update new format loader
This commit is contained in:
parent
8f24daeccd
commit
4cc31281d7
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -1,6 +1,7 @@
|
||||
|
||||
Please follow these instructions when creating a new pull request:
|
||||
|
||||
* Validating PRs can take a lot of time. The simpler the PR, the higher the chance that it will get accepted.
|
||||
* Set the potree develop branch as the PR target.
|
||||
* Builds should not be part of the PR. Don't commit them.
|
||||
* Do not use a formatter. They make a mess out of diffs.
|
||||
|
||||
@ -372,7 +372,21 @@ export class PointCloudOctree extends PointCloudTree {
|
||||
data[parentOffset * 4 + 2] = (offsetsToChild[parentOffset] % 256);
|
||||
}
|
||||
|
||||
data[i * 4 + 3] = node.name.length - 1;
|
||||
// data[i * 4 + 3] = node.geometryNode.nodeType === 1 ? 1 : 0;
|
||||
// data[i * 4 + 3] = node.name.length - 1;
|
||||
|
||||
let density = node.geometryNode.density;
|
||||
|
||||
if(typeof density === "number"){
|
||||
let lodOffset = Math.log2(density) / 2 - 1.5;
|
||||
|
||||
let offsetUint8 = (lodOffset + 10) * 10;
|
||||
|
||||
data[i * 4 + 3] = offsetUint8;
|
||||
}else{
|
||||
data[i * 4 + 3] = 100;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var a = 10;
|
||||
|
||||
124
src/Potree.js
124
src/Potree.js
@ -32,6 +32,7 @@ export * from "./materials/NormalizationMaterial.js";
|
||||
export * from "./materials/PointCloudMaterial.js";
|
||||
|
||||
export * from "./loader/POCLoader.js";
|
||||
export * from "./modules/Loader_1.8/OctreeLoader_1_8.js";
|
||||
export * from "./loader/EptLoader.js";
|
||||
export * from "./loader/ept/BinaryLoader.js";
|
||||
export * from "./loader/ept/LaszipLoader.js";
|
||||
@ -79,6 +80,7 @@ import "./extensions/PerspectiveCamera.js";
|
||||
import "./extensions/Ray.js";
|
||||
|
||||
import {LRU} from "./LRU.js";
|
||||
import {OctreeLoader_1_8} from "./modules/Loader_1.8/OctreeLoader_1_8.js";
|
||||
import {POCLoader} from "./loader/POCLoader.js";
|
||||
import {EptLoader} from "./loader/EptLoader.js";
|
||||
import {PointCloudOctree} from "./PointCloudOctree.js";
|
||||
@ -127,47 +129,93 @@ export {scriptPath, resourcePath};
|
||||
|
||||
|
||||
export function loadPointCloud(path, name, callback){
|
||||
let loaded = function(pointcloud){
|
||||
pointcloud.name = name;
|
||||
callback({type: 'pointcloud_loaded', pointcloud: pointcloud});
|
||||
let loaded = function(e){
|
||||
e.pointcloud.name = name;
|
||||
callback(e);
|
||||
};
|
||||
|
||||
// load pointcloud
|
||||
if (!path){
|
||||
// TODO: callback? comment? Hello? Bueller? Anyone?
|
||||
} else if (path.indexOf('ept.json') > 0) {
|
||||
EptLoader.load(path, function(geometry) {
|
||||
if (!geometry) {
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
}
|
||||
else {
|
||||
let pointcloud = new PointCloudOctree(geometry);
|
||||
loaded(pointcloud);
|
||||
}
|
||||
let promise = new Promise( resolve => {
|
||||
|
||||
// load pointcloud
|
||||
if (!path){
|
||||
// TODO: callback? comment? Hello? Bueller? Anyone?
|
||||
} else if (path.indexOf('ept.json') > 0) {
|
||||
EptLoader.load(path, function(geometry) {
|
||||
if (!geometry) {
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
}
|
||||
else {
|
||||
let pointcloud = new PointCloudOctree(geometry);
|
||||
//loaded(pointcloud);
|
||||
resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
|
||||
}
|
||||
});
|
||||
} else if (path.indexOf('cloud.js') > 0) {
|
||||
POCLoader.load(path, function (geometry) {
|
||||
if (!geometry) {
|
||||
//callback({type: 'loading_failed'});
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
} else {
|
||||
let pointcloud = new PointCloudOctree(geometry);
|
||||
// loaded(pointcloud);
|
||||
resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
|
||||
}
|
||||
});
|
||||
} else if (path.indexOf('metadata.json') > 0) {
|
||||
Potree.OctreeLoader_1_8.load(path).then(e => {
|
||||
let geometry = e.geometry;
|
||||
|
||||
if(!geometry){
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
}else{
|
||||
let pointcloud = new PointCloudOctree(geometry);
|
||||
|
||||
let aPosition = pointcloud.getAttribute("position");
|
||||
|
||||
let material = pointcloud.material;
|
||||
material.elevationRange = [
|
||||
aPosition.range[0][2],
|
||||
aPosition.range[1][2],
|
||||
];
|
||||
|
||||
// loaded(pointcloud);
|
||||
resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
|
||||
}
|
||||
});
|
||||
|
||||
OctreeLoader_1_8.load(path, function (geometry) {
|
||||
if (!geometry) {
|
||||
//callback({type: 'loading_failed'});
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
} else {
|
||||
let pointcloud = new PointCloudOctree(geometry);
|
||||
// loaded(pointcloud);
|
||||
resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
|
||||
}
|
||||
});
|
||||
} else if (path.indexOf('.vpc') > 0) {
|
||||
PointCloudArena4DGeometry.load(path, function (geometry) {
|
||||
if (!geometry) {
|
||||
//callback({type: 'loading_failed'});
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
} else {
|
||||
let pointcloud = new PointCloudArena4D(geometry);
|
||||
// loaded(pointcloud);
|
||||
resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//callback({'type': 'loading_failed'});
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
}
|
||||
});
|
||||
|
||||
if(callback){
|
||||
promise.then(pointcloud => {
|
||||
loaded(pointcloud);
|
||||
});
|
||||
} else if (path.indexOf('cloud.js') > 0) {
|
||||
POCLoader.load(path, function (geometry) {
|
||||
if (!geometry) {
|
||||
//callback({type: 'loading_failed'});
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
} else {
|
||||
let pointcloud = new PointCloudOctree(geometry);
|
||||
loaded(pointcloud);
|
||||
}
|
||||
});
|
||||
} else if (path.indexOf('.vpc') > 0) {
|
||||
PointCloudArena4DGeometry.load(path, function (geometry) {
|
||||
if (!geometry) {
|
||||
//callback({type: 'loading_failed'});
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
} else {
|
||||
let pointcloud = new PointCloudArena4D(geometry);
|
||||
loaded(pointcloud);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//callback({'type': 'loading_failed'});
|
||||
console.error(new Error(`failed to load point cloud from URL: ${path}`));
|
||||
}else{
|
||||
return promise;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -240,8 +240,35 @@ float getLOD(){
|
||||
depth++;
|
||||
}else{
|
||||
// no more visible child nodes at this position
|
||||
return value.a * 255.0;
|
||||
//return depth;
|
||||
//return value.a * 255.0;
|
||||
|
||||
float lodOffset = (255.0 * value.a) / 10.0 - 10.0;
|
||||
|
||||
return depth + lodOffset;
|
||||
|
||||
// if(255.0 * value.a < 4.0){
|
||||
// return depth - 0.5;
|
||||
// }if(255.0 * value.a < 12.0){
|
||||
// return depth;
|
||||
// }else if(255.0 * value.a < 24.0){
|
||||
// return depth + 1.0;
|
||||
// }else if(255.0 * value.a < 48.0){
|
||||
// return depth + 1.5;
|
||||
// }else{
|
||||
// return depth + 2.0;
|
||||
// }
|
||||
|
||||
// return depth;
|
||||
|
||||
// test
|
||||
// bool isLeaf = value.a > 0.0;
|
||||
|
||||
// if(isLeaf){
|
||||
// return 1000.0;
|
||||
// }else{
|
||||
// //return value.a * 255.0;
|
||||
// return depth;
|
||||
// }
|
||||
}
|
||||
|
||||
offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;
|
||||
@ -683,16 +710,22 @@ float getPointSize(){
|
||||
pointSize = (worldSpaceSize / uOrthoWidth) * uScreenWidth;
|
||||
} else {
|
||||
|
||||
if(uIsLeafNode && false){
|
||||
pointSize = size * spacing * projFactor;
|
||||
}else{
|
||||
// float leafSpacing = 0.122069092 * 8.0;
|
||||
|
||||
// bool isLeafNode = getLOD() == 1000.0;
|
||||
// if(isLeafNode){
|
||||
// // pointSize = size * spacing * projFactor;
|
||||
|
||||
// float worldSpaceSize = size * leafSpacing;
|
||||
// pointSize = worldSpaceSize * projFactor;
|
||||
// }else{
|
||||
float worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation();
|
||||
|
||||
// minimum world space size
|
||||
// worldSpaceSize = max(worldSpaceSize, 0.02);
|
||||
// worldSpaceSize = max(worldSpaceSize, leafSpacing);
|
||||
|
||||
pointSize = worldSpaceSize * projFactor;
|
||||
}
|
||||
// }
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ Potree = {};
|
||||
|
||||
onmessage = function (event) {
|
||||
|
||||
let {buffer, pointAttributes, scale, min, offset} = event.data;
|
||||
let {buffer, pointAttributes, scale, name, min, max, size, offset} = event.data;
|
||||
|
||||
let numPoints = buffer.byteLength / pointAttributes.byteSize;
|
||||
let view = new DataView(buffer);
|
||||
@ -33,6 +33,28 @@ onmessage = function (event) {
|
||||
bytesPerPoint += pointAttribute.byteSize;
|
||||
}
|
||||
|
||||
let gridSize = 32;
|
||||
let grid = new Uint32Array(gridSize ** 3);
|
||||
let toIndex = (x, y, z) => {
|
||||
// let dx = gridSize * (x - min.x) / size.x;
|
||||
// let dy = gridSize * (y - min.y) / size.y;
|
||||
// let dz = gridSize * (z - min.z) / size.z;
|
||||
|
||||
// min is already subtracted
|
||||
let dx = gridSize * x / size.x;
|
||||
let dy = gridSize * y / size.y;
|
||||
let dz = gridSize * z / size.z;
|
||||
|
||||
let ix = Math.min(parseInt(dx), gridSize - 1);
|
||||
let iy = Math.min(parseInt(dy), gridSize - 1);
|
||||
let iz = Math.min(parseInt(dz), gridSize - 1);
|
||||
|
||||
let index = ix + iy * gridSize + iz * gridSize * gridSize;
|
||||
|
||||
return index;
|
||||
};
|
||||
|
||||
let numOccupiedCells = 0;
|
||||
for (let pointAttribute of pointAttributes.attributes) {
|
||||
|
||||
if(["POSITION_CARTESIAN", "position"].includes(pointAttribute.name)){
|
||||
@ -47,6 +69,12 @@ onmessage = function (event) {
|
||||
let y = (view.getUint32(pointOffset + attributeOffset + 4, true) * scale[1]) + offset[1] - min.y;
|
||||
let z = (view.getUint32(pointOffset + attributeOffset + 8, true) * scale[2]) + offset[2] - min.z;
|
||||
|
||||
let index = toIndex(x, y, z);
|
||||
let count = grid[index]++;
|
||||
if(count === 0){
|
||||
numOccupiedCells++;
|
||||
}
|
||||
|
||||
positions[3 * j + 0] = x;
|
||||
positions[3 * j + 1] = y;
|
||||
positions[3 * j + 2] = z;
|
||||
@ -74,23 +102,20 @@ onmessage = function (event) {
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let f32 = new Float32Array(buff);
|
||||
|
||||
// console.log(pointAttribute.name, pointAttribute.type.name);
|
||||
|
||||
let TypedArray = typedArrayMapping[pointAttribute.type.name];
|
||||
preciseBuffer = new TypedArray(numPoints);
|
||||
|
||||
let [min, max] = [Infinity, -Infinity];
|
||||
let [offset, scale] = [0, 1];
|
||||
|
||||
const getterMap = {
|
||||
"int8": view.getInt8,
|
||||
"int16": view.getInt16,
|
||||
"int32": view.getInt32,
|
||||
"int64": view.getInt64,
|
||||
// "int64": view.getInt64,
|
||||
"uint8": view.getUint8,
|
||||
"uint16": view.getUint16,
|
||||
"uint32": view.getUint32,
|
||||
"uint64": view.getUint64,
|
||||
// "uint64": view.getUint64,
|
||||
"float": view.getFloat32,
|
||||
"double": view.getFloat64,
|
||||
};
|
||||
@ -98,47 +123,19 @@ onmessage = function (event) {
|
||||
|
||||
// compute offset and scale to pack larger types into 32 bit floats
|
||||
if(pointAttribute.type.size > 4){
|
||||
|
||||
let [amin, amax] = pointAttribute.range;
|
||||
offset = amin;
|
||||
scale = 1 / (amax - amin);
|
||||
|
||||
// for(let j = 0; j < numPoints; j++){
|
||||
// let pointOffset = j * bytesPerPoint;
|
||||
// let value = getter(pointOffset + attributeOffset, true);
|
||||
|
||||
// if(!Number.isNaN(value)){
|
||||
// min = Math.min(min, value);
|
||||
// max = Math.max(max, value);
|
||||
// }
|
||||
// }
|
||||
|
||||
// if(pointAttribute.initialRange != null){
|
||||
// offset = pointAttribute.initialRange[0];
|
||||
// scale = 1 / (pointAttribute.initialRange[1] - pointAttribute.initialRange[0]);
|
||||
// }else{
|
||||
// offset = min;
|
||||
// scale = 1 / (max - min);
|
||||
// }
|
||||
}
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
let pointOffset = j * bytesPerPoint;
|
||||
let value = getter(pointOffset + attributeOffset, true);
|
||||
|
||||
if(!Number.isNaN(value)){
|
||||
min = Math.min(min, value);
|
||||
max = Math.max(max, value);
|
||||
}
|
||||
|
||||
f32[j] = (value - offset) * scale;
|
||||
preciseBuffer[j] = value;
|
||||
}
|
||||
|
||||
// pointAttribute.range = [min, max];
|
||||
|
||||
//console.log(pointAttribute.range);
|
||||
//attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
attributeBuffers[pointAttribute.name] = {
|
||||
buffer: buff,
|
||||
preciseBuffer: preciseBuffer,
|
||||
@ -153,6 +150,9 @@ onmessage = function (event) {
|
||||
|
||||
}
|
||||
|
||||
let occupancy = parseInt(numPoints / numOccupiedCells);
|
||||
// console.log(`${name}: #points: ${numPoints}: #occupiedCells: ${numOccupiedCells}, occupancy: ${occupancy} points/cell`);
|
||||
|
||||
{ // add indices
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let indices = new Uint32Array(buff);
|
||||
@ -208,6 +208,7 @@ onmessage = function (event) {
|
||||
let message = {
|
||||
buffer: buffer,
|
||||
attributeBuffers: attributeBuffers,
|
||||
density: occupancy,
|
||||
};
|
||||
|
||||
let transferables = [];
|
||||
|
||||
@ -78,19 +78,12 @@ export class NodeLoader{
|
||||
};
|
||||
|
||||
geometry.addAttribute(property, bufferAttribute);
|
||||
|
||||
const attribute = pointAttributes.attributes.find(a => a.name === batchAttribute.name);
|
||||
// attribute.range[0] = Math.min(attribute.range[0], batchAttribute.range[0]);
|
||||
// attribute.range[1] = Math.max(attribute.range[1], batchAttribute.range[1]);
|
||||
|
||||
// if(node.getLevel() === 0){
|
||||
// attribute.initialRange = batchAttribute.range;
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
// indices ??
|
||||
|
||||
node.density = data.density;
|
||||
node.geometry = geometry;
|
||||
node.loaded = true;
|
||||
node.loading = false;
|
||||
@ -100,8 +93,11 @@ export class NodeLoader{
|
||||
let pointAttributes = node.octreeGeometry.pointAttributes;
|
||||
let scale = node.octreeGeometry.scale;
|
||||
|
||||
let min = node.octreeGeometry.offset.clone().add(node.boundingBox.min);
|
||||
//let min = node.boundingBox.min;
|
||||
let box = node.boundingBox;
|
||||
let min = node.octreeGeometry.offset.clone().add(box.min);
|
||||
let size = box.max.clone().sub(box.min);
|
||||
let max = min.clone().add(size);
|
||||
|
||||
let offset = node.octreeGeometry.loader.offset;
|
||||
|
||||
let message = {
|
||||
@ -110,8 +106,9 @@ export class NodeLoader{
|
||||
pointAttributes: pointAttributes,
|
||||
scale: scale,
|
||||
min: min,
|
||||
max: max,
|
||||
size: size,
|
||||
offset: offset,
|
||||
//min: node.boundingBox.min,
|
||||
};
|
||||
|
||||
worker.postMessage(message, [message.buffer]);
|
||||
@ -310,12 +307,12 @@ export class OctreeLoader_1_8{
|
||||
|
||||
let attribute = new PointAttribute(potreeAttributeName, type, numElements);
|
||||
|
||||
// attribute.range = {
|
||||
// min: min,
|
||||
// max: max,
|
||||
// };
|
||||
// TODO should support vector ranges
|
||||
attribute.range = [min[0], max[0]];
|
||||
if(numElements === 1){
|
||||
attribute.range = [min[0], max[0]];
|
||||
}else{
|
||||
attribute.range = [min, max];
|
||||
}
|
||||
|
||||
attribute.initialRange = attribute.range;
|
||||
|
||||
attributes.add(attribute);
|
||||
@ -358,6 +355,9 @@ export class OctreeLoader_1_8{
|
||||
octree.spacing = metadata.spacing;
|
||||
octree.scale = metadata.scale;
|
||||
|
||||
// let aPosition = metadata.attributes.find(a => a.name === "position");
|
||||
// octree
|
||||
|
||||
let min = new THREE.Vector3(...metadata.boundingBox.min);
|
||||
let max = new THREE.Vector3(...metadata.boundingBox.max);
|
||||
let boundingBox = new THREE.Box3(min, max);
|
||||
|
||||
@ -730,15 +730,32 @@ export class PropertiesPanel{
|
||||
});
|
||||
|
||||
let updateHeightRange = function () {
|
||||
let box = [pointcloud.pcoGeometry.tightBoundingBox, pointcloud.getBoundingBoxWorld()]
|
||||
.find(v => v !== undefined);
|
||||
|
||||
|
||||
pointcloud.updateMatrixWorld(true);
|
||||
box = Utils.computeTransformedBoundingBox(box, pointcloud.matrixWorld);
|
||||
let aPosition = pointcloud.getAttribute("position");
|
||||
|
||||
let bWidth = box.max.z - box.min.z;
|
||||
let bMin = box.min.z - 0.2 * bWidth;
|
||||
let bMax = box.max.z + 0.2 * bWidth;
|
||||
let bMin, bMax;
|
||||
|
||||
if(aPosition){
|
||||
// for new format 2.0 and loader that contain precomputed min/max of attributes
|
||||
let min = aPosition.range[0][2];
|
||||
let max = aPosition.range[1][2];
|
||||
let width = max - min;
|
||||
|
||||
bMin = min - 0.2 * width;
|
||||
bMax = max + 0.2 * width;
|
||||
}else{
|
||||
// for format up until exlusive 2.0
|
||||
let box = [pointcloud.pcoGeometry.tightBoundingBox, pointcloud.getBoundingBoxWorld()]
|
||||
.find(v => v !== undefined);
|
||||
|
||||
pointcloud.updateMatrixWorld(true);
|
||||
box = Utils.computeTransformedBoundingBox(box, pointcloud.matrixWorld);
|
||||
|
||||
let bWidth = box.max.z - box.min.z;
|
||||
bMin = box.min.z - 0.2 * bWidth;
|
||||
bMax = box.max.z + 0.2 * bWidth;
|
||||
}
|
||||
|
||||
let range = material.elevationRange;
|
||||
|
||||
@ -754,10 +771,15 @@ export class PropertiesPanel{
|
||||
if(attribute == null){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let range = material.getRange(attributeName);
|
||||
|
||||
// currently only supporting scalar ranges.
|
||||
// rgba, normals, positions, etc have vector ranges, however
|
||||
if(typeof range !== "number"){
|
||||
return;
|
||||
}
|
||||
|
||||
if(range == null){
|
||||
range = attribute.range;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user