@@ -21,15 +21,13 @@ export class Controls {
2121 const gui = new GUI ( { title : 'Control panel' , container : this . element } ) ;
2222
2323 const centerLineParam = {
24- 'show center lines' : s . centerLines . segments . show ,
25- 'line color' : s . centerLines . segments . color ,
26- 'gradient start color' : s . caveLines . color . start ,
27- 'gradient end color' : s . caveLines . color . end ,
28- width : s . centerLines . segments . width ,
29- opacity : s . centerLines . segments . opacity ,
30- 'show station' : s . centerLines . spheres . show ,
31- 'station color' : s . centerLines . spheres . color ,
32- 'station size' : s . centerLines . spheres . radius
24+ 'show center lines' : s . centerLines . segments . show ,
25+ 'line color' : s . centerLines . segments . color ,
26+ width : s . centerLines . segments . width ,
27+ opacity : s . centerLines . segments . opacity ,
28+ 'show station' : s . centerLines . spheres . show ,
29+ 'station color' : s . centerLines . spheres . color ,
30+ 'station size' : s . centerLines . spheres . radius
3331 } ;
3432
3533 const splayParam = {
@@ -66,6 +64,53 @@ export class Controls {
6664 DPI : this . options . screen . DPI
6765 } ;
6866
67+ // Multi-color gradient controls
68+ const gradientFolder = gui . addFolder ( 'Color gradient' ) ;
69+
70+ // Add gradient color controls
71+ const addGradientColor = ( ) => {
72+ const maxDepth = Math . max ( ...s . caveLines . color . gradientColors . map ( ( gc ) => gc . depth ) ) ;
73+ const newColor = { depth : Math . min ( maxDepth + 25 , 100 ) , color : '#ffffff' } ;
74+ s . caveLines . color . gradientColors = [ ...s . caveLines . color . gradientColors , newColor ] ; // trigger a change event
75+ this . reload ( ) ;
76+ } ;
77+
78+ const removeGradientColor = ( index ) => {
79+ if ( s . caveLines . color . gradientColors . length > 2 ) {
80+ s . caveLines . color . gradientColors . splice ( index , 1 ) ;
81+ s . caveLines . color . gradientColors = [ ...s . caveLines . color . gradientColors ] ; // trigger a change event
82+ this . reload ( ) ;
83+ }
84+ } ;
85+
86+ gradientFolder . add ( { 'Add Color Stop' : addGradientColor } , 'Add Color Stop' ) ;
87+
88+ // Create controls for each gradient color
89+ s . caveLines . color . gradientColors . forEach ( ( gradientColor , index ) => {
90+ const colorFolder = gradientFolder . addFolder ( `Color Stop ${ index + 1 } ` ) ;
91+
92+ colorFolder
93+ . add ( gradientColor , 'depth' , 0 , 100 )
94+ . step ( 1 )
95+ . name ( 'Relative Depth' )
96+ . onFinishChange ( ( ) => {
97+ // Sort gradient colors by depth
98+ s . caveLines . color . gradientColors . sort ( ( a , b ) => a . depth - b . depth ) ;
99+ // Trigger scene update by changing the gradientColors array
100+ s . caveLines . color . gradientColors = [ ...s . caveLines . color . gradientColors ] ;
101+ this . reload ( ) ;
102+ } ) ;
103+
104+ colorFolder . addColor ( gradientColor , 'color' ) . onFinishChange ( ( ) => {
105+ // Trigger scene update by changing the gradientColors array
106+ s . caveLines . color . gradientColors = [ ...s . caveLines . color . gradientColors ] ;
107+ } ) ;
108+
109+ if ( s . caveLines . color . gradientColors . length > 2 ) {
110+ colorFolder . add ( { Remove : ( ) => removeGradientColor ( index ) } , 'Remove' ) ;
111+ }
112+ } ) ;
113+
69114 const centerLineFolder = gui . addFolder ( 'Center lines' ) ;
70115
71116 centerLineFolder . add ( centerLineParam , 'show center lines' ) . onFinishChange ( function ( val ) {
@@ -76,14 +121,6 @@ export class Controls {
76121 s . centerLines . segments . color = val ;
77122 } ) ;
78123
79- centerLineFolder . addColor ( centerLineParam , 'gradient start color' ) . onChange ( function ( val ) {
80- s . caveLines . color . start = val ;
81- } ) ;
82-
83- centerLineFolder . addColor ( centerLineParam , 'gradient end color' ) . onChange ( function ( val ) {
84- s . caveLines . color . end = val ;
85- } ) ;
86-
87124 centerLineFolder
88125 . add ( centerLineParam , 'width' , 0.5 , 8 )
89126 . step ( 0.1 )
0 commit comments