From ae0e6d987781d2fbf225611e2f8df37380a2bbcd Mon Sep 17 00:00:00 2001 From: yo mama Date: Thu, 12 Feb 2015 18:29:27 -0800 Subject: first --- js/3D_Landscape.js | 197 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 js/3D_Landscape.js (limited to 'js/3D_Landscape.js') diff --git a/js/3D_Landscape.js b/js/3D_Landscape.js new file mode 100644 index 0000000..6871786 --- /dev/null +++ b/js/3D_Landscape.js @@ -0,0 +1,197 @@ +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