hw2 helper
texture map
HTML
<div id="info">Texture Map
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="https://jyunming-chen.github.io/tutsplus/js/KeyboardState.js"></script>
CSS
#info {
position: absolute;
top: 0px;
width: 100%;
padding: 10px;
text-align: center;
color: #ffff00
}
body {
overflow: hidden;
}
JavaScript
var camera, scene, renderer;
init();
animate();
function init() {
renderer = new THREE.WebGLRenderer({
antialias: true
});
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
scene = new THREE.Scene();
camera = new THREE.OrthographicCamera(-50, 50, 50, -50, -10, 100);
camera.position.z = 10;
scene.add(camera);
////////////////////////////////////////////////////////////////////////////////////////////
// loading texture from imgur.com
THREE.ImageUtils.crossOrigin = '';
texture = THREE.ImageUtils.loadTexture('http://i.imgur.com/iBXGew8.jpg');
texture.wrapS = THREE.RepeatWrapping;
// setting up texMat
// Plane with default texture coordinates [0,1]x[0,1]
var texMat = new THREE.MeshBasicMaterial({map: texture});
var floor = new THREE.Mesh(new THREE.PlaneGeometry(80, 80), texMat);
scene.add(floor);
//window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
renderer.render(scene, camera);
}