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

Function LoadAnimations

engine/modelc/src/modelimporter_gltf.cpp:1818–1860  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1816}
1817
1818static void LoadAnimations(Scene* scene, cgltf_data* gltf_data)
1819{
1820 if (gltf_data->animations_count == 0)
1821 return;
1822
1823 InitSize(scene->m_Animations, gltf_data->animations_count, gltf_data->animations_count);
1824
1825 // first, count number of animated nodes we have
1826 for (uint32_t a = 0; a < gltf_data->animations_count; ++a)
1827 {
1828 cgltf_animation* gltf_animation = &gltf_data->animations[a];
1829 Animation* animation = &scene->m_Animations[a];
1830
1831 animation->m_Name = DuplicateObjectName(gltf_animation);
1832
1833 // Here we want to create a many individual tracks for different bones (name.type): "a.rot", "b.rot", "a.pos", "b.scale"...
1834 // into a list of tracks that holds all 3 types: [a: {rot, pos, scale}, b: {rot, pos, scale}...]
1835 dmHashTable64<uint32_t> node_name_to_index;
1836 uint32_t node_animations_count = CountAnimatedNodes(scene, gltf_data, gltf_animation, node_name_to_index);
1837
1838 InitSize(animation->m_NodeAnimations, node_animations_count, node_animations_count);
1839
1840 animation->m_Duration = 0.0f;
1841
1842 for (size_t i = 0; i < gltf_animation->channels_count; ++i)
1843 {
1844 cgltf_animation_channel* channel = &gltf_animation->channels[i];
1845
1846 Node* node = TranslateNode(channel->target_node, gltf_data, scene);
1847 dmhash_t node_name_hash = node->m_NameHash;
1848
1849 uint32_t* node_index = node_name_to_index.Get(node_name_hash);
1850 assert(node_index != 0);
1851
1852 NodeAnimation* node_animation = &animation->m_NodeAnimations[*node_index];
1853 node_animation->m_Node = node;
1854
1855 LoadChannel(node_animation, channel);
1856
1857 animation->m_Duration = dmMath::Max(animation->m_Duration, node_animation->m_EndTime);
1858 }
1859 }
1860}
1861
1862// Based on cgltf.h: cgltf_load_buffers(...)
1863static cgltf_result ResolveBuffers(const cgltf_options* options, cgltf_data* data, const char* gltf_path)

Callers 1

LoadSceneFunction · 0.85

Calls 8

InitSizeFunction · 0.85
DuplicateObjectNameFunction · 0.85
CountAnimatedNodesFunction · 0.85
TranslateNodeFunction · 0.85
LoadChannelFunction · 0.85
assertFunction · 0.50
MaxFunction · 0.50
GetMethod · 0.45

Tested by

no test coverage detected