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; }
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With