Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let animationChannelTargetPath: Nullable = null;
let dataAccessorType = AccessorType.VEC3;
let useQuaternion: boolean = false;
let property = animation.targetProperty.split('.');
switch (property[0]) {
case 'scaling': {
animationChannelTargetPath = AnimationChannelTargetPath.SCALE;
break;
}
case 'position': {
animationChannelTargetPath = AnimationChannelTargetPath.TRANSLATION;
break;
}
case 'rotation': {
dataAccessorType = AccessorType.VEC4;
animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;
break;
}
case 'rotationQuaternion': {
dataAccessorType = AccessorType.VEC4;
useQuaternion = true;
animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;
break;
}
default: {
Tools.Error(`Unsupported animatable property ${property[0]}`);
}
}
if (animationChannelTargetPath) {
return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
}
else {
return this._loadAnimationSamplerAsync(`${animationContext}/samplers/${channel.sampler}`, sampler).then((data) => {
let targetPath: string;
let animationType: number;
switch (channel.target.path) {
case AnimationChannelTargetPath.TRANSLATION: {
targetPath = "position";
animationType = Animation.ANIMATIONTYPE_VECTOR3;
break;
}
case AnimationChannelTargetPath.ROTATION: {
targetPath = "rotationQuaternion";
animationType = Animation.ANIMATIONTYPE_QUATERNION;
break;
}
case AnimationChannelTargetPath.SCALE: {
targetPath = "scaling";
animationType = Animation.ANIMATIONTYPE_VECTOR3;
break;
}
case AnimationChannelTargetPath.WEIGHTS: {
targetPath = "influence";
animationType = Animation.ANIMATIONTYPE_FLOAT;
break;
}
default: {
throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);
private static _SetInterpolatedValue(babylonTransformNode: TransformNode, value: Nullable, time: number, animation: Animation, animationChannelTargetPath: AnimationChannelTargetPath, quaternionCache: Quaternion, inputs: number[], outputs: number[][], convertToRightHandedSystem: boolean, useQuaternion: boolean) {
const animationType = animation.dataType;
let cacheValue: Vector3 | Quaternion;
inputs.push(time);
if (typeof value === "number") {
value = this._ConvertFactorToVector3OrQuaternion(value as number, babylonTransformNode, animation, animationType, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
}
if (value) {
if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {
if (useQuaternion) {
quaternionCache = value as Quaternion;
}
else {
cacheValue = value as Vector3;
Quaternion.RotationYawPitchRollToRef(cacheValue.y, cacheValue.x, cacheValue.z, quaternionCache);
}
if (convertToRightHandedSystem) {
_GLTFUtilities._GetRightHandedQuaternionFromRef(quaternionCache);
if (!babylonTransformNode.parent) {
quaternionCache = Quaternion.FromArray([0, 1, 0, 0]).multiply(quaternionCache);
}
}
outputs.push(quaternionCache.asArray());
}
animationChannelTargetPath = AnimationChannelTargetPath.SCALE;
break;
}
case 'position': {
animationChannelTargetPath = AnimationChannelTargetPath.TRANSLATION;
break;
}
case 'rotation': {
dataAccessorType = AccessorType.VEC4;
animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;
break;
}
case 'rotationQuaternion': {
dataAccessorType = AccessorType.VEC4;
useQuaternion = true;
animationChannelTargetPath = AnimationChannelTargetPath.ROTATION;
break;
}
default: {
Tools.Error(`Unsupported animatable property ${property[0]}`);
}
}
if (animationChannelTargetPath) {
return { animationChannelTargetPath: animationChannelTargetPath, dataAccessorType: dataAccessorType, useQuaternion: useQuaternion };
}
else {
Tools.Error('animation channel target path and data accessor type could be deduced');
}
return null;
}
private static _GetBasePositionRotationOrScale(babylonTransformNode: TransformNode, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean) {
let basePositionRotationOrScale: number[];
if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {
if (useQuaternion) {
if (babylonTransformNode.rotationQuaternion) {
basePositionRotationOrScale = babylonTransformNode.rotationQuaternion.asArray();
if (convertToRightHandedSystem) {
_GLTFUtilities._GetRightHandedQuaternionArrayFromRef(basePositionRotationOrScale);
if (!babylonTransformNode.parent) {
basePositionRotationOrScale = Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(basePositionRotationOrScale)).asArray();
}
}
}
else {
basePositionRotationOrScale = Quaternion.Identity().asArray();
}
}
else {
basePositionRotationOrScale = babylonTransformNode.rotation.asArray();
return this._loadAnimationSamplerAsync(`${animationContext}/samplers/${channel.sampler}`, sampler).then((data) => {
let targetPath: string;
let animationType: number;
switch (channel.target.path) {
case AnimationChannelTargetPath.TRANSLATION: {
targetPath = "position";
animationType = Animation.ANIMATIONTYPE_VECTOR3;
break;
}
case AnimationChannelTargetPath.ROTATION: {
targetPath = "rotationQuaternion";
animationType = Animation.ANIMATIONTYPE_QUATERNION;
break;
}
case AnimationChannelTargetPath.SCALE: {
targetPath = "scaling";
animationType = Animation.ANIMATIONTYPE_VECTOR3;
break;
}
case AnimationChannelTargetPath.WEIGHTS: {
targetPath = "influence";
animationType = Animation.ANIMATIONTYPE_FLOAT;
break;
}
default: {
throw new Error(`${context}/target/path: Invalid value (${channel.target.path})`);