itowns 2.43.2-next.15 → 2.43.2-next.17

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.
@@ -72,12 +72,12 @@ class C3DTFeature {
72
72
  target.min.y = Infinity;
73
73
  target.min.z = Infinity;
74
74
  this.groups.forEach(group => {
75
- const positionIndexStart = group.start * 3;
76
- const positionIndexCount = (group.start + group.count) * 3;
77
- for (let index = positionIndexStart; index < positionIndexCount; index += 3) {
78
- const x = this.object3d.geometry.attributes.position.array[index];
79
- const y = this.object3d.geometry.attributes.position.array[index + 1];
80
- const z = this.object3d.geometry.attributes.position.array[index + 2];
75
+ const positionIndexStart = group.start * this.object3d.geometry.attributes.position.itemSize;
76
+ const positionIndexCount = (group.start + group.count) * this.object3d.geometry.attributes.position.itemSize;
77
+ for (let index = positionIndexStart; index < positionIndexCount; index++) {
78
+ const x = this.object3d.geometry.attributes.position.getX(index);
79
+ const y = this.object3d.geometry.attributes.position.getY(index);
80
+ const z = this.object3d.geometry.attributes.position.getZ(index);
81
81
  target.max.x = Math.max(x, target.max.x);
82
82
  target.max.y = Math.max(y, target.max.y);
83
83
  target.max.z = Math.max(z, target.max.z);
@@ -243,7 +243,7 @@ class C3DTilesLayer extends GeometryLayer {
243
243
  // face is a Face3 object of THREE which is a
244
244
  // triangular face. face.a is its first vertex
245
245
  const vertex = closestIntersect.face.a;
246
- const batchID = closestIntersect.object.geometry.attributes._BATCHID.array[vertex];
246
+ const batchID = closestIntersect.object.geometry.attributes._BATCHID.getX(vertex);
247
247
  return this.tilesC3DTileFeatures.get(tileId).get(batchID);
248
248
  }
249
249
 
@@ -1,6 +1,23 @@
1
1
  import * as THREE from 'three';
2
- import LASLoader from "../Loader/LASLoader.js";
3
- const lasLoader = new LASLoader();
2
+ import { spawn, Thread, Transfer } from 'threads';
3
+ let _lazPerf;
4
+ let _thread;
5
+ function workerInstance() {
6
+ return new Worker( /* webpackChunkName: "itowns_lasparser" */
7
+ new URL('../Worker/LASLoaderWorker.js', import.meta.url), {
8
+ type: 'module'
9
+ });
10
+ }
11
+ async function loader() {
12
+ if (_thread) {
13
+ return _thread;
14
+ }
15
+ _thread = await spawn(workerInstance());
16
+ if (_lazPerf) {
17
+ _thread.lazPerf(_lazPerf);
18
+ }
19
+ return _thread;
20
+ }
4
21
  function buildBufferGeometry(attributes) {
5
22
  const geometry = new THREE.BufferGeometry();
6
23
  const positionBuffer = new THREE.BufferAttribute(attributes.position, 3);
@@ -42,7 +59,16 @@ export default {
42
59
  if (!path) {
43
60
  throw new Error('Path to laz-perf is mandatory');
44
61
  }
45
- lasLoader.lazPerf = path;
62
+ _lazPerf = path;
63
+ },
64
+ /**
65
+ * Terminate all worker instances.
66
+ * @returns {Promise<void>}
67
+ */
68
+ terminate() {
69
+ const currentThread = _thread;
70
+ _thread = undefined;
71
+ return Thread.terminate(currentThread);
46
72
  },
47
73
  /**
48
74
  * Parses a chunk of a LAS or LAZ (LASZip) and returns the corresponding
@@ -66,13 +92,18 @@ export default {
66
92
  * @return {Promise<THREE.BufferGeometry>} A promise resolving with a
67
93
  * `THREE.BufferGeometry`.
68
94
  */
69
- parseChunk(data) {
95
+ async parseChunk(data) {
70
96
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
71
- return lasLoader.parseChunk(data, options.in).then(parsedData => {
72
- const geometry = buildBufferGeometry(parsedData.attributes);
73
- geometry.computeBoundingBox();
74
- return geometry;
97
+ const lasLoader = await loader();
98
+ const parsedData = await lasLoader.parseChunk(Transfer(data), {
99
+ pointCount: options.in.pointCount,
100
+ header: options.in.header,
101
+ eb: options.eb,
102
+ colorDepth: options.in.colorDepth
75
103
  });
104
+ const geometry = buildBufferGeometry(parsedData.attributes);
105
+ geometry.computeBoundingBox();
106
+ return geometry;
76
107
  },
77
108
  /**
78
109
  * Parses a LAS file or a LAZ (LASZip) file and return the corresponding
@@ -88,18 +119,19 @@ export default {
88
119
  * @return {Promise} A promise resolving with a `THREE.BufferGeometry`. The
89
120
  * header of the file is contained in `userData`.
90
121
  */
91
- parse(data) {
122
+ async parse(data) {
92
123
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
93
124
  if (options.out?.skip) {
94
125
  console.warn("Warning: options 'skip' not supported anymore");
95
126
  }
96
- return lasLoader.parseFile(data, {
97
- colorDepth: options.in?.colorDepth
98
- }).then(parsedData => {
99
- const geometry = buildBufferGeometry(parsedData.attributes);
100
- geometry.userData.header = parsedData.header;
101
- geometry.computeBoundingBox();
102
- return geometry;
127
+ const input = options.in;
128
+ const lasLoader = await loader();
129
+ const parsedData = await lasLoader.parseFile(Transfer(data), {
130
+ colorDepth: input?.colorDepth
103
131
  });
132
+ const geometry = buildBufferGeometry(parsedData.attributes);
133
+ geometry.userData.header = parsedData.header;
134
+ geometry.computeBoundingBox();
135
+ return geometry;
104
136
  }
105
137
  };
@@ -0,0 +1,19 @@
1
+ import { expose, Transfer } from 'threads/worker';
2
+ import LASLoader from "../Loader/LASLoader.js";
3
+ const loader = new LASLoader();
4
+ function transferable(attributes) {
5
+ return Object.values(attributes).filter(ArrayBuffer.isView).map(a => a.buffer);
6
+ }
7
+ expose({
8
+ lazPerf(path) {
9
+ loader.lazPerf = path;
10
+ },
11
+ async parseChunk(data, options) {
12
+ const result = await loader.parseChunk(data, options);
13
+ return Transfer(result, transferable(result.attributes));
14
+ },
15
+ async parseFile(data, options) {
16
+ const result = await loader.parseFile(data, options);
17
+ return Transfer(result, transferable(result.attributes));
18
+ }
19
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.43.2-next.15",
3
+ "version": "2.43.2-next.17",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "type": "module",
6
6
  "main": "lib/Main.js",