@@ -2658,21 +2658,25 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
26582658 if ( ! func ) return Promise . reject ( Error ( `Function ${ funcname } not found` ) ) ;
26592659
26602660 return func ( obj , opt ) . then ( tracks => {
2661- if ( tracks ) {
2662- this . drawExtras ( tracks , "" , false ) ; // FIXME: probably tracks should be remembered??
2661+ if ( ! tracks ) return this ;
2662+
2663+ // FIXME: probably tracks should be remembered??
2664+ return this . drawExtras ( tracks , "" , false ) . then ( ( ) => {
26632665 this . updateClipping ( true ) ;
26642666 this . render3D ( 100 ) ;
2665- }
2666- return this ;
2667+ return this ;
2668+ } ) ;
26672669 } ) ;
26682670 }
26692671
2670- if ( this . drawExtras ( obj , itemname ) ) {
2671- if ( hitem ) hitem . _painter = this ; // set for the browser item back pointer
2672- this . render3D ( 100 ) ;
2673- }
2672+ return this . drawExtras ( obj , itemname ) . then ( is_any => {
2673+ if ( is_any ) {
2674+ if ( hitem ) hitem . _painter = this ; // set for the browser item back pointer
2675+ this . render3D ( 100 ) ;
2676+ }
26742677
2675- return Promise . resolve ( this ) ;
2678+ return this ;
2679+ } ) ;
26762680 }
26772681
26782682 /** @summary function called when mouse is going over the item in the browser */
@@ -2720,7 +2724,7 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
27202724 let itemname = hpainter . itemFullName ( hitem ) ,
27212725 indx = this . _extraObjects . opt . indexOf ( itemname ) ;
27222726
2723- if ( ( indx < 0 ) && hitem . _obj ) {
2727+ if ( ( indx < 0 ) && hitem . _obj ) {
27242728 indx = this . _extraObjects . arr . indexOf ( hitem . _obj ) ;
27252729 // workaround - if object found, replace its name
27262730 if ( indx >= 0 ) this . _extraObjects . opt [ indx ] = itemname ;
@@ -2736,66 +2740,79 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
27362740
27372741 let mesh = null ;
27382742 // either found painted object or just draw once again
2739- this . _toplevel . traverse ( function ( node ) { if ( node . geo_object === obj ) mesh = node ; } ) ;
2743+ this . _toplevel . traverse ( node => { if ( node . geo_object === obj ) mesh = node ; } ) ;
27402744
2741- if ( mesh ) mesh . visible = res ; else
2742- if ( res ) {
2743- this . drawExtras ( obj , "" , false ) ;
2744- this . updateClipping ( true ) ;
2745+ if ( mesh ) {
2746+ mesh . visible = res ;
2747+ this . render3D ( ) ;
2748+ } else if ( res ) {
2749+ this . drawExtras ( obj , "" , false ) . then ( ( ) => {
2750+ this . updateClipping ( true ) ;
2751+ this . render3D ( ) ;
2752+ } ) ;
27452753 }
2746-
2747- if ( mesh || res ) this . render3D ( ) ;
27482754 }
27492755
27502756 return res ;
27512757 }
27522758
27532759 /** @summary Draw extra object like tracks
2754- * @returns {Promise } when ready */
2760+ * @returns {Promise } for ready */
27552761 TGeoPainter . prototype . drawExtras = function ( obj , itemname , add_objects ) {
2756- if ( ! obj || ! obj . _typename )
2757- return false ;
2758-
27592762 // if object was hidden via menu, do not redraw it with next draw call
2760- if ( ! add_objects && obj . $hidden_via_menu )
2761- return false ;
2763+ if ( ! obj || ! obj . _typename || ( ! add_objects && obj . $hidden_via_menu ) )
2764+ return Promise . resolve ( false ) ;
27622765
2763- let is_any = false , do_render = false ;
2766+ let do_render = false ;
27642767 if ( add_objects === undefined ) {
27652768 add_objects = true ;
27662769 do_render = true ;
27672770 }
27682771
2772+ let promise = false ;
2773+
27692774 if ( ( obj . _typename === "TList" ) || ( obj . _typename === "TObjArray" ) ) {
27702775 if ( ! obj . arr ) return false ;
2771- for ( let n = 0 ; n < obj . arr . length ; ++ n ) {
2776+ let parr = [ ] ;
2777+ for ( let n = 0 ; n < obj . arr . length ; ++ n ) {
27722778 let sobj = obj . arr [ n ] , sname = obj . opt ? obj . opt [ n ] : "" ;
27732779 if ( ! sname ) sname = ( itemname || "<prnt>" ) + "/[" + n + "]" ;
2774- if ( this . drawExtras ( sobj , sname , add_objects ) ) is_any = true ;
2780+ parr . push ( this . drawExtras ( sobj , sname , add_objects ) ) ;
27752781 }
2782+ promise = Promise . all ( parr ) . then ( ress => ress . indexOf ( true ) >= 0 ) ;
27762783 } else if ( obj . _typename === 'THREE.Mesh' ) {
27772784 // adding mesh as is
27782785 this . addToExtrasContainer ( obj ) ;
2786+ promise = Promise . resolve ( true ) ;
27792787 is_any = true ;
27802788 } else if ( obj . _typename === 'TGeoTrack' ) {
2781- if ( add_objects && ! this . addExtra ( obj , itemname ) ) return false ;
2782- is_any = this . drawGeoTrack ( obj , itemname ) ;
2789+ if ( ! add_objects || this . addExtra ( obj , itemname ) )
2790+ promise = this . drawGeoTrack ( obj , itemname ) ;
27832791 } else if ( ( obj . _typename === 'TEveTrack' ) || ( obj . _typename === 'ROOT::Experimental::TEveTrack' ) ) {
2784- if ( add_objects && ! this . addExtra ( obj , itemname ) ) return false ;
2785- is_any = this . drawEveTrack ( obj , itemname ) ;
2792+ if ( ! add_objects || this . addExtra ( obj , itemname ) )
2793+ promise = this . drawEveTrack ( obj , itemname ) ;
27862794 } else if ( ( obj . _typename === 'TEvePointSet' ) || ( obj . _typename === "ROOT::Experimental::TEvePointSet" ) || ( obj . _typename === "TPolyMarker3D" ) ) {
2787- if ( add_objects && ! this . addExtra ( obj , itemname ) ) return false ;
2788- is_any = this . drawHit ( obj , itemname ) ;
2795+ if ( ! add_objects || this . addExtra ( obj , itemname ) )
2796+ promise = this . drawHit ( obj , itemname ) ;
27892797 } else if ( ( obj . _typename === "TEveGeoShapeExtract" ) || ( obj . _typename === "ROOT::Experimental::REveGeoShapeExtract" ) ) {
2790- if ( add_objects && ! this . addExtra ( obj , itemname ) ) return false ;
2791- is_any = this . drawExtraShape ( obj , itemname ) ;
2798+ if ( ! add_objects || this . addExtra ( obj , itemname ) )
2799+ promise = this . drawExtraShape ( obj , itemname ) ;
27922800 }
27932801
2794- if ( do_render && is_any ) {
2795- this . updateClipping ( true ) ;
2796- this . render3D ( 100 ) ;
2797- }
2798- return is_any ;
2802+ if ( ! jsrp . isPromise ( promise ) )
2803+ promise = Promise . resolve ( promise ) ;
2804+
2805+ if ( ! do_render )
2806+ return promise ;
2807+
2808+ return promise . then ( is_any => {
2809+ if ( is_any ) {
2810+ this . updateClipping ( true ) ;
2811+ this . render3D ( 100 ) ;
2812+ }
2813+
2814+ return is_any ;
2815+ } ) ;
27992816 }
28002817
28012818 /** @summary returns container for extra objects */
@@ -2944,7 +2961,7 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
29442961 projz = ( this . ctrl . project === "z" ) ,
29452962 pnts = new jsrp . PointsCreator ( size , this . _webgl , hit_size ) ;
29462963
2947- for ( let i = 0 ; i < size ; i ++ )
2964+ for ( let i = 0 ; i < size ; i ++ )
29482965 pnts . addPoint ( projx ? projv : hit . fP [ i * 3 ] ,
29492966 projy ? projv : hit . fP [ i * 3 + 1 ] ,
29502967 projz ? projv : hit . fP [ i * 3 + 2 ] ) ;
@@ -3289,7 +3306,7 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
32893306 if ( take_time > 300 ) {
32903307 jsrp . showProgress ( 'Rendering geometry' ) ;
32913308 this . showDrawInfo ( "Rendering" ) ;
3292- return setTimeout ( this . completeDraw . bind ( this , true ) , 10 ) ;
3309+ return setTimeout ( ( ) => this . completeDraw ( true ) , 10 ) ;
32933310 }
32943311
32953312 this . completeDraw ( true ) ;
@@ -3809,107 +3826,116 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
38093826 this . _complete_handler = callback ;
38103827 }
38113828
3812- /** @summary Completes drawing procedure */
3829+ /** @summary Completes drawing procedure
3830+ * @returns {Promise } for ready */
38133831 TGeoPainter . prototype . completeDraw = function ( close_progress ) {
38143832
38153833 let first_time = false , full_redraw = false , check_extras = true ;
38163834
38173835 if ( ! this . ctrl ) {
38183836 console . warn ( 'ctrl object does not exist in completeDraw - something went wrong' ) ;
3819- return ;
3837+ return Promise . resolve ( this ) ;
38203838 }
38213839
3840+ let promise = Promise . resolve ( true ) ;
3841+
38223842 if ( ! this . _clones ) {
38233843 check_extras = false ;
38243844 // if extra object where append, redraw them at the end
38253845 this . getExtrasContainer ( "delete" ) ; // delete old container
38263846 let extras = ( this . _main_painter ? this . _main_painter . _extraObjects : null ) || this . _extraObjects ;
3827- this . drawExtras ( extras , "" , false ) ;
3847+ promise = this . drawExtras ( extras , "" , false ) ;
38283848 } else if ( this . _first_drawing || this . _full_redrawing ) {
38293849 if ( this . ctrl . tracks && this . geo_manager )
3830- this . drawExtras ( this . geo_manager . fTracks , "<prnt>/Tracks" ) ;
3850+ promise = this . drawExtras ( this . geo_manager . fTracks , "<prnt>/Tracks" ) ;
38313851 }
38323852
3833- if ( this . _full_redrawing ) {
3834- this . adjustCameraPosition ( true ) ;
3835- this . _full_redrawing = false ;
3836- full_redraw = true ;
3837- this . changedDepthMethod ( "norender" ) ;
3838- }
3853+ return promise . then ( ( ) => {
38393854
3840- if ( this . _first_drawing ) {
3841- this . adjustCameraPosition ( true ) ;
3842- this . showDrawInfo ( ) ;
3843- this . _first_drawing = false ;
3844- first_time = true ;
3845- full_redraw = true ;
3846- }
3855+ if ( this . _full_redrawing ) {
3856+ this . adjustCameraPosition ( true ) ;
3857+ this . _full_redrawing = false ;
3858+ full_redraw = true ;
3859+ this . changedDepthMethod ( "norender" ) ;
3860+ }
38473861
3848- if ( this . ctrl . transparency !== 0 )
3849- this . changedGlobalTransparency ( this . ctrl . transparency , true ) ;
3862+ if ( this . _first_drawing ) {
3863+ this . adjustCameraPosition ( true ) ;
3864+ this . showDrawInfo ( ) ;
3865+ this . _first_drawing = false ;
3866+ first_time = true ;
3867+ full_redraw = true ;
3868+ }
38503869
3851- if ( first_time )
3852- this . completeScene ( ) ;
3870+ if ( this . ctrl . transparency !== 0 )
3871+ this . changedGlobalTransparency ( this . ctrl . transparency , true ) ;
38533872
3854- if ( full_redraw && ( this . ctrl . trans_radial || this . ctrl . trans_z ) )
3855- this . changedTransformation ( "norender" ) ;
3873+ if ( first_time )
3874+ this . completeScene ( ) ;
38563875
3857- if ( full_redraw && this . ctrl . _axis )
3858- this . drawSimpleAxis ( true ) ;
3876+ if ( full_redraw && ( this . ctrl . trans_radial || this . ctrl . trans_z ) )
3877+ this . changedTransformation ( "norender" ) ;
38593878
3860- this . _scene . overrideMaterial = null ;
3879+ if ( full_redraw && this . ctrl . _axis )
3880+ this . drawSimpleAxis ( true ) ;
38613881
3862- if ( this . _provided_more_nodes !== undefined ) {
3863- this . appendMoreNodes ( this . _provided_more_nodes , true ) ;
3864- delete this . _provided_more_nodes ;
3865- }
3882+ this . _scene . overrideMaterial = null ;
38663883
3867- if ( check_extras ) {
3868- // if extra object where append, redraw them at the end
3869- this . getExtrasContainer ( "delete" ) ; // delete old container
3870- let extras = ( this . _main_painter ? this . _main_painter . _extraObjects : null ) || this . _extraObjects ;
3871- this . drawExtras ( extras , "" , false ) ;
3872- }
3884+ if ( this . _provided_more_nodes !== undefined ) {
3885+ this . appendMoreNodes ( this . _provided_more_nodes , true ) ;
3886+ delete this . _provided_more_nodes ;
3887+ }
38733888
3874- this . updateClipping ( true ) ; // do not render
3889+ if ( check_extras ) {
3890+ // if extra object where append, redraw them at the end
3891+ this . getExtrasContainer ( "delete" ) ; // delete old container
3892+ let extras = ( this . _main_painter ? this . _main_painter . _extraObjects : null ) || this . _extraObjects ;
3893+ return this . drawExtras ( extras , "" , false ) ;
3894+ }
3895+ } ) . then ( ( ) => {
38753896
3876- this . render3D ( 0 , true ) ;
3897+ this . updateClipping ( true ) ; // do not render
38773898
3878- if ( close_progress ) jsrp . showProgress ( ) ;
3899+ this . render3D ( 0 , true ) ;
38793900
3880- this . addOrbitControls ( ) ;
3901+ if ( close_progress ) jsrp . showProgress ( ) ;
38813902
3882- this . addTransformControl ( ) ;
3903+ this . addOrbitControls ( ) ;
38833904
3884- if ( first_time ) {
3905+ this . addTransformControl ( ) ;
38853906
3886- // after first draw check if highlight can be enabled
3887- if ( this . ctrl . highlight === false )
3888- this . ctrl . highlight = ( this . first_render_tm < 1000 ) ;
3907+ if ( first_time ) {
38893908
3890- // also highlight of scene object can be assigned at the first draw
3891- if ( this . ctrl . highlight_scene === false )
3892- this . ctrl . highlight_scene = this . ctrl . highlight ;
3909+ // after first draw check if highlight can be enabled
3910+ if ( this . ctrl . highlight === false )
3911+ this . ctrl . highlight = ( this . first_render_tm < 1000 ) ;
38933912
3894- // if rotation was enabled, do it
3895- if ( this . _webgl && this . ctrl . rotate && ! this . ctrl . project ) this . autorotate ( 2.5 ) ;
3896- if ( this . _webgl && this . ctrl . show_controls && ! JSROOT . batch_mode ) this . showControlOptions ( true ) ;
3897- }
3913+ // also highlight of scene object can be assigned at the first draw
3914+ if ( this . ctrl . highlight_scene === false )
3915+ this . ctrl . highlight_scene = this . ctrl . highlight ;
38983916
3899- this . setAsMainPainter ( ) ;
3917+ // if rotation was enabled, do it
3918+ if ( this . _webgl && this . ctrl . rotate && ! this . ctrl . project ) this . autorotate ( 2.5 ) ;
3919+ if ( this . _webgl && this . ctrl . show_controls && ! JSROOT . batch_mode ) this . showControlOptions ( true ) ;
3920+ }
39003921
3901- if ( typeof this . _resolveFunc == 'function' ) {
3902- this . _resolveFunc ( this ) ;
3903- delete this . _resolveFunc ;
3904- }
3922+ this . setAsMainPainter ( ) ;
39053923
3906- if ( typeof this . _complete_handler == 'function' )
3907- this . _complete_handler ( this ) ;
3924+ if ( typeof this . _resolveFunc == 'function' ) {
3925+ this . _resolveFunc ( this ) ;
3926+ delete this . _resolveFunc ;
3927+ }
39083928
3909- if ( this . _draw_nodes_again )
3910- return this . startDrawGeometry ( ) ; // relaunch drawing
3929+ if ( typeof this . _complete_handler == 'function' )
3930+ this . _complete_handler ( this ) ;
39113931
3912- this . _drawing_ready = true ; // indicate that drawing is completed
3932+ if ( this . _draw_nodes_again )
3933+ this . startDrawGeometry ( ) ; // relaunch drawing
3934+ else
3935+ this . _drawing_ready = true ; // indicate that drawing is completed
3936+
3937+ return this ;
3938+ } ) ;
39133939 }
39143940
39153941 /** @summary Returns true if geometry drawing is completed */
0 commit comments