From: hgn Date: Wed, 31 Jan 2024 06:27:23 +0000 (+0000) Subject: add skybox editor X-Git-Url: https://harrygodden.com/git/?p=carveJwlIkooP6JGAAIwe30JlM.git;a=commitdiff_plain;h=83890302a02892a2e6f26fa8d7bfe1309463c133 add skybox editor --- diff --git a/world.h b/world.h index 7b10743..9e9387b 100644 --- a/world.h +++ b/world.h @@ -56,7 +56,8 @@ static void skaterift_world_get_save_path( enum world_purpose which, static f32 k_day_length = 30.0f; /* minutes */ static i32 k_debug_light_indices = 0, k_debug_light_complexity= 0, - k_light_preview = 0; + k_light_preview = 0, + k_light_editor = 0; #define WORLD_SURFACE_HAS_TRAFFIC 0x1 #define WORLD_SURFACE_HAS_PROPS 0x2 diff --git a/world_render.c b/world_render.c index e675abf..1033041 100644 --- a/world_render.c +++ b/world_render.c @@ -70,6 +70,7 @@ static void world_render_init(void){ VG_VAR_I32( k_debug_light_indices ); VG_VAR_I32( k_debug_light_complexity ); VG_VAR_I32( k_light_preview ); + VG_VAR_I32( k_light_editor ); vg_console_reg_cmd( "set_time", ccmd_set_time, NULL ); world_render.sky_rate = 1.0; @@ -1188,4 +1189,48 @@ static void render_world_position( world_instance *world, camera *cam ){ mesh_draw( &world->mesh_geo ); } +struct ui_enum_opt skybox_setting_options[] = { + { 0, "g_daysky_colour" }, + { 1, "g_nightsky_colour" }, + { 2, "g_sunset_colour" }, + { 3, "g_ambient_colour" }, + { 4, "g_sun_colour" }, +}; + +static f32 *skybox_prop_location( world_instance *world, i32 index ){ + switch( index ){ + case 0: return world->ub_lighting.g_daysky_colour; break; + case 1: return world->ub_lighting.g_nightsky_colour; break; + case 2: return world->ub_lighting.g_sunset_colour; break; + case 3: return world->ub_lighting.g_ambient_colour; break; + case 4: return world->ub_lighting.g_sun_colour; break; + default: return NULL; + } +} + +static void imgui_world_light_edit( world_instance *world ){ + ui_rect panel = { vg.window_x-400, 0, 400, vg.window_y }; + ui_fill( panel, ui_colour( k_ui_bg+1 ) ); + ui_outline( panel, 1, ui_colour( k_ui_bg+7 ), 0 ); + ui_rect_pad( panel, (ui_px[2]){ 8, 8 } ); + vg_ui.wants_mouse = 1; + + static i32 option_to_edit = 0; + ui_enum( panel, "option", skybox_setting_options, 5, &option_to_edit ); + ui_colourpicker( panel, "colour", + skybox_prop_location( world, option_to_edit ) ); + + if( ui_button( panel, "save tweaker file ('/tmp/tweaker.txt')\n" ) == 1 ){ + FILE *fp = fopen( "/tmp/tweaker.txt", "w" ); + + for( i32 i=0; i<5; i ++ ){ + struct ui_enum_opt *opt = &skybox_setting_options[i]; + f32 *val = skybox_prop_location( world, i ); + fprintf( fp, "%s = {%.3ff, %.3ff, %.3ff, %.3ff},\n", + opt->alias, val[0], val[1], val[2], val[3] ); + } + fclose( fp ); + } +} + #endif