diff --git a/src/ifcconvert/ColladaSerializer.cpp b/src/ifcconvert/ColladaSerializer.cpp index 9b12842e59..8d8f0d3433 100644 --- a/src/ifcconvert/ColladaSerializer.cpp +++ b/src/ifcconvert/ColladaSerializer.cpp @@ -335,30 +335,6 @@ void ColladaSerializer::ColladaExporter::startDocument(const std::string& unit_n asset.add(); } -void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationElement* o) -{ - const IfcGeom::Representation::Triangulation& mesh = o->geometry(); - const std::string name = serializer->settings().get(SerializerSettings::USE_ELEMENT_GUIDS) ? - o->guid() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES) ? - o->name() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_TYPES) ? o->type() : o->unique_id())); - const std::string representation_id = "representation-" + boost::lexical_cast(o->geometry().id()); - std::vector material_references; - foreach(const IfcGeom::Material& material, mesh.materials()) { - if (!materials.contains(material)) { - materials.add(material); - } - std::string material_name = (serializer->settings().get(SerializerSettings::USE_MATERIAL_NAMES) - ? material.original_name() : material.name()); - collada_id(material_name); - material_references.push_back(material_name); - } - - 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()) - ); -} - void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationElement* o, const IfcGeom::Element* parent) { const IfcGeom::Representation::Triangulation& mesh = o->geometry(); @@ -433,7 +409,7 @@ void ColladaSerializer::writeHeader() { } void ColladaSerializer::write(const IfcGeom::TriangulationElement* o) { - exporter.write(o); + exporter.write(o, NULL); } void ColladaSerializer::write(const IfcGeom::TriangulationElement* o, const IfcGeom::Element* parent) diff --git a/src/ifcconvert/ColladaSerializer.h b/src/ifcconvert/ColladaSerializer.h index a0f98d78df..96a5f32ab2 100644 --- a/src/ifcconvert/ColladaSerializer.h +++ b/src/ifcconvert/ColladaSerializer.h @@ -129,12 +129,20 @@ private: { const IfcGeom::Element* parent1 = def_obj1.parent; const IfcGeom::Element* parent2 = def_obj2.parent; - + std::cout << "comparing..\n"; + if (parent1 == NULL || parent2 == NULL) { - return (def_obj1.unique_id < def_obj2.unique_id ? true : false); + bool res = (def_obj1.unique_id < def_obj2.unique_id ? true : false); + std::cout << "done\n"; + return res; + } + else + { + bool res = parent1->name() < parent2->name() ? true : false; + std::cout << "done\n"; + return res; } - else return parent1->name() < parent2->name() ? true : false; } public: std::string unique_id, representation_id, type; @@ -164,8 +172,9 @@ 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, @@ -184,8 +193,9 @@ private: , materials(materials) , material_references(material_references) , uvs(uvs) + , parent(NULL) { - parent = NULL; + } }; COLLADABU::NativeString filename; @@ -209,7 +219,7 @@ private: std::vector deferreds; virtual ~ColladaExporter() {} void startDocument(const std::string& unit_name, float unit_magnitude); - void write(const IfcGeom::TriangulationElement* o); + void write(const IfcGeom::TriangulationElement* o) {}; void write(const IfcGeom::TriangulationElement* o, const IfcGeom::Element* parent); void endDocument(); }; @@ -228,7 +238,7 @@ public: } bool ready(); void writeHeader(); - void write(const IfcGeom::TriangulationElement* o); + void write(const IfcGeom::TriangulationElement* o); void write(const IfcGeom::TriangulationElement* o, const IfcGeom::Element* parent); void write(const IfcGeom::BRepElement* /*o*/) {} void finalize(); diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index d5dc39f06f..5ceb200d30 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -587,11 +587,12 @@ int main(int argc, char** argv) do { IfcGeom::Element *geom_object = context_iterator.get(); - + // if the target is a .dae file, get the parent of the object - if (output_extension == ".dae" && geom_object->parent_id() != -1) + if (serializer->settings().get(SerializerSettings::USE_ELEMENT_HIERARCHY) && output_extension == ".dae" && geom_object->parent_id() != -1) { const IfcGeom::Element *parent_object = NULL; + bool hasParent = true; try { parent_object = context_iterator.getObject(geom_object->parent_id()); } catch (std::exception e) @@ -610,8 +611,9 @@ int main(int argc, char** argv) hasParent = hasParent && parent_object->parent_id() != 1; } - if (parent_object != NULL) serializer->write(static_cast*>(geom_object), parent_object); - else serializer->write(static_cast*>(geom_object)); + serializer->write(static_cast*>(geom_object), parent_object); + //delete parent_object; + //parent_object = NULL; } else {