zincjs 1.8.4 → 1.9.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/build/zinc.frontend.js +1 -1
- package/build/zinc.js +17 -13
- package/build/zinc.js.map +1 -1
- package/package.json +1 -1
- package/src/controls.js +29 -6
- package/src/primitives/label.js +2 -1
- package/src/primitives/lines2.js +1 -3
- package/src/primitives/pointset.js +80 -10
package/package.json
CHANGED
package/src/controls.js
CHANGED
|
@@ -1508,6 +1508,7 @@ const RayCaster = function (sceneIn, hostSceneIn, callbackFunctionIn, hoverCallb
|
|
|
1508
1508
|
let timeDiff = 0;
|
|
1509
1509
|
let pickedObjects = new Array();
|
|
1510
1510
|
let lastPosition = { zincCamera: undefined, x: -1 ,y: -1};
|
|
1511
|
+
let pickableObjects = undefined;
|
|
1511
1512
|
|
|
1512
1513
|
this.enable = () => {
|
|
1513
1514
|
enable = true;
|
|
@@ -1517,22 +1518,44 @@ const RayCaster = function (sceneIn, hostSceneIn, callbackFunctionIn, hoverCallb
|
|
|
1517
1518
|
enable = false;
|
|
1518
1519
|
}
|
|
1519
1520
|
|
|
1520
|
-
|
|
1521
|
-
zincCamera.getNDCFromDocumentCoords(x, y, mouse);
|
|
1521
|
+
this.getIntersectsObject = (zincCamera) => {
|
|
1522
1522
|
if (hostScene !== scene) {
|
|
1523
1523
|
const threejsScene = scene.getThreeJSScene();
|
|
1524
1524
|
renderer.render(threejsScene, zincCamera.cameraObject);
|
|
1525
1525
|
}
|
|
1526
|
-
|
|
1527
|
-
let objects = scene.getPickableThreeJSObjects();
|
|
1526
|
+
let objects = pickableObjects ? pickableObjects : scene.getPickableThreeJSObjects();
|
|
1528
1527
|
//Reset pickedObjects array
|
|
1529
1528
|
pickedObjects.length = 0;
|
|
1530
1529
|
return raycaster.intersectObjects( objects, true, pickedObjects );
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
this.setPickableObjects = (zincObjects) => {
|
|
1533
|
+
if (zincObjects === undefined) {
|
|
1534
|
+
pickableObjects = undefined;
|
|
1535
|
+
} else {
|
|
1536
|
+
pickableObjects = [];
|
|
1537
|
+
zincObjects.forEach(zincObject => {
|
|
1538
|
+
if (zincObject.getGroup() && zincObject.getGroup().visible) {
|
|
1539
|
+
pickableObjects.push(zincObject.getGroup());
|
|
1540
|
+
}
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
this.getIntersectsObjectWithOrigin = (zincCamera, origin, direction) => {
|
|
1546
|
+
raycaster.set(origin, direction);
|
|
1547
|
+
return this.getIntersectsObject(zincCamera);
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
this.getIntersectsObjectWithCamera = (zincCamera, x, y) => {
|
|
1551
|
+
zincCamera.getNDCFromDocumentCoords(x, y, mouse);
|
|
1552
|
+
raycaster.setFromCamera(mouse, zincCamera.cameraObject);
|
|
1553
|
+
return this.getIntersectsObject(zincCamera);
|
|
1531
1554
|
};
|
|
1532
1555
|
|
|
1533
1556
|
this.pick = (zincCamera, x, y) => {
|
|
1534
1557
|
if (enabled && renderer && scene && zincCamera && callbackFunction) {
|
|
1535
|
-
|
|
1558
|
+
this.getIntersectsObjectWithCamera(zincCamera, x, y);
|
|
1536
1559
|
const length = pickedObjects.length;
|
|
1537
1560
|
for (let i = 0; i < length; i++) {
|
|
1538
1561
|
let zincObject = pickedObjects[i].object ? pickedObjects[i].object.userData : undefined;
|
|
@@ -1548,7 +1571,7 @@ const RayCaster = function (sceneIn, hostSceneIn, callbackFunctionIn, hoverCallb
|
|
|
1548
1571
|
|
|
1549
1572
|
let hovered = (zincCamera, x, y) => {
|
|
1550
1573
|
if (enabled && renderer && scene && zincCamera && hoverCallbackFunction) {
|
|
1551
|
-
|
|
1574
|
+
this.getIntersectsObjectWithCamera(zincCamera, x, y);
|
|
1552
1575
|
lastHoveredDate.setTime(Date.now());
|
|
1553
1576
|
if (pickedObjects.length === 0) {
|
|
1554
1577
|
//skip hovered callback if the previous one is empty
|
package/src/primitives/label.js
CHANGED
package/src/primitives/lines2.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const THREE = require('three');
|
|
2
|
-
const createBufferGeometry = require('../utilities').createBufferGeometry;
|
|
3
2
|
const toBufferGeometry = require('../utilities').toBufferGeometry;
|
|
4
3
|
const LineSegments2 = require("../three/line/LineSegments2").LineSegments2;
|
|
5
4
|
const LineMaterial = require("../three/line/LineMaterial").LineMaterial;
|
|
@@ -115,7 +114,7 @@ const Lines2 = function () {
|
|
|
115
114
|
/**
|
|
116
115
|
* Edit Vertice in index.
|
|
117
116
|
*/
|
|
118
|
-
this.
|
|
117
|
+
this.editVertices = function(coords, i) {
|
|
119
118
|
if (coords && coords.length) {
|
|
120
119
|
let mesh = this.getMorph();
|
|
121
120
|
const maxIndex = i + coords.length - 1;
|
|
@@ -142,7 +141,6 @@ const Lines2 = function () {
|
|
|
142
141
|
return positions;
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
|
|
146
144
|
/**
|
|
147
145
|
* Add new lines to existing lines if it exists, otherwise
|
|
148
146
|
* create a new one and add to it.
|
|
@@ -2,6 +2,7 @@ const THREE = require('three');
|
|
|
2
2
|
const Points = require('../three/Points').Points;
|
|
3
3
|
const toBufferGeometry = require('../utilities').toBufferGeometry;
|
|
4
4
|
const getCircularTexture = require('../utilities').getCircularTexture;
|
|
5
|
+
const Label = require('./label').Label;
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Provides an object which stores points and provides method which controls its position.
|
|
@@ -15,6 +16,7 @@ const getCircularTexture = require('../utilities').getCircularTexture;
|
|
|
15
16
|
const Pointset = function () {
|
|
16
17
|
(require('./zincObject').ZincObject).call(this);
|
|
17
18
|
this.isPointset = true;
|
|
19
|
+
const labelSets = [];
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Create the pointsets using geometry and material.
|
|
@@ -38,16 +40,33 @@ const Pointset = function () {
|
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
const addLabel = (index, coord, labelText, colourHex) => {
|
|
44
|
+
if (labelText) {
|
|
45
|
+
const colour = new THREE.Color(colourHex);
|
|
46
|
+
const label = new Label(labelText, colour);
|
|
47
|
+
label.setPosition(coord[0], coord[1], coord[2]);
|
|
48
|
+
const sprite = label.getSprite();
|
|
49
|
+
sprite.material.sizeAttenuation = false;
|
|
50
|
+
sprite.material.alphaTest = 0.5;
|
|
51
|
+
sprite.material.transparent = true;
|
|
52
|
+
sprite.material.depthWrite = false;
|
|
53
|
+
sprite.material.depthTest = false;
|
|
54
|
+
this.group.add(sprite);
|
|
55
|
+
labelSets[index] = label;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
41
59
|
/**
|
|
42
60
|
* Add points to existing mesh if it exists, otherwise
|
|
43
61
|
* create a new one and add to it.
|
|
44
62
|
* @param {Array} coords -An array of three components coordinates.
|
|
45
|
-
* @param {Array} labels - An array of strings, these are only added
|
|
63
|
+
* @param {Array|String} labels - An array of strings, these are only added
|
|
46
64
|
* if the number of coords equals to the number labels provided.
|
|
47
65
|
* @param {Number} colour - A hex value of the colour for the points
|
|
48
66
|
*/
|
|
49
67
|
this.addPoints = (coords, labels, colour) => {
|
|
50
68
|
if (coords && coords.length > 0) {
|
|
69
|
+
let current = this.drawRange - 1;
|
|
51
70
|
const geometry = this.addVertices(coords);
|
|
52
71
|
let mesh = this.getMorph();
|
|
53
72
|
if (!mesh) {
|
|
@@ -57,6 +76,16 @@ const Pointset = function () {
|
|
|
57
76
|
geometry.colorsNeedUpdate = true;
|
|
58
77
|
this.createMesh(geometry, material, options);
|
|
59
78
|
}
|
|
79
|
+
let end = current + coords.length;
|
|
80
|
+
let index = 0;
|
|
81
|
+
if ((Array.isArray(labels) && labels.length === coords.length) ||
|
|
82
|
+
(typeof labels === "string")) {
|
|
83
|
+
for (current; current + index < end;) {
|
|
84
|
+
const labelText = typeof labels === "string" ? labels : labels[index];
|
|
85
|
+
addLabel(index, coords[index], labelText, colour);
|
|
86
|
+
index++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
60
89
|
if (this.region) this.region.pickableUpdateRequired = true;
|
|
61
90
|
}
|
|
62
91
|
}
|
|
@@ -86,18 +115,59 @@ const Pointset = function () {
|
|
|
86
115
|
}
|
|
87
116
|
}
|
|
88
117
|
|
|
89
|
-
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
118
|
+
/**
|
|
119
|
+
* Get vertices at index
|
|
120
|
+
*/
|
|
121
|
+
this.getVerticesByIndex = function(index) {
|
|
122
|
+
if (index >= 0 && this.drawRange > index) {
|
|
123
|
+
const positionAttribute = this.getMorph().geometry.getAttribute( 'position' );
|
|
124
|
+
return [
|
|
125
|
+
positionAttribute.getX(index),
|
|
126
|
+
positionAttribute.getY(index),
|
|
127
|
+
positionAttribute.getZ(index)
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Edit Vertice in index.
|
|
94
135
|
*/
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
136
|
+
this.editVertices = function(coords, i) {
|
|
137
|
+
if (coords && coords.length) {
|
|
138
|
+
let mesh = this.getMorph();
|
|
139
|
+
const maxIndex = i + coords.length - 1;
|
|
140
|
+
if (!mesh || 0 > i || maxIndex >= this.drawRange) {
|
|
141
|
+
return;
|
|
142
|
+
} else {
|
|
143
|
+
const positionAttribute = mesh.geometry.getAttribute( 'position' );
|
|
144
|
+
let index = i;
|
|
145
|
+
coords.forEach(coord => {
|
|
146
|
+
const label = labelSets[index];
|
|
147
|
+
if (label) {
|
|
148
|
+
label.setPosition(coord[0], coord[1], coord[2]);
|
|
149
|
+
}
|
|
150
|
+
positionAttribute.setXYZ(index++, coord[0], coord[1], coord[2]);
|
|
151
|
+
|
|
152
|
+
});
|
|
153
|
+
positionAttribute.needsUpdate = true;
|
|
154
|
+
this.boundingBoxUpdateRequired = true;
|
|
98
155
|
}
|
|
99
|
-
Pointset.prototype.render.call(this, delta, playAnimation, cameraControls, options);
|
|
100
156
|
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Turn size attenuation on/off based on the flag.
|
|
161
|
+
*
|
|
162
|
+
* @param {Boolean} flag - Determin either size attenuation
|
|
163
|
+
* should be on or off.
|
|
164
|
+
*/
|
|
165
|
+
this.render = (delta, playAnimation, cameraControls, options) => {
|
|
166
|
+
if (this.morph && cameraControls) {
|
|
167
|
+
this.morph.sizePerPixel = cameraControls.pixelHeight;
|
|
168
|
+
}
|
|
169
|
+
Pointset.prototype.render.call(this, delta, playAnimation, cameraControls, options);
|
|
170
|
+
}
|
|
101
171
|
}
|
|
102
172
|
|
|
103
173
|
Pointset.prototype = Object.create((require('./zincObject').ZincObject).prototype);
|