فهرست منبع

Merge pull request #8059 from jbousquie/fix.ExpandableSPSPicking

fix bug in picking on expandable SPS
David Catuhe 5 سال پیش
والد
کامیت
1bbc3692cf
2فایلهای تغییر یافته به همراه38 افزوده شده و 11 حذف شده
  1. 1 0
      dist/preview release/what's new.md
  2. 37 11
      src/Particles/solidParticleSystem.ts

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

@@ -118,6 +118,7 @@
 
 - Fix infinite loop in `GlowLayer.unReferenceMeshFromUsingItsOwnMaterial` ([Popov72](https://github.com/Popov72)
 - Fix picking issue in the Solid Particle System when MultiMaterial is enabled ([jerome](https://github.com/jbousquie))
+- Fix picking issue in the Solid Particle System when expandable ([jerome](https://github.com/jbousquie))
 - `QuadraticErrorSimplification` was not exported ([RaananW](https://github.com/Raananw)
 - Fix NME Frames bug where collapsing and moving a frame removed the nodes inside ([belfortk](https://github.com/belfortk)
 - Fix moving / disappearing controls when freezing/unfreezing the ScrollViewer ([Popov72](https://github.com/Popov72)

+ 37 - 11
src/Particles/solidParticleSystem.ts

@@ -248,6 +248,22 @@ export class SolidParticleSystem implements IDisposable {
         vertexData.applyToMesh(this.mesh, this._updatable);
         this.mesh.isPickable = this._pickable;
 
+        if (this._pickable) {
+            let faceId = 0;
+            for (let p = 0; p < this.nbParticles; p++) {
+                let part = this.particles[p];
+                let lind = part._model._indicesLength;
+                for (let i = 0; i < lind; i++) {
+                    let f = i % 3;
+                    if (f == 0) {
+                        const pickedData = {idx: part.idx, faceId: faceId};
+                        this.pickedParticles[faceId] = pickedData;
+                        faceId++;
+                    }
+                }
+            }
+        }
+
         if (this._multimaterialEnabled) {
             this.setMultiMaterial(this._materials);
         }
@@ -573,13 +589,6 @@ export class SolidParticleSystem implements IDisposable {
             }
         }
 
-        if (this._pickable) {
-            var nbfaces = meshInd.length / 3;
-            for (i = 0; i < nbfaces; i++) {
-                this.pickedParticles.push({ idx: idx, faceId: i });
-            }
-        }
-
         if (this._depthSort || this._multimaterialEnabled) {
             var matIndex = (copy.materialIndex !== null) ? copy.materialIndex : 0;
             this.depthSortedParticles.push(new DepthSortedParticle(idx, ind, meshInd.length, matIndex));
@@ -1266,12 +1275,23 @@ export class SolidParticleSystem implements IDisposable {
                 depthSortedParticles.sort(this._depthSortFunction);
                 const dspl = depthSortedParticles.length;
                 let sid = 0;
+                let faceId = 0;
                 for (let sorted = 0; sorted < dspl; sorted++) {
-                    const lind = depthSortedParticles[sorted].indicesLength;
-                    const sind = depthSortedParticles[sorted].ind;
+                    const sortedParticle = depthSortedParticles[sorted];
+                    const lind = sortedParticle.indicesLength;
+                    const sind = sortedParticle.ind;
                     for (var i = 0; i < lind; i++) {
                         indices32[sid] = indices[sind + i];
                         sid++;
+                        if (this._pickable) {
+                            let f = i % 3;
+                            if (f == 0) {
+                                let pickedData = this.pickedParticles[faceId];
+                                pickedData.idx = sortedParticle.idx;
+                                pickedData.faceId = faceId;
+                                faceId++;
+                            }
+                        }
                     }
                 }
                 mesh.updateIndices(indices32);
@@ -1475,8 +1495,14 @@ export class SolidParticleSystem implements IDisposable {
                 if (this._pickable) {
                     let f = i % 3;
                     if (f == 0) {
-                        const pickedData = {idx: sortedPart.idx, faceId: faceId};
-                        this.pickedBySubMesh[subMeshIndex][subMeshFaceId] = pickedData;
+                        let pickedData = this.pickedBySubMesh[subMeshIndex][subMeshFaceId];
+                        if (pickedData) {
+                            pickedData.idx = sortedPart.idx;
+                            pickedData.faceId = faceId;
+                        }
+                        else {
+                            this.pickedBySubMesh[subMeshIndex][subMeshFaceId] = {idx: sortedPart.idx, faceId: faceId};
+                        }
                         subMeshFaceId++;
                         faceId++;
                     }