Skip to content

Commit

Permalink
Choose appropriate defaults for user when files are loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
verma committed Mar 10, 2014
1 parent 0920e68 commit c53d27c
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 36 deletions.
3 changes: 1 addition & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
107 changes: 82 additions & 25 deletions js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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 },
Expand All @@ -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,
Expand All @@ -326,25 +346,25 @@ 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() {
var f = currentPointSize();
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;

Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
60 changes: 51 additions & 9 deletions js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"<tr><td>Name</td><td>" + name + "</td></tr>" +
"<tr><td>Name</td><td>" + header.name + "</td></tr>" +
"<tr><td>File Version</td><td>" + header.versionAsString + "</td></tr>" +
"<tr><td>Compressed?</td><td>" + (header.isCompressed ? "Yes" : "No") + "</td></tr>" +
"<tr><td>Total Points</td><td>" + numberWithCommas(header.pointsCount) + " (" +
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand All @@ -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({
Expand Down

0 comments on commit c53d27c

Please sign in to comment.