@loaders.gl/obj 4.0.0-alpha.4 → 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.
Files changed (89) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +2 -2
  4. package/dist/dist.min.js +744 -0
  5. package/dist/es5/bundle.js +6 -0
  6. package/dist/es5/bundle.js.map +1 -0
  7. package/dist/es5/index.js +74 -0
  8. package/dist/es5/index.js.map +1 -0
  9. package/dist/es5/lib/get-obj-schema.js +54 -0
  10. package/dist/es5/lib/get-obj-schema.js.map +1 -0
  11. package/dist/es5/lib/obj-types.js +2 -0
  12. package/dist/es5/lib/obj-types.js.map +1 -0
  13. package/dist/es5/lib/parse-mtl.js +86 -0
  14. package/dist/es5/lib/parse-mtl.js.map +1 -0
  15. package/dist/es5/lib/parse-obj-meshes.js +486 -0
  16. package/dist/es5/lib/parse-obj-meshes.js.map +1 -0
  17. package/dist/es5/lib/parse-obj.js +100 -0
  18. package/dist/es5/lib/parse-obj.js.map +1 -0
  19. package/dist/es5/mtl-loader.js +26 -0
  20. package/dist/es5/mtl-loader.js.map +1 -0
  21. package/dist/es5/obj-loader.js +27 -0
  22. package/dist/es5/obj-loader.js.map +1 -0
  23. package/dist/es5/workers/obj-worker.js +6 -0
  24. package/dist/es5/workers/obj-worker.js.map +1 -0
  25. package/dist/esm/bundle.js +4 -0
  26. package/dist/esm/bundle.js.map +1 -0
  27. package/dist/esm/index.js +18 -0
  28. package/dist/esm/index.js.map +1 -0
  29. package/dist/esm/lib/get-obj-schema.js +49 -0
  30. package/dist/esm/lib/get-obj-schema.js.map +1 -0
  31. package/dist/esm/lib/obj-types.js +2 -0
  32. package/dist/esm/lib/obj-types.js.map +1 -0
  33. package/dist/esm/lib/parse-mtl.js +68 -0
  34. package/dist/esm/lib/parse-mtl.js.map +1 -0
  35. package/dist/esm/lib/parse-obj-meshes.js +385 -0
  36. package/dist/esm/lib/parse-obj-meshes.js.map +1 -0
  37. package/dist/{lib/load-obj.js → esm/lib/parse-obj.js} +5 -15
  38. package/dist/esm/lib/parse-obj.js.map +1 -0
  39. package/dist/esm/mtl-loader.js +16 -0
  40. package/dist/esm/mtl-loader.js.map +1 -0
  41. package/dist/esm/obj-loader.js +19 -0
  42. package/dist/esm/obj-loader.js.map +1 -0
  43. package/dist/esm/workers/obj-worker.js +4 -0
  44. package/dist/esm/workers/obj-worker.js.map +1 -0
  45. package/dist/index.d.ts +18 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +26 -8
  48. package/dist/lib/get-obj-schema.d.ts +4 -0
  49. package/dist/lib/get-obj-schema.d.ts.map +1 -0
  50. package/dist/lib/get-obj-schema.js +33 -33
  51. package/dist/lib/obj-types.d.ts +1 -0
  52. package/dist/lib/obj-types.d.ts.map +1 -0
  53. package/dist/lib/obj-types.js +1 -2
  54. package/dist/lib/parse-mtl.d.ts +34 -0
  55. package/dist/lib/parse-mtl.d.ts.map +1 -0
  56. package/dist/lib/parse-mtl.js +201 -0
  57. package/dist/lib/parse-obj-meshes.d.ts +5 -0
  58. package/dist/lib/parse-obj-meshes.d.ts.map +1 -0
  59. package/dist/lib/parse-obj-meshes.js +440 -0
  60. package/dist/lib/parse-obj.d.ts +3 -0
  61. package/dist/lib/parse-obj.d.ts.map +1 -0
  62. package/dist/lib/parse-obj.js +63 -449
  63. package/dist/mtl-loader.d.ts +12 -0
  64. package/dist/mtl-loader.d.ts.map +1 -0
  65. package/dist/mtl-loader.js +24 -0
  66. package/dist/obj-loader.d.ts +11 -0
  67. package/dist/obj-loader.d.ts.map +1 -0
  68. package/dist/obj-loader.js +24 -18
  69. package/dist/obj-worker.js +213 -507
  70. package/dist/workers/obj-worker.d.ts +2 -0
  71. package/dist/workers/obj-worker.d.ts.map +1 -0
  72. package/dist/workers/obj-worker.js +5 -4
  73. package/package.json +9 -9
  74. package/src/index.ts +25 -4
  75. package/src/lib/get-obj-schema.ts +24 -20
  76. package/src/lib/parse-mtl.ts +246 -0
  77. package/src/lib/parse-obj-meshes.ts +525 -0
  78. package/src/lib/parse-obj.ts +67 -508
  79. package/src/mtl-loader.ts +31 -0
  80. package/src/obj-loader.ts +8 -3
  81. package/dist/bundle.js.map +0 -1
  82. package/dist/index.js.map +0 -1
  83. package/dist/lib/get-obj-schema.js.map +0 -1
  84. package/dist/lib/load-obj.js.map +0 -1
  85. package/dist/lib/obj-types.js.map +0 -1
  86. package/dist/lib/parse-obj.js.map +0 -1
  87. package/dist/obj-loader.js.map +0 -1
  88. package/src/lib/load-obj.ts +0 -83
  89. /package/src/workers/{obj-worker.js → obj-worker.ts} +0 -0
@@ -0,0 +1,525 @@
1
+ // OBJ Loader, adapted from THREE.js (MIT license)
2
+ //
3
+ // Attributions per original THREE.js source file:
4
+ //
5
+ // @author mrdoob / http://mrdoob.com/
6
+
7
+ // @ts-nocheck
8
+
9
+ // o object_name | g group_name
10
+ const OBJECT_RE = /^[og]\s*(.+)?/;
11
+ // mtllib file_reference
12
+ const MATERIAL_RE = /^mtllib /;
13
+ // usemtl material_name
14
+ const MATERIAL_USE_RE = /^usemtl /;
15
+
16
+ class MeshMaterial {
17
+ constructor({index, name = '', mtllib, smooth, groupStart}) {
18
+ this.index = index;
19
+ this.name = name;
20
+ this.mtllib = mtllib;
21
+ this.smooth = smooth;
22
+ this.groupStart = groupStart;
23
+ this.groupEnd = -1;
24
+ this.groupCount = -1;
25
+ this.inherited = false;
26
+ }
27
+
28
+ clone(index = this.index) {
29
+ return new MeshMaterial({
30
+ index,
31
+ name: this.name,
32
+ mtllib: this.mtllib,
33
+ smooth: this.smooth,
34
+ groupStart: 0
35
+ });
36
+ }
37
+ }
38
+
39
+ class MeshObject {
40
+ constructor(name = '') {
41
+ this.name = name;
42
+
43
+ this.geometry = {
44
+ vertices: [],
45
+ normals: [],
46
+ colors: [],
47
+ uvs: []
48
+ };
49
+
50
+ this.materials = [];
51
+ this.smooth = true;
52
+
53
+ this.fromDeclaration = null;
54
+ }
55
+
56
+ startMaterial(name, libraries) {
57
+ const previous = this._finalize(false);
58
+
59
+ // New usemtl declaration overwrites an inherited material, except if faces were declared
60
+ // after the material, then it must be preserved for proper MultiMaterial continuation.
61
+ if (previous && (previous.inherited || previous.groupCount <= 0)) {
62
+ this.materials.splice(previous.index, 1);
63
+ }
64
+
65
+ const material = new MeshMaterial({
66
+ index: this.materials.length,
67
+ name,
68
+ mtllib:
69
+ Array.isArray(libraries) && libraries.length > 0 ? libraries[libraries.length - 1] : '',
70
+ smooth: previous !== undefined ? previous.smooth : this.smooth,
71
+ groupStart: previous !== undefined ? previous.groupEnd : 0
72
+ });
73
+
74
+ this.materials.push(material);
75
+
76
+ return material;
77
+ }
78
+
79
+ currentMaterial() {
80
+ if (this.materials.length > 0) {
81
+ return this.materials[this.materials.length - 1];
82
+ }
83
+
84
+ return undefined;
85
+ }
86
+
87
+ _finalize(end) {
88
+ const lastMultiMaterial = this.currentMaterial();
89
+ if (lastMultiMaterial && lastMultiMaterial.groupEnd === -1) {
90
+ lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
91
+ lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
92
+ lastMultiMaterial.inherited = false;
93
+ }
94
+
95
+ // Ignore objects tail materials if no face declarations followed them before a new o/g started.
96
+ if (end && this.materials.length > 1) {
97
+ for (let mi = this.materials.length - 1; mi >= 0; mi--) {
98
+ if (this.materials[mi].groupCount <= 0) {
99
+ this.materials.splice(mi, 1);
100
+ }
101
+ }
102
+ }
103
+
104
+ // Guarantee at least one empty material, this makes the creation later more straight forward.
105
+ if (end && this.materials.length === 0) {
106
+ this.materials.push({
107
+ name: '',
108
+ smooth: this.smooth
109
+ });
110
+ }
111
+
112
+ return lastMultiMaterial;
113
+ }
114
+ }
115
+
116
+ class ParserState {
117
+ constructor() {
118
+ this.objects = [];
119
+ this.object = null;
120
+
121
+ this.vertices = [];
122
+ this.normals = [];
123
+ this.colors = [];
124
+ this.uvs = [];
125
+
126
+ this.materialLibraries = [];
127
+
128
+ this.startObject('', false);
129
+ }
130
+
131
+ startObject(name, fromDeclaration = true) {
132
+ // If the current object (initial from reset) is not from a g/o declaration in the parsed
133
+ // file. We need to use it for the first parsed g/o to keep things in sync.
134
+ if (this.object && !this.object.fromDeclaration) {
135
+ this.object.name = name;
136
+ this.object.fromDeclaration = fromDeclaration;
137
+ return;
138
+ }
139
+
140
+ const previousMaterial =
141
+ this.object && typeof this.object.currentMaterial === 'function'
142
+ ? this.object.currentMaterial()
143
+ : undefined;
144
+
145
+ if (this.object && typeof this.object._finalize === 'function') {
146
+ this.object._finalize(true);
147
+ }
148
+
149
+ this.object = new MeshObject(name);
150
+ this.object.fromDeclaration = fromDeclaration;
151
+
152
+ // Inherit previous objects material.
153
+ // Spec tells us that a declared material must be set to all objects until a new material is declared.
154
+ // If a usemtl declaration is encountered while this new object is being parsed, it will
155
+ // overwrite the inherited material. Exception being that there was already face declarations
156
+ // to the inherited material, then it will be preserved for proper MultiMaterial continuation.
157
+ if (previousMaterial && previousMaterial.name && typeof previousMaterial.clone === 'function') {
158
+ const declared = previousMaterial.clone(0);
159
+ declared.inherited = true;
160
+ this.object.materials.push(declared);
161
+ }
162
+
163
+ this.objects.push(this.object);
164
+ }
165
+
166
+ finalize() {
167
+ if (this.object && typeof this.object._finalize === 'function') {
168
+ this.object._finalize(true);
169
+ }
170
+ }
171
+
172
+ parseVertexIndex(value, len) {
173
+ const index = parseInt(value);
174
+ return (index >= 0 ? index - 1 : index + len / 3) * 3;
175
+ }
176
+
177
+ parseNormalIndex(value, len) {
178
+ const index = parseInt(value);
179
+ return (index >= 0 ? index - 1 : index + len / 3) * 3;
180
+ }
181
+
182
+ parseUVIndex(value, len) {
183
+ const index = parseInt(value);
184
+ return (index >= 0 ? index - 1 : index + len / 2) * 2;
185
+ }
186
+
187
+ addVertex(a, b, c) {
188
+ const src = this.vertices;
189
+ const dst = this.object.geometry.vertices;
190
+
191
+ dst.push(src[a + 0], src[a + 1], src[a + 2]);
192
+ dst.push(src[b + 0], src[b + 1], src[b + 2]);
193
+ dst.push(src[c + 0], src[c + 1], src[c + 2]);
194
+ }
195
+
196
+ addVertexPoint(a) {
197
+ const src = this.vertices;
198
+ const dst = this.object.geometry.vertices;
199
+
200
+ dst.push(src[a + 0], src[a + 1], src[a + 2]);
201
+ }
202
+
203
+ addVertexLine(a) {
204
+ const src = this.vertices;
205
+ const dst = this.object.geometry.vertices;
206
+
207
+ dst.push(src[a + 0], src[a + 1], src[a + 2]);
208
+ }
209
+
210
+ addNormal(a, b, c) {
211
+ const src = this.normals;
212
+ const dst = this.object.geometry.normals;
213
+
214
+ dst.push(src[a + 0], src[a + 1], src[a + 2]);
215
+ dst.push(src[b + 0], src[b + 1], src[b + 2]);
216
+ dst.push(src[c + 0], src[c + 1], src[c + 2]);
217
+ }
218
+
219
+ addColor(a, b, c) {
220
+ const src = this.colors;
221
+ const dst = this.object.geometry.colors;
222
+
223
+ dst.push(src[a + 0], src[a + 1], src[a + 2]);
224
+ dst.push(src[b + 0], src[b + 1], src[b + 2]);
225
+ dst.push(src[c + 0], src[c + 1], src[c + 2]);
226
+ }
227
+
228
+ addUV(a, b, c) {
229
+ const src = this.uvs;
230
+ const dst = this.object.geometry.uvs;
231
+
232
+ dst.push(src[a + 0], src[a + 1]);
233
+ dst.push(src[b + 0], src[b + 1]);
234
+ dst.push(src[c + 0], src[c + 1]);
235
+ }
236
+
237
+ addUVLine(a) {
238
+ const src = this.uvs;
239
+ const dst = this.object.geometry.uvs;
240
+
241
+ dst.push(src[a + 0], src[a + 1]);
242
+ }
243
+
244
+ // eslint-disable-next-line max-params
245
+ addFace(a, b, c, ua, ub, uc, na, nb, nc) {
246
+ const vLen = this.vertices.length;
247
+
248
+ let ia = this.parseVertexIndex(a, vLen);
249
+ let ib = this.parseVertexIndex(b, vLen);
250
+ let ic = this.parseVertexIndex(c, vLen);
251
+
252
+ this.addVertex(ia, ib, ic);
253
+
254
+ if (ua !== undefined && ua !== '') {
255
+ const uvLen = this.uvs.length;
256
+ ia = this.parseUVIndex(ua, uvLen);
257
+ ib = this.parseUVIndex(ub, uvLen);
258
+ ic = this.parseUVIndex(uc, uvLen);
259
+ this.addUV(ia, ib, ic);
260
+ }
261
+
262
+ if (na !== undefined && na !== '') {
263
+ // Normals are many times the same. If so, skip function call and parseInt.
264
+ const nLen = this.normals.length;
265
+ ia = this.parseNormalIndex(na, nLen);
266
+
267
+ ib = na === nb ? ia : this.parseNormalIndex(nb, nLen);
268
+ ic = na === nc ? ia : this.parseNormalIndex(nc, nLen);
269
+
270
+ this.addNormal(ia, ib, ic);
271
+ }
272
+
273
+ if (this.colors.length > 0) {
274
+ this.addColor(ia, ib, ic);
275
+ }
276
+ }
277
+
278
+ addPointGeometry(vertices) {
279
+ this.object.geometry.type = 'Points';
280
+
281
+ const vLen = this.vertices.length;
282
+
283
+ for (const vertex of vertices) {
284
+ this.addVertexPoint(this.parseVertexIndex(vertex, vLen));
285
+ }
286
+ }
287
+
288
+ addLineGeometry(vertices, uvs) {
289
+ this.object.geometry.type = 'Line';
290
+
291
+ const vLen = this.vertices.length;
292
+ const uvLen = this.uvs.length;
293
+
294
+ for (const vertex of vertices) {
295
+ this.addVertexLine(this.parseVertexIndex(vertex, vLen));
296
+ }
297
+
298
+ for (const uv of uvs) {
299
+ this.addUVLine(this.parseUVIndex(uv, uvLen));
300
+ }
301
+ }
302
+ }
303
+
304
+ // eslint-disable-next-line max-statements, complexity
305
+ export function parseOBJMeshes(text) {
306
+ const state = new ParserState();
307
+
308
+ if (text.indexOf('\r\n') !== -1) {
309
+ // This is faster than String.split with regex that splits on both
310
+ text = text.replace(/\r\n/g, '\n');
311
+ }
312
+
313
+ if (text.indexOf('\\\n') !== -1) {
314
+ // join lines separated by a line continuation character (\)
315
+ text = text.replace(/\\\n/g, '');
316
+ }
317
+
318
+ const lines = text.split('\n');
319
+ let line = '';
320
+ let lineFirstChar = '';
321
+ let lineLength = 0;
322
+ let result = [];
323
+
324
+ // Faster to just trim left side of the line. Use if available.
325
+ const trimLeft = typeof ''.trimLeft === 'function';
326
+
327
+ /* eslint-disable no-continue, max-depth */
328
+ for (let i = 0, l = lines.length; i < l; i++) {
329
+ line = lines[i];
330
+ line = trimLeft ? line.trimLeft() : line.trim();
331
+ lineLength = line.length;
332
+
333
+ if (lineLength === 0) continue;
334
+
335
+ lineFirstChar = line.charAt(0);
336
+
337
+ // @todo invoke passed in handler if any
338
+ if (lineFirstChar === '#') continue;
339
+
340
+ if (lineFirstChar === 'v') {
341
+ const data = line.split(/\s+/);
342
+
343
+ switch (data[0]) {
344
+ case 'v':
345
+ state.vertices.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
346
+ if (data.length === 8) {
347
+ state.colors.push(parseFloat(data[4]), parseFloat(data[5]), parseFloat(data[6]));
348
+ }
349
+ break;
350
+ case 'vn':
351
+ state.normals.push(parseFloat(data[1]), parseFloat(data[2]), parseFloat(data[3]));
352
+ break;
353
+ case 'vt':
354
+ state.uvs.push(parseFloat(data[1]), parseFloat(data[2]));
355
+ break;
356
+ default:
357
+ }
358
+ } else if (lineFirstChar === 'f') {
359
+ const lineData = line.substr(1).trim();
360
+ const vertexData = lineData.split(/\s+/);
361
+ const faceVertices = [];
362
+
363
+ // Parse the face vertex data into an easy to work with format
364
+
365
+ for (let j = 0, jl = vertexData.length; j < jl; j++) {
366
+ const vertex = vertexData[j];
367
+
368
+ if (vertex.length > 0) {
369
+ const vertexParts = vertex.split('/');
370
+ faceVertices.push(vertexParts);
371
+ }
372
+ }
373
+
374
+ // Draw an edge between the first vertex and all subsequent vertices to form an n-gon
375
+
376
+ const v1 = faceVertices[0];
377
+
378
+ for (let j = 1, jl = faceVertices.length - 1; j < jl; j++) {
379
+ const v2 = faceVertices[j];
380
+ const v3 = faceVertices[j + 1];
381
+
382
+ state.addFace(v1[0], v2[0], v3[0], v1[1], v2[1], v3[1], v1[2], v2[2], v3[2]);
383
+ }
384
+ } else if (lineFirstChar === 'l') {
385
+ const lineParts = line.substring(1).trim().split(' ');
386
+ let lineVertices;
387
+ const lineUVs = [];
388
+
389
+ if (line.indexOf('/') === -1) {
390
+ lineVertices = lineParts;
391
+ } else {
392
+ lineVertices = [];
393
+ for (let li = 0, llen = lineParts.length; li < llen; li++) {
394
+ const parts = lineParts[li].split('/');
395
+
396
+ if (parts[0] !== '') lineVertices.push(parts[0]);
397
+ if (parts[1] !== '') lineUVs.push(parts[1]);
398
+ }
399
+ }
400
+ state.addLineGeometry(lineVertices, lineUVs);
401
+ } else if (lineFirstChar === 'p') {
402
+ const lineData = line.substr(1).trim();
403
+ const pointData = lineData.split(' ');
404
+
405
+ state.addPointGeometry(pointData);
406
+ } else if ((result = OBJECT_RE.exec(line)) !== null) {
407
+ // o object_name
408
+ // or
409
+ // g group_name
410
+
411
+ // WORKAROUND: https://bugs.chromium.org/p/v8/issues/detail?id=2869
412
+ // var name = result[ 0 ].substr( 1 ).trim();
413
+ const name = (' ' + result[0].substr(1).trim()).substr(1); // eslint-disable-line
414
+
415
+ state.startObject(name);
416
+ } else if (MATERIAL_USE_RE.test(line)) {
417
+ // material
418
+
419
+ state.object.startMaterial(line.substring(7).trim(), state.materialLibraries);
420
+ } else if (MATERIAL_RE.test(line)) {
421
+ // mtl file
422
+
423
+ state.materialLibraries.push(line.substring(7).trim());
424
+ } else if (lineFirstChar === 's') {
425
+ result = line.split(' ');
426
+
427
+ // smooth shading
428
+
429
+ // @todo Handle files that have varying smooth values for a set of faces inside one geometry,
430
+ // but does not define a usemtl for each face set.
431
+ // This should be detected and a dummy material created (later MultiMaterial and geometry groups).
432
+ // This requires some care to not create extra material on each smooth value for "normal" obj files.
433
+ // where explicit usemtl defines geometry groups.
434
+ // Example asset: examples/models/obj/cerberus/Cerberus.obj
435
+
436
+ /*
437
+ * http://paulbourke.net/dataformats/obj/
438
+ * or
439
+ * http://www.cs.utah.edu/~boulos/cs3505/obj_spec.pdf
440
+ *
441
+ * From chapter "Grouping" Syntax explanation "s group_number":
442
+ * "group_number is the smoothing group number. To turn off smoothing groups, use a value of 0 or off.
443
+ * Polygonal elements use group numbers to put elements in different smoothing groups. For free-form
444
+ * surfaces, smoothing groups are either turned on or off; there is no difference between values greater
445
+ * than 0."
446
+ */
447
+ if (result.length > 1) {
448
+ const value = result[1].trim().toLowerCase();
449
+ state.object.smooth = value !== '0' && value !== 'off';
450
+ } else {
451
+ // ZBrush can produce "s" lines #11707
452
+ state.object.smooth = true;
453
+ }
454
+ const material = state.object.currentMaterial();
455
+ if (material) material.smooth = state.object.smooth;
456
+ } else {
457
+ // Handle null terminated files without exception
458
+ if (line === '\0') continue;
459
+
460
+ throw new Error(`Unexpected line: "${line}"`);
461
+ }
462
+ }
463
+
464
+ state.finalize();
465
+
466
+ const meshes = [];
467
+ const materials = [];
468
+
469
+ for (const object of state.objects) {
470
+ const {geometry} = object;
471
+
472
+ // Skip o/g line declarations that did not follow with any faces
473
+ if (geometry.vertices.length === 0) continue;
474
+
475
+ const mesh = {
476
+ header: {
477
+ vertexCount: geometry.vertices.length / 3
478
+ },
479
+ attributes: {}
480
+ };
481
+
482
+ switch (geometry.type) {
483
+ case 'Points':
484
+ mesh.mode = 0; // GL.POINTS
485
+ break;
486
+ case 'Line':
487
+ mesh.mode = 1; // GL.LINES
488
+ break;
489
+ default:
490
+ mesh.mode = 4; // GL.TRIANGLES
491
+ break;
492
+ }
493
+
494
+ mesh.attributes.POSITION = {value: new Float32Array(geometry.vertices), size: 3};
495
+
496
+ if (geometry.normals.length > 0) {
497
+ mesh.attributes.NORMAL = {value: new Float32Array(geometry.normals), size: 3};
498
+ }
499
+
500
+ if (geometry.colors.length > 0) {
501
+ mesh.attributes.COLOR_0 = {value: new Float32Array(geometry.colors), size: 3};
502
+ }
503
+
504
+ if (geometry.uvs.length > 0) {
505
+ mesh.attributes.TEXCOORD_0 = {value: new Float32Array(geometry.uvs), size: 2};
506
+ }
507
+
508
+ // Create materials
509
+ mesh.materials = [];
510
+ for (const sourceMaterial of object.materials) {
511
+ // TODO - support full spec
512
+ const _material = {
513
+ name: sourceMaterial.name,
514
+ flatShading: !sourceMaterial.smooth
515
+ };
516
+ mesh.materials.push(_material);
517
+ materials.push(_material);
518
+ }
519
+
520
+ mesh.name = object.name;
521
+ meshes.push(mesh);
522
+ }
523
+
524
+ return {meshes, materials};
525
+ }