Three.js:为场景中的每个网格循环? [英] Three.js: for loop for every mesh in scene?

查看:195
本文介绍了Three.js:为场景中的每个网格循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想要做的事情是

scene.forEachMeshInScene(function(mesh){
      //And here I can do stuff
});

但遗憾的是,这不存在。我该怎么做?

But sadly, that doesn't exist. How can I do something like this?

推荐答案

您可以使用以下模式迭代网格 场景中的对象图表:

You can use the following pattern to iterate over the Mesh objects in the scene graph:

scene.traverse( function( node ) {

    if ( node instanceof THREE.Mesh ) {

        // insert your code here, for example:
        node.material = new THREE.MeshNormalMaterial()

    }

} );

three.js r.69

three.js r.69

这篇关于Three.js:为场景中的每个网格循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆