Pārlūkot izejas kodu

Fix noiseTexture issue when added afterwards (Particles)

David Catuhe 6 gadi atpakaļ
vecāks
revīzija
9926aa2292

+ 14 - 1
src/Particles/babylon.baseParticleSystem.ts

@@ -163,10 +163,23 @@ module BABYLON {
          */
         public preventAutoStart: boolean = false;
 
+        private _noiseTexture: Nullable<ProceduralTexture>;
+
         /**
          * Gets or sets a texture used to add random noise to particle positions
          */
-        public noiseTexture: Nullable<ProceduralTexture>;
+        public get noiseTexture(): Nullable<ProceduralTexture> {
+            return this._noiseTexture;
+        }
+
+        public set noiseTexture(value : Nullable<ProceduralTexture>) {
+            if (this._noiseTexture === value) {
+                return;
+            }
+
+            this._noiseTexture = value;
+            this._reset();
+        }
 
         /** Gets or sets the strength to apply to the noise value (default is (10, 10, 10)) */
         public noiseStrength = new Vector3(10, 10, 10);

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

@@ -308,7 +308,7 @@ module BABYLON {
                     particle.position.addInPlace(this._scaledDirection);
 
                     // Noise
-                    if (noiseTextureData && noiseTextureSize) {
+                    if (noiseTextureData && noiseTextureSize && particle._randomNoiseCoordinates1) {
                         let fetchedColorR = this._fetchR(particle._randomNoiseCoordinates1.x, particle._randomNoiseCoordinates1.y, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);
                         let fetchedColorG = this._fetchR(particle._randomNoiseCoordinates1.z, particle._randomNoiseCoordinates2.x, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);
                         let fetchedColorB = this._fetchR(particle._randomNoiseCoordinates2.y, particle._randomNoiseCoordinates2.z, noiseTextureSize.width, noiseTextureSize.height, noiseTextureData);