Pārlūkot izejas kodu

SPS added particle pivot support

jbousquie 7 gadi atpakaļ
vecāks
revīzija
89a4833f8c

+ 8 - 7
src/Particles/babylon.solidParticle.ts

@@ -3,14 +3,15 @@ module BABYLON {
         export class SolidParticle {
             public idx: number = 0;                                             // particle global index
             public color: Nullable<Color4> = new Color4(1.0, 1.0, 1.0, 1.0);    // color
-            public position = Vector3.Zero();                                   // position
-            public rotation = Vector3.Zero();                                   // rotation
+            public position: Vector3 = Vector3.Zero();                                   // position
+            public rotation: Vector3 = Vector3.Zero();                                   // rotation
             public rotationQuaternion: Nullable<Quaternion>;                    // quaternion, will overwrite rotation
-            public scaling = Vector3.One();                                     // scaling
-            public uvs = new Vector4(0.0, 0.0, 1.0, 1.0);                       // uvs
-            public velocity = Vector3.Zero();                                   // velocity
-            public alive = true;                                                // alive
-            public isVisible = true;                                            // visibility
+            public scaling: Vector3 = Vector3.One();                                     // scaling
+            public uvs: Vector4 = new Vector4(0.0, 0.0, 1.0, 1.0);                       // uvs
+            public velocity: Vector3 = Vector3.Zero();                                   // velocity
+            public pivot: Vector3 = Vector3.Zero();                                      // pivot point in the particle local space
+            public alive: boolean = true;                                                // alive
+            public isVisible: boolean = true;                                            // visibility
             public _pos: number = 0;                                            // index of this particle in the global "positions" array
             public _ind: number = 0;                                            // index of this particle in the global "indices" array
             public _model: ModelShape;                                          // model shape reference

+ 4 - 0
src/Particles/babylon.solidParticleSystem.ts

@@ -749,6 +749,10 @@
                             this._vertex.x *= this._particle.scaling.x;
                             this._vertex.y *= this._particle.scaling.y;
                             this._vertex.z *= this._particle.scaling.z;
+
+                            this._vertex.x += this._particle.pivot.x;
+                            this._vertex.y += this._particle.pivot.y;
+                            this._vertex.z += this._particle.pivot.z;
     
                             this._rotated.x = this._vertex.x * this._rotMatrix.m[0] + this._vertex.y * this._rotMatrix.m[4] + this._vertex.z * this._rotMatrix.m[8];
                             this._rotated.y = this._vertex.x * this._rotMatrix.m[1] + this._vertex.y * this._rotMatrix.m[5] + this._vertex.z * this._rotMatrix.m[9];