From e9dd10d4eca1e7eabc24aa842b2be404fc9ea3dd Mon Sep 17 00:00:00 2001 From: m-schuetz Date: Thu, 18 Sep 2014 08:32:08 +0100 Subject: [PATCH] added FloatingOrigin to preserve precision in huge worlds --- examples/georef_test.html | 236 ++++++++++++++++++++++++++++++++++++++ src/FloatingOrigin.js | 30 +++++ src/PointCloudOctree.js | 2 +- src/utils/LabelHelper.js | 81 +++++++++++++ 4 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 examples/georef_test.html create mode 100644 src/FloatingOrigin.js create mode 100644 src/utils/LabelHelper.js diff --git a/examples/georef_test.html b/examples/georef_test.html new file mode 100644 index 00000000..0b90c5ff --- /dev/null +++ b/examples/georef_test.html @@ -0,0 +1,236 @@ + + + + + Lion + + + + + + + + + + + + + + + + + +
+
+
+
+ +
+ potree.org
+
+ + + + + \ No newline at end of file diff --git a/src/FloatingOrigin.js b/src/FloatingOrigin.js new file mode 100644 index 00000000..e059a516 --- /dev/null +++ b/src/FloatingOrigin.js @@ -0,0 +1,30 @@ + + +function FloatingOrigin(camera){ + this.camera = camera; + this.offset = new THREE.Vector3(); + this.referenceFrames = []; + this.threshold = 1000; + +} + +FloatingOrigin.prototype.addReferenceFrame = function(frame){ + this.referenceFrames.push(frame); +} + +FloatingOrigin.prototype.update = function(){ + var offset = new THREE.Vector3(); + if(this.camera.position.length() > this.threshold){ + offset.copy(camera.position); + } + + camera.position.sub(offset); + this.offset.add(offset); + + for(var i = 0; i < this.referenceFrames.length; i++){ + var frame = this.referenceFrames[i]; + frame.position.sub(offset); + } +} + + diff --git a/src/PointCloudOctree.js b/src/PointCloudOctree.js index 69f52e2b..7c156a95 100644 --- a/src/PointCloudOctree.js +++ b/src/PointCloudOctree.js @@ -84,7 +84,7 @@ Potree.PointCloudOctree.prototype.update = function(camera){ var visible = true; visible = visible && frustum.intersectsBox(box); - if(object.level > 1){ + if(object.level > 0){ // cull detail nodes based in distance to camera visible = visible && Math.pow(radius, 0.8) / distance > (1 / this.LOD); visible = visible && (this.numVisiblePoints + object.numPoints < Potree.pointLoadLimit); diff --git a/src/utils/LabelHelper.js b/src/utils/LabelHelper.js new file mode 100644 index 00000000..6135aff6 --- /dev/null +++ b/src/utils/LabelHelper.js @@ -0,0 +1,81 @@ +/** + * adapted from http://stemkoski.github.io/Three.js/Sprite-Text-Labels.html + */ + + +Potree.LabelHelper = function(){ + +} + +Potree.LabelHelper.createTextSprite = function(message, parameters){ + if ( parameters === undefined ) parameters = {}; + + var fontface = parameters.hasOwnProperty("fontface") ? + parameters["fontface"] : "Arial"; + + var fontsize = parameters.hasOwnProperty("fontsize") ? + parameters["fontsize"] : 18; + + var borderThickness = parameters.hasOwnProperty("borderThickness") ? + parameters["borderThickness"] : 4; + + var borderColor = parameters.hasOwnProperty("borderColor") ? + parameters["borderColor"] : { r:0, g:0, b:0, a:1.0 }; + + var backgroundColor = parameters.hasOwnProperty("backgroundColor") ? + parameters["backgroundColor"] : { r:255, g:255, b:255, a:1.0 }; + + var canvas = document.createElement('canvas'); + var context = canvas.getContext('2d'); + context.font = "Bold " + fontsize + "px " + fontface; + + // get size data (height depends only on font size) + var metrics = context.measureText( message ); + var textWidth = metrics.width; + + // background color + context.fillStyle = "rgba(" + backgroundColor.r + "," + backgroundColor.g + "," + + backgroundColor.b + "," + backgroundColor.a + ")"; + // border color + context.strokeStyle = "rgba(" + borderColor.r + "," + borderColor.g + "," + + borderColor.b + "," + borderColor.a + ")"; + + context.lineWidth = borderThickness; + Potree.LabelHelper.roundRect(context, borderThickness/2, borderThickness/2, textWidth + borderThickness, fontsize * 1.4 + borderThickness, 6); + // 1.4 is extra height factor for text below baseline: g,j,p,q. + + // text color + context.fillStyle = "rgba(0, 0, 0, 1.0)"; + + context.fillText( message, borderThickness, fontsize + borderThickness); + + // canvas contents will be used for a texture + var texture = new THREE.Texture(canvas) + texture.needsUpdate = true; + var spriteMaterial = new THREE.SpriteMaterial( + { map: texture, useScreenCoordinates: false } ); + var sprite = new THREE.Sprite( spriteMaterial ); + sprite.position.set(0,0,0); + sprite.scale.set(8,4,1.0); + return sprite; +} + + + + +// function for drawing rounded rectangles +Potree.LabelHelper.roundRect = function(ctx, x, y, w, h, r) { + ctx.beginPath(); + ctx.moveTo(x+r, y); + ctx.lineTo(x+w-r, y); + ctx.quadraticCurveTo(x+w, y, x+w, y+r); + ctx.lineTo(x+w, y+h-r); + ctx.quadraticCurveTo(x+w, y+h, x+w-r, y+h); + ctx.lineTo(x+r, y+h); + ctx.quadraticCurveTo(x, y+h, x, y+h-r); + ctx.lineTo(x, y+r); + ctx.quadraticCurveTo(x, y, x+r, y); + ctx.closePath(); + ctx.fill(); + ctx.stroke(); +} \ No newline at end of file