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.
- package/build/zinc.frontend.js +1 -1
- package/build/zinc.js +43 -35
- package/build/zinc.js.map +1 -1
- package/package.json +3 -3
- package/src/assets/disc.png +0 -0
- package/src/assets/mapMarker.svg +11 -0
- package/src/controls.js +1594 -0
- package/src/geometryCSG.js +148 -0
- package/src/glyphsetCSG.js +84 -0
- package/src/loaders/GLTFToZincJSLoader.js +85 -0
- package/src/loaders/JSONLoader.js +697 -0
- package/src/loaders/OBJLoader.js +911 -0
- package/src/loaders/STLLoader.js +399 -0
- package/src/loaders/primitivesLoader.js +46 -0
- package/src/minimap.js +82 -0
- package/src/primitives/augmentShader.js +22 -0
- package/src/primitives/geometry.js +109 -0
- package/src/primitives/glyph.js +150 -0
- package/src/primitives/glyphset.js +657 -0
- package/src/primitives/label.js +51 -0
- package/src/primitives/lines.js +35 -0
- package/src/primitives/marker.js +88 -0
- package/src/primitives/pointset.js +53 -0
- package/src/primitives/texturePrimitive.js +16 -0
- package/src/primitives/textureSlides.js +118 -0
- package/src/primitives/zincObject.js +573 -0
- package/src/region.js +554 -0
- package/src/renderer.js +612 -0
- package/src/scene.js +963 -0
- package/src/sceneExporter.js +32 -0
- package/src/sceneLoader.js +842 -0
- package/src/texture/texture.js +57 -0
- package/src/texture/textureArray.js +85 -0
- package/src/three/GLTFExporter.js +2448 -0
- package/src/three/Geometry.js +2084 -0
- package/src/three/Loader.js +344 -0
- package/src/three/Points.js +223 -0
- package/src/three/line/Line.js +293 -0
- package/src/three/line/LineSegments.js +65 -0
- package/src/three-js-csg.js +564 -0
- package/src/utilities.js +321 -0
- package/src/videoHandler.js +92 -0
- package/src/workers/geometryCSG.worker.js +73 -0
- package/src/workers/geometryCSGInternal.js +58 -0
- package/src/zinc.js +38 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const THREE = require('three');
|
|
2
|
+
const ThreeBSP = require('./three-js-csg')(THREE);
|
|
3
|
+
const Geometry = require('./primitives/geometry').Geometry;
|
|
4
|
+
const work = require('webworkify-webpack');
|
|
5
|
+
const Promise = require('promise-polyfill').default;
|
|
6
|
+
//const work = undefined;
|
|
7
|
+
const JSONLoader = THREE.BufferGeometryLoader;
|
|
8
|
+
|
|
9
|
+
const GeometryCSG = function (hostIn) {
|
|
10
|
+
//ZincGeoemtry of the main geometry
|
|
11
|
+
let host = undefined;
|
|
12
|
+
if (hostIn && hostIn.isGeometry)
|
|
13
|
+
host = hostIn;
|
|
14
|
+
let core = undefined;
|
|
15
|
+
let worker = undefined;
|
|
16
|
+
let onProgress = false;
|
|
17
|
+
let myResolve = undefined;
|
|
18
|
+
|
|
19
|
+
var createGeometryFromJSON = json => {
|
|
20
|
+
const material = host.morph.material.clone();
|
|
21
|
+
material.morphTargets = false;
|
|
22
|
+
const newGeometry = new Geometry();
|
|
23
|
+
const JSONParser = new JSONLoader();
|
|
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;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var workerEventHandler = ev => {
|
|
33
|
+
switch (ev.data.action) {
|
|
34
|
+
case 'message':
|
|
35
|
+
console.log(ev.data.message);
|
|
36
|
+
break;
|
|
37
|
+
case 'result':
|
|
38
|
+
const csg = new GeometryCSG(createGeometryFromJSON(ev.data.object));
|
|
39
|
+
if (myResolve)
|
|
40
|
+
myResolve(csg);
|
|
41
|
+
myResolve = undefined;
|
|
42
|
+
onProgress = false;
|
|
43
|
+
break;
|
|
44
|
+
default:
|
|
45
|
+
throw 'Cannot handle specified action.';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var initialise = hostIn => {
|
|
50
|
+
if (work !== undefined) {
|
|
51
|
+
worker = work(require.resolve('./workers/geometryCSG.worker.js'));
|
|
52
|
+
}
|
|
53
|
+
if (!worker) {
|
|
54
|
+
core = new (require('./workers/geometryCSGInternal').GeometryCSGInternal)(hostIn);
|
|
55
|
+
} else {
|
|
56
|
+
if (hostIn && hostIn.isGeometry) {
|
|
57
|
+
let mesh = hostIn.morph;
|
|
58
|
+
let json = mesh.geometry.clone().applyMatrix(mesh.matrix).toJSON();
|
|
59
|
+
worker.addEventListener('message', function (ev) {
|
|
60
|
+
workerEventHandler(ev);
|
|
61
|
+
});
|
|
62
|
+
worker.postMessage({action: "initialise", object: json});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.getHostGeometry = () => {
|
|
68
|
+
const tempCSG = new ThreeBSP(host.morph);
|
|
69
|
+
return new createZincGeometry(tempCSG);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
this.getGeometry = () => host;
|
|
73
|
+
|
|
74
|
+
const createZincGeometry = csgMesh => {
|
|
75
|
+
const material = host.morph.material.clone();
|
|
76
|
+
material.morphTargets = false;
|
|
77
|
+
const newMesh = csgMesh.toMesh(material);
|
|
78
|
+
const newGeometry = new Geometry();
|
|
79
|
+
newGeometry.geometry = newMesh.geometry;
|
|
80
|
+
newGeometry.morph = newMesh;
|
|
81
|
+
newGeometry.morph.userData = newGeometry;
|
|
82
|
+
return newGeometry;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.setCSG = CSG => {
|
|
86
|
+
core.setCSG(CSG);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const sendToWork = (guestGeometry, action, resolve, reject) => {
|
|
90
|
+
if (!onProgress) {
|
|
91
|
+
let mesh = guestGeometry.morph;
|
|
92
|
+
const json = mesh.geometry.clone().applyMatrix(mesh.matrix).toJSON();
|
|
93
|
+
myResolve = resolve;
|
|
94
|
+
onProgress = true;
|
|
95
|
+
worker.postMessage({action: action, object: json});
|
|
96
|
+
} else {
|
|
97
|
+
reject("On progress");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.intersect = guestGeometry => {
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
if (worker) {
|
|
104
|
+
sendToWork(guestGeometry, "intersect", resolve, reject);
|
|
105
|
+
} else {
|
|
106
|
+
const result = core.intersect(guestGeometry);
|
|
107
|
+
const newCSG = new GeometryCSG(createZincGeometry(result));
|
|
108
|
+
newCSG.setCSG(result);
|
|
109
|
+
resolve(newCSG);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
this.subtract = guestGeometry => {
|
|
115
|
+
return new Promise((resolve, reject) => {
|
|
116
|
+
if (worker) {
|
|
117
|
+
sendToWork(guestGeometry, "intersect", resolve, reject);
|
|
118
|
+
} else {
|
|
119
|
+
const result = core.subtract(guestGeometry);
|
|
120
|
+
const newCSG = new GeometryCSG(createZincGeometry(result));
|
|
121
|
+
newCSG.setCSG(result);
|
|
122
|
+
resolve(newCSG);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
this.union = guestGeometry => {
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
if (worker) {
|
|
130
|
+
sendToWork(guestGeometry, "intersect", resolve, reject);
|
|
131
|
+
} else {
|
|
132
|
+
const result = core.union(guestGeometry);
|
|
133
|
+
const newCSG = new GeometryCSG(createZincGeometry(result));
|
|
134
|
+
newCSG.setCSG(result);
|
|
135
|
+
resolve(newCSG);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.terminateWorker = () => {
|
|
141
|
+
if (worker)
|
|
142
|
+
worker.terminate();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
initialise(hostIn);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
exports.GeometryCSG = GeometryCSG;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const THREE = require('three');
|
|
2
|
+
const ThreeBSP = require('./three-js-csg')(THREE);
|
|
3
|
+
const Glyphset = require('./primitives/glyphset').Glyphset;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provides an object which takes in a glyphset, convert it into a CSG and further
|
|
7
|
+
* action such as intersect with another geometry may be performed.
|
|
8
|
+
*
|
|
9
|
+
* @class
|
|
10
|
+
* @author Alan Wu
|
|
11
|
+
* @return {GlyphsetCSG}
|
|
12
|
+
*/
|
|
13
|
+
const GlyphsetCSG = function (hostIn) {
|
|
14
|
+
let host = undefined;
|
|
15
|
+
if (hostIn && hostIn.isGlyphset)
|
|
16
|
+
host = hostIn;
|
|
17
|
+
const hostCSGs = new Array();
|
|
18
|
+
const currentIntersect = undefined;
|
|
19
|
+
|
|
20
|
+
this.setGlyphset = hostIn => {
|
|
21
|
+
if (hostIn && hostIn.isGlyphset)
|
|
22
|
+
host = hostIn;
|
|
23
|
+
hostCSG = undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
this.getGlyphset = () => {
|
|
27
|
+
return host;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const prepareCSGForGlyphs = () => {
|
|
31
|
+
return glyph => {
|
|
32
|
+
const mesh = glyph.getMesh();
|
|
33
|
+
const label = glyph.getLabel();
|
|
34
|
+
if (mesh) {
|
|
35
|
+
const csg = new ThreeBSP(mesh.geometry.clone().applyMatrix(mesh.matrix));
|
|
36
|
+
const store = [];
|
|
37
|
+
store.csg = csg;
|
|
38
|
+
store.label = label;
|
|
39
|
+
if (mesh.material)
|
|
40
|
+
store.material = mesh.material.clone();
|
|
41
|
+
hostCSGs.push(store);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const prepareCSG = guestGeometry => {
|
|
47
|
+
if (host && guestGeometry && guestGeometry.morph) {
|
|
48
|
+
if (hostCSGs.length == 0) {
|
|
49
|
+
host.forEachGlyph(prepareCSGForGlyphs());
|
|
50
|
+
}
|
|
51
|
+
const guestCSG = new ThreeBSP(guestGeometry.morph);
|
|
52
|
+
return guestCSG;
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
this.intersect = guestGeometry => {
|
|
58
|
+
const guestCSG = prepareCSG(guestGeometry);
|
|
59
|
+
if ((hostCSGs.length > 0) && guestCSG) {
|
|
60
|
+
const glyphset = new (require('./primitives/glyphset').Glyphset)();
|
|
61
|
+
for (let i = 0; i < hostCSGs.length; i++) {
|
|
62
|
+
const hostCSG = hostCSGs[i];
|
|
63
|
+
const intersect = hostCSG.csg.intersect(guestCSG);
|
|
64
|
+
const mesh = intersect.toMesh();
|
|
65
|
+
if (mesh && mesh.geometry && (mesh.geometry.vertices.length > 0)) {
|
|
66
|
+
if (hostCSG.material) {
|
|
67
|
+
mesh.material = hostCSG.material;
|
|
68
|
+
mesh.material.side = THREE.DoubleSide;
|
|
69
|
+
mesh.material.clippingPlanes = null;
|
|
70
|
+
}
|
|
71
|
+
const glyph = glyphset.addMeshAsGlyph(mesh, i+1);
|
|
72
|
+
glyph.setLabel(hostCSG.label);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const newCSG = new GlyphsetCSG(glyphset);
|
|
76
|
+
return newCSG;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
exports.GlyphsetCSG = GlyphsetCSG;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const THREE = require('three');
|
|
2
|
+
|
|
3
|
+
const GLTFLoader = require('three/examples/jsm/loaders/GLTFLoader').GLTFLoader;
|
|
4
|
+
|
|
5
|
+
const GLTFToZincJSLoader = function () {
|
|
6
|
+
|
|
7
|
+
const _this = this;
|
|
8
|
+
|
|
9
|
+
this.parseGLTFObjects = (object, region, depth, finishCallback) => {
|
|
10
|
+
let childRegion = region;
|
|
11
|
+
if (depth !== 0) {
|
|
12
|
+
if (object.type === "Object3D") {
|
|
13
|
+
if (object.name !== "") {
|
|
14
|
+
if (region)
|
|
15
|
+
childRegion = region.findOrCreateChildFromPath(object.name);
|
|
16
|
+
if (childRegion) {
|
|
17
|
+
const group = childRegion.getGroup();
|
|
18
|
+
group.position.copy(object.position);
|
|
19
|
+
group.rotation.copy(object.rotation);
|
|
20
|
+
group.quaternion.copy(object.quaternion);
|
|
21
|
+
group.matrixAutoUpdate = true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
let zincGeometry = undefined;
|
|
26
|
+
if (object.type === "Mesh") {
|
|
27
|
+
zincGeometry = new (require('../primitives/geometry').Geometry)();
|
|
28
|
+
} else if (object.type === "LineSegments") {
|
|
29
|
+
zincGeometry = new (require('../primitives/lines').Lines)();
|
|
30
|
+
} else if (object.type === "Points") {
|
|
31
|
+
zincGeometry = new (require('../primitives/pointset').Pointset)();
|
|
32
|
+
}
|
|
33
|
+
if (zincGeometry) {
|
|
34
|
+
let localTimeEnabled = false;
|
|
35
|
+
let localMorphColour = false;
|
|
36
|
+
if (object.geometry && object.geometry.morphAttributes) {
|
|
37
|
+
localTimeEnabled = object.geometry.morphAttributes.position ? true : false;
|
|
38
|
+
localMorphColour = object.geometry.morphAttributes.color ? true : false;
|
|
39
|
+
}
|
|
40
|
+
zincGeometry.setMesh(object.clone(), localTimeEnabled, localMorphColour);
|
|
41
|
+
region.addZincObject(zincGeometry);
|
|
42
|
+
zincGeometry.groupName = zincGeometry.morph.name;
|
|
43
|
+
zincGeometry.morph.matrixAutoUpdate = true;
|
|
44
|
+
if (finishCallback != undefined && (typeof finishCallback == 'function'))
|
|
45
|
+
finishCallback(zincGeometry);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
depth++;
|
|
50
|
+
object.children.forEach( child => {
|
|
51
|
+
_this.parseGLTFObjects(child, childRegion, depth, finishCallback);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this.setCamera = scene => {
|
|
56
|
+
scene.viewAll();
|
|
57
|
+
const cameraControls = scene.getZincCameraControls();
|
|
58
|
+
const viewport = cameraControls.getCurrentViewport();
|
|
59
|
+
cameraControls.addViewport('default', viewport);
|
|
60
|
+
cameraControls.setDefaultViewport('default');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Load GLTF into this scene object.
|
|
65
|
+
*
|
|
66
|
+
* @param {String} url - URL to the GLTF file
|
|
67
|
+
* @param {Function} finishCallback - Callback function which will be called
|
|
68
|
+
* once the glyphset is succssfully load in.
|
|
69
|
+
*/
|
|
70
|
+
this.load = (scene, region, url, finishCallback, allCompletedCallback, options) => {
|
|
71
|
+
const path = url.substring(0, url.lastIndexOf("/") + 1);
|
|
72
|
+
const filename = url.substring(url.lastIndexOf("/") + 1, url.length);
|
|
73
|
+
const loader = new GLTFLoader().setPath(path);
|
|
74
|
+
|
|
75
|
+
loader.load( filename, function ( gltf ) {
|
|
76
|
+
console.log(gltf)
|
|
77
|
+
_this.parseGLTFObjects(gltf.scene, region, 0, finishCallback);
|
|
78
|
+
_this.setCamera(scene);
|
|
79
|
+
if (allCompletedCallback != undefined && (typeof allCompletedCallback == 'function'))
|
|
80
|
+
allCompletedCallback();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.GLTFToZincJSLoader = GLTFToZincJSLoader;
|