瀏覽代碼

fix SPS insertParticlesFromArray : now the positionFunction can be run

Jérôme Bousquié 5 年之前
父節點
當前提交
cf52cf24aa
共有 2 個文件被更改,包括 19 次插入8 次删除
  1. 6 1
      src/Particles/solidParticle.ts
  2. 13 7
      src/Particles/solidParticleSystem.ts

+ 6 - 1
src/Particles/solidParticle.ts

@@ -168,7 +168,12 @@ export class SolidParticle {
         }
         }
         target.scaling.copyFrom(this.scaling);
         target.scaling.copyFrom(this.scaling);
         if (this.color) {
         if (this.color) {
-            target.color!.copyFrom(this.color!);
+            if (target.color) {
+                target.color!.copyFrom(this.color!);
+            }
+            else {
+                target.color = this.color.clone();
+            }
         }
         }
         target.uvs.copyFrom(this.uvs);
         target.uvs.copyFrom(this.uvs);
         target.velocity.copyFrom(this.velocity);
         target.velocity.copyFrom(this.velocity);

+ 13 - 7
src/Particles/solidParticleSystem.ts

@@ -105,6 +105,7 @@ export class SolidParticleSystem implements IDisposable {
     private _expandable: boolean = false;
     private _expandable: boolean = false;
     private _shapeCounter: number = 0;
     private _shapeCounter: number = 0;
     private _copy: SolidParticle = new SolidParticle(0, 0, 0, 0, null, 0, 0, this);
     private _copy: SolidParticle = new SolidParticle(0, 0, 0, 0, null, 0, 0, this);
+    private _mustResetCopy: boolean = true;
     private _color: Color4 = new Color4(0, 0, 0, 0);
     private _color: Color4 = new Color4(0, 0, 0, 0);
     private _computeParticleColor: boolean = true;
     private _computeParticleColor: boolean = true;
     private _computeParticleTexture: boolean = true;
     private _computeParticleTexture: boolean = true;
@@ -418,13 +419,11 @@ export class SolidParticleSystem implements IDisposable {
         var c = 0;
         var c = 0;
         var n = 0;
         var n = 0;
 
 
-        this._resetCopy();
+        if (this._mustResetCopy) {
+            this._resetCopy();
+        }
         const copy = this._copy;
         const copy = this._copy;
         const storeApart = (options && options.storage) ? true : false;
         const storeApart = (options && options.storage) ? true : false;
-        // in case the particle geometry must NOT be inserted in the SPS mesh geometry
-        if (storeApart) {
-            return copy;
-        }
         copy.idx = idx;
         copy.idx = idx;
         copy.idxInShape = idxInShape;
         copy.idxInShape = idxInShape;
 
 
@@ -433,6 +432,11 @@ export class SolidParticleSystem implements IDisposable {
             this._mustUnrotateFixedNormals = true;
             this._mustUnrotateFixedNormals = true;
         }
         }
 
 
+        // in case the particle geometry must NOT be inserted in the SPS mesh geometry
+        if (storeApart) {
+            return copy;
+        }
+
         const rotMatrix = TmpVectors.Matrix[0];
         const rotMatrix = TmpVectors.Matrix[0];
         const tmpVertex = TmpVectors.Vector3[0];
         const tmpVertex = TmpVectors.Vector3[0];
         const tmpRotated = TmpVectors.Vector3[1];
         const tmpRotated = TmpVectors.Vector3[1];
@@ -739,6 +743,7 @@ export class SolidParticleSystem implements IDisposable {
         if (!this._expandable) {
         if (!this._expandable) {
             return this;
             return this;
         }
         }
+        this._mustResetCopy = false;
         var idxInShape = 0;
         var idxInShape = 0;
         var  currentShapeId = solidParticleArray[0].shapeId;
         var  currentShapeId = solidParticleArray[0].shapeId;
         const nb = solidParticleArray.length;
         const nb = solidParticleArray.length;
@@ -751,14 +756,15 @@ export class SolidParticleSystem implements IDisposable {
             var meshCol = model._shapeColors;
             var meshCol = model._shapeColors;
             var meshNor = model._normals;
             var meshNor = model._normals;
             var bbInfo = sp._boundingInfo;
             var bbInfo = sp._boundingInfo;
-            var particle = this._insertNewParticle(this.nbParticles, idxInShape, sp._model, shape, meshInd, meshUV, meshCol, meshNor, bbInfo, null, null);
-            sp.copyToRef(particle!);
+            sp.copyToRef(this._copy);
+            this._insertNewParticle(this.nbParticles, idxInShape, sp._model, shape, meshInd, meshUV, meshCol, meshNor, bbInfo, null, null);
             idxInShape++;
             idxInShape++;
             if (currentShapeId != sp.shapeId) {
             if (currentShapeId != sp.shapeId) {
                 currentShapeId = sp.shapeId;
                 currentShapeId = sp.shapeId;
                 idxInShape = 0;
                 idxInShape = 0;
             }
             }
         }
         }
+        this._mustResetCopy = true;
         this._isNotBuilt = true;        // buildMesh() call is now expected for setParticles() to work
         this._isNotBuilt = true;        // buildMesh() call is now expected for setParticles() to work
         return this;
         return this;
     }
     }