@loaders.gl/potree 4.3.0-alpha.4 → 4.3.0-alpha.6

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.
Files changed (37) hide show
  1. package/dist/dist.dev.js +19541 -21
  2. package/dist/dist.min.js +21 -1
  3. package/dist/index.cjs +181 -20
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -0
  8. package/dist/lib/potree-node-source.d.ts +66 -0
  9. package/dist/lib/potree-node-source.d.ts.map +1 -0
  10. package/dist/lib/potree-node-source.js +141 -0
  11. package/dist/parsers/parse-potree-hierarchy-chunk.d.ts +21 -2
  12. package/dist/parsers/parse-potree-hierarchy-chunk.d.ts.map +1 -1
  13. package/dist/parsers/parse-potree-hierarchy-chunk.js +32 -18
  14. package/dist/potree-hierarchy-chunk-loader.d.ts +6 -1
  15. package/dist/potree-hierarchy-chunk-loader.d.ts.map +1 -1
  16. package/dist/potree-hierarchy-chunk-loader.js +9 -3
  17. package/dist/potree-loader.d.ts +3 -2
  18. package/dist/potree-loader.d.ts.map +1 -1
  19. package/dist/potree-loader.js +4 -5
  20. package/dist/potree-source.d.ts +22 -0
  21. package/dist/potree-source.d.ts.map +1 -0
  22. package/dist/potree-source.js +22 -0
  23. package/dist/types/potree-metadata.d.ts +88 -0
  24. package/dist/types/potree-metadata.d.ts.map +1 -0
  25. package/dist/types/potree-metadata.js +4 -0
  26. package/dist/utils/parse-version.d.ts +5 -0
  27. package/dist/utils/parse-version.d.ts.map +1 -0
  28. package/dist/utils/parse-version.js +7 -0
  29. package/package.json +5 -3
  30. package/src/index.ts +1 -0
  31. package/src/lib/potree-node-source.ts +174 -0
  32. package/src/parsers/parse-potree-hierarchy-chunk.ts +52 -26
  33. package/src/potree-hierarchy-chunk-loader.ts +10 -3
  34. package/src/potree-loader.ts +3 -4
  35. package/src/potree-source.ts +28 -0
  36. package/src/types/potree-metadata.ts +94 -0
  37. package/src/utils/parse-version.ts +8 -0
package/dist/index.cjs CHANGED
@@ -22,27 +22,28 @@ var dist_exports = {};
22
22
  __export(dist_exports, {
23
23
  PotreeBinLoader: () => PotreeBinLoader,
24
24
  PotreeHierarchyChunkLoader: () => PotreeHierarchyChunkLoader,
25
- PotreeLoader: () => PotreeLoader
25
+ PotreeLoader: () => PotreeLoader,
26
+ PotreeSource: () => PotreeSource
26
27
  });
27
28
  module.exports = __toCommonJS(dist_exports);
28
29
 
29
30
  // dist/potree-loader.js
30
- var VERSION = true ? "4.3.0-alpha.3" : "latest";
31
+ var VERSION = true ? "4.3.0-alpha.5" : "latest";
31
32
  var PotreeLoader = {
32
33
  dataType: null,
33
34
  batchType: null,
34
- name: "potree",
35
+ name: "potree metadata",
35
36
  id: "potree",
36
37
  module: "potree",
37
38
  version: VERSION,
38
- extensions: ["json"],
39
+ extensions: ["js"],
39
40
  mimeTypes: ["application/json"],
40
41
  testText: (text) => text.indexOf("octreeDir") >= 0,
42
+ parse: (data) => JSON.parse(new TextDecoder().decode(data)),
41
43
  parseTextSync: (text) => JSON.parse(text),
42
44
  options: {
43
45
  potree: {}
44
46
  }
45
- // @ts-ignore
46
47
  };
47
48
 
48
49
  // dist/parsers/parse-potree-hierarchy-chunk.js
@@ -56,7 +57,7 @@ function parseBinaryChunk(arrayBuffer, byteOffset = 0) {
56
57
  const topTileHeader = {};
57
58
  byteOffset = decodeRow(dataView, byteOffset, topTileHeader);
58
59
  stack.push(topTileHeader);
59
- const tileHeaders = [];
60
+ const tileHeaders = [topTileHeader];
60
61
  while (stack.length > 0) {
61
62
  const snode = stack.shift();
62
63
  let mask = 1;
@@ -86,45 +87,50 @@ function decodeRow(dataView, byteOffset, tileHeader) {
86
87
  byteOffset += 5;
87
88
  return byteOffset;
88
89
  }
89
- function buildHierarchy(tileHeaders, options = {}) {
90
+ function buildHierarchy(flatNodes, options = {}) {
90
91
  const DEFAULT_OPTIONS = { spacing: 100 };
91
92
  options = { ...DEFAULT_OPTIONS, ...options };
92
- const topNode = tileHeaders[0];
93
+ const topNode = flatNodes[0];
93
94
  const nodes = {};
94
- for (const tileHeader of tileHeaders) {
95
- const { name } = tileHeader;
95
+ for (const node of flatNodes) {
96
+ const { name } = node;
96
97
  const index = parseInt(name.charAt(name.length - 1), 10);
97
98
  const parentName = name.substring(0, name.length - 1);
98
99
  const parentNode = nodes[parentName];
99
100
  const level = name.length - 1;
100
- tileHeader.level = level;
101
- tileHeader.hasChildren = tileHeader.header.childCount;
102
- tileHeader.children = [];
103
- tileHeader.childrenByIndex = new Array(8).fill(null);
104
- tileHeader.spacing = ((options == null ? void 0 : options.spacing) || 0) / Math.pow(2, level);
101
+ node.level = level;
102
+ node.hasChildren = Boolean(node.header.childCount);
103
+ node.children = [];
104
+ node.childrenByIndex = new Array(8).fill(null);
105
+ node.spacing = ((options == null ? void 0 : options.spacing) || 0) / Math.pow(2, level);
105
106
  if (parentNode) {
106
- parentNode.children.push(tileHeader);
107
- parentNode.childrenByIndex[index] = tileHeader;
107
+ parentNode.children.push(node);
108
+ parentNode.childrenByIndex[index] = node;
108
109
  }
109
- nodes[name] = tileHeader;
110
+ nodes[name] = node;
110
111
  }
111
112
  return topNode;
112
113
  }
113
114
 
114
115
  // dist/potree-hierarchy-chunk-loader.js
116
+ var VERSION2 = true ? "4.3.0-alpha.5" : "latest";
115
117
  var PotreeHierarchyChunkLoader = {
116
118
  dataType: null,
117
119
  batchType: null,
118
- id: "potree",
119
120
  name: "potree Hierarchy Chunk",
121
+ id: "potree-hrc",
122
+ module: "potree",
123
+ version: VERSION2,
120
124
  extensions: ["hrc"],
121
125
  mimeTypes: ["application/octet-stream"],
122
126
  // binary potree files have no header bytes, no content test function possible
123
127
  // test: ['...'],
124
128
  parse: async (arrayBuffer, options) => parsePotreeHierarchyChunk(arrayBuffer),
125
129
  parseSync: (arrayBuffer, options) => parsePotreeHierarchyChunk(arrayBuffer),
130
+ options: {
131
+ potree: {}
132
+ },
126
133
  binary: true
127
- // @ts-ignore
128
134
  };
129
135
 
130
136
  // dist/parsers/parse-potree-bin.js
@@ -153,4 +159,159 @@ function parseSync(arrayBuffer, options) {
153
159
  parsePotreeBin(arrayBuffer, byteOffset, options, index);
154
160
  return index;
155
161
  }
162
+
163
+ // dist/lib/potree-node-source.js
164
+ var import_core = require("@loaders.gl/core");
165
+ var import_loader_utils = require("@loaders.gl/loader-utils");
166
+ var import_las = require("@loaders.gl/las");
167
+
168
+ // dist/utils/parse-version.js
169
+ function parseVersion(version) {
170
+ const parts = version.split(".").map(Number);
171
+ return { major: parts[0], minor: parts[1] };
172
+ }
173
+
174
+ // dist/lib/potree-node-source.js
175
+ var PotreeNodesSource = class extends import_loader_utils.DataSource {
176
+ /** Dataset base URL */
177
+ baseUrl = "";
178
+ /** Input data: string - dataset url, blob - single file data */
179
+ data;
180
+ /** Input props */
181
+ props;
182
+ /** Meta information from `cloud.js` */
183
+ metadata = null;
184
+ /** Root node */
185
+ root = null;
186
+ /** Is data source ready to use after initial loading */
187
+ isReady = false;
188
+ initPromise = null;
189
+ /**
190
+ * @constructor
191
+ * @param data - if string - data set path url or path to `cloud.js` metadata file
192
+ * - if Blob - single file data
193
+ * @param props - data source properties
194
+ */
195
+ constructor(data, props) {
196
+ super(props);
197
+ this.props = props;
198
+ this.data = data;
199
+ this.makeBaseUrl(this.data);
200
+ this.initPromise = this.init();
201
+ }
202
+ /** Initial data source loading */
203
+ async init() {
204
+ if (this.initPromise) {
205
+ await this.initPromise;
206
+ return;
207
+ }
208
+ this.metadata = await (0, import_core.load)(`${this.baseUrl}/cloud.js`, PotreeLoader);
209
+ await this.loadHierarchy();
210
+ this.isReady = true;
211
+ }
212
+ /** Is data set supported */
213
+ isSupported() {
214
+ var _a, _b, _c;
215
+ const { minor, major } = parseVersion(((_a = this.metadata) == null ? void 0 : _a.version) ?? "");
216
+ return this.isReady && major === 1 && minor < 2 && typeof ((_b = this.metadata) == null ? void 0 : _b.pointAttributes) === "string" && ["LAS", "LAZ"].includes((_c = this.metadata) == null ? void 0 : _c.pointAttributes);
217
+ }
218
+ /** Get content files extension */
219
+ getContentExtension() {
220
+ var _a;
221
+ if (!this.isReady) {
222
+ return null;
223
+ }
224
+ switch ((_a = this.metadata) == null ? void 0 : _a.pointAttributes) {
225
+ case "LAS":
226
+ return "las";
227
+ case "LAZ":
228
+ return "laz";
229
+ default:
230
+ return "bin";
231
+ }
232
+ }
233
+ /**
234
+ * Load octree node content
235
+ * @param path array of numbers between 0-7 specifying successive octree divisions.
236
+ * @return node content geometry or null if the node doesn't exist
237
+ */
238
+ async loadNodeContent(path) {
239
+ var _a;
240
+ await this.initPromise;
241
+ if (!this.isSupported()) {
242
+ return null;
243
+ }
244
+ const isAvailable = await this.isNodeAvailable(path);
245
+ if (isAvailable) {
246
+ return (0, import_core.load)(`${this.baseUrl}/${(_a = this.metadata) == null ? void 0 : _a.octreeDir}/r/r${path.join()}.${this.getContentExtension()}`, import_las.LASLoader);
247
+ }
248
+ return null;
249
+ }
250
+ /**
251
+ * Check if a node exists in the octree
252
+ * @param path array of numbers between 0-7 specifying successive octree divisions
253
+ * @returns true - the node does exist, false - the nodes doesn't exist
254
+ */
255
+ async isNodeAvailable(path) {
256
+ var _a;
257
+ if ((_a = this.metadata) == null ? void 0 : _a.hierarchy) {
258
+ return this.metadata.hierarchy.findIndex((item) => item[0] === `r${path.join()}`) !== -1;
259
+ }
260
+ if (!this.root) {
261
+ return false;
262
+ }
263
+ let currentParent = this.root;
264
+ let name = "";
265
+ let result = true;
266
+ for (const nodeLevel of path) {
267
+ const newName = `${name}${nodeLevel}`;
268
+ const node = currentParent.children.find((child) => child.name === newName);
269
+ if (node) {
270
+ currentParent = node;
271
+ name = newName;
272
+ } else {
273
+ result = false;
274
+ break;
275
+ }
276
+ }
277
+ return result;
278
+ }
279
+ /**
280
+ * Load data source hierarchy into tree of available nodes
281
+ */
282
+ async loadHierarchy() {
283
+ var _a;
284
+ this.root = await (0, import_core.load)(`${this.baseUrl}/${(_a = this.metadata) == null ? void 0 : _a.octreeDir}/r/r.hrc`, PotreeHierarchyChunkLoader);
285
+ }
286
+ /**
287
+ * Deduce base url from the input url sring
288
+ * @param data - data source input data
289
+ */
290
+ makeBaseUrl(data) {
291
+ this.baseUrl = typeof data === "string" ? (0, import_loader_utils.resolvePath)(data) : "";
292
+ if (this.baseUrl.endsWith("cloud.js")) {
293
+ this.baseUrl = this.baseUrl.substring(0, -8);
294
+ }
295
+ if (this.baseUrl.endsWith("/")) {
296
+ this.baseUrl = this.baseUrl.substring(0, -1);
297
+ }
298
+ }
299
+ };
300
+
301
+ // dist/potree-source.js
302
+ var VERSION3 = "1.7";
303
+ var PotreeSource = {
304
+ name: "Potree",
305
+ id: "potree",
306
+ module: "potree",
307
+ version: VERSION3,
308
+ extensions: ["bin", "las", "laz"],
309
+ mimeTypes: ["application/octet-stream"],
310
+ options: { url: void 0, potree: {} },
311
+ type: "potree",
312
+ fromUrl: true,
313
+ fromBlob: true,
314
+ testURL: (url) => url.endsWith(".js"),
315
+ createDataSource: (url, props) => new PotreeNodesSource(url, props)
316
+ };
156
317
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["index.js", "potree-loader.js", "parsers/parse-potree-hierarchy-chunk.js", "potree-hierarchy-chunk-loader.js", "parsers/parse-potree-bin.js", "potree-bin-loader.js"],
4
- "sourcesContent": ["export { PotreeLoader } from \"./potree-loader.js\";\nexport { PotreeHierarchyChunkLoader } from \"./potree-hierarchy-chunk-loader.js\";\nexport { PotreeBinLoader } from \"./potree-bin-loader.js\";\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright vis.gl contributors\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof \"4.3.0-alpha.3\" !== 'undefined' ? \"4.3.0-alpha.3\" : 'latest';\n/** Potree loader */\n// @ts-ignore\nexport const PotreeLoader = {\n dataType: null,\n batchType: null,\n name: 'potree',\n id: 'potree',\n module: 'potree',\n version: VERSION,\n extensions: ['json'],\n mimeTypes: ['application/json'],\n testText: (text) => text.indexOf('octreeDir') >= 0,\n parseTextSync: (text) => JSON.parse(text),\n options: {\n potree: {}\n }\n // @ts-ignore\n};\n", "// This file is derived from the Cesium code base under BSD 2-clause license\n// See LICENSE.md and https://github.com/potree/potree/blob/develop/LICENSE\n// type POTreeTileNode = POTreeNode;\n// load hierarchy\nexport function parsePotreeHierarchyChunk(arrayBuffer) {\n const tileHeaders = parseBinaryChunk(arrayBuffer);\n return buildHierarchy(tileHeaders);\n}\n// Parses the binary rows\nfunction parseBinaryChunk(arrayBuffer, byteOffset = 0) {\n const dataView = new DataView(arrayBuffer);\n const stack = [];\n // Get root mask\n // @ts-expect-error\n const topTileHeader = {};\n byteOffset = decodeRow(dataView, byteOffset, topTileHeader);\n stack.push(topTileHeader);\n const tileHeaders = [];\n while (stack.length > 0) {\n const snode = stack.shift();\n let mask = 1;\n for (let i = 0; i < 8; i++) {\n if (snode && (snode.header.childMask & mask) !== 0) {\n // @ts-expect-error\n const tileHeader = {};\n byteOffset = decodeRow(dataView, byteOffset, tileHeader);\n tileHeader.name = snode.name + i;\n // @ts-expect-error\n stack.push(tileHeader);\n tileHeaders.push(tileHeader);\n snode.header.childCount++;\n }\n mask = mask * 2;\n }\n if (byteOffset === dataView.byteLength) {\n break;\n }\n }\n return tileHeaders;\n}\nfunction decodeRow(dataView, byteOffset, tileHeader) {\n tileHeader.header = tileHeader.header || {};\n tileHeader.header.childMask = dataView.getUint8(byteOffset);\n tileHeader.header.childCount = 0;\n tileHeader.pointCount = dataView.getUint32(byteOffset + 1, true);\n tileHeader.name = '';\n byteOffset += 5;\n return byteOffset;\n}\n// Resolves the binary rows into a hierarchy (tree structure)\nfunction buildHierarchy(tileHeaders, options = {}) {\n const DEFAULT_OPTIONS = { spacing: 100 }; // TODO assert instead of default?\n options = { ...DEFAULT_OPTIONS, ...options };\n const topNode = tileHeaders[0];\n const nodes = {};\n for (const tileHeader of tileHeaders) {\n const { name } = tileHeader;\n const index = parseInt(name.charAt(name.length - 1), 10);\n const parentName = name.substring(0, name.length - 1);\n const parentNode = nodes[parentName];\n const level = name.length - 1;\n // assert(parentNode && level >= 0);\n tileHeader.level = level;\n tileHeader.hasChildren = tileHeader.header.childCount;\n tileHeader.children = [];\n tileHeader.childrenByIndex = new Array(8).fill(null);\n tileHeader.spacing = (options?.spacing || 0) / Math.pow(2, level);\n // tileHeader.boundingVolume = Utils.createChildAABB(parentNode.boundingBox, index);\n if (parentNode) {\n parentNode.children.push(tileHeader);\n parentNode.childrenByIndex[index] = tileHeader;\n }\n // Add the node to the map\n nodes[name] = tileHeader;\n }\n // First node is the root\n return topNode;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright vis.gl contributors\nimport { parsePotreeHierarchyChunk } from \"./parsers/parse-potree-hierarchy-chunk.js\";\n/** Potree hierarchy chunk loader */\n// @ts-ignore not a valid loader\nexport const PotreeHierarchyChunkLoader = {\n dataType: null,\n batchType: null,\n id: 'potree',\n name: 'potree Hierarchy Chunk',\n extensions: ['hrc'],\n mimeTypes: ['application/octet-stream'],\n // binary potree files have no header bytes, no content test function possible\n // test: ['...'],\n parse: async (arrayBuffer, options) => parsePotreeHierarchyChunk(arrayBuffer),\n parseSync: (arrayBuffer, options) => parsePotreeHierarchyChunk(arrayBuffer),\n binary: true\n // @ts-ignore\n};\n", "export function parsePotreeBin(arrayBuffer, byteOffset, options, index) {\n return null;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright vis.gl contributors\nimport { parsePotreeBin } from \"./parsers/parse-potree-bin.js\";\n/**\n * Loader for potree Binary Point Attributes\n * */\nexport const PotreeBinLoader = {\n dataType: null,\n batchType: null,\n name: 'potree Binary Point Attributes',\n id: 'potree',\n extensions: ['bin'],\n mimeTypes: ['application/octet-stream'],\n // Unfortunately binary potree files have no header bytes, no test possible\n // test: ['...'],\n parseSync,\n binary: true,\n options: {}\n // @ts-ignore\n};\nfunction parseSync(arrayBuffer, options) {\n const index = {};\n const byteOffset = 0;\n parsePotreeBin(arrayBuffer, byteOffset, options, index);\n return index;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,UAAU,OAAyC,kBAAkB;AAGpE,IAAM,eAAe;AAAA,EACxB,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,YAAY,CAAC,MAAM;AAAA,EACnB,WAAW,CAAC,kBAAkB;AAAA,EAC9B,UAAU,CAAC,SAAS,KAAK,QAAQ,WAAW,KAAK;AAAA,EACjD,eAAe,CAAC,SAAS,KAAK,MAAM,IAAI;AAAA,EACxC,SAAS;AAAA,IACL,QAAQ,CAAC;AAAA,EACb;AAAA;AAEJ;;;ACnBO,SAAS,0BAA0B,aAAa;AACnD,QAAM,cAAc,iBAAiB,WAAW;AAChD,SAAO,eAAe,WAAW;AACrC;AAEA,SAAS,iBAAiB,aAAa,aAAa,GAAG;AACnD,QAAM,WAAW,IAAI,SAAS,WAAW;AACzC,QAAM,QAAQ,CAAC;AAGf,QAAM,gBAAgB,CAAC;AACvB,eAAa,UAAU,UAAU,YAAY,aAAa;AAC1D,QAAM,KAAK,aAAa;AACxB,QAAM,cAAc,CAAC;AACrB,SAAO,MAAM,SAAS,GAAG;AACrB,UAAM,QAAQ,MAAM,MAAM;AAC1B,QAAI,OAAO;AACX,aAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AACxB,UAAI,UAAU,MAAM,OAAO,YAAY,UAAU,GAAG;AAEhD,cAAM,aAAa,CAAC;AACpB,qBAAa,UAAU,UAAU,YAAY,UAAU;AACvD,mBAAW,OAAO,MAAM,OAAO;AAE/B,cAAM,KAAK,UAAU;AACrB,oBAAY,KAAK,UAAU;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AA,EACN,YAAY,CAAC,KAAK;AAAA,EAClB,WAAW,CAAC,0BAA0B;AAAA;AAAA;AAAA,EAGtC,OAAO,OAAO,aAAa,YAAY,0BAA0B,WAAW;AAAA,EAC5E,WAAW,CAAC,aAAa,YAAY,0BAA0B,WAAW;AAAA,EAC1E,QAAQ;AAAA;AAEZ;;;ACnBO,SAAS,eAAe,aAAa,YAAY,SAAS,OAAO;AACpE,SAAO;AACX;;;ACKO,IAAM,kBAAkB;AAAA,EAC3B,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,YAAY,CAAC,KAAK;AAAA,EAClB,WAAW,CAAC,0BAA0B;AAAA;AAAA;AAAA,EAGtC;AAAA,EACA,QAAQ;AAAA,EACR,SAAS,CAAC;AAAA;AAEd;AACA,SAAS,UAAU,aAAa,SAAS;AACrC,QAAM,QAAQ,CAAC;AACf,QAAM,aAAa;AACnB,iBAAe,aAAa,YAAY,SAAS,KAAK;AACtD,SAAO;AACX;",
6
- "names": []
3
+ "sources": ["index.js", "potree-loader.js", "parsers/parse-potree-hierarchy-chunk.js", "potree-hierarchy-chunk-loader.js", "parsers/parse-potree-bin.js", "potree-bin-loader.js", "lib/potree-node-source.js", "utils/parse-version.js", "potree-source.js"],
4
+ "sourcesContent": ["export { PotreeLoader } from \"./potree-loader.js\";\nexport { PotreeHierarchyChunkLoader } from \"./potree-hierarchy-chunk-loader.js\";\nexport { PotreeBinLoader } from \"./potree-bin-loader.js\";\nexport { PotreeSource } from \"./potree-source.js\";\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright vis.gl contributors\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof \"4.3.0-alpha.5\" !== 'undefined' ? \"4.3.0-alpha.5\" : 'latest';\n/** Potree loader */\nexport const PotreeLoader = {\n dataType: null,\n batchType: null,\n name: 'potree metadata',\n id: 'potree',\n module: 'potree',\n version: VERSION,\n extensions: ['js'],\n mimeTypes: ['application/json'],\n testText: (text) => text.indexOf('octreeDir') >= 0,\n parse: (data) => JSON.parse(new TextDecoder().decode(data)),\n parseTextSync: (text) => JSON.parse(text),\n options: {\n potree: {}\n }\n};\n", "// This file is derived from the Cesium code base under BSD 2-clause license\n// See LICENSE.md and https://github.com/potree/potree/blob/develop/LICENSE\n/**\n * load hierarchy\n * @param arrayBuffer - binary index data\n * @returns root node\n **/\nexport function parsePotreeHierarchyChunk(arrayBuffer) {\n const tileHeaders = parseBinaryChunk(arrayBuffer);\n return buildHierarchy(tileHeaders);\n}\n/**\n * Parses the binary rows\n * @param arrayBuffer - binary index data to parse\n * @param byteOffset - byte offset to start from\n * @returns flat nodes array\n * */\nfunction parseBinaryChunk(arrayBuffer, byteOffset = 0) {\n const dataView = new DataView(arrayBuffer);\n const stack = [];\n // Get root mask\n // @ts-expect-error\n const topTileHeader = {};\n byteOffset = decodeRow(dataView, byteOffset, topTileHeader);\n stack.push(topTileHeader);\n const tileHeaders = [topTileHeader];\n while (stack.length > 0) {\n const snode = stack.shift();\n let mask = 1;\n for (let i = 0; i < 8; i++) {\n if (snode && (snode.header.childMask & mask) !== 0) {\n // @ts-expect-error\n const tileHeader = {};\n byteOffset = decodeRow(dataView, byteOffset, tileHeader);\n tileHeader.name = snode.name + i;\n stack.push(tileHeader);\n tileHeaders.push(tileHeader);\n snode.header.childCount++;\n }\n mask = mask * 2;\n }\n if (byteOffset === dataView.byteLength) {\n break;\n }\n }\n return tileHeaders;\n}\n/**\n * Reads next row from binary index file\n * @param dataView - index data\n * @param byteOffset - current offset in the index data\n * @param tileHeader - container to read to\n * @returns new offset\n */\nfunction decodeRow(dataView, byteOffset, tileHeader) {\n tileHeader.header = tileHeader.header || {};\n tileHeader.header.childMask = dataView.getUint8(byteOffset);\n tileHeader.header.childCount = 0;\n tileHeader.pointCount = dataView.getUint32(byteOffset + 1, true);\n tileHeader.name = '';\n byteOffset += 5;\n return byteOffset;\n}\n/** Resolves the binary rows into a hierarchy (tree structure) */\nfunction buildHierarchy(flatNodes, options = {}) {\n const DEFAULT_OPTIONS = { spacing: 100 }; // TODO assert instead of default?\n options = { ...DEFAULT_OPTIONS, ...options };\n const topNode = flatNodes[0];\n const nodes = {};\n for (const node of flatNodes) {\n const { name } = node;\n const index = parseInt(name.charAt(name.length - 1), 10);\n const parentName = name.substring(0, name.length - 1);\n const parentNode = nodes[parentName];\n const level = name.length - 1;\n // assert(parentNode && level >= 0);\n node.level = level;\n node.hasChildren = Boolean(node.header.childCount);\n node.children = [];\n node.childrenByIndex = new Array(8).fill(null);\n node.spacing = (options?.spacing || 0) / Math.pow(2, level);\n // tileHeader.boundingVolume = Utils.createChildAABB(parentNode.boundingBox, index);\n if (parentNode) {\n parentNode.children.push(node);\n parentNode.childrenByIndex[index] = node;\n }\n // Add the node to the map\n nodes[name] = node;\n }\n // First node is the root\n return topNode;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright vis.gl contributors\nimport { parsePotreeHierarchyChunk } from \"./parsers/parse-potree-hierarchy-chunk.js\";\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof \"4.3.0-alpha.5\" !== 'undefined' ? \"4.3.0-alpha.5\" : 'latest';\n/** Potree hierarchy chunk loader */\nexport const PotreeHierarchyChunkLoader = {\n dataType: null,\n batchType: null,\n name: 'potree Hierarchy Chunk',\n id: 'potree-hrc',\n module: 'potree',\n version: VERSION,\n extensions: ['hrc'],\n mimeTypes: ['application/octet-stream'],\n // binary potree files have no header bytes, no content test function possible\n // test: ['...'],\n parse: async (arrayBuffer, options) => parsePotreeHierarchyChunk(arrayBuffer),\n parseSync: (arrayBuffer, options) => parsePotreeHierarchyChunk(arrayBuffer),\n options: {\n potree: {}\n },\n binary: true\n};\n", "export function parsePotreeBin(arrayBuffer, byteOffset, options, index) {\n return null;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright vis.gl contributors\nimport { parsePotreeBin } from \"./parsers/parse-potree-bin.js\";\n/**\n * Loader for potree Binary Point Attributes\n * */\nexport const PotreeBinLoader = {\n dataType: null,\n batchType: null,\n name: 'potree Binary Point Attributes',\n id: 'potree',\n extensions: ['bin'],\n mimeTypes: ['application/octet-stream'],\n // Unfortunately binary potree files have no header bytes, no test possible\n // test: ['...'],\n parseSync,\n binary: true,\n options: {}\n // @ts-ignore\n};\nfunction parseSync(arrayBuffer, options) {\n const index = {};\n const byteOffset = 0;\n parsePotreeBin(arrayBuffer, byteOffset, options, index);\n return index;\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { load } from '@loaders.gl/core';\nimport { DataSource, resolvePath } from '@loaders.gl/loader-utils';\nimport { LASLoader } from '@loaders.gl/las';\nimport { PotreeHierarchyChunkLoader } from \"../potree-hierarchy-chunk-loader.js\";\nimport { PotreeLoader } from \"../potree-loader.js\";\nimport { parseVersion } from \"../utils/parse-version.js\";\n/**\n * A Potree data source\n * @version 1.0 - https://github.com/potree/potree/blob/1.0RC/docs/file_format.md\n * @version 1.7 - https://github.com/potree/potree/blob/1.7/docs/potree-file-format.md\n * @note Point cloud nodes tile source\n */\nexport class PotreeNodesSource extends DataSource {\n /** Dataset base URL */\n baseUrl = '';\n /** Input data: string - dataset url, blob - single file data */\n data;\n /** Input props */\n props;\n /** Meta information from `cloud.js` */\n metadata = null;\n /** Root node */\n root = null;\n /** Is data source ready to use after initial loading */\n isReady = false;\n initPromise = null;\n /**\n * @constructor\n * @param data - if string - data set path url or path to `cloud.js` metadata file\n * - if Blob - single file data\n * @param props - data source properties\n */\n constructor(data, props) {\n super(props);\n this.props = props;\n this.data = data;\n this.makeBaseUrl(this.data);\n this.initPromise = this.init();\n }\n /** Initial data source loading */\n async init() {\n if (this.initPromise) {\n await this.initPromise;\n return;\n }\n this.metadata = await load(`${this.baseUrl}/cloud.js`, PotreeLoader);\n await this.loadHierarchy();\n this.isReady = true;\n }\n /** Is data set supported */\n isSupported() {\n const { minor, major } = parseVersion(this.metadata?.version ?? '');\n return (this.isReady &&\n major === 1 &&\n minor < 2 &&\n typeof this.metadata?.pointAttributes === 'string' &&\n ['LAS', 'LAZ'].includes(this.metadata?.pointAttributes));\n }\n /** Get content files extension */\n getContentExtension() {\n if (!this.isReady) {\n return null;\n }\n switch (this.metadata?.pointAttributes) {\n case 'LAS':\n return 'las';\n case 'LAZ':\n return 'laz';\n default:\n return 'bin';\n }\n }\n /**\n * Load octree node content\n * @param path array of numbers between 0-7 specifying successive octree divisions.\n * @return node content geometry or null if the node doesn't exist\n */\n async loadNodeContent(path) {\n await this.initPromise;\n if (!this.isSupported()) {\n return null;\n }\n const isAvailable = await this.isNodeAvailable(path);\n if (isAvailable) {\n return load(`${this.baseUrl}/${this.metadata\n ?.octreeDir}/r/r${path.join()}.${this.getContentExtension()}`, LASLoader);\n }\n return null;\n }\n /**\n * Check if a node exists in the octree\n * @param path array of numbers between 0-7 specifying successive octree divisions\n * @returns true - the node does exist, false - the nodes doesn't exist\n */\n async isNodeAvailable(path) {\n if (this.metadata?.hierarchy) {\n return this.metadata.hierarchy.findIndex((item) => item[0] === `r${path.join()}`) !== -1;\n }\n if (!this.root) {\n return false;\n }\n let currentParent = this.root;\n let name = '';\n let result = true;\n for (const nodeLevel of path) {\n const newName = `${name}${nodeLevel}`;\n const node = currentParent.children.find((child) => child.name === newName);\n if (node) {\n currentParent = node;\n name = newName;\n }\n else {\n result = false;\n break;\n }\n }\n return result;\n }\n /**\n * Load data source hierarchy into tree of available nodes\n */\n async loadHierarchy() {\n this.root = await load(`${this.baseUrl}/${this.metadata?.octreeDir}/r/r.hrc`, PotreeHierarchyChunkLoader);\n }\n /**\n * Deduce base url from the input url sring\n * @param data - data source input data\n */\n makeBaseUrl(data) {\n this.baseUrl = typeof data === 'string' ? resolvePath(data) : '';\n if (this.baseUrl.endsWith('cloud.js')) {\n this.baseUrl = this.baseUrl.substring(0, -8);\n }\n if (this.baseUrl.endsWith('/')) {\n this.baseUrl = this.baseUrl.substring(0, -1);\n }\n }\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nexport function parseVersion(version) {\n const parts = version.split('.').map(Number);\n return { major: parts[0], minor: parts[1] };\n}\n", "// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport { PotreeNodesSource } from \"./lib/potree-node-source.js\";\nconst VERSION = '1.7';\n/**\n * Creates point cloud data sources for Potree urls\n */\nexport const PotreeSource = {\n name: 'Potree',\n id: 'potree',\n module: 'potree',\n version: VERSION,\n extensions: ['bin', 'las', 'laz'],\n mimeTypes: ['application/octet-stream'],\n options: { url: undefined, potree: {} },\n type: 'potree',\n fromUrl: true,\n fromBlob: true,\n testURL: (url) => url.endsWith('.js'),\n createDataSource: (url, props) => new PotreeNodesSource(url, props)\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,IAAM,UAAU,OAAyC,kBAAkB;AAEpE,IAAM,eAAe;AAAA,EACxB,UAAU;AAAA,EACV,WAAW;AAAA,EACX,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,YAAY,CAAC,IAAI;AAAA,EACjB,WAAW,CAAC,kBAAkB;AAAA,EAC9B,UAAU,CAAC,SAAS,KAAK,QAAQ,WAAW,KAAK;AAAA,EACjD,OAAO,CAAC,SAAS,KAAK,MAAM,IAAI,YAAY,EAAE,OAAO,IAAI,CAAC;AAAA,EAC1D,eAAe,CAAC,SAAS,KAAK,MAAM,IAAI;AAAA,EACxC,SAAS;AAAA,IACL,QAAQ,CAAC;AAAA,EACb;AACJ;;;ACfO,SAAS,0BAA0B,aAAa;AACnD,QAAM,cAAc,iBAAiB,WAAW;AAChD,SAAO,eAAe,WAAW;AACrC;AAOA,SAAS,iBAA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K,UAAU,OAAO,SAAS,eAAW,iCAAY,IAAI,IAAI;AAC9D,QAAI,KAAK,QAAQ,SAAS,UAAU,GAAG;AACnC,WAAK,UAAU,KAAK,QAAQ,UAAU,GAAG,EAAE;AAAA,IAC/C;AACA,QAAI,KAAK,QAAQ,SAAS,GAAG,GAAG;AAC5B,WAAK,UAAU,KAAK,QAAQ,UAAU,GAAG,EAAE;AAAA,IAC/C;AAAA,EACJ;AACJ;;;AExIA,IAAMC,WAAU;AAIT,IAAM,eAAe;AAAA,EACxB,MAAM;AAAA,EACN,IAAI;AAAA,EACJ,QAAQ;AAAA,EACR,SAASA;AAAA,EACT,YAAY,CAAC,OAAO,OAAO,KAAK;AAAA,EAChC,WAAW,CAAC,0BAA0B;AAAA,EACtC,SAAS,EAAE,KAAK,QAAW,QAAQ,CAAC,EAAE;AAAA,EACtC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU;AAAA,EACV,SAAS,CAAC,QAAQ,IAAI,SAAS,KAAK;AAAA,EACpC,kBAAkB,CAAC,KAAK,UAAU,IAAI,kBAAkB,KAAK,KAAK;AACtE;",
6
+ "names": ["VERSION", "VERSION"]
7
7
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { PotreeLoader } from "./potree-loader.js";
2
2
  export { PotreeHierarchyChunkLoader } from "./potree-hierarchy-chunk-loader.js";
3
3
  export { PotreeBinLoader } from "./potree-bin-loader.js";
4
+ export { PotreeSource } from "./potree-source.js";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAC7C,OAAO,EAAC,0BAA0B,EAAC,2CAAwC;AAC3E,OAAO,EAAC,eAAe,EAAC,+BAA4B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,2BAAwB;AAC7C,OAAO,EAAC,0BAA0B,EAAC,2CAAwC;AAC3E,OAAO,EAAC,eAAe,EAAC,+BAA4B;AACpD,OAAO,EAAC,YAAY,EAAC,2BAAwB"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { PotreeLoader } from "./potree-loader.js";
2
2
  export { PotreeHierarchyChunkLoader } from "./potree-hierarchy-chunk-loader.js";
3
3
  export { PotreeBinLoader } from "./potree-bin-loader.js";
4
+ export { PotreeSource } from "./potree-source.js";
@@ -0,0 +1,66 @@
1
+ import { MeshGeometry } from '@loaders.gl/schema';
2
+ import { DataSource, DataSourceProps, LoaderOptions } from '@loaders.gl/loader-utils';
3
+ import { PotreeMetadata } from "../types/potree-metadata.js";
4
+ import { POTreeNode } from "../parsers/parse-potree-hierarchy-chunk.js";
5
+ export type PotreeNodesSourceProps = DataSourceProps & {
6
+ attributions?: string[];
7
+ potree?: {
8
+ loadOptions?: LoaderOptions;
9
+ };
10
+ };
11
+ /**
12
+ * A Potree data source
13
+ * @version 1.0 - https://github.com/potree/potree/blob/1.0RC/docs/file_format.md
14
+ * @version 1.7 - https://github.com/potree/potree/blob/1.7/docs/potree-file-format.md
15
+ * @note Point cloud nodes tile source
16
+ */
17
+ export declare class PotreeNodesSource extends DataSource {
18
+ /** Dataset base URL */
19
+ baseUrl: string;
20
+ /** Input data: string - dataset url, blob - single file data */
21
+ data: string | Blob;
22
+ /** Input props */
23
+ props: PotreeNodesSourceProps;
24
+ /** Meta information from `cloud.js` */
25
+ metadata: PotreeMetadata | null;
26
+ /** Root node */
27
+ root: POTreeNode | null;
28
+ /** Is data source ready to use after initial loading */
29
+ isReady: boolean;
30
+ private initPromise;
31
+ /**
32
+ * @constructor
33
+ * @param data - if string - data set path url or path to `cloud.js` metadata file
34
+ * - if Blob - single file data
35
+ * @param props - data source properties
36
+ */
37
+ constructor(data: string | Blob, props: PotreeNodesSourceProps);
38
+ /** Initial data source loading */
39
+ init(): Promise<void>;
40
+ /** Is data set supported */
41
+ isSupported(): boolean;
42
+ /** Get content files extension */
43
+ getContentExtension(): string | null;
44
+ /**
45
+ * Load octree node content
46
+ * @param path array of numbers between 0-7 specifying successive octree divisions.
47
+ * @return node content geometry or null if the node doesn't exist
48
+ */
49
+ loadNodeContent(path: number[]): Promise<MeshGeometry | null>;
50
+ /**
51
+ * Check if a node exists in the octree
52
+ * @param path array of numbers between 0-7 specifying successive octree divisions
53
+ * @returns true - the node does exist, false - the nodes doesn't exist
54
+ */
55
+ isNodeAvailable(path: number[]): Promise<boolean>;
56
+ /**
57
+ * Load data source hierarchy into tree of available nodes
58
+ */
59
+ private loadHierarchy;
60
+ /**
61
+ * Deduce base url from the input url sring
62
+ * @param data - data source input data
63
+ */
64
+ private makeBaseUrl;
65
+ }
66
+ //# sourceMappingURL=potree-node-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"potree-node-source.d.ts","sourceRoot":"","sources":["../../src/lib/potree-node-source.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAC,UAAU,EAAE,eAAe,EAAE,aAAa,EAAc,MAAM,0BAA0B,CAAC;AAEjG,OAAO,EAAC,cAAc,EAAC,oCAAiC;AACxD,OAAO,EAAC,UAAU,EAAC,mDAAgD;AAKnE,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAAG;IACrD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,CAAC,EAAE;QACP,WAAW,CAAC,EAAE,aAAa,CAAC;KAE7B,CAAC;CACH,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,UAAU;IAC/C,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAM;IACrB,gEAAgE;IAChE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,kBAAkB;IAClB,KAAK,EAAE,sBAAsB,CAAC;IAC9B,uCAAuC;IACvC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAQ;IACvC,gBAAgB;IAChB,IAAI,EAAE,UAAU,GAAG,IAAI,CAAQ;IAC/B,wDAAwD;IACxD,OAAO,UAAS;IAEhB,OAAO,CAAC,WAAW,CAA8B;IAEjD;;;;;OAKG;gBACS,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,sBAAsB;IAS9D,kCAAkC;IAC5B,IAAI;IAUV,4BAA4B;IAC5B,WAAW,IAAI,OAAO;IAWtB,kCAAkC;IAClC,mBAAmB,IAAI,MAAM,GAAG,IAAI;IAcpC;;;;OAIG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAkBnE;;;;OAIG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAyBvD;;OAEG;YACW,aAAa;IAO3B;;;OAGG;IACH,OAAO,CAAC,WAAW;CASpB"}
@@ -0,0 +1,141 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ import { load } from '@loaders.gl/core';
5
+ import { DataSource, resolvePath } from '@loaders.gl/loader-utils';
6
+ import { LASLoader } from '@loaders.gl/las';
7
+ import { PotreeHierarchyChunkLoader } from "../potree-hierarchy-chunk-loader.js";
8
+ import { PotreeLoader } from "../potree-loader.js";
9
+ import { parseVersion } from "../utils/parse-version.js";
10
+ /**
11
+ * A Potree data source
12
+ * @version 1.0 - https://github.com/potree/potree/blob/1.0RC/docs/file_format.md
13
+ * @version 1.7 - https://github.com/potree/potree/blob/1.7/docs/potree-file-format.md
14
+ * @note Point cloud nodes tile source
15
+ */
16
+ export class PotreeNodesSource extends DataSource {
17
+ /** Dataset base URL */
18
+ baseUrl = '';
19
+ /** Input data: string - dataset url, blob - single file data */
20
+ data;
21
+ /** Input props */
22
+ props;
23
+ /** Meta information from `cloud.js` */
24
+ metadata = null;
25
+ /** Root node */
26
+ root = null;
27
+ /** Is data source ready to use after initial loading */
28
+ isReady = false;
29
+ initPromise = null;
30
+ /**
31
+ * @constructor
32
+ * @param data - if string - data set path url or path to `cloud.js` metadata file
33
+ * - if Blob - single file data
34
+ * @param props - data source properties
35
+ */
36
+ constructor(data, props) {
37
+ super(props);
38
+ this.props = props;
39
+ this.data = data;
40
+ this.makeBaseUrl(this.data);
41
+ this.initPromise = this.init();
42
+ }
43
+ /** Initial data source loading */
44
+ async init() {
45
+ if (this.initPromise) {
46
+ await this.initPromise;
47
+ return;
48
+ }
49
+ this.metadata = await load(`${this.baseUrl}/cloud.js`, PotreeLoader);
50
+ await this.loadHierarchy();
51
+ this.isReady = true;
52
+ }
53
+ /** Is data set supported */
54
+ isSupported() {
55
+ const { minor, major } = parseVersion(this.metadata?.version ?? '');
56
+ return (this.isReady &&
57
+ major === 1 &&
58
+ minor < 2 &&
59
+ typeof this.metadata?.pointAttributes === 'string' &&
60
+ ['LAS', 'LAZ'].includes(this.metadata?.pointAttributes));
61
+ }
62
+ /** Get content files extension */
63
+ getContentExtension() {
64
+ if (!this.isReady) {
65
+ return null;
66
+ }
67
+ switch (this.metadata?.pointAttributes) {
68
+ case 'LAS':
69
+ return 'las';
70
+ case 'LAZ':
71
+ return 'laz';
72
+ default:
73
+ return 'bin';
74
+ }
75
+ }
76
+ /**
77
+ * Load octree node content
78
+ * @param path array of numbers between 0-7 specifying successive octree divisions.
79
+ * @return node content geometry or null if the node doesn't exist
80
+ */
81
+ async loadNodeContent(path) {
82
+ await this.initPromise;
83
+ if (!this.isSupported()) {
84
+ return null;
85
+ }
86
+ const isAvailable = await this.isNodeAvailable(path);
87
+ if (isAvailable) {
88
+ return load(`${this.baseUrl}/${this.metadata
89
+ ?.octreeDir}/r/r${path.join()}.${this.getContentExtension()}`, LASLoader);
90
+ }
91
+ return null;
92
+ }
93
+ /**
94
+ * Check if a node exists in the octree
95
+ * @param path array of numbers between 0-7 specifying successive octree divisions
96
+ * @returns true - the node does exist, false - the nodes doesn't exist
97
+ */
98
+ async isNodeAvailable(path) {
99
+ if (this.metadata?.hierarchy) {
100
+ return this.metadata.hierarchy.findIndex((item) => item[0] === `r${path.join()}`) !== -1;
101
+ }
102
+ if (!this.root) {
103
+ return false;
104
+ }
105
+ let currentParent = this.root;
106
+ let name = '';
107
+ let result = true;
108
+ for (const nodeLevel of path) {
109
+ const newName = `${name}${nodeLevel}`;
110
+ const node = currentParent.children.find((child) => child.name === newName);
111
+ if (node) {
112
+ currentParent = node;
113
+ name = newName;
114
+ }
115
+ else {
116
+ result = false;
117
+ break;
118
+ }
119
+ }
120
+ return result;
121
+ }
122
+ /**
123
+ * Load data source hierarchy into tree of available nodes
124
+ */
125
+ async loadHierarchy() {
126
+ this.root = await load(`${this.baseUrl}/${this.metadata?.octreeDir}/r/r.hrc`, PotreeHierarchyChunkLoader);
127
+ }
128
+ /**
129
+ * Deduce base url from the input url sring
130
+ * @param data - data source input data
131
+ */
132
+ makeBaseUrl(data) {
133
+ this.baseUrl = typeof data === 'string' ? resolvePath(data) : '';
134
+ if (this.baseUrl.endsWith('cloud.js')) {
135
+ this.baseUrl = this.baseUrl.substring(0, -8);
136
+ }
137
+ if (this.baseUrl.endsWith('/')) {
138
+ this.baseUrl = this.baseUrl.substring(0, -1);
139
+ }
140
+ }
141
+ }
@@ -1,16 +1,35 @@
1
- /** @todo these types are an incorrect mess */
1
+ /** Node metadata from index file */
2
2
  export type POTreeTileHeader = {
3
+ /** Number of child nodes */
3
4
  childCount: number;
5
+ /** Human readable name */
4
6
  name: string;
7
+ /** Child availability mask */
5
8
  childMask: number;
6
9
  };
7
- /** @todo these types are an incorrect mess */
10
+ /** Hierarchical potree node structure */
8
11
  export type POTreeNode = {
12
+ /** Index data */
9
13
  header: POTreeTileHeader;
14
+ /** Human readable name */
10
15
  name: string;
16
+ /** Number of points */
11
17
  pointCount: number;
18
+ /** Node's level in the tree */
19
+ level: number;
20
+ /** Has children */
21
+ hasChildren: boolean;
22
+ /** Space between points */
23
+ spacing: number;
24
+ /** Available children */
12
25
  children: POTreeNode[];
26
+ /** All children including unavailable */
13
27
  childrenByIndex: POTreeNode[];
14
28
  };
29
+ /**
30
+ * load hierarchy
31
+ * @param arrayBuffer - binary index data
32
+ * @returns root node
33
+ **/
15
34
  export declare function parsePotreeHierarchyChunk(arrayBuffer: ArrayBuffer): POTreeNode;
16
35
  //# sourceMappingURL=parse-potree-hierarchy-chunk.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-potree-hierarchy-chunk.d.ts","sourceRoot":"","sources":["../../src/parsers/parse-potree-hierarchy-chunk.ts"],"names":[],"mappings":"AAwDA,8CAA8C;AAC9C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,8CAA8C;AAC9C,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,gBAAgB,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,eAAe,EAAE,UAAU,EAAE,CAAC;CAC/B,CAAC;AAKF,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,WAAW,cAGjE"}
1
+ {"version":3,"file":"parse-potree-hierarchy-chunk.d.ts","sourceRoot":"","sources":["../../src/parsers/parse-potree-hierarchy-chunk.ts"],"names":[],"mappings":"AAwDA,oCAAoC;AACpC,MAAM,MAAM,gBAAgB,GAAG;IAC7B,4BAA4B;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,yCAAyC;AACzC,MAAM,MAAM,UAAU,GAAG;IACvB,iBAAiB;IACjB,MAAM,EAAE,gBAAgB,CAA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