11

我正在尝试在挤压形状的正面和背面应用不同的材料,但不知道在哪里放置side: THREE.FrontSideside: THREE.BackSide。它们应该放在哪里?

我的相关代码部分是:

var materialFront = new THREE.MeshPhongMaterial({环境:0xffffff,地图:frontTexture});

var materialSide = new THREE.MeshPhongMaterial({color: 0xE68A00,ambient: 0xffffff});

变种挤压设置 = {
          数量:10,
          bevelEnabled:假,
          斜面厚度:0.2,
          斜角尺寸:0.2,
          bevelSegments: 8,
          材料:0,
          挤出材料:1
};

var geometry = new THREE.ExtrudeGeometry(形状,extrusionSettings);

var 材料 = [materialFront, materialSide];

var material = new THREE.MeshFaceMaterial(materials);

网格=新的三。网格(几何,材料);

更新:根据 WestLangley 的评论,我成功地将不同的纹理添加到背面:

// ...
var 材料 = [materialFront, materialSide,materialBack];
// ...
for ( var face in mesh.geometry.faces ) {
if (mesh.geometry.faces[ face ].normal.z == 1) mesh.geometry.faces[ face ].materialIndex = 2;
}
4

2 回答 2

9

创建网格几何体后,在第一次调用 之前,您必须将背面的render()更改为 2。materialIndex然后,在您的材质阵列中添加第三种材质。

您可以通过面法线识别背面。几何体背面的面法线应全部指向同一方向。

三.js r.58

于 2013-05-10T15:50:02.037 回答
1

Try using:

var materialFront = new THREE.MeshPhongMaterial({ ambient: 0xffffff, map: frontTexture, side: THREE.FrontSide });
var materialSide = new THREE.MeshPhongMaterial({ color: 0xE68A00, ambient: 0xffffff, side: THREE.BackSide });

even though you should probably lower your ambient contribution and give a color to the FrontSide material.

Then:

var materials = [materialFront, materialSide];
scene.add( THREE.SceneUtils.createMultiMaterialObject( geometry, materials ));
于 2013-05-10T15:05:06.810 回答