我可以在three.js中隐藏网格的面吗? [英] Can I hide faces of a mesh in three.js?

查看:368
本文介绍了我可以在three.js中隐藏网格的面吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时使网格的一部分不可见。我可以将这些部件设置为不可见/透明,例如通过改变单面的属性?网格本身只使用一种材质。

I want to make parts of a mesh invisible at runtime. Can I set these parts invisible/transparent, e.g. by changing attributes of single faces? The mesh itself uses only one material.

编辑器<示例 理解这个问题:想象一个网格(这里有20个顶点的几何),其中四个顶点的每个四边形构建一个 Face4 。现在,网格的某些部分应该是不可见的(这里两个面是不可见的)。

Exemplary illustration as the editor understands this question: Imagine a mesh (here with a geometry of 20 vertices) where each quad of four vertices builds up a Face4. Now, some parts of the mesh should be made invisible (here two faces are invisible).

推荐答案

您可以为每个面指定不同的材质。以下是面部共享材质的示例,但有些面部是透明的:

You can assign a different material to each face. Here is an example where the faces share a material, but some faces are transparent:

// geometry
var geometry = new THREE.BoxGeometry( 100, 100, 100, 4, 4, 4 );

// materials
materials = [
    new THREE.MeshLambertMaterial( { color: 0xffff00, side: THREE.DoubleSide } ),
    new THREE.MeshBasicMaterial( { transparent: true, opacity: 0 } )
];

// assign material to each face
for( var i = 0; i < geometry.faces.length; i++ ) {
    geometry.faces[ i ].materialIndex = THREE.Math.randInt( 0, 1 );
}
geometry.sortFacesByMaterialIndex(); // optional, to reduce draw calls

// mesh
mesh = new THREE.Mesh( geometry, materials );
scene.add( mesh );

更新小提琴显示在运行时更改材料的一种方法: http://jsfiddle.net/e0x88z7w/

Updated Fiddle showing one way to change a material at runtime: http://jsfiddle.net/e0x88z7w/

编辑: MeshFaceMaterial 已被弃用。帖子和小提琴更新。

MeshFaceMaterial has been deprecated. Post and fiddle updated.

three.js r.87

three.js r.87

这篇关于我可以在three.js中隐藏网格的面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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