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,697 @@
1
+ var THREE = require('three');
2
+
3
+ var Loader = require('../three/Loader').Loader;
4
+ var LoaderUtils = THREE.LoaderUtils;
5
+ var AnimationClip = THREE.AnimationClip;
6
+ var Vector3 = THREE.Vector3;
7
+ var Vector4 = THREE.Vector4;
8
+ var Color = THREE.Color;
9
+ var Vector2 = THREE.Vector2;
10
+ var Face3 = require('../three/Geometry').Face3;
11
+ var Geometry = require('../three/Geometry').Geometry;
12
+ var FileLoader = THREE.FileLoader;
13
+ var DefaultLoadingManager = THREE.DefaultLoadingManager;
14
+ var VideoHandler = require('../videoHandler').VideoHandler;
15
+
16
+ /**
17
+ * @author mrdoob / http://mrdoob.com/
18
+ * @author alteredq / http://alteredqualia.com/
19
+ */
20
+
21
+ function JSONLoader( manager ) {
22
+
23
+ if ( typeof manager === 'boolean' ) {
24
+
25
+ console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
26
+ manager = undefined;
27
+
28
+ }
29
+
30
+ this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
31
+
32
+ this.withCredentials = false;
33
+
34
+ this.paramsString = "";
35
+
36
+ }
37
+
38
+ Object.assign( JSONLoader.prototype, {
39
+
40
+ load: function ( url, onLoad, onProgress, onError ) {
41
+
42
+ var scope = this;
43
+
44
+ var texturePath = this.texturePath && ( typeof this.texturePath === 'string' ) ? this.texturePath : LoaderUtils.extractUrlBase( url );
45
+
46
+ var loader = new FileLoader( this.manager );
47
+
48
+ const params = url.split("?");
49
+
50
+ //There are parameters, add them to the target
51
+ if (url.length === 2) {
52
+
53
+ this.paramsString = paramsStrings[1];
54
+
55
+ } else {
56
+
57
+ this.paramsString = "";
58
+
59
+ }
60
+
61
+ loader.setWithCredentials( this.withCredentials );
62
+ loader.load( url, function ( text ) {
63
+
64
+ var json = JSON.parse( text );
65
+ var metadata = json.metadata;
66
+
67
+ if ( metadata !== undefined ) {
68
+
69
+ var type = metadata.type;
70
+
71
+ if ( type !== undefined ) {
72
+
73
+ if ( type.toLowerCase() === 'object' ) {
74
+
75
+ console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
76
+ return;
77
+
78
+ }
79
+
80
+ }
81
+
82
+ }
83
+
84
+ if (scope && scope.parse) {
85
+ var object = scope.parse( json, texturePath );
86
+ onLoad( object.geometry, object.materials );
87
+ }
88
+
89
+ }, onProgress, onError );
90
+
91
+ },
92
+
93
+ setTexturePath: function ( value ) {
94
+
95
+ this.texturePath = value;
96
+
97
+ },
98
+
99
+ parse: ( function () {
100
+
101
+ function parseModel( json, geometry ) {
102
+
103
+ function isBitSet( value, position ) {
104
+
105
+ return value & ( 1 << position );
106
+
107
+ }
108
+
109
+ var i, j, fi,
110
+
111
+ offset, zLength,
112
+
113
+ colorIndex, normalIndex, uvIndex, materialIndex,
114
+
115
+ type,
116
+ isQuad,
117
+ hasMaterial,
118
+ hasFaceVertexUv,
119
+ hasFaceNormal, hasFaceVertexNormal,
120
+ hasFaceColor, hasFaceVertexColor,
121
+
122
+ vertex, face, faceA, faceB, hex, normal,
123
+
124
+ uvLayer, uv, u, v,
125
+
126
+ faces = json.faces,
127
+ vertices = json.vertices,
128
+ normals = json.normals,
129
+ colors = json.colors,
130
+
131
+ scale = json.scale,
132
+
133
+ nUvLayers = 0;
134
+
135
+
136
+ if ( json.uvs !== undefined ) {
137
+
138
+ // disregard empty arrays
139
+
140
+ for ( i = 0; i < json.uvs.length; i ++ ) {
141
+
142
+ if ( json.uvs[ i ].length ) nUvLayers ++;
143
+
144
+ }
145
+
146
+ for ( i = 0; i < nUvLayers; i ++ ) {
147
+
148
+ geometry.faceVertexUvs[ i ] = [];
149
+
150
+ }
151
+
152
+ }
153
+
154
+ offset = 0;
155
+ zLength = vertices.length;
156
+
157
+ while ( offset < zLength ) {
158
+
159
+ vertex = new Vector3();
160
+
161
+ vertex.x = vertices[ offset ++ ] * scale;
162
+ vertex.y = vertices[ offset ++ ] * scale;
163
+ vertex.z = vertices[ offset ++ ] * scale;
164
+
165
+ geometry.vertices.push( vertex );
166
+
167
+ }
168
+
169
+ offset = 0;
170
+ zLength = faces.length;
171
+
172
+ if (json.uvs) {
173
+
174
+ for ( i = 0; i < json.uvs.length; i ++ ) {
175
+
176
+ geometry.uvs[i] = [];
177
+
178
+ for ( let k = 0; k < json.uvs[i].length ; k++ ) {
179
+
180
+ geometry.uvs[i][k] = json.uvs[i][k];
181
+
182
+ }
183
+
184
+ }
185
+
186
+ }
187
+
188
+ if (normals) {
189
+
190
+ for ( i = 0; i < normals.length; i ++ ) {
191
+
192
+ geometry.normals[i] = normals[i];
193
+
194
+ }
195
+
196
+ }
197
+
198
+ if (colors) {
199
+
200
+ for ( i = 0; i < colors.length; i ++ ) {
201
+
202
+ geometry.colors[i] = colors[i];
203
+
204
+ }
205
+
206
+ }
207
+
208
+
209
+ while ( offset < zLength ) {
210
+
211
+ type = faces[ offset ++ ];
212
+
213
+ isQuad = isBitSet( type, 0 );
214
+ hasMaterial = isBitSet( type, 1 );
215
+ hasFaceVertexUv = isBitSet( type, 3 );
216
+ hasFaceNormal = isBitSet( type, 4 );
217
+ hasFaceVertexNormal = isBitSet( type, 5 );
218
+ hasFaceColor = isBitSet( type, 6 );
219
+ hasFaceVertexColor = isBitSet( type, 7 );
220
+
221
+ // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
222
+
223
+ if ( isQuad ) {
224
+
225
+ faceA = new Face3();
226
+ faceA.a = faces[ offset ];
227
+ faceA.b = faces[ offset + 1 ];
228
+ faceA.c = faces[ offset + 3 ];
229
+
230
+ faceB = new Face3();
231
+ faceB.a = faces[ offset + 1 ];
232
+ faceB.b = faces[ offset + 2 ];
233
+ faceB.c = faces[ offset + 3 ];
234
+
235
+ offset += 4;
236
+
237
+ if ( hasMaterial ) {
238
+
239
+ materialIndex = faces[ offset ++ ];
240
+ faceA.materialIndex = materialIndex;
241
+ faceB.materialIndex = materialIndex;
242
+
243
+ }
244
+
245
+ // to get face <=> uv index correspondence
246
+
247
+ fi = geometry.faces.length;
248
+
249
+ if ( hasFaceVertexUv ) {
250
+
251
+ for ( i = 0; i < nUvLayers; i ++ ) {
252
+
253
+ uvLayer = json.uvs[ i ];
254
+
255
+ geometry.faceVertexUvs[ i ][ fi ] = [];
256
+ geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
257
+
258
+ for ( j = 0; j < 4; j ++ ) {
259
+
260
+ uvIndex = faces[ offset ++ ];
261
+
262
+ u = uvLayer[ uvIndex * 2 ];
263
+ v = uvLayer[ uvIndex * 2 + 1 ];
264
+
265
+ uv = new Vector2( u, v );
266
+
267
+ if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
268
+ if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
269
+
270
+ }
271
+
272
+ }
273
+
274
+ }
275
+
276
+ if ( hasFaceNormal ) {
277
+
278
+ normalIndex = faces[ offset ++ ] * 3;
279
+
280
+ faceA.normal.set(
281
+ normals[ normalIndex ++ ],
282
+ normals[ normalIndex ++ ],
283
+ normals[ normalIndex ]
284
+ );
285
+
286
+ faceB.normal.copy( faceA.normal );
287
+
288
+ }
289
+
290
+ if ( hasFaceVertexNormal ) {
291
+
292
+ for ( i = 0; i < 4; i ++ ) {
293
+
294
+ normalIndex = faces[ offset ++ ] * 3;
295
+
296
+ normal = new Vector3(
297
+ normals[ normalIndex ++ ],
298
+ normals[ normalIndex ++ ],
299
+ normals[ normalIndex ]
300
+ );
301
+
302
+
303
+ if ( i !== 2 ) faceA.vertexNormals.push( normal );
304
+ if ( i !== 0 ) faceB.vertexNormals.push( normal );
305
+
306
+ }
307
+
308
+ }
309
+
310
+
311
+ if ( hasFaceColor ) {
312
+
313
+ colorIndex = faces[ offset ++ ];
314
+ hex = colors[ colorIndex ];
315
+
316
+ faceA.color.setHex( hex );
317
+ faceB.color.setHex( hex );
318
+
319
+ }
320
+
321
+
322
+ if ( hasFaceVertexColor ) {
323
+
324
+ for ( i = 0; i < 4; i ++ ) {
325
+
326
+ colorIndex = faces[ offset ++ ];
327
+ hex = colors[ colorIndex ];
328
+
329
+ if ( i !== 2 ) faceA.vertexColors.push( new Color( hex ) );
330
+ if ( i !== 0 ) faceB.vertexColors.push( new Color( hex ) );
331
+
332
+ }
333
+
334
+ }
335
+
336
+ geometry.faces.push( faceA );
337
+ geometry.faces.push( faceB );
338
+
339
+ } else {
340
+
341
+ face = new Face3();
342
+ face.a = faces[ offset ++ ];
343
+ face.b = faces[ offset ++ ];
344
+ face.c = faces[ offset ++ ];
345
+
346
+ if ( hasMaterial ) {
347
+
348
+ materialIndex = faces[ offset ++ ];
349
+ face.materialIndex = materialIndex;
350
+
351
+ }
352
+
353
+ // to get face <=> uv index correspondence
354
+
355
+ fi = geometry.faces.length;
356
+
357
+ if ( hasFaceVertexUv ) {
358
+
359
+ for ( i = 0; i < nUvLayers; i ++ ) {
360
+
361
+ uvLayer = json.uvs[ i ];
362
+
363
+ geometry.faceVertexUvs[ i ][ fi ] = [];
364
+
365
+ for ( j = 0; j < 3; j ++ ) {
366
+
367
+ uvIndex = faces[ offset ++ ];
368
+
369
+ u = uvLayer[ uvIndex * 2 ];
370
+ v = uvLayer[ uvIndex * 2 + 1 ];
371
+
372
+ uv = new Vector2( u, v );
373
+
374
+ geometry.faceVertexUvs[ i ][ fi ].push( uv );
375
+
376
+ }
377
+
378
+ }
379
+
380
+ }
381
+
382
+ if ( hasFaceNormal ) {
383
+
384
+ normalIndex = faces[ offset ++ ] * 3;
385
+
386
+ face.normal.set(
387
+ normals[ normalIndex ++ ],
388
+ normals[ normalIndex ++ ],
389
+ normals[ normalIndex ]
390
+ );
391
+
392
+ }
393
+
394
+ if ( hasFaceVertexNormal ) {
395
+
396
+ for ( i = 0; i < 3; i ++ ) {
397
+
398
+ normalIndex = faces[ offset ++ ] * 3;
399
+
400
+ normal = new Vector3(
401
+ normals[ normalIndex ++ ],
402
+ normals[ normalIndex ++ ],
403
+ normals[ normalIndex ]
404
+ );
405
+
406
+ face.vertexNormals.push( normal );
407
+
408
+ }
409
+
410
+ }
411
+
412
+
413
+ if ( hasFaceColor ) {
414
+
415
+ colorIndex = faces[ offset ++ ];
416
+ face.color.setHex( colors[ colorIndex ] );
417
+
418
+ }
419
+
420
+
421
+ if ( hasFaceVertexColor ) {
422
+
423
+ for ( i = 0; i < 3; i ++ ) {
424
+
425
+ colorIndex = faces[ offset ++ ];
426
+ face.vertexColors.push( new Color( colors[ colorIndex ] ) );
427
+
428
+ }
429
+
430
+ }
431
+
432
+ geometry.faces.push( face );
433
+
434
+ }
435
+
436
+ }
437
+
438
+ }
439
+
440
+ function parseSkin( json, geometry ) {
441
+
442
+ var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
443
+
444
+ if ( json.skinWeights ) {
445
+
446
+ for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
447
+
448
+ var x = json.skinWeights[ i ];
449
+ var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
450
+ var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
451
+ var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
452
+
453
+ geometry.skinWeights.push( new Vector4( x, y, z, w ) );
454
+
455
+ }
456
+
457
+ }
458
+
459
+ if ( json.skinIndices ) {
460
+
461
+ for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
462
+
463
+ var a = json.skinIndices[ i ];
464
+ var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
465
+ var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
466
+ var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
467
+
468
+ geometry.skinIndices.push( new Vector4( a, b, c, d ) );
469
+
470
+ }
471
+
472
+ }
473
+
474
+ geometry.bones = json.bones;
475
+
476
+ if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
477
+
478
+ console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
479
+ geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
480
+
481
+ }
482
+
483
+ }
484
+
485
+ function parseMorphing( json, geometry ) {
486
+
487
+ var scale = json.scale;
488
+
489
+ if ( json.morphTargets !== undefined ) {
490
+
491
+ for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
492
+
493
+ geometry.morphTargets[ i ] = {};
494
+ geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
495
+ geometry.morphTargets[ i ].vertices = [];
496
+
497
+ var dstVertices = geometry.morphTargets[ i ].vertices;
498
+ var srcVertices = json.morphTargets[ i ].vertices;
499
+
500
+ for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
501
+
502
+ var vertex = new Vector3();
503
+ vertex.x = srcVertices[ v ] * scale;
504
+ vertex.y = srcVertices[ v + 1 ] * scale;
505
+ vertex.z = srcVertices[ v + 2 ] * scale;
506
+
507
+ dstVertices.push( vertex );
508
+
509
+ }
510
+
511
+ }
512
+
513
+ }
514
+
515
+ if ( json.morphNormals !== undefined ) {
516
+
517
+ for ( var i = 0, l = json.morphNormals.length; i < l; i ++ ) {
518
+
519
+ if (geometry.morphTargets[ i ]) {
520
+
521
+ geometry.morphTargets[ i ].normals = [];
522
+
523
+ var dstNormals = geometry.morphTargets[ i ].normals;
524
+ var srcNormals = json.morphNormals[ i ].normals;
525
+
526
+ for ( var v = 0, vl = srcNormals.length; v < vl; v += 3 ) {
527
+
528
+ var normals = new Vector3();
529
+ normals.x = srcNormals[ v ];
530
+ normals.y = srcNormals[ v + 1 ] ;
531
+ normals.z = srcNormals[ v + 2 ] ;
532
+
533
+ dstNormals.push( normals );
534
+
535
+ }
536
+
537
+ geometry.morphNormalsReady = true;
538
+
539
+ }
540
+
541
+ }
542
+
543
+ }
544
+
545
+ if ( json.morphColors !== undefined ) {
546
+
547
+ var i, l, c, cl, dstColors, srcColors, color;
548
+
549
+ for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
550
+
551
+ geometry.morphColors[ i ] = {};
552
+ geometry.morphColors[ i ].name = json.morphColors[ i ].name;
553
+ geometry.morphColors[ i ].colors = [];
554
+
555
+ dstColors = geometry.morphColors[ i ].colors;
556
+ srcColors = json.morphColors[ i ].colors;
557
+
558
+ for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
559
+
560
+ color = new THREE.Color( 0xffaa00 );
561
+ color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
562
+ dstColors.push( color );
563
+
564
+ }
565
+
566
+ }
567
+
568
+ }
569
+
570
+ }
571
+
572
+ function parseAnimations( json, geometry ) {
573
+
574
+ var outputAnimations = [];
575
+
576
+ // parse old style Bone/Hierarchy animations
577
+ var animations = [];
578
+
579
+ if ( json.animation !== undefined ) {
580
+
581
+ animations.push( json.animation );
582
+
583
+ }
584
+
585
+ if ( json.animations !== undefined ) {
586
+
587
+ if ( json.animations.length ) {
588
+
589
+ animations = animations.concat( json.animations );
590
+
591
+ } else {
592
+
593
+ animations.push( json.animations );
594
+
595
+ }
596
+
597
+ }
598
+
599
+ for ( var i = 0; i < animations.length; i ++ ) {
600
+
601
+ var clip = AnimationClip.parseAnimation( animations[ i ], geometry.bones );
602
+ if ( clip ) outputAnimations.push( clip );
603
+
604
+ }
605
+
606
+ // parse implicit morph animations
607
+ if ( geometry.morphTargets ) {
608
+
609
+ // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
610
+ var morphAnimationClips = AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
611
+ outputAnimations = outputAnimations.concat( morphAnimationClips );
612
+
613
+ }
614
+
615
+ if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
616
+
617
+ }
618
+
619
+ return function parse( json, texturePath ) {
620
+
621
+ if ( json.data !== undefined ) {
622
+
623
+ // Geometry 4.0 spec
624
+ json = json.data;
625
+
626
+ }
627
+
628
+ if ( json.scale !== undefined ) {
629
+
630
+ json.scale = 1.0 / json.scale;
631
+
632
+ } else {
633
+
634
+ json.scale = 1.0;
635
+
636
+ }
637
+
638
+ var geometry = new Geometry();
639
+ geometry.morphColors = [];
640
+ parseModel( json, geometry );
641
+ parseSkin( json, geometry );
642
+ parseMorphing( json, geometry );
643
+ parseAnimations( json, geometry );
644
+
645
+ geometry.computeFaceNormals();
646
+ geometry.computeBoundingSphere();
647
+
648
+ if ( json.materials === undefined || json.materials.length === 0 ) {
649
+
650
+ return { geometry: geometry };
651
+
652
+ } else {
653
+
654
+ var materials = Loader.prototype.initMaterials( json.materials, texturePath, 'Anonymous' );
655
+
656
+
657
+ if (json.materials[0].video) {
658
+
659
+ var fullPath = texturePath + json.materials[0].video;
660
+
661
+ if (this.paramsString) {
662
+
663
+ fullPath = fullPath + `?${this.paramsString}`;
664
+
665
+ }
666
+
667
+ const videoHandler = new VideoHandler(fullPath);
668
+
669
+ geometry._video = videoHandler;
670
+
671
+ }
672
+
673
+ if (materials && materials.length > 0) {
674
+ if (json.materials[0].singleSided) {
675
+ materials[0].side = THREE.FrontSide;
676
+ } else if (json.materials[0].flipSided){
677
+ materials[0].side = THREE.BackSide;
678
+ } else {
679
+ materials[0].side = THREE.DoubleSide;
680
+ }
681
+ if (json.materials[0].specularCoef) {
682
+ materials[0].shininess = Math.floor(json.materials[0].specularCoef / 3);
683
+ }
684
+ }
685
+
686
+ return { geometry: geometry, materials: materials };
687
+
688
+ }
689
+
690
+ };
691
+
692
+ } )()
693
+
694
+ } );
695
+
696
+
697
+ export { JSONLoader };