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