admin管理员组

文章数量:1201156

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.


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).

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.


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).

Share Improve this question edited Oct 8, 2013 at 21:47 user128511 asked Jun 14, 2012 at 0:38 user1455053user1455053 1511 silver badge3 bronze badges 2
  • Your question is not really clear. Are you trying to set faces' visibility as false (make them invisible)? – frank Commented Jun 14, 2012 at 11:30
  • I edited this question in a way I am understanding it. Especially, because I am having this question also and don't want to create a duplicate. – Matthias Commented Aug 23, 2012 at 1:56
Add a comment  | 

1 Answer 1

Reset to default 24 +50

Note: This answer applies to legacy versions of three.js


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 );

three.js r.87

本文标签: javascriptCan I hide faces of a mesh in threejsStack Overflow