var container, stats; var camera, controls, scene, renderer; var mesh, texture, material; var worldWidth = 256, worldDepth = 256, worldHalfWidth = worldWidth / 2, worldHalfDepth = worldDepth / 2; var textureURL, heightmapURL; var textureFile = 'img/test2.gif'; //texture doesn't need resizing var heightmapFile = 'img/testnew.png'; var pos_x, pos_y, pos_z, rot_x, rot_y, rot_z; var wf = false; function runWebGLSimulation(){ //Detect WebGL if (!Detector.webgl) { Detector.addGetWebGLMessage(); document.getElementById('container').innerHTML = ""; } //Start Graphics initGraphics(function(){ animate() }); //Start Scene Animation } function initGraphics(cb) { container = document.getElementById('container'); //Set camera camera = new THREE.PerspectiveCamera(60, window.innerWidth / window.innerHeight, 1, 20000); //Set scene scene = new THREE.Scene(); //Get heightmap data //Generates the heightmap data from the heightmap image var size = worldWidth * worldDepth, data = new Float32Array(size); var canvas = document.createElement('canvas'); canvas.width = worldWidth; canvas.height = worldDepth; context = canvas.getContext('2d'); context.fillStyle = '#000'; context.fillRect(0, 0, worldWidth, worldDepth); var img = new Image(); img.src = heightmapFile; //FIXME img.onload = function(){ context.drawImage(img, 0, 0); image = context.getImageData(0, 0, worldWidth, worldDepth); var imageData = image.data; var pixels = size; for (var i=0; i