diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 6f9295c94b9..c36b8bddf48 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -3764,9 +3764,10 @@ Error GLTFDocument::_serialize_animations(Ref p_state) { Dictionary sampler; sampler["input"] = GLTFAccessor::encode_new_accessor_from_float64s(p_state, pointer_track.times); sampler["interpolation"] = interpolation_to_string(pointer_track.interpolation); + GLTFAccessor::GLTFComponentType component_type = obj_model_prop->get_component_type(pointer_track.values); // TODO: This can be made faster after this pull request is merged: https://github.com/godotengine/godot/pull/109003 Array values_arr = GLTFTemplateConvert::to_array(pointer_track.values); - sampler["output"] = GLTFAccessor::encode_new_accessor_from_variants(p_state, values_arr, obj_model_prop->get_variant_type(), obj_model_prop->get_accessor_type()); + sampler["output"] = GLTFAccessor::encode_new_accessor_from_variants(p_state, values_arr, obj_model_prop->get_variant_type(), obj_model_prop->get_accessor_type(), component_type); samplers.push_back(sampler); } } diff --git a/modules/gltf/structures/gltf_object_model_property.cpp b/modules/gltf/structures/gltf_object_model_property.cpp index 4b6748acbb8..6e2c08b4eaa 100644 --- a/modules/gltf/structures/gltf_object_model_property.cpp +++ b/modules/gltf/structures/gltf_object_model_property.cpp @@ -103,6 +103,25 @@ GLTFAccessor::GLTFAccessorType GLTFObjectModelProperty::get_accessor_type() cons } } +GLTFAccessor::GLTFComponentType GLTFObjectModelProperty::get_component_type(const Vector &p_values) const { + switch (object_model_type) { + case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_BOOL: { + return GLTFAccessor::COMPONENT_TYPE_UNSIGNED_BYTE; + } break; + case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_INT: { + PackedInt64Array int_values; + for (int i = 0; i < p_values.size(); i++) { + int_values.append(p_values[i]); + } + return GLTFAccessor::get_minimal_integer_component_type_from_ints(int_values); + } break; + default: { + // The base glTF specification only supports 32-bit float accessors for floating point data. + return GLTFAccessor::COMPONENT_TYPE_SINGLE_FLOAT; + } break; + } +} + Ref GLTFObjectModelProperty::get_gltf_to_godot_expression() const { return gltf_to_godot_expr; } diff --git a/modules/gltf/structures/gltf_object_model_property.h b/modules/gltf/structures/gltf_object_model_property.h index 02ea46210e3..04162650f68 100644 --- a/modules/gltf/structures/gltf_object_model_property.h +++ b/modules/gltf/structures/gltf_object_model_property.h @@ -71,6 +71,7 @@ public: void append_path_to_property(const NodePath &p_node_path, const StringName &p_prop_name); GLTFAccessor::GLTFAccessorType get_accessor_type() const; + GLTFAccessor::GLTFComponentType get_component_type(const Vector &p_values) const; Ref get_gltf_to_godot_expression() const; void set_gltf_to_godot_expression(const Ref &p_gltf_to_godot_expr);