mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 13:43:40 +00:00
.glb --separate-z-up-node option
This commit is contained in:
@@ -647,7 +647,7 @@ namespace ifcopenshell {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Settings : public SettingsContainer<
|
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>
|
||||||
>
|
>
|
||||||
{};
|
{};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 const char* const description = "Use a geometrical section rather than full polyhedral output and footprint in TTL WKT";
|
||||||
static constexpr bool defaultvalue = false;
|
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 <
|
class SerializerSettings : public SettingsContainer <
|
||||||
// @todo should we use tuple_cat here to unify the settings into a single class?
|
// @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>>
|
||||||
>
|
|
||||||
{};
|
{};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ void GltfSerializer::write(const IfcGeom::TriangulationElement* o) {
|
|||||||
json parent_node = json::object();
|
json parent_node = json::object();
|
||||||
|
|
||||||
std::array<double, 16> matrix_flat;
|
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
|
// y-up transform is only accounted for on root
|
||||||
matrix_flat = {
|
matrix_flat = {
|
||||||
mm(0,0), mm(1,0), mm(2,0), mm(3,0),
|
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;
|
json node;
|
||||||
{
|
{
|
||||||
std::array<double, 16> matrix_flat;
|
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
|
// y-up transform is only accounted for on root
|
||||||
matrix_flat = {
|
matrix_flat = {
|
||||||
m(0,0), m(1,0), m(2,0), m(3,0),
|
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() {
|
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_) {
|
if (north_rotation_) {
|
||||||
(*north_rotation_)["children"] = json::array();
|
(*north_rotation_)["children"] = roots_;
|
||||||
for (int i = 0; i < json_["nodes"].size(); ++i) {
|
|
||||||
(*north_rotation_)["children"].push_back(i);
|
|
||||||
}
|
|
||||||
json_["nodes"].push_back(*north_rotation_);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ecef_transform_) {
|
if (ecef_transform_) {
|
||||||
(*ecef_transform_)["children"] = json::array();
|
(*ecef_transform_)["children"] = roots_;
|
||||||
for (int i = 0; i < json_["nodes"].size(); ++i) {
|
}
|
||||||
(*ecef_transform_)["children"].push_back(i);
|
|
||||||
}
|
if (z_up_transform_) {
|
||||||
json_["nodes"].push_back(*ecef_transform_);
|
(*ecef_transform_)["children"] = roots_;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_fstream1_.close();
|
tmp_fstream1_.close();
|
||||||
@@ -447,7 +457,7 @@ void GltfSerializer::finalize() {
|
|||||||
json scene_0;
|
json scene_0;
|
||||||
if (geometry_settings().get<ifcopenshell::geometry::settings::UseElementHierarchy>().get()) {
|
if (geometry_settings().get<ifcopenshell::geometry::settings::UseElementHierarchy>().get()) {
|
||||||
scene_0["nodes"] = roots_;
|
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};
|
scene_0["nodes"] = std::array<size_t, 1>{json_["nodes"].size() - 1};
|
||||||
} else {
|
} else {
|
||||||
scene_0["nodes"] = node_array_;
|
scene_0["nodes"] = node_array_;
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ private:
|
|||||||
std::ofstream fstream_, tmp_fstream1_, tmp_fstream2_;
|
std::ofstream fstream_, tmp_fstream1_, tmp_fstream2_;
|
||||||
std::map<std::string, int> materials_, meshes_;
|
std::map<std::string, int> materials_, meshes_;
|
||||||
json json_, node_array_;
|
json json_, node_array_;
|
||||||
boost::optional<json> ecef_transform_, north_rotation_;
|
boost::optional<json> ecef_transform_, north_rotation_, z_up_transform_;
|
||||||
int bufferViewId;
|
int bufferViewId;
|
||||||
std::map<const IfcUtil::IfcBaseEntity*, size_t> node_indices_;
|
std::map<const IfcUtil::IfcBaseEntity*, size_t> node_indices_;
|
||||||
std::vector<size_t> roots_;
|
std::vector<size_t> roots_;
|
||||||
|
|||||||
Reference in New Issue
Block a user