瀏覽代碼

Add emitFromSpawnPointOnly to ConeParticleEmitter

David Catuhe 7 年之前
父節點
當前提交
98c83fc6b6

文件差異過大導致無法顯示
+ 10576 - 10572
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 25 - 25
dist/preview release/babylon.js


文件差異過大導致無法顯示
+ 19 - 5
dist/preview release/babylon.max.js


文件差異過大導致無法顯示
+ 19 - 5
dist/preview release/babylon.no-module.max.js


文件差異過大導致無法顯示
+ 25 - 25
dist/preview release/babylon.worker.js


文件差異過大導致無法顯示
+ 19 - 5
dist/preview release/es6.js


文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/viewer/babylon.viewer.js


文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 21 - 4
src/Particles/EmitterTypes/babylon.coneParticleEmitter.ts

@@ -20,6 +20,11 @@ module BABYLON {
         public heightRange = 1;   
 
         /**
+         * Gets or sets a value indicating if all the particles should be emitted from the spawn point only (the base of the cone)
+         */
+        public emitFromSpawnPointOnly = false;
+
+        /**
          * Gets or sets the radius of the emission cone
          */
         public get radius(): number {
@@ -98,9 +103,15 @@ module BABYLON {
          */
         startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle): void {
             var s = Scalar.RandomRange(0, Math.PI * 2);
-            var h = Scalar.RandomRange(0, this.heightRange);
-            // Better distribution in a cone at normal angles.
-            h = 1 - h * h;
+            var h: number;
+            
+            if (!this.emitFromSpawnPointOnly) {
+                h = Scalar.RandomRange(0, this.heightRange);
+                // Better distribution in a cone at normal angles.
+                h = 1 - h * h;
+            } else {
+                h = 0.0001;
+            }
             var radius = this._radius - Scalar.RandomRange(0, this._radius * this.radiusRange);
             radius = radius * h;
 
@@ -139,7 +150,13 @@ module BABYLON {
          * @returns a string containng the defines string
          */
         public getEffectDefines(): string {
-            return "#define CONEEMITTER"
+            let defines = "#define CONEEMITTER";
+
+            if (this.emitFromSpawnPointOnly) {
+                defines += "\n#define CONEEMITTERSPAWNPOINT"
+            }
+
+            return defines;
         }     
         
         /**

+ 10 - 4
src/Shaders/gpuUpdateParticles.vertex.fx

@@ -217,10 +217,16 @@ void main() {
     vec3 randoms2 = getRandomVec3(seed.y);
 
     float s = 2.0 * PI * randoms2.x;
-    float h = randoms2.y * height.y;
-    
-    // Better distribution in a cone at normal angles.
-    h = 1. - h * h;
+
+    #ifdef CONEEMITTERSPAWNPOINT
+        float h = 0.00001;
+    #else
+        float h = randoms2.y * height.y;
+        
+        // Better distribution in a cone at normal angles.
+        h = 1. - h * h;        
+    #endif
+
     float lRadius = radius.x - radius.x * randoms2.z * radius.y;
     lRadius = lRadius * h;