Skip to content

Commit 20d171d

Browse files
committed
Let superimpose TPolyLine3D and TPolyMarker3D with TGeo drawing
1 parent 3d5be31 commit 20d171d

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

changes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
2. Enable geometry clipping in node.js
66
3. Upgrade node.js packages
77
4. Let draw TGeo object inside TCanvas
8+
5. Let superimpose TPolyLine3D and TPolyMarker3D with TGeo drawing
89

910

1011
## Changes in 6.3.3

scripts/JSRoot.base3d.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,9 +1409,16 @@ JSROOT.define(['d3', 'threejs_jsroot', 'painter'], (d3, THREE, jsrp) => {
14091409
let line = this.getObject(),
14101410
main = this.getFramePainter();
14111411

1412-
if (!main || !main.mode3d || !main.toplevel || !line)
1412+
if (!main || !main.mode3d || !line)
14131413
return null;
14141414

1415+
if (!main.toplevel) {
1416+
let main = this.getMainPainter();
1417+
if (main && typeof main.drawExtras == 'function')
1418+
return main.drawExtras(line);
1419+
return null;
1420+
}
1421+
14151422
let fN, fP, pnts = [];
14161423

14171424
if (line._blob && (line._blob.length==4)) {

scripts/JSRoot.geom.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,9 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
28072807
} else if (obj._typename === 'TGeoTrack') {
28082808
if (!add_objects || this.addExtra(obj, itemname))
28092809
promise = this.drawGeoTrack(obj, itemname);
2810+
} else if (obj._typename === 'TPolyLine3D') {
2811+
if (!add_objects || this.addExtra(obj, itemname))
2812+
promise = this.drawPolyLine(obj, itemname);
28102813
} else if ((obj._typename === 'TEveTrack') || (obj._typename === 'ROOT::Experimental::TEveTrack')) {
28112814
if (!add_objects || this.addExtra(obj, itemname))
28122815
promise = this.drawEveTrack(obj, itemname);
@@ -2920,6 +2923,56 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
29202923
return true;
29212924
}
29222925

2926+
/** @summary drawing TPolyLine3D */
2927+
TGeoPainter.prototype.drawPolyLine = function(line, itemname) {
2928+
if (!line) return false;
2929+
2930+
let track_width = line.fLineWidth || 1,
2931+
track_color = jsrp.getColor(line.fLineColor) || "#ff00ff";
2932+
2933+
if (JSROOT.browser.isWin) track_width = 1; // not supported on windows
2934+
2935+
let fN, fP;
2936+
2937+
if (line._blob && (line._blob.length == 4)) {
2938+
// workaround for custom streamer for JSON, should be resolved
2939+
fN = line._blob[1];
2940+
fP = line._blob[2];
2941+
} else {
2942+
fN = line.fN;
2943+
fP = line.fP;
2944+
}
2945+
2946+
let npoints = fN,
2947+
buf = new Float32Array((npoints-1)*6),
2948+
pos = 0, projv = this.ctrl.projectPos,
2949+
projx = (this.ctrl.project === "x"),
2950+
projy = (this.ctrl.project === "y"),
2951+
projz = (this.ctrl.project === "z");
2952+
2953+
for (let k = 0; k < npoints-1; ++k) {
2954+
buf[pos] = projx ? projv : fP[k*3];
2955+
buf[pos+1] = projy ? projv : fP[k*3+1];
2956+
buf[pos+2] = projz ? projv : fP[k*3+2];
2957+
buf[pos+3] = projx ? projv : fP[k*3+3];
2958+
buf[pos+4] = projy ? projv : fP[k*3+4];
2959+
buf[pos+5] = projz ? projv : fP[k*3+5];
2960+
pos+=6;
2961+
}
2962+
2963+
let lineMaterial = new THREE.LineBasicMaterial({ color: track_color, linewidth: track_width }),
2964+
line3d = jsrp.createLineSegments(buf, lineMaterial);
2965+
2966+
line3d.renderOrder = 1000000; // to bring line to the front
2967+
line3d.geo_name = itemname;
2968+
line3d.geo_object = line;
2969+
line3d.hightlightWidthScale = 2;
2970+
2971+
this.addToExtrasContainer(line3d);
2972+
2973+
return true;
2974+
}
2975+
29232976
/** @summary Drawing TEveTrack */
29242977
TGeoPainter.prototype.drawEveTrack = function(track, itemname) {
29252978
if (!track || (track.fN <= 0)) return false;

0 commit comments

Comments
 (0)