@loaders.gl/ply 4.0.0-alpha.5 → 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.
- package/dist/bundle.js +2 -2
- package/dist/dist.min.js +201 -609
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/index.js +51 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/lib/get-ply-schema.js +28 -0
- package/dist/es5/lib/get-ply-schema.js.map +1 -0
- package/dist/es5/lib/normalize-ply.js +93 -0
- package/dist/es5/lib/normalize-ply.js.map +1 -0
- package/dist/es5/lib/parse-ply-in-batches.js +289 -0
- package/dist/es5/lib/parse-ply-in-batches.js.map +1 -0
- package/dist/es5/lib/parse-ply.js +348 -0
- package/dist/es5/lib/parse-ply.js.map +1 -0
- package/dist/es5/lib/ply-types.js +2 -0
- package/dist/es5/lib/ply-types.js.map +1 -0
- package/dist/es5/ply-loader.js +26 -0
- package/dist/es5/ply-loader.js.map +1 -0
- package/dist/es5/workers/ply-worker.js +6 -0
- package/dist/es5/workers/ply-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/get-ply-schema.js +22 -0
- package/dist/esm/lib/get-ply-schema.js.map +1 -0
- package/dist/esm/lib/normalize-ply.js +86 -0
- package/dist/esm/lib/normalize-ply.js.map +1 -0
- package/dist/esm/lib/parse-ply-in-batches.js +177 -0
- package/dist/esm/lib/parse-ply-in-batches.js.map +1 -0
- package/dist/esm/lib/parse-ply.js +319 -0
- package/dist/esm/lib/parse-ply.js.map +1 -0
- package/dist/esm/lib/ply-types.js +2 -0
- package/dist/esm/lib/ply-types.js.map +1 -0
- package/dist/esm/ply-loader.js +18 -0
- package/dist/esm/ply-loader.js.map +1 -0
- package/dist/esm/workers/ply-worker.js +4 -0
- package/dist/esm/workers/ply-worker.js.map +1 -0
- package/dist/index.d.ts +7 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -11
- package/dist/lib/get-ply-schema.js +34 -24
- package/dist/lib/normalize-ply.js +76 -65
- package/dist/lib/parse-ply-in-batches.d.ts +1 -1
- package/dist/lib/parse-ply-in-batches.d.ts.map +1 -1
- package/dist/lib/parse-ply-in-batches.js +237 -202
- package/dist/lib/parse-ply.d.ts +4 -1
- package/dist/lib/parse-ply.d.ts.map +1 -1
- package/dist/lib/parse-ply.js +378 -299
- package/dist/lib/ply-types.d.ts +22 -14
- package/dist/lib/ply-types.d.ts.map +1 -1
- package/dist/lib/ply-types.js +2 -2
- package/dist/ply-loader.d.ts +3 -17
- package/dist/ply-loader.d.ts.map +1 -1
- package/dist/ply-loader.js +27 -18
- package/dist/ply-worker.js +240 -578
- package/dist/workers/ply-worker.js +5 -4
- package/package.json +6 -6
- package/src/index.ts +15 -10
- package/src/lib/get-ply-schema.ts +11 -10
- package/src/lib/normalize-ply.ts +34 -12
- package/src/lib/parse-ply-in-batches.ts +20 -22
- package/src/lib/parse-ply.ts +114 -55
- package/src/lib/ply-types.ts +21 -12
- package/src/ply-loader.ts +4 -3
- package/dist/bundle.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/get-ply-schema.js.map +0 -1
- package/dist/lib/normalize-ply.js.map +0 -1
- package/dist/lib/parse-ply-in-batches.js.map +0 -1
- package/dist/lib/parse-ply.js.map +0 -1
- package/dist/lib/ply-types.js.map +0 -1
- package/dist/ply-loader.js.map +0 -1
- package/dist/workers/ply-worker.js.map +0 -1
|
@@ -1,218 +1,253 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.parsePLYInBatches = void 0;
|
|
29
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
30
|
+
const normalize_ply_1 = __importDefault(require("./normalize-ply"));
|
|
3
31
|
let currentElement;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
/**
|
|
33
|
+
* PARSER
|
|
34
|
+
* @param iterator
|
|
35
|
+
* @param options
|
|
36
|
+
*/
|
|
37
|
+
async function* parsePLYInBatches(iterator, options) {
|
|
38
|
+
const lineIterator = (0, loader_utils_1.makeLineIterator)((0, loader_utils_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);
|
|
19
50
|
}
|
|
20
|
-
|
|
51
|
+
exports.parsePLYInBatches = parsePLYInBatches;
|
|
52
|
+
/**
|
|
53
|
+
* Parses header
|
|
54
|
+
* @param lineIterator
|
|
55
|
+
* @param options
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
21
58
|
async function parsePLYHeader(lineIterator, options) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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);
|
|
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, loader_utils_1.forEach)(lineIterator, (line) => {
|
|
67
|
+
line = line.trim();
|
|
68
|
+
// End of header
|
|
69
|
+
if (line === 'end_header') {
|
|
70
|
+
return true; // Returning true cancels `forEach`
|
|
57
71
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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);
|
|
73
113
|
}
|
|
74
|
-
|
|
75
|
-
return false;
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
if (currentElement) {
|
|
79
|
-
header.elements.push(currentElement);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return header;
|
|
114
|
+
return header;
|
|
83
115
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return property;
|
|
116
|
+
function makePLYElementProperty(propertyValues, propertyNameMapping) {
|
|
117
|
+
const type = propertyValues[0];
|
|
118
|
+
switch (type) {
|
|
119
|
+
case 'list':
|
|
120
|
+
return {
|
|
121
|
+
type,
|
|
122
|
+
name: propertyValues[3],
|
|
123
|
+
countType: propertyValues[1],
|
|
124
|
+
itemType: propertyValues[2]
|
|
125
|
+
};
|
|
126
|
+
default:
|
|
127
|
+
return {
|
|
128
|
+
type,
|
|
129
|
+
name: propertyValues[1]
|
|
130
|
+
};
|
|
131
|
+
}
|
|
103
132
|
}
|
|
104
|
-
|
|
133
|
+
// ASCII PARSING
|
|
134
|
+
/**
|
|
135
|
+
* @param lineIterator
|
|
136
|
+
* @param header
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
105
139
|
async function parseASCII(lineIterator, header) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
currentElementCount++;
|
|
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 = parsePLYElement(header.elements[currentElement].properties, line);
|
|
158
|
+
handleElement(attributes, header.elements[currentElement].name, element);
|
|
159
|
+
currentElementCount++;
|
|
160
|
+
}
|
|
128
161
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
return attributes;
|
|
162
|
+
return attributes;
|
|
132
163
|
}
|
|
133
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Parses ASCII number
|
|
166
|
+
* @param n
|
|
167
|
+
* @param type
|
|
168
|
+
* @returns ASCII number
|
|
169
|
+
*/
|
|
170
|
+
// eslint-disable-next-line complexity
|
|
134
171
|
function parseASCIINumber(n, type) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
throw new Error(type);
|
|
158
|
-
}
|
|
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
|
+
}
|
|
159
194
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
195
|
+
/**
|
|
196
|
+
* Parses ASCII element
|
|
197
|
+
* @param properties
|
|
198
|
+
* @param line
|
|
199
|
+
* @returns element
|
|
200
|
+
*/
|
|
201
|
+
function parsePLYElement(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
|
+
}
|
|
177
216
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return element;
|
|
217
|
+
return element;
|
|
181
218
|
}
|
|
182
|
-
|
|
219
|
+
/**
|
|
220
|
+
* @param buffer
|
|
221
|
+
* @param elementName
|
|
222
|
+
* @param element
|
|
223
|
+
*/
|
|
224
|
+
// HELPER FUNCTIONS
|
|
225
|
+
// eslint-disable-next-line complexity
|
|
183
226
|
function handleElement(buffer, elementName, element = {}) {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
default:
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
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
|
+
}
|
|
217
253
|
}
|
|
218
|
-
//# sourceMappingURL=parse-ply-in-batches.js.map
|
package/dist/lib/parse-ply.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { PLYMesh } from './ply-types';
|
|
2
|
+
export type ParsePLYOptions = {
|
|
3
|
+
propertyNameMapping?: Record<string, string>;
|
|
4
|
+
};
|
|
2
5
|
/**
|
|
3
6
|
* @param data
|
|
4
7
|
* @param options
|
|
5
8
|
* @returns
|
|
6
9
|
*/
|
|
7
|
-
export
|
|
10
|
+
export declare function parsePLY(data: ArrayBuffer | string, options?: ParsePLYOptions): PLYMesh;
|
|
8
11
|
//# sourceMappingURL=parse-ply.d.ts.map
|
|
@@ -1 +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
|
|
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,MAAM,MAAM,eAAe,GAAG;IAC5B,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,OAAO,CAc3F"}
|