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

Method BuildPolyDataFromSkin

IO/Geometry/vtkGLTFDocumentLoader.cxx:1285–1361  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

1283
1284//------------------------------------------------------------------------------
1285bool vtkGLTFDocumentLoader::BuildPolyDataFromSkin(Skin& skin)
1286{
1287 if (skin.Skeleton >= 0 && skin.Skeleton < static_cast<int>(this->InternalModel->Nodes.size()))
1288 {
1289 skin.Armature = vtkSmartPointer<vtkPolyData>::New();
1290
1291 vtkNew<vtkPoints> points;
1292 points->SetNumberOfPoints(skin.Joints.size());
1293
1294 vtkNew<vtkCellArray> vertices;
1295
1296 std::vector<int> nodeMapping(this->InternalModel->Nodes.size(), -1);
1297
1298 for (size_t i = 0; i < skin.Joints.size(); i++)
1299 {
1300 if (skin.Joints[i] >= static_cast<int>(nodeMapping.size()))
1301 {
1302 // invalid index
1303 return false;
1304 }
1305
1306 double p[3] = {};
1307
1308 auto trs = this->InternalModel->Nodes[skin.Joints[i]].GlobalTransform;
1309 if (trs)
1310 {
1311 p[0] = trs->GetElement(0, 3);
1312 p[1] = trs->GetElement(1, 3);
1313 p[2] = trs->GetElement(2, 3);
1314 }
1315
1316 points->SetPoint(i, p);
1317
1318 vtkIdType vId = i;
1319 vertices->InsertNextCell(1, &vId);
1320
1321 nodeMapping[skin.Joints[i]] = static_cast<int>(i);
1322 }
1323
1324 vtkNew<vtkCellArray> lines;
1325
1326 std::function<bool(int)> VisitJoint = [&](int nodeIndex)
1327 {
1328 const Node& node = this->InternalModel->Nodes[nodeIndex];
1329
1330 int mappedNode = nodeMapping[nodeIndex];
1331
1332 if (mappedNode == -1)
1333 {
1334 return false;
1335 }
1336
1337 for (int childIndex : node.Children)
1338 {
1339 int mappedChild = nodeMapping[childIndex];
1340
1341 if (mappedChild == -1)
1342 {

Callers 1

BuildModelVTKGeometryMethod · 0.95

Calls 8

SetVertsMethod · 0.80
SetLinesMethod · 0.80
NewFunction · 0.50
sizeMethod · 0.45
SetNumberOfPointsMethod · 0.45
SetPointMethod · 0.45
InsertNextCellMethod · 0.45
SetPointsMethod · 0.45

Tested by

no test coverage detected