updated builds

This commit is contained in:
mschuetz 2014-12-17 13:03:43 +01:00
parent 7fada95d6e
commit d1de7f23e3
2 changed files with 417 additions and 61 deletions

View File

@ -699,6 +699,8 @@ Potree.LasLazBatcher = function(node){
var returnNumbers_f = new Float32Array(returnNumbers.byteLength);
var pointSourceIDs = new Uint16Array(e.data.pointSourceID);
var pointSourceIDs_f = new Float32Array(pointSourceIDs.length);
var indices = new ArrayBuffer(numPoints*4);
var iIndices = new Uint32Array(indices);
var box = new THREE.Box3();
@ -707,6 +709,7 @@ Potree.LasLazBatcher = function(node){
classifications_f[i] = classifications[i];
returnNumbers_f[i] = returnNumbers[i];
pointSourceIDs_f[i] = pointSourceIDs[i];
iIndices[i] = i;
box.expandByPoint(new THREE.Vector3(fPositions[3*i+0], fPositions[3*i+1], fPositions[3*i+2]));
}
@ -717,6 +720,7 @@ Potree.LasLazBatcher = function(node){
geometry.addAttribute('classification', new THREE.BufferAttribute(new Float32Array(classifications_f), 1));
geometry.addAttribute('returnNumber', new THREE.BufferAttribute(new Float32Array(returnNumbers_f), 1));
geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(new Float32Array(pointSourceIDs_f), 1));
geometry.addAttribute('indices', new THREE.BufferAttribute(indices, 1));
//geometry.boundingBox = node.boundingBox;
geometry.boundingBox = new THREE.Box3(mins, maxs);
node.boundingBox = geometry.boundingBox;
@ -744,6 +748,16 @@ Potree.LasLazBatcher = function(node){
}
};
//
//
//
// how to calculate the radius of a projected sphere in screen space
// http://stackoverflow.com/questions/21648630/radius-of-projected-sphere-in-screen-space
// http://stackoverflow.com/questions/3717226/radius-of-projected-sphere
//
Potree.PointSizeType = {
FIXED: 0,
ATTENUATED: 1,
@ -791,18 +805,24 @@ Potree.PointCloudMaterial = function(parameters){
var attributes = {};
var uniforms = {
uColor: { type: "c", value: new THREE.Color( 0xff0000 ) },
opacity: { type: "f", value: 1.0 },
size: { type: "f", value: 10 },
minSize: { type: "f", value: 2 },
nodeSize: { type: "f", value: nodeSize },
heightMin: { type: "f", value: 0.0 },
heightMax: { type: "f", value: 1.0 },
intensityMin: { type: "f", value: 0.0 },
intensityMax: { type: "f", value: 1.0 },
visibleNodes: { type: "t", value: this.visibleNodesTexture },
pcIndex: { type: "f", value: 0 },
gradient: {type: "t", value: this.gradientTexture},
spacing: { type: "f", value: 1.0 },
fov: { type: "f", value: 1.0 },
screenWidth: { type: "f", value: 1.0 },
screenHeight: { type: "f", value: 1.0 },
near: { type: "f", value: 0.1 },
far: { type: "f", value: 1.0 },
uColor: { type: "c", value: new THREE.Color( 0xff0000 ) },
opacity: { type: "f", value: 1.0 },
size: { type: "f", value: 10 },
minSize: { type: "f", value: 2 },
nodeSize: { type: "f", value: nodeSize },
heightMin: { type: "f", value: 0.0 },
heightMax: { type: "f", value: 1.0 },
intensityMin: { type: "f", value: 0.0 },
intensityMax: { type: "f", value: 1.0 },
visibleNodes: { type: "t", value: this.visibleNodesTexture },
pcIndex: { type: "f", value: 0 },
gradient: {type: "t", value: this.gradientTexture},
};
@ -915,6 +935,78 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){
return defines;
};
Object.defineProperty(Potree.PointCloudMaterial.prototype, "spacing", {
get: function(){
return this.uniforms.spacing.value;
},
set: function(value){
if(this.uniforms.spacing.value !== value){
this.uniforms.spacing.value = value;
//this.updateShaderSource();
}
}
});
Object.defineProperty(Potree.PointCloudMaterial.prototype, "fov", {
get: function(){
return this.uniforms.fov.value;
},
set: function(value){
if(this.uniforms.fov.value !== value){
this.uniforms.fov.value = value;
//this.updateShaderSource();
}
}
});
Object.defineProperty(Potree.PointCloudMaterial.prototype, "screenWidth", {
get: function(){
return this.uniforms.screenWidth.value;
},
set: function(value){
if(this.uniforms.screenWidth.value !== value){
this.uniforms.screenWidth.value = value;
//this.updateShaderSource();
}
}
});
Object.defineProperty(Potree.PointCloudMaterial.prototype, "screenHeight", {
get: function(){
return this.uniforms.screenHeight.value;
},
set: function(value){
if(this.uniforms.screenHeight.value !== value){
this.uniforms.screenHeight.value = value;
//this.updateShaderSource();
}
}
});
Object.defineProperty(Potree.PointCloudMaterial.prototype, "near", {
get: function(){
return this.uniforms.near.value;
},
set: function(value){
if(this.uniforms.near.value !== value){
this.uniforms.near.value = value;
//this.updateShaderSource();
}
}
});
Object.defineProperty(Potree.PointCloudMaterial.prototype, "far", {
get: function(){
return this.uniforms.far.value;
},
set: function(value){
if(this.uniforms.far.value !== value){
this.uniforms.far.value = value;
//this.updateShaderSource();
}
}
});
Object.defineProperty(Potree.PointCloudMaterial.prototype, "opacity", {
get: function(){
return this.uniforms.opacity.value;
@ -1096,8 +1188,8 @@ Potree.PointCloudMaterial.generateGradient = function() {
}
Potree.PointCloudMaterial.vs_points = [
"precision highp float; ",
"precision highp int; ",
"precision mediump float; ",
"precision mediump int; ",
" ",
"attribute vec3 position; ",
"attribute vec3 color; ",
@ -1113,6 +1205,13 @@ Potree.PointCloudMaterial.vs_points = [
"uniform mat4 viewMatrix; ",
"uniform mat3 normalMatrix; ",
"uniform vec3 cameraPosition; ",
"uniform float screenWidth; ",
"uniform float screenHeight; ",
"uniform float fov; ",
"uniform float spacing; ",
"uniform float near; ",
"uniform float far; ",
" ",
" ",
"uniform float heightMin; ",
"uniform float heightMax; ",
@ -1269,18 +1368,23 @@ Potree.PointCloudMaterial.vs_points = [
" // ",
" // POINT SIZE TYPES ",
" // ",
" float r = spacing * 1.5; ",
" #if defined fixed_point_size ",
" gl_PointSize = size; ",
" #elif defined attenuated_point_size ",
" gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); ",
" //gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); ",
" gl_PointSize = (1.0 / tan(fov/2.0)) * size / (-mvPosition.z); ",
" gl_PointSize = gl_PointSize * screenHeight / 2.0; ",
" #elif defined adaptive_point_size ",
" gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); ",
" //gl_PointSize = size * ( 300.0 / length( mvPosition.xyz ) ); ",
" //gl_PointSize = (1.0 / tan(fov/2.0)) * r / sqrt( max(0.0, mvPosition.z * mvPosition.z - r * r)); ",
" gl_PointSize = (1.0 / tan(fov/2.0)) * r / (-mvPosition.z); ",
" gl_PointSize = size * gl_PointSize * screenHeight / 2.0; ",
" gl_PointSize = gl_PointSize / pow(1.9, getOctreeDepth()); ",
" #endif ",
" ",
" ",
" gl_PointSize = max(minSize, gl_PointSize); ",
" gl_PointSize = min(30.0, gl_PointSize); ",
" ",
" gl_PointSize = min(50.0, gl_PointSize); ",
" ",
"} "];
@ -1890,7 +1994,7 @@ Potree.PointCloudOctree = function(geometry, material){
Potree.PointCloudOctree.prototype = Object.create(THREE.Object3D.prototype);
Potree.PointCloudOctree.prototype.update = function(camera){
Potree.PointCloudOctree.prototype.update = function(camera, renderer){
this.updateMatrixWorld(true);
this.visibleGeometry = this.getVisibleGeometry(camera);
@ -1910,6 +2014,13 @@ Potree.PointCloudOctree.prototype.update = function(camera){
this.numVisibleNodes = 0;
this.numVisiblePoints = 0;
this.material.fov = camera.fov * (Math.PI / 180);
this.material.screenWidth = renderer.domElement.clientWidth;
this.material.screenHeight = renderer.domElement.clientHeight;
this.material.spacing = pointcloud.pcoGeometry.spacing;
this.material.near = camera.near;
this.material.far = camera.far;
this.hideDescendants(this.children[0]);
var stack = [];
@ -1921,6 +2032,8 @@ Potree.PointCloudOctree.prototype.update = function(camera){
node.visible = true;
node.matrixWorld.multiplyMatrices( node.parent.matrixWorld, node.matrix );
if (node instanceof Potree.PointCloudOctreeProxyNode) {
var geometryNode = node.geometryNode;
if(geometryNode.loaded === true){
@ -2978,10 +3091,10 @@ Potree.Version.prototype.newerThan = function(version){
Potree.MeasuringTool = function(scene, camera, renderer){
var scope = this;
this.enabled = false;
this.scene = scene;
this.camera = camera;
this.renderer = renderer;
this.domElement = renderer.domElement;
this.mouse = {x: 0, y: 0};
@ -2994,12 +3107,119 @@ Potree.MeasuringTool = function(scene, camera, renderer){
var state = STATE.DEFAULT;
var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10);
this.activeMeasurement;
this.measurements = [];
this.sceneMeasurement = new THREE.Scene();
this.sceneRoot = new THREE.Object3D();
this.sceneMeasurement.add(this.sceneRoot);
this.light = new THREE.DirectionalLight( 0xffffff, 1 );
this.light.position.set( 0, 0, 10 );
this.light.lookAt(new THREE.Vector3(0,0,0));
this.sceneMeasurement.add( this.light );
this.hoveredElement = null;
var moveEvent = function(event){
event.target.material.emissive.setHex(0x888888);
};
var leaveEvent = function(event){
event.target.material.emissive.setHex(0x000000);
};
var dragEvent = function(event){
var I = getMousePointCloudIntersection();
if(I){
for(var i = 0; i < scope.measurements.length; i++){
var m = scope.measurements[i];
var index = m.spheres.indexOf(scope.dragstart.object);
if(index >= 0){
var sphere = m.spheres[index];
if(index === 0){
var edge = m.edges[index];
var edgeLabel = m.edgeLabels[index];
sphere.position.copy(I);
edge.geometry.vertices[0].copy(I);
edge.geometry.verticesNeedUpdate = true;
edge.geometry.computeBoundingSphere();
var edgeLabelPos = edge.geometry.vertices[0].clone().add(edge.geometry.vertices[1]).multiplyScalar(0.5);
var edgeLabelText = edge.geometry.vertices[0].distanceTo(edge.geometry.vertices[1]).toFixed(2);
edgeLabel.position.copy(edgeLabelPos);
edgeLabel.setText(edgeLabelText);
edgeLabel.scale.multiplyScalar(10);
}else if(index === m.spheres.length - 1){
var edge = m.edges[index - 1];
var edgeLabel = m.edgeLabels[index - 1];
sphere.position.copy(I);
edge.geometry.vertices[1].copy(I);
edge.geometry.verticesNeedUpdate = true;
edge.geometry.computeBoundingSphere();
var edgeLabelPos = edge.geometry.vertices[0].clone().add(edge.geometry.vertices[1]).multiplyScalar(0.5);
var edgeLabelText = edge.geometry.vertices[0].distanceTo(edge.geometry.vertices[1]).toFixed(2);
edgeLabel.position.copy(edgeLabelPos);
edgeLabel.setText(edgeLabelText);
edgeLabel.scale.multiplyScalar(10);
}else{
var edge1 = m.edges[index-1];
var edge2 = m.edges[index];
var edge1Label = m.edgeLabels[index-1];
var edge2Label = m.edgeLabels[index];
sphere.position.copy(I);
edge1.geometry.vertices[1].copy(I);
edge1.geometry.verticesNeedUpdate = true;
edge1.geometry.computeBoundingSphere();
edge2.geometry.vertices[0].copy(I);
edge2.geometry.verticesNeedUpdate = true;
edge2.geometry.computeBoundingSphere();
var edge1LabelPos = edge1.geometry.vertices[0].clone().add(edge1.geometry.vertices[1]).multiplyScalar(0.5);
var edge1LabelText = edge1.geometry.vertices[0].distanceTo(edge1.geometry.vertices[1]).toFixed(2);
edge1Label.position.copy(edge1LabelPos);
edge1Label.setText(edge1LabelText);
edge1Label.scale.multiplyScalar(10);
var edge2LabelPos = edge2.geometry.vertices[0].clone().add(edge2.geometry.vertices[1]).multiplyScalar(0.5);
var edge2LabelText = edge2.geometry.vertices[0].distanceTo(edge2.geometry.vertices[1]).toFixed(2);
edge2Label.position.copy(edge2LabelPos);
edge2Label.setText(edge2LabelText);
edge2Label.scale.multiplyScalar(10);
}
break;
}
}
//scope.dragstart.object.position.copy(I);
}
event.event.stopImmediatePropagation();
};
var dropEvent = function(event){
};
function Measure(){
this.points = [];
this.spheres = [];
@ -3007,23 +3227,45 @@ Potree.MeasuringTool = function(scene, camera, renderer){
this.sphereLabels = [];
this.edgeLabels = [];
}
function createSphereMaterial(){
var sphereMaterial = new THREE.MeshLambertMaterial({
shading: THREE.SmoothShading,
color: 0xff0000,
ambient: 0xaaaaaa,
depthTest: false,
depthWrite: false}
);
return sphereMaterial;
};
function onDoubleClick(event){
function onClick(event){
if(!scope.enabled){
return;
}
var I = getMousePointCloudIntersection();
if(I){
var pos = I.clone();
var sphereMaterial = new THREE.MeshNormalMaterial({shading: THREE.SmoothShading, depthTest: false, depthWrite: false})
var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10);
var sphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial());
sphere.position.copy(I);
scope.sceneRoot.add(sphere);
sphere.addEventListener("mousemove", moveEvent);
sphere.addEventListener("mouseleave", leaveEvent);
sphere.addEventListener("mousedrag", dragEvent);
sphere.addEventListener("drop", dropEvent);
var sphereEnd = new THREE.Mesh(sphereGeometry, sphereMaterial);
var sphereEnd = new THREE.Mesh(sphereGeometry, createSphereMaterial());
sphereEnd.position.copy(I);
scope.sceneRoot.add(sphereEnd);
sphereEnd.addEventListener("mousemove", moveEvent);
sphereEnd.addEventListener("mouseleave", leaveEvent);
sphereEnd.addEventListener("mousedrag", dragEvent);
sphereEnd.addEventListener("drop", dropEvent);
var msg = pos.x.toFixed(2) + " / " + pos.y.toFixed(2) + " / " + pos.z.toFixed(2);
@ -3103,35 +3345,67 @@ Potree.MeasuringTool = function(scene, camera, renderer){
scope.mouse.x = ( event.clientX / scope.domElement.clientWidth ) * 2 - 1;
scope.mouse.y = - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1;
if(state == STATE.PICKING && scope.activeMeasurement){
if(scope.dragstart){
scope.dragstart.object.dispatchEvent({type: "mousedrag", event: event});
}else if(state == STATE.PICKING && scope.activeMeasurement){
var I = getMousePointCloudIntersection();
if(I){
var pos = I.clone();
var l = scope.activeMeasurement.spheres.length;
var sphere = scope.activeMeasurement.spheres[l-1];
var label = scope.activeMeasurement.sphereLabels[l-1];
var edge = scope.activeMeasurement.edges[l-2];
var edgeLabel = scope.activeMeasurement.edgeLabels[l-2];
var msg = pos.x.toFixed(2) + " / " + pos.y.toFixed(2) + " / " + pos.z.toFixed(2);
label.setText(msg);
sphere.position.copy(I);
label.position.copy(I);
label.position.y += 0.5;
edge.geometry.vertices[1].copy(I);
edge.geometry.verticesNeedUpdate = true;
edge.geometry.computeBoundingSphere();
var edgeLabelPos = edge.geometry.vertices[1].clone().add(edge.geometry.vertices[0]).multiplyScalar(0.5);
var edgeLabelText = edge.geometry.vertices[0].distanceTo(edge.geometry.vertices[1]).toFixed(2);
edgeLabel.position.copy(edgeLabelPos);
edgeLabel.setText(edgeLabelText);
edgeLabel.scale.multiplyScalar(10);
if(scope.activeMeasurement.spheres.length === 1){
var pos = I.clone();
var sphere = scope.activeMeasurement.spheres[0];
sphere.position.copy(I);
}else{
var pos = I.clone();
var l = scope.activeMeasurement.spheres.length;
var sphere = scope.activeMeasurement.spheres[l-1];
var label = scope.activeMeasurement.sphereLabels[l-1];
var edge = scope.activeMeasurement.edges[l-2];
var edgeLabel = scope.activeMeasurement.edgeLabels[l-2];
var msg = pos.x.toFixed(2) + " / " + pos.y.toFixed(2) + " / " + pos.z.toFixed(2);
label.setText(msg);
sphere.position.copy(I);
label.position.copy(I);
label.position.y += 0.5;
edge.geometry.vertices[1].copy(I);
edge.geometry.verticesNeedUpdate = true;
edge.geometry.computeBoundingSphere();
var edgeLabelPos = edge.geometry.vertices[1].clone().add(edge.geometry.vertices[0]).multiplyScalar(0.5);
var edgeLabelText = edge.geometry.vertices[0].distanceTo(edge.geometry.vertices[1]).toFixed(2);
edgeLabel.position.copy(edgeLabelPos);
edgeLabel.setText(edgeLabelText);
edgeLabel.scale.multiplyScalar(10);
}
}
}else{
var I = getHoveredElement();
if(I){
I.object.dispatchEvent({type: "mousemove", target: I.object, event: event});
if(scope.hoveredElement && scope.hoveredElement !== I.object){
scope.hoveredElement.dispatchEvent({type: "mouseleave", target: scope.hoveredElement, event: event});
}
scope.hoveredElement = I.object;
}else{
if(scope.hoveredElement){
scope.hoveredElement.dispatchEvent({type: "mouseleave", target: scope.hoveredElement, event: event});
}
scope.hoveredElement = null;
}
}
};
@ -3151,15 +3425,65 @@ Potree.MeasuringTool = function(scene, camera, renderer){
scope.activeMeasurement = undefined;
state = STATE.DEFAULT;
scope.setEnabled(false);
}
}
function onMouseDown(event){
if(event.which === 3){
if(event.which === 1){
var I = getHoveredElement();
if(I){
scope.dragstart = {
object: I.object,
sceneClickPos: I.point,
sceneStartPos: scope.sceneRoot.position.clone(),
mousePos: {x: scope.mouse.x, y: scope.mouse.y}
};
}
}else if(event.which === 3){
onRightClick(event);
}
}
function onMouseUp(event){
if(scope.dragstart){
scope.dragstart.object.dispatchEvent({type: "drop", event: event});
scope.dragstart = null;
}
}
function getHoveredElement(){
var vector = new THREE.Vector3( scope.mouse.x, scope.mouse.y, 0.5 );
vector.unproject(scope.camera);
var raycaster = new THREE.Raycaster();
raycaster.ray.set( scope.camera.position, vector.sub( scope.camera.position ).normalize() );
var spheres = [];
for(var i = 0; i < scope.measurements.length; i++){
var m = scope.measurements[i];
for(var j = 0; j < m.spheres.length; j++){
spheres.push(m.spheres[j]);
}
}
var intersections = raycaster.intersectObjects(spheres, true);
if(intersections.length > 0){
return intersections[0];
}else{
return false;
}
};
function getMousePointCloudIntersection(){
var vector = new THREE.Vector3( scope.mouse.x, scope.mouse.y, 0.5 );
vector.unproject(scope.camera);
@ -3194,12 +3518,34 @@ Potree.MeasuringTool = function(scene, camera, renderer){
}
return closestPoint ? closestPoint.position : null;
}
this.domElement.addEventListener("dblclick", onDoubleClick, false);
this.domElement.addEventListener( 'mousemove', onMouseMove, false );
this.domElement.addEventListener( 'mousedown', onMouseDown, false );
}
this.setEnabled = function(enable){
if(this.enabled === enable){
return;
}
this.enabled = enable;
if(enable){
state = STATE.PICKING;
scope.activeMeasurement = new Measure();
var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial());
scope.sceneRoot.add(sphere);
scope.activeMeasurement.spheres.push(sphere);
sphere.addEventListener("mousemove", moveEvent);
sphere.addEventListener("mouseleave", leaveEvent);
sphere.addEventListener("mousedrag", dragEvent);
sphere.addEventListener("drop", dropEvent);
}else{
//this.domElement.removeEventListener( 'click', onClick, false);
//this.domElement.removeEventListener( 'mousemove', onMouseMove, false );
//this.domElement.removeEventListener( 'mousedown', onMouseDown, false );
}
};
this.update = function(){
var measurements = [];
@ -3217,7 +3563,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){
var sphere = measurement.spheres[j];
var wp = sphere.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse);
var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
var w = (wp.z / 80); // * (2 - pp.z / pp.w);
var w = Math.abs((wp.z / 60)); // * (2 - pp.z / pp.w);
sphere.scale.set(w, w, w);
}
@ -3229,17 +3575,27 @@ Potree.MeasuringTool = function(scene, camera, renderer){
label.scale.multiplyScalar(w / l);
}
}
this.light.position.copy(this.camera.position);
this.light.lookAt(this.camera.getWorldDirection().add(this.camera.position));
};
this.render = function(){
this.update();
renderer.render(this.sceneMeasurement, this.camera);
};
this.domElement.addEventListener( 'click', onClick, false);
this.domElement.addEventListener( 'mousemove', onMouseMove, false );
this.domElement.addEventListener( 'mousedown', onMouseDown, false );
this.domElement.addEventListener( 'mouseup', onMouseUp, true );
};
Potree.MeasuringTool.prototype = Object.create( THREE.EventDispatcher.prototype );
Potree.ProfileTool = function(width, height, depth){
THREE.Object3D.call( this );

File diff suppressed because one or more lines are too long