(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o elø1 ? (function () { return minø1 = elø1; })() : void 0; }.call(this)); return loop[0] = inc(index1ø1), loop; })() : void 0; } while (index1ø1 = loop[0], recur === loop); return recur; }.call(this); }.call(this); }.call(this)); return function () { var spanø1 = maxø1 - minø1; return function () { var array4ø1 = heightmap; return function () { var G__5ø1 = array4ø1.shape[0]; return function loop() { var recur = loop; var xø1 = 0; do { recur = xø1 < G__5ø1 ? (function () { (function () { var G__6ø1 = array4ø1.shape[1]; return function loop() { var recur = loop; var yø1 = 0; do { recur = yø1 < G__6ø1 ? (function () { (function () { return heightmapSet(heightmap, xø1, yø1, (heightmapGet(heightmap, xø1, yø1) - minø1) / spanø1); })(); return loop[0] = inc(yø1), loop; })() : void 0; } while (yø1 = loop[0], recur === loop); return recur; }.call(this); }.call(this)); return loop[0] = inc(xø1), loop; })() : void 0; } while (xø1 = loop[0], recur === loop); return recur; }.call(this); }.call(this); }.call(this); }.call(this); }.call(this); }; var makeHeightmap = exports.makeHeightmap = function makeHeightmap(exponent) { return function () { var resolutionø1 = Math.pow(2, exponent) + 1; return function () { var heightmapø1 = ndarray(new Float64Array(resolutionø1 * resolutionø1), [ resolutionø1, resolutionø1 ]); heightmapø1.exponent = exponent; heightmapø1.resolution = resolutionø1; heightmapø1.last = dec(resolutionø1); return heightmapø1; }.call(this); }.call(this); }; var topLeftCorner = exports.topLeftCorner = function topLeftCorner(heightmap) { return function () { var centerø1 = heightmapCenterIndex(heightmap); return heightmap.lo(0, 0).hi(inc(centerø1), inc(centerø1)); }.call(this); }; var topRightCorner = exports.topRightCorner = function topRightCorner(heightmap) { return function () { var centerø1 = heightmapCenterIndex(heightmap); return heightmap.lo(centerø1, 0).hi(inc(centerø1), inc(centerø1)); }.call(this); }; var bottomLeftCorner = exports.bottomLeftCorner = function bottomLeftCorner(heightmap) { return function () { var centerø1 = heightmapCenterIndex(heightmap); return heightmap.lo(0, centerø1).hi(inc(centerø1), inc(centerø1)); }.call(this); }; var bottomRightCorner = exports.bottomRightCorner = function bottomRightCorner(heightmap) { return function () { var centerø1 = heightmapCenterIndex(heightmap); return heightmap.lo(centerø1, centerø1).hi(inc(centerø1), inc(centerø1)); }.call(this); }; var mpdInitCorners = exports.mpdInitCorners = function mpdInitCorners(heightmap) { return function () { var lastø1 = heightmapLastIndex(heightmap); heightmapSet(heightmap, 0, 0, rand()); heightmapSet(heightmap, 0, lastø1, rand()); heightmapSet(heightmap, lastø1, 0, rand()); return heightmapSet(heightmap, lastø1, lastø1, rand()); }.call(this); }; var mpdDisplace = exports.mpdDisplace = function mpdDisplace(heightmap, spread, spreadReduction) { return function () { var lastø1 = heightmapLastIndex(heightmap); var cø1 = midpoint(0, lastø1); var bottomLeftø1 = heightmapGet(heightmap, 0, 0); var bottomRightø1 = heightmapGet(heightmap, lastø1, 0); var topLeftø1 = heightmapGet(heightmap, 0, lastø1); var topRightø1 = heightmapGet(heightmap, lastø1, lastø1); var topø1 = average2(topLeftø1, topRightø1); var leftø1 = average2(bottomLeftø1, topLeftø1); var bottomø1 = average2(bottomLeftø1, bottomRightø1); var rightø1 = average2(bottomRightø1, topRightø1); var centerø1 = average4(topø1, leftø1, bottomø1, rightø1); var nextSpreadø1 = spread * spreadReduction; heightmapSetIfUnset(heightmap, cø1, 0, jitter(bottomø1, spread)); heightmapSetIfUnset(heightmap, cø1, lastø1, jitter(topø1, spread)); heightmapSetIfUnset(heightmap, 0, cø1, jitter(leftø1, spread)); heightmapSetIfUnset(heightmap, lastø1, cø1, jitter(rightø1, spread)); heightmapSetIfUnset(heightmap, cø1, cø1, jitter(centerø1, spread)); return !(3 == heightmapResolution(heightmap)) ? (function () { heightmapSetIfUnset(heightmap, cø1, 0, jitter(bottomø1, spread)); heightmapSetIfUnset(heightmap, cø1, lastø1, jitter(topø1, spread)); heightmapSetIfUnset(heightmap, 0, cø1, jitter(leftø1, spread)); heightmapSetIfUnset(heightmap, lastø1, cø1, jitter(rightø1, spread)); heightmapSetIfUnset(heightmap, cø1, cø1, jitter(centerø1, spread)); mpdDisplace(topLeftCorner(heightmap), nextSpreadø1, spreadReduction); mpdDisplace(topRightCorner(heightmap), nextSpreadø1, spreadReduction); mpdDisplace(bottomLeftCorner(heightmap), nextSpreadø1, spreadReduction); return mpdDisplace(bottomRightCorner(heightmap), nextSpreadø1, spreadReduction); })() : void 0; }.call(this); }; var midpointDisplacement = exports.midpointDisplacement = function midpointDisplacement(heightmap) { return function () { var initialSpreadø1 = 0.3; var spreadReductionø1 = 0.55; mpdInitCorners(heightmap); mpdDisplace(heightmap, initialSpreadø1, spreadReductionø1); return normalize(heightmap); }.call(this); }; var makeDirectionalLight = exports.makeDirectionalLight = function makeDirectionalLight() { return function () { var lightø1 = new THREE.DirectionalLight(16777215, 1); lightø1.position.set(100, 0, 150); return lightø1; }.call(this); }; var makeCamera = exports.makeCamera = function makeCamera() { return function () { var cameraø1 = new THREE.PerspectiveCamera(55, width / height, 0.1, 1000); cameraø1.position.set(0, -100, 150); return cameraø1; }.call(this); }; var makeRenderer = exports.makeRenderer = function makeRenderer() { return function () { var rendererø1 = new THREE.WebGLRenderer({ 'antialias': false }); rendererø1.setClearColor(16777215); rendererø1.setSize(width, height); rendererø1.setPixelRatio(2); return rendererø1; }.call(this); }; var makeGeometry = exports.makeGeometry = function makeGeometry(heightmap) { return function () { var resolutionø1 = heightmap.shape[0]; var geometryø1 = new THREE.PlaneGeometry(terrainSize, terrainSize, resolutionø1 - 1, resolutionø1 - 1); return geometryø1; }.call(this); }; var makeControls = exports.makeControls = function makeControls(camera, renderer) { return function () { var controlsø1 = new THREE.TrackballControls(camera, renderer.domElement); controlsø1.rotateSpeed = 1.4; controlsø1.zoomSpeed = 0.5; controlsø1.staticMoving = true; controlsø1.dynamicDampingFactor = 0.3; return controlsø1; }.call(this); }; var makePlane = exports.makePlane = function makePlane(geometry) { return function () { var materialø1 = new THREE.MeshLambertMaterial({ 'wireframe': wireframe, 'wireframeLinewidth': wireframeWidth, 'color': 47872 }); return new THREE.Mesh(geometry, materialø1); }.call(this); }; var attachToDom = exports.attachToDom = function attachToDom(renderer, elName, refreshFn) { return function () { var containerø1 = document.getElementById(elName); var settingsø1 = document.createElement('div'); var refreshButtonø1 = document.createElement('button'); var buttonTextø1 = document.createTextNode('Refresh'); var cancelScrollø1 = function (e) { return e.preventDefault(); }; refreshButtonø1.onclick = refreshFn; renderer.domElement.onmousewheel = cancelScrollø1; renderer.domElement.addEventListener('MozMousePixelScroll', cancelScrollø1, false); refreshButtonø1.appendChild(buttonTextø1); containerø1.appendChild(renderer.domElement); containerø1.appendChild(settingsø1); return settingsø1.appendChild(refreshButtonø1); }.call(this); }; var updateGeometry = exports.updateGeometry = function updateGeometry(geometry, heightmap) { (function loop() { var recur = loop; var iø1 = 0; do { recur = iø1 < geometry.vertices.length ? (function () { geometry.vertices[iø1].z = terrainHeight * heightmap.data[iø1]; return loop[0] = iø1 + 1, loop; })() : void 0; } while (iø1 = loop[0], recur === loop); return recur; }.call(this)); geometry.computeVertexNormals(); return geometry; }; var makeFinal = exports.makeFinal = function makeFinal(elementId) { var scene = new THREE.Scene(); scene.add(new THREE.AxisHelper(100)); var clock = new THREE.Clock(); var camera = makeCamera(); var renderer = makeRenderer(); var geometry = void 0; var plane = void 0; scene.add(makeDirectionalLight()); scene.add(new THREE.AmbientLight(16777215, 0.05)); var refresh = function refresh() { return function () { var heightmapø1 = makeHeightmap(6); console.log('Generating terrain...'); (function () { var G__7ø1 = new Date().getTime(); var G__9ø1 = (function () { return midpointDisplacement(heightmapø1); })(); var G__8ø1 = new Date().getTime(); console.log('Elapsed time: ' + (G__8ø1 - G__7ø1) + 'ms.'); return G__9ø1; }.call(this)); console.log('Rebuilding geometry...'); (function () { var G__10ø1 = new Date().getTime(); var G__12ø1 = (function () { geometry = makeGeometry(heightmapø1); return updateGeometry(geometry, heightmapø1); })(); var G__11ø1 = new Date().getTime(); console.log('Elapsed time: ' + (G__11ø1 - G__10ø1) + 'ms.'); return G__12ø1; }.call(this)); console.log('Rebuilding plane...'); return function () { var G__13ø1 = new Date().getTime(); var G__15ø1 = (function () { scene.remove(plane); plane = makePlane(geometry); return scene.add(plane); })(); var G__14ø1 = new Date().getTime(); console.log('Elapsed time: ' + (G__14ø1 - G__13ø1) + 'ms.'); return G__15ø1; }.call(this); }.call(this); }; attachToDom(renderer, elementId, refresh); var controls = makeControls(camera, renderer); var render = function render() { return function () { var deltaø1 = clock.getDelta(); requestAnimationFrame(render); controls.update(deltaø1); return renderer.render(scene, camera); }.call(this); }; refresh(); render(); return void 0; }; var run = exports.run = function run() { return makeFinal('demo-final'); }; $(run); },{"ndarray":4}],2:[function(require,module,exports){ "use strict" function iota(n) { var result = new Array(n) for(var i=0; i * License: MIT * * `npm install is-buffer` */ module.exports = function (obj) { return !!(obj != null && (obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor) (obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)) )) } },{}],4:[function(require,module,exports){ var iota = require("iota-array") var isBuffer = require("is-buffer") var hasTypedArrays = ((typeof Float64Array) !== "undefined") function compare1st(a, b) { return a[0] - b[0] } function order() { var stride = this.stride var terms = new Array(stride.length) var i for(i=0; iMath.abs(this.stride[1]))?[1,0]:[0,1]}})") } else if(dimension === 3) { code.push( "var s0=Math.abs(this.stride[0]),s1=Math.abs(this.stride[1]),s2=Math.abs(this.stride[2]);\ if(s0>s1){\ if(s1>s2){\ return [2,1,0];\ }else if(s0>s2){\ return [1,2,0];\ }else{\ return [1,0,2];\ }\ }else if(s0>s2){\ return [2,0,1];\ }else if(s2>s1){\ return [0,1,2];\ }else{\ return [0,2,1];\ }}})") } } else { code.push("ORDER})") } } //view.set(i0, ..., v): code.push( "proto.set=function "+className+"_set("+args.join(",")+",v){") if(useGetters) { code.push("return this.data.set("+index_str+",v)}") } else { code.push("return this.data["+index_str+"]=v}") } //view.get(i0, ...): code.push("proto.get=function "+className+"_get("+args.join(",")+"){") if(useGetters) { code.push("return this.data.get("+index_str+")}") } else { code.push("return this.data["+index_str+"]}") } //view.index: code.push( "proto.index=function "+className+"_index(", args.join(), "){return "+index_str+"}") //view.hi(): code.push("proto.hi=function "+className+"_hi("+args.join(",")+"){return new "+className+"(this.data,"+ indices.map(function(i) { return ["(typeof i",i,"!=='number'||i",i,"<0)?this.shape[", i, "]:i", i,"|0"].join("") }).join(",")+","+ indices.map(function(i) { return "this.stride["+i + "]" }).join(",")+",this.offset)}") //view.lo(): var a_vars = indices.map(function(i) { return "a"+i+"=this.shape["+i+"]" }) var c_vars = indices.map(function(i) { return "c"+i+"=this.stride["+i+"]" }) code.push("proto.lo=function "+className+"_lo("+args.join(",")+"){var b=this.offset,d=0,"+a_vars.join(",")+","+c_vars.join(",")) for(var i=0; i=0){\ d=i"+i+"|0;\ b+=c"+i+"*d;\ a"+i+"-=d}") } code.push("return new "+className+"(this.data,"+ indices.map(function(i) { return "a"+i }).join(",")+","+ indices.map(function(i) { return "c"+i }).join(",")+",b)}") //view.step(): code.push("proto.step=function "+className+"_step("+args.join(",")+"){var "+ indices.map(function(i) { return "a"+i+"=this.shape["+i+"]" }).join(",")+","+ indices.map(function(i) { return "b"+i+"=this.stride["+i+"]" }).join(",")+",c=this.offset,d=0,ceil=Math.ceil") for(var i=0; i=0){c=(c+this.stride["+i+"]*i"+i+")|0}else{a.push(this.shape["+i+"]);b.push(this.stride["+i+"])}") } code.push("var ctor=CTOR_LIST[a.length+1];return ctor(this.data,a,b,c)}") //Add return statement code.push("return function construct_"+className+"(data,shape,stride,offset){return new "+className+"(data,"+ indices.map(function(i) { return "shape["+i+"]" }).join(",")+","+ indices.map(function(i) { return "stride["+i+"]" }).join(",")+",offset)}") //Compile procedure var procedure = new Function("CTOR_LIST", "ORDER", code.join("\n")) return procedure(CACHED_CONSTRUCTORS[dtype], order) } function arrayDType(data) { if(isBuffer(data)) { return "buffer" } if(hasTypedArrays) { switch(Object.prototype.toString.call(data)) { case "[object Float64Array]": return "float64" case "[object Float32Array]": return "float32" case "[object Int8Array]": return "int8" case "[object Int16Array]": return "int16" case "[object Int32Array]": return "int32" case "[object Uint8Array]": return "uint8" case "[object Uint16Array]": return "uint16" case "[object Uint32Array]": return "uint32" case "[object Uint8ClampedArray]": return "uint8_clamped" } } if(Array.isArray(data)) { return "array" } return "generic" } var CACHED_CONSTRUCTORS = { "float32":[], "float64":[], "int8":[], "int16":[], "int32":[], "uint8":[], "uint16":[], "uint32":[], "array":[], "uint8_clamped":[], "buffer":[], "generic":[] } ;(function() { for(var id in CACHED_CONSTRUCTORS) { CACHED_CONSTRUCTORS[id].push(compileConstructor(id, -1)) } }); function wrappedNDArrayCtor(data, shape, stride, offset) { if(data === undefined) { var ctor = CACHED_CONSTRUCTORS.array[0] return ctor([]) } else if(typeof data === "number") { data = [data] } if(shape === undefined) { shape = [ data.length ] } var d = shape.length if(stride === undefined) { stride = new Array(d) for(var i=d-1, sz=1; i>=0; --i) { stride[i] = sz sz *= shape[i] } } if(offset === undefined) { offset = 0 for(var i=0; i