Skip to content

Commit 9067e87

Browse files
committed
Solve custom marker on 3d with node.js
three.js texture loader fails, therefore one need to use three.js canvas directly
1 parent abb6706 commit 9067e87

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

scripts/JSRoot.base3d.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,30 +1331,47 @@ JSROOT.define(['d3', 'threejs_jsroot', 'painter'], (d3, THREE, jsrp) => {
13311331

13321332
let material;
13331333

1334-
if ((k !== 1) || JSROOT.nodejs) {
1334+
if ((k !== 1) || (JSROOT.nodejs && !args.promise)) {
13351335
// this is plain creation of points, no texture loading, which does not work in node.js
13361336
material = new THREE.PointsMaterial({ size: (this.webgl ? 3 : 1) * this.scale * k, color: args.color });
13371337

13381338
} else {
13391339

1340-
let handler = new JSROOT.TAttMarkerHandler({ style: args.style, color: args.color, size: 8 }),
1340+
let handler = new JSROOT.TAttMarkerHandler({ style: args.style, color: args.color, size: 7 }),
13411341
w = handler.fill ? 1 : 7,
13421342
dataUrl = 'data:image/svg+xml;utf8,' +
1343-
'<svg width="70" height="70" xmlns="http://www.w3.org/2000/svg">' +
1344-
`<path d="${handler.create(35,35)}" stroke="${handler.getStrokeColor()}" stroke-width="${w}" fill="${handler.getFillColor()}"/>` +
1343+
'<svg width="64" height="64" xmlns="http://www.w3.org/2000/svg">' +
1344+
`<path d="${handler.create(32,32)}" stroke="${handler.getStrokeColor()}" stroke-width="${w}" fill="${handler.getFillColor()}"/>` +
13451345
'</svg>',
13461346
loader = new THREE.TextureLoader();
13471347

1348-
if (args.promise)
1348+
if (args.promise && !JSROOT.nodejs)
13491349
return new Promise(resolveFunc => {
13501350
loader.load(dataUrl, texture => {
1351-
material = new THREE.PointsMaterial({ size: (this.webgl ? 3 : 1) * this.scale, map: texture, transparent: true });
1351+
material = new THREE.PointsMaterial({ size: 3*this.scale, map: texture, transparent: true });
13521352
let pnts = new THREE.Points(this.geom, material);
13531353
pnts.nvertex = 1;
13541354
resolveFunc(pnts);
13551355
});
13561356
});
13571357

1358+
if (args.promise && JSROOT.nodejs) {
1359+
const { createCanvas, loadImage } = require('canvas');
1360+
1361+
return new Promise(resolveFunc => {
1362+
loadImage(dataUrl).then(img => {
1363+
const canvas = createCanvas(64, 64);
1364+
const ctx = canvas.getContext('2d');
1365+
ctx.drawImage(img, 0, 0, 64, 64);
1366+
let texture = new THREE.CanvasTexture(canvas);
1367+
texture.needsUpdate = true;
1368+
material = new THREE.PointsMaterial({ size: 3*this.scale, map: texture, transparent: true });
1369+
let pnts = new THREE.Points(this.geom, material);
1370+
pnts.nvertex = 1;
1371+
resolveFunc(pnts);
1372+
});
1373+
});
1374+
}
13581375

13591376
let texture = loader.load(dataUrl);
13601377

0 commit comments

Comments
 (0)