zincjs 1.2.0 → 1.4.0-beta.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zincjs",
3
- "version": "1.2.0",
3
+ "version": "1.4.0-beta.0",
4
4
  "description": "ZincJS (Web-based-Zinc-Visualisation)",
5
5
  "main": "build/zinc.js",
6
6
  "directories": {
@@ -4,7 +4,7 @@
4
4
  <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
5
5
  viewBox="0 0 365 560" enable-background="new 0 0 365 560" xml:space="preserve">
6
6
  <g>
7
- <path fill="#00AEEF" d="M182.9,551.7c0,0.1,0.2,0.3,0.2,0.3S358.3,283,358.3,194.6c0-130.1-88.8-186.7-175.4-186.9
7
+ <path fill="#005974" d="M182.9,551.7c0,0.1,0.2,0.3,0.2,0.3S358.3,283,358.3,194.6c0-130.1-88.8-186.7-175.4-186.9
8
8
  C96.3,7.9,7.5,64.5,7.5,194.6c0,88.4,175.3,357.4,175.3,357.4S182.9,551.7,182.9,551.7z M122.2,187.2c0-33.6,27.2-60.8,60.8-60.8
9
9
  c33.6,0,60.8,27.2,60.8,60.8S216.5,248,182.9,248C149.4,248,122.2,220.8,122.2,187.2z"/>
10
10
  </g>
@@ -17,16 +17,16 @@ const GeometryCSG = function (hostIn) {
17
17
  let myResolve = undefined;
18
18
 
19
19
  var createGeometryFromJSON = json => {
20
- const material = host.morph.material.clone();
21
- material.morphTargets = false;
22
- const newGeometry = new Geometry();
20
+ const material = host.getMorph().material.clone();
21
+ material.morphTargets = false;
22
+ const newGeometry = new Geometry();
23
23
  const JSONParser = new JSONLoader();
24
24
  const geometry = JSONParser.parse(json);
25
- const mesh = new THREE.Mesh(geometry.geometry, material);
26
- newGeometry.geometry = mesh.geometry;
27
- newGeometry.morph = mesh;
28
- newGeometry.morph.userData = newGeometry;
29
- return newGeometry;
25
+ const mesh = new THREE.Mesh(geometry.geometry, material);
26
+ newGeometry.geometry = mesh.geometry;
27
+ mesh.userData = newGeometry;
28
+ newGeometry.setMorph(mesh);
29
+ return newGeometry;
30
30
  }
31
31
 
32
32
  var workerEventHandler = ev => {
@@ -54,7 +54,7 @@ const GeometryCSG = function (hostIn) {
54
54
  core = new (require('./workers/geometryCSGInternal').GeometryCSGInternal)(hostIn);
55
55
  } else {
56
56
  if (hostIn && hostIn.isGeometry) {
57
- let mesh = hostIn.morph;
57
+ let mesh = hostIn.getMorph();
58
58
  let json = mesh.geometry.clone().applyMatrix(mesh.matrix).toJSON();
59
59
  worker.addEventListener('message', function (ev) {
60
60
  workerEventHandler(ev);
@@ -65,20 +65,20 @@ const GeometryCSG = function (hostIn) {
65
65
  }
66
66
 
67
67
  this.getHostGeometry = () => {
68
- const tempCSG = new ThreeBSP(host.morph);
68
+ const tempCSG = new ThreeBSP(host.getMorph());
69
69
  return new createZincGeometry(tempCSG);
70
70
  }
71
71
 
72
72
  this.getGeometry = () => host;
73
73
 
74
74
  const createZincGeometry = csgMesh => {
75
- const material = host.morph.material.clone();
75
+ const material = host.getMorph().material.clone();
76
76
  material.morphTargets = false;
77
77
  const newMesh = csgMesh.toMesh(material);
78
78
  const newGeometry = new Geometry();
79
79
  newGeometry.geometry = newMesh.geometry;
80
- newGeometry.morph = newMesh;
81
- newGeometry.morph.userData = newGeometry;
80
+ newMesh.userData = newGeometry;
81
+ newGeometry.setMorph(newMesh);
82
82
  return newGeometry;
83
83
  }
84
84
 
@@ -88,7 +88,7 @@ const GeometryCSG = function (hostIn) {
88
88
 
89
89
  const sendToWork = (guestGeometry, action, resolve, reject) => {
90
90
  if (!onProgress) {
91
- let mesh = guestGeometry.morph;
91
+ let mesh = guestGeometry.getMorph();
92
92
  const json = mesh.geometry.clone().applyMatrix(mesh.matrix).toJSON();
93
93
  myResolve = resolve;
94
94
  onProgress = true;
@@ -44,11 +44,11 @@ const GlyphsetCSG = function (hostIn) {
44
44
  };
45
45
 
46
46
  const prepareCSG = guestGeometry => {
47
- if (host && guestGeometry && guestGeometry.morph) {
47
+ if (host && guestGeometry && guestGeometry.getMorph()) {
48
48
  if (hostCSGs.length == 0) {
49
49
  host.forEachGlyph(prepareCSGForGlyphs());
50
50
  }
51
- const guestCSG = new ThreeBSP(guestGeometry.morph);
51
+ const guestCSG = new ThreeBSP(guestGeometry.getMorph());
52
52
  return guestCSG;
53
53
  }
54
54
  return undefined;
@@ -39,8 +39,9 @@ const GLTFToZincJSLoader = function () {
39
39
  }
40
40
  zincGeometry.setMesh(object.clone(), localTimeEnabled, localMorphColour);
41
41
  region.addZincObject(zincGeometry);
42
- zincGeometry.groupName = zincGeometry.morph.name;
43
- zincGeometry.morph.matrixAutoUpdate = true;
42
+ const morph = zincGeometry.getMorph();
43
+ zincGeometry.groupName = morph.name;
44
+ morph.matrixAutoUpdate = true;
44
45
  if (finishCallback != undefined && (typeof finishCallback == 'function'))
45
46
  finishCallback(zincGeometry);
46
47
  }
@@ -33,7 +33,9 @@ exports.PrimitivesLoader = function () {
33
33
  const onFinally = function(callback, loader) {
34
34
  return (...args) => {
35
35
  --concurrentDownloads;
36
- callback(...args);
36
+ if (callback) {
37
+ callback(...args);
38
+ }
37
39
  loader.loadFromWaitingList();
38
40
  }
39
41
  }
@@ -1,4 +1,61 @@
1
1
  const THREE = require('three');
2
+ const toBufferGeometry = require('../utilities').toBufferGeometry;
3
+
4
+ const createMeshForGeometry = (geometryIn, materialIn, options) => {
5
+ // First copy the geometry
6
+ let geometry = toBufferGeometry(geometryIn, options);
7
+
8
+ let isTransparent = false;
9
+ if (1.0 > options.opacity)
10
+ isTransparent = true;
11
+
12
+ let material = undefined;
13
+ if (geometry._video === undefined) {
14
+ const morphTargets = options.localTimeEnabled || options.localMorphColour;
15
+ if (materialIn) {
16
+ material = materialIn;
17
+ material.morphTargets = morphTargets;
18
+ material.morphNormals = options.localTimeEnabled;
19
+ } else {
20
+ if (geometry instanceof THREE.BufferGeometry && geometry.attributes.color === undefined) {
21
+ material = new THREE.MeshPhongMaterial({
22
+ color : options.colour,
23
+ morphTargets : morphTargets,
24
+ morphNormals : options.localTimeEnabled,
25
+ transparent : isTransparent,
26
+ opacity : options.opacity,
27
+ side : THREE.DoubleSide
28
+ });
29
+ } else {
30
+ material = new THREE.MeshPhongMaterial({
31
+ color : options.colour,
32
+ morphTargets : morphTargets,
33
+ morphNormals : options.localTimeEnabled,
34
+ vertexColors : THREE.VertexColors,
35
+ transparent : isTransparent,
36
+ opacity : options.opacity,
37
+ side : THREE.DoubleSide
38
+ });
39
+ }
40
+ }
41
+ //material = PhongToToon(material);
42
+ if (options.localMorphColour && geometry.morphAttributes[ "color" ]) {
43
+ material.onBeforeCompile = (require("./augmentShader").augmentMorphColor)();
44
+ }
45
+ } else {
46
+ let videoTexture = geometry._video.createCanvasVideoTexture();
47
+ material = new THREE.MeshBasicMaterial({
48
+ morphTargets : options.localTimeEnabled,
49
+ color : new THREE.Color(1, 1, 1),
50
+ transparent : isTransparent,
51
+ opacity : options.opacity,
52
+ map : videoTexture,
53
+ side : THREE.DoubleSide
54
+ });
55
+ this.videoHandler = geometry._video;
56
+ }
57
+ return new THREE.Mesh(geometry, material);
58
+ }
2
59
 
3
60
  /**
4
61
  * Provides an object which stores geometry and provides method which controls its animations.
@@ -29,61 +86,10 @@ const Geometry = function () {
29
86
  * @param {Number} options.opacity - Opacity to be set for the geometry
30
87
  */
31
88
  this.createMesh = (geometryIn, materialIn, options) => {
32
- if (this.geometry && this.morph && (geometryIn != undefined))
89
+ //Skip if there is a morph already
90
+ if (this.morph && this.morph.geometry && (geometryIn != undefined))
33
91
  return;
34
- // First copy the geometry
35
- let geometry = this.toBufferGeometry(geometryIn, options);
36
-
37
- let isTransparent = false;
38
- if (1.0 > options.opacity)
39
- isTransparent = true;
40
-
41
- let material = undefined;
42
- if (geometry._video === undefined) {
43
- const morphTargets = options.localTimeEnabled || options.localMorphColour;
44
- if (materialIn) {
45
- material = materialIn;
46
- material.morphTargets = morphTargets;
47
- material.morphNormals = options.localTimeEnabled;
48
- } else {
49
- if (geometry instanceof THREE.BufferGeometry && geometry.attributes.color === undefined) {
50
- material = new THREE.MeshPhongMaterial({
51
- color : options.colour,
52
- morphTargets : morphTargets,
53
- morphNormals : options.localTimeEnabled,
54
- transparent : isTransparent,
55
- opacity : options.opacity,
56
- side : THREE.DoubleSide
57
- });
58
- } else {
59
- material = new THREE.MeshPhongMaterial({
60
- color : options.colour,
61
- morphTargets : morphTargets,
62
- morphNormals : options.localTimeEnabled,
63
- vertexColors : THREE.VertexColors,
64
- transparent : isTransparent,
65
- opacity : options.opacity,
66
- side : THREE.DoubleSide
67
- });
68
- }
69
- }
70
- //material = PhongToToon(material);
71
- if (options.localMorphColour && geometry.morphAttributes[ "color" ]) {
72
- material.onBeforeCompile = (require("./augmentShader").augmentMorphColor)();
73
- }
74
- } else {
75
- let videoTexture = geometry._video.createCanvasVideoTexture();
76
- material = new THREE.MeshBasicMaterial({
77
- morphTargets : options.localTimeEnabled,
78
- color : new THREE.Color(1, 1, 1),
79
- transparent : isTransparent,
80
- opacity : options.opacity,
81
- map : videoTexture,
82
- side : THREE.DoubleSide
83
- });
84
- this.videoHandler = geometry._video;
85
- }
86
- let mesh = new THREE.Mesh(geometry, material);
92
+ const mesh = createMeshForGeometry(geometryIn, materialIn, options);
87
93
  this.setMesh(mesh, options.localTimeEnabled, options.localMorphColour);
88
94
  }
89
95
 
@@ -91,6 +97,7 @@ const Geometry = function () {
91
97
  * Calculate the UV for texture rendering.
92
98
  */
93
99
  this.calculateUVs = () => {
100
+ //Multilayers
94
101
  this.geometry.computeBoundingBox();
95
102
  const max = this.geometry.boundingBox.max, min = this.geometry.boundingBox.min;
96
103
  const offset = new THREE.Vector2(0 - min.x, 0 - min.y);
@@ -109,6 +116,14 @@ const Geometry = function () {
109
116
  }
110
117
  geometry.uvsNeedUpdate = true;
111
118
  }
119
+
120
+ /**
121
+ * Handle transparent mesh, create a clone for backside rendering if it is
122
+ * transparent.
123
+ */
124
+ this.checkTransparentMesh = function(transparentChanged) {
125
+ this._lod.checkTransparentMesh(this.animationGroup, transparentChanged);
126
+ }
112
127
 
113
128
  /**
114
129
  * Set wireframe display for this geometry.
@@ -119,6 +134,7 @@ const Geometry = function () {
119
134
  this.morph.material.wireframe = wireframe;
120
135
  }
121
136
 
137
+
122
138
  }
123
139
 
124
140
  Geometry.prototype = Object.create((require('./zincObject').ZincObject).prototype);
@@ -90,7 +90,8 @@ const Glyphset = function () {
90
90
  scaleFactors = glyphsetData.metadata.scale_factors;
91
91
  const loader = new JSONLoader();
92
92
  this.geometry = new THREE.BufferGeometry();
93
- this.morph = new THREE.InstancedMesh(this.geometry, undefined, numberOfVertices);
93
+ const instancedMesh = new THREE.InstancedMesh(this.geometry, undefined, numberOfVertices);
94
+ this.setMorph(instancedMesh);
94
95
  if (isInline) {
95
96
  var object = loader.parse(glyphURL);
96
97
  (meshloader(finishCallback, displayLabels))(object.geometry, object.materials);
@@ -498,6 +499,7 @@ const Glyphset = function () {
498
499
  createGlyphs(displayLabels);
499
500
  this.morph.name = this.groupName;
500
501
  this.morph.userData = this;
502
+ this.setMorph(this.morph);
501
503
  geometry.dispose();
502
504
  if (finishCallback != undefined && (typeof finishCallback == 'function'))
503
505
  finishCallback(this);
@@ -510,19 +512,17 @@ const Glyphset = function () {
510
512
  this.getClosestVertexIndex = function () {
511
513
  let closestIndex = -1;
512
514
  if (this.morph && this.ready) {
513
- let center = new THREE.Vector3();
514
- this.getBoundingBox().getCenter(center);
515
+ this.getBoundingBox().getCenter(this._v1);
515
516
  let current_positions = positions["0"];
516
517
  const numberOfPositions = current_positions.length / 3;
517
- let position = new THREE.Vector3();
518
518
  let distance = -1;
519
519
  let currentDistance = 0;
520
520
  for (let i = 0; i < numberOfPositions; i++) {
521
521
  const current_index = i * 3;
522
- position.set(current_positions[current_index],
522
+ this._v2.set(current_positions[current_index],
523
523
  current_positions[current_index + 1],
524
524
  current_positions[current_index + 2]);
525
- currentDistance = center.distanceTo(position);
525
+ currentDistance = this._v1.distanceTo(this._v2);
526
526
  if (distance == -1) {
527
527
  distance = currentDistance;
528
528
  closestIndex = i;
@@ -1,4 +1,5 @@
1
1
  const THREE = require('three');
2
+ const toBufferGeometry = require('../utilities').toBufferGeometry;
2
3
 
3
4
  /**
4
5
  * Provides an object which stores lines.
@@ -26,7 +27,7 @@ const Lines = function () {
26
27
  */
27
28
  this.createLineSegment = (geometryIn, materialIn, options) => {
28
29
  if (geometryIn && materialIn) {
29
- let geometry = this.toBufferGeometry(geometryIn, options);
30
+ let geometry = toBufferGeometry(geometryIn, options);
30
31
  if (options.localMorphColour && geometry.morphAttributes[ "color" ])
31
32
  materialIn.onBeforeCompile = (require("./augmentShader").augmentMorphColor)();
32
33
  let line = new (require("../three/line/LineSegments").LineSegments)(geometry, materialIn);