add skybox editor
authorhgn <hgodden00@gmail.com>
Wed, 31 Jan 2024 06:27:23 +0000 (06:27 +0000)
committerhgn <hgodden00@gmail.com>
Wed, 31 Jan 2024 06:27:23 +0000 (06:27 +0000)
world.h
world_render.c

diff --git a/world.h b/world.h
index 7b1074354901f8abb99718e9c09a1f5f8ab8de93..9e9387b658d9eefc05239da2e8549f5706c42059 100644 (file)
--- 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
index e675abf96501afcebf59316c57e3f0150bf0deda..103304196783e864dbdd7fe8e3e9600c6d011c01 100644 (file)
@@ -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