Skip to content

Commit 4be8c40

Browse files
committed
Use THREE.LineSegments to draw TH2 contour in 3D
1 parent 186bbce commit 4be8c40

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

scripts/JSRoot3DPainter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@
705705

706706
JSROOT.Painter.drawPolyLine3D = drawPolyLine3D;
707707

708+
JSROOT.Painter.Create3DLineMaterial = Create3DLineMaterial;
709+
708710

709711
return JSROOT;
710712

scripts/JSRootPainter.hist3d.js

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,14 +1558,11 @@
15581558
JSROOT.TH2Painter.prototype.DrawContour3D = function(realz) {
15591559
// for contour plots one requires handle with full range
15601560
var main = this.main_painter(),
1561-
handle = this.PrepareColorDraw({rounding: false, use3d: true, extra: 100, middle: 0.0 });
1562-
1563-
// get levels
1564-
var histo = this.GetObject(),
1561+
handle = this.PrepareColorDraw({rounding: false, use3d: true, extra: 100, middle: 0.0 }),
1562+
histo = this.GetObject(), // get levels
15651563
levels = this.GetContour(), // init contour if not exists
15661564
palette = this.GetPalette(),
1567-
painter = this,
1568-
layerz = 2*main.size_z3d;
1565+
layerz = 2*main.size_z3d, pnts = [];
15691566

15701567
this.BuildContour(handle, levels, palette,
15711568
function(colindx,xp,yp,iminus,iplus,ilevel) {
@@ -1577,23 +1574,15 @@
15771574
if ((layerz < 0) || (layerz > 2*main.size_z3d)) return;
15781575
}
15791576

1580-
var linepos = new Float32Array((iplus-iminus+1)*3), indx = 0;
1581-
for (var i=iminus;i<=iplus;++i) {
1582-
linepos[indx] = xp[i];
1583-
linepos[indx+1] = yp[i];
1584-
linepos[indx+2] = layerz;
1585-
indx+=3;
1577+
for (var i=iminus;i<iplus;++i) {
1578+
pnts.push(xp[i], yp[i], layerz);
1579+
pnts.push(xp[i+1], yp[i+1], layerz);
15861580
}
1587-
1588-
var geometry = new THREE.BufferGeometry();
1589-
geometry.addAttribute( 'position', new THREE.BufferAttribute( linepos, 3 ) );
1590-
1591-
var material = new THREE.LineBasicMaterial({ color: new THREE.Color(main.get_color(histo.fLineColor)) });
1592-
1593-
var line = new THREE.Line(geometry, material);
1594-
main.toplevel.add(line);
15951581
}
15961582
);
1583+
1584+
var lines = JSROOT.Painter.createLineSegments(pnts, JSROOT.Painter.Create3DLineMaterial(this, histo));
1585+
main.toplevel.add(lines);
15971586
}
15981587

15991588
JSROOT.TH2Painter.prototype.DrawSurf = function() {

0 commit comments

Comments
 (0)