diff --git a/src/ifcconvert/ColladaSerializer.cpp b/src/ifcconvert/ColladaSerializer.cpp index 6ef394ad2e..9c26211e84 100644 --- a/src/ifcconvert/ColladaSerializer.cpp +++ b/src/ifcconvert/ColladaSerializer.cpp @@ -34,6 +34,8 @@ #include #include +using namespace IfcSchema; + static void collada_id(std::string &s) { IfcUtil::sanitate_material_name(s); @@ -66,12 +68,12 @@ void ColladaSerializer::ColladaExporter::ColladaGeometries::write( const std::vector& uvs) { openMesh(mesh_id); - + // The normals vector can be empty for example when the WELD_VERTICES setting is used. // IfcOpenShell does not provide them with multiple face normals collapsed into a single vertex. const bool has_normals = !normals.empty(); const bool has_uvs = !uvs.empty(); - + addFloatSource(mesh_id, COLLADASW::LibraryGeometries::POSITIONS_SOURCE_ID_SUFFIX, positions); if (has_normals) { addFloatSource(mesh_id, COLLADASW::LibraryGeometries::NORMALS_SOURCE_ID_SUFFIX, normals); @@ -298,14 +300,16 @@ void ColladaSerializer::ColladaExporter::startDocument(const std::string& unit_n asset.setUpAxisType(COLLADASW::Asset::Z_UP); asset.add(); } - +// ******************************** +// NOTE : o->context.parent_id ????????????????? == -1 si pas de parent +// On a un type de product ifcBuildingStorey 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() : o->unique_id()); + o->guid() : (serializer->settings().get(SerializerSettings::USE_ELEMENT_NAMES) ? o->name() : (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)) { @@ -323,6 +327,7 @@ void ColladaSerializer::ColladaExporter::write(const IfcGeom::TriangulationEleme ); } + 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. @@ -338,6 +343,7 @@ void ColladaSerializer::ColladaExporter::endDocument() { geometries.close(); for (std::vector::const_iterator it = deferreds.begin(); it != deferreds.end(); ++it) { const std::string object_name = it->unique_id; + /// @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); } diff --git a/src/ifcconvert/ColladaSerializer.h b/src/ifcconvert/ColladaSerializer.h index faa092203f..e466413b7b 100644 --- a/src/ifcconvert/ColladaSerializer.h +++ b/src/ifcconvert/ColladaSerializer.h @@ -177,6 +177,7 @@ private: ColladaExporter exporter; std::string unit_name; float unit_magnitude; + IfcParse::IfcFile* file; public: ColladaSerializer(const std::string& dae_filename, const SerializerSettings& settings) : GeometrySerializer(settings) @@ -197,7 +198,7 @@ public: unit_name = name; unit_magnitude = magnitude; } - void setFile(IfcParse::IfcFile*) {} + void setFile(IfcParse::IfcFile* f) { file = f; } }; #endif diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index 6ec5660ebf..b13d799ad7 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -519,7 +519,7 @@ int main(int argc, char** argv) time_t start,end; time(&start); - + IfcGeom::Iterator context_iterator(settings, &ifc_file, filter_funcs); if (!context_iterator.initialize()) { /// @todo It would be nice to know and print separate error prints for a case where we found no entities @@ -577,9 +577,32 @@ int main(int argc, char** argv) do { IfcGeom::Element *geom_object = context_iterator.get(); - if (is_tesselated) { + + // Note : Ici on envoie au Serializer les obj à traier. + // Un tri a déjà été fait, on envoie pas tous les objets. Les IfcBuildingStorey ne sont déjà plus là ... + + // if the target is a .dae file, get the parent of the object + if (output_extension == ".dae" && geom_object->parent_id() != -1) + { + const IfcGeom::Element *parent_object = context_iterator.getObject(geom_object->parent_id()); + + int cptSecure = 0; + while (parent_object->type() != "IfcBuildingStorey" && cptSecure < 1000 && parent_object->parent_id() != 1) + { + cptSecure++; + parent_object = context_iterator.getObject(parent_object->parent_id()); + } + //Debug + if (geom_object->parent_id() == -1) std::cout << "Parent = -1 : " << geom_object->name(); + std::cout << '\n' << "obj " << geom_object->unique_id() << " parent = " << parent_object->name() << " of type " << parent_object->type() << '\n'; + } + + if (is_tesselated) + { serializer->write(static_cast*>(geom_object)); - } else { + } + else + { serializer->write(static_cast*>(geom_object)); } const int progress = context_iterator.progress() / 2;