diff --git a/gulpfile.js b/gulpfile.js index 81a81e6..691c135 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -78,8 +78,7 @@ gulp.task('lint', function (){ .pipe(jshint({ "smarttabs": true })) - .pipe(jshint.reporter('default')) - .pipe(jshint.reporter('fail')); + .pipe(jshint.reporter('default')); }); var startServer = function(cb) { diff --git a/js/render.js b/js/render.js index d334545..43cad75 100644 --- a/js/render.js +++ b/js/render.js @@ -38,8 +38,12 @@ var THREE = require("three"), oldBatcher = batcher; setupView(batcher.mn, batcher.mx); - restorePoint = [batcher.mn.clone(), batcher.mx.clone()]; + + // trigger a signal which will cause the intenisty range to update + $.event.trigger({ + type: 'plasio.intensityClampChanged' + }); }; var setupView = function(mins, maxs) { @@ -69,7 +73,7 @@ var THREE = require("three"), // camera.position.set( -range[0]/2, - 2000, + maxs.z * 1.5, -range[1]/2); console.log('Camera position set to:', camera.position); @@ -252,8 +256,6 @@ var THREE = require("three"), uniforms.height_f.value = 0.0; uniforms.iheight_f.value = 0.0; - console.log('updating', source); - switch(source) { case "intensity": uniforms.intensity_f.value = 1.0; break; case "heightmap": uniforms.height_f.value = 1.0; break; @@ -263,6 +265,21 @@ var THREE = require("three"), console.log(uniforms); } + function updateIntensityClampingForBatcher(uniforms, batcher) { + var range = currentIntensityClamp(); + + var f = function(v) { + var vf = v / 100.0; + return batcher.in_n + (batcher.in_x - batcher.in_n) * vf; + }; + + var lower = f(parseFloat(range[0])); + var higher = f(parseFloat(range[1])); + + uniforms.clampLower.value = lower; + uniforms.clampHigher.value = Math.max(higher, lower + 0.001); + } + var shaderMaterial = null; function getMaterial(vs, fs) { if (shaderMaterial !== null) @@ -279,6 +296,7 @@ var THREE = require("three"), var uniforms = { pointSize: { type: 'f', value: currentPointSize() }, intensityBlend: { type: 'f', value: currentIntensityBlend() / 100.0 }, + maxColorComponent: { type: 'f', value: 1.0 }, // colors rgb_f: { type: 'f', value: 1.0 }, @@ -302,6 +320,8 @@ var THREE = require("three"), updateColorUniformsForSource(uniforms, currentColorSource()); updateIntensityUniformsForSource(uniforms, currentIntensitySource()); + if (oldBatcher !== null) + updateIntensityClampingForBatcher(uniforms, oldBatcher); shaderMaterial = new THREE.ShaderMaterial({ vertexShader: vs, @@ -326,18 +346,14 @@ var THREE = require("three"), }); $(document).on("plasio.intensityClampChanged", function() { - var range = currentIntensityClamp(); - - var lower = parseFloat(range[0]); - var higher = parseFloat(range[1]); - - uniforms.clampLower.value = lower; - uniforms.clampHigher.value = Math.max(higher, lower + 0.001); // make sure higher value always greater than lower. + if (oldBatcher !== null) + updateIntensityClampingForBatcher(uniforms, oldBatcher); }); $(document).on("plasio.intensityBlendChanged", function() { var f = currentIntensityBlend(); uniforms.intensityBlend.value = f / 100.0; + }); $(document).on("plasio.pointSizeChanged", function() { @@ -345,6 +361,10 @@ var THREE = require("three"), uniforms.pointSize.value = f; }); + $(document).on("plasio.maxColorComponent", function(e) { + uniforms.maxColorComponent.value = Math.max(0.0001, e.maxColorComponent); + }); + shaderMaterial.uniforms = uniforms; shaderMaterial.attributes = attributes; @@ -360,9 +380,11 @@ var THREE = require("three"), this.mx = null; this.mn = null; this.cg = null; + this.cn = null; + this.cx = null; + this.in_x = null; + this.in_y = null; this.pointsSoFar = 0; - - this.hasColor = false; }; ParticleSystemBatcher.prototype.push = function(lasBuffer) { @@ -383,6 +405,8 @@ var THREE = require("three"), var cg = null; var mx = null; var mn = null; + var cn = null, cx = null; + var in_x = null, in_n = null; for ( var i = 0; i < count; i ++) { var p = lasBuffer.getPoint(i); @@ -391,9 +415,6 @@ var THREE = require("three"), var y = p.position[1] * lasBuffer.scale[1] + lasBuffer.offset[1]; var z = p.position[2] * lasBuffer.scale[2] + lasBuffer.offset[2]; - if (x > -180.0 && x < 180.0) x *= 111000; - if (y > -90.0 && x < 90.0) y *= 111000; - if (cg === null) cg = new THREE.Vector3(x, y, z); else @@ -415,24 +436,43 @@ var THREE = require("three"), Math.min(mn.y, y), Math.min(mn.z, z)); - - positions[ 3*i ] = x; - positions[ 3*i + 1 ] = y; - positions[ 3*i + 2 ] = z; - + // get the color component out var r, g, b; - if (p.color) { r = p.color[0] / 255.0; g = p.color[1] / 255.0; b = p.color[2] / 255.0; } else { - var c = 0; - r = g = b = c; + r = g = b = 0; } - this.hasColor |= (p.color !== undefined && (r > 0 || g > 0 || b > 0)); + if (cn === null) { + cn = new THREE.Color(); + cn.r = r; cn.g = g; cn.b = b; + } + else { + cn.r = Math.max(cn.r, r); + cn.g = Math.max(cn.g, g); + cn.r = Math.max(cn.b, b); + } + + if (cx === null) { + cx = new THREE.Color(); + cx.r = r; cx.g = g; cx.b = b; + } + else { + cx.r = Math.max(cx.r, r); + cx.g = Math.max(cx.g, g); + cx.r = Math.max(cx.b, b); + } + + in_n = (in_n === null)? p.intensity : Math.min(in_n, p.intensity); + in_x = (in_x === null)? p.intensity : Math.max(in_x, p.intensity); + + positions[ 3*i ] = x; + positions[ 3*i + 1 ] = y; + positions[ 3*i + 2 ] = z; colors[ 3*i ] = r; colors[ 3*i + 1 ] = g; @@ -460,6 +500,23 @@ var THREE = require("three"), Math.min(mn.y, this.mn.y), Math.min(mn.z, this.mn.z)); + if (this.cn === null) this.cn = cn; + else { + this.cn.r = Math.min(this.cn.r, cn.r); + this.cn.g = Math.min(this.cn.g, cn.g); + this.cn.b = Math.min(this.cn.b, cn.b); + } + + if (this.cx === null) this.cx = cx; + else { + this.cx.r = Math.max(this.cx.r, cx.r); + this.cx.g = Math.max(this.cx.g, cx.g); + this.cx.b = Math.max(this.cx.b, cx.b); + } + + this.in_n = (this.in_n === null)? in_n : Math.min(in_n, this.in_y); + this.in_x = (this.in_x === null)? in_x : Math.max(in_x, this.in_x); + var ps = new THREE.ParticleSystem(geometry, this.material); this.pss.push(ps); diff --git a/js/ui.js b/js/ui.js index 493778c..a237926 100644 --- a/js/ui.js +++ b/js/ui.js @@ -147,13 +147,49 @@ var Promise = require("bluebird"), // load the batcher render.loadBatcher(batcher); + console.log(batcher); - if (!batcher.hasColor) + var batcherHasColor = + (batcher.cx.r - batcher.cn.r) > 0.0 || + (batcher.cx.g - batcher.cn.g) > 0.0 || + (batcher.cx.b - batcher.cn.b) > 0.0; + + var batcherHasIntensity = + (batcher.in_x - batcher.in_y) > 0.0; + + console.log('Has color:', batcherHasColor); + console.log('Has intensity:', batcherHasIntensity); + + if (batcherHasColor && batcherHasIntensity) { + // enable both intensity and color, and set blend to 50 + $("#rgb").trigger("click"); + $("#intensity").trigger("click"); + $("#blending").val(50, true); + } + else if (batcherHasColor && !batcherHasIntensity) { + $("#rgb").trigger("click"); + $("#blending").val(0, true); + } + else if (!batcherHasColor && batcherHasIntensity) { + $("#intensity").click(); + $("#blending").val(100, true); + } + else { + // no color, no intensity $(".default-if-no-color").trigger("click"); + $("#blending").val(0, true); + } + + var maxColorComponent = Math.max(batcher.cx.r, batcher.cx.g, batcher.cx.b); + console.log('Max color component', maxColorComponent); + $.event.trigger({ + type: "plasio.maxColorComponent", + maxColorComponent: maxColorComponent + }); // Set properties $(".props").html( - "Name" + name + "" + + "Name" + header.name + "" + "File Version" + header.versionAsString + "" + "Compressed?" + (header.isCompressed ? "Yes" : "No") + "" + "Total Points" + numberWithCommas(header.pointsCount) + " (" + @@ -362,6 +398,9 @@ var Promise = require("bluebird"), var header = v[0]; var batcher = v[1]; + // add name to header + header.name = name; + $.event.trigger({ type: "plasio.load.completed", batcher: batcher, @@ -412,8 +451,8 @@ var Promise = require("bluebird"), }); $("#intensity").noUiSlider({ - range: [0, 255], - start: [20, 150], + range: [0, 100], + start: [0, 100], connect: true, slide: function() { $.event.trigger({ @@ -422,15 +461,18 @@ var Promise = require("bluebird"), } }); + var blendUpdate = function() { + $.event.trigger({ + type: 'plasio.intensityBlendChanged' + }); + }; + $("#blending").noUiSlider({ range: [0, 100], start: 0, handles: 1, - slide: function() { - $.event.trigger({ - type: 'plasio.intensityBlendChanged' - }); - } + slide: blendUpdate, + set: blendUpdate }); $("#pointsize").noUiSlider({