three.jsで立方体にテクスチャを貼る r59 (2013年)

f:id:peroon:20130813231755j:plain

three.js r59 textured cube sample

リビジョンが古くなってしまったサンプルが多いので
2013年8月のリビジョンr59でのサンプルコードです。

function getTexturedCube(){
    var path = './avater.jpg';
    var materials = [
       new THREE.MeshLambertMaterial({map: THREE.ImageUtils.loadTexture(path)}),
       new THREE.MeshLambertMaterial({map: THREE.ImageUtils.loadTexture(path)}),
       new THREE.MeshLambertMaterial({map: THREE.ImageUtils.loadTexture(path)}),
       new THREE.MeshLambertMaterial({map: THREE.ImageUtils.loadTexture(path)}),
       new THREE.MeshLambertMaterial({map: THREE.ImageUtils.loadTexture(path)}),
       new THREE.MeshLambertMaterial({map: THREE.ImageUtils.loadTexture(path)}),
    ];

    var cube = new THREE.Mesh(
        new THREE.CubeGeometry(2, 2, 2, 1, 1, 1),
        new THREE.MeshFaceMaterial(materials)
        );
    return cube;
}