summaryrefslogtreecommitdiff
path: root/editor/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'editor/plugins')
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp83
-rw-r--r--editor/plugins/animation_player_editor_plugin.h2
-rw-r--r--editor/plugins/animation_tree_editor_plugin.cpp49
-rw-r--r--editor/plugins/animation_tree_editor_plugin.h2
-rw-r--r--editor/plugins/asset_library_editor_plugin.cpp1486
-rw-r--r--editor/plugins/asset_library_editor_plugin.h328
-rw-r--r--editor/plugins/baked_light_baker.cpp2732
-rw-r--r--editor/plugins/baked_light_baker.h382
-rw-r--r--editor/plugins/baked_light_baker_cmpxchg.cpp105
-rw-r--r--editor/plugins/baked_light_editor_plugin.cpp377
-rw-r--r--editor/plugins/baked_light_editor_plugin.h118
-rw-r--r--editor/plugins/camera_editor_plugin.cpp8
-rw-r--r--editor/plugins/camera_editor_plugin.h2
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp493
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h25
-rw-r--r--editor/plugins/collision_polygon_2d_editor_plugin.cpp23
-rw-r--r--editor/plugins/collision_polygon_2d_editor_plugin.h2
-rw-r--r--editor/plugins/collision_polygon_editor_plugin.cpp24
-rw-r--r--editor/plugins/collision_polygon_editor_plugin.h2
-rw-r--r--editor/plugins/collision_shape_2d_editor_plugin.cpp22
-rw-r--r--editor/plugins/collision_shape_2d_editor_plugin.h2
-rw-r--r--editor/plugins/cube_grid_theme_editor_plugin.cpp130
-rw-r--r--editor/plugins/cube_grid_theme_editor_plugin.h2
-rw-r--r--editor/plugins/curve_editor_plugin.cpp18
-rw-r--r--editor/plugins/curve_editor_plugin.h2
-rw-r--r--editor/plugins/editor_preview_plugins.cpp20
-rw-r--r--editor/plugins/editor_preview_plugins.h5
-rw-r--r--editor/plugins/gi_probe_editor_plugin.cpp4
-rw-r--r--editor/plugins/gi_probe_editor_plugin.h2
-rw-r--r--editor/plugins/gradient_editor_plugin.cpp4
-rw-r--r--editor/plugins/gradient_editor_plugin.h2
-rw-r--r--editor/plugins/item_list_editor_plugin.cpp12
-rw-r--r--editor/plugins/item_list_editor_plugin.h2
-rw-r--r--editor/plugins/light_occluder_2d_editor_plugin.cpp19
-rw-r--r--editor/plugins/light_occluder_2d_editor_plugin.h2
-rw-r--r--editor/plugins/line_2d_editor_plugin.cpp6
-rw-r--r--editor/plugins/line_2d_editor_plugin.h2
-rw-r--r--editor/plugins/material_editor_plugin.cpp10
-rw-r--r--editor/plugins/material_editor_plugin.h9
-rw-r--r--editor/plugins/mesh_editor_plugin.cpp4
-rw-r--r--editor/plugins/mesh_editor_plugin.h2
-rw-r--r--editor/plugins/mesh_instance_editor_plugin.cpp6
-rw-r--r--editor/plugins/mesh_instance_editor_plugin.h2
-rw-r--r--editor/plugins/multimesh_editor_plugin.cpp23
-rw-r--r--editor/plugins/multimesh_editor_plugin.h2
-rw-r--r--editor/plugins/navigation_polygon_editor_plugin.cpp23
-rw-r--r--editor/plugins/navigation_polygon_editor_plugin.h2
-rw-r--r--editor/plugins/particles_2d_editor_plugin.cpp11
-rw-r--r--editor/plugins/particles_2d_editor_plugin.h2
-rw-r--r--editor/plugins/particles_editor_plugin.cpp14
-rw-r--r--editor/plugins/particles_editor_plugin.h2
-rw-r--r--editor/plugins/path_2d_editor_plugin.cpp223
-rw-r--r--editor/plugins/path_2d_editor_plugin.h2
-rw-r--r--editor/plugins/path_editor_plugin.cpp10
-rw-r--r--editor/plugins/path_editor_plugin.h2
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.cpp46
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.h2
-rw-r--r--editor/plugins/resource_preloader_editor_plugin.cpp5
-rw-r--r--editor/plugins/resource_preloader_editor_plugin.h2
-rw-r--r--editor/plugins/rich_text_editor_plugin.cpp151
-rw-r--r--editor/plugins/rich_text_editor_plugin.h90
-rw-r--r--editor/plugins/sample_editor_plugin.cpp452
-rw-r--r--editor/plugins/sample_editor_plugin.h93
-rw-r--r--editor/plugins/sample_library_editor_plugin.cpp547
-rw-r--r--editor/plugins/sample_library_editor_plugin.h108
-rw-r--r--editor/plugins/sample_player_editor_plugin.cpp202
-rw-r--r--editor/plugins/sample_player_editor_plugin.h91
-rw-r--r--editor/plugins/script_editor_plugin.cpp365
-rw-r--r--editor/plugins/script_editor_plugin.h13
-rw-r--r--editor/plugins/script_text_editor.cpp53
-rw-r--r--editor/plugins/script_text_editor.h7
-rw-r--r--editor/plugins/shader_editor_plugin.cpp130
-rw-r--r--editor/plugins/shader_editor_plugin.h11
-rw-r--r--editor/plugins/shader_graph_editor_plugin.cpp57
-rw-r--r--editor/plugins/shader_graph_editor_plugin.h11
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp444
-rw-r--r--editor/plugins/spatial_editor_plugin.h15
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp78
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.h4
-rw-r--r--editor/plugins/stream_editor_plugin.cpp150
-rw-r--r--editor/plugins/stream_editor_plugin.h85
-rw-r--r--editor/plugins/style_box_editor_plugin.cpp6
-rw-r--r--editor/plugins/style_box_editor_plugin.h2
-rw-r--r--editor/plugins/texture_editor_plugin.cpp14
-rw-r--r--editor/plugins/texture_editor_plugin.h2
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp16
-rw-r--r--editor/plugins/texture_region_editor_plugin.h2
-rw-r--r--editor/plugins/theme_editor_plugin.cpp12
-rw-r--r--editor/plugins/theme_editor_plugin.h2
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp16
-rw-r--r--editor/plugins/tile_map_editor_plugin.h2
-rw-r--r--editor/plugins/tile_set_editor_plugin.cpp23
-rw-r--r--editor/plugins/tile_set_editor_plugin.h2
93 files changed, 2756 insertions, 7403 deletions
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index ecae272b6d..cc7fc57cde 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -367,10 +367,6 @@ void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resou
int flg = 0;
if (EditorSettings::get_singleton()->get("filesystem/on_save/compress_binary_resources"))
flg |= ResourceSaver::FLAG_COMPRESS;
- /*
- if (EditorSettings::get_singleton()->get("filesystem/on_save/save_paths_as_relative"))
- flg |= ResourceSaver::FLAG_RELATIVE_PATHS;
- */
String path = ProjectSettings::get_singleton()->localize_path(p_path);
Error err = ResourceSaver::save(path, p_resource, flg | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS);
@@ -380,7 +376,6 @@ void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resou
accept->popup_centered_minsize();
return;
}
- //EditorFileSystem::get_singleton()->update_file(path,p_resource->get_type());
((Resource *)p_resource.ptr())->set_path(path);
editor->emit_signal("resource_saved", p_resource);
@@ -656,8 +651,8 @@ void AnimationPlayerEditor::set_state(const Dictionary &p_state) {
return;
Node *n = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["player"]);
- if (n && n->cast_to<AnimationPlayer>() && EditorNode::get_singleton()->get_editor_selection()->is_selected(n)) {
- player = n->cast_to<AnimationPlayer>();
+ if (Object::cast_to<AnimationPlayer>(n) && EditorNode::get_singleton()->get_editor_selection()->is_selected(n)) {
+ player = Object::cast_to<AnimationPlayer>(n);
_update_player();
show();
set_process(true);
@@ -737,9 +732,9 @@ void AnimationPlayerEditor::_dialog_action(String p_file) {
if (current != "") {
Ref<Animation> anim = player->get_animation(current);
- ERR_FAIL_COND(!anim->cast_to<Resource>())
+ ERR_FAIL_COND(!Object::cast_to<Resource>(*anim))
- RES current_res = RES(anim->cast_to<Resource>());
+ RES current_res = RES(Object::cast_to<Resource>(*anim));
_animation_save_in_path(current_res, p_file);
}
@@ -970,71 +965,6 @@ void AnimationPlayerEditor::_list_changed() {
if (is_visible_in_tree())
_update_player();
}
-#if 0
-void AnimationPlayerEditor::_editor_store() {
-
- if (animation->get_item_count()==0)
- return;
- String current = animation->get_item_text(animation->get_selected());
- Ref<Animation> anim = player->get_animation(current);
-
- if (key_editor->get_current_animation()==anim)
- return; //already there
-
-
- undo_redo->create_action("Store anim in editor");
- undo_redo->add_do_method(key_editor,"set_animation",anim);
- undo_redo->add_undo_method(key_editor,"remove_animation",anim);
- undo_redo->commit_action();
-}
-
-void AnimationPlayerEditor::_editor_load(){
-
- Ref<Animation> anim = key_editor->get_current_animation();
- if (anim.is_null())
- return;
-
- String existing = player->find_animation(anim);
- if (existing!="") {
- _select_anim_by_name(existing);
- return; //already has
- }
-
- int count=1;
- String base=anim->get_name();
- bool noname=false;
- if (base=="") {
- base="New Anim";
- noname=true;
- }
-
- while(true) {
- String attempt = base;
- if (count>1)
- attempt+=" ("+itos(count)+")";
- if (player->has_animation(attempt)) {
- count++;
- continue;
- }
- base=attempt;
- break;
- }
-
- if (noname)
- anim->set_name(base);
-
- undo_redo->create_action("Add Animation From Editor");
- undo_redo->add_do_method(player,"add_animation",base,anim);
- undo_redo->add_undo_method(player,"remove_animation",base);
- undo_redo->add_do_method(this,"_animation_player_changed",player);
- undo_redo->add_undo_method(this,"_animation_player_changed",player);
- undo_redo->commit_action();
-
- _select_anim_by_name(base);
-
-
-}
-#endif
void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) {
@@ -1395,7 +1325,6 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) {
error_dialog = memnew(ConfirmationDialog);
error_dialog->get_ok()->set_text(TTR("Close"));
- //error_dialog->get_cancel()->set_text("Close");
error_dialog->set_text(TTR("Error!"));
add_child(error_dialog);
@@ -1461,7 +1390,7 @@ void AnimationPlayerEditorPlugin::edit(Object *p_object) {
anim_editor->set_undo_redo(&get_undo_redo());
if (!p_object)
return;
- anim_editor->edit(p_object->cast_to<AnimationPlayer>());
+ anim_editor->edit(Object::cast_to<AnimationPlayer>(p_object));
}
bool AnimationPlayerEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h
index bcf40f52d3..cea6b05ed4 100644
--- a/editor/plugins/animation_player_editor_plugin.h
+++ b/editor/plugins/animation_player_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp
index 6e24d4d2cb..054124da8f 100644
--- a/editor/plugins/animation_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_tree_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -212,7 +212,7 @@ void AnimationTreeEditor::_edit_dialog_animation_changed() {
void AnimationTreeEditor::_edit_dialog_edit_animation() {
- if (get_tree()->is_editor_hint()) {
+ if (Engine::get_singleton()->is_editor_hint()) {
get_tree()->get_root()->get_child(0)->call("_resource_selected", property_editor->get_variant().operator RefPtr());
};
};
@@ -281,11 +281,11 @@ void AnimationTreeEditor::_popup_edit_dialog() {
case AnimationTreePlayer::NODE_ANIMATION:
- if (anim_tree->get_master_player() != NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>()) {
+ if (anim_tree->get_master_player() != NodePath() && anim_tree->has_node(anim_tree->get_master_player()) && Object::cast_to<AnimationPlayer>(anim_tree->get_node(anim_tree->get_master_player()))) {
- AnimationPlayer *ap = anim_tree->get_node(anim_tree->get_master_player())->cast_to<AnimationPlayer>();
+ AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(anim_tree->get_node(anim_tree->get_master_player()));
master_anim_popup->clear();
- master_anim_popup->add_item("Edit Filters");
+ master_anim_popup->add_item(TTR("Edit Filters"));
master_anim_popup->add_separator();
List<StringName> sn;
ap->get_animation_list(&sn);
@@ -605,15 +605,6 @@ void AnimationTreeEditor::_draw_node(const StringName &p_node) {
}
}
-#if 0
-void AnimationTreeEditor::_node_param_changed() {
-
- //anim_tree->node_set_param( click_node,property_editor->get_variant() );
- //update();
- //_write_anim_tree_graph();
-}
-#endif
-
AnimationTreeEditor::ClickType AnimationTreeEditor::_locate_click(const Point2 &p_click, StringName *p_node_id, int *p_slot_index) const {
Ref<StyleBox> style = get_stylebox("panel", "PopupMenu");
@@ -714,32 +705,6 @@ Point2 AnimationTreeEditor::_get_slot_pos(const StringName &p_node_id, bool p_in
return pos;
}
-#if 0
-void AnimationTreeEditor::_node_edit_property(const StringName& p_node) {
-
- Ref<StyleBox> style = get_stylebox("panel","PopupMenu");
- Size2 size = get_node_size(p_node);
- Point2 pos = Point2( anim_tree->node_get_pos_x(p_node), anim_tree->node_get_pos_y(p_node) )-offset;
-
- VisualServer::AnimationTreeNodeType type=anim_tree->node_get_type(p_node);
-
- PropertyInfo ph = VisualServer::get_singleton()->anim_tree_node_get_type_info(type);
- if (ph.type==Variant::NIL)
- return;
- if (ph.type==Variant::_RID)
- ph.type=Variant::RESOURCE;
-
- property_editor->edit(NULL,ph.name,ph.type,anim_tree->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_position();
- property_editor->set_position(popup_pos);
-
- property_editor->popup();
-
-}
-#endif
-
void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) {
Ref<InputEventMouseButton> mb = p_event;
@@ -1233,7 +1198,7 @@ void AnimationTreeEditor::_edit_filters() {
if (np.get_property() != StringName()) {
Node *n = base->get_node(np);
- Skeleton *s = n->cast_to<Skeleton>();
+ Skeleton *s = Object::cast_to<Skeleton>(n);
if (s) {
String skelbase = E->get().substr(0, E->get().find(":"));
@@ -1439,7 +1404,7 @@ AnimationTreeEditor::AnimationTreeEditor() {
void AnimationTreeEditorPlugin::edit(Object *p_object) {
- anim_tree_editor->edit(p_object->cast_to<AnimationTreePlayer>());
+ anim_tree_editor->edit(Object::cast_to<AnimationTreePlayer>(p_object));
}
bool AnimationTreeEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h
index 972c6c9b47..a5bef263f4 100644
--- a/editor/plugins/animation_tree_editor_plugin.h
+++ b/editor/plugins/animation_tree_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp
new file mode 100644
index 0000000000..626b4f5a7f
--- /dev/null
+++ b/editor/plugins/asset_library_editor_plugin.cpp
@@ -0,0 +1,1486 @@
+/*************************************************************************/
+/* asset_library_editor_plugin.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#include "asset_library_editor_plugin.h"
+
+#include "editor_node.h"
+#include "editor_settings.h"
+#include "io/json.h"
+
+void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost) {
+
+ title->set_text(p_title);
+ asset_id = p_asset_id;
+ category->set_text(p_category);
+ category_id = p_category_id;
+ author->set_text(p_author);
+ author_id = p_author_id;
+ price->set_text(p_cost);
+
+ for (int i = 0; i < 5; i++) {
+ if (i < p_rating)
+ stars[i]->set_texture(get_icon("RatingStar", "EditorIcons"));
+ else
+ stars[i]->set_texture(get_icon("RatingNoStar", "EditorIcons"));
+ }
+}
+
+void EditorAssetLibraryItem::set_image(int p_type, int p_index, const Ref<Texture> &p_image) {
+
+ ERR_FAIL_COND(p_type != EditorAssetLibrary::IMAGE_QUEUE_ICON);
+ ERR_FAIL_COND(p_index != 0);
+
+ icon->set_normal_texture(p_image);
+}
+
+void EditorAssetLibraryItem::_notification(int p_what) {
+
+ if (p_what == NOTIFICATION_ENTER_TREE) {
+
+ icon->set_normal_texture(get_icon("GodotAssetDefault", "EditorIcons"));
+ category->add_color_override("font_color", Color(0.5, 0.5, 0.5));
+ author->add_color_override("font_color", Color(0.5, 0.5, 0.5));
+ }
+}
+
+void EditorAssetLibraryItem::_asset_clicked() {
+
+ emit_signal("asset_selected", asset_id);
+}
+
+void EditorAssetLibraryItem::_category_clicked() {
+
+ emit_signal("category_selected", category_id);
+}
+void EditorAssetLibraryItem::_author_clicked() {
+
+ emit_signal("author_selected", author_id);
+}
+
+void EditorAssetLibraryItem::_bind_methods() {
+
+ ClassDB::bind_method("set_image", &EditorAssetLibraryItem::set_image);
+ ClassDB::bind_method("_asset_clicked", &EditorAssetLibraryItem::_asset_clicked);
+ ClassDB::bind_method("_category_clicked", &EditorAssetLibraryItem::_category_clicked);
+ ClassDB::bind_method("_author_clicked", &EditorAssetLibraryItem::_author_clicked);
+ ADD_SIGNAL(MethodInfo("asset_selected"));
+ ADD_SIGNAL(MethodInfo("category_selected"));
+ ADD_SIGNAL(MethodInfo("author_selected"));
+}
+
+EditorAssetLibraryItem::EditorAssetLibraryItem() {
+
+ Ref<StyleBoxEmpty> border;
+ border.instance();
+ border->set_default_margin(MARGIN_LEFT, 5);
+ border->set_default_margin(MARGIN_RIGHT, 5);
+ border->set_default_margin(MARGIN_BOTTOM, 5);
+ border->set_default_margin(MARGIN_TOP, 5);
+ add_style_override("panel", border);
+
+ HBoxContainer *hb = memnew(HBoxContainer);
+ add_child(hb);
+
+ icon = memnew(TextureButton);
+ icon->set_default_cursor_shape(CURSOR_POINTING_HAND);
+ icon->connect("pressed", this, "_asset_clicked");
+
+ hb->add_child(icon);
+
+ VBoxContainer *vb = memnew(VBoxContainer);
+
+ hb->add_child(vb);
+ vb->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ title = memnew(LinkButton);
+ title->set_text("My Awesome Addon");
+ title->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
+ title->connect("pressed", this, "_asset_clicked");
+ vb->add_child(title);
+
+ category = memnew(LinkButton);
+ category->set_text("Editor Tools");
+ category->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
+ category->connect("pressed", this, "_category_clicked");
+ vb->add_child(category);
+
+ author = memnew(LinkButton);
+ author->set_text("Johny Tolengo");
+ author->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
+ author->connect("pressed", this, "_author_clicked");
+ vb->add_child(author);
+
+ HBoxContainer *rating_hb = memnew(HBoxContainer);
+ vb->add_child(rating_hb);
+
+ for (int i = 0; i < 5; i++) {
+ stars[i] = memnew(TextureRect);
+ rating_hb->add_child(stars[i]);
+ }
+ price = memnew(Label);
+ price->set_text(TTR("Free"));
+ vb->add_child(price);
+
+ set_custom_minimum_size(Size2(250, 100));
+ set_h_size_flags(SIZE_EXPAND_FILL);
+
+ set_mouse_filter(MOUSE_FILTER_PASS);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const Ref<Texture> &p_image) {
+
+ switch (p_type) {
+
+ case EditorAssetLibrary::IMAGE_QUEUE_ICON: {
+
+ item->call("set_image", p_type, p_index, p_image);
+ icon = p_image;
+ } break;
+ case EditorAssetLibrary::IMAGE_QUEUE_THUMBNAIL: {
+
+ for (int i = 0; i < preview_images.size(); i++) {
+ if (preview_images[i].id == p_index) {
+ preview_images[i].button->set_icon(p_image);
+ break;
+ }
+ }
+ //item->call("set_image",p_type,p_index,p_image);
+ } break;
+ case EditorAssetLibrary::IMAGE_QUEUE_SCREENSHOT: {
+
+ for (int i = 0; i < preview_images.size(); i++) {
+ if (preview_images[i].id == p_index) {
+ preview_images[i].image = p_image;
+ if (preview_images[i].button->is_pressed()) {
+ _preview_click(p_index);
+ }
+ break;
+ }
+ }
+ //item->call("set_image",p_type,p_index,p_image);
+ } break;
+ }
+}
+void EditorAssetLibraryItemDescription::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ previews_bg->add_style_override("panel", get_stylebox("normal", "TextEdit"));
+ desc_bg->add_style_override("panel", get_stylebox("normal", "TextEdit"));
+ } break;
+ }
+}
+void EditorAssetLibraryItemDescription::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_image"), &EditorAssetLibraryItemDescription::set_image);
+ ClassDB::bind_method(D_METHOD("_link_click"), &EditorAssetLibraryItemDescription::_link_click);
+ ClassDB::bind_method(D_METHOD("_preview_click"), &EditorAssetLibraryItemDescription::_preview_click);
+}
+
+void EditorAssetLibraryItemDescription::_link_click(const String &p_url) {
+ ERR_FAIL_COND(!p_url.begins_with("http"));
+ OS::get_singleton()->shell_open(p_url);
+}
+
+void EditorAssetLibraryItemDescription::_preview_click(int p_id) {
+ for (int i = 0; i < preview_images.size(); i++) {
+ if (preview_images[i].id == p_id) {
+ preview_images[i].button->set_pressed(true);
+ if (!preview_images[i].is_video) {
+ if (preview_images[i].image.is_valid()) {
+ preview->set_texture(preview_images[i].image);
+ }
+ } else {
+ _link_click(preview_images[i].video_link);
+ }
+ } else {
+ preview_images[i].button->set_pressed(false);
+ }
+ }
+}
+
+void EditorAssetLibraryItemDescription::configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost, int p_version, const String &p_version_string, const String &p_description, const String &p_download_url, const String &p_browse_url, const String &p_sha256_hash) {
+
+ asset_id = p_asset_id;
+ title = p_title;
+ download_url = p_download_url;
+ sha256 = p_sha256_hash;
+ item->configure(p_title, p_asset_id, p_category, p_category_id, p_author, p_author_id, p_rating, p_cost);
+ description->clear();
+ description->add_text(TTR("Version:") + " " + p_version_string + "\n");
+ description->add_text(TTR("Contents:") + " ");
+ description->push_meta(p_browse_url);
+ description->add_text(TTR("View Files"));
+ description->pop();
+ description->add_text("\n" + TTR("Description:") + "\n\n");
+ description->append_bbcode(p_description);
+ set_title(p_title);
+}
+
+void EditorAssetLibraryItemDescription::add_preview(int p_id, bool p_video, const String &p_url) {
+
+ Preview preview;
+ preview.id = p_id;
+ preview.video_link = p_url;
+ preview.is_video = p_video;
+ preview.button = memnew(Button);
+ preview.button->set_flat(true);
+ preview.button->set_icon(get_icon("ThumbnailWait", "EditorIcons"));
+ preview.button->set_toggle_mode(true);
+ preview.button->connect("pressed", this, "_preview_click", varray(p_id));
+ preview_hb->add_child(preview.button);
+ if (!p_video) {
+ preview.image = get_icon("ThumbnailWait", "EditorIcons");
+ }
+ if (preview_images.size() == 0 && !p_video) {
+ _preview_click(p_id);
+ }
+ preview_images.push_back(preview);
+}
+
+EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() {
+
+ VBoxContainer *vbox = memnew(VBoxContainer);
+ add_child(vbox);
+
+ HBoxContainer *hbox = memnew(HBoxContainer);
+ vbox->add_child(hbox);
+ vbox->add_constant_override("separation", 15);
+ VBoxContainer *desc_vbox = memnew(VBoxContainer);
+ hbox->add_child(desc_vbox);
+ hbox->add_constant_override("separation", 15);
+
+ item = memnew(EditorAssetLibraryItem);
+
+ desc_vbox->add_child(item);
+ desc_vbox->set_custom_minimum_size(Size2(300, 0));
+
+ desc_bg = memnew(PanelContainer);
+ desc_vbox->add_child(desc_bg);
+ desc_bg->set_v_size_flags(SIZE_EXPAND_FILL);
+
+ description = memnew(RichTextLabel);
+ description->connect("meta_clicked", this, "_link_click");
+ desc_bg->add_child(description);
+
+ preview = memnew(TextureRect);
+ preview->set_custom_minimum_size(Size2(640, 345));
+ hbox->add_child(preview);
+
+ previews_bg = memnew(PanelContainer);
+ vbox->add_child(previews_bg);
+ previews_bg->set_custom_minimum_size(Size2(0, 85));
+
+ previews = memnew(ScrollContainer);
+ previews_bg->add_child(previews);
+ previews->set_enable_v_scroll(false);
+ previews->set_enable_h_scroll(true);
+ preview_hb = memnew(HBoxContainer);
+ preview_hb->set_v_size_flags(SIZE_EXPAND_FILL);
+
+ previews->add_child(preview_hb);
+ get_ok()->set_text(TTR("Install"));
+ get_cancel()->set_text(TTR("Close"));
+}
+///////////////////////////////////////////////////////////////////////////////////
+
+void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) {
+
+ String error_text;
+ print_line("COMPLETED: " + itos(p_status) + " code: " + itos(p_code) + " data size: " + itos(p_data.size()));
+
+ switch (p_status) {
+
+ case HTTPRequest::RESULT_CANT_RESOLVE: {
+ error_text = TTR("Can't resolve hostname:") + " " + host;
+ status->set_text(TTR("Can't resolve."));
+ } break;
+ case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED:
+ case HTTPRequest::RESULT_CONNECTION_ERROR:
+ case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: {
+ error_text = TTR("Connection error, please try again.");
+ status->set_text(TTR("Can't connect."));
+ } break;
+ case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR:
+ case HTTPRequest::RESULT_CANT_CONNECT: {
+ error_text = TTR("Can't connect to host:") + " " + host;
+ status->set_text(TTR("Can't connect."));
+ } break;
+ case HTTPRequest::RESULT_NO_RESPONSE: {
+ error_text = TTR("No response from host:") + " " + host;
+ status->set_text(TTR("No response."));
+ } break;
+ case HTTPRequest::RESULT_REQUEST_FAILED: {
+ error_text = TTR("Request failed, return code:") + " " + itos(p_code);
+ status->set_text(TTR("Req. Failed."));
+ } break;
+ case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: {
+ error_text = TTR("Request failed, too many redirects");
+ status->set_text(TTR("Redirect Loop."));
+ } break;
+ default: {
+ if (p_code != 200) {
+ error_text = TTR("Request failed, return code:") + " " + itos(p_code);
+ status->set_text(TTR("Failed:") + " " + itos(p_code));
+ } else if (sha256 != "") {
+ String download_sha256 = FileAccess::get_sha256(download->get_download_file());
+ if (sha256 != download_sha256) {
+ error_text = TTR("Bad download hash, assuming file has been tampered with.") + "\n";
+ error_text += TTR("Expected:") + " " + sha256 + "\n" + TTR("Got:") + " " + download_sha256;
+ status->set_text(TTR("Failed sha256 hash check"));
+ }
+ }
+ } break;
+ }
+
+ if (error_text != String()) {
+ download_error->set_text(TTR("Asset Download Error:") + "\n" + error_text);
+ download_error->popup_centered_minsize();
+ return;
+ }
+
+ progress->set_max(download->get_body_size());
+ progress->set_value(download->get_downloaded_bytes());
+
+ print_line("max: " + itos(download->get_body_size()) + " bytes: " + itos(download->get_downloaded_bytes()));
+ install->set_disabled(false);
+
+ progress->set_value(download->get_downloaded_bytes());
+
+ status->set_text(TTR("Success!") + " (" + String::humanize_size(download->get_downloaded_bytes()) + ")");
+ set_process(false);
+}
+
+void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asset_id, const Ref<Texture> &p_preview, const String &p_download_url, const String &p_sha256_hash) {
+
+ title->set_text(p_title);
+ icon->set_texture(p_preview);
+ asset_id = p_asset_id;
+ if (!p_preview.is_valid())
+ icon->set_texture(get_icon("GodotAssetDefault", "EditorIcons"));
+ host = p_download_url;
+ sha256 = p_sha256_hash;
+ asset_installer->connect("confirmed", this, "_close");
+ dismiss->set_normal_texture(get_icon("Close", "EditorIcons"));
+ _make_request();
+}
+
+void EditorAssetLibraryItemDownload::_notification(int p_what) {
+
+ if (p_what == NOTIFICATION_PROCESS) {
+
+ progress->set_max(download->get_body_size());
+ progress->set_value(download->get_downloaded_bytes());
+
+ int cstatus = download->get_http_client_status();
+
+ if (cstatus == HTTPClient::STATUS_BODY)
+ status->set_text(TTR("Fetching:") + " " + String::humanize_size(download->get_downloaded_bytes()));
+
+ if (cstatus != prev_status) {
+ switch (cstatus) {
+
+ case HTTPClient::STATUS_RESOLVING: {
+ status->set_text(TTR("Resolving.."));
+ } break;
+ case HTTPClient::STATUS_CONNECTING: {
+ status->set_text(TTR("Connecting.."));
+ } break;
+ case HTTPClient::STATUS_REQUESTING: {
+ status->set_text(TTR("Requesting.."));
+ } break;
+ default: {}
+ }
+ prev_status = cstatus;
+ }
+ }
+}
+void EditorAssetLibraryItemDownload::_close() {
+
+ DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
+ da->remove(download->get_download_file()); //clean up removed file
+ memdelete(da);
+ queue_delete();
+}
+
+void EditorAssetLibraryItemDownload::_install() {
+
+ String file = download->get_download_file();
+
+ if (external_install) {
+ emit_signal("install_asset", file, title->get_text());
+ return;
+ }
+
+ asset_installer->open(file, 1);
+}
+
+void EditorAssetLibraryItemDownload::_make_request() {
+ download->cancel_request();
+ download->set_download_file(EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("tmp_asset_" + itos(asset_id)) + ".zip");
+
+ Error err = download->request(host);
+ if (err != OK) {
+ status->set_text(TTR("Error making request"));
+ } else {
+ set_process(true);
+ }
+}
+
+void EditorAssetLibraryItemDownload::_bind_methods() {
+
+ ClassDB::bind_method("_http_download_completed", &EditorAssetLibraryItemDownload::_http_download_completed);
+ ClassDB::bind_method("_install", &EditorAssetLibraryItemDownload::_install);
+ ClassDB::bind_method("_close", &EditorAssetLibraryItemDownload::_close);
+ ClassDB::bind_method("_make_request", &EditorAssetLibraryItemDownload::_make_request);
+
+ ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name")));
+}
+
+EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() {
+
+ HBoxContainer *hb = memnew(HBoxContainer);
+ add_child(hb);
+ icon = memnew(TextureRect);
+ hb->add_child(icon);
+
+ VBoxContainer *vb = memnew(VBoxContainer);
+ hb->add_child(vb);
+ vb->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ HBoxContainer *title_hb = memnew(HBoxContainer);
+ vb->add_child(title_hb);
+ title = memnew(Label);
+ title_hb->add_child(title);
+ title->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ dismiss = memnew(TextureButton);
+ dismiss->connect("pressed", this, "_close");
+ title_hb->add_child(dismiss);
+
+ title->set_clip_text(true);
+
+ vb->add_spacer();
+
+ status = memnew(Label(TTR("Idle")));
+ vb->add_child(status);
+ status->add_color_override("font_color", Color(0.5, 0.5, 0.5));
+ progress = memnew(ProgressBar);
+ vb->add_child(progress);
+
+ HBoxContainer *hb2 = memnew(HBoxContainer);
+ vb->add_child(hb2);
+ hb2->add_spacer();
+
+ install = memnew(Button);
+ install->set_text(TTR("Install"));
+ install->set_disabled(true);
+ install->connect("pressed", this, "_install");
+
+ retry = memnew(Button);
+ retry->set_text(TTR("Retry"));
+ retry->connect("pressed", this, "_make_request");
+
+ hb2->add_child(retry);
+ hb2->add_child(install);
+ set_custom_minimum_size(Size2(250, 0));
+
+ download = memnew(HTTPRequest);
+ add_child(download);
+ download->connect("request_completed", this, "_http_download_completed");
+
+ download_error = memnew(AcceptDialog);
+ add_child(download_error);
+ download_error->set_title(TTR("Download Error"));
+
+ asset_installer = memnew(EditorAssetInstaller);
+ add_child(asset_installer);
+
+ prev_status = -1;
+
+ external_install = false;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+void EditorAssetLibrary::_notification(int p_what) {
+
+ switch (p_what) {
+ case NOTIFICATION_READY: {
+
+ TextureRect *tf = memnew(TextureRect);
+ tf->set_texture(get_icon("Error", "EditorIcons"));
+ reverse->set_icon(get_icon("Sort", "EditorIcons"));
+
+ error_hb->add_child(tf);
+ error_label->raise();
+ } break;
+
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+
+ if (is_visible()) {
+ _repository_changed(0); // Update when shown for the first time
+ }
+ } break;
+
+ case NOTIFICATION_PROCESS: {
+
+ HTTPClient::Status s = request->get_http_client_status();
+ bool visible = s != HTTPClient::STATUS_DISCONNECTED;
+
+ if (visible != load_status->is_visible()) {
+ load_status->set_visible(visible);
+ }
+
+ if (visible) {
+ switch (s) {
+
+ case HTTPClient::STATUS_RESOLVING: {
+ load_status->set_value(0.1);
+ } break;
+ case HTTPClient::STATUS_CONNECTING: {
+ load_status->set_value(0.2);
+ } break;
+ case HTTPClient::STATUS_REQUESTING: {
+ load_status->set_value(0.3);
+ } break;
+ case HTTPClient::STATUS_BODY: {
+ load_status->set_value(0.4);
+ } break;
+ default: {}
+ }
+ }
+
+ bool no_downloads = downloads_hb->get_child_count() == 0;
+ if (no_downloads == downloads_scroll->is_visible()) {
+ downloads_scroll->set_visible(!no_downloads);
+ }
+
+ } break;
+ case NOTIFICATION_THEME_CHANGED: {
+
+ library_scroll_bg->add_style_override("panel", get_stylebox("bg", "Tree"));
+ } break;
+ }
+}
+
+void EditorAssetLibrary::_install_asset() {
+
+ ERR_FAIL_COND(!description);
+
+ for (int i = 0; i < downloads_hb->get_child_count(); i++) {
+
+ EditorAssetLibraryItemDownload *d = Object::cast_to<EditorAssetLibraryItemDownload>(downloads_hb->get_child(i));
+ if (d && d->get_asset_id() == description->get_asset_id()) {
+
+ if (EditorNode::get_singleton() != NULL)
+ EditorNode::get_singleton()->show_warning(TTR("Download for this asset is already in progress!"));
+ return;
+ }
+ }
+
+ EditorAssetLibraryItemDownload *download = memnew(EditorAssetLibraryItemDownload);
+ downloads_hb->add_child(download);
+ download->configure(description->get_title(), description->get_asset_id(), description->get_preview_icon(), description->get_download_url(), description->get_sha256());
+
+ if (templates_only) {
+ download->set_external_install(true);
+ download->connect("install_asset", this, "_install_external_asset");
+ }
+}
+
+const char *EditorAssetLibrary::sort_key[SORT_MAX] = {
+ "rating",
+ "downloads",
+ "name",
+ "cost",
+ "updated"
+};
+
+const char *EditorAssetLibrary::sort_text[SORT_MAX] = {
+ "Rating",
+ "Downloads",
+ "Name",
+ "Cost",
+ "Updated"
+};
+
+const char *EditorAssetLibrary::support_key[SUPPORT_MAX] = {
+ "official",
+ "community",
+ "testing"
+};
+
+void EditorAssetLibrary::_select_author(int p_id) {
+
+ //opemn author window
+}
+
+void EditorAssetLibrary::_select_category(int p_id) {
+
+ for (int i = 0; i < categories->get_item_count(); i++) {
+
+ if (i == 0)
+ continue;
+ int id = categories->get_item_metadata(i);
+ if (id == p_id) {
+ categories->select(i);
+ _search();
+ break;
+ }
+ }
+}
+void EditorAssetLibrary::_select_asset(int p_id) {
+
+ _api_request("asset/" + itos(p_id), REQUESTING_ASSET);
+
+ /*
+ if (description) {
+ memdelete(description);
+ }
+
+
+ description = memnew( EditorAssetLibraryItemDescription );
+ add_child(description);
+ description->popup_centered_minsize();*/
+}
+
+void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByteArray &p_data, int p_queue_id) {
+ Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target);
+
+ if (obj) {
+ bool image_set = false;
+ PoolByteArray image_data = p_data;
+
+ if (use_cache) {
+ String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
+
+ FileAccess *file = FileAccess::open(cache_filename_base + ".data", FileAccess::READ);
+
+ if (file) {
+ PoolByteArray cached_data;
+ int len = file->get_32();
+ cached_data.resize(len);
+
+ PoolByteArray::Write w = cached_data.write();
+ file->get_buffer(w.ptr(), len);
+
+ image_data = cached_data;
+ file->close();
+ }
+ }
+
+ int len = image_data.size();
+ PoolByteArray::Read r = image_data.read();
+ Ref<Image> image = Ref<Image>(memnew(Image(r.ptr(), len)));
+
+ if (!image->empty()) {
+ float max_height = 10000;
+ switch (image_queue[p_queue_id].image_type) {
+ case IMAGE_QUEUE_ICON: max_height = 80; break;
+ case IMAGE_QUEUE_THUMBNAIL: max_height = 80; break;
+ case IMAGE_QUEUE_SCREENSHOT: max_height = 345; break;
+ }
+ float scale_ratio = max_height / image->get_height();
+ if (scale_ratio < 1) {
+ image->resize(image->get_width() * scale_ratio, image->get_height() * scale_ratio, Image::INTERPOLATE_CUBIC);
+ }
+
+ Ref<ImageTexture> tex;
+ tex.instance();
+ tex->create_from_image(image);
+
+ obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, tex);
+ image_set = true;
+ }
+
+ if (!image_set && final) {
+ obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("ErrorSign", "EditorIcons"));
+ }
+ }
+}
+
+void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data, int p_queue_id) {
+
+ ERR_FAIL_COND(!image_queue.has(p_queue_id));
+
+ if (p_status == HTTPRequest::RESULT_SUCCESS) {
+
+ print_line("GOT IMAGE YAY!");
+
+ if (p_code != HTTPClient::RESPONSE_NOT_MODIFIED) {
+ for (int i = 0; i < headers.size(); i++) {
+ if (headers[i].findn("ETag:") == 0) { // Save etag
+ String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text());
+ String new_etag = headers[i].substr(headers[i].find(":") + 1, headers[i].length()).strip_edges();
+ FileAccess *file;
+
+ file = FileAccess::open(cache_filename_base + ".etag", FileAccess::WRITE);
+ if (file) {
+ file->store_line(new_etag);
+ file->close();
+ }
+
+ int len = p_data.size();
+ PoolByteArray::Read r = p_data.read();
+ file = FileAccess::open(cache_filename_base + ".data", FileAccess::WRITE);
+ if (file) {
+ file->store_32(len);
+ file->store_buffer(r.ptr(), len);
+ file->close();
+ }
+
+ break;
+ }
+ }
+ }
+ _image_update(p_code == HTTPClient::RESPONSE_NOT_MODIFIED, true, p_data, p_queue_id);
+
+ } else {
+ WARN_PRINTS("Error getting PNG file for asset id " + itos(image_queue[p_queue_id].asset_id));
+ Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target);
+ if (obj) {
+ obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("ErrorSign", "EditorIcons"));
+ }
+ }
+
+ image_queue[p_queue_id].request->queue_delete();
+ image_queue.erase(p_queue_id);
+
+ _update_image_queue();
+}
+
+void EditorAssetLibrary::_update_image_queue() {
+
+ int max_images = 2;
+ int current_images = 0;
+
+ List<int> to_delete;
+ for (Map<int, ImageQueue>::Element *E = image_queue.front(); E; E = E->next()) {
+ if (!E->get().active && current_images < max_images) {
+
+ String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + E->get().image_url.md5_text());
+ Vector<String> headers;
+
+ if (FileAccess::exists(cache_filename_base + ".etag") && FileAccess::exists(cache_filename_base + ".data")) {
+ FileAccess *file = FileAccess::open(cache_filename_base + ".etag", FileAccess::READ);
+ if (file) {
+ headers.push_back("If-None-Match: " + file->get_line());
+ file->close();
+ }
+ }
+
+ print_line("REQUEST ICON FOR: " + itos(E->get().asset_id));
+ Error err = E->get().request->request(E->get().image_url, headers);
+ if (err != OK) {
+ to_delete.push_back(E->key());
+ } else {
+ E->get().active = true;
+ }
+ current_images++;
+ } else if (E->get().active) {
+ current_images++;
+ }
+ }
+
+ while (to_delete.size()) {
+ image_queue[to_delete.front()->get()].request->queue_delete();
+ image_queue.erase(to_delete.front()->get());
+ to_delete.pop_front();
+ }
+}
+
+void EditorAssetLibrary::_request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index) {
+
+ ImageQueue iq;
+ iq.image_url = p_image_url;
+ iq.image_index = p_image_index;
+ iq.image_type = p_type;
+ iq.request = memnew(HTTPRequest);
+
+ iq.target = p_for;
+ iq.queue_id = ++last_queue_id;
+ iq.active = false;
+
+ iq.request->connect("request_completed", this, "_image_request_completed", varray(iq.queue_id));
+
+ image_queue[iq.queue_id] = iq;
+
+ add_child(iq.request);
+
+ _image_update(true, false, PoolByteArray(), iq.queue_id);
+ _update_image_queue();
+}
+
+void EditorAssetLibrary::_repository_changed(int p_repository_id) {
+ host = repository->get_item_metadata(p_repository_id);
+ print_line(".." + host);
+ if (templates_only) {
+ _api_request("configure", REQUESTING_CONFIG, "?type=project");
+ } else {
+ _api_request("configure", REQUESTING_CONFIG);
+ }
+}
+
+void EditorAssetLibrary::_support_toggled(int p_support) {
+ support->get_popup()->set_item_checked(p_support, !support->get_popup()->is_item_checked(p_support));
+ _search();
+}
+
+void EditorAssetLibrary::_rerun_search(int p_ignore) {
+ _search();
+}
+
+void EditorAssetLibrary::_search(int p_page) {
+
+ String args;
+
+ if (templates_only) {
+ args += "?type=project&";
+ } else {
+ args += "?";
+ }
+ args += String() + "sort=" + sort_key[sort->get_selected()];
+
+ String support_list;
+ for (int i = 0; i < SUPPORT_MAX; i++) {
+ if (support->get_popup()->is_item_checked(i)) {
+ support_list += String(support_key[i]) + "+";
+ }
+ }
+ if (support_list != String()) {
+ args += "&support=" + support_list.substr(0, support_list.length() - 1);
+ }
+
+ if (categories->get_selected() > 0) {
+
+ args += "&category=" + itos(categories->get_item_metadata(categories->get_selected()));
+ }
+
+ if (reverse->is_pressed()) {
+
+ args += "&reverse=true";
+ }
+
+ if (filter->get_text() != String()) {
+ args += "&filter=" + filter->get_text().http_escape();
+ }
+
+ if (p_page > 0) {
+ args += "&page=" + itos(p_page);
+ }
+
+ _api_request("asset", REQUESTING_SEARCH, args);
+}
+
+HBoxContainer *EditorAssetLibrary::_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items) {
+
+ HBoxContainer *hbc = memnew(HBoxContainer);
+
+ //do the mario
+ int from = p_page - 5;
+ if (from < 0)
+ from = 0;
+ int to = from + 10;
+ if (to > p_page_count)
+ to = p_page_count;
+
+ Color gray = Color(0.65, 0.65, 0.65);
+
+ hbc->add_spacer();
+ hbc->add_constant_override("separation", 10);
+
+ if (p_page != 0) {
+ LinkButton *first = memnew(LinkButton);
+ first->set_text(TTR("first"));
+ first->add_color_override("font_color", gray);
+ first->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
+ first->connect("pressed", this, "_search", varray(0));
+ hbc->add_child(first);
+ }
+
+ if (p_page > 0) {
+ LinkButton *prev = memnew(LinkButton);
+ prev->set_text(TTR("prev"));
+ prev->add_color_override("font_color", gray);
+ prev->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
+ prev->connect("pressed", this, "_search", varray(p_page - 1));
+ hbc->add_child(prev);
+ }
+
+ for (int i = from; i < to; i++) {
+
+ if (i == p_page) {
+
+ Label *current = memnew(Label);
+ current->set_text(itos(i + 1));
+ hbc->add_child(current);
+ } else {
+
+ LinkButton *current = memnew(LinkButton);
+ current->add_color_override("font_color", gray);
+ current->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
+ current->set_text(itos(i + 1));
+ current->connect("pressed", this, "_search", varray(i));
+
+ hbc->add_child(current);
+ }
+ }
+
+ if (p_page < p_page_count - 1) {
+ LinkButton *next = memnew(LinkButton);
+ next->set_text(TTR("next"));
+ next->add_color_override("font_color", gray);
+ next->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
+ next->connect("pressed", this, "_search", varray(p_page + 1));
+
+ hbc->add_child(next);
+ }
+
+ if (p_page != p_page_count - 1) {
+ LinkButton *last = memnew(LinkButton);
+ last->set_text(TTR("last"));
+ last->add_color_override("font_color", gray);
+ last->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER);
+ hbc->add_child(last);
+ last->connect("pressed", this, "_search", varray(p_page_count - 1));
+ }
+
+ Label *totals = memnew(Label);
+ totals->set_text("( " + itos(from * p_page_len) + " - " + itos(from * p_page_len + p_current_items - 1) + " / " + itos(p_total_items) + " )");
+ hbc->add_child(totals);
+
+ hbc->add_spacer();
+
+ return hbc;
+}
+
+void EditorAssetLibrary::_api_request(const String &p_request, RequestType p_request_type, const String &p_arguments) {
+
+ if (requesting != REQUESTING_NONE) {
+ request->cancel_request();
+ }
+
+ requesting = p_request_type;
+
+ error_hb->hide();
+ request->request(host + "/" + p_request + p_arguments);
+}
+
+void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data) {
+
+ String str;
+
+ {
+ int datalen = p_data.size();
+ PoolByteArray::Read r = p_data.read();
+ str.parse_utf8((const char *)r.ptr(), datalen);
+ }
+
+ bool error_abort = true;
+
+ switch (p_status) {
+
+ case HTTPRequest::RESULT_CANT_RESOLVE: {
+ error_label->set_text(TTR("Can't resolve hostname:") + " " + host);
+ } break;
+ case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED:
+ case HTTPRequest::RESULT_CONNECTION_ERROR:
+ case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: {
+ error_label->set_text(TTR("Connection error, please try again."));
+ } break;
+ case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR:
+ case HTTPRequest::RESULT_CANT_CONNECT: {
+ error_label->set_text(TTR("Can't connect to host:") + " " + host);
+ } break;
+ case HTTPRequest::RESULT_NO_RESPONSE: {
+ error_label->set_text(TTR("No response from host:") + " " + host);
+ } break;
+ case HTTPRequest::RESULT_REQUEST_FAILED: {
+ error_label->set_text(TTR("Request failed, return code:") + " " + itos(p_code));
+ } break;
+ case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: {
+ error_label->set_text(TTR("Request failed, too many redirects"));
+
+ } break;
+ default: {
+ if (p_code != 200) {
+ error_label->set_text(TTR("Request failed, return code:") + " " + itos(p_code));
+ } else {
+
+ error_abort = false;
+ }
+ } break;
+ }
+
+ if (error_abort) {
+ error_hb->show();
+ return;
+ }
+
+ print_line("response: " + itos(p_status) + " code: " + itos(p_code));
+
+ Dictionary d;
+ {
+ Variant js;
+ String errs;
+ int errl;
+ JSON::parse(str, js, errs, errl);
+ d = js;
+ }
+
+ print_line(Variant(d).get_construct_string());
+
+ RequestType requested = requesting;
+ requesting = REQUESTING_NONE;
+
+ switch (requested) {
+ case REQUESTING_CONFIG: {
+
+ categories->clear();
+ categories->add_item(TTR("All"));
+ categories->set_item_metadata(0, 0);
+ if (d.has("categories")) {
+ Array clist = d["categories"];
+ for (int i = 0; i < clist.size(); i++) {
+ Dictionary cat = clist[i];
+ if (!cat.has("name") || !cat.has("id"))
+ continue;
+ String name = cat["name"];
+ int id = cat["id"];
+ categories->add_item(name);
+ categories->set_item_metadata(categories->get_item_count() - 1, id);
+ category_map[cat["id"]] = name;
+ }
+ }
+
+ _search();
+ } break;
+ case REQUESTING_SEARCH: {
+ if (asset_items) {
+ memdelete(asset_items);
+ }
+
+ if (asset_top_page) {
+ memdelete(asset_top_page);
+ }
+
+ if (asset_bottom_page) {
+ memdelete(asset_bottom_page);
+ }
+
+ int page = 0;
+ int pages = 1;
+ int page_len = 10;
+ int total_items = 1;
+ Array result;
+
+ if (d.has("page")) {
+ page = d["page"];
+ }
+ if (d.has("pages")) {
+ pages = d["pages"];
+ }
+ if (d.has("page_length")) {
+ page_len = d["page_length"];
+ }
+ if (d.has("total")) {
+ total_items = d["total"];
+ }
+ if (d.has("result")) {
+ result = d["result"];
+ }
+
+ asset_top_page = _make_pages(page, pages, page_len, total_items, result.size());
+ library_vb->add_child(asset_top_page);
+
+ asset_items = memnew(GridContainer);
+ asset_items->set_columns(2);
+ asset_items->add_constant_override("hseparation", 10);
+ asset_items->add_constant_override("vseparation", 10);
+
+ library_vb->add_child(asset_items);
+
+ asset_bottom_page = _make_pages(page, pages, page_len, total_items, result.size());
+ library_vb->add_child(asset_bottom_page);
+
+ for (int i = 0; i < result.size(); i++) {
+
+ Dictionary r = result[i];
+
+ ERR_CONTINUE(!r.has("title"));
+ ERR_CONTINUE(!r.has("asset_id"));
+ ERR_CONTINUE(!r.has("author"));
+ ERR_CONTINUE(!r.has("author_id"));
+ ERR_CONTINUE(!r.has("category_id"));
+ ERR_FAIL_COND(!category_map.has(r["category_id"]));
+ ERR_CONTINUE(!r.has("rating"));
+ ERR_CONTINUE(!r.has("cost"));
+
+ EditorAssetLibraryItem *item = memnew(EditorAssetLibraryItem);
+ asset_items->add_child(item);
+ item->configure(r["title"], r["asset_id"], category_map[r["category_id"]], r["category_id"], r["author"], r["author_id"], r["rating"], r["cost"]);
+ item->connect("asset_selected", this, "_select_asset");
+ item->connect("author_selected", this, "_select_author");
+ item->connect("category_selected", this, "_select_category");
+
+ if (r.has("icon_url") && r["icon_url"] != "") {
+ _request_image(item->get_instance_id(), r["icon_url"], IMAGE_QUEUE_ICON, 0);
+ }
+ }
+ } break;
+ case REQUESTING_ASSET: {
+ Dictionary r = d;
+
+ ERR_FAIL_COND(!r.has("title"));
+ ERR_FAIL_COND(!r.has("asset_id"));
+ ERR_FAIL_COND(!r.has("author"));
+ ERR_FAIL_COND(!r.has("author_id"));
+ ERR_FAIL_COND(!r.has("version"));
+ ERR_FAIL_COND(!r.has("version_string"));
+ ERR_FAIL_COND(!r.has("category_id"));
+ ERR_FAIL_COND(!category_map.has(r["category_id"]));
+ ERR_FAIL_COND(!r.has("rating"));
+ ERR_FAIL_COND(!r.has("cost"));
+ ERR_FAIL_COND(!r.has("description"));
+ ERR_FAIL_COND(!r.has("download_url"));
+ ERR_FAIL_COND(!r.has("download_hash"));
+ ERR_FAIL_COND(!r.has("browse_url"));
+
+ if (description) {
+ memdelete(description);
+ }
+
+ description = memnew(EditorAssetLibraryItemDescription);
+ add_child(description);
+ description->popup_centered_minsize();
+ description->connect("confirmed", this, "_install_asset");
+
+ description->configure(r["title"], r["asset_id"], category_map[r["category_id"]], r["category_id"], r["author"], r["author_id"], r["rating"], r["cost"], r["version"], r["version_string"], r["description"], r["download_url"], r["browse_url"], r["download_hash"]);
+ /*item->connect("asset_selected",this,"_select_asset");
+ item->connect("author_selected",this,"_select_author");
+ item->connect("category_selected",this,"_category_selected");*/
+
+ if (r.has("icon_url") && r["icon_url"] != "") {
+ _request_image(description->get_instance_id(), r["icon_url"], IMAGE_QUEUE_ICON, 0);
+ }
+
+ if (d.has("previews")) {
+ Array previews = d["previews"];
+
+ for (int i = 0; i < previews.size(); i++) {
+
+ Dictionary p = previews[i];
+
+ ERR_CONTINUE(!p.has("type"));
+ ERR_CONTINUE(!p.has("link"));
+
+ bool is_video = p.has("type") && String(p["type"]) == "video";
+ String video_url;
+ if (is_video && p.has("link")) {
+ video_url = p["link"];
+ }
+
+ description->add_preview(i, is_video, video_url);
+
+ if (p.has("thumbnail")) {
+ _request_image(description->get_instance_id(), p["thumbnail"], IMAGE_QUEUE_THUMBNAIL, i);
+ }
+ if (is_video) {
+ //_request_image(description->get_instance_id(),p["link"],IMAGE_QUEUE_SCREENSHOT,i);
+ } else {
+ _request_image(description->get_instance_id(), p["link"], IMAGE_QUEUE_SCREENSHOT, i);
+ }
+ }
+ }
+ } break;
+ default: break;
+ }
+}
+
+void EditorAssetLibrary::_asset_file_selected(const String &p_file) {
+
+ if (asset_installer) {
+ memdelete(asset_installer);
+ asset_installer = NULL;
+ }
+
+ asset_installer = memnew(EditorAssetInstaller);
+ add_child(asset_installer);
+ asset_installer->open(p_file);
+}
+
+void EditorAssetLibrary::_asset_open() {
+
+ asset_open->popup_centered_ratio();
+}
+
+void EditorAssetLibrary::_manage_plugins() {
+
+ ProjectSettingsEditor::get_singleton()->popup_project_settings();
+ ProjectSettingsEditor::get_singleton()->set_plugins_page();
+}
+
+void EditorAssetLibrary::_install_external_asset(String p_zip_path, String p_title) {
+
+ emit_signal("install_asset", p_zip_path, p_title);
+}
+
+void EditorAssetLibrary::_bind_methods() {
+
+ ClassDB::bind_method("_http_request_completed", &EditorAssetLibrary::_http_request_completed);
+ ClassDB::bind_method("_select_asset", &EditorAssetLibrary::_select_asset);
+ ClassDB::bind_method("_select_author", &EditorAssetLibrary::_select_author);
+ ClassDB::bind_method("_select_category", &EditorAssetLibrary::_select_category);
+ ClassDB::bind_method("_image_request_completed", &EditorAssetLibrary::_image_request_completed);
+ ClassDB::bind_method("_search", &EditorAssetLibrary::_search, DEFVAL(0));
+ ClassDB::bind_method("_install_asset", &EditorAssetLibrary::_install_asset);
+ ClassDB::bind_method("_manage_plugins", &EditorAssetLibrary::_manage_plugins);
+ ClassDB::bind_method("_asset_open", &EditorAssetLibrary::_asset_open);
+ ClassDB::bind_method("_asset_file_selected", &EditorAssetLibrary::_asset_file_selected);
+ ClassDB::bind_method("_repository_changed", &EditorAssetLibrary::_repository_changed);
+ ClassDB::bind_method("_support_toggled", &EditorAssetLibrary::_support_toggled);
+ ClassDB::bind_method("_rerun_search", &EditorAssetLibrary::_rerun_search);
+ ClassDB::bind_method("_install_external_asset", &EditorAssetLibrary::_install_external_asset);
+
+ ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name")));
+}
+
+EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) {
+
+ templates_only = p_templates_only;
+
+ VBoxContainer *library_main = memnew(VBoxContainer);
+
+ add_child(library_main);
+
+ HBoxContainer *search_hb = memnew(HBoxContainer);
+
+ library_main->add_child(search_hb);
+ library_main->add_constant_override("separation", 10);
+
+ search_hb->add_child(memnew(Label(TTR("Search:") + " ")));
+ filter = memnew(LineEdit);
+ search_hb->add_child(filter);
+ filter->set_h_size_flags(SIZE_EXPAND_FILL);
+ filter->connect("text_entered", this, "_search");
+ search = memnew(Button(TTR("Search")));
+ search->connect("pressed", this, "_search");
+ search_hb->add_child(search);
+
+ if (!p_templates_only)
+ search_hb->add_child(memnew(VSeparator));
+
+ Button *open_asset = memnew(Button);
+ open_asset->set_text(TTR("Import"));
+ search_hb->add_child(open_asset);
+ open_asset->connect("pressed", this, "_asset_open");
+
+ Button *plugins = memnew(Button);
+ plugins->set_text(TTR("Plugins"));
+ search_hb->add_child(plugins);
+ plugins->connect("pressed", this, "_manage_plugins");
+
+ if (p_templates_only) {
+ open_asset->hide();
+ plugins->hide();
+ }
+
+ HBoxContainer *search_hb2 = memnew(HBoxContainer);
+ library_main->add_child(search_hb2);
+
+ search_hb2->add_child(memnew(Label(TTR("Sort:") + " ")));
+ sort = memnew(OptionButton);
+ for (int i = 0; i < SORT_MAX; i++) {
+ sort->add_item(sort_text[i]);
+ }
+
+ search_hb2->add_child(sort);
+
+ sort->set_h_size_flags(SIZE_EXPAND_FILL);
+ sort->connect("item_selected", this, "_rerun_search");
+
+ reverse = memnew(ToolButton);
+ reverse->set_toggle_mode(true);
+ reverse->connect("toggled", this, "_rerun_search");
+ //reverse->set_text(TTR("Reverse"));
+ search_hb2->add_child(reverse);
+
+ search_hb2->add_child(memnew(VSeparator));
+
+ //search_hb2->add_spacer();
+
+ search_hb2->add_child(memnew(Label(TTR("Category:") + " ")));
+ categories = memnew(OptionButton);
+ categories->add_item(TTR("All"));
+ search_hb2->add_child(categories);
+ categories->set_h_size_flags(SIZE_EXPAND_FILL);
+ //search_hb2->add_spacer();
+ categories->connect("item_selected", this, "_rerun_search");
+
+ search_hb2->add_child(memnew(VSeparator));
+
+ search_hb2->add_child(memnew(Label(TTR("Site:") + " ")));
+ repository = memnew(OptionButton);
+
+ // FIXME: Reenable me once GH-7147 is fixed.
+ /*
+ repository->add_item("godotengine.org");
+ repository->set_item_metadata(0, "https://godotengine.org/asset-library/api");
+ */
+ repository->add_item("localhost");
+ repository->set_item_metadata(/*1*/ 0, "http://127.0.0.1/asset-library/api");
+ repository->connect("item_selected", this, "_repository_changed");
+
+ search_hb2->add_child(repository);
+ repository->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ search_hb2->add_child(memnew(VSeparator));
+
+ support = memnew(MenuButton);
+ search_hb2->add_child(support);
+ support->set_text(TTR("Support.."));
+ support->get_popup()->add_check_item(TTR("Official"), SUPPORT_OFFICIAL);
+ support->get_popup()->add_check_item(TTR("Community"), SUPPORT_COMMUNITY);
+ support->get_popup()->add_check_item(TTR("Testing"), SUPPORT_TESTING);
+ support->get_popup()->set_item_checked(SUPPORT_OFFICIAL, true);
+ support->get_popup()->set_item_checked(SUPPORT_COMMUNITY, true);
+ support->get_popup()->connect("id_pressed", this, "_support_toggled");
+
+ /////////
+
+ library_scroll_bg = memnew(PanelContainer);
+ library_main->add_child(library_scroll_bg);
+ library_scroll_bg->set_v_size_flags(SIZE_EXPAND_FILL);
+
+ library_scroll = memnew(ScrollContainer);
+ library_scroll->set_enable_v_scroll(true);
+ library_scroll->set_enable_h_scroll(false);
+
+ library_scroll_bg->add_child(library_scroll);
+
+ Ref<StyleBoxEmpty> border2;
+ border2.instance();
+ border2->set_default_margin(MARGIN_LEFT, 15);
+ border2->set_default_margin(MARGIN_RIGHT, 35);
+ border2->set_default_margin(MARGIN_BOTTOM, 15);
+ border2->set_default_margin(MARGIN_TOP, 15);
+
+ PanelContainer *library_vb_border = memnew(PanelContainer);
+ library_scroll->add_child(library_vb_border);
+ library_vb_border->add_style_override("panel", border2);
+ library_vb_border->set_h_size_flags(SIZE_EXPAND_FILL);
+ library_vb_border->set_mouse_filter(MOUSE_FILTER_PASS);
+
+ library_vb = memnew(VBoxContainer);
+ library_vb->set_h_size_flags(SIZE_EXPAND_FILL);
+
+ library_vb_border->add_child(library_vb);
+ //margin_panel->set_stop_mouse(false);
+
+ asset_top_page = memnew(HBoxContainer);
+ library_vb->add_child(asset_top_page);
+
+ asset_items = memnew(GridContainer);
+ asset_items->set_columns(2);
+ asset_items->add_constant_override("hseparation", 10);
+ asset_items->add_constant_override("vseparation", 10);
+
+ library_vb->add_child(asset_items);
+
+ asset_bottom_page = memnew(HBoxContainer);
+ library_vb->add_child(asset_bottom_page);
+
+ request = memnew(HTTPRequest);
+ add_child(request);
+ request->set_use_threads(EDITOR_DEF("asset_library/use_threads", true));
+ request->connect("request_completed", this, "_http_request_completed");
+
+ last_queue_id = 0;
+
+ library_vb->add_constant_override("separation", 20);
+
+ load_status = memnew(ProgressBar);
+ load_status->set_min(0);
+ load_status->set_max(1);
+ load_status->set_step(0.001);
+ library_main->add_child(load_status);
+
+ error_hb = memnew(HBoxContainer);
+ library_main->add_child(error_hb);
+ error_label = memnew(Label);
+ error_label->add_color_override("color", Color(1, 0.4, 0.3));
+ error_hb->add_child(error_label);
+
+ description = NULL;
+
+ set_process(true);
+
+ downloads_scroll = memnew(ScrollContainer);
+ downloads_scroll->set_enable_h_scroll(true);
+ downloads_scroll->set_enable_v_scroll(false);
+ library_main->add_child(downloads_scroll);
+ downloads_hb = memnew(HBoxContainer);
+ downloads_scroll->add_child(downloads_hb);
+
+ asset_open = memnew(EditorFileDialog);
+
+ asset_open->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
+ asset_open->add_filter("*.zip ; " + TTR("Assets ZIP File"));
+ asset_open->set_mode(EditorFileDialog::MODE_OPEN_FILE);
+ add_child(asset_open);
+ asset_open->connect("file_selected", this, "_asset_file_selected");
+
+ asset_installer = NULL;
+}
+
+///////
+
+void AssetLibraryEditorPlugin::make_visible(bool p_visible) {
+
+ if (p_visible) {
+
+ addon_library->show();
+ } else {
+
+ addon_library->hide();
+ }
+}
+
+AssetLibraryEditorPlugin::AssetLibraryEditorPlugin(EditorNode *p_node) {
+
+ editor = p_node;
+ addon_library = memnew(EditorAssetLibrary);
+ addon_library->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ editor->get_viewport()->add_child(addon_library);
+ addon_library->set_area_as_parent_rect();
+ addon_library->hide();
+}
+
+AssetLibraryEditorPlugin::~AssetLibraryEditorPlugin() {
+}
diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h
new file mode 100644
index 0000000000..35977f3949
--- /dev/null
+++ b/editor/plugins/asset_library_editor_plugin.h
@@ -0,0 +1,328 @@
+/*************************************************************************/
+/* asset_library_editor_plugin.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#ifndef ASSET_LIBRARY_EDITOR_PLUGIN_H
+#define ASSET_LIBRARY_EDITOR_PLUGIN_H
+
+#include "editor_plugin.h"
+#include "scene/gui/box_container.h"
+#include "scene/gui/check_box.h"
+#include "scene/gui/line_edit.h"
+#include "scene/gui/link_button.h"
+#include "scene/gui/option_button.h"
+#include "scene/gui/panel_container.h"
+#include "scene/gui/progress_bar.h"
+#include "scene/gui/separator.h"
+#include "scene/gui/tab_container.h"
+
+#include "editor_plugin_settings.h"
+#include "scene/gui/grid_container.h"
+#include "scene/gui/rich_text_label.h"
+#include "scene/gui/scroll_container.h"
+#include "scene/gui/texture_button.h"
+
+#include "editor_asset_installer.h"
+#include "scene/main/http_request.h"
+
+class EditorAssetLibraryItem : public PanelContainer {
+
+ GDCLASS(EditorAssetLibraryItem, PanelContainer);
+
+ TextureButton *icon;
+ LinkButton *title;
+ LinkButton *category;
+ LinkButton *author;
+ TextureRect *stars[5];
+ Label *price;
+
+ int asset_id;
+ int category_id;
+ int author_id;
+
+ void _asset_clicked();
+ void _category_clicked();
+ void _author_clicked();
+
+ void set_image(int p_type, int p_index, const Ref<Texture> &p_image);
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ void configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost);
+
+ EditorAssetLibraryItem();
+};
+
+class EditorAssetLibraryItemDescription : public ConfirmationDialog {
+
+ GDCLASS(EditorAssetLibraryItemDescription, ConfirmationDialog);
+
+ EditorAssetLibraryItem *item;
+ RichTextLabel *description;
+ ScrollContainer *previews;
+ HBoxContainer *preview_hb;
+ PanelContainer *previews_bg;
+ PanelContainer *desc_bg;
+
+ struct Preview {
+ int id;
+ bool is_video;
+ String video_link;
+ Button *button;
+ Ref<Texture> image;
+ };
+
+ Vector<Preview> preview_images;
+ TextureRect *preview;
+
+ void set_image(int p_type, int p_index, const Ref<Texture> &p_image);
+
+ int asset_id;
+ String download_url;
+ String title;
+ String sha256;
+ Ref<Texture> icon;
+
+ void _link_click(const String &p_url);
+ void _preview_click(int p_id);
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ void configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost, int p_version, const String &p_version_string, const String &p_description, const String &p_download_url, const String &p_browse_url, const String &p_sha256_hash);
+ void add_preview(int p_id, bool p_video, const String &p_url);
+
+ String get_title() { return title; }
+ Ref<Texture> get_preview_icon() { return icon; }
+ String get_download_url() { return download_url; }
+ int get_asset_id() { return asset_id; }
+ String get_sha256() { return sha256; }
+ EditorAssetLibraryItemDescription();
+};
+
+class EditorAssetLibraryItemDownload : public PanelContainer {
+
+ GDCLASS(EditorAssetLibraryItemDownload, PanelContainer);
+
+ TextureRect *icon;
+ Label *title;
+ ProgressBar *progress;
+ Button *install;
+ Button *retry;
+ TextureButton *dismiss;
+
+ AcceptDialog *download_error;
+ HTTPRequest *download;
+ String host;
+ String sha256;
+ Label *status;
+
+ int prev_status;
+
+ int asset_id;
+
+ bool external_install;
+
+ EditorAssetInstaller *asset_installer;
+
+ void _close();
+ void _install();
+ void _make_request();
+ void _http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);
+
+protected:
+ void _notification(int p_what);
+ static void _bind_methods();
+
+public:
+ void set_external_install(bool p_enable) { external_install = p_enable; }
+ int get_asset_id() { return asset_id; }
+ void configure(const String &p_title, int p_asset_id, const Ref<Texture> &p_preview, const String &p_download_url, const String &p_sha256_hash);
+ EditorAssetLibraryItemDownload();
+};
+
+class EditorAssetLibrary : public PanelContainer {
+ GDCLASS(EditorAssetLibrary, PanelContainer);
+
+ String host;
+
+ EditorFileDialog *asset_open;
+ EditorAssetInstaller *asset_installer;
+
+ void _asset_open();
+ void _asset_file_selected(const String &p_file);
+
+ PanelContainer *library_scroll_bg;
+ ScrollContainer *library_scroll;
+ VBoxContainer *library_vb;
+ LineEdit *filter;
+ OptionButton *categories;
+ OptionButton *repository;
+ OptionButton *sort;
+ ToolButton *reverse;
+ Button *search;
+ ProgressBar *load_status;
+ HBoxContainer *error_hb;
+ Label *error_label;
+ MenuButton *support;
+
+ HBoxContainer *contents;
+
+ HBoxContainer *asset_top_page;
+ GridContainer *asset_items;
+ HBoxContainer *asset_bottom_page;
+
+ HTTPRequest *request;
+
+ bool templates_only;
+
+ enum Support {
+ SUPPORT_OFFICIAL,
+ SUPPORT_COMMUNITY,
+ SUPPORT_TESTING,
+ SUPPORT_MAX
+ };
+
+ enum SortOrder {
+ SORT_RATING,
+ SORT_DOWNLOADS,
+ SORT_NAME,
+ SORT_COST,
+ SORT_UPDATED,
+ SORT_MAX
+ };
+
+ static const char *sort_key[SORT_MAX];
+ static const char *sort_text[SORT_MAX];
+ static const char *support_key[SUPPORT_MAX];
+
+ ///MainListing
+
+ enum ImageType {
+ IMAGE_QUEUE_ICON,
+ IMAGE_QUEUE_THUMBNAIL,
+ IMAGE_QUEUE_SCREENSHOT,
+
+ };
+
+ struct ImageQueue {
+
+ bool active;
+ int queue_id;
+ int asset_id;
+ ImageType image_type;
+ int image_index;
+ String image_url;
+ HTTPRequest *request;
+ ObjectID target;
+ };
+
+ int last_queue_id;
+ Map<int, ImageQueue> image_queue;
+
+ void _image_update(bool use_cache, bool final, const PoolByteArray &p_data, int p_queue_id);
+ void _image_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data, int p_queue_id);
+ void _request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index);
+ void _update_image_queue();
+
+ HBoxContainer *_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items);
+
+ //
+ EditorAssetLibraryItemDescription *description;
+ //
+
+ enum RequestType {
+ REQUESTING_NONE,
+ REQUESTING_CONFIG,
+ REQUESTING_SEARCH,
+ REQUESTING_ASSET,
+ };
+
+ RequestType requesting;
+ Dictionary category_map;
+
+ ScrollContainer *downloads_scroll;
+ HBoxContainer *downloads_hb;
+
+ void _install_asset();
+
+ void _select_author(int p_id);
+ void _select_category(int p_id);
+ void _select_asset(int p_id);
+
+ void _manage_plugins();
+
+ void _search(int p_page = 0);
+ void _rerun_search(int p_ignore);
+ void _api_request(const String &p_request, RequestType p_request_type, const String &p_arguments = "");
+ void _http_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);
+ void _http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);
+
+ void _repository_changed(int p_repository_id);
+ void _support_toggled(int p_support);
+
+ void _install_external_asset(String p_zip_path, String p_title);
+
+ friend class EditorAssetLibraryItemDescription;
+ friend class EditorAssetLibraryItem;
+
+protected:
+ static void _bind_methods();
+ void _notification(int p_what);
+
+public:
+ EditorAssetLibrary(bool p_templates_only = false);
+};
+
+class AssetLibraryEditorPlugin : public EditorPlugin {
+
+ GDCLASS(AssetLibraryEditorPlugin, EditorPlugin);
+
+ EditorAssetLibrary *addon_library;
+ EditorNode *editor;
+
+public:
+ virtual String get_name() const { return "AssetLib"; }
+ bool has_main_screen() const { return true; }
+ virtual void edit(Object *p_object) {}
+ virtual bool handles(Object *p_object) const { return false; }
+ virtual void make_visible(bool p_visible);
+ //virtual bool get_remove_list(List<Node*> *p_list) { return canvas_item_editor->get_remove_list(p_list); }
+ //virtual Dictionary get_state() const;
+ //virtual void set_state(const Dictionary& p_state);
+
+ AssetLibraryEditorPlugin(EditorNode *p_node);
+ ~AssetLibraryEditorPlugin();
+};
+
+#endif // EDITORASSETLIBRARY_H
diff --git a/editor/plugins/baked_light_baker.cpp b/editor/plugins/baked_light_baker.cpp
deleted file mode 100644
index bef35647d4..0000000000
--- a/editor/plugins/baked_light_baker.cpp
+++ /dev/null
@@ -1,2732 +0,0 @@
-/*************************************************************************/
-/* baked_light_baker.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "baked_light_baker.h"
-
-#include "editor/editor_node.h"
-#include "editor/editor_settings.h"
-#include "io/marshalls.h"
-#include <stdlib.h>
-#include <cmath>
-
-#if 0
-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));
-
- if (lat==0) {
- return 60;
- } else if (lat==6) {
- return 61;
- }
-
- int lon = Math::fast_ftoi(Math::floor( (Math_PI+Math::atan2(p_vector.x,p_vector.z))*12.0/(Math_PI*2.0) + 0.5))%12;
-
- return lon+(lat-1)*12;
-}
-
-
-
-_FORCE_INLINE_ static Vector3 get_bit_normal(int p_bit) {
-
- if (p_bit==61) {
- return Vector3(0,1,0);
- } else if (p_bit==62){
- return Vector3(0,-1,0);
- }
-
- float latang = ((p_bit / 12)+1)*Math_PI/6.0;
-
- Vector2 latv(Math::sin(latang),Math::cos(latang));
-
- float lonang = ((p_bit%12)*Math_PI*2.0/12.0)-Math_PI;
-
- Vector2 lonv(Math::sin(lonang),Math::cos(lonang));
-
- return Vector3(lonv.x*latv.x,latv.y,lonv.y*latv.x).normalized();
-
-}
-
-
-BakedLightBaker::MeshTexture* BakedLightBaker::_get_mat_tex(const Ref<Texture>& p_tex) {
-
- if (!tex_map.has(p_tex)) {
-
- Ref<ImageTexture> imgtex=p_tex;
- if (imgtex.is_null())
- return NULL;
- Image image=imgtex->get_data();
- if (image.empty())
- return NULL;
-
- if (image.get_format()!=Image::FORMAT_RGBA8) {
- if (image.get_format()>Image::FORMAT_INDEXED_ALPHA) {
- Error err = image.decompress();
- if (err)
- return NULL;
- }
-
- if (image.get_format()!=Image::FORMAT_RGBA8)
- image.convert(Image::FORMAT_RGBA8);
- }
-
- if (imgtex->get_flags()&Texture::FLAG_CONVERT_TO_LINEAR) {
- Image copy = image;
- copy.srgb_to_linear();
- image=copy;
- }
-
- PoolVector<uint8_t> dvt=image.get_data();
- PoolVector<uint8_t>::Read r=dvt.read();
- MeshTexture mt;
- mt.tex_w=image.get_width();
- mt.tex_h=image.get_height();
- int len = image.get_width()*image.get_height()*4;
- mt.tex.resize(len);
- copymem(mt.tex.ptr(),r.ptr(),len);
-
- textures.push_back(mt);
- tex_map[p_tex]=&textures.back()->get();
- }
-
- return tex_map[p_tex];
-}
-
-
-void BakedLightBaker::_add_mesh(const Ref<Mesh>& p_mesh,const Ref<Material>& p_mat_override,const Transform& p_xform,int p_baked_texture) {
-
-
- for(int i=0;i<p_mesh->get_surface_count();i++) {
-
- if (p_mesh->surface_get_primitive_type(i)!=Mesh::PRIMITIVE_TRIANGLES)
- continue;
- Ref<Material> mat = p_mat_override.is_valid()?p_mat_override:p_mesh->surface_get_material(i);
-
- MeshMaterial *matptr=NULL;
- int baked_tex=p_baked_texture;
-
- if (mat.is_valid()) {
-
- if (!mat_map.has(mat)) {
-
- MeshMaterial mm;
-
- Ref<SpatialMaterial> fm = mat;
- if (fm.is_valid()) {
- //fixed route
- mm.diffuse.color=fm->get_parameter(SpatialMaterial::PARAM_DIFFUSE);
- if (linear_color)
- mm.diffuse.color=mm.diffuse.color.to_linear();
- mm.diffuse.tex=_get_mat_tex(fm->get_texture(SpatialMaterial::PARAM_DIFFUSE));
- mm.specular.color=fm->get_parameter(SpatialMaterial::PARAM_SPECULAR);
- if (linear_color)
- mm.specular.color=mm.specular.color.to_linear();
-
- mm.specular.tex=_get_mat_tex(fm->get_texture(SpatialMaterial::PARAM_SPECULAR));
- } else {
-
- mm.diffuse.color=Color(1,1,1,1);
- mm.diffuse.tex=NULL;
- mm.specular.color=Color(0,0,0,1);
- mm.specular.tex=NULL;
- }
-
- materials.push_back(mm);
- mat_map[mat]=&materials.back()->get();
-
- }
-
- matptr=mat_map[mat];
-
- }
-
-
- int facecount=0;
-
-
- if (p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_INDEX) {
-
- facecount=p_mesh->surface_get_array_index_len(i);
- } else {
-
- facecount=p_mesh->surface_get_array_len(i);
- }
-
- ERR_CONTINUE((facecount==0 || (facecount%3)!=0));
-
- facecount/=3;
-
- int tbase=triangles.size();
- triangles.resize(facecount+tbase);
-
-
- Array a = p_mesh->surface_get_arrays(i);
-
- PoolVector<Vector3> vertices = a[Mesh::ARRAY_VERTEX];
- PoolVector<Vector3>::Read vr=vertices.read();
- PoolVector<Vector2> uv;
- PoolVector<Vector2>::Read uvr;
- PoolVector<Vector2> uv2;
- PoolVector<Vector2>::Read uv2r;
- PoolVector<Vector3> normal;
- PoolVector<Vector3>::Read normalr;
- bool read_uv=false;
- bool read_normal=false;
-
- if (p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_TEX_UV) {
-
- uv=a[Mesh::ARRAY_TEX_UV];
- uvr=uv.read();
- read_uv=true;
-
- if (mat.is_valid() && mat->get_flag(Material::FLAG_LIGHTMAP_ON_UV2) && p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_TEX_UV2) {
-
- uv2=a[Mesh::ARRAY_TEX_UV2];
- uv2r=uv2.read();
-
- } else {
- uv2r=uv.read();
- if (baked_light->get_transfer_lightmaps_only_to_uv2()) {
- baked_tex=-1;
- }
- }
- }
-
- if (p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_NORMAL) {
-
- normal=a[Mesh::ARRAY_NORMAL];
- normalr=normal.read();
- read_normal=true;
- }
-
- Matrix3 normal_xform = p_xform.basis.inverse().transposed();
-
-
- if (p_mesh->surface_get_format(i)&Mesh::ARRAY_FORMAT_INDEX) {
-
- PoolVector<int> indices = a[Mesh::ARRAY_INDEX];
- PoolVector<int>::Read ir = indices.read();
-
- for(int i=0;i<facecount;i++) {
- Triangle &t=triangles[tbase+i];
- t.vertices[0]=p_xform.xform(vr[ ir[i*3+0] ]);
- t.vertices[1]=p_xform.xform(vr[ ir[i*3+1] ]);
- t.vertices[2]=p_xform.xform(vr[ ir[i*3+2] ]);
- t.material=matptr;
- t.baked_texture=baked_tex;
- if (read_uv) {
-
- t.uvs[0]=uvr[ ir[i*3+0] ];
- t.uvs[1]=uvr[ ir[i*3+1] ];
- t.uvs[2]=uvr[ ir[i*3+2] ];
-
- t.bake_uvs[0]=uv2r[ ir[i*3+0] ];
- t.bake_uvs[1]=uv2r[ ir[i*3+1] ];
- t.bake_uvs[2]=uv2r[ ir[i*3+2] ];
- }
- if (read_normal) {
-
- t.normals[0]=normal_xform.xform(normalr[ ir[i*3+0] ]).normalized();
- t.normals[1]=normal_xform.xform(normalr[ ir[i*3+1] ]).normalized();
- t.normals[2]=normal_xform.xform(normalr[ ir[i*3+2] ]).normalized();
- }
- }
-
- } else {
-
- for(int i=0;i<facecount;i++) {
- Triangle &t=triangles[tbase+i];
- t.vertices[0]=p_xform.xform(vr[ i*3+0 ]);
- t.vertices[1]=p_xform.xform(vr[ i*3+1 ]);
- t.vertices[2]=p_xform.xform(vr[ i*3+2 ]);
- t.material=matptr;
- t.baked_texture=baked_tex;
- if (read_uv) {
-
- t.uvs[0]=uvr[ i*3+0 ];
- t.uvs[1]=uvr[ i*3+1 ];
- t.uvs[2]=uvr[ i*3+2 ];
-
- t.bake_uvs[0]=uv2r[ i*3+0 ];
- t.bake_uvs[1]=uv2r[ i*3+1 ];
- t.bake_uvs[2]=uv2r[ i*3+2 ];
-
- }
- if (read_normal) {
-
- t.normals[0]=normal_xform.xform(normalr[ i*3+0 ]).normalized();
- t.normals[1]=normal_xform.xform(normalr[ i*3+1 ]).normalized();
- t.normals[2]=normal_xform.xform(normalr[ i*3+2 ]).normalized();
- }
- }
- }
- }
-
-}
-
-
-void BakedLightBaker::_parse_geometry(Node* p_node) {
-
- if (p_node->cast_to<MeshInstance>()) {
-
- MeshInstance *meshi=p_node->cast_to<MeshInstance>();
- Ref<Mesh> mesh=meshi->get_mesh();
- if (mesh.is_valid()) {
- _add_mesh(mesh,meshi->get_material_override(),base_inv * meshi->get_global_transform(),meshi->get_baked_light_texture_id());
- }
- } else if (p_node->cast_to<Light>()) {
-
- Light *dl=p_node->cast_to<Light>();
-
- if (dl->get_bake_mode()!=Light::BAKE_MODE_DISABLED) {
-
-
- LightData dirl;
- 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();
- dirl.left=dl->get_global_transform().basis.get_axis(0).normalized();
- dirl.dir=-dl->get_global_transform().basis.get_axis(2).normalized();
- dirl.spot_angle=dl->get_parameter(DirectionalLight::PARAM_SPOT_ANGLE);
- dirl.spot_attenuation=dl->get_parameter(DirectionalLight::PARAM_SPOT_ATTENUATION);
- dirl.attenuation=dl->get_parameter(DirectionalLight::PARAM_ATTENUATION);
- dirl.darkening=dl->get_parameter(DirectionalLight::PARAM_SHADOW_DARKENING);
- dirl.radius=dl->get_parameter(DirectionalLight::PARAM_RADIUS);
- dirl.bake_direct=dl->get_bake_mode()==Light::BAKE_MODE_FULL;
- dirl.rays_thrown=0;
- dirl.bake_shadow=dl->get_bake_mode()==Light::BAKE_MODE_INDIRECT_AND_SHADOWS;
- lights.push_back(dirl);
- }
-
- } else if (p_node->cast_to<Spatial>()){
-
- Spatial *sp = p_node->cast_to<Spatial>();
-
- Array arr = p_node->call("_get_baked_light_meshes");
- for(int i=0;i<arr.size();i+=2) {
-
- Transform xform=arr[i];
- Ref<Mesh> mesh=arr[i+1];
- _add_mesh(mesh,Ref<Material>(),base_inv * (sp->get_global_transform() * xform));
- }
- }
-
- for(int i=0;i<p_node->get_child_count();i++) {
-
- _parse_geometry(p_node->get_child(i));
- }
-}
-
-
-void BakedLightBaker::_fix_lights() {
-
-
- total_light_area=0;
- for(int i=0;i<lights.size();i++) {
-
- LightData &dl=lights[i];
-
- switch(dl.type) {
- case VS::LIGHT_DIRECTIONAL: {
-
- float up_max=-1e10;
- float dir_max=-1e10;
- float left_max=-1e10;
- float up_min=1e10;
- float dir_min=1e10;
- float left_min=1e10;
-
- for(int j=0;j<triangles.size();j++) {
-
- for(int k=0;k<3;k++) {
-
- Vector3 v = triangles[j].vertices[k];
-
- float up_d = dl.up.dot(v);
- float dir_d = dl.dir.dot(v);
- float left_d = dl.left.dot(v);
-
- if (up_d>up_max)
- up_max=up_d;
- if (up_d<up_min)
- up_min=up_d;
-
- if (left_d>left_max)
- left_max=left_d;
- if (left_d<left_min)
- left_min=left_d;
-
- if (dir_d>dir_max)
- dir_max=dir_d;
- if (dir_d<dir_min)
- dir_min=dir_d;
-
- }
- }
-
- //make a center point, then the upvector and leftvector
- dl.pos = dl.left*( left_max+left_min )*0.5 + dl.up*( up_max+up_min )*0.5 + dl.dir*(dir_min-(dir_max-dir_min));
- dl.left*=(left_max-left_min)*0.5;
- dl.up*=(up_max-up_min)*0.5;
- dl.length = (dir_max - dir_min)*10; //arbitrary number to keep it in scale
- dl.area=dl.left.length()*2*dl.up.length()*2;
- dl.constant=1.0/dl.area;
- } break;
- case VS::LIGHT_OMNI:
- case VS::LIGHT_SPOT: {
-
- dl.attenuation_table.resize(ATTENUATION_CURVE_LEN);
- for(int j=0;j<ATTENUATION_CURVE_LEN;j++) {
- dl.attenuation_table[j]=1.0-Math::pow(j/float(ATTENUATION_CURVE_LEN),dl.attenuation);
- float falloff=j*dl.radius/float(ATTENUATION_CURVE_LEN);
- if (falloff==0)
- falloff=0.000001;
- float intensity=4*Math_PI*(falloff*falloff);
- //dl.attenuation_table[j]*=falloff*falloff;
- dl.attenuation_table[j]*=1.0/(3.0/intensity);
-
- }
- if (dl.type==VS::LIGHT_OMNI) {
-
- dl.area=4.0*Math_PI*pow(dl.radius,2.0f);
- dl.constant=1.0/3.5;
- } else {
-
-
- float r = Math::tan(Math::deg2rad(dl.spot_angle))*dl.radius;
- float c = 1.0-(Math::deg2rad(dl.spot_angle)*0.5+0.5);
- dl.constant=1.0/3.5;
- dl.constant*=1.0/c;
-
- dl.area=Math_PI*r*r*c;
- }
-
- } break;
-
-
- }
-
- total_light_area+=dl.area;
- }
-}
-
-BakedLightBaker::BVH* BakedLightBaker::_parse_bvh(BVH** p_children, int p_size, int p_depth, int &max_depth) {
-
- if (p_depth>max_depth) {
- max_depth=p_depth;
- }
-
- if (p_size==1) {
-
- return p_children[0];
- } else if (p_size==0) {
-
- return NULL;
- }
-
-
- AABB aabb;
- aabb=p_children[0]->aabb;
- for(int i=1;i<p_size;i++) {
-
- aabb.merge_with(p_children[i]->aabb);
- }
-
- int li=aabb.get_longest_axis_index();
-
- switch(li) {
-
- case Vector3::AXIS_X: {
- SortArray<BVH*,BVHCmpX> sort_x;
- sort_x.nth_element(0,p_size,p_size/2,p_children);
- //sort_x.sort(&p_bb[p_from],p_size);
- } break;
- case Vector3::AXIS_Y: {
- SortArray<BVH*,BVHCmpY> sort_y;
- sort_y.nth_element(0,p_size,p_size/2,p_children);
- //sort_y.sort(&p_bb[p_from],p_size);
- } break;
- case Vector3::AXIS_Z: {
- SortArray<BVH*,BVHCmpZ> sort_z;
- sort_z.nth_element(0,p_size,p_size/2,p_children);
- //sort_z.sort(&p_bb[p_from],p_size);
-
- } break;
- }
-
-
- BVH* left = _parse_bvh(p_children,p_size/2,p_depth+1,max_depth);
- BVH* right = _parse_bvh(&p_children[p_size/2],p_size-p_size/2,p_depth+1,max_depth);
-
- BVH *_new = memnew(BVH);
- _new->aabb=aabb;
- _new->center=aabb.pos+aabb.size*0.5;
- _new->children[0]=left;
- _new->children[1]=right;
- _new->leaf=NULL;
-
- return _new;
-}
-
-void BakedLightBaker::_make_bvh() {
-
- Vector<BVH*> bases;
- bases.resize(triangles.size());
- int max_depth=0;
- for(int i=0;i<triangles.size();i++) {
- bases[i]=memnew( BVH );
- bases[i]->leaf=&triangles[i];
- bases[i]->aabb.pos=triangles[i].vertices[0];
- bases[i]->aabb.expand_to(triangles[i].vertices[1]);
- bases[i]->aabb.expand_to(triangles[i].vertices[2]);
- triangles[i].aabb=bases[i]->aabb;
- bases[i]->center=bases[i]->aabb.pos+bases[i]->aabb.size*0.5;
- }
-
- 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) {
-
-
-
-
- uint32_t *stack=octant_stack;
- uint32_t *ptr_stack=octantptr_stack;
- Octant *octants=octant_pool.ptr();
-
- stack[0]=0;
- ptr_stack[0]=0;
-
- int stack_pos=0;
-
-
- while(true) {
-
- Octant *octant=&octants[ptr_stack[stack_pos]];
- if (stack[stack_pos]<8) {
-
- int i = stack[stack_pos];
- stack[stack_pos]++;
-
-
-
- //fit_aabb=fit_aabb.grow(bvh->aabb.size.x*0.0001);
-
- int child_idx =octant->children[i];
- bool encloses;
- if (!child_idx) {
-
- AABB aabb=octant->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;
-
- aabb.grow_by(cell_size*octree_extra_margin);
- if (!aabb.intersects(p_triangle->aabb))
- continue;
- encloses=aabb.grow(cell_size*-octree_extra_margin*2.0).encloses(p_triangle->aabb);
- if (!encloses && !Face3(p_triangle->vertices[0],p_triangle->vertices[1],p_triangle->vertices[2]).intersects_aabb2(aabb))
- continue;
- } else {
-
- Octant *child=&octants[child_idx];
- AABB aabb=child->aabb;
- aabb.grow_by(cell_size*octree_extra_margin);
- if (!aabb.intersects(p_triangle->aabb))
- continue;
- encloses=aabb.grow(cell_size*-octree_extra_margin*2.0).encloses(p_triangle->aabb);
- if (!encloses && !Face3(p_triangle->vertices[0],p_triangle->vertices[1],p_triangle->vertices[2]).intersects_aabb2(aabb))
- continue;
-
- }
-
- if (encloses)
- stack[stack_pos]=8; // quick and dirty opt
-
- if (!child_idx) {
-
-
- if (octant_pool_size==octant_pool.size()) {
- octant_pool.resize(octant_pool_size+OCTANT_POOL_CHUNK);
- octants=octant_pool.ptr();
- octant=&octants[ptr_stack[stack_pos]];
- }
- child_idx=octant_pool_size++;
- octant->children[i]=child_idx;
- Octant *child=&octants[child_idx];
-
- child->aabb=octant->aabb;
- child->texture_x=0;
- child->texture_y=0;
-
- child->aabb.size*=0.5;
- if (i&1)
- child->aabb.pos.x+=child->aabb.size.x;
- if (i&2)
- child->aabb.pos.y+=child->aabb.size.y;
- if (i&4)
- 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;
- child->offset[0]=child->aabb.pos.x+child->aabb.size.x*0.5;
- child->offset[1]=child->aabb.pos.y+child->aabb.size.y*0.5;
- child->offset[2]=child->aabb.pos.z+child->aabb.size.z*0.5;
- child->next_leaf=leaf_list;
-
-
- for(int ci=0;ci<8;ci++) {
- child->normal_accum[ci][0]=0;
- child->normal_accum[ci][1]=0;
- child->normal_accum[ci][2]=0;
-
- }
-
- child->bake_neighbour=0;
- child->first_neighbour=true;
- leaf_list=child_idx;
- cell_count++;
-
- 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];
-
- } else {
-
- child->leaf=false;
- for(int j=0;j<8;j++) {
- child->children[j]=0;
- }
- }
- }
-
- if (!octants[child_idx].leaf) {
- stack_pos++;
- stack[stack_pos]=0;
- ptr_stack[stack_pos]=child_idx;
- } else {
-
- Octant *child=&octants[child_idx];
-
- Vector3 n = Plane(p_triangle->vertices[0],p_triangle->vertices[1],p_triangle->vertices[2]).normal;
-
-
- for(int ci=0;ci<8;ci++) {
-
- Vector3 pos = child->aabb.pos;
-
- if (ci&1)
- pos.x+=child->aabb.size.x;
- if (ci&2)
- pos.y+=child->aabb.size.y;
- if (ci&4)
- pos.z+=child->aabb.size.z;
-
-
- pos.x=floor((pos.x+cell_size*0.5)/cell_size);
- pos.y=floor((pos.y+cell_size*0.5)/cell_size);
- pos.z=floor((pos.z+cell_size*0.5)/cell_size);
-
- {
- Map<Vector3,Vector3>::Element *E=endpoint_normal.find(pos);
- if (!E) {
- endpoint_normal[pos]=n;
- } else {
- E->get()+=n;
- }
- }
-
- {
-
- uint64_t bit = get_uv_normal_bit(n);
-
- Map<Vector3,uint64_t>::Element *E=endpoint_normal_bits.find(pos);
- if (!E) {
- endpoint_normal_bits[pos]=(1<<bit);
- } else {
- E->get()|=(1<<bit);
- }
-
- }
-
- }
-
- }
-
-
- } else {
- stack_pos--;
- if (stack_pos<0)
- break;
- }
- }
-
-
-}
-
-
-void BakedLightBaker::_make_octree() {
-
-
- AABB base = bvh->aabb;
- float lal=base.get_longest_axis_size();
- //must be square because we want square blocks
- base.size.x=lal;
- base.size.y=lal;
- base.size.z=lal;
- base.grow_by(lal*0.001); //for precision
- octree_aabb=base;
-
- cell_size=base.size.x;
- for(int i=0;i<octree_depth;i++)
- cell_size/=2.0;
- octant_stack = memnew_arr(uint32_t,octree_depth*2 );
- octantptr_stack = memnew_arr(uint32_t,octree_depth*2 );
-
- octant_pool.resize(OCTANT_POOL_CHUNK);
- octant_pool_size=1;
- Octant *root=octant_pool.ptr();
- root->leaf=false;
- root->aabb=octree_aabb;
- root->parent=-1;
- for(int i=0;i<8;i++)
- root->children[i]=0;
-
- EditorProgress ep("bake_octree",vformat(TTR("Parsing %d Triangles:"), triangles.size()),triangles.size());
-
- for(int i=0;i<triangles.size();i++) {
-
- _octree_insert(0,&triangles[i],octree_depth-1);
- if ((i%1000)==0) {
-
- ep.step(TTR("Triangle #")+itos(i),i);
- }
- }
-
- {
- uint32_t oct_idx=leaf_list;
- Octant *octants=octant_pool.ptr();
- while(oct_idx) {
-
- BakedLightBaker::Octant *oct = &octants[oct_idx];
- for(int ci=0;ci<8;ci++) {
-
-
- Vector3 pos = oct->aabb.pos;
-
- if (ci&1)
- pos.x+=oct->aabb.size.x;
- if (ci&2)
- pos.y+=oct->aabb.size.y;
- if (ci&4)
- pos.z+=oct->aabb.size.z;
-
-
- pos.x=floor((pos.x+cell_size*0.5)/cell_size);
- pos.y=floor((pos.y+cell_size*0.5)/cell_size);
- pos.z=floor((pos.z+cell_size*0.5)/cell_size);
-
- {
- Map<Vector3,Vector3>::Element *E=endpoint_normal.find(pos);
- if (!E) {
- //?
- print_line("lolwut?");
- } else {
- Vector3 n = E->get().normalized();
- oct->normal_accum[ci][0]=n.x;
- oct->normal_accum[ci][1]=n.y;
- oct->normal_accum[ci][2]=n.z;
-
- }
-
- }
-
- {
-
- Map<Vector3,uint64_t>::Element *E=endpoint_normal_bits.find(pos);
- if (!E) {
- //?
- print_line("lolwut?");
- } else {
-
- float max_aper=0;
- for(uint64_t i=0;i<62;i++) {
-
- if (!(E->get()&(1<<i)))
- continue;
- Vector3 ang_i = get_bit_normal(i);
-
- for(uint64_t j=0;j<62;j++) {
-
- if (i==j)
- continue;
- if (!(E->get()&(1<<j)))
- continue;
- Vector3 ang_j = get_bit_normal(j);
- float ang = Math::acos(ang_i.dot(ang_j));
- if (ang>max_aper)
- max_aper=ang;
- }
- }
- if (max_aper>0.75*Math_PI) {
- //angle too wide prevent problems and forget
- oct->normal_accum[ci][0]=0;
- oct->normal_accum[ci][1]=0;
- oct->normal_accum[ci][2]=0;
- }
- }
- }
-
-
- }
-
- oct_idx=oct->next_leaf;
- }
- }
-
-
-}
-
-
-
-
-
-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=thread_stack.octant_stack;
- uint32_t *ptr_stack=thread_stack.octantptr_stack;
- Octant *octants=octant_pool.ptr();
-
- stack[0]=0;
- ptr_stack[0]=0;
-
- int stack_pos=0;
-
-
- while(true) {
-
- 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) {
-
-
-
- //if (p_plane.normal.dot(octant.aabb.get_support(p_plane.normal)) < p_plane.d-CMP_EPSILON) { //octants behind are no go
-
-
- 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);
-
- 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 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);
-
- 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);
-
-
- }
- }
- }
-
- stack_pos--;
- } else if (stack[stack_pos]<8) {
-
- int i = stack[stack_pos];
- stack[stack_pos]++;
-
- if (!octant.children[i]) {
- continue;
- }
-
- Octant &child=octants[octant.children[i]];
-
- if (!child.aabb.intersects(p_plot_aabb))
- continue;
-
- if (child.aabb.encloses(p_plot_aabb)) {
- stack[stack_pos]=8; //don't test the rest
- }
-
- stack_pos++;
- stack[stack_pos]=0;
- ptr_stack[stack_pos]=octant.children[i];
- } else {
- stack_pos--;
- if (stack_pos<0)
- break;
- }
- }
-
-
-}
-
-
-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 = thread_stack.ray_stack;
- BVH **bstack = thread_stack.bvh_stack;
-
- enum {
- TEST_AABB_BIT=0,
- VISIT_LEFT_BIT=1,
- VISIT_RIGHT_BIT=2,
- VISIT_DONE_BIT=3,
-
-
- };
-
- Vector3 n = (p_end-p_begin);
- float len=n.length();
- if (len==0)
- return 0;
- n/=len;
-
-
-
- real_t d=1e10;
- bool inters=false;
- Vector3 r_normal;
- Vector3 r_point;
- Vector3 end=p_end;
-
- Triangle *triangle=NULL;
-
- /*
- for(int i=0;i<max_depth;i++)
- stack[i]=0;
- */
-
- int level=0;
- //AABB ray_aabb;
- //ray_aabb.pos=p_begin;
- //ray_aabb.expand_to(p_end);
-
-
- bstack[0]=bvh;
- stack[0]=TEST_AABB_BIT;
-
-
- while(true) {
-
- uint32_t mode = stack[level];
- const BVH &b = *bstack[level];
- bool done=false;
-
- switch(mode) {
- case TEST_AABB_BIT: {
-
- if (b.leaf) {
-
-
- Face3 f3(b.leaf->vertices[0],b.leaf->vertices[1],b.leaf->vertices[2]);
-
-
- Vector3 res;
-
- if (f3.intersects_segment(p_begin,end,&res)) {
-
-
- float nd = n.dot(res);
- if (nd<d) {
-
- d=nd;
- r_point=res;
- end=res;
- len=(p_begin-end).length();
- r_normal=f3.get_plane().get_normal();
- triangle=b.leaf;
- inters=true;
- }
-
- }
-
- stack[level]=VISIT_DONE_BIT;
- } else {
-
-
- bool valid = b.aabb.smits_intersect_ray(p_begin,n,0,len);
- //bool valid = b.aabb.intersects_segment(p_begin,p_end);
- //bool valid = b.aabb.intersects(ray_aabb);
-
- if (!valid) {
-
- stack[level]=VISIT_DONE_BIT;
-
- } else {
-
- stack[level]=VISIT_LEFT_BIT;
- }
- }
-
- } continue;
- case VISIT_LEFT_BIT: {
-
- stack[level]=VISIT_RIGHT_BIT;
- bstack[level+1]=b.children[0];
- stack[level+1]=TEST_AABB_BIT;
- level++;
-
- } continue;
- case VISIT_RIGHT_BIT: {
-
- stack[level]=VISIT_DONE_BIT;
- bstack[level+1]=b.children[1];
- stack[level+1]=TEST_AABB_BIT;
- level++;
- } continue;
- case VISIT_DONE_BIT: {
-
- if (level==0) {
- done=true;
- break;
- } else
- level--;
-
- } continue;
- }
-
-
- if (done)
- break;
- }
-
-
-
- if (inters) {
-
- if (p_only_dist) {
-
- return p_begin.distance_to(r_point);
- }
-
-
- //should check if there is normals first
- Vector2 uv;
- if (true) {
-
- triangle->get_uv_and_normal(r_point,uv,r_normal);
-
- } else {
-
- }
-
- if (n.dot(r_normal)>0)
- return -1;
-
- if (n.dot(r_normal)>0)
- r_normal=-r_normal;
-
-
- //ok...
- Color diffuse_at_point(0.8,0.8,0.8);
- Color specular_at_point(0.0,0.0,0.0);
-
-
- float dist = p_begin.distance_to(r_point);
-
- AABB aabb;
- aabb.pos=r_point;
- aabb.pos-=Vector3(1,1,1)*cell_size*plot_size;
- aabb.size=Vector3(2,2,2)*cell_size*plot_size;
-
- Color res_light=p_light;
- float att=1.0;
- float dp=(1.0-normal_damp)*n.dot(-r_normal)+normal_damp;
-
- if (p_att_curve) {
-
- p_att_pos+=dist;
- int cpos = Math::fast_ftoi((p_att_pos/p_att_curve_len)*ATTENUATION_CURVE_LEN);
- cpos=CLAMP(cpos,0,ATTENUATION_CURVE_LEN-1);
- att=p_att_curve[cpos];
- }
-
-
- res_light.r*=dp;
- res_light.g*=dp;
- res_light.b*=dp;
-
- //light is plotted before multiplication with diffuse, this way
- //the multiplication can happen with more detail in the shader
-
-
-
- if (triangle->material) {
-
- //triangle->get_uv(r_point);
-
- diffuse_at_point=triangle->material->diffuse.get_color(uv);
- specular_at_point=triangle->material->specular.get_color(uv);
- }
-
-
- diffuse_at_point.r=res_light.r*diffuse_at_point.r;
- diffuse_at_point.g=res_light.g*diffuse_at_point.g;
- diffuse_at_point.b=res_light.b*diffuse_at_point.b;
-
- if (p_bounces>0) {
-
-
- p_rest-=dist;
- if (p_rest<CMP_EPSILON)
- return 0;
-
- if (r_normal==-n)
- return 0; //todo change a little
-
- r_point+=r_normal*0.01;
-
-
-
-
- specular_at_point.r=res_light.r*specular_at_point.r;
- specular_at_point.g=res_light.g*specular_at_point.g;
- specular_at_point.b=res_light.b*specular_at_point.b;
-
-
-
- if (use_diffuse && (diffuse_at_point.r>CMP_EPSILON || diffuse_at_point.g>CMP_EPSILON || diffuse_at_point.b>CMP_EPSILON)) {
- //diffuse bounce
-
- Vector3 c1=r_normal.cross(n).normalized();
- Vector3 c2=r_normal.cross(c1).normalized();
- double r1 = double(rand())/RAND_MAX;
- double r2 = double(rand())/RAND_MAX;
- double r3 = double(rand())/RAND_MAX;
-#if 0
- Vector3 next = - ((c1*(r1-0.5)) + (c2*(r2-0.5)) + (r_normal*(r3-0.5))).normalized()*0.5 + r_normal*0.5;
-
- if (next==Vector3())
- next=r_normal;
- Vector3 rn=next.normalized();
-
-#else
- Vector3 rn = ((c1*(r1-0.5)) + (c2*(r2-0.5)) + (r_normal*r3*0.5)).normalized();
-#endif
-
-
- _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)) {
- //specular bounce
-
- //Vector3 c1=r_normal.cross(n).normalized();
- //Vector3 c2=r_normal.cross(c1).normalized();
-
- Vector3 rn = n - r_normal *r_normal.dot(n) * 2.0;
-
- _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);
- }
- }
-
- //specular later
- //_plot_light_point(r_point,octree,octree_aabb,p_light);
-
-
- 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 || 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);
- skip=true;
-
- } else {
-
-
- Vector3 c1=r_normal.cross(n).normalized();
- Vector3 c2=r_normal.cross(c1).normalized();
- double r1 = double(rand())/RAND_MAX;
- 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(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);
- skip=true;
-
- } else {
- //plot_light=Color(0,0,0,0);
- }
- }
- }
-
-
- 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;
- }
-
- return -1;
-
-}
-
-
-
-
-void BakedLightBaker::_make_octree_texture() {
-
-
- BakedLightBaker::Octant *octants=octant_pool.ptr();
-
- //find neighbours first, to have a better idea of what amount of space is needed
- {
-
- Vector<OctantHash> octant_hashing;
- octant_hashing.resize(octant_pool_size);
- Vector<uint32_t> hash_table;
- int hash_table_size=Math::larger_prime(16384);
- hash_table.resize(hash_table_size);
- uint32_t*hashptr = hash_table.ptr();
- OctantHash*octhashptr = octant_hashing.ptr();
-
- for(int i=0;i<hash_table_size;i++)
- hashptr[i]=0;
-
-
- //step 1 add to hash table
-
- uint32_t oct_idx=leaf_list;
-
-
- while(oct_idx) {
-
- BakedLightBaker::Octant *oct = &octants[oct_idx];
- uint64_t base=0;
- Vector3 pos = oct->aabb.pos - octree_aabb.pos; //make sure is always positive
- base=int((pos.x+cell_size*0.5)/cell_size);
- base<<=16;
- base|=int((pos.y+cell_size*0.5)/cell_size);
- base<<=16;
- base|=int((pos.z+cell_size*0.5)/cell_size);
-
- uint32_t hash = HashMapHasherDefault::hash(base);
- uint32_t idx = hash % hash_table_size;
- octhashptr[oct_idx].next=hashptr[idx];
- octhashptr[oct_idx].hash=hash;
- octhashptr[oct_idx].value=base;
- hashptr[idx]=oct_idx;
-
- oct_idx=oct->next_leaf;
-
- }
-
- //step 2 find neighbours
- oct_idx=leaf_list;
- int neighbours=0;
-
-
- while(oct_idx) {
-
- BakedLightBaker::Octant *oct = &octants[oct_idx];
- Vector3 pos = oct->aabb.pos - octree_aabb.pos; //make sure is always positive
- pos.x+=cell_size;
- uint64_t base=0;
- base=int((pos.x+cell_size*0.5)/cell_size);
- base<<=16;
- base|=int((pos.y+cell_size*0.5)/cell_size);
- base<<=16;
- base|=int((pos.z+cell_size*0.5)/cell_size);
-
- uint32_t hash = HashMapHasherDefault::hash(base);
- uint32_t idx = hash % hash_table_size;
-
- uint32_t bucket = hashptr[idx];
-
- while(bucket) {
-
- if (octhashptr[bucket].value==base) {
-
- oct->bake_neighbour=bucket;
- octants[bucket].first_neighbour=false;
- neighbours++;
- break;
- }
-
- bucket = octhashptr[bucket].next;
- }
-
- oct_idx=oct->next_leaf;
-
- }
-
- print_line("octant with neighbour: "+itos(neighbours));
-
- }
-
-
- //ok let's try to just create a texture
-
- int otex_w=256;
-
- while (true) {
-
-
-
- uint32_t oct_idx=leaf_list;
-
- int row=0;
-
-
- print_line("begin at row "+itos(row));
- int longest_line_reused=0;
- int col=0;
- int processed=0;
-
- //reset
- while(oct_idx) {
-
- BakedLightBaker::Octant *oct = &octants[oct_idx];
- 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;
- }
-
- row+=4;
-
- if (otex_w < row) {
-
- otex_w*=2;
- } else {
-
- baked_light_texture_w=otex_w;
- baked_light_texture_h=next_power_of_2(row);
- print_line("w: "+itos(otex_w));
- print_line("h: "+itos(row));
- break;
- }
-
-
- }
-
-
- {
-
- 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;
- }
-
-
-
- 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;
- print_line("end at row "+itos(row));
-
- //put octree, no need for recursion, just loop backwards.
- int regular_octants=0;
- for(int i=octant_pool_size-1;i>=0;i--) {
-
- BakedLightBaker::Octant *oct = &octants[i];
- if (oct->leaf) //ignore leaf
- continue;
- if (oct->aabb.size.x>lattice_cell_size.x*1.1) { //bigger than latice, skip
- oct->texture_x=0;
- oct->texture_y=0;
- } else if (oct->aabb.size.x>lattice_cell_size.x*0.8) {
- //this is the initial lattice
- Vector3 pos = oct->aabb.pos - octree_aabb.pos; //make sure is always positive
- int x = int((pos.x+lattice_cell_size.x*0.5)/lattice_cell_size.x);
- int y = int((pos.y+lattice_cell_size.y*0.5)/lattice_cell_size.y);
- int z = int((pos.z+lattice_cell_size.z*0.5)/lattice_cell_size.z);
- //bug net
- ERR_FAIL_INDEX(x,(1<<lattice_size));
- ERR_FAIL_INDEX(y,(1<<lattice_size));
- ERR_FAIL_INDEX(z,(1<<lattice_size));
-
- /*int ofs = z*(1<<lattice_size)*(1<<lattice_size)+y*(1<<lattice_size)+x;
- ofs*=4;
- oct->texture_x=ofs%otex_w;
- oct->texture_y=(ofs/otex_w)*4+4;
- */
-
- oct->texture_x=(x+(1<<lattice_size)*z)*2;
- oct->texture_y=4+y*4;
- //print_line("pos: "+itos(x)+","+itos(y)+","+itos(z)+" - ofs"+itos(oct->texture_x)+","+itos(oct->texture_y));
-
-
- } else {
- //an everyday regular octant
-
- if (col+2 > otex_w) {
- col=0;
- row+=4;
- }
-
- oct->texture_x=col;
- oct->texture_y=row;
- col+=2;
- regular_octants++;
-
-
- }
- }
- print_line("octants end at row "+itos(row)+" totalling"+itos(regular_octants));
-
- //ok evaluation.
-
- if (otex_w<=2048 && row>2048) { //too big upwards, try bigger texture
- otex_w*=2;
- continue;
- } else {
- baked_octree_texture_w=otex_w;
- baked_octree_texture_h=row+4;
- break;
- }
-
- }
-
-
- }
-
-
- baked_octree_texture_h=next_power_of_2(baked_octree_texture_h);
- print_line("RESULT! "+itos(baked_octree_texture_w)+","+itos(baked_octree_texture_h));
-
-}
-
-
-
-
-
-
-
-
-double BakedLightBaker::get_normalization(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=dl.rays_thrown * cell_area;
- nrg*=(Math_PI*plot_size*plot_size)*0.5; // damping of radial linear gradient kernel
- nrg*=dl.constant;
- //nrg*=5;
-
-
- return nrg;
-}
-
-
-
-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) {
-
-
-
- for(int i=0;i<lights.size();i++) {
-
- LightData &dl=lights[i];
-
-
- 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) {
-
- case VS::LIGHT_DIRECTIONAL: {
-
-
- for(int j=0;j<amount;j++) {
- Vector3 from = dl.pos;
- double r1 = double(rand())/RAND_MAX;
- double r2 = double(rand())/RAND_MAX;
- from+=dl.up*(r1*2.0-1.0);
- from+=dl.left*(r2*2.0-1.0);
- Vector3 to = from+dl.dir*dl.length;
- Color col=dl.diffuse;
- float m = mod*dl.energy;
- col.r*=m;
- col.g*=m;
- col.b*=m;
-
- dl.rays_thrown++;
- 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: {
-
-
- for(int j=0;j<amount;j++) {
- Vector3 from = dl.pos;
-
- double r1 = double(rand())/RAND_MAX;
- double r2 = double(rand())/RAND_MAX;
- double r3 = double(rand())/RAND_MAX;
-
-#if 0
- //crap is not uniform..
- Vector3 dir = Vector3(r1*2.0-1.0,r2*2.0-1.0,r3*2.0-1.0).normalized();
-
-#else
-
- double phi = r1*Math_PI*2.0;
- double costheta = r2*2.0-1.0;
- double u = r3;
-
- double theta = acos( costheta );
- double r = 1.0 * pow( u,1/3.0 );
-
- Vector3 dir(
- r * sin( theta) * cos( phi ),
- r * sin( theta) * sin( phi ),
- r * cos( theta )
- );
- dir.normalize();
-
-#endif
- Vector3 to = dl.pos+dir*dl.radius;
- Color col=dl.diffuse;
- float m = mod*dl.energy;
- col.r*=m;
- col.g*=m;
- col.b*=m;
-
- dl.rays_thrown++;
- 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);
- }
-
- } break;
- case VS::LIGHT_SPOT: {
-
- for(int j=0;j<amount;j++) {
- Vector3 from = dl.pos;
-
- double r1 = double(rand())/RAND_MAX;
- //double r2 = double(rand())/RAND_MAX;
- double r3 = double(rand())/RAND_MAX;
-
- float d=Math::tan(Math::deg2rad(dl.spot_angle));
-
- float x = sin(r1*Math_PI*2.0)*d;
- float y = cos(r1*Math_PI*2.0)*d;
-
- Vector3 dir = r3*(dl.dir + dl.up*y + dl.left*x) + (1.0-r3)*dl.dir;
- dir.normalize();
-
-
- Vector3 to = dl.pos+dir*dl.radius;
- Color col=dl.diffuse;
- float m = mod*dl.energy;
- col.r*=m;
- col.g*=m;
- col.b*=m;
-
- dl.rays_thrown++;
- 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);
- }
-
- } break;
-
- }
- }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-void BakedLightBaker::bake(const Ref<BakedLight> &p_light, Node* p_node) {
-
- if (baking)
- return;
- cell_count=0;
-
- base_inv=p_node->cast_to<Spatial>()->get_global_transform().affine_inverse();
- EditorProgress ep("bake",TTR("Light Baker Setup:"),5);
- baked_light=p_light;
- lattice_size=baked_light->get_initial_lattice_subdiv();
- octree_depth=baked_light->get_cell_subdivision();
- plot_size=baked_light->get_plot_size();
- max_bounces=baked_light->get_bounces();
- use_diffuse=baked_light->get_bake_flag(BakedLight::BAKE_DIFFUSE);
- use_specular=baked_light->get_bake_flag(BakedLight::BAKE_SPECULAR);
- use_translucency=baked_light->get_bake_flag(BakedLight::BAKE_TRANSLUCENT);
-
- 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++) {
- BakeTexture bt;
- bt.width=baked_light->get_lightmap_gen_size(i).x;
- bt.height=baked_light->get_lightmap_gen_size(i).y;
- baked_textures.push_back(bt);
- }
-
-
- ep.step(TTR("Parsing Geometry"),0);
- _parse_geometry(p_node);
- mat_map.clear();
- tex_map.clear();
- print_line("\ttotal triangles: "+itos(triangles.size()));
- // no geometry
- if (triangles.size() == 0) {
- return;
- }
- ep.step(TTR("Fixing Lights"),1);
- _fix_lights();
- ep.step(TTR("Making BVH"),2);
- _make_bvh();
- ep.step(TTR("Creating Light Octree"),3);
- _make_octree();
- ep.step(TTR("Creating Octree Texture"),4);
- _make_octree_texture();
- baking=true;
- _start_thread();
-
-}
-
-
-void BakedLightBaker::update_octree_sampler(PoolVector<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());
- PoolVector<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();
-
- PoolVector<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(PoolVector<uint8_t> &p_octree,PoolVector<uint8_t> &p_light) {
-
-
- int len = baked_octree_texture_w*baked_octree_texture_h*4;
- p_octree.resize(len);
-
- int ilen = baked_light_texture_w*baked_light_texture_h*4;
- p_light.resize(ilen);
-
-
- PoolVector<uint8_t>::Write w = p_octree.write();
- zeromem(w.ptr(),len);
-
- PoolVector<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();
-
- for(int i=0;i<len;i+=4) {
- w[i+0]=0xFF;
- w[i+1]=0;
- w[i+2]=0xFF;
- 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)
- multiplier=8;
- encode_uint32(baked_octree_texture_w,&w[0]);
- encode_uint32(baked_octree_texture_h,&w[4]);
- encode_uint32(0,&w[8]);
- 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]);
- encode_float(octree_aabb.pos.z,&w[40]);
- encode_float(octree_aabb.size.x,&w[44]);
- encode_float(octree_aabb.size.y,&w[48]);
- encode_float(octree_aabb.size.z,&w[52]);
-
-
- 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]={
- 0,
- 4,
- baked_octree_texture_w*4,
- baked_octree_texture_w*4+4,
- baked_octree_texture_w*8+0,
- baked_octree_texture_w*8+4,
- baked_octree_texture_w*8+baked_octree_texture_w*4,
- baked_octree_texture_w*8+baked_octree_texture_w*4+4,
- };
-
- 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++) {
- norm_arr[i] = 1.0/get_normalization(i);
- }
-
- const double *normptr=norm_arr.ptr();
-*/
- double norm = 1.0/double(total_rays);
- 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;
-
-
- 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=&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,
- b,
- };
- iptr[0]=CLAMP(ic[0]*255.0,0,255);
- iptr[1]=CLAMP(ic[1]*255.0,0,255);
- iptr[2]=CLAMP(ic[2]*255.0,0,255);
- iptr[3]=255;
- }
-
- } 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++) {
-
- if (!oct.children[j])
- continue;
- Octant&choct=octants[oct.children[j]];
- uint8_t *iptr=&ptr[ofs+child_offsets[j]];
-
- iptr[0]=choct.texture_x>>8;
- iptr[1]=choct.texture_x&0xFF;
- iptr[2]=choct.texture_y>>8;
- iptr[3]=choct.texture_y&0xFF;
-
- }
- }
-
- }
-
-
-}
-
-
-void BakedLightBaker::_free_bvh(BVH* p_bvh) {
-
- if (!p_bvh->leaf) {
- if (p_bvh->children[0])
- _free_bvh(p_bvh->children[0]);
- if (p_bvh->children[1])
- _free_bvh(p_bvh->children[1]);
- }
-
- memdelete(p_bvh);
-
-}
-
-
-bool BakedLightBaker::is_baking() {
-
- return baking;
-}
-
-void BakedLightBaker::set_pause(bool p_pause){
-
- if (paused==p_pause)
- return;
-
- paused=p_pause;
-
- if (paused) {
- _stop_thread();
- } else {
- _start_thread();
- }
-}
-bool BakedLightBaker::is_paused() {
-
- return paused;
-
-}
-
-void BakedLightBaker::_bake_thread_func(void *arg) {
-
- BakedLightBaker *ble = (BakedLightBaker*)arg;
-
-
-
- ThreadStack thread_stack;
-
- 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 );
-
- 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 (threads.size()!=0)
- return;
- bake_thread_exit=false;
-
- 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 (threads.size()==0)
- return;
- bake_thread_exit=true;
- for(int i=0;i<threads.size();i++) {
- Thread::wait_to_finish(threads[i]);
- memdelete(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();
- double norm = 1.0/double(total_rays);
-
-
- Color color;
-
- Octant *octants=octant_pool.ptr();
-
-
- int octant_idx=0;
-
-
- while(true) {
-
- Octant &octant=octants[octant_idx];
-
- if (octant.leaf) {
-
- Vector3 lpos = p_pos-octant.aabb.pos;
- lpos/=octant.aabb.size;
-
- Vector3 cols[8];
-
- for(int i=0;i<8;i++) {
-
- 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;
- }
-
-
- /*Vector3 final = (cols[0] + (cols[1] - cols[0]) * lpos.y);
- final = final + ((cols[2] + (cols[3] - cols[2]) * lpos.y) - final)*lpos.x;
-
- Vector3 final2 = (cols[4+0] + (cols[4+1] - cols[4+0]) * lpos.y);
- final2 = final2 + ((cols[4+2] + (cols[4+3] - cols[4+2]) * lpos.y) - final2)*lpos.x;*/
-
- Vector3 finala = cols[0].linear_interpolate(cols[1],lpos.x);
- Vector3 finalb = cols[2].linear_interpolate(cols[3],lpos.x);
- Vector3 final = finala.linear_interpolate(finalb,lpos.y);
-
- Vector3 final2a = cols[4+0].linear_interpolate(cols[4+1],lpos.x);
- Vector3 final2b = cols[4+2].linear_interpolate(cols[4+3],lpos.x);
- Vector3 final2 = final2a.linear_interpolate(final2b,lpos.y);
-
- final = final.linear_interpolate(final2,lpos.z);
- if (baked_light->get_format()==BakedLight::FORMAT_HDR8)
- final*=8.0;
-
-
- color.r=pow(final.x*mult,gamma);
- color.g=pow(final.y*mult,gamma);
- color.b=pow(final.z*mult,gamma);
- color.a=1.0;
-
- int lc = lights.size();
- LightData *lv = lights.ptr();
- for(int i=0;i<lc;i++) {
- //shadow baking
- if (!lv[i].bake_shadow)
- continue;
- Vector3 from = p_pos+p_normal*0.01;
- Vector3 to;
- float att=0;
- switch(lv[i].type) {
- case VS::LIGHT_DIRECTIONAL: {
- to=from-lv[i].dir*lv[i].length;
- } break;
- case VS::LIGHT_OMNI: {
- to=lv[i].pos;
- float d = MIN(lv[i].radius,to.distance_to(from))/lv[i].radius;
- att=d;//1.0-d;
- } break;
- default: continue;
- }
-
- uint32_t* stack = ray_stack;
- BVH **bstack = bvh_stack;
-
- enum {
- TEST_RAY_BIT=0,
- VISIT_LEFT_BIT=1,
- VISIT_RIGHT_BIT=2,
- VISIT_DONE_BIT=3,
-
-
- };
-
- bool intersected=false;
-
- int level=0;
-
- Vector3 n = (to-from);
- float len=n.length();
- if (len==0)
- continue;
- n/=len;
-
- bstack[0]=bvh;
- stack[0]=TEST_RAY_BIT;
-
-
- while(!intersected) {
-
- uint32_t mode = stack[level];
- const BVH &b = *bstack[level];
- bool done=false;
-
- switch(mode) {
- case TEST_RAY_BIT: {
-
- if (b.leaf) {
-
-
- Face3 f3(b.leaf->vertices[0],b.leaf->vertices[1],b.leaf->vertices[2]);
-
-
- Vector3 res;
-
- if (f3.intersects_segment(from,to)) {
- intersected=true;
- done=true;
- }
-
- stack[level]=VISIT_DONE_BIT;
- } else {
-
-
- bool valid = b.aabb.smits_intersect_ray(from,n,0,len);
- //bool valid = b.aabb.intersects_segment(p_begin,p_end);
- //bool valid = b.aabb.intersects(ray_aabb);
-
- if (!valid) {
-
- stack[level]=VISIT_DONE_BIT;
-
- } else {
-
- stack[level]=VISIT_LEFT_BIT;
- }
- }
-
- } continue;
- case VISIT_LEFT_BIT: {
-
- stack[level]=VISIT_RIGHT_BIT;
- bstack[level+1]=b.children[0];
- stack[level+1]=TEST_RAY_BIT;
- level++;
-
- } continue;
- case VISIT_RIGHT_BIT: {
-
- stack[level]=VISIT_DONE_BIT;
- bstack[level+1]=b.children[1];
- stack[level+1]=TEST_RAY_BIT;
- level++;
- } continue;
- case VISIT_DONE_BIT: {
-
- if (level==0) {
- done=true;
- break;
- } else
- level--;
-
- } continue;
- }
-
-
- if (done)
- break;
- }
-
-
-
- if (intersected) {
-
- color.a=Math::lerp(MAX(0.01,lv[i].darkening),1.0,att);
- }
-
- }
-
- break;
- } else {
-
- Vector3 lpos = p_pos - octant.aabb.pos;
- Vector3 half = octant.aabb.size * 0.5;
-
- int ofs=0;
-
- if (lpos.x >= half.x)
- ofs|=1;
- if (lpos.y >= half.y)
- ofs|=2;
- if (lpos.z >= half.z)
- ofs|=4;
-
- octant_idx = octant.children[ofs];
-
- if (octant_idx==0)
- return;
-
- }
- }
-
- ptr[0]=CLAMP(color.r*255.0,0,255);
- ptr[1]=CLAMP(color.g*255.0,0,255);
- ptr[2]=CLAMP(color.b*255.0,0,255);
- ptr[3]=CLAMP(color.a*255.0,0,255);
-
-}
-
-
-Error BakedLightBaker::transfer_to_lightmaps() {
-
- if (!triangles.size() || baked_textures.size()==0)
- return ERR_UNCONFIGURED;
-
- EditorProgress ep("transfer_to_lightmaps",TTR("Transfer to Lightmaps:"),baked_textures.size()*2+triangles.size());
-
- for(int i=0;i<baked_textures.size();i++) {
-
- ERR_FAIL_COND_V( baked_textures[i].width<=0 || baked_textures[i].height<=0,ERR_UNCONFIGURED );
-
- baked_textures[i].data.resize( baked_textures[i].width*baked_textures[i].height*4 );
- zeromem(baked_textures[i].data.ptr(),baked_textures[i].data.size());
- ep.step(TTR("Allocating Texture #")+itos(i+1),i);
- }
-
- 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);
- }
- float gamma = baked_light->get_gamma_adjust();
- float mult = baked_light->get_energy_multiplier();
-
- for(int i=0;i<triangles.size();i++) {
-
- if (i%200==0) {
- ep.step(TTR("Baking Triangle #")+itos(i),i+baked_textures.size());
- }
- Triangle &t=triangles[i];
- if (t.baked_texture<0 || t.baked_texture>=baked_textures.size())
- continue;
-
- BakeTexture &bt=baked_textures[t.baked_texture];
- Vector3 normal = Plane(t.vertices[0],t.vertices[1],t.vertices[2]).normal;
-
-
- int x[3];
- int y[3];
-
- Vector3 vertices[3]={
- t.vertices[0],
- t.vertices[1],
- t.vertices[2]
- };
-
- for(int j=0;j<3;j++) {
-
- x[j]=t.bake_uvs[j].x*bt.width;
- y[j]=t.bake_uvs[j].y*bt.height;
- x[j]=CLAMP(x[j],0,bt.width-1);
- y[j]=CLAMP(y[j],0,bt.height-1);
- }
-
-
- {
-
- // sort the points vertically
- if (y[1] > y[2]) {
- SWAP(x[1], x[2]);
- SWAP(y[1], y[2]);
- SWAP(vertices[1],vertices[2]);
- }
- if (y[0] > y[1]) {
- SWAP(x[0], x[1]);
- SWAP(y[0], y[1]);
- SWAP(vertices[0],vertices[1]);
- }
- if (y[1] > y[2]) {
- SWAP(x[1], x[2]);
- SWAP(y[1], y[2]);
- SWAP(vertices[1],vertices[2]);
- }
-
- double dx_far = double(x[2] - x[0]) / (y[2] - y[0] + 1);
- double dx_upper = double(x[1] - x[0]) / (y[1] - y[0] + 1);
- double dx_low = double(x[2] - x[1]) / (y[2] - y[1] + 1);
- double xf = x[0];
- double xt = x[0] + dx_upper; // if y[0] == y[1], special case
- for (int yi = y[0]; yi <= (y[2] > bt.height-1 ? bt.height-1 : y[2]); yi++)
- {
- if (yi >= 0) {
- for (int xi = (xf > 0 ? int(xf) : 0); xi <= (xt < bt.width ? xt : bt.width-1) ; xi++) {
- //pixels[int(x + y * width)] = color;
-
- Vector2 v0 = Vector2(x[1]-x[0],y[1]-y[0]);
- Vector2 v1 = Vector2(x[2]-x[0],y[2]-y[0]);
- //vertices[2] - vertices[0];
- Vector2 v2 = Vector2(xi-x[0],yi-y[0]);
- float d00 = v0.dot( v0);
- float d01 = v0.dot( v1);
- float d11 = v1.dot( v1);
- float d20 = v2.dot( v0);
- float d21 = v2.dot( v1);
- float denom = (d00 * d11 - d01 * d01);
- Vector3 pos;
- if (denom==0) {
- pos=t.vertices[0];
- } else {
- float v = (d11 * d20 - d01 * d21) / denom;
- float w = (d00 * d21 - d01 * d20) / denom;
- float u = 1.0f - v - w;
- pos = vertices[0]*u + vertices[1]*v + vertices[2]*w;
- }
- _plot_pixel_to_lightmap(xi,yi,bt.width,bt.height,bt.data.ptr(),pos,normal,norm_arr.ptr(),mult,gamma);
-
- }
-
- for (int xi = (xf < bt.width ? int(xf) : bt.width-1); xi >= (xt > 0 ? xt : 0); xi--) {
- //pixels[int(x + y * width)] = color;
- Vector2 v0 = Vector2(x[1]-x[0],y[1]-y[0]);
- Vector2 v1 = Vector2(x[2]-x[0],y[2]-y[0]);
- //vertices[2] - vertices[0];
- Vector2 v2 = Vector2(xi-x[0],yi-y[0]);
- float d00 = v0.dot( v0);
- float d01 = v0.dot( v1);
- float d11 = v1.dot( v1);
- float d20 = v2.dot( v0);
- float d21 = v2.dot( v1);
- float denom = (d00 * d11 - d01 * d01);
- Vector3 pos;
- if (denom==0) {
- pos=t.vertices[0];
- } else {
- float v = (d11 * d20 - d01 * d21) / denom;
- float w = (d00 * d21 - d01 * d20) / denom;
- float u = 1.0f - v - w;
- pos = vertices[0]*u + vertices[1]*v + vertices[2]*w;
- }
-
- _plot_pixel_to_lightmap(xi,yi,bt.width,bt.height,bt.data.ptr(),pos,normal,norm_arr.ptr(),mult,gamma);
-
- }
- }
- xf += dx_far;
- if (yi < y[1])
- xt += dx_upper;
- else
- xt += dx_low;
- }
- }
-
- }
-
-
- for(int i=0;i<baked_textures.size();i++) {
-
-
- {
-
- ep.step(TTR("Post-Processing Texture #")+itos(i),i+baked_textures.size()+triangles.size());
-
- BakeTexture &bt=baked_textures[i];
-
- Vector<uint8_t> copy_data=bt.data;
- uint8_t *data=bt.data.ptr();
- const int max_radius=8;
- const int shadow_radius=2;
- const int max_dist=0x7FFFFFFF;
-
- for(int x=0;x<bt.width;x++) {
-
- for(int y=0;y<bt.height;y++) {
-
-
- uint8_t a = copy_data[(y*bt.width+x)*4+3];
-
- if (a>0) {
- //blur shadow
-
- int from_x = MAX(0,x-shadow_radius);
- int to_x = MIN(bt.width-1,x+shadow_radius);
- int from_y = MAX(0,y-shadow_radius);
- int to_y = MIN(bt.height-1,y+shadow_radius);
-
- int sum=0;
- int sumc=0;
-
- for(int k=from_y;k<=to_y;k++) {
- for(int l=from_x;l<=to_x;l++) {
-
- const uint8_t * rp = &copy_data[(k*bt.width+l)<<2];
-
- sum+=rp[3];
- sumc++;
- }
- }
-
- sum/=sumc;
- data[(y*bt.width+x)*4+3]=sum;
-
- } else {
-
- int closest_dist=max_dist;
- uint8_t closest_color[4];
-
- int from_x = MAX(0,x-max_radius);
- int to_x = MIN(bt.width-1,x+max_radius);
- int from_y = MAX(0,y-max_radius);
- int to_y = MIN(bt.height-1,y+max_radius);
-
- for(int k=from_y;k<=to_y;k++) {
- for(int l=from_x;l<=to_x;l++) {
-
- int dy = y-k;
- int dx = x-l;
- int dist = dy*dy+dx*dx;
- if (dist>=closest_dist)
- continue;
-
- const uint8_t * rp = &copy_data[(k*bt.width+l)<<2];
-
- if (rp[3]==0)
- continue;
-
- closest_dist=dist;
- closest_color[0]=rp[0];
- closest_color[1]=rp[1];
- closest_color[2]=rp[2];
- closest_color[3]=rp[3];
- }
- }
-
-
- if (closest_dist!=max_dist) {
-
- data[(y*bt.width+x)*4+0]=closest_color[0];
- data[(y*bt.width+x)*4+1]=closest_color[1];
- data[(y*bt.width+x)*4+2]=closest_color[2];
- data[(y*bt.width+x)*4+3]=closest_color[3];
- }
- }
- }
- }
- }
-
- PoolVector<uint8_t> dv;
- dv.resize(baked_textures[i].data.size());
- {
- PoolVector<uint8_t>::Write w = dv.write();
- copymem(w.ptr(),baked_textures[i].data.ptr(),baked_textures[i].data.size());
- }
-
- Image img(baked_textures[i].width,baked_textures[i].height,0,Image::FORMAT_RGBA8,dv);
- Ref<ImageTexture> tex = memnew( ImageTexture );
- tex->create_from_image(img);
- baked_light->set_lightmap_texture(i,tex);
- }
-
-
- return OK;
-}
-
-void BakedLightBaker::clear() {
-
-
-
- _stop_thread();
-
- if (bvh)
- _free_bvh(bvh);
-
- if (ray_stack)
- memdelete_arr(ray_stack);
- if (octant_stack)
- memdelete_arr(octant_stack);
- if (octantptr_stack)
- 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());
- */
-
- for(int i=0;i<lights.size();i++) {
- norm_arr[i] = 1.0/get_normalization(i);
- }
-
- const double *normptr=norm_arr.ptr();
- }
-*/
- octant_pool.clear();
- octant_pool_size=0;
- bvh=NULL;
- leaf_list=0;
- cell_count=0;
- ray_stack=NULL;
- octant_stack=NULL;
- octantptr_stack=NULL;
- bvh_stack=NULL;
- materials.clear();
- materials.clear();
- textures.clear();
- lights.clear();
- triangles.clear();
- endpoint_normal.clear();
- endpoint_normal_bits.clear();
- baked_octree_texture_w=0;
- baked_octree_texture_h=0;
- paused=false;
- baking=false;
-
- bake_thread_exit=false;
- first_bake_to_map=true;
- baked_light=Ref<BakedLight>();
- total_rays=0;
-
-}
-
-BakedLightBaker::BakedLightBaker() {
- octree_depth=9;
- lattice_size=4;
- octant_pool.clear();
- octant_pool_size=0;
- bvh=NULL;
- leaf_list=0;
- cell_count=0;
- ray_stack=NULL;
- bvh_stack=NULL;
- octant_stack=NULL;
- octantptr_stack=NULL;
- plot_size=2.5;
- max_bounces=2;
- materials.clear();
- baked_octree_texture_w=0;
- baked_octree_texture_h=0;
- paused=false;
- baking=false;
-
- bake_thread_exit=false;
- total_rays=0;
- first_bake_to_map=true;
- linear_color=false;
-
-}
-
-BakedLightBaker::~BakedLightBaker() {
-
- clear();
-}
-#endif
diff --git a/editor/plugins/baked_light_baker.h b/editor/plugins/baked_light_baker.h
deleted file mode 100644
index 123812fc07..0000000000
--- a/editor/plugins/baked_light_baker.h
+++ /dev/null
@@ -1,382 +0,0 @@
-/*************************************************************************/
-/* baked_light_baker.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef BAKED_LIGHT_BAKER_H
-#define BAKED_LIGHT_BAKER_H
-
-#include "os/thread.h"
-
-#include "scene/3d/light.h"
-#include "scene/3d/mesh_instance.h"
-
-#if 0
-
-class BakedLightBaker {
-public:
-
- enum {
-
- ATTENUATION_CURVE_LEN=256,
- OCTANT_POOL_CHUNK=1000000
- };
-
- /*
- struct OctantLight {
- 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 {
- int next_leaf;
- float offset[3];
- int bake_neighbour;
- bool first_neighbour;
- double light_accum[8][3];
- };
- int children[8];
- };
- };
-
- struct OctantHash {
-
- int next;
- uint32_t hash;
- uint64_t value;
-
- };
-
- struct MeshTexture {
-
- Vector<uint8_t> tex;
- int tex_w,tex_h;
-
- _FORCE_INLINE_ void get_color(const Vector2& p_uv,Color& ret) {
-
- if (tex_w && tex_h) {
-
- int x = Math::fast_ftoi(Math::fposmod(p_uv.x,1.0)*tex_w);
- int y = Math::fast_ftoi(Math::fposmod(p_uv.y,1.0)*tex_w);
- x=CLAMP(x,0,tex_w-1);
- y=CLAMP(y,0,tex_h-1);
- const uint8_t*ptr = &tex[(y*tex_w+x)*4];
- ret.r*=ptr[0]/255.0;
- ret.g*=ptr[1]/255.0;
- ret.b*=ptr[2]/255.0;
- ret.a*=ptr[3]/255.0;
- }
- }
-
- };
-
- struct Param {
-
- Color color;
- MeshTexture*tex;
- _FORCE_INLINE_ Color get_color(const Vector2& p_uv) {
-
- Color ret=color;
- if (tex)
- tex->get_color(p_uv,ret);
- return ret;
-
- }
-
- };
-
- struct MeshMaterial {
-
- Param diffuse;
- Param specular;
- Param emission;
- };
-
- struct Triangle {
-
- AABB aabb;
- Vector3 vertices[3];
- Vector2 uvs[3];
- Vector2 bake_uvs[3];
- Vector3 normals[3];
- MeshMaterial *material;
- int baked_texture;
-
- _FORCE_INLINE_ Vector2 get_uv(const Vector3& p_pos) {
-
- Vector3 v0 = vertices[1] - vertices[0];
- Vector3 v1 = vertices[2] - vertices[0];
- Vector3 v2 = p_pos - vertices[0];
-
- float d00 = v0.dot( v0);
- float d01 = v0.dot( v1);
- float d11 = v1.dot( v1);
- float d20 = v2.dot( v0);
- float d21 = v2.dot( v1);
- float denom = (d00 * d11 - d01 * d01);
- if (denom==0)
- return uvs[0];
- float v = (d11 * d20 - d01 * d21) / denom;
- float w = (d00 * d21 - d01 * d20) / denom;
- float u = 1.0f - v - w;
-
- return uvs[0]*u + uvs[1]*v + uvs[2]*w;
- }
-
- _FORCE_INLINE_ void get_uv_and_normal(const Vector3& p_pos,Vector2& r_uv,Vector3& r_normal) {
-
- Vector3 v0 = vertices[1] - vertices[0];
- Vector3 v1 = vertices[2] - vertices[0];
- Vector3 v2 = p_pos - vertices[0];
-
- float d00 = v0.dot( v0);
- float d01 = v0.dot( v1);
- float d11 = v1.dot( v1);
- float d20 = v2.dot( v0);
- float d21 = v2.dot( v1);
- float denom = (d00 * d11 - d01 * d01);
- if (denom==0) {
- r_normal=normals[0];
- r_uv=uvs[0];
- return;
- }
- float v = (d11 * d20 - d01 * d21) / denom;
- float w = (d00 * d21 - d01 * d20) / denom;
- float u = 1.0f - v - w;
-
- r_uv=uvs[0]*u + uvs[1]*v + uvs[2]*w;
- r_normal=(normals[0]*u+normals[1]*v+normals[2]*w).normalized();
- }
- };
-
-
- struct BVH {
-
- AABB aabb;
- Vector3 center;
- Triangle *leaf;
- BVH*children[2];
- };
-
-
- struct BVHCmpX {
-
- bool operator()(const BVH* p_left, const BVH* p_right) const {
-
- return p_left->center.x < p_right->center.x;
- }
- };
-
- struct BVHCmpY {
-
- bool operator()(const BVH* p_left, const BVH* p_right) const {
-
- return p_left->center.y < p_right->center.y;
- }
- };
- struct BVHCmpZ {
-
- bool operator()(const BVH* p_left, const BVH* p_right) const {
-
- return p_left->center.z < p_right->center.z;
- }
- };
-
- struct BakeTexture {
-
- Vector<uint8_t> data;
- int width,height;
- };
-
-
- struct LightData {
-
- VS::LightType type;
-
- Vector3 pos;
- Vector3 up;
- Vector3 left;
- Vector3 dir;
- Color diffuse;
- Color specular;
- float energy;
- float length;
- int rays_thrown;
- bool bake_shadow;
-
- float radius;
- float attenuation;
- float spot_angle;
- float darkening;
- float spot_attenuation;
- float area;
-
- float constant;
-
- bool bake_direct;
-
- Vector<float> attenuation_table;
-
- };
-
-
- Vector<LightData> lights;
-
- List<MeshMaterial> materials;
- List<MeshTexture> textures;
-
- AABB octree_aabb;
- Vector<Octant> octant_pool;
- int octant_pool_size;
- BVH*bvh;
- Vector<Triangle> triangles;
- Vector<BakeTexture> baked_textures;
- 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;
-
- float cell_size;
- float plot_size; //multiplied by cell size
- float octree_extra_margin;
-
- int max_bounces;
- 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;
-
-
-
- MeshTexture* _get_mat_tex(const Ref<Texture>& p_tex);
- void _add_mesh(const Ref<Mesh>& p_mesh,const Ref<Material>& p_mat_override,const Transform& p_xform,int p_baked_texture=-1);
- void _parse_geometry(Node* p_node);
- BVH* _parse_bvh(BVH** p_children,int p_size,int p_depth,int& max_depth);
- void _make_bvh();
- void _make_octree();
- void _make_octree_texture();
- void _octree_insert(int p_octant, Triangle* p_triangle, int p_depth);
- _FORCE_INLINE_ void _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);
-
-
- void _free_bvh(BVH* p_bvh);
-
- void _fix_lights();
-
- Ref<BakedLight> baked_light;
-
-
- //void _plot_light(const Vector3& p_plot_pos,const AABB& p_plot_aabb,const Color& p_light,int p_octant=0);
- 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(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;
-
- Vector<Thread*> threads;
-
- bool bake_thread_exit;
- static void _bake_thread_func(void *arg);
-
- void _start_thread();
- void _stop_thread();
-public:
-
-
- 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();
- uint64_t get_rays_thrown() { return total_rays; }
-
- Error transfer_to_lightmaps();
-
- void update_octree_sampler(PoolVector<int> &p_sampler);
- void update_octree_images(PoolVector<uint8_t> &p_octree,PoolVector<uint8_t> &p_light);
-
- Ref<BakedLight> get_baked_light() { return baked_light; }
-
- void clear();
-
- BakedLightBaker();
- ~BakedLightBaker();
-
-};
-
-#endif // BAKED_LIGHT_BAKER_H
-#endif
diff --git a/editor/plugins/baked_light_baker_cmpxchg.cpp b/editor/plugins/baked_light_baker_cmpxchg.cpp
deleted file mode 100644
index f0a1aea416..0000000000
--- a/editor/plugins/baked_light_baker_cmpxchg.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*************************************************************************/
-/* baked_light_baker_cmpxchg.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#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/editor/plugins/baked_light_editor_plugin.cpp b/editor/plugins/baked_light_editor_plugin.cpp
deleted file mode 100644
index f973639a67..0000000000
--- a/editor/plugins/baked_light_editor_plugin.cpp
+++ /dev/null
@@ -1,377 +0,0 @@
-/*************************************************************************/
-/* baked_light_editor_plugin.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "baked_light_editor_plugin.h"
-
-#include "io/marshalls.h"
-#include "io/resource_saver.h"
-#include "scene/3d/mesh_instance.h"
-#include "scene/gui/box_container.h"
-
-#if 0
-
-
-void BakedLightEditor::_end_baking() {
-
- baker->clear();
- set_process(false);
- button_bake->set_pressed(false);
- bake_info->set_text("");
-}
-
-void BakedLightEditor::_node_removed(Node *p_node) {
-
- if(p_node==node) {
- _end_baking();
- node=NULL;
-
- hide();
- }
-
-}
-
-
-
-
-
-void BakedLightEditor::_notification(int p_option) {
-
-
- if (p_option==NOTIFICATION_ENTER_TREE) {
-
- button_bake->set_icon(get_icon("Bake","EditorIcons"));
- button_reset->set_icon(get_icon("Reload","EditorIcons"));
- button_make_lightmaps->set_icon(get_icon("LightMap","EditorIcons"));
- }
-
- if (p_option==NOTIFICATION_PROCESS) {
-
- if (baker->is_baking() && !baker->is_paused()) {
-
- update_timeout-=get_process_delta_time();
- if (update_timeout<0) {
-
- if (baker->get_baked_light()!=node->get_baked_light()) {
- _end_baking();
- return;
- }
-
- uint64_t t = OS::get_singleton()->get_ticks_msec();
-
-#ifdef DEBUG_CUBES
- double norm = baker->get_normalization();
- float max_lum=0;
-
- {
- PoolVector<Color>::Write cw=colors.write();
- BakedLightBaker::Octant *octants=baker->octant_pool.ptr();
- BakedLightBaker::Octant *oct = &octants[baker->leaf_list];
- int vert_idx=0;
-
- while(oct) {
-
-
-
- Color colors[8];
- for(int i=0;i<8;i++) {
-
- colors[i].r=oct->light_accum[i][0]/norm;
- colors[i].g=oct->light_accum[i][1]/norm;
- colors[i].b=oct->light_accum[i][2]/norm;
-
- float lum = colors[i].get_v();
- /*
- if (lum<0.05)
- color.a=0;
- */
- if (lum>max_lum)
- max_lum=lum;
-
- }
- static const int vert2cub[36]={7,3,1,1,5,7,7,6,2,2,3,7,7,5,4,4,6,7,2,6,4,4,0,2,4,5,1,1,0,4,1,3,2,2,0,1};
- for (int i=0;i<36;i++) {
-
-
- cw[vert_idx++]=colors[vert2cub[i]];
- }
-
- if (oct->next_leaf)
- oct=&octants[oct->next_leaf];
- else
- oct=NULL;
-
- }
- }
- print_line("MSCOL: "+itos(OS::get_singleton()->get_ticks_msec()-t));
- t = OS::get_singleton()->get_ticks_msec();
-
- 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);
-#endif
- ERR_FAIL_COND(node->get_baked_light().is_null());
-
- 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_RGBA8,octree_texture);
- Ref<ImageTexture> it = memnew( ImageTexture );
- it->create_from_image(img);
- ResourceSaver::save("baked_octree.png",it);
-
-#endif
-
-
- 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));
-
-
-
- }
- }
- }
-}
-
-
-void BakedLightEditor::_menu_option(int p_option) {
-
-
- switch(p_option) {
-
-
- case MENU_OPTION_BAKE: {
-
- ERR_FAIL_COND(!node);
- ERR_FAIL_COND(node->get_baked_light().is_null());
- baker->bake(node->get_baked_light(),node);
- node->get_baked_light()->set_mode(BakedLight::MODE_OCTREE);
- update_timeout=0;
- set_process(true);
-
-
- } break;
- case MENU_OPTION_CLEAR: {
-
-
-
- } break;
-
- }
-}
-
-void BakedLightEditor::_bake_pressed() {
-
- ERR_FAIL_COND(!node);
- const String conf_warning = node->get_configuration_warning();
- if (!conf_warning.empty()) {
- err_dialog->set_text(conf_warning);
- err_dialog->popup_centered_minsize();
- button_bake->set_pressed(false);
- return;
- }
-
- if (baker->is_baking()) {
-
- baker->set_pause(!button_bake->is_pressed());
- if (baker->is_paused()) {
-
- set_process(false);
- bake_info->set_text("");
- button_reset->show();
- button_make_lightmaps->show();
-
- } else {
-
- update_timeout=0;
- set_process(true);
- button_make_lightmaps->hide();
- button_reset->hide();
- }
- } else {
- baker->bake(node->get_baked_light(),node);
- node->get_baked_light()->set_mode(BakedLight::MODE_OCTREE);
- update_timeout=0;
-
- last_rays_time=0;
- button_bake->set_pressed(false);
-
- set_process(true);
- }
-
-}
-
-void BakedLightEditor::_clear_pressed(){
-
- baker->clear();
- button_bake->set_pressed(false);
- bake_info->set_text("");
-
-}
-
-void BakedLightEditor::edit(BakedLightInstance *p_baked_light) {
-
- if (p_baked_light==NULL || node==p_baked_light) {
- return;
- }
- if (node && node!=p_baked_light)
- _end_baking();
-
-
- node=p_baked_light;
- //_end_baking();
-
-}
-
-void BakedLightEditor::_bake_lightmaps() {
-
- Error err = baker->transfer_to_lightmaps();
- if (err) {
-
- err_dialog->set_text("Error baking to lightmaps!\nMake sure that a bake has just\n happened and that lightmaps are\n configured. ");
- err_dialog->popup_centered_minsize();
- return;
- }
-
- node->get_baked_light()->set_mode(BakedLight::MODE_LIGHTMAPS);
-
-
-}
-
-void BakedLightEditor::_bind_methods() {
-
- ClassDB::bind_method("_menu_option",&BakedLightEditor::_menu_option);
- ClassDB::bind_method("_bake_pressed",&BakedLightEditor::_bake_pressed);
- ClassDB::bind_method("_clear_pressed",&BakedLightEditor::_clear_pressed);
- ClassDB::bind_method("_bake_lightmaps",&BakedLightEditor::_bake_lightmaps);
-}
-
-BakedLightEditor::BakedLightEditor() {
-
-
- bake_hbox = memnew( HBoxContainer );
- button_bake = memnew( ToolButton );
- button_bake->set_text(TTR("Bake!"));
- button_bake->set_toggle_mode(true);
- button_reset = memnew( Button );
- button_make_lightmaps = memnew( Button );
- button_bake->set_tooltip("Start/Unpause the baking process.\nThis bakes lighting into the lightmap octree.");
- button_make_lightmaps ->set_tooltip("Convert the lightmap octree to lightmap textures\n(must have set up UV/Lightmaps properly before!).");
-
-
- bake_info = memnew( Label );
- bake_hbox->add_child( button_bake );
- bake_hbox->add_child( button_reset );
- bake_hbox->add_child( bake_info );
-
- err_dialog = memnew( AcceptDialog );
- add_child(err_dialog);
- node=NULL;
- baker = memnew( BakedLightBaker );
-
- bake_hbox->add_child(button_make_lightmaps);
- button_make_lightmaps->hide();
-
- button_bake->connect("pressed",this,"_bake_pressed");
- button_reset->connect("pressed",this,"_clear_pressed");
- button_make_lightmaps->connect("pressed",this,"_bake_lightmaps");
- button_reset->hide();
- button_reset->set_tooltip(TTR("Reset the lightmap octree baking process (start over)."));
-
-
- update_timeout=0;
-
-
-
-}
-
-BakedLightEditor::~BakedLightEditor() {
-
- memdelete(baker);
-}
-
-void BakedLightEditorPlugin::edit(Object *p_object) {
-
- baked_light_editor->edit(p_object->cast_to<BakedLightInstance>());
-}
-
-bool BakedLightEditorPlugin::handles(Object *p_object) const {
-
- return p_object->is_type("BakedLightInstance");
-}
-
-void BakedLightEditorPlugin::make_visible(bool p_visible) {
-
- if (p_visible) {
- baked_light_editor->show();
- baked_light_editor->bake_hbox->show();
- } else {
-
- baked_light_editor->hide();
- baked_light_editor->bake_hbox->hide();
- baked_light_editor->edit(NULL);
- }
-
-}
-
-BakedLightEditorPlugin::BakedLightEditorPlugin(EditorNode *p_node) {
-
- editor=p_node;
- baked_light_editor = memnew( BakedLightEditor );
- editor->get_viewport()->add_child(baked_light_editor);
- add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU,baked_light_editor->bake_hbox);
- baked_light_editor->hide();
- baked_light_editor->bake_hbox->hide();
-}
-
-
-BakedLightEditorPlugin::~BakedLightEditorPlugin()
-{
-}
-
-#endif
diff --git a/editor/plugins/baked_light_editor_plugin.h b/editor/plugins/baked_light_editor_plugin.h
deleted file mode 100644
index c4a7cd51cf..0000000000
--- a/editor/plugins/baked_light_editor_plugin.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*************************************************************************/
-/* baked_light_editor_plugin.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef BAKED_LIGHT_EDITOR_PLUGIN_H
-#define BAKED_LIGHT_EDITOR_PLUGIN_H
-
-#include "editor/editor_node.h"
-#include "editor/editor_plugin.h"
-#include "editor/plugins/baked_light_baker.h"
-#include "scene/gui/spin_box.h"
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-
-#if 0
-
-class MeshInstance;
-
-class BakedLightEditor : public Control {
-
- GDCLASS(BakedLightEditor, Control );
-
-
- float update_timeout;
- PoolVector<uint8_t> octree_texture;
- PoolVector<uint8_t> light_texture;
- PoolVector<int> octree_sampler;
-
- BakedLightBaker *baker;
- AcceptDialog *err_dialog;
-
- HBoxContainer *bake_hbox;
- Button *button_bake;
- Button *button_reset;
- Button *button_make_lightmaps;
- Label *bake_info;
-
- uint64_t last_rays_time;
-
-
-
- BakedLightInstance *node;
-
- enum Menu {
-
- MENU_OPTION_BAKE,
- MENU_OPTION_CLEAR
- };
-
- void _bake_lightmaps();
-
- void _bake_pressed();
- void _clear_pressed();
-
- 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(BakedLightInstance *p_baked_light);
- BakedLightEditor();
- ~BakedLightEditor();
-};
-
-class BakedLightEditorPlugin : public EditorPlugin {
-
- GDCLASS( BakedLightEditorPlugin, EditorPlugin );
-
- BakedLightEditor *baked_light_editor;
- EditorNode *editor;
-
-public:
-
- virtual String get_name() const { return "BakedLight"; }
- 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);
-
- BakedLightEditorPlugin(EditorNode *p_node);
- ~BakedLightEditorPlugin();
-
-};
-
-#endif // MULTIMESH_EDITOR_PLUGIN_H
-#endif
diff --git a/editor/plugins/camera_editor_plugin.cpp b/editor/plugins/camera_editor_plugin.cpp
index 8e625c4a73..c19540116e 100644
--- a/editor/plugins/camera_editor_plugin.cpp
+++ b/editor/plugins/camera_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -97,8 +97,8 @@ CameraEditor::CameraEditor() {
void CameraEditorPlugin::edit(Object *p_object) {
- SpatialEditor::get_singleton()->set_can_preview(p_object->cast_to<Camera>());
- //camera_editor->edit(p_object->cast_to<Node>());
+ SpatialEditor::get_singleton()->set_can_preview(Object::cast_to<Camera>(p_object));
+ //camera_editor->edit(Object::cast_to<Node>(p_object));
}
bool CameraEditorPlugin::handles(Object *p_object) const {
@@ -109,7 +109,7 @@ bool CameraEditorPlugin::handles(Object *p_object) const {
void CameraEditorPlugin::make_visible(bool p_visible) {
if (p_visible) {
- //SpatialEditor::get_singleton()->set_can_preview(p_object->cast_to<Camera>());
+ //SpatialEditor::get_singleton()->set_can_preview(Object::cast_to<Camera>(p_object));
} else {
SpatialEditor::get_singleton()->set_can_preview(NULL);
}
diff --git a/editor/plugins/camera_editor_plugin.h b/editor/plugins/camera_editor_plugin.h
index a0f98687cb..12702db7a5 100644
--- a/editor/plugins/camera_editor_plugin.h
+++ b/editor/plugins/camera_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 9e57e53a24..4f3472bf03 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -175,7 +175,7 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Node2D *n2d = E->get()->cast_to<Node2D>();
+ Node2D *n2d = Object::cast_to<Node2D>(E->get());
if (n2d && n2d->edit_has_pivot()) {
Vector2 offset = n2d->edit_get_pivot();
@@ -190,7 +190,7 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) {
undo_redo->add_undo_method(n2d, "set_global_position", gpos);
undo_redo->add_undo_method(n2d, "edit_set_pivot", offset);
for (int i = 0; i < n2d->get_child_count(); i++) {
- Node2D *n2dc = n2d->get_child(i)->cast_to<Node2D>();
+ Node2D *n2dc = Object::cast_to<Node2D>(n2d->get_child(i));
if (!n2dc)
continue;
@@ -199,7 +199,7 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) {
}
}
- Control *cnt = E->get()->cast_to<Control>();
+ Control *cnt = Object::cast_to<Control>(E->get());
if (cnt) {
Vector2 old_pivot = cnt->get_pivot_offset();
@@ -265,7 +265,7 @@ void CanvasItemEditor::_tool_select(int p_index) {
Object *CanvasItemEditor::_get_editor_data(Object *p_what) {
- CanvasItem *ci = p_what->cast_to<CanvasItem>();
+ CanvasItem *ci = Object::cast_to<CanvasItem>(p_what);
if (!ci)
return NULL;
@@ -382,54 +382,15 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) {
void CanvasItemEditor::_add_canvas_item(CanvasItem *p_canvas_item) {
editor_selection->add_node(p_canvas_item);
-#if 0
- if (canvas_items.has(p_canvas_item))
- return;
-
- canvas_items.insert(p_canvas_item,p_info);
- p_canvas_item->connect("hide",this,"_visibility_changed",varray(p_canvas_item->get_instance_id()),CONNECT_ONESHOT);
-#endif
}
void CanvasItemEditor::_remove_canvas_item(CanvasItem *p_canvas_item) {
editor_selection->remove_node(p_canvas_item);
-#if 0
- p_canvas_item->disconnect("hide",this,"_visibility_changed");
- canvas_items.erase(p_canvas_item);
-#endif
}
void CanvasItemEditor::_clear_canvas_items() {
editor_selection->clear();
-#if 0
- while(canvas_items.size())
- _remove_canvas_item(canvas_items.front()->key());
-#endif
-}
-
-void CanvasItemEditor::_visibility_changed(ObjectID p_canvas_item) {
-#if 0
- Object *c = ObjectDB::get_instance(p_canvas_item);
- if (!c)
- return;
- CanvasItem *ct = c->cast_to<CanvasItem>();
- if (!ct)
- return;
- canvas_items.erase(ct);
- //_remove_canvas_item(ct);
- update();
-#endif
-}
-
-void CanvasItemEditor::_node_removed(Node *p_node) {
-#if 0
- CanvasItem *canvas_item = (CanvasItem*)p_node; //not a good cast, but safe
- if (canvas_items.has(canvas_item))
- _remove_canvas_item(canvas_item);
-
- update();
-#endif
}
void CanvasItemEditor::_keying_changed() {
@@ -451,17 +412,17 @@ bool CanvasItemEditor::_is_part_of_subscene(CanvasItem *p_item) {
void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, const Transform2D &p_parent_xform, const Transform2D &p_canvas_xform, Vector<_SelectResult> &r_items, unsigned int limit) {
if (!p_node)
return;
- if (p_node->cast_to<Viewport>())
+ if (Object::cast_to<Viewport>(p_node))
return;
- CanvasItem *c = p_node->cast_to<CanvasItem>();
+ CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
if (c && !c->is_set_as_toplevel())
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), p_parent_xform * c->get_transform(), p_canvas_xform, r_items);
else {
- CanvasLayer *cl = p_node->cast_to<CanvasLayer>();
+ CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
_find_canvas_items_at_pos(p_pos, p_node->get_child(i), transform, cl ? cl->get_transform() : p_canvas_xform, r_items); //use base transform
}
@@ -469,13 +430,13 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no
return;
}
- if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !c->cast_to<CanvasLayer>()) {
+ if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) {
Rect2 rect = c->get_item_rect();
Point2 local_pos = (p_parent_xform * p_canvas_xform * c->get_transform()).affine_inverse().xform(p_pos);
if (rect.has_point(local_pos)) {
- Node2D *node = c->cast_to<Node2D>();
+ Node2D *node = Object::cast_to<Node2D>(c);
_SelectResult res;
res.item = c;
@@ -492,10 +453,10 @@ void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_n
if (!p_node)
return;
- if (p_node->cast_to<Viewport>())
+ if (Object::cast_to<Viewport>(p_node))
return;
- CanvasItem *c = p_node->cast_to<CanvasItem>();
+ CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
bool inherited = p_node != get_tree()->get_edited_scene_root() && p_node->get_filename() != "";
bool editable = false;
@@ -509,13 +470,13 @@ void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_n
if (c && !c->is_set_as_toplevel())
_find_canvas_items_at_rect(p_rect, p_node->get_child(i), p_parent_xform * c->get_transform(), p_canvas_xform, r_items);
else {
- CanvasLayer *cl = p_node->cast_to<CanvasLayer>();
+ CanvasLayer *cl = Object::cast_to<CanvasLayer>(p_node);
_find_canvas_items_at_rect(p_rect, p_node->get_child(i), transform, cl ? cl->get_transform() : p_canvas_xform, r_items);
}
}
}
- if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !c->cast_to<CanvasLayer>()) {
+ if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) {
Rect2 rect = c->get_item_rect();
Transform2D xform = p_parent_xform * p_canvas_xform * c->get_transform();
@@ -561,7 +522,7 @@ bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_po
editor_selection->clear();
editor_selection->add_node(item);
// Reselect
- if (get_tree()->is_editor_hint()) {
+ if (Engine::get_singleton()->is_editor_hint()) {
editor->call("edit_node", item);
}
}
@@ -590,7 +551,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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
@@ -619,7 +580,7 @@ void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE
} else { // p_move_mode==MOVE_LOCAL_BASE || p_move_mode==MOVE_LOCAL_WITH_ROT
- if (Node2D *node_2d = canvas_item->cast_to<Node2D>()) {
+ if (Node2D *node_2d = Object::cast_to<Node2D>(canvas_item)) {
if (p_move_mode == MOVE_LOCAL_WITH_ROT) {
Transform2D m;
@@ -628,7 +589,7 @@ void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE
}
node_2d->set_position(node_2d->get_position() + drag);
- } else if (Control *control = canvas_item->cast_to<Control>()) {
+ } else if (Control *control = Object::cast_to<Control>(canvas_item)) {
control->set_position(control->get_position() + drag);
}
@@ -648,7 +609,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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
@@ -673,7 +634,7 @@ int CanvasItemEditor::get_item_count() {
int ic = 0;
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
@@ -694,7 +655,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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
@@ -822,7 +783,7 @@ CanvasItemEditor::DragType CanvasItemEditor::_get_anchor_handle_drag_type(const
CanvasItem *canvas_item = get_single_item();
ERR_FAIL_COND_V(!canvas_item, DRAG_NONE);
- Control *control = canvas_item->cast_to<Control>();
+ Control *control = Object::cast_to<Control>(canvas_item);
ERR_FAIL_COND_V(!control, DRAG_NONE);
Vector2 anchor_pos[4];
@@ -865,7 +826,7 @@ void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
@@ -876,15 +837,15 @@ void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) {
continue;
se->undo_state = canvas_item->edit_get_state();
- if (canvas_item->cast_to<Node2D>())
- se->undo_pivot = canvas_item->cast_to<Node2D>()->edit_get_pivot();
- if (canvas_item->cast_to<Control>())
- se->undo_pivot = canvas_item->cast_to<Control>()->get_pivot_offset();
+ if (Object::cast_to<Node2D>(canvas_item))
+ se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot();
+ if (Object::cast_to<Control>(canvas_item))
+ se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
}
- if (selection.size() == 1 && selection[0]->cast_to<Node2D>()) {
+ if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0])) {
drag = DRAG_NODE_2D;
- drag_point_from = selection[0]->cast_to<Node2D>()->get_global_position();
+ drag_point_from = Object::cast_to<Node2D>(selection[0])->get_global_position();
} else {
drag = DRAG_ALL;
drag_point_from = _find_topleftmost_point();
@@ -993,11 +954,6 @@ void CanvasItemEditor::_selection_menu_hide() {
selection_menu->set_size(Vector2(0, 0));
}
-bool CanvasItemEditor::get_remove_list(List<Node *> *p_list) {
-
- return false; //!p_list->empty();
-}
-
void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) {
Point2 click = b->get_position();
@@ -1169,7 +1125,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
List<Node *> &selection = editor_selection->get_selected_node_list();
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
@@ -1180,10 +1136,10 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
continue;
canvas_item->edit_set_state(se->undo_state);
- if (canvas_item->cast_to<Node2D>())
- canvas_item->cast_to<Node2D>()->edit_set_pivot(se->undo_pivot);
- if (canvas_item->cast_to<Control>())
- canvas_item->cast_to<Control>()->set_pivot_offset(se->undo_pivot);
+ if (Object::cast_to<Node2D>(canvas_item))
+ Object::cast_to<Node2D>(canvas_item)->edit_set_pivot(se->undo_pivot);
+ if (Object::cast_to<Control>(canvas_item))
+ Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot);
}
}
@@ -1251,7 +1207,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
@@ -1265,13 +1221,13 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
undo_redo->add_do_method(canvas_item, "edit_set_state", state);
undo_redo->add_undo_method(canvas_item, "edit_set_state", se->undo_state);
{
- Node2D *pvt = canvas_item->cast_to<Node2D>();
+ Node2D *pvt = Object::cast_to<Node2D>(canvas_item);
if (pvt && pvt->edit_has_pivot()) {
undo_redo->add_do_method(canvas_item, "edit_set_pivot", pvt->edit_get_pivot());
undo_redo->add_undo_method(canvas_item, "edit_set_pivot", se->undo_pivot);
}
- Control *cnt = canvas_item->cast_to<Control>();
+ Control *cnt = Object::cast_to<Control>(canvas_item);
if (cnt) {
undo_redo->add_do_method(canvas_item, "set_pivot_offset", cnt->get_pivot_offset());
undo_redo->add_undo_method(canvas_item, "set_pivot_offset", se->undo_pivot);
@@ -1341,10 +1297,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
}
if (Cbone) {
- Node2D *b = NULL;
- Object *obj = ObjectDB::get_instance(Cbone->get().bone);
- if (obj)
- b = obj->cast_to<Node2D>();
+ Node2D *b = Object::cast_to<Node2D>(ObjectDB::get_instance(Cbone->get().bone));
if (b) {
@@ -1359,7 +1312,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
break;
float len = pi->get_global_transform().get_origin().distance_to(b->get_global_position());
- b = pi->cast_to<Node2D>();
+ b = Object::cast_to<Node2D>(pi);
if (!b)
break;
@@ -1405,10 +1358,10 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
drag = DRAG_ROTATE;
drag_from = transform.affine_inverse().xform(click);
se->undo_state = canvas_item->edit_get_state();
- if (canvas_item->cast_to<Node2D>())
- se->undo_pivot = canvas_item->cast_to<Node2D>()->edit_get_pivot();
- if (canvas_item->cast_to<Control>())
- se->undo_pivot = canvas_item->cast_to<Control>()->get_pivot_offset();
+ if (Object::cast_to<Node2D>(canvas_item))
+ se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot();
+ if (Object::cast_to<Control>(canvas_item))
+ se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
return;
}
@@ -1426,15 +1379,15 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
if (drag != DRAG_NONE) {
drag_from = transform.affine_inverse().xform(click);
se->undo_state = canvas_item->edit_get_state();
- if (canvas_item->cast_to<Node2D>())
- se->undo_pivot = canvas_item->cast_to<Node2D>()->edit_get_pivot();
- if (canvas_item->cast_to<Control>())
- se->undo_pivot = canvas_item->cast_to<Control>()->get_pivot_offset();
+ if (Object::cast_to<Node2D>(canvas_item))
+ se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot();
+ if (Object::cast_to<Control>(canvas_item))
+ se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
return;
}
// Drag anchor handles
- if (canvas_item->cast_to<Control>()) {
+ if (Object::cast_to<Control>(canvas_item)) {
drag = _get_anchor_handle_drag_type(click, drag_point_from);
if (drag != DRAG_NONE) {
drag_from = transform.affine_inverse().xform(click);
@@ -1457,9 +1410,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
CanvasItem *c = NULL;
if (Cbone) {
- Object *obj = ObjectDB::get_instance(Cbone->get().bone);
- if (obj)
- c = obj->cast_to<CanvasItem>();
+ c = Object::cast_to<CanvasItem>(ObjectDB::get_instance(Cbone->get().bone));
if (c)
c = c->get_parent_item();
}
@@ -1489,7 +1440,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
};
if (n) {
- c = n->cast_to<CanvasItem>();
+ c = Object::cast_to<CanvasItem>(n);
} else {
c = NULL;
}
@@ -1537,7 +1488,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
List<Node *> &selection = editor_selection->get_selected_node_list();
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = E->get()->cast_to<CanvasItem>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
@@ -1551,10 +1502,10 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
if (!dragging_bone) {
canvas_item->edit_set_state(se->undo_state); //reset state and reapply
- if (canvas_item->cast_to<Node2D>())
- canvas_item->cast_to<Node2D>()->edit_set_pivot(se->undo_pivot);
- if (canvas_item->cast_to<Control>())
- canvas_item->cast_to<Control>()->set_pivot_offset(se->undo_pivot);
+ if (Object::cast_to<Node2D>(canvas_item))
+ Object::cast_to<Node2D>(canvas_item)->edit_set_pivot(se->undo_pivot);
+ if (Object::cast_to<Control>(canvas_item))
+ Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot);
}
Vector2 dfrom = drag_from;
@@ -1566,7 +1517,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
// Rotate the node
Vector2 center = canvas_item->get_global_transform_with_canvas().get_origin();
{
- Node2D *node = canvas_item->cast_to<Node2D>();
+ Node2D *node = Object::cast_to<Node2D>(canvas_item);
if (node) {
real_t angle = node->get_rotation();
@@ -1578,7 +1529,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
}
{
- Control *node = canvas_item->cast_to<Control>();
+ Control *node = Object::cast_to<Control>(canvas_item);
if (node) {
real_t angle = node->get_rotation();
@@ -1592,7 +1543,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
continue;
}
- Control *control = canvas_item->cast_to<Control>();
+ Control *control = Object::cast_to<Control>(canvas_item);
if (control) {
// Drag and snap the anchor
Vector2 anchor = _position_to_anchor(control, canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto - drag_from + drag_point_from));
@@ -1728,19 +1679,19 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
case DRAG_PIVOT:
- if (canvas_item->cast_to<Node2D>()) {
- Node2D *n2d = canvas_item->cast_to<Node2D>();
+ if (Object::cast_to<Node2D>(canvas_item)) {
+ Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
n2d->edit_set_pivot(se->undo_pivot + drag_vector);
}
- if (canvas_item->cast_to<Control>()) {
- canvas_item->cast_to<Control>()->set_pivot_offset(se->undo_pivot + drag_vector);
+ if (Object::cast_to<Control>(canvas_item)) {
+ Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot + drag_vector);
}
continue;
break;
case DRAG_NODE_2D:
- ERR_FAIL_COND(!canvas_item->cast_to<Node2D>());
- canvas_item->cast_to<Node2D>()->set_global_position(dto);
+ ERR_FAIL_COND(!Object::cast_to<Node2D>(canvas_item));
+ Object::cast_to<Node2D>(canvas_item)->set_global_position(dto);
continue;
break;
}
@@ -1754,7 +1705,7 @@ void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
} else {
//ok, all that had to be done was done, now solve IK
- Node2D *n2d = canvas_item->cast_to<Node2D>();
+ Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
Transform2D final_xform = bone_orig_xform;
if (n2d) {
@@ -1981,7 +1932,7 @@ void CanvasItemEditor::_viewport_draw() {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
@@ -2013,16 +1964,16 @@ void CanvasItemEditor::_viewport_draw() {
if (single && (tool == TOOL_SELECT || tool == TOOL_MOVE || tool == TOOL_ROTATE || tool == TOOL_EDIT_PIVOT)) { //kind of sucks
- if (canvas_item->cast_to<Node2D>()) {
+ if (Object::cast_to<Node2D>(canvas_item)) {
- if (canvas_item->cast_to<Node2D>()->edit_has_pivot()) {
+ if (Object::cast_to<Node2D>(canvas_item)->edit_has_pivot()) {
viewport->draw_texture(pivot, xform.get_origin() + (-pivot->get_size() / 2).floor());
can_move_pivot = true;
pivot_found = true;
}
}
- Control *control = canvas_item->cast_to<Control>();
+ Control *control = Object::cast_to<Control>(canvas_item);
if (control) {
Vector2 pivot_ofs = control->get_pivot_offset();
if (pivot_ofs != Vector2()) {
@@ -2214,11 +2165,7 @@ void CanvasItemEditor::_viewport_draw() {
E->get().from = Vector2();
E->get().to = Vector2();
- Object *obj = ObjectDB::get_instance(E->get().bone);
- if (!obj)
- continue;
-
- Node2D *n2d = obj->cast_to<Node2D>();
+ Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->get().bone));
if (!n2d)
continue;
@@ -2227,7 +2174,7 @@ void CanvasItemEditor::_viewport_draw() {
CanvasItem *pi = n2d->get_parent_item();
- Node2D *pn2d = n2d->get_parent()->cast_to<Node2D>();
+ Node2D *pn2d = Object::cast_to<Node2D>(n2d->get_parent());
if (!pn2d)
continue;
@@ -2283,14 +2230,14 @@ 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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
- if (canvas_item->cast_to<Control>())
+ if (Object::cast_to<Control>(canvas_item))
has_control = true;
else
all_control = false;
@@ -2304,12 +2251,12 @@ void CanvasItemEditor::_notification(int p_what) {
float anchors[4];
Vector2 pivot;
- if (canvas_item->cast_to<Control>()) {
- pivot = canvas_item->cast_to<Control>()->get_pivot_offset();
- anchors[MARGIN_LEFT] = canvas_item->cast_to<Control>()->get_anchor(MARGIN_LEFT);
- anchors[MARGIN_RIGHT] = canvas_item->cast_to<Control>()->get_anchor(MARGIN_RIGHT);
- anchors[MARGIN_TOP] = canvas_item->cast_to<Control>()->get_anchor(MARGIN_TOP);
- anchors[MARGIN_BOTTOM] = canvas_item->cast_to<Control>()->get_anchor(MARGIN_BOTTOM);
+ if (Object::cast_to<Control>(canvas_item)) {
+ pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset();
+ anchors[MARGIN_LEFT] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_LEFT);
+ anchors[MARGIN_RIGHT] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_RIGHT);
+ anchors[MARGIN_TOP] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_TOP);
+ anchors[MARGIN_BOTTOM] = Object::cast_to<Control>(canvas_item)->get_anchor(MARGIN_BOTTOM);
}
if (r != se->prev_rect || xform != se->prev_xform || pivot != se->prev_pivot || anchors[MARGIN_LEFT] != se->prev_anchors[MARGIN_LEFT] || anchors[MARGIN_RIGHT] != se->prev_anchors[MARGIN_RIGHT] || anchors[MARGIN_TOP] != se->prev_anchors[MARGIN_TOP] || anchors[MARGIN_BOTTOM] != se->prev_anchors[MARGIN_BOTTOM]) {
@@ -2338,7 +2285,7 @@ void CanvasItemEditor::_notification(int p_what) {
break;
}
- Node2D *b2 = b->cast_to<Node2D>();
+ Node2D *b2 = Object::cast_to<Node2D>(b);
if (!b2) {
continue;
}
@@ -2373,7 +2320,6 @@ void CanvasItemEditor::_notification(int p_what) {
ungroup_button->set_icon(get_icon("Ungroup", "EditorIcons"));
key_insert_button->set_icon(get_icon("Key", "EditorIcons"));
- //anchor_menu->add_icon_override("Align Top Left");
anchor_menu->set_icon(get_icon("Anchor", "EditorIcons"));
PopupMenu *p = anchor_menu->get_popup();
@@ -2400,14 +2346,48 @@ void CanvasItemEditor::_notification(int p_what) {
AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed", this, "_keying_changed");
_keying_changed();
- }
+ } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
- if (p_what == NOTIFICATION_READY) {
+ select_sb->set_texture(get_icon("EditorRect2D", "EditorIcons"));
- get_tree()->connect("node_removed", this, "_node_removed");
- }
+ select_button->set_icon(get_icon("ToolSelect", "EditorIcons"));
+ list_select_button->set_icon(get_icon("ListSelect", "EditorIcons"));
+ move_button->set_icon(get_icon("ToolMove", "EditorIcons"));
+ rotate_button->set_icon(get_icon("ToolRotate", "EditorIcons"));
+ pan_button->set_icon(get_icon("ToolPan", "EditorIcons"));
+ pivot_button->set_icon(get_icon("EditPivot", "EditorIcons"));
+ select_handle = get_icon("EditorHandle", "EditorIcons");
+ anchor_handle = get_icon("EditorControlAnchor", "EditorIcons");
+ lock_button->set_icon(get_icon("Lock", "EditorIcons"));
+ unlock_button->set_icon(get_icon("Unlock", "EditorIcons"));
+ group_button->set_icon(get_icon("Group", "EditorIcons"));
+ ungroup_button->set_icon(get_icon("Ungroup", "EditorIcons"));
+ key_insert_button->set_icon(get_icon("Key", "EditorIcons"));
- if (p_what == NOTIFICATION_DRAW) {
+ anchor_menu->set_icon(get_icon("Anchor", "EditorIcons"));
+ PopupMenu *p = anchor_menu->get_popup();
+ p->clear();
+
+ p->add_icon_item(get_icon("ControlAlignTopLeft", "EditorIcons"), "Top Left", ANCHOR_ALIGN_TOP_LEFT);
+ p->add_icon_item(get_icon("ControlAlignTopRight", "EditorIcons"), "Top Right", ANCHOR_ALIGN_TOP_RIGHT);
+ p->add_icon_item(get_icon("ControlAlignBottomRight", "EditorIcons"), "Bottom Right", ANCHOR_ALIGN_BOTTOM_RIGHT);
+ p->add_icon_item(get_icon("ControlAlignBottomLeft", "EditorIcons"), "Bottom Left", ANCHOR_ALIGN_BOTTOM_LEFT);
+ p->add_separator();
+ p->add_icon_item(get_icon("ControlAlignLeftCenter", "EditorIcons"), "Center Left", ANCHOR_ALIGN_CENTER_LEFT);
+ p->add_icon_item(get_icon("ControlAlignTopCenter", "EditorIcons"), "Center Top", ANCHOR_ALIGN_CENTER_TOP);
+ p->add_icon_item(get_icon("ControlAlignRightCenter", "EditorIcons"), "Center Right", ANCHOR_ALIGN_CENTER_RIGHT);
+ p->add_icon_item(get_icon("ControlAlignBottomCenter", "EditorIcons"), "Center Bottom", ANCHOR_ALIGN_CENTER_BOTTOM);
+ p->add_icon_item(get_icon("ControlAlignCenter", "EditorIcons"), "Center", ANCHOR_ALIGN_CENTER);
+ p->add_separator();
+ p->add_icon_item(get_icon("ControlAlignLeftWide", "EditorIcons"), "Left Wide", ANCHOR_ALIGN_LEFT_WIDE);
+ p->add_icon_item(get_icon("ControlAlignTopWide", "EditorIcons"), "Top Wide", ANCHOR_ALIGN_TOP_WIDE);
+ p->add_icon_item(get_icon("ControlAlignRightWide", "EditorIcons"), "Right Wide", ANCHOR_ALIGN_RIGHT_WIDE);
+ p->add_icon_item(get_icon("ControlAlignBottomWide", "EditorIcons"), "Bottom Wide", ANCHOR_ALIGN_BOTTOM_WIDE);
+ p->add_icon_item(get_icon("ControlVcenterWide", "EditorIcons"), "VCenter Wide ", ANCHOR_ALIGN_VCENTER_WIDE);
+ p->add_icon_item(get_icon("ControlHcenterWide", "EditorIcons"), "HCenter Wide ", ANCHOR_ALIGN_HCENTER_WIDE);
+ p->add_separator();
+ p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect", ANCHOR_ALIGN_WIDE);
+ p->add_icon_item(get_icon("ControlAlignWide", "EditorIcons"), "Full Rect and Fit Parent", ANCHOR_ALIGN_WIDE_FIT);
}
}
@@ -2426,7 +2406,7 @@ void CanvasItemEditor::_find_canvas_items_span(Node *p_node, Rect2 &r_rect, cons
if (!p_node)
return;
- CanvasItem *c = p_node->cast_to<CanvasItem>();
+ CanvasItem *c = Object::cast_to<CanvasItem>(p_node);
for (int i = p_node->get_child_count() - 1; i >= 0; i--) {
@@ -2587,7 +2567,7 @@ void CanvasItemEditor::_set_anchors_preset(Control::LayoutPreset p_preset) {
undo_redo->create_action(TTR("Change Anchors"));
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Control *c = E->get()->cast_to<Control>();
+ Control *c = Object::cast_to<Control>(E->get());
undo_redo->add_do_method(c, "set_anchors_preset", p_preset);
undo_redo->add_undo_method(c, "set_anchor", MARGIN_LEFT, c->get_anchor(MARGIN_LEFT));
@@ -2605,7 +2585,7 @@ void CanvasItemEditor::_set_full_rect() {
undo_redo->create_action(TTR("Change Anchors"));
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Control *c = E->get()->cast_to<Control>();
+ Control *c = Object::cast_to<Control>(E->get());
undo_redo->add_do_method(c, "set_anchors_preset", PRESET_WIDE);
undo_redo->add_do_method(c, "set_margin", MARGIN_LEFT, 0);
@@ -2713,7 +2693,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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
@@ -2731,7 +2711,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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
@@ -2751,7 +2731,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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
@@ -2769,7 +2749,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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
@@ -2783,50 +2763,6 @@ void CanvasItemEditor::_popup_callback(int p_op) {
viewport->update();
} break;
-
- case ALIGN_VERTICAL: {
-#if 0
- if ( ref_item && canvas_items.size() > 1 ) {
- Vector2 ref_pos = ref_item->get_global_transform().elements[2];
- Rect2 ref_r = ref_item->get_item_rect();
- for ( CanvasItemMap::Element *E = canvas_items.front(); E; E = E->next() ) {
- CanvasItem *it_curr = E->key();
- if ( it_curr == ref_item ) continue;
- Vector2 v = it_curr->get_global_transform().elements[2];
- Rect2 r = it_curr->get_item_rect();
- r.pos.x = ( ref_pos.x + ref_r.size.x / 2 ) - ( v.x + r.size.x / 2 );
- it_curr->edit_set_rect( r );
- }
- viewport->update();
- }
-#endif
- } break;
-
- case ALIGN_HORIZONTAL: {
-#if 0
- if ( ref_item && canvas_items.size() > 1 ) {
- Vector2 ref_pos = ref_item->get_global_transform().elements[2];
- Rect2 ref_r = ref_item->get_item_rect();
- for ( CanvasItemMap::Element *E = canvas_items.front(); E; E = E->next() ) {
- CanvasItem *it_curr = E->key();
- if ( it_curr == ref_item ) continue;
- Vector2 v = it_curr->get_global_transform().elements[2];
- Rect2 r = it_curr->get_item_rect();
- r.pos.y = ( ref_pos.y + ref_r.size.y / 2 ) - ( v.y + r.size.y / 2 );
- it_curr->edit_set_rect( r );
- }
- viewport->update();
- }
-#endif
- } break;
-
- case SPACE_HORIZONTAL: {
- //space_selected_items< proj_vector2_x, compare_items_x >();
- } break;
-
- case SPACE_VERTICAL: {
- //space_selected_items< proj_vector2_y, compare_items_y >();
- } break;
case ANCHOR_ALIGN_TOP_LEFT: {
_set_anchors_preset(PRESET_TOP_LEFT);
} break;
@@ -2888,15 +2824,15 @@ 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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
- if (canvas_item->cast_to<Node2D>()) {
- Node2D *n2d = canvas_item->cast_to<Node2D>();
+ if (Object::cast_to<Node2D>(canvas_item)) {
+ Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
if (key_pos)
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "position", n2d->get_position(), existing);
@@ -2909,7 +2845,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
//look for an IK chain
List<Node2D *> ik_chain;
- Node2D *n = n2d->get_parent_item()->cast_to<Node2D>();
+ Node2D *n = Object::cast_to<Node2D>(n2d->get_parent_item());
bool has_chain = false;
while (n) {
@@ -2922,7 +2858,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
if (!n->get_parent_item())
break;
- n = n->get_parent_item()->cast_to<Node2D>();
+ n = Object::cast_to<Node2D>(n->get_parent_item());
}
if (has_chain && ik_chain.size()) {
@@ -2939,9 +2875,9 @@ void CanvasItemEditor::_popup_callback(int p_op) {
}
}
- } else if (canvas_item->cast_to<Control>()) {
+ } else if (Object::cast_to<Control>(canvas_item)) {
- Control *ctrl = canvas_item->cast_to<Control>();
+ Control *ctrl = Object::cast_to<Control>(canvas_item);
if (key_pos)
AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect_position", ctrl->get_position(), existing);
@@ -2998,16 +2934,16 @@ 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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
- if (canvas_item->cast_to<Node2D>()) {
+ if (Object::cast_to<Node2D>(canvas_item)) {
- Node2D *n2d = canvas_item->cast_to<Node2D>();
+ Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
PoseClipboard pc;
pc.pos = n2d->get_position();
pc.rot = n2d->get_rotation();
@@ -3026,10 +2962,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
undo_redo->create_action(TTR("Paste Pose"));
for (List<PoseClipboard>::Element *E = pose_clipboard.front(); E; E = E->next()) {
- Object *o = ObjectDB::get_instance(E->get().id);
- if (!o)
- continue;
- Node2D *n2d = o->cast_to<Node2D>();
+ Node2D *n2d = Object::cast_to<Node2D>(ObjectDB::get_instance(E->get().id));
if (!n2d)
continue;
undo_redo->add_do_method(n2d, "set_position", E->get().pos);
@@ -3048,15 +2981,15 @@ 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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
- if (canvas_item->cast_to<Node2D>()) {
- Node2D *n2d = canvas_item->cast_to<Node2D>();
+ if (Object::cast_to<Node2D>(canvas_item)) {
+ Node2D *n2d = Object::cast_to<Node2D>(canvas_item);
if (key_pos)
n2d->set_position(Vector2());
@@ -3064,9 +2997,9 @@ void CanvasItemEditor::_popup_callback(int p_op) {
n2d->set_rotation(0);
if (key_scale)
n2d->set_scale(Vector2(1, 1));
- } else if (canvas_item->cast_to<Control>()) {
+ } else if (Object::cast_to<Control>(canvas_item)) {
- Control *ctrl = canvas_item->cast_to<Control>();
+ Control *ctrl = Object::cast_to<Control>(canvas_item);
if (key_pos)
ctrl->set_position(Point2());
@@ -3090,7 +3023,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- Node2D *n2d = E->key()->cast_to<Node2D>();
+ Node2D *n2d = Object::cast_to<Node2D>(E->key());
if (!n2d)
continue;
if (!n2d->is_visible_in_tree())
@@ -3111,7 +3044,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- Node2D *n2d = E->key()->cast_to<Node2D>();
+ Node2D *n2d = Object::cast_to<Node2D>(E->key());
if (!n2d)
continue;
if (!n2d->is_visible_in_tree())
@@ -3130,7 +3063,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>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->get());
if (!canvas_item || !canvas_item->is_visible_in_tree())
continue;
@@ -3151,7 +3084,7 @@ void CanvasItemEditor::_popup_callback(int p_op) {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *n2d = E->key()->cast_to<CanvasItem>();
+ CanvasItem *n2d = Object::cast_to<CanvasItem>(E->key());
if (!n2d)
continue;
if (!n2d->is_visible_in_tree())
@@ -3166,34 +3099,6 @@ void CanvasItemEditor::_popup_callback(int p_op) {
} break;
}
}
-#if 0
-template< class P, class C > void CanvasItemEditor::space_selected_items() {
- P p;
- if ( canvas_items.size() > 2 ) {
- Vector< CanvasItem * > items;
- for ( CanvasItemMap::Element *E = canvas_items.front(); E; E = E->next() ) {
- CanvasItem *it_curr = E->key();
- items.push_back( it_curr );
- }
- items.sort_custom< C >();
-
- float width_s = p.get( items[0]->get_item_rect().size );
- float width_e = p.get( items[ items.size() - 1 ]->get_item_rect().size );
- float start_x = p.get( items[0]->get_global_transform().elements[2] ) + ( width_s / 2 );
- float end_x = p.get( items[ items.size() - 1 ]->get_global_transform().elements[2] ) + ( width_e / 2 );
- float sp = ( end_x - start_x ) / ( items.size() - 1 );
-
- for ( int i = 0; i < items.size(); i++ ) {
- CanvasItem *it_curr = items[i];
- Vector2 v = it_curr->get_global_transform().elements[2];
- Rect2 r = it_curr->get_item_rect();
- p.set( r.pos, ( start_x + sp * i ) - ( p.get( v ) + p.get( r.size ) / 2 ) );
- it_curr->edit_set_rect( r );
- }
- viewport->update();
- }
-}
-#endif
void CanvasItemEditor::_focus_selection(int p_op) {
Vector2 center(0.f, 0.f);
@@ -3202,7 +3107,7 @@ void CanvasItemEditor::_focus_selection(int p_op) {
Map<Node *, Object *> &selection = editor_selection->get_selection();
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- CanvasItem *canvas_item = E->key()->cast_to<CanvasItem>();
+ CanvasItem *canvas_item = Object::cast_to<CanvasItem>(E->key());
if (!canvas_item) continue;
if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root())
continue;
@@ -3250,10 +3155,8 @@ void CanvasItemEditor::_focus_selection(int p_op) {
void CanvasItemEditor::_bind_methods() {
- ClassDB::bind_method("_node_removed", &CanvasItemEditor::_node_removed);
ClassDB::bind_method("_update_scroll", &CanvasItemEditor::_update_scroll);
ClassDB::bind_method("_popup_callback", &CanvasItemEditor::_popup_callback);
- ClassDB::bind_method("_visibility_changed", &CanvasItemEditor::_visibility_changed);
ClassDB::bind_method("_dialog_value_changed", &CanvasItemEditor::_dialog_value_changed);
ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data);
ClassDB::bind_method("_tool_select", &CanvasItemEditor::_tool_select);
@@ -3269,74 +3172,6 @@ void CanvasItemEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_group_status_changed"));
}
-#if 0
-void CanvasItemEditor::end_drag() {
- print_line( "end drag" );
-
- if (undo_redo) {
-
- undo_redo->create_action("Edit CanvasItem");
- for(CanvasItemMap::Element *E=canvas_items.front();E;E=E->next()) {
- CanvasItem *canvas_item = E->key();
- Variant state=canvas_item->edit_get_state();
- undo_redo->add_do_method(canvas_item,"edit_set_state",state);
- undo_redo->add_undo_method(canvas_item,"edit_set_state",E->get().undo_state);
- }
- undo_redo->commit_action();
- }
-
- drag=DRAG_NONE;
- viewport->update();
-}
-
-void CanvasItemEditor::box_selection_start( Point2 &click ) {
- print_line( "box selection start" );
-
- drag_from=transform.affine_inverse().xform(click);
-
- box_selecting=true;
- box_selecting_to=drag_from;
- viewport->update();
-}
-
-bool CanvasItemEditor::box_selection_end() {
- print_line( "box selection end" );
-
- Node* scene = get_scene()->get_root_node()->cast_to<EditorNode>()->get_edited_scene();
- if (scene) {
-
- List<CanvasItem*> selitems;
-
- Point2 bsfrom = transform.xform(drag_from);
- Point2 bsto= transform.xform(box_selecting_to);
- if (bsfrom.x>bsto.x)
- SWAP(bsfrom.x,bsto.x);
- if (bsfrom.y>bsto.y)
- SWAP(bsfrom.y,bsto.y);
-
- if ( bsfrom.distance_to( bsto ) < 3 ) {
- print_line( "box selection too small" );
- box_selecting=false;
- viewport->update();
- return false;
- }
-
- _find_canvas_items_at_rect(Rect2(bsfrom,bsto-bsfrom),scene,transform,&selitems);
-
- for(List<CanvasItem*>::Element *E=selitems.front();E;E=E->next()) {
-
- _append_canvas_item(E->get());
- }
-
- }
-
- box_selecting=false;
- viewport->update();
-
- return true;
-}
-#endif
-
void CanvasItemEditor::add_control_to_menu_panel(Control *p_control) {
hb->add_child(p_control);
@@ -3507,12 +3342,6 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
skeleton_menu->set_hide_on_checkable_item_selection(false);
skeleton_menu->connect("id_pressed", this, "_popup_callback");
- /*
- p->add_item("Align Horizontal",ALIGN_HORIZONTAL);
- p->add_item("Align Vertical",ALIGN_VERTICAL);
- p->add_item("Space Horizontal",SPACE_HORIZONTAL);
- p->add_item("Space Vertical",SPACE_VERTICAL);*/
-
view_menu = memnew(MenuButton);
view_menu->set_text(TTR("View"));
hb->add_child(view_menu);
@@ -3651,7 +3480,7 @@ CanvasItemEditor *CanvasItemEditor::singleton = NULL;
void CanvasItemEditorPlugin::edit(Object *p_object) {
canvas_item_editor->set_undo_redo(&get_undo_redo());
- canvas_item_editor->edit(p_object->cast_to<CanvasItem>());
+ canvas_item_editor->edit(Object::cast_to<CanvasItem>(p_object));
}
bool CanvasItemEditorPlugin::handles(Object *p_object) const {
@@ -3704,7 +3533,7 @@ void CanvasItemEditorViewport::_on_mouse_exit() {
}
void CanvasItemEditorViewport::_on_select_type(Object *selected) {
- CheckBox *check = selected->cast_to<CheckBox>();
+ CheckBox *check = Object::cast_to<CheckBox>(selected);
String type = check->get_text();
selector_label->set_text(vformat(TTR("Add %s"), type));
label->set_text(vformat(TTR("Adding %s..."), type));
@@ -3714,7 +3543,7 @@ void CanvasItemEditorViewport::_on_change_type() {
if (!button_group->get_pressed_button())
return;
- CheckBox *check = button_group->get_pressed_button()->cast_to<CheckBox>();
+ CheckBox *check = Object::cast_to<CheckBox>(button_group->get_pressed_button());
default_type = check->get_text();
_perform_drop_data();
selector->hide();
@@ -3726,8 +3555,8 @@ void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) cons
for (int i = 0; i < files.size(); i++) {
String path = files[i];
RES res = ResourceLoader::load(path);
- Ref<Texture> texture = Ref<Texture>(res->cast_to<Texture>());
- Ref<PackedScene> scene = Ref<PackedScene>(res->cast_to<PackedScene>());
+ Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(*res));
+ Ref<PackedScene> scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*res));
if (texture != NULL || scene != NULL) {
if (texture != NULL) {
Sprite *sprite = memnew(Sprite);
@@ -3778,7 +3607,7 @@ bool CanvasItemEditorViewport::_cyclical_dependency_exists(const String &p_targe
void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &path, const Point2 &p_point) {
child->set_name(path.get_file().get_basename());
- Ref<Texture> texture = Ref<Texture>(ResourceCache::get(path)->cast_to<Texture>());
+ Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(ResourceCache::get(path)));
Size2 texture_size = texture->get_size();
editor_data->get_undo_redo().add_do_method(parent, "add_child", child);
@@ -3867,11 +3696,11 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons
editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
Point2 pos;
- Node2D *parent_node2d = parent->cast_to<Node2D>();
+ Node2D *parent_node2d = Object::cast_to<Node2D>(parent);
if (parent_node2d) {
pos = parent_node2d->get_global_position();
} else {
- Control *parent_control = parent->cast_to<Control>();
+ Control *parent_control = Object::cast_to<Control>(parent);
if (parent_control) {
pos = parent_control->get_global_position();
}
@@ -3879,7 +3708,7 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons
Transform2D trans = canvas->get_canvas_transform();
Vector2 target_pos = (p_point - trans.get_origin()) / trans.get_scale().x - pos;
// in relative snapping it may be useful for the user to take the original node position into account
- Vector2 start_pos = instanced_scene->cast_to<Node2D>() ? instanced_scene->cast_to<Node2D>()->get_position() : target_pos;
+ Vector2 start_pos = Object::cast_to<Node2D>(instanced_scene) ? Object::cast_to<Node2D>(instanced_scene)->get_position() : target_pos;
target_pos = canvas->snap_point(target_pos, start_pos);
editor_data->get_undo_redo().add_do_method(instanced_scene, "set_position", target_pos);
@@ -3899,8 +3728,8 @@ void CanvasItemEditorViewport::_perform_drop_data() {
if (res.is_null()) {
continue;
}
- Ref<Texture> texture = Ref<Texture>(res->cast_to<Texture>());
- Ref<PackedScene> scene = Ref<PackedScene>(res->cast_to<PackedScene>());
+ Ref<Texture> texture = Ref<Texture>(Object::cast_to<Texture>(*res));
+ Ref<PackedScene> scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*res));
if (texture != NULL) {
Node *child;
if (default_type == "Light2D")
@@ -4016,7 +3845,7 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p
button_group->get_buttons(&btn_list);
for (int i = 0; i < btn_list.size(); i++) {
- CheckBox *check = btn_list[i]->cast_to<CheckBox>();
+ CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]);
check->set_pressed(check->get_text() == default_type);
}
selector_label->set_text(vformat(TTR("Add %s"), default_type));
@@ -4114,3 +3943,7 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte
label_desc->hide();
editor->get_gui_base()->add_child(label_desc);
}
+
+CanvasItemEditorViewport::~CanvasItemEditorViewport() {
+ memdelete(preview);
+}
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 9b027fda60..8f67d641f5 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -94,8 +94,6 @@ class CanvasItemEditor : public VBoxContainer {
UNLOCK_SELECTED,
GROUP_SELECTED,
UNGROUP_SELECTED,
- ALIGN_HORIZONTAL,
- ALIGN_VERTICAL,
ANCHOR_ALIGN_TOP_LEFT,
ANCHOR_ALIGN_TOP_RIGHT,
ANCHOR_ALIGN_BOTTOM_LEFT,
@@ -113,9 +111,6 @@ class CanvasItemEditor : public VBoxContainer {
ANCHOR_ALIGN_HCENTER_WIDE,
ANCHOR_ALIGN_WIDE,
ANCHOR_ALIGN_WIDE_FIT,
-
- SPACE_HORIZONTAL,
- SPACE_VERTICAL,
ANIM_INSERT_KEY,
ANIM_INSERT_KEY_EXISTING,
ANIM_INSERT_POS,
@@ -289,20 +284,7 @@ class CanvasItemEditor : public VBoxContainer {
bool updating_value_dialog;
Point2 display_rotate_from;
Point2 display_rotate_to;
-#if 0
- struct EditInfo {
-
- Variant undo_state;
- Matrix32 prev_xform;
- float prev_rot;
- Rect2 prev_rect;
- EditInfo() { prev_rot=0; }
- };
-
- typedef Map<CanvasItem*,EditInfo> CanvasItemMap;
- CanvasItemMap canvas_items;
-#endif
Ref<StyleBoxTexture> select_sb;
Ref<Texture> select_handle;
Ref<Texture> anchor_handle;
@@ -327,7 +309,6 @@ class CanvasItemEditor : public VBoxContainer {
void _add_canvas_item(CanvasItem *p_canvas_item);
void _remove_canvas_item(CanvasItem *p_canvas_item);
void _clear_canvas_items();
- void _visibility_changed(ObjectID p_canvas_item);
void _key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode);
void _list_select(const Ref<InputEventMouseButton> &b);
@@ -384,7 +365,6 @@ class CanvasItemEditor : public VBoxContainer {
protected:
void _notification(int p_what);
- void _node_removed(Node *p_node);
static void _bind_methods();
void end_drag();
void box_selection_start(Point2 &click);
@@ -436,7 +416,6 @@ public:
Control *get_viewport_control() { return viewport; }
- bool get_remove_list(List<Node *> *p_list);
void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
void edit(CanvasItem *p_canvas_item);
@@ -458,7 +437,6 @@ public:
virtual void edit(Object *p_object);
virtual bool handles(Object *p_object) const;
virtual void make_visible(bool p_visible);
- virtual bool get_remove_list(List<Node *> *p_list) { return canvas_item_editor->get_remove_list(p_list); }
virtual Dictionary get_state() const;
virtual void set_state(const Dictionary &p_state);
@@ -512,6 +490,7 @@ public:
virtual void drop_data(const Point2 &p_point, const Variant &p_data);
CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas);
+ ~CanvasItemEditorViewport();
};
#endif
diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/editor/plugins/collision_polygon_2d_editor_plugin.cpp
index 346c00df64..38f95d8278 100644
--- a/editor/plugins/collision_polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_polygon_2d_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -343,7 +343,11 @@ void CollisionPolygon2DEditor::edit(Node *p_collision_polygon) {
if (p_collision_polygon) {
- node = p_collision_polygon->cast_to<CollisionPolygon2D>();
+ node = Object::cast_to<CollisionPolygon2D>(p_collision_polygon);
+ //Enable the pencil tool if the polygon is empty
+ if (node->get_polygon().size() == 0) {
+ _menu_option(MODE_CREATE);
+ }
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();
@@ -384,18 +388,7 @@ CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) {
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);
-
-#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("id_pressed", this,"_menu_option");
-#endif
+ button_edit->set_tooltip(TTR("Edit existing polygon:\nLMB: Move Point.\nCtrl+LMB: Split Segment.\nRMB: Erase Point."));
mode = MODE_EDIT;
wip_active = false;
@@ -403,7 +396,7 @@ CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) {
void CollisionPolygon2DEditorPlugin::edit(Object *p_object) {
- collision_polygon_editor->edit(p_object->cast_to<Node>());
+ collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
}
bool CollisionPolygon2DEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.h b/editor/plugins/collision_polygon_2d_editor_plugin.h
index b2f32d8491..bc3c5a1659 100644
--- a/editor/plugins/collision_polygon_2d_editor_plugin.h
+++ b/editor/plugins/collision_polygon_2d_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp
index 5b364ed2c1..24c4813771 100644
--- a/editor/plugins/collision_polygon_editor_plugin.cpp
+++ b/editor/plugins/collision_polygon_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -48,6 +48,9 @@ void CollisionPolygonEditor::_notification(int p_what) {
} break;
case NOTIFICATION_PROCESS: {
+ if (!node) {
+ return;
+ }
if (node->get_depth() != prev_depth) {
_polygon_draw();
@@ -464,7 +467,11 @@ void CollisionPolygonEditor::edit(Node *p_collision_polygon) {
if (p_collision_polygon) {
- node = p_collision_polygon->cast_to<CollisionPolygon>();
+ node = Object::cast_to<CollisionPolygon>(p_collision_polygon);
+ //Enable the pencil tool if the polygon is empty
+ if (node->get_polygon().size() == 0) {
+ _menu_option(MODE_CREATE);
+ }
wip.clear();
wip_active = false;
edited_point = -1;
@@ -507,17 +514,6 @@ CollisionPolygonEditor::CollisionPolygonEditor(EditorNode *p_editor) {
button_edit->connect("pressed", this, "_menu_option", varray(MODE_EDIT));
button_edit->set_toggle_mode(true);
-//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("id_pressed", this,"_menu_option");
-#endif
-
mode = MODE_EDIT;
wip_active = false;
imgeom = memnew(ImmediateGeometry);
@@ -555,7 +551,7 @@ CollisionPolygonEditor::~CollisionPolygonEditor() {
void CollisionPolygonEditorPlugin::edit(Object *p_object) {
- collision_polygon_editor->edit(p_object->cast_to<Node>());
+ collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
}
bool CollisionPolygonEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/collision_polygon_editor_plugin.h b/editor/plugins/collision_polygon_editor_plugin.h
index 9f8b52d7f2..0150d8a9d7 100644
--- a/editor/plugins/collision_polygon_editor_plugin.h
+++ b/editor/plugins/collision_polygon_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp
index fb2aa16383..3e6165e552 100644
--- a/editor/plugins/collision_shape_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -393,21 +393,21 @@ void CollisionShape2DEditor::_get_current_shape_type() {
return;
}
- if (s->cast_to<CapsuleShape2D>()) {
+ if (Object::cast_to<CapsuleShape2D>(*s)) {
shape_type = CAPSULE_SHAPE;
- } else if (s->cast_to<CircleShape2D>()) {
+ } else if (Object::cast_to<CircleShape2D>(*s)) {
shape_type = CIRCLE_SHAPE;
- } else if (s->cast_to<ConcavePolygonShape2D>()) {
+ } else if (Object::cast_to<ConcavePolygonShape2D>(*s)) {
shape_type = CONCAVE_POLYGON_SHAPE;
- } else if (s->cast_to<ConvexPolygonShape2D>()) {
+ } else if (Object::cast_to<ConvexPolygonShape2D>(*s)) {
shape_type = CONVEX_POLYGON_SHAPE;
- } else if (s->cast_to<LineShape2D>()) {
+ } else if (Object::cast_to<LineShape2D>(*s)) {
shape_type = LINE_SHAPE;
- } else if (s->cast_to<RayShape2D>()) {
+ } else if (Object::cast_to<RayShape2D>(*s)) {
shape_type = RAY_SHAPE;
- } else if (s->cast_to<RectangleShape2D>()) {
+ } else if (Object::cast_to<RectangleShape2D>(*s)) {
shape_type = RECTANGLE_SHAPE;
- } else if (s->cast_to<SegmentShape2D>()) {
+ } else if (Object::cast_to<SegmentShape2D>(*s)) {
shape_type = SEGMENT_SHAPE;
} else {
shape_type = -1;
@@ -530,7 +530,7 @@ void CollisionShape2DEditor::edit(Node *p_node) {
}
if (p_node) {
- node = p_node->cast_to<CollisionShape2D>();
+ node = Object::cast_to<CollisionShape2D>(p_node);
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
@@ -570,7 +570,7 @@ CollisionShape2DEditor::CollisionShape2DEditor(EditorNode *p_editor) {
void CollisionShape2DEditorPlugin::edit(Object *p_obj) {
- collision_shape_2d_editor->edit(p_obj->cast_to<Node>());
+ collision_shape_2d_editor->edit(Object::cast_to<Node>(p_obj));
}
bool CollisionShape2DEditorPlugin::handles(Object *p_obj) const {
diff --git a/editor/plugins/collision_shape_2d_editor_plugin.h b/editor/plugins/collision_shape_2d_editor_plugin.h
index 09aefc65c0..ffa91952e0 100644
--- a/editor/plugins/collision_shape_2d_editor_plugin.h
+++ b/editor/plugins/collision_shape_2d_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/cube_grid_theme_editor_plugin.cpp b/editor/plugins/cube_grid_theme_editor_plugin.cpp
index b26b2aec4f..08b38c2ca2 100644
--- a/editor/plugins/cube_grid_theme_editor_plugin.cpp
+++ b/editor/plugins/cube_grid_theme_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -72,10 +72,10 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
Node *child = p_scene->get_child(i);
- if (!child->cast_to<MeshInstance>()) {
+ if (!Object::cast_to<MeshInstance>(child)) {
if (child->get_child_count() > 0) {
child = child->get_child(0);
- if (!child->cast_to<MeshInstance>()) {
+ if (!Object::cast_to<MeshInstance>(child)) {
continue;
}
@@ -83,7 +83,7 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
continue;
}
- MeshInstance *mi = child->cast_to<MeshInstance>();
+ MeshInstance *mi = Object::cast_to<MeshInstance>(child);
Ref<Mesh> mesh = mi->get_mesh();
if (mesh.is_null())
continue;
@@ -98,15 +98,15 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
p_library->set_item_mesh(id, mesh);
- Ref<Shape> collision;
+ Vector<MeshLibrary::ShapeData> collisions;
for (int j = 0; j < mi->get_child_count(); j++) {
Node *child2 = mi->get_child(j);
- if (!child2->cast_to<StaticBody>())
+ if (!Object::cast_to<StaticBody>(child2))
continue;
- StaticBody *sb = child2->cast_to<StaticBody>();
+ StaticBody *sb = Object::cast_to<StaticBody>(child2);
List<uint32_t> shapes;
sb->get_shape_owners(&shapes);
@@ -119,30 +119,25 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
for (int k = 0; k < sb->shape_owner_get_shape_count(E->get()); k++) {
- collision = sb->shape_owner_get_shape(E->get(), k);
+ Ref<Shape> collision = sb->shape_owner_get_shape(E->get(), k);
if (collision.is_valid())
- break;
- /* TileSet::ShapeData shape_data;
- shape_data.shape = shape;
- shape_data.shape_transform = shape_transform;
- shape_data.one_way_collision = one_way;
- collisions.push_back(shape_data);*/
+ continue;
+ MeshLibrary::ShapeData shape_data;
+ shape_data.shape = collision;
+ shape_data.local_transform = sb->shape_owner_get_transform(E->get());
+ collisions.push_back(shape_data);
}
- if (collision.is_valid())
- break;
}
}
- if (!collision.is_null()) {
+ p_library->set_item_shapes(id, collisions);
- p_library->set_item_shape(id, collision);
- }
Ref<NavigationMesh> navmesh;
for (int j = 0; j < mi->get_child_count(); j++) {
Node *child2 = mi->get_child(j);
- if (!child2->cast_to<NavigationMeshInstance>())
+ if (!Object::cast_to<NavigationMeshInstance>(child2))
continue;
- NavigationMeshInstance *sb = child2->cast_to<NavigationMeshInstance>();
+ NavigationMeshInstance *sb = Object::cast_to<NavigationMeshInstance>(child2);
navmesh = sb->get_navigation_mesh();
if (!navmesh.is_null())
break;
@@ -155,91 +150,17 @@ void MeshLibraryEditor::_import_scene(Node *p_scene, Ref<MeshLibrary> p_library,
//generate previews!
if (1) {
- Vector<int> ids = p_library->get_item_list();
- RID vp = VS::get_singleton()->viewport_create();
- int size = EditorSettings::get_singleton()->get("editors/grid_map/preview_size");
-
- RID scenario = VS::get_singleton()->scenario_create();
-
- RID viewport = VS::get_singleton()->viewport_create();
- VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ALWAYS);
- VS::get_singleton()->viewport_set_vflip(viewport, true);
- VS::get_singleton()->viewport_set_scenario(viewport, scenario);
- VS::get_singleton()->viewport_set_size(viewport, size, size);
- VS::get_singleton()->viewport_set_transparent_background(viewport, true);
- VS::get_singleton()->viewport_set_active(viewport, true);
- RID viewport_texture = VS::get_singleton()->viewport_get_texture(viewport);
-
- RID camera = VS::get_singleton()->camera_create();
- VS::get_singleton()->viewport_attach_camera(viewport, camera);
- VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3)));
- //VS::get_singleton()->camera_set_perspective(camera,45,0.1,10);
- VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0);
-
- RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL);
- RID light_instance = VS::get_singleton()->instance_create2(light, scenario);
- VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0)));
-
- RID light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL);
- VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7));
- //VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0));
- RID light_instance2 = VS::get_singleton()->instance_create2(light2, scenario);
-
- VS::get_singleton()->instance_set_transform(light_instance2, Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1)));
-
- //sphere = VS::get_singleton()->mesh_create();
- RID mesh_instance = VS::get_singleton()->instance_create();
- VS::get_singleton()->instance_set_scenario(mesh_instance, scenario);
-
- EditorProgress ep("mlib", TTR("Creating Mesh Library"), ids.size());
+ Vector<Ref<Mesh> > meshes;
+ Vector<int> ids = p_library->get_item_list();
for (int i = 0; i < ids.size(); i++) {
-
- int id = ids[i];
- Ref<Mesh> mesh = p_library->get_item_mesh(id);
- if (!mesh.is_valid())
- continue;
- Rect3 aabb = mesh->get_aabb();
- print_line("aabb: " + aabb);
- Vector3 ofs = aabb.position + aabb.size * 0.5;
- aabb.position -= ofs;
- Transform xform;
- xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.25);
- xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.25) * xform.basis;
- Rect3 rot_aabb = xform.xform(aabb);
- print_line("rot_aabb: " + rot_aabb);
- float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5;
- if (m == 0)
- continue;
- m = 1.0 / m;
- m *= 0.5;
- print_line("scale: " + rtos(m));
- xform.basis.scale(Vector3(m, m, m));
- xform.origin = -xform.basis.xform(ofs); //-ofs*m;
- xform.origin.z -= rot_aabb.size.z * 2;
- RID inst = VS::get_singleton()->instance_create2(mesh->get_rid(), scenario);
- VS::get_singleton()->instance_set_transform(inst, xform);
- ep.step(TTR("Thumbnail.."), i);
- Main::iteration();
- Main::iteration();
- Ref<Image> img = VS::get_singleton()->texture_get_data(viewport_texture);
- ERR_CONTINUE(!img.is_valid() || img->empty());
- Ref<ImageTexture> it(memnew(ImageTexture));
- it->create_from_image(img);
- p_library->set_item_preview(id, it);
-
- //print_line("loaded image, size: "+rtos(m)+" dist: "+rtos(dist)+" empty?"+itos(img.empty())+" w: "+itos(it->get_width())+" h: "+itos(it->get_height()));
- VS::get_singleton()->free(inst);
+ meshes.push_back(p_library->get_item_mesh(ids[i]));
}
- VS::get_singleton()->free(mesh_instance);
- VS::get_singleton()->free(viewport);
- VS::get_singleton()->free(light);
- VS::get_singleton()->free(light_instance);
- VS::get_singleton()->free(light2);
- VS::get_singleton()->free(light_instance2);
- VS::get_singleton()->free(camera);
- VS::get_singleton()->free(scenario);
+ Vector<Ref<Texture> > textures = EditorInterface::get_singleton()->make_mesh_previews(meshes, EditorSettings::get_singleton()->get("editors/grid_map/preview_size"));
+ for (int i = 0; i < ids.size(); i++) {
+ p_library->set_item_preview(ids[i], textures[i]);
+ }
}
}
@@ -341,8 +262,8 @@ MeshLibraryEditor::MeshLibraryEditor(EditorNode *p_editor) {
void MeshLibraryEditorPlugin::edit(Object *p_node) {
- if (p_node && p_node->cast_to<MeshLibrary>()) {
- theme_editor->edit(p_node->cast_to<MeshLibrary>());
+ if (Object::cast_to<MeshLibrary>(p_node)) {
+ theme_editor->edit(Object::cast_to<MeshLibrary>(p_node));
theme_editor->show();
} else
theme_editor->hide();
@@ -368,7 +289,6 @@ MeshLibraryEditorPlugin::MeshLibraryEditorPlugin(EditorNode *p_node) {
p_node->get_viewport()->add_child(theme_editor);
theme_editor->set_area_as_parent_rect();
- theme_editor->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
theme_editor->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_BEGIN);
theme_editor->set_end(Point2(0, 22));
theme_editor->hide();
diff --git a/editor/plugins/cube_grid_theme_editor_plugin.h b/editor/plugins/cube_grid_theme_editor_plugin.h
index 6fe5fc4235..b5fa18a4ad 100644
--- a/editor/plugins/cube_grid_theme_editor_plugin.h
+++ b/editor/plugins/cube_grid_theme_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp
index 2d05c8eba1..615cf85aa4 100644
--- a/editor/plugins/curve_editor_plugin.cpp
+++ b/editor/plugins/curve_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -775,7 +775,7 @@ CurveEditorPlugin::CurveEditorPlugin(EditorNode *p_node) {
_toggle_button = _editor_node->add_bottom_panel_item(get_name(), _view);
_toggle_button->hide();
- get_resource_previewer()->add_preview_generator(memnew(CurvePreviewGenerator));
+ get_editor_interface()->get_resource_previewer()->add_preview_generator(memnew(CurvePreviewGenerator));
}
CurveEditorPlugin::~CurveEditorPlugin() {
@@ -786,24 +786,24 @@ void CurveEditorPlugin::edit(Object *p_object) {
Ref<Curve> curve_ref;
if (_current_ref.is_valid()) {
- CurveTexture *ct = _current_ref->cast_to<CurveTexture>();
+ CurveTexture *ct = Object::cast_to<CurveTexture>(*_current_ref);
if (ct)
ct->disconnect(CoreStringNames::get_singleton()->changed, this, "_curve_texture_changed");
}
if (p_object) {
- Resource *res = p_object->cast_to<Resource>();
+ Resource *res = Object::cast_to<Resource>(p_object);
ERR_FAIL_COND(res == NULL);
ERR_FAIL_COND(!handles(p_object));
- _current_ref = Ref<Resource>(p_object->cast_to<Resource>());
+ _current_ref = Ref<Resource>(Object::cast_to<Resource>(p_object));
if (_current_ref.is_valid()) {
- Curve *curve = _current_ref->cast_to<Curve>();
+ Curve *curve = Object::cast_to<Curve>(*_current_ref);
if (curve)
curve_ref = Ref<Curve>(curve);
else {
- CurveTexture *ct = _current_ref->cast_to<CurveTexture>();
+ CurveTexture *ct = Object::cast_to<CurveTexture>(*_current_ref);
if (ct) {
ct->connect(CoreStringNames::get_singleton()->changed, this, "_curve_texture_changed");
curve_ref = ct->get_curve();
@@ -820,7 +820,7 @@ void CurveEditorPlugin::edit(Object *p_object) {
bool CurveEditorPlugin::handles(Object *p_object) const {
// Both handled so that we can keep the curve editor open
- return p_object->cast_to<Curve>() || p_object->cast_to<CurveTexture>();
+ return Object::cast_to<Curve>(p_object) || Object::cast_to<CurveTexture>(p_object);
}
void CurveEditorPlugin::make_visible(bool p_visible) {
@@ -837,7 +837,7 @@ void CurveEditorPlugin::make_visible(bool p_visible) {
void CurveEditorPlugin::_curve_texture_changed() {
// If the curve is shown indirectly as a CurveTexture is edited,
// we need to monitor when the curve property gets assigned
- CurveTexture *ct = _current_ref->cast_to<CurveTexture>();
+ CurveTexture *ct = Object::cast_to<CurveTexture>(*_current_ref);
if (ct) {
_view->set_curve(ct->get_curve());
}
diff --git a/editor/plugins/curve_editor_plugin.h b/editor/plugins/curve_editor_plugin.h
index 040c298a92..2df9d05533 100644
--- a/editor/plugins/curve_editor_plugin.h
+++ b/editor/plugins/curve_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp
index ce6eefd694..c48a241e4d 100644
--- a/editor/plugins/editor_preview_plugins.cpp
+++ b/editor/plugins/editor_preview_plugins.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -29,14 +29,13 @@
/*************************************************************************/
#include "editor_preview_plugins.h"
+#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "io/file_access_memory.h"
#include "io/resource_loader.h"
#include "os/os.h"
-#include "scene/resources/material.h"
-//#include "scene/resources/sample.h"
-#include "editor/editor_scale.h"
#include "scene/resources/bit_mask.h"
+#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
bool EditorTexturePreviewPlugin::handles(const String &p_type) const {
@@ -239,7 +238,6 @@ Ref<Texture> EditorMaterialPreviewPlugin::generate(const RES &p_from) {
VS::get_singleton()->mesh_surface_set_material(sphere, 0, material->get_rid());
VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
- //print_line("queue capture!");
preview_done = false;
VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant());
@@ -454,9 +452,7 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from) {
while (_is_text_char(code[pos])) {
pos++;
}
- ///print_line("from "+itos(i)+" to "+itos(pos));
String word = code.substr(i, pos - i);
- //print_line("found word: "+word);
if (keywords.has(word))
in_keyword = true;
@@ -502,6 +498,8 @@ Ref<Texture> EditorScriptPreviewPlugin::generate(const RES &p_from) {
EditorScriptPreviewPlugin::EditorScriptPreviewPlugin() {
}
///////////////////////////////////////////////////////////////////
+
+// FIXME: Needs to be rewritten for AudioStream in Godot 3.0+
#if 0
bool EditorSamplePreviewPlugin::handles(const String& p_type) const {
@@ -766,10 +764,9 @@ Ref<Texture> EditorSamplePreviewPlugin::generate(const RES& p_from) {
}
EditorSamplePreviewPlugin::EditorSamplePreviewPlugin() {
-
-
}
#endif
+
///////////////////////////////////////////////////////////////////////////
void EditorMeshPreviewPlugin::_preview_done(const Variant &p_udata) {
@@ -788,14 +785,12 @@ bool EditorMeshPreviewPlugin::handles(const String &p_type) const {
Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) {
- print_line("**Generating for mesh finally??");
Ref<Mesh> mesh = p_from;
ERR_FAIL_COND_V(mesh.is_null(), Ref<Texture>());
VS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid());
Rect3 aabb = mesh->get_aabb();
- print_line("mesh aabb: " + aabb);
Vector3 ofs = aabb.position + aabb.size * 0.5;
aabb.position -= ofs;
Transform xform;
@@ -807,14 +802,12 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) {
return Ref<Texture>();
m = 1.0 / m;
m *= 0.5;
- //print_line("scale: "+rtos(m));
xform.basis.scale(Vector3(m, m, m));
xform.origin = -xform.basis.xform(ofs); //-ofs*m;
xform.origin.z -= rot_aabb.size.z * 2;
VS::get_singleton()->instance_set_transform(mesh_instance, xform);
VS::get_singleton()->viewport_set_update_mode(viewport, VS::VIEWPORT_UPDATE_ONCE); //once used for capture
- //print_line("queue capture!");
preview_done = false;
VS::get_singleton()->request_frame_drawn_callback(this, "_preview_done", Variant());
@@ -826,7 +819,6 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) {
Ref<Image> img = VS::get_singleton()->VS::get_singleton()->texture_get_data(viewport_texture);
ERR_FAIL_COND_V(img.is_null(), Ref<ImageTexture>());
- print_line("captured! " + itos(img->get_width()) + "x" + itos(img->get_height()));
VS::get_singleton()->instance_set_base(mesh_instance, RID());
int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size");
diff --git a/editor/plugins/editor_preview_plugins.h b/editor/plugins/editor_preview_plugins.h
index 7e7d36eb1e..c422d5c686 100644
--- a/editor/plugins/editor_preview_plugins.h
+++ b/editor/plugins/editor_preview_plugins.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -97,6 +97,7 @@ public:
EditorScriptPreviewPlugin();
};
+// FIXME: Needs to be rewritten for AudioStream in Godot 3.0+
#if 0
class EditorSamplePreviewPlugin : public EditorResourcePreviewGenerator {
public:
@@ -106,8 +107,8 @@ public:
EditorSamplePreviewPlugin();
};
-
#endif
+
class EditorMeshPreviewPlugin : public EditorResourcePreviewGenerator {
GDCLASS(EditorMeshPreviewPlugin, EditorResourcePreviewGenerator)
diff --git a/editor/plugins/gi_probe_editor_plugin.cpp b/editor/plugins/gi_probe_editor_plugin.cpp
index a8f840a8b1..fcbf282758 100644
--- a/editor/plugins/gi_probe_editor_plugin.cpp
+++ b/editor/plugins/gi_probe_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -38,7 +38,7 @@ void GIProbeEditorPlugin::_bake() {
void GIProbeEditorPlugin::edit(Object *p_object) {
- GIProbe *s = p_object->cast_to<GIProbe>();
+ GIProbe *s = Object::cast_to<GIProbe>(p_object);
if (!s)
return;
diff --git a/editor/plugins/gi_probe_editor_plugin.h b/editor/plugins/gi_probe_editor_plugin.h
index e4151d4b8c..a1fecd2911 100644
--- a/editor/plugins/gi_probe_editor_plugin.h
+++ b/editor/plugins/gi_probe_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/gradient_editor_plugin.cpp b/editor/plugins/gradient_editor_plugin.cpp
index 4aaa155cfd..abd2559d1f 100644
--- a/editor/plugins/gradient_editor_plugin.cpp
+++ b/editor/plugins/gradient_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -46,7 +46,7 @@ GradientEditorPlugin::GradientEditorPlugin(EditorNode *p_node) {
void GradientEditorPlugin::edit(Object *p_object) {
- Gradient *gradient = p_object->cast_to<Gradient>();
+ Gradient *gradient = Object::cast_to<Gradient>(p_object);
if (!gradient)
return;
gradient_ref = Ref<Gradient>(gradient);
diff --git a/editor/plugins/gradient_editor_plugin.h b/editor/plugins/gradient_editor_plugin.h
index 1acf5f7e57..c169fa0947 100644
--- a/editor/plugins/gradient_editor_plugin.h
+++ b/editor/plugins/gradient_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/item_list_editor_plugin.cpp b/editor/plugins/item_list_editor_plugin.cpp
index f567abc5b1..aeb6e5c302 100644
--- a/editor/plugins/item_list_editor_plugin.cpp
+++ b/editor/plugins/item_list_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -115,7 +115,7 @@ void ItemListPlugin::_get_property_list(List<PropertyInfo> *p_list) const {
void ItemListOptionButtonPlugin::set_object(Object *p_object) {
- ob = p_object->cast_to<OptionButton>();
+ ob = Object::cast_to<OptionButton>(p_object);
}
bool ItemListOptionButtonPlugin::handles(Object *p_object) const {
@@ -155,9 +155,9 @@ ItemListOptionButtonPlugin::ItemListOptionButtonPlugin() {
void ItemListPopupMenuPlugin::set_object(Object *p_object) {
if (p_object->is_class("MenuButton"))
- pp = p_object->cast_to<MenuButton>()->get_popup();
+ pp = Object::cast_to<MenuButton>(p_object)->get_popup();
else
- pp = p_object->cast_to<PopupMenu>();
+ pp = Object::cast_to<PopupMenu>(p_object);
}
bool ItemListPopupMenuPlugin::handles(Object *p_object) const {
@@ -196,7 +196,7 @@ ItemListPopupMenuPlugin::ItemListPopupMenuPlugin() {
void ItemListItemListPlugin::set_object(Object *p_object) {
- pp = p_object->cast_to<ItemList>();
+ pp = Object::cast_to<ItemList>(p_object);
}
bool ItemListItemListPlugin::handles(Object *p_object) const {
@@ -384,7 +384,7 @@ ItemListEditor::~ItemListEditor() {
void ItemListEditorPlugin::edit(Object *p_object) {
- item_list_editor->edit(p_object->cast_to<Node>());
+ item_list_editor->edit(Object::cast_to<Node>(p_object));
}
bool ItemListEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h
index 3bfe2c88e0..808f308c0c 100644
--- a/editor/plugins/item_list_editor_plugin.h
+++ b/editor/plugins/item_list_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp
index a7a20e71fe..e6b921c539 100644
--- a/editor/plugins/light_occluder_2d_editor_plugin.cpp
+++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -106,7 +106,7 @@ bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (node->get_occluder_polygon().is_null()) {
Ref<InputEventMouseButton> mb = p_event;
if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
- create_poly->set_text("No OccluderPolygon2D resource on this node.\nCreate and assign one?");
+ create_poly->set_text(TTR("No OccluderPolygon2D resource on this node.\nCreate and assign one?"));
create_poly->popup_centered_minsize();
}
return (mb.is_valid() && mb->get_button_index() == 1);
@@ -367,7 +367,7 @@ void LightOccluder2DEditor::edit(Node *p_collision_polygon) {
if (p_collision_polygon) {
- node = p_collision_polygon->cast_to<LightOccluder2D>();
+ node = Object::cast_to<LightOccluder2D>(p_collision_polygon);
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();
@@ -424,24 +424,13 @@ LightOccluder2DEditor::LightOccluder2DEditor(EditorNode *p_editor) {
add_child(create_poly);
create_poly->get_ok()->set_text(TTR("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("id_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>());
+ collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
}
bool LightOccluder2DEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/light_occluder_2d_editor_plugin.h b/editor/plugins/light_occluder_2d_editor_plugin.h
index 435d650a69..7a4f18963d 100644
--- a/editor/plugins/light_occluder_2d_editor_plugin.h
+++ b/editor/plugins/light_occluder_2d_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/line_2d_editor_plugin.cpp b/editor/plugins/line_2d_editor_plugin.cpp
index 41327fb07e..a5f854e1b1 100644
--- a/editor/plugins/line_2d_editor_plugin.cpp
+++ b/editor/plugins/line_2d_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -189,7 +189,7 @@ void Line2DEditor::edit(Node *p_line2d) {
canvas_item_editor = CanvasItemEditor::get_singleton();
if (p_line2d) {
- node = p_line2d->cast_to<Line2D>();
+ node = Object::cast_to<Line2D>(p_line2d);
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
if (!node->is_connected("visibility_changed", this, "_node_visibility_changed"))
@@ -276,7 +276,7 @@ Line2DEditor::Line2DEditor(EditorNode *p_editor) {
//----------------------------------------------------------------------------
void Line2DEditorPlugin::edit(Object *p_object) {
- line2d_editor->edit(p_object->cast_to<Node>());
+ line2d_editor->edit(Object::cast_to<Node>(p_object));
}
bool Line2DEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/line_2d_editor_plugin.h b/editor/plugins/line_2d_editor_plugin.h
index f2979e4330..dea77ec248 100644
--- a/editor/plugins/line_2d_editor_plugin.h
+++ b/editor/plugins/line_2d_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp
index 179ef27eda..d2767bf1b2 100644
--- a/editor/plugins/material_editor_plugin.cpp
+++ b/editor/plugins/material_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -27,12 +27,14 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
+// FIXME: Disabled as (according to reduz) users were complaining that it gets in the way
+// Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored.
+#if 0
#include "material_editor_plugin.h"
#include "scene/main/viewport.h"
-#if 0
-
void MaterialEditor::_gui_input(InputEvent p_event) {
@@ -372,7 +374,7 @@ MaterialEditor::MaterialEditor() {
void MaterialEditorPlugin::edit(Object *p_object) {
- Material * s = p_object->cast_to<Material>();
+ Material * s = Object::cast_to<Material>(p_object);
if (!s)
return;
diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h
index a0a91f53a6..10d7997a52 100644
--- a/editor/plugins/material_editor_plugin.h
+++ b/editor/plugins/material_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -30,6 +30,10 @@
#ifndef MATERIAL_EDITOR_PLUGIN_H
#define MATERIAL_EDITOR_PLUGIN_H
+// FIXME: Disabled as (according to reduz) users were complaining that it gets in the way
+// Waiting for PropertyEditor rewrite (planned for 3.1) to be refactored.
+#if 0
+
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "scene/3d/camera.h"
@@ -37,7 +41,6 @@
#include "scene/3d/mesh_instance.h"
#include "scene/resources/material.h"
-#if 0
class MaterialEditor : public Control {
GDCLASS(MaterialEditor, Control);
@@ -97,5 +100,5 @@ public:
};
-#endif // MATERIAL_EDITOR_PLUGIN_H
#endif
+#endif // MATERIAL_EDITOR_PLUGIN_H
diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp
index 23b19e61b9..a77f022347 100644
--- a/editor/plugins/mesh_editor_plugin.cpp
+++ b/editor/plugins/mesh_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -187,7 +187,7 @@ MeshEditor::MeshEditor() {
void MeshEditorPlugin::edit(Object *p_object) {
- Mesh *s = p_object->cast_to<Mesh>();
+ Mesh *s = Object::cast_to<Mesh>(p_object);
if (!s)
return;
diff --git a/editor/plugins/mesh_editor_plugin.h b/editor/plugins/mesh_editor_plugin.h
index 305d24ba07..8ae20a5434 100644
--- a/editor/plugins/mesh_editor_plugin.h
+++ b/editor/plugins/mesh_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/mesh_instance_editor_plugin.cpp b/editor/plugins/mesh_instance_editor_plugin.cpp
index 49498d0fa0..84fc0cecf2 100644
--- a/editor/plugins/mesh_instance_editor_plugin.cpp
+++ b/editor/plugins/mesh_instance_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -101,7 +101,7 @@ void MeshInstanceEditor::_menu_option(int p_option) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- MeshInstance *instance = E->get()->cast_to<MeshInstance>();
+ MeshInstance *instance = Object::cast_to<MeshInstance>(E->get());
if (!instance)
continue;
@@ -290,7 +290,7 @@ MeshInstanceEditor::MeshInstanceEditor() {
void MeshInstanceEditorPlugin::edit(Object *p_object) {
- mesh_editor->edit(p_object->cast_to<MeshInstance>());
+ mesh_editor->edit(Object::cast_to<MeshInstance>(p_object));
}
bool MeshInstanceEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/mesh_instance_editor_plugin.h b/editor/plugins/mesh_instance_editor_plugin.h
index 614dcac0b9..fa851458ce 100644
--- a/editor/plugins/mesh_instance_editor_plugin.h
+++ b/editor/plugins/mesh_instance_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp
index a9689cce56..79345754b6 100644
--- a/editor/plugins/multimesh_editor_plugin.cpp
+++ b/editor/plugins/multimesh_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -77,7 +77,7 @@ void MultiMeshEditor::_populate() {
return;
}
- MeshInstance *ms_instance = ms_node->cast_to<MeshInstance>();
+ MeshInstance *ms_instance = Object::cast_to<MeshInstance>(ms_node);
if (!ms_instance) {
@@ -112,7 +112,7 @@ void MultiMeshEditor::_populate() {
return;
}
- GeometryInstance *ss_instance = ss_node->cast_to<MeshInstance>();
+ GeometryInstance *ss_instance = Object::cast_to<MeshInstance>(ss_node);
if (!ss_instance) {
@@ -144,22 +144,7 @@ void MultiMeshEditor::_populate() {
}
w = PoolVector<Face3>::Write();
-#if 0
- node->get_multimesh()->set_instance_count(populate_amount->get_val());
- node->populate_parent(populate_rotate_random->get_val(),populate_tilt_random->get_val(),populate_scale_random->get_val(),populate_scale->get_val());
-
- ERR_EXPLAIN("Parent is not of type VisualInstance.");
- ERR_FAIL_COND(!get_parent() || !get_parent()->is_type("VisualInstance"));
-
- ERR_EXPLAIN("Multimesh not present.");
- ERR_FAIL_COND(multimesh.is_null());
-
- VisualInstance *vi = get_parent()->cast_to<VisualInstance>();
- ERR_EXPLAIN("Parent is not of type VisualInstance, can't be populated.");
- ERR_FAIL_COND(!vi);
-
-#endif
PoolVector<Face3> faces = geometry;
ERR_EXPLAIN(TTR("Parent has no solid faces to populate."));
int facecount = faces.size();
@@ -402,7 +387,7 @@ MultiMeshEditor::MultiMeshEditor() {
void MultiMeshEditorPlugin::edit(Object *p_object) {
- multimesh_editor->edit(p_object->cast_to<MultiMeshInstance>());
+ multimesh_editor->edit(Object::cast_to<MultiMeshInstance>(p_object));
}
bool MultiMeshEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/multimesh_editor_plugin.h b/editor/plugins/multimesh_editor_plugin.h
index a93fa73a2e..6b44662091 100644
--- a/editor/plugins/multimesh_editor_plugin.h
+++ b/editor/plugins/multimesh_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp
index 725e57fe0b..de8d4f9618 100644
--- a/editor/plugins/navigation_polygon_editor_plugin.cpp
+++ b/editor/plugins/navigation_polygon_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -69,6 +69,7 @@ void NavigationPolygonEditor::_create_nav() {
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();
+ _menu_option(MODE_CREATE);
}
void NavigationPolygonEditor::_menu_option(int p_option) {
@@ -422,7 +423,12 @@ void NavigationPolygonEditor::edit(Node *p_collision_polygon) {
if (p_collision_polygon) {
- node = p_collision_polygon->cast_to<NavigationPolygonInstance>();
+ node = Object::cast_to<NavigationPolygonInstance>(p_collision_polygon);
+ //Enable the pencil tool if the polygon is empty
+ if (!node->get_navigation_polygon().is_null()) {
+ if (node->get_navigation_polygon()->get_polygon_count() == 0)
+ _menu_option(MODE_CREATE);
+ }
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();
@@ -468,17 +474,6 @@ NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) {
add_child(create_nav);
create_nav->get_ok()->set_text(TTR("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("id_pressed", this,"_menu_option");
-#endif
-
mode = MODE_EDIT;
wip_active = false;
edited_outline = -1;
@@ -486,7 +481,7 @@ NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) {
void NavigationPolygonEditorPlugin::edit(Object *p_object) {
- collision_polygon_editor->edit(p_object->cast_to<Node>());
+ collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
}
bool NavigationPolygonEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/navigation_polygon_editor_plugin.h b/editor/plugins/navigation_polygon_editor_plugin.h
index 6ec9b14cc1..33f9d5c785 100644
--- a/editor/plugins/navigation_polygon_editor_plugin.h
+++ b/editor/plugins/navigation_polygon_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp
index a759e5892f..5eaa248224 100644
--- a/editor/plugins/particles_2d_editor_plugin.cpp
+++ b/editor/plugins/particles_2d_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -33,13 +33,10 @@
#include "io/image_loader.h"
#include "scene/3d/particles.h"
#include "scene/gui/separator.h"
+
void Particles2DEditorPlugin::edit(Object *p_object) {
- if (p_object) {
- particles = p_object->cast_to<Particles2D>();
- } else {
- particles = NULL;
- }
+ particles = Object::cast_to<Particles2D>(p_object);
}
bool Particles2DEditorPlugin::handles(Object *p_object) const {
@@ -357,7 +354,7 @@ Particles2DEditorPlugin::Particles2DEditorPlugin(EditorNode *p_node) {
menu->get_popup()->add_separator();
menu->get_popup()->add_item(TTR("Load Emission Mask"), MENU_LOAD_EMISSION_MASK);
// menu->get_popup()->add_item(TTR("Clear Emission Mask"), MENU_CLEAR_EMISSION_MASK);
- menu->set_text("Particles");
+ menu->set_text(TTR("Particles"));
toolbar->add_child(menu);
file = memnew(EditorFileDialog);
diff --git a/editor/plugins/particles_2d_editor_plugin.h b/editor/plugins/particles_2d_editor_plugin.h
index ccfec1a25f..fd42abb6bd 100644
--- a/editor/plugins/particles_2d_editor_plugin.h
+++ b/editor/plugins/particles_2d_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp
index d918a3e24e..10834b74ff 100644
--- a/editor/plugins/particles_editor_plugin.cpp
+++ b/editor/plugins/particles_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -51,7 +51,7 @@ void ParticlesEditor::_node_selected(const NodePath &p_path) {
if (!sel)
return;
- VisualInstance *vi = sel->cast_to<VisualInstance>();
+ VisualInstance *vi = Object::cast_to<VisualInstance>(sel);
if (!vi) {
err_dialog->set_text(TTR("Node does not contain geometry."));
@@ -135,7 +135,7 @@ void ParticlesEditor::_menu_option(int p_option) {
/*
Node *root = get_scene()->get_root_node();
ERR_FAIL_COND(!root);
- EditorNode *en = root->cast_to<EditorNode>();
+ EditorNode *en = Object::cast_to<EditorNode>(root);
ERR_FAIL_COND(!en);
Node * node = en->get_edited_scene();
*/
@@ -270,9 +270,7 @@ void ParticlesEditor::_generate_emission_points() {
Vector3 dir;
dir[Math::rand() % 3] = 1.0;
- Vector3 ofs = Vector3(1, 1, 1) - dir;
- ofs = (Vector3(1, 1, 1) - dir) * Vector3(Math::randf(), Math::randf(), Math::randf()) * aabb.size;
- ofs += aabb.position;
+ Vector3 ofs = (Vector3(1, 1, 1) - dir) * Vector3(Math::randf(), Math::randf(), Math::randf()) * aabb.size + aabb.position;
Vector3 ofsv = ofs + aabb.size * dir;
@@ -391,7 +389,7 @@ ParticlesEditor::ParticlesEditor() {
particles_editor_hb->add_child(options);
particles_editor_hb->hide();
- options->set_text("Particles");
+ options->set_text(TTR("Particles"));
options->get_popup()->add_item(TTR("Generate AABB"), MENU_OPTION_GENERATE_AABB);
options->get_popup()->add_separator();
options->get_popup()->add_item(TTR("Create Emission Points From Mesh"), MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_MESH);
@@ -463,7 +461,7 @@ ParticlesEditor::ParticlesEditor() {
void ParticlesEditorPlugin::edit(Object *p_object) {
- particles_editor->edit(p_object->cast_to<Particles>());
+ particles_editor->edit(Object::cast_to<Particles>(p_object));
}
bool ParticlesEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/particles_editor_plugin.h b/editor/plugins/particles_editor_plugin.h
index a6e14266c7..2c8ce88eb2 100644
--- a/editor/plugins/particles_editor_plugin.h
+++ b/editor/plugins/particles_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp
index 3a210f3fe0..adc8d4f091 100644
--- a/editor/plugins/path_2d_editor_plugin.cpp
+++ b/editor/plugins/path_2d_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -33,6 +33,7 @@
#include "editor/editor_settings.h"
#include "os/file_access.h"
#include "os/keyboard.h"
+
void Path2DEditor::_notification(int p_what) {
switch (p_what) {
@@ -228,200 +229,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
return true;
}
-
-#if 0
- switch(mode) {
-
-
- case MODE_CREATE: {
-
- if (mb->get_button_index()==BUTTON_LEFT && mb->is_pressed()) {
-
-
- if (!wip_active) {
-
- wip.clear();
- wip.push_back( canvas_item_editor->snap_point(cpoint) );
- wip_active=true;
- edited_point_pos=canvas_item_editor->snap_point(cpoint);
- canvas_item_editor->update();
- edited_point=1;
- return true;
- } else {
- if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_threshold) {
- //wip closed
- _wip_close();
-
-
- return true;
- } else {
-
- wip.push_back( canvas_item_editor->snap_point(cpoint) );
- edited_point=wip.size();
- canvas_item_editor->update();
- return true;
-
- //add wip point
- }
- }
- } else if (mb->get_button_index()==BUTTON_RIGHT && mb->is_pressed() && wip_active) {
- _wip_close();
- }
-
- } break;
-
- case MODE_EDIT: {
-
- if (mb->get_button_index()==BUTTON_LEFT) {
- if (mb->is_pressed()) {
-
- if (mb->get_control()) {
-
-
- if (poly.size() < 3) {
-
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_undo_method(node,"set_polygon",poly);
- poly.push_back(cpoint);
- undo_redo->add_do_method(node,"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++) {
-
- if (d<closest_dist && d<grab_threshold) {
- closest_dist=d;
- closest_pos=cp;
- closest_idx=i;
- }
-
- 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_threshold) {
- closest_dist=d;
- closest_pos=cp;
- closest_idx=i;
- }
-
-
- }
-
- if (closest_idx>=0) {
-
- pre_move_edit=poly;
- poly.insert(closest_idx+1,canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos)));
- edited_point=closest_idx+1;
- edited_point_pos=canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos));
- node->set_polygon(poly);
- canvas_item_editor->update();
- return true;
- }
- } else {
-
- real_t d = cp.distance_to(gpoint);
- if (d<closest_dist && d<grab_threshold) {
- closest_dist=d;
- closest_pos=cp;
- closest_idx=i;
- }
-
- 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_threshold) {
- 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->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(TTR("Edit Poly"));
- undo_redo->add_do_method(node,"set_polygon",poly);
- undo_redo->add_undo_method(node,"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->get_button_index()==BUTTON_RIGHT && mb->is_pressed() && edited_point==-1) {
-
- real_t d = cp.distance_to(gpoint);
- if (d<closest_dist && d<grab_threshold) {
- closest_dist=d;
- closest_pos=cp;
- closest_idx=i;
- }
-
- 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_threshold) {
- closest_dist=d;
- closest_pos=cp;
- closest_idx=i;
- }
-
- }
-
- if (closest_idx>=0) {
-
-
- undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
- undo_redo->add_undo_method(node,"set_polygon",poly);
- poly.remove(closest_idx);
- undo_redo->add_do_method(node,"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;
- }
-#endif
}
Ref<InputEventMouseMotion> mm = p_event;
@@ -463,19 +270,6 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
canvas_item_editor->get_viewport_control()->update();
return true;
}
-
-#if 0
- if (edited_point!=-1 && (wip_active || mm->get_button_mask()&BUTTON_MASK_LEFT)) {
-
-
- Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
-
- Vector2 gpoint = Point2(mm.x,mm.y);
- edited_point_pos = canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint));
- canvas_item_editor->update();
-
- }
-#endif
}
return false;
@@ -534,7 +328,7 @@ void Path2DEditor::edit(Node *p_path2d) {
if (p_path2d) {
- node = p_path2d->cast_to<Path2D>();
+ node = Object::cast_to<Path2D>(p_path2d);
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
if (!node->is_connected("visibility_changed", this, "_node_visibility_changed"))
@@ -619,16 +413,7 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) {
undo_redo = editor->get_undo_redo();
mode = MODE_EDIT;
-
action = ACTION_NONE;
-#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("id_pressed", this,"_menu_option");
-#endif
base_hb = memnew(HBoxContainer);
CanvasItemEditor::get_singleton()->add_control_to_menu_panel(base_hb);
@@ -676,7 +461,7 @@ Path2DEditor::Path2DEditor(EditorNode *p_editor) {
void Path2DEditorPlugin::edit(Object *p_object) {
- path2d_editor->edit(p_object->cast_to<Node>());
+ path2d_editor->edit(Object::cast_to<Node>(p_object));
}
bool Path2DEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h
index 61ff700118..c195845244 100644
--- a/editor/plugins/path_2d_editor_plugin.h
+++ b/editor/plugins/path_2d_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp
index 96a98f3c48..d0f2b19ed3 100644
--- a/editor/plugins/path_editor_plugin.cpp
+++ b/editor/plugins/path_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -269,9 +269,9 @@ PathSpatialGizmo::PathSpatialGizmo(Path *p_path) {
Ref<SpatialEditorGizmo> PathEditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {
- if (p_spatial->cast_to<Path>()) {
+ if (Object::cast_to<Path>(p_spatial)) {
- return memnew(PathSpatialGizmo(p_spatial->cast_to<Path>()));
+ return memnew(PathSpatialGizmo(Object::cast_to<Path>(p_spatial)));
}
return Ref<SpatialEditorGizmo>();
@@ -433,7 +433,7 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<Inp
void PathEditorPlugin::edit(Object *p_object) {
if (p_object) {
- path = p_object->cast_to<Path>();
+ path = Object::cast_to<Path>(p_object);
if (path) {
if (path->get_curve().is_valid()) {
@@ -447,7 +447,7 @@ void PathEditorPlugin::edit(Object *p_object) {
pre->get_curve()->emit_signal("changed");
}
}
- //collision_polygon_editor->edit(p_object->cast_to<Node>());
+ //collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
}
bool PathEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/path_editor_plugin.h b/editor/plugins/path_editor_plugin.h
index 43df9d460f..b672e828a9 100644
--- a/editor/plugins/path_editor_plugin.h
+++ b/editor/plugins/path_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp
index 24ccdcd445..a3195c05d6 100644
--- a/editor/plugins/polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/polygon_2d_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -402,6 +402,14 @@ bool Polygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
cpoint = canvas_item_editor->snap_point(cpoint);
edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
+ if (!wip_active) {
+
+ Vector<Vector2> poly = Variant(node->get_polygon());
+ ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
+ poly[edited_point] = edited_point_pos - node->get_offset();
+ node->set_polygon(Variant(poly));
+ }
+
canvas_item_editor->get_viewport_control()->update();
}
}
@@ -425,6 +433,23 @@ void Polygon2DEditor::_canvas_draw() {
Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons");
+ if (!wip_active && edited_point >= 0 && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) {
+
+ const Color col = node->get_color().contrasted();
+ const int n = pre_move_edit.size();
+ for (int i = 0; i < n; i++) {
+
+ Vector2 p, p2;
+ p = pre_move_edit[i] + node->get_offset();
+ p2 = pre_move_edit[(i + 1) % n] + node->get_offset();
+
+ Vector2 point = xform.xform(p);
+ Vector2 next_point = xform.xform(p2);
+
+ vpc->draw_line(point, next_point, col, 2);
+ }
+ }
+
for (int i = 0; i < poly.size(); i++) {
Vector2 p, p2;
@@ -697,7 +722,11 @@ void Polygon2DEditor::edit(Node *p_collision_polygon) {
if (p_collision_polygon) {
- node = p_collision_polygon->cast_to<Polygon2D>();
+ node = Object::cast_to<Polygon2D>(p_collision_polygon);
+ //Enable the pencil tool if the polygon is empty
+ if (node->get_polygon().size() == 0) {
+ _menu_option(MODE_CREATE);
+ }
if (!canvas_item_editor->get_viewport_control()->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->get_viewport_control()->connect("draw", this, "_canvas_draw");
@@ -770,17 +799,6 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) {
add_child(button_uv);
button_uv->connect("pressed", this, "_menu_option", varray(MODE_EDIT_UV));
-//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("id_pressed", this,"_menu_option");
-#endif
-
mode = MODE_EDIT;
wip_active = false;
@@ -925,7 +943,7 @@ Polygon2DEditor::Polygon2DEditor(EditorNode *p_editor) {
void Polygon2DEditorPlugin::edit(Object *p_object) {
- collision_polygon_editor->edit(p_object->cast_to<Node>());
+ collision_polygon_editor->edit(Object::cast_to<Node>(p_object));
}
bool Polygon2DEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h
index 4fcb1d81c2..38148ca7e3 100644
--- a/editor/plugins/polygon_2d_editor_plugin.h
+++ b/editor/plugins/polygon_2d_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp
index ccefbc1843..e157ddbf90 100644
--- a/editor/plugins/resource_preloader_editor_plugin.cpp
+++ b/editor/plugins/resource_preloader_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -157,7 +157,6 @@ void ResourcePreloaderEditor::_paste_pressed() {
if (!r.is_valid()) {
dialog->set_text(TTR("Resource clipboard is empty!"));
dialog->set_title(TTR("Error!"));
- //dialog->get_cancel()->set_text("Close");
dialog->get_ok()->set_text(TTR("Close"));
dialog->popup_centered_minsize();
return; ///beh should show an error i guess
@@ -410,7 +409,7 @@ ResourcePreloaderEditor::ResourcePreloaderEditor() {
void ResourcePreloaderEditorPlugin::edit(Object *p_object) {
preloader_editor->set_undo_redo(&get_undo_redo());
- ResourcePreloader *s = p_object->cast_to<ResourcePreloader>();
+ ResourcePreloader *s = Object::cast_to<ResourcePreloader>(p_object);
if (!s)
return;
diff --git a/editor/plugins/resource_preloader_editor_plugin.h b/editor/plugins/resource_preloader_editor_plugin.h
index 6e4726748d..46539f432c 100644
--- a/editor/plugins/resource_preloader_editor_plugin.h
+++ b/editor/plugins/resource_preloader_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/rich_text_editor_plugin.cpp b/editor/plugins/rich_text_editor_plugin.cpp
deleted file mode 100644
index 07c0cced49..0000000000
--- a/editor/plugins/rich_text_editor_plugin.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/*************************************************************************/
-/* rich_text_editor_plugin.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "rich_text_editor_plugin.h"
-
-#include "canvas_item_editor_plugin.h"
-#include "os/file_access.h"
-
-void RichTextEditor::_notification(int p_what) {
-
- switch (p_what) {
-
- case NOTIFICATION_FIXED_PROCESS: {
-
- } break;
- }
-}
-void RichTextEditor::_node_removed(Node *p_node) {
-
- if (p_node == node) {
- node = NULL;
- hide();
- }
-}
-
-void RichTextEditor::_file_selected(const String &p_path) {
-
- CharString cs;
- FileAccess *fa = FileAccess::open(p_path, FileAccess::READ);
- if (!fa) {
- ERR_FAIL();
- }
-
- while (!fa->eof_reached())
- cs.push_back(fa->get_8());
- cs.push_back(0);
- memdelete(fa);
-
- String bbcode;
- bbcode.parse_utf8(&cs[0]);
- node->parse_bbcode(bbcode);
-}
-
-void RichTextEditor::_menu_option(int p_option) {
-
- switch (p_option) {
-
- case PARSE_BBCODE: {
-
- file_dialog->popup_centered_ratio();
- } break;
- case CLEAR: {
-
- node->clear();
-
- } break;
- }
-}
-
-void RichTextEditor::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_menu_option"), &RichTextEditor::_menu_option);
- ClassDB::bind_method(D_METHOD("_file_selected"), &RichTextEditor::_file_selected);
-}
-
-void RichTextEditor::edit(Node *p_rich_text) {
-
- node = p_rich_text->cast_to<RichTextLabel>();
-}
-RichTextEditor::RichTextEditor() {
-
- options = memnew(MenuButton);
- //add_child(options);
- CanvasItemEditor::get_singleton()->add_control_to_menu_panel(options);
- options->set_area_as_parent_rect();
-
- options->set_text("RichText");
- options->get_popup()->add_item(TTR("Parse BBCode"), PARSE_BBCODE);
- options->get_popup()->add_item(TTR("Clear"), CLEAR);
-
- options->get_popup()->connect("id_pressed", this, "_menu_option");
- file_dialog = memnew(EditorFileDialog);
- add_child(file_dialog);
- file_dialog->add_filter("*.txt");
- file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE);
- file_dialog->connect("file_selected", this, "_file_selected");
-}
-
-void RichTextEditorPlugin::edit(Object *p_object) {
-
- rich_text_editor->edit(p_object->cast_to<Node>());
-}
-
-bool RichTextEditorPlugin::handles(Object *p_object) const {
-
- return p_object->is_class("RichTextLabel");
-}
-
-void RichTextEditorPlugin::make_visible(bool p_visible) {
-
- if (p_visible) {
- rich_text_editor->options->show();
- } else {
-
- rich_text_editor->options->hide();
- rich_text_editor->edit(NULL);
- }
-}
-
-RichTextEditorPlugin::RichTextEditorPlugin(EditorNode *p_node) {
-
- editor = p_node;
- rich_text_editor = memnew(RichTextEditor);
- editor->get_viewport()->add_child(rich_text_editor);
-
- rich_text_editor->set_margin(MARGIN_LEFT, 184);
- rich_text_editor->set_margin(MARGIN_RIGHT, 230);
- rich_text_editor->set_margin(MARGIN_TOP, 0);
- rich_text_editor->set_margin(MARGIN_BOTTOM, 10);
-
- rich_text_editor->options->hide();
-}
-
-RichTextEditorPlugin::~RichTextEditorPlugin() {
-}
diff --git a/editor/plugins/rich_text_editor_plugin.h b/editor/plugins/rich_text_editor_plugin.h
deleted file mode 100644
index 2665db2993..0000000000
--- a/editor/plugins/rich_text_editor_plugin.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*************************************************************************/
-/* rich_text_editor_plugin.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef RICH_TEXT_EDITOR_PLUGIN_H
-#define RICH_TEXT_EDITOR_PLUGIN_H
-
-#include "editor/editor_node.h"
-#include "editor/editor_plugin.h"
-#include "scene/gui/file_dialog.h"
-#include "scene/gui/rich_text_label.h"
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-
-class RichTextEditor : public Control {
-
- GDCLASS(RichTextEditor, Control);
-
- friend class RichTextEditorPlugin;
-
- enum {
-
- PARSE_BBCODE,
- CLEAR
- };
-
- Panel *panel;
- MenuButton *options;
- RichTextLabel *node;
- EditorFileDialog *file_dialog;
-
- void _file_selected(const String &p_path);
- void _menu_option(int p_option);
-
-protected:
- void _notification(int p_what);
- void _node_removed(Node *p_node);
- static void _bind_methods();
-
-public:
- void edit(Node *p_rich_text);
- RichTextEditor();
-};
-
-class RichTextEditorPlugin : public EditorPlugin {
-
- GDCLASS(RichTextEditorPlugin, EditorPlugin);
-
- RichTextEditor *rich_text_editor;
- EditorNode *editor;
-
-public:
- virtual String get_name() const { return "RichText"; }
- bool has_main_screen() const { return false; }
- virtual void edit(Object *p_object);
- virtual bool handles(Object *p_object) const;
- virtual void make_visible(bool p_visible);
-
- RichTextEditorPlugin(EditorNode *p_node);
- ~RichTextEditorPlugin();
-};
-
-#endif // RICH_TEXT_EDITOR_PLUGIN_H
diff --git a/editor/plugins/sample_editor_plugin.cpp b/editor/plugins/sample_editor_plugin.cpp
deleted file mode 100644
index 1d6417e2d5..0000000000
--- a/editor/plugins/sample_editor_plugin.cpp
+++ /dev/null
@@ -1,452 +0,0 @@
-/*************************************************************************/
-/* sample_editor_plugin.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "sample_editor_plugin.h"
-
-#if 0
-#include "editor/editor_settings.h"
-#include "io/resource_loader.h"
-#include "project_settings.h"
-
-
-
-
-void SampleEditor::_gui_input(InputEvent p_event) {
-
-
-}
-
-void SampleEditor::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_FIXED_PROCESS) {
-
- }
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
- play->set_icon( get_icon("Play","EditorIcons") );
- stop->set_icon( get_icon("Stop","EditorIcons") );
- }
-
- if (p_what==NOTIFICATION_READY) {
-
- //get_scene()->connect("node_removed",this,"_node_removed");
-
- }
-
- if (p_what==NOTIFICATION_DRAW) {
-
- }
-}
-
-void SampleEditor::_play_pressed() {
-
- player->play("default",true);
- stop->set_pressed(false);
- play->set_pressed(true);
-}
-void SampleEditor::_stop_pressed() {
-
- player->stop_all();
- play->set_pressed(false);
-}
-
-void SampleEditor::generate_preview_texture(const Ref<Sample>& p_sample,Ref<ImageTexture> &p_texture) {
-
-
- PoolVector<uint8_t> data = p_sample->get_data();
-
- PoolVector<uint8_t> img;
- int w = p_texture->get_width();
- int h = p_texture->get_height();
- img.resize(w*h*3);
- PoolVector<uint8_t>::Write imgdata = img.write();
- uint8_t * imgw = imgdata.ptr();
- PoolVector<uint8_t>::Read sampledata = data.read();
- const uint8_t *sdata=sampledata.ptr();
-
- bool stereo = p_sample->is_stereo();
- bool _16=p_sample->get_format()==Sample::FORMAT_PCM16;
- int len = p_sample->get_length();
-
- if (len<1)
- return;
-
- if (p_sample->get_format()==Sample::FORMAT_IMA_ADPCM) {
-
-
- struct IMA_ADPCM_State {
-
- int16_t step_index;
- int32_t predictor;
- /* values at loop point */
- int16_t loop_step_index;
- int32_t loop_predictor;
- int32_t last_nibble;
- int32_t loop_pos;
- int32_t window_ofs;
- const uint8_t *ptr;
- } ima_adpcm;
-
- ima_adpcm.step_index=0;
- ima_adpcm.predictor=0;
- ima_adpcm.loop_step_index=0;
- ima_adpcm.loop_predictor=0;
- ima_adpcm.last_nibble=-1;
- ima_adpcm.loop_pos=0x7FFFFFFF;
- ima_adpcm.window_ofs=0;
- ima_adpcm.ptr=NULL;
-
-
- for(int i=0;i<w;i++) {
-
- float max[2]={-1e10,-1e10};
- float min[2]={1e10,1e10};
- int from = i*len/w;
- int to = (i+1)*len/w;
- if (to>=len)
- to=len-1;
-
- for(int j=from;j<to;j++) {
-
- while(j>ima_adpcm.last_nibble) {
-
- static const int16_t _ima_adpcm_step_table[89] = {
- 7, 8, 9, 10, 11, 12, 13, 14, 16, 17,
- 19, 21, 23, 25, 28, 31, 34, 37, 41, 45,
- 50, 55, 60, 66, 73, 80, 88, 97, 107, 118,
- 130, 143, 157, 173, 190, 209, 230, 253, 279, 307,
- 337, 371, 408, 449, 494, 544, 598, 658, 724, 796,
- 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066,
- 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358,
- 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899,
- 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767
- };
-
- static const int8_t _ima_adpcm_index_table[16] = {
- -1, -1, -1, -1, 2, 4, 6, 8,
- -1, -1, -1, -1, 2, 4, 6, 8
- };
-
- int16_t nibble,diff,step;
-
- ima_adpcm.last_nibble++;
- const uint8_t *src_ptr=sdata;
-
- int ofs = ima_adpcm.last_nibble>>1;
-
- if (stereo)
- ofs*=2;
-
- nibble = (ima_adpcm.last_nibble&1)?
- (src_ptr[ofs]>>4):(src_ptr[ofs]&0xF);
-
- step=_ima_adpcm_step_table[ima_adpcm.step_index];
-
- ima_adpcm.step_index += _ima_adpcm_index_table[nibble];
- if (ima_adpcm.step_index<0)
- ima_adpcm.step_index=0;
- if (ima_adpcm.step_index>88)
- ima_adpcm.step_index=88;
-
- diff = step >> 3 ;
- if (nibble & 1)
- diff += step >> 2 ;
- if (nibble & 2)
- diff += step >> 1 ;
- if (nibble & 4)
- diff += step ;
- if (nibble & 8)
- diff = -diff ;
-
- ima_adpcm.predictor+=diff;
- if (ima_adpcm.predictor<-0x8000)
- ima_adpcm.predictor=-0x8000;
- else if (ima_adpcm.predictor>0x7FFF)
- ima_adpcm.predictor=0x7FFF;
-
-
- /* store loop if there */
- if (ima_adpcm.last_nibble==ima_adpcm.loop_pos) {
-
- ima_adpcm.loop_step_index = ima_adpcm.step_index;
- ima_adpcm.loop_predictor = ima_adpcm.predictor;
- }
-
- }
-
- float v=ima_adpcm.predictor/32767.0;
- if (v>max[0])
- max[0]=v;
- if (v<min[0])
- min[0]=v;
- }
-
- for(int j=0;j<h;j++) {
- float v = (j/(float)h) * 2.0 - 1.0;
- uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3];
- if (v>min[0] && v<max[0]) {
- imgofs[0]=255;
- imgofs[1]=150;
- imgofs[2]=80;
- } else {
- imgofs[0]=0;
- imgofs[1]=0;
- imgofs[2]=0;
- }
- }
- }
- } else {
- for(int i=0;i<w;i++) {
- // i trust gcc will optimize this loop
- float max[2]={-1e10,-1e10};
- float min[2]={1e10,1e10};
- int c=stereo?2:1;
- int from = uint64_t(i)*len/w;
- int to = (uint64_t(i)+1)*len/w;
- if (to>=len)
- to=len-1;
-
- if (_16) {
- const int16_t*src =(const int16_t*)sdata;
-
- for(int j=0;j<c;j++) {
-
- for(int k=from;k<=to;k++) {
-
- float v = src[uint64_t(k)*c+j]/32768.0;
- if (v>max[j])
- max[j]=v;
- if (v<min[j])
- min[j]=v;
- }
-
- }
- } else {
-
- const int8_t*src =(const int8_t*)sdata;
-
- for(int j=0;j<c;j++) {
-
- for(int k=from;k<=to;k++) {
-
- float v = src[uint64_t(k)*c+j]/128.0;
- if (v>max[j])
- max[j]=v;
- if (v<min[j])
- min[j]=v;
- }
-
- }
- }
-
- if (!stereo) {
- for(int j=0;j<h;j++) {
- float v = (j/(float)h) * 2.0 - 1.0;
- uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3];
- if (v>min[0] && v<max[0]) {
- imgofs[0]=255;
- imgofs[1]=150;
- imgofs[2]=80;
- } else {
- imgofs[0]=0;
- imgofs[1]=0;
- imgofs[2]=0;
- }
- }
- } else {
-
- for(int j=0;j<h;j++) {
-
- int half;
- float v;
- if (j<(h/2)) {
- half=0;
- v = (j/(float)(h/2)) * 2.0 - 1.0;
- } else {
- half=1;
- v = ((j-(h/2))/(float)(h/2)) * 2.0 - 1.0;
- }
-
- uint8_t* imgofs = &imgw[(uint64_t(j)*w+i)*3];
- if (v>min[half] && v<max[half]) {
- imgofs[0]=255;
- imgofs[1]=150;
- imgofs[2]=80;
- } else {
- imgofs[0]=0;
- imgofs[1]=0;
- imgofs[2]=0;
- }
- }
-
- }
-
- }
- }
-
- imgdata = PoolVector<uint8_t>::Write();
-
-
- p_texture->set_data(Image(w,h,0,Image::FORMAT_RGB8,img));
-
-}
-
-void SampleEditor::_update_sample() {
-
- player->stop_all();
-
- generate_preview_texture(sample,peakdisplay);
- info_label->set_text(TTR("Length:")+" "+String::num(sample->get_length()/(float)sample->get_mix_rate(),2)+"s");
-
- if (library->has_sample("default"))
- library->remove_sample("default");
-
- library->add_sample("default",sample);
-}
-
-
-
-void SampleEditor::edit(Ref<Sample> p_sample) {
-
- sample=p_sample;
-
- if (!sample.is_null())
- _update_sample();
- else {
-
- hide();
- set_fixed_process(false);
- }
-
-}
-
-
-
-void SampleEditor::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_gui_input"),&SampleEditor::_gui_input);
- ClassDB::bind_method(D_METHOD("_play_pressed"),&SampleEditor::_play_pressed);
- ClassDB::bind_method(D_METHOD("_stop_pressed"),&SampleEditor::_stop_pressed);
-
-}
-
-SampleEditor::SampleEditor() {
-
- player = memnew(SamplePlayer);
- add_child(player);
- add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel"));
- library = Ref<SampleLibrary>(memnew(SampleLibrary));
- player->set_sample_library(library);
- sample_texframe = memnew( TextureRect );
- add_child(sample_texframe);
- sample_texframe->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5);
- sample_texframe->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,-5);
- sample_texframe->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,30);
- sample_texframe->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,-5);
-
- info_label = memnew( Label );
- sample_texframe->add_child(info_label);
- info_label->set_area_as_parent_rect();
- info_label->set_anchor_and_margin(MARGIN_TOP,ANCHOR_END,-15);
- info_label->set_margin(MARGIN_BOTTOM,4);
- info_label->set_margin(MARGIN_RIGHT,4);
- info_label->set_align(Label::ALIGN_RIGHT);
-
-
- play = memnew( Button );
-
- play->set_position(Point2( 5, 5 ));
- play->set_size( Size2(1,1 ) );
- play->set_toggle_mode(true);
- add_child(play);
-
- stop = memnew( Button );
-
- stop->set_position(Point2( 35, 5 ));
- stop->set_size( Size2(1,1 ) );
- stop->set_toggle_mode(true);
- add_child(stop);
-
- peakdisplay=Ref<ImageTexture>( memnew( ImageTexture) );
- peakdisplay->create( EDITOR_DEF("editors/sample_editor/preview_width",512),EDITOR_DEF("editors/sample_editor/preview_height",128),Image::FORMAT_RGB8);
- sample_texframe->set_expand(true);
- sample_texframe->set_texture(peakdisplay);
-
- play->connect("pressed", this,"_play_pressed");
- stop->connect("pressed", this,"_stop_pressed");
-
- set_custom_minimum_size(Size2(1,150)*EDSCALE);
-
-}
-
-
-void SampleEditorPlugin::edit(Object *p_object) {
-
- Sample * s = p_object->cast_to<Sample>();
- if (!s)
- return;
-
- sample_editor->edit(Ref<Sample>(s));
-}
-
-bool SampleEditorPlugin::handles(Object *p_object) const {
-
- return p_object->is_class("Sample");
-}
-
-void SampleEditorPlugin::make_visible(bool p_visible) {
-
- if (p_visible) {
- sample_editor->show();
- //sample_editor->set_process(true);
- } else {
-
- sample_editor->hide();
- //sample_editor->set_process(false);
- }
-
-}
-
-SampleEditorPlugin::SampleEditorPlugin(EditorNode *p_node) {
-
- editor=p_node;
- sample_editor = memnew( SampleEditor );
- add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM,sample_editor);
- sample_editor->hide();
-
-
-
-}
-
-
-SampleEditorPlugin::~SampleEditorPlugin()
-{
-}
-
-#endif
diff --git a/editor/plugins/sample_editor_plugin.h b/editor/plugins/sample_editor_plugin.h
deleted file mode 100644
index 8f93026c92..0000000000
--- a/editor/plugins/sample_editor_plugin.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*************************************************************************/
-/* sample_editor_plugin.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef SAMPLE_EDITOR_PLUGIN_H
-#define SAMPLE_EDITOR_PLUGIN_H
-
-#if 0
-#include "editor/editor_node.h"
-#include "editor/editor_plugin.h"
-#include "scene/audio/sample_player.h"
-#include "scene/resources/sample.h"
-#include "scene/resources/sample_library.h"
-
-
-class SampleEditor : public Panel {
-
- GDCLASS(SampleEditor, Panel );
-
-
- SamplePlayer *player;
- Label *info_label;
- Ref<ImageTexture> peakdisplay;
- Ref<Sample> sample;
- Ref<SampleLibrary> library;
- TextureRect *sample_texframe;
- Button *stop;
- Button *play;
-
- void _play_pressed();
- void _stop_pressed();
- void _update_sample();
-
-protected:
- void _notification(int p_what);
- void _gui_input(InputEvent p_event);
- static void _bind_methods();
-public:
-
- static void generate_preview_texture(const Ref<Sample>& p_sample,Ref<ImageTexture> &p_texture);
- void edit(Ref<Sample> p_sample);
- SampleEditor();
-};
-
-
-class SampleEditorPlugin : public EditorPlugin {
-
- GDCLASS( SampleEditorPlugin, EditorPlugin );
-
- SampleEditor *sample_editor;
- EditorNode *editor;
-
-public:
-
- virtual String get_name() const { return "Sample"; }
- 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);
-
- SampleEditorPlugin(EditorNode *p_node);
- ~SampleEditorPlugin();
-
-};
-
-#endif
-
-#endif // SAMPLE_EDITOR_PLUGIN_H
diff --git a/editor/plugins/sample_library_editor_plugin.cpp b/editor/plugins/sample_library_editor_plugin.cpp
deleted file mode 100644
index 3deb634491..0000000000
--- a/editor/plugins/sample_library_editor_plugin.cpp
+++ /dev/null
@@ -1,547 +0,0 @@
-/*************************************************************************/
-/* sample_library_editor_plugin.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#if 0
-#include "sample_library_editor_plugin.h"
-
-#include "editor/editor_settings.h"
-#include "io/resource_loader.h"
-#include "project_settings.h"
-#include "sample_editor_plugin.h"
-#include "scene/main/viewport.h"
-
-
-void SampleLibraryEditor::_gui_input(InputEvent p_event) {
-
-
-}
-
-void SampleLibraryEditor::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_PROCESS) {
- if (is_playing && !player->is_active()) {
- TreeItem *tl=last_sample_playing->cast_to<TreeItem>();
- tl->set_button(0,0,get_icon("Play","EditorIcons"));
- is_playing = false;
- set_process(false);
- }
- }
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
- load->set_icon( get_icon("Folder","EditorIcons") );
- load->set_tooltip(TTR("Open Sample File(s)"));
- }
-
- if (p_what==NOTIFICATION_READY) {
-
- //NodePath("/root")->connect("node_removed", this,"_node_removed",Vector<Variant>(),true);
- }
-
- if (p_what==NOTIFICATION_DRAW) {
-
- }
-}
-
-void SampleLibraryEditor::_file_load_request(const PoolVector<String>& p_path) {
-
-
- for(int i=0;i<p_path.size();i++) {
-
- String path = p_path[i];
- Ref<Sample> sample = ResourceLoader::load(path,"Sample");
- if (sample.is_null()) {
- dialog->set_text(TTR("ERROR: Couldn't load sample!"));
- dialog->set_title(TTR("Error!"));
- //dialog->get_cancel()->set_text("Close");
- dialog->get_ok()->set_text(TTR("Close"));
- dialog->popup_centered_minsize();
- return; ///beh should show an error i guess
- }
- String basename = path.get_file().get_basename();
- String name=basename;
- int counter=0;
- while(sample_library->has_sample(name)) {
- counter++;
- name=basename+"_"+itos(counter);
- }
-
- undo_redo->create_action(TTR("Add Sample"));
- undo_redo->add_do_method(sample_library.operator->(),"add_sample",name,sample);
- undo_redo->add_undo_method(sample_library.operator->(),"remove_sample",name);
- undo_redo->add_do_method(this,"_update_library");
- undo_redo->add_undo_method(this,"_update_library");
- undo_redo->commit_action();
- }
-}
-
-void SampleLibraryEditor::_load_pressed() {
-
- file->popup_centered_ratio();
-
-}
-
-void SampleLibraryEditor::_button_pressed(Object *p_item,int p_column, int p_id) {
-
- TreeItem *ti=p_item->cast_to<TreeItem>();
- String name = ti->get_text(0);
-
- if (p_column==0) { // Play/Stop
-
- String btn_type;
- if(!is_playing) {
- is_playing = true;
- btn_type = TTR("Stop");
- player->play(name,true);
- last_sample_playing = p_item;
- set_process(true);
- } else {
- player->stop_all();
- if(last_sample_playing != p_item){
- TreeItem *tl=last_sample_playing->cast_to<TreeItem>();
- tl->set_button(p_column,0,get_icon("Play","EditorIcons"));
- btn_type = TTR("Stop");
- player->play(name,true);
- last_sample_playing = p_item;
- } else {
- btn_type = TTR("Play");
- is_playing = false;
- }
- }
- ti->set_button(p_column,0,get_icon(btn_type,"EditorIcons"));
- } else if (p_column==1) { // Edit
-
- get_tree()->get_root()->get_child(0)->call("_resource_selected",sample_library->get_sample(name));
- } else if (p_column==5) { // Delete
-
- ti->select(0);
- _delete_pressed();
- }
-
-
-}
-
-
-
-
-
-void SampleLibraryEditor::_item_edited() {
-
- if (!tree->get_selected())
- return;
-
- TreeItem *s = tree->get_selected();
-
- if (tree->get_selected_column()==0) { // Name
- // renamed
- String old_name=s->get_metadata(0);
- String new_name=s->get_text(0);
- if (old_name==new_name)
- return;
-
- if (new_name=="" || new_name.find("\\")!=-1 || new_name.find("/")!=-1 || sample_library->has_sample(new_name)) {
-
- s->set_text(0,old_name);
- return;
- }
-
- Ref<Sample> samp = sample_library->get_sample(old_name);
- undo_redo->create_action(TTR("Rename Sample"));
- undo_redo->add_do_method(sample_library.operator->(),"remove_sample",old_name);
- undo_redo->add_do_method(sample_library.operator->(),"add_sample",new_name,samp);
- undo_redo->add_undo_method(sample_library.operator->(),"remove_sample",new_name);
- undo_redo->add_undo_method(sample_library.operator->(),"add_sample",old_name,samp);
- undo_redo->add_do_method(this,"_update_library");
- undo_redo->add_undo_method(this,"_update_library");
- undo_redo->commit_action();
-
- } else if (tree->get_selected_column()==3) { // Volume dB
-
- StringName n = s->get_text(0);
- sample_library->sample_set_volume_db(n,s->get_range(3));
-
- } else if (tree->get_selected_column()==4) { // Pitch scale
-
- StringName n = s->get_text(0);
- sample_library->sample_set_pitch_scale(n,s->get_range(4));
-
- }
-
-
-}
-
-void SampleLibraryEditor::_delete_pressed() {
-
- if (!tree->get_selected())
- return;
-
- String to_remove = tree->get_selected()->get_text(0);
- undo_redo->create_action(TTR("Delete Sample"));
- undo_redo->add_do_method(sample_library.operator->(),"remove_sample",to_remove);
- undo_redo->add_undo_method(sample_library.operator->(),"add_sample",to_remove,sample_library->get_sample(to_remove));
- undo_redo->add_do_method(this,"_update_library");
- undo_redo->add_undo_method(this,"_update_library");
- undo_redo->commit_action();
-}
-
-
-void SampleLibraryEditor::_update_library() {
-
- player->stop_all();
-
- tree->clear();
- tree->set_hide_root(true);
- TreeItem *root = tree->create_item(NULL);
-
- 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()) {
-
- TreeItem *ti = tree->create_item(root);
-
- // Name + Play/Stop
- ti->set_cell_mode(0,TreeItem::CELL_MODE_STRING);
- ti->set_editable(0,true);
- ti->set_selectable(0,true);
- ti->set_text(0,E->get());
- ti->set_metadata(0,E->get());
- ti->add_button(0,get_icon("Play","EditorIcons"));
-
- Ref<Sample> smp = sample_library->get_sample(E->get());
-
- // Preview/edit
- Ref<ImageTexture> preview( memnew( ImageTexture ));
- preview->create(128,16,Image::FORMAT_RGB8);
- SampleEditor::generate_preview_texture(smp,preview);
- ti->set_cell_mode(1,TreeItem::CELL_MODE_ICON);
- ti->set_selectable(1,false);
- ti->set_editable(1,false);
- ti->set_icon(1,preview);
- ti->add_button(1,get_icon("Edit","EditorIcons"));
-
- // Format
- ti->set_cell_mode(2,TreeItem::CELL_MODE_STRING);
- ti->set_editable(2,false);
- ti->set_selectable(2,false);
- ti->set_text(2,String()+(smp->get_format()==Sample::FORMAT_PCM16?TTR("16 Bits")+", ":(smp->get_format()==Sample::FORMAT_PCM8?TTR("8 Bits")+", ":"IMA-ADPCM,"))+(smp->is_stereo()?TTR("Stereo"):TTR("Mono")));
-
- // Volume dB
- ti->set_cell_mode(3,TreeItem::CELL_MODE_RANGE);
- ti->set_range_config(3,-60,24,0.01);
- ti->set_selectable(3,true);
- ti->set_editable(3,true);
- ti->set_range(3,sample_library->sample_get_volume_db(E->get()));
-
- // Pitch scale
- ti->set_cell_mode(4,TreeItem::CELL_MODE_RANGE);
- ti->set_range_config(4,0.01,100,0.01);
- ti->set_selectable(4,true);
- ti->set_editable(4,true);
- ti->set_range(4,sample_library->sample_get_pitch_scale(E->get()));
-
- // Delete
- ti->set_cell_mode(5,TreeItem::CELL_MODE_STRING);
- ti->add_button(5,get_icon("Remove","EditorIcons"));
-
- }
-
- //player->add_sample("default",sample);
-}
-
-
-
-void SampleLibraryEditor::edit(Ref<SampleLibrary> p_sample_library) {
-
- sample_library=p_sample_library;
-
-
- if (!sample_library.is_null()) {
- player->set_sample_library(sample_library);
- _update_library();
- } else {
-
- hide();
- }
-
-}
-
-Variant SampleLibraryEditor::get_drag_data_fw(const Point2& p_point,Control* p_from) {
-
- TreeItem*ti =tree->get_item_at_pos(p_point);
- if (!ti)
- return Variant();
-
- String name = ti->get_metadata(0);
-
- RES res = sample_library->get_sample(name);
- if (!res.is_valid())
- return Variant();
-
- return EditorNode::get_singleton()->drag_resource(res,p_from);
-
-
-}
-
-bool SampleLibraryEditor::can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const {
-
-
-
- Dictionary d = p_data;
-
- if (!d.has("type"))
- return false;
-
- if (d.has("from") && (Object*)(d["from"])==tree)
- return false;
-
- if (String(d["type"])=="resource" && d.has("resource")) {
- RES r=d["resource"];
-
- Ref<Sample> sample = r;
-
- if (sample.is_valid()) {
-
- return true;
- }
- }
-
-
- if (String(d["type"])=="files") {
-
- Vector<String> files = d["files"];
-
- if (files.size()==0)
- return false;
-
- for(int i=0;i<files.size();i++) {
- String file = files[0];
- String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
-
- if (ftype!="Sample") {
- return false;
- }
-
- }
-
- return true;
-
- }
- return false;
-}
-
-void SampleLibraryEditor::drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) {
-
- if (!can_drop_data_fw(p_point,p_data,p_from))
- return;
-
- Dictionary d = p_data;
-
- if (!d.has("type"))
- return;
-
-
- if (String(d["type"])=="resource" && d.has("resource")) {
- RES r=d["resource"];
-
- Ref<Sample> sample = r;
-
- if (sample.is_valid()) {
-
- String basename;
- if (sample->get_name()!="") {
- basename=sample->get_name();
- } else if (sample->get_path().is_resource_file()) {
- basename = sample->get_path().get_basename();
- } else {
- basename="Sample";
- }
-
- String name=basename;
- int counter=0;
- while(sample_library->has_sample(name)) {
- counter++;
- name=basename+"_"+itos(counter);
- }
-
- undo_redo->create_action(TTR("Add Sample"));
- undo_redo->add_do_method(sample_library.operator->(),"add_sample",name,sample);
- undo_redo->add_undo_method(sample_library.operator->(),"remove_sample",name);
- undo_redo->add_do_method(this,"_update_library");
- undo_redo->add_undo_method(this,"_update_library");
- undo_redo->commit_action();
- }
- }
-
-
- if (String(d["type"])=="files") {
-
- PoolVector<String> files = d["files"];
-
- _file_load_request(files);
-
- }
-
-}
-
-
-void SampleLibraryEditor::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_gui_input"),&SampleLibraryEditor::_gui_input);
- ClassDB::bind_method(D_METHOD("_load_pressed"),&SampleLibraryEditor::_load_pressed);
- ClassDB::bind_method(D_METHOD("_item_edited"),&SampleLibraryEditor::_item_edited);
- ClassDB::bind_method(D_METHOD("_delete_pressed"),&SampleLibraryEditor::_delete_pressed);
- ClassDB::bind_method(D_METHOD("_file_load_request"),&SampleLibraryEditor::_file_load_request);
- ClassDB::bind_method(D_METHOD("_update_library"),&SampleLibraryEditor::_update_library);
- ClassDB::bind_method(D_METHOD("_button_pressed"),&SampleLibraryEditor::_button_pressed);
-
- ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SampleLibraryEditor::get_drag_data_fw);
- ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SampleLibraryEditor::can_drop_data_fw);
- ClassDB::bind_method(D_METHOD("drop_data_fw"), &SampleLibraryEditor::drop_data_fw);
-
-}
-
-SampleLibraryEditor::SampleLibraryEditor() {
-
- player = memnew(SamplePlayer);
- add_child(player);
- add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("panel","Panel"));
-
-
- load = memnew( Button );
- load->set_position(Point2( 5, 5 ));
- load->set_size( Size2(1,1 ) );
- add_child(load);
-
- file = memnew( EditorFileDialog );
- add_child(file);
- List<String> extensions;
- ResourceLoader::get_recognized_extensions_for_type("Sample",&extensions);
- for(int i=0;i<extensions.size();i++)
- file->add_filter("*."+extensions[i]);
- file->set_mode(EditorFileDialog::MODE_OPEN_FILES);
-
- tree = memnew( Tree );
- tree->set_columns(6);
- add_child(tree);
- tree->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_BEGIN,5);
- tree->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,-5);
- tree->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,30);
- tree->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_END,-5);
- tree->set_column_titles_visible(true);
- tree->set_column_title(0,TTR("Name"));
- tree->set_column_title(1,TTR("Preview"));
- tree->set_column_title(2,TTR("Format"));
- tree->set_column_title(3,"dB");
- tree->set_column_title(4,TTR("Pitch"));
- tree->set_column_title(5,"");
-
- tree->set_column_min_width(1,150);
- tree->set_column_min_width(2,100);
- tree->set_column_min_width(3,50);
- tree->set_column_min_width(4,50);
- tree->set_column_min_width(5,32);
- tree->set_column_expand(1,false);
- tree->set_column_expand(2,false);
- tree->set_column_expand(3,false);
- tree->set_column_expand(4,false);
- tree->set_column_expand(5,false);
-
- tree->set_drag_forwarding(this);
-
- dialog = memnew( ConfirmationDialog );
- add_child( dialog );
-
- tree->connect("button_pressed",this,"_button_pressed");
- load->connect("pressed", this,"_load_pressed");
- file->connect("files_selected", this,"_file_load_request");
- tree->connect("item_edited", this,"_item_edited");
-
- is_playing = false;
-}
-
-
-void SampleLibraryEditorPlugin::edit(Object *p_object) {
-
- sample_library_editor->set_undo_redo(&get_undo_redo());
- SampleLibrary * s = p_object->cast_to<SampleLibrary>();
- if (!s)
- return;
-
- sample_library_editor->edit(Ref<SampleLibrary>(s));
-}
-
-bool SampleLibraryEditorPlugin::handles(Object *p_object) const {
-
- return p_object->is_class("SampleLibrary");
-}
-
-void SampleLibraryEditorPlugin::make_visible(bool p_visible) {
-
- if (p_visible) {
- //sample_library_editor->show();
- button->show();
- editor->make_bottom_panel_item_visible(sample_library_editor);
- //sample_library_editor->set_process(true);
- } else {
-
- if (sample_library_editor->is_visible_in_tree())
- editor->hide_bottom_panel();
- button->hide();
-
- //sample_library_editor->set_process(false);
- }
-
-}
-
-SampleLibraryEditorPlugin::SampleLibraryEditorPlugin(EditorNode *p_node) {
-
- editor=p_node;
- sample_library_editor = memnew( SampleLibraryEditor );
-
- //editor->get_viewport()->add_child(sample_library_editor);
- sample_library_editor->set_custom_minimum_size(Size2(0,250));
- button=p_node->add_bottom_panel_item("SampleLibrary",sample_library_editor);
- button->hide();
-
- //sample_library_editor->set_area_as_parent_rect();
- //sample_library_editor->set_anchor( MARGIN_TOP, Control::ANCHOR_END);
- //sample_library_editor->set_margin( MARGIN_TOP, 120 );
- //sample_library_editor->hide();
-
-
-
-}
-
-
-SampleLibraryEditorPlugin::~SampleLibraryEditorPlugin()
-{
-}
-#endif
diff --git a/editor/plugins/sample_library_editor_plugin.h b/editor/plugins/sample_library_editor_plugin.h
deleted file mode 100644
index 0244fa66ed..0000000000
--- a/editor/plugins/sample_library_editor_plugin.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*************************************************************************/
-/* sample_library_editor_plugin.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef SAMPLE_LIBRARY_EDITOR_PLUGIN_H
-#define SAMPLE_LIBRARY_EDITOR_PLUGIN_H
-
-#if 0
-#include "editor/editor_node.h"
-#include "editor/editor_plugin.h"
-#include "scene/audio/sample_player.h"
-#include "scene/gui/dialogs.h"
-#include "scene/gui/file_dialog.h"
-#include "scene/gui/tree.h"
-#include "scene/resources/sample.h"
-
-
-class SampleLibraryEditor : public Panel {
-
- GDCLASS(SampleLibraryEditor, Panel );
-
-
-
- SamplePlayer *player;
- Ref<SampleLibrary> sample_library;
- Button *load;
- Tree *tree;
- bool is_playing;
- Object *last_sample_playing;
-
- EditorFileDialog *file;
-
- ConfirmationDialog *dialog;
-
-
- void _load_pressed();
- void _file_load_request(const PoolVector<String>& p_path);
- void _delete_pressed();
- void _update_library();
- void _item_edited();
-
- UndoRedo *undo_redo;
-
- void _button_pressed(Object *p_item,int p_column, int p_id);
-
- Variant get_drag_data_fw(const Point2& p_point,Control* p_from);
- bool can_drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from) const;
- void drop_data_fw(const Point2& p_point,const Variant& p_data,Control* p_from);
-
-protected:
- void _notification(int p_what);
- void _gui_input(InputEvent p_event);
- static void _bind_methods();
-public:
-
- void set_undo_redo(UndoRedo *p_undo_redo) {undo_redo=p_undo_redo; }
- void edit(Ref<SampleLibrary> p_sample);
- SampleLibraryEditor();
-};
-
-class SampleLibraryEditorPlugin : public EditorPlugin {
-
- GDCLASS( SampleLibraryEditorPlugin, EditorPlugin );
-
- SampleLibraryEditor *sample_library_editor;
- EditorNode *editor;
- Button *button;
-
-public:
-
- virtual String get_name() const { return "SampleLibrary"; }
- 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);
-
- SampleLibraryEditorPlugin(EditorNode *p_node);
- ~SampleLibraryEditorPlugin();
-
-};
-
-#endif
-#endif // SAMPLE_LIBRARY_EDITOR_PLUGIN_H
diff --git a/editor/plugins/sample_player_editor_plugin.cpp b/editor/plugins/sample_player_editor_plugin.cpp
deleted file mode 100644
index ea9b646a9b..0000000000
--- a/editor/plugins/sample_player_editor_plugin.cpp
+++ /dev/null
@@ -1,202 +0,0 @@
-/*************************************************************************/
-/* sample_player_editor_plugin.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#if 0
-#include "sample_player_editor_plugin.h"
-
-#include "scene/resources/sample_library.h"
-
-
-void SamplePlayerEditor::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
- play->set_icon( get_icon("Play","EditorIcons") );
- stop->set_icon( get_icon("Stop","EditorIcons") );
- }
-
-}
-
-void SamplePlayerEditor::_node_removed(Node *p_node) {
-
- if(p_node==node) {
- node=NULL;
- hide();
- }
-
-}
-
-void SamplePlayerEditor::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_play"),&SamplePlayerEditor::_play);
- ClassDB::bind_method(D_METHOD("_stop"),&SamplePlayerEditor::_stop);
-
-}
-
-
-void SamplePlayerEditor::_play() {
-
- if (!node)
- return;
- if (samples->get_item_count()<=0)
- return;
-
- node->call("play",samples->get_item_text( samples->get_selected() ));
- stop->set_pressed(false);
- play->set_pressed(true);
-}
-
-void SamplePlayerEditor::_stop() {
-
- if (!node)
- return;
- if (samples->get_item_count()<=0)
- return;
-
- node->call("stop_all");
- print_line("STOP ALL!!");
- stop->set_pressed(true);
- play->set_pressed(false);
-
-}
-
-
-void SamplePlayerEditor::_update_sample_library() {
-
- samples->clear();
- Ref<SampleLibrary> sl = node->call("get_sample_library");
- if (sl.is_null()) {
- samples->add_item("<NO SAMPLE LIBRARY>");
- return; //no 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());
- }
-
-}
-
-void SamplePlayerEditor::edit(Node *p_sample_player) {
-
- node=p_sample_player;
- if (node) {
- _update_sample_library();
- }
-
-}
-SamplePlayerEditor::SamplePlayerEditor() {
-
-
- play = memnew( Button );
-
- play->set_position(Point2( 5, 5 ));
- play->set_toggle_mode(true);
- play->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-250);
- play->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-230);
- play->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0);
- play->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0);
-
- add_child(play);
-
- stop = memnew( Button );
-
- stop->set_position(Point2( 35, 5 ));
- stop->set_toggle_mode(true);
- stop->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-220);
- stop->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-200);
- stop->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0);
- stop->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0);
- add_child(stop);
-
- samples = memnew( OptionButton );
- samples->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,-190);
- samples->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,-5);
- samples->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0);
- samples->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0);
- add_child(samples);
-
- play->connect("pressed", this,"_play");
- stop->connect("pressed", this,"_stop");
-
-}
-
-
-void SamplePlayerEditorPlugin::edit(Object *p_object) {
-
- sample_player_editor->edit(p_object->cast_to<Node>());
-}
-
-bool SamplePlayerEditorPlugin::handles(Object *p_object) const {
-
- return p_object->is_class("SamplePlayer2D") || p_object->is_class("SamplePlayer") || p_object->is_class("SpatialSamplePlayer");
-}
-
-void SamplePlayerEditorPlugin::make_visible(bool p_visible) {
-
- if (p_visible) {
- sample_player_editor->show();
- sample_player_editor->set_fixed_process(true);
- } else {
-
- sample_player_editor->hide();
- sample_player_editor->set_fixed_process(false);
- sample_player_editor->edit(NULL);
- }
-
-}
-
-SamplePlayerEditorPlugin::SamplePlayerEditorPlugin(EditorNode *p_node) {
-
- editor=p_node;
- sample_player_editor = memnew( SamplePlayerEditor );
- editor->get_viewport()->add_child(sample_player_editor);
-
- sample_player_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END);
- sample_player_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);
- sample_player_editor->set_margin(MARGIN_LEFT,-250);
- sample_player_editor->set_margin(MARGIN_RIGHT,0);
- sample_player_editor->set_margin(MARGIN_TOP,0);
- sample_player_editor->set_margin(MARGIN_BOTTOM,10);
-
-
- sample_player_editor->hide();
-
-
-
-}
-
-
-SamplePlayerEditorPlugin::~SamplePlayerEditorPlugin()
-{
-}
-
-#endif
diff --git a/editor/plugins/sample_player_editor_plugin.h b/editor/plugins/sample_player_editor_plugin.h
deleted file mode 100644
index 5c1b25aaa2..0000000000
--- a/editor/plugins/sample_player_editor_plugin.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*************************************************************************/
-/* sample_player_editor_plugin.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef SAMPLE_PLAYER_EDITOR_PLUGIN_H
-#define SAMPLE_PLAYER_EDITOR_PLUGIN_H
-
-#if 0
-
-#include "editor/editor_node.h"
-#include "editor/editor_plugin.h"
-#include "scene/3d/spatial_sample_player.h"
-#include "scene/audio/sample_player.h"
-#include "scene/gui/option_button.h"
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-
-class SamplePlayerEditor : public Control {
-
- GDCLASS(SamplePlayerEditor, Control );
-
- Panel *panel;
- Button * play;
- Button * stop;
- OptionButton *samples;
- Node *node;
-
-
- void _update_sample_library();
- void _play();
- void _stop();
-
-protected:
- void _notification(int p_what);
- void _node_removed(Node *p_node);
- static void _bind_methods();
-public:
-
- void edit(Node *p_sample_player);
- SamplePlayerEditor();
-};
-
-class SamplePlayerEditorPlugin : public EditorPlugin {
-
- GDCLASS( SamplePlayerEditorPlugin, EditorPlugin );
-
- SamplePlayerEditor *sample_player_editor;
- EditorNode *editor;
-
-public:
-
- virtual String get_name() const { return "SamplePlayer"; }
- 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);
-
- SamplePlayerEditorPlugin(EditorNode *p_node);
- ~SamplePlayerEditorPlugin();
-
-};
-
-#endif
-#endif // SAMPLE_PLAYER_EDITOR_PLUGIN_H
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index fc89a4b9b4..a529f152dc 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -29,24 +29,25 @@
/*************************************************************************/
#include "script_editor_plugin.h"
+#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
+#include "core/os/file_access.h"
+#include "core/os/input.h"
+#include "core/os/keyboard.h"
+#include "core/os/os.h"
+#include "core/project_settings.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
+#include "editor/node_dock.h"
#include "editor/script_editor_debugger.h"
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "node_dock.h"
-#include "os/file_access.h"
-#include "os/input.h"
-#include "os/keyboard.h"
-#include "os/os.h"
-#include "project_settings.h"
#include "scene/main/viewport.h"
+
/*** SCRIPT EDITOR ****/
void ScriptEditorBase::_bind_methods() {
ADD_SIGNAL(MethodInfo("name_changed"));
- ADD_SIGNAL(MethodInfo("script_changed"));
+ ADD_SIGNAL(MethodInfo("edited_script_changed"));
ADD_SIGNAL(MethodInfo("request_help_search", PropertyInfo(Variant::STRING, "topic")));
ADD_SIGNAL(MethodInfo("request_help_index"));
ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line")));
@@ -256,7 +257,7 @@ ScriptEditor *ScriptEditor::script_editor = NULL;
String ScriptEditor::_get_debug_tooltip(const String &p_text, Node *_se) {
- //ScriptEditorBase *se=_se->cast_to<ScriptEditorBase>();
+ //ScriptEditorBase *se=Object::cast_to<ScriptEditorBase>(_se);
String val = debugger->get_var_value(p_text);
if (val != String()) {
@@ -280,7 +281,7 @@ void ScriptEditor::_breaked(bool p_breaked, bool p_can_debug) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se) {
continue;
@@ -305,7 +306,7 @@ void ScriptEditor::_goto_script_line2(int p_line) {
if (selected < 0 || selected >= tab_container->get_child_count())
return;
- ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
if (!current)
return;
@@ -318,7 +319,7 @@ void ScriptEditor::_goto_script_line(REF p_script, int p_line) {
if (bool(EditorSettings::get_singleton()->get("text_editor/external/use_external_editor"))) {
- Ref<Script> script = p_script->cast_to<Script>();
+ Ref<Script> script = Object::cast_to<Script>(*p_script);
if (!script.is_null() && script->get_path().is_resource_file())
edit(p_script, p_line, 0);
}
@@ -327,7 +328,7 @@ void ScriptEditor::_goto_script_line(REF p_script, int p_line) {
if (selected < 0 || selected >= tab_container->get_child_count())
return;
- ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
if (!current)
return;
@@ -346,13 +347,13 @@ void ScriptEditor::_save_history() {
Node *n = tab_container->get_current_tab_control();
- if (n->cast_to<ScriptEditorBase>()) {
+ if (Object::cast_to<ScriptEditorBase>(n)) {
- history[history_pos].state = n->cast_to<ScriptEditorBase>()->get_edit_state();
+ history[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state();
}
- if (n->cast_to<EditorHelp>()) {
+ if (Object::cast_to<EditorHelp>(n)) {
- history[history_pos].state = n->cast_to<EditorHelp>()->get_scroll();
+ history[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll();
}
}
@@ -369,10 +370,7 @@ void ScriptEditor::_save_history() {
void ScriptEditor::_go_to_tab(int p_idx) {
- Node *cn = tab_container->get_child(p_idx);
- if (!cn)
- return;
- Control *c = cn->cast_to<Control>();
+ Control *c = Object::cast_to<Control>(tab_container->get_child(p_idx));
if (!c)
return;
@@ -380,13 +378,13 @@ void ScriptEditor::_go_to_tab(int p_idx) {
Node *n = tab_container->get_current_tab_control();
- if (n->cast_to<ScriptEditorBase>()) {
+ if (Object::cast_to<ScriptEditorBase>(n)) {
- history[history_pos].state = n->cast_to<ScriptEditorBase>()->get_edit_state();
+ history[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state();
}
- if (n->cast_to<EditorHelp>()) {
+ if (Object::cast_to<EditorHelp>(n)) {
- history[history_pos].state = n->cast_to<EditorHelp>()->get_scroll();
+ history[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll();
}
}
@@ -402,21 +400,21 @@ void ScriptEditor::_go_to_tab(int p_idx) {
c = tab_container->get_current_tab_control();
- if (c->cast_to<ScriptEditorBase>()) {
+ if (Object::cast_to<ScriptEditorBase>(c)) {
- script_name_label->set_text(c->cast_to<ScriptEditorBase>()->get_name());
- script_icon->set_texture(c->cast_to<ScriptEditorBase>()->get_icon());
+ script_name_label->set_text(Object::cast_to<ScriptEditorBase>(c)->get_name());
+ script_icon->set_texture(Object::cast_to<ScriptEditorBase>(c)->get_icon());
if (is_visible_in_tree())
- c->cast_to<ScriptEditorBase>()->ensure_focus();
+ Object::cast_to<ScriptEditorBase>(c)->ensure_focus();
- notify_script_changed(c->cast_to<ScriptEditorBase>()->get_edited_script());
+ notify_script_changed(Object::cast_to<ScriptEditorBase>(c)->get_edited_script());
}
- if (c->cast_to<EditorHelp>()) {
+ if (Object::cast_to<EditorHelp>(c)) {
- script_name_label->set_text(c->cast_to<EditorHelp>()->get_class());
+ script_name_label->set_text(Object::cast_to<EditorHelp>(c)->get_class());
script_icon->set_texture(get_icon("Help", "EditorIcons"));
if (is_visible_in_tree())
- c->cast_to<EditorHelp>()->set_focused();
+ Object::cast_to<EditorHelp>(c)->set_focused();
}
c->set_meta("__editor_pass", ++edit_pass);
@@ -508,7 +506,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) {
return;
Node *tselected = tab_container->get_child(selected);
- ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
if (current) {
_add_recent_script(current->get_edited_script()->get_path());
if (p_save) {
@@ -517,7 +515,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save) {
current->clear_edit_menu();
notify_script_close(current->get_edited_script());
} else {
- EditorHelp *help = tab_container->get_child(selected)->cast_to<EditorHelp>();
+ EditorHelp *help = Object::cast_to<EditorHelp>(tab_container->get_child(selected));
_add_recent_script(help->get_class());
}
@@ -575,7 +573,7 @@ void ScriptEditor::_close_docs_tab() {
int child_count = tab_container->get_child_count();
for (int i = child_count - 1; i >= 0; i--) {
- EditorHelp *se = tab_container->get_child(i)->cast_to<EditorHelp>();
+ EditorHelp *se = Object::cast_to<EditorHelp>(tab_container->get_child(i));
if (se) {
_close_tab(i);
@@ -589,7 +587,7 @@ void ScriptEditor::_close_all_tabs() {
for (int i = child_count - 1; i >= 0; i--) {
tab_container->set_current_tab(i);
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se) {
@@ -605,7 +603,7 @@ void ScriptEditor::_close_all_tabs() {
}
void ScriptEditor::_ask_close_current_unsaved_tab(ScriptEditorBase *current) {
- erase_tab_confirm->set_text("Close and save changes?\n\"" + current->get_name() + "\"");
+ erase_tab_confirm->set_text(TTR("Close and save changes?\n\"") + current->get_name() + "\"");
erase_tab_confirm->popup_centered_minsize();
}
@@ -615,7 +613,7 @@ void ScriptEditor::_resave_scripts(const String &p_str) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se)
continue;
@@ -647,7 +645,7 @@ void ScriptEditor::_reload_scripts() {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se) {
continue;
@@ -684,7 +682,7 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se) {
continue;
@@ -727,7 +725,7 @@ bool ScriptEditor::_test_script_times_on_disk(Ref<Script> p_for_script) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se) {
Ref<Script> script = se->get_edited_script();
@@ -791,7 +789,7 @@ Ref<Script> ScriptEditor::_get_current_script() {
if (selected < 0 || selected >= tab_container->get_child_count())
return NULL;
- ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
if (current) {
return current->get_edited_script();
} else {
@@ -865,7 +863,7 @@ void ScriptEditor::_menu_option(int p_option) {
String current;
if (tab_container->get_tab_count() > 0) {
- EditorHelp *eh = tab_container->get_child(tab_container->get_current_tab())->cast_to<EditorHelp>();
+ EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(tab_container->get_current_tab()));
if (eh) {
current = eh->get_class();
}
@@ -919,7 +917,7 @@ void ScriptEditor::_menu_option(int p_option) {
if (selected < 0 || selected >= tab_container->get_child_count())
return;
- ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
if (current) {
switch (p_option) {
@@ -956,7 +954,7 @@ void ScriptEditor::_menu_option(int p_option) {
current->convert_indent_to_tabs();
}
}
- editor->push_item(current->get_edited_script()->cast_to<Object>());
+ editor->push_item(Object::cast_to<Object>(current->get_edited_script().ptr()));
editor->save_resource_as(current->get_edited_script());
} break;
@@ -967,7 +965,33 @@ void ScriptEditor::_menu_option(int p_option) {
current->reload(p_option == FILE_TOOL_RELOAD_SOFT);
} break;
+ case FILE_RUN: {
+
+ Ref<Script> scr = current->get_edited_script();
+ if (scr.is_null()) {
+ EditorNode::get_singleton()->show_warning("Can't obtain the script for running");
+ break;
+ }
+ if (!scr->is_tool()) {
+
+ EditorNode::get_singleton()->show_warning("Script is not in tool mode, will not be able to run");
+ return;
+ }
+
+ if (!ClassDB::is_parent_class(scr->get_instance_base_type(), "EditorScript")) {
+
+ EditorNode::get_singleton()->show_warning("To run this script, it must inherit EditorScript and be set to tool mode");
+ return;
+ }
+
+ Ref<EditorScript> es = memnew(EditorScript);
+ es->set_script(scr.get_ref_ptr());
+ es->set_editor(EditorNode::get_singleton());
+ es->_run();
+
+ EditorNode::get_undo_redo()->clear_history();
+ } break;
case FILE_CLOSE: {
if (current->is_unsaved()) {
_ask_close_current_unsaved_tab(current);
@@ -1035,7 +1059,7 @@ void ScriptEditor::_menu_option(int p_option) {
}
} else {
- EditorHelp *help = tab_container->get_current_tab_control()->cast_to<EditorHelp>();
+ EditorHelp *help = Object::cast_to<EditorHelp>(tab_container->get_current_tab_control());
if (help) {
switch (p_option) {
@@ -1127,9 +1151,12 @@ void ScriptEditor::_notification(int p_what) {
tab_container->add_style_override("panel", editor->get_gui_base()->get_stylebox("ScriptPanel", "EditorStyles"));
- Ref<StyleBox> sb = editor->get_gui_base()->get_stylebox("panel", "TabContainer")->duplicate();
- sb->set_default_margin(MARGIN_TOP, 0);
- add_style_override("panel", sb);
+ help_search->set_icon(get_icon("HelpSearch", "EditorIcons"));
+ site_search->set_icon(get_icon("Instance", "EditorIcons"));
+ class_search->set_icon(get_icon("ClassList", "EditorIcons"));
+
+ script_forward->set_icon(get_icon("Forward", "EditorIcons"));
+ script_back->set_icon(get_icon("Back", "EditorIcons"));
} break;
default:
@@ -1143,7 +1170,7 @@ bool ScriptEditor::can_take_away_focus() const {
if (selected < 0 || selected >= tab_container->get_child_count())
return true;
- ScriptEditorBase *current = tab_container->get_child(selected)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *current = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected));
if (!current)
return true;
@@ -1154,7 +1181,7 @@ void ScriptEditor::close_builtin_scripts_from_scene(const String &p_scene) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se) {
@@ -1198,122 +1225,11 @@ static const Node *_find_node_with_script(const Node *p_node, const RefPtr &p_sc
return NULL;
}
-Dictionary ScriptEditor::get_state() const {
-
- //apply_scripts();
-
- Dictionary state;
-#if 0
- Array paths;
- int open=-1;
-
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ScriptTextEditor *se = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
- if (!se)
- continue;
-
-
- Ref<Script> script = se->get_edited_script();
- if (script->get_path()!="" && script->get_path().find("local://")==-1 && script->get_path().find("::")==-1) {
-
- paths.push_back(script->get_path());
- } else {
-
-
- const Node *owner = _find_node_with_script(get_tree()->get_root(),script.get_ref_ptr());
- if (owner)
- paths.push_back(owner->get_path());
-
- }
-
- if (i==tab_container->get_current_tab())
- open=i;
- }
-
- if (paths.size())
- state["sources"]=paths;
- if (open!=-1)
- state["current"]=open;
-
-#endif
- return state;
-}
-void ScriptEditor::set_state(const Dictionary &p_state) {
-
-#if 0
- print_line("attempt set state: "+String(Variant(p_state)));
-
- if (!p_state.has("sources"))
- return; //bleh
-
- Array sources = p_state["sources"];
- for(int i=0;i<sources.size();i++) {
-
- Variant source=sources[i];
-
- Ref<Script> script;
-
- if (source.get_type()==Variant::NODE_PATH) {
-
-
- Node *owner=get_tree()->get_root()->get_node(source);
- if (!owner)
- continue;
-
- script = owner->get_script();
- } else if (source.get_type()==Variant::STRING) {
-
-
- script = ResourceLoader::load(source,"Script");
- }
-
-
- if (script.is_null()) //ah well..
- continue;
-
- editor->call("_resource_selected",script);
- }
-
- if (p_state.has("current")) {
- tab_container->set_current_tab(p_state["current"]);
- }
-#endif
-}
-void ScriptEditor::clear() {
-#if 0
- List<ScriptTextEditor*> stes;
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ScriptTextEditor *se = tab_container->get_child(i)->cast_to<ScriptTextEditor>();
- if (!se)
- continue;
- stes.push_back(se);
-
- }
-
- while(stes.size()) {
-
- memdelete(stes.front()->get());
- stes.pop_front();
- }
-
- int idx = tab_container->get_current_tab();
- if (idx>=tab_container->get_child_count())
- idx=tab_container->get_child_count()-1;
- if (idx>=0) {
- tab_container->set_current_tab(idx);
- script_list->select( script_list->find_metadata(idx) );
- }
-
-#endif
-}
-
void ScriptEditor::get_breakpoints(List<String> *p_breakpoints) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se)
continue;
@@ -1339,10 +1255,8 @@ void ScriptEditor::ensure_focus_current() {
if (cidx < 0 || cidx >= tab_container->get_tab_count())
return;
- Control *c = tab_container->get_child(cidx)->cast_to<Control>();
- if (!c)
- return;
- ScriptEditorBase *se = c->cast_to<ScriptEditorBase>();
+ Control *c = Object::cast_to<Control>(tab_container->get_child(cidx));
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(c);
if (!se)
return;
se->ensure_focus();
@@ -1350,7 +1264,7 @@ void ScriptEditor::ensure_focus_current() {
void ScriptEditor::_members_overview_selected(int p_idx) {
Node *current = tab_container->get_child(tab_container->get_current_tab());
- ScriptEditorBase *se = current->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(current);
if (!se) {
return;
}
@@ -1372,7 +1286,7 @@ void ScriptEditor::ensure_select_current() {
Node *current = tab_container->get_child(tab_container->get_current_tab());
- ScriptEditorBase *se = current->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(current);
if (se) {
Ref<Script> script = se->get_edited_script();
@@ -1384,7 +1298,7 @@ void ScriptEditor::ensure_select_current() {
//search_menu->show();
}
- EditorHelp *eh = current->cast_to<EditorHelp>();
+ EditorHelp *eh = Object::cast_to<EditorHelp>(current);
if (eh) {
//edit_menu->hide();
@@ -1434,7 +1348,7 @@ void ScriptEditor::_update_members_overview_visibility() {
return;
Node *current = tab_container->get_child(tab_container->get_current_tab());
- ScriptEditorBase *se = current->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(current);
if (!se) {
members_overview->set_visible(false);
return;
@@ -1455,7 +1369,7 @@ void ScriptEditor::_update_members_overview() {
return;
Node *current = tab_container->get_child(tab_container->get_current_tab());
- ScriptEditorBase *se = current->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(current);
if (!se) {
return;
}
@@ -1529,7 +1443,7 @@ void ScriptEditor::_update_script_names() {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se) {
String name = se->get_name();
@@ -1572,12 +1486,12 @@ void ScriptEditor::_update_script_names() {
sedata.push_back(sd);
}
- EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>();
+ EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
if (eh) {
String name = eh->get_class();
Ref<Texture> icon = get_icon("Help", "EditorIcons");
- String tooltip = name + " Class Reference";
+ String tooltip = name + TTR(" Class Reference");
_ScriptEditorItemData sd;
sd.icon = icon;
@@ -1667,7 +1581,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se)
continue;
@@ -1715,7 +1629,7 @@ bool ScriptEditor::edit(const Ref<Script> &p_script, int p_line, int p_col, bool
_update_script_names();
_save_layout();
se->connect("name_changed", this, "_update_script_names");
- se->connect("script_changed", this, "_script_changed");
+ se->connect("edited_script_changed", this, "_script_changed");
se->connect("request_help_search", this, "_help_search");
se->connect("request_open_script_at_line", this, "_goto_script_line");
se->connect("go_to_help", this, "_help_class_goto");
@@ -1737,7 +1651,7 @@ void ScriptEditor::save_all_scripts() {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se)
continue;
@@ -1775,7 +1689,7 @@ void ScriptEditor::apply_scripts() const {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se)
continue;
se->apply_code();
@@ -1806,7 +1720,7 @@ void ScriptEditor::_editor_stop() {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se) {
continue;
@@ -1827,7 +1741,7 @@ void ScriptEditor::_add_callback(Object *p_obj, const String &p_function, const
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se)
continue;
if (se->get_edited_script() != script)
@@ -1878,7 +1792,7 @@ void ScriptEditor::_editor_settings_changed() {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se)
continue;
@@ -1981,7 +1895,7 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se) {
String path = se->get_edited_script()->get_path();
@@ -1991,7 +1905,7 @@ void ScriptEditor::get_window_layout(Ref<ConfigFile> p_layout) {
scripts.push_back(path);
}
- EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>();
+ EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
if (eh) {
@@ -2011,7 +1925,7 @@ void ScriptEditor::_help_class_open(const String &p_class) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>();
+ EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
if (eh && eh->get_class() == p_class) {
@@ -2038,7 +1952,7 @@ void ScriptEditor::_help_class_goto(const String &p_desc) {
for (int i = 0; i < tab_container->get_child_count(); i++) {
- EditorHelp *eh = tab_container->get_child(i)->cast_to<EditorHelp>();
+ EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(i));
if (eh && eh->get_class() == cname) {
@@ -2066,7 +1980,7 @@ void ScriptEditor::_update_selected_editor_menu() {
bool current = tab_container->get_current_tab() == i;
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (se && se->get_edit_menu()) {
if (current)
@@ -2076,7 +1990,7 @@ void ScriptEditor::_update_selected_editor_menu() {
}
}
- EditorHelp *eh = tab_container->get_current_tab_control()->cast_to<EditorHelp>();
+ EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_current_tab_control());
if (eh) {
script_search_menu->show();
} else {
@@ -2088,13 +2002,13 @@ void ScriptEditor::_update_history_pos(int p_new_pos) {
Node *n = tab_container->get_current_tab_control();
- if (n->cast_to<ScriptEditorBase>()) {
+ if (Object::cast_to<ScriptEditorBase>(n)) {
- history[history_pos].state = n->cast_to<ScriptEditorBase>()->get_edit_state();
+ history[history_pos].state = Object::cast_to<ScriptEditorBase>(n)->get_edit_state();
}
- if (n->cast_to<EditorHelp>()) {
+ if (Object::cast_to<EditorHelp>(n)) {
- history[history_pos].state = n->cast_to<EditorHelp>()->get_scroll();
+ history[history_pos].state = Object::cast_to<EditorHelp>(n)->get_scroll();
}
history_pos = p_new_pos;
@@ -2102,18 +2016,18 @@ void ScriptEditor::_update_history_pos(int p_new_pos) {
n = history[history_pos].control;
- if (n->cast_to<ScriptEditorBase>()) {
+ if (Object::cast_to<ScriptEditorBase>(n)) {
- n->cast_to<ScriptEditorBase>()->set_edit_state(history[history_pos].state);
- n->cast_to<ScriptEditorBase>()->ensure_focus();
+ Object::cast_to<ScriptEditorBase>(n)->set_edit_state(history[history_pos].state);
+ Object::cast_to<ScriptEditorBase>(n)->ensure_focus();
- notify_script_changed(n->cast_to<ScriptEditorBase>()->get_edited_script());
+ notify_script_changed(Object::cast_to<ScriptEditorBase>(n)->get_edited_script());
}
- if (n->cast_to<EditorHelp>()) {
+ if (Object::cast_to<EditorHelp>(n)) {
- n->cast_to<EditorHelp>()->set_scroll(history[history_pos].state);
- n->cast_to<EditorHelp>()->set_focused();
+ Object::cast_to<EditorHelp>(n)->set_scroll(history[history_pos].state);
+ Object::cast_to<EditorHelp>(n)->set_focused();
}
n->set_meta("__editor_pass", ++edit_pass);
@@ -2141,7 +2055,7 @@ Vector<Ref<Script> > ScriptEditor::get_open_scripts() const {
Vector<Ref<Script> > out_scripts = Vector<Ref<Script> >();
for (int i = 0; i < tab_container->get_child_count(); i++) {
- ScriptEditorBase *se = tab_container->get_child(i)->cast_to<ScriptEditorBase>();
+ ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i));
if (!se)
continue;
out_scripts.push_back(se->get_edited_script());
@@ -2253,8 +2167,8 @@ void ScriptEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_current_script"), &ScriptEditor::_get_current_script);
ClassDB::bind_method(D_METHOD("get_open_scripts"), &ScriptEditor::_get_open_scripts);
- ADD_SIGNAL(MethodInfo("editor_script_changed", PropertyInfo(Variant::OBJECT, "script:Script")));
- ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::OBJECT, "script:Script")));
+ ADD_SIGNAL(MethodInfo("editor_script_changed", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
+ ADD_SIGNAL(MethodInfo("script_close", PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script")));
}
ScriptEditor::ScriptEditor(EditorNode *p_editor) {
@@ -2269,9 +2183,6 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
members_overview_enabled = true;
editor = p_editor;
- Ref<StyleBox> sb = p_editor->get_gui_base()->get_stylebox("panel", "TabContainer")->duplicate();
- sb->set_default_margin(MARGIN_TOP, 0);
- add_style_override("panel", sb);
VBoxContainer *main_container = memnew(VBoxContainer);
add_child(main_container);
@@ -2342,6 +2253,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE);
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL);
file_menu->get_popup()->add_separator();
+ file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/run_file", TTR("Run"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_X), FILE_RUN);
+ file_menu->get_popup()->add_separator();
file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/toggle_scripts_panel", TTR("Toggle Scripts Panel"), KEY_MASK_CMD | KEY_BACKSLASH), TOGGLE_SCRIPTS_PANEL);
file_menu->get_popup()->connect("id_pressed", this, "_menu_option");
@@ -2356,7 +2269,6 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
debug_menu = memnew(MenuButton);
menu_hb->add_child(debug_menu);
debug_menu->set_text(TTR("Debug"));
- debug_menu->get_popup()->add_separator();
debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/step_over", TTR("Step Over"), KEY_F10), DEBUG_NEXT);
debug_menu->get_popup()->add_shortcut(ED_SHORTCUT("debugger/step_into", TTR("Step Into"), KEY_F11), DEBUG_STEP);
debug_menu->get_popup()->add_separator();
@@ -2373,19 +2285,6 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_BREAK), true);
debug_menu->get_popup()->set_item_disabled(debug_menu->get_popup()->get_item_index(DEBUG_CONTINUE), true);
-#if 0
- window_menu = memnew( MenuButton );
- menu_hb->add_child(window_menu);
- window_menu->set_text(TTR("Window"));
- window_menu->get_popup()->add_item(TTR("Close"),WINDOW_CLOSE,KEY_MASK_CMD|KEY_W);
- window_menu->get_popup()->add_separator();
- window_menu->get_popup()->add_item(TTR("Move Left"),WINDOW_MOVE_LEFT,KEY_MASK_CMD|KEY_LEFT);
- window_menu->get_popup()->add_item(TTR("Move Right"),WINDOW_MOVE_RIGHT,KEY_MASK_CMD|KEY_RIGHT);
- window_menu->get_popup()->add_separator();
- window_menu->get_popup()->connect("id_pressed", this,"_menu_option");
-
-#endif
-
menu_hb->add_spacer();
script_icon = memnew(TextureRect);
@@ -2515,17 +2414,17 @@ ScriptEditor::~ScriptEditor() {
void ScriptEditorPlugin::edit(Object *p_object) {
- if (!p_object->cast_to<Script>())
+ if (!Object::cast_to<Script>(p_object))
return;
- script_editor->edit(p_object->cast_to<Script>());
+ script_editor->edit(Object::cast_to<Script>(p_object));
}
bool ScriptEditorPlugin::handles(Object *p_object) const {
- if (p_object->cast_to<Script>()) {
+ if (Object::cast_to<Script>(p_object)) {
- bool valid = _can_open_in_editor(p_object->cast_to<Script>());
+ bool valid = _can_open_in_editor(Object::cast_to<Script>(p_object));
if (!valid) { //user tried to open it by clicking
EditorNode::get_singleton()->show_warning(TTR("Built-in scripts can only be edited when the scene they belong to is loaded"));
@@ -2554,20 +2453,6 @@ void ScriptEditorPlugin::selected_notify() {
script_editor->ensure_select_current();
}
-Dictionary ScriptEditorPlugin::get_state() const {
-
- return script_editor->get_state();
-}
-
-void ScriptEditorPlugin::set_state(const Dictionary &p_state) {
-
- script_editor->set_state(p_state);
-}
-void ScriptEditorPlugin::clear() {
-
- script_editor->clear();
-}
-
void ScriptEditorPlugin::save_external_data() {
script_editor->save_all_scripts();
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index f87a20a1f0..d2677c6a4a 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -131,6 +131,7 @@ class ScriptEditor : public PanelContainer {
FILE_RELOAD_THEME,
FILE_SAVE_THEME,
FILE_SAVE_THEME_AS,
+ FILE_RUN,
FILE_CLOSE,
CLOSE_DOCS,
CLOSE_ALL,
@@ -344,14 +345,8 @@ public:
_FORCE_INLINE_ bool edit(const Ref<Script> &p_script, bool p_grab_focus = true) { return edit(p_script, -1, 0, p_grab_focus); }
bool edit(const Ref<Script> &p_script, int p_line, int p_col, bool p_grab_focus = true);
- Dictionary get_state() const;
- void set_state(const Dictionary &p_state);
- void clear();
-
void get_breakpoints(List<String> *p_breakpoints);
- //void swap_lines(TextEdit *tx, int line1, int line2);
-
void save_all_scripts();
void set_window_layout(Ref<ConfigFile> p_layout);
@@ -398,10 +393,6 @@ public:
virtual void make_visible(bool p_visible);
virtual void selected_notify();
- Dictionary get_state() const;
- virtual void set_state(const Dictionary &p_state);
- virtual void clear();
-
virtual void save_external_data();
virtual void apply_changes();
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 1aa9f04484..a8f1b00776 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -75,9 +75,14 @@ void ScriptTextEditor::_load_theme_settings() {
text_edit->clear_colors();
- /* keyword color */
+ /* color from color_theme or from editor color */
+
+ Color background_color = EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0));
+ if (EDITOR_DEF("text_editor/theme/adapted_code_editor_background_color", false))
+ background_color = get_color("dark_color_1", "Editor");
- text_edit->add_color_override("background_color", EDITOR_DEF("text_editor/highlighting/background_color", Color(0, 0, 0, 0)));
+ /* keyword color */
+ text_edit->add_color_override("background_color", background_color);
text_edit->add_color_override("completion_background_color", EDITOR_DEF("text_editor/highlighting/completion_background_color", Color(0, 0, 0, 0)));
text_edit->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/highlighting/completion_selected_color", Color::html("434244")));
text_edit->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/highlighting/completion_existing_color", Color::html("21dfdfdf")));
@@ -524,7 +529,7 @@ void ScriptTextEditor::_validate_script() {
}
emit_signal("name_changed");
- emit_signal("script_changed");
+ emit_signal("edited_script_changed");
}
static Node *_find_node_for_script(Node *p_base, Node *p_current, const Ref<Script> &p_script) {
@@ -597,13 +602,13 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo
}
}
-void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options) {
+void ScriptTextEditor::_code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options, bool &r_force) {
ScriptTextEditor *ste = (ScriptTextEditor *)p_ud;
- ste->_code_complete_script(p_code, r_options);
+ ste->_code_complete_script(p_code, r_options, r_force);
}
-void ScriptTextEditor::_code_complete_script(const String &p_code, List<String> *r_options) {
+void ScriptTextEditor::_code_complete_script(const String &p_code, List<String> *r_options, bool &r_force) {
if (color_panel->is_visible_in_tree()) return;
Node *base = get_tree()->get_edited_scene_root();
@@ -611,7 +616,7 @@ void ScriptTextEditor::_code_complete_script(const String &p_code, List<String>
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);
+ Error err = script->get_language()->complete_code(p_code, script->get_path().get_base_dir(), base, r_options, r_force, hint);
if (hint != "") {
code_editor->get_text_edit()->set_code_hint(hint);
}
@@ -867,6 +872,21 @@ void ScriptTextEditor::_edit_option(int p_op) {
//tx->deselect();
} break;
+ case EDIT_DELETE_LINE: {
+
+ TextEdit *tx = code_editor->get_text_edit();
+ Ref<Script> scr = get_edited_script();
+ if (scr.is_null())
+ return;
+
+ tx->begin_complex_operation();
+ int line = tx->cursor_get_line();
+ tx->set_line(tx->cursor_get_line(), "");
+ tx->backspace_at_cursor();
+ tx->cursor_set_line(line);
+ tx->end_complex_operation();
+
+ } break;
case EDIT_CLONE_DOWN: {
TextEdit *tx = code_editor->get_text_edit();
@@ -957,16 +977,27 @@ void ScriptTextEditor::_edit_option(int p_op) {
Ref<Script> scr = get_edited_script();
if (scr.is_null())
return;
+
+ te->begin_complex_operation();
int begin, end;
if (te->is_selection_active()) {
begin = te->get_selection_from_line();
end = te->get_selection_to_line();
+ // ignore if the cursor is not past the first column
+ if (te->get_selection_to_column() == 0) {
+ end--;
+ }
} else {
begin = 0;
end = te->get_line_count() - 1;
}
scr->get_language()->auto_indent_code(text, begin, end);
- te->set_text(text);
+ Vector<String> lines = text.split("\n");
+ for (int i = begin; i <= end; ++i) {
+ te->set_line(i, lines[i]);
+ }
+
+ te->end_complex_operation();
} break;
case EDIT_TRIM_TRAILING_WHITESAPCE: {
@@ -1199,7 +1230,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
}
if (res->get_path().is_resource_file()) {
- EditorNode::get_singleton()->show_warning("Only resources from filesystem can be dropped.");
+ EditorNode::get_singleton()->show_warning(TTR("Only resources from filesystem can be dropped."));
return;
}
@@ -1392,6 +1423,7 @@ ScriptTextEditor::ScriptTextEditor() {
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT);
+ edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT);
edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN);
edit_menu->get_popup()->add_separator();
@@ -1466,6 +1498,7 @@ void ScriptTextEditor::register_editor() {
ED_SHORTCUT("script_text_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A);
ED_SHORTCUT("script_text_editor/move_up", TTR("Move Up"), KEY_MASK_ALT | KEY_UP);
ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN);
+ ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KEY_MASK_CTRL | KEY_MASK_SHIFT | KEY_K);
//leave these at zero, same can be accomplished with tab/shift-tab, including selection
//the next/previous in history shortcut in this case makes a lot more sene.
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index e55847832f..f8b7470ec8 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -74,6 +74,7 @@ class ScriptTextEditor : public ScriptEditorBase {
EDIT_MOVE_LINE_DOWN,
EDIT_INDENT_RIGHT,
EDIT_INDENT_LEFT,
+ EDIT_DELETE_LINE,
EDIT_CLONE_DOWN,
EDIT_PICK_COLOR,
EDIT_TO_UPPERCASE,
@@ -93,12 +94,12 @@ class ScriptTextEditor : public ScriptEditorBase {
};
protected:
- static void _code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options);
+ static void _code_complete_scripts(void *p_ud, const String &p_code, List<String> *r_options, bool &r_force);
void _breakpoint_toggled(int p_row);
//no longer virtual
void _validate_script();
- void _code_complete_script(const String &p_code, List<String> *r_options);
+ void _code_complete_script(const String &p_code, List<String> *r_options, bool &r_force);
void _load_theme_settings();
void _notification(int p_what);
diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index bad88979ac..8672892b5a 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -29,20 +29,17 @@
/*************************************************************************/
#include "shader_editor_plugin.h"
+#include "core/io/resource_loader.h"
+#include "core/io/resource_saver.h"
+#include "core/os/keyboard.h"
+#include "core/os/os.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "editor/property_editor.h"
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "os/keyboard.h"
-#include "os/os.h"
#include "scene/resources/shader_graph.h"
#include "servers/visual/shader_types.h"
-#include "spatial_editor_plugin.h"
-/*** SETTINGS EDITOR ****/
-
-/*** SCRIPT EDITOR ****/
+/*** SHADER SCRIPT EDITOR ****/
Ref<Shader> ShaderTextEditor::get_edited_shader() const {
@@ -96,9 +93,9 @@ void ShaderTextEditor::_load_theme_settings() {
if (shader.is_valid()) {
- for (const Map<StringName, Map<StringName, ShaderLanguage::DataType> >::Element *E = ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
+ for (const Map<StringName, ShaderLanguage::FunctionInfo>::Element *E = ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())).front(); E; E = E->next()) {
- for (const Map<StringName, ShaderLanguage::DataType>::Element *F = E->get().front(); F; F = F->next()) {
+ for (const Map<StringName, ShaderLanguage::DataType>::Element *F = E->get().built_ins.front(); F; F = F->next()) {
keywords.push_back(F->key());
}
}
@@ -200,8 +197,6 @@ void ShaderTextEditor::_validate_script() {
}
void ShaderTextEditor::_bind_methods() {
-
- //ADD_SIGNAL( MethodInfo("script_changed") );
}
ShaderTextEditor::ShaderTextEditor() {
@@ -255,9 +250,6 @@ void ShaderEditor::_menu_option(int p_option) {
current->get_find_replace_bar()->popup_replace();
} break;
- //case SEARCH_LOCATE_SYMBOL: {
-
- //} break;
case SEARCH_GOTO_LINE: {
goto_line_dialog->popup_find_line(current->get_text_edit());
@@ -277,90 +269,6 @@ void ShaderEditor::_notification(int p_what) {
}
}
-Dictionary ShaderEditor::get_state() const {
-#if 0
- apply_shaders();
-
- Dictionary state;
-
- Array paths;
- int open=-1;
-
- for(int i=0;i<tab_container->get_child_count();i++) {
-
- ShaderTextEditor *ste = tab_container->get_child(i)->cast_to<ShaderTextEditor>();
- if (!ste)
- continue;
-
-
- Ref<Shader> shader = ste->get_edited_shader();
- if (shader->get_path()!="" && shader->get_path().find("local://")==-1 && shader->get_path().find("::")==-1) {
-
- paths.push_back(shader->get_path());
- } else {
-
-
- const Node *owner = _find_node_with_shader(get_root_node(),shader.get_ref_ptr());
- if (owner)
- paths.push_back(owner->get_path());
-
- }
-
- if (i==tab_container->get_current_tab())
- open=i;
- }
-
- if (paths.size())
- state["sources"]=paths;
- if (open!=-1)
- state["current"]=open;
-
-
- return state;
-#endif
- return Dictionary();
-}
-void ShaderEditor::set_state(const Dictionary &p_state) {
-#if 0
- print_line("setting state..");
- if (!p_state.has("sources"))
- return; //bleh
-
- Array sources = p_state["sources"];
- for(int i=0;i<sources.size();i++) {
-
- Variant source=sources[i];
-
- Ref<Shader> shader;
-
- if (source.get_type()==Variant::NODE_PATH) {
-
- print_line("cain find owner at path "+String(source));
- Node *owner=get_root_node()->get_node(source);
- if (!owner)
- continue;
-
- shader = owner->get_shader();
- } else if (source.get_type()==Variant::STRING) {
-
- print_line("loading at path "+String(source));
- shader = ResourceLoader::load(source,"Shader");
- }
-
- print_line("found shader at "+String(source)+"? - "+itos(shader.is_null()));
- if (shader.is_null()) //ah well..
- continue;
-
- get_scene()->get_root_node()->call("_resource_selected",shader);
- }
-
- if (p_state.has("current"))
- tab_container->set_current_tab(p_state["current"]);
-#endif
-}
-void ShaderEditor::clear() {
-}
-
void ShaderEditor::_params_changed() {
shader_editor->_validate_script();
@@ -397,7 +305,7 @@ void ShaderEditor::ensure_select_current() {
/*
if (tab_container->get_child_count() && tab_container->get_current_tab()>=0) {
- ShaderTextEditor *ste = tab_container->get_child(tab_container->get_current_tab())->cast_to<ShaderTextEditor>();
+ ShaderTextEditor *ste = Object::cast_to<ShaderTextEditor>(tab_container->get_child(tab_container->get_current_tab()));
if (!ste)
return;
Ref<Shader> shader = ste->get_edited_shader();
@@ -486,16 +394,16 @@ ShaderEditor::ShaderEditor() {
void ShaderEditorPlugin::edit(Object *p_object) {
- Shader *s = p_object->cast_to<Shader>();
+ Shader *s = Object::cast_to<Shader>(p_object);
shader_editor->edit(s);
}
bool ShaderEditorPlugin::handles(Object *p_object) const {
bool handles = true;
- Shader *shader = p_object->cast_to<Shader>();
+ Shader *shader = Object::cast_to<Shader>(p_object);
/*
- if (!shader || shader->cast_to<ShaderGraph>()) // Don't handle ShaderGraph's
+ if (Object::cast_to<ShaderGraph>(shader)) // Don't handle ShaderGraph's
handles = false;
*/
@@ -522,20 +430,6 @@ void ShaderEditorPlugin::selected_notify() {
shader_editor->ensure_select_current();
}
-Dictionary ShaderEditorPlugin::get_state() const {
-
- return shader_editor->get_state();
-}
-
-void ShaderEditorPlugin::set_state(const Dictionary &p_state) {
-
- shader_editor->set_state(p_state);
-}
-void ShaderEditorPlugin::clear() {
-
- shader_editor->clear();
-}
-
void ShaderEditorPlugin::save_external_data() {
shader_editor->save_external_data();
diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h
index 8625267a63..ab18784d9f 100644
--- a/editor/plugins/shader_editor_plugin.h
+++ b/editor/plugins/shader_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -77,7 +77,6 @@ class ShaderEditor : public VBoxContainer {
SEARCH_FIND_NEXT,
SEARCH_FIND_PREV,
SEARCH_REPLACE,
- //SEARCH_LOCATE_SYMBOL,
SEARCH_GOTO_LINE,
};
@@ -108,10 +107,6 @@ public:
void ensure_select_current();
void edit(const Ref<Shader> &p_shader);
- Dictionary get_state() const;
- void set_state(const Dictionary &p_state);
- void clear();
-
virtual Size2 get_minimum_size() const { return Size2(0, 200); }
void save_external_data();
@@ -135,10 +130,6 @@ public:
virtual void make_visible(bool p_visible);
virtual void selected_notify();
- Dictionary get_state() const;
- virtual void set_state(const Dictionary &p_state);
- virtual void clear();
-
virtual void save_external_data();
virtual void apply_changes();
diff --git a/editor/plugins/shader_graph_editor_plugin.cpp b/editor/plugins/shader_graph_editor_plugin.cpp
index 5506c035ec..732344cb78 100644
--- a/editor/plugins/shader_graph_editor_plugin.cpp
+++ b/editor/plugins/shader_graph_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -27,9 +27,11 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "shader_graph_editor_plugin.h"
+// FIXME: Godot 3.0 broke compatibility with ShaderGraphEditorPlugin,
+// it needs to be ported to the new shader language.
#if 0
+#include "shader_graph_editor_plugin.h"
#include "canvas_item_editor_plugin.h"
#include "os/keyboard.h"
@@ -539,22 +541,7 @@ void GraphCurveMapEdit::_plot_curve(const Vector2& p_a,const Vector2& p_b,const
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
+ if ((lastx != newx) || (lasty != newy)) {
draw_line(Vector2(lastx,ymax-lasty),Vector2(newx,ymax-newy),Color(0.8,0.8,0.8,0.8),2.0);
}
@@ -839,7 +826,7 @@ void ShaderGraphView::_vec_input_changed(double p_value, int p_id,Array p_arr){
void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){
- ToolButton *tb = p_button->cast_to<ToolButton>();
+ ToolButton *tb = Object::cast_to<ToolButton>(p_button);
ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height));
ped_popup->set_size(tb->get_size());
edited_id=p_id;
@@ -850,7 +837,7 @@ void ShaderGraphView::_xform_input_changed(int p_id, Node *p_button){
}
void ShaderGraphView::_xform_const_changed(int p_id, Node *p_button){
- ToolButton *tb = p_button->cast_to<ToolButton>();
+ ToolButton *tb = Object::cast_to<ToolButton>(p_button);
ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height));
ped_popup->set_size(tb->get_size());
edited_id=p_id;
@@ -964,7 +951,7 @@ void ShaderGraphView::_variant_edited() {
void ShaderGraphView::_comment_edited(int p_id,Node* p_button) {
UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
- TextEdit *te=p_button->cast_to<TextEdit>();
+ TextEdit *te=Object::cast_to<TextEdit>(p_button);
ur->create_action(TTR("Change Comment"),UndoRedo::MERGE_ENDS);
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));
@@ -978,7 +965,7 @@ void ShaderGraphView::_comment_edited(int p_id,Node* p_button) {
void ShaderGraphView::_color_ramp_changed(int p_id,Node* p_ramp) {
- GraphColorRampEdit *cr=p_ramp->cast_to<GraphColorRampEdit>();
+ GraphColorRampEdit *cr=Object::cast_to<GraphColorRampEdit>(p_ramp);
UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
@@ -1020,7 +1007,7 @@ void ShaderGraphView::_color_ramp_changed(int p_id,Node* p_ramp) {
void ShaderGraphView::_curve_changed(int p_id,Node* p_curve) {
- GraphCurveMapEdit *cr=p_curve->cast_to<GraphCurveMapEdit>();
+ GraphCurveMapEdit *cr=Object::cast_to<GraphCurveMapEdit>(p_curve);
UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
@@ -1057,7 +1044,7 @@ void ShaderGraphView::_curve_changed(int p_id,Node* p_curve) {
void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node *p_line_edit) {
- LineEdit *le=p_line_edit->cast_to<LineEdit>();
+ LineEdit *le=Object::cast_to<LineEdit>(p_line_edit);
ERR_FAIL_COND(!le);
UndoRedo *ur=EditorNode::get_singleton()->get_undo_redo();
@@ -1074,7 +1061,7 @@ void ShaderGraphView::_input_name_changed(const String& p_name, int p_id, Node *
void ShaderGraphView::_tex_edited(int p_id,Node* p_button) {
- ToolButton *tb = p_button->cast_to<ToolButton>();
+ ToolButton *tb = Object::cast_to<ToolButton>(p_button);
ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height));
ped_popup->set_size(tb->get_size());
edited_id=p_id;
@@ -1084,7 +1071,7 @@ void ShaderGraphView::_tex_edited(int p_id,Node* p_button) {
void ShaderGraphView::_cube_edited(int p_id,Node* p_button) {
- ToolButton *tb = p_button->cast_to<ToolButton>();
+ ToolButton *tb = Object::cast_to<ToolButton>(p_button);
ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height));
ped_popup->set_size(tb->get_size());
edited_id=p_id;
@@ -1299,7 +1286,7 @@ void ShaderGraphView::_delete_nodes_request()
void ShaderGraphView::_default_changed(int p_id, Node *p_button, int p_param, int v_type, String p_hint)
{
- ToolButton *tb = p_button->cast_to<ToolButton>();
+ ToolButton *tb = Object::cast_to<ToolButton>(p_button);
ped_popup->set_position(tb->get_global_position()+Vector2(0,tb->get_size().height));
ped_popup->set_size(tb->get_size());
edited_id=p_id;
@@ -2530,7 +2517,7 @@ void ShaderGraphView::_sg_updated() {
Variant ShaderGraphView::get_drag_data_fw(const Point2 &p_point, Control *p_from)
{
- TextureRect* frame = p_from->cast_to<TextureRect>();
+ TextureRect* frame = Object::cast_to<TextureRect>(p_from);
if (!frame)
return Variant();
@@ -2556,7 +2543,7 @@ bool ShaderGraphView::can_drop_data_fw(const Point2 &p_point, const Variant &p_d
if (val.get_type()==Variant::OBJECT) {
RES res = val;
- if (res.is_valid() && res->cast_to<Texture>())
+ if (res.is_valid() && Object::cast_to<Texture>(res))
return true;
}
}
@@ -2576,7 +2563,7 @@ void ShaderGraphView::drop_data_fw(const Point2 &p_point, const Variant &p_data,
if (!can_drop_data_fw(p_point, p_data, p_from))
return;
- TextureRect *frame = p_from->cast_to<TextureRect>();
+ TextureRect *frame = Object::cast_to<TextureRect>(p_from);
if (!frame)
return;
@@ -2590,20 +2577,20 @@ void ShaderGraphView::drop_data_fw(const Point2 &p_point, const Variant &p_data,
if (val.get_type()==Variant::OBJECT) {
RES res = val;
if (res.is_valid())
- tex = Ref<Texture>(res->cast_to<Texture>());
+ tex = Ref<Texture>(Object::cast_to<Texture>(*res));
}
}
else if (d["type"] == "files" && d.has("files")) {
Vector<String> files = d["files"];
RES res = ResourceLoader::load(files[0]);
if (res.is_valid())
- tex = Ref<Texture>(res->cast_to<Texture>());
+ tex = Ref<Texture>(Object::cast_to<Texture>(*res));
}
}
if (!tex.is_valid()) return;
- GraphNode *gn = frame->get_parent()->cast_to<GraphNode>();
+ GraphNode *gn = Object::cast_to<GraphNode>(frame->get_parent());
if (!gn) return;
int id = -1;
@@ -2896,12 +2883,12 @@ ShaderGraphEditor::ShaderGraphEditor(bool p_2d) {
void ShaderGraphEditorPlugin::edit(Object *p_object) {
- shader_editor->edit(p_object->cast_to<ShaderGraph>());
+ shader_editor->edit(Object::cast_to<ShaderGraph>(p_object));
}
bool ShaderGraphEditorPlugin::handles(Object *p_object) const {
- ShaderGraph *shader=p_object->cast_to<ShaderGraph>();
+ ShaderGraph *shader=Object::cast_to<ShaderGraph>(p_object);
if (!shader)
return false;
if (_2d)
diff --git a/editor/plugins/shader_graph_editor_plugin.h b/editor/plugins/shader_graph_editor_plugin.h
index e7cab50d8d..f53dd8200d 100644
--- a/editor/plugins/shader_graph_editor_plugin.h
+++ b/editor/plugins/shader_graph_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -30,6 +30,10 @@
#ifndef SHADER_GRAPH_EDITOR_PLUGIN_H
#define SHADER_GRAPH_EDITOR_PLUGIN_H
+// FIXME: Godot 3.0 broke compatibility with ShaderGraphEditorPlugin,
+// it needs to be ported to the new shader language.
+#if 0
+
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "editor/property_editor.h"
@@ -39,11 +43,11 @@
#include "scene/gui/tree.h"
#include "scene/resources/shader.h"
#include "scene/resources/shader_graph.h"
+
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-#if 0
class GraphColorRampEdit : public Control {
GDCLASS(GraphColorRampEdit,Control);
@@ -238,5 +242,6 @@ public:
~ShaderGraphEditorPlugin();
};
+
#endif
-#endif
+#endif // SHADER_GRAPH_EDITOR_PLUGIN_H
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 5faacf7a67..bc5c700959 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -50,6 +50,9 @@
#define GIZMO_RING_HALF_WIDTH 0.1
//#define GIZMO_SCALE_DEFAULT 0.28
#define GIZMO_SCALE_DEFAULT 0.15
+#define GIZMO_PLANE_SIZE 0.2
+#define GIZMO_PLANE_DST 0.3
+#define GIZMO_CIRCLE_SIZE 0.9
#define ZOOM_MIN_DISTANCE 0.001
#define ZOOM_MULTIPLIER 1.08
@@ -63,17 +66,47 @@
#define MIN_FOV 0.01
#define MAX_FOV 179
-void SpatialEditorViewport::_update_camera() {
+void SpatialEditorViewport::_update_camera(float p_interp_delta) {
if (orthogonal) {
//camera->set_orthogonal(size.width*cursor.distance,get_znear(),get_zfar());
camera->set_orthogonal(2 * cursor.distance, 0.1, 8192);
} else
camera->set_perspective(get_fov(), get_znear(), get_zfar());
- Transform camera_transform = to_camera_transform(cursor);
+ Transform new_transform = to_camera_transform(cursor);
+ Transform old_transform = camera->get_global_transform();
+ Transform transform;
- if (camera->get_global_transform() != camera_transform) {
- camera->set_global_transform(camera_transform);
+ bool disable_interp = (Input::get_singleton()->get_mouse_button_mask() & (2 | 4)) || Input::get_singleton()->is_key_pressed(KEY_SHIFT) || Input::get_singleton()->is_key_pressed(KEY_ALT) || Input::get_singleton()->is_key_pressed(KEY_CONTROL);
+
+ if (p_interp_delta && !disable_interp) {
+ //interpolate
+ float interp_speed = 14; //maybe should be made configuration
+ transform = old_transform.interpolate_with(new_transform, MIN(1.0, p_interp_delta * interp_speed));
+ } else {
+ transform = new_transform;
+ }
+
+ float tolerance = 0.0001;
+ bool equal = true;
+ for (int i = 0; i < 3; i++) {
+ if (transform.basis[i].distance_to(old_transform.basis[i]) > tolerance) {
+ equal = false;
+ break;
+ }
+ }
+
+ if (equal && transform.origin.distance_to(old_transform.origin) > tolerance) {
+ equal = false;
+ }
+
+ if (equal) {
+ transform = new_transform;
+ }
+
+ if (!equal || p_interp_delta == 0) {
+ //print_line(transform);
+ camera->set_global_transform(transform);
update_transform_gizmo_view();
}
}
@@ -143,7 +176,7 @@ int SpatialEditorViewport::get_selected_count() const {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->key()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->key());
if (!sp)
continue;
@@ -218,11 +251,7 @@ void SpatialEditorViewport::_select_clicked(bool p_append, bool p_single) {
if (!clicked)
return;
- Object *obj = ObjectDB::get_instance(clicked);
- if (!obj)
- return;
-
- Spatial *sp = obj->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(ObjectDB::get_instance(clicked));
if (!sp)
return;
@@ -261,21 +290,15 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
Vector<ObjectID> instances = VisualServer::get_singleton()->instances_cull_ray(pos, ray, get_tree()->get_root()->get_world()->get_scenario());
Set<Ref<SpatialEditorGizmo> > found_gizmos;
+ Node *edited_scene = get_tree()->get_edited_scene_root();
ObjectID closest = 0;
Spatial *item = NULL;
float closest_dist = 1e20;
int selected_handle = -1;
- Vector<Spatial *> subscenes = Vector<Spatial *>();
- Vector<Vector3> subscenes_positions = Vector<Vector3>();
-
for (int i = 0; i < instances.size(); i++) {
- Object *obj = ObjectDB::get_instance(instances[i]);
- if (!obj)
- continue;
-
- Spatial *spat = obj->cast_to<Spatial>();
+ Spatial *spat = Object::cast_to<Spatial>(ObjectDB::get_instance(instances[i]));
if (!spat)
continue;
@@ -283,19 +306,6 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
Ref<SpatialEditorGizmo> seg = spat->get_gizmo();
if ((!seg.is_valid()) || found_gizmos.has(seg)) {
-
- Node *subscene_candidate = spat;
- Vector3 source_click_spatial_pos = spat->get_global_transform().origin;
-
- while ((subscene_candidate->get_owner() != NULL) && (subscene_candidate->get_owner() != editor->get_edited_scene()))
- subscene_candidate = subscene_candidate->get_owner();
-
- spat = subscene_candidate->cast_to<Spatial>();
- if (spat && (spat->get_filename() != "") && (subscene_candidate->get_owner() != NULL)) {
- subscenes.push_back(spat);
- subscenes_positions.push_back(source_click_spatial_pos);
- }
-
continue;
}
@@ -315,32 +325,26 @@ ObjectID SpatialEditorViewport::_select_ray(const Point2 &p_pos, bool p_append,
continue;
if (dist < closest_dist) {
- closest = instances[i];
- closest_dist = dist;
- selected_handle = handle;
- item = spat;
+ //make sure that whathever is selected is editable
+ while (spat && spat != edited_scene && spat->get_owner() != edited_scene && !edited_scene->is_editable_instance(spat->get_owner())) {
+
+ spat = Object::cast_to<Spatial>(spat->get_owner());
+ }
+
+ if (spat) {
+ item = spat;
+ closest = spat->get_instance_id();
+ closest_dist = dist;
+ selected_handle = handle;
+ } else {
+ ERR_PRINT("Bug?");
+ }
}
// if (editor_selection->is_selected(spat))
// r_includes_current=true;
}
- for (int idx_subscene = 0; idx_subscene < subscenes.size(); idx_subscene++) {
-
- Spatial *subscene = subscenes.get(idx_subscene);
- float dist = ray.cross(subscenes_positions.get(idx_subscene) - pos).length();
-
- if ((dist < 0) || (dist > 1.2))
- continue;
-
- if (dist < closest_dist) {
- closest = subscene->get_instance_id();
- closest_dist = dist;
- item = subscene;
- selected_handle = -1;
- }
- }
-
if (!item)
return 0;
@@ -365,12 +369,7 @@ void SpatialEditorViewport::_find_items_at_pos(const Point2 &p_pos, bool &r_incl
for (int i = 0; i < instances.size(); i++) {
- Object *obj = ObjectDB::get_instance(instances[i]);
-
- if (!obj)
- continue;
-
- Spatial *spat = obj->cast_to<Spatial>();
+ Spatial *spat = Object::cast_to<Spatial>(ObjectDB::get_instance(instances[i]));
if (!spat)
continue;
@@ -480,10 +479,7 @@ void SpatialEditorViewport::_select_region() {
for (int i = 0; i < instances.size(); i++) {
- Object *obj = ObjectDB::get_instance(instances[i]);
- if (!obj)
- continue;
- Spatial *sp = obj->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(ObjectDB::get_instance(instances[i]));
if (!sp)
continue;
@@ -524,7 +520,7 @@ void SpatialEditorViewport::_compute_edit(const Point2 &p_point) {
//int nc=0;
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -595,6 +591,7 @@ bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hig
float grabber_radius = gs * GIZMO_ARROW_SIZE;
Vector3 r;
+
if (Geometry::segment_intersects_sphere(ray_pos, ray_pos + ray * 10000.0, grabber_pos, grabber_radius, &r)) {
float d = r.distance_to(ray_pos);
if (d < col_d) {
@@ -604,17 +601,49 @@ bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hig
}
}
+ bool is_plane_translate = false;
+ // second try
+ if (col_axis == -1) {
+ col_d = 1e20;
+
+ for (int i = 0; i < 3; i++) {
+
+ Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized();
+ Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized();
+
+ Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST);
+
+ Vector3 r;
+ Plane plane(gt.origin, gt.basis.get_axis(i).normalized());
+
+ if (plane.intersects_ray(ray_pos, ray, &r)) {
+
+ float dist = r.distance_to(grabber_pos);
+ if (dist < (gs * GIZMO_PLANE_SIZE)) {
+
+ float d = ray_pos.distance_to(r);
+ if (d < col_d) {
+ col_d = d;
+ col_axis = i;
+
+ is_plane_translate = true;
+ }
+ }
+ }
+ }
+ }
+
if (col_axis != -1) {
if (p_highlight_only) {
- spatial_editor->select_gizmo_highlight_axis(col_axis);
+ spatial_editor->select_gizmo_highlight_axis(col_axis + (is_plane_translate ? 6 : 0));
} else {
- //handle rotate
+ //handle plane translate
_edit.mode = TRANSFORM_TRANSLATE;
_compute_edit(Point2(p_screenpos.x, p_screenpos.y));
- _edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis);
+ _edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis + (is_plane_translate ? 3 : 0));
}
return true;
}
@@ -634,7 +663,7 @@ bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hig
float dist = r.distance_to(gt.origin);
- if (dist > gs * (1 - GIZMO_RING_HALF_WIDTH) && dist < gs * (1 + GIZMO_RING_HALF_WIDTH)) {
+ if (dist > gs * (GIZMO_CIRCLE_SIZE - GIZMO_RING_HALF_WIDTH) && dist < gs * (GIZMO_CIRCLE_SIZE + GIZMO_RING_HALF_WIDTH)) {
float d = ray_pos.distance_to(r);
if (d < col_d) {
@@ -796,7 +825,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -928,7 +957,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (get_selected_count() == 0)
break; //bye
- //handle rotate
+ //handle translate
_edit.mode = TRANSFORM_TRANSLATE;
_compute_edit(b->get_position());
break;
@@ -967,22 +996,18 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (clicked && gizmo_handle >= 0) {
- Object *obj = ObjectDB::get_instance(clicked);
- if (obj) {
-
- Spatial *spa = obj->cast_to<Spatial>();
- if (spa) {
+ Spatial *spa = Object::cast_to<Spatial>(ObjectDB::get_instance(clicked));
+ if (spa) {
- Ref<SpatialEditorGizmo> seg = spa->get_gizmo();
- if (seg.is_valid()) {
+ Ref<SpatialEditorGizmo> seg = spa->get_gizmo();
+ if (seg.is_valid()) {
- _edit.gizmo = seg;
- _edit.gizmo_handle = gizmo_handle;
- //_edit.gizmo_initial_pos=seg->get_handle_pos(gizmo_handle);
- _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle);
- //print_line("GIZMO: "+itos(gizmo_handle)+" FROMPOS: "+_edit.orig_gizmo_pos);
- break;
- }
+ _edit.gizmo = seg;
+ _edit.gizmo_handle = gizmo_handle;
+ //_edit.gizmo_initial_pos=seg->get_handle_pos(gizmo_handle);
+ _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle);
+ //print_line("GIZMO: "+itos(gizmo_handle)+" FROMPOS: "+_edit.orig_gizmo_pos);
+ break;
}
}
//_compute_edit(Point2(b.x,b.y)); //in case a motion happens..
@@ -1018,7 +1043,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -1162,7 +1187,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -1186,6 +1211,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Vector3 motion_mask;
Plane plane;
+ bool plane_mv;
switch (_edit.plane) {
case TRANSFORM_VIEW:
@@ -1204,6 +1230,21 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2);
plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized());
break;
+ case TRANSFORM_YZ:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2) + spatial_editor->get_gizmo_transform().basis.get_axis(1);
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(0));
+ plane_mv = true;
+ break;
+ case TRANSFORM_XZ:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2) + spatial_editor->get_gizmo_transform().basis.get_axis(0);
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(1));
+ plane_mv = true;
+ break;
+ case TRANSFORM_XY:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(0) + spatial_editor->get_gizmo_transform().basis.get_axis(1);
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(2));
+ plane_mv = true;
+ break;
}
Vector3 intersection;
@@ -1217,7 +1258,10 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
//_validate_selection();
Vector3 motion = intersection - click;
if (motion_mask != Vector3()) {
- motion = motion_mask.dot(motion) * motion_mask;
+ if (plane_mv)
+ motion *= motion_mask;
+ else
+ motion = motion_mask.dot(motion) * motion_mask;
}
//set_message("Translating: "+motion);
@@ -1236,7 +1280,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
Spatial *node = NULL;
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp) {
continue;
}
@@ -1264,7 +1308,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp) {
continue;
}
@@ -1334,7 +1378,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -1453,8 +1497,12 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
case NAVIGATION_ORBIT: {
Point2i relative = _get_warped_mouse_motion(m);
- cursor.x_rot += relative.y / 80.0;
- cursor.y_rot += relative.x / 80.0;
+
+ real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/orbit_sensitivity");
+ real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel);
+
+ cursor.x_rot += relative.y * radians_per_pixel;
+ cursor.y_rot += relative.x * radians_per_pixel;
if (cursor.x_rot > Math_PI / 2.0)
cursor.x_rot = Math_PI / 2.0;
if (cursor.x_rot < -Math_PI / 2.0)
@@ -1468,8 +1516,12 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
// It technically works too in ortho, but it's awful for a user due to fov being near zero
if (!orthogonal) {
Point2i relative = _get_warped_mouse_motion(m);
- cursor.x_rot += relative.y / 120.0;
- cursor.y_rot += relative.x / 120.0;
+
+ real_t degrees_per_pixel = EditorSettings::get_singleton()->get("editors/3d/orbit_sensitivity");
+ real_t radians_per_pixel = Math::deg2rad(degrees_per_pixel);
+
+ cursor.x_rot += relative.y * radians_per_pixel;
+ cursor.y_rot += relative.x * radians_per_pixel;
if (cursor.x_rot > Math_PI / 2.0)
cursor.x_rot = Math_PI / 2.0;
if (cursor.x_rot < -Math_PI / 2.0)
@@ -1561,7 +1613,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -1611,68 +1663,78 @@ Point2i SpatialEditorViewport::_get_warped_mouse_motion(const Ref<InputEventMous
void SpatialEditorViewport::_update_freelook(real_t delta) {
- if (!is_freelook_active())
+ if (!is_freelook_active()) {
+ freelook_velocity = Vector3();
return;
+ }
Vector3 forward = camera->get_transform().basis.xform(Vector3(0, 0, -1));
Vector3 right = camera->get_transform().basis.xform(Vector3(1, 0, 0));
Vector3 up = camera->get_transform().basis.xform(Vector3(0, 1, 0));
- int key_left = ED_GET_SHORTCUT("spatial_editor/freelook_left")->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
- int key_right = ED_GET_SHORTCUT("spatial_editor/freelook_right")->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
- int key_forward = ED_GET_SHORTCUT("spatial_editor/freelook_forward")->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
- int key_backwards = ED_GET_SHORTCUT("spatial_editor/freelook_backwards")->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
- int key_up = ED_GET_SHORTCUT("spatial_editor/freelook_up")->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
- int key_down = ED_GET_SHORTCUT("spatial_editor/freelook_down")->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
- int key_speed_modifier = ED_GET_SHORTCUT("spatial_editor/freelook_speed_modifier")->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
+ int key_left = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_left")->get_shortcut().ptr())->get_scancode();
+ int key_right = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_right")->get_shortcut().ptr())->get_scancode();
+ int key_forward = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_forward")->get_shortcut().ptr())->get_scancode();
+ int key_backwards = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_backwards")->get_shortcut().ptr())->get_scancode();
+ int key_up = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_up")->get_shortcut().ptr())->get_scancode();
+ int key_down = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_down")->get_shortcut().ptr())->get_scancode();
+ int key_speed_modifier = Object::cast_to<InputEventKey>(ED_GET_SHORTCUT("spatial_editor/freelook_speed_modifier")->get_shortcut().ptr())->get_scancode();
- Vector3 velocity;
+ Vector3 direction;
bool pressed = false;
bool speed_modifier = false;
const Input &input = *Input::get_singleton();
if (input.is_key_pressed(key_left)) {
- velocity -= right;
+ direction -= right;
pressed = true;
}
if (input.is_key_pressed(key_right)) {
- velocity += right;
+ direction += right;
pressed = true;
}
if (input.is_key_pressed(key_forward)) {
- velocity += forward;
+ direction += forward;
pressed = true;
}
if (input.is_key_pressed(key_backwards)) {
- velocity -= forward;
+ direction -= forward;
pressed = true;
}
if (input.is_key_pressed(key_up)) {
- velocity += up;
+ direction += up;
pressed = true;
}
if (input.is_key_pressed(key_down)) {
- velocity -= up;
+ direction -= up;
pressed = true;
}
if (input.is_key_pressed(key_speed_modifier)) {
speed_modifier = true;
}
- if (pressed) {
- const EditorSettings &s = *EditorSettings::get_singleton();
- const real_t base_speed = s.get("editors/3d/freelook_base_speed");
- const real_t modifier_speed_factor = s.get("editors/3d/freelook_modifier_speed_factor");
+ const EditorSettings &s = *EditorSettings::get_singleton();
+ real_t inertia = s.get("editors/3d/freelook_inertia");
+ if (inertia < 0)
+ inertia = 0;
- real_t speed = base_speed * cursor.distance;
- if (speed_modifier)
- speed *= modifier_speed_factor;
+ const real_t base_speed = s.get("editors/3d/freelook_base_speed");
+ const real_t modifier_speed_factor = s.get("editors/3d/freelook_modifier_speed_factor");
- velocity.normalize();
+ real_t speed = base_speed * cursor.distance;
+ if (speed_modifier)
+ speed *= modifier_speed_factor;
- cursor.pos += velocity * (speed * delta);
- }
+ Vector3 instant_velocity = direction * speed;
+
+ // Higher inertia should increase "lag" (lerp with factor between 0 and 1)
+ // Inertia of zero should produce instant movement (lerp with factor of 1)
+ // Takes reference of 60fps for units, so that inertia of 1 gives approximate lerp factor of 0.5
+ real_t factor = 1.0 / (1.0 + inertia * delta * 60.f);
+ freelook_velocity = freelook_velocity.linear_interpolate(instant_velocity, CLAMP(factor, 0, 1));
+
+ cursor.pos += freelook_velocity * delta;
}
void SpatialEditorViewport::set_message(String p_message, float p_time) {
@@ -1690,7 +1752,7 @@ void SpatialEditorViewport::_notification(int p_what) {
set_process(visible);
if (visible)
- _update_camera();
+ _update_camera(0);
call_deferred("update_transform_gizmo_view");
}
@@ -1722,7 +1784,7 @@ void SpatialEditorViewport::_notification(int p_what) {
_update_freelook(delta);
- _update_camera();
+ _update_camera(get_process_delta_time());
Map<Node *, Object *> &selection = editor_selection->get_selection();
@@ -1731,7 +1793,7 @@ void SpatialEditorViewport::_notification(int p_what) {
for (Map<Node *, Object *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->key()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->key());
if (!sp)
continue;
@@ -1739,7 +1801,7 @@ void SpatialEditorViewport::_notification(int p_what) {
if (!se)
continue;
- VisualInstance *vi = sp->cast_to<VisualInstance>();
+ VisualInstance *vi = Object::cast_to<VisualInstance>(sp);
if (se->aabb.has_no_surface()) {
@@ -1748,7 +1810,11 @@ void SpatialEditorViewport::_notification(int p_what) {
Transform t = sp->get_global_transform();
t.translate(se->aabb.position);
- t.basis.scale(se->aabb.size);
+
+ // apply AABB scaling before item's global transform
+ Basis aabb_s;
+ aabb_s.scale(se->aabb.size);
+ t.basis = t.basis * aabb_s;
exist = true;
if (se->last_xform == t)
@@ -2025,7 +2091,7 @@ void SpatialEditorViewport::_menu_option(int p_option) {
undo_redo->create_action(TTR("Align with view"));
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -2174,6 +2240,14 @@ void SpatialEditorViewport::_init_gizmo_instance(int p_idx) {
VS::get_singleton()->instance_geometry_set_cast_shadows_setting(move_gizmo_instance[i], VS::SHADOW_CASTING_SETTING_OFF);
VS::get_singleton()->instance_set_layer_mask(move_gizmo_instance[i], layer);
+ move_plane_gizmo_instance[i] = VS::get_singleton()->instance_create();
+ VS::get_singleton()->instance_set_base(move_plane_gizmo_instance[i], spatial_editor->get_move_plane_gizmo(i)->get_rid());
+ VS::get_singleton()->instance_set_scenario(move_plane_gizmo_instance[i], get_tree()->get_root()->get_world()->get_scenario());
+ VS::get_singleton()->instance_set_visible(move_plane_gizmo_instance[i], false);
+ //VS::get_singleton()->instance_geometry_set_flag(move_plane_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true);
+ VS::get_singleton()->instance_geometry_set_cast_shadows_setting(move_plane_gizmo_instance[i], VS::SHADOW_CASTING_SETTING_OFF);
+ VS::get_singleton()->instance_set_layer_mask(move_plane_gizmo_instance[i], layer);
+
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_tree()->get_root()->get_world()->get_scenario());
@@ -2188,6 +2262,7 @@ void SpatialEditorViewport::_finish_gizmo_instances() {
for (int i = 0; i < 3; i++) {
VS::get_singleton()->free(move_gizmo_instance[i]);
+ VS::get_singleton()->free(move_plane_gizmo_instance[i]);
VS::get_singleton()->free(rotate_gizmo_instance[i]);
}
}
@@ -2279,6 +2354,8 @@ void SpatialEditorViewport::update_transform_gizmo_view() {
for (int i = 0; i < 3; i++) {
VisualServer::get_singleton()->instance_set_transform(move_gizmo_instance[i], xform);
VisualServer::get_singleton()->instance_set_visible(move_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_MOVE));
+ VisualServer::get_singleton()->instance_set_transform(move_plane_gizmo_instance[i], xform);
+ VisualServer::get_singleton()->instance_set_visible(move_plane_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_MOVE));
VisualServer::get_singleton()->instance_set_transform(rotate_gizmo_instance[i], xform);
VisualServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE));
}
@@ -2315,8 +2392,8 @@ void SpatialEditorViewport::set_state(const Dictionary &p_state) {
if (p_state.has("previewing")) {
Node *pv = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["previewing"]);
- if (pv && pv->cast_to<Camera>()) {
- previewing = pv->cast_to<Camera>();
+ if (Object::cast_to<Camera>(pv)) {
+ previewing = Object::cast_to<Camera>(pv);
previewing->connect("tree_exited", this, "_preview_exited_scene");
VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), previewing->get_camera()); //replace
view_menu->hide();
@@ -2385,7 +2462,7 @@ void SpatialEditorViewport::focus_selection() {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -2491,7 +2568,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed
preview_camera->set_toggle_mode(true);
preview_camera->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -90 * EDSCALE);
preview_camera->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 10 * EDSCALE);
- preview_camera->set_text("preview");
+ preview_camera->set_text(TTR("preview"));
surface->add_child(preview_camera);
preview_camera->hide();
preview_camera->connect("toggled", this, "_toggle_camera_preview");
@@ -2681,7 +2758,7 @@ void SpatialEditorViewportContainer::_notification(int p_what) {
SpatialEditorViewport *viewports[4];
int vc = 0;
for (int i = 0; i < get_child_count(); i++) {
- viewports[vc] = get_child(i)->cast_to<SpatialEditorViewport>();
+ viewports[vc] = Object::cast_to<SpatialEditorViewport>(get_child(i));
if (viewports[vc]) {
vc++;
}
@@ -2837,6 +2914,7 @@ void SpatialEditor::select_gizmo_highlight_axis(int p_axis) {
for (int i = 0; i < 3; i++) {
move_gizmo[i]->surface_set_material(0, i == p_axis ? gizmo_hl : gizmo_color[i]);
+ move_plane_gizmo[i]->surface_set_material(0, (i + 6) == p_axis ? gizmo_hl : plane_gizmo_color[i]);
rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_hl : gizmo_color[i]);
}
}
@@ -2852,7 +2930,7 @@ void SpatialEditor::update_transform_gizmo() {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -2887,7 +2965,7 @@ void SpatialEditor::update_transform_gizmo() {
Object *SpatialEditor::_get_editor_data(Object *p_what) {
- Spatial *sp = p_what->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(p_what);
if (!sp)
return NULL;
@@ -2897,7 +2975,7 @@ Object *SpatialEditor::_get_editor_data(Object *p_what) {
si->sbox_instance = VisualServer::get_singleton()->instance_create2(selection_box->get_rid(), sp->get_world()->get_scenario());
VS::get_singleton()->instance_geometry_set_cast_shadows_setting(si->sbox_instance, VS::SHADOW_CASTING_SETTING_OFF);
- if (get_tree()->is_editor_hint())
+ if (Engine::get_singleton()->is_editor_hint())
editor->call("edit_node", sp);
return si;
@@ -3127,7 +3205,7 @@ void SpatialEditor::_xform_dialog_action() {
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(E->get());
if (!sp)
continue;
@@ -3430,10 +3508,12 @@ void SpatialEditor::_init_indicators() {
gizmo_hl->set_flag(SpatialMaterial::FLAG_ONTOP, true);
gizmo_hl->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
gizmo_hl->set_albedo(Color(1, 1, 1, gizmo_alph + 0.2f));
+ gizmo_hl->set_cull_mode(SpatialMaterial::CULL_DISABLED);
for (int i = 0; i < 3; i++) {
move_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
+ move_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh));
Ref<SpatialMaterial> mat = memnew(SpatialMaterial);
@@ -3444,6 +3524,7 @@ void SpatialEditor::_init_indicators() {
col[i] = 1.0;
col.a = gizmo_alph;
mat->set_albedo(col);
+
gizmo_color[i] = mat;
Vector3 ivec;
@@ -3501,17 +3582,60 @@ void SpatialEditor::_init_indicators() {
surftool->commit(move_gizmo[i]);
}
+ // plane translation
+ {
+ Ref<SurfaceTool> surftool = memnew(SurfaceTool);
+ surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
+
+ Vector3 vec = ivec2 - ivec3;
+ Vector3 plane[4] = {
+ vec * GIZMO_PLANE_DST,
+ vec * GIZMO_PLANE_DST + ivec2 * GIZMO_PLANE_SIZE,
+ vec * (GIZMO_PLANE_DST + GIZMO_PLANE_SIZE),
+ vec * GIZMO_PLANE_DST - ivec3 * GIZMO_PLANE_SIZE
+ };
+
+ Basis ma(ivec, Math_PI / 2);
+
+ Vector3 points[4] = {
+ ma.xform(plane[0]),
+ ma.xform(plane[1]),
+ ma.xform(plane[2]),
+ ma.xform(plane[3]),
+ };
+ surftool->add_vertex(points[0]);
+ surftool->add_vertex(points[1]);
+ surftool->add_vertex(points[2]);
+
+ surftool->add_vertex(points[0]);
+ surftool->add_vertex(points[2]);
+ surftool->add_vertex(points[3]);
+
+ Ref<SpatialMaterial> plane_mat = memnew(SpatialMaterial);
+ plane_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
+ plane_mat->set_flag(SpatialMaterial::FLAG_ONTOP, true);
+ plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
+ plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED);
+ Color col;
+ col[i] = 1.0;
+ col.a = gizmo_alph;
+ plane_mat->set_albedo(col);
+ plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides
+ surftool->set_material(plane_mat);
+ surftool->commit(move_plane_gizmo[i]);
+ }
+
{
Ref<SurfaceTool> surftool = memnew(SurfaceTool);
surftool->begin(Mesh::PRIMITIVE_TRIANGLES);
Vector3 circle[5] = {
- ivec * 0.02 + ivec2 * 0.02 + ivec2 * 1.0,
- ivec * -0.02 + ivec2 * 0.02 + ivec2 * 1.0,
- ivec * -0.02 + ivec2 * -0.02 + ivec2 * 1.0,
- ivec * 0.02 + ivec2 * -0.02 + ivec2 * 1.0,
- ivec * 0.02 + ivec2 * 0.02 + ivec2 * 1.0,
+ ivec * 0.02 + ivec2 * 0.02 + ivec2 * GIZMO_CIRCLE_SIZE,
+ ivec * -0.02 + ivec2 * 0.02 + ivec2 * GIZMO_CIRCLE_SIZE,
+ ivec * -0.02 + ivec2 * -0.02 + ivec2 * GIZMO_CIRCLE_SIZE,
+ ivec * 0.02 + ivec2 * -0.02 + ivec2 * GIZMO_CIRCLE_SIZE,
+ ivec * 0.02 + ivec2 * 0.02 + ivec2 * GIZMO_CIRCLE_SIZE,
};
for (int k = 0; k < 33; k++) {
@@ -3550,7 +3674,7 @@ void SpatialEditor::_init_indicators() {
_generate_selection_box();
- //get_scene()->get_root_node()->cast_to<EditorNode>()->get_scene_root()->add_child(camera);
+ //Object::cast_to<EditorNode>(get_scene()->get_root_node())->get_scene_root()->add_child(camera);
//current_camera=camera;
}
@@ -3584,21 +3708,6 @@ void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) {
if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack())
return;
-#if 0
-//i don't remember this being used, why was it here?
- {
-
- EditorNode *en = editor;
- EditorPluginList *over_plugin_list = en->get_editor_plugins_over();
-
- if (!over_plugin_list->empty() && over_plugin_list->forward_gui_input(p_event)) {
-
- return; //ate the over input event
- }
-
- }
-#endif
-
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
@@ -3656,6 +3765,20 @@ void SpatialEditor::_notification(int p_what) {
_finish_indicators();
memdelete(gizmos);
}
+ if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) {
+ tool_button[SpatialEditor::TOOL_MODE_SELECT]->set_icon(get_icon("ToolSelect", "EditorIcons"));
+ tool_button[SpatialEditor::TOOL_MODE_MOVE]->set_icon(get_icon("ToolMove", "EditorIcons"));
+ tool_button[SpatialEditor::TOOL_MODE_ROTATE]->set_icon(get_icon("ToolRotate", "EditorIcons"));
+ tool_button[SpatialEditor::TOOL_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons"));
+ tool_button[SpatialEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_icon("ListSelect", "EditorIcons"));
+
+ view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_1_VIEWPORT), get_icon("Panels1", "EditorIcons"));
+ view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS), get_icon("Panels2", "EditorIcons"));
+ view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_2_VIEWPORTS_ALT), get_icon("Panels2Alt", "EditorIcons"));
+ view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS), get_icon("Panels3", "EditorIcons"));
+ view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_3_VIEWPORTS_ALT), get_icon("Panels3Alt", "EditorIcons"));
+ view_menu->get_popup()->set_item_icon(view_menu->get_popup()->get_item_index(MENU_VIEW_USE_4_VIEWPORTS), get_icon("Panels4", "EditorIcons"));
+ }
}
void SpatialEditor::add_control_to_menu_panel(Control *p_control) {
@@ -3682,10 +3805,10 @@ HSplitContainer *SpatialEditor::get_palette_split() {
void SpatialEditor::_request_gizmo(Object *p_obj) {
- Spatial *sp = p_obj->cast_to<Spatial>();
+ Spatial *sp = Object::cast_to<Spatial>(p_obj);
if (!sp)
return;
- if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || sp->get_owner() == editor->get_edited_scene() || editor->get_edited_scene()->is_editable_instance(sp->get_owner()))) {
+ if (editor->get_edited_scene() && (sp == editor->get_edited_scene() || (sp->get_owner() && editor->get_edited_scene()->is_a_parent_of(sp)))) {
Ref<SpatialEditorGizmo> seg;
@@ -3699,7 +3822,6 @@ void SpatialEditor::_request_gizmo(Object *p_obj) {
if (!seg.is_valid()) {
seg = gizmos->get_gizmo(sp);
}
-
if (seg.is_valid()) {
sp->set_gizmo(seg);
}
@@ -3713,7 +3835,7 @@ void SpatialEditor::_request_gizmo(Object *p_obj) {
void SpatialEditor::_toggle_maximize_view(Object *p_viewport) {
if (!p_viewport) return;
- SpatialEditorViewport *current_viewport = p_viewport->cast_to<SpatialEditorViewport>();
+ SpatialEditorViewport *current_viewport = Object::cast_to<SpatialEditorViewport>(p_viewport);
if (!current_viewport) return;
int index = -1;
@@ -3837,7 +3959,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
tool_button[TOOL_MODE_SELECT]->set_pressed(true);
button_binds[0] = MENU_TOOL_SELECT;
tool_button[TOOL_MODE_SELECT]->connect("pressed", this, "_menu_item_pressed", button_binds);
- tool_button[TOOL_MODE_SELECT]->set_tooltip("Select Mode (Q)\n" + keycode_get_string(KEY_MASK_CMD) + "Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection");
+ tool_button[TOOL_MODE_SELECT]->set_tooltip(TTR("Select Mode (Q)\n") + keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection"));
tool_button[TOOL_MODE_MOVE] = memnew(ToolButton);
@@ -4110,7 +4232,7 @@ void SpatialEditorPlugin::make_visible(bool p_visible) {
}
void SpatialEditorPlugin::edit(Object *p_object) {
- spatial_editor->edit(p_object->cast_to<Spatial>());
+ spatial_editor->edit(Object::cast_to<Spatial>(p_object));
}
bool SpatialEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 2fd72739df..374861b5e7 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -49,6 +49,7 @@ class SpatialEditorGizmo : public SpatialGizmo {
GDCLASS(SpatialEditorGizmo, SpatialGizmo);
bool selected;
+ bool instanced;
public:
void set_selected(bool p_selected) { selected = p_selected; }
@@ -121,6 +122,7 @@ private:
float gizmo_scale;
bool freelook_active;
+ Vector3 freelook_velocity;
PanelContainer *info;
Label *info_label;
@@ -194,6 +196,9 @@ private:
TRANSFORM_X_AXIS,
TRANSFORM_Y_AXIS,
TRANSFORM_Z_AXIS,
+ TRANSFORM_YZ,
+ TRANSFORM_XZ,
+ TRANSFORM_XY,
};
struct EditData {
@@ -231,7 +236,7 @@ private:
real_t zoom_indicator_delay;
- RID move_gizmo_instance[3], rotate_gizmo_instance[3];
+ RID move_gizmo_instance[3], move_plane_gizmo_instance[3], rotate_gizmo_instance[3];
String last_message;
String message;
@@ -240,7 +245,7 @@ private:
void set_message(String p_message, float p_time = 5);
//
- void _update_camera();
+ void _update_camera(float p_interp_delta);
Transform to_camera_transform(const Cursor &p_cursor) const;
void _draw();
@@ -376,8 +381,9 @@ private:
bool grid_enable[3]; //should be always visible if true
bool grid_enabled;
- Ref<ArrayMesh> move_gizmo[3], rotate_gizmo[3];
+ Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[3];
Ref<SpatialMaterial> gizmo_color[3];
+ Ref<SpatialMaterial> plane_gizmo_color[3];
Ref<SpatialMaterial> gizmo_hl;
int over_gizmo_handle;
@@ -517,6 +523,7 @@ public:
bool are_local_coords_enabled() const { return transform_menu->get_popup()->is_item_checked(transform_menu->get_popup()->get_item_index(SpatialEditor::MENU_TRANSFORM_LOCAL_COORDS)); }
Ref<ArrayMesh> get_move_gizmo(int idx) const { return move_gizmo[idx]; }
+ Ref<ArrayMesh> get_move_plane_gizmo(int idx) const { return move_plane_gizmo[idx]; }
Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; }
void update_transform_gizmo();
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index 0608ecec58..c2c26bfe6c 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -120,63 +120,6 @@ void SpriteFramesEditor::_load_pressed() {
file->popup_centered_ratio();
}
-void SpriteFramesEditor::_item_edited() {
-
-#if 0
- if (!tree->get_selected())
- return;
-
- TreeItem *s = tree->get_selected();
-
- if (tree->get_selected_column()==0) {
- // renamed
- String old_name=s->get_metadata(0);
- String new_name=s->get_text(0);
- if (old_name==new_name)
- return;
-
- if (new_name=="" || new_name.find("\\")!=-1 || new_name.find("/")!=-1 || frames->has_resource(new_name)) {
-
- s->set_text(0,old_name);
- return;
- }
-
- RES samp = frames->get_resource(old_name);
- undo_redo->create_action("Rename Resource");
- undo_redo->add_do_method(frames,"remove_resource",old_name);
- undo_redo->add_do_method(frames,"add_resource",new_name,samp);
- undo_redo->add_undo_method(frames,"remove_resource",new_name);
- undo_redo->add_undo_method(frames,"add_resource",old_name,samp);
- undo_redo->add_do_method(this,"_update_library");
- undo_redo->add_undo_method(this,"_update_library");
- undo_redo->commit_action();
-
- }
-#endif
-}
-
-void SpriteFramesEditor::_delete_confirm_pressed() {
-
- ERR_FAIL_COND(!frames->has_animation(edited_anim));
-
- if (tree->get_current() < 0)
- return;
-
- sel -= 1;
- if (sel < 0 && frames->get_frame_count(edited_anim))
- sel = 0;
-
- int to_remove = tree->get_current();
- sel = to_remove;
- Ref<Texture> r = frames->get_frame(edited_anim, to_remove);
- undo_redo->create_action(TTR("Delete Resource"));
- undo_redo->add_do_method(frames, "remove_frame", edited_anim, to_remove);
- undo_redo->add_undo_method(frames, "add_frame", edited_anim, r, to_remove);
- undo_redo->add_do_method(this, "_update_library");
- undo_redo->add_undo_method(this, "_update_library");
- undo_redo->commit_action();
-}
-
void SpriteFramesEditor::_paste_pressed() {
ERR_FAIL_COND(!frames->has_animation(edited_anim));
@@ -303,15 +246,6 @@ void SpriteFramesEditor::_delete_pressed() {
if (tree->get_current() < 0)
return;
-
- _delete_confirm_pressed(); //it has undo.. why bother with a dialog..
- /*
- dialog->set_title("Confirm...");
- dialog->set_text("Remove Resource '"+tree->get_selected()->get_text(0)+"' ?");
- //dialog->get_cancel()->set_text("Cancel");
- //dialog->get_ok()->show();
- dialog->get_ok()->set_text("Remove");
- dialog->popup_centered(Size2(300,60));*/
}
void SpriteFramesEditor::_animation_select() {
@@ -334,14 +268,14 @@ static void _find_anim_sprites(Node *p_node, List<Node *> *r_nodes, Ref<SpriteFr
return;
{
- AnimatedSprite *as = p_node->cast_to<AnimatedSprite>();
+ AnimatedSprite *as = Object::cast_to<AnimatedSprite>(p_node);
if (as && as->get_sprite_frames() == p_sfames) {
r_nodes->push_back(p_node);
}
}
{
- AnimatedSprite3D *as = p_node->cast_to<AnimatedSprite3D>();
+ AnimatedSprite3D *as = Object::cast_to<AnimatedSprite3D>(p_node);
if (as && as->get_sprite_frames() == p_sfames) {
r_nodes->push_back(p_node);
}
@@ -693,10 +627,8 @@ void SpriteFramesEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_load_pressed"), &SpriteFramesEditor::_load_pressed);
ClassDB::bind_method(D_METHOD("_empty_pressed"), &SpriteFramesEditor::_empty_pressed);
ClassDB::bind_method(D_METHOD("_empty2_pressed"), &SpriteFramesEditor::_empty2_pressed);
- ClassDB::bind_method(D_METHOD("_item_edited"), &SpriteFramesEditor::_item_edited);
ClassDB::bind_method(D_METHOD("_delete_pressed"), &SpriteFramesEditor::_delete_pressed);
ClassDB::bind_method(D_METHOD("_paste_pressed"), &SpriteFramesEditor::_paste_pressed);
- ClassDB::bind_method(D_METHOD("_delete_confirm_pressed"), &SpriteFramesEditor::_delete_confirm_pressed);
ClassDB::bind_method(D_METHOD("_file_load_request", "files", "atpos"), &SpriteFramesEditor::_file_load_request, DEFVAL(-1));
ClassDB::bind_method(D_METHOD("_update_library", "skipsel"), &SpriteFramesEditor::_update_library, DEFVAL(false));
ClassDB::bind_method(D_METHOD("_up_pressed"), &SpriteFramesEditor::_up_pressed);
@@ -829,8 +761,6 @@ SpriteFramesEditor::SpriteFramesEditor() {
move_up->connect("pressed", this, "_up_pressed");
move_down->connect("pressed", this, "_down_pressed");
file->connect("files_selected", this, "_file_load_request");
- //dialog->connect("confirmed", this,"_delete_confirm_pressed");
- //tree->connect("item_selected", this,"_item_edited");
loading_scene = false;
sel = -1;
@@ -842,7 +772,7 @@ SpriteFramesEditor::SpriteFramesEditor() {
void SpriteFramesEditorPlugin::edit(Object *p_object) {
frames_editor->set_undo_redo(&get_undo_redo());
- SpriteFrames *s = p_object->cast_to<SpriteFrames>();
+ SpriteFrames *s = Object::cast_to<SpriteFrames>(p_object);
if (!s)
return;
diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h
index c0eb1ec3d0..0d1ab9fd8c 100644
--- a/editor/plugins/sprite_frames_editor_plugin.h
+++ b/editor/plugins/sprite_frames_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -76,11 +76,9 @@ class SpriteFramesEditor : public PanelContainer {
void _empty_pressed();
void _empty2_pressed();
void _delete_pressed();
- void _delete_confirm_pressed();
void _up_pressed();
void _down_pressed();
void _update_library(bool p_skip_selector = false);
- void _item_edited();
void _animation_select();
void _animation_name_edited();
diff --git a/editor/plugins/stream_editor_plugin.cpp b/editor/plugins/stream_editor_plugin.cpp
deleted file mode 100644
index dd97ce936d..0000000000
--- a/editor/plugins/stream_editor_plugin.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/*************************************************************************/
-/* stream_editor_plugin.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "stream_editor_plugin.h"
-
-#if 0
-
-void StreamEditor::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
- play->set_icon( get_icon("Play","EditorIcons") );
- stop->set_icon( get_icon("Stop","EditorIcons") );
- }
-
-}
-void StreamEditor::_node_removed(Node *p_node) {
-
- if(p_node==node) {
- node=NULL;
- hide();
- }
-
-}
-
-void StreamEditor::_play() {
-
- node->call("play");
-}
-
-void StreamEditor::_stop() {
-
- node->call("stop");
-}
-
-void StreamEditor::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("_play"),&StreamEditor::_play);
- ClassDB::bind_method(D_METHOD("_stop"),&StreamEditor::_stop);
-
-}
-
-void StreamEditor::edit(Node *p_stream) {
-
- node=p_stream;
-
-}
-StreamEditor::StreamEditor() {
-
- play = memnew( Button );
-
-
- play->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,60);
- play->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,40);
- play->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0);
- play->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0);
-
- add_child(play);
-
- stop = memnew( Button );
-
- stop->set_position(Point2( 35, 5 ));
- stop->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_END,30);
- stop->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,10);
- stop->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,0);
- stop->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_BEGIN,0);
- add_child(stop);
-
-
- play->connect("pressed", this,"_play");
- stop->connect("pressed", this,"_stop");
-
-}
-
-
-void StreamEditorPlugin::edit(Object *p_object) {
-
- stream_editor->edit(p_object->cast_to<Node>());
-}
-
-bool StreamEditorPlugin::handles(Object *p_object) const {
-
- return p_object->is_class("StreamPlayer") || p_object->is_class("SpatialStreamPlayer");
-}
-
-void StreamEditorPlugin::make_visible(bool p_visible) {
-
- if (p_visible) {
- stream_editor->show();
- stream_editor->set_fixed_process(true);
- } else {
-
- stream_editor->hide();
- stream_editor->set_fixed_process(false);
- stream_editor->edit(NULL);
- }
-
-}
-
-StreamEditorPlugin::StreamEditorPlugin(EditorNode *p_node) {
-
- editor=p_node;
- stream_editor = memnew( StreamEditor );
- editor->get_viewport()->add_child(stream_editor);
-
- stream_editor->set_anchor(MARGIN_LEFT,Control::ANCHOR_END);
- stream_editor->set_anchor(MARGIN_RIGHT,Control::ANCHOR_END);
- stream_editor->set_margin(MARGIN_LEFT,60);
- stream_editor->set_margin(MARGIN_RIGHT,0);
- stream_editor->set_margin(MARGIN_TOP,0);
- stream_editor->set_margin(MARGIN_BOTTOM,10);
-
-
- stream_editor->hide();
-
-
-
-}
-
-
-StreamEditorPlugin::~StreamEditorPlugin()
-{
-}
-
-#endif
diff --git a/editor/plugins/stream_editor_plugin.h b/editor/plugins/stream_editor_plugin.h
deleted file mode 100644
index cdd1c126ad..0000000000
--- a/editor/plugins/stream_editor_plugin.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*************************************************************************/
-/* stream_editor_plugin.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef STREAM_EDITOR_PLUGIN_H
-#define STREAM_EDITOR_PLUGIN_H
-
-#if 0
-#include "editor/editor_node.h"
-#include "editor/editor_plugin.h"
-#include "scene/audio/stream_player.h"
-
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-
-class StreamEditor : public Control {
-
- GDCLASS(StreamEditor, Control );
-
- Button * play;
- Button * stop;
-
- Panel *panel;
- Node *node;
-
- void _play();
- void _stop();
-protected:
- void _notification(int p_what);
- void _node_removed(Node *p_node);
- static void _bind_methods();
-public:
-
- void edit(Node *p_stream);
- StreamEditor();
-};
-
-class StreamEditorPlugin : public EditorPlugin {
-
- GDCLASS( StreamEditorPlugin, EditorPlugin );
-
- StreamEditor *stream_editor;
- EditorNode *editor;
-
-public:
-
- virtual String get_name() const { return "Stream"; }
- 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);
-
- StreamEditorPlugin(EditorNode *p_node);
- ~StreamEditorPlugin();
-
-};
-
-#endif // STREAM_EDITOR_PLUGIN_H
-#endif
diff --git a/editor/plugins/style_box_editor_plugin.cpp b/editor/plugins/style_box_editor_plugin.cpp
index d421b203e9..478ca2e972 100644
--- a/editor/plugins/style_box_editor_plugin.cpp
+++ b/editor/plugins/style_box_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -72,8 +72,8 @@ StyleBoxEditor::StyleBoxEditor() {
void StyleBoxEditorPlugin::edit(Object *p_node) {
- if (p_node && p_node->cast_to<StyleBox>()) {
- stylebox_editor->edit(p_node->cast_to<StyleBox>());
+ if (Object::cast_to<StyleBox>(p_node)) {
+ stylebox_editor->edit(Object::cast_to<StyleBox>(p_node));
stylebox_editor->show();
} else
stylebox_editor->hide();
diff --git a/editor/plugins/style_box_editor_plugin.h b/editor/plugins/style_box_editor_plugin.h
index effcdb7e5a..bf3c56197c 100644
--- a/editor/plugins/style_box_editor_plugin.h
+++ b/editor/plugins/style_box_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp
index 57c27a8a7e..90dc4cf993 100644
--- a/editor/plugins/texture_editor_plugin.cpp
+++ b/editor/plugins/texture_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -70,7 +70,7 @@ void TextureEditor::_notification(int p_what) {
int ofs_x = (size.width - tex_width) / 2;
int ofs_y = (size.height - tex_height) / 2;
- if (texture->cast_to<CurveTexture>()) {
+ if (Object::cast_to<CurveTexture>(*texture)) {
// In the case of CurveTextures we know they are 1 in height, so fill the preview to see the gradient
ofs_y = 0;
tex_height = size.height;
@@ -81,10 +81,10 @@ void TextureEditor::_notification(int p_what) {
Ref<Font> font = get_font("font", "Label");
String format;
- if (texture->cast_to<ImageTexture>()) {
- format = Image::get_format_name(texture->cast_to<ImageTexture>()->get_format());
- } else if (texture->cast_to<StreamTexture>()) {
- format = Image::get_format_name(texture->cast_to<StreamTexture>()->get_format());
+ if (Object::cast_to<ImageTexture>(*texture)) {
+ format = Image::get_format_name(Object::cast_to<ImageTexture>(*texture)->get_format());
+ } else if (Object::cast_to<StreamTexture>(*texture)) {
+ format = Image::get_format_name(Object::cast_to<StreamTexture>(*texture)->get_format());
} else {
format = texture->get_class();
}
@@ -136,7 +136,7 @@ TextureEditor::TextureEditor() {
void TextureEditorPlugin::edit(Object *p_object) {
- Texture *s = p_object->cast_to<Texture>();
+ Texture *s = Object::cast_to<Texture>(p_object);
if (!s)
return;
diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h
index 2b5e7ed629..c7734b5b3d 100644
--- a/editor/plugins/texture_editor_plugin.h
+++ b/editor/plugins/texture_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index d878bba427..82b507bd49 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -280,7 +280,7 @@ void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
rect.expand_to(r.position);
rect.expand_to(r.position + r.size);
}
- undo_redo->create_action("Set Region Rect");
+ undo_redo->create_action(TTR("Set Region Rect"));
if (node_sprite) {
undo_redo->add_do_method(node_sprite, "set_region_rect", rect);
undo_redo->add_undo_method(node_sprite, "set_region_rect", node_sprite->get_region_rect());
@@ -626,12 +626,12 @@ void TextureRegionEditor::edit(Object *p_obj) {
if (atlas_tex.is_valid())
atlas_tex->remove_change_receptor(this);
if (p_obj) {
- node_sprite = p_obj->cast_to<Sprite>();
- node_patch9 = p_obj->cast_to<NinePatchRect>();
- if (p_obj->cast_to<StyleBoxTexture>())
- obj_styleBox = Ref<StyleBoxTexture>(p_obj->cast_to<StyleBoxTexture>());
- if (p_obj->cast_to<AtlasTexture>())
- atlas_tex = Ref<AtlasTexture>(p_obj->cast_to<AtlasTexture>());
+ node_sprite = Object::cast_to<Sprite>(p_obj);
+ node_patch9 = Object::cast_to<NinePatchRect>(p_obj);
+ if (Object::cast_to<StyleBoxTexture>(p_obj))
+ obj_styleBox = Ref<StyleBoxTexture>(Object::cast_to<StyleBoxTexture>(p_obj));
+ if (Object::cast_to<AtlasTexture>(p_obj))
+ atlas_tex = Ref<AtlasTexture>(Object::cast_to<AtlasTexture>(p_obj));
p_obj->add_change_receptor(this);
_edit_region();
} else {
diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h
index 265d46cb08..0789dde1c1 100644
--- a/editor/plugins/texture_region_editor_plugin.h
+++ b/editor/plugins/texture_region_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp
index d45a3b1312..86ef1a489f 100644
--- a/editor/plugins/theme_editor_plugin.cpp
+++ b/editor/plugins/theme_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -44,7 +44,7 @@ void ThemeEditor::_propagate_redraw(Control *p_at) {
p_at->minimum_size_changed();
p_at->update();
for (int i = 0; i < p_at->get_child_count(); i++) {
- Control *a = p_at->get_child(i)->cast_to<Control>();
+ Control *a = Object::cast_to<Control>(p_at->get_child(i));
if (a)
_propagate_redraw(a);
}
@@ -529,8 +529,8 @@ void ThemeEditor::_theme_menu_cbk(int p_option) {
} else if (p_option == POPUP_CLASS_REMOVE) {
- add_del_dialog->set_title("Remove All Items");
- add_del_dialog->get_ok()->set_text("Remove All");
+ add_del_dialog->set_title(TTR("Remove All Items"));
+ add_del_dialog->get_ok()->set_text(TTR("Remove All"));
add_del_dialog->popup_centered(Size2(240, 85) * EDSCALE);
base_theme = Theme::get_default();
@@ -892,9 +892,9 @@ ThemeEditor::ThemeEditor() {
void ThemeEditorPlugin::edit(Object *p_node) {
- if (p_node && p_node->cast_to<Theme>()) {
+ if (Object::cast_to<Theme>(p_node)) {
theme_editor->show();
- theme_editor->edit(p_node->cast_to<Theme>());
+ theme_editor->edit(Object::cast_to<Theme>(p_node));
} else {
theme_editor->edit(Ref<Theme>());
theme_editor->hide();
diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h
index a75b83e76a..cb6f086de6 100644
--- a/editor/plugins/theme_editor_plugin.h
+++ b/editor/plugins/theme_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index 80ff6627b2..f943ee5f6d 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -106,7 +106,7 @@ void TileMapEditor::_menu_option(int p_option) {
if (!selection_active)
return;
- undo_redo->create_action("Erase Selection");
+ undo_redo->create_action(TTR("Erase Selection"));
for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) {
for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) {
@@ -730,7 +730,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (id != TileMap::INVALID_CELL) {
- undo_redo->create_action("Line Draw");
+ undo_redo->create_action(TTR("Line Draw"));
for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
_set_cell(E->key(), id, flip_h, flip_v, transpose, true);
@@ -747,7 +747,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (id != TileMap::INVALID_CELL) {
- undo_redo->create_action("Rectangle Paint");
+ undo_redo->create_action(TTR("Rectangle Paint"));
for (int i = rectangle.position.y; i <= rectangle.position.y + rectangle.size.y; i++) {
for (int j = rectangle.position.x; j <= rectangle.position.x + rectangle.size.x; j++) {
@@ -796,7 +796,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
op["flip_v"] = flip_v;
op["transpose"] = transpose;
- undo_redo->create_action("Bucket Fill");
+ undo_redo->create_action(TTR("Bucket Fill"));
undo_redo->add_do_method(this, "_fill_points", points, op);
undo_redo->add_undo_method(this, "_fill_points", points, pop);
@@ -1329,7 +1329,7 @@ void TileMapEditor::edit(Node *p_tile_map) {
node->disconnect("settings_changed", this, "_tileset_settings_changed");
if (p_tile_map) {
- node = p_tile_map->cast_to<TileMap>();
+ node = Object::cast_to<TileMap>(p_tile_map);
if (!canvas_item_editor->is_connected("draw", this, "_canvas_draw"))
canvas_item_editor->connect("draw", this, "_canvas_draw");
if (!canvas_item_editor->is_connected("mouse_entered", this, "_canvas_mouse_enter"))
@@ -1407,7 +1407,7 @@ TileMapEditor::CellOp TileMapEditor::_get_op_from_cell(const Point2i &p_pos) {
void TileMapEditor::_update_transform_buttons(Object *p_button) {
//ERR_FAIL_NULL(p_button);
- ToolButton *b = p_button->cast_to<ToolButton>();
+ ToolButton *b = Object::cast_to<ToolButton>(p_button);
//ERR_FAIL_COND(!b);
if (b == rotate_0) {
@@ -1582,7 +1582,7 @@ TileMapEditor::~TileMapEditor() {
void TileMapEditorPlugin::edit(Object *p_object) {
- tile_map_editor->edit(p_object->cast_to<Node>());
+ tile_map_editor->edit(Object::cast_to<Node>(p_object));
}
bool TileMapEditorPlugin::handles(Object *p_object) const {
diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h
index d76884e663..e863c4bf3d 100644
--- a/editor/plugins/tile_map_editor_plugin.h
+++ b/editor/plugins/tile_map_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp
index bed4727bb9..443c280428 100644
--- a/editor/plugins/tile_set_editor_plugin.cpp
+++ b/editor/plugins/tile_set_editor_plugin.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -43,7 +43,7 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
Node *child = p_node->get_child(i);
- if (!child->cast_to<Sprite>()) {
+ if (!Object::cast_to<Sprite>(child)) {
if (child->get_child_count() > 0) {
_import_node(child, p_library);
}
@@ -51,7 +51,7 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
continue;
}
- Sprite *mi = child->cast_to<Sprite>();
+ Sprite *mi = Object::cast_to<Sprite>(child);
Ref<Texture> texture = mi->get_texture();
Ref<Texture> normal_map = mi->get_normal_map();
Ref<ShaderMaterial> material = mi->get_material();
@@ -99,18 +99,18 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
Node *child2 = mi->get_child(j);
- if (child2->cast_to<NavigationPolygonInstance>())
- nav_poly = child2->cast_to<NavigationPolygonInstance>()->get_navigation_polygon();
+ if (Object::cast_to<NavigationPolygonInstance>(child2))
+ nav_poly = Object::cast_to<NavigationPolygonInstance>(child2)->get_navigation_polygon();
- if (child2->cast_to<LightOccluder2D>())
- occluder = child2->cast_to<LightOccluder2D>()->get_occluder_polygon();
+ if (Object::cast_to<LightOccluder2D>(child2))
+ occluder = Object::cast_to<LightOccluder2D>(child2)->get_occluder_polygon();
- if (!child2->cast_to<StaticBody2D>())
+ if (!Object::cast_to<StaticBody2D>(child2))
continue;
found_collisions = true;
- StaticBody2D *sb = child2->cast_to<StaticBody2D>();
+ StaticBody2D *sb = Object::cast_to<StaticBody2D>(child2);
List<uint32_t> shapes;
sb->get_shape_owners(&shapes);
@@ -268,8 +268,8 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) {
void TileSetEditorPlugin::edit(Object *p_node) {
- if (p_node && p_node->cast_to<TileSet>()) {
- tileset_editor->edit(p_node->cast_to<TileSet>());
+ if (Object::cast_to<TileSet>(p_node)) {
+ tileset_editor->edit(Object::cast_to<TileSet>(p_node));
tileset_editor->show();
} else
tileset_editor->hide();
@@ -294,7 +294,6 @@ TileSetEditorPlugin::TileSetEditorPlugin(EditorNode *p_node) {
p_node->get_viewport()->add_child(tileset_editor);
tileset_editor->set_area_as_parent_rect();
- tileset_editor->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END);
tileset_editor->set_anchor(MARGIN_BOTTOM, Control::ANCHOR_BEGIN);
tileset_editor->set_end(Point2(0, 22));
tileset_editor->hide();
diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h
index d04ebc7197..677ee05b55 100644
--- a/editor/plugins/tile_set_editor_plugin.h
+++ b/editor/plugins/tile_set_editor_plugin.h
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */