@loaders.gl/potree 4.3.0-alpha.5 → 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.
package/dist/index.cjs CHANGED
@@ -22,12 +22,13 @@ 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.4" : "latest";
31
+ var VERSION = true ? "4.3.0-alpha.5" : "latest";
31
32
  var PotreeLoader = {
32
33
  dataType: null,
33
34
  batchType: null,
@@ -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,33 +87,33 @@ 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
115
- var VERSION2 = true ? "4.3.0-alpha.4" : "latest";
116
+ var VERSION2 = true ? "4.3.0-alpha.5" : "latest";
116
117
  var PotreeHierarchyChunkLoader = {
117
118
  dataType: null,
118
119
  batchType: null,
@@ -158,4 +159,159 @@ function parseSync(arrayBuffer, options) {
158
159
  parsePotreeBin(arrayBuffer, byteOffset, options, index);
159
160
  return index;
160
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
+ };
161
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.4\" !== 'undefined' ? \"4.3.0-alpha.4\" : '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// 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// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof \"4.3.0-alpha.4\" !== 'undefined' ? \"4.3.0-alpha.4\" : '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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;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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ACpE,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": ["VERSION"]
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,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,aAAa;AAClC,SAAO,MAAM,SAAS,GAAG;AACrB,UAAM,QAA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AAA,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";
@@ -47,16 +47,16 @@ export declare class PotreeNodesSource extends DataSource {
47
47
  * @return node content geometry or null if the node doesn't exist
48
48
  */
49
49
  loadNodeContent(path: number[]): Promise<MeshGeometry | null>;
50
- /**
51
- * Load data source hierarchy into tree of available nodes
52
- */
53
- loadHierarchy(): Promise<void>;
54
50
  /**
55
51
  * Check if a node exists in the octree
56
52
  * @param path array of numbers between 0-7 specifying successive octree divisions
57
53
  * @returns true - the node does exist, false - the nodes doesn't exist
58
54
  */
59
55
  isNodeAvailable(path: number[]): Promise<boolean>;
56
+ /**
57
+ * Load data source hierarchy into tree of available nodes
58
+ */
59
+ private loadHierarchy;
60
60
  /**
61
61
  * Deduce base url from the input url sring
62
62
  * @param data - data source input data
@@ -1 +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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AAE,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"}
@@ -42,6 +42,10 @@ export class PotreeNodesSource extends DataSource {
42
42
  }
43
43
  /** Initial data source loading */
44
44
  async init() {
45
+ if (this.initPromise) {
46
+ await this.initPromise;
47
+ return;
48
+ }
45
49
  this.metadata = await load(`${this.baseUrl}/cloud.js`, PotreeLoader);
46
50
  await this.loadHierarchy();
47
51
  this.isReady = true;
@@ -86,13 +90,6 @@ export class PotreeNodesSource extends DataSource {
86
90
  }
87
91
  return null;
88
92
  }
89
- /**
90
- * Load data source hierarchy into tree of available nodes
91
- */
92
- async loadHierarchy() {
93
- await this.initPromise;
94
- this.root = await load(`${this.baseUrl}/${this.metadata?.octreeDir}/r/r.hrc`, PotreeHierarchyChunkLoader);
95
- }
96
93
  /**
97
94
  * Check if a node exists in the octree
98
95
  * @param path array of numbers between 0-7 specifying successive octree divisions
@@ -122,6 +119,12 @@ export class PotreeNodesSource extends DataSource {
122
119
  }
123
120
  return result;
124
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
+ }
125
128
  /**
126
129
  * Deduce base url from the input url sring
127
130
  * @param data - data source input data
@@ -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,CAAC;IACzB,0BAA0B;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,uBAAuB;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,yCAAyC;IACzC,eAAe,EAAE,UAAU,EAAE,CAAC;CAC/B,CAAC;AAEF;;;;IAII;AACJ,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,WAAW,GAAG,UAAU,CAG9E"}
@@ -1,12 +1,20 @@
1
1
  // This file is derived from the Cesium code base under BSD 2-clause license
2
2
  // See LICENSE.md and https://github.com/potree/potree/blob/develop/LICENSE
3
- // type POTreeTileNode = POTreeNode;
4
- // load hierarchy
3
+ /**
4
+ * load hierarchy
5
+ * @param arrayBuffer - binary index data
6
+ * @returns root node
7
+ **/
5
8
  export function parsePotreeHierarchyChunk(arrayBuffer) {
6
9
  const tileHeaders = parseBinaryChunk(arrayBuffer);
7
10
  return buildHierarchy(tileHeaders);
8
11
  }
9
- // Parses the binary rows
12
+ /**
13
+ * Parses the binary rows
14
+ * @param arrayBuffer - binary index data to parse
15
+ * @param byteOffset - byte offset to start from
16
+ * @returns flat nodes array
17
+ * */
10
18
  function parseBinaryChunk(arrayBuffer, byteOffset = 0) {
11
19
  const dataView = new DataView(arrayBuffer);
12
20
  const stack = [];
@@ -15,7 +23,7 @@ function parseBinaryChunk(arrayBuffer, byteOffset = 0) {
15
23
  const topTileHeader = {};
16
24
  byteOffset = decodeRow(dataView, byteOffset, topTileHeader);
17
25
  stack.push(topTileHeader);
18
- const tileHeaders = [];
26
+ const tileHeaders = [topTileHeader];
19
27
  while (stack.length > 0) {
20
28
  const snode = stack.shift();
21
29
  let mask = 1;
@@ -25,7 +33,6 @@ function parseBinaryChunk(arrayBuffer, byteOffset = 0) {
25
33
  const tileHeader = {};
26
34
  byteOffset = decodeRow(dataView, byteOffset, tileHeader);
27
35
  tileHeader.name = snode.name + i;
28
- // @ts-expect-error
29
36
  stack.push(tileHeader);
30
37
  tileHeaders.push(tileHeader);
31
38
  snode.header.childCount++;
@@ -38,6 +45,13 @@ function parseBinaryChunk(arrayBuffer, byteOffset = 0) {
38
45
  }
39
46
  return tileHeaders;
40
47
  }
48
+ /**
49
+ * Reads next row from binary index file
50
+ * @param dataView - index data
51
+ * @param byteOffset - current offset in the index data
52
+ * @param tileHeader - container to read to
53
+ * @returns new offset
54
+ */
41
55
  function decodeRow(dataView, byteOffset, tileHeader) {
42
56
  tileHeader.header = tileHeader.header || {};
43
57
  tileHeader.header.childMask = dataView.getUint8(byteOffset);
@@ -47,31 +61,31 @@ function decodeRow(dataView, byteOffset, tileHeader) {
47
61
  byteOffset += 5;
48
62
  return byteOffset;
49
63
  }
50
- // Resolves the binary rows into a hierarchy (tree structure)
51
- function buildHierarchy(tileHeaders, options = {}) {
64
+ /** Resolves the binary rows into a hierarchy (tree structure) */
65
+ function buildHierarchy(flatNodes, options = {}) {
52
66
  const DEFAULT_OPTIONS = { spacing: 100 }; // TODO assert instead of default?
53
67
  options = { ...DEFAULT_OPTIONS, ...options };
54
- const topNode = tileHeaders[0];
68
+ const topNode = flatNodes[0];
55
69
  const nodes = {};
56
- for (const tileHeader of tileHeaders) {
57
- const { name } = tileHeader;
70
+ for (const node of flatNodes) {
71
+ const { name } = node;
58
72
  const index = parseInt(name.charAt(name.length - 1), 10);
59
73
  const parentName = name.substring(0, name.length - 1);
60
74
  const parentNode = nodes[parentName];
61
75
  const level = name.length - 1;
62
76
  // assert(parentNode && level >= 0);
63
- tileHeader.level = level;
64
- tileHeader.hasChildren = tileHeader.header.childCount;
65
- tileHeader.children = [];
66
- tileHeader.childrenByIndex = new Array(8).fill(null);
67
- tileHeader.spacing = (options?.spacing || 0) / Math.pow(2, level);
77
+ node.level = level;
78
+ node.hasChildren = Boolean(node.header.childCount);
79
+ node.children = [];
80
+ node.childrenByIndex = new Array(8).fill(null);
81
+ node.spacing = (options?.spacing || 0) / Math.pow(2, level);
68
82
  // tileHeader.boundingVolume = Utils.createChildAABB(parentNode.boundingBox, index);
69
83
  if (parentNode) {
70
- parentNode.children.push(tileHeader);
71
- parentNode.childrenByIndex[index] = tileHeader;
84
+ parentNode.children.push(node);
85
+ parentNode.childrenByIndex[index] = node;
72
86
  }
73
87
  // Add the node to the map
74
- nodes[name] = tileHeader;
88
+ nodes[name] = node;
75
89
  }
76
90
  // First node is the root
77
91
  return topNode;
@@ -4,7 +4,7 @@
4
4
  import { parsePotreeHierarchyChunk } from "./parsers/parse-potree-hierarchy-chunk.js";
5
5
  // __VERSION__ is injected by babel-plugin-version-inline
6
6
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
7
- const VERSION = typeof "4.3.0-alpha.4" !== 'undefined' ? "4.3.0-alpha.4" : 'latest';
7
+ const VERSION = typeof "4.3.0-alpha.5" !== 'undefined' ? "4.3.0-alpha.5" : 'latest';
8
8
  /** Potree hierarchy chunk loader */
9
9
  export const PotreeHierarchyChunkLoader = {
10
10
  dataType: null,
@@ -3,7 +3,7 @@
3
3
  // Copyright vis.gl contributors
4
4
  // __VERSION__ is injected by babel-plugin-version-inline
5
5
  // @ts-ignore TS2304: Cannot find name '__VERSION__'.
6
- const VERSION = typeof "4.3.0-alpha.4" !== 'undefined' ? "4.3.0-alpha.4" : 'latest';
6
+ const VERSION = typeof "4.3.0-alpha.5" !== 'undefined' ? "4.3.0-alpha.5" : 'latest';
7
7
  /** Potree loader */
8
8
  export const PotreeLoader = {
9
9
  dataType: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loaders.gl/potree",
3
- "version": "4.3.0-alpha.5",
3
+ "version": "4.3.0-alpha.6",
4
4
  "description": "potree loaders for large point clouds.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -44,13 +44,13 @@
44
44
  "build-bundle-dev": "ocular-bundle ./bundle.ts --env=dev --output=dist/dist.dev.js"
45
45
  },
46
46
  "dependencies": {
47
- "@loaders.gl/las": "4.3.0-alpha.5",
48
- "@loaders.gl/math": "4.3.0-alpha.5",
49
- "@loaders.gl/schema": "4.3.0-alpha.5",
47
+ "@loaders.gl/las": "4.3.0-alpha.6",
48
+ "@loaders.gl/math": "4.3.0-alpha.6",
49
+ "@loaders.gl/schema": "4.3.0-alpha.6",
50
50
  "@math.gl/core": "^4.0.0"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@loaders.gl/core": "^4.0.0"
54
54
  },
55
- "gitHead": "b57553345b3cbf621c95ad9b22aa672217451f61"
55
+ "gitHead": "315f2e232fc4e6a477c41de800a54d3e3d957e8c"
56
56
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export {PotreeLoader} from './potree-loader';
2
2
  export {PotreeHierarchyChunkLoader} from './potree-hierarchy-chunk-loader';
3
3
  export {PotreeBinLoader} from './potree-bin-loader';
4
+ export {PotreeSource} from './potree-source';
@@ -59,6 +59,10 @@ export class PotreeNodesSource extends DataSource {
59
59
 
60
60
  /** Initial data source loading */
61
61
  async init() {
62
+ if (this.initPromise) {
63
+ await this.initPromise;
64
+ return;
65
+ }
62
66
  this.metadata = await load(`${this.baseUrl}/cloud.js`, PotreeLoader);
63
67
  await this.loadHierarchy();
64
68
  this.isReady = true;
@@ -114,17 +118,6 @@ export class PotreeNodesSource extends DataSource {
114
118
  return null;
115
119
  }
116
120
 
117
- /**
118
- * Load data source hierarchy into tree of available nodes
119
- */
120
- async loadHierarchy(): Promise<void> {
121
- await this.initPromise;
122
- this.root = await load(
123
- `${this.baseUrl}/${this.metadata?.octreeDir}/r/r.hrc`,
124
- PotreeHierarchyChunkLoader
125
- );
126
- }
127
-
128
121
  /**
129
122
  * Check if a node exists in the octree
130
123
  * @param path array of numbers between 0-7 specifying successive octree divisions
@@ -155,6 +148,16 @@ export class PotreeNodesSource extends DataSource {
155
148
  return result;
156
149
  }
157
150
 
151
+ /**
152
+ * Load data source hierarchy into tree of available nodes
153
+ */
154
+ private async loadHierarchy(): Promise<void> {
155
+ this.root = await load(
156
+ `${this.baseUrl}/${this.metadata?.octreeDir}/r/r.hrc`,
157
+ PotreeHierarchyChunkLoader
158
+ );
159
+ }
160
+
158
161
  /**
159
162
  * Deduce base url from the input url sring
160
163
  * @param data - data source input data