Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
autra committed Jun 29, 2018
1 parent fe850ac commit 005bb62
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 27 deletions.
9 changes: 4 additions & 5 deletions src/Parser/PotreeBinParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ for (const potreeName of Object.keys(POINT_ATTTRIBUTES)) {
attr.byteSize = attr.numElements * attr.numByte;
attr.normalized = attr.normalized || false;
// chrome is known to perform badly when we call a method without respecting its arity
// also, not using ternary because I measured a 25% perf hit on firefox doing so...
const fnName = `getUint${attr.numByte * 8}`;
attr.value = attr.numByte === 1 ?
function value(view, offset) { return view[fnName](offset); } :
function value(view, offset) { return view[fnName](offset, true); };
attr.getValue = attr.numByte === 1 ?
function getValue(view, offset) { return view[fnName](offset); } :
function getValue(view, offset) { return view[fnName](offset, true); };
}

export default {
Expand Down Expand Up @@ -93,7 +92,7 @@ export default {
const array = new attr.arrayType(arrayLength);
for (let arrayOffset = 0; arrayOffset < arrayLength; arrayOffset += attr.numElements) {
for (let elemIdx = 0; elemIdx < attr.numElements; elemIdx++) {
array[arrayOffset + elemIdx] = attr.value(view, attrOffset + elemIdx * attr.numByte);
array[arrayOffset + elemIdx] = attr.getValue(view, attrOffset + elemIdx * attr.numByte);
}
attrOffset += pointByteSize;
}
Expand Down
1 change: 0 additions & 1 deletion src/Process/PointCloudProcessing.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export default {
layer.material.opacity = layer.opacity;
layer.material.transparent = layer.opacity < 1;
layer.material.size = layer.pointSize;
layer.material.mode = layer.mode;
}

// lookup lowest common ancestor of changeSources
Expand Down
1 change: 1 addition & 0 deletions src/Provider/PointCloudProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export default {
layer.type = 'geometry';
layer.material = layer.material || {};
layer.material = layer.material.isMaterial ? layer.material : new PointsMaterial(layer.material);
layer.material.defines = layer.material.defines || {};
layer.mode = MODE.COLOR;

// default update methods
Expand Down
31 changes: 12 additions & 19 deletions src/Renderer/PointsMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import Capabilities from '../Core/System/Capabilities';

export const MODE = {
COLOR: 0,
PICKING: 1,
INTENSITY: 2,
CLASSIFICATION: 3,
NORMAL: 4,
INTENSITY: 1,
CLASSIFICATION: 2,
NORMAL: 3,
};

class PointsMaterial extends RawShaderMaterial {
Expand All @@ -21,7 +20,7 @@ class PointsMaterial extends RawShaderMaterial {
this.scale = options.scale || 0.05 * 0.5 / Math.tan(1.0 / 2.0); // autosizing scale
this.overlayColor = options.overlayColor || new Vector4(0, 0, 0, 0);
this.mode = options.mode || MODE.COLOR;
this.oldMode = null;
this.picking = false;

for (const key in MODE) {
if (Object.prototype.hasOwnProperty.call(MODE, key)) {
Expand All @@ -31,7 +30,7 @@ class PointsMaterial extends RawShaderMaterial {

this.uniforms.size = new Uniform(this.size);
this.uniforms.mode = new Uniform(this.mode);
this.uniforms.pickingMode = new Uniform(false);
this.uniforms.pickingMode = new Uniform(this.picking);
this.uniforms.opacity = new Uniform(this.opacity);
this.uniforms.overlayColor = new Uniform(this.overlayColor);

Expand All @@ -46,24 +45,17 @@ class PointsMaterial extends RawShaderMaterial {
this.updateUniforms();
}

enablePicking(pickingMode) {
// we don't want pixels to blend over already drawn pixels
this.blending = pickingMode ? NoBlending : NormalBlending;
if (pickingMode) {
if (this.uniforms.mode.value !== MODE.PICKING) {
this.oldMode = this.uniforms.mode.value;
this.uniforms.mode.value = MODE.PICKING;
}
} else {
this.uniforms.mode.value = this.oldMode || this.uniforms.mode.value;
this.oldMode = null;
}
enablePicking(picking) {
this.picking = picking;
this.blending = picking ? NoBlending : NormalBlending;
this.updateUniforms();
}

updateUniforms() {
// if size is null, switch to autosizing using the canvas height
this.uniforms.size.value = (this.size > 0) ? this.size : -this.scale * window.innerHeight;
this.uniforms.mode.value = this.mode || MODE.COLOR;
this.uniforms.mode.value = this.mode;
this.uniforms.pickingMode.value = this.picking;
this.uniforms.opacity.value = this.opacity;
this.uniforms.overlayColor.value = this.overlayColor;
}
Expand All @@ -74,6 +66,7 @@ class PointsMaterial extends RawShaderMaterial {
this.transparent = source.transparent;
this.size = source.size;
this.mode = source.mode;
this.picking = source.picking;
this.scale = source.scale;
this.overlayColor.copy(source.overlayColor);
this.updateUniforms();
Expand Down
3 changes: 2 additions & 1 deletion src/Renderer/Shader/PointsVS.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
uniform float size;

uniform bool pickingMode;
uniform int mode;
uniform float opacity;
uniform vec4 overlayColor;
Expand Down Expand Up @@ -57,7 +58,7 @@ vec3 decodeSphereMappedNormal(vec2 encodedNormal) {
#endif

void main() {
if (mode == MODE_PICKING) {
if (pickingMode) {
vColor = unique_id;
} else if (mode == MODE_INTENSITY) {
vColor = vec4(intensity, intensity, intensity, opacity);
Expand Down
5 changes: 4 additions & 1 deletion utils/debug/PointCloudDebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ export default {
layer.dbgDisplaybbox = false;

var styleUI = layer.debugUI.addFolder('Styling');
styleUI.add(layer, 'mode', MODE).name('Display mode').onChange(update);
styleUI.add(layer.material, 'mode', MODE).name('Display mode').onChange(update);
styleUI.add(layer, 'opacity', 0, 1).name('Layer Opacity').onChange(update);
styleUI.add(layer, 'pointSize', 0, 15).name('Point Size').onChange(update);
styleUI.add(layer, 'dbgDisplaybbox').name('Display Bounding Boxes').onChange(update);
styleUI.add(layer.material, 'picking').name('Display picking id').onChange((value) => {
update();
});

// UI
const sticky = layer.debugUI.addFolder('Sticky');
Expand Down

0 comments on commit 005bb62

Please sign in to comment.