| 1816 | } |
| 1817 | |
| 1818 | static 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(...) |
| 1863 | static cgltf_result ResolveBuffers(const cgltf_options* options, cgltf_data* data, const char* gltf_path) |
no test coverage detected