Scene loading/saving improvements, transform gizmo, entity creation
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#load "../ui/widgets.jai";
|
||||
|
||||
#placeholder editor_ui_entity_creation;
|
||||
|
||||
pick_scene_view_at :: (camera: Camera, coordinates: Vector2) {
|
||||
ray := normalized_screen_to_ray_v2(camera, coordinates);
|
||||
|
||||
@@ -54,22 +56,22 @@ editor_ui :: () {
|
||||
|
||||
ui_space(20, 0);
|
||||
|
||||
//if mode == {
|
||||
// case .PLAYING; {
|
||||
// ui_set_next_background_color(.{0,0.6,0,1});
|
||||
// if ui_button_with_texture(editor.icons.stop) {
|
||||
// edit_engine.current_scene();
|
||||
// }
|
||||
// ui_label(tprint("Playing '%'", engine.current_scene.name), .{0,0.7,0,1});
|
||||
// }
|
||||
// case .EDITING; {
|
||||
if engine.mode == {
|
||||
case .PLAYING; {
|
||||
ui_set_next_background_color(.{0,0.6,0,1});
|
||||
if ui_button_with_texture(engine.editor.icons.stop) {
|
||||
switch_engine_mode(.EDITING);
|
||||
}
|
||||
ui_label(tprint("Playing '%'", engine.current_scene.name), .{0,0.7,0,1});
|
||||
}
|
||||
case .EDITING; {
|
||||
ui_set_next_background_color(.{0.6,0,0,1});
|
||||
//if ui_button_with_texture(editor.icons.play) {
|
||||
// play_current_editor_scene();
|
||||
//}
|
||||
if ui_button_with_texture(engine.editor.icons.play) {
|
||||
switch_engine_mode(.PLAYING);
|
||||
}
|
||||
ui_label(tprint("Editing '%'", engine.current_scene.name), .{1,1,1,1});
|
||||
//}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
ui_pop_parent();
|
||||
|
||||
@@ -135,7 +137,7 @@ editor_ui :: () {
|
||||
ui_set_next_size_x(.PCT, 1.0);
|
||||
ui_tab_title_bar("SCENE");
|
||||
ui_set_next_size_x(.PCT, 1.0);
|
||||
ui_set_next_size_y(.PCT, 0.9);
|
||||
ui_set_next_size_y(.PCT, 0.75);
|
||||
|
||||
state := ui_interactable_texture(get_texture_from_pass("UI Blend Pass"));
|
||||
if state.left_mouse_down {
|
||||
@@ -146,8 +148,15 @@ editor_ui :: () {
|
||||
engine.editor.mouse_viewport_state = state;
|
||||
|
||||
ui_set_next_size_x(.PCT, 1.0);
|
||||
ui_set_next_size_y(.PCT, 0.1);
|
||||
ui_tab_title_bar("SCENES");
|
||||
ui_set_next_size_y(.PCT, 0.25);
|
||||
ui_tab_title_bar("Create entities");
|
||||
{
|
||||
new_entity := editor_ui_entity_creation();
|
||||
if new_entity != null {
|
||||
engine.editor.selected_entities.count = 0;
|
||||
array_add(*engine.editor.selected_entities, new_entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
ui_pop_parent();
|
||||
|
||||
@@ -162,14 +171,15 @@ editor_ui :: () {
|
||||
ui_set_next_size_x(.PCT, 1.0);
|
||||
ui_tab_title_bar("PROPERTIES");
|
||||
|
||||
//if editor.selected_entity != null {
|
||||
// ui_slider(*slider_value, 0.0, 1.0);
|
||||
// ui_label(tprint("Name: %", editor.selected_entity.name));
|
||||
// ui_label(tprint("Id: %", editor.selected_entity.id));
|
||||
// ui_label(tprint("Position: % % %", editor.selected_entity.transform.position.x, editor.selected_entity.transform.position.y, editor.selected_entity.transform.position.z));
|
||||
// ui_label(tprint("Rotation: % % % %", editor.selected_entity.transform.orientation.x, editor.selected_entity.transform.orientation.y, editor.selected_entity.transform.orientation.z, editor.selected_entity.transform.orientation.w));
|
||||
// ui_label(tprint("Scale: % % %", editor.selected_entity.transform.scale.x, editor.selected_entity.transform.scale.y, editor.selected_entity.transform.scale.z));
|
||||
//}
|
||||
if engine.editor.selected_entities.count == 1 {
|
||||
entity := engine.editor.selected_entities[0];
|
||||
ui_slider(*slider_value, 0.0, 1.0);
|
||||
ui_label(tprint("Name: %", entity.name));
|
||||
ui_label(tprint("Id: %", entity.id));
|
||||
ui_label(tprint("Position: % % %", entity.transform.position.x, entity.transform.position.y, entity.transform.position.z));
|
||||
ui_label(tprint("Rotation: % % % %", entity.transform.orientation.x, entity.transform.orientation.y, entity.transform.orientation.z, entity.transform.orientation.w));
|
||||
ui_label(tprint("Scale: % % %", entity.transform.scale.x, entity.transform.scale.y, entity.transform.scale.z));
|
||||
}
|
||||
|
||||
}
|
||||
ui_pop_parent();
|
||||
@@ -187,22 +197,28 @@ base_editor_update :: () {
|
||||
eat_key(.MOUSE_LEFT);
|
||||
}
|
||||
|
||||
// @Incomplete: Show that we saved the scene in the editor. Maybe a quick text message or just inside one of the tab titles
|
||||
if key_pressed(.CTRL) && key_down(.S) {
|
||||
save_scene(engine.current_scene);
|
||||
}
|
||||
|
||||
// Check if we hit the gizmo
|
||||
// @Incomplete: MOVE THIS
|
||||
engine.editor.should_check_entities = true;
|
||||
|
||||
//if editor.selected_entity != null {
|
||||
// gizmo_scale := distance(editor.selected_entity.transform.position, editor.camera.position) * 0.1 * 0.5;
|
||||
// editor.transform_gizmo.uniform_gizmo_scale = gizmo_scale;
|
||||
// set_scale(*editor.transform_gizmo.transform, .{gizmo_scale, gizmo_scale, gizmo_scale});
|
||||
if engine.editor.selected_entities.count == 1 {
|
||||
entity := engine.editor.selected_entities[0];
|
||||
gizmo_scale := distance(entity.transform.position, engine.editor.camera.position) * 0.1 * 0.5;
|
||||
engine.editor.transform_gizmo.uniform_gizmo_scale = gizmo_scale;
|
||||
set_scale(*engine.editor.transform_gizmo.transform, .{gizmo_scale, gizmo_scale, gizmo_scale});
|
||||
|
||||
// coordinates := Vector2.{editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - editor.mouse_viewport_state.normalized_local_mouse_coordinates.y};
|
||||
// ray := normalized_screen_to_ray_v2(*editor.camera, coordinates);
|
||||
coordinates := Vector2.{engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.x, 1.0 - engine.editor.mouse_viewport_state.normalized_local_mouse_coordinates.y};
|
||||
ray := normalized_screen_to_ray_v2(engine.editor.camera, coordinates);
|
||||
|
||||
// if update_transform_gizmo(ray, coordinates) {
|
||||
// editor.should_check_entities = false;
|
||||
// }
|
||||
//}
|
||||
if update_transform_gizmo(ray, coordinates) {
|
||||
engine.editor.should_check_entities = false;
|
||||
}
|
||||
}
|
||||
|
||||
editor_ui();
|
||||
|
||||
@@ -212,7 +228,7 @@ base_editor_update :: () {
|
||||
// // @Incomplete: At some point we want this to place entities at either a set distance or a distance depending on a raycast in the camera's forward direction so that we don't place things behind other entities
|
||||
// set_position(*placed_entity.transform, editor.camera.position + editor.camera.forward * 30);
|
||||
// editor.show_menu = false;
|
||||
// editor.selected_entity = placed_entity;
|
||||
// entity = placed_entity;
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -223,20 +239,20 @@ base_editor_update :: () {
|
||||
//show_message("Saved scene");
|
||||
}
|
||||
|
||||
//if editor.selected_entity != null {
|
||||
//if entity != null {
|
||||
// // @Incomplete:@Incomplete: Duplicate
|
||||
// //if key_pressed(.CTRL) && key_down(.D) {
|
||||
// // make_directory_if_it_does_not_exist("../temp");
|
||||
// // save_entity(editor.selected_entity, "../temp/", "temp");
|
||||
// // save_entity(entity, "../temp/", "temp");
|
||||
// // duplicated := load_entity(editor_scene, "../temp/temp.ent");
|
||||
// // editor.selected_entity = duplicated;
|
||||
// // entity = duplicated;
|
||||
// //}
|
||||
|
||||
// // DELETE
|
||||
// // DELETE
|
||||
// //if key_down(.DELETE) || key_down(.BACKSPACE) {
|
||||
// // delete_entity(editor.selected_entity);
|
||||
// // editor.selected_entity = null;
|
||||
// // delete_entity(entity);
|
||||
// // entity = null;
|
||||
// // editor.transform_gizmo.selected_axis = .NONE;
|
||||
// //}
|
||||
//}
|
||||
@@ -297,27 +313,26 @@ base_editor_update :: () {
|
||||
engine.editor.menu_position.y = cast(float)engine.renderer.render_target_height - mouse_position.y;
|
||||
}
|
||||
|
||||
if key_down(.W) {
|
||||
engine.editor.transform_gizmo.transform_type = .TRANSLATION;
|
||||
}
|
||||
if !key_pressed(.CTRL) {
|
||||
if key_down(.W) {
|
||||
engine.editor.transform_gizmo.transform_type = .TRANSLATION;
|
||||
}
|
||||
|
||||
if key_down(.E) {
|
||||
engine.editor.transform_gizmo.transform_type = .ROTATION;
|
||||
}
|
||||
if key_down(.E) {
|
||||
engine.editor.transform_gizmo.transform_type = .ROTATION;
|
||||
}
|
||||
|
||||
if key_down(.R) {
|
||||
engine.editor.transform_gizmo.transform_type = .SCALE;
|
||||
if key_down(.R) {
|
||||
engine.editor.transform_gizmo.transform_type = .SCALE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_view_matrix(camera);
|
||||
}
|
||||
|
||||
//if editor.selected_entity != null {
|
||||
// e := editor.selected_entity;
|
||||
// set_position(*editor.transform_gizmo.transform, e.transform.position);
|
||||
// update_gizmo_buffers();
|
||||
//}
|
||||
|
||||
//edit_scene_settings(*game_state.engine.current_scene.settings);
|
||||
if key_pressed(.CTRL) && key_down(.E) {
|
||||
new_mode := ifx engine.mode == .EDITING then Engine_Mode.PLAYING else .EDITING;
|
||||
switch_engine_mode(new_mode);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user