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

前端 未结 2 484
伪装坚强ぢ
伪装坚强ぢ 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:06

    You need to place two plane geometries back-to-back.

    First, create a geometry for the front.

    var geometry1 = new THREE.PlaneGeometry( 90, 110, 1, 1 );
    

    Now create another geometry for the back.

    var geometry2 = new THREE.PlaneGeometry( 90, 110, 1, 1 );
    

    Spin it 180 degrees.

    geometry2.applyMatrix( new THREE.Matrix4().makeRotationY( Math.PI ) );
    

    After you load the materials, create the meshes, and add them as children of a "card" object.

    // textures
    var textureFront = new THREE.ImageUtils.loadTexture('images/cardFront.png' );      
    var textureBack = new THREE.ImageUtils.loadTexture('images/cardBack.png' );
    
    // material
    var material1 = new THREE.MeshBasicMaterial( { color: 0xffffff, map: textureFront } );
    var material2 = new THREE.MeshBasicMaterial( { color: 0xffffff, map: textureBack } );
    
    // card
    card = new THREE.Object3D();
    scene.add( card );
    
    // mesh
    mesh1 = new THREE.Mesh( geometry1, material1 );
    card.add( mesh1 );
    mesh2 = new THREE.Mesh( geometry2, material2 );
    card.add( mesh2 );
    

    You'll have an easier time with this if you use WebGLRenderer.

    Fiddle: http://jsfiddle.net/mdAb7/11/

    Updated to three.js r.69

提交回复
热议问题