diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 10 | ||||
-rw-r--r-- | editor/editor_node.h | 10 | ||||
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 4 | ||||
-rw-r--r-- | editor/plugins/baked_lightmap_editor_plugin.cpp | 95 | ||||
-rw-r--r-- | editor/plugins/baked_lightmap_editor_plugin.h | 39 | ||||
-rw-r--r-- | editor/progress_dialog.cpp | 36 | ||||
-rw-r--r-- | editor/progress_dialog.h | 11 | ||||
-rw-r--r-- | editor/spatial_editor_gizmos.cpp | 121 | ||||
-rw-r--r-- | editor/spatial_editor_gizmos.h | 17 |
9 files changed, 326 insertions, 17 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 27ed53bb42..d0d13fdbcf 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -67,6 +67,7 @@ #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/plugins/asset_library_editor_plugin.h" +#include "editor/plugins/baked_lightmap_editor_plugin.h" #include "editor/plugins/camera_editor_plugin.h" #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/collision_polygon_2d_editor_plugin.h" @@ -3384,14 +3385,14 @@ void EditorNode::stop_child_process() { _menu_option_confirm(RUN_STOP, false); } -void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps) { +void EditorNode::progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) { - singleton->progress_dialog->add_task(p_task, p_label, p_steps); + singleton->progress_dialog->add_task(p_task, p_label, p_steps, p_can_cancel); } -void EditorNode::progress_task_step(const String &p_task, const String &p_state, int p_step, bool p_force_refresh) { +bool EditorNode::progress_task_step(const String &p_task, const String &p_state, int p_step, bool p_force_refresh) { - singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh); + return singleton->progress_dialog->task_step(p_task, p_state, p_step, p_force_refresh); } void EditorNode::progress_end_task(const String &p_task) { @@ -5659,6 +5660,7 @@ EditorNode::EditorNode() { add_editor_plugin(memnew(TextureRegionEditorPlugin(this))); add_editor_plugin(memnew(Particles2DEditorPlugin(this))); add_editor_plugin(memnew(GIProbeEditorPlugin(this))); + add_editor_plugin(memnew(BakedLightmapEditorPlugin(this))); add_editor_plugin(memnew(Path2DEditorPlugin(this))); add_editor_plugin(memnew(PathEditorPlugin(this))); add_editor_plugin(memnew(Line2DEditorPlugin(this))); diff --git a/editor/editor_node.h b/editor/editor_node.h index 658d5dc0ae..e7ef9eefb5 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -745,8 +745,8 @@ public: static void add_io_error(const String &p_error); - static void progress_add_task(const String &p_task, const String &p_label, int p_steps); - static void progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true); + static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false); + static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true); static void progress_end_task(const String &p_task); static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps); @@ -807,9 +807,9 @@ public: struct EditorProgress { String task; - void step(const String &p_state, int p_step = -1, bool p_force_refresh = true) { EditorNode::progress_task_step(task, p_state, p_step, p_force_refresh); } - EditorProgress(const String &p_task, const String &p_label, int p_amount) { - EditorNode::progress_add_task(p_task, p_label, p_amount); + bool step(const String &p_state, int p_step = -1, bool p_force_refresh = true) { return EditorNode::progress_task_step(task, p_state, p_step, p_force_refresh); } + EditorProgress(const String &p_task, const String &p_label, int p_amount, bool p_can_cancel = false) { + EditorNode::progress_add_task(p_task, p_label, p_amount, p_can_cancel); task = p_task; } ~EditorProgress() { EditorNode::progress_end_task(task); } diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 08d2897250..ed7c6dba79 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -1165,8 +1165,8 @@ void ResourceImporterScene::get_import_options(List<ImportOption> *r_options, in r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/compress"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/ensure_tangents"), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/storage", PROPERTY_HINT_ENUM, "Built-In,Files"), meshes_out ? 1 : 0)); - r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/light_baking", PROPERTY_HINT_ENUM, "Disabled,Enable,Gen Lightmaps"), 0)); - r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "meshes/lightmap_texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.05)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "meshes/light_baking", PROPERTY_HINT_ENUM, "Disabled,Enable,Gen Lightmaps", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "meshes/lightmap_texel_size", PROPERTY_HINT_RANGE, "0.001,100,0.001"), 0.1)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "external_files/store_in_subdir"), false)); r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "animation/import", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true)); r_options->push_back(ImportOption(PropertyInfo(Variant::REAL, "animation/fps", PROPERTY_HINT_RANGE, "1,120,1"), 15)); diff --git a/editor/plugins/baked_lightmap_editor_plugin.cpp b/editor/plugins/baked_lightmap_editor_plugin.cpp new file mode 100644 index 0000000000..9ae3a4c771 --- /dev/null +++ b/editor/plugins/baked_lightmap_editor_plugin.cpp @@ -0,0 +1,95 @@ +#include "baked_lightmap_editor_plugin.h" + +void BakedLightmapEditorPlugin::_bake() { + + if (lightmap) { + BakedLightmap::BakeError err; + if (get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root() == lightmap) { + err = lightmap->bake(lightmap); + } else { + err = lightmap->bake(lightmap->get_parent()); + } + + switch (err) { + case BakedLightmap::BAKE_ERROR_NO_SAVE_PATH: + EditorNode::get_singleton()->show_warning(TTR("Can't determine a save path for lightmap images.\nSave your scene (for images to be saved in the same dir), or pick a save path from the BakedLightmap properties.")); + break; + case BakedLightmap::BAKE_ERROR_NO_MESHES: + EditorNode::get_singleton()->show_warning(TTR("No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake Light' flag is on.")); + break; + case BakedLightmap::BAKE_ERROR_CANT_CREATE_IMAGE: + EditorNode::get_singleton()->show_warning(TTR("Failed creating lightmap images, make sure path is writable.")); + break; + defaut : {} + } + } +} + +void BakedLightmapEditorPlugin::edit(Object *p_object) { + + BakedLightmap *s = Object::cast_to<BakedLightmap>(p_object); + if (!s) + return; + + lightmap = s; +} + +bool BakedLightmapEditorPlugin::handles(Object *p_object) const { + + return p_object->is_class("BakedLightmap"); +} + +void BakedLightmapEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + bake->show(); + } else { + + bake->hide(); + } +} + +EditorProgress *BakedLightmapEditorPlugin::tmp_progress = NULL; + +void BakedLightmapEditorPlugin::bake_func_begin(int p_steps) { + + ERR_FAIL_COND(tmp_progress != NULL); + + tmp_progress = memnew(EditorProgress("bake_lightmaps", TTR("Bake Lightmaps"), p_steps, true)); +} + +bool BakedLightmapEditorPlugin::bake_func_step(int p_step, const String &p_description) { + + ERR_FAIL_COND_V(tmp_progress == NULL, false); + return tmp_progress->step(p_description, p_step); +} + +void BakedLightmapEditorPlugin::bake_func_end() { + ERR_FAIL_COND(tmp_progress == NULL); + memdelete(tmp_progress); + tmp_progress = NULL; +} + +void BakedLightmapEditorPlugin::_bind_methods() { + + ClassDB::bind_method("_bake", &BakedLightmapEditorPlugin::_bake); +} + +BakedLightmapEditorPlugin::BakedLightmapEditorPlugin(EditorNode *p_node) { + + editor = p_node; + bake = memnew(Button); + bake->set_icon(editor->get_gui_base()->get_icon("BakedLight", "EditorIcons")); + bake->set_text(TTR("Bake Lightmaps")); + bake->hide(); + bake->connect("pressed", this, "_bake"); + add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, bake); + lightmap = NULL; + + BakedLightmap::bake_begin_function = bake_func_begin; + BakedLightmap::bake_step_function = bake_func_step; + BakedLightmap::bake_end_function = bake_func_end; +} + +BakedLightmapEditorPlugin::~BakedLightmapEditorPlugin() { +} diff --git a/editor/plugins/baked_lightmap_editor_plugin.h b/editor/plugins/baked_lightmap_editor_plugin.h new file mode 100644 index 0000000000..d64c33884a --- /dev/null +++ b/editor/plugins/baked_lightmap_editor_plugin.h @@ -0,0 +1,39 @@ +#ifndef BAKED_LIGHTMAP_EDITOR_PLUGIN_H +#define BAKED_LIGHTMAP_EDITOR_PLUGIN_H + +#include "editor/editor_node.h" +#include "editor/editor_plugin.h" +#include "scene/3d/baked_lightmap.h" +#include "scene/resources/material.h" + +class BakedLightmapEditorPlugin : public EditorPlugin { + + GDCLASS(BakedLightmapEditorPlugin, EditorPlugin); + + BakedLightmap *lightmap; + + Button *bake; + EditorNode *editor; + + static EditorProgress *tmp_progress; + static void bake_func_begin(int p_steps); + static bool bake_func_step(int p_step, const String &p_description); + static void bake_func_end(); + + void _bake(); + +protected: + static void _bind_methods(); + +public: + virtual String get_name() const { return "BakedLightmap"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_object); + virtual bool handles(Object *p_object) const; + virtual void make_visible(bool p_visible); + + BakedLightmapEditorPlugin(EditorNode *p_node); + ~BakedLightmapEditorPlugin(); +}; + +#endif // BAKED_LIGHTMAP_EDITOR_PLUGIN_H diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index 09f5375bb4..2c2e5a7c9b 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -163,7 +163,7 @@ void ProgressDialog::_popup() { popup_centered(ms); } -void ProgressDialog::add_task(const String &p_task, const String &p_label, int p_steps) { +void ProgressDialog::add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel) { ERR_FAIL_COND(tasks.has(p_task)); Task t; @@ -180,17 +180,24 @@ void ProgressDialog::add_task(const String &p_task, const String &p_label, int p main->add_child(t.vb); tasks[p_task] = t; + if (p_can_cancel) { + cancel_hb->show(); + } else { + cancel_hb->hide(); + } + cancel_hb->raise(); + cancelled = false; _popup(); } -void ProgressDialog::task_step(const String &p_task, const String &p_state, int p_step, bool p_force_redraw) { +bool ProgressDialog::task_step(const String &p_task, const String &p_state, int p_step, bool p_force_redraw) { - ERR_FAIL_COND(!tasks.has(p_task)); + ERR_FAIL_COND_V(!tasks.has(p_task), cancelled); if (!p_force_redraw) { uint64_t tus = OS::get_singleton()->get_ticks_usec(); if (tus - last_progress_tick < 50000) //50ms - return; + return cancelled; } Task &t = tasks[p_task]; @@ -201,7 +208,11 @@ void ProgressDialog::task_step(const String &p_task, const String &p_state, int t.state->set_text(p_state); last_progress_tick = OS::get_singleton()->get_ticks_usec(); + if (cancel_hb->is_visible()) { + OS::get_singleton()->force_process_input(); + } Main::iteration(); // this will not work on a lot of platforms, so it's only meant for the editor + return cancelled; } void ProgressDialog::end_task(const String &p_task) { @@ -218,6 +229,14 @@ void ProgressDialog::end_task(const String &p_task) { _popup(); } +void ProgressDialog::_cancel_pressed() { + cancelled = true; +} + +void ProgressDialog::_bind_methods() { + ClassDB::bind_method("_cancel_pressed", &ProgressDialog::_cancel_pressed); +} + ProgressDialog::ProgressDialog() { main = memnew(VBoxContainer); @@ -226,4 +245,13 @@ ProgressDialog::ProgressDialog() { set_exclusive(true); last_progress_tick = 0; singleton = this; + cancel_hb = memnew(HBoxContainer); + main->add_child(cancel_hb); + cancel_hb->hide(); + cancel = memnew(Button); + cancel_hb->add_spacer(); + cancel_hb->add_child(cancel); + cancel->set_text(TTR("Cancel")); + cancel_hb->add_spacer(); + cancel->connect("pressed", this, "_cancel_pressed"); } diff --git a/editor/progress_dialog.h b/editor/progress_dialog.h index 8ac0907145..b13ea606bc 100644 --- a/editor/progress_dialog.h +++ b/editor/progress_dialog.h @@ -31,6 +31,7 @@ #define PROGRESS_DIALOG_H #include "scene/gui/box_container.h" +#include "scene/gui/button.h" #include "scene/gui/label.h" #include "scene/gui/popup.h" #include "scene/gui/progress_bar.h" @@ -76,6 +77,8 @@ class ProgressDialog : public Popup { ProgressBar *progress; Label *state; }; + HBoxContainer *cancel_hb; + Button *cancel; Map<String, Task> tasks; VBoxContainer *main; @@ -84,13 +87,17 @@ class ProgressDialog : public Popup { static ProgressDialog *singleton; void _popup(); + void _cancel_pressed(); + bool cancelled; + protected: void _notification(int p_what); + static void _bind_methods(); public: static ProgressDialog *get_singleton() { return singleton; } - void add_task(const String &p_task, const String &p_label, int p_steps); - void task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_redraw = true); + void add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false); + bool task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_redraw = true); void end_task(const String &p_task); ProgressDialog(); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index f785b3e198..8fddd2170f 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -2753,7 +2753,122 @@ GIProbeGizmo::GIProbeGizmo(GIProbe *p_probe) { } //////// +//////// + +/// + +String BakedIndirectLightGizmo::get_handle_name(int p_idx) const { + + switch (p_idx) { + case 0: return "Extents X"; + case 1: return "Extents Y"; + case 2: return "Extents Z"; + } + + return ""; +} +Variant BakedIndirectLightGizmo::get_handle_value(int p_idx) const { + + return baker->get_extents(); +} +void BakedIndirectLightGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) { + + Transform gt = baker->get_global_transform(); + //gt.orthonormalize(); + Transform gi = gt.affine_inverse(); + + Vector3 extents = baker->get_extents(); + + Vector3 ray_from = p_camera->project_ray_origin(p_point); + Vector3 ray_dir = p_camera->project_ray_normal(p_point); + + Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) }; + + Vector3 axis; + axis[p_idx] = 1.0; + + Vector3 ra, rb; + Geometry::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb); + float d = ra[p_idx]; + if (d < 0.001) + d = 0.001; + + extents[p_idx] = d; + baker->set_extents(extents); +} + +void BakedIndirectLightGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { + + Vector3 restore = p_restore; + + if (p_cancel) { + baker->set_extents(restore); + return; + } + + UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); + ur->create_action(TTR("Change Probe Extents")); + ur->add_do_method(baker, "set_extents", baker->get_extents()); + ur->add_undo_method(baker, "set_extents", restore); + ur->commit_action(); +} +void BakedIndirectLightGizmo::redraw() { + + Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/baked_indirect_light"); + Ref<Material> material = create_material("baked_indirect_light_material", gizmo_color); + Ref<Material> icon = create_icon_material("baked_indirect_light_icon", SpatialEditor::get_singleton()->get_icon("GizmoGIProbe", "EditorIcons")); + Color gizmo_color_internal = gizmo_color; + gizmo_color_internal.a = 0.1; + Ref<Material> material_internal = create_material("baked_indirect_light_internal_material", gizmo_color_internal); + + clear(); + + Vector<Vector3> lines; + Vector3 extents = baker->get_extents(); + + static const int subdivs[BakedLightmap::SUBDIV_MAX] = { 64, 128, 256, 512 }; + + AABB aabb = AABB(-extents, extents * 2); + int subdiv = subdivs[baker->get_bake_subdiv()]; + float cell_size = aabb.get_longest_axis_size() / subdiv; + + for (int i = 0; i < 12; i++) { + Vector3 a, b; + aabb.get_edge(i, a, b); + lines.push_back(a); + lines.push_back(b); + } + + add_lines(lines, material); + add_collision_segments(lines); + + Vector<Vector3> handles; + + for (int i = 0; i < 3; i++) { + + Vector3 ax; + ax[i] = aabb.position[i] + aabb.size[i]; + handles.push_back(ax); + } + + if (is_selected()) { + + gizmo_color.a = 0.1; + Ref<Material> solid_material = create_material("baked_indirect_light_solid_material", gizmo_color); + add_solid_box(solid_material, aabb.get_size()); + } + + add_unscaled_billboard(icon, 0.05); + add_handles(handles); +} +BakedIndirectLightGizmo::BakedIndirectLightGizmo(BakedLightmap *p_baker) { + + baker = p_baker; + set_spatial_node(p_baker); +} + +//////// void NavigationMeshSpatialGizmo::redraw() { Ref<Material> edge_material = create_material("navigation_material", EDITOR_GET("editors/3d_gizmos/gizmo_colors/navigation_edge")); @@ -3409,6 +3524,11 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { Ref<GIProbeGizmo> misg = memnew(GIProbeGizmo(Object::cast_to<GIProbe>(p_spatial))); return misg; } + if (Object::cast_to<BakedLightmap>(p_spatial)) { + + Ref<BakedIndirectLightGizmo> misg = memnew(BakedIndirectLightGizmo(Object::cast_to<BakedLightmap>(p_spatial))); + return misg; + } if (Object::cast_to<VehicleWheel>(p_spatial)) { @@ -3495,6 +3615,7 @@ SpatialEditorGizmos::SpatialEditorGizmos() { EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4)); EDITOR_DEF("editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5)); EDITOR_DEF("editors/3d_gizmos/gizmo_colors/gi_probe", Color(0.5, 1, 0.6)); + EDITOR_DEF("editors/3d_gizmos/gizmo_colors/baked_indirect_light", Color(0.5, 0.6, 1)); EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1)); EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_edge", Color(0.5, 1, 1)); diff --git a/editor/spatial_editor_gizmos.h b/editor/spatial_editor_gizmos.h index 751bad2b13..ea8a33d2c6 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -32,6 +32,7 @@ #include "editor/plugins/spatial_editor_plugin.h" #include "scene/3d/audio_stream_player_3d.h" +#include "scene/3d/baked_lightmap.h" #include "scene/3d/camera.h" #include "scene/3d/collision_polygon.h" #include "scene/3d/collision_shape.h" @@ -288,6 +289,22 @@ public: GIProbeGizmo(GIProbe *p_probe = NULL); }; +class BakedIndirectLightGizmo : public EditorSpatialGizmo { + + GDCLASS(BakedIndirectLightGizmo, EditorSpatialGizmo); + + BakedLightmap *baker; + +public: + virtual String get_handle_name(int p_idx) const; + virtual Variant get_handle_value(int p_idx) const; + virtual void set_handle(int p_idx, Camera *p_camera, const Point2 &p_point); + virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false); + + void redraw(); + BakedIndirectLightGizmo(BakedLightmap *p_baker = NULL); +}; + class CollisionShapeSpatialGizmo : public EditorSpatialGizmo { GDCLASS(CollisionShapeSpatialGizmo, EditorSpatialGizmo); |