从对象(THREE.JS和GLTF)创建网格阵列 [英] Create an Array of Meshes from Object (THREE.JS and GLTF)
本文介绍了从对象(THREE.JS和GLTF)创建网格阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的一段代码,该代码将网格物体加载到对象上.目前,它遍历了整个事物.
Below is my piece of code which loads a mesh onto the object. At the moment its traversing through the entire thing.
当前代码:
var loader = new THREE.GLTFLoader();
loader.load( '../gtf/Box.gltf', function ( gltf ) {
model = gltf.scene;
gltf.scene.traverse( function ( child ) {
if ( child.isMesh ) {
child.material.map = texture;
}
} );
scene.add( model);
} );
我将如何制作children[]
的数组?然后每个孩子都会允许我分配单独的纹理.
How would I go about making an array of children[]
? Each child will would then allow me to assign separate textures.
我已经在Blender中使用单独的网格和材质制作了模型.
I have made the model in Blender with separate meshes and materials.
在THREE.JS中,我希望能够运行:
In THREE.JS, I want to be able to go:
children[0].material.map = blueTexture;
children[1].material.map = greenTexture;
等
推荐答案
如果我正确理解了您的问题,则可以执行以下操作:
If I understand your question correctly, you could do the following:
var loader = new THREE.GLTFLoader();
loader.load( '../gtf/Box.gltf', function ( gltf ) {
model = gltf.scene;
var children = []
// Construct array of children during traversal of gltf object
gltf.scene.traverse( function ( child ) {
if ( child.isMesh ) {
children.push(child)
}
} );
// Assuming array length is 2 or more, and blueTexture/greenTexture are defined
children[0].material.map = blueTexture;
children[1].material.map = greenTexture;
scene.add( model);
} );
这篇关于从对象(THREE.JS和GLTF)创建网格阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文