MCPcopy Create free account
hub / github.com/Kitware/VTK / WriteToStream

Method WriteToStream

IO/Export/vtkGLTFExporter.cxx:543–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

541}
542
543void 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;

Callers 2

WriteToStringMethod · 0.95
WriteDataMethod · 0.95

Calls 15

GetRenderersMethod · 0.80
GetActiveCameraMethod · 0.80
GetNextPropMethod · 0.80
GetNextActorMethod · 0.80
GetLastNodeMethod · 0.80
GetMapperMethod · 0.80
GetInputDataObjectMethod · 0.80
findPolyDataFunction · 0.70
WriteMeshFunction · 0.70
WriteTextureFunction · 0.70
WriteMaterialFunction · 0.70
WriteCameraFunction · 0.70

Tested by

no test coverage detected