Skip to content

Commit

Permalink
Merge pull request #11700 from CesiumGS/consistent-scratch-variable-type
Browse files Browse the repository at this point in the history
Use proper type for scratch variables
  • Loading branch information
ggetz committed Jan 12, 2024
2 parents 2602d03 + 55d84c5 commit c7edfae
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions packages/engine/Source/Scene/Model/ModelAnimationChannel.js
Expand Up @@ -215,7 +215,8 @@ function createSplines(times, points, interpolation, path, count) {
return splines;
}

let scratchVariable;
const scratchCartesian3 = new Cartesian3();
const scratchQuaternion = new Quaternion();

function initialize(runtimeChannel) {
const channel = runtimeChannel._channel;
Expand All @@ -236,19 +237,6 @@ function initialize(runtimeChannel) {

runtimeChannel._splines = splines;
runtimeChannel._path = path;

switch (path) {
case AnimatedPropertyType.TRANSLATION:
case AnimatedPropertyType.SCALE:
scratchVariable = new Cartesian3();
break;
case AnimatedPropertyType.ROTATION:
scratchVariable = new Quaternion();
break;
case AnimatedPropertyType.WEIGHTS:
// This is unused when setting a node's morph weights.
break;
}
}

/**
Expand Down Expand Up @@ -286,7 +274,20 @@ ModelAnimationChannel.prototype.animate = function (time) {
: spline.wrapTime(time);

// This sets the translate, rotate, and scale properties.
runtimeNode[path] = spline.evaluate(localAnimationTime, scratchVariable);
if (
path === AnimatedPropertyType.TRANSLATION ||
path === AnimatedPropertyType.SCALE
) {
runtimeNode[path] = spline.evaluate(
localAnimationTime,
scratchCartesian3
);
} else if (path === AnimatedPropertyType.ROTATION) {
runtimeNode[path] = spline.evaluate(
localAnimationTime,
scratchQuaternion
);
}
}
};

Expand Down

0 comments on commit c7edfae

Please sign in to comment.