diff options
author | Juan Linietsky <reduzio@gmail.com> | 2014-10-12 02:13:22 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2014-10-12 02:13:22 -0300 |
commit | 948fd83cdded7fed77ae5213101c1a2ece580434 (patch) | |
tree | a6953095dc4feaac1485c04b35039b85f1a95534 /tools/editor | |
parent | 37354da5b0dc1dc8dcfd9d844e593935311f4f8f (diff) |
Little Bits
-=-=-=-=-=-
-fix duplicate function bug when creating script callback in editor
-fix bug where hiding lights does not work
-fix 2D audio listener bug (romulox_x reported)
-fix exported properties with inheritance bug
-fix timer autostart (make it not work on editor)
-reactivate first camara found if viewport runs out of active camera
-option to hide gizmos in viewport
-changed skeleton gizmo because it sucks
-Make convex shapes using CollisionShape visible (use quickhull class)
-fix up menu when editing a mesh, to export collision, navmesh, convex, etc. from it.
-make a menu option to show SRGB in 3D editor views by default
-make option to edit default light direction in viewport settings
-make option to edit default ambient light in viewport settings
-make software conversion of linear->RGB if hardware support not found
Diffstat (limited to 'tools/editor')
-rw-r--r-- | tools/editor/editor_node.cpp | 4 | ||||
-rw-r--r-- | tools/editor/plugins/mesh_editor_plugin.cpp | 227 | ||||
-rw-r--r-- | tools/editor/plugins/mesh_editor_plugin.h | 68 | ||||
-rw-r--r-- | tools/editor/plugins/script_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | tools/editor/plugins/spatial_editor_plugin.cpp | 234 | ||||
-rw-r--r-- | tools/editor/plugins/spatial_editor_plugin.h | 39 | ||||
-rw-r--r-- | tools/editor/spatial_editor_gizmos.cpp | 131 |
7 files changed, 645 insertions, 60 deletions
diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 8c3eb844b7..701704fbfa 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -69,6 +69,7 @@ #include "plugins/item_list_editor_plugin.h" #include "plugins/stream_editor_plugin.h" #include "plugins/multimesh_editor_plugin.h" +#include "plugins/mesh_editor_plugin.h" #include "plugins/theme_editor_plugin.h" #include "plugins/tile_map_editor_plugin.h" @@ -2336,6 +2337,8 @@ void EditorNode::set_edited_scene(Node *p_scene) { if (edited_scene && edited_scene->cast_to<Popup>()) edited_scene->cast_to<Popup>()->show(); //show popups scene_tree_dock->set_edited_scene(edited_scene); + if (get_scene()) + get_scene()->set_edited_scene_root(edited_scene); if (edited_scene) { if (p_scene->get_parent()!=scene_root) @@ -3974,6 +3977,7 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( SampleLibraryEditorPlugin(this) ) ); add_editor_plugin( memnew( ThemeEditorPlugin(this) ) ); add_editor_plugin( memnew( MultiMeshEditorPlugin(this) ) ); + add_editor_plugin( memnew( MeshInstanceEditorPlugin(this) ) ); add_editor_plugin( memnew( AnimationTreeEditorPlugin(this) ) ); add_editor_plugin( memnew( SamplePlayerEditorPlugin(this) ) ); add_editor_plugin( memnew( MeshLibraryEditorPlugin(this) ) ); diff --git a/tools/editor/plugins/mesh_editor_plugin.cpp b/tools/editor/plugins/mesh_editor_plugin.cpp new file mode 100644 index 0000000000..b8a5bd3bbe --- /dev/null +++ b/tools/editor/plugins/mesh_editor_plugin.cpp @@ -0,0 +1,227 @@ +#include "mesh_editor_plugin.h" + +#include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_node.h" +#include "scene/3d/mesh_instance.h" +#include "scene/3d/physics_body.h" +#include "scene/3d/body_shape.h" +#include "scene/gui/spin_box.h" +#include "scene/gui/box_container.h" +#include "scene/3d/mesh_instance.h" +#include "scene/3d/navigation_mesh.h" +#include "spatial_editor_plugin.h" + +void MeshInstanceEditor::_node_removed(Node *p_node) { + + if(p_node==node) { + node=NULL; + options->hide(); + } + +} + + + +void MeshInstanceEditor::edit(MeshInstance *p_mesh) { + + node=p_mesh; + +} + +void MeshInstanceEditor::_menu_option(int p_option) { + + Ref<Mesh> mesh = node->get_mesh(); + if (mesh.is_null()) { + err_dialog->set_text("Mesh is empty!"); + err_dialog->popup_centered(Size2(100,50)); + return; + } + + switch(p_option) { + case MENU_OPTION_CREATE_STATIC_TRIMESH_BODY: { + + Ref<Shape> shape = mesh->create_trimesh_shape(); + if (shape.is_null()) + return; + StaticBody *body = memnew( StaticBody ); + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + body->add_child(cshape); + Node *owner = node==get_scene()->get_edited_scene_root() ? node : node->get_owner(); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Create Static Trimesh"); + ur->add_do_method(node,"add_child",body); + ur->add_do_method(body,"set_owner",owner); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(body); + ur->add_undo_method(node,"remove_child",body); + ur->commit_action(); + + } break; + case MENU_OPTION_CREATE_STATIC_CONVEX_BODY: { + + Ref<Shape> shape = mesh->create_convex_shape(); + if (shape.is_null()) + return; + StaticBody *body = memnew( StaticBody ); + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + body->add_child(cshape); + Node *owner = node==get_scene()->get_edited_scene_root() ? node : node->get_owner(); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Create Static Trimesh"); + ur->add_do_method(node,"add_child",body); + ur->add_do_method(body,"set_owner",owner); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(body); + ur->add_undo_method(node,"remove_child",body); + ur->commit_action(); + + } break; + case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: { + + + if (node==get_scene()->get_edited_scene_root()) { + err_dialog->set_text("This doesn't work on scene root!"); + err_dialog->popup_centered(Size2(100,50)); + return; + } + Ref<Shape> shape = mesh->create_trimesh_shape(); + if (shape.is_null()) + return; + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + + Node *owner = node->get_owner(); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Create Static Trimesh"); + ur->add_do_method(node->get_parent(),"add_child",cshape); + ur->add_do_method(node->get_parent(),"move_child",cshape,node->get_index()+1); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(cshape); + ur->add_undo_method(node->get_parent(),"remove_child",cshape); + ur->commit_action(); + + } break; + case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: { + + + if (node==get_scene()->get_edited_scene_root()) { + err_dialog->set_text("This doesn't work on scene root!"); + err_dialog->popup_centered(Size2(100,50)); + return; + } + Ref<Shape> shape = mesh->create_convex_shape(); + if (shape.is_null()) + return; + CollisionShape *cshape = memnew( CollisionShape ); + cshape->set_shape(shape); + + Node *owner = node->get_owner(); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Create Static Trimesh"); + ur->add_do_method(node->get_parent(),"add_child",cshape); + ur->add_do_method(node->get_parent(),"move_child",cshape,node->get_index()+1); + ur->add_do_method(cshape,"set_owner",owner); + ur->add_do_reference(cshape); + ur->add_undo_method(node->get_parent(),"remove_child",cshape); + ur->commit_action(); + + } break; + case MENU_OPTION_CREATE_NAVMESH: { + + + + + Ref<NavigationMesh> nmesh = memnew( NavigationMesh ); + + if (nmesh.is_null()) + return; + + nmesh->create_from_mesh(mesh); + NavigationMeshInstance *nmi = memnew( NavigationMeshInstance ); + nmi->set_navigation_mesh(nmesh); + + Node *owner = node==get_scene()->get_edited_scene_root() ? node : node->get_owner(); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Create Navigation Mesh"); + + ur->add_do_method(node,"add_child",nmi); + ur->add_do_method(nmi,"set_owner",owner); + + ur->add_do_reference(nmi); + ur->add_undo_method(node,"remove_child",nmi); + ur->commit_action(); + } break; + } + +} + +void MeshInstanceEditor::_bind_methods() { + + ObjectTypeDB::bind_method("_menu_option",&MeshInstanceEditor::_menu_option); +} + +MeshInstanceEditor::MeshInstanceEditor() { + + + options = memnew( MenuButton ); + //add_child(options); + SpatialEditor::get_singleton()->add_control_to_menu_panel(options); + + options->set_text("Mesh"); + options->get_popup()->add_item("Create Trimesh Static Body",MENU_OPTION_CREATE_STATIC_TRIMESH_BODY); + options->get_popup()->add_item("Create Convex Static Body",MENU_OPTION_CREATE_STATIC_CONVEX_BODY); + options->get_popup()->add_separator(); + options->get_popup()->add_item("Create Trimesh Collision Sibling",MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE); + options->get_popup()->add_item("Create Convex Collision Sibling",MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE); + options->get_popup()->add_separator(); + options->get_popup()->add_item("Create Navigation Mesh",MENU_OPTION_CREATE_NAVMESH); + + options->get_popup()->connect("item_pressed", this,"_menu_option"); + +} + + +void MeshInstanceEditorPlugin::edit(Object *p_object) { + + mesh_editor->edit(p_object->cast_to<MeshInstance>()); +} + +bool MeshInstanceEditorPlugin::handles(Object *p_object) const { + + return p_object->is_type("MeshInstance"); +} + +void MeshInstanceEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + mesh_editor->options->show(); + } else { + + mesh_editor->options->hide(); + mesh_editor->edit(NULL); + } + +} + +MeshInstanceEditorPlugin::MeshInstanceEditorPlugin(EditorNode *p_node) { + + editor=p_node; + mesh_editor = memnew( MeshInstanceEditor ); + editor->get_viewport()->add_child(mesh_editor); + + mesh_editor->options->hide(); +} + + +MeshInstanceEditorPlugin::~MeshInstanceEditorPlugin() +{ +} + + diff --git a/tools/editor/plugins/mesh_editor_plugin.h b/tools/editor/plugins/mesh_editor_plugin.h new file mode 100644 index 0000000000..557eb90148 --- /dev/null +++ b/tools/editor/plugins/mesh_editor_plugin.h @@ -0,0 +1,68 @@ +#ifndef MESH_EDITOR_PLUGIN_H +#define MESH_EDITOR_PLUGIN_H + + +#include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_node.h" +#include "scene/3d/mesh_instance.h" +#include "scene/gui/spin_box.h" + + +class MeshInstanceEditor : public Node { + + OBJ_TYPE(MeshInstanceEditor, Node ); + + + enum Menu { + + MENU_OPTION_CREATE_STATIC_TRIMESH_BODY, + MENU_OPTION_CREATE_STATIC_CONVEX_BODY, + MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE, + MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE, + MENU_OPTION_CREATE_NAVMESH, + }; + + AcceptDialog *err_dialog; + + + Panel *panel; + MeshInstance *node; + + LineEdit *surface_source; + LineEdit *mesh_source; + + + void _menu_option(int p_option); +friend class MeshInstanceEditorPlugin; + MenuButton * options; + +protected: + void _node_removed(Node *p_node); + static void _bind_methods(); +public: + + void edit(MeshInstance *p_mesh); + MeshInstanceEditor(); +}; + +class MeshInstanceEditorPlugin : public EditorPlugin { + + OBJ_TYPE( MeshInstanceEditorPlugin, EditorPlugin ); + + MeshInstanceEditor *mesh_editor; + EditorNode *editor; + +public: + + virtual String get_name() const { return "MeshInstance"; } + bool has_main_screen() const { return false; } + virtual void edit(Object *p_node); + virtual bool handles(Object *p_node) const; + virtual void make_visible(bool p_visible); + + MeshInstanceEditorPlugin(EditorNode *p_node); + ~MeshInstanceEditorPlugin(); + +}; + +#endif // MESH_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index ba6e153e2c..24e09111e2 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -1286,7 +1286,7 @@ void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const continue; String code = ste->get_text_edit()->get_text(); - int pos = script->get_language()->find_function(code,p_function); + int pos = script->get_language()->find_function(p_function,code); if (pos==-1) { //does not exist diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index f0d0d53dd5..8f3f4dea8e 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -860,10 +860,19 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { _edit.snap=false; _edit.mode=TRANSFORM_NONE; + //gizmo has priority over everything + bool can_select_gizmos=true; + + { + int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); + can_select_gizmos = view_menu->get_popup()->is_item_checked( idx ); + } + + - if (spatial_editor->get_selected()) { + if (can_select_gizmos && spatial_editor->get_selected()) { Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo(); if (seg.is_valid()) { @@ -1934,6 +1943,18 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked( idx, current ); } break; + case VIEW_GIZMOS: { + + int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS); + bool current = view_menu->get_popup()->is_item_checked( idx ); + current=!current; + if (current) + camera->set_visible_layers( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+index))|(1<<GIZMO_EDIT_LAYER) ); + else + camera->set_visible_layers( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+index)) ); + view_menu->get_popup()->set_item_checked( idx, current ); + + } break; } @@ -2115,6 +2136,9 @@ void SpatialEditorViewport::reset() { cursor.distance=4; cursor.region_select=false; + + + } SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, EditorNode *p_editor, int p_index) { @@ -2139,7 +2163,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed surface->set_area_as_parent_rect(); camera = memnew(Camera); camera->set_disable_gizmo(true); - camera->set_visible_layers( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+p_index)) ); + camera->set_visible_layers( ((1<<20)-1)|(1<<(GIZMO_BASE_LAYER+p_index))|(1<<GIZMO_EDIT_LAYER) ); //camera->set_environment(SpatialEditor::get_singleton()->get_viewport_environment()); viewport->add_child(camera); camera->make_current(); @@ -2166,6 +2190,9 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT),true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_item("Audio Listener",VIEW_AUDIO_LISTENER); + view_menu->get_popup()->add_separator(); + view_menu->get_popup()->add_check_item("Gizmos",VIEW_GIZMOS); + view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_GIZMOS),true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_item("Selection (F)",VIEW_CENTER_TO_SELECTION); @@ -2362,11 +2389,16 @@ Dictionary SpatialEditor::get_state() const { d["viewports"]=vpdata; d["default_light"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT) );; + d["ambient_light_color"]=settings_ambient_color->get_color(); + + d["default_srgb"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB) );; d["show_grid"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_GRID) );; d["show_origin"]=view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_ORIGIN) );; d["fov"]=get_fov(); d["znear"]=get_znear(); d["zfar"]=get_zfar(); + d["deflight_rot_x"]=settings_default_light_rot_x; + d["deflight_rot_y"]=settings_default_light_rot_y; return d; } @@ -2407,11 +2439,12 @@ void SpatialEditor::set_state(const Dictionary& p_state) { if (d.has("zfar")) - settings_zfar->set_text(d["zfar"]); + settings_zfar->set_val(float(d["zfar"])); if (d.has("znear")) - settings_znear->set_text(d["znear"]); + settings_znear->set_val(float(d["znear"])); if (d.has("fov")) - settings_fov->set_text(d["fov"]); + settings_fov->set_val(float(d["fov"])); + if (d.has("default_light")) { bool use = d["default_light"]; @@ -2429,7 +2462,17 @@ void SpatialEditor::set_state(const Dictionary& p_state) { } } + if (d.has("ambient_light_color")) { + settings_ambient_color->set_color(d["ambient_light_color"]); + viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,d["ambient_light_color"]); + } + + if (d.has("default_srgb")) { + bool use = d["default_light"]; + viewport_environment->set_enable_fx(Environment::FX_SRGB,use); + view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_USE_DEFAULT_SRGB), use ); + } if (d.has("show_grid")) { bool use = d["show_grid"]; @@ -2447,6 +2490,12 @@ void SpatialEditor::set_state(const Dictionary& p_state) { } } + if (d.has("deflight_rot_x")) + settings_default_light_rot_x=d["deflight_rot_x"]; + if (d.has("deflight_rot_y")) + settings_default_light_rot_y=d["deflight_rot_y"]; + + _update_default_light_angle(); } @@ -2609,11 +2658,29 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } else { light_instance=VisualServer::get_singleton()->instance_create2(light,get_scene()->get_root()->get_world()->get_scenario()); VisualServer::get_singleton()->instance_set_transform(light_instance,light_transform); + + _update_default_light_angle(); } view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(p_option), light_instance.is_valid() ); } break; + case MENU_VIEW_USE_DEFAULT_SRGB: { + + bool is_checked = view_menu->get_popup()->is_item_checked( view_menu->get_popup()->get_item_index(p_option) ); + + if (is_checked) { + viewport_environment->set_enable_fx(Environment::FX_SRGB,false); + } else { + viewport_environment->set_enable_fx(Environment::FX_SRGB,true); + } + + is_checked = ! is_checked; + + view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(p_option), is_checked ); + + + } break; case MENU_VIEW_USE_1_VIEWPORT: { for(int i=1;i<4;i++) { @@ -2824,7 +2891,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_CAMERA_SETTINGS: { - settings_dialog->popup_centered(Size2(200,160)); + settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size()+Size2(50,50)); } break; } @@ -3233,13 +3300,15 @@ void SpatialEditor::_notification(int p_what) { _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); get_scene()->connect("node_removed",this,"_node_removed"); + VS::get_singleton()->scenario_set_fallback_environment(get_viewport()->find_world()->get_scenario(),viewport_environment->get_rid()); + } if (p_what==NOTIFICATION_ENTER_SCENE) { gizmos = memnew( SpatialEditorGizmos ); _init_indicators(); - + _update_default_light_angle(); } if (p_what==NOTIFICATION_EXIT_SCENE) { @@ -3374,7 +3443,8 @@ void SpatialEditor::_bind_methods() { // ObjectTypeDB::bind_method("_update_selection",&SpatialEditor::_update_selection); ObjectTypeDB::bind_method("_get_editor_data",&SpatialEditor::_get_editor_data); ObjectTypeDB::bind_method("_request_gizmo",&SpatialEditor::_request_gizmo); - + ObjectTypeDB::bind_method("_default_light_angle_input",&SpatialEditor::_default_light_angle_input); + ObjectTypeDB::bind_method("_update_ambient_light_color",&SpatialEditor::_update_ambient_light_color); ObjectTypeDB::bind_method("_toggle_maximize_view",&SpatialEditor::_toggle_maximize_view); ADD_SIGNAL( MethodInfo("transform_key_request") ); @@ -3384,9 +3454,9 @@ void SpatialEditor::_bind_methods() { void SpatialEditor::clear() { - settings_fov->set_text(EDITOR_DEF("3d_editor/default_fov",60.0)); - settings_znear->set_text(EDITOR_DEF("3d_editor/default_z_near",0.1)); - settings_zfar->set_text(EDITOR_DEF("3d_editor/default_z_far",1500.0)); + settings_fov->set_val(EDITOR_DEF("3d_editor/default_fov",60.0)); + settings_znear->set_val(EDITOR_DEF("3d_editor/default_z_near",0.1)); + settings_zfar->set_val(EDITOR_DEF("3d_editor/default_z_far",1500.0)); for(int i=0;i<4;i++) { viewports[i]->reset(); @@ -3410,11 +3480,54 @@ void SpatialEditor::clear() { viewports[i]->view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(SpatialEditorViewport::VIEW_AUDIO_LISTENER),i==0); viewports[i]->viewport->set_as_audio_listener(i==0); } + view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_GRID), true ); + settings_default_light_rot_x=Math_PI*0.3; + settings_default_light_rot_y=Math_PI*0.2; + + viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15)); + settings_ambient_color->set_color(Color(0.15,0.15,0.15)); + if (!light_instance.is_valid()) + _menu_item_pressed(MENU_VIEW_USE_DEFAULT_LIGHT); + + _update_default_light_angle(); + + +} + + +void SpatialEditor::_update_ambient_light_color(const Color& p_color) { + + viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,settings_ambient_color->get_color()); + +} + +void SpatialEditor::_update_default_light_angle() { + + Transform t; + t.basis.rotate(Vector3(1,0,0),settings_default_light_rot_x); + t.basis.rotate(Vector3(0,1,0),settings_default_light_rot_y); + settings_dlight->set_transform(t); + if (light_instance.is_valid()) { + VS::get_singleton()->instance_set_transform(light_instance,t); + } + +} + +void SpatialEditor::_default_light_angle_input(const InputEvent& p_event) { + + + if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&(0x1|0x2|0x4)) { + + settings_default_light_rot_y = Math::fposmod(settings_default_light_rot_y - p_event.mouse_motion.relative_x*0.01,Math_PI*2.0); + settings_default_light_rot_x = Math::fposmod(settings_default_light_rot_x - p_event.mouse_motion.relative_y*0.01,Math_PI*2.0); + _update_default_light_angle(); + } } + SpatialEditor::SpatialEditor(EditorNode *p_editor) { @@ -3510,6 +3623,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p = view_menu->get_popup(); p->add_check_item("Use Default Light",MENU_VIEW_USE_DEFAULT_LIGHT); + p->add_check_item("Use Default sRGB",MENU_VIEW_USE_DEFAULT_SRGB); p->add_separator(); p->add_check_item("1 Viewport",MENU_VIEW_USE_1_VIEWPORT,KEY_MASK_ALT+KEY_1); @@ -3612,42 +3726,68 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { settings_dialog = memnew( ConfirmationDialog ); settings_dialog->set_title("Viewport Settings"); add_child(settings_dialog); - l = memnew(Label); - l->set_text("Perspective FOV (deg.):"); - l->set_pos(Point2(5,5)); - settings_dialog->add_child(l); - - settings_fov = memnew( LineEdit ); - settings_fov->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - settings_fov->set_begin( Point2(15,22) ); - settings_fov->set_end( Point2(15,35) ); - settings_fov->set_text(EDITOR_DEF("3d_editor/default_fov",60.0)); - settings_dialog->add_child(settings_fov); - - l = memnew(Label); - l->set_text("View Z-Near"); - l->set_pos(Point2(5,45)); - settings_dialog->add_child(l); - - settings_znear = memnew( LineEdit ); - settings_znear->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - settings_znear->set_begin( Point2(15,62) ); - settings_znear->set_end( Point2(15,75) ); - settings_znear->set_text(EDITOR_DEF("3d_editor/default_z_near",0.1)); - settings_dialog->add_child(settings_znear); - - - l = memnew(Label); - l->set_text("View Z-Far"); - l->set_pos(Point2(5,85)); - settings_dialog->add_child(l); - - settings_zfar = memnew( LineEdit ); - settings_zfar->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - settings_zfar->set_begin( Point2(15,102) ); - settings_zfar->set_end( Point2(15,115) ); - settings_zfar->set_text(EDITOR_DEF("3d_editor/default_z_far",1500.0)); - settings_dialog->add_child(settings_zfar); + settings_vbc = memnew( VBoxContainer ); + settings_vbc->set_custom_minimum_size(Size2(200,0)); + settings_dialog->add_child(settings_vbc); + settings_dialog->set_child_rect(settings_vbc); + + + + settings_light_base = memnew( Control ); + settings_light_base->set_custom_minimum_size(Size2(128,128)); + settings_light_base->connect("input_event",this,"_default_light_angle_input"); + settings_vbc->add_margin_child("Default Light Normal:",settings_light_base); + settings_light_vp = memnew( Viewport ); + settings_light_vp->set_use_own_world(true); + settings_light_base->add_child(settings_light_vp); + + settings_dlight = memnew( DirectionalLight ); + settings_light_vp->add_child(settings_dlight); + settings_sphere = memnew( ImmediateGeometry ); + settings_sphere->begin(Mesh::PRIMITIVE_TRIANGLES,Ref<Texture>()); + settings_sphere->set_color(Color(1,1,1)); + settings_sphere->add_sphere(32,16,1); + settings_sphere->end(); + settings_light_vp->add_child(settings_sphere); + settings_camera = memnew( Camera ); + settings_light_vp->add_child(settings_camera); + settings_camera->set_translation(Vector3(0,0,2)); + settings_camera->set_orthogonal(2.1,0.1,5); + + settings_default_light_rot_x=Math_PI*0.3; + settings_default_light_rot_y=Math_PI*0.2; + + + + settings_ambient_color = memnew( ColorPickerButton ); + settings_vbc->add_margin_child("Ambient Light Color:",settings_ambient_color); + settings_ambient_color->connect("color_changed",this,"_update_ambient_light_color"); + + viewport_environment->set_enable_fx(Environment::FX_AMBIENT_LIGHT,true); + viewport_environment->fx_set_param(Environment::FX_PARAM_AMBIENT_LIGHT_COLOR,Color(0.15,0.15,0.15)); + settings_ambient_color->set_color(Color(0.15,0.15,0.15)); + + + settings_fov = memnew( SpinBox ); + settings_fov->set_max(179); + settings_fov->set_min(1); + settings_fov->set_step(0.01); + settings_fov->set_val(EDITOR_DEF("3d_editor/default_fov",60.0)); + settings_vbc->add_margin_child("Perspective FOV (deg.):",settings_fov); + + settings_znear = memnew( SpinBox ); + settings_znear->set_max(10000); + settings_znear->set_min(0.1); + settings_znear->set_step(0.01); + settings_znear->set_val(EDITOR_DEF("3d_editor/default_z_near",0.1)); + settings_vbc->add_margin_child("View Z-Near:",settings_znear); + + settings_zfar = memnew( SpinBox ); + settings_zfar->set_max(10000); + settings_zfar->set_min(0.1); + settings_zfar->set_step(0.01); + settings_zfar->set_val(EDITOR_DEF("3d_editor/default_z_far",1500)); + settings_vbc->add_margin_child("View Z-Far:",settings_zfar); //settings_dialog->get_cancel()->hide(); /* XFORM DIALOG */ diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h index 1b50f180d5..797ef08099 100644 --- a/tools/editor/plugins/spatial_editor_plugin.h +++ b/tools/editor/plugins/spatial_editor_plugin.h @@ -32,6 +32,8 @@ #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_node.h" #include "scene/3d/visual_instance.h" +#include "scene/3d/immediate_geometry.h" +#include "scene/3d/light.h" #include "scene/gui/panel_container.h" /** @author Juan Linietsky <reduzio@gmail.com> @@ -80,11 +82,14 @@ friend class SpatialEditor; VIEW_ENVIRONMENT, VIEW_ORTHOGONAL, VIEW_AUDIO_LISTENER, + VIEW_GIZMOS, }; +public: enum { - GIZMO_BASE_LAYER=25 + GIZMO_BASE_LAYER=27, + GIZMO_EDIT_LAYER=26 }; - +private: int index; void _menu_option(int p_option); Size2 prev_size; @@ -349,6 +354,7 @@ private: MENU_VIEW_USE_3_VIEWPORTS_ALT, MENU_VIEW_USE_4_VIEWPORTS, MENU_VIEW_USE_DEFAULT_LIGHT, + MENU_VIEW_USE_DEFAULT_SRGB, MENU_VIEW_DISPLAY_NORMAL, MENU_VIEW_DISPLAY_WIREFRAME, MENU_VIEW_DISPLAY_OVERDRAW, @@ -382,15 +388,28 @@ private: LineEdit *xform_scale[3]; OptionButton *xform_type; - LineEdit *settings_fov; - LineEdit *settings_znear; - LineEdit *settings_zfar; + VBoxContainer *settings_vbc; + SpinBox *settings_fov; + SpinBox *settings_znear; + SpinBox *settings_zfar; + DirectionalLight *settings_dlight; + ImmediateGeometry *settings_sphere; + Camera *settings_camera; + float settings_default_light_rot_x; + float settings_default_light_rot_y; + + Control *settings_light_base; + Viewport *settings_light_vp; + ColorPickerButton *settings_ambient_color; + Image settings_light_dir_image; + void _xform_dialog_action(); void _menu_item_pressed(int p_option); HBoxContainer *hbc_menu; + // // void _generate_selection_box(); @@ -420,6 +439,10 @@ private: SpatialEditorGizmos *gizmos; SpatialEditor(); + void _update_ambient_light_color(const Color& p_color); + void _update_default_light_angle(); + void _default_light_angle_input(const InputEvent& p_event); + protected: @@ -436,9 +459,9 @@ public: static SpatialEditor *get_singleton() { return singleton; } void snap_cursor_to_plane(const Plane& p_plane); - float get_znear() const { return settings_znear->get_text().to_double(); } - float get_zfar() const { return settings_zfar->get_text().to_double(); } - float get_fov() const { return settings_fov->get_text().to_double(); } + float get_znear() const { return settings_znear->get_val(); } + float get_zfar() const { return settings_zfar->get_val(); } + float get_fov() const { return settings_fov->get_val(); } Transform get_gizmo_transform() const { return gizmo.transform; } bool is_gizmo_visible() const { return gizmo.visible; } diff --git a/tools/editor/spatial_editor_gizmos.cpp b/tools/editor/spatial_editor_gizmos.cpp index c613a34895..04d5888861 100644 --- a/tools/editor/spatial_editor_gizmos.cpp +++ b/tools/editor/spatial_editor_gizmos.cpp @@ -36,7 +36,7 @@ #include "scene/resources/ray_shape.h"
#include "scene/resources/convex_polygon_shape.h"
#include "scene/resources/plane_shape.h"
-
+#include "quick_hull.h"
// Keep small children away from this file.
// It's so ugly it will eat them alive
@@ -75,6 +75,7 @@ void SpatialGizmoTool::Instance::create_instance(Spatial *p_base) { VS::get_singleton()->instance_set_extra_visibility_margin(instance,1);
VS::get_singleton()->instance_geometry_set_flag(instance,VS::INSTANCE_FLAG_CAST_SHADOW,false);
VS::get_singleton()->instance_geometry_set_flag(instance,VS::INSTANCE_FLAG_RECEIVE_SHADOWS,false);
+ VS::get_singleton()->instance_set_layer_mask(instance,1<<SpatialEditorViewport::GIZMO_EDIT_LAYER); //gizmos are 26
}
@@ -1237,6 +1238,10 @@ void SkeletonSpatialGizmo::redraw() { weights[0]=1;
+ AABB aabb;
+
+ Color bonecolor = Color(1.0,0.4,0.4,0.3);
+ Color rootcolor = Color(0.4,1.0,0.4,0.1);
for (int i=0;i<skel->get_bone_count();i++) {
@@ -1247,8 +1252,96 @@ void SkeletonSpatialGizmo::redraw() { Vector3 v0 = grests[parent].origin;
Vector3 v1 = grests[i].origin;
+ Vector3 d = (v1-v0).normalized();
+ float dist = v0.distance_to(v1);
+
+ //find closest axis
+ int closest=-1;
+ float closest_d;
+ for(int j=0;j<3;j++) {
+ float dp = Math::abs(grests[parent].basis[j].normalized().dot(d));
+ if (j==0 || dp>closest_d)
+ closest=j;
+ }
+
+ //find closest other
+ Vector3 first;
+ Vector3 points[4];
+ int pointidx=0;
+ for(int j=0;j<3;j++) {
+
+ bones[0]=parent;
+ surface_tool->add_bones(bones);
+ surface_tool->add_weights(weights);
+ surface_tool->add_color(rootcolor);
+ surface_tool->add_vertex(v0-grests[parent].basis[j].normalized()*dist*0.05);
+ surface_tool->add_bones(bones);
+ surface_tool->add_weights(weights);
+ surface_tool->add_color(rootcolor);
+ surface_tool->add_vertex(v0+grests[parent].basis[j].normalized()*dist*0.05);
+
+ if (j==closest)
+ continue;
+
+ Vector3 axis;
+ if (first==Vector3()) {
+ axis = d.cross(d.cross(grests[parent].basis[j])).normalized();
+ first=axis;
+ } else {
+ axis = d.cross(first).normalized();
+ }
+
+ for(int k=0;k<2;k++) {
+
+ if (k==1)
+ axis=-axis;
+ Vector3 point = v0+d*dist*0.2;
+ point+=axis*dist*0.1;
+
+
+ bones[0]=parent;
+ surface_tool->add_bones(bones);
+ surface_tool->add_weights(weights);
+ surface_tool->add_color(bonecolor);
+ surface_tool->add_vertex(v0);
+ surface_tool->add_bones(bones);
+ surface_tool->add_weights(weights);
+ surface_tool->add_color(bonecolor);
+ surface_tool->add_vertex(point);
+
+ bones[0]=parent;
+ surface_tool->add_bones(bones);
+ surface_tool->add_weights(weights);
+ surface_tool->add_color(bonecolor);
+ surface_tool->add_vertex(point);
+ bones[0]=i;
+ surface_tool->add_bones(bones);
+ surface_tool->add_weights(weights);
+ surface_tool->add_color(bonecolor);
+ surface_tool->add_vertex(v1);
+ points[pointidx++]=point;
+
+ }
+
+ }
+
+ SWAP( points[1],points[2] );
+ for(int j=0;j<4;j++) {
+
+
+ bones[0]=parent;
+ surface_tool->add_bones(bones);
+ surface_tool->add_weights(weights);
+ surface_tool->add_color(bonecolor);
+ surface_tool->add_vertex(points[j]);
+ surface_tool->add_bones(bones);
+ surface_tool->add_weights(weights);
+ surface_tool->add_color(bonecolor);
+ surface_tool->add_vertex(points[(j+1)%4]);
+ }
+/*
bones[0]=parent;
surface_tool->add_bones(bones);
surface_tool->add_weights(weights);
@@ -1259,13 +1352,13 @@ void SkeletonSpatialGizmo::redraw() { surface_tool->add_weights(weights);
surface_tool->add_color(Color(0.4,1,0.4,0.4));
surface_tool->add_vertex(v1);
-
+*/
} else {
grests[i]=skel->get_bone_rest(i);
bones[0]=i;
}
-
+/*
Transform t = grests[i];
t.orthonormalize();
@@ -1302,6 +1395,7 @@ void SkeletonSpatialGizmo::redraw() { }
}
+ */
}
Ref<Mesh> m = surface_tool->commit();
@@ -1978,6 +2072,34 @@ void CollisionShapeSpatialGizmo::redraw(){ }
+ if (s->cast_to<ConvexPolygonShape>()) {
+
+ DVector<Vector3> points = s->cast_to<ConvexPolygonShape>()->get_points();
+
+ if (points.size()>3) {
+
+ QuickHull qh;
+ Vector<Vector3> varr = Variant(points);
+ Geometry::MeshData md;
+ Error err = qh.build(varr,md);
+ if (err==OK) {
+ Vector<Vector3> points;
+ points.resize(md.edges.size()*2);
+ for(int i=0;i<md.edges.size();i++) {
+ points[i*2+0]=md.vertices[md.edges[i].a];
+ points[i*2+1]=md.vertices[md.edges[i].b];
+ }
+
+
+ add_lines(points,SpatialEditorGizmos::singleton->shape_material);
+ add_collision_segments(points);
+
+ }
+ }
+
+ }
+
+
if (s->cast_to<RayShape>()) {
Ref<RayShape> rs=s;
@@ -2210,7 +2332,8 @@ void NavigationMeshSpatialGizmo::redraw() { Ref<TriangleMesh> tmesh = memnew( TriangleMesh);
tmesh->create(tmeshfaces);
- add_lines(lines,navmesh->is_enabled()?SpatialEditorGizmos::singleton->navmesh_edge_material:SpatialEditorGizmos::singleton->navmesh_edge_material_disabled);
+ if (lines.size())
+ add_lines(lines,navmesh->is_enabled()?SpatialEditorGizmos::singleton->navmesh_edge_material:SpatialEditorGizmos::singleton->navmesh_edge_material_disabled);
add_collision_triangles(tmesh);
Ref<Mesh> m = memnew( Mesh );
Array a;
|