-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequenceFlow.js
117 lines (96 loc) · 4.67 KB
/
sequenceFlow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
AFRAME.registerGeometry('sequenceFlow', {
schema: {
points: {
default: ['0 0', '10 10']
}
},
init: function (data) {
var geometry = new THREE.Geometry();
const waypoints = data.points.map(point => {
return point.split(' ').map(coordinate => parseFloat(coordinate));
}).map(coordinate => {
return new THREE.Vector2(coordinate[0], coordinate[1]);
});
const mappedWaypoints = calculateWaypoints(waypoints);
geometry.vertices = [];
geometry.faces = [];
mappedWaypoints.forEach((waypoint, idx) => {
geometry.vertices.push(
new THREE.Vector3(waypoint[0].y, 0, -waypoint[0].x),
new THREE.Vector3(waypoint[1].y, 0, -waypoint[1].x),
new THREE.Vector3(waypoint[0].y, sequenceFlowHeight, -waypoint[0].x),
new THREE.Vector3(waypoint[1].y, sequenceFlowHeight, -waypoint[1].x),
new THREE.Vector3(waypoint[2].y, 0, -waypoint[2].x),
new THREE.Vector3(waypoint[3].y, 0, -waypoint[3].x),
);
if(idx > 0) {
const faceIndexOffset = (idx - 1) * 6;
geometry.faces.push(new THREE.Face3(4 + faceIndexOffset, 10+ faceIndexOffset, 5 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(5 + faceIndexOffset, 10+ faceIndexOffset, 11+ faceIndexOffset));
geometry.faces.push(new THREE.Face3(2 + faceIndexOffset, 3 + faceIndexOffset, 8 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(3 + faceIndexOffset, 9 + faceIndexOffset, 8 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(0 + faceIndexOffset, 2 + faceIndexOffset, 6 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(2 + faceIndexOffset, 8 + faceIndexOffset, 6 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(1 + faceIndexOffset, 7 + faceIndexOffset, 3 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(3 + faceIndexOffset, 7 + faceIndexOffset, 9 + faceIndexOffset));
addSpace(geometry.vertices[4 + faceIndexOffset], geometry.vertices[10 + faceIndexOffset], geometry.vertices[5 + faceIndexOffset]);
addSpace(geometry.vertices[5 + faceIndexOffset], geometry.vertices[10 + faceIndexOffset], geometry.vertices[11 + faceIndexOffset]);
}
});
geometry.computeFaceNormals();
geometry.computeVertexNormals();
this.geometry = geometry;
}
});
AFRAME.registerGeometry('sequenceFlowLine', {
schema: {
points: {
default: ['0 0', '10 10']
}
},
init: function (data) {
var geometry = new THREE.Geometry();
const waypoints = data.points.map(point => {
return point.split(' ').map(coordinate => parseFloat(coordinate));
}).map(coordinate => {
return new THREE.Vector2(coordinate[0], coordinate[1]);
});
const mappedWaypoints = calculateWaypoints(waypoints);
geometry.vertices = [];
geometry.faces = [];
mappedWaypoints.forEach((waypoint, idx) => {
geometry.vertices.push(
new THREE.Vector3(waypoint[0].y, 0, -waypoint[0].x),
new THREE.Vector3(waypoint[1].y, 0, -waypoint[1].x),
new THREE.Vector3(waypoint[2].y, 0, -waypoint[2].x),
new THREE.Vector3(waypoint[3].y, 0, -waypoint[3].x),
);
if(idx > 0) {
const faceIndexOffset = (idx - 1) * 4;
geometry.faces.push(new THREE.Face3(0 + faceIndexOffset, 4 + faceIndexOffset, 2 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(2 + faceIndexOffset, 4 + faceIndexOffset, 6 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(3 + faceIndexOffset, 7 + faceIndexOffset, 1 + faceIndexOffset));
geometry.faces.push(new THREE.Face3(1 + faceIndexOffset, 7 + faceIndexOffset, 5 + faceIndexOffset));
}
});
geometry.computeFaceNormals();
geometry.computeVertexNormals();
this.geometry = geometry;
}
});
function handleSequenceFlow(scene, element) {
/* <a-entity geometry="primitive: sequenceFlow; points:0 0, 0 5, 0 10, 5 10, 10 10, 10 15;" material="color: #FFFFFF"></a-entity>
<a-entity geometry="primitive: sequenceFlowLine; points:0 0, 0 5, 0 10, 5 10, 10 10, 10 15;" material="color: #333333"></a-entity>
*/
const points = element.waypoints.reduce((acc, val) => {
return acc += (val.x * globalScaleFactor) + ' ' + (val.y * globalScaleFactor) + ', ';
}, '').slice(0, -2);
const flow = document.createElement('a-entity');
flow.setAttribute('geometry', 'primitive: sequenceFlow; points:' + points + ';');
flow.setAttribute('material', 'color: #FFFFFF; side: double;');
const line = document.createElement('a-entity');
line.setAttribute('geometry', 'primitive: sequenceFlowLine; points:' + points + ';');
line.setAttribute('material', 'color: #333333');
scene.appendChild(flow);
scene.appendChild(line);
}