@ohuoy/easymap 1.0.19 → 1.0.21

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