Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different material on back and frontside of extruded shape

Tags:

three.js

I'm trying to apply different material on front and back sides of extruded shape, but cannot figure out where to put side: THREE.FrontSide and side: THREE.BackSide. Where they should be putted?

My relevant code part is:

var materialFront = new THREE.MeshPhongMaterial({ ambient: 0xffffff, map: frontTexture });

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

var extrusionSettings = {
          amount: 10,
          bevelEnabled: false,
          bevelThickness: 0.2,
          bevelSize: 0.2,
          bevelSegments: 8,
          material: 0,
          extrudeMaterial: 1
};

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

var materials = [materialFront, materialSide];

var material = new THREE.MeshFaceMaterial(materials);

mesh = new THREE.Mesh(geometry, material);

UPDATE: According to WestLangley's comment I succeeded in adding the different texture to backfaces:

// ...
var materials = [materialFront, materialSide, materialBack];
// ...
for ( var face in mesh.geometry.faces ) {
if (mesh.geometry.faces[ face ].normal.z == 1) mesh.geometry.faces[ face ].materialIndex = 2;
}
like image 445
Timo Kähkönen Avatar asked May 10 '13 14:05

Timo Kähkönen


1 Answers

After you create your mesh geometry, and before the first call to render(), you have to change the materialIndex to 2 for the back faces. Then, add a third material in your material array.

You can identify the back faces by their face normals. Face normals for faces on the back of the geometry should all point in the same direction.

three.js r.58

like image 68
WestLangley Avatar answered Sep 17 '22 19:09

WestLangley