فهرست منبع

Add the possibility to use the bounding info defined at the geometry class level as the meshes bounding info

Popov72 5 سال پیش
والد
کامیت
3427b94d8e
1فایلهای تغییر یافته به همراه22 افزوده شده و 6 حذف شده
  1. 22 6
      src/Meshes/geometry.ts

+ 22 - 6
src/Meshes/geometry.ts

@@ -113,6 +113,12 @@ export class Geometry implements IGetSetVerticesData {
     }
 
     /**
+     * If set to true (false by defaut), the bounding info applied to the meshes sharing this geometry will be the bounding info defined at the class level
+     * and won't be computed based on the vertex positions (which is what we get when useBoundingInfoFromGeometry = false)
+     */
+    public useBoundingInfoFromGeometry = false;
+
+    /**
      * Creates a new geometry
      * @param id defines the unique ID
      * @param scene defines the hosting scene
@@ -275,9 +281,12 @@ export class Geometry implements IGetSetVerticesData {
             var meshes = this._meshes;
             var numOfMeshes = meshes.length;
 
+            var minimum = this.useBoundingInfoFromGeometry && this._boundingInfo ? this._boundingInfo.minimum : this._extend.minimum;
+            var maximum = this.useBoundingInfoFromGeometry && this._boundingInfo ? this._boundingInfo.maximum : this._extend.maximum;
+
             for (var index = 0; index < numOfMeshes; index++) {
                 var mesh = meshes[index];
-                mesh._boundingInfo = new BoundingInfo(this._extend.minimum, this._extend.maximum);
+                mesh._boundingInfo = new BoundingInfo(minimum, maximum);
                 mesh._createGlobalSubMesh(false);
                 mesh.computeWorldMatrix(true);
             }
@@ -341,13 +350,16 @@ export class Geometry implements IGetSetVerticesData {
         this._resetPointsArrayCache();
 
         if (updateExtends) {
+            var minimum = this.useBoundingInfoFromGeometry && this._boundingInfo ? this._boundingInfo.minimum : this._extend.minimum;
+            var maximum = this.useBoundingInfoFromGeometry && this._boundingInfo ? this._boundingInfo.maximum : this._extend.maximum;
+
             var meshes = this._meshes;
             for (const mesh of meshes) {
                 if (mesh._boundingInfo) {
-                    mesh._boundingInfo.reConstruct(this._extend.minimum, this._extend.maximum);
+                    mesh._boundingInfo.reConstruct(minimum, maximum);
                 }
                 else {
-                    mesh._boundingInfo = new BoundingInfo(this._extend.minimum, this._extend.maximum);
+                    mesh._boundingInfo = new BoundingInfo(minimum, maximum);
                 }
 
                 const subMeshes = mesh.subMeshes;
@@ -717,10 +729,14 @@ export class Geometry implements IGetSetVerticesData {
             }
 
             if (kind === VertexBuffer.PositionKind) {
-                if (!this._extend) {
-                    this._updateExtend();
+                if (this.useBoundingInfoFromGeometry && this._boundingInfo) {
+                    mesh._boundingInfo = new BoundingInfo(this._boundingInfo.minimum, this._boundingInfo.maximum);
+                } else {
+                    if (!this._extend) {
+                        this._updateExtend();
+                    }
+                    mesh._boundingInfo = new BoundingInfo(this._extend.minimum, this._extend.maximum);
                 }
-                mesh._boundingInfo = new BoundingInfo(this._extend.minimum, this._extend.maximum);
 
                 mesh._createGlobalSubMesh(false);