@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.
- package/dist/bundle.js +2 -2
- package/dist/bundle.js.map +1 -0
- package/dist/dist.min.js +3 -11
- package/dist/index.js +11 -21
- package/dist/index.js.map +1 -0
- package/dist/lib/get-ply-schema.js +24 -33
- package/dist/lib/get-ply-schema.js.map +1 -0
- package/dist/lib/normalize-ply.js +65 -54
- package/dist/lib/normalize-ply.js.map +1 -0
- package/dist/lib/parse-ply-in-batches.d.ts.map +1 -1
- package/dist/lib/parse-ply-in-batches.js +200 -235
- package/dist/lib/parse-ply-in-batches.js.map +1 -0
- package/dist/lib/parse-ply.js +297 -320
- package/dist/lib/parse-ply.js.map +1 -0
- package/dist/lib/ply-types.js +2 -2
- package/dist/{es5/lib → lib}/ply-types.js.map +0 -0
- package/dist/ply-loader.js +18 -27
- package/dist/ply-loader.js.map +1 -0
- package/dist/ply-worker.js +1 -1
- package/dist/workers/ply-worker.js +4 -5
- package/dist/workers/ply-worker.js.map +1 -0
- package/package.json +7 -10
- package/src/lib/parse-ply-in-batches.ts +3 -4
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -63
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/get-ply-schema.js +0 -35
- package/dist/es5/lib/get-ply-schema.js.map +0 -1
- package/dist/es5/lib/normalize-ply.js +0 -78
- package/dist/es5/lib/normalize-ply.js.map +0 -1
- package/dist/es5/lib/parse-ply-in-batches.js +0 -370
- package/dist/es5/lib/parse-ply-in-batches.js.map +0 -1
- package/dist/es5/lib/parse-ply.js +0 -340
- package/dist/es5/lib/parse-ply.js.map +0 -1
- package/dist/es5/lib/ply-types.js +0 -2
- package/dist/es5/ply-loader.js +0 -27
- package/dist/es5/ply-loader.js.map +0 -1
- package/dist/es5/workers/ply-worker.js +0 -8
- package/dist/es5/workers/ply-worker.js.map +0 -1
- package/dist/esm/bundle.js +0 -5
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/index.js +0 -12
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/get-ply-schema.js +0 -27
- package/dist/esm/lib/get-ply-schema.js.map +0 -1
- package/dist/esm/lib/normalize-ply.js +0 -69
- package/dist/esm/lib/normalize-ply.js.map +0 -1
- package/dist/esm/lib/parse-ply-in-batches.js +0 -218
- package/dist/esm/lib/parse-ply-in-batches.js.map +0 -1
- package/dist/esm/lib/parse-ply.js +0 -327
- package/dist/esm/lib/parse-ply.js.map +0 -1
- package/dist/esm/lib/ply-types.js +0 -2
- package/dist/esm/lib/ply-types.js.map +0 -1
- package/dist/esm/ply-loader.js +0 -19
- package/dist/esm/ply-loader.js.map +0 -1
- package/dist/esm/workers/ply-worker.js +0 -4
- package/dist/esm/workers/ply-worker.js.map +0 -1
package/dist/lib/parse-ply.js
CHANGED
|
@@ -1,350 +1,327 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const text = new TextDecoder().decode(data);
|
|
17
|
-
header = parseHeader(text, options);
|
|
18
|
-
attributes = header.format === 'ascii' ? parseASCII(text, header) : parseBinary(data, header);
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
header = parseHeader(data, options);
|
|
22
|
-
attributes = parseASCII(data, header);
|
|
23
|
-
}
|
|
24
|
-
return (0, normalize_ply_1.default)(header, attributes);
|
|
1
|
+
import normalizePLY from './normalize-ply';
|
|
2
|
+
export default function parsePLY(data, options = {}) {
|
|
3
|
+
let header;
|
|
4
|
+
let attributes;
|
|
5
|
+
|
|
6
|
+
if (data instanceof ArrayBuffer) {
|
|
7
|
+
const text = new TextDecoder().decode(data);
|
|
8
|
+
header = parseHeader(text, options);
|
|
9
|
+
attributes = header.format === 'ascii' ? parseASCII(text, header) : parseBinary(data, header);
|
|
10
|
+
} else {
|
|
11
|
+
header = parseHeader(data, options);
|
|
12
|
+
attributes = parseASCII(data, header);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return normalizePLY(header, attributes);
|
|
25
16
|
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param data
|
|
29
|
-
* @param options
|
|
30
|
-
* @returns header
|
|
31
|
-
*/
|
|
17
|
+
|
|
32
18
|
function parseHeader(data, options) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
const PLY_HEADER_PATTERN = /ply([\s\S]*)end_header\s/;
|
|
20
|
+
let headerText = '';
|
|
21
|
+
let headerLength = 0;
|
|
22
|
+
const result = PLY_HEADER_PATTERN.exec(data);
|
|
23
|
+
|
|
24
|
+
if (result !== null) {
|
|
25
|
+
headerText = result[1];
|
|
26
|
+
headerLength = result[0].length;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const lines = headerText.split('\n');
|
|
30
|
+
const header = parseHeaderLines(lines, headerLength, options);
|
|
31
|
+
return header;
|
|
44
32
|
}
|
|
45
|
-
|
|
46
|
-
* @param lines
|
|
47
|
-
* @param headerLength
|
|
48
|
-
* @param options
|
|
49
|
-
* @returns header
|
|
50
|
-
*/
|
|
33
|
+
|
|
51
34
|
function parseHeaderLines(lines, headerLength, options) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
35
|
+
const header = {
|
|
36
|
+
comments: [],
|
|
37
|
+
elements: [],
|
|
38
|
+
headerLength
|
|
39
|
+
};
|
|
40
|
+
let lineType;
|
|
41
|
+
let lineValues;
|
|
42
|
+
let currentElement = null;
|
|
43
|
+
|
|
44
|
+
for (let i = 0; i < lines.length; i++) {
|
|
45
|
+
let line = lines[i];
|
|
46
|
+
line = line.trim();
|
|
47
|
+
|
|
48
|
+
if (line === '') {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
lineValues = line.split(/\s+/);
|
|
53
|
+
lineType = lineValues.shift();
|
|
54
|
+
line = lineValues.join(' ');
|
|
55
|
+
|
|
56
|
+
switch (lineType) {
|
|
57
|
+
case 'format':
|
|
58
|
+
header.format = lineValues[0];
|
|
59
|
+
header.version = lineValues[1];
|
|
60
|
+
break;
|
|
61
|
+
|
|
62
|
+
case 'comment':
|
|
63
|
+
header.comments.push(line);
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case 'element':
|
|
67
|
+
if (currentElement) {
|
|
68
|
+
header.elements.push(currentElement);
|
|
66
69
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
case 'element':
|
|
79
|
-
if (currentElement) {
|
|
80
|
-
header.elements.push(currentElement);
|
|
81
|
-
}
|
|
82
|
-
currentElement = {
|
|
83
|
-
name: lineValues[0],
|
|
84
|
-
count: parseInt(lineValues[1], 10),
|
|
85
|
-
properties: []
|
|
86
|
-
};
|
|
87
|
-
break;
|
|
88
|
-
case 'property':
|
|
89
|
-
if (!currentElement) {
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
currentElement.properties.push(makePLYElementProperty(lineValues, options.propertyNameMapping));
|
|
93
|
-
break;
|
|
94
|
-
default:
|
|
95
|
-
// eslint-disable-next-line
|
|
96
|
-
console.log('unhandled', lineType, lineValues);
|
|
70
|
+
|
|
71
|
+
currentElement = {
|
|
72
|
+
name: lineValues[0],
|
|
73
|
+
count: parseInt(lineValues[1], 10),
|
|
74
|
+
properties: []
|
|
75
|
+
};
|
|
76
|
+
break;
|
|
77
|
+
|
|
78
|
+
case 'property':
|
|
79
|
+
if (!currentElement) {
|
|
80
|
+
break;
|
|
97
81
|
}
|
|
82
|
+
|
|
83
|
+
currentElement.properties.push(makePLYElementProperty(lineValues, options.propertyNameMapping));
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
default:
|
|
87
|
+
console.log('unhandled', lineType, lineValues);
|
|
98
88
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (currentElement !== undefined) {
|
|
92
|
+
header.elements.push(currentElement);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return header;
|
|
103
96
|
}
|
|
104
|
-
|
|
105
|
-
* @param propertValues
|
|
106
|
-
* @param propertyNameMapping
|
|
107
|
-
* @returns property of ply element
|
|
108
|
-
*/
|
|
97
|
+
|
|
109
98
|
function makePLYElementProperty(propertValues, propertyNameMapping) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
99
|
+
const property = {
|
|
100
|
+
type: propertValues[0]
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
if (property.type === 'list') {
|
|
104
|
+
property.name = propertValues[3];
|
|
105
|
+
property.countType = propertValues[1];
|
|
106
|
+
property.itemType = propertValues[2];
|
|
107
|
+
} else {
|
|
108
|
+
property.name = propertValues[1];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (propertyNameMapping && property.name in propertyNameMapping) {
|
|
112
|
+
property.name = propertyNameMapping[property.name];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return property;
|
|
125
116
|
}
|
|
126
|
-
|
|
127
|
-
* Parses ASCII number
|
|
128
|
-
* @param n
|
|
129
|
-
* @param type
|
|
130
|
-
* @returns
|
|
131
|
-
*/
|
|
132
|
-
// eslint-disable-next-line complexity
|
|
117
|
+
|
|
133
118
|
function parseASCIINumber(n, type) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
119
|
+
switch (type) {
|
|
120
|
+
case 'char':
|
|
121
|
+
case 'uchar':
|
|
122
|
+
case 'short':
|
|
123
|
+
case 'ushort':
|
|
124
|
+
case 'int':
|
|
125
|
+
case 'uint':
|
|
126
|
+
case 'int8':
|
|
127
|
+
case 'uint8':
|
|
128
|
+
case 'int16':
|
|
129
|
+
case 'uint16':
|
|
130
|
+
case 'int32':
|
|
131
|
+
case 'uint32':
|
|
132
|
+
return parseInt(n, 10);
|
|
133
|
+
|
|
134
|
+
case 'float':
|
|
135
|
+
case 'double':
|
|
136
|
+
case 'float32':
|
|
137
|
+
case 'float64':
|
|
138
|
+
return parseFloat(n);
|
|
139
|
+
|
|
140
|
+
default:
|
|
141
|
+
throw new Error(type);
|
|
142
|
+
}
|
|
156
143
|
}
|
|
157
|
-
|
|
158
|
-
* @param properties
|
|
159
|
-
* @param line
|
|
160
|
-
* @returns ASCII element
|
|
161
|
-
*/
|
|
144
|
+
|
|
162
145
|
function parseASCIIElement(properties, line) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
146
|
+
const values = line.split(/\s+/);
|
|
147
|
+
const element = {};
|
|
148
|
+
|
|
149
|
+
for (let i = 0; i < properties.length; i++) {
|
|
150
|
+
if (properties[i].type === 'list') {
|
|
151
|
+
const list = [];
|
|
152
|
+
const n = parseASCIINumber(values.shift(), properties[i].countType);
|
|
153
|
+
|
|
154
|
+
for (let j = 0; j < n; j++) {
|
|
155
|
+
list.push(parseASCIINumber(values.shift(), properties[i].itemType));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
element[properties[i].name] = list;
|
|
159
|
+
} else {
|
|
160
|
+
element[properties[i].name] = parseASCIINumber(values.shift(), properties[i].type);
|
|
177
161
|
}
|
|
178
|
-
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return element;
|
|
179
165
|
}
|
|
180
|
-
|
|
181
|
-
* @param data
|
|
182
|
-
* @param header
|
|
183
|
-
* @returns [attributes]
|
|
184
|
-
*/
|
|
166
|
+
|
|
185
167
|
function parseASCII(data, header) {
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
168
|
+
const attributes = {
|
|
169
|
+
indices: [],
|
|
170
|
+
vertices: [],
|
|
171
|
+
normals: [],
|
|
172
|
+
uvs: [],
|
|
173
|
+
colors: []
|
|
174
|
+
};
|
|
175
|
+
let result;
|
|
176
|
+
const patternBody = /end_header\s([\s\S]*)$/;
|
|
177
|
+
let body = '';
|
|
178
|
+
|
|
179
|
+
if ((result = patternBody.exec(data)) !== null) {
|
|
180
|
+
body = result[1];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const lines = body.split('\n');
|
|
184
|
+
let currentElement = 0;
|
|
185
|
+
let currentElementCount = 0;
|
|
186
|
+
|
|
187
|
+
for (let i = 0; i < lines.length; i++) {
|
|
188
|
+
let line = lines[i];
|
|
189
|
+
line = line.trim();
|
|
190
|
+
|
|
191
|
+
if (line !== '') {
|
|
192
|
+
if (currentElementCount >= header.elements[currentElement].count) {
|
|
193
|
+
currentElement++;
|
|
194
|
+
currentElementCount = 0;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const element = parseASCIIElement(header.elements[currentElement].properties, line);
|
|
198
|
+
handleElement(attributes, header.elements[currentElement].name, element);
|
|
199
|
+
currentElementCount++;
|
|
215
200
|
}
|
|
216
|
-
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return attributes;
|
|
217
204
|
}
|
|
218
|
-
|
|
219
|
-
* @param buffer
|
|
220
|
-
* @param elementName
|
|
221
|
-
* @param element
|
|
222
|
-
*/
|
|
223
|
-
// eslint-disable-next-line complexity
|
|
205
|
+
|
|
224
206
|
function handleElement(buffer, elementName, element = {}) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if ('s' in element && 't' in element) {
|
|
231
|
-
buffer.uvs.push(element.s, element.t);
|
|
232
|
-
}
|
|
233
|
-
if ('red' in element && 'green' in element && 'blue' in element) {
|
|
234
|
-
buffer.colors.push(element.red, element.green, element.blue);
|
|
235
|
-
}
|
|
207
|
+
if (elementName === 'vertex') {
|
|
208
|
+
buffer.vertices.push(element.x, element.y, element.z);
|
|
209
|
+
|
|
210
|
+
if ('nx' in element && 'ny' in element && 'nz' in element) {
|
|
211
|
+
buffer.normals.push(element.nx, element.ny, element.nz);
|
|
236
212
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
|
|
241
|
-
}
|
|
242
|
-
else if (vertexIndices.length === 4) {
|
|
243
|
-
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
|
|
244
|
-
buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
|
|
245
|
-
}
|
|
213
|
+
|
|
214
|
+
if ('s' in element && 't' in element) {
|
|
215
|
+
buffer.uvs.push(element.s, element.t);
|
|
246
216
|
}
|
|
217
|
+
|
|
218
|
+
if ('red' in element && 'green' in element && 'blue' in element) {
|
|
219
|
+
buffer.colors.push(element.red, element.green, element.blue);
|
|
220
|
+
}
|
|
221
|
+
} else if (elementName === 'face') {
|
|
222
|
+
const vertexIndices = element.vertex_indices || element.vertex_index;
|
|
223
|
+
|
|
224
|
+
if (vertexIndices.length === 3) {
|
|
225
|
+
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[2]);
|
|
226
|
+
} else if (vertexIndices.length === 4) {
|
|
227
|
+
buffer.indices.push(vertexIndices[0], vertexIndices[1], vertexIndices[3]);
|
|
228
|
+
buffer.indices.push(vertexIndices[1], vertexIndices[2], vertexIndices[3]);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
247
231
|
}
|
|
248
|
-
|
|
249
|
-
* Reads binary data
|
|
250
|
-
* @param dataview
|
|
251
|
-
* @param at
|
|
252
|
-
* @param type
|
|
253
|
-
* @param littleEndian
|
|
254
|
-
* @returns [number, number]
|
|
255
|
-
*/
|
|
256
|
-
// eslint-disable-next-line complexity
|
|
232
|
+
|
|
257
233
|
function binaryRead(dataview, at, type, littleEndian) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
234
|
+
switch (type) {
|
|
235
|
+
case 'int8':
|
|
236
|
+
case 'char':
|
|
237
|
+
return [dataview.getInt8(at), 1];
|
|
238
|
+
|
|
239
|
+
case 'uint8':
|
|
240
|
+
case 'uchar':
|
|
241
|
+
return [dataview.getUint8(at), 1];
|
|
242
|
+
|
|
243
|
+
case 'int16':
|
|
244
|
+
case 'short':
|
|
245
|
+
return [dataview.getInt16(at, littleEndian), 2];
|
|
246
|
+
|
|
247
|
+
case 'uint16':
|
|
248
|
+
case 'ushort':
|
|
249
|
+
return [dataview.getUint16(at, littleEndian), 2];
|
|
250
|
+
|
|
251
|
+
case 'int32':
|
|
252
|
+
case 'int':
|
|
253
|
+
return [dataview.getInt32(at, littleEndian), 4];
|
|
254
|
+
|
|
255
|
+
case 'uint32':
|
|
256
|
+
case 'uint':
|
|
257
|
+
return [dataview.getUint32(at, littleEndian), 4];
|
|
258
|
+
|
|
259
|
+
case 'float32':
|
|
260
|
+
case 'float':
|
|
261
|
+
return [dataview.getFloat32(at, littleEndian), 4];
|
|
262
|
+
|
|
263
|
+
case 'float64':
|
|
264
|
+
case 'double':
|
|
265
|
+
return [dataview.getFloat64(at, littleEndian), 8];
|
|
266
|
+
|
|
267
|
+
default:
|
|
268
|
+
throw new Error(type);
|
|
269
|
+
}
|
|
287
270
|
}
|
|
288
|
-
|
|
289
|
-
* Reads binary data
|
|
290
|
-
* @param dataview
|
|
291
|
-
* @param at
|
|
292
|
-
* @param properties
|
|
293
|
-
* @param littleEndian
|
|
294
|
-
* @returns [object, number]
|
|
295
|
-
*/
|
|
271
|
+
|
|
296
272
|
function binaryReadElement(dataview, at, properties, littleEndian) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
273
|
+
const element = {};
|
|
274
|
+
let result;
|
|
275
|
+
let read = 0;
|
|
276
|
+
|
|
277
|
+
for (let i = 0; i < properties.length; i++) {
|
|
278
|
+
if (properties[i].type === 'list') {
|
|
279
|
+
const list = [];
|
|
280
|
+
result = binaryRead(dataview, at + read, properties[i].countType, littleEndian);
|
|
281
|
+
const n = result[0];
|
|
282
|
+
read += result[1];
|
|
283
|
+
|
|
284
|
+
for (let j = 0; j < n; j++) {
|
|
285
|
+
result = binaryRead(dataview, at + read, properties[i].itemType, littleEndian);
|
|
286
|
+
list.push(result[0]);
|
|
287
|
+
read += result[1];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
element[properties[i].name] = list;
|
|
291
|
+
} else {
|
|
292
|
+
result = binaryRead(dataview, at + read, properties[i].type, littleEndian);
|
|
293
|
+
element[properties[i].name] = result[0];
|
|
294
|
+
read += result[1];
|
|
319
295
|
}
|
|
320
|
-
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return [element, read];
|
|
321
299
|
}
|
|
322
|
-
|
|
323
|
-
* Parses binary data
|
|
324
|
-
* @param data
|
|
325
|
-
* @param header
|
|
326
|
-
* @returns [attributes] of data
|
|
327
|
-
*/
|
|
300
|
+
|
|
328
301
|
function parseBinary(data, header) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
302
|
+
const attributes = {
|
|
303
|
+
indices: [],
|
|
304
|
+
vertices: [],
|
|
305
|
+
normals: [],
|
|
306
|
+
uvs: [],
|
|
307
|
+
colors: []
|
|
308
|
+
};
|
|
309
|
+
const littleEndian = header.format === 'binary_little_endian';
|
|
310
|
+
const body = new DataView(data, header.headerLength);
|
|
311
|
+
let result;
|
|
312
|
+
let loc = 0;
|
|
313
|
+
|
|
314
|
+
for (let currentElement = 0; currentElement < header.elements.length; currentElement++) {
|
|
315
|
+
const count = header.elements[currentElement].count;
|
|
316
|
+
|
|
317
|
+
for (let currentElementCount = 0; currentElementCount < count; currentElementCount++) {
|
|
318
|
+
result = binaryReadElement(body, loc, header.elements[currentElement].properties, littleEndian);
|
|
319
|
+
loc += result[1];
|
|
320
|
+
const element = result[0];
|
|
321
|
+
handleElement(attributes, header.elements[currentElement].name, element);
|
|
348
322
|
}
|
|
349
|
-
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return attributes;
|
|
350
326
|
}
|
|
327
|
+
//# sourceMappingURL=parse-ply.js.map
|