Skip to content

Commit

Permalink
Merge pull request #2407 from KhronosGroup/fix_2301_armature_obj_keep
Browse files Browse the repository at this point in the history
Fix #2301 - fix armature object keep channel option
  • Loading branch information
julienduroure authored Nov 28, 2024
2 parents 985d436 + 2f4d9a1 commit 100b079
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,29 @@ def gather_armature_sampled_channels(armature_uuid, blender_action_name,
if channel is not None:
channels.append(channel)

bake_interpolation = get_gltf_interpolation("LINEAR")
# Retrieve animation on armature object itself, if any
# If armature is baked (no animation of armature), need to use all channels
if blender_action_name == armature_uuid or export_settings['gltf_animation_mode'] in ["SCENE", "NLA_TRACKS"]:
armature_channels = []
# If armature is baked (no animation of armature), need to use all channels
armature_channels = [
["location", bake_interpolation],
["rotation_quaternion", bake_interpolation],
["scale", bake_interpolation]
]
animated_channels = []
else:
# The armature has some channel(s) animated, checking which one(s)
armature_channels = __gather_armature_object_channel(
armature_uuid, bpy.data.actions[blender_action_name], export_settings)
animated_channels = armature_channels

for p in ["location", "rotation_quaternion", "scale"]:
for (p, i) in armature_channels:
armature_channel = gather_sampled_object_channel(
armature_uuid,
p,
blender_action_name,
p in [a[0] for a in armature_channels],
[c[1] for c in armature_channels if c[0] == p][0] if p in [a[0] for a in armature_channels] else "LINEAR",
p in [a[0] for a in animated_channels],
[c[1] for c in animated_channels if c[0] == p][0] if p in [a[0] for a in animated_channels] else bake_interpolation,
export_settings
)

Expand Down
16 changes: 4 additions & 12 deletions tests/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1492,16 +1492,12 @@ describe('Exporter', function () {
const arma2_scale_channel = anim_armature2.channels.filter(a => asset.nodes[a.target.node].name === armature2_node.name).filter(a => a.target.path === "scale")[0];

const arma2_translation_sampler = anim_armature2.samplers[arma2_translation_channel.sampler];
const arma2_rotation_sampler = anim_armature2.samplers[arma2_rotation_channel.sampler];
const arma2_scale_sampler = anim_armature2.samplers[arma2_scale_channel.sampler];
assert.ok(arma2_rotation_channel == null);
assert.ok(arma2_scale_channel == null);

assert.strictEqual(arma2_translation_sampler.interpolation, "LINEAR");
assert.strictEqual(arma2_rotation_sampler.interpolation, "STEP");
assert.strictEqual(arma2_scale_sampler.interpolation, "STEP");

assert.strictEqual(asset.accessors[arma2_translation_sampler.input].count, 1);
assert.strictEqual(asset.accessors[arma2_rotation_sampler.input].count, 1);
assert.strictEqual(asset.accessors[arma2_scale_sampler.input].count, 1);

const anim_sphere = asset.animations.filter(a => a.name === 'Sphere.001Action')[0];

Expand Down Expand Up @@ -1835,16 +1831,12 @@ describe('Exporter', function () {
const arma2_scale_channel = anim_armature2.channels.filter(a => asset.nodes[a.target.node].name === armature2_node.name).filter(a => a.target.path === "scale")[0];

const arma2_translation_sampler = anim_armature2.samplers[arma2_translation_channel.sampler];
const arma2_rotation_sampler = anim_armature2.samplers[arma2_rotation_channel.sampler];
const arma2_scale_sampler = anim_armature2.samplers[arma2_scale_channel.sampler];
assert.ok(arma2_rotation_channel == null);
assert.ok(arma2_scale_channel == null);

assert.strictEqual(arma2_translation_sampler.interpolation, "LINEAR");
assert.strictEqual(arma2_rotation_sampler.interpolation, "STEP");
assert.strictEqual(arma2_scale_sampler.interpolation, "STEP");

assert.strictEqual(asset.accessors[arma2_translation_sampler.input].count, 1);
assert.strictEqual(asset.accessors[arma2_rotation_sampler.input].count, 1);
assert.strictEqual(asset.accessors[arma2_scale_sampler.input].count, 1);

const anim_sphere = asset.animations.filter(a => a.name === 'Sphere.001Action')[0];

Expand Down

0 comments on commit 100b079

Please sign in to comment.