@loaders.gl/ply 4.0.0-alpha.4 → 4.0.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 (82) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +833 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/index.js +51 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/lib/get-ply-schema.js +28 -0
  10. package/dist/es5/lib/get-ply-schema.js.map +1 -0
  11. package/dist/es5/lib/normalize-ply.js +93 -0
  12. package/dist/es5/lib/normalize-ply.js.map +1 -0
  13. package/dist/es5/lib/parse-ply-in-batches.js +289 -0
  14. package/dist/es5/lib/parse-ply-in-batches.js.map +1 -0
  15. package/dist/es5/lib/parse-ply.js +348 -0
  16. package/dist/es5/lib/parse-ply.js.map +1 -0
  17. package/dist/es5/lib/ply-types.js +2 -0
  18. package/dist/es5/lib/ply-types.js.map +1 -0
  19. package/dist/es5/ply-loader.js +26 -0
  20. package/dist/es5/ply-loader.js.map +1 -0
  21. package/dist/es5/workers/ply-worker.js +6 -0
  22. package/dist/es5/workers/ply-worker.js.map +1 -0
  23. package/dist/esm/bundle.js +4 -0
  24. package/dist/esm/bundle.js.map +1 -0
  25. package/dist/esm/index.js +12 -0
  26. package/dist/esm/index.js.map +1 -0
  27. package/dist/esm/lib/get-ply-schema.js +22 -0
  28. package/dist/esm/lib/get-ply-schema.js.map +1 -0
  29. package/dist/esm/lib/normalize-ply.js +86 -0
  30. package/dist/esm/lib/normalize-ply.js.map +1 -0
  31. package/dist/esm/lib/parse-ply-in-batches.js +177 -0
  32. package/dist/esm/lib/parse-ply-in-batches.js.map +1 -0
  33. package/dist/esm/lib/parse-ply.js +319 -0
  34. package/dist/esm/lib/parse-ply.js.map +1 -0
  35. package/dist/esm/lib/ply-types.js +2 -0
  36. package/dist/esm/lib/ply-types.js.map +1 -0
  37. package/dist/esm/ply-loader.js +18 -0
  38. package/dist/esm/ply-loader.js.map +1 -0
  39. package/dist/esm/workers/ply-worker.js +4 -0
  40. package/dist/esm/workers/ply-worker.js.map +1 -0
  41. package/dist/index.d.ts +13 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +18 -11
  44. package/dist/lib/get-ply-schema.d.ts +10 -0
  45. package/dist/lib/get-ply-schema.d.ts.map +1 -0
  46. package/dist/lib/get-ply-schema.js +34 -24
  47. package/dist/lib/normalize-ply.d.ts +8 -0
  48. package/dist/lib/normalize-ply.d.ts.map +1 -0
  49. package/dist/lib/normalize-ply.js +76 -65
  50. package/dist/lib/parse-ply-in-batches.d.ts +8 -0
  51. package/dist/lib/parse-ply-in-batches.d.ts.map +1 -0
  52. package/dist/lib/parse-ply-in-batches.js +237 -202
  53. package/dist/lib/parse-ply.d.ts +11 -0
  54. package/dist/lib/parse-ply.d.ts.map +1 -0
  55. package/dist/lib/parse-ply.js +378 -299
  56. package/dist/lib/ply-types.d.ts +37 -0
  57. package/dist/lib/ply-types.d.ts.map +1 -0
  58. package/dist/lib/ply-types.js +2 -2
  59. package/dist/ply-loader.d.ts +10 -0
  60. package/dist/ply-loader.d.ts.map +1 -0
  61. package/dist/ply-loader.js +27 -18
  62. package/dist/ply-worker.js +240 -578
  63. package/dist/workers/ply-worker.d.ts +2 -0
  64. package/dist/workers/ply-worker.d.ts.map +1 -0
  65. package/dist/workers/ply-worker.js +5 -4
  66. package/package.json +9 -12
  67. package/src/index.ts +15 -10
  68. package/src/lib/get-ply-schema.ts +11 -10
  69. package/src/lib/normalize-ply.ts +34 -12
  70. package/src/lib/parse-ply-in-batches.ts +23 -26
  71. package/src/lib/parse-ply.ts +114 -55
  72. package/src/lib/ply-types.ts +21 -12
  73. package/src/ply-loader.ts +4 -3
  74. package/dist/bundle.js.map +0 -1
  75. package/dist/index.js.map +0 -1
  76. package/dist/lib/get-ply-schema.js.map +0 -1
  77. package/dist/lib/normalize-ply.js.map +0 -1
  78. package/dist/lib/parse-ply-in-batches.js.map +0 -1
  79. package/dist/lib/parse-ply.js.map +0 -1
  80. package/dist/lib/ply-types.js.map +0 -1
  81. package/dist/ply-loader.js.map +0 -1
  82. package/dist/workers/ply-worker.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,12 +1,19 @@
1
- import { PLYLoader as PLYWorkerLoader } from './ply-loader';
2
- import parsePLY from './lib/parse-ply';
3
- import parsePLYInBatches from './lib/parse-ply-in-batches';
4
- export { PLYWorkerLoader };
5
- export const PLYLoader = { ...PLYWorkerLoader,
6
- parse: async (arrayBuffer, options) => parsePLY(arrayBuffer, options),
7
- parseTextSync: parsePLY,
8
- parseSync: parsePLY,
9
- parseInBatches: parsePLYInBatches
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PLYLoader = exports.PLYWorkerLoader = void 0;
5
+ const ply_loader_1 = require("./ply-loader");
6
+ Object.defineProperty(exports, "PLYWorkerLoader", { enumerable: true, get: function () { return ply_loader_1.PLYLoader; } });
7
+ const parse_ply_1 = require("./lib/parse-ply");
8
+ const parse_ply_in_batches_1 = require("./lib/parse-ply-in-batches");
9
+ /**
10
+ * Loader for PLY - Polygon File Format
11
+ */
12
+ exports.PLYLoader = {
13
+ ...ply_loader_1.PLYLoader,
14
+ // Note: parsePLY supports both text and binary
15
+ parse: async (arrayBuffer, options) => (0, parse_ply_1.parsePLY)(arrayBuffer, options?.ply),
16
+ parseTextSync: (arrayBuffer, options) => (0, parse_ply_1.parsePLY)(arrayBuffer, options?.ply),
17
+ parseSync: (arrayBuffer, options) => (0, parse_ply_1.parsePLY)(arrayBuffer, options?.ply),
18
+ parseInBatches: (arrayBuffer, options) => (0, parse_ply_in_batches_1.parsePLYInBatches)(arrayBuffer, options?.ply)
10
19
  };
11
- export const _typecheckPLYLoader = PLYLoader;
12
- //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ import { Schema, MeshAttributes } from '@loaders.gl/schema';
2
+ import type { PLYHeader } from './ply-types';
3
+ /**
4
+ * Gets schema from PLY header
5
+ * @param plyHeader
6
+ * @param metadata
7
+ * @returns Schema
8
+ */
9
+ export declare function getPLYSchema(plyHeader: PLYHeader, attributes: MeshAttributes): Schema;
10
+ //# sourceMappingURL=get-ply-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-ply-schema.d.ts","sourceRoot":"","sources":["../../src/lib/get-ply-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,cAAc,EAAmB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,GAAG,MAAM,CAIrF"}
@@ -1,27 +1,37 @@
1
- import { deduceMeshSchema } from '@loaders.gl/schema';
2
- export function getPLYSchema(plyHeader, attributes) {
3
- const metadataMap = makeMetadataFromPlyHeader(plyHeader);
4
- const schema = deduceMeshSchema(attributes, metadataMap);
5
- return schema;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPLYSchema = void 0;
4
+ const schema_1 = require("@loaders.gl/schema");
5
+ /**
6
+ * Gets schema from PLY header
7
+ * @param plyHeader
8
+ * @param metadata
9
+ * @returns Schema
10
+ */
11
+ function getPLYSchema(plyHeader, attributes) {
12
+ const metadata = makeMetadataFromPlyHeader(plyHeader);
13
+ const schema = (0, schema_1.deduceMeshSchema)(attributes, metadata);
14
+ return schema;
6
15
  }
7
-
16
+ exports.getPLYSchema = getPLYSchema;
17
+ /**
18
+ * Make arrow like schema metadata by PlyHeader properties
19
+ * @param plyHeader
20
+ * @returns
21
+ */
8
22
  function makeMetadataFromPlyHeader(plyHeader) {
9
- const metadataMap = new Map();
10
- metadataMap.set('ply_comments', JSON.stringify(plyHeader.comments));
11
- metadataMap.set('ply_elements', JSON.stringify(plyHeader.elements));
12
-
13
- if (plyHeader.format !== undefined) {
14
- metadataMap.set('ply_format', plyHeader.format);
15
- }
16
-
17
- if (plyHeader.version !== undefined) {
18
- metadataMap.set('ply_version', plyHeader.version);
19
- }
20
-
21
- if (plyHeader.headerLength !== undefined) {
22
- metadataMap.set('ply_headerLength', plyHeader.headerLength.toString(10));
23
- }
24
-
25
- return metadataMap;
23
+ /* eslint-disable camelcase */
24
+ const metadata = {};
25
+ metadata.ply_comments = JSON.stringify(plyHeader.comments);
26
+ metadata.ply_elements = JSON.stringify(plyHeader.elements);
27
+ if (plyHeader.format !== undefined) {
28
+ metadata.ply_format = plyHeader.format;
29
+ }
30
+ if (plyHeader.version !== undefined) {
31
+ metadata.ply_version = plyHeader.version;
32
+ }
33
+ if (plyHeader.headerLength !== undefined) {
34
+ metadata.ply_headerLength = plyHeader.headerLength.toString(10);
35
+ }
36
+ return metadata;
26
37
  }
27
- //# sourceMappingURL=get-ply-schema.js.map
@@ -0,0 +1,8 @@
1
+ import type { PLYMesh, PLYHeader, PLYAttributes, MeshHeader } from './ply-types';
2
+ /**
3
+ * @param header
4
+ * @param attributes
5
+ * @returns data and header
6
+ */
7
+ export default function normalizePLY(plyHeader: MeshHeader & PLYHeader, plyAttributes: PLYAttributes, options?: {}): PLYMesh;
8
+ //# sourceMappingURL=normalize-ply.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-ply.d.ts","sourceRoot":"","sources":["../../src/lib/normalize-ply.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAC,MAAM,aAAa,CAAC;AAG/E;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,SAAS,EAAE,UAAU,GAAG,SAAS,EACjC,aAAa,EAAE,aAAa,EAC5B,OAAO,CAAC,EAAE,EAAE,GACX,OAAO,CAgCT"}
@@ -1,69 +1,80 @@
1
- import { getMeshBoundingBox } from '@loaders.gl/schema';
2
- import { getPLYSchema } from './get-ply-schema';
3
- export default function normalizePLY(plyHeader, plyAttributes, options) {
4
- const attributes = getMeshAttributes(plyAttributes);
5
- const boundingBox = getMeshBoundingBox(attributes);
6
- const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;
7
- const isTriangles = plyAttributes.indices && plyAttributes.indices.length > 0;
8
- const mode = isTriangles ? 4 : 0;
9
- const topology = isTriangles ? 'triangle-list' : 'point-list';
10
- const schema = getPLYSchema(plyHeader, attributes);
11
- const plyMesh = {
12
- loader: 'ply',
13
- loaderData: plyHeader,
14
- header: {
15
- vertexCount,
16
- boundingBox
17
- },
18
- schema,
19
- attributes,
20
- indices: {
21
- value: new Uint32Array(0),
22
- size: 0
23
- },
24
- mode,
25
- topology
26
- };
27
-
28
- if (plyAttributes.indices.length > 0) {
29
- plyMesh.indices = {
30
- value: new Uint32Array(plyAttributes.indices),
31
- size: 1
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const schema_1 = require("@loaders.gl/schema");
4
+ const get_ply_schema_1 = require("./get-ply-schema");
5
+ /**
6
+ * @param header
7
+ * @param attributes
8
+ * @returns data and header
9
+ */
10
+ function normalizePLY(plyHeader, plyAttributes, options) {
11
+ const attributes = getMeshAttributes(plyAttributes);
12
+ const boundingBox = (0, schema_1.getMeshBoundingBox)(attributes);
13
+ const vertexCount = plyAttributes.indices.length || plyAttributes.vertices.length / 3;
14
+ // TODO - how to detect POINT CLOUDS vs MESHES?
15
+ // TODO - For Meshes, PLY quadrangles must be split?
16
+ const isTriangles = plyAttributes.indices && plyAttributes.indices.length > 0;
17
+ const mode = isTriangles ? 4 : 0; // TRIANGLES vs POINTS
18
+ const topology = isTriangles ? 'triangle-list' : 'point-list';
19
+ const schema = (0, get_ply_schema_1.getPLYSchema)(plyHeader, attributes);
20
+ const plyMesh = {
21
+ loader: 'ply',
22
+ loaderData: plyHeader,
23
+ header: {
24
+ vertexCount,
25
+ boundingBox
26
+ },
27
+ schema,
28
+ attributes,
29
+ indices: { value: new Uint32Array(0), size: 0 },
30
+ mode,
31
+ topology
32
32
  };
33
- }
34
-
35
- return plyMesh;
33
+ if (plyAttributes.indices.length > 0) {
34
+ plyMesh.indices = { value: new Uint32Array(plyAttributes.indices), size: 1 };
35
+ }
36
+ return plyMesh;
36
37
  }
37
-
38
+ exports.default = normalizePLY;
39
+ /**
40
+ * @param attributes
41
+ * @returns accessors []
42
+ */
43
+ // eslint-disable-next-line complexity
38
44
  function getMeshAttributes(attributes) {
39
- const accessors = {};
40
- accessors.POSITION = {
41
- value: new Float32Array(attributes.vertices),
42
- size: 3
43
- };
44
-
45
- if (attributes.normals.length > 0) {
46
- accessors.NORMAL = {
47
- value: new Float32Array(attributes.normals),
48
- size: 3
49
- };
50
- }
51
-
52
- if (attributes.uvs.length > 0) {
53
- accessors.TEXCOORD_0 = {
54
- value: new Float32Array(attributes.uvs),
55
- size: 2
56
- };
57
- }
58
-
59
- if (attributes.colors.length > 0) {
60
- accessors.COLOR_0 = {
61
- value: new Uint8Array(attributes.colors),
62
- size: 3,
63
- normalized: true
64
- };
65
- }
66
-
67
- return accessors;
45
+ const accessors = {};
46
+ for (const attributeName of Object.keys(attributes)) {
47
+ switch (attributeName) {
48
+ case 'vertices':
49
+ if (attributes.vertices.length > 0) {
50
+ accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
51
+ }
52
+ break;
53
+ // optional attributes data
54
+ case 'normals':
55
+ if (attributes.normals.length > 0) {
56
+ accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
57
+ }
58
+ break;
59
+ case 'uvs':
60
+ if (attributes.uvs.length > 0) {
61
+ accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
62
+ }
63
+ break;
64
+ case 'colors':
65
+ if (attributes.colors.length > 0) {
66
+ // TODO - normalized shoud be based on `uchar` flag in source data?
67
+ accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
68
+ }
69
+ break;
70
+ case 'indices':
71
+ break;
72
+ default:
73
+ if (attributes[attributeName].length > 0) {
74
+ accessors[attributeName] = { value: new Float32Array(attributes[attributeName]), size: 1 };
75
+ }
76
+ break;
77
+ }
78
+ }
79
+ return accessors;
68
80
  }
69
- //# sourceMappingURL=normalize-ply.js.map
@@ -0,0 +1,8 @@
1
+ import { PLYMesh } from './ply-types';
2
+ /**
3
+ * PARSER
4
+ * @param iterator
5
+ * @param options
6
+ */
7
+ export declare function parsePLYInBatches(iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options: any): AsyncIterable<PLYMesh>;
8
+ //# sourceMappingURL=parse-ply-in-batches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-ply-in-batches.d.ts","sourceRoot":"","sources":["../../src/lib/parse-ply-in-batches.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAC,OAAO,EAAoD,MAAM,aAAa,CAAC;AAIvF;;;;GAIG;AACH,wBAAuB,iBAAiB,CACtC,QAAQ,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EAC5D,OAAO,EAAE,GAAG,GACX,aAAa,CAAC,OAAO,CAAC,CAexB"}