MCPcopy Create free account
hub / github.com/defold/defold / LoadNodes

Function LoadNodes

engine/modelc/src/modelimporter_gltf.cpp:546–618  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544}
545
546static void LoadNodes(Scene* scene, cgltf_data* gltf_data)
547{
548 // We allocate one extra node, in case we need it for later
549 // In the case we generate a root bone, we want a valid node for it.
550 InitSize(scene->m_Nodes, gltf_data->nodes_count+1, gltf_data->nodes_count);
551
552 for (size_t i = 0; i < gltf_data->nodes_count; ++i)
553 {
554 cgltf_node* gltf_node = &gltf_data->nodes[i];
555
556 Node* node = &scene->m_Nodes[i];
557 node->m_Name = DuplicateObjectName(gltf_node);
558 node->m_NameHash = dmHashString64(node->m_Name);
559 node->m_Index = i;
560
561 // We link them together later
562 // node->m_Model = ...
563
564 dmVMath::Vector3 scale = dmVMath::Vector3(1,1,1);
565 dmVMath::Vector3 translation = dmVMath::Vector3(0,0,0);
566 dmVMath::Quat rotation = dmVMath::Quat(0,0,0,1);
567
568 node->m_Skin = 0;
569 if (gltf_node->skin)
570 {
571 node->m_Skin = FindSkin(scene, gltf_data, gltf_node->skin);
572 }
573
574 if (gltf_node->has_translation)
575 translation = dmVMath::Vector3(gltf_node->translation[0], gltf_node->translation[1], gltf_node->translation[2]);
576 if (gltf_node->has_scale)
577 scale = dmVMath::Vector3(gltf_node->scale[0], gltf_node->scale[1], gltf_node->scale[2]);
578 if (gltf_node->has_rotation)
579 rotation = dmVMath::Quat(gltf_node->rotation[0], gltf_node->rotation[1], gltf_node->rotation[2], gltf_node->rotation[3]);
580
581 if (gltf_node->has_matrix)
582 {
583 FromMatrix4x4(gltf_node->matrix, node->m_Local);
584 }
585 else
586 {
587 FromTransform(dmTransform::Transform(translation, rotation, scale), node->m_Local);
588 }
589 }
590
591 // find all the parents and all the children
592
593 for (size_t i = 0; i < gltf_data->nodes_count; ++i)
594 {
595 cgltf_node* gltf_node = &gltf_data->nodes[i];
596 Node* node = &scene->m_Nodes[i];
597
598 node->m_Parent = gltf_node->parent ? TranslateNode(gltf_node->parent, gltf_data, scene) : 0;
599
600 InitSize(node->m_Children, gltf_node->children_count, gltf_node->children_count);
601 for (uint32_t c = 0; c < gltf_node->children_count; ++c)
602 node->m_Children[c] = TranslateNode(gltf_node->children[c], gltf_data, scene);
603 }

Callers 1

LoadSceneFunction · 0.85

Calls 12

InitSizeFunction · 0.85
DuplicateObjectNameFunction · 0.85
FindSkinFunction · 0.85
TranslateNodeFunction · 0.85
UpdateWorldTransformsFunction · 0.85
Vector3Class · 0.70
QuatClass · 0.70
TransformClass · 0.70
SizeMethod · 0.45
FullMethod · 0.45
OffsetCapacityMethod · 0.45
PushMethod · 0.45

Tested by

no test coverage detected