@loaders.gl/ply 3.1.0-alpha.5 → 3.1.0-beta.5

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.
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports._typecheckPLYLoader = exports.PLYLoader = void 0;
7
- const VERSION = typeof "3.1.0-alpha.5" !== 'undefined' ? "3.1.0-alpha.5" : 'latest';
7
+ const VERSION = typeof "3.1.0-beta.5" !== 'undefined' ? "3.1.0-beta.5" : 'latest';
8
8
  const PLYLoader = {
9
9
  name: 'PLY',
10
10
  id: 'ply',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ply-loader.ts"],"names":["VERSION","PLYLoader","name","id","module","shapes","version","worker","extensions","mimeTypes","text","binary","tests","options","ply","_typecheckPLYLoader"],"mappings":";;;;;;AAKA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAOO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,KADiB;AAEvBC,EAAAA,EAAE,EAAE,KAFmB;AAGvBC,EAAAA,MAAM,EAAE,KAHe;AAIvBC,EAAAA,MAAM,EAAE,CAAC,MAAD,EAAS,MAAT,EAAiB,gBAAjB,CAJe;AAKvBC,EAAAA,OAAO,EAAEN,OALc;AAMvBO,EAAAA,MAAM,EAAE,IANe;AAOvBC,EAAAA,UAAU,EAAE,CAAC,KAAD,CAPW;AAQvBC,EAAAA,SAAS,EAAE,CAAC,YAAD,EAAe,0BAAf,CARY;AASvBC,EAAAA,IAAI,EAAE,IATiB;AAUvBC,EAAAA,MAAM,EAAE,IAVe;AAWvBC,EAAAA,KAAK,EAAE,CAAC,KAAD,CAXgB;AAYvBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AADE;AAZc,CAAlB;;AAiBA,MAAMC,mBAA2B,GAAGd,SAApC","sourcesContent":["// PLY Loader\nimport type {Loader} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for PLY - Polygon File Format (aka Stanford Triangle Format)'\n * links: ['http://paulbourke.net/dataformats/ply/',\n * 'https://en.wikipedia.org/wiki/PLY_(file_format)']\n */\nexport const PLYLoader = {\n name: 'PLY',\n id: 'ply',\n module: 'ply',\n shapes: ['mesh', 'gltf', 'columnar-table'],\n version: VERSION,\n worker: true,\n extensions: ['ply'],\n mimeTypes: ['text/plain', 'application/octet-stream'],\n text: true,\n binary: true,\n tests: ['ply'],\n options: {\n ply: {}\n }\n};\n\nexport const _typecheckPLYLoader: Loader = PLYLoader;\n"],"file":"ply-loader.js"}
1
+ {"version":3,"sources":["../../src/ply-loader.ts"],"names":["VERSION","PLYLoader","name","id","module","shapes","version","worker","extensions","mimeTypes","text","binary","tests","options","ply","_typecheckPLYLoader"],"mappings":";;;;;;AAKA,MAAMA,OAAO,GAAG,0BAAuB,WAAvB,oBAAmD,QAAnE;AAOO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,KADiB;AAEvBC,EAAAA,EAAE,EAAE,KAFmB;AAGvBC,EAAAA,MAAM,EAAE,KAHe;AAIvBC,EAAAA,MAAM,EAAE,CAAC,MAAD,EAAS,MAAT,EAAiB,gBAAjB,CAJe;AAKvBC,EAAAA,OAAO,EAAEN,OALc;AAMvBO,EAAAA,MAAM,EAAE,IANe;AAOvBC,EAAAA,UAAU,EAAE,CAAC,KAAD,CAPW;AAQvBC,EAAAA,SAAS,EAAE,CAAC,YAAD,EAAe,0BAAf,CARY;AASvBC,EAAAA,IAAI,EAAE,IATiB;AAUvBC,EAAAA,MAAM,EAAE,IAVe;AAWvBC,EAAAA,KAAK,EAAE,CAAC,KAAD,CAXgB;AAYvBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AADE;AAZc,CAAlB;;AAiBA,MAAMC,mBAA2B,GAAGd,SAApC","sourcesContent":["// PLY Loader\nimport type {Loader} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for PLY - Polygon File Format (aka Stanford Triangle Format)'\n * links: ['http://paulbourke.net/dataformats/ply/',\n * 'https://en.wikipedia.org/wiki/PLY_(file_format)']\n */\nexport const PLYLoader = {\n name: 'PLY',\n id: 'ply',\n module: 'ply',\n shapes: ['mesh', 'gltf', 'columnar-table'],\n version: VERSION,\n worker: true,\n extensions: ['ply'],\n mimeTypes: ['text/plain', 'application/octet-stream'],\n text: true,\n binary: true,\n tests: ['ply'],\n options: {\n ply: {}\n }\n};\n\nexport const _typecheckPLYLoader: Loader = PLYLoader;\n"],"file":"ply-loader.js"}
@@ -1,4 +1,4 @@
1
- const VERSION = typeof "3.1.0-alpha.5" !== 'undefined' ? "3.1.0-alpha.5" : 'latest';
1
+ const VERSION = typeof "3.1.0-beta.5" !== 'undefined' ? "3.1.0-beta.5" : 'latest';
2
2
  export const PLYLoader = {
3
3
  name: 'PLY',
4
4
  id: 'ply',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ply-loader.ts"],"names":["VERSION","PLYLoader","name","id","module","shapes","version","worker","extensions","mimeTypes","text","binary","tests","options","ply","_typecheckPLYLoader"],"mappings":"AAKA,MAAMA,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAOA,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,KADiB;AAEvBC,EAAAA,EAAE,EAAE,KAFmB;AAGvBC,EAAAA,MAAM,EAAE,KAHe;AAIvBC,EAAAA,MAAM,EAAE,CAAC,MAAD,EAAS,MAAT,EAAiB,gBAAjB,CAJe;AAKvBC,EAAAA,OAAO,EAAEN,OALc;AAMvBO,EAAAA,MAAM,EAAE,IANe;AAOvBC,EAAAA,UAAU,EAAE,CAAC,KAAD,CAPW;AAQvBC,EAAAA,SAAS,EAAE,CAAC,YAAD,EAAe,0BAAf,CARY;AASvBC,EAAAA,IAAI,EAAE,IATiB;AAUvBC,EAAAA,MAAM,EAAE,IAVe;AAWvBC,EAAAA,KAAK,EAAE,CAAC,KAAD,CAXgB;AAYvBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AADE;AAZc,CAAlB;AAiBP,OAAO,MAAMC,mBAA2B,GAAGd,SAApC","sourcesContent":["// PLY Loader\nimport type {Loader} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for PLY - Polygon File Format (aka Stanford Triangle Format)'\n * links: ['http://paulbourke.net/dataformats/ply/',\n * 'https://en.wikipedia.org/wiki/PLY_(file_format)']\n */\nexport const PLYLoader = {\n name: 'PLY',\n id: 'ply',\n module: 'ply',\n shapes: ['mesh', 'gltf', 'columnar-table'],\n version: VERSION,\n worker: true,\n extensions: ['ply'],\n mimeTypes: ['text/plain', 'application/octet-stream'],\n text: true,\n binary: true,\n tests: ['ply'],\n options: {\n ply: {}\n }\n};\n\nexport const _typecheckPLYLoader: Loader = PLYLoader;\n"],"file":"ply-loader.js"}
1
+ {"version":3,"sources":["../../src/ply-loader.ts"],"names":["VERSION","PLYLoader","name","id","module","shapes","version","worker","extensions","mimeTypes","text","binary","tests","options","ply","_typecheckPLYLoader"],"mappings":"AAKA,MAAMA,OAAO,GAAG,0BAAuB,WAAvB,oBAAmD,QAAnE;AAOA,OAAO,MAAMC,SAAS,GAAG;AACvBC,EAAAA,IAAI,EAAE,KADiB;AAEvBC,EAAAA,EAAE,EAAE,KAFmB;AAGvBC,EAAAA,MAAM,EAAE,KAHe;AAIvBC,EAAAA,MAAM,EAAE,CAAC,MAAD,EAAS,MAAT,EAAiB,gBAAjB,CAJe;AAKvBC,EAAAA,OAAO,EAAEN,OALc;AAMvBO,EAAAA,MAAM,EAAE,IANe;AAOvBC,EAAAA,UAAU,EAAE,CAAC,KAAD,CAPW;AAQvBC,EAAAA,SAAS,EAAE,CAAC,YAAD,EAAe,0BAAf,CARY;AASvBC,EAAAA,IAAI,EAAE,IATiB;AAUvBC,EAAAA,MAAM,EAAE,IAVe;AAWvBC,EAAAA,KAAK,EAAE,CAAC,KAAD,CAXgB;AAYvBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,GAAG,EAAE;AADE;AAZc,CAAlB;AAiBP,OAAO,MAAMC,mBAA2B,GAAGd,SAApC","sourcesContent":["// PLY Loader\nimport type {Loader} from '@loaders.gl/loader-utils';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/**\n * Worker loader for PLY - Polygon File Format (aka Stanford Triangle Format)'\n * links: ['http://paulbourke.net/dataformats/ply/',\n * 'https://en.wikipedia.org/wiki/PLY_(file_format)']\n */\nexport const PLYLoader = {\n name: 'PLY',\n id: 'ply',\n module: 'ply',\n shapes: ['mesh', 'gltf', 'columnar-table'],\n version: VERSION,\n worker: true,\n extensions: ['ply'],\n mimeTypes: ['text/plain', 'application/octet-stream'],\n text: true,\n binary: true,\n tests: ['ply'],\n options: {\n ply: {}\n }\n};\n\nexport const _typecheckPLYLoader: Loader = PLYLoader;\n"],"file":"ply-loader.js"}
package/dist/index.d.ts CHANGED
@@ -27,3 +27,4 @@ export declare const PLYLoader: {
27
27
  };
28
28
  };
29
29
  export declare const _typecheckPLYLoader: LoaderWithParser;
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAC,SAAS,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAC1D,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,iBAAiB,MAAM,4BAA4B,CAAC;AAI3D,OAAO,EAAC,eAAe,EAAC,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;CAOrB,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,gBAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports._typecheckPLYLoader = exports.PLYLoader = exports.PLYWorkerLoader = void 0;
7
+ const ply_loader_1 = require("./ply-loader");
8
+ Object.defineProperty(exports, "PLYWorkerLoader", { enumerable: true, get: function () { return ply_loader_1.PLYLoader; } });
9
+ const parse_ply_1 = __importDefault(require("./lib/parse-ply"));
10
+ const parse_ply_in_batches_1 = __importDefault(require("./lib/parse-ply-in-batches"));
11
+ /**
12
+ * Loader for PLY - Polygon File Format
13
+ */
14
+ exports.PLYLoader = {
15
+ ...ply_loader_1.PLYLoader,
16
+ // Note: parsePLY supports both text and binary
17
+ parse: async (arrayBuffer, options) => (0, parse_ply_1.default)(arrayBuffer, options),
18
+ parseTextSync: parse_ply_1.default,
19
+ parseSync: parse_ply_1.default,
20
+ parseInBatches: parse_ply_in_batches_1.default
21
+ };
22
+ exports._typecheckPLYLoader = exports.PLYLoader;
@@ -7,3 +7,4 @@ import type { PLYHeader } from './ply-types';
7
7
  * @returns Schema
8
8
  */
9
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"}
@@ -0,0 +1,36 @@
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 metadataMap = makeMetadataFromPlyHeader(plyHeader);
13
+ const schema = (0, schema_1.deduceMeshSchema)(attributes, metadataMap);
14
+ return schema;
15
+ }
16
+ exports.getPLYSchema = getPLYSchema;
17
+ /**
18
+ * Make arrow like schema metadata by PlyHeader properties
19
+ * @param plyHeader
20
+ * @returns
21
+ */
22
+ function makeMetadataFromPlyHeader(plyHeader) {
23
+ const metadataMap = new Map();
24
+ metadataMap.set('ply_comments', JSON.stringify(plyHeader.comments));
25
+ metadataMap.set('ply_elements', JSON.stringify(plyHeader.elements));
26
+ if (plyHeader.format !== undefined) {
27
+ metadataMap.set('ply_format', plyHeader.format);
28
+ }
29
+ if (plyHeader.version !== undefined) {
30
+ metadataMap.set('ply_version', plyHeader.version);
31
+ }
32
+ if (plyHeader.headerLength !== undefined) {
33
+ metadataMap.set('ply_headerLength', plyHeader.headerLength.toString(10));
34
+ }
35
+ return metadataMap;
36
+ }
@@ -5,3 +5,4 @@ import type { PLYMesh, PLYHeader, PLYAttributes, MeshHeader } from './ply-types'
5
5
  * @returns data and header
6
6
  */
7
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"}
@@ -0,0 +1,58 @@
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
+ };
33
+ if (plyAttributes.indices.length > 0) {
34
+ plyMesh.indices = { value: new Uint32Array(plyAttributes.indices), size: 1 };
35
+ }
36
+ return plyMesh;
37
+ }
38
+ exports.default = normalizePLY;
39
+ /**
40
+ * @param attributes
41
+ * @returns accessors []
42
+ */
43
+ function getMeshAttributes(attributes) {
44
+ const accessors = {};
45
+ accessors.POSITION = { value: new Float32Array(attributes.vertices), size: 3 };
46
+ // optional attributes data
47
+ if (attributes.normals.length > 0) {
48
+ accessors.NORMAL = { value: new Float32Array(attributes.normals), size: 3 };
49
+ }
50
+ if (attributes.uvs.length > 0) {
51
+ accessors.TEXCOORD_0 = { value: new Float32Array(attributes.uvs), size: 2 };
52
+ }
53
+ if (attributes.colors.length > 0) {
54
+ // TODO - normalized shoud be based on `uchar` flag in source data?
55
+ accessors.COLOR_0 = { value: new Uint8Array(attributes.colors), size: 3, normalized: true };
56
+ }
57
+ return accessors;
58
+ }
@@ -5,3 +5,4 @@ import { PLYMesh } from './ply-types';
5
5
  * @param options
6
6
  */
7
7
  export default 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":"AA0BA,OAAO,EAAC,OAAO,EAAyC,MAAM,aAAa,CAAC;AAI5E;;;;GAIG;AACH,wBAA+B,iBAAiB,CAC9C,QAAQ,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EAC5D,OAAO,EAAE,GAAG,GACX,aAAa,CAAC,OAAO,CAAC,CAexB"}
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ // PLY Loader, adapted from THREE.js (MIT license)
3
+ //
4
+ // Attributions per original THREE.js source file:
5
+ //
6
+ // @author Wei Meng / http://about.me/menway
7
+ //
8
+ // Description: A loader for PLY ASCII files (known as the Polygon File Format
9
+ // or the Stanford Triangle Format).
10
+ //
11
+ // Limitations: ASCII decoding assumes file is UTF-8.
12
+ //
13
+ // If the PLY file uses non standard property names, they can be mapped while
14
+ // loading. For example, the following maps the properties
15
+ // “diffuse_(red|green|blue)” in the file to standard color names.
16
+ //
17
+ // parsePLY(data, {
18
+ // propertyNameMapping: {
19
+ // diffuse_red: 'red',
20
+ // diffuse_green: 'green',
21
+ // diffuse_blue: 'blue'
22
+ // }
23
+ // });
24
+ // @ts-nocheck
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const core_1 = require("@loaders.gl/core");
30
+ const normalize_ply_1 = __importDefault(require("./normalize-ply"));
31
+ let currentElement;
32
+ /**
33
+ * PARSER
34
+ * @param iterator
35
+ * @param options
36
+ */
37
+ async function* parsePLYInBatches(iterator, options) {
38
+ const lineIterator = (0, core_1.makeLineIterator)((0, core_1.makeTextDecoderIterator)(iterator));
39
+ const header = await parsePLYHeader(lineIterator, options);
40
+ let attributes;
41
+ switch (header.format) {
42
+ case 'ascii':
43
+ attributes = await parseASCII(lineIterator, header);
44
+ break;
45
+ default:
46
+ throw new Error('Binary PLY can not yet be parsed in streaming mode');
47
+ // attributes = await parseBinary(lineIterator, header);
48
+ }
49
+ yield (0, normalize_ply_1.default)(header, attributes, options);
50
+ }
51
+ exports.default = parsePLYInBatches;
52
+ /**
53
+ * Parses header
54
+ * @param lineIterator
55
+ * @param options
56
+ * @returns
57
+ */
58
+ async function parsePLYHeader(lineIterator, options) {
59
+ const header = {
60
+ comments: [],
61
+ elements: []
62
+ // headerLength
63
+ };
64
+ // Note: forEach does not reset iterator if exiting loop prematurely
65
+ // so that iteration can continue in a second loop
66
+ await (0, core_1.forEach)(lineIterator, (line) => {
67
+ line = line.trim();
68
+ // End of header
69
+ if (line === 'end_header') {
70
+ return true; // Returning true cancels `forEach`
71
+ }
72
+ // Ignore empty lines
73
+ if (line === '') {
74
+ // eslint-disable-next-line
75
+ return false; // Returning false does not cancel `forEach`
76
+ }
77
+ const lineValues = line.split(/\s+/);
78
+ const lineType = lineValues.shift();
79
+ line = lineValues.join(' ');
80
+ switch (lineType) {
81
+ case 'ply':
82
+ // First line magic characters, ignore
83
+ break;
84
+ case 'format':
85
+ header.format = lineValues[0];
86
+ header.version = lineValues[1];
87
+ break;
88
+ case 'comment':
89
+ header.comments.push(line);
90
+ break;
91
+ case 'element':
92
+ if (currentElement) {
93
+ header.elements.push(currentElement);
94
+ }
95
+ currentElement = {
96
+ name: lineValues[0],
97
+ count: parseInt(lineValues[1], 10),
98
+ properties: []
99
+ };
100
+ break;
101
+ case 'property':
102
+ const property = makePLYElementProperty(lineValues, options.propertyNameMapping);
103
+ currentElement.properties.push(property);
104
+ break;
105
+ default:
106
+ // eslint-disable-next-line
107
+ console.log('unhandled', lineType, lineValues);
108
+ }
109
+ return false;
110
+ });
111
+ if (currentElement) {
112
+ header.elements.push(currentElement);
113
+ }
114
+ return header;
115
+ }
116
+ function makePLYElementProperty(propertValues, propertyNameMapping) {
117
+ const property = {
118
+ type: propertValues[0]
119
+ };
120
+ if (property.type === 'list') {
121
+ property.name = propertValues[3];
122
+ property.countType = propertValues[1];
123
+ property.itemType = propertValues[2];
124
+ }
125
+ else {
126
+ property.name = propertValues[1];
127
+ }
128
+ if (propertyNameMapping && property.name in propertyNameMapping) {
129
+ property.name = propertyNameMapping[property.name];
130
+ }
131
+ return property;
132
+ }
133
+ // ASCII PARSING
134
+ /**
135
+ * @param lineIterator
136
+ * @param header
137
+ * @returns
138
+ */
139
+ async function parseASCII(lineIterator, header) {
140
+ // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
141
+ const attributes = {
142
+ indices: [],
143
+ vertices: [],
144
+ normals: [],
145
+ uvs: [],
146
+ colors: []
147
+ };
148
+ let currentElement = 0;
149
+ let currentElementCount = 0;
150
+ for await (let line of lineIterator) {
151
+ line = line.trim();
152
+ if (line !== '') {
153
+ if (currentElementCount >= header.elements[currentElement].count) {
154
+ currentElement++;
155
+ currentElementCount = 0;
156
+ }
157
+ const element = parseASCIIElement(header.elements[currentElement].properties, line);
158
+ handleElement(attributes, header.elements[currentElement].name, element);
159
+ currentElementCount++;
160
+ }
161
+ }
162
+ return attributes;
163
+ }
164
+ /**
165
+ * Parses ASCII number
166
+ * @param n
167
+ * @param type
168
+ * @returns ASCII number
169
+ */
170
+ // eslint-disable-next-line complexity
171
+ function parseASCIINumber(n, type) {
172
+ switch (type) {
173
+ case 'char':
174
+ case 'uchar':
175
+ case 'short':
176
+ case 'ushort':
177
+ case 'int':
178
+ case 'uint':
179
+ case 'int8':
180
+ case 'uint8':
181
+ case 'int16':
182
+ case 'uint16':
183
+ case 'int32':
184
+ case 'uint32':
185
+ return parseInt(n, 10);
186
+ case 'float':
187
+ case 'double':
188
+ case 'float32':
189
+ case 'float64':
190
+ return parseFloat(n);
191
+ default:
192
+ throw new Error(type);
193
+ }
194
+ }
195
+ /**
196
+ * Parses ASCII element
197
+ * @param properties
198
+ * @param line
199
+ * @returns element
200
+ */
201
+ function parseASCIIElement(properties, line) {
202
+ const values = line.split(/\s+/);
203
+ const element = {};
204
+ for (let i = 0; i < properties.length; i++) {
205
+ if (properties[i].type === 'list') {
206
+ const list = [];
207
+ const n = parseASCIINumber(values.shift(), properties[i].countType);
208
+ for (let j = 0; j < n; j++) {
209
+ list.push(parseASCIINumber(values.shift(), properties[i].itemType));
210
+ }
211
+ element[properties[i].name] = list;
212
+ }
213
+ else {
214
+ element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);
215
+ }
216
+ }
217
+ return element;
218
+ }
219
+ /**
220
+ * @param buffer
221
+ * @param elementName
222
+ * @param element
223
+ */
224
+ // HELPER FUNCTIONS
225
+ // eslint-disable-next-line complexity
226
+ function handleElement(buffer, elementName, element = {}) {
227
+ switch (elementName) {
228
+ case 'vertex':
229
+ buffer.vertices.push(element.x, element.y, element.z);
230
+ if ('nx' in element && 'ny' in element && 'nz' in element) {
231
+ buffer.normals.push(element.nx, element.ny, element.nz);
232
+ }
233
+ if ('s' in element && 't' in element) {
234
+ buffer.uvs.push(element.s, element.t);
235
+ }
236
+ if ('red' in element && 'green' in element && 'blue' in element) {
237
+ buffer.colors.push(element.red / 255.0, element.green / 255.0, element.blue / 255.0);
238
+ }
239
+ break;
240
+ case 'face':
241
+ const vertexIndices = element.vertex_indices || element.vertex_index; // issue #9338
242
+ if (vertexIndices.length === 3) {
243
+ buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
244
+ }
245
+ else if (vertexIndices.length === 4) {
246
+ buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
247
+ buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
248
+ }
249
+ break;
250
+ default:
251
+ break;
252
+ }
253
+ }
@@ -5,3 +5,4 @@ import type { PLYMesh } from './ply-types';
5
5
  * @returns
6
6
  */
7
7
  export default function parsePLY(data: ArrayBuffer | string, options?: {}): PLYMesh;
8
+ //# sourceMappingURL=parse-ply.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-ply.d.ts","sourceRoot":"","sources":["../../src/lib/parse-ply.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,OAAO,EAMR,MAAM,aAAa,CAAC;AAGrB;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,EAAE,OAAO,KAAK,GAAG,OAAO,CAclF"}