Skip to content

Commit 963b33a

Browse files
committed
GLTF: Enforce STEP interpolation for integer and boolean animations
1 parent fc7065d commit 963b33a

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

modules/gltf/gltf_document.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8271,7 +8271,20 @@ void GLTFDocument::_convert_animation(Ref<GLTFState> p_state, AnimationPlayer *p
82718271
if (obj_model_prop.is_valid() && obj_model_prop->has_json_pointers()) {
82728272
// Insert the property track into the KHR_animation_pointer pointer tracks.
82738273
GLTFAnimation::Channel<Variant> channel;
8274-
channel.interpolation = gltf_interpolation;
8274+
// Animation samplers used with `int` or `bool` Object Model Data Types **MUST** use `STEP` interpolation.
8275+
// https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_animation_pointer
8276+
switch (obj_model_prop->get_object_model_type()) {
8277+
case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_BOOL:
8278+
case GLTFObjectModelProperty::GLTF_OBJECT_MODEL_TYPE_INT: {
8279+
channel.interpolation = GLTFAnimation::INTERP_STEP;
8280+
if (gltf_interpolation != GLTFAnimation::INTERP_STEP) {
8281+
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)));
8282+
}
8283+
} break;
8284+
default: {
8285+
channel.interpolation = gltf_interpolation;
8286+
} break;
8287+
}
82758288
channel.times = times;
82768289
channel.values.resize(anim_key_count);
82778290
// If using an expression, determine the base instance to pass to the expression.

0 commit comments

Comments
 (0)