소스 검색

Box3: Better support for animated objects in `expandByObject()` in precise mode. (#26919)

Michael Herzog 1 년 전
부모
커밋
8735897544
2개의 변경된 파일42개의 추가작업 그리고 18개의 파일을 삭제
  1. 7 0
      editor/js/Viewport.js
  2. 35 18
      src/math/Box3.js

+ 7 - 0
editor/js/Viewport.js

@@ -713,6 +713,13 @@ function Viewport( editor ) {
 			mixer.update( delta );
 			needsUpdate = true;
 
+			if ( editor.selected !== null ) {
+
+				editor.selected.updateWorldMatrix( false, true ); // avoid frame late effect for certain skinned meshes (e.g. Michelle.glb)
+				selectionBox.box.setFromObject( editor.selected, true ); // selection box should reflect current animation state
+
+			}
+
 		}
 
 		// View Helper

+ 35 - 18
src/math/Box3.js

@@ -159,37 +159,53 @@ class Box3 {
 
 		object.updateWorldMatrix( false, false );
 
-		if ( object.boundingBox !== undefined ) {
+		const geometry = object.geometry;
 
-			if ( object.boundingBox === null ) {
+		if ( geometry !== undefined ) {
 
-				object.computeBoundingBox();
+			const positionAttribute = geometry.getAttribute( 'position' );
 
-			}
+			// precise AABB computation based on vertex data requires at least a position attribute.
+			// instancing isn't supported so far and uses the normal (conservative) code path.
 
-			_box.copy( object.boundingBox );
-			_box.applyMatrix4( object.matrixWorld );
+			if ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) {
 
-			this.union( _box );
+				for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
 
-		} else {
+					if ( object.isMesh === true ) {
+
+						object.getVertexPosition( i, _vector );
+
+					} else {
+
+						_vector.fromBufferAttribute( positionAttribute, i );
+
+					}
+
+					_vector.applyMatrix4( object.matrixWorld );
+					this.expandByPoint( _vector );
 
-			const geometry = object.geometry;
+				}
+
+			} else {
 
-			if ( geometry !== undefined ) {
+				if ( object.boundingBox !== undefined ) {
 
-				if ( precise && geometry.attributes !== undefined && geometry.attributes.position !== undefined ) {
+					// object-level bounding box
 
-					const position = geometry.attributes.position;
-					for ( let i = 0, l = position.count; i < l; i ++ ) {
+					if ( object.boundingBox === null ) {
 
-						_vector.fromBufferAttribute( position, i ).applyMatrix4( object.matrixWorld );
-						this.expandByPoint( _vector );
+						object.computeBoundingBox();
 
 					}
 
+					_box.copy( object.boundingBox );
+
+
 				} else {
 
+					// geometry-level bounding box
+
 					if ( geometry.boundingBox === null ) {
 
 						geometry.computeBoundingBox();
@@ -197,12 +213,13 @@ class Box3 {
 					}
 
 					_box.copy( geometry.boundingBox );
-					_box.applyMatrix4( object.matrixWorld );
-
-					this.union( _box );
 
 				}
 
+				_box.applyMatrix4( object.matrixWorld );
+
+				this.union( _box );
+
 			}
 
 		}