如何使用Three.js将透明度设置为自定义几何体的单面?

时间:2013-01-03 13:47:41

标签: three.js

我使用sqaure-base的自定义几何体,它看起来像一个圆锥体。这里是jsfiddle链接:http://jsfiddle.net/suvKg/18/

我在这里获得了整个对象的透明度:

 var meshMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, opacity: 0.6, depthWrite: false, depthTest: false, vertexColors: THREE.VertexColors } ); 

但我不希望透明度应用于锥体的底部,但只有侧面应该有它。怎么做?

1 个答案:

答案 0 :(得分:2)

您需要为整个网格使用THREE.MeshFaceMaterial()。例如,如果您的geometry有X个面和2个不同的材料:

var materials = [
  new THREE.MeshLambertMaterial( { color: 0xffffff, opacity: 0.6, depthWrite: false, depthTest: false, vertexColors: THREE.VertexColors } ),
  new THREE.MeshLambertMaterial( { color: 0xffffff, opacity: 1, depthWrite: false, depthTest: false, vertexColors: THREE.VertexColors } )
]; // the two materials 

var mesh = new THREE.Mesh(yourGeometry, new THREE.MeshFaceMaterial(materials)); //tell three.js that you will have several materials in your geometry

然后,您需要根据材料索引在每张面上确定materialIndex

yourGeometry.faces[0].materialIndex = 0; 
yourGeometry.faces[1].materialIndex = 0;
yourGeometry.faces[2].materialIndex = 1; // <= the cone base 
...
yourGeometry.faces[lastFaceIndex].materialIndex = 0;

注意:materialIndex的默认参数为0,因此您需要在案例中仅确定其材质索引的一个面