commit
699706cbaf
@ -26,6 +26,10 @@ For more details, read the [Getting Started Section](./docs/getting_started.md)
|
||||
## Convert Your Own Pointclouds
|
||||
Use the [PotreeConverter](https://github.com/potree/PotreeConverter) to convert your own point clouds into the potree format.
|
||||
|
||||
## Changelog
|
||||
Take a look at the changelog to get an overview of new features and possible changes to the usage:
|
||||
[docs/changelog.md](./docs/changelog.md)
|
||||
|
||||
## Compatibility
|
||||
|
||||
| Browser | OS | Result |
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
build/js/laslaz.min.js
vendored
2
build/js/laslaz.min.js
vendored
File diff suppressed because one or more lines are too long
1059
build/js/potree.js
1059
build/js/potree.js
File diff suppressed because it is too large
Load Diff
6
build/js/potree.min.js
vendored
6
build/js/potree.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
50
docs/changelog.md
Normal file
50
docs/changelog.md
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
|
||||
## 2014.12.17
|
||||
|
||||
### features
|
||||
* Added Area and Volume measurement tools.
|
||||
* Made tool markers draggable.
|
||||
* See examples/viewer.js for a demo of all measurement tools. In this demo, the volume can be translated, scaled and rotated by pressing e, r and t.
|
||||
* Attenuated point sizes are differently scaled. Now, the point size specifies the radius of the point in scene coordinates.
|
||||
* Adaptive point sizes are differently scaled. A size of 1 means that the point size is choosen to optimaly cover holes. Due to this it is now necessary to pass the renderer to the pointcloud.update() function:
|
||||
|
||||
```
|
||||
pointcloud.update(camera, renderer);
|
||||
```
|
||||
|
||||
|
||||
|
||||
### bugfixes
|
||||
* LAS and LAZ format now support point picking, too.
|
||||
* Using mediump precision instead of highp. Highp is not supported on all devices and it seems like it's generaly adviced not to use it.
|
||||
|
||||
|
||||
## 2014.12.03
|
||||
|
||||
* Made measurement tool independant of scale. Spheres and Labels are displayed at the same size regardless of the distance to the camera.
|
||||
MeasurementTool now has to be rendered using
|
||||
```
|
||||
// render scene first, then measuring tool over the scene
|
||||
renderer.render(scene, camera);
|
||||
measuringTool.render();
|
||||
```
|
||||
|
||||
* Support for binary files with .bin extension. Files without extension have shown to cause problems with FTP Uploaders and some WebServers.
|
||||
* Added classification, return number and point source ID to Potree.PointColorType. These color modes only work with LAS and LAZ files.
|
||||
* Replaced synchronous requests in favour of async requests.
|
||||
You must now provide a callback method in order to add a pointcloud to the scene:
|
||||
|
||||
```
|
||||
var pco = POCLoader.load(pointcloudPath, function(geometry){
|
||||
pointcloud = new Potree.PointCloudOctree(geometry);
|
||||
...
|
||||
scene.add(pointcloud);
|
||||
});
|
||||
```
|
||||
You must also make sure that the pointcloud has been loaded before operating on it:
|
||||
```
|
||||
if(pointcloud){
|
||||
// now you can safely use the pointcloud object
|
||||
}
|
||||
```
|
||||
@ -159,7 +159,7 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
|
||||
|
||||
<div id="renderArea"></div>
|
||||
<script type="text/javascript">
|
||||
var pointSize = 20;
|
||||
var pointSize = 1;
|
||||
var pointCountTarget = 1;
|
||||
var opacity = 1;
|
||||
var pointSizeType = Potree.PointSizeType.ADAPTIVE;
|
||||
@ -576,7 +576,7 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
|
||||
pointcloud.material.heightMin = 710;
|
||||
pointcloud.material.heightMax = 770;
|
||||
|
||||
pointcloud.update(camera);
|
||||
pointcloud.update(camera, renderer);
|
||||
updateMapFrustum();
|
||||
updateCoordinatePicking();
|
||||
updateProfile();
|
||||
@ -772,10 +772,11 @@ The updateMapExtent() shows how this can be used to visualize the boundaries in
|
||||
renderer.render(skybox.scene, skybox.camera);
|
||||
}
|
||||
|
||||
|
||||
// render scenes
|
||||
profileTool.render(renderer, scene);
|
||||
renderer.render(scene, camera);
|
||||
renderer.render(measuringTool.sceneMeasurement, camera);
|
||||
measuringTool.render();
|
||||
renderer.render(sceneHUD, cameraHUD);
|
||||
|
||||
}
|
||||
|
||||
@ -7,6 +7,12 @@ function ProgressBar(){
|
||||
this.maxOpacity = 0.6;
|
||||
|
||||
this.element = document.createElement("div");
|
||||
this.elProgress = document.createElement("div");
|
||||
this.elProgressMessage = document.createElement("div");
|
||||
|
||||
//this.element.innerHTML = "element";
|
||||
//this.elProgress.innerHTML = "progress";
|
||||
|
||||
this.element.innerHTML = "";
|
||||
this.element.style.position = "fixed";
|
||||
this.element.style.bottom = "20px";
|
||||
@ -17,12 +23,29 @@ function ProgressBar(){
|
||||
this.element.style.border = "1px solid #727678";
|
||||
this.element.style.height = "16px";
|
||||
this.element.style.padding = "1px";
|
||||
// this.element.style.backgroundColor = "white";
|
||||
this.element.style.backgroundImage = "-webkit-linear-gradient(right, #f2f6f8 0%,#d8e1e7 50%,#b5c6d0 51%,#e0eff9 100%)";
|
||||
this.element.style.textAlign = "center";
|
||||
this.element.style.backgroundColor = "#6ba8e5";
|
||||
this.element.style.opacity = this.maxOpacity;
|
||||
|
||||
this.elProgress.innerHTML = " ";
|
||||
this.elProgress.style.backgroundColor = "#b8e1fc";
|
||||
this.elProgress.style.position = "absolute";
|
||||
this.elProgress.style.borderRadius = "5px";
|
||||
this.elProgress.style.width = "0%";
|
||||
this.elProgress.style.height = "100%";
|
||||
this.elProgress.style.margin = "0px";
|
||||
this.elProgress.style.padding = "0px";
|
||||
|
||||
this.elProgressMessage.style.position = "absolute";
|
||||
this.elProgressMessage.style.width = "100%";
|
||||
this.elProgressMessage.innerHTML = "loading 1 / 10";
|
||||
|
||||
|
||||
|
||||
document.body.appendChild(this.element);
|
||||
this.element.appendChild(this.elProgress);
|
||||
this.element.appendChild(this.elProgressMessage);
|
||||
|
||||
};
|
||||
|
||||
ProgressBar.prototype.hide = function(){
|
||||
@ -41,7 +64,7 @@ Object.defineProperty(ProgressBar.prototype, "progress", {
|
||||
},
|
||||
set: function(value){
|
||||
this._progress = value;
|
||||
this.element.style.backgroundImage = "-webkit-linear-gradient(left, #f2f6f8 0%,#d8e1e7 " + (value * 100) + "%,#b5c6d0 " + (value * 100 + 1) + "%,#e0eff9 100%)";
|
||||
this.elProgress.style.width = (value * 100) + "%";
|
||||
}
|
||||
});
|
||||
|
||||
@ -51,6 +74,6 @@ Object.defineProperty(ProgressBar.prototype, "message", {
|
||||
},
|
||||
set: function(message){
|
||||
this._message = message;
|
||||
this.element.innerHTML = message;
|
||||
this.elProgressMessage.innerHTML = message;
|
||||
}
|
||||
});
|
||||
@ -48,7 +48,7 @@
|
||||
<div id="renderArea"></div>
|
||||
|
||||
<script>
|
||||
var pointSize = 0.5;
|
||||
var pointSize = 1;
|
||||
var pointCountTarget = 0.4;
|
||||
var opacity = 1;
|
||||
var pointSizeType = Potree.PointSizeType.ADAPTIVE;
|
||||
@ -219,7 +219,7 @@
|
||||
pointcloud.material.heightMin = 0;
|
||||
pointcloud.material.heightMax = 8;
|
||||
|
||||
pointcloud.update(camera);
|
||||
pointcloud.update(camera, renderer);
|
||||
|
||||
document.getElementById("lblNumVisibleNodes").innerHTML = "visible nodes: " + pointcloud.numVisibleNodes;
|
||||
document.getElementById("lblNumVisiblePoints").innerHTML = "visible points: " + Potree.utils.addCommas(pointcloud.numVisiblePoints);
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
<div id="renderArea"></div>
|
||||
|
||||
<script>
|
||||
var pointSize = 0.5;
|
||||
var pointSize = 1;
|
||||
var pointCountTarget = 0.4;
|
||||
var opacity = 1;
|
||||
var pointSizeType = Potree.PointSizeType.ADAPTIVE;
|
||||
@ -228,7 +228,7 @@
|
||||
pointcloud.material.intensityMin = 0;
|
||||
pointcloud.material.intensityMax = 65000;
|
||||
|
||||
pointcloud.update(camera);
|
||||
pointcloud.update(camera, renderer);
|
||||
|
||||
document.getElementById("lblNumVisibleNodes").innerHTML = "visible nodes: " + pointcloud.numVisibleNodes;
|
||||
document.getElementById("lblNumVisiblePoints").innerHTML = "visible points: " + Potree.utils.addCommas(pointcloud.numVisiblePoints);
|
||||
|
||||
@ -51,7 +51,7 @@
|
||||
<div id="renderArea"></div>
|
||||
|
||||
<script>
|
||||
var pointSize = 0.5;
|
||||
var pointSize = 1;
|
||||
var pointCountTarget = 0.4;
|
||||
var opacity = 1;
|
||||
var pointSizeType = Potree.PointSizeType.ADAPTIVE;
|
||||
@ -228,7 +228,7 @@
|
||||
pointcloud.material.intensityMin = 0;
|
||||
pointcloud.material.intensityMax = 65000;
|
||||
|
||||
pointcloud.update(camera);
|
||||
pointcloud.update(camera, renderer);
|
||||
|
||||
document.getElementById("lblNumVisibleNodes").innerHTML = "visible nodes: " + pointcloud.numVisibleNodes;
|
||||
document.getElementById("lblNumVisiblePoints").innerHTML = "visible points: " + Potree.utils.addCommas(pointcloud.numVisiblePoints);
|
||||
|
||||
379
examples/viewer.html
Normal file
379
examples/viewer.html
Normal file
@ -0,0 +1,379 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<title>Lion</title>
|
||||
<style>canvas { width: 100%; height: 100% }</style>
|
||||
</head>
|
||||
<body style="margin: 0; padding: 0">
|
||||
|
||||
<style type="text/css">
|
||||
|
||||
#renderArea{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.info{
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
text-shadow: 1px 1px 1px black,
|
||||
1px -1px 1px black,
|
||||
-1px 1px 1px black,
|
||||
-1px -1px 1px black;
|
||||
}
|
||||
|
||||
a:hover, a:visited, a:link, a:active{
|
||||
color: #ccccff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script src="../libs/plasio/js/laslaz.js"></script>
|
||||
<script src="../libs/plasio/vendor/bluebird.js"></script>
|
||||
<script src="../libs/three.js/build/three.js"></script>
|
||||
<script src="../libs/other/OrbitControls.js"></script>
|
||||
<script src="../libs/other/stats.min.js"></script>
|
||||
<script src="../libs/other/dat.gui.min.js"></script>
|
||||
|
||||
<script src="../build/js/potree.js"></script>
|
||||
<script src="../build/js/laslaz.js"></script>
|
||||
<script src="../examples/js/ProgressBar.js"></script>
|
||||
<script src="../src/PointCloudOctree.js"></script>
|
||||
<script src="../src/utils/MeasuringTool.js"></script>
|
||||
<script src="../src/utils/AreaTool.js"></script>
|
||||
<script src="../src/utils/VolumeTool.js"></script>
|
||||
<script src="../src/utils/TransformationTool.js"></script>
|
||||
<script src="../src/materials/PointCloudMaterial.js"></script>
|
||||
<script src="viewer.js"></script>
|
||||
|
||||
<div id="lblNumVisibleNodes" class="info" style="position: absolute; left: 10px; top: 80px; width: 400px; color:white"></div>
|
||||
<div id="lblNumVisiblePoints" class="info" style="position: absolute; left: 10px; top: 100px; width: 400px; color:white"></div>
|
||||
<div id="lblMessage" class="info" style="position: absolute; left: 10px; bottom: 0px; width: 400px; color:white"></div>
|
||||
|
||||
<div id="tools" style="position: fixed; width: 200px; bottom: 10px; right: 10px">
|
||||
<input type="button" value="distance" onclick="measuringTool.setEnabled(true)"/>
|
||||
<input type="button" value="area" onclick="areaTool.setEnabled(true)"/>
|
||||
<input type="button" value="volume" onclick="volumeTool.startInsertion()"/>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="test" style="border: 1px solid red; position: fixed; pointer-events: none">
|
||||
|
||||
</div>
|
||||
|
||||
<div id="test1" style="border: 1px solid red; position: fixed; pointer-events: none;">
|
||||
|
||||
</div>
|
||||
|
||||
<div id="test2" style="border: 1px solid red; position: fixed; pointer-events: none;">
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="info" style="position: absolute; left: 300px; right: 300px; top: 10px; text-align: center;">
|
||||
<a href="http://potree.org" target="_blank">potree.org</a><br>
|
||||
Point cloud courtesy of <a href="http://www.sigeom.ch/" target="_blank">sigeom sa</a><br>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="renderArea"></div>
|
||||
|
||||
<script>
|
||||
var pointSize = 1.0 ;
|
||||
var pointCountTarget = 1;
|
||||
var opacity = 1;
|
||||
var pointSizeType = Potree.PointSizeType.ADAPTIVE;
|
||||
var pointColorType = Potree.PointColorType.RGB;
|
||||
var pointShape = Potree.PointShape.SQUARE;
|
||||
var interpolate = false;
|
||||
|
||||
var progressBar = new ProgressBar();
|
||||
|
||||
var pointcloudPath = "../resources/pointclouds/vol_total/cloud.js";
|
||||
|
||||
var elRenderArea = document.getElementById("renderArea");
|
||||
|
||||
var renderer;
|
||||
var camera;
|
||||
var scene;
|
||||
var pointcloud;
|
||||
var skybox;
|
||||
var stats;
|
||||
var clock = new THREE.Clock();
|
||||
var showSkybox = false;
|
||||
var measuringTool;
|
||||
var areaTool;
|
||||
var volumeTool;
|
||||
var transformationTool;
|
||||
var referenceFrame;
|
||||
|
||||
function initGUI(){
|
||||
|
||||
// dat.gui
|
||||
var gui = new dat.GUI({
|
||||
height : 5 * 32 - 1
|
||||
});
|
||||
|
||||
var params = {
|
||||
"points(m)": pointCountTarget,
|
||||
PointSize: pointSize,
|
||||
"opacity": opacity,
|
||||
"SizeType" : "Adaptive",
|
||||
"show octree" : false,
|
||||
"Materials" : "RGB",
|
||||
"interpolate": interpolate,
|
||||
"circles": false,
|
||||
"skybox": false
|
||||
};
|
||||
|
||||
var pPoints = gui.add(params, 'points(m)', 0.02, 2);
|
||||
pPoints.onChange(function(value){
|
||||
pointCountTarget = value ;
|
||||
});
|
||||
|
||||
var pPointSize = gui.add(params, 'PointSize', 0, 3);
|
||||
pPointSize.onChange(function(value){
|
||||
pointSize = value;
|
||||
});
|
||||
|
||||
var pOpacity = gui.add(params, 'opacity', 0, 1);
|
||||
pOpacity.onChange(function(value){
|
||||
opacity = value;
|
||||
});
|
||||
|
||||
var pSizeType = gui.add(params, 'SizeType', [ "Fixed", "Attenuated", "Adaptive"]);
|
||||
pSizeType.onChange(function(value){
|
||||
if(value === "Fixed"){
|
||||
pointSizeType = Potree.PointSizeType.FIXED;
|
||||
}else if(value === "Attenuated"){
|
||||
pointSizeType = Potree.PointSizeType.ATTENUATED;
|
||||
}else if(value === "Adaptive"){
|
||||
pointSizeType = Potree.PointSizeType.ADAPTIVE;
|
||||
}
|
||||
});
|
||||
|
||||
var pMaterial = gui.add(params, 'Materials', [ "RGB", "Color", "Height", "Octree Depth"]);
|
||||
pMaterial.onChange(function(value){
|
||||
if(value === "RGB"){
|
||||
pointColorType = Potree.PointColorType.RGB;
|
||||
}else if(value === "Color"){
|
||||
pointColorType = Potree.PointColorType.COLOR;
|
||||
}else if(value === "Height"){
|
||||
pointColorType = Potree.PointColorType.HEIGHT;
|
||||
|
||||
}else if(value === "Octree Depth"){
|
||||
pointColorType = Potree.PointColorType.OCTREE_DEPTH;
|
||||
}else if(value === "Point Index"){
|
||||
pointColorType = Potree.PointColorType.POINT_INDEX;
|
||||
}
|
||||
});
|
||||
|
||||
if(renderer.context.getExtension("EXT_frag_depth")){
|
||||
var pInterpolate = gui.add(params, 'interpolate');
|
||||
pInterpolate.onChange(function(value){
|
||||
interpolate = value;
|
||||
});
|
||||
}
|
||||
|
||||
var pCircular = gui.add(params, 'circles');
|
||||
pCircular.onChange(function(value){
|
||||
if(value){
|
||||
pointShape = Potree.PointShape.CIRCLE;
|
||||
}else{
|
||||
pointShape = Potree.PointShape.SQUARE;
|
||||
}
|
||||
});
|
||||
|
||||
var pSykbox = gui.add(params, 'skybox');
|
||||
pSykbox.onChange(function(value){
|
||||
showSkybox = value;
|
||||
});
|
||||
|
||||
// stats
|
||||
stats = new Stats();
|
||||
stats.domElement.style.position = 'absolute';
|
||||
stats.domElement.style.top = '0px';
|
||||
stats.domElement.style.margin = '5px';
|
||||
document.body.appendChild( stats.domElement );
|
||||
}
|
||||
|
||||
function initThree(){
|
||||
var fov = 75;
|
||||
var width = elRenderArea.clientWidth;
|
||||
var height = elRenderArea.clientHeight;
|
||||
var aspect = width / height;
|
||||
var near = 0.1;
|
||||
var far = 1000000;
|
||||
|
||||
scene = new THREE.Scene();
|
||||
camera = new THREE.PerspectiveCamera(fov, aspect, near, far);
|
||||
|
||||
referenceFrame = new THREE.Object3D();
|
||||
scene.add(referenceFrame);
|
||||
|
||||
renderer = new THREE.WebGLRenderer();
|
||||
renderer.setSize(width, height);
|
||||
renderer.autoClear = false;
|
||||
elRenderArea.appendChild(renderer.domElement);
|
||||
|
||||
skybox = Potree.utils.loadSkybox("../resources/textures/skybox/");
|
||||
|
||||
// camera and controls
|
||||
camera.position.set(-304, 372, 318);
|
||||
camera.rotation.y = -Math.PI / 4;
|
||||
camera.rotation.x = -Math.PI / 6;
|
||||
controls = new THREE.FirstPersonControls(camera, renderer.domElement);
|
||||
controls.moveSpeed *= 10;
|
||||
|
||||
// enable frag_depth extension for the interpolation shader, if available
|
||||
renderer.context.getExtension("EXT_frag_depth");
|
||||
|
||||
// load pointcloud
|
||||
POCLoader.load(pointcloudPath, function(geometry){
|
||||
pointcloud = new Potree.PointCloudOctree(geometry);
|
||||
|
||||
pointcloud.material.pointSizeType = Potree.PointSizeType.ADAPTIVE;
|
||||
pointcloud.material.size = pointSize;
|
||||
pointcloud.visiblePointsTarget = pointCountTarget * 1000 * 1000;
|
||||
|
||||
//pointcloud.rotation.set(Math.PI/2, 0.85* -Math.PI/2, -0.0);
|
||||
|
||||
referenceFrame.add(pointcloud);
|
||||
|
||||
referenceFrame.applyMatrix(new THREE.Matrix4().set(
|
||||
1,0,0,0,
|
||||
0,0,1,0,
|
||||
0,-1,0,0,
|
||||
0,0,0,1
|
||||
));
|
||||
|
||||
referenceFrame.updateMatrixWorld(true);
|
||||
var sg = pointcloud.boundingSphere.clone().applyMatrix4(pointcloud.matrixWorld);
|
||||
|
||||
referenceFrame.position.copy(sg.center).multiplyScalar(-1);
|
||||
referenceFrame.position.y += sg.radius;
|
||||
|
||||
referenceFrame.updateMatrixWorld(true);
|
||||
|
||||
//zoomTo(camera, pointcloud, 0.7);
|
||||
});
|
||||
|
||||
var grid = Potree.utils.createGrid(5, 5, 2);
|
||||
scene.add(grid);
|
||||
|
||||
measuringTool = new Potree.MeasuringTool(scene, camera, renderer);
|
||||
areaTool = new Potree.AreaTool(scene, camera, renderer);
|
||||
volumeTool = new Potree.VolumeTool(scene, camera, renderer);
|
||||
transformationTool = new Potree.TransformationTool(scene, camera, renderer);
|
||||
|
||||
|
||||
|
||||
window.addEventListener( 'keydown', onKeyDown, false );
|
||||
}
|
||||
|
||||
function onKeyDown(event){
|
||||
//console.log(event.keyCode);
|
||||
|
||||
if(event.keyCode === 69){
|
||||
// e pressed
|
||||
|
||||
transformationTool.translate();
|
||||
}else if(event.keyCode === 82){
|
||||
// r pressed
|
||||
|
||||
transformationTool.scale();
|
||||
}else if(event.keyCode === 84){
|
||||
// r pressed
|
||||
|
||||
transformationTool.rotate();
|
||||
}
|
||||
};
|
||||
|
||||
function update(){
|
||||
if(pointcloud){
|
||||
pointcloud.material.size = pointSize;
|
||||
pointcloud.visiblePointsTarget = pointCountTarget * 1000 * 1000;
|
||||
pointcloud.material.opacity = opacity;
|
||||
pointcloud.material.pointSizeType = pointSizeType;
|
||||
pointcloud.material.pointColorType = pointColorType;
|
||||
pointcloud.material.pointShape = pointShape;
|
||||
pointcloud.material.interpolate = interpolate;
|
||||
pointcloud.material.heightMin = 0;
|
||||
pointcloud.material.heightMax = 8;
|
||||
|
||||
pointcloud.update(camera, renderer);
|
||||
|
||||
document.getElementById("lblNumVisibleNodes").innerHTML = "visible nodes: " + pointcloud.numVisibleNodes;
|
||||
document.getElementById("lblNumVisiblePoints").innerHTML = "visible points: " + Potree.utils.addCommas(pointcloud.numVisiblePoints);
|
||||
}
|
||||
|
||||
stats.update();
|
||||
|
||||
controls.update(clock.getDelta());
|
||||
|
||||
// update progress bar
|
||||
if(pointcloud){
|
||||
var progress = pointcloud.visibleNodes.length / pointcloud.visibleGeometry.length;
|
||||
|
||||
progressBar.progress = progress;
|
||||
progressBar.message = "loading: " + pointcloud.visibleNodes.length + " / " + pointcloud.visibleGeometry.length;
|
||||
|
||||
if(progress === 1){
|
||||
progressBar.hide();
|
||||
}else if(progress < 1){
|
||||
progressBar.show();
|
||||
}
|
||||
}else{
|
||||
progressBar.show();
|
||||
progressBar.message = "loading metadata";
|
||||
}
|
||||
|
||||
volumeTool.update();
|
||||
transformationTool.update();
|
||||
}
|
||||
|
||||
function render(){
|
||||
// resize
|
||||
var width = elRenderArea.clientWidth;
|
||||
var height = elRenderArea.clientHeight;
|
||||
var aspect = width / height;
|
||||
|
||||
camera.aspect = aspect;
|
||||
camera.updateProjectionMatrix();
|
||||
|
||||
renderer.setSize(width, height);
|
||||
|
||||
|
||||
// render skybox
|
||||
if(showSkybox){
|
||||
skybox.camera.rotation.copy(camera.rotation);
|
||||
renderer.render(skybox.scene, skybox.camera);
|
||||
}
|
||||
|
||||
// render scene
|
||||
renderer.render(scene, camera);
|
||||
|
||||
renderer.clearDepth();
|
||||
measuringTool.render();
|
||||
areaTool.render();
|
||||
transformationTool.render();
|
||||
}
|
||||
|
||||
function loop() {
|
||||
requestAnimationFrame(loop);
|
||||
|
||||
update();
|
||||
render();
|
||||
};
|
||||
|
||||
|
||||
|
||||
initThree();
|
||||
initGUI();
|
||||
loop();
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
46
examples/viewer.js
Normal file
46
examples/viewer.js
Normal file
@ -0,0 +1,46 @@
|
||||
zoomTo = function( camera, node, factor ){
|
||||
|
||||
if ( !node.geometry && !node.boundingSphere ) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( node.geometry && node.geometry.boundingSphere === null ) {
|
||||
|
||||
node.geometry.computeBoundingSphere();
|
||||
|
||||
}
|
||||
|
||||
var boundingSphere = node.boundingSphere || node.geometry.boundingSphere;
|
||||
|
||||
if ( !boundingSphere ) {
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
node.updateMatrixWorld();
|
||||
|
||||
boundingSphere = boundingSphere.clone().applyMatrix4(node.matrixWorld);
|
||||
|
||||
var _factor = factor || 1;
|
||||
|
||||
var radius = boundingSphere.radius;
|
||||
var center = boundingSphere.center;
|
||||
var fovr = camera.fov * Math.PI / 180;
|
||||
|
||||
if( camera.aspect < 1 ){
|
||||
|
||||
fovr = fovr * camera.aspect;
|
||||
|
||||
}
|
||||
|
||||
var distanceFactor = Math.abs( radius / Math.sin( fovr / 2 ) ) * _factor ;
|
||||
|
||||
var dir = new THREE.Vector3( 0, 0, -1 ).applyQuaternion( camera.quaternion );
|
||||
var offset = dir.multiplyScalar( -distanceFactor );
|
||||
camera.position.copy(center.add( offset ));
|
||||
|
||||
};
|
||||
@ -20,6 +20,7 @@ var paths = {
|
||||
"src/extensions/Ray.js",
|
||||
"src/loader/POCLoader.js",
|
||||
"src/loader/PointAttributes.js",
|
||||
"src/loader/BinaryLoader.js",
|
||||
"src/loader/LasLazLoader.js",
|
||||
"src/materials/PointCloudMaterial.js",
|
||||
"src/FirstPersonControls.js",
|
||||
@ -28,6 +29,7 @@ var paths = {
|
||||
"src/PointCloudOctreeGeometry.js",
|
||||
"src/utils.js",
|
||||
"src/TextSprite.js",
|
||||
"src/Version.js",
|
||||
"src/utils/MeasuringTool.js",
|
||||
"src/utils/ProfileTool.js",
|
||||
"src/utils/TranslationTool.js"
|
||||
|
||||
@ -154,6 +154,7 @@ THREE.FirstPersonControls = function ( object, domElement ) {
|
||||
};
|
||||
|
||||
this.update = function (delta) {
|
||||
this.object.rotation.order = 'ZYX';
|
||||
var position = this.object.position;
|
||||
|
||||
if(delta !== undefined){
|
||||
@ -181,6 +182,15 @@ THREE.FirstPersonControls = function ( object, domElement ) {
|
||||
|
||||
position.add(pan);
|
||||
|
||||
if(!(thetaDelta === 0.0 && phiDelta === 0.0)) {
|
||||
var event = {
|
||||
type: 'rotate',
|
||||
thetaDelta: thetaDelta,
|
||||
phiDelta: phiDelta
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
|
||||
this.object.updateMatrix();
|
||||
var rot = new THREE.Matrix4().makeRotationY(thetaDelta);
|
||||
var res = new THREE.Matrix4().multiplyMatrices(rot, this.object.matrix);
|
||||
@ -272,14 +282,9 @@ THREE.FirstPersonControls = function ( object, domElement ) {
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var delta = 0;
|
||||
if ( event.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
|
||||
delta = event.wheelDelta;
|
||||
} else if ( event.detail !== undefined ) { // Firefox
|
||||
delta = - event.detail;
|
||||
}
|
||||
var direction = (event.detail<0 || event.wheelDelta>0) ? 1 : -1;
|
||||
scope.moveSpeed += scope.moveSpeed * 0.1 * direction;
|
||||
|
||||
scope.moveSpeed += scope.moveSpeed * 0.001 * delta;
|
||||
scope.moveSpeed = Math.max(0.1, scope.moveSpeed);
|
||||
|
||||
scope.dispatchEvent( startEvent );
|
||||
|
||||
@ -88,7 +88,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);
|
||||
@ -108,6 +108,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 = [];
|
||||
@ -119,6 +126,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){
|
||||
|
||||
@ -32,7 +32,7 @@ Potree.PointCloudOctreeGeometryNode.prototype.addChild = function(child){
|
||||
}
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
|
||||
if(this.loading === true || this.pcoGeometry.numNodesLoading > 5){
|
||||
if(this.loading === true || this.pcoGeometry.numNodesLoading > 1){
|
||||
return;
|
||||
}else{
|
||||
this.loading = true;
|
||||
@ -44,144 +44,8 @@ Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
|
||||
|
||||
|
||||
this.pcoGeometry.numNodesLoading++;
|
||||
var pointAttributes = this.pcoGeometry.pointAttributes;
|
||||
if(pointAttributes === "LAS" || pointAttributes === "LAZ"){
|
||||
// load las or laz node files
|
||||
|
||||
var url = this.pcoGeometry.octreeDir + "/" + this.name + "." + pointAttributes.toLowerCase();
|
||||
nodesLoadTimes[url] = {};
|
||||
nodesLoadTimes[url].start = new Date().getTime();
|
||||
LasLazLoader.load(url, new Potree.LasLazBatcher(this, url));
|
||||
} else if ( pointAttributes === "POT"){
|
||||
|
||||
var callback = function(node, buffer){
|
||||
var dv = new DataView(buffer, 0, 4);
|
||||
var headerSize = dv.getUint32(0, true);
|
||||
var pointOffset = 4 + headerSize;
|
||||
|
||||
var headerBuffer = buffer.slice(4, 4 + headerSize);
|
||||
var header = String.fromCharCode.apply(null, new Uint8Array(headerBuffer));
|
||||
header = JSON.parse(header);
|
||||
console.log(header);
|
||||
|
||||
var pScale = header.attributes[0].scale;
|
||||
var pOffset = header.attributes[0].offset;
|
||||
var pEncoding = header.attributes[0].encoding;
|
||||
|
||||
var scale = new THREE.Vector3(pScale[0], pScale[1], pScale[2]);
|
||||
var offset = new THREE.Vector3(pOffset[0], pOffset[1], pOffset[2]);
|
||||
var min = pEncoding.min;
|
||||
var max = pEncoding.max;
|
||||
var bits = pEncoding.bits;
|
||||
|
||||
var pointBuffer = buffer.slice(pointOffset, pointOffset + buffer.byteLength - pointOffset);
|
||||
var br = new BitReader(pointBuffer);
|
||||
|
||||
var X = br.read(32);
|
||||
var Y = br.read(32);
|
||||
var Z = br.read(32);
|
||||
|
||||
var r = br.read(8);
|
||||
var g = br.read(8);
|
||||
var b = br.read(8);
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var numPoints = header.pointcount;
|
||||
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Float32Array(numPoints*3);
|
||||
var color = new THREE.Color();
|
||||
|
||||
for(var i = 0; i < header.pointcount - 1; i++){
|
||||
|
||||
dx = br.read(bits[0]) + min[0];
|
||||
dy = br.read(bits[1]) + min[1];
|
||||
dz = br.read(bits[2]) + min[2];
|
||||
|
||||
X = X + dx;
|
||||
Y = Y + dy;
|
||||
Z = Z + dz;
|
||||
|
||||
x = X * scale.x + offset.x;
|
||||
y = Y * scale.y + offset.y;
|
||||
z = Z * scale.z + offset.z;
|
||||
|
||||
r = br.read(8);
|
||||
g = br.read(8);
|
||||
b = br.read(8);
|
||||
|
||||
positions[3*i+0] = x;// + node.pcoGeometry.offset.x;
|
||||
positions[3*i+1] = y;// + node.pcoGeometry.offset.y;
|
||||
positions[3*i+2] = z;// + node.pcoGeometry.offset.z;
|
||||
|
||||
colors[3*i+0] = r / 255;
|
||||
colors[3*i+1] = g / 255;
|
||||
colors[3*i+2] = b / 255;
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
|
||||
geometry.boundingBox = node.boundingBox;
|
||||
node.geometry = geometry;
|
||||
node.loaded = true;
|
||||
node.loading = false;
|
||||
node.pcoGeometry.numNodesLoading--;
|
||||
|
||||
};
|
||||
|
||||
Potree.BinaryNodeLoader.load(this, "pot", callback);
|
||||
|
||||
} else {
|
||||
// load binary node files
|
||||
|
||||
var url = this.pcoGeometry.octreeDir + "/" + this.name;
|
||||
nodesLoadTimes[url] = {};
|
||||
nodesLoadTimes[url].start = new Date().getTime();
|
||||
var callback = function(node, buffer){
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var numPoints = buffer.byteLength / 16;
|
||||
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Float32Array(numPoints*3);
|
||||
var indices = new ArrayBuffer(numPoints*4);
|
||||
var color = new THREE.Color();
|
||||
|
||||
var fView = new Float32Array(buffer);
|
||||
var uiView = new Uint8Array(buffer);
|
||||
|
||||
var iIndices = new Uint32Array(indices);
|
||||
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
positions[3*i+0] = fView[4*i+0] + node.pcoGeometry.offset.x;
|
||||
positions[3*i+1] = fView[4*i+1] + node.pcoGeometry.offset.y;
|
||||
positions[3*i+2] = fView[4*i+2] + node.pcoGeometry.offset.z;
|
||||
|
||||
color.setRGB(uiView[16*i+12], uiView[16*i+13], uiView[16*i+14]);
|
||||
colors[3*i+0] = color.r / 255;
|
||||
colors[3*i+1] = color.g / 255;
|
||||
colors[3*i+2] = color.b / 255;
|
||||
|
||||
iIndices[i] = i;
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
|
||||
geometry.addAttribute('indices', new THREE.BufferAttribute(indices, 1));
|
||||
geometry.boundingBox = node.boundingBox;
|
||||
node.geometry = geometry;
|
||||
node.loaded = true;
|
||||
node.loading = false;
|
||||
node.pcoGeometry.numNodesLoading--;
|
||||
|
||||
nodesLoadTimes[url].end = new Date().getTime();
|
||||
|
||||
var time = nodesLoadTimes[url].end - nodesLoadTimes[url].start;
|
||||
};
|
||||
|
||||
nodesLoadTimes[url] = {};
|
||||
nodesLoadTimes[url].start = new Date().getTime();
|
||||
Potree.BinaryNodeLoader.load(this, "", callback);
|
||||
}
|
||||
|
||||
this.pcoGeometry.loader.load(this);
|
||||
}
|
||||
|
||||
Potree.BinaryNodeLoader = function(){
|
||||
@ -215,75 +79,6 @@ Potree.BinaryNodeLoader.load = function(node, extension, callback){
|
||||
}
|
||||
|
||||
|
||||
Potree.LasLazBatcher = function(node, url){
|
||||
this.push = function(lasBuffer){
|
||||
var ww = Potree.workers.lasdecoder.getWorker();
|
||||
var mins = new THREE.Vector3(lasBuffer.mins[0], lasBuffer.mins[1], lasBuffer.mins[2]);
|
||||
var maxs = new THREE.Vector3(lasBuffer.maxs[0], lasBuffer.maxs[1], lasBuffer.maxs[2]);
|
||||
mins.add(node.pcoGeometry.offset);
|
||||
maxs.add(node.pcoGeometry.offset);
|
||||
|
||||
ww.onmessage = function(e){
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var numPoints = lasBuffer.pointsCount;
|
||||
|
||||
var endsWith = function(str, suffix) {
|
||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||
}
|
||||
|
||||
var positions = e.data.position;
|
||||
var colors = e.data.color;
|
||||
var intensities = e.data.intensity;
|
||||
var classifications = new Uint8Array(e.data.classification);
|
||||
var classifications_f = new Float32Array(classifications.byteLength);
|
||||
|
||||
var box = new THREE.Box3();
|
||||
|
||||
var fPositions = new Float32Array(positions);
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
//fPositions[3*i+0] += node.pcoGeometry.offset.x;
|
||||
//fPositions[3*i+1] += node.pcoGeometry.offset.y;
|
||||
//fPositions[3*i+2] += node.pcoGeometry.offset.z;
|
||||
|
||||
classifications_f[i] = classifications[i];
|
||||
|
||||
box.expandByPoint(new THREE.Vector3(fPositions[3*i+0], fPositions[3*i+1], fPositions[3*i+2]));
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(colors), 3));
|
||||
geometry.addAttribute('intensity', new THREE.BufferAttribute(new Float32Array(intensities), 1));
|
||||
geometry.addAttribute('classification', new THREE.BufferAttribute(new Float32Array(classifications_f), 1));
|
||||
//geometry.boundingBox = node.boundingBox;
|
||||
geometry.boundingBox = new THREE.Box3(mins, maxs);
|
||||
node.boundingBox = geometry.boundingBox;
|
||||
|
||||
node.geometry = geometry;
|
||||
node.loaded = true;
|
||||
node.loading = false;
|
||||
node.pcoGeometry.numNodesLoading--;
|
||||
|
||||
nodesLoadTimes[url].end = new Date().getTime();
|
||||
|
||||
var time = nodesLoadTimes[url].end - nodesLoadTimes[url].start;
|
||||
Potree.workers.lasdecoder.returnWorker(ww);
|
||||
};
|
||||
|
||||
var message = {
|
||||
buffer: lasBuffer.arrayb,
|
||||
numPoints: lasBuffer.pointsCount,
|
||||
pointSize: lasBuffer.pointSize,
|
||||
pointFormatID: 2,
|
||||
scale: lasBuffer.scale,
|
||||
offset: lasBuffer.offset,
|
||||
mins: [node.pcoGeometry.boundingBox.min.x, node.pcoGeometry.boundingBox.min.y, node.pcoGeometry.boundingBox.min.z],
|
||||
maxs: [node.pcoGeometry.boundingBox.max.x, node.pcoGeometry.boundingBox.max.y, node.pcoGeometry.boundingBox.max.z],
|
||||
bbOffset: [node.pcoGeometry.offset.x, node.pcoGeometry.offset.y, node.pcoGeometry.offset.z]
|
||||
};
|
||||
ww.postMessage(message, [message.buffer]);
|
||||
}
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.dispose = function(){
|
||||
delete this.geometry;
|
||||
this.loaded = false;
|
||||
|
||||
23
src/Version.js
Normal file
23
src/Version.js
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
Potree.Version = function(version){
|
||||
this.version = version;
|
||||
var vmLength = (version.indexOf(".") === -1) ? version.length : version.indexOf(".");
|
||||
this.versionMajor = version.substr(0, vmLength);
|
||||
this.versionMinor = version.substr(vmLength + 1);
|
||||
if(this.versionMinor.length === 0){
|
||||
this.versionMinor = 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.Version.prototype.newerThan = function(version){
|
||||
var v = new Potree.Version(version);
|
||||
|
||||
if( this.versionMajor > v.versionMajor){
|
||||
return true;
|
||||
}else if( this.versionMajor === v.versionMajor && this.versionMinor > v.versionMinor){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
86
src/loader/BinaryLoader.js
Normal file
86
src/loader/BinaryLoader.js
Normal file
@ -0,0 +1,86 @@
|
||||
|
||||
Potree.BinaryLoader = function(version){
|
||||
if(typeof(version) === "string"){
|
||||
this.version = new Potree.Version(version);
|
||||
}else{
|
||||
this.version = version;
|
||||
}
|
||||
};
|
||||
|
||||
Potree.BinaryLoader.prototype.newerVersion = function(version){
|
||||
|
||||
};
|
||||
|
||||
Potree.BinaryLoader.prototype.load = function(node){
|
||||
|
||||
if(node.loaded){
|
||||
return;
|
||||
}
|
||||
|
||||
var url = node.pcoGeometry.octreeDir + "/" + node.name;
|
||||
if(this.version.newerThan("1.3")){
|
||||
url += ".bin";
|
||||
}
|
||||
|
||||
var scope = this;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
var buffer = xhr.response;
|
||||
scope.parse(node, buffer);
|
||||
} else {
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
|
||||
}
|
||||
}
|
||||
};
|
||||
try{
|
||||
xhr.send(null);
|
||||
}catch(e){
|
||||
console.log("fehler beim laden der punktwolke: " + e);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.BinaryLoader.prototype.parse = function(node, buffer){
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var numPoints = buffer.byteLength / 16;
|
||||
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Float32Array(numPoints*3);
|
||||
var indices = new ArrayBuffer(numPoints*4);
|
||||
var color = new THREE.Color();
|
||||
|
||||
var fView = new Float32Array(buffer);
|
||||
var uiView = new Uint8Array(buffer);
|
||||
|
||||
var iIndices = new Uint32Array(indices);
|
||||
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
positions[3*i+0] = fView[4*i+0] + node.pcoGeometry.offset.x;
|
||||
positions[3*i+1] = fView[4*i+1] + node.pcoGeometry.offset.y;
|
||||
positions[3*i+2] = fView[4*i+2] + node.pcoGeometry.offset.z;
|
||||
|
||||
color.setRGB(uiView[16*i+12], uiView[16*i+13], uiView[16*i+14]);
|
||||
colors[3*i+0] = color.r / 255;
|
||||
colors[3*i+1] = color.g / 255;
|
||||
colors[3*i+2] = color.b / 255;
|
||||
|
||||
iIndices[i] = i;
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3));
|
||||
geometry.addAttribute('indices', new THREE.BufferAttribute(indices, 1));
|
||||
geometry.boundingBox = node.boundingBox;
|
||||
node.geometry = geometry;
|
||||
node.loaded = true;
|
||||
node.loading = false;
|
||||
node.pcoGeometry.numNodesLoading--;
|
||||
};
|
||||
|
||||
|
||||
@ -1,20 +1,45 @@
|
||||
|
||||
function LasLazLoader(){
|
||||
/**
|
||||
* laslaz code taken and adapted from plas.io js-laslaz
|
||||
* http://plas.io/
|
||||
* https://github.com/verma/plasio
|
||||
*
|
||||
* Thanks to Uday Verma and Howard Butler
|
||||
*
|
||||
*/
|
||||
|
||||
Potree.LasLazLoader = function(version){
|
||||
if(typeof(version) === "string"){
|
||||
this.version = new Potree.Version(version);
|
||||
}else{
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
LasLazLoader.load = function(file, handler){
|
||||
Potree.LasLazLoader.prototype.load = function(node){
|
||||
|
||||
if(node.loaded){
|
||||
return;
|
||||
}
|
||||
|
||||
//var url = node.pcoGeometry.octreeDir + "/" + node.name;
|
||||
var pointAttributes = node.pcoGeometry.pointAttributes;
|
||||
var url = node.pcoGeometry.octreeDir + "/" + node.name + "." + pointAttributes.toLowerCase()
|
||||
|
||||
var scope = this;
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', file, true);
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
var buffer = xhr.response;
|
||||
LasLazLoader.loadData(buffer, handler);
|
||||
//LasLazLoader.loadData(buffer, handler);
|
||||
scope.parse(node, buffer);
|
||||
} else {
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + file);
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -22,12 +47,13 @@ LasLazLoader.load = function(file, handler){
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
LasLazLoader.progressCB = function(arg){
|
||||
Potree.LasLazLoader.progressCB = function(arg){
|
||||
|
||||
};
|
||||
|
||||
LasLazLoader.loadData = function loadData(buffer, handler){
|
||||
Potree.LasLazLoader.prototype.parse = function loadData(node, buffer){
|
||||
var lf = new LASFile(buffer);
|
||||
var handler = new Potree.LasLazBatcher(node);
|
||||
|
||||
return Promise.resolve(lf).cancellable().then(function(lf) {
|
||||
return lf.open().then(function() {
|
||||
@ -64,7 +90,7 @@ LasLazLoader.loadData = function loadData(buffer, handler){
|
||||
header.mins, header.maxs));
|
||||
|
||||
totalRead += data.count;
|
||||
LasLazLoader.progressCB(totalRead / totalToRead);
|
||||
Potree.LasLazLoader.progressCB(totalRead / totalToRead);
|
||||
|
||||
if (data.hasMoreData)
|
||||
return reader();
|
||||
@ -83,7 +109,7 @@ LasLazLoader.loadData = function loadData(buffer, handler){
|
||||
var lf = v[0];
|
||||
// we're done loading this file
|
||||
//
|
||||
LasLazLoader.progressCB(1);
|
||||
Potree.LasLazLoader.progressCB(1);
|
||||
|
||||
// Close it
|
||||
return lf.close().then(function() {
|
||||
@ -106,4 +132,87 @@ LasLazLoader.loadData = function loadData(buffer, handler){
|
||||
});
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Potree.LasLazLoader.prototype.handle = function(node, url){
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Potree.LasLazBatcher = function(node){
|
||||
this.push = function(lasBuffer){
|
||||
var ww = Potree.workers.lasdecoder.getWorker();
|
||||
var mins = new THREE.Vector3(lasBuffer.mins[0], lasBuffer.mins[1], lasBuffer.mins[2]);
|
||||
var maxs = new THREE.Vector3(lasBuffer.maxs[0], lasBuffer.maxs[1], lasBuffer.maxs[2]);
|
||||
mins.add(node.pcoGeometry.offset);
|
||||
maxs.add(node.pcoGeometry.offset);
|
||||
|
||||
ww.onmessage = function(e){
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
var numPoints = lasBuffer.pointsCount;
|
||||
|
||||
var endsWith = function(str, suffix) {
|
||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||
}
|
||||
|
||||
var positions = e.data.position;
|
||||
var colors = e.data.color;
|
||||
var intensities = e.data.intensity;
|
||||
var classifications = new Uint8Array(e.data.classification);
|
||||
var classifications_f = new Float32Array(classifications.byteLength);
|
||||
var returnNumbers = new Uint8Array(e.data.returnNumber);
|
||||
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();
|
||||
|
||||
var fPositions = new Float32Array(positions);
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
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]));
|
||||
}
|
||||
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(positions), 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(new Float32Array(colors), 3));
|
||||
geometry.addAttribute('intensity', new THREE.BufferAttribute(new Float32Array(intensities), 1));
|
||||
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;
|
||||
|
||||
node.geometry = geometry;
|
||||
node.loaded = true;
|
||||
node.loading = false;
|
||||
node.pcoGeometry.numNodesLoading--;
|
||||
|
||||
Potree.workers.lasdecoder.returnWorker(ww);
|
||||
};
|
||||
|
||||
var message = {
|
||||
buffer: lasBuffer.arrayb,
|
||||
numPoints: lasBuffer.pointsCount,
|
||||
pointSize: lasBuffer.pointSize,
|
||||
pointFormatID: 2,
|
||||
scale: lasBuffer.scale,
|
||||
offset: lasBuffer.offset,
|
||||
mins: [node.pcoGeometry.boundingBox.min.x, node.pcoGeometry.boundingBox.min.y, node.pcoGeometry.boundingBox.min.z],
|
||||
maxs: [node.pcoGeometry.boundingBox.max.x, node.pcoGeometry.boundingBox.max.y, node.pcoGeometry.boundingBox.max.z],
|
||||
bbOffset: [node.pcoGeometry.offset.x, node.pcoGeometry.offset.y, node.pcoGeometry.offset.z]
|
||||
};
|
||||
ww.postMessage(message, [message.buffer]);
|
||||
}
|
||||
};
|
||||
@ -51,6 +51,13 @@ POCLoader.load = function load(url, callback) {
|
||||
pco.boundingBox = boundingBox;
|
||||
pco.boundingSphere = boundingBox.getBoundingSphere();
|
||||
pco.offset = offset;
|
||||
if(fMno.pointAttributes === "LAS"){
|
||||
pco.loader = new Potree.LasLazLoader(fMno.version);
|
||||
}else if(fMno.pointAttributes === "LAZ"){
|
||||
pco.loader = new Potree.LasLazLoader(fMno.version);
|
||||
}else{
|
||||
pco.loader = new Potree.BinaryLoader(fMno.version);
|
||||
}
|
||||
|
||||
var nodes = {};
|
||||
|
||||
|
||||
@ -1,4 +1,14 @@
|
||||
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
// 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,
|
||||
@ -18,7 +28,10 @@ Potree.PointColorType = {
|
||||
INTENSITY: 4,
|
||||
INTENSITY_GRADIENT: 5,
|
||||
OCTREE_DEPTH: 6,
|
||||
POINT_INDEX: 7
|
||||
POINT_INDEX: 7,
|
||||
CLASSIFICATION: 8,
|
||||
RETURN_NUMBER: 9,
|
||||
SOURCE: 10
|
||||
};
|
||||
|
||||
Potree.PointCloudMaterial = function(parameters){
|
||||
@ -43,18 +56,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},
|
||||
};
|
||||
|
||||
|
||||
@ -81,6 +100,12 @@ Potree.PointCloudMaterial.prototype.updateShaderSource = function(){
|
||||
if(this.pointColorType === Potree.PointColorType.INTENSITY
|
||||
|| this.pointColorType === Potree.PointColorType.INTENSITY_GRADIENT){
|
||||
attributes.intensity = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === Potree.PointColorType.CLASSIFICATION){
|
||||
attributes.classification = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === Potree.PointColorType.RETURN_NUMBER){
|
||||
attributes.returnNumber = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === Potree.PointColorType.SOURCE){
|
||||
attributes.pointSourceID = { type: "f", value: [] };
|
||||
}
|
||||
|
||||
this.setValues({
|
||||
@ -150,11 +175,89 @@ Potree.PointCloudMaterial.prototype.getDefines = function(){
|
||||
defines += "#define color_type_octree_depth\n";
|
||||
}else if(this._pointColorType === Potree.PointColorType.POINT_INDEX){
|
||||
defines += "#define color_type_point_index\n";
|
||||
}else if(this._pointColorType === Potree.PointColorType.CLASSIFICATION){
|
||||
defines += "#define color_type_classification\n";
|
||||
}else if(this._pointColorType === Potree.PointColorType.RETURN_NUMBER){
|
||||
defines += "#define color_type_return_number\n";
|
||||
}else if(this._pointColorType === Potree.PointColorType.SOURCE){
|
||||
defines += "#define color_type_source\n";
|
||||
}
|
||||
|
||||
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;
|
||||
@ -316,11 +419,12 @@ Potree.PointCloudMaterial.generateGradient = function() {
|
||||
// draw gradient
|
||||
context.rect( 0, 0, size, size );
|
||||
var gradient = context.createLinearGradient( 0, 0, size, size );
|
||||
gradient.addColorStop(0, 'blue');
|
||||
gradient.addColorStop(1/5, 'aqua');
|
||||
gradient.addColorStop(2/5, 'green')
|
||||
gradient.addColorStop(3/5, 'yellow');
|
||||
gradient.addColorStop(4/5, 'orange');
|
||||
gradient.addColorStop(0, "#4700b6");
|
||||
gradient.addColorStop(1/6, 'blue');
|
||||
gradient.addColorStop(2/6, 'aqua');
|
||||
gradient.addColorStop(3/6, 'green')
|
||||
gradient.addColorStop(4/6, 'yellow');
|
||||
gradient.addColorStop(5/6, 'orange');
|
||||
gradient.addColorStop(1, 'red');
|
||||
|
||||
|
||||
@ -335,12 +439,15 @@ 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; ",
|
||||
"attribute float intensity; ",
|
||||
"attribute float classification; ",
|
||||
"attribute float returnNumber; ",
|
||||
"attribute float pointSourceID; ",
|
||||
"attribute vec4 indices; ",
|
||||
" ",
|
||||
"uniform mat4 modelMatrix; ",
|
||||
@ -349,6 +456,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; ",
|
||||
@ -427,7 +541,37 @@ Potree.PointCloudMaterial.vs_points = [
|
||||
" ",
|
||||
"#endif ",
|
||||
" ",
|
||||
" ",
|
||||
"vec3 classificationColor(float classification){ ",
|
||||
" vec3 color = vec3(0.0, 0.0, 0.0); ",
|
||||
" float c = mod(classification, 16.0); ",
|
||||
" if(c == 0.0){ ",
|
||||
" color = vec3(0.5, 0.5, 0.5); ",
|
||||
" }else if(c == 1.0){ ",
|
||||
" color = vec3(0.5, 0.5, 0.5); ",
|
||||
" }else if(c == 2.0){ ",
|
||||
" color = vec3(0.63, 0.32, 0.18); ",
|
||||
" }else if(c == 3.0){ ",
|
||||
" color = vec3(0.0, 1.0, 0.0); ",
|
||||
" }else if(c == 4.0){ ",
|
||||
" color = vec3(0.0, 0.8, 0.0); ",
|
||||
" }else if(c == 5.0){ ",
|
||||
" color = vec3(0.0, 0.6, 0.0); ",
|
||||
" }else if(c == 6.0){ ",
|
||||
" color = vec3(1.0, 0.66, 0.0); ",
|
||||
" }else if(c == 7.0){ ",
|
||||
" color = vec3(1.0, 0, 1.0); ",
|
||||
" }else if(c == 8.0){ ",
|
||||
" color = vec3(1.0, 0, 0.0); ",
|
||||
" }else if(c == 9.0){ ",
|
||||
" color = vec3(0.0, 0.0, 1.0); ",
|
||||
" }else if(c == 12.0){ ",
|
||||
" color = vec3(1.0, 1.0, 0.0); ",
|
||||
" }else{ ",
|
||||
" color = vec3(0.3, 0.6, 0.6); ",
|
||||
" } ",
|
||||
" ",
|
||||
" return color; ",
|
||||
"} ",
|
||||
" ",
|
||||
"void main() { ",
|
||||
" ",
|
||||
@ -461,24 +605,37 @@ Potree.PointCloudMaterial.vs_points = [
|
||||
" vColor = texture2D(gradient, vec2(w,1.0-w)).rgb; ",
|
||||
" #elif defined color_type_point_index ",
|
||||
" vColor = indices.rgb; ",
|
||||
" #elif defined color_type_classification ",
|
||||
" vColor = classificationColor(classification); ",
|
||||
" #elif defined color_type_return_number ",
|
||||
" float w = (returnNumber - 1.0) / 4.0 + 0.1; ",
|
||||
" vColor = texture2D(gradient, vec2(w, 1.0 - w)).rgb; ",
|
||||
" #elif defined color_type_source ",
|
||||
" float w = mod(pointSourceID, 10.0) / 10.0; ",
|
||||
" vColor = texture2D(gradient, vec2(w,1.0 - w)).rgb; ",
|
||||
" #endif ",
|
||||
" ",
|
||||
" ",
|
||||
" // ",
|
||||
" // 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); ",
|
||||
" ",
|
||||
"} "];
|
||||
|
||||
@ -519,6 +676,5 @@ Potree.PointCloudMaterial.fs_points_rgb = [
|
||||
" gl_FragColor = vec4(vColor, opacity); ",
|
||||
" #endif ",
|
||||
" ",
|
||||
" ",
|
||||
"} "];
|
||||
|
||||
|
||||
518
src/utils/AreaTool.js
Normal file
518
src/utils/AreaTool.js
Normal file
@ -0,0 +1,518 @@
|
||||
|
||||
//
|
||||
// calculating area of a polygon:
|
||||
// http://www.mathopenref.com/coordpolygonarea2.html
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
Potree.AreaTool = 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};
|
||||
this.accuracy = 0.5;
|
||||
|
||||
var STATE = {
|
||||
DEFAULT: 0,
|
||||
PICKING: 1
|
||||
};
|
||||
|
||||
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){
|
||||
scope.measurements[i].setPosition(index, I);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//scope.dragstart.object.position.copy(I);
|
||||
}
|
||||
|
||||
event.event.stopImmediatePropagation();
|
||||
};
|
||||
|
||||
var dropEvent = function(event){
|
||||
|
||||
};
|
||||
|
||||
|
||||
function Measure(root){
|
||||
this.points = [];
|
||||
this.spheres = [];
|
||||
this.edges = [];
|
||||
this.sphereLabels = [];
|
||||
this.edgeLabels = [];
|
||||
this.root = root;
|
||||
this.closed = true;
|
||||
|
||||
this.areaLabel = new Potree.TextSprite();
|
||||
this.areaLabel.setBorderColor({r:0, g:255, b:0, a:0.0});
|
||||
this.areaLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0});
|
||||
this.areaLabel.material.depthTest = false;
|
||||
this.areaLabel.material.opacity = 1;
|
||||
root.add(this.areaLabel);
|
||||
|
||||
var sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10);
|
||||
var lineColor = new THREE.Color( 0xff0000 );
|
||||
|
||||
var createSphereMaterial = function(){
|
||||
var sphereMaterial = new THREE.MeshLambertMaterial({
|
||||
shading: THREE.SmoothShading,
|
||||
color: 0xff0000,
|
||||
ambient: 0xaaaaaa,
|
||||
depthTest: false,
|
||||
depthWrite: false}
|
||||
);
|
||||
|
||||
return sphereMaterial;
|
||||
};
|
||||
|
||||
this.add = function(point){
|
||||
|
||||
this.points.push(point);
|
||||
|
||||
// sphere
|
||||
var sphere = new THREE.Mesh(sphereGeometry, createSphereMaterial());
|
||||
sphere.addEventListener("mousemove", moveEvent);
|
||||
sphere.addEventListener("mouseleave", leaveEvent);
|
||||
sphere.addEventListener("mousedrag", dragEvent);
|
||||
sphere.addEventListener("drop", dropEvent);
|
||||
|
||||
// edge
|
||||
var lineGeometry = new THREE.Geometry();
|
||||
lineGeometry.vertices.push(new THREE.Vector3(), new THREE.Vector3());
|
||||
lineGeometry.colors.push(lineColor, lineColor, lineColor);
|
||||
var lineMaterial = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, linewidth: 2 } );
|
||||
lineMaterial.depthTest = false;
|
||||
var edge = new THREE.Line(lineGeometry, lineMaterial);
|
||||
|
||||
|
||||
// edgeLabel
|
||||
var edgeLabel = new Potree.TextSprite("abc");
|
||||
edgeLabel.setBorderColor({r:0, g:255, b:0, a:0.0});
|
||||
edgeLabel.setBackgroundColor({r:0, g:255, b:0, a:0.0});
|
||||
edgeLabel.material.depthTest = false;
|
||||
edgeLabel.material.opacity = 1;
|
||||
|
||||
|
||||
this.root.add(sphere);
|
||||
this.root.add(edge);
|
||||
this.root.add(edgeLabel);
|
||||
|
||||
this.spheres.push(sphere);
|
||||
this.edges.push(edge);
|
||||
this.edgeLabels.push(edgeLabel);
|
||||
|
||||
this.setPosition(this.points.length-1, point);
|
||||
};
|
||||
|
||||
this.remove = function(index){
|
||||
this.points.splice(index, 1);
|
||||
|
||||
this.root.remove(this.spheres[index]);
|
||||
this.root.remove(this.edges[index]);
|
||||
this.root.remove(this.edgeLabels[index]);
|
||||
|
||||
this.spheres.splice(index, 1);
|
||||
this.edges.splice(index, 1);
|
||||
this.edgeLabels.splice(index, 1);
|
||||
|
||||
this.update();
|
||||
};
|
||||
|
||||
/**
|
||||
* see http://www.mathopenref.com/coordpolygonarea2.html
|
||||
*/
|
||||
this.getArea = function(){
|
||||
var area = 0;
|
||||
var j = this.points.length - 1;
|
||||
|
||||
for(var i = 0; i < this.points.length; i++){
|
||||
var p1 = this.points[i];
|
||||
var p2 = this.points[j];
|
||||
area += (p2.x + p1.x) * (p1.z - p2.z);
|
||||
j = i;
|
||||
}
|
||||
|
||||
return Math.abs(area / 2);
|
||||
};
|
||||
|
||||
this.setPosition = function(index, position){
|
||||
var point = this.points[index];
|
||||
point.copy(position);
|
||||
|
||||
this.update();
|
||||
};
|
||||
|
||||
this.setClosed = function(closed){
|
||||
this.closed = closed;
|
||||
|
||||
this.update();
|
||||
};
|
||||
|
||||
this.update = function(){
|
||||
this.areaLabel.visible = this.points.length >= 3;
|
||||
|
||||
if(this.points.length === 1){
|
||||
var point = this.points[0];
|
||||
this.spheres[0].position.copy(point);
|
||||
this.edges[0].visible = false;
|
||||
this.edgeLabels[0].visible = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var centroid = new THREE.Vector3();
|
||||
var lastIndex = this.points.length - 1;
|
||||
for(var i = 0; i <= lastIndex; i++){
|
||||
var point = this.points[i];
|
||||
var sphere = this.spheres[i];
|
||||
var leftIndex = (i === 0) ? lastIndex : i - 1;
|
||||
var rightIndex = (i === lastIndex) ? 0 : i + 1;
|
||||
var leftVertex = this.points[leftIndex];
|
||||
var rightVertex = this.points[rightIndex];
|
||||
var leftEdge = this.edges[leftIndex];
|
||||
var rightEdge = this.edges[i];
|
||||
var leftEdgeLabel = this.edgeLabels[leftIndex];
|
||||
var rightEdgeLabel = this.edgeLabels[i];
|
||||
|
||||
var leftEdgeLength = point.distanceTo(leftVertex);
|
||||
var rightEdgeLength = point.distanceTo(rightVertex);
|
||||
var leftEdgeCenter = new THREE.Vector3().addVectors(leftVertex, point).multiplyScalar(0.5);
|
||||
var rightEdgeCenter = new THREE.Vector3().addVectors(point, rightVertex).multiplyScalar(0.5);
|
||||
|
||||
leftEdgeLabel.position.copy(leftEdgeCenter);
|
||||
rightEdgeLabel.position.copy(rightEdgeCenter);
|
||||
leftEdgeLabel.setText(leftEdgeLength.toFixed(2));
|
||||
rightEdgeLabel.setText(rightEdgeLength.toFixed(2));
|
||||
|
||||
sphere.position.copy(point);
|
||||
leftEdge.geometry.vertices[1].copy(point);
|
||||
leftEdge.geometry.verticesNeedUpdate = true;
|
||||
leftEdge.geometry.computeBoundingSphere();
|
||||
rightEdge.geometry.vertices[0].copy(point);
|
||||
rightEdge.geometry.verticesNeedUpdate = true;
|
||||
rightEdge.geometry.computeBoundingSphere();
|
||||
|
||||
if(i === lastIndex && !this.closed){
|
||||
rightEdge.visible = false;
|
||||
rightEdgeLabel.visible = false;
|
||||
}else{
|
||||
rightEdge.visible = true;
|
||||
rightEdgeLabel.visible = true;
|
||||
}
|
||||
|
||||
centroid.add(point);
|
||||
}
|
||||
centroid.multiplyScalar(1 / this.points.length);
|
||||
|
||||
|
||||
var msg = Potree.utils.addCommas(this.getArea().toFixed(1)) + "²";
|
||||
this.areaLabel.setText(msg);
|
||||
this.areaLabel.position.copy(centroid);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
function createSphereMaterial(){
|
||||
var sphereMaterial = new THREE.MeshLambertMaterial({
|
||||
shading: THREE.SmoothShading,
|
||||
color: 0xff0000,
|
||||
ambient: 0xaaaaaa,
|
||||
depthTest: false,
|
||||
depthWrite: false}
|
||||
);
|
||||
|
||||
return sphereMaterial;
|
||||
};
|
||||
|
||||
|
||||
function onClick(event){
|
||||
|
||||
if(!scope.enabled){
|
||||
return;
|
||||
}
|
||||
|
||||
var I = getMousePointCloudIntersection();
|
||||
if(I){
|
||||
var pos = I.clone();
|
||||
|
||||
if(state === STATE.DEFAULT){
|
||||
state = STATE.PICKING;
|
||||
scope.activeMeasurement = new Measure();
|
||||
}
|
||||
|
||||
scope.activeMeasurement.add(pos);
|
||||
|
||||
var event = {
|
||||
type: 'newpoint',
|
||||
position: pos.clone()
|
||||
};
|
||||
scope.dispatchEvent(event);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
function onMouseMove(event){
|
||||
scope.mouse.x = ( event.clientX / scope.domElement.clientWidth ) * 2 - 1;
|
||||
scope.mouse.y = - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1;
|
||||
|
||||
if(scope.dragstart){
|
||||
|
||||
scope.dragstart.object.dispatchEvent({type: "mousedrag", event: event});
|
||||
|
||||
}else if(state == STATE.PICKING && scope.activeMeasurement){
|
||||
var I = getMousePointCloudIntersection();
|
||||
|
||||
if(I){
|
||||
|
||||
var lastIndex = scope.activeMeasurement.points.length-1;
|
||||
scope.activeMeasurement.setPosition(lastIndex, I);
|
||||
}
|
||||
|
||||
}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;
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function onRightClick(event){
|
||||
if(state == STATE.PICKING){
|
||||
scope.activeMeasurement.remove(scope.activeMeasurement.points.length-1);
|
||||
|
||||
scope.measurements.push(scope.activeMeasurement);
|
||||
scope.activeMeasurement = undefined;
|
||||
|
||||
state = STATE.DEFAULT;
|
||||
scope.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseDown(event){
|
||||
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);
|
||||
|
||||
var direction = vector.sub(scope.camera.position).normalize();
|
||||
var ray = new THREE.Ray(scope.camera.position, direction);
|
||||
|
||||
var pointClouds = [];
|
||||
scope.scene.traverse(function(object){
|
||||
if(object instanceof Potree.PointCloudOctree){
|
||||
pointClouds.push(object);
|
||||
}
|
||||
});
|
||||
|
||||
var closestPoint = null;
|
||||
var closestPointDistance = null;
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointcloud = pointClouds[i];
|
||||
var point = pointcloud.pick(scope.renderer, scope.camera, ray, {accuracy: scope.accuracy});
|
||||
|
||||
if(!point){
|
||||
continue;
|
||||
}
|
||||
|
||||
var distance = scope.camera.position.distanceTo(point.position);
|
||||
|
||||
if(!closestPoint || distance < closestPointDistance){
|
||||
closestPoint = point;
|
||||
closestPointDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
return closestPoint ? closestPoint.position : null;
|
||||
}
|
||||
|
||||
this.setEnabled = function(enable){
|
||||
if(this.enabled === enable){
|
||||
return;
|
||||
}
|
||||
|
||||
this.enabled = enable;
|
||||
|
||||
if(enable){
|
||||
|
||||
state = STATE.PICKING;
|
||||
scope.activeMeasurement = new Measure(scope.sceneRoot);
|
||||
|
||||
scope.activeMeasurement.add(new THREE.Vector3(0,0,0));
|
||||
}
|
||||
};
|
||||
|
||||
this.update = function(){
|
||||
var measurements = [];
|
||||
for(var i = 0; i < this.measurements.length; i++){
|
||||
measurements.push(this.measurements[i]);
|
||||
}
|
||||
if(this.activeMeasurement){
|
||||
measurements.push(this.activeMeasurement);
|
||||
}
|
||||
|
||||
|
||||
for(var i = 0; i < measurements.length; i++){
|
||||
var measurement = measurements[i];
|
||||
for(var j = 0; j < measurement.spheres.length; j++){
|
||||
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 = Math.abs((wp.z / 60)); // * (2 - pp.z / pp.w);
|
||||
sphere.scale.set(w, w, w);
|
||||
}
|
||||
|
||||
for(var j = 0; j < measurement.edgeLabels.length; j++){
|
||||
var label = measurement.edgeLabels[j];
|
||||
var wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse);
|
||||
var w = Math.abs(wp.z / 10);
|
||||
var l = label.scale.length();
|
||||
label.scale.multiplyScalar(w / l);
|
||||
}
|
||||
|
||||
var wp = measurement.areaLabel.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse);
|
||||
var w = Math.abs(wp.z / 8);
|
||||
var l = measurement.areaLabel.scale.length();
|
||||
measurement.areaLabel.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 );
|
||||
|
||||
|
||||
|
||||
//this.activeMeasurement = new Measure(this.sceneRoot);
|
||||
//this.activeMeasurement.add(new THREE.Vector3(-3,0,-3));
|
||||
//this.activeMeasurement.add(new THREE.Vector3(3,0,-3));
|
||||
//this.activeMeasurement.add(new THREE.Vector3(0,0,3));
|
||||
//this.activeMeasurement.setPosition(0, new THREE.Vector3(-5, 0, -5));
|
||||
|
||||
};
|
||||
|
||||
|
||||
Potree.AreaTool.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
@ -2,10 +2,10 @@
|
||||
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};
|
||||
@ -18,12 +18,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 = [];
|
||||
@ -31,23 +138,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})
|
||||
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);
|
||||
|
||||
@ -57,7 +186,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){
|
||||
label.material.opacity = 0;
|
||||
label.position.copy(I);
|
||||
label.position.y += 0.5;
|
||||
scope.sceneRoot.add( label );
|
||||
|
||||
|
||||
var labelEnd = new Potree.TextSprite(msg);
|
||||
labelEnd.setBorderColor({r:0, g:255, b:0, a:1.0});
|
||||
@ -65,16 +194,15 @@ Potree.MeasuringTool = function(scene, camera, renderer){
|
||||
labelEnd.material.opacity = 0;
|
||||
labelEnd.position.copy(I);
|
||||
labelEnd.position.y += 0.5;
|
||||
scope.sceneRoot.add( labelEnd );
|
||||
|
||||
|
||||
var lc = new THREE.Color( 0xff0000 );
|
||||
var lineGeometry = new THREE.Geometry();
|
||||
lineGeometry.vertices.push(I.clone(), I.clone());
|
||||
lineGeometry.colors.push(lc, lc, lc);
|
||||
var lineMaterial = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
|
||||
var lineMaterial = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, linewidth: 10 } );
|
||||
lineMaterial.depthTest = false;
|
||||
sConnection = new THREE.Line(lineGeometry, lineMaterial);
|
||||
scope.sceneRoot.add(sConnection);
|
||||
|
||||
var edgeLabel = new Potree.TextSprite(0);
|
||||
edgeLabel.setBorderColor({r:0, g:255, b:0, a:0.0});
|
||||
@ -82,6 +210,11 @@ Potree.MeasuringTool = function(scene, camera, renderer){
|
||||
edgeLabel.material.depthTest = false;
|
||||
edgeLabel.position.copy(I);
|
||||
edgeLabel.position.y += 0.5;
|
||||
|
||||
|
||||
scope.sceneRoot.add(sConnection);
|
||||
scope.sceneRoot.add( label );
|
||||
scope.sceneRoot.add( labelEnd );
|
||||
scope.sceneRoot.add( edgeLabel );
|
||||
|
||||
|
||||
@ -98,7 +231,7 @@ Potree.MeasuringTool = function(scene, camera, renderer){
|
||||
|
||||
scope.activeMeasurement.spheres.push(sphere);
|
||||
}else if(state === STATE.PICKING){
|
||||
|
||||
scope.sceneRoot.remove(sphere);
|
||||
}
|
||||
|
||||
scope.activeMeasurement.points.push(I);
|
||||
@ -123,35 +256,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;
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -171,15 +336,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);
|
||||
@ -214,12 +429,79 @@ Potree.MeasuringTool = function(scene, camera, renderer){
|
||||
}
|
||||
|
||||
return closestPoint ? closestPoint.position : null;
|
||||
}
|
||||
}
|
||||
|
||||
this.domElement.addEventListener("dblclick", onDoubleClick, 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 = [];
|
||||
for(var i = 0; i < this.measurements.length; i++){
|
||||
measurements.push(this.measurements[i]);
|
||||
}
|
||||
if(this.activeMeasurement){
|
||||
measurements.push(this.activeMeasurement);
|
||||
}
|
||||
|
||||
|
||||
for(var i = 0; i < measurements.length; i++){
|
||||
var measurement = measurements[i];
|
||||
for(var j = 0; j < measurement.spheres.length; j++){
|
||||
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 = Math.abs((wp.z / 60)); // * (2 - pp.z / pp.w);
|
||||
sphere.scale.set(w, w, w);
|
||||
}
|
||||
|
||||
for(var j = 0; j < measurement.edgeLabels.length; j++){
|
||||
var label = measurement.edgeLabels[j];
|
||||
var wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse);
|
||||
var w = Math.abs(wp.z / 10);
|
||||
var l = label.scale.length();
|
||||
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.MeasuringTool.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
|
||||
685
src/utils/TransformationTool.js
Normal file
685
src/utils/TransformationTool.js
Normal file
@ -0,0 +1,685 @@
|
||||
|
||||
Potree.TransformationTool = 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};
|
||||
this.dragstart = null;
|
||||
|
||||
this.sceneTransformation = new THREE.Scene();
|
||||
this.sceneRoot = new THREE.Object3D();
|
||||
this.sceneTransformation.add(this.sceneRoot);
|
||||
|
||||
this.sceneRotation = new THREE.Scene();
|
||||
|
||||
this.translationNode = new THREE.Object3D();
|
||||
this.rotationNode = new THREE.Object3D();
|
||||
this.scaleNode = new THREE.Object3D();
|
||||
|
||||
this.sceneRoot.add(this.translationNode);
|
||||
this.sceneRoot.add(this.rotationNode);
|
||||
this.sceneRoot.add(this.scaleNode);
|
||||
|
||||
this.sceneRoot.visible = false;
|
||||
|
||||
this.hoveredElement = null;
|
||||
|
||||
this.STATE = {
|
||||
DEFAULT: 0,
|
||||
TRANSLATE_X: 1,
|
||||
TRANSLATE_Y: 2,
|
||||
TRANSLATE_Z: 3,
|
||||
SCALE_X: 1,
|
||||
SCALE_Y: 2,
|
||||
SCALE_Z: 3
|
||||
};
|
||||
|
||||
this.parts = {
|
||||
ARROW_X : {name: "arrow_x", object: undefined, color: new THREE.Color( 0xff0000 ), state: this.STATE.TRANSLATE_X},
|
||||
ARROW_Z : {name: "arrow_z", object: undefined, color: new THREE.Color( 0x0000ff ), state: this.STATE.TRANSLATE_Z},
|
||||
ARROW_Y : {name: "arrow_y", object: undefined, color: new THREE.Color( 0x00ff00 ), state: this.STATE.TRANSLATE_Y},
|
||||
SCALE_X : {name: "scale_x", object: undefined, color: new THREE.Color( 0xff0000 ), state: this.STATE.SCALE_X},
|
||||
SCALE_Z : {name: "scale_z", object: undefined, color: new THREE.Color( 0x0000ff ), state: this.STATE.SCALE_Z},
|
||||
SCALE_Y : {name: "scale_y", object: undefined, color: new THREE.Color( 0x00ff00 ), state: this.STATE.SCALE_Y},
|
||||
ROTATE_X : {name: "rotate_x", object: undefined, color: new THREE.Color( 0xff0000 ), state: this.STATE.ROTATE_X},
|
||||
ROTATE_Z : {name: "rotate_z", object: undefined, color: new THREE.Color( 0x0000ff ), state: this.STATE.ROTATE_Z},
|
||||
ROTATE_Y : {name: "rotate_y", object: undefined, color: new THREE.Color( 0x00ff00 ), state: this.STATE.ROTATE_Y}
|
||||
}
|
||||
|
||||
this.buildTranslationNode = function(){
|
||||
var arrowX = scope.createArrow(scope.parts.ARROW_X, scope.parts.ARROW_X.color);
|
||||
arrowX.rotation.z = -Math.PI/2;
|
||||
|
||||
var arrowY = scope.createArrow(scope.parts.ARROW_Y, scope.parts.ARROW_Y.color);
|
||||
|
||||
var arrowZ = scope.createArrow(scope.parts.ARROW_Z, scope.parts.ARROW_Z.color);
|
||||
arrowZ.rotation.x = -Math.PI/2;
|
||||
|
||||
this.translationNode.add(arrowX);
|
||||
this.translationNode.add(arrowY);
|
||||
this.translationNode.add(arrowZ);
|
||||
};
|
||||
|
||||
this.buildScaleNode = function(){
|
||||
var xHandle = this.createScaleHandle(scope.parts.SCALE_X, 0xff0000);
|
||||
xHandle.rotation.z = -Math.PI/2;
|
||||
|
||||
var yHandle = this.createScaleHandle(scope.parts.SCALE_Y, 0x00ff00);
|
||||
|
||||
var zHandle = this.createScaleHandle(scope.parts.SCALE_Z, 0x0000ff);
|
||||
zHandle.rotation.x = -Math.PI/2;
|
||||
|
||||
this.scaleNode.add(xHandle);
|
||||
this.scaleNode.add(yHandle);
|
||||
this.scaleNode.add(zHandle);
|
||||
}
|
||||
|
||||
this.buildRotationNode = function(){
|
||||
var xHandle = this.createRotationCircle(scope.parts.ROTATE_X, 0xff0000);
|
||||
xHandle.rotation.y = -Math.PI/2;
|
||||
|
||||
var yHandle = this.createRotationCircle(scope.parts.ROTATE_Y, 0x00ff00);
|
||||
|
||||
var zHandle = this.createRotationCircle(scope.parts.ROTATE_Z, 0x0000ff);
|
||||
yHandle.rotation.x = -Math.PI/2;
|
||||
|
||||
this.rotationNode.add(xHandle);
|
||||
this.rotationNode.add(yHandle);
|
||||
this.rotationNode.add(zHandle);
|
||||
|
||||
|
||||
|
||||
var sg = new THREE.SphereGeometry(2.9, 24, 24);
|
||||
var sphere = new THREE.Mesh(sg, new THREE.MeshBasicMaterial({color: 0xaaaaaa, transparent: true, opacity: 0.4}));
|
||||
|
||||
this.sceneRotation.add(sphere);
|
||||
|
||||
var moveEvent = function(event){
|
||||
sphere.material.color.setHex(0x555555);
|
||||
//sphere.material.emissive.setHex(0x555555);
|
||||
//sphere.material.opacity = 0.2;
|
||||
};
|
||||
|
||||
var leaveEvent = function(event){
|
||||
sphere.material.color.setHex(0xaaaaaa);
|
||||
//sphere.material.emissive.setHex(0x000000);
|
||||
//sphere.material.opacity = 0.3;
|
||||
};
|
||||
|
||||
var dragEvent = function(event){
|
||||
event.event.stopImmediatePropagation();
|
||||
|
||||
var mouseStart = new THREE.Vector3(scope.dragstart.mousePos.x, scope.dragstart.mousePos.y, 0.1);
|
||||
var mouseEnd = new THREE.Vector3(scope.mouse.x, scope.mouse.y, 0.1);
|
||||
var mouseDiff = new THREE.Vector3().subVectors(mouseEnd, mouseStart);
|
||||
|
||||
var sceneStart = mouseStart.clone().unproject(scope.camera);
|
||||
var sceneEnd = mouseEnd.clone().unproject(scope.camera);
|
||||
var sceneDiff = new THREE.Vector3().subVectors(sceneEnd, sceneStart);
|
||||
var sceneDir = sceneDiff.clone().normalize();
|
||||
var toCamDir = new THREE.Vector3().subVectors(scope.camera.position, sceneStart).normalize();
|
||||
var rotationAxis = toCamDir.clone().cross(sceneDir);
|
||||
var rotationAmount = 6 * mouseDiff.length();
|
||||
|
||||
for(var i = 0; i < scope.targets.length; i++){
|
||||
var target = scope.targets[i];
|
||||
var startRotation = scope.dragstart.rotations[i];
|
||||
|
||||
target.rotation.copy(startRotation);
|
||||
|
||||
var q = new THREE.Quaternion();
|
||||
|
||||
q.setFromAxisAngle( rotationAxis, rotationAmount );
|
||||
target.quaternion.multiplyQuaternions( q, target.quaternion );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//console.log(mouseDiff);
|
||||
};
|
||||
|
||||
var dropEvent = function(event){
|
||||
|
||||
};
|
||||
|
||||
sphere.addEventListener("mousemove", moveEvent);
|
||||
sphere.addEventListener("mouseleave", leaveEvent);
|
||||
sphere.addEventListener("mousedrag", dragEvent);
|
||||
sphere.addEventListener("drop", dropEvent);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.createBox = function(color){
|
||||
var boxGeometry = new THREE.BoxGeometry(1, 1, 1);
|
||||
var boxMaterial = new THREE.MeshBasicMaterial({color: color, transparent: true, opacity: 0.5});
|
||||
var box = new THREE.Mesh(boxGeometry, boxMaterial);
|
||||
|
||||
return box;
|
||||
};
|
||||
|
||||
var sph1, sph2, sph3;
|
||||
|
||||
this.createRotationCircle = function(partID, color){
|
||||
var geometry = new THREE.TorusGeometry(3, 0.1, 12, 48);
|
||||
//var material = new THREE.MeshBasicMaterial({color: color, depthTest: false, depthWrite: false});
|
||||
var material = new THREE.MeshBasicMaterial({color: color});
|
||||
|
||||
var ring = new THREE.Mesh(geometry, material);
|
||||
|
||||
var moveEvent = function(event){
|
||||
material.color.setRGB(1, 1, 0);
|
||||
};
|
||||
|
||||
var leaveEvent = function(event){
|
||||
material.color.setHex(color);
|
||||
};
|
||||
|
||||
var dragEvent = function(event){
|
||||
|
||||
event.event.stopImmediatePropagation();
|
||||
|
||||
var normal = new THREE.Vector3();
|
||||
if(partID === scope.parts.ROTATE_X){
|
||||
normal.x = 1;
|
||||
}else if(partID === scope.parts.ROTATE_Y){
|
||||
normal.y = 1;
|
||||
}else if(partID === scope.parts.ROTATE_Z){
|
||||
normal.z = -1;
|
||||
}
|
||||
|
||||
var sceneClickPos = scope.dragstart.sceneClickPos.clone();
|
||||
var sceneOrigin = scope.sceneRoot.position.clone();
|
||||
var sceneNormal = sceneClickPos.clone().sub(sceneOrigin).normalize();
|
||||
|
||||
var screenClickPos = sceneClickPos.clone().project(scope.camera);
|
||||
var screenOrigin = sceneOrigin.clone().project(scope.camera);
|
||||
var screenNormal = screenClickPos.clone().sub(screenOrigin).normalize();
|
||||
var screenTangent = new THREE.Vector3(screenNormal.y, screenNormal.x, 0);
|
||||
|
||||
var mouseStart = new THREE.Vector3(scope.dragstart.mousePos.x, scope.dragstart.mousePos.y, 0);
|
||||
var mouseEnd = new THREE.Vector3(scope.mouse.x, scope.mouse.y, 0);
|
||||
|
||||
var plane = new THREE.Plane().setFromNormalAndCoplanarPoint(normal, scope.sceneRoot.position);
|
||||
var camOrigin = scope.camera.position;
|
||||
var camDirection = new THREE.Vector3( 0, 0, -1 ).applyQuaternion( scope.camera.quaternion );
|
||||
var direction = new THREE.Vector3( mouseEnd.x, mouseEnd.y, 0.5 ).unproject(scope.camera).sub( scope.camera.position ).normalize();
|
||||
var ray = new THREE.Ray( camOrigin, direction);
|
||||
var I = ray.intersectPlane(plane);
|
||||
|
||||
if(!I){
|
||||
return;
|
||||
}
|
||||
|
||||
sceneTargetNormal = I.clone().sub(sceneOrigin).normalize();
|
||||
|
||||
var angleToClick;
|
||||
var angleToTarget;
|
||||
|
||||
if(partID === scope.parts.ROTATE_X){
|
||||
angleToClick = 2 * Math.PI + Math.atan2(sceneNormal.y, -sceneNormal.z);
|
||||
angleToTarget = 4 * Math.PI + Math.atan2(sceneTargetNormal.y, -sceneTargetNormal.z);
|
||||
}else if(partID === scope.parts.ROTATE_Y){
|
||||
angleToClick = 2 * Math.PI + Math.atan2(-sceneNormal.z, sceneNormal.x);
|
||||
angleToTarget = 4 * Math.PI + Math.atan2(-sceneTargetNormal.z, sceneTargetNormal.x);
|
||||
}else if(partID === scope.parts.ROTATE_Z){
|
||||
angleToClick = 2 * Math.PI + Math.atan2(sceneNormal.x, sceneNormal.y);
|
||||
angleToTarget = 4 * Math.PI + Math.atan2(sceneTargetNormal.x, sceneTargetNormal.y);
|
||||
}
|
||||
|
||||
var diff = angleToTarget - angleToClick;
|
||||
|
||||
for(var i = 0; i < scope.targets.length; i++){
|
||||
var target = scope.targets[i];
|
||||
var startRotation = scope.dragstart.rotations[i];
|
||||
|
||||
target.rotation.copy(startRotation);
|
||||
|
||||
var q = new THREE.Quaternion();
|
||||
|
||||
q.setFromAxisAngle( normal, diff ); // axis must be normalized, angle in radians
|
||||
target.quaternion.multiplyQuaternions( q, target.quaternion );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
var dropEvent = function(event){
|
||||
|
||||
};
|
||||
|
||||
ring.addEventListener("mousemove", moveEvent);
|
||||
ring.addEventListener("mouseleave", leaveEvent);
|
||||
ring.addEventListener("mousedrag", dragEvent);
|
||||
ring.addEventListener("drop", dropEvent);
|
||||
|
||||
return ring;
|
||||
};
|
||||
|
||||
this.createScaleHandle = function(partID, color){
|
||||
var boxGeometry = new THREE.BoxGeometry(1, 1, 1);
|
||||
var material = new THREE.MeshBasicMaterial({color: color, depthTest: false, depthWrite: false});
|
||||
|
||||
var box = new THREE.Mesh(boxGeometry, material);
|
||||
box.scale.set(0.3, 0.3, 0.3);
|
||||
box.position.set(0, 3, 0);
|
||||
|
||||
var shaft = new THREE.Mesh(boxGeometry, material);
|
||||
shaft.scale.set(0.05, 3, 0.05);
|
||||
shaft.position.set(0, 1.5, 0);
|
||||
|
||||
var handle = new THREE.Object3D();
|
||||
handle.add(box);
|
||||
handle.add(shaft);
|
||||
|
||||
handle.partID = partID;
|
||||
|
||||
|
||||
var moveEvent = function(event){
|
||||
material.color.setRGB(1, 1, 0);
|
||||
};
|
||||
|
||||
var leaveEvent = function(event){
|
||||
material.color.setHex(color);
|
||||
};
|
||||
|
||||
var dragEvent = function(event){
|
||||
|
||||
var sceneDirection = new THREE.Vector3();
|
||||
if(partID === scope.parts.SCALE_X){
|
||||
sceneDirection.x = 1;
|
||||
}else if(partID === scope.parts.SCALE_Y){
|
||||
sceneDirection.y = 1;
|
||||
}else if(partID === scope.parts.SCALE_Z){
|
||||
sceneDirection.z = -1;
|
||||
}
|
||||
|
||||
var sceneClickPos = scope.dragstart.sceneClickPos.clone();
|
||||
sceneClickPos.multiply(sceneDirection);
|
||||
sceneClickPos.z *= -1;
|
||||
|
||||
var lineStart = scope.dragstart.sceneStartPos.clone().project(scope.camera);
|
||||
var lineEnd = scope.dragstart.sceneStartPos.clone().add(sceneDirection).project(scope.camera);
|
||||
|
||||
var origin = lineStart.clone();
|
||||
var screenDirection = lineEnd.clone().sub(lineStart);
|
||||
screenDirection.normalize();
|
||||
|
||||
var mouseStart = new THREE.Vector3(scope.dragstart.mousePos.x, scope.dragstart.mousePos.y, 0);
|
||||
var mouseEnd = new THREE.Vector3(scope.mouse.x, scope.mouse.y, 0);
|
||||
|
||||
var directionDistance = new THREE.Vector3().subVectors(mouseEnd, mouseStart).dot(screenDirection);
|
||||
var pointOnLine = screenDirection.clone().multiplyScalar(directionDistance).add(origin);
|
||||
|
||||
pointOnLine.unproject(scope.camera);
|
||||
|
||||
var diff = scope.sceneRoot.position.clone().sub(pointOnLine);
|
||||
//var offset = sceneClickPos.clone().sub(scope.dragstart.sceneStartPos);
|
||||
//scope.sceneRoot.position.copy(pointOnLine);
|
||||
//diff.sub(scope.sceneRoot.position);
|
||||
|
||||
diff.multiply(new THREE.Vector3(-1, -1, 1)).addScalar(1);
|
||||
|
||||
for(var i = 0; i < scope.targets.length; i++){
|
||||
var target = scope.targets[i];
|
||||
var startScale = scope.dragstart.scales[i];
|
||||
target.scale.copy(startScale).add(diff);
|
||||
target.scale.x = Math.max(target.scale.x, 0.01);
|
||||
target.scale.y = Math.max(target.scale.y, 0.01);
|
||||
target.scale.z = Math.max(target.scale.z, 0.01);
|
||||
// target.scale.sub(diff);
|
||||
}
|
||||
|
||||
event.event.stopImmediatePropagation();
|
||||
|
||||
};
|
||||
|
||||
var dropEvent = function(event){
|
||||
material.color.set(color);
|
||||
};
|
||||
|
||||
box.addEventListener("mousemove", moveEvent);
|
||||
box.addEventListener("mouseleave", leaveEvent);
|
||||
box.addEventListener("mousedrag", dragEvent);
|
||||
box.addEventListener("drop", dropEvent);
|
||||
|
||||
return handle;
|
||||
};
|
||||
|
||||
this.createArrow = function(partID, color){
|
||||
var material = new THREE.MeshBasicMaterial({color: color, depthTest: false, depthWrite: false});
|
||||
|
||||
var shaftGeometry = new THREE.CylinderGeometry(0.05, 0.05, 3, 10, 1, false);
|
||||
var shaftMaterial = material;
|
||||
var shaft = new THREE.Mesh(shaftGeometry, shaftMaterial);
|
||||
shaft.position.y = 1.5;
|
||||
|
||||
var headGeometry = new THREE.CylinderGeometry(0, 0.2, 0.5, 10, 1, false);
|
||||
var headMaterial = material;
|
||||
var head = new THREE.Mesh(headGeometry, headMaterial);
|
||||
head.position.y = 3;
|
||||
|
||||
var arrow = new THREE.Object3D();
|
||||
arrow.add(shaft);
|
||||
arrow.add(head);
|
||||
arrow.partID = partID;
|
||||
arrow.material = material;
|
||||
|
||||
var moveEvent = function(event){
|
||||
shaftMaterial.color.setRGB(1, 1, 0);
|
||||
};
|
||||
|
||||
var leaveEvent = function(event){
|
||||
shaftMaterial.color.set(color);
|
||||
};
|
||||
|
||||
var dragEvent = function(event){
|
||||
|
||||
var sceneDirection = new THREE.Vector3();
|
||||
if(partID === scope.parts.ARROW_X){
|
||||
sceneDirection.x = 1;
|
||||
}else if(partID === scope.parts.ARROW_Y){
|
||||
sceneDirection.y = 1;
|
||||
}else if(partID === scope.parts.ARROW_Z){
|
||||
sceneDirection.z = -1;
|
||||
}
|
||||
|
||||
var sceneClickPos = scope.dragstart.sceneClickPos.clone();
|
||||
sceneClickPos.multiply(sceneDirection);
|
||||
sceneClickPos.z *= -1;
|
||||
|
||||
//var lineStart = new THREE.Vector3();
|
||||
//lineStart.x = scope.dragstart.mousePos.x;
|
||||
//lineStart.y = scope.dragstart.mousePos.y;
|
||||
var lineStart = scope.dragstart.sceneStartPos.clone().project(scope.camera);
|
||||
var lineEnd = scope.dragstart.sceneStartPos.clone().add(sceneDirection).project(scope.camera);
|
||||
|
||||
var origin = lineStart.clone();
|
||||
var screenDirection = lineEnd.clone().sub(lineStart);
|
||||
screenDirection.normalize();
|
||||
|
||||
|
||||
|
||||
var mouseStart = new THREE.Vector3(scope.dragstart.mousePos.x, scope.dragstart.mousePos.y, 0);
|
||||
var mouseEnd = new THREE.Vector3(scope.mouse.x, scope.mouse.y, 0);
|
||||
|
||||
//var htmlStart = mouseStart.clone().addScalar(1).multiplyScalar(0.5);
|
||||
//htmlStart.x *= scope.domElement.clientWidth;
|
||||
//htmlStart.y *= scope.domElement.clientHeight;
|
||||
//
|
||||
//var htmlEnd = mouseEnd.clone().addScalar(1).multiplyScalar(0.5);
|
||||
//htmlEnd.x *= scope.domElement.clientWidth;
|
||||
//htmlEnd.y *= scope.domElement.clientHeight;
|
||||
//
|
||||
//var el = document.getElementById("testDiv");
|
||||
//el.style.left = htmlStart.x;
|
||||
//el.style.width = htmlEnd.x - htmlStart.x;
|
||||
//el.style.bottom = htmlStart.y;
|
||||
//el.style.top = scope.domElement.clientHeight - htmlEnd.y;
|
||||
|
||||
|
||||
|
||||
|
||||
//var directionDistance = new THREE.Vector3().subVectors(mouseEnd, origin).dot(screenDirection);
|
||||
var directionDistance = new THREE.Vector3().subVectors(mouseEnd, mouseStart).dot(screenDirection);
|
||||
var pointOnLine = screenDirection.clone().multiplyScalar(directionDistance).add(origin);
|
||||
|
||||
pointOnLine.unproject(scope.camera);
|
||||
|
||||
var diff = scope.sceneRoot.position.clone();
|
||||
//scope.position.copy(pointOnLine);
|
||||
var offset = sceneClickPos.clone().sub(scope.dragstart.sceneStartPos);
|
||||
scope.sceneRoot.position.copy(pointOnLine);
|
||||
//scope.sceneRoot.position.sub(offset);
|
||||
diff.sub(scope.sceneRoot.position);
|
||||
|
||||
for(var i = 0; i < scope.targets.length; i++){
|
||||
var target = scope.targets[i];
|
||||
target.position.sub(diff);
|
||||
}
|
||||
|
||||
//if(!sph1){
|
||||
// var g = new THREE.SphereGeometry(0.2);
|
||||
//
|
||||
// var m1 = new THREE.MeshBasicMaterial({color: 0xff0000});
|
||||
// var m2 = new THREE.MeshBasicMaterial({color: 0x00ff00});
|
||||
// var m3 = new THREE.MeshBasicMaterial({color: 0x0000ff});
|
||||
//
|
||||
// sph1 = new THREE.Mesh(g, m1);
|
||||
// sph2 = new THREE.Mesh(g, m2);
|
||||
// sph3 = new THREE.Mesh(g, m3);
|
||||
//
|
||||
// scope.scene.add(sph1);
|
||||
// scope.scene.add(sph2);
|
||||
// scope.scene.add(sph3);
|
||||
//}
|
||||
//sph1.position.copy(scope.dragstart.sceneStartPos);
|
||||
//sph2.position.copy(scope.dragstart.sceneClickPos);
|
||||
//sph3.position.copy(pointOnLine);
|
||||
|
||||
event.event.stopImmediatePropagation();
|
||||
|
||||
};
|
||||
|
||||
var dropEvent = function(event){
|
||||
shaftMaterial.color.set(color);
|
||||
};
|
||||
|
||||
shaft.addEventListener("mousemove", moveEvent);
|
||||
head.addEventListener("mousemove", moveEvent);
|
||||
|
||||
shaft.addEventListener("mouseleave", leaveEvent);
|
||||
head.addEventListener("mouseleave", leaveEvent);
|
||||
|
||||
shaft.addEventListener("mousedrag", dragEvent);
|
||||
head.addEventListener("mousedrag", dragEvent);
|
||||
|
||||
shaft.addEventListener("drop", dropEvent);
|
||||
head.addEventListener("drop", dropEvent);
|
||||
|
||||
|
||||
|
||||
return arrow;
|
||||
};
|
||||
|
||||
function onMouseMove(event){
|
||||
scope.mouse.x = ( event.clientX / scope.domElement.clientWidth ) * 2 - 1;
|
||||
scope.mouse.y = - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1;
|
||||
|
||||
|
||||
if(scope.dragstart){
|
||||
|
||||
scope.dragstart.object.dispatchEvent({
|
||||
type: "mousedrag",
|
||||
event: event
|
||||
});
|
||||
|
||||
}else{
|
||||
|
||||
|
||||
var I = getHoveredElement();
|
||||
if(I){
|
||||
var object = I.object;
|
||||
|
||||
object.dispatchEvent({type: "mousemove", event: event});
|
||||
|
||||
if(scope.hoveredElement && scope.hoveredElement !== object){
|
||||
scope.hoveredElement.dispatchEvent({type: "mouseleave", event: event});
|
||||
}
|
||||
|
||||
scope.hoveredElement = object;
|
||||
|
||||
}else{
|
||||
if(scope.hoveredElement){
|
||||
scope.hoveredElement.dispatchEvent({type: "mouseleave", event: event});
|
||||
}
|
||||
|
||||
scope.hoveredElement = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
function onMouseDown(event){
|
||||
|
||||
if(event.which === 1){
|
||||
// left click
|
||||
var I = getHoveredElement();
|
||||
if(I){
|
||||
|
||||
var scales = [];
|
||||
var rotations = [];
|
||||
for(var i = 0; i < scope.targets.length; i++){
|
||||
scales.push(scope.targets[i].scale.clone());
|
||||
rotations.push(scope.targets[i].rotation.clone());
|
||||
}
|
||||
|
||||
scope.dragstart = {
|
||||
object: I.object,
|
||||
sceneClickPos: I.point,
|
||||
sceneStartPos: scope.sceneRoot.position.clone(),
|
||||
mousePos: {x: scope.mouse.x, y: scope.mouse.y},
|
||||
scales: scales,
|
||||
rotations: rotations
|
||||
};
|
||||
}
|
||||
}else if(event.which === 3){
|
||||
// right click
|
||||
|
||||
scope.setTargets([]);
|
||||
}
|
||||
};
|
||||
|
||||
function onMouseUp(event){
|
||||
|
||||
if(scope.dragstart){
|
||||
scope.dragstart.object.dispatchEvent({type: "drop", event: event});
|
||||
scope.dragstart = null;
|
||||
}
|
||||
};
|
||||
|
||||
function getHoveredElement(){
|
||||
|
||||
if(scope.targets.length === 0){
|
||||
return;
|
||||
}
|
||||
|
||||
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 objects = [];
|
||||
if(scope.translationNode.visible){
|
||||
objects.push(scope.translationNode);
|
||||
}else if(scope.scaleNode.visible){
|
||||
objects.push(scope.scaleNode);
|
||||
}else if(scope.rotationNode.visible){
|
||||
objects.push(scope.rotationNode);
|
||||
objects.push(scope.sceneRotation);
|
||||
}
|
||||
|
||||
var intersections = raycaster.intersectObjects(objects, true);
|
||||
if(intersections.length > 0){
|
||||
return intersections[0];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
this.setTargets = function(targets){
|
||||
scope.targets = targets;
|
||||
|
||||
if(scope.targets.length === 0){
|
||||
this.sceneRoot.visible = false;
|
||||
this.sceneRotation.visible = false;
|
||||
|
||||
return;
|
||||
}else{
|
||||
this.sceneRoot.visible = true;
|
||||
}
|
||||
|
||||
//TODO calculate centroid of all targets
|
||||
var target = targets[0];
|
||||
var bb;
|
||||
if(target.geometry && target.geometry.boundingBox){
|
||||
bb = target.geometry.boundingBox;
|
||||
}else{
|
||||
bb = target.boundingBox;
|
||||
}
|
||||
|
||||
if(bb){
|
||||
var centroid = bb.clone().applyMatrix4(target.matrixWorld).center();
|
||||
scope.sceneRoot.position.copy(centroid);
|
||||
}
|
||||
|
||||
//for(var i = 0; i < targets.length; i++){
|
||||
// var target = targets[i];
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
this.update = function(){
|
||||
var node = this.sceneRoot;
|
||||
var wp = node.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse);
|
||||
var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
|
||||
var w = Math.abs((wp.z / 20)); // * (2 - pp.z / pp.w);
|
||||
node.scale.set(w, w, w);
|
||||
|
||||
this.sceneRotation.scale.set(w,w,w);
|
||||
};
|
||||
|
||||
this.render = function(){
|
||||
this.update();
|
||||
this.sceneRotation.position.copy(this.sceneRoot.position);
|
||||
this.sceneRotation.visible = this.rotationNode.visible && this.sceneRoot.visible;
|
||||
|
||||
renderer.render(this.sceneRotation, this.camera);
|
||||
renderer.render(this.sceneTransformation, this.camera);
|
||||
};
|
||||
|
||||
this.translate = function(){
|
||||
this.translationNode.visible = true;
|
||||
this.scaleNode.visible = false;
|
||||
this.rotationNode.visible = false;
|
||||
};
|
||||
|
||||
this.scale = function(){
|
||||
this.translationNode.visible = false;
|
||||
this.scaleNode.visible = true;
|
||||
this.rotationNode.visible = false;
|
||||
};
|
||||
|
||||
this.rotate = function(){
|
||||
this.translationNode.visible = false;
|
||||
this.scaleNode.visible = false;
|
||||
this.rotationNode.visible = true;
|
||||
};
|
||||
|
||||
this.buildTranslationNode();
|
||||
this.buildScaleNode();
|
||||
this.buildRotationNode();
|
||||
|
||||
//this.translate();
|
||||
this.rotate();
|
||||
|
||||
this.setTargets([]);
|
||||
|
||||
//this.domElement.addEventListener( 'click', onClick, false);
|
||||
this.domElement.addEventListener( 'mousemove', onMouseMove, true );
|
||||
this.domElement.addEventListener( 'mousedown', onMouseDown, true );
|
||||
this.domElement.addEventListener( 'mouseup', onMouseUp, true );
|
||||
};
|
||||
221
src/utils/VolumeTool.js
Normal file
221
src/utils/VolumeTool.js
Normal file
@ -0,0 +1,221 @@
|
||||
|
||||
Potree.VolumeTool = 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};
|
||||
this.accuracy = 0.5;
|
||||
|
||||
this.volumes = [];
|
||||
|
||||
var STATE = {
|
||||
DEFAULT: 0,
|
||||
INSERT_VOLUME: 1
|
||||
|
||||
};
|
||||
|
||||
var state = STATE.DEFAULT;
|
||||
|
||||
var material = new THREE.MeshBasicMaterial( {color: 0x00ff00, transparent: true, opacity: 0.3} );
|
||||
|
||||
var boxGeometry = new THREE.BoxGeometry(1, 1, 1);
|
||||
boxGeometry.computeBoundingBox();
|
||||
|
||||
var boxFrameGeometry = new THREE.Geometry();
|
||||
// bottom
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, -0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, -0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, -0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, -0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, 0.5));
|
||||
// top
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, 0.5));
|
||||
// sides
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, -0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, 0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, -0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(0.5, 0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, -0.5, -0.5));
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, -0.5));
|
||||
|
||||
function onMouseMove(event){
|
||||
scope.mouse.x = ( event.clientX / scope.domElement.clientWidth ) * 2 - 1;
|
||||
scope.mouse.y = - ( event.clientY / scope.domElement.clientHeight ) * 2 + 1;
|
||||
};
|
||||
|
||||
function onMouseClick(event){
|
||||
|
||||
if(state === STATE.INSERT_VOLUME){
|
||||
scope.finishInsertion();
|
||||
}else if(event.which === 1){
|
||||
var I = getHoveredElement();
|
||||
|
||||
if(I){
|
||||
transformationTool.setTargets([I.object]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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 objects = [];
|
||||
for(var i = 0; i < scope.volumes.length; i++){
|
||||
var object = scope.volumes[i].object;
|
||||
objects.push(object);
|
||||
}
|
||||
|
||||
var intersections = raycaster.intersectObjects(objects, false);
|
||||
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);
|
||||
|
||||
var direction = vector.sub(scope.camera.position).normalize();
|
||||
var ray = new THREE.Ray(scope.camera.position, direction);
|
||||
|
||||
var pointClouds = [];
|
||||
scope.scene.traverse(function(object){
|
||||
if(object instanceof Potree.PointCloudOctree){
|
||||
pointClouds.push(object);
|
||||
}
|
||||
});
|
||||
|
||||
var closestPoint = null;
|
||||
var closestPointDistance = null;
|
||||
|
||||
for(var i = 0; i < pointClouds.length; i++){
|
||||
var pointcloud = pointClouds[i];
|
||||
var point = pointcloud.pick(scope.renderer, scope.camera, ray, {accuracy: scope.accuracy});
|
||||
|
||||
if(!point){
|
||||
continue;
|
||||
}
|
||||
|
||||
var distance = scope.camera.position.distanceTo(point.position);
|
||||
|
||||
if(!closestPoint || distance < closestPointDistance){
|
||||
closestPoint = point;
|
||||
closestPointDistance = distance;
|
||||
}
|
||||
}
|
||||
|
||||
return closestPoint ? closestPoint.position : null;
|
||||
}
|
||||
|
||||
this.update = function(delta){
|
||||
|
||||
if(state === STATE.INSERT_VOLUME){
|
||||
var I = getMousePointCloudIntersection();
|
||||
|
||||
if(I){
|
||||
var object = this.activeVolume.object;
|
||||
//var label = this.activeVolume.label;
|
||||
|
||||
object.position.copy(I);
|
||||
|
||||
var wp = object.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse);
|
||||
var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(this.camera.projectionMatrix);
|
||||
var w = Math.abs((wp.z / 10));
|
||||
object.scale.set(w, w, w);
|
||||
|
||||
//label.scale.set(w,w,w);
|
||||
//box.scale.set(1,1,1);
|
||||
}
|
||||
}
|
||||
|
||||
var volumes = [];
|
||||
for(var i = 0; i < this.volumes.length; i++){
|
||||
volumes.push(this.volumes[i]);
|
||||
}
|
||||
if(this.activeVolume){
|
||||
volumes.push(this.activeVolume);
|
||||
}
|
||||
|
||||
for(var i = 0; i < volumes.length; i++){
|
||||
var box = volumes[i].object;
|
||||
var label = volumes[i].label;
|
||||
|
||||
var volume = box.scale.x * box.scale.y * box.scale.z;
|
||||
var msg = Potree.utils.addCommas(volume.toFixed(1)) + "³";
|
||||
|
||||
var wp = label.getWorldPosition().applyMatrix4(this.camera.matrixWorldInverse);
|
||||
var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(this.camera.projectionMatrix);
|
||||
var w = Math.abs(wp.z / 5);
|
||||
label.setText(msg);
|
||||
var l = label.scale.length();
|
||||
label.scale.multiplyScalar(w / l);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
this.startInsertion = function(){
|
||||
state = STATE.INSERT_VOLUME;
|
||||
|
||||
var box = new THREE.Mesh( boxGeometry, material);
|
||||
this.scene.add(box);
|
||||
|
||||
var label = new Potree.TextSprite("0");
|
||||
label.setBorderColor({r:0, g:255, b:0, a:0.0});
|
||||
label.setBackgroundColor({r:0, g:255, b:0, a:0.0});
|
||||
label.material.depthTest = false;
|
||||
label.position.y -= 0.5;
|
||||
//label.material.opacity = 0;
|
||||
//label.position.copy(I);
|
||||
|
||||
box.add(label);
|
||||
|
||||
var line = new THREE.Line( boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000}));
|
||||
line.mode = THREE.LinePieces;
|
||||
box.add(line);
|
||||
|
||||
this.activeVolume = {
|
||||
object: box,
|
||||
label: label
|
||||
};
|
||||
}
|
||||
|
||||
this.finishInsertion = function(){
|
||||
this.volumes.push(this.activeVolume);
|
||||
transformationTool.setTargets([this.activeVolume.object]);
|
||||
|
||||
this.activeVolume = null;
|
||||
state = STATE.DEFAULT;
|
||||
|
||||
}
|
||||
|
||||
this.domElement.addEventListener( 'click', onMouseClick, false );
|
||||
this.domElement.addEventListener( 'mousemove', onMouseMove, false );
|
||||
};
|
||||
@ -75,11 +75,15 @@ onmessage = function(event){
|
||||
var cBuff = new ArrayBuffer(numPoints*3*4);
|
||||
var iBuff = new ArrayBuffer(numPoints*4);
|
||||
var clBuff = new ArrayBuffer(numPoints);
|
||||
var rnBuff = new ArrayBuffer(numPoints);
|
||||
var psBuff = new ArrayBuffer(numPoints * 2);
|
||||
|
||||
var positions = new Float32Array(pBuff);
|
||||
var colors = new Float32Array(cBuff);
|
||||
var intensities = new Float32Array(iBuff);
|
||||
var classifications = new Uint8Array(clBuff);
|
||||
var returnNumbers = new Uint8Array(rnBuff);
|
||||
var pointSourceIDs = new Uint16Array(psBuff);
|
||||
|
||||
|
||||
// temp arrays seem to be significantly faster than DataViews
|
||||
@ -105,10 +109,6 @@ onmessage = function(event){
|
||||
tempUint8[3] = bufferView[i*pointSize+11];
|
||||
var z = tempInt32[0];
|
||||
|
||||
//positions[3*i+0] = x * scale[0] + offset[0] - mins[0];
|
||||
//positions[3*i+1] = y * scale[1] + offset[1] - mins[1];
|
||||
//positions[3*i+2] = z * scale[2] + offset[2] - mins[2];
|
||||
|
||||
positions[3*i+0] = x * scale[0] + offset[0] + bbOffset[0];
|
||||
positions[3*i+1] = y * scale[1] + offset[1] + bbOffset[1];
|
||||
positions[3*i+2] = z * scale[2] + offset[2] + bbOffset[2];
|
||||
@ -119,11 +119,19 @@ onmessage = function(event){
|
||||
var intensity = tempUint16[0];
|
||||
intensities[i] = intensity;
|
||||
|
||||
// RETURN NUMBER, stored in the first 3 bits
|
||||
var returnNumber = bufferView[i*pointSize+14] & 7;
|
||||
returnNumbers[i] = returnNumber;
|
||||
|
||||
// CLASSIFICATION
|
||||
var classification = bufferView[i*pointSize+15];
|
||||
classifications[i] = classification;
|
||||
|
||||
// POINT SOURCE ID
|
||||
tempUint8[0] = bufferView[i*pointSize+18];
|
||||
tempUint8[1] = bufferView[i*pointSize+19];
|
||||
var pointSourceID = tempUint16[0];
|
||||
pointSourceIDs[i] = pointSourceID;
|
||||
|
||||
// COLOR, if available
|
||||
if(pointFormatID === 2){
|
||||
@ -149,13 +157,17 @@ onmessage = function(event){
|
||||
position: pBuff,
|
||||
color: cBuff,
|
||||
intensity: iBuff,
|
||||
classification: clBuff};
|
||||
classification: clBuff,
|
||||
returnNumber: rnBuff,
|
||||
pointSourceID: psBuff};
|
||||
|
||||
var transferables = [
|
||||
message.position,
|
||||
message.color,
|
||||
message.intensity,
|
||||
message.classification];
|
||||
message.classification,
|
||||
message.returnNumber,
|
||||
message.pointSourceID];
|
||||
|
||||
postMessage(message, transferables);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user