Skip to content

Commit

Permalink
Use proper type for scratch variables
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl authored and pupitetris committed Mar 4, 2024
1 parent d7c63a9 commit ba075e1
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/engine/Source/Scene/Model/ModelAnimationChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ function createSplines(times, points, interpolation, path, count) {
return splines;
}

let scratchVariable;
let scratchCartesian3;
let scratchQuaternion;

function initialize(runtimeChannel) {
const channel = runtimeChannel._channel;
Expand All @@ -240,10 +241,10 @@ function initialize(runtimeChannel) {
switch (path) {
case AnimatedPropertyType.TRANSLATION:
case AnimatedPropertyType.SCALE:
scratchVariable = new Cartesian3();
scratchCartesian3 = new Cartesian3();
break;
case AnimatedPropertyType.ROTATION:
scratchVariable = new Quaternion();
scratchQuaternion = new Quaternion();
break;
case AnimatedPropertyType.WEIGHTS:
// This is unused when setting a node's morph weights.
Expand Down Expand Up @@ -286,7 +287,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 ba075e1

Please sign in to comment.