2014-04-27 28 views
6

我正在嘗試將紋理應用於Box對象的僅一側。如何創建多個Box並只更改一側的紋理?

Basic代碼:

BoxGeo = new THREE.BoxGeometry(50, 50, 125); 
BoxMat = new THREE.MeshLambertMaterial({ color: 0xF0F0F0 }); 
BoxObj = new THREE.Mesh(GeoBox, GeoMat); 

我使用含有6種材料的陣列試圖對象,5個彩色和一個與圖像(從紋理的另一個陣列對每個盒中隨機選用)。但是,它拋出一個錯誤:(

是否有可能提供一個簡單的立方體爲例具有不同紋理每個面? 我在網上看到一些爲例,但他們需要把材料陣列幾何對象內部和我想,以避免由於性能原因創建每個箱子一個新的幾何對象。

回答

3

什麼this sample?它創建材料數組,然後將其添加到網格。所以,你可以重新使用它。

相關代碼:

// Create an array of materials to be used in a cube, one for each side 
var cubeMaterialArray = []; 
// order to add materials: x+,x-,y+,y-,z+,z- 
cubeMaterialArray.push(new THREE.MeshBasicMaterial({ color: 0xff3333 })); 
cubeMaterialArray.push(new THREE.MeshBasicMaterial({ color: 0xff8800 })); 
cubeMaterialArray.push(new THREE.MeshBasicMaterial({ color: 0xffff33 })); 
cubeMaterialArray.push(new THREE.MeshBasicMaterial({ color: 0x33ff33 })); 
cubeMaterialArray.push(new THREE.MeshBasicMaterial({ color: 0x3333ff })); 
cubeMaterialArray.push(new THREE.MeshBasicMaterial({ color: 0x8833ff })); 
var cubeMaterials = new THREE.MeshFaceMaterial(cubeMaterialArray); 
// Cube parameters: width (x), height (y), depth (z), 
//  (optional) segments along x, segments along y, segments along z 
var cubeGeometry = new THREE.CubeGeometry(100, 100, 100, 1, 1, 1); 
// using THREE.MeshFaceMaterial() in the constructor below 
// causes the mesh to use the materials stored in the geometry 
cube = new THREE.Mesh(cubeGeometry, cubeMaterials); 
+0

哈哈哈!驚人!非常感謝! (我想我檢查了這個網站上的所有演示除外) –

+0

@JeremyDicaire - 很高興幫助 – acarlon

相關問題