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

Function LoadChannel

engine/modelc/src/modelimporter_gltf.cpp:1620–1791  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1618}
1619
1620static void LoadChannel(NodeAnimation* node_animation, cgltf_animation_channel* channel)
1621{
1622 cgltf_accessor* accessor_times = channel->sampler->input;
1623 cgltf_accessor* accessor = channel->sampler->output;
1624
1625 uint32_t key_count = accessor_times->count;
1626
1627 // 1 for 1xf32, 4 for 4xf32
1628 uint32_t num_components = (uint32_t)cgltf_num_components(accessor->type);
1629 // number of items per time step
1630 uint32_t num_items = accessor->count / key_count;
1631
1632 bool all_identical = true;
1633
1634 float time_min = FLT_MAX;
1635 float time_max = -FLT_MAX;
1636
1637 uint32_t num_values = num_items * num_components;
1638
1639 if (channel->target_path == cgltf_animation_path_type_weights)
1640 {
1641 // glTF stores one SCALAR accessor element per morph weight per key; cubic spline packs
1642 // (in-tangent, value, out-tangent) per weight. cgltf_accessor_read_float only reads
1643 // num_components floats from a single element — do not pass morph_count as element_size on SCALAR.
1644 if (key_count == 0 || accessor->count == 0)
1645 {
1646 return;
1647 }
1648
1649 const bool cubic = (channel->sampler->interpolation == cgltf_interpolation_type_cubic_spline);
1650 const uint32_t cubic_stride = cubic ? 3u : 1u;
1651
1652 Node* anim_node = node_animation->m_Node;
1653 uint32_t morph_count = 0;
1654 if (anim_node && anim_node->m_Model && anim_node->m_Model->m_Meshes.Size() > 0)
1655 {
1656 morph_count = anim_node->m_Model->m_Meshes[0].m_MorphTargets.Size();
1657 }
1658 if (morph_count == 0)
1659 {
1660 if (accessor->count % (key_count * cubic_stride) != 0)
1661 {
1662 return;
1663 }
1664 morph_count = (uint32_t)(accessor->count / (key_count * cubic_stride));
1665 }
1666 if (morph_count == 0)
1667 {
1668 return;
1669 }
1670
1671 const cgltf_size expected_out = (cgltf_size)key_count * (cgltf_size)morph_count * (cgltf_size)cubic_stride;
1672 if (accessor->count != expected_out)
1673 {
1674 dmLogWarning("GLTF morph weights animation output count %u does not match %u keys, %u morph targets, cubic=%d.",
1675 (unsigned)accessor->count, key_count, morph_count, cubic ? 1 : 0);
1676 }
1677

Callers 1

LoadAnimationsFunction · 0.85

Calls 8

cgltf_num_componentsFunction · 0.85
AreEqualFunction · 0.85
MinFunction · 0.85
MaxFunction · 0.50
SizeMethod · 0.45
SetCapacityMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected