Merge pull request #366 from martinheidegger/happiness-linting
Moved code to be linted by happiness linter.
This commit is contained in:
commit
d9155a1fe6
35
.eslintrc
Normal file
35
.eslintrc
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"extends": "happiness",
|
||||
"globals": {
|
||||
"THREE": false,
|
||||
"TWEEN": false,
|
||||
"$": false,
|
||||
"XMLHttpRequest": false,
|
||||
"requestAnimationFrame": false,
|
||||
"Blob": false,
|
||||
"i18n": false,
|
||||
"URL": false,
|
||||
"Stats": false,
|
||||
"ProgressBar": false,
|
||||
"d3": false,
|
||||
"btoa": false,
|
||||
"alert": false,
|
||||
"ol": false,
|
||||
"proj4": false,
|
||||
"shapefile": false,
|
||||
"Worker": false,
|
||||
"Image": false,
|
||||
"LASFile": false,
|
||||
"LASDecoder": false,
|
||||
"BinaryHeap": false,
|
||||
"Potree": true,
|
||||
"initSidebar": true,
|
||||
"HoverMenu": true,
|
||||
"HoverMenuItem": true,
|
||||
"LRU": true,
|
||||
"viewer": true
|
||||
},
|
||||
"rules": {
|
||||
"no-lone-blocks": "off"
|
||||
}
|
||||
}
|
||||
23
.jshintrc
23
.jshintrc
@ -1,23 +0,0 @@
|
||||
{
|
||||
"bitwise": true,
|
||||
"camelcase": true,
|
||||
"curly": true,
|
||||
"eqeqeq": true,
|
||||
"immed": true,
|
||||
"indent": 4,
|
||||
"latedef": true,
|
||||
"newcap": true,
|
||||
"noarg": true,
|
||||
"nonew": true,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"esversion": 6,
|
||||
"sub": true,
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"globals": {
|
||||
"Potree": true,
|
||||
"THREE": true,
|
||||
"$": true
|
||||
}
|
||||
}
|
||||
@ -15,10 +15,10 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
|
||||
<script src="../libs/jquery/jquery-3.1.1.js"></script>
|
||||
<script src="../libs/spectrum/spectrum.js"></script>
|
||||
|
||||
|
||||
<script src="../libs/perfect-scrollbar/js/perfect-scrollbar.jquery.js"></script>
|
||||
<script src="../libs/jquery-ui/jquery-ui.min.js"></script>
|
||||
<script src="../libs/three.js/build/three.js"></script>
|
||||
@ -29,13 +29,13 @@
|
||||
<script src="../libs/proj4/proj4.js"></script>
|
||||
<script src="../libs/openlayers3/ol.js"></script>
|
||||
<script src="../libs/i18next/i18next.js"></script>
|
||||
|
||||
|
||||
<script src="../build/potree/potree.js"></script>
|
||||
<!--<script src="../src/viewer/sidebar.js"></script>-->
|
||||
|
||||
|
||||
<!-- INCLUDE ADDITIONAL DEPENDENCIES HERE -->
|
||||
<!-- INCLUDE SETTINGS HERE -->
|
||||
|
||||
|
||||
<script src="../libs/plasio/js/laslaz.js"></script>
|
||||
<script src="../libs/plasio/vendor/bluebird.js"></script>
|
||||
|
||||
@ -43,61 +43,61 @@
|
||||
<div id="potree_render_area"></div>
|
||||
<div id="potree_sidebar_container"> </div>
|
||||
</div>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
window.viewer = new Potree.Viewer(document.getElementById("potree_render_area"));
|
||||
|
||||
|
||||
viewer.setEDLEnabled(true);
|
||||
viewer.setFOV(60);
|
||||
viewer.setPointBudget(2*1000*1000);
|
||||
viewer.loadSettingsFromURL();
|
||||
|
||||
|
||||
viewer.setDescription("Point cloud courtesy of <a target='_blank' href='https://www.sigeom.ch/'>sigeom sa</a>");
|
||||
|
||||
|
||||
viewer.loadGUI(() => {
|
||||
viewer.setLanguage('en');
|
||||
$("#menu_other_settings").next().show();
|
||||
viewer.setClipMode(Potree.ClipMode.CLIP_OUTSIDE)
|
||||
viewer.toggleSidebar();
|
||||
});
|
||||
|
||||
|
||||
// Sigeom
|
||||
Potree.loadPointCloud("../pointclouds/vol_total/cloud.js", "sigeom.sa", function(e){
|
||||
let scene = viewer.scene;
|
||||
scene.addPointCloud(e.pointcloud);
|
||||
|
||||
|
||||
let material = e.pointcloud.material;
|
||||
material.size = 1;
|
||||
material.pointSizeType = Potree.PointSizeType.ADAPTIVE;
|
||||
|
||||
|
||||
{ // VOLUME visible
|
||||
let volume = new Potree.Volume();
|
||||
volume.scale.set(178.04, 159.14, 70.00);
|
||||
volume.position.set(589877.20, 231374.01, 749.62);
|
||||
volume.clip = true;
|
||||
volume.visible = false;
|
||||
|
||||
|
||||
scene.addVolume(volume);
|
||||
}
|
||||
|
||||
|
||||
{ // VOLUME invisible
|
||||
let volume = new Potree.Volume();
|
||||
volume.scale.set(178.04, 159.14, 70.00);
|
||||
volume.position.set(589661.930, 231374.010, 749.620);
|
||||
volume.clip = true;
|
||||
|
||||
|
||||
|
||||
|
||||
scene.addVolume(volume);
|
||||
}
|
||||
|
||||
|
||||
scene.view.position.set(590017.55, 231689.93, 1027.90);
|
||||
scene.view.lookAt(new THREE.Vector3(589807.53, 231410.61, 765.30));
|
||||
// viewer.fitToScreen();
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
4508
package-lock.json
generated
Normal file
4508
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@ -3,19 +3,29 @@
|
||||
"private": true,
|
||||
"version": "0.0.1",
|
||||
"description": "WebGL point cloud viewer",
|
||||
"scripts": {
|
||||
"lint": "eslint src",
|
||||
"test": "npm run lint"
|
||||
},
|
||||
"dependencies": {},
|
||||
"author": "Markus Schütz",
|
||||
"license": "BSD-2-CLAUSE",
|
||||
"devDependencies": {
|
||||
"eslint": "^4.3.0",
|
||||
"eslint-config-happiness": "^10.2.1",
|
||||
"eslint-plugin-import": "^2.7.0",
|
||||
"eslint-plugin-node": "^5.1.1",
|
||||
"eslint-plugin-promise": "^3.5.0",
|
||||
"eslint-plugin-standard": "^3.0.1",
|
||||
"gulp": "~3.5.2",
|
||||
"gulp-jshint": "^2.0.4",
|
||||
"gulp-size": "^2.1.0",
|
||||
"jshint": "^2.9.5"
|
||||
"gulp-concat": "~2.1.7",
|
||||
"gulp-connect": "^2.3.1",
|
||||
"gulp-jshint": "^2.0.4",
|
||||
"gulp-rename": "~1.0.0",
|
||||
"gulp-size": "^2.1.0",
|
||||
"gulp-uglify": "~0.2.1",
|
||||
"gulp-util": "~2.2.20",
|
||||
"jshint": "^2.9.5",
|
||||
"through": "~2.3.4"
|
||||
}
|
||||
}
|
||||
|
||||
100
src/Actions.js
100
src/Actions.js
@ -1,86 +1,80 @@
|
||||
|
||||
Potree.Action = class Action extends THREE.EventDispatcher{
|
||||
|
||||
constructor(args = {}){
|
||||
Potree.Action = class Action extends THREE.EventDispatcher {
|
||||
constructor (args = {}) {
|
||||
super();
|
||||
|
||||
this.icon = args.icon || "";
|
||||
|
||||
this.icon = args.icon || '';
|
||||
this.tooltip = args.tooltip;
|
||||
|
||||
if(args.onclick !== undefined){
|
||||
|
||||
if (args.onclick !== undefined) {
|
||||
this.onclick = args.onclick;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
onclick(event){
|
||||
|
||||
|
||||
onclick (event) {
|
||||
|
||||
}
|
||||
|
||||
pairWith(object){
|
||||
|
||||
|
||||
pairWith (object) {
|
||||
|
||||
}
|
||||
|
||||
setIcon(newIcon){
|
||||
|
||||
setIcon (newIcon) {
|
||||
let oldIcon = this.icon;
|
||||
|
||||
if(newIcon === oldIcon){
|
||||
|
||||
if (newIcon === oldIcon) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.icon = newIcon;
|
||||
|
||||
|
||||
this.dispatchEvent({
|
||||
type: "icon_changed",
|
||||
type: 'icon_changed',
|
||||
action: this,
|
||||
icon: newIcon,
|
||||
oldIcon: oldIcon
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.Actions = {};
|
||||
|
||||
Potree.Actions.ToggleAnnotationVisibility = class ToggleAnnotationVisibility extends Potree.Action{
|
||||
|
||||
constructor(args = {}){
|
||||
Potree.Actions.ToggleAnnotationVisibility = class ToggleAnnotationVisibility extends Potree.Action {
|
||||
constructor (args = {}) {
|
||||
super(args);
|
||||
|
||||
this.icon = Potree.resourcePath + "/icons/eye.svg";
|
||||
this.showIn = "sidebar";
|
||||
this.tooltip = "toggle visibility";
|
||||
|
||||
this.icon = Potree.resourcePath + '/icons/eye.svg';
|
||||
this.showIn = 'sidebar';
|
||||
this.tooltip = 'toggle visibility';
|
||||
}
|
||||
|
||||
pairWith(annotation){
|
||||
|
||||
if(annotation.visible){
|
||||
this.setIcon(Potree.resourcePath + "/icons/eye.svg");
|
||||
}else{
|
||||
this.setIcon(Potree.resourcePath + "/icons/eye_crossed.svg");
|
||||
|
||||
pairWith (annotation) {
|
||||
if (annotation.visible) {
|
||||
this.setIcon(Potree.resourcePath + '/icons/eye.svg');
|
||||
} else {
|
||||
this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
|
||||
}
|
||||
|
||||
annotation.addEventListener("visibility_changed", e => {
|
||||
|
||||
annotation.addEventListener('visibility_changed', e => {
|
||||
let annotation = e.annotation;
|
||||
|
||||
if(annotation.visible){
|
||||
this.setIcon(Potree.resourcePath + "/icons/eye.svg");
|
||||
}else{
|
||||
this.setIcon(Potree.resourcePath + "/icons/eye_crossed.svg");
|
||||
|
||||
if (annotation.visible) {
|
||||
this.setIcon(Potree.resourcePath + '/icons/eye.svg');
|
||||
} else {
|
||||
this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onclick(event){
|
||||
|
||||
onclick (event) {
|
||||
let annotation = event.annotation;
|
||||
|
||||
|
||||
annotation.visible = !annotation.visible;
|
||||
|
||||
if(annotation.visible){
|
||||
this.setIcon(Potree.resourcePath + "/icons/eye.svg");
|
||||
}else{
|
||||
this.setIcon(Potree.resourcePath + "/icons/eye_crossed.svg");
|
||||
|
||||
if (annotation.visible) {
|
||||
this.setIcon(Potree.resourcePath + '/icons/eye.svg');
|
||||
} else {
|
||||
this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -1,29 +1,26 @@
|
||||
|
||||
//
|
||||
// TODO
|
||||
//
|
||||
//
|
||||
// TODO
|
||||
//
|
||||
// - option to look along path during animation
|
||||
// -
|
||||
//
|
||||
// -
|
||||
//
|
||||
|
||||
|
||||
Potree.AnimationPath = class{
|
||||
|
||||
constructor(points = []){
|
||||
Potree.AnimationPath = class {
|
||||
constructor (points = []) {
|
||||
this.points = points;
|
||||
this.spline = new THREE.Spline(points);
|
||||
this.spline.reparametrizeByArcLength(1 / this.spline.getLength().total);
|
||||
this.tween = null;
|
||||
}
|
||||
|
||||
get(t){
|
||||
|
||||
get (t) {
|
||||
return this.spline.getPoint(t);
|
||||
}
|
||||
|
||||
animate(metersPerSecond = 1){
|
||||
|
||||
stop();
|
||||
|
||||
|
||||
animate (metersPerSecond = 1) {
|
||||
this.stop();
|
||||
|
||||
let length = this.spline.getLength().total;
|
||||
let animationDuration = (1000 * length) / metersPerSecond;
|
||||
|
||||
@ -33,52 +30,50 @@ Potree.AnimationPath = class{
|
||||
this.tween.onUpdate((e) => {
|
||||
viewer.scene.view.position.copy(this.spline.getPoint(progress.t));
|
||||
});
|
||||
|
||||
|
||||
this.tween.start();
|
||||
}
|
||||
|
||||
stop(){
|
||||
if(this.tween){
|
||||
|
||||
stop () {
|
||||
if (this.tween) {
|
||||
this.tween.stop();
|
||||
}
|
||||
}
|
||||
|
||||
resume(){
|
||||
if(this.tween){
|
||||
|
||||
resume () {
|
||||
if (this.tween) {
|
||||
this.tween.start();
|
||||
}
|
||||
}
|
||||
|
||||
getGeometry(){
|
||||
|
||||
getGeometry () {
|
||||
let geometry = new THREE.Geometry();
|
||||
|
||||
|
||||
let samples = 100;
|
||||
let i = 0;
|
||||
for(let u = 0; u <= 1; u += 1 / samples){
|
||||
for (let u = 0; u <= 1; u += 1 / samples) {
|
||||
let position = this.spline.getPoint(u);
|
||||
geometry.vertices[i] = new THREE.Vector3( position.x, position.y, position.z );
|
||||
|
||||
geometry.vertices[i] = new THREE.Vector3(position.x, position.y, position.z);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
return geometry;
|
||||
|
||||
//let material = new THREE.LineBasicMaterial( { color: 0xffffff, opacity: 1, linewidth: 2 } );
|
||||
//let line = new THREE.Line(geometry, material);
|
||||
//viewer.scene.scene.add(line);
|
||||
|
||||
// let material = new THREE.LineBasicMaterial( { color: 0xffffff, opacity: 1, linewidth: 2 } );
|
||||
// let line = new THREE.Line(geometry, material);
|
||||
// viewer.scene.scene.add(line);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//let target = new THREE.Vector3(589854.34, 231411.19, 692.77)
|
||||
//let points = [
|
||||
// let target = new THREE.Vector3(589854.34, 231411.19, 692.77)
|
||||
// let points = [
|
||||
// new THREE.Vector3(589815.52, 231738.31, 959.48 ),
|
||||
// new THREE.Vector3(589604.73, 231615.00, 968.10 ),
|
||||
// new THREE.Vector3(589579.11, 231354.41, 1010.06),
|
||||
// new THREE.Vector3(589723.00, 231169.95, 1015.57),
|
||||
// new THREE.Vector3(589960.76, 231116.87, 978.60 ),
|
||||
// new THREE.Vector3(590139.29, 231268.71, 972.33 )
|
||||
//]
|
||||
// ]
|
||||
//
|
||||
//let path = new Potree.AnimationPath(points);
|
||||
// let path = new Potree.AnimationPath(points);
|
||||
|
||||
@ -1,25 +1,24 @@
|
||||
Potree.Annotation = class extends THREE.EventDispatcher{
|
||||
|
||||
constructor(args = {}){
|
||||
Potree.Annotation = class extends THREE.EventDispatcher {
|
||||
constructor (args = {}) {
|
||||
super();
|
||||
|
||||
|
||||
this.scene = null;
|
||||
this.title = args.title || "No Title";
|
||||
this.description = args.description || "";
|
||||
|
||||
if(!args.position){
|
||||
//this.position = new THREE.Vector3(0, 0, 0);
|
||||
this.title = args.title || 'No Title';
|
||||
this.description = args.description || '';
|
||||
|
||||
if (!args.position) {
|
||||
// this.position = new THREE.Vector3(0, 0, 0);
|
||||
this.position = null;
|
||||
}else if(args.position instanceof THREE.Vector3){
|
||||
} else if (args.position instanceof THREE.Vector3) {
|
||||
this.position = args.position;
|
||||
}else{
|
||||
} else {
|
||||
this.position = new THREE.Vector3(...args.position);
|
||||
}
|
||||
|
||||
this.cameraPosition = (args.cameraPosition instanceof Array) ?
|
||||
new THREE.Vector3().fromArray(args.cameraPosition) : args.cameraPosition;
|
||||
this.cameraTarget = (args.cameraTarget instanceof Array) ?
|
||||
new THREE.Vector3().fromArray(args.cameraTarget) : args.cameraTarget;
|
||||
|
||||
this.cameraPosition = (args.cameraPosition instanceof Array)
|
||||
? new THREE.Vector3().fromArray(args.cameraPosition) : args.cameraPosition;
|
||||
this.cameraTarget = (args.cameraTarget instanceof Array)
|
||||
? new THREE.Vector3().fromArray(args.cameraTarget) : args.cameraTarget;
|
||||
this.radius = args.radius;
|
||||
this.view = args.view || null;
|
||||
this.keepOpen = false;
|
||||
@ -32,13 +31,13 @@ Potree.Annotation = class extends THREE.EventDispatcher{
|
||||
this._display = true;
|
||||
this._expand = false;
|
||||
this.collapseThreshold = [args.collapseThreshold, 100].find(e => e !== undefined);
|
||||
|
||||
|
||||
this.children = [];
|
||||
this.parent = null;
|
||||
this.boundingBox = new THREE.Box3();
|
||||
|
||||
let iconClose = Potree.resourcePath + "/icons/close.svg";
|
||||
|
||||
|
||||
let iconClose = Potree.resourcePath + '/icons/close.svg';
|
||||
|
||||
this.domElement = $(`
|
||||
<div class="annotation" oncontextmenu="return false;">
|
||||
<div class="annotation-titlebar">
|
||||
@ -52,272 +51,267 @@ Potree.Annotation = class extends THREE.EventDispatcher{
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
|
||||
this.elTitlebar = this.domElement.find(".annotation-titlebar");
|
||||
this.elTitle = this.elTitlebar.find(".annotation-label");
|
||||
this.elDescription = this.domElement.find(".annotation-description");
|
||||
this.elDescriptionClose = this.elDescription.find(".annotation-description-close");
|
||||
//this.elDescriptionContent = this.elDescription.find(".annotation-description-content");
|
||||
|
||||
|
||||
this.elTitlebar = this.domElement.find('.annotation-titlebar');
|
||||
this.elTitle = this.elTitlebar.find('.annotation-label');
|
||||
this.elDescription = this.domElement.find('.annotation-description');
|
||||
this.elDescriptionClose = this.elDescription.find('.annotation-description-close');
|
||||
// this.elDescriptionContent = this.elDescription.find(".annotation-description-content");
|
||||
|
||||
this.clickTitle = () => {
|
||||
if(this.hasView()){
|
||||
if (this.hasView()) {
|
||||
this.moveHere(this.scene.camera);
|
||||
}
|
||||
this.dispatchEvent({type: "click", target: this});
|
||||
this.dispatchEvent({type: 'click', target: this});
|
||||
};
|
||||
|
||||
|
||||
this.elTitle.click(this.clickTitle);
|
||||
|
||||
|
||||
this.actions = this.actions.map(a => {
|
||||
if(a instanceof Potree.Action){
|
||||
if (a instanceof Potree.Action) {
|
||||
return a;
|
||||
}else{
|
||||
} else {
|
||||
return new Potree.Action(a);
|
||||
}
|
||||
});
|
||||
|
||||
for(let action of this.actions){
|
||||
|
||||
for (let action of this.actions) {
|
||||
action.pairWith(this);
|
||||
}
|
||||
|
||||
|
||||
let actions = this.actions.filter(
|
||||
a => a.showIn === undefined || a.showIn.includes("scene"));
|
||||
|
||||
for(let action of actions){
|
||||
this.elTitle.css("padding", "1px 3px 0px 8px");
|
||||
|
||||
a => a.showIn === undefined || a.showIn.includes('scene'));
|
||||
|
||||
for (let action of actions) {
|
||||
this.elTitle.css('padding', '1px 3px 0px 8px');
|
||||
|
||||
let elButton = $(`<img src="${action.icon}" class="annotation-action-icon">`);
|
||||
this.elTitlebar.append(elButton);
|
||||
elButton.click(() => action.onclick({annotation: this}));
|
||||
}
|
||||
|
||||
|
||||
this.elDescriptionClose.hover(
|
||||
e => this.elDescriptionClose.css("opacity", "1"),
|
||||
e => this.elDescriptionClose.css("opacity", "0.5")
|
||||
e => this.elDescriptionClose.css('opacity', '1'),
|
||||
e => this.elDescriptionClose.css('opacity', '0.5')
|
||||
);
|
||||
this.elDescriptionClose.click(e => this.setHighlighted(false));
|
||||
//this.elDescriptionContent.html(this.description);
|
||||
|
||||
// this.elDescriptionContent.html(this.description);
|
||||
|
||||
this.domElement.mouseenter(e => this.setHighlighted(true));
|
||||
this.domElement.mouseleave(e => this.setHighlighted(false));
|
||||
|
||||
this.domElement.on("touchstart", e => {
|
||||
|
||||
this.domElement.on('touchstart', e => {
|
||||
this.setHighlighted(!this.isHighlighted);
|
||||
});
|
||||
|
||||
|
||||
this.display = false;
|
||||
}
|
||||
|
||||
get visible(){
|
||||
|
||||
get visible () {
|
||||
return this._visible;
|
||||
}
|
||||
|
||||
set visible(value){
|
||||
if(this._visible === value){
|
||||
|
||||
set visible (value) {
|
||||
if (this._visible === value) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this._visible = value;
|
||||
|
||||
|
||||
this.traverse(node => {
|
||||
node.display = value;
|
||||
});
|
||||
|
||||
|
||||
this.dispatchEvent({
|
||||
type: "visibility_changed",
|
||||
type: 'visibility_changed',
|
||||
annotation: this
|
||||
});
|
||||
}
|
||||
|
||||
get display(){
|
||||
|
||||
get display () {
|
||||
return this._display;
|
||||
}
|
||||
|
||||
set display(display){
|
||||
|
||||
if(this._display === display){
|
||||
|
||||
set display (display) {
|
||||
if (this._display === display) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this._display = display;
|
||||
|
||||
if(display){
|
||||
//this.domElement.fadeIn(200);
|
||||
|
||||
if (display) {
|
||||
// this.domElement.fadeIn(200);
|
||||
this.domElement.show();
|
||||
}else{
|
||||
//this.domElement.fadeOut(200);
|
||||
} else {
|
||||
// this.domElement.fadeOut(200);
|
||||
this.domElement.hide();
|
||||
}
|
||||
}
|
||||
|
||||
get expand(){
|
||||
|
||||
get expand () {
|
||||
return this._expand;
|
||||
}
|
||||
|
||||
set expand(expand){
|
||||
|
||||
if(this._expand === expand){
|
||||
|
||||
set expand (expand) {
|
||||
if (this._expand === expand) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(expand){
|
||||
|
||||
if (expand) {
|
||||
this.display = false;
|
||||
}else{
|
||||
} else {
|
||||
this.display = true;
|
||||
this.traverseDescendants(node => {
|
||||
node.display = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this._expand = expand;
|
||||
}
|
||||
|
||||
add(annotation){
|
||||
if(!this.children.includes(annotation)){
|
||||
|
||||
add (annotation) {
|
||||
if (!this.children.includes(annotation)) {
|
||||
this.children.push(annotation);
|
||||
annotation.parent = this;
|
||||
|
||||
|
||||
let descendants = [];
|
||||
annotation.traverse(a => {descendants.push(a)});
|
||||
|
||||
for(let descendant of descendants){
|
||||
annotation.traverse(a => { descendants.push(a); });
|
||||
|
||||
for (let descendant of descendants) {
|
||||
let c = this;
|
||||
while(c !== null){
|
||||
while (c !== null) {
|
||||
c.dispatchEvent({
|
||||
"type": "annotation_added",
|
||||
"annotation": descendant
|
||||
'type': 'annotation_added',
|
||||
'annotation': descendant
|
||||
});
|
||||
c = c.parent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
level(){
|
||||
if(this.parent === null){
|
||||
|
||||
level () {
|
||||
if (this.parent === null) {
|
||||
return 0;
|
||||
}else{
|
||||
} else {
|
||||
return this.parent.level() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
remove(annotation){
|
||||
|
||||
remove (annotation) {
|
||||
this.children = this.children.filter(e => e !== annotation);
|
||||
annotation.parent = null;
|
||||
}
|
||||
|
||||
updateBounds(){
|
||||
|
||||
updateBounds () {
|
||||
let box = new THREE.Box3();
|
||||
|
||||
if(this.position){
|
||||
|
||||
if (this.position) {
|
||||
box.expandByPoint(this.position);
|
||||
}
|
||||
|
||||
for(let child of this.children){
|
||||
|
||||
for (let child of this.children) {
|
||||
child.updateBounds();
|
||||
|
||||
|
||||
box.union(child.boundingBox);
|
||||
}
|
||||
|
||||
|
||||
this.boundingBox.copy(box);
|
||||
}
|
||||
|
||||
traverse(callback){
|
||||
let expand = callback(this);
|
||||
|
||||
if(expand === undefined || expand === true){
|
||||
for(let child of this.children){
|
||||
child.traverse(callback);
|
||||
|
||||
traverse (handler) {
|
||||
let expand = handler(this);
|
||||
|
||||
if (expand === undefined || expand === true) {
|
||||
for (let child of this.children) {
|
||||
child.traverse(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
traverseDescendants(callback){
|
||||
for(let child of this.children){
|
||||
child.traverse(callback);
|
||||
|
||||
traverseDescendants (handler) {
|
||||
for (let child of this.children) {
|
||||
child.traverse(handler);
|
||||
}
|
||||
}
|
||||
|
||||
flatten(){
|
||||
|
||||
flatten () {
|
||||
let annotations = [];
|
||||
|
||||
|
||||
this.traverse(annotation => {
|
||||
annotations.push(annotation);
|
||||
});
|
||||
|
||||
|
||||
return annotations;
|
||||
}
|
||||
|
||||
descendants(){
|
||||
|
||||
descendants () {
|
||||
let annotations = [];
|
||||
|
||||
|
||||
this.traverse(annotation => {
|
||||
if(annotation !== this){
|
||||
if (annotation !== this) {
|
||||
annotations.push(annotation);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return annotations;
|
||||
}
|
||||
|
||||
setHighlighted(highlighted){
|
||||
if(highlighted){
|
||||
this.domElement.css("opacity", "0.8");
|
||||
this.elTitlebar.css("box-shadow", "0 0 5px #fff");
|
||||
this.domElement.css("z-index", "1000");
|
||||
|
||||
if(this.description){
|
||||
this.descriptionVisible = true;
|
||||
//this.elDescription.css("display", "block");
|
||||
|
||||
setHighlighted (highlighted) {
|
||||
if (highlighted) {
|
||||
this.domElement.css('opacity', '0.8');
|
||||
this.elTitlebar.css('box-shadow', '0 0 5px #fff');
|
||||
this.domElement.css('z-index', '1000');
|
||||
|
||||
if (this.description) {
|
||||
this.descriptionVisible = true;
|
||||
// this.elDescription.css("display", "block");
|
||||
this.elDescription.fadeIn(200);
|
||||
this.elDescription.css("position", "relative");
|
||||
this.elDescription.css('position', 'relative');
|
||||
}
|
||||
}else{
|
||||
this.domElement.css("opacity", "0.5");
|
||||
this.elTitlebar.css("box-shadow", "");
|
||||
this.domElement.css("z-index", "100");
|
||||
this.descriptionVisible = false;
|
||||
this.elDescription.css("display", "none");
|
||||
//this.elDescription.fadeOut(200);
|
||||
} else {
|
||||
this.domElement.css('opacity', '0.5');
|
||||
this.elTitlebar.css('box-shadow', '');
|
||||
this.domElement.css('z-index', '100');
|
||||
this.descriptionVisible = false;
|
||||
this.elDescription.css('display', 'none');
|
||||
// this.elDescription.fadeOut(200);
|
||||
}
|
||||
|
||||
|
||||
this.isHighlighted = highlighted;
|
||||
}
|
||||
|
||||
hasView(){
|
||||
|
||||
hasView () {
|
||||
let hasPosTargetView = this.cameraTarget instanceof THREE.Vector3;
|
||||
hasPosTargetView = hasPosTargetView && this.cameraPosition instanceof THREE.Vector3;
|
||||
|
||||
|
||||
let hasRadiusView = this.radius !== undefined;
|
||||
|
||||
|
||||
let hasView = hasPosTargetView || hasRadiusView;
|
||||
|
||||
|
||||
return hasView;
|
||||
};
|
||||
|
||||
moveHere(camera){
|
||||
if(!this.hasView()){
|
||||
|
||||
moveHere (camera) {
|
||||
if (!this.hasView()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let view = this.scene.view;
|
||||
|
||||
|
||||
var animationDuration = 300;
|
||||
var easing = TWEEN.Easing.Quartic.Out;
|
||||
|
||||
|
||||
|
||||
let endTarget;
|
||||
if(this.cameraTarget){
|
||||
if (this.cameraTarget) {
|
||||
endTarget = this.cameraTarget;
|
||||
}else if(this.position){
|
||||
} else if (this.position) {
|
||||
endTarget = this.position;
|
||||
}else{
|
||||
} else {
|
||||
endTarget = this.boundingBox.getCenter();
|
||||
}
|
||||
|
||||
if(this.cameraPosition){
|
||||
|
||||
|
||||
if (this.cameraPosition) {
|
||||
let endPosition = this.cameraPosition;
|
||||
|
||||
{ // animate camera position
|
||||
@ -325,11 +319,11 @@ Potree.Annotation = class extends THREE.EventDispatcher{
|
||||
tween.easing(easing);
|
||||
tween.start();
|
||||
}
|
||||
|
||||
|
||||
{ // animate camera target
|
||||
var camTargetDistance = camera.position.distanceTo(endTarget);
|
||||
var target = new THREE.Vector3().addVectors(
|
||||
camera.position,
|
||||
camera.position,
|
||||
camera.getWorldDirection().clone().multiplyScalar(camTargetDistance)
|
||||
);
|
||||
var tween = new TWEEN.Tween(target).to(endTarget, animationDuration);
|
||||
@ -339,49 +333,45 @@ Potree.Annotation = class extends THREE.EventDispatcher{
|
||||
});
|
||||
tween.onComplete(() => {
|
||||
view.lookAt(target);
|
||||
this.dispatchEvent({type: "focusing_finished", target: this});
|
||||
this.dispatchEvent({type: 'focusing_finished', target: this});
|
||||
});
|
||||
|
||||
this.dispatchEvent({type: "focusing_started", target: this});
|
||||
|
||||
this.dispatchEvent({type: 'focusing_started', target: this});
|
||||
tween.start();
|
||||
}
|
||||
}else if(this.radius){
|
||||
} else if (this.radius) {
|
||||
let direction = view.direction;
|
||||
let endPosition = endTarget.clone().add(direction.multiplyScalar(-this.radius));
|
||||
let startRadius = view.radius;
|
||||
let endRadius = this.radius;
|
||||
|
||||
|
||||
{ // animate camera position
|
||||
let tween = new TWEEN.Tween(view.position).to(endPosition, animationDuration);
|
||||
tween.easing(easing);
|
||||
tween.start();
|
||||
}
|
||||
|
||||
|
||||
{ // animate radius
|
||||
let t = {x: 0};
|
||||
|
||||
|
||||
let tween = new TWEEN.Tween(t)
|
||||
.to({x: 1}, animationDuration)
|
||||
.onUpdate(function(){
|
||||
.onUpdate(function () {
|
||||
view.radius = this.x * endRadius + (1 - this.x) * startRadius;
|
||||
});
|
||||
tween.easing(easing);
|
||||
tween.start();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
dispose(){
|
||||
if(this.domElement.parentElement){
|
||||
|
||||
dispose () {
|
||||
if (this.domElement.parentElement) {
|
||||
this.domElement.parentElement.removeChild(this.domElement);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
toString(){
|
||||
return "Annotation: " + this.title;
|
||||
|
||||
toString () {
|
||||
return 'Annotation: ' + this.title;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
|
||||
/* globals BitReader:true */
|
||||
/* exported BitReader */
|
||||
/**
|
||||
* Reads unsigned integers encoded in a variable amount of bits from the buffer.
|
||||
* Bits are aligned into 32bit unsigned integers.
|
||||
@ -6,44 +7,44 @@
|
||||
* x: 123 encoded in 11 bits, binary: 00001111011
|
||||
* y: 7945 encoded in 17 bits, binary: 00001111100001001
|
||||
* z: 12 encoded in 6 bits, binary: 001100
|
||||
*
|
||||
* | --- 32 bits --- || --- 32 bits --- |
|
||||
*
|
||||
* | --- 32 bits --- || --- 32 bits --- |
|
||||
* |................................||................................|
|
||||
* |00001111011000011111000010010011||00
|
||||
* | x || y || z |
|
||||
*
|
||||
* z does not fit fully into the first 32 bit integer.
|
||||
* The first 4 bits of z are stored at the end of the first 32 bit integer
|
||||
* z does not fit fully into the first 32 bit integer.
|
||||
* The first 4 bits of z are stored at the end of the first 32 bit integer
|
||||
* and the remaining 2 bits at the next 32 bit integer.
|
||||
*
|
||||
*
|
||||
*/
|
||||
BitReader = function(buf){
|
||||
|
||||
BitReader = function (buf) {
|
||||
var buffer = new Uint32Array(buf);
|
||||
var bitOffset = 0;
|
||||
|
||||
this.read = function(bits){
|
||||
|
||||
this.read = function (bits) {
|
||||
var result;
|
||||
|
||||
if((bitOffset % 32) + bits <= 32){
|
||||
var val = buffer[Math.floor(bitOffset / 32)];
|
||||
var leftGap = bitOffset % 32;
|
||||
var rightGap = 32 - (leftGap + bits);
|
||||
|
||||
|
||||
// TODO val & leftGap seem to be duplicate code? Move out of if-block
|
||||
if ((bitOffset % 32) + bits <= 32) {
|
||||
let val = buffer[Math.floor(bitOffset / 32)];
|
||||
let leftGap = bitOffset % 32;
|
||||
let rightGap = 32 - (leftGap + bits);
|
||||
|
||||
result = (val << leftGap) >>> (leftGap + rightGap);
|
||||
}else{
|
||||
var val = buffer[Math.floor(bitOffset / 32)];
|
||||
var leftGap = bitOffset % 32;
|
||||
var rightGap = (leftGap + bits) - 32;
|
||||
|
||||
} else {
|
||||
let val = buffer[Math.floor(bitOffset / 32)];
|
||||
let leftGap = bitOffset % 32;
|
||||
let rightGap = (leftGap + bits) - 32;
|
||||
|
||||
result = (val << leftGap) >>> (leftGap - rightGap);
|
||||
|
||||
val = buffer[Math.floor(bitOffset / 32)+1];
|
||||
|
||||
val = buffer[Math.floor(bitOffset / 32) + 1];
|
||||
result = result | val >>> (32 - rightGap);
|
||||
}
|
||||
|
||||
|
||||
bitOffset += bits;
|
||||
|
||||
|
||||
return result;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,74 +1,66 @@
|
||||
|
||||
Potree.Features = function(){
|
||||
|
||||
var ftCanvas = document.createElement("canvas");
|
||||
var gl = ftCanvas.getContext("webgl") || ftCanvas.getContext("experimental-webgl");
|
||||
if (gl === null)
|
||||
return null;
|
||||
Potree.Features = (function () {
|
||||
var ftCanvas = document.createElement('canvas');
|
||||
var gl = ftCanvas.getContext('webgl') || ftCanvas.getContext('experimental-webgl');
|
||||
if (gl === null) { return null; }
|
||||
|
||||
// -- code taken from THREE.WebGLRenderer --
|
||||
var _vertexShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT );
|
||||
var _vertexShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT );
|
||||
var _vertexShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.LOW_FLOAT );
|
||||
var _vertexShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT);
|
||||
var _vertexShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT);
|
||||
// Unused: var _vertexShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
|
||||
|
||||
var _fragmentShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT );
|
||||
var _fragmentShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT );
|
||||
var _fragmentShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.LOW_FLOAT );
|
||||
var _fragmentShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
|
||||
var _fragmentShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT);
|
||||
// Unused: var _fragmentShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.LOW_FLOAT);
|
||||
|
||||
var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
|
||||
var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
|
||||
// -----------------------------------------
|
||||
|
||||
var precision;
|
||||
if(highpAvailable){
|
||||
precision = "highp";
|
||||
}else if(mediumpAvailable){
|
||||
precision = "mediump";
|
||||
}else{
|
||||
precision = "lowp";
|
||||
if (highpAvailable) {
|
||||
precision = 'highp';
|
||||
} else if (mediumpAvailable) {
|
||||
precision = 'mediump';
|
||||
} else {
|
||||
precision = 'lowp';
|
||||
}
|
||||
|
||||
return {
|
||||
SHADER_INTERPOLATION: {
|
||||
isSupported: function(){
|
||||
|
||||
isSupported: function () {
|
||||
var supported = true;
|
||||
|
||||
supported = supported && gl.getExtension("EXT_frag_depth");
|
||||
supported = supported && gl.getExtension('EXT_frag_depth');
|
||||
supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
|
||||
|
||||
return supported;
|
||||
}
|
||||
},
|
||||
SHADER_SPLATS: {
|
||||
isSupported: function(){
|
||||
|
||||
isSupported: function () {
|
||||
var supported = true;
|
||||
|
||||
supported = supported && gl.getExtension("EXT_frag_depth");
|
||||
supported = supported && gl.getExtension("OES_texture_float");
|
||||
supported = supported && gl.getExtension('EXT_frag_depth');
|
||||
supported = supported && gl.getExtension('OES_texture_float');
|
||||
supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
|
||||
|
||||
return supported;
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
SHADER_EDL: {
|
||||
isSupported: function(){
|
||||
|
||||
isSupported: function () {
|
||||
var supported = true;
|
||||
|
||||
supported = supported && gl.getExtension("EXT_frag_depth");
|
||||
supported = supported && gl.getExtension("OES_texture_float");
|
||||
|
||||
supported = supported && gl.getExtension('EXT_frag_depth');
|
||||
supported = supported && gl.getExtension('OES_texture_float');
|
||||
supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
|
||||
|
||||
|
||||
return supported;
|
||||
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
precision: precision
|
||||
};
|
||||
|
||||
}();
|
||||
}());
|
||||
|
||||
127
src/LRU.js
127
src/LRU.js
@ -1,21 +1,20 @@
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param node
|
||||
* @class an item in the lru list.
|
||||
* @class an item in the lru list.
|
||||
*/
|
||||
function LRUItem(node){
|
||||
function LRUItem (node) {
|
||||
this.previous = null;
|
||||
this.next = null;
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @class A doubly-linked-list of the least recently used elements.
|
||||
*/
|
||||
function LRU(){
|
||||
function LRU () {
|
||||
// the least recently used item
|
||||
this.first = null;
|
||||
// the most recently used item
|
||||
@ -28,50 +27,50 @@ function LRU(){
|
||||
|
||||
/**
|
||||
* number of elements in the list
|
||||
*
|
||||
*
|
||||
* @returns {Number}
|
||||
*/
|
||||
LRU.prototype.size = function(){
|
||||
LRU.prototype.size = function () {
|
||||
return this.elements;
|
||||
};
|
||||
|
||||
LRU.prototype.contains = function(node){
|
||||
LRU.prototype.contains = function (node) {
|
||||
return this.items[node.id] == null;
|
||||
};
|
||||
|
||||
/**
|
||||
* makes node the most recently used item. if the list does not contain node, it will be added.
|
||||
*
|
||||
*
|
||||
* @param node
|
||||
*/
|
||||
LRU.prototype.touch = function(node){
|
||||
if(!node.loaded){
|
||||
LRU.prototype.touch = function (node) {
|
||||
if (!node.loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
var item;
|
||||
if(this.items[node.id] == null){
|
||||
if (this.items[node.id] == null) {
|
||||
// add to list
|
||||
item = new LRUItem(node);
|
||||
item.previous = this.last;
|
||||
this.last = item;
|
||||
if(item.previous !== null){
|
||||
if (item.previous !== null) {
|
||||
item.previous.next = item;
|
||||
}
|
||||
|
||||
|
||||
this.items[node.id] = item;
|
||||
this.elements++;
|
||||
|
||||
if(this.first === null){
|
||||
|
||||
if (this.first === null) {
|
||||
this.first = item;
|
||||
}
|
||||
this.numPoints += node.numPoints;
|
||||
}else{
|
||||
} else {
|
||||
// update in list
|
||||
item = this.items[node.id];
|
||||
if(item.previous === null){
|
||||
if (item.previous === null) {
|
||||
// handle touch on first element
|
||||
if(item.next !== null){
|
||||
if (item.next !== null) {
|
||||
this.first = item.next;
|
||||
this.first.previous = null;
|
||||
item.previous = this.last;
|
||||
@ -79,9 +78,9 @@ LRU.prototype.touch = function(node){
|
||||
this.last = item;
|
||||
item.previous.next = item;
|
||||
}
|
||||
}else if(item.next === null){
|
||||
} else if (item.next === null) {
|
||||
// handle touch on last element
|
||||
}else{
|
||||
} else {
|
||||
// handle touch on any other element
|
||||
item.previous.next = item.next;
|
||||
item.next.previous = item.previous;
|
||||
@ -90,22 +89,20 @@ LRU.prototype.touch = function(node){
|
||||
this.last = item;
|
||||
item.previous.next = item;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
///**
|
||||
// * removes the least recently used item from the list and returns it.
|
||||
/// **
|
||||
// * removes the least recently used item from the list and returns it.
|
||||
// * if the list was empty, null will be returned.
|
||||
// */
|
||||
//LRU.prototype.remove = function remove(){
|
||||
// LRU.prototype.remove = function remove(){
|
||||
// if(this.first === null){
|
||||
// return null;
|
||||
// }
|
||||
// var lru = this.first;
|
||||
//
|
||||
// // if the lru list contains at least 2 items, the item after the least recently used elemnt will be the new lru item.
|
||||
// // if the lru list contains at least 2 items, the item after the least recently used elemnt will be the new lru item.
|
||||
// if(lru.next !== null){
|
||||
// this.first = lru.next;
|
||||
// this.first.previous = null;
|
||||
@ -113,100 +110,96 @@ LRU.prototype.touch = function(node){
|
||||
// this.first = null;
|
||||
// this.last = null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// delete this.items[lru.node.id];
|
||||
// this.elements--;
|
||||
// this.numPoints -= lru.node.numPoints;
|
||||
//
|
||||
//// Logger.info("removed node: " + lru.node.id);
|
||||
//
|
||||
/// / Logger.info("removed node: " + lru.node.id);
|
||||
// return lru.node;
|
||||
//};
|
||||
|
||||
LRU.prototype.remove = function remove(node){
|
||||
// };
|
||||
|
||||
LRU.prototype.remove = function remove (node) {
|
||||
var lruItem = this.items[node.id];
|
||||
if(lruItem){
|
||||
|
||||
if(this.elements === 1){
|
||||
if (lruItem) {
|
||||
if (this.elements === 1) {
|
||||
this.first = null;
|
||||
this.last = null;
|
||||
}else{
|
||||
if(!lruItem.previous){
|
||||
} else {
|
||||
if (!lruItem.previous) {
|
||||
this.first = lruItem.next;
|
||||
this.first.previous = null;
|
||||
}
|
||||
if(!lruItem.next){
|
||||
if (!lruItem.next) {
|
||||
this.last = lruItem.previous;
|
||||
this.last.next = null;
|
||||
}
|
||||
if(lruItem.previous &&lruItem.next){
|
||||
if (lruItem.previous && lruItem.next) {
|
||||
lruItem.previous.next = lruItem.next;
|
||||
lruItem.next.previous = lruItem.previous;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delete this.items[node.id];
|
||||
this.elements--;
|
||||
this.numPoints -= node.numPoints;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
LRU.prototype.getLRUItem = function(){
|
||||
if(this.first === null){
|
||||
LRU.prototype.getLRUItem = function () {
|
||||
if (this.first === null) {
|
||||
return null;
|
||||
}
|
||||
var lru = this.first;
|
||||
|
||||
|
||||
return lru.node;
|
||||
};
|
||||
|
||||
LRU.prototype.toString = function(){
|
||||
var string = "{ ";
|
||||
LRU.prototype.toString = function () {
|
||||
var string = '{ ';
|
||||
var curr = this.first;
|
||||
while(curr !== null){
|
||||
while (curr !== null) {
|
||||
string += curr.node.id;
|
||||
if(curr.next !== null){
|
||||
string += ", ";
|
||||
if (curr.next !== null) {
|
||||
string += ', ';
|
||||
}
|
||||
curr = curr.next;
|
||||
}
|
||||
string += "}";
|
||||
string += "(" + this.size() + ")";
|
||||
string += '}';
|
||||
string += '(' + this.size() + ')';
|
||||
return string;
|
||||
};
|
||||
|
||||
LRU.prototype.freeMemory = function(){
|
||||
if(this.elements <= 1){
|
||||
LRU.prototype.freeMemory = function () {
|
||||
if (this.elements <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
while(this.numPoints > Potree.pointLoadLimit){
|
||||
while (this.numPoints > Potree.pointLoadLimit) {
|
||||
var element = this.first;
|
||||
var node = element.node;
|
||||
this.disposeDescendants(node);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
LRU.prototype.disposeDescendants = function(node){
|
||||
LRU.prototype.disposeDescendants = function (node) {
|
||||
var stack = [];
|
||||
stack.push(node);
|
||||
while(stack.length > 0){
|
||||
while (stack.length > 0) {
|
||||
var current = stack.pop();
|
||||
|
||||
//console.log(current);
|
||||
|
||||
|
||||
// console.log(current);
|
||||
|
||||
current.dispose();
|
||||
this.remove(current);
|
||||
|
||||
for(var key in current.children){
|
||||
if(current.children.hasOwnProperty(key)){
|
||||
|
||||
for (var key in current.children) {
|
||||
if (current.children.hasOwnProperty(key)) {
|
||||
var child = current.children[key];
|
||||
if(child.loaded){
|
||||
if (child.loaded) {
|
||||
stack.push(current.children[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,65 +1,65 @@
|
||||
//
|
||||
//Potree.PointCloud = class PointCloud extends THREE.Object3D{
|
||||
//
|
||||
// Potree.PointCloud = class PointCloud extends THREE.Object3D{
|
||||
//
|
||||
// constructor(octree){
|
||||
// this.octree = octree;
|
||||
// }
|
||||
//
|
||||
//};
|
||||
// };
|
||||
//
|
||||
//Potree.GLObject = class GLObject{
|
||||
// Potree.GLObject = class GLObject{
|
||||
// constructor(tBuffer){
|
||||
// this.tBuffer = tBuffer;
|
||||
// this.vbos = new Map();
|
||||
// }
|
||||
//};
|
||||
// };
|
||||
//
|
||||
//Potree.GLProgram = class GLProgram{
|
||||
// Potree.GLProgram = class GLProgram{
|
||||
// constructor(tMaterial){
|
||||
// this.tMaterial = tMaterial;
|
||||
// this.program = null;
|
||||
// this.uniforms = new Map();
|
||||
// }
|
||||
//};
|
||||
// };
|
||||
//
|
||||
//
|
||||
//
|
||||
//Potree.Renderer = class PotreeRenderer{
|
||||
// Potree.Renderer = class PotreeRenderer{
|
||||
// constructor(threeRenderer){
|
||||
// this.threeRenderer = threeRenderer;
|
||||
// this.gl = this.threeRenderer.getContext();
|
||||
//
|
||||
//
|
||||
// this.glObjects = new Map();
|
||||
// this.glPrograms = new Map();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// render(pointcloud){
|
||||
// let gl = this.gl;
|
||||
// this.threeRenderer.resetGLState();
|
||||
//
|
||||
//
|
||||
// let visibleNodes = pointcloud.visibleNodes;
|
||||
// let material = pointcloud.material;
|
||||
//
|
||||
//
|
||||
// let glProgram = this.glPrograms.get(material);
|
||||
// if(!glProgram){
|
||||
// this.createProgram(material);
|
||||
// glProgram = this.glPrograms.get(material);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// for(let node of visibleNodes){
|
||||
// if(!(node.sceneNode && node.sceneNode instanceof THREE.Points)){
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// let glObject = this.glObjects.get(node);
|
||||
// if(!glObject){
|
||||
// this.createObject(node);
|
||||
// glObject = this.glObjects.get(node);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// for(let attribute of Object.keys(glObject.buffers)){
|
||||
// let value = glObject.buffers[attribute];
|
||||
//
|
||||
//
|
||||
// let type = null;
|
||||
// if(value.threeAttribute.array instanceof Float32Array){
|
||||
// type = gl.FLOAT;
|
||||
@ -68,29 +68,29 @@
|
||||
// }else if(value.threeAttribute.array instanceof Uint18Array){
|
||||
// type = gl.BYTE;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// let itemSize = value.threeAttribute.itemSize;
|
||||
//
|
||||
//
|
||||
// gl.bindBuffer(gl.ARRAY_BUFFER, value.vbo);
|
||||
// gl.vertexAttribPointer(vertexPositionAttribute, itemSize, type, false, 0, 0);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// gl.drawArrays(gl.POINT, 0, glObject.buffers.threeAttribute.position.count);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// this.threeRenderer.resetGLState();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// createShader(type, source){
|
||||
// let gl = this.gl;
|
||||
//
|
||||
//
|
||||
// let shader = gl.createShader(type);
|
||||
// gl.shaderSource(shader, source);
|
||||
// gl.compileShader(shader);
|
||||
//
|
||||
//
|
||||
// let success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
|
||||
// if(success){
|
||||
// return shader;
|
||||
@ -98,83 +98,83 @@
|
||||
// console.err("Shader compilation failed:");
|
||||
// console.err(gl.getShaderInfoLog(shader));
|
||||
// gl.deleteShader(shader);
|
||||
//
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// createProgram(material){
|
||||
// let gl = this.gl;
|
||||
//
|
||||
//
|
||||
// let vsSource = material.vertexShader;
|
||||
// let fsSource = material.fragmentShader;
|
||||
//
|
||||
//
|
||||
// let vs = this.createShader(gl.VERTEX_SHADER, vsSource);
|
||||
// let fs = this.createShader(gl.FRAGMENT_SHADER, fsSource);
|
||||
//
|
||||
//
|
||||
// if(vs === null || fs === null){
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// let program = gl.createProgram();
|
||||
// gl.attachShader(program, vs);
|
||||
// gl.attachShader(program, fs);
|
||||
// gl.linkProgram(program);
|
||||
//
|
||||
//
|
||||
// let success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
||||
// if(!success){
|
||||
// console.err("failed to create/link shader program");
|
||||
// console.err(gl.getProgramInfoLog(program));
|
||||
// gl.deleteProgram(program);
|
||||
//
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// let glProgram = new Potree.GLProgram();
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// createObject(renderer, node){
|
||||
//
|
||||
//
|
||||
// let gl = renderer.getContext();
|
||||
//
|
||||
//
|
||||
// let bufferGeometry = node.sceneNode.geometry;
|
||||
//
|
||||
//
|
||||
// let buffers = {};
|
||||
//
|
||||
//
|
||||
// for(let attributeName of Object.keys(bufferGeometry.attributes)){
|
||||
// let attribute = bufferGeometry.attributes[attributeName];
|
||||
// let vbo = gl.createBuffer();
|
||||
// gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
|
||||
// gl.bufferData(gl.ARRAY_BUFFER, attribute.array, gl.STATIC_DRAW);
|
||||
//
|
||||
//
|
||||
// buffers[attributeName] = {
|
||||
// threeAttribute: attribute,
|
||||
// vbo: vbo
|
||||
// };
|
||||
// }
|
||||
// gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
||||
//
|
||||
//
|
||||
// let glObject = new Potree.GLObject(node);
|
||||
// let webgl = {
|
||||
// node: node,
|
||||
// geometry: bufferGeometry,
|
||||
// buffers
|
||||
// };
|
||||
//
|
||||
//
|
||||
// console.log(webgl);
|
||||
//
|
||||
//
|
||||
// this.wegbl.set(node, webgl);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// freeObject(node){
|
||||
//
|
||||
//
|
||||
// // TODO destroy buffers
|
||||
//
|
||||
//
|
||||
// this.webgl.delete(node);
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
//};
|
||||
//
|
||||
//
|
||||
// };
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
Potree.PointCloudGreyhoundGeometry = function(){
|
||||
Potree.PointCloudGreyhoundGeometry = function () {
|
||||
this.spacing = 0;
|
||||
this.boundingBox = null;
|
||||
this.root = null;
|
||||
@ -7,7 +7,7 @@ Potree.PointCloudGreyhoundGeometry = function(){
|
||||
this.pointAttributes = {};
|
||||
this.hierarchyStepSize = -1;
|
||||
this.loader = null;
|
||||
this.schema = null;
|
||||
this.schema = null;
|
||||
|
||||
this.baseDepth = null;
|
||||
this.offset = null;
|
||||
@ -15,8 +15,8 @@ Potree.PointCloudGreyhoundGeometry = function(){
|
||||
|
||||
this.boundingSphere = null;
|
||||
|
||||
//the serverURL will contain the base URL of the greyhound server. f.e. http://dev.greyhound.io/resource/autzen/
|
||||
// the serverURL will contain the base URL of the greyhound server. f.e. http://dev.greyhound.io/resource/autzen/
|
||||
this.serverURL = null;
|
||||
|
||||
this.normalize = { color: false, intensity: false };
|
||||
this.normalize = { color: false, intensity: false };
|
||||
};
|
||||
|
||||
@ -1,24 +1,23 @@
|
||||
var nodesLoadTimes = {};
|
||||
var baseLoaded = false;
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode = function(
|
||||
name, pcoGeometry, boundingBox, scale, offset) {
|
||||
Potree.PointCloudGreyhoundGeometryNode = function (
|
||||
name, pcoGeometry, boundingBox, scale, offset) {
|
||||
this.id = Potree.PointCloudGreyhoundGeometryNode.IDCount++;
|
||||
this.name = name;
|
||||
this.index = parseInt(name.charAt(name.length-1));
|
||||
this.index = parseInt(name.charAt(name.length - 1));
|
||||
this.pcoGeometry = pcoGeometry;
|
||||
this.geometry = null;
|
||||
this.boundingBox = boundingBox;
|
||||
this.boundingSphere = boundingBox.getBoundingSphere();
|
||||
this.scale = scale;
|
||||
this.offset = offset;
|
||||
this.scale = scale;
|
||||
this.offset = offset;
|
||||
this.children = {};
|
||||
this.numPoints = 0;
|
||||
this.level = null;
|
||||
this.loaded = false;
|
||||
this.oneTimeDisposeHandlers = [];
|
||||
|
||||
let bounds = this.boundingBox.clone()
|
||||
let bounds = this.boundingBox.clone();
|
||||
bounds.min.sub(this.pcoGeometry.boundingBox.getCenter());
|
||||
bounds.max.sub(this.pcoGeometry.boundingBox.getCenter());
|
||||
|
||||
@ -27,47 +26,48 @@ Potree.PointCloudGreyhoundGeometryNode = function(
|
||||
bounds.max.multiplyScalar(1 / this.scale);
|
||||
}
|
||||
|
||||
// This represents the bounds for this node in the reference frame of the
|
||||
// global bounds from `info`, centered around the origin, and then scaled
|
||||
// by our selected scale.
|
||||
this.greyhoundBounds = bounds;
|
||||
// This represents the bounds for this node in the reference frame of the
|
||||
// global bounds from `info`, centered around the origin, and then scaled
|
||||
// by our selected scale.
|
||||
this.greyhoundBounds = bounds;
|
||||
|
||||
// This represents the offset between the coordinate system described above
|
||||
// and our pcoGeometry bounds.
|
||||
this.greyhoundOffset = this.pcoGeometry.offset.clone().add(
|
||||
this.pcoGeometry.boundingBox.getSize().multiplyScalar(0.5));
|
||||
// This represents the offset between the coordinate system described above
|
||||
// and our pcoGeometry bounds.
|
||||
this.greyhoundOffset = this.pcoGeometry.offset.clone().add(
|
||||
this.pcoGeometry.boundingBox.getSize().multiplyScalar(0.5)
|
||||
);
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.IDCount = 0;
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype =
|
||||
Object.create(Potree.PointCloudTreeNode.prototype);
|
||||
Object.create(Potree.PointCloudTreeNode.prototype);
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.isGeometryNode = function() {
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.isGeometryNode = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.isTreeNode = function() {
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.isTreeNode = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.isLoaded = function() {
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.isLoaded = function () {
|
||||
return this.loaded;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getBoundingSphere = function() {
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getBoundingSphere = function () {
|
||||
return this.boundingSphere;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getBoundingBox = function() {
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getBoundingBox = function () {
|
||||
return this.boundingBox;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getLevel = function(){
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getLevel = function () {
|
||||
return this.level;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getChildren = function() {
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getChildren = function () {
|
||||
var children = [];
|
||||
|
||||
for (var i = 0; i < 8; ++i) {
|
||||
@ -79,50 +79,46 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.getChildren = function() {
|
||||
return children;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getURL = function() {
|
||||
var schema = this.pcoGeometry.schema;
|
||||
let bounds = this.greyhoundBounds;
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getURL = function () {
|
||||
var schema = this.pcoGeometry.schema;
|
||||
let bounds = this.greyhoundBounds;
|
||||
|
||||
var boundsString =
|
||||
bounds.min.x + ',' + bounds.min.y + ',' + bounds.min.z + ',' +
|
||||
bounds.max.x + ',' + bounds.max.y + ',' + bounds.max.z;
|
||||
var boundsString =
|
||||
bounds.min.x + ',' + bounds.min.y + ',' + bounds.min.z + ',' +
|
||||
bounds.max.x + ',' + bounds.max.y + ',' + bounds.max.z;
|
||||
|
||||
var url = ''+this.pcoGeometry.serverURL +
|
||||
'read?depthBegin=' +
|
||||
(baseLoaded ? (this.level + this.pcoGeometry.baseDepth) : 0) +
|
||||
'&depthEnd=' + (this.level + this.pcoGeometry.baseDepth + 1) +
|
||||
'&bounds=[' + boundsString + ']' +
|
||||
'&schema=' + JSON.stringify(schema) +
|
||||
'&compress=true';
|
||||
var url = '' + this.pcoGeometry.serverURL +
|
||||
'read?depthBegin=' +
|
||||
(baseLoaded ? (this.level + this.pcoGeometry.baseDepth) : 0) +
|
||||
'&depthEnd=' + (this.level + this.pcoGeometry.baseDepth + 1) +
|
||||
'&bounds=[' + boundsString + ']' +
|
||||
'&schema=' + JSON.stringify(schema) +
|
||||
'&compress=true';
|
||||
|
||||
if (this.scale) {
|
||||
url += '&scale=' + this.scale;
|
||||
}
|
||||
if (this.scale) {
|
||||
url += '&scale=' + this.scale;
|
||||
}
|
||||
|
||||
if (this.greyhoundOffset) {
|
||||
if (this.greyhoundOffset) {
|
||||
let offset = this.greyhoundOffset;
|
||||
url += '&offset=[' + offset.x + ',' + offset.y + ',' + offset.z + ']';
|
||||
}
|
||||
|
||||
if(this.level === 1){
|
||||
let a = 1;
|
||||
}
|
||||
if (!baseLoaded) baseLoaded = true;
|
||||
|
||||
if (!baseLoaded) baseLoaded = true;
|
||||
|
||||
return url;
|
||||
return url;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.addChild = function(child) {
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.addChild = function (child) {
|
||||
this.children[child.index] = child;
|
||||
child.parent = this;
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.load = function(){
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.load = function () {
|
||||
if (
|
||||
this.loading === true ||
|
||||
this.loaded === true ||
|
||||
this.pcoGeometry.numNodesLoading > 3) {
|
||||
this.loading === true ||
|
||||
this.loaded === true ||
|
||||
this.pcoGeometry.numNodesLoading > 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -130,108 +126,105 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.load = function(){
|
||||
this.pcoGeometry.numNodesLoading++;
|
||||
|
||||
if (
|
||||
this.level % this.pcoGeometry.hierarchyStepSize === 0 &&
|
||||
this.hasChildren) {
|
||||
this.level % this.pcoGeometry.hierarchyStepSize === 0 &&
|
||||
this.hasChildren) {
|
||||
this.loadHierarchyThenPoints();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.loadPoints();
|
||||
}
|
||||
};
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.loadPoints = function(){
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.loadPoints = function () {
|
||||
this.pcoGeometry.loader.load(this);
|
||||
};
|
||||
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints =
|
||||
function() {
|
||||
// From Greyhound (Cartesian) ordering for the octree to Potree-default
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints = function () {
|
||||
// From Greyhound (Cartesian) ordering for the octree to Potree-default
|
||||
var transform = [0, 2, 1, 3, 4, 6, 5, 7];
|
||||
|
||||
var makeBitMask = function(node) {
|
||||
var mask = 0;
|
||||
Object.keys(node).forEach(function(key) {
|
||||
if (key === 'swd') mask += 1 << transform[0];
|
||||
else if (key === 'nwd') mask += 1 << transform[1];
|
||||
else if (key === 'swu') mask += 1 << transform[2];
|
||||
else if (key === 'nwu') mask += 1 << transform[3];
|
||||
else if (key === 'sed') mask += 1 << transform[4];
|
||||
else if (key === 'ned') mask += 1 << transform[5];
|
||||
else if (key === 'seu') mask += 1 << transform[6];
|
||||
else if (key === 'neu') mask += 1 << transform[7];
|
||||
});
|
||||
return mask;
|
||||
};
|
||||
var makeBitMask = function (node) {
|
||||
var mask = 0;
|
||||
Object.keys(node).forEach(function (key) {
|
||||
if (key === 'swd') mask += 1 << transform[0];
|
||||
else if (key === 'nwd') mask += 1 << transform[1];
|
||||
else if (key === 'swu') mask += 1 << transform[2];
|
||||
else if (key === 'nwu') mask += 1 << transform[3];
|
||||
else if (key === 'sed') mask += 1 << transform[4];
|
||||
else if (key === 'ned') mask += 1 << transform[5];
|
||||
else if (key === 'seu') mask += 1 << transform[6];
|
||||
else if (key === 'neu') mask += 1 << transform[7];
|
||||
});
|
||||
return mask;
|
||||
};
|
||||
|
||||
var parseChildrenCounts = function(base, parentName, stack) {
|
||||
var keys = Object.keys(base);
|
||||
var child;
|
||||
var childName;
|
||||
var parseChildrenCounts = function (base, parentName, stack) {
|
||||
var keys = Object.keys(base);
|
||||
var child;
|
||||
var childName;
|
||||
|
||||
keys.forEach(function(key) {
|
||||
if (key === 'n') return;
|
||||
switch (key) {
|
||||
case 'swd':
|
||||
child = base.swd; childName = parentName + transform[0];
|
||||
break;
|
||||
case 'nwd':
|
||||
child = base.nwd; childName = parentName + transform[1];
|
||||
break;
|
||||
case 'swu':
|
||||
child = base.swu; childName = parentName + transform[2];
|
||||
break;
|
||||
case 'nwu':
|
||||
child = base.nwu; childName = parentName + transform[3];
|
||||
break;
|
||||
case 'sed':
|
||||
child = base.sed; childName = parentName + transform[4];
|
||||
break;
|
||||
case 'ned':
|
||||
child = base.ned; childName = parentName + transform[5];
|
||||
break;
|
||||
case 'seu':
|
||||
child = base.seu; childName = parentName + transform[6];
|
||||
break;
|
||||
case 'neu':
|
||||
child = base.neu; childName = parentName + transform[7];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
keys.forEach(function (key) {
|
||||
if (key === 'n') return;
|
||||
switch (key) {
|
||||
case 'swd':
|
||||
child = base.swd; childName = parentName + transform[0];
|
||||
break;
|
||||
case 'nwd':
|
||||
child = base.nwd; childName = parentName + transform[1];
|
||||
break;
|
||||
case 'swu':
|
||||
child = base.swu; childName = parentName + transform[2];
|
||||
break;
|
||||
case 'nwu':
|
||||
child = base.nwu; childName = parentName + transform[3];
|
||||
break;
|
||||
case 'sed':
|
||||
child = base.sed; childName = parentName + transform[4];
|
||||
break;
|
||||
case 'ned':
|
||||
child = base.ned; childName = parentName + transform[5];
|
||||
break;
|
||||
case 'seu':
|
||||
child = base.seu; childName = parentName + transform[6];
|
||||
break;
|
||||
case 'neu':
|
||||
child = base.neu; childName = parentName + transform[7];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
stack.push({
|
||||
children: makeBitMask(child),
|
||||
numPoints: child.n,
|
||||
name: childName
|
||||
});
|
||||
stack.push({
|
||||
children: makeBitMask(child),
|
||||
numPoints: child.n,
|
||||
name: childName
|
||||
});
|
||||
|
||||
parseChildrenCounts(child, childName, stack);
|
||||
});
|
||||
};
|
||||
parseChildrenCounts(child, childName, stack);
|
||||
});
|
||||
};
|
||||
|
||||
// Load hierarchy.
|
||||
var callback = function(node, greyhoundHierarchy) {
|
||||
var callback = function (node, greyhoundHierarchy) {
|
||||
var decoded = [];
|
||||
node.numPoints = greyhoundHierarchy.n;
|
||||
parseChildrenCounts(greyhoundHierarchy, node.name, decoded);
|
||||
parseChildrenCounts(greyhoundHierarchy, node.name, decoded);
|
||||
|
||||
var nodes = {};
|
||||
nodes[node.name] = node;
|
||||
var pgg = node.pcoGeometry;
|
||||
|
||||
for( var i = 0; i < decoded.length; i++){
|
||||
for (var i = 0; i < decoded.length; i++) {
|
||||
var name = decoded[i].name;
|
||||
var numPoints = decoded[i].numPoints;
|
||||
var index = parseInt(name.charAt(name.length-1));
|
||||
var parentName = name.substring(0, name.length-1);
|
||||
var index = parseInt(name.charAt(name.length - 1));
|
||||
var parentName = name.substring(0, name.length - 1);
|
||||
var parentNode = nodes[parentName];
|
||||
var level = name.length-1;
|
||||
var level = name.length - 1;
|
||||
var boundingBox = Potree.GreyhoundLoader.createChildAABB(
|
||||
parentNode.boundingBox, index);
|
||||
parentNode.boundingBox, index);
|
||||
|
||||
var currentNode = new Potree.PointCloudGreyhoundGeometryNode(
|
||||
name, pgg, boundingBox, node.scale, node.offset);
|
||||
name, pgg, boundingBox, node.scale, node.offset);
|
||||
|
||||
currentNode.level = level;
|
||||
currentNode.numPoints = numPoints;
|
||||
@ -245,68 +238,66 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.loadHierarchyThenPoints =
|
||||
};
|
||||
|
||||
if (this.level % this.pcoGeometry.hierarchyStepSize === 0) {
|
||||
var depthBegin = this.level + this.pcoGeometry.baseDepth;
|
||||
var depthEnd = depthBegin + this.pcoGeometry.hierarchyStepSize + 2;
|
||||
var depthBegin = this.level + this.pcoGeometry.baseDepth;
|
||||
var depthEnd = depthBegin + this.pcoGeometry.hierarchyStepSize + 2;
|
||||
|
||||
let bounds = this.greyhoundBounds;
|
||||
let bounds = this.greyhoundBounds;
|
||||
|
||||
var boundsString =
|
||||
bounds.min.x + ',' + bounds.min.y + ',' + bounds.min.z + ',' +
|
||||
bounds.max.x + ',' + bounds.max.y + ',' + bounds.max.z;
|
||||
var boundsString =
|
||||
bounds.min.x + ',' + bounds.min.y + ',' + bounds.min.z + ',' +
|
||||
bounds.max.x + ',' + bounds.max.y + ',' + bounds.max.z;
|
||||
|
||||
var hurl = '' + this.pcoGeometry.serverURL +
|
||||
'hierarchy?bounds=[' + boundsString + ']' +
|
||||
'&depthBegin=' + depthBegin +
|
||||
'&depthEnd=' + depthEnd;
|
||||
'hierarchy?bounds=[' + boundsString + ']' +
|
||||
'&depthBegin=' + depthBegin +
|
||||
'&depthEnd=' + depthEnd;
|
||||
|
||||
if (this.scale) {
|
||||
hurl += '&scale=' + this.scale;
|
||||
}
|
||||
|
||||
if (this.greyhoundOffset) {
|
||||
let offset = this.greyhoundOffset;
|
||||
if (this.greyhoundOffset) {
|
||||
let offset = this.greyhoundOffset;
|
||||
hurl += '&offset=[' + offset.x + ',' + offset.y + ',' + offset.z + ']';
|
||||
}
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', hurl, true);
|
||||
|
||||
var that = this;
|
||||
xhr.onreadystatechange = function() {
|
||||
var that = this;
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
var greyhoundHierarchy = JSON.parse(xhr.responseText) || { };
|
||||
callback(that, greyhoundHierarchy);
|
||||
var greyhoundHierarchy = JSON.parse(xhr.responseText) || { };
|
||||
callback(that, greyhoundHierarchy);
|
||||
} else {
|
||||
console.log(
|
||||
'Failed to load file! HTTP status:', xhr.status,
|
||||
'file:', hurl);
|
||||
console.log(
|
||||
'Failed to load file! HTTP status:', xhr.status,
|
||||
'file:', hurl
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
xhr.send(null);
|
||||
}
|
||||
catch(e) {
|
||||
console.log("fehler beim laden der punktwolke: " + e);
|
||||
} catch (e) {
|
||||
console.log('fehler beim laden der punktwolke: ' + e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getNumPoints = function(){
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.getNumPoints = function () {
|
||||
return this.numPoints;
|
||||
};
|
||||
|
||||
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.dispose = function(){
|
||||
Potree.PointCloudGreyhoundGeometryNode.prototype.dispose = function () {
|
||||
if (this.geometry && this.parent != null) {
|
||||
this.geometry.dispose();
|
||||
this.geometry = null;
|
||||
this.loaded = false;
|
||||
|
||||
//this.dispatchEvent( { type: 'dispose' } );
|
||||
// this.dispatchEvent( { type: 'dispose' } );
|
||||
for (var i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
|
||||
var handler = this.oneTimeDisposeHandlers[i];
|
||||
handler();
|
||||
@ -315,7 +306,6 @@ Potree.PointCloudGreyhoundGeometryNode.prototype.dispose = function(){
|
||||
}
|
||||
};
|
||||
|
||||
//THREE.EventDispatcher.prototype.apply(
|
||||
// THREE.EventDispatcher.prototype.apply(
|
||||
// Potree.PointCloudGreyhoundGeometryNode.prototype);
|
||||
Object.assign( Potree.PointCloudGreyhoundGeometryNode.prototype, THREE.EventDispatcher.prototype );
|
||||
|
||||
Object.assign(Potree.PointCloudGreyhoundGeometryNode.prototype, THREE.EventDispatcher.prototype);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,5 @@
|
||||
|
||||
var nodesLoadTimes = {};
|
||||
|
||||
Potree.PointCloudOctreeGeometry = function(){
|
||||
Potree.PointCloudOctreeGeometry = function () {
|
||||
this.url = null;
|
||||
this.octreeDir = null;
|
||||
this.spacing = 0;
|
||||
@ -14,10 +12,10 @@ Potree.PointCloudOctreeGeometry = function(){
|
||||
this.loader = null;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode = function(name, pcoGeometry, boundingBox){
|
||||
Potree.PointCloudOctreeGeometryNode = function (name, pcoGeometry, boundingBox) {
|
||||
this.id = Potree.PointCloudOctreeGeometryNode.IDCount++;
|
||||
this.name = name;
|
||||
this.index = parseInt(name.charAt(name.length-1));
|
||||
this.index = parseInt(name.charAt(name.length - 1));
|
||||
this.pcoGeometry = pcoGeometry;
|
||||
this.geometry = null;
|
||||
this.boundingBox = boundingBox;
|
||||
@ -33,226 +31,212 @@ Potree.PointCloudOctreeGeometryNode.IDCount = 0;
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype = Object.create(Potree.PointCloudTreeNode.prototype);
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.isGeometryNode = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.isGeometryNode = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getLevel = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getLevel = function () {
|
||||
return this.level;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.isTreeNode = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.isTreeNode = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.isLoaded = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.isLoaded = function () {
|
||||
return this.loaded;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getBoundingSphere = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getBoundingSphere = function () {
|
||||
return this.boundingSphere;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getBoundingBox = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getBoundingBox = function () {
|
||||
return this.boundingBox;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getChildren = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getChildren = function () {
|
||||
var children = [];
|
||||
|
||||
for(var i = 0; i < 8; i++){
|
||||
if(this.children[i]){
|
||||
|
||||
for (var i = 0; i < 8; i++) {
|
||||
if (this.children[i]) {
|
||||
children.push(this.children[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getBoundingBox = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getBoundingBox = function () {
|
||||
return this.boundingBox;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getURL = function(){
|
||||
var url = "";
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getURL = function () {
|
||||
var url = '';
|
||||
|
||||
var version = this.pcoGeometry.loader.version;
|
||||
|
||||
if(version.equalOrHigher("1.5")){
|
||||
url = this.pcoGeometry.octreeDir + "/" + this.getHierarchyPath() + "/" + this.name;
|
||||
}else if(version.equalOrHigher("1.4")){
|
||||
url = this.pcoGeometry.octreeDir + "/" + this.name;
|
||||
}else if(version.upTo("1.3")){
|
||||
url = this.pcoGeometry.octreeDir + "/" + this.name;
|
||||
|
||||
if (version.equalOrHigher('1.5')) {
|
||||
url = this.pcoGeometry.octreeDir + '/' + this.getHierarchyPath() + '/' + this.name;
|
||||
} else if (version.equalOrHigher('1.4')) {
|
||||
url = this.pcoGeometry.octreeDir + '/' + this.name;
|
||||
} else if (version.upTo('1.3')) {
|
||||
url = this.pcoGeometry.octreeDir + '/' + this.name;
|
||||
}
|
||||
|
||||
|
||||
return url;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getHierarchyPath = function(){
|
||||
var path = "r/";
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getHierarchyPath = function () {
|
||||
var path = 'r/';
|
||||
|
||||
var hierarchyStepSize = this.pcoGeometry.hierarchyStepSize;
|
||||
var indices = this.name.substr(1);
|
||||
|
||||
|
||||
var numParts = Math.floor(indices.length / hierarchyStepSize);
|
||||
for(var i = 0; i < numParts; i++){
|
||||
path += indices.substr(i * hierarchyStepSize, hierarchyStepSize) + "/";
|
||||
for (var i = 0; i < numParts; i++) {
|
||||
path += indices.substr(i * hierarchyStepSize, hierarchyStepSize) + '/';
|
||||
}
|
||||
|
||||
path = path.slice(0,-1);
|
||||
|
||||
path = path.slice(0, -1);
|
||||
|
||||
return path;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.addChild = function(child){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.addChild = function (child) {
|
||||
this.children[child.index] = child;
|
||||
child.parent = this;
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.load = function(){
|
||||
if(this.loading === true || this.loaded === true ||this.pcoGeometry.numNodesLoading > 3){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.load = function () {
|
||||
if (this.loading === true || this.loaded === true || this.pcoGeometry.numNodesLoading > 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.loading = true;
|
||||
|
||||
|
||||
this.pcoGeometry.numNodesLoading++;
|
||||
|
||||
|
||||
if(this.pcoGeometry.loader.version.equalOrHigher("1.5")){
|
||||
if((this.level % this.pcoGeometry.hierarchyStepSize) === 0 && this.hasChildren){
|
||||
|
||||
if (this.pcoGeometry.loader.version.equalOrHigher('1.5')) {
|
||||
if ((this.level % this.pcoGeometry.hierarchyStepSize) === 0 && this.hasChildren) {
|
||||
this.loadHierachyThenPoints();
|
||||
}else{
|
||||
} else {
|
||||
this.loadPoints();
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
this.loadPoints();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.loadPoints = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.loadPoints = function () {
|
||||
this.pcoGeometry.loader.load(this);
|
||||
};
|
||||
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints = function(){
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints = function () {
|
||||
var node = this;
|
||||
|
||||
// load hierarchy
|
||||
var callback = function(node, hbuffer){
|
||||
var count = hbuffer.byteLength / 5;
|
||||
var callback = function (node, hbuffer) {
|
||||
var view = new DataView(hbuffer);
|
||||
|
||||
|
||||
var stack = [];
|
||||
var children = view.getUint8(0);
|
||||
var numPoints = view.getUint32(1, true);
|
||||
node.numPoints = numPoints;
|
||||
stack.push({children: children, numPoints: numPoints, name: node.name});
|
||||
|
||||
|
||||
var decoded = [];
|
||||
|
||||
|
||||
var offset = 5;
|
||||
while(stack.length > 0){
|
||||
|
||||
while (stack.length > 0) {
|
||||
var snode = stack.shift();
|
||||
var mask = 1;
|
||||
for(var i = 0; i < 8; i++){
|
||||
if((snode.children & mask) !== 0){
|
||||
var childIndex = i;
|
||||
for (let i = 0; i < 8; i++) {
|
||||
if ((snode.children & mask) !== 0) {
|
||||
var childName = snode.name + i;
|
||||
|
||||
|
||||
var childChildren = view.getUint8(offset);
|
||||
var childNumPoints = view.getUint32(offset + 1, true);
|
||||
|
||||
|
||||
stack.push({children: childChildren, numPoints: childNumPoints, name: childName});
|
||||
|
||||
|
||||
decoded.push({children: childChildren, numPoints: childNumPoints, name: childName});
|
||||
|
||||
|
||||
offset += 5;
|
||||
}
|
||||
|
||||
|
||||
mask = mask * 2;
|
||||
}
|
||||
|
||||
if(offset === hbuffer.byteLength){
|
||||
|
||||
if (offset === hbuffer.byteLength) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//console.log(decoded);
|
||||
|
||||
|
||||
// console.log(decoded);
|
||||
|
||||
var nodes = {};
|
||||
nodes[node.name] = node;
|
||||
var pco = node.pcoGeometry;
|
||||
|
||||
|
||||
for( var i = 0; i < decoded.length; i++){
|
||||
|
||||
for (let i = 0; i < decoded.length; i++) {
|
||||
var name = decoded[i].name;
|
||||
var numPoints = decoded[i].numPoints;
|
||||
var index = parseInt(name.charAt(name.length-1));
|
||||
var parentName = name.substring(0, name.length-1);
|
||||
var decodedNumPoints = decoded[i].numPoints;
|
||||
var index = parseInt(name.charAt(name.length - 1));
|
||||
var parentName = name.substring(0, name.length - 1);
|
||||
var parentNode = nodes[parentName];
|
||||
var level = name.length-1;
|
||||
var level = name.length - 1;
|
||||
var boundingBox = Potree.POCLoader.createChildAABB(parentNode.boundingBox, index);
|
||||
|
||||
|
||||
var currentNode = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
|
||||
currentNode.level = level;
|
||||
currentNode.numPoints = numPoints;
|
||||
currentNode.numPoints = decodedNumPoints;
|
||||
currentNode.hasChildren = decoded[i].children > 0;
|
||||
currentNode.spacing = pco.spacing / Math.pow(2, level);
|
||||
parentNode.addChild(currentNode);
|
||||
nodes[name] = currentNode;
|
||||
}
|
||||
|
||||
|
||||
node.loadPoints();
|
||||
|
||||
};
|
||||
if((node.level % node.pcoGeometry.hierarchyStepSize) === 0){
|
||||
//var hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
|
||||
var hurl = node.pcoGeometry.octreeDir + "/" + node.getHierarchyPath() + "/" + node.name + ".hrc";
|
||||
|
||||
if ((node.level % node.pcoGeometry.hierarchyStepSize) === 0) {
|
||||
// var hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
|
||||
var hurl = node.pcoGeometry.octreeDir + '/' + node.getHierarchyPath() + '/' + node.name + '.hrc';
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', hurl, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
xhr.onreadystatechange = function() {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
var hbuffer = xhr.response;
|
||||
callback(node, hbuffer);
|
||||
} else {
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + hurl);
|
||||
}
|
||||
}
|
||||
};
|
||||
try{
|
||||
try {
|
||||
xhr.send(null);
|
||||
}catch(e){
|
||||
console.log("fehler beim laden der punktwolke: " + e);
|
||||
} catch (e) {
|
||||
console.log('fehler beim laden der punktwolke: ' + e);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getNumPoints = function(){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.getNumPoints = function () {
|
||||
return this.numPoints;
|
||||
};
|
||||
|
||||
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.dispose = function(){
|
||||
if(this.geometry && this.parent != null){
|
||||
Potree.PointCloudOctreeGeometryNode.prototype.dispose = function () {
|
||||
if (this.geometry && this.parent != null) {
|
||||
this.geometry.dispose();
|
||||
this.geometry = null;
|
||||
this.loaded = false;
|
||||
|
||||
//this.dispatchEvent( { type: 'dispose' } );
|
||||
for(var i = 0; i < this.oneTimeDisposeHandlers.length; i++){
|
||||
|
||||
// this.dispatchEvent( { type: 'dispose' } );
|
||||
for (var i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
|
||||
var handler = this.oneTimeDisposeHandlers[i];
|
||||
handler();
|
||||
}
|
||||
@ -260,5 +244,5 @@ Potree.PointCloudOctreeGeometryNode.prototype.dispose = function(){
|
||||
}
|
||||
};
|
||||
|
||||
//THREE.EventDispatcher.prototype.apply( Potree.PointCloudOctreeGeometryNode.prototype );
|
||||
Object.assign( Potree.PointCloudOctreeGeometryNode.prototype, THREE.EventDispatcher.prototype );
|
||||
// THREE.EventDispatcher.prototype.apply( Potree.PointCloudOctreeGeometryNode.prototype );
|
||||
Object.assign(Potree.PointCloudOctreeGeometryNode.prototype, THREE.EventDispatcher.prototype);
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
|
||||
//
|
||||
// index is in order xyzxyzxyz
|
||||
//
|
||||
// index is in order xyzxyzxyz
|
||||
//
|
||||
|
||||
Potree.DEMNode = class DEMNode{
|
||||
constructor(name, box, tileSize){
|
||||
Potree.DEMNode = class DEMNode {
|
||||
constructor (name, box, tileSize) {
|
||||
this.name = name;
|
||||
this.box = box;
|
||||
this.tileSize = tileSize;
|
||||
@ -12,159 +12,154 @@ Potree.DEMNode = class DEMNode{
|
||||
this.data = new Float32Array(tileSize * tileSize);
|
||||
this.data.fill(-Infinity);
|
||||
this.children = [];
|
||||
|
||||
|
||||
this.mipMap = [this.data];
|
||||
this.mipMapNeedsUpdate = true;
|
||||
}
|
||||
|
||||
createMipMap(){
|
||||
|
||||
createMipMap () {
|
||||
this.mipMap = [this.data];
|
||||
|
||||
|
||||
let sourceSize = this.tileSize;
|
||||
let mipSize = parseInt(sourceSize / 2);
|
||||
let mipSource = this.data;
|
||||
while(mipSize > 1){
|
||||
while (mipSize > 1) {
|
||||
let mipData = new Float32Array(mipSize * mipSize);
|
||||
|
||||
for(let i = 0; i < mipSize; i++){
|
||||
for(let j = 0; j < mipSize; j++){
|
||||
let h00 = mipSource[2*i+0 + 2*j*sourceSize];
|
||||
let h01 = mipSource[2*i+0 + 2*j*sourceSize + sourceSize];
|
||||
let h10 = mipSource[2*i+1 + 2*j*sourceSize];
|
||||
let h11 = mipSource[2*i+1 + 2*j*sourceSize + sourceSize];
|
||||
|
||||
|
||||
for (let i = 0; i < mipSize; i++) {
|
||||
for (let j = 0; j < mipSize; j++) {
|
||||
let h00 = mipSource[2 * i + 0 + 2 * j * sourceSize];
|
||||
let h01 = mipSource[2 * i + 0 + 2 * j * sourceSize + sourceSize];
|
||||
let h10 = mipSource[2 * i + 1 + 2 * j * sourceSize];
|
||||
let h11 = mipSource[2 * i + 1 + 2 * j * sourceSize + sourceSize];
|
||||
|
||||
let [height, weight] = [0, 0];
|
||||
|
||||
if(isFinite(h00)){height += h00; weight += 1};
|
||||
if(isFinite(h01)){height += h01; weight += 1};
|
||||
if(isFinite(h10)){height += h10; weight += 1};
|
||||
if(isFinite(h11)){height += h11; weight += 1};
|
||||
|
||||
|
||||
if (isFinite(h00)) { height += h00; weight += 1; };
|
||||
if (isFinite(h01)) { height += h01; weight += 1; };
|
||||
if (isFinite(h10)) { height += h10; weight += 1; };
|
||||
if (isFinite(h11)) { height += h11; weight += 1; };
|
||||
|
||||
height = height / weight;
|
||||
|
||||
//let hs = [h00, h01, h10, h11].filter(h => isFinite(h));
|
||||
//let height = hs.reduce( (a, v, i) => a + v, 0) / hs.length;
|
||||
|
||||
|
||||
// let hs = [h00, h01, h10, h11].filter(h => isFinite(h));
|
||||
// let height = hs.reduce( (a, v, i) => a + v, 0) / hs.length;
|
||||
|
||||
mipData[i + j * mipSize] = height;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.mipMap.push(mipData);
|
||||
|
||||
|
||||
mipSource = mipData;
|
||||
sourceSize = mipSize;
|
||||
mipSize = parseInt(mipSize / 2);
|
||||
}
|
||||
|
||||
|
||||
this.mipMapNeedsUpdate = false;
|
||||
}
|
||||
|
||||
uv(position){
|
||||
|
||||
uv (position) {
|
||||
let boxSize = this.box.getSize();
|
||||
|
||||
|
||||
let u = (position.x - this.box.min.x) / boxSize.x;
|
||||
let v = (position.y - this.box.min.y) / boxSize.y;
|
||||
|
||||
|
||||
return [u, v];
|
||||
}
|
||||
|
||||
heightAtMipMapLevel(position, mipMapLevel){
|
||||
|
||||
heightAtMipMapLevel (position, mipMapLevel) {
|
||||
let uv = this.uv(position);
|
||||
|
||||
|
||||
let tileSize = parseInt(this.tileSize / parseInt(2 ** mipMapLevel));
|
||||
let data = this.mipMap[mipMapLevel];
|
||||
|
||||
|
||||
let i = Math.min(uv[0] * tileSize, tileSize - 1);
|
||||
let j = Math.min(uv[1] * tileSize, tileSize - 1);
|
||||
|
||||
|
||||
let a = i % 1;
|
||||
let b = j % 1;
|
||||
|
||||
|
||||
let [i0, i1] = [Math.floor(i), Math.ceil(i)];
|
||||
let [j0, j1] = [Math.floor(j), Math.ceil(j)];
|
||||
|
||||
|
||||
let h00 = data[i0 + tileSize * j0];
|
||||
let h01 = data[i0 + tileSize * j1];
|
||||
let h10 = data[i1 + tileSize * j0];
|
||||
let h11 = data[i1 + tileSize * j1];
|
||||
|
||||
|
||||
let wh00 = isFinite(h00) ? (1 - a) * (1 - b) : 0;
|
||||
let wh01 = isFinite(h01) ? (1 - a) * b : 0;
|
||||
let wh10 = isFinite(h10) ? a * (1 - b) : 0;
|
||||
let wh11 = isFinite(h11) ? a * b : 0;
|
||||
|
||||
|
||||
let wsum = wh00 + wh01 + wh10 + wh11;
|
||||
wh00 = wh00 / wsum;
|
||||
wh01 = wh01 / wsum;
|
||||
wh10 = wh10 / wsum;
|
||||
wh11 = wh11 / wsum;
|
||||
|
||||
if(wsum === 0){
|
||||
|
||||
if (wsum === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
let h = 0;
|
||||
|
||||
if(isFinite(h00)) h += h00 * wh00;
|
||||
if(isFinite(h01)) h += h01 * wh01;
|
||||
if(isFinite(h10)) h += h10 * wh10;
|
||||
if(isFinite(h11)) h += h11 * wh11;
|
||||
|
||||
|
||||
if (isFinite(h00)) h += h00 * wh00;
|
||||
if (isFinite(h01)) h += h01 * wh01;
|
||||
if (isFinite(h10)) h += h10 * wh10;
|
||||
if (isFinite(h11)) h += h11 * wh11;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
height(position){
|
||||
|
||||
|
||||
height (position) {
|
||||
let h = null;
|
||||
|
||||
for(let i = 0; i < this.mipMap.length; i++){
|
||||
|
||||
for (let i = 0; i < this.mipMap.length; i++) {
|
||||
h = this.heightAtMipMapLevel(position, i);
|
||||
|
||||
if(h !== null){
|
||||
|
||||
if (h !== null) {
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
traverse(callback, level = 0){
|
||||
callback(this, level);
|
||||
|
||||
for(let child of this.children.filter(c => c !== undefined)){
|
||||
child.traverse(callback, level + 1);
|
||||
|
||||
traverse (handler, level = 0) {
|
||||
handler(this, level);
|
||||
|
||||
for (let child of this.children.filter(c => c !== undefined)) {
|
||||
child.traverse(handler, level + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Potree.DEM = class DEM{
|
||||
constructor(pointcloud){
|
||||
|
||||
Potree.DEM = class DEM {
|
||||
constructor (pointcloud) {
|
||||
this.pointcloud = pointcloud;
|
||||
this.matrix = null;
|
||||
this.boundingBox = null;
|
||||
this.tileSize = 64;
|
||||
this.root = null;
|
||||
this.version = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// expands the tree to all nodes that intersect <box> at <level>
|
||||
// returns the intersecting nodes at <level>
|
||||
expandAndFindByBox(box, level){
|
||||
|
||||
if(level === 0){
|
||||
expandAndFindByBox (box, level) {
|
||||
if (level === 0) {
|
||||
return [this.root];
|
||||
}
|
||||
|
||||
|
||||
let result = [];
|
||||
let stack = [this.root];
|
||||
|
||||
while(stack.length > 0){
|
||||
|
||||
|
||||
while (stack.length > 0) {
|
||||
let node = stack.pop();
|
||||
let nodeBoxSize = node.box.getSize();
|
||||
|
||||
|
||||
// check which children intersect by transforming min/max to quadrants
|
||||
let min = {
|
||||
x: (box.min.x - node.box.min.x) / nodeBoxSize.x,
|
||||
@ -172,196 +167,184 @@ Potree.DEM = class DEM{
|
||||
let max = {
|
||||
x: (box.max.x - node.box.max.x) / nodeBoxSize.x,
|
||||
y: (box.max.y - node.box.max.y) / nodeBoxSize.y};
|
||||
|
||||
|
||||
min.x = min.x < 0.5 ? 0 : 1;
|
||||
min.y = min.y < 0.5 ? 0 : 1;
|
||||
max.x = max.x < 0.5 ? 0 : 1;
|
||||
max.y = max.y < 0.5 ? 0 : 1;
|
||||
|
||||
|
||||
let childIndices;
|
||||
if(min.x === 0 && min.y === 0 && max.x === 1 && max.y === 1){
|
||||
if (min.x === 0 && min.y === 0 && max.x === 1 && max.y === 1) {
|
||||
childIndices = [0, 1, 2, 3];
|
||||
}else if(min.x === max.x && min.y == max.y){
|
||||
} else if (min.x === max.x && min.y === max.y) {
|
||||
childIndices = [(min.x << 1) | min.y];
|
||||
}else{
|
||||
} else {
|
||||
childIndices = [(min.x << 1) | min.y, (max.x << 1) | max.y];
|
||||
}
|
||||
|
||||
for(let index of childIndices){
|
||||
if(node.children[index] === undefined){
|
||||
|
||||
for (let index of childIndices) {
|
||||
if (node.children[index] === undefined) {
|
||||
let childBox = node.box.clone();
|
||||
|
||||
if((index & 2) > 0){
|
||||
|
||||
if ((index & 2) > 0) {
|
||||
childBox.min.x += nodeBoxSize.x / 2.0;
|
||||
}else{
|
||||
} else {
|
||||
childBox.max.x -= nodeBoxSize.x / 2.0;
|
||||
}
|
||||
|
||||
if((index & 1) > 0){
|
||||
|
||||
if ((index & 1) > 0) {
|
||||
childBox.min.y += nodeBoxSize.y / 2.0;
|
||||
}else{
|
||||
} else {
|
||||
childBox.max.y -= nodeBoxSize.y / 2.0;
|
||||
}
|
||||
|
||||
|
||||
let child = new Potree.DEMNode(node.name + index, childBox, this.tileSize);
|
||||
node.children[index] = child;
|
||||
}
|
||||
|
||||
|
||||
let child = node.children[index];
|
||||
|
||||
if(child.level < level){
|
||||
|
||||
if (child.level < level) {
|
||||
stack.push(child);
|
||||
}else{
|
||||
} else {
|
||||
result.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
childIndex(uv){
|
||||
|
||||
childIndex (uv) {
|
||||
let [x, y] = uv.map(n => n < 0.5 ? 0 : 1);
|
||||
|
||||
|
||||
let index = (x << 1) | y;
|
||||
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
height(position){
|
||||
|
||||
//return this.root.height(position);
|
||||
|
||||
if(!this.root){
|
||||
|
||||
height (position) {
|
||||
// return this.root.height(position);
|
||||
|
||||
if (!this.root) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
let height = null;
|
||||
let list = [this.root];
|
||||
while(true){
|
||||
while (true) {
|
||||
let node = list[list.length - 1];
|
||||
|
||||
|
||||
let currentHeight = node.height(position);
|
||||
|
||||
if(currentHeight !== null){
|
||||
|
||||
if (currentHeight !== null) {
|
||||
height = currentHeight;
|
||||
}
|
||||
|
||||
|
||||
let uv = node.uv(position);
|
||||
let childIndex = this.childIndex(uv);
|
||||
|
||||
if(node.children[childIndex]){
|
||||
|
||||
if (node.children[childIndex]) {
|
||||
list.push(node.children[childIndex]);
|
||||
}else{
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return height + this.pointcloud.position.z;
|
||||
}
|
||||
|
||||
update(visibleNodes){
|
||||
|
||||
if(Potree.getDEMWorkerInstance().working){
|
||||
|
||||
update (visibleNodes) {
|
||||
if (Potree.getDEMWorkerInstance().working) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// check if point cloud transformation changed
|
||||
if(this.matrix === null || !this.matrix.equals(this.pointcloud.matrixWorld)){
|
||||
if (this.matrix === null || !this.matrix.equals(this.pointcloud.matrixWorld)) {
|
||||
this.matrix = this.pointcloud.matrixWorld.clone();
|
||||
this.boundingBox = this.pointcloud.boundingBox.clone().applyMatrix4(this.matrix);
|
||||
this.root = new Potree.DEMNode("r", this.boundingBox, this.tileSize);
|
||||
this.root = new Potree.DEMNode('r', this.boundingBox, this.tileSize);
|
||||
this.version++;
|
||||
}
|
||||
|
||||
|
||||
// find node to update
|
||||
let node = null;
|
||||
for(let vn of visibleNodes){
|
||||
if(vn.demVersion === undefined || vn.demVersion < this.version){
|
||||
for (let vn of visibleNodes) {
|
||||
if (vn.demVersion === undefined || vn.demVersion < this.version) {
|
||||
node = vn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(node === null){
|
||||
if (node === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// update node
|
||||
let projectedBox = node.getBoundingBox().clone().applyMatrix4(this.matrix);
|
||||
let projectedBoxSize = projectedBox.getSize();
|
||||
|
||||
|
||||
let targetNodes = this.expandAndFindByBox(projectedBox, node.getLevel());
|
||||
node.demVersion = this.version;
|
||||
|
||||
|
||||
Potree.getDEMWorkerInstance().onmessage = (e) => {
|
||||
|
||||
let data = new Float32Array(e.data.dem.data);
|
||||
|
||||
for(let demNode of targetNodes){
|
||||
|
||||
|
||||
for (let demNode of targetNodes) {
|
||||
let boxSize = demNode.box.getSize();
|
||||
|
||||
for(let i = 0; i < this.tileSize; i++){
|
||||
for(let j = 0; j < this.tileSize; j++){
|
||||
|
||||
|
||||
for (let i = 0; i < this.tileSize; i++) {
|
||||
for (let j = 0; j < this.tileSize; j++) {
|
||||
let u = (i / (this.tileSize - 1));
|
||||
let v = (j / (this.tileSize - 1));
|
||||
|
||||
|
||||
let x = demNode.box.min.x + u * boxSize.x;
|
||||
let y = demNode.box.min.y + v * boxSize.y;
|
||||
|
||||
|
||||
let ix = this.tileSize * (x - projectedBox.min.x) / projectedBoxSize.x;
|
||||
let iy = this.tileSize * (y - projectedBox.min.y) / projectedBoxSize.y;
|
||||
|
||||
if(ix < 0 || ix > this.tileSize){
|
||||
|
||||
if (ix < 0 || ix > this.tileSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(iy < 0 || iy > this.tileSize){
|
||||
|
||||
if (iy < 0 || iy > this.tileSize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
ix = Math.min(Math.floor(ix), this.tileSize - 1);
|
||||
iy = Math.min(Math.floor(iy), this.tileSize - 1);
|
||||
|
||||
|
||||
demNode.data[i + this.tileSize * j] = data[ix + this.tileSize * iy];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
demNode.createMipMap();
|
||||
demNode.mipMapNeedsUpdate = true;
|
||||
|
||||
|
||||
Potree.getDEMWorkerInstance().working = false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO only works somewhat if there is no rotation to the point cloud
|
||||
|
||||
//let target = targetNodes[0];
|
||||
//target.data = new Float32Array(data);
|
||||
|
||||
// TODO only works somewhat if there is no rotation to the point cloud
|
||||
|
||||
// let target = targetNodes[0];
|
||||
// target.data = new Float32Array(data);
|
||||
//
|
||||
//
|
||||
////node.dem = e.data.dem;
|
||||
//
|
||||
//Potree.getDEMWorkerInstance().working = false;
|
||||
/// /node.dem = e.data.dem;
|
||||
//
|
||||
//{ // create scene objects for debugging
|
||||
// Potree.getDEMWorkerInstance().working = false;
|
||||
//
|
||||
// { // create scene objects for debugging
|
||||
// //for(let demNode of targetNodes){
|
||||
// var bb = new Potree.Box3Helper(box);
|
||||
// viewer.scene.scene.add(bb);
|
||||
//
|
||||
//
|
||||
// createDEMMesh(this, target);
|
||||
// //}
|
||||
//
|
||||
//}
|
||||
//
|
||||
// }
|
||||
};
|
||||
|
||||
|
||||
let position = node.geometryNode.geometry.attributes.position.array;
|
||||
let message = {
|
||||
boundingBox: {
|
||||
@ -373,61 +356,47 @@ Potree.DEM = class DEM{
|
||||
let transferables = [message.position];
|
||||
Potree.getDEMWorkerInstance().working = true;
|
||||
Potree.getDEMWorkerInstance().postMessage(message, transferables);
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.PointCloudTreeNode = class{
|
||||
|
||||
constructor(){
|
||||
|
||||
}
|
||||
|
||||
getChildren(){
|
||||
throw "override function";
|
||||
}
|
||||
|
||||
getBoundingBox(){
|
||||
throw "override function";
|
||||
Potree.PointCloudTreeNode = class {
|
||||
getChildren () {
|
||||
throw new Error('override function');
|
||||
}
|
||||
|
||||
isLoaded(){
|
||||
throw "override function";
|
||||
}
|
||||
|
||||
isGeometryNode(){
|
||||
throw "override function";
|
||||
}
|
||||
|
||||
isTreeNode(){
|
||||
throw "override function";
|
||||
}
|
||||
|
||||
getLevel(){
|
||||
throw "override function";
|
||||
getBoundingBox () {
|
||||
throw new Error('override function');
|
||||
}
|
||||
|
||||
getBoundingSphere(){
|
||||
throw "override function";
|
||||
isLoaded () {
|
||||
throw new Error('override function');
|
||||
}
|
||||
|
||||
isGeometryNode () {
|
||||
throw new Error('override function');
|
||||
}
|
||||
|
||||
isTreeNode () {
|
||||
throw new Error('override function');
|
||||
}
|
||||
|
||||
getLevel () {
|
||||
throw new Error('override function');
|
||||
}
|
||||
|
||||
getBoundingSphere () {
|
||||
throw new Error('override function');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Potree.PointCloudTree = class PointCloudTree extends THREE.Object3D{
|
||||
|
||||
constructor(){
|
||||
Potree.PointCloudTree = class PointCloudTree extends THREE.Object3D {
|
||||
constructor () {
|
||||
super();
|
||||
|
||||
|
||||
this.dem = new Potree.DEM(this);
|
||||
}
|
||||
|
||||
initialized(){
|
||||
|
||||
initialized () {
|
||||
return this.root !== null;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
702
src/Potree.js
702
src/Potree.js
File diff suppressed because it is too large
Load Diff
@ -1,21 +1,18 @@
|
||||
|
||||
|
||||
|
||||
Potree.ProfileData = class ProfileData{
|
||||
|
||||
constructor(profile){
|
||||
Potree.ProfileData = class ProfileData {
|
||||
constructor (profile) {
|
||||
this.profile = profile;
|
||||
|
||||
|
||||
this.segments = [];
|
||||
this.boundingBox = new THREE.Box3();
|
||||
|
||||
for(let i = 0; i < profile.points.length - 1; i++){
|
||||
|
||||
for (let i = 0; i < profile.points.length - 1; i++) {
|
||||
let start = profile.points[i];
|
||||
let end = profile.points[i+1];
|
||||
|
||||
let end = profile.points[i + 1];
|
||||
|
||||
let startGround = new THREE.Vector3(start.x, start.y, 0);
|
||||
let endGround = new THREE.Vector3(end.x, end.y, 0);
|
||||
|
||||
|
||||
let center = new THREE.Vector3().addVectors(endGround, startGround).multiplyScalar(0.5);
|
||||
let length = startGround.distanceTo(endGround);
|
||||
let side = new THREE.Vector3().subVectors(endGround, startGround).normalize();
|
||||
@ -24,7 +21,7 @@ Potree.ProfileData = class ProfileData{
|
||||
let N = forward;
|
||||
let cutPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(N, startGround);
|
||||
let halfPlane = new THREE.Plane().setFromNormalAndCoplanarPoint(side, center);
|
||||
|
||||
|
||||
let segment = {
|
||||
start: start,
|
||||
end: end,
|
||||
@ -33,26 +30,23 @@ Potree.ProfileData = class ProfileData{
|
||||
length: length,
|
||||
points: new Potree.Points()
|
||||
};
|
||||
|
||||
|
||||
this.segments.push(segment);
|
||||
}
|
||||
}
|
||||
|
||||
size(){
|
||||
|
||||
|
||||
size () {
|
||||
let size = 0;
|
||||
for(let segment of this.segments){
|
||||
for (let segment of this.segments) {
|
||||
size += segment.points.numPoints;
|
||||
}
|
||||
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.ProfileRequest = class ProfileRequest{
|
||||
|
||||
constructor(pointcloud, profile, maxDepth, callback){
|
||||
Potree.ProfileRequest = class ProfileRequest {
|
||||
constructor (pointcloud, profile, maxDepth, callback) {
|
||||
this.pointcloud = pointcloud;
|
||||
this.profile = profile;
|
||||
this.maxDepth = maxDepth || Number.MAX_VALUE;
|
||||
@ -61,214 +55,199 @@ Potree.ProfileRequest = class ProfileRequest{
|
||||
this.pointsServed = 0;
|
||||
this.highestLevelServed = 0;
|
||||
|
||||
this.priorityQueue = new BinaryHeap(function(x){return 1 / x.weight;});
|
||||
|
||||
this.priorityQueue = new BinaryHeap(function (x) { return 1 / x.weight; });
|
||||
|
||||
this.initialize();
|
||||
}
|
||||
|
||||
initialize(){
|
||||
initialize () {
|
||||
this.priorityQueue.push({node: this.pointcloud.pcoGeometry.root, weight: 1});
|
||||
this.traverse(this.pointcloud.pcoGeometry.root);
|
||||
};
|
||||
|
||||
|
||||
// traverse the node and add intersecting descendants to queue
|
||||
traverse(node){
|
||||
|
||||
traverse (node) {
|
||||
let stack = [];
|
||||
for(let i = 0; i < 8; i++){
|
||||
for (let i = 0; i < 8; i++) {
|
||||
let child = node.children[i];
|
||||
if(child && this.pointcloud.nodeIntersectsProfile(child, this.profile)){
|
||||
if (child && this.pointcloud.nodeIntersectsProfile(child, this.profile)) {
|
||||
stack.push(child);
|
||||
}
|
||||
}
|
||||
|
||||
while(stack.length > 0){
|
||||
|
||||
while (stack.length > 0) {
|
||||
let node = stack.pop();
|
||||
let weight = node.boundingSphere.radius;
|
||||
|
||||
|
||||
this.priorityQueue.push({node: node, weight: weight});
|
||||
|
||||
|
||||
// add children that intersect the cutting plane
|
||||
if(node.level < this.maxDepth){
|
||||
for(let i = 0; i < 8; i++){
|
||||
if (node.level < this.maxDepth) {
|
||||
for (let i = 0; i < 8; i++) {
|
||||
let child = node.children[i];
|
||||
if(child && this.pointcloud.nodeIntersectsProfile(child, this.profile)){
|
||||
if (child && this.pointcloud.nodeIntersectsProfile(child, this.profile)) {
|
||||
stack.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update(){
|
||||
|
||||
|
||||
update () {
|
||||
// load nodes in queue
|
||||
// if hierarchy expands, also load nodes from expanded hierarchy
|
||||
// once loaded, add data to this.points and remove node from queue
|
||||
// only evaluate 1-50 nodes per frame to maintain responsiveness
|
||||
|
||||
|
||||
let maxNodesPerUpdate = 1;
|
||||
let intersectedNodes = [];
|
||||
|
||||
for(let i = 0; i < Math.min(maxNodesPerUpdate, this.priorityQueue.size()); i++){
|
||||
|
||||
for (let i = 0; i < Math.min(maxNodesPerUpdate, this.priorityQueue.size()); i++) {
|
||||
let element = this.priorityQueue.pop();
|
||||
let node = element.node;
|
||||
|
||||
|
||||
if(node.loaded){
|
||||
|
||||
if (node.loaded) {
|
||||
// add points to result
|
||||
intersectedNodes.push(node);
|
||||
Potree.getLRU().touch(node);
|
||||
this.highestLevelServed = node.getLevel();
|
||||
|
||||
if((node.level % node.pcoGeometry.hierarchyStepSize) === 0 && node.hasChildren){
|
||||
|
||||
if ((node.level % node.pcoGeometry.hierarchyStepSize) === 0 && node.hasChildren) {
|
||||
this.traverse(node);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
node.load();
|
||||
this.priorityQueue.push(element);
|
||||
}
|
||||
}
|
||||
|
||||
if(intersectedNodes.length > 0){
|
||||
|
||||
if (intersectedNodes.length > 0) {
|
||||
this.getPointsInsideProfile(intersectedNodes, this.temporaryResult);
|
||||
if(this.temporaryResult.size() > 100){
|
||||
if (this.temporaryResult.size() > 100) {
|
||||
this.pointsServed += this.temporaryResult.size();
|
||||
this.callback.onProgress({request: this, points: this.temporaryResult});
|
||||
this.temporaryResult = new Potree.ProfileData(this.profile);
|
||||
}
|
||||
}
|
||||
|
||||
if(this.priorityQueue.size() === 0){
|
||||
|
||||
if (this.priorityQueue.size() === 0) {
|
||||
// we're done! inform callback and remove from pending requests
|
||||
|
||||
if(this.temporaryResult.size() > 0){
|
||||
if (this.temporaryResult.size() > 0) {
|
||||
this.pointsServed += this.temporaryResult.size();
|
||||
this.callback.onProgress({request: this, points: this.temporaryResult});
|
||||
this.temporaryResult = new Potree.ProfileData(this.profile);
|
||||
}
|
||||
|
||||
|
||||
this.callback.onFinish({request: this});
|
||||
|
||||
|
||||
let index = this.pointcloud.profileRequests.indexOf(this);
|
||||
if(index >= 0){
|
||||
if (index >= 0) {
|
||||
this.pointcloud.profileRequests.splice(index, 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
getPointsInsideProfile(nodes, target){
|
||||
|
||||
|
||||
getPointsInsideProfile (nodes, target) {
|
||||
let totalMileage = 0;
|
||||
|
||||
|
||||
for(let segment of target.segments){
|
||||
|
||||
for(let node of nodes){
|
||||
|
||||
for (let segment of target.segments) {
|
||||
for (let node of nodes) {
|
||||
let geometry = node.geometry;
|
||||
let positions = geometry.attributes.position;
|
||||
let p = positions.array;
|
||||
let numPoints = node.numPoints;
|
||||
|
||||
|
||||
let sv = new THREE.Vector3().subVectors(segment.end, segment.start).setZ(0);
|
||||
let segmentDir = sv.clone().normalize();
|
||||
|
||||
|
||||
let accepted = [];
|
||||
let mileage = [];
|
||||
let acceptedPositions = [];
|
||||
let points = new Potree.Points();
|
||||
|
||||
|
||||
let nodeMatrix = new THREE.Matrix4().makeTranslation(...node.boundingBox.min.toArray());
|
||||
|
||||
|
||||
let matrix = new THREE.Matrix4().multiplyMatrices(
|
||||
this.pointcloud.matrixWorld, nodeMatrix);
|
||||
|
||||
for(let i = 0; i < numPoints; i++){
|
||||
let pos = new THREE.Vector3(p[3*i], p[3*i+1], p[3*i+2]);
|
||||
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
let pos = new THREE.Vector3(p[3 * i], p[3 * i + 1], p[3 * i + 2]);
|
||||
pos.applyMatrix4(matrix);
|
||||
let distance = Math.abs(segment.cutPlane.distanceToPoint(pos));
|
||||
let centerDistance = Math.abs(segment.halfPlane.distanceToPoint(pos));
|
||||
|
||||
if(distance < this.profile.width / 2 && centerDistance < segment.length / 2){
|
||||
|
||||
|
||||
if (distance < this.profile.width / 2 && centerDistance < segment.length / 2) {
|
||||
let svp = new THREE.Vector3().subVectors(pos, segment.start);
|
||||
let localMileage = segmentDir.dot(svp);
|
||||
|
||||
|
||||
accepted.push(i);
|
||||
mileage.push(localMileage + totalMileage);
|
||||
points.boundingBox.expandByPoint(pos);
|
||||
|
||||
|
||||
acceptedPositions.push(pos.x);
|
||||
acceptedPositions.push(pos.y);
|
||||
acceptedPositions.push(pos.z);
|
||||
}
|
||||
}
|
||||
|
||||
for(let attribute of Object.keys(geometry.attributes).filter(a => a !== "indices")) {
|
||||
|
||||
for (let attribute of Object.keys(geometry.attributes).filter(a => a !== 'indices')) {
|
||||
let bufferedAttribute = geometry.attributes[attribute];
|
||||
let type = bufferedAttribute.array.constructor;
|
||||
|
||||
let Type = bufferedAttribute.array.constructor;
|
||||
|
||||
let filteredBuffer = null;
|
||||
|
||||
if(attribute === "position"){
|
||||
filteredBuffer = new type(acceptedPositions);
|
||||
}else{
|
||||
filteredBuffer = new type(accepted.length * bufferedAttribute.itemSize);
|
||||
|
||||
for(let i = 0; i < accepted.length; i++){
|
||||
|
||||
if (attribute === 'position') {
|
||||
filteredBuffer = new Type(acceptedPositions);
|
||||
} else {
|
||||
filteredBuffer = new Type(accepted.length * bufferedAttribute.itemSize);
|
||||
|
||||
for (let i = 0; i < accepted.length; i++) {
|
||||
let index = accepted[i];
|
||||
|
||||
|
||||
filteredBuffer.set(
|
||||
bufferedAttribute.array.subarray(
|
||||
bufferedAttribute.itemSize * index,
|
||||
bufferedAttribute.itemSize * index,
|
||||
bufferedAttribute.itemSize * index + bufferedAttribute.itemSize),
|
||||
bufferedAttribute.itemSize * i)
|
||||
bufferedAttribute.itemSize * i);
|
||||
}
|
||||
}
|
||||
points.data[attribute] = filteredBuffer;
|
||||
|
||||
|
||||
}
|
||||
|
||||
points.data["mileage"] = new Float64Array(mileage);
|
||||
|
||||
points.data['mileage'] = new Float64Array(mileage);
|
||||
points.numPoints = accepted.length;
|
||||
|
||||
|
||||
segment.points.add(points);
|
||||
|
||||
}
|
||||
|
||||
|
||||
totalMileage += segment.length;
|
||||
}
|
||||
|
||||
for(let segment of target.segments){
|
||||
|
||||
for (let segment of target.segments) {
|
||||
target.boundingBox.union(segment.points.boundingBox);
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
finishLevelThenCancel(){
|
||||
if(this.cancelRequested){
|
||||
|
||||
finishLevelThenCancel () {
|
||||
if (this.cancelRequested) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.maxDepth = this.highestLevelServed + 1;
|
||||
this.cancelRequested = true;
|
||||
|
||||
|
||||
console.log(`maxDepth: ${this.maxDepth}`);
|
||||
};
|
||||
|
||||
cancel(){
|
||||
|
||||
cancel () {
|
||||
this.callback.onCancel();
|
||||
|
||||
this.priorityQueue = new BinaryHeap(function(x){return 1 / x.weight;});
|
||||
|
||||
|
||||
this.priorityQueue = new BinaryHeap(function (x) { return 1 / x.weight; });
|
||||
|
||||
let index = this.pointcloud.profileRequests.indexOf(this);
|
||||
if(index >= 0){
|
||||
if (index >= 0) {
|
||||
this.pointcloud.profileRequests.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -2,131 +2,124 @@
|
||||
* adapted from http://stemkoski.github.io/Three.js/Sprite-Text-Labels.html
|
||||
*/
|
||||
|
||||
Potree.TextSprite = function(text){
|
||||
|
||||
Potree.TextSprite = function (text) {
|
||||
THREE.Object3D.call(this);
|
||||
|
||||
var scope = this;
|
||||
|
||||
var texture = new THREE.Texture();
|
||||
texture.minFilter = THREE.LinearFilter;
|
||||
texture.magFilter = THREE.LinearFilter;
|
||||
var spriteMaterial = new THREE.SpriteMaterial( {
|
||||
map: texture,
|
||||
//useScreenCoordinates: false,
|
||||
var spriteMaterial = new THREE.SpriteMaterial({
|
||||
map: texture,
|
||||
// useScreenCoordinates: false,
|
||||
depthTest: false,
|
||||
depthWrite: false} );
|
||||
|
||||
depthWrite: false});
|
||||
|
||||
this.material = spriteMaterial;
|
||||
this.sprite = new THREE.Sprite(spriteMaterial);
|
||||
this.add(this.sprite);
|
||||
|
||||
//THREE.Sprite.call(this, spriteMaterial);
|
||||
|
||||
|
||||
// THREE.Sprite.call(this, spriteMaterial);
|
||||
|
||||
this.borderThickness = 4;
|
||||
this.fontface = "Arial";
|
||||
this.fontface = 'Arial';
|
||||
this.fontsize = 28;
|
||||
this.borderColor = { r:0, g:0, b:0, a:1.0 };
|
||||
this.backgroundColor = { r:255, g:255, b:255, a:1.0 };
|
||||
this.borderColor = { r: 0, g: 0, b: 0, a: 1.0 };
|
||||
this.backgroundColor = { r: 255, g: 255, b: 255, a: 1.0 };
|
||||
this.textColor = {r: 255, g: 255, b: 255, a: 1.0};
|
||||
this.text = "";
|
||||
|
||||
this.text = '';
|
||||
|
||||
this.setText(text);
|
||||
};
|
||||
|
||||
Potree.TextSprite.prototype = new THREE.Object3D();
|
||||
|
||||
Potree.TextSprite.prototype.setText = function(text){
|
||||
if(this.text !== text){
|
||||
Potree.TextSprite.prototype.setText = function (text) {
|
||||
if (this.text !== text) {
|
||||
this.text = text;
|
||||
|
||||
|
||||
this.update();
|
||||
}
|
||||
};
|
||||
|
||||
Potree.TextSprite.prototype.setTextColor = function(color){
|
||||
Potree.TextSprite.prototype.setTextColor = function (color) {
|
||||
this.textColor = color;
|
||||
|
||||
|
||||
this.update();
|
||||
};
|
||||
|
||||
Potree.TextSprite.prototype.setBorderColor = function(color){
|
||||
Potree.TextSprite.prototype.setBorderColor = function (color) {
|
||||
this.borderColor = color;
|
||||
|
||||
|
||||
this.update();
|
||||
};
|
||||
|
||||
Potree.TextSprite.prototype.setBackgroundColor = function(color){
|
||||
Potree.TextSprite.prototype.setBackgroundColor = function (color) {
|
||||
this.backgroundColor = color;
|
||||
|
||||
|
||||
this.update();
|
||||
};
|
||||
|
||||
Potree.TextSprite.prototype.update = function(){
|
||||
|
||||
Potree.TextSprite.prototype.update = function () {
|
||||
var canvas = document.createElement('canvas');
|
||||
var context = canvas.getContext('2d');
|
||||
context.font = "Bold " + this.fontsize + "px " + this.fontface;
|
||||
|
||||
context.font = 'Bold ' + this.fontsize + 'px ' + this.fontface;
|
||||
|
||||
// get size data (height depends only on font size)
|
||||
var metrics = context.measureText( this.text );
|
||||
var metrics = context.measureText(this.text);
|
||||
var textWidth = metrics.width;
|
||||
var margin = 5;
|
||||
var spriteWidth = 2*margin + textWidth + 2 * this.borderThickness;
|
||||
var spriteWidth = 2 * margin + textWidth + 2 * this.borderThickness;
|
||||
var spriteHeight = this.fontsize * 1.4 + 2 * this.borderThickness;
|
||||
|
||||
var canvas = document.createElement('canvas');
|
||||
var context = canvas.getContext('2d');
|
||||
|
||||
context.canvas.width = spriteWidth;
|
||||
context.canvas.height = spriteHeight;
|
||||
context.font = "Bold " + this.fontsize + "px " + this.fontface;
|
||||
|
||||
context.font = 'Bold ' + this.fontsize + 'px ' + this.fontface;
|
||||
|
||||
// background color
|
||||
context.fillStyle = "rgba(" + this.backgroundColor.r + "," + this.backgroundColor.g + ","
|
||||
+ this.backgroundColor.b + "," + this.backgroundColor.a + ")";
|
||||
context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' +
|
||||
this.backgroundColor.b + ',' + this.backgroundColor.a + ')';
|
||||
// border color
|
||||
context.strokeStyle = "rgba(" + this.borderColor.r + "," + this.borderColor.g + ","
|
||||
+ this.borderColor.b + "," + this.borderColor.a + ")";
|
||||
|
||||
context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' +
|
||||
this.borderColor.b + ',' + this.borderColor.a + ')';
|
||||
|
||||
context.lineWidth = this.borderThickness;
|
||||
this.roundRect(context, this.borderThickness/2, this.borderThickness/2,
|
||||
textWidth + this.borderThickness + 2*margin, this.fontsize * 1.4 + this.borderThickness, 6);
|
||||
|
||||
this.roundRect(context, this.borderThickness / 2, this.borderThickness / 2,
|
||||
textWidth + this.borderThickness + 2 * margin, this.fontsize * 1.4 + this.borderThickness, 6);
|
||||
|
||||
// text color
|
||||
context.strokeStyle = "rgba(0, 0, 0, 1.0)";
|
||||
context.strokeText( this.text, this.borderThickness + margin, this.fontsize + this.borderThickness);
|
||||
|
||||
context.fillStyle = "rgba(" + this.textColor.r + "," + this.textColor.g + ","
|
||||
+ this.textColor.b + "," + this.textColor.a + ")";
|
||||
context.fillText( this.text, this.borderThickness + margin, this.fontsize + this.borderThickness);
|
||||
|
||||
|
||||
var texture = new THREE.Texture(canvas);
|
||||
context.strokeStyle = 'rgba(0, 0, 0, 1.0)';
|
||||
context.strokeText(this.text, this.borderThickness + margin, this.fontsize + this.borderThickness);
|
||||
|
||||
context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' +
|
||||
this.textColor.b + ',' + this.textColor.a + ')';
|
||||
context.fillText(this.text, this.borderThickness + margin, this.fontsize + this.borderThickness);
|
||||
|
||||
var texture = new THREE.Texture(canvas);
|
||||
texture.minFilter = THREE.LinearFilter;
|
||||
texture.magFilter = THREE.LinearFilter;
|
||||
texture.needsUpdate = true;
|
||||
|
||||
//var spriteMaterial = new THREE.SpriteMaterial(
|
||||
texture.needsUpdate = true;
|
||||
|
||||
// var spriteMaterial = new THREE.SpriteMaterial(
|
||||
// { map: texture, useScreenCoordinates: false } );
|
||||
this.sprite.material.map = texture;
|
||||
|
||||
this.sprite.scale.set(spriteWidth*0.01,spriteHeight*0.01,1.0);
|
||||
|
||||
//this.material = spriteMaterial;
|
||||
|
||||
this.sprite.scale.set(spriteWidth * 0.01, spriteHeight * 0.01, 1.0);
|
||||
|
||||
// this.material = spriteMaterial;
|
||||
};
|
||||
|
||||
Potree.TextSprite.prototype.roundRect = function(ctx, x, y, w, h, r) {
|
||||
Potree.TextSprite.prototype.roundRect = function (ctx, x, y, w, h, r) {
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(x+r, y);
|
||||
ctx.lineTo(x+w-r, y);
|
||||
ctx.quadraticCurveTo(x+w, y, x+w, y+r);
|
||||
ctx.lineTo(x+w, y+h-r);
|
||||
ctx.quadraticCurveTo(x+w, y+h, x+w-r, y+h);
|
||||
ctx.lineTo(x+r, y+h);
|
||||
ctx.quadraticCurveTo(x, y+h, x, y+h-r);
|
||||
ctx.lineTo(x, y+r);
|
||||
ctx.quadraticCurveTo(x, y, x+r, y);
|
||||
ctx.moveTo(x + r, y);
|
||||
ctx.lineTo(x + w - r, y);
|
||||
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
|
||||
ctx.lineTo(x + w, y + h - r);
|
||||
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
|
||||
ctx.lineTo(x + r, y + h);
|
||||
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
|
||||
ctx.lineTo(x, y + r);
|
||||
ctx.quadraticCurveTo(x, y, x + r, y);
|
||||
ctx.closePath();
|
||||
ctx.fill();
|
||||
ctx.stroke();
|
||||
};
|
||||
ctx.stroke();
|
||||
};
|
||||
|
||||
@ -1,39 +1,38 @@
|
||||
|
||||
Potree.Version = function(version){
|
||||
Potree.Version = function (version) {
|
||||
this.version = version;
|
||||
var vmLength = (version.indexOf(".") === -1) ? version.length : version.indexOf(".");
|
||||
var vmLength = (version.indexOf('.') === -1) ? version.length : version.indexOf('.');
|
||||
this.versionMajor = parseInt(version.substr(0, vmLength));
|
||||
this.versionMinor = parseInt(version.substr(vmLength + 1));
|
||||
if(this.versionMinor.length === 0){
|
||||
if (this.versionMinor.length === 0) {
|
||||
this.versionMinor = 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.Version.prototype.newerThan = function(version){
|
||||
Potree.Version.prototype.newerThan = function (version) {
|
||||
var v = new Potree.Version(version);
|
||||
|
||||
if( this.versionMajor > v.versionMajor){
|
||||
|
||||
if (this.versionMajor > v.versionMajor) {
|
||||
return true;
|
||||
}else if( this.versionMajor === v.versionMajor && this.versionMinor > v.versionMinor){
|
||||
} else if (this.versionMajor === v.versionMajor && this.versionMinor > v.versionMinor) {
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Potree.Version.prototype.equalOrHigher = function(version){
|
||||
Potree.Version.prototype.equalOrHigher = function (version) {
|
||||
var v = new Potree.Version(version);
|
||||
|
||||
if( this.versionMajor > v.versionMajor){
|
||||
|
||||
if (this.versionMajor > v.versionMajor) {
|
||||
return true;
|
||||
}else if( this.versionMajor === v.versionMajor && this.versionMinor >= v.versionMinor){
|
||||
} else if (this.versionMajor === v.versionMajor && this.versionMinor >= v.versionMinor) {
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Potree.Version.prototype.upTo = function(version){
|
||||
Potree.Version.prototype.upTo = function (version) {
|
||||
return !this.newerThan(version);
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,32 +1,27 @@
|
||||
|
||||
Potree.WorkerPool = class WorkerPool{
|
||||
|
||||
constructor(){
|
||||
Potree.WorkerPool = class WorkerPool {
|
||||
constructor () {
|
||||
this.workers = {};
|
||||
}
|
||||
|
||||
getWorker(url){
|
||||
|
||||
if(!this.workers[url]){
|
||||
|
||||
getWorker (url) {
|
||||
if (!this.workers[url]) {
|
||||
this.workers[url] = [];
|
||||
}
|
||||
|
||||
if(this.workers[url].length === 0){
|
||||
if (this.workers[url].length === 0) {
|
||||
let worker = new Worker(url);
|
||||
this.workers[url].push(worker);
|
||||
}
|
||||
|
||||
|
||||
let worker = this.workers[url].pop();
|
||||
|
||||
|
||||
return worker;
|
||||
}
|
||||
|
||||
returnWorker(url, worker){
|
||||
|
||||
returnWorker (url, worker) {
|
||||
this.workers[url].push(worker);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.workerPool = new Potree.WorkerPool();
|
||||
|
||||
|
||||
|
||||
@ -1,60 +1,59 @@
|
||||
|
||||
Potree.PointCloudArena4DNode = class PointCloudArena4DNode extends Potree.PointCloudTreeNode{
|
||||
|
||||
constructor(){
|
||||
super();
|
||||
|
||||
Potree.PointCloudArena4DNode = class PointCloudArena4DNode extends Potree.PointCloudTreeNode {
|
||||
constructor () {
|
||||
super();
|
||||
|
||||
this.left = null;
|
||||
this.right = null;
|
||||
this.sceneNode = null;
|
||||
this.kdtree = null;
|
||||
}
|
||||
|
||||
getNumPoints(){
|
||||
|
||||
getNumPoints () {
|
||||
return this.geometryNode.numPoints;
|
||||
}
|
||||
|
||||
isLoaded(){
|
||||
|
||||
isLoaded () {
|
||||
return true;
|
||||
}
|
||||
|
||||
isTreeNode(){
|
||||
|
||||
isTreeNode () {
|
||||
return true;
|
||||
}
|
||||
|
||||
isGeometryNode(){
|
||||
|
||||
isGeometryNode () {
|
||||
return false;
|
||||
}
|
||||
|
||||
getLevel(){
|
||||
|
||||
getLevel () {
|
||||
return this.geometryNode.level;
|
||||
}
|
||||
|
||||
getBoundingSphere(){
|
||||
|
||||
getBoundingSphere () {
|
||||
return this.geometryNode.boundingSphere;
|
||||
}
|
||||
|
||||
getBoundingBox(){
|
||||
|
||||
getBoundingBox () {
|
||||
return this.geometryNode.boundingBox;
|
||||
}
|
||||
|
||||
toTreeNode(child){
|
||||
|
||||
toTreeNode (child) {
|
||||
var geometryNode = null;
|
||||
|
||||
if(this.left === child){
|
||||
|
||||
if (this.left === child) {
|
||||
geometryNode = this.left;
|
||||
}else if(this.right === child){
|
||||
} else if (this.right === child) {
|
||||
geometryNode = this.right;
|
||||
}
|
||||
|
||||
if(!geometryNode.loaded){
|
||||
|
||||
if (!geometryNode.loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var node = new Potree.PointCloudArena4DNode();
|
||||
var sceneNode = THREE.PointCloud(geometryNode.geometry, this.kdtree.material);
|
||||
sceneNode.visible = false;
|
||||
|
||||
|
||||
node.kdtree = this.kdtree;
|
||||
node.geometryNode = geometryNode;
|
||||
node.sceneNode = sceneNode;
|
||||
@ -62,53 +61,50 @@ Potree.PointCloudArena4DNode = class PointCloudArena4DNode extends Potree.PointC
|
||||
node.left = this.geometryNode.left;
|
||||
node.right = this.geometryNode.right;
|
||||
}
|
||||
|
||||
getChildren(){
|
||||
|
||||
getChildren () {
|
||||
var children = [];
|
||||
|
||||
if(this.left){
|
||||
|
||||
if (this.left) {
|
||||
children.push(this.left);
|
||||
}
|
||||
|
||||
if(this.right){
|
||||
}
|
||||
|
||||
if (this.right) {
|
||||
children.push(this.right);
|
||||
}
|
||||
|
||||
|
||||
return children;
|
||||
}
|
||||
};
|
||||
|
||||
Potree.PointCloudOctreeNode.prototype = Object.create(Potree.PointCloudTreeNode.prototype);
|
||||
|
||||
Potree.PointCloudArena4D = class PointCloudArena4D extends Potree.PointCloudTree {
|
||||
constructor (geometry) {
|
||||
super();
|
||||
|
||||
|
||||
Potree.PointCloudArena4D = class PointCloudArena4D extends Potree.PointCloudTree{
|
||||
|
||||
constructor(geometry){
|
||||
super()
|
||||
|
||||
this.root = null;
|
||||
if(geometry.root){
|
||||
if (geometry.root) {
|
||||
this.root = geometry.root;
|
||||
}else{
|
||||
geometry.addEventListener("hierarchy_loaded", () => {
|
||||
} else {
|
||||
geometry.addEventListener('hierarchy_loaded', () => {
|
||||
this.root = geometry.root;
|
||||
});
|
||||
}
|
||||
|
||||
this.visiblePointsTarget = 2*1000*1000;
|
||||
|
||||
this.visiblePointsTarget = 2 * 1000 * 1000;
|
||||
this.minimumNodePixelSize = 150;
|
||||
|
||||
|
||||
this.position.sub(geometry.offset);
|
||||
this.updateMatrix();
|
||||
|
||||
|
||||
this.numVisibleNodes = 0;
|
||||
this.numVisiblePoints = 0;
|
||||
|
||||
|
||||
this.boundingBoxNodes = [];
|
||||
this.loadQueue = [];
|
||||
this.visibleNodes = [];
|
||||
|
||||
|
||||
this.pcoGeometry = geometry;
|
||||
this.boundingBox = this.pcoGeometry.boundingBox;
|
||||
this.boundingSphere = this.pcoGeometry.boundingSphere;
|
||||
@ -116,264 +112,254 @@ Potree.PointCloudArena4D = class PointCloudArena4D extends Potree.PointCloudTree
|
||||
this.material.sizeType = Potree.PointSizeType.ATTENUATED;
|
||||
this.material.size = 0.05;
|
||||
this.profileRequests = [];
|
||||
this.name = "";
|
||||
this.name = '';
|
||||
}
|
||||
|
||||
setName(name){
|
||||
if(this.name !== name){
|
||||
|
||||
setName (name) {
|
||||
if (this.name !== name) {
|
||||
this.name = name;
|
||||
this.dispatchEvent({type: "name_changed", name: name, pointcloud: this});
|
||||
this.dispatchEvent({type: 'name_changed', name: name, pointcloud: this});
|
||||
}
|
||||
}
|
||||
|
||||
getName(){
|
||||
|
||||
getName () {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
getLevel(){
|
||||
|
||||
getLevel () {
|
||||
return this.level;
|
||||
}
|
||||
|
||||
toTreeNode(geometryNode, parent){
|
||||
|
||||
toTreeNode (geometryNode, parent) {
|
||||
var node = new Potree.PointCloudArena4DNode();
|
||||
var sceneNode = new THREE.Points(geometryNode.geometry, this.material);
|
||||
|
||||
|
||||
sceneNode.frustumCulled = false;
|
||||
sceneNode.onBeforeRender = (_this, scene, camera, geometry, material, group) => {
|
||||
|
||||
if(material.program){
|
||||
if (material.program) {
|
||||
_this.getContext().useProgram(material.program.program);
|
||||
|
||||
if(material.program.getUniforms().map.level){
|
||||
|
||||
if (material.program.getUniforms().map.level) {
|
||||
let level = geometryNode.getLevel();
|
||||
material.uniforms.level.value = level;
|
||||
material.program.getUniforms().map.level.setValue(_this.getContext(), level);
|
||||
}
|
||||
|
||||
if(this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart){
|
||||
|
||||
if (this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart) {
|
||||
let vnStart = this.visibleNodeTextureOffsets.get(node);
|
||||
material.uniforms.vnStart.value = vnStart;
|
||||
material.program.getUniforms().map.vnStart.setValue(_this.getContext(), vnStart);
|
||||
}
|
||||
|
||||
if(material.program.getUniforms().map.pcIndex){
|
||||
|
||||
if (material.program.getUniforms().map.pcIndex) {
|
||||
let i = node.pcIndex ? node.pcIndex : this.visibleNodes.indexOf(node);
|
||||
material.uniforms.pcIndex.value = i;
|
||||
material.program.getUniforms().map.pcIndex.setValue(_this.getContext(), i);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
node.geometryNode = geometryNode;
|
||||
node.sceneNode = sceneNode;
|
||||
node.pointcloud = this;
|
||||
node.left = geometryNode.left;
|
||||
node.right = geometryNode.right;
|
||||
|
||||
if(!parent){
|
||||
|
||||
if (!parent) {
|
||||
this.root = node;
|
||||
this.add(sceneNode);
|
||||
}else{
|
||||
} else {
|
||||
parent.sceneNode.add(sceneNode);
|
||||
|
||||
if(parent.left === geometryNode){
|
||||
|
||||
if (parent.left === geometryNode) {
|
||||
parent.left = node;
|
||||
}else if(parent.right === geometryNode){
|
||||
} else if (parent.right === geometryNode) {
|
||||
parent.right = node;
|
||||
}
|
||||
}
|
||||
|
||||
var disposeListener = function(){
|
||||
|
||||
var disposeListener = function () {
|
||||
parent.sceneNode.remove(node.sceneNode);
|
||||
|
||||
if(parent.left === node){
|
||||
|
||||
if (parent.left === node) {
|
||||
parent.left = geometryNode;
|
||||
}else if(parent.right === node){
|
||||
} else if (parent.right === node) {
|
||||
parent.right = geometryNode;
|
||||
}
|
||||
}
|
||||
};
|
||||
geometryNode.oneTimeDisposeHandlers.push(disposeListener);
|
||||
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
updateMaterial(material, visibleNodes, camera, renderer){
|
||||
|
||||
updateMaterial (material, visibleNodes, camera, renderer) {
|
||||
material.fov = camera.fov * (Math.PI / 180);
|
||||
material.screenWidth = renderer.domElement.clientWidth;
|
||||
material.screenHeight = renderer.domElement.clientHeight;
|
||||
material.spacing = this.pcoGeometry.spacing;
|
||||
material.near = camera.near;
|
||||
material.far = camera.far;
|
||||
|
||||
|
||||
// reduce shader source updates by setting maxLevel slightly higher than actually necessary
|
||||
if(this.maxLevel > material.levels){
|
||||
if (this.maxLevel > material.levels) {
|
||||
material.levels = this.maxLevel + 2;
|
||||
}
|
||||
|
||||
//material.minSize = 3;
|
||||
|
||||
//material.uniforms.octreeSize.value = this.boundingBox.size().x;
|
||||
|
||||
// material.minSize = 3;
|
||||
|
||||
// material.uniforms.octreeSize.value = this.boundingBox.size().x;
|
||||
var bbSize = this.boundingBox.getSize();
|
||||
material.bbSize = [bbSize.x, bbSize.y, bbSize.z];
|
||||
|
||||
|
||||
// update visibility texture
|
||||
if(material.pointSizeType){
|
||||
if(material.pointSizeType === Potree.PointSizeType.ADAPTIVE
|
||||
|| material.pointColorType === Potree.PointColorType.LOD){
|
||||
|
||||
if (material.pointSizeType) {
|
||||
if (material.pointSizeType === Potree.PointSizeType.ADAPTIVE ||
|
||||
material.pointColorType === Potree.PointColorType.LOD) {
|
||||
this.updateVisibilityTexture(material, visibleNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateVisibleBounds(){
|
||||
|
||||
|
||||
updateVisibleBounds () {
|
||||
|
||||
}
|
||||
|
||||
hideDescendants(object){
|
||||
|
||||
hideDescendants (object) {
|
||||
var stack = [];
|
||||
for(var i = 0; i < object.children.length; i++){
|
||||
var child = object.children[i];
|
||||
if(child.visible){
|
||||
for (let i = 0; i < object.children.length; i++) {
|
||||
let child = object.children[i];
|
||||
if (child.visible) {
|
||||
stack.push(child);
|
||||
}
|
||||
}
|
||||
|
||||
while(stack.length > 0){
|
||||
var object = stack.shift();
|
||||
|
||||
object.visible = false;
|
||||
if(object.boundingBoxNode){
|
||||
object.boundingBoxNode.visible = false;
|
||||
|
||||
while (stack.length > 0) {
|
||||
let child = stack.shift();
|
||||
|
||||
child.visible = false;
|
||||
if (child.boundingBoxNode) {
|
||||
child.boundingBoxNode.visible = false;
|
||||
}
|
||||
|
||||
for(var i = 0; i < object.children.length; i++){
|
||||
var child = object.children[i];
|
||||
if(child.visible){
|
||||
stack.push(child);
|
||||
|
||||
for (let i = 0; i < child.children.length; i++) {
|
||||
let childOfChild = child.children[i];
|
||||
if (childOfChild.visible) {
|
||||
stack.push(childOfChild);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateMatrixWorld( force ){
|
||||
//node.matrixWorld.multiplyMatrices( node.parent.matrixWorld, node.matrix );
|
||||
|
||||
if ( this.matrixAutoUpdate === true ) this.updateMatrix();
|
||||
|
||||
if ( this.matrixWorldNeedsUpdate === true || force === true ) {
|
||||
updateMatrixWorld (force) {
|
||||
// node.matrixWorld.multiplyMatrices( node.parent.matrixWorld, node.matrix );
|
||||
|
||||
if ( this.parent === undefined ) {
|
||||
|
||||
this.matrixWorld.copy( this.matrix );
|
||||
if (this.matrixAutoUpdate === true) this.updateMatrix();
|
||||
|
||||
if (this.matrixWorldNeedsUpdate === true || force === true) {
|
||||
if (this.parent === undefined) {
|
||||
this.matrixWorld.copy(this.matrix);
|
||||
} else {
|
||||
|
||||
this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
|
||||
|
||||
this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
|
||||
}
|
||||
|
||||
this.matrixWorldNeedsUpdate = false;
|
||||
|
||||
force = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
nodesOnRay(nodes, ray){
|
||||
|
||||
nodesOnRay (nodes, ray) {
|
||||
var nodesOnRay = [];
|
||||
|
||||
var _ray = ray.clone();
|
||||
for(var i = 0; i < nodes.length; i++){
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var node = nodes[i];
|
||||
var sphere = node.getBoundingSphere().clone().applyMatrix4(node.sceneNode.matrixWorld);
|
||||
var box = node.getBoundingBox().clone().applyMatrix4(node.sceneNode.matrixWorld);
|
||||
|
||||
if(_ray.intersectsSphere(sphere)){
|
||||
// TODO Unused: var box = node.getBoundingBox().clone().applyMatrix4(node.sceneNode.matrixWorld);
|
||||
|
||||
if (_ray.intersectsSphere(sphere)) {
|
||||
nodesOnRay.push(node);
|
||||
}
|
||||
//if(_ray.isIntersectionBox(box)){
|
||||
// if(_ray.isIntersectionBox(box)){
|
||||
// nodesOnRay.push(node);
|
||||
//}
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
return nodesOnRay;
|
||||
}
|
||||
|
||||
pick(renderer, camera, ray, params = {}){
|
||||
|
||||
//let start = new Date().getTime();
|
||||
|
||||
|
||||
pick (renderer, camera, ray, params = {}) {
|
||||
// let start = new Date().getTime();
|
||||
|
||||
let pickWindowSize = params.pickWindowSize || 17;
|
||||
let pickOutsideClipRegion = params.pickOutsideClipRegion || false;
|
||||
let width = Math.ceil(renderer.domElement.clientWidth);
|
||||
let height = Math.ceil(renderer.domElement.clientHeight);
|
||||
|
||||
|
||||
let nodes = this.nodesOnRay(this.visibleNodes, ray);
|
||||
|
||||
if(nodes.length === 0){
|
||||
|
||||
if (nodes.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if(!this.pickState){
|
||||
|
||||
|
||||
if (!this.pickState) {
|
||||
let scene = new THREE.Scene();
|
||||
|
||||
|
||||
let material = new Potree.PointCloudMaterial();
|
||||
material.pointColorType = Potree.PointColorType.POINT_INDEX;
|
||||
|
||||
let renderTarget = new THREE.WebGLRenderTarget(
|
||||
1, 1,
|
||||
{ minFilter: THREE.LinearFilter,
|
||||
magFilter: THREE.NearestFilter,
|
||||
format: THREE.RGBAFormat }
|
||||
material.pointColorType = Potree.PointColorType.POINT_INDEX;
|
||||
|
||||
let renderTarget = new THREE.WebGLRenderTarget(
|
||||
1, 1,
|
||||
{ minFilter: THREE.LinearFilter,
|
||||
magFilter: THREE.NearestFilter,
|
||||
format: THREE.RGBAFormat }
|
||||
);
|
||||
|
||||
|
||||
this.pickState = {
|
||||
renderTarget: renderTarget,
|
||||
material: material,
|
||||
scene: scene
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
let pickState = this.pickState;
|
||||
let pickMaterial = pickState.material;
|
||||
|
||||
|
||||
{ // update pick material
|
||||
pickMaterial.pointSizeType = this.material.pointSizeType;
|
||||
pickMaterial.shape = this.material.shape;
|
||||
|
||||
|
||||
pickMaterial.size = this.material.size;
|
||||
pickMaterial.minSize = this.material.minSize;
|
||||
pickMaterial.maxSize = this.material.maxSize;
|
||||
pickMaterial.classification = this.material.classification;
|
||||
|
||||
if(pickOutsideClipRegion){
|
||||
|
||||
if (pickOutsideClipRegion) {
|
||||
pickMaterial.clipMode = Potree.ClipMode.DISABLED;
|
||||
}else{
|
||||
} else {
|
||||
pickMaterial.clipMode = this.material.clipMode;
|
||||
if(this.material.clipMode === Potree.ClipMode.CLIP_OUTSIDE){
|
||||
if (this.material.clipMode === Potree.ClipMode.CLIP_OUTSIDE) {
|
||||
pickMaterial.setClipBoxes(this.material.clipBoxes);
|
||||
}else{
|
||||
} else {
|
||||
pickMaterial.setClipBoxes([]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.updateMaterial(pickMaterial, nodes, camera, renderer);
|
||||
}
|
||||
|
||||
if(pickState.renderTarget.width != width || pickState.renderTarget.height != height){
|
||||
|
||||
if (pickState.renderTarget.width !== width || pickState.renderTarget.height !== height) {
|
||||
pickState.renderTarget.dispose();
|
||||
pickState.renderTarget = new THREE.WebGLRenderTarget(
|
||||
1, 1,
|
||||
{ minFilter: THREE.LinearFilter,
|
||||
magFilter: THREE.NearestFilter,
|
||||
format: THREE.RGBAFormat }
|
||||
pickState.renderTarget = new THREE.WebGLRenderTarget(
|
||||
1, 1,
|
||||
{ minFilter: THREE.LinearFilter,
|
||||
magFilter: THREE.NearestFilter,
|
||||
format: THREE.RGBAFormat }
|
||||
);
|
||||
}
|
||||
pickState.renderTarget.setSize(width, height);
|
||||
renderer.setRenderTarget( pickState.renderTarget );
|
||||
|
||||
renderer.setRenderTarget(pickState.renderTarget);
|
||||
|
||||
let pixelPos = new THREE.Vector3()
|
||||
.addVectors(camera.position, ray.direction)
|
||||
.project(camera)
|
||||
@ -381,194 +367,190 @@ Potree.PointCloudArena4D = class PointCloudArena4D extends Potree.PointCloudTree
|
||||
.multiplyScalar(0.5);
|
||||
pixelPos.x *= width;
|
||||
pixelPos.y *= height;
|
||||
|
||||
|
||||
renderer.setScissor(
|
||||
parseInt(pixelPos.x - (pickWindowSize - 1) / 2),
|
||||
parseInt(pixelPos.x - (pickWindowSize - 1) / 2),
|
||||
parseInt(pixelPos.y - (pickWindowSize - 1) / 2),
|
||||
parseInt(pickWindowSize), parseInt(pickWindowSize));
|
||||
renderer.setScissorTest(true);
|
||||
|
||||
|
||||
renderer.state.buffers.depth.setTest(pickMaterial.depthTest);
|
||||
renderer.state.buffers.depth.setMask(pickMaterial.depthWrite);
|
||||
renderer.state.setBlending(THREE.NoBlending);
|
||||
|
||||
renderer.clearTarget( pickState.renderTarget, true, true, true );
|
||||
|
||||
//pickState.scene.children = nodes.map(n => n.sceneNode);
|
||||
|
||||
//let childStates = [];
|
||||
|
||||
renderer.clearTarget(pickState.renderTarget, true, true, true);
|
||||
|
||||
// pickState.scene.children = nodes.map(n => n.sceneNode);
|
||||
|
||||
// let childStates = [];
|
||||
let tempNodes = [];
|
||||
for(let i = 0; i < nodes.length; i++){
|
||||
for (let i = 0; i < nodes.length; i++) {
|
||||
let node = nodes[i];
|
||||
node.pcIndex = i+1;
|
||||
node.pcIndex = i + 1;
|
||||
let sceneNode = node.sceneNode;
|
||||
|
||||
|
||||
let tempNode = new THREE.Points(sceneNode.geometry, pickMaterial);
|
||||
tempNode.matrix = sceneNode.matrix;
|
||||
tempNode.matrixWorld = sceneNode.matrixWorld;
|
||||
tempNode.matrixAutoUpdate = false;
|
||||
tempNode.frustumCulled = false;
|
||||
tempNode.pcIndex = i+1;
|
||||
|
||||
tempNode.pcIndex = i + 1;
|
||||
|
||||
let geometryNode = node.geometryNode;
|
||||
let material = pickMaterial;
|
||||
// TODO Unused: let material = pickMaterial;
|
||||
tempNode.onBeforeRender = (_this, scene, camera, geometry, material, group) => {
|
||||
|
||||
if(material.program){
|
||||
if (material.program) {
|
||||
_this.getContext().useProgram(material.program.program);
|
||||
|
||||
if(material.program.getUniforms().map.level){
|
||||
|
||||
if (material.program.getUniforms().map.level) {
|
||||
let level = geometryNode.getLevel();
|
||||
material.uniforms.level.value = level;
|
||||
material.program.getUniforms().map.level.setValue(_this.getContext(), level);
|
||||
}
|
||||
|
||||
if(this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart){
|
||||
|
||||
if (this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart) {
|
||||
let vnStart = this.visibleNodeTextureOffsets.get(node);
|
||||
material.uniforms.vnStart.value = vnStart;
|
||||
material.program.getUniforms().map.vnStart.setValue(_this.getContext(), vnStart);
|
||||
}
|
||||
|
||||
if(material.program.getUniforms().map.pcIndex){
|
||||
|
||||
if (material.program.getUniforms().map.pcIndex) {
|
||||
material.uniforms.pcIndex.value = node.pcIndex;
|
||||
material.program.getUniforms().map.pcIndex.setValue(_this.getContext(), node.pcIndex);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
tempNodes.push(tempNode);
|
||||
|
||||
//for(let child of nodes[i].sceneNode.children){
|
||||
|
||||
// for(let child of nodes[i].sceneNode.children){
|
||||
// childStates.push({child: child, visible: child.visible});
|
||||
// child.visible = false;
|
||||
//}
|
||||
// }
|
||||
}
|
||||
pickState.scene.autoUpdate = false;
|
||||
pickState.scene.children = tempNodes;
|
||||
//pickState.scene.overrideMaterial = pickMaterial;
|
||||
|
||||
// pickState.scene.overrideMaterial = pickMaterial;
|
||||
|
||||
renderer.state.setBlending(THREE.NoBlending);
|
||||
|
||||
|
||||
// RENDER
|
||||
renderer.render(pickState.scene, camera, pickState.renderTarget);
|
||||
|
||||
//for(let childState of childStates){
|
||||
|
||||
// for(let childState of childStates){
|
||||
// childState.child = childState.visible;
|
||||
//}
|
||||
|
||||
//pickState.scene.overrideMaterial = null;
|
||||
|
||||
//renderer.context.readPixels(
|
||||
// pixelPos.x - (pickWindowSize-1) / 2, pixelPos.y - (pickWindowSize-1) / 2,
|
||||
// pickWindowSize, pickWindowSize,
|
||||
// }
|
||||
|
||||
// pickState.scene.overrideMaterial = null;
|
||||
|
||||
// renderer.context.readPixels(
|
||||
// pixelPos.x - (pickWindowSize-1) / 2, pixelPos.y - (pickWindowSize-1) / 2,
|
||||
// pickWindowSize, pickWindowSize,
|
||||
// renderer.context.RGBA, renderer.context.UNSIGNED_BYTE, pixels);
|
||||
|
||||
|
||||
let clamp = (number, min, max) => Math.min(Math.max(min, number), max);
|
||||
|
||||
let x = parseInt(clamp(pixelPos.x - (pickWindowSize-1) / 2, 0, width));
|
||||
let y = parseInt(clamp(pixelPos.y - (pickWindowSize-1) / 2, 0, height));
|
||||
|
||||
let x = parseInt(clamp(pixelPos.x - (pickWindowSize - 1) / 2, 0, width));
|
||||
let y = parseInt(clamp(pixelPos.y - (pickWindowSize - 1) / 2, 0, height));
|
||||
let w = parseInt(Math.min(x + pickWindowSize, width) - x);
|
||||
let h = parseInt(Math.min(y + pickWindowSize, height) - y);
|
||||
|
||||
|
||||
let pixelCount = w * h;
|
||||
let buffer = new Uint8Array(4 * pixelCount);
|
||||
renderer.readRenderTargetPixels(pickState.renderTarget,
|
||||
x, y, w, h,
|
||||
renderer.readRenderTargetPixels(pickState.renderTarget,
|
||||
x, y, w, h,
|
||||
buffer);
|
||||
|
||||
|
||||
renderer.setScissorTest(false);
|
||||
|
||||
|
||||
renderer.setRenderTarget(null);
|
||||
|
||||
|
||||
let pixels = buffer;
|
||||
let ibuffer = new Uint32Array(buffer.buffer);
|
||||
|
||||
|
||||
// find closest hit inside pixelWindow boundaries
|
||||
let min = Number.MAX_VALUE;
|
||||
let hit = null;
|
||||
for(let u = 0; u < pickWindowSize; u++){
|
||||
for(let v = 0; v < pickWindowSize; v++){
|
||||
let offset = (u + v*pickWindowSize);
|
||||
let distance = Math.pow(u - (pickWindowSize-1) / 2, 2) + Math.pow(v - (pickWindowSize-1) / 2, 2);
|
||||
|
||||
let pcIndex = pixels[4*offset + 3];
|
||||
pixels[4*offset + 3] = 0;
|
||||
for (let u = 0; u < pickWindowSize; u++) {
|
||||
for (let v = 0; v < pickWindowSize; v++) {
|
||||
let offset = (u + v * pickWindowSize);
|
||||
let distance = Math.pow(u - (pickWindowSize - 1) / 2, 2) + Math.pow(v - (pickWindowSize - 1) / 2, 2);
|
||||
|
||||
let pcIndex = pixels[4 * offset + 3];
|
||||
pixels[4 * offset + 3] = 0;
|
||||
let pIndex = ibuffer[offset];
|
||||
|
||||
//if((pIndex !== 0 || pcIndex !== 0) && distance < min){
|
||||
if(pcIndex > 0 && distance < min){
|
||||
|
||||
|
||||
|
||||
// if((pIndex !== 0 || pcIndex !== 0) && distance < min){
|
||||
if (pcIndex > 0 && distance < min) {
|
||||
hit = {
|
||||
pIndex: pIndex,
|
||||
pcIndex: pcIndex - 1
|
||||
};
|
||||
min = distance;
|
||||
|
||||
//console.log(hit);
|
||||
|
||||
// console.log(hit);
|
||||
}
|
||||
}
|
||||
}
|
||||
//console.log(pixels);
|
||||
|
||||
//{ // open window with image
|
||||
// console.log(pixels);
|
||||
|
||||
// { // open window with image
|
||||
// let img = Potree.utils.pixelsArrayToImage(buffer, w, h);
|
||||
// let screenshot = img.src;
|
||||
//
|
||||
//
|
||||
// if(!this.debugDIV){
|
||||
// this.debugDIV = $(`
|
||||
// <div id="pickDebug"
|
||||
// style="position: absolute;
|
||||
// <div id="pickDebug"
|
||||
// style="position: absolute;
|
||||
// right: 400px; width: 300px;
|
||||
// bottom: 44px; width: 300px;
|
||||
// z-index: 1000;
|
||||
// "></div>`);
|
||||
// $(document.body).append(this.debugDIV);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// this.debugDIV.empty();
|
||||
// this.debugDIV.append($(`<img src="${screenshot}"
|
||||
// style="transform: scaleY(-1);"/>`));
|
||||
// //$(this.debugWindow.document).append($(`<img src="${screenshot}"/>`));
|
||||
// //this.debugWindow.document.write('<img src="'+screenshot+'"/>');
|
||||
//}
|
||||
|
||||
//return;
|
||||
|
||||
// }
|
||||
|
||||
// return;
|
||||
|
||||
let point = null;
|
||||
|
||||
if(hit){
|
||||
|
||||
if (hit) {
|
||||
point = {};
|
||||
|
||||
if(!nodes[hit.pcIndex]){
|
||||
|
||||
if (!nodes[hit.pcIndex]) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
let pc = nodes[hit.pcIndex].sceneNode;
|
||||
let attributes = pc.geometry.attributes;
|
||||
|
||||
for(let property in attributes) {
|
||||
|
||||
for (let property in attributes) {
|
||||
if (attributes.hasOwnProperty(property)) {
|
||||
let values = pc.geometry.attributes[property];
|
||||
|
||||
if(property === "position"){
|
||||
|
||||
if (property === 'position') {
|
||||
let positionArray = values.array;
|
||||
let x = positionArray[3*hit.pIndex+0];
|
||||
let y = positionArray[3*hit.pIndex+1];
|
||||
let z = positionArray[3*hit.pIndex+2];
|
||||
let x = positionArray[3 * hit.pIndex + 0];
|
||||
let y = positionArray[3 * hit.pIndex + 1];
|
||||
let z = positionArray[3 * hit.pIndex + 2];
|
||||
let position = new THREE.Vector3(x, y, z);
|
||||
position.applyMatrix4(pc.matrixWorld);
|
||||
|
||||
|
||||
point[property] = position;
|
||||
}else if(property === "indices"){
|
||||
|
||||
}else{
|
||||
if(values.itemSize === 1){
|
||||
} else if (property === 'indices') {
|
||||
|
||||
} else {
|
||||
if (values.itemSize === 1) {
|
||||
point[property] = values.array[hit.pIndex];
|
||||
}else{
|
||||
} else {
|
||||
let value = [];
|
||||
for(let j = 0; j < values.itemSize; j++){
|
||||
value.push(values.array[values.itemSize*hit.pIndex + j]);
|
||||
for (let j = 0; j < values.itemSize; j++) {
|
||||
value.push(values.array[values.itemSize * hit.pIndex + j]);
|
||||
}
|
||||
point[property] = value;
|
||||
}
|
||||
@ -576,86 +558,81 @@ Potree.PointCloudArena4D = class PointCloudArena4D extends Potree.PointCloudTree
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//let end = new Date().getTime();
|
||||
//let duration = end - start;
|
||||
//console.log(`pick duration: ${duration}ms`);
|
||||
|
||||
return point;
|
||||
|
||||
|
||||
}
|
||||
|
||||
updateVisibilityTexture(material, visibleNodes){
|
||||
|
||||
if(!material){
|
||||
// let end = new Date().getTime();
|
||||
// let duration = end - start;
|
||||
// console.log(`pick duration: ${duration}ms`);
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
updateVisibilityTexture (material, visibleNodes) {
|
||||
if (!material) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var texture = material.visibleNodesTexture;
|
||||
var data = texture.image.data;
|
||||
|
||||
|
||||
// copy array
|
||||
visibleNodes = visibleNodes.slice();
|
||||
|
||||
|
||||
// sort by level and number
|
||||
var sort = function(a, b){
|
||||
var sort = function (a, b) {
|
||||
var la = a.geometryNode.level;
|
||||
var lb = b.geometryNode.level;
|
||||
var na = a.geometryNode.number;
|
||||
var nb = b.geometryNode.number;
|
||||
if(la != lb) return la - lb;
|
||||
if(na < nb) return -1;
|
||||
if(na > nb) return 1;
|
||||
if (la !== lb) return la - lb;
|
||||
if (na < nb) return -1;
|
||||
if (na > nb) return 1;
|
||||
return 0;
|
||||
};
|
||||
visibleNodes.sort(sort);
|
||||
|
||||
|
||||
var visibleNodeNames = [];
|
||||
for(var i = 0; i < visibleNodes.length; i++){
|
||||
//visibleNodeNames[visibleNodes[i].pcoGeometry.number] = true;
|
||||
for (let i = 0; i < visibleNodes.length; i++) {
|
||||
// visibleNodeNames[visibleNodes[i].pcoGeometry.number] = true;
|
||||
visibleNodeNames.push(visibleNodes[i].geometryNode.number);
|
||||
}
|
||||
|
||||
for(var i = 0; i < visibleNodes.length; i++){
|
||||
|
||||
for (let i = 0; i < visibleNodes.length; i++) {
|
||||
var node = visibleNodes[i];
|
||||
|
||||
|
||||
var b1 = 0; // children
|
||||
var b2 = 0; // offset to first child
|
||||
var b3 = 0; // split
|
||||
|
||||
if(node.geometryNode.left && visibleNodeNames.indexOf(node.geometryNode.left.number) > 0){
|
||||
var b3 = 0; // split
|
||||
|
||||
if (node.geometryNode.left && visibleNodeNames.indexOf(node.geometryNode.left.number) > 0) {
|
||||
b1 += 1;
|
||||
b2 = visibleNodeNames.indexOf(node.geometryNode.left.number) - i;
|
||||
}
|
||||
if(node.geometryNode.right && visibleNodeNames.indexOf(node.geometryNode.right.number) > 0){
|
||||
if (node.geometryNode.right && visibleNodeNames.indexOf(node.geometryNode.right.number) > 0) {
|
||||
b1 += 2;
|
||||
b2 = (b2 === 0) ? visibleNodeNames.indexOf(node.geometryNode.right.number) - i : b2;
|
||||
}
|
||||
|
||||
if(node.geometryNode.split === "X"){
|
||||
|
||||
if (node.geometryNode.split === 'X') {
|
||||
b3 = 1;
|
||||
}else if(node.geometryNode.split === "Y"){
|
||||
} else if (node.geometryNode.split === 'Y') {
|
||||
b3 = 2;
|
||||
}else if(node.geometryNode.split === "Z"){
|
||||
} else if (node.geometryNode.split === 'Z') {
|
||||
b3 = 4;
|
||||
}
|
||||
|
||||
|
||||
data[i*3+0] = b1;
|
||||
data[i*3+1] = b2;
|
||||
data[i*3+2] = b3;
|
||||
|
||||
data[i * 3 + 0] = b1;
|
||||
data[i * 3 + 1] = b2;
|
||||
data[i * 3 + 2] = b3;
|
||||
}
|
||||
|
||||
|
||||
|
||||
texture.needsUpdate = true;
|
||||
}
|
||||
|
||||
get progress(){
|
||||
if(this.pcoGeometry.root){
|
||||
|
||||
get progress () {
|
||||
if (this.pcoGeometry.root) {
|
||||
return Potree.PointCloudArena4DGeometryNode.nodesLoading > 0 ? 0 : 1;
|
||||
}else{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode = function(){
|
||||
var scope = this;
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode = function () {
|
||||
this.left = null;
|
||||
this.right = null;
|
||||
this.boundingBox = null;
|
||||
@ -17,135 +14,133 @@ Potree.PointCloudArena4DGeometryNode = function(){
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.nodesLoading = 0;
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.isGeometryNode = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.isGeometryNode = function () {
|
||||
return true;
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.isTreeNode = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.isTreeNode = function () {
|
||||
return false;
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.isLoaded = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.isLoaded = function () {
|
||||
return this.loaded;
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getBoundingSphere = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getBoundingSphere = function () {
|
||||
return this.boundingSphere;
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getBoundingBox = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getBoundingBox = function () {
|
||||
return this.boundingBox;
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getChildren = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getChildren = function () {
|
||||
var children = [];
|
||||
|
||||
if(this.left){
|
||||
|
||||
if (this.left) {
|
||||
children.push(this.left);
|
||||
}
|
||||
|
||||
if(this.right){
|
||||
}
|
||||
|
||||
if (this.right) {
|
||||
children.push(this.right);
|
||||
}
|
||||
|
||||
|
||||
return children;
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getBoundingBox = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getBoundingBox = function () {
|
||||
return this.boundingBox;
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getLevel = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getLevel = function () {
|
||||
return this.level;
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.load = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.load = function () {
|
||||
if (this.loaded || this.loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.loaded || this.loading){
|
||||
if (Potree.PointCloudArena4DGeometryNode.nodesLoading >= 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(Potree.PointCloudArena4DGeometryNode.nodesLoading >= 5){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.loading = true;
|
||||
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.nodesLoading++;
|
||||
|
||||
var url = this.pcoGeometry.url + "?node=" + this.number;
|
||||
|
||||
var url = this.pcoGeometry.url + '?node=' + this.number;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
|
||||
var scope = this;
|
||||
|
||||
xhr.onreadystatechange = function(){
|
||||
if(!(xhr.readyState === 4 && xhr.status === 200)){
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (!(xhr.readyState === 4 && xhr.status === 200)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var buffer = xhr.response;
|
||||
var view = new DataView(buffer);
|
||||
var numPoints = buffer.byteLength / 17;
|
||||
|
||||
var positions = new Float32Array(numPoints*3);
|
||||
var colors = new Uint8Array(numPoints*3);
|
||||
var indices = new ArrayBuffer(numPoints*4);
|
||||
|
||||
var positions = new Float32Array(numPoints * 3);
|
||||
var colors = new Uint8Array(numPoints * 3);
|
||||
var indices = new ArrayBuffer(numPoints * 4);
|
||||
var iIndices = new Uint32Array(indices);
|
||||
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
var x = view.getFloat32(i*17 + 0, true) + scope.boundingBox.min.x;
|
||||
var y = view.getFloat32(i*17 + 4, true) + scope.boundingBox.min.y;
|
||||
var z = view.getFloat32(i*17 + 8, true) + scope.boundingBox.min.z;
|
||||
var r = view.getUint8(i*17 + 12, true);
|
||||
var g = view.getUint8(i*17 + 13, true);
|
||||
var b = view.getUint8(i*17 + 14, true);
|
||||
|
||||
positions[i*3+0] = x;
|
||||
positions[i*3+1] = y;
|
||||
positions[i*3+2] = z;
|
||||
|
||||
colors[i*3+0] = r;
|
||||
colors[i*3+1] = g;
|
||||
colors[i*3+2] = b;
|
||||
|
||||
|
||||
for (var i = 0; i < numPoints; i++) {
|
||||
var x = view.getFloat32(i * 17 + 0, true) + scope.boundingBox.min.x;
|
||||
var y = view.getFloat32(i * 17 + 4, true) + scope.boundingBox.min.y;
|
||||
var z = view.getFloat32(i * 17 + 8, true) + scope.boundingBox.min.z;
|
||||
var r = view.getUint8(i * 17 + 12, true);
|
||||
var g = view.getUint8(i * 17 + 13, true);
|
||||
var b = view.getUint8(i * 17 + 14, true);
|
||||
|
||||
positions[i * 3 + 0] = x;
|
||||
positions[i * 3 + 1] = y;
|
||||
positions[i * 3 + 2] = z;
|
||||
|
||||
colors[i * 3 + 0] = r;
|
||||
colors[i * 3 + 1] = g;
|
||||
colors[i * 3 + 2] = b;
|
||||
|
||||
iIndices[i] = i;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));
|
||||
geometry.addAttribute("color", new THREE.BufferAttribute(colors, 3, true));
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(numPoints*3), 3));
|
||||
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3, true));
|
||||
geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(numPoints * 3), 3));
|
||||
|
||||
let indicesAttribute = new THREE.Uint8BufferAttribute(indices, 4);
|
||||
indicesAttribute.normalized = true;
|
||||
geometry.addAttribute("indices", indicesAttribute);
|
||||
|
||||
geometry.addAttribute('indices', indicesAttribute);
|
||||
|
||||
scope.geometry = geometry;
|
||||
scope.loaded = true;
|
||||
Potree.PointCloudArena4DGeometryNode.nodesLoading--;
|
||||
|
||||
|
||||
geometry.boundingBox = scope.boundingBox;
|
||||
geometry.boundingSphere = scope.boundingSphere;
|
||||
|
||||
|
||||
scope.numPoints = numPoints;
|
||||
|
||||
scope.loading = false;
|
||||
};
|
||||
|
||||
|
||||
xhr.send(null);
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.dispose = function(){
|
||||
if(this.geometry && this.parent != null){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.dispose = function () {
|
||||
if (this.geometry && this.parent != null) {
|
||||
this.geometry.dispose();
|
||||
this.geometry = null;
|
||||
this.loaded = false;
|
||||
|
||||
//this.dispatchEvent( { type: 'dispose' } );
|
||||
for(var i = 0; i < this.oneTimeDisposeHandlers.length; i++){
|
||||
|
||||
// this.dispatchEvent( { type: 'dispose' } );
|
||||
for (var i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
|
||||
var handler = this.oneTimeDisposeHandlers[i];
|
||||
handler();
|
||||
}
|
||||
@ -153,14 +148,11 @@ Potree.PointCloudArena4DGeometryNode.prototype.dispose = function(){
|
||||
}
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getNumPoints = function(){
|
||||
Potree.PointCloudArena4DGeometryNode.prototype.getNumPoints = function () {
|
||||
return this.numPoints;
|
||||
};
|
||||
|
||||
|
||||
Potree.PointCloudArena4DGeometry = function(){
|
||||
var scope = this;
|
||||
|
||||
Potree.PointCloudArena4DGeometry = function () {
|
||||
this.numPoints = 0;
|
||||
this.version = 0;
|
||||
this.boundingBox = null;
|
||||
@ -172,23 +164,22 @@ Potree.PointCloudArena4DGeometry = function(){
|
||||
this.levels = 0;
|
||||
this._spacing = null;
|
||||
this.pointAttributes = new Potree.PointAttributes([
|
||||
"POSITION_CARTESIAN",
|
||||
"COLOR_PACKED"
|
||||
'POSITION_CARTESIAN',
|
||||
'COLOR_PACKED'
|
||||
]);
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometry.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
|
||||
Potree.PointCloudArena4DGeometry.load = function(url, callback){
|
||||
Potree.PointCloudArena4DGeometry.prototype = Object.create(THREE.EventDispatcher.prototype);
|
||||
|
||||
Potree.PointCloudArena4DGeometry.load = function (url, callback) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url + "?info", true);
|
||||
|
||||
xhr.onreadystatechange = function(){
|
||||
try{
|
||||
if(xhr.readyState === 4 && xhr.status === 200){
|
||||
xhr.open('GET', url + '?info', true);
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
try {
|
||||
if (xhr.readyState === 4 && xhr.status === 200) {
|
||||
var response = JSON.parse(xhr.responseText);
|
||||
|
||||
|
||||
var geometry = new Potree.PointCloudArena4DGeometry();
|
||||
geometry.url = url;
|
||||
geometry.name = response.Name;
|
||||
@ -197,82 +188,79 @@ Potree.PointCloudArena4DGeometry.load = function(url, callback){
|
||||
geometry.numPoints = response.Points;
|
||||
geometry.version = response.Version;
|
||||
geometry.boundingBox = new THREE.Box3(
|
||||
new THREE.Vector3().fromArray(response.BoundingBox.slice(0,3)),
|
||||
new THREE.Vector3().fromArray(response.BoundingBox.slice(3,6))
|
||||
new THREE.Vector3().fromArray(response.BoundingBox.slice(0, 3)),
|
||||
new THREE.Vector3().fromArray(response.BoundingBox.slice(3, 6))
|
||||
);
|
||||
if(response.Spacing){
|
||||
if (response.Spacing) {
|
||||
geometry.spacing = response.Spacing;
|
||||
}
|
||||
|
||||
|
||||
var offset = geometry.boundingBox.min.clone().multiplyScalar(-1);
|
||||
|
||||
|
||||
geometry.boundingBox.min.add(offset);
|
||||
geometry.boundingBox.max.add(offset);
|
||||
geometry.offset = offset;
|
||||
|
||||
|
||||
var center = geometry.boundingBox.getCenter();
|
||||
var radius = geometry.boundingBox.getSize().length() / 2;
|
||||
geometry.boundingSphere = new THREE.Sphere(center, radius);
|
||||
|
||||
|
||||
geometry.loadHierarchy();
|
||||
|
||||
|
||||
callback(geometry);
|
||||
}else if(xhr.readyState === 4){
|
||||
} else if (xhr.readyState === 4) {
|
||||
callback(null);
|
||||
}
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
callback(null);
|
||||
}
|
||||
};
|
||||
|
||||
xhr.send(null);
|
||||
|
||||
xhr.send(null);
|
||||
};
|
||||
|
||||
Potree.PointCloudArena4DGeometry.prototype.loadHierarchy = function(){
|
||||
var url = this.url + "?tree";
|
||||
Potree.PointCloudArena4DGeometry.prototype.loadHierarchy = function () {
|
||||
var url = this.url + '?tree';
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
|
||||
var scope = this;
|
||||
|
||||
xhr.onreadystatechange = function(){
|
||||
if(!(xhr.readyState === 4 && xhr.status === 200)){
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (!(xhr.readyState === 4 && xhr.status === 200)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var buffer = xhr.response;
|
||||
var numNodes = buffer.byteLength / 3;
|
||||
var view = new DataView(buffer);
|
||||
var stack = [];
|
||||
var root = null;
|
||||
|
||||
|
||||
var levels = 0;
|
||||
|
||||
var start = new Date().getTime();
|
||||
|
||||
// TODO Debug: var start = new Date().getTime();
|
||||
// read hierarchy
|
||||
for(var i = 0; i < numNodes; i++){
|
||||
var mask = view.getUint8(i*3+0, true);
|
||||
var numPoints = view.getUint16(i*3+1, true);
|
||||
|
||||
|
||||
for (var i = 0; i < numNodes; i++) {
|
||||
var mask = view.getUint8(i * 3 + 0, true);
|
||||
// TODO Unused: var numPoints = view.getUint16(i * 3 + 1, true);
|
||||
|
||||
var hasLeft = (mask & 1) > 0;
|
||||
var hasRight = (mask & 2) > 0;
|
||||
var splitX = (mask & 4) > 0;
|
||||
var splitY = (mask & 8) > 0;
|
||||
var splitZ = (mask & 16) > 0;
|
||||
var split = null;
|
||||
if(splitX){
|
||||
split = "X";
|
||||
}else if(splitY){
|
||||
split = "Y";
|
||||
}if(splitZ){
|
||||
split = "Z";
|
||||
if (splitX) {
|
||||
split = 'X';
|
||||
} else if (splitY) {
|
||||
split = 'Y';
|
||||
} if (splitZ) {
|
||||
split = 'Z';
|
||||
}
|
||||
|
||||
|
||||
|
||||
var node = new Potree.PointCloudArena4DGeometryNode();
|
||||
node.hasLeft = hasLeft;
|
||||
node.hasRight = hasRight;
|
||||
@ -284,99 +272,94 @@ Potree.PointCloudArena4DGeometry.prototype.loadHierarchy = function(){
|
||||
node.pcoGeometry = scope;
|
||||
node.level = stack.length;
|
||||
levels = Math.max(levels, node.level);
|
||||
|
||||
if(stack.length > 0){
|
||||
var parent = stack[stack.length-1];
|
||||
|
||||
if (stack.length > 0) {
|
||||
var parent = stack[stack.length - 1];
|
||||
node.boundingBox = parent.boundingBox.clone();
|
||||
var parentBBSize = parent.boundingBox.getSize();
|
||||
|
||||
if(parent.hasLeft && !parent.left){
|
||||
|
||||
if (parent.hasLeft && !parent.left) {
|
||||
parent.left = node;
|
||||
parent.children.push(node);
|
||||
|
||||
if(parent.split === "X"){
|
||||
|
||||
if (parent.split === 'X') {
|
||||
node.boundingBox.max.x = node.boundingBox.min.x + parentBBSize.x / 2;
|
||||
}else if(parent.split === "Y"){
|
||||
} else if (parent.split === 'Y') {
|
||||
node.boundingBox.max.y = node.boundingBox.min.y + parentBBSize.y / 2;
|
||||
}else if(parent.split === "Z"){
|
||||
} else if (parent.split === 'Z') {
|
||||
node.boundingBox.max.z = node.boundingBox.min.z + parentBBSize.z / 2;
|
||||
}
|
||||
|
||||
var center = node.boundingBox.getCenter();
|
||||
var radius = node.boundingBox.getSize().length() / 2;
|
||||
|
||||
let center = node.boundingBox.getCenter();
|
||||
let radius = node.boundingBox.getSize().length() / 2;
|
||||
node.boundingSphere = new THREE.Sphere(center, radius);
|
||||
|
||||
}else{
|
||||
} else {
|
||||
parent.right = node;
|
||||
parent.children.push(node);
|
||||
|
||||
if(parent.split === "X"){
|
||||
|
||||
if (parent.split === 'X') {
|
||||
node.boundingBox.min.x = node.boundingBox.min.x + parentBBSize.x / 2;
|
||||
}else if(parent.split === "Y"){
|
||||
} else if (parent.split === 'Y') {
|
||||
node.boundingBox.min.y = node.boundingBox.min.y + parentBBSize.y / 2;
|
||||
}else if(parent.split === "Z"){
|
||||
} else if (parent.split === 'Z') {
|
||||
node.boundingBox.min.z = node.boundingBox.min.z + parentBBSize.z / 2;
|
||||
}
|
||||
|
||||
var center = node.boundingBox.getCenter();
|
||||
var radius = node.boundingBox.getSize().length() / 2;
|
||||
|
||||
let center = node.boundingBox.getCenter();
|
||||
let radius = node.boundingBox.getSize().length() / 2;
|
||||
node.boundingSphere = new THREE.Sphere(center, radius);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
root = node;
|
||||
root.boundingBox = scope.boundingBox.clone();
|
||||
var center = root.boundingBox.getCenter();
|
||||
var radius = root.boundingBox.getSize().length() / 2;
|
||||
root.boundingSphere = new THREE.Sphere(center, radius);
|
||||
}
|
||||
|
||||
|
||||
var bbSize = node.boundingBox.getSize();
|
||||
node.spacing = ((bbSize.x + bbSize.y + bbSize.z) / 3) / 75;
|
||||
|
||||
|
||||
stack.push(node);
|
||||
|
||||
if(node.isLeaf){
|
||||
|
||||
if (node.isLeaf) {
|
||||
var done = false;
|
||||
while(!done && stack.length > 0){
|
||||
while (!done && stack.length > 0) {
|
||||
stack.pop();
|
||||
|
||||
var top = stack[stack.length-1];
|
||||
|
||||
|
||||
var top = stack[stack.length - 1];
|
||||
|
||||
done = stack.length > 0 && top.hasRight && top.right == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
var end = new Date().getTime();
|
||||
var parseDuration = end - start;
|
||||
var msg = parseDuration;
|
||||
//document.getElementById("lblDebug").innerHTML = msg;
|
||||
|
||||
// TODO Debug:
|
||||
// var end = new Date().getTime();
|
||||
// var parseDuration = end - start;
|
||||
// var msg = parseDuration;
|
||||
// document.getElementById("lblDebug").innerHTML = msg;
|
||||
|
||||
scope.root = root;
|
||||
scope.levels = levels;
|
||||
//console.log(this.root);
|
||||
|
||||
scope.dispatchEvent({type: "hierarchy_loaded"});
|
||||
|
||||
// console.log(this.root);
|
||||
|
||||
scope.dispatchEvent({type: 'hierarchy_loaded'});
|
||||
};
|
||||
|
||||
|
||||
xhr.send(null);
|
||||
|
||||
|
||||
};
|
||||
|
||||
Object.defineProperty(Potree.PointCloudArena4DGeometry.prototype, "spacing", {
|
||||
get: function(){
|
||||
if(this._spacing){
|
||||
Object.defineProperty(Potree.PointCloudArena4DGeometry.prototype, 'spacing', {
|
||||
get: function () {
|
||||
if (this._spacing) {
|
||||
return this._spacing;
|
||||
}else if(this.root){
|
||||
} else if (this.root) {
|
||||
return this.root.spacing;
|
||||
}else{
|
||||
null;
|
||||
} else {
|
||||
// TODO ???: null;
|
||||
}
|
||||
},
|
||||
set: function(value){
|
||||
set: function (value) {
|
||||
this._spacing = value;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -1,52 +1,49 @@
|
||||
|
||||
Potree.CSVExporter = class CSVExporter{
|
||||
|
||||
static toString(points){
|
||||
let string = "";
|
||||
|
||||
Potree.CSVExporter = class CSVExporter {
|
||||
static toString (points) {
|
||||
let string = '';
|
||||
|
||||
let attributes = Object.keys(points.data)
|
||||
.filter(a => a !== "normal")
|
||||
.filter(a => a !== 'normal')
|
||||
.sort((a, b) => {
|
||||
if(a === "position") return -1;
|
||||
if(b === "position") return 1;
|
||||
if(a === "color") return -1;
|
||||
if(b === "color") return 1;
|
||||
if (a === 'position') return -1;
|
||||
if (b === 'position') return 1;
|
||||
if (a === 'color') return -1;
|
||||
if (b === 'color') return 1;
|
||||
});
|
||||
|
||||
|
||||
let headerValues = [];
|
||||
for(let attribute of attributes){
|
||||
for (let attribute of attributes) {
|
||||
let itemSize = points.data[attribute].length / points.numPoints;
|
||||
|
||||
if(attribute === "position"){
|
||||
headerValues = headerValues.concat(["x", "y", "z"]);
|
||||
}else if(attribute === "color"){
|
||||
headerValues = headerValues.concat(["r", "g", "b"]);
|
||||
}else if(itemSize > 1){
|
||||
for(let i = 0; i < itemSize; i++){
|
||||
|
||||
if (attribute === 'position') {
|
||||
headerValues = headerValues.concat(['x', 'y', 'z']);
|
||||
} else if (attribute === 'color') {
|
||||
headerValues = headerValues.concat(['r', 'g', 'b']);
|
||||
} else if (itemSize > 1) {
|
||||
for (let i = 0; i < itemSize; i++) {
|
||||
headerValues.push(`${attribute}_${i}`);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
headerValues.push(attribute);
|
||||
}
|
||||
}
|
||||
string = headerValues.join(", ") + "\n";
|
||||
string = headerValues.join(', ') + '\n';
|
||||
|
||||
for(let i = 0; i < points.numPoints; i++){
|
||||
|
||||
for (let i = 0; i < points.numPoints; i++) {
|
||||
let values = [];
|
||||
|
||||
for(let attribute of attributes){
|
||||
|
||||
for (let attribute of attributes) {
|
||||
let itemSize = points.data[attribute].length / points.numPoints;
|
||||
let value = points.data[attribute]
|
||||
.subarray(itemSize * i, itemSize * i + itemSize)
|
||||
.join(", ");
|
||||
.join(', ');
|
||||
values.push(value);
|
||||
}
|
||||
|
||||
string += values.join(", ") + "\n";
|
||||
|
||||
string += values.join(', ') + '\n';
|
||||
}
|
||||
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,21 +1,19 @@
|
||||
/**
|
||||
*
|
||||
* @author sigeom sa / http://sigeom.ch
|
||||
* @author Ioda-Net Sàrl / https://www.ioda-net.ch/
|
||||
* @author Markus Schütz / http://potree.org
|
||||
* @author Ioda-Net Sàrl / https://www.ioda-net.ch/
|
||||
* @author Markus Schuetz / http://potree.org
|
||||
*
|
||||
*/
|
||||
|
||||
Potree.DXFExporter = class DXFExporter{
|
||||
|
||||
static measurementPointSection(measurement){
|
||||
|
||||
Potree.DXFExporter = class DXFExporter {
|
||||
static measurementPointSection (measurement) {
|
||||
let position = measurement.points[0].position;
|
||||
|
||||
if(!position){
|
||||
return "";
|
||||
|
||||
if (!position) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
let dxfSection = `0
|
||||
CIRCLE
|
||||
8
|
||||
@ -32,15 +30,15 @@ ${position.z}
|
||||
|
||||
return dxfSection;
|
||||
}
|
||||
|
||||
static measurementPolylineSection(measurement){
|
||||
// bit code for polygons/polylines:
|
||||
|
||||
static measurementPolylineSection (measurement) {
|
||||
// bit code for polygons/polylines:
|
||||
// https://www.autodesk.com/techpubs/autocad/acad2000/dxf/polyline_dxf_06.htm
|
||||
let geomCode = 8;
|
||||
if(measurement.closed){
|
||||
let geomCode = 8;
|
||||
if (measurement.closed) {
|
||||
geomCode += 1;
|
||||
}
|
||||
|
||||
|
||||
let dxfSection = `0
|
||||
POLYLINE
|
||||
8
|
||||
@ -62,12 +60,12 @@ ${geomCode}
|
||||
let xMax = 0.0;
|
||||
let yMax = 0.0;
|
||||
let zMax = 0.0;
|
||||
for(let point of measurement.points){
|
||||
for (let point of measurement.points) {
|
||||
point = point.position;
|
||||
xMax = Math.max(xMax, point.x);
|
||||
yMax = Math.max(yMax, point.y);
|
||||
zMax = Math.max(zMax, point.z);
|
||||
|
||||
|
||||
dxfSection += `0
|
||||
VERTEX
|
||||
8
|
||||
@ -81,52 +79,46 @@ ${point.z}
|
||||
70
|
||||
32
|
||||
`;
|
||||
|
||||
}
|
||||
dxfSection += `0
|
||||
dxfSection += `0
|
||||
SEQEND
|
||||
`;
|
||||
|
||||
return dxfSection;
|
||||
}
|
||||
|
||||
static measurementSection(measurement){
|
||||
|
||||
//if(measurement.points.length <= 1){
|
||||
|
||||
static measurementSection (measurement) {
|
||||
// if(measurement.points.length <= 1){
|
||||
// return "";
|
||||
//}
|
||||
|
||||
if(measurement.points.length === 0){
|
||||
return "";
|
||||
}else if(measurement.points.length === 1){
|
||||
// }
|
||||
|
||||
if (measurement.points.length === 0) {
|
||||
return '';
|
||||
} else if (measurement.points.length === 1) {
|
||||
return Potree.DXFExporter.measurementPointSection(measurement);
|
||||
}else if(measurement.points.length >= 2){
|
||||
} else if (measurement.points.length >= 2) {
|
||||
return Potree.DXFExporter.measurementPolylineSection(measurement);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static toString(measurements){
|
||||
|
||||
if(!(measurements instanceof Array)){
|
||||
|
||||
static toString (measurements) {
|
||||
if (!(measurements instanceof Array)) {
|
||||
measurements = [measurements];
|
||||
}
|
||||
measurements = measurements.filter(m => m instanceof Potree.Measure);
|
||||
|
||||
|
||||
let points = measurements.filter(m => (m instanceof Potree.Measure))
|
||||
.map(m => m.points)
|
||||
.reduce((a, v) => a.concat(v))
|
||||
.map(p => p.position);
|
||||
|
||||
|
||||
let min = new THREE.Vector3(Infinity, Infinity, Infinity);
|
||||
let max = new THREE.Vector3(-Infinity, -Infinity, -Infinity);
|
||||
for(let point of points){
|
||||
for (let point of points) {
|
||||
min.min(point);
|
||||
max.max(point);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
let dxfHeader = `999
|
||||
DXF created from potree
|
||||
0
|
||||
@ -170,19 +162,17 @@ SECTION
|
||||
2
|
||||
ENTITIES
|
||||
`;
|
||||
|
||||
for(let measurement of measurements){
|
||||
|
||||
for (let measurement of measurements) {
|
||||
dxfBody += Potree.DXFExporter.measurementSection(measurement);
|
||||
}
|
||||
|
||||
|
||||
dxfBody += `0
|
||||
ENDSEC
|
||||
`;
|
||||
|
||||
let dxf = dxfHeader + dxfBody + '0\nEOF';
|
||||
|
||||
|
||||
return dxf;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -6,61 +6,58 @@
|
||||
*
|
||||
*/
|
||||
|
||||
Potree.GeoJSONExporter = class GeoJSONExporter{
|
||||
|
||||
static measurementToFeatures(measurement){
|
||||
|
||||
Potree.GeoJSONExporter = class GeoJSONExporter {
|
||||
static measurementToFeatures (measurement) {
|
||||
let coords = measurement.points.map(e => e.position.toArray());
|
||||
|
||||
|
||||
let features = [];
|
||||
|
||||
if(coords.length === 1){
|
||||
|
||||
if (coords.length === 1) {
|
||||
let feature = {
|
||||
type: 'Feature',
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: coords[0],
|
||||
coordinates: coords[0]
|
||||
},
|
||||
properties: {
|
||||
name: measurement.name
|
||||
}
|
||||
};
|
||||
features.push(feature);
|
||||
}else if(coords.length > 1 && !measurement.closed){
|
||||
} else if (coords.length > 1 && !measurement.closed) {
|
||||
let object = {
|
||||
"type": "Feature",
|
||||
"geometry": {
|
||||
"type": "LineString",
|
||||
"coordinates": coords
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'LineString',
|
||||
'coordinates': coords
|
||||
},
|
||||
"properties": {
|
||||
'properties': {
|
||||
name: measurement.name
|
||||
}
|
||||
};
|
||||
|
||||
features.push(object);
|
||||
}else if(coords.length > 1 && measurement.closed){
|
||||
|
||||
features.push(object);
|
||||
} else if (coords.length > 1 && measurement.closed) {
|
||||
let object = {
|
||||
"type": "Feature",
|
||||
"geometry": {
|
||||
"type": "Polygon",
|
||||
"coordinates": [[...coords, coords[0]]]
|
||||
'type': 'Feature',
|
||||
'geometry': {
|
||||
'type': 'Polygon',
|
||||
'coordinates': [[...coords, coords[0]]]
|
||||
},
|
||||
"properties": {
|
||||
'properties': {
|
||||
name: measurement.name
|
||||
}
|
||||
};
|
||||
features.push(object);
|
||||
}
|
||||
|
||||
if(measurement.showDistances){
|
||||
if (measurement.showDistances) {
|
||||
measurement.edgeLabels.forEach((label) => {
|
||||
let labelPoint = {
|
||||
type: 'Feature',
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: label.position.toArray(),
|
||||
coordinates: label.position.toArray()
|
||||
},
|
||||
properties: {
|
||||
distance: label.text
|
||||
@ -69,14 +66,14 @@ Potree.GeoJSONExporter = class GeoJSONExporter{
|
||||
features.push(labelPoint);
|
||||
});
|
||||
}
|
||||
|
||||
if(measurement.showArea){
|
||||
|
||||
if (measurement.showArea) {
|
||||
var point = measurement.areaLabel.position;
|
||||
var labelArea = {
|
||||
type: 'Feature',
|
||||
geometry: {
|
||||
type: 'Point',
|
||||
coordinates: point.toArray(),
|
||||
coordinates: point.toArray()
|
||||
},
|
||||
properties: {
|
||||
area: measurement.areaLabel.text
|
||||
@ -84,33 +81,29 @@ Potree.GeoJSONExporter = class GeoJSONExporter{
|
||||
};
|
||||
features.push(labelArea);
|
||||
}
|
||||
|
||||
|
||||
return features;
|
||||
}
|
||||
|
||||
static toString(measurements){
|
||||
|
||||
if(!(measurements instanceof Array)){
|
||||
|
||||
static toString (measurements) {
|
||||
if (!(measurements instanceof Array)) {
|
||||
measurements = [measurements];
|
||||
}
|
||||
|
||||
|
||||
measurements = measurements.filter(m => m instanceof Potree.Measure);
|
||||
|
||||
|
||||
let features = [];
|
||||
for(let measure of measurements){
|
||||
for (let measure of measurements) {
|
||||
let f = Potree.GeoJSONExporter.measurementToFeatures(measure);
|
||||
|
||||
|
||||
features = features.concat(f);
|
||||
}
|
||||
|
||||
|
||||
let geojson = {
|
||||
"type": "FeatureCollection",
|
||||
"features": features
|
||||
'type': 'FeatureCollection',
|
||||
'features': features
|
||||
};
|
||||
|
||||
return JSON.stringify(geojson, null, "\t");
|
||||
|
||||
return JSON.stringify(geojson, null, '\t');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -1,150 +1,148 @@
|
||||
|
||||
Potree.LASExporter = class LASExporter{
|
||||
|
||||
static toLAS(points){
|
||||
let string = "";
|
||||
|
||||
Potree.LASExporter = class LASExporter {
|
||||
static toLAS (points) {
|
||||
// TODO Unused: let string = '';
|
||||
|
||||
let boundingBox = points.boundingBox;
|
||||
let offset = boundingBox.min.clone();
|
||||
let diagonal = boundingBox.min.distanceTo(boundingBox.max);
|
||||
let scale = new THREE.Vector3(0.001, 0.001, 0.001);
|
||||
if(diagonal > 1000*1000){
|
||||
if (diagonal > 1000 * 1000) {
|
||||
scale = new THREE.Vector3(0.01, 0.01, 0.01);
|
||||
}else{
|
||||
} else {
|
||||
scale = new THREE.Vector3(0.001, 0.001, 0.001);
|
||||
}
|
||||
|
||||
let setString = function(string, offset, buffer){
|
||||
|
||||
let setString = function (string, offset, buffer) {
|
||||
let view = new Uint8Array(buffer);
|
||||
|
||||
for(let i = 0; i < string.length; i++){
|
||||
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
let charCode = string.charCodeAt(i);
|
||||
view[offset + i] = charCode;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
let buffer = new ArrayBuffer(227 + 28 * points.numPoints);
|
||||
let view = new DataView(buffer);
|
||||
let u8View = new Uint8Array(buffer);
|
||||
//let u16View = new Uint16Array(buffer);
|
||||
|
||||
setString("LASF", 0, buffer);
|
||||
// let u16View = new Uint16Array(buffer);
|
||||
|
||||
setString('LASF', 0, buffer);
|
||||
u8View[24] = 1;
|
||||
u8View[25] = 2;
|
||||
|
||||
|
||||
// system identifier o:26 l:32
|
||||
|
||||
|
||||
// generating software o:58 l:32
|
||||
setString("Potree 1.5", 58, buffer);
|
||||
|
||||
setString('Potree 1.5', 58, buffer);
|
||||
|
||||
// file creation day of year o:90 l:2
|
||||
// file creation year o:92 l:2
|
||||
|
||||
|
||||
// header size o:94 l:2
|
||||
view.setUint16(94, 227, true);
|
||||
|
||||
|
||||
// offset to point data o:96 l:4
|
||||
view.setUint32(96, 227, true);
|
||||
|
||||
|
||||
// number of letiable length records o:100 l:4
|
||||
|
||||
|
||||
// point data record format 104 1
|
||||
u8View[104] = 2;
|
||||
|
||||
|
||||
// point data record length 105 2
|
||||
view.setUint16(105, 28, true);
|
||||
|
||||
// number of point records 107 4
|
||||
|
||||
// number of point records 107 4
|
||||
view.setUint32(107, points.numPoints, true);
|
||||
|
||||
|
||||
// number of points by return 111 20
|
||||
|
||||
|
||||
// x scale factor 131 8
|
||||
view.setFloat64(131, scale.x, true);
|
||||
|
||||
|
||||
// y scale factor 139 8
|
||||
view.setFloat64(139, scale.y, true);
|
||||
|
||||
|
||||
// z scale factor 147 8
|
||||
view.setFloat64(147, scale.z, true);
|
||||
|
||||
|
||||
// x offset 155 8
|
||||
view.setFloat64(155, offset.x, true);
|
||||
|
||||
|
||||
// y offset 163 8
|
||||
view.setFloat64(163, offset.y, true);
|
||||
|
||||
|
||||
// z offset 171 8
|
||||
view.setFloat64(171, offset.z, true);
|
||||
|
||||
|
||||
// max x 179 8
|
||||
view.setFloat64(179, boundingBox.max.x, true);
|
||||
|
||||
|
||||
// min x 187 8
|
||||
view.setFloat64(187, boundingBox.min.x, true);
|
||||
|
||||
|
||||
// max y 195 8
|
||||
view.setFloat64(195, boundingBox.max.y, true);
|
||||
|
||||
|
||||
// min y 203 8
|
||||
view.setFloat64(203, boundingBox.min.y, true);
|
||||
|
||||
|
||||
// max z 211 8
|
||||
view.setFloat64(211, boundingBox.max.z, true);
|
||||
|
||||
|
||||
// min z 219 8
|
||||
view.setFloat64(219, boundingBox.min.z, true);
|
||||
|
||||
|
||||
let boffset = 227;
|
||||
for(let i = 0; i < points.numPoints; i++){
|
||||
//let point = points[i];
|
||||
//let position = new THREE.Vector3(point.x, point.y, point.z);
|
||||
|
||||
let px = points.data.position[3*i + 0];
|
||||
let py = points.data.position[3*i + 1];
|
||||
let pz = points.data.position[3*i + 2];
|
||||
|
||||
for (let i = 0; i < points.numPoints; i++) {
|
||||
// let point = points[i];
|
||||
// let position = new THREE.Vector3(point.x, point.y, point.z);
|
||||
|
||||
let px = points.data.position[3 * i + 0];
|
||||
let py = points.data.position[3 * i + 1];
|
||||
let pz = points.data.position[3 * i + 2];
|
||||
|
||||
let ux = parseInt((px - offset.x) / scale.x);
|
||||
let uy = parseInt((py - offset.y) / scale.y);
|
||||
let uz = parseInt((pz - offset.z) / scale.z);
|
||||
|
||||
|
||||
view.setUint32(boffset + 0, ux, true);
|
||||
view.setUint32(boffset + 4, uy, true);
|
||||
view.setUint32(boffset + 8, uz, true);
|
||||
|
||||
if(points.data.intensity){
|
||||
|
||||
if (points.data.intensity) {
|
||||
view.setUint16(boffset + 12, (points.data.intensity[i]), true);
|
||||
}
|
||||
|
||||
|
||||
let rt = 0;
|
||||
if(points.data.returnNumber){
|
||||
if (points.data.returnNumber) {
|
||||
rt += points.data.returnNumber[i];
|
||||
}
|
||||
if(points.data.numberOfReturns){
|
||||
if (points.data.numberOfReturns) {
|
||||
rt += (points.data.numberOfReturns[i] << 3);
|
||||
}
|
||||
view.setUint8(boffset + 14, rt);
|
||||
|
||||
if(points.data.classification){
|
||||
|
||||
if (points.data.classification) {
|
||||
view.setUint8(boffset + 15, points.data.classification[i]);
|
||||
}
|
||||
// scan angle rank
|
||||
// user data
|
||||
// point source id
|
||||
if(points.data.pointSourceID){
|
||||
if (points.data.pointSourceID) {
|
||||
view.setUint16(boffset + 18, points.data.pointSourceID[i]);
|
||||
}
|
||||
|
||||
if(points.data.color){
|
||||
view.setUint16(boffset + 20, (points.data.color[3*i + 0] * 255), true);
|
||||
view.setUint16(boffset + 22, (points.data.color[3*i + 1] * 255), true);
|
||||
view.setUint16(boffset + 24, (points.data.color[3*i + 2] * 255), true);
|
||||
|
||||
if (points.data.color) {
|
||||
view.setUint16(boffset + 20, (points.data.color[3 * i + 0] * 255), true);
|
||||
view.setUint16(boffset + 22, (points.data.color[3 * i + 1] * 255), true);
|
||||
view.setUint16(boffset + 24, (points.data.color[3 * i + 2] * 255), true);
|
||||
}
|
||||
|
||||
|
||||
boffset += 28;
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,16 +1,10 @@
|
||||
|
||||
THREE.EventDispatcher.prototype.removeEventListeners = function(type){
|
||||
|
||||
if ( this._listeners === undefined ) {
|
||||
|
||||
THREE.EventDispatcher.prototype.removeEventListeners = function (type) {
|
||||
if (this._listeners === undefined) {
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if ( this._listeners[ type ] ) {
|
||||
|
||||
|
||||
if (this._listeners[ type ]) {
|
||||
delete this._listeners[ type ];
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,47 +1,42 @@
|
||||
|
||||
|
||||
THREE.PerspectiveCamera.prototype.zoomTo = function( node, factor ){
|
||||
|
||||
if ( !node.geometry && !node.boundingSphere && !node.boundingBox) {
|
||||
THREE.PerspectiveCamera.prototype.zoomTo = function (node, factor) {
|
||||
if (!node.geometry && !node.boundingSphere && !node.boundingBox) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( node.geometry && node.geometry.boundingSphere === null ) {
|
||||
|
||||
if (node.geometry && node.geometry.boundingSphere === null) {
|
||||
node.geometry.computeBoundingSphere();
|
||||
}
|
||||
|
||||
|
||||
node.updateMatrixWorld();
|
||||
|
||||
|
||||
var bs;
|
||||
|
||||
if(node.boundingSphere){
|
||||
|
||||
if (node.boundingSphere) {
|
||||
bs = node.boundingSphere;
|
||||
}else if(node.geometry && node.geometry.boundingSphere){
|
||||
} else if (node.geometry && node.geometry.boundingSphere) {
|
||||
bs = node.geometry.boundingSphere;
|
||||
}else{
|
||||
} else {
|
||||
bs = node.boundingBox.getBoundingSphere();
|
||||
}
|
||||
|
||||
var _factor = factor || 1;
|
||||
|
||||
bs = bs.clone().applyMatrix4(node.matrixWorld);
|
||||
|
||||
bs = bs.clone().applyMatrix4(node.matrixWorld);
|
||||
var radius = bs.radius;
|
||||
var fovr = this.fov * Math.PI / 180;
|
||||
|
||||
if( this.aspect < 1 ){
|
||||
|
||||
if (this.aspect < 1) {
|
||||
fovr = fovr * this.aspect;
|
||||
}
|
||||
|
||||
var distanceFactor = Math.abs( radius / Math.sin( fovr / 2 ) ) * _factor ;
|
||||
|
||||
var offset = this.getWorldDirection().multiplyScalar( -distanceFactor );
|
||||
this.position.copy(bs.center.clone().add( offset ));
|
||||
|
||||
|
||||
var distanceFactor = Math.abs(radius / Math.sin(fovr / 2)) * _factor;
|
||||
|
||||
var offset = this.getWorldDirection().multiplyScalar(-distanceFactor);
|
||||
this.position.copy(bs.center.clone().add(offset));
|
||||
};
|
||||
|
||||
|
||||
|
||||
//THREE.PerspectiveCamera.prototype.zoomTo = function(node, factor){
|
||||
// THREE.PerspectiveCamera.prototype.zoomTo = function(node, factor){
|
||||
// if(factor === undefined){
|
||||
// factor = 1;
|
||||
// }
|
||||
@ -49,11 +44,11 @@ THREE.PerspectiveCamera.prototype.zoomTo = function( node, factor ){
|
||||
// node.updateMatrixWorld();
|
||||
// this.updateMatrix();
|
||||
// this.updateMatrixWorld();
|
||||
//
|
||||
//
|
||||
// var box = Potree.utils.computeTransformedBoundingBox(node.boundingBox, node.matrixWorld);
|
||||
// var dir = new THREE.Vector3(0, 0, -1).applyQuaternion(this.quaternion);
|
||||
// var pos = box.center().sub(dir);
|
||||
//
|
||||
//
|
||||
// var ps = [
|
||||
// new THREE.Vector3(box.min.x, box.min.y, box.min.z),
|
||||
// new THREE.Vector3(box.min.x, box.min.y, box.min.z),
|
||||
@ -65,14 +60,14 @@ THREE.PerspectiveCamera.prototype.zoomTo = function( node, factor ){
|
||||
// new THREE.Vector3(box.max.x, box.min.y, box.max.z),
|
||||
// new THREE.Vector3(box.max.x, box.max.y, box.max.z)
|
||||
// ];
|
||||
//
|
||||
//
|
||||
// var frustum = new THREE.Frustum();
|
||||
// frustum.setFromMatrix(new THREE.Matrix4().multiplyMatrices(this.projectionMatrix, this.matrixWorldInverse));
|
||||
//
|
||||
//
|
||||
// var max = Number.MIN_VALUE;
|
||||
// for(var i = 0; i < ps.length; i++){
|
||||
// var p = ps[i];
|
||||
//
|
||||
//
|
||||
// var distance = Number.MIN_VALUE;
|
||||
// // iterate through left, right, top and bottom planes
|
||||
// for(var j = 0; j < frustum.planes.length-2; j++){
|
||||
@ -87,5 +82,5 @@ THREE.PerspectiveCamera.prototype.zoomTo = function( node, factor ){
|
||||
// offset.multiplyScalar(factor);
|
||||
// pos.add(offset);
|
||||
// this.position.copy(pos);
|
||||
//
|
||||
//}
|
||||
//
|
||||
// }
|
||||
|
||||
@ -1,16 +1,15 @@
|
||||
THREE.Ray.prototype.distanceToPlaneWithNegative = function ( plane ) {
|
||||
var denominator = plane.normal.dot( this.direction );
|
||||
if ( denominator === 0 ) {
|
||||
|
||||
THREE.Ray.prototype.distanceToPlaneWithNegative = function (plane) {
|
||||
var denominator = plane.normal.dot(this.direction);
|
||||
if (denominator === 0) {
|
||||
// line is coplanar, return origin
|
||||
if( plane.distanceToPoint( this.origin ) === 0 ) {
|
||||
if (plane.distanceToPoint(this.origin) === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Null is preferable to undefined since undefined means.... it is undefined
|
||||
return null;
|
||||
}
|
||||
var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
|
||||
var t = -(this.origin.dot(plane.normal) + plane.constant) / denominator;
|
||||
|
||||
return t;
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
|
||||
Potree.BinaryLoader = function(version, boundingBox, scale){
|
||||
if(typeof(version) === "string"){
|
||||
Potree.BinaryLoader = function (version, boundingBox, scale) {
|
||||
if (typeof (version) === 'string') {
|
||||
this.version = new Potree.Version(version);
|
||||
}else{
|
||||
} else {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@ -10,8 +10,8 @@ Potree.BinaryLoader = function(version, boundingBox, scale){
|
||||
this.scale = scale;
|
||||
};
|
||||
|
||||
Potree.BinaryLoader.prototype.load = function(node){
|
||||
if(node.loaded){
|
||||
Potree.BinaryLoader.prototype.load = function (node) {
|
||||
if (node.loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -19,44 +19,43 @@ Potree.BinaryLoader.prototype.load = function(node){
|
||||
|
||||
let url = node.getURL();
|
||||
|
||||
if(this.version.equalOrHigher("1.4")){
|
||||
url += ".bin";
|
||||
if (this.version.equalOrHigher('1.4')) {
|
||||
url += '.bin';
|
||||
}
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
xhr.onreadystatechange = function() {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
let buffer = xhr.response;
|
||||
scope.parse(node, buffer);
|
||||
} else {
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + url);
|
||||
}
|
||||
}
|
||||
};
|
||||
try{
|
||||
try {
|
||||
xhr.send(null);
|
||||
}catch(e){
|
||||
console.log("fehler beim laden der punktwolke: " + e);
|
||||
} catch (e) {
|
||||
console.log('fehler beim laden der punktwolke: ' + e);
|
||||
}
|
||||
};
|
||||
|
||||
Potree.BinaryLoader.prototype.parse = function(node, buffer){
|
||||
|
||||
Potree.BinaryLoader.prototype.parse = function (node, buffer) {
|
||||
let numPoints = buffer.byteLength / node.pcoGeometry.pointAttributes.byteSize;
|
||||
let pointAttributes = node.pcoGeometry.pointAttributes;
|
||||
|
||||
if(this.version.upTo("1.5")){
|
||||
if (this.version.upTo('1.5')) {
|
||||
node.numPoints = numPoints;
|
||||
}
|
||||
|
||||
let workerPath = Potree.scriptPath + "/workers/BinaryDecoderWorker.js";
|
||||
let workerPath = Potree.scriptPath + '/workers/BinaryDecoderWorker.js';
|
||||
let worker = Potree.workerPool.getWorker(workerPath);
|
||||
|
||||
worker.onmessage = function(e){
|
||||
|
||||
worker.onmessage = function (e) {
|
||||
let data = e.data;
|
||||
let buffers = data.attributeBuffers;
|
||||
let tightBoundingBox = new THREE.Box3(
|
||||
@ -68,38 +67,38 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){
|
||||
|
||||
let geometry = new THREE.BufferGeometry();
|
||||
|
||||
for(let property in buffers){
|
||||
if(buffers.hasOwnProperty(property)){
|
||||
for (let property in buffers) {
|
||||
if (buffers.hasOwnProperty(property)) {
|
||||
let buffer = buffers[property].buffer;
|
||||
let attribute = buffers[property].attribute;
|
||||
let numElements = attribute.numElements;
|
||||
// TODO Unused: let attribute = buffers[property].attribute;
|
||||
// TODO Unused: let numElements = attribute.numElements;
|
||||
|
||||
if(parseInt(property) === Potree.PointAttributeNames.POSITION_CARTESIAN){
|
||||
geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.COLOR_PACKED){
|
||||
geometry.addAttribute("color", new THREE.BufferAttribute(new Uint8Array(buffer), 3, true));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.INTENSITY){
|
||||
geometry.addAttribute("intensity", new THREE.BufferAttribute(new Float32Array(buffer), 1));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.CLASSIFICATION){
|
||||
geometry.addAttribute("classification", new THREE.BufferAttribute(new Uint8Array(buffer), 1));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.NORMAL_SPHEREMAPPED){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.NORMAL_OCT16){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}else if(parseInt(property) === Potree.PointAttributeNames.NORMAL){
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
if (parseInt(property) === Potree.PointAttributeNames.POSITION_CARTESIAN) {
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
} else if (parseInt(property) === Potree.PointAttributeNames.COLOR_PACKED) {
|
||||
geometry.addAttribute('color', new THREE.BufferAttribute(new Uint8Array(buffer), 3, true));
|
||||
} else if (parseInt(property) === Potree.PointAttributeNames.INTENSITY) {
|
||||
geometry.addAttribute('intensity', new THREE.BufferAttribute(new Float32Array(buffer), 1));
|
||||
} else if (parseInt(property) === Potree.PointAttributeNames.CLASSIFICATION) {
|
||||
geometry.addAttribute('classification', new THREE.BufferAttribute(new Uint8Array(buffer), 1));
|
||||
} else if (parseInt(property) === Potree.PointAttributeNames.NORMAL_SPHEREMAPPED) {
|
||||
geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
} else if (parseInt(property) === Potree.PointAttributeNames.NORMAL_OCT16) {
|
||||
geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
} else if (parseInt(property) === Potree.PointAttributeNames.NORMAL) {
|
||||
geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}
|
||||
}
|
||||
}
|
||||
let indicesAttribute = new THREE.Uint8BufferAttribute(data.indices, 4);
|
||||
indicesAttribute.normalized = true;
|
||||
geometry.addAttribute("indices", indicesAttribute);
|
||||
geometry.addAttribute('indices', indicesAttribute);
|
||||
|
||||
if(!geometry.attributes.normal){
|
||||
let buffer = new Float32Array(numPoints*3);
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
if (!geometry.attributes.normal) {
|
||||
let buffer = new Float32Array(numPoints * 3);
|
||||
geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(buffer), 3));
|
||||
}
|
||||
|
||||
|
||||
tightBoundingBox.max.sub(tightBoundingBox.min);
|
||||
tightBoundingBox.min.set(0, 0, 0);
|
||||
|
||||
@ -121,5 +120,4 @@ Potree.BinaryLoader.prototype.parse = function(node, buffer){
|
||||
scale: this.scale
|
||||
};
|
||||
worker.postMessage(message, [message.buffer]);
|
||||
|
||||
};
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
function networkToNative(val) {
|
||||
return ((val & 0x00FF) << 24) |
|
||||
((val & 0xFF00) << 8) |
|
||||
((val >> 8) & 0xFF00) |
|
||||
((val >> 24) & 0x00FF);
|
||||
function networkToNative (val) {
|
||||
return ((val & 0x00FF) << 24) |
|
||||
((val & 0xFF00) << 8) |
|
||||
((val >> 8) & 0xFF00) |
|
||||
((val >> 24) & 0x00FF);
|
||||
}
|
||||
|
||||
Potree.GreyhoundBinaryLoader = function(version, boundingBox, scale){
|
||||
if (typeof(version) === "string") {
|
||||
Potree.GreyhoundBinaryLoader = function (version, boundingBox, scale) {
|
||||
if (typeof (version) === 'string') {
|
||||
this.version = new Potree.Version(version);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
@ -17,10 +16,10 @@ Potree.GreyhoundBinaryLoader = function(version, boundingBox, scale){
|
||||
this.scale = scale;
|
||||
};
|
||||
|
||||
Potree.GreyhoundBinaryLoader.prototype.load = function(node){
|
||||
Potree.GreyhoundBinaryLoader.prototype.load = function (node) {
|
||||
if (node.loaded) return;
|
||||
|
||||
var scope = this;
|
||||
var scope = this;
|
||||
var url = node.getURL();
|
||||
|
||||
var xhr = new XMLHttpRequest();
|
||||
@ -28,42 +27,40 @@ Potree.GreyhoundBinaryLoader.prototype.load = function(node){
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
var buffer = xhr.response;
|
||||
scope.parse(node, buffer);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
console.log(
|
||||
'Failed to load file! HTTP status:', xhr.status,
|
||||
'file:', url);
|
||||
'Failed to load file! HTTP status:', xhr.status,
|
||||
'file:', url);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
xhr.send(null);
|
||||
}
|
||||
catch(e) {
|
||||
console.log("error loading point cloud: " + e);
|
||||
} catch (e) {
|
||||
console.log('error loading point cloud: ' + e);
|
||||
}
|
||||
};
|
||||
|
||||
Potree.GreyhoundBinaryLoader.prototype.parse = function(node, buffer){
|
||||
Potree.GreyhoundBinaryLoader.prototype.parse = function (node, buffer) {
|
||||
var NUM_POINTS_BYTES = 4;
|
||||
|
||||
var view = new DataView(
|
||||
buffer, buffer.byteLength - NUM_POINTS_BYTES, NUM_POINTS_BYTES);
|
||||
var numPoints = networkToNative(view.getUint32(0));
|
||||
var view = new DataView(
|
||||
buffer, buffer.byteLength - NUM_POINTS_BYTES, NUM_POINTS_BYTES);
|
||||
var numPoints = networkToNative(view.getUint32(0));
|
||||
var pointAttributes = node.pcoGeometry.pointAttributes;
|
||||
|
||||
node.numPoints = numPoints;
|
||||
node.numPoints = numPoints;
|
||||
|
||||
let workerPath = Potree.scriptPath + "/workers/GreyhoundBinaryDecoderWorker.js";
|
||||
let workerPath = Potree.scriptPath + '/workers/GreyhoundBinaryDecoderWorker.js';
|
||||
let worker = Potree.workerPool.getWorker(workerPath);
|
||||
|
||||
worker.onmessage = function(e){
|
||||
worker.onmessage = function (e) {
|
||||
var data = e.data;
|
||||
var buffers = data.attributeBuffers;
|
||||
var tightBoundingBox = new THREE.Box3(
|
||||
@ -75,56 +72,56 @@ Potree.GreyhoundBinaryLoader.prototype.parse = function(node, buffer){
|
||||
|
||||
var geometry = new THREE.BufferGeometry();
|
||||
|
||||
var addAttribute = function(name, buffer, size) {
|
||||
geometry.addAttribute(
|
||||
name,
|
||||
new THREE.BufferAttribute(new Float32Array(buffer), size));
|
||||
};
|
||||
var addAttribute = function (name, buffer, size) {
|
||||
geometry.addAttribute(
|
||||
name,
|
||||
new THREE.BufferAttribute(new Float32Array(buffer), size));
|
||||
};
|
||||
|
||||
for (var property in buffers) {
|
||||
if (buffers.hasOwnProperty(property)) {
|
||||
var buffer = buffers[property].buffer;
|
||||
var attribute = buffers[property].attribute;
|
||||
var numElements = attribute.numElements;
|
||||
// TODO Unused: var attribute = buffers[property].attribute;
|
||||
// TODO Unused: var numElements = attribute.numElements;
|
||||
|
||||
var pointAttributes = Potree.PointAttributeNames;
|
||||
var pointAttributes = Potree.PointAttributeNames;
|
||||
|
||||
switch (parseInt(property)) {
|
||||
case pointAttributes.POSITION_CARTESIAN:
|
||||
addAttribute('position', buffer, 3);
|
||||
//let fb = new Float32Array(buffer);
|
||||
//console.log(fb);
|
||||
break;
|
||||
case pointAttributes.COLOR_PACKED:
|
||||
geometry.addAttribute("color",
|
||||
switch (parseInt(property)) {
|
||||
case pointAttributes.POSITION_CARTESIAN:
|
||||
addAttribute('position', buffer, 3);
|
||||
// let fb = new Float32Array(buffer);
|
||||
// console.log(fb);
|
||||
break;
|
||||
case pointAttributes.COLOR_PACKED:
|
||||
geometry.addAttribute('color',
|
||||
new THREE.BufferAttribute(new Uint8Array(buffer), 3, true));
|
||||
break;
|
||||
case pointAttributes.INTENSITY:
|
||||
addAttribute('intensity', buffer, 1);
|
||||
break;
|
||||
case pointAttributes.CLASSIFICATION:
|
||||
addAttribute('classification', buffer, 1);
|
||||
break;
|
||||
case pointAttributes.NORMAL_SPHEREMAPPED:
|
||||
case pointAttributes.NORMAL_OCT16:
|
||||
case pointAttributes.NORMAL:
|
||||
addAttribute('normal', buffer, 3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case pointAttributes.INTENSITY:
|
||||
addAttribute('intensity', buffer, 1);
|
||||
break;
|
||||
case pointAttributes.CLASSIFICATION:
|
||||
addAttribute('classification', buffer, 1);
|
||||
break;
|
||||
case pointAttributes.NORMAL_SPHEREMAPPED:
|
||||
case pointAttributes.NORMAL_OCT16:
|
||||
case pointAttributes.NORMAL:
|
||||
addAttribute('normal', buffer, 3);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//addAttribute('indices', data.indices, 1);
|
||||
|
||||
// addAttribute('indices', data.indices, 1);
|
||||
|
||||
let indicesAttribute = new THREE.Uint8BufferAttribute(data.indices, 4);
|
||||
indicesAttribute.normalized = true;
|
||||
geometry.addAttribute("indices", indicesAttribute);
|
||||
geometry.addAttribute('indices', indicesAttribute);
|
||||
|
||||
if (!geometry.attributes.normal) {
|
||||
addAttribute('normal', new Float32Array(numPoints * 3), 3);
|
||||
}
|
||||
addAttribute('normal', new Float32Array(numPoints * 3), 3);
|
||||
}
|
||||
|
||||
geometry.boundingBox = node.boundingBox;
|
||||
node.geometry = geometry;
|
||||
@ -134,27 +131,25 @@ Potree.GreyhoundBinaryLoader.prototype.parse = function(node, buffer){
|
||||
--node.pcoGeometry.numNodesLoading;
|
||||
};
|
||||
|
||||
var bb = node.boundingBox;
|
||||
var pco = node.pcoGeometry;
|
||||
var bb = node.boundingBox;
|
||||
// TODO Unused: var pco = node.pcoGeometry;
|
||||
|
||||
|
||||
//let nodeOffset = node.boundingBox.getCenter();
|
||||
//let nodeOffset = new THREE.Vector3(0, 0, 0);
|
||||
// let nodeOffset = node.boundingBox.getCenter();
|
||||
// let nodeOffset = new THREE.Vector3(0, 0, 0);
|
||||
let nodeOffset = node.pcoGeometry.boundingBox.getCenter().sub(node.boundingBox.min);
|
||||
//let nodeOffset = node.pcoGeometry.boundingBox.min;
|
||||
// let nodeOffset = node.pcoGeometry.boundingBox.min;
|
||||
|
||||
var message = {
|
||||
buffer: buffer,
|
||||
pointAttributes: pointAttributes,
|
||||
version: this.version.version,
|
||||
schema: node.pcoGeometry.schema,
|
||||
schema: node.pcoGeometry.schema,
|
||||
min: [bb.min.x, bb.min.y, bb.min.z],
|
||||
max: [bb.max.x, bb.max.y, bb.max.z],
|
||||
offset: nodeOffset.toArray(),
|
||||
scale: this.scale,
|
||||
normalize: node.pcoGeometry.normalize
|
||||
scale: this.scale,
|
||||
normalize: node.pcoGeometry.normalize
|
||||
};
|
||||
|
||||
worker.postMessage(message, [message.buffer]);
|
||||
};
|
||||
|
||||
|
||||
@ -6,22 +6,21 @@
|
||||
* @author Connor Manning
|
||||
*/
|
||||
|
||||
class GreyhoundUtils{
|
||||
|
||||
static getQueryParam(name) {
|
||||
name = name.replace(/[\[\]]/g, "\\$&");
|
||||
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
|
||||
results = regex.exec(window.location.href);
|
||||
class GreyhoundUtils {
|
||||
static getQueryParam (name) {
|
||||
name = name.replace(/[[\]]/g, '\\$&');
|
||||
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
|
||||
var results = regex.exec(window.location.href);
|
||||
if (!results) return null;
|
||||
if (!results[2]) return '';
|
||||
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
||||
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
||||
}
|
||||
|
||||
static createSchema(attributes) {
|
||||
|
||||
static createSchema (attributes) {
|
||||
var schema = [
|
||||
{ "name": "X", "size": 4, "type": "signed" },
|
||||
{ "name": "Y", "size": 4, "type": "signed" },
|
||||
{ "name": "Z", "size": 4, "type": "signed" }
|
||||
{ 'name': 'X', 'size': 4, 'type': 'signed' },
|
||||
{ 'name': 'Y', 'size': 4, 'type': 'signed' },
|
||||
{ 'name': 'Z', 'size': 4, 'type': 'signed' }
|
||||
];
|
||||
|
||||
// Once we include options in the UI to load a dynamic list of available
|
||||
@ -31,31 +30,29 @@ class GreyhoundUtils{
|
||||
// If we do that though, we also need to tell Potree to redraw the points
|
||||
// that are already loaded (with different attributes).
|
||||
// This is not default behaviour.
|
||||
attributes.forEach(function(item) {
|
||||
if(item === 'COLOR_PACKED') {
|
||||
schema.push({ "name": "Red", "size": 2, "type": "unsigned" });
|
||||
schema.push({ "name": "Green", "size": 2, "type": "unsigned" });
|
||||
schema.push({ "name": "Blue", "size": 2, "type": "unsigned" });
|
||||
} else if(item === 'INTENSITY'){
|
||||
schema.push({ "name": "Intensity", "size": 2, "type": "unsigned" });
|
||||
} else if(item === 'CLASSIFICATION') {
|
||||
schema.push(
|
||||
{ "name": "Classification", "size": 1, "type": "unsigned" });
|
||||
attributes.forEach(function (item) {
|
||||
if (item === 'COLOR_PACKED') {
|
||||
schema.push({ 'name': 'Red', 'size': 2, 'type': 'unsigned' });
|
||||
schema.push({ 'name': 'Green', 'size': 2, 'type': 'unsigned' });
|
||||
schema.push({ 'name': 'Blue', 'size': 2, 'type': 'unsigned' });
|
||||
} else if (item === 'INTENSITY') {
|
||||
schema.push({ 'name': 'Intensity', 'size': 2, 'type': 'unsigned' });
|
||||
} else if (item === 'CLASSIFICATION') {
|
||||
schema.push({ 'name': 'Classification', 'size': 1, 'type': 'unsigned' });
|
||||
}
|
||||
});
|
||||
|
||||
return schema;
|
||||
return schema;
|
||||
}
|
||||
|
||||
static fetch(url, cb) {
|
||||
|
||||
static fetch (url, cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.onreadystatechange = function() {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
cb(null, xhr.responseText);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cb(xhr.responseText);
|
||||
}
|
||||
}
|
||||
@ -63,16 +60,15 @@ class GreyhoundUtils{
|
||||
xhr.send(null);
|
||||
};
|
||||
|
||||
static fetchBinary(url, cb) {
|
||||
static fetchBinary (url, cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.onreadystatechange = function() {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200 || xhr.status === 0) {
|
||||
cb(null, xhr.response);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cb(xhr.responseText);
|
||||
}
|
||||
}
|
||||
@ -80,34 +76,34 @@ class GreyhoundUtils{
|
||||
xhr.send(null);
|
||||
};
|
||||
|
||||
static pointSizeFrom(schema) {
|
||||
static pointSizeFrom (schema) {
|
||||
return schema.reduce((p, c) => p + c.size, 0);
|
||||
};
|
||||
|
||||
static getNormalization(serverURL, baseDepth, cb) {
|
||||
static getNormalization (serverURL, baseDepth, cb) {
|
||||
var s = [
|
||||
{ "name": "X", "size": 4, "type": "floating" },
|
||||
{ "name": "Y", "size": 4, "type": "floating" },
|
||||
{ "name": "Z", "size": 4, "type": "floating" },
|
||||
{ "name": "Red", "size": 2, "type": "unsigned" },
|
||||
{ "name": "Green", "size": 2, "type": "unsigned" },
|
||||
{ "name": "Blue", "size": 2, "type": "unsigned" },
|
||||
{ "name": "Intensity", "size": 2, "type": "unsigned" }
|
||||
{ 'name': 'X', 'size': 4, 'type': 'floating' },
|
||||
{ 'name': 'Y', 'size': 4, 'type': 'floating' },
|
||||
{ 'name': 'Z', 'size': 4, 'type': 'floating' },
|
||||
{ 'name': 'Red', 'size': 2, 'type': 'unsigned' },
|
||||
{ 'name': 'Green', 'size': 2, 'type': 'unsigned' },
|
||||
{ 'name': 'Blue', 'size': 2, 'type': 'unsigned' },
|
||||
{ 'name': 'Intensity', 'size': 2, 'type': 'unsigned' }
|
||||
];
|
||||
|
||||
var url = serverURL + 'read?depth=' + baseDepth +
|
||||
'&schema=' + JSON.stringify(s);
|
||||
|
||||
GreyhoundUtils.fetchBinary(url, function(err, buffer) {
|
||||
GreyhoundUtils.fetchBinary(url, function (err, buffer) {
|
||||
if (err) throw new Error(err);
|
||||
|
||||
var view = new DataView(buffer);
|
||||
var numBytes = buffer.byteLength - 4;
|
||||
var numPoints = view.getUint32(numBytes, true);
|
||||
// TODO Unused: var numPoints = view.getUint32(numBytes, true);
|
||||
var pointSize = GreyhoundUtils.pointSizeFrom(s);
|
||||
|
||||
var colorNorm = false, intensityNorm = false;
|
||||
var v;
|
||||
var colorNorm = false;
|
||||
var intensityNorm = false;
|
||||
|
||||
for (var offset = 0; offset < numBytes; offset += pointSize) {
|
||||
if (view.getUint16(offset + 12, true) > 255 ||
|
||||
@ -129,11 +125,10 @@ class GreyhoundUtils{
|
||||
cb(null, { color: colorNorm, intensity: intensityNorm });
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Potree.GreyhoundLoader = function() { };
|
||||
Potree.GreyhoundLoader.loadInfoJSON = function load(url, callback) { }
|
||||
Potree.GreyhoundLoader = function () { };
|
||||
Potree.GreyhoundLoader.loadInfoJSON = function load (url, callback) { };
|
||||
|
||||
/**
|
||||
* @return a point cloud octree with the root node data loaded.
|
||||
@ -143,159 +138,160 @@ Potree.GreyhoundLoader.loadInfoJSON = function load(url, callback) { }
|
||||
* @param loadingFinishedListener executed after loading the binary has been
|
||||
* finished
|
||||
*/
|
||||
Potree.GreyhoundLoader.load = function load(url, callback) {
|
||||
Potree.GreyhoundLoader.load = function load (url, callback) {
|
||||
var HIERARCHY_STEP_SIZE = 5;
|
||||
|
||||
try {
|
||||
// We assume everything ater the string 'greyhound://' is the server url
|
||||
var serverURL = url.split('greyhound://')[1];
|
||||
if (serverURL.split('http://').length == 1) {
|
||||
serverURL = 'http://' + serverURL;
|
||||
}
|
||||
if (serverURL.split('http://').length === 1) {
|
||||
serverURL = 'http://' + serverURL;
|
||||
}
|
||||
|
||||
GreyhoundUtils.fetch(serverURL + 'info', function(err, data) {
|
||||
if (err) throw new Error(err);
|
||||
GreyhoundUtils.fetch(serverURL + 'info', function (err, data) {
|
||||
if (err) throw new Error(err);
|
||||
|
||||
/* We parse the result of the info query, which should be a JSON
|
||||
* datastructure somewhat like:
|
||||
{
|
||||
"bounds": [635577, 848882, -1000, 639004, 853538, 2000],
|
||||
"numPoints": 10653336,
|
||||
"schema": [
|
||||
{ "name": "X", "size": 8, "type": "floating" },
|
||||
{ "name": "Y", "size": 8, "type": "floating" },
|
||||
{ "name": "Z", "size": 8, "type": "floating" },
|
||||
{ "name": "Intensity", "size": 2, "type": "unsigned" },
|
||||
{ "name": "OriginId", "size": 4, "type": "unsigned" },
|
||||
{ "name": "Red", "size": 2, "type": "unsigned" },
|
||||
{ "name": "Green", "size": 2, "type": "unsigned" },
|
||||
{ "name": "Blue", "size": 2, "type": "unsigned" }
|
||||
],
|
||||
"srs": "<omitted for brevity>",
|
||||
"type": "octree"
|
||||
}
|
||||
*/
|
||||
var greyhoundInfo = JSON.parse(data);
|
||||
var version = new Potree.Version('1.4');
|
||||
/* We parse the result of the info query, which should be a JSON
|
||||
* datastructure somewhat like:
|
||||
{
|
||||
"bounds": [635577, 848882, -1000, 639004, 853538, 2000],
|
||||
"numPoints": 10653336,
|
||||
"schema": [
|
||||
{ "name": "X", "size": 8, "type": "floating" },
|
||||
{ "name": "Y", "size": 8, "type": "floating" },
|
||||
{ "name": "Z", "size": 8, "type": "floating" },
|
||||
{ "name": "Intensity", "size": 2, "type": "unsigned" },
|
||||
{ "name": "OriginId", "size": 4, "type": "unsigned" },
|
||||
{ "name": "Red", "size": 2, "type": "unsigned" },
|
||||
{ "name": "Green", "size": 2, "type": "unsigned" },
|
||||
{ "name": "Blue", "size": 2, "type": "unsigned" }
|
||||
],
|
||||
"srs": "<omitted for brevity>",
|
||||
"type": "octree"
|
||||
}
|
||||
*/
|
||||
var greyhoundInfo = JSON.parse(data);
|
||||
var version = new Potree.Version('1.4');
|
||||
|
||||
var bounds = greyhoundInfo.bounds;
|
||||
var boundsConforming = greyhoundInfo.boundsConforming;
|
||||
var bounds = greyhoundInfo.bounds;
|
||||
// TODO Unused: var boundsConforming = greyhoundInfo.boundsConforming;
|
||||
|
||||
var width = bounds[3] - bounds[0];
|
||||
var depth = bounds[4] - bounds[1];
|
||||
var height= bounds[5] - bounds[2];
|
||||
var radius = width / 2;
|
||||
// TODO Unused: var width = bounds[3] - bounds[0];
|
||||
// TODO Unused: var depth = bounds[4] - bounds[1];
|
||||
// TODO Unused: var height = bounds[5] - bounds[2];
|
||||
// TODO Unused: var radius = width / 2;
|
||||
var scale = greyhoundInfo.scale || 0.01;
|
||||
if (Array.isArray(scale)) {
|
||||
scale = Math.min(scale[0], scale[1], scale[2]);
|
||||
}
|
||||
|
||||
var scale = greyhoundInfo.scale;
|
||||
var scale = greyhoundInfo.scale || .01;
|
||||
if (Array.isArray(scale)) {
|
||||
scale = Math.min(scale[0], scale[1], scale[2]);
|
||||
}
|
||||
if (GreyhoundUtils.getQueryParam('scale')) {
|
||||
scale = parseFloat(GreyhoundUtils.getQueryParam('scale'));
|
||||
}
|
||||
|
||||
if (GreyhoundUtils.getQueryParam('scale')) {
|
||||
scale = parseFloat(GreyhoundUtils.getQueryParam('scale'));
|
||||
}
|
||||
var baseDepth = Math.max(8, greyhoundInfo.baseDepth);
|
||||
|
||||
var baseDepth = Math.max(8, greyhoundInfo.baseDepth);
|
||||
// Ideally we want to change this bit completely, since
|
||||
// greyhound's options are wider than the default options for
|
||||
// visualizing pointclouds. If someone ever has time to build a
|
||||
// custom ui element for greyhound, the schema options from
|
||||
// this info request should be given to the UI, so the user can
|
||||
// choose between them. The selected option can then be
|
||||
// directly requested from the server in the
|
||||
// PointCloudGreyhoundGeometryNode without asking for
|
||||
// attributes that we are not currently visualizing. We assume
|
||||
// XYZ are always available.
|
||||
var attributes = ['POSITION_CARTESIAN'];
|
||||
|
||||
// Ideally we want to change this bit completely, since
|
||||
// greyhound's options are wider than the default options for
|
||||
// visualizing pointclouds. If someone ever has time to build a
|
||||
// custom ui element for greyhound, the schema options from
|
||||
// this info request should be given to the UI, so the user can
|
||||
// choose between them. The selected option can then be
|
||||
// directly requested from the server in the
|
||||
// PointCloudGreyhoundGeometryNode without asking for
|
||||
// attributes that we are not currently visualizing. We assume
|
||||
// XYZ are always available.
|
||||
var attributes = ['POSITION_CARTESIAN'];
|
||||
// To be careful, we only add COLOR_PACKED as an option if all
|
||||
// colors are actually found.
|
||||
var red = false;
|
||||
var green = false;
|
||||
var blue = false;
|
||||
|
||||
// To be careful, we only add COLOR_PACKED as an option if all
|
||||
// colors are actually found.
|
||||
var red = false, green = false, blue = false;
|
||||
greyhoundInfo.schema.forEach(function (entry) {
|
||||
// Intensity and Classification are optional.
|
||||
if (entry.name === 'Intensity') {
|
||||
attributes.push('INTENSITY');
|
||||
}
|
||||
if (entry.name === 'Classification') {
|
||||
attributes.push('CLASSIFICATION');
|
||||
}
|
||||
|
||||
greyhoundInfo.schema.forEach(function(entry) {
|
||||
// Intensity and Classification are optional.
|
||||
if (entry.name === 'Intensity') {
|
||||
attributes.push('INTENSITY');
|
||||
}
|
||||
if (entry.name === 'Classification') {
|
||||
attributes.push('CLASSIFICATION');
|
||||
}
|
||||
if (entry.name === 'Red') red = true;
|
||||
else if (entry.name === 'Green') green = true;
|
||||
else if (entry.name === 'Blue') blue = true;
|
||||
});
|
||||
|
||||
if (entry.name === 'Red') red = true;
|
||||
else if (entry.name === 'Green') green = true;
|
||||
else if (entry.name === 'Blue') blue = true;
|
||||
});
|
||||
if (red && green && blue) attributes.push('COLOR_PACKED');
|
||||
|
||||
if (red && green && blue) attributes.push('COLOR_PACKED');
|
||||
// Fill in geometry fields.
|
||||
var pgg = new Potree.PointCloudGreyhoundGeometry();
|
||||
pgg.serverURL = serverURL;
|
||||
pgg.spacing = (bounds[3] - bounds[0]) / Math.pow(2, baseDepth);
|
||||
pgg.baseDepth = baseDepth;
|
||||
pgg.hierarchyStepSize = HIERARCHY_STEP_SIZE;
|
||||
|
||||
// Fill in geometry fields.
|
||||
var pgg = new Potree.PointCloudGreyhoundGeometry();
|
||||
pgg.serverURL = serverURL;
|
||||
pgg.spacing = (bounds[3] - bounds[0]) / Math.pow(2, baseDepth);
|
||||
pgg.baseDepth = baseDepth;
|
||||
pgg.hierarchyStepSize = HIERARCHY_STEP_SIZE;
|
||||
pgg.schema = GreyhoundUtils.createSchema(attributes);
|
||||
var pointSize = GreyhoundUtils.pointSizeFrom(pgg.schema);
|
||||
|
||||
pgg.schema = GreyhoundUtils.createSchema(attributes);
|
||||
var pointSize = GreyhoundUtils.pointSizeFrom(pgg.schema);
|
||||
pgg.pointAttributes = new Potree.PointAttributes(attributes);
|
||||
pgg.pointAttributes.byteSize = pointSize;
|
||||
|
||||
pgg.pointAttributes = new Potree.PointAttributes(attributes);
|
||||
pgg.pointAttributes.byteSize = pointSize;
|
||||
var boundingBox = new THREE.Box3(
|
||||
new THREE.Vector3().fromArray(bounds, 0),
|
||||
new THREE.Vector3().fromArray(bounds, 3)
|
||||
);
|
||||
|
||||
var boundingBox = new THREE.Box3(
|
||||
new THREE.Vector3().fromArray(bounds, 0),
|
||||
new THREE.Vector3().fromArray(bounds, 3));
|
||||
var offset = boundingBox.min.clone();
|
||||
|
||||
var offset = boundingBox.min.clone();
|
||||
boundingBox.max.sub(boundingBox.min);
|
||||
boundingBox.min.set(0, 0, 0);
|
||||
|
||||
boundingBox.max.sub(boundingBox.min);
|
||||
boundingBox.min.set(0, 0, 0);
|
||||
pgg.projection = greyhoundInfo.srs;
|
||||
pgg.boundingBox = boundingBox;
|
||||
pgg.boundingSphere = boundingBox.getBoundingSphere();
|
||||
|
||||
pgg.projection = greyhoundInfo.srs;
|
||||
pgg.boundingBox = boundingBox;
|
||||
pgg.boundingSphere = boundingBox.getBoundingSphere();
|
||||
pgg.scale = scale;
|
||||
pgg.offset = offset;
|
||||
|
||||
pgg.scale = scale;
|
||||
pgg.offset = offset;
|
||||
console.log('Scale:', scale);
|
||||
console.log('Offset:', offset);
|
||||
console.log('Bounds:', boundingBox);
|
||||
|
||||
console.log('Scale:', scale);
|
||||
console.log('Offset:', offset);
|
||||
console.log('Bounds:', boundingBox);
|
||||
pgg.loader = new Potree.GreyhoundBinaryLoader(version, boundingBox, pgg.scale);
|
||||
|
||||
pgg.loader = new Potree.GreyhoundBinaryLoader(
|
||||
version, boundingBox, pgg.scale);
|
||||
var nodes = {};
|
||||
|
||||
var nodes = {};
|
||||
{ // load root
|
||||
var name = 'r';
|
||||
|
||||
{ // load root
|
||||
var name = "r";
|
||||
var root = new Potree.PointCloudGreyhoundGeometryNode(
|
||||
name, pgg, boundingBox,
|
||||
scale, offset
|
||||
);
|
||||
|
||||
var root = new Potree.PointCloudGreyhoundGeometryNode(
|
||||
name, pgg, boundingBox,
|
||||
scale, offset);
|
||||
root.level = 0;
|
||||
root.hasChildren = true;
|
||||
root.numPoints = greyhoundInfo.numPoints;
|
||||
root.spacing = pgg.spacing;
|
||||
pgg.root = root;
|
||||
pgg.root.load();
|
||||
nodes[name] = root;
|
||||
}
|
||||
|
||||
root.level = 0;
|
||||
root.hasChildren = true;
|
||||
root.numPoints = greyhoundInfo.numPoints;
|
||||
root.spacing = pgg.spacing;
|
||||
pgg.root = root;
|
||||
pgg.root.load();
|
||||
nodes[name] = root;
|
||||
}
|
||||
pgg.nodes = nodes;
|
||||
|
||||
pgg.nodes = nodes;
|
||||
GreyhoundUtils.getNormalization(serverURL, greyhoundInfo.baseDepth,
|
||||
function (_, normalize) {
|
||||
if (normalize.color) pgg.normalize.color = true;
|
||||
if (normalize.intensity) pgg.normalize.intensity = true;
|
||||
|
||||
GreyhoundUtils.getNormalization(serverURL, greyhoundInfo.baseDepth,
|
||||
function(err, normalize) {
|
||||
if (normalize.color) pgg.normalize.color = true;
|
||||
if (normalize.intensity) pgg.normalize.intensity = true;
|
||||
|
||||
callback(pgg);
|
||||
});
|
||||
});
|
||||
}
|
||||
catch(e) {
|
||||
callback(pgg);
|
||||
}
|
||||
);
|
||||
});
|
||||
} catch (e) {
|
||||
console.log("loading failed: '" + url + "'");
|
||||
console.log(e);
|
||||
|
||||
@ -303,11 +299,11 @@ Potree.GreyhoundLoader.load = function load(url, callback) {
|
||||
}
|
||||
};
|
||||
|
||||
Potree.GreyhoundLoader.loadPointAttributes = function(mno){
|
||||
Potree.GreyhoundLoader.loadPointAttributes = function (mno) {
|
||||
var fpa = mno.pointAttributes;
|
||||
var pa = new Potree.PointAttributes();
|
||||
|
||||
for(var i = 0; i < fpa.length; i++){
|
||||
for (var i = 0; i < fpa.length; i++) {
|
||||
var pointAttribute = Potree.PointAttribute[fpa[i]];
|
||||
pa.add(pointAttribute);
|
||||
}
|
||||
@ -315,9 +311,7 @@ Potree.GreyhoundLoader.loadPointAttributes = function(mno){
|
||||
return pa;
|
||||
};
|
||||
|
||||
|
||||
Potree.GreyhoundLoader.createChildAABB = function(aabb, childIndex){
|
||||
var V3 = THREE.Vector3;
|
||||
Potree.GreyhoundLoader.createChildAABB = function (aabb, childIndex) {
|
||||
var min = aabb.min;
|
||||
var max = aabb.max;
|
||||
var dHalfLength = new THREE.Vector3().copy(max).sub(min).multiplyScalar(0.5);
|
||||
@ -328,29 +322,28 @@ Potree.GreyhoundLoader.createChildAABB = function(aabb, childIndex){
|
||||
var cmin = min;
|
||||
var cmax = new THREE.Vector3().add(min).add(dHalfLength);
|
||||
|
||||
var min, max;
|
||||
if (childIndex === 1) {
|
||||
min = new THREE.Vector3().copy(cmin).add(zHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(zHalfLength);
|
||||
}else if (childIndex === 3) {
|
||||
} else if (childIndex === 3) {
|
||||
min = new THREE.Vector3().copy(cmin).add(zHalfLength).add(yHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(zHalfLength).add(yHalfLength);
|
||||
}else if (childIndex === 0) {
|
||||
} else if (childIndex === 0) {
|
||||
min = cmin;
|
||||
max = cmax;
|
||||
}else if (childIndex === 2) {
|
||||
} else if (childIndex === 2) {
|
||||
min = new THREE.Vector3().copy(cmin).add(yHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(yHalfLength);
|
||||
}else if (childIndex === 5) {
|
||||
} else if (childIndex === 5) {
|
||||
min = new THREE.Vector3().copy(cmin).add(zHalfLength).add(xHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(zHalfLength).add(xHalfLength);
|
||||
}else if (childIndex === 7) {
|
||||
} else if (childIndex === 7) {
|
||||
min = new THREE.Vector3().copy(cmin).add(dHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(dHalfLength);
|
||||
}else if (childIndex === 4) {
|
||||
} else if (childIndex === 4) {
|
||||
min = new THREE.Vector3().copy(cmin).add(xHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(xHalfLength);
|
||||
}else if (childIndex === 6) {
|
||||
} else if (childIndex === 6) {
|
||||
min = new THREE.Vector3().copy(cmin).add(xHalfLength).add(yHalfLength);
|
||||
max = new THREE.Vector3().copy(cmax).add(xHalfLength).add(yHalfLength);
|
||||
}
|
||||
|
||||
@ -7,100 +7,97 @@
|
||||
* Thanks to Uday Verma and Howard Butler
|
||||
*
|
||||
*/
|
||||
|
||||
Potree.LasLazLoader = class LasLazLoader{
|
||||
|
||||
constructor(version){
|
||||
if(typeof(version) === "string"){
|
||||
|
||||
Potree.LasLazLoader = class LasLazLoader {
|
||||
constructor (version) {
|
||||
if (typeof (version) === 'string') {
|
||||
this.version = new Potree.Version(version);
|
||||
}else{
|
||||
} else {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
|
||||
static progressCB(){
|
||||
|
||||
|
||||
static progressCB () {
|
||||
}
|
||||
|
||||
load(node){
|
||||
|
||||
if(node.loaded){
|
||||
|
||||
load (node) {
|
||||
if (node.loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let pointAttributes = node.pcoGeometry.pointAttributes;
|
||||
|
||||
let url = node.getURL();
|
||||
|
||||
if(this.version.equalOrHigher("1.4")){
|
||||
url += "." + pointAttributes.toLowerCase();
|
||||
|
||||
if (this.version.equalOrHigher('1.4')) {
|
||||
url += '.' + pointAttributes.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
let scope = this;
|
||||
|
||||
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
||||
xhr.onreadystatechange = function() {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
let buffer = xhr.response;
|
||||
scope.parse(node, buffer);
|
||||
} else {
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ", file: " + url);
|
||||
console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + url);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
parse(node, buffer){
|
||||
|
||||
parse (node, buffer) {
|
||||
let lf = new LASFile(buffer);
|
||||
let handler = new Potree.LasLazBatcher(node);
|
||||
|
||||
return Promise.resolve(lf).cancellable().then(function(lf) {
|
||||
return lf.open().then(function() {
|
||||
lf.isOpen = true;
|
||||
return lf;
|
||||
})
|
||||
.catch(Promise.CancellationError, function(e) {
|
||||
// open message was sent at this point, but then handler was not called
|
||||
// because the operation was cancelled, explicitly close the file
|
||||
return lf.close().then(function() {
|
||||
throw e;
|
||||
|
||||
return Promise.resolve(lf).cancellable().then(function (lf) {
|
||||
return lf.open()
|
||||
.then(function () {
|
||||
lf.isOpen = true;
|
||||
return lf;
|
||||
})
|
||||
.catch(Promise.CancellationError, function (e) {
|
||||
// open message was sent at this point, but then handler was not called
|
||||
// because the operation was cancelled, explicitly close the file
|
||||
return lf.close().then(function () {
|
||||
throw e;
|
||||
});
|
||||
});
|
||||
});
|
||||
}).then(function(lf) {
|
||||
return lf.getHeader().then(function(h) {
|
||||
}).then(function (lf) {
|
||||
return lf.getHeader().then(function (h) {
|
||||
return [lf, h];
|
||||
});
|
||||
}).then(function(v) {
|
||||
}).then(function (v) {
|
||||
let lf = v[0];
|
||||
let header = v[1];
|
||||
|
||||
|
||||
let skip = 1;
|
||||
let totalRead = 0;
|
||||
let totalToRead = (skip <= 1 ? header.pointsCount : header.pointsCount / skip);
|
||||
let reader = function() {
|
||||
let reader = function () {
|
||||
let p = lf.readData(1000000, 0, skip);
|
||||
return p.then(function(data) {
|
||||
return p.then(function (data) {
|
||||
handler.push(new LASDecoder(data.buffer,
|
||||
header.pointsFormatId,
|
||||
header.pointsStructSize,
|
||||
data.count,
|
||||
header.scale,
|
||||
header.offset,
|
||||
header.mins, header.maxs));
|
||||
header.pointsFormatId,
|
||||
header.pointsStructSize,
|
||||
data.count,
|
||||
header.scale,
|
||||
header.offset,
|
||||
header.mins, header.maxs));
|
||||
|
||||
totalRead += data.count;
|
||||
Potree.LasLazLoader.progressCB(totalRead / totalToRead);
|
||||
|
||||
if (data.hasMoreData)
|
||||
if (data.hasMoreData) {
|
||||
return reader();
|
||||
else {
|
||||
|
||||
} else {
|
||||
header.totalRead = totalRead;
|
||||
header.versionAsString = lf.versionAsString;
|
||||
header.isCompressed = lf.isCompressed;
|
||||
@ -108,62 +105,63 @@ Potree.LasLazLoader = class LasLazLoader{
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
return reader();
|
||||
}).then(function(v) {
|
||||
}).then(function (v) {
|
||||
let lf = v[0];
|
||||
// we're done loading this file
|
||||
//
|
||||
Potree.LasLazLoader.progressCB(1);
|
||||
|
||||
// Close it
|
||||
return lf.close().then(function() {
|
||||
return lf.close().then(function () {
|
||||
lf.isOpen = false;
|
||||
// Delay this a bit so that the user sees 100% completion
|
||||
//
|
||||
return Promise.delay(200).cancellable();
|
||||
}).then(function() {
|
||||
}).then(function () {
|
||||
// trim off the first element (our LASFile which we don't really want to pass to the user)
|
||||
//
|
||||
return v.slice(1);
|
||||
});
|
||||
}).catch(Promise.CancellationError, function(e) {
|
||||
}).catch(Promise.CancellationError, function (e) {
|
||||
// If there was a cancellation, make sure the file is closed, if the file is open
|
||||
// close and then fail
|
||||
if (lf.isOpen)
|
||||
return lf.close().then(function() {
|
||||
if (lf.isOpen) {
|
||||
return lf.close().then(function () {
|
||||
lf.isOpen = false;
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
|
||||
handle(node, url){
|
||||
|
||||
|
||||
handle (node, url) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.LasLazBatcher = class LasLazBatcher{
|
||||
|
||||
constructor(node){
|
||||
Potree.LasLazBatcher = class LasLazBatcher {
|
||||
constructor (node) {
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
push(lasBuffer){
|
||||
|
||||
let workerPath = Potree.scriptPath + "/workers/LASDecoderWorker.js";
|
||||
|
||||
push (lasBuffer) {
|
||||
let workerPath = Potree.scriptPath + '/workers/LASDecoderWorker.js';
|
||||
let worker = Potree.workerPool.getWorker(workerPath);
|
||||
|
||||
|
||||
worker.onmessage = (e) => {
|
||||
let geometry = new THREE.BufferGeometry();
|
||||
let numPoints = lasBuffer.pointsCount;
|
||||
|
||||
let endsWith = function(str, suffix) {
|
||||
|
||||
/*
|
||||
TODO Unused:
|
||||
let endsWith = function (str, suffix) {
|
||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
let positions = e.data.position;
|
||||
let colors = new Uint8Array(e.data.color);
|
||||
let intensities = e.data.intensity;
|
||||
@ -171,16 +169,16 @@ Potree.LasLazBatcher = class LasLazBatcher{
|
||||
let returnNumbers = new Uint8Array(e.data.returnNumber);
|
||||
let numberOfReturns = new Uint8Array(e.data.numberOfReturns);
|
||||
let pointSourceIDs = new Uint16Array(e.data.pointSourceID);
|
||||
//let indices = new ArrayBuffer(numPoints*4);
|
||||
//let iIndices = new Uint32Array(indices);
|
||||
|
||||
//let box = new THREE.Box3();
|
||||
// let indices = new ArrayBuffer(numPoints*4);
|
||||
// let iIndices = new Uint32Array(indices);
|
||||
|
||||
// let box = new THREE.Box3();
|
||||
//
|
||||
//let fPositions = new Float32Array(positions);
|
||||
//for(let i = 0; i < numPoints; i++){
|
||||
// let fPositions = new Float32Array(positions);
|
||||
// for(let i = 0; i < numPoints; 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(colors, 3, true));
|
||||
geometry.addAttribute('intensity', new THREE.BufferAttribute(new Float32Array(intensities), 1));
|
||||
@ -188,29 +186,29 @@ Potree.LasLazBatcher = class LasLazBatcher{
|
||||
geometry.addAttribute('returnNumber', new THREE.BufferAttribute(returnNumbers, 1));
|
||||
geometry.addAttribute('numberOfReturns', new THREE.BufferAttribute(numberOfReturns, 1));
|
||||
geometry.addAttribute('pointSourceID', new THREE.BufferAttribute(pointSourceIDs, 1));
|
||||
geometry.addAttribute("normal", new THREE.BufferAttribute(new Float32Array(numPoints*3), 3));
|
||||
|
||||
geometry.addAttribute('normal', new THREE.BufferAttribute(new Float32Array(numPoints * 3), 3));
|
||||
|
||||
let indicesAttribute = new THREE.Uint8BufferAttribute(e.data.indices, 4);
|
||||
indicesAttribute.normalized = true;
|
||||
geometry.addAttribute("indices", indicesAttribute);
|
||||
|
||||
geometry.addAttribute('indices', indicesAttribute);
|
||||
|
||||
let tightBoundingBox = new THREE.Box3(
|
||||
new THREE.Vector3().fromArray(e.data.tightBoundingBox.min),
|
||||
new THREE.Vector3().fromArray(e.data.tightBoundingBox.max)
|
||||
);
|
||||
|
||||
|
||||
geometry.boundingBox = this.node.boundingBox;
|
||||
this.node.tightBoundingBox = tightBoundingBox;
|
||||
|
||||
|
||||
this.node.geometry = geometry;
|
||||
this.node.loaded = true;
|
||||
this.node.loading = false;
|
||||
this.node.pcoGeometry.numNodesLoading--;
|
||||
this.node.mean = new THREE.Vector3(...e.data.mean);
|
||||
|
||||
|
||||
Potree.workerPool.returnWorker(workerPath, worker);
|
||||
};
|
||||
|
||||
|
||||
let message = {
|
||||
buffer: lasBuffer.arrayb,
|
||||
numPoints: lasBuffer.pointsCount,
|
||||
@ -223,4 +221,4 @@ Potree.LasLazBatcher = class LasLazBatcher{
|
||||
};
|
||||
worker.postMessage(message, [message.buffer]);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,110 +1,109 @@
|
||||
|
||||
|
||||
/**
|
||||
* @class Loads mno files and returns a PointcloudOctree
|
||||
* for a description of the mno binary file format, read mnoFileFormat.txt
|
||||
*
|
||||
*
|
||||
* @author Markus Schuetz
|
||||
*/
|
||||
Potree.POCLoader = function(){
|
||||
|
||||
Potree.POCLoader = function () {
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @return a point cloud octree with the root node data loaded.
|
||||
* @return a point cloud octree with the root node data loaded.
|
||||
* loading of descendants happens asynchronously when they're needed
|
||||
*
|
||||
*
|
||||
* @param url
|
||||
* @param loadingFinishedListener executed after loading the binary has been finished
|
||||
*/
|
||||
Potree.POCLoader.load = function load(url, callback) {
|
||||
try{
|
||||
Potree.POCLoader.load = function load (url, callback) {
|
||||
try {
|
||||
let pco = new Potree.PointCloudOctreeGeometry();
|
||||
pco.url = url;
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url, true);
|
||||
|
||||
xhr.onreadystatechange = function(){
|
||||
if(xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)){
|
||||
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) {
|
||||
let fMno = JSON.parse(xhr.responseText);
|
||||
|
||||
|
||||
let version = new Potree.Version(fMno.version);
|
||||
|
||||
|
||||
// assume octreeDir is absolute if it starts with http
|
||||
if(fMno.octreeDir.indexOf("http") === 0){
|
||||
if (fMno.octreeDir.indexOf('http') === 0) {
|
||||
pco.octreeDir = fMno.octreeDir;
|
||||
}else{
|
||||
pco.octreeDir = url + "/../" + fMno.octreeDir;
|
||||
} else {
|
||||
pco.octreeDir = url + '/../' + fMno.octreeDir;
|
||||
}
|
||||
|
||||
|
||||
pco.spacing = fMno.spacing;
|
||||
pco.hierarchyStepSize = fMno.hierarchyStepSize;
|
||||
|
||||
pco.pointAttributes = fMno.pointAttributes;
|
||||
|
||||
|
||||
let min = new THREE.Vector3(fMno.boundingBox.lx, fMno.boundingBox.ly, fMno.boundingBox.lz);
|
||||
let max = new THREE.Vector3(fMno.boundingBox.ux, fMno.boundingBox.uy, fMno.boundingBox.uz);
|
||||
let boundingBox = new THREE.Box3(min, max);
|
||||
let tightBoundingBox = boundingBox.clone();
|
||||
|
||||
if(fMno.tightBoundingBox){
|
||||
|
||||
if (fMno.tightBoundingBox) {
|
||||
tightBoundingBox.min.copy(new THREE.Vector3(fMno.tightBoundingBox.lx, fMno.tightBoundingBox.ly, fMno.tightBoundingBox.lz));
|
||||
tightBoundingBox.max.copy(new THREE.Vector3(fMno.tightBoundingBox.ux, fMno.tightBoundingBox.uy, fMno.tightBoundingBox.uz));
|
||||
}
|
||||
|
||||
let offset = min.clone();
|
||||
|
||||
|
||||
boundingBox.min.sub(offset);
|
||||
boundingBox.max.sub(offset);
|
||||
|
||||
|
||||
tightBoundingBox.min.sub(offset);
|
||||
tightBoundingBox.max.sub(offset);
|
||||
|
||||
|
||||
pco.projection = fMno.projection;
|
||||
pco.boundingBox = boundingBox;
|
||||
pco.tightBoundingBox = tightBoundingBox;
|
||||
pco.boundingSphere = boundingBox.getBoundingSphere();
|
||||
pco.tightBoundingSphere = tightBoundingBox.getBoundingSphere();
|
||||
pco.offset = offset;
|
||||
if(fMno.pointAttributes === "LAS"){
|
||||
if (fMno.pointAttributes === 'LAS') {
|
||||
pco.loader = new Potree.LasLazLoader(fMno.version);
|
||||
}else if(fMno.pointAttributes === "LAZ"){
|
||||
} else if (fMno.pointAttributes === 'LAZ') {
|
||||
pco.loader = new Potree.LasLazLoader(fMno.version);
|
||||
}else{
|
||||
} else {
|
||||
pco.loader = new Potree.BinaryLoader(fMno.version, boundingBox, fMno.scale);
|
||||
pco.pointAttributes = new Potree.PointAttributes(pco.pointAttributes);
|
||||
}
|
||||
|
||||
|
||||
let nodes = {};
|
||||
|
||||
|
||||
{ // load root
|
||||
let name = "r";
|
||||
|
||||
let name = 'r';
|
||||
|
||||
let root = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
|
||||
root.level = 0;
|
||||
root.hasChildren = true;
|
||||
root.spacing = pco.spacing;
|
||||
if(version.upTo("1.5")){
|
||||
if (version.upTo('1.5')) {
|
||||
root.numPoints = fMno.hierarchy[0][1];
|
||||
}else{
|
||||
} else {
|
||||
root.numPoints = 0;
|
||||
}
|
||||
pco.root = root;
|
||||
pco.root.load();
|
||||
nodes[name] = root;
|
||||
}
|
||||
|
||||
|
||||
// load remaining hierarchy
|
||||
if(version.upTo("1.4")){
|
||||
for( let i = 1; i < fMno.hierarchy.length; i++){
|
||||
if (version.upTo('1.4')) {
|
||||
for (let i = 1; i < fMno.hierarchy.length; i++) {
|
||||
let name = fMno.hierarchy[i][0];
|
||||
let numPoints = fMno.hierarchy[i][1];
|
||||
let index = parseInt(name.charAt(name.length-1));
|
||||
let parentName = name.substring(0, name.length-1);
|
||||
let index = parseInt(name.charAt(name.length - 1));
|
||||
let parentName = name.substring(0, name.length - 1);
|
||||
let parentNode = nodes[parentName];
|
||||
let level = name.length-1;
|
||||
let level = name.length - 1;
|
||||
let boundingBox = Potree.POCLoader.createChildAABB(parentNode.boundingBox, index);
|
||||
|
||||
|
||||
let node = new Potree.PointCloudOctreeGeometryNode(name, pco, boundingBox);
|
||||
node.level = level;
|
||||
node.numPoints = numPoints;
|
||||
@ -113,61 +112,56 @@ Potree.POCLoader.load = function load(url, callback) {
|
||||
nodes[name] = node;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pco.nodes = nodes;
|
||||
|
||||
|
||||
callback(pco);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
xhr.send(null);
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
console.log("loading failed: '" + url + "'");
|
||||
console.log(e);
|
||||
|
||||
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
Potree.POCLoader.loadPointAttributes = function(mno){
|
||||
|
||||
Potree.POCLoader.loadPointAttributes = function (mno) {
|
||||
let fpa = mno.pointAttributes;
|
||||
let pa = new Potree.PointAttributes();
|
||||
|
||||
for(let i = 0; i < fpa.length; i++){
|
||||
|
||||
for (let i = 0; i < fpa.length; i++) {
|
||||
let pointAttribute = Potree.PointAttribute[fpa[i]];
|
||||
pa.add(pointAttribute);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return pa;
|
||||
};
|
||||
|
||||
|
||||
Potree.POCLoader.createChildAABB = function(aabb, index){
|
||||
|
||||
Potree.POCLoader.createChildAABB = function (aabb, index) {
|
||||
let min = aabb.min.clone();
|
||||
let max = aabb.max.clone();
|
||||
let size = new THREE.Vector3().subVectors(max, min);
|
||||
|
||||
if((index & 0b0001) > 0){
|
||||
|
||||
if ((index & 0b0001) > 0) {
|
||||
min.z += size.z / 2;
|
||||
}else{
|
||||
} else {
|
||||
max.z -= size.z / 2;
|
||||
}
|
||||
|
||||
if((index & 0b0010) > 0){
|
||||
|
||||
if ((index & 0b0010) > 0) {
|
||||
min.y += size.y / 2;
|
||||
}else{
|
||||
} else {
|
||||
max.y -= size.y / 2;
|
||||
}
|
||||
|
||||
if((index & 0b0100) > 0){
|
||||
|
||||
if ((index & 0b0100) > 0) {
|
||||
min.x += size.x / 2;
|
||||
}else{
|
||||
} else {
|
||||
max.x -= size.x / 2;
|
||||
}
|
||||
|
||||
|
||||
return new THREE.Box3(min, max);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -19,20 +19,20 @@ Potree.PointAttributeNames.NORMAL = 10;
|
||||
* @class
|
||||
*/
|
||||
Potree.PointAttributeTypes = {
|
||||
DATA_TYPE_DOUBLE : {ordinal : 0, size: 8},
|
||||
DATA_TYPE_FLOAT : {ordinal : 1, size: 4},
|
||||
DATA_TYPE_INT8 : {ordinal : 2, size: 1},
|
||||
DATA_TYPE_UINT8 : {ordinal : 3, size: 1},
|
||||
DATA_TYPE_INT16 : {ordinal : 4, size: 2},
|
||||
DATA_TYPE_UINT16 : {ordinal : 5, size: 2},
|
||||
DATA_TYPE_INT32 : {ordinal : 6, size: 4},
|
||||
DATA_TYPE_UINT32 : {ordinal : 7, size: 4},
|
||||
DATA_TYPE_INT64 : {ordinal : 8, size: 8},
|
||||
DATA_TYPE_UINT64 : {ordinal : 9, size: 8}
|
||||
DATA_TYPE_DOUBLE: {ordinal: 0, size: 8},
|
||||
DATA_TYPE_FLOAT: {ordinal: 1, size: 4},
|
||||
DATA_TYPE_INT8: {ordinal: 2, size: 1},
|
||||
DATA_TYPE_UINT8: {ordinal: 3, size: 1},
|
||||
DATA_TYPE_INT16: {ordinal: 4, size: 2},
|
||||
DATA_TYPE_UINT16: {ordinal: 5, size: 2},
|
||||
DATA_TYPE_INT32: {ordinal: 6, size: 4},
|
||||
DATA_TYPE_UINT32: {ordinal: 7, size: 4},
|
||||
DATA_TYPE_INT64: {ordinal: 8, size: 8},
|
||||
DATA_TYPE_UINT64: {ordinal: 9, size: 8}
|
||||
};
|
||||
|
||||
var i = 0;
|
||||
for(var obj in Potree.PointAttributeTypes){
|
||||
for (var obj in Potree.PointAttributeTypes) {
|
||||
Potree.PointAttributeTypes[i] = Potree.PointAttributeTypes[obj];
|
||||
i++;
|
||||
}
|
||||
@ -46,7 +46,7 @@ for(var obj in Potree.PointAttributeTypes){
|
||||
* @param size
|
||||
* @returns
|
||||
*/
|
||||
Potree.PointAttribute = function(name, type, numElements){
|
||||
Potree.PointAttribute = function (name, type, numElements) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.numElements = numElements;
|
||||
@ -54,46 +54,46 @@ Potree.PointAttribute = function(name, type, numElements){
|
||||
};
|
||||
|
||||
Potree.PointAttribute.POSITION_CARTESIAN = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.POSITION_CARTESIAN,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
Potree.PointAttributeNames.POSITION_CARTESIAN,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
|
||||
Potree.PointAttribute.RGBA_PACKED = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.COLOR_PACKED,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_INT8, 4);
|
||||
Potree.PointAttributeNames.COLOR_PACKED,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_INT8, 4);
|
||||
|
||||
Potree.PointAttribute.COLOR_PACKED = Potree.PointAttribute.RGBA_PACKED;
|
||||
|
||||
Potree.PointAttribute.RGB_PACKED = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.COLOR_PACKED,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_INT8, 3);
|
||||
Potree.PointAttributeNames.COLOR_PACKED,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_INT8, 3);
|
||||
|
||||
Potree.PointAttribute.NORMAL_FLOATS = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.NORMAL_FLOATS,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
Potree.PointAttributeNames.NORMAL_FLOATS,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
|
||||
Potree.PointAttribute.FILLER_1B = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.FILLER,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 1);
|
||||
Potree.PointAttributeNames.FILLER,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 1);
|
||||
|
||||
Potree.PointAttribute.INTENSITY = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.INTENSITY,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT16, 1);
|
||||
Potree.PointAttributeNames.INTENSITY,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT16, 1);
|
||||
|
||||
Potree.PointAttribute.CLASSIFICATION = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.CLASSIFICATION,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 1);
|
||||
Potree.PointAttributeNames.CLASSIFICATION,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 1);
|
||||
|
||||
Potree.PointAttribute.NORMAL_SPHEREMAPPED = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.NORMAL_SPHEREMAPPED,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 2);
|
||||
Potree.PointAttributeNames.NORMAL_SPHEREMAPPED,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 2);
|
||||
|
||||
Potree.PointAttribute.NORMAL_OCT16 = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.NORMAL_OCT16,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 2);
|
||||
Potree.PointAttributeNames.NORMAL_OCT16,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_UINT8, 2);
|
||||
|
||||
Potree.PointAttribute.NORMAL = new Potree.PointAttribute(
|
||||
Potree.PointAttributeNames.NORMAL,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
Potree.PointAttributeNames.NORMAL,
|
||||
Potree.PointAttributeTypes.DATA_TYPE_FLOAT, 3);
|
||||
|
||||
/**
|
||||
* Ordered list of PointAttributes used to identify how points are aligned in a buffer.
|
||||
@ -101,13 +101,13 @@ Potree.PointAttribute.NORMAL = new Potree.PointAttribute(
|
||||
* @class
|
||||
*
|
||||
*/
|
||||
Potree.PointAttributes = function(pointAttributes){
|
||||
Potree.PointAttributes = function (pointAttributes) {
|
||||
this.attributes = [];
|
||||
this.byteSize = 0;
|
||||
this.size = 0;
|
||||
|
||||
if(pointAttributes != null){
|
||||
for(var i = 0; i < pointAttributes.length; i++){
|
||||
if (pointAttributes != null) {
|
||||
for (var i = 0; i < pointAttributes.length; i++) {
|
||||
var pointAttributeName = pointAttributes[i];
|
||||
var pointAttribute = Potree.PointAttribute[pointAttributeName];
|
||||
this.attributes.push(pointAttribute);
|
||||
@ -117,16 +117,16 @@ Potree.PointAttributes = function(pointAttributes){
|
||||
}
|
||||
};
|
||||
|
||||
Potree.PointAttributes.prototype.add = function(pointAttribute){
|
||||
Potree.PointAttributes.prototype.add = function (pointAttribute) {
|
||||
this.attributes.push(pointAttribute);
|
||||
this.byteSize += pointAttribute.byteSize;
|
||||
this.size++;
|
||||
};
|
||||
|
||||
Potree.PointAttributes.prototype.hasColors = function(){
|
||||
for(var name in this.attributes){
|
||||
Potree.PointAttributes.prototype.hasColors = function () {
|
||||
for (var name in this.attributes) {
|
||||
var pointAttribute = this.attributes[name];
|
||||
if(pointAttribute.name === Potree.PointAttributeNames.COLOR_PACKED){
|
||||
if (pointAttribute.name === Potree.PointAttributeNames.COLOR_PACKED) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -134,14 +134,14 @@ Potree.PointAttributes.prototype.hasColors = function(){
|
||||
return false;
|
||||
};
|
||||
|
||||
Potree.PointAttributes.prototype.hasNormals = function(){
|
||||
for(var name in this.attributes){
|
||||
Potree.PointAttributes.prototype.hasNormals = function () {
|
||||
for (var name in this.attributes) {
|
||||
var pointAttribute = this.attributes[name];
|
||||
if(
|
||||
if (
|
||||
pointAttribute === Potree.PointAttribute.NORMAL_SPHEREMAPPED ||
|
||||
pointAttribute === Potree.PointAttribute.NORMAL_FLOATS ||
|
||||
pointAttribute === Potree.PointAttribute.NORMAL ||
|
||||
pointAttribute === Potree.PointAttribute.NORMAL_OCT16){
|
||||
pointAttribute === Potree.PointAttribute.NORMAL_OCT16) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,37 +1,24 @@
|
||||
|
||||
// see http://john-chapman-graphics.blogspot.co.at/2013/01/ssao-tutorial.html
|
||||
|
||||
|
||||
|
||||
Potree.BlurMaterial = function(parameters){
|
||||
THREE.Material.call( this );
|
||||
Potree.BlurMaterial = function (parameters) {
|
||||
THREE.Material.call(this);
|
||||
|
||||
parameters = parameters || {};
|
||||
|
||||
|
||||
var uniforms = {
|
||||
near: { type: "f", value: 0 },
|
||||
far: { type: "f", value: 0 },
|
||||
screenWidth: { type: "f", value: 0 },
|
||||
screenHeight: { type: "f", value: 0 },
|
||||
map: { type: "t", value: null }
|
||||
near: { type: 'f', value: 0 },
|
||||
far: { type: 'f', value: 0 },
|
||||
screenWidth: { type: 'f', value: 0 },
|
||||
screenHeight: { type: 'f', value: 0 },
|
||||
map: { type: 't', value: null }
|
||||
};
|
||||
|
||||
|
||||
this.setValues({
|
||||
uniforms: uniforms,
|
||||
vertexShader: Potree.Shaders["blur.vs"],
|
||||
fragmentShader: Potree.Shaders["blur.fs"],
|
||||
vertexShader: Potree.Shaders['blur.vs'],
|
||||
fragmentShader: Potree.Shaders['blur.fs']
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
Potree.BlurMaterial.prototype = new THREE.ShaderMaterial();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -8,109 +8,95 @@
|
||||
// http://www.kitware.com/source/home/post/9
|
||||
// https://tel.archives-ouvertes.fr/tel-00438464/document p. 115+ (french)
|
||||
|
||||
|
||||
|
||||
|
||||
Potree.EyeDomeLightingMaterial = function(parameters){
|
||||
THREE.Material.call( this );
|
||||
Potree.EyeDomeLightingMaterial = function (parameters) {
|
||||
THREE.Material.call(this);
|
||||
|
||||
parameters = parameters || {};
|
||||
|
||||
|
||||
this._neighbourCount = 4;
|
||||
this.neighbours = new Float32Array(this.neighbourCount*2);
|
||||
for(var c = 0; c < this.neighbourCount; c++){
|
||||
this.neighbours[2*c+0] = Math.cos(2 * c * Math.PI / this.neighbourCount);
|
||||
this.neighbours[2*c+1] = Math.sin(2 * c * Math.PI / this.neighbourCount);
|
||||
this.neighbours = new Float32Array(this.neighbourCount * 2);
|
||||
for (var c = 0; c < this.neighbourCount; c++) {
|
||||
this.neighbours[2 * c + 0] = Math.cos(2 * c * Math.PI / this.neighbourCount);
|
||||
this.neighbours[2 * c + 1] = Math.sin(2 * c * Math.PI / this.neighbourCount);
|
||||
}
|
||||
|
||||
//var lightDir = new THREE.Vector3(0.0, 0.0, 1.0).normalize();
|
||||
|
||||
|
||||
// var lightDir = new THREE.Vector3(0.0, 0.0, 1.0).normalize();
|
||||
|
||||
var uniforms = {
|
||||
screenWidth: { type: "f", value: 0 },
|
||||
screenHeight: { type: "f", value: 0 },
|
||||
edlStrength: { type: "f", value: 1.0 },
|
||||
radius: { type: "f", value: 1.0 },
|
||||
neighbours: { type: "2fv", value: this.neighbours },
|
||||
depthMap: { type: "t", value: null },
|
||||
colorMap: { type: "t", value: null },
|
||||
opacity: { type: "f", value: 1.0}
|
||||
screenWidth: { type: 'f', value: 0 },
|
||||
screenHeight: { type: 'f', value: 0 },
|
||||
edlStrength: { type: 'f', value: 1.0 },
|
||||
radius: { type: 'f', value: 1.0 },
|
||||
neighbours: { type: '2fv', value: this.neighbours },
|
||||
depthMap: { type: 't', value: null },
|
||||
colorMap: { type: 't', value: null },
|
||||
opacity: { type: 'f', value: 1.0 }
|
||||
};
|
||||
|
||||
|
||||
this.setValues({
|
||||
uniforms: uniforms,
|
||||
vertexShader: this.getDefines() + Potree.Shaders["edl.vs"],
|
||||
fragmentShader: this.getDefines() + Potree.Shaders["edl.fs"],
|
||||
vertexShader: this.getDefines() + Potree.Shaders['edl.vs'],
|
||||
fragmentShader: this.getDefines() + Potree.Shaders['edl.fs'],
|
||||
lights: false
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
Potree.EyeDomeLightingMaterial.prototype = new THREE.ShaderMaterial();
|
||||
|
||||
Potree.EyeDomeLightingMaterial.prototype.getDefines = function () {
|
||||
var defines = '';
|
||||
|
||||
Potree.EyeDomeLightingMaterial.prototype.getDefines = function(){
|
||||
var defines = "";
|
||||
|
||||
defines += "#define NEIGHBOUR_COUNT " + this.neighbourCount + "\n";
|
||||
defines += '#define NEIGHBOUR_COUNT ' + this.neighbourCount + '\n';
|
||||
|
||||
return defines;
|
||||
};
|
||||
|
||||
Potree.EyeDomeLightingMaterial.prototype.updateShaderSource = function(){
|
||||
Potree.EyeDomeLightingMaterial.prototype.updateShaderSource = function () {
|
||||
var attributes = {};
|
||||
|
||||
|
||||
let PC = Potree.PointColorType;
|
||||
|
||||
if([PC.INTENSITY, PC.INTENSITY_GRADIENT].includes(this.pointColorType)){
|
||||
attributes.intensity = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === PC.CLASSIFICATION){
|
||||
//attributes.classification = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === PC.RETURN_NUMBER){
|
||||
attributes.returnNumber = { type: "f", value: [] };
|
||||
attributes.numberOfReturns = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === PC.SOURCE){
|
||||
attributes.pointSourceID = { type: "f", value: [] };
|
||||
}else if(this.pointColorType === PC.NORMAL || this.pointColorType === Potree.PointColorType.PHONG){
|
||||
attributes.normal = { type: "f", value: [] };
|
||||
|
||||
if ([PC.INTENSITY, PC.INTENSITY_GRADIENT].includes(this.pointColorType)) {
|
||||
attributes.intensity = { type: 'f', value: [] };
|
||||
} else if (this.pointColorType === PC.CLASSIFICATION) {
|
||||
// attributes.classification = { type: "f", value: [] };
|
||||
} else if (this.pointColorType === PC.RETURN_NUMBER) {
|
||||
attributes.returnNumber = { type: 'f', value: [] };
|
||||
attributes.numberOfReturns = { type: 'f', value: [] };
|
||||
} else if (this.pointColorType === PC.SOURCE) {
|
||||
attributes.pointSourceID = { type: 'f', value: [] };
|
||||
} else if (this.pointColorType === PC.NORMAL || this.pointColorType === Potree.PointColorType.PHONG) {
|
||||
attributes.normal = { type: 'f', value: [] };
|
||||
}
|
||||
attributes.classification = { type: "f", value: 0 };
|
||||
|
||||
var vs = this.getDefines() + Potree.Shaders["edl.vs"];
|
||||
var fs = this.getDefines() + Potree.Shaders["edl.fs"];
|
||||
attributes.classification = { type: 'f', value: 0 };
|
||||
|
||||
var vs = this.getDefines() + Potree.Shaders['edl.vs'];
|
||||
var fs = this.getDefines() + Potree.Shaders['edl.fs'];
|
||||
|
||||
this.setValues({
|
||||
vertexShader: vs,
|
||||
fragmentShader: fs
|
||||
});
|
||||
|
||||
|
||||
this.uniforms.neighbours.value = this.neighbours;
|
||||
|
||||
|
||||
this.needsUpdate = true;
|
||||
};
|
||||
|
||||
Object.defineProperty(Potree.EyeDomeLightingMaterial.prototype, "neighbourCount", {
|
||||
get: function(){
|
||||
Object.defineProperty(Potree.EyeDomeLightingMaterial.prototype, 'neighbourCount', {
|
||||
get: function () {
|
||||
return this._neighbourCount;
|
||||
},
|
||||
set: function(value){
|
||||
if(this._neighbourCount !== value){
|
||||
set: function (value) {
|
||||
if (this._neighbourCount !== value) {
|
||||
this._neighbourCount = value;
|
||||
this.neighbours = new Float32Array(this._neighbourCount*2);
|
||||
for(var c = 0; c < this._neighbourCount; c++){
|
||||
this.neighbours[2*c+0] = Math.cos(2 * c * Math.PI / this._neighbourCount);
|
||||
this.neighbours[2*c+1] = Math.sin(2 * c * Math.PI / this._neighbourCount);
|
||||
this.neighbours = new Float32Array(this._neighbourCount * 2);
|
||||
for (var c = 0; c < this._neighbourCount; c++) {
|
||||
this.neighbours[2 * c + 0] = Math.cos(2 * c * Math.PI / this._neighbourCount);
|
||||
this.neighbours[2 * c + 1] = Math.sin(2 * c * Math.PI / this._neighbourCount);
|
||||
}
|
||||
|
||||
|
||||
this.updateShaderSource();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,27 +1,23 @@
|
||||
|
||||
|
||||
Potree.EarthControls = class EarthControls extends THREE.EventDispatcher{
|
||||
|
||||
constructor(viewer){
|
||||
Potree.EarthControls = class EarthControls extends THREE.EventDispatcher {
|
||||
constructor (viewer) {
|
||||
super(viewer);
|
||||
|
||||
|
||||
this.viewer = viewer;
|
||||
this.renderer = viewer.renderer;
|
||||
|
||||
|
||||
this.scene = null;
|
||||
this.sceneControls = new THREE.Scene();
|
||||
|
||||
|
||||
this.rotationSpeed = 10;
|
||||
|
||||
|
||||
this.fadeFactor = 20;
|
||||
this.wheelDelta = 0;
|
||||
this.zoomDelta = new THREE.Vector3();
|
||||
this.camStart = null;
|
||||
|
||||
|
||||
this.tweens = [];
|
||||
|
||||
|
||||
this.pivotIndicator;
|
||||
{
|
||||
let sg = new THREE.SphereGeometry(1, 16, 16);
|
||||
let sm = new THREE.MeshNormalMaterial();
|
||||
@ -29,59 +25,58 @@ Potree.EarthControls = class EarthControls extends THREE.EventDispatcher{
|
||||
this.pivotIndicator.visible = false;
|
||||
this.sceneControls.add(this.pivotIndicator);
|
||||
}
|
||||
|
||||
|
||||
let drag = (e) => {
|
||||
if(e.drag.object !== null){
|
||||
if (e.drag.object !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this.pivot){
|
||||
|
||||
if (!this.pivot) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(e.drag.startHandled === undefined){
|
||||
|
||||
if (e.drag.startHandled === undefined) {
|
||||
e.drag.startHandled = true;
|
||||
|
||||
this.dispatchEvent({type: "start"});
|
||||
|
||||
this.dispatchEvent({type: 'start'});
|
||||
}
|
||||
|
||||
|
||||
let camStart = this.camStart;
|
||||
let view = this.viewer.scene.view;
|
||||
|
||||
//let camera = this.viewer.scene.camera;
|
||||
|
||||
// let camera = this.viewer.scene.camera;
|
||||
let mouse = e.drag.end;
|
||||
let domElement = this.viewer.renderer.domElement;
|
||||
|
||||
if(e.drag.mouse === Potree.MOUSE.LEFT){
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth ) * 2 - 1,
|
||||
y: - (mouse.y / domElement.clientHeight ) * 2 + 1
|
||||
|
||||
if (e.drag.mouse === Potree.MOUSE.LEFT) {
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(camStart);
|
||||
|
||||
let dir = vector.sub( camStart.position).normalize();
|
||||
|
||||
let dir = vector.sub(camStart.position).normalize();
|
||||
let ray = new THREE.Ray(camStart.position, dir);
|
||||
let plane = new THREE.Plane().setFromNormalAndCoplanarPoint(
|
||||
new THREE.Vector3(0, 0, 1),
|
||||
new THREE.Vector3(0, 0, 1),
|
||||
this.pivot);
|
||||
|
||||
|
||||
|
||||
let distanceToPlane = ray.distanceToPlane(plane);
|
||||
|
||||
if(distanceToPlane > 0){
|
||||
if (distanceToPlane > 0) {
|
||||
let I = new THREE.Vector3().addVectors(
|
||||
camStart.position,
|
||||
camStart.position,
|
||||
dir.clone().multiplyScalar(distanceToPlane));
|
||||
|
||||
|
||||
let movedBy = new THREE.Vector3().subVectors(
|
||||
I, this.pivot);
|
||||
|
||||
|
||||
let newCamPos = camStart.position.clone().sub(movedBy);
|
||||
|
||||
|
||||
view.position.copy(newCamPos);
|
||||
|
||||
|
||||
{
|
||||
let distance = newCamPos.distanceTo(this.pivot);
|
||||
view.radius = distance;
|
||||
@ -89,184 +84,179 @@ Potree.EarthControls = class EarthControls extends THREE.EventDispatcher{
|
||||
this.viewer.setMoveSpeed(speed);
|
||||
}
|
||||
}
|
||||
|
||||
}else if(e.drag.mouse === Potree.MOUSE.RIGHT){
|
||||
} else if (e.drag.mouse === Potree.MOUSE.RIGHT) {
|
||||
let ndrag = {
|
||||
x: e.drag.lastDrag.x / this.renderer.domElement.clientWidth,
|
||||
y: e.drag.lastDrag.y / this.renderer.domElement.clientHeight
|
||||
};
|
||||
|
||||
|
||||
let yawDelta = -ndrag.x * this.rotationSpeed * 0.5;
|
||||
let pitchDelta = -ndrag.y * this.rotationSpeed * 0.2;
|
||||
|
||||
|
||||
let originalPitch = view.pitch;
|
||||
let tmpView = view.clone();
|
||||
tmpView.pitch = tmpView.pitch + pitchDelta;
|
||||
pitchDelta = tmpView.pitch - originalPitch;
|
||||
|
||||
|
||||
|
||||
let pivotToCam = new THREE.Vector3().subVectors(view.position, this.pivot);
|
||||
let pivotToCamTarget = new THREE.Vector3().subVectors(view.getPivot(), this.pivot);
|
||||
let side = view.getSide();
|
||||
|
||||
|
||||
pivotToCam.applyAxisAngle(side, pitchDelta);
|
||||
pivotToCamTarget.applyAxisAngle(side, pitchDelta);
|
||||
|
||||
|
||||
pivotToCam.applyAxisAngle(new THREE.Vector3(0, 0, 1), yawDelta);
|
||||
pivotToCamTarget.applyAxisAngle(new THREE.Vector3(0, 0, 1), yawDelta);
|
||||
|
||||
|
||||
let newCam = new THREE.Vector3().addVectors(this.pivot, pivotToCam);
|
||||
let newCamTarget = new THREE.Vector3().addVectors(this.pivot, pivotToCamTarget);
|
||||
|
||||
// TODO: Unused: let newCamTarget = new THREE.Vector3().addVectors(this.pivot, pivotToCamTarget);
|
||||
|
||||
view.position.copy(newCam);
|
||||
view.yaw += yawDelta;
|
||||
view.pitch += pitchDelta;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
let onMouseDown = e => {
|
||||
let I = Potree.utils.getMousePointCloudIntersection(
|
||||
e.mouse,
|
||||
this.scene.camera,
|
||||
this.renderer,
|
||||
e.mouse,
|
||||
this.scene.camera,
|
||||
this.renderer,
|
||||
this.scene.pointclouds);
|
||||
|
||||
if(I){
|
||||
|
||||
if (I) {
|
||||
this.pivot = I.location;
|
||||
this.camStart = this.scene.camera.clone();
|
||||
this.pivotIndicator.visible = true;
|
||||
this.pivotIndicator.position.copy(I.location);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let drop = e => {
|
||||
this.dispatchEvent({type: "end"});
|
||||
this.dispatchEvent({type: 'end'});
|
||||
};
|
||||
|
||||
|
||||
let onMouseUp = e => {
|
||||
this.camStart = null;
|
||||
this.pivot = null;
|
||||
this.pivotIndicator.visible = false;
|
||||
};
|
||||
|
||||
|
||||
let scroll = (e) => {
|
||||
this.wheelDelta += e.delta
|
||||
this.wheelDelta += e.delta;
|
||||
};
|
||||
|
||||
|
||||
let dblclick = (e) => {
|
||||
this.zoomToLocation(e.mouse);
|
||||
};
|
||||
|
||||
this.addEventListener("drag", drag);
|
||||
this.addEventListener("drop", drop);
|
||||
this.addEventListener("mousewheel", scroll);
|
||||
this.addEventListener("mousedown", onMouseDown);
|
||||
this.addEventListener("mouseup", onMouseUp);
|
||||
this.addEventListener("dblclick", dblclick);
|
||||
|
||||
this.addEventListener('drag', drag);
|
||||
this.addEventListener('drop', drop);
|
||||
this.addEventListener('mousewheel', scroll);
|
||||
this.addEventListener('mousedown', onMouseDown);
|
||||
this.addEventListener('mouseup', onMouseUp);
|
||||
this.addEventListener('dblclick', dblclick);
|
||||
}
|
||||
|
||||
setScene(scene){
|
||||
|
||||
setScene (scene) {
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
zoomToLocation(mouse){
|
||||
|
||||
zoomToLocation (mouse) {
|
||||
let camera = this.scene.camera;
|
||||
|
||||
|
||||
let I = Potree.utils.getMousePointCloudIntersection(
|
||||
mouse,
|
||||
camera,
|
||||
this.renderer,
|
||||
mouse,
|
||||
camera,
|
||||
this.renderer,
|
||||
this.scene.pointclouds);
|
||||
|
||||
if(I === null){
|
||||
|
||||
if (I === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let nmouse = {
|
||||
x: +( mouse.x / this.renderer.domElement.clientWidth ) * 2 - 1,
|
||||
y: -( mouse.y / this.renderer.domElement.clientHeight ) * 2 + 1
|
||||
|
||||
let nmouse = {
|
||||
x: +(mouse.x / this.renderer.domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / this.renderer.domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
|
||||
let targetRadius = 0;
|
||||
{
|
||||
let minimumJumpDistance = 0.2;
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(camera);
|
||||
|
||||
|
||||
let direction = vector.sub(camera.position).normalize();
|
||||
let ray = new THREE.Ray(camera.position, direction);
|
||||
|
||||
|
||||
let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
|
||||
let lastNode = nodes[nodes.length - 1];
|
||||
let radius = lastNode.getBoundingSphere().radius;
|
||||
targetRadius = Math.min(this.scene.view.radius, radius);
|
||||
targetRadius = Math.max(minimumJumpDistance, targetRadius);
|
||||
}
|
||||
|
||||
|
||||
let d = this.scene.view.direction.multiplyScalar(-1);
|
||||
let cameraTargetPosition = new THREE.Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
|
||||
let controlsTargetPosition = I.location;
|
||||
|
||||
// TODO Unused: let controlsTargetPosition = I.location;
|
||||
|
||||
var animationDuration = 600;
|
||||
var easing = TWEEN.Easing.Quartic.Out;
|
||||
|
||||
{ // animate
|
||||
|
||||
|
||||
{ // animate
|
||||
let value = {x: 0};
|
||||
let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
|
||||
tween.easing(easing);
|
||||
this.tweens.push(tween);
|
||||
|
||||
|
||||
let startPos = this.scene.view.position.clone();
|
||||
let targetPos = cameraTargetPosition.clone();
|
||||
let startRadius = this.scene.view.radius;
|
||||
let targetRadius = cameraTargetPosition.distanceTo(I.location);
|
||||
|
||||
tween.onUpdate( () => {
|
||||
|
||||
tween.onUpdate(() => {
|
||||
let t = value.x;
|
||||
this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
|
||||
this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
|
||||
this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
|
||||
|
||||
|
||||
this.scene.view.radius = (1 - t) * startRadius + t * targetRadius;
|
||||
this.viewer.setMoveSpeed(this.scene.view.radius / 2.5);
|
||||
});
|
||||
|
||||
tween.onComplete( () => {
|
||||
this.tweens = this.tweens.filter( e => e !== tween);
|
||||
|
||||
tween.onComplete(() => {
|
||||
this.tweens = this.tweens.filter(e => e !== tween);
|
||||
});
|
||||
|
||||
|
||||
tween.start();
|
||||
}
|
||||
}
|
||||
|
||||
update(delta){
|
||||
|
||||
update (delta) {
|
||||
let view = this.scene.view;
|
||||
let fade = Math.pow(0.5, this.fadeFactor * delta);
|
||||
let progression = 1 - fade;
|
||||
let camera = this.scene.camera;
|
||||
|
||||
|
||||
// compute zoom
|
||||
if(this.wheelDelta !== 0){
|
||||
if (this.wheelDelta !== 0) {
|
||||
let I = Potree.utils.getMousePointCloudIntersection(
|
||||
this.viewer.inputHandler.mouse,
|
||||
this.scene.camera,
|
||||
this.renderer,
|
||||
this.viewer.inputHandler.mouse,
|
||||
this.scene.camera,
|
||||
this.renderer,
|
||||
this.scene.pointclouds);
|
||||
|
||||
if(I){
|
||||
|
||||
if (I) {
|
||||
let resolvedPos = new THREE.Vector3().addVectors(view.position, this.zoomDelta);
|
||||
let distance = I.location.distanceTo(resolvedPos);
|
||||
let jumpDistance = distance * 0.2 * this.wheelDelta;
|
||||
let targetDir = new THREE.Vector3().subVectors(I.location, view.position);
|
||||
targetDir.normalize();
|
||||
|
||||
|
||||
resolvedPos.add(targetDir.multiplyScalar(jumpDistance));
|
||||
this.zoomDelta.subVectors(resolvedPos, view.position);
|
||||
|
||||
|
||||
{
|
||||
let distance = resolvedPos.distanceTo(I.location);
|
||||
view.radius = distance;
|
||||
@ -275,37 +265,27 @@ Potree.EarthControls = class EarthControls extends THREE.EventDispatcher{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// apply zoom
|
||||
if(this.zoomDelta.length() !== 0){
|
||||
if (this.zoomDelta.length() !== 0) {
|
||||
let p = this.zoomDelta.clone().multiplyScalar(progression);
|
||||
|
||||
|
||||
let newPos = new THREE.Vector3().addVectors(view.position, p);
|
||||
view.position.copy(newPos);
|
||||
}
|
||||
|
||||
if(this.pivotIndicator.visible){
|
||||
|
||||
if (this.pivotIndicator.visible) {
|
||||
let distance = this.pivotIndicator.position.distanceTo(view.position);
|
||||
let pixelHeight = this.renderer.domElement.clientHeight;
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, pixelHeight);
|
||||
let scale = (10 / pr);
|
||||
this.pivotIndicator.scale.set(scale, scale, scale);
|
||||
}
|
||||
|
||||
|
||||
// decelerate over time
|
||||
{
|
||||
this.zoomDelta.multiplyScalar(fade);
|
||||
this.wheelDelta = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @author mschuetz / http://mschuetz.at
|
||||
*
|
||||
* adapted from THREE.OrbitControls by
|
||||
* adapted from THREE.OrbitControls by
|
||||
*
|
||||
* @author qiao / https://github.com/qiao
|
||||
* @author mrdoob / http://mrdoob.com
|
||||
@ -12,264 +12,252 @@
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
Potree.FirstPersonControls = class FirstPersonControls extends THREE.EventDispatcher{
|
||||
|
||||
constructor(viewer){
|
||||
|
||||
Potree.FirstPersonControls = class FirstPersonControls extends THREE.EventDispatcher {
|
||||
constructor (viewer) {
|
||||
super();
|
||||
|
||||
|
||||
this.viewer = viewer;
|
||||
this.renderer = viewer.renderer;
|
||||
|
||||
|
||||
this.scene = null;
|
||||
this.sceneControls = new THREE.Scene();
|
||||
|
||||
|
||||
this.rotationSpeed = 200;
|
||||
this.moveSpeed = 10;
|
||||
|
||||
|
||||
this.keys = {
|
||||
FORWARD: ['W'.charCodeAt(0), 38],
|
||||
BACKWARD: ['S'.charCodeAt(0), 40],
|
||||
LEFT: ['A'.charCodeAt(0), 37],
|
||||
RIGHT: ['D'.charCodeAt(0), 39],
|
||||
UP: ['R'.charCodeAt(0), 33],
|
||||
DOWN: ['F'.charCodeAt(0), 34]
|
||||
FORWARD: ['W'.charCodeAt(0), 38],
|
||||
BACKWARD: ['S'.charCodeAt(0), 40],
|
||||
LEFT: ['A'.charCodeAt(0), 37],
|
||||
RIGHT: ['D'.charCodeAt(0), 39],
|
||||
UP: ['R'.charCodeAt(0), 33],
|
||||
DOWN: ['F'.charCodeAt(0), 34]
|
||||
};
|
||||
|
||||
|
||||
this.fadeFactor = 50;
|
||||
this.yawDelta = 0;
|
||||
this.pitchDelta = 0;
|
||||
this.translationDelta = new THREE.Vector3(0, 0, 0);
|
||||
this.translationWorldDelta = new THREE.Vector3(0, 0, 0);
|
||||
|
||||
|
||||
this.tweens = [];
|
||||
|
||||
|
||||
let drag = (e) => {
|
||||
if(e.drag.object !== null){
|
||||
if (e.drag.object !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(e.drag.startHandled === undefined){
|
||||
|
||||
if (e.drag.startHandled === undefined) {
|
||||
e.drag.startHandled = true;
|
||||
|
||||
this.dispatchEvent({type: "start"});
|
||||
|
||||
this.dispatchEvent({type: 'start'});
|
||||
}
|
||||
|
||||
|
||||
let moveSpeed = this.viewer.getMoveSpeed();
|
||||
|
||||
|
||||
let ndrag = {
|
||||
x: e.drag.lastDrag.x / this.renderer.domElement.clientWidth,
|
||||
y: e.drag.lastDrag.y / this.renderer.domElement.clientHeight
|
||||
};
|
||||
|
||||
if(e.drag.mouse === Potree.MOUSE.LEFT){
|
||||
|
||||
if (e.drag.mouse === Potree.MOUSE.LEFT) {
|
||||
this.yawDelta += ndrag.x * this.rotationSpeed;
|
||||
this.pitchDelta += ndrag.y * this.rotationSpeed;
|
||||
}else if(e.drag.mouse === Potree.MOUSE.RIGHT){
|
||||
} else if (e.drag.mouse === Potree.MOUSE.RIGHT) {
|
||||
this.translationDelta.x -= ndrag.x * moveSpeed * 100;
|
||||
this.translationDelta.z += ndrag.y * moveSpeed * 100;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let drop = e => {
|
||||
this.dispatchEvent({type: "end"});
|
||||
this.dispatchEvent({type: 'end'});
|
||||
};
|
||||
|
||||
|
||||
let scroll = (e) => {
|
||||
let speed = this.viewer.getMoveSpeed();
|
||||
|
||||
if(e.delta < 0){
|
||||
|
||||
if (e.delta < 0) {
|
||||
speed = speed * 0.9;
|
||||
}else if(e.delta > 0){
|
||||
} else if (e.delta > 0) {
|
||||
speed = speed / 0.9;
|
||||
}
|
||||
|
||||
|
||||
speed = Math.max(speed, 0.1);
|
||||
|
||||
|
||||
this.viewer.setMoveSpeed(speed);
|
||||
};
|
||||
|
||||
|
||||
let dblclick = (e) => {
|
||||
this.zoomToLocation(e.mouse);
|
||||
};
|
||||
|
||||
this.addEventListener("drag", drag);
|
||||
this.addEventListener("drop", drop);
|
||||
this.addEventListener("mousewheel", scroll);
|
||||
this.addEventListener("dblclick", dblclick);
|
||||
|
||||
this.addEventListener('drag', drag);
|
||||
this.addEventListener('drop', drop);
|
||||
this.addEventListener('mousewheel', scroll);
|
||||
this.addEventListener('dblclick', dblclick);
|
||||
}
|
||||
|
||||
setScene(scene){
|
||||
|
||||
setScene (scene) {
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
zoomToLocation(mouse){
|
||||
|
||||
zoomToLocation (mouse) {
|
||||
let camera = this.scene.camera;
|
||||
|
||||
|
||||
let I = Potree.utils.getMousePointCloudIntersection(
|
||||
mouse,
|
||||
camera,
|
||||
this.renderer,
|
||||
mouse,
|
||||
camera,
|
||||
this.renderer,
|
||||
this.scene.pointclouds);
|
||||
|
||||
if(I === null){
|
||||
|
||||
if (I === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let nmouse = {
|
||||
x: +( mouse.x / this.renderer.domElement.clientWidth ) * 2 - 1,
|
||||
y: -( mouse.y / this.renderer.domElement.clientHeight ) * 2 + 1
|
||||
|
||||
let nmouse = {
|
||||
x: +(mouse.x / this.renderer.domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / this.renderer.domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
|
||||
let targetRadius = 0;
|
||||
{
|
||||
let minimumJumpDistance = 0.2;
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(camera);
|
||||
|
||||
|
||||
let direction = vector.sub(camera.position).normalize();
|
||||
let ray = new THREE.Ray(camera.position, direction);
|
||||
|
||||
|
||||
let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
|
||||
let lastNode = nodes[nodes.length - 1];
|
||||
let radius = lastNode.getBoundingSphere().radius;
|
||||
targetRadius = Math.min(this.scene.view.radius, radius);
|
||||
targetRadius = Math.max(minimumJumpDistance, targetRadius);
|
||||
}
|
||||
|
||||
|
||||
let d = this.scene.view.direction.multiplyScalar(-1);
|
||||
let cameraTargetPosition = new THREE.Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
|
||||
let controlsTargetPosition = I.location;
|
||||
|
||||
// TODO Unused: let controlsTargetPosition = I.location;
|
||||
|
||||
var animationDuration = 600;
|
||||
var easing = TWEEN.Easing.Quartic.Out;
|
||||
|
||||
{ // animate
|
||||
|
||||
|
||||
{ // animate
|
||||
let value = {x: 0};
|
||||
let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
|
||||
tween.easing(easing);
|
||||
this.tweens.push(tween);
|
||||
|
||||
|
||||
let startPos = this.scene.view.position.clone();
|
||||
let targetPos = cameraTargetPosition.clone();
|
||||
let startRadius = this.scene.view.radius;
|
||||
let targetRadius = cameraTargetPosition.distanceTo(I.location);
|
||||
|
||||
tween.onUpdate( () => {
|
||||
|
||||
tween.onUpdate(() => {
|
||||
let t = value.x;
|
||||
this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
|
||||
this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
|
||||
this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
|
||||
|
||||
|
||||
this.scene.view.radius = (1 - t) * startRadius + t * targetRadius;
|
||||
this.viewer.setMoveSpeed(this.scene.view.radius / 2.5);
|
||||
});
|
||||
|
||||
tween.onComplete( () => {
|
||||
this.tweens = this.tweens.filter( e => e !== tween);
|
||||
|
||||
tween.onComplete(() => {
|
||||
this.tweens = this.tweens.filter(e => e !== tween);
|
||||
});
|
||||
|
||||
|
||||
tween.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update(delta){
|
||||
|
||||
update (delta) {
|
||||
let view = this.scene.view;
|
||||
|
||||
|
||||
{ // cancel move animations on user input
|
||||
let changes = [ this.yawDelta,
|
||||
this.pitchDelta,
|
||||
let changes = [ this.yawDelta,
|
||||
this.pitchDelta,
|
||||
this.translationDelta.length(),
|
||||
this.translationWorldDelta.length() ];
|
||||
let changeHappens = changes.some( e => Math.abs(e) > 0.001);
|
||||
if(changeHappens && this.tweens.length > 0){
|
||||
this.tweens.forEach( e => e.stop() );
|
||||
let changeHappens = changes.some(e => Math.abs(e) > 0.001);
|
||||
if (changeHappens && this.tweens.length > 0) {
|
||||
this.tweens.forEach(e => e.stop());
|
||||
this.tweens = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{ // accelerate while input is given
|
||||
let ih = this.viewer.inputHandler;
|
||||
|
||||
|
||||
let moveForward = this.keys.FORWARD.some(e => ih.pressedKeys[e]);
|
||||
let moveBackward = this.keys.BACKWARD.some(e => ih.pressedKeys[e]);
|
||||
let moveLeft = this.keys.LEFT.some(e => ih.pressedKeys[e]);
|
||||
let moveRight = this.keys.RIGHT.some(e => ih.pressedKeys[e]);
|
||||
let moveUp = this.keys.UP.some(e => ih.pressedKeys[e]);
|
||||
let moveDown = this.keys.DOWN.some(e => ih.pressedKeys[e]);
|
||||
|
||||
if(moveForward && moveBackward){
|
||||
|
||||
if (moveForward && moveBackward) {
|
||||
this.translationDelta.y = 0;
|
||||
}else if(moveForward){
|
||||
} else if (moveForward) {
|
||||
this.translationDelta.y = this.viewer.getMoveSpeed();
|
||||
}else if(moveBackward){
|
||||
} else if (moveBackward) {
|
||||
this.translationDelta.y = -this.viewer.getMoveSpeed();
|
||||
}
|
||||
|
||||
if(moveLeft && moveRight){
|
||||
|
||||
if (moveLeft && moveRight) {
|
||||
this.translationDelta.x = 0;
|
||||
}else if(moveLeft){
|
||||
} else if (moveLeft) {
|
||||
this.translationDelta.x = -this.viewer.getMoveSpeed();
|
||||
}else if(moveRight){
|
||||
} else if (moveRight) {
|
||||
this.translationDelta.x = this.viewer.getMoveSpeed();
|
||||
}
|
||||
|
||||
if(moveUp && moveDown){
|
||||
|
||||
if (moveUp && moveDown) {
|
||||
this.translationWorldDelta.z = 0;
|
||||
}else if(moveUp){
|
||||
} else if (moveUp) {
|
||||
this.translationWorldDelta.z = this.viewer.getMoveSpeed();
|
||||
}else if(moveDown){
|
||||
} else if (moveDown) {
|
||||
this.translationWorldDelta.z = -this.viewer.getMoveSpeed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
{ // apply rotation
|
||||
let yaw = view.yaw;
|
||||
let pitch = view.pitch;
|
||||
|
||||
|
||||
yaw -= this.yawDelta * delta;
|
||||
pitch -= this.pitchDelta * delta;
|
||||
|
||||
|
||||
view.yaw = yaw;
|
||||
view.pitch = pitch;
|
||||
}
|
||||
|
||||
|
||||
{ // apply translation
|
||||
view.translate(
|
||||
this.translationDelta.x * delta,
|
||||
this.translationDelta.y * delta,
|
||||
this.translationDelta.z * delta
|
||||
);
|
||||
|
||||
|
||||
view.translateWorld(
|
||||
this.translationWorldDelta.x * delta,
|
||||
this.translationWorldDelta.y * delta,
|
||||
this.translationWorldDelta.z * delta
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
{ // set view target according to speed
|
||||
view.radius = 3 * this.viewer.getMoveSpeed();
|
||||
}
|
||||
|
||||
{// decelerate over time
|
||||
|
||||
{ // decelerate over time
|
||||
let attenuation = Math.max(0, 1 - this.fadeFactor * delta);
|
||||
this.yawDelta *= attenuation;
|
||||
this.pitchDelta *= attenuation;
|
||||
this.translationDelta.multiplyScalar(attenuation);
|
||||
this.translationWorldDelta.multiplyScalar(attenuation);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
|
||||
|
||||
/**
|
||||
* @author mschuetz / http://mschuetz.at
|
||||
*
|
||||
* adapted from THREE.OrbitControls by
|
||||
* adapted from THREE.OrbitControls by
|
||||
*
|
||||
* @author qiao / https://github.com/qiao
|
||||
* @author mrdoob / http://mrdoob.com
|
||||
@ -22,12 +21,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
Potree.GeoControls = function ( object, domElement ) {
|
||||
Potree.GeoControls = function (object, domElement) {
|
||||
this.object = object;
|
||||
this.domElement = ( domElement !== undefined ) ? domElement : document;
|
||||
|
||||
this.domElement = (domElement !== undefined) ? domElement : document;
|
||||
|
||||
// Set to false to disable this control
|
||||
this.enabled = true;
|
||||
|
||||
@ -35,14 +32,14 @@ Potree.GeoControls = function ( object, domElement ) {
|
||||
this.track = null;
|
||||
// position on track in intervall [0,1]
|
||||
this.trackPos = 0;
|
||||
|
||||
|
||||
this.rotateSpeed = 1.0;
|
||||
this.moveSpeed = 10.0;
|
||||
|
||||
this.keys = {
|
||||
LEFT: 37,
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
this.keys = {
|
||||
LEFT: 37,
|
||||
UP: 38,
|
||||
RIGHT: 39,
|
||||
BOTTOM: 40,
|
||||
A: 'A'.charCodeAt(0),
|
||||
S: 'S'.charCodeAt(0),
|
||||
@ -65,18 +62,17 @@ Potree.GeoControls = function ( object, domElement ) {
|
||||
var panDelta = new THREE.Vector2();
|
||||
var panOffset = new THREE.Vector3();
|
||||
|
||||
var offset = new THREE.Vector3();
|
||||
// TODO Unused: var offset = new THREE.Vector3();
|
||||
|
||||
var phiDelta = 0;
|
||||
var thetaDelta = 0;
|
||||
var scale = 1;
|
||||
var pan = new THREE.Vector3();
|
||||
|
||||
|
||||
this.shiftDown = false;
|
||||
|
||||
var lastPosition = new THREE.Vector3();
|
||||
|
||||
var STATE = { NONE : -1, ROTATE : 0, SPEEDCHANGE : 1, PAN : 2 };
|
||||
var STATE = { NONE: -1, ROTATE: 0, SPEEDCHANGE: 1, PAN: 2 };
|
||||
|
||||
var state = STATE.NONE;
|
||||
|
||||
@ -86,38 +82,38 @@ Potree.GeoControls = function ( object, domElement ) {
|
||||
// events
|
||||
|
||||
var changeEvent = { type: 'change' };
|
||||
var startEvent = { type: 'start'};
|
||||
var endEvent = { type: 'end'};
|
||||
|
||||
this.setTrack = function(track){
|
||||
if(this.track !== track){
|
||||
var startEvent = { type: 'start' };
|
||||
var endEvent = { type: 'end' };
|
||||
|
||||
this.setTrack = function (track) {
|
||||
if (this.track !== track) {
|
||||
this.track = track;
|
||||
this.trackPos = null;
|
||||
}
|
||||
};
|
||||
|
||||
this.setTrackPos = function(trackPos, _preserveRelativeRotation){
|
||||
var preserveRelativeRotation = _preserveRelativeRotation || false;
|
||||
|
||||
|
||||
this.setTrackPos = function (trackPos, _preserveRelativeRotation) {
|
||||
// TODO Unused: var preserveRelativeRotation = _preserveRelativeRotation || false;
|
||||
|
||||
var newTrackPos = Math.max(0, Math.min(1, trackPos));
|
||||
var oldTrackPos = this.trackPos || newTrackPos;
|
||||
|
||||
|
||||
var newTangent = this.track.getTangentAt(newTrackPos);
|
||||
var oldTangent = this.track.getTangentAt(oldTrackPos);
|
||||
|
||||
if(newTangent.equals(oldTangent)){
|
||||
|
||||
if (newTangent.equals(oldTangent)) {
|
||||
// no change in direction
|
||||
}else{
|
||||
} else {
|
||||
var tangentDiffNormal = new THREE.Vector3().crossVectors(oldTangent, newTangent).normalize();
|
||||
var angle = oldTangent.angleTo(newTangent);
|
||||
var rot = new THREE.Matrix4().makeRotationAxis(tangentDiffNormal, angle);
|
||||
var dir = this.object.getWorldDirection().clone();
|
||||
dir = dir.applyMatrix4(rot);
|
||||
var target = new THREE.Vector3().addVectors(this.object.position, dir);
|
||||
let target = new THREE.Vector3().addVectors(this.object.position, dir);
|
||||
this.object.lookAt(target);
|
||||
this.object.updateMatrixWorld();
|
||||
|
||||
var event = {
|
||||
|
||||
let event = {
|
||||
type: 'path_relative_rotation',
|
||||
angle: angle,
|
||||
axis: tangentDiffNormal,
|
||||
@ -125,341 +121,325 @@ Potree.GeoControls = function ( object, domElement ) {
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
|
||||
if(this.trackPos === null){
|
||||
var target = new THREE.Vector3().addVectors(this.object.position, newTangent);
|
||||
|
||||
if (this.trackPos === null) {
|
||||
let target = new THREE.Vector3().addVectors(this.object.position, newTangent);
|
||||
this.object.lookAt(target);
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.trackPos = newTrackPos;
|
||||
|
||||
//var pStart = this.track.getPointAt(oldTrackPos);
|
||||
//var pEnd = this.track.getPointAt(newTrackPos);
|
||||
//var pDiff = pEnd.sub(pStart);
|
||||
|
||||
|
||||
if(newTrackPos !== oldTrackPos){
|
||||
var event = {
|
||||
|
||||
// var pStart = this.track.getPointAt(oldTrackPos);
|
||||
// var pEnd = this.track.getPointAt(newTrackPos);
|
||||
// var pDiff = pEnd.sub(pStart);
|
||||
|
||||
if (newTrackPos !== oldTrackPos) {
|
||||
let event = {
|
||||
type: 'move',
|
||||
translation: pan.clone()
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
this.getTrackPos = function(){
|
||||
};
|
||||
|
||||
this.getTrackPos = function () {
|
||||
return this.trackPos;
|
||||
};
|
||||
|
||||
this.rotateLeft = function ( angle ) {
|
||||
this.rotateLeft = function (angle) {
|
||||
thetaDelta -= angle;
|
||||
};
|
||||
|
||||
this.rotateUp = function ( angle ) {
|
||||
this.rotateUp = function (angle) {
|
||||
phiDelta -= angle;
|
||||
};
|
||||
|
||||
// pass in distance in world space to move left
|
||||
this.panLeft = function ( distance ) {
|
||||
|
||||
this.panLeft = function (distance) {
|
||||
var te = this.object.matrix.elements;
|
||||
|
||||
// get X column of matrix
|
||||
panOffset.set( te[ 0 ], te[ 1 ], te[ 2 ] );
|
||||
panOffset.multiplyScalar( - distance );
|
||||
|
||||
pan.add( panOffset );
|
||||
panOffset.set(te[ 0 ], te[ 1 ], te[ 2 ]);
|
||||
panOffset.multiplyScalar(-distance);
|
||||
|
||||
pan.add(panOffset);
|
||||
};
|
||||
|
||||
// pass in distance in world space to move up
|
||||
this.panUp = function ( distance ) {
|
||||
|
||||
this.panUp = function (distance) {
|
||||
var te = this.object.matrix.elements;
|
||||
|
||||
// get Y column of matrix
|
||||
panOffset.set( te[ 4 ], te[ 5 ], te[ 6 ] );
|
||||
panOffset.multiplyScalar( distance );
|
||||
|
||||
pan.add( panOffset );
|
||||
panOffset.set(te[ 4 ], te[ 5 ], te[ 6 ]);
|
||||
panOffset.multiplyScalar(distance);
|
||||
|
||||
pan.add(panOffset);
|
||||
};
|
||||
|
||||
// pass in distance in world space to move forward
|
||||
this.panForward = function ( distance ) {
|
||||
|
||||
if(this.track){
|
||||
this.setTrackPos( this.getTrackPos() - distance / this.track.getLength());
|
||||
}else{
|
||||
// pass in distance in world space to move forward
|
||||
this.panForward = function (distance) {
|
||||
if (this.track) {
|
||||
this.setTrackPos(this.getTrackPos() - distance / this.track.getLength());
|
||||
} else {
|
||||
var te = this.object.matrix.elements;
|
||||
|
||||
// get Y column of matrix
|
||||
panOffset.set( te[ 8 ], te[ 9 ], te[ 10 ] );
|
||||
//panOffset.set( te[ 8 ], 0, te[ 10 ] );
|
||||
panOffset.multiplyScalar( distance );
|
||||
|
||||
pan.add( panOffset );
|
||||
panOffset.set(te[ 8 ], te[ 9 ], te[ 10 ]);
|
||||
// panOffset.set( te[ 8 ], 0, te[ 10 ] );
|
||||
panOffset.multiplyScalar(distance);
|
||||
|
||||
pan.add(panOffset);
|
||||
}
|
||||
};
|
||||
|
||||
this.pan = function ( deltaX, deltaY ) {
|
||||
|
||||
this.pan = function (deltaX, deltaY) {
|
||||
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
|
||||
|
||||
if ( scope.object.fov !== undefined ) {
|
||||
if (scope.object.fov !== undefined) {
|
||||
// perspective
|
||||
var position = scope.object.position;
|
||||
var offset = position.clone();
|
||||
var targetDistance = offset.length();
|
||||
|
||||
// half of the fov is center to top of screen
|
||||
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
|
||||
targetDistance *= Math.tan((scope.object.fov / 2) * Math.PI / 180.0);
|
||||
|
||||
// we actually don't use screenWidth, since perspective camera is fixed to screen height
|
||||
scope.panLeft( 2 * deltaX * targetDistance / element.clientHeight );
|
||||
scope.panUp( 2 * deltaY * targetDistance / element.clientHeight );
|
||||
} else if ( scope.object.top !== undefined ) {
|
||||
|
||||
scope.panLeft(2 * deltaX * targetDistance / element.clientHeight);
|
||||
scope.panUp(2 * deltaY * targetDistance / element.clientHeight);
|
||||
} else if (scope.object.top !== undefined) {
|
||||
// orthographic
|
||||
scope.panLeft( deltaX * (scope.object.right - scope.object.left) / element.clientWidth );
|
||||
scope.panUp( deltaY * (scope.object.top - scope.object.bottom) / element.clientHeight );
|
||||
scope.panLeft(deltaX * (scope.object.right - scope.object.left) / element.clientWidth);
|
||||
scope.panUp(deltaY * (scope.object.top - scope.object.bottom) / element.clientHeight);
|
||||
} else {
|
||||
|
||||
// camera neither orthographic or perspective
|
||||
console.warn( 'WARNING: GeoControls.js encountered an unknown camera type - pan disabled.' );
|
||||
console.warn('WARNING: GeoControls.js encountered an unknown camera type - pan disabled.');
|
||||
}
|
||||
};
|
||||
|
||||
this.update = function (delta) {
|
||||
this.object.rotation.order = 'ZYX';
|
||||
|
||||
|
||||
var object = this.object;
|
||||
|
||||
|
||||
this.object = new THREE.Object3D();
|
||||
this.object.position.copy(object.position);
|
||||
this.object.rotation.copy(object.rotation);
|
||||
this.object.updateMatrix();
|
||||
this.object.updateMatrixWorld();
|
||||
|
||||
|
||||
var position = this.object.position;
|
||||
|
||||
if(delta !== undefined){
|
||||
|
||||
|
||||
if (delta !== undefined) {
|
||||
var multiplier = scope.shiftDown ? 4 : 1;
|
||||
if(this.moveRight){
|
||||
if (this.moveRight) {
|
||||
this.panLeft(-delta * this.moveSpeed * multiplier);
|
||||
}
|
||||
if(this.moveLeft){
|
||||
if (this.moveLeft) {
|
||||
this.panLeft(delta * this.moveSpeed * multiplier);
|
||||
}
|
||||
if(this.moveForward || this.moveForwardMouse){
|
||||
if (this.moveForward || this.moveForwardMouse) {
|
||||
this.panForward(-delta * this.moveSpeed * multiplier);
|
||||
}
|
||||
if(this.moveBackward){
|
||||
if (this.moveBackward) {
|
||||
this.panForward(delta * this.moveSpeed * multiplier);
|
||||
}
|
||||
if(this.rotLeft){
|
||||
scope.rotateLeft( -0.5 * Math.PI * delta / scope.rotateSpeed );
|
||||
if (this.rotLeft) {
|
||||
scope.rotateLeft(-0.5 * Math.PI * delta / scope.rotateSpeed);
|
||||
}
|
||||
if(this.rotRight){
|
||||
scope.rotateLeft( 0.5 * Math.PI * delta / scope.rotateSpeed );
|
||||
if (this.rotRight) {
|
||||
scope.rotateLeft(0.5 * Math.PI * delta / scope.rotateSpeed);
|
||||
}
|
||||
if(this.raiseCamera){
|
||||
//scope.rotateUp( -0.5 * Math.PI * delta / scope.rotateSpeed );
|
||||
scope.panUp( delta * this.moveSpeed * multiplier );
|
||||
if (this.raiseCamera) {
|
||||
// scope.rotateUp( -0.5 * Math.PI * delta / scope.rotateSpeed );
|
||||
scope.panUp(delta * this.moveSpeed * multiplier);
|
||||
}
|
||||
if(this.lowerCamera){
|
||||
//scope.rotateUp( 0.5 * Math.PI * delta / scope.rotateSpeed );
|
||||
scope.panUp( -delta * this.moveSpeed * multiplier );
|
||||
if (this.lowerCamera) {
|
||||
// scope.rotateUp( 0.5 * Math.PI * delta / scope.rotateSpeed );
|
||||
scope.panUp(-delta * this.moveSpeed * multiplier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!pan.equals(new THREE.Vector3(0,0,0))){
|
||||
var event = {
|
||||
|
||||
if (!pan.equals(new THREE.Vector3(0, 0, 0))) {
|
||||
let event = {
|
||||
type: 'move',
|
||||
translation: pan.clone()
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
|
||||
|
||||
position.add(pan);
|
||||
|
||||
if(!(thetaDelta === 0.0 && phiDelta === 0.0)) {
|
||||
var event = {
|
||||
|
||||
if (!(thetaDelta === 0.0 && phiDelta === 0.0)) {
|
||||
let 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);
|
||||
this.object.quaternion.setFromRotationMatrix(res);
|
||||
|
||||
|
||||
this.object.rotation.x += phiDelta;
|
||||
this.object.updateMatrixWorld();
|
||||
|
||||
|
||||
// send transformation proposal to listeners
|
||||
var proposeTransformEvent = {
|
||||
type: "proposeTransform",
|
||||
type: 'proposeTransform',
|
||||
oldPosition: object.position,
|
||||
newPosition: this.object.position,
|
||||
objections: 0,
|
||||
counterProposals: []
|
||||
};
|
||||
this.dispatchEvent(proposeTransformEvent);
|
||||
|
||||
|
||||
// check some counter proposals if transformation wasn't accepted
|
||||
if(proposeTransformEvent.objections > 0 ){
|
||||
if(proposeTransformEvent.counterProposals.length > 0){
|
||||
if (proposeTransformEvent.objections > 0) {
|
||||
if (proposeTransformEvent.counterProposals.length > 0) {
|
||||
var cp = proposeTransformEvent.counterProposals;
|
||||
this.object.position.copy(cp[0]);
|
||||
|
||||
|
||||
proposeTransformEvent.objections = 0;
|
||||
proposeTransformEvent.counterProposals = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// apply transformation, if accepted
|
||||
if(proposeTransformEvent.objections > 0){
|
||||
|
||||
}else{
|
||||
if (proposeTransformEvent.objections > 0) {
|
||||
|
||||
} else {
|
||||
object.position.copy(this.object.position);
|
||||
}
|
||||
|
||||
|
||||
object.rotation.copy(this.object.rotation);
|
||||
|
||||
|
||||
this.object = object;
|
||||
|
||||
thetaDelta = 0;
|
||||
phiDelta = 0;
|
||||
scale = 1;
|
||||
pan.set( 0, 0, 0 );
|
||||
pan.set(0, 0, 0);
|
||||
|
||||
if ( lastPosition.distanceTo( this.object.position ) > 0 ) {
|
||||
this.dispatchEvent( changeEvent );
|
||||
if (lastPosition.distanceTo(this.object.position) > 0) {
|
||||
this.dispatchEvent(changeEvent);
|
||||
|
||||
lastPosition.copy( this.object.position );
|
||||
lastPosition.copy(this.object.position);
|
||||
}
|
||||
|
||||
if(this.track){
|
||||
|
||||
if (this.track) {
|
||||
var pos = this.track.getPointAt(this.trackPos);
|
||||
object.position.copy(pos);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.reset = function () {
|
||||
state = STATE.NONE;
|
||||
|
||||
this.object.position.copy( this.position0 );
|
||||
this.object.position.copy(this.position0);
|
||||
};
|
||||
|
||||
function onMouseDown( event ) {
|
||||
if ( scope.enabled === false ) return;
|
||||
function onMouseDown (event) {
|
||||
if (scope.enabled === false) return;
|
||||
event.preventDefault();
|
||||
|
||||
if ( event.button === 0 ) {
|
||||
if (event.button === 0) {
|
||||
state = STATE.ROTATE;
|
||||
|
||||
rotateStart.set( event.clientX, event.clientY );
|
||||
} else if ( event.button === 1 ) {
|
||||
rotateStart.set(event.clientX, event.clientY);
|
||||
} else if (event.button === 1) {
|
||||
state = STATE.PAN;
|
||||
|
||||
panStart.set( event.clientX, event.clientY );
|
||||
} else if ( event.button === 2 ) {
|
||||
//state = STATE.PAN;
|
||||
//
|
||||
//panStart.set( event.clientX, event.clientY );
|
||||
|
||||
panStart.set(event.clientX, event.clientY);
|
||||
} else if (event.button === 2) {
|
||||
// state = STATE.PAN;
|
||||
// panStart.set( event.clientX, event.clientY );
|
||||
scope.moveForwardMouse = true;
|
||||
}
|
||||
|
||||
//scope.domElement.addEventListener( 'mousemove', onMouseMove, false );
|
||||
//scope.domElement.addEventListener( 'mouseup', onMouseUp, false );
|
||||
scope.dispatchEvent( startEvent );
|
||||
// scope.domElement.addEventListener( 'mousemove', onMouseMove, false );
|
||||
// scope.domElement.addEventListener( 'mouseup', onMouseUp, false );
|
||||
scope.dispatchEvent(startEvent);
|
||||
}
|
||||
|
||||
function onMouseMove( event ) {
|
||||
if ( scope.enabled === false ) return;
|
||||
function onMouseMove (event) {
|
||||
if (scope.enabled === false) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
|
||||
|
||||
if ( state === STATE.ROTATE ) {
|
||||
rotateEnd.set( event.clientX, event.clientY );
|
||||
rotateDelta.subVectors( rotateEnd, rotateStart );
|
||||
if (state === STATE.ROTATE) {
|
||||
rotateEnd.set(event.clientX, event.clientY);
|
||||
rotateDelta.subVectors(rotateEnd, rotateStart);
|
||||
|
||||
// rotating across whole screen goes 360 degrees around
|
||||
scope.rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed );
|
||||
scope.rotateLeft(2 * Math.PI * rotateDelta.x / element.clientWidth * scope.rotateSpeed);
|
||||
|
||||
// rotating up and down along whole screen attempts to go 360, but limited to 180
|
||||
scope.rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed );
|
||||
scope.rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight * scope.rotateSpeed);
|
||||
|
||||
rotateStart.copy( rotateEnd );
|
||||
|
||||
} else if ( state === STATE.PAN ) {
|
||||
panEnd.set( event.clientX, event.clientY );
|
||||
panDelta.subVectors( panEnd, panStart );
|
||||
//panDelta.multiplyScalar(this.moveSpeed).multiplyScalar(0.0001);
|
||||
rotateStart.copy(rotateEnd);
|
||||
} else if (state === STATE.PAN) {
|
||||
panEnd.set(event.clientX, event.clientY);
|
||||
panDelta.subVectors(panEnd, panStart);
|
||||
// panDelta.multiplyScalar(this.moveSpeed).multiplyScalar(0.0001);
|
||||
panDelta.multiplyScalar(0.002).multiplyScalar(scope.moveSpeed);
|
||||
|
||||
scope.pan( panDelta.x, panDelta.y );
|
||||
|
||||
panStart.copy( panEnd );
|
||||
scope.pan(panDelta.x, panDelta.y);
|
||||
|
||||
panStart.copy(panEnd);
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseUp(event) {
|
||||
if ( scope.enabled === false ) return;
|
||||
|
||||
//console.log(event.which);
|
||||
|
||||
if(event.button === 2){
|
||||
function onMouseUp (event) {
|
||||
if (scope.enabled === false) return;
|
||||
|
||||
// console.log(event.which);
|
||||
|
||||
if (event.button === 2) {
|
||||
scope.moveForwardMouse = false;
|
||||
}else{
|
||||
//scope.domElement.removeEventListener( 'mousemove', onMouseMove, false );
|
||||
//scope.domElement.removeEventListener( 'mouseup', onMouseUp, false );
|
||||
scope.dispatchEvent( endEvent );
|
||||
} else {
|
||||
// scope.domElement.removeEventListener( 'mousemove', onMouseMove, false );
|
||||
// scope.domElement.removeEventListener( 'mouseup', onMouseUp, false );
|
||||
scope.dispatchEvent(endEvent);
|
||||
state = STATE.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseWheel(event) {
|
||||
if ( scope.enabled === false || scope.noZoom === true ) return;
|
||||
function onMouseWheel (event) {
|
||||
if (scope.enabled === false || scope.noZoom === true) return;
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
var direction = (event.detail<0 || event.wheelDelta>0) ? 1 : -1;
|
||||
var direction = (event.detail < 0 || event.wheelDelta > 0) ? 1 : -1;
|
||||
var moveSpeed = scope.moveSpeed + scope.moveSpeed * 0.1 * direction;
|
||||
moveSpeed = Math.max(0.1, moveSpeed);
|
||||
|
||||
scope.setMoveSpeed(moveSpeed);
|
||||
|
||||
scope.dispatchEvent( startEvent );
|
||||
scope.dispatchEvent( endEvent );
|
||||
scope.dispatchEvent(startEvent);
|
||||
scope.dispatchEvent(endEvent);
|
||||
}
|
||||
|
||||
this.setMoveSpeed = function(value){
|
||||
if(scope.moveSpeed !== value){
|
||||
|
||||
this.setMoveSpeed = function (value) {
|
||||
if (scope.moveSpeed !== value) {
|
||||
scope.moveSpeed = value;
|
||||
scope.dispatchEvent( {
|
||||
type: "move_speed_changed",
|
||||
scope.dispatchEvent({
|
||||
type: 'move_speed_changed',
|
||||
controls: scope
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function onKeyDown( event ) {
|
||||
if ( scope.enabled === false) return;
|
||||
|
||||
function onKeyDown (event) {
|
||||
if (scope.enabled === false) return;
|
||||
|
||||
scope.shiftDown = event.shiftKey;
|
||||
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
switch (event.keyCode) {
|
||||
case scope.keys.UP: scope.moveForward = true; break;
|
||||
case scope.keys.BOTTOM: scope.moveBackward = true; break;
|
||||
case scope.keys.LEFT: scope.moveLeft = true; break;
|
||||
@ -467,19 +447,18 @@ Potree.GeoControls = function ( object, domElement ) {
|
||||
case scope.keys.W: scope.moveForward = true; break;
|
||||
case scope.keys.S: scope.moveBackward = true; break;
|
||||
case scope.keys.A: scope.moveLeft = true; break;
|
||||
case scope.keys.D: scope.moveRight = true; break;
|
||||
case scope.keys.Q: scope.rotLeft = true; break;
|
||||
case scope.keys.E: scope.rotRight = true; break;
|
||||
case scope.keys.R: scope.raiseCamera = true; break;
|
||||
case scope.keys.F: scope.lowerCamera = true; break;
|
||||
case scope.keys.D: scope.moveRight = true; break;
|
||||
case scope.keys.Q: scope.rotLeft = true; break;
|
||||
case scope.keys.E: scope.rotRight = true; break;
|
||||
case scope.keys.R: scope.raiseCamera = true; break;
|
||||
case scope.keys.F: scope.lowerCamera = true; break;
|
||||
}
|
||||
}
|
||||
|
||||
function onKeyUp( event ) {
|
||||
|
||||
|
||||
function onKeyUp (event) {
|
||||
scope.shiftDown = event.shiftKey;
|
||||
|
||||
switch ( event.keyCode ) {
|
||||
|
||||
switch (event.keyCode) {
|
||||
case scope.keys.W: scope.moveForward = false; break;
|
||||
case scope.keys.S: scope.moveBackward = false; break;
|
||||
case scope.keys.A: scope.moveLeft = false; break;
|
||||
@ -488,27 +467,26 @@ Potree.GeoControls = function ( object, domElement ) {
|
||||
case scope.keys.BOTTOM: scope.moveBackward = false; break;
|
||||
case scope.keys.LEFT: scope.moveLeft = false; break;
|
||||
case scope.keys.RIGHT: scope.moveRight = false; break;
|
||||
case scope.keys.Q: scope.rotLeft = false; break;
|
||||
case scope.keys.Q: scope.rotLeft = false; break;
|
||||
case scope.keys.E: scope.rotRight = false; break;
|
||||
case scope.keys.R: scope.raiseCamera = false; break;
|
||||
case scope.keys.F: scope.lowerCamera = false; break;
|
||||
case scope.keys.R: scope.raiseCamera = false; break;
|
||||
case scope.keys.F: scope.lowerCamera = false; break;
|
||||
}
|
||||
}
|
||||
|
||||
this.domElement.addEventListener( 'contextmenu', function ( event ) { event.preventDefault(); }, false );
|
||||
this.domElement.addEventListener( 'mousedown', onMouseDown, false );
|
||||
this.domElement.addEventListener( 'mousewheel', onMouseWheel, false );
|
||||
this.domElement.addEventListener( 'DOMMouseScroll', onMouseWheel, false ); // firefox
|
||||
|
||||
scope.domElement.addEventListener( 'mousemove', onMouseMove, false );
|
||||
scope.domElement.addEventListener( 'mouseup', onMouseUp, false );
|
||||
this.domElement.addEventListener('contextmenu', function (event) { event.preventDefault(); }, false);
|
||||
this.domElement.addEventListener('mousedown', onMouseDown, false);
|
||||
this.domElement.addEventListener('mousewheel', onMouseWheel, false);
|
||||
this.domElement.addEventListener('DOMMouseScroll', onMouseWheel, false); // firefox
|
||||
|
||||
if(this.domElement.tabIndex === -1){
|
||||
scope.domElement.addEventListener('mousemove', onMouseMove, false);
|
||||
scope.domElement.addEventListener('mouseup', onMouseUp, false);
|
||||
|
||||
if (this.domElement.tabIndex === -1) {
|
||||
this.domElement.tabIndex = 2222;
|
||||
}
|
||||
scope.domElement.addEventListener( 'keydown', onKeyDown, false );
|
||||
scope.domElement.addEventListener( 'keyup', onKeyUp, false );
|
||||
|
||||
scope.domElement.addEventListener('keydown', onKeyDown, false);
|
||||
scope.domElement.addEventListener('keyup', onKeyUp, false);
|
||||
};
|
||||
|
||||
Potree.GeoControls.prototype = Object.create( THREE.EventDispatcher.prototype );
|
||||
Potree.GeoControls.prototype = Object.create(THREE.EventDispatcher.prototype);
|
||||
|
||||
@ -2,76 +2,75 @@
|
||||
* @author mschuetz / http://mschuetz.at
|
||||
*
|
||||
*
|
||||
*/
|
||||
Potree.InputHandler = class InputHandler extends THREE.EventDispatcher{
|
||||
|
||||
constructor(viewer){
|
||||
*/
|
||||
Potree.InputHandler = class InputHandler extends THREE.EventDispatcher {
|
||||
constructor (viewer) {
|
||||
super();
|
||||
|
||||
|
||||
this.viewer = viewer;
|
||||
this.renderer = viewer.renderer;
|
||||
this.domElement = this.renderer.domElement;
|
||||
|
||||
|
||||
this.scene = null;
|
||||
this.interactiveScenes = [];
|
||||
this.inputListeners = [];
|
||||
|
||||
|
||||
this.drag = null;
|
||||
this.mouse = new THREE.Vector2(0, 0);
|
||||
|
||||
|
||||
this.selection = [];
|
||||
|
||||
|
||||
this.hoveredElements = [];
|
||||
this.pressedKeys = {};
|
||||
|
||||
|
||||
this.wheelDelta = 0;
|
||||
|
||||
|
||||
this.speed = 1;
|
||||
|
||||
|
||||
this.logMessages = false;
|
||||
|
||||
if(this.domElement.tabIndex === -1){
|
||||
|
||||
if (this.domElement.tabIndex === -1) {
|
||||
this.domElement.tabIndex = 2222;
|
||||
}
|
||||
|
||||
this.domElement.addEventListener("contextmenu", (event) => { event.preventDefault(); }, false );
|
||||
this.domElement.addEventListener("click", this.onMouseClick.bind(this), false);
|
||||
this.domElement.addEventListener("mousedown", this.onMouseDown.bind(this), false);
|
||||
this.domElement.addEventListener("mouseup", this.onMouseUp.bind(this), false);
|
||||
this.domElement.addEventListener("mousemove", this.onMouseMove.bind(this), false);
|
||||
this.domElement.addEventListener("mousewheel", this.onMouseWheel.bind(this), false );
|
||||
this.domElement.addEventListener("DOMMouseScroll", this.onMouseWheel.bind(this), false ); // Firefox
|
||||
this.domElement.addEventListener("dblclick", this.onDoubleClick.bind(this));
|
||||
this.domElement.addEventListener("keydown", this.onKeyDown.bind(this));
|
||||
this.domElement.addEventListener("keyup", this.onKeyUp.bind(this));
|
||||
this.domElement.addEventListener("touchstart", this.onTouchStart.bind(this));
|
||||
this.domElement.addEventListener("touchend", this.onTouchEnd.bind(this));
|
||||
this.domElement.addEventListener("touchmove", this.onTouchMove.bind(this));
|
||||
|
||||
this.domElement.addEventListener('contextmenu', (event) => { event.preventDefault(); }, false);
|
||||
this.domElement.addEventListener('click', this.onMouseClick.bind(this), false);
|
||||
this.domElement.addEventListener('mousedown', this.onMouseDown.bind(this), false);
|
||||
this.domElement.addEventListener('mouseup', this.onMouseUp.bind(this), false);
|
||||
this.domElement.addEventListener('mousemove', this.onMouseMove.bind(this), false);
|
||||
this.domElement.addEventListener('mousewheel', this.onMouseWheel.bind(this), false);
|
||||
this.domElement.addEventListener('DOMMouseScroll', this.onMouseWheel.bind(this), false); // Firefox
|
||||
this.domElement.addEventListener('dblclick', this.onDoubleClick.bind(this));
|
||||
this.domElement.addEventListener('keydown', this.onKeyDown.bind(this));
|
||||
this.domElement.addEventListener('keyup', this.onKeyUp.bind(this));
|
||||
this.domElement.addEventListener('touchstart', this.onTouchStart.bind(this));
|
||||
this.domElement.addEventListener('touchend', this.onTouchEnd.bind(this));
|
||||
this.domElement.addEventListener('touchmove', this.onTouchMove.bind(this));
|
||||
}
|
||||
|
||||
addInputListener(listener){
|
||||
|
||||
addInputListener (listener) {
|
||||
this.inputListeners.push(listener);
|
||||
}
|
||||
|
||||
removeInputListener(listener){
|
||||
|
||||
removeInputListener (listener) {
|
||||
this.inputListeners = this.inputListeners.filter(e => e !== listener);
|
||||
}
|
||||
|
||||
onTouchStart(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onTouchStart");
|
||||
|
||||
|
||||
onTouchStart (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onTouchStart');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
if(e.touches.length === 1){
|
||||
if (e.touches.length === 1) {
|
||||
let rect = this.domElement.getBoundingClientRect();
|
||||
let x = e.touches[0].pageX - rect.left;
|
||||
let y = e.touches[0].pageY - rect.top;
|
||||
this.mouse.set(x, y);
|
||||
|
||||
|
||||
this.startDragging(null);
|
||||
}
|
||||
|
||||
for(let inputListener of this.inputListeners){
|
||||
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: e.type,
|
||||
touches: e.touches,
|
||||
@ -79,23 +78,23 @@ Potree.InputHandler = class InputHandler extends THREE.EventDispatcher{
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onTouchEnd(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onTouchEnd");
|
||||
|
||||
|
||||
onTouchEnd (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onTouchEnd');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
for(let inputListener of this.inputListeners){
|
||||
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: "drop",
|
||||
type: 'drop',
|
||||
drag: this.drag,
|
||||
viewer: this.viewer
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.drag = null;
|
||||
|
||||
for(let inputListener of this.inputListeners){
|
||||
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: e.type,
|
||||
touches: e.touches,
|
||||
@ -103,107 +102,106 @@ Potree.InputHandler = class InputHandler extends THREE.EventDispatcher{
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
onTouchMove(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onTouchMove");
|
||||
|
||||
|
||||
onTouchMove (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onTouchMove');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
if(e.touches.length === 1){
|
||||
|
||||
if (e.touches.length === 1) {
|
||||
let rect = this.domElement.getBoundingClientRect();
|
||||
let x = e.touches[0].pageX - rect.left;
|
||||
let y = e.touches[0].pageY - rect.top;
|
||||
this.mouse.set(x, y);
|
||||
|
||||
if(this.drag){
|
||||
|
||||
if (this.drag) {
|
||||
this.drag.mouse = 1;
|
||||
|
||||
|
||||
this.drag.lastDrag.x = x - this.drag.end.x;
|
||||
this.drag.lastDrag.y = y - this.drag.end.y;
|
||||
|
||||
|
||||
this.drag.end.set(x, y);
|
||||
|
||||
if(this.logMessages) console.log(this.constructor.name + ": drag: ");
|
||||
for(let inputListener of this.inputListeners){
|
||||
|
||||
if (this.logMessages) console.log(this.constructor.name + ': drag: ');
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: "drag",
|
||||
type: 'drag',
|
||||
drag: this.drag,
|
||||
viewer: this.viewer
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(let inputListener of this.inputListeners){
|
||||
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: e.type,
|
||||
touches: e.touches,
|
||||
changedTouches: e.changedTouches
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// DEBUG CODE
|
||||
//let debugTouches = [...e.touches, {
|
||||
// pageX: this.domElement.clientWidth / 2,
|
||||
// let debugTouches = [...e.touches, {
|
||||
// pageX: this.domElement.clientWidth / 2,
|
||||
// pageY: this.domElement.clientHeight / 2}];
|
||||
//for(let inputListener of this.inputListeners){
|
||||
// for(let inputListener of this.inputListeners){
|
||||
// inputListener.dispatchEvent({
|
||||
// type: e.type,
|
||||
// touches: debugTouches,
|
||||
// changedTouches: e.changedTouches
|
||||
// });
|
||||
//}
|
||||
// }
|
||||
}
|
||||
|
||||
onKeyDown(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onKeyDown");
|
||||
|
||||
if(e.keyCode === 46 && this.selection.length > 0){
|
||||
|
||||
onKeyDown (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onKeyDown');
|
||||
|
||||
if (e.keyCode === 46 && this.selection.length > 0) {
|
||||
// DELETE
|
||||
this.dispatchEvent({
|
||||
type: "delete",
|
||||
type: 'delete',
|
||||
selection: this.selection
|
||||
});
|
||||
|
||||
|
||||
this.deselectAll();
|
||||
}
|
||||
|
||||
|
||||
this.dispatchEvent({
|
||||
type: "keydown",
|
||||
type: 'keydown',
|
||||
keyCode: e.keyCode,
|
||||
event: e
|
||||
});
|
||||
|
||||
//for(let l of this.inputListeners){
|
||||
|
||||
// for(let l of this.inputListeners){
|
||||
// l.dispatchEvent({
|
||||
// type: "keydown",
|
||||
// keyCode: e.keyCode,
|
||||
// event: e
|
||||
// });
|
||||
//}
|
||||
|
||||
// }
|
||||
|
||||
this.pressedKeys[e.keyCode] = true;
|
||||
|
||||
//e.preventDefault();
|
||||
|
||||
// e.preventDefault();
|
||||
}
|
||||
|
||||
onKeyUp(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onKeyUp");
|
||||
|
||||
|
||||
onKeyUp (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onKeyUp');
|
||||
|
||||
delete this.pressedKeys[e.keyCode];
|
||||
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
onDoubleClick(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onDoubleClick");
|
||||
|
||||
|
||||
|
||||
onDoubleClick (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onDoubleClick');
|
||||
|
||||
let consumed = false;
|
||||
for(let hovered of this.hoveredElements){
|
||||
if(hovered._listeners && hovered._listeners["dblclick"]){
|
||||
for (let hovered of this.hoveredElements) {
|
||||
if (hovered._listeners && hovered._listeners['dblclick']) {
|
||||
hovered.object.dispatchEvent({
|
||||
type: "dblclick",
|
||||
type: 'dblclick',
|
||||
mouse: this.mouse,
|
||||
object: hovered.object
|
||||
});
|
||||
@ -211,248 +209,245 @@ Potree.InputHandler = class InputHandler extends THREE.EventDispatcher{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!consumed){
|
||||
for(let inputListener of this.inputListeners){
|
||||
|
||||
if (!consumed) {
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: "dblclick",
|
||||
type: 'dblclick',
|
||||
mouse: this.mouse,
|
||||
object: null
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
onMouseClick(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onMouseClick");
|
||||
|
||||
|
||||
onMouseClick (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onMouseClick');
|
||||
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
onMouseDown(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onMouseDown");
|
||||
|
||||
|
||||
onMouseDown (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onMouseDown');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
if(this.hoveredElements.length === 0){
|
||||
for(let inputListener of this.inputListeners){
|
||||
|
||||
if (this.hoveredElements.length === 0) {
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: "mousedown",
|
||||
type: 'mousedown',
|
||||
viewer: this.viewer,
|
||||
mouse: this.mouse
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if(!this.drag){
|
||||
|
||||
if (!this.drag) {
|
||||
let target = this.hoveredElements
|
||||
.find(el => (
|
||||
el.object._listeners
|
||||
&& el.object._listeners["drag"]
|
||||
&& el.object._listeners["drag"].length > 0));
|
||||
|
||||
if(target){
|
||||
el.object._listeners &&
|
||||
el.object._listeners['drag'] &&
|
||||
el.object._listeners['drag'].length > 0));
|
||||
|
||||
if (target) {
|
||||
this.startDragging(target.object, {location: target.point});
|
||||
}else{
|
||||
} else {
|
||||
this.startDragging(null);
|
||||
}
|
||||
}
|
||||
|
||||
if(this.scene){
|
||||
|
||||
if (this.scene) {
|
||||
this.viewStart = this.scene.view.clone();
|
||||
}
|
||||
}
|
||||
|
||||
onMouseUp(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onMouseUp");
|
||||
|
||||
|
||||
onMouseUp (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onMouseUp');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
let noMovement = this.getNormalizedDrag().length() === 0;
|
||||
|
||||
if(e.button === THREE.MOUSE.LEFT){
|
||||
if(noMovement){
|
||||
|
||||
|
||||
let noMovement = this.getNormalizedDrag().length() === 0;
|
||||
|
||||
if (e.button === THREE.MOUSE.LEFT) {
|
||||
if (noMovement) {
|
||||
let selectable = this.hoveredElements
|
||||
.find(el => el.object._listeners && el.object._listeners["select"]);
|
||||
|
||||
if(selectable){
|
||||
.find(el => el.object._listeners && el.object._listeners['select']);
|
||||
|
||||
if (selectable) {
|
||||
selectable = selectable.object;
|
||||
|
||||
if(this.isSelected(selectable)){
|
||||
|
||||
if (this.isSelected(selectable)) {
|
||||
this.selection
|
||||
.filter(e => e !== selectable)
|
||||
.forEach(e => this.toggleSelection(e));
|
||||
}else{
|
||||
} else {
|
||||
this.deselectAll();
|
||||
this.toggleSelection(selectable);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
this.deselectAll();
|
||||
}
|
||||
}
|
||||
}else if((e.button === THREE.MOUSE.RIGHT) && noMovement){
|
||||
} else if ((e.button === THREE.MOUSE.RIGHT) && noMovement) {
|
||||
this.deselectAll();
|
||||
}
|
||||
|
||||
if(this.hoveredElements.length === 0){
|
||||
for(let inputListener of this.inputListeners){
|
||||
|
||||
if (this.hoveredElements.length === 0) {
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: "mouseup",
|
||||
type: 'mouseup',
|
||||
viewer: this.viewer,
|
||||
mouse: this.mouse
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if(this.drag){
|
||||
if(this.drag.object){
|
||||
|
||||
if (this.drag) {
|
||||
if (this.drag.object) {
|
||||
this.drag.object.dispatchEvent({
|
||||
type: "drop",
|
||||
type: 'drop',
|
||||
drag: this.drag,
|
||||
viewer: this.viewer
|
||||
|
||||
|
||||
});
|
||||
}else{
|
||||
if(this.logMessages) console.log(this.constructor.name + ": drop: ");
|
||||
for(let inputListener of this.inputListeners){
|
||||
} else {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': drop: ');
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: "drop",
|
||||
type: 'drop',
|
||||
drag: this.drag,
|
||||
viewer: this.viewer
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.drag = null;
|
||||
}
|
||||
}
|
||||
|
||||
onMouseMove(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onMouseMove");
|
||||
|
||||
}
|
||||
|
||||
onMouseMove (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onMouseMove');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
let rect = this.domElement.getBoundingClientRect();
|
||||
let x = e.clientX - rect.left;
|
||||
let y = e.clientY - rect.top;
|
||||
this.mouse.set(x, y);
|
||||
|
||||
if(this.drag){
|
||||
|
||||
if (this.drag) {
|
||||
this.drag.mouse = e.buttons;
|
||||
|
||||
|
||||
this.drag.lastDrag.x = x - this.drag.end.x;
|
||||
this.drag.lastDrag.y = y - this.drag.end.y;
|
||||
|
||||
|
||||
this.drag.end.set(x, y);
|
||||
|
||||
if(this.drag.object){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": drag: " + this.drag.object.name);
|
||||
|
||||
if (this.drag.object) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': drag: ' + this.drag.object.name);
|
||||
this.drag.object.dispatchEvent({
|
||||
type: "drag",
|
||||
type: 'drag',
|
||||
drag: this.drag,
|
||||
viewer: this.viewer
|
||||
});
|
||||
}else{
|
||||
if(this.logMessages) console.log(this.constructor.name + ": drag: ");
|
||||
for(let inputListener of this.inputListeners){
|
||||
} else {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': drag: ');
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: "drag",
|
||||
type: 'drag',
|
||||
drag: this.drag,
|
||||
viewer: this.viewer
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let hoveredElements = this.getHoveredElements();
|
||||
let currentlyHoveredObjects = hoveredElements.map(e => e.object);
|
||||
let previouslyHoveredObjects = this.hoveredElements.map(e => e.object);
|
||||
|
||||
let now = currentlyHoveredObjects.find(e => (e._listeners && e._listeners["mouseover"]));
|
||||
let prev = previouslyHoveredObjects.find(e => (e._listeners && e._listeners["mouseover"]));
|
||||
|
||||
if(now !== prev){
|
||||
if(now){
|
||||
|
||||
let now = currentlyHoveredObjects.find(e => (e._listeners && e._listeners['mouseover']));
|
||||
let prev = previouslyHoveredObjects.find(e => (e._listeners && e._listeners['mouseover']));
|
||||
|
||||
if (now !== prev) {
|
||||
if (now) {
|
||||
now.dispatchEvent({
|
||||
type: "mouseover",
|
||||
type: 'mouseover',
|
||||
object: now
|
||||
});
|
||||
}
|
||||
|
||||
if(prev){
|
||||
|
||||
if (prev) {
|
||||
prev.dispatchEvent({
|
||||
type: "mouseleave",
|
||||
type: 'mouseleave',
|
||||
object: prev
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//let justHovered = currentlyHoveredObjects
|
||||
|
||||
// let justHovered = currentlyHoveredObjects
|
||||
// .filter(e => previouslyHoveredObjects.indexOf(e) === -1);
|
||||
//let justUnhovered = previouslyHoveredObjects
|
||||
// let justUnhovered = previouslyHoveredObjects
|
||||
// .filter(e => currentlyHoveredObjects.indexOf(e) === -1);
|
||||
//
|
||||
//justHovered = justHovered.find(e => (e._listeners && e._listeners["mouseover"]));
|
||||
//justUnhovered = justUnhovered.find(e => (e._listeners && e._listeners["mouseover"]));
|
||||
|
||||
|
||||
|
||||
//let over = justHovered.find(e => (e._listeners && e._listeners["mouseover"]));
|
||||
//if(over){
|
||||
//
|
||||
// justHovered = justHovered.find(e => (e._listeners && e._listeners["mouseover"]));
|
||||
// justUnhovered = justUnhovered.find(e => (e._listeners && e._listeners["mouseover"]));
|
||||
|
||||
// let over = justHovered.find(e => (e._listeners && e._listeners["mouseover"]));
|
||||
// if(over){
|
||||
// over.dispatchEvent({
|
||||
// type: "mouseover",
|
||||
// object: over
|
||||
// });
|
||||
//}
|
||||
// }
|
||||
//
|
||||
//let leave = justUnhovered.find(e => (e._listeners && e._listeners["mouseleave"]));
|
||||
//if(leave){
|
||||
// let leave = justUnhovered.find(e => (e._listeners && e._listeners["mouseleave"]));
|
||||
// if(leave){
|
||||
// leave.dispatchEvent({
|
||||
// type: "mouseleave",
|
||||
// object: leave
|
||||
// });
|
||||
//}
|
||||
|
||||
// }
|
||||
|
||||
this.hoveredElements = hoveredElements;
|
||||
}
|
||||
|
||||
onMouseWheel(e){
|
||||
if(this.logMessages) console.log(this.constructor.name + ": onMouseWheel");
|
||||
|
||||
|
||||
onMouseWheel (e) {
|
||||
if (this.logMessages) console.log(this.constructor.name + ': onMouseWheel');
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
let delta = 0;
|
||||
if( e.wheelDelta !== undefined ) { // WebKit / Opera / Explorer 9
|
||||
if (e.wheelDelta !== undefined) { // WebKit / Opera / Explorer 9
|
||||
delta = e.wheelDelta;
|
||||
} else if ( e.detail !== undefined ) { // Firefox
|
||||
} else if (e.detail !== undefined) { // Firefox
|
||||
delta = -e.detail;
|
||||
}
|
||||
|
||||
|
||||
let ndelta = Math.sign(delta);
|
||||
|
||||
//this.wheelDelta += Math.sign(delta);
|
||||
|
||||
if(this.hoveredElement){
|
||||
|
||||
// this.wheelDelta += Math.sign(delta);
|
||||
|
||||
if (this.hoveredElement) {
|
||||
this.hoveredElement.object.dispatchEvent({
|
||||
type: "mousewheel",
|
||||
type: 'mousewheel',
|
||||
delta: ndelta,
|
||||
object: this.hoveredElement.object
|
||||
});
|
||||
}else{
|
||||
for(let inputListener of this.inputListeners){
|
||||
} else {
|
||||
for (let inputListener of this.inputListeners) {
|
||||
inputListener.dispatchEvent({
|
||||
type: "mousewheel",
|
||||
type: 'mousewheel',
|
||||
delta: ndelta,
|
||||
object: null
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startDragging(object, args = null){
|
||||
|
||||
startDragging (object, args = null) {
|
||||
this.drag = {
|
||||
start: this.mouse.clone(),
|
||||
end: this.mouse.clone(),
|
||||
@ -460,174 +455,169 @@ Potree.InputHandler = class InputHandler extends THREE.EventDispatcher{
|
||||
startView: this.scene.view.clone(),
|
||||
object: object
|
||||
};
|
||||
|
||||
if(args){
|
||||
for(let key of Object.keys(args)){
|
||||
|
||||
if (args) {
|
||||
for (let key of Object.keys(args)) {
|
||||
this.drag[key] = args[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getMousePointCloudIntersection(mouse){
|
||||
|
||||
getMousePointCloudIntersection (mouse) {
|
||||
return Potree.utils.getMousePointCloudIntersection(
|
||||
this.mouse,
|
||||
this.scene.camera,
|
||||
this.renderer,
|
||||
this.mouse,
|
||||
this.scene.camera,
|
||||
this.renderer,
|
||||
this.scene.pointclouds);
|
||||
}
|
||||
|
||||
toggleSelection(object){
|
||||
|
||||
|
||||
toggleSelection (object) {
|
||||
let oldSelection = this.selection;
|
||||
|
||||
|
||||
let index = this.selection.indexOf(object);
|
||||
|
||||
if(index === -1){
|
||||
|
||||
if (index === -1) {
|
||||
this.selection.push(object);
|
||||
object.dispatchEvent({
|
||||
type: "select"
|
||||
type: 'select'
|
||||
});
|
||||
}else{
|
||||
} else {
|
||||
this.selection.splice(index, 1);
|
||||
object.dispatchEvent({
|
||||
type: "deselect"
|
||||
type: 'deselect'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
this.dispatchEvent({
|
||||
type: "selection_changed",
|
||||
type: 'selection_changed',
|
||||
oldSelection: oldSelection,
|
||||
selection: this.selection
|
||||
});
|
||||
}
|
||||
|
||||
deselectAll(){
|
||||
for(let object of this.selection){
|
||||
|
||||
deselectAll () {
|
||||
for (let object of this.selection) {
|
||||
object.dispatchEvent({
|
||||
type: "deselect"
|
||||
type: 'deselect'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
let oldSelection = this.selection;
|
||||
|
||||
if(this.selection.length > 0){
|
||||
|
||||
if (this.selection.length > 0) {
|
||||
this.selection = [];
|
||||
this.dispatchEvent({
|
||||
type: "selection_changed",
|
||||
type: 'selection_changed',
|
||||
oldSelection: oldSelection,
|
||||
selection: this.selection
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
isSelected(object){
|
||||
|
||||
isSelected (object) {
|
||||
let index = this.selection.indexOf(object);
|
||||
|
||||
|
||||
return index !== -1;
|
||||
}
|
||||
|
||||
registerInteractiveScene(scene){
|
||||
|
||||
registerInteractiveScene (scene) {
|
||||
let index = this.interactiveScenes.indexOf(scene);
|
||||
if(index === -1){
|
||||
if (index === -1) {
|
||||
this.interactiveScenes.push(scene);
|
||||
}
|
||||
}
|
||||
|
||||
unregisterInteractiveScene(scene){
|
||||
|
||||
unregisterInteractiveScene (scene) {
|
||||
let index = this.interactiveScenes.indexOf(scene);
|
||||
if (index > -1) {
|
||||
this.interactiveScenes.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
getHoveredElement(){
|
||||
|
||||
getHoveredElement () {
|
||||
let hoveredElements = this.getHoveredElements();
|
||||
if(hoveredElements.length > 0){
|
||||
if (hoveredElements.length > 0) {
|
||||
return hoveredElements[0];
|
||||
}else{
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
getHoveredElements(){
|
||||
|
||||
|
||||
getHoveredElements () {
|
||||
let scenes = this.interactiveScenes.concat(this.scene.scene);
|
||||
|
||||
let interactableListeners = ["mouseover", "mouseleave", "drag", "drop", "click", "select", "deselect"];
|
||||
|
||||
let interactableListeners = ['mouseover', 'mouseleave', 'drag', 'drop', 'click', 'select', 'deselect'];
|
||||
let interactables = [];
|
||||
for(let scene of scenes){
|
||||
for (let scene of scenes) {
|
||||
scene.traverseVisible(node => {
|
||||
if(node._listeners && node.visible){
|
||||
if (node._listeners && node.visible) {
|
||||
let hasInteractableListener = interactableListeners.filter((e) => {
|
||||
return node._listeners[e] !== undefined
|
||||
return node._listeners[e] !== undefined;
|
||||
}).length > 0;
|
||||
|
||||
if(hasInteractableListener){
|
||||
|
||||
if (hasInteractableListener) {
|
||||
interactables.push(node);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let nmouse = {
|
||||
x: (this.mouse.x / this.domElement.clientWidth ) * 2 - 1,
|
||||
y: - (this.mouse.y / this.domElement.clientHeight ) * 2 + 1
|
||||
|
||||
let nmouse = {
|
||||
x: (this.mouse.x / this.domElement.clientWidth) * 2 - 1,
|
||||
y: -(this.mouse.y / this.domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(this.scene.camera);
|
||||
|
||||
|
||||
let raycaster = new THREE.Raycaster();
|
||||
raycaster.ray.set( this.scene.camera.position, vector.sub( this.scene.camera.position ).normalize() );
|
||||
raycaster.ray.set(this.scene.camera.position, vector.sub(this.scene.camera.position).normalize());
|
||||
raycaster.linePrecision = 0.2;
|
||||
|
||||
|
||||
let intersections = raycaster.intersectObjects(interactables, false);
|
||||
|
||||
|
||||
return intersections;
|
||||
|
||||
//if(intersections.length > 0){
|
||||
|
||||
// if(intersections.length > 0){
|
||||
// return intersections[0];
|
||||
//}else{
|
||||
// }else{
|
||||
// return null;
|
||||
//}
|
||||
}
|
||||
|
||||
setScene(scene){
|
||||
this.deselectAll();
|
||||
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
update(delta){
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
getNormalizedDrag(){
|
||||
if(!this.drag){
|
||||
setScene (scene) {
|
||||
this.deselectAll();
|
||||
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
update (delta) {
|
||||
|
||||
}
|
||||
|
||||
getNormalizedDrag () {
|
||||
if (!this.drag) {
|
||||
return new THREE.Vector2(0, 0);
|
||||
}
|
||||
|
||||
|
||||
let diff = new THREE.Vector2().subVectors(this.drag.end, this.drag.start);
|
||||
|
||||
diff.x = diff.x / this.domElement.clientWidth;
|
||||
diff.y = diff.y / this.domElement.clientHeight;
|
||||
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
getNormalizedLastDrag(){
|
||||
if(!this.drag){
|
||||
|
||||
getNormalizedLastDrag () {
|
||||
if (!this.drag) {
|
||||
return new THREE.Vector2(0, 0);
|
||||
}
|
||||
|
||||
|
||||
let lastDrag = this.drag.lastDrag.clone();
|
||||
|
||||
|
||||
lastDrag.x = lastDrag.x / this.domElement.clientWidth;
|
||||
lastDrag.y = lastDrag.y / this.domElement.clientHeight;
|
||||
|
||||
|
||||
return lastDrag;
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* @author mschuetz / http://mschuetz.at
|
||||
*
|
||||
* adapted from THREE.OrbitControls by
|
||||
* adapted from THREE.OrbitControls by
|
||||
*
|
||||
* @author qiao / https://github.com/qiao
|
||||
* @author mrdoob / http://mrdoob.com
|
||||
@ -12,100 +12,94 @@
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
Potree.OrbitControls = class OrbitControls extends THREE.EventDispatcher{
|
||||
|
||||
constructor(viewer){
|
||||
super()
|
||||
|
||||
|
||||
Potree.OrbitControls = class OrbitControls extends THREE.EventDispatcher {
|
||||
constructor (viewer) {
|
||||
super();
|
||||
|
||||
this.viewer = viewer;
|
||||
this.renderer = viewer.renderer;
|
||||
|
||||
|
||||
this.scene = null;
|
||||
this.sceneControls = new THREE.Scene();
|
||||
|
||||
|
||||
this.rotationSpeed = 5;
|
||||
|
||||
|
||||
this.fadeFactor = 10;
|
||||
this.yawDelta = 0;
|
||||
this.pitchDelta = 0;
|
||||
this.panDelta = new THREE.Vector2(0, 0);
|
||||
this.radiusDelta = 0;
|
||||
|
||||
|
||||
this.tweens = [];
|
||||
|
||||
|
||||
|
||||
let drag = (e) => {
|
||||
if(e.drag.object !== null){
|
||||
if (e.drag.object !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(e.drag.startHandled === undefined){
|
||||
|
||||
if (e.drag.startHandled === undefined) {
|
||||
e.drag.startHandled = true;
|
||||
|
||||
this.dispatchEvent({type: "start"});
|
||||
|
||||
this.dispatchEvent({type: 'start'});
|
||||
}
|
||||
|
||||
|
||||
let ndrag = {
|
||||
x: e.drag.lastDrag.x / this.renderer.domElement.clientWidth,
|
||||
y: e.drag.lastDrag.y / this.renderer.domElement.clientHeight
|
||||
};
|
||||
|
||||
if(e.drag.mouse === Potree.MOUSE.LEFT){
|
||||
|
||||
if (e.drag.mouse === Potree.MOUSE.LEFT) {
|
||||
this.yawDelta += ndrag.x * this.rotationSpeed;
|
||||
this.pitchDelta += ndrag.y * this.rotationSpeed;
|
||||
|
||||
|
||||
this.stopTweens();
|
||||
}else if(e.drag.mouse === Potree.MOUSE.RIGHT){
|
||||
} else if (e.drag.mouse === Potree.MOUSE.RIGHT) {
|
||||
this.panDelta.x += ndrag.x;
|
||||
this.panDelta.y += ndrag.y;
|
||||
|
||||
|
||||
this.stopTweens();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
let drop = e => {
|
||||
this.dispatchEvent({type: "end"});
|
||||
this.dispatchEvent({type: 'end'});
|
||||
};
|
||||
|
||||
|
||||
let scroll = (e) => {
|
||||
let resolvedRadius = this.scene.view.radius + this.radiusDelta;
|
||||
|
||||
|
||||
this.radiusDelta += -e.delta * resolvedRadius * 0.1;
|
||||
|
||||
|
||||
this.stopTweens();
|
||||
};
|
||||
|
||||
|
||||
let dblclick = (e) => {
|
||||
this.zoomToLocation(e.mouse);
|
||||
};
|
||||
|
||||
|
||||
|
||||
let previousTouch = null;
|
||||
let touchStart = e => {
|
||||
previousTouch = e;
|
||||
};
|
||||
|
||||
|
||||
let touchEnd = e => {
|
||||
previousTouch = e;
|
||||
};
|
||||
|
||||
|
||||
let touchMove = e => {
|
||||
|
||||
if(e.touches.length === 2 && previousTouch.touches.length === 2){
|
||||
if (e.touches.length === 2 && previousTouch.touches.length === 2) {
|
||||
let prev = previousTouch;
|
||||
let curr = e;
|
||||
|
||||
|
||||
let prevDX = prev.touches[0].pageX - prev.touches[1].pageX;
|
||||
let prevDY = prev.touches[0].pageY - prev.touches[1].pageY;
|
||||
let prevDist = Math.sqrt(prevDX * prevDX + prevDY * prevDY);
|
||||
|
||||
|
||||
let currDX = curr.touches[0].pageX - curr.touches[1].pageX;
|
||||
let currDY = curr.touches[0].pageY - curr.touches[1].pageY;
|
||||
let currDist = Math.sqrt(currDX * currDX + currDY * currDY);
|
||||
|
||||
|
||||
let delta = currDist / prevDist;
|
||||
let resolvedRadius = this.scene.view.radius + this.radiusDelta;
|
||||
let newRadius = resolvedRadius / delta;
|
||||
@ -113,162 +107,158 @@ Potree.OrbitControls = class OrbitControls extends THREE.EventDispatcher{
|
||||
|
||||
this.stopTweens();
|
||||
}
|
||||
|
||||
|
||||
previousTouch = e;
|
||||
};
|
||||
|
||||
this.addEventListener("touchstart", touchStart);
|
||||
this.addEventListener("touchend", touchEnd);
|
||||
this.addEventListener("touchmove", touchMove);
|
||||
this.addEventListener("drag", drag);
|
||||
this.addEventListener("drop", drop);
|
||||
this.addEventListener("mousewheel", scroll);
|
||||
this.addEventListener("dblclick", dblclick);
|
||||
|
||||
|
||||
this.addEventListener('touchstart', touchStart);
|
||||
this.addEventListener('touchend', touchEnd);
|
||||
this.addEventListener('touchmove', touchMove);
|
||||
this.addEventListener('drag', drag);
|
||||
this.addEventListener('drop', drop);
|
||||
this.addEventListener('mousewheel', scroll);
|
||||
this.addEventListener('dblclick', dblclick);
|
||||
}
|
||||
|
||||
setScene(scene){
|
||||
|
||||
setScene (scene) {
|
||||
this.scene = scene;
|
||||
}
|
||||
|
||||
zoomToLocation(mouse){
|
||||
|
||||
zoomToLocation (mouse) {
|
||||
let camera = this.scene.camera;
|
||||
|
||||
|
||||
let I = Potree.utils.getMousePointCloudIntersection(
|
||||
mouse,
|
||||
camera,
|
||||
this.renderer,
|
||||
mouse,
|
||||
camera,
|
||||
this.renderer,
|
||||
this.scene.pointclouds);
|
||||
|
||||
if(I === null){
|
||||
|
||||
if (I === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
let nmouse = {
|
||||
x: +( mouse.x / this.renderer.domElement.clientWidth ) * 2 - 1,
|
||||
y: -( mouse.y / this.renderer.domElement.clientHeight ) * 2 + 1
|
||||
|
||||
let nmouse = {
|
||||
x: +(mouse.x / this.renderer.domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / this.renderer.domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
|
||||
let targetRadius = 0;
|
||||
{
|
||||
let minimumJumpDistance = 0.2;
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(camera);
|
||||
|
||||
|
||||
let direction = vector.sub(camera.position).normalize();
|
||||
let ray = new THREE.Ray(camera.position, direction);
|
||||
|
||||
|
||||
let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
|
||||
let lastNode = nodes[nodes.length - 1];
|
||||
let radius = lastNode.getBoundingSphere().radius;
|
||||
targetRadius = Math.min(this.scene.view.radius, radius);
|
||||
targetRadius = Math.max(minimumJumpDistance, targetRadius);
|
||||
}
|
||||
|
||||
|
||||
let d = this.scene.view.direction.multiplyScalar(-1);
|
||||
let cameraTargetPosition = new THREE.Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
|
||||
let controlsTargetPosition = I.location;
|
||||
|
||||
// TODO Unused: let controlsTargetPosition = I.location;
|
||||
|
||||
var animationDuration = 600;
|
||||
var easing = TWEEN.Easing.Quartic.Out;
|
||||
|
||||
{ // animate
|
||||
|
||||
|
||||
{ // animate
|
||||
let value = {x: 0};
|
||||
let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
|
||||
tween.easing(easing);
|
||||
this.tweens.push(tween);
|
||||
|
||||
|
||||
let startPos = this.scene.view.position.clone();
|
||||
let targetPos = cameraTargetPosition.clone();
|
||||
let startRadius = this.scene.view.radius;
|
||||
let targetRadius = cameraTargetPosition.distanceTo(I.location);
|
||||
|
||||
tween.onUpdate( () => {
|
||||
|
||||
tween.onUpdate(() => {
|
||||
let t = value.x;
|
||||
this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
|
||||
this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
|
||||
this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
|
||||
|
||||
|
||||
this.scene.view.radius = (1 - t) * startRadius + t * targetRadius;
|
||||
this.viewer.setMoveSpeed(this.scene.view.radius / 2.5);
|
||||
});
|
||||
|
||||
tween.onComplete( () => {
|
||||
this.tweens = this.tweens.filter( e => e !== tween);
|
||||
|
||||
tween.onComplete(() => {
|
||||
this.tweens = this.tweens.filter(e => e !== tween);
|
||||
});
|
||||
|
||||
|
||||
tween.start();
|
||||
}
|
||||
}
|
||||
|
||||
stopTweens(){
|
||||
this.tweens.forEach( e => e.stop() );
|
||||
|
||||
stopTweens () {
|
||||
this.tweens.forEach(e => e.stop());
|
||||
this.tweens = [];
|
||||
}
|
||||
|
||||
update(delta){
|
||||
|
||||
|
||||
update (delta) {
|
||||
let view = this.scene.view;
|
||||
|
||||
|
||||
{ // apply rotation
|
||||
let progression = Math.min(1, this.fadeFactor * delta);
|
||||
|
||||
|
||||
let yaw = view.yaw;
|
||||
let pitch = view.pitch;
|
||||
let pivot = view.getPivot();
|
||||
|
||||
|
||||
yaw -= progression * this.yawDelta;
|
||||
pitch -= progression * this.pitchDelta;
|
||||
|
||||
|
||||
view.yaw = yaw;
|
||||
view.pitch = pitch;
|
||||
|
||||
|
||||
let V = this.scene.view.direction.multiplyScalar(-view.radius);
|
||||
let position = new THREE.Vector3().addVectors(pivot, V);
|
||||
|
||||
|
||||
view.position.copy(position);
|
||||
}
|
||||
|
||||
|
||||
{ // apply pan
|
||||
let progression = Math.min(1, this.fadeFactor * delta);
|
||||
let panDistance = progression * view.radius * 3;
|
||||
|
||||
|
||||
let px = -this.panDelta.x * panDistance;
|
||||
let py = this.panDelta.y * panDistance;
|
||||
|
||||
|
||||
view.pan(px, py);
|
||||
}
|
||||
|
||||
|
||||
{ // apply zoom
|
||||
let progression = Math.min(1, this.fadeFactor * delta);
|
||||
|
||||
//let radius = view.radius + progression * this.radiusDelta * view.radius * 0.1;
|
||||
|
||||
// let radius = view.radius + progression * this.radiusDelta * view.radius * 0.1;
|
||||
let radius = view.radius + progression * this.radiusDelta;
|
||||
|
||||
|
||||
let V = view.direction.multiplyScalar(-radius);
|
||||
let position = new THREE.Vector3().addVectors(view.getPivot(), V);
|
||||
view.radius = radius;
|
||||
|
||||
|
||||
view.position.copy(position);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
let speed = view.radius / 2.5;
|
||||
this.viewer.setMoveSpeed(speed);
|
||||
}
|
||||
|
||||
{// decelerate over time
|
||||
|
||||
{ // decelerate over time
|
||||
let progression = Math.min(1, this.fadeFactor * delta);
|
||||
let attenuation = Math.max(0, 1 - this.fadeFactor * delta);
|
||||
|
||||
|
||||
this.yawDelta *= attenuation;
|
||||
this.pitchDelta *= attenuation;
|
||||
this.panDelta.multiplyScalar(attenuation);
|
||||
//this.radiusDelta *= attenuation;
|
||||
this.radiusDelta -= progression * this.radiusDelta
|
||||
// this.radiusDelta *= attenuation;
|
||||
this.radiusDelta -= progression * this.radiusDelta;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@ -1,91 +1,90 @@
|
||||
class HoverMenuItem{
|
||||
|
||||
constructor(icon, callback){
|
||||
/* globals HoverMenu:true HoverMenuItem:true */
|
||||
/* exported HoverMenu */
|
||||
/* exported HoverMenuItem */
|
||||
HoverMenuItem = class {
|
||||
constructor (icon, callback) {
|
||||
this.icon = icon;
|
||||
this.callback = callback;
|
||||
|
||||
|
||||
this.element = $(`
|
||||
<span class="hover_menu_item">
|
||||
<img src="${icon}">
|
||||
</span>
|
||||
`);
|
||||
|
||||
this.element.click(function(){
|
||||
|
||||
this.element.click(function () {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
class HoverMenu{
|
||||
|
||||
constructor(icon){
|
||||
HoverMenu = class {
|
||||
constructor (icon) {
|
||||
let scope = this;
|
||||
|
||||
|
||||
this.items = [];
|
||||
|
||||
|
||||
this.x = 0;
|
||||
this.y = 0;
|
||||
this.circumference = 32;
|
||||
|
||||
|
||||
this.element = $('<span class="hover_menu"></span>');
|
||||
this.elIcon = $(`<span class="hover_menu_icon">
|
||||
<img src="${icon}">
|
||||
</span>`);
|
||||
this.element.append(this.elIcon);
|
||||
|
||||
this.element.click(function(){
|
||||
$(this).find(".hover_menu_item").fadeIn(200);
|
||||
$(this).find(".hover_menu_icon").fadeOut(200);
|
||||
|
||||
$(this).css("left", (scope.x - scope.circumference - $(this).width() / 2) + "px");
|
||||
$(this).css("top", (scope.y - scope.circumference - $(this).height() / 2) + "px");
|
||||
$(this).css("border", scope.circumference + "px solid transparent");
|
||||
}).mouseleave(function(){
|
||||
$(this).find(".hover_menu_item").fadeOut(200);
|
||||
$(this).find(".hover_menu_icon").fadeIn(200);
|
||||
|
||||
$(this).css("left", (scope.x - $(this).width() / 2) + "px");
|
||||
$(this).css("top", (scope.y - $(this).height() / 2) + "px");
|
||||
$(this).css("border", "0px solid black");
|
||||
|
||||
this.element.click(function () {
|
||||
$(this).find('.hover_menu_item').fadeIn(200);
|
||||
$(this).find('.hover_menu_icon').fadeOut(200);
|
||||
|
||||
$(this).css('left', (scope.x - scope.circumference - $(this).width() / 2) + 'px');
|
||||
$(this).css('top', (scope.y - scope.circumference - $(this).height() / 2) + 'px');
|
||||
$(this).css('border', scope.circumference + 'px solid transparent');
|
||||
}).mouseleave(function () {
|
||||
$(this).find('.hover_menu_item').fadeOut(200);
|
||||
$(this).find('.hover_menu_icon').fadeIn(200);
|
||||
|
||||
$(this).css('left', (scope.x - $(this).width() / 2) + 'px');
|
||||
$(this).css('top', (scope.y - $(this).height() / 2) + 'px');
|
||||
$(this).css('border', '0px solid black');
|
||||
});
|
||||
}
|
||||
|
||||
addItem(item){
|
||||
|
||||
addItem (item) {
|
||||
this.items.push(item);
|
||||
this.element.append(item.element);
|
||||
item.element.hide();
|
||||
|
||||
|
||||
this.arrange();
|
||||
}
|
||||
|
||||
removeItem(item){
|
||||
|
||||
removeItem (item) {
|
||||
this.items = this.items.filter(e => e !== item);
|
||||
this.element.remove(item.element);
|
||||
|
||||
|
||||
this.arrange();
|
||||
}
|
||||
|
||||
arrange(){
|
||||
let menuItems = this.element.find(".hover_menu_item");
|
||||
menuItems.each(function(index, value){
|
||||
|
||||
arrange () {
|
||||
let menuItems = this.element.find('.hover_menu_item');
|
||||
menuItems.each(function (index, value) {
|
||||
let u = (index / menuItems.length) * Math.PI * 2;
|
||||
let radius = 22;
|
||||
let x = Math.cos(u) * radius;// + offset ;
|
||||
let y = Math.sin(u) * radius;// + offset ;
|
||||
|
||||
$(this).css("left", x).css("top", y);
|
||||
|
||||
|
||||
$(this).css('left', x).css('top', y);
|
||||
});
|
||||
}
|
||||
|
||||
setPosition(x, y){
|
||||
|
||||
setPosition (x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
let rect = this.element.get(0).getBoundingClientRect();
|
||||
|
||||
this.element.css("left", (this.x - rect.width / 2) + "px");
|
||||
this.element.css("top", (this.y - rect.height / 2) + "px");
|
||||
}
|
||||
|
||||
};
|
||||
let rect = this.element.get(0).getBoundingClientRect();
|
||||
|
||||
this.element.css('left', (this.x - rect.width / 2) + 'px');
|
||||
this.element.css('top', (this.y - rect.height / 2) + 'px');
|
||||
}
|
||||
};
|
||||
|
||||
385
src/utils.js
385
src/utils.js
@ -1,49 +1,47 @@
|
||||
|
||||
|
||||
Potree.utils = class{
|
||||
|
||||
static loadShapefileFeatures(file, callback){
|
||||
|
||||
Potree.utils = class {
|
||||
static loadShapefileFeatures (file, callback) {
|
||||
let features = [];
|
||||
|
||||
|
||||
let handleFinish = () => {
|
||||
callback(features);
|
||||
};
|
||||
|
||||
|
||||
shapefile.open(file)
|
||||
.then(source => {source.read()
|
||||
.then(function log(result){
|
||||
if(result.done){
|
||||
handleFinish();
|
||||
return;
|
||||
}
|
||||
|
||||
//console.log(result.value);
|
||||
|
||||
if(result.value && result.value.type === "Feature" && result.value.geometry !== undefined){
|
||||
features.push(result.value);
|
||||
}
|
||||
|
||||
return source.read().then(log);
|
||||
})
|
||||
});
|
||||
.then(source => {
|
||||
source.read()
|
||||
.then(function log (result) {
|
||||
if (result.done) {
|
||||
handleFinish();
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log(result.value);
|
||||
|
||||
if (result.value && result.value.type === 'Feature' && result.value.geometry !== undefined) {
|
||||
features.push(result.value);
|
||||
}
|
||||
|
||||
return source.read().then(log);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static toString(value){
|
||||
if(value instanceof THREE.Vector3){
|
||||
return value.x.toFixed(2) + ", " + value.y.toFixed(2) + ", " + value.z.toFixed(2);
|
||||
}else{
|
||||
return "" + value + "";
|
||||
|
||||
static toString (value) {
|
||||
if (value instanceof THREE.Vector3) {
|
||||
return value.x.toFixed(2) + ', ' + value.y.toFixed(2) + ', ' + value.z.toFixed(2);
|
||||
} else {
|
||||
return '' + value + '';
|
||||
}
|
||||
}
|
||||
|
||||
static normalizeURL(url){
|
||||
|
||||
static normalizeURL (url) {
|
||||
let u = new URL(url);
|
||||
|
||||
return u.protocol + "//" + u.hostname + u.pathname.replace(/\/+/g, "/");
|
||||
|
||||
return u.protocol + '//' + u.hostname + u.pathname.replace(/\/+/g, '/');
|
||||
};
|
||||
|
||||
static pathExists(url){
|
||||
static pathExists (url) {
|
||||
let req = new XMLHttpRequest();
|
||||
req.open('GET', url, false);
|
||||
req.send(null);
|
||||
@ -56,8 +54,7 @@ Potree.utils = class{
|
||||
/**
|
||||
* adapted from mhluska at https://github.com/mrdoob/three.js/issues/1561
|
||||
*/
|
||||
static computeTransformedBoundingBox(box, transform){
|
||||
|
||||
static computeTransformedBoundingBox (box, transform) {
|
||||
let vertices = [
|
||||
new THREE.Vector3(box.min.x, box.min.y, box.min.z).applyMatrix4(transform),
|
||||
new THREE.Vector3(box.min.x, box.min.y, box.min.z).applyMatrix4(transform),
|
||||
@ -69,20 +66,20 @@ Potree.utils = class{
|
||||
new THREE.Vector3(box.max.x, box.min.y, box.max.z).applyMatrix4(transform),
|
||||
new THREE.Vector3(box.max.x, box.max.y, box.max.z).applyMatrix4(transform)
|
||||
];
|
||||
|
||||
|
||||
let boundingBox = new THREE.Box3();
|
||||
boundingBox.setFromPoints( vertices );
|
||||
|
||||
boundingBox.setFromPoints(vertices);
|
||||
|
||||
return boundingBox;
|
||||
};
|
||||
|
||||
/**
|
||||
* add separators to large numbers
|
||||
*
|
||||
*
|
||||
* @param nStr
|
||||
* @returns
|
||||
*/
|
||||
static addCommas(nStr){
|
||||
static addCommas (nStr) {
|
||||
nStr += '';
|
||||
let x = nStr.split('.');
|
||||
let x1 = x[0];
|
||||
@ -93,9 +90,9 @@ Potree.utils = class{
|
||||
}
|
||||
return x1 + x2;
|
||||
};
|
||||
|
||||
static removeCommas(str){
|
||||
return str.replace(/,/g, "");
|
||||
|
||||
static removeCommas (str) {
|
||||
return str.replace(/,/g, '');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,27 +100,27 @@ Potree.utils = class{
|
||||
*
|
||||
* code from http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string
|
||||
*/
|
||||
static createWorker(code){
|
||||
let blob = new Blob([code], {type: 'application/javascript'});
|
||||
let worker = new Worker(URL.createObjectURL(blob));
|
||||
|
||||
return worker;
|
||||
static createWorker (code) {
|
||||
let blob = new Blob([code], {type: 'application/javascript'});
|
||||
let worker = new Worker(URL.createObjectURL(blob));
|
||||
|
||||
return worker;
|
||||
};
|
||||
|
||||
static loadSkybox(path){
|
||||
let camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 100000 );
|
||||
static loadSkybox (path) {
|
||||
let camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 100000);
|
||||
camera.up.set(0, 0, 1);
|
||||
let scene = new THREE.Scene();
|
||||
|
||||
let format = ".jpg";
|
||||
let format = '.jpg';
|
||||
let urls = [
|
||||
path + 'px' + format, path + 'nx' + format,
|
||||
path + 'py' + format, path + 'ny' + format,
|
||||
path + 'pz' + format, path + 'nz' + format
|
||||
];
|
||||
|
||||
//var materialArray = [];
|
||||
//for (var i = 0; i < 6; i++){
|
||||
|
||||
// var materialArray = [];
|
||||
// for (var i = 0; i < 6; i++){
|
||||
// materialArray.push( new THREE.MeshBasicMaterial({
|
||||
// map: THREE.ImageUtils.loadTexture( urls[i] ),
|
||||
// side: THREE.BackSide,
|
||||
@ -131,169 +128,164 @@ Potree.utils = class{
|
||||
// depthWrite: false
|
||||
// })
|
||||
// );
|
||||
//}
|
||||
|
||||
// }
|
||||
|
||||
let materialArray = [];
|
||||
{
|
||||
for (let i = 0; i < 6; i++){
|
||||
|
||||
for (let i = 0; i < 6; i++) {
|
||||
let material = new THREE.MeshBasicMaterial({
|
||||
map: null,
|
||||
side: THREE.BackSide,
|
||||
depthTest: false,
|
||||
depthWrite: false
|
||||
});
|
||||
|
||||
|
||||
materialArray.push(material);
|
||||
|
||||
|
||||
let loader = new THREE.TextureLoader();
|
||||
loader.load( urls[i],
|
||||
function loaded(texture){
|
||||
loader.load(urls[i],
|
||||
function loaded (texture) {
|
||||
material.map = texture;
|
||||
material.needsUpdate = true;
|
||||
},function progress(xhr){
|
||||
//console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
|
||||
},function error(xhr){
|
||||
console.log( 'An error happened', xhr );
|
||||
}, function progress (xhr) {
|
||||
// console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
|
||||
}, function error (xhr) {
|
||||
console.log('An error happened', xhr);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
var skyGeometry = new THREE.CubeGeometry( 5000, 5000, 5000 );
|
||||
var skybox = new THREE.Mesh( skyGeometry, materialArray );
|
||||
|
||||
var skyGeometry = new THREE.CubeGeometry(5000, 5000, 5000);
|
||||
var skybox = new THREE.Mesh(skyGeometry, materialArray);
|
||||
|
||||
scene.add(skybox);
|
||||
|
||||
|
||||
// z up
|
||||
scene.rotation.x = Math.PI / 2;
|
||||
|
||||
return {"camera": camera, "scene": scene};
|
||||
|
||||
return {'camera': camera, 'scene': scene};
|
||||
};
|
||||
|
||||
static createGrid(width, length, spacing, color){
|
||||
static createGrid (width, length, spacing, color) {
|
||||
let material = new THREE.LineBasicMaterial({
|
||||
color: color || 0x888888
|
||||
});
|
||||
|
||||
|
||||
let geometry = new THREE.Geometry();
|
||||
for(let i = 0; i <= length; i++){
|
||||
geometry.vertices.push(new THREE.Vector3(-(spacing*width)/2, i*spacing-(spacing*length)/2, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(+(spacing*width)/2, i*spacing-(spacing*length)/2, 0));
|
||||
for (let i = 0; i <= length; i++) {
|
||||
geometry.vertices.push(new THREE.Vector3(-(spacing * width) / 2, i * spacing - (spacing * length) / 2, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(+(spacing * width) / 2, i * spacing - (spacing * length) / 2, 0));
|
||||
}
|
||||
|
||||
for(let i = 0; i <= width; i++){
|
||||
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, -(spacing*length)/2, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(i*spacing-(spacing*width)/2, +(spacing*length)/2, 0));
|
||||
|
||||
for (let i = 0; i <= width; i++) {
|
||||
geometry.vertices.push(new THREE.Vector3(i * spacing - (spacing * width) / 2, -(spacing * length) / 2, 0));
|
||||
geometry.vertices.push(new THREE.Vector3(i * spacing - (spacing * width) / 2, +(spacing * length) / 2, 0));
|
||||
}
|
||||
|
||||
|
||||
let line = new THREE.LineSegments(geometry, material, THREE.LinePieces);
|
||||
line.receiveShadow = true;
|
||||
return line;
|
||||
};
|
||||
|
||||
|
||||
static createBackgroundTexture(width, height){
|
||||
|
||||
function gauss(x, y){
|
||||
return (1 / (2 * Math.PI)) * Math.exp( - (x*x + y*y) / 2);
|
||||
static createBackgroundTexture (width, height) {
|
||||
function gauss (x, y) {
|
||||
return (1 / (2 * Math.PI)) * Math.exp(-(x * x + y * y) / 2);
|
||||
};
|
||||
|
||||
//map.magFilter = THREE.NearestFilter;
|
||||
// map.magFilter = THREE.NearestFilter;
|
||||
let size = width * height;
|
||||
let data = new Uint8Array( 3 * size );
|
||||
let data = new Uint8Array(3 * size);
|
||||
|
||||
let chroma = [1, 1.5, 1.7];
|
||||
let max = gauss(0, 0);
|
||||
|
||||
for(let x = 0; x < width; x++){
|
||||
for(let y = 0; y < height; y++){
|
||||
for (let x = 0; x < width; x++) {
|
||||
for (let y = 0; y < height; y++) {
|
||||
let u = 2 * (x / width) - 1;
|
||||
let v = 2 * (y / height) - 1;
|
||||
|
||||
let i = x + width*y;
|
||||
let d = gauss(2*u, 2*v) / max;
|
||||
|
||||
let i = x + width * y;
|
||||
let d = gauss(2 * u, 2 * v) / max;
|
||||
let r = (Math.random() + Math.random() + Math.random()) / 3;
|
||||
r = (d * 0.5 + 0.5) * r * 0.03;
|
||||
r = r * 0.4;
|
||||
|
||||
//d = Math.pow(d, 0.6);
|
||||
|
||||
data[3*i+0] = 255 * (d / 15 + 0.05 + r) * chroma[0];
|
||||
data[3*i+1] = 255 * (d / 15 + 0.05 + r) * chroma[1];
|
||||
data[3*i+2] = 255 * (d / 15 + 0.05 + r) * chroma[2];
|
||||
|
||||
// d = Math.pow(d, 0.6);
|
||||
|
||||
data[3 * i + 0] = 255 * (d / 15 + 0.05 + r) * chroma[0];
|
||||
data[3 * i + 1] = 255 * (d / 15 + 0.05 + r) * chroma[1];
|
||||
data[3 * i + 2] = 255 * (d / 15 + 0.05 + r) * chroma[2];
|
||||
}
|
||||
}
|
||||
|
||||
let texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
|
||||
|
||||
let texture = new THREE.DataTexture(data, width, height, THREE.RGBFormat);
|
||||
texture.needsUpdate = true;
|
||||
|
||||
|
||||
return texture;
|
||||
};
|
||||
|
||||
static getMousePointCloudIntersection(mouse, camera, renderer, pointclouds){
|
||||
let nmouse = {
|
||||
x: (mouse.x / renderer.domElement.clientWidth ) * 2 - 1,
|
||||
y: - (mouse.y / renderer.domElement.clientHeight ) * 2 + 1
|
||||
static getMousePointCloudIntersection (mouse, camera, renderer, pointclouds) {
|
||||
let nmouse = {
|
||||
x: (mouse.x / renderer.domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / renderer.domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
//let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
//vector.unproject(camera);
|
||||
|
||||
//let direction = vector.sub(camera.position).normalize();
|
||||
//let ray = new THREE.Ray(camera.position, direction);
|
||||
|
||||
// let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
// vector.unproject(camera);
|
||||
|
||||
// let direction = vector.sub(camera.position).normalize();
|
||||
// let ray = new THREE.Ray(camera.position, direction);
|
||||
|
||||
let raycaster = new THREE.Raycaster();
|
||||
raycaster.setFromCamera(nmouse, camera);
|
||||
let ray = raycaster.ray;
|
||||
|
||||
|
||||
let selectedPointcloud = null;
|
||||
let closestDistance = Infinity;
|
||||
let closestIntersection = null;
|
||||
let closestPoint = null;
|
||||
|
||||
for(let pointcloud of pointclouds){
|
||||
|
||||
for (let pointcloud of pointclouds) {
|
||||
let point = pointcloud.pick(renderer, camera, ray);
|
||||
|
||||
if(!point){
|
||||
|
||||
if (!point) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
let distance = camera.position.distanceTo(point.position);
|
||||
|
||||
if(distance < closestDistance){
|
||||
|
||||
if (distance < closestDistance) {
|
||||
closestDistance = distance;
|
||||
selectedPointcloud = pointcloud;
|
||||
closestIntersection = point.position;
|
||||
closestPoint = point;
|
||||
}
|
||||
}
|
||||
|
||||
if(selectedPointcloud){
|
||||
|
||||
if (selectedPointcloud) {
|
||||
return {
|
||||
location: closestIntersection,
|
||||
distance: closestDistance,
|
||||
pointcloud: selectedPointcloud,
|
||||
point: closestPoint
|
||||
};
|
||||
}else{
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
static pixelsArrayToImage(pixels, width, height){
|
||||
};
|
||||
|
||||
static pixelsArrayToImage (pixels, width, height) {
|
||||
let canvas = document.createElement('canvas');
|
||||
canvas.width = width;
|
||||
canvas.height = height;
|
||||
|
||||
let context = canvas.getContext('2d');
|
||||
|
||||
|
||||
pixels = new pixels.constructor(pixels);
|
||||
|
||||
for(let i = 0; i < pixels.length; i++){
|
||||
pixels[i*4 + 3] = 255;
|
||||
|
||||
for (let i = 0; i < pixels.length; i++) {
|
||||
pixels[i * 4 + 3] = 255;
|
||||
}
|
||||
|
||||
let imageData = context.createImageData(width, height);
|
||||
@ -302,131 +294,124 @@ Potree.utils = class{
|
||||
|
||||
let img = new Image();
|
||||
img.src = canvas.toDataURL();
|
||||
//img.style.transform = "scaleY(-1)";
|
||||
|
||||
// img.style.transform = "scaleY(-1)";
|
||||
|
||||
return img;
|
||||
};
|
||||
|
||||
static projectedRadius(radius, fov, distance, screenHeight){
|
||||
let projFactor = (1 / Math.tan(fov / 2)) / distance;
|
||||
static projectedRadius (radius, fov, distance, screenHeight) {
|
||||
let projFactor = (1 / Math.tan(fov / 2)) / distance;
|
||||
projFactor = projFactor * screenHeight / 2;
|
||||
|
||||
|
||||
return radius * projFactor;
|
||||
};
|
||||
|
||||
|
||||
static topView(camera, node){
|
||||
|
||||
static topView (camera, node) {
|
||||
camera.position.set(0, 1, 0);
|
||||
camera.rotation.set(-Math.PI / 2, 0, 0);
|
||||
camera.zoomTo(node, 1);
|
||||
};
|
||||
|
||||
static frontView(camera, node){
|
||||
static frontView (camera, node) {
|
||||
camera.position.set(0, 0, 1);
|
||||
camera.rotation.set(0, 0, 0);
|
||||
camera.zoomTo(node, 1);
|
||||
};
|
||||
|
||||
|
||||
static leftView(camera, node){
|
||||
static leftView (camera, node) {
|
||||
camera.position.set(-1, 0, 0);
|
||||
camera.rotation.set(0, -Math.PI / 2, 0);
|
||||
camera.zoomTo(node, 1);
|
||||
};
|
||||
|
||||
static rightView(camera, node){
|
||||
static rightView (camera, node) {
|
||||
camera.position.set(1, 0, 0);
|
||||
camera.rotation.set(0, Math.PI / 2, 0);
|
||||
camera.zoomTo(node, 1);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* 0: no intersection
|
||||
* 1: intersection
|
||||
* 2: fully inside
|
||||
*/
|
||||
static frustumSphereIntersection(frustum, sphere){
|
||||
static frustumSphereIntersection (frustum, sphere) {
|
||||
let planes = frustum.planes;
|
||||
let center = sphere.center;
|
||||
let negRadius = - sphere.radius;
|
||||
let negRadius = -sphere.radius;
|
||||
|
||||
let minDistance = Number.MAX_VALUE;
|
||||
|
||||
for ( let i = 0; i < 6; i ++ ) {
|
||||
|
||||
let distance = planes[ i ].distanceToPoint( center );
|
||||
|
||||
if ( distance < negRadius ) {
|
||||
for (let i = 0; i < 6; i++) {
|
||||
let distance = planes[ i ].distanceToPoint(center);
|
||||
|
||||
if (distance < negRadius) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
minDistance = Math.min(minDistance, distance);
|
||||
|
||||
minDistance = Math.min(minDistance, distance);
|
||||
}
|
||||
|
||||
return (minDistance >= sphere.radius) ? 2 : 1;
|
||||
};
|
||||
|
||||
|
||||
// code taken from three.js
|
||||
// ImageUtils - generateDataTexture()
|
||||
static generateDataTexture(width, height, color){
|
||||
static generateDataTexture (width, height, color) {
|
||||
let size = width * height;
|
||||
let data = new Uint8Array(3 * width * height);
|
||||
|
||||
let r = Math.floor( color.r * 255 );
|
||||
let g = Math.floor( color.g * 255 );
|
||||
let b = Math.floor( color.b * 255 );
|
||||
|
||||
for ( let i = 0; i < size; i ++ ) {
|
||||
data[ i * 3 ] = r;
|
||||
|
||||
let r = Math.floor(color.r * 255);
|
||||
let g = Math.floor(color.g * 255);
|
||||
let b = Math.floor(color.b * 255);
|
||||
|
||||
for (let i = 0; i < size; i++) {
|
||||
data[ i * 3 ] = r;
|
||||
data[ i * 3 + 1 ] = g;
|
||||
data[ i * 3 + 2 ] = b;
|
||||
}
|
||||
|
||||
let texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
|
||||
|
||||
let texture = new THREE.DataTexture(data, width, height, THREE.RGBFormat);
|
||||
texture.needsUpdate = true;
|
||||
texture.magFilter = THREE.NearestFilter;
|
||||
|
||||
|
||||
return texture;
|
||||
};
|
||||
|
||||
|
||||
// from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
|
||||
static getParameterByName(name) {
|
||||
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||
let regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
|
||||
return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||
static getParameterByName (name) {
|
||||
name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
|
||||
let regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
||||
let results = regex.exec(document.location.search);
|
||||
return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, ' '));
|
||||
}
|
||||
|
||||
static setParameter(name, value){
|
||||
//value = encodeURIComponent(value);
|
||||
|
||||
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||
let regex = new RegExp("([\\?&])(" + name + "=([^&#]*))");
|
||||
let results = regex.exec(location.search);
|
||||
|
||||
static setParameter (name, value) {
|
||||
// value = encodeURIComponent(value);
|
||||
|
||||
name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
|
||||
let regex = new RegExp('([\\?&])(' + name + '=([^&#]*))');
|
||||
let results = regex.exec(document.location.search);
|
||||
|
||||
let url = window.location.href;
|
||||
if(results === null){
|
||||
if(window.location.search.length === 0){
|
||||
url = url + "?";
|
||||
}else{
|
||||
url = url + "&";
|
||||
if (results === null) {
|
||||
if (window.location.search.length === 0) {
|
||||
url = url + '?';
|
||||
} else {
|
||||
url = url + '&';
|
||||
}
|
||||
|
||||
url = url + name + "=" + value;
|
||||
}else{
|
||||
let newValue = name + "=" + value;
|
||||
url = url + name + '=' + value;
|
||||
} else {
|
||||
let newValue = name + '=' + value;
|
||||
url = url.replace(results[2], newValue);
|
||||
}
|
||||
window.history.replaceState({}, "", url);
|
||||
window.history.replaceState({}, '', url);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Potree.utils.screenPass = new function(){
|
||||
|
||||
Potree.utils.screenPass = new function () {
|
||||
this.screenScene = new THREE.Scene();
|
||||
this.screenQuad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2, 0));
|
||||
this.screenQuad.material.depthTest = true;
|
||||
@ -434,16 +419,14 @@ Potree.utils.screenPass = new function(){
|
||||
this.screenQuad.material.transparent = true;
|
||||
this.screenScene.add(this.screenQuad);
|
||||
this.camera = new THREE.Camera();
|
||||
|
||||
this.render = function(renderer, material, target){
|
||||
|
||||
this.render = function (renderer, material, target) {
|
||||
this.screenQuad.material = material;
|
||||
|
||||
if(typeof target === "undefined"){
|
||||
|
||||
if (typeof target === 'undefined') {
|
||||
renderer.render(this.screenScene, this.camera);
|
||||
}else{
|
||||
} else {
|
||||
renderer.render(this.screenScene, this.camera, target);
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
|
||||
|
||||
@ -8,14 +8,12 @@
|
||||
* @author mschuetz / http://potree.org
|
||||
*/
|
||||
|
||||
Potree.Box3Helper = class Box3Helper extends THREE.LineSegments{
|
||||
|
||||
constructor(box, color){
|
||||
|
||||
if ( color === undefined ) color = 0xffff00;
|
||||
Potree.Box3Helper = class Box3Helper extends THREE.LineSegments {
|
||||
constructor (box, color) {
|
||||
if (color === undefined) color = 0xffff00;
|
||||
|
||||
let indices = new Uint16Array([ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ]);
|
||||
let positions = new Float32Array( [
|
||||
let positions = new Float32Array([
|
||||
box.min.x, box.min.y, box.min.z,
|
||||
box.max.x, box.min.y, box.min.z,
|
||||
box.max.x, box.min.y, box.max.z,
|
||||
@ -27,12 +25,11 @@ Potree.Box3Helper = class Box3Helper extends THREE.LineSegments{
|
||||
]);
|
||||
|
||||
let geometry = new THREE.BufferGeometry();
|
||||
geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
|
||||
geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
|
||||
geometry.setIndex(new THREE.BufferAttribute(indices, 1));
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
|
||||
let material = new THREE.LineBasicMaterial({ color: color });
|
||||
|
||||
let material = new THREE.LineBasicMaterial( { color: color } ) ;
|
||||
|
||||
super(geometry, material);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
|
||||
Potree.Measure = class Measure extends THREE.Object3D{
|
||||
constructor(){
|
||||
Potree.Measure = class Measure extends THREE.Object3D {
|
||||
constructor () {
|
||||
super();
|
||||
|
||||
|
||||
this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
|
||||
|
||||
this.name = "Measure_" + this.constructor.counter;
|
||||
|
||||
this.name = 'Measure_' + this.constructor.counter;
|
||||
this.points = [];
|
||||
this._showDistances = true;
|
||||
this._showCoordinates = false;
|
||||
@ -14,410 +14,402 @@ Potree.Measure = class Measure extends THREE.Object3D{
|
||||
this._showAngles = false;
|
||||
this._showHeight = false;
|
||||
this.maxMarkers = Number.MAX_SAFE_INTEGER;
|
||||
|
||||
this.sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10);
|
||||
this.color = new THREE.Color( 0xff0000 );
|
||||
|
||||
this.lengthUnit = {code: "m"};
|
||||
|
||||
this.sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10);
|
||||
this.color = new THREE.Color(0xff0000);
|
||||
|
||||
this.lengthUnit = {code: 'm'};
|
||||
|
||||
this.spheres = [];
|
||||
this.edges = [];
|
||||
this.sphereLabels = [];
|
||||
this.edgeLabels = [];
|
||||
this.angleLabels = [];
|
||||
this.coordinateLabels = [];
|
||||
|
||||
this.heightEdge;
|
||||
this.heightLabel;
|
||||
|
||||
// this.heightEdge;
|
||||
// this.heightLabel;
|
||||
{ // height stuff
|
||||
|
||||
{ // height line
|
||||
let lineGeometry = new THREE.Geometry();
|
||||
lineGeometry.vertices.push(
|
||||
new THREE.Vector3(),
|
||||
new THREE.Vector3(),
|
||||
new THREE.Vector3(),
|
||||
new THREE.Vector3(),
|
||||
new THREE.Vector3(),
|
||||
new THREE.Vector3(),
|
||||
new THREE.Vector3());
|
||||
lineGeometry.colors.push(this.color, this.color, this.color);
|
||||
let lineMaterial = new THREE.LineDashedMaterial(
|
||||
{ color: 0xff0000, dashSize: 5, gapSize: 2 } );
|
||||
|
||||
let lineMaterial = new THREE.LineDashedMaterial(
|
||||
{ color: 0xff0000, dashSize: 5, gapSize: 2 });
|
||||
|
||||
lineMaterial.depthTest = false;
|
||||
this.heightEdge = new THREE.Line(lineGeometry, lineMaterial);
|
||||
this.heightEdge.visible = false;
|
||||
|
||||
|
||||
this.add(this.heightEdge);
|
||||
}
|
||||
|
||||
|
||||
{ // height label
|
||||
this.heightLabel = new Potree.TextSprite("");
|
||||
this.heightLabel.setBorderColor({r:0, g:0, b:0, a:0.8});
|
||||
this.heightLabel.setBackgroundColor({r:0, g:0, b:0, a:0.3});
|
||||
this.heightLabel.setTextColor({r:180, g:220, b:180, a:1.0});
|
||||
this.heightLabel = new Potree.TextSprite('');
|
||||
this.heightLabel.setBorderColor({r: 0, g: 0, b: 0, a: 0.8});
|
||||
this.heightLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 0.3});
|
||||
this.heightLabel.setTextColor({r: 180, g: 220, b: 180, a: 1.0});
|
||||
this.heightLabel.material.depthTest = false;
|
||||
this.heightLabel.material.opacity = 1;
|
||||
this.heightLabel.visible = false;;
|
||||
this.heightLabel.visible = false; ;
|
||||
this.add(this.heightLabel);
|
||||
}
|
||||
}
|
||||
|
||||
this.areaLabel = new Potree.TextSprite("");
|
||||
this.areaLabel.setBorderColor({r:0, g:0, b:0, a:0.8});
|
||||
this.areaLabel.setBackgroundColor({r:0, g:0, b:0, a:0.3});
|
||||
this.areaLabel.setTextColor({r:180, g:220, b:180, a:1.0});
|
||||
|
||||
this.areaLabel = new Potree.TextSprite('');
|
||||
this.areaLabel.setBorderColor({r: 0, g: 0, b: 0, a: 0.8});
|
||||
this.areaLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 0.3});
|
||||
this.areaLabel.setTextColor({r: 180, g: 220, b: 180, a: 1.0});
|
||||
this.areaLabel.material.depthTest = false;
|
||||
this.areaLabel.material.opacity = 1;
|
||||
this.areaLabel.visible = false;;
|
||||
this.areaLabel.visible = false; ;
|
||||
this.add(this.areaLabel);
|
||||
|
||||
|
||||
}
|
||||
|
||||
createSphereMaterial(){
|
||||
|
||||
createSphereMaterial () {
|
||||
let sphereMaterial = new THREE.MeshLambertMaterial({
|
||||
shading: THREE.SmoothShading,
|
||||
color: this.color,
|
||||
depthTest: false,
|
||||
shading: THREE.SmoothShading,
|
||||
color: this.color,
|
||||
depthTest: false,
|
||||
depthWrite: false}
|
||||
);
|
||||
|
||||
|
||||
return sphereMaterial;
|
||||
};
|
||||
|
||||
addMarker(point){
|
||||
if(point instanceof THREE.Vector3){
|
||||
|
||||
addMarker (point) {
|
||||
if (point instanceof THREE.Vector3) {
|
||||
point = {position: point};
|
||||
}
|
||||
this.points.push(point);
|
||||
|
||||
|
||||
// sphere
|
||||
let sphere = new THREE.Mesh(this.sphereGeometry, this.createSphereMaterial());
|
||||
|
||||
|
||||
this.add(sphere);
|
||||
this.spheres.push(sphere);
|
||||
|
||||
|
||||
{ // edges
|
||||
let lineGeometry = new THREE.Geometry();
|
||||
lineGeometry.vertices.push(new THREE.Vector3(), new THREE.Vector3());
|
||||
lineGeometry.colors.push(this.color, this.color, this.color);
|
||||
let lineMaterial = new THREE.LineBasicMaterial( {
|
||||
let lineMaterial = new THREE.LineBasicMaterial({
|
||||
linewidth: 1
|
||||
});
|
||||
lineMaterial.depthTest = false;
|
||||
let edge = new THREE.Line(lineGeometry, lineMaterial);
|
||||
edge.visible = true;
|
||||
|
||||
|
||||
this.add(edge);
|
||||
this.edges.push(edge);
|
||||
}
|
||||
|
||||
|
||||
|
||||
{ // edge labels
|
||||
let edgeLabel = new Potree.TextSprite();
|
||||
edgeLabel.setBorderColor({r:0, g:0, b:0, a:0.8});
|
||||
edgeLabel.setBackgroundColor({r:0, g:0, b:0, a:0.3});
|
||||
edgeLabel.setBorderColor({r: 0, g: 0, b: 0, a: 0.8});
|
||||
edgeLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 0.3});
|
||||
edgeLabel.material.depthTest = false;
|
||||
edgeLabel.visible = false;
|
||||
this.edgeLabels.push(edgeLabel);
|
||||
this.add(edgeLabel);
|
||||
}
|
||||
|
||||
|
||||
{ // angle labels
|
||||
let angleLabel = new Potree.TextSprite();
|
||||
angleLabel.setBorderColor({r:0, g:0, b:0, a:0.8});
|
||||
angleLabel.setBackgroundColor({r:0, g:0, b:0, a:0.3});
|
||||
angleLabel.material.depthTest = false;
|
||||
angleLabel.material.opacity = 1;
|
||||
angleLabel.setBorderColor({r: 0, g: 0, b: 0, a: 0.8});
|
||||
angleLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 0.3});
|
||||
angleLabel.material.depthTest = false;
|
||||
angleLabel.material.opacity = 1;
|
||||
angleLabel.visible = false;
|
||||
this.angleLabels.push(angleLabel);
|
||||
this.add(angleLabel);
|
||||
}
|
||||
|
||||
|
||||
{ // coordinate labels
|
||||
let coordinateLabel = new Potree.TextSprite();
|
||||
coordinateLabel.setBorderColor({r:0, g:0, b:0, a:0.8});
|
||||
coordinateLabel.setBackgroundColor({r:0, g:0, b:0, a:0.3});
|
||||
coordinateLabel.setBorderColor({r: 0, g: 0, b: 0, a: 0.8});
|
||||
coordinateLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 0.3});
|
||||
coordinateLabel.material.depthTest = false;
|
||||
coordinateLabel.material.opacity = 1;
|
||||
coordinateLabel.visible = false;
|
||||
this.coordinateLabels.push(coordinateLabel);
|
||||
this.add(coordinateLabel);
|
||||
}
|
||||
|
||||
|
||||
{ // Event Listeners
|
||||
let drag = (e) => {
|
||||
let I = Potree.utils.getMousePointCloudIntersection(
|
||||
e.drag.end,
|
||||
e.viewer.scene.camera,
|
||||
e.viewer.renderer,
|
||||
e.drag.end,
|
||||
e.viewer.scene.camera,
|
||||
e.viewer.renderer,
|
||||
e.viewer.scene.pointclouds);
|
||||
|
||||
if(I){
|
||||
|
||||
if (I) {
|
||||
let i = this.spheres.indexOf(e.drag.object);
|
||||
if(i !== -1){
|
||||
|
||||
if (i !== -1) {
|
||||
let point = this.points[i];
|
||||
for(let key of Object.keys(I.point).filter(e => e !== "position")){
|
||||
for (let key of Object.keys(I.point).filter(e => e !== 'position')) {
|
||||
point[key] = I.point[key];
|
||||
}
|
||||
|
||||
|
||||
this.setPosition(i, I.location);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let drop = e => {
|
||||
let i = this.spheres.indexOf(e.drag.object);
|
||||
if(i !== -1){
|
||||
if (i !== -1) {
|
||||
this.dispatchEvent({
|
||||
"type": "marker_dropped",
|
||||
"measurement": this,
|
||||
"index": i
|
||||
'type': 'marker_dropped',
|
||||
'measurement': this,
|
||||
'index': i
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let mouseover = (e) => e.object.material.emissive.setHex(0x888888);
|
||||
let mouseleave = (e) => e.object.material.emissive.setHex(0x000000);
|
||||
|
||||
sphere.addEventListener("drag", drag);
|
||||
sphere.addEventListener("drop", drop);
|
||||
sphere.addEventListener("mouseover", mouseover);
|
||||
sphere.addEventListener("mouseleave", mouseleave);
|
||||
|
||||
sphere.addEventListener('drag', drag);
|
||||
sphere.addEventListener('drop', drop);
|
||||
sphere.addEventListener('mouseover', mouseover);
|
||||
sphere.addEventListener('mouseleave', mouseleave);
|
||||
}
|
||||
|
||||
let event = {
|
||||
type: "marker_added",
|
||||
type: 'marker_added',
|
||||
measurement: this,
|
||||
sphere: sphere
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
|
||||
this.setMarker(this.points.length-1, point);
|
||||
|
||||
this.setMarker(this.points.length - 1, point);
|
||||
};
|
||||
|
||||
removeMarker(index){
|
||||
|
||||
removeMarker (index) {
|
||||
this.points.splice(index, 1);
|
||||
|
||||
|
||||
this.remove(this.spheres[index]);
|
||||
|
||||
|
||||
let edgeIndex = (index === 0) ? 0 : (index - 1);
|
||||
this.remove(this.edges[edgeIndex]);
|
||||
this.edges.splice(edgeIndex, 1);
|
||||
|
||||
|
||||
this.remove(this.edgeLabels[edgeIndex]);
|
||||
this.edgeLabels.splice(edgeIndex, 1);
|
||||
this.coordinateLabels.splice(index, 1);
|
||||
|
||||
|
||||
this.spheres.splice(index, 1);
|
||||
|
||||
|
||||
this.update();
|
||||
|
||||
this.dispatchEvent({type: "marker_removed", measurement: this});
|
||||
|
||||
this.dispatchEvent({type: 'marker_removed', measurement: this});
|
||||
};
|
||||
|
||||
setMarker(index, point){
|
||||
|
||||
setMarker (index, point) {
|
||||
this.points[index] = point;
|
||||
|
||||
|
||||
let event = {
|
||||
type: 'marker_moved',
|
||||
type: 'marker_moved',
|
||||
measure: this,
|
||||
index: index,
|
||||
position: point.position.clone()
|
||||
index: index,
|
||||
position: point.position.clone()
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
setPosition(index, position){
|
||||
let point = this.points[index];
|
||||
|
||||
setPosition (index, position) {
|
||||
let point = this.points[index];
|
||||
point.position.copy(position);
|
||||
|
||||
|
||||
let event = {
|
||||
type: 'marker_moved',
|
||||
type: 'marker_moved',
|
||||
measure: this,
|
||||
index: index,
|
||||
position: position.clone()
|
||||
index: index,
|
||||
position: position.clone()
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
|
||||
|
||||
this.update();
|
||||
};
|
||||
|
||||
getArea(){
|
||||
|
||||
getArea () {
|
||||
let area = 0;
|
||||
let j = this.points.length - 1;
|
||||
|
||||
for(let i = 0; i < this.points.length; i++){
|
||||
|
||||
for (let i = 0; i < this.points.length; i++) {
|
||||
let p1 = this.points[i].position;
|
||||
let p2 = this.points[j].position;
|
||||
area += (p2.x + p1.x) * (p1.y - p2.y);
|
||||
j = i;
|
||||
}
|
||||
|
||||
|
||||
return Math.abs(area / 2);
|
||||
};
|
||||
|
||||
getTotalDistance(){
|
||||
|
||||
if(this.points.length === 0){
|
||||
|
||||
getTotalDistance () {
|
||||
if (this.points.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
let distance = 0;
|
||||
|
||||
for(let i = 1; i < this.points.length; i++){
|
||||
let prev = this.points[i-1].position;
|
||||
|
||||
for (let i = 1; i < this.points.length; i++) {
|
||||
let prev = this.points[i - 1].position;
|
||||
let curr = this.points[i].position;
|
||||
let d = prev.distanceTo(curr);
|
||||
|
||||
|
||||
distance += d;
|
||||
}
|
||||
|
||||
if(this.closed && this.points.length > 1){
|
||||
|
||||
if (this.closed && this.points.length > 1) {
|
||||
let first = this.points[0].position;
|
||||
let last = this.points[this.points.length - 1].position;
|
||||
let d = last.distanceTo(first);
|
||||
|
||||
|
||||
distance += d;
|
||||
}
|
||||
|
||||
|
||||
return distance;
|
||||
}
|
||||
|
||||
getAngleBetweenLines(cornerPoint, point1, point2) {
|
||||
let v1 = new THREE.Vector3().subVectors(point1.position, cornerPoint.position);
|
||||
let v2 = new THREE.Vector3().subVectors(point2.position, cornerPoint.position);
|
||||
return v1.angleTo(v2);
|
||||
};
|
||||
|
||||
getAngle(index){
|
||||
|
||||
if(this.points.length < 3 || index >= this.points.length){
|
||||
|
||||
getAngleBetweenLines (cornerPoint, point1, point2) {
|
||||
let v1 = new THREE.Vector3().subVectors(point1.position, cornerPoint.position);
|
||||
let v2 = new THREE.Vector3().subVectors(point2.position, cornerPoint.position);
|
||||
return v1.angleTo(v2);
|
||||
};
|
||||
|
||||
getAngle (index) {
|
||||
if (this.points.length < 3 || index >= this.points.length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let previous = (index === 0) ? this.points[this.points.length-1] : this.points[index-1];
|
||||
|
||||
let previous = (index === 0) ? this.points[this.points.length - 1] : this.points[index - 1];
|
||||
let point = this.points[index];
|
||||
let next = this.points[(index + 1) % (this.points.length)];
|
||||
|
||||
|
||||
return this.getAngleBetweenLines(point, previous, next);
|
||||
};
|
||||
|
||||
update(){
|
||||
|
||||
if(this.points.length === 0){
|
||||
|
||||
update () {
|
||||
if (this.points.length === 0) {
|
||||
return;
|
||||
}else if(this.points.length === 1){
|
||||
} else if (this.points.length === 1) {
|
||||
let point = this.points[0];
|
||||
let position = point.position;
|
||||
this.spheres[0].position.copy(position);
|
||||
|
||||
{// coordinate labels
|
||||
|
||||
{ // coordinate labels
|
||||
let coordinateLabel = this.coordinateLabels[0];
|
||||
|
||||
let labelPos = position.clone().add(new THREE.Vector3(0,1,0));
|
||||
|
||||
let labelPos = position.clone().add(new THREE.Vector3(0, 1, 0));
|
||||
coordinateLabel.position.copy(labelPos);
|
||||
|
||||
/*let msg = Potree.utils.addCommas(position.x.toFixed(2))
|
||||
+ " / " + Potree.utils.addCommas(position.y.toFixed(2))
|
||||
+ " / " + Potree.utils.addCommas(position.z.toFixed(2));*/
|
||||
let msg = Potree.utils.addCommas(position.z.toFixed(2) + " " + this.lengthUnit.code);
|
||||
|
||||
/* let msg = Potree.utils.addCommas(position.x.toFixed(2))
|
||||
+ " / " + Potree.utils.addCommas(position.y.toFixed(2))
|
||||
+ " / " + Potree.utils.addCommas(position.z.toFixed(2)); */
|
||||
let msg = Potree.utils.addCommas(position.z.toFixed(2) + ' ' + this.lengthUnit.code);
|
||||
coordinateLabel.setText(msg);
|
||||
|
||||
|
||||
coordinateLabel.visible = this.showCoordinates;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let lastIndex = this.points.length - 1;
|
||||
|
||||
|
||||
let centroid = new THREE.Vector3();
|
||||
for(let i = 0; i <= lastIndex; i++){
|
||||
for (let i = 0; i <= lastIndex; i++) {
|
||||
let point = this.points[i];
|
||||
centroid.add(point.position);
|
||||
}
|
||||
centroid.divideScalar(this.points.length);
|
||||
|
||||
for(let i = 0; i <= lastIndex; i++){
|
||||
|
||||
for (let i = 0; i <= lastIndex; i++) {
|
||||
let index = i;
|
||||
let nextIndex = ( i + 1 > lastIndex ) ? 0 : i + 1;
|
||||
let nextIndex = (i + 1 > lastIndex) ? 0 : i + 1;
|
||||
let previousIndex = (i === 0) ? lastIndex : i - 1;
|
||||
|
||||
|
||||
let point = this.points[index];
|
||||
let nextPoint = this.points[nextIndex];
|
||||
let previousPoint = this.points[previousIndex];
|
||||
|
||||
|
||||
let sphere = this.spheres[index];
|
||||
|
||||
|
||||
// spheres
|
||||
sphere.position.copy(point.position);
|
||||
sphere.material.color = this.color;
|
||||
|
||||
{// edges
|
||||
{ // edges
|
||||
let edge = this.edges[index];
|
||||
|
||||
|
||||
edge.material.color = this.color;
|
||||
|
||||
|
||||
edge.position.copy(point.position);
|
||||
|
||||
|
||||
edge.geometry.vertices[0].set(0, 0, 0);
|
||||
edge.geometry.vertices[1].copy(nextPoint.position).sub(point.position);
|
||||
|
||||
|
||||
edge.geometry.verticesNeedUpdate = true;
|
||||
edge.geometry.computeBoundingSphere();
|
||||
edge.visible = index < lastIndex || this.closed;
|
||||
}
|
||||
|
||||
{// edge labels
|
||||
|
||||
{ // edge labels
|
||||
let edgeLabel = this.edgeLabels[i];
|
||||
|
||||
|
||||
let center = new THREE.Vector3().add(point.position);
|
||||
center.add(nextPoint.position);
|
||||
center = center.multiplyScalar(0.5);
|
||||
let distance = point.position.distanceTo(nextPoint.position);
|
||||
|
||||
|
||||
edgeLabel.position.copy(center);
|
||||
edgeLabel.setText(Potree.utils.addCommas(distance.toFixed(2)) + " " + this.lengthUnit.code);
|
||||
edgeLabel.setText(Potree.utils.addCommas(distance.toFixed(2)) + ' ' + this.lengthUnit.code);
|
||||
edgeLabel.visible = this.showDistances && (index < lastIndex || this.closed) && this.points.length >= 2 && distance > 0;
|
||||
}
|
||||
|
||||
{// angle labels
|
||||
|
||||
{ // angle labels
|
||||
let angleLabel = this.angleLabels[i];
|
||||
let angle = this.getAngleBetweenLines(point, previousPoint, nextPoint);
|
||||
|
||||
|
||||
let dir = nextPoint.position.clone().sub(previousPoint.position);
|
||||
dir.multiplyScalar(0.5);
|
||||
dir = previousPoint.position.clone().add(dir).sub(point.position).normalize();
|
||||
|
||||
|
||||
let dist = Math.min(point.position.distanceTo(previousPoint.position), point.position.distanceTo(nextPoint.position));
|
||||
dist = dist / 9;
|
||||
|
||||
|
||||
let labelPos = point.position.clone().add(dir.multiplyScalar(dist));
|
||||
angleLabel.position.copy(labelPos);
|
||||
|
||||
let msg = Potree.utils.addCommas((angle*(180.0/Math.PI)).toFixed(1)) + '\u00B0';
|
||||
|
||||
let msg = Potree.utils.addCommas((angle * (180.0 / Math.PI)).toFixed(1)) + '\u00B0';
|
||||
angleLabel.setText(msg);
|
||||
|
||||
|
||||
angleLabel.visible = this.showAngles && (index < lastIndex || this.closed) && this.points.length >= 3 && angle > 0;
|
||||
}
|
||||
|
||||
{// coordinate labels
|
||||
let coordinateLabel = this.coordinateLabels[0];
|
||||
|
||||
let labelPos = point.position.clone().add(new THREE.Vector3(0,1,0));
|
||||
coordinateLabel.position.copy(labelPos);
|
||||
|
||||
/*let msg = Potree.utils.addCommas(point.position.x.toFixed(2))
|
||||
+ " / " + Potree.utils.addCommas(point.position.y.toFixed(2))
|
||||
+ " / " + Potree.utils.addCommas(point.position.z.toFixed(2));*/
|
||||
|
||||
let msg = Potree.utils.addCommas(point.position.z.toFixed(2) + " " + this.lengthUnit.code);
|
||||
{ // coordinate labels
|
||||
let coordinateLabel = this.coordinateLabels[0];
|
||||
|
||||
let labelPos = point.position.clone().add(new THREE.Vector3(0, 1, 0));
|
||||
coordinateLabel.position.copy(labelPos);
|
||||
|
||||
/* let msg = Potree.utils.addCommas(point.position.x.toFixed(2))
|
||||
+ " / " + Potree.utils.addCommas(point.position.y.toFixed(2))
|
||||
+ " / " + Potree.utils.addCommas(point.position.z.toFixed(2)); */
|
||||
|
||||
let msg = Potree.utils.addCommas(point.position.z.toFixed(2) + ' ' + this.lengthUnit.code);
|
||||
coordinateLabel.setText(msg);
|
||||
|
||||
//coordinateLabel.visible = this.showCoordinates && (index < lastIndex || this.closed);
|
||||
|
||||
// coordinateLabel.visible = this.showCoordinates && (index < lastIndex || this.closed);
|
||||
coordinateLabel.visible = this.showCoordinates;
|
||||
}
|
||||
}
|
||||
@ -426,120 +418,117 @@ Potree.Measure = class Measure extends THREE.Object3D{
|
||||
let heightEdge = this.heightEdge;
|
||||
heightEdge.visible = this.showHeight;
|
||||
this.heightLabel.visible = this.showHeight;
|
||||
|
||||
if(this.showHeight){
|
||||
let sorted = this.points.slice().sort( (a, b) => a.position.z - b.position.z );
|
||||
|
||||
if (this.showHeight) {
|
||||
let sorted = this.points.slice().sort((a, b) => a.position.z - b.position.z);
|
||||
let lowPoint = sorted[0].position.clone();
|
||||
let highPoint = sorted[sorted.length - 1].position.clone();
|
||||
let min = lowPoint.z;
|
||||
let max = highPoint.z;
|
||||
let height = max - min;
|
||||
|
||||
|
||||
let start = new THREE.Vector3(highPoint.x, highPoint.y, min);
|
||||
let end = new THREE.Vector3(highPoint.x, highPoint.y, max);
|
||||
|
||||
|
||||
heightEdge.position.copy(lowPoint);
|
||||
|
||||
|
||||
heightEdge.geometry.vertices[0].set(0, 0, 0);
|
||||
heightEdge.geometry.vertices[1].copy(start).sub(lowPoint);
|
||||
heightEdge.geometry.vertices[2].copy(start).sub(lowPoint);
|
||||
heightEdge.geometry.vertices[3].copy(end).sub(lowPoint);
|
||||
|
||||
|
||||
heightEdge.geometry.verticesNeedUpdate = true;
|
||||
//heightEdge.geometry.computeLineDistances();
|
||||
//heightEdge.geometry.lineDistancesNeedUpdate = true;
|
||||
// heightEdge.geometry.computeLineDistances();
|
||||
// heightEdge.geometry.lineDistancesNeedUpdate = true;
|
||||
heightEdge.geometry.computeBoundingSphere();
|
||||
|
||||
//heightEdge.material.dashSize = height / 40;
|
||||
//heightEdge.material.gapSize = height / 40;
|
||||
|
||||
|
||||
|
||||
// heightEdge.material.dashSize = height / 40;
|
||||
// heightEdge.material.gapSize = height / 40;
|
||||
|
||||
let heightLabelPosition = start.clone().add(end).multiplyScalar(0.5);
|
||||
this.heightLabel.position.copy(heightLabelPosition);
|
||||
let msg = Potree.utils.addCommas(height.toFixed(2)) + " " + this.lengthUnit.code;
|
||||
let msg = Potree.utils.addCommas(height.toFixed(2)) + ' ' + this.lengthUnit.code;
|
||||
this.heightLabel.setText(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
{ // update area label
|
||||
this.areaLabel.position.copy(centroid);
|
||||
this.areaLabel.visible = this.showArea && this.points.length >= 3;
|
||||
let msg = Potree.utils.addCommas(this.getArea().toFixed(1)) + " " + this.lengthUnit.code + "\u00B2";
|
||||
let msg = Potree.utils.addCommas(this.getArea().toFixed(1)) + ' ' + this.lengthUnit.code + '\u00B2';
|
||||
this.areaLabel.setText(msg);
|
||||
}
|
||||
};
|
||||
|
||||
raycast(raycaster, intersects){
|
||||
|
||||
for(let i = 0; i < this.points.length; i++){
|
||||
|
||||
raycast (raycaster, intersects) {
|
||||
for (let i = 0; i < this.points.length; i++) {
|
||||
let sphere = this.spheres[i];
|
||||
|
||||
|
||||
sphere.raycast(raycaster, intersects);
|
||||
}
|
||||
|
||||
|
||||
// recalculate distances because they are not necessarely correct
|
||||
// for scaled objects.
|
||||
// see https://github.com/mrdoob/three.js/issues/5827
|
||||
// TODO: remove this once the bug has been fixed
|
||||
for(let i = 0; i < intersects.length; i++){
|
||||
for (let i = 0; i < intersects.length; i++) {
|
||||
let I = intersects[i];
|
||||
I.distance = raycaster.ray.origin.distanceTo(I.point);
|
||||
}
|
||||
intersects.sort( function ( a, b ) { return a.distance - b.distance;} );
|
||||
intersects.sort(function (a, b) { return a.distance - b.distance; });
|
||||
};
|
||||
|
||||
get showCoordinates(){
|
||||
|
||||
get showCoordinates () {
|
||||
return this._showCoordinates;
|
||||
}
|
||||
|
||||
set showCoordinates(value){
|
||||
|
||||
set showCoordinates (value) {
|
||||
this._showCoordinates = value;
|
||||
this.update();
|
||||
}
|
||||
|
||||
get showAngles(){
|
||||
|
||||
get showAngles () {
|
||||
return this._showAngles;
|
||||
}
|
||||
|
||||
set showAngles(value){
|
||||
|
||||
set showAngles (value) {
|
||||
this._showAngles = value;
|
||||
this.update();
|
||||
}
|
||||
|
||||
get showHeight(){
|
||||
|
||||
get showHeight () {
|
||||
return this._showHeight;
|
||||
}
|
||||
|
||||
set showHeight(value){
|
||||
|
||||
set showHeight (value) {
|
||||
this._showHeight = value;
|
||||
this.update();
|
||||
}
|
||||
|
||||
get showArea(){
|
||||
|
||||
get showArea () {
|
||||
return this._showArea;
|
||||
}
|
||||
|
||||
set showArea(value){
|
||||
|
||||
set showArea (value) {
|
||||
this._showArea = value;
|
||||
this.update();
|
||||
}
|
||||
|
||||
get closed(){
|
||||
|
||||
get closed () {
|
||||
return this._closed;
|
||||
}
|
||||
|
||||
set closed(value){
|
||||
|
||||
set closed (value) {
|
||||
this._closed = value;
|
||||
this.update();
|
||||
}
|
||||
|
||||
get showDistances(){
|
||||
|
||||
get showDistances () {
|
||||
return this._showDistances;
|
||||
}
|
||||
|
||||
set showDistances(value){
|
||||
|
||||
set showDistances (value) {
|
||||
this._showDistances = value;
|
||||
this.update();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,239 +1,218 @@
|
||||
|
||||
|
||||
Potree.MeasuringTool = class MeasuringTool extends THREE.EventDispatcher{
|
||||
|
||||
constructor(viewer){
|
||||
Potree.MeasuringTool = class MeasuringTool extends THREE.EventDispatcher {
|
||||
constructor (viewer) {
|
||||
super();
|
||||
|
||||
|
||||
this.viewer = viewer;
|
||||
this.renderer = viewer.renderer;
|
||||
|
||||
this.addEventListener("start_inserting_measurement", e => {
|
||||
|
||||
this.addEventListener('start_inserting_measurement', e => {
|
||||
this.viewer.dispatchEvent({
|
||||
type: "cancel_insertions"
|
||||
type: 'cancel_insertions'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
this.sceneMeasurement = new THREE.Scene();
|
||||
this.sceneMeasurement.name = "scene_measurement";
|
||||
this.light = new THREE.PointLight( 0xffffff, 1.0 );
|
||||
this.sceneMeasurement.name = 'scene_measurement';
|
||||
this.light = new THREE.PointLight(0xffffff, 1.0);
|
||||
this.sceneMeasurement.add(this.light);
|
||||
|
||||
|
||||
this.viewer.inputHandler.registerInteractiveScene(this.sceneMeasurement);
|
||||
|
||||
this.onRemove = (e) => {this.sceneMeasurement.remove(e.measurement)};
|
||||
this.onAdd = e => {this.sceneMeasurement.add(e.measurement)};
|
||||
|
||||
this.onRemove = (e) => { this.sceneMeasurement.remove(e.measurement); };
|
||||
this.onAdd = e => { this.sceneMeasurement.add(e.measurement); };
|
||||
}
|
||||
|
||||
setScene(scene){
|
||||
if(this.scene === scene){
|
||||
|
||||
setScene (scene) {
|
||||
if (this.scene === scene) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.scene){
|
||||
this.scene.removeEventListener("measurement_added", this.onAdd);
|
||||
this.scene.removeEventListener("measurement_removed", this.onRemove);
|
||||
|
||||
if (this.scene) {
|
||||
this.scene.removeEventListener('measurement_added', this.onAdd);
|
||||
this.scene.removeEventListener('measurement_removed', this.onRemove);
|
||||
}
|
||||
|
||||
|
||||
this.scene = scene;
|
||||
|
||||
this.scene.addEventListener("measurement_added", this.onAdd);
|
||||
this.scene.addEventListener("measurement_removed", this.onRemove);
|
||||
|
||||
|
||||
this.scene.addEventListener('measurement_added', this.onAdd);
|
||||
this.scene.addEventListener('measurement_removed', this.onRemove);
|
||||
}
|
||||
|
||||
startInsertion(args = {}){
|
||||
|
||||
|
||||
startInsertion (args = {}) {
|
||||
let domElement = this.viewer.renderer.domElement;
|
||||
|
||||
|
||||
let measure = new Potree.Measure();
|
||||
|
||||
|
||||
this.dispatchEvent({
|
||||
type: "start_inserting_measurement",
|
||||
type: 'start_inserting_measurement',
|
||||
measure: measure
|
||||
});
|
||||
|
||||
measure.showDistances = (args.showDistances == null) ? true : args.showDistances;
|
||||
measure.showDistances = (args.showDistances == null) ? true : args.showDistances;
|
||||
measure.showArea = args.showArea || false;
|
||||
measure.showAngles = args.showAngles || false;
|
||||
measure.showCoordinates = args.showCoordinates || false;
|
||||
measure.showHeight = args.showHeight || false;
|
||||
measure.closed = args.closed || false;
|
||||
measure.maxMarkers = args.maxMarkers || Infinity;
|
||||
measure.name = args.name || "Measurement";
|
||||
|
||||
measure.name = args.name || 'Measurement';
|
||||
|
||||
this.sceneMeasurement.add(measure);
|
||||
|
||||
|
||||
let cancel = {
|
||||
removeLastMarker: measure.maxMarkers > 3,
|
||||
callback: null
|
||||
};
|
||||
|
||||
|
||||
let insertionCallback = (e) => {
|
||||
if(e.button === THREE.MOUSE.LEFT){
|
||||
|
||||
if (e.button === THREE.MOUSE.LEFT) {
|
||||
measure.addMarker(measure.points[measure.points.length - 1].position.clone());
|
||||
|
||||
if(measure.points.length >= measure.maxMarkers){
|
||||
|
||||
if (measure.points.length >= measure.maxMarkers) {
|
||||
cancel.callback();
|
||||
}
|
||||
|
||||
|
||||
this.viewer.inputHandler.startDragging(
|
||||
measure.spheres[measure.spheres.length - 1]);
|
||||
}else if(e.button === THREE.MOUSE.RIGHT){
|
||||
} else if (e.button === THREE.MOUSE.RIGHT) {
|
||||
cancel.callback();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cancel.callback = e => {
|
||||
if(cancel.removeLastMarker){
|
||||
if (cancel.removeLastMarker) {
|
||||
measure.removeMarker(measure.points.length - 1);
|
||||
}
|
||||
domElement.removeEventListener("mouseup", insertionCallback, true);
|
||||
this.viewer.removeEventListener("cancel_insertions", cancel.callback);
|
||||
domElement.removeEventListener('mouseup', insertionCallback, true);
|
||||
this.viewer.removeEventListener('cancel_insertions', cancel.callback);
|
||||
};
|
||||
|
||||
if(measure.maxMarkers > 1){
|
||||
this.viewer.addEventListener("cancel_insertions", cancel.callback);
|
||||
domElement.addEventListener("mouseup", insertionCallback , true);
|
||||
|
||||
if (measure.maxMarkers > 1) {
|
||||
this.viewer.addEventListener('cancel_insertions', cancel.callback);
|
||||
domElement.addEventListener('mouseup', insertionCallback, true);
|
||||
}
|
||||
|
||||
|
||||
measure.addMarker(new THREE.Vector3(0, 0, 0));
|
||||
this.viewer.inputHandler.startDragging(
|
||||
measure.spheres[measure.spheres.length - 1]);
|
||||
|
||||
|
||||
this.viewer.scene.addMeasurement(measure);
|
||||
}
|
||||
|
||||
update(){
|
||||
|
||||
update () {
|
||||
let camera = this.viewer.scene.camera;
|
||||
let domElement = this.renderer.domElement;
|
||||
let measurements = this.viewer.scene.measurements;
|
||||
|
||||
|
||||
this.light.position.copy(camera.position);
|
||||
|
||||
|
||||
// make size independant of distance
|
||||
for(let measure of measurements){
|
||||
|
||||
for (let measure of measurements) {
|
||||
measure.lengthUnit = this.viewer.lengthUnit;
|
||||
measure.update();
|
||||
|
||||
// spheres
|
||||
for(let sphere of measure.spheres){
|
||||
for (let sphere of measure.spheres) {
|
||||
let distance = camera.position.distanceTo(sphere.getWorldPosition());
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, domElement.clientHeight);
|
||||
let scale = (15 / pr);
|
||||
sphere.scale.set(scale, scale, scale);
|
||||
}
|
||||
|
||||
|
||||
// labels
|
||||
let labels = measure.edgeLabels.concat(measure.angleLabels);
|
||||
for(let label of labels){
|
||||
for (let label of labels) {
|
||||
let distance = camera.position.distanceTo(label.getWorldPosition());
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, domElement.clientHeight);
|
||||
let scale = (70 / pr);
|
||||
label.scale.set(scale, scale, scale);
|
||||
}
|
||||
|
||||
|
||||
// coordinate labels
|
||||
for(let j = 0; j < measure.coordinateLabels.length; j++){
|
||||
let label = measure.coordinateLabels[j]
|
||||
for (let j = 0; j < measure.coordinateLabels.length; j++) {
|
||||
let label = measure.coordinateLabels[j];
|
||||
let sphere = measure.spheres[j];
|
||||
let point = measure.points[j];
|
||||
|
||||
// measure.points[j]
|
||||
|
||||
let distance = camera.position.distanceTo(sphere.getWorldPosition());
|
||||
|
||||
let screenPos = sphere.getWorldPosition().clone().project( camera );
|
||||
screenPos.x = Math.round( ( screenPos.x + 1 ) * domElement.clientWidth / 2 ),
|
||||
screenPos.y = Math.round( ( - screenPos.y + 1 ) * domElement.clientHeight / 2 );
|
||||
|
||||
let screenPos = sphere.getWorldPosition().clone().project(camera);
|
||||
screenPos.x = Math.round((screenPos.x + 1) * domElement.clientWidth / 2);
|
||||
screenPos.y = Math.round((-screenPos.y + 1) * domElement.clientHeight / 2);
|
||||
screenPos.z = 0;
|
||||
screenPos.y -= 30;
|
||||
|
||||
let labelPos = new THREE.Vector3(
|
||||
(screenPos.x / domElement.clientWidth) * 2 - 1,
|
||||
-(screenPos.y / domElement.clientHeight) * 2 + 1,
|
||||
0.5 );
|
||||
|
||||
let labelPos = new THREE.Vector3(
|
||||
(screenPos.x / domElement.clientWidth) * 2 - 1,
|
||||
-(screenPos.y / domElement.clientHeight) * 2 + 1,
|
||||
0.5);
|
||||
labelPos.unproject(camera);
|
||||
|
||||
|
||||
let direction = labelPos.sub(camera.position).normalize();
|
||||
labelPos = new THREE.Vector3().addVectors(
|
||||
camera.position, direction.multiplyScalar(distance));
|
||||
|
||||
|
||||
label.position.copy(labelPos);
|
||||
|
||||
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, domElement.clientHeight);
|
||||
let scale = (70 / pr);
|
||||
label.scale.set(scale, scale, scale);
|
||||
}
|
||||
|
||||
|
||||
// height label
|
||||
if(measure.showHeight){
|
||||
if (measure.showHeight) {
|
||||
let label = measure.heightLabel;
|
||||
|
||||
|
||||
{
|
||||
let distance = label.position.distanceTo(camera.position);
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, domElement.clientHeight);
|
||||
let scale = (70 / pr);
|
||||
label.scale.set(scale, scale, scale);
|
||||
}
|
||||
|
||||
|
||||
{ // height edge
|
||||
let edge = measure.heightEdge;
|
||||
let lowpoint = edge.geometry.vertices[0].clone().add(edge.position);
|
||||
let start = edge.geometry.vertices[2].clone().add(edge.position);
|
||||
let end = edge.geometry.vertices[3].clone().add(edge.position);
|
||||
|
||||
|
||||
let lowScreen = lowpoint.clone().project(camera);
|
||||
let startScreen = start.clone().project(camera);
|
||||
let endScreen = end.clone().project(camera);
|
||||
|
||||
|
||||
let toPixelCoordinates = v => {
|
||||
let r = v.clone().addScalar(1).divideScalar(2);
|
||||
r.x = r.x * domElement.clientWidth;
|
||||
r.y = r.y * domElement.clientHeight;
|
||||
r.z = 0;
|
||||
|
||||
|
||||
return r;
|
||||
};
|
||||
|
||||
|
||||
let lowEL = toPixelCoordinates(lowScreen);
|
||||
let startEL = toPixelCoordinates(startScreen);
|
||||
let endEL = toPixelCoordinates(endScreen);
|
||||
|
||||
let distances = [0,
|
||||
lowEL.distanceTo(startEL),
|
||||
startEL.distanceTo(endEL), 0];
|
||||
|
||||
|
||||
let lToS = lowEL.distanceTo(startEL);
|
||||
let sToE = startEL.distanceTo(endEL);
|
||||
|
||||
|
||||
edge.geometry.lineDistances = [0, lToS, lToS, lToS + sToE];
|
||||
edge.geometry.lineDistancesNeedUpdate = true;
|
||||
|
||||
|
||||
edge.material.dashSize = 10;
|
||||
edge.material.gapSize = 10;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
{ // area label
|
||||
let label = measure.areaLabel;
|
||||
|
||||
|
||||
let distance = label.position.distanceTo(camera.position);
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, domElement.clientHeight);
|
||||
let scale = (70 / pr);
|
||||
label.scale.set(scale, scale, scale);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
|
||||
Potree.Profile = class extends THREE.Object3D{
|
||||
|
||||
constructor(){
|
||||
Potree.Profile = class extends THREE.Object3D {
|
||||
constructor () {
|
||||
super();
|
||||
|
||||
|
||||
this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
|
||||
|
||||
this.name = "Profile_" + this.constructor.counter;
|
||||
|
||||
this.name = 'Profile_' + this.constructor.counter;
|
||||
this.points = [];
|
||||
this.spheres = [];
|
||||
this.edges = [];
|
||||
@ -14,44 +13,44 @@ Potree.Profile = class extends THREE.Object3D{
|
||||
this.width = 1;
|
||||
this.height = 20;
|
||||
this._modifiable = true;
|
||||
|
||||
|
||||
this.sphereGeometry = new THREE.SphereGeometry(0.4, 10, 10);
|
||||
this.color = new THREE.Color( 0xff0000 );
|
||||
this.lineColor = new THREE.Color( 0xff0000 );
|
||||
this.color = new THREE.Color(0xff0000);
|
||||
this.lineColor = new THREE.Color(0xff0000);
|
||||
}
|
||||
|
||||
createSphereMaterial(){
|
||||
|
||||
createSphereMaterial () {
|
||||
let sphereMaterial = new THREE.MeshLambertMaterial({
|
||||
shading: THREE.SmoothShading,
|
||||
color: 0xff0000,
|
||||
depthTest: false,
|
||||
shading: THREE.SmoothShading,
|
||||
color: 0xff0000,
|
||||
depthTest: false,
|
||||
depthWrite: false}
|
||||
);
|
||||
|
||||
|
||||
return sphereMaterial;
|
||||
};
|
||||
|
||||
getSegments(){
|
||||
|
||||
getSegments () {
|
||||
let segments = [];
|
||||
|
||||
for(let i = 0; i < this.points.length - 1; i++){
|
||||
|
||||
for (let i = 0; i < this.points.length - 1; i++) {
|
||||
let start = this.points[i].clone();
|
||||
let end = this.points[i+1].clone();
|
||||
let end = this.points[i + 1].clone();
|
||||
segments.push({start: start, end: end});
|
||||
}
|
||||
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
getSegmentMatrices(){
|
||||
|
||||
getSegmentMatrices () {
|
||||
let segments = this.getSegments();
|
||||
let matrices = [];
|
||||
|
||||
for(let segment of segments){
|
||||
|
||||
for (let segment of segments) {
|
||||
let {start, end} = segment;
|
||||
|
||||
|
||||
let box = new THREE.Object3D();
|
||||
|
||||
|
||||
let length = start.clone().setZ(0).distanceTo(end.clone().setZ(0));
|
||||
box.scale.set(length, 10000, this.width);
|
||||
box.up.set(0, 0, 1);
|
||||
@ -60,222 +59,219 @@ Potree.Profile = class extends THREE.Object3D{
|
||||
let diff = new THREE.Vector3().subVectors(end, start);
|
||||
let target = new THREE.Vector3(diff.y, -diff.x, 0);
|
||||
|
||||
box.position.set(0,0,0);
|
||||
box.position.set(0, 0, 0);
|
||||
box.lookAt(target);
|
||||
box.position.copy(center);
|
||||
|
||||
|
||||
box.updateMatrixWorld();
|
||||
matrices.push(box.matrixWorld);
|
||||
}
|
||||
|
||||
|
||||
return matrices;
|
||||
}
|
||||
|
||||
addMarker(point){
|
||||
|
||||
addMarker (point) {
|
||||
this.points.push(point);
|
||||
|
||||
|
||||
let sphere = new THREE.Mesh(this.sphereGeometry, this.createSphereMaterial());
|
||||
|
||||
|
||||
this.add(sphere);
|
||||
this.spheres.push(sphere);
|
||||
|
||||
|
||||
// edges & boxes
|
||||
if(this.points.length > 1){
|
||||
|
||||
if (this.points.length > 1) {
|
||||
var lineGeometry = new THREE.Geometry();
|
||||
lineGeometry.vertices.push(new THREE.Vector3(), new THREE.Vector3());
|
||||
lineGeometry.colors.push(this.lineColor, this.lineColor, this.lineColor);
|
||||
var lineMaterial = new THREE.LineBasicMaterial( {
|
||||
vertexColors: THREE.VertexColors,
|
||||
linewidth: 2,
|
||||
transparent: true,
|
||||
opacity: 0.4
|
||||
var lineMaterial = new THREE.LineBasicMaterial({
|
||||
vertexColors: THREE.VertexColors,
|
||||
linewidth: 2,
|
||||
transparent: true,
|
||||
opacity: 0.4
|
||||
});
|
||||
lineMaterial.depthTest = false;
|
||||
var edge = new THREE.Line(lineGeometry, lineMaterial);
|
||||
edge.visible = false;
|
||||
|
||||
|
||||
this.add(edge);
|
||||
this.edges.push(edge);
|
||||
|
||||
|
||||
|
||||
var boxGeometry = new THREE.BoxGeometry(1, 1, 1);
|
||||
var boxMaterial = new THREE.MeshBasicMaterial({color: 0xff0000, transparent: true, opacity: 0.2});
|
||||
var box = new THREE.Mesh(boxGeometry, boxMaterial);
|
||||
box.visible = false;
|
||||
|
||||
|
||||
this.add(box);
|
||||
this.boxes.push(box);
|
||||
}
|
||||
|
||||
|
||||
{ // event listeners
|
||||
let drag = (e) => {
|
||||
let I = Potree.utils.getMousePointCloudIntersection(
|
||||
e.drag.end,
|
||||
e.viewer.scene.camera,
|
||||
e.viewer.renderer,
|
||||
e.drag.end,
|
||||
e.viewer.scene.camera,
|
||||
e.viewer.renderer,
|
||||
e.viewer.scene.pointclouds);
|
||||
|
||||
if(I){
|
||||
|
||||
if (I) {
|
||||
let i = this.spheres.indexOf(e.drag.object);
|
||||
if(i !== -1){
|
||||
if (i !== -1) {
|
||||
this.setPosition(i, I.location);
|
||||
this.dispatchEvent({
|
||||
"type": "marker_moved",
|
||||
"profile": this,
|
||||
"index": i
|
||||
'type': 'marker_moved',
|
||||
'profile': this,
|
||||
'index': i
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let drop = e => {
|
||||
let i = this.spheres.indexOf(e.drag.object);
|
||||
if(i !== -1){
|
||||
if (i !== -1) {
|
||||
this.dispatchEvent({
|
||||
"type": "marker_dropped",
|
||||
"profile": this,
|
||||
"index": i
|
||||
'type': 'marker_dropped',
|
||||
'profile': this,
|
||||
'index': i
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let mouseover = (e) => e.object.material.emissive.setHex(0x888888);
|
||||
let mouseleave = (e) => e.object.material.emissive.setHex(0x000000);
|
||||
|
||||
sphere.addEventListener("drag", drag);
|
||||
sphere.addEventListener("drop", drop);
|
||||
sphere.addEventListener("mouseover", mouseover);
|
||||
sphere.addEventListener("mouseleave", mouseleave);
|
||||
|
||||
sphere.addEventListener('drag', drag);
|
||||
sphere.addEventListener('drop', drop);
|
||||
sphere.addEventListener('mouseover', mouseover);
|
||||
sphere.addEventListener('mouseleave', mouseleave);
|
||||
}
|
||||
|
||||
|
||||
let event = {
|
||||
type: "marker_added",
|
||||
type: 'marker_added',
|
||||
profile: this,
|
||||
sphere: sphere
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
|
||||
this.setPosition(this.points.length-1, point);
|
||||
|
||||
this.setPosition(this.points.length - 1, point);
|
||||
}
|
||||
|
||||
removeMarker(index){
|
||||
|
||||
removeMarker (index) {
|
||||
this.points.splice(index, 1);
|
||||
|
||||
|
||||
this.remove(this.spheres[index]);
|
||||
|
||||
|
||||
var edgeIndex = (index === 0) ? 0 : (index - 1);
|
||||
this.remove(this.edges[edgeIndex]);
|
||||
this.edges.splice(edgeIndex, 1);
|
||||
this.remove(this.boxes[edgeIndex]);
|
||||
this.boxes.splice(edgeIndex, 1);
|
||||
|
||||
|
||||
this.spheres.splice(index, 1);
|
||||
|
||||
|
||||
this.update();
|
||||
|
||||
|
||||
this.dispatchEvent({
|
||||
"type": "marker_removed",
|
||||
"profile": this
|
||||
'type': 'marker_removed',
|
||||
'profile': this
|
||||
});
|
||||
}
|
||||
|
||||
setPosition(index, position){
|
||||
let point = this.points[index];
|
||||
|
||||
setPosition (index, position) {
|
||||
let point = this.points[index];
|
||||
point.copy(position);
|
||||
|
||||
|
||||
let event = {
|
||||
type: 'marker_moved',
|
||||
type: 'marker_moved',
|
||||
profile: this,
|
||||
index: index,
|
||||
position: point.clone()
|
||||
index: index,
|
||||
position: point.clone()
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
setWidth(width){
|
||||
|
||||
setWidth (width) {
|
||||
this.width = width;
|
||||
|
||||
|
||||
let event = {
|
||||
type: 'width_changed',
|
||||
type: 'width_changed',
|
||||
profile: this,
|
||||
width: width
|
||||
width: width
|
||||
};
|
||||
this.dispatchEvent(event);
|
||||
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
getWidth(){
|
||||
|
||||
getWidth () {
|
||||
return this.width;
|
||||
}
|
||||
|
||||
update(){
|
||||
|
||||
if(this.points.length === 0){
|
||||
|
||||
update () {
|
||||
if (this.points.length === 0) {
|
||||
return;
|
||||
}else if(this.points.length === 1){
|
||||
} else if (this.points.length === 1) {
|
||||
let point = this.points[0];
|
||||
this.spheres[0].position.copy(point);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let min = this.points[0].clone();
|
||||
let max = this.points[0].clone();
|
||||
let centroid = new THREE.Vector3();
|
||||
let lastIndex = this.points.length - 1;
|
||||
for(var i = 0; i <= lastIndex; i++){
|
||||
for (let i = 0; i <= lastIndex; i++) {
|
||||
let point = this.points[i];
|
||||
let sphere = this.spheres[i];
|
||||
let leftIndex = (i === 0) ? lastIndex : i - 1;
|
||||
let rightIndex = (i === lastIndex) ? 0 : i + 1;
|
||||
// let rightIndex = (i === lastIndex) ? 0 : i + 1;
|
||||
let leftVertex = this.points[leftIndex];
|
||||
let rightVertex = this.points[rightIndex];
|
||||
// let rightVertex = this.points[rightIndex];
|
||||
let leftEdge = this.edges[leftIndex];
|
||||
let rightEdge = this.edges[i];
|
||||
let leftBox = this.boxes[leftIndex];
|
||||
let rightBox = this.boxes[i];
|
||||
|
||||
let leftEdgeLength = point.distanceTo(leftVertex);
|
||||
let rightEdgeLength = point.distanceTo(rightVertex);
|
||||
let leftEdgeCenter = new THREE.Vector3().addVectors(leftVertex, point).multiplyScalar(0.5);
|
||||
let rightEdgeCenter = new THREE.Vector3().addVectors(point, rightVertex).multiplyScalar(0.5);
|
||||
|
||||
// rightBox = this.boxes[i];
|
||||
|
||||
// let leftEdgeLength = point.distanceTo(leftVertex);
|
||||
// let rightEdgeLength = point.distanceTo(rightVertex);
|
||||
// let leftEdgeCenter = new THREE.Vector3().addVectors(leftVertex, point).multiplyScalar(0.5);
|
||||
// let rightEdgeCenter = new THREE.Vector3().addVectors(point, rightVertex).multiplyScalar(0.5);
|
||||
|
||||
sphere.position.copy(point);
|
||||
|
||||
if(this._modifiable){
|
||||
|
||||
if (this._modifiable) {
|
||||
sphere.visible = true;
|
||||
}else{
|
||||
} else {
|
||||
sphere.visible = false;
|
||||
}
|
||||
|
||||
if(leftEdge){
|
||||
|
||||
if (leftEdge) {
|
||||
leftEdge.geometry.vertices[1].copy(point);
|
||||
leftEdge.geometry.verticesNeedUpdate = true;
|
||||
leftEdge.geometry.computeBoundingSphere();
|
||||
}
|
||||
|
||||
if(rightEdge){
|
||||
|
||||
if (rightEdge) {
|
||||
rightEdge.geometry.vertices[0].copy(point);
|
||||
rightEdge.geometry.verticesNeedUpdate = true;
|
||||
rightEdge.geometry.computeBoundingSphere();
|
||||
}
|
||||
|
||||
if(leftBox){
|
||||
|
||||
if (leftBox) {
|
||||
var start = leftVertex;
|
||||
var end = point;
|
||||
var length = start.clone().setZ(0).distanceTo(end.clone().setZ(0));
|
||||
leftBox.scale.set(length, 1000000, this.width);
|
||||
leftBox.up.set(0, 0, 1);
|
||||
|
||||
|
||||
var center = new THREE.Vector3().addVectors(start, end).multiplyScalar(0.5);
|
||||
var diff = new THREE.Vector3().subVectors(end, start);
|
||||
var target = new THREE.Vector3(diff.y, -diff.x, 0);
|
||||
|
||||
leftBox.position.set(0,0,0);
|
||||
|
||||
leftBox.position.set(0, 0, 0);
|
||||
leftBox.lookAt(target);
|
||||
leftBox.position.copy(center);
|
||||
}
|
||||
@ -285,53 +281,38 @@ Potree.Profile = class extends THREE.Object3D{
|
||||
max.max(point);
|
||||
}
|
||||
centroid.multiplyScalar(1 / this.points.length);
|
||||
|
||||
for(var i = 0; i < this.boxes.length; i++){
|
||||
|
||||
for (let i = 0; i < this.boxes.length; i++) {
|
||||
var box = this.boxes[i];
|
||||
|
||||
|
||||
box.position.z = min.z + (max.z - min.z) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
raycast(raycaster, intersects){
|
||||
|
||||
for(let i = 0; i < this.points.length; i++){
|
||||
|
||||
raycast (raycaster, intersects) {
|
||||
for (let i = 0; i < this.points.length; i++) {
|
||||
let sphere = this.spheres[i];
|
||||
|
||||
|
||||
sphere.raycast(raycaster, intersects);
|
||||
}
|
||||
|
||||
|
||||
// recalculate distances because they are not necessarely correct
|
||||
// for scaled objects.
|
||||
// see https://github.com/mrdoob/three.js/issues/5827
|
||||
// TODO: remove this once the bug has been fixed
|
||||
for(let i = 0; i < intersects.length; i++){
|
||||
for (let i = 0; i < intersects.length; i++) {
|
||||
let I = intersects[i];
|
||||
I.distance = raycaster.ray.origin.distanceTo(I.point);
|
||||
}
|
||||
intersects.sort( function ( a, b ) { return a.distance - b.distance;} );
|
||||
intersects.sort(function (a, b) { return a.distance - b.distance; });
|
||||
};
|
||||
|
||||
get modifiable(){
|
||||
|
||||
get modifiable () {
|
||||
return this._modifiable;
|
||||
}
|
||||
|
||||
set modifiable(value){
|
||||
|
||||
set modifiable (value) {
|
||||
this._modifiable = value;
|
||||
this.update();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,110 +1,107 @@
|
||||
|
||||
Potree.ProfileTool = class ProfileTool extends THREE.EventDispatcher{
|
||||
|
||||
constructor(viewer){
|
||||
Potree.ProfileTool = class ProfileTool extends THREE.EventDispatcher {
|
||||
constructor (viewer) {
|
||||
super();
|
||||
|
||||
|
||||
this.viewer = viewer;
|
||||
this.renderer = viewer.renderer;
|
||||
|
||||
this.addEventListener("start_inserting_profile", e => {
|
||||
|
||||
this.addEventListener('start_inserting_profile', e => {
|
||||
this.viewer.dispatchEvent({
|
||||
type: "cancel_insertions"
|
||||
type: 'cancel_insertions'
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
this.sceneProfile = new THREE.Scene();
|
||||
this.sceneProfile.name = "scene_profile";
|
||||
this.light = new THREE.PointLight( 0xffffff, 1.0 );
|
||||
this.sceneProfile.name = 'scene_profile';
|
||||
this.light = new THREE.PointLight(0xffffff, 1.0);
|
||||
this.sceneProfile.add(this.light);
|
||||
|
||||
|
||||
this.viewer.inputHandler.registerInteractiveScene(this.sceneProfile);
|
||||
|
||||
this.onRemove = e => this.sceneProfile.remove(e.profile);
|
||||
this.onAdd = e => this.sceneProfile.add(e.profile);
|
||||
}
|
||||
|
||||
setScene(scene){
|
||||
if(this.scene === scene){
|
||||
|
||||
setScene (scene) {
|
||||
if (this.scene === scene) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.scene){
|
||||
this.scene.removeEventListeners("profile_added", this.onAdd);
|
||||
this.scene.removeEventListeners("profile_removed", this.onRemove);
|
||||
|
||||
if (this.scene) {
|
||||
this.scene.removeEventListeners('profile_added', this.onAdd);
|
||||
this.scene.removeEventListeners('profile_removed', this.onRemove);
|
||||
}
|
||||
|
||||
|
||||
this.scene = scene;
|
||||
|
||||
this.scene.addEventListener("profile_added", this.onAdd);
|
||||
this.scene.addEventListener("profile_removed", this.onRemove);
|
||||
|
||||
this.scene.addEventListener('profile_added', this.onAdd);
|
||||
this.scene.addEventListener('profile_removed', this.onRemove);
|
||||
}
|
||||
|
||||
startInsertion(args = {}){
|
||||
|
||||
startInsertion (args = {}) {
|
||||
let domElement = this.viewer.renderer.domElement;
|
||||
|
||||
|
||||
let profile = new Potree.Profile();
|
||||
profile.name = args.name || "Profile";
|
||||
|
||||
profile.name = args.name || 'Profile';
|
||||
|
||||
this.dispatchEvent({
|
||||
type: "start_inserting_profile",
|
||||
type: 'start_inserting_profile',
|
||||
profile: profile
|
||||
});
|
||||
|
||||
|
||||
this.sceneProfile.add(profile);
|
||||
|
||||
|
||||
let cancel = {
|
||||
callback: null
|
||||
};
|
||||
|
||||
|
||||
let insertionCallback = (e) => {
|
||||
if(e.button === THREE.MOUSE.LEFT){
|
||||
if(profile.points.length <= 1){
|
||||
if (e.button === THREE.MOUSE.LEFT) {
|
||||
if (profile.points.length <= 1) {
|
||||
let camera = this.viewer.scene.camera;
|
||||
let distance = camera.position.distanceTo(profile.points[0]);
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, domElement.clientHeight);
|
||||
let width = (10 / pr);
|
||||
|
||||
|
||||
profile.setWidth(width);
|
||||
}
|
||||
|
||||
|
||||
profile.addMarker(profile.points[profile.points.length - 1].clone());
|
||||
|
||||
|
||||
this.viewer.inputHandler.startDragging(
|
||||
profile.spheres[profile.spheres.length - 1]);
|
||||
}else if(e.button === THREE.MOUSE.RIGHT){
|
||||
} else if (e.button === THREE.MOUSE.RIGHT) {
|
||||
cancel.callback();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
cancel.callback = e => {
|
||||
profile.removeMarker(profile.points.length - 1);
|
||||
domElement.removeEventListener("mouseup", insertionCallback, true);
|
||||
this.viewer.removeEventListener("cancel_insertions", cancel.callback);
|
||||
domElement.removeEventListener('mouseup', insertionCallback, true);
|
||||
this.viewer.removeEventListener('cancel_insertions', cancel.callback);
|
||||
};
|
||||
|
||||
this.viewer.addEventListener("cancel_insertions", cancel.callback);
|
||||
domElement.addEventListener("mouseup", insertionCallback , true);
|
||||
|
||||
|
||||
this.viewer.addEventListener('cancel_insertions', cancel.callback);
|
||||
domElement.addEventListener('mouseup', insertionCallback, true);
|
||||
|
||||
profile.addMarker(new THREE.Vector3(0, 0, 0));
|
||||
this.viewer.inputHandler.startDragging(
|
||||
profile.spheres[profile.spheres.length - 1]);
|
||||
|
||||
|
||||
this.viewer.scene.addProfile(profile);
|
||||
}
|
||||
|
||||
update(){
|
||||
|
||||
update () {
|
||||
let camera = this.viewer.scene.camera;
|
||||
let domElement = this.renderer.domElement;
|
||||
let profiles = this.viewer.scene.profiles;
|
||||
|
||||
|
||||
this.light.position.copy(camera.position);
|
||||
|
||||
|
||||
// make size independant of distance
|
||||
for(let profile of profiles){
|
||||
for(let sphere of profile.spheres){
|
||||
for (let profile of profiles) {
|
||||
for (let sphere of profile.spheres) {
|
||||
let distance = camera.position.distanceTo(sphere.getWorldPosition());
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, domElement.clientHeight);
|
||||
let scale = (15 / pr);
|
||||
@ -112,9 +109,4 @@ Potree.ProfileTool = class ProfileTool extends THREE.EventDispatcher{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,567 +1,545 @@
|
||||
|
||||
Potree.TransformationTool = class TransformationTool{
|
||||
|
||||
constructor(viewer){
|
||||
|
||||
Potree.TransformationTool = class TransformationTool {
|
||||
constructor (viewer) {
|
||||
this.viewer = viewer;
|
||||
|
||||
|
||||
this.sceneTransform = new THREE.Scene();
|
||||
this.translationNode = new THREE.Object3D();
|
||||
this.rotationNode = new THREE.Object3D();
|
||||
this.scaleNode = new THREE.Object3D();
|
||||
|
||||
|
||||
this.TRANSFORMATION_MODES = {
|
||||
DEFAULT: 0,
|
||||
TRANSLATE: 1,
|
||||
ROTATE: 2,
|
||||
SCALE: 3
|
||||
};
|
||||
|
||||
|
||||
this.keys = {
|
||||
TRANSLATE: ['E'.charCodeAt(0)],
|
||||
SCALE: ['R'.charCodeAt(0)],
|
||||
ROTATE: ['T'.charCodeAt(0)]
|
||||
}
|
||||
|
||||
TRANSLATE: ['E'.charCodeAt(0)],
|
||||
SCALE: ['R'.charCodeAt(0)],
|
||||
ROTATE: ['T'.charCodeAt(0)]
|
||||
};
|
||||
|
||||
this.mode = this.TRANSFORMATION_MODES.DEFAULT;
|
||||
|
||||
this.menu = new HoverMenu(Potree.resourcePath + "/icons/menu_icon.svg");
|
||||
|
||||
|
||||
this.menu = new HoverMenu(Potree.resourcePath + '/icons/menu_icon.svg');
|
||||
|
||||
this.selection = [];
|
||||
|
||||
|
||||
this.viewer.inputHandler.registerInteractiveScene(this.sceneTransform);
|
||||
this.viewer.inputHandler.addEventListener("selection_changed", (e) => {
|
||||
this.viewer.inputHandler.addEventListener('selection_changed', (e) => {
|
||||
this.selection = e.selection;
|
||||
});
|
||||
this.viewer.inputHandler.addEventListener("keydown", (e) => {
|
||||
if(this.selection.length > 0){
|
||||
if(this.keys.TRANSLATE.some(key => key === e.keyCode)){
|
||||
this.viewer.inputHandler.addEventListener('keydown', (e) => {
|
||||
if (this.selection.length > 0) {
|
||||
if (this.keys.TRANSLATE.some(key => key === e.keyCode)) {
|
||||
this.setMode(this.TRANSFORMATION_MODES.TRANSLATE);
|
||||
}else if(this.keys.SCALE.some(key => key === e.keyCode)){
|
||||
} else if (this.keys.SCALE.some(key => key === e.keyCode)) {
|
||||
this.setMode(this.TRANSFORMATION_MODES.SCALE);
|
||||
}else if(this.keys.ROTATE.some(key => key === e.keyCode)){
|
||||
} else if (this.keys.ROTATE.some(key => key === e.keyCode)) {
|
||||
this.setMode(this.TRANSFORMATION_MODES.ROTATE);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
{ // Menu
|
||||
this.menu.addItem(new HoverMenuItem(Potree.resourcePath + "/icons/translate.svg", e => {
|
||||
//console.log("translate!");
|
||||
this.menu.addItem(new HoverMenuItem(Potree.resourcePath + '/icons/translate.svg', e => {
|
||||
// console.log("translate!");
|
||||
this.setMode(this.TRANSFORMATION_MODES.TRANSLATE);
|
||||
}));
|
||||
this.menu.addItem(new HoverMenuItem(Potree.resourcePath + "/icons/rotate.svg", e => {
|
||||
//console.log("rotate!");
|
||||
this.menu.addItem(new HoverMenuItem(Potree.resourcePath + '/icons/rotate.svg', e => {
|
||||
// console.log("rotate!");
|
||||
this.setMode(this.TRANSFORMATION_MODES.ROTATE);
|
||||
}));
|
||||
this.menu.addItem(new HoverMenuItem(Potree.resourcePath + "/icons/scale.svg", e => {
|
||||
//console.log("scale!");
|
||||
this.menu.addItem(new HoverMenuItem(Potree.resourcePath + '/icons/scale.svg', e => {
|
||||
// console.log("scale!");
|
||||
this.setMode(this.TRANSFORMATION_MODES.SCALE);
|
||||
}));
|
||||
this.menu.setPosition(100, 100);
|
||||
$(this.viewer.renderArea).append(this.menu.element);
|
||||
this.menu.element.hide();
|
||||
}
|
||||
|
||||
|
||||
{ // translation node
|
||||
|
||||
let createArrow = (name, direction, color) => {
|
||||
let material = new THREE.MeshBasicMaterial({
|
||||
color: color,
|
||||
depthTest: false,
|
||||
color: color,
|
||||
depthTest: false,
|
||||
depthWrite: false});
|
||||
|
||||
|
||||
let shaftGeometry = new THREE.Geometry();
|
||||
shaftGeometry.vertices.push(new THREE.Vector3(0, 0, 0));
|
||||
shaftGeometry.vertices.push(new THREE.Vector3(0, 1, 0));
|
||||
|
||||
|
||||
let shaftMaterial = new THREE.LineBasicMaterial({
|
||||
color: color,
|
||||
depthTest: true,
|
||||
color: color,
|
||||
depthTest: true,
|
||||
depthWrite: true,
|
||||
transparent: true
|
||||
});
|
||||
});
|
||||
let shaft = new THREE.Line(shaftGeometry, shaftMaterial);
|
||||
shaft.name = name + "_shaft";
|
||||
|
||||
shaft.name = name + '_shaft';
|
||||
|
||||
let headGeometry = new THREE.CylinderGeometry(0, 0.04, 0.1, 10, 1, false);
|
||||
let headMaterial = material;
|
||||
let headMaterial = material;
|
||||
let head = new THREE.Mesh(headGeometry, headMaterial);
|
||||
head.name = name + "_head";
|
||||
head.name = name + '_head';
|
||||
head.position.y = 1;
|
||||
|
||||
|
||||
let arrow = new THREE.Object3D();
|
||||
arrow.name = name;
|
||||
arrow.add(shaft);
|
||||
arrow.add(head);
|
||||
|
||||
|
||||
let mouseover = e => {
|
||||
let c = new THREE.Color(0xFFFF00);
|
||||
shaftMaterial.color = c;
|
||||
headMaterial.color = c;
|
||||
};
|
||||
|
||||
|
||||
let mouseleave = e => {
|
||||
let c = new THREE.Color(color);
|
||||
shaftMaterial.color = c;
|
||||
headMaterial.color = c;
|
||||
};
|
||||
|
||||
|
||||
let drag = e => {
|
||||
|
||||
let camera = this.viewer.scene.camera;
|
||||
|
||||
if(!e.drag.intersectionStart){
|
||||
|
||||
if (!e.drag.intersectionStart) {
|
||||
e.drag.intersectionStart = e.drag.location;
|
||||
e.drag.objectStart = e.drag.object.getWorldPosition();
|
||||
|
||||
|
||||
let start = this.sceneTransform.position.clone();
|
||||
let end = direction.clone().applyMatrix4(this.sceneTransform.matrixWorld);
|
||||
//let end = start.clone().add(direction);
|
||||
// let end = start.clone().add(direction);
|
||||
let line = new THREE.Line3(start, end);
|
||||
e.drag.line = line;
|
||||
|
||||
|
||||
let camOnLine = line.closestPointToPoint(camera.position, false);
|
||||
let normal = new THREE.Vector3().subVectors(
|
||||
camera.position, camOnLine);
|
||||
let plane = new THREE.Plane()
|
||||
.setFromNormalAndCoplanarPoint(normal, e.drag.intersectionStart);
|
||||
|
||||
|
||||
e.drag.dragPlane = plane;
|
||||
e.drag.pivot = e.drag.intersectionStart;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
let mouse = e.drag.end;
|
||||
let domElement = viewer.renderer.domElement;
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth ) * 2 - 1,
|
||||
y: - (mouse.y / domElement.clientHeight ) * 2 + 1
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(camera);
|
||||
|
||||
let ray = new THREE.Ray(camera.position, vector.sub( camera.position));
|
||||
|
||||
let ray = new THREE.Ray(camera.position, vector.sub(camera.position));
|
||||
let I = ray.intersectPlane(e.drag.dragPlane);
|
||||
|
||||
if(I){
|
||||
|
||||
|
||||
if (I) {
|
||||
let iOnLine = e.drag.line.closestPointToPoint(I, false);
|
||||
|
||||
|
||||
let diff = new THREE.Vector3().subVectors(
|
||||
iOnLine, e.drag.pivot);
|
||||
|
||||
for(let selection of this.selection){
|
||||
|
||||
for (let selection of this.selection) {
|
||||
selection.position.add(diff);
|
||||
}
|
||||
|
||||
|
||||
e.drag.pivot = e.drag.pivot.add(diff);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
shaft.addEventListener("mouseover", mouseover);
|
||||
shaft.addEventListener("mouseleave", mouseleave);
|
||||
shaft.addEventListener("drag", drag);
|
||||
|
||||
shaft.addEventListener('mouseover', mouseover);
|
||||
shaft.addEventListener('mouseleave', mouseleave);
|
||||
shaft.addEventListener('drag', drag);
|
||||
|
||||
return arrow;
|
||||
};
|
||||
|
||||
let arrowX = createArrow("arrow_x", new THREE.Vector3(1, 0, 0), 0xFF0000);
|
||||
let arrowY = createArrow("arrow_y", new THREE.Vector3(0, 1, 0), 0x00FF00);
|
||||
let arrowZ = createArrow("arrow_z", new THREE.Vector3(0, 0, 1), 0x0000FF);
|
||||
|
||||
arrowX.rotation.z = -Math.PI/2;
|
||||
arrowZ.rotation.x = Math.PI/2;
|
||||
|
||||
|
||||
let arrowX = createArrow('arrow_x', new THREE.Vector3(1, 0, 0), 0xFF0000);
|
||||
let arrowY = createArrow('arrow_y', new THREE.Vector3(0, 1, 0), 0x00FF00);
|
||||
let arrowZ = createArrow('arrow_z', new THREE.Vector3(0, 0, 1), 0x0000FF);
|
||||
|
||||
arrowX.rotation.z = -Math.PI / 2;
|
||||
arrowZ.rotation.x = Math.PI / 2;
|
||||
|
||||
this.translationNode.add(arrowX);
|
||||
this.translationNode.add(arrowY);
|
||||
this.translationNode.add(arrowZ);
|
||||
}
|
||||
|
||||
|
||||
{ // Rotation Node
|
||||
let createCircle = (name, normal, color) => {
|
||||
let material = new THREE.LineBasicMaterial({
|
||||
color: color,
|
||||
depthTest: true,
|
||||
color: color,
|
||||
depthTest: true,
|
||||
depthWrite: true,
|
||||
transparent: true
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
let segments = 32;
|
||||
let radius = 1;
|
||||
let geometry = new THREE.BufferGeometry();
|
||||
let positions = new Float32Array( (segments + 1) * 3 );
|
||||
for(let i = 0; i <= segments; i++){
|
||||
let positions = new Float32Array((segments + 1) * 3);
|
||||
for (let i = 0; i <= segments; i++) {
|
||||
let u = (i / segments) * Math.PI * 2;
|
||||
let x = Math.cos(u) * radius;
|
||||
let y = Math.sin(u) * radius;
|
||||
|
||||
|
||||
positions[3 * i + 0] = x;
|
||||
positions[3 * i + 1] = y;
|
||||
positions[3 * i + 2] = 0;
|
||||
}
|
||||
geometry.addAttribute("position", new THREE.BufferAttribute(positions, 3));
|
||||
geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3));
|
||||
geometry.computeBoundingSphere();
|
||||
|
||||
|
||||
let circle = new THREE.Line(geometry, material);
|
||||
circle.name = name + "_circle";
|
||||
circle.name = name + '_circle';
|
||||
circle.lookAt(normal);
|
||||
|
||||
|
||||
let mouseover = e => {
|
||||
let c = new THREE.Color(0xFFFF00);
|
||||
material.color = c;
|
||||
};
|
||||
|
||||
|
||||
let mouseleave = e => {
|
||||
let c = new THREE.Color(color);
|
||||
material.color = c;
|
||||
};
|
||||
|
||||
|
||||
let drag = e => {
|
||||
|
||||
let camera = this.viewer.scene.camera;
|
||||
let n = normal.clone().applyEuler(this.sceneTransform.rotation);
|
||||
|
||||
if(!e.drag.intersectionStart){
|
||||
|
||||
if (!e.drag.intersectionStart) {
|
||||
e.drag.objectStart = e.drag.object.getWorldPosition();
|
||||
|
||||
|
||||
let plane = new THREE.Plane()
|
||||
.setFromNormalAndCoplanarPoint(n, this.sceneTransform.getWorldPosition());
|
||||
|
||||
|
||||
{ // e.drag.location seems imprecisse, calculate real start location
|
||||
let mouse = e.drag.end;
|
||||
let domElement = viewer.renderer.domElement;
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth ) * 2 - 1,
|
||||
y: - (mouse.y / domElement.clientHeight ) * 2 + 1
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(camera);
|
||||
|
||||
let ray = new THREE.Ray(camera.position, vector.sub( camera.position));
|
||||
|
||||
let ray = new THREE.Ray(camera.position, vector.sub(camera.position));
|
||||
let I = ray.intersectPlane(plane);
|
||||
|
||||
|
||||
e.drag.intersectionStart = I;
|
||||
}
|
||||
|
||||
|
||||
e.drag.dragPlane = plane;
|
||||
e.drag.pivot = e.drag.intersectionStart;
|
||||
}
|
||||
|
||||
|
||||
let mouse = e.drag.end;
|
||||
let domElement = viewer.renderer.domElement;
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth ) * 2 - 1,
|
||||
y: - (mouse.y / domElement.clientHeight ) * 2 + 1
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(camera);
|
||||
|
||||
let ray = new THREE.Ray(camera.position, vector.sub( camera.position));
|
||||
|
||||
let ray = new THREE.Ray(camera.position, vector.sub(camera.position));
|
||||
let I = ray.intersectPlane(e.drag.dragPlane);
|
||||
|
||||
if(I){
|
||||
|
||||
if (I) {
|
||||
let center = this.sceneTransform.position;
|
||||
let from = e.drag.pivot;
|
||||
let to = I;
|
||||
|
||||
|
||||
let v1 = from.clone().sub(center).normalize();
|
||||
let v2 = to.clone().sub(center).normalize();
|
||||
|
||||
|
||||
let angle = Math.acos(v1.dot(v2));
|
||||
let sign = Math.sign(v1.cross(v2).dot(n));
|
||||
angle = angle * sign;
|
||||
if(Number.isNaN(angle)){
|
||||
if (Number.isNaN(angle)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for(let selection of this.selection){
|
||||
|
||||
for (let selection of this.selection) {
|
||||
selection.rotateOnAxis(normal, angle);
|
||||
}
|
||||
|
||||
|
||||
e.drag.pivot = I;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
circle.addEventListener("mouseover", mouseover);
|
||||
circle.addEventListener("mouseleave", mouseleave);
|
||||
circle.addEventListener("drag", drag);
|
||||
|
||||
|
||||
|
||||
circle.addEventListener('mouseover', mouseover);
|
||||
circle.addEventListener('mouseleave', mouseleave);
|
||||
circle.addEventListener('drag', drag);
|
||||
|
||||
return circle;
|
||||
};
|
||||
|
||||
|
||||
{ // transparent ball
|
||||
let sg = new THREE.SphereGeometry(1, 32, 32);
|
||||
let sm = new THREE.MeshBasicMaterial({
|
||||
//let sm = new THREE.MeshNormalMaterial({
|
||||
// let sm = new THREE.MeshNormalMaterial({
|
||||
color: 0xaaaaaa,
|
||||
transparent: true,
|
||||
depthTest: true,
|
||||
depthWrite: true,
|
||||
opacity: 0.4
|
||||
});
|
||||
|
||||
|
||||
let sphere = new THREE.Mesh(sg, sm);
|
||||
sphere.name = name + "_sphere";
|
||||
sphere.name = name + '_sphere';
|
||||
sphere.scale.set(0.9, 0.9, 0.9);
|
||||
this.rotationNode.add(sphere);
|
||||
}
|
||||
|
||||
let yaw = createCircle("yaw", new THREE.Vector3(0, 0, 1), 0xff0000);
|
||||
let pitch = createCircle("pitch", new THREE.Vector3(1, 0, 0), 0x00ff00);
|
||||
let roll = createCircle("roll", new THREE.Vector3(0, 1, 0), 0x0000ff);
|
||||
|
||||
|
||||
let yaw = createCircle('yaw', new THREE.Vector3(0, 0, 1), 0xff0000);
|
||||
let pitch = createCircle('pitch', new THREE.Vector3(1, 0, 0), 0x00ff00);
|
||||
let roll = createCircle('roll', new THREE.Vector3(0, 1, 0), 0x0000ff);
|
||||
|
||||
this.rotationNode.add(yaw);
|
||||
this.rotationNode.add(pitch);
|
||||
this.rotationNode.add(roll);
|
||||
}
|
||||
|
||||
|
||||
{ // scale node
|
||||
|
||||
let createHandle = (name, direction, color) => {
|
||||
let material = new THREE.MeshBasicMaterial({
|
||||
color: color,
|
||||
depthTest: false,
|
||||
color: color,
|
||||
depthTest: false,
|
||||
depthWrite: false});
|
||||
|
||||
|
||||
let shaftGeometry = new THREE.Geometry();
|
||||
shaftGeometry.vertices.push(new THREE.Vector3(0, 0, 0));
|
||||
shaftGeometry.vertices.push(new THREE.Vector3(0, 1, 0));
|
||||
|
||||
|
||||
let shaftMaterial = new THREE.LineBasicMaterial({
|
||||
color: color,
|
||||
depthTest: true,
|
||||
color: color,
|
||||
depthTest: true,
|
||||
depthWrite: true,
|
||||
transparent: true
|
||||
});
|
||||
});
|
||||
let shaft = new THREE.Line(shaftGeometry, shaftMaterial);
|
||||
shaft.name = name + "_shaft";
|
||||
|
||||
shaft.name = name + '_shaft';
|
||||
|
||||
let headGeometry = new THREE.BoxGeometry(1, 1, 1);
|
||||
let headMaterial = material;
|
||||
let headMaterial = material;
|
||||
let head = new THREE.Mesh(headGeometry, headMaterial);
|
||||
head.name = name + "_head";
|
||||
head.name = name + '_head';
|
||||
head.position.y = 1;
|
||||
head.scale.set(0.07, 0.07, 0.07);
|
||||
|
||||
|
||||
let arrow = new THREE.Object3D();
|
||||
arrow.add(shaft);
|
||||
arrow.add(head);
|
||||
|
||||
|
||||
let mouseover = e => {
|
||||
let c = new THREE.Color(0xFFFF00);
|
||||
shaftMaterial.color = c;
|
||||
headMaterial.color = c;
|
||||
};
|
||||
|
||||
|
||||
let mouseleave = e => {
|
||||
let c = new THREE.Color(color);
|
||||
shaftMaterial.color = c;
|
||||
headMaterial.color = c;
|
||||
};
|
||||
|
||||
|
||||
let drag = e => {
|
||||
|
||||
let camera = this.viewer.scene.camera;
|
||||
|
||||
if(!e.drag.intersectionStart){
|
||||
|
||||
if (!e.drag.intersectionStart) {
|
||||
e.drag.intersectionStart = e.drag.location;
|
||||
e.drag.scaleStart = this.selection[0].scale.clone();
|
||||
|
||||
|
||||
let start = this.sceneTransform.position.clone();
|
||||
let end = direction.clone().applyMatrix4(this.sceneTransform.matrixWorld);
|
||||
//let end = start.clone().add(direction);
|
||||
// let end = start.clone().add(direction);
|
||||
let line = new THREE.Line3(start, end);
|
||||
e.drag.line = line;
|
||||
|
||||
|
||||
let camOnLine = line.closestPointToPoint(camera.position, false);
|
||||
let normal = new THREE.Vector3().subVectors(
|
||||
camera.position, camOnLine);
|
||||
let plane = new THREE.Plane()
|
||||
.setFromNormalAndCoplanarPoint(normal, e.drag.intersectionStart);
|
||||
|
||||
|
||||
e.drag.dragPlane = plane;
|
||||
e.drag.pivot = e.drag.intersectionStart;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
let mouse = e.drag.end;
|
||||
let domElement = viewer.renderer.domElement;
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth ) * 2 - 1,
|
||||
y: - (mouse.y / domElement.clientHeight ) * 2 + 1
|
||||
let nmouse = {
|
||||
x: (mouse.x / domElement.clientWidth) * 2 - 1,
|
||||
y: -(mouse.y / domElement.clientHeight) * 2 + 1
|
||||
};
|
||||
|
||||
let vector = new THREE.Vector3( nmouse.x, nmouse.y, 0.5 );
|
||||
|
||||
let vector = new THREE.Vector3(nmouse.x, nmouse.y, 0.5);
|
||||
vector.unproject(camera);
|
||||
|
||||
let ray = new THREE.Ray(camera.position, vector.sub( camera.position));
|
||||
|
||||
let ray = new THREE.Ray(camera.position, vector.sub(camera.position));
|
||||
let I = ray.intersectPlane(e.drag.dragPlane);
|
||||
|
||||
if(I){
|
||||
|
||||
let iOnLine = e.drag.line.closestPointToPoint(I, false);
|
||||
|
||||
//let diff = new THREE.Vector3().subVectors(
|
||||
|
||||
if (I) {
|
||||
// let iOnLine = e.drag.line.closestPointToPoint(I, false);
|
||||
// let diff = new THREE.Vector3().subVectors(
|
||||
// iOnLine, e.drag.pivot);
|
||||
|
||||
|
||||
let oldDistance = this.sceneTransform.position.distanceTo(e.drag.pivot);
|
||||
let newDistance = this.sceneTransform.position.distanceTo(I);
|
||||
|
||||
|
||||
let s = newDistance / oldDistance;
|
||||
let scale = new THREE.Vector3(
|
||||
direction.x === 0 ? 1 : s * direction.x,
|
||||
direction.y === 0 ? 1 : s * direction.y,
|
||||
direction.z === 0 ? 1 : s * direction.z
|
||||
);
|
||||
|
||||
|
||||
for(let selection of this.selection){
|
||||
//selection.position.add(diff);
|
||||
|
||||
|
||||
for (let selection of this.selection) {
|
||||
// selection.position.add(diff);
|
||||
|
||||
selection.scale.copy(e.drag.scaleStart.clone().multiply(scale));
|
||||
|
||||
//selection.scale.copy(
|
||||
|
||||
// selection.scale.copy(
|
||||
// e.drag.scaleStart.clone()
|
||||
// .multiplyScalar(scale)
|
||||
// .multiply(direction));
|
||||
//console.log(Potree.utils.toString(selection.scale));
|
||||
// console.log(Potree.utils.toString(selection.scale));
|
||||
}
|
||||
|
||||
//e.drag.pivot = e.drag.pivot.add(diff);
|
||||
|
||||
// e.drag.pivot = e.drag.pivot.add(diff);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
shaft.addEventListener("mouseover", mouseover);
|
||||
shaft.addEventListener("mouseleave", mouseleave);
|
||||
shaft.addEventListener("drag", drag);
|
||||
|
||||
shaft.addEventListener('mouseover', mouseover);
|
||||
shaft.addEventListener('mouseleave', mouseleave);
|
||||
shaft.addEventListener('drag', drag);
|
||||
|
||||
return arrow;
|
||||
};
|
||||
|
||||
let arrowX = createHandle("arrow_x", new THREE.Vector3(1, 0, 0), 0xFF0000);
|
||||
let arrowY = createHandle("arrow_y", new THREE.Vector3(0, 1, 0), 0x00FF00);
|
||||
let arrowZ = createHandle("arrow_z", new THREE.Vector3(0, 0, 1), 0x0000FF);
|
||||
|
||||
arrowX.rotation.z = -Math.PI/2;
|
||||
arrowZ.rotation.x = Math.PI/2;
|
||||
|
||||
|
||||
let arrowX = createHandle('arrow_x', new THREE.Vector3(1, 0, 0), 0xFF0000);
|
||||
let arrowY = createHandle('arrow_y', new THREE.Vector3(0, 1, 0), 0x00FF00);
|
||||
let arrowZ = createHandle('arrow_z', new THREE.Vector3(0, 0, 1), 0x0000FF);
|
||||
|
||||
arrowX.rotation.z = -Math.PI / 2;
|
||||
arrowZ.rotation.x = Math.PI / 2;
|
||||
|
||||
this.scaleNode.add(arrowX);
|
||||
this.scaleNode.add(arrowY);
|
||||
this.scaleNode.add(arrowZ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
this.setMode(this.TRANSFORMATION_MODES.TRANSLATE);
|
||||
}
|
||||
|
||||
getSelectionBoundingBox(){
|
||||
|
||||
|
||||
getSelectionBoundingBox () {
|
||||
let min = new THREE.Vector3(+Infinity, +Infinity, +Infinity);
|
||||
let max = new THREE.Vector3(-Infinity, -Infinity, -Infinity);
|
||||
|
||||
for(let node of this.selection){
|
||||
|
||||
|
||||
for (let node of this.selection) {
|
||||
let box = null;
|
||||
if(node.boundingBox){
|
||||
if (node.boundingBox) {
|
||||
box = node.boundingBox;
|
||||
}else if(node.geometry && node.geometry.boundingBox){
|
||||
} else if (node.geometry && node.geometry.boundingBox) {
|
||||
box = node.geometry.boundingBox;
|
||||
}
|
||||
|
||||
if(box){
|
||||
//let tbox = Potree.utils.computeTransformedBoundingBox(box, node.matrixWorld);
|
||||
|
||||
if (box) {
|
||||
// let tbox = Potree.utils.computeTransformedBoundingBox(box, node.matrixWorld);
|
||||
let tbox = box.clone().applyMatrix4(node.matrixWorld);
|
||||
|
||||
|
||||
min = min.min(tbox.min);
|
||||
max = max.max(tbox.max);
|
||||
}else{
|
||||
} else {
|
||||
let wp = node.getWorldPosition();
|
||||
min = min.min(wp);
|
||||
max = max.max(wp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new THREE.Box3(min, max);
|
||||
|
||||
}
|
||||
|
||||
setMode(mode){
|
||||
if(this.mode === mode){
|
||||
|
||||
setMode (mode) {
|
||||
if (this.mode === mode) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
this.sceneTransform.remove(this.translationNode);
|
||||
this.sceneTransform.remove(this.rotationNode);
|
||||
this.sceneTransform.remove(this.scaleNode);
|
||||
|
||||
if(mode === this.TRANSFORMATION_MODES.TRANSLATE){
|
||||
|
||||
if (mode === this.TRANSFORMATION_MODES.TRANSLATE) {
|
||||
this.sceneTransform.add(this.translationNode);
|
||||
}else if(mode === this.TRANSFORMATION_MODES.ROTATE){
|
||||
} else if (mode === this.TRANSFORMATION_MODES.ROTATE) {
|
||||
this.sceneTransform.add(this.rotationNode);
|
||||
}else if(mode === this.TRANSFORMATION_MODES.SCALE){
|
||||
} else if (mode === this.TRANSFORMATION_MODES.SCALE) {
|
||||
this.sceneTransform.add(this.scaleNode);
|
||||
}
|
||||
|
||||
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
|
||||
//setSelection(selection){
|
||||
|
||||
// setSelection(selection){
|
||||
// this.selection = selection;
|
||||
//}
|
||||
|
||||
update(){
|
||||
|
||||
if(this.selection.length === 0){
|
||||
// }
|
||||
|
||||
update () {
|
||||
if (this.selection.length === 0) {
|
||||
this.sceneTransform.visible = false;
|
||||
this.menu.element.hide();
|
||||
return;
|
||||
}else{
|
||||
} else {
|
||||
this.sceneTransform.visible = true;
|
||||
this.menu.element.show();
|
||||
}
|
||||
|
||||
if(this.selection.length === 1){
|
||||
|
||||
if (this.selection.length === 1) {
|
||||
this.sceneTransform.rotation.copy(this.selection[0].rotation);
|
||||
}
|
||||
|
||||
|
||||
let scene = this.viewer.scene;
|
||||
let renderer = this.viewer.renderer;
|
||||
let domElement = renderer.domElement;
|
||||
|
||||
|
||||
let box = this.getSelectionBoundingBox();
|
||||
let pivot = box.getCenter();
|
||||
this.sceneTransform.position.copy(pivot);
|
||||
|
||||
|
||||
{ // size
|
||||
let distance = scene.camera.position.distanceTo(pivot);
|
||||
let pr = Potree.utils.projectedRadius(1, scene.camera.fov * Math.PI / 180, distance, renderer.domElement.clientHeight);
|
||||
let scale = (120 / pr);
|
||||
this.sceneTransform.scale.set(scale, scale, scale);
|
||||
}
|
||||
|
||||
|
||||
{ // menu
|
||||
let screenPos = pivot.clone().project(scene.camera);
|
||||
screenPos.x = domElement.clientWidth * (screenPos.x + 1) / 2;
|
||||
screenPos.y = domElement.clientHeight * (1-(screenPos.y + 1) / 2);
|
||||
|
||||
screenPos.y = domElement.clientHeight * (1 - (screenPos.y + 1) / 2);
|
||||
|
||||
this.menu.setPosition(screenPos.x, screenPos.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//render(camera, target){
|
||||
|
||||
// render(camera, target){
|
||||
// this.update();
|
||||
// this.renderer.render(this.sceneTransform, camera, target);
|
||||
//}
|
||||
|
||||
};
|
||||
// }
|
||||
};
|
||||
|
||||
@ -1,242 +1,216 @@
|
||||
|
||||
Potree.TranslationTool = function(camera) {
|
||||
THREE.Object3D.call( this );
|
||||
Potree.TranslationTool = function (camera) {
|
||||
THREE.Object3D.call(this);
|
||||
var scope = this;
|
||||
|
||||
this.camera = camera;
|
||||
|
||||
this.geometry = new THREE.Geometry();
|
||||
this.material = new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
|
||||
|
||||
this.material = new THREE.MeshBasicMaterial({ color: Math.random() * 0xffffff });
|
||||
|
||||
this.STATE = {
|
||||
DEFAULT: 0,
|
||||
TRANSLATE_X: 1,
|
||||
TRANSLATE_Y: 2,
|
||||
TRANSLATE_Z: 3
|
||||
};
|
||||
|
||||
|
||||
this.parts = {
|
||||
ARROW_X : {name: "arrow_x", object: undefined, color: new THREE.Color( 0xff0000 ), state: this.STATE.TRANSLATE_X},
|
||||
ARROW_Y : {name: "arrow_y", object: undefined, color: new THREE.Color( 0x00ff00 ), state: this.STATE.TRANSLATE_Y},
|
||||
ARROW_Z : {name: "arrow_z", object: undefined, color: new THREE.Color( 0x0000ff ), state: this.STATE.TRANSLATE_Z}
|
||||
ARROW_X: {name: 'arrow_x', object: undefined, color: new THREE.Color(0xff0000), state: this.STATE.TRANSLATE_X},
|
||||
ARROW_Y: {name: 'arrow_y', object: undefined, color: new THREE.Color(0x00ff00), state: this.STATE.TRANSLATE_Y},
|
||||
ARROW_Z: {name: 'arrow_z', object: undefined, color: new THREE.Color(0x0000ff), state: this.STATE.TRANSLATE_Z}
|
||||
};
|
||||
|
||||
|
||||
this.state = this.STATE.DEFAULT;
|
||||
this.highlighted = null;
|
||||
this.targets = null;
|
||||
|
||||
this.build = function(){
|
||||
|
||||
this.build = function () {
|
||||
var arrowX = scope.createArrow(scope.parts.ARROW_X, scope.parts.ARROW_X.color);
|
||||
arrowX.rotation.z = -Math.PI/2;
|
||||
|
||||
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;
|
||||
|
||||
arrowZ.rotation.x = -Math.PI / 2;
|
||||
|
||||
scope.add(arrowX);
|
||||
scope.add(arrowY);
|
||||
scope.add(arrowZ);
|
||||
|
||||
|
||||
var boxXY = scope.createBox(new THREE.Color( 0xffff00 ));
|
||||
|
||||
var boxXY = scope.createBox(new THREE.Color(0xffff00));
|
||||
boxXY.scale.z = 0.02;
|
||||
boxXY.position.set(0.5, 0.5, 0);
|
||||
|
||||
var boxXZ = scope.createBox(new THREE.Color( 0xff00ff ));
|
||||
|
||||
var boxXZ = scope.createBox(new THREE.Color(0xff00ff));
|
||||
boxXZ.scale.y = 0.02;
|
||||
boxXZ.position.set(0.5, 0, -0.5);
|
||||
|
||||
var boxYZ = scope.createBox(new THREE.Color( 0x00ffff ));
|
||||
|
||||
var boxYZ = scope.createBox(new THREE.Color(0x00ffff));
|
||||
boxYZ.scale.x = 0.02;
|
||||
boxYZ.position.set(0, 0.5, -0.5);
|
||||
|
||||
|
||||
scope.add(boxXY);
|
||||
scope.add(boxXZ);
|
||||
scope.add(boxYZ);
|
||||
|
||||
|
||||
|
||||
scope.parts.ARROW_X.object = arrowX;
|
||||
scope.parts.ARROW_Y.object = arrowY;
|
||||
scope.parts.ARROW_Z.object = arrowZ;
|
||||
|
||||
|
||||
|
||||
scope.scale.multiplyScalar(5);
|
||||
};
|
||||
|
||||
this.createBox = function(color){
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
this.createArrow = function(partID, color){
|
||||
|
||||
this.createArrow = function (partID, color) {
|
||||
var material = new THREE.MeshBasicMaterial({color: color});
|
||||
|
||||
|
||||
var shaftGeometry = new THREE.CylinderGeometry(0.1, 0.1, 3, 10, 1, false);
|
||||
var shaftMatterial = material;
|
||||
var shaftMatterial = material;
|
||||
var shaft = new THREE.Mesh(shaftGeometry, shaftMatterial);
|
||||
shaft.position.y = 1.5;
|
||||
|
||||
|
||||
var headGeometry = new THREE.CylinderGeometry(0, 0.3, 1, 10, 1, false);
|
||||
var headMaterial = material;
|
||||
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;
|
||||
|
||||
|
||||
return arrow;
|
||||
};
|
||||
|
||||
this.setHighlighted = function(partID){
|
||||
if(partID === undefined){
|
||||
if(scope.highlighted){
|
||||
|
||||
this.setHighlighted = function (partID) {
|
||||
if (partID === undefined) {
|
||||
if (scope.highlighted) {
|
||||
scope.highlighted.object.material.color = scope.highlighted.color;
|
||||
scope.highlighted = undefined;
|
||||
}
|
||||
|
||||
return;
|
||||
}else if(scope.highlighted !== undefined && scope.highlighted !== partID){
|
||||
|
||||
return;
|
||||
} else if (scope.highlighted !== undefined && scope.highlighted !== partID) {
|
||||
scope.highlighted.object.material.color = scope.highlighted.color;
|
||||
}
|
||||
|
||||
scope.highlighted = partID;
|
||||
partID.object.material.color = new THREE.Color(0xffff00);
|
||||
};
|
||||
|
||||
this.getHoveredObject = function(mouse){
|
||||
var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
|
||||
|
||||
this.getHoveredObject = function (mouse) {
|
||||
var vector = new THREE.Vector3(mouse.x, 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() );
|
||||
|
||||
raycaster.ray.set(scope.camera.position, vector.sub(scope.camera.position).normalize());
|
||||
|
||||
var intersections = raycaster.intersectObject(scope, true);
|
||||
if(intersections.length === 0){
|
||||
if (intersections.length === 0) {
|
||||
scope.setHighlighted(undefined);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
var I = intersections[0];
|
||||
var partID = I.object.parent.partID;
|
||||
|
||||
return partID;
|
||||
};
|
||||
|
||||
this.onMouseMove = function(event){
|
||||
|
||||
return partID;
|
||||
};
|
||||
|
||||
this.onMouseMove = function (event) {
|
||||
var mouse = event.normalizedPosition;
|
||||
|
||||
if(scope.state === scope.STATE.DEFAULT){
|
||||
|
||||
if (scope.state === scope.STATE.DEFAULT) {
|
||||
scope.setHighlighted(scope.getHoveredObject(mouse));
|
||||
}else if(scope.state === scope.STATE.TRANSLATE_X || scope.state === scope.STATE.TRANSLATE_Y || scope.state === scope.STATE.TRANSLATE_Z){
|
||||
} else if (scope.state === scope.STATE.TRANSLATE_X || scope.state === scope.STATE.TRANSLATE_Y || scope.state === scope.STATE.TRANSLATE_Z) {
|
||||
var origin = scope.start.lineStart.clone();
|
||||
var direction = scope.start.lineEnd.clone().sub(scope.start.lineStart);
|
||||
direction.normalize();
|
||||
|
||||
|
||||
var mousePoint = new THREE.Vector3(mouse.x, mouse.y);
|
||||
|
||||
|
||||
var directionDistance = new THREE.Vector3().subVectors(mousePoint, origin).dot(direction);
|
||||
var pointOnLine = direction.clone().multiplyScalar(directionDistance).add(origin);
|
||||
|
||||
|
||||
pointOnLine.unproject(scope.camera);
|
||||
|
||||
|
||||
var diff = pointOnLine.clone().sub(scope.position);
|
||||
scope.position.copy(pointOnLine);
|
||||
|
||||
for(var i = 0; i < scope.targets.length; i++){
|
||||
|
||||
for (var i = 0; i < scope.targets.length; i++) {
|
||||
var target = scope.targets[0];
|
||||
target.position.add(diff);
|
||||
}
|
||||
|
||||
|
||||
event.signal.halt();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.onMouseDown = function(event){
|
||||
|
||||
if(scope.state === scope.STATE.DEFAULT){
|
||||
|
||||
this.onMouseDown = function (event) {
|
||||
if (scope.state === scope.STATE.DEFAULT) {
|
||||
var hoveredObject = scope.getHoveredObject(event.normalizedPosition, scope.camera);
|
||||
if(hoveredObject){
|
||||
if (hoveredObject) {
|
||||
scope.state = hoveredObject.state;
|
||||
|
||||
|
||||
var lineStart = scope.position.clone();
|
||||
var lineEnd;
|
||||
|
||||
if(scope.state === scope.STATE.TRANSLATE_X){
|
||||
|
||||
if (scope.state === scope.STATE.TRANSLATE_X) {
|
||||
lineEnd = scope.position.clone();
|
||||
lineEnd.x += 2;
|
||||
}else if(scope.state === scope.STATE.TRANSLATE_Y){
|
||||
} else if (scope.state === scope.STATE.TRANSLATE_Y) {
|
||||
lineEnd = scope.position.clone();
|
||||
lineEnd.y += 2;
|
||||
}else if(scope.state === scope.STATE.TRANSLATE_Z){
|
||||
} else if (scope.state === scope.STATE.TRANSLATE_Z) {
|
||||
lineEnd = scope.position.clone();
|
||||
lineEnd.z -= 2;
|
||||
}
|
||||
|
||||
|
||||
lineStart.project(scope.camera);
|
||||
lineEnd.project(scope.camera);
|
||||
|
||||
|
||||
scope.start = {
|
||||
mouse: event.normalizedPosition,
|
||||
lineStart: lineStart,
|
||||
lineEnd: lineEnd
|
||||
};
|
||||
|
||||
|
||||
event.signal.halt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.onMouseUp = function(event){
|
||||
|
||||
this.onMouseUp = function (event) {
|
||||
scope.setHighlighted();
|
||||
scope.state = scope.STATE.DEFAULT;
|
||||
|
||||
};
|
||||
|
||||
this.setTargets = function(targets){
|
||||
|
||||
this.setTargets = function (targets) {
|
||||
scope.targets = targets;
|
||||
|
||||
if(scope.targets.length === 0){
|
||||
|
||||
if (scope.targets.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO calculate centroid of all targets
|
||||
|
||||
// TODO calculate centroid of all targets
|
||||
var centroid = targets[0].position.clone();
|
||||
//for(var i = 0; i < targets.length; i++){
|
||||
// for(var i = 0; i < targets.length; i++){
|
||||
// var target = targets[i];
|
||||
//}
|
||||
|
||||
// }
|
||||
|
||||
scope.position.copy(centroid);
|
||||
|
||||
};
|
||||
|
||||
this.build();
|
||||
};
|
||||
|
||||
Potree.TranslationTool.prototype = Object.create( THREE.Object3D.prototype );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Potree.TranslationTool.prototype = Object.create(THREE.Object3D.prototype);
|
||||
|
||||
@ -1,49 +1,48 @@
|
||||
|
||||
Potree.Volume = class extends THREE.Object3D{
|
||||
|
||||
constructor(args = {}){
|
||||
Potree.Volume = class extends THREE.Object3D {
|
||||
constructor (args = {}) {
|
||||
super();
|
||||
|
||||
|
||||
this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
|
||||
|
||||
this.name = "volume_" + this.constructor.counter;
|
||||
|
||||
|
||||
this.name = 'volume_' + this.constructor.counter;
|
||||
|
||||
this._clip = args.clip || false;
|
||||
this._modifiable = args.modifiable || true;
|
||||
|
||||
|
||||
let boxGeometry = new THREE.BoxGeometry(1, 1, 1);
|
||||
boxGeometry.computeBoundingBox();
|
||||
|
||||
|
||||
let boxFrameGeometry = new THREE.Geometry();
|
||||
{
|
||||
let l = 0.1;
|
||||
|
||||
// let l = 0.1;
|
||||
|
||||
// corner vertices
|
||||
let v = [
|
||||
[-0.5, -0.5, -0.5],
|
||||
[-0.5, -0.5, +0.5],
|
||||
[-0.5, +0.5, -0.5],
|
||||
[-0.5, +0.5, +0.5],
|
||||
[+0.5, -0.5, -0.5],
|
||||
[+0.5, -0.5, +0.5],
|
||||
[+0.5, +0.5, -0.5],
|
||||
[+0.5, +0.5, +0.5]
|
||||
];
|
||||
// let v = [
|
||||
// [-0.5, -0.5, -0.5],
|
||||
// [-0.5, -0.5, +0.5],
|
||||
// [-0.5, +0.5, -0.5],
|
||||
// [-0.5, +0.5, +0.5],
|
||||
// [+0.5, -0.5, -0.5],
|
||||
// [+0.5, -0.5, +0.5],
|
||||
// [+0.5, +0.5, -0.5],
|
||||
// [+0.5, +0.5, +0.5]
|
||||
// ];
|
||||
//
|
||||
/// / create a cross at each corner with cross length l
|
||||
// for(let b of v){
|
||||
//
|
||||
//// create a cross at each corner with cross length l
|
||||
//for(let b of v){
|
||||
//
|
||||
// let b1 = [ b[0] - l * Math.sign(b[0]), b[1], b[2] ];
|
||||
// let b2 = [ b[0], b[1] - l * Math.sign(b[1]), b[2] ];
|
||||
// let b3 = [ b[0], b[1], b[2] - l * Math.sign(b[2]) ];
|
||||
//
|
||||
//
|
||||
// // create the 3 lines that a cross consists of
|
||||
// for(let d of [b, b1, b, b2, b, b3]){
|
||||
// boxFrameGeometry.vertices.push(new THREE.Vector3().fromArray(d));
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
//
|
||||
// }
|
||||
|
||||
// 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));
|
||||
@ -73,75 +72,74 @@ Potree.Volume = class extends THREE.Object3D{
|
||||
boxFrameGeometry.vertices.push(new THREE.Vector3(-0.5, 0.5, -0.5));
|
||||
}
|
||||
|
||||
this.dimension = new THREE.Vector3(1,1,1);
|
||||
this.material = new THREE.MeshBasicMaterial( {
|
||||
color: 0x00ff00,
|
||||
transparent: true,
|
||||
this.dimension = new THREE.Vector3(1, 1, 1);
|
||||
this.material = new THREE.MeshBasicMaterial({
|
||||
color: 0x00ff00,
|
||||
transparent: true,
|
||||
opacity: 0.3,
|
||||
depthTest: true,
|
||||
depthWrite: false} );
|
||||
depthTest: true,
|
||||
depthWrite: false});
|
||||
this.box = new THREE.Mesh(boxGeometry, this.material);
|
||||
this.box.geometry.computeBoundingBox();
|
||||
this.boundingBox = this.box.geometry.boundingBox;
|
||||
this.add(this.box);
|
||||
|
||||
this.frame = new THREE.LineSegments( boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000}));
|
||||
//this.frame.mode = THREE.Lines;
|
||||
|
||||
this.frame = new THREE.LineSegments(boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000}));
|
||||
// this.frame.mode = THREE.Lines;
|
||||
this.add(this.frame);
|
||||
|
||||
this.label = new Potree.TextSprite("0");
|
||||
this.label.setBorderColor({r:0, g:255, b:0, a:0.0});
|
||||
this.label.setBackgroundColor({r:0, g:255, b:0, a:0.0});
|
||||
|
||||
this.label = new Potree.TextSprite('0');
|
||||
this.label.setBorderColor({r: 0, g: 255, b: 0, a: 0.0});
|
||||
this.label.setBackgroundColor({r: 0, g: 255, b: 0, a: 0.0});
|
||||
this.label.material.depthTest = false;
|
||||
this.label.material.depthWrite = false;
|
||||
this.label.material.transparent = true;
|
||||
this.label.position.y -= 0.5;
|
||||
this.add(this.label);
|
||||
|
||||
|
||||
this.label.updateMatrixWorld = () => {
|
||||
var volumeWorldPos = new THREE.Vector3();
|
||||
volumeWorldPos.setFromMatrixPosition( this.matrixWorld );
|
||||
volumeWorldPos.setFromMatrixPosition(this.matrixWorld);
|
||||
this.label.position.copy(volumeWorldPos);
|
||||
this.label.updateMatrix();
|
||||
this.label.matrixWorld.copy(this.label.matrix);
|
||||
this.label.matrixWorldNeedsUpdate = false;
|
||||
|
||||
for ( var i = 0, l = this.label.children.length; i < l; i ++ ) {
|
||||
this.label.children[ i ].updateMatrixWorld( true );
|
||||
|
||||
for (var i = 0, l = this.label.children.length; i < l; i++) {
|
||||
this.label.children[ i ].updateMatrixWorld(true);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
{ // event listeners
|
||||
this.addEventListener("select", e => {});
|
||||
this.addEventListener("deselect", e => {});
|
||||
this.addEventListener('select', e => {});
|
||||
this.addEventListener('deselect', e => {});
|
||||
}
|
||||
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
getVolume(){
|
||||
getVolume () {
|
||||
return Math.abs(this.scale.x * this.scale.y * this.scale.z);
|
||||
}
|
||||
|
||||
update(){
|
||||
|
||||
update () {
|
||||
this.boundingBox = this.box.geometry.boundingBox;
|
||||
this.boundingSphere = this.boundingBox.getBoundingSphere();
|
||||
|
||||
if(this._clip){
|
||||
|
||||
if (this._clip) {
|
||||
this.box.visible = false;
|
||||
this.label.visible = false;
|
||||
}else{
|
||||
} else {
|
||||
this.box.visible = true;
|
||||
this.label.visible = true;
|
||||
}
|
||||
};
|
||||
|
||||
raycast(raycaster, intersects){
|
||||
|
||||
|
||||
raycast (raycaster, intersects) {
|
||||
let is = [];
|
||||
this.box.raycast(raycaster, is);
|
||||
|
||||
if(is.length > 0){
|
||||
|
||||
if (is.length > 0) {
|
||||
var I = is[0];
|
||||
intersects.push({
|
||||
distance: I.distance,
|
||||
@ -150,24 +148,24 @@ Potree.Volume = class extends THREE.Object3D{
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
get clip(){
|
||||
|
||||
get clip () {
|
||||
return this._clip;
|
||||
}
|
||||
|
||||
set clip(value){
|
||||
|
||||
set clip (value) {
|
||||
this._clip = value;
|
||||
|
||||
|
||||
this.update();
|
||||
}
|
||||
|
||||
get modifieable(){
|
||||
|
||||
get modifieable () {
|
||||
return this._modifiable;
|
||||
}
|
||||
|
||||
set modifieable(value){
|
||||
|
||||
set modifieable (value) {
|
||||
this._modifiable = value;
|
||||
|
||||
|
||||
this.update();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,137 +1,130 @@
|
||||
|
||||
Potree.VolumeTool = class VolumeTool extends THREE.EventDispatcher {
|
||||
constructor (viewer) {
|
||||
super();
|
||||
|
||||
Potree.VolumeTool = class VolumeTool extends THREE.EventDispatcher{
|
||||
|
||||
constructor(viewer){
|
||||
super()
|
||||
|
||||
this.viewer = viewer;
|
||||
this.renderer = viewer.renderer;
|
||||
|
||||
this.addEventListener("start_inserting_volume", e => {
|
||||
|
||||
this.addEventListener('start_inserting_volume', e => {
|
||||
this.viewer.dispatchEvent({
|
||||
type: "cancel_insertions"
|
||||
type: 'cancel_insertions'
|
||||
});
|
||||
});
|
||||
|
||||
this.sceneVolume = new THREE.Scene();
|
||||
this.sceneVolume.name = "scene_volume";
|
||||
|
||||
this.sceneVolume.name = 'scene_volume';
|
||||
|
||||
this.viewer.inputHandler.registerInteractiveScene(this.sceneVolume);
|
||||
|
||||
this.onRemove = e => {
|
||||
this.sceneVolume.remove(e.volume);
|
||||
};
|
||||
|
||||
|
||||
this.onAdd = e => {
|
||||
this.sceneVolume.add(e.volume);
|
||||
};
|
||||
|
||||
this.viewer.inputHandler.addEventListener("delete", e => {
|
||||
|
||||
this.viewer.inputHandler.addEventListener('delete', e => {
|
||||
let volumes = e.selection.filter(e => (e instanceof Potree.Volume));
|
||||
volumes.forEach(e => this.viewer.scene.removeVolume(e));
|
||||
});
|
||||
}
|
||||
|
||||
setScene(scene){
|
||||
if(this.scene === scene){
|
||||
|
||||
setScene (scene) {
|
||||
if (this.scene === scene) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.scene){
|
||||
this.scene.removeEventListeners("volume_added", this.onAdd);
|
||||
this.scene.removeEventListeners("volume_removed", this.onRemove);
|
||||
|
||||
if (this.scene) {
|
||||
this.scene.removeEventListeners('volume_added', this.onAdd);
|
||||
this.scene.removeEventListeners('volume_removed', this.onRemove);
|
||||
}
|
||||
|
||||
|
||||
this.scene = scene;
|
||||
|
||||
this.scene.addEventListener("volume_added", this.onAdd);
|
||||
this.scene.addEventListener("volume_removed", this.onRemove);
|
||||
|
||||
this.scene.addEventListener('volume_added', this.onAdd);
|
||||
this.scene.addEventListener('volume_removed', this.onRemove);
|
||||
}
|
||||
|
||||
startInsertion(args = {}){
|
||||
let domElement = this.viewer.renderer.domElement;
|
||||
|
||||
|
||||
startInsertion (args = {}) {
|
||||
let volume = new Potree.Volume();
|
||||
volume.clip = args.clip || false;
|
||||
volume.name = args.name || "Volume";
|
||||
|
||||
volume.name = args.name || 'Volume';
|
||||
|
||||
this.dispatchEvent({
|
||||
type: "start_inserting_volume",
|
||||
type: 'start_inserting_volume',
|
||||
volume: volume
|
||||
});
|
||||
|
||||
//this.sceneVolume.add(volume);
|
||||
|
||||
// this.sceneVolume.add(volume);
|
||||
this.viewer.scene.addVolume(volume);
|
||||
|
||||
|
||||
let cancel = {
|
||||
callback: null
|
||||
};
|
||||
|
||||
let drag = e => {
|
||||
let camera = this.viewer.scene.camera;
|
||||
|
||||
|
||||
let I = Potree.utils.getMousePointCloudIntersection(
|
||||
e.drag.end,
|
||||
this.viewer.scene.camera,
|
||||
this.viewer.renderer,
|
||||
e.drag.end,
|
||||
this.viewer.scene.camera,
|
||||
this.viewer.renderer,
|
||||
this.viewer.scene.pointclouds);
|
||||
|
||||
if(I){
|
||||
|
||||
if (I) {
|
||||
volume.position.copy(I.location);
|
||||
|
||||
|
||||
var wp = volume.getWorldPosition().applyMatrix4(camera.matrixWorldInverse);
|
||||
var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
|
||||
var w = Math.abs((wp.z / 10));
|
||||
volume.scale.set(w,w,w);
|
||||
// var pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
|
||||
var w = Math.abs((wp.z / 10));
|
||||
volume.scale.set(w, w, w);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
let drop = e => {
|
||||
volume.removeEventListener("drag", drag);
|
||||
volume.removeEventListener("drop", drop);
|
||||
|
||||
volume.removeEventListener('drag', drag);
|
||||
volume.removeEventListener('drop', drop);
|
||||
|
||||
cancel.callback();
|
||||
};
|
||||
|
||||
|
||||
cancel.callback = e => {
|
||||
volume.removeEventListener("drag", drag);
|
||||
volume.removeEventListener("drop", drop);
|
||||
this.viewer.removeEventListener("cancel_insertions", cancel.callback);
|
||||
volume.removeEventListener('drag', drag);
|
||||
volume.removeEventListener('drop', drop);
|
||||
this.viewer.removeEventListener('cancel_insertions', cancel.callback);
|
||||
};
|
||||
|
||||
volume.addEventListener("drag", drag);
|
||||
volume.addEventListener("drop", drop);
|
||||
this.viewer.addEventListener("cancel_insertions", cancel.callback);
|
||||
|
||||
|
||||
volume.addEventListener('drag', drag);
|
||||
volume.addEventListener('drop', drop);
|
||||
this.viewer.addEventListener('cancel_insertions', cancel.callback);
|
||||
|
||||
this.viewer.inputHandler.startDragging(volume);
|
||||
}
|
||||
|
||||
update(delta){
|
||||
|
||||
if(!this.scene){
|
||||
|
||||
update (delta) {
|
||||
if (!this.scene) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let camera = this.viewer.scene.camera;
|
||||
let domElement = this.viewer.renderer.domElement;
|
||||
//let labels = this.viewer.scene.volumes.map(e => e.label);
|
||||
|
||||
// let labels = this.viewer.scene.volumes.map(e => e.label);
|
||||
|
||||
let volumes = this.viewer.scene.volumes;
|
||||
for(let volume of volumes){
|
||||
for (let volume of volumes) {
|
||||
let label = volume.label;
|
||||
|
||||
|
||||
{
|
||||
let distance = label.position.distanceTo(camera.position);
|
||||
let pr = Potree.utils.projectedRadius(1, camera.fov * Math.PI / 180, distance, domElement.clientHeight);
|
||||
let scale = (70 / pr);
|
||||
label.scale.set(scale, scale, scale);
|
||||
}
|
||||
|
||||
let text = Potree.utils.addCommas(volume.getVolume().toFixed(3)) + "\u00B3";
|
||||
|
||||
let text = Potree.utils.addCommas(volume.getVolume().toFixed(3)) + '\u00B3';
|
||||
label.setText(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,81 +1,78 @@
|
||||
|
||||
|
||||
function ProgressBar(){
|
||||
function ProgressBar () {
|
||||
this._progress = 0;
|
||||
this._message = "";
|
||||
|
||||
this._message = '';
|
||||
|
||||
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 = "40px";
|
||||
this.element.style.width = "200px";
|
||||
this.element.style.marginLeft = "-100px";
|
||||
this.element.style.left = "50%";
|
||||
this.element.style.borderRadius = "5px";
|
||||
this.element.style.border = "1px solid #727678";
|
||||
this.element.style.height = "16px";
|
||||
this.element.style.padding = "1px";
|
||||
this.element.style.textAlign = "center";
|
||||
this.element.style.backgroundColor = "#6ba8e5";
|
||||
|
||||
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 = '40px';
|
||||
this.element.style.width = '200px';
|
||||
this.element.style.marginLeft = '-100px';
|
||||
this.element.style.left = '50%';
|
||||
this.element.style.borderRadius = '5px';
|
||||
this.element.style.border = '1px solid #727678';
|
||||
this.element.style.height = '16px';
|
||||
this.element.style.padding = '1px';
|
||||
this.element.style.textAlign = 'center';
|
||||
this.element.style.backgroundColor = '#6ba8e5';
|
||||
this.element.style.opacity = this.maxOpacity;
|
||||
this.element.style.pointerEvents = "none";
|
||||
|
||||
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";
|
||||
|
||||
|
||||
|
||||
this.element.style.pointerEvents = 'none';
|
||||
|
||||
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);
|
||||
|
||||
|
||||
this.hide();
|
||||
};
|
||||
|
||||
ProgressBar.prototype.hide = function(){
|
||||
ProgressBar.prototype.hide = function () {
|
||||
this.element.style.opacity = 0;
|
||||
this.element.style.transition = "all 0.2s ease";
|
||||
this.element.style.transition = 'all 0.2s ease';
|
||||
};
|
||||
|
||||
ProgressBar.prototype.show = function(){
|
||||
ProgressBar.prototype.show = function () {
|
||||
this.element.style.opacity = this.maxOpacity;
|
||||
this.element.style.transition = "all 0.2s ease";
|
||||
this.element.style.transition = 'all 0.2s ease';
|
||||
};
|
||||
|
||||
Object.defineProperty(ProgressBar.prototype, "progress", {
|
||||
get: function(){
|
||||
Object.defineProperty(ProgressBar.prototype, 'progress', {
|
||||
get: function () {
|
||||
return this._progress;
|
||||
},
|
||||
set: function(value){
|
||||
set: function (value) {
|
||||
this._progress = value;
|
||||
this.elProgress.style.width = (value * 100) + "%";
|
||||
this.elProgress.style.width = (value * 100) + '%';
|
||||
}
|
||||
});
|
||||
|
||||
Object.defineProperty(ProgressBar.prototype, "message", {
|
||||
get: function(){
|
||||
Object.defineProperty(ProgressBar.prototype, 'message', {
|
||||
get: function () {
|
||||
return this._message;
|
||||
},
|
||||
set: function(message){
|
||||
set: function (message) {
|
||||
this._message = message;
|
||||
this.elProgressMessage.innerHTML = message;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,24 +1,23 @@
|
||||
|
||||
// http://epsg.io/
|
||||
proj4.defs("UTM10N", "+proj=utm +zone=10 +ellps=GRS80 +datum=NAD83 +units=m +no_defs");
|
||||
proj4.defs('UTM10N', '+proj=utm +zone=10 +ellps=GRS80 +datum=NAD83 +units=m +no_defs');
|
||||
|
||||
Potree.MapView = class{
|
||||
|
||||
constructor(viewer){
|
||||
Potree.MapView = class {
|
||||
constructor (viewer) {
|
||||
this.viewer = viewer;
|
||||
|
||||
this.webMapService = "WMTS";
|
||||
this.mapProjectionName = "EPSG:3857";
|
||||
|
||||
this.webMapService = 'WMTS';
|
||||
this.mapProjectionName = 'EPSG:3857';
|
||||
this.mapProjection = proj4.defs(this.mapProjectionName);
|
||||
this.sceneProjection = null;
|
||||
|
||||
|
||||
this.extentsLayer = null;
|
||||
this.cameraLayer = null;
|
||||
this.toolLayer = null;
|
||||
this.sourcesLayer = null;
|
||||
this.sourcesLabelLayer = null;
|
||||
this.enabled = false;
|
||||
|
||||
|
||||
this.createAnnotationStyle = (text) => {
|
||||
return [
|
||||
new ol.style.Style({
|
||||
@ -45,10 +44,10 @@ Potree.MapView = class{
|
||||
width: 2
|
||||
})
|
||||
})
|
||||
})*/
|
||||
}) */
|
||||
];
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
this.createLabelStyle = (text) => {
|
||||
let style = new ol.style.Style({
|
||||
image: new ol.style.Circle({
|
||||
@ -73,129 +72,123 @@ Potree.MapView = class{
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
return style;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
showSources(show){
|
||||
|
||||
showSources (show) {
|
||||
this.sourcesLayer.setVisible(show);
|
||||
this.sourcesLabelLayer.setVisible(show);
|
||||
}
|
||||
|
||||
init(){
|
||||
this.elMap = $("#potree_map");
|
||||
|
||||
init () {
|
||||
this.elMap = $('#potree_map');
|
||||
this.elMap.draggable({ handle: $('#potree_map_header') });
|
||||
this.elMap.resizable();
|
||||
|
||||
|
||||
this.elTooltip = $(`<div style="position: relative; z-index: 100"></div>`);
|
||||
this.elMap.append(this.elTooltip);
|
||||
|
||||
|
||||
let extentsLayer = this.getExtentsLayer();
|
||||
let cameraLayer = this.getCameraLayer();
|
||||
let toolLayer = this.getToolLayer();
|
||||
this.getToolLayer();
|
||||
let sourcesLayer = this.getSourcesLayer();
|
||||
let sourcesLabelLayer = this.getSourcesLabelLayer();
|
||||
let annotationsLayer = this.getAnnotationsLayer();
|
||||
|
||||
this.getSourcesLabelLayer();
|
||||
this.getAnnotationsLayer();
|
||||
|
||||
let mousePositionControl = new ol.control.MousePosition({
|
||||
coordinateFormat: ol.coordinate.createStringXY(5),
|
||||
projection: "EPSG:4326",
|
||||
projection: 'EPSG:4326',
|
||||
undefinedHTML: ' '
|
||||
});
|
||||
|
||||
|
||||
let _this = this;
|
||||
let DownloadSelectionControl = function(opt_options){
|
||||
let options = opt_options || {};
|
||||
|
||||
let DownloadSelectionControl = function (optOptions) {
|
||||
let options = optOptions || {};
|
||||
|
||||
// TOGGLE TILES
|
||||
let btToggleTiles = document.createElement('button');
|
||||
btToggleTiles.innerHTML = 'T';
|
||||
btToggleTiles.addEventListener('click', () => {
|
||||
let visible = sourcesLayer.getVisible();
|
||||
_this.showSources(!visible);
|
||||
//sourcesLayer.setVisible(!visible);
|
||||
//sourcesLabelLayer.setVisible(!visible);
|
||||
}, false);
|
||||
btToggleTiles.style.float = "left";
|
||||
btToggleTiles.title = "show / hide tiles";
|
||||
|
||||
btToggleTiles.style.float = 'left';
|
||||
btToggleTiles.title = 'show / hide tiles';
|
||||
|
||||
// DOWNLOAD SELECTED TILES
|
||||
let link = document.createElement("a");
|
||||
link.href = "#";
|
||||
link.download = "list.txt";
|
||||
link.style.float = "left";
|
||||
|
||||
let link = document.createElement('a');
|
||||
link.href = '#';
|
||||
link.download = 'list.txt';
|
||||
link.style.float = 'left';
|
||||
|
||||
let button = document.createElement('button');
|
||||
button.innerHTML = 'D';
|
||||
link.appendChild(button);
|
||||
|
||||
let this_ = this;
|
||||
|
||||
let handleDownload = (e) => {
|
||||
let features = selectedFeatures.getArray();
|
||||
|
||||
let url = [location.protocol, '//', location.host, location.pathname].join('');
|
||||
|
||||
if(features.length === 0){
|
||||
alert("No tiles were selected. Select area with ctrl + left mouse button!");
|
||||
|
||||
let url = [document.location.protocol, '//', document.location.host, document.location.pathname].join('');
|
||||
|
||||
if (features.length === 0) {
|
||||
alert('No tiles were selected. Select area with ctrl + left mouse button!');
|
||||
e.preventDefault();
|
||||
e.stopImmediatePropagation();
|
||||
return false;
|
||||
}else if(features.length === 1){
|
||||
} else if (features.length === 1) {
|
||||
let feature = features[0];
|
||||
|
||||
if(feature.source){
|
||||
|
||||
if (feature.source) {
|
||||
let cloudjsurl = feature.pointcloud.pcoGeometry.url;
|
||||
let sourceurl = new URL(url + '/../' + cloudjsurl + '/../source/' + feature.source.name);
|
||||
link.href = sourceurl.href;
|
||||
link.download = feature.source.name;
|
||||
}
|
||||
}else{
|
||||
let content = "";
|
||||
for(var i = 0; i < features.length; i++){
|
||||
} else {
|
||||
let content = '';
|
||||
for (var i = 0; i < features.length; i++) {
|
||||
let feature = features[i];
|
||||
|
||||
if(feature.source){
|
||||
|
||||
if (feature.source) {
|
||||
let cloudjsurl = feature.pointcloud.pcoGeometry.url;
|
||||
let sourceurl = new URL(url + '/../' + cloudjsurl + '/../source/' + feature.source.name);
|
||||
content += sourceurl.href + "\n";
|
||||
content += sourceurl.href + '\n';
|
||||
}
|
||||
}
|
||||
|
||||
let uri = "data:application/octet-stream;base64,"+btoa(content);
|
||||
|
||||
let uri = 'data:application/octet-stream;base64,' + btoa(content);
|
||||
link.href = uri;
|
||||
link.download = "list_of_files.txt";
|
||||
link.download = 'list_of_files.txt';
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
button.addEventListener('click', handleDownload, false);
|
||||
|
||||
|
||||
// assemble container
|
||||
let element = document.createElement('div');
|
||||
element.className = 'ol-unselectable ol-control';
|
||||
element.appendChild(link);
|
||||
element.appendChild(btToggleTiles);
|
||||
element.style.bottom = "0.5em";
|
||||
element.style.left = "0.5em";
|
||||
element.title = "Download file or list of selected tiles. Select tile with left mouse button or area using ctrl + left mouse.";
|
||||
|
||||
element.style.bottom = '0.5em';
|
||||
element.style.left = '0.5em';
|
||||
element.title = 'Download file or list of selected tiles. Select tile with left mouse button or area using ctrl + left mouse.';
|
||||
|
||||
ol.control.Control.call(this, {
|
||||
element: element,
|
||||
target: options.target
|
||||
});
|
||||
|
||||
};
|
||||
ol.inherits(DownloadSelectionControl, ol.control.Control);
|
||||
|
||||
|
||||
this.map = new ol.Map({
|
||||
controls: ol.control.defaults({
|
||||
attributionOptions: ({
|
||||
collapsible: false
|
||||
collapsible: false
|
||||
})
|
||||
}).extend([
|
||||
//this.controls.zoomToExtent,
|
||||
// this.controls.zoomToExtent,
|
||||
new DownloadSelectionControl(),
|
||||
mousePositionControl
|
||||
]),
|
||||
@ -220,51 +213,51 @@ Potree.MapView = class{
|
||||
source: new ol.source.Vector({}),
|
||||
style: new ol.style.Style({
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'rgba(0, 0, 255, 1)',
|
||||
width: 2
|
||||
color: 'rgba(0, 0, 255, 1)',
|
||||
width: 2
|
||||
})
|
||||
})
|
||||
});
|
||||
this.map.addLayer(this.dragBoxLayer);
|
||||
|
||||
|
||||
let select = new ol.interaction.Select();
|
||||
this.map.addInteraction(select);
|
||||
|
||||
|
||||
let selectedFeatures = select.getFeatures();
|
||||
|
||||
|
||||
let dragBox = new ol.interaction.DragBox({
|
||||
condition: ol.events.condition.platformModifierKeyOnly
|
||||
condition: ol.events.condition.platformModifierKeyOnly
|
||||
});
|
||||
|
||||
|
||||
this.map.addInteraction(dragBox);
|
||||
|
||||
|
||||
this.map.on('pointermove', evt => {
|
||||
let pixel = evt.pixel;
|
||||
let feature = this.map.forEachFeatureAtPixel(pixel, function(feature) {
|
||||
let feature = this.map.forEachFeatureAtPixel(pixel, function (feature) {
|
||||
return feature;
|
||||
});
|
||||
|
||||
//console.log(feature);
|
||||
//this.elTooltip.css("display", feature ? '' : 'none');
|
||||
this.elTooltip.css("display", "none");
|
||||
if(feature && feature.onHover){
|
||||
|
||||
// console.log(feature);
|
||||
// this.elTooltip.css("display", feature ? '' : 'none');
|
||||
this.elTooltip.css('display', 'none');
|
||||
if (feature && feature.onHover) {
|
||||
feature.onHover(evt);
|
||||
//overlay.setPosition(evt.coordinate);
|
||||
//tooltip.innerHTML = feature.get('name');
|
||||
// overlay.setPosition(evt.coordinate);
|
||||
// tooltip.innerHTML = feature.get('name');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.map.on('click', evt => {
|
||||
let pixel = evt.pixel;
|
||||
let feature = this.map.forEachFeatureAtPixel(pixel, function(feature) {
|
||||
let feature = this.map.forEachFeatureAtPixel(pixel, function (feature) {
|
||||
return feature;
|
||||
});
|
||||
|
||||
if(feature && feature.onHover){
|
||||
|
||||
if (feature && feature.onHover) {
|
||||
feature.onClick(evt);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
dragBox.on('boxend', (e) => {
|
||||
// features that intersect the box are added to the collection of
|
||||
// selected features, and their names are displayed in the "info"
|
||||
@ -274,7 +267,7 @@ Potree.MapView = class{
|
||||
selectedFeatures.push(feature);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// clear selection when drawing a new box and when clicking on the map
|
||||
dragBox.on('boxstart', (e) => {
|
||||
selectedFeatures.clear();
|
||||
@ -283,84 +276,84 @@ Potree.MapView = class{
|
||||
selectedFeatures.clear();
|
||||
});
|
||||
|
||||
this.viewer.addEventListener("scene_changed", e => {
|
||||
this.viewer.addEventListener('scene_changed', e => {
|
||||
this.setScene(e.scene);
|
||||
});
|
||||
|
||||
|
||||
this.onPointcloudAdded = e => {
|
||||
this.load(e.pointcloud);
|
||||
};
|
||||
|
||||
|
||||
this.onAnnotationAdded = e => {
|
||||
if(!this.sceneProjection){
|
||||
if (!this.sceneProjection) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let annotation = e.annotation;
|
||||
let position = annotation.position;
|
||||
let mapPos = this.toMap.forward([position.x, position.y]);
|
||||
let feature = new ol.Feature({
|
||||
geometry: new ol.geom.Point(mapPos),
|
||||
name: annotation.title
|
||||
geometry: new ol.geom.Point(mapPos),
|
||||
name: annotation.title
|
||||
});
|
||||
feature.setStyle(this.createAnnotationStyle(annotation.title));
|
||||
|
||||
|
||||
feature.onHover = evt => {
|
||||
let coordinates = feature.getGeometry().getCoordinates();
|
||||
let p = this.map.getPixelFromCoordinate(coordinates);
|
||||
|
||||
|
||||
this.elTooltip.html(annotation.title);
|
||||
this.elTooltip.css("display", "");
|
||||
this.elTooltip.css("left", `${p[0]}px`);
|
||||
this.elTooltip.css("top", `${p[1]}px`);
|
||||
this.elTooltip.css('display', '');
|
||||
this.elTooltip.css('left', `${p[0]}px`);
|
||||
this.elTooltip.css('top', `${p[1]}px`);
|
||||
};
|
||||
|
||||
|
||||
feature.onClick = evt => {
|
||||
annotation.clickTitle();
|
||||
};
|
||||
|
||||
|
||||
this.getAnnotationsLayer().getSource().addFeature(feature);
|
||||
};
|
||||
|
||||
|
||||
this.setScene(this.viewer.scene);
|
||||
}
|
||||
|
||||
setScene(scene){
|
||||
if(this.scene === scene){
|
||||
|
||||
setScene (scene) {
|
||||
if (this.scene === scene) {
|
||||
return;
|
||||
};
|
||||
|
||||
if(this.scene){
|
||||
this.scene.removeEventListener("pointcloud_added", this.onPointcloudAdded);
|
||||
this.scene.annotations.removeEventListener("annotation_added", this.onAnnotationAdded);
|
||||
|
||||
if (this.scene) {
|
||||
this.scene.removeEventListener('pointcloud_added', this.onPointcloudAdded);
|
||||
this.scene.annotations.removeEventListener('annotation_added', this.onAnnotationAdded);
|
||||
}
|
||||
|
||||
|
||||
this.scene = scene;
|
||||
|
||||
this.scene.addEventListener("pointcloud_added", this.onPointcloudAdded);
|
||||
this.scene.annotations.addEventListener("annotation_added", this.onAnnotationAdded);
|
||||
|
||||
for(let pointcloud of this.viewer.scene.pointclouds){
|
||||
|
||||
this.scene.addEventListener('pointcloud_added', this.onPointcloudAdded);
|
||||
this.scene.annotations.addEventListener('annotation_added', this.onAnnotationAdded);
|
||||
|
||||
for (let pointcloud of this.viewer.scene.pointclouds) {
|
||||
this.load(pointcloud);
|
||||
}
|
||||
|
||||
|
||||
this.viewer.scene.annotations.traverseDescendants(annotation => {
|
||||
this.onAnnotationAdded({annotation: annotation});
|
||||
});
|
||||
}
|
||||
|
||||
getExtentsLayer(){
|
||||
if(this.extentsLayer){
|
||||
|
||||
getExtentsLayer () {
|
||||
if (this.extentsLayer) {
|
||||
return this.extentsLayer;
|
||||
}
|
||||
|
||||
this.gExtent = new ol.geom.LineString([[0,0], [0,0]]);
|
||||
|
||||
|
||||
this.gExtent = new ol.geom.LineString([[0, 0], [0, 0]]);
|
||||
|
||||
let feature = new ol.Feature(this.gExtent);
|
||||
let featureVector = new ol.source.Vector({
|
||||
features: [feature]
|
||||
});
|
||||
|
||||
|
||||
this.extentsLayer = new ol.layer.Vector({
|
||||
source: featureVector,
|
||||
style: new ol.style.Style({
|
||||
@ -368,8 +361,8 @@ Potree.MapView = class{
|
||||
color: 'rgba(255, 255, 255, 0.2)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#0000ff',
|
||||
width: 2
|
||||
color: '#0000ff',
|
||||
width: 2
|
||||
}),
|
||||
image: new ol.style.Circle({
|
||||
radius: 3,
|
||||
@ -379,15 +372,15 @@ Potree.MapView = class{
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
return this.extentsLayer;
|
||||
}
|
||||
|
||||
getAnnotationsLayer(){
|
||||
if(this.annotationsLayer){
|
||||
|
||||
getAnnotationsLayer () {
|
||||
if (this.annotationsLayer) {
|
||||
return this.annotationsLayer;
|
||||
}
|
||||
|
||||
|
||||
this.annotationsLayer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
}),
|
||||
@ -396,45 +389,45 @@ Potree.MapView = class{
|
||||
color: 'rgba(255, 0, 0, 1)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'rgba(255, 0, 0, 1)',
|
||||
width: 2
|
||||
color: 'rgba(255, 0, 0, 1)',
|
||||
width: 2
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
return this.annotationsLayer;
|
||||
}
|
||||
|
||||
getCameraLayer(){
|
||||
if(this.cameraLayer){
|
||||
|
||||
getCameraLayer () {
|
||||
if (this.cameraLayer) {
|
||||
return this.cameraLayer;
|
||||
}
|
||||
|
||||
|
||||
// CAMERA LAYER
|
||||
this.gCamera = new ol.geom.LineString([[0,0], [0,0], [0,0], [0,0]]);
|
||||
this.gCamera = new ol.geom.LineString([[0, 0], [0, 0], [0, 0], [0, 0]]);
|
||||
let feature = new ol.Feature(this.gCamera);
|
||||
let featureVector = new ol.source.Vector({
|
||||
features: [feature]
|
||||
});
|
||||
|
||||
|
||||
this.cameraLayer = new ol.layer.Vector({
|
||||
source: featureVector,
|
||||
style: new ol.style.Style({
|
||||
stroke: new ol.style.Stroke({
|
||||
color: '#0000ff',
|
||||
width: 2
|
||||
color: '#0000ff',
|
||||
width: 2
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
return this.cameraLayer;
|
||||
}
|
||||
|
||||
getToolLayer(){
|
||||
if(this.toolLayer){
|
||||
|
||||
getToolLayer () {
|
||||
if (this.toolLayer) {
|
||||
return this.toolLayer;
|
||||
}
|
||||
|
||||
|
||||
this.toolLayer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
}),
|
||||
@ -443,20 +436,20 @@ Potree.MapView = class{
|
||||
color: 'rgba(255, 0, 0, 1)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'rgba(255, 0, 0, 1)',
|
||||
width: 2
|
||||
color: 'rgba(255, 0, 0, 1)',
|
||||
width: 2
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
return this.toolLayer;
|
||||
}
|
||||
|
||||
getSourcesLayer(){
|
||||
if(this.sourcesLayer){
|
||||
|
||||
getSourcesLayer () {
|
||||
if (this.sourcesLayer) {
|
||||
return this.sourcesLayer;
|
||||
}
|
||||
|
||||
|
||||
this.sourcesLayer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({}),
|
||||
style: new ol.style.Style({
|
||||
@ -464,20 +457,20 @@ Potree.MapView = class{
|
||||
color: 'rgba(0, 0, 150, 0.1)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'rgba(0, 0, 150, 1)',
|
||||
width: 1
|
||||
color: 'rgba(0, 0, 150, 1)',
|
||||
width: 1
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
return this.sourcesLayer;
|
||||
}
|
||||
|
||||
getSourcesLabelLayer(){
|
||||
if(this.sourcesLabelLayer){
|
||||
|
||||
getSourcesLabelLayer () {
|
||||
if (this.sourcesLabelLayer) {
|
||||
return this.sourcesLabelLayer;
|
||||
}
|
||||
|
||||
|
||||
this.sourcesLabelLayer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
}),
|
||||
@ -486,205 +479,194 @@ Potree.MapView = class{
|
||||
color: 'rgba(255, 0, 0, 0.1)'
|
||||
}),
|
||||
stroke: new ol.style.Stroke({
|
||||
color: 'rgba(255, 0, 0, 1)',
|
||||
width: 2
|
||||
color: 'rgba(255, 0, 0, 1)',
|
||||
width: 2
|
||||
})
|
||||
}),
|
||||
minResolution: 0.01,
|
||||
maxResolution: 20
|
||||
maxResolution: 20
|
||||
});
|
||||
|
||||
|
||||
return this.sourcesLabelLayer;
|
||||
}
|
||||
|
||||
setSceneProjection(sceneProjection){
|
||||
|
||||
setSceneProjection (sceneProjection) {
|
||||
this.sceneProjection = sceneProjection;
|
||||
this.toMap = proj4(this.sceneProjection, this.mapProjection);
|
||||
this.toScene = proj4(this.mapProjection, this.sceneProjection);
|
||||
};
|
||||
|
||||
getMapExtent(){
|
||||
|
||||
getMapExtent () {
|
||||
let bb = this.viewer.getBoundingBox();
|
||||
|
||||
|
||||
let bottomLeft = this.toMap.forward([bb.min.x, bb.min.y]);
|
||||
let bottomRight = this.toMap.forward([bb.max.x, bb.min.y]);
|
||||
let topRight = this.toMap.forward([bb.max.x, bb.max.y]);
|
||||
let topLeft = this.toMap.forward([bb.min.x, bb.max.y]);
|
||||
|
||||
|
||||
let extent = {
|
||||
bottomLeft: bottomLeft,
|
||||
bottomRight: bottomRight,
|
||||
topRight: topRight,
|
||||
topLeft: topLeft
|
||||
};
|
||||
|
||||
|
||||
return extent;
|
||||
};
|
||||
|
||||
getMapCenter(){
|
||||
|
||||
getMapCenter () {
|
||||
let mapExtent = this.getMapExtent();
|
||||
|
||||
|
||||
let mapCenter = [
|
||||
(mapExtent.bottomLeft[0] + mapExtent.topRight[0]) / 2,
|
||||
(mapExtent.bottomLeft[0] + mapExtent.topRight[0]) / 2,
|
||||
(mapExtent.bottomLeft[1] + mapExtent.topRight[1]) / 2
|
||||
];
|
||||
|
||||
|
||||
return mapCenter;
|
||||
};
|
||||
|
||||
updateToolDrawings(){
|
||||
};
|
||||
|
||||
updateToolDrawings () {
|
||||
this.toolLayer.getSource().clear();
|
||||
|
||||
|
||||
let profiles = this.viewer.profileTool.profiles;
|
||||
for(var i = 0; i < profiles.length; i++){
|
||||
for (let i = 0; i < profiles.length; i++) {
|
||||
let profile = profiles[i];
|
||||
let coordinates = [];
|
||||
|
||||
for(var j = 0; j < profile.points.length; j++){
|
||||
|
||||
for (let j = 0; j < profile.points.length; j++) {
|
||||
let point = profile.points[j];
|
||||
let pointMap = this.toMap.forward([point.x, point.y]);
|
||||
coordinates.push(pointMap);
|
||||
}
|
||||
|
||||
|
||||
let line = new ol.geom.LineString(coordinates);
|
||||
let feature = new ol.Feature(line);
|
||||
this.toolLayer.getSource().addFeature(feature);
|
||||
}
|
||||
|
||||
|
||||
let measurements = this.viewer.measuringTool.measurements;
|
||||
for(var i = 0; i < measurements.length; i++){
|
||||
for (let i = 0; i < measurements.length; i++) {
|
||||
let measurement = measurements[i];
|
||||
let coordinates = [];
|
||||
|
||||
for(var j = 0; j < measurement.points.length; j++){
|
||||
|
||||
for (let j = 0; j < measurement.points.length; j++) {
|
||||
let point = measurement.points[j].position;
|
||||
let pointMap = this.toMap.forward([point.x, point.y]);
|
||||
coordinates.push(pointMap);
|
||||
}
|
||||
|
||||
if(measurement.closed && measurement.points.length > 0){
|
||||
|
||||
if (measurement.closed && measurement.points.length > 0) {
|
||||
coordinates.push(coordinates[0]);
|
||||
}
|
||||
|
||||
|
||||
let line = new ol.geom.LineString(coordinates);
|
||||
let feature = new ol.Feature(line);
|
||||
this.toolLayer.getSource().addFeature(feature);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
load(pointcloud){
|
||||
|
||||
if(!pointcloud){
|
||||
|
||||
load (pointcloud) {
|
||||
if (!pointcloud) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!pointcloud.projection){
|
||||
|
||||
if (!pointcloud.projection) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!this.sceneProjection){
|
||||
|
||||
if (!this.sceneProjection) {
|
||||
this.setSceneProjection(pointcloud.projection);
|
||||
}
|
||||
|
||||
|
||||
let mapExtent = this.getMapExtent();
|
||||
let mapCenter = this.getMapCenter();
|
||||
|
||||
|
||||
|
||||
let view = this.map.getView();
|
||||
view.setCenter(mapCenter);
|
||||
|
||||
|
||||
this.gExtent.setCoordinates([
|
||||
mapExtent.bottomLeft,
|
||||
mapExtent.bottomRight,
|
||||
mapExtent.topRight,
|
||||
mapExtent.bottomLeft,
|
||||
mapExtent.bottomRight,
|
||||
mapExtent.topRight,
|
||||
mapExtent.topLeft,
|
||||
mapExtent.bottomLeft
|
||||
]);
|
||||
|
||||
|
||||
view.fit(this.gExtent, [300, 300], {
|
||||
constrainResolution: false
|
||||
});
|
||||
|
||||
|
||||
|
||||
let url = pointcloud.pcoGeometry.url + "/../sources.json";
|
||||
let url = pointcloud.pcoGeometry.url + '/../sources.json';
|
||||
$.getJSON(url, (data) => {
|
||||
let sources = data.sources;
|
||||
|
||||
for(var i = 0; i < sources.length; i++){
|
||||
|
||||
for (var i = 0; i < sources.length; i++) {
|
||||
let source = sources[i];
|
||||
let name = source.name;
|
||||
let points = source.points;
|
||||
let bounds = source.bounds;
|
||||
|
||||
let mapBounds = {
|
||||
min: this.toMap.forward( [bounds.min[0], bounds.min[1]] ),
|
||||
max: this.toMap.forward( [bounds.max[0], bounds.max[1]] )
|
||||
}
|
||||
min: this.toMap.forward([bounds.min[0], bounds.min[1]]),
|
||||
max: this.toMap.forward([bounds.max[0], bounds.max[1]])
|
||||
};
|
||||
let mapCenter = [
|
||||
(mapBounds.min[0] + mapBounds.max[0]) / 2,
|
||||
(mapBounds.min[1] + mapBounds.max[1]) / 2,
|
||||
(mapBounds.min[1] + mapBounds.max[1]) / 2
|
||||
];
|
||||
|
||||
let p1 = this.toMap.forward( [bounds.min[0], bounds.min[1]] );
|
||||
let p2 = this.toMap.forward( [bounds.max[0], bounds.min[1]] );
|
||||
let p3 = this.toMap.forward( [bounds.max[0], bounds.max[1]] );
|
||||
let p4 = this.toMap.forward( [bounds.min[0], bounds.max[1]] );
|
||||
|
||||
let boxes = [];
|
||||
//var feature = new ol.Feature({
|
||||
|
||||
let p1 = this.toMap.forward([bounds.min[0], bounds.min[1]]);
|
||||
let p2 = this.toMap.forward([bounds.max[0], bounds.min[1]]);
|
||||
let p3 = this.toMap.forward([bounds.max[0], bounds.max[1]]);
|
||||
let p4 = this.toMap.forward([bounds.min[0], bounds.max[1]]);
|
||||
|
||||
// var feature = new ol.Feature({
|
||||
// 'geometry': new ol.geom.LineString([p1, p2, p3, p4, p1])
|
||||
//});
|
||||
// });
|
||||
let feature = new ol.Feature({
|
||||
'geometry': new ol.geom.Polygon([[p1, p2, p3, p4, p1]])
|
||||
});
|
||||
feature.source = source;
|
||||
feature.pointcloud = pointcloud;
|
||||
this.getSourcesLayer().getSource().addFeature(feature);
|
||||
|
||||
|
||||
|
||||
feature = new ol.Feature({
|
||||
geometry: new ol.geom.Point(mapCenter),
|
||||
name: name
|
||||
geometry: new ol.geom.Point(mapCenter),
|
||||
name: name
|
||||
});
|
||||
feature.setStyle(this.createLabelStyle(name));
|
||||
this.sourcesLabelLayer.getSource().addFeature(feature);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
toggle(){
|
||||
|
||||
if(this.elMap.is(":visible")){
|
||||
this.elMap.css("display", "none");
|
||||
|
||||
toggle () {
|
||||
if (this.elMap.is(':visible')) {
|
||||
this.elMap.css('display', 'none');
|
||||
this.enabled = false;
|
||||
}else{
|
||||
this.elMap.css("display", "block");
|
||||
} else {
|
||||
this.elMap.css('display', 'block');
|
||||
this.enabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
update(delta){
|
||||
if(!this.sceneProjection){
|
||||
|
||||
update (delta) {
|
||||
if (!this.sceneProjection) {
|
||||
return;
|
||||
}
|
||||
|
||||
let pm = $( "#potree_map" );
|
||||
|
||||
if(!this.enabled){
|
||||
|
||||
let pm = $('#potree_map');
|
||||
|
||||
if (!this.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// resize
|
||||
let mapSize = this.map.getSize();
|
||||
let resized = (pm.width() != mapSize[0] || pm.height() != mapSize[1]);
|
||||
if(resized){
|
||||
let resized = (pm.width() !== mapSize[0] || pm.height() !== mapSize[1]);
|
||||
if (resized) {
|
||||
this.map.updateSize();
|
||||
}
|
||||
|
||||
|
||||
// camera
|
||||
let scale = this.map.getView().getResolution();
|
||||
let camera = this.viewer.scene.camera;
|
||||
@ -699,24 +681,19 @@ Potree.MapView = class{
|
||||
mapLookAt = mapPos.clone().add(mapDir.clone().multiplyScalar(30 * scale));
|
||||
let mapLength = mapPos.distanceTo(mapLookAt);
|
||||
let mapSide = new THREE.Vector2(-mapDir.y, mapDir.x);
|
||||
|
||||
|
||||
let p1 = mapPos.toArray();
|
||||
let p2 = mapLookAt.clone().sub(mapSide.clone().multiplyScalar(0.3 * mapLength)).toArray();
|
||||
let p3 = mapLookAt.clone().add(mapSide.clone().multiplyScalar(0.3 * mapLength)).toArray();
|
||||
|
||||
|
||||
this.gCamera.setCoordinates([p1, p2, p3, p1]);
|
||||
}
|
||||
|
||||
get sourcesVisible(){
|
||||
|
||||
get sourcesVisible () {
|
||||
return this.getSourcesLayer().getVisible();
|
||||
}
|
||||
|
||||
set sourcesVisible(value){
|
||||
|
||||
set sourcesVisible (value) {
|
||||
this.getSourcesLayer().setVisible(value);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1825
src/viewer/viewer.js
1825
src/viewer/viewer.js
File diff suppressed because it is too large
Load Diff
@ -1,45 +1,44 @@
|
||||
|
||||
Potree.GLProgram = class GLProgram{
|
||||
|
||||
constructor(gl, material){
|
||||
Potree.GLProgram = class GLProgram {
|
||||
constructor (gl, material) {
|
||||
this.gl = gl;
|
||||
this.material = material;
|
||||
this.program = gl.createProgram();;
|
||||
|
||||
this.program = gl.createProgram(); ;
|
||||
|
||||
this.recompile();
|
||||
}
|
||||
|
||||
compileShader(type, source){
|
||||
|
||||
compileShader (type, source) {
|
||||
let gl = this.gl;
|
||||
|
||||
|
||||
let vs = gl.createShader(type);
|
||||
|
||||
|
||||
gl.shaderSource(vs, source);
|
||||
gl.compileShader(vs);
|
||||
|
||||
|
||||
let success = gl.getShaderParameter(vs, gl.COMPILE_STATUS);
|
||||
if (!success) {
|
||||
console.error("could not compile shader:");
|
||||
|
||||
console.error('could not compile shader:');
|
||||
|
||||
let log = gl.getShaderInfoLog(vs);
|
||||
console.error(log, source);
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return vs;
|
||||
}
|
||||
|
||||
recompile(){
|
||||
|
||||
recompile () {
|
||||
let gl = this.gl;
|
||||
|
||||
let vs = this.compileShader(gl.VERTEX_SHADER, this.material.vertexShader);
|
||||
let fs = this.compileShader(gl.FRAGMENT_SHADER, this.material.fragmentShader);
|
||||
|
||||
if(vs === null || fs === null){
|
||||
|
||||
if (vs === null || fs === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// PROGRAM
|
||||
let program = this.program;
|
||||
gl.attachShader(program, vs);
|
||||
@ -47,34 +46,33 @@ Potree.GLProgram = class GLProgram{
|
||||
gl.linkProgram(program);
|
||||
let success = gl.getProgramParameter(program, gl.LINK_STATUS);
|
||||
if (!success) {
|
||||
console.error("could not compile/link program:");
|
||||
console.error('could not compile/link program:');
|
||||
console.error(this.material.vertexShader);
|
||||
console.error(this.material.fragmentShader);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
gl.detachShader(program, vs);
|
||||
gl.detachShader(program, fs);
|
||||
gl.deleteShader(vs);
|
||||
gl.deleteShader(fs);
|
||||
|
||||
|
||||
gl.useProgram(program);
|
||||
|
||||
|
||||
{ // UNIFORMS
|
||||
let uniforms = {};
|
||||
let n = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
|
||||
|
||||
for(let i = 0; i < n; i++){
|
||||
for (let i = 0; i < n; i++) {
|
||||
var uniform = gl.getActiveUniform(program, i);
|
||||
var name = uniform.name;
|
||||
var loc = gl.getUniformLocation(program, name);
|
||||
|
||||
uniforms[name] = loc;
|
||||
}
|
||||
|
||||
|
||||
this.uniforms = uniforms;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
/* global onmessage:true postMessage:false */
|
||||
/* exported onmessage */
|
||||
// http://jsperf.com/uint8array-vs-dataview3/3
|
||||
function CustomView(buffer) {
|
||||
function CustomView (buffer) {
|
||||
this.buffer = buffer;
|
||||
this.u8 = new Uint8Array(buffer);
|
||||
|
||||
@ -9,138 +10,121 @@ function CustomView(buffer) {
|
||||
let tmpu8 = new Uint8Array(tmp);
|
||||
|
||||
this.getUint32 = function (i) {
|
||||
return (this.u8[i+3] << 24) | (this.u8[i+2] << 16) | (this.u8[i+1] << 8) | this.u8[i];
|
||||
return (this.u8[i + 3] << 24) | (this.u8[i + 2] << 16) | (this.u8[i + 1] << 8) | this.u8[i];
|
||||
};
|
||||
|
||||
this.getUint16 = function (i) {
|
||||
return (this.u8[i+1] << 8) | this.u8[i];
|
||||
return (this.u8[i + 1] << 8) | this.u8[i];
|
||||
};
|
||||
|
||||
this.getFloat32 = function(i){
|
||||
tmpu8[0] = this.u8[i+0];
|
||||
tmpu8[1] = this.u8[i+1];
|
||||
tmpu8[2] = this.u8[i+2];
|
||||
tmpu8[3] = this.u8[i+3];
|
||||
this.getFloat32 = function (i) {
|
||||
tmpu8[0] = this.u8[i + 0];
|
||||
tmpu8[1] = this.u8[i + 1];
|
||||
tmpu8[2] = this.u8[i + 2];
|
||||
tmpu8[3] = this.u8[i + 3];
|
||||
|
||||
return tmpf[0];
|
||||
};
|
||||
|
||||
this.getUint8 = function(i){
|
||||
this.getUint8 = function (i) {
|
||||
return this.u8[i];
|
||||
};
|
||||
}
|
||||
|
||||
Potree = {};
|
||||
|
||||
|
||||
onmessage = function(event){
|
||||
|
||||
let start = new Date().getTime();
|
||||
|
||||
onmessage = function (event) {
|
||||
let buffer = event.data.buffer;
|
||||
let pointAttributes = event.data.pointAttributes;
|
||||
let numPoints = buffer.byteLength / pointAttributes.byteSize;
|
||||
let cv = new CustomView(buffer);
|
||||
//let cv = new DataView(buffer);
|
||||
// let cv = new DataView(buffer);
|
||||
let version = new Potree.Version(event.data.version);
|
||||
let min = event.data.min;
|
||||
// event.data.min
|
||||
let nodeOffset = event.data.offset;
|
||||
let scale = event.data.scale;
|
||||
let tightBoxMin = [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY];
|
||||
let tightBoxMax = [ Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY ];
|
||||
let tightBoxMin = [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY ];
|
||||
let tightBoxMax = [ Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY ];
|
||||
|
||||
let attributeBuffers = {};
|
||||
|
||||
|
||||
let mean = [0, 0, 0];
|
||||
|
||||
let offset = 0;
|
||||
for(let i = 0; i < pointAttributes.attributes.length; i++){
|
||||
for (let i = 0; i < pointAttributes.attributes.length; i++) {
|
||||
let pointAttribute = pointAttributes.attributes[i];
|
||||
|
||||
if(pointAttribute.name === Potree.PointAttribute.POSITION_CARTESIAN.name){
|
||||
|
||||
let buff = new ArrayBuffer(numPoints*4*3);
|
||||
if (pointAttribute.name === Potree.PointAttribute.POSITION_CARTESIAN.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let positions = new Float32Array(buff);
|
||||
|
||||
let startPos = new Date().getTime();
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
let x, y, z;
|
||||
|
||||
if(version.newerThan("1.3")){
|
||||
x = (cv.getUint32(offset + j*pointAttributes.byteSize+0, true) * scale);
|
||||
y = (cv.getUint32(offset + j*pointAttributes.byteSize+4, true) * scale);
|
||||
z = (cv.getUint32(offset + j*pointAttributes.byteSize+8, true) * scale);
|
||||
}else{
|
||||
x = cv.getFloat32(j*pointAttributes.byteSize+0, true) + nodeOffset[0];
|
||||
y = cv.getFloat32(j*pointAttributes.byteSize+4, true) + nodeOffset[1];
|
||||
z = cv.getFloat32(j*pointAttributes.byteSize+8, true) + nodeOffset[2];
|
||||
|
||||
if (version.newerThan('1.3')) {
|
||||
x = (cv.getUint32(offset + j * pointAttributes.byteSize + 0, true) * scale);
|
||||
y = (cv.getUint32(offset + j * pointAttributes.byteSize + 4, true) * scale);
|
||||
z = (cv.getUint32(offset + j * pointAttributes.byteSize + 8, true) * scale);
|
||||
} else {
|
||||
x = cv.getFloat32(j * pointAttributes.byteSize + 0, true) + nodeOffset[0];
|
||||
y = cv.getFloat32(j * pointAttributes.byteSize + 4, true) + nodeOffset[1];
|
||||
z = cv.getFloat32(j * pointAttributes.byteSize + 8, true) + nodeOffset[2];
|
||||
}
|
||||
|
||||
positions[3*j+0] = x;
|
||||
positions[3*j+1] = y;
|
||||
positions[3*j+2] = z;
|
||||
|
||||
|
||||
positions[3 * j + 0] = x;
|
||||
positions[3 * j + 1] = y;
|
||||
positions[3 * j + 2] = z;
|
||||
|
||||
mean[0] += x / numPoints;
|
||||
mean[1] += y / numPoints;
|
||||
mean[2] += z / numPoints;
|
||||
|
||||
tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3*j+0]);
|
||||
tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3*j+1]);
|
||||
tightBoxMin[2] = Math.min(tightBoxMin[2], positions[3*j+2]);
|
||||
tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3 * j + 0]);
|
||||
tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3 * j + 1]);
|
||||
tightBoxMin[2] = Math.min(tightBoxMin[2], positions[3 * j + 2]);
|
||||
|
||||
tightBoxMax[0] = Math.max(tightBoxMax[0], positions[3*j+0]);
|
||||
tightBoxMax[1] = Math.max(tightBoxMax[1], positions[3*j+1]);
|
||||
tightBoxMax[2] = Math.max(tightBoxMax[2], positions[3*j+2]);
|
||||
tightBoxMax[0] = Math.max(tightBoxMax[0], positions[3 * j + 0]);
|
||||
tightBoxMax[1] = Math.max(tightBoxMax[1], positions[3 * j + 1]);
|
||||
tightBoxMax[2] = Math.max(tightBoxMax[2], positions[3 * j + 2]);
|
||||
}
|
||||
let endPos = new Date().getTime();
|
||||
let duration = endPos - startPos;
|
||||
//console.log(`duration pos: ${duration}ms`);
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.COLOR_PACKED.name){
|
||||
let buff = new ArrayBuffer(numPoints*3);
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.COLOR_PACKED.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 3);
|
||||
let colors = new Uint8Array(buff);
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
colors[3*j+0] = cv.getUint8(offset + j*pointAttributes.byteSize + 0);
|
||||
colors[3*j+1] = cv.getUint8(offset + j*pointAttributes.byteSize + 1);
|
||||
colors[3*j+2] = cv.getUint8(offset + j*pointAttributes.byteSize + 2);
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
colors[3 * j + 0] = cv.getUint8(offset + j * pointAttributes.byteSize + 0);
|
||||
colors[3 * j + 1] = cv.getUint8(offset + j * pointAttributes.byteSize + 1);
|
||||
colors[3 * j + 2] = cv.getUint8(offset + j * pointAttributes.byteSize + 2);
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.INTENSITY.name){
|
||||
|
||||
let buff = new ArrayBuffer(numPoints*4);
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.INTENSITY.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let intensities = new Float32Array(buff);
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
let intensity = cv.getUint16(offset + j*pointAttributes.byteSize, true);
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
let intensity = cv.getUint16(offset + j * pointAttributes.byteSize, true);
|
||||
intensities[j] = intensity;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.CLASSIFICATION.name){
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.CLASSIFICATION.name) {
|
||||
let buff = new ArrayBuffer(numPoints);
|
||||
let classifications = new Uint8Array(buff);
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
let classification = cv.getUint8(offset + j*pointAttributes.byteSize);
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
let classification = cv.getUint8(offset + j * pointAttributes.byteSize);
|
||||
classifications[j] = classification;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.NORMAL_SPHEREMAPPED.name){
|
||||
|
||||
let buff = new ArrayBuffer(numPoints*4*3);
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.NORMAL_SPHEREMAPPED.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let normals = new Float32Array(buff);
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
let bx = cv.getUint8(offset + j * pointAttributes.byteSize + 0);
|
||||
let by = cv.getUint8(offset + j * pointAttributes.byteSize + 1);
|
||||
|
||||
@ -161,17 +145,16 @@ onmessage = function(event){
|
||||
ny = ny * 2;
|
||||
nz = nz * 2 - 1;
|
||||
|
||||
normals[3*j + 0] = nx;
|
||||
normals[3*j + 1] = ny;
|
||||
normals[3*j + 2] = nz;
|
||||
normals[3 * j + 0] = nx;
|
||||
normals[3 * j + 1] = ny;
|
||||
normals[3 * j + 2] = nz;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.NORMAL_OCT16.name){
|
||||
|
||||
let buff = new ArrayBuffer(numPoints*4*3);
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.NORMAL_OCT16.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let normals = new Float32Array(buff);
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
let bx = cv.getUint8(offset + j * pointAttributes.byteSize + 0);
|
||||
let by = cv.getUint8(offset + j * pointAttributes.byteSize + 1);
|
||||
|
||||
@ -182,60 +165,59 @@ onmessage = function(event){
|
||||
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
if(z >= 0){
|
||||
if (z >= 0) {
|
||||
x = u;
|
||||
y = v;
|
||||
}else{
|
||||
x = - (v/Math.sign(v) - 1) / Math.sign(u);
|
||||
y = - (u/Math.sign(u) - 1) / Math.sign(v);
|
||||
} else {
|
||||
x = -(v / Math.sign(v) - 1) / Math.sign(u);
|
||||
y = -(u / Math.sign(u) - 1) / Math.sign(v);
|
||||
}
|
||||
|
||||
let length = Math.sqrt(x*x + y*y + z*z);
|
||||
let length = Math.sqrt(x * x + y * y + z * z);
|
||||
x = x / length;
|
||||
y = y / length;
|
||||
z = z / length;
|
||||
|
||||
normals[3*j + 0] = x;
|
||||
normals[3*j + 1] = y;
|
||||
normals[3*j + 2] = z;
|
||||
normals[3 * j + 0] = x;
|
||||
normals[3 * j + 1] = y;
|
||||
normals[3 * j + 2] = z;
|
||||
}
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.NORMAL.name){
|
||||
|
||||
let buff = new ArrayBuffer(numPoints*4*3);
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.NORMAL.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let normals = new Float32Array(buff);
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
let x = cv.getFloat32(offset + j * pointAttributes.byteSize + 0, true);
|
||||
let y = cv.getFloat32(offset + j * pointAttributes.byteSize + 4, true);
|
||||
let z = cv.getFloat32(offset + j * pointAttributes.byteSize + 8, true);
|
||||
|
||||
normals[3*j + 0] = x;
|
||||
normals[3*j + 1] = y;
|
||||
normals[3*j + 2] = z;
|
||||
normals[3 * j + 0] = x;
|
||||
normals[3 * j + 1] = y;
|
||||
normals[3 * j + 2] = z;
|
||||
}
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
}
|
||||
|
||||
offset += pointAttribute.byteSize;
|
||||
}
|
||||
|
||||
let indices = new ArrayBuffer(numPoints*4);
|
||||
let indices = new ArrayBuffer(numPoints * 4);
|
||||
let iIndices = new Uint32Array(indices);
|
||||
for(let i = 0; i < numPoints; i++){
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
iIndices[i] = i;
|
||||
}
|
||||
|
||||
if(attributeBuffers[Potree.PointAttribute.CLASSIFICATION.name] === undefined){
|
||||
let buff = new ArrayBuffer(numPoints*4);
|
||||
|
||||
if (attributeBuffers[Potree.PointAttribute.CLASSIFICATION.name] === undefined) {
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let classifications = new Float32Array(buff);
|
||||
|
||||
for(let j = 0; j < numPoints; j++){
|
||||
|
||||
for (let j = 0; j < numPoints; j++) {
|
||||
classifications[j] = 0;
|
||||
}
|
||||
|
||||
attributeBuffers[Potree.PointAttribute.CLASSIFICATION.name] = { buffer: buff, attribute: Potree.PointAttribute.CLASSIFICATION};
|
||||
|
||||
attributeBuffers[Potree.PointAttribute.CLASSIFICATION.name] = { buffer: buff, attribute: Potree.PointAttribute.CLASSIFICATION };
|
||||
}
|
||||
|
||||
|
||||
let message = {
|
||||
mean: mean,
|
||||
attributeBuffers: attributeBuffers,
|
||||
@ -245,18 +227,13 @@ onmessage = function(event){
|
||||
|
||||
let transferables = [];
|
||||
|
||||
for(let property in message.attributeBuffers){
|
||||
if(message.attributeBuffers.hasOwnProperty(property)){
|
||||
for (let property in message.attributeBuffers) {
|
||||
if (message.attributeBuffers.hasOwnProperty(property)) {
|
||||
transferables.push(message.attributeBuffers[property].buffer);
|
||||
}
|
||||
}
|
||||
|
||||
transferables.push(message.indices);
|
||||
|
||||
let end = new Date().getTime();
|
||||
let duration = end - start;
|
||||
//console.log(`duration: ${duration}ms`);
|
||||
|
||||
postMessage(message, transferables);
|
||||
|
||||
};
|
||||
|
||||
@ -1,37 +1,35 @@
|
||||
|
||||
|
||||
onmessage = function(event){
|
||||
let start = new Date().getTime();
|
||||
|
||||
/* global onmessage:true postMessage:false */
|
||||
/* exported onmessage */
|
||||
onmessage = function (event) {
|
||||
let boundingBox = event.data.boundingBox;
|
||||
let position = new Float32Array(event.data.position);
|
||||
let width = 64;
|
||||
let height = 64;
|
||||
let numPoints = position.length / 3;
|
||||
|
||||
|
||||
let boxSize = {
|
||||
x: boundingBox.max[0] - boundingBox.min[0],
|
||||
y: boundingBox.max[1] - boundingBox.min[1],
|
||||
z: boundingBox.max[2] - boundingBox.min[2]
|
||||
};
|
||||
|
||||
|
||||
let dem = new Float32Array(width * height);
|
||||
dem.fill(-Infinity);
|
||||
for(let i = 0; i < numPoints; i++){
|
||||
let x = position[3*i + 0];
|
||||
let y = position[3*i + 1];
|
||||
let z = position[3*i + 2];
|
||||
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
let x = position[3 * i + 0];
|
||||
let y = position[3 * i + 1];
|
||||
let z = position[3 * i + 2];
|
||||
|
||||
let dx = x / boxSize.x;
|
||||
let dy = y / boxSize.y;
|
||||
|
||||
|
||||
let ix = parseInt(Math.min(width * dx, width - 1));
|
||||
let iy = parseInt(Math.min(height * dy, height - 1));
|
||||
|
||||
|
||||
let index = ix + width * iy;
|
||||
dem[index] = z;
|
||||
}
|
||||
|
||||
|
||||
let message = {
|
||||
dem: {
|
||||
width: width,
|
||||
@ -39,11 +37,6 @@ onmessage = function(event){
|
||||
data: dem.buffer
|
||||
}
|
||||
};
|
||||
|
||||
let end = new Date().getTime();
|
||||
let duration = end - start;
|
||||
//console.log(`duration: ${duration}ms`);
|
||||
|
||||
|
||||
postMessage(message, [message.dem.data]);
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
/* global onmessage:true postMessage:false Module */
|
||||
/* exported onmessage */
|
||||
// http://jsperf.com/uint8array-vs-dataview3/3
|
||||
function CustomView(buffer) {
|
||||
function CustomView (buffer) {
|
||||
this.buffer = buffer;
|
||||
this.u8 = new Uint8Array(buffer);
|
||||
|
||||
@ -8,197 +10,185 @@ function CustomView(buffer) {
|
||||
var tmpu8 = new Uint8Array(tmp);
|
||||
|
||||
this.getUint32 = function (i) {
|
||||
return (this.u8[i+3] << 24) | (this.u8[i+2] << 16) | (this.u8[i+1] << 8) | this.u8[i];
|
||||
return (this.u8[i + 3] << 24) | (this.u8[i + 2] << 16) | (this.u8[i + 1] << 8) | this.u8[i];
|
||||
};
|
||||
|
||||
this.getUint16 = function (i) {
|
||||
return (this.u8[i+1] << 8) | this.u8[i];
|
||||
return (this.u8[i + 1] << 8) | this.u8[i];
|
||||
};
|
||||
|
||||
this.getFloat = function(i){
|
||||
tmpu8[0] = this.u8[i+0];
|
||||
tmpu8[1] = this.u8[i+1];
|
||||
tmpu8[2] = this.u8[i+2];
|
||||
tmpu8[3] = this.u8[i+3];
|
||||
this.getFloat = function (i) {
|
||||
tmpu8[0] = this.u8[i + 0];
|
||||
tmpu8[1] = this.u8[i + 1];
|
||||
tmpu8[2] = this.u8[i + 2];
|
||||
tmpu8[3] = this.u8[i + 3];
|
||||
|
||||
return tmpf[0];
|
||||
};
|
||||
|
||||
this.getUint8 = function(i){
|
||||
this.getUint8 = function (i) {
|
||||
return this.u8[i];
|
||||
};
|
||||
}
|
||||
|
||||
function networkToNative(val) {
|
||||
return ((val & 0x00FF) << 24) |
|
||||
((val & 0xFF00) << 8) |
|
||||
((val >> 8) & 0xFF00) |
|
||||
((val >> 24) & 0x00FF);
|
||||
function networkToNative (val) {
|
||||
return ((val & 0x00FF) << 24) |
|
||||
((val & 0xFF00) << 8) |
|
||||
((val >> 8) & 0xFF00) |
|
||||
((val >> 24) & 0x00FF);
|
||||
}
|
||||
|
||||
var decompress = function(schema, input, numPoints) {
|
||||
var x = new Module.DynamicLASZip();
|
||||
var decompress = function (schema, input, numPoints) {
|
||||
var x = new Module.DynamicLASZip();
|
||||
|
||||
var abInt = new Uint8Array(input);
|
||||
var buf = Module._malloc(input.byteLength);
|
||||
var abInt = new Uint8Array(input);
|
||||
var buf = Module._malloc(input.byteLength);
|
||||
|
||||
Module.HEAPU8.set(abInt, buf);
|
||||
x.open(buf, input.byteLength);
|
||||
Module.HEAPU8.set(abInt, buf);
|
||||
x.open(buf, input.byteLength);
|
||||
|
||||
var pointSize = 0;
|
||||
var pointSize = 0;
|
||||
|
||||
schema.forEach(function(f) {
|
||||
pointSize += f.size;
|
||||
if (f.type === "floating") x.addFieldFloating(f.size);
|
||||
else if (f.type === "unsigned") x.addFieldUnsigned(f.size);
|
||||
else if (f.type === "signed") x.addFieldSigned(f.size);
|
||||
else throw new Error("Unrecognized field desc:", f);
|
||||
});
|
||||
schema.forEach(function (f) {
|
||||
pointSize += f.size;
|
||||
if (f.type === 'floating') x.addFieldFloating(f.size);
|
||||
else if (f.type === 'unsigned') x.addFieldUnsigned(f.size);
|
||||
else if (f.type === 'signed') x.addFieldSigned(f.size);
|
||||
else throw new Error('Unrecognized field desc:', f);
|
||||
});
|
||||
|
||||
var out = Module._malloc(numPoints * pointSize);
|
||||
var out = Module._malloc(numPoints * pointSize);
|
||||
|
||||
for (var i = 0 ; i < numPoints ; i ++) {
|
||||
x.getPoint(out + i * pointSize);
|
||||
}
|
||||
for (var i = 0; i < numPoints; i++) {
|
||||
x.getPoint(out + i * pointSize);
|
||||
}
|
||||
|
||||
var ret = new Uint8Array(numPoints * pointSize);
|
||||
ret.set(Module.HEAPU8.subarray(out, out + numPoints * pointSize));
|
||||
var ret = new Uint8Array(numPoints * pointSize);
|
||||
ret.set(Module.HEAPU8.subarray(out, out + numPoints * pointSize));
|
||||
|
||||
Module._free(out);
|
||||
Module._free(buf);
|
||||
Module._free(out);
|
||||
Module._free(buf);
|
||||
|
||||
return ret.buffer;
|
||||
}
|
||||
return ret.buffer;
|
||||
};
|
||||
|
||||
Potree = {};
|
||||
|
||||
|
||||
onmessage = function(event){
|
||||
onmessage = function (event) {
|
||||
var NUM_POINTS_BYTES = 4;
|
||||
|
||||
var buffer = event.data.buffer;
|
||||
var pointAttributes = event.data.pointAttributes;
|
||||
|
||||
var view = new DataView(
|
||||
buffer, buffer.byteLength - NUM_POINTS_BYTES, NUM_POINTS_BYTES);
|
||||
var numPoints = networkToNative(view.getUint32(0));
|
||||
buffer = buffer.slice(0, buffer.byteLength - NUM_POINTS_BYTES);
|
||||
var view = new DataView(
|
||||
buffer, buffer.byteLength - NUM_POINTS_BYTES, NUM_POINTS_BYTES);
|
||||
var numPoints = networkToNative(view.getUint32(0));
|
||||
buffer = buffer.slice(0, buffer.byteLength - NUM_POINTS_BYTES);
|
||||
|
||||
buffer = decompress(event.data.schema, buffer, numPoints);
|
||||
buffer = decompress(event.data.schema, buffer, numPoints);
|
||||
|
||||
var cv = new CustomView(buffer);
|
||||
var version = new Potree.Version(event.data.version);
|
||||
var min = event.data.min;
|
||||
var max = event.data.max;
|
||||
// event.data.version
|
||||
// event.data.min
|
||||
// event.data.max
|
||||
var nodeOffset = event.data.offset;
|
||||
var scale = event.data.scale;
|
||||
var tightBoxMin = [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY];
|
||||
var tightBoxMin = [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY ];
|
||||
var tightBoxMax = [ Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY ];
|
||||
|
||||
var attributeBuffers = {};
|
||||
var offset = 0;
|
||||
var pointSize = pointAttributes.byteSize;
|
||||
|
||||
var pointSize = pointAttributes.byteSize;
|
||||
|
||||
let mean = [0, 0, 0];
|
||||
|
||||
var logged = 0;
|
||||
|
||||
for(var i = 0; i < pointAttributes.attributes.length; i++){
|
||||
for (let i = 0; i < pointAttributes.attributes.length; i++) {
|
||||
var pointAttribute = pointAttributes.attributes[i];
|
||||
|
||||
if(pointAttribute.name === Potree.PointAttribute.POSITION_CARTESIAN.name){
|
||||
var buff = new ArrayBuffer(numPoints*4*3);
|
||||
var positions = new Float32Array(buff);
|
||||
if (pointAttribute.name === Potree.PointAttribute.POSITION_CARTESIAN.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let positions = new Float32Array(buff);
|
||||
|
||||
for (var j = 0; j < numPoints; ++j) {
|
||||
|
||||
let ux = cv.getUint32(offset + j*pointSize+0);
|
||||
let uy = cv.getUint32(offset + j*pointSize+4);
|
||||
let uz = cv.getUint32(offset + j*pointSize+8);
|
||||
for (let j = 0; j < numPoints; ++j) {
|
||||
let ux = cv.getUint32(offset + j * pointSize + 0);
|
||||
let uy = cv.getUint32(offset + j * pointSize + 4);
|
||||
let uz = cv.getUint32(offset + j * pointSize + 8);
|
||||
|
||||
let x = (scale * ux) + nodeOffset[0];
|
||||
let y = (scale * uy) + nodeOffset[1];
|
||||
let z = (scale * uz) + nodeOffset[2];
|
||||
|
||||
positions[3*j+0] = x;
|
||||
positions[3*j+1] = y;
|
||||
positions[3*j+2] = z;
|
||||
|
||||
positions[3 * j + 0] = x;
|
||||
positions[3 * j + 1] = y;
|
||||
positions[3 * j + 2] = z;
|
||||
|
||||
mean[0] += x / numPoints;
|
||||
mean[1] += y / numPoints;
|
||||
mean[2] += z / numPoints;
|
||||
|
||||
tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3*j+0]);
|
||||
tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3*j+1]);
|
||||
tightBoxMin[2] = Math.min(tightBoxMin[2], positions[3*j+2]);
|
||||
tightBoxMin[0] = Math.min(tightBoxMin[0], positions[3 * j + 0]);
|
||||
tightBoxMin[1] = Math.min(tightBoxMin[1], positions[3 * j + 1]);
|
||||
tightBoxMin[2] = Math.min(tightBoxMin[2], positions[3 * j + 2]);
|
||||
|
||||
tightBoxMax[0] = Math.max(tightBoxMax[0], positions[3*j+0]);
|
||||
tightBoxMax[1] = Math.max(tightBoxMax[1], positions[3*j+1]);
|
||||
tightBoxMax[2] = Math.max(tightBoxMax[2], positions[3*j+2]);
|
||||
tightBoxMax[0] = Math.max(tightBoxMax[0], positions[3 * j + 0]);
|
||||
tightBoxMax[1] = Math.max(tightBoxMax[1], positions[3 * j + 1]);
|
||||
tightBoxMax[2] = Math.max(tightBoxMax[2], positions[3 * j + 2]);
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.COLOR_PACKED.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 3);
|
||||
let colors = new Uint8Array(buff);
|
||||
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.COLOR_PACKED.name){
|
||||
let div = event.data.normalize.color ? 256 : 1;
|
||||
|
||||
var buff = new ArrayBuffer(numPoints*3);
|
||||
var colors = new Uint8Array(buff);
|
||||
|
||||
var div = event.data.normalize.color ? 256 : 1;
|
||||
|
||||
for(var j = 0; j < numPoints; ++j){
|
||||
colors[3*j+0] = cv.getUint16(offset + j*pointSize + 0) / div;
|
||||
colors[3*j+1] = cv.getUint16(offset + j*pointSize + 2) / div;
|
||||
colors[3*j+2] = cv.getUint16(offset + j*pointSize + 4) / div;
|
||||
for (let j = 0; j < numPoints; ++j) {
|
||||
colors[3 * j + 0] = cv.getUint16(offset + j * pointSize + 0) / div;
|
||||
colors[3 * j + 1] = cv.getUint16(offset + j * pointSize + 2) / div;
|
||||
colors[3 * j + 2] = cv.getUint16(offset + j * pointSize + 4) / div;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.INTENSITY.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let intensities = new Float32Array(buff);
|
||||
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.INTENSITY.name){
|
||||
|
||||
var buff = new ArrayBuffer(numPoints*4);
|
||||
var intensities = new Float32Array(buff);
|
||||
|
||||
for(var j = 0; j < numPoints; ++j){
|
||||
var intensity = cv.getUint16(offset + j*pointSize);
|
||||
//if (event.data.normalize.intensity) {
|
||||
// intensity = Math.floor(intensity / 256);
|
||||
//}
|
||||
for (let j = 0; j < numPoints; ++j) {
|
||||
var intensity = cv.getUint16(offset + j * pointSize);
|
||||
// if (event.data.normalize.intensity) {
|
||||
// intensity = Math.floor(intensity / 256);
|
||||
// }
|
||||
intensities[j] = intensity;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.CLASSIFICATION.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4);
|
||||
let classifications = new Float32Array(buff);
|
||||
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.CLASSIFICATION.name){
|
||||
|
||||
var buff = new ArrayBuffer(numPoints*4);
|
||||
var classifications = new Float32Array(buff);
|
||||
|
||||
for(var j = 0; j < numPoints; ++j){
|
||||
var classification = cv.getUint8(offset + j*pointSize);
|
||||
for (let j = 0; j < numPoints; ++j) {
|
||||
var classification = cv.getUint8(offset + j * pointSize);
|
||||
classifications[j] = classification;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.NORMAL_SPHEREMAPPED.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let normals = new Float32Array(buff);
|
||||
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.NORMAL_SPHEREMAPPED.name){
|
||||
for (let j = 0; j < numPoints; ++j) {
|
||||
let bx = cv.getUint8(offset + j * pointSize + 0);
|
||||
let by = cv.getUint8(offset + j * pointSize + 1);
|
||||
|
||||
var buff = new ArrayBuffer(numPoints*4*3);
|
||||
var normals = new Float32Array(buff);
|
||||
let ex = bx / 255;
|
||||
let ey = by / 255;
|
||||
|
||||
for(var j = 0; j < numPoints; ++j){
|
||||
var bx = cv.getUint8(offset + j * pointSize + 0);
|
||||
var by = cv.getUint8(offset + j * pointSize + 1);
|
||||
let nx = ex * 2 - 1;
|
||||
let ny = ey * 2 - 1;
|
||||
let nz = 1;
|
||||
let nw = -1;
|
||||
|
||||
var ex = bx / 255;
|
||||
var ey = by / 255;
|
||||
|
||||
var nx = ex * 2 - 1;
|
||||
var ny = ey * 2 - 1;
|
||||
var nz = 1;
|
||||
var nw = -1;
|
||||
|
||||
var l = (nx * (-nx)) + (ny * (-ny)) + (nz * (-nw));
|
||||
let l = (nx * (-nx)) + (ny * (-ny)) + (nz * (-nw));
|
||||
nz = l;
|
||||
nx = nx * Math.sqrt(l);
|
||||
ny = ny * Math.sqrt(l);
|
||||
@ -207,67 +197,65 @@ onmessage = function(event){
|
||||
ny = ny * 2;
|
||||
nz = nz * 2 - 1;
|
||||
|
||||
normals[3*j + 0] = nx;
|
||||
normals[3*j + 1] = ny;
|
||||
normals[3*j + 2] = nz;
|
||||
normals[3 * j + 0] = nx;
|
||||
normals[3 * j + 1] = ny;
|
||||
normals[3 * j + 2] = nz;
|
||||
}
|
||||
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.NORMAL_OCT16.name){
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.NORMAL_OCT16.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let normals = new Float32Array(buff);
|
||||
for (let j = 0; j < numPoints; ++j) {
|
||||
let bx = cv.getUint8(offset + j * pointSize + 0);
|
||||
let by = cv.getUint8(offset + j * pointSize + 1);
|
||||
|
||||
var buff = new ArrayBuffer(numPoints*4*3);
|
||||
var normals = new Float32Array(buff);
|
||||
for(var j = 0; j < numPoints; ++j){
|
||||
var bx = cv.getUint8(offset + j * pointSize + 0);
|
||||
var by = cv.getUint8(offset + j * pointSize + 1);
|
||||
let u = (bx / 255) * 2 - 1;
|
||||
let v = (by / 255) * 2 - 1;
|
||||
|
||||
var u = (bx / 255) * 2 - 1;
|
||||
var v = (by / 255) * 2 - 1;
|
||||
let z = 1 - Math.abs(u) - Math.abs(v);
|
||||
|
||||
var z = 1 - Math.abs(u) - Math.abs(v);
|
||||
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
if(z >= 0){
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
if (z >= 0) {
|
||||
x = u;
|
||||
y = v;
|
||||
}else{
|
||||
x = - (v/Math.sign(v) - 1) / Math.sign(u);
|
||||
y = - (u/Math.sign(u) - 1) / Math.sign(v);
|
||||
} else {
|
||||
x = -(v / Math.sign(v) - 1) / Math.sign(u);
|
||||
y = -(u / Math.sign(u) - 1) / Math.sign(v);
|
||||
}
|
||||
|
||||
var length = Math.sqrt(x*x + y*y + z*z);
|
||||
var length = Math.sqrt(x * x + y * y + z * z);
|
||||
x = x / length;
|
||||
y = y / length;
|
||||
z = z / length;
|
||||
|
||||
normals[3*j + 0] = x;
|
||||
normals[3*j + 1] = y;
|
||||
normals[3*j + 2] = z;
|
||||
normals[3 * j + 0] = x;
|
||||
normals[3 * j + 1] = y;
|
||||
normals[3 * j + 2] = z;
|
||||
}
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
}else if(pointAttribute.name === Potree.PointAttribute.NORMAL.name){
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
} else if (pointAttribute.name === Potree.PointAttribute.NORMAL.name) {
|
||||
let buff = new ArrayBuffer(numPoints * 4 * 3);
|
||||
let normals = new Float32Array(buff);
|
||||
for (var j = 0; j < numPoints; ++j) {
|
||||
let x = cv.getFloat(offset + j * pointSize + 0);
|
||||
let y = cv.getFloat(offset + j * pointSize + 4);
|
||||
let z = cv.getFloat(offset + j * pointSize + 8);
|
||||
|
||||
var buff = new ArrayBuffer(numPoints*4*3);
|
||||
var normals = new Float32Array(buff);
|
||||
for(var j = 0; j < numPoints; ++j){
|
||||
var x = cv.getFloat(offset + j * pointSize + 0);
|
||||
var y = cv.getFloat(offset + j * pointSize + 4);
|
||||
var z = cv.getFloat(offset + j * pointSize + 8);
|
||||
|
||||
normals[3*j + 0] = x;
|
||||
normals[3*j + 1] = y;
|
||||
normals[3*j + 2] = z;
|
||||
normals[3 * j + 0] = x;
|
||||
normals[3 * j + 1] = y;
|
||||
normals[3 * j + 2] = z;
|
||||
}
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute};
|
||||
attributeBuffers[pointAttribute.name] = { buffer: buff, attribute: pointAttribute };
|
||||
}
|
||||
|
||||
offset += pointAttribute.byteSize;
|
||||
}
|
||||
|
||||
var indices = new ArrayBuffer(numPoints*4);
|
||||
var indices = new ArrayBuffer(numPoints * 4);
|
||||
var iIndices = new Uint32Array(indices);
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
iIndices[i] = i;
|
||||
}
|
||||
|
||||
@ -280,8 +268,8 @@ onmessage = function(event){
|
||||
|
||||
var transferables = [];
|
||||
|
||||
for(var property in message.attributeBuffers){
|
||||
if(message.attributeBuffers.hasOwnProperty(property)){
|
||||
for (var property in message.attributeBuffers) {
|
||||
if (message.attributeBuffers.hasOwnProperty(property)) {
|
||||
transferables.push(message.attributeBuffers[property].buffer);
|
||||
}
|
||||
}
|
||||
@ -289,5 +277,4 @@ onmessage = function(event){
|
||||
transferables.push(message.indices);
|
||||
|
||||
postMessage(message, transferables);
|
||||
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
//var pointFormatReaders = {
|
||||
/* global onmessage:true postMessage:false */
|
||||
/* exported onmessage */
|
||||
// var pointFormatReaders = {
|
||||
// 0: function(dv) {
|
||||
// return {
|
||||
// "position": [ dv.getInt32(0, true), dv.getInt32(4, true), dv.getInt32(8, true)],
|
||||
@ -31,53 +31,52 @@
|
||||
// "color": [dv.getUint16(28, true), dv.getUint16(30, true), dv.getUint16(32, true)]
|
||||
// };
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//
|
||||
// };
|
||||
//
|
||||
//
|
||||
// Decodes LAS records into points
|
||||
//
|
||||
//var LASDecoder = function(buffer, pointFormatID, pointSize, pointsCount, scale, offset) {
|
||||
// var LASDecoder = function(buffer, pointFormatID, pointSize, pointsCount, scale, offset) {
|
||||
// this.arrayb = buffer;
|
||||
// this.decoder = pointFormatReaders[pointFormatID];
|
||||
// this.pointsCount = pointsCount;
|
||||
// this.pointSize = pointSize;
|
||||
// this.scale = scale;
|
||||
// this.offset = offset;
|
||||
//};
|
||||
// };
|
||||
//
|
||||
//LASDecoder.prototype.getPoint = function(index) {
|
||||
// LASDecoder.prototype.getPoint = function(index) {
|
||||
// if (index < 0 || index >= this.pointsCount)
|
||||
// throw new Error("Point index out of range");
|
||||
//
|
||||
// var dv = new DataView(this.arrayb, index * this.pointSize, this.pointSize);
|
||||
// return this.decoder(dv);
|
||||
//};
|
||||
// };
|
||||
|
||||
onmessage = function(event){
|
||||
onmessage = function (event) {
|
||||
var buffer = event.data.buffer;
|
||||
var numPoints = event.data.numPoints;
|
||||
var pointSize = event.data.pointSize;
|
||||
var pointFormatID = event.data.pointFormatID;
|
||||
var scale = event.data.scale;
|
||||
var offset = event.data.offset;
|
||||
var mins = event.data.mins;
|
||||
var maxs = event.data.maxs;
|
||||
|
||||
// event.data.mins
|
||||
// event.data.maxs
|
||||
|
||||
var temp = new ArrayBuffer(4);
|
||||
var tempUint8 = new Uint8Array(temp);
|
||||
var tempUint16 = new Uint16Array(temp);
|
||||
var tempFloat32 = new Float32Array(temp);
|
||||
var tempInt32 = new Int32Array(temp);
|
||||
var bufferView = new Uint8Array(buffer);
|
||||
|
||||
var pBuff = new ArrayBuffer(numPoints*3*4);
|
||||
var cBuff = new ArrayBuffer(numPoints*3);
|
||||
var iBuff = new ArrayBuffer(numPoints*4);
|
||||
|
||||
var pBuff = new ArrayBuffer(numPoints * 3 * 4);
|
||||
var cBuff = new ArrayBuffer(numPoints * 3);
|
||||
var iBuff = new ArrayBuffer(numPoints * 4);
|
||||
var clBuff = new ArrayBuffer(numPoints);
|
||||
var rnBuff = new ArrayBuffer(numPoints);
|
||||
var nrBuff = new ArrayBuffer(numPoints);
|
||||
var psBuff = new ArrayBuffer(numPoints * 2);
|
||||
|
||||
|
||||
var positions = new Float32Array(pBuff);
|
||||
var colors = new Uint8Array(cBuff);
|
||||
var intensities = new Float32Array(iBuff);
|
||||
@ -86,109 +85,107 @@ onmessage = function(event){
|
||||
var numberOfReturns = new Uint8Array(nrBuff);
|
||||
var pointSourceIDs = new Uint16Array(psBuff);
|
||||
var tightBoundingBox = {
|
||||
min: [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY],
|
||||
max: [ Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY , Number.NEGATIVE_INFINITY ]
|
||||
min: [ Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY ],
|
||||
max: [ Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY ]
|
||||
};
|
||||
|
||||
|
||||
let mean = [0, 0, 0];
|
||||
|
||||
|
||||
|
||||
// temp arrays seem to be significantly faster than DataViews
|
||||
// at the moment: http://jsperf.com/dataview-vs-temporary-float64array
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
// POSITION
|
||||
tempUint8[0] = bufferView[i*pointSize+0];
|
||||
tempUint8[1] = bufferView[i*pointSize+1];
|
||||
tempUint8[2] = bufferView[i*pointSize+2];
|
||||
tempUint8[3] = bufferView[i*pointSize+3];
|
||||
tempUint8[0] = bufferView[i * pointSize + 0];
|
||||
tempUint8[1] = bufferView[i * pointSize + 1];
|
||||
tempUint8[2] = bufferView[i * pointSize + 2];
|
||||
tempUint8[3] = bufferView[i * pointSize + 3];
|
||||
var x = tempInt32[0];
|
||||
|
||||
tempUint8[0] = bufferView[i*pointSize+4];
|
||||
tempUint8[1] = bufferView[i*pointSize+5];
|
||||
tempUint8[2] = bufferView[i*pointSize+6];
|
||||
tempUint8[3] = bufferView[i*pointSize+7];
|
||||
|
||||
tempUint8[0] = bufferView[i * pointSize + 4];
|
||||
tempUint8[1] = bufferView[i * pointSize + 5];
|
||||
tempUint8[2] = bufferView[i * pointSize + 6];
|
||||
tempUint8[3] = bufferView[i * pointSize + 7];
|
||||
var y = tempInt32[0];
|
||||
|
||||
tempUint8[0] = bufferView[i*pointSize+8];
|
||||
tempUint8[1] = bufferView[i*pointSize+9];
|
||||
tempUint8[2] = bufferView[i*pointSize+10];
|
||||
tempUint8[3] = bufferView[i*pointSize+11];
|
||||
|
||||
tempUint8[0] = bufferView[i * pointSize + 8];
|
||||
tempUint8[1] = bufferView[i * pointSize + 9];
|
||||
tempUint8[2] = bufferView[i * pointSize + 10];
|
||||
tempUint8[3] = bufferView[i * pointSize + 11];
|
||||
var z = tempInt32[0];
|
||||
|
||||
x = x * scale[0] + offset[0] - event.data.mins[0];
|
||||
y = y * scale[1] + offset[1] - event.data.mins[1];
|
||||
z = z * scale[2] + offset[2] - event.data.mins[2];
|
||||
|
||||
positions[3*i+0] = x;
|
||||
positions[3*i+1] = y;
|
||||
positions[3*i+2] = z;
|
||||
|
||||
|
||||
x = x * scale[0] + offset[0] - event.data.mins[0];
|
||||
y = y * scale[1] + offset[1] - event.data.mins[1];
|
||||
z = z * scale[2] + offset[2] - event.data.mins[2];
|
||||
|
||||
positions[3 * i + 0] = x;
|
||||
positions[3 * i + 1] = y;
|
||||
positions[3 * i + 2] = z;
|
||||
|
||||
mean[0] += x / numPoints;
|
||||
mean[1] += y / numPoints;
|
||||
mean[2] += z / numPoints;
|
||||
|
||||
tightBoundingBox.min[0] = Math.min(tightBoundingBox.min[0], positions[3*i+0]);
|
||||
tightBoundingBox.min[1] = Math.min(tightBoundingBox.min[1], positions[3*i+1]);
|
||||
tightBoundingBox.min[2] = Math.min(tightBoundingBox.min[2], positions[3*i+2]);
|
||||
|
||||
tightBoundingBox.max[0] = Math.max(tightBoundingBox.max[0], positions[3*i+0]);
|
||||
tightBoundingBox.max[1] = Math.max(tightBoundingBox.max[1], positions[3*i+1]);
|
||||
tightBoundingBox.max[2] = Math.max(tightBoundingBox.max[2], positions[3*i+2]);
|
||||
|
||||
|
||||
tightBoundingBox.min[0] = Math.min(tightBoundingBox.min[0], positions[3 * i + 0]);
|
||||
tightBoundingBox.min[1] = Math.min(tightBoundingBox.min[1], positions[3 * i + 1]);
|
||||
tightBoundingBox.min[2] = Math.min(tightBoundingBox.min[2], positions[3 * i + 2]);
|
||||
|
||||
tightBoundingBox.max[0] = Math.max(tightBoundingBox.max[0], positions[3 * i + 0]);
|
||||
tightBoundingBox.max[1] = Math.max(tightBoundingBox.max[1], positions[3 * i + 1]);
|
||||
tightBoundingBox.max[2] = Math.max(tightBoundingBox.max[2], positions[3 * i + 2]);
|
||||
|
||||
// INTENSITY
|
||||
tempUint8[0] = bufferView[i*pointSize+12];
|
||||
tempUint8[1] = bufferView[i*pointSize+13];
|
||||
tempUint8[0] = bufferView[i * pointSize + 12];
|
||||
tempUint8[1] = bufferView[i * pointSize + 13];
|
||||
var intensity = tempUint16[0];
|
||||
intensities[i] = intensity;
|
||||
|
||||
|
||||
// RETURN NUMBER, stored in the first 3 bits - 00000111
|
||||
var returnNumber = bufferView[i*pointSize+14] & 7;
|
||||
var returnNumber = bufferView[i * pointSize + 14] & 7;
|
||||
returnNumbers[i] = returnNumber;
|
||||
|
||||
|
||||
// NUMBER OF RETURNS, stored in 00111000
|
||||
numberOfReturns[i] = (bufferView[i*pointSize+14] & 56) / 8;
|
||||
|
||||
numberOfReturns[i] = (bufferView[i * pointSize + 14] & 56) / 8;
|
||||
|
||||
// CLASSIFICATION
|
||||
var classification = bufferView[i*pointSize+15];
|
||||
var classification = bufferView[i * pointSize + 15];
|
||||
classifications[i] = classification;
|
||||
|
||||
|
||||
// POINT SOURCE ID
|
||||
tempUint8[0] = bufferView[i*pointSize+18];
|
||||
tempUint8[1] = bufferView[i*pointSize+19];
|
||||
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){
|
||||
tempUint8[0] = bufferView[i*pointSize+20];
|
||||
tempUint8[1] = bufferView[i*pointSize+21];
|
||||
if (pointFormatID === 2) {
|
||||
tempUint8[0] = bufferView[i * pointSize + 20];
|
||||
tempUint8[1] = bufferView[i * pointSize + 21];
|
||||
var r = tempUint16[0];
|
||||
|
||||
tempUint8[0] = bufferView[i*pointSize+22];
|
||||
tempUint8[1] = bufferView[i*pointSize+23];
|
||||
|
||||
tempUint8[0] = bufferView[i * pointSize + 22];
|
||||
tempUint8[1] = bufferView[i * pointSize + 23];
|
||||
var g = tempUint16[0];
|
||||
|
||||
tempUint8[0] = bufferView[i*pointSize+24];
|
||||
tempUint8[1] = bufferView[i*pointSize+25];
|
||||
|
||||
tempUint8[0] = bufferView[i * pointSize + 24];
|
||||
tempUint8[1] = bufferView[i * pointSize + 25];
|
||||
var b = tempUint16[0];
|
||||
|
||||
colors[3*i+0] = r / 256;
|
||||
colors[3*i+1] = g / 256;
|
||||
colors[3*i+2] = b / 256;
|
||||
|
||||
colors[3 * i + 0] = r / 256;
|
||||
colors[3 * i + 1] = g / 256;
|
||||
colors[3 * i + 2] = b / 256;
|
||||
}
|
||||
}
|
||||
|
||||
var indices = new ArrayBuffer(numPoints*4);
|
||||
|
||||
var indices = new ArrayBuffer(numPoints * 4);
|
||||
var iIndices = new Uint32Array(indices);
|
||||
for(var i = 0; i < numPoints; i++){
|
||||
for (let i = 0; i < numPoints; i++) {
|
||||
iIndices[i] = i;
|
||||
}
|
||||
|
||||
|
||||
var message = {
|
||||
mean: mean,
|
||||
position: pBuff,
|
||||
color: cBuff,
|
||||
position: pBuff,
|
||||
color: cBuff,
|
||||
intensity: iBuff,
|
||||
classification: clBuff,
|
||||
returnNumber: rnBuff,
|
||||
@ -197,16 +194,16 @@ onmessage = function(event){
|
||||
tightBoundingBox: tightBoundingBox,
|
||||
indices: indices
|
||||
};
|
||||
|
||||
|
||||
var transferables = [
|
||||
message.position,
|
||||
message.color,
|
||||
message.color,
|
||||
message.intensity,
|
||||
message.classification,
|
||||
message.returnNumber,
|
||||
message.numberOfReturns,
|
||||
message.pointSourceID,
|
||||
message.indices];
|
||||
|
||||
|
||||
postMessage(message, transferables);
|
||||
};
|
||||
|
||||
@ -1,36 +1,36 @@
|
||||
/* global onmessage:true postMessage:false Module */
|
||||
/* exported onmessage */
|
||||
// laz-loader-worker.js
|
||||
//
|
||||
|
||||
//importScripts('laz-perf.js');
|
||||
// importScripts('laz-perf.js');
|
||||
|
||||
var instance = null; // laz-perf instance
|
||||
|
||||
function readAs(buf, Type, offset, count) {
|
||||
function readAs (buf, Type, offset, count) {
|
||||
count = (count === undefined || count === 0 ? 1 : count);
|
||||
var sub = buf.slice(offset, offset + Type.BYTES_PER_ELEMENT * count);
|
||||
|
||||
var r = new Type(sub);
|
||||
if (count === undefined || count === 1)
|
||||
return r[0];
|
||||
if (count === undefined || count === 1) { return r[0]; }
|
||||
|
||||
var ret = [];
|
||||
for (var i = 0 ; i < count ; i ++) {
|
||||
for (var i = 0; i < count; i++) {
|
||||
ret.push(r[i]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function parseLASHeader(arraybuffer) {
|
||||
function parseLASHeader (arraybuffer) {
|
||||
var o = {};
|
||||
|
||||
o.pointsOffset = readAs(arraybuffer, Uint32Array, 32*3);
|
||||
o.pointsFormatId = readAs(arraybuffer, Uint8Array, 32*3+8);
|
||||
o.pointsStructSize = readAs(arraybuffer, Uint16Array, 32*3+8+1);
|
||||
o.pointsCount = readAs(arraybuffer, Uint32Array, 32*3 + 11);
|
||||
o.pointsOffset = readAs(arraybuffer, Uint32Array, 32 * 3);
|
||||
o.pointsFormatId = readAs(arraybuffer, Uint8Array, 32 * 3 + 8);
|
||||
o.pointsStructSize = readAs(arraybuffer, Uint16Array, 32 * 3 + 8 + 1);
|
||||
o.pointsCount = readAs(arraybuffer, Uint32Array, 32 * 3 + 11);
|
||||
|
||||
|
||||
var start = 32*3 + 35;
|
||||
var start = 32 * 3 + 35;
|
||||
o.scale = readAs(arraybuffer, Float64Array, start, 3); start += 24; // 8*3
|
||||
o.offset = readAs(arraybuffer, Float64Array, start, 3); start += 24;
|
||||
|
||||
@ -41,9 +41,9 @@ function parseLASHeader(arraybuffer) {
|
||||
return o;
|
||||
}
|
||||
|
||||
function handleEvent(msg) {
|
||||
switch(msg.type) {
|
||||
case "open":
|
||||
function handleEvent (msg) {
|
||||
switch (msg.type) {
|
||||
case 'open':
|
||||
try {
|
||||
instance = new Module.LASZip();
|
||||
var abInt = new Uint8Array(msg.arraybuffer);
|
||||
@ -56,80 +56,73 @@ function handleEvent(msg) {
|
||||
|
||||
instance.readOffset = 0;
|
||||
|
||||
postMessage({ type: "open", status: 1});
|
||||
}
|
||||
catch(e) {
|
||||
postMessage({ type: "open", status: 0, details: e });
|
||||
postMessage({ type: 'open', status: 1 });
|
||||
} catch (e) {
|
||||
postMessage({ type: 'open', status: 0, details: e });
|
||||
}
|
||||
break;
|
||||
|
||||
case "header":
|
||||
if (!instance)
|
||||
throw new Error("You need to open the file before trying to read header");
|
||||
|
||||
|
||||
case 'header':
|
||||
if (!instance) { throw new Error('You need to open the file before trying to read header'); }
|
||||
|
||||
var header = parseLASHeader(instance.arraybuffer);
|
||||
header.pointsFormatId &= 0x3f;
|
||||
instance.header = header;
|
||||
postMessage({type: "header", status: 1, header: header});
|
||||
postMessage({ type: 'header', status: 1, header: header });
|
||||
break;
|
||||
|
||||
case "read":
|
||||
if (!instance)
|
||||
throw new Error("You need to open the file before trying to read stuff");
|
||||
case 'read':
|
||||
if (!instance) { throw new Error('You need to open the file before trying to read stuff'); }
|
||||
|
||||
var start = msg.start, count = msg.count, skip = msg.skip;
|
||||
// msg.start
|
||||
var count = msg.count;
|
||||
var skip = msg.skip;
|
||||
var o = instance;
|
||||
|
||||
if (!o.header)
|
||||
throw new Error("You need to query header before reading, I maintain state that way, sorry :(");
|
||||
if (!o.header) { throw new Error('You need to query header before reading, I maintain state that way, sorry :('); }
|
||||
|
||||
var pointsToRead = Math.min(count * skip, o.header.pointsCount - o.readOffset);
|
||||
var bufferSize = Math.ceil(pointsToRead / skip);
|
||||
var pointsRead = 0;
|
||||
|
||||
var this_buf = new Uint8Array(bufferSize * o.header.pointsStructSize);
|
||||
var buf_read = Module._malloc(o.header.pointsStructSize);
|
||||
for (var i = 0 ; i < pointsToRead ; i ++) {
|
||||
o.getPoint(buf_read);
|
||||
var thisBuf = new Uint8Array(bufferSize * o.header.pointsStructSize);
|
||||
var bufRead = Module._malloc(o.header.pointsStructSize);
|
||||
for (var i = 0; i < pointsToRead; i++) {
|
||||
o.getPoint(bufRead);
|
||||
|
||||
if (i % skip === 0) {
|
||||
var a = new Uint8Array(Module.HEAPU8.buffer, buf_read, o.header.pointsStructSize);
|
||||
this_buf.set(a, pointsRead * o.header.pointsStructSize, o.header.pointsStructSize);
|
||||
pointsRead ++;
|
||||
var a = new Uint8Array(Module.HEAPU8.buffer, bufRead, o.header.pointsStructSize);
|
||||
thisBuf.set(a, pointsRead * o.header.pointsStructSize, o.header.pointsStructSize);
|
||||
pointsRead++;
|
||||
}
|
||||
|
||||
o.readOffset ++;
|
||||
o.readOffset++;
|
||||
}
|
||||
|
||||
postMessage({
|
||||
type: 'header',
|
||||
status: 1,
|
||||
buffer: this_buf.buffer,
|
||||
buffer: thisBuf.buffer,
|
||||
count: pointsRead,
|
||||
hasMoreData: o.readOffset < o.header.pointsCount
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case "close":
|
||||
case 'close':
|
||||
if (instance !== null) {
|
||||
instance.delete();
|
||||
instance = null;
|
||||
}
|
||||
postMessage({ type: "close", status: 1});
|
||||
postMessage({ type: 'close', status: 1 });
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onmessage = function(event) {
|
||||
onmessage = function (event) {
|
||||
try {
|
||||
handleEvent(event.data);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
postMessage({type: event.data.type, status: 0, details: e});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user