From 9f362853d6a8dbdb43ed46ea0faa2acc840e6f65 Mon Sep 17 00:00:00 2001 From: Tristan Zimpfer Date: Wed, 19 Apr 2017 11:48:52 +0200 Subject: [PATCH] Added a matrix for the parent node and a better id. --- src/ifcconvert/ColladaSerializer.cpp | 35 +++++++++++++++++++++------- src/ifcconvert/ColladaSerializer.h | 34 ++++++++++++++++++++++----- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/ifcconvert/ColladaSerializer.cpp b/src/ifcconvert/ColladaSerializer.cpp index fb72473d63..0890667834 100644 --- a/src/ifcconvert/ColladaSerializer.cpp +++ b/src/ifcconvert/ColladaSerializer.cpp @@ -220,16 +220,33 @@ void ColladaSerializer::ColladaExporter::ColladaScene::add( node.end(); } -void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const std::string& node_name){ +void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::Element& parent){ if (!scene_opened) { openVisualScene(scene_id); scene_opened = true; } + const std::vector matrix = parent.transformation().matrix().data(); + + double matrix_array[4][4] = { + { (double)matrix[0], (double)matrix[3], (double)matrix[6], (double)matrix[9] }, + { (double)matrix[1], (double)matrix[4], (double)matrix[7], (double)matrix[10] }, + { (double)matrix[2], (double)matrix[5], (double)matrix[8], (double)matrix[11] }, + { 0, 0, 0, 1 } + }; + + matrix_array[0][3] += serializer->settings().offset[0]; + matrix_array[1][3] += serializer->settings().offset[1]; + matrix_array[2][3] += serializer->settings().offset[2]; + + + const std::string id = "representation-" + boost::lexical_cast(parent.id()); + current_node = new COLLADASW::Node(mSW); - current_node->setNodeId(node_name); - current_node->setNodeName(node_name); + current_node->setNodeId(id); + current_node->setNodeName(parent.name()); + current_node->addMatrix(matrix_array); current_node->setType(COLLADASW::Node::NODE); current_node->start(); } @@ -338,7 +355,7 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme deferreds.push_back( DeferredObject(name, representation_id, o->type(), o->transformation().matrix().data(), mesh.verts(), mesh.normals(), - mesh.faces(), mesh.edges(), mesh.material_ids(), mesh.materials(), material_references, mesh.uvs(), "") + mesh.faces(), mesh.edges(), mesh.material_ids(), mesh.materials(), material_references, mesh.uvs()) ); } @@ -361,7 +378,7 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme deferreds.push_back( DeferredObject(name, representation_id, o->type(), o->transformation().matrix().data(), mesh.verts(), mesh.normals(), - mesh.faces(), mesh.edges(), mesh.material_ids(), mesh.materials(), material_references, mesh.uvs(), parent->name()) + mesh.faces(), mesh.edges(), mesh.material_ids(), mesh.materials(), material_references, mesh.uvs(), *parent) ); } @@ -379,17 +396,17 @@ void ColladaSerializer::ColladaExporter::endDocument() { geometries.write(it->representation_id, it->type, it->vertices, it->normals, it->faces, it->edges, it->material_ids, it->materials, it->uvs); } geometries.close(); - std::string parent_name; + int parent_id; bool is_parent_empty = true; for (std::vector::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it) { const std::string object_name = it->unique_id; - if (parent_name != it->parent){ + if (parent_id != it->parent->id()){ if (!is_parent_empty){ scene.closeParent(); } - parent_name = it->parent; - scene.addParent(parent_name); + parent_id = it->parent->id(); + scene.addParent(*it->parent); is_parent_empty = false; } diff --git a/src/ifcconvert/ColladaSerializer.h b/src/ifcconvert/ColladaSerializer.h index 716575b632..870c9a91fe 100644 --- a/src/ifcconvert/ColladaSerializer.h +++ b/src/ifcconvert/ColladaSerializer.h @@ -89,7 +89,7 @@ private: {} void add(const std::string& node_id, const std::string& node_name, const std::string& geom_name, const std::vector& material_ids, const std::vector& matrix); - void addParent(const std::string& node_name); + void addParent(const IfcGeom::Element& parent); void closeParent(); void write(); ColladaSerializer *serializer; @@ -127,7 +127,9 @@ private: class DeferredObject { friend bool operator < (const DeferredObject & def_obj1, const DeferredObject & def_obj2) { - return (def_obj1.parent < def_obj2.parent ? true : false); + const IfcGeom::Element parent1 = *def_obj1.parent; + const IfcGeom::Element parent2 = *def_obj2.parent; + return (parent1.name() < parent2.name() ? true : false); } public: std::string unique_id, representation_id, type; @@ -140,11 +142,11 @@ private: std::vector materials; std::vector material_references; std::vector uvs; - std::string parent; + const IfcGeom::Element* parent; DeferredObject(const std::string& unique_id, const std::string& representation_id, const std::string& type, const std::vector& matrix, const std::vector& vertices, const std::vector& normals, const std::vector& faces, const std::vector& edges, const std::vector& material_ids, const std::vector& materials, - const std::vector& material_references, const std::vector& uvs, const std::string& parent) + const std::vector& material_references, const std::vector& uvs, const IfcGeom::Element& _parent) : unique_id(unique_id) , representation_id(representation_id) , type(type) @@ -157,8 +159,28 @@ private: , materials(materials) , material_references(material_references) , uvs(uvs) - , parent(parent) - {} + { + parent = &_parent; + } + + DeferredObject(const std::string& unique_id, const std::string& representation_id, const std::string& type, const std::vector& matrix, + const std::vector& vertices, const std::vector& normals, const std::vector& faces, + const std::vector& edges, const std::vector& material_ids, const std::vector& materials, + const std::vector& material_references, const std::vector& uvs) + : unique_id(unique_id) + , representation_id(representation_id) + , type(type) + , matrix(matrix) + , vertices(vertices) + , normals(normals) + , faces(faces) + , edges(edges) + , material_ids(material_ids) + , materials(materials) + , material_references(material_references) + , uvs(uvs) + { + } }; COLLADABU::NativeString filename; COLLADASW::StreamWriter stream;