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,399 @@
1
+ import {
2
+ BufferAttribute,
3
+ BufferGeometry,
4
+ FileLoader,
5
+ Float32BufferAttribute,
6
+ Loader,
7
+ LoaderUtils,
8
+ Vector3
9
+ } from 'three';
10
+
11
+ /**
12
+ * Description: A THREE loader for STL ASCII files, as created by Solidworks and other CAD programs.
13
+ *
14
+ * Supports both binary and ASCII encoded files, with automatic detection of type.
15
+ *
16
+ * The loader returns a non-indexed buffer geometry.
17
+ *
18
+ * Limitations:
19
+ * Binary decoding supports "Magics" color format (http://en.wikipedia.org/wiki/STL_(file_format)#Color_in_binary_STL).
20
+ * There is perhaps some question as to how valid it is to always assume little-endian-ness.
21
+ * ASCII decoding assumes file is UTF-8.
22
+ *
23
+ * Usage:
24
+ * const loader = new STLLoader();
25
+ * loader.load( './models/stl/slotted_disk.stl', function ( geometry ) {
26
+ * scene.add( new THREE.Mesh( geometry ) );
27
+ * });
28
+ *
29
+ * For binary STLs geometry might contain colors for vertices. To use it:
30
+ * // use the same code to load STL as above
31
+ * if (geometry.hasColors) {
32
+ * material = new THREE.MeshPhongMaterial({ opacity: geometry.alpha, vertexColors: true });
33
+ * } else { .... }
34
+ * const mesh = new THREE.Mesh( geometry, material );
35
+ *
36
+ * For ASCII STLs containing multiple solids, each solid is assigned to a different group.
37
+ * Groups can be used to assign a different color by defining an array of materials with the same length of
38
+ * geometry.groups and passing it to the Mesh constructor:
39
+ *
40
+ * const mesh = new THREE.Mesh( geometry, material );
41
+ *
42
+ * For example:
43
+ *
44
+ * const materials = [];
45
+ * const nGeometryGroups = geometry.groups.length;
46
+ *
47
+ * const colorMap = ...; // Some logic to index colors.
48
+ *
49
+ * for (let i = 0; i < nGeometryGroups; i++) {
50
+ *
51
+ * const material = new THREE.MeshPhongMaterial({
52
+ * color: colorMap[i],
53
+ * wireframe: false
54
+ * });
55
+ *
56
+ * }
57
+ *
58
+ * materials.push(material);
59
+ * const mesh = new THREE.Mesh(geometry, materials);
60
+ */
61
+
62
+
63
+ class STLLoader extends Loader {
64
+
65
+ constructor( manager ) {
66
+
67
+ super( manager );
68
+
69
+ }
70
+
71
+ load( url, onLoad, onProgress, onError ) {
72
+
73
+ const scope = this;
74
+
75
+ const loader = new FileLoader( this.manager );
76
+ loader.setPath( this.path );
77
+ loader.setResponseType( 'arraybuffer' );
78
+ loader.setRequestHeader( this.requestHeader );
79
+ loader.setWithCredentials( this.withCredentials );
80
+
81
+ loader.load( url, function ( text ) {
82
+
83
+ try {
84
+
85
+ onLoad( scope.parse( text ) );
86
+
87
+ } catch ( e ) {
88
+
89
+ if ( onError ) {
90
+
91
+ onError( e );
92
+
93
+ } else {
94
+
95
+ console.error( e );
96
+
97
+ }
98
+
99
+ scope.manager.itemError( url );
100
+
101
+ }
102
+
103
+ }, onProgress, onError );
104
+
105
+ }
106
+
107
+ parse( data ) {
108
+
109
+ function isBinary( data ) {
110
+
111
+ const reader = new DataView( data );
112
+ const face_size = ( 32 / 8 * 3 ) + ( ( 32 / 8 * 3 ) * 3 ) + ( 16 / 8 );
113
+ const n_faces = reader.getUint32( 80, true );
114
+ const expect = 80 + ( 32 / 8 ) + ( n_faces * face_size );
115
+
116
+ if ( expect === reader.byteLength ) {
117
+
118
+ return true;
119
+
120
+ }
121
+
122
+ // An ASCII STL data must begin with 'solid ' as the first six bytes.
123
+ // However, ASCII STLs lacking the SPACE after the 'd' are known to be
124
+ // plentiful. So, check the first 5 bytes for 'solid'.
125
+
126
+ // Several encodings, such as UTF-8, precede the text with up to 5 bytes:
127
+ // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
128
+ // Search for "solid" to start anywhere after those prefixes.
129
+
130
+ // US-ASCII ordinal values for 's', 'o', 'l', 'i', 'd'
131
+
132
+ const solid = [ 115, 111, 108, 105, 100 ];
133
+
134
+ for ( let off = 0; off < 5; off ++ ) {
135
+
136
+ // If "solid" text is matched to the current offset, declare it to be an ASCII STL.
137
+
138
+ if ( matchDataViewAt( solid, reader, off ) ) return false;
139
+
140
+ }
141
+
142
+ // Couldn't find "solid" text at the beginning; it is binary STL.
143
+
144
+ return true;
145
+
146
+ }
147
+
148
+ function matchDataViewAt( query, reader, offset ) {
149
+
150
+ // Check if each byte in query matches the corresponding byte from the current offset
151
+
152
+ for ( let i = 0, il = query.length; i < il; i ++ ) {
153
+
154
+ if ( query[ i ] !== reader.getUint8( offset + i, false ) ) return false;
155
+
156
+ }
157
+
158
+ return true;
159
+
160
+ }
161
+
162
+ function parseBinary( data ) {
163
+
164
+ const reader = new DataView( data );
165
+ const faces = reader.getUint32( 80, true );
166
+
167
+ let r, g, b, hasColors = false, colors;
168
+ let defaultR, defaultG, defaultB, alpha;
169
+
170
+ // process STL header
171
+ // check for default color in header ("COLOR=rgba" sequence).
172
+
173
+ for ( let index = 0; index < 80 - 10; index ++ ) {
174
+
175
+ if ( ( reader.getUint32( index, false ) == 0x434F4C4F /*COLO*/ ) &&
176
+ ( reader.getUint8( index + 4 ) == 0x52 /*'R'*/ ) &&
177
+ ( reader.getUint8( index + 5 ) == 0x3D /*'='*/ ) ) {
178
+
179
+ hasColors = true;
180
+ colors = new Float32Array( faces * 3 * 3 );
181
+
182
+ defaultR = reader.getUint8( index + 6 ) / 255;
183
+ defaultG = reader.getUint8( index + 7 ) / 255;
184
+ defaultB = reader.getUint8( index + 8 ) / 255;
185
+ alpha = reader.getUint8( index + 9 ) / 255;
186
+
187
+ }
188
+
189
+ }
190
+
191
+ const dataOffset = 84;
192
+ const faceLength = 12 * 4 + 2;
193
+
194
+ const geometry = new BufferGeometry();
195
+
196
+ const vertices = new Float32Array( faces * 3 * 3 );
197
+ const normals = new Float32Array( faces * 3 * 3 );
198
+
199
+ for ( let face = 0; face < faces; face ++ ) {
200
+
201
+ const start = dataOffset + face * faceLength;
202
+ const normalX = reader.getFloat32( start, true );
203
+ const normalY = reader.getFloat32( start + 4, true );
204
+ const normalZ = reader.getFloat32( start + 8, true );
205
+
206
+ if ( hasColors ) {
207
+
208
+ const packedColor = reader.getUint16( start + 48, true );
209
+
210
+ if ( ( packedColor & 0x8000 ) === 0 ) {
211
+
212
+ // facet has its own unique color
213
+
214
+ r = ( packedColor & 0x1F ) / 31;
215
+ g = ( ( packedColor >> 5 ) & 0x1F ) / 31;
216
+ b = ( ( packedColor >> 10 ) & 0x1F ) / 31;
217
+
218
+ } else {
219
+
220
+ r = defaultR;
221
+ g = defaultG;
222
+ b = defaultB;
223
+
224
+ }
225
+
226
+ }
227
+
228
+ for ( let i = 1; i <= 3; i ++ ) {
229
+
230
+ const vertexstart = start + i * 12;
231
+ const componentIdx = ( face * 3 * 3 ) + ( ( i - 1 ) * 3 );
232
+
233
+ vertices[ componentIdx ] = reader.getFloat32( vertexstart, true );
234
+ vertices[ componentIdx + 1 ] = reader.getFloat32( vertexstart + 4, true );
235
+ vertices[ componentIdx + 2 ] = reader.getFloat32( vertexstart + 8, true );
236
+
237
+ normals[ componentIdx ] = normalX;
238
+ normals[ componentIdx + 1 ] = normalY;
239
+ normals[ componentIdx + 2 ] = normalZ;
240
+
241
+ if ( hasColors ) {
242
+
243
+ colors[ componentIdx ] = r;
244
+ colors[ componentIdx + 1 ] = g;
245
+ colors[ componentIdx + 2 ] = b;
246
+
247
+ }
248
+
249
+ }
250
+
251
+ }
252
+
253
+ geometry.setAttribute( 'position', new BufferAttribute( vertices, 3 ) );
254
+ geometry.setAttribute( 'normal', new BufferAttribute( normals, 3 ) );
255
+
256
+ if ( hasColors ) {
257
+
258
+ geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
259
+ geometry.hasColors = true;
260
+ geometry.alpha = alpha;
261
+
262
+ }
263
+
264
+ return geometry;
265
+
266
+ }
267
+
268
+ function parseASCII( data ) {
269
+
270
+ const geometry = new BufferGeometry();
271
+ const patternSolid = /solid([\s\S]*?)endsolid/g;
272
+ const patternFace = /facet([\s\S]*?)endfacet/g;
273
+ let faceCounter = 0;
274
+
275
+ const patternFloat = /[\s]+([+-]?(?:\d*)(?:\.\d*)?(?:[eE][+-]?\d+)?)/.source;
276
+ const patternVertex = new RegExp( 'vertex' + patternFloat + patternFloat + patternFloat, 'g' );
277
+ const patternNormal = new RegExp( 'normal' + patternFloat + patternFloat + patternFloat, 'g' );
278
+
279
+ const vertices = [];
280
+ const normals = [];
281
+
282
+ const normal = new Vector3();
283
+
284
+ let result;
285
+
286
+ let groupCount = 0;
287
+ let startVertex = 0;
288
+ let endVertex = 0;
289
+
290
+ while ( ( result = patternSolid.exec( data ) ) !== null ) {
291
+
292
+ startVertex = endVertex;
293
+
294
+ const solid = result[ 0 ];
295
+
296
+ while ( ( result = patternFace.exec( solid ) ) !== null ) {
297
+
298
+ let vertexCountPerFace = 0;
299
+ let normalCountPerFace = 0;
300
+
301
+ const text = result[ 0 ];
302
+
303
+ while ( ( result = patternNormal.exec( text ) ) !== null ) {
304
+
305
+ normal.x = parseFloat( result[ 1 ] );
306
+ normal.y = parseFloat( result[ 2 ] );
307
+ normal.z = parseFloat( result[ 3 ] );
308
+ normalCountPerFace ++;
309
+
310
+ }
311
+
312
+ while ( ( result = patternVertex.exec( text ) ) !== null ) {
313
+
314
+ vertices.push( parseFloat( result[ 1 ] ), parseFloat( result[ 2 ] ), parseFloat( result[ 3 ] ) );
315
+ normals.push( normal.x, normal.y, normal.z );
316
+ vertexCountPerFace ++;
317
+ endVertex ++;
318
+
319
+ }
320
+
321
+ // every face have to own ONE valid normal
322
+
323
+ if ( normalCountPerFace !== 1 ) {
324
+
325
+ console.error( 'THREE.STLLoader: Something isn\'t right with the normal of face number ' + faceCounter );
326
+
327
+ }
328
+
329
+ // each face have to own THREE valid vertices
330
+
331
+ if ( vertexCountPerFace !== 3 ) {
332
+
333
+ console.error( 'THREE.STLLoader: Something isn\'t right with the vertices of face number ' + faceCounter );
334
+
335
+ }
336
+
337
+ faceCounter ++;
338
+
339
+ }
340
+
341
+ const start = startVertex;
342
+ const count = endVertex - startVertex;
343
+
344
+ geometry.addGroup( start, count, groupCount );
345
+ groupCount ++;
346
+
347
+ }
348
+
349
+ geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
350
+ geometry.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
351
+
352
+ return geometry;
353
+
354
+ }
355
+
356
+ function ensureString( buffer ) {
357
+
358
+ if ( typeof buffer !== 'string' ) {
359
+
360
+ return LoaderUtils.decodeText( new Uint8Array( buffer ) );
361
+
362
+ }
363
+
364
+ return buffer;
365
+
366
+ }
367
+
368
+ function ensureBinary( buffer ) {
369
+
370
+ if ( typeof buffer === 'string' ) {
371
+
372
+ const array_buffer = new Uint8Array( buffer.length );
373
+ for ( let i = 0; i < buffer.length; i ++ ) {
374
+
375
+ array_buffer[ i ] = buffer.charCodeAt( i ) & 0xff; // implicitly assumes little-endian
376
+
377
+ }
378
+
379
+ return array_buffer.buffer || array_buffer;
380
+
381
+ } else {
382
+
383
+ return buffer;
384
+
385
+ }
386
+
387
+ }
388
+
389
+ // start
390
+
391
+ const binData = ensureBinary( data );
392
+
393
+ return isBinary( binData ) ? parseBinary( binData ) : parseASCII( ensureString( data ) );
394
+
395
+ }
396
+
397
+ }
398
+
399
+ export { STLLoader };
@@ -0,0 +1,46 @@
1
+ const JSONLoader = require('./JSONLoader').JSONLoader;
2
+
3
+ exports.PrimitivesLoader = function () {
4
+ let concurrentDownloads = 0;
5
+ const MAX_DOWNLOAD = 20;
6
+ this.crossOrigin = "Anonymous";
7
+ const loader = new JSONLoader();
8
+ const waitingList = [];
9
+
10
+ this.load = (url, onLoad, onProgress, onError) => {
11
+ if (MAX_DOWNLOAD > concurrentDownloads) {
12
+ ++concurrentDownloads;
13
+ loader.crossOrigin = this.crossOrigin;
14
+ const onLoadCallback = new onFinally(onLoad, this);
15
+ const onErrorCallback = new onFinally(onError, this);
16
+ loader.load(url, onLoadCallback, onProgress, onErrorCallback);
17
+ } else {
18
+ waitingList.push({
19
+ url,
20
+ onLoad,
21
+ onProgress,
22
+ onError
23
+ });
24
+ }
25
+ }
26
+
27
+ this.loadFromWaitingList = () => {
28
+ const item = waitingList.shift();
29
+ if (item)
30
+ this.load(item.url, item.onLoad, item.onProgress, item.onError);
31
+ }
32
+
33
+ const onFinally = function(callback, loader) {
34
+ return (...args) => {
35
+ --concurrentDownloads;
36
+ callback(...args);
37
+ loader.loadFromWaitingList();
38
+ }
39
+ }
40
+
41
+
42
+ this.parse = data => {
43
+ return loader.parse(data);
44
+ }
45
+
46
+ }
package/src/minimap.js ADDED
@@ -0,0 +1,82 @@
1
+ const THREE = require('three');
2
+
3
+ exports.Minimap = function (sceneIn) {
4
+ let targetScene = sceneIn;
5
+ this.camera = new THREE.OrthographicCamera(
6
+ -0.5, 0.5, 0.5, -0.5, 0.01, 10);
7
+ this.helper = undefined;
8
+ let geometry = new THREE.BufferGeometry();
9
+ var vertices = new Float32Array( [
10
+ -1.0, -1.0, 1.0,
11
+ 1.0, -1.0, 1.0,
12
+ 1.0, 1.0, 1.0,
13
+ 1.0, 1.0, 1.0,
14
+ -1.0, 1.0, 1.0,
15
+ -1.0, -1.0, 1.0
16
+ ] );
17
+ let positionAttributes = new THREE.BufferAttribute( vertices, 3 );
18
+ geometry.setAttribute( 'position', positionAttributes);
19
+ var material = new THREE.MeshBasicMaterial( { color: 0x333333,
20
+ depthTest: false,
21
+ depthWrite: false,
22
+ opacity: 0.5,
23
+ transparent: true } );
24
+ this.mask = new THREE.Mesh( geometry, material );
25
+ let _box = new THREE.Box3();
26
+ let _center = new THREE.Vector3();
27
+
28
+ this.getDiffFromNormalised = (x, y) => {
29
+ _box.setFromBufferAttribute(positionAttributes).getCenter(_center);
30
+ let coord = _center.clone().project(this.camera);
31
+ let new_coord = new THREE.Vector3(x, y, coord.z).unproject(this.camera);
32
+ return new_coord.sub(_center);
33
+ }
34
+
35
+ let setCurrentCameraSettings = (diameter, newViewport) => {
36
+ if (targetScene.camera.near)
37
+ this.camera.near = targetScene.camera.near;
38
+ if (newViewport.farPlane)
39
+ this.camera.far = newViewport.farPlane;
40
+ if (newViewport.eyePosition)
41
+ this.camera.position.set(newViewport.eyePosition[0],
42
+ newViewport.eyePosition[1], newViewport.eyePosition[2]);
43
+ if (newViewport.upVector)
44
+ this.camera.up.set(newViewport.upVector[0], newViewport.upVector[1],
45
+ newViewport.upVector[2]);
46
+ if (newViewport.targetPosition)
47
+ this.camera.lookAt(new THREE.Vector3(newViewport.targetPosition[0],
48
+ newViewport.targetPosition[1], newViewport.targetPosition[2]));
49
+ this.camera.zoom = 1 / diameter;
50
+ this.camera.updateProjectionMatrix();
51
+ }
52
+
53
+ this.getBoundary = () => {
54
+ let target = new THREE.Vector3().copy(
55
+ targetScene.camera.target).project(targetScene.camera);
56
+ let v1 = new THREE.Vector3(-1, -1, target.z).unproject(targetScene.camera);
57
+ let v2 = new THREE.Vector3(1, -1, target.z).unproject(targetScene.camera);
58
+ let v3 = new THREE.Vector3(1, 1, target.z).unproject(targetScene.camera);
59
+ let v4 = new THREE.Vector3(-1, 1, target.z).unproject(targetScene.camera);
60
+ let array = [v1, v2, v3, v3, v4, v1];
61
+ positionAttributes.copyVector3sArray(array);
62
+ positionAttributes.needsUpdate = true;
63
+ }
64
+
65
+ this.updateCamera = () => {
66
+ this.getBoundary();
67
+ let cameraControl = targetScene.getZincCameraControls();
68
+ let boundingBox = targetScene.getBoundingBox();
69
+ if (boundingBox) {
70
+ // enlarge radius to keep image within edge of window
71
+ const diameter = boundingBox.min.distanceTo(boundingBox.max);
72
+ const radius = diameter / 2.0;
73
+ const centreX = (boundingBox.min.x + boundingBox.max.x) / 2.0;
74
+ const centreY = (boundingBox.min.y + boundingBox.max.y) / 2.0;
75
+ const centreZ = (boundingBox.min.z + boundingBox.max.z) / 2.0;
76
+ const clip_factor = 4.0;
77
+ const viewport = cameraControl.getViewportFromCentreAndRadius(
78
+ centreX, centreY, centreZ, radius, 40, radius * clip_factor);
79
+ setCurrentCameraSettings(diameter, viewport);
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,22 @@
1
+ exports.augmentMorphColor = function() {
2
+ return function(shader) {
3
+ shader.vertexShader = shader.vertexShader.replace(
4
+ '#include <color_pars_vertex>',
5
+ [
6
+ 'varying vec3 vColor;',
7
+ 'attribute vec3 morphColor0;',
8
+ 'attribute vec3 morphColor1;'
9
+ ].join( '\n' )
10
+ );
11
+ shader.vertexShader = shader.vertexShader.replace(
12
+ '#include <color_vertex>',
13
+ [
14
+ 'vColor.xyz = color.xyz;',
15
+ '#ifdef USE_MORPHTARGETS',
16
+ 'vColor = morphColor0 * morphTargetInfluences[ 0 ];',
17
+ 'vColor += morphColor1 * morphTargetInfluences[ 1 ];',
18
+ '#endif'
19
+ ].join( '\n' )
20
+ );
21
+ };
22
+ }
@@ -0,0 +1,109 @@
1
+ const THREE = require('three');
2
+
3
+ /**
4
+ * Provides an object which stores geometry and provides method which controls its animations.
5
+ * This is created when a valid json file containging geometry is read into a {@link Zinc.Scene}
6
+ * object.
7
+ *
8
+ * @class
9
+ * @author Alan Wu
10
+ * @return {Zinc.Geometry}
11
+ */
12
+ const Geometry = function () {
13
+ (require('./zincObject').ZincObject).call(this);
14
+ // THREE.Geometry or THREE.BufferGeometry
15
+ this.videoHandler = undefined;
16
+ this.isGeometry = true;
17
+
18
+ this.createMesh = (geometryIn, materialIn, options) => {
19
+ if (this.geometry && this.morph && (geometryIn != undefined))
20
+ return;
21
+ // First copy the geometry
22
+ let geometry = this.toBufferGeometry(geometryIn, options);
23
+
24
+ let isTransparent = false;
25
+ if (1.0 > options.opacity)
26
+ isTransparent = true;
27
+
28
+ let material = undefined;
29
+ if (geometry._video === undefined) {
30
+ const morphTargets = options.localTimeEnabled || options.localMorphColour;
31
+ if (materialIn) {
32
+ material = materialIn;
33
+ material.morphTargets = morphTargets;
34
+ material.morphNormals = options.localTimeEnabled;
35
+ } else {
36
+ if (geometry instanceof THREE.BufferGeometry && geometry.attributes.color === undefined) {
37
+ material = new THREE.MeshPhongMaterial({
38
+ color : options.colour,
39
+ morphTargets : morphTargets,
40
+ morphNormals : options.localTimeEnabled,
41
+ transparent : isTransparent,
42
+ opacity : options.opacity,
43
+ side : THREE.DoubleSide
44
+ });
45
+ } else {
46
+ material = new THREE.MeshPhongMaterial({
47
+ color : options.colour,
48
+ morphTargets : morphTargets,
49
+ morphNormals : options.localTimeEnabled,
50
+ vertexColors : THREE.VertexColors,
51
+ transparent : isTransparent,
52
+ opacity : options.opacity,
53
+ side : THREE.DoubleSide
54
+ });
55
+ }
56
+ }
57
+ //material = PhongToToon(material);
58
+ if (options.localMorphColour && geometry.morphAttributes[ "color" ]) {
59
+ material.onBeforeCompile = (require("./augmentShader").augmentMorphColor)();
60
+ }
61
+ } else {
62
+ let videoTexture = geometry._video.createCanvasVideoTexture();
63
+ material = new THREE.MeshBasicMaterial({
64
+ morphTargets : options.localTimeEnabled,
65
+ color : new THREE.Color(1, 1, 1),
66
+ transparent : isTransparent,
67
+ opacity : options.opacity,
68
+ map : videoTexture,
69
+ side : THREE.DoubleSide
70
+ });
71
+ this.videoHandler = geometry._video;
72
+ }
73
+ let mesh = new THREE.Mesh(geometry, material);
74
+ this.setMesh(mesh, options.localTimeEnabled, options.localMorphColour);
75
+ }
76
+
77
+ this.calculateUVs = () => {
78
+ this.geometry.computeBoundingBox();
79
+ const max = this.geometry.boundingBox.max, min = this.geometry.boundingBox.min;
80
+ const offset = new THREE.Vector2(0 - min.x, 0 - min.y);
81
+ const range = new THREE.Vector2(max.x - min.x, max.y - min.y);
82
+ this.geometry.faceVertexUvs[0] = [];
83
+ for (let i = 0; i < this.geometry.faces.length ; i++) {
84
+ const v1 = this.geometry.vertices[this.geometry.faces[i].a];
85
+ const v2 = this.geometry.vertices[this.geometry.faces[i].b];
86
+ const v3 = this.geometry.vertices[this.geometry.faces[i].c];
87
+ geometry.faceVertexUvs[0].push(
88
+ [
89
+ new THREE.Vector2((v1.x + offset.x)/range.x ,(v1.y + offset.y)/range.y),
90
+ new THREE.Vector2((v2.x + offset.x)/range.x ,(v2.y + offset.y)/range.y),
91
+ new THREE.Vector2((v3.x + offset.x)/range.x ,(v3.y + offset.y)/range.y)
92
+ ]);
93
+ }
94
+ geometry.uvsNeedUpdate = true;
95
+ }
96
+
97
+ /**
98
+ * Set wireframe display for this geometry.
99
+ *
100
+ * @param {Boolean} wireframe - Flag to turn on/off wireframe display.
101
+ */
102
+ this.setWireframe = wireframe => {
103
+ this.morph.material.wireframe = wireframe;
104
+ }
105
+
106
+ }
107
+
108
+ Geometry.prototype = Object.create((require('./zincObject').ZincObject).prototype);
109
+ exports.Geometry = Geometry;