@giro3d/giro3d
Version:
A JS/WebGL framework for 3D geospatial data visualization
77 lines (73 loc) • 2.09 kB
JavaScript
import { Points } from 'three';
import { enablePointCloudPostProcessing } from '../renderer/RenderPipeline';
import { nonNull } from '../utils/tsutils';
/** Options for constructing {@link PointCloud} */
/**
* A point cloud object with geospatial properties.
*
*/
class PointCloud extends Points {
isPointCloud = true;
type = 'PointCloud';
static isPointCloud(obj) {
return obj?.isPointCloud;
}
get level() {
if (PointCloud.isPointCloud(this.parent)) {
return this.parent.level + 1;
} else {
return 0;
}
}
constructor(opts) {
super(opts.geometry, opts.material);
enablePointCloudPostProcessing(this);
this.extent = opts.extent ?? undefined;
this.textureSize = opts.textureSize;
this.disposed = false;
}
getPointValue(pointIndex, attribute) {
if (this.geometry.hasAttribute(attribute)) {
const buffer = this.geometry.getAttribute(attribute).array;
return buffer[pointIndex];
}
return undefined;
}
/**
* Returns the intensity of the specified point.
*
* @param pointIndex - The index of the point.
* @returns The intensity value for the specified point, or `undefined` if this point cloud does not support intensities.
*/
getIntensity(pointIndex) {
return this.getPointValue(pointIndex, 'intensity');
}
/**
* Returns the classification number of the specified point.
*
* @param pointIndex - The index of the point.
* @returns The classification number for the specified point, or `undefined` if this point cloud does not support classifications.
*/
getClassification(pointIndex) {
return this.getPointValue(pointIndex, 'classification');
}
canProcessColorLayer() {
return true;
}
getExtent() {
return nonNull(this.extent);
}
dispose() {
if (this.disposed) {
return;
}
this.disposed = true;
// @ts-expect-error Points does not transmit proper event map to parent
this.dispatchEvent({
type: 'dispose'
});
this.geometry.dispose();
this.material.dispose();
}
}
export default PointCloud;