Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static _CreateNodeAnimation(babylonTransformNode: TransformNode, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData> {
const inputs: number[] = [];
const outputs: number[][] = [];
const keyFrames = animation.getKeys();
const minMaxKeyFrames = _GLTFAnimation.calculateMinMaxKeyFrames(keyFrames);
const interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);
const frameDelta = minMaxKeyFrames.max - minMaxKeyFrames.min;
const interpolation = interpolationOrBake.interpolationType;
const shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;
if (shouldBakeAnimation) {
_GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
}
else {
if (interpolation === AnimationSamplerInterpolation.LINEAR || interpolation === AnimationSamplerInterpolation.STEP) {
_GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
}
else if (interpolation === AnimationSamplerInterpolation.CUBICSPLINE) {
_GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
}
else {
_GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
}
}
if (inputs.length && outputs.length) {
const result: _IAnimationData = {
inputs: inputs,
outputs: outputs,
samplerInterpolation: interpolation,
public static _CreateNodeAnimation(babylonTransformNode: TransformNode, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean, animationSampleRate: number): Nullable<_IAnimationData> {
const inputs: number[] = [];
const outputs: number[][] = [];
const keyFrames = animation.getKeys();
const minMaxKeyFrames = _GLTFAnimation.calculateMinMaxKeyFrames(keyFrames);
const interpolationOrBake = _GLTFAnimation._DeduceInterpolation(keyFrames, animationChannelTargetPath, useQuaternion);
const frameDelta = minMaxKeyFrames.max - minMaxKeyFrames.min;
const interpolation = interpolationOrBake.interpolationType;
const shouldBakeAnimation = interpolationOrBake.shouldBakeAnimation;
if (shouldBakeAnimation) {
_GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
}
else {
if (interpolation === AnimationSamplerInterpolation.LINEAR || interpolation === AnimationSamplerInterpolation.STEP) {
_GLTFAnimation._CreateLinearOrStepAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
}
else if (interpolation === AnimationSamplerInterpolation.CUBICSPLINE) {
_GLTFAnimation._CreateCubicSplineAnimation(babylonTransformNode, animation, animationChannelTargetPath, frameDelta, inputs, outputs, convertToRightHandedSystem, useQuaternion);
}
else {
_GLTFAnimation._CreateBakedAnimation(babylonTransformNode, animation, animationChannelTargetPath, minMaxKeyFrames.min, minMaxKeyFrames.max, animation.framePerSecond, animationSampleRate, inputs, outputs, minMaxKeyFrames, convertToRightHandedSystem, useQuaternion);
}
}
if (inputs.length && outputs.length) {
const result: _IAnimationData = {
inputs: inputs,
outputs: outputs,
samplerInterpolation: interpolation,
else {
interpolationType = AnimationSamplerInterpolation.CUBICSPLINE;
}
}
else {
if (interpolationType) {
if (interpolationType === AnimationSamplerInterpolation.CUBICSPLINE ||
(key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP) && interpolationType !== AnimationSamplerInterpolation.STEP)) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
shouldBakeAnimation = true;
break;
}
}
else {
if (key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP)) {
interpolationType = AnimationSamplerInterpolation.STEP;
}
else {
interpolationType = AnimationSamplerInterpolation.LINEAR;
}
}
}
}
if (!interpolationType) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
}
return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };
}
if (key.inTangent || key.outTangent) {
if (interpolationType) {
if (interpolationType !== AnimationSamplerInterpolation.CUBICSPLINE) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
shouldBakeAnimation = true;
break;
}
}
else {
interpolationType = AnimationSamplerInterpolation.CUBICSPLINE;
}
}
else {
if (interpolationType) {
if (interpolationType === AnimationSamplerInterpolation.CUBICSPLINE ||
(key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP) && interpolationType !== AnimationSamplerInterpolation.STEP)) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
shouldBakeAnimation = true;
break;
}
}
else {
if (key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP)) {
interpolationType = AnimationSamplerInterpolation.STEP;
}
else {
interpolationType = AnimationSamplerInterpolation.LINEAR;
}
}
}
}
if (!interpolationType) {
if (key.inTangent || key.outTangent) {
if (interpolationType) {
if (interpolationType !== AnimationSamplerInterpolation.CUBICSPLINE) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
shouldBakeAnimation = true;
break;
}
}
else {
interpolationType = AnimationSamplerInterpolation.CUBICSPLINE;
}
}
else {
if (interpolationType) {
if (interpolationType === AnimationSamplerInterpolation.CUBICSPLINE ||
(key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP) && interpolationType !== AnimationSamplerInterpolation.STEP)) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
shouldBakeAnimation = true;
break;
}
}
else {
if (key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP)) {
interpolationType = AnimationSamplerInterpolation.STEP;
}
else {
interpolationType = AnimationSamplerInterpolation.LINEAR;
}
}
}
}
if (!interpolationType) {
}
case "influence": {
getNextOutputValue = () => {
const value = new Array(targetNode._numMorphTargets!);
for (let i = 0; i < targetNode._numMorphTargets!; i++) {
value[i] = data.output[outputBufferOffset++];
}
return value;
};
break;
}
}
let getNextKey: (frameIndex: number) => IAnimationKey;
switch (data.interpolation) {
case AnimationSamplerInterpolation.STEP: {
getNextKey = (frameIndex) => ({
frame: data.input[frameIndex],
value: getNextOutputValue(),
interpolation: AnimationKeyInterpolation.STEP
});
break;
}
case AnimationSamplerInterpolation.LINEAR: {
getNextKey = (frameIndex) => ({
frame: data.input[frameIndex],
value: getNextOutputValue()
});
break;
}
case AnimationSamplerInterpolation.CUBICSPLINE: {
getNextKey = (frameIndex) => ({
private _loadAnimationSamplerAsync(context: string, sampler: IAnimationSampler): Promise<_IAnimationSamplerData> {
if (sampler._data) {
return sampler._data;
}
const interpolation = sampler.interpolation || AnimationSamplerInterpolation.LINEAR;
switch (interpolation) {
case AnimationSamplerInterpolation.STEP:
case AnimationSamplerInterpolation.LINEAR:
case AnimationSamplerInterpolation.CUBICSPLINE: {
break;
}
default: {
throw new Error(`${context}/interpolation: Invalid value (${sampler.interpolation})`);
}
}
const inputAccessor = ArrayItem.Get(`${context}/input`, this._gltf.accessors, sampler.input);
const outputAccessor = ArrayItem.Get(`${context}/output`, this._gltf.accessors, sampler.output);
sampler._data = Promise.all([
this._loadFloatAccessorAsync(`/accessors/${inputAccessor.index}`, inputAccessor),
this._loadFloatAccessorAsync(`/accessors/${outputAccessor.index}`, outputAccessor)
]).then(([inputData, outputData]) => {
return {
else {
interpolationType = AnimationSamplerInterpolation.CUBICSPLINE;
}
}
else {
if (interpolationType) {
if (interpolationType === AnimationSamplerInterpolation.CUBICSPLINE ||
(key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP) && interpolationType !== AnimationSamplerInterpolation.STEP)) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
shouldBakeAnimation = true;
break;
}
}
else {
if (key.interpolation && (key.interpolation === AnimationKeyInterpolation.STEP)) {
interpolationType = AnimationSamplerInterpolation.STEP;
}
else {
interpolationType = AnimationSamplerInterpolation.LINEAR;
}
}
}
}
if (!interpolationType) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
}
return { interpolationType: interpolationType, shouldBakeAnimation: shouldBakeAnimation };
}