From 963b33ac4077d458fa305a828ebe96ddc2b88be4 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Mon, 13 Oct 2025 12:42:32 -0700 Subject: [PATCH] GLTF: Enforce `STEP` interpolation for integer and boolean animations --- modules/gltf/gltf_document.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 7ea1fec1195..90002703853 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -8271,7 +8271,20 @@ void GLTFDocument::_convert_animation(Ref p_state, AnimationPlayer *p if (obj_model_prop.is_valid() && obj_model_prop->has_json_pointers()) { // Insert the property track into the KHR_animation_pointer pointer tracks. GLTFAnimation::Channel channel; - channel.interpolation = gltf_interpolation; + // Animation samplers used with `int` or `bool` Object Model Data Types **MUST** use `STEP` interpolation. + // https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_animation_pointer + switch (obj_model_prop->get_object_model_type()) { + case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_BOOL: + case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_INT: { + channel.interpolation = GLTFAnimation::INTERP_STEP; + if (gltf_interpolation != GLTFAnimation::INTERP_STEP) { + WARN_PRINT(vformat("glTF export: Animation track %d on property %s is animating an int or bool, so it MUST use STEP interpolation (Godot \"Nearest\"), but the track in the Godot AnimationPlayer is using a different interpolation. Forcing STEP interpolation. Correct this track's interpolation in the source AnimationPlayer to avoid this warning.", track_index, String(track_path))); + } + } break; + default: { + channel.interpolation = gltf_interpolation; + } break; + } channel.times = times; channel.values.resize(anim_key_count); // If using an expression, determine the base instance to pass to the expression.