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

Function WriteMesh

IO/Geometry/vtkGLTFWriter.cxx:453–717  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

451}
452
453void WriteMesh(nlohmann::json& accessors, nlohmann::json& buffers, nlohmann::json& bufferViews,
454 nlohmann::json& meshes, nlohmann::json& nodes, vtkPolyData* pd, const char* fileName,
455 bool inlineData, bool saveNormal, bool saveBatchId, bool saveActivePointColor,
456 bool structuralMetadataExtension, ostream& output, bool binary, size_t* currentBufferOffset)
457{
458 vtkNew<vtkTriangleFilter> trif;
459 trif->SetInputData(pd);
460 trif->Update();
461 vtkPolyData* tris = trif->GetOutput();
462
463 // write the point locations
464 size_t pointAccessor = 0;
465 {
466 vtkDataArray* da = tris->GetPoints()->GetData();
467 WriteBufferAndView(
468 da, fileName, inlineData, buffers, bufferViews, binary, output, currentBufferOffset);
469 // write the accessor
470 nlohmann::json acc;
471 acc["bufferView"] = bufferViews.size() - 1;
472 acc["byteOffset"] = 0;
473 acc["type"] = "VEC3";
474 acc["componentType"] = GL_FLOAT;
475 acc["count"] = da->GetNumberOfTuples();
476 double range[6];
477 tris->GetPoints()->GetBounds(range);
478 nlohmann::json mins;
479 mins.emplace_back(range[0]);
480 mins.emplace_back(range[2]);
481 mins.emplace_back(range[4]);
482 nlohmann::json maxs;
483 maxs.emplace_back(range[1]);
484 maxs.emplace_back(range[3]);
485 maxs.emplace_back(range[5]);
486 acc["min"] = mins;
487 acc["max"] = maxs;
488 pointAccessor = accessors.size();
489 accessors.emplace_back(acc);
490 }
491
492 std::vector<vtkDataArray*> arraysToSave;
493 vtkNew<vtkFloatArray> normals;
494 vtkNew<vtkUnsignedCharArray> ucColor0;
495 vtkNew<vtkUnsignedShortArray> usColor0;
496 vtkNew<vtkFloatArray> fColor0;
497 if (saveBatchId)
498 {
499 vtkDataArray* a;
500 if ((a = pd->GetPointData()->GetArray("_BATCHID")))
501 {
502 arraysToSave.push_back(a);
503 }
504 }
505 if (saveNormal)
506 {
507 vtkDataArray* a = pd->GetPointData()->GetNormals();
508 if (a)
509 {
510 normals->ShallowCopy(a);

Callers 1

Calls 15

WriteBufferAndViewFunction · 0.85
GetGLTypeFunction · 0.85
FlipYTCoordsFunction · 0.85
WriteCellBufferAndViewFunction · 0.85
GetVertsMethod · 0.80
GetPolysMethod · 0.80
to_stringFunction · 0.50
SetInputDataMethod · 0.45
UpdateMethod · 0.45
GetOutputMethod · 0.45
GetDataMethod · 0.45
GetPointsMethod · 0.45

Tested by

no test coverage detected