summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2014-05-24 01:35:47 -0300
committerJuan Linietsky <reduzio@gmail.com>2014-05-24 01:35:47 -0300
commit1cad087969efefa401a11051343cd0689f660770 (patch)
tree1595dd049bdb7289752012dca4398b2251fb08fa /tools
parentf9ff086235cd4ff406b136f62fff77b85c0873f9 (diff)
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.
Diffstat (limited to 'tools')
-rw-r--r--tools/editor/io_plugins/editor_texture_import_plugin.cpp12
-rw-r--r--tools/editor/io_plugins/editor_texture_import_plugin.h3
-rw-r--r--tools/editor/plugins/baked_light_editor_plugin.cpp193
-rw-r--r--tools/editor/plugins/baked_light_editor_plugin.h12
-rw-r--r--tools/editor/plugins/canvas_item_editor_plugin.cpp15
-rw-r--r--tools/editor/plugins/script_editor_plugin.cpp21
-rw-r--r--tools/editor/plugins/script_editor_plugin.h1
-rw-r--r--tools/editor/property_editor.cpp1
8 files changed, 225 insertions, 33 deletions
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 Ref<Resourc
image.fix_alpha_edges();
}
+ if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_PREMULT_ALPHA) {
+
+ image.premultiply_alpha();
+ }
+
if (shrink>1) {
@@ -972,6 +979,11 @@ Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<Resourc
image.fix_alpha_edges();
}
+ if (image.get_format()==Image::FORMAT_RGBA && flags&IMAGE_FLAG_PREMULT_ALPHA) {
+
+ image.premultiply_alpha();
+ }
+
int orig_w=image.get_width();
int orig_h=image.get_height();
diff --git a/tools/editor/io_plugins/editor_texture_import_plugin.h b/tools/editor/io_plugins/editor_texture_import_plugin.h
index b2950a889c..fcc1bd2d0c 100644
--- a/tools/editor/io_plugins/editor_texture_import_plugin.h
+++ b/tools/editor/io_plugins/editor_texture_import_plugin.h
@@ -91,7 +91,8 @@ public:
IMAGE_FLAG_COMPRESS_EXTRA=8, // used for pvrtc2
IMAGE_FLAG_NO_MIPMAPS=16, //normal for 2D games
IMAGE_FLAG_REPEAT=32, //usually disabled in 2D
- IMAGE_FLAG_FILTER=64 //almost always enabled
+ IMAGE_FLAG_FILTER=64, //almost always enabled
+ IMAGE_FLAG_PREMULT_ALPHA=128//almost always enabled
};
virtual String get_name() const;
diff --git a/tools/editor/plugins/baked_light_editor_plugin.cpp b/tools/editor/plugins/baked_light_editor_plugin.cpp
index b1e42e3369..77f9d1ed78 100644
--- a/tools/editor/plugins/baked_light_editor_plugin.cpp
+++ b/tools/editor/plugins/baked_light_editor_plugin.cpp
@@ -134,6 +134,8 @@ public:
void _plot_light(const Vector3& p_plot_pos,const AABB& p_plot_aabb, Octant *p_octant, const AABB& p_aabb,const Color& p_light);
+ void _plot_light_point(const Vector3& p_plot_pos, Octant *p_octant, const AABB& p_aabb,const Color& p_light);
+
void _throw_ray(const Vector3& p_from, const Vector3& p_to,const Color& p_light,float *p_att_curve,float p_att_curve_len,int p_bounces);
@@ -165,7 +167,7 @@ public:
}
BakedLightBaker() {
- octree_depth=8;
+ octree_depth=6;
octree=NULL;
bvh=NULL;
leaf_list=NULL;
@@ -408,7 +410,7 @@ void BakedLightBaker::_make_bvh() {
void BakedLightBaker::_octree_insert(const AABB& p_aabb,Octant *p_octant,Triangle* p_triangle, int p_depth) {
if (p_octant->leaf) {
-
+#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;i<poly.size();i++) {
- p_octant->surface_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;i<octree_depth;i++)
cell_size/=2.0;
octree = memnew( Octant );
@@ -526,7 +534,7 @@ void BakedLightBaker::_plot_light(const Vector3& p_plot_pos,const AABB& p_plot_a
float d = p_plot_pos.distance_to(center);
if (d>r)
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<Mesh>());
@@ -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<Color>::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<Mesh>());
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<Color> colors;
- DVector<Vector3> 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<FixedMaterial> 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<Mesh> 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<FixedMaterial> ( 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<Mesh>( 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<Color> colors;
+ DVector<Vector3> vertices;
+ Ref<Mesh> mesh;
+ Ref<FixedMaterial> 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
@@ -688,6 +688,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<Script> scr = current->get_edited_script();
+ if (scr.is_null())
+ return;
+ int begin,end;
+ if (te->is_selection_active()) {
+ begin=te->get_selection_from_line();
+ end=te->get_selection_to_line();
+ } else {
+ begin=0;
+ end=te->get_line_count()-1;
+ }
+ scr->get_language()->auto_indent_code(text,begin,end);
+ te->set_text(text);
+
+
+ } break;
case SEARCH_FIND: {
find_replace_dialog->set_text_edit(current->get_text_edit());
@@ -1321,6 +1341,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
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("Complete Symbol",EDIT_COMPLETE,KEY_MASK_CMD|KEY_SPACE);
+ 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");
diff --git a/tools/editor/plugins/script_editor_plugin.h b/tools/editor/plugins/script_editor_plugin.h
index 97f1702f8f..69b8739d67 100644
--- a/tools/editor/plugins/script_editor_plugin.h
+++ b/tools/editor/plugins/script_editor_plugin.h
@@ -122,6 +122,7 @@ class ScriptEditor : public VBoxContainer {
EDIT_PASTE,
EDIT_SELECT_ALL,
EDIT_COMPLETE,
+ EDIT_AUTO_INDENT,
SEARCH_FIND,
SEARCH_FIND_NEXT,
SEARCH_REPLACE,
diff --git a/tools/editor/property_editor.cpp b/tools/editor/property_editor.cpp
index 2087345888..2197902933 100644
--- a/tools/editor/property_editor.cpp
+++ b/tools/editor/property_editor.cpp
@@ -1566,6 +1566,7 @@ CustomPropertyEditor::CustomPropertyEditor() {
add_child(checks20[i]);
checks20[i]->hide();
checks20[i]->connect("pressed",this,"_action_pressed",make_binds(i));
+ checks20[i]->set_tooltip("Bit "+itos(i)+", val "+itos(1<<i)+".");
}
text_edit = memnew( TextEdit );