From 1cad087969efefa401a11051343cd0689f660770 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 24 May 2014 01:35:47 -0300 Subject: Making Godot Easier to Use.. -=-=-=-=-=-=-=-=-=-=-=-=-=-= -Auto indenter in code editor, this makes it much easier to paste external code. -Zoom in 2D viewport now uses the mouse pointer as reference. -Obscure hack to see where code/line of GDScript in C++ backtrace. -Fixed a bug where keys would get stuck on X11 if pressed simultaneously -Added Api on IP singleton to request local IPs. -Premultiplied alpha support when importing texture, editing PNGs and as a blend mode. --- .../io_plugins/editor_texture_import_plugin.cpp | 12 ++ .../io_plugins/editor_texture_import_plugin.h | 3 +- tools/editor/plugins/baked_light_editor_plugin.cpp | 193 +++++++++++++++++---- tools/editor/plugins/baked_light_editor_plugin.h | 12 ++ tools/editor/plugins/canvas_item_editor_plugin.cpp | 15 ++ tools/editor/plugins/script_editor_plugin.cpp | 21 +++ tools/editor/plugins/script_editor_plugin.h | 1 + tools/editor/property_editor.cpp | 1 + 8 files changed, 225 insertions(+), 33 deletions(-) (limited to 'tools') diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.cpp b/tools/editor/io_plugins/editor_texture_import_plugin.cpp index 916bd59360..4da712c7b3 100644 --- a/tools/editor/io_plugins/editor_texture_import_plugin.cpp +++ b/tools/editor/io_plugins/editor_texture_import_plugin.cpp @@ -44,6 +44,7 @@ static const char *flag_names[]={ "No MipMaps", "Repeat", "Filter (Magnifying)", + "Premultiply Alpha", NULL }; @@ -55,6 +56,7 @@ static const char *flag_short_names[]={ "NoMipMap", "Repeat", "Filter", + "PMAlpha", NULL }; @@ -919,6 +921,11 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref1) { @@ -972,6 +979,11 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Refleaf) { - +#if 0 if (p_aabb.has_point(p_triangle->vertices[0]) && p_aabb.has_point(p_triangle->vertices[1]) &&p_aabb.has_point(p_triangle->vertices[2])) { //face is completely enclosed, add area p_octant->surface_area+=Face3(p_triangle->vertices[0],p_triangle->vertices[1],p_triangle->vertices[2]).get_area(); @@ -433,12 +435,18 @@ void BakedLightBaker::_octree_insert(const AABB& p_aabb,Octant *p_octant,Triangl p.d=-p_aabb.pos[i]; poly=Geometry::clip_polygon(poly,p); } + + //calculate area + float clipped_area=0; for(int i=2;isurface_area+=Face3(poly[0],poly[i-1],poly[i]).get_area(); + clipped_area+=Face3(poly[0],poly[i-1],poly[i]).get_area(); } - } + print_line(itos(poly.size())+" Base: "+rtos(Face3(p_triangle->vertices[0],p_triangle->vertices[1],p_triangle->vertices[2]).get_area())+" clipped: "+rtos(clipped_area)); + p_octant->surface_area+=clipped_area; + } +#endif } else { @@ -500,7 +508,7 @@ void BakedLightBaker::_make_octree() { octree_aabb=base; cell_size=base.size.x; - for(int i=0;i<=octree_depth;i++) + for(int i=0;ir) return; //oh crap! outside radius - float intensity = 1.0 - (d/r)*(d/r); //not gauss but.. + float intensity = 1.0;// - (d/r)*(d/r); //not gauss but.. p_octant->light_accum[0]+=p_light.r*intensity; p_octant->light_accum[1]+=p_light.g*intensity; p_octant->light_accum[2]+=p_light.b*intensity; @@ -558,6 +566,42 @@ void BakedLightBaker::_plot_light(const Vector3& p_plot_pos,const AABB& p_plot_a } } +void BakedLightBaker::_plot_light_point(const Vector3& p_plot_pos, Octant *p_octant, const AABB& p_aabb,const Color& p_light) { + + + if (p_octant->leaf) { + + p_octant->light_accum[0]+=p_light.r; + p_octant->light_accum[1]+=p_light.g; + p_octant->light_accum[2]+=p_light.b; + + } else { + + for(int i=0;i<8;i++) { + + if (!p_octant->children[i]) + continue; + + AABB aabb=p_aabb; + aabb.size*=0.5; + if (i&1) + aabb.pos.x+=aabb.size.x; + if (i&2) + aabb.pos.y+=aabb.size.y; + if (i&4) + aabb.pos.z+=aabb.size.z; + + + if (!aabb.has_point(p_plot_pos)) + continue; + + _plot_light_point(p_plot_pos,p_octant->children[i],aabb,p_light); + + } + + } +} + void BakedLightBaker::_throw_ray(const Vector3& p_begin, const Vector3& p_end,const Color& p_light,float *p_att_curve,float p_att_curve_len,int p_bounces) { @@ -692,6 +736,7 @@ void BakedLightBaker::_throw_ray(const Vector3& p_begin, const Vector3& p_end,co aabb.size=Vector3(2,2,2)*cell_size*plot_size; _plot_light(r_point,aabb,octree,octree_aabb,p_light); +// _plot_light_point(r_point,octree,octree_aabb,p_light); } @@ -772,9 +817,21 @@ void BakedLightBaker::bake(Node* p_node) { +void BakedLightEditor::_end_baking() { + + if (!bake_thread) + return; + + bake_thread_exit=true; + Thread::wait_to_finish(bake_thread); + bake_thread=NULL; + bake_thread_exit=false; +} + void BakedLightEditor::_node_removed(Node *p_node) { if(p_node==node) { + _end_baking(); node=NULL; p_node->remove_child(preview); preview->set_mesh(Ref()); @@ -784,6 +841,79 @@ void BakedLightEditor::_node_removed(Node *p_node) { } +void BakedLightEditor::_bake_thread_func(void *arg) { + + BakedLightEditor *ble = (BakedLightEditor*)arg; + + while(!ble->bake_thread_exit) { + + ble->baker->throw_rays(1000); + } + +} + + + +void BakedLightEditor::_notification(int p_option) { + + + if (p_option==NOTIFICATION_PROCESS) { + + if (bake_thread) { + + update_timeout-=get_process_delta_time(); + if (update_timeout<0) { + + + + float norm = baker->get_normalization(); + float max_lum=0; + { + DVector::Write cw=colors.write(); + BakedLightBaker::Octant *oct = baker->leaf_list; + int vert_idx=0; + + while(oct) { + + Color color; + + + color.r=oct->light_accum[0]/norm; + color.g=oct->light_accum[1]/norm; + color.b=oct->light_accum[2]/norm; + float lum = color.get_v(); + //if (lum<0.05) + // color.a=0; + if (lum>max_lum) + max_lum=lum; + + for (int i=0;i<36;i++) { + + + cw[vert_idx++]=color; + } + + oct=oct->next_leaf; + + } + } + + + Array a; + a.resize(Mesh::ARRAY_MAX); + a[Mesh::ARRAY_VERTEX]=vertices; + a[Mesh::ARRAY_COLOR]=colors; + while(mesh->get_surface_count()) + mesh->surface_remove(0); + mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,a); + mesh->surface_set_material(0,material); + + update_timeout=1; + } + } + } +} + void BakedLightEditor::_menu_option(int p_option) { @@ -797,13 +927,9 @@ void BakedLightEditor::_menu_option(int p_option) { preview->set_mesh(Ref()); baker->base_inv=node->get_global_transform().affine_inverse(); baker->bake(node); - baker->throw_rays(100000); - float norm = baker->get_normalization(); - float max_lum=0; print_line("CELLS: "+itos(baker->cell_count)); - DVector colors; - DVector vertices; + print_line("cell size: "+rtos(baker->cell_size)); colors.resize(baker->cell_count*36); vertices.resize(baker->cell_count*36); @@ -817,12 +943,6 @@ void BakedLightEditor::_menu_option(int p_option) { while(oct) { Color color; - color.r=oct->light_accum[0]/norm; - color.g=oct->light_accum[1]/norm; - color.b=oct->light_accum[2]/norm; - float lum = color.get_v(); - if (lum>max_lum) - max_lum=lum; for (int i=0;i<6;i++) { @@ -845,7 +965,7 @@ void BakedLightEditor::_menu_option(int p_option) { } for(int j=0;j<4;j++) { - face_points[j]*=baker->cell_size; + face_points[j]*=baker->cell_size*0.5; face_points[j]+=Vector3(oct->offset[0],oct->offset[1],oct->offset[2]); } @@ -873,25 +993,20 @@ void BakedLightEditor::_menu_option(int p_option) { } - print_line("max lum: "+rtos(max_lum)); Array a; a.resize(Mesh::ARRAY_MAX); a[Mesh::ARRAY_VERTEX]=vertices; a[Mesh::ARRAY_COLOR]=colors; + while(mesh->get_surface_count()) + mesh->surface_remove(0); + mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,a); + mesh->surface_set_material(0,material); - Ref matcol = memnew( FixedMaterial ); - matcol->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY,true); - matcol->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true); - matcol->set_flag(FixedMaterial::FLAG_UNSHADED,true); - matcol->set_flag(FixedMaterial::FLAG_DOUBLE_SIDED,true); - matcol->set_parameter(FixedMaterial::PARAM_DIFFUSE,Color(1,1,1)); - Ref m = memnew( Mesh ); - m->add_surface(Mesh::PRIMITIVE_TRIANGLES,a); - m->surface_set_material(0,matcol); - preview->set_mesh(m); - - - + bake_thread_exit=false; + update_timeout=0; + set_process(true); + bake_thread=Thread::create(_bake_thread_func,this); + preview->set_mesh(mesh); } break; @@ -914,6 +1029,7 @@ void BakedLightEditor::edit(BakedLight *p_baked_light) { } node=p_baked_light; + _end_baking(); if (node) node->add_child(preview); @@ -943,6 +1059,19 @@ BakedLightEditor::BakedLightEditor() { node=NULL; baker = memnew( BakedLightBaker ); preview = memnew( MeshInstance ); + bake_thread=NULL; + update_timeout=0; + + material = Ref ( memnew( FixedMaterial ) ); + material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY,true); + material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true); + material->set_flag(FixedMaterial::FLAG_UNSHADED,true); + material->set_flag(FixedMaterial::FLAG_DOUBLE_SIDED,true); + material->set_parameter(FixedMaterial::PARAM_DIFFUSE,Color(1,1,1)); + + mesh = Ref( memnew( Mesh )); + + } BakedLightEditor::~BakedLightEditor() { diff --git a/tools/editor/plugins/baked_light_editor_plugin.h b/tools/editor/plugins/baked_light_editor_plugin.h index 698d3f825f..9424503a16 100644 --- a/tools/editor/plugins/baked_light_editor_plugin.h +++ b/tools/editor/plugins/baked_light_editor_plugin.h @@ -19,6 +19,15 @@ class BakedLightEditor : public Control { OBJ_TYPE(BakedLightEditor, Control ); + float update_timeout; + DVector colors; + DVector vertices; + Ref mesh; + Ref material; + + Thread *bake_thread; + bool bake_thread_exit; + MeshInstance *preview; BakedLightBaker *baker; AcceptDialog *err_dialog; @@ -32,12 +41,15 @@ class BakedLightEditor : public Control { MENU_OPTION_CLEAR }; + static void _bake_thread_func(void *arg); + void _end_baking(); void _menu_option(int); friend class BakedLightEditorPlugin; protected: void _node_removed(Node *p_node); static void _bind_methods(); + void _notification(int p_what); public: void edit(BakedLight *p_baked_light); diff --git a/tools/editor/plugins/canvas_item_editor_plugin.cpp b/tools/editor/plugins/canvas_item_editor_plugin.cpp index 5f87b791f7..6540ae9288 100644 --- a/tools/editor/plugins/canvas_item_editor_plugin.cpp +++ b/tools/editor/plugins/canvas_item_editor_plugin.cpp @@ -608,7 +608,14 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { if (b.button_index==BUTTON_WHEEL_DOWN) { + float prev_zoom=zoom; zoom=zoom*0.95; + { + Point2 ofs(b.x,b.y); + ofs = ofs/prev_zoom - ofs/zoom; + h_scroll->set_val( h_scroll->get_val() + ofs.x ); + v_scroll->set_val( v_scroll->get_val() + ofs.y ); + } _update_scroll(0); viewport->update(); return; @@ -616,7 +623,15 @@ void CanvasItemEditor::_viewport_input_event(const InputEvent& p_event) { if (b.button_index==BUTTON_WHEEL_UP) { + float prev_zoom=zoom; zoom=zoom*(1.0/0.95); + { + Point2 ofs(b.x,b.y); + ofs = ofs/prev_zoom - ofs/zoom; + h_scroll->set_val( h_scroll->get_val() + ofs.x ); + v_scroll->set_val( v_scroll->get_val() + ofs.y ); + } + _update_scroll(0); viewport->update(); return; diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 83cf753692..31ccc79d2a 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -687,6 +687,26 @@ void ScriptEditor::_menu_option(int p_option) { current->get_text_edit()->query_code_comple(); + } break; + case EDIT_AUTO_INDENT: { + + TextEdit *te = current->get_text_edit(); + String text = te->get_text(); + Ref