diff options
Diffstat (limited to 'tools')
263 files changed, 8204 insertions, 2189 deletions
diff --git a/tools/SCsub b/tools/SCsub index 875663b849..ce7df2c35b 100644 --- a/tools/SCsub +++ b/tools/SCsub @@ -5,16 +5,17 @@ env.add_source_files(env.tool_sources,"*.cpp") Export('env') -SConscript('editor/SCsub'); -#SConscript('scintilla/SCsub'); -SConscript('collada/SCsub'); -SConscript('docdump/SCsub'); -SConscript('freetype/SCsub'); -SConscript('doc/SCsub'); -SConscript('pck/SCsub'); +if (env["tools"]!="no"): + SConscript('editor/SCsub'); + #SConscript('scintilla/SCsub'); + SConscript('collada/SCsub'); + SConscript('docdump/SCsub'); + SConscript('freetype/SCsub'); + SConscript('doc/SCsub') + SConscript('pck/SCsub') -lib = env.Library("tool",env.tool_sources) + lib = env.Library("tool",env.tool_sources) -env.Prepend(LIBS=[lib]) + env.Prepend(LIBS=[lib]) diff --git a/tools/collada/collada.cpp b/tools/collada/collada.cpp index 7f4f92e82d..b55edde801 100644 --- a/tools/collada/collada.cpp +++ b/tools/collada/collada.cpp @@ -817,7 +817,7 @@ void Collada::_parse_camera(XMLParser& parser) { if (name=="perspective") { camera.mode=CameraData::MODE_PERSPECTIVE; - } else if (name=="orthogonal") { + } else if (name=="orthographic") { camera.mode=CameraData::MODE_ORTHOGONAL; } else if (name=="xfov") { @@ -2106,6 +2106,8 @@ void Collada::_parse_animation_clip(XMLParser& parser) { if (parser.has_attribute("name")) clip.name=parser.get_attribute_value("name"); + else if (parser.has_attribute("id")) + clip.name=parser.get_attribute_value("id"); if (parser.has_attribute("start")) clip.begin=parser.get_attribute_value("start").to_double(); if (parser.has_attribute("end")) @@ -2248,29 +2250,35 @@ void Collada::_joint_set_owner(Collada::Node *p_node, NodeSkeleton *p_owner) { } } -void Collada::_create_skeletons(Collada::Node **p_node) { +void Collada::_create_skeletons(Collada::Node **p_node,NodeSkeleton *p_skeleton) { Node *node = *p_node; - - if (node->type==Node::TYPE_JOINT) { - // ohohohoohoo it's a joint node, time to work! + if (!p_skeleton) { + + // ohohohoohoo it's a joint node, time to work! + NodeSkeleton *sk = memnew( NodeSkeleton ); + *p_node=sk; + sk->children.push_back(node); + sk->parent=node->parent; + node->parent=sk; + p_skeleton=sk; + } - NodeSkeleton *sk = memnew( NodeSkeleton ); - *p_node=sk; - sk->children.push_back(node); - sk->parent=node->parent; - node->parent=sk; - _joint_set_owner(node,sk); + NodeJoint *nj = static_cast<NodeJoint*>(node); + nj->owner=p_skeleton; } else { + p_skeleton=NULL; + } - for(int i=0;i<node->children.size();i++) { - _create_skeletons(&node->children[i]); - } + + for(int i=0;i<node->children.size();i++) { + _create_skeletons(&node->children[i],p_skeleton); } + } bool Collada::_remove_node(Node *p_parent,Node *p_node) { @@ -2323,6 +2331,9 @@ void Collada::_merge_skeletons(VisualScene *p_vscene,Node *p_node) { NodeJoint *nj = SAFE_CAST<NodeJoint*>(state.scene_map[nodeid]); + if (!nj->owner) { + print_line("no owner for: "+String(nodeid)); + } ERR_CONTINUE( !nj->owner ); //weird, node should have a skeleton owner skeletons.insert(nj->owner); @@ -2624,6 +2635,7 @@ void Collada::_optimize() { _create_skeletons(&vs.root_nodes[i]); } +#if 1 for(int i=0;i<vs.root_nodes.size();i++) { _merge_skeletons(&vs,vs.root_nodes[i]); } @@ -2651,6 +2663,7 @@ void Collada::_optimize() { } } +#endif for(int i=0;i<vs.root_nodes.size();i++) { _find_morph_nodes(&vs,vs.root_nodes[i]); } diff --git a/tools/collada/collada.h b/tools/collada/collada.h index c5e5705105..7691d90c0a 100644 --- a/tools/collada/collada.h +++ b/tools/collada/collada.h @@ -337,6 +337,24 @@ public: if(normal==p_vert.normal) { if(uv==p_vert.uv) { if(uv2==p_vert.uv2) { + + if (!weights.empty() || !p_vert.weights.empty()) { + + if (weights.size()==p_vert.weights.size()) { + + for(int i=0;i<weights.size();i++) { + if (weights[i].bone_idx!=p_vert.weights[i].bone_idx) + return weights[i].bone_idx<p_vert.weights[i].bone_idx; + + if (weights[i].weight!=p_vert.weights[i].weight) + return weights[i].weight<p_vert.weights[i].weight; + } + } else { + return weights.size() < p_vert.weights.size(); + } + + } + return (color<p_vert.color); } else return (uv2<p_vert.uv2); @@ -619,7 +637,7 @@ private: // private stuff Transform _read_transform(XMLParser& parser); void _joint_set_owner(Collada::Node *p_node, NodeSkeleton *p_owner); - void _create_skeletons(Collada::Node **p_node); + void _create_skeletons(Collada::Node **p_node, NodeSkeleton *p_skeleton=NULL); void _find_morph_nodes(VisualScene *p_vscene,Node *p_node); bool _remove_node(Node *p_parent,Node *p_node); void _remove_node(VisualScene *p_vscene,Node *p_node); diff --git a/tools/doc/doc_data.cpp b/tools/doc/doc_data.cpp index 0bd21219bf..75759e7d30 100644 --- a/tools/doc/doc_data.cpp +++ b/tools/doc/doc_data.cpp @@ -186,8 +186,10 @@ void DocData::generate(bool p_basic_types) { arginfo=E->get().return_val; if (arginfo.type==Variant::NIL) continue; - - method.return_type=(arginfo.hint==PROPERTY_HINT_RESOURCE_TYPE)?arginfo.hint_string:Variant::get_type_name(arginfo.type); + if (m && m->get_return_type()!=StringName()) + method.return_type=m->get_return_type(); + else + method.return_type=(arginfo.hint==PROPERTY_HINT_RESOURCE_TYPE)?arginfo.hint_string:Variant::get_type_name(arginfo.type); } else { @@ -724,6 +726,7 @@ Error DocData::_load(Ref<XMLParser> parser) { class_list[name]=ClassDoc(); ClassDoc& c = class_list[name]; +// print_line("class: "+name); c.name=name; if (parser->has_attribute("inherits")) c.inherits = parser->get_attribute_value("inherits"); @@ -809,7 +812,7 @@ Error DocData::_load(Ref<XMLParser> parser) { ERR_FAIL_V(ERR_FILE_CORRUPT); } - } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()=="members") + } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name()=="theme_items") break; //end of <constants> } diff --git a/tools/docdump/class_list.xml b/tools/docdump/class_list.xml index 897477ff48..ab33cef7d7 100644 --- a/tools/docdump/class_list.xml +++ b/tools/docdump/class_list.xml @@ -319,7 +319,7 @@ <argument index="1" name="animation" type="Object"> </argument> <description> - Add an animation resource to the player, which will be later referenced by the "name" arguemnt. + Add an animation resource to the player, which will be later referenced by the "name" argument. </description> </method> <method name="remove_animation" > diff --git a/tools/docdump/makemd.py b/tools/docdump/makemd.py index 7cc2e9dc4b..f85d145d5e 100644 --- a/tools/docdump/makemd.py +++ b/tools/docdump/makemd.py @@ -337,7 +337,7 @@ for file in input_list: class_names.sort() -make_class_list(class_names, 3) +make_class_list(class_names, 2) for cn in class_names: c = classes[cn] diff --git a/tools/editor/animation_editor.cpp b/tools/editor/animation_editor.cpp index e693753c33..db70a2675a 100644 --- a/tools/editor/animation_editor.cpp +++ b/tools/editor/animation_editor.cpp @@ -687,9 +687,7 @@ void AnimationKeyEditor::_menu_track(int p_type) { case TRACK_MENU_OPTIMIZE: { - animation->optimize(); - - track_editor->update(); + optimize_dialog->popup_centered(Size2(250,180)); } break; @@ -698,6 +696,18 @@ void AnimationKeyEditor::_menu_track(int p_type) { } + +void AnimationKeyEditor::_animation_optimize() { + + + print_line("OPTIMIZE!"); + animation->optimize(optimize_linear_error->get_val(),optimize_angular_error->get_val(),optimize_max_angle->get_val()); + track_editor->update(); + undo_redo->clear_history(); + +} + + float AnimationKeyEditor::_get_zoom_scale() const { float zv = zoom->get_val(); @@ -2309,7 +2319,7 @@ void AnimationKeyEditor::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { zoomicon->set_texture( get_icon("Zoom","EditorIcons") ); //menu_track->set_icon(get_icon("AddTrack","EditorIcons")); @@ -2335,11 +2345,12 @@ void AnimationKeyEditor::_notification(int p_what) { tpp->add_item("Out-In",TRACK_MENU_SET_ALL_TRANS_OUTIN); tpp->set_name("Transitions"); tpp->connect("item_pressed",this,"_menu_track"); + optimize_dialog->connect("confirmed",this,"_animation_optimize"); menu_track->get_popup()->add_child(tpp); menu_track->get_popup()->add_submenu_item("Set Transitions..","Transitions"); - //menu_track->get_popup()->add_separator(); - //menu_track->get_popup()->add_item("Optimize Animation",TRACK_MENU_OPTIMIZE); + menu_track->get_popup()->add_separator(); + menu_track->get_popup()->add_item("Optimize Animation",TRACK_MENU_OPTIMIZE); @@ -2465,12 +2476,12 @@ void AnimationKeyEditor::set_animation(const Ref<Animation>& p_anim) { void AnimationKeyEditor::set_root(Node *p_root) { if (root) - root->disconnect("exit_scene",this,"_root_removed"); + root->disconnect("exit_tree",this,"_root_removed"); root=p_root; if (root) - root->connect("exit_scene",this,"_root_removed",make_binds(),CONNECT_ONESHOT); + root->connect("exit_tree",this,"_root_removed",make_binds(),CONNECT_ONESHOT); } @@ -2502,6 +2513,7 @@ void AnimationKeyEditor::_query_insert(const InsertData& p_id) { if (insert_frame!=OS::get_singleton()->get_frames_drawn()) { + //clear insert list for the frame if frame changed if (insert_confirm->is_visible()) return; //do nothing insert_data.clear(); @@ -2509,19 +2521,29 @@ void AnimationKeyEditor::_query_insert(const InsertData& p_id) { } insert_frame=OS::get_singleton()->get_frames_drawn(); + for (List<InsertData>::Element *E=insert_data.front();E;E=E->next()) { + //prevent insertion of multiple tracks + if (E->get().path==p_id.path) + return; //already inserted a track for this on this frame + } + insert_data.push_back(p_id); if (p_id.track_idx==-1) { - //potential new key, does not exist - if (insert_data.size()==1) - insert_confirm->set_text("Create NEW track for "+p_id.query+" and insert key?"); - else - insert_confirm->set_text("Create "+itos(insert_data.size())+" NEW tracks and insert keys?"); - - insert_confirm->get_ok()->set_text("Create"); - insert_confirm->popup_centered(Size2(300,100)); - insert_query=true; - + if (bool(EDITOR_DEF("animation/confirm_insert_track",true))) { + //potential new key, does not exist + if (insert_data.size()==1) + insert_confirm->set_text("Create NEW track for "+p_id.query+" and insert key?"); + else + insert_confirm->set_text("Create "+itos(insert_data.size())+" NEW tracks and insert keys?"); + + insert_confirm->get_ok()->set_text("Create"); + insert_confirm->popup_centered(Size2(300,100)); + insert_query=true; + } else { + call_deferred("_insert_delay"); + insert_queue=true; + } } else { if (!insert_query && !insert_queue) { @@ -2887,11 +2909,11 @@ void AnimationKeyEditor::set_anim_pos(float p_pos) { void AnimationKeyEditor::_pane_drag(const Point2& p_delta) { - Size2 ecs = ec->get_minsize(); + Size2 ecs = ec->get_custom_minimum_size(); ecs.y-=p_delta.y; if (ecs.y<100) ecs.y=100; - ec->set_minsize(ecs);; + ec->set_custom_minimum_size(ecs);; } @@ -3099,6 +3121,7 @@ void AnimationKeyEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_animation_len_update"),&AnimationKeyEditor::_animation_len_update); ObjectTypeDB::bind_method(_MD("set_animation"),&AnimationKeyEditor::set_animation); + ObjectTypeDB::bind_method(_MD("_animation_optimize"),&AnimationKeyEditor::_animation_optimize); ADD_SIGNAL( MethodInfo("resource_selected", PropertyInfo( Variant::OBJECT, "res"),PropertyInfo( Variant::STRING, "prop") ) ); @@ -3131,7 +3154,7 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h //add_child(menu); menu_track = memnew( MenuButton ); - menu_track->set_text("Tracks.."); + menu_track->set_text("Tracks"); hb->add_child(menu_track); menu_track->get_popup()->connect("item_pressed",this,"_menu_track"); @@ -3215,7 +3238,7 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h move_down_button->connect("pressed",this,"_menu_track",make_binds(TRACK_MENU_MOVE_DOWN)); move_down_button->set_focus_mode(FOCUS_NONE); move_down_button->set_disabled(true); - move_down_button->set_tooltip("Move current track dosn."); + move_down_button->set_tooltip("Move current track down."); remove_button = memnew( ToolButton ); hb->add_child(remove_button); @@ -3224,6 +3247,37 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h remove_button->set_disabled(true); remove_button->set_tooltip("Remove selected track."); + + optimize_dialog = memnew( ConfirmationDialog ); + add_child(optimize_dialog); + optimize_dialog->set_title("Anim. Optimizer"); + VBoxContainer *optimize_vb = memnew( VBoxContainer ); + optimize_dialog->add_child(optimize_vb); + optimize_dialog->set_child_rect(optimize_vb); + optimize_linear_error = memnew( SpinBox ); + optimize_linear_error->set_max(1.0); + optimize_linear_error->set_min(0.001); + optimize_linear_error->set_step(0.001); + optimize_linear_error->set_val(0.05); + optimize_vb->add_margin_child("Max. Linear Error:",optimize_linear_error); + optimize_angular_error = memnew( SpinBox ); + optimize_angular_error->set_max(1.0); + optimize_angular_error->set_min(0.001); + optimize_angular_error->set_step(0.001); + optimize_angular_error->set_val(0.01); + + optimize_vb->add_margin_child("Max. Angular Error:",optimize_angular_error); + optimize_max_angle = memnew( SpinBox ); + optimize_vb->add_margin_child("Max Optimizable Angle:",optimize_max_angle); + optimize_max_angle->set_max(360.0); + optimize_max_angle->set_min(0.0); + optimize_max_angle->set_step(0.1); + optimize_max_angle->set_val(22); + + optimize_dialog->get_ok()->set_text("Optimize"); + + + /*keying = memnew( Button ); keying->set_toggle_mode(true); //keying->set_text("Keys"); @@ -3242,8 +3296,8 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h // menu->get_popup()->connect("item_pressed",this,"_menu_callback"); - ec = memnew (EmptyControl); - ec->set_minsize(Size2(0,50)); + ec = memnew (Control); + ec->set_custom_minimum_size(Size2(0,50)); add_child(ec); ec->set_v_size_flags(SIZE_EXPAND_FILL); @@ -3298,8 +3352,6 @@ AnimationKeyEditor::AnimationKeyEditor(UndoRedo *p_undo_redo, EditorHistory *p_h add_child(insert_confirm); insert_confirm->connect("confirmed",this,"_confirm_insert_list"); - EDITOR_DEF("animation_editor/confirm_insert_key",true); - click.click=ClickOver::CLICK_NONE; diff --git a/tools/editor/animation_editor.h b/tools/editor/animation_editor.h index 01f6e294cc..1f17922552 100644 --- a/tools/editor/animation_editor.h +++ b/tools/editor/animation_editor.h @@ -37,7 +37,7 @@ #include "scene/gui/scroll_bar.h" #include "scene/gui/tool_button.h" #include "scene/gui/file_dialog.h" -#include "scene/gui/empty_control.h" + #include "scene/resources/animation.h" #include "scene/animation/animation_cache.h" #include "scene_tree_editor.h" @@ -157,7 +157,7 @@ class AnimationKeyEditor : public VBoxContainer { PopupMenu *track_menu; PopupMenu *type_menu; - EmptyControl *ec; + Control *ec; TextureFrame *zoomicon; HSlider *zoom; //MenuButton *menu; @@ -169,6 +169,11 @@ class AnimationKeyEditor : public VBoxContainer { ToolButton *move_down_button; ToolButton *remove_button; + ConfirmationDialog *optimize_dialog; + SpinBox *optimize_linear_error; + SpinBox *optimize_angular_error; + SpinBox *optimize_max_angle; + SpinBox *step; MenuButton *menu_track; @@ -257,6 +262,7 @@ class AnimationKeyEditor : public VBoxContainer { StringName alc; void _animation_changed(); + void _animation_optimize(); void _scroll_changed(double); diff --git a/tools/editor/call_dialog.cpp b/tools/editor/call_dialog.cpp index 4548d7291c..2e4fb96a58 100644 --- a/tools/editor/call_dialog.cpp +++ b/tools/editor/call_dialog.cpp @@ -76,7 +76,7 @@ void CallDialog::_notification(int p_what) { _update_method_list(); } - if (p_what==NOTIFICATION_EXIT_SCENE) { + if (p_what==NOTIFICATION_EXIT_TREE) { call->disconnect("pressed", this,"_call"); cancel->disconnect("pressed", this,"_cancel"); @@ -285,7 +285,7 @@ CallDialog::CallDialog() { property_editor->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 50 ); property_editor->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 ); property_editor->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, 90 ); - property_editor->get_tree()->set_hide_root( true ); + property_editor->get_scene_tree()->set_hide_root( true ); property_editor->hide_top_label(); add_child(property_editor); diff --git a/tools/editor/code_editor.cpp b/tools/editor/code_editor.cpp index 6de59f184a..2209b24245 100644 --- a/tools/editor/code_editor.cpp +++ b/tools/editor/code_editor.cpp @@ -487,6 +487,7 @@ FindReplaceDialog::FindReplaceDialog() { vb->add_child(error_label); + set_hide_on_ok(false); } @@ -507,15 +508,19 @@ void CodeTextEditor::_text_changed() { } void CodeTextEditor::_code_complete_timer_timeout() { + if (!is_visible()) + return; if (enable_complete_timer) text_editor->query_code_comple(); } -void CodeTextEditor::_complete_request(const String& p_request, int p_line) { +void CodeTextEditor::_complete_request() { List<String> entries; - _code_complete_script(text_editor->get_text(),p_request,p_line,&entries); + _code_complete_script(text_editor->get_text_for_completion(),&entries); // print_line("COMPLETE: "+p_request); + if (entries.size()==0) + return; Vector<String> strs; strs.resize(entries.size()); int i=0; @@ -555,7 +560,7 @@ void CodeTextEditor::_on_settings_change() { // AUTO BRACE COMPLETION text_editor->set_auto_brace_completion( - EDITOR_DEF("text_editor/auto_brace_complete", false) + EDITOR_DEF("text_editor/auto_brace_complete", true) ); code_complete_timer->set_wait_time( @@ -594,8 +599,21 @@ CodeTextEditor::CodeTextEditor() { add_child(text_editor); text_editor->set_area_as_parent_rect(); text_editor->set_margin(MARGIN_BOTTOM,20); - text_editor->add_font_override("font",get_font("source","Fonts")); + + String editor_font = EDITOR_DEF("text_editor/font", ""); + bool font_overrode = false; + if (editor_font!="") { + Ref<Font> fnt = ResourceLoader::load(editor_font); + if (fnt.is_valid()) { + text_editor->add_font_override("font",fnt); + font_overrode = true; + } + } + + if (!font_overrode) + text_editor->add_font_override("font",get_font("source","Fonts")); text_editor->set_show_line_numbers(true); + text_editor->set_brace_matching(true); line_col = memnew( Label ); add_child(line_col); @@ -632,6 +650,8 @@ CodeTextEditor::CodeTextEditor() { text_editor->connect("request_completion", this,"_complete_request"); Vector<String> cs; cs.push_back("."); + cs.push_back(","); + cs.push_back("("); text_editor->set_completion(true,cs); idle->connect("timeout", this,"_text_changed_idle_timeout"); diff --git a/tools/editor/code_editor.h b/tools/editor/code_editor.h index 1804237f18..f82eaf5ec5 100644 --- a/tools/editor/code_editor.h +++ b/tools/editor/code_editor.h @@ -135,7 +135,7 @@ class CodeTextEditor : public Control { void _on_settings_change(); - void _complete_request(const String& p_request,int p_line); + void _complete_request(); protected: void set_error(const String& p_error); @@ -143,7 +143,7 @@ protected: virtual void _load_theme_settings() {} virtual void _validate_script()=0; - virtual void _code_complete_script(const String& p_code, const String& p_keyword,int p_line, List<String>* r_options) {}; + virtual void _code_complete_script(const String& p_code, List<String>* r_options) {}; void _text_changed_idle_timeout(); diff --git a/tools/editor/connections_dialog.cpp b/tools/editor/connections_dialog.cpp index d7158eb7e9..cf4b21510a 100644 --- a/tools/editor/connections_dialog.cpp +++ b/tools/editor/connections_dialog.cpp @@ -607,6 +607,14 @@ void ConnectionsDialog::_remove_confirm() { } */ + +struct _ConnectionsDialogMethodInfoSort { + + _FORCE_INLINE_ bool operator()(const MethodInfo& a, const MethodInfo& b) const { + return a.name < b.name; + } +}; + void ConnectionsDialog::update_tree() { if (!is_visible()) @@ -623,7 +631,8 @@ void ConnectionsDialog::update_tree() { node->get_signal_list(&node_signals); - + //node_signals.sort_custom<_ConnectionsDialogMethodInfoSort>(); + for(List<MethodInfo>::Element *E=node_signals.front();E;E=E->next()) { diff --git a/tools/editor/console.cpp b/tools/editor/console.cpp index 746f61ad67..6b37895bc4 100644 --- a/tools/editor/console.cpp +++ b/tools/editor/console.cpp @@ -129,7 +129,7 @@ void Console::_window_input_event(InputEvent p_event) { if (p_event.key.scancode==KEY_ESCAPE && !window_has_modal_stack() && is_visible()) { hide(); - get_scene()->call_group(0,"windows","_cancel_input_ID",p_event.ID); + get_tree()->call_group(0,"windows","_cancel_input_ID",p_event.ID); } @@ -153,7 +153,7 @@ void Console::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { _resized(); show(); diff --git a/tools/editor/create_dialog.cpp b/tools/editor/create_dialog.cpp index 3a6b856247..f816e46bcf 100644 --- a/tools/editor/create_dialog.cpp +++ b/tools/editor/create_dialog.cpp @@ -225,7 +225,7 @@ void CreateDialog::_confirmed() { void CreateDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { connect("confirmed",this,"_confirmed"); _update_search(); @@ -289,7 +289,7 @@ CreateDialog::CreateDialog() { search_box->connect("input_event",this,"_sbox_input"); search_options = memnew( Tree ); vbc->add_margin_child("Matches:",search_options,true); - get_ok()->set_text("Open"); + get_ok()->set_text("Create"); get_ok()->set_disabled(true); register_text_enter(search_box); set_hide_on_ok(false); diff --git a/tools/editor/editor_data.cpp b/tools/editor/editor_data.cpp index bb4262e4b0..aeca76bb29 100644 --- a/tools/editor/editor_data.cpp +++ b/tools/editor/editor_data.cpp @@ -462,7 +462,7 @@ void EditorSelection::add_node(Node *p_node) { } selection[p_node]=meta; - p_node->connect("exit_scene",this,"_node_removed",varray(p_node),CONNECT_ONESHOT); + p_node->connect("exit_tree",this,"_node_removed",varray(p_node),CONNECT_ONESHOT); //emit_signal("selection_changed"); } @@ -478,7 +478,7 @@ void EditorSelection::remove_node(Node *p_node) { if (meta) memdelete(meta); selection.erase(p_node); - p_node->disconnect("exit_scene",this,"_node_removed"); + p_node->disconnect("exit_tree",this,"_node_removed"); //emit_signal("selection_changed"); } bool EditorSelection::is_selected(Node * p_node) const { diff --git a/tools/editor/editor_dir_dialog.cpp b/tools/editor/editor_dir_dialog.cpp index 790c3c8cd5..eec452ab7f 100644 --- a/tools/editor/editor_dir_dialog.cpp +++ b/tools/editor/editor_dir_dialog.cpp @@ -28,6 +28,9 @@ /*************************************************************************/ #include "editor_dir_dialog.h" #include "os/os.h" +#include "os/keyboard.h" +#include "tools/editor/editor_settings.h" + void EditorDirDialog::_update_dir(TreeItem* p_item) { @@ -39,12 +42,21 @@ void EditorDirDialog::_update_dir(TreeItem* p_item) { da->change_dir(cdir); da->list_dir_begin(); String p=da->get_next(); + + bool ishidden; + bool show_hidden = EditorSettings::get_singleton()->get("file_dialog/show_hidden_files"); + while(p!="") { - if (da->current_is_dir() && !p.begins_with(".")) { - TreeItem *ti = tree->create_item(p_item); - ti->set_text(0,p); - ti->set_icon(0,get_icon("Folder","EditorIcons")); - ti->set_collapsed(true); + + ishidden = da->current_is_hidden(); + + if (show_hidden || !ishidden) { + if (da->current_is_dir() && !p.begins_with(".")) { + TreeItem *ti = tree->create_item(p_item); + ti->set_text(0,p); + ti->set_icon(0,get_icon("Folder","EditorIcons")); + ti->set_collapsed(true); + } } p=da->get_next(); @@ -69,7 +81,7 @@ void EditorDirDialog::reload() { void EditorDirDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { reload(); tree->connect("item_collapsed",this,"_item_collapsed",varray(),CONNECT_DEFERRED); } diff --git a/tools/editor/editor_file_system.cpp b/tools/editor/editor_file_system.cpp index daba52be03..5d72928e9c 100644 --- a/tools/editor/editor_file_system.cpp +++ b/tools/editor/editor_file_system.cpp @@ -142,7 +142,7 @@ void EditorFileSystemDirectory::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_file","idx"),&EditorFileSystemDirectory::get_file); ObjectTypeDB::bind_method(_MD("get_file_path","idx"),&EditorFileSystemDirectory::get_file_path); ObjectTypeDB::bind_method(_MD("get_file_types","idx"),&EditorFileSystemDirectory::get_file_type); - ObjectTypeDB::bind_method(_MD("is_missing_sources","idx"),&EditorFileSystemDirectory::get_file_type); + ObjectTypeDB::bind_method(_MD("is_missing_sources","idx"),&EditorFileSystemDirectory::is_missing_sources); ObjectTypeDB::bind_method(_MD("get_name"),&EditorFileSystemDirectory::get_name); ObjectTypeDB::bind_method(_MD("get_parent"),&EditorFileSystemDirectory::get_parent); @@ -681,12 +681,12 @@ void EditorFileSystem::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { _load_type_cache(); scan(); } break; - case NOTIFICATION_EXIT_SCENE: { + case NOTIFICATION_EXIT_TREE: { if (use_threads && thread) { //abort thread if in progress abort_scan=true; @@ -992,6 +992,35 @@ void EditorFileSystem::_resource_saved(const String& p_path){ EditorFileSystem::get_singleton()->update_file(p_path); } +String EditorFileSystem::_find_first_from_source(EditorFileSystemDirectory* p_dir,const String &p_src) const { + + for(int i=0;i<p_dir->files.size();i++) { + for(int j=0;j<p_dir->files[i].meta.sources.size();j++) { + + if (p_dir->files[i].meta.sources[j].path==p_src) + return p_dir->get_file_path(i); + } + } + + for(int i=0;i<p_dir->subdirs.size();i++) { + + String ret = _find_first_from_source(p_dir->subdirs[i],p_src); + if (ret.length()>0) + return ret; + } + + return String(); +} + + +String EditorFileSystem::find_resource_from_source(const String& p_path) const { + + + if (filesystem) + return _find_first_from_source(filesystem,p_path); + return String(); +} + void EditorFileSystem::update_file(const String& p_file) { EditorFileSystemDirectory *fs=NULL; diff --git a/tools/editor/editor_file_system.h b/tools/editor/editor_file_system.h index c26fc02548..2d14f9012f 100644 --- a/tools/editor/editor_file_system.h +++ b/tools/editor/editor_file_system.h @@ -75,6 +75,7 @@ class EditorFileSystemDirectory : public Object { static void _bind_methods(); + friend class EditorFileSystem; public: @@ -180,6 +181,7 @@ class EditorFileSystem : public Node { List<String> sources_changed; static void _resource_saved(const String& p_path); + String _find_first_from_source(EditorFileSystemDirectory* p_dir,const String &p_src) const; protected: @@ -197,6 +199,7 @@ public: void scan_sources(); void get_changed_sources(List<String> *r_changed); void update_file(const String& p_file); + String find_resource_from_source(const String& p_path) const; EditorFileSystemDirectory *get_path(const String& p_path); String get_file_type(const String& p_file) const; EditorFileSystem(); diff --git a/tools/editor/editor_help.cpp b/tools/editor/editor_help.cpp index 819da4bb45..7deb136470 100644 --- a/tools/editor/editor_help.cpp +++ b/tools/editor/editor_help.cpp @@ -270,7 +270,7 @@ void EditorHelpSearch::_confirmed() { void EditorHelpSearch::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { connect("confirmed",this,"_confirmed"); _update_search(); @@ -293,7 +293,7 @@ void EditorHelpSearch::_bind_methods() { ObjectTypeDB::bind_method(_MD("_text_changed"),&EditorHelpSearch::_text_changed); ObjectTypeDB::bind_method(_MD("_confirmed"),&EditorHelpSearch::_confirmed); ObjectTypeDB::bind_method(_MD("_sbox_input"),&EditorHelpSearch::_sbox_input); - ObjectTypeDB::bind_method(_MD("_update_search"),&EditorHelpSearch::_sbox_input); + ObjectTypeDB::bind_method(_MD("_update_search"),&EditorHelpSearch::_update_search); ADD_SIGNAL(MethodInfo("go_to_help")); @@ -1361,8 +1361,8 @@ EditorHelp::EditorHelp(EditorNode *p_editor) { Separator *hs = memnew( VSeparator ); panel_hb->add_child(hs); - EmptyControl *ec = memnew( EmptyControl ); - ec->set_minsize(Size2(200,1)); + Control *ec = memnew( Control ); + ec->set_custom_minimum_size(Size2(200,1)); panel_hb->add_child(ec); search = memnew( LineEdit ); ec->add_child(search); @@ -1390,7 +1390,9 @@ EditorHelp::EditorHelp(EditorNode *p_editor) { { PanelContainer *pc = memnew( PanelContainer ); - pc->add_style_override("panel",get_stylebox("normal","TextEdit")); + Ref<StyleBoxFlat> style( memnew( StyleBoxFlat ) ); + style->set_bg_color( EditorSettings::get_singleton()->get("text_editor/background_color") ); + pc->add_style_override("panel", style); //get_stylebox("normal","TextEdit")); h_split->add_child(pc); class_desc = memnew( RichTextLabel ); pc->add_child(class_desc); diff --git a/tools/editor/editor_import_export.cpp b/tools/editor/editor_import_export.cpp index 6e8cb987e9..e6ec11e9d3 100644 --- a/tools/editor/editor_import_export.cpp +++ b/tools/editor/editor_import_export.cpp @@ -292,7 +292,11 @@ Vector<StringName> EditorExportPlatform::get_dependencies(bool p_bundles) const _add_filter_to_list(exported,"*"); } else { _add_to_list(EditorFileSystem::get_singleton()->get_filesystem(),exported); - _add_filter_to_list(exported,EditorImportExport::get_singleton()->get_export_custom_filter()); + String cf = EditorImportExport::get_singleton()->get_export_custom_filter(); + if (cf!="") + cf+=","; + cf+="*.flags"; + _add_filter_to_list(exported,cf); } @@ -361,8 +365,12 @@ Vector<StringName> EditorExportPlatform::get_dependencies(bool p_bundles) const } } } + String cf = EditorImportExport::get_singleton()->get_export_custom_filter(); + if (cf!="") + cf+=","; + cf+="*.flags"; + _add_filter_to_list(exported,cf); - _add_filter_to_list(exported,EditorImportExport::get_singleton()->get_export_custom_filter()); } @@ -896,6 +904,16 @@ Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func return OK; } +static int _get_pad(int p_alignment, int p_n) { + + int rest = p_n % p_alignment; + int pad = 0; + if (rest > 0) { + pad = p_alignment - rest; + }; + + return pad; +}; Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total) { @@ -922,11 +940,19 @@ Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path pd->ep->step("Storing File: "+p_path,2+p_file*100/p_total); pd->count++; pd->ftmp->store_buffer(p_data.ptr(),p_data.size()); + if (pd->alignment > 1) { + + int pad = _get_pad(pd->alignment, pd->ftmp->get_pos()); + for (int i=0; i<pad; i++) { + + pd->ftmp->store_8(0); + }; + }; return OK; } -Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles) { +Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles, int p_alignment) { EditorProgress ep("savepack","Packing",102); @@ -938,13 +964,12 @@ Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles) { dst->store_32(0); //pack version dst->store_32(VERSION_MAJOR); dst->store_32(VERSION_MINOR); - dst->store_32(VERSION_REVISION); + dst->store_32(0); //hmph for(int i=0;i<16;i++) { //reserved dst->store_32(0); } - size_t fcountpos = dst->get_pos(); dst->store_32(0); @@ -953,11 +978,20 @@ Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles) { pd.f=dst; pd.ftmp=tmp; pd.count=0; + pd.alignment = p_alignment; Error err = export_project_files(save_pack_file,&pd,p_make_bundles); memdelete(tmp); if (err) return err; + if (p_alignment > 1) { + int pad = _get_pad(p_alignment, dst->get_pos()); + for (int i=0; i<pad; i++) { + + dst->store_8(0); + }; + }; + size_t ofsplus = dst->get_pos(); //append file @@ -1133,10 +1167,36 @@ EditorImportExport* EditorImportExport::singleton=NULL; void EditorImportExport::add_import_plugin(const Ref<EditorImportPlugin>& p_plugin) { + // Need to make sure the name is unique if we are going to lookup by it + ERR_FAIL_COND(by_idx.has(p_plugin->get_name())); + by_idx[ p_plugin->get_name() ]=plugins.size(); plugins.push_back(p_plugin); } +void EditorImportExport::remove_import_plugin(const Ref<EditorImportPlugin>& p_plugin) { + + String plugin_name = p_plugin->get_name(); + + // Keep the indices the same + // Find the index of the target plugin + ERR_FAIL_COND(!by_idx.has(plugin_name)); + int idx = by_idx[plugin_name]; + int last_idx = plugins.size() - 1; + + // Swap the last plugin and the target one + SWAP(plugins[idx], plugins[last_idx]); + + // Update the index of the old last one + by_idx[plugins[idx]->get_name()] = idx; + + // Remove the target plugin's by_idx entry + by_idx.erase(plugin_name); + + // Erase the plugin + plugins.remove(last_idx); +} + int EditorImportExport::get_import_plugin_count() const{ return plugins.size(); diff --git a/tools/editor/editor_import_export.h b/tools/editor/editor_import_export.h index 8305e3c88c..a4723f41d0 100644 --- a/tools/editor/editor_import_export.h +++ b/tools/editor/editor_import_export.h @@ -100,6 +100,7 @@ protected: Vector<TempData> file_ofs; EditorProgress *ep; int count; + int alignment; }; @@ -121,7 +122,7 @@ public: Error export_project_files(EditorExportSaveFunction p_func, void* p_udata,bool p_make_bundles); - Error save_pack(FileAccess *p_where, bool p_make_bundles=false); + Error save_pack(FileAccess *p_where, bool p_make_bundles=false, int p_alignment = 1); virtual String get_name() const =0; virtual ImageCompression get_image_compression() const=0; virtual Ref<Texture> get_logo() const =0; @@ -270,6 +271,7 @@ public: static EditorImportExport* get_singleton() { return singleton; } void add_import_plugin(const Ref<EditorImportPlugin>& p_plugin); + void remove_import_plugin(const Ref<EditorImportPlugin>& p_plugin); int get_import_plugin_count() const; Ref<EditorImportPlugin> get_import_plugin(int p_idx) const; Ref<EditorImportPlugin> get_import_plugin_by_name(const String& p_string) const; diff --git a/tools/editor/editor_log.cpp b/tools/editor/editor_log.cpp index 23ba88ef81..7c3fa6c1bd 100644 --- a/tools/editor/editor_log.cpp +++ b/tools/editor/editor_log.cpp @@ -76,7 +76,7 @@ void EditorLog::_error_handler(void *p_self, const char*p_func, const char*p_fil void EditorLog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { log->add_color_override("default_color",get_color("font_color","Tree")); tb->set_normal_texture( get_icon("Collapse","EditorIcons")); @@ -203,9 +203,9 @@ EditorLog::EditorLog() { tb->connect("pressed",this,"_close_request"); - ec = memnew( EmptyControl); + ec = memnew( Control); vb->add_child(ec); - ec->set_minsize(Size2(0,100)); + ec->set_custom_minimum_size(Size2(0,100)); ec->set_v_size_flags(SIZE_EXPAND_FILL); diff --git a/tools/editor/editor_log.h b/tools/editor/editor_log.h index b6cd951287..27cce4a584 100644 --- a/tools/editor/editor_log.h +++ b/tools/editor/editor_log.h @@ -33,7 +33,7 @@ #include "scene/gui/label.h" #include "scene/gui/rich_text_label.h" #include "scene/gui/texture_button.h" -#include "scene/gui/empty_control.h" +//#include "scene/gui/empty_control.h" #include "scene/gui/box_container.h" #include "scene/gui/panel_container.h" #include "scene/gui/texture_frame.h" @@ -50,7 +50,7 @@ class EditorLog : public PanelContainer { TextureButton *tb; HBoxContainer *title_hb; // PaneDrag *pd; - EmptyControl *ec; + Control *ec; static void _error_handler(void *p_self, const char*p_func, const char*p_file,int p_line, const char*p_error,const char*p_errorexp,ErrorHandlerType p_type); diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 701704fbfa..41545b887a 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -75,6 +75,7 @@ #include "plugins/tile_map_editor_plugin.h" #include "plugins/cube_grid_theme_editor_plugin.h" #include "plugins/shader_editor_plugin.h" +#include "plugins/shader_graph_editor_plugin.h" #include "plugins/path_editor_plugin.h" #include "plugins/rich_text_editor_plugin.h" #include "plugins/collision_polygon_editor_plugin.h" @@ -88,6 +89,8 @@ #include "plugins/animation_player_editor_plugin.h" #include "plugins/baked_light_editor_plugin.h" #include "plugins/polygon_2d_editor_plugin.h" +#include "plugins/navigation_polygon_editor_plugin.h" +#include "plugins/light_occluder_2d_editor_plugin.h" // end #include "tools/editor/io_plugins/editor_texture_import_plugin.h" #include "tools/editor/io_plugins/editor_scene_import_plugin.h" @@ -140,7 +143,7 @@ void EditorNode::_unhandled_input(const InputEvent& p_event) { void EditorNode::_notification(int p_what) { - if (p_what==NOTIFICATION_EXIT_SCENE) { + if (p_what==NOTIFICATION_EXIT_TREE) { editor_data.save_editor_external_data(); log->deinit(); // do not get messages anymore @@ -213,13 +216,14 @@ void EditorNode::_notification(int p_what) { } } - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { + //MessageQueue::get_singleton()->push_call(this,"_get_scene_metadata"); - get_scene()->set_editor_hint(true); - get_scene()->get_root()->set_as_audio_listener(false); - get_scene()->get_root()->set_as_audio_listener_2d(false); - get_scene()->set_auto_accept_quit(false); + get_tree()->set_editor_hint(true); + get_tree()->get_root()->set_as_audio_listener(false); + get_tree()->get_root()->set_as_audio_listener_2d(false); + get_tree()->set_auto_accept_quit(false); //VisualServer::get_singleton()->viewport_set_hide_canvas(editor->get_scene_root()->get_viewport(),false); //import_monitor->scan_changes(); @@ -228,6 +232,8 @@ void EditorNode::_notification(int p_what) { VisualServer::get_singleton()->viewport_set_hide_scenario(get_scene_root()->get_viewport(),true); VisualServer::get_singleton()->viewport_set_hide_canvas(get_scene_root()->get_viewport(),true); + VisualServer::get_singleton()->viewport_set_disable_environment(get_viewport()->get_viewport_rid(),true); + _editor_select(1); if (defer_load_scene!="") { @@ -242,7 +248,7 @@ void EditorNode::_notification(int p_what) { if (ok!=OK) OS::get_singleton()->set_exit_code(255); defer_translatable=""; - get_scene()->quit(); + get_tree()->quit(); } /* @@ -335,6 +341,19 @@ void EditorNode::_vp_resized() { } +void EditorNode::_rebuild_import_menu() +{ + PopupMenu* p = import_menu->get_popup(); + p->clear(); + p->add_item("Sub-Scene", FILE_IMPORT_SUBSCENE); + p->add_separator(); + for (int i = 0; i < editor_import_export->get_import_plugin_count(); i++) { + p->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(), IMPORT_PLUGIN_BASE + i); + } + p->add_separator(); + p->add_item("Re-Import..", SETTINGS_IMPORT); +} + void EditorNode::_node_renamed() { if (property_editor) @@ -977,6 +996,15 @@ void EditorNode::_dialog_action(String p_file) { } } break; + + case FILE_SAVE_AND_RUN: { + if (file->get_mode()==FileDialog::MODE_SAVE_FILE) { + + _save_scene(p_file); + _run(false); + } + } break; + case FILE_EXPORT_MESH_LIBRARY: { Ref<MeshLibrary> ml; @@ -1232,7 +1260,7 @@ void EditorNode::_edit_current() { Node * current_node = current_obj->cast_to<Node>(); ERR_FAIL_COND(!current_node); - ERR_FAIL_COND(!current_node->is_inside_scene()); + ERR_FAIL_COND(!current_node->is_inside_tree()); @@ -1310,6 +1338,8 @@ void EditorNode::_edit_current() { p->add_item("Copy Params",OBJECT_COPY_PARAMS); p->add_item("Set Params",OBJECT_PASTE_PARAMS); p->add_separator(); + p->add_item("Make Resources Unique",OBJECT_UNIQUE_RESOURCES); + p->add_separator(); p->add_icon_item(gui_base->get_icon("Help","EditorIcons"),"Class Reference",OBJECT_REQUEST_HELP); List<MethodInfo> methods; current_obj->get_method_list(&methods); @@ -1388,13 +1418,10 @@ void EditorNode::_run(bool p_current,const String& p_custom) { } if (scene->get_filename()=="") { - - current_option=-1; //accept->get_cancel()->hide(); - accept->get_ok()->set_text("I see.."); - accept->set_text("Scene has never been saved. Save before running!"); - accept->popup_centered(Size2(300,70));; + /**/ + _menu_option_confirm(FILE_SAVE_BEFORE_RUN, false); return; } @@ -1661,6 +1688,18 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } break; + case FILE_SAVE_BEFORE_RUN: { + if (!p_confirmed) { + accept->get_ok()->set_text("Yes"); + accept->set_text("This scene has never been saved. Save before running?"); + accept->popup_centered(Size2(300, 70)); + break; + } + + _menu_option(FILE_SAVE_AS_SCENE); + _menu_option_confirm(FILE_SAVE_AND_RUN, true); + } break; + case FILE_DUMP_STRINGS: { Node *scene = edited_scene; @@ -1900,7 +1939,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { } _menu_option_confirm(RUN_STOP,true); - get_scene()->quit(); + get_tree()->quit(); } break; case FILE_EXTERNAL_OPEN_SCENE: { @@ -1946,6 +1985,25 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { log->add_message("REDO: "+action); } break; + + case EDIT_REVERT: { + + Node *scene = get_edited_scene(); + + if (!scene) + break; + + if (unsaved_cache && !p_confirmed) { + confirmation->get_ok()->set_text("Revert"); + confirmation->set_text("This action cannot be undone. Revert anyway?"); + confirmation->popup_centered(Size2(300,70)); + break; + } + + Error err = load_scene(scene->get_filename()); + + } break; + #if 0 case NODE_EXTERNAL_INSTANCE: { @@ -2023,6 +2081,47 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { editor_data.paste_object_params(current); editor_data.get_undo_redo().clear_history(); } break; + case OBJECT_UNIQUE_RESOURCES: { + + editor_data.apply_changes_in_editors();; + if (current) { + List<PropertyInfo> props; + current->get_property_list(&props); + Map<RES,RES> duplicates; + for (List<PropertyInfo>::Element *E=props.front();E;E=E->next()) { + + if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) + continue; + + Variant v = current->get(E->get().name); + if (v.is_ref()) { + REF ref = v; + if (ref.is_valid()) { + + RES res = ref; + if (res.is_valid()) { + + if (!duplicates.has(res)) { + duplicates[res]=res->duplicate(); + } + res=duplicates[res]; + + current->set(E->get().name,res); + } + + } + } + + } + } + + editor_data.get_undo_redo().clear_history(); + if (editor_plugin_screen) { //reload editor plugin + editor_plugin_over->edit(NULL); + editor_plugin_over->edit(current); + } + + } break; case OBJECT_CALL_METHOD: { editor_data.apply_changes_in_editors();; @@ -2079,7 +2178,7 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) { break; } - get_scene()->quit(); + get_tree()->quit(); String exec = OS::get_singleton()->get_executable_path(); List<String> args; @@ -2326,6 +2425,19 @@ void EditorNode::remove_editor_plugin(EditorPlugin *p_editor) { } +void EditorNode::add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) { + + editor_import_export->add_import_plugin(p_editor_import); + _rebuild_import_menu(); +} + +void EditorNode::remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import) { + + editor_import_export->remove_import_plugin(p_editor_import); + _rebuild_import_menu(); +} + + void EditorNode::set_edited_scene(Node *p_scene) { if (edited_scene) { @@ -2337,8 +2449,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 (get_tree()) + get_tree()->set_edited_scene_root(edited_scene); if (edited_scene) { if (p_scene->get_parent()!=scene_root) @@ -2382,7 +2494,7 @@ void EditorNode::_fetch_translatable_strings(const Object *p_object,Set<StringNa Error EditorNode::save_translatable_strings(const String& p_to_file) { - if (!is_inside_scene()) { + if (!is_inside_tree()) { defer_translatable=p_to_file; return OK; } @@ -2576,7 +2688,7 @@ Error EditorNode::save_optimized_copy(const String& p_scene,const String& p_pres Error EditorNode::load_scene(const String& p_scene) { - if (!is_inside_scene()) { + if (!is_inside_tree()) { defer_load_scene = p_scene; return OK; } @@ -2776,6 +2888,8 @@ void EditorNode::animation_editor_make_visible(bool p_visible) { //pd_anim->hide(); animation_editor->hide(); // scene_root_parent->set_margin(MARGIN_TOP,0); + if (!animation_vb->get_parent_control()) + return; animation_vb->get_parent_control()->minimum_size_changed(); top_split->set_collapsed(true); } @@ -3088,6 +3202,9 @@ void EditorNode::_bind_methods() { ObjectTypeDB::bind_method("_sources_changed",&EditorNode::_sources_changed); ObjectTypeDB::bind_method("_fs_changed",&EditorNode::_fs_changed); + ObjectTypeDB::bind_method(_MD("add_editor_import_plugin", "plugin"), &EditorNode::add_editor_import_plugin); + ObjectTypeDB::bind_method(_MD("remove_editor_import_plugin", "plugin"), &EditorNode::remove_editor_import_plugin); + ObjectTypeDB::bind_method(_MD("get_gui_base"), &EditorNode::get_gui_base); ADD_SIGNAL( MethodInfo("play_pressed") ); ADD_SIGNAL( MethodInfo("pause_pressed") ); @@ -3148,6 +3265,11 @@ Error EditorNode::export_platform(const String& p_platform, const String& p_path return OK; } +void EditorNode::show_warning(const String& p_text) { + + warning->set_text(p_text); + warning->popup_centered_minsize(); +} EditorNode::EditorNode() { @@ -3165,6 +3287,7 @@ EditorNode::EditorNode() { EditorSettings::create(); ResourceLoader::set_abort_on_missing_resources(false); + FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("file_dialog/show_hidden_files")); ResourceLoader::set_error_notify_func(this,_load_error_notify); ResourceLoader::set_timestamp_on_load(true); @@ -3200,7 +3323,7 @@ EditorNode::EditorNode() { gui_base->set_area_as_parent_rect(); - Ref<Theme> theme( memnew( Theme ) ); + theme = Ref<Theme>( memnew( Theme ) ); gui_base->set_theme( theme ); editor_register_icons(theme); editor_register_fonts(theme); @@ -3263,13 +3386,13 @@ EditorNode::EditorNode() { main_editor_tabs->connect("tab_changed",this,"_editor_select"); HBoxContainer *srth = memnew( HBoxContainer ); srt->add_child( srth ); - EmptyControl *tec = memnew( EmptyControl ); - tec->set_minsize(Size2(100,0)); + Control *tec = memnew( Control ); + tec->set_custom_minimum_size(Size2(100,0)); tec->set_h_size_flags(Control::SIZE_EXPAND_FILL); srth->add_child(tec); srth->add_child(main_editor_tabs); - tec = memnew( EmptyControl ); - tec->set_minsize(Size2(100,0)); + tec = memnew( Control ); + tec->set_custom_minimum_size(Size2(100,0)); srth->add_child(tec); tec->set_h_size_flags(Control::SIZE_EXPAND_FILL); @@ -3293,6 +3416,8 @@ EditorNode::EditorNode() { scene_root = memnew( Viewport ); + + //scene_root_base->add_child(scene_root); scene_root->set_meta("_editor_disable_input",true); VisualServer::get_singleton()->viewport_set_hide_scenario(scene_root->get_viewport(),true); @@ -3377,7 +3502,7 @@ EditorNode::EditorNode() { p->add_item("New Scene",FILE_NEW_SCENE); p->add_item("Open Scene..",FILE_OPEN_SCENE,KEY_MASK_CMD+KEY_O); p->add_item("Save Scene",FILE_SAVE_SCENE,KEY_MASK_CMD+KEY_S); - p->add_item("Save Scene As..",FILE_SAVE_AS_SCENE); + p->add_item("Save Scene As..",FILE_SAVE_AS_SCENE,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_S); p->add_separator(); p->add_item("Goto Prev. Scene",FILE_OPEN_PREV,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_P); p->add_submenu_item("Open Recent","RecentScenes",FILE_OPEN_RECENT); @@ -3405,6 +3530,8 @@ EditorNode::EditorNode() { p->add_separator(); p->add_item("Project Settings",RUN_SETTINGS); p->add_separator(); + p->add_item("Revert Scene",EDIT_REVERT); + p->add_separator(); p->add_item("Quit to Project List",RUN_PROJECT_MANAGER,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_Q); p->add_item("Quit",FILE_QUIT,KEY_MASK_CMD+KEY_Q); @@ -3449,8 +3576,6 @@ EditorNode::EditorNode() { left_menu_hb->add_child( import_menu ); p=import_menu->get_popup(); - p->add_item("Sub-Scene",FILE_IMPORT_SUBSCENE); - p->add_separator(); p->connect("item_pressed",this,"_menu_option"); export_button = memnew( ToolButton ); @@ -3488,7 +3613,7 @@ EditorNode::EditorNode() { play_button->set_icon(gui_base->get_icon("MainPlay","EditorIcons")); play_button->set_focus_mode(Control::FOCUS_NONE); play_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY)); - play_button->set_tooltip("Start the scene (F5)."); + play_button->set_tooltip("Play the project (F5)."); @@ -3629,8 +3754,8 @@ EditorNode::EditorNode() { top_pallete->add_child(resources_dock); top_pallete->set_v_size_flags(Control::SIZE_EXPAND_FILL); - EmptyControl *editor_spacer = memnew( EmptyControl ); - editor_spacer->set_minsize(Size2(260,200)); + Control *editor_spacer = memnew( Control ); + editor_spacer->set_custom_minimum_size(Size2(260,200)); editor_spacer->set_v_size_flags(Control::SIZE_EXPAND_FILL); editor_vsplit->add_child( editor_spacer ); editor_spacer->add_child( top_pallete ); @@ -3641,8 +3766,8 @@ EditorNode::EditorNode() { prop_pallete->set_v_size_flags(Control::SIZE_EXPAND_FILL); - editor_spacer = memnew( EmptyControl ); - editor_spacer->set_minsize(Size2(260,200)); + editor_spacer = memnew( Control ); + editor_spacer->set_custom_minimum_size(Size2(260,200)); editor_spacer->set_v_size_flags(Control::SIZE_EXPAND_FILL); editor_vsplit->add_child( editor_spacer ); editor_spacer->add_child( prop_pallete ); @@ -3858,6 +3983,8 @@ EditorNode::EditorNode() { logo->set_pos(Point2(20,20)); logo->set_texture(gui_base->get_icon("Logo","EditorIcons") ); + warning = memnew( AcceptDialog ); + add_child(warning); @@ -3950,8 +4077,8 @@ EditorNode::EditorNode() { Ref<EditorSceneImportPlugin> _scene_import = memnew(EditorSceneImportPlugin(this) ); Ref<EditorSceneImporterCollada> _collada_import = memnew( EditorSceneImporterCollada); _scene_import->add_importer(_collada_import); - Ref<EditorSceneImporterFBXConv> _fbxconv_import = memnew( EditorSceneImporterFBXConv); - _scene_import->add_importer(_fbxconv_import); +// Ref<EditorSceneImporterFBXConv> _fbxconv_import = memnew( EditorSceneImporterFBXConv); +// _scene_import->add_importer(_fbxconv_import); editor_import_export->add_import_plugin( _scene_import); editor_import_export->add_import_plugin( Ref<EditorSceneAnimationImportPlugin>( memnew(EditorSceneAnimationImportPlugin(this)))); editor_import_export->add_import_plugin( Ref<EditorMeshImportPlugin>( memnew(EditorMeshImportPlugin(this)))); @@ -3959,11 +4086,6 @@ EditorNode::EditorNode() { editor_import_export->add_import_plugin( Ref<EditorSampleImportPlugin>( memnew(EditorSampleImportPlugin(this)))); editor_import_export->add_import_plugin( Ref<EditorTranslationImportPlugin>( memnew(EditorTranslationImportPlugin(this)))); - - for(int i=0;i<editor_import_export->get_import_plugin_count();i++) { - import_menu->get_popup()->add_item(editor_import_export->get_import_plugin(i)->get_visible_name(),IMPORT_PLUGIN_BASE+i); - } - editor_import_export->add_export_plugin( Ref<EditorTextureExportPlugin>( memnew(EditorTextureExportPlugin))); add_editor_plugin( memnew( CanvasItemEditorPlugin(this) ) ); @@ -3971,7 +4093,10 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( ScriptEditorPlugin(this) ) ); add_editor_plugin( memnew( EditorHelpPlugin(this) ) ); add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) ); - add_editor_plugin( memnew( ShaderEditorPlugin(this) ) ); + add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,true) ) ); + add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,false) ) ); + add_editor_plugin( memnew( ShaderEditorPlugin(this,true) ) ); + add_editor_plugin( memnew( ShaderEditorPlugin(this,false) ) ); add_editor_plugin( memnew( CameraEditorPlugin(this) ) ); add_editor_plugin( memnew( SampleEditorPlugin(this) ) ); add_editor_plugin( memnew( SampleLibraryEditorPlugin(this) ) ); @@ -3997,6 +4122,8 @@ EditorNode::EditorNode() { add_editor_plugin( memnew( PathEditorPlugin(this) ) ); add_editor_plugin( memnew( BakedLightEditorPlugin(this) ) ); add_editor_plugin( memnew( Polygon2DEditorPlugin(this) ) ); + add_editor_plugin( memnew( LightOccluder2DEditorPlugin(this) ) ); + add_editor_plugin( memnew( NavigationPolygonEditorPlugin(this) ) ); for(int i=0;i<EditorPlugins::get_plugin_count();i++) add_editor_plugin( EditorPlugins::create(i,this) ); @@ -4005,9 +4132,7 @@ EditorNode::EditorNode() { circle_step_frame=OS::get_singleton()->get_frames_drawn();; circle_step=0; - - import_menu->get_popup()->add_separator(); - import_menu->get_popup()->add_item("Re-Import..",SETTINGS_IMPORT); + _rebuild_import_menu(); editor_plugin_screen=NULL; editor_plugin_over=NULL; @@ -4022,9 +4147,9 @@ EditorNode::EditorNode() { Globals::get_singleton()->set("debug/indicators_enabled",true); Globals::get_singleton()->set("render/room_cull_enabled",false); - theme->set_color("prop_category","Editor",Color::hex(0x3f3945ff)); - theme->set_color("prop_section","Editor",Color::hex(0x38323dff)); - theme->set_color("prop_subsection","Editor",Color::hex(0x342e39ff)); + theme->set_color("prop_category","Editor",Color::hex(0x403d41ff)); + theme->set_color("prop_section","Editor",Color::hex(0x383539ff)); + theme->set_color("prop_subsection","Editor",Color::hex(0x343135ff)); theme->set_color("fg_selected","Editor",Color::html("ffbd8e8e")); theme->set_color("fg_error","Editor",Color::html("ffbd8e8e")); diff --git a/tools/editor/editor_node.h b/tools/editor/editor_node.h index 2cec301cf6..531eccb546 100644 --- a/tools/editor/editor_node.h +++ b/tools/editor/editor_node.h @@ -108,6 +108,8 @@ class EditorNode : public Node { FILE_OPEN_SCENE, FILE_SAVE_SCENE, FILE_SAVE_AS_SCENE, + FILE_SAVE_BEFORE_RUN, + FILE_SAVE_AND_RUN, FILE_IMPORT_SUBSCENE, FILE_EXPORT_PROJECT, FILE_EXPORT_MESH_LIBRARY, @@ -125,6 +127,7 @@ class EditorNode : public Node { FILE_EXTERNAL_OPEN_SCENE, EDIT_UNDO, EDIT_REDO, + EDIT_REVERT, RESOURCE_NEW, RESOURCE_LOAD, RESOURCE_SAVE, @@ -133,6 +136,7 @@ class EditorNode : public Node { RESOURCE_COPY, OBJECT_COPY_PARAMS, OBJECT_PASTE_PARAMS, + OBJECT_UNIQUE_RESOURCES, OBJECT_CALL_METHOD, OBJECT_REQUEST_HELP, RUN_PLAY, @@ -211,6 +215,7 @@ class EditorNode : public Node { AcceptDialog *load_error_dialog; Control *scene_root_base; + Ref<Theme> theme; PopupMenu *recent_scenes; Button *property_back; @@ -227,6 +232,7 @@ class EditorNode : public Node { ConfirmationDialog *open_recent_confirmation; AcceptDialog *accept; AcceptDialog *about; + AcceptDialog *warning; //OptimizedPresetsDialog *optimized_presets; EditorSettingsDialog *settings_config_dialog; @@ -335,6 +341,8 @@ class EditorNode : public Node { void _show_messages(); void _vp_resized(); + void _rebuild_import_menu(); + void _save_scene(String p_file); @@ -416,6 +424,9 @@ public: static void add_editor_plugin(EditorPlugin *p_editor); static void remove_editor_plugin(EditorPlugin *p_editor); + void add_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import); + void remove_editor_import_plugin(const Ref<EditorImportPlugin>& p_editor_import); + void edit_node(Node *p_node); void edit_resource(const Ref<Resource>& p_resource); @@ -471,6 +482,12 @@ public: void stop_child_process(); + Ref<Theme> get_editor_theme() const { return theme; } + + + void show_warning(const String& p_text); + + Error export_platform(const String& p_platform, const String& p_path, bool p_debug,const String& p_password,bool p_quit_after=false); static void register_editor_types(); diff --git a/tools/editor/editor_plugin.cpp b/tools/editor/editor_plugin.cpp index 2a2ad63d32..1bad1dc6ac 100644 --- a/tools/editor/editor_plugin.cpp +++ b/tools/editor/editor_plugin.cpp @@ -73,6 +73,12 @@ void EditorPlugin::add_custom_control(CustomControlContainer p_location,Control } break; case CONTAINER_CANVAS_EDITOR_SIDE: { + CanvasItemEditor::get_singleton()->get_palette_split()->add_child(p_control); + + } break; + case CONTAINER_CANVAS_EDITOR_BOTTOM: { + + CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(p_control); } break; diff --git a/tools/editor/editor_plugin.h b/tools/editor/editor_plugin.h index bcde0f73fb..4f2341d3b1 100644 --- a/tools/editor/editor_plugin.h +++ b/tools/editor/editor_plugin.h @@ -66,7 +66,8 @@ public: CONTAINER_SPATIAL_EDITOR_SIDE, CONTAINER_SPATIAL_EDITOR_BOTTOM, CONTAINER_CANVAS_EDITOR_MENU, - CONTAINER_CANVAS_EDITOR_SIDE + CONTAINER_CANVAS_EDITOR_SIDE, + CONTAINER_CANVAS_EDITOR_BOTTOM }; //TODO: send a resoucre for editing to the editor node? diff --git a/tools/editor/editor_run_native.cpp b/tools/editor/editor_run_native.cpp index be1a124fc2..17117be188 100644 --- a/tools/editor/editor_run_native.cpp +++ b/tools/editor/editor_run_native.cpp @@ -33,7 +33,7 @@ void EditorRunNative::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { List<StringName> ep; EditorImportExport::get_singleton()->get_export_platforms(&ep); diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 2b54a334bf..deb5d86a2e 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -386,6 +386,8 @@ void EditorSettings::_load_defaults() { set("global/font",""); hints["global/font"]=PropertyInfo(Variant::STRING,"global/font",PROPERTY_HINT_GLOBAL_FILE,"*.fnt"); + set("global/autoscan_project_path",""); + hints["global/autoscan_project_path"]=PropertyInfo(Variant::STRING,"global/autoscan_project_path",PROPERTY_HINT_GLOBAL_DIR); set("global/default_project_path",""); hints["global/default_project_path"]=PropertyInfo(Variant::STRING,"global/default_project_path",PROPERTY_HINT_GLOBAL_DIR); set("global/default_project_export_path",""); @@ -401,6 +403,8 @@ void EditorSettings::_load_defaults() { set("text_editor/string_color",Color::html("ef6ebe")); set("text_editor/symbol_color",Color::html("badfff")); set("text_editor/selection_color",Color::html("7b5dbe")); + set("text_editor/brace_mismatch_color",Color(1,0.2,0.2)); + set("text_editor/current_line_color",Color(0.3,0.5,0.8,0.15)); set("text_editor/idle_parse_delay",2); set("text_editor/create_signal_callbacks",true); @@ -410,12 +414,18 @@ void EditorSettings::_load_defaults() { set("text_editor/auto_brace_complete", false); + set("scenetree_editor/duplicate_node_name_num_separator",0); + hints["scenetree_editor/duplicate_node_name_num_separator"]=PropertyInfo(Variant::INT,"scenetree_editor/duplicate_node_name_num_separator",PROPERTY_HINT_ENUM, "None,Space,Underscore,Dash"); + + set("3d_editor/default_fov",45.0); set("3d_editor/default_z_near",0.1); set("3d_editor/default_z_far",500.0); set("3d_editor/navigation_scheme",0); hints["3d_editor/navigation_scheme"]=PropertyInfo(Variant::INT,"3d_editor/navigation_scheme",PROPERTY_HINT_ENUM,"Godot,Maya,Modo"); + set("3d_editor/zoom_style",0); + hints["3d_editor/zoom_style"]=PropertyInfo(Variant::INT,"3d_editor/zoom_style",PROPERTY_HINT_ENUM,"Vertical, Horizontal"); set("3d_editor/orbit_modifier",0); hints["3d_editor/orbit_modifier"]=PropertyInfo(Variant::INT,"3d_editor/orbit_modifier",PROPERTY_HINT_ENUM,"None,Shift,Alt,Meta,Ctrl"); set("3d_editor/pan_modifier",1); @@ -436,10 +446,13 @@ void EditorSettings::_load_defaults() { set("text_editor/create_signal_callbacks",true); + set("file_dialog/show_hidden_files", false); set("animation/autorename_animation_tracks",true); + set("animation/confirm_insert_track",true); set("property_editor/texture_preview_width",48); + set("property_editor/auto_refresh_interval",0.3); set("help/doc_path",""); set("import/ask_save_before_reimport",false); @@ -462,10 +475,10 @@ void EditorSettings::notify_changes() { _THREAD_SAFE_METHOD_ - SceneMainLoop *sml=NULL; + SceneTree *sml=NULL; if (OS::get_singleton()->get_main_loop()) - sml = OS::get_singleton()->get_main_loop()->cast_to<SceneMainLoop>(); + sml = OS::get_singleton()->get_main_loop()->cast_to<SceneTree>(); if (!sml) { print_line("not SML"); diff --git a/tools/editor/groups_editor.cpp b/tools/editor/groups_editor.cpp index f0a2a6a758..52db562d8a 100644 --- a/tools/editor/groups_editor.cpp +++ b/tools/editor/groups_editor.cpp @@ -36,7 +36,7 @@ void GroupsEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { connect("confirmed", this,"_close"); } } diff --git a/tools/editor/icons/icon_add.png b/tools/editor/icons/icon_add.png Binary files differindex 1a97f356d6..26283ca67c 100644 --- a/tools/editor/icons/icon_add.png +++ b/tools/editor/icons/icon_add.png diff --git a/tools/editor/icons/icon_animation.png b/tools/editor/icons/icon_animation.png Binary files differindex 6af126bf37..ac663c0554 100644 --- a/tools/editor/icons/icon_animation.png +++ b/tools/editor/icons/icon_animation.png diff --git a/tools/editor/icons/icon_atlas_texture.png b/tools/editor/icons/icon_atlas_texture.png Binary files differindex 3da9f0bee4..0051b0cda4 100644 --- a/tools/editor/icons/icon_atlas_texture.png +++ b/tools/editor/icons/icon_atlas_texture.png diff --git a/tools/editor/icons/icon_audio_stream_gibberish.png b/tools/editor/icons/icon_audio_stream_gibberish.png Binary files differindex f10671e8a2..95470c298e 100644 --- a/tools/editor/icons/icon_audio_stream_gibberish.png +++ b/tools/editor/icons/icon_audio_stream_gibberish.png diff --git a/tools/editor/icons/icon_auto_play.png b/tools/editor/icons/icon_auto_play.png Binary files differindex e454ca8c7b..1d5c957cc7 100644 --- a/tools/editor/icons/icon_auto_play.png +++ b/tools/editor/icons/icon_auto_play.png diff --git a/tools/editor/icons/icon_back_buffer_copy.png b/tools/editor/icons/icon_back_buffer_copy.png Binary files differnew file mode 100644 index 0000000000..b27eb39108 --- /dev/null +++ b/tools/editor/icons/icon_back_buffer_copy.png diff --git a/tools/editor/icons/icon_bake.png b/tools/editor/icons/icon_bake.png Binary files differindex b1b0f941da..ae06ce48e6 100644 --- a/tools/editor/icons/icon_bake.png +++ b/tools/editor/icons/icon_bake.png diff --git a/tools/editor/icons/icon_blend.png b/tools/editor/icons/icon_blend.png Binary files differindex 985b63d5d1..2a75f0b2f4 100644 --- a/tools/editor/icons/icon_blend.png +++ b/tools/editor/icons/icon_blend.png diff --git a/tools/editor/icons/icon_bone.png b/tools/editor/icons/icon_bone.png Binary files differindex 174b0bc167..81b6d8856e 100644 --- a/tools/editor/icons/icon_bone.png +++ b/tools/editor/icons/icon_bone.png diff --git a/tools/editor/icons/icon_bool.png b/tools/editor/icons/icon_bool.png Binary files differindex d465b7da07..3381033b00 100644 --- a/tools/editor/icons/icon_bool.png +++ b/tools/editor/icons/icon_bool.png diff --git a/tools/editor/icons/icon_canvas_item.png b/tools/editor/icons/icon_canvas_item.png Binary files differindex 99403bed21..add54ba1af 100644 --- a/tools/editor/icons/icon_canvas_item.png +++ b/tools/editor/icons/icon_canvas_item.png diff --git a/tools/editor/icons/icon_canvas_item_material.png b/tools/editor/icons/icon_canvas_item_material.png Binary files differnew file mode 100644 index 0000000000..2fe8921653 --- /dev/null +++ b/tools/editor/icons/icon_canvas_item_material.png diff --git a/tools/editor/icons/icon_canvas_item_shader.png b/tools/editor/icons/icon_canvas_item_shader.png Binary files differnew file mode 100644 index 0000000000..a5f4e7bf85 --- /dev/null +++ b/tools/editor/icons/icon_canvas_item_shader.png diff --git a/tools/editor/icons/icon_canvas_item_shader_graph.png b/tools/editor/icons/icon_canvas_item_shader_graph.png Binary files differnew file mode 100644 index 0000000000..bba966b43e --- /dev/null +++ b/tools/editor/icons/icon_canvas_item_shader_graph.png diff --git a/tools/editor/icons/icon_canvas_modulate.png b/tools/editor/icons/icon_canvas_modulate.png Binary files differnew file mode 100644 index 0000000000..2a34df7793 --- /dev/null +++ b/tools/editor/icons/icon_canvas_modulate.png diff --git a/tools/editor/icons/icon_check_box.png b/tools/editor/icons/icon_check_box.png Binary files differnew file mode 100644 index 0000000000..8a2b56cc3e --- /dev/null +++ b/tools/editor/icons/icon_check_box.png diff --git a/tools/editor/icons/icon_close.png b/tools/editor/icons/icon_close.png Binary files differindex 11fa746271..10e56d5bb8 100644 --- a/tools/editor/icons/icon_close.png +++ b/tools/editor/icons/icon_close.png diff --git a/tools/editor/icons/icon_close_hover.png b/tools/editor/icons/icon_close_hover.png Binary files differindex efcc9e7471..cb519691e5 100644 --- a/tools/editor/icons/icon_close_hover.png +++ b/tools/editor/icons/icon_close_hover.png diff --git a/tools/editor/icons/icon_collapse.png b/tools/editor/icons/icon_collapse.png Binary files differindex bd5c9765a5..23db9e42a7 100644 --- a/tools/editor/icons/icon_collapse.png +++ b/tools/editor/icons/icon_collapse.png diff --git a/tools/editor/icons/icon_collapse_hl.png b/tools/editor/icons/icon_collapse_hl.png Binary files differindex 7ed9a5c125..0dfbc8b175 100644 --- a/tools/editor/icons/icon_collapse_hl.png +++ b/tools/editor/icons/icon_collapse_hl.png diff --git a/tools/editor/icons/icon_connect.png b/tools/editor/icons/icon_connect.png Binary files differindex 24258414c4..745e445a61 100644 --- a/tools/editor/icons/icon_connect.png +++ b/tools/editor/icons/icon_connect.png diff --git a/tools/editor/icons/icon_del.png b/tools/editor/icons/icon_del.png Binary files differindex 5349af466e..10e56d5bb8 100644 --- a/tools/editor/icons/icon_del.png +++ b/tools/editor/icons/icon_del.png diff --git a/tools/editor/icons/icon_duplicate.png b/tools/editor/icons/icon_duplicate.png Binary files differindex bae4aa2c30..f854a14fd3 100644 --- a/tools/editor/icons/icon_duplicate.png +++ b/tools/editor/icons/icon_duplicate.png diff --git a/tools/editor/icons/icon_edit.png b/tools/editor/icons/icon_edit.png Binary files differindex 012a7f5f1d..157f785b83 100644 --- a/tools/editor/icons/icon_edit.png +++ b/tools/editor/icons/icon_edit.png diff --git a/tools/editor/icons/icon_edit_key.png b/tools/editor/icons/icon_edit_key.png Binary files differindex 43a7056f38..9ab1287fc6 100644 --- a/tools/editor/icons/icon_edit_key.png +++ b/tools/editor/icons/icon_edit_key.png diff --git a/tools/editor/icons/icon_edit_resource.png b/tools/editor/icons/icon_edit_resource.png Binary files differindex de538dfe95..31d0c68fc6 100644 --- a/tools/editor/icons/icon_edit_resource.png +++ b/tools/editor/icons/icon_edit_resource.png diff --git a/tools/editor/icons/icon_editor_focus.png b/tools/editor/icons/icon_editor_focus.png Binary files differindex f21d22ebd8..40ce11f381 100644 --- a/tools/editor/icons/icon_editor_focus.png +++ b/tools/editor/icons/icon_editor_focus.png diff --git a/tools/editor/icons/icon_enum.png b/tools/editor/icons/icon_enum.png Binary files differindex 2496e1d0db..ac36c96e28 100644 --- a/tools/editor/icons/icon_enum.png +++ b/tools/editor/icons/icon_enum.png diff --git a/tools/editor/icons/icon_event_player.png b/tools/editor/icons/icon_event_player.png Binary files differindex b67f91b1b3..68646b3dfe 100644 --- a/tools/editor/icons/icon_event_player.png +++ b/tools/editor/icons/icon_event_player.png diff --git a/tools/editor/icons/icon_file_server.png b/tools/editor/icons/icon_file_server.png Binary files differindex 27c99127c3..4bd94fa8c8 100644 --- a/tools/editor/icons/icon_file_server.png +++ b/tools/editor/icons/icon_file_server.png diff --git a/tools/editor/icons/icon_folder.png b/tools/editor/icons/icon_folder.png Binary files differindex 814f217edf..a450a7b297 100644 --- a/tools/editor/icons/icon_folder.png +++ b/tools/editor/icons/icon_folder.png diff --git a/tools/editor/icons/icon_font.png b/tools/editor/icons/icon_font.png Binary files differindex d9554183c2..3ffe4f1b17 100644 --- a/tools/editor/icons/icon_font.png +++ b/tools/editor/icons/icon_font.png diff --git a/tools/editor/icons/icon_g_d_script.png b/tools/editor/icons/icon_g_d_script.png Binary files differindex 3b1cc98c4d..88d865356c 100644 --- a/tools/editor/icons/icon_g_d_script.png +++ b/tools/editor/icons/icon_g_d_script.png diff --git a/tools/editor/icons/icon_graph_color_ramp.png b/tools/editor/icons/icon_graph_color_ramp.png Binary files differnew file mode 100644 index 0000000000..9031b5ec53 --- /dev/null +++ b/tools/editor/icons/icon_graph_color_ramp.png diff --git a/tools/editor/icons/icon_graph_comment.png b/tools/editor/icons/icon_graph_comment.png Binary files differnew file mode 100644 index 0000000000..bf7889c510 --- /dev/null +++ b/tools/editor/icons/icon_graph_comment.png diff --git a/tools/editor/icons/icon_graph_cube_uniform.png b/tools/editor/icons/icon_graph_cube_uniform.png Binary files differnew file mode 100644 index 0000000000..d1b92b4943 --- /dev/null +++ b/tools/editor/icons/icon_graph_cube_uniform.png diff --git a/tools/editor/icons/icon_graph_curve_map.png b/tools/editor/icons/icon_graph_curve_map.png Binary files differnew file mode 100644 index 0000000000..de5c32f09e --- /dev/null +++ b/tools/editor/icons/icon_graph_curve_map.png diff --git a/tools/editor/icons/icon_graph_default_texture.png b/tools/editor/icons/icon_graph_default_texture.png Binary files differnew file mode 100644 index 0000000000..da77ec9364 --- /dev/null +++ b/tools/editor/icons/icon_graph_default_texture.png diff --git a/tools/editor/icons/icon_graph_input.png b/tools/editor/icons/icon_graph_input.png Binary files differnew file mode 100644 index 0000000000..a396bc2350 --- /dev/null +++ b/tools/editor/icons/icon_graph_input.png diff --git a/tools/editor/icons/icon_graph_rgb.png b/tools/editor/icons/icon_graph_rgb.png Binary files differnew file mode 100644 index 0000000000..abffaedd34 --- /dev/null +++ b/tools/editor/icons/icon_graph_rgb.png diff --git a/tools/editor/icons/icon_graph_rgb_op.png b/tools/editor/icons/icon_graph_rgb_op.png Binary files differnew file mode 100644 index 0000000000..642fc838c2 --- /dev/null +++ b/tools/editor/icons/icon_graph_rgb_op.png diff --git a/tools/editor/icons/icon_graph_rgb_uniform.png b/tools/editor/icons/icon_graph_rgb_uniform.png Binary files differnew file mode 100644 index 0000000000..92c79997ef --- /dev/null +++ b/tools/editor/icons/icon_graph_rgb_uniform.png diff --git a/tools/editor/icons/icon_graph_scalar.png b/tools/editor/icons/icon_graph_scalar.png Binary files differnew file mode 100644 index 0000000000..028d0e9ea4 --- /dev/null +++ b/tools/editor/icons/icon_graph_scalar.png diff --git a/tools/editor/icons/icon_graph_scalar_interp.png b/tools/editor/icons/icon_graph_scalar_interp.png Binary files differnew file mode 100644 index 0000000000..4f178a27c4 --- /dev/null +++ b/tools/editor/icons/icon_graph_scalar_interp.png diff --git a/tools/editor/icons/icon_graph_scalar_op.png b/tools/editor/icons/icon_graph_scalar_op.png Binary files differnew file mode 100644 index 0000000000..0fc4cae94c --- /dev/null +++ b/tools/editor/icons/icon_graph_scalar_op.png diff --git a/tools/editor/icons/icon_graph_scalar_uniform.png b/tools/editor/icons/icon_graph_scalar_uniform.png Binary files differnew file mode 100644 index 0000000000..fc6590a8cf --- /dev/null +++ b/tools/editor/icons/icon_graph_scalar_uniform.png diff --git a/tools/editor/icons/icon_graph_scalars_to_vec.png b/tools/editor/icons/icon_graph_scalars_to_vec.png Binary files differnew file mode 100644 index 0000000000..7ca39a2f56 --- /dev/null +++ b/tools/editor/icons/icon_graph_scalars_to_vec.png diff --git a/tools/editor/icons/icon_graph_texscreen.png b/tools/editor/icons/icon_graph_texscreen.png Binary files differnew file mode 100644 index 0000000000..e183a8fa56 --- /dev/null +++ b/tools/editor/icons/icon_graph_texscreen.png diff --git a/tools/editor/icons/icon_graph_texture_uniform.png b/tools/editor/icons/icon_graph_texture_uniform.png Binary files differnew file mode 100644 index 0000000000..7517ac1d92 --- /dev/null +++ b/tools/editor/icons/icon_graph_texture_uniform.png diff --git a/tools/editor/icons/icon_graph_time.png b/tools/editor/icons/icon_graph_time.png Binary files differnew file mode 100644 index 0000000000..b61e45589f --- /dev/null +++ b/tools/editor/icons/icon_graph_time.png diff --git a/tools/editor/icons/icon_graph_vec_dp.png b/tools/editor/icons/icon_graph_vec_dp.png Binary files differnew file mode 100644 index 0000000000..059c3025e7 --- /dev/null +++ b/tools/editor/icons/icon_graph_vec_dp.png diff --git a/tools/editor/icons/icon_graph_vec_interp.png b/tools/editor/icons/icon_graph_vec_interp.png Binary files differnew file mode 100644 index 0000000000..daf7a00203 --- /dev/null +++ b/tools/editor/icons/icon_graph_vec_interp.png diff --git a/tools/editor/icons/icon_graph_vec_length.png b/tools/editor/icons/icon_graph_vec_length.png Binary files differnew file mode 100644 index 0000000000..60ade8c90a --- /dev/null +++ b/tools/editor/icons/icon_graph_vec_length.png diff --git a/tools/editor/icons/icon_graph_vec_op.png b/tools/editor/icons/icon_graph_vec_op.png Binary files differnew file mode 100644 index 0000000000..f2a7a51123 --- /dev/null +++ b/tools/editor/icons/icon_graph_vec_op.png diff --git a/tools/editor/icons/icon_graph_vec_scalar_op.png b/tools/editor/icons/icon_graph_vec_scalar_op.png Binary files differnew file mode 100644 index 0000000000..f0f4e7a196 --- /dev/null +++ b/tools/editor/icons/icon_graph_vec_scalar_op.png diff --git a/tools/editor/icons/icon_graph_vec_to_scalars.png b/tools/editor/icons/icon_graph_vec_to_scalars.png Binary files differnew file mode 100644 index 0000000000..a677a7cc53 --- /dev/null +++ b/tools/editor/icons/icon_graph_vec_to_scalars.png diff --git a/tools/editor/icons/icon_graph_vecs_to_xform.png b/tools/editor/icons/icon_graph_vecs_to_xform.png Binary files differnew file mode 100644 index 0000000000..51216c93eb --- /dev/null +++ b/tools/editor/icons/icon_graph_vecs_to_xform.png diff --git a/tools/editor/icons/icon_graph_vector.png b/tools/editor/icons/icon_graph_vector.png Binary files differnew file mode 100644 index 0000000000..9dfe47d757 --- /dev/null +++ b/tools/editor/icons/icon_graph_vector.png diff --git a/tools/editor/icons/icon_graph_vector_uniform.png b/tools/editor/icons/icon_graph_vector_uniform.png Binary files differnew file mode 100644 index 0000000000..611539fca7 --- /dev/null +++ b/tools/editor/icons/icon_graph_vector_uniform.png diff --git a/tools/editor/icons/icon_graph_xform.png b/tools/editor/icons/icon_graph_xform.png Binary files differnew file mode 100644 index 0000000000..22df472be4 --- /dev/null +++ b/tools/editor/icons/icon_graph_xform.png diff --git a/tools/editor/icons/icon_graph_xform_mult.png b/tools/editor/icons/icon_graph_xform_mult.png Binary files differnew file mode 100644 index 0000000000..5d0ce7982d --- /dev/null +++ b/tools/editor/icons/icon_graph_xform_mult.png diff --git a/tools/editor/icons/icon_graph_xform_scalar_func.png b/tools/editor/icons/icon_graph_xform_scalar_func.png Binary files differnew file mode 100644 index 0000000000..e53f08a564 --- /dev/null +++ b/tools/editor/icons/icon_graph_xform_scalar_func.png diff --git a/tools/editor/icons/icon_graph_xform_to_vecs.png b/tools/editor/icons/icon_graph_xform_to_vecs.png Binary files differnew file mode 100644 index 0000000000..847261f726 --- /dev/null +++ b/tools/editor/icons/icon_graph_xform_to_vecs.png diff --git a/tools/editor/icons/icon_graph_xform_uniform.png b/tools/editor/icons/icon_graph_xform_uniform.png Binary files differnew file mode 100644 index 0000000000..94c9759b25 --- /dev/null +++ b/tools/editor/icons/icon_graph_xform_uniform.png diff --git a/tools/editor/icons/icon_graph_xform_vec_func.png b/tools/editor/icons/icon_graph_xform_vec_func.png Binary files differnew file mode 100644 index 0000000000..f3ba528896 --- /dev/null +++ b/tools/editor/icons/icon_graph_xform_vec_func.png diff --git a/tools/editor/icons/icon_graph_xform_vec_imult.png b/tools/editor/icons/icon_graph_xform_vec_imult.png Binary files differnew file mode 100644 index 0000000000..7e7330cb8c --- /dev/null +++ b/tools/editor/icons/icon_graph_xform_vec_imult.png diff --git a/tools/editor/icons/icon_graph_xform_vec_mult.png b/tools/editor/icons/icon_graph_xform_vec_mult.png Binary files differnew file mode 100644 index 0000000000..f80a28c80d --- /dev/null +++ b/tools/editor/icons/icon_graph_xform_vec_mult.png diff --git a/tools/editor/icons/icon_group.png b/tools/editor/icons/icon_group.png Binary files differindex 577c84777e..d43b4958c9 100644 --- a/tools/editor/icons/icon_group.png +++ b/tools/editor/icons/icon_group.png diff --git a/tools/editor/icons/icon_groups.png b/tools/editor/icons/icon_groups.png Binary files differindex da4fd0d985..f4386821ed 100644 --- a/tools/editor/icons/icon_groups.png +++ b/tools/editor/icons/icon_groups.png diff --git a/tools/editor/icons/icon_hidden.png b/tools/editor/icons/icon_hidden.png Binary files differindex 45fcfc2f47..e51b9ad03a 100644 --- a/tools/editor/icons/icon_hidden.png +++ b/tools/editor/icons/icon_hidden.png diff --git a/tools/editor/icons/icon_image.png b/tools/editor/icons/icon_image.png Binary files differindex a6b1fbf6c1..5919ca8c6d 100644 --- a/tools/editor/icons/icon_image.png +++ b/tools/editor/icons/icon_image.png diff --git a/tools/editor/icons/icon_image_texture.png b/tools/editor/icons/icon_image_texture.png Binary files differindex 4618d984b8..b87e284a52 100644 --- a/tools/editor/icons/icon_image_texture.png +++ b/tools/editor/icons/icon_image_texture.png diff --git a/tools/editor/icons/icon_instance_options.png b/tools/editor/icons/icon_instance_options.png Binary files differindex 2d3e98b2ea..9108448095 100644 --- a/tools/editor/icons/icon_instance_options.png +++ b/tools/editor/icons/icon_instance_options.png diff --git a/tools/editor/icons/icon_integer.png b/tools/editor/icons/icon_integer.png Binary files differindex 0e5b5abd62..32c8d9885b 100644 --- a/tools/editor/icons/icon_integer.png +++ b/tools/editor/icons/icon_integer.png diff --git a/tools/editor/icons/icon_interp_cubic.png b/tools/editor/icons/icon_interp_cubic.png Binary files differindex ab33aa7e6a..a946d70947 100644 --- a/tools/editor/icons/icon_interp_cubic.png +++ b/tools/editor/icons/icon_interp_cubic.png diff --git a/tools/editor/icons/icon_interp_linear.png b/tools/editor/icons/icon_interp_linear.png Binary files differindex bf3849ecaf..9174af39e7 100644 --- a/tools/editor/icons/icon_interp_linear.png +++ b/tools/editor/icons/icon_interp_linear.png diff --git a/tools/editor/icons/icon_interp_raw.png b/tools/editor/icons/icon_interp_raw.png Binary files differindex 48650d6e66..f12936493b 100644 --- a/tools/editor/icons/icon_interp_raw.png +++ b/tools/editor/icons/icon_interp_raw.png diff --git a/tools/editor/icons/icon_key.png b/tools/editor/icons/icon_key.png Binary files differindex d647876866..d6096ef41f 100644 --- a/tools/editor/icons/icon_key.png +++ b/tools/editor/icons/icon_key.png diff --git a/tools/editor/icons/icon_key_selected.png b/tools/editor/icons/icon_key_selected.png Binary files differindex d916c55286..562beef98a 100644 --- a/tools/editor/icons/icon_key_selected.png +++ b/tools/editor/icons/icon_key_selected.png diff --git a/tools/editor/icons/icon_light_2d.png b/tools/editor/icons/icon_light_2d.png Binary files differnew file mode 100644 index 0000000000..9162b33090 --- /dev/null +++ b/tools/editor/icons/icon_light_2d.png diff --git a/tools/editor/icons/icon_light_map.png b/tools/editor/icons/icon_light_map.png Binary files differindex 96d3f6e11c..e0333f06ea 100644 --- a/tools/editor/icons/icon_light_map.png +++ b/tools/editor/icons/icon_light_map.png diff --git a/tools/editor/icons/icon_light_occluder_2d.png b/tools/editor/icons/icon_light_occluder_2d.png Binary files differnew file mode 100644 index 0000000000..c66dd536d3 --- /dev/null +++ b/tools/editor/icons/icon_light_occluder_2d.png diff --git a/tools/editor/icons/icon_load.png b/tools/editor/icons/icon_load.png Binary files differindex fdc06d38a3..a450a7b297 100644 --- a/tools/editor/icons/icon_load.png +++ b/tools/editor/icons/icon_load.png diff --git a/tools/editor/icons/icon_lock.png b/tools/editor/icons/icon_lock.png Binary files differindex 0cfd1d4ab1..995d87b6fb 100644 --- a/tools/editor/icons/icon_lock.png +++ b/tools/editor/icons/icon_lock.png diff --git a/tools/editor/icons/icon_loop.png b/tools/editor/icons/icon_loop.png Binary files differindex d75642359d..7bde451ca0 100644 --- a/tools/editor/icons/icon_loop.png +++ b/tools/editor/icons/icon_loop.png diff --git a/tools/editor/icons/icon_main_play.png b/tools/editor/icons/icon_main_play.png Binary files differindex 401708c49e..9e8cc6c4a9 100644 --- a/tools/editor/icons/icon_main_play.png +++ b/tools/editor/icons/icon_main_play.png diff --git a/tools/editor/icons/icon_main_stop.png b/tools/editor/icons/icon_main_stop.png Binary files differindex 3f54ba69c9..31a6cd601e 100644 --- a/tools/editor/icons/icon_main_stop.png +++ b/tools/editor/icons/icon_main_stop.png diff --git a/tools/editor/icons/icon_material_shader.png b/tools/editor/icons/icon_material_shader.png Binary files differnew file mode 100644 index 0000000000..0e476b2540 --- /dev/null +++ b/tools/editor/icons/icon_material_shader.png diff --git a/tools/editor/icons/icon_material_shader_graph.png b/tools/editor/icons/icon_material_shader_graph.png Binary files differnew file mode 100644 index 0000000000..68d8b4cb49 --- /dev/null +++ b/tools/editor/icons/icon_material_shader_graph.png diff --git a/tools/editor/icons/icon_mirror_x.png b/tools/editor/icons/icon_mirror_x.png Binary files differindex d20f90c1da..657e7f5458 100644 --- a/tools/editor/icons/icon_mirror_x.png +++ b/tools/editor/icons/icon_mirror_x.png diff --git a/tools/editor/icons/icon_mirror_y.png b/tools/editor/icons/icon_mirror_y.png Binary files differindex 5e2f710425..111aa5e4ae 100644 --- a/tools/editor/icons/icon_mirror_y.png +++ b/tools/editor/icons/icon_mirror_y.png diff --git a/tools/editor/icons/icon_move_down.png b/tools/editor/icons/icon_move_down.png Binary files differindex ef310e80e1..06c7246084 100644 --- a/tools/editor/icons/icon_move_down.png +++ b/tools/editor/icons/icon_move_down.png diff --git a/tools/editor/icons/icon_move_down_hl.png b/tools/editor/icons/icon_move_down_hl.png Binary files differindex dec56e8da8..f9de58a940 100644 --- a/tools/editor/icons/icon_move_down_hl.png +++ b/tools/editor/icons/icon_move_down_hl.png diff --git a/tools/editor/icons/icon_move_up.png b/tools/editor/icons/icon_move_up.png Binary files differindex d67b1aff0b..ca6c64f7a1 100644 --- a/tools/editor/icons/icon_move_up.png +++ b/tools/editor/icons/icon_move_up.png diff --git a/tools/editor/icons/icon_move_up_hl.png b/tools/editor/icons/icon_move_up_hl.png Binary files differindex 19ce8bbe27..e076c9a265 100644 --- a/tools/editor/icons/icon_move_up_hl.png +++ b/tools/editor/icons/icon_move_up_hl.png diff --git a/tools/editor/icons/icon_navigation_2d.png b/tools/editor/icons/icon_navigation_2d.png Binary files differnew file mode 100644 index 0000000000..8170ecf68c --- /dev/null +++ b/tools/editor/icons/icon_navigation_2d.png diff --git a/tools/editor/icons/icon_navigation_polygon_instance.png b/tools/editor/icons/icon_navigation_polygon_instance.png Binary files differnew file mode 100644 index 0000000000..9f9c318906 --- /dev/null +++ b/tools/editor/icons/icon_navigation_polygon_instance.png diff --git a/tools/editor/icons/icon_new.png b/tools/editor/icons/icon_new.png Binary files differindex 3596d2e8ea..c04785fc3f 100644 --- a/tools/editor/icons/icon_new.png +++ b/tools/editor/icons/icon_new.png diff --git a/tools/editor/icons/icon_node.png b/tools/editor/icons/icon_node.png Binary files differindex b0f7fb01dc..d8ce1b7538 100644 --- a/tools/editor/icons/icon_node.png +++ b/tools/editor/icons/icon_node.png diff --git a/tools/editor/icons/icon_occluder_polygon_2d.png b/tools/editor/icons/icon_occluder_polygon_2d.png Binary files differnew file mode 100644 index 0000000000..705794b729 --- /dev/null +++ b/tools/editor/icons/icon_occluder_polygon_2d.png diff --git a/tools/editor/icons/icon_open.png b/tools/editor/icons/icon_open.png Binary files differindex 4fad5677ca..a450a7b297 100644 --- a/tools/editor/icons/icon_open.png +++ b/tools/editor/icons/icon_open.png diff --git a/tools/editor/icons/icon_p_hash_translation.png b/tools/editor/icons/icon_p_hash_translation.png Binary files differindex c0eadc3c55..e18ef6a76f 100644 --- a/tools/editor/icons/icon_p_hash_translation.png +++ b/tools/editor/icons/icon_p_hash_translation.png diff --git a/tools/editor/icons/icon_packed_scene.png b/tools/editor/icons/icon_packed_scene.png Binary files differindex 9c1e1c4fbf..c9802f2b66 100644 --- a/tools/editor/icons/icon_packed_scene.png +++ b/tools/editor/icons/icon_packed_scene.png diff --git a/tools/editor/icons/icon_panels_1.png b/tools/editor/icons/icon_panels_1.png Binary files differindex 501c8c9acc..546ca61c89 100644 --- a/tools/editor/icons/icon_panels_1.png +++ b/tools/editor/icons/icon_panels_1.png diff --git a/tools/editor/icons/icon_panels_2.png b/tools/editor/icons/icon_panels_2.png Binary files differindex 08f104e2b1..5a4750bda2 100644 --- a/tools/editor/icons/icon_panels_2.png +++ b/tools/editor/icons/icon_panels_2.png diff --git a/tools/editor/icons/icon_panels_3.png b/tools/editor/icons/icon_panels_3.png Binary files differindex 1d1902d8dd..13988de93a 100644 --- a/tools/editor/icons/icon_panels_3.png +++ b/tools/editor/icons/icon_panels_3.png diff --git a/tools/editor/icons/icon_panels_4.png b/tools/editor/icons/icon_panels_4.png Binary files differindex 83cc133d21..c217330d43 100644 --- a/tools/editor/icons/icon_panels_4.png +++ b/tools/editor/icons/icon_panels_4.png diff --git a/tools/editor/icons/icon_pin.png b/tools/editor/icons/icon_pin.png Binary files differindex f34c8585f7..037352137d 100644 --- a/tools/editor/icons/icon_pin.png +++ b/tools/editor/icons/icon_pin.png diff --git a/tools/editor/icons/icon_pin_pressed.png b/tools/editor/icons/icon_pin_pressed.png Binary files differindex f151b5a590..5738e6856f 100644 --- a/tools/editor/icons/icon_pin_pressed.png +++ b/tools/editor/icons/icon_pin_pressed.png diff --git a/tools/editor/icons/icon_play.png b/tools/editor/icons/icon_play.png Binary files differindex 544b3bc5f4..08cce495a9 100644 --- a/tools/editor/icons/icon_play.png +++ b/tools/editor/icons/icon_play.png diff --git a/tools/editor/icons/icon_play_custom.png b/tools/editor/icons/icon_play_custom.png Binary files differindex 5c98c7100b..8e8ab8c62a 100644 --- a/tools/editor/icons/icon_play_custom.png +++ b/tools/editor/icons/icon_play_custom.png diff --git a/tools/editor/icons/icon_play_scene.png b/tools/editor/icons/icon_play_scene.png Binary files differindex 7ca59fe900..7079cc9677 100644 --- a/tools/editor/icons/icon_play_scene.png +++ b/tools/editor/icons/icon_play_scene.png diff --git a/tools/editor/icons/icon_prev_scene.png b/tools/editor/icons/icon_prev_scene.png Binary files differindex c7c180e1c4..9d8dda5180 100644 --- a/tools/editor/icons/icon_prev_scene.png +++ b/tools/editor/icons/icon_prev_scene.png diff --git a/tools/editor/icons/icon_real.png b/tools/editor/icons/icon_real.png Binary files differindex bfe5038319..80fbf7017c 100644 --- a/tools/editor/icons/icon_real.png +++ b/tools/editor/icons/icon_real.png diff --git a/tools/editor/icons/icon_reload.png b/tools/editor/icons/icon_reload.png Binary files differindex 07f53efb56..f7c6530d77 100644 --- a/tools/editor/icons/icon_reload.png +++ b/tools/editor/icons/icon_reload.png diff --git a/tools/editor/icons/icon_remove.png b/tools/editor/icons/icon_remove.png Binary files differindex 5349af466e..10e56d5bb8 100644 --- a/tools/editor/icons/icon_remove.png +++ b/tools/editor/icons/icon_remove.png diff --git a/tools/editor/icons/icon_rename.png b/tools/editor/icons/icon_rename.png Binary files differindex f88da39915..7b6a10df93 100644 --- a/tools/editor/icons/icon_rename.png +++ b/tools/editor/icons/icon_rename.png diff --git a/tools/editor/icons/icon_reparent.png b/tools/editor/icons/icon_reparent.png Binary files differindex af85b17ecc..59aee5e42d 100644 --- a/tools/editor/icons/icon_reparent.png +++ b/tools/editor/icons/icon_reparent.png diff --git a/tools/editor/icons/icon_replace.png b/tools/editor/icons/icon_replace.png Binary files differindex 2ae843ae10..662a58dc93 100644 --- a/tools/editor/icons/icon_replace.png +++ b/tools/editor/icons/icon_replace.png diff --git a/tools/editor/icons/icon_resource_preloader.png b/tools/editor/icons/icon_resource_preloader.png Binary files differindex e31e5a0d59..14b8c4de3c 100644 --- a/tools/editor/icons/icon_resource_preloader.png +++ b/tools/editor/icons/icon_resource_preloader.png diff --git a/tools/editor/icons/icon_rotate_0.png b/tools/editor/icons/icon_rotate_0.png Binary files differnew file mode 100644 index 0000000000..85a4b4c420 --- /dev/null +++ b/tools/editor/icons/icon_rotate_0.png diff --git a/tools/editor/icons/icon_rotate_180.png b/tools/editor/icons/icon_rotate_180.png Binary files differnew file mode 100644 index 0000000000..c4c516cff5 --- /dev/null +++ b/tools/editor/icons/icon_rotate_180.png diff --git a/tools/editor/icons/icon_rotate_270.png b/tools/editor/icons/icon_rotate_270.png Binary files differnew file mode 100644 index 0000000000..6e0f2e62b8 --- /dev/null +++ b/tools/editor/icons/icon_rotate_270.png diff --git a/tools/editor/icons/icon_rotate_90.png b/tools/editor/icons/icon_rotate_90.png Binary files differnew file mode 100644 index 0000000000..f25b0e99a3 --- /dev/null +++ b/tools/editor/icons/icon_rotate_90.png diff --git a/tools/editor/icons/icon_sample_player.png b/tools/editor/icons/icon_sample_player.png Binary files differindex 5561769b05..92d9cc77bf 100644 --- a/tools/editor/icons/icon_sample_player.png +++ b/tools/editor/icons/icon_sample_player.png diff --git a/tools/editor/icons/icon_save.png b/tools/editor/icons/icon_save.png Binary files differindex dce274ffb1..ddef66688d 100644 --- a/tools/editor/icons/icon_save.png +++ b/tools/editor/icons/icon_save.png diff --git a/tools/editor/icons/icon_script.png b/tools/editor/icons/icon_script.png Binary files differindex 65fb3c4934..baf5927c18 100644 --- a/tools/editor/icons/icon_script.png +++ b/tools/editor/icons/icon_script.png diff --git a/tools/editor/icons/icon_sound_room_params.png b/tools/editor/icons/icon_sound_room_params.png Binary files differindex 8e381d7978..2d37a4b49f 100644 --- a/tools/editor/icons/icon_sound_room_params.png +++ b/tools/editor/icons/icon_sound_room_params.png diff --git a/tools/editor/icons/icon_stop.png b/tools/editor/icons/icon_stop.png Binary files differindex 3b7562fa4a..fd568b61a8 100644 --- a/tools/editor/icons/icon_stop.png +++ b/tools/editor/icons/icon_stop.png diff --git a/tools/editor/icons/icon_stream_player.png b/tools/editor/icons/icon_stream_player.png Binary files differindex 2670a567e8..cf8fdcbaea 100644 --- a/tools/editor/icons/icon_stream_player.png +++ b/tools/editor/icons/icon_stream_player.png diff --git a/tools/editor/icons/icon_string.png b/tools/editor/icons/icon_string.png Binary files differindex 86cc8e633f..48bf753c40 100644 --- a/tools/editor/icons/icon_string.png +++ b/tools/editor/icons/icon_string.png diff --git a/tools/editor/icons/icon_texture.png b/tools/editor/icons/icon_texture.png Binary files differindex 03d6ac7db2..bbcc54bd6e 100644 --- a/tools/editor/icons/icon_texture.png +++ b/tools/editor/icons/icon_texture.png diff --git a/tools/editor/icons/icon_timer.png b/tools/editor/icons/icon_timer.png Binary files differindex 3855683033..e8c36ae893 100644 --- a/tools/editor/icons/icon_timer.png +++ b/tools/editor/icons/icon_timer.png diff --git a/tools/editor/icons/icon_tool_move.png b/tools/editor/icons/icon_tool_move.png Binary files differindex fc611cdbb1..7257d3897b 100644 --- a/tools/editor/icons/icon_tool_move.png +++ b/tools/editor/icons/icon_tool_move.png diff --git a/tools/editor/icons/icon_tool_pan.png b/tools/editor/icons/icon_tool_pan.png Binary files differindex 5c078a7b1c..bfe6fddf45 100644 --- a/tools/editor/icons/icon_tool_pan.png +++ b/tools/editor/icons/icon_tool_pan.png diff --git a/tools/editor/icons/icon_tool_rotate.png b/tools/editor/icons/icon_tool_rotate.png Binary files differindex c833b93d6e..9575ceb54e 100644 --- a/tools/editor/icons/icon_tool_rotate.png +++ b/tools/editor/icons/icon_tool_rotate.png diff --git a/tools/editor/icons/icon_tool_scale.png b/tools/editor/icons/icon_tool_scale.png Binary files differindex 3eaeae1e99..a94a6e7c98 100644 --- a/tools/editor/icons/icon_tool_scale.png +++ b/tools/editor/icons/icon_tool_scale.png diff --git a/tools/editor/icons/icon_tool_select.png b/tools/editor/icons/icon_tool_select.png Binary files differindex eb5ff6e1da..47683228e9 100644 --- a/tools/editor/icons/icon_tool_select.png +++ b/tools/editor/icons/icon_tool_select.png diff --git a/tools/editor/icons/icon_tools.png b/tools/editor/icons/icon_tools.png Binary files differindex 927173ea0f..f02d924203 100644 --- a/tools/editor/icons/icon_tools.png +++ b/tools/editor/icons/icon_tools.png diff --git a/tools/editor/icons/icon_track_continuous.png b/tools/editor/icons/icon_track_continuous.png Binary files differindex 97e8762299..9f99891c21 100644 --- a/tools/editor/icons/icon_track_continuous.png +++ b/tools/editor/icons/icon_track_continuous.png diff --git a/tools/editor/icons/icon_track_discrete.png b/tools/editor/icons/icon_track_discrete.png Binary files differindex 57a4cd5579..4e65e49afb 100644 --- a/tools/editor/icons/icon_track_discrete.png +++ b/tools/editor/icons/icon_track_discrete.png diff --git a/tools/editor/icons/icon_translation.png b/tools/editor/icons/icon_translation.png Binary files differindex 6211ab9a1b..917c6f548a 100644 --- a/tools/editor/icons/icon_translation.png +++ b/tools/editor/icons/icon_translation.png diff --git a/tools/editor/icons/icon_transpose.png b/tools/editor/icons/icon_transpose.png Binary files differnew file mode 100644 index 0000000000..f9b78bc0fd --- /dev/null +++ b/tools/editor/icons/icon_transpose.png diff --git a/tools/editor/icons/icon_unbone.png b/tools/editor/icons/icon_unbone.png Binary files differindex 819e8a8e5d..c8cd774460 100644 --- a/tools/editor/icons/icon_unbone.png +++ b/tools/editor/icons/icon_unbone.png diff --git a/tools/editor/icons/icon_ungroup.png b/tools/editor/icons/icon_ungroup.png Binary files differindex 16511e3f1c..4ea620bf96 100644 --- a/tools/editor/icons/icon_ungroup.png +++ b/tools/editor/icons/icon_ungroup.png diff --git a/tools/editor/icons/icon_unlock.png b/tools/editor/icons/icon_unlock.png Binary files differindex b86447bf7a..f9fa31c3e0 100644 --- a/tools/editor/icons/icon_unlock.png +++ b/tools/editor/icons/icon_unlock.png diff --git a/tools/editor/icons/icon_uv.png b/tools/editor/icons/icon_uv.png Binary files differindex 4d9d198d86..39bc737a37 100644 --- a/tools/editor/icons/icon_uv.png +++ b/tools/editor/icons/icon_uv.png diff --git a/tools/editor/icons/icon_vector.png b/tools/editor/icons/icon_vector.png Binary files differindex 7826d7f7a9..0ee33ba0b7 100644 --- a/tools/editor/icons/icon_vector.png +++ b/tools/editor/icons/icon_vector.png diff --git a/tools/editor/icons/icon_vector2.png b/tools/editor/icons/icon_vector2.png Binary files differindex 44e48c36c7..5920109a55 100644 --- a/tools/editor/icons/icon_vector2.png +++ b/tools/editor/icons/icon_vector2.png diff --git a/tools/editor/icons/icon_viewport.png b/tools/editor/icons/icon_viewport.png Binary files differindex 0a0d93cf4d..3859f6c7e9 100644 --- a/tools/editor/icons/icon_viewport.png +++ b/tools/editor/icons/icon_viewport.png diff --git a/tools/editor/icons/icon_visible.png b/tools/editor/icons/icon_visible.png Binary files differindex 519898bbef..cbc44c4e30 100644 --- a/tools/editor/icons/icon_visible.png +++ b/tools/editor/icons/icon_visible.png diff --git a/tools/editor/icons/icon_zoom.png b/tools/editor/icons/icon_zoom.png Binary files differindex cbacaaaeca..e4bbbfe7c3 100644 --- a/tools/editor/icons/icon_zoom.png +++ b/tools/editor/icons/icon_zoom.png diff --git a/tools/editor/import_settings.cpp b/tools/editor/import_settings.cpp index 74e4aa97d7..63b8d65b69 100644 --- a/tools/editor/import_settings.cpp +++ b/tools/editor/import_settings.cpp @@ -224,7 +224,7 @@ void ImportSettingsDialog::update_tree() { void ImportSettingsDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { EditorFileSystem::get_singleton()->connect("filesystem_changed",this,"update_tree"); } diff --git a/tools/editor/io_plugins/editor_font_import_plugin.cpp b/tools/editor/io_plugins/editor_font_import_plugin.cpp index 6a6ee8c614..0562153199 100644 --- a/tools/editor/io_plugins/editor_font_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_font_import_plugin.cpp @@ -47,6 +47,12 @@ class _EditorFontImportOptions : public Object { OBJ_TYPE(_EditorFontImportOptions,Object); public: + enum FontMode { + + FONT_BITMAP, + FONT_DISTANCE_FIELD + }; + enum ColorType { COLOR_WHITE, COLOR_CUSTOM, @@ -69,6 +75,9 @@ public: CHARSET_CUSTOM_LATIN }; + + FontMode font_mode; + CharacterSet character_set; String custom_file; @@ -91,7 +100,6 @@ public: bool color_use_monochrome; String gradient_image; - bool disable_filter; bool round_advance; @@ -100,7 +108,10 @@ public: bool _set(const StringName& p_name, const Variant& p_value) { String n = p_name; - if (n=="extra_space/char") + if (n=="mode/mode") { + font_mode=FontMode(int(p_value)); + _change_notify(); + } else if (n=="extra_space/char") char_extra_spacing=p_value; else if (n=="extra_space/space") space_extra_spacing=p_value; @@ -169,7 +180,9 @@ public: bool _get(const StringName& p_name,Variant &r_ret) const{ String n = p_name; - if (n=="extra_space/char") + if (n=="mode/mode") + r_ret=font_mode; + else if (n=="extra_space/char") r_ret=char_extra_spacing; else if (n=="extra_space/space") r_ret=space_extra_spacing; @@ -231,6 +244,9 @@ public: void _get_property_list( List<PropertyInfo> *p_list) const{ + + p_list->push_back(PropertyInfo(Variant::INT,"mode/mode",PROPERTY_HINT_ENUM,"Bitmap,Distance Field")); + p_list->push_back(PropertyInfo(Variant::INT,"extra_space/char",PROPERTY_HINT_RANGE,"-64,64,1")); p_list->push_back(PropertyInfo(Variant::INT,"extra_space/space",PROPERTY_HINT_RANGE,"-64,64,1")); p_list->push_back(PropertyInfo(Variant::INT,"extra_space/top",PROPERTY_HINT_RANGE,"-64,64,1")); @@ -240,35 +256,45 @@ public: if (character_set>=CHARSET_CUSTOM) p_list->push_back(PropertyInfo(Variant::STRING,"character_set/custom",PROPERTY_HINT_FILE)); - p_list->push_back(PropertyInfo(Variant::BOOL,"shadow/enabled")); - if (shadow) { - p_list->push_back(PropertyInfo(Variant::INT,"shadow/radius",PROPERTY_HINT_RANGE,"-64,64,1")); - p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow/offset")); - p_list->push_back(PropertyInfo(Variant::COLOR,"shadow/color")); - p_list->push_back(PropertyInfo(Variant::REAL,"shadow/transition",PROPERTY_HINT_EXP_EASING)); - } + int usage = PROPERTY_USAGE_DEFAULT; - p_list->push_back(PropertyInfo(Variant::BOOL,"shadow2/enabled")); - if (shadow2) { - p_list->push_back(PropertyInfo(Variant::INT,"shadow2/radius",PROPERTY_HINT_RANGE,"-64,64,1")); - p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow2/offset")); - p_list->push_back(PropertyInfo(Variant::COLOR,"shadow2/color")); - p_list->push_back(PropertyInfo(Variant::REAL,"shadow2/transition",PROPERTY_HINT_EXP_EASING)); + if (font_mode==FONT_DISTANCE_FIELD) { + usage = PROPERTY_USAGE_NOEDITOR; } - p_list->push_back(PropertyInfo(Variant::INT,"color/mode",PROPERTY_HINT_ENUM,"White,Color,Gradient,Gradient Image")); - if (color_type==COLOR_CUSTOM) { - p_list->push_back(PropertyInfo(Variant::COLOR,"color/color")); + { + p_list->push_back(PropertyInfo(Variant::BOOL,"shadow/enabled",PROPERTY_HINT_NONE,"",usage)); + if (shadow) { + p_list->push_back(PropertyInfo(Variant::INT,"shadow/radius",PROPERTY_HINT_RANGE,"-64,64,1",usage)); + p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow/offset",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"shadow/color",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::REAL,"shadow/transition",PROPERTY_HINT_EXP_EASING,"",usage)); + } + + p_list->push_back(PropertyInfo(Variant::BOOL,"shadow2/enabled",PROPERTY_HINT_NONE,"",usage)); + if (shadow2) { + p_list->push_back(PropertyInfo(Variant::INT,"shadow2/radius",PROPERTY_HINT_RANGE,"-64,64,1",usage)); + p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow2/offset",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"shadow2/color",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::REAL,"shadow2/transition",PROPERTY_HINT_EXP_EASING,"",usage)); + } + + p_list->push_back(PropertyInfo(Variant::INT,"color/mode",PROPERTY_HINT_ENUM,"White,Color,Gradient,Gradient Image",usage)); + if (color_type==COLOR_CUSTOM) { + p_list->push_back(PropertyInfo(Variant::COLOR,"color/color",PROPERTY_HINT_NONE,"",usage)); + + } + if (color_type==COLOR_GRADIENT_RANGE) { + p_list->push_back(PropertyInfo(Variant::COLOR,"color/begin",PROPERTY_HINT_NONE,"",usage)); + p_list->push_back(PropertyInfo(Variant::COLOR,"color/end",PROPERTY_HINT_NONE,"",usage)); + } + if (color_type==COLOR_GRADIENT_IMAGE) { + p_list->push_back(PropertyInfo(Variant::STRING,"color/image",PROPERTY_HINT_FILE,"",usage)); + } + p_list->push_back(PropertyInfo(Variant::BOOL,"color/monochrome",PROPERTY_HINT_NONE,"",usage)); } - if (color_type==COLOR_GRADIENT_RANGE) { - p_list->push_back(PropertyInfo(Variant::COLOR,"color/begin")); - p_list->push_back(PropertyInfo(Variant::COLOR,"color/end")); - } - if (color_type==COLOR_GRADIENT_IMAGE) { - p_list->push_back(PropertyInfo(Variant::STRING,"color/image",PROPERTY_HINT_FILE)); - } - p_list->push_back(PropertyInfo(Variant::BOOL,"color/monochrome")); + p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/round_advance")); p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/disable_filter")); @@ -307,6 +333,7 @@ public: gradient_end=Color(0.5,0.5,0.5,1); color_use_monochrome=false; + font_mode=FONT_BITMAP; round_advance=true; disable_filter=false; @@ -314,6 +341,8 @@ public: _EditorFontImportOptions() { + font_mode=FONT_BITMAP; + char_extra_spacing=0; top_extra_spacing=0; bottom_extra_spacing=0; @@ -499,7 +528,7 @@ class EditorFontImportDialog : public ConfirmationDialog { Error err = plugin->import(dest->get_line_edit()->get_text(),rimd); if (err!=OK) { - error_dialog->set_text("Could't save font."); + error_dialog->set_text("Couldn't save font."); error_dialog->popup_centered(Size2(200,100)); return; } @@ -529,7 +558,7 @@ public: void _notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { prop_edit->edit(options); _update_text(); } @@ -706,6 +735,137 @@ struct _EditorKerningKey { }; + +static unsigned char get_SDF_radial( + unsigned char *fontmap, + int w, int h, + int x, int y, + int max_radius ) +{ + // hideous brute force method + float d2 = max_radius*max_radius+1.0; + unsigned char v = fontmap[x+y*w]; + for( int radius = 1; (radius <= max_radius) && (radius*radius < d2); ++radius ) + { + int line, lo, hi; + // north + line = y - radius; + if( (line >= 0) && (line < h) ) + { + lo = x - radius; + hi = x + radius; + if( lo < 0 ) { lo = 0; } + if( hi >= w ) { hi = w-1; } + int idx = line * w + lo; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = i - x; + float ny = line - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + ++idx; + } + } + // south + line = y + radius; + if( (line >= 0) && (line < h) ) + { + lo = x - radius; + hi = x + radius; + if( lo < 0 ) { lo = 0; } + if( hi >= w ) { hi = w-1; } + int idx = line * w + lo; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = i - x; + float ny = line - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + ++idx; + } + } + // west + line = x - radius; + if( (line >= 0) && (line < w) ) + { + lo = y - radius + 1; + hi = y + radius - 1; + if( lo < 0 ) { lo = 0; } + if( hi >= h ) { hi = h-1; } + int idx = lo * w + line; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = line - x; + float ny = i - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + idx += w; + } + } + // east + line = x + radius; + if( (line >= 0) && (line < w) ) + { + lo = y - radius + 1; + hi = y + radius - 1; + if( lo < 0 ) { lo = 0; } + if( hi >= h ) { hi = h-1; } + int idx = lo * w + line; + for( int i = lo; i <= hi; ++i ) + { + // check this pixel + if( fontmap[idx] != v ) + { + float nx = line - x; + float ny = i - y; + float nd2 = nx*nx+ny*ny; + if( nd2 < d2 ) + { + d2 = nd2; + } + } + // move on + idx += w; + } + } + } + d2 = sqrtf( d2 ); + if( v==0 ) + { + d2 = -d2; + } + d2 *= 127.5 / max_radius; + d2 += 127.5; + if( d2 < 0.0 ) d2 = 0.0; + if( d2 > 255.0 ) d2 = 255.0; + return (unsigned char)(d2 + 0.5); +} + + Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata>& p_from, const String &p_existing) { Ref<ResourceImportMetadata> from = p_from; @@ -754,7 +914,11 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata } - error = FT_Set_Pixel_Sizes(face,0,size); + int font_mode = from->get_option("mode/mode"); + + int scaler=(font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD)?16:1; + + error = FT_Set_Pixel_Sizes(face,0,size*scaler); FT_GlyphSlot slot = face->glyph; @@ -820,9 +984,9 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata { bool skip=false; - error = FT_Load_Char( face, charcode, FT_LOAD_RENDER ); + error = FT_Load_Char( face, charcode, font_mode==_EditorFontImportOptions::FONT_BITMAP?FT_LOAD_RENDER:FT_LOAD_MONOCHROME ); if (error) skip=true; - else error = FT_Render_Glyph( face->glyph, ft_render_mode_normal ); + else error = FT_Render_Glyph( face->glyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono ); if (error) { skip=true; } else if (!skip) { @@ -847,28 +1011,36 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata } _EditorFontData * fdata = memnew( _EditorFontData ); - fdata->bitmap.resize( slot->bitmap.width*slot->bitmap.rows ); - fdata->width=slot->bitmap.width; - fdata->height=slot->bitmap.rows; - fdata->character=charcode; - fdata->glyph=FT_Get_Char_Index(face,charcode); - if (charcode=='x') - xsize=slot->bitmap.width; - if (charcode<127) { - if (slot->bitmap_top>max_up) { + int w = slot->bitmap.width; + int h = slot->bitmap.rows; + int p = slot->bitmap.pitch; - max_up=slot->bitmap_top; - } + print_line("W: "+itos(w)+" P: "+itos(slot->bitmap.pitch)); + if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { - if ( (slot->bitmap_top - fdata->height)<max_down ) { + // oversize the holding buffer so I can smooth it! + int sw = w + scaler * 4; + int sh = h + scaler * 4; + // do the SDF + int sdfw = sw / scaler; + int sdfh = sh / scaler; - max_down=slot->bitmap_top - fdata->height; - } + fdata->width=sdfw; + fdata->height=sdfh; + } else { + fdata->width=w; + fdata->height=h; } + fdata->character=charcode; + fdata->glyph=FT_Get_Char_Index(face,charcode); + if (charcode=='x') + xsize=w/scaler; + + fdata->valign=slot->bitmap_top; fdata->halign=slot->bitmap_left; @@ -878,12 +1050,85 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata else fdata->advance=slot->advance.x/float(1<<6); + if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { + + fdata->halign = fdata->halign / scaler - 1.5; + fdata->valign = fdata->valign / scaler + 1.5; + fdata->advance/=scaler; + + } + fdata->advance+=font_spacing; - for (int i=0;i<slot->bitmap.width;i++) { - for (int j=0;j<slot->bitmap.rows;j++) { - fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + if (charcode<127) { + int top = fdata->valign; + int hmax = h/scaler; + + if (top>max_up) { + + max_up=top; + } + + + if ( (top - hmax)<max_down ) { + + max_down=top - hmax; + } + } + + if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) { + + + // oversize the holding buffer so I can smooth it! + int sw = w + scaler * 4; + int sh = h + scaler * 4; + + unsigned char *smooth_buf = new unsigned char[sw*sh]; + + for( int i = 0; i < sw*sh; ++i ) { + smooth_buf[i] = 0; + } + + // copy the glyph into the buffer to be smoothed + unsigned char *buf = slot->bitmap.buffer; + for( int j = 0; j < h; ++j ) { + for( int i = 0; i < w; ++i ) { + smooth_buf[scaler*2+i+(j+scaler*2)*sw] = 255 * ((buf[j*p+(i>>3)] >> (7 - (i & 7))) & 1); + } + } + + // do the SDF + int sdfw = fdata->width; + int sdfh = fdata->height; + + fdata->bitmap.resize( sdfw*sdfh ); + + for( int j = 0; j < sdfh; ++j ) { + for( int i = 0; i < sdfw; ++i ) { + int pd_idx = j*sdfw+i; + + //fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + + fdata->bitmap[pd_idx] = + //get_SDF + get_SDF_radial + ( smooth_buf, sw, sh, + i*scaler + (scaler >>1), j*scaler + (scaler >>1), + 2*scaler ); + + } + } + + delete [] smooth_buf; + + } else { + fdata->bitmap.resize( slot->bitmap.width*slot->bitmap.rows ); + for (int i=0;i<slot->bitmap.width;i++) { + for (int j=0;j<slot->bitmap.rows;j++) { + + fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i]; + } } } @@ -904,9 +1149,10 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata spd->ofs_x=0; spd->ofs_y=0; - if (!FT_Load_Char( face, ' ', FT_LOAD_RENDER ) && !FT_Render_Glyph( face->glyph, ft_render_mode_normal )) { + if (!FT_Load_Char( face, ' ', FT_LOAD_RENDER ) && !FT_Render_Glyph( face->glyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono )) { spd->advance = slot->advance.x>>6; //round to nearest or store as float + spd->advance/=scaler; spd->advance+=font_spacing; } else { @@ -955,7 +1201,7 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata if (kern==0) continue; - kerning_map[kpk]=kern; + kerning_map[kpk]=kern/scaler; } } } @@ -1079,7 +1325,7 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata pixels.resize(s.x*s.y*4); DVector<uint8_t>::Write w = pixels.write(); - print_line("val: "+itos(font_data_list[i]->valign)); + //print_line("val: "+itos(font_data_list[i]->valign)); for(int y=0;y<s.height;y++) { int yc=CLAMP(y-o.y+font_data_list[i]->valign,0,height-1); @@ -1284,6 +1530,7 @@ Ref<Font> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata font->clear(); font->set_height(height+bottom_space+top_space); font->set_ascent(ascent+top_space); + font->set_distance_field_hint(font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD); //register texures { diff --git a/tools/editor/io_plugins/editor_import_collada.cpp b/tools/editor/io_plugins/editor_import_collada.cpp index e86356ebe9..990e52be46 100644 --- a/tools/editor/io_plugins/editor_import_collada.cpp +++ b/tools/editor/io_plugins/editor_import_collada.cpp @@ -39,6 +39,7 @@ #include "scene/resources/packed_scene.h" #include "os/os.h" #include "tools/editor/editor_node.h" +#include <iostream> struct ColladaImport { @@ -61,6 +62,8 @@ struct ColladaImport { Color ambient; bool found_directional; bool force_make_tangents; + bool apply_mesh_xform_to_vertices; + float bake_fps; @@ -68,6 +71,7 @@ struct ColladaImport { Map<String, Ref<Mesh> > mesh_cache; Map<String, Ref<Curve3D> > curve_cache; Map<String, Ref<Material> > material_cache; + Map<Collada::Node*,Skeleton*> skeleton_map; Map< Skeleton*, Map< String, int> > skeleton_bone_map; @@ -76,6 +80,7 @@ struct ColladaImport { Map<String,bool> bones_with_animation; Error _populate_skeleton(Skeleton *p_skeleton,Collada::Node *p_node, int &r_bone, int p_parent); + Error _create_scene_skeletons(Collada::Node *p_node); Error _create_scene(Collada::Node *p_node, Spatial *p_parent); Error _create_resources(Collada::Node *p_node); Error _create_material(const String& p_material); @@ -95,6 +100,8 @@ struct ColladaImport { found_ambient=false; found_directional=false; force_make_tangents=false; + apply_mesh_xform_to_vertices=true; + bake_fps=15; } }; @@ -108,7 +115,7 @@ Error ColladaImport::_populate_skeleton(Skeleton *p_skeleton,Collada::Node *p_no Collada::NodeJoint *joint = static_cast<Collada::NodeJoint*>(p_node); - + print_line("populating joint "+joint->name); p_skeleton->add_bone(p_node->name); if (p_parent>=0) p_skeleton->set_bone_parent(r_bone,p_parent); @@ -168,6 +175,34 @@ void ColladaImport::_pre_process_lights(Collada::Node *p_node) { _pre_process_lights(p_node->children[i]); } +Error ColladaImport::_create_scene_skeletons(Collada::Node *p_node) { + + + if (p_node->type==Collada::Node::TYPE_SKELETON) { + + Skeleton *sk = memnew( Skeleton ); + int bone = 0; + + for(int i=0;i<p_node->children.size();i++) { + + _populate_skeleton(sk,p_node->children[i],bone,-1); + } + sk->localize_rests(); //after creating skeleton, rests must be localized...! + skeleton_map[p_node]=sk; + } + + + for(int i=0;i<p_node->children.size();i++) { + + Error err = _create_scene_skeletons(p_node->children[i]); + if (err) + return err; + } + return OK; + +} + + Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) { Spatial * node=NULL; @@ -251,13 +286,16 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) { case Collada::CameraData::MODE_ORTHOGONAL: { - if (cd.orthogonal.x_mag) { + if (cd.orthogonal.y_mag) { - camera->set_orthogonal(cd.orthogonal.x_mag,cd.z_near,cd.z_far); + camera->set_keep_aspect_mode(Camera::KEEP_HEIGHT); + camera->set_orthogonal(cd.orthogonal.y_mag*2.0 ,cd.z_near,cd.z_far); - } else if (!cd.orthogonal.x_mag && cd.orthogonal.y_mag) { + } else if (!cd.orthogonal.y_mag && cd.orthogonal.x_mag) { - camera->set_orthogonal(cd.orthogonal.y_mag * cd.aspect,cd.z_near,cd.z_far); + + camera->set_keep_aspect_mode(Camera::KEEP_WIDTH); + camera->set_orthogonal(cd.orthogonal.x_mag*2.0,cd.z_near,cd.z_far); } } break; @@ -295,15 +333,8 @@ Error ColladaImport::_create_scene(Collada::Node *p_node, Spatial *p_parent) { } break; case Collada::Node::TYPE_SKELETON: { - Skeleton *sk = memnew( Skeleton ); - int bone = 0; - - for(int i=0;i<p_node->children.size();i++) { - - _populate_skeleton(sk,p_node->children[i],bone,-1); - } - sk->localize_rests(); //after creating skeleton, rests must be localized...! - + ERR_FAIL_COND_V(!skeleton_map.has(p_node),ERR_CANT_CREATE); + Skeleton *sk = skeleton_map[p_node]; node=sk; } break; @@ -1327,8 +1358,60 @@ Error ColladaImport::_create_mesh_surfaces(Ref<Mesh>& p_mesh,const Map<String,Co vertw = DVector<Vector3>::Write(); DVector<Vector3> normals; DVector<float> tangents; + if(md.vertices[vertex_src_id].sources.has("NORMAL")){ + //has normals + normals.resize(vlen); + //std::cout << "has normals" << std::endl; + String normal_src_id = md.vertices[vertex_src_id].sources["NORMAL"]; + //std::cout << "normals source: "<< normal_src_id.utf8().get_data() <<std::endl; + ERR_FAIL_COND_V(!md.sources.has(normal_src_id),ERR_INVALID_DATA); + + const Collada::MeshData::Source *m=&md.sources[normal_src_id]; + + ERR_FAIL_COND_V( m->array.size() != vertex_src->array.size(), ERR_INVALID_DATA); + int stride=m->stride; + if (stride==0) + stride=3; + + + //read normals from morph target + DVector<Vector3>::Write vertw = normals.write(); + + for(int m_i=0;m_i<m->array.size()/stride;m_i++) { + + int pos = m_i*stride; + Vector3 vtx( m->array[pos+0], m->array[pos+1], m->array[pos+2] ); + + #ifndef NO_UP_AXIS_SWAP + if (collada.state.up_axis==Vector3::AXIS_Z) { - _generate_normals(index_array,vertices,normals); + SWAP( vtx.z, vtx.y ); + vtx.z = -vtx.z; + + } + #endif + + Collada::Vertex vertex; + vertex.vertex=vtx; + vertex.fix_unit_scale(collada); + vtx=vertex.vertex; + + vtx = p_local_xform.xform(vtx); + + + if (vertex_map.has(m_i)) { //vertex may no longer be here, don't bother converting + + + for (Set<int> ::Element *E=vertex_map[m_i].front() ; E; E=E->next() ) { + + vertw[E->get()]=vtx; + } + } + } + + }else{ + _generate_normals(index_array,vertices,normals);//no normals + } if (final_tangent_array.size() && final_uv_array.size()) { _generate_tangents_and_binormals(index_array,vertices,final_uv_array,normals,tangents); @@ -1500,6 +1583,9 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { ERR_FAIL_COND_V( skeletons.empty(), ERR_INVALID_DATA ); String skname = skeletons[0]; + if (!node_map.has(skname)) { + print_line("no node for skeleton "+skname); + } ERR_FAIL_COND_V( !node_map.has(skname), ERR_INVALID_DATA ); NodeMap nmsk = node_map[skname]; Skeleton *sk = nmsk.node->cast_to<Skeleton>(); @@ -1516,8 +1602,12 @@ Error ColladaImport::_create_resources(Collada::Node *p_node) { meshid=morph->mesh; } - apply_xform=collada.fix_transform(p_node->default_transform); - node->set_transform(Transform()); + if (apply_mesh_xform_to_vertices) { + apply_xform=collada.fix_transform(p_node->default_transform); + node->set_transform(Transform()); + } else { + apply_xform=Transform(); + } Collada::SkinControllerData::Source *joint_src=NULL; @@ -1613,6 +1703,16 @@ Error ColladaImport::load(const String& p_path,int p_flags,bool p_force_make_tan } //import scene + + for(int i=0;i<vs.root_nodes.size();i++) { + + Error err = _create_scene_skeletons(vs.root_nodes[i]); + if (err!=OK) { + memdelete(scene); + ERR_FAIL_COND_V(err,err); + } + } + for(int i=0;i<vs.root_nodes.size();i++) { Error err = _create_scene(vs.root_nodes[i],scene); @@ -1835,19 +1935,22 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones Vector<float> base_snapshots; float f=0; - float snapshot_interval = 1.0/20.0; //should be customizable somewhere... + float snapshot_interval = 1.0/bake_fps; //should be customizable somewhere... float anim_length=collada.state.animation_length; if (p_clip>=0 && collada.state.animation_clips[p_clip].end) anim_length=collada.state.animation_clips[p_clip].end; while(f<anim_length) { - if (f>=anim_length) - f=anim_length; base_snapshots.push_back(f); f+=snapshot_interval; + + if (f>=anim_length) { + base_snapshots.push_back(anim_length); + } } + //print_line("anim len: "+rtos(anim_length)); animation->set_length(anim_length); @@ -1892,6 +1995,8 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones for(int i=0;i<at.keys.size();i++) snapshots.push_back(at.keys[i].time); + print_line("using anim snapshots"); + } @@ -2142,14 +2247,14 @@ void EditorSceneImporterCollada::get_extensions(List<String> *r_extensions) cons r_extensions->push_back("dae"); } -Node* EditorSceneImporterCollada::import_scene(const String& p_path, uint32_t p_flags, List<String> *r_missing_deps, Error* r_err) { - +Node* EditorSceneImporterCollada::import_scene(const String& p_path, uint32_t p_flags,int p_bake_fps, List<String> *r_missing_deps, Error* r_err) { ColladaImport state; uint32_t flags=Collada::IMPORT_FLAG_SCENE; if (p_flags&IMPORT_ANIMATION) flags|=Collada::IMPORT_FLAG_ANIMATION; + state.bake_fps=p_bake_fps; Error err = state.load(p_path,flags,p_flags&EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS); @@ -2174,7 +2279,7 @@ Node* EditorSceneImporterCollada::import_scene(const String& p_path, uint32_t p_ if (p_flags&IMPORT_ANIMATION) { - state.create_animations(p_flags&IMPORT_ANIMATION_FORCE_TRACKS_IN_ALL_BONES); + state.create_animations(p_flags&IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS); AnimationPlayer *ap = memnew( AnimationPlayer ); for(int i=0;i<state.animations.size();i++) { String name; @@ -2183,8 +2288,6 @@ Node* EditorSceneImporterCollada::import_scene(const String& p_path, uint32_t p_ else name=state.animations[i]->get_name(); - if (p_flags&IMPORT_ANIMATION_OPTIMIZE) - state.animations[i]->optimize(); if (p_flags&IMPORT_ANIMATION_DETECT_LOOP) { if (name.begins_with("loop") || name.ends_with("loop") || name.begins_with("cycle") || name.ends_with("cycle")) { @@ -2213,7 +2316,7 @@ Ref<Animation> EditorSceneImporterCollada::import_animation(const String& p_path ERR_FAIL_COND_V(err!=OK,RES()); - state.create_animations(p_flags&EditorSceneImporter::IMPORT_ANIMATION_FORCE_TRACKS_IN_ALL_BONES); + state.create_animations(p_flags&EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS); if (state.scene) memdelete(state.scene); @@ -2230,8 +2333,6 @@ Ref<Animation> EditorSceneImporterCollada::import_animation(const String& p_path } } - if (p_flags&IMPORT_ANIMATION_OPTIMIZE) - anim->optimize(); return anim; } diff --git a/tools/editor/io_plugins/editor_import_collada.h b/tools/editor/io_plugins/editor_import_collada.h index 9580f42ed0..ae4cedeff6 100644 --- a/tools/editor/io_plugins/editor_import_collada.h +++ b/tools/editor/io_plugins/editor_import_collada.h @@ -40,7 +40,7 @@ public: virtual uint32_t get_import_flags() const; virtual void get_extensions(List<String> *r_extensions) const; - virtual Node* import_scene(const String& p_path,uint32_t p_flags,List<String> *r_missing_deps=NULL,Error* r_err=NULL); + virtual Node* import_scene(const String& p_path,uint32_t p_flags,int p_bake_fps,List<String> *r_missing_deps=NULL,Error* r_err=NULL); virtual Ref<Animation> import_animation(const String& p_path,uint32_t p_flags); EditorSceneImporterCollada(); diff --git a/tools/editor/io_plugins/editor_mesh_import_plugin.cpp b/tools/editor/io_plugins/editor_mesh_import_plugin.cpp index d76a778433..7d6f400ccc 100644 --- a/tools/editor/io_plugins/editor_mesh_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_mesh_import_plugin.cpp @@ -245,7 +245,7 @@ public: void _notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { option_editor->edit(options); } @@ -425,7 +425,7 @@ Error EditorMeshImportPlugin::import(const String& p_path, const Ref<ResourceImp ERR_FAIL_COND_V(v.size()<3,ERR_INVALID_DATA); Vector2 uv; uv.x=v[1].to_float(); - uv.y=v[2].to_float(); + uv.y=1.0-v[2].to_float(); uvs.push_back(uv); } else if (l.begins_with("vn ")) { diff --git a/tools/editor/io_plugins/editor_sample_import_plugin.cpp b/tools/editor/io_plugins/editor_sample_import_plugin.cpp index cd02156eef..377af8f179 100644 --- a/tools/editor/io_plugins/editor_sample_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_sample_import_plugin.cpp @@ -290,7 +290,7 @@ public: void _notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { option_editor->edit(options); } diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.cpp b/tools/editor/io_plugins/editor_scene_import_plugin.cpp index 27400344d3..06780e4d8a 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_scene_import_plugin.cpp @@ -78,12 +78,31 @@ class EditorImportAnimationOptions : public VBoxContainer { OBJ_TYPE( EditorImportAnimationOptions, VBoxContainer ); + + TreeItem *fps; + TreeItem* optimize_linear_error; + TreeItem* optimize_angular_error; + TreeItem* optimize_max_angle; + + TreeItem *clips_base; + + TextEdit *filters; + Vector<TreeItem*> clips; + Tree *flags; + Tree *clips_tree; + Tree *optimization_tree; Vector<TreeItem*> items; bool updating; + bool validating; + + void _changed(); + void _item_edited(); + void _button_action(Object *p_obj,int p_col,int p_id); + protected: static void _bind_methods(); void _notification(int p_what); @@ -93,6 +112,23 @@ public: void set_flags(uint32_t p_flags); uint32_t get_flags() const; + void set_fps(int p_fps); + int get_fps() const; + + void set_optimize_linear_error(float p_error); + float get_optimize_linear_error() const; + + void set_optimize_angular_error(float p_error); + float get_optimize_angular_error() const; + + void set_optimize_max_angle(float p_error); + float get_optimize_max_angle() const; + + void setup_clips(const Array& p_clips); + Array get_clips() const; + + void set_filter(const String& p_filter); + String get_filter() const; EditorImportAnimationOptions(); @@ -141,6 +177,9 @@ class EditorSceneImportDialog : public ConfirmationDialog { Map<Ref<Mesh>,Ref<Shape> > collision_map; ConfirmationDialog *error_dialog; + OptionButton *this_import; + OptionButton *next_import; + void _choose_file(const String& p_path); void _choose_save_file(const String& p_path); void _choose_script(const String& p_path); @@ -178,7 +217,7 @@ static const char *anim_flag_names[]={ "Detect Loop (-loop,-cycle)", "Keep Value Tracks", "Optimize", - "Force Tracks in All Bones", + "Force All Tracks in All Clips", NULL }; @@ -223,9 +262,101 @@ void EditorImportAnimationOptions::_changed() { } +void EditorImportAnimationOptions::_button_action(Object *p_obj,int p_col,int p_id) { + + memdelete(p_obj); + +} + + +void EditorImportAnimationOptions::_item_edited() { + + if (validating) + return; + + if (clips.size()==0) + return; + validating=true; + print_line("edited"); + TreeItem *item = clips_tree->get_edited(); + if (item==clips[clips.size()-1]) { + //add new + print_line("islast"); + if (item->get_text(0).find("<")!=-1 || item->get_text(0).find(">")!=-1) { + validating=false; + return; //fuckit + } + + item->set_editable(1,true); + item->set_editable(2,true); + item->add_button(0,EditorNode::get_singleton()->get_gui_base()->get_icon("Del","EditorIcons")); + item->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); + item->set_range_config(1,0,3600,0.01); + item->set_range(1,0); + item->set_editable(1,true); + item->set_cell_mode(2,TreeItem::CELL_MODE_RANGE); + item->set_range_config(2,0,3600,0.01); + item->set_range(2,0); + item->set_cell_mode(3,TreeItem::CELL_MODE_CHECK); + item->set_editable(3,true); + + TreeItem *newclip = clips_tree->create_item(clips_base); + newclip->set_text(0,"<new clip>"); + newclip->set_editable(0,true); + newclip->set_editable(1,false); + newclip->set_editable(2,false); + clips.push_back(newclip); + + + + } + + + //make name unique JUST IN CASE + String name = item->get_text(0); + name=name.replace("/","_").replace(":","_").strip_edges(); + if (name=="") + name="New Clip"; + + if (clips.size()>2) { + int index=1; + while(true) { + bool valid = true; + String try_name=name; + if (index>1) + try_name+=" "+itos(index); + + for(int i=0;i<clips.size()-1;i++) { + + if (clips[i]==item) + continue; + if (clips[i]->get_text(0)==try_name) { + index++; + valid=false; + break; + } + } + + if (valid) { + name=try_name; + break; + } + + } + } + + if (item->get_text(0)!=name) + item->set_text(0,name); + + validating=false; + +} + void EditorImportAnimationOptions::_bind_methods() { ObjectTypeDB::bind_method("_changed",&EditorImportAnimationOptions::_changed); + ObjectTypeDB::bind_method("_item_edited",&EditorImportAnimationOptions::_item_edited); + ObjectTypeDB::bind_method("_button_action",&EditorImportAnimationOptions::_button_action); // ObjectTypeDB::bind_method("_changedp",&EditorImportAnimationOptions::_changedp); ADD_SIGNAL(MethodInfo("changed")); @@ -234,20 +365,87 @@ void EditorImportAnimationOptions::_bind_methods() { void EditorImportAnimationOptions::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { flags->connect("item_edited",this,"_changed"); + clips_tree->connect("item_edited",this,"_item_edited"); + clips_tree->connect("button_pressed",this,"_button_action",varray(),CONNECT_DEFERRED); // format->connect("item_selected",this,"_changedp"); } } + +Array EditorImportAnimationOptions::get_clips() const { + + Array arr; + for(int i=0;i<clips.size()-1;i++) { + + arr.push_back(clips[i]->get_text(0)); + arr.push_back(clips[i]->get_range(1)); + arr.push_back(clips[i]->get_range(2)); + arr.push_back(clips[i]->is_checked(3)); + } + + return arr; +} + + +void EditorImportAnimationOptions::setup_clips(const Array& p_clips) { + + ERR_FAIL_COND(p_clips.size()%4!=0); + for(int i=0;i<clips.size();i++) { + + memdelete(clips[i]); + } + + + clips.clear(); + + for(int i=0;i<p_clips.size();i+=4) { + + TreeItem *clip = clips_tree->create_item(clips_base); + clip->set_text(0,p_clips[i]); + clip->add_button(0,EditorNode::get_singleton()->get_gui_base()->get_icon("Del","EditorIcons")); + clip->set_editable(0,true); + clip->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); + clip->set_range_config(1,0,3600,0.01); + clip->set_range(1,p_clips[i+1]); + clip->set_editable(1,true); + clip->set_cell_mode(2,TreeItem::CELL_MODE_RANGE); + clip->set_range_config(2,0,3600,0.01); + clip->set_range(2,p_clips[i+2]); + clip->set_editable(2,true); + clip->set_cell_mode(3,TreeItem::CELL_MODE_CHECK); + clip->set_editable(3,true); + clip->set_checked(3,p_clips[i+3]); + clips.push_back(clip); + + } + + TreeItem *newclip = clips_tree->create_item(clips_base); + newclip->set_text(0,"<new clip>"); + newclip->set_editable(0,true); + newclip->set_editable(1,false); + newclip->set_editable(2,false); + newclip->set_editable(3,false); + clips.push_back(newclip); + +} + + EditorImportAnimationOptions::EditorImportAnimationOptions() { updating=false; + validating=false; + + TabContainer *tab= memnew(TabContainer); + add_margin_child("Animation Options",tab,true); flags = memnew( Tree ); flags->set_hide_root(true); + tab->add_child(flags); + flags->set_name("Flags"); TreeItem *root = flags->create_item(); const char ** fname=anim_flag_names; @@ -263,14 +461,133 @@ EditorImportAnimationOptions::EditorImportAnimationOptions() { items.push_back(ti); fname++; fdescr++; - } + } + + + TreeItem *fps_base = flags->create_item(root); + fps_base->set_text(0,"Bake FPS:"); + fps_base->set_editable(0,false); + fps = flags->create_item(fps_base); + fps->set_cell_mode(0,TreeItem::CELL_MODE_RANGE); + fps->set_editable(0,true); + fps->set_range_config(0,1,120,1); + fps->set_range(0,15); + + optimization_tree = memnew( Tree ); + optimization_tree->set_columns(2); + tab->add_child(optimization_tree); + optimization_tree->set_name("Optimizer"); + optimization_tree->set_column_expand(0,true); + optimization_tree->set_column_expand(1,false); + optimization_tree->set_column_min_width(1,80); + optimization_tree->set_hide_root(true); + + + TreeItem *optimize_root = optimization_tree->create_item(); + + optimize_linear_error = optimization_tree->create_item(optimize_root); + optimize_linear_error->set_text(0,"Max Linear Error"); + optimize_linear_error->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); + optimize_linear_error->set_editable(1,true); + optimize_linear_error->set_range_config(1,0,1,0.001); + optimize_linear_error->set_range(1,0.05); + + optimize_angular_error = optimization_tree->create_item(optimize_root); + optimize_angular_error->set_text(0,"Max Angular Error"); + optimize_angular_error->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); + optimize_angular_error->set_editable(1,true); + optimize_angular_error->set_range_config(1,0,1,0.001); + optimize_angular_error->set_range(1,0.01); + + optimize_max_angle = optimization_tree->create_item(optimize_root); + optimize_max_angle->set_text(0,"Max Angle"); + optimize_max_angle->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); + optimize_max_angle->set_editable(1,true); + optimize_max_angle->set_range_config(1,0,360,0.001); + optimize_max_angle->set_range(1,int(180*0.125)); + + clips_tree = memnew( Tree ); + clips_tree->set_hide_root(true); + tab->add_child(clips_tree); + clips_tree->set_name("Clips"); + + clips_tree->set_columns(4); + clips_tree->set_column_expand(0,1); + clips_tree->set_column_expand(1,0); + clips_tree->set_column_expand(2,0); + clips_tree->set_column_expand(3,0); + clips_tree->set_column_min_width(1,60); + clips_tree->set_column_min_width(2,60); + clips_tree->set_column_min_width(3,40); + clips_tree->set_column_titles_visible(true); + clips_tree->set_column_title(0,"Name"); + clips_tree->set_column_title(1,"Start(s)"); + clips_tree->set_column_title(2,"End(s)"); + clips_tree->set_column_title(3,"Loop"); + clips_base =clips_tree->create_item(0); + + + setup_clips(Array()); + + + filters = memnew( TextEdit ); + tab->add_child(filters); + filters->set_name("Filters"); +} + + + +void EditorImportAnimationOptions::set_fps(int p_fps) { + + fps->set_range(0,p_fps); +} + +int EditorImportAnimationOptions::get_fps() const { + + return fps->get_range(0); +} + + +void EditorImportAnimationOptions::set_optimize_linear_error(float p_optimize_linear_error) { + + optimize_linear_error->set_range(1,p_optimize_linear_error); +} + +float EditorImportAnimationOptions::get_optimize_linear_error() const { + + return optimize_linear_error->get_range(1); +} + +void EditorImportAnimationOptions::set_optimize_angular_error(float p_optimize_angular_error) { + + optimize_angular_error->set_range(1,p_optimize_angular_error); +} + +float EditorImportAnimationOptions::get_optimize_angular_error() const { + + return optimize_angular_error->get_range(1); +} + +void EditorImportAnimationOptions::set_optimize_max_angle(float p_optimize_max_angle) { + + optimize_max_angle->set_range(1,p_optimize_max_angle); +} + +float EditorImportAnimationOptions::get_optimize_max_angle() const { + + return optimize_max_angle->get_range(1); +} - add_margin_child("Animation Options",flags,true); +void EditorImportAnimationOptions::set_filter(const String& p_filter) { + filters->set_text(p_filter); } +String EditorImportAnimationOptions::get_filter() const { + return filters->get_text(); +} @@ -308,6 +625,17 @@ void EditorSceneImportDialog::_choose_file(const String& p_path) { } #endif + if (p_path!=String()) { + + String from_path = EditorFileSystem::get_singleton()->find_resource_from_source(EditorImportPlugin::validate_source_path(p_path)); + print_line("from path.."+from_path); + if (from_path!=String()) { + popup_import(from_path); + + } + } + + import_path->set_text(p_path); } @@ -413,7 +741,15 @@ void EditorSceneImportDialog::_import(bool p_and_open) { rim->set_option("texture_format",texture_options->get_format()); rim->set_option("texture_quality",texture_options->get_quality()); rim->set_option("animation_flags",animation_options->get_flags()); + rim->set_option("animation_bake_fps",animation_options->get_fps()); + rim->set_option("animation_optimizer_linear_error",animation_options->get_optimize_linear_error()); + rim->set_option("animation_optimizer_angular_error",animation_options->get_optimize_angular_error()); + rim->set_option("animation_optimizer_max_angle",animation_options->get_optimize_max_angle()); + rim->set_option("animation_filters",animation_options->get_filter()); + rim->set_option("animation_clips",animation_options->get_clips()); rim->set_option("post_import_script",script_path->get_text()!=String()?EditorImportPlugin::validate_source_path(script_path->get_text()):String()); + rim->set_option("import_this_time",this_import->get_selected()); + rim->set_option("import_next_time",next_import->get_selected()); rim->set_option("reimport",true); List<String> missing; @@ -526,7 +862,7 @@ void EditorSceneImportDialog::_browse_script() { void EditorSceneImportDialog::popup_import(const String &p_from) { - popup_centered(Size2(700,500)); + popup_centered(Size2(750,550)); if (p_from!="") { Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from); if (rimd.is_null()) @@ -544,7 +880,24 @@ void EditorSceneImportDialog::popup_import(const String &p_from) { texture_options->set_format(EditorTextureImportPlugin::ImageFormat(int(rimd->get_option("texture_format")))); texture_options->set_quality(rimd->get_option("texture_quality")); animation_options->set_flags(rimd->get_option("animation_flags")); + if (rimd->has_option("animation_clips")) + animation_options->setup_clips(rimd->get_option("animation_clips")); + if (rimd->has_option("animation_filters")) + animation_options->set_filter(rimd->get_option("animation_filters")); + if (rimd->has_option("animation_bake_fps")) + animation_options->set_fps(rimd->get_option("animation_bake_fps")); + if (rimd->has_option("animation_optimizer_linear_error")) + animation_options->set_optimize_linear_error(rimd->get_option("animation_optimizer_linear_error")); + if (rimd->has_option("animation_optimizer_angular_error")) + animation_options->set_optimize_angular_error(rimd->get_option("animation_optimizer_angular_error")); + if (rimd->has_option("animation_optimizer_max_angle")) + animation_options->set_optimize_max_angle(rimd->get_option("animation_optimizer_max_angle")); + script_path->set_text(rimd->get_option("post_import_script")); + if (rimd->has_option("import_this_time")) + this_import->select(rimd->get_option("import_this_time")); + if (rimd->has_option("import_next_time")) + next_import->select(rimd->get_option("import_next_time")); save_path->set_text(p_from.get_base_dir()); import_path->set_text(EditorImportPlugin::expand_source_path(rimd->get_source_path(0))); @@ -556,7 +909,7 @@ void EditorSceneImportDialog::popup_import(const String &p_from) { void EditorSceneImportDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { List<String> extensions; @@ -619,7 +972,7 @@ void EditorSceneImportDialog::_bind_methods() { ObjectTypeDB::bind_method("_choose_file",&EditorSceneImportDialog::_choose_file); ObjectTypeDB::bind_method("_choose_save_file",&EditorSceneImportDialog::_choose_save_file); ObjectTypeDB::bind_method("_choose_script",&EditorSceneImportDialog::_choose_script); - ObjectTypeDB::bind_method("_import",&EditorSceneImportDialog::_import); + ObjectTypeDB::bind_method("_import",&EditorSceneImportDialog::_import,DEFVAL(false)); ObjectTypeDB::bind_method("_browse",&EditorSceneImportDialog::_browse); ObjectTypeDB::bind_method("_browse_target",&EditorSceneImportDialog::_browse_target); ObjectTypeDB::bind_method("_browse_script",&EditorSceneImportDialog::_browse_script); @@ -792,6 +1145,20 @@ EditorSceneImportDialog::EditorSceneImportDialog(EditorNode *p_editor, EditorSce error_dialog->get_ok()->set_text("Accept"); // error_dialog->get_cancel()->hide(); + this_import = memnew( OptionButton ); + this_import->add_item("Overwrite Existing Scene"); + this_import->add_item("Owerwrite Existing, Keep Materials"); + this_import->add_item("Keep Existing, Merge with New"); + this_import->add_item("Keep Existing, Ignore New"); + vbc->add_margin_child("This Time:",this_import); + + next_import = memnew( OptionButton ); + next_import->add_item("Overwrite Existing Scene"); + next_import->add_item("Owerwrite Existing, Keep Materials"); + next_import->add_item("Keep Existing, Merge with New"); + next_import->add_item("Keep Existing, Ignore New"); + vbc->add_margin_child("Next Time:",next_import); + set_hide_on_ok(false); GLOBAL_DEF("import/shared_textures","res://"); @@ -814,7 +1181,7 @@ EditorSceneImportDialog::EditorSceneImportDialog(EditorNode *p_editor, EditorSce animation_options = memnew( EditorImportAnimationOptions ); ovb->add_child(animation_options); animation_options->set_v_size_flags(SIZE_EXPAND_FILL); - animation_options->set_flags(EditorSceneAnimationImportPlugin::ANIMATION_DETECT_LOOP|EditorSceneAnimationImportPlugin::ANIMATION_KEEP_VALUE_TRACKS|EditorSceneAnimationImportPlugin::ANIMATION_OPTIMIZE|EditorSceneAnimationImportPlugin::ANIMATION_FORCE_TRACKS_IN_ALL_BONES); + animation_options->set_flags(EditorSceneAnimationImportPlugin::ANIMATION_DETECT_LOOP|EditorSceneAnimationImportPlugin::ANIMATION_KEEP_VALUE_TRACKS|EditorSceneAnimationImportPlugin::ANIMATION_OPTIMIZE|EditorSceneAnimationImportPlugin::ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS); confirm_import = memnew( ConfirmationDialog ); @@ -1815,6 +2182,79 @@ void EditorSceneImportPlugin::_merge_scenes(Node *p_node,Node *p_imported) { } +void EditorSceneImportPlugin::_scan_materials(Node*p_base,Node *p_node,Map<String,Ref<Material> > &mesh_materials,Map<String,Ref<Material> >& override_materials) { + + if (!p_base && p_node->get_owner()!=p_base) + return; + MeshInstance *mi=p_node->cast_to<MeshInstance>(); + + if (mi) { + if (mi->get_material_override().is_valid()) { + String path = p_base->get_path_to(p_node); + override_materials[path]=mi->get_material_override(); + } + Ref<Mesh> mesh = mi->get_mesh(); + if (mesh.is_valid()) { + + for(int i=0;i<mesh->get_surface_count();i++) { + + String name = mesh->get_name()+":"+mesh->surface_get_name(i); + if (!mesh_materials.has(name)) { + mesh_materials[name]=mesh->surface_get_material(i); + } + } + } + } + + for(int i=0;i<p_node->get_child_count();i++) { + _scan_materials(p_base,p_node->get_child(i),mesh_materials,override_materials); + } +} + + +void EditorSceneImportPlugin::_apply_materials(Node*p_base,Node *p_node,Map<String,Ref<Material> > &mesh_materials,Map<String,Ref<Material> >& override_materials,Set<Ref<Mesh> >& meshes_processed) { + + if (!p_base && p_node->get_owner()!=p_base) + return; + + MeshInstance *mi=p_node->cast_to<MeshInstance>(); + + if (mi) { + + String path = p_base->get_path_to(p_node); + if (override_materials.has(path)) + mi->set_material_override(override_materials[path]); + + Ref<Mesh> mesh = mi->get_mesh(); + if (mesh.is_valid() && !meshes_processed.has(mesh)) { + meshes_processed.insert(mesh); + for(int i=0;i<mesh->get_surface_count();i++) { + + String name = mesh->get_name()+":"+mesh->surface_get_name(i); + if (mesh_materials.has(name)) { + + Ref<Material> mat = mesh_materials[name]; + mesh->surface_set_material(i,mat); + } + } + } + } + + for(int i=0;i<p_node->get_child_count();i++) { + _apply_materials(p_base,p_node->get_child(i),mesh_materials,override_materials,meshes_processed); + } +} + +void EditorSceneImportPlugin::_merge_materials(Node *p_node,Node *p_imported) { + + Map<String,Ref<Material> > mesh_materials; + Map<String,Ref<Material> > override_materials; + + _scan_materials(p_node,p_node,mesh_materials,override_materials); + Set<Ref<Mesh> > mp; + _apply_materials(p_imported,p_imported,mesh_materials,override_materials,mp); + +} #if 0 @@ -1882,14 +2322,22 @@ Error EditorSceneImportPlugin::import1(const Ref<ResourceImportMetadata>& p_from int animation_flags=p_from->get_option("animation_flags"); int scene_flags = from->get_option("flags"); + int fps = 24; + if (from->has_option("animation_bake_fps")) + fps=from->get_option("animation_bake_fps"); + + + Array clips; + if (from->has_option("animation_clips")) + clips=from->get_option("animation_clips"); uint32_t import_flags=0; if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_DETECT_LOOP) import_flags|=EditorSceneImporter::IMPORT_ANIMATION_DETECT_LOOP; if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_OPTIMIZE) import_flags|=EditorSceneImporter::IMPORT_ANIMATION_OPTIMIZE; - if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_FORCE_TRACKS_IN_ALL_BONES) - import_flags|=EditorSceneImporter::IMPORT_ANIMATION_FORCE_TRACKS_IN_ALL_BONES; + if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS) + import_flags|=EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS; if (scene_flags&SCENE_FLAG_IMPORT_ANIMATIONS) import_flags|=EditorSceneImporter::IMPORT_ANIMATION; //if (scene_flags&SCENE_FLAG_FAIL_ON_MISSING_IMAGES) @@ -1902,7 +2350,7 @@ Error EditorSceneImportPlugin::import1(const Ref<ResourceImportMetadata>& p_from Error err=OK; - Node *scene = importer->import_scene(src_path,import_flags,r_missing,&err); + Node *scene = importer->import_scene(src_path,import_flags,fps,r_missing,&err); if (!scene || err!=OK) { return err; } @@ -1913,19 +2361,301 @@ Error EditorSceneImportPlugin::import1(const Ref<ResourceImportMetadata>& p_from return OK; } + +void EditorSceneImportPlugin::_create_clips(Node *scene, const Array& p_clips,bool p_bake_all) { + + if (!scene->has_node(String("AnimationPlayer"))) + return; + + Node* n = scene->get_node(String("AnimationPlayer")); + ERR_FAIL_COND(!n); + AnimationPlayer *anim = n->cast_to<AnimationPlayer>(); + ERR_FAIL_COND(!anim); + + if (!anim->has_animation("default")) + return; + + + Ref<Animation> default_anim = anim->get_animation("default"); + + for(int i=0;i<p_clips.size();i+=4) { + + String name = p_clips[i]; + float from=p_clips[i+1]; + float to=p_clips[i+2]; + bool loop=p_clips[i+3]; + if (from>=to) + continue; + + Ref<Animation> new_anim = memnew( Animation ); + + for(int j=0;j<default_anim->get_track_count();j++) { + + + List<float> keys; + int kc = default_anim->track_get_key_count(j); + int dtrack=-1; + for(int k=0;k<kc;k++) { + + float kt = default_anim->track_get_key_time(j,k); + if (kt>=from && kt<to) { + + //found a key within range, so create track + if (dtrack==-1) { + new_anim->add_track(default_anim->track_get_type(j)); + dtrack = new_anim->get_track_count()-1; + new_anim->track_set_path(dtrack,default_anim->track_get_path(j)); + + if (kt>(from+0.01) && k>0) { + + if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) { + Quat q; + Vector3 p; + Vector3 s; + default_anim->transform_track_interpolate(j,from,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,0,p,q,s); + } + } + + } + + if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) { + Quat q; + Vector3 p; + Vector3 s; + default_anim->transform_track_get_key(j,k,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,kt-from,p,q,s); + } + + } + + if (dtrack!=-1 && kt>=to) { + + if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) { + Quat q; + Vector3 p; + Vector3 s; + default_anim->transform_track_interpolate(j,to,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,to-from,p,q,s); + } + } + + } + + if (dtrack==-1 && p_bake_all) { + new_anim->add_track(default_anim->track_get_type(j)); + dtrack = new_anim->get_track_count()-1; + new_anim->track_set_path(dtrack,default_anim->track_get_path(j)); + if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) { + + + Quat q; + Vector3 p; + Vector3 s; + default_anim->transform_track_interpolate(j,from,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,0,p,q,s); + default_anim->transform_track_interpolate(j,to,&p,&q,&s); + new_anim->transform_track_insert_key(dtrack,to-from,p,q,s); + } + + } + } + + + new_anim->set_loop(loop); + new_anim->set_length(to-from); + anim->add_animation(name,new_anim); + } + + anim->remove_animation("default"); //remove default (no longer needed) +} + +void EditorSceneImportPlugin::_filter_anim_tracks(Ref<Animation> anim,Set<String> &keep) { + + Ref<Animation> a = anim; + ERR_FAIL_COND(!a.is_valid()); + + print_line("From Anim "+anim->get_name()+":"); + + for(int j=0;j<a->get_track_count();j++) { + + String path = a->track_get_path(j); + + if (!keep.has(path)) { + + print_line("Remove: "+path); + a->remove_track(j); + j--; + } + + } +} + + +void EditorSceneImportPlugin::_filter_tracks(Node *scene, const String& p_text) { + + if (!scene->has_node(String("AnimationPlayer"))) + return; + Node* n = scene->get_node(String("AnimationPlayer")); + ERR_FAIL_COND(!n); + AnimationPlayer *anim = n->cast_to<AnimationPlayer>(); + ERR_FAIL_COND(!anim); + + Vector<String> strings = p_text.split("\n"); + for(int i=0;i<strings.size();i++) { + + strings[i]=strings[i].strip_edges(); + } + + List<StringName> anim_names; + anim->get_animation_list(&anim_names); + for(List<StringName>::Element *E=anim_names.front();E;E=E->next()) { + + String name = E->get(); + bool valid_for_this=false; + bool valid=false; + + Set<String> keep; + Set<String> keep_local; + + + for(int i=0;i<strings.size();i++) { + + + if (strings[i].begins_with("@")) { + + valid_for_this=false; + for(Set<String>::Element *F=keep_local.front();F;F=F->next()) { + keep.insert(F->get()); + } + keep_local.clear(); + + Vector<String> filters=strings[i].substr(1,strings[i].length()).split(","); + for(int j=0;j<filters.size();j++) { + + String fname = filters[j].strip_edges(); + if (fname=="") + continue; + int fc = fname[0]; + bool plus; + if (fc=='+') + plus=true; + else if (fc=='-') + plus=false; + else + continue; + + String filter=fname.substr(1,fname.length()).strip_edges(); + + if (!name.matchn(filter)) + continue; + valid_for_this=plus; + } + + if (valid_for_this) + valid=true; + + } else if (valid_for_this) { + + Ref<Animation> a = anim->get_animation(name); + if (!a.is_valid()) + continue; + + for(int j=0;j<a->get_track_count();j++) { + + String path = a->track_get_path(j); + + String tname = strings[i]; + if (tname=="") + continue; + int fc = tname[0]; + bool plus; + if (fc=='+') + plus=true; + else if (fc=='-') + plus=false; + else + continue; + + String filter=tname.substr(1,tname.length()).strip_edges(); + + if (!path.matchn(filter)) + continue; + + if (plus) + keep_local.insert(path); + else if (!keep.has(path)) { + keep_local.erase(path); + } + } + + } + + } + + if (valid) { + for(Set<String>::Element *F=keep_local.front();F;F=F->next()) { + keep.insert(F->get()); + } + + _filter_anim_tracks(anim->get_animation(name),keep); + } + + } + + + +} + +void EditorSceneImportPlugin::_optimize_animations(Node *scene, float p_max_lin_error,float p_max_ang_error,float p_max_angle) { + + if (!scene->has_node(String("AnimationPlayer"))) + return; + Node* n = scene->get_node(String("AnimationPlayer")); + ERR_FAIL_COND(!n); + AnimationPlayer *anim = n->cast_to<AnimationPlayer>(); + ERR_FAIL_COND(!anim); + + + List<StringName> anim_names; + anim->get_animation_list(&anim_names); + for(List<StringName>::Element *E=anim_names.front();E;E=E->next()) { + + Ref<Animation> a = anim->get_animation(E->get()); + a->optimize(p_max_lin_error,p_max_ang_error,Math::deg2rad(p_max_angle)); + } +} + + Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, const Ref<ResourceImportMetadata>& p_from) { Error err=OK; Ref<ResourceImportMetadata> from=p_from; String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0)); int animation_flags=p_from->get_option("animation_flags"); + Array animation_clips = p_from->get_option("animation_clips"); + String animation_filter = p_from->get_option("animation_filters"); int scene_flags = from->get_option("flags"); + float anim_optimizer_linerr=0.05; + float anim_optimizer_angerr=0.01; + float anim_optimizer_maxang=22; + + if (from->has_option("animation_optimizer_linear_error")) + anim_optimizer_linerr=from->get_option("animation_optimizer_linear_error"); + if (from->has_option("animation_optimizer_angular_error")) + anim_optimizer_angerr=from->get_option("animation_optimizer_angular_error"); + if (from->has_option("animation_optimizer_max_angle")) + anim_optimizer_maxang=from->get_option("animation_optimizer_max_angle"); EditorProgress progress("import","Import Scene",104); progress.step("Importing Scene..",2); - bool merge = !bool(from->get_option("reimport")); + bool reimport = bool(from->get_option("reimport")); + int this_time_action = from->get_option("import_this_time"); + int next_time_action = from->get_option("import_next_time"); + + int import_action = reimport?this_time_action:next_time_action; from->set_source_md5(0,FileAccess::get_md5(src_path)); from->set_editor(get_name()); @@ -1940,6 +2670,13 @@ Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, c Map< Ref<ImageTexture>,TextureRole > imagemap; scene=_fix_node(scene,scene,collision_map,scene_flags,imagemap); + if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_OPTIMIZE) + _optimize_animations(scene,anim_optimizer_linerr,anim_optimizer_angerr,anim_optimizer_maxang); + if (animation_clips.size()) + _create_clips(scene,animation_clips,animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS); + + _filter_tracks(scene,animation_filter); + /// BEFORE ANYTHING, RUN SCRIPT @@ -2063,7 +2800,7 @@ Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, c /// BEFORE SAVING - MERGE - if (merge) { + if (import_action!=SCENE_UPDATE_REPLACE_WITH_NEW) { progress.step("Merging..",103); @@ -2082,10 +2819,30 @@ Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, c if (existing) { - _merge_scenes(existing,scene); - memdelete(scene); - scene=existing; + switch(import_action) { + + case SCENE_UPDATE_REPLACE_WITH_NEW: break; + case SCENE_UPDATE_REPLACE_WITH_NEW_KEEP_MATERIALS: { + + _merge_materials(existing,scene); + memdelete(existing); + + } break; + case SCENE_UPDATE_KEEP_OLD_MERGE_CHANGES: { + + _merge_scenes(existing,scene); + memdelete(scene); + scene=existing; + + } break; + case SCENE_UPDATE_KEEP_OLD: { + + memdelete(scene); + scene=existing; + } break; + } + } } diff --git a/tools/editor/io_plugins/editor_scene_import_plugin.h b/tools/editor/io_plugins/editor_scene_import_plugin.h index 72b4089d89..fa4730f7ee 100644 --- a/tools/editor/io_plugins/editor_scene_import_plugin.h +++ b/tools/editor/io_plugins/editor_scene_import_plugin.h @@ -58,7 +58,7 @@ public: IMPORT_ANIMATION=2, IMPORT_ANIMATION_DETECT_LOOP=4, IMPORT_ANIMATION_OPTIMIZE=8, - IMPORT_ANIMATION_FORCE_TRACKS_IN_ALL_BONES=16, + IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS=16, IMPORT_GENERATE_TANGENT_ARRAYS=256, IMPORT_FAIL_ON_MISSING_DEPENDENCIES=512 @@ -66,7 +66,7 @@ public: virtual uint32_t get_import_flags() const=0; virtual void get_extensions(List<String> *r_extensions) const=0; - virtual Node* import_scene(const String& p_path,uint32_t p_flags,List<String> *r_missing_deps,Error* r_err=NULL)=0; + virtual Node* import_scene(const String& p_path,uint32_t p_flags,int p_bake_fps,List<String> *r_missing_deps,Error* r_err=NULL)=0; virtual Ref<Animation> import_animation(const String& p_path,uint32_t p_flags)=0; @@ -108,10 +108,18 @@ class EditorSceneImportPlugin : public EditorImportPlugin { void _find_resources(const Variant& p_var,Map<Ref<ImageTexture>,TextureRole >& image_map,int p_flags); Node* _fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>,Ref<Shape> > &collision_map,uint32_t p_flags,Map<Ref<ImageTexture>,TextureRole >& image_map); + void _create_clips(Node *scene, const Array& p_clips, bool p_bake_all); + void _filter_anim_tracks(Ref<Animation> anim,Set<String> &keep); + void _filter_tracks(Node *scene, const String& p_text); void _merge_existing_node(Node *p_node,Node *p_imported_scene,Set<Ref<Resource> >& checked_resources,Set<Node*> &checked_nodes); + void _add_new_nodes(Node *p_node,Node *p_imported,Node *p_imported_scene,Set<Node*> &checked_nodes); + void _optimize_animations(Node *scene, float p_max_lin_error,float p_max_ang_error,float p_max_angle); void _merge_scenes(Node *p_node, Node *p_imported); + void _scan_materials(Node*p_base,Node *p_node,Map<String,Ref<Material> > &mesh_materials,Map<String,Ref<Material> >& override_materials); + void _apply_materials(Node*p_base,Node *p_node,Map<String,Ref<Material> > &mesh_materials,Map<String,Ref<Material> >& override_materials,Set<Ref<Mesh> >& meshes_processed); + void _merge_materials(Node *p_node,Node *p_imported); void _tag_import_paths(Node *p_scene,Node *p_node); @@ -142,6 +150,13 @@ public: SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY=1<<30, }; + enum SceneUpdate { + SCENE_UPDATE_REPLACE_WITH_NEW, + SCENE_UPDATE_REPLACE_WITH_NEW_KEEP_MATERIALS, + SCENE_UPDATE_KEEP_OLD_MERGE_CHANGES, + SCENE_UPDATE_KEEP_OLD, + }; + virtual String get_name() const; virtual String get_visible_name() const; @@ -171,7 +186,7 @@ public: ANIMATION_DETECT_LOOP=1, ANIMATION_KEEP_VALUE_TRACKS=2, ANIMATION_OPTIMIZE=4, - ANIMATION_FORCE_TRACKS_IN_ALL_BONES=8 + ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS=8 }; virtual String get_name() const; @@ -185,5 +200,4 @@ public: }; - #endif // EDITOR_SCENE_IMPORT_PLUGIN_H diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.cpp b/tools/editor/io_plugins/editor_texture_import_plugin.cpp index 86f7787a9c..ce376f2e7b 100644 --- a/tools/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_texture_import_plugin.cpp @@ -151,7 +151,7 @@ void EditorImportTextureOptions::_bind_methods() { void EditorImportTextureOptions::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { flags->connect("item_edited",this,"_changed"); format->connect("item_selected",this,"_changedp"); @@ -411,7 +411,11 @@ void EditorTextureImportDialog::popup_import(const String& p_from) { Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from); ERR_FAIL_COND(!rimd.is_valid()); - save_path->set_text(p_from.get_base_dir()); + if (plugin->get_mode()==EditorTextureImportPlugin::MODE_ATLAS) + save_path->set_text(p_from); + else + save_path->set_text(p_from.get_base_dir()); + texture_options->set_format(EditorTextureImportPlugin::ImageFormat(int(rimd->get_option("format")))); texture_options->set_flags(rimd->get_option("flags")); texture_options->set_quality(rimd->get_option("quality")); @@ -429,7 +433,7 @@ void EditorTextureImportDialog::popup_import(const String& p_from) { void EditorTextureImportDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { List<String> extensions; diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.h b/tools/editor/io_plugins/editor_texture_import_plugin.h index d17b3c05c2..e733a3ddf9 100644 --- a/tools/editor/io_plugins/editor_texture_import_plugin.h +++ b/tools/editor/io_plugins/editor_texture_import_plugin.h @@ -98,6 +98,7 @@ public: IMAGE_FLAG_USE_ANISOTROPY=1024, //convert image to linear }; + Mode get_mode() const { return mode; } virtual String get_name() const; virtual String get_visible_name() const; virtual void import_dialog(const String& p_from=""); diff --git a/tools/editor/io_plugins/editor_translation_import_plugin.cpp b/tools/editor/io_plugins/editor_translation_import_plugin.cpp index 89a7584f77..9540869789 100644 --- a/tools/editor/io_plugins/editor_translation_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_translation_import_plugin.cpp @@ -273,7 +273,7 @@ public: void _notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { } diff --git a/tools/editor/output_strings.cpp b/tools/editor/output_strings.cpp index 122db3adf9..ec85505484 100644 --- a/tools/editor/output_strings.cpp +++ b/tools/editor/output_strings.cpp @@ -129,7 +129,7 @@ void OutputStrings::_notification(int p_what) { } break; - case NOTIFICATION_ENTER_SCENE: + case NOTIFICATION_ENTER_TREE: case NOTIFICATION_RESIZED: { diff --git a/tools/editor/plugins/animation_player_editor_plugin.cpp b/tools/editor/plugins/animation_player_editor_plugin.cpp index 0d709b9a72..f706d67f6d 100644 --- a/tools/editor/plugins/animation_player_editor_plugin.cpp +++ b/tools/editor/plugins/animation_player_editor_plugin.cpp @@ -76,6 +76,8 @@ void AnimationPlayerEditor::_notification(int p_what) { seek->set_val(player->get_current_animation_pos()); if (edit_anim->is_pressed()) editor->get_animation_editor()->set_anim_pos(player->get_current_animation_pos()); + EditorNode::get_singleton()->get_property_editor()->refresh(); + } else if (last_active) { //need the last frame after it stopped @@ -87,7 +89,7 @@ void AnimationPlayerEditor::_notification(int p_what) { updating = false; } - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { editor->connect("hide_animation_player_editors",this,"_hide_anim_editors"); add_anim->set_icon( get_icon("New","EditorIcons") ); @@ -119,7 +121,7 @@ void AnimationPlayerEditor::_notification(int p_what) { if (p_what==NOTIFICATION_READY) { - get_scene()->connect("node_removed",this,"_node_removed"); + get_tree()->connect("node_removed",this,"_node_removed"); } if (p_what==NOTIFICATION_DRAW) { @@ -854,6 +856,8 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos) { return; seek->set_val(p_pos); + EditorNode::get_singleton()->get_property_editor()->refresh(); + //seekit diff --git a/tools/editor/plugins/animation_tree_editor_plugin.cpp b/tools/editor/plugins/animation_tree_editor_plugin.cpp index aeef593093..af15e17f50 100644 --- a/tools/editor/plugins/animation_tree_editor_plugin.cpp +++ b/tools/editor/plugins/animation_tree_editor_plugin.cpp @@ -221,8 +221,8 @@ void AnimationTreeEditor::_edit_dialog_animation_changed() { void AnimationTreeEditor::_edit_dialog_edit_animation() { - if (get_scene()->is_editor_hint()) { - get_scene()->get_root()->get_child(0)->call("_resource_selected", property_editor->get_variant().operator RefPtr()); + if (get_tree()->is_editor_hint()) { + get_tree()->get_root()->get_child(0)->call("_resource_selected", property_editor->get_variant().operator RefPtr()); }; }; @@ -936,7 +936,7 @@ void AnimationTreeEditor::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { play_button->set_icon( get_icon("Play","EditorIcons") ); add_menu->set_icon( get_icon("Add","EditorIcons") ); diff --git a/tools/editor/plugins/baked_light_baker.cpp b/tools/editor/plugins/baked_light_baker.cpp index 3774b7d25b..184f80a1b7 100644 --- a/tools/editor/plugins/baked_light_baker.cpp +++ b/tools/editor/plugins/baked_light_baker.cpp @@ -4,8 +4,17 @@ #include <cmath> #include "io/marshalls.h" #include "tools/editor/editor_node.h" +#include "tools/editor/editor_settings.h" +void baked_light_baker_add_64f(double *dst,double value); +void baked_light_baker_add_64i(int64_t *dst,int64_t value); + +//-separar en 2 testuras? +//*mejorar performance y threads +//*modos lineales +//*saturacion + _FORCE_INLINE_ static uint64_t get_uv_normal_bit(const Vector3& p_vector) { int lat = Math::fast_ftoi(Math::floor(Math::acos(p_vector.dot(Vector3(0,1,0)))*6.0/Math_PI+0.5)); @@ -66,6 +75,12 @@ BakedLightBaker::MeshTexture* BakedLightBaker::_get_mat_tex(const Ref<Texture>& image.convert(Image::FORMAT_RGBA); } + if (imgtex->get_flags()&Texture::FLAG_CONVERT_TO_LINEAR) { + Image copy = image; + copy.srgb_to_linear(); + image=copy; + } + DVector<uint8_t> dvt=image.get_data(); DVector<uint8_t>::Read r=dvt.read(); MeshTexture mt; @@ -105,8 +120,13 @@ void BakedLightBaker::_add_mesh(const Ref<Mesh>& p_mesh,const Ref<Material>& p_m if (fm.is_valid()) { //fixed route mm.diffuse.color=fm->get_parameter(FixedMaterial::PARAM_DIFFUSE); + if (linear_color) + mm.diffuse.color=mm.diffuse.color.to_linear(); mm.diffuse.tex=_get_mat_tex(fm->get_texture(FixedMaterial::PARAM_DIFFUSE)); mm.specular.color=fm->get_parameter(FixedMaterial::PARAM_SPECULAR); + if (linear_color) + mm.specular.color=mm.specular.color.to_linear(); + mm.specular.tex=_get_mat_tex(fm->get_texture(FixedMaterial::PARAM_SPECULAR)); } else { @@ -270,6 +290,11 @@ void BakedLightBaker::_parse_geometry(Node* p_node) { dirl.type=VS::LightType(dl->get_light_type()); dirl.diffuse=dl->get_color(DirectionalLight::COLOR_DIFFUSE); dirl.specular=dl->get_color(DirectionalLight::COLOR_SPECULAR); + if (linear_color) + dirl.diffuse=dirl.diffuse.to_linear(); + if (linear_color) + dirl.specular=dirl.specular.to_linear(); + dirl.energy=dl->get_parameter(DirectionalLight::PARAM_ENERGY); dirl.pos=dl->get_global_transform().origin; dirl.up=dl->get_global_transform().basis.get_axis(1).normalized(); @@ -472,8 +497,11 @@ void BakedLightBaker::_make_bvh() { } bvh=_parse_bvh(bases.ptr(),bases.size(),1,max_depth); + ray_stack = memnew_arr(uint32_t,max_depth); bvh_stack = memnew_arr(BVH*,max_depth); + + bvh_depth = max_depth; } void BakedLightBaker::_octree_insert(int p_octant,Triangle* p_triangle, int p_depth) { @@ -563,6 +591,12 @@ void BakedLightBaker::_octree_insert(int p_octant,Triangle* p_triangle, int p_de child->aabb.pos.z+=child->aabb.size.z; + child->full_accum[0]=0; + child->full_accum[1]=0; + child->full_accum[2]=0; + child->sampler_ofs=0; + + if (stack_pos==octree_depth-1) { child->leaf=true; @@ -585,14 +619,10 @@ void BakedLightBaker::_octree_insert(int p_octant,Triangle* p_triangle, int p_de cell_count++; int lz = lights.size(); - child->light = memnew_arr(OctantLight,lz); - - for(int li=0;li<lz;li++) { - for(int ci=0;ci<8;ci++) { - child->light[li].accum[ci][0]=0; - child->light[li].accum[ci][1]=0; - child->light[li].accum[ci][2]=0; - } + for(int ci=0;ci<8;ci++) { + child->light_accum[ci][0]=0; + child->light_accum[ci][1]=0; + child->light_accum[ci][2]=0; } child->parent=ptr_stack[stack_pos]; @@ -797,12 +827,12 @@ void BakedLightBaker::_make_octree() { -void BakedLightBaker::_plot_light(int p_light_index, const Vector3& p_plot_pos, const AABB& p_plot_aabb, const Color& p_light, const Plane& p_plane) { +void BakedLightBaker::_plot_light(ThreadStack& thread_stack,const Vector3& p_plot_pos, const AABB& p_plot_aabb, const Color& p_light,const Color& p_tint_light,bool p_only_full, const Plane& p_plane) { //stackless version - uint32_t *stack=octant_stack; - uint32_t *ptr_stack=octantptr_stack; + uint32_t *stack=thread_stack.octant_stack; + uint32_t *ptr_stack=thread_stack.octantptr_stack; Octant *octants=octant_pool.ptr(); stack[0]=0; @@ -815,6 +845,29 @@ void BakedLightBaker::_plot_light(int p_light_index, const Vector3& p_plot_pos, Octant &octant=octants[ptr_stack[stack_pos]]; + if (stack[stack_pos]==0) { + + + Vector3 pos = octant.aabb.pos + octant.aabb.size*0.5; + float md = 1<<(octree_depth - stack_pos ); + float r=cell_size*plot_size*md; + float div = 1.0/(md*md*md); + //div=1.0; + + + float d = p_plot_pos.distance_to(pos); + + if ((p_plane.distance_to(pos)>-cell_size*1.75*md) && d<=r) { + + + float intensity = 1.0 - (d/r)*(d/r); //not gauss but.. + + baked_light_baker_add_64f(&octant.full_accum[0],p_tint_light.r*intensity*div); + baked_light_baker_add_64f(&octant.full_accum[1],p_tint_light.g*intensity*div); + baked_light_baker_add_64f(&octant.full_accum[2],p_tint_light.b*intensity*div); + } + } + if (octant.leaf) { @@ -822,41 +875,44 @@ void BakedLightBaker::_plot_light(int p_light_index, const Vector3& p_plot_pos, //if (p_plane.normal.dot(octant.aabb.get_support(p_plane.normal)) < p_plane.d-CMP_EPSILON) { //octants behind are no go - - float r=cell_size*plot_size; - for(int i=0;i<8;i++) { - Vector3 pos=octant.aabb.pos; - if (i&1) - pos.x+=octant.aabb.size.x; - if (i&2) - pos.y+=octant.aabb.size.y; - if (i&4) - pos.z+=octant.aabb.size.z; + if (!p_only_full) { + float r=cell_size*plot_size; + for(int i=0;i<8;i++) { + Vector3 pos=octant.aabb.pos; + if (i&1) + pos.x+=octant.aabb.size.x; + if (i&2) + pos.y+=octant.aabb.size.y; + if (i&4) + pos.z+=octant.aabb.size.z; - float d = p_plot_pos.distance_to(pos); + float d = p_plot_pos.distance_to(pos); - if ((p_plane.distance_to(pos)>-cell_size*1.75) && d<=r) { + if ((p_plane.distance_to(pos)>-cell_size*1.75) && d<=r) { - float intensity = 1.0 - (d/r)*(d/r); //not gauss but.. - if (edge_damp>0) { - Vector3 normal = Vector3(octant.normal_accum[i][0],octant.normal_accum[i][1],octant.normal_accum[i][2]); - if (normal.x>0 || normal.y>0 || normal.z>0) { + float intensity = 1.0 - (d/r)*(d/r); //not gauss but.. + if (edge_damp>0) { + Vector3 normal = Vector3(octant.normal_accum[i][0],octant.normal_accum[i][1],octant.normal_accum[i][2]); + if (normal.x>0 || normal.y>0 || normal.z>0) { - float damp = Math::abs(p_plane.normal.dot(normal)); - intensity*=pow(damp,edge_damp); + float damp = Math::abs(p_plane.normal.dot(normal)); + intensity*=pow(damp,edge_damp); + } } - } - //intensity*=1.0-Math::abs(p_plane.distance_to(pos))/(plot_size*cell_size); - //intensity = Math::cos(d*Math_PI*0.5/r); + //intensity*=1.0-Math::abs(p_plane.distance_to(pos))/(plot_size*cell_size); + //intensity = Math::cos(d*Math_PI*0.5/r); + + baked_light_baker_add_64f(&octant.light_accum[i][0],p_light.r*intensity); + baked_light_baker_add_64f(&octant.light_accum[i][1],p_light.g*intensity); + baked_light_baker_add_64f(&octant.light_accum[i][2],p_light.b*intensity); + - octant.light[p_light_index].accum[i][0]+=p_light.r*intensity; - octant.light[p_light_index].accum[i][1]+=p_light.g*intensity; - octant.light[p_light_index].accum[i][2]+=p_light.b*intensity; + } } } @@ -893,11 +949,11 @@ void BakedLightBaker::_plot_light(int p_light_index, const Vector3& p_plot_pos, } -float BakedLightBaker::_throw_ray(int p_light_index,const Vector3& p_begin, const Vector3& p_end,float p_rest,const Color& p_light,float *p_att_curve,float p_att_pos,int p_att_curve_len,int p_bounces,bool p_first_bounce,bool p_only_dist) { +float BakedLightBaker::_throw_ray(ThreadStack& thread_stack,bool p_bake_direct,const Vector3& p_begin, const Vector3& p_end,float p_rest,const Color& p_light,float *p_att_curve,float p_att_pos,int p_att_curve_len,int p_bounces,bool p_first_bounce,bool p_only_dist) { - uint32_t* stack = ray_stack; - BVH **bstack = bvh_stack; + uint32_t* stack = thread_stack.ray_stack; + BVH **bstack = thread_stack.bvh_stack; enum { TEST_AABB_BIT=0, @@ -915,6 +971,7 @@ float BakedLightBaker::_throw_ray(int p_light_index,const Vector3& p_begin, cons n/=len; + real_t d=1e10; bool inters=false; Vector3 r_normal; @@ -1139,7 +1196,7 @@ float BakedLightBaker::_throw_ray(int p_light_index,const Vector3& p_begin, cons #endif - ret=_throw_ray(p_light_index,r_point,r_point+rn*p_rest,p_rest,diffuse_at_point,p_att_curve,p_att_pos,p_att_curve_len,p_bounces-1); + ret=_throw_ray(thread_stack,p_bake_direct,r_point,r_point+rn*p_rest,p_rest,diffuse_at_point,p_att_curve,p_att_pos,p_att_curve_len,p_bounces-1); } if (use_specular && (specular_at_point.r>CMP_EPSILON || specular_at_point.g>CMP_EPSILON || specular_at_point.b>CMP_EPSILON)) { @@ -1150,7 +1207,7 @@ float BakedLightBaker::_throw_ray(int p_light_index,const Vector3& p_begin, cons Vector3 rn = n - r_normal *r_normal.dot(n) * 2.0; - _throw_ray(p_light_index,r_point,r_point+rn*p_rest,p_rest,specular_at_point,p_att_curve,p_att_pos,p_att_curve_len,p_bounces-1); + _throw_ray(thread_stack,p_bake_direct,r_point,r_point+rn*p_rest,p_rest,specular_at_point,p_att_curve,p_att_pos,p_att_curve_len,p_bounces-1); } } @@ -1158,19 +1215,25 @@ float BakedLightBaker::_throw_ray(int p_light_index,const Vector3& p_begin, cons // _plot_light_point(r_point,octree,octree_aabb,p_light); - Color plot_light=diffuse_at_point; + Color plot_light=res_light.linear_interpolate(diffuse_at_point,tint); plot_light.r*=att; plot_light.g*=att; plot_light.b*=att; + Color tint_light=diffuse_at_point; + tint_light.r*=att; + tint_light.g*=att; + tint_light.b*=att; + + bool skip=false; - if (!p_first_bounce) { + if (!p_first_bounce || p_bake_direct) { float r = plot_size * cell_size*2; if (dist<r) { //avoid accumulaiton of light on corners //plot_light=plot_light.linear_interpolate(Color(0,0,0,0),1.0-sd/plot_size*plot_size); - plot_light=Color(0,0,0,0); + skip=true; } else { @@ -1181,12 +1244,12 @@ float BakedLightBaker::_throw_ray(int p_light_index,const Vector3& p_begin, cons double r2 = double(rand())/RAND_MAX; double r3 = double(rand())/RAND_MAX; Vector3 rn = ((c1*(r1-0.5)) + (c2*(r2-0.5)) + (r_normal*r3*0.25)).normalized(); - float d =_throw_ray(p_light_index,r_point,r_point+rn*p_rest,p_rest,diffuse_at_point,p_att_curve,p_att_pos,p_att_curve_len,p_bounces-1,false,true); - r = plot_size*cell_size*0.7; + float d =_throw_ray(thread_stack,p_bake_direct,r_point,r_point+rn*p_rest,p_rest,diffuse_at_point,p_att_curve,p_att_pos,p_att_curve_len,p_bounces-1,false,true); + r = plot_size*cell_size*ao_radius; if (d>0 && d<r) { //avoid accumulaiton of light on corners //plot_light=plot_light.linear_interpolate(Color(0,0,0,0),1.0-sd/plot_size*plot_size); - plot_light=Color(0,0,0,0); + skip=true; } else { //plot_light=Color(0,0,0,0); @@ -1195,11 +1258,9 @@ float BakedLightBaker::_throw_ray(int p_light_index,const Vector3& p_begin, cons } - if (!p_first_bounce || lights[p_light_index].bake_direct) { - Plane plane(r_point,r_normal); - //print_line(String(plot_light)+String(" ")+rtos(att)); - _plot_light(p_light_index,r_point,aabb,plot_light,plane); - } + Plane plane(r_point,r_normal); + if (!skip) + _plot_light(thread_stack,r_point,aabb,plot_light,tint_light,!(!p_first_bounce || p_bake_direct),plane); return dist; @@ -1305,79 +1366,100 @@ void BakedLightBaker::_make_octree_texture() { //ok let's try to just create a texture - { + int otex_w=256; - int otex_w=(1<<lattice_size)*(1<<lattice_size)*2; //make sure lattice fits horizontally - Vector3 lattice_cell_size=octree_aabb.size; - for(int i=0;i<lattice_size;i++) { + while (true) { - lattice_cell_size*=0.5; - } + uint32_t oct_idx=leaf_list; - while(true) { + int row=0; - //let's plot the leafs first, given the octree is not so obvious which size it will have - int row=4+4*(1<<lattice_size); + print_line("begin at row "+itos(row)); + int longest_line_reused=0; + int col=0; + int processed=0; + + //reset + while(oct_idx) { - uint32_t oct_idx=leaf_list; + BakedLightBaker::Octant *oct = &octants[oct_idx]; + oct->texture_x=0; + oct->texture_y=0; + oct_idx=oct->next_leaf; - //untag - while(oct_idx) { + } - BakedLightBaker::Octant *oct = &octants[oct_idx]; - //0,0 also means unprocessed - oct->texture_x=0; - oct->texture_y=0; - oct_idx=oct->next_leaf; + oct_idx=leaf_list; + //assign + while(oct_idx) { + BakedLightBaker::Octant *oct = &octants[oct_idx]; + if (oct->first_neighbour && oct->texture_x==0 && oct->texture_y==0) { + //was not processed + uint32_t current_idx=oct_idx; + int reused=0; + + while(current_idx) { + BakedLightBaker::Octant *o = &octants[current_idx]; + if (col+1 >= otex_w) { + col=0; + row+=4; + } + o->texture_x=col; + o->texture_y=row; + processed++; + + if (o->bake_neighbour) { + reused++; + } + col+=o->bake_neighbour ? 1 : 2; //reuse neighbour + current_idx=o->bake_neighbour; + } + + if (reused>longest_line_reused) { + longest_line_reused=reused; + } } + oct_idx=oct->next_leaf; + } - oct_idx=leaf_list; + row+=4; + if (otex_w < row) { - print_line("begin at row "+itos(row)); - int longest_line_reused=0; - int col=0; - int processed=0; + otex_w*=2; + } else { + + baked_light_texture_w=otex_w; + baked_light_texture_h=nearest_power_of_2(row); + print_line("w: "+itos(otex_w)); + print_line("h: "+itos(row)); + break; + } - while(oct_idx) { - BakedLightBaker::Octant *oct = &octants[oct_idx]; - if (oct->first_neighbour && oct->texture_x==0 && oct->texture_y==0) { - //was not processed - uint32_t current_idx=oct_idx; - int reused=0; + } - while(current_idx) { - BakedLightBaker::Octant *o = &octants[current_idx]; - if (col+1 >= otex_w) { - col=0; - row+=4; - } - o->texture_x=col; - o->texture_y=row; - processed++; - if (o->bake_neighbour) { - reused++; - } - col+=o->bake_neighbour ? 1 : 2; //reuse neighbour - current_idx=o->bake_neighbour; - } + { - if (reused>longest_line_reused) { - longest_line_reused=reused; - } - } - oct_idx=oct->next_leaf; - } + otex_w=(1<<lattice_size)*(1<<lattice_size)*2; //make sure lattice fits horizontally + Vector3 lattice_cell_size=octree_aabb.size; + for(int i=0;i<lattice_size;i++) { + + lattice_cell_size*=0.5; + } - print_line("processed "+itos(processed)); - print_line("longest reused: "+itos(longest_line_reused)); + + while(true) { + + //let's plot the leafs first, given the octree is not so obvious which size it will have + int row=4+4*(1<<lattice_size); + int col=0; col=0; row+=4; @@ -1478,7 +1560,25 @@ double BakedLightBaker::get_normalization(int p_light_idx) const { return nrg; } -void BakedLightBaker::throw_rays(int p_amount) { + + +double BakedLightBaker::get_modifier(int p_light_idx) const { + + double nrg=0; + + const LightData &dl=lights[p_light_idx]; + double cell_area = cell_size*cell_size;; + //nrg+= /*dl.energy */ (dl.rays_thrown * cell_area / dl.area); + nrg=cell_area; + nrg*=(Math_PI*plot_size*plot_size)*0.5; // damping of radial linear gradient kernel + nrg*=dl.constant; + //nrg*=5; + + + return nrg; +} + +void BakedLightBaker::throw_rays(ThreadStack& thread_stack,int p_amount) { @@ -1488,6 +1588,8 @@ void BakedLightBaker::throw_rays(int p_amount) { int amount = p_amount * total_light_area / dl.area; + double mod = 1.0/double(get_modifier(i)); + mod*=p_amount/float(amount); switch(dl.type) { @@ -1502,12 +1604,15 @@ void BakedLightBaker::throw_rays(int p_amount) { from+=dl.left*(r2*2.0-1.0); Vector3 to = from+dl.dir*dl.length; Color col=dl.diffuse; - col.r*=dl.energy; - col.g*=dl.energy; - col.b*=dl.energy; + float m = mod*dl.energy; + col.r*=m; + col.g*=m; + col.b*=m; + dl.rays_thrown++; - total_rays++; - _throw_ray(i,from,to,dl.length,col,NULL,0,0,max_bounces,true); + baked_light_baker_add_64i(&total_rays,1); + + _throw_ray(thread_stack,dl.bake_direct,from,to,dl.length,col,NULL,0,0,max_bounces,true); } } break; case VS::LIGHT_OMNI: { @@ -1543,13 +1648,14 @@ void BakedLightBaker::throw_rays(int p_amount) { #endif Vector3 to = dl.pos+dir*dl.radius; Color col=dl.diffuse; - col.r*=dl.energy; - col.g*=dl.energy; - col.b*=dl.energy; + float m = mod*dl.energy; + col.r*=m; + col.g*=m; + col.b*=m; dl.rays_thrown++; - total_rays++; - _throw_ray(i,from,to,dl.radius,col,dl.attenuation_table.ptr(),0,dl.radius,max_bounces,true); + baked_light_baker_add_64i(&total_rays,1); + _throw_ray(thread_stack,dl.bake_direct,from,to,dl.radius,col,dl.attenuation_table.ptr(),0,dl.radius,max_bounces,true); // _throw_ray(i,from,to,dl.radius,col,NULL,0,dl.radius,max_bounces,true); } @@ -1574,13 +1680,14 @@ void BakedLightBaker::throw_rays(int p_amount) { Vector3 to = dl.pos+dir*dl.radius; Color col=dl.diffuse; - col.r*=dl.energy; - col.g*=dl.energy; - col.b*=dl.energy; + float m = mod*dl.energy; + col.r*=m; + col.g*=m; + col.b*=m; dl.rays_thrown++; - total_rays++; - _throw_ray(i,from,to,dl.radius,col,dl.attenuation_table.ptr(),0,dl.radius,max_bounces,true); + baked_light_baker_add_64i(&total_rays,1); + _throw_ray(thread_stack,dl.bake_direct,from,to,dl.radius,col,dl.attenuation_table.ptr(),0,dl.radius,max_bounces,true); // _throw_ray(i,from,to,dl.radius,col,NULL,0,dl.radius,max_bounces,true); } @@ -1622,6 +1729,10 @@ void BakedLightBaker::bake(const Ref<BakedLight> &p_light, Node* p_node) { edge_damp=baked_light->get_edge_damp(); normal_damp=baked_light->get_normal_damp(); octree_extra_margin=baked_light->get_cell_extra_margin(); + tint=baked_light->get_tint(); + ao_radius=baked_light->get_ao_radius(); + ao_strength=baked_light->get_ao_strength(); + linear_color=baked_light->get_bake_flag(BakedLight::BAKE_LINEAR_COLOR); baked_textures.clear(); for(int i=0;i<baked_light->get_lightmaps_count();i++) { @@ -1651,13 +1762,134 @@ void BakedLightBaker::bake(const Ref<BakedLight> &p_light, Node* p_node) { } -void BakedLightBaker::update_octree_image(DVector<uint8_t> &p_image) { +void BakedLightBaker::update_octree_sampler(DVector<int> &p_sampler) { + + BakedLightBaker::Octant *octants=octant_pool.ptr(); + double norm = 1.0/double(total_rays); + + + + if (p_sampler.size()==0 || first_bake_to_map) { + + Vector<int> tmp_smp; + tmp_smp.resize(32); //32 for header + + for(int i=0;i<32;i++) { + tmp_smp[i]=0; + } + + for(int i=octant_pool_size-1;i>=0;i--) { + + if (i==0) + tmp_smp[1]=tmp_smp.size(); + + Octant &octant=octants[i]; + octant.sampler_ofs = tmp_smp.size(); + int idxcol[2]={0,0}; + + int r = CLAMP((octant.full_accum[0]*norm)*2048,0,32767); + int g = CLAMP((octant.full_accum[1]*norm)*2048,0,32767); + int b = CLAMP((octant.full_accum[2]*norm)*2048,0,32767); + + idxcol[0]|=r; + idxcol[1]|=(g<<16)|b; + + if (octant.leaf) { + tmp_smp.push_back(idxcol[0]); + tmp_smp.push_back(idxcol[1]); + } else { + + for(int j=0;j<8;j++) { + if (octant.children[j]) { + idxcol[0]|=(1<<(j+16)); + } + } + tmp_smp.push_back(idxcol[0]); + tmp_smp.push_back(idxcol[1]); + for(int j=0;j<8;j++) { + if (octant.children[j]) { + tmp_smp.push_back(octants[octant.children[j]].sampler_ofs); + if (octants[octant.children[j]].sampler_ofs==0) { + print_line("FUUUUUUUUCK"); + } + } + } + } + + } + + p_sampler.resize(tmp_smp.size()); + DVector<int>::Write w = p_sampler.write(); + int ss = tmp_smp.size(); + for(int i=0;i<ss;i++) { + w[i]=tmp_smp[i]; + } + + first_bake_to_map=false; + + } + + double gamma = baked_light->get_gamma_adjust(); + double mult = baked_light->get_energy_multiplier(); + float saturation = baked_light->get_saturation(); + + DVector<int>::Write w = p_sampler.write(); + + encode_uint32(octree_depth,(uint8_t*)&w[2]); + encode_uint32(linear_color,(uint8_t*)&w[3]); + + encode_float(octree_aabb.pos.x,(uint8_t*)&w[4]); + encode_float(octree_aabb.pos.y,(uint8_t*)&w[5]); + encode_float(octree_aabb.pos.z,(uint8_t*)&w[6]); + encode_float(octree_aabb.size.x,(uint8_t*)&w[7]); + encode_float(octree_aabb.size.y,(uint8_t*)&w[8]); + encode_float(octree_aabb.size.z,(uint8_t*)&w[9]); + + //norm*=multiplier; + + for(int i=octant_pool_size-1;i>=0;i--) { + + Octant &octant=octants[i]; + int idxcol[2]={w[octant.sampler_ofs],w[octant.sampler_ofs+1]}; + + double rf=pow(octant.full_accum[0]*norm*mult,gamma); + double gf=pow(octant.full_accum[1]*norm*mult,gamma); + double bf=pow(octant.full_accum[2]*norm*mult,gamma); + + double gray = (rf+gf+bf)/3.0; + rf = gray + (rf-gray)*saturation; + gf = gray + (gf-gray)*saturation; + bf = gray + (bf-gray)*saturation; + + + int r = CLAMP((rf)*2048,0,32767); + int g = CLAMP((gf)*2048,0,32767); + int b = CLAMP((bf)*2048,0,32767); + + idxcol[0]=((idxcol[0]>>16)<<16)|r; + idxcol[1]=(g<<16)|b; + w[octant.sampler_ofs]=idxcol[0]; + w[octant.sampler_ofs+1]=idxcol[1]; + } + +} + +void BakedLightBaker::update_octree_images(DVector<uint8_t> &p_octree,DVector<uint8_t> &p_light) { int len = baked_octree_texture_w*baked_octree_texture_h*4; - p_image.resize(len); - DVector<uint8_t>::Write w = p_image.write(); + p_octree.resize(len); + + int ilen = baked_light_texture_w*baked_light_texture_h*4; + p_light.resize(ilen); + + + DVector<uint8_t>::Write w = p_octree.write(); zeromem(w.ptr(),len); + + DVector<uint8_t>::Write iw = p_light.write(); + zeromem(iw.ptr(),ilen); + float gamma = baked_light->get_gamma_adjust(); float mult = baked_light->get_energy_multiplier(); @@ -1668,6 +1900,13 @@ void BakedLightBaker::update_octree_image(DVector<uint8_t> &p_image) { w[i+3]=0xFF; } + for(int i=0;i<ilen;i+=4) { + iw[i+0]=0xFF; + iw[i+1]=0; + iw[i+2]=0xFF; + iw[i+3]=0xFF; + } + float multiplier=1.0; if (baked_light->get_format()==BakedLight::FORMAT_HDR8) @@ -1678,6 +1917,9 @@ void BakedLightBaker::update_octree_image(DVector<uint8_t> &p_image) { encode_float(1<<lattice_size,&w[12]); encode_uint32(octree_depth-lattice_size,&w[16]); encode_uint32(multiplier,&w[20]); + encode_uint16(baked_light_texture_w,&w[24]); //if present, use the baked light texture + encode_uint16(baked_light_texture_h,&w[26]); + encode_uint32(0,&w[28]); //baked light texture format encode_float(octree_aabb.pos.x,&w[32]); encode_float(octree_aabb.pos.y,&w[36]); @@ -1690,6 +1932,7 @@ void BakedLightBaker::update_octree_image(DVector<uint8_t> &p_image) { BakedLightBaker::Octant *octants=octant_pool.ptr(); int octant_count=octant_pool_size; uint8_t *ptr = w.ptr(); + uint8_t *lptr = iw.ptr(); int child_offsets[8]={ @@ -1703,7 +1946,18 @@ void BakedLightBaker::update_octree_image(DVector<uint8_t> &p_image) { baked_octree_texture_w*8+baked_octree_texture_w*4+4, }; - Vector<double> norm_arr; + int lchild_offsets[8]={ + 0, + 4, + baked_light_texture_w*4, + baked_light_texture_w*4+4, + baked_light_texture_w*8+0, + baked_light_texture_w*8+4, + baked_light_texture_w*8+baked_light_texture_w*4, + baked_light_texture_w*8+baked_light_texture_w*4+4, + }; + + /*Vector<double> norm_arr; norm_arr.resize(lights.size()); for(int i=0;i<lights.size();i++) { @@ -1711,39 +1965,43 @@ void BakedLightBaker::update_octree_image(DVector<uint8_t> &p_image) { } const double *normptr=norm_arr.ptr(); - +*/ + double norm = 1.0/double(total_rays); int lz=lights.size(); mult/=multiplier; + double saturation = baked_light->get_saturation(); for(int i=0;i<octant_count;i++) { Octant &oct=octants[i]; if (oct.texture_x==0 && oct.texture_y==0) continue; - int ofs = (oct.texture_y * baked_octree_texture_w + oct.texture_x)<<2; + if (oct.leaf) { + int ofs = (oct.texture_y * baked_light_texture_w + oct.texture_x)<<2; + ERR_CONTINUE(ofs<0 || ofs >ilen); //write colors for(int j=0;j<8;j++) { //if (!oct.children[j]) // continue; - uint8_t *iptr=&ptr[ofs+child_offsets[j]]; - float r=0; - float g=0; - float b=0; - - for(int k=0;k<lz;k++) { - r+=oct.light[k].accum[j][0]*normptr[k]; - g+=oct.light[k].accum[j][1]*normptr[k]; - b+=oct.light[k].accum[j][2]*normptr[k]; - } + uint8_t *iptr=&lptr[ofs+lchild_offsets[j]]; + + float r=oct.light_accum[j][0]*norm; + float g=oct.light_accum[j][1]*norm; + float b=oct.light_accum[j][2]*norm; r=pow(r*mult,gamma); g=pow(g*mult,gamma); b=pow(b*mult,gamma); + double gray = (r+g+b)/3.0; + r = gray + (r-gray)*saturation; + g = gray + (g-gray)*saturation; + b = gray + (b-gray)*saturation; + float ic[3]={ r, g, @@ -1757,6 +2015,8 @@ void BakedLightBaker::update_octree_image(DVector<uint8_t> &p_image) { } else { + int ofs = (oct.texture_y * baked_octree_texture_w + oct.texture_x)<<2; + ERR_CONTINUE(ofs<0 || ofs >len); //write indices for(int j=0;j<8;j++) { @@ -1822,49 +2082,61 @@ void BakedLightBaker::_bake_thread_func(void *arg) { BakedLightBaker *ble = (BakedLightBaker*)arg; - ble->rays_at_snap_time=ble->total_rays; - ble->snap_time=OS::get_singleton()->get_ticks_usec(); - while(!ble->bake_thread_exit) { - ble->throw_rays(1000); - uint64_t t=OS::get_singleton()->get_ticks_usec(); - if (t-ble->snap_time>1000000) { + ThreadStack thread_stack; - double time = (t-ble->snap_time)/1000000.0; + thread_stack.ray_stack = memnew_arr(uint32_t,ble->bvh_depth); + thread_stack.bvh_stack = memnew_arr(BVH*,ble->bvh_depth); + thread_stack.octant_stack = memnew_arr(uint32_t,ble->octree_depth*2 ); + thread_stack.octantptr_stack = memnew_arr(uint32_t,ble->octree_depth*2 ); - int rays=ble->total_rays-ble->rays_at_snap_time; - ble->rays_sec=int(rays/time); - ble->snap_time=OS::get_singleton()->get_ticks_usec(); - ble->rays_at_snap_time=ble->total_rays; - } + while(!ble->bake_thread_exit) { + + ble->throw_rays(thread_stack,1000); } + memdelete_arr(thread_stack.ray_stack ); + memdelete_arr(thread_stack.bvh_stack ); + memdelete_arr(thread_stack.octant_stack ); + memdelete_arr(thread_stack.octantptr_stack ); + } void BakedLightBaker::_start_thread() { - if (thread!=NULL) + if (threads.size()!=0) return; bake_thread_exit=false; - thread=Thread::create(_bake_thread_func,this); + int thread_count = EDITOR_DEF("light_baker/custom_bake_threads",0); + if (thread_count<=0 || thread_count>64) + thread_count=OS::get_singleton()->get_processor_count(); + + //thread_count=1; + threads.resize(thread_count); + for(int i=0;i<threads.size();i++) { + threads[i]=Thread::create(_bake_thread_func,this); + } } void BakedLightBaker::_stop_thread() { - if (thread==NULL) + if (threads.size()==0) return; bake_thread_exit=true; - Thread::wait_to_finish(thread); - thread=NULL; + for(int i=0;i<threads.size();i++) { + Thread::wait_to_finish(threads[i]); + } + threads.clear(); } void BakedLightBaker::_plot_pixel_to_lightmap(int x, int y, int width, int height, uint8_t *image, const Vector3& p_pos,const Vector3& p_normal,double *p_norm_ptr,float mult,float gamma) { uint8_t *ptr = &image[(y*width+x)*4]; - int lc = lights.size(); + //int lc = lights.size(); + double norm = 1.0/double(total_rays); Color color; @@ -1888,11 +2160,9 @@ void BakedLightBaker::_plot_pixel_to_lightmap(int x, int y, int width, int heigh for(int i=0;i<8;i++) { - for(int j=0;j<lc;j++) { - cols[i].x+=octant.light[j].accum[i][0]*p_norm_ptr[j]; - cols[i].y+=octant.light[j].accum[i][1]*p_norm_ptr[j]; - cols[i].z+=octant.light[j].accum[i][2]*p_norm_ptr[j]; - } + cols[i].x+=octant.light_accum[i][0]*norm; + cols[i].y+=octant.light_accum[i][1]*norm; + cols[i].z+=octant.light_accum[i][2]*norm; } @@ -2355,12 +2625,13 @@ void BakedLightBaker::clear() { memdelete_arr(octantptr_stack); if (bvh_stack) memdelete_arr(bvh_stack); - +/* + * ??? for(int i=0;i<octant_pool.size();i++) { - if (octant_pool[i].leaf) { - memdelete_arr( octant_pool[i].light ); - } Vector<double> norm_arr; - norm_arr.resize(lights.size()); + //if (octant_pool[i].leaf) { + // memdelete_arr( octant_pool[i].light ); + //} Vector<double> norm_arr; + //norm_arr.resize(lights.size()); for(int i=0;i<lights.size();i++) { norm_arr[i] = 1.0/get_normalization(i); @@ -2368,6 +2639,7 @@ void BakedLightBaker::clear() { const double *normptr=norm_arr.ptr(); } +*/ octant_pool.clear(); octant_pool_size=0; bvh=NULL; @@ -2388,8 +2660,9 @@ void BakedLightBaker::clear() { baked_octree_texture_h=0; paused=false; baking=false; - thread=NULL; + bake_thread_exit=false; + first_bake_to_map=true; baked_light=Ref<BakedLight>(); total_rays=0; @@ -2414,12 +2687,11 @@ BakedLightBaker::BakedLightBaker() { baked_octree_texture_h=0; paused=false; baking=false; - thread=NULL; + bake_thread_exit=false; - rays_at_snap_time=0; - snap_time=0; - rays_sec=0; total_rays=0; + first_bake_to_map=true; + linear_color=false; } diff --git a/tools/editor/plugins/baked_light_baker.h b/tools/editor/plugins/baked_light_baker.h index e0a9d91cd4..8fbeeddc6a 100644 --- a/tools/editor/plugins/baked_light_baker.h +++ b/tools/editor/plugins/baked_light_baker.h @@ -15,17 +15,19 @@ public: OCTANT_POOL_CHUNK=1000000 }; - struct OctantLight { + //struct OctantLight { - double accum[8][3]; - }; + // double accum[8][3]; + //}; struct Octant { bool leaf; AABB aabb; uint16_t texture_x; uint16_t texture_y; + int sampler_ofs; float normal_accum[8][3]; + double full_accum[3]; int parent; union { struct { @@ -33,7 +35,7 @@ public: float offset[3]; int bake_neighbour; bool first_neighbour; - OctantLight *light; + double light_accum[8][3]; }; int children[8]; }; @@ -234,32 +236,49 @@ public: Transform base_inv; int leaf_list; int octree_depth; + int bvh_depth; int cell_count; uint32_t *ray_stack; + BVH **bvh_stack; uint32_t *octant_stack; uint32_t *octantptr_stack; + + struct ThreadStack { + uint32_t *octant_stack; + uint32_t *octantptr_stack; + uint32_t *ray_stack; + BVH **bvh_stack; + }; + Map<Vector3,Vector3> endpoint_normal; Map<Vector3,uint64_t> endpoint_normal_bits; - BVH **bvh_stack; + float cell_size; float plot_size; //multiplied by cell size float octree_extra_margin; int max_bounces; - uint64_t total_rays; + int64_t total_rays; bool use_diffuse; bool use_specular; bool use_translucency; + bool linear_color; int baked_octree_texture_w; int baked_octree_texture_h; + int baked_light_texture_w; + int baked_light_texture_h; int lattice_size; float edge_damp; float normal_damp; + float tint; + float ao_radius; + float ao_strength; bool paused; bool baking; + bool first_bake_to_map; Map<Ref<Material>,MeshMaterial*> mat_map; Map<Ref<Texture>,MeshTexture*> tex_map; @@ -285,19 +304,16 @@ public: //void _plot_light(const Vector3& p_plot_pos,const AABB& p_plot_aabb,const Color& p_light,int p_octant=0); - void _plot_light(int p_light_index,const Vector3& p_plot_pos,const AABB& p_plot_aabb,const Color& p_light,const Plane& p_plane); + void _plot_light(ThreadStack& thread_stack,const Vector3& p_plot_pos,const AABB& p_plot_aabb,const Color& p_light,const Color& p_tint_light,bool p_only_full,const Plane& p_plane); //void _plot_light_point(const Vector3& p_plot_pos, Octant *p_octant, const AABB& p_aabb,const Color& p_light); - float _throw_ray(int p_light_index,const Vector3& p_begin, const Vector3& p_end,float p_rest,const Color& p_light,float *p_att_curve,float p_att_pos,int p_att_curve_len,int p_bounces,bool p_first_bounce=false,bool p_only_dist=false); + float _throw_ray(ThreadStack& thread_stack,bool p_bake_direct,const Vector3& p_begin, const Vector3& p_end,float p_rest,const Color& p_light,float *p_att_curve,float p_att_pos,int p_att_curve_len,int p_bounces,bool p_first_bounce=false,bool p_only_dist=false); float total_light_area; - uint64_t rays_at_snap_time; - uint64_t snap_time; - int rays_sec; + Vector<Thread*> threads; - Thread *thread; bool bake_thread_exit; static void _bake_thread_func(void *arg); @@ -306,18 +322,20 @@ public: public: - void throw_rays(int p_amount); + void throw_rays(ThreadStack &thread_stack, int p_amount); double get_normalization(int p_light_idx) const; + double get_modifier(int p_light_idx) const; void bake(const Ref<BakedLight>& p_light,Node *p_base); bool is_baking(); void set_pause(bool p_pause); bool is_paused(); - int get_rays_sec() { return rays_sec; } + uint64_t get_rays_thrown() { return total_rays; } Error transfer_to_lightmaps(); - void update_octree_image(DVector<uint8_t> &p_image); + void update_octree_sampler(DVector<int> &p_sampler); + void update_octree_images(DVector<uint8_t> &p_octree,DVector<uint8_t> &p_light); Ref<BakedLight> get_baked_light() { return baked_light; } diff --git a/tools/editor/plugins/baked_light_baker_cmpxchg.cpp b/tools/editor/plugins/baked_light_baker_cmpxchg.cpp new file mode 100644 index 0000000000..42d3fc5276 --- /dev/null +++ b/tools/editor/plugins/baked_light_baker_cmpxchg.cpp @@ -0,0 +1,85 @@ + +#include "typedefs.h" + + +#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) > 40100 + +void baked_light_baker_add_64f(double *dst,double value) { + + + union { + int64_t i; + double f; + } swapy; + + + while(true) { + swapy.f=*dst; + int64_t from = swapy.i; + swapy.f+=value; + int64_t to=swapy.i; + if (__sync_bool_compare_and_swap((int64_t*)dst,from,to)) + break; + } +} + +void baked_light_baker_add_64i(int64_t *dst,int64_t value) { + + while(!__sync_bool_compare_and_swap(dst,*dst,(*dst)+value)) {} + +} + +#elif defined(WINDOWS_ENABLED) + +#include "windows.h" + +void baked_light_baker_add_64f(double *dst,double value) { + + union { + int64_t i; + double f; + } swapy; + + + while(true) { + swapy.f=*dst; + int64_t from = swapy.i; + swapy.f+=value; + int64_t to=swapy.i; + int64_t result = InterlockedCompareExchange64((int64_t*)dst,to,from); + if (result==from) + break; + } + +} + +void baked_light_baker_add_64i(int64_t *dst,int64_t value) { + + while(true) { + int64_t from = *dst; + int64_t to = from+value; + int64_t result = InterlockedCompareExchange64(dst,to,from); + if (result==from) + break; + } +} + + +#else + +//in goder (the god of programmers) we trust +#warning seems this platform or compiler does not support safe cmpxchg, your baked lighting may be funny + +void baked_light_baker_add_64f(double *dst,double value) { + + *dst+=value; + +} + +void baked_light_baker_add_64i(int64_t *dst,int64_t value) { + + *dst+=value; + +} + +#endif diff --git a/tools/editor/plugins/baked_light_editor_plugin.cpp b/tools/editor/plugins/baked_light_editor_plugin.cpp index 3d48f2e732..0f02899dc2 100644 --- a/tools/editor/plugins/baked_light_editor_plugin.cpp +++ b/tools/editor/plugins/baked_light_editor_plugin.cpp @@ -34,7 +34,7 @@ void BakedLightEditor::_node_removed(Node *p_node) { void BakedLightEditor::_notification(int p_option) { - if (p_option==NOTIFICATION_ENTER_SCENE) { + if (p_option==NOTIFICATION_ENTER_TREE) { button_bake->set_icon(get_icon("Bake","EditorIcons")); button_reset->set_icon(get_icon("Reload","EditorIcons")); @@ -111,7 +111,10 @@ void BakedLightEditor::_notification(int p_option) { #endif ERR_FAIL_COND(node->get_baked_light().is_null()); - baker->update_octree_image(octree_texture); + baker->update_octree_images(octree_texture,light_texture); + baker->update_octree_sampler(octree_sampler); + // print_line("sampler size: "+itos(octree_sampler.size()*4)); + #if 1 //debug Image img(baker->baked_octree_texture_w,baker->baked_octree_texture_h,0,Image::FORMAT_RGBA,octree_texture); @@ -121,11 +124,19 @@ void BakedLightEditor::_notification(int p_option) { #endif - bake_info->set_text("rays/s: "+itos(baker->get_rays_sec())); + + + uint64_t rays_snap = baker->get_rays_thrown(); + int rays_sec = (rays_snap-last_rays_time)*1.0-(update_timeout); + last_rays_time=rays_snap; + + bake_info->set_text("rays/s: "+itos(rays_sec)); update_timeout=1; print_line("MSUPDATE: "+itos(OS::get_singleton()->get_ticks_msec()-t)); t=OS::get_singleton()->get_ticks_msec(); node->get_baked_light()->set_octree(octree_texture); + node->get_baked_light()->set_light(light_texture); + node->get_baked_light()->set_sampler_octree(octree_sampler); node->get_baked_light()->set_edited(true); print_line("MSSET: "+itos(OS::get_singleton()->get_ticks_msec()-t)); @@ -195,6 +206,9 @@ void BakedLightEditor::_bake_pressed() { baker->bake(node->get_baked_light(),node); node->get_baked_light()->set_mode(BakedLight::MODE_OCTREE); update_timeout=0; + + last_rays_time=0; + set_process(true); } diff --git a/tools/editor/plugins/baked_light_editor_plugin.h b/tools/editor/plugins/baked_light_editor_plugin.h index 7912bd92e5..27ab88d70b 100644 --- a/tools/editor/plugins/baked_light_editor_plugin.h +++ b/tools/editor/plugins/baked_light_editor_plugin.h @@ -23,6 +23,8 @@ class BakedLightEditor : public Control { float update_timeout; DVector<uint8_t> octree_texture; + DVector<uint8_t> light_texture; + DVector<int> octree_sampler; BakedLightBaker *baker; AcceptDialog *err_dialog; @@ -33,6 +35,9 @@ class BakedLightEditor : public Control { Button *button_make_lightmaps; Label *bake_info; + uint64_t last_rays_time; + + BakedLightInstance *node; diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index e2944af422..32d5641e68 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -36,6 +36,110 @@ #include "globals.h" #include "os/input.h" #include "tools/editor/editor_settings.h" +#include "scene/gui/grid_container.h" + +class SnapDialog : public ConfirmationDialog { + + OBJ_TYPE(SnapDialog,ConfirmationDialog); + +protected: + friend class CanvasItemEditor; + SpinBox *grid_offset_x; + SpinBox *grid_offset_y; + SpinBox *grid_step_x; + SpinBox *grid_step_y; + SpinBox *rotation_offset; + SpinBox *rotation_step; + +public: + SnapDialog() : ConfirmationDialog() { + const int SPIN_BOX_GRID_RANGE = 256; + const int SPIN_BOX_ROTATION_RANGE = 360; + Label *label; + VBoxContainer *container; + GridContainer *child_container; + + set_title("Configure Snap"); + get_ok()->set_text("Close"); + container = memnew(VBoxContainer); + add_child(container); + + child_container = memnew(GridContainer); + child_container->set_columns(3); + container->add_child(child_container); + + label = memnew(Label); + label->set_text("Grid Offset:"); + child_container->add_child(label); + grid_offset_x=memnew(SpinBox); + grid_offset_x->set_min(-SPIN_BOX_GRID_RANGE); + grid_offset_x->set_max(SPIN_BOX_GRID_RANGE); + grid_offset_x->set_suffix("px"); + child_container->add_child(grid_offset_x); + grid_offset_y=memnew(SpinBox); + grid_offset_y->set_min(-SPIN_BOX_GRID_RANGE); + grid_offset_y->set_max(SPIN_BOX_GRID_RANGE); + grid_offset_y->set_suffix("px"); + child_container->add_child(grid_offset_y); + + label = memnew(Label); + label->set_text("Grid Step:"); + child_container->add_child(label); + grid_step_x=memnew(SpinBox); + grid_step_x->set_min(-SPIN_BOX_GRID_RANGE); + grid_step_x->set_max(SPIN_BOX_GRID_RANGE); + grid_step_x->set_suffix("px"); + child_container->add_child(grid_step_x); + grid_step_y=memnew(SpinBox); + grid_step_y->set_min(-SPIN_BOX_GRID_RANGE); + grid_step_y->set_max(SPIN_BOX_GRID_RANGE); + grid_step_y->set_suffix("px"); + child_container->add_child(grid_step_y); + + container->add_child(memnew(HSeparator)); + + child_container = memnew(GridContainer); + child_container->set_columns(2); + container->add_child(child_container); + + label = memnew(Label); + label->set_text("Rotation Offset:"); + child_container->add_child(label); + rotation_offset=memnew(SpinBox); + rotation_offset->set_min(-SPIN_BOX_ROTATION_RANGE); + rotation_offset->set_max(SPIN_BOX_ROTATION_RANGE); + rotation_offset->set_suffix("deg"); + child_container->add_child(rotation_offset); + + label = memnew(Label); + label->set_text("Rotation Step:"); + child_container->add_child(label); + rotation_step=memnew(SpinBox); + rotation_step->set_min(-SPIN_BOX_ROTATION_RANGE); + rotation_step->set_max(SPIN_BOX_ROTATION_RANGE); + rotation_step->set_suffix("deg"); + child_container->add_child(rotation_step); + } + + void set_fields(const Point2 p_grid_offset, const Size2 p_grid_step, const float p_rotation_offset, const float p_rotation_step) { + grid_offset_x->set_val(p_grid_offset.x); + grid_offset_y->set_val(p_grid_offset.y); + grid_step_x->set_val(p_grid_step.x); + grid_step_y->set_val(p_grid_step.y); + rotation_offset->set_val(p_rotation_offset * (180 / Math_PI)); + rotation_step->set_val(p_rotation_step * (180 / Math_PI)); + } + + void get_fields(Point2 &p_grid_offset, Size2 &p_grid_step, float &p_rotation_offset, float &p_rotation_step) { + p_grid_offset.x = grid_offset_x->get_val(); + p_grid_offset.y = grid_offset_y->get_val(); + p_grid_step.x = grid_step_x->get_val(); + p_grid_step.y = grid_step_y->get_val(); + p_rotation_offset = rotation_offset->get_val() / (180 / Math_PI); + p_rotation_step = rotation_step->get_val() / (180 / Math_PI); + } +}; + void CanvasItemEditor::_unhandled_key_input(const InputEvent& p_ev) { if (!is_visible()) @@ -75,9 +179,24 @@ Object *CanvasItemEditor::_get_editor_data(Object *p_what) { return memnew( CanvasItemEditorSelectedItem ); } -bool CanvasItemEditor::is_snap_active() const { +inline float _snap_scalar(float p_offset, float p_step, bool p_snap_relative, float p_target, float p_start) { + float offset = p_snap_relative ? p_start : p_offset; + return p_step != 0 ? Math::stepify(p_target - offset, p_step) + offset : p_target; +} + +Vector2 CanvasItemEditor::snap_point(Vector2 p_target, Vector2 p_start) const { + if (snap_grid) { + p_target.x = _snap_scalar(snap_offset.x, snap_step.x, snap_relative, p_target.x, p_start.x); + p_target.y = _snap_scalar(snap_offset.y, snap_step.y, snap_relative, p_target.y, p_start.y); + } + if (snap_pixel) + p_target = p_target.snapped(Size2(1, 1)); - return edit_menu->get_popup()->is_item_checked(edit_menu->get_popup()->get_item_index(SNAP_USE)); + return p_target; +} + +float CanvasItemEditor::snap_angle(float p_target, float p_start) const { + return snap_rotation ? _snap_scalar(snap_rotation_offset, snap_rotation_step, snap_relative, p_target, p_start) : p_target; } Dictionary CanvasItemEditor::get_state() const { @@ -86,9 +205,15 @@ Dictionary CanvasItemEditor::get_state() const { state["zoom"]=zoom; state["ofs"]=Point2(h_scroll->get_val(),v_scroll->get_val()); // state["ofs"]=-transform.get_origin(); - state["use_snap"]=is_snap_active(); - state["snap"]=snap; - state["pixel_snap"]=pixel_snap; + state["snap_offset"]=snap_offset; + state["snap_step"]=snap_step; + state["snap_rotation_offset"]=snap_rotation_offset; + state["snap_rotation_step"]=snap_rotation_step; + state["snap_grid"]=snap_grid; + state["snap_show_grid"]=snap_show_grid; + state["snap_rotation"]=snap_rotation; + state["snap_relative"]=snap_relative; + state["snap_pixel"]=snap_pixel; return state; } void CanvasItemEditor::set_state(const Dictionary& p_state){ @@ -105,19 +230,50 @@ void CanvasItemEditor::set_state(const Dictionary& p_state){ v_scroll->set_val(ofs.y); } - if (state.has("use_snap")) { + if (state.has("snap_step")) { + snap_step=state["snap_step"]; + } + + if (state.has("snap_offset")) { + snap_offset=state["snap_offset"]; + } + + if (state.has("snap_rotation_step")) { + snap_rotation_step=state["snap_rotation_step"]; + } + + if (state.has("snap_rotation_offset")) { + snap_rotation_offset=state["snap_rotation_offset"]; + } + + if (state.has("snap_grid")) { + snap_grid=state["snap_grid"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE); - edit_menu->get_popup()->set_item_checked(idx,state["use_snap"]); + edit_menu->get_popup()->set_item_checked(idx,snap_grid); } - if (state.has("snap")) { - snap=state["snap"]; + if (state.has("snap_show_grid")) { + snap_show_grid=state["snap_show_grid"]; + int idx = edit_menu->get_popup()->get_item_index(SNAP_SHOW_GRID); + edit_menu->get_popup()->set_item_checked(idx,snap_show_grid); } - if (state.has("pixel_snap")) { - pixel_snap=state["pixel_snap"]; + if (state.has("snap_rotation")) { + snap_rotation=state["snap_rotation"]; + int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION); + edit_menu->get_popup()->set_item_checked(idx,snap_rotation); + } + + if (state.has("snap_relative")) { + snap_relative=state["snap_relative"]; + int idx = edit_menu->get_popup()->get_item_index(SNAP_RELATIVE); + edit_menu->get_popup()->set_item_checked(idx,snap_relative); + } + + if (state.has("snap_pixel")) { + snap_pixel=state["snap_pixel"]; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_PIXEL); - edit_menu->get_popup()->set_item_checked(idx,pixel_snap); + edit_menu->get_popup()->set_item_checked(idx,snap_pixel); } } @@ -286,9 +442,7 @@ void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (!se) @@ -300,7 +454,7 @@ void CanvasItemEditor::_key_move(const Vector2& p_dir, bool p_snap, KeyMoveMODE Vector2 drag = p_dir; if (p_snap) - drag*=snap; + drag*=snap_step; undo_redo->add_undo_method(canvas_item,"edit_set_state",canvas_item->edit_get_state()); @@ -347,9 +501,7 @@ Point2 CanvasItemEditor::_find_topleftmost_point() { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -377,9 +529,7 @@ int CanvasItemEditor::get_item_count() { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; ic++; @@ -398,9 +548,7 @@ CanvasItem *CanvasItemEditor::get_single_item() { for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; if (single_item) @@ -554,6 +702,11 @@ void CanvasItemEditor::_append_canvas_item(CanvasItem *c) { } +void CanvasItemEditor::_snap_changed() { + ((SnapDialog *)snap_dialog)->get_fields(snap_offset, snap_step, snap_rotation_offset, snap_rotation_step); + viewport->update(); +} + void CanvasItemEditor::_dialog_value_changed(double) { if (updating_value_dialog) @@ -561,11 +714,6 @@ void CanvasItemEditor::_dialog_value_changed(double) { switch(last_option) { - case SNAP_CONFIGURE: { - - snap=dialog_val->get_val(); - viewport->update(); - } break; case ZOOM_SET: { zoom=dialog_val->get_val()/100.0; @@ -661,9 +809,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); @@ -735,9 +881,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (!se) @@ -943,9 +1087,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (!se) @@ -1055,7 +1197,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { editor_selection->clear(); editor_selection->add_node(c); //reselect - if (get_scene()->is_editor_hint()) { + if (get_tree()->is_editor_hint()) { editor->call("edit_node",c); } @@ -1068,9 +1210,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (!se) @@ -1126,9 +1266,7 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (!se) @@ -1153,39 +1291,21 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { if (drag==DRAG_ROTATE) { Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin(); - - Matrix32 rot; - rot.elements[1] = (dfrom - center).normalized(); - rot.elements[0] = rot.elements[1].tangent(); - float ang = rot.xform_inv(dto-center).atan2(); - canvas_item->edit_rotate(ang); - display_rotate_to = dto; - display_rotate_from = center; + if (Node2D *node = canvas_item->cast_to<Node2D>()) { + Matrix32 rot; + rot.elements[1] = (dfrom - center).normalized(); + rot.elements[0] = rot.elements[1].tangent(); + node->set_rot(snap_angle(rot.xform_inv(dto-center).atan2(), node->get_rot())); + display_rotate_to = dto; + display_rotate_from = center; + viewport->update(); + } continue; } - if (pixel_snap || (is_snap_active() && snap>0)) { - - if (drag!=DRAG_ALL) { - dfrom=drag_point_from; - dto=snapify(dto); - } else { - - Vector2 newpos = drag_point_from + (dto-dfrom); - Vector2 disp; - if (!is_snap_active() || snap<1) { - - disp.x = Math::fposmod(newpos.x,1); - disp.y = Math::fposmod(newpos.y,1); - - } else { - disp.x = Math::fposmod(newpos.x,snap); - disp.y = Math::fposmod(newpos.y,snap); - } - dto-=disp; - } - } + dfrom = drag_point_from; + dto = snap_point(dto - (drag == DRAG_ALL ? drag_from - drag_point_from : Vector2(0, 0)), drag_point_from); Vector2 drag_vector = canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto) - @@ -1293,8 +1413,6 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { - - if (!dragging_bone) { local_rect.pos=begin; @@ -1477,32 +1595,32 @@ void CanvasItemEditor::_viewport_draw() { _update_scrollbars(); RID ci=viewport->get_canvas_item(); - if (snap>0 && is_snap_active() && true ) { - + if (snap_show_grid) { Size2 s = viewport->get_size(); - int last_cell; Matrix32 xform = transform.affine_inverse(); - for(int i=0;i<s.width;i++) { - int cell = Math::fast_ftoi(Math::floor(xform.xform(Vector2(i,0)).x/snap)); - if (i==0) + if (snap_step.x!=0) { + for(int i=0;i<s.width;i++) { + int cell = Math::fast_ftoi(Math::floor((xform.xform(Vector2(i,0)).x-snap_offset.x)/snap_step.x)); + if (i==0) + last_cell=cell; + if (last_cell!=cell) + viewport->draw_line(Point2(i,0),Point2(i,s.height),Color(0.3,0.7,1,0.3)); last_cell=cell; - if (last_cell!=cell) - viewport->draw_line(Point2(i,0),Point2(i,s.height),Color(0.3,0.7,1,0.3)); - last_cell=cell; + } } - for(int i=0;i<s.height;i++) { - - int cell = Math::fast_ftoi(Math::floor(xform.xform(Vector2(0,i)).y/snap)); - if (i==0) + if (snap_step.y!=0) { + for(int i=0;i<s.height;i++) { + int cell = Math::fast_ftoi(Math::floor((xform.xform(Vector2(0,i)).y-snap_offset.y)/snap_step.y)); + if (i==0) + last_cell=cell; + if (last_cell!=cell) + viewport->draw_line(Point2(0,i),Point2(s.width,i),Color(0.3,0.7,1,0.3)); last_cell=cell; - if (last_cell!=cell) - viewport->draw_line(Point2(0,i),Point2(s.width,i),Color(0.3,0.7,1,0.3)); - last_cell=cell; + } } - } if (viewport->has_focus()) { @@ -1530,9 +1648,7 @@ void CanvasItemEditor::_viewport_draw() { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); if (!se) @@ -1749,9 +1865,7 @@ void CanvasItemEditor::_notification(int p_what) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; CanvasItemEditorSelectedItem *se=editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item); @@ -1791,7 +1905,7 @@ void CanvasItemEditor::_notification(int p_what) { } } - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { select_sb->set_texture( get_icon("EditorRect2D","EditorIcons") ); for(int i=0;i<4;i++) { @@ -1814,7 +1928,7 @@ void CanvasItemEditor::_notification(int p_what) { if (p_what==NOTIFICATION_READY) { - get_scene()->connect("node_removed",this,"_node_removed"); + get_tree()->connect("node_removed",this,"_node_removed"); } if (p_what==NOTIFICATION_DRAW) { @@ -1996,59 +2110,40 @@ void CanvasItemEditor::_update_scroll(float) { } -Point2 CanvasItemEditor::snapify(const Point2& p_pos) const { - - bool active=is_snap_active(); - - Vector2 pos = p_pos; - - if (!active || snap<1) { - - if (pixel_snap) { - - pos.x=Math::stepify(pos.x,1); - pos.y=Math::stepify(pos.y,1); - } - - return pos; - } - - - pos.x=Math::stepify(pos.x,snap); - pos.y=Math::stepify(pos.y,snap); - return pos; - - -} - - void CanvasItemEditor::_popup_callback(int p_op) { last_option=MenuOption(p_op); switch(p_op) { case SNAP_USE: { - + snap_grid = !snap_grid; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE); - edit_menu->get_popup()->set_item_checked( idx,!edit_menu->get_popup()->is_item_checked(0)); + edit_menu->get_popup()->set_item_checked(idx,snap_grid); + } break; + case SNAP_SHOW_GRID: { + snap_show_grid = !snap_show_grid; + int idx = edit_menu->get_popup()->get_item_index(SNAP_SHOW_GRID); + edit_menu->get_popup()->set_item_checked(idx,snap_show_grid); viewport->update(); } break; + case SNAP_USE_ROTATION: { + snap_rotation = !snap_rotation; + int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_ROTATION); + edit_menu->get_popup()->set_item_checked(idx,snap_rotation); + } break; + case SNAP_RELATIVE: { + snap_relative = !snap_relative; + int idx = edit_menu->get_popup()->get_item_index(SNAP_RELATIVE); + edit_menu->get_popup()->set_item_checked(idx,snap_relative); + } break; case SNAP_USE_PIXEL: { - pixel_snap = ! pixel_snap; + snap_pixel = !snap_pixel; int idx = edit_menu->get_popup()->get_item_index(SNAP_USE_PIXEL); - edit_menu->get_popup()->set_item_checked(idx,pixel_snap); + edit_menu->get_popup()->set_item_checked(idx,snap_pixel); } break; case SNAP_CONFIGURE: { - updating_value_dialog=true; - - dialog_label->set_text("Snap (Pixels):"); - dialog_val->set_min(1); - dialog_val->set_step(1); - dialog_val->set_max(4096); - dialog_val->set_val(snap); - value_dialog->popup_centered(Size2(200,85)); - updating_value_dialog=false; - + ((SnapDialog *)snap_dialog)->set_fields(snap_offset, snap_step, snap_rotation_offset, snap_rotation_step); + snap_dialog->popup_centered(Size2(200,160)); } break; case ZOOM_IN: { zoom=zoom*(1.0/0.5); @@ -2092,9 +2187,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; canvas_item->set_meta("_edit_lock_",true); @@ -2109,9 +2202,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -2129,9 +2220,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; canvas_item->set_meta("_edit_group_",true); @@ -2146,9 +2235,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; canvas_item->set_meta("_edit_group_",Variant()); @@ -2166,9 +2253,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -2236,9 +2321,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; if (canvas_item->cast_to<Node2D>()) { @@ -2307,7 +2390,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { } break; case ANIM_INSERT_ROT: { - key_pos = key_rot_button->is_pressed(); + key_rot = key_rot_button->is_pressed(); } break; case ANIM_INSERT_SCALE: { @@ -2348,9 +2431,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -2400,9 +2481,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(Map<Node*,Object*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; if (canvas_item->cast_to<Node2D>()) { @@ -2528,9 +2607,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { for(List<Node*>::Element *E=selection.front();E;E=E->next()) { CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>(); - if (!canvas_item) - continue; - if (!canvas_item->is_visible()) + if (!canvas_item || !canvas_item->is_visible()) continue; @@ -2604,6 +2681,7 @@ void CanvasItemEditor::_bind_methods() { ObjectTypeDB::bind_method("_unhandled_key_input",&CanvasItemEditor::_unhandled_key_input); ObjectTypeDB::bind_method("_viewport_draw",&CanvasItemEditor::_viewport_draw); ObjectTypeDB::bind_method("_viewport_input_event",&CanvasItemEditor::_viewport_input_event); + ObjectTypeDB::bind_method("_snap_changed",&CanvasItemEditor::_snap_changed); ADD_SIGNAL( MethodInfo("item_lock_status_changed") ); ADD_SIGNAL( MethodInfo("item_group_status_changed") ); @@ -2683,6 +2761,16 @@ void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) { hb->add_child(p_control); } +HSplitContainer *CanvasItemEditor::get_palette_split() { + + return palette_split; +} + +VSplitContainer *CanvasItemEditor::get_bottom_split() { + + return bottom_split; +} + CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { tool = TOOL_SELECT; @@ -2697,15 +2785,24 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { add_child( hb ); hb->set_area_as_parent_rect(); + bottom_split = memnew( VSplitContainer ); + bottom_split->set_v_size_flags(SIZE_EXPAND_FILL); + add_child(bottom_split); + + palette_split = memnew( HSplitContainer); + palette_split->set_v_size_flags(SIZE_EXPAND_FILL); + bottom_split->add_child(palette_split); + Control *vp_base = memnew (Control); - add_child(vp_base); vp_base->set_v_size_flags(SIZE_EXPAND_FILL); + palette_split->add_child(vp_base); Control *vp = memnew (Control); vp_base->add_child(vp); vp->set_area_as_parent_rect(); vp->add_child(p_editor->get_scene_root()); + viewport = memnew( Control ); vp_base->add_child(viewport); viewport->set_area_as_parent_rect(); @@ -2790,6 +2887,9 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { PopupMenu *p; p = edit_menu->get_popup(); p->add_check_item("Use Snap",SNAP_USE); + p->add_check_item("Show Grid",SNAP_SHOW_GRID); + p->add_check_item("Use Rotation Snap",SNAP_USE_ROTATION); + p->add_check_item("Snap Relative",SNAP_RELATIVE); p->add_item("Configure Snap..",SNAP_CONFIGURE); p->add_separator(); p->add_check_item("Use Pixel Snap",SNAP_USE_PIXEL); @@ -2878,7 +2978,11 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_separator(); p->add_item("Copy Pose",ANIM_COPY_POSE); p->add_item("Paste Pose",ANIM_PASTE_POSE); - p->add_item("Clear Pose",ANIM_CLEAR_POSE,KEY_MASK_ALT|KEY_K); + p->add_item("Clear Pose",ANIM_CLEAR_POSE,KEY_MASK_SHIFT|KEY_K); + + snap_dialog = memnew(SnapDialog); + snap_dialog->connect("confirmed",this,"_snap_changed"); + add_child(snap_dialog); value_dialog = memnew( AcceptDialog ); value_dialog->set_title("Set a Value"); @@ -2904,7 +3008,14 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { key_scale=false; zoom=1; - snap=10; + snap_offset=Vector2(0, 0); + snap_step=Vector2(10, 10); + snap_rotation_offset=0; + snap_rotation_step=15 / (180 / Math_PI); + snap_grid=false; + snap_show_grid=false; + snap_rotation=false; + snap_pixel=false; updating_value_dialog=false; box_selecting=false; //zoom=0.5; @@ -2912,7 +3023,6 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { editor->get_animation_editor()->connect("keying_changed",this,"_keying_changed"); set_process_unhandled_key_input(true); can_move_pivot=false; - pixel_snap=false; drag=DRAG_NONE; } diff --git a/tools/editor/plugins/canvas_item_editor_plugin.h b/tools/editor/plugins/canvas_item_editor_plugin.h index 15ac7b1bb3..f25296abdc 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.h +++ b/tools/editor/plugins/canvas_item_editor_plugin.h @@ -75,6 +75,9 @@ class CanvasItemEditor : public VBoxContainer { enum MenuOption { SNAP_USE, + SNAP_SHOW_GRID, + SNAP_USE_ROTATION, + SNAP_RELATIVE, SNAP_CONFIGURE, SNAP_USE_PIXEL, ZOOM_IN, @@ -143,8 +146,15 @@ class CanvasItemEditor : public VBoxContainer { Matrix32 transform; float zoom; - int snap; - bool pixel_snap; + Vector2 snap_offset; + Vector2 snap_step; + float snap_rotation_step; + float snap_rotation_offset; + bool snap_grid; + bool snap_show_grid; + bool snap_rotation; + bool snap_relative; + bool snap_pixel; bool box_selecting; Point2 box_selecting_to; bool key_pos; @@ -247,6 +257,8 @@ class CanvasItemEditor : public VBoxContainer { CanvasItem* _select_canvas_item_at_pos(const Point2 &p_pos,Node* p_node,const Matrix32& p_parent_xform,const Matrix32& p_canvas_xform); void _find_canvas_items_at_rect(const Rect2& p_rect,Node* p_node,const Matrix32& p_parent_xform,const Matrix32& p_canvas_xform,List<CanvasItem*> *r_items); + ConfirmationDialog *snap_dialog; + AcceptDialog *value_dialog; Label *dialog_label; SpinBox *dialog_val; @@ -261,7 +273,6 @@ class CanvasItemEditor : public VBoxContainer { DragType _find_drag_type(const Matrix32& p_xform, const Rect2& p_local_rect, const Point2& p_click, Vector2& r_point); - Point2 snapify(const Point2& p_pos) const; void _popup_callback(int p_op); bool updating_scroll; void _update_scroll(float); @@ -271,6 +282,7 @@ class CanvasItemEditor : public VBoxContainer { void _append_canvas_item(CanvasItem *p_item); void _dialog_value_changed(double); + void _snap_changed(); UndoRedo *undo_redo; Point2 _find_topleftmost_point(); @@ -289,6 +301,10 @@ class CanvasItemEditor : public VBoxContainer { void _viewport_input_event(const InputEvent& p_event); void _viewport_draw(); + + HSplitContainer *palette_split; + VSplitContainer *bottom_split; + friend class CanvasItemEditorPlugin; protected: @@ -330,8 +346,8 @@ protected: static CanvasItemEditor *singleton; public: - bool is_snap_active() const; - int get_snap() const { return snap; } + Vector2 snap_point(Vector2 p_target, Vector2 p_start = Vector2(0, 0)) const; + float snap_angle(float p_target, float p_start = 0) const; Matrix32 get_canvas_transform() const { return transform; } @@ -341,6 +357,9 @@ public: void add_control_to_menu_panel(Control *p_control); + HSplitContainer *get_palette_split(); + VSplitContainer *get_bottom_split(); + Control *get_viewport_control() { return viewport; } diff --git a/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp index 080ed7d11c..a533c6aa1e 100644 --- a/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp +++ b/tools/editor/plugins/collision_polygon_2d_editor_plugin.cpp @@ -4,6 +4,7 @@ #include "os/file_access.h" #include "tools/editor/editor_settings.h" + void CollisionPolygon2DEditor::_notification(int p_what) { switch(p_what) { @@ -13,7 +14,7 @@ void CollisionPolygon2DEditor::_notification(int p_what) { button_create->set_icon( get_icon("Edit","EditorIcons")); button_edit->set_icon( get_icon("MovePoint","EditorIcons")); button_edit->set_pressed(true); - + get_tree()->connect("node_removed",this,"_node_removed"); } break; case NOTIFICATION_FIXED_PROCESS: { @@ -28,22 +29,12 @@ void CollisionPolygon2DEditor::_node_removed(Node *p_node) { if(p_node==node) { node=NULL; hide(); + canvas_item_editor->get_viewport_control()->update(); } } -Vector2 CollisionPolygon2DEditor::snap_point(const Vector2& p_point) const { - - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } -} - void CollisionPolygon2DEditor::_menu_option(int p_option) { switch(p_option) { @@ -83,6 +74,9 @@ void CollisionPolygon2DEditor::_wip_close() { bool CollisionPolygon2DEditor::forward_input_event(const InputEvent& p_event) { + if (!node) + return false; + switch(p_event.type) { case InputEvent::MOUSE_BUTTON: { @@ -94,7 +88,7 @@ bool CollisionPolygon2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mb.x,mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); Vector<Vector2> poly = node->get_polygon(); @@ -297,7 +291,7 @@ bool CollisionPolygon2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mm.x,mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); @@ -364,6 +358,7 @@ void CollisionPolygon2DEditor::edit(Node *p_collision_polygon) { wip.clear(); wip_active=false; edited_point=-1; + canvas_item_editor->get_viewport_control()->update(); } else { node=NULL; @@ -379,6 +374,7 @@ void CollisionPolygon2DEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_menu_option"),&CollisionPolygon2DEditor::_menu_option); ObjectTypeDB::bind_method(_MD("_canvas_draw"),&CollisionPolygon2DEditor::_canvas_draw); + ObjectTypeDB::bind_method(_MD("_node_removed"),&CollisionPolygon2DEditor::_node_removed); } @@ -393,11 +389,13 @@ CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) { add_child(button_create); button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE)); button_create->set_toggle_mode(true); + button_create->set_tooltip("Create a new polygon from scratch"); button_edit = memnew( ToolButton ); add_child(button_edit); button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT)); button_edit->set_toggle_mode(true); + button_edit->set_tooltip("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point."); //add_constant_override("separation",0); diff --git a/tools/editor/plugins/collision_polygon_2d_editor_plugin.h b/tools/editor/plugins/collision_polygon_2d_editor_plugin.h index 052019b6c5..f34405b355 100644 --- a/tools/editor/plugins/collision_polygon_2d_editor_plugin.h +++ b/tools/editor/plugins/collision_polygon_2d_editor_plugin.h @@ -53,7 +53,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); void edit(Node *p_collision_polygon); CollisionPolygon2DEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.cpp b/tools/editor/plugins/collision_polygon_editor_plugin.cpp index 16b9622312..126328bac3 100644 --- a/tools/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/tools/editor/plugins/collision_polygon_editor_plugin.cpp @@ -31,6 +31,8 @@ #include "os/file_access.h" #include "tools/editor/editor_settings.h" #include "scene/3d/camera.h" +#include "canvas_item_editor_plugin.h" + void CollisionPolygonEditor::_notification(int p_what) { switch(p_what) { @@ -40,7 +42,7 @@ void CollisionPolygonEditor::_notification(int p_what) { button_create->set_icon( get_icon("Edit","EditorIcons")); button_edit->set_icon( get_icon("MovePoint","EditorIcons")); button_edit->set_pressed(true); - get_scene()->connect("node_removed",this,"_node_removed"); + get_tree()->connect("node_removed",this,"_node_removed"); } break; @@ -68,19 +70,6 @@ void CollisionPolygonEditor::_node_removed(Node *p_node) { } -Vector2 CollisionPolygonEditor::snap_point(const Vector2& p_point) const { - - return p_point; - /* - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } ??? */ -} - void CollisionPolygonEditor::_menu_option(int p_option) { switch(p_option) { @@ -120,6 +109,8 @@ void CollisionPolygonEditor::_wip_close() { bool CollisionPolygonEditor::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) { + if (!node) + return false; Transform gt = node->get_global_transform(); float depth = node->get_depth()*0.5; @@ -146,7 +137,7 @@ bool CollisionPolygonEditor::forward_spatial_input_event(Camera* p_camera,const Vector2 cpoint(spoint.x,spoint.y); - //cpoint=snap_point(cpoint); snap? + cpoint=CanvasItemEditor::get_singleton()->snap_point(cpoint); Vector<Vector2> poly = node->get_polygon(); @@ -360,7 +351,7 @@ bool CollisionPolygonEditor::forward_spatial_input_event(Camera* p_camera,const Vector2 cpoint(spoint.x,spoint.y); - //cpoint=snap_point(cpoint); + cpoint=CanvasItemEditor::get_singleton()->snap_point(cpoint); edited_point_pos = cpoint; _polygon_draw(); diff --git a/tools/editor/plugins/collision_polygon_editor_plugin.h b/tools/editor/plugins/collision_polygon_editor_plugin.h index 54b0706149..1c12ee0041 100644 --- a/tools/editor/plugins/collision_polygon_editor_plugin.h +++ b/tools/editor/plugins/collision_polygon_editor_plugin.h @@ -90,7 +90,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; virtual bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event); void edit(Node *p_collision_polygon); CollisionPolygonEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/item_list_editor_plugin.cpp b/tools/editor/plugins/item_list_editor_plugin.cpp index a059470cec..a8b34ef503 100644 --- a/tools/editor/plugins/item_list_editor_plugin.cpp +++ b/tools/editor/plugins/item_list_editor_plugin.cpp @@ -157,7 +157,7 @@ void ItemListEditor::_add_pressed() { void ItemListEditor::_notification(int p_notification) { - if (p_notification==NOTIFICATION_ENTER_SCENE) { + if (p_notification==NOTIFICATION_ENTER_TREE) { add_button->set_icon(get_icon("Add","EditorIcons")); del_button->set_icon(get_icon("Del","EditorIcons")); @@ -210,6 +210,7 @@ void ItemListEditor::_bind_methods() { } bool ItemListEditor::handles(Object *p_object) const { + return false; for(int i=0;i<item_plugins.size();i++) { if (item_plugins[i]->handles(p_object)) { return true; diff --git a/tools/editor/plugins/light_occluder_2d_editor_plugin.cpp b/tools/editor/plugins/light_occluder_2d_editor_plugin.cpp new file mode 100644 index 0000000000..bf882857d9 --- /dev/null +++ b/tools/editor/plugins/light_occluder_2d_editor_plugin.cpp @@ -0,0 +1,491 @@ +#include "light_occluder_2d_editor_plugin.h" + +#include "canvas_item_editor_plugin.h" +#include "os/file_access.h" +#include "tools/editor/editor_settings.h" + +void LightOccluder2DEditor::_notification(int p_what) { + + switch(p_what) { + + case NOTIFICATION_READY: { + + button_create->set_icon( get_icon("Edit","EditorIcons")); + button_edit->set_icon( get_icon("MovePoint","EditorIcons")); + button_edit->set_pressed(true); + get_tree()->connect("node_removed",this,"_node_removed"); + create_poly->connect("confirmed",this,"_create_poly"); + + } break; + case NOTIFICATION_FIXED_PROCESS: { + + + } break; + } + +} +void LightOccluder2DEditor::_node_removed(Node *p_node) { + + if(p_node==node) { + node=NULL; + hide(); + canvas_item_editor->get_viewport_control()->update(); + } + +} + + +void LightOccluder2DEditor::_menu_option(int p_option) { + + switch(p_option) { + + case MODE_CREATE: { + + mode=MODE_CREATE; + button_create->set_pressed(true); + button_edit->set_pressed(false); + } break; + case MODE_EDIT: { + + mode=MODE_EDIT; + button_create->set_pressed(false); + button_edit->set_pressed(true); + } break; + + } +} + +void LightOccluder2DEditor::_wip_close(bool p_closed) { + + undo_redo->create_action("Create Poly"); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_polygon",node->get_occluder_polygon()->get_polygon()); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_polygon",wip); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_closed",node->get_occluder_polygon()->is_closed()); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_closed",p_closed); + + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->commit_action(); + wip.clear(); + wip_active=false; + mode=MODE_EDIT; + button_edit->set_pressed(true); + button_create->set_pressed(false); + edited_point=-1; +} + +bool LightOccluder2DEditor::forward_input_event(const InputEvent& p_event) { + + + if (!node) + return false; + + if (node->get_occluder_polygon().is_null()) { + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + create_poly->set_text("No OccluderPolygon2D resource on this node.\nCreate and assign one?"); + create_poly->popup_centered_minsize(); + } + return (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1); + } + switch(p_event.type) { + + case InputEvent::MOUSE_BUTTON: { + + const InputEventMouseButton &mb=p_event.mouse_button; + + Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); + + + Vector2 gpoint = Point2(mb.x,mb.y); + Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); + cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = node->get_global_transform().affine_inverse().xform(cpoint); + + Vector<Vector2> poly = Variant(node->get_occluder_polygon()->get_polygon()); + + //first check if a point is to be added (segment split) + real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8); + + switch(mode) { + + + case MODE_CREATE: { + + if (mb.button_index==BUTTON_LEFT && mb.pressed) { + + + if (!wip_active) { + + wip.clear(); + wip.push_back( cpoint ); + wip_active=true; + edited_point_pos=cpoint; + canvas_item_editor->get_viewport_control()->update(); + edited_point=1; + return true; + } else { + + + if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_treshold) { + //wip closed + _wip_close(true); + + return true; + } else if (wip.size()>1 && xform.xform(wip[wip.size()-1]).distance_to(gpoint)<grab_treshold) { + //wip closed + _wip_close(false); + return true; + + } else { + + wip.push_back( cpoint ); + edited_point=wip.size(); + canvas_item_editor->get_viewport_control()->update(); + return true; + + //add wip point + } + } + } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) { + _wip_close(true); + } + + + + } break; + + case MODE_EDIT: { + + if (mb.button_index==BUTTON_LEFT) { + if (mb.pressed) { + + if (mb.mod.control) { + + + if (poly.size() < 3) { + + undo_redo->create_action("Edit Poly"); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); + poly.push_back(cpoint); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->commit_action(); + return true; + } + + //search edges + int closest_idx=-1; + Vector2 closest_pos; + real_t closest_dist=1e10; + for(int i=0;i<poly.size();i++) { + + Vector2 points[2] ={ xform.xform(poly[i]), + xform.xform(poly[(i+1)%poly.size()]) }; + + Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points); + if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2) + continue; //not valid to reuse point + + real_t d = cp.distance_to(gpoint); + if (d<closest_dist && d<grab_treshold) { + closest_dist=d; + closest_pos=cp; + closest_idx=i; + } + + + } + + if (closest_idx>=0) { + + pre_move_edit=poly; + poly.insert(closest_idx+1,xform.affine_inverse().xform(closest_pos)); + edited_point=closest_idx+1; + edited_point_pos=xform.affine_inverse().xform(closest_pos); + node->get_occluder_polygon()->set_polygon(Variant(poly)); + canvas_item_editor->get_viewport_control()->update(); + return true; + } + } else { + + //look for points to move + + int closest_idx=-1; + Vector2 closest_pos; + real_t closest_dist=1e10; + for(int i=0;i<poly.size();i++) { + + Vector2 cp =xform.xform(poly[i]); + + real_t d = cp.distance_to(gpoint); + if (d<closest_dist && d<grab_treshold) { + closest_dist=d; + closest_pos=cp; + closest_idx=i; + } + + } + + if (closest_idx>=0) { + + pre_move_edit=poly; + edited_point=closest_idx; + edited_point_pos=xform.affine_inverse().xform(closest_pos); + canvas_item_editor->get_viewport_control()->update(); + return true; + } + } + } else { + + if (edited_point!=-1) { + + //apply + + ERR_FAIL_INDEX_V(edited_point,poly.size(),false); + poly[edited_point]=edited_point_pos; + undo_redo->create_action("Edit Poly"); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_polygon",pre_move_edit); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->commit_action(); + + edited_point=-1; + return true; + } + } + } if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) { + + + + int closest_idx=-1; + Vector2 closest_pos; + real_t closest_dist=1e10; + for(int i=0;i<poly.size();i++) { + + Vector2 cp =xform.xform(poly[i]); + + real_t d = cp.distance_to(gpoint); + if (d<closest_dist && d<grab_treshold) { + closest_dist=d; + closest_pos=cp; + closest_idx=i; + } + + } + + if (closest_idx>=0) { + + + undo_redo->create_action("Edit Poly (Remove Point)"); + undo_redo->add_undo_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); + poly.remove(closest_idx); + undo_redo->add_do_method(node->get_occluder_polygon().ptr(),"set_polygon",poly); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->commit_action(); + return true; + } + + } + + + + } break; + } + + + + } break; + case InputEvent::MOUSE_MOTION: { + + const InputEventMouseMotion &mm=p_event.mouse_motion; + + if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) { + + Vector2 gpoint = Point2(mm.x,mm.y); + Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); + cpoint=canvas_item_editor->snap_point(cpoint); + edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); + + canvas_item_editor->get_viewport_control()->update(); + + } + + } break; + } + + return false; +} +void LightOccluder2DEditor::_canvas_draw() { + + if (!node || !node->get_occluder_polygon().is_valid()) + return; + + Control *vpc = canvas_item_editor->get_viewport_control(); + + Vector<Vector2> poly; + + if (wip_active) + poly=wip; + else + poly=Variant(node->get_occluder_polygon()->get_polygon()); + + + Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); + Ref<Texture> handle= get_icon("EditorHandle","EditorIcons"); + + int len = poly.size(); + + for(int i=0;i<poly.size();i++) { + + + Vector2 p,p2; + p = i==edited_point ? edited_point_pos : poly[i]; + if ((wip_active && i==poly.size()-1) || (((i+1)%poly.size())==edited_point)) + p2=edited_point_pos; + else + p2 = poly[(i+1)%poly.size()]; + + Vector2 point = xform.xform(p); + Vector2 next_point = xform.xform(p2); + + Color col=Color(1,0.3,0.1,0.8); + + if (i==poly.size()-1 && (!node->get_occluder_polygon()->is_closed() || wip_active)) { + + } else { + vpc->draw_line(point,next_point,col,2); + } + vpc->draw_texture(handle,point-handle->get_size()*0.5); + } +} + + + +void LightOccluder2DEditor::edit(Node *p_collision_polygon) { + + if (!canvas_item_editor) { + canvas_item_editor=CanvasItemEditor::get_singleton(); + } + + if (p_collision_polygon) { + + node=p_collision_polygon->cast_to<LightOccluder2D>(); + if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) + canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw"); + wip.clear(); + wip_active=false; + edited_point=-1; + canvas_item_editor->get_viewport_control()->update(); + } else { + node=NULL; + + if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw",this,"_canvas_draw"); + + } + +} + +void LightOccluder2DEditor::_create_poly() { + + if (!node) + return; + undo_redo->create_action("Create Occluder Polygon"); + undo_redo->add_do_method(node,"set_occluder_polygon",Ref<OccluderPolygon2D>(memnew( OccluderPolygon2D))); + undo_redo->add_undo_method(node,"set_occluder_polygon",Variant(REF())); + undo_redo->commit_action(); +} + +void LightOccluder2DEditor::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("_menu_option"),&LightOccluder2DEditor::_menu_option); + ObjectTypeDB::bind_method(_MD("_canvas_draw"),&LightOccluder2DEditor::_canvas_draw); + ObjectTypeDB::bind_method(_MD("_node_removed"),&LightOccluder2DEditor::_node_removed); + ObjectTypeDB::bind_method(_MD("_create_poly"),&LightOccluder2DEditor::_create_poly); + +} + + +LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) { + + canvas_item_editor=NULL; + editor=p_editor; + undo_redo = editor->get_undo_redo(); + + add_child( memnew( VSeparator )); + button_create = memnew( ToolButton ); + add_child(button_create); + button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE)); + button_create->set_toggle_mode(true); + button_create->set_tooltip("Create a new polygon from scratch"); + + button_edit = memnew( ToolButton ); + add_child(button_edit); + button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT)); + button_edit->set_toggle_mode(true); + button_edit->set_tooltip("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point."); + + create_poly = memnew( ConfirmationDialog ); + add_child(create_poly); + create_poly->get_ok()->set_text("Create"); + + + //add_constant_override("separation",0); + +#if 0 + options = memnew( MenuButton ); + add_child(options); + options->set_area_as_parent_rect(); + options->set_text("Polygon"); + //options->get_popup()->add_item("Parse BBCODE",PARSE_BBCODE); + options->get_popup()->connect("item_pressed", this,"_menu_option"); +#endif + + mode = MODE_EDIT; + wip_active=false; + +} + + +void LightOccluder2DEditorPlugin::edit(Object *p_object) { + + collision_polygon_editor->edit(p_object->cast_to<Node>()); +} + +bool LightOccluder2DEditorPlugin::handles(Object *p_object) const { + + return p_object->is_type("LightOccluder2D"); +} + +void LightOccluder2DEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + collision_polygon_editor->show(); + } else { + + collision_polygon_editor->hide(); + collision_polygon_editor->edit(NULL); + } + +} + +LightOccluder2DEditorPlugin::LightOccluder2DEditorPlugin(EditorNode *p_node) { + + editor=p_node; + collision_polygon_editor = memnew( LightOccluder2DEditor(p_node) ); + CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); + + collision_polygon_editor->hide(); + + + +} + + +LightOccluder2DEditorPlugin::~LightOccluder2DEditorPlugin() +{ +} + diff --git a/tools/editor/plugins/light_occluder_2d_editor_plugin.h b/tools/editor/plugins/light_occluder_2d_editor_plugin.h new file mode 100644 index 0000000000..5fb5631d05 --- /dev/null +++ b/tools/editor/plugins/light_occluder_2d_editor_plugin.h @@ -0,0 +1,87 @@ +#ifndef LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H +#define LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H + + + +#include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_node.h" +#include "scene/2d/light_occluder_2d.h" +#include "scene/gui/tool_button.h" +#include "scene/gui/button_group.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class CanvasItemEditor; + +class LightOccluder2DEditor : public HBoxContainer { + + OBJ_TYPE(LightOccluder2DEditor, HBoxContainer ); + + UndoRedo *undo_redo; + enum Mode { + + MODE_CREATE, + MODE_EDIT, + + }; + + Mode mode; + + ToolButton *button_create; + ToolButton *button_edit; + + CanvasItemEditor *canvas_item_editor; + EditorNode *editor; + Panel *panel; + LightOccluder2D *node; + MenuButton *options; + + int edited_point; + Vector2 edited_point_pos; + Vector<Vector2> pre_move_edit; + Vector<Vector2> wip; + bool wip_active; + + ConfirmationDialog *create_poly; + + void _wip_close(bool p_closed); + void _canvas_draw(); + void _menu_option(int p_option); + void _create_poly(); + +protected: + void _notification(int p_what); + void _node_removed(Node *p_node); + static void _bind_methods(); +public: + + Vector2 snap_point(const Vector2& p_point) const; + bool forward_input_event(const InputEvent& p_event); + void edit(Node *p_collision_polygon); + LightOccluder2DEditor(EditorNode *p_editor); +}; + +class LightOccluder2DEditorPlugin : public EditorPlugin { + + OBJ_TYPE( LightOccluder2DEditorPlugin, EditorPlugin ); + + LightOccluder2DEditor *collision_polygon_editor; + EditorNode *editor; + +public: + + virtual bool forward_input_event(const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); } + + virtual String get_name() const { return "LightOccluder2D"; } + 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); + + LightOccluder2DEditorPlugin(EditorNode *p_node); + ~LightOccluder2DEditorPlugin(); + +}; + +#endif // LIGHT_OCCLUDER_2D_EDITOR_PLUGIN_H diff --git a/tools/editor/plugins/mesh_editor_plugin.cpp b/tools/editor/plugins/mesh_editor_plugin.cpp index b8a5bd3bbe..f8c75e1cf5 100644 --- a/tools/editor/plugins/mesh_editor_plugin.cpp +++ b/tools/editor/plugins/mesh_editor_plugin.cpp @@ -33,7 +33,7 @@ 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)); + err_dialog->popup_centered(Size2(100,80)); return; } @@ -47,7 +47,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { 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(); + Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action("Create Static Trimesh"); @@ -68,7 +68,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { 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(); + Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action("Create Static Trimesh"); @@ -83,7 +83,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { case MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE: { - if (node==get_scene()->get_edited_scene_root()) { + if (node==get_tree()->get_edited_scene_root()) { err_dialog->set_text("This doesn't work on scene root!"); err_dialog->popup_centered(Size2(100,50)); return; @@ -109,7 +109,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { case MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE: { - if (node==get_scene()->get_edited_scene_root()) { + if (node==get_tree()->get_edited_scene_root()) { err_dialog->set_text("This doesn't work on scene root!"); err_dialog->popup_centered(Size2(100,50)); return; @@ -146,7 +146,7 @@ void MeshInstanceEditor::_menu_option(int p_option) { NavigationMeshInstance *nmi = memnew( NavigationMeshInstance ); nmi->set_navigation_mesh(nmesh); - Node *owner = node==get_scene()->get_edited_scene_root() ? node : node->get_owner(); + Node *owner = node==get_tree()->get_edited_scene_root() ? node : node->get_owner(); UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); ur->create_action("Create Navigation Mesh"); @@ -158,13 +158,54 @@ void MeshInstanceEditor::_menu_option(int p_option) { ur->add_undo_method(node,"remove_child",nmi); ur->commit_action(); } break; + case MENU_OPTION_CREATE_OUTLINE_MESH: { + + outline_dialog->popup_centered(Size2(200,80)); + } break; + } + +} + +void MeshInstanceEditor::_create_outline_mesh() { + + Ref<Mesh> mesh = node->get_mesh(); + if (mesh.is_null()) { + err_dialog->set_text("MeshInstance lacks a Mesh!"); + err_dialog->popup_centered(Size2(100,50)); + return; } + Ref<Mesh> mesho = mesh->create_outline(outline_size->get_val()); + + if (mesho.is_null()) { + err_dialog->set_text("Could not create outline!"); + err_dialog->popup_centered(Size2(100,50)); + return; + } + + MeshInstance *mi = memnew( MeshInstance ); + mi->set_mesh(mesho); + Node *owner=node->get_owner(); + if (get_tree()->get_edited_scene_root()==node) { + owner=node; + } + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + + ur->create_action("Create Outline"); + + ur->add_do_method(node,"add_child",mi); + ur->add_do_method(mi,"set_owner",owner); + + ur->add_do_reference(mi); + ur->add_undo_method(node,"remove_child",mi); + ur->commit_action(); } void MeshInstanceEditor::_bind_methods() { ObjectTypeDB::bind_method("_menu_option",&MeshInstanceEditor::_menu_option); + ObjectTypeDB::bind_method("_create_outline_mesh",&MeshInstanceEditor::_create_outline_mesh); } MeshInstanceEditor::MeshInstanceEditor() { @@ -182,9 +223,26 @@ MeshInstanceEditor::MeshInstanceEditor() { 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()->add_separator(); + options->get_popup()->add_item("Create Outline Mesh..",MENU_OPTION_CREATE_OUTLINE_MESH); options->get_popup()->connect("item_pressed", this,"_menu_option"); + outline_dialog = memnew( ConfirmationDialog ); + outline_dialog->set_title("Outline Size: "); + outline_size = memnew( SpinBox ); + outline_size->set_min(0.001); + outline_size->set_max(1024); + outline_size->set_step(0.001); + outline_size->set_val(0.05); + outline_dialog->add_child(outline_size); + outline_dialog->set_child_rect(outline_size); + add_child(outline_dialog); + outline_dialog->connect("confirmed",this,"_create_outline_mesh"); + + err_dialog = memnew( AcceptDialog ); + add_child(err_dialog); + } diff --git a/tools/editor/plugins/mesh_editor_plugin.h b/tools/editor/plugins/mesh_editor_plugin.h index 557eb90148..e502b5dc2b 100644 --- a/tools/editor/plugins/mesh_editor_plugin.h +++ b/tools/editor/plugins/mesh_editor_plugin.h @@ -20,8 +20,12 @@ class MeshInstanceEditor : public Node { MENU_OPTION_CREATE_TRIMESH_COLLISION_SHAPE, MENU_OPTION_CREATE_CONVEX_COLLISION_SHAPE, MENU_OPTION_CREATE_NAVMESH, + MENU_OPTION_CREATE_OUTLINE_MESH, }; + ConfirmationDialog *outline_dialog; + SpinBox *outline_size; + AcceptDialog *err_dialog; @@ -33,6 +37,8 @@ class MeshInstanceEditor : public Node { void _menu_option(int p_option); + void _create_outline_mesh(); + friend class MeshInstanceEditorPlugin; MenuButton * options; diff --git a/tools/editor/plugins/navigation_polygon_editor_plugin.cpp b/tools/editor/plugins/navigation_polygon_editor_plugin.cpp new file mode 100644 index 0000000000..bc15741d0f --- /dev/null +++ b/tools/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -0,0 +1,540 @@ +#include "navigation_polygon_editor_plugin.h" + +#include "canvas_item_editor_plugin.h" +#include "os/file_access.h" +#include "tools/editor/editor_settings.h" + +void NavigationPolygonEditor::_notification(int p_what) { + + switch(p_what) { + + case NOTIFICATION_READY: { + + button_create->set_icon( get_icon("Edit","EditorIcons")); + button_edit->set_icon( get_icon("MovePoint","EditorIcons")); + button_edit->set_pressed(true); + get_tree()->connect("node_removed",this,"_node_removed"); + create_nav->connect("confirmed",this,"_create_nav"); + + } break; + case NOTIFICATION_FIXED_PROCESS: { + + + } break; + } + +} +void NavigationPolygonEditor::_node_removed(Node *p_node) { + + if(p_node==node) { + node=NULL; + hide(); + canvas_item_editor->get_viewport_control()->update(); + } + +} + +void NavigationPolygonEditor::_create_nav() { + + if (!node) + return; + + undo_redo->create_action("Create Navigation Polygon"); + undo_redo->add_do_method(node,"set_navigation_polygon",Ref<NavigationPolygon>(memnew( NavigationPolygon))); + undo_redo->add_undo_method(node,"set_navigation_polygon",Variant(REF())); + undo_redo->commit_action(); +} + +void NavigationPolygonEditor::_menu_option(int p_option) { + + switch(p_option) { + + case MODE_CREATE: { + + mode=MODE_CREATE; + button_create->set_pressed(true); + button_edit->set_pressed(false); + } break; + case MODE_EDIT: { + + mode=MODE_EDIT; + button_create->set_pressed(false); + button_edit->set_pressed(true); + } break; + + } +} + +void NavigationPolygonEditor::_wip_close() { + + + if (wip.size()>=3) { + + undo_redo->create_action("Create Poly"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"remove_outline",node->get_navigation_polygon()->get_outline_count()); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"add_outline",wip); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->commit_action(); + mode=MODE_EDIT; + button_edit->set_pressed(true); + button_create->set_pressed(false); + } + + wip.clear(); + wip_active=false; + edited_point=-1; +} + +bool NavigationPolygonEditor::forward_input_event(const InputEvent& p_event) { + + + if (!node) + return false; + + if (node->get_navigation_polygon().is_null()) { + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + create_nav->set_text("No NavigationPolygon resource on this node.\nCreate and assign one?"); + create_nav->popup_centered_minsize(); + } + return (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1);; + } + + + switch(p_event.type) { + + case InputEvent::MOUSE_BUTTON: { + + const InputEventMouseButton &mb=p_event.mouse_button; + + Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); + + + Vector2 gpoint = Point2(mb.x,mb.y); + Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); + cpoint=canvas_item_editor->snap_point(cpoint); + cpoint = node->get_global_transform().affine_inverse().xform(cpoint); + + + + //first check if a point is to be added (segment split) + real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8); + + switch(mode) { + + + case MODE_CREATE: { + + if (mb.button_index==BUTTON_LEFT && mb.pressed) { + + + if (!wip_active) { + + wip.clear(); + wip.push_back( cpoint ); + wip_active=true; + edited_point_pos=cpoint; + edited_outline=-1; + canvas_item_editor->get_viewport_control()->update(); + edited_point=1; + return true; + } else { + + + if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_treshold) { + //wip closed + _wip_close(); + + return true; + } else { + + wip.push_back( cpoint ); + edited_point=wip.size(); + canvas_item_editor->get_viewport_control()->update(); + return true; + + //add wip point + } + } + } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) { + _wip_close(); + } + + + + } break; + + case MODE_EDIT: { + + if (mb.button_index==BUTTON_LEFT) { + if (mb.pressed) { + + if (mb.mod.control) { + + + //search edges + int closest_outline=-1; + int closest_idx=-1; + Vector2 closest_pos; + real_t closest_dist=1e10; + + for(int j=0;j<node->get_navigation_polygon()->get_outline_count();j++) { + + + DVector<Vector2> points=node->get_navigation_polygon()->get_outline(j); + + int pc=points.size(); + DVector<Vector2>::Read poly=points.read(); + + for(int i=0;i<pc;i++) { + + Vector2 points[2] ={ xform.xform(poly[i]), + xform.xform(poly[(i+1)%pc]) }; + + Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points); + if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2) + continue; //not valid to reuse point + + real_t d = cp.distance_to(gpoint); + if (d<closest_dist && d<grab_treshold) { + closest_dist=d; + closest_outline=j; + closest_pos=cp; + closest_idx=i; + } + + + } + } + + if (closest_idx>=0) { + + pre_move_edit=node->get_navigation_polygon()->get_outline(closest_outline); + DVector<Point2> poly = pre_move_edit; + poly.insert(closest_idx+1,xform.affine_inverse().xform(closest_pos)); + edited_point=closest_idx+1; + edited_outline=closest_outline; + edited_point_pos=xform.affine_inverse().xform(closest_pos); + node->get_navigation_polygon()->set_outline(closest_outline,poly); + canvas_item_editor->get_viewport_control()->update(); + return true; + } + } else { + + //look for points to move + int closest_outline=-1; + int closest_idx=-1; + Vector2 closest_pos; + real_t closest_dist=1e10; + + for(int j=0;j<node->get_navigation_polygon()->get_outline_count();j++) { + + + DVector<Vector2> points=node->get_navigation_polygon()->get_outline(j); + + int pc=points.size(); + DVector<Vector2>::Read poly=points.read(); + + for(int i=0;i<pc;i++) { + + + Vector2 cp =xform.xform(poly[i]); + + real_t d = cp.distance_to(gpoint); + if (d<closest_dist && d<grab_treshold) { + closest_dist=d; + closest_pos=cp; + closest_outline=j; + closest_idx=i; + } + } + } + + if (closest_idx>=0) { + + pre_move_edit=node->get_navigation_polygon()->get_outline(closest_outline); + edited_point=closest_idx; + edited_outline=closest_outline; + edited_point_pos=xform.affine_inverse().xform(closest_pos); + canvas_item_editor->get_viewport_control()->update(); + return true; + } + } + } else { + + if (edited_point!=-1) { + + //apply + + DVector<Vector2> poly = node->get_navigation_polygon()->get_outline(edited_outline); + ERR_FAIL_INDEX_V(edited_point,poly.size(),false); + poly.set(edited_point,edited_point_pos); + undo_redo->create_action("Edit Poly"); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"set_outline",edited_outline,poly); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"set_outline",edited_outline,pre_move_edit); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->commit_action(); + + edited_point=-1; + return true; + } + } + } if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) { + + int closest_outline=-1; + int closest_idx=-1; + Vector2 closest_pos; + real_t closest_dist=1e10; + + for(int j=0;j<node->get_navigation_polygon()->get_outline_count();j++) { + + + DVector<Vector2> points=node->get_navigation_polygon()->get_outline(j); + + int pc=points.size(); + DVector<Vector2>::Read poly=points.read(); + + for(int i=0;i<pc;i++) { + + + Vector2 cp =xform.xform(poly[i]); + + real_t d = cp.distance_to(gpoint); + if (d<closest_dist && d<grab_treshold) { + closest_dist=d; + closest_pos=cp; + closest_outline=j; + closest_idx=i; + } + } + } + + if (closest_idx>=0) { + + + DVector<Vector2> poly = node->get_navigation_polygon()->get_outline(closest_outline); + + if (poly.size()>3) { + undo_redo->create_action("Edit Poly (Remove Point)"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"set_outline",closest_outline,poly); + poly.remove(closest_idx); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"set_outline",closest_outline,poly); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->commit_action(); + } else { + + undo_redo->create_action("Remove Poly And Point"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"add_outline_at_index",poly,closest_outline); + poly.remove(closest_idx); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"remove_outline",closest_outline); + undo_redo->add_do_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); + undo_redo->add_undo_method(node->get_navigation_polygon().ptr(),"make_polygons_from_outlines"); + undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update"); + undo_redo->commit_action(); + + } + return true; + } + } + + + + } break; + } + + + + } break; + case InputEvent::MOUSE_MOTION: { + + const InputEventMouseMotion &mm=p_event.mouse_motion; + + if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) { + + Vector2 gpoint = Point2(mm.x,mm.y); + Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); + cpoint=canvas_item_editor->snap_point(cpoint); + edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); + + canvas_item_editor->get_viewport_control()->update(); + + } + + } break; + } + + return false; +} +void NavigationPolygonEditor::_canvas_draw() { + + if (!node) + return; + + Control *vpc = canvas_item_editor->get_viewport_control(); + if (node->get_navigation_polygon().is_null()) + return; + + Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); + Ref<Texture> handle= get_icon("EditorHandle","EditorIcons"); + + + + for(int j=-1;j<node->get_navigation_polygon()->get_outline_count();j++) { + Vector<Vector2> poly; + + if (wip_active && j==edited_outline) { + poly=wip; + } else { + if (j==-1) + continue; + poly = Variant(node->get_navigation_polygon()->get_outline(j)); + } + + int len = poly.size(); + + for(int i=0;i<poly.size();i++) { + + + Vector2 p,p2; + p = (j==edited_outline && i==edited_point) ? edited_point_pos : poly[i]; + if (j==edited_outline && ((wip_active && i==poly.size()-1) || (((i+1)%poly.size())==edited_point))) + p2=edited_point_pos; + else + p2 = poly[(i+1)%poly.size()]; + + Vector2 point = xform.xform(p); + Vector2 next_point = xform.xform(p2); + + Color col=Color(1,0.3,0.1,0.8); + vpc->draw_line(point,next_point,col,2); + vpc->draw_texture(handle,point-handle->get_size()*0.5); + } + } +} + + + +void NavigationPolygonEditor::edit(Node *p_collision_polygon) { + + if (!canvas_item_editor) { + canvas_item_editor=CanvasItemEditor::get_singleton(); + } + + if (p_collision_polygon) { + + node=p_collision_polygon->cast_to<NavigationPolygonInstance>(); + if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) + canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw"); + wip.clear(); + wip_active=false; + edited_point=-1; + canvas_item_editor->get_viewport_control()->update(); + + } else { + node=NULL; + + if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) + canvas_item_editor->get_viewport_control()->disconnect("draw",this,"_canvas_draw"); + + } + +} + +void NavigationPolygonEditor::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("_menu_option"),&NavigationPolygonEditor::_menu_option); + ObjectTypeDB::bind_method(_MD("_canvas_draw"),&NavigationPolygonEditor::_canvas_draw); + ObjectTypeDB::bind_method(_MD("_node_removed"),&NavigationPolygonEditor::_node_removed); + ObjectTypeDB::bind_method(_MD("_create_nav"),&NavigationPolygonEditor::_create_nav); + +} + +NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) { + + canvas_item_editor=NULL; + editor=p_editor; + undo_redo = editor->get_undo_redo(); + + add_child( memnew( VSeparator )); + button_create = memnew( ToolButton ); + add_child(button_create); + button_create->connect("pressed",this,"_menu_option",varray(MODE_CREATE)); + button_create->set_toggle_mode(true); + button_create->set_tooltip("Create a new polygon from scratch"); + + button_edit = memnew( ToolButton ); + add_child(button_edit); + button_edit->connect("pressed",this,"_menu_option",varray(MODE_EDIT)); + button_edit->set_toggle_mode(true); + button_edit->set_tooltip("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point."); + create_nav = memnew( ConfirmationDialog ); + add_child(create_nav); + create_nav->get_ok()->set_text("Create"); + + + //add_constant_override("separation",0); + +#if 0 + options = memnew( MenuButton ); + add_child(options); + options->set_area_as_parent_rect(); + options->set_text("Polygon"); + //options->get_popup()->add_item("Parse BBCODE",PARSE_BBCODE); + options->get_popup()->connect("item_pressed", this,"_menu_option"); +#endif + + mode = MODE_EDIT; + wip_active=false; + edited_outline=-1; + +} + + +void NavigationPolygonEditorPlugin::edit(Object *p_object) { + + collision_polygon_editor->edit(p_object->cast_to<Node>()); +} + +bool NavigationPolygonEditorPlugin::handles(Object *p_object) const { + + return p_object->is_type("NavigationPolygonInstance"); +} + +void NavigationPolygonEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + collision_polygon_editor->show(); + } else { + + collision_polygon_editor->hide(); + collision_polygon_editor->edit(NULL); + } + +} + +NavigationPolygonEditorPlugin::NavigationPolygonEditorPlugin(EditorNode *p_node) { + + editor=p_node; + collision_polygon_editor = memnew( NavigationPolygonEditor(p_node) ); + CanvasItemEditor::get_singleton()->add_control_to_menu_panel(collision_polygon_editor); + + collision_polygon_editor->hide(); + + + +} + + +NavigationPolygonEditorPlugin::~NavigationPolygonEditorPlugin() +{ +} + diff --git a/tools/editor/plugins/navigation_polygon_editor_plugin.h b/tools/editor/plugins/navigation_polygon_editor_plugin.h new file mode 100644 index 0000000000..f742cb011d --- /dev/null +++ b/tools/editor/plugins/navigation_polygon_editor_plugin.h @@ -0,0 +1,90 @@ +#ifndef NAVIGATIONPOLYGONEDITORPLUGIN_H +#define NAVIGATIONPOLYGONEDITORPLUGIN_H + + + +#include "tools/editor/editor_plugin.h" +#include "tools/editor/editor_node.h" +#include "scene/2d/navigation_polygon.h" +#include "scene/gui/tool_button.h" +#include "scene/gui/button_group.h" + +/** + @author Juan Linietsky <reduzio@gmail.com> +*/ +class CanvasItemEditor; + +class NavigationPolygonEditor : public HBoxContainer { + + OBJ_TYPE(NavigationPolygonEditor, HBoxContainer ); + + UndoRedo *undo_redo; + enum Mode { + + MODE_CREATE, + MODE_EDIT, + + }; + + Mode mode; + + ToolButton *button_create; + ToolButton *button_edit; + + ConfirmationDialog *create_nav; + + CanvasItemEditor *canvas_item_editor; + EditorNode *editor; + Panel *panel; + NavigationPolygonInstance *node; + MenuButton *options; + + int edited_outline; + int edited_point; + Vector2 edited_point_pos; + DVector<Vector2> pre_move_edit; + Vector<Vector2> wip; + bool wip_active; + + + void _wip_close(); + void _canvas_draw(); + void _create_nav(); + + void _menu_option(int p_option); + +protected: + void _notification(int p_what); + void _node_removed(Node *p_node); + static void _bind_methods(); +public: + + bool forward_input_event(const InputEvent& p_event); + void edit(Node *p_collision_polygon); + NavigationPolygonEditor(EditorNode *p_editor); +}; + +class NavigationPolygonEditorPlugin : public EditorPlugin { + + OBJ_TYPE( NavigationPolygonEditorPlugin, EditorPlugin ); + + NavigationPolygonEditor *collision_polygon_editor; + EditorNode *editor; + +public: + + virtual bool forward_input_event(const InputEvent& p_event) { return collision_polygon_editor->forward_input_event(p_event); } + + virtual String get_name() const { return "NavigationPolygonInstance"; } + 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); + + NavigationPolygonEditorPlugin(EditorNode *p_node); + ~NavigationPolygonEditorPlugin(); + +}; + + +#endif // NAVIGATIONPOLYGONEDITORPLUGIN_H diff --git a/tools/editor/plugins/particles_2d_editor_plugin.cpp b/tools/editor/plugins/particles_2d_editor_plugin.cpp index b23847231b..a7adfcd172 100644 --- a/tools/editor/plugins/particles_2d_editor_plugin.cpp +++ b/tools/editor/plugins/particles_2d_editor_plugin.cpp @@ -26,173 +26,173 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "particles_2d_editor_plugin.h"
-#include "canvas_item_editor_plugin.h"
-#include "io/image_loader.h"
-
-
-void Particles2DEditorPlugin::edit(Object *p_object) {
-
- if (p_object) {
- particles=p_object->cast_to<Particles2D>();
- } else {
- particles=NULL;
- }
-}
-
-bool Particles2DEditorPlugin::handles(Object *p_object) const {
-
- return p_object->is_type("Particles2D");
-}
-
-void Particles2DEditorPlugin::make_visible(bool p_visible) {
-
- if (p_visible) {
-
- sep->show();
- menu->show();
- } else {
-
- menu->hide();
- sep->hide();
- }
-
-}
-
-void Particles2DEditorPlugin::_file_selected(const String& p_file) {
-
- print_line("file: "+p_file);
-
- int epc=epoints->get_val();
-
- Image img;
- Error err = ImageLoader::load_image(p_file,&img);
- ERR_EXPLAIN("Error loading image: "+p_file);
- ERR_FAIL_COND(err!=OK);
-
- img.convert(Image::FORMAT_GRAYSCALE_ALPHA);
- ERR_FAIL_COND(img.get_format()!=Image::FORMAT_GRAYSCALE_ALPHA);
- Size2i s = Size2(img.get_width(),img.get_height());
- ERR_FAIL_COND(s.width==0 || s.height==0);
-
- DVector<uint8_t> data = img.get_data();
- DVector<uint8_t>::Read r = data.read();
-
- Vector<Point2i> valid_positions;
- valid_positions.resize(s.width*s.height);
- int vpc=0;
-
-
- for(int i=0;i<s.width*s.height;i++) {
-
- uint8_t a = r[i*2+1];
- if (a>128) {
- valid_positions[vpc++]=Point2i(i%s.width,i/s.width);
- }
- }
-
- valid_positions.resize(vpc);
-
- ERR_EXPLAIN("No pixels with transparency > 128 in image..");
- ERR_FAIL_COND(valid_positions.size()==0);
-
- DVector<Point2> epoints;
- epoints.resize(epc);
- DVector<Point2>::Write w = epoints.write();
-
- Size2 extents = Size2(img.get_width()*0.5,img.get_height()*0.5);
-
- for(int i=0;i<epc;i++) {
-
- Point2 p = valid_positions[Math::rand()%vpc];
- p-=s/2;
- w[i]=p/extents;
- }
-
- w = DVector<Point2>::Write();
-
- undo_redo->create_action("Set Emission Mask");
- undo_redo->add_do_method(particles,"set_emission_points",epoints);
- undo_redo->add_do_method(particles,"set_emission_half_extents",extents);
- undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points());
- undo_redo->add_undo_method(particles,"set_emission_half_extents",particles->get_emission_half_extents());
- undo_redo->commit_action();
-
-}
-
-void Particles2DEditorPlugin::_menu_callback(int p_idx) {
-
- switch(p_idx) {
- case MENU_LOAD_EMISSION_MASK: {
-
-
- file->popup_centered_ratio();
-
- } break;
- case MENU_CLEAR_EMISSION_MASK: {
-
- undo_redo->create_action("Clear Emission Mask");
- undo_redo->add_do_method(particles,"set_emission_points",DVector<Vector2>());
- undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points());
- undo_redo->commit_action();
- } break;
- }
-
-}
-
-
-void Particles2DEditorPlugin::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_ENTER_SCENE) {
-
- menu->get_popup()->connect("item_pressed",this,"_menu_callback");
- file->connect("file_selected",this,"_file_selected");
- }
-}
-
-void Particles2DEditorPlugin::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("_menu_callback"),&Particles2DEditorPlugin::_menu_callback);
- ObjectTypeDB::bind_method(_MD("_file_selected"),&Particles2DEditorPlugin::_file_selected);
-}
-
-
-
-Particles2DEditorPlugin::Particles2DEditorPlugin(EditorNode *p_node) {
-
- particles=NULL;
- editor=p_node;
- undo_redo=editor->get_undo_redo();
- sep = memnew( VSeparator );
- CanvasItemEditor::get_singleton()->add_control_to_menu_panel(sep);
- sep->hide();
-
- menu = memnew( MenuButton );
- menu->get_popup()->add_item("Load Emission Mask",MENU_LOAD_EMISSION_MASK);
- menu->get_popup()->add_item("Clear Emission Mask",MENU_CLEAR_EMISSION_MASK);
- menu->set_text("Particles");
-
- file = memnew(FileDialog);
- add_child(file);
- List<String> ext;
- ImageLoader::get_recognized_extensions(&ext);
- for(List<String>::Element *E=ext.front();E;E=E->next()) {
- file->add_filter("*."+E->get()+"; "+E->get().to_upper());
- }
- file->set_mode(FileDialog::MODE_OPEN_FILE);
- CanvasItemEditor::get_singleton()->add_control_to_menu_panel(menu);
- epoints = memnew( SpinBox );
- epoints->set_min(1);
- epoints->set_max(8192);
- epoints->set_step(1);
- epoints->set_val(512);
- file->get_vbox()->add_margin_child("Generated Point Count:",epoints);
- menu->hide();
-
-}
-
-
-Particles2DEditorPlugin::~Particles2DEditorPlugin()
-{
-}
-
+#include "particles_2d_editor_plugin.h" +#include "canvas_item_editor_plugin.h" +#include "io/image_loader.h" + + +void Particles2DEditorPlugin::edit(Object *p_object) { + + if (p_object) { + particles=p_object->cast_to<Particles2D>(); + } else { + particles=NULL; + } +} + +bool Particles2DEditorPlugin::handles(Object *p_object) const { + + return p_object->is_type("Particles2D"); +} + +void Particles2DEditorPlugin::make_visible(bool p_visible) { + + if (p_visible) { + + sep->show(); + menu->show(); + } else { + + menu->hide(); + sep->hide(); + } + +} + +void Particles2DEditorPlugin::_file_selected(const String& p_file) { + + print_line("file: "+p_file); + + int epc=epoints->get_val(); + + Image img; + Error err = ImageLoader::load_image(p_file,&img); + ERR_EXPLAIN("Error loading image: "+p_file); + ERR_FAIL_COND(err!=OK); + + img.convert(Image::FORMAT_GRAYSCALE_ALPHA); + ERR_FAIL_COND(img.get_format()!=Image::FORMAT_GRAYSCALE_ALPHA); + Size2i s = Size2(img.get_width(),img.get_height()); + ERR_FAIL_COND(s.width==0 || s.height==0); + + DVector<uint8_t> data = img.get_data(); + DVector<uint8_t>::Read r = data.read(); + + Vector<Point2i> valid_positions; + valid_positions.resize(s.width*s.height); + int vpc=0; + + + for(int i=0;i<s.width*s.height;i++) { + + uint8_t a = r[i*2+1]; + if (a>128) { + valid_positions[vpc++]=Point2i(i%s.width,i/s.width); + } + } + + valid_positions.resize(vpc); + + ERR_EXPLAIN("No pixels with transparency > 128 in image.."); + ERR_FAIL_COND(valid_positions.size()==0); + + DVector<Point2> epoints; + epoints.resize(epc); + DVector<Point2>::Write w = epoints.write(); + + Size2 extents = Size2(img.get_width()*0.5,img.get_height()*0.5); + + for(int i=0;i<epc;i++) { + + Point2 p = valid_positions[Math::rand()%vpc]; + p-=s/2; + w[i]=p/extents; + } + + w = DVector<Point2>::Write(); + + undo_redo->create_action("Set Emission Mask"); + undo_redo->add_do_method(particles,"set_emission_points",epoints); + undo_redo->add_do_method(particles,"set_emission_half_extents",extents); + undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points()); + undo_redo->add_undo_method(particles,"set_emission_half_extents",particles->get_emission_half_extents()); + undo_redo->commit_action(); + +} + +void Particles2DEditorPlugin::_menu_callback(int p_idx) { + + switch(p_idx) { + case MENU_LOAD_EMISSION_MASK: { + + + file->popup_centered_ratio(); + + } break; + case MENU_CLEAR_EMISSION_MASK: { + + undo_redo->create_action("Clear Emission Mask"); + undo_redo->add_do_method(particles,"set_emission_points",DVector<Vector2>()); + undo_redo->add_undo_method(particles,"set_emission_points",particles->get_emission_points()); + undo_redo->commit_action(); + } break; + } + +} + + +void Particles2DEditorPlugin::_notification(int p_what) { + + if (p_what==NOTIFICATION_ENTER_TREE) { + + menu->get_popup()->connect("item_pressed",this,"_menu_callback"); + file->connect("file_selected",this,"_file_selected"); + } +} + +void Particles2DEditorPlugin::_bind_methods() { + + ObjectTypeDB::bind_method(_MD("_menu_callback"),&Particles2DEditorPlugin::_menu_callback); + ObjectTypeDB::bind_method(_MD("_file_selected"),&Particles2DEditorPlugin::_file_selected); +} + + + +Particles2DEditorPlugin::Particles2DEditorPlugin(EditorNode *p_node) { + + particles=NULL; + editor=p_node; + undo_redo=editor->get_undo_redo(); + sep = memnew( VSeparator ); + CanvasItemEditor::get_singleton()->add_control_to_menu_panel(sep); + sep->hide(); + + menu = memnew( MenuButton ); + menu->get_popup()->add_item("Load Emission Mask",MENU_LOAD_EMISSION_MASK); + menu->get_popup()->add_item("Clear Emission Mask",MENU_CLEAR_EMISSION_MASK); + menu->set_text("Particles"); + + file = memnew(FileDialog); + add_child(file); + List<String> ext; + ImageLoader::get_recognized_extensions(&ext); + for(List<String>::Element *E=ext.front();E;E=E->next()) { + file->add_filter("*."+E->get()+"; "+E->get().to_upper()); + } + file->set_mode(FileDialog::MODE_OPEN_FILE); + CanvasItemEditor::get_singleton()->add_control_to_menu_panel(menu); + epoints = memnew( SpinBox ); + epoints->set_min(1); + epoints->set_max(8192); + epoints->set_step(1); + epoints->set_val(512); + file->get_vbox()->add_margin_child("Generated Point Count:",epoints); + menu->hide(); + +} + + +Particles2DEditorPlugin::~Particles2DEditorPlugin() +{ +} + diff --git a/tools/editor/plugins/particles_editor_plugin.cpp b/tools/editor/plugins/particles_editor_plugin.cpp index 418ad11704..ebb45bc316 100644 --- a/tools/editor/plugins/particles_editor_plugin.cpp +++ b/tools/editor/plugins/particles_editor_plugin.cpp @@ -110,7 +110,7 @@ void ParticlesEditor::_populate() { void ParticlesEditor::_notification(int p_notification) { - if (p_notification==NOTIFICATION_ENTER_SCENE) { + if (p_notification==NOTIFICATION_ENTER_TREE) { } } diff --git a/tools/editor/plugins/path_2d_editor_plugin.cpp b/tools/editor/plugins/path_2d_editor_plugin.cpp index 33ea5f3588..a38ec5bb7a 100644 --- a/tools/editor/plugins/path_2d_editor_plugin.cpp +++ b/tools/editor/plugins/path_2d_editor_plugin.cpp @@ -62,17 +62,6 @@ void Path2DEditor::_node_removed(Node *p_node) { } -Vector2 Path2DEditor::snap_point(const Vector2& p_point) const { - - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } -} - bool Path2DEditor::forward_input_event(const InputEvent& p_event) { if (!node) @@ -93,8 +82,8 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mb.x,mb.y); - Vector2 cpoint = !mb.mod.alt? snap_point(xform.affine_inverse().xform(gpoint)) - : node->get_global_transform().affine_inverse().xform( snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); + Vector2 cpoint = !mb.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) + : node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); //first check if a point is to be added (segment split) real_t grab_treshold=EDITOR_DEF("poly_editor/point_grab_radius",8); @@ -195,7 +184,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Ref<Curve2D> curve = node->get_curve(); - Vector2 new_pos = moving_from + xform.basis_xform( gpoint - moving_screen_from ); + Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); switch(action) { case ACTION_MOVING_POINT: { @@ -250,9 +239,9 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { if (!wip_active) { wip.clear(); - wip.push_back( snap_point(cpoint) ); + wip.push_back( canvas_item_editor->snap_point(cpoint) ); wip_active=true; - edited_point_pos=snap_point(cpoint); + edited_point_pos=canvas_item_editor->snap_point(cpoint); canvas_item_editor->update(); edited_point=1; return true; @@ -265,7 +254,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { return true; } else { - wip.push_back( snap_point(cpoint) ); + wip.push_back( canvas_item_editor->snap_point(cpoint) ); edited_point=wip.size(); canvas_item_editor->update(); return true; @@ -327,9 +316,9 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { if (closest_idx>=0) { pre_move_edit=poly; - poly.insert(closest_idx+1,snap_point(xform.affine_inverse().xform(closest_pos))); + poly.insert(closest_idx+1,canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos))); edited_point=closest_idx+1; - edited_point_pos=snap_point(xform.affine_inverse().xform(closest_pos)); + edited_point_pos=canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos)); node->set_polygon(poly); canvas_item_editor->update(); return true; @@ -434,12 +423,12 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mm.x,mm.y); - Vector2 cpoint = !mm.mod.alt? snap_point(xform.affine_inverse().xform(gpoint)) - : node->get_global_transform().affine_inverse().xform( snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); + Vector2 cpoint = !mm.mod.alt? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) + : node->get_global_transform().affine_inverse().xform( canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)) ); Ref<Curve2D> curve = node->get_curve(); - Vector2 new_pos = moving_from + xform.basis_xform( gpoint - moving_screen_from ); + Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from); switch(action) { @@ -471,7 +460,7 @@ bool Path2DEditor::forward_input_event(const InputEvent& p_event) { Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = Point2(mm.x,mm.y); - edited_point_pos = snap_point(xform.affine_inverse().xform(gpoint)); + edited_point_pos = canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)); canvas_item_editor->update(); } diff --git a/tools/editor/plugins/path_2d_editor_plugin.h b/tools/editor/plugins/path_2d_editor_plugin.h index 73de2cc838..6ff69b96a2 100644 --- a/tools/editor/plugins/path_2d_editor_plugin.h +++ b/tools/editor/plugins/path_2d_editor_plugin.h @@ -94,7 +94,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); void edit(Node *p_path2d); Path2DEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/path_editor_plugin.cpp b/tools/editor/plugins/path_editor_plugin.cpp index 7b0ff971d2..3f540a3bf4 100644 --- a/tools/editor/plugins/path_editor_plugin.cpp +++ b/tools/editor/plugins/path_editor_plugin.cpp @@ -500,7 +500,7 @@ void PathEditorPlugin::_close_curve() { void PathEditorPlugin::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_SCENE) {
+ if (p_what==NOTIFICATION_ENTER_TREE) {
curve_create->connect("pressed",this,"_mode_changed",make_binds(0));
curve_edit->connect("pressed",this,"_mode_changed",make_binds(1));
diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.cpp b/tools/editor/plugins/polygon_2d_editor_plugin.cpp index 7dd8dd3035..3858bf2c68 100644 --- a/tools/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/tools/editor/plugins/polygon_2d_editor_plugin.cpp @@ -69,17 +69,6 @@ void Polygon2DEditor::_node_removed(Node *p_node) { } -Vector2 Polygon2DEditor::snap_point(const Vector2& p_point) const { - - if (canvas_item_editor->is_snap_active()) { - - return p_point.snapped(Vector2(1,1)*canvas_item_editor->get_snap()); - - } else { - return p_point; - } -} - void Polygon2DEditor::_menu_option(int p_option) { switch(p_option) { @@ -187,6 +176,8 @@ void Polygon2DEditor::_wip_close() { bool Polygon2DEditor::forward_input_event(const InputEvent& p_event) { + if (node==NULL) + return false; switch(p_event.type) { @@ -199,7 +190,7 @@ bool Polygon2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mb.x,mb.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); cpoint = node->get_global_transform().affine_inverse().xform(cpoint); @@ -403,7 +394,7 @@ bool Polygon2DEditor::forward_input_event(const InputEvent& p_event) { Vector2 gpoint = Point2(mm.x,mm.y); Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint); - cpoint=snap_point(cpoint); + cpoint=canvas_item_editor->snap_point(cpoint); edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint); canvas_item_editor->get_viewport_control()->update(); @@ -701,11 +692,16 @@ void Polygon2DEditor::edit(Node *p_collision_polygon) { node=p_collision_polygon->cast_to<Polygon2D>(); if (!canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) canvas_item_editor->get_viewport_control()->connect("draw",this,"_canvas_draw"); + node->connect("exit_tree",this,"_node_removed",varray(),CONNECT_ONESHOT); wip.clear(); wip_active=false; edited_point=-1; } else { + + if (node) + node->disconnect("exit_tree",this,"_node_removed"); + node=NULL; if (canvas_item_editor->get_viewport_control()->is_connected("draw",this,"_canvas_draw")) @@ -723,12 +719,14 @@ void Polygon2DEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_uv_draw"),&Polygon2DEditor::_uv_draw); ObjectTypeDB::bind_method(_MD("_uv_input"),&Polygon2DEditor::_uv_input); ObjectTypeDB::bind_method(_MD("_uv_scroll_changed"),&Polygon2DEditor::_uv_scroll_changed); + ObjectTypeDB::bind_method(_MD("_node_removed"),&Polygon2DEditor::_node_removed); } Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) { + node=NULL; canvas_item_editor=NULL; editor=p_editor; undo_redo = editor->get_undo_redo(); diff --git a/tools/editor/plugins/polygon_2d_editor_plugin.h b/tools/editor/plugins/polygon_2d_editor_plugin.h index 88d1c20493..8f807cb7e8 100644 --- a/tools/editor/plugins/polygon_2d_editor_plugin.h +++ b/tools/editor/plugins/polygon_2d_editor_plugin.h @@ -92,7 +92,6 @@ protected: static void _bind_methods(); public: - Vector2 snap_point(const Vector2& p_point) const; bool forward_input_event(const InputEvent& p_event); void edit(Node *p_collision_polygon); Polygon2DEditor(EditorNode *p_editor); diff --git a/tools/editor/plugins/resource_preloader_editor_plugin.cpp b/tools/editor/plugins/resource_preloader_editor_plugin.cpp index b0841933ec..d9726cac21 100644 --- a/tools/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/tools/editor/plugins/resource_preloader_editor_plugin.cpp @@ -45,7 +45,7 @@ void ResourcePreloaderEditor::_notification(int p_what) { } - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { load->set_icon( get_icon("Folder","EditorIcons") ); _delete->set_icon( get_icon("Del","EditorIcons") ); } diff --git a/tools/editor/plugins/sample_editor_plugin.cpp b/tools/editor/plugins/sample_editor_plugin.cpp index e3fad58a89..83adeee789 100644 --- a/tools/editor/plugins/sample_editor_plugin.cpp +++ b/tools/editor/plugins/sample_editor_plugin.cpp @@ -46,7 +46,7 @@ void SampleEditor::_notification(int p_what) { } - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { play->set_icon( get_icon("Play","EditorIcons") ); stop->set_icon( get_icon("Stop","EditorIcons") ); } diff --git a/tools/editor/plugins/sample_library_editor_plugin.cpp b/tools/editor/plugins/sample_library_editor_plugin.cpp index 84143dcd4b..96d72595ab 100644 --- a/tools/editor/plugins/sample_library_editor_plugin.cpp +++ b/tools/editor/plugins/sample_library_editor_plugin.cpp @@ -47,7 +47,7 @@ void SampleLibraryEditor::_notification(int p_what) { } - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { play->set_icon( get_icon("Play","EditorIcons") ); stop->set_icon( get_icon("Stop","EditorIcons") ); load->set_icon( get_icon("Folder","EditorIcons") ); @@ -129,7 +129,7 @@ void SampleLibraryEditor::_button_pressed(Object *p_item,int p_column, int p_id) player->play(name,true); } else if (p_column==1) { - get_scene()->get_root()->get_child(0)->call("_resource_selected",sample_library->get_sample(name)); + get_tree()->get_root()->get_child(0)->call("_resource_selected",sample_library->get_sample(name)); } @@ -186,7 +186,7 @@ void SampleLibraryEditor::_item_edited() { Ref<Sample> samp = sample_library->get_sample(tree->get_selected()->get_metadata(0)); - get_scene()->get_root()->get_child(0)->call("_resource_selected",samp); + get_tree()->get_root()->get_child(0)->call("_resource_selected",samp); } @@ -235,6 +235,7 @@ void SampleLibraryEditor::_update_library() { List<StringName> names; sample_library->get_sample_list(&names); + names.sort_custom<StringName::AlphCompare>(); for(List<StringName>::Element *E=names.front();E;E=E->next()) { diff --git a/tools/editor/plugins/sample_player_editor_plugin.cpp b/tools/editor/plugins/sample_player_editor_plugin.cpp index f3d6fe65da..2e31467dc7 100644 --- a/tools/editor/plugins/sample_player_editor_plugin.cpp +++ b/tools/editor/plugins/sample_player_editor_plugin.cpp @@ -32,7 +32,7 @@ void SamplePlayerEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { play->set_icon( get_icon("Play","EditorIcons") ); stop->set_icon( get_icon("Stop","EditorIcons") ); } @@ -94,6 +94,7 @@ void SamplePlayerEditor::_update_sample_library() { List<StringName> samplenames; sl->get_sample_list(&samplenames); + samplenames.sort_custom<StringName::AlphCompare>(); for(List<StringName>::Element *E=samplenames.front();E;E=E->next()) { samples->add_item(E->get()); } diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 24e09111e2..72b3025f2f 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -115,7 +115,7 @@ void ScriptEditorQuickOpen::_confirmed() { void ScriptEditorQuickOpen::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { connect("confirmed",this,"_confirmed"); } @@ -188,7 +188,7 @@ void ScriptTextEditor::apply_code() { if (script.is_null()) return; - print_line("applying code"); +// print_line("applying code"); script->set_source_code(get_text_edit()->get_text()); script->update_exports(); } @@ -209,6 +209,8 @@ void ScriptTextEditor::_load_theme_settings() { get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0))); get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1))); get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1))); + get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/brace_mismatch_color",Color(1,0.2,0.2))); + get_text_edit()->add_color_override("current_line_color",EDITOR_DEF("text_editor/current_line_color",Color(0.3,0.5,0.8,0.15))); Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2)); @@ -237,7 +239,7 @@ void ScriptTextEditor::_load_theme_settings() { //colorize engine types Color type_color= EDITOR_DEF("text_editor/engine_type_color",Color(0.0,0.2,0.4)); - List<String> types; + List<String> types; ObjectTypeDB::get_type_list(&types); for(List<String>::Element *E=types.front();E;E=E->next()) { @@ -384,9 +386,35 @@ void ScriptTextEditor::_validate_script() { _update_name(); } -void ScriptTextEditor::_code_complete_script(const String& p_code, const String& p_keyword,int p_line, List<String>* r_options) { - Error err = script->get_language()->complete_keyword(p_code,p_line,script->get_path().get_base_dir(),p_keyword,r_options); +static Node* _find_node_for_script(Node* p_base, Node*p_current, const Ref<Script>& p_script) { + + if (p_current->get_owner()!=p_base && p_base!=p_current) + return NULL; + Ref<Script> c = p_current->get_script(); + if (c==p_script) + return p_current; + for(int i=0;i<p_current->get_child_count();i++) { + Node *found = _find_node_for_script(p_base,p_current->get_child(i),p_script); + if (found) + return found; + } + + return NULL; +} + +void ScriptTextEditor::_code_complete_script(const String& p_code, List<String>* r_options) { + + Node *base = get_tree()->get_edited_scene_root(); + if (base) { + base = _find_node_for_script(base,base,script); + } + String hint; + Error err = script->get_language()->complete_code(p_code,script->get_path().get_base_dir(),base,r_options,hint); + if (hint!="") { + get_text_edit()->set_code_hint(hint); + print_line("hint: "+hint.replace(String::chr(0xFFFF),"|")); + } } @@ -602,12 +630,27 @@ bool ScriptEditor::_test_script_times_on_disk() { - if (!all_ok) - disk_changed->call_deferred("popup_centered_ratio",0.5); + if (!all_ok) { + if (bool(EDITOR_DEF("text_editor/auto_reload_changed_scripts",false))) { + script_editor->_reload_scripts(); + } else { + disk_changed->call_deferred("popup_centered_ratio",0.5); + } + } return all_ok; } +void ScriptEditor::swap_lines(TextEdit *tx, int line1, int line2) +{ + String tmp = tx->get_line(line1); + String tmp2 = tx->get_line(line2); + tx->set_line(line2, tmp); + tx->set_line(line1, tmp2); + + tx->cursor_set_line(line2); +} + void ScriptEditor::_menu_option(int p_option) { @@ -661,13 +704,10 @@ void ScriptEditor::_menu_option(int p_option) { } break; case EDIT_UNDO: { - - current->get_text_edit()->undo(); } break; case EDIT_REDO: { current->get_text_edit()->redo(); - } break; case EDIT_CUT: { @@ -686,6 +726,223 @@ void ScriptEditor::_menu_option(int p_option) { current->get_text_edit()->select_all(); } break; + case EDIT_MOVE_LINE_UP: { + + TextEdit *tx = current->get_text_edit(); + Ref<Script> scr = current->get_edited_script(); + if (scr.is_null()) + return; + + if (tx->is_selection_active()) + { + int from_line = tx->get_selection_from_line(); + int from_col = tx->get_selection_from_column(); + int to_line = tx->get_selection_to_line(); + int to_column = tx->get_selection_to_column(); + + for (int i = from_line; i <= to_line; i++) + { + int line_id = i; + int next_id = i - 1; + + if (line_id == 0 || next_id < 0) + return; + + swap_lines(tx, line_id, next_id); + } + int from_line_up = from_line > 0 ? from_line-1 : from_line; + int to_line_up = to_line > 0 ? to_line-1 : to_line; + tx->select(from_line_up, from_col, to_line_up, to_column); + } + else + { + int line_id = tx->cursor_get_line(); + int next_id = line_id - 1; + + if (line_id == 0 || next_id < 0) + return; + + swap_lines(tx, line_id, next_id); + } + tx->update(); + + } break; + case EDIT_MOVE_LINE_DOWN: { + + TextEdit *tx = current->get_text_edit(); + Ref<Script> scr = current->get_edited_script(); + if (scr.is_null()) + return; + + if (tx->is_selection_active()) + { + int from_line = tx->get_selection_from_line(); + int from_col = tx->get_selection_from_column(); + int to_line = tx->get_selection_to_line(); + int to_column = tx->get_selection_to_column(); + + for (int i = to_line; i >= from_line; i--) + { + int line_id = i; + int next_id = i + 1; + + if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) + return; + + swap_lines(tx, line_id, next_id); + } + int from_line_down = from_line < tx->get_line_count() ? from_line+1 : from_line; + int to_line_down = to_line < tx->get_line_count() ? to_line+1 : to_line; + tx->select(from_line_down, from_col, to_line_down, to_column); + } + else + { + int line_id = tx->cursor_get_line(); + int next_id = line_id + 1; + + if (line_id == tx->get_line_count()-1 || next_id > tx->get_line_count()) + return; + + swap_lines(tx, line_id, next_id); + } + tx->update(); + + } break; + case EDIT_INDENT_LEFT: { + + TextEdit *tx = current->get_text_edit(); + Ref<Script> scr = current->get_edited_script(); + if (scr.is_null()) + return; + + int begin, end; + begin = tx->get_selection_from_line(); + if (tx->is_selection_active()) + { + end = tx->get_selection_to_line(); + for (int i = begin; i <= end; i++) + { + String line_text = tx->get_line(i); + // begins with tab + if (line_text.begins_with("\t")) + { + line_text = line_text.substr(1, line_text.length()); + tx->set_line(i, line_text); + } + // begins with 4 spaces + else if (line_text.begins_with(" ")) + { + line_text = line_text.substr(4, line_text.length()); + tx->set_line(i, line_text); + } + } + } + else + { + begin = tx->cursor_get_line(); + String line_text = tx->get_line(begin); + // begins with tab + if (line_text.begins_with("\t")) + { + line_text = line_text.substr(1, line_text.length()); + tx->set_line(begin, line_text); + } + // begins with 4 spaces + else if (line_text.begins_with(" ")) + { + line_text = line_text.substr(4, line_text.length()); + tx->set_line(begin, line_text); + } + } + tx->update(); + //tx->deselect(); + + } break; + case EDIT_INDENT_RIGHT: { + + TextEdit *tx = current->get_text_edit(); + Ref<Script> scr = current->get_edited_script(); + if (scr.is_null()) + return; + + int begin, end; + begin = tx->get_selection_from_line(); + if (tx->is_selection_active()) + { + end = tx->get_selection_to_line(); + for (int i = begin; i <= end; i++) + { + String line_text = tx->get_line(i); + line_text = '\t' + line_text; + tx->set_line(i, line_text); + } + } + else + { + begin = tx->cursor_get_line(); + String line_text = tx->get_line(begin); + line_text = '\t' + line_text; + tx->set_line(begin, line_text); + } + tx->update(); + //tx->deselect(); + + } break; + case EDIT_CLONE_DOWN: { + + TextEdit *tx = current->get_text_edit(); + Ref<Script> scr = current->get_edited_script(); + if (scr.is_null()) + return; + int line = tx->cursor_get_line(); + int next_line = line + 1; + + if (line == tx->get_line_count() || next_line > tx->get_line_count()) + return; + + String line_clone = tx->get_line(line); + tx->insert_at(line_clone, next_line); + tx->update(); + + } break; + case EDIT_TOGGLE_COMMENT: { + + TextEdit *tx = current->get_text_edit(); + Ref<Script> scr = current->get_edited_script(); + if (scr.is_null()) + return; + + int begin, end; + begin = tx->get_selection_from_line(); + if (tx->is_selection_active()) + { + end = tx->get_selection_to_line(); + for (int i = begin; i <= end; i++) + { + String line_text = tx->get_line(i); + + if (line_text.begins_with("#")) + line_text = line_text.substr(1, line_text.length()); + else + line_text = "#" + line_text; + tx->set_line(i, line_text); + } + } + else + { + begin = tx->cursor_get_line(); + String line_text = tx->get_line(begin); + + if (line_text.begins_with("#")) + line_text = line_text.substr(1, line_text.length()); + else + line_text = "#" + line_text; + tx->set_line(begin, line_text); + } + tx->update(); + //tx->deselect(); + + } break; case EDIT_COMPLETE: { current->get_text_edit()->query_code_comple(); @@ -782,9 +1039,12 @@ void ScriptEditor::_menu_option(int p_option) { editor->emit_signal("request_help", text); } break; case WINDOW_CLOSE: { - - erase_tab_confirm->set_text("Close Tab?:\n\""+current->get_name()+"\""); - erase_tab_confirm->popup_centered(Point2(250,80)); + if (current->get_text_edit()->get_version()!=current->get_text_edit()->get_saved_version()) { + erase_tab_confirm->set_text("Close and save changes?\n\""+current->get_name()+"\""); + erase_tab_confirm->popup_centered(Point2(250,80)); + } else { + _close_current_tab(); + } } break; case WINDOW_MOVE_LEFT: { @@ -822,7 +1082,7 @@ void ScriptEditor::_tab_changed(int p_which) { void ScriptEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { editor->connect("play_pressed",this,"_editor_play"); editor->connect("pause_pressed",this,"_editor_pause"); @@ -837,7 +1097,7 @@ void ScriptEditor::_notification(int p_what) { _update_window_menu(); } - if (p_what==NOTIFICATION_EXIT_SCENE) { + if (p_what==NOTIFICATION_EXIT_TREE) { editor->disconnect("play_pressed",this,"_editor_play"); editor->disconnect("pause_pressed",this,"_editor_pause"); @@ -895,7 +1155,7 @@ Dictionary ScriptEditor::get_state() const { } else { - const Node *owner = _find_node_with_script(get_scene()->get_root(),script.get_ref_ptr()); + const Node *owner = _find_node_with_script(get_tree()->get_root(),script.get_ref_ptr()); if (owner) paths.push_back(owner->get_path()); @@ -931,7 +1191,7 @@ void ScriptEditor::set_state(const Dictionary& p_state) { if (source.get_type()==Variant::NODE_PATH) { - Node *owner=get_scene()->get_root()->get_node(source); + Node *owner=get_tree()->get_root()->get_node(source); if (!owner) continue; @@ -1289,7 +1549,7 @@ void ScriptEditor::_add_callback(Object *p_obj, const String& p_function, const int pos = script->get_language()->find_function(p_function,code); if (pos==-1) { //does not exist - + ste->get_text_edit()->deselect(); pos=ste->get_text_edit()->get_line_count()+2; String func = script->get_language()->make_function("",p_function,p_args); //code=code+func; @@ -1327,7 +1587,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { menu_hb->add_child(file_menu); file_menu->set_text("File"); file_menu->get_popup()->add_item("Open",FILE_OPEN); - file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_S); + file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_MASK_CMD|KEY_S); file_menu->get_popup()->add_item("Save As..",FILE_SAVE_AS); file_menu->get_popup()->add_item("Save All",FILE_SAVE_ALL,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_S); file_menu->get_popup()->connect("item_pressed", this,"_menu_option"); @@ -1335,8 +1595,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { edit_menu = memnew( MenuButton ); menu_hb->add_child(edit_menu); edit_menu->set_text("Edit"); - edit_menu->get_popup()->add_item("Undo"); - edit_menu->get_popup()->add_item("Redo"); + edit_menu->get_popup()->add_item("Undo",EDIT_UNDO,KEY_MASK_CMD|KEY_Z); + edit_menu->get_popup()->add_item("Redo",EDIT_REDO,KEY_MASK_CMD|KEY_Y); edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_item("Cut",EDIT_CUT,KEY_MASK_CMD|KEY_X); edit_menu->get_popup()->add_item("Copy",EDIT_COPY,KEY_MASK_CMD|KEY_C); @@ -1344,7 +1604,18 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_item("Select All",EDIT_SELECT_ALL,KEY_MASK_CMD|KEY_A); edit_menu->get_popup()->add_separator(); + edit_menu->get_popup()->add_item("Move Up",EDIT_MOVE_LINE_UP,KEY_MASK_ALT|KEY_UP); + edit_menu->get_popup()->add_item("Move Down",EDIT_MOVE_LINE_DOWN,KEY_MASK_ALT|KEY_DOWN); + edit_menu->get_popup()->add_item("Indent Left",EDIT_INDENT_LEFT,KEY_MASK_ALT|KEY_LEFT); + edit_menu->get_popup()->add_item("Indent Right",EDIT_INDENT_RIGHT,KEY_MASK_ALT|KEY_RIGHT); + edit_menu->get_popup()->add_item("Toggle Comment",EDIT_TOGGLE_COMMENT,KEY_MASK_CMD|KEY_K); + edit_menu->get_popup()->add_item("Clone Down",EDIT_CLONE_DOWN,KEY_MASK_CMD|KEY_B); + edit_menu->get_popup()->add_separator(); +#ifdef OSX_ENABLED + edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CTRL|KEY_SPACE); +#else edit_menu->get_popup()->add_item("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CMD|KEY_SPACE); +#endif edit_menu->get_popup()->add_item("Auto Indent",EDIT_AUTO_INDENT,KEY_MASK_CMD|KEY_I); edit_menu->get_popup()->connect("item_pressed", this,"_menu_option"); @@ -1540,6 +1811,7 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { script_editor->hide(); + EDITOR_DEF("text_editor/auto_reload_changed_scripts",false); EDITOR_DEF("external_editor/use_external_editor",false); EDITOR_DEF("external_editor/exec_path",""); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"external_editor/exec_path",PROPERTY_HINT_GLOBAL_FILE)); diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h index 69b8739d67..136d966587 100644 --- a/tools/editor/plugins/script_editor_plugin.h +++ b/tools/editor/plugins/script_editor_plugin.h @@ -85,7 +85,7 @@ protected: virtual void _validate_script(); - virtual void _code_complete_script(const String& p_code,const String& p_keyword, int p_line, List<String>* r_options); + virtual void _code_complete_script(const String& p_code, List<String>* r_options); virtual void _load_theme_settings(); void _notification(int p_what); @@ -123,6 +123,12 @@ class ScriptEditor : public VBoxContainer { EDIT_SELECT_ALL, EDIT_COMPLETE, EDIT_AUTO_INDENT, + EDIT_TOGGLE_COMMENT, + EDIT_MOVE_LINE_UP, + EDIT_MOVE_LINE_DOWN, + EDIT_INDENT_RIGHT, + EDIT_INDENT_LEFT, + EDIT_CLONE_DOWN, SEARCH_FIND, SEARCH_FIND_NEXT, SEARCH_REPLACE, @@ -212,7 +218,7 @@ public: void get_breakpoints(List<String> *p_breakpoints); - + void swap_lines(TextEdit *tx, int line1, int line2); void save_external_data(); diff --git a/tools/editor/plugins/shader_editor_plugin.cpp b/tools/editor/plugins/shader_editor_plugin.cpp index 17c4291378..2fcd4e8cd1 100644 --- a/tools/editor/plugins/shader_editor_plugin.cpp +++ b/tools/editor/plugins/shader_editor_plugin.cpp @@ -57,9 +57,9 @@ void ShaderTextEditor::set_edited_shader(const Ref<Shader>& p_shader,ShaderLangu _load_theme_settings(); - if (p_type==ShaderLanguage::SHADER_MATERIAL_LIGHT) + if (p_type==ShaderLanguage::SHADER_MATERIAL_LIGHT || p_type==ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT) get_text_edit()->set_text(shader->get_light_code()); - else if (p_type==ShaderLanguage::SHADER_MATERIAL_VERTEX) + else if (p_type==ShaderLanguage::SHADER_MATERIAL_VERTEX || p_type==ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX) get_text_edit()->set_text(shader->get_vertex_code()); else get_text_edit()->set_text(shader->get_fragment_code()); @@ -80,6 +80,8 @@ void ShaderTextEditor::_load_theme_settings() { get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0))); get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1))); get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1))); + get_text_edit()->add_color_override("brace_mismatch_color",EDITOR_DEF("text_editor/brace_mismatch_color",Color(1,0.2,0.2))); + get_text_edit()->add_color_override("current_line_color",EDITOR_DEF("text_editor/current_line_color",Color(0.3,0.5,0.8,0.15))); Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2)); @@ -130,24 +132,22 @@ void ShaderTextEditor::_validate_script() { String errortxt; int line,col; - String code; - if (type==ShaderLanguage::SHADER_MATERIAL_LIGHT) - code=get_text_edit()->get_text(); - else if (type==ShaderLanguage::SHADER_MATERIAL_VERTEX) - code=get_text_edit()->get_text(); - else - code=get_text_edit()->get_text(); - + String code=get_text_edit()->get_text(); //List<StringName> params; //shader->get_param_list(¶ms); + print_line("compile: type: "+itos(type)+" code:\n"+code); + Error err = ShaderLanguage::compile(code,type,NULL,NULL,&errortxt,&line,&col); if (err!=OK) { - String error_text="error("+itos(line)+","+itos(col)+"): "+errortxt; + String error_text="error("+itos(line+1)+","+itos(col)+"): "+errortxt; set_error(error_text); + get_text_edit()->set_line_as_marked(line,true); } else { + for(int i=0;i<get_text_edit()->get_line_count();i++) + get_text_edit()->set_line_as_marked(i,false); set_error(""); } @@ -229,25 +229,7 @@ void ShaderEditor::_menu_option(int p_option) { goto_line_dialog->popup_find_line(current->get_text_edit()); } break; - case SHADER_POST_PROCESS_MODE:{ - - fragment_editor->set_edited_shader(shader,ShaderLanguage::SHADER_POST_PROCESS); - fragment_editor->_validate_script(); - apply_shaders(); - settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), false); - settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), true); - - - } break; - case SHADER_MATERIAL_MODE: { - fragment_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_FRAGMENT); - fragment_editor->_validate_script(); - apply_shaders(); - settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), true); - settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), false); - - } break; } } @@ -258,7 +240,7 @@ void ShaderEditor::_tab_changed(int p_which) { void ShaderEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { close->set_normal_texture( get_icon("Close","EditorIcons")); close->set_hover_texture( get_icon("CloseHover","EditorIcons")); @@ -404,18 +386,17 @@ void ShaderEditor::edit(const Ref<Shader>& p_shader) { shader=p_shader; if (shader->get_mode()==Shader::MODE_MATERIAL) { + vertex_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_MATERIAL_VERTEX); fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_MATERIAL_FRAGMENT); light_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_LIGHT); - settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), true); - settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), false); - } else { + } else if (shader->get_mode()==Shader::MODE_CANVAS_ITEM) { - fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_POST_PROCESS); - settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), false); - settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), true); + vertex_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX); + fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT); + light_editor->set_edited_shader(shader,ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT); } - vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX); + //vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX); // see if already has it @@ -491,15 +472,6 @@ ShaderEditor::ShaderEditor() { search_menu->get_popup()->add_item("Goto Line..",SEARCH_GOTO_LINE,KEY_MASK_CMD|KEY_G); search_menu->get_popup()->connect("item_pressed", this,"_menu_option"); - settings_menu = memnew( MenuButton ); - add_child(settings_menu); - settings_menu->set_pos(Point2(90,-1)); - settings_menu->set_text("Shader"); - settings_menu->get_popup()->add_check_item("Material Mode",SHADER_MATERIAL_MODE); - settings_menu->get_popup()->set_item_checked(settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE),true); - settings_menu->get_popup()->add_check_item("Post Process Mode",SHADER_POST_PROCESS_MODE); - - settings_menu->get_popup()->connect("item_pressed", this,"_menu_option"); tab_container->connect("tab_changed", this,"_tab_changed"); @@ -546,7 +518,13 @@ void ShaderEditorPlugin::edit(Object *p_object) { bool ShaderEditorPlugin::handles(Object *p_object) const { - return p_object->is_type("Shader"); + Shader *shader=p_object->cast_to<Shader>(); + if (!shader) + return false; + if (_2d) + return shader->get_mode()==Shader::MODE_CANVAS_ITEM; + else + return shader->get_mode()==Shader::MODE_MATERIAL; } void ShaderEditorPlugin::make_visible(bool p_visible) { @@ -592,12 +570,15 @@ void ShaderEditorPlugin::apply_changes() { shader_editor->apply_shaders(); } -ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) { +ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node, bool p_2d) { editor=p_node; shader_editor = memnew( ShaderEditor ); - - SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor); + _2d=p_2d; + if (p_2d) + add_custom_control(CONTAINER_CANVAS_EDITOR_BOTTOM,shader_editor); + else + add_custom_control(CONTAINER_SPATIAL_EDITOR_BOTTOM,shader_editor); // editor->get_viewport()->add_child(shader_editor); // shader_editor->set_area_as_parent_rect(); diff --git a/tools/editor/plugins/shader_editor_plugin.h b/tools/editor/plugins/shader_editor_plugin.h index 49caee5da6..daaa0ccb94 100644 --- a/tools/editor/plugins/shader_editor_plugin.h +++ b/tools/editor/plugins/shader_editor_plugin.h @@ -79,9 +79,6 @@ class ShaderEditor : public Control { SEARCH_REPLACE, //SEARCH_LOCATE_SYMBOL, SEARCH_GOTO_LINE, - SHADER_MATERIAL_MODE, - SHADER_POST_PROCESS_MODE, - SHADER_SHADE_MODEL_MODE, }; @@ -134,6 +131,7 @@ class ShaderEditorPlugin : public EditorPlugin { OBJ_TYPE( ShaderEditorPlugin, EditorPlugin ); + bool _2d; ShaderEditor *shader_editor; EditorNode *editor; public: @@ -152,7 +150,7 @@ public: virtual void save_external_data(); virtual void apply_changes(); - ShaderEditorPlugin(EditorNode *p_node); + ShaderEditorPlugin(EditorNode *p_node,bool p_2d); ~ShaderEditorPlugin(); }; diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 2686ca895e..e829c06e6f 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -28,1082 +28,2363 @@ /*************************************************************************/ #include "shader_graph_editor_plugin.h" -#if 0 + #include "scene/gui/menu_button.h" #include "scene/gui/panel.h" +#include "spatial_editor_plugin.h" +#include "os/keyboard.h" +#include "canvas_item_editor_plugin.h" -class _ShaderTester : public ShaderCodeGenerator { -public: +void GraphColorRampEdit::_input_event(const InputEvent& p_event) { - Set<int> *_set; + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { - virtual void begin() {} - virtual Error add_node(VS::ShaderNodeType p_type,int p_node_pos,int p_id,const Variant& p_param,const Vector<int>& p_in_connections,const Vector<int>& p_out_connections,const Vector<int>& p_out_connection_outputs) { if (_set) _set->insert(p_id); return OK; } - virtual void end() {} + points.remove(grabbed); + grabbed=-1; + update(); + emit_signal("ramp_changed"); + accept_event(); + } - _ShaderTester() { _set=NULL; } -}; + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + + update(); + int x = p_event.mouse_button.x; + int total_w = get_size().width-get_size().height-3; + if (x>total_w+3) { + + if (grabbed==-1) + return; + Size2 ms = Size2(350, picker->get_combined_minimum_size().height+10); + picker->set_color(points[grabbed].color); + popup->set_pos(get_global_pos()-Size2(0,ms.height)); + popup->set_size(ms); + popup->popup(); + return; + } + float ofs = CLAMP(x/float(total_w),0,1); -void ShaderEditor::edit(Ref<Shader> p_shader) { + grabbed=-1; + grabbing=true; + int pos=-1; + for(int i=0;i<points.size();i++) { + if (ABS(x-points[i].offset*total_w)<4) { + grabbed=i; + } + if (points[i].offset<ofs) + pos=i; + } - shader=p_shader; + grabbed_at=ofs; + //grab or select + if (grabbed!=-1) { + return; + } + //insert - if (shader.is_null()) - hide(); - else { - _read_shader_graph(); - } -} + Point p; + p.offset=ofs; -Size2 ShaderEditor::_get_maximum_size() { + Point prev; + Point next; - Size2 max; + if (pos==-1) { - for(List<int>::Element *E=order.front();E;E=E->next()) { + prev.color=Color(0,0,0); + prev.offset=0; + if (points.size()) { + next=points[0]; + } else { + next.color=Color(1,1,1); + next.offset=1.0; + } + } else { - Point2 pos = Point2( shader_graph.node_get_pos_x(E->get()), shader_graph.node_get_pos_y(E->get()) ); + if (pos==points.size()-1) { + next.color=Color(1,1,1); + next.offset=1.0; + } else { + next=points[pos+1]; + } + prev=points[pos]; + + } - if (click_type==CLICK_NODE && click_node==E->get()) { + p.color=prev.color.linear_interpolate(next.color,(p.offset-prev.offset)/(next.offset-prev.offset)); - pos+=click_motion-click_pos; + points.push_back(p); + points.sort(); + for(int i=0;i<points.size();i++) { + if (points[i].offset==ofs) { + grabbed=i; + break; + } } - pos+=get_node_size(E->get()); - if (pos.x>max.x) - max.x=pos.x; - if (pos.y>max.y) - max.y=pos.y; + + emit_signal("ramp_changed"); } - return max; -} + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && !p_event.mouse_button.pressed) { -Size2 ShaderEditor::get_node_size(int p_node) const { + if (grabbing) { + grabbing=false; + emit_signal("ramp_changed"); + } + update(); + } - VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node); - Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); - Ref<Font> font = get_font("font","PopupMenu"); - Color font_color = get_color("font_color","PopupMenu"); + if (p_event.type==InputEvent::MOUSE_MOTION && grabbing) { - Size2 size = style->get_minimum_size(); + int total_w = get_size().width-get_size().height-3; - int count=1; // title - count += VisualServer::shader_get_input_count( type) + VisualServer::shader_get_output_count( type); + int x = p_event.mouse_motion.x; + float newofs = CLAMP(x/float(total_w),0,1); - float max_w=font->get_string_size( VisualServer::shader_node_get_type_info(type).name ).width; + bool valid=true; + for(int i=0;i<points.size();i++) { - for(int i=0;i<VisualServer::shader_get_input_count(type);i++) - max_w = MAX( max_w, font->get_string_size( VisualServer::shader_get_input_name(type,i) ).width ); + if (points[i].offset==newofs && i!=grabbed) { + valid=false; + } + } + + if (!valid) + return; + points[grabbed].offset=newofs; - for(int i=0;i<VisualServer::shader_get_output_count(type);i++) - max_w = MAX( max_w, font->get_string_size( VisualServer::shader_get_output_name(type,i) ).width ); + points.sort(); + for(int i=0;i<points.size();i++) { + if (points[i].offset==newofs) { + grabbed=i; + break; + } + } + emit_signal("ramp_changed"); + update(); + } +} +void GraphColorRampEdit::_notification(int p_what){ - switch(type) { + if (p_what==NOTIFICATION_ENTER_TREE) { + picker->connect("color_changed",this,"_color_changed"); + } + if (p_what==NOTIFICATION_DRAW) { - case VS::NODE_IN: - case VS::NODE_OUT: - case VS::NODE_VEC_IN: - case VS::NODE_VEC_OUT: - case VS::NODE_PARAMETER: - case VS::NODE_VEC_PARAMETER: - case VS::NODE_COLOR_PARAMETER: - case VS::NODE_TEXTURE_PARAMETER: - case VS::NODE_TEXTURE_2D_PARAMETER: - case VS::NODE_TEXTURE_CUBE_PARAMETER: - case VS::NODE_TRANSFORM_PARAMETER: - case VS::NODE_LABEL: { - max_w=MAX( max_w, font->get_string_size( shader_graph.node_get_param(p_node) ).width ); - count++; - } break; - case VS::NODE_TIME: - case VS::NODE_CONSTANT: - case VS::NODE_VEC_CONSTANT: - case VS::NODE_COLOR_CONSTANT: - case VS::NODE_TRANSFORM_CONSTANT: { - count++; - } break; - case VS::NODE_TEXTURE: - case VS::NODE_VEC_TEXTURE_2D: - case VS::NODE_VEC_TEXTURE_CUBE: { + Point prev; + prev.offset=0; + prev.color=Color(0,0,0); + int w = get_size().x; + int h = get_size().y; - RefPtr res = shader_graph.node_get_param(p_node); - Ref<Texture> texture = res; - if (texture.is_null() || texture->get_width()==0) { + int total_w = get_size().width-get_size().height-3; - size.y+=max_w; + for(int i=-1;i<points.size();i++) { + + Point next; + if (i+1==points.size()) { + next.color=Color(1,1,1); + next.offset=1; } else { + next=points[i+1]; + } - size.y+=max_w * texture->get_height() / texture->get_width(); + if (prev.offset==next.offset) { + prev=next; + continue; } - } break; - default: {} + Vector<Vector2> points; + Vector<Color> colors; + points.push_back(Vector2(prev.offset*total_w,h)); + points.push_back(Vector2(prev.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,0)); + points.push_back(Vector2(next.offset*total_w,h)); + colors.push_back(prev.color); + colors.push_back(prev.color); + colors.push_back(next.color); + colors.push_back(next.color); + draw_primitive(points,colors,Vector<Point2>()); + prev=next; + } + + for(int i=0;i<points.size();i++) { + + Color col=i==grabbed?Color(1,0.0,0.0,0.9):Color(1,1,1,0.8); + + draw_line(Vector2(points[i].offset*total_w,0),Vector2(points[i].offset*total_w,h-1),Color(0,0,0,0.7)); + draw_line(Vector2(points[i].offset*total_w-1,h/2),Vector2(points[i].offset*total_w-1,h-1),col); + draw_line(Vector2(points[i].offset*total_w+1,h/2),Vector2(points[i].offset*total_w+1,h-1),col); + draw_line(Vector2(points[i].offset*total_w-1,h/2),Vector2(points[i].offset*total_w+1,h/2),col); + draw_line(Vector2(points[i].offset*total_w-1,h-1),Vector2(points[i].offset*total_w+1,h-1),col); + + } + + if (grabbed!=-1) { + + draw_rect(Rect2(total_w+3,0,h,h),points[grabbed].color); + } + + if (has_focus()) { + + draw_line(Vector2(-1,-1),Vector2(total_w+1,-1),Color(1,1,1,0.6)); + draw_line(Vector2(total_w+1,-1),Vector2(total_w+1,h+1),Color(1,1,1,0.6)); + draw_line(Vector2(total_w+1,h+1),Vector2(-1,h+1),Color(1,1,1,0.6)); + draw_line(Vector2(-1,-1),Vector2(-1,h+1),Color(1,1,1,0.6)); + } + + } +} + +Size2 GraphColorRampEdit::get_minimum_size() const { + + return Vector2(0,16); +} + + +void GraphColorRampEdit::_color_changed(const Color& p_color) { + + if (grabbed==-1) + return; + points[grabbed].color=p_color; + update(); + emit_signal("ramp_changed"); + +} + +void GraphColorRampEdit::set_ramp(const Vector<float>& p_offsets,const Vector<Color>& p_colors) { + + ERR_FAIL_COND(p_offsets.size()!=p_colors.size()); + points.clear(); + for(int i=0;i<p_offsets.size();i++) { + Point p; + p.offset=p_offsets[i]; + p.color=p_colors[i]; + points.push_back(p); } - size.x+=max_w; - size.y+=count*(font->get_height()+get_constant("vseparation","PopupMenu")); + points.sort(); + update(); +} - return size; +Vector<float> GraphColorRampEdit::get_offsets() const{ + Vector<float> ret; + for(int i=0;i<points.size();i++) + ret.push_back(points[i].offset); + return ret; } +Vector<Color> GraphColorRampEdit::get_colors() const{ + Vector<Color> ret; + for(int i=0;i<points.size();i++) + ret.push_back(points[i].color); + return ret; +} -Error ShaderEditor::validate_graph() { - _ShaderTester st; - active_nodes.clear(); - st._set=&active_nodes; - return shader_graph.generate(&st); +void GraphColorRampEdit::_bind_methods(){ + + ObjectTypeDB::bind_method(_MD("_input_event"),&GraphColorRampEdit::_input_event); + ObjectTypeDB::bind_method(_MD("_color_changed"),&GraphColorRampEdit::_color_changed); + ADD_SIGNAL(MethodInfo("ramp_changed")); } -void ShaderEditor::_draw_node(int p_node) { +GraphColorRampEdit::GraphColorRampEdit(){ + + grabbed=-1; + grabbing=false; + set_focus_mode(FOCUS_ALL); + + popup = memnew( PopupPanel ); + picker = memnew( ColorPicker ); + popup->add_child(picker); + popup->set_child_rect(picker); + add_child(popup); - VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node); - Ref<StyleBox> style = active_nodes.has(p_node)?get_stylebox("panel","PopupMenu"):get_stylebox("panel_disabled","PopupMenu"); - Ref<Font> font = get_font("font","PopupMenu"); - Color font_color = get_color("font_color","PopupMenu"); - Color font_color_title = get_color("font_color_hover","PopupMenu"); - Size2 size=get_node_size(p_node); - Point2 pos = Point2( shader_graph.node_get_pos_x(p_node), shader_graph.node_get_pos_y(p_node) )-offset; +} +//////////// - if (click_type==CLICK_NODE && click_node==p_node) { +void GraphCurveMapEdit::_input_event(const InputEvent& p_event) { - pos+=click_motion-click_pos; + if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) { + + points.remove(grabbed); + grabbed=-1; + update(); + emit_signal("curve_changed"); + accept_event(); } - RID ci = get_canvas_item(); - style->draw(ci,Rect2(pos,size)); + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) { + + update(); + Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size(); + p.y=1.0-p.y; + grabbed=-1; + grabbing=true; - Point2 ofs=style->get_offset()+pos; - Point2 ascent=Point2(0,font->get_ascent()); - float w = size.width-style->get_minimum_size().width; - float h = font->get_height()+get_constant("vseparation","PopupMenu"); + for(int i=0;i<points.size();i++) { - font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, VisualServer::shader_node_get_type_info(type).name,font_color_title); - ofs.y+=h; + Vector2 ps = p*get_size(); + Vector2 pt = Vector2(points[i].offset,points[i].height)*get_size(); + if (ps.distance_to(pt)<4) { + grabbed=i; + } + + } + + + //grab or select + if (grabbed!=-1) { + return; + } + //insert - Ref<Texture> vec_icon = get_icon("NodeVecSlot","EditorIcons"); - Ref<Texture> real_icon = get_icon("NodeRealSlot","EditorIcons"); - float icon_h_ofs = Math::floor(( font->get_height()-vec_icon->get_height())/2.0 )+1; + Point np; + np.offset=p.x; + np.height=p.y; - for(int i=0;i<VisualServer::shader_get_input_count(type);i++) { + points.push_back(np); + points.sort(); + for(int i=0;i<points.size();i++) { + if (points[i].offset==p.x && points[i].height==p.y) { + grabbed=i; + break; + } + } + + emit_signal("curve_changed"); - String name = VisualServer::shader_get_input_name(type,i); - font->draw_halign( ci, ofs+ascent, HALIGN_LEFT,w, name,font_color); - Ref<Texture> icon = VisualServer::shader_is_input_vector(type,i)?vec_icon:real_icon; - icon->draw(ci,ofs+Point2(-real_icon->get_width(),icon_h_ofs)); - ofs.y+=h; } - for(int i=0;i<VisualServer::shader_get_output_count(type);i++) { + if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && !p_event.mouse_button.pressed) { - String name = VisualServer::shader_get_output_name(type,i); - font->draw_halign( ci, ofs+ascent, HALIGN_RIGHT,w, name,font_color); - Ref<Texture> icon = VisualServer::shader_is_output_vector(type,i)?vec_icon:real_icon; - icon->draw(ci,ofs+Point2(w,icon_h_ofs)); - ofs.y+=h; + if (grabbing) { + grabbing=false; + emit_signal("curve_changed"); + } + update(); } - switch(type) { - - case VS::NODE_IN: - case VS::NODE_OUT: - case VS::NODE_PARAMETER: - case VS::NODE_VEC_IN: - case VS::NODE_COLOR_PARAMETER: - case VS::NODE_VEC_OUT: - case VS::NODE_TEXTURE_PARAMETER: - case VS::NODE_TEXTURE_2D_PARAMETER: - case VS::NODE_TEXTURE_CUBE_PARAMETER: - case VS::NODE_TRANSFORM_CONSTANT: - case VS::NODE_TRANSFORM_PARAMETER: - case VS::NODE_VEC_PARAMETER: - case VS::NODE_LABEL: { - String text = shader_graph.node_get_param(p_node); - font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); - } break; - case VS::NODE_TIME: - case VS::NODE_CONSTANT: { - String text = rtos(shader_graph.node_get_param(p_node)); - font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); + if (p_event.type==InputEvent::MOUSE_MOTION && grabbing && grabbed != -1) { - } break; - case VS::NODE_VEC_CONSTANT: { - String text = Vector3(shader_graph.node_get_param(p_node)); - font->draw_halign( ci, ofs+ascent, HALIGN_CENTER,w, text,font_color); - } break; - case VS::NODE_COLOR_CONSTANT: { + Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size(); + p.y=1.0-p.y; - Color color = shader_graph.node_get_param(p_node); - Rect2 r(ofs,Size2(w,h)); - VisualServer::get_singleton()->canvas_item_add_rect(ci,r,color); - } break; - case VS::NODE_TEXTURE: - case VS::NODE_VEC_TEXTURE_2D: - case VS::NODE_VEC_TEXTURE_CUBE: { - - Rect2 r(ofs,Size2(w,(pos.y+size.y-style->get_margin(MARGIN_BOTTOM))-ofs.y)); - Vector<Point2> points; - Vector<Point2> uvs; - points.resize(4); - uvs.resize(4); - points[0]=r.pos; - points[1]=r.pos+Point2(r.size.x,0); - points[2]=r.pos+r.size; - points[3]=r.pos+Point2(0,r.size.y); - uvs[0]=Point2(0,0); - uvs[1]=Point2(1,0); - uvs[2]=Point2(1,1); - uvs[3]=Point2(0,1); - - Ref<Texture> texture = shader_graph.node_get_param(p_node).operator RefPtr(); - if (texture.is_null() || texture->get_width()==0) { - texture=get_icon("Click2Edit","EditorIcons"); + p.x = CLAMP(p.x,0.0,1.0); + p.y = CLAMP(p.y,0.0,1.0); + + bool valid=true; + + for(int i=0;i<points.size();i++) { + + if (points[i].offset==p.x && points[i].height==p.y && i!=grabbed) { + valid=false; } + } - VisualServer::get_singleton()->canvas_item_add_primitive(ci,points,Vector<Color>(),uvs,texture->get_rid()); - } break; - default: {} + if (!valid) + return; + + points[grabbed].offset=p.x; + points[grabbed].height=p.y; + + points.sort(); + for(int i=0;i<points.size();i++) { + if (points[i].offset==p.x && points[i].height==p.y) { + grabbed=i; + break; + } + } + + emit_signal("curve_changed"); + + update(); } } -void ShaderEditor::_node_param_changed() { +void GraphCurveMapEdit::_plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d) { + + float geometry[4][4]; + float tmp1[4][4]; + float tmp2[4][4]; + float deltas[4][4]; + double x, dx, dx2, dx3; + double y, dy, dy2, dy3; + double d, d2, d3; + int lastx, lasty; + int newx, newy; + int ntimes; + int i,j; + + int xmax=get_size().x; + int ymax=get_size().y; + + /* construct the geometry matrix from the segment */ + for (i = 0; i < 4; i++) { + geometry[i][2] = 0; + geometry[i][3] = 0; + } - shader_graph.node_set_param( click_node,property_editor->get_variant() ); - update(); - _write_shader_graph(); + geometry[0][0] = (p_a[0] * xmax); + geometry[1][0] = (p_b[0] * xmax); + geometry[2][0] = (p_c[0] * xmax); + geometry[3][0] = (p_d[0] * xmax); + + geometry[0][1] = (p_a[1] * ymax); + geometry[1][1] = (p_b[1] * ymax); + geometry[2][1] = (p_c[1] * ymax); + geometry[3][1] = (p_d[1] * ymax); + + /* subdivide the curve ntimes (1000) times */ + ntimes = 4 * xmax; + /* ntimes can be adjusted to give a finer or coarser curve */ + d = 1.0 / ntimes; + d2 = d * d; + d3 = d * d * d; + + /* construct a temporary matrix for determining the forward differencing deltas */ + tmp2[0][0] = 0; tmp2[0][1] = 0; tmp2[0][2] = 0; tmp2[0][3] = 1; + tmp2[1][0] = d3; tmp2[1][1] = d2; tmp2[1][2] = d; tmp2[1][3] = 0; + tmp2[2][0] = 6*d3; tmp2[2][1] = 2*d2; tmp2[2][2] = 0; tmp2[2][3] = 0; + tmp2[3][0] = 6*d3; tmp2[3][1] = 0; tmp2[3][2] = 0; tmp2[3][3] = 0; + + /* compose the basis and geometry matrices */ + + static const float CR_basis[4][4] = + { + { -0.5, 1.5, -1.5, 0.5 }, + { 1.0, -2.5, 2.0, -0.5 }, + { -0.5, 0.0, 0.5, 0.0 }, + { 0.0, 1.0, 0.0, 0.0 }, + }; + + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + tmp1[i][j] = (CR_basis[i][0] * geometry[0][j] + + CR_basis[i][1] * geometry[1][j] + + CR_basis[i][2] * geometry[2][j] + + CR_basis[i][3] * geometry[3][j]); + } + } + /* compose the above results to get the deltas matrix */ + + for (i = 0; i < 4; i++) + { + for (j = 0; j < 4; j++) + { + deltas[i][j] = (tmp2[i][0] * tmp1[0][j] + + tmp2[i][1] * tmp1[1][j] + + tmp2[i][2] * tmp1[2][j] + + tmp2[i][3] * tmp1[3][j]); + } + } + + + /* extract the x deltas */ + x = deltas[0][0]; + dx = deltas[1][0]; + dx2 = deltas[2][0]; + dx3 = deltas[3][0]; + + /* extract the y deltas */ + y = deltas[0][1]; + dy = deltas[1][1]; + dy2 = deltas[2][1]; + dy3 = deltas[3][1]; + + + lastx = CLAMP (x, 0, xmax); + lasty = CLAMP (y, 0, ymax); + +/* if (fix255) + { + cd->curve[cd->outline][lastx] = lasty; + } + else + { + cd->curve_ptr[cd->outline][lastx] = lasty; + if(gb_debug) printf("bender_plot_curve xmax:%d ymax:%d\n", (int)xmax, (int)ymax); + } +*/ + /* loop over the curve */ + for (i = 0; i < ntimes; i++) + { + /* increment the x values */ + x += dx; + dx += dx2; + dx2 += dx3; + + /* increment the y values */ + y += dy; + dy += dy2; + dy2 += dy3; + + newx = CLAMP ((Math::round (x)), 0, xmax); + newy = CLAMP ((Math::round (y)), 0, ymax); + + /* if this point is different than the last one...then draw it */ + if ((lastx != newx) || (lasty != newy)) + { +#if 0 + /* + if(fix255) + { + /* use fixed array size (for the curve graph) */ + cd->curve[cd->outline][newx] = newy; + } + else + { + /* use dynamic allocated curve_ptr (for the real curve) */ + cd->curve_ptr[cd->outline][newx] = newy; + + if(gb_debug) printf("outline: %d cX: %d cY: %d\n", (int)cd->outline, (int)newx, (int)newy); + } +#endif + draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0); + } + + lastx = newx; + lasty = newy; + } } -ShaderEditor::ClickType ShaderEditor::_locate_click(const Point2& p_click,int *p_node_id,int *p_slot_index) const { - Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); - Ref<Texture> real_icon = get_icon("NodeRealSlot","EditorIcons"); - Ref<Font> font = get_font("font","PopupMenu"); - float h = font->get_height()+get_constant("vseparation","PopupMenu"); - float extra_left=MAX( real_icon->get_width()-style->get_margin(MARGIN_LEFT), 0 ); - float extra_right=MAX( real_icon->get_width()-style->get_margin(MARGIN_RIGHT), 0 ); +void GraphCurveMapEdit::_notification(int p_what){ + if (p_what==NOTIFICATION_DRAW) { - for(const List<int>::Element *E=order.back();E;E=E->prev()) { + draw_style_box(get_stylebox("bg","Tree"),Rect2(Point2(),get_size())); - Size2 size=get_node_size(E->get()); - size.width+=extra_left+extra_right; - Point2 pos = Point2( shader_graph.node_get_pos_x(E->get()), shader_graph.node_get_pos_y(E->get()) )-offset; - pos.x-=extra_left; + int w = get_size().x; + int h = get_size().y; - Rect2 rect( pos, size ); - if (!rect.has_point(p_click)) - continue; - VisualServer::ShaderNodeType type=shader_graph.node_get_type(E->get()); - if (p_node_id) - *p_node_id=E->get(); - float y=p_click.y-(pos.y+style->get_margin(MARGIN_TOP)); - if (y<h) - return CLICK_NODE; - y-=h; + Vector2 prev=Vector2(0,0); + Vector2 prev2=Vector2(0,0); - for(int i=0;i<VisualServer::shader_get_input_count(type);i++) { + for(int i=-1;i<points.size();i++) { - if (y<h) { - if (p_slot_index) - *p_slot_index=i; - return CLICK_INPUT_SLOT; + Vector2 next; + Vector2 next2; + if (i+1>=points.size()) { + next=Vector2(1,1); + } else { + next=Vector2(points[i+1].offset,points[i+1].height); } - y-=h; + + if (i+2>=points.size()) { + next2=Vector2(1,1); + } else { + next2=Vector2(points[i+2].offset,points[i+2].height); + } + + /*if (i==-1 && prev.offset==next.offset) { + prev=next; + continue; + }*/ + + _plot_curve(prev2,prev,next,next2); + + prev2=prev; + prev=next; } - for(int i=0;i<VisualServer::shader_get_output_count(type);i++) { + for(int i=0;i<points.size();i++) { - if (y<h) { - if (p_slot_index) - *p_slot_index=i; - return CLICK_OUTPUT_SLOT; - } - y-=h; + Color col=i==grabbed?Color(1,0.0,0.0,0.9):Color(1,1,1,0.8); + + + draw_rect(Rect2( Vector2(points[i].offset,1.0-points[i].height)*get_size()-Vector2(2,2),Vector2(5,5)),col); } - if (p_click.y<(rect.pos.y+rect.size.height-style->get_margin(MARGIN_BOTTOM))) - return CLICK_PARAMETER; - else - return CLICK_NODE; +/* if (grabbed!=-1) { + + draw_rect(Rect2(total_w+3,0,h,h),points[grabbed].color); + } +*/ + if (has_focus()) { + + draw_line(Vector2(-1,-1),Vector2(w+1,-1),Color(1,1,1,0.6)); + draw_line(Vector2(w+1,-1),Vector2(w+1,h+1),Color(1,1,1,0.6)); + draw_line(Vector2(w+1,h+1),Vector2(-1,h+1),Color(1,1,1,0.6)); + draw_line(Vector2(-1,-1),Vector2(-1,h+1),Color(1,1,1,0.6)); + } } +} - return CLICK_NONE; +Size2 GraphCurveMapEdit::get_minimum_size() const { + return Vector2(64,64); } -Point2 ShaderEditor::_get_slot_pos(int p_node_id,bool p_input,int p_slot) { - Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); - float w = get_node_size(p_node_id).width; - Ref<Font> font = get_font("font","PopupMenu"); - float h = font->get_height()+get_constant("vseparation","PopupMenu"); - Ref<Texture> vec_icon = get_icon("NodeVecSlot","EditorIcons"); - Point2 pos = Point2( shader_graph.node_get_pos_x(p_node_id), shader_graph.node_get_pos_y(p_node_id) )-offset; - pos+=style->get_offset(); - pos.y+=h; - if(p_input) { +void GraphCurveMapEdit::set_points(const Vector<Vector2>& p_points) { - pos.y+=p_slot*h; - pos+=Point2( -vec_icon->get_width()/2.0, h/2.0).floor(); - return pos; - } else { - pos.y+=VisualServer::shader_get_input_count( shader_graph.node_get_type(p_node_id ) )*h; + points.clear(); + for(int i=0;i<p_points.size();i++) { + Point p; + p.offset=p_points[i].x; + p.height=p_points[i].y; + points.push_back(p); } - pos.y+=p_slot*h; - pos+=Point2( w-style->get_minimum_size().width+vec_icon->get_width()/2.0, h/2.0).floor(); - - return pos; + points.sort(); + update(); +} +Vector<Vector2> GraphCurveMapEdit::get_points() const { + Vector<Vector2> ret; + for(int i=0;i<points.size();i++) + ret.push_back(Vector2(points[i].offset,points[i].height)); + return ret; } -void ShaderEditor::_node_edit_property(int p_node) { +void GraphCurveMapEdit::_bind_methods(){ - Ref<StyleBox> style = get_stylebox("panel","PopupMenu"); - Size2 size = get_node_size(p_node); - Point2 pos = Point2( shader_graph.node_get_pos_x(p_node), shader_graph.node_get_pos_y(p_node) )-offset; + ObjectTypeDB::bind_method(_MD("_input_event"),&GraphCurveMapEdit::_input_event); + ADD_SIGNAL(MethodInfo("curve_changed")); +} - VisualServer::ShaderNodeType type=shader_graph.node_get_type(p_node); +GraphCurveMapEdit::GraphCurveMapEdit(){ - PropertyInfo ph = VisualServer::get_singleton()->shader_node_get_type_info(type); - if (ph.type==Variant::NIL) - return; - if (ph.type==Variant::_RID) - ph.type=Variant::OBJECT; + grabbed=-1; + grabbing=false; + set_focus_mode(FOCUS_ALL); - property_editor->edit(NULL,ph.name,ph.type,shader_graph.node_get_param(p_node),ph.hint,ph.hint_string); +} - Point2 popup_pos=Point2( pos.x+(size.width-property_editor->get_size().width)/2.0,pos.y+(size.y-style->get_margin(MARGIN_BOTTOM))).floor(); - popup_pos+=get_global_pos(); - property_editor->set_pos(popup_pos); - property_editor->popup(); +////cbacks +/// +void ShaderGraphView::_scalar_const_changed(double p_value,int p_id) { + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Constant",true); + ur->add_do_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,p_value); + ur->add_undo_method(graph.ptr(),"scalar_const_node_set_value",type,p_id,graph->scalar_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } -bool ShaderEditor::has_point(const Point2& p_point) const { +void ShaderGraphView::_vec_const_changed(double p_value, int p_id,Array p_arr){ - int n,si; + Vector3 val; + for(int i=0;i<p_arr.size();i++) { + val[i]=p_arr[i].call("get_val"); + } - return _locate_click(p_point,&n,&si)!=CLICK_NONE; -} + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Constant",true); + ur->add_do_method(graph.ptr(),"vec_const_node_set_value",type,p_id,val); + ur->add_undo_method(graph.ptr(),"vec_const_node_set_value",type,p_id,graph->vec_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; -void ShaderEditor::_input_event(InputEvent p_event) { - - switch(p_event.type) { - - case InputEvent::MOUSE_BUTTON: { - - if (p_event.mouse_button.pressed) { - - - if (p_event.mouse_button.button_index==1) { - click_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); - click_motion=click_pos; - click_type = _locate_click(click_pos,&click_node,&click_slot); - if( click_type!=CLICK_NONE) { - - order.erase(click_node); - order.push_back(click_node); - update(); - } - switch(click_type) { - case CLICK_INPUT_SLOT: { - click_pos=_get_slot_pos(click_node,true,click_slot); - } break; - case CLICK_OUTPUT_SLOT: { - click_pos=_get_slot_pos(click_node,false,click_slot); - } break; - case CLICK_PARAMETER: { - //open editor - _node_edit_property(click_node); - } break; - } - } - if (p_event.mouse_button.button_index==2) { +} +void ShaderGraphView::_rgb_const_changed(const Color& p_color, int p_id){ + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Constant",true); + ur->add_do_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,p_color); + ur->add_undo_method(graph.ptr(),"rgb_const_node_set_value",type,p_id,graph->rgb_const_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; - if (click_type!=CLICK_NONE) { - click_type=CLICK_NONE; - update(); - } else { - // try to disconnect/remove +} +void ShaderGraphView::_scalar_op_changed(int p_op, int p_id){ + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Operator"); + ur->add_do_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"scalar_op_node_set_op",type,p_id,graph->scalar_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; - Point2 rclick_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); - rclick_type = _locate_click(rclick_pos,&rclick_node,&rclick_slot); - if (rclick_type==CLICK_INPUT_SLOT || rclick_type==CLICK_OUTPUT_SLOT) { +} +void ShaderGraphView::_vec_op_changed(int p_op, int p_id){ + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Operator"); + ur->add_do_method(graph.ptr(),"vec_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"vec_op_node_set_op",type,p_id,graph->vec_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; +} +void ShaderGraphView::_vec_scalar_op_changed(int p_op, int p_id){ + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change VecxScalar Operator"); + ur->add_do_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"vec_scalar_op_node_set_op",type,p_id,graph->vec_scalar_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; - node_popup->clear(); - node_popup->add_item("Disconnect",NODE_DISCONNECT); - node_popup->set_pos(rclick_pos); - node_popup->popup(); +} +void ShaderGraphView::_rgb_op_changed(int p_op, int p_id){ + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Operator"); + ur->add_do_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,p_op); + ur->add_undo_method(graph.ptr(),"rgb_op_node_set_op",type,p_id,graph->rgb_op_node_get_op(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; +} +void ShaderGraphView::_xform_inv_rev_changed(bool p_enabled, int p_id){ + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Toggle Rot Only"); + ur->add_do_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,p_enabled); + ur->add_undo_method(graph.ptr(),"xform_vec_mult_node_set_no_translation",type,p_id,graph->xform_vec_mult_node_get_no_translation(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; +} +void ShaderGraphView::_scalar_func_changed(int p_func, int p_id){ + + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Function"); + ur->add_do_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,p_func); + ur->add_undo_method(graph.ptr(),"scalar_func_node_set_function",type,p_id,graph->scalar_func_node_get_function(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; +} +void ShaderGraphView::_vec_func_changed(int p_func, int p_id){ + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Function"); + ur->add_do_method(graph.ptr(),"vec_func_node_set_function",type,p_id,p_func); + ur->add_undo_method(graph.ptr(),"vec_func_node_set_function",type,p_id,graph->vec_func_node_get_function(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; - } +} +void ShaderGraphView::_scalar_input_changed(double p_value,int p_id){ + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Scalar Uniform",true); + ur->add_do_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,p_value); + ur->add_undo_method(graph.ptr(),"scalar_input_node_set_value",type,p_id,graph->scalar_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; - if (rclick_type==CLICK_NODE) { - node_popup->clear(); - node_popup->add_item("Remove",NODE_ERASE); - node_popup->set_pos(rclick_pos); - node_popup->popup(); - } +} +void ShaderGraphView::_vec_input_changed(double p_value, int p_id,Array p_arr){ + Vector3 val; + for(int i=0;i<p_arr.size();i++) { + val[i]=p_arr[i].call("get_val"); + } - } - } - } else { + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Vec Uniform",true); + ur->add_do_method(graph.ptr(),"vec_input_node_set_value",type,p_id,val); + ur->add_undo_method(graph.ptr(),"vec_input_node_set_value",type,p_id,graph->vec_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; - if (p_event.mouse_button.button_index==1 && click_type!=CLICK_NONE) { +} +void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){ - switch(click_type) { - case CLICK_INPUT_SLOT: - case CLICK_OUTPUT_SLOT: { - Point2 dst_click_pos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); - int id; - int slot; - ClickType dst_click_type = _locate_click(dst_click_pos,&id,&slot); - if (dst_click_type==CLICK_INPUT_SLOT && click_type==CLICK_OUTPUT_SLOT) { + ToolButton *tb = p_button->cast_to<ToolButton>(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_input_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); + ped_popup->popup(); - shader_graph.connect(click_node,click_slot,id,slot); +} +void ShaderGraphView::_xform_const_changed(int p_id, Node *p_button){ - Error err = validate_graph(); - if (err==ERR_CYCLIC_LINK) - shader_graph.disconnect(click_node,click_slot,id,slot); - _write_shader_graph(); + ToolButton *tb = p_button->cast_to<ToolButton>(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::TRANSFORM,graph->xform_const_node_get_value(type,p_id),PROPERTY_HINT_NONE,""); + ped_popup->popup(); - } - if (click_type==CLICK_INPUT_SLOT && dst_click_type==CLICK_OUTPUT_SLOT) { +} - shader_graph.connect(id,slot,click_node,click_slot); +void ShaderGraphView::_rgb_input_changed(const Color& p_color, int p_id){ - Error err = validate_graph(); - if (err==ERR_CYCLIC_LINK) - shader_graph.disconnect(id,slot,click_node,click_slot); - _write_shader_graph(); - } - } break; - case CLICK_NODE: { - int new_x=shader_graph.node_get_pos_x(click_node)+(click_motion.x-click_pos.x); - int new_y=shader_graph.node_get_pos_y(click_node)+(click_motion.y-click_pos.y); - shader_graph.node_set_pos(click_node,new_x,new_y); - _write_shader_graph(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change RGB Uniform",true); + ur->add_do_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,p_color); + ur->add_undo_method(graph.ptr(),"rgb_input_node_set_value",type,p_id,graph->rgb_input_node_get_value(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; +} +void ShaderGraphView::_tex_input_change(int p_id, Node *p_button){ - } break; - } - click_type=CLICK_NONE; - update(); - } - } +} +void ShaderGraphView::_cube_input_change(int p_id){ - } - case InputEvent::MOUSE_MOTION: { +} - if (p_event.mouse_motion.button_mask&1 && click_type!=CLICK_NONE) { +void ShaderGraphView::_variant_edited() { - click_motion=Point2(p_event.mouse_button.x,p_event.mouse_button.y); - update(); - } + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_CONST) { - } break; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change XForm Uniform"); + ur->add_do_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"xform_const_node_set_value",type,edited_id,graph->xform_const_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); } -} -void ShaderEditor::_notification(int p_what) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_XFORM_INPUT) { - switch(p_what) { + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change XForm Uniform"); + ur->add_do_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"xform_input_node_set_value",type,edited_id,graph->xform_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - case NOTIFICATION_DRAW: { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_TEXTURE_INPUT) { - _update_scrollbars(); - //VisualServer::get_singleton()->canvas_item_add_rect(get_canvas_item(),Rect2(Point2(),get_size()),Color(0,0,0,1)); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Texture Uniform"); + ur->add_do_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"texture_input_node_set_value",type,edited_id,graph->texture_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - for(List<int>::Element *E=order.front();E;E=E->next()) { + if (graph->node_get_type(type,edited_id)==ShaderGraph::NODE_CUBEMAP_INPUT) { - _draw_node(E->get()); - } + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Cubemap Uniform"); + ur->add_do_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,ped_popup->get_variant()); + ur->add_undo_method(graph.ptr(),"cubemap_input_node_set_value",type,edited_id,graph->cubemap_input_node_get_value(type,edited_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + } - if (click_type==CLICK_INPUT_SLOT || click_type==CLICK_OUTPUT_SLOT) { +} - VisualServer::get_singleton()->canvas_item_add_line(get_canvas_item(),click_pos,click_motion,Color(0.5,1,0.5,0.8),2); - } +void ShaderGraphView::_comment_edited(int p_id,Node* p_button) { - List<ShaderGraph::Connection> connections = shader_graph.get_connection_list(); - for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) { + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + TextEdit *te=p_button->cast_to<TextEdit>(); + ur->create_action("Change Comment",true); + ur->add_do_method(graph.ptr(),"comment_node_set_text",type,p_id,te->get_text()); + ur->add_undo_method(graph.ptr(),"comment_node_set_text",type,p_id,graph->comment_node_get_text(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; - const ShaderGraph::Connection &c=E->get(); - Point2 source = _get_slot_pos(c.src_id,false,c.src_slot); - Point2 dest = _get_slot_pos(c.dst_id,true,c.dst_slot); - bool vec = VisualServer::shader_is_input_vector( shader_graph.node_get_type(c.dst_id), c.dst_slot ); - Color col = vec?Color(1,0.5,0.5,0.8):Color(1,1,0.5,0.8); +} - if (click_type==CLICK_NODE && click_node==c.src_id) { +void ShaderGraphView::_color_ramp_changed(int p_id,Node* p_ramp) { - source+=click_motion-click_pos; - } + GraphColorRampEdit *cr=p_ramp->cast_to<GraphColorRampEdit>(); - if (click_type==CLICK_NODE && click_node==c.dst_id) { + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - dest+=click_motion-click_pos; - } - VisualServer::get_singleton()->canvas_item_add_line(get_canvas_item(),source,dest,col,2); + Vector<float> offsets=cr->get_offsets(); + Vector<Color> colors=cr->get_colors(); + + DVector<float> new_offsets; + DVector<Color> new_colors; + { + new_offsets.resize(offsets.size()); + new_colors.resize(colors.size()); + DVector<float>::Write ow=new_offsets.write(); + DVector<Color>::Write cw=new_colors.write(); + for(int i=0;i<new_offsets.size();i++) { + ow[i]=offsets[i]; + cw[i]=colors[i]; + } - } - } break; } -} -void ShaderEditor::_update_scrollbars() { + DVector<float> old_offsets=graph->color_ramp_node_get_offsets(type,p_id); + DVector<Color> old_colors=graph->color_ramp_node_get_colors(type,p_id); - Size2 size = get_size(); - Size2 hmin = h_scroll->get_minimum_size(); - Size2 vmin = v_scroll->get_minimum_size(); + if (old_offsets.size()!=new_offsets.size()) + ur->create_action("Add/Remove to Color Ramp"); + else + ur->create_action("Modify Color Ramp",true); - v_scroll->set_begin( Point2(size.width - vmin.width, 0) ); - v_scroll->set_end( Point2(size.width, size.height) ); + ur->add_do_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,new_colors,new_offsets); + ur->add_undo_method(graph.ptr(),"color_ramp_node_set_ramp",type,p_id,old_colors,old_offsets); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; +} - h_scroll->set_begin( Point2( 0, size.height - hmin.height) ); - h_scroll->set_end( Point2(size.width-vmin.width, size.height) ); +void ShaderGraphView::_curve_changed(int p_id,Node* p_curve) { + GraphCurveMapEdit *cr=p_curve->cast_to<GraphCurveMapEdit>(); - Size2 min = _get_maximum_size(); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - if (min.height < size.height - hmin.height) { - v_scroll->hide(); - offset.y=0; - } else { + Vector<Point2> points=cr->get_points(); + + DVector<Vector2> new_points; + { + new_points.resize(points.size()); + DVector<Vector2>::Write ow=new_points.write(); + for(int i=0;i<new_points.size();i++) { + ow[i]=points[i]; + } - v_scroll->show(); - v_scroll->set_max(min.height); - v_scroll->set_page(size.height - hmin.height); - offset.y=v_scroll->get_val(); } - if (min.width < size.width - vmin.width) { - h_scroll->hide(); - offset.x=0; - } else { + DVector<Vector2> old_points=graph->curve_map_node_get_points(type,p_id); - h_scroll->show(); - h_scroll->set_max(min.width); - h_scroll->set_page(size.width - vmin.width); - offset.x=h_scroll->get_val(); - } + if (old_points.size()!=new_points.size()) + ur->create_action("Add/Remove to Curve Map"); + else + ur->create_action("Modify Curve Map",true); + + ur->add_do_method(graph.ptr(),"curve_map_node_set_points",type,p_id,new_points); + ur->add_undo_method(graph.ptr(),"curve_map_node_set_points",type,p_id,old_points); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; } -void ShaderEditor::_scroll_moved() { - offset.x=h_scroll->get_val(); - offset.y=v_scroll->get_val(); - update(); +void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node *p_line_edit) { + + LineEdit *le=p_line_edit->cast_to<LineEdit>(); + ERR_FAIL_COND(!le); + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Change Input Name"); + ur->add_do_method(graph.ptr(),"input_node_set_name",type,p_id,p_name); + ur->add_undo_method(graph.ptr(),"input_node_set_name",type,p_id,graph->input_node_get_name(type,p_id)); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + block_update=true; + ur->commit_action(); + block_update=false; + le->set_text(graph->input_node_get_name(type,p_id)); +} + +void ShaderGraphView::_tex_edited(int p_id,Node* p_button) { + + ToolButton *tb = p_button->cast_to<ToolButton>(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::OBJECT,graph->texture_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"Texture"); } -void ShaderEditor::_bind_methods() { +void ShaderGraphView::_cube_edited(int p_id,Node* p_button) { - ObjectTypeDB::bind_method( "_node_menu_item", &ShaderEditor::_node_menu_item ); - ObjectTypeDB::bind_method( "_node_add_callback", &ShaderEditor::_node_add_callback ); - ObjectTypeDB::bind_method( "_input_event", &ShaderEditor::_input_event ); - ObjectTypeDB::bind_method( "_node_param_changed", &ShaderEditor::_node_param_changed ); - ObjectTypeDB::bind_method( "_scroll_moved", &ShaderEditor::_scroll_moved ); - ObjectTypeDB::bind_method( "_vertex_item", &ShaderEditor::_vertex_item ); - ObjectTypeDB::bind_method( "_fragment_item", &ShaderEditor::_fragment_item ); - ObjectTypeDB::bind_method( "_post_item", &ShaderEditor::_post_item ); + ToolButton *tb = p_button->cast_to<ToolButton>(); + ped_popup->set_pos(tb->get_global_pos()+Vector2(0,tb->get_size().height)); + ped_popup->set_size(tb->get_size()); + edited_id=p_id; + ped_popup->edit(NULL,"",Variant::OBJECT,graph->cubemap_input_node_get_value(type,p_id),PROPERTY_HINT_RESOURCE_TYPE,"CubeMap"); } -void ShaderEditor::_read_shader_graph() { - shader_graph.clear();; - order.clear(); - List<int> nodes; - shader->get_node_list(&nodes); - int larger_id=0; - for(List<int>::Element *E=nodes.front();E;E=E->next()) { +//////////////view///////////// + + +void ShaderGraphView::_connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot) { + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - if (E->get() > larger_id) - larger_id = E->get(); + int from_idx=-1; + int to_idx=-1; + for (Map<int,GraphNode*>::Element *E=node_map.front();E;E=E->next()) { - shader_graph.node_add( (VS::ShaderNodeType)shader->node_get_type(E->get()), E->get() ); - shader_graph.node_set_param( E->get(), shader->node_get_param( E->get() ) ); - Point2 pos = shader->node_get_pos(E->get()); - shader_graph.node_set_pos( E->get(), pos.x,pos.y ); - order.push_back(E->get()); + if (p_from==E->get()->get_name()) + from_idx=E->key(); + if (p_to==E->get()->get_name()) + to_idx=E->key(); } - last_id=larger_id+1; + ERR_FAIL_COND(from_idx==-1); + ERR_FAIL_COND(to_idx==-1); - List<Shader::Connection> connections; - shader->get_connections(&connections); + ur->create_action("Connect Graph Nodes"); - for(List<Shader::Connection>::Element *E=connections.front();E;E=E->next()) { + List<ShaderGraph::Connection> conns; - Shader::Connection &c=E->get(); - shader_graph.connect(c.src_id,c.src_slot,c.dst_id,c.dst_slot); + graph->get_node_connections(type,&conns); + //disconnect/reconnect dependencies + ur->add_undo_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + for(List<ShaderGraph::Connection>::Element *E=conns.front();E;E=E->next()) { + + if (E->get().dst_id==to_idx && E->get().dst_slot==p_to_slot) { + ur->add_do_method(graph.ptr(),"disconnect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + } } + ur->add_do_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + - validate_graph(); - update(); } -void ShaderEditor::_write_shader_graph() { +void ShaderGraphView::_disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot) { + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); - shader->clear(); - List<int> nodes; - shader_graph.get_node_list(&nodes); - for(List<int>::Element *E=nodes.front();E;E=E->next()) { + int from_idx=-1; + int to_idx=-1; + for (Map<int,GraphNode*>::Element *E=node_map.front();E;E=E->next()) { - shader->node_add((Shader::NodeType)shader_graph.node_get_type(E->get()),E->get()); - shader->node_set_param(E->get(),shader_graph.node_get_param(E->get())); - shader->node_set_pos(E->get(),Point2( shader_graph.node_get_pos_x(E->get()),shader_graph.node_get_pos_y(E->get()) ) ); + if (p_from==E->get()->get_name()) + from_idx=E->key(); + if (p_to==E->get()->get_name()) + to_idx=E->key(); } - List<ShaderGraph::Connection> connections = shader_graph.get_connection_list(); - for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) { + ERR_FAIL_COND(from_idx==-1); + ERR_FAIL_COND(to_idx==-1); - const ShaderGraph::Connection &c=E->get(); - shader->connect(c.src_id,c.src_slot,c.dst_id,c.dst_slot); - } -} + if (!graph->is_node_connected(type,from_idx,p_from_slot,to_idx,p_to_slot)) + return; //nothing to disconnect -void ShaderEditor::_add_node_from_text(const String& p_text) { + ur->create_action("Disconnect Graph Nodes"); - ERR_FAIL_COND( p_text.get_slice_count(" ") != 3 ); - bool input = p_text.get_slice(" ",0)=="In:"; - String name = p_text.get_slice(" ",1); - bool vec = p_text.get_slice(" ",2)=="(vec3)"; + List<ShaderGraph::Connection> conns; + + graph->get_node_connections(type,&conns); + //disconnect/reconnect dependencies + ur->add_do_method(graph.ptr(),"disconnect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_undo_method(graph.ptr(),"connect_node",type,from_idx,p_from_slot,to_idx,p_to_slot); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); - _node_add( input? - ( vec? VisualServer::NODE_VEC_IN : VisualServer::NODE_IN ) : - ( vec? VisualServer::NODE_VEC_OUT : VisualServer::NODE_OUT ) ); - shader_graph.node_set_param( last_id-1,name ); - _write_shader_graph(); } -void ShaderEditor::_vertex_item(int p_item) { +void ShaderGraphView::_node_removed(int p_id) { + + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Remove Shader Graph Node"); + + ur->add_do_method(graph.ptr(),"node_remove",type,p_id); + ur->add_undo_method(graph.ptr(),"node_add",type,graph->node_get_type(type,p_id),p_id); + ur->add_undo_method(graph.ptr(),"node_set_state",type,p_id,graph->node_get_state(type,p_id)); + List<ShaderGraph::Connection> conns; + + graph->get_node_connections(type,&conns); + for(List<ShaderGraph::Connection>::Element *E=conns.front();E;E=E->next()) { + + if (E->get().dst_id==p_id || E->get().src_id==p_id) { + ur->add_undo_method(graph.ptr(),"connect_node",type,E->get().src_id,E->get().src_slot,E->get().dst_id,E->get().dst_slot); + } + } + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); - _add_node_from_text(vertex_popup->get_item_text(p_item)); } -void ShaderEditor::_fragment_item(int p_item) { - _add_node_from_text(fragment_popup->get_item_text(p_item)); +void ShaderGraphView::_node_moved(const Vector2& p_from, const Vector2& p_to,int p_id) { + + + ERR_FAIL_COND(!node_map.has(p_id)); + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Move Shader Graph Node"); + ur->add_do_method(this,"_move_node",p_id,p_to); + ur->add_undo_method(this,"_move_node",p_id,p_from); + ur->commit_action(); } -void ShaderEditor::_post_item(int p_item) { - _add_node_from_text(post_popup->get_item_text(p_item)); +void ShaderGraphView::_move_node(int p_id,const Vector2& p_to) { + + ERR_FAIL_COND(!node_map.has(p_id)); + node_map[p_id]->set_offset(p_to); + graph->node_set_pos(type,p_id,p_to); } -void ShaderEditor::_node_menu_item(int p_item) { +void ShaderGraphView::_create_node(int p_id) { - switch(p_item) { - case GRAPH_ADD_NODE: { - add_popup->popup_centered_ratio(); - validate_graph(); - } break; - case NODE_DISCONNECT: { + GraphNode *gn = memnew( GraphNode ); + gn->set_show_close_button(true); + Color typecol[4]={ + Color(0.9,0.4,1), + Color(0.8,1,0.2), + Color(1,0.2,0.2), + Color(0,1,1) + }; + - if (rclick_type==CLICK_INPUT_SLOT) { + switch(graph->node_get_type(type,p_id)) { - List<ShaderGraph::Connection> connections = shader_graph.get_connection_list(); - for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) { + case ShaderGraph::NODE_INPUT: { - const ShaderGraph::Connection &c=E->get(); - if( c.dst_id==rclick_node && c.dst_slot==rclick_slot) { + gn->set_title("Input"); - shader_graph.disconnect(c.src_id,c.src_slot,c.dst_id,c.dst_slot); - } + List<ShaderGraph::SlotInfo> si; + ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); + + int idx=0; + for (List<ShaderGraph::SlotInfo>::Element *E=si.front();E;E=E->next()) { + ShaderGraph::SlotInfo& s=E->get(); + if (s.dir==ShaderGraph::SLOT_IN) { + + Label *l= memnew( Label ); + l->set_text(s.name); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + gn->set_slot(idx,false,0,Color(),true,s.type,typecol[s.type]); + idx++; } - update(); - _write_shader_graph(); - validate_graph(); } - if (rclick_type==CLICK_OUTPUT_SLOT) { + } break; // all inputs (case Shader type dependent) + case ShaderGraph::NODE_SCALAR_CONST: { + gn->set_title("Scalar"); + SpinBox *sb = memnew( SpinBox ); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->scalar_const_node_get_value(type,p_id)); + sb->connect("value_changed",this,"_scalar_const_changed",varray(p_id)); + gn->add_child(sb); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; //scalar constant + case ShaderGraph::NODE_VEC_CONST: { + + gn->set_title("Vector"); + Array v3p(true); + for(int i=0;i<3;i++) { + HBoxContainer *hbc = memnew( HBoxContainer ); + Label *l = memnew( Label ); + l->set_text(String::chr('X'+i)); + hbc->add_child(l); + SpinBox *sb = memnew( SpinBox ); + sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->vec_const_node_get_value(type,p_id)[i]); + sb->connect("value_changed",this,"_vec_const_changed",varray(p_id,v3p)); + v3p.push_back(sb); + hbc->add_child(sb); + gn->add_child(hbc); + } + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; //vec3 constant + case ShaderGraph::NODE_RGB_CONST: { + + gn->set_title("Color"); + ColorPickerButton *cpb = memnew( ColorPickerButton ); + cpb->set_color(graph->rgb_const_node_get_value(type,p_id)); + cpb->connect("color_changed",this,"_rgb_const_changed",varray(p_id)); + gn->add_child(cpb); + Label *l = memnew( Label ); + l->set_text("RGB"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; //rgb constant (shows a color picker instead) + case ShaderGraph::NODE_XFORM_CONST: { + gn->set_title("XForm"); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_xform_const_changed",varray(p_id,edit)); + gn->add_child(edit); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + + } break; // 4x4 matrix constant + case ShaderGraph::NODE_TIME: { + + gn->set_title("Time"); + Label *l = memnew( Label ); + l->set_text("(s)"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + gn->set_slot(0,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // time in seconds + case ShaderGraph::NODE_SCREEN_TEX: { + + gn->set_title("ScreenTex"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("RGB"))); + gn->add_child(hbc); + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) + case ShaderGraph::NODE_SCALAR_OP: { + + gn->set_title("ScalarOp"); + static const char* op_name[ShaderGraph::SCALAR_MAX_OP]={ + "Add", + "Sub", + "Mul", + "Div", + "Mod", + "Pow", + "Max", + "Min", + "Atan2" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;i<ShaderGraph::SCALAR_MAX_OP;i++) { + + ob->add_item(op_name[i],i); + } + + ob->select(graph->scalar_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_scalar_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // scalar vs scalar op (mul: { } break; add: { } break; div: { } break; etc) + case ShaderGraph::NODE_VEC_OP: { + + gn->set_title("VecOp"); + static const char* op_name[ShaderGraph::VEC_MAX_OP]={ + "Add", + "Sub", + "Mul", + "Div", + "Mod", + "Pow", + "Max", + "Min", + "Cross" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;i<ShaderGraph::VEC_MAX_OP;i++) { + + ob->add_item(op_name[i],i); + } - List<ShaderGraph::Connection> connections = shader_graph.get_connection_list(); - for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) { + ob->select(graph->vec_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_vec_op_changed",varray(p_id)); + gn->add_child(ob); - const ShaderGraph::Connection &c=E->get(); - if( c.src_id==rclick_node && c.src_slot==rclick_slot) { + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); - shader_graph.disconnect(c.src_id,c.src_slot,c.dst_id,c.dst_slot); - } - } - update(); - _write_shader_graph(); - validate_graph(); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + + } break; // vec3 vs vec3 op (mul: { } break;ad: { } break;div: { } break;crossprod: { } break;etc) + case ShaderGraph::NODE_VEC_SCALAR_OP: { + + gn->set_title("VecScalarOp"); + static const char* op_name[ShaderGraph::VEC_SCALAR_MAX_OP]={ + "Mul", + "Div", + "Pow", + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;i<ShaderGraph::VEC_SCALAR_MAX_OP;i++) { + + ob->add_item(op_name[i],i); } - } break; - case NODE_ERASE: { + ob->select(graph->vec_scalar_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_vec_scalar_op_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // vec3 vs scalar op (mul: { } break; add: { } break; div: { } break; etc) + case ShaderGraph::NODE_RGB_OP: { + + gn->set_title("RGB Op"); + static const char* op_name[ShaderGraph::RGB_MAX_OP]={ + "Screen", + "Difference", + "Darken", + "Lighten", + "Overlay", + "Dodge", + "Burn", + "SoftLight", + "HardLight" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;i<ShaderGraph::RGB_MAX_OP;i++) { + + ob->add_item(op_name[i],i); + } - order.erase(rclick_node); - shader_graph.node_remove(rclick_node); - update(); - _write_shader_graph(); - validate_graph(); - } break; - case GRAPH_CLEAR: { + ob->select(graph->rgb_op_node_get_op(type,p_id)); + ob->connect("item_selected",this,"_rgb_op_changed",varray(p_id)); + gn->add_child(ob); - order.clear(); - shader_graph.clear(); - last_id=1; - last_x=20; - last_y=20; - update(); - _write_shader_graph(); - validate_graph(); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); - } break; - } -} + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); -void ShaderEditor::_node_add(VisualServer::ShaderNodeType p_type) { + } break; // vec3 vs vec3 rgb op (with scalar amount): { } break; like brighten: { } break; darken: { } break; burn: { } break; dodge: { } break; multiply: { } break; etc. + case ShaderGraph::NODE_XFORM_MULT: { - shader_graph.node_add(p_type,last_id ); - shader_graph.node_set_pos(last_id ,last_x,last_y); - String test_param; + gn->set_title("XFMult"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); - switch(p_type) { - case VS::NODE_PARAMETER: { + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],false,0,Color()); - test_param="param"; - } break; - case VS::NODE_VEC_PARAMETER: { - test_param="vec"; - } break; - case VS::NODE_COLOR_PARAMETER: { + } break; // mat4 x mat4 + case ShaderGraph::NODE_XFORM_VEC_MULT: { - test_param="color"; - } break; - case VS::NODE_TEXTURE_PARAMETER: { + gn->set_title("XFVecMult"); - test_param="tex"; - } break; - case VS::NODE_TEXTURE_2D_PARAMETER: { + Button *button = memnew( Button("RotOnly")); + button->set_toggle_mode(true); + button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); + button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); - test_param="tex2D"; - } break; - case VS::NODE_TEXTURE_CUBE_PARAMETER: { + gn->add_child(button); - test_param="cubemap"; - } break; - case VS::NODE_TRANSFORM_PARAMETER: { - test_param="xform"; - } break; - case VS::NODE_LABEL: { + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l = memnew(Label("out")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + gn->add_child( memnew(Label("vec"))); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); - test_param="label"; } break; - } + case ShaderGraph::NODE_XFORM_VEC_INV_MULT: { + + gn->set_title("XFVecInvMult"); + + + Button *button = memnew( Button("RotOnly")); + button->set_toggle_mode(true); + button->set_pressed(graph->xform_vec_mult_node_get_no_translation(type,p_id)); + button->connect("toggled",this,"_xform_inv_rev_changed",varray(p_id)); + + gn->add_child(button); + + gn->add_child( memnew(Label("vec"))); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l = memnew(Label("out")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + + } break; // mat4 x vec3 inverse mult (with no-translation option) + case ShaderGraph::NODE_SCALAR_FUNC: { + + gn->set_title("ScalarFunc"); + static const char* func_name[ShaderGraph::SCALAR_MAX_FUNC]={ + "Sin", + "Cos", + "Tan", + "ASin", + "ACos", + "ATan", + "SinH", + "CosH", + "TanH", + "Log", + "Exp", + "Sqrt", + "Abs", + "Sign", + "Floor", + "Round", + "Ceil", + "Frac", + "Satr", + "Neg" + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;i<ShaderGraph::SCALAR_MAX_FUNC;i++) { + + ob->add_item(func_name[i],i); + } + + ob->select(graph->scalar_func_node_get_function(type,p_id)); + ob->connect("item_selected",this,"_scalar_func_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar function (sin: { } break; cos: { } break; etc) + case ShaderGraph::NODE_VEC_FUNC: { + + + + gn->set_title("VecFunc"); + static const char* func_name[ShaderGraph::VEC_MAX_FUNC]={ + "Normalize", + "Saturate", + "Negate", + "Reciprocal", + "RGB to HSV", + "HSV to RGB", + }; + + OptionButton *ob = memnew( OptionButton ); + for(int i=0;i<ShaderGraph::VEC_MAX_FUNC;i++) { + + ob->add_item(func_name[i],i); + } + + ob->select(graph->vec_func_node_get_function(type,p_id)); + ob->connect("item_selected",this,"_vec_func_changed",varray(p_id)); + gn->add_child(ob); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("out"))); + gn->add_child(hbc); + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // vector function (normalize: { } break; negate: { } break; reciprocal: { } break; rgb2hsv: { } break; hsv2rgb: { } break; etc: { } break; etc) + case ShaderGraph::NODE_VEC_LEN: { + gn->set_title("VecLength"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("in"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("len"))); + gn->add_child(hbc); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // vec3 length + case ShaderGraph::NODE_DOT_PROD: { + + gn->set_title("DotProduct"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("dp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; // vec3 . vec3 (dot product -> scalar output) + case ShaderGraph::NODE_VEC_TO_SCALAR: { + + gn->set_title("Vec2Scalar"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("vec"))); + hbc->add_spacer(); + Label *l=memnew(Label("x")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("y")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l ); + l=memnew(Label("z")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + + + } break; // 1 vec3 input: { } break; 3 scalar outputs + case ShaderGraph::NODE_SCALAR_TO_VEC: { + + gn->set_title("Scalar2Vec"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("x"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("vec"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("y"))); + gn->add_child( memnew(Label("z"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + } break; // 3 scalar input: { } break; 1 vec3 output + case ShaderGraph::NODE_VEC_TO_XFORM: { + + gn->set_title("Vec2XForm"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("x"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("xf"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("y"))); + gn->add_child( memnew(Label("z"))); + gn->add_child( memnew(Label("ofs"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + + } break; // 3 vec input: { } break; 1 xform output + case ShaderGraph::NODE_XFORM_TO_VEC: { + + gn->set_title("XForm2Vec"); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("xf"))); + hbc->add_spacer(); + Label *l=memnew(Label("x")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("y")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l ); + l=memnew(Label("z")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + l=memnew(Label("ofs")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // 3 vec input: { } break; 1 xform output + case ShaderGraph::NODE_SCALAR_INTERP: { + + gn->set_title("ScalarInterp"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("interp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + gn->add_child( memnew(Label("c"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + + } break; // scalar interpolation (with optional curve) + case ShaderGraph::NODE_VEC_INTERP: { + + gn->set_title("VecInterp"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_child( memnew(Label("a"))); + hbc->add_spacer(); + hbc->add_child( memnew(Label("interp"))); + gn->add_child(hbc); + gn->add_child( memnew(Label("b"))); + gn->add_child( memnew(Label("c"))); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],false,0,Color()); + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],false,0,Color()); + + } break; // vec3 interpolation (with optional curve) + case ShaderGraph::NODE_COLOR_RAMP: { + + gn->set_title("ColorRamp"); + GraphColorRampEdit * ramp = memnew( GraphColorRampEdit ); + + DVector<real_t> offsets = graph->color_ramp_node_get_offsets(type,p_id); + DVector<Color> colors = graph->color_ramp_node_get_colors(type,p_id); + + int oc = offsets.size(); + + if (oc) { + DVector<real_t>::Read rofs = offsets.read(); + DVector<Color>::Read rcol = colors.read(); + + Vector<float> ofsv; + Vector<Color> colorv; + for(int i=0;i<oc;i++) { + ofsv.push_back(rofs[i]); + colorv.push_back(rcol[i]); + } + + ramp->set_ramp(ofsv,colorv); + + } + + ramp->connect("ramp_changed",this,"_color_ramp_changed",varray(p_id,ramp)); + ramp->set_custom_minimum_size(Size2(128,1)); + gn->add_child(ramp); - if(test_param!="") { - int iter=0; - List<int> l; + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("c"))); + hbc->add_spacer(); + Label *l=memnew(Label("rgb")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + l=memnew(Label("alpha")); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child( l); - shader_graph.get_node_list(&l); - bool found; - String test; - do { - iter++; - test=test_param; - if (iter>1) - test+="_"+itos(iter); - found=false; - for(List<int>::Element *E=l.front();E;E=E->next()) { + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(2,false,ShaderGraph::SLOT_MAX,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); - String param = shader_graph.node_get_param( E->get() ); - if (param==test) { - found=true; - break; + } break; // scalar interpolation (with optional curve) + case ShaderGraph::NODE_CURVE_MAP: { + + gn->set_title("CurveMap"); + GraphCurveMapEdit * map = memnew( GraphCurveMapEdit ); + + DVector<Vector2> points = graph->curve_map_node_get_points(type,p_id); + + int oc = points.size(); + + if (oc) { + DVector<Vector2>::Read rofs = points.read(); + + + Vector<Vector2> ofsv; + for(int i=0;i<oc;i++) { + ofsv.push_back(rofs[i]); + } + + map->set_points(ofsv); + + } + map->connect("curve_changed",this,"_curve_changed",varray(p_id,map)); + + //map->connect("map_changed",this,"_curve_map_changed",varray(p_id,map)); + map->set_custom_minimum_size(Size2(128,64)); + gn->add_child(map); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("c"))); + hbc->add_spacer(); + Label *l=memnew(Label("cmap")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child( l); + gn->add_child(hbc); + + + gn->set_slot(1,true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR],true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // scalar interpolation (with optional curve) + + case ShaderGraph::NODE_SCALAR_INPUT: { + + gn->set_title("ScalarUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + SpinBox *sb = memnew( SpinBox ); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->scalar_input_node_get_value(type,p_id)); + sb->connect("value_changed",this,"_scalar_input_changed",varray(p_id)); + gn->add_child(sb); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // scalar uniform (assignable in material) + case ShaderGraph::NODE_VEC_INPUT: { + + gn->set_title("VectorUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + Array v3p(true); + for(int i=0;i<3;i++) { + HBoxContainer *hbc = memnew( HBoxContainer ); + Label *l = memnew( Label ); + l->set_text(String::chr('X'+i)); + hbc->add_child(l); + SpinBox *sb = memnew( SpinBox ); + sb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + sb->set_min(-100000); + sb->set_max(100000); + sb->set_step(0.001); + sb->set_val(graph->vec_input_node_get_value(type,p_id)[i]); + sb->connect("value_changed",this,"_vec_input_changed",varray(p_id,v3p)); + v3p.push_back(sb); + hbc->add_child(sb); + gn->add_child(hbc); + } + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + + } break; // vec3 uniform (assignable in material) + case ShaderGraph::NODE_RGB_INPUT: { + + gn->set_title("ColorUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + ColorPickerButton *cpb = memnew( ColorPickerButton ); + cpb->set_color(graph->rgb_input_node_get_value(type,p_id)); + cpb->connect("color_changed",this,"_rgb_input_changed",varray(p_id)); + gn->add_child(cpb); + Label *l = memnew( Label ); + l->set_text("RGB"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(2,false,0,Color(),true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // color uniform (assignable in material) + case ShaderGraph::NODE_XFORM_INPUT: { + gn->set_title("XFUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_xform_input_changed",varray(p_id,edit)); + gn->add_child(edit); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_XFORM,typecol[ShaderGraph::SLOT_TYPE_XFORM]); + + } break; // mat4 uniform (assignable in material) + case ShaderGraph::NODE_TEXTURE_INPUT: { + + gn->set_title("TexUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + TextureFrame *tex = memnew( TextureFrame ); + tex->set_expand(true); + tex->set_custom_minimum_size(Size2(80,80)); + gn->add_child(tex); + tex->set_texture(graph->texture_input_node_get_value(type,p_id)); + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_tex_edited",varray(p_id,edit)); + gn->add_child(edit); + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(3,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(4,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // texture input (assignable in material) + case ShaderGraph::NODE_CUBEMAP_INPUT: { + + gn->set_title("TexUniform"); + LineEdit *le = memnew( LineEdit ); + gn->add_child(le); + le->set_text(graph->input_node_get_name(type,p_id)); + le->connect("text_entered",this,"_input_name_changed",varray(p_id,le)); + + ToolButton *edit = memnew( ToolButton ); + edit->set_text("edit.."); + edit->connect("pressed",this,"_cube_edited",varray(p_id,edit)); + gn->add_child(edit); + + + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(2,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(3,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + } break; // cubemap input (assignable in material) + case ShaderGraph::NODE_DEFAULT_TEXTURE: { + + gn->set_title("CanvasItemTex"); + HBoxContainer *hbc = memnew( HBoxContainer ); + hbc->add_constant_override("separation",0); + hbc->add_child( memnew(Label("UV"))); + hbc->add_spacer(); + Label *l=memnew(Label("RGB")); + l->set_align(Label::ALIGN_RIGHT); + hbc->add_child(l); + gn->add_child(hbc); + l = memnew( Label ); + l->set_text("Alpha"); + l->set_align(Label::ALIGN_RIGHT); + gn->add_child(l); + + gn->set_slot(0,true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC],true,ShaderGraph::SLOT_TYPE_VEC,typecol[ShaderGraph::SLOT_TYPE_VEC]); + gn->set_slot(1,false,0,Color(),true,ShaderGraph::SLOT_TYPE_SCALAR,typecol[ShaderGraph::SLOT_TYPE_SCALAR]); + + + } break; // screen texture sampler (takes UV) (only usable in fragment case Shader) + + case ShaderGraph::NODE_OUTPUT: { + gn->set_title("Output"); + + List<ShaderGraph::SlotInfo> si; + ShaderGraph::get_input_output_node_slot_info(graph->get_mode(),type,&si); + + int idx=0; + for (List<ShaderGraph::SlotInfo>::Element *E=si.front();E;E=E->next()) { + ShaderGraph::SlotInfo& s=E->get(); + if (s.dir==ShaderGraph::SLOT_OUT) { + + Label *l= memnew( Label ); + l->set_text(s.name); + l->set_align(Label::ALIGN_LEFT); + gn->add_child(l); + gn->set_slot(idx,true,s.type,typecol[s.type],false,0,Color()); + idx++; } } - } while (found); + } break; // output (case Shader type dependent) + case ShaderGraph::NODE_COMMENT: { + gn->set_title("Comment"); + TextEdit *te = memnew(TextEdit); + te->set_custom_minimum_size(Size2(100,100)); + gn->add_child(te); + te->set_text(graph->comment_node_get_text(type,p_id)); + te->connect("text_changed",this,"_comment_edited",varray(p_id,te)); + + } break; // comment - shader_graph.node_set_param(last_id,test); } - order.push_back(last_id); - last_x+=10; - last_y+=10; - last_id++; - last_x=last_x % (int)get_size().width; - last_y=last_y % (int)get_size().height; - update(); - add_popup->hide();; - _write_shader_graph(); -} + gn->connect("dragged",this,"_node_moved",varray(p_id)); + gn->connect("close_request",this,"_node_removed",varray(p_id),CONNECT_DEFERRED); + graph_edit->add_child(gn); + node_map[p_id]=gn; + gn->set_offset(graph->node_get_pos(type,p_id)); -void ShaderEditor::_node_add_callback() { - TreeItem * item = add_types->get_selected(); - ERR_FAIL_COND(!item); - _node_add((VisualServer::ShaderNodeType)(int)item->get_metadata(0)); - add_popup->hide() ; } -ShaderEditor::ShaderEditor() { +void ShaderGraphView::_update_graph() { - set_focus_mode(FOCUS_ALL); - Panel* menu_panel = memnew( Panel ); - menu_panel->set_anchor( MARGIN_RIGHT, Control::ANCHOR_END ); - menu_panel->set_end( Point2(0,22) ); + if (block_update) + return; - add_child( menu_panel ); + for (Map<int,GraphNode*>::Element *E=node_map.front();E;E=E->next()) { - PopupMenu *p; - List<PropertyInfo> defaults; + memdelete(E->get()); + } - MenuButton* node_menu = memnew( MenuButton ); - node_menu->set_text("Graph"); - node_menu->set_pos( Point2( 5,0) ); - menu_panel->add_child( node_menu ); + node_map.clear(); - p=node_menu->get_popup(); - p->add_item("Add Node",GRAPH_ADD_NODE); - p->add_separator(); - p->add_item("Clear",GRAPH_CLEAR); - p->connect("item_pressed", this,"_node_menu_item"); + if (!graph.is_valid()) + return; - MenuButton* vertex_menu = memnew( MenuButton ); - vertex_menu->set_text("Vertex"); - vertex_menu->set_pos( Point2( 49,0) ); - menu_panel->add_child( vertex_menu ); - p=vertex_menu->get_popup(); - defaults.clear(); - VisualServer::shader_get_default_input_nodes(VisualServer::SHADER_VERTEX,&defaults); + List<int> nl; + graph->get_node_list(type,&nl); - int id=0; - for(int i=0;i<defaults.size();i++) { + for(List<int>::Element *E=nl.front();E;E=E->next()) { - p->add_item("In: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++); + _create_node(E->get()); } - p->add_separator(); - id++; + graph_edit->clear_connections(); - defaults.clear(); - VisualServer::shader_get_default_output_nodes(VisualServer::SHADER_VERTEX,&defaults); - - for(int i=0;i<defaults.size();i++) { + List<ShaderGraph::Connection> connections; + graph->get_node_connections(type,&connections); + for(List<ShaderGraph::Connection>::Element *E=connections.front();E;E=E->next()) { - p->add_item("Out: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++); + ERR_CONTINUE(!node_map.has(E->get().src_id) || !node_map.has(E->get().dst_id)); + graph_edit->connect_node(node_map[E->get().src_id]->get_name(),E->get().src_slot,node_map[E->get().dst_id]->get_name(),E->get().dst_slot); } - vertex_popup=p; - vertex_popup->connect("item_pressed", this,"_vertex_item"); - MenuButton* fragment_menu = memnew( MenuButton ); - fragment_menu->set_text("Fragment"); - fragment_menu->set_pos( Point2( 95 ,0) ); - menu_panel->add_child( fragment_menu ); - p=fragment_menu->get_popup(); - defaults.clear(); - VisualServer::shader_get_default_input_nodes(VisualServer::SHADER_FRAGMENT,&defaults); - id=0; - for(int i=0;i<defaults.size();i++) { - p->add_item("In: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++); +} + +void ShaderGraphView::_sg_updated() { + + if (!graph.is_valid()) + return; + switch(graph->get_graph_error(type)) { + case ShaderGraph::GRAPH_OK: status->set_text(""); break; + case ShaderGraph::GRAPH_ERROR_CYCLIC: status->set_text("Error: Cyclic Connection Link"); break; + case ShaderGraph::GRAPH_ERROR_MISSING_CONNECTIONS: status->set_text("Error: Missing Input Connections"); break; } - p->add_separator(); - id++; - defaults.clear(); - VisualServer::shader_get_default_output_nodes(VisualServer::SHADER_FRAGMENT,&defaults); +} - for(int i=0;i<defaults.size();i++) { +void ShaderGraphView::set_graph(Ref<ShaderGraph> p_graph){ - p->add_item("Out: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++); + + if (graph.is_valid()) { + graph->disconnect("updated",this,"_sg_updated"); + } + graph=p_graph; + if (graph.is_valid()) { + graph->connect("updated",this,"_sg_updated"); } + _update_graph(); + _sg_updated(); + +} + +void ShaderGraphView::_notification(int p_what) { - fragment_popup=p; - fragment_popup->connect("item_pressed", this,"_fragment_item"); + if (p_what==NOTIFICATION_ENTER_TREE) { - MenuButton* post_menu = memnew( MenuButton ); - post_menu->set_text("Post"); - post_menu->set_pos( Point2( 161,0) ); - menu_panel->add_child( post_menu ); + ped_popup->connect("variant_changed",this,"_variant_edited"); + } + } + +void ShaderGraphView::add_node(int p_type) { + + List<int> existing; + graph->get_node_list(type,&existing); + existing.sort(); + int newid=1; + for(List<int>::Element *E=existing.front();E;E=E->next()) { + if (!E->next() || (E->get()+1!=E->next()->get())){ + newid=E->get()+1; + break; + } + } - p=post_menu->get_popup(); - defaults.clear(); - VisualServer::shader_get_default_input_nodes(VisualServer::SHADER_POST_PROCESS,&defaults); - id=0; - for(int i=0;i<defaults.size();i++) { + Vector2 init_ofs(20,20); + while(true) { + bool valid=true; + for(List<int>::Element *E=existing.front();E;E=E->next()) { + Vector2 pos = graph->node_get_pos(type,E->get()); + if (init_ofs==pos) { + init_ofs+=Vector2(20,20); + valid=false; + break; + + } + } - p->add_item("In: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++); + if (valid) + break; } - p->add_separator(); - id++; + UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo(); + ur->create_action("Add Shader Graph Node"); + ur->add_do_method(graph.ptr(),"node_add",type,p_type,newid); + ur->add_do_method(graph.ptr(),"node_set_pos",type,newid,init_ofs); + ur->add_undo_method(graph.ptr(),"node_remove",type,newid); + ur->add_do_method(this,"_update_graph"); + ur->add_undo_method(this,"_update_graph"); + ur->commit_action(); + +} + +void ShaderGraphView::_bind_methods() { + + ObjectTypeDB::bind_method("_update_graph",&ShaderGraphView::_update_graph); + ObjectTypeDB::bind_method("_node_moved",&ShaderGraphView::_node_moved); + ObjectTypeDB::bind_method("_move_node",&ShaderGraphView::_move_node); + ObjectTypeDB::bind_method("_node_removed",&ShaderGraphView::_node_removed); + ObjectTypeDB::bind_method("_connection_request",&ShaderGraphView::_connection_request); + ObjectTypeDB::bind_method("_disconnection_request",&ShaderGraphView::_disconnection_request); + + ObjectTypeDB::bind_method("_scalar_const_changed",&ShaderGraphView::_scalar_const_changed); + ObjectTypeDB::bind_method("_vec_const_changed",&ShaderGraphView::_vec_const_changed); + ObjectTypeDB::bind_method("_rgb_const_changed",&ShaderGraphView::_rgb_const_changed); + ObjectTypeDB::bind_method("_xform_const_changed",&ShaderGraphView::_xform_const_changed); + ObjectTypeDB::bind_method("_scalar_op_changed",&ShaderGraphView::_scalar_op_changed); + ObjectTypeDB::bind_method("_vec_op_changed",&ShaderGraphView::_vec_op_changed); + ObjectTypeDB::bind_method("_vec_scalar_op_changed",&ShaderGraphView::_vec_scalar_op_changed); + ObjectTypeDB::bind_method("_rgb_op_changed",&ShaderGraphView::_rgb_op_changed); + ObjectTypeDB::bind_method("_xform_inv_rev_changed",&ShaderGraphView::_xform_inv_rev_changed); + ObjectTypeDB::bind_method("_scalar_func_changed",&ShaderGraphView::_scalar_func_changed); + ObjectTypeDB::bind_method("_vec_func_changed",&ShaderGraphView::_vec_func_changed); + ObjectTypeDB::bind_method("_scalar_input_changed",&ShaderGraphView::_scalar_input_changed); + ObjectTypeDB::bind_method("_vec_input_changed",&ShaderGraphView::_vec_input_changed); + ObjectTypeDB::bind_method("_xform_input_changed",&ShaderGraphView::_xform_input_changed); + ObjectTypeDB::bind_method("_rgb_input_changed",&ShaderGraphView::_rgb_input_changed); + ObjectTypeDB::bind_method("_tex_input_change",&ShaderGraphView::_tex_input_change); + ObjectTypeDB::bind_method("_cube_input_change",&ShaderGraphView::_cube_input_change); + ObjectTypeDB::bind_method("_input_name_changed",&ShaderGraphView::_input_name_changed); + ObjectTypeDB::bind_method("_tex_edited",&ShaderGraphView::_tex_edited); + ObjectTypeDB::bind_method("_variant_edited",&ShaderGraphView::_variant_edited); + ObjectTypeDB::bind_method("_cube_edited",&ShaderGraphView::_cube_edited); + ObjectTypeDB::bind_method("_comment_edited",&ShaderGraphView::_comment_edited); + ObjectTypeDB::bind_method("_color_ramp_changed",&ShaderGraphView::_color_ramp_changed); + ObjectTypeDB::bind_method("_curve_changed",&ShaderGraphView::_curve_changed); + + ObjectTypeDB::bind_method("_sg_updated",&ShaderGraphView::_sg_updated); +} + +ShaderGraphView::ShaderGraphView(ShaderGraph::ShaderType p_type) { + + type=p_type; + graph_edit = memnew( GraphEdit ); + block_update=false; + ped_popup = memnew( CustomPropertyEditor ); + graph_edit->add_child(ped_popup); + status = memnew( Label ); + graph_edit->get_top_layer()->add_child(status); + status->set_pos(Vector2(5,5)); + status->add_color_override("font_color_shadow",Color(0,0,0)); + status->add_color_override("font_color",Color(1,0.4,0.3)); + status->add_constant_override("shadow_as_outline",1); + status->add_constant_override("shadow_offset_x",2); + status->add_constant_override("shadow_offset_y",2); + status->set_text(""); +} - defaults.clear(); - VisualServer::shader_get_default_output_nodes(VisualServer::SHADER_POST_PROCESS,&defaults); - for(int i=0;i<defaults.size();i++) { +//////////////edit////////////// +void ShaderGraphEditor::edit(Ref<ShaderGraph> p_shader) { - p->add_item("Out: "+defaults[i].name+(defaults[i].type==Variant::VECTOR3?" (vec3)":" (real)"),id++); + for(int i=0;i<ShaderGraph::SHADER_TYPE_MAX;i++) { + graph_edits[i]->set_graph(p_shader); } +} + +void ShaderGraphEditor::_add_node(int p_type) { + + ShaderGraph::ShaderType shader_type=ShaderGraph::ShaderType(tabs->get_current_tab()); + + graph_edits[shader_type]->add_node(p_type); +} + + +void ShaderGraphEditor::_notification(int p_what) { + if (p_what==NOTIFICATION_ENTER_TREE) { + + for(int i=0;i<ShaderGraph::NODE_TYPE_MAX;i++) { - post_popup=p; - post_popup->connect("item_pressed", this,"_post_item"); + if (i==ShaderGraph::NODE_OUTPUT) + continue; + if (!_2d && i==ShaderGraph::NODE_DEFAULT_TEXTURE) + continue; + + String nn = node_names[i]; + String ic = nn.get_slice(":",0); + String v = nn.get_slice(":",1); + bool addsep=false; + if (nn.ends_with(":")) { + addsep=true; + } + menu->get_popup()->add_icon_item(get_icon(ic,"EditorIcons"),v,i); + if (addsep) + menu->get_popup()->add_separator(); + } + menu->get_popup()->connect("item_pressed",this,"_add_node"); - /* add popup */ + } +} - add_popup = memnew( Popup ); - add_child(add_popup); - add_popup->set_as_toplevel(true); - Panel *add_panel = memnew( Panel ); - add_popup->add_child(add_panel); - add_panel->set_area_as_parent_rect(); +void ShaderGraphEditor::_bind_methods() { - Label *add_label = memnew (Label ); - add_label->set_pos(Point2(5,5)); - add_label->set_text("Available Nodes:"); - add_panel->add_child(add_label); + ObjectTypeDB::bind_method("_add_node",&ShaderGraphEditor::_add_node); +} - add_types = memnew( Tree ); - add_types->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - add_types->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); - add_types->set_begin( Point2( 20,25 ) ); - add_types->set_end( Point2( 10, 30 ) ); - add_types->set_hide_root(true); - add_types->set_columns(4); - add_types->set_select_mode(Tree::SELECT_ROW); +const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={ + "GraphInput:Input", // all inputs (shader type dependent) + "GraphScalar:Scalar Constant", //scalar constant + "GraphVector:Vector Constant", //vec3 constant + "GraphRgb:RGB Constant", //rgb constant (shows a color picker instead) + "GraphXform:XForm Constant", // 4x4 matrix constant + "GraphTime:Time:", // time in seconds + "GraphTexscreen:Screen Sample", // screen texture sampler (takes uv) (only usable in fragment shader) + "GraphScalarOp:Scalar Operator", // scalar vs scalar op (mul", add", div", etc) + "GraphVecOp:Vector Operator", // vec3 vs vec3 op (mul",ad",div",crossprod",etc) + "GraphVecScalarOp:Scalar+Vector Operator", // vec3 vs scalar op (mul", add", div", etc) + "GraphRgbOp:RGB Operator:", // vec3 vs vec3 rgb op (with scalar amount)", like brighten", darken", burn", dodge", multiply", etc. + "GraphXformMult:XForm Multiply", // mat4 x mat4 + "GraphXformVecMult:XForm+Vector Multiply", // mat4 x vec3 mult (with no-translation option) + "GraphXformVecImult:Form+Vector InvMultiply:", // mat4 x vec3 inverse mult (with no-translation option) + "GraphXformScalarFunc:Scalar Function", // scalar function (sin", cos", etc) + "GraphXformVecFunc:Vector Function", // vector function (normalize", negate", reciprocal", rgb2hsv", hsv2rgb", etc", etc) + "GraphVecLength:Vector Length", // vec3 length + "GraphVecDp:Dot Product:", // vec3 . vec3 (dot product -> scalar output) + "GraphVecToScalars:Vector -> Scalars", // 1 vec3 input", 3 scalar outputs + "GraphScalarsToVec:Scalars -> Vector", // 3 scalar input", 1 vec3 output + "GraphXformToVecs:XForm -> Vectors", // 3 vec input", 1 xform output + "GraphVecsToXform:Vectors -> XForm:", // 3 vec input", 1 xform output + "GraphScalarInterp:Scalar Interpolate", // scalar interpolation (with optional curve) + "GraphVecInterp:Vector Interpolate:", // vec3 interpolation (with optional curve) + "GraphColorRamp:Color Ramp", // vec3 interpolation (with optional curve) + "GraphCurveMap:Curve Remap:", // vec3 interpolation (with optional curve) + "GraphScalarUniform:Scalar Uniform", // scalar uniform (assignable in material) + "GraphVectorUniform:Vector Uniform", // vec3 uniform (assignable in material) + "GraphRgbUniform:RGB Uniform", // color uniform (assignable in material) + "GraphXformUniform:XForm Uniform", // mat4 uniform (assignable in material) + "GraphTextureUniform:Texture Uniform", // texture input (assignable in material) + "GraphCubeUniform:CubeMap Uniform:", // cubemap input (assignable in material) + "GraphDefaultTexture:CanvasItem Texture:", // cubemap input (assignable in material) + "Output", // output (shader type dependent) + "GraphComment:Comment", // comment - TreeItem *add_types_root = add_types->create_item(NULL); - TreeItem *info_item = add_types->create_item(add_types_root); - for(int i=0;i<VisualServer::NODE_TYPE_MAX;i++) { +}; +ShaderGraphEditor::ShaderGraphEditor(bool p_2d) { + _2d=p_2d; + + HBoxContainer *hbc = memnew( HBoxContainer ); + menu = memnew( MenuButton ); + menu->set_text("Add Node.."); + hbc->add_child(menu); + add_child(hbc); + + + tabs = memnew(TabContainer); + tabs->set_v_size_flags(SIZE_EXPAND_FILL); + add_child(tabs); + const char* sname[ShaderGraph::SHADER_TYPE_MAX]={ + "Vertex", + "Fragment", + "Light" + }; + for(int i=0;i<ShaderGraph::SHADER_TYPE_MAX;i++) { + + graph_edits[i]= memnew( ShaderGraphView(ShaderGraph::ShaderType(i)) ); + add_child(graph_edits[i]); + graph_edits[i]->get_graph_edit()->set_name(sname[i]); + tabs->add_child(graph_edits[i]->get_graph_edit()); + graph_edits[i]->get_graph_edit()->connect("connection_request",graph_edits[i],"_connection_request"); + graph_edits[i]->get_graph_edit()->connect("disconnection_request",graph_edits[i],"_disconnection_request"); + graph_edits[i]->get_graph_edit()->set_right_disconnects(true); - TreeItem *item = add_types->create_item(add_types_root); - PropertyInfo prop = VisualServer::shader_node_get_type_info((VisualServer::ShaderNodeType)i); - item->set_text(0,prop.name); - item->set_text(1,itos(VisualServer::shader_get_input_count((VisualServer::ShaderNodeType)i))); - item->set_text(2,itos(VisualServer::shader_get_output_count((VisualServer::ShaderNodeType)i))); - String hint = (prop.type==Variant::_RID)?prop.hint_string:Variant::get_type_name(prop.type); - item->set_text(3,hint); - item->set_metadata(0,i); } - info_item->set_text(0,"::NODE::"); - info_item->set_custom_color(0,Color(0.6,0.1,0.1)); - info_item->set_text(1,"::INPUTS::"); - info_item->set_custom_color(1,Color(0.6,0.1,0.1)); - info_item->set_text(2,"::OUTPUTS::"); - info_item->set_custom_color(2,Color(0.6,0.1,0.1)); - info_item->set_text(3,"::PARAM::"); - info_item->set_custom_color(3,Color(0.6,0.1,0.1)); - info_item->set_selectable(0,false); - info_item->set_selectable(1,false); - info_item->set_selectable(2,false); - info_item->set_selectable(3,false); - - add_panel->add_child(add_types); - - add_confirm = memnew( Button ); - add_confirm->set_anchor( MARGIN_LEFT, ANCHOR_END ); - add_confirm->set_anchor( MARGIN_TOP, ANCHOR_END ); - add_confirm->set_anchor( MARGIN_RIGHT, ANCHOR_END ); - add_confirm->set_anchor( MARGIN_BOTTOM, ANCHOR_END ); - add_confirm->set_begin( Point2( 75, 29 ) ); - add_confirm->set_end( Point2( 10, 15 ) ); - add_confirm->set_text("Add"); - add_panel->add_child(add_confirm); - add_confirm->connect("pressed", this,"_node_add_callback"); - - last_id=1; - last_x=20; - last_y=20; - - property_editor = memnew( CustomPropertyEditor ); - add_child(property_editor); - property_editor->connect("variant_changed", this,"_node_param_changed"); - - h_scroll = memnew( HScrollBar ); - v_scroll = memnew( VScrollBar ); - - add_child(h_scroll); - add_child(v_scroll); - - h_scroll->connect("value_changed", this,"_scroll_moved"); - v_scroll->connect("value_changed", this,"_scroll_moved"); - - node_popup= memnew(PopupMenu ); - add_child(node_popup); - node_popup->set_as_toplevel(true); - - node_popup->connect("item_pressed", this,"_node_menu_item"); + tabs->set_current_tab(1); + + set_custom_minimum_size(Size2(100,300)); } -void ShaderEditorPlugin::edit(Object *p_object) { +void ShaderGraphEditorPlugin::edit(Object *p_object) { - shader_editor->edit(p_object->cast_to<Shader>()); + shader_editor->edit(p_object->cast_to<ShaderGraph>()); } -bool ShaderEditorPlugin::handles(Object *p_object) const { +bool ShaderGraphEditorPlugin::handles(Object *p_object) const { - return p_object->is_type("Shader"); + ShaderGraph *shader=p_object->cast_to<ShaderGraph>(); + if (!shader) + return false; + if (_2d) + return shader->get_mode()==Shader::MODE_CANVAS_ITEM; + else + return shader->get_mode()==Shader::MODE_MATERIAL; } -void ShaderEditorPlugin::make_visible(bool p_visible) { +void ShaderGraphEditorPlugin::make_visible(bool p_visible) { if (p_visible) { shader_editor->show(); - shader_editor->set_process(true); } else { shader_editor->hide(); - shader_editor->set_process(false); } } -ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) { +ShaderGraphEditorPlugin::ShaderGraphEditorPlugin(EditorNode *p_node, bool p_2d) { + _2d=p_2d; editor=p_node; - shader_editor = memnew( ShaderEditor ); - editor->get_viewport()->add_child(shader_editor); - shader_editor->set_area_as_parent_rect(); + shader_editor = memnew( ShaderGraphEditor(p_2d) ); shader_editor->hide(); + if (p_2d) + CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(shader_editor); + else + SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor); +// editor->get_viewport()->add_child(shader_editor); +// shader_editor->set_area_as_parent_rect(); +// shader_editor->hide(); } -ShaderEditorPlugin::~ShaderEditorPlugin() +ShaderGraphEditorPlugin::~ShaderGraphEditorPlugin() { } -#endif + diff --git a/tools/editor/plugins/shader_graph_editor_plugin.h b/tools/editor/plugins/shader_graph_editor_plugin.h index 5b0767dc82..1726302e90 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.h +++ b/tools/editor/plugins/shader_graph_editor_plugin.h @@ -29,122 +29,198 @@ #ifndef SHADER_GRAPH_EDITOR_PLUGIN_H #define SHADER_GRAPH_EDITOR_PLUGIN_H -#if 0 + #include "tools/editor/editor_plugin.h" #include "tools/editor/editor_node.h" #include "scene/resources/shader.h" #include "servers/visual/shader_graph.h" #include "scene/gui/tree.h" #include "scene/gui/button.h" +#include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" #include "tools/editor/property_editor.h" +#include "scene/resources/shader_graph.h" /** @author Juan Linietsky <reduzio@gmail.com> */ -class ShaderEditor : public Control { - OBJ_TYPE(ShaderEditor, Control ); +class GraphColorRampEdit : public Control { + + OBJ_TYPE(GraphColorRampEdit,Control); - enum MenuAction { - GRAPH_ADD_NODE, - GRAPH_CLEAR, - NODE_DISCONNECT, - NODE_ERASE, + struct Point { + float offset; + Color color; + bool operator<(const Point& p_ponit) const { + return offset<p_ponit.offset; + } }; - enum ClickType { - CLICK_NONE, - CLICK_NODE, - CLICK_INPUT_SLOT, - CLICK_OUTPUT_SLOT, - CLICK_PARAMETER + PopupPanel *popup; + ColorPicker *picker; + + + bool grabbing; + int grabbed; + float grabbed_at; + Vector<Point> points; + + void _color_changed(const Color& p_color); + +protected: + void _input_event(const InputEvent& p_event); + void _notification(int p_what); + static void _bind_methods(); +public: + + void set_ramp(const Vector<float>& p_offsets,const Vector<Color>& p_colors); + Vector<float> get_offsets() const; + Vector<Color> get_colors() const; + virtual Size2 get_minimum_size() const; + GraphColorRampEdit(); +}; + + +class GraphCurveMapEdit : public Control { + + OBJ_TYPE(GraphCurveMapEdit,Control); + + + struct Point { + + float offset; + float height; + bool operator<(const Point& p_ponit) const { + return offset<p_ponit.offset; + } }; - PopupMenu *node_popup; - Popup *add_popup; - PopupMenu *vertex_popup; - PopupMenu *fragment_popup; - PopupMenu *post_popup; - Tree *add_types; - Button *add_confirm; - HScrollBar *h_scroll; - VScrollBar *v_scroll; - - Ref<Shader> shader; - List<int> order; - Set<int> active_nodes; - ShaderGraph shader_graph; - int last_x,last_y; - uint32_t last_id; - - CustomPropertyEditor *property_editor; - - Point2 offset; - ClickType click_type; - Point2 click_pos; - int click_node; - int click_slot; - Point2 click_motion; - ClickType rclick_type; - int rclick_node; - int rclick_slot; - - Size2 _get_maximum_size(); - Size2 get_node_size(int p_node) const; - void _draw_node(int p_node); - - void _add_node_from_text(const String& p_text); - void _update_scrollbars(); - void _scroll_moved(); - void _node_param_changed(); - void _node_add_callback(); - void _node_add(VisualServer::ShaderNodeType p_type); - void _node_edit_property(int p_node); - void _node_menu_item(int p_item); - void _vertex_item(int p_item); - void _fragment_item(int p_item); - void _post_item(int p_item); - - ClickType _locate_click(const Point2& p_click,int *p_node_id,int *p_slot_index) const; - Point2 _get_slot_pos(int p_node_id,bool p_input,int p_slot); - - Error validate_graph(); - - void _read_shader_graph(); - void _write_shader_graph(); - - virtual bool has_point(const Point2& p_point) const; + + bool grabbing; + int grabbed; + Vector<Point> points; + + void _plot_curve(const Vector2& p_a,const Vector2& p_b,const Vector2& p_c,const Vector2& p_d); protected: + void _input_event(const InputEvent& p_event); void _notification(int p_what); - void _input_event(InputEvent p_event); static void _bind_methods(); public: - void edit(Ref<Shader> p_shader); - ShaderEditor(); + void set_points(const Vector<Vector2>& p_points); + Vector<Vector2> get_points() const; + virtual Size2 get_minimum_size() const; + GraphCurveMapEdit(); }; -class ShaderEditorPlugin : public EditorPlugin { +class ShaderGraphView : public Node { + + OBJ_TYPE(ShaderGraphView,Node); + + + + CustomPropertyEditor *ped_popup; + bool block_update; + + Label *status; + GraphEdit *graph_edit; + Ref<ShaderGraph> graph; + int edited_id; + + ShaderGraph::ShaderType type; - OBJ_TYPE( ShaderEditorPlugin, EditorPlugin ); + void _update_graph(); + void _create_node(int p_id); - ShaderEditor *shader_editor; + + + void _connection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); + void _disconnection_request(const String& p_from, int p_from_slot,const String& p_to,int p_to_slot); + + void _node_removed(int p_id); + void _node_moved(const Vector2& p_from, const Vector2& p_to,int p_id); + void _move_node(int p_id,const Vector2& p_to); + + void _scalar_const_changed(double p_value,int p_id); + void _vec_const_changed(double p_value, int p_id, Array p_arr); + void _rgb_const_changed(const Color& p_color, int p_id); + void _xform_const_changed(int p_id,Node* p_button); + void _scalar_op_changed(int p_op, int p_id); + void _vec_op_changed(int p_op, int p_id); + void _vec_scalar_op_changed(int p_op, int p_id); + void _rgb_op_changed(int p_op, int p_id); + void _xform_inv_rev_changed(bool p_enabled, int p_id); + void _scalar_func_changed(int p_func, int p_id); + void _vec_func_changed(int p_func, int p_id); + void _scalar_input_changed(double p_value,int p_id); + void _vec_input_changed(double p_value, int p_id, Array p_arr); + void _xform_input_changed(int p_id,Node* p_button); + void _rgb_input_changed(const Color& p_color, int p_id); + void _tex_input_change(int p_id,Node* p_button); + void _cube_input_change(int p_id); + void _input_name_changed(const String& p_name,int p_id,Node* p_line_edit); + void _tex_edited(int p_id,Node* p_button); + void _cube_edited(int p_id,Node* p_button); + void _variant_edited(); + void _comment_edited(int p_id,Node* p_button); + void _color_ramp_changed(int p_id,Node* p_ramp); + void _curve_changed(int p_id,Node* p_curve); + void _sg_updated(); + Map<int,GraphNode*> node_map; +protected: + void _notification(int p_what); + static void _bind_methods(); +public: + + void add_node(int p_type); + GraphEdit *get_graph_edit() { return graph_edit; } + void set_graph(Ref<ShaderGraph> p_graph); + + ShaderGraphView(ShaderGraph::ShaderType p_type=ShaderGraph::SHADER_TYPE_FRAGMENT); +}; + +class ShaderGraphEditor : public VBoxContainer { + + OBJ_TYPE(ShaderGraphEditor,VBoxContainer); + + MenuButton *menu; + TabContainer *tabs; + ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX]; + static const char* node_names[ShaderGraph::NODE_TYPE_MAX]; + + bool _2d; + void _add_node(int p_type); +protected: + void _notification(int p_what); + static void _bind_methods(); +public: + + void edit(Ref<ShaderGraph> p_shader); + ShaderGraphEditor(bool p_2d); +}; + +class ShaderGraphEditorPlugin : public EditorPlugin { + + OBJ_TYPE( ShaderGraphEditorPlugin, EditorPlugin ); + + bool _2d; + ShaderGraphEditor *shader_editor; EditorNode *editor; public: - virtual String get_name() const { return "Shader"; } + virtual String get_name() const { return "ShaderGraph"; } 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); - ShaderEditorPlugin(EditorNode *p_node); - ~ShaderEditorPlugin(); + ShaderGraphEditorPlugin(EditorNode *p_node,bool p_2d); + ~ShaderGraphEditorPlugin(); }; #endif -#endif // SHADER_GRAPH_EDITOR_PLUGIN_H + diff --git a/tools/editor/plugins/spatial_editor_plugin.cpp b/tools/editor/plugins/spatial_editor_plugin.cpp index 074fa5c946..30ac50057f 100644 --- a/tools/editor/plugins/spatial_editor_plugin.cpp +++ b/tools/editor/plugins/spatial_editor_plugin.cpp @@ -249,7 +249,7 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2& p_pos, bool p_append,b Vector3 ray=_get_ray(p_pos); Vector3 pos=_get_ray_pos(p_pos); - Vector<RID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_scene()->get_root()->get_world()->get_scenario() ); + Vector<RID> instances=VisualServer::get_singleton()->instances_cull_ray(pos,ray,get_tree()->get_root()->get_world()->get_scenario() ); Set<Ref<SpatialEditorGizmo> > found_gizmos; //uint32_t closest=0; @@ -449,7 +449,7 @@ void SpatialEditorViewport::_select_region() { frustum.push_back( far ); - Vector<RID> instances=VisualServer::get_singleton()->instances_cull_convex(frustum,get_scene()->get_root()->get_world()->get_scenario()); + Vector<RID> instances=VisualServer::get_singleton()->instances_cull_convex(frustum,get_tree()->get_root()->get_world()->get_scenario()); for (int i=0;i<instances.size();i++) { @@ -477,6 +477,16 @@ void SpatialEditorViewport::_select_region() { } +void SpatialEditorViewport::_update_name() { + + String ortho = orthogonal?"Orthogonal":"Perspective"; + + if (name!="") + view_menu->set_text("[ "+name+" "+ortho+" ]"); + else + view_menu->set_text("[ "+ortho+" ]"); +} + void SpatialEditorViewport::_compute_edit(const Point2& p_point) { @@ -535,6 +545,14 @@ SpatialEditorViewport::NavigationScheme SpatialEditorViewport::_get_navigation_s return NAVIGATION_GODOT; } +SpatialEditorViewport::NavigationZoomStyle SpatialEditorViewport::_get_navigation_zoom_style(const String& p_property) { + switch(EditorSettings::get_singleton()->get(p_property).operator int()) { + case 0: return NAVIGATION_ZOOM_VERTICAL; + case 1: return NAVIGATION_ZOOM_HORIZONTAL; + } + return NAVIGATION_ZOOM_VERTICAL; +} + bool SpatialEditorViewport::_gizmo_select(const Vector2& p_screenpos,bool p_hilite_only) { if (!spatial_editor->is_gizmo_visible()) @@ -724,7 +742,7 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (b.mod.control) { - Vector<RID> instances=VisualServer::get_singleton()->instances_cull_ray(ray_origin,ray_dir,get_scene()->get_root()->get_world()->get_scenario() ); + Vector<RID> instances=VisualServer::get_singleton()->instances_cull_ray(ray_origin,ray_dir,get_tree()->get_root()->get_world()->get_scenario() ); Plane p(ray_origin,_get_camera_normal()); @@ -824,6 +842,8 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { _edit.plane=TRANSFORM_X_AXIS; set_message("View Plane Transform.",2); + name=""; + _update_name(); } break; case TRANSFORM_X_AXIS: { @@ -1429,10 +1449,19 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (nav_scheme==NAVIGATION_MAYA && m.mod.shift) zoom_speed *= zoom_speed_modifier; - if ( m.relative_y > 0) - cursor.distance*=1+m.relative_y*zoom_speed; - else if (m.relative_y < 0) - cursor.distance/=1-m.relative_y*zoom_speed; + NavigationZoomStyle zoom_style = _get_navigation_zoom_style("3d_editor/zoom_style"); + if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) { + if ( m.relative_x > 0) + cursor.distance*=1-m.relative_x*zoom_speed; + else if (m.relative_x < 0) + cursor.distance/=1+m.relative_x*zoom_speed; + } + else { + if ( m.relative_y > 0) + cursor.distance*=1+m.relative_y*zoom_speed; + else if (m.relative_y < 0) + cursor.distance/=1-m.relative_y*zoom_speed; + } } break; @@ -1443,6 +1472,8 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { cursor.x_rot=Math_PI/2.0; if (cursor.x_rot<-Math_PI/2.0) cursor.x_rot=-Math_PI/2.0; + name=""; + _update_name(); } break; default: {} @@ -1467,9 +1498,14 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (k.mod.shift) { cursor.x_rot=-Math_PI/2.0; set_message("Bottom View.",2); + name="Bottom"; + _update_name(); + } else { cursor.x_rot=Math_PI/2.0; set_message("Top View.",2); + name="Top"; + _update_name(); } } break; case KEY_KP_1: { @@ -1478,10 +1514,14 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (k.mod.shift) { cursor.y_rot=Math_PI; set_message("Rear View.",2); + name="Rear"; + _update_name(); } else { cursor.y_rot=0; set_message("Front View.",2); + name="Front"; + _update_name(); } } break; @@ -1491,9 +1531,13 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { if (k.mod.shift) { cursor.y_rot=Math_PI/2.0; set_message("Left View.",2); + name="Left"; + _update_name(); } else { cursor.y_rot=-Math_PI/2.0; set_message("Right View.",2); + name="Right"; + _update_name(); } } break; @@ -1501,6 +1545,7 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) { orthogonal = !orthogonal; _menu_option(orthogonal?VIEW_PERSPECTIVE:VIEW_ORTHOGONAL); + _update_name(); } break; @@ -1711,7 +1756,7 @@ void SpatialEditorViewport::_notification(int p_what) { } - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { surface->connect("draw",this,"_draw"); surface->connect("input_event",this,"_sinput"); @@ -1814,35 +1859,47 @@ void SpatialEditorViewport::_menu_option(int p_option) { cursor.x_rot=Math_PI/2.0; cursor.y_rot=0; + name="Top"; + _update_name(); } break; case VIEW_BOTTOM: { cursor.x_rot=-Math_PI/2.0; cursor.y_rot=0; + name="Bottom"; + _update_name(); } break; case VIEW_LEFT: { cursor.y_rot=Math_PI/2.0; cursor.x_rot=0; + name="Left"; + _update_name(); } break; case VIEW_RIGHT: { cursor.y_rot=-Math_PI/2.0; cursor.x_rot=0; + name="Right"; + _update_name(); } break; case VIEW_FRONT: { cursor.y_rot=0; cursor.x_rot=0; + name="Front"; + _update_name(); } break; case VIEW_REAR: { cursor.y_rot=Math_PI; cursor.x_rot=0; + name="Rear"; + _update_name(); } break; case VIEW_CENTER_TO_SELECTION: { @@ -1924,6 +1981,7 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), false ); orthogonal=false; call_deferred("update_transform_gizmo_view"); + _update_name(); } break; case VIEW_ORTHOGONAL: { @@ -1932,6 +1990,7 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(VIEW_ORTHOGONAL), true ); orthogonal=true; call_deferred("update_transform_gizmo_view"); + _update_name(); } break; case VIEW_AUDIO_LISTENER: { @@ -1971,12 +2030,12 @@ void SpatialEditorViewport::_preview_exited_scene() { void SpatialEditorViewport::_init_gizmo_instance(int p_idx) { - uint32_t layer=1<<(GIZMO_BASE_LAYER+p_idx)|(1<<GIZMO_GRID_LAYER); + uint32_t layer=1<<(GIZMO_BASE_LAYER+p_idx);//|(1<<GIZMO_GRID_LAYER); for(int i=0;i<3;i++) { move_gizmo_instance[i]=VS::get_singleton()->instance_create(); VS::get_singleton()->instance_set_base(move_gizmo_instance[i],spatial_editor->get_move_gizmo(i)->get_rid()); - VS::get_singleton()->instance_set_scenario(move_gizmo_instance[i],get_scene()->get_root()->get_world()->get_scenario()); + VS::get_singleton()->instance_set_scenario(move_gizmo_instance[i],get_tree()->get_root()->get_world()->get_scenario()); VS::get_singleton()->instance_geometry_set_flag(move_gizmo_instance[i],VS::INSTANCE_FLAG_VISIBLE,false); //VS::get_singleton()->instance_geometry_set_flag(move_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true); VS::get_singleton()->instance_geometry_set_flag(move_gizmo_instance[i],VS::INSTANCE_FLAG_CAST_SHADOW,false); @@ -1984,7 +2043,7 @@ void SpatialEditorViewport::_init_gizmo_instance(int p_idx) { rotate_gizmo_instance[i]=VS::get_singleton()->instance_create(); VS::get_singleton()->instance_set_base(rotate_gizmo_instance[i],spatial_editor->get_rotate_gizmo(i)->get_rid()); - VS::get_singleton()->instance_set_scenario(rotate_gizmo_instance[i],get_scene()->get_root()->get_world()->get_scenario()); + VS::get_singleton()->instance_set_scenario(rotate_gizmo_instance[i],get_tree()->get_root()->get_world()->get_scenario()); VS::get_singleton()->instance_geometry_set_flag(rotate_gizmo_instance[i],VS::INSTANCE_FLAG_VISIBLE,false); //VS::get_singleton()->instance_geometry_set_flag(rotate_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true); VS::get_singleton()->instance_geometry_set_flag(rotate_gizmo_instance[i],VS::INSTANCE_FLAG_CAST_SHADOW,false); @@ -2001,7 +2060,7 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { if (!p_activate) { - previewing->disconnect("exit_scene",this,"_preview_exited_scene"); + previewing->disconnect("exit_tree",this,"_preview_exited_scene"); previewing=NULL; VS::get_singleton()->viewport_attach_camera( viewport->get_viewport(), camera->get_camera() ); //restore if (!preview) @@ -2012,7 +2071,7 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { } else { previewing=preview; - previewing->connect("exit_scene",this,"_preview_exited_scene"); + previewing->connect("exit_tree",this,"_preview_exited_scene"); VS::get_singleton()->viewport_attach_camera( viewport->get_viewport(), preview->get_camera() ); //replace view_menu->hide(); surface->update(); @@ -2130,15 +2189,13 @@ void SpatialEditorViewport::reset() { message_time=0; message=""; last_message=""; + name="Top"; cursor.x_rot=0; cursor.y_rot=0; cursor.distance=4; cursor.region_select=false; - - - - + _update_name(); } SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, EditorNode *p_editor, int p_index) { @@ -2172,18 +2229,17 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu = memnew( MenuButton ); surface->add_child(view_menu); view_menu->set_pos( Point2(4,4)); - view_menu->set_text("[view]"); view_menu->set_self_opacity(0.5); - view_menu->get_popup()->add_item("Top",VIEW_TOP); - view_menu->get_popup()->add_item("Bottom",VIEW_BOTTOM); - view_menu->get_popup()->add_item("Left",VIEW_LEFT); - view_menu->get_popup()->add_item("Right",VIEW_RIGHT); - view_menu->get_popup()->add_item("Front",VIEW_FRONT); - view_menu->get_popup()->add_item("Rear",VIEW_REAR); + view_menu->get_popup()->add_item("Top (Num7)",VIEW_TOP); + view_menu->get_popup()->add_item("Bottom (Shift+Num7)",VIEW_BOTTOM); + view_menu->get_popup()->add_item("Left (Num3)",VIEW_LEFT); + view_menu->get_popup()->add_item("Right (Shift+Num3)",VIEW_RIGHT); + view_menu->get_popup()->add_item("Front (Num1)",VIEW_FRONT); + view_menu->get_popup()->add_item("Rear (Shift+Num1)",VIEW_REAR); view_menu->get_popup()->add_separator(); - view_menu->get_popup()->add_check_item("Perspective",VIEW_PERSPECTIVE); - view_menu->get_popup()->add_check_item("Orthogonal",VIEW_ORTHOGONAL); + view_menu->get_popup()->add_check_item("Perspective (Num5)",VIEW_PERSPECTIVE); + view_menu->get_popup()->add_check_item("Orthogonal (Num5)",VIEW_ORTHOGONAL); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_PERSPECTIVE),true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_item("Environment",VIEW_ENVIRONMENT); @@ -2216,6 +2272,10 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed viewport->set_as_audio_listener(true); } + + name="Top"; + _update_name(); + EditorSettings::get_singleton()->connect("settings_changed",this,"update_transform_gizmo_view"); } @@ -2313,7 +2373,7 @@ Object *SpatialEditor::_get_editor_data(Object *p_what) { // si->aabb = VisualServer::get_singleton()->instance_get_base_aabb(inst); - if (get_scene()->is_editor_hint()) + if (get_tree()->is_editor_hint()) editor->call("edit_node",sp); @@ -2454,7 +2514,7 @@ void SpatialEditor::set_state(const Dictionary& p_state) { VisualServer::get_singleton()->free(light_instance); light_instance=RID(); } else { - light_instance=VisualServer::get_singleton()->instance_create2(light,get_scene()->get_root()->get_world()->get_scenario()); + light_instance=VisualServer::get_singleton()->instance_create2(light,get_tree()->get_root()->get_world()->get_scenario()); VisualServer::get_singleton()->instance_set_transform(light_instance,light_transform); } @@ -2656,7 +2716,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { VisualServer::get_singleton()->free(light_instance); light_instance=RID(); } else { - light_instance=VisualServer::get_singleton()->instance_create2(light,get_scene()->get_root()->get_world()->get_scenario()); + light_instance=VisualServer::get_singleton()->instance_create2(light,get_tree()->get_root()->get_world()->get_scenario()); VisualServer::get_singleton()->instance_set_transform(light_instance,light_transform); _update_default_light_angle(); @@ -2828,7 +2888,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { case MENU_VIEW_DISPLAY_NORMAL: { - VisualServer::get_singleton()->scenario_set_debug( get_scene()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_DISABLED ); + VisualServer::get_singleton()->scenario_set_debug( get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_DISABLED ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), true ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false ); @@ -2838,7 +2898,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_DISPLAY_WIREFRAME: { - VisualServer::get_singleton()->scenario_set_debug( get_scene()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_WIREFRAME ); + VisualServer::get_singleton()->scenario_set_debug( get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_WIREFRAME ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), true ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false ); @@ -2847,7 +2907,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_DISPLAY_OVERDRAW: { - VisualServer::get_singleton()->scenario_set_debug( get_scene()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW ); + VisualServer::get_singleton()->scenario_set_debug( get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_OVERDRAW ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), true ); @@ -2856,7 +2916,7 @@ void SpatialEditor::_menu_item_pressed(int p_option) { } break; case MENU_VIEW_DISPLAY_SHADELESS: { - VisualServer::get_singleton()->scenario_set_debug( get_scene()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS ); + VisualServer::get_singleton()->scenario_set_debug( get_tree()->get_root()->get_world()->get_scenario(), VisualServer::SCENARIO_DEBUG_SHADELESS ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_NORMAL), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME), false ); view_menu->get_popup()->set_item_checked( view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_OVERDRAW), false ); @@ -2903,7 +2963,7 @@ void SpatialEditor::_init_indicators() { //make sure that the camera indicator is not selectable light=VisualServer::get_singleton()->light_create( VisualServer::LIGHT_DIRECTIONAL ); //VisualServer::get_singleton()->light_set_shadow( light, true ); - light_instance=VisualServer::get_singleton()->instance_create2(light,get_scene()->get_root()->get_world()->get_scenario()); + light_instance=VisualServer::get_singleton()->instance_create2(light,get_tree()->get_root()->get_world()->get_scenario()); @@ -2964,7 +3024,7 @@ void SpatialEditor::_init_indicators() { d[VisualServer::ARRAY_COLOR]=grid_colors[i]; VisualServer::get_singleton()->mesh_add_surface(grid[i],VisualServer::PRIMITIVE_LINES,d); VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat); - grid_instance[i] = VisualServer::get_singleton()->instance_create2(grid[i],get_scene()->get_root()->get_world()->get_scenario()); + grid_instance[i] = VisualServer::get_singleton()->instance_create2(grid[i],get_tree()->get_root()->get_world()->get_scenario()); grid_visible[i]=false; grid_enable[i]=false; @@ -2988,7 +3048,7 @@ void SpatialEditor::_init_indicators() { // origin = VisualServer::get_singleton()->poly_create(); // VisualServer::get_singleton()->poly_add_primitive(origin,origin_points,Vector<Vector3>(),origin_colors,Vector<Vector3>()); // VisualServer::get_singleton()->poly_set_material(origin,indicator_mat,true); - origin_instance = VisualServer::get_singleton()->instance_create2(origin,get_scene()->get_root()->get_world()->get_scenario()); + origin_instance = VisualServer::get_singleton()->instance_create2(origin,get_tree()->get_root()->get_world()->get_scenario()); VS::get_singleton()->instance_set_layer_mask(origin_instance,1<<SpatialEditorViewport::GIZMO_GRID_LAYER); VisualServer::get_singleton()->instance_geometry_set_flag(origin_instance,VS::INSTANCE_FLAG_CAST_SHADOW,false); @@ -3025,7 +3085,7 @@ void SpatialEditor::_init_indicators() { VisualServer::get_singleton()->mesh_add_surface(cursor_mesh,VS::PRIMITIVE_LINES,d); VisualServer::get_singleton()->mesh_surface_set_material(cursor_mesh,0,cmat,true); - cursor_instance = VisualServer::get_singleton()->instance_create2(cursor_mesh,get_scene()->get_root()->get_world()->get_scenario()); + cursor_instance = VisualServer::get_singleton()->instance_create2(cursor_mesh,get_tree()->get_root()->get_world()->get_scenario()); VS::get_singleton()->instance_set_layer_mask(cursor_instance,1<<SpatialEditorViewport::GIZMO_GRID_LAYER); VisualServer::get_singleton()->instance_geometry_set_flag(cursor_instance,VS::INSTANCE_FLAG_CAST_SHADOW,false); @@ -3306,19 +3366,19 @@ void SpatialEditor::_notification(int p_what) { _menu_item_pressed(MENU_VIEW_USE_1_VIEWPORT); - get_scene()->connect("node_removed",this,"_node_removed"); + get_tree()->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) { + if (p_what==NOTIFICATION_ENTER_TREE) { gizmos = memnew( SpatialEditorGizmos ); _init_indicators(); _update_default_light_angle(); } - if (p_what==NOTIFICATION_EXIT_SCENE) { + if (p_what==NOTIFICATION_EXIT_TREE) { _finish_indicators(); memdelete( gizmos ); @@ -3633,12 +3693,12 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { 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); - p->add_check_item("2 Viewports",MENU_VIEW_USE_2_VIEWPORTS,KEY_MASK_ALT+KEY_2); - p->add_check_item("2 Viewports (Alt)",MENU_VIEW_USE_2_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_ALT+KEY_2); - p->add_check_item("3 Viewports",MENU_VIEW_USE_3_VIEWPORTS,KEY_MASK_ALT+KEY_3); - p->add_check_item("3 Viewports (Alt)",MENU_VIEW_USE_3_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_ALT+KEY_3); - p->add_check_item("4 Viewports",MENU_VIEW_USE_4_VIEWPORTS,KEY_MASK_ALT+KEY_4); + p->add_check_item("1 Viewport",MENU_VIEW_USE_1_VIEWPORT,KEY_MASK_CMD+KEY_1); + p->add_check_item("2 Viewports",MENU_VIEW_USE_2_VIEWPORTS,KEY_MASK_CMD+KEY_2); + p->add_check_item("2 Viewports (Alt)",MENU_VIEW_USE_2_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_2); + p->add_check_item("3 Viewports",MENU_VIEW_USE_3_VIEWPORTS,KEY_MASK_CMD+KEY_3); + p->add_check_item("3 Viewports (Alt)",MENU_VIEW_USE_3_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_3); + p->add_check_item("4 Viewports",MENU_VIEW_USE_4_VIEWPORTS,KEY_MASK_CMD+KEY_4); p->add_separator(); p->add_check_item("Display Normal",MENU_VIEW_DISPLAY_NORMAL); @@ -3649,7 +3709,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_check_item("View Origin",MENU_VIEW_ORIGIN); p->add_check_item("View Grid",MENU_VIEW_GRID); p->add_separator(); - p->add_check_item("Settings",MENU_VIEW_CAMERA_SETTINGS ); + p->add_item("Settings",MENU_VIEW_CAMERA_SETTINGS); p->set_item_checked( p->get_item_index(MENU_VIEW_USE_DEFAULT_LIGHT), true ); diff --git a/tools/editor/plugins/spatial_editor_plugin.h b/tools/editor/plugins/spatial_editor_plugin.h index 1fdc97c49d..4d594d1921 100644 --- a/tools/editor/plugins/spatial_editor_plugin.h +++ b/tools/editor/plugins/spatial_editor_plugin.h @@ -92,6 +92,7 @@ public: }; private: int index; + String name; void _menu_option(int p_option); Size2 prev_size; @@ -110,6 +111,7 @@ private: bool orthogonal; float gizmo_scale; + void _update_name(); void _compute_edit(const Point2& p_point); void _clear_selected(); void _select_clicked(bool p_append,bool p_single); @@ -144,6 +146,12 @@ private: }; NavigationScheme _get_navigation_schema(const String& p_property); + enum NavigationZoomStyle { + NAVIGATION_ZOOM_VERTICAL, + NAVIGATION_ZOOM_HORIZONTAL + }; + NavigationZoomStyle _get_navigation_zoom_style(const String& p_property); + enum NavigationMode { NAVIGATION_NONE, NAVIGATION_PAN, diff --git a/tools/editor/plugins/sprite_frames_editor_plugin.cpp b/tools/editor/plugins/sprite_frames_editor_plugin.cpp index a26fab0f9a..9a9e8ee611 100644 --- a/tools/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/tools/editor/plugins/sprite_frames_editor_plugin.cpp @@ -46,7 +46,7 @@ void SpriteFramesEditor::_notification(int p_what) { } - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { load->set_icon( get_icon("Folder","EditorIcons") ); _delete->set_icon( get_icon("Del","EditorIcons") ); } @@ -229,6 +229,33 @@ void SpriteFramesEditor::_empty_pressed() { } +void SpriteFramesEditor::_empty2_pressed() { + + + int from=-1; + + if (tree->get_selected()) { + + from = tree->get_selected()->get_metadata(0); + sel=from; + + } else { + from=frames->get_frame_count(); + } + + + + Ref<Texture> r; + + undo_redo->create_action("Add Empty"); + undo_redo->add_do_method(frames,"add_frame",r,from+1); + undo_redo->add_undo_method(frames,"remove_frame",from+1); + undo_redo->add_do_method(this,"_update_library"); + undo_redo->add_undo_method(this,"_update_library"); + undo_redo->commit_action(); + +} + void SpriteFramesEditor::_up_pressed() { if (!tree->get_selected()) @@ -322,6 +349,8 @@ void SpriteFramesEditor::_update_library() { ti->set_text(0,"Frame "+itos(i)); ti->set_icon(0,frames->get_frame(i)); } + if (frames->get_frame(i).is_valid()) + ti->set_tooltip(0,frames->get_frame(i)->get_path()); ti->set_metadata(0,i); ti->set_icon_max_width(0,96); if (sel==i) @@ -355,6 +384,7 @@ void SpriteFramesEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&SpriteFramesEditor::_input_event); ObjectTypeDB::bind_method(_MD("_load_pressed"),&SpriteFramesEditor::_load_pressed); ObjectTypeDB::bind_method(_MD("_empty_pressed"),&SpriteFramesEditor::_empty_pressed); + ObjectTypeDB::bind_method(_MD("_empty2_pressed"),&SpriteFramesEditor::_empty2_pressed); ObjectTypeDB::bind_method(_MD("_item_edited"),&SpriteFramesEditor::_item_edited); ObjectTypeDB::bind_method(_MD("_delete_pressed"),&SpriteFramesEditor::_delete_pressed); ObjectTypeDB::bind_method(_MD("_paste_pressed"),&SpriteFramesEditor::_paste_pressed); @@ -387,9 +417,13 @@ SpriteFramesEditor::SpriteFramesEditor() { hbc->add_child(paste); empty = memnew( Button ); - empty->set_text("Insert Empty"); + empty->set_text("Insert Empty (Before)"); hbc->add_child(empty); + empty2 = memnew( Button ); + empty2->set_text("Insert Empty (After)"); + hbc->add_child(empty2); + move_up = memnew( Button ); move_up->set_text("Up"); hbc->add_child(move_up); @@ -422,6 +456,7 @@ SpriteFramesEditor::SpriteFramesEditor() { _delete->connect("pressed", this,"_delete_pressed"); paste->connect("pressed", this,"_paste_pressed"); empty->connect("pressed", this,"_empty_pressed"); + empty2->connect("pressed", this,"_empty2_pressed"); move_up->connect("pressed", this,"_up_pressed"); move_down->connect("pressed", this,"_down_pressed"); file->connect("files_selected", this,"_file_load_request"); diff --git a/tools/editor/plugins/sprite_frames_editor_plugin.h b/tools/editor/plugins/sprite_frames_editor_plugin.h index 99c6ad486e..b0f2201b9e 100644 --- a/tools/editor/plugins/sprite_frames_editor_plugin.h +++ b/tools/editor/plugins/sprite_frames_editor_plugin.h @@ -46,6 +46,7 @@ class SpriteFramesEditor : public PanelContainer { Button *_delete; Button *paste; Button *empty; + Button *empty2; Button *move_up; Button *move_down; Tree *tree; @@ -65,6 +66,7 @@ class SpriteFramesEditor : public PanelContainer { void _file_load_request(const DVector<String>& p_path); void _paste_pressed(); void _empty_pressed(); + void _empty2_pressed(); void _delete_pressed(); void _delete_confirm_pressed(); void _up_pressed(); diff --git a/tools/editor/plugins/stream_editor_plugin.cpp b/tools/editor/plugins/stream_editor_plugin.cpp index 4588c694ee..6477cce47c 100644 --- a/tools/editor/plugins/stream_editor_plugin.cpp +++ b/tools/editor/plugins/stream_editor_plugin.cpp @@ -32,7 +32,7 @@ void StreamEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { play->set_icon( get_icon("Play","EditorIcons") ); stop->set_icon( get_icon("Stop","EditorIcons") ); } diff --git a/tools/editor/plugins/theme_editor_plugin.cpp b/tools/editor/plugins/theme_editor_plugin.cpp index ccbd923118..bd6fb37b29 100644 --- a/tools/editor/plugins/theme_editor_plugin.cpp +++ b/tools/editor/plugins/theme_editor_plugin.cpp @@ -568,6 +568,26 @@ ThemeEditor::ThemeEditor() { CheckButton *cb = memnew( CheckButton ); cb->set_text("CheckButton"); first_vb->add_child(cb ); + CheckBox *cbx = memnew( CheckBox ); + cbx->set_text("CheckBox"); + first_vb->add_child(cbx ); + + /* TODO: This is not working properly, controls are overlapping*/ + /* + ButtonGroup *bg = memnew( ButtonGroup ); + bg->set_v_size_flags(SIZE_EXPAND_FILL); + VBoxContainer *gbvb = memnew( VBoxContainer ); + gbvb->set_v_size_flags(SIZE_EXPAND_FILL); + CheckBox *rbx1 = memnew( CheckBox ); + rbx1->set_text("CheckBox Radio1"); + rbx1->set_pressed(true); + gbvb->add_child(rbx1); + CheckBox *rbx2 = memnew( CheckBox ); + rbx2->set_text("CheckBox Radio2"); + gbvb->add_child(rbx2); + bg->add_child(gbvb); + first_vb->add_child(bg); + */ MenuButton* test_menu_button = memnew( MenuButton ); test_menu_button->set_text("MenuButton"); diff --git a/tools/editor/plugins/theme_editor_plugin.h b/tools/editor/plugins/theme_editor_plugin.h index 98156422ee..83432b9232 100644 --- a/tools/editor/plugins/theme_editor_plugin.h +++ b/tools/editor/plugins/theme_editor_plugin.h @@ -33,6 +33,8 @@ #include "scene/gui/texture_frame.h" #include "scene/gui/option_button.h" #include "scene/gui/file_dialog.h" +#include "scene/gui/check_box.h" +#include "scene/gui/button_group.h" #include "tools/editor/editor_node.h" diff --git a/tools/editor/plugins/tile_map_editor_plugin.cpp b/tools/editor/plugins/tile_map_editor_plugin.cpp index a25997108b..79e43f9012 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.cpp +++ b/tools/editor/plugins/tile_map_editor_plugin.cpp @@ -34,7 +34,7 @@ #include "os/file_access.h" #include "tools/editor/editor_settings.h" #include "os/input.h" - +#include "method_bind_ext.inc" void TileMapEditor::_notification(int p_what) { @@ -42,9 +42,13 @@ void TileMapEditor::_notification(int p_what) { case NOTIFICATION_READY: { - pane_drag->connect("dragged", this,"_pane_drag"); + transpose->set_icon( get_icon("Transpose","EditorIcons")); mirror_x->set_icon( get_icon("MirrorX","EditorIcons")); mirror_y->set_icon( get_icon("MirrorY","EditorIcons")); + rotate_0->set_icon( get_icon("Rotate0","EditorIcons")); + rotate_90->set_icon( get_icon("Rotate90","EditorIcons")); + rotate_180->set_icon( get_icon("Rotate180","EditorIcons")); + rotate_270->set_icon( get_icon("Rotate270","EditorIcons")); } break; } @@ -74,24 +78,43 @@ int TileMapEditor::get_selected_tile() const { return item->get_metadata(0); } -void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bool p_flip_v,bool p_with_undo) { +void TileMapEditor::set_selected_tile(int p_tile) { + TreeItem *item = palette->get_root()->get_children(); + while (item) { + if ((int)item->get_metadata(0) == p_tile) { + item->select(0); + palette->ensure_cursor_is_visible(); + break; + } + item = item->get_next(); + } +} + +// Wrapper to workaround five arg limit of undo/redo methods +void TileMapEditor::_set_cell_shortened(const Point2& p_pos,int p_value,bool p_flip_h, bool p_flip_v, bool p_transpose) { + ERR_FAIL_COND(!node); + node->set_cell(floor(p_pos.x), floor(p_pos.y), p_value, p_flip_h, p_flip_v, p_transpose); +} + +void TileMapEditor::_set_cell(const Point2i& p_pos,int p_value,bool p_flip_h, bool p_flip_v, bool p_transpose,bool p_with_undo) { ERR_FAIL_COND(!node); bool prev_flip_h=node->is_cell_x_flipped(p_pos.x,p_pos.y); bool prev_flip_v=node->is_cell_y_flipped(p_pos.x,p_pos.y); + bool prev_transpose=node->is_cell_transposed(p_pos.x,p_pos.y); int prev_val=node->get_cell(p_pos.x,p_pos.y); - if (p_value==prev_val && p_flip_h==prev_flip_h && p_flip_v==prev_flip_v) + if (p_value==prev_val && p_flip_h==prev_flip_h && p_flip_v==prev_flip_v && p_transpose==prev_transpose) return; //check that it's actually different if (p_with_undo) { - undo_redo->add_do_method(node,"set_cell",p_pos.x,p_pos.y,p_value,p_flip_h,p_flip_v); - undo_redo->add_undo_method(node,"set_cell",p_pos.x,p_pos.y,prev_val,prev_flip_h,prev_flip_v); + undo_redo->add_do_method(this,"_set_cell_shortened",Point2(p_pos),p_value,p_flip_h,p_flip_v,p_transpose); + undo_redo->add_undo_method(this,"_set_cell_shortened",Point2(p_pos),prev_val,prev_flip_h,prev_flip_v,prev_transpose); } else { - node->set_cell(p_pos.x,p_pos.y,p_value,p_flip_h,p_flip_v); + node->set_cell(p_pos.x,p_pos.y,p_value,p_flip_h,p_flip_v,p_transpose); } @@ -157,6 +180,7 @@ struct _TileMapEditorCopyData { int cell; bool flip_h; bool flip_v; + bool transpose; }; bool TileMapEditor::forward_input_event(const InputEvent& p_event) { @@ -193,6 +217,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { tcd.cell=node->get_cell(j,i); tcd.flip_h=node->is_cell_x_flipped(j,i); tcd.flip_v=node->is_cell_y_flipped(j,i); + tcd.transpose=node->is_cell_transposed(j,i); dupdata.push_back(tcd); @@ -203,7 +228,7 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { for (List<_TileMapEditorCopyData>::Element *E=dupdata.front();E;E=E->next()) { - _set_cell(E->get().pos+ofs,E->get().cell,E->get().flip_h,E->get().flip_v,true); + _set_cell(E->get().pos+ofs,E->get().cell,E->get().flip_h,E->get().flip_v,E->get().transpose,true); } undo_redo->commit_action(); @@ -225,28 +250,29 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { canvas_item_editor->update(); return true; + } else if (mb.mod.control) { + tool=TOOL_PICKING; + set_selected_tile(node->get_cell(over_tile.x, over_tile.y)); + mirror_x->set_pressed(node->is_cell_x_flipped(over_tile.x, over_tile.y)); + mirror_y->set_pressed(node->is_cell_y_flipped(over_tile.x, over_tile.y)); + transpose->set_pressed(node->is_cell_transposed(over_tile.x, over_tile.y)); + _update_transform_buttons(); + canvas_item_editor->update(); + return true; } else { int id = get_selected_tile(); if (id!=TileMap::INVALID_CELL) { tool=TOOL_PAINTING; Point2i local =node->world_to_map((xform_inv.xform(Point2(mb.x,mb.y)))); paint_undo.clear(); - CellOp op; - op.idx = node->get_cell(local.x,local.y); - if (op.idx>=0) { - if (node->is_cell_x_flipped(local.x,local.y)) - op.xf=true; - if (node->is_cell_y_flipped(local.x,local.y)) - op.yf=true; - } - paint_undo[local]=op; - node->set_cell(local.x,local.y,id,mirror_x->is_pressed(),mirror_y->is_pressed()); + paint_undo[local]=_get_op_from_cell(local); + node->set_cell(local.x,local.y,id,mirror_x->is_pressed(),mirror_y->is_pressed(),transpose->is_pressed()); return true; } } } else { - if (tool==TOOL_PAINTING || tool == TOOL_SELECTING) { + if (tool==TOOL_PAINTING || tool == TOOL_SELECTING || tool == TOOL_PICKING) { if (tool==TOOL_PAINTING) { @@ -255,8 +281,8 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { for(Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) { Point2i p=E->key(); - undo_redo->add_do_method(node,"set_cell",p.x,p.y,node->get_cell(p.x,p.y),node->is_cell_x_flipped(p.x,p.y),node->is_cell_y_flipped(p.x,p.y)); - undo_redo->add_undo_method(node,"set_cell",p.x,p.y,E->get().idx,E->get().xf,E->get().yf); + undo_redo->add_do_method(this,"_set_cell_shortened",Point2(p),node->get_cell(p.x,p.y),node->is_cell_x_flipped(p.x,p.y),node->is_cell_y_flipped(p.x,p.y),node->is_cell_transposed(p.x,p.y)); + undo_redo->add_undo_method(this,"_set_cell_shortened",Point2(p),E->get().idx,E->get().xf,E->get().yf,E->get().tr); } undo_redo->commit_action(); @@ -280,16 +306,8 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { tool=TOOL_ERASING; Point2i local =node->world_to_map(xform_inv.xform(Point2(mb.x,mb.y))); paint_undo.clear(); - CellOp op; - op.idx = node->get_cell(local.x,local.y); - if (op.idx>=0) { - if (node->is_cell_x_flipped(local.x,local.y)) - op.xf=true; - if (node->is_cell_y_flipped(local.x,local.y)) - op.yf=true; - } - paint_undo[local]=op; - //node->set_cell(local.x,local.y,id,mirror_x->is_pressed(),mirror_y->is_pressed()); + paint_undo[local]=_get_op_from_cell(local); + //node->set_cell(local.x,local.y,id,mirror_x->is_pressed(),mirror_y->is_pressed(),transpose->is_pressed()); //return true; _set_cell(local,TileMap::INVALID_CELL); return true; @@ -302,9 +320,9 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { for(Map<Point2i,CellOp>::Element *E=paint_undo.front();E;E=E->next()) { Point2i p=E->key(); - //undo_redo->add_do_method(node,"set_cell",p.x,p.y,node->get_cell(p.x,p.y),node->is_cell_x_flipped(p.x,p.y),node->is_cell_y_flipped(p.x,p.y)); - _set_cell(p,TileMap::INVALID_CELL,false,false,true); - undo_redo->add_undo_method(node,"set_cell",p.x,p.y,E->get().idx,E->get().xf,E->get().yf); + //undo_redo->add_do_method(node,"set_cell",p.x,p.y,node->get_cell(p.x,p.y),node->is_cell_x_flipped(p.x,p.y),node->is_cell_y_flipped(p.x,p.y),node->is_cell_transposed(p.x,p.y)); + _set_cell(p,TileMap::INVALID_CELL,false,false,false,true); + undo_redo->add_undo_method(this,"_set_cell_shortened",Point2(p),E->get().idx,E->get().xf,E->get().yf,E->get().tr); } undo_redo->commit_action(); @@ -338,17 +356,9 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { if (!paint_undo.has(over_tile)) { - CellOp op; - op.idx = node->get_cell(over_tile.x,over_tile.y); - if (op.idx>=0) { - if (node->is_cell_x_flipped(over_tile.x,over_tile.y)) - op.xf=true; - if (node->is_cell_y_flipped(over_tile.x,over_tile.y)) - op.yf=true; - } - paint_undo[over_tile]=op; + paint_undo[over_tile]=_get_op_from_cell(over_tile); } - node->set_cell(over_tile.x,over_tile.y,id,mirror_x->is_pressed(),mirror_y->is_pressed()); + node->set_cell(over_tile.x,over_tile.y,id,mirror_x->is_pressed(),mirror_y->is_pressed(),transpose->is_pressed()); return true; } @@ -375,25 +385,26 @@ bool TileMapEditor::forward_input_event(const InputEvent& p_event) { return true; } + if (tool==TOOL_ERASING) { Point2i local =over_tile; if (!paint_undo.has(over_tile)) { - - CellOp op; - op.idx = node->get_cell(over_tile.x,over_tile.y); - if (op.idx>=0) { - if (node->is_cell_x_flipped(over_tile.x,over_tile.y)) - op.xf=true; - if (node->is_cell_y_flipped(over_tile.x,over_tile.y)) - op.yf=true; - } - paint_undo[over_tile]=op; + paint_undo[over_tile]=_get_op_from_cell(over_tile); } - //node->set_cell(over_tile.x,over_tile.y,id,mirror_x->is_pressed(),mirror_y->is_pressed()); + //node->set_cell(over_tile.x,over_tile.y,id,mirror_x->is_pressed(),mirror_y->is_pressed(),transpose->is_pressed()); _set_cell(local,TileMap::INVALID_CELL); return true; } + if (tool==TOOL_PICKING) { + set_selected_tile(node->get_cell(over_tile.x, over_tile.y)); + mirror_x->set_pressed(node->is_cell_x_flipped(over_tile.x, over_tile.y)); + mirror_y->set_pressed(node->is_cell_y_flipped(over_tile.x, over_tile.y)); + transpose->set_pressed(node->is_cell_transposed(over_tile.x, over_tile.y)); + _update_transform_buttons(); + canvas_item_editor->update(); + return true; + } } break; case InputEvent::KEY: { @@ -629,19 +640,53 @@ void TileMapEditor::_canvas_draw() { Ref<Texture> t = ts->tile_get_texture(st); if (t.is_valid()) { - Vector2 from = xform.xform(ts->tile_get_texture_offset(st)+node->map_to_world(over_tile)+node->get_cell_draw_offset()); + Vector2 from = node->map_to_world(over_tile)+node->get_cell_draw_offset(); Rect2 r = ts->tile_get_region(st); Size2 sc = xform.get_scale(); if (mirror_x->is_pressed()) sc.x*=-1.0; if (mirror_y->is_pressed()) sc.y*=-1.0; + + Rect2 rect; + if (r==Rect2()) { + rect=Rect2(from,t->get_size()); + } else { + + rect=Rect2(from,r.get_size()); + } + + + if (node->get_tile_origin()==TileMap::TILE_ORIGIN_TOP_LEFT) { + rect.pos+=ts->tile_get_texture_offset(st); + + } else if (node->get_tile_origin()==TileMap::TILE_ORIGIN_CENTER) { + rect.pos+=node->get_cell_size()/2; + Vector2 s = r.size; + + Vector2 center = (s/2) - ts->tile_get_texture_offset(st); + + + if (mirror_x->is_pressed()) + rect.pos.x-=s.x-center.x; + else + rect.pos.x-=center.x; + + if (mirror_y->is_pressed()) + rect.pos.y-=s.y-center.y; + else + rect.pos.y-=center.y; + } + + rect.pos=xform.xform(rect.pos); + rect.size*=sc; + if (r==Rect2()) { - canvas_item_editor->draw_texture_rect(t,Rect2(from,t->get_size()*sc),false,Color(1,1,1,0.5)); + canvas_item_editor->draw_texture_rect(t,rect,false,Color(1,1,1,0.5),transpose->is_pressed()); } else { - canvas_item_editor->draw_texture_rect_region(t,Rect2(from,r.get_size()*sc),r,Color(1,1,1,0.5)); + canvas_item_editor->draw_texture_rect_region(t,rect,r,Color(1,1,1,0.5),transpose->is_pressed()); } } } @@ -701,27 +746,79 @@ void TileMapEditor::_tileset_settings_changed() { canvas_item_editor->update(); } -void TileMapEditor::_pane_drag(const Point2& p_to) { - - int x = theme_panel->get_margin(MARGIN_RIGHT); - - x+=p_to.x; - if (x<10) - x=10; - if (x>300) - x=300; - theme_panel->set_margin(MARGIN_RIGHT,x); -} - void TileMapEditor::_bind_methods() { ObjectTypeDB::bind_method(_MD("_menu_option"),&TileMapEditor::_menu_option); ObjectTypeDB::bind_method(_MD("_canvas_draw"),&TileMapEditor::_canvas_draw); - ObjectTypeDB::bind_method(_MD("_pane_drag"),&TileMapEditor::_pane_drag); ObjectTypeDB::bind_method(_MD("_canvas_mouse_enter"),&TileMapEditor::_canvas_mouse_enter); ObjectTypeDB::bind_method(_MD("_canvas_mouse_exit"),&TileMapEditor::_canvas_mouse_exit); ObjectTypeDB::bind_method(_MD("_tileset_settings_changed"),&TileMapEditor::_tileset_settings_changed); + ObjectTypeDB::bind_method(_MD("_update_transform_buttons"),&TileMapEditor::_update_transform_buttons); + ObjectTypeDB::bind_method(_MD("_set_cell_shortened","pos","tile","flip_x","flip_y","transpose"),&TileMapEditor::_set_cell_shortened,DEFVAL(false),DEFVAL(false),DEFVAL(false)); + +} +TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i& p_pos) +{ + CellOp op; + op.idx = node->get_cell(p_pos.x,p_pos.y); + if (op.idx>=0) { + if (node->is_cell_x_flipped(p_pos.x,p_pos.y)) + op.xf=true; + if (node->is_cell_y_flipped(p_pos.x,p_pos.y)) + op.yf=true; + if (node->is_cell_transposed(p_pos.x,p_pos.y)) + op.tr=true; + } + return op; +} + +void TileMapEditor::_update_transform_buttons(Object *p_button) { + //ERR_FAIL_NULL(p_button); + ToolButton *b=p_button->cast_to<ToolButton>(); + //ERR_FAIL_COND(!b); + + mirror_x->set_block_signals(true); + mirror_y->set_block_signals(true); + transpose->set_block_signals(true); + rotate_0->set_block_signals(true); + rotate_90->set_block_signals(true); + rotate_180->set_block_signals(true); + rotate_270->set_block_signals(true); + + if (b == rotate_0) { + mirror_x->set_pressed(false); + mirror_y->set_pressed(false); + transpose->set_pressed(false); + } + else if (b == rotate_90) { + mirror_x->set_pressed(true); + mirror_y->set_pressed(false); + transpose->set_pressed(true); + } + else if (b == rotate_180) { + mirror_x->set_pressed(true); + mirror_y->set_pressed(true); + transpose->set_pressed(false); + } + else if (b == rotate_270) { + mirror_x->set_pressed(false); + mirror_y->set_pressed(true); + transpose->set_pressed(true); + } + + rotate_0->set_pressed(!mirror_x->is_pressed() && !mirror_y->is_pressed() && !transpose->is_pressed()); + rotate_90->set_pressed(mirror_x->is_pressed() && !mirror_y->is_pressed() && transpose->is_pressed()); + rotate_180->set_pressed(mirror_x->is_pressed() && mirror_y->is_pressed() && !transpose->is_pressed()); + rotate_270->set_pressed(!mirror_x->is_pressed() && mirror_y->is_pressed() && transpose->is_pressed()); + + mirror_x->set_block_signals(false); + mirror_y->set_block_signals(false); + transpose->set_block_signals(false); + rotate_0->set_block_signals(false); + rotate_90->set_block_signals(false); + rotate_180->set_block_signals(false); + rotate_270->set_block_signals(false); } TileMapEditor::TileMapEditor(EditorNode *p_editor) { @@ -731,37 +828,66 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { editor=p_editor; undo_redo = editor->get_undo_redo(); - theme_panel = memnew( Panel ); - theme_panel->set_anchor(MARGIN_BOTTOM,ANCHOR_END); - theme_panel->set_begin( Point2(0,26)); - theme_panel->set_end( Point2(100,0) ); - p_editor->get_viewport()->add_child(theme_panel); - theme_panel->hide(); + int mw = EDITOR_DEF("tile_map/palette_min_width",80); + Control *ec = memnew( Control); + ec->set_custom_minimum_size(Size2(mw,0)); + add_child(ec); + // Add tile palette palette = memnew( Tree ); - palette->set_area_as_parent_rect(4); - palette->set_margin(MARGIN_TOP,25);; - theme_panel->add_child(palette); - - pane_drag = memnew( PaneDrag ) ; - pane_drag->set_anchor(MARGIN_LEFT,ANCHOR_END); - pane_drag->set_begin(Point2(16,4)); - theme_panel->add_child(pane_drag); - - add_child( memnew( VSeparator )); - + palette->set_v_size_flags(SIZE_EXPAND_FILL); + add_child(palette); + + // Add menu items + canvas_item_editor_hb = memnew( HBoxContainer ); + CanvasItemEditor::get_singleton()->add_control_to_menu_panel(canvas_item_editor_hb); + canvas_item_editor_hb->add_child( memnew( VSeparator )); + transpose = memnew( ToolButton ); + transpose->set_toggle_mode(true); + transpose->set_tooltip("Transpose"); + transpose->set_focus_mode(FOCUS_NONE); + transpose->connect("pressed", this, "_update_transform_buttons", make_binds(transpose)); + canvas_item_editor_hb->add_child(transpose); mirror_x = memnew( ToolButton ); mirror_x->set_toggle_mode(true); mirror_x->set_tooltip("Mirror X (A)"); mirror_x->set_focus_mode(FOCUS_NONE); - add_child(mirror_x); + mirror_x->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_x)); + canvas_item_editor_hb->add_child(mirror_x); mirror_y = memnew( ToolButton ); mirror_y->set_toggle_mode(true); mirror_y->set_tooltip("Mirror Y (S)"); mirror_y->set_focus_mode(FOCUS_NONE); - add_child(mirror_y); - - + mirror_y->connect("pressed", this, "_update_transform_buttons", make_binds(mirror_y)); + canvas_item_editor_hb->add_child(mirror_y); + canvas_item_editor_hb->add_child(memnew(VSeparator)); + rotate_0 = memnew( ToolButton ); + rotate_0->set_toggle_mode(true); + rotate_0->set_tooltip("Rotate 0 degrees"); + rotate_0->set_focus_mode(FOCUS_NONE); + rotate_0->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_0)); + canvas_item_editor_hb->add_child(rotate_0); + rotate_90 = memnew( ToolButton ); + rotate_90->set_toggle_mode(true); + rotate_90->set_tooltip("Rotate 90 degrees"); + rotate_90->set_focus_mode(FOCUS_NONE); + rotate_90->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_90)); + canvas_item_editor_hb->add_child(rotate_90); + rotate_180 = memnew( ToolButton ); + rotate_180->set_toggle_mode(true); + rotate_180->set_tooltip("Rotate 180 degrees"); + rotate_180->set_focus_mode(FOCUS_NONE); + rotate_180->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_180)); + canvas_item_editor_hb->add_child(rotate_180); + rotate_270 = memnew( ToolButton ); + rotate_270->set_toggle_mode(true); + rotate_270->set_tooltip("Rotate 270 degrees"); + rotate_270->set_focus_mode(FOCUS_NONE); + rotate_270->connect("pressed", this, "_update_transform_buttons", make_binds(rotate_270)); + canvas_item_editor_hb->add_child(rotate_270); + canvas_item_editor_hb->hide(); + + rotate_0->set_pressed(true); tool=TOOL_NONE; selection_active=false; mouse_over=false; @@ -782,12 +908,12 @@ void TileMapEditorPlugin::make_visible(bool p_visible) { if (p_visible) { tile_map_editor->show(); - tile_map_editor->theme_panel->show(); + tile_map_editor->get_canvas_item_editor_hb()->show(); } else { tile_map_editor->hide(); - tile_map_editor->theme_panel->hide(); + tile_map_editor->get_canvas_item_editor_hb()->hide(); tile_map_editor->edit(NULL); } @@ -797,7 +923,8 @@ TileMapEditorPlugin::TileMapEditorPlugin(EditorNode *p_node) { editor=p_node; tile_map_editor = memnew( TileMapEditor(p_node) ); - CanvasItemEditor::get_singleton()->add_control_to_menu_panel(tile_map_editor); + CanvasItemEditor::get_singleton()->get_palette_split()->add_child(tile_map_editor); + CanvasItemEditor::get_singleton()->get_palette_split()->move_child(tile_map_editor,0); tile_map_editor->hide(); diff --git a/tools/editor/plugins/tile_map_editor_plugin.h b/tools/editor/plugins/tile_map_editor_plugin.h index 2336507f1b..fe1295fe98 100644 --- a/tools/editor/plugins/tile_map_editor_plugin.h +++ b/tools/editor/plugins/tile_map_editor_plugin.h @@ -34,15 +34,14 @@ #include "scene/2d/tile_map.h" #include "scene/gui/tool_button.h" #include "scene/gui/button_group.h" -#include "tools/editor/pane_drag.h" /** @author Juan Linietsky <reduzio@gmail.com> */ class CanvasItemEditor; -class TileMapEditor : public HBoxContainer { +class TileMapEditor : public VBoxContainer { - OBJ_TYPE(TileMapEditor, BoxContainer ); + OBJ_TYPE(TileMapEditor, VBoxContainer ); UndoRedo *undo_redo; @@ -52,7 +51,8 @@ class TileMapEditor : public HBoxContainer { TOOL_PAINTING, TOOL_SELECTING, TOOL_ERASING, - TOOL_DUPLICATING + TOOL_DUPLICATING, + TOOL_PICKING }; Tool tool; @@ -63,7 +63,6 @@ class TileMapEditor : public HBoxContainer { Panel *panel; TileMap *node; MenuButton *options; - PaneDrag *pane_drag; bool selection_active; Point2i selection_begin; @@ -72,42 +71,51 @@ class TileMapEditor : public HBoxContainer { bool mouse_over; Label *mirror_label; + ToolButton *transpose; ToolButton *mirror_x; ToolButton *mirror_y; + ToolButton *rotate_0; + ToolButton *rotate_90; + ToolButton *rotate_180; + ToolButton *rotate_270; + + HBoxContainer *canvas_item_editor_hb; struct CellOp { int idx; bool xf; bool yf; - CellOp() { idx=-1; xf=false; yf=false; } + bool tr; + CellOp() { idx=-1; xf=false; yf=false; tr=false; } }; Map<Point2i,CellOp> paint_undo; int get_selected_tile() const; + void set_selected_tile(int p_tile); void _update_palette(); - void _pane_drag(const Point2& p_to); void _canvas_draw(); void _menu_option(int p_option); - void _set_cell(const Point2i& p_pos, int p_value, bool p_flip_h=false, bool p_flip_v=false, bool p_with_undo=false); + void _set_cell(const Point2i& p_pos, int p_value, bool p_flip_h=false, bool p_flip_v=false, bool p_transpose=false, bool p_with_undo=false); + void _set_cell_shortened(const Point2& p_pos, int p_value, bool p_flip_h=false, bool p_flip_v=false, bool p_transpose=false); void _canvas_mouse_enter(); void _canvas_mouse_exit(); void _tileset_settings_changed(); -friend class TileMapEditorPlugin; - Panel *theme_panel; protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); + CellOp _get_op_from_cell(const Point2i& p_pos); + void _update_transform_buttons(Object *p_button=0); public: - Vector2 snap_point(const Vector2& p_point) const; + HBoxContainer *get_canvas_item_editor_hb() const { return canvas_item_editor_hb; } bool forward_input_event(const InputEvent& p_event); void edit(Node *p_tile_map); TileMapEditor(EditorNode *p_editor); @@ -120,6 +128,7 @@ class TileMapEditorPlugin : public EditorPlugin { TileMapEditor *tile_map_editor; EditorNode *editor; + public: virtual bool forward_input_event(const InputEvent& p_event) { return tile_map_editor->forward_input_event(p_event); } diff --git a/tools/editor/plugins/tile_set_editor_plugin.cpp b/tools/editor/plugins/tile_set_editor_plugin.cpp index a51caf7d54..8ff7720934 100644 --- a/tools/editor/plugins/tile_set_editor_plugin.cpp +++ b/tools/editor/plugins/tile_set_editor_plugin.cpp @@ -37,83 +37,103 @@ void TileSetEditor::edit(const Ref<TileSet>& p_tileset) { void TileSetEditor::_import_scene(Node *scene, Ref<TileSet> p_library, bool p_merge) { if (!p_merge) - p_library->clear(); + p_library->clear(); for(int i=0;i<scene->get_child_count();i++) { - Node *child = scene->get_child(i); + Node *child = scene->get_child(i); - if (!child->cast_to<Sprite>()) { - if (child->get_child_count()>0) { - child=child->get_child(0); - if (!child->cast_to<Sprite>()) { - continue; - } + if (!child->cast_to<Sprite>()) { + if (child->get_child_count()>0) { + child=child->get_child(0); + if (!child->cast_to<Sprite>()) { + continue; + } - } else - continue; + } else + continue; - } + } - Sprite *mi = child->cast_to<Sprite>(); - Ref<Texture> texture=mi->get_texture(); - if (texture.is_null()) + Sprite *mi = child->cast_to<Sprite>(); + Ref<Texture> texture=mi->get_texture(); + Ref<CanvasItemMaterial> material=mi->get_material(); + + if (texture.is_null()) continue; - int id = p_library->find_tile_by_name(mi->get_name()); - if (id<0) { - - id=p_library->get_last_unused_tile_id(); - p_library->create_tile(id); - p_library->tile_set_name(id,mi->get_name()); - } - - - p_library->tile_set_texture(id,texture); - Vector2 phys_offset; - - if (mi->is_centered()) { - Size2 s; - if (mi->is_region()) { - s=mi->get_region_rect().size; - } else { - s=texture->get_size(); - } - phys_offset+=-s/2; - } - if (mi->is_region()) { - p_library->tile_set_region(id,mi->get_region_rect()); - } - - Vector<Ref<Shape2D> >collisions; - - for(int j=0;j<mi->get_child_count();j++) { - - Node *child2 = mi->get_child(j); - if (!child2->cast_to<StaticBody2D>()) - continue; - StaticBody2D *sb = child2->cast_to<StaticBody2D>(); - if (sb->get_shape_count()==0) - continue; - Ref<Shape2D> collision=sb->get_shape(0); - if (collision.is_valid()) { - collisions.push_back(collision); + int id = p_library->find_tile_by_name(mi->get_name()); + if (id<0) { + + id=p_library->get_last_unused_tile_id(); + p_library->create_tile(id); + p_library->tile_set_name(id,mi->get_name()); + } + + + + p_library->tile_set_texture(id,texture); + p_library->tile_set_material(id,material); + + Vector2 phys_offset; + + if (mi->is_centered()) { + Size2 s; + if (mi->is_region()) { + s=mi->get_region_rect().size; + } else { + s=texture->get_size(); + } + phys_offset+=-s/2; + } + if (mi->is_region()) { + p_library->tile_set_region(id,mi->get_region_rect()); + } + + Vector<Ref<Shape2D> >collisions; + Ref<NavigationPolygon> nav_poly; + Ref<OccluderPolygon2D> occluder; + + for(int j=0;j<mi->get_child_count();j++) { + + Node *child2 = mi->get_child(j); + + if (child2->cast_to<NavigationPolygonInstance>()) + nav_poly=child2->cast_to<NavigationPolygonInstance>()->get_navigation_polygon(); + + if (child2->cast_to<LightOccluder2D>()) + occluder=child2->cast_to<LightOccluder2D>()->get_occluder_polygon(); + + if (!child2->cast_to<StaticBody2D>()) + continue; + StaticBody2D *sb = child2->cast_to<StaticBody2D>(); + if (sb->get_shape_count()==0) + continue; + Ref<Shape2D> collision=sb->get_shape(0); + if (collision.is_valid()) { + collisions.push_back(collision); } - } + } - if (collisions.size()) { + if (collisions.size()) { - p_library->tile_set_shapes(id,collisions); - p_library->tile_set_shape_offset(id,-phys_offset); - } else { - p_library->tile_set_shape_offset(id,Vector2()); + p_library->tile_set_shapes(id,collisions); + p_library->tile_set_shape_offset(id,-phys_offset); + } else { + p_library->tile_set_shape_offset(id,Vector2()); + + } + + p_library->tile_set_texture_offset(id,mi->get_offset()); + p_library->tile_set_navigation_polygon(id,nav_poly); + p_library->tile_set_light_occluder(id,occluder); + p_library->tile_set_occluder_offset(id,-phys_offset); + p_library->tile_set_navigation_polygon_offset(id,-phys_offset); - } - p_library->tile_set_texture_offset(id,mi->get_offset()); } } @@ -121,23 +141,23 @@ void TileSetEditor::_menu_confirm() { switch(option) { - case MENU_OPTION_REMOVE_ITEM: { + case MENU_OPTION_REMOVE_ITEM: { - tileset->remove_tile(to_erase); - } break; - case MENU_OPTION_MERGE_FROM_SCENE: - case MENU_OPTION_CREATE_FROM_SCENE: { + tileset->remove_tile(to_erase); + } break; + case MENU_OPTION_MERGE_FROM_SCENE: + case MENU_OPTION_CREATE_FROM_SCENE: { - EditorNode *en = editor; - Node * scene = en->get_edited_scene(); - if (!scene) - break; + EditorNode *en = editor; + Node * scene = en->get_edited_scene(); + if (!scene) + break; - _import_scene(scene,tileset,option==MENU_OPTION_MERGE_FROM_SCENE); + _import_scene(scene,tileset,option==MENU_OPTION_MERGE_FROM_SCENE); - } break; + } break; } } @@ -165,11 +185,11 @@ void TileSetEditor::_menu_cbk(int p_option) { cd->set_text("Create from scene?"); cd->popup_centered(Size2(300,60)); } break; - case MENU_OPTION_MERGE_FROM_SCENE: { + case MENU_OPTION_MERGE_FROM_SCENE: { - cd->set_text("Merge from scene?"); - cd->popup_centered(Size2(300,60)); - } break; + cd->set_text("Merge from scene?"); + cd->popup_centered(Size2(300,60)); + } break; } } diff --git a/tools/editor/plugins/tile_set_editor_plugin.h b/tools/editor/plugins/tile_set_editor_plugin.h index 2531ec55bf..1248b4e007 100644 --- a/tools/editor/plugins/tile_set_editor_plugin.h +++ b/tools/editor/plugins/tile_set_editor_plugin.h @@ -56,7 +56,7 @@ class TileSetEditor : public Control { int option; void _menu_cbk(int p_option); - void _menu_confirm(); + void _menu_confirm(); static void _import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge); diff --git a/tools/editor/progress_dialog.cpp b/tools/editor/progress_dialog.cpp index 42dd971bc3..df40c5d5a5 100644 --- a/tools/editor/progress_dialog.cpp +++ b/tools/editor/progress_dialog.cpp @@ -29,7 +29,7 @@ #include "progress_dialog.h" #include "main/main.h" #include "message_queue.h" -#include "scene/gui/empty_control.h" + void BackgroundProgress::_add_task(const String& p_task,const String& p_label, int p_steps) { @@ -43,12 +43,12 @@ void BackgroundProgress::_add_task(const String& p_task,const String& p_label, i t.progress = memnew( ProgressBar ); t.progress->set_max(p_steps); t.progress->set_val(p_steps); - EmptyControl *ec = memnew( EmptyControl ); + Control *ec = memnew( Control ); ec->set_h_size_flags(SIZE_EXPAND_FILL); ec->set_v_size_flags(SIZE_EXPAND_FILL); t.progress->set_area_as_parent_rect(); ec->add_child(t.progress); - ec->set_minsize(Size2(80,5)); + ec->set_custom_minimum_size(Size2(80,5)); t.hb->add_child(ec); add_child(t.hb); @@ -182,6 +182,7 @@ void ProgressDialog::add_task(const String& p_task,const String& p_label,int p_s t.progress->set_val(p_steps); vb2->add_child(t.progress); t.state=memnew( Label ); + t.state->set_clip_text(true); vb2->add_child(t.state); main->add_child(t.vb); diff --git a/tools/editor/project_export.cpp b/tools/editor/project_export.cpp index 1da29c5e7b..449e54e12f 100644 --- a/tools/editor/project_export.cpp +++ b/tools/editor/project_export.cpp @@ -256,7 +256,7 @@ void ProjectExportDialog::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { CenterContainer *cc = memnew( CenterContainer ); @@ -320,7 +320,7 @@ void ProjectExportDialog::_notification(int p_what) { _update_group_tree(); } break; - case NOTIFICATION_EXIT_SCENE: { + case NOTIFICATION_EXIT_TREE: { } break; case MainLoop::NOTIFICATION_WM_FOCUS_IN: { @@ -482,7 +482,7 @@ Error ProjectExportDialog::export_platform(const String& p_platform, const Strin return ERR_CANT_CREATE; } else { if (p_quit_after) { - get_scene()->quit(); + get_tree()->quit(); } } @@ -529,6 +529,8 @@ void ProjectExportDialog::_group_selected() { _update_group(); //? + + _update_group_tree(); } String ProjectExportDialog::_get_selected_group() { @@ -738,6 +740,8 @@ void ProjectExportDialog::_group_changed(Variant v) { EditorNode::get_undo_redo()->add_undo_method(this,"_save_export_cfg"); EditorNode::get_undo_redo()->commit_action(); updating=false; + // update atlas preview button + _update_group(); } void ProjectExportDialog::_group_item_edited() { @@ -1236,8 +1240,8 @@ ProjectExportDialog::ProjectExportDialog(EditorNode *p_editor) { group_options->add_child(atlas_preview); atlas_preview->show(); atlas_preview->connect("pressed",this,"_group_atlas_preview"); - EmptyControl *ec = memnew(EmptyControl ); - ec->set_minsize(Size2(150,1)); + Control *ec = memnew(Control ); + ec->set_custom_minimum_size(Size2(150,1)); gvb->add_child(ec); VBoxContainer *group_vb_right = memnew( VBoxContainer ); diff --git a/tools/editor/project_export.h b/tools/editor/project_export.h index dfe7a2d900..e437497dd2 100644 --- a/tools/editor/project_export.h +++ b/tools/editor/project_export.h @@ -40,7 +40,7 @@ #include "os/dir_access.h" #include "os/thread.h" #include "scene/gui/option_button.h" -#include "scene/gui/empty_control.h" + #include "scene/gui/slider.h" #include "tools/editor/editor_file_system.h" #include "property_editor.h" diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp index 5764f9f2d9..0af4a23547 100644 --- a/tools/editor/project_manager.cpp +++ b/tools/editor/project_manager.cpp @@ -39,7 +39,7 @@ #include "scene/gui/line_edit.h" #include "scene/gui/panel_container.h" -#include "scene/gui/empty_control.h" + #include "scene/gui/texture_frame.h" #include "scene/gui/margin_container.h" #include "io/resource_saver.h" @@ -65,7 +65,7 @@ class NewProjectDialog : public ConfirmationDialog { error->set_text(""); get_ok()->set_disabled(true); DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - if (d->change_dir(project_path->get_text())!=OK) { + if (project_path->get_text() != "" && d->change_dir(project_path->get_text())!=OK) { error->set_text("Invalid Path for Project, Path Must Exist!"); memdelete(d); return false; @@ -82,7 +82,7 @@ class NewProjectDialog : public ConfirmationDialog { } else { - if (!d->file_exists("engine.cfg")) { + if (project_path->get_text() != "" && !d->file_exists("engine.cfg")) { error->set_text("Invalid Project Path (engine.cfg must exist)."); memdelete(d); @@ -321,6 +321,7 @@ public: fdialog = memnew( FileDialog ); add_child(fdialog); fdialog->set_access(FileDialog::ACCESS_FILESYSTEM); + fdialog->set_current_dir( EditorSettings::get_singleton()->get("global/default_project_path") ); project_name->connect("text_changed", this,"_text_changed"); project_path->connect("text_changed", this,"_path_text_changed"); fdialog->connect("dir_selected", this,"_path_selected"); @@ -579,8 +580,8 @@ void ProjectManager::_load_recent_projects() { VBoxContainer *vb = memnew(VBoxContainer); hb->add_child(vb); - EmptyControl *ec = memnew( EmptyControl ); - ec->set_minsize(Size2(0,1)); + Control *ec = memnew( Control ); + ec->set_custom_minimum_size(Size2(0,1)); vb->add_child(ec); Label *title = memnew( Label(project_name) ); title->add_font_override("font",get_font("large","Fonts")); @@ -627,7 +628,7 @@ void ProjectManager::_open_project_confirm() { ERR_FAIL_COND(err); } - get_scene()->quit(); + get_tree()->quit(); } void ProjectManager::_open_project() { @@ -785,7 +786,7 @@ void ProjectManager::_erase_project() { void ProjectManager::_exit_dialog() { - get_scene()->quit(); + get_tree()->quit(); } void ProjectManager::_bind_methods() { @@ -973,6 +974,11 @@ ProjectManager::ProjectManager() { npdialog->connect("project_created", this,"_load_recent_projects"); _load_recent_projects(); + + if ( EditorSettings::get_singleton()->get("global/autoscan_project_path") ) { + _scan_begin( EditorSettings::get_singleton()->get("global/autoscan_project_path") ); + } + //get_ok()->set_text("Open"); //get_ok()->set_text("Exit"); @@ -1027,7 +1033,7 @@ void ProjectListFilter::_filter_option_selected(int p_idx) { void ProjectListFilter::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { clear_search_button->set_icon(get_icon("CloseHover","EditorIcons")); } break; } diff --git a/tools/editor/project_settings.cpp b/tools/editor/project_settings.cpp index 105f251461..304fb76d1c 100644 --- a/tools/editor/project_settings.cpp +++ b/tools/editor/project_settings.cpp @@ -57,7 +57,7 @@ static const char* _button_names[JOY_BUTTON_MAX]={ void ProjectSettings::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { translation_list->connect("button_pressed",this,"_translation_delete"); _update_actions(); @@ -504,7 +504,7 @@ void ProjectSettings::popup_project_settings() { void ProjectSettings::_item_selected() { - TreeItem *ti = globals_editor->get_tree()->get_selected(); + TreeItem *ti = globals_editor->get_scene_tree()->get_selected(); if (!ti) return; if (!ti->get_parent()) @@ -1212,7 +1212,7 @@ ProjectSettings::ProjectSettings(EditorData *p_data) { globals_editor->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN, 5 ); globals_editor->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END, 5 ); globals_editor->set_capitalize_paths(false); - globals_editor->get_tree()->connect("cell_selected",this,"_item_selected"); + globals_editor->get_scene_tree()->connect("cell_selected",this,"_item_selected"); globals_editor->connect("property_toggled",this,"_item_checked"); globals_editor->connect("property_edited",this,"_settings_prop_edited"); diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp index 645d967a4b..3fd713c5b0 100644 --- a/tools/editor/property_editor.cpp +++ b/tools/editor/property_editor.cpp @@ -142,7 +142,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { } String orig_type = res_orig->get_type(); - print_line("orig type: "+orig_type); + Object *inst = ObjectTypeDB::instance( orig_type ); Ref<Resource> res = Ref<Resource>( inst->cast_to<Resource>() ); @@ -187,6 +187,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { ERR_FAIL_COND( inheritors_array.empty() ); + String intype=inheritors_array[p_which-TYPE_BASE_ID]; Object *obj = ObjectTypeDB::instance(intype); @@ -603,6 +604,7 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty if (hint_text!="") { + int idx=0; for(int i=0;i<hint_text.get_slice_count(",");i++) { @@ -620,19 +622,19 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty E=E->next(); } - int idx=0; for(Set<String>::Element *E=valid_inheritors.front();E;E=E->next()) { String t = E->get(); if (!ObjectTypeDB::can_instance(t)) continue; inheritors_array.push_back(t); + int id = TYPE_BASE_ID+idx; if (has_icon(t,"EditorIcons")) { - menu->add_icon_item(get_icon(t,"EditorIcons"),"New "+t,TYPE_BASE_ID+idx); + menu->add_icon_item(get_icon(t,"EditorIcons"),"New "+t,id); } else { - menu->add_item("New "+t,TYPE_BASE_ID+idx); + menu->add_item("New "+t,id); } idx++; @@ -649,6 +651,8 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty if (!RES(v).is_null()) { + + menu->add_icon_item(get_icon("EditResource","EditorIcons"),"Edit",OBJ_MENU_EDIT); menu->add_icon_item(get_icon("Del","EditorIcons"),"Clear",OBJ_MENU_CLEAR); menu->add_icon_item(get_icon("Duplicate","EditorIcons"),"Make Unique",OBJ_MENU_MAKE_UNIQUE); @@ -657,6 +661,13 @@ bool CustomPropertyEditor::edit(Object* p_owner,const String& p_name,Variant::Ty menu->add_separator(); menu->add_icon_item(get_icon("Reload","EditorIcons"),"Re-Import",OBJ_MENU_REIMPORT); } + /*if (r.is_valid() && r->get_path().is_resource_file()) { + menu->set_item_tooltip(1,r->get_path()); + } else if (r.is_valid()) { + menu->set_item_tooltip(1,r->get_name()+" ("+r->get_type()+")"); + }*/ + } else { + } @@ -970,9 +981,11 @@ void CustomPropertyEditor::_action_pressed(int p_which) { if (p_which==0) { + ERR_FAIL_COND( inheritors_array.empty() ); String intype=inheritors_array[0]; + if (hint==PROPERTY_HINT_RESOURCE_TYPE) { @@ -1853,8 +1866,41 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p } else { p_item->set_text(1,"<"+res->get_type()+">"); }; + + + if (res.is_valid() && res->get_path().is_resource_file()) { + p_item->set_tooltip(1,res->get_path()); + } else if (res.is_valid()) { + p_item->set_tooltip(1,res->get_name()+" ("+res->get_type()+")"); + } + + + if (has_icon(res->get_type(),"EditorIcons")) { + + p_item->set_icon(0,get_icon(res->get_type(),"EditorIcons")); + } else { + + Dictionary d = p_item->get_metadata(0); + int hint=d.has("hint")?d["hint"].operator int():-1; + String hint_text=d.has("hint_text")?d["hint_text"]:""; + if (hint==PROPERTY_HINT_RESOURCE_TYPE) { + + if (has_icon(hint_text,"EditorIcons")) { + + p_item->set_icon(0,get_icon(hint_text,"EditorIcons")); + + } else { + p_item->set_icon(0,get_icon("Object","EditorIcons")); + + } + } + } + + + } + } break; default: {}; } @@ -1863,11 +1909,11 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String& p void PropertyEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { - get_scene()->connect("node_removed",this,"_node_removed"); + get_tree()->connect("node_removed",this,"_node_removed"); } - if (p_what==NOTIFICATION_EXIT_SCENE) { + if (p_what==NOTIFICATION_EXIT_TREE) { edit(NULL); } @@ -1876,6 +1922,14 @@ void PropertyEditor::_notification(int p_what) { if (p_what==NOTIFICATION_FIXED_PROCESS) { + if (refresh_countdown>0) { + refresh_countdown-=get_fixed_process_delta_time(); + if (refresh_countdown<=0) { + TreeItem *root = tree->get_root(); + _refresh_item(root); + } + } + changing=true; if (update_tree_pending) { @@ -1982,7 +2036,71 @@ TreeItem *PropertyEditor::get_parent_node(String p_path,HashMap<String,TreeItem* } +void PropertyEditor::_refresh_item(TreeItem *p_item) { + + if (!p_item) + return; + + String name = p_item->get_metadata(1); + + if (name!=String()) { + + if (get_instanced_node()) { + + Dictionary d = get_instanced_node()->get_instance_state(); + if (d.has(name)) { + Variant v = obj->get(name); + Variant vorig = d[name]; + + int found=-1; + for(int i=0;i<p_item->get_button_count(1);i++) { + + if (p_item->get_button_id(1,i)==3) { + found=i; + break; + } + } + + bool changed = ! (v==vorig); + + if ((found!=-1)!=changed) { + + if (changed) { + + p_item->add_button(1,get_icon("Reload","EditorIcons"),3); + } else { + + p_item->erase_button(1,found); + } + + } + + } + + } + + Dictionary d=p_item->get_metadata(0); + set_item_text(p_item,d["type"],d["name"],d["hint"],d["hint_text"]); + } + + TreeItem *c=p_item->get_children(); + + while (c) { + + _refresh_item(c); + + c=c->get_next(); + } + +} + +void PropertyEditor::refresh() { + + if (refresh_countdown>0) + return; + refresh_countdown=EditorSettings::get_singleton()->get("property_editor/auto_refresh_interval"); +} void PropertyEditor::update_tree() { @@ -2140,7 +2258,7 @@ void PropertyEditor::update_tree() { } if (capitalize_paths) - item->set_text( 0, name.capitalize() ); + item->set_text( 0, name.camelcase_to_underscore().capitalize() ); else item->set_text( 0, name ); @@ -2261,7 +2379,7 @@ void PropertyEditor::update_tree() { } else { if (p.type == Variant::REAL) { - item->set_range_config(1, -65536, 65535, 0.01); + item->set_range_config(1, -65536, 65535, 0.001); } else { item->set_range_config(1, -65536, 65535, 1); @@ -2453,7 +2571,10 @@ void PropertyEditor::update_tree() { item->set_editable( 1, !read_only ); item->add_button(1,get_icon("EditResource","EditorIcons")); String type; + if (p.hint==PROPERTY_HINT_RESOURCE_TYPE) + type=p.hint_string; bool notnil=false; + if (obj->get( p.name ).get_type() == Variant::NIL || obj->get( p.name ).operator RefPtr().is_null()) { item->set_text(1,"<null>"); @@ -2477,12 +2598,25 @@ void PropertyEditor::update_tree() { }; notnil=true; + if (has_icon(res->get_type(),"EditorIcons")) { + type=res->get_type(); + } + + if (res.is_valid() && res->get_path().is_resource_file()) { + item->set_tooltip(1,res->get_path()); + } else if (res.is_valid()) { + item->set_tooltip(1,res->get_name()+" ("+res->get_type()+")"); + } + } - if (p.hint==PROPERTY_HINT_RESOURCE_TYPE) { + + if (type!=String()) { + if (type.find(",")!=-1) + type=type.get_slice(",",0); //printf("prop %s , type %s\n",p.name.ascii().get_data(),p.hint_string.ascii().get_data()); - if (has_icon(p.hint_string,"EditorIcons")) - item->set_icon( 0, get_icon(p.hint_string,"EditorIcons") ); + if (has_icon(type,"EditorIcons")) + item->set_icon( 0, get_icon(type,"EditorIcons") ); else item->set_icon( 0, get_icon("Object","EditorIcons") ); } @@ -2919,7 +3053,7 @@ void PropertyEditor::_bind_methods() { ADD_SIGNAL( MethodInfo("property_edited",PropertyInfo( Variant::STRING, "property"))); } -Tree *PropertyEditor::get_tree() { +Tree *PropertyEditor::get_scene_tree() { return tree; } @@ -3021,6 +3155,7 @@ PropertyEditor::PropertyEditor() { keying=false; read_only=false; show_categories=false; + refresh_countdown=0; } diff --git a/tools/editor/property_editor.h b/tools/editor/property_editor.h index f13deab1ae..c05e13b90e 100644 --- a/tools/editor/property_editor.h +++ b/tools/editor/property_editor.h @@ -156,6 +156,7 @@ class PropertyEditor : public Control { bool keying; bool read_only; bool show_categories; + float refresh_countdown; HashMap<String,String> pending; String selected_property; @@ -185,6 +186,7 @@ class PropertyEditor : public Control { void _draw_flags(Object *ti,const Rect2& p_rect); Node *get_instanced_node(); + void _refresh_item(TreeItem *p_item); UndoRedo *undo_redo; protected: @@ -197,12 +199,14 @@ public: String get_selected_path() const; - Tree *get_tree(); + Tree *get_scene_tree(); Label* get_top_label(); void hide_top_label(); void update_tree(); void update_property(const String& p_prop); + void refresh(); + void edit(Object* p_object); void set_keying(bool p_active); diff --git a/tools/editor/pvrtc_compress.cpp b/tools/editor/pvrtc_compress.cpp index 9511d6a26d..777a05f272 100644 --- a/tools/editor/pvrtc_compress.cpp +++ b/tools/editor/pvrtc_compress.cpp @@ -32,11 +32,34 @@ #include "io/resource_saver.h" #include "io/resource_loader.h" #include "os/os.h" - +#include "os/file_access.h" +static void (*_base_image_compress_pvrtc2_func)(Image *)=NULL; +static void (*_base_image_compress_pvrtc4_func)(Image *)=NULL; static void _compress_image(Image::CompressMode p_mode,Image *p_image) { String ttpath = EditorSettings::get_singleton()->get("PVRTC/texture_tool"); + + if (ttpath.strip_edges()=="" || !FileAccess::exists(ttpath)) { + switch(p_mode) { + + case Image::COMPRESS_PVRTC2: + if (_base_image_compress_pvrtc2_func) + _base_image_compress_pvrtc2_func(p_image); + else if (_base_image_compress_pvrtc4_func) + _base_image_compress_pvrtc4_func(p_image); + + break; + case Image::COMPRESS_PVRTC4: + if (_base_image_compress_pvrtc4_func) + _base_image_compress_pvrtc4_func(p_image); + + break; + default: ERR_FAIL(); + + } + return; + } String spath = EditorSettings::get_singleton()->get_settings_path(); @@ -100,6 +123,9 @@ static void _compress_etc(Image *p_image) { void _pvrtc_register_compressors() { + _base_image_compress_pvrtc2_func=Image::_image_compress_pvrtc2_func; + _base_image_compress_pvrtc4_func=Image::_image_compress_pvrtc4_func; + Image::_image_compress_pvrtc2_func=_compress_pvrtc2; Image::_image_compress_pvrtc4_func=_compress_pvrtc4; //Image::_image_compress_etc_func=_compress_etc; //use the built in one for ETC diff --git a/tools/editor/quick_open.cpp b/tools/editor/quick_open.cpp index bae7528150..129c637ab0 100644 --- a/tools/editor/quick_open.cpp +++ b/tools/editor/quick_open.cpp @@ -111,7 +111,7 @@ void EditorQuickOpen::_confirmed() { void EditorQuickOpen::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { connect("confirmed",this,"_confirmed"); } diff --git a/tools/editor/reparent_dialog.cpp b/tools/editor/reparent_dialog.cpp index 2c85eb3a2a..5a5566c756 100644 --- a/tools/editor/reparent_dialog.cpp +++ b/tools/editor/reparent_dialog.cpp @@ -36,7 +36,7 @@ void ReparentDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { connect("confirmed", this,"_reparent"); } diff --git a/tools/editor/resources_dock.cpp b/tools/editor/resources_dock.cpp index a05fe425b3..4614c4945d 100644 --- a/tools/editor/resources_dock.cpp +++ b/tools/editor/resources_dock.cpp @@ -69,36 +69,8 @@ void ResourcesDock::_tool_selected(int p_tool) { TreeItem *ti = resources->get_selected(); if (!ti) break; - Ref<Resource> current_res = ti->get_metadata(0); - - RES res(current_res); - - List<String> extensions; - ResourceSaver::get_recognized_extensions(res,&extensions); - file->set_mode(FileDialog::MODE_SAVE_FILE); - //not for now? - - if (current_res->get_path()!="" && current_res->get_path().find("::")==-1) { - - file->set_current_path(current_res->get_path()); - } else { - String existing; - if (extensions.size()) { - existing="new_"+res->get_type().to_lower()+"."+extensions.front()->get().to_lower(); - } - - file->set_current_file(existing); - } - - file->clear_filters(); - for(int i=0;i<extensions.size();i++) { - - file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); - } - - //file->set_current_path(current_path); - file->popup_centered_ratio(); + save_resource_as(ti->get_metadata(0)); } break; @@ -134,7 +106,7 @@ void ResourcesDock::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { button_new->set_icon(get_icon("New","EditorIcons")); button_open->set_icon(get_icon("Folder","EditorIcons")); @@ -174,33 +146,34 @@ void ResourcesDock::save_resource(const String& p_path,const Ref<Resource>& p_re void ResourcesDock::save_resource_as(const Ref<Resource>& p_resource) { + current_action=TOOL_SAVE_AS; - add_resource(p_resource); - TreeItem *root=resources->get_root(); - ERR_FAIL_COND(!root); + RES res(p_resource); - TreeItem *existing=root->get_children(); + List<String> extensions; + ResourceSaver::get_recognized_extensions(res,&extensions); + file->set_mode(FileDialog::MODE_SAVE_FILE); - while(existing) { + if (p_resource->get_path()!="" && p_resource->get_path().find("::")==-1) { - Ref<Resource> r = existing->get_metadata(0); - if (r==p_resource) { - //existing->move_to_top(); - existing->select(0); - resources->ensure_cursor_is_visible(); - return; // existing - } - existing=existing->get_next(); - } - - ERR_FAIL_COND(!existing); + file->set_current_path(p_resource->get_path()); + } else { - existing->select(0); + String existing; + if (extensions.size()) { + existing="new_"+res->get_type().to_lower()+"."+extensions.front()->get().to_lower(); + } - _tool_selected(TOOL_SAVE_AS); + file->set_current_file(existing); + } + file->clear_filters(); + for(int i=0;i<extensions.size();i++) { + file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper()); + } + file->popup_centered_ratio(); } diff --git a/tools/editor/scene_tree_dock.cpp b/tools/editor/scene_tree_dock.cpp index f693036bc2..84b34cf130 100644 --- a/tools/editor/scene_tree_dock.cpp +++ b/tools/editor/scene_tree_dock.cpp @@ -79,10 +79,22 @@ Node* SceneTreeDock::instance(const String& p_file) { //accept->get_cancel()->hide(); accept->get_ok()->set_text("Ugh"); accept->set_text(String("Error loading scene from ")+p_file); - accept->popup_centered(Size2(300,70));; + accept->popup_centered(Size2(300,70)); return NULL; } + // If the scene hasn't been saved yet a cyclical dependency cannot exist. + if (edited_scene->get_filename()!="") { + + if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) { + + accept->get_ok()->set_text("Ok"); + accept->set_text(String("Cannot instance the scene '")+p_file+String("' because the current scene exists within one of its' nodes.")); + accept->popup_centered(Size2(300,90)); + return NULL; + } + } + instanced_scene->generate_instance_state(); instanced_scene->set_filename( Globals::get_singleton()->localize_path(p_file) ); @@ -100,6 +112,35 @@ Node* SceneTreeDock::instance(const String& p_file) { } +bool SceneTreeDock::_cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node) { + int childCount = p_desired_node->get_child_count(); + + if (p_desired_node->get_filename()==p_target_scene_path) { + return true; + } + + for (int i=0;i<childCount;i++) { + Node* child=p_desired_node->get_child(i); + + if(_cyclical_dependency_exists(p_target_scene_path,child)) { + return true; + } + } + + return false; +} + + +static String _get_name_num_separator() { + switch(EditorSettings::get_singleton()->get("scenetree_editor/duplicate_node_name_num_separator").operator int()) { + case 0: return ""; + case 1: return " "; + case 2: return "_"; + case 3: return "-"; + } + return " "; +} + void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { current_option=p_tool; @@ -212,17 +253,50 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (!_validate_no_foreign()) break; - Node * node=scene_tree->get_selected(); - ERR_FAIL_COND(!node->get_parent()); - int current_pos = node->get_index(); - int next_pos = current_pos + ((p_tool==TOOL_MOVE_DOWN)?1:-1); + bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN); + bool MOVING_UP = !MOVING_DOWN; + + Node *common_parent = scene_tree->get_selected()->get_parent(); + List<Node*> selection = editor_selection->get_selected_node_list(); + selection.sort_custom<Node::Comparator>(); // sort by index + if (MOVING_DOWN) + selection.invert(); + + int lowest_id = common_parent->get_child_count() - 1; + int highest_id = 0; + for (List<Node*>::Element *E = selection.front(); E; E = E->next()) { + int index = E->get()->get_index(); + + if (index > highest_id) highest_id = index; + if (index < lowest_id) lowest_id = index; + + if (E->get()->get_parent() != common_parent) + common_parent = NULL; + } + + if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0)) + break; // one or more nodes can not be moved + + if (selection.size() == 1) editor_data->get_undo_redo().create_action("Move Node In Parent"); + if (selection.size() > 1) editor_data->get_undo_redo().create_action("Move Nodes In Parent"); + + for (int i = 0; i < selection.size(); i++) { + Node *top_node = selection[i]; + Node *bottom_node = selection[selection.size() - 1 - i]; + + ERR_FAIL_COND(!top_node->get_parent()); + ERR_FAIL_COND(!bottom_node->get_parent()); - if (next_pos< 0 || next_pos>=node->get_parent()->get_child_count()) - break; // invalid position + int top_node_pos = top_node->get_index(); + int bottom_node_pos = bottom_node->get_index(); + + int top_node_pos_next = top_node_pos + (MOVING_DOWN ? 1 : -1); + int bottom_node_pos_next = bottom_node_pos + (MOVING_DOWN ? 1 : -1); + + editor_data->get_undo_redo().add_do_method(top_node->get_parent(), "move_child", top_node, top_node_pos_next); + editor_data->get_undo_redo().add_undo_method(bottom_node->get_parent(), "move_child", bottom_node, bottom_node_pos); + } - editor_data->get_undo_redo().create_action("Move Node In Parent"); - editor_data->get_undo_redo().add_do_method(node->get_parent(),"move_child",node,next_pos); - editor_data->get_undo_redo().add_undo_method(node->get_parent(),"move_child",node,current_pos); editor_data->get_undo_redo().commit_action(); } break; @@ -285,17 +359,21 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } int num=nums.to_int(); - if (num<2) - num=2; + if (num<1) + num=1; else num++; - name=name.substr(0,name.length()-nums.length()).strip_edges(); - String attempt=name+" "+itos(num); + String nnsep = _get_name_num_separator(); + name = name.substr(0,name.length()-nums.length()).strip_edges(); + if ( name.substr(name.length()-nnsep.length(),nnsep.length()) == nnsep) { + name = name.substr(0,name.length()-nnsep.length()); + } + String attempt = (name + nnsep + itos(num)).strip_edges(); while(parent->has_node(attempt)) { num++; - attempt=name+" "+itos(num); + attempt = (name + nnsep + itos(num)).strip_edges(); } dup->set_name(attempt); @@ -393,7 +471,7 @@ void SceneTreeDock::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { static const char* button_names[TOOL_BUTTON_MAX]={ "New", @@ -913,7 +991,7 @@ void SceneTreeDock::_delete_confirm() { //delete from animation for(List<Node*>::Element *E=remove_list.front();E;E=E->next()) { Node *n = E->get(); - if (!n->is_inside_scene() || !n->get_parent()) + if (!n->is_inside_tree() || !n->get_parent()) continue; fill_path_renames(n,NULL,&path_renames); @@ -924,7 +1002,7 @@ void SceneTreeDock::_delete_confirm() { //delete for read for(List<Node*>::Element *E=remove_list.front();E;E=E->next()) { Node *n = E->get(); - if (!n->is_inside_scene() || !n->get_parent()) + if (!n->is_inside_tree() || !n->get_parent()) continue; List<Node*> owned; @@ -981,14 +1059,15 @@ void SceneTreeDock::_create() { if (edited_scene) { - + // If root exists in edited scene parent = scene_tree->get_selected(); - ERR_FAIL_COND(!parent); - } else { + if( !parent ) + parent = edited_scene; + } else { + // If no root exist in edited scene parent = scene_root; ERR_FAIL_COND(!parent); - } Object *c = create_dialog->instance_selected(); @@ -1176,7 +1255,7 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec tb = memnew( ToolButton ); tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_INSTANCE, false)); - tb->set_tooltip("Instance a Node from scene file."); + tb->set_tooltip("Instance a scene file as a Node."); hbc_top->add_child(tb); tool_buttons[TOOL_INSTANCE]=tb; diff --git a/tools/editor/scene_tree_dock.h b/tools/editor/scene_tree_dock.h index ac5391f3b9..92ebfc5bee 100644 --- a/tools/editor/scene_tree_dock.h +++ b/tools/editor/scene_tree_dock.h @@ -102,6 +102,7 @@ class SceneTreeDock : public VBoxContainer { void _load_request(const String& p_path); void _script_open_request(const Ref<Script>& p_script); + bool _cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node); void _node_selected(); void _node_renamed(); diff --git a/tools/editor/scene_tree_editor.cpp b/tools/editor/scene_tree_editor.cpp index 9b4ef6cef1..e9ec0199d0 100644 --- a/tools/editor/scene_tree_editor.cpp +++ b/tools/editor/scene_tree_editor.cpp @@ -36,11 +36,11 @@ Node *SceneTreeEditor::get_scene_node() { - ERR_FAIL_COND_V(!is_inside_scene(),NULL); - if (get_scene()->get_root()->get_child_count() && get_scene()->get_root()->get_child(0)->cast_to<EditorNode>()) - return get_scene()->get_root()->get_child(0)->cast_to<EditorNode>()->get_edited_scene(); + ERR_FAIL_COND_V(!is_inside_tree(),NULL); + if (get_tree()->get_root()->get_child_count() && get_tree()->get_root()->get_child(0)->cast_to<EditorNode>()) + return get_tree()->get_root()->get_child(0)->cast_to<EditorNode>()->get_edited_scene(); else - return get_scene()->get_root(); + return get_tree()->get_root(); return NULL; } @@ -367,7 +367,7 @@ void SceneTreeEditor::_node_removed(Node *p_node) { void SceneTreeEditor::_update_tree() { - if (!is_inside_scene()) { + if (!is_inside_tree()) { tree_dirty=false; return; } @@ -403,7 +403,7 @@ void SceneTreeEditor::_test_update_tree() { pending_test_update=false; - if (!is_inside_scene()) + if (!is_inside_tree()) return; if(tree_dirty) @@ -483,10 +483,10 @@ void SceneTreeEditor::_cell_multi_selected(Object *p_object,int p_cell,bool p_se void SceneTreeEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { - get_scene()->connect("tree_changed",this,"_tree_changed"); - get_scene()->connect("node_removed",this,"_node_removed"); + get_tree()->connect("tree_changed",this,"_tree_changed"); + get_tree()->connect("node_removed",this,"_node_removed"); instance_menu->set_item_icon(2,get_icon("Load","EditorIcons")); tree->connect("item_collapsed",this,"_cell_collapsed"); @@ -494,10 +494,10 @@ void SceneTreeEditor::_notification(int p_what) { // get_scene()->connect("node_removed",this,"_node_removed",Vector<Variant>(),CONNECT_DEFERRED); _update_tree(); } - if (p_what==NOTIFICATION_EXIT_SCENE) { + if (p_what==NOTIFICATION_EXIT_TREE) { - get_scene()->disconnect("tree_changed",this,"_tree_changed"); - get_scene()->disconnect("node_removed",this,"_node_removed"); + get_tree()->disconnect("tree_changed",this,"_tree_changed"); + get_tree()->disconnect("node_removed",this,"_node_removed"); _update_tree(); } @@ -806,7 +806,7 @@ SceneTreeEditor::~SceneTreeEditor() { void SceneTreeDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { connect("confirmed", this,"_select"); } diff --git a/tools/editor/scenes_dock.cpp b/tools/editor/scenes_dock.cpp index 3f7c82d988..516cb5930d 100644 --- a/tools/editor/scenes_dock.cpp +++ b/tools/editor/scenes_dock.cpp @@ -115,7 +115,7 @@ void ScenesDock::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { EditorFileSystem::get_singleton()->connect("filesystem_changed",this,"_update_tree"); @@ -145,7 +145,7 @@ void ScenesDock::_notification(int p_what) { _update_tree(); //maybe it finished already } break; - case NOTIFICATION_EXIT_SCENE: { + case NOTIFICATION_EXIT_TREE: { } break; case NOTIFICATION_PROCESS: { @@ -383,7 +383,7 @@ void ScenesDockFilter::_file_filter_selected(int p_idx) { void ScenesDockFilter::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { clear_search_button->set_icon(get_icon("CloseHover","EditorIcons")); } break; } diff --git a/tools/editor/script_editor_debugger.cpp b/tools/editor/script_editor_debugger.cpp index 00066e67e9..5043c5cdcd 100644 --- a/tools/editor/script_editor_debugger.cpp +++ b/tools/editor/script_editor_debugger.cpp @@ -431,7 +431,7 @@ void ScriptEditorDebugger::_notification(int p_what) { switch(p_what) { - case NOTIFICATION_ENTER_SCENE: { + case NOTIFICATION_ENTER_TREE: { step->set_icon( get_icon("DebugStep","EditorIcons")); next->set_icon( get_icon("DebugNext","EditorIcons")); @@ -478,8 +478,6 @@ void ScriptEditorDebugger::_notification(int p_what) { if (!connection->is_connected()) { stop(); editor->notify_child_process_exited(); //somehow, exited - msgdialog->set_text("Process being debugged exited."); - msgdialog->popup_centered(Size2(250,100)); break; }; @@ -771,7 +769,7 @@ ScriptEditorDebugger::ScriptEditorDebugger(EditorNode *p_editor){ inspector = memnew( PropertyEditor ); inspector->set_h_size_flags(SIZE_EXPAND_FILL); inspector->hide_top_label(); - inspector->get_tree()->set_column_title(0,"Variable"); + inspector->get_scene_tree()->set_column_title(0,"Variable"); inspector->set_capitalize_paths(false); inspector->set_read_only(true); sc->add_child(inspector); diff --git a/tools/editor/settings_config_dialog.cpp b/tools/editor/settings_config_dialog.cpp index c82b075bc4..2310df4ffb 100644 --- a/tools/editor/settings_config_dialog.cpp +++ b/tools/editor/settings_config_dialog.cpp @@ -246,7 +246,7 @@ void EditorSettingsDialog::_update_plugins() { void EditorSettingsDialog::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_SCENE) { + if (p_what==NOTIFICATION_ENTER_TREE) { rescan_plugins->set_icon(get_icon("Reload","EditorIcons")); _update_plugins(); diff --git a/tools/editor/spatial_editor_gizmos.cpp b/tools/editor/spatial_editor_gizmos.cpp index 04d5888861..d48a4ce813 100644 --- a/tools/editor/spatial_editor_gizmos.cpp +++ b/tools/editor/spatial_editor_gizmos.cpp @@ -1779,7 +1779,7 @@ void CollisionShapeSpatialGizmo::set_handle(int p_idx,Camera *p_camera, const Po Ref<CapsuleShape> cs = s;
Vector3 ra,rb;
Geometry::get_closest_points_between_segments(Vector3(),axis*4096,sg[0],sg[1],ra,rb);
- float d = ra[p_idx];
+ float d = axis.dot(ra);
if (p_idx==1)
d-=cs->get_radius();
if (d<0.001)
diff --git a/tools/export/blender25/godot_export_manager.py b/tools/export/blender25/godot_export_manager.py new file mode 100644 index 0000000000..31db2c9e94 --- /dev/null +++ b/tools/export/blender25/godot_export_manager.py @@ -0,0 +1,474 @@ +# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# Script copyright (c) Andreas Esau
+
+bl_info = {
+ "name": "Godot Export Manager",
+ "author": "Andreas Esau",
+ "version": (1, 0),
+ "blender": (2, 7, 0),
+ "location": "Scene Properties > Godot Export Manager",
+ "description": "Godot Export Manager uses the Better Collada Exporter to manage Export Groups and automatically export the objects groups to Collada Files.",
+ "warning": "",
+ "wiki_url": ("http://www.godotengine.org"),
+ "tracker_url": "",
+ "category": "Import-Export"}
+
+import bpy
+from bpy.props import StringProperty, BoolProperty, EnumProperty, FloatProperty, FloatVectorProperty, IntProperty, CollectionProperty, PointerProperty
+import os
+from bpy.app.handlers import persistent
+from mathutils import Vector, Matrix
+
+class godot_export_manager(bpy.types.Panel):
+ bl_label = "Godot Export Manager"
+ bl_space_type = 'PROPERTIES'
+ bl_region_type = 'WINDOW'
+ bl_context = "scene"
+
+ bpy.types.Scene.godot_export_on_save = BoolProperty(default=False)
+
+ ### draw function for all ui elements
+ def draw(self, context):
+ layout = self.layout
+ split = self.layout.split()
+ scene = bpy.data.scenes[0]
+ ob = context.object
+ scene = context.scene
+
+ row = layout.row()
+ col = row.column()
+ col.prop(scene,"godot_export_on_save",text="Export Groups on save")
+
+ row = layout.row()
+ col = row.column(align=True)
+ op = col.operator("scene.godot_add_objects_to_group",text="Add selected objects to Group",icon="COPYDOWN")
+
+ op = col.operator("scene.godot_delete_objects_from_group",text="Delete selected objects from Group",icon="PASTEDOWN")
+
+
+
+ row = layout.row()
+ col = row.column()
+ col.label(text="Export Groups:")
+
+
+ row = layout.row()
+ col = row.column()
+
+ col.template_list("UI_List_Godot","dummy",scene, "godot_export_groups", scene, "godot_export_groups_index",rows=1,maxrows=10,type='DEFAULT')
+
+ col = row.column(align=True)
+ col.operator("scene.godot_add_export_group",text="",icon="ZOOMIN")
+ col.operator("scene.godot_delete_export_group",text="",icon="ZOOMOUT")
+ col.operator("scene.godot_export_all_groups",text="",icon="EXPORT")
+
+ if len(scene.godot_export_groups) > 0:
+ row = layout.row()
+ col = row.column()
+ group = scene.godot_export_groups[scene.godot_export_groups_index]
+ col.prop(group,"name",text="Group Name")
+ col.prop(group,"export_name",text="Export Name")
+ col.prop(group,"export_path",text="Export Filepath")
+
+ row = layout.row()
+ col = row.column()
+ row = layout.row()
+ col = row.column()
+ col.label(text="Export Settings:")
+
+ col = col.row(align=True)
+ col.prop(group,"apply_loc",toggle=True,icon="MAN_TRANS")
+ col.prop(group,"apply_rot",toggle=True,icon="MAN_ROT")
+ col.prop(group,"apply_scale",toggle=True,icon="MAN_SCALE")
+
+ row = layout.row()
+ col = row.column()
+
+ col.prop(group,"use_include_particle_duplicates")
+ col.prop(group,"use_mesh_modifiers")
+ col.prop(group,"use_tangent_arrays")
+ col.prop(group,"use_triangles")
+ col.prop(group,"use_copy_images")
+ col.prop(group,"use_active_layers")
+ col.prop(group,"use_exclude_ctrl_bones")
+ col.prop(group,"use_anim")
+ col.prop(group,"use_anim_action_all")
+ col.prop(group,"use_anim_skip_noexp")
+ col.prop(group,"use_anim_optimize")
+ col.prop(group,"anim_optimize_precision")
+ col.prop(group,"use_metadata")
+
+### Custom template_list look
+class UI_List_Godot(bpy.types.UIList):
+ def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
+ ob = data
+ slot = item
+ col = layout.row(align=True)
+
+ col.label(text=item.name,icon="GROUP")
+ col.prop(item,"active",text="")
+
+ op = col.operator("scene.godot_select_group_objects",text="",emboss=False,icon="RESTRICT_SELECT_OFF")
+ op.idx = index
+ op = col.operator("scene.godot_export_group",text="",emboss=False,icon="EXPORT")
+ op.idx = index
+
+class add_objects_to_group(bpy.types.Operator):
+ bl_idname = "scene.godot_add_objects_to_group"
+ bl_label = "Add Objects to Group"
+ bl_description = "Adds the selected Objects to the active group below."
+
+ undo = BoolProperty(default=True)
+
+ def execute(self,context):
+ scene = context.scene
+
+ objects_str = ""
+ if len(scene.godot_export_groups) > 0:
+ for i,object in enumerate(context.selected_objects):
+ if object.name not in scene.godot_export_groups[scene.godot_export_groups_index].nodes:
+ node = scene.godot_export_groups[scene.godot_export_groups_index].nodes.add()
+ node.name = object.name
+ if i == 0:
+ objects_str += object.name
+ else:
+ objects_str += ", "+object.name
+
+
+ self.report({'INFO'}, objects_str + " added to group." )
+ if self.undo:
+ bpy.ops.ed.undo_push(message="Objects added to group")
+ else:
+ self.report({'WARNING'}, "Create a group first." )
+ return{'FINISHED'}
+
+class del_objects_from_group(bpy.types.Operator):
+ bl_idname = "scene.godot_delete_objects_from_group"
+ bl_label = "Delete Objects from Group"
+ bl_description = "Delets the selected Objects from the active group below."
+
+ def execute(self,context):
+ scene = context.scene
+
+ if len(scene.godot_export_groups) > 0:
+
+ selected_objects = []
+ for object in context.selected_objects:
+ selected_objects.append(object.name)
+
+ objects_str = ""
+ j = 0
+ for i,node in enumerate(scene.godot_export_groups[scene.godot_export_groups_index].nodes):
+ if node.name in selected_objects:
+ scene.godot_export_groups[scene.godot_export_groups_index].nodes.remove(i)
+
+
+ if j == 0:
+ objects_str += object.name
+ else:
+ objects_str += ", "+object.name
+ j+=1
+
+
+ self.report({'INFO'}, objects_str + " deleted from group." )
+ bpy.ops.ed.undo_push(message="Objects deleted from group")
+ else:
+ self.report({'WARNING'}, "There is no group to delete from." )
+ return{'FINISHED'}
+
+class select_group_objects(bpy.types.Operator):
+ bl_idname = "scene.godot_select_group_objects"
+ bl_label = "Select Group Objects"
+ bl_description = "Will select all group Objects in the scene."
+
+ idx = IntProperty()
+
+ def execute(self,context):
+ scene = context.scene
+ for object in context.scene.objects:
+ object.select = False
+ for node in scene.godot_export_groups[self.idx].nodes:
+ if node.name in bpy.data.objects:
+ bpy.data.objects[node.name].select = True
+ context.scene.objects.active = bpy.data.objects[node.name]
+ return{'FINISHED'}
+
+class export_groups_autosave(bpy.types.Operator):
+ bl_idname = "scene.godot_export_groups_autosave"
+ bl_label = "Export All Groups"
+ bl_description = "Exports all groups to Collada."
+
+ def execute(self,context):
+ scene = context.scene
+ if scene.godot_export_on_save:
+ for i in range(len(scene.godot_export_groups)):
+ if scene.godot_export_groups[i].active:
+ bpy.ops.scene.godot_export_group(idx=i)
+ self.report({'INFO'}, "All Groups exported." )
+ bpy.ops.ed.undo_push(message="Export all Groups")
+ return{'FINISHED'}
+
+class export_all_groups(bpy.types.Operator):
+ bl_idname = "scene.godot_export_all_groups"
+ bl_label = "Export All Groups"
+ bl_description = "Exports all groups to Collada."
+
+ def execute(self,context):
+ scene = context.scene
+
+ for i in range(0,len(scene.godot_export_groups)):
+ bpy.ops.scene.godot_export_group(idx=i,export_all=True)
+
+ self.report({'INFO'}, "All Groups exported." )
+ return{'FINISHED'}
+
+
+class export_group(bpy.types.Operator):
+ bl_idname = "scene.godot_export_group"
+ bl_label = "Export Group"
+ bl_description = "Exports the active group to destination folder as Collada file."
+
+ idx = IntProperty(default=0)
+ export_all = BoolProperty(default=False)
+
+
+ def copy_object_recursive(self,ob,parent,single_user = True):
+ new_ob = bpy.data.objects[ob.name].copy()
+ if single_user or ob.type=="ARMATURE":
+ new_mesh_data = new_ob.data.copy()
+ new_ob.data = new_mesh_data
+ bpy.context.scene.objects.link(new_ob)
+
+ if ob != parent:
+ new_ob.parent = parent
+ else:
+ new_ob.parent = None
+
+ for child in ob.children:
+ self.copy_object_recursive(child,new_ob,single_user)
+ new_ob.select = True
+ return new_ob
+
+ def delete_object(self,ob):
+ if ob != None:
+ for child in ob.children:
+ self.delete_object(child)
+ bpy.context.scene.objects.unlink(ob)
+ bpy.data.objects.remove(ob)
+
+ def convert_group_to_node(self,group):
+ if group.dupli_group != None:
+ for object in group.dupli_group.objects:
+ if object.parent == None:
+ object = self.copy_object_recursive(object,object,True)
+ matrix = Matrix(object.matrix_local)
+ object.matrix_local = Matrix()
+ object.matrix_local *= group.matrix_local
+ object.matrix_local *= matrix
+
+ self.delete_object(group)
+
+ def execute(self,context):
+
+ scene = context.scene
+ group = context.scene.godot_export_groups
+
+ if not group[self.idx].active and self.export_all:
+ return{'FINISHED'}
+
+ for i,object in enumerate(group[self.idx].nodes):
+ if object.name in bpy.data.objects:
+ pass
+ else:
+ group[self.idx].nodes.remove(i)
+ bpy.ops.ed.undo_push(message="Clear not existent Group Nodes.")
+
+ path = group[self.idx].export_path
+ if (path.find("//")==0 or path.find("\\\\")==0):
+ #if relative, convert to absolute
+ path = bpy.path.abspath(path)
+ path = path.replace("\\","/")
+
+ ### if path exists and group export name is set the group will be exported
+ if os.path.exists(path) and group[self.idx].export_name != "":
+
+ context.scene.layers = [True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True]
+
+
+ if group[self.idx].export_name.endswith(".dae"):
+ path = os.path.join(path,group[self.idx].export_name)
+ else:
+ path = os.path.join(path,group[self.idx].export_name+".dae")
+
+ hide_select = []
+ for object in context.scene.objects:
+ hide_select.append(object.hide_select)
+ object.hide_select = False
+ object.select = False
+ context.scene.objects.active = None
+
+ ### make particle duplicates, parent and select them
+ nodes_to_be_added = []
+ if group[self.idx].use_include_particle_duplicates:
+ for i,object in enumerate(group[self.idx].nodes):
+ if bpy.data.objects[object.name].type != "EMPTY":
+ context.scene.objects.active = bpy.data.objects[object.name]
+ bpy.data.objects[object.name].select = True
+ bpy.ops.object.duplicates_make_real()
+ for object in context.selected_objects:
+ nodes_to_be_added.append(object)
+ bpy.ops.object.parent_set(type="OBJECT", keep_transform=False)
+
+ for object in context.selected_objects:
+ object.select = False
+ bpy.data.objects[object.name].select = False
+ context.scene.objects.active = None
+ for object in nodes_to_be_added:
+ object.select = True
+
+ ### select all other nodes from the group
+ for i,object in enumerate(group[self.idx].nodes):
+ if bpy.data.objects[object.name].type == "EMPTY":
+ self.convert_group_to_node(bpy.data.objects[object.name])
+ else:
+ bpy.data.objects[object.name].select = True
+
+ bpy.ops.object.transform_apply(location=group[self.idx].apply_loc, rotation=group[self.idx].apply_rot, scale=group[self.idx].apply_scale)
+ bpy.ops.export_scene.dae(check_existing=True, filepath=path, filter_glob="*.dae", object_types=group[self.idx].object_types, use_export_selected=group[self.idx].use_export_selected, use_mesh_modifiers=group[self.idx].use_mesh_modifiers, use_tangent_arrays=group[self.idx].use_tangent_arrays, use_triangles=group[self.idx].use_triangles, use_copy_images=group[self.idx].use_copy_images, use_active_layers=group[self.idx].use_active_layers, use_exclude_ctrl_bones=group[self.idx].use_exclude_ctrl_bones, use_anim=group[self.idx].use_anim, use_anim_action_all=group[self.idx].use_anim_action_all, use_anim_skip_noexp=group[self.idx].use_anim_skip_noexp, use_anim_optimize=group[self.idx].use_anim_optimize, anim_optimize_precision=group[self.idx].anim_optimize_precision, use_metadata=group[self.idx].use_metadata)
+
+ self.report({'INFO'}, '"'+group[self.idx].name+'"' + " Group exported." )
+ msg = "Export Group "+group[self.idx].name
+
+ bpy.ops.ed.undo_push(message="")
+ bpy.ops.ed.undo()
+ bpy.ops.ed.undo_push(message=msg)
+
+ else:
+ self.report({'INFO'}, "Define Export Name and Export Path." )
+ return{'FINISHED'}
+
+class add_export_group(bpy.types.Operator):
+ bl_idname = "scene.godot_add_export_group"
+ bl_label = "Adds a new export Group"
+ bl_description = "Creates a new Export Group with the selected Objects assigned to it."
+
+ def execute(self,context):
+ scene = context.scene
+
+ item = scene.godot_export_groups.add()
+ item.name = "New Group"
+ for object in context.selected_objects:
+ node = item.nodes.add()
+ node.name = object.name
+ scene.godot_export_groups_index = len(scene.godot_export_groups)-1
+ bpy.ops.ed.undo_push(message="Create New Export Group")
+ return{'FINISHED'}
+
+class del_export_group(bpy.types.Operator):
+ bl_idname = "scene.godot_delete_export_group"
+ bl_label = "Delets the selected export Group"
+ bl_description = "Delets the active Export Group."
+
+ def invoke(self, context, event):
+ wm = context.window_manager
+ return wm.invoke_confirm(self,event)
+
+ def execute(self,context):
+ scene = context.scene
+
+ scene.godot_export_groups.remove(scene.godot_export_groups_index)
+ if scene.godot_export_groups_index > 0:
+ scene.godot_export_groups_index -= 1
+ bpy.ops.ed.undo_push(message="Delete Export Group")
+ return{'FINISHED'}
+
+class godot_node_list(bpy.types.PropertyGroup):
+ name = StringProperty()
+
+class godot_export_groups(bpy.types.PropertyGroup):
+ name = StringProperty(name="Group Name")
+ export_name = StringProperty(name="scene_name")
+ nodes = CollectionProperty(type=godot_node_list)
+ export_path = StringProperty(subtype="DIR_PATH")
+ active = BoolProperty(default=True,description="Export Group")
+
+ object_types = EnumProperty(name="Object Types",options={'ENUM_FLAG'},items=(('EMPTY', "Empty", ""),('CAMERA', "Camera", ""),('LAMP', "Lamp", ""),('ARMATURE', "Armature", ""),('MESH', "Mesh", ""),('CURVE', "Curve", ""),),default={'EMPTY', 'CAMERA', 'LAMP', 'ARMATURE', 'MESH','CURVE'})
+
+ apply_scale = BoolProperty(name="Apply Scale",description="Apply Scale before export.",default=False)
+ apply_rot = BoolProperty(name="Apply Rotation",description="Apply Rotation before export.",default=False)
+ apply_loc = BoolProperty(name="Apply Location",description="Apply Location before export.",default=False)
+
+ use_export_selected = BoolProperty(name="Selected Objects",description="Export only selected objects (and visible in active layers if that applies).",default=True)
+ use_mesh_modifiers = BoolProperty(name="Apply Modifiers",description="Apply modifiers to mesh objects (on a copy!).",default=True)
+ use_tangent_arrays = BoolProperty(name="Tangent Arrays",description="Export Tangent and Binormal arrays (for normalmapping).",default=False)
+ use_triangles = BoolProperty(name="Triangulate",description="Export Triangles instead of Polygons.",default=False)
+
+ use_copy_images = BoolProperty(name="Copy Images",description="Copy Images (create images/ subfolder)",default=False)
+ use_active_layers = BoolProperty(name="Active Layers",description="Export only objects on the active layers.",default=True)
+ use_exclude_ctrl_bones = BoolProperty(name="Exclude Control Bones",description="Exclude skeleton bones with names that begin with 'ctrl'.",default=True)
+ use_anim = BoolProperty(name="Export Animation",description="Export keyframe animation",default=False)
+ use_anim_action_all = BoolProperty(name="All Actions",description=("Export all actions for the first armature found in separate DAE files"),default=False)
+ use_anim_skip_noexp = BoolProperty(name="Skip (-noexp) Actions",description="Skip exporting of actions whose name end in (-noexp). Useful to skip control animations.",default=True)
+ use_anim_optimize = BoolProperty(name="Optimize Keyframes",description="Remove double keyframes",default=True)
+
+ anim_optimize_precision = FloatProperty(name="Precision",description=("Tolerence for comparing double keyframes (higher for greater accuracy)"),min=1, max=16,soft_min=1, soft_max=16,default=6.0)
+
+ use_metadata = BoolProperty(name="Use Metadata",default=True,options={'HIDDEN'})
+ use_include_particle_duplicates = BoolProperty(name="Include Particle Duplicates",default=True)
+
+def register():
+ bpy.utils.register_class(godot_export_manager)
+ bpy.utils.register_class(godot_node_list)
+ bpy.utils.register_class(godot_export_groups)
+ bpy.utils.register_class(add_export_group)
+ bpy.utils.register_class(del_export_group)
+ bpy.utils.register_class(export_all_groups)
+ bpy.utils.register_class(export_groups_autosave)
+ bpy.utils.register_class(export_group)
+ bpy.utils.register_class(add_objects_to_group)
+ bpy.utils.register_class(del_objects_from_group)
+ bpy.utils.register_class(select_group_objects)
+ bpy.utils.register_class(UI_List_Godot)
+
+ bpy.types.Scene.godot_export_groups = CollectionProperty(type=godot_export_groups)
+ bpy.types.Scene.godot_export_groups_index = IntProperty(default=0,min=0)
+
+def unregister():
+ bpy.utils.unregister_class(godot_export_manager)
+ bpy.utils.unregister_class(godot_node_list)
+ bpy.utils.unregister_class(godot_export_groups)
+ bpy.utils.unregister_class(export_groups_autosave)
+ bpy.utils.unregister_class(add_export_group)
+ bpy.utils.unregister_class(del_export_group)
+ bpy.utils.unregister_class(export_all_groups)
+ bpy.utils.unregister_class(export_group)
+ bpy.utils.unregister_class(add_objects_to_group)
+ bpy.utils.unregister_class(del_objects_from_group)
+ bpy.utils.unregister_class(select_group_objects)
+ bpy.utils.unregister_class(UI_List_Godot)
+
+@persistent
+def auto_export(dummy):
+ bpy.ops.scene.godot_export_groups_autosave()
+
+bpy.app.handlers.save_post.append(auto_export)
+
+if __name__ == "__main__":
+ register()
diff --git a/tools/export/blender25/io_scene_dae/export_dae.py b/tools/export/blender25/io_scene_dae/export_dae.py index 7899098e3d..020ab6ca08 100644 --- a/tools/export/blender25/io_scene_dae/export_dae.py +++ b/tools/export/blender25/io_scene_dae/export_dae.py @@ -94,8 +94,6 @@ def strarr(arr): s+=" " return s - - class DaeExporter: def validate_id(self,d): @@ -132,10 +130,10 @@ class DaeExporter: tup = tup + (self.tangent.x,self.tangent.y,self.tangent.z) if (self.bitangent!=None): tup = tup + (self.bitangent.x,self.bitangent.y,self.bitangent.z) - #for t in self.bones: - # tup = tup + (t) - #for t in self.weights: - # tup = tup + (t) + for t in self.bones: + tup = tup + (float(t),) + for t in self.weights: + tup = tup + (float(t),) return tup @@ -162,33 +160,64 @@ class DaeExporter: def export_image(self,image): - if (image in self.image_cache): return self.image_cache[image] - + imgpath = image.filepath if (imgpath.find("//")==0 or imgpath.find("\\\\")==0): #if relative, convert to absolute imgpath = bpy.path.abspath(imgpath) #path is absolute, now do something! - + if (self.config["use_copy_images"]): #copy image basedir = os.path.dirname(self.path)+"/images" if (not os.path.isdir(basedir)): os.makedirs(basedir) - dstfile=basedir+"/"+os.path.basename(imgpath) - if (not os.path.isfile(dstfile)): - shutil.copy(imgpath,dstfile) - imgpath="images/"+os.path.basename(imgpath) + + if os.path.isfile(imgpath): + dstfile=basedir+"/"+os.path.basename(imgpath) + + if (not os.path.isfile(dstfile)): + shutil.copy(imgpath,dstfile) + imgpath="images/"+os.path.basename(imgpath) + else: + ### if file is not found save it as png file in the destination folder + img_tmp_path = image.filepath + if img_tmp_path.endswith((".bmp",".rgb",".png",".jpeg",".jpg",".jp2",".tga",".cin",".dpx",".exr",".hdr",".tif")): + image.filepath = basedir+"/"+os.path.basename(img_tmp_path) + else: + image.filepath = basedir+"/"+image.name+".png" + + dstfile=basedir+"/"+os.path.basename(image.filepath) + + if (not os.path.isfile(dstfile)): + + image.save() + imgpath="images/"+os.path.basename(image.filepath) + image.filepath = img_tmp_path else: #export relative, always, no one wants absolute paths. - imgpath = os.path.relpath(imgpath,os.path.dirname(self.path)).replace("\\","/") # export unix compatible always - + try: + imgpath = os.path.relpath(imgpath,os.path.dirname(self.path)).replace("\\","/") # export unix compatible always + + except: + pass #fails sometimes, not sure why + imgid = self.new_id("image") + + print("FOR: "+imgpath) + +# if (not os.path.isfile(imgpath)): +# print("NOT FILE?") +# if imgpath.endswith((".bmp",".rgb",".png",".jpeg",".jpg",".jp2",".tga",".cin",".dpx",".exr",".hdr",".tif")): +# imgpath="images/"+os.path.basename(imgpath) +# else: +# imgpath="images/"+image.name+".png" + self.writel(S_IMGS,1,'<image id="'+imgid+'" name="'+image.name+'">') self.writel(S_IMGS,2,'<init_from>'+imgpath+'</init_from>"/>') self.writel(S_IMGS,1,'</image>') @@ -331,7 +360,7 @@ class DaeExporter: return matid - def export_mesh(self,node,armature=None,skeyindex=-1,skel_source=None): + def export_mesh(self,node,armature=None,skeyindex=-1,skel_source=None,custom_name=None): mesh = node.data @@ -368,9 +397,9 @@ class DaeExporter: # self.export_node(node,il,shape.name) node.data.update() if (armature and k==0): - md=self.export_mesh(node,armature,k,mid) + md=self.export_mesh(node,armature,k,mid,shape.name) else: - md=self.export_mesh(node,None,k) + md=self.export_mesh(node,None,k,None,shape.name) node.data = p node.data.update() @@ -484,10 +513,18 @@ class DaeExporter: mat_assign=[] uv_layer_count=len(mesh.uv_textures) - if (len(mesh.uv_textures)): - mesh.calc_tangents() + if (has_tangents and len(mesh.uv_textures)): + try: + mesh.calc_tangents() + except: + self.operator.report({'WARNING'},'CalcTangets failed for mesh "'+mesh.name+'", no tangets will be exported.') + #uv_layer_count=0 + mesh.calc_normals_split() + has_tangents=False + else: mesh.calc_normals_split() + has_tangents=False for fi in range(len(mesh.polygons)): @@ -495,8 +532,8 @@ class DaeExporter: if (not (f.material_index in surface_indices)): surface_indices[f.material_index]=[] - print("Type: "+str(type(f.material_index))) - print("IDX: "+str(f.material_index)+"/"+str(len(mesh.materials))) + #print("Type: "+str(type(f.material_index))) + #print("IDX: "+str(f.material_index)+"/"+str(len(mesh.materials))) try: #Bizarre blender behavior i don't understand, so catching exception @@ -555,16 +592,30 @@ class DaeExporter: if (armature!=None): wsum=0.0 + zero_bones=[] + for vg in mv.groups: if vg.group >= len(node.vertex_groups): continue; name = node.vertex_groups[vg.group].name + if (name in si["bone_index"]): #could still put the weight as 0.0001 maybe if (vg.weight>0.001): #blender has a lot of zero weight stuff v.bones.append(si["bone_index"][name]) v.weights.append(vg.weight) wsum+=vg.weight + if (wsum==0.0): + if not self.wrongvtx_report: + self.operator.report({'WARNING'},'Mesh for object "'+node.name+'" has unassigned weights. This may look wrong in exported model.') + self.wrongvtx_report=True + + #blender can have bones assigned that weight zero so they remain local + #this is the best it can be done? + v.bones.append(0) + v.weights.append(1) + + tup = v.get_tup() @@ -584,7 +635,10 @@ class DaeExporter: meshid = self.new_id("mesh") - self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+mesh.name+'">') + if (custom_name!=None): + self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+custom_name+'">') + else: + self.writel(S_GEOM,1,'<geometry id="'+meshid+'" name="'+mesh.name+'">') self.writel(S_GEOM,2,'<mesh>') @@ -850,6 +904,29 @@ class DaeExporter: if (node.parent!=None): if (node.parent.type=="ARMATURE"): armature=node.parent + armcount=0 + for n in node.modifiers: + if (n.type=="ARMATURE"): + armcount+=1 + if (armcount>1): + self.operator.report({'WARNING'},'Object "'+node.name+'" refers to more than one armature! This is unsopported.') + + + + + if (node.data.shape_keys!=None): + sk = node.data.shape_keys + if (sk.animation_data): + #print("HAS ANIM") + #print("DRIVERS: "+str(len(sk.animation_data.drivers))) + for d in sk.animation_data.drivers: + if (d.driver): + for v in d.driver.variables: + for t in v.targets: + if (t.id!=None and t.id.name in self.scene.objects): + #print("LINKING "+str(node)+" WITH "+str(t.id.name)) + self.armature_for_morph[node]=self.scene.objects[t.id.name] + meshdata = self.export_mesh(node,armature) close_controller=False @@ -887,6 +964,12 @@ class DaeExporter: boneidx = si["bone_count"] si["bone_count"]+=1 bonesid = si["id"]+"-"+str(boneidx) + if (bone.name in self.used_bones): + if (self.config["use_anim_action_all"]): + self.operator.report({'WARNING'},'Bone name "'+bone.name+'" used in more than one skeleton. Actions might export wrong.') + else: + self.used_bones.append(bone.name) + si["bone_index"][bone.name]=boneidx si["bone_ids"][bone]=boneid si["bone_names"].append(bonesid) @@ -949,12 +1032,12 @@ class DaeExporter: self.writel(S_CAMS,5,'<zfar> '+str(camera.clip_end)+' </zfar>') self.writel(S_CAMS,4,'</perspective>') else: - self.writel(S_CAMS,4,'<orthografic>') - self.writel(S_CAMS,5,'<xmag> '+str(camera.ortho_scale)+' </xmag>') # I think? + self.writel(S_CAMS,4,'<orthographic>') + self.writel(S_CAMS,5,'<xmag> '+str(camera.ortho_scale*0.5)+' </xmag>') # I think? self.writel(S_CAMS,5,'<aspect_ratio> '+str(self.scene.render.resolution_x / self.scene.render.resolution_y)+' </aspect_ratio>') self.writel(S_CAMS,5,'<znear> '+str(camera.clip_start)+' </znear>') self.writel(S_CAMS,5,'<zfar> '+str(camera.clip_end)+' </zfar>') - self.writel(S_CAMS,4,'</orthografic>') + self.writel(S_CAMS,4,'</orthographic>') self.writel(S_CAMS,3,'</technique_common>') self.writel(S_CAMS,2,'</optics>') @@ -1145,15 +1228,16 @@ class DaeExporter: def export_node(self,node,il): - if (not self.is_node_valid(node)): + if (not node in self.valid_nodes): return + prev_node = bpy.context.scene.objects.active bpy.context.scene.objects.active = node self.writel(S_NODES,il,'<node id="'+self.validate_id(node.name)+'" name="'+node.name+'" type="NODE">') il+=1 self.writel(S_NODES,il,'<matrix sid="transform">'+strmtx(node.matrix_local)+'</matrix>') - print("NODE TYPE: "+node.type+" NAME: "+node.name) + #print("NODE TYPE: "+node.type+" NAME: "+node.name) if (node.type=="MESH"): self.export_mesh_node(node,il) elif (node.type=="CURVE"): @@ -1165,18 +1249,19 @@ class DaeExporter: elif (node.type=="LAMP"): self.export_lamp_node(node,il) - self.valid_nodes.append(node) for x in node.children: self.export_node(x,il) il-=1 self.writel(S_NODES,il,'</node>') + bpy.context.scene.objects.active = prev_node #make previous node active again def is_node_valid(self,node): if (not node.type in self.config["object_types"]): return False if (self.config["use_active_layers"]): valid=False + #print("NAME: "+node.name) for i in range(20): if (node.layers[i] and self.scene.layers[i]): valid=True @@ -1196,8 +1281,21 @@ class DaeExporter: self.writel(S_NODES,0,'<library_visual_scenes>') self.writel(S_NODES,1,'<visual_scene id="'+self.scene_name+'" name="scene">') + #validate nodes + for obj in self.scene.objects: + if (obj in self.valid_nodes): + continue + if (self.is_node_valid(obj)): + n = obj + while (n!=None): + if (not n in self.valid_nodes): + self.valid_nodes.append(n) + n=n.parent + + + for obj in self.scene.objects: - if (obj.parent==None): + if (obj in self.valid_nodes and obj.parent==None): self.export_node(obj,2) self.writel(S_NODES,1,'</visual_scene>') @@ -1313,7 +1411,7 @@ class DaeExporter: # Change frames first, export objects last # This improves performance enormously - print("anim from: "+str(start)+" to "+str(end)+" allowed: "+str(allowed)) + #print("anim from: "+str(start)+" to "+str(end)+" allowed: "+str(allowed)) for t in range(start,end+1): self.scene.frame_set(t) key = t * frame_len - frame_sub @@ -1327,6 +1425,7 @@ class DaeExporter: if (node.type=="MESH" and node.data!=None and (node in self.armature_for_morph) and (self.armature_for_morph[node] in allowed)): pass #all good you pass with flying colors for morphs inside of action else: + #print("fail "+str((node in self.armature_for_morph))) continue if (node.type=="MESH" and node.data!=None and node.data.shape_keys!=None and (node.data in self.mesh_cache) and len(node.data.shape_keys.key_blocks)): target = self.mesh_cache[node.data]["morph_id"] @@ -1366,7 +1465,7 @@ class DaeExporter: bone_name=self.skeleton_info[node]["bone_ids"][bone] if (not (bone_name in xform_cache)): - print("has bone: "+bone_name) + #print("has bone: "+bone_name) xform_cache[bone_name]=[] posebone = node.pose.bones[bone.name] @@ -1398,11 +1497,17 @@ class DaeExporter: return tcn def export_animations(self): - + tmp_mat = [] + for s in self.skeletons: + tmp_bone_mat = [] + for bone in s.pose.bones: + tmp_bone_mat.append(Matrix(bone.matrix_basis)) + bone.matrix_basis = Matrix() + tmp_mat.append([Matrix(s.matrix_local),tmp_bone_mat]) + self.writel(S_ANIM,0,'<library_animations>') - if (self.config["use_anim_action_all"] and len(self.skeletons)): cached_actions = {} @@ -1433,41 +1538,55 @@ class DaeExporter: bones.append(dp) allowed_skeletons=[] - for y in self.skeletons: + for i,y in enumerate(self.skeletons): if (y.animation_data): for z in y.pose.bones: if (z.bone.name in bones): if (not y in allowed_skeletons): allowed_skeletons.append(y) y.animation_data.action=x; + + y.matrix_local = tmp_mat[i][0] + for j,bone in enumerate(s.pose.bones): + bone.matrix_basis = Matrix() + + #print("allowed skeletons "+str(allowed_skeletons)) + #print(str(x)) - print(str(x)) - - tcn = self.export_animation(int(x.frame_range[0]),int(x.frame_range[1]),allowed_skeletons) + tcn = self.export_animation(int(x.frame_range[0]),int(x.frame_range[1]+0.5),allowed_skeletons) framelen=(1.0/self.scene.render.fps) start = x.frame_range[0]*framelen end = x.frame_range[1]*framelen - print("Export anim: "+x.name) + #print("Export anim: "+x.name) self.writel(S_ANIM_CLIPS,1,'<animation_clip name="'+x.name+'" start="'+str(start)+'" end="'+str(end)+'">') for z in tcn: self.writel(S_ANIM_CLIPS,2,'<instance_animation url="#'+z+'"/>') self.writel(S_ANIM_CLIPS,1,'</animation_clip>') + if (len(tcn)==0): + self.operator.report({'WARNING'},'Animation clip "'+x.name+'" contains no tracks.') + self.writel(S_ANIM_CLIPS,0,'</library_animation_clips>') - for s in self.skeletons: + + for i,s in enumerate(self.skeletons): if (s.animation_data==None): continue if s in cached_actions: s.animation_data.action = bpy.data.actions[cached_actions[s]] else: s.animation_data.action = None + for j,bone in enumerate(s.pose.bones): + bone.matrix_basis = tmp_mat[i][1][j] + else: self.export_animation(self.scene.frame_start,self.scene.frame_end) - + + + self.writel(S_ANIM,0,'</library_animations>') def export(self): @@ -1533,7 +1652,8 @@ class DaeExporter: f.write(bytes('</COLLADA>\n',"UTF-8")) return True - def __init__(self,path,kwargs): + def __init__(self,path,kwargs,operator): + self.operator=operator self.scene=bpy.context.scene self.last_id=0 self.scene_name=self.new_id("scene") @@ -1547,6 +1667,11 @@ class DaeExporter: self.config=kwargs self.valid_nodes=[] self.armature_for_morph={} + self.used_bones=[] + self.wrongvtx_report=False + + + @@ -1557,9 +1682,11 @@ def save(operator, context, **kwargs ): - exp = DaeExporter(filepath,kwargs) + exp = DaeExporter(filepath,kwargs,operator) exp.export() + + return {'FINISHED'} # so the script wont run after we have batch exported. diff --git a/tools/script_plugins/time/time.gd b/tools/script_plugins/time/time.gd index 66b3e9ed04..2e56d89d4f 100644 --- a/tools/script_plugins/time/time.gd +++ b/tools/script_plugins/time/time.gd @@ -21,12 +21,12 @@ func _init(): timer.set_one_shot(false) timer.connect("timeout",self,"_timeout") -func _enter_scene(): +func _enter_tree(): label = Label.new() add_custom_control(CONTAINER_TOOLBAR,label) timer.start() -func _exit_scene(): +func _exit_tree(): timer.stop() label.free() label=null |