diff --git a/include/mitsuba/render/shape.h b/include/mitsuba/render/shape.h index 0a48defd..37a2b3fa 100644 --- a/include/mitsuba/render/shape.h +++ b/include/mitsuba/render/shape.h @@ -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; } diff --git a/src/libcore/serialization.cpp b/src/libcore/serialization.cpp index a8afbc12..cfd5d55e 100644 --- a/src/libcore/serialization.cpp +++ b/src/libcore/serialization.cpp @@ -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); } } diff --git a/src/librender/trimesh.cpp b/src/librender/trimesh.cpp index 59974880..fecc71e8 100644 --- a/src/librender/trimesh.cpp +++ b/src/librender/trimesh.cpp @@ -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) diff --git a/src/qtgui/mainwindow.cpp b/src/qtgui/mainwindow.cpp index 0940f2ef..562a56e6 100644 --- a/src/qtgui/mainwindow.cpp +++ b/src/qtgui/mainwindow.cpp @@ -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); diff --git a/src/shapes/obj.cpp b/src/shapes/obj.cpp index 6000d67c..05a52fea 100644 --- a/src/shapes/obj.cpp +++ b/src/shapes/obj.cpp @@ -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(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; iserialize(stream, m_meshes[i]); + } + void parse(OBJTriangle &t, int i, const std::string &str) { std::vector 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; idecRef(); @@ -297,6 +312,8 @@ public: m_bsdf = static_cast(child); for (size_t i=0; iaddChild(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(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 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