浏览代码

Fix SPS intersection and BBox computation

sebavan 6 年之前
父节点
当前提交
b997f9d6a1
共有 1 个文件被更改,包括 6 次插入1 次删除
  1. 6 1
      src/Particles/solidParticleSystem.ts

+ 6 - 1
src/Particles/solidParticleSystem.ts

@@ -284,12 +284,17 @@ export class SolidParticleSystem implements IDisposable {
             barycenter.scaleInPlace(1 / shape.length);
 
             // shift the shape from its barycenter to the origin
+            // and compute the BBox required for intersection.
+            var minimum: Vector3 = new Vector3(Infinity, Infinity, Infinity);
+            var maximum: Vector3 = new Vector3(-Infinity, -Infinity, -Infinity);
             for (v = 0; v < shape.length; v++) {
                 shape[v].subtractInPlace(barycenter);
+                minimum.minimizeInPlaceFromFloats(shape[v].x, shape[v].y, shape[v].z);
+                maximum.maximizeInPlaceFromFloats(shape[v].x, shape[v].y, shape[v].z);
             }
             var bInfo;
             if (this._particlesIntersect) {
-                bInfo = new BoundingInfo(barycenter, barycenter);
+                bInfo = new BoundingInfo(minimum, maximum);
             }
             var modelShape = new ModelShape(this._shapeCounter, shape, size * 3, shapeUV, null, null);