浏览代码

Merge pull request #6009 from bghgary/skin-bb-fix

Fix a bug with bounding box calculation when using skeleton.overrideMesh
David Catuhe 6 年之前
父节点
当前提交
323eea6a4b
共有 2 个文件被更改,包括 10 次插入8 次删除
  1. 7 2
      src/Meshes/abstractMesh.ts
  2. 3 6
      src/Meshes/mesh.ts

+ 7 - 2
src/Meshes/abstractMesh.ts

@@ -1204,7 +1204,8 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
                 var matricesIndicesExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesIndicesExtraKind) : null;
                 var matricesWeightsExtraData = needExtras ? this.getVerticesData(VertexBuffer.MatricesWeightsExtraKind) : null;
 
-                var skeletonMatrices = this.skeleton.getTransformMatrices(this);
+                this.skeleton.prepare();
+                var skeletonMatrices = this.skeleton.getTransformMatrices(this._effectiveMesh);
 
                 var tempVector = Tmp.Vector3[0];
                 var finalMatrix = Tmp.Matrix[0];
@@ -1244,7 +1245,7 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
 
     /** @hidden */
     public _updateBoundingInfo(): AbstractMesh {
-        const effectiveMesh = (this.skeleton && this.skeleton.overrideMesh) || this;
+        const effectiveMesh = this._effectiveMesh;
         if (this._boundingInfo) {
             this._boundingInfo.update(effectiveMesh.worldMatrixFromCache);
         }
@@ -1276,6 +1277,10 @@ export class AbstractMesh extends TransformNode implements IDisposable, ICullabl
         this._updateBoundingInfo();
     }
 
+    protected get _effectiveMesh(): AbstractMesh {
+        return (this.skeleton && this.skeleton.overrideMesh) || this;
+    }
+
     /**
      * Returns `true` if the mesh is within the frustum defined by the passed array of planes.
      * A mesh is in the frustum if its bounding box intersects the frustum

+ 3 - 6
src/Meshes/mesh.ts

@@ -1442,9 +1442,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
         var offset = 0;
         var instancesCount = 0;
 
-        const effectiveMesh = (this.skeleton && this.skeleton.overrideMesh) || this;
-
-        var world = effectiveMesh.getWorldMatrix();
+        var world = this._effectiveMesh.getWorldMatrix();
         if (batch.renderSelf[subMesh._id]) {
             world.copyToArray(instanceStorage.instancesData, offset);
             offset += 16;
@@ -1488,7 +1486,6 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
         onBeforeDraw: (isInstance: boolean, world: Matrix, effectiveMaterial?: Material) => void, effectiveMaterial?: Material): Mesh {
         var scene = this.getScene();
         var engine = scene.getEngine();
-        const effectiveMesh = (this.skeleton && this.skeleton.overrideMesh) || this;
 
         if (hardwareInstancedRendering) {
             this._renderWithInstances(subMesh, fillMode, batch, effect, engine);
@@ -1496,7 +1493,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
             if (batch.renderSelf[subMesh._id]) {
                 // Draw
                 if (onBeforeDraw) {
-                    onBeforeDraw(false, effectiveMesh.getWorldMatrix(), effectiveMaterial);
+                    onBeforeDraw(false, this._effectiveMesh.getWorldMatrix(), effectiveMaterial);
                 }
 
                 this._draw(subMesh, fillMode, this._instanceDataStorage.overridenInstanceCount);
@@ -1590,7 +1587,7 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
             return this;
         }
 
-        const effectiveMesh = (this.skeleton && this.skeleton.overrideMesh) || this;
+        const effectiveMesh = this._effectiveMesh;
 
         var sideOrientation = this.overrideMaterialSideOrientation;
         if (sideOrientation == null) {