From 470e8e772e4352beae4126a45097ffb7181c3d63 Mon Sep 17 00:00:00 2001 From: Tristan Zimpfer Date: Fri, 21 Apr 2017 16:15:41 +0200 Subject: [PATCH 1/2] Comments + conditions for sorting the deferred objects added. --- src/ifcconvert/ColladaSerializer.cpp | 32 ++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/ifcconvert/ColladaSerializer.cpp b/src/ifcconvert/ColladaSerializer.cpp index 0e8b3d83a6..b87d33ebdd 100644 --- a/src/ifcconvert/ColladaSerializer.cpp +++ b/src/ifcconvert/ColladaSerializer.cpp @@ -221,11 +221,13 @@ void ColladaSerializer::ColladaExporter::ColladaScene::add( } void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::Element& parent){ - + //we open the visual scene tag if it's not. if (!scene_opened) { openVisualScene(scene_id); scene_opened = true; } + + const std::vector matrix = parent.transformation().matrix().data(); double matrix_array[4][4] = { @@ -235,6 +237,7 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom:: { 0, 0, 0, 1 } }; + //adding the offset to the matrix matrix_array[0][3] += serializer->settings().offset[0]; matrix_array[1][3] += serializer->settings().offset[1]; matrix_array[2][3] += serializer->settings().offset[2]; @@ -366,8 +369,14 @@ void ColladaSerializer::ColladaExporter::endDocument() { // In fact due the XML based nature of Collada and its dependency on library nodes, // only at this point all objects are written to the stream. materials.write(); + + std::set geometries_written; - std::sort(deferreds.begin(), deferreds.end()); + + //if the setting USE_ELEMENT_HIERARCHY is in use, we sort the deferreds objects by their parents. + if (serializer->settings().get(SerializerSettings::USE_ELEMENT_HIERARCHY)) { + std::sort(deferreds.begin(), deferreds.end()); + } for (std::vector::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it) { if (geometries_written.find(it->representation_id) != geometries_written.end()) { continue; @@ -376,26 +385,31 @@ 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(); + int parent_id = -1; bool is_parent_empty = true; - for (std::vector::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it) - { + for (std::vector::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it){ const std::string object_name = it->unique_id; - if (it->parent != NULL && parent_id != it->parent->id()) - { - if (!is_parent_empty) - { + //if the setting USE_ELEMENT_HIERARCHY is in use, we check if the parent changed + if (serializer->settings().get(SerializerSettings::USE_ELEMENT_HIERARCHY) && it->parent != NULL && parent_id != it->parent->id()){ + + //close the parent tag, if one is already open. + if (!is_parent_empty){ scene.closeParent(); } parent_id = it->parent->id(); scene.addParent(*it->parent); is_parent_empty = false; } + /// @todo redundant information using ID as both ID and Name, maybe omit Name or allow specifying what would be used as the name scene.add(object_name, object_name, it->representation_id, it->material_references, it->matrix); } - if (!is_parent_empty) scene.closeParent(); + //close the last parent tag. + if (!is_parent_empty) { + scene.closeParent(); + }; scene.write(); stream.endDocument(); } From 08e4d16f28f7531e22e22acfa5d72b6467bc1f70 Mon Sep 17 00:00:00 2001 From: Tristan Zimpfer Date: Fri, 21 Apr 2017 18:05:35 +0200 Subject: [PATCH 2/2] Modified the condition checking if the parent had changed so an object without parent isn't placed in a storey. --- src/ifcconvert/ColladaSerializer.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ifcconvert/ColladaSerializer.cpp b/src/ifcconvert/ColladaSerializer.cpp index b87d33ebdd..1512b2836f 100644 --- a/src/ifcconvert/ColladaSerializer.cpp +++ b/src/ifcconvert/ColladaSerializer.cpp @@ -369,7 +369,6 @@ void ColladaSerializer::ColladaExporter::endDocument() { // In fact due the XML based nature of Collada and its dependency on library nodes, // only at this point all objects are written to the stream. materials.write(); - std::set geometries_written; @@ -391,16 +390,19 @@ void ColladaSerializer::ColladaExporter::endDocument() { for (std::vector::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it){ const std::string object_name = it->unique_id; - //if the setting USE_ELEMENT_HIERARCHY is in use, we check if the parent changed - if (serializer->settings().get(SerializerSettings::USE_ELEMENT_HIERARCHY) && it->parent != NULL && parent_id != it->parent->id()){ + //if the setting USE_ELEMENT_HIERARCHY is in use, we check if the parent has changed + if (serializer->settings().get(SerializerSettings::USE_ELEMENT_HIERARCHY) && ((it->parent == NULL && parent_id != -1) || (it->parent != NULL && parent_id != it->parent->id()))){ //close the parent tag, if one is already open. if (!is_parent_empty){ scene.closeParent(); } - parent_id = it->parent->id(); - scene.addParent(*it->parent); - is_parent_empty = false; + + if (it->parent != NULL){ + parent_id = it->parent->id(); + scene.addParent(*it->parent); + is_parent_empty = false; + } } /// @todo redundant information using ID as both ID and Name, maybe omit Name or allow specifying what would be used as the name