itowns 2.43.2-next.11 → 2.43.2-next.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,7 @@
24
24
 
25
25
  "Pointcloud": {
26
26
  "potree_25d_map": "Potree 2.5D map",
27
+ "potree2_25d_map": "Potree 2.5D map 2.0 format",
27
28
  "potree_3d_map": "Potree 3D map",
28
29
  "laz_dragndrop": "LAS/LAZ viewer",
29
30
  "entwine_simple_loader": "Entwine loader",
@@ -0,0 +1,127 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Point Cloud Viewer</title>
5
+
6
+ <style type="text/css">
7
+ #info {
8
+ color: #7ad7ff;
9
+ font-family: 'Open Sans', sans-serif;
10
+ position: absolute;
11
+ top: 0;
12
+ left: 0;
13
+ padding: 0.3rem;
14
+ background-color: #404040;
15
+ z-index: 1;
16
+ }
17
+ @media (max-width: 600px) {
18
+ #info,
19
+ .dg {
20
+ display: none;
21
+ }
22
+ }
23
+ </style>
24
+
25
+ <meta charset="UTF-8">
26
+ <link rel="stylesheet" type="text/css" href="css/example.css">
27
+ <link rel="stylesheet" type="text/css" href="css/LoadingScreen.css">
28
+
29
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
30
+ </head>
31
+ <body>
32
+ <div id="viewerDiv">
33
+ <div id="info"></div>
34
+ </div>
35
+
36
+ <div>
37
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.7.6/dat.gui.min.js"></script>
38
+ <script src="../dist/itowns.js"></script>
39
+ <script src="js/GUI/LoadingScreen.js"></script>
40
+ <script src="../dist/debug.js"></script>
41
+ <script type="text/javascript">
42
+ var potreeLayer;
43
+ var oldPostUpdate;
44
+ var viewerDiv;
45
+ var debugGui;
46
+ var view;
47
+ var controls;
48
+
49
+ // Define crs projection that we will use (taken from https://epsg.io/3946, Proj4js section)
50
+ itowns.proj4.defs('EPSG:3946', '+proj=lcc +lat_1=45.25 +lat_2=46.75 +lat_0=46 +lon_0=3 +x_0=1700000 +y_0=5200000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
51
+
52
+ viewerDiv = document.getElementById('viewerDiv');
53
+ viewerDiv.style.display = 'block';
54
+
55
+ debugGui = new dat.GUI();
56
+
57
+ // TODO: do we really need to disable logarithmicDepthBuffer ?
58
+ view = new itowns.View('EPSG:3946', viewerDiv);
59
+ setupLoadingScreen(viewerDiv, view);
60
+ view.mainLoop.gfxEngine.renderer.setClearColor(0xcccccc);
61
+
62
+ // Configure Point Cloud layer
63
+ potreeLayer = new itowns.Potree2Layer('Lion', {
64
+ source: new itowns.Potree2Source({
65
+ file: 'metadata.json',
66
+ url: 'https://blocinbloc-public-test.s3.fr-par.scw.cloud/lion-potree2',
67
+ crs: view.referenceCrs,
68
+ }),
69
+ });
70
+
71
+ // point selection on double-click
72
+ function dblClickHandler(event) {
73
+ var pick = view.pickObjectsAt(event, 5, potreeLayer);
74
+
75
+ for (const p of pick) {
76
+ console.info('Selected point #' + p.index + ' in position (' +
77
+ p.object.position.x + ', ' +
78
+ p.object.position.y + ', ' +
79
+ p.object.position.z +
80
+ ') in Points ' + p.object.layer.id);
81
+ }
82
+ }
83
+ view.domElement.addEventListener('dblclick', dblClickHandler);
84
+
85
+ function placeCamera(position, lookAt) {
86
+ view.camera.camera3D.position.copy(position);
87
+ view.camera.camera3D.lookAt(lookAt);
88
+ // create controls
89
+ controls = new itowns.FirstPersonControls(view, { focusOnClick: true });
90
+ debugGui.add(controls.options, 'moveSpeed', 1, 100).name('Movement speed');
91
+
92
+ view.notifyChange(view.camera.camera3D);
93
+ }
94
+
95
+ // add potreeLayer to scene
96
+ function onLayerReady() {
97
+ var ratio;
98
+ var position;
99
+ var lookAt = new itowns.THREE.Vector3();
100
+ var size = new itowns.THREE.Vector3();
101
+
102
+ potreeLayer.root.bbox.getSize(size);
103
+ potreeLayer.root.bbox.getCenter(lookAt);
104
+
105
+ debug.PointCloudDebug.initTools(view, potreeLayer, debugGui);
106
+
107
+ view.camera.camera3D.far = 2.0 * size.length();
108
+
109
+ ratio = size.x / size.z;
110
+ position = potreeLayer.root.bbox.min.clone().add(
111
+ size.multiply({ x: 0, y: 0, z: ratio * 0.5 }));
112
+ lookAt.z = potreeLayer.root.bbox.min.z;
113
+ placeCamera(position, lookAt);
114
+ controls.moveSpeed = size.length() / 3;
115
+
116
+ // update stats window
117
+ var info = document.getElementById('info');
118
+ view.addFrameRequester(itowns.MAIN_LOOP_EVENTS.AFTER_RENDER, () => {
119
+ info.textContent = potreeLayer.displayedCount.toLocaleString() + ' points';
120
+ });
121
+ }
122
+ window.view = view;
123
+ view.addLayer(potreeLayer).then(onLayerReady);
124
+ </script>
125
+ </body>
126
+ </html>
127
+
@@ -0,0 +1,201 @@
1
+ /*
2
+ ============
3
+ == POTREE ==
4
+ ============
5
+
6
+ http://potree.org
7
+
8
+ Copyright (c) 2011-2020, Markus Schütz
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice, this
15
+ list of conditions and the following disclaimer.
16
+ 2. Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ The views and conclusions contained in the software and documentation are those
32
+ of the authors and should not be interpreted as representing official policies,
33
+ either expressed or implied, of the FreeBSD Project.
34
+ */
35
+
36
+ import * as THREE from 'three';
37
+ import PointCloudNode from "./PointCloudNode.js";
38
+
39
+ // Create an A(xis)A(ligned)B(ounding)B(ox) for the child `childIndex` of one aabb.
40
+ // (PotreeConverter protocol builds implicit octree hierarchy by applying the same
41
+ // subdivision algo recursively)
42
+ const dHalfLength = new THREE.Vector3();
43
+ const NODE_TYPE = {
44
+ NORMAL: 0,
45
+ LEAF: 1,
46
+ PROXY: 2
47
+ };
48
+ class Potree2Node extends PointCloudNode {
49
+ constructor() {
50
+ let numPoints = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
51
+ let childrenBitField = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
52
+ let layer = arguments.length > 2 ? arguments[2] : undefined;
53
+ super(numPoints, layer);
54
+ this.childrenBitField = childrenBitField;
55
+ this.id = '';
56
+ this.depth = 0;
57
+ this.baseurl = layer.source.baseurl;
58
+ }
59
+ add(node, indexChild) {
60
+ super.add(node, indexChild);
61
+ node.id = this.id + indexChild;
62
+ node.depth = this.depth + 1;
63
+ }
64
+ createChildAABB(node, childIndex) {
65
+ // Code inspired from potree
66
+ node.bbox.copy(this.bbox);
67
+ this.bbox.getCenter(node.bbox.max);
68
+ dHalfLength.copy(node.bbox.max).sub(this.bbox.min);
69
+ if (childIndex === 1) {
70
+ node.bbox.min.z += dHalfLength.z;
71
+ node.bbox.max.z += dHalfLength.z;
72
+ } else if (childIndex === 3) {
73
+ node.bbox.min.z += dHalfLength.z;
74
+ node.bbox.max.z += dHalfLength.z;
75
+ node.bbox.min.y += dHalfLength.y;
76
+ node.bbox.max.y += dHalfLength.y;
77
+ } else if (childIndex === 0) {
78
+ //
79
+ } else if (childIndex === 2) {
80
+ node.bbox.min.y += dHalfLength.y;
81
+ node.bbox.max.y += dHalfLength.y;
82
+ } else if (childIndex === 5) {
83
+ node.bbox.min.z += dHalfLength.z;
84
+ node.bbox.max.z += dHalfLength.z;
85
+ node.bbox.min.x += dHalfLength.x;
86
+ node.bbox.max.x += dHalfLength.x;
87
+ } else if (childIndex === 7) {
88
+ node.bbox.min.add(dHalfLength);
89
+ node.bbox.max.add(dHalfLength);
90
+ } else if (childIndex === 4) {
91
+ node.bbox.min.x += dHalfLength.x;
92
+ node.bbox.max.x += dHalfLength.x;
93
+ } else if (childIndex === 6) {
94
+ node.bbox.min.y += dHalfLength.y;
95
+ node.bbox.max.y += dHalfLength.y;
96
+ node.bbox.min.x += dHalfLength.x;
97
+ node.bbox.max.x += dHalfLength.x;
98
+ }
99
+ }
100
+ get octreeIsLoaded() {
101
+ return !(this.childrenBitField && this.children.length === 0);
102
+ }
103
+ get url() {
104
+ return `${this.baseurl}/octree.bin`;
105
+ }
106
+ networkOptions(byteOffset, byteSize) {
107
+ const first = byteOffset;
108
+ const networkOptions = {
109
+ ...this.layer.source.networkOptions,
110
+ headers: {
111
+ ...this.layer.source.networkOptions.headers,
112
+ 'content-type': 'multipart/byteranges',
113
+ Range: `bytes=${first}-${first + byteSize - 1n}`
114
+ }
115
+ };
116
+ return networkOptions;
117
+ }
118
+ async load() {
119
+ // Query octree if we don't have children potreeNode yet.
120
+ if (!this.octreeIsLoaded) {
121
+ await this.loadOctree();
122
+ }
123
+ return this.layer.source.fetcher(this.url, this.networkOptions(this.byteOffset, this.byteSize)).then(file => this.layer.source.parser(file, {
124
+ in: {
125
+ source: this.layer.source,
126
+ bbox: this.bbox,
127
+ numPoints: this.numPoints
128
+ },
129
+ out: this.layer
130
+ })).then(data => {
131
+ this.loaded = true;
132
+ this.loading = false;
133
+ return data.geometry;
134
+ });
135
+ }
136
+ async loadOctree() {
137
+ if (this.loaded || this.loading) {
138
+ return;
139
+ }
140
+ this.loading = true;
141
+ return this.nodeType === NODE_TYPE.PROXY ? this.loadHierarchy() : Promise.resolve();
142
+ }
143
+ async loadHierarchy() {
144
+ const hierarchyPath = `${this.baseurl}/hierarchy.bin`;
145
+ const buffer = await this.layer.source.fetcher(hierarchyPath, this.networkOptions(this.hierarchyByteOffset, this.hierarchyByteSize));
146
+ this.parseHierarchy(buffer);
147
+ }
148
+ parseHierarchy(buffer) {
149
+ const view = new DataView(buffer);
150
+ const bytesPerNode = 22;
151
+ const numNodes = buffer.byteLength / bytesPerNode;
152
+ const stack = [];
153
+ stack.push(this);
154
+ for (let indexNode = 0; indexNode < numNodes; indexNode++) {
155
+ const current = stack.shift();
156
+ const offset = indexNode * bytesPerNode;
157
+ const type = view.getUint8(offset + 0);
158
+ const childMask = view.getUint8(offset + 1);
159
+ const numPoints = view.getUint32(offset + 2, true);
160
+ const byteOffset = view.getBigInt64(offset + 6, true);
161
+ const byteSize = view.getBigInt64(offset + 14, true);
162
+ if (current.nodeType === NODE_TYPE.PROXY) {
163
+ // replace proxy with real node
164
+ current.byteOffset = byteOffset;
165
+ current.byteSize = byteSize;
166
+ current.numPoints = numPoints;
167
+ } else if (type === NODE_TYPE.PROXY) {
168
+ // load proxy
169
+ current.hierarchyByteOffset = byteOffset;
170
+ current.hierarchyByteSize = byteSize;
171
+ current.numPoints = numPoints;
172
+ } else {
173
+ // load real node
174
+ current.byteOffset = byteOffset;
175
+ current.byteSize = byteSize;
176
+ current.numPoints = numPoints;
177
+ }
178
+ if (current.byteSize === 0n) {
179
+ // workaround for issue potree/potree#1125
180
+ // some inner nodes erroneously report >0 points even though have 0 points
181
+ // however, they still report a byteSize of 0, so based on that we now set node.numPoints to 0
182
+ current.numPoints = 0;
183
+ }
184
+ current.nodeType = type;
185
+ if (current.nodeType === NODE_TYPE.PROXY) {
186
+ continue;
187
+ }
188
+ for (let childIndex = 0; childIndex < 8; childIndex++) {
189
+ const childExists = (1 << childIndex & childMask) !== 0;
190
+ if (!childExists) {
191
+ continue;
192
+ }
193
+ const child = new Potree2Node(numPoints, childMask, this.layer);
194
+ child.spacing = current.spacing / 2;
195
+ current.add(child, childIndex);
196
+ stack.push(child);
197
+ }
198
+ }
199
+ }
200
+ }
201
+ export default Potree2Node;
@@ -0,0 +1,139 @@
1
+ /*
2
+ ============
3
+ == POTREE ==
4
+ ============
5
+
6
+ http://potree.org
7
+
8
+ Copyright (c) 2011-2020, Markus Schütz
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice, this
15
+ list of conditions and the following disclaimer.
16
+ 2. Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ The views and conclusions contained in the software and documentation are those
32
+ of the authors and should not be interpreted as representing official policies,
33
+ either expressed or implied, of the FreeBSD Project.
34
+ */
35
+
36
+ /**
37
+ * Some types of possible point attribute data formats
38
+ *
39
+ * @class
40
+ */
41
+ const PointAttributeTypes = {
42
+ DATA_TYPE_DOUBLE: {
43
+ name: 'double',
44
+ size: 8
45
+ },
46
+ DATA_TYPE_FLOAT: {
47
+ name: 'float',
48
+ size: 4
49
+ },
50
+ DATA_TYPE_INT8: {
51
+ name: 'int8',
52
+ size: 1
53
+ },
54
+ DATA_TYPE_UINT8: {
55
+ name: 'uint8',
56
+ size: 1
57
+ },
58
+ DATA_TYPE_INT16: {
59
+ name: 'int16',
60
+ size: 2
61
+ },
62
+ DATA_TYPE_UINT16: {
63
+ name: 'uint16',
64
+ size: 2
65
+ },
66
+ DATA_TYPE_INT32: {
67
+ name: 'int32',
68
+ size: 4
69
+ },
70
+ DATA_TYPE_UINT32: {
71
+ name: 'uint32',
72
+ size: 4
73
+ },
74
+ DATA_TYPE_INT64: {
75
+ name: 'int64',
76
+ size: 8
77
+ },
78
+ DATA_TYPE_UINT64: {
79
+ name: 'uint64',
80
+ size: 8
81
+ }
82
+ };
83
+ Object.keys(PointAttributeTypes).forEach((type, index) => {
84
+ PointAttributeTypes[index] = PointAttributeTypes[type];
85
+ });
86
+ export { PointAttributeTypes };
87
+ class PointAttribute {
88
+ constructor(name, type, numElements) {
89
+ this.name = name;
90
+ this.type = type;
91
+ this.numElements = numElements;
92
+ this.byteSize = this.numElements * this.type.size;
93
+ this.description = '';
94
+ this.range = [Infinity, -Infinity];
95
+ }
96
+ }
97
+ PointAttribute.POSITION_CARTESIAN = new PointAttribute('POSITION_CARTESIAN', PointAttributeTypes.DATA_TYPE_FLOAT, 3);
98
+ PointAttribute.RGBA_PACKED = new PointAttribute('COLOR_PACKED', PointAttributeTypes.DATA_TYPE_INT8, 4);
99
+ PointAttribute.COLOR_PACKED = PointAttribute.RGBA_PACKED;
100
+ PointAttribute.RGB_PACKED = new PointAttribute('COLOR_PACKED', PointAttributeTypes.DATA_TYPE_INT8, 3);
101
+ PointAttribute.NORMAL_FLOATS = new PointAttribute('NORMAL_FLOATS', PointAttributeTypes.DATA_TYPE_FLOAT, 3);
102
+ PointAttribute.INTENSITY = new PointAttribute('INTENSITY', PointAttributeTypes.DATA_TYPE_UINT16, 1);
103
+ PointAttribute.CLASSIFICATION = new PointAttribute('CLASSIFICATION', PointAttributeTypes.DATA_TYPE_UINT8, 1);
104
+ PointAttribute.NORMAL_SPHEREMAPPED = new PointAttribute('NORMAL_SPHEREMAPPED', PointAttributeTypes.DATA_TYPE_UINT8, 2);
105
+ PointAttribute.NORMAL_OCT16 = new PointAttribute('NORMAL_OCT16', PointAttributeTypes.DATA_TYPE_UINT8, 2);
106
+ PointAttribute.NORMAL = new PointAttribute('NORMAL', PointAttributeTypes.DATA_TYPE_FLOAT, 3);
107
+ PointAttribute.RETURN_NUMBER = new PointAttribute('RETURN_NUMBER', PointAttributeTypes.DATA_TYPE_UINT8, 1);
108
+ PointAttribute.NUMBER_OF_RETURNS = new PointAttribute('NUMBER_OF_RETURNS', PointAttributeTypes.DATA_TYPE_UINT8, 1);
109
+ PointAttribute.SOURCE_ID = new PointAttribute('SOURCE_ID', PointAttributeTypes.DATA_TYPE_UINT16, 1);
110
+ PointAttribute.INDICES = new PointAttribute('INDICES', PointAttributeTypes.DATA_TYPE_UINT32, 1);
111
+ PointAttribute.SPACING = new PointAttribute('SPACING', PointAttributeTypes.DATA_TYPE_FLOAT, 1);
112
+ PointAttribute.GPS_TIME = new PointAttribute('GPS_TIME', PointAttributeTypes.DATA_TYPE_DOUBLE, 1);
113
+ export { PointAttribute };
114
+ export class Potree2PointAttributes {
115
+ constructor() {
116
+ this.attributes = [];
117
+ this.byteSize = 0;
118
+ this.size = 0;
119
+ this.vectors = [];
120
+ }
121
+ add(pointAttribute) {
122
+ this.attributes.push(pointAttribute);
123
+ this.byteSize += pointAttribute.byteSize;
124
+ this.size++;
125
+ }
126
+ addVector(vector) {
127
+ this.vectors.push(vector);
128
+ }
129
+ hasNormals() {
130
+ for (let index = 0; index < this.attributes.length; index++) {
131
+ const name = this.attributes[index];
132
+ const pointAttribute = this.attributes[name];
133
+ if (pointAttribute === PointAttribute.NORMAL_SPHEREMAPPED || pointAttribute === PointAttribute.NORMAL_FLOATS || pointAttribute === PointAttribute.NORMAL || pointAttribute === PointAttribute.NORMAL_OCT16) {
134
+ return true;
135
+ }
136
+ }
137
+ return false;
138
+ }
139
+ }
@@ -140,7 +140,7 @@ Scheduler.prototype.execute = function (command) {
140
140
 
141
141
  // parse host
142
142
  const layer = command.layer;
143
- const host = layer.source && layer.source.url ? new URL(URLBuilder.subDomains(layer.source.url), document.location).host : undefined;
143
+ const host = layer.source && layer.source.url && layer.source.url !== 'none' ? new URL(URLBuilder.subDomains(layer.source.url), document.location).host : undefined;
144
144
  command.promise = new Promise((resolve, reject) => {
145
145
  command.resolve = resolve;
146
146
  command.reject = reject;
@@ -0,0 +1,165 @@
1
+ /*
2
+ ============
3
+ == POTREE ==
4
+ ============
5
+
6
+ http://potree.org
7
+
8
+ Copyright (c) 2011-2020, Markus Schütz
9
+ All rights reserved.
10
+
11
+ Redistribution and use in source and binary forms, with or without
12
+ modification, are permitted provided that the following conditions are met:
13
+
14
+ 1. Redistributions of source code must retain the above copyright notice, this
15
+ list of conditions and the following disclaimer.
16
+ 2. Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ The views and conclusions contained in the software and documentation are those
32
+ of the authors and should not be interpreted as representing official policies,
33
+ either expressed or implied, of the FreeBSD Project.
34
+ */
35
+
36
+ import * as THREE from 'three';
37
+ import PointCloudLayer from "./PointCloudLayer.js";
38
+ import Potree2Node from "../Core/Potree2Node.js";
39
+ import Extent from "../Core/Geographic/Extent.js";
40
+ import { PointAttribute, Potree2PointAttributes, PointAttributeTypes } from "../Core/Potree2PointAttributes.js";
41
+ const bboxMesh = new THREE.Mesh();
42
+ const box3 = new THREE.Box3();
43
+ bboxMesh.geometry.boundingBox = box3;
44
+ const typeNameAttributeMap = {
45
+ double: PointAttributeTypes.DATA_TYPE_DOUBLE,
46
+ float: PointAttributeTypes.DATA_TYPE_FLOAT,
47
+ int8: PointAttributeTypes.DATA_TYPE_INT8,
48
+ uint8: PointAttributeTypes.DATA_TYPE_UINT8,
49
+ int16: PointAttributeTypes.DATA_TYPE_INT16,
50
+ uint16: PointAttributeTypes.DATA_TYPE_UINT16,
51
+ int32: PointAttributeTypes.DATA_TYPE_INT32,
52
+ uint32: PointAttributeTypes.DATA_TYPE_UINT32,
53
+ int64: PointAttributeTypes.DATA_TYPE_INT64,
54
+ uint64: PointAttributeTypes.DATA_TYPE_UINT64
55
+ };
56
+ function parseAttributes(jsonAttributes) {
57
+ const attributes = new Potree2PointAttributes();
58
+ const replacements = {
59
+ rgb: 'rgba'
60
+ };
61
+ for (const jsonAttribute of jsonAttributes) {
62
+ const {
63
+ name,
64
+ numElements,
65
+ min,
66
+ max
67
+ } = jsonAttribute;
68
+ const type = typeNameAttributeMap[jsonAttribute.type];
69
+ const potreeAttributeName = replacements[name] ? replacements[name] : name;
70
+ const attribute = new PointAttribute(potreeAttributeName, type, numElements);
71
+ if (numElements === 1) {
72
+ attribute.range = [min[0], max[0]];
73
+ } else {
74
+ attribute.range = [min, max];
75
+ }
76
+ if (name === 'gps-time') {
77
+ // HACK: Guard against bad gpsTime range in metadata, see potree/potree#909
78
+ if (attribute.range[0] === attribute.range[1]) {
79
+ attribute.range[1] += 1;
80
+ }
81
+ }
82
+ attribute.initialRange = attribute.range;
83
+ attributes.add(attribute);
84
+ }
85
+ {
86
+ // check if it has normals
87
+ const hasNormals = attributes.attributes.find(a => a.name === 'NormalX') !== undefined && attributes.attributes.find(a => a.name === 'NormalY') !== undefined && attributes.attributes.find(a => a.name === 'NormalZ') !== undefined;
88
+ if (hasNormals) {
89
+ attributes.addVector({
90
+ name: 'NORMAL',
91
+ attributes: ['NormalX', 'NormalY', 'NormalZ']
92
+ });
93
+ }
94
+ }
95
+ return attributes;
96
+ }
97
+
98
+ /**
99
+ * @property {boolean} isPotreeLayer - Used to checkout whether this layer
100
+ * is a Potree2Layer. Default is `true`. You should not change this, as it is
101
+ * used internally for optimisation.
102
+ */
103
+ class Potree2Layer extends PointCloudLayer {
104
+ /**
105
+ * Constructs a new instance of Potree2 layer.
106
+ *
107
+ * @constructor
108
+ * @extends PointCloudLayer
109
+ *
110
+ * @example
111
+ * // Create a new point cloud layer
112
+ * const points = new Potree2Layer('points',
113
+ * {
114
+ * source: new Potree2Source({
115
+ * url: 'https://pointsClouds/',
116
+ * file: 'metadata.json',
117
+ * }
118
+ * });
119
+ *
120
+ * View.prototype.addLayer.call(view, points);
121
+ *
122
+ * @param {string} id - The id of the layer, that should be unique. It is
123
+ * not mandatory, but an error will be emitted if this layer is added a
124
+ * {@link View} that already has a layer going by that id.
125
+ * @param {Object} config - Configuration, all elements in it
126
+ * will be merged as is in the layer. For example, if the configuration
127
+ * contains three elements `name, protocol, extent`, these elements will be
128
+ * available using `layer.name` or something else depending on the property
129
+ * name. See the list of properties to know which one can be specified.
130
+ * @param {string} [config.crs=ESPG:4326] - The CRS of the {@link View} this
131
+ * layer will be attached to. This is used to determine the extent of this
132
+ * layer. Default to `EPSG:4326`.
133
+ */
134
+ constructor(id, config) {
135
+ super(id, config);
136
+ this.isPotreeLayer = true;
137
+ const resolve = this.addInitializationStep();
138
+ this.source.whenReady.then(metadata => {
139
+ this.scale = new THREE.Vector3(1, 1, 1);
140
+ this.metadata = metadata;
141
+ this.pointAttributes = parseAttributes(metadata.attributes);
142
+ this.spacing = metadata.spacing;
143
+ const normal = Array.isArray(this.pointAttributes.attributes) && this.pointAttributes.attributes.find(elem => elem.name.startsWith('NORMAL'));
144
+ if (normal) {
145
+ this.material.defines[normal.name] = 1;
146
+ }
147
+ const min = new THREE.Vector3(...metadata.boundingBox.min);
148
+ const max = new THREE.Vector3(...metadata.boundingBox.max);
149
+ const boundingBox = new THREE.Box3(min, max);
150
+ const root = new Potree2Node(0, 0, this);
151
+ root.bbox = boundingBox;
152
+ root.boundingSphere = boundingBox.getBoundingSphere(new THREE.Sphere());
153
+ root.id = 'r';
154
+ root.depth = 0;
155
+ root.nodeType = 2;
156
+ root.hierarchyByteOffset = 0n;
157
+ root.hierarchyByteSize = BigInt(metadata.hierarchy.firstChunkSize);
158
+ root.byteOffset = 0;
159
+ this.root = root;
160
+ this.extent = Extent.fromBox3(this.source.crs || 'EPSG:4326', boundingBox);
161
+ return this.root.loadOctree().then(resolve);
162
+ });
163
+ }
164
+ }
165
+ export default Potree2Layer;