未验证 提交 2480ed0a 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #18907 from zeux/gltf-smaller-bounds

GLTFLoader: Use a smaller bounding box for morph targets
......@@ -2225,6 +2225,7 @@ THREE.GLTFLoader = ( function () {
if ( targets !== undefined ) {
var maxDisplacement = new THREE.Vector3();
var vector = new THREE.Vector3();
for ( var i = 0, il = targets.length; i < il; i ++ ) {
......@@ -2246,7 +2247,11 @@ THREE.GLTFLoader = ( function () {
vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
box.expandByVector( vector );
// Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
// to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
// are used to implement key-frame animations and as such only two are active at a time - this results in very large
// boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
maxDisplacement.max( vector );
} else {
......@@ -2258,6 +2263,9 @@ THREE.GLTFLoader = ( function () {
}
// As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
box.expandByVector( maxDisplacement );
}
geometry.boundingBox = box;
......
......@@ -2288,6 +2288,7 @@ var GLTFLoader = ( function () {
if ( targets !== undefined ) {
var maxDisplacement = new Vector3();
var vector = new Vector3();
for ( var i = 0, il = targets.length; i < il; i ++ ) {
......@@ -2309,7 +2310,11 @@ var GLTFLoader = ( function () {
vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
box.expandByVector( vector );
// Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
// to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
// are used to implement key-frame animations and as such only two are active at a time - this results in very large
// boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
maxDisplacement.max( vector );
} else {
......@@ -2321,6 +2326,9 @@ var GLTFLoader = ( function () {
}
// As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
box.expandByVector( maxDisplacement );
}
geometry.boundingBox = box;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册