| 411 | } |
| 412 | |
| 413 | void GltfSerializer::finalize() { |
| 414 | // separate z up |
| 415 | if (settings_.get<ifcopenshell::geometry::settings::SeparateZUpNode>().get()) { |
| 416 | z_up_transform_ = json::object(); |
| 417 | (*z_up_transform_)["name"] = "Z_UP"; |
| 418 | static const std::array<double, 16> z_up_matrix = { |
| 419 | 1, 0, 0, 0, |
| 420 | 0, 0, -1, 0, |
| 421 | 0, 1, 0, 0, |
| 422 | 0, 0, 0, 1}; |
| 423 | (*z_up_transform_)["matrix"] = z_up_matrix; |
| 424 | (*z_up_transform_)["children"] = roots_; |
| 425 | json_["nodes"].push_back(*z_up_transform_); |
| 426 | } |
| 427 | |
| 428 | if (north_rotation_) { |
| 429 | (*north_rotation_)["children"] = roots_; |
| 430 | } |
| 431 | |
| 432 | if (ecef_transform_) { |
| 433 | (*ecef_transform_)["children"] = roots_; |
| 434 | } |
| 435 | |
| 436 | if (z_up_transform_) { |
| 437 | (*ecef_transform_)["children"] = roots_; |
| 438 | } |
| 439 | |
| 440 | tmp_fstream1_.close(); |
| 441 | tmp_fstream2_.close(); |
| 442 | |
| 443 | std::vector<char> binary_contents; |
| 444 | // nb: uint32_t is the max buffer size in glTF |
| 445 | uint32_t indices_length, binary_length; |
| 446 | { |
| 447 | std::ifstream ifs(IfcUtil::path::from_utf8(tmp_filename1_).c_str(), std::ios::binary); |
| 448 | ifs.ignore(std::numeric_limits<std::streamsize>::max()); |
| 449 | indices_length = ifs.gcount(); |
| 450 | } |
| 451 | { |
| 452 | std::ifstream ifs(IfcUtil::path::from_utf8(tmp_filename2_).c_str(), std::ios::binary); |
| 453 | ifs.ignore(std::numeric_limits<std::streamsize>::max()); |
| 454 | binary_length = indices_length + ifs.gcount(); |
| 455 | } |
| 456 | |
| 457 | json scene_0; |
| 458 | if (geometry_settings().get<ifcopenshell::geometry::settings::UseElementHierarchy>().get()) { |
| 459 | scene_0["nodes"] = roots_; |
| 460 | } else if (north_rotation_ || ecef_transform_ || z_up_transform_) { |
| 461 | scene_0["nodes"] = std::array<size_t, 1>{json_["nodes"].size() - 1}; |
| 462 | } else { |
| 463 | scene_0["nodes"] = node_array_; |
| 464 | } |
| 465 | json_["scenes"].push_back(scene_0); |
| 466 | |
| 467 | //The generated glb file will contain the indices buffer followed by the vertices buffer. |
| 468 | //Therefore once we know the size of the indices buffer, we update our vertices buffer |
| 469 | //to have an offset equal to the size of the indices buffer. |
| 470 | for (auto &n : json_["bufferViews"]) { |