CylinderGeometry with MeshFaceMaterial

failed attempt...

by jmchen

HTML

<div id="info">hw3 helper
    <br/>(no bump yet)</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://dl.dropboxusercontent.com/u/3587259/Code/Threejs/OrbitControls.js">
    
</script>

CSS

#info {
    position: absolute;
    top: 0px;
    width: 100%;
    padding: 10px;
    text-align: center;
    color: #ffff00
}

JavaScript

var camera, scene, renderer, geometry, material, light, controls;

init();
animate();

function init() {
    scene = new THREE.Scene();

    camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 10000);
    camera.position.z = 500;
    scene.add(camera);

    THREE.ImageUtils.crossOrigin = '';
    var colormap = THREE.ImageUtils.loadTexture('http://jyunming-chen.github.io/tutsplus/images/tire-side.png');
    //    var colormap2 = THREE.ImageUtils.loadTexture('http://jyunming-//chen.github.io/tutsplus/images/tire-wheel.jpg');


    // create an array with six textures for a cool cube
    var materialArray = [];
    materialArray.push(new THREE.MeshBasicMaterial({
        // map: colormap
        color: 0x999999
    }));
    materialArray.push(new THREE.MeshBasicMaterial({
        color: 0x880000
    }));
/*
    materialArray.push(new THREE.MeshBasicMaterial({
        color: 0x888800
    }));
*/    
    var tireMaterial = new THREE.MeshFaceMaterial(materialArray);

    var mesh = new THREE.Mesh(new THREE.CylinderGeometry(50, 50, 20),
//    var mesh = new THREE.Mesh(new THREE.BoxGeometry(50,50,50),
    //                          new THREE.MeshBasicMaterial());
    tireMaterial);
    scene.add(mesh);

    //////////////////////////////////////////////////////////
    light = new THREE.PointLight(0xffffff);
    light.position.set(100, 300, 200);
    scene.add(light);

    var gridXZ = new THREE.GridHelper(100, 10);
    gridXZ.setColors(new THREE.Color(0xff0000), new THREE.Color(0xffffff));
    scene.add(gridXZ);

    renderer = new THREE.WebGLRenderer();
    renderer.setSize(window.innerWidth, window.innerHeight);
    renderer.setClearColor(0x888888);

    controls = new THREE.OrbitControls(camera, renderer.domElement);

    document.body.appendChild(renderer.domElement);
}

function animate() {
    controls.update();
    requestAnimationFrame(animate);
    render();
}

function render() {
    renderer.render(scene, camera);
}