refactoring profile
This commit is contained in:
parent
7603bf091a
commit
9e1ad3be0a
@ -231,7 +231,7 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
|
||||
near: { type: "f", value: 0.1 },
|
||||
far: { type: "f", value: 1.0 },
|
||||
uColor: { type: "c", value: new THREE.Color( 0xffffff ) },
|
||||
opacity: { type: "f", value: 1.0 },
|
||||
uOpacity: { type: "f", value: 1.0 },
|
||||
size: { type: "f", value: pointSize },
|
||||
minSize: { type: "f", value: minSize },
|
||||
maxSize: { type: "f", value: maxSize },
|
||||
@ -631,13 +631,13 @@ Potree.PointCloudMaterial = class PointCloudMaterial extends THREE.RawShaderMate
|
||||
|
||||
|
||||
get opacity(){
|
||||
return this.uniforms.opacity.value;
|
||||
return this.uniforms.uOpacity.value;
|
||||
}
|
||||
|
||||
set opacity (value) {
|
||||
if (this.uniforms && this.uniforms.opacity) {
|
||||
if (this.uniforms.opacity.value !== value) {
|
||||
this.uniforms.opacity.value = value;
|
||||
if (this.uniforms.uOpacity.value !== value) {
|
||||
this.uniforms.uOpacity.value = value;
|
||||
this.updateShaderSource();
|
||||
this.dispatchEvent({
|
||||
type: 'opacity_changed',
|
||||
|
||||
@ -154,12 +154,6 @@ void main() {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -623,4 +623,5 @@ void main() {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -1,34 +1,88 @@
|
||||
|
||||
|
||||
class ProfilePointCloud{
|
||||
class ProfilePointCloudEntry{
|
||||
|
||||
constructor(){
|
||||
|
||||
this.maxPoints = 0;
|
||||
this.points = [];
|
||||
|
||||
this.geometry = new THREE.BufferGeometry();
|
||||
this.buffers = {
|
||||
position: new Float32Array(3 * this.maxPoints),
|
||||
color: new Uint8Array(4 * this.maxPoints),
|
||||
intensity: new Uint16Array(this.maxPoints),
|
||||
classification: new Uint8Array(this.maxPoints),
|
||||
returnNumber: new Uint8Array(this.maxPoints),
|
||||
numberOfReturns: new Uint8Array(this.maxPoints),
|
||||
pointSourceID: new Uint16Array(this.maxPoints)
|
||||
};
|
||||
let geometry = new THREE.BufferGeometry();
|
||||
let material = new Potree.PointCloudMaterial();
|
||||
material.uniforms.minSize.value = 2;
|
||||
material.uniforms.maxSize.value = 2;
|
||||
material.pointColorType = Potree.PointColorType.RGB;
|
||||
material.opacity = 1.0;
|
||||
this.sceneNode = new THREE.Points(geometry, material);
|
||||
}
|
||||
|
||||
this.geometry.addAttribute('position', new THREE.BufferAttribute(this.buffers.position, 3));
|
||||
this.geometry.addAttribute('color', new THREE.BufferAttribute(this.buffers.color, 4, true));
|
||||
this.geometry.addAttribute('intensity', new THREE.BufferAttribute(this.buffers.intensity, 1, false));
|
||||
this.geometry.addAttribute('classification', new THREE.BufferAttribute(this.buffers.classification, 1, false));
|
||||
this.geometry.addAttribute('returnNumber', new THREE.BufferAttribute(this.buffers.returnNumber, 1, false));
|
||||
this.geometry.addAttribute('numberOfReturns', new THREE.BufferAttribute(this.buffers.numberOfReturns, 1, false));
|
||||
this.geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(this.buffers.pointSourceID, 1, false));
|
||||
|
||||
this.geometry.setDrawRange(0, 0);
|
||||
addPoints(data){
|
||||
this.points.push(data);
|
||||
|
||||
let projectedBox = new THREE.Box3();
|
||||
|
||||
{ // REBUILD MODEL
|
||||
|
||||
if(this.sceneNode){
|
||||
this.sceneNode.geometry.dispose();
|
||||
}
|
||||
|
||||
let numPoints = this.points.reduce((a, i) => a + i.numPoints, 0);
|
||||
|
||||
let geometry = new THREE.BufferGeometry();
|
||||
let buffers = {
|
||||
position: new Float32Array(3 * numPoints),
|
||||
color: new Uint8Array(4 * numPoints),
|
||||
intensity: new Uint16Array(numPoints),
|
||||
classification: new Uint8Array(numPoints),
|
||||
returnNumber: new Uint8Array(numPoints),
|
||||
numberOfReturns: new Uint8Array(numPoints),
|
||||
pointSourceID: new Uint16Array(numPoints)
|
||||
};
|
||||
|
||||
let pointsProcessed = 0;
|
||||
for(let part of this.points){
|
||||
|
||||
for(let i = 0; i < part.numPoints; i++){
|
||||
let x = part.data.mileage[i];
|
||||
let y = part.data.position[3 * i + 2];
|
||||
let z = 0;
|
||||
|
||||
projectedBox.expandByPoint(new THREE.Vector3(x, y, 0));
|
||||
|
||||
buffers.position[3 * pointsProcessed + 0] = x;
|
||||
buffers.position[3 * pointsProcessed + 1] = y;
|
||||
buffers.position[3 * pointsProcessed + 2] = z;
|
||||
|
||||
if( part.data.color){
|
||||
buffers.color[4 * pointsProcessed + 0] = part.data.color[4 * i + 0];
|
||||
buffers.color[4 * pointsProcessed + 1] = part.data.color[4 * i + 1];
|
||||
buffers.color[4 * pointsProcessed + 2] = part.data.color[4 * i + 2];
|
||||
buffers.color[4 * pointsProcessed + 3] = 255;
|
||||
}
|
||||
|
||||
pointsProcessed++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data.projectedBox = projectedBox;
|
||||
|
||||
this.projectedBox = this.points.reduce( (a, i) => a.union(i.projectedBox), new THREE.Box3());
|
||||
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(buffers.position, 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(buffers.color, 4, true));
|
||||
geometry.addAttribute('intensity', new THREE.BufferAttribute(buffers.intensity, 1, false));
|
||||
geometry.addAttribute('classification', new THREE.BufferAttribute(buffers.classification, 1, false));
|
||||
geometry.addAttribute('returnNumber', new THREE.BufferAttribute(buffers.returnNumber, 1, false));
|
||||
geometry.addAttribute('numberOfReturns', new THREE.BufferAttribute(buffers.numberOfReturns, 1, false));
|
||||
geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(buffers.pointSourceID, 1, false));
|
||||
|
||||
this.sceneNode.geometry = geometry;
|
||||
|
||||
}
|
||||
|
||||
|
||||
this.material = new Potree.PointCloudMaterial();
|
||||
this.material.uniforms.minSize.value = 2;
|
||||
}
|
||||
|
||||
};
|
||||
@ -233,20 +287,6 @@ Potree.ProfileWindow = class ProfileWindow extends THREE.EventDispatcher {
|
||||
|
||||
let uri = 'data:application/octet-stream;base64,' + btoa(binString);
|
||||
$('#potree_download_profile_link').attr('href', uri);
|
||||
|
||||
// let uri = "data:application/octet-stream;base64,"+btoa(string);
|
||||
// $('#potree_download_profile_ortho_link').attr("href", uri);
|
||||
|
||||
// let las = viewer.profileWindow.getPointsInProfileAsLas();
|
||||
// let u8view = new Uint8Array(las);
|
||||
//
|
||||
// let binString = "";
|
||||
// for(let i = 0; i < u8view.length; i++){
|
||||
// binString += String.fromCharCode(u8view[i]);
|
||||
// }
|
||||
//
|
||||
// let uri = "data:application/octet-stream;base64,"+btoa(binString);
|
||||
// $('#potree_download_profile_link').attr("href", uri);
|
||||
});
|
||||
}
|
||||
|
||||
@ -318,13 +358,10 @@ Potree.ProfileWindow = class ProfileWindow extends THREE.EventDispatcher {
|
||||
|
||||
this.scene = new THREE.Scene();
|
||||
|
||||
//this.model = new THREE.Points(this.geometry, this.material);
|
||||
//this.scene.add(model);
|
||||
|
||||
let sg = new THREE.SphereGeometry(1, 16, 16);
|
||||
let sm = new THREE.MeshNormalMaterial();
|
||||
this.pickSphere = new THREE.Mesh(sg, sm);
|
||||
this.pickSphere.visible = false;
|
||||
//this.pickSphere.visible = false;
|
||||
this.scene.add(this.pickSphere);
|
||||
}
|
||||
|
||||
@ -375,97 +412,53 @@ Potree.ProfileWindow = class ProfileWindow extends THREE.EventDispatcher {
|
||||
|
||||
addPoints (pointcloud, points) {
|
||||
|
||||
console.log(pointcloud);
|
||||
console.log(points);
|
||||
let entry = this.pointclouds.get(pointcloud);
|
||||
if(!entry){
|
||||
entry = new ProfilePointCloudEntry();
|
||||
this.pointclouds.set(pointcloud, entry);
|
||||
|
||||
return;
|
||||
|
||||
|
||||
let pc = this.pointclouds.get(pointcloud);
|
||||
pc.points.add(points);
|
||||
|
||||
// rebuild 3d model
|
||||
let projectedBox = new THREE.Box3();
|
||||
{
|
||||
let geometry = pc.geometry;
|
||||
|
||||
for (let attribute of Object.keys(pc.points.data)) {
|
||||
let buffer = pc.points.data[attribute];
|
||||
|
||||
if (attribute === 'position') {
|
||||
let posBuffer = new Float32Array(buffer.length);
|
||||
|
||||
for (let i = 0; i < pc.points.numPoints; i++) {
|
||||
let x = pc.points.data.mileage[i];
|
||||
let y = buffer[3 * i + 2];
|
||||
|
||||
posBuffer[3 * i + 0] = x;
|
||||
posBuffer[3 * i + 1] = y;
|
||||
posBuffer[3 * i + 2] = y;
|
||||
projectedBox.expandByPoint(new THREE.Vector3(x, y, 0));
|
||||
}
|
||||
|
||||
if (!posBuffer) {
|
||||
console.log('wtf');
|
||||
}
|
||||
|
||||
geometry.attributes[attribute].array.set(posBuffer);
|
||||
} else if (attribute === 'color') {
|
||||
geometry.attributes[attribute].array.set(buffer);
|
||||
} else if (attribute === 'mileage') {
|
||||
continue;
|
||||
} else if (geometry.attributes[attribute] === undefined) {
|
||||
continue;
|
||||
} else {
|
||||
geometry.attributes[attribute].array.set(buffer);
|
||||
}
|
||||
|
||||
geometry.attributes[attribute].needsUpdate = true;
|
||||
geometry.setDrawRange(0, pc.points.numPoints);
|
||||
}
|
||||
|
||||
let radius = pc.points.boundingBox.getSize().toArray().reduce((a, v) => Math.max(a, v));
|
||||
geometry.boundingSphere = new THREE.Sphere(this.camera.position, radius);
|
||||
geometry.boundingBox = geometry.boundingSphere.getBoundingBox();
|
||||
let materialChanged = () => this.render();
|
||||
pointcloud.material.addEventListener('material_property_changed', materialChanged);
|
||||
this.addEventListener("on_reset_once", () => {
|
||||
pointcloud.material.removeEventListener('material_property_changed', materialChanged);
|
||||
});
|
||||
}
|
||||
|
||||
this.projectedBox.union(projectedBox);
|
||||
entry.addPoints(points);
|
||||
this.scene.add(entry.sceneNode);
|
||||
|
||||
if (this.autoFit) { // SCALE
|
||||
if (this.autoFit) {
|
||||
let width = this.renderArea[0].clientWidth;
|
||||
let height = this.renderArea[0].clientHeight;
|
||||
|
||||
let size = this.projectedBox.getSize();
|
||||
let size = entry.projectedBox.getSize();
|
||||
|
||||
let sx = width / size.x;
|
||||
let sy = height / size.y;
|
||||
let scale = Math.min(sx, sy);
|
||||
|
||||
let center = this.projectedBox.getCenter();
|
||||
let center = entry.projectedBox.getCenter();
|
||||
this.scale.set(scale, scale, 1);
|
||||
this.camera.position.copy(center);
|
||||
}
|
||||
|
||||
let numPoints = 0;
|
||||
for (let entry of this.pointclouds.entries()) {
|
||||
numPoints += entry[1].points.numPoints;
|
||||
|
||||
$(`#profile_num_points`).html(Potree.utils.addCommas(numPoints));
|
||||
}
|
||||
|
||||
this.render();
|
||||
|
||||
let numPoints = 0;
|
||||
for (let [key, value] of this.pointclouds.entries()) {
|
||||
numPoints += value.points.reduce( (a, i) => a + i.numPoints, 0);
|
||||
}
|
||||
$(`#profile_num_points`).html(Potree.utils.addCommas(numPoints));
|
||||
|
||||
}
|
||||
|
||||
reset () {
|
||||
this.dispatchEvent({type: "on_reset_once"});
|
||||
this.removeEventListeners("on_reset_once");
|
||||
|
||||
this.autoFit = true;
|
||||
this.projectedBox = new THREE.Box3();
|
||||
|
||||
//for (let entry of this.pointclouds) {
|
||||
// for (let listener of entry[1].listeners) {
|
||||
// listener.target.removeEventListener(listener.type, listener.callback);
|
||||
// }
|
||||
//}
|
||||
|
||||
this.pointclouds.clear();
|
||||
this.mouseIsDown = false;
|
||||
this.mouse.set(0, 0);
|
||||
@ -474,7 +467,11 @@ Potree.ProfileWindow = class ProfileWindow extends THREE.EventDispatcher {
|
||||
|
||||
this.scene.children
|
||||
.filter(c => c instanceof THREE.Points)
|
||||
.forEach(c => this.scene.remove(c));
|
||||
.forEach(c => {
|
||||
this.scene.remove(c);
|
||||
c.geometry.dispose();
|
||||
c.material.dispose();
|
||||
});
|
||||
|
||||
this.elRoot.find('#profileSelectionProperties').hide();
|
||||
|
||||
@ -523,10 +520,9 @@ Potree.ProfileWindow = class ProfileWindow extends THREE.EventDispatcher {
|
||||
this.pickSphere.scale.set(radius, radius, radius);
|
||||
this.pickSphere.position.z = this.camera.far - radius;
|
||||
|
||||
for (let entry of this.pointclouds) {
|
||||
let pointcloud = entry[0];
|
||||
let material = entry[1].material;
|
||||
|
||||
for (let [pointcloud, entry] of this.pointclouds) {
|
||||
let material = entry.sceneNode.material;
|
||||
|
||||
material.pointColorType = pointcloud.material.pointColorType;
|
||||
material.uniforms.intensityRange.value = pointcloud.material.uniforms.intensityRange.value;
|
||||
material.heightMin = pointcloud.material.heightMin;
|
||||
@ -540,6 +536,8 @@ Potree.ProfileWindow = class ProfileWindow extends THREE.EventDispatcher {
|
||||
material.intensityBrightness = pointcloud.material.intensityBrightness;
|
||||
}
|
||||
|
||||
this.pickSphere.visible = false;
|
||||
|
||||
this.renderer.setSize(width, height);
|
||||
|
||||
this.renderer.render(this.scene, this.camera);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user