提交 ed042044 编写于 作者: D Don McCurdy

GLTFLoader: Disambiguate names for multiple instances of the same mesh.

上级 b000372c
...@@ -2225,6 +2225,9 @@ THREE.GLTFLoader = ( function () { ...@@ -2225,6 +2225,9 @@ THREE.GLTFLoader = ( function () {
var nodes = json.nodes || []; var nodes = json.nodes || [];
var skins = json.skins || []; var skins = json.skins || [];
var meshReferences = {};
var meshUses = {};
// Nothing in the node definition indicates whether it is a Bone or an // Nothing in the node definition indicates whether it is a Bone or an
// Object3D. Use the skins' joint references to mark bones. // Object3D. Use the skins' joint references to mark bones.
skins.forEach( function ( skin ) { skins.forEach( function ( skin ) {
...@@ -2237,6 +2240,27 @@ THREE.GLTFLoader = ( function () { ...@@ -2237,6 +2240,27 @@ THREE.GLTFLoader = ( function () {
} ); } );
// Meshes can (and should) be reused by multiple nodes in a glTF asset. To
// avoid having more than one THREE.Mesh with the same name, count
// references and rename instances below.
//
// Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
nodes.forEach( function ( nodeDef ) {
if ( nodeDef.mesh ) {
if ( meshReferences[ nodeDef.mesh ] === undefined ) {
meshReferences[ nodeDef.mesh ] = meshUses[ nodeDef.mesh ] = 0;
}
meshReferences[ nodeDef.mesh ]++;
}
} );
return scope._withDependencies( [ return scope._withDependencies( [
'meshes', 'meshes',
...@@ -2253,7 +2277,15 @@ THREE.GLTFLoader = ( function () { ...@@ -2253,7 +2277,15 @@ THREE.GLTFLoader = ( function () {
} else if ( nodeDef.mesh !== undefined ) { } else if ( nodeDef.mesh !== undefined ) {
return dependencies.meshes[ nodeDef.mesh ].clone(); var mesh = dependencies.meshes[ nodeDef.mesh ].clone();
if ( meshReferences[ nodeDef.mesh ] > 1 ) {
mesh.name += '_instance_' + meshUses[ nodeDef.mesh ]++;
}
return mesh;
} else if ( nodeDef.camera !== undefined ) { } else if ( nodeDef.camera !== undefined ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册