Prechádzať zdrojové kódy

Adding new custom functions for ParticleSystem

David Catuhe 11 rokov pred
rodič
commit
045cae317b

+ 5 - 3
Babylon/Loading/Plugins/babylon.babylonFileLoader.js

@@ -501,11 +501,13 @@ var BABYLON = BABYLON || {};
         BABYLON.Tags.AddTagsTo(mesh, parsedMesh.tags);
 
         mesh.position = BABYLON.Vector3.FromArray(parsedMesh.position);
-        if (parsedMesh.rotation) {
-            mesh.rotation = BABYLON.Vector3.FromArray(parsedMesh.rotation);
-        } else if (parsedMesh.rotationQuaternion) {
+
+        if (parsedMesh.rotationQuaternion) {
             mesh.rotationQuaternion = BABYLON.Quaternion.FromArray(parsedMesh.rotationQuaternion);
+        } else if (parsedMesh.rotation) {
+            mesh.rotation = BABYLON.Vector3.FromArray(parsedMesh.rotation);
         }
+
         mesh.scaling = BABYLON.Vector3.FromArray(parsedMesh.scaling);
 
         if (parsedMesh.localMatrix) {

+ 20 - 10
Babylon/Particles/babylon.particleSystem.js

@@ -12,6 +12,7 @@
 
     var ParticleSystem = (function () {
         function ParticleSystem(name, capacity, scene) {
+            var _this = this;
             this.name = name;
             this.renderingGroupId = 0;
             this.emitter = null;
@@ -77,6 +78,23 @@
             this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
 
             this._vertices = new Float32Array(capacity * this._vertexStrideSize);
+
+            // Default behaviors
+            this.startDirectionFunction = function (emitPower, worldMatrix, directionToUpdate) {
+                var randX = randomNumber(_this.direction1.x, _this.direction2.x);
+                var randY = randomNumber(_this.direction1.y, _this.direction2.y);
+                var randZ = randomNumber(_this.direction1.z, _this.direction2.z);
+
+                BABYLON.Vector3.TransformNormalFromFloatsToRef(randX * emitPower, randY * emitPower, randZ * emitPower, worldMatrix, directionToUpdate);
+            };
+
+            this.startPositionFunction = function (worldMatrix, positionToUpdate) {
+                var randX = randomNumber(_this.minEmitBox.x, _this.maxEmitBox.x);
+                var randY = randomNumber(_this.minEmitBox.y, _this.maxEmitBox.y);
+                var randZ = randomNumber(_this.minEmitBox.z, _this.maxEmitBox.z);
+
+                BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);
+            };
         }
         ParticleSystem.prototype.getCapacity = function () {
             return this._capacity;
@@ -163,22 +181,14 @@
 
                 var emitPower = randomNumber(this.minEmitPower, this.maxEmitPower);
 
-                var randX = randomNumber(this.direction1.x, this.direction2.x);
-                var randY = randomNumber(this.direction1.y, this.direction2.y);
-                var randZ = randomNumber(this.direction1.z, this.direction2.z);
-
-                BABYLON.Vector3.TransformNormalFromFloatsToRef(randX * emitPower, randY * emitPower, randZ * emitPower, worldMatrix, particle.direction);
+                this.startDirectionFunction(emitPower, worldMatrix, particle.direction);
 
                 particle.lifeTime = randomNumber(this.minLifeTime, this.maxLifeTime);
 
                 particle.size = randomNumber(this.minSize, this.maxSize);
                 particle.angularSpeed = randomNumber(this.minAngularSpeed, this.maxAngularSpeed);
 
-                randX = randomNumber(this.minEmitBox.x, this.maxEmitBox.x);
-                randY = randomNumber(this.minEmitBox.y, this.maxEmitBox.y);
-                randZ = randomNumber(this.minEmitBox.z, this.maxEmitBox.z);
-
-                BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, particle.position);
+                this.startPositionFunction(worldMatrix, particle.position);
 
                 var step = randomNumber(0, 1.0);
 

+ 22 - 10
Babylon/Particles/babylon.particleSystem.ts

@@ -52,6 +52,9 @@
         public color2 = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
         public colorDead = new BABYLON.Color4(0, 0, 0, 1.0);
         public textureMask = new BABYLON.Color4(1.0, 1.0, 1.0, 1.0);
+        public startDirectionFunction: (emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3) => void;
+        public startPositionFunction: (worldMatrix: Matrix, positionToUpdate: Vector3) => void;
+
         private particles = new Array<Particle>();
 
         private _capacity: number;
@@ -104,6 +107,23 @@
             this._indexBuffer = scene.getEngine().createIndexBuffer(indices);
 
             this._vertices = new Float32Array(capacity * this._vertexStrideSize);
+
+            // Default behaviors
+            this.startDirectionFunction = (emitPower: number, worldMatrix: Matrix, directionToUpdate: Vector3): void => {
+                var randX = randomNumber(this.direction1.x, this.direction2.x);
+                var randY = randomNumber(this.direction1.y, this.direction2.y);
+                var randZ = randomNumber(this.direction1.z, this.direction2.z);
+
+                BABYLON.Vector3.TransformNormalFromFloatsToRef(randX * emitPower, randY * emitPower, randZ * emitPower, worldMatrix, directionToUpdate);
+            }
+
+            this.startPositionFunction = (worldMatrix: Matrix, positionToUpdate: Vector3): void => {
+                var randX = randomNumber(this.minEmitBox.x, this.maxEmitBox.x);
+                var randY = randomNumber(this.minEmitBox.y, this.maxEmitBox.y);
+                var randZ = randomNumber(this.minEmitBox.z, this.maxEmitBox.z);
+
+                BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, positionToUpdate);
+            }
         }
 
         public getCapacity(): number {
@@ -192,22 +212,14 @@
 
                 var emitPower = randomNumber(this.minEmitPower, this.maxEmitPower);
 
-                var randX = randomNumber(this.direction1.x, this.direction2.x);
-                var randY = randomNumber(this.direction1.y, this.direction2.y);
-                var randZ = randomNumber(this.direction1.z, this.direction2.z);
-
-                BABYLON.Vector3.TransformNormalFromFloatsToRef(randX * emitPower, randY * emitPower, randZ * emitPower, worldMatrix, particle.direction);
+                this.startDirectionFunction(emitPower, worldMatrix, particle.direction);
 
                 particle.lifeTime = randomNumber(this.minLifeTime, this.maxLifeTime);
 
                 particle.size = randomNumber(this.minSize, this.maxSize);
                 particle.angularSpeed = randomNumber(this.minAngularSpeed, this.maxAngularSpeed);
 
-                randX = randomNumber(this.minEmitBox.x, this.maxEmitBox.x);
-                randY = randomNumber(this.minEmitBox.y, this.maxEmitBox.y);
-                randZ = randomNumber(this.minEmitBox.z, this.maxEmitBox.z);
-
-                BABYLON.Vector3.TransformCoordinatesFromFloatsToRef(randX, randY, randZ, worldMatrix, particle.position);
+                this.startPositionFunction(worldMatrix, particle.position);
 
                 var step = randomNumber(0, 1.0);
 

+ 3 - 3
Babylon/Tools/babylon.sceneSerializer.js

@@ -517,10 +517,10 @@
 
         serializationObject.position = mesh.position.asArray();
 
-        if (mesh.rotation) {
-            serializationObject.rotation = mesh.rotation.asArray();
-        } else if (mesh.rotationQuaternion) {
+        if (mesh.rotationQuaternion) {
             serializationObject.rotationQuaternion = mesh.rotationQuaternion.asArray();
+        } else if (mesh.rotation) {
+            serializationObject.rotation = mesh.rotation.asArray();
         }
 
         serializationObject.scaling = mesh.scaling.asArray();

+ 3 - 3
Babylon/Tools/babylon.sceneSerializer.ts

@@ -526,10 +526,10 @@
 
         serializationObject.position = mesh.position.asArray();
 
-        if (mesh.rotation) {
-            serializationObject.rotation = mesh.rotation.asArray();
-        } else if (mesh.rotationQuaternion) {
+        if (mesh.rotationQuaternion) {
             serializationObject.rotationQuaternion = mesh.rotationQuaternion.asArray();
+        } else if (mesh.rotation) {
+            serializationObject.rotation = mesh.rotation.asArray();
         }
 
         serializationObject.scaling = mesh.scaling.asArray();

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 7 - 7
babylon.1.12-beta.js