10

问题:我正在尝试创建(只是为了好玩)一张简单的扑克牌(背面有卡片,正面有卡片)。我有两个不同的图像,用于背面和正面。我很容易地为双方创建了一个带有单个纹理的平面几何图形,但我真的不知道如何为一侧分配一个纹理,为另一侧分配另一个纹理......我试过这个(没有成功:():

var textureBack = new THREE.ImageUtils.loadTexture( 'images/cardBack.png' );
var textureFront = new THREE.ImageUtils.loadTexture( 'images/cardFront.png' );      

var material1 = new THREE.MeshBasicMaterial( { map: textureBack } );
var material2 = new THREE.MeshBasicMaterial( { map: textureFront } );

var geometry = new THREE.PlaneGeometry( 90, 110, 1, 1 );            
geometry.faces[ 0 ].materials.push( material1 );
geometry.faces[ 1 ].materials.push( material2 );

var card = new THREE.Mesh( geometry, new THREE.MeshFaceMaterial());

有什么帮助吗?:)

4

2 回答 2

12

在不复制我所有的几何图形的情况下寻找解决方案。

来了,女士们,先生们……

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 一个两面平面,循环也适用于具有更多面的几何图形,复制每个面并对其应用 BackSide 纹理。

享受!

于 2013-07-11T20:17:08.193 回答
6

您需要背靠背放置两个平面几何图形。

首先,为前面创建一个几何图形。

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

现在为背面创建另一个几何图形。

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

旋转 180 度。

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

加载材质后,创建网格并将它们添加为“卡片”对象的子对象。

// 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 );

如果您使用WebGLRenderer.

小提琴:http: //jsfiddle.net/mdAb7/11/

更新到three.js r.69

于 2012-07-29T18:29:28.763 回答