Browse Source

Fix computeBoundingBox/Sphere for relative morph targets

expandByVector is not correct to call here; if a morph target has a min
of [1,1,1], it should *not* change the box.min but it should expand
box.max by 1.

To avoid doing per-component math we use addVectors to get the corners
of the box, and use expandByPoint to union the box with the resulting
point.
Arseny Kapoulkine 5 years ago
parent
commit
1ecba90e02
1 changed files with 10 additions and 4 deletions
  1. 10 4
      src/core/BufferGeometry.js

+ 10 - 4
src/core/BufferGeometry.js

@@ -599,8 +599,11 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 					if ( this.morphTargetsRelative ) {
 
-						this.boundingBox.expandByVector( _box.min );
-						this.boundingBox.expandByVector( _box.max );
+						_vector.addVectors( this.boundingBox.min, _box.min );
+						this.boundingBox.expandByPoint( _vector );
+
+						_vector.addVectors( this.boundingBox.max, _box.max );
+						this.boundingBox.expandByPoint( _vector );
 
 					} else {
 
@@ -657,8 +660,11 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
 
 					if ( this.morphTargetsRelative ) {
 
-						_box.expandByVector( _boxMorphTargets.min );
-						_box.expandByVector( _boxMorphTargets.max );
+						_vector.addVectors( _box.min, _boxMorphTargets.min );
+						_box.expandByPoint( _vector );
+
+						_vector.addVectors( _box.max, _boxMorphTargets.max );
+						_box.expandByPoint( _vector );
 
 					} else {