How to use the babylonjs/Maths/math.Quaternion.FromArray function in babylonjs

To help you get started, we’ve selected a few babylonjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFAnimation.ts View on Github external
private static _ConvertFactorToVector3OrQuaternion(factor: number, babylonTransformNode: TransformNode, animation: Animation, animationType: number, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean): Nullable<Vector3 | Quaternion> {
        let property: string[];
        let componentName: string;
        let value: Nullable<Quaternion | Vector3> = null;
        const basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
        if (animationType === Animation.ANIMATIONTYPE_FLOAT) { // handles single component x, y, z or w component animation by using a base property and animating over a component.
            property = animation.targetProperty.split('.');
            componentName = property ? property[1] : ''; // x, y, or z component
            value = useQuaternion ? Quaternion.FromArray(basePositionRotationOrScale).normalize() : Vector3.FromArray(basePositionRotationOrScale);

            switch (componentName) {
                case 'x': {
                    value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== AnimationChannelTargetPath.SCALE)) ? -factor : factor;
                    break;
                }
                case 'y': {
                    value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== AnimationChannelTargetPath.SCALE)) ? -factor : factor;
                    break;
                }
                case 'z': {
                    value[componentName] = (convertToRightHandedSystem && !useQuaternion && (animationChannelTargetPath !== AnimationChannelTargetPath.SCALE)) ? -factor : factor;
                    break;
                }
                case 'w': {
                    (value as Quaternion).w = factor;
github BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFAnimation.ts View on Github external
private static _ConvertFactorToVector3OrQuaternion(factor: number, babylonTransformNode: TransformNode, animation: Animation, animationType: number, animationChannelTargetPath: AnimationChannelTargetPath, convertToRightHandedSystem: boolean, useQuaternion: boolean): Nullable<Vector3 | Quaternion> {
        let property: string[];
        let componentName: string;
        let value: Nullable<Quaternion | Vector3> = null;
        const basePositionRotationOrScale = _GLTFAnimation._GetBasePositionRotationOrScale(babylonTransformNode, animationChannelTargetPath, convertToRightHandedSystem, useQuaternion);
        if (animationType === Animation.ANIMATIONTYPE_FLOAT) { // handles single component x, y, z or w component animation by using a base property and animating over a component.
            property = animation.targetProperty.split('.');
            componentName = property ? property[1] : ''; // x, y, or z component
            value = useQuaternion ? Quaternion.FromArray(basePositionRotationOrScale).normalize() : Vector3.FromArray(basePositionRotationOrScale);

            switch (componentName) {
                case 'x': {
                    value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== AnimationChannelTargetPath.SCALE)) ? -factor : factor;
                    break;
                }
                case 'y': {
                    value[componentName] = (convertToRightHandedSystem && useQuaternion && (animationChannelTargetPath !== AnimationChannelTargetPath.SCALE)) ? -factor : factor;
                    break;
                }
                case 'z': {
                    value[componentName] = (convertToRightHandedSystem && !useQuaternion && (animationChannelTargetPath !== AnimationChannelTargetPath.SCALE)) ? -factor : factor;
                    break;
                }
                case 'w': {
                    (value as Quaternion).w = factor;
github BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFAnimation.ts View on Github external
let tangentValue: Vector3 | Quaternion = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;
        if (interpolation === AnimationSamplerInterpolation.CUBICSPLINE) {
            if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {
                if (tangentValue) {
                    if (useQuaternion) {
                        tangent = (tangentValue as Quaternion).scale(frameDelta).asArray();
                    }
                    else {
                        const array = (tangentValue as Vector3).scale(frameDelta);
                        tangent = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z).asArray();
                    }

                    if (convertToRightHandedSystem) {
                        _GLTFUtilities._GetRightHandedQuaternionArrayFromRef(tangent);
                        if (!babylonTransformNode.parent) {
                            tangent = Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(tangent)).asArray();
                        }
                    }
                }
                else {
                    tangent = [0, 0, 0, 0];
                }
            }
            else {
                if (tangentValue) {
                    tangent = (tangentValue as Vector3).scale(frameDelta).asArray();
                    if (convertToRightHandedSystem) {
                        if (animationChannelTargetPath === AnimationChannelTargetPath.TRANSLATION) {
                            _GLTFUtilities._GetRightHandedPositionArray3FromRef(tangent);
                            if (!babylonTransformNode.parent) {
                                tangent[0] *= -1; // x
                                tangent[2] *= -1; // z
github BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFAnimation.ts View on Github external
let tangentValue: Vector3 | Quaternion = tangentType === _TangentType.INTANGENT ? keyFrame.inTangent : keyFrame.outTangent;
        if (interpolation === AnimationSamplerInterpolation.CUBICSPLINE) {
            if (animationChannelTargetPath === AnimationChannelTargetPath.ROTATION) {
                if (tangentValue) {
                    if (useQuaternion) {
                        tangent = (tangentValue as Quaternion).scale(frameDelta).asArray();
                    }
                    else {
                        const array = (tangentValue as Vector3).scale(frameDelta);
                        tangent = Quaternion.RotationYawPitchRoll(array.y, array.x, array.z).asArray();
                    }

                    if (convertToRightHandedSystem) {
                        _GLTFUtilities._GetRightHandedQuaternionArrayFromRef(tangent);
                        if (!babylonTransformNode.parent) {
                            tangent = Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(tangent)).asArray();
                        }
                    }
                }
                else {
                    tangent = [0, 0, 0, 0];
                }
            }
            else {
                if (tangentValue) {
                    tangent = (tangentValue as Vector3).scale(frameDelta).asArray();
                    if (convertToRightHandedSystem) {
                        if (animationChannelTargetPath === AnimationChannelTargetPath.TRANSLATION) {
                            _GLTFUtilities._GetRightHandedPositionArray3FromRef(tangent);
                            if (!babylonTransformNode.parent) {
                                tangent[0] *= -1; // x
                                tangent[2] *= -1; // z
github BabylonJS / Babylon.js / loaders / src / glTF / 2.0 / glTFLoader.ts View on Github external
getNextOutputValue = () => {
                        const value = Quaternion.FromArray(data.output, outputBufferOffset);
                        outputBufferOffset += 4;
                        return value;
                    };
                    break;
github BabylonJS / Babylon.js / loaders / src / glTF / 2.0 / glTFLoader.ts View on Github external
private _getNodeMatrix(node: INode): Matrix {
        return node.matrix ?
            Matrix.FromArray(node.matrix) :
            Matrix.Compose(
                node.scale ? Vector3.FromArray(node.scale) : Vector3.One(),
                node.rotation ? Quaternion.FromArray(node.rotation) : Quaternion.Identity(),
                node.translation ? Vector3.FromArray(node.translation) : Vector3.Zero());
    }
github BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFAnimation.ts View on Github external
newPositionRotationOrScale.x *= -1;
                            newPositionRotationOrScale.z *= -1;
                        }
                    }
                }
                outputs.push(newPositionRotationOrScale.asArray());
            }
        }
        else if (animationType === Animation.ANIMATIONTYPE_QUATERNION) {
            value = (keyFrame.value as Quaternion).normalize().asArray();

            if (convertToRightHandedSystem) {
                _GLTFUtilities._GetRightHandedQuaternionArrayFromRef(value);

                if (!babylonTransformNode.parent) {
                    value = Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(value)).asArray();
                }
            }

            outputs.push(value);
        }
        else {
            Tools.Error('glTFAnimation: Unsupported key frame values for animation!');
        }
    }
github BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFExporter.ts View on Github external
} else if (babylonNode.metadata.gltf) {
                                glTFNode.extras = babylonNode.metadata.gltf.extras;
                            }
                        }

                        if (!babylonNode.parent) {
                            if (this._options.shouldExportNode && !this._options.shouldExportNode(babylonNode)) {
                                Tools.Log("Omitting " + babylonNode.name + " from scene.");
                            }
                            else {
                                if (this._convertToRightHandedSystem) {
                                    if (glTFNode.translation) {
                                        glTFNode.translation[2] *= -1;
                                        glTFNode.translation[0] *= -1;
                                    }
                                    glTFNode.rotation = glTFNode.rotation ? Quaternion.FromArray([0, 1, 0, 0]).multiply(Quaternion.FromArray(glTFNode.rotation)).asArray() : (Quaternion.FromArray([0, 1, 0, 0])).asArray();
                                }

                                scene.nodes.push(glTFNodeIndex);
                            }
                        }

                        directDescendents = babylonNode.getDescendants(true);
                        if (!glTFNode.children && directDescendents && directDescendents.length) {
                            const children: number[] = [];
                            for (let descendent of directDescendents) {
                                if (this._nodeMap[descendent.uniqueId] != null) {
                                    children.push(this._nodeMap[descendent.uniqueId]);
                                }
                            }
                            if (children.length) {
                                glTFNode.children = children;
github BabylonJS / Babylon.js / serializers / src / glTF / 2.0 / glTFAnimation.ts View on Github external
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());
            }
            else {
                cacheValue = value as Vector3;
                if (convertToRightHandedSystem && (animationChannelTargetPath !== AnimationChannelTargetPath.SCALE)) {
                    _GLTFUtilities._GetRightHandedPositionVector3FromRef(cacheValue);
                    if (!babylonTransformNode.parent) {
                        cacheValue.x *= -1;
                        cacheValue.z *= -1;
                    }
                }

                outputs.push(cacheValue.asArray());
            }