Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
private static _DeduceInterpolation(keyFrames: IAnimationKey[], animationChannelTargetPath: AnimationChannelTargetPath, useQuaternion: boolean): { interpolationType: AnimationSamplerInterpolation, shouldBakeAnimation: boolean } {
let interpolationType: AnimationSamplerInterpolation | undefined;
let shouldBakeAnimation = false;
let key: IAnimationKey;
if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION && !useQuaternion) {
return { interpolationType: AnimationSamplerInterpolation.LINEAR, shouldBakeAnimation: true };
}
for (let i = 0, length = keyFrames.length; i < length; ++i) {
key = keyFrames[i];
if (key.inTangent || key.outTangent) {
if (interpolationType) {
if (interpolationType !== AnimationSamplerInterpolation.CUBICSPLINE) {
interpolationType = AnimationSamplerInterpolation.LINEAR;
shouldBakeAnimation = true;
break;
}
}
else {
interpolationType = AnimationSamplerInterpolation.CUBICSPLINE;
}
}
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 };
}
};
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) => ({
frame: data.input[frameIndex],
inTangent: getNextOutputValue(),
value: getNextOutputValue(),
outTangent: getNextOutputValue()
});
break;
}
}
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)
};
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) => ({
frame: data.input[frameIndex],
inTangent: getNextOutputValue(),
value: getNextOutputValue(),
outTangent: getNextOutputValue()
});
break;
}
}
private static _DeduceInterpolation(keyFrames: IAnimationKey[], animationChannelTargetPath: AnimationChannelTargetPath, useQuaternion: boolean): { interpolationType: AnimationSamplerInterpolation, shouldBakeAnimation: boolean } {
let interpolationType: AnimationSamplerInterpolation | undefined;
let shouldBakeAnimation = false;
let key: IAnimationKey;
if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION && !useQuaternion) {
return { interpolationType: AnimationSamplerInterpolation.LINEAR, shouldBakeAnimation: true };
}
for (let i = 0, length = keyFrames.length; i < length; ++i) {
key = keyFrames[i];
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 (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 };
}