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,344 @@
1
+ var THREE = require('three');
2
+
3
+ import {
4
+ NoBlending,
5
+ NormalBlending,
6
+ AdditiveBlending,
7
+ SubtractiveBlending,
8
+ MultiplyBlending,
9
+ CustomBlending,
10
+
11
+ FaceColors,
12
+ VertexColors,
13
+
14
+ DoubleSide,
15
+ BackSide,
16
+
17
+ MirroredRepeatWrapping,
18
+ RepeatWrapping,
19
+ MathUtils,
20
+ MaterialLoader,
21
+ TextureLoader,
22
+ Color
23
+ } from 'three';
24
+
25
+ /**
26
+ * @author alteredq / http://alteredqualia.com/
27
+ */
28
+
29
+ function Loader() {}
30
+
31
+ Loader.Handlers = {
32
+
33
+ handlers: [],
34
+
35
+ add: function ( regex, loader ) {
36
+
37
+ this.handlers.push( regex, loader );
38
+
39
+ },
40
+
41
+ get: function ( file ) {
42
+
43
+ var handlers = this.handlers;
44
+
45
+ for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
46
+
47
+ var regex = handlers[ i ];
48
+ var loader = handlers[ i + 1 ];
49
+
50
+ if ( regex.test( file ) ) {
51
+
52
+ return loader;
53
+
54
+ }
55
+
56
+ }
57
+
58
+ return null;
59
+
60
+ }
61
+
62
+ };
63
+
64
+ Object.assign( Loader.prototype, {
65
+
66
+ crossOrigin: 'anonymous',
67
+
68
+ onLoadStart: function () {},
69
+
70
+ onLoadProgress: function () {},
71
+
72
+ onLoadComplete: function () {},
73
+
74
+ initMaterials: function ( materials, texturePath, crossOrigin ) {
75
+
76
+ var array = [];
77
+
78
+ for ( var i = 0; i < materials.length; ++ i ) {
79
+
80
+ array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
81
+
82
+ }
83
+
84
+ return array;
85
+
86
+ },
87
+
88
+ createMaterial: ( function () {
89
+
90
+ var BlendingMode = {
91
+ NoBlending: NoBlending,
92
+ NormalBlending: NormalBlending,
93
+ AdditiveBlending: AdditiveBlending,
94
+ SubtractiveBlending: SubtractiveBlending,
95
+ MultiplyBlending: MultiplyBlending,
96
+ CustomBlending: CustomBlending
97
+ };
98
+
99
+ var color = new Color();
100
+ var textureLoader = new TextureLoader();
101
+ var materialLoader = new MaterialLoader();
102
+
103
+ return function createMaterial( m, texturePath, crossOrigin ) {
104
+
105
+ // convert from old material format
106
+
107
+ var textures = {};
108
+
109
+ function loadTexture( path, repeat, offset, wrap, anisotropy ) {
110
+
111
+ var fullPath = texturePath + path;
112
+ var loader = Loader.Handlers.get( fullPath );
113
+
114
+ var texture;
115
+
116
+ if ( loader !== null ) {
117
+
118
+ texture = loader.load( fullPath );
119
+
120
+ } else {
121
+
122
+ textureLoader.setCrossOrigin( crossOrigin );
123
+ texture = textureLoader.load( fullPath );
124
+
125
+ }
126
+
127
+ if ( repeat !== undefined ) {
128
+
129
+ texture.repeat.fromArray( repeat );
130
+
131
+ if ( repeat[ 0 ] !== 1 ) texture.wrapS = RepeatWrapping;
132
+ if ( repeat[ 1 ] !== 1 ) texture.wrapT = RepeatWrapping;
133
+
134
+ }
135
+
136
+ if ( offset !== undefined ) {
137
+
138
+ texture.offset.fromArray( offset );
139
+
140
+ }
141
+
142
+ if ( wrap !== undefined ) {
143
+
144
+ if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = RepeatWrapping;
145
+ if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = MirroredRepeatWrapping;
146
+
147
+ if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = RepeatWrapping;
148
+ if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = MirroredRepeatWrapping;
149
+
150
+ }
151
+
152
+ if ( anisotropy !== undefined ) {
153
+
154
+ texture.anisotropy = anisotropy;
155
+
156
+ }
157
+
158
+ var uuid = MathUtils.generateUUID();
159
+
160
+ textures[ uuid ] = texture;
161
+
162
+ return uuid;
163
+
164
+ }
165
+
166
+ //
167
+
168
+ var json = {
169
+ uuid: MathUtils.generateUUID(),
170
+ type: 'MeshLambertMaterial'
171
+ };
172
+
173
+ for ( var name in m ) {
174
+
175
+ var value = m[ name ];
176
+
177
+ switch ( name ) {
178
+
179
+ case 'DbgColor':
180
+ case 'DbgIndex':
181
+ case 'opticalDensity':
182
+ case 'illumination':
183
+ break;
184
+ case 'DbgName':
185
+ json.name = value;
186
+ break;
187
+ case 'blending':
188
+ json.blending = BlendingMode[ value ];
189
+ break;
190
+ case 'colorAmbient':
191
+ case 'mapAmbient':
192
+ console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
193
+ break;
194
+ case 'colorDiffuse':
195
+ json.color = color.fromArray( value ).getHex();
196
+ break;
197
+ case 'colorSpecular':
198
+ json.specular = color.fromArray( value ).getHex();
199
+ break;
200
+ case 'colorEmissive':
201
+ json.emissive = color.fromArray( value ).getHex();
202
+ break;
203
+ case 'specularCoef':
204
+ json.shininess = value;
205
+ break;
206
+ case 'shading':
207
+ if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
208
+ if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
209
+ if ( value.toLowerCase() === 'standard' ) json.type = 'MeshStandardMaterial';
210
+ break;
211
+ case 'mapDiffuse':
212
+ json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
213
+ break;
214
+ case 'mapDiffuseRepeat':
215
+ case 'mapDiffuseOffset':
216
+ case 'mapDiffuseWrap':
217
+ case 'mapDiffuseAnisotropy':
218
+ break;
219
+ case 'mapEmissive':
220
+ json.emissiveMap = loadTexture( value, m.mapEmissiveRepeat, m.mapEmissiveOffset, m.mapEmissiveWrap, m.mapEmissiveAnisotropy );
221
+ break;
222
+ case 'mapEmissiveRepeat':
223
+ case 'mapEmissiveOffset':
224
+ case 'mapEmissiveWrap':
225
+ case 'mapEmissiveAnisotropy':
226
+ break;
227
+ case 'mapLight':
228
+ json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
229
+ break;
230
+ case 'mapLightRepeat':
231
+ case 'mapLightOffset':
232
+ case 'mapLightWrap':
233
+ case 'mapLightAnisotropy':
234
+ break;
235
+ case 'mapAO':
236
+ json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
237
+ break;
238
+ case 'mapAORepeat':
239
+ case 'mapAOOffset':
240
+ case 'mapAOWrap':
241
+ case 'mapAOAnisotropy':
242
+ break;
243
+ case 'mapBump':
244
+ json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
245
+ break;
246
+ case 'mapBumpScale':
247
+ json.bumpScale = value;
248
+ break;
249
+ case 'mapBumpRepeat':
250
+ case 'mapBumpOffset':
251
+ case 'mapBumpWrap':
252
+ case 'mapBumpAnisotropy':
253
+ break;
254
+ case 'mapNormal':
255
+ json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
256
+ break;
257
+ case 'mapNormalFactor':
258
+ json.normalScale = value;
259
+ break;
260
+ case 'mapNormalRepeat':
261
+ case 'mapNormalOffset':
262
+ case 'mapNormalWrap':
263
+ case 'mapNormalAnisotropy':
264
+ break;
265
+ case 'mapSpecular':
266
+ json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
267
+ break;
268
+ case 'mapSpecularRepeat':
269
+ case 'mapSpecularOffset':
270
+ case 'mapSpecularWrap':
271
+ case 'mapSpecularAnisotropy':
272
+ break;
273
+ case 'mapMetalness':
274
+ json.metalnessMap = loadTexture( value, m.mapMetalnessRepeat, m.mapMetalnessOffset, m.mapMetalnessWrap, m.mapMetalnessAnisotropy );
275
+ break;
276
+ case 'mapMetalnessRepeat':
277
+ case 'mapMetalnessOffset':
278
+ case 'mapMetalnessWrap':
279
+ case 'mapMetalnessAnisotropy':
280
+ break;
281
+ case 'mapRoughness':
282
+ json.roughnessMap = loadTexture( value, m.mapRoughnessRepeat, m.mapRoughnessOffset, m.mapRoughnessWrap, m.mapRoughnessAnisotropy );
283
+ break;
284
+ case 'mapRoughnessRepeat':
285
+ case 'mapRoughnessOffset':
286
+ case 'mapRoughnessWrap':
287
+ case 'mapRoughnessAnisotropy':
288
+ break;
289
+ case 'mapAlpha':
290
+ json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
291
+ break;
292
+ case 'mapAlphaRepeat':
293
+ case 'mapAlphaOffset':
294
+ case 'mapAlphaWrap':
295
+ case 'mapAlphaAnisotropy':
296
+ break;
297
+ case 'flipSided':
298
+ json.side = BackSide;
299
+ break;
300
+ case 'doubleSided':
301
+ json.side = DoubleSide;
302
+ break;
303
+ case 'transparency':
304
+ console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
305
+ json.opacity = value;
306
+ break;
307
+ case 'depthTest':
308
+ case 'depthWrite':
309
+ case 'colorWrite':
310
+ case 'opacity':
311
+ case 'reflectivity':
312
+ case 'transparent':
313
+ case 'visible':
314
+ case 'wireframe':
315
+ json[ name ] = value;
316
+ break;
317
+ case 'vertexColors':
318
+ if ( value === true ) json.vertexColors = VertexColors;
319
+ if ( value === 'face' ) json.vertexColors = FaceColors;
320
+ break;
321
+ default:
322
+ console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
323
+ break;
324
+
325
+ }
326
+
327
+ }
328
+
329
+ if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
330
+ if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
331
+
332
+ if ( json.opacity < 1 ) json.transparent = true;
333
+
334
+ materialLoader.setTextures( textures );
335
+
336
+ return materialLoader.parse( json );
337
+
338
+ };
339
+
340
+ } )()
341
+
342
+ } );
343
+
344
+ export { Loader };
@@ -0,0 +1,223 @@
1
+ import {
2
+ BufferGeometry,
3
+ Matrix4,
4
+ Object3D,
5
+ PointsMaterial,
6
+ Ray,
7
+ Sphere,
8
+ Vector3
9
+ } from 'three';
10
+
11
+
12
+ const _inverseMatrix = /*@__PURE__*/ new Matrix4();
13
+ const _ray = /*@__PURE__*/ new Ray();
14
+ const _sphere = /*@__PURE__*/ new Sphere();
15
+ const _position = /*@__PURE__*/ new Vector3();
16
+ const _morphA = /*@__PURE__*/ new Vector3();
17
+ const _tempA = /*@__PURE__*/ new Vector3();
18
+
19
+ class Points extends Object3D {
20
+
21
+ constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
22
+
23
+ super();
24
+
25
+ this.type = 'Points';
26
+
27
+ this.geometry = geometry;
28
+ this.material = material;
29
+
30
+ this.updateMorphTargets();
31
+
32
+ }
33
+
34
+ copy( source ) {
35
+
36
+ super.copy( source );
37
+
38
+ this.material = source.material;
39
+ this.geometry = source.geometry;
40
+
41
+ return this;
42
+
43
+ }
44
+
45
+ raycast( raycaster, intersects ) {
46
+
47
+ const geometry = this.geometry;
48
+ const matrixWorld = this.matrixWorld;
49
+ const threshold = raycaster.params.Points.threshold;
50
+ const drawRange = geometry.drawRange;
51
+
52
+ // Checking boundingSphere distance to ray
53
+
54
+ if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
55
+
56
+ _sphere.copy( geometry.boundingSphere );
57
+ _sphere.applyMatrix4( matrixWorld );
58
+ _sphere.radius += threshold;
59
+
60
+ if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
61
+
62
+ //
63
+
64
+ _inverseMatrix.copy( matrixWorld ).invert();
65
+ _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
66
+
67
+ const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
68
+ const localThresholdSq = localThreshold * localThreshold;
69
+
70
+ if ( geometry.isBufferGeometry ) {
71
+
72
+ const index = geometry.index;
73
+ const attributes = geometry.attributes;
74
+ const positionAttribute = attributes.position;
75
+ const morphPosition = geometry.morphAttributes.position;
76
+
77
+ if ( index !== null ) {
78
+
79
+ const start = Math.max( 0, drawRange.start );
80
+ const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
81
+
82
+ for ( let i = start, il = end; i < il; i ++ ) {
83
+
84
+ const a = index.getX( i );
85
+
86
+ calculatePosition( this, positionAttribute, morphPosition, a );
87
+
88
+ testPoint( _position, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
89
+
90
+ }
91
+
92
+ } else {
93
+
94
+ const start = Math.max( 0, drawRange.start );
95
+ const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
96
+
97
+ for ( let i = start, l = end; i < l; i ++ ) {
98
+
99
+ calculatePosition( this, positionAttribute, morphPosition, i );
100
+
101
+ testPoint( _position, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
102
+
103
+ }
104
+
105
+ }
106
+
107
+ } else {
108
+
109
+ console.error( 'THREE.Points.raycast() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
110
+
111
+ }
112
+
113
+ }
114
+
115
+ updateMorphTargets() {
116
+
117
+ const geometry = this.geometry;
118
+
119
+ if ( geometry.isBufferGeometry ) {
120
+
121
+ const morphAttributes = geometry.morphAttributes;
122
+ const keys = Object.keys( morphAttributes );
123
+
124
+ if ( keys.length > 0 ) {
125
+
126
+ const morphAttribute = morphAttributes[ keys[ 0 ] ];
127
+
128
+ if ( morphAttribute !== undefined ) {
129
+
130
+ this.morphTargetInfluences = [];
131
+ this.morphTargetDictionary = {};
132
+
133
+ for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
134
+
135
+ const name = morphAttribute[ m ].name || String( m );
136
+
137
+ this.morphTargetInfluences.push( 0 );
138
+ this.morphTargetDictionary[ name ] = m;
139
+
140
+ }
141
+
142
+ }
143
+
144
+ }
145
+
146
+ } else {
147
+
148
+ const morphTargets = geometry.morphTargets;
149
+
150
+ if ( morphTargets !== undefined && morphTargets.length > 0 ) {
151
+
152
+ console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
153
+
154
+ }
155
+
156
+ }
157
+
158
+ }
159
+
160
+ }
161
+
162
+ Points.prototype.isPoints = true;
163
+
164
+ function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
165
+
166
+ const rayPointDistanceSq = _ray.distanceSqToPoint( point );
167
+
168
+ if ( rayPointDistanceSq < localThresholdSq ) {
169
+
170
+ const intersectPoint = new Vector3();
171
+
172
+ _ray.closestPointToPoint( point, intersectPoint );
173
+ intersectPoint.applyMatrix4( matrixWorld );
174
+
175
+ const distance = raycaster.ray.origin.distanceTo( intersectPoint );
176
+
177
+ if ( distance < raycaster.near || distance > raycaster.far ) return;
178
+
179
+ intersects.push( {
180
+
181
+ distance: distance,
182
+ distanceToRay: Math.sqrt( rayPointDistanceSq ),
183
+ point: intersectPoint,
184
+ index: index,
185
+ face: null,
186
+ object: object
187
+
188
+ } );
189
+
190
+ }
191
+
192
+ }
193
+
194
+ function calculatePosition( object, position, morphPosition, a ) {
195
+
196
+ _position.fromBufferAttribute( position, a );
197
+
198
+ const morphInfluences = object.morphTargetInfluences;
199
+
200
+ if ( object.material.morphTargets && morphPosition && morphInfluences ) {
201
+
202
+ _morphA.set( 0, 0, 0 );
203
+
204
+ for ( var i = 0, il = morphPosition.length; i < il; i ++ ) {
205
+
206
+ const influence = morphInfluences[ i ];
207
+ const morphAttribute = morphPosition[ i ];
208
+
209
+ if ( influence === 0 ) continue;
210
+
211
+ _tempA.fromBufferAttribute( morphAttribute, a );
212
+
213
+ _morphA.addScaledVector( _tempA.sub( _position ), influence );
214
+
215
+ }
216
+
217
+ _position.add( _morphA );
218
+
219
+ }
220
+
221
+ }
222
+
223
+ export { Points };