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,35 @@
1
+ const THREE = require('three');
2
+ /**
3
+ * Provides an object which stores points and provides method which controls its position.
4
+ * This is created when a valid json file containing point is read into a {@link Zinc.Scene}
5
+ * object.
6
+ *
7
+ * @class
8
+ * @author Alan Wu
9
+ * @return {Zinc.Lines}
10
+ */
11
+ const Lines = function () {
12
+ (require('./zincObject').ZincObject).call(this);
13
+ this.isLines = true;
14
+
15
+ this.createLineSegment = (geometryIn, materialIn, options) => {
16
+ if (geometryIn && materialIn) {
17
+ let geometry = this.toBufferGeometry(geometryIn, options);
18
+ if (options.localMorphColour && geometry.morphAttributes[ "color" ])
19
+ materialIn.onBeforeCompile = (require("./augmentShader").augmentMorphColor)();
20
+ let line = new (require("../three/line/LineSegments").LineSegments)(geometry, materialIn);
21
+ this.setMesh(line, options.localTimeEnabled, options.localMorphColour);
22
+ }
23
+ }
24
+
25
+ this.setWidth = width => {
26
+ if (this.morph && this.morph.material) {
27
+ this.morph.material.linewidth = width;
28
+ this.morph.material.needsUpdate = true;
29
+ }
30
+ }
31
+
32
+ }
33
+
34
+ Lines.prototype = Object.create((require('./zincObject').ZincObject).prototype);
35
+ exports.Lines = Lines;
@@ -0,0 +1,88 @@
1
+ var THREE = require('three');
2
+ const markerImage = new Image(128, 128);
3
+ markerImage.src = require("../assets/mapMarker.svg");
4
+ const texture = new THREE.Texture();
5
+ texture.image = markerImage;
6
+ texture.needsUpdate = true;
7
+ const size = [0.015, 0.02, 1];
8
+
9
+ //Marker - used to indicate there is a
10
+ const Marker = function(zincObject) {
11
+ (require('./zincObject').ZincObject).call(this);
12
+ this.texture = texture;
13
+ let spriteMaterial = undefined;
14
+ let sprite = undefined;
15
+ this.morph = new THREE.Group();
16
+ this.parent = zincObject;
17
+ this.isMarker = true;
18
+ let enabled = false;
19
+ let vector = new THREE.Vector3();
20
+
21
+ let initialise = () => {
22
+ spriteMaterial = new THREE.SpriteMaterial({
23
+ map: texture,
24
+ alphaTest: 0.5,
25
+ transparent: true,
26
+ depthTest: false,
27
+ depthWrite: false,
28
+ sizeAttenuation: false
29
+ });
30
+ sprite = new THREE.Sprite(spriteMaterial);
31
+ sprite.center.set(0.5, 0);
32
+ this.morph.add(sprite);
33
+ this.morph.position.set(0, 0, 0);
34
+ this.morph.renderOrder = 10000;
35
+ sprite.scale.set(size[0], size[1], size[2]);
36
+ sprite.userData = this;
37
+ }
38
+
39
+ this.updateVisual = (min, max) => {
40
+ let scale = 1;
41
+ let opacity = 1;
42
+ let porportion = 0;
43
+ if (min !== max) {
44
+ porportion = (1 - (vector.z - min) / (max - min));
45
+ scale = 0.5 + porportion * 0.5;
46
+ opacity = 0.6 + porportion * 0.4;
47
+ }
48
+ sprite.material.opacity = opacity;
49
+ this.setSpriteSize(scale);
50
+ }
51
+
52
+ this.updateNDC = camera => {
53
+ vector.copy(this.morph.position);
54
+ vector.project(camera);
55
+ vector.z = Math.min(Math.max(vector.z, 0), 1);
56
+ return vector.z;
57
+ }
58
+
59
+ this.setPosition = (x, y, z) => {
60
+ this.morph.position.set(x, y, z);
61
+ }
62
+
63
+ this.setSpriteSize = size => {
64
+ sprite.scale.set(0.015, 0.02, 1);
65
+ sprite.scale.multiplyScalar(size);
66
+ }
67
+
68
+ this.isEnabled = () => {
69
+ return enabled;
70
+ }
71
+
72
+ this.enable = () => {
73
+ enabled = true;
74
+ this.morph.visible = true;
75
+ }
76
+
77
+ this.disable = () => {
78
+ enabled = false;
79
+ this.morph.visible = false;
80
+ }
81
+
82
+ //this should be handle by scene... check the sync at
83
+ initialise();
84
+
85
+ }
86
+
87
+ Marker.prototype = Object.create((require('./zincObject').ZincObject).prototype);
88
+ exports.Marker = Marker;
@@ -0,0 +1,53 @@
1
+ const THREE = require('three');
2
+ const Points = require('../three/Points').Points;
3
+
4
+ /**
5
+ * Provides an object which stores points and provides method which controls its position.
6
+ * This is created when a valid json file containing point is read into a {@link Zinc.Scene}
7
+ * object.
8
+ *
9
+ * @class
10
+ * @author Alan Wu
11
+ * @return {Zinc.Geometry}
12
+ */
13
+ const Pointset = function () {
14
+ (require('./zincObject').ZincObject).call(this);
15
+ this.isPointset = true;
16
+
17
+ /** Shape of the points is created using the function below */
18
+ const getCircularTexture = () => {
19
+ var image = new Image();
20
+ image.src = require("../assets/disc.png");
21
+ const texture = new THREE.Texture();
22
+ texture.image = image;
23
+ texture.needsUpdate = true;
24
+ return texture;
25
+ }
26
+
27
+ this.createMesh = (geometryIn, materialIn, options) => {
28
+ if (geometryIn && materialIn) {
29
+ let geometry = this.toBufferGeometry(geometryIn, options);
30
+ const texture = getCircularTexture();
31
+ materialIn.map = texture;
32
+ let point = new Points(geometry, materialIn);
33
+ this.setMesh(point, options.localTimeEnabled, options.localMorphColour);
34
+ }
35
+ }
36
+
37
+ this.setSize = size => {
38
+ if (this.morph && this.morph.material) {
39
+ this.morph.material.size = size;
40
+ this.morph.material.needsUpdate = true;
41
+ }
42
+ }
43
+
44
+ this.setSizeAttenuation = flag => {
45
+ if (this.morph && this.morph.material) {
46
+ this.morph.material.sizeAttenuation = flag;
47
+ this.morph.material.needsUpdate = true;
48
+ }
49
+ }
50
+ }
51
+
52
+ Pointset.prototype = Object.create((require('./zincObject').ZincObject).prototype);
53
+ exports.Pointset = Pointset;
@@ -0,0 +1,16 @@
1
+ const THREE = require('three');
2
+ /**
3
+ * Provides a base class object which stores textures and rendering object.
4
+ *
5
+ * @class
6
+ * @author Alan Wu
7
+ * @return {Zinc.Lines}
8
+ */
9
+ const TexturePrimitive = function (textureIn) {
10
+ (require('./zincObject').ZincObject).call(this);
11
+ this.isTexturePrimitive = true;
12
+ this.texture = textureIn;
13
+ }
14
+
15
+ TexturePrimitive.prototype = Object.create((require('./zincObject').ZincObject).prototype);
16
+ exports.TexturePrimitive = TexturePrimitive;
@@ -0,0 +1,118 @@
1
+ const THREE = require('three');
2
+ const shader = require("../shaders/textureSlide.js");
3
+ /**
4
+ * Provides a base class object which stores textures and rendering object.
5
+ *
6
+ * @class
7
+ * @author Alan Wu
8
+ * @return {Zinc.Lines}
9
+ */
10
+ const TextureSlides = function (textureIn) {
11
+ (require('./texturePrimitive').TexturePrimitive).call(this, textureIn);
12
+ this.isTextureSlides = true;
13
+
14
+ /*
15
+ * Create slides
16
+ */
17
+ this.createSlides = slideSettings => {
18
+ if (!this.morph) this.morph = new THREE.Group();
19
+ if (this.texture && this.texture.isTextureArray && this.texture.isReady()) {
20
+ slideSettings.forEach(slide => {
21
+ if (slide.direction && slide.value) {
22
+ const geometry = new THREE.PlaneGeometry( 1, 1 );
23
+ geometry.translate(0.5, 0.5, 0);
24
+ const uniforms = shader.getUniforms();
25
+ uniforms.diffuse.value = this.texture.impl;
26
+ uniforms.depth.value = this.texture.size.depth;
27
+ switch(slide.direction) {
28
+ case "x":
29
+ uniforms.slide.value.set(slide.value, 0, 0);
30
+ break;
31
+ case "y":
32
+ uniforms.slide.value.set(0, slide.value, 0);
33
+ break;
34
+ case "z":
35
+ uniforms.slide.value.set(0, 0, slide.value);
36
+ break;
37
+ default:
38
+ break;
39
+ }
40
+ const options = {
41
+ fs: shader.fs,
42
+ vs: shader.vs,
43
+ uniforms: uniforms,
44
+ glslVersion: shader.glslVersion,
45
+ side: THREE.DoubleSide,
46
+ transparent: false
47
+ };
48
+ const material = this.texture.getMaterial(options);
49
+ material.needsUpdate = true;
50
+ const mesh = new THREE.Mesh( geometry, material );
51
+ this.morph.add(mesh);
52
+ }
53
+ });
54
+ }
55
+ }
56
+
57
+ /*
58
+ * Get all slides, return them in an array
59
+ */
60
+ this.getSlides = () => {
61
+ if (this.morph) return [...this.morph.children];
62
+ return [];
63
+ }
64
+
65
+ /*
66
+ * Remove a slide, this will dispose the slide and its material.
67
+ */
68
+ this.removeSlide = slide => {
69
+ if (slide && this.morph) {
70
+ if (this.morph.getObjectById(slide.id)) {
71
+ this.morph.remove(slide);
72
+ slide.disppose();
73
+ if (slide.geometry)
74
+ slide.geometry.dispose();
75
+ if (slide.material)
76
+ slide.material.dispose();
77
+ }
78
+ }
79
+ }
80
+
81
+ this.dispose = () => {
82
+ this.morph.children.forEach(slide=> {
83
+ if (slide.geometry)
84
+ slide.geometry.dispose();
85
+ if (slide.material)
86
+ slide.material.dispose();
87
+ });
88
+ (require('./texturePrimitive').TexturePrimitive).prototype.dispose.call(this);
89
+ }
90
+
91
+ /**
92
+ * Get the bounding box of this geometry.
93
+ *
94
+ * @return {THREE.Box3}.
95
+ */
96
+ this.getBoundingBox = function() {
97
+ if (this.morph && this.morph.children && this.morph.visible &&
98
+ this.boundingBoxUpdateRequired) {
99
+ let first = true;
100
+ this.morph.children.forEach( morph => {
101
+ if (first) {
102
+ this.cachedBoundingBox.setFromBufferAttribute(
103
+ morph.geometry.attributes.position);
104
+ first = false;
105
+ } else {
106
+ this.cachedBoundingBox.expandByObject(morph);
107
+ }
108
+ });
109
+ this.boundingBoxUpdateRequired = false;
110
+ return this.cachedBoundingBox;
111
+ }
112
+ return undefined;
113
+ }
114
+ }
115
+
116
+
117
+ TextureSlides.prototype = Object.create((require('./texturePrimitive').TexturePrimitive).prototype);
118
+ exports.TextureSlides = TextureSlides;