Beispiel #1
0
        /**
         * Returns a new Matrix composed by the passed scale (vector3), rotation (quaternion) and translation (vector3).
         */
        public static BabylonMatrix Compose(BabylonVector3 scale, BabylonQuaternion rotation, BabylonVector3 translation)
        {
            var result = BabylonMatrix.Identity();

            BabylonMatrix.ComposeToRef(scale, rotation, translation, result);
            return(result);
        }
Beispiel #2
0
        public BabylonScene(string outputPath)
        {
            OutputPath = outputPath;

            MeshesList              = new List <BabylonMesh>();
            MaterialsList           = new List <BabylonMaterial>();
            CamerasList             = new List <BabylonCamera>();
            LightsList              = new List <BabylonLight>();
            MultiMaterialsList      = new List <BabylonMultiMaterial>();
            ShadowGeneratorsList    = new List <BabylonShadowGenerator>();
            SkeletonsList           = new List <BabylonSkeleton>();
            SoundsList              = new List <BabylonSound>();
            MorphTargetManagersList = new List <BabylonMorphTargetManager>();

            // Default values
            autoClear    = true;
            clearColor   = new[] { 0.2f, 0.2f, 0.3f };
            ambientColor = new[] { 0f, 0f, 0f };
            gravity      = new[] { 0f, 0f, -0.9f };

            MaxVector = new BabylonVector3 {
                X = float.MinValue, Y = float.MinValue, Z = float.MinValue
            };
            MinVector = new BabylonVector3 {
                X = float.MaxValue, Y = float.MaxValue, Z = float.MaxValue
            };
        }
Beispiel #3
0
        public BabylonScene(string outputPath)
        {
            OutputPath = outputPath;

            MeshesList           = new List <BabylonMesh>();
            MaterialsList        = new List <BabylonMaterial>();
            CamerasList          = new List <BabylonCamera>();
            LightsList           = new List <BabylonLight>();
            MultiMaterialsList   = new List <BabylonMultiMaterial>();
            ShadowGeneratorsList = new List <BabylonShadowGenerator>();
            SkeletonsList        = new List <BabylonSkeleton>();
            SoundsList           = new List <BabylonSound>();

            environmentTexture          = null;
            environmentTextureType      = null;
            environmentTextureSize      = null;
            environmentTextureRotationY = null;

            // Default values
            autoClear    = true;
            clearColor   = new[] { 0.2f, 0.2f, 0.2f };
            ambientColor = new[] { 0f, 0f, 0f };
            gravity      = new[] { 0f, -9.81f, -0.0f };

            MaxVector = new BabylonVector3 {
                X = float.MinValue, Y = float.MinValue, Z = float.MinValue
            };
            MinVector = new BabylonVector3 {
                X = float.MaxValue, Y = float.MaxValue, Z = float.MaxValue
            };
        }
Beispiel #4
0
        public BabylonScene(string outputPath)
        {
            OutputPath = outputPath;

            MeshesList              = new List <BabylonMesh>();
            MaterialsList           = new List <BabylonMaterial>();
            CamerasList             = new List <BabylonCamera>();
            LightsList              = new List <BabylonLight>();
            MultiMaterialsList      = new List <BabylonMultiMaterial>();
            ShadowGeneratorsList    = new List <BabylonShadowGenerator>();
            SkeletonsList           = new List <BabylonSkeleton>();
            SoundsList              = new List <BabylonSound>();
            MorphTargetManagersList = new List <BabylonMorphTargetManager>();
            NodeMap = new Dictionary <string, BabylonNode>();
            BabylonToGLTFExtensions = new Dictionary <IBabylonExtensionExporter, ExtendedTypes>();
            RootNodes = new List <BabylonNode>();

            // Default values
            autoClear    = true;
            clearColor   = new[] { 0.2f, 0.2f, 0.3f };
            ambientColor = new[] { 0f, 0f, 0f };
            gravity      = new[] { 0f, 0f, -0.9f };

            MaxVector = new BabylonVector3 {
                X = float.MinValue, Y = float.MinValue, Z = float.MinValue
            };
            MinVector = new BabylonVector3 {
                X = float.MaxValue, Y = float.MaxValue, Z = float.MaxValue
            };
        }
Beispiel #5
0
        /**
         * Returns a new Translation Matrix from a vector3
         */
        public static BabylonMatrix Translation(BabylonVector3 translation)
        {
            var result = Identity();

            result.setTranslation(translation);
            return(result);
        }
Beispiel #6
0
        /**
         * Inserts the translation vector in the current Matrix.
         * Returns the updated Matrix.
         */
        public BabylonMatrix setTranslation(BabylonVector3 vector3)
        {
            this.m[12] = vector3.X;
            this.m[13] = vector3.Y;
            this.m[14] = vector3.Z;

            return(this);
        }
        public BabylonVector3 Rotate(BabylonVector3 v)
        {
            BabylonMatrix m = new BabylonMatrix();

            toRotationMatrix(m);

            BabylonVector3 result = new BabylonVector3
            {
                X = m.m[0] * v.X + m.m[1] * v.Y + m.m[2] * v.Z,
                Y = m.m[4] * v.X + m.m[5] * v.Y + m.m[6] * v.Z,
                Z = m.m[8] * v.X + m.m[9] * v.Y + m.m[10] * v.Z
            };

            return(result);
        }
Beispiel #8
0
        /**
         * Update a Matrix with values composed by the passed scale (vector3), rotation (quaternion) and translation (vector3).
         */
        public static void ComposeToRef(BabylonVector3 scale, BabylonQuaternion rotation, BabylonVector3 translation, BabylonMatrix result)
        {
            var matrix1 = new BabylonMatrix();

            BabylonMatrix.FromValuesToRef(scale.X, 0, 0, 0,
                                          0, scale.Y, 0, 0,
                                          0, 0, scale.Z, 0,
                                          0, 0, 0, 1, matrix1);

            var matrix0 = new BabylonMatrix();

            rotation.toRotationMatrix(matrix0);
            matrix1.multiplyToRef(matrix0, result);

            result.setTranslation(translation);
        }
Beispiel #9
0
        /**
         * Copy / pasted from babylon
         */
        public BabylonVector3 toEulerAngles()
        {
            var result = new BabylonVector3();

            var qz = this.Z;
            var qx = this.X;
            var qy = this.Y;
            var qw = this.W;

            var sqw = qw * qw;
            var sqz = qz * qz;
            var sqx = qx * qx;
            var sqy = qy * qy;

            var zAxisY = qy * qz - qx * qw;
            var limit  = .4999999;

            if (zAxisY < -limit)
            {
                result.Y = (float)(2 * Math.Atan2(qy, qw));
                result.X = (float)Math.PI / 2;
                result.Z = 0;
            }
            else if (zAxisY > limit)
            {
                result.Y = (float)(2 * Math.Atan2(qy, qw));
                result.X = (float)-Math.PI / 2;
                result.Z = 0;
            }
            else
            {
                result.Z = (float)Math.Atan2(2.0 * (qx * qy + qz * qw), (-sqz - sqx + sqy + sqw));
                result.X = (float)Math.Asin(-2.0 * (qz * qy - qx * qw));
                result.Y = (float)Math.Atan2(2.0 * (qz * qx + qy * qw), (sqz - sqx - sqy + sqw));
            }

            return(result);
        }
Beispiel #10
0
        /**
         * Decomposes the current Matrix into :
         * - a scale vector3 passed as a reference to update,
         * - a rotation quaternion passed as a reference to update,
         * - a translation vector3 passed as a reference to update.
         * Returns the boolean `true`.
         */
        public bool decompose(BabylonVector3 scale, BabylonQuaternion rotation, BabylonVector3 translation)
        {
            translation.X = this.m[12];
            translation.Y = this.m[13];
            translation.Z = this.m[14];

            scale.X = (float)Math.Sqrt(this.m[0] * this.m[0] + this.m[1] * this.m[1] + this.m[2] * this.m[2]);
            scale.Y = (float)Math.Sqrt(this.m[4] * this.m[4] + this.m[5] * this.m[5] + this.m[6] * this.m[6]);
            scale.Z = (float)Math.Sqrt(this.m[8] * this.m[8] + this.m[9] * this.m[9] + this.m[10] * this.m[10]);

            if (this.determinant() <= 0)
            {
                scale.Y *= -1;
            }

            if (scale.X == 0 || scale.Y == 0 || scale.Z == 0)
            {
                rotation.X = 0;
                rotation.Y = 0;
                rotation.Z = 0;
                rotation.W = 1;
                return(false);
            }

            var matrix = new BabylonMatrix();

            BabylonMatrix.FromValuesToRef(
                this.m[0] / scale.X, this.m[1] / scale.X, this.m[2] / scale.X, 0,
                this.m[4] / scale.Y, this.m[5] / scale.Y, this.m[6] / scale.Y, 0,
                this.m[8] / scale.Z, this.m[9] / scale.Z, this.m[10] / scale.Z, 0,
                0, 0, 0, 1, matrix);

            BabylonQuaternion.FromRotationMatrixToRef(matrix, rotation);

            return(true);
        }
Beispiel #11
0
        public static float[] Interpolate(BabylonAnimation animation, BabylonAnimationKey fromKey, BabylonAnimationKey toKey, float frame)
        {
            switch (animation.property)
            {
            case "_matrix":
                var fromMatrix = new BabylonMatrix();
                fromMatrix.m = new List <float>(fromKey.values).ToArray();
                var toMatrix = new BabylonMatrix();
                toMatrix.m = new List <float>(toKey.values).ToArray();
                var fromPosition = new BabylonVector3();
                var fromRotation = new BabylonQuaternion();
                var fromScaling  = new BabylonVector3();
                var toPosition   = new BabylonVector3();
                var toRotation   = new BabylonQuaternion();
                var toScaling    = new BabylonVector3();

                fromMatrix.decompose(fromScaling, fromRotation, fromPosition);
                toMatrix.decompose(toScaling, toRotation, toPosition);

                var lerpFactor = MathUtilities.GetLerpFactor(fromKey.frame, toKey.frame, frame);

                var interpolatedKeyPosition = BabylonVector3.FromArray(MathUtilities.Lerp(fromPosition.ToArray(), toPosition.ToArray(), lerpFactor));
                var interpolatedKeyRotation = BabylonQuaternion.Slerp(fromRotation, toRotation, lerpFactor);
                var interpolatedKeyScaling  = BabylonVector3.FromArray(MathUtilities.Lerp(fromScaling.ToArray(), toScaling.ToArray(), lerpFactor));

                return(BabylonMatrix.Compose(interpolatedKeyScaling, interpolatedKeyRotation, interpolatedKeyPosition).m);

            case "rotationQuaternion":
                return(BabylonQuaternion.Slerp(BabylonQuaternion.FromArray(fromKey.values), BabylonQuaternion.FromArray(toKey.values), MathUtilities.GetLerpFactor(fromKey.frame, toKey.frame, frame)).ToArray());

            case "scaling":
            case "position":
            default:
                return(MathUtilities.Lerp(fromKey.values, toKey.values, MathUtilities.GetLerpFactor(fromKey.frame, toKey.frame, frame)));
            }
        }
        public BabylonScene(string outputPath)
        {
            OutputPath = outputPath;

            MeshesList = new List<BabylonMesh>();
            MaterialsList = new List<BabylonMaterial>();
            CamerasList = new List<BabylonCamera>();
            LightsList = new List<BabylonLight>();
            MultiMaterialsList = new List<BabylonMultiMaterial>();
            ShadowGeneratorsList = new List<BabylonShadowGenerator>();
            SkeletonsList = new List<BabylonSkeleton>();
            SoundsList = new List<BabylonSound>();

            // Default values
            autoClear = true;
            clearColor = new[] { 0.2f, 0.2f, 0.3f };
            ambientColor = new[] { 0f, 0f, 0f };
            gravity = new[] { 0f, 0f, -0.9f };
            physicsEngine = "cannon";

            MaxVector = new BabylonVector3 { X = float.MinValue, Y = float.MinValue, Z = float.MinValue };
            MinVector = new BabylonVector3 { X = float.MaxValue, Y = float.MaxValue, Z = float.MaxValue };
        }