@@ -1310,7 +1310,7 @@ JSROOT.define(['d3', 'threejs_jsroot', 'painter'], (d3, THREE, jsrp) => {
13101310 this . pos [ this . indx ] = x ;
13111311 this . pos [ this . indx + 1 ] = y ;
13121312 this . pos [ this . indx + 2 ] = z ;
1313- this . indx += 3 ;
1313+ this . indx += 3 ;
13141314 }
13151315
13161316 /** @summary Create points */
@@ -1329,61 +1329,48 @@ JSROOT.define(['d3', 'threejs_jsroot', 'painter'], (d3, THREE, jsrp) => {
13291329 if ( args . style === 6 ) k = 0.5 ; else
13301330 if ( args . style === 7 ) k = 0.7 ;
13311331
1332- let material ;
1333-
1334- if ( ( k !== 1 ) || ( JSROOT . nodejs && ! args . promise ) ) {
1335- // this is plain creation of points, no texture loading, which does not work in node.js
1336- material = new THREE . PointsMaterial ( { size : ( this . webgl ? 3 : 1 ) * this . scale * k , color : args . color } ) ;
1337-
1338- } else {
1339-
1340- let handler = new JSROOT . TAttMarkerHandler ( { style : args . style , color : args . color , size : 7 } ) ,
1341- w = handler . fill ? 1 : 7 ,
1342- dataUrl = 'data:image/svg+xml;utf8,' +
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 ( ) } "/>` +
1345- '</svg>' ,
1346- loader = new THREE . TextureLoader ( ) ;
1347-
1348- if ( args . promise && ! JSROOT . nodejs )
1349- return new Promise ( resolveFunc => {
1350- loader . load ( dataUrl , texture => {
1351- material = new THREE . PointsMaterial ( { size : 3 * this . scale , map : texture , transparent : true } ) ;
1352- let pnts = new THREE . Points ( this . geom , material ) ;
1353- pnts . nvertex = 1 ;
1354- resolveFunc ( pnts ) ;
1355- } ) ;
1356- } ) ;
1332+ let makePoints = ( material , skip_promise ) => {
1333+ let pnts = new THREE . Points ( this . geom , material ) ;
1334+ pnts . nvertex = 1 ;
1335+ return ! args . promise || skip_promise ? pnts : Promise . resolve ( pnts ) ;
1336+ } ;
13571337
1358- if ( args . promise && JSROOT . nodejs ) {
1338+ // this is plain creation of points, no need for texture loading
1339+ if ( ( k !== 1 ) || ( JSROOT . nodejs && ! args . promise ) )
1340+ return makePoints ( new THREE . PointsMaterial ( { size : 3 * this . scale * k , color : args . color } ) ) ;
1341+
1342+ let handler = new JSROOT . TAttMarkerHandler ( { style : args . style , color : args . color , size : 7 } ) ,
1343+ w = handler . fill ? 1 : 7 ,
1344+ dataUrl = 'data:image/svg+xml;utf8,' +
1345+ '<svg width="64" height="64" xmlns="http://www.w3.org/2000/svg">' +
1346+ `<path d="${ handler . create ( 32 , 32 ) } " stroke="${ handler . getStrokeColor ( ) } " stroke-width="${ w } " fill="${ handler . getFillColor ( ) } "/>` +
1347+ '</svg>' ,
1348+ loader = new THREE . TextureLoader ( ) ;
1349+
1350+ if ( args . promise ) {
1351+ let texture_promise ;
1352+ if ( JSROOT . nodejs ) {
13591353 const { createCanvas, loadImage } = require ( 'canvas' ) ;
13601354
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- } ) ;
1355+ texture_promise = loadImage ( dataUrl ) . then ( img => {
1356+ const canvas = createCanvas ( 64 , 64 ) ;
1357+ const ctx = canvas . getContext ( '2d' ) ;
1358+ ctx . drawImage ( img , 0 , 0 , 64 , 64 ) ;
1359+ return new THREE . CanvasTexture ( canvas ) ;
1360+ } ) ;
1361+
1362+ } else {
1363+ texture_promise = new Promise ( resolveFunc => {
1364+ loader . load ( dataUrl , texture => resolveFunc ( texture ) ) ;
13731365 } ) ;
13741366 }
13751367
1376- let texture = loader . load ( dataUrl ) ;
1377-
1378- material = new THREE . PointsMaterial ( { size : ( this . webgl ? 3 : 1 ) * this . scale , map : texture , transparent : true } ) ;
1368+ return texture_promise . then ( texture => makePoints ( new THREE . PointsMaterial ( { size : 3 * this . scale , map : texture , transparent : true } ) , true ) ) ;
13791369 }
13801370
1381- let pnts = new THREE . Points ( this . geom , material ) ;
1382- pnts . nvertex = 1 ;
1383- return args . promise ? Promise . resolve ( pnts ) : pnts ;
1371+ return makePoints ( new THREE . PointsMaterial ( { size : 3 * this . scale , map : loader . load ( dataUrl ) , transparent : true } ) ) ;
13841372 }
13851373
1386-
13871374 // ==============================================================================
13881375
13891376 /** @summary Create material for 3D line
0 commit comments