Skip to content

Commit

Permalink
refactor(PointCloudLayer): add new scheme and gradients to generate t…
Browse files Browse the repository at this point in the history
…exture for use in the shader
  • Loading branch information
ftoromanoff committed Feb 28, 2024
1 parent 89d6fbd commit a557914
Show file tree
Hide file tree
Showing 9 changed files with 494 additions and 70 deletions.
3 changes: 2 additions & 1 deletion examples/entwine_simple_loader.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@

view.addLayer(eptLayer).then(onLayerReady);

debug.PotreeDebug.initTools(view, eptLayer, debugGui);
eptLayer.whenReady
.then(() => debug.PotreeDebug.initTools(view, eptLayer, debugGui));

function dblClickHandler(event) {
var pick = view.pickObjectsAt(event, 5, eptLayer);
Expand Down
2 changes: 2 additions & 0 deletions src/Layer/EntwinePointTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class EntwinePointTileLayer extends PointCloudLayer {
this.root = new EntwinePointTileNode(0, 0, 0, 0, this, -1);
this.root.bbox.min.fromArray(this.source.boundsConforming, 0);
this.root.bbox.max.fromArray(this.source.boundsConforming, 3);
this.minElevationRange = this.source.boundsConforming[2];
this.maxElevationRange = this.source.boundsConforming[5];

this.extent = Extent.fromBox3(config.crs || 'EPSG:4326', this.root.bbox);
return this.root.loadOctree().then(resolve);
Expand Down
22 changes: 17 additions & 5 deletions src/Layer/PointCloudLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,15 @@ function markForDeletion(elt) {
}

function changeIntensityRange(layer) {
if (layer.material.intensityRange) {
layer.material.intensityRange.set(layer.minIntensityRange, layer.maxIntensityRange);
}
layer.material.intensityRange?.set(layer.minIntensityRange, layer.maxIntensityRange);
}

function changeElevationRange(layer) {
layer.material.elevationRange?.set(layer.minElevationRange, layer.maxElevationRange);
}

function changeAngleRange(layer) {
layer.material.angleRange?.set(layer.minAngleRange, layer.maxAngleRange);
}

/**
Expand Down Expand Up @@ -158,13 +164,19 @@ class PointCloudLayer extends GeometryLayer {
this.pointSize = config.pointSize === 0 || !isNaN(config.pointSize) ? config.pointSize : 4;
this.sseThreshold = config.sseThreshold || 2;

this.defineLayerProperty('minIntensityRange', config.minIntensityRange || 0, changeIntensityRange);
this.defineLayerProperty('maxIntensityRange', config.maxIntensityRange || 1, changeIntensityRange);
this.defineLayerProperty('minIntensityRange', config.minIntensityRange || 1, changeIntensityRange);
this.defineLayerProperty('maxIntensityRange', config.maxIntensityRange || 65536, changeIntensityRange);
this.defineLayerProperty('minElevationRange', config.minElevationRange || 0, changeElevationRange);
this.defineLayerProperty('maxElevationRange', config.maxElevationRange || 1000, changeElevationRange);
this.defineLayerProperty('minAngleRange', config.minAngleRange || -90, changeAngleRange);
this.defineLayerProperty('maxAngleRange', config.maxAngleRange || 90, changeAngleRange);

this.material = config.material || {};
if (!this.material.isMaterial) {
config.material = config.material || {};
config.material.intensityRange = new THREE.Vector2(this.minIntensityRange, this.maxIntensityRange);
config.material.elevationRange = new THREE.Vector2(this.minElevationRange, this.maxElevationRange);
config.material.angleRange = new THREE.Vector2(this.minAngleRange, this.maxAngleRange);
this.material = new PointsMaterial(config.material);
}
this.material.defines = this.material.defines || {};
Expand Down
11 changes: 11 additions & 0 deletions src/Parser/LASLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class LASLoader {
const getPointSourceID = view.getter('PointSourceId');
const getColor = view.dimensions.Red ?
['Red', 'Green', 'Blue'].map(view.getter) : undefined;
const getScanAngle = view.getter('ScanAngle');

const positions = new Float32Array(view.pointCount * 3);
const intensities = new Uint16Array(view.pointCount);
Expand All @@ -61,6 +62,14 @@ class LASLoader {
const classifications = new Uint8Array(view.pointCount);
const pointSourceIDs = new Uint16Array(view.pointCount);
const colors = getColor ? new Uint8Array(view.pointCount * 4) : undefined;
/*
As described by the LAS spec, Scan Angle is encoded:
- as signed char in a valid range from -90 to +90 (degrees) prior to the LAS 1.4 Point Data Record Formats (PDRF) 6
- as a signed short in a valid range from -30 000 to +30 000. Those values represents scan angles from -180 to +180
degrees with an increment of 0.006 for PDRF >= 6.
The copc.js library does the degree convertion and stores it as a `Float32`.
*/
const scanAngles = new Float32Array(view.pointCount);

for (let i = 0; i < view.pointCount; i++) {
// `getPosition` apply scale and offset transform to the X, Y, Z
Expand Down Expand Up @@ -94,6 +103,7 @@ class LASLoader {

classifications[i] = getClassification(i);
pointSourceIDs[i] = getPointSourceID(i);
scanAngles[i] = getScanAngle(i);
}

return {
Expand All @@ -104,6 +114,7 @@ class LASLoader {
classification: classifications,
pointSourceID: pointSourceIDs,
color: colors,
scanAngle: scanAngles,
};
}

Expand Down
6 changes: 4 additions & 2 deletions src/Parser/LASParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default {
const positionBuffer = new THREE.BufferAttribute(attributes.position, 3);
geometry.setAttribute('position', positionBuffer);

const intensityBuffer = new THREE.BufferAttribute(attributes.intensity, 1, true);
const intensityBuffer = new THREE.BufferAttribute(attributes.intensity, 1);
geometry.setAttribute('intensity', intensityBuffer);

const returnNumber = new THREE.BufferAttribute(attributes.returnNumber, 1);
Expand All @@ -59,7 +59,7 @@ export default {
const numberOfReturns = new THREE.BufferAttribute(attributes.numberOfReturns, 1);
geometry.setAttribute('numberOfReturns', numberOfReturns);

const classBuffer = new THREE.BufferAttribute(attributes.classification, 1, true);
const classBuffer = new THREE.BufferAttribute(attributes.classification, 1);
geometry.setAttribute('classification', classBuffer);

const pointSourceID = new THREE.BufferAttribute(attributes.pointSourceID, 1);
Expand All @@ -69,6 +69,8 @@ export default {
const colorBuffer = new THREE.BufferAttribute(attributes.color, 4, true);
geometry.setAttribute('color', colorBuffer);
}
const scanAngle = new THREE.BufferAttribute(attributes.scanAngle, 1);
geometry.setAttribute('scanAngle', scanAngle);

geometry.computeBoundingBox();
return geometry;
Expand Down
Loading

0 comments on commit a557914

Please sign in to comment.