-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGL.controller.js
287 lines (243 loc) · 10.7 KB
/
GL.controller.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
function EveJetConeGeometry(vertices)
{
THREE.BufferGeometry.call( this );
this.addAttribute( 'position', new THREE.BufferAttribue( vertices, 3 ) );
var N = vertices.length / 3;
var idcs = [];
for (var i = 1; i < N - 1; ++i)
{
idcs.push( i ); idcs.push( 0 ); idcs.push( i + 1 );
}
this.setIndex( idcs );
}
EveJetConeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
EveJetConeGeometry.prototype.constructor = EveJetConeGeometry;
*/
sap.ui.define([
'sap/ui/jsroot/GuiPanelController',
'sap/ui/model/json/JSONModel',
"sap/ui/core/ResizeHandler"
], function (GuiPanelController, JSONModel, ResizeHandler) {
"use strict";
return GuiPanelController.extend("eve.GL", {
// function called from GuiPanelController
onPanelInit : function() {
console.log("onPanelInit id = ", this.getView().getId());
},
onInit : function() {
console.log("onInit id = ", this.getView().getId());
ResizeHandler.register(this.getView(), this.onResize.bind(this));
this.fast_event = [];
},
// function called from GuiPanelController
onPanelExit : function() {
},
geometry:function(data) {
var pthis = this;
var id = this.getView().getId() + "--panelGL";
this.viewType = this.getView().data("type");
JSROOT.draw(id, data, "", function(painter) {
console.log('GL painter initialized', painter);
pthis.geo_painter = painter;
if (pthis.viewType != "3D") {
var a = 651;
painter._camera = new THREE.OrthographicCamera(a, -a, a, -a, a, -a);
painter._camera.position.x = 0;
painter._camera.position.y = 0;
painter._camera.position.z = +200;
painter._controls = JSROOT.Painter.CreateOrbitControl(painter, painter._camera, painter._scene, painter._renderer, painter._lookat);
}
if (pthis.fast_event) pthis.drawExtra();
pthis.geo_painter.Render3D();
});
},
event: function(data) {
/*
if (this.drawExtra(data)) {
this.geo_painter.Render3D();
}*/
},
endChanges: function(val) {
this.needRedraw = true;
},
drawExtra : function(el) {
if (!this.geo_painter) {
// no painter - no draw of event
console.log("fast event geo not initialized append element", this.getView().getId())
this.fast_event.push(el);
return false;
}
else {
// this.geo_painter.clearExtras(); // remove old three.js container with tracks and hits
var len = this.fast_event.length;
for(var i = 0; i < len; i++){
var x = this.fast_event[i];
console.log("draw extra ... catchup fast event ", x, this.getView().getId());
var rnrData = x[this.viewType];
if (rnrData) {
// console.log("calling rendere ",rnrData.rnrFunc, rnrData );
var mesh = this[rnrData.rnrFunc](x, rnrData);
this.geo_painter.getExtrasContainer().add(mesh);
}
}
this.fast_event = [];
if (el) {
console.log("draw extra SINGLE");
var rnrData = el[this.viewType];
if (rnrData) {
// console.log("calling rendere ",rnrData.rnrFunc, rnrData );
var mesh = this[rnrData.rnrFunc](el, rnrData);
this.geo_painter.getExtrasContainer().add(mesh);
}
}
if (this.needRedraw) {
this.geo_painter.Render3D();
this.needRedraw = false;
}
// console.log("PAINTER ", this.geo_painter);
return true;
}
},
makeHit: function(hit, rnrData) {
console.log("drawHit ", hit, "this type ", this.viewType);
// console.log("marker size ", hit.fMarkerSize)
var hit_size = 8*rnrData.fMarkerSize,
size = rnrData.vtxBuff.length/3,
pnts = new JSROOT.Painter.PointsCreator(size, true, hit_size);
for (var i=0;i<size;i++) {
pnts.AddPoint(rnrData.vtxBuff[i*3],rnrData.vtxBuff[i*3+1],rnrData.vtxBuff[i*3+2]);
// console.log("add vertex ", rnrData.vtxBuff[i*3],rnrData.vtxBuff[i*3+1],rnrData.vtxBuff[i*3+2]);
}
var mesh = pnts.CreatePoints(JSROOT.Painter.root_colors[rnrData.fMarkerColor] );
mesh.highlightMarkerSize = hit_size*3;
mesh.normalMarkerSize = hit_size;
mesh.geo_name = hit.fName;
mesh.geo_object = hit;
mesh.visible = hit.fRnrSelf;
mesh.material.sizeAttenuation = false;
return mesh;
},
makeTrack: function(track, rnrData) {
if (this.viewType == "RhoZ") {
console.log("RhoZ track ", rnrData.idxBuff);
}
var N = rnrData.vtxBuff.length/3;
var track_width = track.fLineWidth || 1,
track_color = JSROOT.Painter.root_colors[track.fLineColor] || "rgb(255,0,255)";
var buf = new Float32Array(N*3*2), pos = 0;
for (var k=0;k<(N-1);++k) {
buf[pos] = rnrData.vtxBuff[k*3];
buf[pos+1] = rnrData.vtxBuff[k*3+1];
buf[pos+2] = rnrData.vtxBuff[k*3+2];
var breakTrack = 0;
if (this.viewType == "RhoZ" && rnrData.idxBuff) {
for (var b = 0; b < rnrData.idxBuff.length; b++)
{
if ( (k+1) == rnrData.idxBuff[b]) {
breakTrack = 1;
}
}
}
if (breakTrack) {
buf[pos+3] = rnrData.vtxBuff[k*3];
buf[pos+4] = rnrData.vtxBuff[k*3+1];
buf[pos+5] = rnrData.vtxBuff[k*3+2];
}
else {
buf[pos+3] = rnrData.vtxBuff[k*3+3];
buf[pos+4] = rnrData.vtxBuff[k*3+4];
buf[pos+5] = rnrData.vtxBuff[k*3+5];
}
// console.log(" vertex ", buf[pos],buf[pos+1], buf[pos+2],buf[pos+3], buf[pos+4], buf[pos+5]);
pos+=6;
}
var lineMaterial = new THREE.LineBasicMaterial({ color: track_color, linewidth: track_width });
var geom = new THREE.BufferGeometry();
geom.addAttribute( 'position', new THREE.BufferAttribute( buf, 3 ) );
var line = new THREE.LineSegments(geom, lineMaterial);
line.geo_name = track.fName;
line.geo_object = track;
line.visible = track.fRnrSelf;
console.log("make track ", track, line.visible);
return line;
},
makeJet: function(jet, rnrData) {
console.log("make jet ", jet);
var jet_ro = new THREE.Object3D();
//var geo = new EveJetConeGeometry(jet.geoBuff);
var pos_ba = new THREE.BufferAttribute( rnrData.vtxBuff, 3 );
var N = rnrData.vtxBuff.length / 3;
var geo_body = new THREE.BufferGeometry();
geo_body.addAttribute('position', pos_ba);
{
var idcs = [];
idcs.push( 0 ); idcs.push( N - 1 ); idcs.push( 1 );
for (var i = 1; i < N - 1; ++i)
{
idcs.push( 0 ); idcs.push( i ); idcs.push( i + 1 );
}
geo_body.setIndex( idcs );
}
var geo_rim = new THREE.BufferGeometry();
geo_rim.addAttribute('position', pos_ba);
{
var idcs = [];
for (var i = 1; i < N; ++i)
{
idcs.push( i );
}
geo_rim.setIndex( idcs );
}
var geo_rays = new THREE.BufferGeometry();
geo_rays.addAttribute('position', pos_ba);
{
var idcs = [];
for (var i = 1; i < N; i += 4)
{
idcs.push( 0 ); idcs.push( i );
}
geo_rays.setIndex( idcs );
}
jet_ro.add( new THREE.Mesh (geo_body, new THREE.MeshBasicMaterial({ color: 0xff0000, transparent: true, opacity: 0.5 })) );
jet_ro.add( new THREE.LineLoop (geo_rim, new THREE.LineBasicMaterial({ linewidth: 2, color: 0x00ffff, transparent: true, opacity: 0.5 })) );
jet_ro.add( new THREE.LineSegments(geo_rays, new THREE.LineBasicMaterial({ linewidth: 0.5, color: 0x00ffff, transparent: true, opacity: 0.5 })) );
jet_ro.geo_name = jet.fName;
jet_ro.geo_object = jet;
jet_ro.visible = jet.fRnrSelf;
return jet_ro;
},
replaceElement:function(oldEl, newEl) {
console.log("GL controller replace element OLD", oldEl, oldEl.fRnrSelf);
console.log("GL controller replace element NEW", newEl, newEl.fRnrSelf);
var ec = this.geo_painter.getExtrasContainer();
var chld = ec.children;
var idx = -1;
for (var i = 0; i < chld.length; ++i) {
if (chld[i].geo_object.guid == newEl.guid)
{
idx = i;
break;
}
}
var rnrData = oldEl[this.viewType];
console.log("calling draw", newEl, newEl.fRnrSelf);
chld[idx] = this[rnrData.rnrFunc](newEl, rnrData);
this.geo_painter.Render3D();
console.log("------------- rnrstate ", this.geo_painter, newEl );
//this.geo_painter._renderer.render(this.geo_painter._scene, this.geo_painter._camera);
},
onResize: function(event) {
// use timeout
// console.log("resize painter")
if (this.resize_tmout) clearTimeout(this.resize_tmout);
this.resize_tmout = setTimeout(this.onResizeTimeout.bind(this), 300); // minimal latency
},
onResizeTimeout: function() {
delete this.resize_tmout;
if (this.geo_painter) {
this.geo_painter.CheckResize();
}
}
});
});