| 541 | } |
| 542 | |
| 543 | void vtkGLTFExporter::WriteToStream(ostream& output) |
| 544 | { |
| 545 | nlohmann::json cameras; |
| 546 | nlohmann::json bufferViews; |
| 547 | nlohmann::json buffers; |
| 548 | nlohmann::json accessors; |
| 549 | nlohmann::json nodes; |
| 550 | nlohmann::json meshes; |
| 551 | nlohmann::json textures; |
| 552 | nlohmann::json images; |
| 553 | nlohmann::json samplers; |
| 554 | nlohmann::json materials; |
| 555 | |
| 556 | std::vector<size_t> topNodes; |
| 557 | |
| 558 | // support sharing texture maps |
| 559 | std::map<vtkUnsignedCharArray*, size_t> textureMap; |
| 560 | |
| 561 | for (auto ren : vtk::Range(this->RenderWindow->GetRenderers())) |
| 562 | { |
| 563 | if (this->ActiveRenderer && ren != this->ActiveRenderer) |
| 564 | { |
| 565 | // If ActiveRenderer is specified then ignore all other renderers |
| 566 | continue; |
| 567 | } |
| 568 | if (!ren->GetDraw()) |
| 569 | { |
| 570 | continue; |
| 571 | } |
| 572 | |
| 573 | // setup the camera data in case we need to use it later |
| 574 | // the glTF "nodes" list stores global transformations for objects in the |
| 575 | // scene, so we need to invert the ModelViewTransformMatrix of the camera |
| 576 | // (by a copy, to avoid mutating the renderer's camera) |
| 577 | nlohmann::json anode; |
| 578 | anode["camera"] = cameras.size(); // camera node |
| 579 | vtkMatrix4x4* mat = ren->GetActiveCamera()->GetModelViewTransformMatrix(); |
| 580 | vtkNew<vtkMatrix4x4> inv; |
| 581 | inv->DeepCopy(mat); |
| 582 | inv->Invert(); |
| 583 | for (int i = 0; i < 4; ++i) |
| 584 | { |
| 585 | for (int j = 0; j < 4; ++j) |
| 586 | { |
| 587 | anode["matrix"].emplace_back(inv->GetElement(j, i)); |
| 588 | } |
| 589 | } |
| 590 | anode["name"] = "Camera Node"; |
| 591 | |
| 592 | // setup renderer group node |
| 593 | nlohmann::json rendererNode; |
| 594 | rendererNode["name"] = "Renderer Node"; |
| 595 | |
| 596 | vtkPropCollection* pc; |
| 597 | vtkProp* aProp; |
| 598 | pc = ren->GetViewProps(); |
| 599 | vtkCollectionSimpleIterator pit; |
| 600 | bool foundVisibleProp = false; |
no test coverage detected