How can I put two different textures on the front and back of a plane?

前端 未结 2 487
伪装坚强ぢ
伪装坚强ぢ 2020-12-06 11:50

PRoblem: i\'m trying to create (just for fun) a simple poker card (with a card back and a card front). I have two different images, for back and front. I easily created a Pl

2条回答
  •  感动是毒
    2020-12-06 12:28

    Was searching for solution without duplicating all my geometry.

    Here you go ladies and gentlemen...

    var materials = [new THREE.MeshBasicMaterial({map: texture, side: THREE.FrontSide}),
                     new THREE.MeshBasicMaterial({map: textureBack, side: THREE.BackSide})];
    
    var geometry = new THREE.PlaneGeometry(width, height);
    
    for (var i = 0, len = geometry.faces.length; i < len; i++) {
        var face = geometry.faces[i].clone();
        face.materialIndex = 1;
        geometry.faces.push(face);
        geometry.faceVertexUvs[0].push(geometry.faceVertexUvs[0][i].slice(0));
    }
    
    scene.add(new THREE.Mesh(geometry, new THREE.MeshFaceMaterial(materials)));
    

    BOOM a Two Faced Plane for ya, the loop will also work with geometries with more faces, replicating each face and applying the BackSide texture to it.

    Enjoy!

提交回复
热议问题