fixed obj serialization issues
parent
1c550cc024
commit
723e8d951f
|
@ -80,6 +80,8 @@ public:
|
|||
|
||||
/// Return the shape's BSDF
|
||||
inline const BSDF *getBSDF() const { return m_bsdf.get(); }
|
||||
/// Return the shape's BSDF
|
||||
inline BSDF *getBSDF() { return m_bsdf.get(); }
|
||||
|
||||
/// Return the name of this shape
|
||||
inline const std::string &getName() const { return m_name; }
|
||||
|
|
|
@ -58,12 +58,12 @@ void InstanceManager::serialize(Stream *stream, const SerializableObject *inst)
|
|||
} else if (m_objToId.find(inst) != m_objToId.end()) {
|
||||
stream->writeUInt(m_objToId[inst]);
|
||||
} else {
|
||||
stream->writeUInt(++m_counter);
|
||||
stream->writeString(inst->getClass()->getName());
|
||||
m_objToId[inst]=m_counter;
|
||||
#ifdef DEBUG_SERIALIZATION
|
||||
Log(EDebug, "Serializing a class of type '%s'", inst->getClass()->getName().c_str());
|
||||
#endif
|
||||
stream->writeUInt(++m_counter);
|
||||
stream->writeString(inst->getClass()->getName());
|
||||
m_objToId[inst]=m_counter;
|
||||
inst->serialize(stream, this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ TriMesh::TriMesh(const std::string &name, Transform worldToObject, Triangle *tri
|
|||
m_name = name;
|
||||
m_worldToObject = worldToObject;
|
||||
m_objectToWorld.inverse();
|
||||
|
||||
}
|
||||
|
||||
TriMesh::TriMesh(const Properties &props)
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
static int localWorkerCtr = 0, remoteWorkerCtr = 0;
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent), ui(new Ui::MainWindow) {
|
||||
QMainWindow(parent), ui(new Ui::MainWindow), m_activeWindowHack(false) {
|
||||
Logger *logger = Thread::getThread()->getLogger();
|
||||
|
||||
#if defined(__OSX__)
|
||||
|
@ -110,7 +110,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
#endif
|
||||
m_serverWidget = NULL;
|
||||
m_contextIndex = -1;
|
||||
m_activeWindowHack = false;
|
||||
|
||||
for (int i = 0; i < MAX_RECENT_FILES; ++i) {
|
||||
m_actRecent[i] = new QAction(this);
|
||||
|
|
|
@ -8,7 +8,7 @@ MTS_NAMESPACE_BEGIN
|
|||
/**
|
||||
* Wavefront OBJ triangle mesh loader
|
||||
*/
|
||||
class WavefrontOBJ : public TriMesh {
|
||||
class WavefrontOBJ : public Shape {
|
||||
public:
|
||||
struct OBJTriangle {
|
||||
unsigned int v[3];
|
||||
|
@ -16,7 +16,7 @@ public:
|
|||
unsigned int uv[3];
|
||||
};
|
||||
|
||||
WavefrontOBJ(const Properties &props) : TriMesh(props) {
|
||||
WavefrontOBJ(const Properties &props) : Shape(props) {
|
||||
m_name = FileResolver::getInstance()->resolve(props.getString("filename"));
|
||||
|
||||
/* Load the geometry */
|
||||
|
@ -122,6 +122,24 @@ public:
|
|||
triangles, hasNormals, hasTexcoords, currentMaterial);
|
||||
}
|
||||
|
||||
WavefrontOBJ(Stream *stream, InstanceManager *manager) : Shape(stream, manager) {
|
||||
unsigned int meshCount = stream->readUInt();
|
||||
m_meshes.resize(meshCount);
|
||||
|
||||
for (unsigned int i=0; i<meshCount; ++i) {
|
||||
m_meshes[i] = static_cast<TriMesh *>(manager->getInstance(stream));
|
||||
m_meshes[i]->incRef();
|
||||
}
|
||||
}
|
||||
|
||||
void serialize(Stream *stream, InstanceManager *manager) const {
|
||||
Shape::serialize(stream, manager);
|
||||
|
||||
stream->writeUInt((unsigned int) m_meshes.size());
|
||||
for (size_t i=0; i<m_meshes.size(); ++i)
|
||||
manager->serialize(stream, m_meshes[i]);
|
||||
}
|
||||
|
||||
void parse(OBJTriangle &t, int i, const std::string &str) {
|
||||
std::vector<std::string> tokens = tokenize(str, "/");
|
||||
if (tokens.size() == 1) {
|
||||
|
@ -269,9 +287,6 @@ public:
|
|||
triangles.size(), vertexBuffer.size(), numMerged);
|
||||
}
|
||||
|
||||
WavefrontOBJ(Stream *stream, InstanceManager *manager) : TriMesh(stream, manager) {
|
||||
}
|
||||
|
||||
virtual ~WavefrontOBJ() {
|
||||
for (size_t i=0; i<m_meshes.size(); ++i)
|
||||
m_meshes[i]->decRef();
|
||||
|
@ -297,6 +312,8 @@ public:
|
|||
m_bsdf = static_cast<BSDF *>(child);
|
||||
for (size_t i=0; i<m_meshes.size(); ++i)
|
||||
m_meshes[i]->addChild(name, child);
|
||||
Assert(m_meshes.size() > 0);
|
||||
m_bsdf->setParent(NULL);
|
||||
} else if (cClass->derivesFrom(Luminaire::m_theClass)) {
|
||||
Assert(m_luminaire == NULL && m_meshes.size() == 1);
|
||||
m_luminaire = static_cast<Luminaire *>(child);
|
||||
|
@ -323,7 +340,17 @@ public:
|
|||
Shape *getElement(int index) {
|
||||
if (index >= (int) m_meshes.size())
|
||||
return NULL;
|
||||
return m_meshes[index];
|
||||
Shape *shape = m_meshes[index];
|
||||
BSDF *bsdf = shape->getBSDF();
|
||||
Luminaire *luminaire = shape->getLuminaire();
|
||||
Subsurface *subsurface = shape->getSubsurface();
|
||||
if (bsdf)
|
||||
bsdf->setParent(shape);
|
||||
if (luminaire)
|
||||
luminaire->setParent(shape);
|
||||
if (subsurface)
|
||||
subsurface->setParent(shape);
|
||||
return shape;
|
||||
}
|
||||
|
||||
MTS_DECLARE_CLASS()
|
||||
|
@ -332,6 +359,6 @@ private:
|
|||
std::map<std::string, BSDF *> m_materials;
|
||||
};
|
||||
|
||||
MTS_IMPLEMENT_CLASS_S(WavefrontOBJ, false, TriMesh)
|
||||
MTS_IMPLEMENT_CLASS_S(WavefrontOBJ, false, Shape)
|
||||
MTS_EXPORT_PLUGIN(WavefrontOBJ, "OBJ triangle mesh loader");
|
||||
MTS_NAMESPACE_END
|
||||
|
|
Loading…
Reference in New Issue