@@ -38,131 +38,154 @@ pub fn update_ui(
3838 app_state. restarting = false ;
3939 }
4040
41- if scene_state. get ( ) == & SceneState :: Loading {
42- ui. label ( "Loading..." ) ;
43- } else if let Some ( physics) = physics {
44- let mut changed = false ;
45- egui:: ComboBox :: from_label ( "render mode" )
46- . selected_text ( RenderMode :: from_u32 ( app_state. render_config . mode ) . text ( ) )
47- . show_ui ( ui, |ui| {
48- for i in 0 ..6 {
49- changed = ui
50- . selectable_value (
51- & mut app_state. render_config . mode ,
52- i,
53- RenderMode :: from_u32 ( i) . text ( ) ,
54- )
55- . changed ( )
56- || changed;
57- }
58- } ) ;
59-
60- if changed {
61- queue. write_buffer (
62- app_state. gpu_render_config . buffer . buffer ( ) ,
63- 0 ,
64- bytemuck:: bytes_of ( & app_state. render_config . mode ) ,
65- ) ;
66- queue. submit ( [ ] ) ;
41+ match scene_state. get ( ) {
42+ SceneState :: Waiting => {
43+ ui. label ( "Waiting..." ) ;
6744 }
68-
69- let mut sim_params_changed = false ;
70- sim_params_changed = ui
71- . add ( Slider :: new ( & mut app_state. num_substeps , 1 ..=200 ) . text ( "substeps" ) )
72- . changed ( )
73- || sim_params_changed;
74- sim_params_changed = ui
75- . add ( Slider :: new ( & mut app_state. gravity_factor , 0.0 ..=10.0 ) . text ( "gravity factor" ) )
76- . changed ( )
77- || sim_params_changed;
78-
79- if ui
80- . checkbox ( & mut app_state. show_rigid_particles , "show rigid_particles" )
81- . changed ( )
82- {
83- for mut visibility in rigid_particles. iter_mut ( ) {
84- if app_state. show_rigid_particles {
85- * visibility = Visibility :: Inherited ;
86- } else {
87- * visibility = Visibility :: Hidden ;
88- }
45+ SceneState :: Loading => {
46+ ui. label ( "Loading..." ) ;
47+ }
48+ SceneState :: LoadingError ( errors) => {
49+ ui. label ( "Error loading scene!" ) ;
50+ ui. label ( "Locally, run `cargo run` from the same directory where your `assets/` directory is located." ) ;
51+ ui. label ( "Typically in `examples2d/` or `example3d/`." ) ;
52+ ui. label ( "Errors:" ) ;
53+ for error in errors {
54+ ui. label ( format ! (
55+ "asset \" {}\" failed with errors: {:?}" ,
56+ error. 0 , error. 1
57+ ) ) ;
8958 }
9059 }
60+ SceneState :: Loaded => {
61+ if let Some ( physics) = physics {
62+ let mut changed = false ;
63+ egui:: ComboBox :: from_label ( "render mode" )
64+ . selected_text ( RenderMode :: from_u32 ( app_state. render_config . mode ) . text ( ) )
65+ . show_ui ( ui, |ui| {
66+ for i in 0 ..6 {
67+ changed = ui
68+ . selectable_value (
69+ & mut app_state. render_config . mode ,
70+ i,
71+ RenderMode :: from_u32 ( i) . text ( ) ,
72+ )
73+ . changed ( )
74+ || changed;
75+ }
76+ } ) ;
9177
92- #[ cfg( feature = "dim2" ) ]
93- let gravity = vector ! [ 0.0 , -9.81 ] ;
94- #[ cfg( feature = "dim3" ) ]
95- let gravity = vector ! [ 0.0 , -9.81 , 0.0 ] ;
78+ if changed {
79+ queue. write_buffer (
80+ app_state. gpu_render_config . buffer . buffer ( ) ,
81+ 0 ,
82+ bytemuck:: bytes_of ( & app_state. render_config . mode ) ,
83+ ) ;
84+ queue. submit ( [ ] ) ;
85+ }
86+
87+ let mut sim_params_changed = false ;
88+ sim_params_changed = ui
89+ . add ( Slider :: new ( & mut app_state. num_substeps , 1 ..=200 ) . text ( "substeps" ) )
90+ . changed ( )
91+ || sim_params_changed;
92+ sim_params_changed = ui
93+ . add (
94+ Slider :: new ( & mut app_state. gravity_factor , 0.0 ..=10.0 )
95+ . text ( "gravity factor" ) ,
96+ )
97+ . changed ( )
98+ || sim_params_changed;
99+
100+ if ui
101+ . checkbox ( & mut app_state. show_rigid_particles , "show rigid_particles" )
102+ . changed ( )
103+ {
104+ for mut visibility in rigid_particles. iter_mut ( ) {
105+ if app_state. show_rigid_particles {
106+ * visibility = Visibility :: Inherited ;
107+ } else {
108+ * visibility = Visibility :: Hidden ;
109+ }
110+ }
111+ }
96112
97- if sim_params_changed {
98- let new_params = SimulationParams {
99- gravity : gravity * app_state. gravity_factor ,
100- dt : ( 1.0 / 60.0 ) / ( app_state. num_substeps as f32 ) ,
101113 #[ cfg( feature = "dim2" ) ]
102- padding : 0.0 ,
103- } ;
104- queue. write_buffer (
105- physics. data . sim_params . params . buffer ( ) ,
106- 0 ,
107- bytemuck:: bytes_of ( & new_params) ,
108- ) ;
109- queue. submit ( [ ] ) ;
110- }
114+ let gravity = vector ! [ 0.0 , -9.81 ] ;
115+ #[ cfg( feature = "dim3" ) ]
116+ let gravity = vector ! [ 0.0 , -9.81 , 0.0 ] ;
111117
112- ui. label ( format ! ( "Particle count: {}" , physics. particles. len( ) ) ) ;
113- ui. label ( format ! (
114- "Rigid particle count: {}" ,
115- physics. data. rigid_particles. len( )
116- ) ) ;
118+ if sim_params_changed {
119+ let new_params = SimulationParams {
120+ gravity : gravity * app_state. gravity_factor ,
121+ dt : ( 1.0 / 60.0 ) / ( app_state. num_substeps as f32 ) ,
122+ #[ cfg( feature = "dim2" ) ]
123+ padding : 0.0 ,
124+ } ;
125+ queue. write_buffer (
126+ physics. data . sim_params . params . buffer ( ) ,
127+ 0 ,
128+ bytemuck:: bytes_of ( & new_params) ,
129+ ) ;
130+ queue. submit ( [ ] ) ;
131+ }
117132
118- CollapsingHeader :: new ( format ! ( "GPU runtime: {:.3}ms" , timings. total_time( ) ) )
119- . id_salt ( "GPU runtimes" )
120- . show ( ui, |ui| {
121- ui. label ( format ! (
122- "Rigid update: {:.3}ms" ,
123- timings. update_rigid_particles
124- ) ) ;
125- ui. label ( format ! ( "Grid sort: {:.3}ms" , timings. grid_sort) ) ;
126- ui. label ( format ! ( "CDF Grid update: {:.3}ms" , timings. grid_update_cdf) ) ;
127- ui. label ( format ! ( "CDF P2G: {:.3}ms" , timings. p2g_cdf) ) ;
128- ui. label ( format ! ( "CDF G2P: {:.3}ms" , timings. g2p_cdf) ) ;
129- ui. label ( format ! ( "P2G: {:.3}ms" , timings. p2g) ) ;
130- ui. label ( format ! ( "Grid update: {:.3}ms" , timings. grid_update) ) ;
131- ui. label ( format ! ( "G2P: {:.3}ms" , timings. g2p) ) ;
132- ui. label ( format ! (
133- "Particles update: {:.3}ms" ,
134- timings. particles_update
135- ) ) ;
133+ ui. label ( format ! ( "Particle count: {}" , physics. particles. len( ) ) ) ;
136134 ui. label ( format ! (
137- "Integrate bodies : {:.3}ms " ,
138- timings . integrate_bodies
135+ "Rigid particle count : {} " ,
136+ physics . data . rigid_particles . len ( )
139137 ) ) ;
140- } ) ;
141138
142- ui. horizontal ( |ui| {
143- let label = if app_state. run_state == RunState :: Paused {
144- "Run"
145- } else {
146- "Pause"
147- } ;
139+ CollapsingHeader :: new ( format ! ( "GPU runtime: {:.3}ms" , timings. total_time( ) ) )
140+ . id_salt ( "GPU runtimes" )
141+ . show ( ui, |ui| {
142+ ui. label ( format ! (
143+ "Rigid update: {:.3}ms" ,
144+ timings. update_rigid_particles
145+ ) ) ;
146+ ui. label ( format ! ( "Grid sort: {:.3}ms" , timings. grid_sort) ) ;
147+ ui. label ( format ! ( "CDF Grid update: {:.3}ms" , timings. grid_update_cdf) ) ;
148+ ui. label ( format ! ( "CDF P2G: {:.3}ms" , timings. p2g_cdf) ) ;
149+ ui. label ( format ! ( "CDF G2P: {:.3}ms" , timings. g2p_cdf) ) ;
150+ ui. label ( format ! ( "P2G: {:.3}ms" , timings. p2g) ) ;
151+ ui. label ( format ! ( "Grid update: {:.3}ms" , timings. grid_update) ) ;
152+ ui. label ( format ! ( "G2P: {:.3}ms" , timings. g2p) ) ;
153+ ui. label ( format ! (
154+ "Particles update: {:.3}ms" ,
155+ timings. particles_update
156+ ) ) ;
157+ ui. label ( format ! (
158+ "Integrate bodies: {:.3}ms" ,
159+ timings. integrate_bodies
160+ ) ) ;
161+ } ) ;
148162
149- if ui. button ( label) . clicked ( ) {
150- if app_state. run_state == RunState :: Paused {
151- app_state. run_state = RunState :: Running
152- } else {
153- app_state. run_state = RunState :: Paused
154- }
155- }
163+ ui. horizontal ( |ui| {
164+ let label = if app_state. run_state == RunState :: Paused {
165+ "Run"
166+ } else {
167+ "Pause"
168+ } ;
156169
157- if ui. button ( "Step" ) . clicked ( ) {
158- app_state. run_state = RunState :: Step ;
159- }
170+ if ui. button ( label) . clicked ( ) {
171+ if app_state. run_state == RunState :: Paused {
172+ app_state. run_state = RunState :: Running
173+ } else {
174+ app_state. run_state = RunState :: Paused
175+ }
176+ }
160177
161- if ui. button ( "Restart" ) . clicked ( ) {
162- scenes. init_scene ( & mut commands, app_state. selected_scene ) ;
163- app_state. restarting = true ;
178+ if ui. button ( "Step" ) . clicked ( ) {
179+ app_state. run_state = RunState :: Step ;
180+ }
181+
182+ if ui. button ( "Restart" ) . clicked ( ) {
183+ scenes. init_scene ( & mut commands, app_state. selected_scene ) ;
184+ app_state. restarting = true ;
185+ }
186+ } ) ;
164187 }
165- } ) ;
188+ }
166189 }
167190 } ) ;
168191}
0 commit comments