From c7bc88bce43274dc0dac1c2fa5d74edef7bc0c0d Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 31 Jan 2024 22:16:36 -0600 Subject: [PATCH] chore(model): avoid creating unnecessary texture weight tracks --- src/lib/model/ModelManager.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/lib/model/ModelManager.ts b/src/lib/model/ModelManager.ts index 372f176..342fc5a 100644 --- a/src/lib/model/ModelManager.ts +++ b/src/lib/model/ModelManager.ts @@ -219,13 +219,21 @@ class ModelManager { const animator = new ModelAnimator(spec.loops, spec.sequences, spec.skinned ? spec.bones : []); - for (const [index, textureWeight] of spec.textureWeights.entries()) { - animator.registerTrack( - { state: 'textureWeights', index }, - textureWeight.weightTrack, - THREE.NumberKeyframeTrack, - (value: number) => value / 0x7fff, - ); + const hasTextureWeights = + spec.textureWeights.length > 1 || + spec.textureWeights[0]?.weightTrack.sequenceKeys.length > 1 || + spec.textureWeights[0]?.weightTrack.sequenceKeys[0].length > 1 || + spec.textureWeights[0]?.weightTrack.sequenceKeys[0][0] !== 0x7fff; + + if (hasTextureWeights) { + for (const [index, textureWeight] of spec.textureWeights.entries()) { + animator.registerTrack( + { state: 'textureWeights', index }, + textureWeight.weightTrack, + THREE.NumberKeyframeTrack, + (value: number) => value / 0x7fff, + ); + } } for (const [index, textureTransform] of spec.textureTransforms.entries()) {