tire (hw3)

texture (cutout, bumpMap)

by Perry Keh

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 = 1000;
    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');

    tire = new THREE.Object3D();
    geometry = new THREE.CircleGeometry(50, 20);
    material = new THREE.MeshBasicMaterial({
        map: colormap,
        transparent: true,  // for cut-out texture
        side: THREE.DoubleSide
    });
    var mesh = new THREE.Mesh(geometry, material);
colormap2.wrapS = colormap2.wrapT = THREE.RepeatWrapping; 
	colormap2.repeat.set( 8, 1 );
    var mesh2 = new THREE.Mesh(new THREE.CylinderGeometry(50, 50, 20, 30, 1, true), // only side
    new THREE.MeshBasicMaterial({
        map: colormap2,
        side: THREE.DoubleSide
    }));
    mesh2.rotation.x = Math.PI / 2;
    mesh.position.set(0, 0, 10);
    mesh0 = mesh.clone();
    mesh0.position.set(0, 0, -10);
    mesh0.rotation.y = Math.PI;
    tire.add (mesh);
    tire.add(mesh0);
    tire.add(mesh2);
    scene.add(tire);
    
    tire.position.set (0,50,0);

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

    var gridXZ = new THREE.GridHelper(200, 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();
   ...