Compare commits

...

2 Commits

Author SHA1 Message Date
Petru Conduraru df0af3a65a GltfSerializer: opt-in --gltf-extras with GlobalId, type and name
Issue #790 asked for IFC metadata in glTF node extras so the glb is
self-describing. Off by default to keep file size unchanged, per the
maintainer's concern about embedding data; the flag writes GlobalId,
entity type and Name on every node, including hierarchy group nodes.

Generated with the assistance of an AI coding tool.
2026-07-25 08:21:21 +03:00
Petru Conduraru ecdc60b231 GltfSerializer: name hierarchy group nodes after their own element
With --element-hierarchy, the intermediate nodes representing spatial
structure (storey, building, site) were all named after whichever leaf
element triggered their creation, instead of their own entity. Use the
ancestor element at the current tree level, so --use-element-guids and
default naming both identify group nodes correctly.

Generated with the assistance of an AI coding tool.
2026-07-25 08:21:21 +03:00
2 changed files with 16 additions and 3 deletions
+8 -1
View File
@@ -68,6 +68,13 @@ inline namespace settings {
static constexpr bool defaultvalue = false;
};
struct GltfExtras : public SettingBase<GltfExtras, bool> {
static constexpr const char* const name = "gltf-extras";
static constexpr const char* const description = "Write the IFC GlobalId, entity type and name of every element into the "
"glTF node extras, so the output is self-describing without a sidecar file. Applicable to GLB output.";
static constexpr bool defaultvalue = false;
};
struct FloatingPointDigits : public SettingBase<FloatingPointDigits, int> {
static constexpr const char* const name = "digits";
static constexpr const char* const description = "Sets the precision to be used to format floating-point values, 15 by default. "
@@ -97,7 +104,7 @@ inline namespace settings {
class SerializerSettings : public SettingsContainer <
// @todo should we use tuple_cat here to unify the settings into a single class?
std::tuple<UseElementNames, UseElementGuids, UseElementStepIds, UseElementTypes, UseYUp, WriteGltfEcef, FloatingPointDigits, BaseUri, WktUseSection, SeparateZUpNode>>
std::tuple<UseElementNames, UseElementGuids, UseElementStepIds, UseElementTypes, UseYUp, WriteGltfEcef, GltfExtras, FloatingPointDigits, BaseUri, WktUseSection, SeparateZUpNode>>
{};
}
+8 -2
View File
@@ -249,7 +249,10 @@ void GltfSerializer::write(const IfcGeom::TriangulationElement* o) {
size_t new_node_index = json_["nodes"].size();
node_indices_[(*it)->product()] = new_node_index;
node_array_.push_back(new_node_index);
parent_node["name"] = object_id(o);
parent_node["name"] = object_id(*it);
if (settings_.get<ifcopenshell::geometry::settings::GltfExtras>().get()) {
parent_node["extras"] = { {"GlobalId", (*it)->guid()}, {"IfcType", (*it)->type()}, {"Name", (*it)->name()} };
}
parent_node["children"] = json::array({current_node_index});
json_["nodes"].push_back(parent_node);
@@ -290,7 +293,10 @@ void GltfSerializer::write(const IfcGeom::TriangulationElement* o) {
}
}
node["name"] = object_id(o);
if (settings_.get<ifcopenshell::geometry::settings::GltfExtras>().get()) {
node["extras"] = { {"GlobalId", o->guid()}, {"IfcType", o->type()}, {"Name", o->name()} };
}
int current_mesh_index;
// See if this mesh has already been processed