zincjs 1.0.13 → 1.0.15

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 (45) hide show
  1. package/build/zinc.frontend.js +1 -1
  2. package/build/zinc.js +43 -35
  3. package/build/zinc.js.map +1 -1
  4. package/package.json +3 -3
  5. package/src/assets/disc.png +0 -0
  6. package/src/assets/mapMarker.svg +11 -0
  7. package/src/controls.js +1594 -0
  8. package/src/geometryCSG.js +148 -0
  9. package/src/glyphsetCSG.js +84 -0
  10. package/src/loaders/GLTFToZincJSLoader.js +85 -0
  11. package/src/loaders/JSONLoader.js +697 -0
  12. package/src/loaders/OBJLoader.js +911 -0
  13. package/src/loaders/STLLoader.js +399 -0
  14. package/src/loaders/primitivesLoader.js +46 -0
  15. package/src/minimap.js +82 -0
  16. package/src/primitives/augmentShader.js +22 -0
  17. package/src/primitives/geometry.js +109 -0
  18. package/src/primitives/glyph.js +150 -0
  19. package/src/primitives/glyphset.js +657 -0
  20. package/src/primitives/label.js +51 -0
  21. package/src/primitives/lines.js +35 -0
  22. package/src/primitives/marker.js +88 -0
  23. package/src/primitives/pointset.js +53 -0
  24. package/src/primitives/texturePrimitive.js +16 -0
  25. package/src/primitives/textureSlides.js +118 -0
  26. package/src/primitives/zincObject.js +573 -0
  27. package/src/region.js +554 -0
  28. package/src/renderer.js +612 -0
  29. package/src/scene.js +963 -0
  30. package/src/sceneExporter.js +32 -0
  31. package/src/sceneLoader.js +842 -0
  32. package/src/texture/texture.js +57 -0
  33. package/src/texture/textureArray.js +85 -0
  34. package/src/three/GLTFExporter.js +2448 -0
  35. package/src/three/Geometry.js +2084 -0
  36. package/src/three/Loader.js +344 -0
  37. package/src/three/Points.js +223 -0
  38. package/src/three/line/Line.js +293 -0
  39. package/src/three/line/LineSegments.js +65 -0
  40. package/src/three-js-csg.js +564 -0
  41. package/src/utilities.js +321 -0
  42. package/src/videoHandler.js +92 -0
  43. package/src/workers/geometryCSG.worker.js +73 -0
  44. package/src/workers/geometryCSGInternal.js +58 -0
  45. package/src/zinc.js +38 -0
@@ -0,0 +1,911 @@
1
+ import {
2
+ BufferGeometry,
3
+ FileLoader,
4
+ Float32BufferAttribute,
5
+ Group,
6
+ LineBasicMaterial,
7
+ LineSegments,
8
+ Loader,
9
+ Material,
10
+ Mesh,
11
+ MeshPhongMaterial,
12
+ Points,
13
+ PointsMaterial,
14
+ Vector3
15
+ } from 'three';
16
+
17
+ // o object_name | g group_name
18
+ const _object_pattern = /^[og]\s*(.+)?/;
19
+ // mtllib file_reference
20
+ const _material_library_pattern = /^mtllib /;
21
+ // usemtl material_name
22
+ const _material_use_pattern = /^usemtl /;
23
+ // usemap map_name
24
+ const _map_use_pattern = /^usemap /;
25
+
26
+ const _vA = new Vector3();
27
+ const _vB = new Vector3();
28
+ const _vC = new Vector3();
29
+
30
+ const _ab = new Vector3();
31
+ const _cb = new Vector3();
32
+
33
+ function ParserState() {
34
+
35
+ const state = {
36
+ objects: [],
37
+ object: {},
38
+
39
+ vertices: [],
40
+ normals: [],
41
+ colors: [],
42
+ uvs: [],
43
+
44
+ materials: {},
45
+ materialLibraries: [],
46
+
47
+ startObject: function ( name, fromDeclaration ) {
48
+
49
+ // If the current object (initial from reset) is not from a g/o declaration in the parsed
50
+ // file. We need to use it for the first parsed g/o to keep things in sync.
51
+ if ( this.object && this.object.fromDeclaration === false ) {
52
+
53
+ this.object.name = name;
54
+ this.object.fromDeclaration = ( fromDeclaration !== false );
55
+ return;
56
+
57
+ }
58
+
59
+ const previousMaterial = ( this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined );
60
+
61
+ if ( this.object && typeof this.object._finalize === 'function' ) {
62
+
63
+ this.object._finalize( true );
64
+
65
+ }
66
+
67
+ this.object = {
68
+ name: name || '',
69
+ fromDeclaration: ( fromDeclaration !== false ),
70
+
71
+ geometry: {
72
+ vertices: [],
73
+ normals: [],
74
+ colors: [],
75
+ uvs: [],
76
+ hasUVIndices: false
77
+ },
78
+ materials: [],
79
+ smooth: true,
80
+
81
+ startMaterial: function ( name, libraries ) {
82
+
83
+ const previous = this._finalize( false );
84
+
85
+ // New usemtl declaration overwrites an inherited material, except if faces were declared
86
+ // after the material, then it must be preserved for proper MultiMaterial continuation.
87
+ if ( previous && ( previous.inherited || previous.groupCount <= 0 ) ) {
88
+
89
+ this.materials.splice( previous.index, 1 );
90
+
91
+ }
92
+
93
+ const material = {
94
+ index: this.materials.length,
95
+ name: name || '',
96
+ mtllib: ( Array.isArray( libraries ) && libraries.length > 0 ? libraries[ libraries.length - 1 ] : '' ),
97
+ smooth: ( previous !== undefined ? previous.smooth : this.smooth ),
98
+ groupStart: ( previous !== undefined ? previous.groupEnd : 0 ),
99
+ groupEnd: - 1,
100
+ groupCount: - 1,
101
+ inherited: false,
102
+
103
+ clone: function ( index ) {
104
+
105
+ const cloned = {
106
+ index: ( typeof index === 'number' ? index : this.index ),
107
+ name: this.name,
108
+ mtllib: this.mtllib,
109
+ smooth: this.smooth,
110
+ groupStart: 0,
111
+ groupEnd: - 1,
112
+ groupCount: - 1,
113
+ inherited: false
114
+ };
115
+ cloned.clone = this.clone.bind( cloned );
116
+ return cloned;
117
+
118
+ }
119
+ };
120
+
121
+ this.materials.push( material );
122
+
123
+ return material;
124
+
125
+ },
126
+
127
+ currentMaterial: function () {
128
+
129
+ if ( this.materials.length > 0 ) {
130
+
131
+ return this.materials[ this.materials.length - 1 ];
132
+
133
+ }
134
+
135
+ return undefined;
136
+
137
+ },
138
+
139
+ _finalize: function ( end ) {
140
+
141
+ const lastMultiMaterial = this.currentMaterial();
142
+ if ( lastMultiMaterial && lastMultiMaterial.groupEnd === - 1 ) {
143
+
144
+ lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
145
+ lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
146
+ lastMultiMaterial.inherited = false;
147
+
148
+ }
149
+
150
+ // Ignore objects tail materials if no face declarations followed them before a new o/g started.
151
+ if ( end && this.materials.length > 1 ) {
152
+
153
+ for ( let mi = this.materials.length - 1; mi >= 0; mi -- ) {
154
+
155
+ if ( this.materials[ mi ].groupCount <= 0 ) {
156
+
157
+ this.materials.splice( mi, 1 );
158
+
159
+ }
160
+
161
+ }
162
+
163
+ }
164
+
165
+ // Guarantee at least one empty material, this makes the creation later more straight forward.
166
+ if ( end && this.materials.length === 0 ) {
167
+
168
+ this.materials.push( {
169
+ name: '',
170
+ smooth: this.smooth
171
+ } );
172
+
173
+ }
174
+
175
+ return lastMultiMaterial;
176
+
177
+ }
178
+ };
179
+
180
+ // Inherit previous objects material.
181
+ // Spec tells us that a declared material must be set to all objects until a new material is declared.
182
+ // If a usemtl declaration is encountered while this new object is being parsed, it will
183
+ // overwrite the inherited material. Exception being that there was already face declarations
184
+ // to the inherited material, then it will be preserved for proper MultiMaterial continuation.
185
+
186
+ if ( previousMaterial && previousMaterial.name && typeof previousMaterial.clone === 'function' ) {
187
+
188
+ const declared = previousMaterial.clone( 0 );
189
+ declared.inherited = true;
190
+ this.object.materials.push( declared );
191
+
192
+ }
193
+
194
+ this.objects.push( this.object );
195
+
196
+ },
197
+
198
+ finalize: function () {
199
+
200
+ if ( this.object && typeof this.object._finalize === 'function' ) {
201
+
202
+ this.object._finalize( true );
203
+
204
+ }
205
+
206
+ },
207
+
208
+ parseVertexIndex: function ( value, len ) {
209
+
210
+ const index = parseInt( value, 10 );
211
+ return ( index >= 0 ? index - 1 : index + len / 3 ) * 3;
212
+
213
+ },
214
+
215
+ parseNormalIndex: function ( value, len ) {
216
+
217
+ const index = parseInt( value, 10 );
218
+ return ( index >= 0 ? index - 1 : index + len / 3 ) * 3;
219
+
220
+ },
221
+
222
+ parseUVIndex: function ( value, len ) {
223
+
224
+ const index = parseInt( value, 10 );
225
+ return ( index >= 0 ? index - 1 : index + len / 2 ) * 2;
226
+
227
+ },
228
+
229
+ addVertex: function ( a, b, c ) {
230
+
231
+ const src = this.vertices;
232
+ const dst = this.object.geometry.vertices;
233
+
234
+ dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
235
+ dst.push( src[ b + 0 ], src[ b + 1 ], src[ b + 2 ] );
236
+ dst.push( src[ c + 0 ], src[ c + 1 ], src[ c + 2 ] );
237
+
238
+ },
239
+
240
+ addVertexPoint: function ( a ) {
241
+
242
+ const src = this.vertices;
243
+ const dst = this.object.geometry.vertices;
244
+
245
+ dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
246
+
247
+ },
248
+
249
+ addVertexLine: function ( a ) {
250
+
251
+ const src = this.vertices;
252
+ const dst = this.object.geometry.vertices;
253
+
254
+ dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
255
+
256
+ },
257
+
258
+ addNormal: function ( a, b, c ) {
259
+
260
+ const src = this.normals;
261
+ const dst = this.object.geometry.normals;
262
+
263
+ dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
264
+ dst.push( src[ b + 0 ], src[ b + 1 ], src[ b + 2 ] );
265
+ dst.push( src[ c + 0 ], src[ c + 1 ], src[ c + 2 ] );
266
+
267
+ },
268
+
269
+ addFaceNormal: function ( a, b, c ) {
270
+
271
+ const src = this.vertices;
272
+ const dst = this.object.geometry.normals;
273
+
274
+ _vA.fromArray( src, a );
275
+ _vB.fromArray( src, b );
276
+ _vC.fromArray( src, c );
277
+
278
+ _cb.subVectors( _vC, _vB );
279
+ _ab.subVectors( _vA, _vB );
280
+ _cb.cross( _ab );
281
+
282
+ _cb.normalize();
283
+
284
+ dst.push( _cb.x, _cb.y, _cb.z );
285
+ dst.push( _cb.x, _cb.y, _cb.z );
286
+ dst.push( _cb.x, _cb.y, _cb.z );
287
+
288
+ },
289
+
290
+ addColor: function ( a, b, c ) {
291
+
292
+ const src = this.colors;
293
+ const dst = this.object.geometry.colors;
294
+
295
+ if ( src[ a ] !== undefined ) dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
296
+ if ( src[ b ] !== undefined ) dst.push( src[ b + 0 ], src[ b + 1 ], src[ b + 2 ] );
297
+ if ( src[ c ] !== undefined ) dst.push( src[ c + 0 ], src[ c + 1 ], src[ c + 2 ] );
298
+
299
+ },
300
+
301
+ addUV: function ( a, b, c ) {
302
+
303
+ const src = this.uvs;
304
+ const dst = this.object.geometry.uvs;
305
+
306
+ dst.push( src[ a + 0 ], src[ a + 1 ] );
307
+ dst.push( src[ b + 0 ], src[ b + 1 ] );
308
+ dst.push( src[ c + 0 ], src[ c + 1 ] );
309
+
310
+ },
311
+
312
+ addDefaultUV: function () {
313
+
314
+ const dst = this.object.geometry.uvs;
315
+
316
+ dst.push( 0, 0 );
317
+ dst.push( 0, 0 );
318
+ dst.push( 0, 0 );
319
+
320
+ },
321
+
322
+ addUVLine: function ( a ) {
323
+
324
+ const src = this.uvs;
325
+ const dst = this.object.geometry.uvs;
326
+
327
+ dst.push( src[ a + 0 ], src[ a + 1 ] );
328
+
329
+ },
330
+
331
+ addFace: function ( a, b, c, ua, ub, uc, na, nb, nc ) {
332
+
333
+ const vLen = this.vertices.length;
334
+
335
+ let ia = this.parseVertexIndex( a, vLen );
336
+ let ib = this.parseVertexIndex( b, vLen );
337
+ let ic = this.parseVertexIndex( c, vLen );
338
+
339
+ this.addVertex( ia, ib, ic );
340
+ this.addColor( ia, ib, ic );
341
+
342
+ // normals
343
+
344
+ if ( na !== undefined && na !== '' ) {
345
+
346
+ const nLen = this.normals.length;
347
+
348
+ ia = this.parseNormalIndex( na, nLen );
349
+ ib = this.parseNormalIndex( nb, nLen );
350
+ ic = this.parseNormalIndex( nc, nLen );
351
+
352
+ this.addNormal( ia, ib, ic );
353
+
354
+ } else {
355
+
356
+ this.addFaceNormal( ia, ib, ic );
357
+
358
+ }
359
+
360
+ // uvs
361
+
362
+ if ( ua !== undefined && ua !== '' ) {
363
+
364
+ const uvLen = this.uvs.length;
365
+
366
+ ia = this.parseUVIndex( ua, uvLen );
367
+ ib = this.parseUVIndex( ub, uvLen );
368
+ ic = this.parseUVIndex( uc, uvLen );
369
+
370
+ this.addUV( ia, ib, ic );
371
+
372
+ this.object.geometry.hasUVIndices = true;
373
+
374
+ } else {
375
+
376
+ // add placeholder values (for inconsistent face definitions)
377
+
378
+ this.addDefaultUV();
379
+
380
+ }
381
+
382
+ },
383
+
384
+ addPointGeometry: function ( vertices ) {
385
+
386
+ this.object.geometry.type = 'Points';
387
+
388
+ const vLen = this.vertices.length;
389
+
390
+ for ( let vi = 0, l = vertices.length; vi < l; vi ++ ) {
391
+
392
+ const index = this.parseVertexIndex( vertices[ vi ], vLen );
393
+
394
+ this.addVertexPoint( index );
395
+ this.addColor( index );
396
+
397
+ }
398
+
399
+ },
400
+
401
+ addLineGeometry: function ( vertices, uvs ) {
402
+
403
+ this.object.geometry.type = 'Line';
404
+
405
+ const vLen = this.vertices.length;
406
+ const uvLen = this.uvs.length;
407
+
408
+ for ( let vi = 0, l = vertices.length; vi < l; vi ++ ) {
409
+
410
+ this.addVertexLine( this.parseVertexIndex( vertices[ vi ], vLen ) );
411
+
412
+ }
413
+
414
+ for ( let uvi = 0, l = uvs.length; uvi < l; uvi ++ ) {
415
+
416
+ this.addUVLine( this.parseUVIndex( uvs[ uvi ], uvLen ) );
417
+
418
+ }
419
+
420
+ }
421
+
422
+ };
423
+
424
+ state.startObject( '', false );
425
+
426
+ return state;
427
+
428
+ }
429
+
430
+ //
431
+
432
+ class OBJLoader extends Loader {
433
+
434
+ constructor( manager ) {
435
+
436
+ super( manager );
437
+
438
+ this.materials = null;
439
+
440
+ }
441
+
442
+ load( url, onLoad, onProgress, onError ) {
443
+
444
+ const scope = this;
445
+
446
+ const loader = new FileLoader( this.manager );
447
+ loader.setPath( this.path );
448
+ loader.setRequestHeader( this.requestHeader );
449
+ loader.setWithCredentials( this.withCredentials );
450
+ loader.load( url, function ( text ) {
451
+
452
+ try {
453
+
454
+ onLoad( scope.parse( text ) );
455
+
456
+ } catch ( e ) {
457
+
458
+ if ( onError ) {
459
+
460
+ onError( e );
461
+
462
+ } else {
463
+
464
+ console.error( e );
465
+
466
+ }
467
+
468
+ scope.manager.itemError( url );
469
+
470
+ }
471
+
472
+ }, onProgress, onError );
473
+
474
+ }
475
+
476
+ setMaterials( materials ) {
477
+
478
+ this.materials = materials;
479
+
480
+ return this;
481
+
482
+ }
483
+
484
+ parse( text ) {
485
+
486
+ const state = new ParserState();
487
+
488
+ if ( text.indexOf( '\r\n' ) !== - 1 ) {
489
+
490
+ // This is faster than String.split with regex that splits on both
491
+ text = text.replace( /\r\n/g, '\n' );
492
+
493
+ }
494
+
495
+ if ( text.indexOf( '\\\n' ) !== - 1 ) {
496
+
497
+ // join lines separated by a line continuation character (\)
498
+ text = text.replace( /\\\n/g, '' );
499
+
500
+ }
501
+
502
+ const lines = text.split( '\n' );
503
+ let line = '', lineFirstChar = '';
504
+ let lineLength = 0;
505
+ let result = [];
506
+
507
+ // Faster to just trim left side of the line. Use if available.
508
+ const trimLeft = ( typeof ''.trimLeft === 'function' );
509
+
510
+ for ( let i = 0, l = lines.length; i < l; i ++ ) {
511
+
512
+ line = lines[ i ];
513
+
514
+ line = trimLeft ? line.trimLeft() : line.trim();
515
+
516
+ lineLength = line.length;
517
+
518
+ if ( lineLength === 0 ) continue;
519
+
520
+ lineFirstChar = line.charAt( 0 );
521
+
522
+ // @todo invoke passed in handler if any
523
+ if ( lineFirstChar === '#' ) continue;
524
+
525
+ if ( lineFirstChar === 'v' ) {
526
+
527
+ const data = line.split( /\s+/ );
528
+
529
+ switch ( data[ 0 ] ) {
530
+
531
+ case 'v':
532
+ state.vertices.push(
533
+ parseFloat( data[ 1 ] ),
534
+ parseFloat( data[ 2 ] ),
535
+ parseFloat( data[ 3 ] )
536
+ );
537
+ if ( data.length >= 7 ) {
538
+
539
+ state.colors.push(
540
+ parseFloat( data[ 4 ] ),
541
+ parseFloat( data[ 5 ] ),
542
+ parseFloat( data[ 6 ] )
543
+
544
+ );
545
+
546
+ } else {
547
+
548
+ // if no colors are defined, add placeholders so color and vertex indices match
549
+
550
+ state.colors.push( undefined, undefined, undefined );
551
+
552
+ }
553
+
554
+ break;
555
+ case 'vn':
556
+ state.normals.push(
557
+ parseFloat( data[ 1 ] ),
558
+ parseFloat( data[ 2 ] ),
559
+ parseFloat( data[ 3 ] )
560
+ );
561
+ break;
562
+ case 'vt':
563
+ state.uvs.push(
564
+ parseFloat( data[ 1 ] ),
565
+ parseFloat( data[ 2 ] )
566
+ );
567
+ break;
568
+
569
+ }
570
+
571
+ } else if ( lineFirstChar === 'f' ) {
572
+
573
+ const lineData = line.substr( 1 ).trim();
574
+ const vertexData = lineData.split( /\s+/ );
575
+ const faceVertices = [];
576
+
577
+ // Parse the face vertex data into an easy to work with format
578
+
579
+ for ( let j = 0, jl = vertexData.length; j < jl; j ++ ) {
580
+
581
+ const vertex = vertexData[ j ];
582
+
583
+ if ( vertex.length > 0 ) {
584
+
585
+ const vertexParts = vertex.split( '/' );
586
+ faceVertices.push( vertexParts );
587
+
588
+ }
589
+
590
+ }
591
+
592
+ // Draw an edge between the first vertex and all subsequent vertices to form an n-gon
593
+
594
+ const v1 = faceVertices[ 0 ];
595
+
596
+ for ( let j = 1, jl = faceVertices.length - 1; j < jl; j ++ ) {
597
+
598
+ const v2 = faceVertices[ j ];
599
+ const v3 = faceVertices[ j + 1 ];
600
+
601
+ state.addFace(
602
+ v1[ 0 ], v2[ 0 ], v3[ 0 ],
603
+ v1[ 1 ], v2[ 1 ], v3[ 1 ],
604
+ v1[ 2 ], v2[ 2 ], v3[ 2 ]
605
+ );
606
+
607
+ }
608
+
609
+ } else if ( lineFirstChar === 'l' ) {
610
+
611
+ const lineParts = line.substring( 1 ).trim().split( ' ' );
612
+ let lineVertices = [];
613
+ const lineUVs = [];
614
+
615
+ if ( line.indexOf( '/' ) === - 1 ) {
616
+
617
+ lineVertices = lineParts;
618
+
619
+ } else {
620
+
621
+ for ( let li = 0, llen = lineParts.length; li < llen; li ++ ) {
622
+
623
+ const parts = lineParts[ li ].split( '/' );
624
+
625
+ if ( parts[ 0 ] !== '' ) lineVertices.push( parts[ 0 ] );
626
+ if ( parts[ 1 ] !== '' ) lineUVs.push( parts[ 1 ] );
627
+
628
+ }
629
+
630
+ }
631
+
632
+ state.addLineGeometry( lineVertices, lineUVs );
633
+
634
+ } else if ( lineFirstChar === 'p' ) {
635
+
636
+ const lineData = line.substr( 1 ).trim();
637
+ const pointData = lineData.split( ' ' );
638
+
639
+ state.addPointGeometry( pointData );
640
+
641
+ } else if ( ( result = _object_pattern.exec( line ) ) !== null ) {
642
+
643
+ // o object_name
644
+ // or
645
+ // g group_name
646
+
647
+ // WORKAROUND: https://bugs.chromium.org/p/v8/issues/detail?id=2869
648
+ // let name = result[ 0 ].substr( 1 ).trim();
649
+ const name = ( ' ' + result[ 0 ].substr( 1 ).trim() ).substr( 1 );
650
+
651
+ state.startObject( name );
652
+
653
+ } else if ( _material_use_pattern.test( line ) ) {
654
+
655
+ // material
656
+
657
+ state.object.startMaterial( line.substring( 7 ).trim(), state.materialLibraries );
658
+
659
+ } else if ( _material_library_pattern.test( line ) ) {
660
+
661
+ // mtl file
662
+
663
+ state.materialLibraries.push( line.substring( 7 ).trim() );
664
+
665
+ } else if ( _map_use_pattern.test( line ) ) {
666
+
667
+ // the line is parsed but ignored since the loader assumes textures are defined MTL files
668
+ // (according to https://www.okino.com/conv/imp_wave.htm, 'usemap' is the old-style Wavefront texture reference method)
669
+
670
+ console.warn( 'THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.' );
671
+
672
+ } else if ( lineFirstChar === 's' ) {
673
+
674
+ result = line.split( ' ' );
675
+
676
+ // smooth shading
677
+
678
+ // @todo Handle files that have varying smooth values for a set of faces inside one geometry,
679
+ // but does not define a usemtl for each face set.
680
+ // This should be detected and a dummy material created (later MultiMaterial and geometry groups).
681
+ // This requires some care to not create extra material on each smooth value for "normal" obj files.
682
+ // where explicit usemtl defines geometry groups.
683
+ // Example asset: examples/models/obj/cerberus/Cerberus.obj
684
+
685
+ /*
686
+ * http://paulbourke.net/dataformats/obj/
687
+ * or
688
+ * http://www.cs.utah.edu/~boulos/cs3505/obj_spec.pdf
689
+ *
690
+ * From chapter "Grouping" Syntax explanation "s group_number":
691
+ * "group_number is the smoothing group number. To turn off smoothing groups, use a value of 0 or off.
692
+ * Polygonal elements use group numbers to put elements in different smoothing groups. For free-form
693
+ * surfaces, smoothing groups are either turned on or off; there is no difference between values greater
694
+ * than 0."
695
+ */
696
+ if ( result.length > 1 ) {
697
+
698
+ const value = result[ 1 ].trim().toLowerCase();
699
+ state.object.smooth = ( value !== '0' && value !== 'off' );
700
+
701
+ } else {
702
+
703
+ // ZBrush can produce "s" lines #11707
704
+ state.object.smooth = true;
705
+
706
+ }
707
+
708
+ const material = state.object.currentMaterial();
709
+ if ( material ) material.smooth = state.object.smooth;
710
+
711
+ } else {
712
+
713
+ // Handle null terminated files without exception
714
+ if ( line === '\0' ) continue;
715
+
716
+ console.warn( 'THREE.OBJLoader: Unexpected line: "' + line + '"' );
717
+
718
+ }
719
+
720
+ }
721
+
722
+ state.finalize();
723
+
724
+ const container = new Group();
725
+ container.materialLibraries = [].concat( state.materialLibraries );
726
+
727
+ const hasPrimitives = ! ( state.objects.length === 1 && state.objects[ 0 ].geometry.vertices.length === 0 );
728
+
729
+ if ( hasPrimitives === true ) {
730
+
731
+ for ( let i = 0, l = state.objects.length; i < l; i ++ ) {
732
+
733
+ const object = state.objects[ i ];
734
+ const geometry = object.geometry;
735
+ const materials = object.materials;
736
+ const isLine = ( geometry.type === 'Line' );
737
+ const isPoints = ( geometry.type === 'Points' );
738
+ let hasVertexColors = false;
739
+
740
+ // Skip o/g line declarations that did not follow with any faces
741
+ if ( geometry.vertices.length === 0 ) continue;
742
+
743
+ const buffergeometry = new BufferGeometry();
744
+
745
+ buffergeometry.setAttribute( 'position', new Float32BufferAttribute( geometry.vertices, 3 ) );
746
+
747
+ if ( geometry.normals.length > 0 ) {
748
+
749
+ buffergeometry.setAttribute( 'normal', new Float32BufferAttribute( geometry.normals, 3 ) );
750
+
751
+ }
752
+
753
+ if ( geometry.colors.length > 0 ) {
754
+
755
+ hasVertexColors = true;
756
+ buffergeometry.setAttribute( 'color', new Float32BufferAttribute( geometry.colors, 3 ) );
757
+
758
+ }
759
+
760
+ if ( geometry.hasUVIndices === true ) {
761
+
762
+ buffergeometry.setAttribute( 'uv', new Float32BufferAttribute( geometry.uvs, 2 ) );
763
+
764
+ }
765
+
766
+ // Create materials
767
+
768
+ const createdMaterials = [];
769
+
770
+ for ( let mi = 0, miLen = materials.length; mi < miLen; mi ++ ) {
771
+
772
+ const sourceMaterial = materials[ mi ];
773
+ const materialHash = sourceMaterial.name + '_' + sourceMaterial.smooth + '_' + hasVertexColors;
774
+ let material = state.materials[ materialHash ];
775
+
776
+ if ( this.materials !== null ) {
777
+
778
+ material = this.materials.create( sourceMaterial.name );
779
+
780
+ // mtl etc. loaders probably can't create line materials correctly, copy properties to a line material.
781
+ if ( isLine && material && ! ( material instanceof LineBasicMaterial ) ) {
782
+
783
+ const materialLine = new LineBasicMaterial();
784
+ Material.prototype.copy.call( materialLine, material );
785
+ materialLine.color.copy( material.color );
786
+ material = materialLine;
787
+
788
+ } else if ( isPoints && material && ! ( material instanceof PointsMaterial ) ) {
789
+
790
+ const materialPoints = new PointsMaterial( { size: 10, sizeAttenuation: false } );
791
+ Material.prototype.copy.call( materialPoints, material );
792
+ materialPoints.color.copy( material.color );
793
+ materialPoints.map = material.map;
794
+ material = materialPoints;
795
+
796
+ }
797
+
798
+ }
799
+
800
+ if ( material === undefined ) {
801
+
802
+ if ( isLine ) {
803
+
804
+ material = new LineBasicMaterial();
805
+
806
+ } else if ( isPoints ) {
807
+
808
+ material = new PointsMaterial( { size: 1, sizeAttenuation: false } );
809
+
810
+ } else {
811
+
812
+ material = new MeshPhongMaterial();
813
+
814
+ }
815
+
816
+ material.name = sourceMaterial.name;
817
+ material.flatShading = sourceMaterial.smooth ? false : true;
818
+ material.vertexColors = hasVertexColors;
819
+
820
+ state.materials[ materialHash ] = material;
821
+
822
+ }
823
+
824
+ createdMaterials.push( material );
825
+
826
+ }
827
+
828
+ // Create mesh
829
+
830
+ let mesh;
831
+
832
+ if ( createdMaterials.length > 1 ) {
833
+
834
+ for ( let mi = 0, miLen = materials.length; mi < miLen; mi ++ ) {
835
+
836
+ const sourceMaterial = materials[ mi ];
837
+ buffergeometry.addGroup( sourceMaterial.groupStart, sourceMaterial.groupCount, mi );
838
+
839
+ }
840
+
841
+ if ( isLine ) {
842
+
843
+ mesh = new LineSegments( buffergeometry, createdMaterials );
844
+
845
+ } else if ( isPoints ) {
846
+
847
+ mesh = new Points( buffergeometry, createdMaterials );
848
+
849
+ } else {
850
+
851
+ mesh = new Mesh( buffergeometry, createdMaterials );
852
+
853
+ }
854
+
855
+ } else {
856
+
857
+ if ( isLine ) {
858
+
859
+ mesh = new LineSegments( buffergeometry, createdMaterials[ 0 ] );
860
+
861
+ } else if ( isPoints ) {
862
+
863
+ mesh = new Points( buffergeometry, createdMaterials[ 0 ] );
864
+
865
+ } else {
866
+
867
+ mesh = new Mesh( buffergeometry, createdMaterials[ 0 ] );
868
+
869
+ }
870
+
871
+ }
872
+
873
+ mesh.name = object.name;
874
+
875
+ container.add( mesh );
876
+
877
+ }
878
+
879
+ } else {
880
+
881
+ // if there is only the default parser state object with no geometry data, interpret data as point cloud
882
+
883
+ if ( state.vertices.length > 0 ) {
884
+
885
+ const material = new PointsMaterial( { size: 1, sizeAttenuation: false } );
886
+
887
+ const buffergeometry = new BufferGeometry();
888
+
889
+ buffergeometry.setAttribute( 'position', new Float32BufferAttribute( state.vertices, 3 ) );
890
+
891
+ if ( state.colors.length > 0 && state.colors[ 0 ] !== undefined ) {
892
+
893
+ buffergeometry.setAttribute( 'color', new Float32BufferAttribute( state.colors, 3 ) );
894
+ material.vertexColors = true;
895
+
896
+ }
897
+
898
+ const points = new Points( buffergeometry, material );
899
+ container.add( points );
900
+
901
+ }
902
+
903
+ }
904
+
905
+ return container;
906
+
907
+ }
908
+
909
+ }
910
+
911
+ export { OBJLoader };