@loaders.gl/ply 3.1.3 → 4.0.0-alpha.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.
Files changed (58) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/bundle.js.map +1 -0
  3. package/dist/dist.min.js +3 -11
  4. package/dist/index.js +11 -21
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/get-ply-schema.js +24 -33
  7. package/dist/lib/get-ply-schema.js.map +1 -0
  8. package/dist/lib/normalize-ply.js +65 -54
  9. package/dist/lib/normalize-ply.js.map +1 -0
  10. package/dist/lib/parse-ply-in-batches.d.ts.map +1 -1
  11. package/dist/lib/parse-ply-in-batches.js +200 -235
  12. package/dist/lib/parse-ply-in-batches.js.map +1 -0
  13. package/dist/lib/parse-ply.js +297 -320
  14. package/dist/lib/parse-ply.js.map +1 -0
  15. package/dist/lib/ply-types.js +2 -2
  16. package/dist/{es5/lib → lib}/ply-types.js.map +0 -0
  17. package/dist/ply-loader.js +18 -27
  18. package/dist/ply-loader.js.map +1 -0
  19. package/dist/ply-worker.js +1 -1
  20. package/dist/workers/ply-worker.js +4 -5
  21. package/dist/workers/ply-worker.js.map +1 -0
  22. package/package.json +7 -10
  23. package/src/lib/parse-ply-in-batches.ts +3 -4
  24. package/dist/es5/bundle.js +0 -7
  25. package/dist/es5/bundle.js.map +0 -1
  26. package/dist/es5/index.js +0 -63
  27. package/dist/es5/index.js.map +0 -1
  28. package/dist/es5/lib/get-ply-schema.js +0 -35
  29. package/dist/es5/lib/get-ply-schema.js.map +0 -1
  30. package/dist/es5/lib/normalize-ply.js +0 -78
  31. package/dist/es5/lib/normalize-ply.js.map +0 -1
  32. package/dist/es5/lib/parse-ply-in-batches.js +0 -370
  33. package/dist/es5/lib/parse-ply-in-batches.js.map +0 -1
  34. package/dist/es5/lib/parse-ply.js +0 -340
  35. package/dist/es5/lib/parse-ply.js.map +0 -1
  36. package/dist/es5/lib/ply-types.js +0 -2
  37. package/dist/es5/ply-loader.js +0 -27
  38. package/dist/es5/ply-loader.js.map +0 -1
  39. package/dist/es5/workers/ply-worker.js +0 -8
  40. package/dist/es5/workers/ply-worker.js.map +0 -1
  41. package/dist/esm/bundle.js +0 -5
  42. package/dist/esm/bundle.js.map +0 -1
  43. package/dist/esm/index.js +0 -12
  44. package/dist/esm/index.js.map +0 -1
  45. package/dist/esm/lib/get-ply-schema.js +0 -27
  46. package/dist/esm/lib/get-ply-schema.js.map +0 -1
  47. package/dist/esm/lib/normalize-ply.js +0 -69
  48. package/dist/esm/lib/normalize-ply.js.map +0 -1
  49. package/dist/esm/lib/parse-ply-in-batches.js +0 -218
  50. package/dist/esm/lib/parse-ply-in-batches.js.map +0 -1
  51. package/dist/esm/lib/parse-ply.js +0 -327
  52. package/dist/esm/lib/parse-ply.js.map +0 -1
  53. package/dist/esm/lib/ply-types.js +0 -2
  54. package/dist/esm/lib/ply-types.js.map +0 -1
  55. package/dist/esm/ply-loader.js +0 -19
  56. package/dist/esm/ply-loader.js.map +0 -1
  57. package/dist/esm/workers/ply-worker.js +0 -4
  58. package/dist/esm/workers/ply-worker.js.map +0 -1
@@ -1,253 +1,218 @@
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"));
1
+ import { makeLineIterator, makeTextDecoderIterator, forEach } from '@loaders.gl/loader-utils';
2
+ import normalizePLY from './normalize-ply';
31
3
  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);
4
+ export default async function* parsePLYInBatches(iterator, options) {
5
+ const lineIterator = makeLineIterator(makeTextDecoderIterator(iterator));
6
+ const header = await parsePLYHeader(lineIterator, options);
7
+ let attributes;
8
+
9
+ switch (header.format) {
10
+ case 'ascii':
11
+ attributes = await parseASCII(lineIterator, header);
12
+ break;
13
+
14
+ default:
15
+ throw new Error('Binary PLY can not yet be parsed in streaming mode');
16
+ }
17
+
18
+ yield normalizePLY(header, attributes, options);
50
19
  }
51
- exports.default = parsePLYInBatches;
52
- /**
53
- * Parses header
54
- * @param lineIterator
55
- * @param options
56
- * @returns
57
- */
20
+
58
21
  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);
22
+ const header = {
23
+ comments: [],
24
+ elements: []
25
+ };
26
+ await forEach(lineIterator, line => {
27
+ line = line.trim();
28
+
29
+ if (line === 'end_header') {
30
+ return true;
31
+ }
32
+
33
+ if (line === '') {
34
+ return false;
35
+ }
36
+
37
+ const lineValues = line.split(/\s+/);
38
+ const lineType = lineValues.shift();
39
+ line = lineValues.join(' ');
40
+
41
+ switch (lineType) {
42
+ case 'ply':
43
+ break;
44
+
45
+ case 'format':
46
+ header.format = lineValues[0];
47
+ header.version = lineValues[1];
48
+ break;
49
+
50
+ case 'comment':
51
+ header.comments.push(line);
52
+ break;
53
+
54
+ case 'element':
55
+ if (currentElement) {
56
+ header.elements.push(currentElement);
108
57
  }
109
- return false;
110
- });
111
- if (currentElement) {
112
- header.elements.push(currentElement);
58
+
59
+ currentElement = {
60
+ name: lineValues[0],
61
+ count: parseInt(lineValues[1], 10),
62
+ properties: []
63
+ };
64
+ break;
65
+
66
+ case 'property':
67
+ const property = makePLYElementProperty(lineValues, options.propertyNameMapping);
68
+ currentElement.properties.push(property);
69
+ break;
70
+
71
+ default:
72
+ console.log('unhandled', lineType, lineValues);
113
73
  }
114
- return header;
74
+
75
+ return false;
76
+ });
77
+
78
+ if (currentElement) {
79
+ header.elements.push(currentElement);
80
+ }
81
+
82
+ return header;
115
83
  }
84
+
116
85
  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;
86
+ const property = {
87
+ type: propertValues[0]
88
+ };
89
+
90
+ if (property.type === 'list') {
91
+ property.name = propertValues[3];
92
+ property.countType = propertValues[1];
93
+ property.itemType = propertValues[2];
94
+ } else {
95
+ property.name = propertValues[1];
96
+ }
97
+
98
+ if (propertyNameMapping && property.name in propertyNameMapping) {
99
+ property.name = propertyNameMapping[property.name];
100
+ }
101
+
102
+ return property;
132
103
  }
133
- // ASCII PARSING
134
- /**
135
- * @param lineIterator
136
- * @param header
137
- * @returns
138
- */
104
+
139
105
  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
- }
106
+ const attributes = {
107
+ indices: [],
108
+ vertices: [],
109
+ normals: [],
110
+ uvs: [],
111
+ colors: []
112
+ };
113
+ let currentElement = 0;
114
+ let currentElementCount = 0;
115
+
116
+ for await (let line of lineIterator) {
117
+ line = line.trim();
118
+
119
+ if (line !== '') {
120
+ if (currentElementCount >= header.elements[currentElement].count) {
121
+ currentElement++;
122
+ currentElementCount = 0;
123
+ }
124
+
125
+ const element = parseASCIIElement(header.elements[currentElement].properties, line);
126
+ handleElement(attributes, header.elements[currentElement].name, element);
127
+ currentElementCount++;
161
128
  }
162
- return attributes;
129
+ }
130
+
131
+ return attributes;
163
132
  }
164
- /**
165
- * Parses ASCII number
166
- * @param n
167
- * @param type
168
- * @returns ASCII number
169
- */
170
- // eslint-disable-next-line complexity
133
+
171
134
  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
- }
135
+ switch (type) {
136
+ case 'char':
137
+ case 'uchar':
138
+ case 'short':
139
+ case 'ushort':
140
+ case 'int':
141
+ case 'uint':
142
+ case 'int8':
143
+ case 'uint8':
144
+ case 'int16':
145
+ case 'uint16':
146
+ case 'int32':
147
+ case 'uint32':
148
+ return parseInt(n, 10);
149
+
150
+ case 'float':
151
+ case 'double':
152
+ case 'float32':
153
+ case 'float64':
154
+ return parseFloat(n);
155
+
156
+ default:
157
+ throw new Error(type);
158
+ }
194
159
  }
195
- /**
196
- * Parses ASCII element
197
- * @param properties
198
- * @param line
199
- * @returns element
200
- */
160
+
201
161
  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
- }
162
+ const values = line.split(/\s+/);
163
+ const element = {};
164
+
165
+ for (let i = 0; i < properties.length; i++) {
166
+ if (properties[i].type === 'list') {
167
+ const list = [];
168
+ const n = parseASCIINumber(values.shift(), properties[i].countType);
169
+
170
+ for (let j = 0; j < n; j++) {
171
+ list.push(parseASCIINumber(values.shift(), properties[i].itemType));
172
+ }
173
+
174
+ element[properties[i].name] = list;
175
+ } else {
176
+ element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);
216
177
  }
217
- return element;
178
+ }
179
+
180
+ return element;
218
181
  }
219
- /**
220
- * @param buffer
221
- * @param elementName
222
- * @param element
223
- */
224
- // HELPER FUNCTIONS
225
- // eslint-disable-next-line complexity
182
+
226
183
  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
- }
184
+ switch (elementName) {
185
+ case 'vertex':
186
+ buffer.vertices.push(element.x, element.y, element.z);
187
+
188
+ if ('nx' in element && 'ny' in element && 'nz' in element) {
189
+ buffer.normals.push(element.nx, element.ny, element.nz);
190
+ }
191
+
192
+ if ('s' in element && 't' in element) {
193
+ buffer.uvs.push(element.s, element.t);
194
+ }
195
+
196
+ if ('red' in element && 'green' in element && 'blue' in element) {
197
+ buffer.colors.push(element.red / 255.0, element.green / 255.0, element.blue / 255.0);
198
+ }
199
+
200
+ break;
201
+
202
+ case 'face':
203
+ const vertexIndices = element.vertex_indices || element.vertex_index;
204
+
205
+ if (vertexIndices.length === 3) {
206
+ buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
207
+ } else if (vertexIndices.length === 4) {
208
+ buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
209
+ buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
210
+ }
211
+
212
+ break;
213
+
214
+ default:
215
+ break;
216
+ }
253
217
  }
218
+ //# sourceMappingURL=parse-ply-in-batches.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/parse-ply-in-batches.ts"],"names":["makeLineIterator","makeTextDecoderIterator","forEach","normalizePLY","currentElement","parsePLYInBatches","iterator","options","lineIterator","header","parsePLYHeader","attributes","format","parseASCII","Error","comments","elements","line","trim","lineValues","split","lineType","shift","join","version","push","name","count","parseInt","properties","property","makePLYElementProperty","propertyNameMapping","console","log","propertValues","type","countType","itemType","indices","vertices","normals","uvs","colors","currentElementCount","element","parseASCIIElement","handleElement","parseASCIINumber","n","parseFloat","values","i","length","list","j","buffer","elementName","x","y","z","nx","ny","nz","s","t","red","green","blue","vertexIndices","vertex_indices","vertex_index"],"mappings":"AAuBA,SAAQA,gBAAR,EAA0BC,uBAA1B,EAAmDC,OAAnD,QAAiE,0BAAjE;AACA,OAAOC,YAAP,MAAyB,iBAAzB;AAGA,IAAIC,cAAJ;AAOA,eAAe,gBAAgBC,iBAAhB,CACbC,QADa,EAEbC,OAFa,EAGW;AACxB,QAAMC,YAAY,GAAGR,gBAAgB,CAACC,uBAAuB,CAACK,QAAD,CAAxB,CAArC;AACA,QAAMG,MAAM,GAAG,MAAMC,cAAc,CAACF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AC,CAAD,CAAjC,EAAsCA,aAAa,CAAC,CAAD,CAAnD,EAAwDA,aAAa,CAAC,CAAD,CAArE;AACD,OAFD,MAEO,IAAIA,aAAa,CAAChB,MAAd,KAAyB,CAA7B,EAAgC;AACrCG,QAAAA,MAAM,CAACjB,OAAP,CAAed,IAAf,CAAoB4C,aAAa,CAAC,CAAD,CAAjC,EAAsCA,aAAa,CAAC,CAAD,CAAnD,EAAwDA,aAAa,CAAC,CAAD,CAArE;AACAb,QAAAA,MAAM,CAACjB,OAAP,CAAed,IAAf,CAAoB4C,aAAa,CAAC,CAAD,CAAjC,EAAsCA,aAAa,CAAC,CAAD,CAAnD,EAAwDA,aAAa,CAAC,CAAD,CAArE;AACD;;AACD;;AAEF;AACE;AAzBJ;AA2BD","sourcesContent":["// PLY Loader, adapted from THREE.js (MIT license)\n//\n// Attributions per original THREE.js source file:\n//\n// @author Wei Meng / http://about.me/menway\n//\n// Description: A loader for PLY ASCII files (known as the Polygon File Format\n// or the Stanford Triangle Format).\n//\n// Limitations: ASCII decoding assumes file is UTF-8.\n//\n// If the PLY file uses non standard property names, they can be mapped while\n// loading. For example, the following maps the properties\n// “diffuse_(red|green|blue)” in the file to standard color names.\n//\n// parsePLY(data, {\n// propertyNameMapping: {\n// diffuse_red: 'red',\n// diffuse_green: 'green',\n// diffuse_blue: 'blue'\n// }\n// });\n\nimport {makeLineIterator, makeTextDecoderIterator, forEach} from '@loaders.gl/loader-utils';\nimport normalizePLY from './normalize-ply';\nimport {PLYMesh, PLYHeader, ASCIIElement, PLYAttributes} from './ply-types';\n\nlet currentElement: ASCIIElement;\n\n/**\n * PARSER\n * @param iterator\n * @param options\n */\nexport default async function* parsePLYInBatches(\n iterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options: any\n): AsyncIterable<PLYMesh> {\n const lineIterator = makeLineIterator(makeTextDecoderIterator(iterator));\n const header = await parsePLYHeader(lineIterator, options);\n\n let attributes: PLYAttributes;\n switch (header.format) {\n case 'ascii':\n attributes = await parseASCII(lineIterator, header);\n break;\n default:\n throw new Error('Binary PLY can not yet be parsed in streaming mode');\n // attributes = await parseBinary(lineIterator, header);\n }\n\n yield normalizePLY(header, attributes, options);\n}\n\n/**\n * Parses header\n * @param lineIterator\n * @param options\n * @returns\n */\nasync function parsePLYHeader(\n lineIterator: AsyncIterable<string> | Iterable<string>,\n options: {[key: string]: any}\n): Promise<PLYHeader> {\n const header: PLYHeader = {\n comments: [],\n elements: []\n // headerLength\n };\n\n // Note: forEach does not reset iterator if exiting loop prematurely\n // so that iteration can continue in a second loop\n await forEach(lineIterator, (line: string) => {\n line = line.trim();\n\n // End of header\n if (line === 'end_header') {\n return true; // Returning true cancels `forEach`\n }\n\n // Ignore empty lines\n if (line === '') {\n // eslint-disable-next-line\n return false; // Returning false does not cancel `forEach`\n }\n\n const lineValues = line.split(/\\s+/);\n const lineType = lineValues.shift();\n line = lineValues.join(' ');\n\n switch (lineType) {\n case 'ply':\n // First line magic characters, ignore\n break;\n\n case 'format':\n header.format = lineValues[0];\n header.version = lineValues[1];\n break;\n\n case 'comment':\n header.comments.push(line);\n break;\n\n case 'element':\n if (currentElement) {\n header.elements.push(currentElement);\n }\n\n currentElement = {\n name: lineValues[0],\n count: parseInt(lineValues[1], 10),\n properties: []\n };\n break;\n\n case 'property':\n const property = makePLYElementProperty(lineValues, options.propertyNameMapping);\n currentElement.properties.push(property);\n break;\n\n default:\n // eslint-disable-next-line\n console.log('unhandled', lineType, lineValues);\n }\n\n return false;\n });\n\n if (currentElement) {\n header.elements.push(currentElement);\n }\n\n return header;\n}\n\nfunction makePLYElementProperty(propertValues: string[], propertyNameMapping: []) {\n const property: {[index: string]: string} = {\n type: propertValues[0]\n };\n\n if (property.type === 'list') {\n property.name = propertValues[3];\n property.countType = propertValues[1];\n property.itemType = propertValues[2];\n } else {\n property.name = propertValues[1];\n }\n\n if (propertyNameMapping && property.name in propertyNameMapping) {\n property.name = propertyNameMapping[property.name];\n }\n\n return property;\n}\n\n// ASCII PARSING\n/**\n * @param lineIterator\n * @param header\n * @returns\n */\nasync function parseASCII(lineIterator: AsyncIterable<string>, header: PLYHeader) {\n // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)\n const attributes: PLYAttributes = {\n indices: [],\n vertices: [],\n normals: [],\n uvs: [],\n colors: []\n };\n\n let currentElement = 0;\n let currentElementCount = 0;\n\n for await (let line of lineIterator) {\n line = line.trim();\n\n if (line !== '') {\n if (currentElementCount >= header.elements[currentElement].count) {\n currentElement++;\n currentElementCount = 0;\n }\n\n const element = parseASCIIElement(header.elements[currentElement].properties, line);\n handleElement(attributes, header.elements[currentElement].name, element);\n currentElementCount++;\n }\n }\n\n return attributes;\n}\n/**\n * Parses ASCII number\n * @param n\n * @param type\n * @returns ASCII number\n */\n// eslint-disable-next-line complexity\nfunction parseASCIINumber(n: string, type: string): number {\n switch (type) {\n case 'char':\n case 'uchar':\n case 'short':\n case 'ushort':\n case 'int':\n case 'uint':\n case 'int8':\n case 'uint8':\n case 'int16':\n case 'uint16':\n case 'int32':\n case 'uint32':\n return parseInt(n, 10);\n\n case 'float':\n case 'double':\n case 'float32':\n case 'float64':\n return parseFloat(n);\n\n default:\n throw new Error(type);\n }\n}\n/**\n * Parses ASCII element\n * @param properties\n * @param line\n * @returns element\n */\nfunction parseASCIIElement(properties: any[], line: string) {\n const values: any = line.split(/\\s+/);\n\n const element = {};\n\n for (let i = 0; i < properties.length; i++) {\n if (properties[i].type === 'list') {\n const list: any = [];\n const n = parseASCIINumber(values.shift(), properties[i].countType);\n\n for (let j = 0; j < n; j++) {\n list.push(parseASCIINumber(values.shift(), properties[i].itemType));\n }\n\n element[properties[i].name] = list;\n } else {\n element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);\n }\n }\n\n return element;\n}\n/**\n * @param buffer\n * @param elementName\n * @param element\n */\n// HELPER FUNCTIONS\n// eslint-disable-next-line complexity\nfunction handleElement(\n buffer: {[index: string]: number[]},\n elementName: string,\n element: any = {}\n) {\n switch (elementName) {\n case 'vertex':\n buffer.vertices.push(element.x, element.y, element.z);\n if ('nx' in element && 'ny' in element && 'nz' in element) {\n buffer.normals.push(element.nx, element.ny, element.nz);\n }\n if ('s' in element && 't' in element) {\n buffer.uvs.push(element.s, element.t);\n }\n if ('red' in element && 'green' in element && 'blue' in element) {\n buffer.colors.push(element.red / 255.0, element.green / 255.0, element.blue / 255.0);\n }\n break;\n\n case 'face':\n const vertexIndices = element.vertex_indices || element.vertex_index; // issue #9338\n if (vertexIndices.length === 3) {\n buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);\n } else if (vertexIndices.length === 4) {\n buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);\n buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);\n }\n break;\n\n default:\n break;\n }\n}\n"],"file":"parse-ply-in-batches.js"}