Comments + conditions for sorting the deferred objects added.

This commit is contained in:
Tristan Zimpfer
2017-04-21 16:15:41 +02:00
parent ea609af394
commit 470e8e772e
+23 -9
View File
@@ -221,11 +221,13 @@ void ColladaSerializer::ColladaExporter::ColladaScene::add(
} }
void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::Element<real_t>& parent){ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::Element<real_t>& parent){
//we open the visual scene tag if it's not.
if (!scene_opened) { if (!scene_opened) {
openVisualScene(scene_id); openVisualScene(scene_id);
scene_opened = true; scene_opened = true;
} }
const std::vector<real_t> matrix = parent.transformation().matrix().data(); const std::vector<real_t> matrix = parent.transformation().matrix().data();
double matrix_array[4][4] = { double matrix_array[4][4] = {
@@ -235,6 +237,7 @@ void ColladaSerializer::ColladaExporter::ColladaScene::addParent(const IfcGeom::
{ 0, 0, 0, 1 } { 0, 0, 0, 1 }
}; };
//adding the offset to the matrix
matrix_array[0][3] += serializer->settings().offset[0]; matrix_array[0][3] += serializer->settings().offset[0];
matrix_array[1][3] += serializer->settings().offset[1]; matrix_array[1][3] += serializer->settings().offset[1];
matrix_array[2][3] += serializer->settings().offset[2]; 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, // 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. // only at this point all objects are written to the stream.
materials.write(); materials.write();
std::set<std::string> geometries_written; std::set<std::string> 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<DeferredObject>::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it) { for (std::vector<DeferredObject>::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it) {
if (geometries_written.find(it->representation_id) != geometries_written.end()) { if (geometries_written.find(it->representation_id) != geometries_written.end()) {
continue; 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.write(it->representation_id, it->type, it->vertices, it->normals, it->faces, it->edges, it->material_ids, it->materials, it->uvs);
} }
geometries.close(); geometries.close();
int parent_id = -1; int parent_id = -1;
bool is_parent_empty = true; bool is_parent_empty = true;
for (std::vector<DeferredObject>::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it) for (std::vector<DeferredObject>::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it){
{
const std::string object_name = it->unique_id; const std::string object_name = it->unique_id;
if (it->parent != NULL && parent_id != it->parent->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 (!is_parent_empty)
{ //close the parent tag, if one is already open.
if (!is_parent_empty){
scene.closeParent(); scene.closeParent();
} }
parent_id = it->parent->id(); parent_id = it->parent->id();
scene.addParent(*it->parent); scene.addParent(*it->parent);
is_parent_empty = false; 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 /// @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); 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(); scene.write();
stream.endDocument(); stream.endDocument();
} }