0

在我的项目中,我正在创建 LineSegments(LineMesh),其中包含来自另一个网格的修改几何(更改顶点位置)和MeshBasicMaterial黑色。将其LineMesh添加到已经存在的网格中。一切正常。但是现在我想通过从几何体的面visible中将属性设置为 false来隐藏网格的特定部分。但是在这种情况下,先前创建的网格是隐藏的,但添加到它上面并没有隐藏。是否可以隐藏特定部分,并且还想知道是否会支持。这样我就可以轻松地将属性应用到特定部分。materialIndexLineMeshLineMeshLineMeshMultiMaterialvisibilitytransparentMesh

var mesh, renderer, scene, camera, materials;

init();
animate();

function init() {

// renderer
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );

// scene
scene = new THREE.Scene();

// camera
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
camera.position.z = 300;
camera.lookAt( scene.position );

// directional
var light = new THREE.DirectionalLight( 0xffffff );
light.position.set( 1, 1, 1 );
scene.add( light );

// ambient
var ambient = new THREE.AmbientLight( 0x222222 );
scene.add( ambient );

// 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( { color: 0x00ffff, side: THREE.DoubleSide } )
];

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

mat = new THREE.LineBasicMaterial({color: 0x000000});
mesh2= new THREE.LineSegments(geometry, mat);
mesh.add(mesh2);

}

function animate() {

requestAnimationFrame( animate );

mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
mesh.rotation.z += 0.03;

renderer.render( scene, camera );

}

下面的代码不适用于 LineSegments

mesh2= new THREE.LineSegments(geometry, new THREE.MultiMaterial(materials));  
4

0 回答 0