mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-20 20:22:09 +00:00
.glb --separate-z-up-node option
This commit is contained in:
@@ -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_;
|
||||
|
||||
@@ -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_;
|
||||
|
||||
Reference in New Issue
Block a user