.glb --separate-z-up-node option

This commit is contained in:
Thomas Krijnen
2025-11-17 18:25:51 +01:00
parent 1b9acadd81
commit 9e9d664511
4 changed files with 32 additions and 17 deletions
+1 -1
View File
@@ -647,7 +647,7 @@ namespace ifcopenshell {
};
class Settings : public SettingsContainer<
std::tuple<MesherLinearDeflection, MesherAngularDeflection, ReorientShells, LengthUnit, PlaneUnit, Precision, OutputDimensionality, LayersetFirst, DisableBooleanResult, NoWireIntersectionCheck, NoWireIntersectionTolerance, PrecisionFactor, DebugBooleanOperations, BooleanAttempt2d, SurfaceColour, WeldVertices, UseWorldCoords, UnifyShapes, UseMaterialNames, ConvertBackUnits, ContextIds, ContextTypes, ContextIdentifiers, IteratorOutput, DisableOpeningSubtractions, ApplyDefaultMaterials, DontEmitNormals, GenerateUvs, ApplyLayerSets, UseElementHierarchy, ValidateQuantities, EdgeArrows, BuildingLocalPlacement, SiteLocalPlacement, ForceSpaceTransparency, CircleSegments, CgalSmoothAngleDegrees, KeepBoundingBoxes, ComputeCurvature, FunctionStepType, FunctionStepParam, NoParallelMapping, PermissiveShapeReuse, ModelOffset, ModelRotation, TriangulationType, CgalEmitOriginalEdges, OcctNoCleanTriangulation, CacheShapes, DeferProcessingFirstElement, MaxOffset, MaxOffsetDeviation, ApplyOffset>
std::tuple<MesherLinearDeflection, MesherAngularDeflection, ReorientShells, LengthUnit, PlaneUnit, Precision, OutputDimensionality, LayersetFirst, DisableBooleanResult, NoWireIntersectionCheck, NoWireIntersectionTolerance, PrecisionFactor, DebugBooleanOperations, BooleanAttempt2d, SurfaceColour, WeldVertices, UseWorldCoords, UnifyShapes, UseMaterialNames, ConvertBackUnits, ContextIds, ContextTypes, ContextIdentifiers, IteratorOutput, DisableOpeningSubtractions, ApplyDefaultMaterials, DontEmitNormals, GenerateUvs, ApplyLayerSets, UseElementHierarchy, ValidateQuantities, EdgeArrows, BuildingLocalPlacement, SiteLocalPlacement, ForceSpaceTransparency, CircleSegments, CgalSmoothAngleDegrees, KeepBoundingBoxes, ComputeCurvature, FunctionStepType, FunctionStepParam, NoParallelMapping, PermissiveShapeReuse, ModelOffset, ModelRotation, TriangulationType, CgalEmitOriginalEdges, OcctNoCleanTriangulation, CacheShapes, DeferProcessingFirstElement, MaxOffset, MaxOffsetDeviation, ApplyOffset>
>
{};
}
+7 -2
View File
@@ -87,12 +87,17 @@ inline namespace settings {
static constexpr const char* const description = "Use a geometrical section rather than full polyhedral output and footprint in TTL WKT";
static constexpr bool defaultvalue = false;
};
struct SeparateZUpNode : public SettingBase<SeparateZUpNode, bool> {
static constexpr const char* const name = "separate-z-up-node";
static constexpr const char* const description = "Introduce a separate Z-Up node into the GlTF hierarchy instead of multiplying the transform into the root node matrices";
static constexpr bool defaultvalue = false;
};
}
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>
>
std::tuple<UseElementNames, UseElementGuids, UseElementStepIds, UseElementTypes, UseYUp, WriteGltfEcef, FloatingPointDigits, BaseUri, WktUseSection, SeparateZUpNode>>
{};
}
+23 -13
View File
@@ -215,7 +215,7 @@ void GltfSerializer::write(const IfcGeom::TriangulationElement* o) {
json parent_node = json::object();
std::array<double, 16> matrix_flat;
if (settings_.get<ifcopenshell::geometry::settings::WriteGltfEcef>().get() || !is_root) {
if (settings_.get<ifcopenshell::geometry::settings::SeparateZUpNode>().get() || settings_.get<ifcopenshell::geometry::settings::WriteGltfEcef>().get() || !is_root) {
// y-up transform is only accounted for on root
matrix_flat = {
mm(0,0), mm(1,0), mm(2,0), mm(3,0),
@@ -258,7 +258,7 @@ void GltfSerializer::write(const IfcGeom::TriangulationElement* o) {
json node;
{
std::array<double, 16> matrix_flat;
if (settings_.get<ifcopenshell::geometry::settings::WriteGltfEcef>().get() || !o->parents().empty()) {
if (settings_.get<ifcopenshell::geometry::settings::SeparateZUpNode>().get() || settings_.get<ifcopenshell::geometry::settings::WriteGltfEcef>().get() || !o->parents().empty()) {
// y-up transform is only accounted for on root
matrix_flat = {
m(0,0), m(1,0), m(2,0), m(3,0),
@@ -411,20 +411,30 @@ void write_block(std::ostream& fs, It begin, It end) {
}
void GltfSerializer::finalize() {
// separate z up
if (settings_.get<ifcopenshell::geometry::settings::SeparateZUpNode>().get()) {
z_up_transform_ = json::object();
(*z_up_transform_)["name"] = "Z_UP";
static const std::array<double, 16> z_up_matrix = {
1, 0, 0, 0,
0, 0, -1, 0,
0, 1, 0, 0,
0, 0, 0, 1};
(*z_up_transform_)["matrix"] = z_up_matrix;
(*z_up_transform_)["children"] = roots_;
json_["nodes"].push_back(*z_up_transform_);
}
if (north_rotation_) {
(*north_rotation_)["children"] = json::array();
for (int i = 0; i < json_["nodes"].size(); ++i) {
(*north_rotation_)["children"].push_back(i);
}
json_["nodes"].push_back(*north_rotation_);
(*north_rotation_)["children"] = roots_;
}
if (ecef_transform_) {
(*ecef_transform_)["children"] = json::array();
for (int i = 0; i < json_["nodes"].size(); ++i) {
(*ecef_transform_)["children"].push_back(i);
}
json_["nodes"].push_back(*ecef_transform_);
(*ecef_transform_)["children"] = roots_;
}
if (z_up_transform_) {
(*ecef_transform_)["children"] = roots_;
}
tmp_fstream1_.close();
@@ -447,7 +457,7 @@ void GltfSerializer::finalize() {
json scene_0;
if (geometry_settings().get<ifcopenshell::geometry::settings::UseElementHierarchy>().get()) {
scene_0["nodes"] = roots_;
} else if (north_rotation_ || ecef_transform_) {
} else if (north_rotation_ || ecef_transform_ || z_up_transform_) {
scene_0["nodes"] = std::array<size_t, 1>{json_["nodes"].size() - 1};
} else {
scene_0["nodes"] = node_array_;
+1 -1
View File
@@ -36,7 +36,7 @@ private:
std::ofstream fstream_, tmp_fstream1_, tmp_fstream2_;
std::map<std::string, int> materials_, meshes_;
json json_, node_array_;
boost::optional<json> ecef_transform_, north_rotation_;
boost::optional<json> ecef_transform_, north_rotation_, z_up_transform_;
int bufferViewId;
std::map<const IfcUtil::IfcBaseEntity*, size_t> node_indices_;
std::vector<size_t> roots_;