浏览代码

Added sphereEmitter.radiusRange

David Catuhe 7 年之前
父节点
当前提交
afe9d83462

文件差异内容过多而无法显示
+ 5275 - 5271
dist/preview release/babylon.d.ts


文件差异内容过多而无法显示
+ 4 - 4
dist/preview release/babylon.js


文件差异内容过多而无法显示
+ 9 - 3
dist/preview release/babylon.max.js


文件差异内容过多而无法显示
+ 9 - 3
dist/preview release/babylon.no-module.max.js


文件差异内容过多而无法显示
+ 4 - 4
dist/preview release/babylon.worker.js


文件差异内容过多而无法显示
+ 9 - 3
dist/preview release/es6.js


文件差异内容过多而无法显示
+ 6 - 6
dist/preview release/viewer/babylon.viewer.js


文件差异内容过多而无法显示
+ 9 - 3
dist/preview release/viewer/babylon.viewer.max.js


+ 1 - 0
dist/preview release/what's new.md

@@ -33,6 +33,7 @@
 - AssetsManager tasks will only run when their state is INIT. It is now possible to remove a task from the assets manager ([RaananW](https://github.com/RaananW))
 - Added sprite isVisible field ([TrevorDev](https://github.com/TrevorDev))
 - Added support for `minScaleX`, `minScaleY`, `maxScaleX`, `maxScaleY` for particles ([Deltakosh](https://github.com/deltakosh))
+- Added support for `radiusRange` for sphere particle emitter ([Deltakosh](https://github.com/deltakosh))
 
 ### glTF Loader
 

+ 8 - 2
src/Particles/EmitterTypes/babylon.sphereParticleEmitter.ts

@@ -6,6 +6,11 @@ module BABYLON {
     export class SphereParticleEmitter implements IParticleEmitterType {
 
         /**
+         * Gets or sets a value indicating where on the radius the start position should be picked (1 = everywhere, 0 = only surface)
+         */
+        public radiusRange = 1;
+
+        /**
          * Creates a new instance SphereParticleEmitter
          * @param radius the radius of the emission sphere (1 by default)
          * @param directionRandomizer defines how much to randomize the particle direction [0-1]
@@ -19,7 +24,6 @@ module BABYLON {
              * How much to randomize the particle direction [0-1].
              */
             public directionRandomizer = 0) {
-
         }
 
         /**
@@ -51,7 +55,7 @@ module BABYLON {
         public startPositionFunction(worldMatrix: Matrix, positionToUpdate: Vector3, particle: Particle): void {
             var phi = Scalar.RandomRange(0, 2 * Math.PI);
             var theta = Scalar.RandomRange(0, Math.PI);
-            var randRadius = Scalar.RandomRange(0, this.radius);
+            var randRadius = this.radius - Scalar.RandomRange(0, this.radius * this.radiusRange);
             var randX = randRadius * Math.cos(phi) * Math.sin(theta);
             var randY = randRadius * Math.cos(theta);
             var randZ = randRadius * Math.sin(phi) * Math.sin(theta);
@@ -76,6 +80,7 @@ module BABYLON {
          */        
         public applyToShader(effect: Effect): void {
             effect.setFloat("radius", this.radius);
+            effect.setFloat("radiusRange", this.radiusRange);
             effect.setFloat("directionRandomizer", this.directionRandomizer);
         }    
         
@@ -174,6 +179,7 @@ module BABYLON {
          */        
         public applyToShader(effect: Effect): void {
             effect.setFloat("radius", this.radius);
+            effect.setFloat("radiusRange", this.radiusRange);
             effect.setVector3("direction1", this.direction1);
             effect.setVector3("direction2", this.direction2);
         }       

+ 1 - 1
src/Particles/babylon.gpuParticleSystem.ts

@@ -376,7 +376,7 @@
                 attributes: ["position", "age", "life", "seed", "size", "color", "direction", "angle"],
                 uniformsNames: ["currentCount", "timeDelta", "generalRandoms", "emitterWM", "lifeTime", "color1", "color2", "sizeRange", "scaleRange","gravity", "emitPower",
                                 "direction1", "direction2", "minEmitBox", "maxEmitBox", "radius", "directionRandomizer", "height", "coneAngle", "stopFactor", 
-                                "angleRange"],
+                                "angleRange", "radiusRange"],
                 uniformBuffersNames: [],
                 samplers:["randomSampler"],
                 defines: "",

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

@@ -26,12 +26,13 @@ uniform vec3 maxEmitBox;
 
 #ifdef SPHEREEMITTER
 uniform float radius;
-  #ifdef DIRECTEDSPHEREEMITTER
+uniform float radiusRange;
+#ifdef DIRECTEDSPHEREEMITTER
   uniform vec3 direction1;
   uniform vec3 direction2;
-  #else
+#else
   uniform float directionRandomizer;
-  #endif
+#endif
 #endif
 
 #ifdef CONEEMITTER
@@ -127,7 +128,7 @@ void main() {
     float randY = cos(theta);
     float randZ = sin(phi) * sin(theta);
 
-    position = (radius * randoms2.z) * vec3(randX, randY, randZ);
+    position = (radius - (radius * radiusRange * randoms2.z)) * vec3(randX, randY, randZ);
 
     #ifdef DIRECTEDSPHEREEMITTER
       direction = direction1 + (direction2 - direction1) * randoms3;