Skip to content

Commit

Permalink
Rename ModelExperimentalAnimationChannel -> ModelAnimationChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
Janine Liu committed Jun 29, 2022
1 parent 34f5c78 commit 269dfd2
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ const AnimatedPropertyType = ModelComponents.AnimatedPropertyType;
* @param {ModelExperimentalAnimation} options.runtimeAnimation The runtime animation containing this channel.
* @param {ModelExperimentalNode} options.runtimeNode The runtime node that this channel will animate.
*
* @alias ModelExperimentalAnimationChannel
* @alias ModelAnimationChannel
* @constructor
*
* @private
*/
function ModelExperimentalAnimationChannel(options) {
function ModelAnimationChannel(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

const channel = options.channel;
Expand All @@ -52,11 +52,11 @@ function ModelExperimentalAnimationChannel(options) {
initialize(this);
}

Object.defineProperties(ModelExperimentalAnimationChannel.prototype, {
Object.defineProperties(ModelAnimationChannel.prototype, {
/**
* The glTF animation channel.
*
* @memberof ModelExperimentalAnimationChannel.prototype
* @memberof ModelAnimationChannel.prototype
*
* @type {ModelComponents.AnimationChannel}
* @readonly
Expand All @@ -72,7 +72,7 @@ Object.defineProperties(ModelExperimentalAnimationChannel.prototype, {
/**
* The runtime animation that owns this channel.
*
* @memberof ModelExperimentalAnimationChannel.prototype
* @memberof ModelAnimationChannel.prototype
*
* @type {ModelExperimentalAnimation}
* @readonly
Expand All @@ -88,7 +88,7 @@ Object.defineProperties(ModelExperimentalAnimationChannel.prototype, {
/**
* The runtime node that this channel animates.
*
* @memberof ModelExperimentalAnimationChannel.prototype
* @memberof ModelAnimationChannel.prototype
*
* @type {ModelExperimentalNode}
* @readonly
Expand All @@ -104,7 +104,7 @@ Object.defineProperties(ModelExperimentalAnimationChannel.prototype, {
/**
* The splines used to evaluate this animation channel.
*
* @memberof ModelExperimentalAnimationChannel.prototype
* @memberof ModelAnimationChannel.prototype
*
* @type {Spline[]}
* @readonly
Expand Down Expand Up @@ -171,45 +171,46 @@ function createSpline(times, points, interpolation, path) {
}

function createSplines(times, points, interpolation, path, count) {
if (path !== AnimatedPropertyType.WEIGHTS) {
const spline = createSpline(times, points, interpolation, path);
return [spline];
}

const splines = [];
if (path === AnimatedPropertyType.WEIGHTS) {
const pointsLength = points.length;
// Get the number of keyframes in each weight's output.
const outputLength = pointsLength / count;

// Iterate over the array using the number of morph targets in the model.
let targetIndex, i;
for (targetIndex = 0; targetIndex < count; targetIndex++) {
const output = new Array(outputLength);

// Weights are ordered such that they are keyframed in the order in which
// their targets appear the glTF. For example, the weights of three targets
// may appear as [w(0,0), w(0,1), w(0,2), w(1,0), w(1,1), w(1,2) ...],
// where i and j in w(i,j) are the time indices and target indices, respectively.

// However, for morph targets with cubic interpolation, the data is stored per
// keyframe in the order [a1, a2, ..., an, v1, v2, ... vn, b1, b2, ..., bn],
// where ai, vi, and bi are the in-tangent, property, and out-tangents of
// the ith morph target respectively.
let pointsIndex = targetIndex;
if (interpolation === InterpolationType.CUBICSPLINE) {
for (i = 0; i < outputLength; i += 3) {
output[i] = points[pointsIndex];
output[i + 1] = points[pointsIndex + count];
output[i + 2] = points[pointsIndex + 2 * count];
pointsIndex += count * 3;
}
} else {
for (i = 0; i < outputLength; i++) {
output[i] = points[pointsIndex];
pointsIndex += count;
}
const pointsLength = points.length;
// Get the number of keyframes in each weight's output.
const outputLength = pointsLength / count;

// Iterate over the array using the number of morph targets in the model.
let targetIndex, i;
for (targetIndex = 0; targetIndex < count; targetIndex++) {
const output = new Array(outputLength);

// Weights are ordered such that they are keyframed in the order in which
// their targets appear the glTF. For example, the weights of three targets
// may appear as [w(0,0), w(0,1), w(0,2), w(1,0), w(1,1), w(1,2) ...],
// where i and j in w(i,j) are the time indices and target indices, respectively.

// However, for morph targets with cubic interpolation, the data is stored per
// keyframe in the order [a1, a2, ..., an, v1, v2, ... vn, b1, b2, ..., bn],
// where ai, vi, and bi are the in-tangent, property, and out-tangents of
// the ith morph target respectively.
let pointsIndex = targetIndex;
if (interpolation === InterpolationType.CUBICSPLINE) {
for (i = 0; i < outputLength; i += 3) {
output[i] = points[pointsIndex];
output[i + 1] = points[pointsIndex + count];
output[i + 2] = points[pointsIndex + 2 * count];
pointsIndex += count * 3;
}
} else {
for (i = 0; i < outputLength; i++) {
output[i] = points[pointsIndex];
pointsIndex += count;
}

splines.push(createSpline(times, output, interpolation, path));
}
} else {
splines.push(createSpline(times, points, interpolation, path));

splines.push(createSpline(times, output, interpolation, path));
}

return splines;
Expand Down Expand Up @@ -258,7 +259,7 @@ function initialize(runtimeChannel) {
*
* @private
*/
ModelExperimentalAnimationChannel.prototype.animate = function (time) {
ModelAnimationChannel.prototype.animate = function (time) {
const splines = this._splines;
const path = this._path;
const model = this._runtimeAnimation.model;
Expand Down Expand Up @@ -289,4 +290,4 @@ ModelExperimentalAnimationChannel.prototype.animate = function (time) {
}
};

export default ModelExperimentalAnimationChannel;
export default ModelAnimationChannel;
6 changes: 3 additions & 3 deletions Source/Scene/ModelExperimental/ModelExperimentalAnimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Event from "../../Core/Event.js";
import JulianDate from "../../Core/JulianDate.js";
import ModelAnimationLoop from ".././ModelAnimationLoop.js";
import ModelAnimationState from ".././ModelAnimationState.js";
import ModelExperimentalAnimationChannel from "../ModelExperimental/ModelExperimentalAnimationChannel.js";
import ModelAnimationChannel from "./ModelAnimationChannel.js";

/**
* An active animation derived from a glTF asset. An active animation is an
Expand Down Expand Up @@ -162,7 +162,7 @@ Object.defineProperties(ModelExperimentalAnimation.prototype, {
*
* @memberof ModelExperimentalAnimation.prototype
*
* @type {ModelExperimentalAnimationChannel[]}
* @type {ModelAnimationChannel[]}
* @readonly
*
* @private
Expand Down Expand Up @@ -365,7 +365,7 @@ function initialize(runtimeAnimation) {
const nodeIndex = target.node.index;
const runtimeNode = sceneGraph._runtimeNodes[nodeIndex];

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: channel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
Matrix3,
Matrix4,
ModelComponents,
ModelExperimentalAnimationChannel,
ModelAnimationChannel,
ModelExperimentalNode,
SteppedSpline,
Quaternion,
QuaternionSpline,
} from "../../../Source/Cesium.js";

describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function () {
describe("Scene/ModelExperimental/ModelAnimationChannel", function () {
const AnimatedPropertyType = ModelComponents.AnimatedPropertyType;

const times = [0.0, 0.25, 0.5, 1.0];
Expand Down Expand Up @@ -90,7 +90,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (

it("throws for undefined channel", function () {
expect(function () {
return new ModelExperimentalAnimationChannel({
return new ModelAnimationChannel({
channel: undefined,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand All @@ -100,7 +100,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (

it("throws for undefined runtimeAnimation", function () {
expect(function () {
return new ModelExperimentalAnimationChannel({
return new ModelAnimationChannel({
channel: {},
runtimeAnimation: undefined,
runtimeNode: runtimeNode,
Expand All @@ -110,7 +110,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (

it("throws for undefined runtimeNode", function () {
expect(function () {
return new ModelExperimentalAnimationChannel({
return new ModelAnimationChannel({
channel: {},
runtimeAnimation: runtimeAnimation,
runtimeNode: undefined,
Expand All @@ -131,7 +131,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.TRANSLATION
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand All @@ -157,7 +157,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.TRANSLATION
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand All @@ -183,7 +183,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.ROTATION
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand All @@ -209,7 +209,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.SCALE
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -250,7 +250,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.TRANSLATION
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -288,7 +288,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.WEIGHTS
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -327,7 +327,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.WEIGHTS
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -364,7 +364,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.TRANSLATION
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -410,7 +410,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.ROTATION
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -466,7 +466,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.SCALE
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -510,7 +510,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.WEIGHTS
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -546,7 +546,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
AnimatedPropertyType.TRANSLATION
);

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: runtimeAnimation,
runtimeNode: runtimeNode,
Expand Down Expand Up @@ -593,7 +593,7 @@ describe("Scene/ModelExperimental/ModelExperimentalAnimationChannel", function (
},
};

const runtimeChannel = new ModelExperimentalAnimationChannel({
const runtimeChannel = new ModelAnimationChannel({
channel: mockChannel,
runtimeAnimation: wrappedRuntimeAnimation,
runtimeNode: runtimeNode,
Expand Down

0 comments on commit 269dfd2

Please sign in to comment.