mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 17:58:20 +00:00
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.
This commit is contained in:
@@ -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>>
|
||||
{};
|
||||
|
||||
}
|
||||
|
||||
@@ -250,6 +250,9 @@ void GltfSerializer::write(const IfcGeom::TriangulationElement* o) {
|
||||
node_indices_[(*it)->product()] = new_node_index;
|
||||
node_array_.push_back(new_node_index);
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user