未验证 提交 75a5d82d 编写于 作者: M Michael Herzog 提交者: GitHub

Merge pull request #18164 from Mugen87/dev29

GLTFLoader: Make .computeBounds() more robust.
...@@ -2291,9 +2291,14 @@ THREE.GLTFLoader = ( function () { ...@@ -2291,9 +2291,14 @@ THREE.GLTFLoader = ( function () {
if ( attributes.POSITION !== undefined ) { if ( attributes.POSITION !== undefined ) {
var accessor = parser.json.accessors[ attributes.POSITION ]; var accessor = parser.json.accessors[ attributes.POSITION ];
var min = accessor.min; var min = accessor.min;
var max = accessor.max; var max = accessor.max;
// glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
if ( min !== undefined && max !== undefined ) {
box.set( box.set(
new THREE.Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ), new THREE.Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
new THREE.Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) ); new THREE.Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) );
...@@ -2304,6 +2309,12 @@ THREE.GLTFLoader = ( function () { ...@@ -2304,6 +2309,12 @@ THREE.GLTFLoader = ( function () {
} }
} else {
return;
}
var targets = primitiveDef.targets; var targets = primitiveDef.targets;
if ( targets !== undefined ) { if ( targets !== undefined ) {
...@@ -2320,6 +2331,10 @@ THREE.GLTFLoader = ( function () { ...@@ -2320,6 +2331,10 @@ THREE.GLTFLoader = ( function () {
var min = accessor.min; var min = accessor.min;
var max = accessor.max; var max = accessor.max;
// glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
if ( min !== undefined && max !== undefined ) {
// we need to get max of absolute components because target weight is [-1,1] // we need to get max of absolute components because target weight is [-1,1]
vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) ); vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) ); vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
...@@ -2333,6 +2348,8 @@ THREE.GLTFLoader = ( function () { ...@@ -2333,6 +2348,8 @@ THREE.GLTFLoader = ( function () {
} }
}
geometry.boundingBox = box; geometry.boundingBox = box;
var sphere = new THREE.Sphere(); var sphere = new THREE.Sphere();
......
...@@ -2358,9 +2358,14 @@ var GLTFLoader = ( function () { ...@@ -2358,9 +2358,14 @@ var GLTFLoader = ( function () {
if ( attributes.POSITION !== undefined ) { if ( attributes.POSITION !== undefined ) {
var accessor = parser.json.accessors[ attributes.POSITION ]; var accessor = parser.json.accessors[ attributes.POSITION ];
var min = accessor.min; var min = accessor.min;
var max = accessor.max; var max = accessor.max;
// glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
if ( min !== undefined && max !== undefined ) {
box.set( box.set(
new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ), new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) ); new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] ) );
...@@ -2371,6 +2376,12 @@ var GLTFLoader = ( function () { ...@@ -2371,6 +2376,12 @@ var GLTFLoader = ( function () {
} }
} else {
return;
}
var targets = primitiveDef.targets; var targets = primitiveDef.targets;
if ( targets !== undefined ) { if ( targets !== undefined ) {
...@@ -2387,6 +2398,10 @@ var GLTFLoader = ( function () { ...@@ -2387,6 +2398,10 @@ var GLTFLoader = ( function () {
var min = accessor.min; var min = accessor.min;
var max = accessor.max; var max = accessor.max;
// glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
if ( min !== undefined && max !== undefined ) {
// we need to get max of absolute components because target weight is [-1,1] // we need to get max of absolute components because target weight is [-1,1]
vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) ); vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) ); vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
...@@ -2400,6 +2415,8 @@ var GLTFLoader = ( function () { ...@@ -2400,6 +2415,8 @@ var GLTFLoader = ( function () {
} }
}
geometry.boundingBox = box; geometry.boundingBox = box;
var sphere = new Sphere(); var sphere = new Sphere();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册