Procházet zdrojové kódy

Merge branch 'master' of https://github.com/BabylonJS/Babylon.js

davrous před 8 roky
rodič
revize
0e87b72e4a

+ 2 - 3
Exporters/3ds Max/BabylonExport.Entities/BabylonScene.cs

@@ -123,13 +123,12 @@ namespace BabylonExport.Entities
             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 };
         }
 
-        public void Prepare(bool generateDefaultLight = true)
+        public void Prepare(bool generateDefaultLight = true, bool generateDefaultCamera = true)
         {
             meshes = MeshesList.ToArray();
             sounds = SoundsList.ToArray();
@@ -139,7 +138,7 @@ namespace BabylonExport.Entities
             shadowGenerators = ShadowGeneratorsList.ToArray();
             skeletons = SkeletonsList.ToArray();
 
-            if (CamerasList.Count == 0)
+            if (CamerasList.Count == 0 && generateDefaultCamera)
             {
                 var camera = new BabylonCamera { name = "Default camera", id = Guid.NewGuid().ToString() };
 

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 20 - 20
dist/preview release/babylon.core.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 1423 - 1297
dist/preview release/babylon.d.ts


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 30 - 30
dist/preview release/babylon.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 158 - 14
dist/preview release/babylon.max.js


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 29 - 29
dist/preview release/babylon.noworker.js


+ 5 - 4
src/Cameras/babylon.followCamera.ts

@@ -41,11 +41,12 @@
                 yRotation = cameraTarget.rotation.y;
             }
             var radians = this.getRadians(this.rotationOffset) + yRotation;
-            var targetX: number = cameraTarget.position.x + Math.sin(radians) * this.radius;
+            var targetPosition = cameraTarget.getAbsolutePosition();
+            var targetX: number = targetPosition.x + Math.sin(radians) * this.radius;
 
-            var targetZ: number = cameraTarget.position.z + Math.cos(radians) * this.radius;
+            var targetZ: number = targetPosition.z + Math.cos(radians) * this.radius;
             var dx: number = targetX - this.position.x;
-            var dy: number = (cameraTarget.position.y + this.heightOffset) - this.position.y;
+            var dy: number = (targetPosition.y + this.heightOffset) - this.position.y;
             var dz: number = (targetZ) - this.position.z;
             var vx: number = dx * this.cameraAcceleration * 2;//this is set to .05
             var vy: number = dy * this.cameraAcceleration;
@@ -64,7 +65,7 @@
             }
 
             this.position = new Vector3(this.position.x + vx, this.position.y + vy, this.position.z + vz);
-            this.setTarget(cameraTarget.position);
+            this.setTarget(targetPosition);
         }
 
         public _checkInputs(): void {

+ 2 - 1
src/Math/babylon.math.ts

@@ -4076,7 +4076,8 @@
         public static Vector3: Vector3[] = [Vector3.Zero(), Vector3.Zero(), Vector3.Zero(),
             Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero(), Vector3.Zero()];    // 9 temp Vector3 at once should be enough
         public static Vector4: Vector4[] = [Vector4.Zero(), Vector4.Zero(), Vector4.Zero()];  // 3 temp Vector4 at once should be enough
-        public static Quaternion: Quaternion[] = [new Quaternion(0, 0, 0, 0)];                // 1 temp Quaternion at once should be enough
+        public static Quaternion: Quaternion[] = [new Quaternion(0.0, 0.0, 0.0, 0.0), 
+            new Quaternion(0.0, 0.0, 0.0, 0.0)];                // 2 temp Quaternion at once should be enough
         public static Matrix: Matrix[] = [Matrix.Zero(), Matrix.Zero(),
             Matrix.Zero(), Matrix.Zero(),
             Matrix.Zero(), Matrix.Zero(),

+ 150 - 9
src/Mesh/babylon.abstractMesh.ts

@@ -114,10 +114,10 @@
 
         // Properties
         public definedFacingForward = true; // orientation for POV movement & rotation
-        public position = new Vector3(0, 0, 0);
-        private _rotation = new Vector3(0, 0, 0);
+        public position = new Vector3(0.0, 0.0, 0.0);
+        private _rotation = new Vector3(0.0, 0.0, 0.0);
         public _rotationQuaternion: Quaternion;
-        private _scaling = new Vector3(1, 1, 1);
+        private _scaling = new Vector3(1.0, 1.0, 1.0);
         public billboardMode = AbstractMesh.BILLBOARDMODE_NONE;
         public visibility = 1.0;
         public alphaIndex = Number.MAX_VALUE;
@@ -148,7 +148,9 @@
         public useOctreeForCollisions = true;
 
         public layerMask: number = 0x0FFFFFFF;
-
+        /**
+         * True if the mesh must be rendered in any case.  
+         */
         public alwaysSelectAsActiveMesh = false;
 
         /**
@@ -241,6 +243,9 @@
             scene.addMesh(this);
         }
 
+        /**
+         * Returns the string "AbstractMesh"
+         */
         public getClassName(): string {
             return "AbstractMesh";
         }
@@ -262,8 +267,9 @@
         }
 
         /**
-         * Getting the rotation object. 
-         * If rotation quaternion is set, this vector will (almost always) be the Zero vector!
+         * Ratation property : a Vector3 depicting the rotation value in radians around each local axis X, Y, Z. 
+         * If rotation quaternion is set, this Vector3 will (almost always) be the Zero vector!
+         * Default : (0.0, 0.0, 0.0)
          */
         public get rotation(): Vector3 {
             return this._rotation;
@@ -273,6 +279,10 @@
             this._rotation = newRotation;
         }
 
+        /**
+         * Scaling property : a Vector3 depicting the mesh scaling along each local axis X, Y, Z.  
+         * Default : (1.0, 1.0, 1.0)
+         */
         public get scaling(): Vector3 {
             return this._scaling;
         }
@@ -284,6 +294,11 @@
             }
         }
 
+        /**
+         * Rotation Quaternion property : this a Quaternion object depicting the mesh rotation by using a unit quaternion. 
+         * It's null by default.  
+         * If set, only the rotationQuaternion is then used to compute the mesh rotation and its property `.rotation\ is then ignored and set to (0.0, 0.0, 0.0)
+         */
         public get rotationQuaternion() {
             return this._rotationQuaternion;
         }
@@ -292,7 +307,7 @@
             this._rotationQuaternion = quaternion;
             //reset the rotation vector. 
             if (quaternion && this.rotation.length()) {
-                this.rotation.copyFromFloats(0, 0, 0);
+                this.rotation.copyFromFloats(0.0, 0.0, 0.0);
             }
         }
 
@@ -321,26 +336,49 @@
             return false;
         }
 
+        /**
+         * Returns this by default, used by the class Mesh.  
+         * Returned type : AbstractMesh
+         */
         public getLOD(camera: Camera): AbstractMesh {
             return this;
         }
 
+        /**
+         * Returns 0 by default, used by the class Mesh.  
+         * Returns an integer.  
+         */
         public getTotalVertices(): number {
             return 0;
         }
 
+        /**
+         * Returns null by default, used by the class Mesh. 
+         * Returned type : integer array 
+         */
         public getIndices(): IndicesArray {
             return null;
         }
 
+        /**
+         * Returns the array of the requested vertex data kind. Used by the class Mesh. Returns null here. 
+         * Returned type : float array or Float32Array 
+         */
         public getVerticesData(kind: string): number[] | Float32Array {
             return null;
         }
 
+        /** Returns false by default, used by the class Mesh.  
+         *  Returns a boolean
+        */
         public isVerticesDataPresent(kind: string): boolean {
             return false;
         }
 
+        /**
+         * Returns the mesh BoundingInfo object or creates a new one and returns it if undefined.
+         * Returns a BoundingInfo
+         */
         public getBoundingInfo(): BoundingInfo {
             if (this._masterMesh) {
                 return this._masterMesh.getBoundingInfo();
@@ -352,6 +390,10 @@
             return this._boundingInfo;
         }
 
+        /**
+         * Sets a mesh new object BoundingInfo.
+         * Returns nothing.  
+         */
         public setBoundingInfo(boundingInfo: BoundingInfo): void {
             this._boundingInfo = boundingInfo;
         }
@@ -370,6 +412,10 @@
             this._renderId = renderId;
         }
 
+        /**
+         * Returns the last update of the World matrix
+         * Returns a Matrix.  
+         */
         public getWorldMatrix(): Matrix {
             if (this._masterMesh) {
                 return this._masterMesh.getWorldMatrix();
@@ -381,30 +427,53 @@
             return this._worldMatrix;
         }
 
+        /**
+         * Returns directly the last state of the mesh World matrix. 
+         * A Matrix is returned.    
+         */
         public get worldMatrixFromCache(): Matrix {
             return this._worldMatrix;
         }
 
+        /**
+         * Returns the current mesh absolute position.
+         * Retuns a Vector3
+         */
         public get absolutePosition(): Vector3 {
             return this._absolutePosition;
         }
-
+        /**
+         * Prevents the World matrix to be computed any longer.
+         * Returns nothing.  
+         */
         public freezeWorldMatrix() {
             this._isWorldMatrixFrozen = false;  // no guarantee world is not already frozen, switch off temporarily
             this.computeWorldMatrix(true);
             this._isWorldMatrixFrozen = true;
         }
 
+        /**
+         * Allows back the World matrix computation. 
+         * Returns nothing.  
+         */
         public unfreezeWorldMatrix() {
             this._isWorldMatrixFrozen = false;
             this.computeWorldMatrix(true);
         }
 
+        /**
+         * True if the World matrix has been frozen.  
+         * Returns a boolean.  
+         */
         public get isWorldMatrixFrozen(): boolean {
             return this._isWorldMatrixFrozen;
         }
 
         private static _rotationAxisCache = new Quaternion();
+        /**
+         * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in the given space.  
+         * space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD
+         */
         public rotate(axis: Vector3, amount: number, space?: Space): void {
             axis.normalize();
 
@@ -429,6 +498,10 @@
             }
         }
 
+        /**
+         * Translates the mesh along the axis vector for the passed distance in the given space.  
+         * space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD
+         */
         public translate(axis: Vector3, distance: number, space?: Space): void {
             var displacementVector = axis.scale(distance);
 
@@ -441,6 +514,36 @@
             }
         }
 
+        /**
+         * Adds a rotation step to the mesh current rotation.  
+         * x, y, z are Euler angles expressed in radians.  
+         * This methods updates the current mesh rotation, either mesh.rotation, either mesh.rotationQuaternion if it's set.  
+         * It's useful to set a custom rotation order different from the BJS standard one YXZ.  
+         * Example : this rotates the mesh first around its local X axis, then around its local Z axis, finally around its local Y axis.  
+         * ```javascript
+         * mesh.addRotation(x1, 0, 0).addRotation(0, 0, z2).addRotation(0, 0, y3);
+         * ```
+         * Note that `addRotation()` accumulates the passed rotation values to the current ones and computes the .rotation or .rotationQuaternion updated values.  
+         * Under the hood, only quaternions are used. So it's a little faster is you use .rotationQuaternion because it doesn't need to translate them back to Euler angles.  
+         */
+        public addRotation(x: number, y: number, z: number): AbstractMesh {
+            var rotationQuaternion;
+            if (this.rotationQuaternion) {
+                rotationQuaternion = this.rotationQuaternion;
+            }
+            else {
+                rotationQuaternion = Tmp.Quaternion[1];
+                Quaternion.RotationYawPitchRollToRef(this.rotation.y, this.rotation.x, this.rotation.z, rotationQuaternion);
+            }
+            var accumulation = BABYLON.Tmp.Quaternion[0];
+            Quaternion.RotationYawPitchRollToRef(y, x, z, accumulation);
+            rotationQuaternion.multiplyInPlace(accumulation);
+            if (!this.rotationQuaternion) {
+                rotationQuaternion.toEulerAnglesToRef(this.rotation);
+            }
+            return this;
+        }
+
         public getAbsolutePosition(): Vector3 {
             this.computeWorldMatrix();
             return this._absolutePosition;
@@ -537,11 +640,20 @@
             return new Vector3(flipBack * defForwardMult, twirlClockwise, tiltRight * defForwardMult);
         }
 
+        /**
+         * Sets a new pivot matrix to the mesh.  
+         * Returns nothing.
+         */
         public setPivotMatrix(matrix: Matrix): void {
             this._pivotMatrix = matrix;
             this._cache.pivotMatrixUpdated = true;
         }
 
+        /**
+         * Returns the mesh pivot matrix.
+         * Default : Identity.  
+         * A Matrix is returned.  
+         */
         public getPivotMatrix(): Matrix {
             return this._pivotMatrix;
         }
@@ -620,6 +732,13 @@
             }
         }
 
+        /**
+         * Computes the mesh World matrix and returns it.  
+         * If the mesh world matrix is frozen, this computation does nothing more than returning the last frozen values.  
+         * If the parameter `force` is let to `false` (default), the current cached World matrix is returned. 
+         * If the parameter `force`is set to `true`, the actual computation is done.  
+         * Returns the mesh World Matrix.
+         */
         public computeWorldMatrix(force?: boolean): Matrix {
             if (this._isWorldMatrixFrozen) {
                 return this._worldMatrix;
@@ -757,13 +876,16 @@
         }
 
         /**
-        * If you'd like to be callbacked after the mesh position, rotation or scaling has been updated
+        * If you'd like to be called back after the mesh position, rotation or scaling has been updated
         * @param func: callback function to add
         */
         public registerAfterWorldMatrixUpdate(func: (mesh: AbstractMesh) => void): void {
             this.onAfterWorldMatrixUpdateObservable.add(func);
         }
 
+        /**
+         * Removes a registered callback function
+         */
         public unregisterAfterWorldMatrixUpdate(func: (mesh: AbstractMesh) => void): void {
             this.onAfterWorldMatrixUpdateObservable.removeCallback(func);
         }
@@ -774,6 +896,10 @@
             this.position = Vector3.TransformNormal(vector3, this._localWorld);
         }
 
+        /**
+         * Returns the mesh position in the local space from the current World matrix values.
+         * Returns a new Vector3.
+         */
         public getPositionExpressedInLocalSpace(): Vector3 {
             this.computeWorldMatrix();
             var invLocalWorldMatrix = this._localWorld.clone();
@@ -833,6 +959,11 @@
             return this._boundingInfo.isCompletelyInFrustum(frustumPlanes);;
         }
 
+        /** 
+         * True if the mesh intersects another mesh or a SolidParticle object.  
+         * Unless the parameter `precise` is set to `true` the intersection is computed according to Axis Aligned Bounding Boxes (AABB), else according to OBB (Oriented BBoxes)
+         * Returns a boolean.  
+         */
         public intersectsMesh(mesh: AbstractMesh | SolidParticle, precise?: boolean): boolean {
             if (!this._boundingInfo || !mesh._boundingInfo) {
                 return false;
@@ -841,6 +972,10 @@
             return this._boundingInfo.intersects(mesh._boundingInfo, precise);
         }
 
+        /**
+         * Returns true if the passed point (Vector3) is inside the mesh bounding box.  
+         * Returns a boolean.  
+         */
         public intersectsPoint(point: Vector3): boolean {
             if (!this._boundingInfo) {
                 return false;
@@ -1156,6 +1291,12 @@
             }
         }
 
+        /**
+         * Disposes the AbstractMesh.  
+         * Some internal references are kept for further use.  
+         * By default, all the mesh children are also disposed unless the parameter `doNotRecurse` is set to `true`.  
+         * Returns nothing.  
+         */
         public dispose(doNotRecurse?: boolean): void {
             var index: number;