From 236fd1d9f2009083fbbfce7190c27fbf1d7c88b8 Mon Sep 17 00:00:00 2001 From: yo mama Date: Fri, 7 Aug 2015 18:33:30 -0700 Subject: getting ready --- frontend/imlandscape/js/3D_Landscape.js | 248 ++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 frontend/imlandscape/js/3D_Landscape.js (limited to 'frontend/imlandscape/js/3D_Landscape.js') diff --git a/frontend/imlandscape/js/3D_Landscape.js b/frontend/imlandscape/js/3D_Landscape.js new file mode 100644 index 0000000..411bfe7 --- /dev/null +++ b/frontend/imlandscape/js/3D_Landscape.js @@ -0,0 +1,248 @@ +var container, stats; +var camera, controls, scene, renderer; +var mesh, texture, material; +//FIXME experiment with these fixed params +var worldWidth = 256, worldDepth = 256, worldHalfWidth = worldWidth / 2, worldHalfDepth = worldDepth / 2; +var textureFile = 'img/Texture.jpg'; +var heightmapFile = 'img/Heightmap.jpg'; +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(textureFile, heightmapFile, function(){ animate() }); + //Start Scene Animation +} + +function initGraphics(textureFile, heightmapFile, 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; + img.onerror = function() { + alert("The following url did not work: \n"+heightmapFile.slice(15)); + is_generating = false; + toggle_background(); + }; + + 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