summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-08-27 21:07:15 +0200
committerRémi Verschelde <rverschelde@gmail.com>2017-08-27 22:13:45 +0200
commit7ad14e7a3e6f87ddc450f7e34621eb5200808451 (patch)
tree8804d0dd24cc126087462edfbbbf73ed61b56b0e /editor
parent37da8155a4500a9386027b4d791a86186bc7ab4a (diff)
Dead code tells no tales
Diffstat (limited to 'editor')
-rw-r--r--editor/SCsub1
-rw-r--r--editor/animation_editor.cpp12
-rw-r--r--editor/call_dialog.cpp342
-rw-r--r--editor/call_dialog.h86
-rw-r--r--editor/collada/collada.cpp14
-rw-r--r--editor/connections_dialog.cpp26
-rw-r--r--editor/editor_export.cpp2202
-rw-r--r--editor/editor_help.cpp43
-rw-r--r--editor/editor_node.cpp10
-rw-r--r--editor/editor_node.h2
-rw-r--r--editor/editor_reimport_dialog.cpp149
-rw-r--r--editor/editor_reimport_dialog.h54
-rw-r--r--editor/editor_settings.h2
-rw-r--r--editor/export_template_manager.cpp71
-rw-r--r--editor/import/editor_import_collada.cpp170
-rw-r--r--editor/import/resource_importer_scene.cpp171
-rw-r--r--editor/inspector_dock.cpp51
-rw-r--r--editor/inspector_dock.h63
-rw-r--r--editor/io_plugins/SCsub5
-rw-r--r--editor/io_plugins/editor_atlas.cpp153
-rw-r--r--editor/io_plugins/editor_atlas.h41
-rw-r--r--editor/io_plugins/editor_bitmask_import_plugin.cpp388
-rw-r--r--editor/io_plugins/editor_bitmask_import_plugin.h71
-rw-r--r--editor/io_plugins/editor_export_scene.cpp143
-rw-r--r--editor/io_plugins/editor_export_scene.h45
-rw-r--r--editor/io_plugins/editor_font_import_plugin.cpp1705
-rw-r--r--editor/io_plugins/editor_font_import_plugin.h59
-rw-r--r--editor/io_plugins/editor_mesh_import_plugin.cpp594
-rw-r--r--editor/io_plugins/editor_mesh_import_plugin.h60
-rw-r--r--editor/io_plugins/editor_sample_import_plugin.cpp930
-rw-r--r--editor/io_plugins/editor_sample_import_plugin.h75
-rw-r--r--editor/io_plugins/editor_scene_import_plugin.cpp2986
-rw-r--r--editor/io_plugins/editor_scene_import_plugin.h201
-rw-r--r--editor/io_plugins/editor_scene_importer_fbxconv.cpp1137
-rw-r--r--editor/io_plugins/editor_scene_importer_fbxconv.h112
-rw-r--r--editor/io_plugins/editor_texture_import_plugin.cpp1896
-rw-r--r--editor/io_plugins/editor_texture_import_plugin.h175
-rw-r--r--editor/io_plugins/editor_translation_import_plugin.cpp480
-rw-r--r--editor/io_plugins/editor_translation_import_plugin.h57
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp65
-rw-r--r--editor/plugins/animation_tree_editor_plugin.cpp35
-rw-r--r--editor/plugins/baked_light_baker.cpp2727
-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/canvas_item_editor_plugin.cpp200
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h22
-rw-r--r--editor/plugins/collision_polygon_2d_editor_plugin.cpp11
-rw-r--r--editor/plugins/collision_polygon_editor_plugin.cpp11
-rw-r--r--editor/plugins/light_occluder_2d_editor_plugin.cpp11
-rw-r--r--editor/plugins/multimesh_editor_plugin.cpp15
-rw-r--r--editor/plugins/navigation_polygon_editor_plugin.cpp11
-rw-r--r--editor/plugins/path_2d_editor_plugin.cpp217
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.cpp11
-rw-r--r--editor/plugins/script_editor_plugin.cpp138
-rw-r--r--editor/plugins/script_editor_plugin.h10
-rw-r--r--editor/plugins/shader_editor_plugin.cpp101
-rw-r--r--editor/plugins/shader_editor_plugin.h9
-rw-r--r--editor/plugins/shader_graph_editor_plugin.cpp17
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp15
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp70
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.h2
-rw-r--r--editor/plugins/stream_editor_plugin.cpp150
-rw-r--r--editor/plugins/stream_editor_plugin.h85
-rw-r--r--editor/project_export.cpp1
-rw-r--r--editor/spatial_editor_gizmos.cpp56
67 files changed, 11 insertions, 19743 deletions
diff --git a/editor/SCsub b/editor/SCsub
index a92983851c..b9eead3dfc 100644
--- a/editor/SCsub
+++ b/editor/SCsub
@@ -404,7 +404,6 @@ if (env["tools"] == "yes"):
SConscript('fileserver/SCsub')
SConscript('icons/SCsub')
SConscript('import/SCsub')
- SConscript('io_plugins/SCsub')
SConscript('plugins/SCsub')
lib = env.Library("editor", env.editor_sources)
diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp
index 9e62d589d0..702adf0c68 100644
--- a/editor/animation_editor.cpp
+++ b/editor/animation_editor.cpp
@@ -38,6 +38,7 @@
#include "pair.h"
#include "scene/gui/separator.h"
#include "scene/main/viewport.h"
+
/* Missing to fix:
*Set
@@ -2684,17 +2685,6 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input)
Point2 mpos = mm->get_position() - ofs;
if (mpos.y < h) {
-#if 0
- //seek
- //int zoomw = settings_limit-name_limit;
- float scale = _get_zoom_scale();
- float pos = h_scroll->get_val() + (mpos.y-name_limit) / scale;
- if (pos<0 )
- pos=0;
- if (pos>=animation->get_length())
- pos=animation->get_length();
- timeline->set_val(pos);
-#endif
return;
}
diff --git a/editor/call_dialog.cpp b/editor/call_dialog.cpp
deleted file mode 100644
index ee0f5ce48d..0000000000
--- a/editor/call_dialog.cpp
+++ /dev/null
@@ -1,342 +0,0 @@
-/*************************************************************************/
-/* call_dialog.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 "call_dialog.h"
-
-#if 0
-#include "class_db.h"
-#include "print_string.h"
-#include "scene/gui/label.h"
-
-
-class CallDialogParams : public Object {
-
- GDCLASS( CallDialogParams, Object );
-public:
-
- bool _set(const StringName& p_name, const Variant& p_value) {
-
- values[p_name]=p_value;
- return true;
- }
-
- bool _get(const StringName& p_name,Variant &r_ret) const {
-
- if (values.has(p_name)) {
- r_ret=values[p_name];
- return true;
- }
- return false;
- }
-
- void _get_property_list( List<PropertyInfo> *p_list) const {
-
- for(int i=0;i<method.arguments.size();i++)
- p_list->push_back(method.arguments[i]);
- }
-
- MethodInfo method;
- HashMap<String,Variant> values;
-
- CallDialogParams() {}
-};
-
-
-void CallDialog::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_READY) {
-
- call->connect("pressed", this,"_call");
- cancel->connect("pressed", this,"_cancel");
- //filter->get_path()->connect("text_changed", this,"_text_changed");
- _update_method_list();
- }
-
- if (p_what==NOTIFICATION_EXIT_TREE) {
-
- call->disconnect("pressed", this,"_call");
- cancel->disconnect("pressed", this,"_cancel");
-
- //filter->get_path()->connect("text_changed", this,"_text_changed");
- _update_method_list();
- }
-
- if (p_what==NOTIFICATION_DRAW) {
-
- RID ci = get_canvas_item();
- get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
- }
-}
-
-
-void CallDialog::_call() {
-
- if (!tree->get_selected())
- return;
-
- TreeItem* item=tree->get_selected();
- ERR_FAIL_COND(!item);
- int idx=item->get_metadata(0);
- ERR_FAIL_INDEX(idx,methods.size());
- MethodInfo &m = methods[idx];
-
- Variant args[VARIANT_ARG_MAX];
-
- for(int i=0;i<VARIANT_ARG_MAX;i++) {
-
- if (i>=m.arguments.size())
- continue;
-
- if (call_params->values.has(m.arguments[i].name))
- args[i]=call_params->values[m.arguments[i].name];
- }
-
- Variant ret = object->call(m.name,args[0],args[1],args[2],args[3],args[4]);
- if (ret.get_type()!=Variant::NIL)
- return_value->set_text(ret);
- else
- return_value->set_text("");
-}
-
-void CallDialog::_cancel() {
-
- hide();
-}
-
-
-void CallDialog::_item_selected() {
-
- TreeItem* item=tree->get_selected();
- ERR_FAIL_COND(!item);
-
- if (item->get_metadata(0).get_type()==Variant::NIL) {
-
- call->set_disabled(true);
- return;
- }
-
- call->set_disabled(false);
-
- int idx=item->get_metadata(0);
- ERR_FAIL_INDEX(idx,methods.size());
-
- MethodInfo &m = methods[idx];
-
- call_params->values.clear();
- call_params->method=m;
-
- property_editor->edit(call_params);
- property_editor->update_tree();
-
-
-}
-
-void CallDialog::_update_method_list() {
-
- tree->clear();
- if (!object)
- return;
-
- TreeItem *root = tree->create_item();
-
- List<MethodInfo> method_list;
- object->get_method_list(&method_list);
- method_list.sort();
- methods.clear();
-
- List<String> inheritance_list;
-
- String type = object->get_class();
-
- while(type!="") {
- inheritance_list.push_back( type );
- type=ClassDB::get_parent_class(type);
- }
-
- TreeItem *selected_item=NULL;
-
- for(int i=0;i<inheritance_list.size();i++) {
-
- String type=inheritance_list[i];
- String parent_type=ClassDB::get_parent_class(type);
-
- TreeItem *type_item=NULL;
-
- List<MethodInfo>::Element *N,*E=method_list.front();
-
- while(E) {
-
- N=E->next();
-
- if (parent_type!="" && ClassDB::get_method(parent_type,E->get().name)!=NULL) {
- E=N;
- continue;
- }
-
- if (!type_item) {
- type_item=tree->create_item(root);
- type_item->set_text(0,type);
- if (has_icon(type,"EditorIcons"))
- type_item->set_icon(0,get_icon(type,"EditorIcons"));
- }
-
- TreeItem *method_item = tree->create_item(type_item);
- method_item->set_text(0,E->get().name);
- method_item->set_metadata(0,methods.size());
- if (E->get().name==selected)
- selected_item=method_item;
- methods.push_back( E->get() );
-
- method_list.erase(E);
- E=N;
- }
- }
-
-
-
- if (selected_item)
- selected_item->select(0);
-}
-
-void CallDialog::_bind_methods() {
-
- ClassDB::bind_method("_call",&CallDialog::_call);
- ClassDB::bind_method("_cancel",&CallDialog::_cancel);
- ClassDB::bind_method("_item_selected", &CallDialog::_item_selected);
-
-}
-
-void CallDialog::set_object(Object *p_object,StringName p_selected) {
-
- object=p_object;
- selected=p_selected;
- property_editor->edit(NULL);
- call->set_disabled(true);
- return_value->clear();
-
- _update_method_list();
- method_label->set_text(vformat(TTR("Method List For '%s':"),p_object->get_class()));
-}
-
-CallDialog::CallDialog() {
-
- object=NULL;
-
- call = memnew( Button );
- call->set_anchor( MARGIN_LEFT, ANCHOR_END );
- call->set_anchor( MARGIN_TOP, ANCHOR_END );
- call->set_anchor( MARGIN_RIGHT, ANCHOR_END );
- call->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
- call->set_begin( Point2( -70, -29 ) );
- call->set_end( Point2( -15, -15 ) );
- call->set_text(TTR("Call"));
-
- add_child(call);
-
- cancel = memnew( Button );
- cancel->set_anchor( MARGIN_TOP, ANCHOR_END );
- cancel->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
- cancel->set_begin( Point2( -15, 29 ) );
- cancel->set_end( Point2( 70, -15 ) );
- cancel->set_text(TTR("Close"));
-
- add_child(cancel);
-
- tree = memnew( Tree );
-
- tree->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
- tree->set_begin( Point2( 20,50 ) );
- tree->set_margin(MARGIN_BOTTOM, -44 );
- tree->set_margin(MARGIN_RIGHT, 0.5 );
- tree->set_select_mode( Tree::SELECT_ROW );
- add_child(tree);
-
- tree->connect("item_selected", this,"_item_selected");
- tree->set_hide_root(true);
-
- property_editor = memnew( PropertyEditor );
-
- property_editor->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, -15 );
- property_editor->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 50 );
- //property_editor->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 );
- property_editor->set_anchor_and_margin( MARGIN_BOTTOM, ANCHOR_END, -90 );
- property_editor->get_scene_tree()->set_hide_root( true );
- property_editor->hide_top_label();
-
- add_child(property_editor);
- method_label = memnew(Label);
- method_label->set_position(Point2( 15,25));
- method_label->set_text(TTR("Method List:"));
-
- add_child(method_label);
-
- Label *label = memnew( Label );
- //label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 );
- label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_BEGIN, 25 );
- label->set_text(TTR("Arguments:"));
-
- add_child(label);
-
- return_label = memnew( Label );
- //return_label->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.53 );
- return_label->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, -85 );
- return_label->set_text(TTR("Return:"));
-
- add_child(return_label);
-
- return_value = memnew( LineEdit );
- //return_value->set_anchor_and_margin( MARGIN_LEFT, ANCHOR_RATIO, 0.55 );
- return_value->set_anchor_and_margin( MARGIN_RIGHT, ANCHOR_END, -15 );
- return_value->set_anchor_and_margin( MARGIN_TOP, ANCHOR_END, -65 );
-
- add_child(return_value);
-
- /*
- label = memnew( Label );
- label->set_anchor( MARGIN_TOP, ANCHOR_END );
- label->set_anchor( MARGIN_BOTTOM, ANCHOR_END );
-
- label->set_begin( Point2( 15,54) );
- label->set_end( Point2( 16,44) );
- label->set_text("Parameters:");
-
- add_child(label);
- */
-
-
- call_params = memnew( CallDialogParams );
- set_as_toplevel(true);
-}
-
-
-CallDialog::~CallDialog()
-{
- memdelete(call_params);
-}
-#endif
diff --git a/editor/call_dialog.h b/editor/call_dialog.h
deleted file mode 100644
index 2e20d5e587..0000000000
--- a/editor/call_dialog.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*************************************************************************/
-/* call_dialog.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 CALL_DIALOG_H
-#define CALL_DIALOG_H
-
-#include "editor/property_editor.h"
-#include "scene/gui/button.h"
-#include "scene/gui/label.h"
-#include "scene/gui/line_edit.h"
-#include "scene/gui/popup.h"
-#include "scene/gui/tree.h"
-/**
- @author Juan Linietsky <reduzio@gmail.com>
-*/
-
-#if 0
-
-class CallDialogParams;
-
-class CallDialog : public Popup {
-
- GDCLASS( CallDialog, Popup );
-
-
- Label* method_label;
- Tree *tree;
- Button *call;
- Button *cancel;
-
- CallDialogParams *call_params;
- PropertyEditor *property_editor;
-
- Label *return_label;
- LineEdit *return_value;
- Object *object;
- StringName selected;
-
- Vector<MethodInfo> methods;
-
-
- void _item_selected();
- void _update_method_list();
- void _call();
- void _cancel();
-
-protected:
- static void _bind_methods();
- void _notification(int p_what);
-public:
-
- void set_object(Object *p_object,StringName p_selected="");
-
- CallDialog();
- ~CallDialog();
-
-};
-
-#endif
-#endif
diff --git a/editor/collada/collada.cpp b/editor/collada/collada.cpp
index e90b3ec85c..4986d97e8f 100644
--- a/editor/collada/collada.cpp
+++ b/editor/collada/collada.cpp
@@ -31,7 +31,7 @@
#include "collada.h"
-#include "stdio.h"
+#include <stdio.h>
//#define DEBUG_DEFAULT_ANIMATION
//#define DEBUG_COLLADA
@@ -671,15 +671,7 @@ void Collada::_parse_effect_material(XMLParser &parser, Effect &effect, String &
}
} else if (what == "shininess") {
-#if 1
effect.shininess = _parse_param(parser);
-#else
-
- parser.read();
- float shininess = parser.get_node_data().to_double();
- effect.shininess = shininess;
- COLLADA_PRINT("shininess: " + rtos(shininess));
-#endif
}
} else if (parser.get_node_type() == XMLParser::NODE_ELEMENT_END && (parser.get_node_name() == "constant" ||
parser.get_node_name() == "lambert" ||
@@ -2505,7 +2497,7 @@ void Collada::_optimize() {
for (int i = 0; i < vs.root_nodes.size(); i++) {
_create_skeletons(&vs.root_nodes[i]);
}
-#if 1
+
for (int i = 0; i < vs.root_nodes.size(); i++) {
_merge_skeletons(&vs, vs.root_nodes[i]);
}
@@ -2531,7 +2523,7 @@ void Collada::_optimize() {
mgeom.pop_front();
}
}
-#endif
+
for (int i = 0; i < vs.root_nodes.size(); i++) {
_find_morph_nodes(&vs, vs.root_nodes[i]);
}
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp
index fde6a7a664..b4c2ac95cc 100644
--- a/editor/connections_dialog.cpp
+++ b/editor/connections_dialog.cpp
@@ -113,33 +113,7 @@ void ConnectDialog::_tree_node_selected() {
make_callback->hide();
else
make_callback->show();
-#if 0
- List<MethodInfo> methods;
- current->get_method_list(&methods);
- for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
-
- if (E->get().name.length() && E->get().name[0]=='_')
- continue; // hidden method, not show!
-
- if (ClassDB::has_method(node->get_type(),"Node") || ClassDB::has_method(node->get_type(),"Control",true))
- continue; //avoid too much unnecessary stuff
-
- String method=E->get().name+"(";
- for(int i=0;i<E->get().arguments.size();i++) {
-
- if (i!=0)
- method+=", ";
- method+=Variant::get_type_name(E->get().arguments[i].type);
- if (E->get().arguments[i].name.length()) {
- method+=" ";
- method+=E->get().arguments[i].name;
- }
- }
- method+=")";
- //dst_method_list->get_popup()->add_item(method);
- }
-#endif
dst_path->set_text(node->get_path_to(current));
}
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp
index 9941f0fde0..e761dce8ab 100644
--- a/editor/editor_export.cpp
+++ b/editor/editor_export.cpp
@@ -1169,2205 +1169,3 @@ void EditorExportPlatformPC::get_platform_features(List<String> *r_features) {
EditorExportPlatformPC::EditorExportPlatformPC() {
}
-
-////////
-
-#if 0
-#include "editor/editor_file_system.h"
-#include "editor/plugins/script_editor_plugin.h"
-#include "editor_node.h"
-#include "editor_settings.h"
-#include "io/config_file.h"
-#include "io/md5.h"
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "io/zip_io.h"
-#include "io_plugins/editor_texture_import_plugin.h"
-#include "os/dir_access.h"
-#include "os/file_access.h"
-#include "project_settings.h"
-#include "script_language.h"
-#include "version.h"
-
-
-String EditorImportPlugin::validate_source_path(const String& p_path) {
-
- String gp = ProjectSettings::get_singleton()->globalize_path(p_path);
- String rp = ProjectSettings::get_singleton()->get_resource_path();
- if (!rp.ends_with("/"))
- rp+="/";
-
- return rp.path_to_file(gp);
-}
-
-String EditorImportPlugin::expand_source_path(const String& p_path) {
-
- if (p_path.is_rel_path()) {
- return ProjectSettings::get_singleton()->get_resource_path().plus_file(p_path).simplify_path();
- } else {
- return p_path;
- }
-}
-
-
-String EditorImportPlugin::_validate_source_path(const String& p_path) {
-
- return validate_source_path(p_path);
-}
-
-String EditorImportPlugin::_expand_source_path(const String& p_path) {
-
- return expand_source_path(p_path);
-}
-
-void EditorImportPlugin::_bind_methods() {
-
-
- ClassDB::bind_method(D_METHOD("validate_source_path","path"),&EditorImportPlugin::_validate_source_path);
- ClassDB::bind_method(D_METHOD("expand_source_path","path"),&EditorImportPlugin::_expand_source_path);
-
- ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::STRING,"get_name"));
- ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::STRING,"get_visible_name"));
- ClassDB::add_virtual_method(get_class_static(),MethodInfo("import_dialog",PropertyInfo(Variant::STRING,"from")));
- ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::INT,"import",PropertyInfo(Variant::STRING,"path"),PropertyInfo(Variant::OBJECT,"from",PROPERTY_HINT_RESOURCE_TYPE,"ResourceImportMetadata")));
- ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::POOL_BYTE_ARRAY,"custom_export",PropertyInfo(Variant::STRING,"path"),PropertyInfo(Variant::OBJECT,"platform",PROPERTY_HINT_RESOURCE_TYPE,"EditorExportPlatform")));
- ClassDB::add_virtual_method(get_class_static(),MethodInfo("import_from_drop",PropertyInfo(Variant::POOL_STRING_ARRAY,"files"),PropertyInfo(Variant::STRING,"dest_path")));
- ClassDB::add_virtual_method(get_class_static(),MethodInfo("reimport_multiple_files",PropertyInfo(Variant::POOL_STRING_ARRAY,"files")));
- ClassDB::add_virtual_method(get_class_static(),MethodInfo(Variant::BOOL,"can_reimport_multiple_files"));
-
- //BIND_VMETHOD( mi );
-}
-
-String EditorImportPlugin::get_name() const {
-
- if (get_script_instance() && get_script_instance()->has_method("get_name")) {
- return get_script_instance()->call("get_name");
- }
-
- ERR_FAIL_V("");
-}
-
-String EditorImportPlugin::get_visible_name() const {
-
- if (get_script_instance() && get_script_instance()->has_method("get_visible_name")) {
- return get_script_instance()->call("get_visible_name");
- }
-
- ERR_FAIL_V("");
-}
-
-
-void EditorImportPlugin::import_dialog(const String& p_from) {
-
- if (get_script_instance() && get_script_instance()->has_method("import_dialog")) {
- get_script_instance()->call("import_dialog",p_from);
- return;
- }
-
- ERR_FAIL();
-
-}
-
-Error EditorImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from) {
-
- if (get_script_instance() && get_script_instance()->has_method("import")) {
- return Error(get_script_instance()->call("import",p_path,p_from).operator int());
- }
-
- ERR_FAIL_V(ERR_UNAVAILABLE);
-}
-
-Vector<uint8_t> EditorImportPlugin::custom_export(const String& p_path, const Ref<EditorExportPlatform> &p_platform) {
-
- if (get_script_instance() && get_script_instance()->has_method("custom_export")) {
- get_script_instance()->call("custom_export",p_path,p_platform);
- }
-
- return Vector<uint8_t>();
-}
-
-bool EditorImportPlugin::can_reimport_multiple_files() const {
-
- if (get_script_instance() && get_script_instance()->has_method("can_reimport_multiple_files")) {
- return get_script_instance()->call("can_reimport_multiple_files");
- }
-
- return false;
-}
-void EditorImportPlugin::reimport_multiple_files(const Vector<String>& p_list) {
-
- if (get_script_instance() && get_script_instance()->has_method("reimport_multiple_files")) {
- get_script_instance()->call("reimport_multiple_files",p_list);
- }
-
-}
-
-void EditorImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
-
- if (get_script_instance() && get_script_instance()->has_method("import_from_drop")) {
- get_script_instance()->call("import_from_drop",p_drop,p_dest_path);
- }
-
-}
-
-EditorImportPlugin::EditorImportPlugin() {
-
-
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-void EditorExportPlugin::_bind_methods() {
-
- MethodInfo mi = MethodInfo("custom_export:Variant",PropertyInfo(Variant::STRING,"name"),PropertyInfo(Variant::OBJECT,"platform",PROPERTY_HINT_RESOURCE_TYPE,"EditorExportPlatform"));
- mi.return_val.type=Variant::POOL_BYTE_ARRAY;
-
- BIND_VMETHOD( mi );
-}
-
-
-Vector<uint8_t> EditorExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) {
-
- if (get_script_instance()) {
-
- Variant d = get_script_instance()->call("custom_export",p_path,p_platform);
- if (d.get_type()==Variant::NIL)
- return Vector<uint8_t>();
- if (d.get_type()==Variant::POOL_BYTE_ARRAY)
- return d;
-
- ERR_FAIL_COND_V(d.get_type()!=Variant::DICTIONARY,Vector<uint8_t>());
- Dictionary dict=d;
- ERR_FAIL_COND_V(!dict.has("name"),Vector<uint8_t>());
- ERR_FAIL_COND_V(!dict.has("data"),Vector<uint8_t>());
- p_path=dict["name"];
- return dict["data"];
- }
-
- return Vector<uint8_t>();
-
-}
-
-
-EditorExportPlugin::EditorExportPlugin() {
-
-
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-
-static void _add_to_list(EditorFileSystemDirectory *p_efsd,Set<StringName>& r_list) {
-
- for(int i=0;i<p_efsd->get_subdir_count();i++) {
-
- _add_to_list(p_efsd->get_subdir(i),r_list);
- }
-
- for(int i=0;i<p_efsd->get_file_count();i++) {
- r_list.insert(p_efsd->get_file_path(i));
- }
-}
-
-
-struct __EESortDepCmp {
-
- _FORCE_INLINE_ bool operator()(const StringName& p_l,const StringName& p_r) const {
- return p_l.operator String() < p_r.operator String();
- }
-};
-
-
-
-
-static void _edit_files_with_filter(DirAccess *da,const List<String>& p_filters,Set<StringName>& r_list,bool exclude) {
-
-
- List<String> files;
- List<String> dirs;
-
- da->list_dir_begin();
-
- String f = da->get_next();
- while(f!="") {
-
- print_line("HOHO: "+f);
- if (da->current_is_dir())
- dirs.push_back(f);
- else
- files.push_back(f);
-
- f=da->get_next();
- }
-
- String r = da->get_current_dir().replace("\\","/");
- if (!r.ends_with("/"))
- r+="/";
-
- print_line("AT: "+r);
-
- for(List<String>::Element *E=files.front();E;E=E->next()) {
- String fullpath=r+E->get();
- for(const List<String>::Element *F=p_filters.front();F;F=F->next()) {
-
- if (fullpath.matchn(F->get())) {
- String act = TTR("Added:")+" ";
-
- if (!exclude) {
- r_list.insert(fullpath);
- } else {
- act = TTR("Removed:")+" ";
- r_list.erase(fullpath);
- }
-
-
- print_line(act+fullpath);
- }
- }
- }
-
- da->list_dir_end();
-
- for(List<String>::Element *E=dirs.front();E;E=E->next()) {
- if (E->get().begins_with("."))
- continue;
- da->change_dir(E->get());
- _edit_files_with_filter(da,p_filters,r_list,exclude);
- da->change_dir("..");
- }
-
-}
-
-static void _edit_filter_list(Set<StringName>& r_list,const String& p_filter,bool exclude) {
-
- if (p_filter=="")
- return;
- Vector<String> split = p_filter.split(",");
- List<String> filters;
- for(int i=0;i<split.size();i++) {
- String f = split[i].strip_edges();
- if (f.empty())
- continue;
- filters.push_back(f);
- }
-
- DirAccess *da = DirAccess::open("res://");
- ERR_FAIL_NULL(da);
- _edit_files_with_filter(da,filters,r_list,exclude);
- memdelete(da);
-}
-
-static void _add_filter_to_list(Set<StringName>& r_list,const String& p_filter) {
- _edit_filter_list(r_list,p_filter,false);
-}
-
-static void _remove_filter_from_list(Set<StringName>& r_list,const String& p_filter) {
- _edit_filter_list(r_list,p_filter,true);
-}
-
-bool EditorExportPlatform::_set(const StringName& p_name, const Variant& p_value) {
-
- String n = p_name;
-
- if (n=="debug/debugging_enabled") {
- set_debugging_enabled(p_value);
- } else {
- return false;
- }
-
- return true;
-
-}
-
-bool EditorExportPlatform::_get(const StringName& p_name,Variant &r_ret) const {
-
- String n = p_name;
-
- if (n=="debug/debugging_enabled") {
- r_ret=is_debugging_enabled();
- } else {
- return false;
- }
-
- return true;
-
-}
-
-void EditorExportPlatform::_get_property_list( List<PropertyInfo> *p_list) const {
-
- p_list->push_front( PropertyInfo( Variant::BOOL, "debug/debugging_enabled"));
-}
-
-Vector<uint8_t> EditorExportPlatform::get_exported_file_default(String& p_fname) const {
-
- FileAccess *f = FileAccess::open(p_fname,FileAccess::READ);
- ERR_FAIL_COND_V(!f,Vector<uint8_t>());
- Vector<uint8_t> ret;
- ret.resize(f->get_len());
- int rbs = f->get_buffer(ret.ptr(),ret.size());
- memdelete(f);
- return ret;
-}
-
-Vector<uint8_t> EditorExportPlatform::get_exported_file(String& p_fname) const {
-
- Ref<EditorExportPlatform> ep=EditorImportExport::get_singleton()->get_export_platform(get_name());
-
- for(int i=0;i<EditorImportExport::get_singleton()->get_export_plugin_count();i++) {
-
- Vector<uint8_t> data = EditorImportExport::get_singleton()->get_export_plugin(i)->custom_export(p_fname,ep);
- if (data.size())
- return data;
-
- }
-
-
- return get_exported_file_default(p_fname);
-
-
-}
-
-Vector<StringName> EditorExportPlatform::get_dependencies(bool p_bundles) const {
-
-
- Set<StringName> exported;
-
- if (FileAccess::exists("res://project.godot"))
- exported.insert("res://project.godot");
-
- if (EditorImportExport::get_singleton()->get_export_filter()!=EditorImportExport::EXPORT_SELECTED) {
-
- String filter;
- if (EditorImportExport::get_singleton()->get_export_filter()==EditorImportExport::EXPORT_ALL) {
- _add_filter_to_list(exported,"*");
- } else {
- _add_to_list(EditorFileSystem::get_singleton()->get_filesystem(),exported);
- String cf = EditorImportExport::get_singleton()->get_export_custom_filter();
- if (cf!="")
- cf+=",";
- cf+="*.flags";
- _add_filter_to_list(exported,cf);
-
- cf = EditorImportExport::get_singleton()->get_export_custom_filter_exclude();
- _remove_filter_from_list(exported,cf);
- }
-
-
- } else {
-
-
- Map<String,Map<String,String> > remapped_paths;
-
- Set<String> scene_extensions;
- Set<String> resource_extensions;
-
- {
-
- List<String> l;
- /*
- SceneLoader::get_recognized_extensions(&l);
- for(List<String>::Element *E=l.front();E;E=E->next()) {
- scene_extensions.insert(E->get());
- }
- */
- ResourceLoader::get_recognized_extensions_for_type("",&l);
- for(List<String>::Element *E=l.front();E;E=E->next()) {
-
- resource_extensions.insert(E->get());
- }
- }
-
-
- List<StringName> toexport;
-
- EditorImportExport::get_singleton()->get_export_file_list(&toexport);
-
- print_line("TO EXPORT: "+itos(toexport.size()));
-
-
- for (List<StringName>::Element *E=toexport.front();E;E=E->next()) {
-
- print_line("DEP: "+String(E->get()));
- exported.insert(E->get());
- if (p_bundles && EditorImportExport::get_singleton()->get_export_file_action(E->get())==EditorImportExport::ACTION_BUNDLE) {
- print_line("NO BECAUSE OF BUNDLE!");
- continue; //no dependencies needed to be copied
- }
-
- List<String> testsubs;
- testsubs.push_back(E->get());
-
- while(testsubs.size()) {
- //recursive subdep search!
- List<String> deplist;
- ResourceLoader::get_dependencies(testsubs.front()->get(),&deplist);
- testsubs.pop_front();
-
- List<String> subdeps;
-
- for (List<String>::Element *F=deplist.front();F;F=F->next()) {
-
- StringName dep = F->get();
-
- if (exported.has(dep) || EditorImportExport::get_singleton()->get_export_file_action(dep)!=EditorImportExport::ACTION_NONE)
- continue; //dependency added or to be added
- print_line(" SUBDEP: "+String(dep));
-
- exported.insert(dep);
- testsubs.push_back(dep);
- }
- }
- }
- String cf = EditorImportExport::get_singleton()->get_export_custom_filter();
- if (cf!="")
- cf+=",";
- cf+="*.flags";
- _add_filter_to_list(exported,cf);
-
- cf = EditorImportExport::get_singleton()->get_export_custom_filter_exclude();
- _remove_filter_from_list(exported,cf);
-
-
- }
-
- Vector<StringName> ret;
- ret.resize(exported.size());
-
-
- int idx=0;
- for(Set<StringName>::Element *E=exported.front();E;E=E->next()) {
-
- ret[idx++]=E->get();
-
- }
-
- SortArray<StringName,__EESortDepCmp> sort; //some platforms work better if this is sorted
- sort.sort(ret.ptr(),ret.size());
-
- return ret;
-
-}
-
-///////////////////////////////////////
-
-
-
-bool EditorExportPlatform::is_debugging_enabled() const {
-
- return debugging_enabled;
-}
-
-void EditorExportPlatform::set_debugging_enabled(bool p_enabled) {
-
- debugging_enabled = p_enabled;
-}
-
-bool EditorExportPlatformPC::_set(const StringName& p_name, const Variant& p_value) {
-
- String n = p_name;
-
- if (n=="custom_binary/release") {
-
- custom_release_binary=p_value;
- } else if (n=="custom_binary/debug") {
-
- custom_debug_binary=p_value;
- } else if (n=="resources/pack_mode") {
-
- export_mode=ExportMode(int(p_value));
- } else if (n=="resources/bundle_dependencies_(for_optical_disc)") {
-
- bundle=p_value;
- } else if (n=="binary/64_bits") {
-
- use64=p_value;
- } else
- return false;
-
- return true;
-
-}
-
-bool EditorExportPlatformPC::_get(const StringName& p_name,Variant &r_ret) const {
-
- String n = p_name;
-
- if (n=="custom_binary/release") {
-
- r_ret=custom_release_binary;
- } else if (n=="custom_binary/debug") {
-
- r_ret=custom_debug_binary;
- } else if (n=="resources/pack_mode") {
-
- r_ret=export_mode;
- } else if (n=="resources/bundle_dependencies_(for_optical_disc)") {
-
- r_ret=bundle;
- } else if (n=="binary/64_bits") {
-
- r_ret=use64;
- } else
- return false;
-
- return true;
-
-}
-
-void EditorExportPlatformPC::_get_property_list( List<PropertyInfo> *p_list) const {
-
- p_list->push_back( PropertyInfo( Variant::STRING, "custom_binary/debug", PROPERTY_HINT_GLOBAL_FILE,binary_extension));
- p_list->push_back( PropertyInfo( Variant::STRING, "custom_binary/release", PROPERTY_HINT_GLOBAL_FILE,binary_extension));
- p_list->push_back( PropertyInfo( Variant::INT, "resources/pack_mode", PROPERTY_HINT_ENUM,"Pack into executable,Pack into binary file (.pck),Pack into archive file (.zip)"));
- p_list->push_back( PropertyInfo( Variant::BOOL, "resources/bundle_dependencies_(for_optical_disc)"));
- p_list->push_back( PropertyInfo( Variant::BOOL, "binary/64_bits"));
-}
-
-
-
-static void _exp_add_dep(Map<StringName,List<StringName> > &deps,const StringName& p_path) {
-
-
- if (deps.has(p_path))
- return; //already done
-
- deps.insert(p_path,List<StringName>());
-
- List<StringName> &deplist=deps[p_path];
- Set<StringName> depset;
-
- List<String> dl;
- ResourceLoader::get_dependencies(p_path,&dl);
-
- //added in order so child dependencies are always added bfore parent dependencies
- for (List<String>::Element *E=dl.front();E;E=E->next()) {
-
-
- if (!deps.has(E->get()))
- _exp_add_dep(deps,E->get());
-
- for(List<StringName>::Element *F=deps[E->get()].front();F;F=F->next()) {
-
-
- if (!depset.has(F->get())) {
- depset.insert(F->get());
- deplist.push_back(F->get());
- }
- }
-
- if (!depset.has(E->get())) {
- depset.insert(E->get());
- deplist.push_back(E->get());
- }
-
- }
-}
-
-
-
-Error EditorExportPlatform::export_project_files(EditorExportSaveFunction p_func, void* p_udata,bool p_make_bundles) {
-
-/* ALL FILES AND DEPENDENCIES */
-
- Vector<StringName> files=get_dependencies(p_make_bundles);
-
- Map<StringName,List<StringName> > deps;
-
- if (false) {
- for(int i=0;i<files.size();i++) {
-
- _exp_add_dep(deps,files[i]);
-
- }
- }
-
-
-
-/* GROUP ATLAS */
-
-
- List<StringName> groups;
-
- EditorImportExport::get_singleton()->image_export_get_groups(&groups);
-
- Map<StringName,StringName> remap_files;
- Set<StringName> saved;
-
- int counter=0;
-
- for(List<StringName>::Element *E=groups.front();E;E=E->next()) {
-
- if (!EditorImportExport::get_singleton()->image_export_group_get_make_atlas(E->get()))
- continue; //uninterested, only process for atlas!
-
- List<StringName> atlas_images;
- EditorImportExport::get_singleton()->image_export_get_images_in_group(E->get(),&atlas_images);
- atlas_images.sort_custom<StringName::AlphCompare>();
-
- for (List<StringName>::Element *F=atlas_images.front();F;) {
-
- List<StringName>::Element *N=F->next();
-
- if (!FileAccess::exists(F->get())) {
- atlas_images.erase(F);
- }
-
- F=N;
-
- }
-
- if (atlas_images.size()<=1)
- continue;
-
- int group_format=0;
- float group_lossy_quality=EditorImportExport::get_singleton()->image_export_group_get_lossy_quality(E->get());
- int group_shrink=EditorImportExport::get_singleton()->image_export_group_get_shrink(E->get());
- group_shrink*=EditorImportExport::get_singleton()->get_export_image_shrink();
-
- switch(EditorImportExport::get_singleton()->image_export_group_get_image_action(E->get())) {
- case EditorImportExport::IMAGE_ACTION_KEEP:
- case EditorImportExport::IMAGE_ACTION_NONE: {
-
- switch(EditorImportExport::get_singleton()->get_export_image_action()) {
- case EditorImportExport::IMAGE_ACTION_NONE: {
-
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS; //?
-
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: {
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY;
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: {
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM;
- } break; //use default
- }
-
- group_lossy_quality=EditorImportExport::get_singleton()->get_export_image_quality();
-
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: {
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY;
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: {
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM;
- } break; //use default
- }
-
- String image_list_md5;
-
- {
- MD5_CTX ctx;
- MD5Init(&ctx);
- for (List<StringName>::Element *F=atlas_images.front();F;F=F->next()) {
-
- String p = F->get();
- MD5Update(&ctx,(unsigned char*)p.utf8().get_data(),p.utf8().length());
-
- }
-
- MD5Final(&ctx);
- image_list_md5=String::md5(ctx.digest);
- }
- //ok see if cached
- String md5;
- bool atlas_valid=true;
- String atlas_name;
-
- {
- MD5_CTX ctx;
- MD5Init(&ctx);
- String path = ProjectSettings::get_singleton()->get_resource_path()+"::"+String(E->get())+"::"+get_name();
- MD5Update(&ctx,(unsigned char*)path.utf8().get_data(),path.utf8().length());
- MD5Final(&ctx);
- md5 = String::md5(ctx.digest);
- }
-
- FileAccess *f=NULL;
-
- if (!FileAccess::exists(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5)) {
- print_line("NO MD5 INVALID");
- atlas_valid=false;
- }
-
- if (atlas_valid)
- f=FileAccess::open(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5,FileAccess::READ);
-
- if (atlas_valid) {
- //compare options
- /*Dictionary options;
- options.parse_json(f->get_line());
- if (!options.has("lossy_quality") || float(options["lossy_quality"])!=group_lossy_quality)
- atlas_valid=false;
- else if (!options.has("shrink") || int(options["shrink"])!=group_shrink)
- atlas_valid=false;
- else if (!options.has("image_format") || int(options["image_format"])!=group_format)
- atlas_valid=false;
-
- if (!atlas_valid)
- print_line("JSON INVALID");
-*/
- }
-
-
- if (atlas_valid) {
- //check md5 of list of image /names/
- if (f->get_line().strip_edges()!=image_list_md5) {
- atlas_valid=false;
- print_line("IMAGE MD5 INVALID!");
- }
-
- }
-
- Vector<Rect2> rects;
- bool resave_deps=false;
-
- if (atlas_valid) {
-
- //check if images were not modified
- for (List<StringName>::Element *F=atlas_images.front();F;F=F->next()) {
-
- Vector<String> slices = f->get_line().strip_edges().split("::");
-
- if (slices.size()!=10) {
- atlas_valid=false;
- print_line("CAN'T SLICE IN 10");
- break;
- }
- uint64_t mod_time = slices[0].to_int64();
- uint64_t file_mod_time = FileAccess::get_modified_time(F->get());
- if (mod_time!=file_mod_time) {
-
- String image_md5 = slices[1];
- String file_md5 = FileAccess::get_md5(F->get());
-
- if (image_md5!=file_md5) {
- atlas_valid=false;
- print_line("IMAGE INVALID "+slices[0]);
- break;
- } else {
- resave_deps=true;
- }
- }
-
- if (atlas_valid) {
- //push back region and margin
- rects.push_back(Rect2(slices[2].to_float(),slices[3].to_float(),slices[4].to_float(),slices[5].to_float()));
- rects.push_back(Rect2(slices[6].to_float(),slices[7].to_float(),slices[8].to_float(),slices[9].to_float()));
- }
- }
-
- }
-
- if (f) {
- memdelete(f);
- f=NULL;
- }
-
- print_line("ATLAS VALID? "+itos(atlas_valid)+" RESAVE DEPS? "+itos(resave_deps));
- if (!atlas_valid) {
- rects.clear();
- //oh well, atlas is not valid. need to make new one....
-
- String dst_file = EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5+".tex";
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- //imd->set_editor();
-
-
- for (List<StringName>::Element *F=atlas_images.front();F;F=F->next()) {
-
- imd->add_source(EditorImportPlugin::validate_source_path(F->get()),FileAccess::get_md5(F->get()));
-
- }
-
-
- imd->set_option("format",group_format);
-
-
- int flags=0;
-
- if (ProjectSettings::get_singleton()->get("image_loader/filter"))
- flags|=EditorTextureImportPlugin::IMAGE_FLAG_FILTER;
- if (!ProjectSettings::get_singleton()->get("image_loader/gen_mipmaps"))
- flags|=EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS;
- if (!ProjectSettings::get_singleton()->get("image_loader/repeat"))
- flags|=EditorTextureImportPlugin::IMAGE_FLAG_REPEAT;
-
- flags|=EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA;
-
- imd->set_option("flags",flags);
- imd->set_option("quality",group_lossy_quality);
- imd->set_option("atlas",true);
- imd->set_option("crop",true);
- imd->set_option("shrink",group_shrink);
-
-
-
- Ref<EditorTextureImportPlugin> plugin = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture");
- Error err = plugin->import2(dst_file,imd,get_image_compression(),true);
- if (err) {
-
- EditorNode::add_io_error(TTR("Error saving atlas:")+" "+dst_file.get_file());
- return ERR_CANT_CREATE;
- }
-
- ERR_FAIL_COND_V(imd->get_option("rects")==Variant(),ERR_BUG);
-
- Array r_rects=imd->get_option("rects");
- rects.resize(r_rects.size());
- for(int i=0;i<r_rects.size();i++) {
- //get back region and margins
- rects[i]=r_rects[i];
- }
-
-
- resave_deps=true;
- }
-
-
- //atlas is valid (or it was just saved i guess), create the atex files and save them
-
- if (resave_deps) {
- f=FileAccess::open(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5,FileAccess::WRITE);
- Dictionary options;
- options["lossy_quality"]=group_lossy_quality;
- options["shrink"]=EditorImportExport::get_singleton()->image_export_group_get_shrink(E->get());
- options["image_format"]=group_format;
- //f->store_line(options.to_json());
- f->store_line(image_list_md5);
- }
-
- //go through all ATEX files
-
- {
- Ref<ImageTexture> atlas = memnew( ImageTexture ); //fake atlas!
- String atlas_path="res://atlas-"+md5+".tex";
- atlas->set_path(atlas_path);
- int idx=0;
- for (List<StringName>::Element *F=atlas_images.front();F;F=F->next()) {
-
- String p = F->get();
- Ref<AtlasTexture> atex = memnew(AtlasTexture);
- atex->set_atlas(atlas);
- Rect2 region=rects[idx++];
- Rect2 margin=rects[idx++];
- atex->set_region(region);
- atex->set_margin(margin);
-
- String path = EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmpatlas.atlastex";
- Error err = ResourceSaver::save(path,atex);
- if (err!=OK) {
- EditorNode::add_io_error(TTR("Could not save atlas subtexture:")+" "+path);
- return ERR_CANT_CREATE;
- }
- Vector<uint8_t> data = FileAccess::get_file_as_array(path);
- String dst_path = F->get().operator String().get_basename()+".atlastex";
- err = p_func(p_udata,dst_path,data,counter++,files.size());
- saved.insert(dst_path);
- if (err)
- return err;
-
- if (f) {
- //recreating deps..
- String depline;
- //depline=String(F->get())+"::"+itos(FileAccess::get_modified_time(F->get()))+"::"+FileAccess::get_md5(F->get()); name unnecessary by top md5
- depline=itos(FileAccess::get_modified_time(F->get()))+"::"+FileAccess::get_md5(F->get());
- depline+="::"+itos(region.pos.x)+"::"+itos(region.pos.y)+"::"+itos(region.size.x)+"::"+itos(region.size.y);
- depline+="::"+itos(margin.pos.x)+"::"+itos(margin.pos.y)+"::"+itos(margin.size.x)+"::"+itos(margin.size.y);
- f->store_line(depline);
- }
-
- remap_files[F->get()]=dst_path;
- }
-
- Vector<uint8_t> atlas_data = FileAccess::get_file_as_array(EditorSettings::get_singleton()->get_settings_path()+"/tmp/atlas-"+md5+".tex");
- Error err = p_func(p_udata,atlas_path,atlas_data,counter,files.size());
- saved.insert(atlas_path);
- if (err)
- return err;
-
- }
-
-
- if (f) {
- memdelete(f);
- }
-
- }
-
-
- StringName engine_cfg="res://project.godot";
- StringName boot_splash;
- {
- String splash=ProjectSettings::get_singleton()->get("application/boot_splash"); //avoid splash from being converted
- splash=splash.strip_edges();
- if (splash!=String()) {
- if (!splash.begins_with("res://"))
- splash="res://"+splash;
- splash=splash.simplify_path();
- boot_splash=splash;
- }
- }
- StringName custom_cursor;
- {
- String splash=ProjectSettings::get_singleton()->get("display/custom_mouse_cursor"); //avoid splash from being converted
- splash=splash.strip_edges();
- if (splash!=String()) {
- if (!splash.begins_with("res://"))
- splash="res://"+splash;
- splash=splash.simplify_path();
- custom_cursor=splash;
- }
- }
-
-
-
-
- for(int i=0;i<files.size();i++) {
-
- if (remap_files.has(files[i]) || files[i]==engine_cfg) //gonna be remapped (happened before!)
- continue; //from atlas?
- String src=files[i];
- Vector<uint8_t> buf;
-
- if (src==boot_splash || src==custom_cursor)
- buf = get_exported_file_default(src); //bootsplash must be kept if used
- else
- buf = get_exported_file(src);
-
- ERR_CONTINUE( saved.has(src) );
-
- Error err = p_func(p_udata,src,buf,counter++,files.size());
- if (err)
- return err;
-
- saved.insert(src);
- if (src!=String(files[i]))
- remap_files[files[i]]=src;
-
- }
-
-
- {
-
- //make binary project.godot config
- Map<String,Variant> custom;
-
-
- if (remap_files.size()) {
- Vector<String> remapsprop;
- for(Map<StringName,StringName>::Element *E=remap_files.front();E;E=E->next()) {
- print_line("REMAP: "+String(E->key())+" -> "+E->get());
- remapsprop.push_back(E->key());
- remapsprop.push_back(E->get());
- }
-
- custom["remap/all"]=remapsprop;
- }
-
- //add presaved dependencies
- for(Map<StringName,List<StringName> >::Element *E=deps.front();E;E=E->next()) {
-
- if (E->get().size()==0)
- continue; //no deps
- String key;
- Vector<StringName> deps;
- //if bundle continue (when bundles supported obviously)
-
- if (remap_files.has(E->key())) {
- key=remap_files[E->key()];
- } else {
- key=E->key();
- }
-
- deps.resize(E->get().size());
- int i=0;
-
- for(List<StringName>::Element *F=E->get().front();F;F=F->next()) {
- deps[i++]=F->get();
- print_line(" -"+String(F->get()));
- }
-
- NodePath prop(deps,true,String()); //seems best to use this for performance
-
- custom["deps/"+key.md5_text()]=prop;
-
- }
-
- String remap_file="project.binary";
- String engine_cfb =EditorSettings::get_singleton()->get_settings_path()+"/tmp/tmp"+remap_file;
- ProjectSettings::get_singleton()->save_custom(engine_cfb,custom);
- Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb);
-
- Error err = p_func(p_udata,"res://"+remap_file,data,counter,files.size());
- if (err)
- return err;
-
- }
-
- return OK;
-}
-
-static int _get_pad(int p_alignment, int p_n) {
-
- int rest = p_n % p_alignment;
- int pad = 0;
- if (rest > 0) {
- pad = p_alignment - rest;
- };
-
- return pad;
-};
-
-void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) {
-
- String host = EditorSettings::get_singleton()->get("network/debug/remote_host");
- int remote_port = (int)EditorSettings::get_singleton()->get("network/debug/remote_port");
-
- if (p_flags&EXPORT_REMOTE_DEBUG_LOCALHOST)
- host="localhost";
-
- if (p_flags&EXPORT_DUMB_CLIENT) {
- int port = EditorSettings::get_singleton()->get("filesystem/file_server/port");
- String passwd = EditorSettings::get_singleton()->get("filesystem/file_server/password");
- r_flags.push_back("--remote-fs");
- r_flags.push_back(host+":"+itos(port));
- if (passwd!="") {
- r_flags.push_back("--remote-fs-password");
- r_flags.push_back(passwd);
- }
- }
-
- if (p_flags&EXPORT_REMOTE_DEBUG) {
-
- r_flags.push_back("--remote-debug");
-
- r_flags.push_back(host+":"+String::num(remote_port));
-
- List<String> breakpoints;
- ScriptEditor::get_singleton()->get_breakpoints(&breakpoints);
-
-
- if (breakpoints.size()) {
-
- r_flags.push_back("--breakpoints");
- String bpoints;
- for(const List<String>::Element *E=breakpoints.front();E;E=E->next()) {
-
- bpoints+=E->get().replace(" ","%20");
- if (E->next())
- bpoints+=",";
- }
-
- r_flags.push_back(bpoints);
- }
-
- }
-
- if (p_flags&EXPORT_VIEW_COLLISONS) {
-
- r_flags.push_back("--debug-collisions");
- }
-
- if (p_flags&EXPORT_VIEW_NAVIGATION) {
-
- r_flags.push_back("--debug-navigation");
- }
-
-
-}
-
-Error EditorExportPlatform::save_pack_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total) {
-
-
- PackData *pd = (PackData*)p_userdata;
-
- CharString cs=p_path.utf8();
- pd->f->store_32(cs.length());
- pd->f->store_buffer((uint8_t*)cs.get_data(),cs.length());
- TempData td;
- td.pos=pd->f->get_pos();
- td.ofs=pd->ftmp->get_pos();
- td.size=p_data.size();
- pd->file_ofs.push_back(td);
- pd->f->store_64(0); //ofs
- pd->f->store_64(0); //size
- {
- MD5_CTX ctx;
- MD5Init(&ctx);
- MD5Update(&ctx,(unsigned char*)p_data.ptr(),p_data.size());
- MD5Final(&ctx);
- pd->f->store_buffer(ctx.digest,16);
- }
- pd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false);
- pd->count++;
- pd->ftmp->store_buffer(p_data.ptr(),p_data.size());
- if (pd->alignment > 1) {
-
- int pad = _get_pad(pd->alignment, pd->ftmp->get_pos());
- for (int i=0; i<pad; i++) {
-
- pd->ftmp->store_8(0);
- };
- };
- return OK;
-
-}
-
-Error EditorExportPlatform::save_zip_file(void *p_userdata,const String& p_path, const Vector<uint8_t>& p_data,int p_file,int p_total) {
-
-
- String path=p_path.replace_first("res://","");
-
- ZipData *zd = (ZipData*)p_userdata;
-
- zipFile zip=(zipFile)zd->zip;
-
- zipOpenNewFileInZip(zip,
- path.utf8().get_data(),
- NULL,
- NULL,
- 0,
- NULL,
- 0,
- NULL,
- Z_DEFLATED,
- Z_DEFAULT_COMPRESSION);
-
- zipWriteInFileInZip(zip,p_data.ptr(),p_data.size());
- zipCloseFileInZip(zip);
-
- zd->ep->step(TTR("Storing File:")+" "+p_path,2+p_file*100/p_total,false);
- zd->count++;
- return OK;
-
-}
-
-Error EditorExportPlatform::save_zip(const String& p_path, bool p_make_bundles) {
-
- EditorProgress ep("savezip",TTR("Packing"),102);
-
- //FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE);
-
- FileAccess *src_f;
- zlib_filefunc_def io = zipio_create_io_from_file(&src_f);
- zipFile zip=zipOpen2(p_path.utf8().get_data(),APPEND_STATUS_CREATE,NULL,&io);
-
- ZipData zd;
- zd.count=0;
- zd.ep=&ep;
- zd.zip=zip;
-
-
- Error err = export_project_files(save_zip_file,&zd,p_make_bundles);
-
- zipClose(zip,NULL);
-
- return err;
-}
-
-Error EditorExportPlatform::save_pack(FileAccess *dst,bool p_make_bundles, int p_alignment) {
-
- EditorProgress ep("savepack",TTR("Packing"),102);
-
- String tmppath = EditorSettings::get_singleton()->get_settings_path()+"/tmp/packtmp";
- FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE);
- uint64_t ofs_begin = dst->get_pos();
-
- dst->store_32(0x43504447); //GDPK
- dst->store_32(0); //pack version
- dst->store_32(VERSION_MAJOR);
- dst->store_32(VERSION_MINOR);
- dst->store_32(0); //hmph
- for(int i=0;i<16;i++) {
- //reserved
- dst->store_32(0);
- }
-
- size_t fcountpos = dst->get_pos();
- dst->store_32(0);
-
- PackData pd;
- pd.ep=&ep;
- pd.f=dst;
- pd.ftmp=tmp;
- pd.count=0;
- pd.alignment = p_alignment;
- Error err = export_project_files(save_pack_file,&pd,p_make_bundles);
- memdelete(tmp);
- if (err)
- return err;
-
- if (p_alignment > 1) {
- int pad = _get_pad(p_alignment, dst->get_pos());
- for (int i=0; i<pad; i++) {
-
- dst->store_8(0);
- };
- };
-
- size_t ofsplus = dst->get_pos();
- //append file
-
- tmp = FileAccess::open(tmppath,FileAccess::READ);
-
- ERR_FAIL_COND_V(!tmp,ERR_CANT_OPEN;)
- const int bufsize=16384;
- uint8_t buf[bufsize];
-
- while(true) {
-
- int got = tmp->get_buffer(buf,bufsize);
- if (got<=0)
- break;
- dst->store_buffer(buf,got);
- }
-
- memdelete(tmp);
-
- dst->store_64(dst->get_pos()-ofs_begin);
- dst->store_32(0x43504447); //GDPK
-
- //fix offsets
-
- dst->seek(fcountpos);
- dst->store_32(pd.count);
- for(int i=0;i<pd.file_ofs.size();i++) {
-
- dst->seek(pd.file_ofs[i].pos);
- dst->store_64(pd.file_ofs[i].ofs+ofsplus);
- dst->store_64(pd.file_ofs[i].size);
- }
-
- return OK;
-}
-
-EditorExportPlatform::EditorExportPlatform() {
-
- debugging_enabled = true;
-}
-
-Error EditorExportPlatformPC::export_project(const String& p_path, bool p_debug, int p_flags) {
-
-
-
- EditorProgress ep("export",vformat(TTR("Exporting for %s"),get_name()),102);
-
- const int BUFSIZE = 32768;
-
-
-
- ep.step(TTR("Setting Up.."),0);
-
- String exe_path="";
-
- if (p_debug)
- exe_path=custom_debug_binary;
- else
- exe_path=custom_release_binary;
-
- if (exe_path=="") {
- String fname;
- if (use64) {
- if (p_debug)
- fname=debug_binary64;
- else
- fname=release_binary64;
- } else {
- if (p_debug)
- fname=debug_binary32;
- else
- fname=release_binary32;
- }
- String err="";
- exe_path=find_export_template(fname,&err);
- if (exe_path=="") {
- EditorNode::add_io_error(err);
- return ERR_FILE_CANT_READ;
- }
- }
-
- FileAccess *src_exe=FileAccess::open(exe_path,FileAccess::READ);
- if (!src_exe) {
-
- EditorNode::add_io_error("Couldn't read source executable at:\n "+exe_path);
- return ERR_FILE_CANT_READ;
- }
-
- FileAccess *dst=FileAccess::open(p_path,FileAccess::WRITE);
- if (!dst) {
-
- EditorNode::add_io_error("Can't copy executable file to:\n "+p_path);
- return ERR_FILE_CANT_WRITE;
- }
-
- uint8_t buff[32768];
-
- while(true) {
-
- int c = src_exe->get_buffer(buff,BUFSIZE);
- if (c>0) {
-
- dst->store_buffer(buff,c);
- } else {
- break;
- }
- }
-
- String dstfile = p_path.replace_first("res://","").replace("\\","/");
- if (export_mode!=EXPORT_EXE) {
-
- String dstfile_extension=export_mode==EXPORT_ZIP?".zip":".pck";
- if (dstfile.find("/")!=-1)
- dstfile=dstfile.get_base_dir()+"/data"+dstfile_extension;
- else
- dstfile="data"+dstfile_extension;
- if (export_mode==EXPORT_PACK) {
-
- memdelete(dst);
-
- dst=FileAccess::open(dstfile,FileAccess::WRITE);
- if (!dst) {
-
- EditorNode::add_io_error("Can't write data pack to:\n "+p_path);
- return ERR_FILE_CANT_WRITE;
- }
- }
- }
-
-
-
- memdelete(src_exe);
-
- Error err = export_mode==EXPORT_ZIP?save_zip(dstfile,bundle):save_pack(dst,bundle);
- memdelete(dst);
- return err;
-}
-
-void EditorExportPlatformPC::set_binary_extension(const String& p_extension) {
-
- binary_extension=p_extension;
-}
-
-EditorExportPlatformPC::EditorExportPlatformPC() {
-
- export_mode=EXPORT_PACK;
- use64=true;
-}
-
-
-
-
-
-
-
-
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-EditorImportExport* EditorImportExport::singleton=NULL;
-
-void EditorImportExport::add_import_plugin(const Ref<EditorImportPlugin>& p_plugin) {
-
- // Need to make sure the name is unique if we are going to lookup by it
- ERR_FAIL_COND(by_idx.has(p_plugin->get_name()));
-
- by_idx[ p_plugin->get_name() ]=plugins.size();
- plugins.push_back(p_plugin);
-}
-
-void EditorImportExport::remove_import_plugin(const Ref<EditorImportPlugin>& p_plugin) {
-
- String plugin_name = p_plugin->get_name();
-
- // Keep the indices the same
- // Find the index of the target plugin
- ERR_FAIL_COND(!by_idx.has(plugin_name));
- int idx = by_idx[plugin_name];
- int last_idx = plugins.size() - 1;
-
- // Swap the last plugin and the target one
- SWAP(plugins[idx], plugins[last_idx]);
-
- // Update the index of the old last one
- by_idx[plugins[idx]->get_name()] = idx;
-
- // Remove the target plugin's by_idx entry
- by_idx.erase(plugin_name);
-
- // Erase the plugin
- plugins.remove(last_idx);
-}
-
-int EditorImportExport::get_import_plugin_count() const{
-
- return plugins.size();
-}
-Ref<EditorImportPlugin> EditorImportExport::get_import_plugin(int p_idx) const{
-
- ERR_FAIL_INDEX_V(p_idx,plugins.size(),Ref<EditorImportPlugin>());
- return plugins[p_idx];
-
-}
-
-
-
-Ref<EditorImportPlugin> EditorImportExport::get_import_plugin_by_name(const String& p_string) const{
-
- ERR_FAIL_COND_V( !by_idx.has(p_string), Ref<EditorImportPlugin>());
- return plugins[ by_idx[p_string] ];
-}
-
-void EditorImportExport::add_export_plugin(const Ref<EditorExportPlugin>& p_plugin) {
-
- ERR_FAIL_COND( p_plugin.is_null() );
-
- export_plugins.push_back(p_plugin);
-}
-
-void EditorImportExport::remove_export_plugin(const Ref<EditorExportPlugin>& p_plugin) {
-
- ERR_FAIL_COND( p_plugin.is_null() );
- export_plugins.erase(p_plugin);
-}
-
-int EditorImportExport::get_export_plugin_count() const{
-
- return export_plugins.size();
-}
-Ref<EditorExportPlugin> EditorImportExport::get_export_plugin(int p_idx) const{
-
- ERR_FAIL_INDEX_V(p_idx,export_plugins.size(),Ref<EditorExportPlugin>());
- return export_plugins[p_idx];
-}
-
-void EditorImportExport::set_export_file_action(const StringName& p_file, FileAction p_action) {
-
- if (p_action==ACTION_NONE) {
-
- files.erase(p_file);
- } else {
-
- files[p_file]=p_action;
- }
-
-}
-
-EditorImportExport::FileAction EditorImportExport::get_export_file_action(const StringName& p_file) const{
-
-
- if (files.has(p_file))
- return files[p_file];
-
-
- return ACTION_NONE;
-}
-
-void EditorImportExport::get_export_file_list(List<StringName> *p_files){
-
-
- for (Map<StringName,FileAction>::Element *E=files.front();E;E=E->next()) {
-
- p_files->push_back(E->key());
- }
-
-}
-
-void EditorImportExport::add_export_platform(const Ref<EditorExportPlatform>& p_export) {
-
- exporters[p_export->get_name()]=p_export;
-}
-
-
-void EditorImportExport::get_export_platforms(List<StringName> *r_platforms) {
-
- for (Map<StringName,Ref<EditorExportPlatform> >::Element *E=exporters.front();E;E=E->next()) {
-
- r_platforms->push_back(E->key());
- }
-}
-
-Ref<EditorExportPlatform> EditorImportExport::get_export_platform(const StringName& p_platform) {
-
- if (exporters.has(p_platform)) {
- return exporters[p_platform];
- } else {
- return Ref<EditorExportPlatform>();
- }
-}
-
-
-bool EditorImportExport::poll_export_platforms() {
-
- bool changed=false;
- for (Map<StringName,Ref<EditorExportPlatform> >::Element *E=exporters.front();E;E=E->next()) {
-
- if (E->get()->poll_devices())
- changed=true;
- }
-
- return changed;
-
-}
-
-void EditorImportExport::set_export_filter(ExportFilter p_enable) {
-
- export_filter=p_enable;
-}
-
-EditorImportExport::ExportFilter EditorImportExport::get_export_filter() const{
-
- return export_filter;
-}
-
-void EditorImportExport::set_export_custom_filter(const String& p_custom_filter){
- export_custom_filter=p_custom_filter;
-}
-void EditorImportExport::set_export_custom_filter_exclude(const String& p_custom_filter){
- export_custom_filter_exclude=p_custom_filter;
-}
-String EditorImportExport::get_export_custom_filter() const{
- return export_custom_filter;
-}
-String EditorImportExport::get_export_custom_filter_exclude() const{
- return export_custom_filter_exclude;
-}
-
-void EditorImportExport::set_export_image_action(ImageAction p_action) {
-
- image_action=p_action;
-}
-
-EditorImportExport::ImageAction EditorImportExport::get_export_image_action() const{
-
- return image_action;
-}
-
-void EditorImportExport::set_export_image_shrink(float p_shrink) {
-
- image_shrink=p_shrink;
-}
-
-float EditorImportExport::get_export_image_shrink() const{
-
- return image_shrink;
-}
-
-
-void EditorImportExport::set_export_image_quality(float p_quality){
-
- image_action_compress_quality=p_quality;
-}
-
-float EditorImportExport::get_export_image_quality() const{
-
- return image_action_compress_quality;
-}
-
-void EditorImportExport::image_export_group_create(const StringName& p_name) {
-
- ERR_FAIL_COND(image_groups.has(p_name));
- ImageGroup ig;
- ig.action=IMAGE_ACTION_NONE; //default
- ig.make_atlas=false;
- ig.shrink=1;
- ig.lossy_quality=0.7;
- image_groups[p_name]=ig;
-
-
-}
-
-
-bool EditorImportExport::image_export_has_group(const StringName& p_name) const {
-
- return image_groups.has(p_name);
-}
-void EditorImportExport::image_export_get_groups(List<StringName> *r_name) const {
-
- for (Map<StringName,ImageGroup>::Element *E=image_groups.front();E;E=E->next()) {
-
- r_name->push_back(E->key());
- }
-}
-
-void EditorImportExport::image_export_group_remove(const StringName& p_name){
-
- ERR_FAIL_COND(!image_groups.has(p_name));
- image_groups.erase(p_name);
-}
-void EditorImportExport::image_export_group_set_image_action(const StringName& p_export_group,ImageAction p_action){
-
- ERR_FAIL_COND(!image_groups.has(p_export_group));
- image_groups[p_export_group].action=p_action;
-
-}
-EditorImportExport::ImageAction EditorImportExport::image_export_group_get_image_action(const StringName& p_export_group) const{
-
- ERR_FAIL_COND_V(!image_groups.has(p_export_group),IMAGE_ACTION_NONE);
- return image_groups[p_export_group].action;
-
-}
-void EditorImportExport::image_export_group_set_make_atlas(const StringName& p_export_group,bool p_make){
-
- ERR_FAIL_COND(!image_groups.has(p_export_group));
- image_groups[p_export_group].make_atlas=p_make;
-
-}
-bool EditorImportExport::image_export_group_get_make_atlas(const StringName& p_export_group) const{
-
- ERR_FAIL_COND_V(!image_groups.has(p_export_group),false);
- return image_groups[p_export_group].make_atlas;
-
-}
-void EditorImportExport::image_export_group_set_shrink(const StringName& p_export_group,float p_amount){
- ERR_FAIL_COND(!image_groups.has(p_export_group));
- image_groups[p_export_group].shrink=p_amount;
-
-}
-float EditorImportExport::image_export_group_get_shrink(const StringName& p_export_group) const{
-
- ERR_FAIL_COND_V(!image_groups.has(p_export_group),1);
- return image_groups[p_export_group].shrink;
-
-}
-
-void EditorImportExport::image_export_group_set_lossy_quality(const StringName& p_export_group,float p_amount){
- ERR_FAIL_COND(!image_groups.has(p_export_group));
- image_groups[p_export_group].lossy_quality=p_amount;
-
-}
-float EditorImportExport::image_export_group_get_lossy_quality(const StringName& p_export_group) const{
-
- ERR_FAIL_COND_V(!image_groups.has(p_export_group),1);
- return image_groups[p_export_group].lossy_quality;
-
-}
-
-StringName EditorImportExport::image_get_export_group(const StringName& p_image) const {
-
- if (image_group_files.has(p_image))
- return image_group_files[p_image];
- else
- return StringName();
-
-}
-
-void EditorImportExport::image_add_to_export_group(const StringName& p_image,const StringName& p_export_group) {
-
-
- bool emptygroup = String(p_export_group)==String();
- ERR_FAIL_COND(!emptygroup && !image_groups.has(p_export_group));
-
- if (emptygroup)
- image_group_files.erase(p_image);
- else
- image_group_files[p_image]=p_export_group;
-}
-
-void EditorImportExport::image_export_get_images_in_group(const StringName& p_group,List<StringName> *r_images) const {
-
- for (Map<StringName,StringName>::Element *E=image_group_files.front();E;E=E->next()) {
-
- if (p_group==E->get())
- r_images->push_back(E->key());
- }
-}
-
-void EditorImportExport::set_convert_text_scenes(bool p_convert) {
-
- convert_text_scenes=p_convert;
-}
-
-bool EditorImportExport::get_convert_text_scenes() const{
-
- return convert_text_scenes;
-}
-
-
-void EditorImportExport::load_config() {
-
- Ref<ConfigFile> cf = memnew( ConfigFile );
-
- Error err = cf->load("res://export.cfg");
- if (err!=OK)
- return; //no export config to be loaded!
-
-
- export_custom_filter=cf->get_value("export_filter","filter");
- export_custom_filter_exclude=cf->get_value("export_filter","filter_exclude");
- String t=cf->get_value("export_filter","type");
- if (t=="selected")
- export_filter=EXPORT_SELECTED;
- else if (t=="resources")
- export_filter=EXPORT_RESOURCES;
- else if (t=="all")
- export_filter=EXPORT_ALL;
-
- if (cf->has_section("convert_images")) {
-
- String ci = "convert_images";
- String action = cf->get_value(ci,"action");
- if (action=="none")
- image_action=IMAGE_ACTION_NONE;
- else if (action=="compress_ram")
- image_action=IMAGE_ACTION_COMPRESS_RAM;
- else if (action=="compress_disk")
- image_action=IMAGE_ACTION_COMPRESS_DISK;
-
- image_action_compress_quality = cf->get_value(ci,"compress_quality");
- if (cf->has_section_key(ci,"shrink"))
- image_shrink = cf->get_value(ci,"shrink");
- else
- image_shrink=1;
- String formats=cf->get_value(ci,"formats");
- Vector<String> f = formats.split(",");
- image_formats.clear();
- for(int i=0;i<f.size();i++) {
- image_formats.insert(f[i].strip_edges());
- }
- }
-
- if (cf->has_section("convert_scenes")) {
-
- convert_text_scenes = cf->get_value("convert_scenes","convert_text_scenes");
- }
-
-
- if (cf->has_section("export_filter_files")) {
-
-
- String eff = "export_filter_files";
- List<String> k;
- cf->get_section_keys(eff,&k);
- for(List<String>::Element *E=k.front();E;E=E->next()) {
-
- String val = cf->get_value(eff,E->get());
- if (val=="copy") {
- files[E->get()]=ACTION_COPY;
- } else if (val=="bundle") {
- files[E->get()]=ACTION_BUNDLE;
- }
- }
- }
-
- List<String> sect;
-
- cf->get_sections(&sect);
-
- for(List<String>::Element *E=sect.front();E;E=E->next()) {
-
- String s = E->get();
- if (!s.begins_with("platform:"))
- continue;
- String p = s.substr(s.find(":")+1,s.length());
-
- if (!exporters.has(p))
- continue;
-
- Ref<EditorExportPlatform> ep = exporters[p];
- if (!ep.is_valid()) {
- continue;
- }
- List<String> keys;
- cf->get_section_keys(s,&keys);
- for(List<String>::Element *F=keys.front();F;F=F->next()) {
- ep->set(F->get(),cf->get_value(s,F->get()));
- }
- }
-
- //save image groups
-
- if (cf->has_section("image_groups")) {
-
- sect.clear();
- cf->get_section_keys("image_groups",&sect);
- for(List<String>::Element *E=sect.front();E;E=E->next()) {
-
- Dictionary d = cf->get_value("image_groups",E->get());
- ImageGroup g;
- g.action=IMAGE_ACTION_NONE;
- g.make_atlas=false;
- g.lossy_quality=0.7;
- g.shrink=1;
-
- if (d.has("action")) {
- String action=d["action"];
- if (action=="compress_ram")
- g.action=IMAGE_ACTION_COMPRESS_RAM;
- else if (action=="compress_disk")
- g.action=IMAGE_ACTION_COMPRESS_DISK;
- else if (action=="keep")
- g.action=IMAGE_ACTION_KEEP;
- }
-
- if (d.has("atlas"))
- g.make_atlas=d["atlas"];
- if (d.has("lossy_quality"))
- g.lossy_quality=d["lossy_quality"];
- if (d.has("shrink")) {
-
- g.shrink=d["shrink"];
- g.shrink=CLAMP(g.shrink,1,8);
- }
-
- image_groups[E->get()]=g;
-
- }
-
- if (cf->has_section_key("image_group_files","files")) {
-
- Vector<String> sa=cf->get_value("image_group_files","files");
- if (sa.size()%2==0) {
- for(int i=0;i<sa.size();i+=2) {
- image_group_files[sa[i]]=sa[i+1];
- }
- }
- }
-
- }
-
-
- if (cf->has_section("script")) {
-
- if (cf->has_section_key("script","action")) {
-
- String action = cf->get_value("script","action");
- if (action=="compile")
- script_action=SCRIPT_ACTION_COMPILE;
- else if (action=="encrypt")
- script_action=SCRIPT_ACTION_ENCRYPT;
- else
- script_action=SCRIPT_ACTION_NONE;
-
- }
-
- if (cf->has_section_key("script","encrypt_key")) {
-
- script_key = cf->get_value("script","encrypt_key");
- }
- }
-
- if (cf->has_section("convert_samples")) {
-
- if (cf->has_section_key("convert_samples","action")) {
- String action = cf->get_value("convert_samples","action");
- if (action=="none") {
- sample_action=SAMPLE_ACTION_NONE;
- } else if (action=="compress_ram") {
- sample_action=SAMPLE_ACTION_COMPRESS_RAM;
- }
- }
-
- if (cf->has_section_key("convert_samples","max_hz"))
- sample_action_max_hz=cf->get_value("convert_samples","max_hz");
-
- if (cf->has_section_key("convert_samples","trim"))
- sample_action_trim=cf->get_value("convert_samples","trim");
- }
-
-
-
-}
-
-
-
-
-
-void EditorImportExport::save_config() {
-
- Ref<ConfigFile> cf = memnew( ConfigFile );
-
- switch(export_filter) {
- case EXPORT_SELECTED: cf->set_value("export_filter","type","selected"); break;
- case EXPORT_RESOURCES: cf->set_value("export_filter","type","resources"); break;
- case EXPORT_ALL: cf->set_value("export_filter","type","all"); break;
- }
-
- cf->set_value("export_filter","filter",export_custom_filter);
- cf->set_value("export_filter", "filter_exclude",export_custom_filter_exclude);
-
- String file_action_section = "export_filter_files";
-
- for (Map<StringName,FileAction>::Element *E=files.front();E;E=E->next()) {
-
- String f=E->key();
- String a;
- switch (E->get()) {
- case ACTION_NONE: {}
- case ACTION_COPY: a="copy"; break;
- case ACTION_BUNDLE: a="bundle"; break;
- }
-
- cf->set_value(file_action_section,f,a);
- }
-
-
- for (Map<StringName,Ref<EditorExportPlatform> >::Element *E=exporters.front();E;E=E->next()) {
-
- String pname = "platform:"+String(E->key());
-
- Ref<EditorExportPlatform> ep = E->get();
-
- List<PropertyInfo> pl;
- ep->get_property_list(&pl);
-
- for (List<PropertyInfo>::Element *F=pl.front();F;F=F->next()) {
-
- cf->set_value(pname,F->get().name,ep->get(F->get().name));
- }
-
- }
-
- switch(image_action) {
- case IMAGE_ACTION_NONE: cf->set_value("convert_images","action","none"); break;
- case IMAGE_ACTION_COMPRESS_RAM: cf->set_value("convert_images","action","compress_ram"); break;
- case IMAGE_ACTION_COMPRESS_DISK: cf->set_value("convert_images","action","compress_disk"); break;
- }
-
- cf->set_value("convert_images","shrink",image_shrink);
- cf->set_value("convert_images","compress_quality",image_action_compress_quality);
-
- String formats;
- for(Set<String>::Element *E=image_formats.front();E;E=E->next()) {
-
- if (E!=image_formats.front())
- formats+=",";
- formats+=E->get();
- }
-
- cf->set_value("convert_images","formats",formats);
-
- //save image groups
-
- for(Map<StringName,ImageGroup>::Element *E=image_groups.front();E;E=E->next()) {
-
- Dictionary d;
- switch(E->get().action) {
- case IMAGE_ACTION_NONE: d["action"]="default"; break;
- case IMAGE_ACTION_COMPRESS_RAM: d["action"]="compress_ram"; break;
- case IMAGE_ACTION_COMPRESS_DISK: d["action"]="compress_disk"; break;
- case IMAGE_ACTION_KEEP: d["action"]="keep"; break;
- }
-
-
- d["atlas"]=E->get().make_atlas;
- d["shrink"]=E->get().shrink;
- d["lossy_quality"]=E->get().lossy_quality;
- cf->set_value("image_groups",E->key(),d);
-
- }
-
- if (image_groups.size() && image_group_files.size()){
-
- Vector<String> igfkeys;
- igfkeys.resize(image_group_files.size());
- int idx=0;
- for (Map<StringName,StringName>::Element *E=image_group_files.front();E;E=E->next()) {
- igfkeys[idx++]=E->key();
- }
- igfkeys.sort();
-
- Vector<String> igfsave;
- igfsave.resize(image_group_files.size()*2);
- idx=0;
- for (int i=0;i<igfkeys.size();++i) {
-
- igfsave[idx++]=igfkeys[i];
- igfsave[idx++]=image_group_files[igfkeys[i]];
- }
- cf->set_value("image_group_files","files",igfsave);
- }
-
- switch(script_action) {
- case SCRIPT_ACTION_NONE: cf->set_value("script","action","none"); break;
- case SCRIPT_ACTION_COMPILE: cf->set_value("script","action","compile"); break;
- case SCRIPT_ACTION_ENCRYPT: cf->set_value("script","action","encrypt"); break;
- }
-
- cf->set_value("convert_scenes","convert_text_scenes",convert_text_scenes);
-
- cf->set_value("script","encrypt_key",script_key);
-
- switch(sample_action) {
- case SAMPLE_ACTION_NONE: cf->set_value("convert_samples","action","none"); break;
- case SAMPLE_ACTION_COMPRESS_RAM: cf->set_value("convert_samples","action","compress_ram"); break;
- }
-
- cf->set_value("convert_samples","max_hz",sample_action_max_hz);
- cf->set_value("convert_samples","trim",sample_action_trim);
-
- cf->save("res://export.cfg");
-
-}
-
-
-void EditorImportExport::script_set_action(ScriptAction p_action) {
-
- script_action=p_action;
-}
-
-EditorImportExport::ScriptAction EditorImportExport::script_get_action() const{
-
- return script_action;
-}
-
-void EditorImportExport::script_set_encryption_key(const String& p_key){
-
- script_key=p_key;
-}
-String EditorImportExport::script_get_encryption_key() const{
-
- return script_key;
-}
-
-
-void EditorImportExport::sample_set_action(SampleAction p_action) {
-
- sample_action=p_action;
-}
-
-EditorImportExport::SampleAction EditorImportExport::sample_get_action() const{
-
- return sample_action;
-}
-
-void EditorImportExport::sample_set_max_hz(int p_hz){
-
- sample_action_max_hz=p_hz;
-}
-int EditorImportExport::sample_get_max_hz() const{
-
- return sample_action_max_hz;
-}
-
-void EditorImportExport::sample_set_trim(bool p_trim){
-
- sample_action_trim=p_trim;
-}
-bool EditorImportExport::sample_get_trim() const{
-
- return sample_action_trim;
-}
-
-PoolVector<String> EditorImportExport::_get_export_file_list() {
-
- PoolVector<String> fl;
- for (Map<StringName,FileAction>::Element *E=files.front();E;E=E->next()) {
-
- fl.push_back(E->key());
- }
-
- return fl;
-}
-
-PoolVector<String> EditorImportExport::_get_export_platforms() {
-
- PoolVector<String> ep;
- for (Map<StringName,Ref<EditorExportPlatform> >::Element *E=exporters.front();E;E=E->next()) {
-
- ep.push_back(E->key());
- }
-
- return ep;
-
-}
-
-void EditorImportExport::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("add_import_plugin","plugin"),&EditorImportExport::add_import_plugin);
- ClassDB::bind_method(D_METHOD("remove_import_plugin","plugin"),&EditorImportExport::remove_import_plugin);
- ClassDB::bind_method(D_METHOD("get_import_plugin_count"),&EditorImportExport::get_import_plugin_count);
- ClassDB::bind_method(D_METHOD("get_import_plugin","idx"),&EditorImportExport::get_import_plugin);
- ClassDB::bind_method(D_METHOD("get_import_plugin_by_name","name"),&EditorImportExport::get_import_plugin_by_name);
-
- ClassDB::bind_method(D_METHOD("add_export_plugin","plugin"),&EditorImportExport::add_export_plugin);
- ClassDB::bind_method(D_METHOD("remove_export_plugin","plugin"),&EditorImportExport::remove_export_plugin);
- ClassDB::bind_method(D_METHOD("get_export_plugin_count"),&EditorImportExport::get_export_plugin_count);
- ClassDB::bind_method(D_METHOD("get_export_plugin","idx"),&EditorImportExport::get_export_plugin);
-
- ClassDB::bind_method(D_METHOD("set_export_file_action","file","action"),&EditorImportExport::set_export_file_action);
- ClassDB::bind_method(D_METHOD("get_export_file_action","file"),&EditorImportExport::get_export_file_action);
- ClassDB::bind_method(D_METHOD("get_export_file_list"),&EditorImportExport::_get_export_file_list);
-
- ClassDB::bind_method(D_METHOD("add_export_platform","platform"),&EditorImportExport::add_export_platform);
- //ClassDB::bind_method(D_METHOD("remove_export_platform","platform"),&EditorImportExport::add_export_platform);
- ClassDB::bind_method(D_METHOD("get_export_platform","name"),&EditorImportExport::get_export_platform);
- ClassDB::bind_method(D_METHOD("get_export_platforms"),&EditorImportExport::_get_export_platforms);
-
- ClassDB::bind_method(D_METHOD("set_export_filter","filter"),&EditorImportExport::set_export_filter);
- ClassDB::bind_method(D_METHOD("get_export_filter"),&EditorImportExport::get_export_filter);
-
- ClassDB::bind_method(D_METHOD("set_export_custom_filter","filter"),&EditorImportExport::set_export_custom_filter);
- ClassDB::bind_method(D_METHOD("get_export_custom_filter"),&EditorImportExport::get_export_custom_filter);
-
- ClassDB::bind_method(D_METHOD("set_export_custom_filter_exclude","filter_exclude"),&EditorImportExport::set_export_custom_filter_exclude);
- ClassDB::bind_method(D_METHOD("get_export_custom_filter_exclude"),&EditorImportExport::get_export_custom_filter_exclude);
-
-
- ClassDB::bind_method(D_METHOD("image_export_group_create"),&EditorImportExport::image_export_group_create);
- ClassDB::bind_method(D_METHOD("image_export_group_remove"),&EditorImportExport::image_export_group_remove);
- ClassDB::bind_method(D_METHOD("image_export_group_set_image_action"),&EditorImportExport::image_export_group_set_image_action);
- ClassDB::bind_method(D_METHOD("image_export_group_set_make_atlas"),&EditorImportExport::image_export_group_set_make_atlas);
- ClassDB::bind_method(D_METHOD("image_export_group_set_shrink"),&EditorImportExport::image_export_group_set_shrink);
- ClassDB::bind_method(D_METHOD("image_export_group_get_image_action"),&EditorImportExport::image_export_group_get_image_action);
- ClassDB::bind_method(D_METHOD("image_export_group_get_make_atlas"),&EditorImportExport::image_export_group_get_make_atlas);
- ClassDB::bind_method(D_METHOD("image_export_group_get_shrink"),&EditorImportExport::image_export_group_get_shrink);
- ClassDB::bind_method(D_METHOD("image_add_to_export_group"),&EditorImportExport::image_add_to_export_group);
- ClassDB::bind_method(D_METHOD("script_set_action"),&EditorImportExport::script_set_action);
- ClassDB::bind_method(D_METHOD("script_set_encryption_key"),&EditorImportExport::script_set_encryption_key);
- ClassDB::bind_method(D_METHOD("script_get_action"),&EditorImportExport::script_get_action);
- ClassDB::bind_method(D_METHOD("script_get_encryption_key"),&EditorImportExport::script_get_encryption_key);
-
-
-
- BIND_ENUM_CONSTANT( ACTION_NONE );
- BIND_ENUM_CONSTANT( ACTION_COPY );
- BIND_ENUM_CONSTANT( ACTION_BUNDLE );
-
- BIND_ENUM_CONSTANT( EXPORT_SELECTED );
- BIND_ENUM_CONSTANT( EXPORT_RESOURCES );
- BIND_ENUM_CONSTANT( EXPORT_ALL );
-
- BIND_ENUM_CONSTANT( IMAGE_ACTION_NONE );
- BIND_ENUM_CONSTANT( IMAGE_ACTION_COMPRESS_DISK );
- BIND_ENUM_CONSTANT( IMAGE_ACTION_COMPRESS_RAM );
- BIND_ENUM_CONSTANT( IMAGE_ACTION_KEEP );
-
- BIND_ENUM_CONSTANT( SCRIPT_ACTION_NONE );
- BIND_ENUM_CONSTANT( SCRIPT_ACTION_COMPILE );
- BIND_ENUM_CONSTANT( SCRIPT_ACTION_ENCRYPT );
-};
-
-
-
-EditorImportExport::EditorImportExport() {
-
- export_filter=EXPORT_RESOURCES;
- singleton=this;
- image_action=IMAGE_ACTION_NONE;
- image_action_compress_quality=0.7;
- image_formats.insert("png");
- image_shrink=1;
-
-
- script_action=SCRIPT_ACTION_COMPILE;
-
- sample_action=SAMPLE_ACTION_NONE;
- sample_action_max_hz=44100;
- sample_action_trim=false;
-
- convert_text_scenes=true;
-
-}
-
-
-
-EditorImportExport::~EditorImportExport() {
-
-
-
-}
-#endif
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index 12c9bb9e21..c7c3a88684 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -530,49 +530,6 @@ void EditorHelp::_search(const String &) {
prev_search = stext;
}
-#if 0
-void EditorHelp::_button_pressed(int p_idx) {
-
- if (p_idx==PAGE_CLASS_LIST) {
-
- //edited_class->set_pressed(false);
- //class_list_button->set_pressed(true);
- //tabs->set_current_tab(PAGE_CLASS_LIST);
-
- } else if (p_idx==PAGE_CLASS_DESC) {
-
- //edited_class->set_pressed(true);
- //class_list_button->set_pressed(false);
- //tabs->set_current_tab(PAGE_CLASS_DESC);
-
- } else if (p_idx==PAGE_CLASS_PREV) {
-
- if (history_pos<2)
- return;
- history_pos--;
- ERR_FAIL_INDEX(history_pos-1,history.size());
- _goto_desc(history[history_pos-1].c,false,history[history_pos-1].scroll);
- _update_history_buttons();
-
-
- } else if (p_idx==PAGE_CLASS_NEXT) {
-
- if (history_pos>=history.size())
- return;
-
- history_pos++;
- ERR_FAIL_INDEX(history_pos-1,history.size());
- _goto_desc(history[history_pos-1].c,false,history[history_pos-1].scroll);
- _update_history_buttons();
-
- } else if (p_idx==PAGE_SEARCH) {
-
- _search("");
- }
-}
-
-#endif
-
void EditorHelp::_class_list_select(const String &p_select) {
_goto_desc(p_select);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index cfd628359f..f724cba3ef 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -65,18 +65,9 @@
#include "editor/import/resource_importer_scene.h"
#include "editor/import/resource_importer_texture.h"
#include "editor/import/resource_importer_wav.h"
-#include "editor/io_plugins/editor_bitmask_import_plugin.h"
-#include "editor/io_plugins/editor_export_scene.h"
-#include "editor/io_plugins/editor_font_import_plugin.h"
-#include "editor/io_plugins/editor_mesh_import_plugin.h"
-#include "editor/io_plugins/editor_scene_import_plugin.h"
-#include "editor/io_plugins/editor_scene_importer_fbxconv.h"
-#include "editor/io_plugins/editor_texture_import_plugin.h"
-#include "editor/io_plugins/editor_translation_import_plugin.h"
#include "editor/plugins/animation_player_editor_plugin.h"
#include "editor/plugins/animation_tree_editor_plugin.h"
#include "editor/plugins/asset_library_editor_plugin.h"
-#include "editor/plugins/baked_light_editor_plugin.h"
#include "editor/plugins/camera_editor_plugin.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#include "editor/plugins/collision_polygon_2d_editor_plugin.h"
@@ -107,7 +98,6 @@
#include "editor/plugins/shader_graph_editor_plugin.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor/plugins/sprite_frames_editor_plugin.h"
-#include "editor/plugins/stream_editor_plugin.h"
#include "editor/plugins/style_box_editor_plugin.h"
#include "editor/plugins/texture_editor_plugin.h"
#include "editor/plugins/texture_region_editor_plugin.h"
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 1919a93570..985f5cd894 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -30,7 +30,6 @@
#ifndef EDITOR_NODE_H
#define EDITOR_NODE_H
-#include "editor/call_dialog.h"
#include "editor/connections_dialog.h"
#include "editor/create_dialog.h"
#include "editor/editor_about.h"
@@ -40,7 +39,6 @@
#include "editor/editor_name_dialog.h"
#include "editor/editor_path.h"
#include "editor/editor_plugin.h"
-#include "editor/editor_reimport_dialog.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_run.h"
#include "editor/editor_run_native.h"
diff --git a/editor/editor_reimport_dialog.cpp b/editor/editor_reimport_dialog.cpp
deleted file mode 100644
index ca5853e8a4..0000000000
--- a/editor/editor_reimport_dialog.cpp
+++ /dev/null
@@ -1,149 +0,0 @@
-/*************************************************************************/
-/* editor_reimport_dialog.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 "editor_reimport_dialog.h"
-
-#include "editor_file_system.h"
-#include "editor_node.h"
-
-#if 0
-void EditorReImportDialog::popup_reimport() {
-
- if (EditorFileSystem::get_singleton()->is_scanning()) {
- error->set_text(TTR("Please wait for scan to complete."));
- error->popup_centered_minsize();
- return;
- }
-
- tree->clear();
- items.clear();
- List<String> ril;
- EditorFileSystem::get_singleton()->get_changed_sources(&ril);
-
- scene_must_save=false;
-
-
- TreeItem *root = tree->create_item();
- for(List<String>::Element *E=ril.front();E;E=E->next()) {
-
- TreeItem *item = tree->create_item(root);
- item->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
- item->set_metadata(0,E->get());
- item->set_text(0,E->get().replace_first("res://",""));
- item->set_tooltip(0,E->get());
- item->set_checked(0,true);
- item->set_editable(0,true);
- items.push_back(item);
-
- String name = E->get();
-
- if (EditorFileSystem::get_singleton()->get_file_type(name)=="PackedScene" && EditorNode::get_singleton()->is_scene_in_use(name)) {
-
- scene_must_save=true;
- }
- }
-
-
- if (scene_must_save) {
- if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->get_filename()=="") {
-
- error->set_text(TTR("Current scene must be saved to re-import."));
- error->popup_centered_minsize();
- get_ok()->set_text(TTR("Re-Import"));
- get_ok()->set_disabled(true);
- return;
-
- }
- get_ok()->set_disabled(false);
- get_ok()->set_text(TTR("Save & Re-Import"));
- } else {
- get_ok()->set_text(TTR("Re-Import"));
- get_ok()->set_disabled(false);
- }
-
- popup_centered(Size2(600,400));
-
-
-}
-
-
-void EditorReImportDialog::ok_pressed() {
-
- if (EditorFileSystem::get_singleton()->is_scanning()) {
- error->set_text(TTR("Please wait for scan to complete."));
- error->popup_centered_minsize();
- return;
- }
-
-
-
- EditorProgress ep("reimport",TTR("Re-Importing"),items.size());
- String reload_fname;
- if (scene_must_save && EditorNode::get_singleton()->get_edited_scene()) {
- reload_fname = EditorNode::get_singleton()->get_edited_scene()->get_filename();
- EditorNode::get_singleton()->save_scene(reload_fname);
- EditorNode::get_singleton()->clear_scene();
- }
-
- for(int i=0;i<items.size();i++) {
-
- String it = items[i]->get_metadata(0);
- ep.step(items[i]->get_text(0),i);
- print_line("reload import from: "+it);
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(it);
- ERR_CONTINUE(rimd.is_null());
- String editor = rimd->get_editor();
- Ref<EditorImportPlugin> eip = EditorImportExport::get_singleton()->get_import_plugin_by_name(editor);
- ERR_CONTINUE(eip.is_null());
- Error err = eip->import(it,rimd);
- if (err!=OK) {
- EditorNode::add_io_error("Error Importing:\n "+it);
- }
-
- }
- if (reload_fname!="") {
- EditorNode::get_singleton()->load_scene(reload_fname);
- }
-
- EditorFileSystem::get_singleton()->scan_sources();
-}
-
-EditorReImportDialog::EditorReImportDialog() {
-
- tree = memnew( Tree );
- add_child(tree);
- tree->set_hide_root(true);
- //set_child_rect(tree);
- set_title(TTR("Re-Import Changed Resources"));
- error = memnew( AcceptDialog);
- add_child(error);
- scene_must_save=false;
-
-}
-#endif
diff --git a/editor/editor_reimport_dialog.h b/editor/editor_reimport_dialog.h
deleted file mode 100644
index 9329fa0587..0000000000
--- a/editor/editor_reimport_dialog.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*************************************************************************/
-/* editor_reimport_dialog.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 EDITOR_REIMPORT_DIALOG_H
-#define EDITOR_REIMPORT_DIALOG_H
-
-#if 0
-#include "scene/gui/dialogs.h"
-#include "scene/gui/tree.h"
-
-class EditorReImportDialog : public ConfirmationDialog {
-
- GDCLASS(EditorReImportDialog,ConfirmationDialog);
-
- Tree *tree;
- Vector<TreeItem*> items;
- AcceptDialog *error;
- bool scene_must_save;
-
- void ok_pressed();
-public:
-
- void popup_reimport();
- EditorReImportDialog();
-};
-
-#endif // EDITOR_REIMPORT_DIALOG_H
-#endif
diff --git a/editor/editor_settings.h b/editor/editor_settings.h
index 45a6207eb1..177ec4760d 100644
--- a/editor/editor_settings.h
+++ b/editor/editor_settings.h
@@ -35,7 +35,7 @@
#include "core/io/config_file.h"
#include "os/thread_safe.h"
#include "resource.h"
-#include "scene/gui/input_action.h"
+#include "scene/gui/shortcut.h"
#include "translation.h"
class EditorPlugin;
diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp
index 8883fe517e..147d5f90c6 100644
--- a/editor/export_template_manager.cpp
+++ b/editor/export_template_manager.cpp
@@ -313,77 +313,6 @@ void ExportTemplateManager::_bind_methods() {
ClassDB::bind_method("_uninstall_template", &ExportTemplateManager::_uninstall_template);
ClassDB::bind_method("_uninstall_template_confirm", &ExportTemplateManager::_uninstall_template_confirm);
ClassDB::bind_method("_install_from_file", &ExportTemplateManager::_install_from_file);
-
-#if 0
- FileAccess *fa = NULL;
- zlib_filefunc_def io = zipio_create_io_from_file(&fa);
-
- unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io);
- if (!pkg) {
-
- current_option = -1;
- //confirmation->get_cancel()->hide();
- accept->get_ok()->set_text(TTR("I see.."));
- accept->set_text(TTR("Can't open export templates zip."));
- accept->popup_centered_minsize();
- return;
- }
- int ret = unzGoToFirstFile(pkg);
-
- int fc = 0; //count them
-
- while (ret == UNZ_OK) {
- fc++;
- ret = unzGoToNextFile(pkg);
- }
-
- ret = unzGoToFirstFile(pkg);
-
- EditorProgress p("ltask", TTR("Loading Export Templates"), fc);
-
- fc = 0;
-
- while (ret == UNZ_OK) {
-
- //get filename
- unz_file_info info;
- char fname[16384];
- ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0);
-
- String file = fname;
-
- Vector<uint8_t> data;
- data.resize(info.uncompressed_size);
-
- //read
- ret = unzOpenCurrentFile(pkg);
- ret = unzReadCurrentFile(pkg, data.ptr(), data.size());
- unzCloseCurrentFile(pkg);
-
- print_line(fname);
- /*
- for(int i=0;i<512;i++) {
- print_line(itos(data[i]));
- }
- */
-
- file = file.get_file();
-
- p.step(TTR("Importing:") + " " + file, fc);
-
- FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_settings_path() + "/templates/" + file, FileAccess::WRITE);
-
- ERR_CONTINUE(!f);
- f->store_buffer(data.ptr(), data.size());
-
- memdelete(f);
-
- ret = unzGoToNextFile(pkg);
- fc++;
- }
-
- unzClose(pkg);
-#endif
}
ExportTemplateManager::ExportTemplateManager() {
diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp
index db53ba2455..86482dad5a 100644
--- a/editor/import/editor_import_collada.cpp
+++ b/editor/import/editor_import_collada.cpp
@@ -41,6 +41,7 @@
#include "scene/animation/animation_player.h"
#include "scene/resources/animation.h"
#include "scene/resources/packed_scene.h"
+
#include <iostream>
struct ColladaImport {
@@ -1238,173 +1239,10 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
Array mr;
-////////////////////////////
-// THEN THE MORPH TARGETS //
-////////////////////////////
-#if 0
- if (p_morph_data) {
-
- //add morphie target
- ERR_FAIL_COND_V( !p_morph_data->targets.has("MORPH_TARGET"), ERR_INVALID_DATA );
- String mt = p_morph_data->targets["MORPH_TARGET"];
- ERR_FAIL_COND_V( !p_morph_data->sources.has(mt), ERR_INVALID_DATA);
- int morph_targets = p_morph_data->sources[mt].sarray.size();
- mr.resize(morph_targets);
-
- for(int j=0;j<morph_targets;j++) {
-
- Array mrt;
- mrt.resize(VS::ARRAY_MAX);
-
- String target = p_morph_data->sources[mt].sarray[j];
- ERR_FAIL_COND_V( !collada.state.mesh_data_map.has(target), ERR_INVALID_DATA );
- String name = collada.state.mesh_data_map[target].name;
- Collada::MeshData &md = collada.state.mesh_data_map[target];
-
- // collada in itself supports morphing everything. However, the spec is unclear and no examples or exporters that
- // morph anything but "POSITIONS" seem to exit. Because of this, normals and binormals/tangents have to be regenerated here,
- // which may result in inaccurate (but most of the time good enough) results.
-
- PoolVector<Vector3> vertices;
- vertices.resize(vlen);
-
- ERR_FAIL_COND_V( md.vertices.size() != 1, ERR_INVALID_DATA);
- String vertex_src_id=md.vertices.front()->key();
- ERR_FAIL_COND_V(!md.vertices[vertex_src_id].sources.has("POSITION"),ERR_INVALID_DATA);
- String position_src_id = md.vertices[vertex_src_id].sources["POSITION"];
-
- ERR_FAIL_COND_V(!md.sources.has(position_src_id),ERR_INVALID_DATA);
-
- const Collada::MeshData::Source *m=&md.sources[position_src_id];
-
- ERR_FAIL_COND_V( m->array.size() != vertex_src->array.size(), ERR_INVALID_DATA);
- int stride=m->stride;
- if (stride==0)
- stride=3;
-
-
- //read vertices from morph target
- PoolVector<Vector3>::Write vertw = vertices.write();
-
- for(int m_i=0;m_i<m->array.size()/stride;m_i++) {
-
- int pos = m_i*stride;
- Vector3 vtx( m->array[pos+0], m->array[pos+1], m->array[pos+2] );
-
-#ifndef NO_UP_AXIS_SWAP
- if (collada.state.up_axis==Vector3::AXIS_Z) {
-
- SWAP( vtx.z, vtx.y );
- vtx.z = -vtx.z;
-
- }
-#endif
-
- Collada::Vertex vertex;
- vertex.vertex=vtx;
- vertex.fix_unit_scale(collada);
- vtx=vertex.vertex;
-
- vtx = p_local_xform.xform(vtx);
-
-
- if (vertex_map.has(m_i)) { //vertex may no longer be here, don't bother converting
-
-
- for (Set<int> ::Element *E=vertex_map[m_i].front() ; E; E=E->next() ) {
-
- vertw[E->get()]=vtx;
- }
- }
- }
-
-
- //vertices are in place, now generate everything else
- vertw = PoolVector<Vector3>::Write();
- PoolVector<Vector3> normals;
- PoolVector<float> tangents;
- print_line("vertex source id: "+vertex_src_id);
- if(md.vertices[vertex_src_id].sources.has("NORMAL")){
- //has normals
- normals.resize(vlen);
- //std::cout << "has normals" << std::endl;
- String normal_src_id = md.vertices[vertex_src_id].sources["NORMAL"];
- //std::cout << "normals source: "<< normal_src_id.utf8().get_data() <<std::endl;
- ERR_FAIL_COND_V(!md.sources.has(normal_src_id),ERR_INVALID_DATA);
-
- const Collada::MeshData::Source *m=&md.sources[normal_src_id];
-
- ERR_FAIL_COND_V( m->array.size() != vertex_src->array.size(), ERR_INVALID_DATA);
- int stride=m->stride;
- if (stride==0)
- stride=3;
-
-
- //read normals from morph target
- PoolVector<Vector3>::Write vertw = normals.write();
-
- for(int m_i=0;m_i<m->array.size()/stride;m_i++) {
-
- int pos = m_i*stride;
- Vector3 vtx( m->array[pos+0], m->array[pos+1], m->array[pos+2] );
-
-#ifndef NO_UP_AXIS_SWAP
- if (collada.state.up_axis==Vector3::AXIS_Z) {
-
- SWAP( vtx.z, vtx.y );
- vtx.z = -vtx.z;
-
- }
-#endif
-
- Collada::Vertex vertex;
- vertex.vertex=vtx;
- vertex.fix_unit_scale(collada);
- vtx=vertex.vertex;
-
- vtx = p_local_xform.xform(vtx);
-
-
- if (vertex_map.has(m_i)) { //vertex may no longer be here, don't bother converting
-
-
- for (Set<int> ::Element *E=vertex_map[m_i].front() ; E; E=E->next() ) {
-
- vertw[E->get()]=vtx;
- }
- }
- }
-
- print_line("using built-in normals");
- }else{
- print_line("generating normals");
- _generate_normals(index_array,vertices,normals);//no normals
- }
- if (final_tangent_array.size() && final_uv_array.size()) {
-
- _generate_tangents_and_binormals(index_array,vertices,final_uv_array,normals,tangents);
-
- }
-
- mrt[Mesh::ARRAY_VERTEX]=vertices;
-
- mrt[Mesh::ARRAY_NORMAL]=normals;
- if (tangents.size())
- mrt[Mesh::ARRAY_TANGENT]=tangents;
- if (final_uv_array.size())
- mrt[Mesh::ARRAY_TEX_UV]=final_uv_array;
- if (final_uv2_array.size())
- mrt[Mesh::ARRAY_TEX_UV2]=final_uv2_array;
- if (final_color_array.size())
- mrt[Mesh::ARRAY_COLOR]=final_color_array;
-
- mr[j]=mrt;
-
- }
-
- }
+ ////////////////////////////
+ // THEN THE MORPH TARGETS //
+ ////////////////////////////
-#endif
for (int mi = 0; mi < p_morph_meshes.size(); mi++) {
//print_line("want surface "+itos(mi)+" has "+itos(p_morph_meshes[mi]->get_surface_count()));
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index fb987a5981..dd98494504 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -171,38 +171,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
memdelete(p_node);
return NULL;
}
-#if 0
- if (Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- bool bb = false;
-
- if ((_teststr(name, "bb"))) {
- bb = true;
- } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(), "bb"))) {
- bb = true;
- }
-
- if (bb) {
- mi->set_flag(GeometryInstance::FLAG_BILLBOARD, true);
- if (mi->get_mesh().is_valid()) {
- Ref<ArrayMesh> m = mi->get_mesh();
- for (int i = 0; i < m->get_surface_count(); i++) {
-
- Ref<SpatialMaterial> fm = m->surface_get_material(i);
- if (fm.is_valid()) {
- //fm->set_flag(Material::FLAG_UNSHADED,true);
- //fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- //fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
- //fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- }
- }
- }
- }
- }
-#endif
if (Object::cast_to<MeshInstance>(p_node)) {
MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
@@ -256,115 +225,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
}
}
}
-#if 0
- if (Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- String str;
-
- if ((_teststr(name, "imp"))) {
- str = name;
- } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(), "imp"))) {
- str = mi->get_mesh()->get_name();
- }
-
- if (Object::cast_to<MeshInstance>(p_node->get_parent())) {
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- MeshInstance *mip = Object::cast_to<MeshInstance>(p_node->get_parent());
- String d = str.substr(str.find("imp") + 3, str.length());
- if (d != "") {
- if ((d[0] < '0' || d[0] > '9'))
- d = d.substr(1, d.length());
- if (d.length() && d[0] >= '0' && d[0] <= '9') {
- float dist = d.to_double();
- mi->set_flag(GeometryInstance::FLAG_BILLBOARD, true);
- mi->set_flag(GeometryInstance::FLAG_BILLBOARD_FIX_Y, true);
- //mi->set_draw_range_begin(dist);
- //mi->set_draw_range_end(100000);
-
- //mip->set_draw_range_begin(0);
- //mip->set_draw_range_end(dist);
-
- if (mi->get_mesh().is_valid()) {
-
- Ref<ArrayMesh> m = mi->get_mesh();
- for (int i = 0; i < m->get_surface_count(); i++) {
-
- Ref<SpatialMaterial> fm = m->surface_get_material(i);
- if (fm.is_valid()) {
- //fm->set_flag(Material::FLAG_UNSHADED,true);
- //fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- //fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
- //fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- }
- }
- }
- }
- }
- }
- }
-#endif
-#if 0
- if (p_flags&SCENE_FLAG_CREATE_LODS && Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- String str;
-
- if ((_teststr(name,"lod"))) {
- str=name;
- } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"lod"))) {
- str=mi->get_mesh()->get_name();
-
- }
-
-
- if (Object::cast_to<MeshInstance>(p_node->get_parent())) {
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- MeshInstance *mip = Object::cast_to<MeshInstance>(p_node->get_parent());
- String d=str.substr(str.find("lod")+3,str.length());
- if (d!="") {
- if ((d[0]<'0' || d[0]>'9'))
- d=d.substr(1,d.length());
- if (d.length() && d[0]>='0' && d[0]<='9') {
- float dist = d.to_double();
- /// mi->set_draw_range_begin(dist);
- // mi->set_draw_range_end(100000);
-
- // mip->set_draw_range_begin(0);
- // mip->set_draw_range_end(dist);
-
- /*if (mi->get_mesh().is_valid()) {
-
- Ref<ArrayMesh> m = mi->get_mesh();
- for(int i=0;i<m->get_surface_count();i++) {
-
- Ref<SpatialMaterial> fm = m->surface_get_material(i);
- if (fm.is_valid()) {
- fm->set_flag(Material::FLAG_UNSHADED,true);
- fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- fm->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
- fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- }
- }
- }*/
- }
- }
- }
- }
-
-
- if (p_flags&SCENE_FLAG_DETECT_LIGHTMAP_LAYER && _teststr(name,"lm") && Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- String str=name;
- int layer = str.substr(str.find("lm")+3,str.length()).to_int();
- //mi->set_baked_light_texture_id(layer);
- }
-#endif
if (_teststr(name, "colonly")) {
if (isroot)
@@ -681,38 +542,6 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array
if (!shape.is_null())
collision_map[mesh] = shape;
}
-
- if (!shape.is_null()) {
-#if 0
- StaticBody* static_body = memnew( StaticBody );
- ERR_FAIL_COND_V(!static_body,NULL);
- static_body->set_name( String(mesh->get_name()) + "_col" );
- shape->set_name(static_body->get_name());
- static_body->add_shape(shape);
-
- mi->add_child(static_body);
- if (mi->get_owner())
- static_body->set_owner( mi->get_owner() );
-#endif
- }
- }
-
- for (int i = 0; i < mesh->get_surface_count(); i++) {
-
- Ref<SpatialMaterial> fm = mesh->surface_get_material(i);
- if (fm.is_valid()) {
- String name = fm->get_name();
- /* if (_teststr(name,"alpha")) {
- fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- name=_fixstr(name,"alpha");
- }
-
- if (_teststr(name,"vcol")) {
- fm->set_fixed_flag(SpatialMaterial::FLAG_USE_COLOR_ARRAY,true);
- name=_fixstr(name,"vcol");
- }*/
- fm->set_name(name);
- }
}
}
}
diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp
deleted file mode 100644
index 1f71ee685f..0000000000
--- a/editor/inspector_dock.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/*************************************************************************/
-/* inspector_dock.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 "inspector_dock.h"
-
-#if 0
-void InspectorDock::_go_next() {
-
-
-}
-
-void InspectorDock::_go_prev() {
-
-
-}
-
-void InspectorDock::_bind_methods() {
-
-}
-
-InspectorDock::InspectorDock() {
-
-
-}
-#endif
diff --git a/editor/inspector_dock.h b/editor/inspector_dock.h
deleted file mode 100644
index 2d14b68e92..0000000000
--- a/editor/inspector_dock.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*************************************************************************/
-/* inspector_dock.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 INSPECTOR_DOCK_H
-#define INSPECTOR_DOCK_H
-
-#include "property_editor.h"
-#include "scene/gui/box_container.h"
-
-//this is for now bundled in EditorNode, will be moved away here eventually
-
-#if 0
-class InspectorDock : public VBoxContainer
-{
- GDCLASS(InspectorDock,VBoxContainer);
-
- PropertyEditor *property_editor;
-
- EditorHistory editor_history;
-
- void _go_next();
- void _go_prev();
-
-protected:
-
- static void _bind_methods();
-public:
-
- EditorHistory &get_editor_history();
-
- PropertyEditor *get_property_editor();
-
- InspectorDock();
-};
-
-#endif
-#endif // INSPECTOR_DOCK_H
diff --git a/editor/io_plugins/SCsub b/editor/io_plugins/SCsub
deleted file mode 100644
index f1fa50148f..0000000000
--- a/editor/io_plugins/SCsub
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/usr/bin/env python
-
-Import('env')
-Export('env')
-env.add_source_files(env.editor_sources, "*.cpp")
diff --git a/editor/io_plugins/editor_atlas.cpp b/editor/io_plugins/editor_atlas.cpp
deleted file mode 100644
index 71cdfbfd93..0000000000
--- a/editor/io_plugins/editor_atlas.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*************************************************************************/
-/* editor_atlas.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 "editor_atlas.h"
-
-#include "print_string.h"
-
-struct _EditorAtlasWorkRect {
-
- Size2i s;
- Point2i p;
- int idx;
- _FORCE_INLINE_ bool operator<(const _EditorAtlasWorkRect &p_r) const { return s.width > p_r.s.width; };
-};
-
-struct _EditorAtlasWorkRectResult {
-
- Vector<_EditorAtlasWorkRect> result;
- int max_w;
- int max_h;
-};
-
-void EditorAtlas::fit(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size) {
-
- //super simple, almost brute force scanline stacking fitter
- //it's pretty basic for now, but it tries to make sure that the aspect ratio of the
- //resulting atlas is somehow square. This is necessary because video cards have limits
- //on texture size (usually 2048 or 4096), so the more square a texture, the more chances
- //it will work in every hardware.
- // for example, it will prioritize a 1024x1024 atlas (works everywhere) instead of a
- // 256x8192 atlas (won't work anywhere).
-
- ERR_FAIL_COND(p_rects.size() == 0);
-
- Vector<_EditorAtlasWorkRect> wrects;
- wrects.resize(p_rects.size());
- for (int i = 0; i < p_rects.size(); i++) {
- wrects[i].s = p_rects[i];
- wrects[i].idx = i;
- }
- wrects.sort();
- int widest = wrects[0].s.width;
-
- Vector<_EditorAtlasWorkRectResult> results;
-
- for (int i = 0; i <= 12; i++) {
-
- int w = 1 << i;
- int max_h = 0;
- int max_w = 0;
- if (w < widest)
- continue;
-
- Vector<int> hmax;
- hmax.resize(w);
- for (int j = 0; j < w; j++)
- hmax[j] = 0;
-
- //place them
- int ofs = 0;
-
- for (int j = 0; j < wrects.size(); j++) {
-
- if (ofs + wrects[j].s.width > w) {
-
- ofs = 0;
- }
-
- int from_y = 0;
- for (int k = 0; k < wrects[j].s.width; k++) {
-
- if (hmax[ofs + k] > from_y)
- from_y = hmax[ofs + k];
- }
-
- wrects[j].p.x = ofs;
- wrects[j].p.y = from_y;
-
- int end_h = from_y + wrects[j].s.height;
- int end_w = ofs + wrects[j].s.width;
-
- for (int k = 0; k < wrects[j].s.width; k++) {
-
- hmax[ofs + k] = end_h;
- }
-
- if (end_h > max_h)
- max_h = end_h;
-
- if (end_w > max_w)
- max_w = end_w;
-
- ofs += wrects[j].s.width;
- }
-
- _EditorAtlasWorkRectResult result;
- result.result = wrects;
- result.max_h = max_h;
- result.max_w = max_w;
- results.push_back(result);
- }
-
- //find the result with the best aspect ratio
-
- int best = -1;
- float best_aspect = 1e20;
-
- for (int i = 0; i < results.size(); i++) {
-
- float h = results[i].max_h;
- float w = results[i].max_w;
- float aspect = h > w ? h / w : w / h;
- if (aspect < best_aspect) {
- best = i;
- best_aspect = aspect;
- }
- }
-
- r_result.resize(p_rects.size());
-
- for (int i = 0; i < p_rects.size(); i++) {
-
- r_result[results[best].result[i].idx] = results[best].result[i].p;
- }
-
- r_size = Size2(results[best].max_w, results[best].max_h);
-}
diff --git a/editor/io_plugins/editor_atlas.h b/editor/io_plugins/editor_atlas.h
deleted file mode 100644
index c42222bd99..0000000000
--- a/editor/io_plugins/editor_atlas.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*************************************************************************/
-/* editor_atlas.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 EDITOR_ATLAS_H
-#define EDITOR_ATLAS_H
-
-#include "math_2d.h"
-#include "vector.h"
-
-class EditorAtlas {
-public:
- static void fit(const Vector<Size2i> &p_rects, Vector<Point2i> &r_result, Size2i &r_size);
-};
-
-#endif // EDITOR_ATLAS_H
diff --git a/editor/io_plugins/editor_bitmask_import_plugin.cpp b/editor/io_plugins/editor_bitmask_import_plugin.cpp
deleted file mode 100644
index 01b7f3145e..0000000000
--- a/editor/io_plugins/editor_bitmask_import_plugin.cpp
+++ /dev/null
@@ -1,388 +0,0 @@
-/*************************************************************************/
-/* editor_bitmask_import_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 "editor_bitmask_import_plugin.h"
-#if 0
-#include "editor/editor_dir_dialog.h"
-#include "editor/editor_file_dialog.h"
-#include "editor/editor_node.h"
-#include "editor/editor_settings.h"
-#include "editor/property_editor.h"
-#include "io/image_loader.h"
-#include "io/marshalls.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-
-class _EditorBitMaskImportOptions : public Object {
-
- GDCLASS(_EditorBitMaskImportOptions, Object);
-public:
-
- bool _set(const StringName& p_name, const Variant& p_value) {
-
- return false;
- }
-
- bool _get(const StringName& p_name, Variant &r_ret) const{
-
- return false;
- }
-
- void _get_property_list(List<PropertyInfo> *p_list) const{
-
- }
-
- static void _bind_methods() {
-
- ADD_SIGNAL(MethodInfo("changed"));
- }
-
-
- _EditorBitMaskImportOptions() {
-
- }
-
-};
-
-class EditorBitMaskImportDialog : public ConfirmationDialog {
-
- GDCLASS(EditorBitMaskImportDialog, ConfirmationDialog);
-
- EditorBitMaskImportPlugin *plugin;
-
- LineEdit *import_path;
- LineEdit *save_path;
- EditorFileDialog *file_select;
- EditorDirDialog *save_select;
- ConfirmationDialog *error_dialog;
- PropertyEditor *option_editor;
-
-public:
-
- void _choose_files(const Vector<String>& p_path) {
-
- String files;
- for (int i = 0; i<p_path.size(); i++) {
-
- if (i>0)
- files += ",";
- files += p_path[i];
- }
-
- import_path->set_text(files);
-
- }
- void _choose_save_dir(const String& p_path) {
-
- save_path->set_text(p_path);
- }
-
- void _browse() {
-
- file_select->popup_centered_ratio();
- }
-
- void _browse_target() {
-
- save_select->popup_centered_ratio();
-
- }
-
-
- void popup_import(const String& p_path) {
-
- popup_centered(Size2(400, 100)*EDSCALE);
- if (p_path != "") {
-
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
- ERR_FAIL_COND(!rimd.is_valid());
-
- save_path->set_text(p_path.get_base_dir());
-
- String src = "";
- for (int i = 0; i<rimd->get_source_count(); i++) {
- if (i>0)
- src += ",";
- src += EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
- }
- import_path->set_text(src);
- }
- }
-
-
- void _import() {
-
- Vector<String> bitmasks = import_path->get_text().split(",");
-
- if (bitmasks.size() == 0) {
- error_dialog->set_text(TTR("No bit masks to import!"));
- error_dialog->popup_centered(Size2(200, 100)*EDSCALE);
- }
-
- if (save_path->get_text().strip_edges() == "") {
- error_dialog->set_text(TTR("Target path is empty."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (!save_path->get_text().begins_with("res://")) {
- error_dialog->set_text(TTR("Target path must be a complete resource path."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (!DirAccess::exists(save_path->get_text())) {
- error_dialog->set_text(TTR("Target path must exist."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- for (int i = 0; i<bitmasks.size(); i++) {
-
- Ref<ResourceImportMetadata> imd = memnew(ResourceImportMetadata);
-
- imd->add_source(EditorImportPlugin::validate_source_path(bitmasks[i]));
-
- String dst = save_path->get_text();
- if (dst == "") {
- error_dialog->set_text(TTR("Save path is empty!"));
- error_dialog->popup_centered(Size2(200, 100)*EDSCALE);
- }
-
- dst = dst.plus_file(bitmasks[i].get_file().get_basename() + ".pbm");
-
- plugin->import(dst, imd);
- }
-
- hide();
-
- }
-
-
- void _notification(int p_what) {
-
- }
-
- static void _bind_methods() {
-
-
- ClassDB::bind_method("_choose_files", &EditorBitMaskImportDialog::_choose_files);
- ClassDB::bind_method("_choose_save_dir", &EditorBitMaskImportDialog::_choose_save_dir);
- ClassDB::bind_method("_import", &EditorBitMaskImportDialog::_import);
- ClassDB::bind_method("_browse", &EditorBitMaskImportDialog::_browse);
- ClassDB::bind_method("_browse_target", &EditorBitMaskImportDialog::_browse_target);
- //ADD_SIGNAL( MethodInfo("imported",PropertyInfo(Variant::OBJECT,"scene")) );
- }
-
- EditorBitMaskImportDialog(EditorBitMaskImportPlugin *p_plugin) {
-
- plugin = p_plugin;
-
-
- set_title(TTR("Import BitMasks"));
-
- VBoxContainer *vbc = memnew(VBoxContainer);
- add_child(vbc);
- //set_child_rect(vbc);
-
-
- HBoxContainer *hbc = memnew(HBoxContainer);
- vbc->add_margin_child(TTR("Source Texture(s):"), hbc);
-
- import_path = memnew(LineEdit);
- import_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(import_path);
-
- Button * import_choose = memnew(Button);
- import_choose->set_text(" .. ");
- hbc->add_child(import_choose);
-
- import_choose->connect("pressed", this, "_browse");
-
- hbc = memnew(HBoxContainer);
- vbc->add_margin_child(TTR("Target Path:"), hbc);
-
- save_path = memnew(LineEdit);
- save_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(save_path);
-
- Button * save_choose = memnew(Button);
- save_choose->set_text(" .. ");
- hbc->add_child(save_choose);
-
- save_choose->connect("pressed", this, "_browse_target");
-
- file_select = memnew(EditorFileDialog);
- file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
- add_child(file_select);
- file_select->set_mode(EditorFileDialog::MODE_OPEN_FILES);
- file_select->connect("files_selected", this, "_choose_files");
-
- List<String> extensions;
- ImageLoader::get_recognized_extensions(&extensions);
- file_select->clear_filters();
- for (int i = 0; i<extensions.size(); i++) {
-
- file_select->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
- }
-
- save_select = memnew(EditorDirDialog);
- add_child(save_select);
-
- //save_select->set_mode(EditorFileDialog::MODE_OPEN_DIR);
- save_select->connect("dir_selected", this, "_choose_save_dir");
-
- get_ok()->connect("pressed", this, "_import");
- get_ok()->set_text(TTR("Import"));
-
-
- error_dialog = memnew(ConfirmationDialog);
- add_child(error_dialog);
- error_dialog->get_ok()->set_text(TTR("Accept"));
- //error_dialog->get_cancel()->hide();
-
- set_hide_on_ok(false);
- }
-
- ~EditorBitMaskImportDialog() {
- }
-
-};
-
-
-String EditorBitMaskImportPlugin::get_name() const {
-
- return "bitmask";
-}
-String EditorBitMaskImportPlugin::get_visible_name() const{
-
- return TTR("Bit Mask");
-}
-void EditorBitMaskImportPlugin::import_dialog(const String& p_from){
-
- dialog->popup_import(p_from);
-}
-Error EditorBitMaskImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){
-
- ERR_FAIL_COND_V(p_from->get_source_count() != 1, ERR_INVALID_PARAMETER);
-
- Ref<ResourceImportMetadata> from = p_from;
-
- String src_path = EditorImportPlugin::expand_source_path(from->get_source_path(0));
- Ref<ImageTexture> it = ResourceLoader::load(src_path);
- ERR_FAIL_COND_V(it.is_null(), ERR_CANT_OPEN);
-
- Ref<BitMap> target = memnew(BitMap);
- target->create_from_image_alpha(it.ptr()->get_data());
-
- from->set_source_md5(0, FileAccess::get_md5(src_path));
- from->set_editor(get_name());
- target->set_import_metadata(from);
-
-
- Error err = ResourceSaver::save(p_path, target);
-
- return err;
-
-}
-
-
-EditorBitMaskImportPlugin* EditorBitMaskImportPlugin::singleton = NULL;
-
-
-void EditorBitMaskImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
-
- Vector<String> files;
-
- List<String> valid_extensions;
- ImageLoader::get_recognized_extensions(&valid_extensions);
- for(int i=0;i<p_drop.size();i++) {
-
- String extension=p_drop[i].get_extension().to_lower();
-
- for (List<String>::Element *E=valid_extensions.front();E;E=E->next()) {
-
- if (E->get()==extension) {
- files.push_back(p_drop[i]);
- break;
- }
- }
- }
-
- if (files.size()) {
- import_dialog();
- dialog->_choose_files(files);
- dialog->_choose_save_dir(p_dest_path);
- }
-}
-
-void EditorBitMaskImportPlugin::reimport_multiple_files(const Vector<String>& p_list) {
-
- if (p_list.size() == 0)
- return;
-
- Vector<String> sources;
- for (int i = 0; i<p_list.size(); i++) {
- int idx;
- EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->find_file(p_list[i], &idx);
- if (efsd) {
- for (int j = 0; j<efsd->get_source_count(idx); j++) {
- String file = expand_source_path(efsd->get_source_file(idx, j));
- if (sources.find(file) == -1) {
- sources.push_back(file);
- }
-
- }
- }
- }
-
- if (sources.size()) {
-
- dialog->popup_import(p_list[0]);
- dialog->_choose_files(sources);
- dialog->_choose_save_dir(p_list[0].get_base_dir());
- }
-}
-
-bool EditorBitMaskImportPlugin::can_reimport_multiple_files() const {
-
- return true;
-}
-
-EditorBitMaskImportPlugin::EditorBitMaskImportPlugin(EditorNode* p_editor) {
-
- singleton = this;
- dialog = memnew(EditorBitMaskImportDialog(this));
- p_editor->get_gui_base()->add_child(dialog);
-}
-
-EditorBitMaskExportPlugin::EditorBitMaskExportPlugin() {
-
-}
-#endif
diff --git a/editor/io_plugins/editor_bitmask_import_plugin.h b/editor/io_plugins/editor_bitmask_import_plugin.h
deleted file mode 100644
index 5200be0180..0000000000
--- a/editor/io_plugins/editor_bitmask_import_plugin.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*************************************************************************/
-/* editor_bitmask_import_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 EDITOR_BITMASK_IMPORT_PLUGIN_H
-#define EDITOR_BITMASK_IMPORT_PLUGIN_H
-#if 0
-#include "editor/editor_import_export.h"
-#include "scene/resources/font.h"
-
-class EditorNode;
-class EditorBitMaskImportDialog;
-
-class EditorBitMaskImportPlugin : public EditorImportPlugin {
-
- GDCLASS(EditorBitMaskImportPlugin, EditorImportPlugin);
-
- EditorBitMaskImportDialog *dialog;
-public:
-
- static EditorBitMaskImportPlugin *singleton;
-
- virtual String get_name() const;
- virtual String get_visible_name() const;
- virtual void import_dialog(const String& p_from = "");
- virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
- void import_from_drop(const Vector<String>& p_drop, const String &p_dest_path);
- virtual void reimport_multiple_files(const Vector<String>& p_list);
- virtual bool can_reimport_multiple_files() const;
-
-
- EditorBitMaskImportPlugin(EditorNode* p_editor);
-};
-
-class EditorBitMaskExportPlugin : public EditorExportPlugin {
-
- GDCLASS(EditorBitMaskExportPlugin, EditorExportPlugin);
-
-
-public:
-
- EditorBitMaskExportPlugin();
-};
-
-#endif
-#endif // EDITOR_SAMPLE_IMPORT_PLUGIN_H
diff --git a/editor/io_plugins/editor_export_scene.cpp b/editor/io_plugins/editor_export_scene.cpp
deleted file mode 100644
index b35f311fbd..0000000000
--- a/editor/io_plugins/editor_export_scene.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/*************************************************************************/
-/* editor_export_scene.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 "editor_export_scene.h"
-#if 0
-#include "editor/editor_settings.h"
-#include "io/resource_loader.h"
-#include "io/resource_saver.h"
-#include "os/dir_access.h"
-#include "os/file_access.h"
-#include "project_settings.h"
-#include "scene/resources/packed_scene.h"
-
-Vector<uint8_t> EditorSceneExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) {
-
- if (!EditorImportExport::get_singleton()->get_convert_text_scenes()) {
- return Vector<uint8_t>();
- }
-
-
- String extension = p_path.get_extension();
-
- //step 1 check if scene
-
- if (extension=="xml" || extension=="xres") {
-
- String type = ResourceLoader::get_resource_type(p_path);
-
- if (type!="PackedScene")
- return Vector<uint8_t>();
-
- } else if (extension!="tscn" && extension!="xscn") {
- return Vector<uint8_t>();
- }
-
- //step 2 check if cached
-
- uint64_t sd=0;
- String smd5;
- String gp = ProjectSettings::get_singleton()->globalize_path(p_path);
- String md5=gp.md5_text();
- String tmp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/");
-
- bool valid=false;
- {
- //if existing, make sure it's valid
- FileAccessRef f = FileAccess::open(tmp_path+"scnexp-"+md5+".txt",FileAccess::READ);
- if (f) {
-
- uint64_t d = f->get_line().strip_edges().to_int64();
- sd = FileAccess::get_modified_time(p_path);
-
- if (d==sd) {
- valid=true;
- } else {
- String cmd5 = f->get_line().strip_edges();
- smd5 = FileAccess::get_md5(p_path);
- if (cmd5==smd5) {
- valid=true;
- }
- }
-
-
- }
- }
-
- if (!valid) {
- //cache failed, convert
- DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
-
- String copy = p_path+".convert."+extension;
-
- // a copy will allow loading the internal resources without conflicting with opened scenes
- da->copy(p_path,copy);
-
- //@todo for tscn use something more efficient
-
- Ref<PackedScene> copyres = ResourceLoader::load(copy,"PackedScene");
-
- da->remove(copy);
-
- memdelete(da);
-
- ERR_FAIL_COND_V(!copyres.is_valid(),Vector<uint8_t>());
-
- Error err = ResourceSaver::save(tmp_path+"scnexp-"+md5+".scn",copyres);
-
- copyres=Ref<PackedScene>();
-
- ERR_FAIL_COND_V(err!=OK,Vector<uint8_t>());
-
- FileAccessRef f = FileAccess::open(tmp_path+"scnexp-"+md5+".txt",FileAccess::WRITE);
-
- if (sd==0)
- sd = FileAccess::get_modified_time(p_path);
- if (smd5==String())
- smd5 = FileAccess::get_md5(p_path);
-
- f->store_line(String::num(sd));
- f->store_line(smd5);
- f->store_line(gp); //source path for reference
- }
-
-
- Vector<uint8_t> ret = FileAccess::get_file_as_array(tmp_path+"scnexp-"+md5+".scn");
-
- p_path+=".converted.scn";
-
- return ret;
-
-}
-
-
-EditorSceneExportPlugin::EditorSceneExportPlugin()
-{
-}
-#endif
diff --git a/editor/io_plugins/editor_export_scene.h b/editor/io_plugins/editor_export_scene.h
deleted file mode 100644
index a898af4ec7..0000000000
--- a/editor/io_plugins/editor_export_scene.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*************************************************************************/
-/* editor_export_scene.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 EDITOR_EXPORT_SCENE_H
-#define EDITOR_EXPORT_SCENE_H
-
-#include "editor/editor_export.h"
-
-#if 0
-class EditorSceneExportPlugin : public EditorExportPlugin {
- GDCLASS( EditorSceneExportPlugin, EditorExportPlugin );
-public:
-
- virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
-
- EditorSceneExportPlugin();
-};
-#endif
-#endif // EDITOR_EXPORT_SCENE_H
diff --git a/editor/io_plugins/editor_font_import_plugin.cpp b/editor/io_plugins/editor_font_import_plugin.cpp
deleted file mode 100644
index bf1a1147fd..0000000000
--- a/editor/io_plugins/editor_font_import_plugin.cpp
+++ /dev/null
@@ -1,1705 +0,0 @@
-/*************************************************************************/
-/* editor_font_import_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 "editor_font_import_plugin.h"
-#if 0
-#include "editor/editor_file_dialog.h"
-#include "editor/editor_node.h"
-#include "editor_atlas.h"
-#include "io/image_loader.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-#include "scene/gui/dialogs.h"
-
-#ifdef FREETYPE_ENABLED
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#endif
-
-
-class _EditorFontImportOptions : public Object {
-
- GDCLASS(_EditorFontImportOptions,Object);
-public:
-
- enum FontMode {
-
- FONT_BITMAP,
- FONT_DISTANCE_FIELD
- };
-
- enum ColorType {
- COLOR_WHITE,
- COLOR_CUSTOM,
- COLOR_GRADIENT_RANGE,
- COLOR_GRADIENT_IMAGE
- };
-
-
- int char_extra_spacing;
- int top_extra_spacing;
- int bottom_extra_spacing;
- int space_extra_spacing;
-
- enum CharacterSet {
-
- CHARSET_ASCII,
- CHARSET_LATIN,
- CHARSET_UNICODE,
- CHARSET_CUSTOM,
- CHARSET_CUSTOM_LATIN
- };
-
-
- FontMode font_mode;
-
- CharacterSet character_set;
- String custom_file;
-
- bool shadow;
- Vector2 shadow_offset;
- int shadow_radius;
- Color shadow_color;
- float shadow_transition;
-
- bool shadow2;
- Vector2 shadow2_offset;
- int shadow2_radius;
- Color shadow2_color;
- float shadow2_transition;
-
- ColorType color_type;
- Color color;
- Color gradient_begin;
- Color gradient_end;
- bool color_use_monochrome;
- String gradient_image;
-
- bool enable_filter;
- bool round_advance;
- bool premultiply_alpha;
-
-
-
- bool _set(const StringName& p_name, const Variant& p_value) {
-
- String n = p_name;
- if (n=="mode/mode") {
- font_mode=FontMode(int(p_value));
- _change_notify();
- } else if (n=="extra_space/char")
- char_extra_spacing=p_value;
- else if (n=="extra_space/space")
- space_extra_spacing=p_value;
- else if (n=="extra_space/top")
- top_extra_spacing=p_value;
- else if (n=="extra_space/bottom")
- bottom_extra_spacing=p_value;
-
- else if (n=="character_set/mode") {
- character_set=CharacterSet(int(p_value));
- _change_notify();
- } else if (n=="character_set/custom")
- custom_file=p_value;
-
- else if (n=="shadow/enabled") {
- shadow=p_value;
- _change_notify();
- }else if (n=="shadow/radius")
- shadow_radius=p_value;
- else if (n=="shadow/offset")
- shadow_offset=p_value;
- else if (n=="shadow/color")
- shadow_color=p_value;
- else if (n=="shadow/transition")
- shadow_transition=p_value;
-
- else if (n=="shadow2/enabled") {
- shadow2=p_value;
- _change_notify();
- }else if (n=="shadow2/radius")
- shadow2_radius=p_value;
- else if (n=="shadow2/offset")
- shadow2_offset=p_value;
- else if (n=="shadow2/color")
- shadow2_color=p_value;
- else if (n=="shadow2/transition")
- shadow2_transition=p_value;
-
- else if (n=="color/mode") {
- color_type=ColorType(int(p_value));
- _change_notify();
- }else if (n=="color/color")
- color=p_value;
- else if (n=="color/begin")
- gradient_begin=p_value;
- else if (n=="color/end")
- gradient_end=p_value;
- else if (n=="color/image")
- gradient_image=p_value;
- else if (n=="color/monochrome")
- color_use_monochrome=p_value;
- else if (n=="advanced/round_advance")
- round_advance=p_value;
- else if (n=="advanced/enable_filter")
- enable_filter=p_value;
- else if (n=="advanced/premultiply_alpha")
- premultiply_alpha=p_value;
- else
- return false;
-
- emit_signal("changed");
-
-
- return true;
-
- }
-
- bool _get(const StringName& p_name,Variant &r_ret) const{
-
- String n = p_name;
- if (n=="mode/mode")
- r_ret=font_mode;
- else if (n=="extra_space/char")
- r_ret=char_extra_spacing;
- else if (n=="extra_space/space")
- r_ret=space_extra_spacing;
- else if (n=="extra_space/top")
- r_ret=top_extra_spacing;
- else if (n=="extra_space/bottom")
- r_ret=bottom_extra_spacing;
-
- else if (n=="character_set/mode")
- r_ret=character_set;
- else if (n=="character_set/custom")
- r_ret=custom_file;
-
- else if (n=="shadow/enabled")
- r_ret=shadow;
- else if (n=="shadow/radius")
- r_ret=shadow_radius;
- else if (n=="shadow/offset")
- r_ret=shadow_offset;
- else if (n=="shadow/color")
- r_ret=shadow_color;
- else if (n=="shadow/transition")
- r_ret=shadow_transition;
-
- else if (n=="shadow2/enabled")
- r_ret=shadow2;
- else if (n=="shadow2/radius")
- r_ret=shadow2_radius;
- else if (n=="shadow2/offset")
- r_ret=shadow2_offset;
- else if (n=="shadow2/color")
- r_ret=shadow2_color;
- else if (n=="shadow2/transition")
- r_ret=shadow2_transition;
-
-
- else if (n=="color/mode")
- r_ret=color_type;
- else if (n=="color/color")
- r_ret=color;
- else if (n=="color/begin")
- r_ret=gradient_begin;
- else if (n=="color/end")
- r_ret=gradient_end;
- else if (n=="color/image")
- r_ret=gradient_image;
- else if (n=="color/monochrome")
- r_ret=color_use_monochrome;
- else if (n=="advanced/round_advance")
- r_ret=round_advance;
- else if (n=="advanced/enable_filter")
- r_ret=enable_filter;
- else if (n=="advanced/premultiply_alpha")
- r_ret=premultiply_alpha;
- else
- return false;
-
- return true;
-
- }
-
- void _get_property_list( List<PropertyInfo> *p_list) const{
-
-
- p_list->push_back(PropertyInfo(Variant::INT,"mode/mode",PROPERTY_HINT_ENUM,"Bitmap,Distance Field"));
-
- p_list->push_back(PropertyInfo(Variant::INT,"extra_space/char",PROPERTY_HINT_RANGE,"-64,64,1"));
- p_list->push_back(PropertyInfo(Variant::INT,"extra_space/space",PROPERTY_HINT_RANGE,"-64,64,1"));
- p_list->push_back(PropertyInfo(Variant::INT,"extra_space/top",PROPERTY_HINT_RANGE,"-64,64,1"));
- p_list->push_back(PropertyInfo(Variant::INT,"extra_space/bottom",PROPERTY_HINT_RANGE,"-64,64,1"));
- p_list->push_back(PropertyInfo(Variant::INT,"character_set/mode",PROPERTY_HINT_ENUM,"Ascii,Latin,Unicode,Custom,Custom&Latin"));
-
- if (character_set>=CHARSET_CUSTOM)
- p_list->push_back(PropertyInfo(Variant::STRING,"character_set/custom",PROPERTY_HINT_GLOBAL_FILE));
-
- int usage = PROPERTY_USAGE_DEFAULT;
-
- if (font_mode==FONT_DISTANCE_FIELD) {
- usage = PROPERTY_USAGE_NOEDITOR;
- }
-
- {
-
- p_list->push_back(PropertyInfo(Variant::BOOL,"shadow/enabled",PROPERTY_HINT_NONE,"",usage));
- if (shadow) {
- p_list->push_back(PropertyInfo(Variant::INT,"shadow/radius",PROPERTY_HINT_RANGE,"-64,64,1",usage));
- p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow/offset",PROPERTY_HINT_NONE,"",usage));
- p_list->push_back(PropertyInfo(Variant::COLOR,"shadow/color",PROPERTY_HINT_NONE,"",usage));
- p_list->push_back(PropertyInfo(Variant::REAL,"shadow/transition",PROPERTY_HINT_EXP_EASING,"",usage));
- }
-
- p_list->push_back(PropertyInfo(Variant::BOOL,"shadow2/enabled",PROPERTY_HINT_NONE,"",usage));
- if (shadow2) {
- p_list->push_back(PropertyInfo(Variant::INT,"shadow2/radius",PROPERTY_HINT_RANGE,"-64,64,1",usage));
- p_list->push_back(PropertyInfo(Variant::VECTOR2,"shadow2/offset",PROPERTY_HINT_NONE,"",usage));
- p_list->push_back(PropertyInfo(Variant::COLOR,"shadow2/color",PROPERTY_HINT_NONE,"",usage));
- p_list->push_back(PropertyInfo(Variant::REAL,"shadow2/transition",PROPERTY_HINT_EXP_EASING,"",usage));
- }
-
- p_list->push_back(PropertyInfo(Variant::INT,"color/mode",PROPERTY_HINT_ENUM,"White,Color,Gradient,Gradient Image",usage));
- if (color_type==COLOR_CUSTOM) {
- p_list->push_back(PropertyInfo(Variant::COLOR,"color/color",PROPERTY_HINT_NONE,"",usage));
-
- }
- if (color_type==COLOR_GRADIENT_RANGE) {
- p_list->push_back(PropertyInfo(Variant::COLOR,"color/begin",PROPERTY_HINT_NONE,"",usage));
- p_list->push_back(PropertyInfo(Variant::COLOR,"color/end",PROPERTY_HINT_NONE,"",usage));
- }
- if (color_type==COLOR_GRADIENT_IMAGE) {
- p_list->push_back(PropertyInfo(Variant::STRING,"color/image",PROPERTY_HINT_GLOBAL_FILE,"",usage));
- }
- p_list->push_back(PropertyInfo(Variant::BOOL,"color/monochrome",PROPERTY_HINT_NONE,"",usage));
- }
-
- p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/round_advance"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/enable_filter"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"advanced/premultiply_alpha"));
-
- }
-
-
- static void _bind_methods() {
-
-
- ADD_SIGNAL( MethodInfo("changed"));
- }
-
-
- void reset() {
-
- char_extra_spacing=0;
- top_extra_spacing=0;
- bottom_extra_spacing=0;
- space_extra_spacing=0;
-
- character_set=CHARSET_LATIN;
-
- shadow=false;
- shadow_radius=2;
- shadow_color=Color(0,0,0,0.3);
- shadow_transition=1.0;
-
- shadow2=false;
- shadow2_radius=2;
- shadow2_color=Color(0,0,0,0.3);
- shadow2_transition=1.0;
-
- color_type=COLOR_WHITE;
- color=Color(1,1,1,1);
- gradient_begin=Color(1,1,1,1);
- gradient_end=Color(0.5,0.5,0.5,1);
- color_use_monochrome=false;
-
- font_mode=FONT_BITMAP;
- round_advance=true;
- enable_filter=true;
- premultiply_alpha=false;
-
- }
-
- _EditorFontImportOptions() {
-
- font_mode=FONT_BITMAP;
-
- char_extra_spacing=0;
- top_extra_spacing=0;
- bottom_extra_spacing=0;
- space_extra_spacing=0;
-
- character_set=CHARSET_LATIN;
-
- shadow=false;
- shadow_radius=2;
- shadow_color=Color(0,0,0,0.3);
- shadow_transition=1.0;
-
- shadow2=false;
- shadow2_radius=2;
- shadow2_color=Color(0,0,0,0.3);
- shadow2_transition=1.0;
-
- color_type=COLOR_WHITE;
- color=Color(1,1,1,1);
- gradient_begin=Color(1,1,1,1);
- gradient_end=Color(0.5,0.5,0.5,1);
- color_use_monochrome=false;
-
- round_advance=true;
- enable_filter=true;
- premultiply_alpha=false;
- }
-
-
-};
-
-
-class EditorFontImportDialog : public ConfirmationDialog {
-
- GDCLASS(EditorFontImportDialog, ConfirmationDialog);
-
-
- EditorLineEditFileChooser *source;
- EditorLineEditFileChooser *dest;
- SpinBox *font_size;
- LineEdit *test_string;
- ColorPickerButton *test_color;
- Label *test_label;
- PropertyEditor *prop_edit;
- Timer *timer;
- ConfirmationDialog *error_dialog;
-
-
- Ref<ResourceImportMetadata> get_rimd() {
-
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- List<PropertyInfo> pl;
- options->_get_property_list(&pl);
- for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
-
- Variant v;
- String opt=E->get().name;
- options->_get(opt,v);
- if (opt=="color/image" || opt=="character_set/custom") {
- v = EditorImportPlugin::validate_source_path(v);
- }
- imd->set_option(opt,v);
- }
-
- String src_path = EditorImportPlugin::validate_source_path(source->get_line_edit()->get_text());
- //print_line("pre src path "+source->get_line_edit()->get_text());
- //print_line("src path "+src_path);
- imd->add_source(src_path);
- imd->set_option("font/size",font_size->get_value());
-
- return imd;
-
- }
-
- void _src_changed(String) {
- _prop_changed();
- }
-
- void _update_text2(String) {
- _update_text();
- }
- void _update_text3(Color) {
- _update_text();
- }
-
- void _update_text() {
-
- test_label->set_text("");
- test_label->set_text(test_string->get_text());
- test_label->add_color_override("font_color",test_color->get_pick_color());
- }
-
- void _update() {
-
- Ref<ResourceImportMetadata> imd = get_rimd();
- Ref<BitmapFont> font = plugin->generate_font(imd);
- test_label->add_font_override("font",font);
- _update_text();
- }
-
- void _font_size_changed(double) {
-
- _prop_changed();
- }
-
- void _prop_changed() {
-
- timer->start();
- }
-
- void _import_inc(String p_font) {
-
- Ref<BitmapFont> font = ResourceLoader::load(p_font);
- if (!font.is_valid())
- return;
- Ref<ImageTexture> tex = font->get_texture(0);
- if (tex.is_null())
- return;
- FileAccessRef f=FileAccess::open(p_font.get_basename()+".inc",FileAccess::WRITE);
- Vector<CharType> ck = font->get_char_keys();
-
- f->store_line("static const int _builtin_font_height="+itos(font->get_height())+";");
- f->store_line("static const int _builtin_font_ascent="+itos(font->get_ascent())+";");
- f->store_line("static const int _builtin_font_charcount="+itos(ck.size())+";");
- f->store_line("static const int _builtin_font_charrects["+itos(ck.size())+"][8]={");
- f->store_line("/* charidx , ofs_x, ofs_y, size_x, size_y, valign, halign, advance */");
-
- for(int i=0;i<ck.size();i++) {
- CharType k=ck[i];
- BitmapFont::Character c=font->get_character(k);
- f->store_line("{"+itos(k)+","+rtos(c.rect.pos.x)+","+rtos(c.rect.pos.y)+","+rtos(c.rect.size.x)+","+rtos(c.rect.size.y)+","+rtos(c.v_align)+","+rtos(c.h_align)+","+rtos(c.advance)+"},");
- }
- f->store_line("};");
-
- Vector<BitmapFont::KerningPairKey> kp=font->get_kerning_pair_keys();
- f->store_line("static const int _builtin_font_kerning_pair_count="+itos(kp.size())+";");
- f->store_line("static const int _builtin_font_kerning_pairs["+itos(kp.size())+"][3]={");
- for(int i=0;i<kp.size();i++) {
-
- int d = font->get_kerning_pair(kp[i].A,kp[i].B);
- f->store_line("{"+itos(kp[i].A)+","+itos(kp[i].B)+","+itos(d)+"},");
- }
-
- f->store_line("};");
- Image img = tex->get_data();
-
- f->store_line("static const int _builtin_font_img_width="+itos(img.get_width())+";");
- f->store_line("static const int _builtin_font_img_height="+itos(img.get_height())+";");
-
- String fname = p_font.get_basename()+".sv.png";
- ResourceSaver::save(fname,tex);
- Vector<uint8_t> data=FileAccess::get_file_as_array(fname);
-
-
- f->store_line("static const int _builtin_font_img_data_size="+itos(data.size())+";");
- f->store_line("static const unsigned char _builtin_font_img_data["+itos(data.size())+"]={");
-
-
-
- for(int i=0;i<data.size();i++) {
-
- f->store_line(itos(data[i])+",");
-
- }
- f->store_line("};");
-
- }
-
- void _import() {
-
- if (source->get_line_edit()->get_text()=="") {
- error_dialog->set_text(TTR("No source font file!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- if (dest->get_line_edit()->get_text()=="") {
- error_dialog->set_text(TTR("No target font resource!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- if (dest->get_line_edit()->get_text().get_file()==".font") {
- dest->get_line_edit()->set_text(dest->get_line_edit()->get_text().get_base_dir() + "/" + source->get_line_edit()->get_text().get_file().get_basename() + ".font" );
- }
-
- if (dest->get_line_edit()->get_text().get_extension() == dest->get_line_edit()->get_text()) {
- dest->get_line_edit()->set_text(dest->get_line_edit()->get_text() + ".font");
- }
-
- if (dest->get_line_edit()->get_text().get_extension().to_lower() != "font") {
- error_dialog->set_text(TTR("Invalid file extension.\nPlease use .font."));
- error_dialog->popup_centered(Size2(200,100));
- return;
- }
-
- Ref<ResourceImportMetadata> rimd = get_rimd();
-
- if (rimd.is_null()) {
- error_dialog->set_text(TTR("Can't load/process source font."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- Error err = plugin->import(dest->get_line_edit()->get_text(),rimd);
-
- if (err!=OK) {
- error_dialog->set_text(TTR("Couldn't save font."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- _import_inc(dest->get_line_edit()->get_text());
-
- hide();
- }
-
- EditorFontImportPlugin *plugin;
- _EditorFontImportOptions *options;
-
- static void _bind_methods() {
-
- ClassDB::bind_method("_update",&EditorFontImportDialog::_update);
- ClassDB::bind_method("_update_text",&EditorFontImportDialog::_update_text);
- ClassDB::bind_method("_update_text2",&EditorFontImportDialog::_update_text2);
- ClassDB::bind_method("_update_text3",&EditorFontImportDialog::_update_text3);
- ClassDB::bind_method("_prop_changed",&EditorFontImportDialog::_prop_changed);
- ClassDB::bind_method("_src_changed",&EditorFontImportDialog::_src_changed);
- ClassDB::bind_method("_font_size_changed",&EditorFontImportDialog::_font_size_changed);
- ClassDB::bind_method("_import",&EditorFontImportDialog::_import);
-
- }
-
-public:
-
- void _notification(int p_what) {
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
- prop_edit->edit(options);
- _update_text();
- }
- }
-
- void popup_import(const String& p_path) {
-
- popup_centered(Size2(600,500)*EDSCALE);
-
- if (p_path!="") {
-
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
- ERR_FAIL_COND(!rimd.is_valid());
-
- dest->get_line_edit()->set_text(p_path);
- List<String> opts;
- rimd->get_options(&opts);
- options->reset();
- for(List<String>::Element *E=opts.front();E;E=E->next()) {
-
- options->_set(E->get(),rimd->get_option(E->get()));
- }
-
- String src = "";
- for(int i=0;i<rimd->get_source_count();i++) {
- if (i>0)
- src+=",";
- src+=EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
- }
- source->get_line_edit()->set_text(src);
-
- font_size->set_value(rimd->get_option("font/size"));
- }
- }
-
-
- void set_source_and_dest(const String& p_font,const String& p_dest) {
- source->get_line_edit()->set_text(p_font);
- dest->get_line_edit()->set_text(p_dest);
- _prop_changed();
- }
-
- EditorFontImportDialog(EditorFontImportPlugin *p_plugin) {
- plugin=p_plugin;
- VBoxContainer *vbc = memnew( VBoxContainer );
- add_child(vbc);
- //set_child_rect(vbc);
- HBoxContainer *hbc = memnew( HBoxContainer);
- vbc->add_child(hbc);
- VBoxContainer *vbl = memnew( VBoxContainer );
- hbc->add_child(vbl);
- hbc->set_v_size_flags(SIZE_EXPAND_FILL);
- vbl->set_h_size_flags(SIZE_EXPAND_FILL);
- VBoxContainer *vbr = memnew( VBoxContainer );
- hbc->add_child(vbr);
- vbr->set_h_size_flags(SIZE_EXPAND_FILL);
-
- source = memnew( EditorLineEditFileChooser );
- source->get_file_dialog()->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
- source->get_file_dialog()->set_mode(EditorFileDialog::MODE_OPEN_FILE);
- source->get_file_dialog()->add_filter("*.ttf;TrueType");
- source->get_file_dialog()->add_filter("*.otf;OpenType");
- source->get_file_dialog()->add_filter("*.fnt;BMFont");
- source->get_line_edit()->connect("text_entered",this,"_src_changed");
-
- vbl->add_margin_child(TTR("Source Font:"),source);
- font_size = memnew( SpinBox );
- vbl->add_margin_child(TTR("Source Font Size:"),font_size);
- font_size->set_min(3);
- font_size->set_max(256);
- font_size->set_value(16);
- font_size->connect("value_changed",this,"_font_size_changed");
- dest = memnew( EditorLineEditFileChooser );
- //
- List<String> fl;
- Ref<BitmapFont> font= memnew(BitmapFont);
- dest->get_file_dialog()->add_filter("*.font ; Font" );
- /*
- ResourceSaver::get_recognized_extensions(font,&fl);
- for(List<String>::Element *E=fl.front();E;E=E->next()) {
- dest->get_file_dialog()->add_filter("*."+E->get());
- }
- */
-
- vbl->add_margin_child(TTR("Dest Resource:"),dest);
- HBoxContainer *testhb = memnew( HBoxContainer );
- test_string = memnew( LineEdit );
- test_string->set_text(TTR("The quick brown fox jumps over the lazy dog."));
- test_string->set_h_size_flags(SIZE_EXPAND_FILL);
- test_string->set_stretch_ratio(5);
-
- testhb->add_child(test_string);
- test_color = memnew( ColorPickerButton );
- test_color->set_pick_color(get_color("font_color","Label"));
- test_color->set_h_size_flags(SIZE_EXPAND_FILL);
- test_color->set_stretch_ratio(1);
- test_color->connect("color_changed",this,"_update_text3");
- testhb->add_child(test_color);
-
- vbl->add_spacer();
- vbl->add_margin_child(TTR("Test:")+" ",testhb);
- /*
- HBoxContainer *upd_hb = memnew( HBoxContainer );
- //vbl->add_child(upd_hb);
- upd_hb->add_spacer();
- Button *update = memnew( Button);
- upd_hb->add_child(update);
- update->set_text("Update");
- update->connect("pressed",this,"_update");
-*/
- options = memnew( _EditorFontImportOptions );
- prop_edit = memnew( PropertyEditor() );
- vbr->add_margin_child(TTR("Options:"),prop_edit,true);
- options->connect("changed",this,"_prop_changed");
-
- prop_edit->hide_top_label();
-
- Panel *panel = memnew( Panel );
- vbc->add_child(panel);
- test_label = memnew( Label );
- test_label->set_autowrap(true);
- panel->add_child(test_label);
- test_label->set_area_as_parent_rect();
- panel->set_v_size_flags(SIZE_EXPAND_FILL);
- test_string->connect("text_changed",this,"_update_text2");
- set_title(TTR("Font Import"));
- timer = memnew( Timer );
- add_child(timer);
- timer->connect("timeout",this,"_update");
- timer->set_wait_time(0.4);
- timer->set_one_shot(true);
-
- get_ok()->connect("pressed", this,"_import");
- get_ok()->set_text(TTR("Import"));
-
- error_dialog = memnew ( ConfirmationDialog );
- add_child(error_dialog);
- error_dialog->get_ok()->set_text(TTR("Accept"));
- set_hide_on_ok(false);
-
-
- }
-
- ~EditorFontImportDialog() {
- memdelete(options);
- }
-};
-
-
-///////////////////////////////////////
-
-
-
-struct _EditorFontData {
-
- Vector<uint8_t> bitmap;
- int width,height;
- int ofs_x; //offset to center, from ABOVE
- int ofs_y; //offset to beginning, from LEFT
- int valign; //vertical alignment
- int halign;
- float advance;
- int character;
- int glyph;
-
- int texture;
- Image blit;
- Point2i blit_ofs;
- //bool printable;
-
-};
-
-
-struct _EditorFontDataSort {
-
- bool operator()(const _EditorFontData *p_A,const _EditorFontData *p_B) const {
- return p_A->height > p_B->height;
- };
-};
-
-struct _EditorKerningKey {
-
- CharType A,B;
- bool operator<(const _EditorKerningKey& p_k) const { return (A==p_k.A)?(B<p_k.B):(A<p_k.A); }
-
-};
-
-
-static unsigned char get_SDF_radial(
- unsigned char *fontmap,
- int w, int h,
- int x, int y,
- int max_radius )
-{
- //hideous brute force method
- float d2 = max_radius*max_radius+1.0;
- unsigned char v = fontmap[x+y*w];
- for( int radius = 1; (radius <= max_radius) && (radius*radius < d2); ++radius )
- {
- int line, lo, hi;
- //north
- line = y - radius;
- if( (line >= 0) && (line < h) )
- {
- lo = x - radius;
- hi = x + radius;
- if( lo < 0 ) { lo = 0; }
- if( hi >= w ) { hi = w-1; }
- int idx = line * w + lo;
- for( int i = lo; i <= hi; ++i )
- {
- //check this pixel
- if( fontmap[idx] != v )
- {
- float nx = i - x;
- float ny = line - y;
- float nd2 = nx*nx+ny*ny;
- if( nd2 < d2 )
- {
- d2 = nd2;
- }
- }
- //move on
- ++idx;
- }
- }
- //south
- line = y + radius;
- if( (line >= 0) && (line < h) )
- {
- lo = x - radius;
- hi = x + radius;
- if( lo < 0 ) { lo = 0; }
- if( hi >= w ) { hi = w-1; }
- int idx = line * w + lo;
- for( int i = lo; i <= hi; ++i )
- {
- //check this pixel
- if( fontmap[idx] != v )
- {
- float nx = i - x;
- float ny = line - y;
- float nd2 = nx*nx+ny*ny;
- if( nd2 < d2 )
- {
- d2 = nd2;
- }
- }
- //move on
- ++idx;
- }
- }
- //west
- line = x - radius;
- if( (line >= 0) && (line < w) )
- {
- lo = y - radius + 1;
- hi = y + radius - 1;
- if( lo < 0 ) { lo = 0; }
- if( hi >= h ) { hi = h-1; }
- int idx = lo * w + line;
- for( int i = lo; i <= hi; ++i )
- {
- //check this pixel
- if( fontmap[idx] != v )
- {
- float nx = line - x;
- float ny = i - y;
- float nd2 = nx*nx+ny*ny;
- if( nd2 < d2 )
- {
- d2 = nd2;
- }
- }
- //move on
- idx += w;
- }
- }
- //east
- line = x + radius;
- if( (line >= 0) && (line < w) )
- {
- lo = y - radius + 1;
- hi = y + radius - 1;
- if( lo < 0 ) { lo = 0; }
- if( hi >= h ) { hi = h-1; }
- int idx = lo * w + line;
- for( int i = lo; i <= hi; ++i )
- {
- //check this pixel
- if( fontmap[idx] != v )
- {
- float nx = line - x;
- float ny = i - y;
- float nd2 = nx*nx+ny*ny;
- if( nd2 < d2 )
- {
- d2 = nd2;
- }
- }
- //move on
- idx += w;
- }
- }
- }
- d2 = sqrtf( d2 );
- if( v==0 )
- {
- d2 = -d2;
- }
- d2 *= 127.5 / max_radius;
- d2 += 127.5;
- if( d2 < 0.0 ) d2 = 0.0;
- if( d2 > 255.0 ) d2 = 255.0;
- return (unsigned char)(d2 + 0.5);
-}
-
-
-Ref<BitmapFont> EditorFontImportPlugin::generate_font(const Ref<ResourceImportMetadata>& p_from, const String &p_existing) {
-
-
-
- Ref<ResourceImportMetadata> from = p_from;
- ERR_FAIL_COND_V(from->get_source_count()!=1,Ref<BitmapFont>());
-
- String src_path = EditorImportPlugin::expand_source_path(from->get_source_path(0));
-
- if (src_path.get_extension().to_lower()=="fnt") {
-
- if (ResourceLoader::load(src_path).is_valid()) {
- EditorNode::get_singleton()->show_warning(TTR("Path:")+" "+src_path+"\n"+TTR("This file is already a Godot font file, please supply a BMFont type file instead."));
- return Ref<BitmapFont>();
- }
-
- Ref<BitmapFont> font;
- font.instance();
- Error err = font->create_from_fnt(src_path);
- if (err) {
- EditorNode::get_singleton()->show_warning(TTR("Path:")+" "+src_path+"\n"+TTR("Failed opening as BMFont file."));
- return Ref<BitmapFont>();
- }
-
- return font;
- }
-
- int size = from->get_option("font/size");
-
-#ifdef FREETYPE_ENABLED
- FT_Library library; /* handle to library */
- FT_Face face; /* handle to face object */
-
- Vector<_EditorFontData*> font_data_list;
-
- int error = FT_Init_FreeType( &library );
-
- ERR_EXPLAIN(TTR("Error initializing FreeType."));
- ERR_FAIL_COND_V( error !=0, Ref<BitmapFont>() );
-
- print_line("loadfrom: "+src_path);
- error = FT_New_Face( library, src_path.utf8().get_data(),0,&face );
-
- if ( error == FT_Err_Unknown_File_Format ) {
- ERR_EXPLAIN(TTR("Unknown font format."));
- FT_Done_FreeType( library );
- } else if ( error ) {
-
- ERR_EXPLAIN(TTR("Error loading font."));
- FT_Done_FreeType( library );
-
- }
-
- ERR_FAIL_COND_V(error,Ref<BitmapFont>());
-
-
- int height=0;
- int ascent=0;
- int font_spacing=0;
-
- error = FT_Set_Char_Size(face,0,64*size,512,512);
-
- if ( error ) {
- FT_Done_FreeType( library );
- ERR_EXPLAIN(TTR("Invalid font size."));
- ERR_FAIL_COND_V( error,Ref<BitmapFont>() );
-
- }
-
- int font_mode = from->get_option("mode/mode");
-
- int scaler=(font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD)?16:1;
-
- error = FT_Set_Pixel_Sizes(face,0,size*scaler);
-
- FT_GlyphSlot slot = face->glyph;
-
- //error = FT_Set_Charmap(face,ft_encoding_unicode ); /* encoding.. */
-
-
- /* PRINT CHARACTERS TO INDIVIDUAL BITMAPS */
-
-
- //int space_size=5; //size for space, if none found.. 5!
- //int min_valign=500; //some ridiculous number
-
- FT_ULong charcode;
- FT_UInt gindex;
-
- int max_up=-1324345; ///gibberish
- int max_down=124232;
-
- Map<_EditorKerningKey,int> kerning_map;
-
- charcode = FT_Get_First_Char( face, &gindex );
-
- Set<CharType> import_chars;
-
- int import_mode = from->get_option("character_set/mode");
- bool round_advance = from->get_option("advanced/round_advance");
-
- if (import_mode>=_EditorFontImportOptions::CHARSET_CUSTOM) {
-
- //load from custom text
- String path = from->get_option("character_set/custom");
-
- FileAccess *fa = FileAccess::open(EditorImportPlugin::expand_source_path(path),FileAccess::READ);
-
- if ( !fa ) {
-
- FT_Done_FreeType( library );
- ERR_EXPLAIN(TTR("Invalid font custom source."));
- ERR_FAIL_COND_V( !fa,Ref<BitmapFont>() );
-
- }
-
-
- while(!fa->eof_reached()) {
-
- String line = fa->get_line();
- for(int i=0;i<line.length();i++) {
- import_chars.insert(line[i]);
- }
- }
-
- if (import_mode==_EditorFontImportOptions::CHARSET_CUSTOM_LATIN) {
-
- for(int i=32;i<128;i++)
- import_chars.insert(i);
- }
-
- memdelete(fa);
- }
-
- int xsize=0;
- while ( gindex != 0 )
- {
-
- bool skip=false;
- error = FT_Load_Char( face, charcode, font_mode==_EditorFontImportOptions::FONT_BITMAP?FT_LOAD_RENDER:FT_LOAD_MONOCHROME );
- if (error) skip=true;
- else error = FT_Render_Glyph( face->glyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono );
- if (error) {
- skip=true;
- } else if (!skip) {
-
- switch(import_mode) {
-
- case _EditorFontImportOptions::CHARSET_ASCII: skip = charcode>127; break;
- case _EditorFontImportOptions::CHARSET_LATIN: skip = charcode>255 ;break;
- case _EditorFontImportOptions::CHARSET_UNICODE: break; //none
- case _EditorFontImportOptions::CHARSET_CUSTOM:
- case _EditorFontImportOptions::CHARSET_CUSTOM_LATIN: skip = !import_chars.has(charcode); break;
-
- }
- }
-
- if (charcode<=32) //??
- skip=true;
-
- if (skip) {
- charcode=FT_Get_Next_Char(face,charcode,&gindex);
- continue;
- }
-
- _EditorFontData * fdata = memnew( _EditorFontData );
-
-
- int w = slot->bitmap.width;
- int h = slot->bitmap.rows;
- int p = slot->bitmap.pitch;
-
- //print_line("W: "+itos(w)+" P: "+itos(slot->bitmap.pitch));
-
- if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) {
-
- //oversize the holding buffer so I can smooth it!
- int sw = w + scaler * 4;
- int sh = h + scaler * 4;
- //do the SDF
- int sdfw = sw / scaler;
- int sdfh = sh / scaler;
-
- fdata->width=sdfw;
- fdata->height=sdfh;
- } else {
- fdata->width=w;
- fdata->height=h;
- }
-
- fdata->character=charcode;
- fdata->glyph=FT_Get_Char_Index(face,charcode);
- if (charcode=='x')
- xsize=w/scaler;
-
-
-
- fdata->valign=slot->bitmap_top;
- fdata->halign=slot->bitmap_left;
-
- if (round_advance)
- fdata->advance=(slot->advance.x+(1<<5))>>6;
- else
- fdata->advance=slot->advance.x/float(1<<6);
-
- if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) {
-
- fdata->halign = fdata->halign / scaler - 1.5;
- fdata->valign = fdata->valign / scaler + 1.5;
- fdata->advance/=scaler;
-
- }
-
- fdata->advance+=font_spacing;
-
-
- if (charcode<127) {
- int top = fdata->valign;
- int hmax = h/scaler;
-
- if (top>max_up) {
-
- max_up=top;
- }
-
-
- if ( (top - hmax)<max_down ) {
-
- max_down=top - hmax;
- }
- }
-
- if (font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD) {
-
-
- //oversize the holding buffer so I can smooth it!
- int sw = w + scaler * 4;
- int sh = h + scaler * 4;
-
- unsigned char *smooth_buf = new unsigned char[sw*sh];
-
- for( int i = 0; i < sw*sh; ++i ) {
- smooth_buf[i] = 0;
- }
-
- // copy the glyph into the buffer to be smoothed
- unsigned char *buf = slot->bitmap.buffer;
- for( int j = 0; j < h; ++j ) {
- for( int i = 0; i < w; ++i ) {
- smooth_buf[scaler*2+i+(j+scaler*2)*sw] = 255 * ((buf[j*p+(i>>3)] >> (7 - (i & 7))) & 1);
- }
- }
-
- // do the SDF
- int sdfw = fdata->width;
- int sdfh = fdata->height;
-
- fdata->bitmap.resize( sdfw*sdfh );
-
- for( int j = 0; j < sdfh; ++j ) {
- for( int i = 0; i < sdfw; ++i ) {
- int pd_idx = j*sdfw+i;
-
- //fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i];
-
- fdata->bitmap[pd_idx] =
- //get_SDF
- get_SDF_radial
- ( smooth_buf, sw, sh,
- i*scaler + (scaler >>1), j*scaler + (scaler >>1),
- 2*scaler );
-
- }
- }
-
- delete [] smooth_buf;
-
- } else {
- fdata->bitmap.resize( slot->bitmap.width*slot->bitmap.rows );
- for (int i=0;i<slot->bitmap.width;i++) {
- for (int j=0;j<slot->bitmap.rows;j++) {
-
- fdata->bitmap[j*slot->bitmap.width+i]=slot->bitmap.buffer[j*slot->bitmap.width+i];
- }
- }
- }
-
- font_data_list.push_back(fdata);
- charcode=FT_Get_Next_Char(face,charcode,&gindex);
-// printf("reading char %i\n",charcode);
- }
-
- /* SPACE */
-
- _EditorFontData *spd = memnew( _EditorFontData );
- spd->advance=0;
- spd->character=' ';
- spd->halign=0;
- spd->valign=0;
- spd->width=0;
- spd->height=0;
- spd->ofs_x=0;
- spd->ofs_y=0;
-
- if (!FT_Load_Char( face, ' ', FT_LOAD_RENDER ) && !FT_Render_Glyph( face->glyph, font_mode==_EditorFontImportOptions::FONT_BITMAP?ft_render_mode_normal:ft_render_mode_mono )) {
-
- spd->advance = slot->advance.x>>6; //round to nearest or store as float
- spd->advance/=scaler;
- spd->advance+=font_spacing;
- } else {
-
- spd->advance=xsize;
- spd->advance+=font_spacing;
- }
-
- font_data_list.push_back(spd);
-
- Set<CharType> exported;
- for (int i=0; i<font_data_list.size(); i++) {
- exported.insert(font_data_list[i]->character);
- };
- int missing = 0;
- for(Set<CharType>::Element *E=import_chars.front();E;E=E->next()) {
- CharType c = E->get();
- if (!exported.has(c)) {
- CharType str[2] = {c, 0};
- printf("** Warning: character %i (%ls) not exported\n", (int)c, str);
- ++missing;
- };
- };
- print_line("total_chars: "+itos(font_data_list.size()));
-
- /* KERNING */
-
-
- for(int i=0;i<font_data_list.size();i++) {
-
- if (font_data_list[i]->character>512)
- continue;
- for(int j=0;j<font_data_list.size();j++) {
-
- if (font_data_list[j]->character>512)
- continue;
-
- FT_Vector delta;
- FT_Get_Kerning( face, font_data_list[i]->glyph,font_data_list[j]->glyph, FT_KERNING_DEFAULT, &delta );
-
- if (delta.x!=0) {
-
- _EditorKerningKey kpk;
- kpk.A = font_data_list[i]->character;
- kpk.B = font_data_list[j]->character;
- int kern = ((-delta.x)+(1<<5))>>6;
-
- if (kern==0)
- continue;
- kerning_map[kpk]=kern/scaler;
- }
- }
- }
-
- height=max_up-max_down;
- ascent=max_up;
-
- /* FIND OUT WHAT THE FONT HEIGHT FOR THIS IS */
-
- /* ADJUST THE VALIGN FOR EACH CHARACTER */
-
- for (int i=0;i<(int)font_data_list.size();i++) {
-
- font_data_list[i]->valign=max_up-font_data_list[i]->valign;
- }
-
-
-
- /* ADD THE SPACEBAR CHARACTER */
-/*
- _EditorFontData * fdata = new _EditorFontData;
-
- fdata->character=32;
- fdata->bitmap=0;
- fdata->width=xsize;
- fdata->height=1;
- fdata->valign=0;
-
- font_data_list.push_back(fdata);
-*/
- /* SORT BY HEIGHT, SO THEY FIT BETTER ON THE TEXTURE */
-
- font_data_list.sort_custom<_EditorFontDataSort>();
- Color *color=memnew_arr(Color,height);
-
- int gradient_type=from->get_option("color/mode");
- switch(gradient_type) {
- case _EditorFontImportOptions::COLOR_WHITE: {
-
- for(int i=0;i<height;i++){
- color[i]=Color(1,1,1,1);
- }
-
- } break;
- case _EditorFontImportOptions::COLOR_CUSTOM: {
-
- Color cc = from->get_option("color/color");
- for(int i=0;i<height;i++){
- color[i]=cc;
- }
-
- } break;
- case _EditorFontImportOptions::COLOR_GRADIENT_RANGE: {
-
- Color src=from->get_option("color/begin");
- Color to=from->get_option("color/end");
- for(int i=0;i<height;i++){
- color[i]=src.linear_interpolate(to,i/float(height));
- }
-
- } break;
- case _EditorFontImportOptions::COLOR_GRADIENT_IMAGE: {
-
- String fp = EditorImportPlugin::expand_source_path(from->get_option("color/image"));
- Image img;
- Error err = ImageLoader::load_image(fp,&img);
- if (err==OK) {
-
- for(int i=0;i<height;i++){
- //color[i]=img.get_pixel(0,i*img.get_height()/height);
- }
- } else {
-
- for(int i=0;i<height;i++){
- color[i]=Color(1,1,1,1);
- }
- }
-
- } break;
- }
-
-
- for(int i=0;i<font_data_list.size();i++) {
-
- if (font_data_list[i]->bitmap.size()==0)
- continue;
-
- int margin[4]={0,0,0,0};
-
- if (from->get_option("shadow/enabled").operator bool()) {
- int r=from->get_option("shadow/radius");
- Point2i ofs=Point2(from->get_option("shadow/offset"));
- margin[ MARGIN_LEFT ] = MAX( r - ofs.x, 0);
- margin[ MARGIN_RIGHT ] = MAX( r + ofs.x, 0);
- margin[ MARGIN_TOP ] = MAX( r - ofs.y, 0);
- margin[ MARGIN_BOTTOM ] = MAX( r + ofs.y, 0);
-
- }
-
- if (from->get_option("shadow2/enabled").operator bool()) {
- int r=from->get_option("shadow2/radius");
- Point2i ofs=Point2(from->get_option("shadow2/offset"));
- margin[ MARGIN_LEFT ] = MAX( r - ofs.x, margin[ MARGIN_LEFT ]);
- margin[ MARGIN_RIGHT ] = MAX( r + ofs.x, margin[ MARGIN_RIGHT ]);
- margin[ MARGIN_TOP ] = MAX( r - ofs.y, margin[ MARGIN_TOP ]);
- margin[ MARGIN_BOTTOM ] = MAX( r + ofs.y, margin[ MARGIN_BOTTOM ]);
-
- }
-
- Size2i s;
- s.width=font_data_list[i]->width+margin[MARGIN_LEFT]+margin[MARGIN_RIGHT];
- s.height=font_data_list[i]->height+margin[MARGIN_TOP]+margin[MARGIN_BOTTOM];
- Point2i o;
- o.x=margin[MARGIN_LEFT];
- o.y=margin[MARGIN_TOP];
-
- int ow=font_data_list[i]->width;
- int oh=font_data_list[i]->height;
-
- PoolVector<uint8_t> pixels;
- pixels.resize(s.x*s.y*4);
-
- PoolVector<uint8_t>::Write w = pixels.write();
- //print_line("val: "+itos(font_data_list[i]->valign));
- for(int y=0;y<s.height;y++) {
-
- int yc=CLAMP(y-o.y+font_data_list[i]->valign,0,height-1);
- Color c=color[yc];
- c.a=0;
-
- for(int x=0;x<s.width;x++) {
-
- int ofs=y*s.x+x;
- w[ofs*4+0]=c.r*255.0;
- w[ofs*4+1]=c.g*255.0;
- w[ofs*4+2]=c.b*255.0;
- w[ofs*4+3]=c.a*255.0;
- }
- }
-
-
- for(int si=0;si<2;si++) {
-
-#define S_VAR(m_v) (String(si == 0 ? "shadow/" : "shadow2/") + m_v)
- if (from->get_option(S_VAR("enabled")).operator bool()) {
- int r = from->get_option(S_VAR("radius"));
-
- Color sc = from->get_option(S_VAR("color"));
- Point2i so=Point2(from->get_option(S_VAR("offset")));
-
- float tr = from->get_option(S_VAR("transition"));
- print_line("shadow enabled: "+itos(si));
-
- Vector<uint8_t> s2buf;
- s2buf.resize(s.x*s.y);
- uint8_t *wa=s2buf.ptr();
-
- for(int j=0;j<s.x*s.y;j++){
-
- wa[j]=0;
- }
-
- // blit shadowa
- for(int x=0;x<ow;x++) {
- for(int y=0;y<oh;y++) {
- int ofs = (o.y+y+so.y)*s.x+x+o.x+so.x;
- wa[ofs]=font_data_list[i]->bitmap[y*ow+x];
- }
- }
- //blur shadow2 with separatable convolution
-
- if (r>0) {
-
- Vector<uint8_t> pixels2;
- pixels2.resize(s2buf.size());
- uint8_t *w2=pixels2.ptr();
- //vert
- for(int x=0;x<s.width;x++) {
- for(int y=0;y<s.height;y++) {
-
- int ofs = y*s.width+x;
- int sum=wa[ofs];
-
- for(int k=1;k<=r;k++) {
-
- int ofs_d=MIN(y+k,s.height-1)*s.width+x;
- int ofs_u=MAX(y-k,0)*s.width+x;
- sum+=wa[ofs_d];
- sum+=wa[ofs_u];
- }
-
- w2[ofs]=sum/(r*2+1);
-
- }
- }
- //horiz
- for(int x=0;x<s.width;x++) {
- for(int y=0;y<s.height;y++) {
-
- int ofs = y*s.width+x;
- int sum=w2[ofs];
-
- for(int k=1;k<=r;k++) {
-
- int ofs_r=MIN(x+k,s.width-1)+s.width*y;
- int ofs_l=MAX(x-k,0)+s.width*y;
- sum+=w2[ofs_r];
- sum+=w2[ofs_l];
- }
-
- wa[ofs]=Math::pow(float(sum/(r*2+1))/255.0f,tr)*255.0f;
-
- }
- }
-
- }
-
- //blend back
-
- for(int j=0;j<s.x*s.y;j++){
- Color wd(w[j*4+0]/255.0,w[j*4+1]/255.0,w[j*4+2]/255.0,w[j*4+3]/255.0);
- Color ws(sc.r,sc.g,sc.b,sc.a*(wa[j]/255.0));
- Color b = wd.blend(ws);
-
- w[j*4+0]=b.r*255.0;
- w[j*4+1]=b.g*255.0;
- w[j*4+2]=b.b*255.0;
- w[j*4+3]=b.a*255.0;
-
- }
- }
- }
-
- for(int y=0;y<oh;y++) {
- int yc=CLAMP(y+font_data_list[i]->valign,0,height-1);
- Color sc=color[yc];
- for(int x=0;x<ow;x++) {
- int ofs = (o.y+y)*s.x+x+o.x;
- float c = font_data_list[i]->bitmap[y*ow+x]/255.0;
- Color src_col=sc;
- src_col.a*=c;
- Color dst_col(w[ofs*4+0]/255.0,w[ofs*4+1]/255.0,w[ofs*4+2]/255.0,w[ofs*4+3]/255.0);
- dst_col = dst_col.blend(src_col);
- w[ofs*4+0]=dst_col.r*255.0;
- w[ofs*4+1]=dst_col.g*255.0;
- w[ofs*4+2]=dst_col.b*255.0;
- w[ofs*4+3]=dst_col.a*255.0;
- }
- }
-
-
- w=PoolVector<uint8_t>::Write();
-
- Image img(s.width,s.height,0,Image::FORMAT_RGBA8,pixels);
-
- font_data_list[i]->blit=img;
- font_data_list[i]->blit_ofs=o;
-
- }
-
- //make atlas
- int spacing=2;
- Vector<Size2i> sizes;
- sizes.resize(font_data_list.size());
- for(int i=0;i<font_data_list.size();i++) {
-
- sizes[i]=Size2(font_data_list[i]->blit.get_width()+spacing*2,font_data_list[i]->blit.get_height()+spacing*2);
-
- }
- Vector<Point2i> res;
- Size2i res_size;
- EditorAtlas::fit(sizes,res,res_size);
- res_size.x=next_power_of_2(res_size.x);
- res_size.y=next_power_of_2(res_size.y);
- print_line("Atlas size: "+res_size);
-
- Image atlas(res_size.x,res_size.y,0,Image::FORMAT_RGBA8);
-
- for(int i=0;i<font_data_list.size();i++) {
-
- if (font_data_list[i]->bitmap.size()==0)
- continue;
- atlas.blit_rect(font_data_list[i]->blit,Rect2(0,0,font_data_list[i]->blit.get_width(),font_data_list[i]->blit.get_height()),res[i]+Size2(spacing,spacing));
- font_data_list[i]->ofs_x=res[i].x+spacing;
- font_data_list[i]->ofs_y=res[i].y+spacing;
-
-
- }
-
- if (from->has_option("advanced/premultiply_alpha") && bool(from->get_option("advanced/premultiply_alpha"))) {
-
- PoolVector<uint8_t> data = atlas.get_data();
- int dl = data.size();
- {
- PoolVector<uint8_t>::Write w = data.write();
-
- for(int i=0;i<dl;i+=4) {
-
- w[i+0]= uint8_t(int(w[i+0])*int(w[i+3])/255);
- w[i+1]= uint8_t(int(w[i+1])*int(w[i+3])/255);
- w[i+2]= uint8_t(int(w[i+2])*int(w[i+3])/255);
- }
- }
-
- atlas=Image(res_size.x,res_size.y,0,Image::FORMAT_RGBA8,data);
- }
-
- if (from->has_option("color/monochrome") && bool(from->get_option("color/monochrome"))) {
-
- atlas.convert(Image::FORMAT_LA8);
- }
-
-
- if (0) {
- //debug the texture
- Ref<ImageTexture> atlast = memnew( ImageTexture );
- atlast->create_from_image(atlas);
- //atlast->create_from_image(font_data_list[5]->blit);
- TextureRect *tf = memnew( TextureRect );
- tf->set_texture(atlast);
- dialog->add_child(tf);
- }
-
-
- /* CREATE FONT */
-
- int char_space = from->get_option("extra_space/char");
- int space_space = from->get_option("extra_space/space");
- int top_space = from->get_option("extra_space/top");
- int bottom_space = from->get_option("extra_space/bottom");
- bool enable_filter = from->get_option("advanced/enable_filter");
- if (from->has_option("advanced/disable_filter")){ // this is a compatibility check for a deprecated option
- enable_filter = !from->get_option("advanced/disable_filter");
- }
-
- Ref<BitmapFont> font;
-
- if (p_existing!=String() && ResourceCache::has(p_existing)) {
-
- font = Ref<BitmapFont>( Object::cast_to<BitmapFont>(ResourceCache::get(p_existing)));
- }
-
- if (font.is_null()) {
- font = Ref<BitmapFont>( memnew( BitmapFont ) );
- }
-
- font->clear();
- font->set_height(height+bottom_space+top_space);
- font->set_ascent(ascent+top_space);
- font->set_distance_field_hint(font_mode==_EditorFontImportOptions::FONT_DISTANCE_FIELD);
-
- //register texures
- {
- Ref<ImageTexture> t = memnew(ImageTexture);
- int flags;
- if (!enable_filter)
- flags=0;
- else
- flags=Texture::FLAG_FILTER;
- t->create_from_image(atlas,flags);
- t->set_storage( ImageTexture::STORAGE_COMPRESS_LOSSLESS );
- font->add_texture(t);
-
- }
- //register characters
-
-
- for(int i=0;i<font_data_list.size();i++) {
- _EditorFontData *fd=font_data_list[i];
- int tex_idx=0;
-
- font->add_char(fd->character,tex_idx,Rect2( fd->ofs_x, fd->ofs_y, fd->blit.get_width(), fd->blit.get_height()),Point2(fd->halign-fd->blit_ofs.x,fd->valign-fd->blit_ofs.y+top_space), fd->advance+char_space+(fd->character==' '?space_space:0));
- memdelete(fd);
- }
-
- for(Map<_EditorKerningKey,int>::Element *E=kerning_map.front();E;E=E->next()) {
-
- font->add_kerning_pair(E->key().A,E->key().B,E->get());
- }
-
- FT_Done_FreeType( library );
-
- return font;
-#else
-
- return Ref<BitmapFont>();
-#endif
-}
-
-
-String EditorFontImportPlugin::get_name() const {
-
- return "font";
-}
-String EditorFontImportPlugin::get_visible_name() const{
-
- return TTR("Font");
-}
-void EditorFontImportPlugin::import_dialog(const String& p_from){
-
- dialog->popup_import(p_from);
-}
-Error EditorFontImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){
-
-
- Ref<BitmapFont> font = EditorFontImportPlugin::generate_font(p_from,p_path);
- if (!font.is_valid())
- return ERR_CANT_CREATE;
-
- Ref<ResourceImportMetadata> from=p_from;
- from->set_source_md5(0,FileAccess::get_md5(EditorImportPlugin::expand_source_path(from->get_source_path(0))));
- from->set_editor(get_name());
- font->set_import_metadata(from);
-
- return ResourceSaver::save(p_path,font);
-
-}
-
-void EditorFontImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
-
- for(int i=0;i<p_drop.size();i++) {
- String ext = p_drop[i].get_extension().to_lower();
- String file = p_drop[i].get_file();
- if (ext=="ttf" || ext=="otf" || ext=="fnt") {
-
- import_dialog();
- dialog->set_source_and_dest(p_drop[i],p_dest_path.plus_file(file.get_basename()+".font"));
- break;
- }
- }
-}
-
-
-EditorFontImportPlugin::EditorFontImportPlugin(EditorNode* p_editor) {
-
- dialog = memnew( EditorFontImportDialog(this) );
- p_editor->get_gui_base()->add_child(dialog);
-}
-#endif
diff --git a/editor/io_plugins/editor_font_import_plugin.h b/editor/io_plugins/editor_font_import_plugin.h
deleted file mode 100644
index 67ae7cd8a7..0000000000
--- a/editor/io_plugins/editor_font_import_plugin.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*************************************************************************/
-/* editor_font_import_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 EDITOR_FONT_IMPORT_PLUGIN_H
-#define EDITOR_FONT_IMPORT_PLUGIN_H
-
-#include "editor/editor_export.h"
-#include "scene/resources/font.h"
-#if 0
-class EditorNode;
-class EditorFontImportDialog;
-
-class EditorFontImportPlugin : public EditorImportPlugin {
-
- GDCLASS(EditorFontImportPlugin,EditorImportPlugin);
-
- EditorFontImportDialog *dialog;
-public:
-
- Ref<BitmapFont> generate_font(const Ref<ResourceImportMetadata>& p_from,const String& p_existing=String()); //used by editor
-
- virtual String get_name() const;
- virtual String get_visible_name() const;
- virtual void import_dialog(const String& p_from="");
- virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
- virtual void import_from_drop(const Vector<String>& p_drop,const String& p_dest_path);
-
-
- EditorFontImportPlugin(EditorNode* p_editor);
-};
-
-#endif // EDITOR_FONT_IMPORT_PLUGIN_H
-#endif
diff --git a/editor/io_plugins/editor_mesh_import_plugin.cpp b/editor/io_plugins/editor_mesh_import_plugin.cpp
deleted file mode 100644
index 5612ad160b..0000000000
--- a/editor/io_plugins/editor_mesh_import_plugin.cpp
+++ /dev/null
@@ -1,594 +0,0 @@
-/*************************************************************************/
-/* editor_mesh_import_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 "editor_mesh_import_plugin.h"
-
-#if 0
-
-#include "editor/editor_dir_dialog.h"
-#include "editor/editor_file_dialog.h"
-#include "editor/editor_node.h"
-#include "editor/property_editor.h"
-//#include "scene/resources/sample.h"
-#include "io/marshalls.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-#include "scene/resources/surface_tool.h"
-
-class _EditorMeshImportOptions : public Object {
-
- GDCLASS(_EditorMeshImportOptions,Object);
-public:
-
-
- bool generate_tangents;
- bool generate_normals;
- bool flip_faces;
- bool smooth_shading;
- bool weld_vertices;
- bool import_material;
- bool import_textures;
- float weld_tolerance;
-
-
- bool _set(const StringName& p_name, const Variant& p_value) {
-
- String n = p_name;
- if (n=="generate/tangents")
- generate_tangents=p_value;
- else if (n=="generate/normals")
- generate_normals=p_value;
- else if (n=="import/materials")
- import_material=p_value;
- else if (n=="import/textures")
- import_textures=p_value;
- else if (n=="force/flip_faces")
- flip_faces=p_value;
- else if (n=="force/smooth_shading")
- smooth_shading=p_value;
- else if (n=="force/weld_vertices")
- weld_vertices=p_value;
- else if (n=="force/weld_tolerance")
- weld_tolerance=p_value;
- else
- return false;
-
- return true;
-
- }
-
- bool _get(const StringName& p_name,Variant &r_ret) const{
-
- String n = p_name;
- if (n=="generate/tangents")
- r_ret=generate_tangents;
- else if (n=="generate/normals")
- r_ret=generate_normals;
- else if (n=="import/materials")
- r_ret=import_material;
- else if (n=="import/textures")
- r_ret=import_textures;
- else if (n=="force/flip_faces")
- r_ret=flip_faces;
- else if (n=="force/smooth_shading")
- r_ret=smooth_shading;
- else if (n=="force/weld_vertices")
- r_ret=weld_vertices;
- else if (n=="force/weld_tolerance")
- r_ret=weld_tolerance;
- else
- return false;
-
- return true;
-
- }
- void _get_property_list( List<PropertyInfo> *p_list) const{
-
- p_list->push_back(PropertyInfo(Variant::BOOL,"generate/tangents"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"generate/normals"));
- //not for nowp
- //p_list->push_back(PropertyInfo(Variant::BOOL,"import/materials"));
- //p_list->push_back(PropertyInfo(Variant::BOOL,"import/textures"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"force/flip_faces"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"force/smooth_shading"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"force/weld_vertices"));
- p_list->push_back(PropertyInfo(Variant::REAL,"force/weld_tolerance",PROPERTY_HINT_RANGE,"0.00001,16,0.00001"));
- //p_list->push_back(PropertyInfo(Variant::BOOL,"compress/enable"));
- //p_list->push_back(PropertyInfo(Variant::INT,"compress/bitrate",PROPERTY_HINT_ENUM,"64,96,128,192"));
-
-
- }
-
-
- static void _bind_methods() {
-
-
- ADD_SIGNAL( MethodInfo("changed"));
- }
-
-
- _EditorMeshImportOptions() {
-
- generate_tangents=true;
- generate_normals=false;
- flip_faces=false;
- smooth_shading=false;
- weld_vertices=true;
- weld_tolerance=0.0001;
- import_material=false;
- import_textures=false;
-
- }
-
-
-};
-
-class EditorMeshImportDialog : public ConfirmationDialog {
-
- GDCLASS(EditorMeshImportDialog,ConfirmationDialog);
-
- EditorMeshImportPlugin *plugin;
-
- LineEdit *import_path;
- LineEdit *save_path;
- EditorFileDialog *file_select;
- EditorDirDialog *save_select;
- AcceptDialog *error_dialog;
- PropertyEditor *option_editor;
-
- _EditorMeshImportOptions *options;
-
-
-public:
-
- void _choose_files(const Vector<String>& p_path) {
-
- String files;
- for(int i=0;i<p_path.size();i++) {
-
- if (i>0)
- files+=",";
- files+=p_path[i];
- }
- /*
- if (p_path.size()) {
- String srctex=p_path[0];
- String ipath = EditorImportDB::get_singleton()->find_source_path(srctex);
-
- if (ipath!="")
- save_path->set_text(ipath.get_base_dir());
- }*/
- import_path->set_text(files);
-
- }
- void _choose_save_dir(const String& p_path) {
-
- save_path->set_text(p_path);
- }
-
- void _browse() {
-
- file_select->popup_centered_ratio();
- }
-
- void _browse_target() {
-
- save_select->popup_centered_ratio();
- }
-
- void popup_import(const String& p_path) {
-
- popup_centered(Size2(400,400)*EDSCALE);
-
- if (p_path!="") {
-
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
- ERR_FAIL_COND(!rimd.is_valid());
-
- save_path->set_text(p_path.get_base_dir());
- List<String> opts;
- rimd->get_options(&opts);
- for(List<String>::Element *E=opts.front();E;E=E->next()) {
-
- options->_set(E->get(),rimd->get_option(E->get()));
- }
-
- String src = "";
- for(int i=0;i<rimd->get_source_count();i++) {
- if (i>0)
- src+=",";
- src+=EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
- }
- import_path->set_text(src);
- }
- }
-
- void _import() {
-
- Vector<String> meshes = import_path->get_text().split(",");
- if (meshes.size()==0) {
- error_dialog->set_text(TTR("No meshes to import!"));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- String dst = save_path->get_text();
- if (dst=="") {
- error_dialog->set_text(TTR("Save path is empty!"));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- for(int i=0;i<meshes.size();i++) {
-
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
-
- List<PropertyInfo> pl;
- options->_get_property_list(&pl);
- for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
-
- Variant v;
- String opt=E->get().name;
- options->_get(opt,v);
- imd->set_option(opt,v);
-
- }
-
- imd->add_source(EditorImportPlugin::validate_source_path(meshes[i]));
-
- String file_path = dst.plus_file(meshes[i].get_file().get_basename()+".mesh");
-
- plugin->import(file_path,imd);
- }
-
- hide();
- }
-
- void _notification(int p_what) {
-
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
-
- option_editor->edit(options);
- }
- }
-
- static void _bind_methods() {
-
- ClassDB::bind_method("_choose_files",&EditorMeshImportDialog::_choose_files);
- ClassDB::bind_method("_choose_save_dir",&EditorMeshImportDialog::_choose_save_dir);
- ClassDB::bind_method("_import",&EditorMeshImportDialog::_import);
- ClassDB::bind_method("_browse",&EditorMeshImportDialog::_browse);
- ClassDB::bind_method("_browse_target",&EditorMeshImportDialog::_browse_target);
- }
-
- EditorMeshImportDialog(EditorMeshImportPlugin *p_plugin) {
-
- plugin=p_plugin;
-
- set_title(TTR("Single Mesh Import"));
- set_hide_on_ok(false);
-
- VBoxContainer *vbc = memnew( VBoxContainer );
- add_child(vbc);
- //set_child_rect(vbc);
-
- HBoxContainer *hbc = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Source Mesh(es):"),hbc);
-
- import_path = memnew( LineEdit );
- import_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(import_path);
-
- Button * import_choose = memnew( Button );
- import_choose->set_text(" .. ");
- hbc->add_child(import_choose);
-
- import_choose->connect("pressed", this,"_browse");
-
- hbc = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Target Path:"),hbc);
-
- save_path = memnew( LineEdit );
- save_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(save_path);
-
- Button * save_choose = memnew( Button );
- save_choose->set_text(" .. ");
- hbc->add_child(save_choose);
-
- save_choose->connect("pressed", this,"_browse_target");
-
- file_select = memnew( EditorFileDialog );
- file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
- file_select->set_mode(EditorFileDialog::MODE_OPEN_FILES);
- file_select->add_filter("*.obj ; Wavefront OBJ");
- add_child(file_select);
- file_select->connect("files_selected", this,"_choose_files");
-
- save_select = memnew( EditorDirDialog );
- add_child(save_select);
- save_select->connect("dir_selected", this,"_choose_save_dir");
-
- get_ok()->connect("pressed", this,"_import");
- get_ok()->set_text(TTR("Import"));
-
- error_dialog = memnew( AcceptDialog );
- add_child(error_dialog);
-
- options = memnew( _EditorMeshImportOptions );
-
- option_editor = memnew( PropertyEditor );
- option_editor->hide_top_label();
- vbc->add_margin_child(TTR("Options:"),option_editor,true);
- }
-
- ~EditorMeshImportDialog() {
- memdelete(options);
- }
-
-};
-
-
-String EditorMeshImportPlugin::get_name() const {
-
- return "mesh";
-}
-String EditorMeshImportPlugin::get_visible_name() const{
-
- return TTR("Mesh");
-}
-void EditorMeshImportPlugin::import_dialog(const String& p_from){
-
- dialog->popup_import(p_from);
-}
-Error EditorMeshImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){
-
-
- ERR_FAIL_COND_V(p_from->get_source_count()!=1,ERR_INVALID_PARAMETER);
-
- Ref<ResourceImportMetadata> from=p_from;
-
- String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0));
- FileAccessRef f = FileAccess::open(src_path,FileAccess::READ);
- ERR_FAIL_COND_V(!f,ERR_CANT_OPEN);
-
- Ref<Mesh> mesh;
- Map<String,Ref<Material> > name_map;
-
- if (FileAccess::exists(p_path)) {
- mesh=ResourceLoader::load(p_path,"Mesh");
- if (mesh.is_valid()) {
- for(int i=0;i<mesh->get_surface_count();i++) {
-
- if (!mesh->surface_get_material(i).is_valid())
- continue;
- String name;
- if (mesh->surface_get_name(i)!="")
- name=mesh->surface_get_name(i);
- else
- name=vformat(TTR("Surface %d"),i+1);
-
- name_map[name]=mesh->surface_get_material(i);
- }
-
- while(mesh->get_surface_count()) {
- mesh->surface_remove(0);
- }
- }
- }
-
- if (!mesh.is_valid())
- mesh = Ref<Mesh>( memnew( Mesh ) );
-
-
- bool generate_normals=from->get_option("generate/normals");
- bool generate_tangents=from->get_option("generate/tangents");
- bool flip_faces=from->get_option("force/flip_faces");
- bool force_smooth=from->get_option("force/smooth_shading");
- bool weld_vertices=from->get_option("force/weld_vertices");
- float weld_tolerance=from->get_option("force/weld_tolerance");
- Vector<Vector3> vertices;
- Vector<Vector3> normals;
- Vector<Vector2> uvs;
- String name;
-
- Ref<SurfaceTool> surf_tool = memnew( SurfaceTool) ;
- surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
- if (force_smooth)
- surf_tool->add_smooth_group(true);
- int has_index_data=false;
-
- while(true) {
-
-
- String l = f->get_line().strip_edges();
-
- if (l.begins_with("v ")) {
- //vertex
- Vector<String> v = l.split(" ",false);
- ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA);
- Vector3 vtx;
- vtx.x=v[1].to_float();
- vtx.y=v[2].to_float();
- vtx.z=v[3].to_float();
- vertices.push_back(vtx);
- } else if (l.begins_with("vt ")) {
- //uv
- Vector<String> v = l.split(" ",false);
- ERR_FAIL_COND_V(v.size()<3,ERR_INVALID_DATA);
- Vector2 uv;
- uv.x=v[1].to_float();
- uv.y=1.0-v[2].to_float();
- uvs.push_back(uv);
-
- } else if (l.begins_with("vn ")) {
- //normal
- Vector<String> v = l.split(" ",false);
- ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA);
- Vector3 nrm;
- nrm.x=v[1].to_float();
- nrm.y=v[2].to_float();
- nrm.z=v[3].to_float();
- normals.push_back(nrm);
- } if (l.begins_with("f ")) {
- //vertex
-
- has_index_data=true;
- Vector<String> v = l.split(" ",false);
- ERR_FAIL_COND_V(v.size()<4,ERR_INVALID_DATA);
-
- //not very fast, could be sped up
-
-
- Vector<String> face[3];
- face[0] = v[1].split("/");
- face[1] = v[2].split("/");
- ERR_FAIL_COND_V(face[0].size()==0,ERR_PARSE_ERROR);
- ERR_FAIL_COND_V(face[0].size()!=face[1].size(),ERR_PARSE_ERROR);
- for(int i=2;i<v.size()-1;i++) {
-
- face[2] = v[i+1].split("/");
- ERR_FAIL_COND_V(face[0].size()!=face[2].size(),ERR_PARSE_ERROR);
- for(int j=0;j<3;j++) {
-
- int idx=j;
-
- if (!flip_faces && idx<2) {
- idx=1^idx;
- }
-
-
- if (face[idx].size()==3) {
- int norm = face[idx][2].to_int()-1;
- ERR_FAIL_INDEX_V(norm,normals.size(),ERR_PARSE_ERROR);
- surf_tool->add_normal(normals[norm]);
- }
-
- if (face[idx].size()>=2 && face[idx][1]!=String()) {
-
- int uv = face[idx][1].to_int()-1;
- ERR_FAIL_INDEX_V(uv,uvs.size(),ERR_PARSE_ERROR);
- surf_tool->add_uv(uvs[uv]);
- }
-
- int vtx = face[idx][0].to_int()-1;
- ERR_FAIL_INDEX_V(vtx,vertices.size(),ERR_PARSE_ERROR);
-
- Vector3 vertex = vertices[vtx];
- if (weld_vertices)
- vertex=vertex.snapped(weld_tolerance);
- surf_tool->add_vertex(vertex);
- }
-
- face[1]=face[2];
- }
- } else if (l.begins_with("s ") && !force_smooth) { //smoothing
- String what = l.substr(2,l.length()).strip_edges();
- if (what=="off")
- surf_tool->add_smooth_group(false);
- else
- surf_tool->add_smooth_group(true);
-
- } else if (l.begins_with("o ") || f->eof_reached()) { //new surface or done
-
- if (has_index_data) {
- //new object/surface
- if (generate_normals || force_smooth)
- surf_tool->generate_normals();
- if (uvs.size() && (normals.size() || generate_normals) && generate_tangents)
- surf_tool->generate_tangents();
-
- surf_tool->index();
- mesh = surf_tool->commit(mesh);
- if (name=="")
- name=vformat(TTR("Surface %d"),mesh->get_surface_count()-1);
- mesh->surface_set_name(mesh->get_surface_count()-1,name);
- name="";
- surf_tool->clear();
- surf_tool->begin(Mesh::PRIMITIVE_TRIANGLES);
- if (force_smooth)
- surf_tool->add_smooth_group(true);
-
- has_index_data=false;
-
- if (f->eof_reached())
- break;
- }
-
- if (l.begins_with("o ")) //name
- name=l.substr(2,l.length()).strip_edges();
- }
- }
-
-
- from->set_source_md5(0,FileAccess::get_md5(src_path));
- from->set_editor(get_name());
- mesh->set_import_metadata(from);
-
- //re-apply materials if exist
- for(int i=0;i<mesh->get_surface_count();i++) {
-
- String n = mesh->surface_get_name(i);
- if (name_map.has(n))
- mesh->surface_set_material(i,name_map[n]);
- }
-
- Error err = ResourceSaver::save(p_path,mesh);
-
- return err;
-}
-
-
-void EditorMeshImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
-
-
- Vector<String> files;
- for(int i=0;i<p_drop.size();i++) {
- String ext = p_drop[i].get_extension().to_lower();
- String file = p_drop[i].get_file();
- if (ext=="obj") {
-
- files.push_back(p_drop[i]);
- }
- }
-
- if (files.size()) {
- import_dialog();
- dialog->_choose_files(files);
- dialog->_choose_save_dir(p_dest_path);
- }
-}
-
-EditorMeshImportPlugin::EditorMeshImportPlugin(EditorNode* p_editor) {
-
- dialog = memnew( EditorMeshImportDialog(this));
- p_editor->get_gui_base()->add_child(dialog);
-}
-#endif
diff --git a/editor/io_plugins/editor_mesh_import_plugin.h b/editor/io_plugins/editor_mesh_import_plugin.h
deleted file mode 100644
index 27d523b2be..0000000000
--- a/editor/io_plugins/editor_mesh_import_plugin.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*************************************************************************/
-/* editor_mesh_import_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 EDITOR_MESH_IMPORT_PLUGIN_H
-#define EDITOR_MESH_IMPORT_PLUGIN_H
-
-#if 0
-#include "editor/editor_import_export.h"
-#include "scene/resources/font.h"
-
-class EditorNode;
-class EditorMeshImportDialog;
-
-class EditorMeshImportPlugin : public EditorImportPlugin {
-
- GDCLASS(EditorMeshImportPlugin,EditorImportPlugin);
-
- EditorMeshImportDialog *dialog;
-
-
-public:
-
- virtual String get_name() const;
- virtual String get_visible_name() const;
- virtual void import_dialog(const String& p_from="");
- virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
- void import_from_drop(const Vector<String>& p_drop, const String &p_dest_path);
-
-
- EditorMeshImportPlugin(EditorNode* p_editor);
-};
-
-#endif
-#endif // EDITOR_MESH_IMPORT_PLUGIN_H
diff --git a/editor/io_plugins/editor_sample_import_plugin.cpp b/editor/io_plugins/editor_sample_import_plugin.cpp
deleted file mode 100644
index a522da97ba..0000000000
--- a/editor/io_plugins/editor_sample_import_plugin.cpp
+++ /dev/null
@@ -1,930 +0,0 @@
-/*************************************************************************/
-/* editor_sample_import_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 "editor_sample_import_plugin.h"
-
-#include "editor/editor_dir_dialog.h"
-#include "editor/editor_file_dialog.h"
-#include "editor/editor_node.h"
-#include "editor/editor_settings.h"
-#include "editor/property_editor.h"
-#include "io/marshalls.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-
-#if 0
-
-class _EditorSampleImportOptions : public Object {
-
- GDCLASS(_EditorSampleImportOptions,Object);
-public:
-
- enum CompressMode {
- COMPRESS_MODE_DISABLED,
- COMPRESS_MODE_RAM,
- COMPRESS_MODE_DISK
- };
-
- enum CompressBitrate {
- COMPRESS_64,
- COMPRESS_96,
- COMPRESS_128,
- COMPRESS_192
- };
-
- bool force_8_bit;
- bool force_mono;
- bool force_rate;
- float force_rate_hz;
-
- bool edit_trim;
- bool edit_normalize;
- bool edit_loop;
-
- CompressMode compress_mode;
- CompressBitrate compress_bitrate;
-
-
- bool _set(const StringName& p_name, const Variant& p_value) {
-
- String n = p_name;
- if (n=="force/8_bit")
- force_8_bit=p_value;
- else if (n=="force/mono")
- force_mono=p_value;
- else if (n=="force/max_rate")
- force_rate=p_value;
- else if (n=="force/max_rate_hz")
- force_rate_hz=p_value;
- else if (n=="edit/trim")
- edit_trim=p_value;
- else if (n=="edit/normalize")
- edit_normalize=p_value;
- else if (n=="edit/loop")
- edit_loop=p_value;
- else if (n=="compress/mode")
- compress_mode=CompressMode(int(p_value));
- else if (n=="compress/bitrate")
- compress_bitrate=CompressBitrate(int(p_value));
- else
- return false;
-
- return true;
-
- }
-
- bool _get(const StringName& p_name,Variant &r_ret) const{
-
- String n = p_name;
- if (n=="force/8_bit")
- r_ret=force_8_bit;
- else if (n=="force/mono")
- r_ret=force_mono;
- else if (n=="force/max_rate")
- r_ret=force_rate;
- else if (n=="force/max_rate_hz")
- r_ret=force_rate_hz;
- else if (n=="edit/trim")
- r_ret=edit_trim;
- else if (n=="edit/normalize")
- r_ret=edit_normalize;
- else if (n=="edit/loop")
- r_ret=edit_loop;
- else if (n=="compress/mode")
- r_ret=compress_mode;
- else if (n=="compress/bitrate")
- r_ret=compress_bitrate;
- else
- return false;
-
- return true;
-
- }
- void _get_property_list( List<PropertyInfo> *p_list) const{
-
- p_list->push_back(PropertyInfo(Variant::BOOL,"force/8_bit"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"force/mono"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"force/max_rate"));
- p_list->push_back(PropertyInfo(Variant::REAL,"force/max_rate_hz",PROPERTY_HINT_EXP_RANGE,"11025,192000,1"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"edit/trim"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"edit/normalize"));
- p_list->push_back(PropertyInfo(Variant::BOOL,"edit/loop"));
- p_list->push_back(PropertyInfo(Variant::INT,"compress/mode",PROPERTY_HINT_ENUM,"Disabled,RAM (Ima-ADPCM)"));
- //p_list->push_back(PropertyInfo(Variant::INT,"compress/bitrate",PROPERTY_HINT_ENUM,"64,96,128,192"));
-
-
- }
-
-
- static void _bind_methods() {
-
-
- ADD_SIGNAL( MethodInfo("changed"));
- }
-
-
- _EditorSampleImportOptions() {
-
- force_8_bit=false;
- force_mono=false;
- force_rate=true;
- force_rate_hz=44100;
-
- edit_trim=true;
- edit_normalize=true;
- edit_loop=false;
-
- compress_mode=COMPRESS_MODE_RAM;
- compress_bitrate=COMPRESS_128;
- }
-
-
-};
-
-class EditorSampleImportDialog : public ConfirmationDialog {
-
- GDCLASS(EditorSampleImportDialog,ConfirmationDialog);
-
- EditorSampleImportPlugin *plugin;
-
- LineEdit *import_path;
- LineEdit *save_path;
- EditorFileDialog *file_select;
- EditorDirDialog *save_select;
- ConfirmationDialog *error_dialog;
- PropertyEditor *option_editor;
-
- _EditorSampleImportOptions *options;
-
-
-public:
-
- void _choose_files(const Vector<String>& p_path) {
-
- String files;
- for(int i=0;i<p_path.size();i++) {
-
- if (i>0)
- files+=",";
- files+=p_path[i];
- }
- /*
- if (p_path.size()) {
- String srctex=p_path[0];
- String ipath = EditorImportDB::get_singleton()->find_source_path(srctex);
-
- if (ipath!="")
- save_path->set_text(ipath.get_base_dir());
- }*/
- import_path->set_text(files);
-
- }
- void _choose_save_dir(const String& p_path) {
-
- save_path->set_text(p_path);
- }
-
- void _browse() {
-
- file_select->popup_centered_ratio();
- }
-
- void _browse_target() {
-
- save_select->popup_centered_ratio();
-
- }
-
-
- void popup_import(const String& p_path) {
-
- popup_centered(Size2(400,400)*EDSCALE);
- if (p_path!="") {
-
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
- ERR_FAIL_COND(!rimd.is_valid());
-
- save_path->set_text(p_path.get_base_dir());
- List<String> opts;
- rimd->get_options(&opts);
- for(List<String>::Element *E=opts.front();E;E=E->next()) {
-
- options->_set(E->get(),rimd->get_option(E->get()));
- }
-
- String src = "";
- for(int i=0;i<rimd->get_source_count();i++) {
- if (i>0)
- src+=",";
- src+=EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
- }
- import_path->set_text(src);
- }
- }
-
-
- void _import() {
-
- Vector<String> samples = import_path->get_text().split(",");
-
- if (samples.size()==0) {
- error_dialog->set_text(TTR("No samples to import!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- }
-
- if (save_path->get_text().strip_edges()=="") {
- error_dialog->set_text(TTR("Target path is empty."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (!save_path->get_text().begins_with("res://")) {
- error_dialog->set_text(TTR("Target path must be a complete resource path."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (!DirAccess::exists(save_path->get_text())) {
- error_dialog->set_text(TTR("Target path must exist."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- for(int i=0;i<samples.size();i++) {
-
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
-
- List<PropertyInfo> pl;
- options->_get_property_list(&pl);
- for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
-
- Variant v;
- String opt=E->get().name;
- options->_get(opt,v);
- imd->set_option(opt,v);
-
- }
-
- imd->add_source(EditorImportPlugin::validate_source_path(samples[i]));
-
- String dst = save_path->get_text();
- if (dst=="") {
- error_dialog->set_text(TTR("Save path is empty!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- }
-
- dst = dst.plus_file(samples[i].get_file().get_basename()+".sample");
-
- plugin->import(dst,imd);
- }
-
- hide();
-
- }
-
-
- void _notification(int p_what) {
-
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
-
- option_editor->edit(options);
- }
- }
-
- static void _bind_methods() {
-
-
- ClassDB::bind_method("_choose_files",&EditorSampleImportDialog::_choose_files);
- ClassDB::bind_method("_choose_save_dir",&EditorSampleImportDialog::_choose_save_dir);
- ClassDB::bind_method("_import",&EditorSampleImportDialog::_import);
- ClassDB::bind_method("_browse",&EditorSampleImportDialog::_browse);
- ClassDB::bind_method("_browse_target",&EditorSampleImportDialog::_browse_target);
- //ADD_SIGNAL( MethodInfo("imported",PropertyInfo(Variant::OBJECT,"scene")) );
- }
-
- EditorSampleImportDialog(EditorSampleImportPlugin *p_plugin) {
-
- plugin=p_plugin;
-
-
- set_title(TTR("Import Audio Samples"));
-
- VBoxContainer *vbc = memnew( VBoxContainer );
- add_child(vbc);
- //set_child_rect(vbc);
-
-
- HBoxContainer *hbc = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Source Sample(s):"),hbc);
-
- import_path = memnew( LineEdit );
- import_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(import_path);
-
- Button * import_choose = memnew( Button );
- import_choose->set_text(" .. ");
- hbc->add_child(import_choose);
-
- import_choose->connect("pressed", this,"_browse");
-
- hbc = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Target Path:"),hbc);
-
- save_path = memnew( LineEdit );
- save_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(save_path);
-
- Button * save_choose = memnew( Button );
- save_choose->set_text(" .. ");
- hbc->add_child(save_choose);
-
- save_choose->connect("pressed", this,"_browse_target");
-
- file_select = memnew(EditorFileDialog);
- file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
- add_child(file_select);
- file_select->set_mode(EditorFileDialog::MODE_OPEN_FILES);
- file_select->connect("files_selected", this,"_choose_files");
- file_select->add_filter("*.wav ; MS Waveform");
- save_select = memnew( EditorDirDialog );
- add_child(save_select);
-
- //save_select->set_mode(EditorFileDialog::MODE_OPEN_DIR);
- save_select->connect("dir_selected", this,"_choose_save_dir");
-
- get_ok()->connect("pressed", this,"_import");
- get_ok()->set_text(TTR("Import"));
-
-
- error_dialog = memnew ( ConfirmationDialog );
- add_child(error_dialog);
- error_dialog->get_ok()->set_text(TTR("Accept"));
- //error_dialog->get_cancel()->hide();
-
- set_hide_on_ok(false);
- options = memnew( _EditorSampleImportOptions );
-
- option_editor = memnew( PropertyEditor );
- option_editor->hide_top_label();
- vbc->add_margin_child(TTR("Options:"),option_editor,true);
- }
-
- ~EditorSampleImportDialog() {
- memdelete(options);
- }
-
-};
-
-
-String EditorSampleImportPlugin::get_name() const {
-
- return "sample";
-}
-String EditorSampleImportPlugin::get_visible_name() const{
-
- return TTR("Audio Sample");
-}
-void EditorSampleImportPlugin::import_dialog(const String& p_from){
-
- dialog->popup_import(p_from);
-}
-Error EditorSampleImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){
-
- ERR_FAIL_COND_V(p_from->get_source_count()!=1,ERR_INVALID_PARAMETER);
-
- Ref<ResourceImportMetadata> from=p_from;
-
- String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0));
- Ref<Sample> smp = ResourceLoader::load(src_path);
- ERR_FAIL_COND_V(smp.is_null(),ERR_CANT_OPEN);
-
-
- float rate = smp->get_mix_rate();
- bool is16 = smp->get_format()==Sample::FORMAT_PCM16;
- int chans = smp->is_stereo()?2:1;
- int len = smp->get_length();
- Sample::LoopFormat loop= smp->get_loop_format();
- int loop_beg = smp->get_loop_begin();
- int loop_end = smp->get_loop_end();
-
- print_line("Input Sample: ");
- print_line("\tlen: "+itos(len));
- print_line("\tchans: "+itos(chans));
- print_line("\t16bits: "+itos(is16));
- print_line("\trate: "+itos(rate));
- print_line("\tloop: "+itos(loop));
- print_line("\tloop begin: "+itos(loop_beg));
- print_line("\tloop end: "+itos(loop_end));
- Vector<float> data;
- data.resize(len*chans);
-
- {
- PoolVector<uint8_t> src_data = smp->get_data();
- PoolVector<uint8_t>::Read sr = src_data.read();
-
-
- for(int i=0;i<len*chans;i++) {
-
- float s=0;
- if (is16) {
-
- int16_t i16 = decode_uint16(&sr[i*2]);
- s=i16/32767.0;
- } else {
-
- int8_t i8 = sr[i];
- s=i8/127.0;
- }
- data[i]=s;
- }
- }
-
- //apply frequency limit
-
- bool limit_rate = from->get_option("force/max_rate");
- int limit_rate_hz = from->get_option("force/max_rate_hz");
- if (limit_rate && rate > limit_rate_hz) {
- //resampleeee!!!
- int new_data_len = len * limit_rate_hz / rate;
- Vector<float> new_data;
- new_data.resize( new_data_len * chans );
- for(int c=0;c<chans;c++) {
-
- for(int i=0;i<new_data_len;i++) {
-
- //simple cubic interpolation should be enough.
- float pos = float(i) * len / new_data_len;
- float mu = pos-Math::floor(pos);
- int ipos = int(Math::floor(pos));
-
- float y0=data[MAX(0,ipos-1)*chans+c];
- float y1=data[ipos*chans+c];
- float y2=data[MIN(len-1,ipos+1)*chans+c];
- float y3=data[MIN(len-1,ipos+2)*chans+c];
-
- float mu2 = mu*mu;
- float a0 = y3 - y2 - y0 + y1;
- float a1 = y0 - y1 - a0;
- float a2 = y2 - y0;
- float a3 = y1;
-
- float res=(a0*mu*mu2+a1*mu2+a2*mu+a3);
-
- new_data[i*chans+c]=res;
- }
- }
-
- if (loop) {
-
- loop_beg=loop_beg*new_data_len/len;
- loop_end=loop_end*new_data_len/len;
- }
- data=new_data;
- rate=limit_rate_hz;
- len=new_data_len;
- }
-
-
- bool normalize = from->get_option("edit/normalize");
-
- if (normalize) {
-
- float max=0;
- for(int i=0;i<data.size();i++) {
-
- float amp = Math::abs(data[i]);
- if (amp>max)
- max=amp;
- }
-
- if (max>0) {
-
- float mult=1.0/max;
- for(int i=0;i<data.size();i++) {
-
- data[i]*=mult;
- }
-
- }
- }
-
- bool trim = from->get_option("edit/trim");
-
- if (trim && !loop) {
-
- int first=0;
- int last=(len*chans)-1;
- bool found=false;
- float limit = Math::db2linear((float)-30);
- for(int i=0;i<data.size();i++) {
- float amp = Math::abs(data[i]);
-
- if (!found && amp > limit) {
- first=i;
- found=true;
- }
-
- if (found && amp > limit) {
- last=i;
- }
- }
-
- first/=chans;
- last/=chans;
-
- if (first<last) {
-
- Vector<float> new_data;
- new_data.resize((last-first+1)*chans);
- for(int i=first*chans;i<=last*chans;i++) {
- new_data[i-first*chans]=data[i];
- }
-
- data=new_data;
- len=data.size()/chans;
- }
-
- }
-
- bool make_loop = from->get_option("edit/loop");
-
- if (make_loop && !loop) {
-
- loop=Sample::LOOP_FORWARD;
- loop_beg=0;
- loop_end=len;
- }
-
- int compression = from->get_option("compress/mode");
- bool force_mono = from->get_option("force/mono");
-
-
- if (force_mono && chans==2) {
-
- Vector<float> new_data;
- new_data.resize(data.size()/2);
- for(int i=0;i<len;i++) {
- new_data[i]=(data[i*2+0]+data[i*2+1])/2.0;
- }
-
- data=new_data;
- chans=1;
- }
-
- bool force_8_bit = from->get_option("force/8_bit");
- if (force_8_bit) {
-
- is16=false;
- }
-
-
- PoolVector<uint8_t> dst_data;
- Sample::Format dst_format;
-
- if ( compression == _EditorSampleImportOptions::COMPRESS_MODE_RAM) {
-
- dst_format=Sample::FORMAT_IMA_ADPCM;
- if (chans==1) {
- _compress_ima_adpcm(data,dst_data);
- } else {
-
- print_line("INTERLEAAVE!");
-
-
-
- //byte interleave
- Vector<float> left;
- Vector<float> right;
-
- int tlen = data.size()/2;
- left.resize(tlen);
- right.resize(tlen);
-
- for(int i=0;i<tlen;i++) {
- left[i]=data[i*2+0];
- right[i]=data[i*2+1];
- }
-
- PoolVector<uint8_t> bleft;
- PoolVector<uint8_t> bright;
-
- _compress_ima_adpcm(left,bleft);
- _compress_ima_adpcm(right,bright);
-
- int dl = bleft.size();
- dst_data.resize( dl *2 );
-
- PoolVector<uint8_t>::Write w=dst_data.write();
- PoolVector<uint8_t>::Read rl=bleft.read();
- PoolVector<uint8_t>::Read rr=bright.read();
-
- for(int i=0;i<dl;i++) {
- w[i*2+0]=rl[i];
- w[i*2+1]=rr[i];
- }
- }
-
- //print_line("compressing ima-adpcm, resulting buffersize is "+itos(dst_data.size())+" from "+itos(data.size()));
-
- } else {
-
- dst_format=is16?Sample::FORMAT_PCM16:Sample::FORMAT_PCM8;
- dst_data.resize( data.size() * (is16?2:1));
- {
- PoolVector<uint8_t>::Write w = dst_data.write();
-
- int ds=data.size();
- for(int i=0;i<ds;i++) {
-
- if (is16) {
- int16_t v = CLAMP(data[i]*32767,-32768,32767);
- encode_uint16(v,&w[i*2]);
- } else {
- int8_t v = CLAMP(data[i]*127,-128,127);
- w[i]=v;
- }
- }
- }
- }
-
-
- Ref<Sample> target;
-
- if (ResourceCache::has(p_path)) {
-
- target = Ref<Sample>( Object::cast_to<Sample>(ResourceCache::get(p_path)) );
- } else {
-
- target = smp;
- }
-
- target->create(dst_format,chans==2?true:false,len);
- target->set_data(dst_data);
- target->set_mix_rate(rate);
- target->set_loop_format(loop);
- target->set_loop_begin(loop_beg);
- target->set_loop_end(loop_end);
-
- from->set_source_md5(0,FileAccess::get_md5(src_path));
- from->set_editor(get_name());
- target->set_import_metadata(from);
-
-
- Error err = ResourceSaver::save(p_path,smp);
-
- return err;
-
-}
-
-void EditorSampleImportPlugin::_compress_ima_adpcm(const Vector<float>& p_data,PoolVector<uint8_t>& dst_data) {
-
-
- /*p_sample_data->data = (void*)malloc(len);
- xm_s8 *dataptr=(xm_s8*)p_sample_data->data;*/
-
- 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
- };
-
-
- int datalen = p_data.size();
- int datamax=datalen;
- if (datalen&1)
- datalen++;
-
- dst_data.resize(datalen/2+4);
- PoolVector<uint8_t>::Write w = dst_data.write();
-
-
- int i,step_idx=0,prev=0;
- uint8_t *out = w.ptr();
- //int16_t xm_prev=0;
- const float *in=p_data.ptr();
-
-
- /* initial value is zero */
- *(out++) =0;
- *(out++) =0;
- /* Table index initial value */
- *(out++) =0;
- /* unused */
- *(out++) =0;
-
- for (i=0;i<datalen;i++) {
- int step,diff,vpdiff,mask;
- uint8_t nibble;
- int16_t xm_sample;
-
- if (i>=datamax)
- xm_sample=0;
- else {
-
-
- xm_sample=CLAMP(in[i]*32767.0,-32768,32767);
- /*
- if (xm_sample==32767 || xm_sample==-32768)
- printf("clippy!\n",xm_sample);
- */
- }
-
- //xm_sample=xm_sample+xm_prev;
- //xm_prev=xm_sample;
-
- diff = (int)xm_sample - prev ;
-
- nibble=0 ;
- step = _ima_adpcm_step_table[ step_idx ];
- vpdiff = step >> 3 ;
- if (diff < 0) {
- nibble=8;
- diff=-diff ;
- }
- mask = 4 ;
- while (mask) {
-
- if (diff >= step) {
-
- nibble |= mask;
- diff -= step;
- vpdiff += step;
- }
-
- step >>= 1 ;
- mask >>= 1 ;
- };
-
- if (nibble&8)
- prev-=vpdiff ;
- else
- prev+=vpdiff ;
-
- if (prev > 32767) {
- //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip up %i\n",i,xm_sample,prev,diff,vpdiff,prev);
- prev=32767;
- } else if (prev < -32768) {
- //printf("%i,xms %i, prev %i,diff %i, vpdiff %i, clip down %i\n",i,xm_sample,prev,diff,vpdiff,prev);
- prev = -32768 ;
- }
-
- step_idx += _ima_adpcm_index_table[nibble];
- if (step_idx< 0)
- step_idx= 0 ;
- else if (step_idx> 88)
- step_idx= 88 ;
-
-
- if (i&1) {
- *out|=nibble<<4;
- out++;
- } else {
- *out=nibble;
- }
- /*dataptr[i]=prev>>8;*/
- }
-
-}
-
-
-EditorSampleImportPlugin* EditorSampleImportPlugin::singleton=NULL;
-
-
-void EditorSampleImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
-
-
- Vector<String> files;
- for(int i=0;i<p_drop.size();i++) {
- String ext = p_drop[i].get_extension().to_lower();
-
- if (ext=="wav") {
-
- files.push_back(p_drop[i]);
- }
- }
-
- if (files.size()) {
- import_dialog();
- dialog->_choose_files(files);
- dialog->_choose_save_dir(p_dest_path);
- }
-}
-
-void EditorSampleImportPlugin::reimport_multiple_files(const Vector<String>& p_list) {
-
- if (p_list.size()==0)
- return;
-
- Vector<String> sources;
- for(int i=0;i<p_list.size();i++) {
- int idx;
- EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->find_file(p_list[i],&idx);
- if (efsd) {
- for(int j=0;j<efsd->get_source_count(idx);j++) {
- String file = expand_source_path(efsd->get_source_file(idx,j));
- if (sources.find(file)==-1) {
- sources.push_back(file);
- }
-
- }
- }
- }
-
- if (sources.size()) {
-
- dialog->popup_import(p_list[0]);
- dialog->_choose_files(sources);
- dialog->_choose_save_dir(p_list[0].get_base_dir());
- }
-}
-
-bool EditorSampleImportPlugin::can_reimport_multiple_files() const {
-
- return true;
-}
-
-EditorSampleImportPlugin::EditorSampleImportPlugin(EditorNode* p_editor) {
-
- singleton=this;
- dialog = memnew( EditorSampleImportDialog(this));
- p_editor->get_gui_base()->add_child(dialog);
-}
-
-Vector<uint8_t> EditorSampleExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) {
-
-
-
- if (EditorImportExport::get_singleton()->sample_get_action()==EditorImportExport::SAMPLE_ACTION_NONE || p_path.get_extension().to_lower()!="wav") {
-
- return Vector<uint8_t>();
- }
-
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
-
- imd->add_source(EditorImportPlugin::validate_source_path(p_path));
-
- imd->set_option("force/8_bit",false);
- imd->set_option("force/mono",false);
- imd->set_option("force/max_rate",true);
- imd->set_option("force/max_rate_hz",EditorImportExport::get_singleton()->sample_get_max_hz());
- imd->set_option("edit/trim",EditorImportExport::get_singleton()->sample_get_trim());
- imd->set_option("edit/normalize",false);
- imd->set_option("edit/loop",false);
- imd->set_option("compress/mode",1);
-
- String savepath = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/smpconv.sample");
- Error err = EditorSampleImportPlugin::singleton->import(savepath,imd);
-
-
- ERR_FAIL_COND_V(err!=OK,Vector<uint8_t>());
-
- p_path=p_path.get_basename()+".converted.sample";
- return FileAccess::get_file_as_array(savepath);
-
-}
-
-
-
-EditorSampleExportPlugin::EditorSampleExportPlugin() {
-
-}
-
-#endif
diff --git a/editor/io_plugins/editor_sample_import_plugin.h b/editor/io_plugins/editor_sample_import_plugin.h
deleted file mode 100644
index d9abdd50b2..0000000000
--- a/editor/io_plugins/editor_sample_import_plugin.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*************************************************************************/
-/* editor_sample_import_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 EDITOR_SAMPLE_IMPORT_PLUGIN_H
-#define EDITOR_SAMPLE_IMPORT_PLUGIN_H
-
-#if 0
-#include "editor/editor_import_export.h"
-#include "scene/resources/font.h"
-
-class EditorNode;
-class EditorSampleImportDialog;
-
-class EditorSampleImportPlugin : public EditorImportPlugin {
-
- GDCLASS(EditorSampleImportPlugin,EditorImportPlugin);
-
- EditorSampleImportDialog *dialog;
- void _compress_ima_adpcm(const Vector<float>& p_data,PoolVector<uint8_t>& dst_data);
-public:
-
- static EditorSampleImportPlugin *singleton;
-
- virtual String get_name() const;
- virtual String get_visible_name() const;
- virtual void import_dialog(const String& p_from="");
- virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
- void import_from_drop(const Vector<String>& p_drop, const String &p_dest_path);
- virtual void reimport_multiple_files(const Vector<String>& p_list);
- virtual bool can_reimport_multiple_files() const;
-
-
- EditorSampleImportPlugin(EditorNode* p_editor);
-};
-
-class EditorSampleExportPlugin : public EditorExportPlugin {
-
- GDCLASS( EditorSampleExportPlugin, EditorExportPlugin);
-
-
-public:
-
- virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
-
- EditorSampleExportPlugin();
-};
-
-#endif // EDITOR_SAMPLE_IMPORT_PLUGIN_H
-#endif
diff --git a/editor/io_plugins/editor_scene_import_plugin.cpp b/editor/io_plugins/editor_scene_import_plugin.cpp
deleted file mode 100644
index e202fa1f0d..0000000000
--- a/editor/io_plugins/editor_scene_import_plugin.cpp
+++ /dev/null
@@ -1,2986 +0,0 @@
-/*************************************************************************/
-/* editor_scene_import_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 "editor_scene_import_plugin.h"
-#if 0
-#include "editor/create_dialog.h"
-#include "editor/editor_node.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-#include "os/os.h"
-#include "project_settings.h"
-#include "scene/3d/body_shape.h"
-#include "scene/3d/mesh_instance.h"
-#include "scene/3d/navigation.h"
-#include "scene/3d/path.h"
-#include "scene/3d/physics_body.h"
-#include "scene/3d/portal.h"
-#include "scene/3d/room_instance.h"
-#include "scene/3d/vehicle_body.h"
-#include "scene/animation/animation_player.h"
-#include "scene/resources/box_shape.h"
-#include "scene/resources/packed_scene.h"
-#include "scene/resources/sphere_shape.h"
-#include <scene/resources/box_shape.h>
-#include <scene/resources/plane_shape.h>
-#include <scene/resources/ray_shape.h>
-
-
-
-
-EditorSceneImporter::EditorSceneImporter() {
-
-
-}
-
-void EditorScenePostImport::_bind_methods() {
-
- BIND_VMETHOD( MethodInfo("post_import",PropertyInfo(Variant::OBJECT,"scene")) );
-
-}
-
-Node *EditorScenePostImport::post_import(Node* p_scene) {
-
- if (get_script_instance())
- return get_script_instance()->call("post_import",p_scene);
-
- return p_scene;
-}
-
-EditorScenePostImport::EditorScenePostImport() {
-
-
-}
-
-
-/////////////////////////////
-
-
-class EditorImportAnimationOptions : public VBoxContainer {
-
- GDCLASS( EditorImportAnimationOptions, VBoxContainer );
-
-
-
- TreeItem *fps;
- TreeItem* optimize_linear_error;
- TreeItem* optimize_angular_error;
- TreeItem* optimize_max_angle;
-
- TreeItem *clips_base;
-
- TextEdit *filters;
- Vector<TreeItem*> clips;
-
- Tree *flags;
- Tree *clips_tree;
- Tree *optimization_tree;
- Vector<TreeItem*> items;
-
-
- bool updating;
- bool validating;
-
-
-
- void _changed();
- void _item_edited();
- void _button_action(Object *p_obj,int p_col,int p_id);
-
-protected:
- static void _bind_methods();
- void _notification(int p_what);
-
-public:
-
- void set_flags(uint32_t p_flags);
- uint32_t get_flags() const;
-
- void set_fps(int p_fps);
- int get_fps() const;
-
- void set_optimize_linear_error(float p_error);
- float get_optimize_linear_error() const;
-
- void set_optimize_angular_error(float p_error);
- float get_optimize_angular_error() const;
-
- void set_optimize_max_angle(float p_error);
- float get_optimize_max_angle() const;
-
- void setup_clips(const Array& p_clips);
- Array get_clips() const;
-
- void set_filter(const String& p_filter);
- String get_filter() const;
-
- EditorImportAnimationOptions();
-
-
-};
-
-////////////////////////////
-
-class EditorSceneImportDialog : public ConfirmationDialog {
-
- GDCLASS(EditorSceneImportDialog,ConfirmationDialog);
-
-
- struct FlagInfo {
- int value;
- const char *category;
- const char *text;
- bool defval;
- };
-
- static const FlagInfo scene_flag_names[];
-
- EditorImportTextureOptions *texture_options;
- EditorImportAnimationOptions *animation_options;
-
- EditorSceneImportPlugin *plugin;
-
- EditorNode *editor;
-
- LineEdit *import_path;
- LineEdit *save_path;
- LineEdit *script_path;
- Tree *import_options;
- EditorFileDialog *file_select;
- EditorFileDialog *script_select;
- EditorDirDialog *save_select;
- OptionButton *texture_action;
- CreateDialog *root_type_choose;
- LineEdit *root_node_name;
-
- ConfirmationDialog *confirm_open;
-
- ConfirmationDialog *confirm_import;
- RichTextLabel *missing_files;
-
- Vector<TreeItem*> scene_flags;
-
- Map<Ref<Mesh>,Ref<Shape> > collision_map;
- ConfirmationDialog *error_dialog;
-
- Button *root_type;
- CheckBox *root_default;
-
-
- void _root_default_pressed();
- void _root_type_pressed();
- void _set_root_type();
-
- void _choose_file(const String& p_path);
- void _choose_save_file(const String& p_path);
- void _choose_script(const String& p_path);
- void _browse();
- void _browse_target();
- void _browse_script();
- void _import(bool p_and_open=false);
- void _import_confirm();
-
- Ref<ResourceImportMetadata> wip_rimd;
- Node *wip_import;
- String wip_save_file;
- bool wip_blocked;
- bool wip_open;
-
- void _dialog_hid();
- void _open_and_import();
-
-
-protected:
-
- void _notification(int p_what);
- static void _bind_methods();
-public:
-
- void setup_popup(const String& p_from,const String& p_to_path) {
- _choose_file(p_from);
- _choose_save_file(p_to_path);
- }
-
- Error import(const String& p_from, const String& p_to, const String& p_preset);
- void popup_import(const String& p_from);
- EditorSceneImportDialog(EditorNode *p_editor,EditorSceneImportPlugin *p_plugin);
-};
-
-///////////////////////////////////
-
-
-static const char *anim_flag_names[]={
- "Detect Loop (-loop,-cycle)",
- "Keep Value Tracks",
- "Optimize",
- "Force All Tracks in All Clips",
- NULL
-};
-
-static const char *anim_flag_descript[]={
- "Set loop flag for animation names that\ncontain 'cycle' or 'loop' in the name.",
- "When merging an existing aimation,\nkeep the user-created value-tracks.",
- "Remove redundant keyframes in\n transform tacks.",
- "Some exporters will rely on default pose for some bones.\nThis forces those bones to have at least one animation key.",
- NULL
-};
-
-
-
-void EditorImportAnimationOptions::set_flags(uint32_t p_flags){
-
- updating=true;
- for(int i=0;i<items.size();i++) {
-
- items[i]->set_checked(0,p_flags&(1<<i));
- }
- updating=false;
-
-}
-uint32_t EditorImportAnimationOptions::get_flags() const{
-
- uint32_t f=0;
- for(int i=0;i<items.size();i++) {
-
- if (items[i]->is_checked(0))
- f|=(1<<i);
- }
-
- return f;
-}
-
-
-void EditorImportAnimationOptions::_changed() {
-
- if (updating)
- return;
- emit_signal("changed");
-}
-
-
-void EditorImportAnimationOptions::_button_action(Object *p_obj,int p_col,int p_id) {
-
- memdelete(p_obj);
-
-}
-
-
-void EditorImportAnimationOptions::_item_edited() {
-
- if (validating)
- return;
-
- if (clips.size()==0)
- return;
- validating=true;
- print_line("edited");
- TreeItem *item = clips_tree->get_edited();
- if (item==clips[clips.size()-1]) {
- //add new
- print_line("islast");
- if (item->get_text(0).find("<")!=-1 || item->get_text(0).find(">")!=-1) {
- validating=false;
- return; //fuckit
- }
-
- item->set_editable(1,true);
- item->set_editable(2,true);
- item->add_button(0,EditorNode::get_singleton()->get_gui_base()->get_icon("Del","EditorIcons"));
- item->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
- item->set_range_config(1,0,3600,0.01);
- item->set_range(1,0);
- item->set_editable(1,true);
- item->set_cell_mode(2,TreeItem::CELL_MODE_RANGE);
- item->set_range_config(2,0,3600,0.01);
- item->set_range(2,0);
- item->set_cell_mode(3,TreeItem::CELL_MODE_CHECK);
- item->set_editable(3,true);
-
- TreeItem *newclip = clips_tree->create_item(clips_base);
- newclip->set_text(0,"<new clip>");
- newclip->set_editable(0,true);
- newclip->set_editable(1,false);
- newclip->set_editable(2,false);
- clips.push_back(newclip);
-
-
-
- }
-
-
- //make name unique JUST IN CASE
- String name = item->get_text(0);
- name=name.replace("/","_").replace(":","_").strip_edges();
- if (name=="")
- name=TTR("New Clip");
-
- if (clips.size()>2) {
- int index=1;
- while(true) {
- bool valid = true;
- String try_name=name;
- if (index>1)
- try_name+=" "+itos(index);
-
- for(int i=0;i<clips.size()-1;i++) {
-
- if (clips[i]==item)
- continue;
- if (clips[i]->get_text(0)==try_name) {
- index++;
- valid=false;
- break;
- }
- }
-
- if (valid) {
- name=try_name;
- break;
- }
-
- }
- }
-
- if (item->get_text(0)!=name)
- item->set_text(0,name);
-
- validating=false;
-
-}
-
-void EditorImportAnimationOptions::_bind_methods() {
-
- ClassDB::bind_method("_changed",&EditorImportAnimationOptions::_changed);
- ClassDB::bind_method("_item_edited",&EditorImportAnimationOptions::_item_edited);
- ClassDB::bind_method("_button_action",&EditorImportAnimationOptions::_button_action);
- //ClassDB::bind_method("_changedp",&EditorImportAnimationOptions::_changedp);
-
- ADD_SIGNAL(MethodInfo("changed"));
-}
-
-
-void EditorImportAnimationOptions::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
-
- flags->connect("item_edited",this,"_changed");
- clips_tree->connect("item_edited",this,"_item_edited");
- clips_tree->connect("button_pressed",this,"_button_action",varray(),CONNECT_DEFERRED);
- //format->connect("item_selected",this,"_changedp");
- }
-}
-
-
-Array EditorImportAnimationOptions::get_clips() const {
-
- Array arr;
- for(int i=0;i<clips.size()-1;i++) {
-
- arr.push_back(clips[i]->get_text(0));
- arr.push_back(clips[i]->get_range(1));
- arr.push_back(clips[i]->get_range(2));
- arr.push_back(clips[i]->is_checked(3));
- }
-
- return arr;
-}
-
-
-void EditorImportAnimationOptions::setup_clips(const Array& p_clips) {
-
- ERR_FAIL_COND(p_clips.size()%4!=0);
- for(int i=0;i<clips.size();i++) {
-
- memdelete(clips[i]);
- }
-
-
- clips.clear();
-
- for(int i=0;i<p_clips.size();i+=4) {
-
- TreeItem *clip = clips_tree->create_item(clips_base);
- clip->set_text(0,p_clips[i]);
- clip->add_button(0,EditorNode::get_singleton()->get_gui_base()->get_icon("Del","EditorIcons"));
- clip->set_editable(0,true);
- clip->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
- clip->set_range_config(1,0,3600,0.01);
- clip->set_range(1,p_clips[i+1]);
- clip->set_editable(1,true);
- clip->set_cell_mode(2,TreeItem::CELL_MODE_RANGE);
- clip->set_range_config(2,0,3600,0.01);
- clip->set_range(2,p_clips[i+2]);
- clip->set_editable(2,true);
- clip->set_cell_mode(3,TreeItem::CELL_MODE_CHECK);
- clip->set_editable(3,true);
- clip->set_checked(3,p_clips[i+3]);
- clips.push_back(clip);
-
- }
-
- TreeItem *newclip = clips_tree->create_item(clips_base);
- newclip->set_text(0,"<new clip>");
- newclip->set_editable(0,true);
- newclip->set_editable(1,false);
- newclip->set_editable(2,false);
- newclip->set_editable(3,false);
- clips.push_back(newclip);
-
-}
-
-
-EditorImportAnimationOptions::EditorImportAnimationOptions() {
-
-
- updating=false;
- validating=false;
-
- TabContainer *tab= memnew(TabContainer);
- add_margin_child(TTR("Animation Options"),tab,true);
-
- flags = memnew( Tree );
- flags->set_hide_root(true);
- tab->add_child(flags);
- flags->set_name(TTR("Flags"));
- TreeItem *root = flags->create_item();
-
- const char ** fname=anim_flag_names;
- const char ** fdescr=anim_flag_descript;
-
- while( *fname ) {
-
- TreeItem*ti = flags->create_item(root);
- ti->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
- ti->set_text(0,*fname);
- ti->set_editable(0,true);
- ti->set_tooltip(0,*fdescr);
- items.push_back(ti);
- fname++;
- fdescr++;
- }
-
-
- TreeItem *fps_base = flags->create_item(root);
- fps_base->set_text(0,TTR("Bake FPS:"));
- fps_base->set_editable(0,false);
- fps = flags->create_item(fps_base);
- fps->set_cell_mode(0,TreeItem::CELL_MODE_RANGE);
- fps->set_editable(0,true);
- fps->set_range_config(0,1,120,1);
- fps->set_range(0,15);
-
- optimization_tree = memnew( Tree );
- optimization_tree->set_columns(2);
- tab->add_child(optimization_tree);
- optimization_tree->set_name(TTR("Optimizer"));
- optimization_tree->set_column_expand(0,true);
- optimization_tree->set_column_expand(1,false);
- optimization_tree->set_column_min_width(1,80);
- optimization_tree->set_hide_root(true);
-
-
- TreeItem *optimize_root = optimization_tree->create_item();
-
- optimize_linear_error = optimization_tree->create_item(optimize_root);
- optimize_linear_error->set_text(0,TTR("Max Linear Error"));
- optimize_linear_error->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
- optimize_linear_error->set_editable(1,true);
- optimize_linear_error->set_range_config(1,0,1,0.001);
- optimize_linear_error->set_range(1,0.05);
-
- optimize_angular_error = optimization_tree->create_item(optimize_root);
- optimize_angular_error->set_text(0,TTR("Max Angular Error"));
- optimize_angular_error->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
- optimize_angular_error->set_editable(1,true);
- optimize_angular_error->set_range_config(1,0,1,0.001);
- optimize_angular_error->set_range(1,0.01);
-
- optimize_max_angle = optimization_tree->create_item(optimize_root);
- optimize_max_angle->set_text(0,TTR("Max Angle"));
- optimize_max_angle->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
- optimize_max_angle->set_editable(1,true);
- optimize_max_angle->set_range_config(1,0,360,0.001);
- optimize_max_angle->set_range(1,int(180*0.125));
-
- clips_tree = memnew( Tree );
- clips_tree->set_hide_root(true);
- tab->add_child(clips_tree);
- clips_tree->set_name(TTR("Clips"));
-
- clips_tree->set_columns(4);
- clips_tree->set_column_expand(0,1);
- clips_tree->set_column_expand(1,0);
- clips_tree->set_column_expand(2,0);
- clips_tree->set_column_expand(3,0);
- clips_tree->set_column_min_width(1,60);
- clips_tree->set_column_min_width(2,60);
- clips_tree->set_column_min_width(3,40);
- clips_tree->set_column_titles_visible(true);
- clips_tree->set_column_title(0,TTR("Name"));
- clips_tree->set_column_title(1,TTR("Start(s)"));
- clips_tree->set_column_title(2,TTR("End(s)"));
- clips_tree->set_column_title(3,TTR("Loop"));
- clips_base =clips_tree->create_item(0);
-
-
- setup_clips(Array());
-
-
- filters = memnew( TextEdit );
- tab->add_child(filters);
- filters->set_name(TTR("Filters"));
-}
-
-
-
-void EditorImportAnimationOptions::set_fps(int p_fps) {
-
- fps->set_range(0,p_fps);
-}
-
-int EditorImportAnimationOptions::get_fps() const {
-
- return fps->get_range(0);
-}
-
-
-void EditorImportAnimationOptions::set_optimize_linear_error(float p_optimize_linear_error) {
-
- optimize_linear_error->set_range(1,p_optimize_linear_error);
-}
-
-float EditorImportAnimationOptions::get_optimize_linear_error() const {
-
- return optimize_linear_error->get_range(1);
-}
-
-void EditorImportAnimationOptions::set_optimize_angular_error(float p_optimize_angular_error) {
-
- optimize_angular_error->set_range(1,p_optimize_angular_error);
-}
-
-float EditorImportAnimationOptions::get_optimize_angular_error() const {
-
- return optimize_angular_error->get_range(1);
-}
-
-void EditorImportAnimationOptions::set_optimize_max_angle(float p_optimize_max_angle) {
-
- optimize_max_angle->set_range(1,p_optimize_max_angle);
-}
-
-float EditorImportAnimationOptions::get_optimize_max_angle() const {
-
- return optimize_max_angle->get_range(1);
-}
-
-
-void EditorImportAnimationOptions::set_filter(const String& p_filter) {
-
- filters->set_text(p_filter);
-}
-
-String EditorImportAnimationOptions::get_filter() const {
-
- return filters->get_text();
-}
-
-
-
-
-
-////////////////////////////////////////////////////////
-
-
-
-void EditorSceneImportDialog::_choose_file(const String& p_path) {
-#if 0
- StringName sn = EditorImportDB::get_singleton()->find_source_path(p_path);
- if (sn!=StringName()) {
-
- EditorImportDB::ImportScene isc;
- if (EditorImportDB::get_singleton()->get_scene(sn,isc)==OK) {
-
- save_path->set_text(String(sn).get_base_dir());
- texture_options->set_flags( isc.image_flags );
- texture_options->set_quality( isc.image_quality );
- texture_options->set_format( isc.image_format );
- animation_options->set_flags( isc.anim_flags );
- script_path->set_text( isc.import_script );
- uint32_t f = isc.flags;
- for(int i=0;i<scene_flags.size();i++) {
-
- scene_flags[i]->set_checked(0,f&(1<<i));
- }
- }
- } else {
-#endif
- save_path->set_text("");
- root_node_name->set_text("");
- //save_path->set_text(p_path.get_file().basename()+".scn");
-#if 0
- }
-#endif
-
- if (p_path!=String()) {
-
- String from_path = EditorFileSystem::get_singleton()->find_resource_from_source(EditorImportPlugin::validate_source_path(p_path));
- print_line("from path.."+from_path);
- if (from_path!=String()) {
- popup_import(from_path);
-
- }
- }
-
-
- import_path->set_text(p_path);
- if (root_node_name->get_text().size()==0){
- root_node_name->set_text(import_path->get_text().get_file().get_basename());
- }
-
-}
-void EditorSceneImportDialog::_choose_save_file(const String& p_path) {
-
- save_path->set_text(p_path);
-}
-
-void EditorSceneImportDialog::_choose_script(const String& p_path) {
-
- String p = ProjectSettings::get_singleton()->localize_path(p_path);
- if (!p.is_resource_file())
- p=ProjectSettings::get_singleton()->get_resource_path().path_to(p_path.get_base_dir())+p_path.get_file();
- script_path->set_text(p);
-
-}
-
-
-void EditorSceneImportDialog::_open_and_import() {
-
- bool unsaved=EditorNode::has_unsaved_changes();
-
- if (unsaved) {
-
- confirm_open->popup_centered_minsize(Size2(300,80)*EDSCALE);
- } else {
- _import(true);
- }
-}
-
-void EditorSceneImportDialog::_import(bool p_and_open) {
-
- wip_open=p_and_open;
-//' ImportMonitorBlock imb;
-
-
- if (import_path->get_text().strip_edges()=="") {
- error_dialog->set_text(TTR("Source path is empty."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (save_path->get_text().strip_edges()=="") {
- error_dialog->set_text(TTR("Target path is empty."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (!save_path->get_text().begins_with("res://")) {
- error_dialog->set_text(TTR("Target path must be a complete resource path."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (!DirAccess::exists(save_path->get_text())) {
- error_dialog->set_text(TTR("Target path must exist."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- String dst_path;
-
- if (texture_action->get_selected()==0)
- dst_path=save_path->get_text();//.get_base_dir();
- else
- dst_path=ProjectSettings::get_singleton()->get("import/shared_textures");
-
- uint32_t flags=0;
-
- for(int i=0;i<scene_flags.size();i++) {
-
- if (scene_flags[i]->is_checked(0)) {
- int md = scene_flags[i]->get_metadata(0);
- flags|=md;
- }
- }
-
-
-
-
-
- if (script_path->get_text()!="") {
- Ref<Script> scr = ResourceLoader::load(script_path->get_text());
- if (!scr.is_valid()) {
- error_dialog->set_text(TTR("Couldn't load post-import script."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- Ref<EditorScenePostImport> pi = Ref<EditorScenePostImport>( memnew( EditorScenePostImport ) );
- pi->set_script(scr.get_ref_ptr());
- if (!pi->get_script_instance()) {
-
- error_dialog->set_text(TTR("Invalid/broken script for post-import."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- }
-
-
- // Scenes should always be imported as binary format since vertex data is large and would take
- // up a lot of space and time to load if imported as text format (GH-5778)
- String save_file = save_path->get_text().plus_file(import_path->get_text().get_file().get_basename()+".scn");
- print_line("Saving to: "+save_file);
-
-
-
-
-
- Node *scene=NULL;
-
-
- Ref<ResourceImportMetadata> rim = memnew( ResourceImportMetadata );
-
- rim->add_source(EditorImportPlugin::validate_source_path(import_path->get_text()));
- rim->set_option("flags",flags);
- print_line("GET FLAGS: "+itos(texture_options->get_flags()));
- rim->set_option("texture_flags",texture_options->get_flags());
- rim->set_option("texture_format",texture_options->get_format());
- rim->set_option("texture_quality",texture_options->get_quality());
- rim->set_option("animation_flags",animation_options->get_flags());
- rim->set_option("animation_bake_fps",animation_options->get_fps());
- rim->set_option("animation_optimizer_linear_error",animation_options->get_optimize_linear_error());
- rim->set_option("animation_optimizer_angular_error",animation_options->get_optimize_angular_error());
- rim->set_option("animation_optimizer_max_angle",animation_options->get_optimize_max_angle());
- rim->set_option("animation_filters",animation_options->get_filter());
- rim->set_option("animation_clips",animation_options->get_clips());
- rim->set_option("post_import_script",script_path->get_text());
- rim->set_option("reimport",true);
- if (!root_default->is_pressed()) {
- rim->set_option("root_type",root_type->get_text());
- }
- if (root_node_name->get_text().size()==0) {
- root_node_name->set_text(import_path->get_text().get_file().get_basename());
- }
- rim->set_option("root_name",root_node_name->get_text());
-
- List<String> missing;
- Error err = plugin->import1(rim,&scene,&missing);
-
- if (err || !scene) {
-
- error_dialog->set_text(TTR("Error importing scene."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- if (missing.size()) {
-
- missing_files->clear();
- for(List<String>::Element *E=missing.front();E;E=E->next()) {
-
- missing_files->add_text(E->get());
- missing_files->add_newline();
- }
- wip_import=scene;
- wip_rimd=rim;
- wip_save_file=save_file;
- confirm_import->popup_centered_ratio();
- return;
-
- } else {
-
- err = plugin->import2(scene,save_file,rim);
-
- if (err) {
-
- error_dialog->set_text(TTR("Error importing scene."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
- if (wip_open)
- EditorNode::get_singleton()->load_scene(save_file,false,false,false);
-
- }
-
- hide();
-
- /*
- editor->clear_scene();
-
- Error err = EditorImport::import_scene(import_path->get_text(),save_file,dst_path,flags,texture_options->get_format(),compression,texture_options->get_flags(),texture_options->get_quality(),animation_options->get_flags(), &scene,pi);
-
- if (err) {
-
- error_dialog->set_text("Error importing scene.");
- error_dialog->popup_centered(Size2(200,100));
- return;
- }
-
- editor->save_import_export();
- if (scene)
- editor->set_edited_scene(scene);
-
- hide();
- */
-};
-
-
-void EditorSceneImportDialog::_import_confirm() {
-
- wip_blocked=true;
- print_line("import confirm!");
- Error err = plugin->import2(wip_import,wip_save_file,wip_rimd);
- wip_blocked=false;
- wip_import=NULL;
- wip_rimd=Ref<ResourceImportMetadata>();
- confirm_import->hide();
- if (err) {
-
- wip_save_file="";
- error_dialog->set_text(TTR("Error importing scene."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- if (wip_open)
- EditorNode::get_singleton()->load_scene(wip_save_file,false,false,false);
- wip_open=false;
- wip_save_file="";
-
- hide();
-
-}
-
-
-void EditorSceneImportDialog::_browse() {
-
- file_select->popup_centered_ratio();
-}
-
-void EditorSceneImportDialog::_browse_target() {
-
- save_select->popup_centered_ratio();
- if (save_path->get_text()!="")
- save_select->set_current_path(save_path->get_text());
-
-}
-
-void EditorSceneImportDialog::_browse_script() {
-
- script_select->popup_centered_ratio();
-
-}
-
-void EditorSceneImportDialog::popup_import(const String &p_from) {
-
- popup_centered(Size2(750,550)*EDSCALE);
- if (p_from!="") {
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from);
- if (rimd.is_null())
- return;
-
- int flags = rimd->get_option("flags");
-
- for(int i=0;i<scene_flags.size();i++) {
-
- int md = scene_flags[i]->get_metadata(0);
- scene_flags[i]->set_checked(0,flags&md);
- }
-
- texture_options->set_flags(rimd->get_option("texture_flags"));
- texture_options->set_format(EditorTextureImportPlugin::ImageFormat(int(rimd->get_option("texture_format"))));
- texture_options->set_quality(rimd->get_option("texture_quality"));
- animation_options->set_flags(rimd->get_option("animation_flags"));
- if (rimd->has_option("animation_clips"))
- animation_options->setup_clips(rimd->get_option("animation_clips"));
- if (rimd->has_option("animation_filters"))
- animation_options->set_filter(rimd->get_option("animation_filters"));
- if (rimd->has_option("animation_bake_fps"))
- animation_options->set_fps(rimd->get_option("animation_bake_fps"));
- if (rimd->has_option("animation_optimizer_linear_error"))
- animation_options->set_optimize_linear_error(rimd->get_option("animation_optimizer_linear_error"));
- if (rimd->has_option("animation_optimizer_angular_error"))
- animation_options->set_optimize_angular_error(rimd->get_option("animation_optimizer_angular_error"));
- if (rimd->has_option("animation_optimizer_max_angle"))
- animation_options->set_optimize_max_angle(rimd->get_option("animation_optimizer_max_angle"));
-
- if (rimd->has_option("root_type")) {
- root_default->set_pressed(false);
- String type = rimd->get_option("root_type");
- root_type->set_text(type);
- root_type->set_disabled(false);
-
- if (has_icon(type,"EditorIcons")) {
- root_type->set_icon(get_icon(type,"EditorIcons"));
- } else {
- root_type->set_icon(get_icon("Object","EditorIcons"));
- }
-
- } else {
- root_default->set_pressed(true);
- root_type->set_disabled(true);
- }
- if (rimd->has_option("root_name")) {
- root_node_name->set_text(rimd->get_option("root_name"));
- } else {
- root_node_name->set_text(root_type->get_text()); // backward compatibility for 2.1 or before
- }
- script_path->set_text(rimd->get_option("post_import_script"));
-
- save_path->set_text(p_from.get_base_dir());
- import_path->set_text(EditorImportPlugin::expand_source_path(rimd->get_source_path(0)));
-
- }
-}
-
-
-void EditorSceneImportDialog::_notification(int p_what) {
-
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
-
-
- List<String> extensions;
- file_select->clear_filters();
- root_type->set_icon(get_icon("Spatial","EditorIcons"));
- root_type->set_text("Spatial");
- root_type->set_disabled(true);
-
- for(int i=0;i<plugin->get_importers().size();i++) {
- plugin->get_importers()[i]->get_extensions(&extensions);
- }
-
-
- for(int i=0;i<extensions.size();i++) {
-
- file_select->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
- }
-
- extensions.clear();
-
- //EditorImport::get_import_extensions(&extensions)
- /* ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions);
- save_select->clear_filters();
- for(int i=0;i<extensions.size();i++) {
-
- save_select->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
- }*/
-
-
- }
-}
-
-Error EditorSceneImportDialog::import(const String& p_from, const String& p_to, const String& p_preset) {
-
- import_path->set_text(p_from);
- save_path->set_text(p_to);
- script_path->set_text(p_preset);
-
- _import();
-
-
-
- return OK;
-}
-
-void EditorSceneImportDialog::_dialog_hid() {
-
- if (wip_blocked)
- return;
- print_line("DIALOGHID!");
- if (wip_import) {
- memdelete(wip_import);
- wip_import=NULL;
- wip_save_file="";
- wip_rimd=Ref<ResourceImportMetadata>();
- }
-}
-void EditorSceneImportDialog::_root_default_pressed() {
-
- root_type->set_disabled(root_default->is_pressed());
-}
-
-void EditorSceneImportDialog::_root_type_pressed() {
-
-
- root_type_choose->popup(false);
-}
-
-
-void EditorSceneImportDialog::_set_root_type() {
-
- String type = root_type_choose->get_selected_type();
- if (type==String())
- return;
- root_type->set_text(type);
- if (has_icon(type,"EditorIcons")) {
- root_type->set_icon(get_icon(type,"EditorIcons"));
- } else {
- root_type->set_icon(get_icon("Object","EditorIcons"));
- }
-}
-
-void EditorSceneImportDialog::_bind_methods() {
-
-
- ClassDB::bind_method("_choose_file",&EditorSceneImportDialog::_choose_file);
- ClassDB::bind_method("_choose_save_file",&EditorSceneImportDialog::_choose_save_file);
- ClassDB::bind_method("_choose_script",&EditorSceneImportDialog::_choose_script);
- ClassDB::bind_method("_import",&EditorSceneImportDialog::_import,DEFVAL(false));
- ClassDB::bind_method("_browse",&EditorSceneImportDialog::_browse);
- ClassDB::bind_method("_browse_target",&EditorSceneImportDialog::_browse_target);
- ClassDB::bind_method("_browse_script",&EditorSceneImportDialog::_browse_script);
- ClassDB::bind_method("_dialog_hid",&EditorSceneImportDialog::_dialog_hid);
- ClassDB::bind_method("_import_confirm",&EditorSceneImportDialog::_import_confirm);
- ClassDB::bind_method("_open_and_import",&EditorSceneImportDialog::_open_and_import);
- ClassDB::bind_method("_root_default_pressed",&EditorSceneImportDialog::_root_default_pressed);
- ClassDB::bind_method("_root_type_pressed",&EditorSceneImportDialog::_root_type_pressed);
- ClassDB::bind_method("_set_root_type",&EditorSceneImportDialog::_set_root_type);
-
-
- ADD_SIGNAL( MethodInfo("imported",PropertyInfo(Variant::OBJECT,"scene")) );
-}
-
-
-
-const EditorSceneImportDialog::FlagInfo EditorSceneImportDialog::scene_flag_names[]={
-
- {EditorSceneImportPlugin::SCENE_FLAG_REMOVE_NOIMP,("Actions"),"Remove Nodes (-noimp)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_IMPORT_ANIMATIONS,("Actions"),"Import Animations",true},
- {EditorSceneImportPlugin::SCENE_FLAG_COMPRESS_GEOMETRY,("Actions"),"Compress Geometry",false},
- {EditorSceneImportPlugin::SCENE_FLAG_GENERATE_TANGENT_ARRAYS,("Actions"),"Force Generation of Tangent Arrays",false},
- {EditorSceneImportPlugin::SCENE_FLAG_LINEARIZE_DIFFUSE_TEXTURES,("Actions"),"SRGB->Linear Of Diffuse Textures",false},
- {EditorSceneImportPlugin::SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY,("Actions"),"Convert Normal Maps to XY",true},
- {EditorSceneImportPlugin::SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS,("Actions"),"Set Material Lightmap to UV2 if Tex2Array Exists",true},
- {EditorSceneImportPlugin::SCENE_FLAG_MERGE_KEEP_MATERIALS,("Merge"),"Keep Materials after first import (delete them for re-import).",true},
- {EditorSceneImportPlugin::SCENE_FLAG_MERGE_KEEP_EXTRA_ANIM_TRACKS,("Merge"),"Keep user-added Animation tracks.",true},
- {EditorSceneImportPlugin::SCENE_FLAG_DETECT_ALPHA,("Materials"),"Set Alpha in Materials (-alpha)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_DETECT_VCOLOR,("Materials"),"Set Vert. Color in Materials (-vcol)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_COLLISIONS,("Create"),"Create Collisions and/or Rigid Bodies (-col,-colonly,-rigid,-rigidonly)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_PORTALS,("Create"),"Create Portals (-portal)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_ROOMS,("Create"),"Create Rooms (-room)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_SIMPLIFY_ROOMS,("Create"),"Simplify Rooms",false},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_BILLBOARDS,("Create"),"Create Billboards (-bb)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_IMPOSTORS,("Create"),"Create Impostors (-imp:dist)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_LODS,("Create"),"Create LODs (-lod:dist)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_CARS,("Create"),"Create Vehicles (-vehicle)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_WHEELS,("Create"),"Create Vehicle Wheels (-wheel)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_CREATE_NAVMESH,("Create"),"Create Navigation Meshes (-navmesh)",true},
- {EditorSceneImportPlugin::SCENE_FLAG_DETECT_LIGHTMAP_LAYER,("Create"),"Detect LightMap Layer (-lm:<int>).",true},
- {-1,NULL,NULL,false}
-};
-
-
-EditorSceneImportDialog::EditorSceneImportDialog(EditorNode *p_editor, EditorSceneImportPlugin *p_plugin) {
-
-
- editor=p_editor;
- plugin=p_plugin;
-
- set_title(TTR("Import 3D Scene"));
- HBoxContainer *import_hb = memnew( HBoxContainer );
- add_child(import_hb);
- //set_child_rect(import_hb);
-
- VBoxContainer *vbc = memnew( VBoxContainer );
- import_hb->add_child(vbc);
- vbc->set_h_size_flags(SIZE_EXPAND_FILL);
-
- HBoxContainer *hbc = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Source Scene:"),hbc);
-
- import_path = memnew( LineEdit );
- import_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(import_path);
-
- Button * import_choose = memnew( Button );
- import_choose->set_text(" .. ");
- hbc->add_child(import_choose);
-
- import_choose->connect("pressed", this,"_browse");
-
- hbc = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Target Path:"),hbc);
-
- save_path = memnew( LineEdit );
- save_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(save_path);
-
- Button * save_choose = memnew( Button );
- save_choose->set_text(" .. ");
- hbc->add_child(save_choose);
-
- save_choose->connect("pressed", this,"_browse_target");
-
- texture_action = memnew( OptionButton );
- texture_action->add_item(TTR("Same as Target Scene"));
- texture_action->add_item(TTR("Shared"));
- texture_action->select(0);
- vbc->add_margin_child(TTR("Target Texture Folder:"),texture_action);
-
- import_options = memnew( Tree );
- vbc->set_v_size_flags(SIZE_EXPAND_FILL);
- vbc->add_margin_child(TTR("Options:"),import_options,true);
-
- file_select = memnew(EditorFileDialog);
- file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
- add_child(file_select);
-
-
- file_select->set_mode(EditorFileDialog::MODE_OPEN_FILE);
-
- file_select->connect("file_selected", this,"_choose_file");
-
- save_select = memnew(EditorDirDialog);
- add_child(save_select);
-
- //save_select->set_mode(EditorFileDialog::MODE_SAVE_FILE);
- save_select->connect("dir_selected", this,"_choose_save_file");
-
- get_ok()->connect("pressed", this,"_import");
- get_ok()->set_text(TTR("Import"));
-
- TreeItem *root = import_options->create_item(NULL);
- import_options->set_hide_root(true);
-
- const FlagInfo* fn=scene_flag_names;
-
- Map<String,TreeItem*> categories;
-
- while(fn->text) {
-
- String cat = fn->category;
- TreeItem *parent;
- if (!categories.has(cat)) {
- parent = import_options->create_item(root);
- parent->set_text(0,cat);
- categories[cat]=parent;
- } else {
- parent=categories[cat];
- }
-
- TreeItem *opt = import_options->create_item(parent);
- opt->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
- opt->set_checked(0,fn->defval);
- opt->set_editable(0,true);
- opt->set_text(0,fn->text);
- opt->set_metadata(0,fn->value);
-
- scene_flags.push_back(opt);
- fn++;
- }
-
- hbc = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Post-Process Script:"),hbc);
-
- script_path = memnew( LineEdit );
- script_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(script_path);
-
- Button * script_choose = memnew( Button );
- script_choose->set_text(" .. ");
- hbc->add_child(script_choose);
-
- script_choose->connect("pressed", this,"_browse_script");
-
- script_select = memnew(EditorFileDialog);
- add_child(script_select);
- for(int i=0;i<ScriptServer::get_language_count();i++) {
-
- ScriptLanguage *sl=ScriptServer::get_language(i);
- String ext = sl->get_extension();
- if (ext=="")
- continue;
- script_select->add_filter("*."+ext+" ; "+sl->get_name());
- }
-
-
- script_select->set_mode(EditorFileDialog::MODE_OPEN_FILE);
-
- script_select->connect("file_selected", this,"_choose_script");
-
- error_dialog = memnew ( ConfirmationDialog );
- add_child(error_dialog);
- error_dialog->get_ok()->set_text(TTR("Accept"));
- //error_dialog->get_cancel()->hide();
-
-
- HBoxContainer *custom_root_hb = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Custom Root Node Type:"),custom_root_hb);
- root_type = memnew(Button);
- root_type->set_h_size_flags(SIZE_EXPAND_FILL);
- root_type->set_text_align(Button::ALIGN_LEFT);
- root_type->connect("pressed",this,"_root_type_pressed");
- custom_root_hb->add_child(root_type);
-
- root_default = memnew(CheckBox);
- root_default->set_text(TTR("Auto"));
- root_default->set_pressed(true);
- root_default->connect("pressed",this,"_root_default_pressed");
- custom_root_hb->add_child(root_default);
-
- root_node_name = memnew( LineEdit );
- root_node_name->set_h_size_flags(SIZE_EXPAND_FILL);
- vbc->add_margin_child(TTR("Root Node Name:"),root_node_name);
- /*
- this_import = memnew( OptionButton );
- this_import->add_item("Overwrite Existing Scene");
- this_import->add_item("Overwrite Existing, Keep Materials");
- this_import->add_item("Keep Existing, Merge with New");
- this_import->add_item("Keep Existing, Ignore New");
- vbc->add_margin_child("This Time:",this_import);
-
- next_import = memnew( OptionButton );
- next_import->add_item("Overwrite Existing Scene");
- next_import->add_item("Overwrite Existing, Keep Materials");
- next_import->add_item("Keep Existing, Merge with New");
- next_import->add_item("Keep Existing, Ignore New");
- vbc->add_margin_child("Next Time:",next_import);
-*/
- set_hide_on_ok(false);
-
- GLOBAL_DEF("import/shared_textures","res://");
- ProjectSettings::get_singleton()->set_custom_property_info("import/shared_textures",PropertyInfo(Variant::STRING,"import/shared_textures",PROPERTY_HINT_DIR));
-
- import_hb->add_constant_override("separation",30);
-
-
- VBoxContainer *ovb = memnew( VBoxContainer);
- ovb->set_h_size_flags(SIZE_EXPAND_FILL);
- import_hb->add_child(ovb);
-
- texture_options = memnew( EditorImportTextureOptions );
- ovb->add_child(texture_options);
- texture_options->set_v_size_flags(SIZE_EXPAND_FILL);
- //animation_options->set_flags(EditorImport::
- texture_options->set_format(EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM);
- texture_options->set_flags( EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA | EditorTextureImportPlugin::IMAGE_FLAG_REPEAT | EditorTextureImportPlugin::IMAGE_FLAG_FILTER );
-
-
- animation_options = memnew( EditorImportAnimationOptions );
- ovb->add_child(animation_options);
- animation_options->set_v_size_flags(SIZE_EXPAND_FILL);
- animation_options->set_flags(EditorSceneAnimationImportPlugin::ANIMATION_DETECT_LOOP|EditorSceneAnimationImportPlugin::ANIMATION_KEEP_VALUE_TRACKS|EditorSceneAnimationImportPlugin::ANIMATION_OPTIMIZE|EditorSceneAnimationImportPlugin::ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS);
-
-
- confirm_import = memnew( ConfirmationDialog );
- add_child(confirm_import);
- VBoxContainer *cvb = memnew( VBoxContainer );
- confirm_import->add_child(cvb);
- //confirm_import->set_child_rect(cvb);
-
- PanelContainer *pc = memnew( PanelContainer );
- pc->add_style_override("panel", EditorNode::get_singleton()->get_gui_base()->get_stylebox("normal","TextEdit"));
- //ec->add_child(pc);
- missing_files = memnew( RichTextLabel );
- cvb->add_margin_child(TTR("The Following Files are Missing:"),pc,true);
- pc->add_child(missing_files);
- confirm_import->get_ok()->set_text(TTR("Import Anyway"));
- confirm_import->get_cancel()->set_text(TTR("Cancel"));
- confirm_import->connect("popup_hide",this,"_dialog_hid");
- confirm_import->connect("confirmed",this,"_import_confirm");
- confirm_import->set_hide_on_ok(false);
-
- add_button(TTR("Import & Open"),!OS::get_singleton()->get_swap_ok_cancel())->connect("pressed",this,"_open_and_import");
-
- confirm_open = memnew( ConfirmationDialog );
- add_child(confirm_open);
- confirm_open->set_text(TTR("Edited scene has not been saved, open imported scene anyway?"));
- confirm_open->connect("confirmed",this,"_import",varray(true));
-
-
- wip_import=NULL;
- wip_blocked=false;
- wip_open=false;
- //texture_options->set_format(EditorImport::IMAGE_FORMAT_C);
-
- root_type_choose = memnew( CreateDialog );
- add_child(root_type_choose);
- root_type_choose->set_base_type("Node");
- root_type_choose->connect("create",this,"_set_root_type");
-}
-
-
-
-////////////////////////////////
-
-
-
-String EditorSceneImportPlugin::get_name() const {
-
- return "scene_3d";
-}
-
-String EditorSceneImportPlugin::get_visible_name() const{
-
- return TTR("Scene");
-}
-
-void EditorSceneImportPlugin::import_dialog(const String& p_from){
-
- dialog->popup_import(p_from);
-}
-
-
-//////////////////////////
-
-
-static bool _teststr(const String& p_what,const String& p_str) {
-
- if (p_what.findn("$"+p_str)!=-1) //blender and other stuff
- return true;
- if (p_what.to_lower().ends_with("-"+p_str)) //collada only supports "_" and "-" besides letters
- return true;
- if (p_what.to_lower().ends_with("_"+p_str)) //collada only supports "_" and "-" besides letters
- return true;
- return false;
-}
-
-static String _fixstr(const String& p_what,const String& p_str) {
-
- if (p_what.findn("$"+p_str)!=-1) //blender and other stuff
- return p_what.replace("$"+p_str,"");
- if (p_what.to_lower().ends_with("-"+p_str)) //collada only supports "_" and "-" besides letters
- return p_what.substr(0,p_what.length()-(p_str.length()+1));
- if (p_what.to_lower().ends_with("_"+p_str)) //collada only supports "_" and "-" besides letters
- return p_what.substr(0,p_what.length()-(p_str.length()+1));
- return p_what;
-}
-
-
-
-void EditorSceneImportPlugin::_find_resources(const Variant& p_var, Map<Ref<ImageTexture>, TextureRole> &image_map,int p_flags) {
-
-
- switch(p_var.get_type()) {
-
- case Variant::OBJECT: {
-
- Ref<Resource> res = p_var;
- if (res.is_valid()) {
-
- if (res->is_class("Texture") && !image_map.has(res)) {
-
- image_map.insert(res,TEXTURE_ROLE_DEFAULT);
-
-
- } else {
-
-
- List<PropertyInfo> pl;
- res->get_property_list(&pl);
- for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
-
- if (E->get().type==Variant::OBJECT || E->get().type==Variant::ARRAY || E->get().type==Variant::DICTIONARY) {
- if (E->get().type==Variant::OBJECT && Object::cast_to<SpatialMaterial>(*res) && (E->get().name=="textures/diffuse" || E->get().name=="textures/detail" || E->get().name=="textures/emission")) {
-
- Ref<ImageTexture> tex =res->get(E->get().name);
- if (tex.is_valid()) {
-
- image_map.insert(tex,TEXTURE_ROLE_DIFFUSE);
- }
-
- } else if (E->get().type==Variant::OBJECT && Object::cast_to<SpatialMaterial>(*res) && (E->get().name=="textures/normal")) {
-
- Ref<ImageTexture> tex =res->get(E->get().name);
- if (tex.is_valid()) {
-
- image_map.insert(tex,TEXTURE_ROLE_NORMALMAP);
- /*
- if (p_flags&SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY)
- Object::cast_to<SpatialMaterial>(*res)->set_fixed_flag(SpatialMaterial::FLAG_USE_XY_NORMALMAP,true);
- */
- }
-
-
- } else {
- _find_resources(res->get(E->get().name),image_map,p_flags);
- }
- }
- }
-
- }
- }
-
- } break;
- case Variant::DICTIONARY: {
-
- Dictionary d= p_var;
-
- List<Variant> keys;
- d.get_key_list(&keys);
-
- for(List<Variant>::Element *E=keys.front();E;E=E->next()) {
-
-
- _find_resources(E->get(),image_map,p_flags);
- _find_resources(d[E->get()],image_map,p_flags);
-
- }
-
-
- } break;
- case Variant::ARRAY: {
-
- Array a = p_var;
- for(int i=0;i<a.size();i++) {
-
- _find_resources(a[i],image_map,p_flags);
- }
-
- } break;
- default: {}
-
- }
-
-}
-
-
-Node* EditorSceneImportPlugin::_fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>,Ref<Shape> > &collision_map,uint32_t p_flags,Map<Ref<ImageTexture>,TextureRole >& image_map) {
-
- // children first..
- for(int i=0;i<p_node->get_child_count();i++) {
-
-
- Node *r = _fix_node(p_node->get_child(i),p_root,collision_map,p_flags,image_map);
- if (!r) {
- print_line("was erased..");
- i--; //was erased
- }
- }
-
- String name = p_node->get_name();
-
- bool isroot = p_node==p_root;
-
-
- if (!isroot && p_flags&SCENE_FLAG_REMOVE_NOIMP && _teststr(name,"noimp")) {
-
- memdelete(p_node);
- return NULL;
- }
-
- {
-
- List<PropertyInfo> pl;
- p_node->get_property_list(&pl);
- for(List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
-
- if (E->get().type==Variant::OBJECT || E->get().type==Variant::ARRAY || E->get().type==Variant::DICTIONARY) {
- _find_resources(p_node->get(E->get().name),image_map,p_flags);
- }
- }
-
- }
-
-
-
-
- if (p_flags&SCENE_FLAG_CREATE_BILLBOARDS && Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- bool bb=false;
-
- if ((_teststr(name,"bb"))) {
- bb=true;
- } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"bb"))) {
- bb=true;
-
- }
-
- if (bb) {
- mi->set_flag(GeometryInstance::FLAG_BILLBOARD,true);
- if (mi->get_mesh().is_valid()) {
-
- Ref<Mesh> m = mi->get_mesh();
- for(int i=0;i<m->get_surface_count();i++) {
-
- Ref<SpatialMaterial> fm = m->surface_get_material(i);
- if (fm.is_valid()) {
- //fm->set_flag(Material::FLAG_UNSHADED,true);
- //fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- //fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
- //fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- }
- }
- }
- }
- }
-
-
- if (p_flags&(SCENE_FLAG_DETECT_ALPHA|SCENE_FLAG_DETECT_VCOLOR|SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS) && Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- Ref<Mesh> m = mi->get_mesh();
-
- if (m.is_valid()) {
-
- for(int i=0;i<m->get_surface_count();i++) {
-
- Ref<SpatialMaterial> mat = m->surface_get_material(i);
- if (!mat.is_valid())
- continue;
-
- if (p_flags&SCENE_FLAG_DETECT_ALPHA && _teststr(mat->get_name(),"alpha")) {
-
- //mat->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- //mat->set_name(_fixstr(mat->get_name(),"alpha"));
- }
- if (p_flags&SCENE_FLAG_DETECT_VCOLOR && _teststr(mat->get_name(),"vcol")) {
-
- //mat->set_fixed_flag(SpatialMaterial::FLAG_USE_COLOR_ARRAY,true);
- //mat->set_name(_fixstr(mat->get_name(),"vcol"));
- }
-
- if (p_flags&SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS && m->surface_get_format(i)&Mesh::ARRAY_FORMAT_TEX_UV2) {
- //mat->set_flag(Material::FLAG_LIGHTMAP_ON_UV2,true);
- }
-
- }
- }
- }
-
- if (p_flags&SCENE_FLAG_REMOVE_NOIMP && Object::cast_to<AnimationPlayer>(p_node)) {
- //remove animations referencing non-importable nodes
- AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node);
-
- List<StringName> anims;
- ap->get_animation_list(&anims);
- for(List<StringName>::Element *E=anims.front();E;E=E->next()) {
-
- Ref<Animation> anim=ap->get_animation(E->get());
- ERR_CONTINUE(anim.is_null());
- for(int i=0;i<anim->get_track_count();i++) {
- NodePath path = anim->track_get_path(i);
-
- for(int j=0;j<path.get_name_count();j++) {
- String node = path.get_name(j);
- if (_teststr(node,"noimp")) {
- anim->remove_track(i);
- i--;
- break;
- }
- }
- }
-
- }
- }
-
-
- if (p_flags&SCENE_FLAG_CREATE_IMPOSTORS && Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- String str;
-
- if ((_teststr(name,"imp"))) {
- str=name;
- } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"imp"))) {
- str=mi->get_mesh()->get_name();
-
- }
-
-
- if (Object::cast_to<MeshInstance>(p_node->get_parent())) {
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- MeshInstance *mip = Object::cast_to<MeshInstance>(p_node->get_parent());
- String d=str.substr(str.find("imp")+3,str.length());
- if (d!="") {
- if ((d[0]<'0' || d[0]>'9'))
- d=d.substr(1,d.length());
- if (d.length() && d[0]>='0' && d[0]<='9') {
- float dist = d.to_double();
- mi->set_flag(GeometryInstance::FLAG_BILLBOARD,true);
- mi->set_flag(GeometryInstance::FLAG_BILLBOARD_FIX_Y,true);
- //mi->set_draw_range_begin(dist);
- //mi->set_draw_range_end(100000);
-
- //mip->set_draw_range_begin(0);
- //mip->set_draw_range_end(dist);
-
- if (mi->get_mesh().is_valid()) {
-
- Ref<Mesh> m = mi->get_mesh();
- for(int i=0;i<m->get_surface_count();i++) {
-
- Ref<SpatialMaterial> fm = m->surface_get_material(i);
- if (fm.is_valid()) {
- //fm->set_flag(Material::FLAG_UNSHADED,true);
- //fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- //fm->set_depth_draw_mode(Material::DEPTH_DRAW_NEVER);
- //fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- }
- }
- }
- }
- }
- }
- }
-
- if (p_flags&SCENE_FLAG_CREATE_LODS && Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- String str;
-
- if ((_teststr(name,"lod"))) {
- str=name;
- } else if (mi->get_mesh().is_valid() && (_teststr(mi->get_mesh()->get_name(),"lod"))) {
- str=mi->get_mesh()->get_name();
-
- }
-
-
- if (Object::cast_to<MeshInstance>(p_node->get_parent())) {
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- MeshInstance *mip = Object::cast_to<MeshInstance>(p_node->get_parent());
- String d=str.substr(str.find("lod")+3,str.length());
- if (d!="") {
- if ((d[0]<'0' || d[0]>'9'))
- d=d.substr(1,d.length());
- if (d.length() && d[0]>='0' && d[0]<='9') {
- float dist = d.to_double();
- /// mi->set_draw_range_begin(dist);
- // mi->set_draw_range_end(100000);
-
- // mip->set_draw_range_begin(0);
- // mip->set_draw_range_end(dist);
-
- /*if (mi->get_mesh().is_valid()) {
-
- Ref<Mesh> m = mi->get_mesh();
- for(int i=0;i<m->get_surface_count();i++) {
-
- Ref<SpatialMaterial> fm = m->surface_get_material(i);
- if (fm.is_valid()) {
- fm->set_flag(Material::FLAG_UNSHADED,true);
- fm->set_flag(Material::FLAG_DOUBLE_SIDED,true);
- fm->set_hint(Material::HINT_NO_DEPTH_DRAW,true);
- fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- }
- }
- }*/
- }
- }
- }
- }
-
-
- if (p_flags&SCENE_FLAG_DETECT_LIGHTMAP_LAYER && _teststr(name,"lm") && Object::cast_to<MeshInstance>(p_node)) {
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- String str=name;
- int layer = str.substr(str.find("lm")+3,str.length()).to_int();
- //mi->set_baked_light_texture_id(layer);
- }
-
- bool is_rigid = _teststr(name, "rigidonly");
-
- if (p_flags & SCENE_FLAG_CREATE_COLLISIONS && (_teststr(name, "colonly") || is_rigid)) {
-
- if (isroot)
- return p_node;
-
- if (Object::cast_to<MeshInstance>(p_node) && !is_rigid) {
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- Node * col = mi->create_trimesh_collision_node();
- ERR_FAIL_COND_V(!col,NULL);
-
- col->set_name(_fixstr(name,"colonly"));
- Object::cast_to<Spatial>(col)->set_transform(mi->get_transform());
- p_node->replace_by(col);
- memdelete(p_node);
- p_node=col;
-
- StaticBody *sb = Object::cast_to<StaticBody>(col);
- CollisionShape *colshape = memnew( CollisionShape);
- colshape->set_shape(sb->get_shape(0));
- colshape->set_name("shape");
- sb->add_child(colshape);
- colshape->set_owner(p_node->get_owner());
- } else if (p_node->has_meta("empty_draw_type")) {
- String empty_draw_type = String(p_node->get_meta("empty_draw_type"));
- print_line(empty_draw_type);
- PhysicsBody *pb;
- if (is_rigid) {
- pb = memnew(RigidBody);
- pb->set_name(_fixstr(name, "rigidonly"));
- } else {
- pb = memnew(StaticBody);
- pb->set_name(_fixstr(name, "colonly"));
- }
- Object::cast_to<Spatial>(pb)->set_transform(Object::cast_to<Spatial>(p_node)->get_transform());
- p_node->replace_by(pb);
- memdelete(p_node);
- CollisionShape *colshape = memnew( CollisionShape);
- if (empty_draw_type == "CUBE") {
- BoxShape *boxShape = memnew( BoxShape);
- boxShape->set_extents(Vector3(1, 1, 1));
- colshape->set_shape(boxShape);
- colshape->set_name("BoxShape");
- } else if (empty_draw_type == "SINGLE_ARROW") {
- RayShape *rayShape = memnew( RayShape);
- rayShape->set_length(1);
- colshape->set_shape(rayShape);
- colshape->set_name("RayShape");
- Object::cast_to<Spatial>(pb)->rotate_x(Math_PI / 2);
- } else if (empty_draw_type == "IMAGE") {
- PlaneShape *planeShape = memnew( PlaneShape);
- colshape->set_shape(planeShape);
- colshape->set_name("PlaneShape");
- } else {
- SphereShape *sphereShape = memnew( SphereShape);
- sphereShape->set_radius(1);
- colshape->set_shape(sphereShape);
- colshape->set_name("SphereShape");
- }
- pb->add_child(colshape);
- colshape->set_owner(pb->get_owner());
- }
-
- } else if (p_flags&SCENE_FLAG_CREATE_COLLISIONS && _teststr(name,"rigid") && Object::cast_to<MeshInstance>(p_node)) {
-
- if (isroot)
- return p_node;
-
- // get mesh instance and bounding box
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- Rect3 aabb = mi->get_aabb();
-
- // create a new rigid body collision node
- RigidBody * rigid_body = memnew( RigidBody );
- Node * col = rigid_body;
- ERR_FAIL_COND_V(!col,NULL);
-
- // remove node name postfix
- col->set_name(_fixstr(name,"rigid"));
- // get mesh instance xform matrix to the rigid body collision node
- Object::cast_to<Spatial>(col)->set_transform(mi->get_transform());
- // save original node by duplicating it into a new instance and correcting the name
- Node * mesh = p_node->duplicate();
- mesh->set_name(_fixstr(name,"rigid"));
- // reset the xform matrix of the duplicated node so it can inherit parent node xform
- Object::cast_to<Spatial>(mesh)->set_transform(Transform(Basis()));
- // reparent the new mesh node to the rigid body collision node
- p_node->add_child(mesh);
- mesh->set_owner(p_node->get_owner());
- // replace the original node with the rigid body collision node
- p_node->replace_by(col);
- memdelete(p_node);
- p_node=col;
-
- // create an alias for the rigid body collision node
- RigidBody *rb = Object::cast_to<RigidBody>(col);
- // create a new Box collision shape and set the right extents
- Ref<BoxShape> shape = memnew( BoxShape );
- shape->set_extents(aabb.get_size() * 0.5);
- CollisionShape *colshape = memnew( CollisionShape);
- colshape->set_name("shape");
- colshape->set_shape(shape);
- // reparent the new collision shape to the rigid body collision node
- rb->add_child(colshape);
- colshape->set_owner(p_node->get_owner());
-
- } else if (p_flags&SCENE_FLAG_CREATE_COLLISIONS &&_teststr(name,"col") && Object::cast_to<MeshInstance>(p_node)) {
-
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- mi->set_name(_fixstr(name,"col"));
- Node *col= mi->create_trimesh_collision_node();
- ERR_FAIL_COND_V(!col,NULL);
-
- col->set_name("col");
- p_node->add_child(col);
-
- StaticBody *sb=Object::cast_to<StaticBody>(col);
- CollisionShape *colshape = memnew( CollisionShape);
- colshape->set_shape(sb->get_shape(0));
- colshape->set_name("shape");
- col->add_child(colshape);
- colshape->set_owner(p_node->get_owner());
- sb->set_owner(p_node->get_owner());
-
- } else if (p_flags&SCENE_FLAG_CREATE_NAVMESH &&_teststr(name,"navmesh") && Object::cast_to<MeshInstance>(p_node)) {
-
- if (isroot)
- return p_node;
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- Ref<Mesh> mesh=mi->get_mesh();
- ERR_FAIL_COND_V(mesh.is_null(),NULL);
- NavigationMeshInstance *nmi = memnew( NavigationMeshInstance );
-
-
- nmi->set_name(_fixstr(name,"navmesh"));
- Ref<NavigationMesh> nmesh = memnew( NavigationMesh);
- nmesh->create_from_mesh(mesh);
- nmi->set_navigation_mesh(nmesh);
- Object::cast_to<Spatial>(nmi)->set_transform(mi->get_transform());
- p_node->replace_by(nmi);
- memdelete(p_node);
- p_node=nmi;
- } else if (p_flags&SCENE_FLAG_CREATE_CARS &&_teststr(name,"vehicle")) {
-
- if (isroot)
- return p_node;
-
- Node *owner = p_node->get_owner();
- Spatial *s = Object::cast_to<Spatial>(p_node);
- VehicleBody *bv = memnew( VehicleBody );
- String n = _fixstr(p_node->get_name(),"vehicle");
- bv->set_name(n);
- p_node->replace_by(bv);
- p_node->set_name(n);
- bv->add_child(p_node);
- bv->set_owner(owner);
- p_node->set_owner(owner);
- bv->set_transform(s->get_transform());
- s->set_transform(Transform());
-
- p_node=bv;
-
-
- } else if (p_flags&SCENE_FLAG_CREATE_CARS &&_teststr(name,"wheel")) {
-
- if (isroot)
- return p_node;
-
- Node *owner = p_node->get_owner();
- Spatial *s = Object::cast_to<Spatial>(p_node);
- VehicleWheel *bv = memnew( VehicleWheel );
- String n = _fixstr(p_node->get_name(),"wheel");
- bv->set_name(n);
- p_node->replace_by(bv);
- p_node->set_name(n);
- bv->add_child(p_node);
- bv->set_owner(owner);
- p_node->set_owner(owner);
- bv->set_transform(s->get_transform());
- s->set_transform(Transform());
-
- p_node=bv;
-
- } else if (p_flags&SCENE_FLAG_CREATE_ROOMS && _teststr(name,"room") && Object::cast_to<MeshInstance>(p_node)) {
-
-
- if (isroot)
- return p_node;
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- PoolVector<Face3> faces = mi->get_faces(VisualInstance::FACES_SOLID);
-
-
- BSP_Tree bsptree(faces);
-
- Ref<RoomBounds> area = memnew( RoomBounds );
- //area->set_bounds(faces);
- //area->set_geometry_hint(faces);
-
-
- Room * room = memnew( Room );
- room->set_name(_fixstr(name,"room"));
- room->set_transform(mi->get_transform());
- room->set_room(area);
-
- p_node->replace_by(room);
- memdelete(p_node);
- p_node=room;
-
- } else if (p_flags&SCENE_FLAG_CREATE_ROOMS &&_teststr(name,"room")) {
-
- if (isroot)
- return p_node;
-
- Spatial *dummy = Object::cast_to<Spatial>(p_node);
- ERR_FAIL_COND_V(!dummy,NULL);
-
- Room * room = memnew( Room );
- room->set_name(_fixstr(name,"room"));
- room->set_transform(dummy->get_transform());
-
- p_node->replace_by(room);
- memdelete(p_node);
- p_node=room;
-
- //room->compute_room_from_subtree();
-
- } else if (p_flags&SCENE_FLAG_CREATE_PORTALS &&_teststr(name,"portal") && Object::cast_to<MeshInstance>(p_node)) {
-
- if (isroot)
- return p_node;
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
- PoolVector<Face3> faces = mi->get_faces(VisualInstance::FACES_SOLID);
-
- ERR_FAIL_COND_V(faces.size()==0,NULL);
- //step 1 compute the plane
- Set<Vector3> points;
- Plane plane;
-
- Vector3 center;
-
- for(int i=0;i<faces.size();i++) {
-
- Face3 f = faces.get(i);
- Plane p = f.get_plane();
- plane.normal+=p.normal;
- plane.d+=p.d;
-
- for(int i=0;i<3;i++) {
-
- Vector3 v = f.vertex[i].snapped(0.01);
- if (!points.has(v)) {
- points.insert(v);
- center+=v;
- }
- }
- }
-
- plane.normal.normalize();
- plane.d/=faces.size();
- center/=points.size();
-
- //step 2, create points
-
- Transform t;
- t.basis.from_z(plane.normal);
- t.basis.transpose();
- t.origin=center;
-
- Vector<Point2> portal_points;
-
- for(Set<Vector3>::Element *E=points.front();E;E=E->next()) {
-
- Vector3 local = t.xform_inv(E->get());
- portal_points.push_back(Point2(local.x,local.y));
- }
- // step 3 bubbly sort points
-
- int swaps=0;
-
- do {
- swaps=0;
-
- for(int i=0;i<portal_points.size()-1;i++) {
-
- float a = portal_points[i].angle();
- float b = portal_points[i+1].angle();
-
- if (a>b) {
- SWAP( portal_points[i], portal_points[i+1] );
- swaps++;
- }
-
- }
-
- } while(swaps);
-
-
- Portal *portal = memnew( Portal );
-
- portal->set_shape(portal_points);
- portal->set_transform( mi->get_transform() * t);
-
- p_node->replace_by(portal);
- memdelete(p_node);
- p_node=portal;
-
- } else if (Object::cast_to<MeshInstance>(p_node)) {
-
- //last attempt, maybe collision insde the mesh data
-
- MeshInstance *mi = Object::cast_to<MeshInstance>(p_node);
-
- Ref<Mesh> mesh = mi->get_mesh();
- if (!mesh.is_null()) {
-
- if (p_flags&SCENE_FLAG_CREATE_COLLISIONS && _teststr(mesh->get_name(),"col")) {
-
- mesh->set_name( _fixstr(mesh->get_name(),"col") );
- Ref<Shape> shape;
-
- if (collision_map.has(mesh)) {
- shape = collision_map[mesh];
-
- } else {
-
- shape = mesh->create_trimesh_shape();
- if (!shape.is_null())
- collision_map[mesh]=shape;
-
-
- }
-
- if (!shape.is_null()) {
-#if 0
- StaticBody* static_body = memnew( StaticBody );
- ERR_FAIL_COND_V(!static_body,NULL);
- static_body->set_name( String(mesh->get_name()) + "_col" );
- shape->set_name(static_body->get_name());
- static_body->add_shape(shape);
-
- mi->add_child(static_body);
- if (mi->get_owner())
- static_body->set_owner( mi->get_owner() );
-#endif
- }
-
- }
-
- for(int i=0;i<mesh->get_surface_count();i++) {
-
- Ref<SpatialMaterial> fm = mesh->surface_get_material(i);
- if (fm.is_valid()) {
- String name = fm->get_name();
- /* if (_teststr(name,"alpha")) {
- fm->set_fixed_flag(SpatialMaterial::FLAG_USE_ALPHA,true);
- name=_fixstr(name,"alpha");
- }
-
- if (_teststr(name,"vcol")) {
- fm->set_fixed_flag(SpatialMaterial::FLAG_USE_COLOR_ARRAY,true);
- name=_fixstr(name,"vcol");
- }*/
- fm->set_name(name);
- }
- }
-
- }
-
- }
-
-
- return p_node;
-}
-
-void EditorSceneImportPlugin::_tag_import_paths(Node *p_scene,Node *p_node) {
-
- if (p_scene!=p_node && p_node->get_owner()!=p_scene)
- return;
-
- NodePath path = p_scene->get_path_to(p_node);
- p_node->set_import_path( path );
-
- Spatial *snode=Object::cast_to<Spatial>(p_node);
-
- if (snode) {
-
- snode->set_import_transform(snode->get_transform());
- }
-
- for(int i=0;i<p_node->get_child_count();i++) {
- _tag_import_paths(p_scene,p_node->get_child(i));
- }
-
-}
-
-Error EditorSceneImportPlugin::import1(const Ref<ResourceImportMetadata>& p_from,Node**r_node,List<String> *r_missing) {
-
- Ref<ResourceImportMetadata> from=p_from;
-
- ERR_FAIL_COND_V(from->get_source_count()!=1,ERR_INVALID_PARAMETER);
-
- String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0));
-
- Ref<EditorSceneImporter> importer;
- String ext=src_path.get_extension().to_lower();
-
-
- EditorProgress progress("import",TTR("Import Scene"),104);
- progress.step(TTR("Importing Scene.."),0);
-
- for(int i=0;i<importers.size();i++) {
-
- List<String> extensions;
- importers[i]->get_extensions(&extensions);
-
- for(List<String>::Element *E=extensions.front();E;E=E->next()) {
-
- if (E->get().to_lower()==ext) {
-
- importer = importers[i];
- break;
- }
- }
-
- if (importer.is_valid())
- break;
- }
-
- ERR_FAIL_COND_V(!importer.is_valid(),ERR_FILE_UNRECOGNIZED);
-
- int animation_flags=p_from->get_option("animation_flags");
- int scene_flags = from->get_option("flags");
- int fps = 24;
- if (from->has_option("animation_bake_fps"))
- fps=from->get_option("animation_bake_fps");
-
-
- Array clips;
- if (from->has_option("animation_clips"))
- clips=from->get_option("animation_clips");
-
- uint32_t import_flags=0;
- if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_DETECT_LOOP)
- import_flags|=EditorSceneImporter::IMPORT_ANIMATION_DETECT_LOOP;
- if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_KEEP_VALUE_TRACKS)
- import_flags |= EditorSceneImporter::IMPORT_ANIMATION_KEEP_VALUE_TRACKS;
- if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_OPTIMIZE)
- import_flags|=EditorSceneImporter::IMPORT_ANIMATION_OPTIMIZE;
- if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS)
- import_flags|=EditorSceneImporter::IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS;
- if (scene_flags&SCENE_FLAG_IMPORT_ANIMATIONS)
- import_flags|=EditorSceneImporter::IMPORT_ANIMATION;
- /*
- if (scene_flags&SCENE_FLAG_FAIL_ON_MISSING_IMAGES)
- import_flags|=EditorSceneImporter::IMPORT_FAIL_ON_MISSING_DEPENDENCIES;
- */
- if (scene_flags&SCENE_FLAG_GENERATE_TANGENT_ARRAYS)
- import_flags|=EditorSceneImporter::IMPORT_GENERATE_TANGENT_ARRAYS;
-
-
-
-
-
- Error err=OK;
- Node *scene = importer->import_scene(src_path,import_flags,fps,r_missing,&err);
- if (!scene || err!=OK) {
- return err;
- }
-
- if (from->has_option("root_type")) {
- String type = from->get_option("root_type");
- Node *base_node = Object::cast_to<Node>(ClassDB::instance(type));
-
- if (base_node) {
-
- scene->replace_by(base_node);
- memdelete(scene);
- scene=base_node;
- }
- }
-
- scene->set_name(from->get_option("root_name"));
- _tag_import_paths(scene,scene);
-
- *r_node=scene;
- return OK;
-}
-
-
-void EditorSceneImportPlugin::_create_clips(Node *scene, const Array& p_clips,bool p_bake_all) {
-
- if (!scene->has_node(String("AnimationPlayer")))
- return;
-
- Node* n = scene->get_node(String("AnimationPlayer"));
- ERR_FAIL_COND(!n);
- AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n);
- ERR_FAIL_COND(!anim);
-
- if (!anim->has_animation("default"))
- return;
-
-
- Ref<Animation> default_anim = anim->get_animation("default");
-
- for(int i=0;i<p_clips.size();i+=4) {
-
- String name = p_clips[i];
- float from=p_clips[i+1];
- float to=p_clips[i+2];
- bool loop=p_clips[i+3];
- if (from>=to)
- continue;
-
- Ref<Animation> new_anim = memnew( Animation );
-
- for(int j=0;j<default_anim->get_track_count();j++) {
-
-
- List<float> keys;
- int kc = default_anim->track_get_key_count(j);
- int dtrack=-1;
- for(int k=0;k<kc;k++) {
-
- float kt = default_anim->track_get_key_time(j,k);
- if (kt>=from && kt<to) {
-
- //found a key within range, so create track
- if (dtrack==-1) {
- new_anim->add_track(default_anim->track_get_type(j));
- dtrack = new_anim->get_track_count()-1;
- new_anim->track_set_path(dtrack,default_anim->track_get_path(j));
-
- if (kt>(from+0.01) && k>0) {
-
- if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) {
- Quat q;
- Vector3 p;
- Vector3 s;
- default_anim->transform_track_interpolate(j,from,&p,&q,&s);
- new_anim->transform_track_insert_key(dtrack,0,p,q,s);
- }
- }
-
- }
-
- if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) {
- Quat q;
- Vector3 p;
- Vector3 s;
- default_anim->transform_track_get_key(j,k,&p,&q,&s);
- new_anim->transform_track_insert_key(dtrack,kt-from,p,q,s);
- }
-
- }
-
- if (dtrack!=-1 && kt>=to) {
-
- if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) {
- Quat q;
- Vector3 p;
- Vector3 s;
- default_anim->transform_track_interpolate(j,to,&p,&q,&s);
- new_anim->transform_track_insert_key(dtrack,to-from,p,q,s);
- }
- }
-
- }
-
- if (dtrack==-1 && p_bake_all) {
- new_anim->add_track(default_anim->track_get_type(j));
- dtrack = new_anim->get_track_count()-1;
- new_anim->track_set_path(dtrack,default_anim->track_get_path(j));
- if (default_anim->track_get_type(j)==Animation::TYPE_TRANSFORM) {
-
-
- Quat q;
- Vector3 p;
- Vector3 s;
- default_anim->transform_track_interpolate(j,from,&p,&q,&s);
- new_anim->transform_track_insert_key(dtrack,0,p,q,s);
- default_anim->transform_track_interpolate(j,to,&p,&q,&s);
- new_anim->transform_track_insert_key(dtrack,to-from,p,q,s);
- }
-
- }
- }
-
-
- new_anim->set_loop(loop);
- new_anim->set_length(to-from);
- anim->add_animation(name,new_anim);
- }
-
- anim->remove_animation("default"); //remove default (no longer needed)
-}
-
-void EditorSceneImportPlugin::_filter_anim_tracks(Ref<Animation> anim,Set<String> &keep) {
-
- Ref<Animation> a = anim;
- ERR_FAIL_COND(!a.is_valid());
-
- print_line("From Anim "+anim->get_name()+":");
-
- for(int j=0;j<a->get_track_count();j++) {
-
- String path = a->track_get_path(j);
-
- if (!keep.has(path)) {
-
- print_line("Remove: "+path);
- a->remove_track(j);
- j--;
- }
-
- }
-}
-
-
-void EditorSceneImportPlugin::_filter_tracks(Node *scene, const String& p_text) {
-
- if (!scene->has_node(String("AnimationPlayer")))
- return;
- Node* n = scene->get_node(String("AnimationPlayer"));
- ERR_FAIL_COND(!n);
- AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n);
- ERR_FAIL_COND(!anim);
-
- Vector<String> strings = p_text.split("\n");
- for(int i=0;i<strings.size();i++) {
-
- strings[i]=strings[i].strip_edges();
- }
-
- List<StringName> anim_names;
- anim->get_animation_list(&anim_names);
- for(List<StringName>::Element *E=anim_names.front();E;E=E->next()) {
-
- String name = E->get();
- bool valid_for_this=false;
- bool valid=false;
-
- Set<String> keep;
- Set<String> keep_local;
-
-
- for(int i=0;i<strings.size();i++) {
-
-
- if (strings[i].begins_with("@")) {
-
- valid_for_this=false;
- for(Set<String>::Element *F=keep_local.front();F;F=F->next()) {
- keep.insert(F->get());
- }
- keep_local.clear();
-
- Vector<String> filters=strings[i].substr(1,strings[i].length()).split(",");
- for(int j=0;j<filters.size();j++) {
-
- String fname = filters[j].strip_edges();
- if (fname=="")
- continue;
- int fc = fname[0];
- bool plus;
- if (fc=='+')
- plus=true;
- else if (fc=='-')
- plus=false;
- else
- continue;
-
- String filter=fname.substr(1,fname.length()).strip_edges();
-
- if (!name.matchn(filter))
- continue;
- valid_for_this=plus;
- }
-
- if (valid_for_this)
- valid=true;
-
- } else if (valid_for_this) {
-
- Ref<Animation> a = anim->get_animation(name);
- if (!a.is_valid())
- continue;
-
- for(int j=0;j<a->get_track_count();j++) {
-
- String path = a->track_get_path(j);
-
- String tname = strings[i];
- if (tname=="")
- continue;
- int fc = tname[0];
- bool plus;
- if (fc=='+')
- plus=true;
- else if (fc=='-')
- plus=false;
- else
- continue;
-
- String filter=tname.substr(1,tname.length()).strip_edges();
-
- if (!path.matchn(filter))
- continue;
-
- if (plus)
- keep_local.insert(path);
- else if (!keep.has(path)) {
- keep_local.erase(path);
- }
- }
-
- }
-
- }
-
- if (valid) {
- for(Set<String>::Element *F=keep_local.front();F;F=F->next()) {
- keep.insert(F->get());
- }
- print_line("FILTERING ANIM: "+String(E->get()));
- _filter_anim_tracks(anim->get_animation(name),keep);
- } else {
- print_line("NOT FILTERING ANIM: "+String(E->get()));
-
- }
-
- }
-
-
-
-}
-
-void EditorSceneImportPlugin::_optimize_animations(Node *scene, float p_max_lin_error,float p_max_ang_error,float p_max_angle) {
-
- if (!scene->has_node(String("AnimationPlayer")))
- return;
- Node* n = scene->get_node(String("AnimationPlayer"));
- ERR_FAIL_COND(!n);
- AnimationPlayer *anim = Object::cast_to<AnimationPlayer>(n);
- ERR_FAIL_COND(!anim);
-
-
- List<StringName> anim_names;
- anim->get_animation_list(&anim_names);
- for(List<StringName>::Element *E=anim_names.front();E;E=E->next()) {
-
- Ref<Animation> a = anim->get_animation(E->get());
- a->optimize(p_max_lin_error,p_max_ang_error,Math::deg2rad(p_max_angle));
- }
-}
-
-
-void EditorSceneImportPlugin::_find_resources_to_merge(Node *scene, Node *node, bool p_merge_material, Map<String, Ref<Material> > &materials, bool p_merge_anims, Map<String,Ref<Animation> >& merged_anims,Set<Ref<Mesh> > &tested_meshes) {
-
- if (node!=scene && node->get_owner()!=scene)
- return;
-
- String path = scene->get_path_to(node);
-
- if (p_merge_anims && Object::cast_to<AnimationPlayer>(node)) {
-
- AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(node);
- List<StringName> anims;
- ap->get_animation_list(&anims);
- for (List<StringName>::Element *E=anims.front();E;E=E->next()) {
- Ref<Animation> anim = ap->get_animation(E->get());
- Ref<Animation> clone;
-
- bool has_user_tracks=false;
-
- for(int i=0;i<anim->get_track_count();i++) {
-
- if (!anim->track_is_imported(i)) {
- has_user_tracks=true;
- break;
- }
- }
-
- if (has_user_tracks) {
-
- clone = anim->duplicate();
- for(int i=0;i<clone->get_track_count();i++) {
- if (clone->track_is_imported(i)) {
- clone->remove_track(i);
- i--;
- }
- }
-
- merged_anims[path+"::"+String(E->get())]=clone;
- }
- }
- }
-
-
-
- if (p_merge_material && Object::cast_to<MeshInstance>(node)) {
- MeshInstance *mi=Object::cast_to<MeshInstance>(node);
- Ref<Mesh> mesh = mi->get_mesh();
- if (mesh.is_valid() && mesh->get_name()!=String() && !tested_meshes.has(mesh)) {
-
- for(int i=0;i<mesh->get_surface_count();i++) {
- Ref<Material> material = mesh->surface_get_material(i);
-
- if (material.is_valid()) {
-
- String sname = mesh->surface_get_name(i);
- if (sname=="")
- sname="surf_"+itos(i);
-
- sname=mesh->get_name()+":surf:"+sname;
- materials[sname]=material;
- }
- }
-
- tested_meshes.insert(mesh);
- }
-
- if (mesh.is_valid()) {
-
- for(int i=0;i<mesh->get_surface_count();i++) {
- Ref<Material> material = mi->get_surface_material(i);
- if (material.is_valid()) {
- String sname = mesh->surface_get_name(i);
- if (sname=="")
- sname="surf_"+itos(i);
-
- sname=path+":inst_surf:"+sname;
- materials[sname]=material;
- }
- }
-
- }
-
- Ref<Material> override = mi->get_material_override();
-
- if (override.is_valid()) {
-
- materials[path+":override"]=override;
- }
- }
-
-
-
- for(int i=0;i<node->get_child_count();i++) {
- _find_resources_to_merge(scene,node->get_child(i),p_merge_material,materials,p_merge_anims,merged_anims,tested_meshes);
- }
-
-}
-
-
-void EditorSceneImportPlugin::_merge_found_resources(Node *scene, Node *node, bool p_merge_material, const Map<String, Ref<Material> > &materials, bool p_merge_anims, const Map<String,Ref<Animation> >& merged_anims, Set<Ref<Mesh> > &tested_meshes) {
-
- if (node!=scene && node->get_owner()!=scene)
- return;
-
- String path = scene->get_path_to(node);
-
- print_line("at path: "+path);
-
- if (AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(node)) {
-
- List<StringName> anims;
- ap->get_animation_list(&anims);
- for (List<StringName>::Element *E=anims.front();E;E=E->next()) {
- Ref<Animation> anim = ap->get_animation(E->get());
-
- String anim_path = path+"::"+String(E->get());
-
- if (merged_anims.has(anim_path)) {
-
- Ref<Animation> user_tracks = merged_anims[anim_path];
- for(int i=0;i<user_tracks->get_track_count();i++) {
-
- int idx = anim->get_track_count();
- anim->add_track(user_tracks->track_get_type(i));
- anim->track_set_path(idx,user_tracks->track_get_path(i));
- anim->track_set_interpolation_type(idx,user_tracks->track_get_interpolation_type(i));
- for(int j=0;j<user_tracks->track_get_key_count(i);j++) {
-
- float ofs = user_tracks->track_get_key_time(i,j);
- float trans = user_tracks->track_get_key_transition(i,j);
- Variant value = user_tracks->track_get_key_value(i,j);
-
- anim->track_insert_key(idx,ofs,value,trans);
- }
- }
- }
- }
- }
-
-
-
- if (MeshInstance *mi=Object::cast_to<MeshInstance>(node)) {
-
- Ref<Mesh> mesh = mi->get_mesh();
- if (mesh.is_valid() && mesh->get_name()!=String() && !tested_meshes.has(mesh)) {
-
- for(int i=0;i<mesh->get_surface_count();i++) {
-
- String sname = mesh->surface_get_name(i);
- if (sname=="")
- sname="surf_"+itos(i);
-
- sname=mesh->get_name()+":surf:"+sname;
-
-
- if (materials.has(sname)) {
-
- mesh->surface_set_material(i,materials[sname]);
- }
- }
-
- tested_meshes.insert(mesh);
- }
-
- if (mesh.is_valid()) {
-
- for(int i=0;i<mesh->get_surface_count();i++) {
-
- String sname = mesh->surface_get_name(i);
- if (sname=="")
- sname="surf_"+itos(i);
-
- sname=path+":inst_surf:"+sname;
-
-
- if (materials.has(sname)) {
-
- mi->set_surface_material(i,materials[sname]);
- }
- }
-
- }
-
-
- String opath = path+":override";
- if (materials.has(opath)) {
- mi->set_material_override(materials[opath]);
- }
-
- }
-
-
-
- for(int i=0;i<node->get_child_count();i++) {
- _merge_found_resources(scene,node->get_child(i),p_merge_material,materials,p_merge_anims,merged_anims,tested_meshes);
- }
-
-}
-
-Error EditorSceneImportPlugin::import2(Node *scene, const String& p_dest_path, const Ref<ResourceImportMetadata>& p_from) {
-
- Error err=OK;
- Ref<ResourceImportMetadata> from=p_from;
- String src_path=EditorImportPlugin::expand_source_path(from->get_source_path(0));
- int animation_flags=p_from->get_option("animation_flags");
- Array animation_clips = p_from->get_option("animation_clips");
- String animation_filter = p_from->get_option("animation_filters");
- int scene_flags = from->get_option("flags");
- float anim_optimizer_linerr=0.05;
- float anim_optimizer_angerr=0.01;
- float anim_optimizer_maxang=22;
-
- if (from->has_option("animation_optimizer_linear_error"))
- anim_optimizer_linerr=from->get_option("animation_optimizer_linear_error");
- if (from->has_option("animation_optimizer_angular_error"))
- anim_optimizer_angerr=from->get_option("animation_optimizer_angular_error");
- if (from->has_option("animation_optimizer_max_angle"))
- anim_optimizer_maxang=from->get_option("animation_optimizer_max_angle");
-
- EditorProgress progress("import",TTR("Import Scene"),104);
- progress.step(TTR("Importing Scene.."),2);
-
-
- from->set_source_md5(0,FileAccess::get_md5(src_path));
- from->set_editor(get_name());
-
- from->set_option("reimport",false);
- String target_res_path=p_dest_path.get_base_dir();
-
- Map<Ref<Mesh>,Ref<Shape> > collision_map;
-
- Map< Ref<ImageTexture>,TextureRole > imagemap;
-
- scene=_fix_node(scene,scene,collision_map,scene_flags,imagemap);
- if (animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_OPTIMIZE)
- _optimize_animations(scene,anim_optimizer_linerr,anim_optimizer_angerr,anim_optimizer_maxang);
- if (animation_clips.size())
- _create_clips(scene,animation_clips,animation_flags&EditorSceneAnimationImportPlugin::ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS);
-
- _filter_tracks(scene,animation_filter);
-
-
- if (scene_flags&(SCENE_FLAG_MERGE_KEEP_MATERIALS|SCENE_FLAG_MERGE_KEEP_EXTRA_ANIM_TRACKS) && FileAccess::exists(p_dest_path)) {
- //must merge!
-
- print_line("MUST MERGE");
- Ref<PackedScene> pscene = ResourceLoader::load(p_dest_path,"PackedScene",true);
- if (pscene.is_valid()) {
-
- Node *instance = pscene->instance();
- if (instance) {
- Map<String,Ref<Animation> > merged_anims;
- Map<String,Ref<Material> > merged_materials;
- Set<Ref<Mesh> > tested_meshes;
-
- _find_resources_to_merge(instance,instance,scene_flags&SCENE_FLAG_MERGE_KEEP_MATERIALS,merged_materials,scene_flags&SCENE_FLAG_MERGE_KEEP_EXTRA_ANIM_TRACKS,merged_anims,tested_meshes);
-
- tested_meshes.clear();
- _merge_found_resources(scene,scene,scene_flags&SCENE_FLAG_MERGE_KEEP_MATERIALS,merged_materials,scene_flags&SCENE_FLAG_MERGE_KEEP_EXTRA_ANIM_TRACKS,merged_anims,tested_meshes);
-
- memdelete(instance);
- }
-
- }
-
- }
-
- /// BEFORE ANYTHING, RUN SCRIPT
-
- progress.step(TTR("Running Custom Script.."),2);
-
- String post_import_script_path = from->get_option("post_import_script");
- Ref<EditorScenePostImport> post_import_script;
-
- if (post_import_script_path!="") {
- post_import_script_path = post_import_script_path;
- Ref<Script> scr = ResourceLoader::load(post_import_script_path);
- if (!scr.is_valid()) {
- EditorNode::add_io_error(TTR("Couldn't load post-import script:")+" "+post_import_script_path);
- } else {
-
- post_import_script = Ref<EditorScenePostImport>( memnew( EditorScenePostImport ) );
- post_import_script->set_script(scr.get_ref_ptr());
- if (!post_import_script->get_script_instance()) {
- EditorNode::add_io_error(TTR("Invalid/broken script for post-import (check console):")+" "+post_import_script_path);
- post_import_script.unref();
- return ERR_CANT_CREATE;
- }
- }
- }
-
-
- if (post_import_script.is_valid()) {
- scene = post_import_script->post_import(scene);
- if (!scene) {
- EditorNode::add_io_error(TTR("Error running post-import script:")+" "+post_import_script_path);
- return err;
- }
-
-
- }
-
-
- /// IMPORT IMAGES
-
-
- int idx=0;
-
- int image_format = from->get_option("texture_format");
- int image_flags = from->get_option("texture_flags");
- float image_quality = from->get_option("texture_quality");
-
- for (Map< Ref<ImageTexture>,TextureRole >::Element *E=imagemap.front();E;E=E->next()) {
-
- //texture could be converted to something more useful for 3D, that could load individual mipmaps and stuff
- //but not yet..
-
- Ref<ImageTexture> texture = E->key();
-
- ERR_CONTINUE(!texture.is_valid());
-
- String path = texture->get_path();
- String fname= path.get_file();
- String target_path = ProjectSettings::get_singleton()->localize_path(target_res_path.plus_file(fname));
- progress.step(TTR("Import Image:")+" "+fname,3+(idx)*100/imagemap.size());
-
- idx++;
-
- if (path==target_path) {
-
- EditorNode::add_io_error(TTR("Can't import a file over itself:")+" "+target_path);
- continue;
- }
-
- if (!target_path.begins_with("res://")) {
- EditorNode::add_io_error(vformat(TTR("Couldn't localize path: %s (already local)"),target_path));
- continue;
- }
-
-
- {
-
-
- target_path=target_path.get_basename()+".tex";
-
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
-
- uint32_t flags = image_flags;
- if (E->get()==TEXTURE_ROLE_DIFFUSE && scene_flags&SCENE_FLAG_LINEARIZE_DIFFUSE_TEXTURES)
- flags|=EditorTextureImportPlugin::IMAGE_FLAG_CONVERT_TO_LINEAR;
-
- if (E->get()==TEXTURE_ROLE_NORMALMAP && scene_flags&SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY)
- flags|=EditorTextureImportPlugin::IMAGE_FLAG_CONVERT_NORMAL_TO_XY;
-
- imd->set_option("flags",flags);
- imd->set_option("format",image_format);
- imd->set_option("quality",image_quality);
- imd->set_option("atlas",false);
- imd->add_source(EditorImportPlugin::validate_source_path(path));
-
-
- if (FileAccess::exists(target_path)) {
-
- Ref<ResourceImportMetadata> rimdex = ResourceLoader::load_import_metadata(target_path);
- if (rimdex.is_valid()) {
- //make sure the options are the same, otherwise re-import
- List<String> opts;
- imd->get_options(&opts);
- bool differ=false;
- for (List<String>::Element *E=opts.front();E;E=E->next()) {
- if (!(rimdex->get_option(E->get())==imd->get_option(E->get()))) {
- differ=true;
- break;
- }
- }
-
- if (!differ) {
- texture->set_path(target_path);
- continue; //already imported
- }
- }
- }
-
- EditorTextureImportPlugin::get_singleton()->import(target_path,imd);
-
- }
- }
-
-
-
- progress.step(TTR("Saving.."),104);
-
- Ref<PackedScene> packer = memnew( PackedScene );
- packer->pack(scene);
- //packer->set_path(p_dest_path); do not take over, let the changed files reload themselves
- packer->set_import_metadata(from);
-
- print_line("SAVING TO: "+p_dest_path);
- err = ResourceSaver::save(p_dest_path,packer); //do not take over, let the changed files reload themselves
-
- //EditorFileSystem::get_singleton()->update_resource(packer);
-
- memdelete(scene);
-
- /*
- scene->set_filename(p_dest_path);
- if (r_scene) {
- *r_scene=scene;
- } else {
- memdelete(scene);
- }
-
- String sp;
- if (p_post_import.is_valid() && !p_post_import->get_script().is_null()) {
- Ref<Script> scr = p_post_import->get_script();
- if (scr.is_valid())
- sp=scr->get_path();
- }
-
- String op=_getrelpath(p_path,p_dest_path);
-
- */
-
- EditorNode::get_singleton()->reload_scene(p_dest_path);
-
- return err;
-
-}
-
-
-Error EditorSceneImportPlugin::import(const String& p_dest_path, const Ref<ResourceImportMetadata>& p_from){
-
-
- Node *n=NULL;
- Error err = import1(p_from,&n);
- if (err!=OK) {
- if (n) {
- memdelete(n);
- }
- return err;
- }
- return import2(n,p_dest_path,p_from);
-}
-
-void EditorSceneImportPlugin::add_importer(const Ref<EditorSceneImporter>& p_importer) {
-
- importers.push_back(p_importer);
-}
-
-void EditorSceneImportPlugin::import_from_drop(const Vector<String>& p_drop,const String& p_dest_path) {
-
- List<String> extensions;
- for(int i=0;i<importers.size();i++) {
- importers[i]->get_extensions(&extensions);
- }
- //bool warn_compatible=false;
- for(int i=0;i<p_drop.size();i++) {
-
- String extension = p_drop[i].get_extension().to_lower();
-
- for(List<String>::Element *E=extensions.front();E;E=E->next()) {
-
- if (E->get()==extension) {
-
- dialog->popup_import(String());
- dialog->setup_popup(p_drop[i],p_dest_path);
- return;
- }
- }
- }
-
-}
-
-
-EditorSceneImportPlugin::EditorSceneImportPlugin(EditorNode* p_editor) {
-
- dialog = memnew( EditorSceneImportDialog(p_editor,this) );
- p_editor->get_gui_base()->add_child(dialog);
-}
-
-
-///////////////////////////////
-
-
-String EditorSceneAnimationImportPlugin::get_name() const {
-
- return "anim_3d";
-}
-String EditorSceneAnimationImportPlugin::get_visible_name() const{
-
-
- return TTR("3D Scene Animation");
-}
-void EditorSceneAnimationImportPlugin::import_dialog(const String& p_from){
-
-
-}
-Error EditorSceneAnimationImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from){
-
- return OK;
-}
-
-EditorSceneAnimationImportPlugin::EditorSceneAnimationImportPlugin(EditorNode* p_editor) {
-
-
-}
-#endif
diff --git a/editor/io_plugins/editor_scene_import_plugin.h b/editor/io_plugins/editor_scene_import_plugin.h
deleted file mode 100644
index afaeea49af..0000000000
--- a/editor/io_plugins/editor_scene_import_plugin.h
+++ /dev/null
@@ -1,201 +0,0 @@
-/*************************************************************************/
-/* editor_scene_import_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 EDITOR_SCENE_IMPORT_PLUGIN_H
-#define EDITOR_SCENE_IMPORT_PLUGIN_H
-#if 0
-#include "editor/editor_dir_dialog.h"
-#include "editor/editor_file_system.h"
-#include "editor/editor_import_export.h"
-#include "editor/io_plugins/editor_texture_import_plugin.h"
-#include "scene/gui/dialogs.h"
-#include "scene/gui/file_dialog.h"
-#include "scene/gui/label.h"
-#include "scene/gui/line_edit.h"
-#include "scene/gui/option_button.h"
-#include "scene/gui/progress_bar.h"
-#include "scene/gui/slider.h"
-#include "scene/gui/spin_box.h"
-#include "scene/gui/tree.h"
-#include "scene/resources/animation.h"
-#include "scene/resources/mesh.h"
-
-
-class EditorNode;
-class EditorSceneImportDialog;
-
-class EditorSceneImporter : public Reference {
-
- GDCLASS(EditorSceneImporter,Reference );
-public:
-
- enum ImportFlags {
- IMPORT_SCENE=1,
- IMPORT_ANIMATION=2,
- IMPORT_ANIMATION_DETECT_LOOP=4,
- IMPORT_ANIMATION_OPTIMIZE=8,
- IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS=16,
- IMPORT_ANIMATION_KEEP_VALUE_TRACKS=32,
- IMPORT_GENERATE_TANGENT_ARRAYS=256,
- IMPORT_FAIL_ON_MISSING_DEPENDENCIES=512
-
- };
-
- virtual uint32_t get_import_flags() const=0;
- virtual void get_extensions(List<String> *r_extensions) const=0;
- virtual Node* import_scene(const String& p_path,uint32_t p_flags,int p_bake_fps,List<String> *r_missing_deps,Error* r_err=NULL)=0;
- virtual Ref<Animation> import_animation(const String& p_path,uint32_t p_flags)=0;
-
-
-
- EditorSceneImporter();
-};
-
-/////////////////////////////////////////
-
-
-//Plugin for post processing scenes or images
-
-class EditorScenePostImport : public Reference {
-
- GDCLASS(EditorScenePostImport,Reference );
-protected:
-
- static void _bind_methods();
-public:
-
- virtual Node* post_import(Node* p_scene);
- EditorScenePostImport();
-};
-
-
-class EditorSceneImportPlugin : public EditorImportPlugin {
-
- GDCLASS(EditorSceneImportPlugin,EditorImportPlugin);
-
- EditorSceneImportDialog *dialog;
-
- Vector<Ref<EditorSceneImporter> > importers;
-
- enum TextureRole {
- TEXTURE_ROLE_DEFAULT,
- TEXTURE_ROLE_DIFFUSE,
- TEXTURE_ROLE_NORMALMAP
- };
-
- void _find_resources(const Variant& p_var,Map<Ref<ImageTexture>,TextureRole >& image_map,int p_flags);
- Node* _fix_node(Node *p_node,Node *p_root,Map<Ref<Mesh>,Ref<Shape> > &collision_map,uint32_t p_flags,Map<Ref<ImageTexture>,TextureRole >& image_map);
- void _create_clips(Node *scene, const Array& p_clips, bool p_bake_all);
- void _filter_anim_tracks(Ref<Animation> anim,Set<String> &keep);
- void _filter_tracks(Node *scene, const String& p_text);
- void _optimize_animations(Node *scene, float p_max_lin_error,float p_max_ang_error,float p_max_angle);
-
- void _tag_import_paths(Node *p_scene,Node *p_node);
-
- void _find_resources_to_merge(Node *scene, Node *node, bool p_merge_material, Map<String,Ref<Material> >&materials, bool p_merge_anims, Map<String,Ref<Animation> >& merged_anims, Set<Ref<Mesh> > &tested_meshes);
- void _merge_found_resources(Node *scene, Node *node, bool p_merge_material, const Map<String, Ref<Material> > &materials, bool p_merge_anims, const Map<String,Ref<Animation> >& merged_anims, Set<Ref<Mesh> > &tested_meshes);
-
-
-public:
-
- enum SceneFlags {
-
- SCENE_FLAG_CREATE_COLLISIONS=1<<0,
- SCENE_FLAG_CREATE_PORTALS=1<<1,
- SCENE_FLAG_CREATE_ROOMS=1<<2,
- SCENE_FLAG_SIMPLIFY_ROOMS=1<<3,
- SCENE_FLAG_CREATE_BILLBOARDS=1<<4,
- SCENE_FLAG_CREATE_IMPOSTORS=1<<5,
- SCENE_FLAG_CREATE_LODS=1<<6,
- SCENE_FLAG_CREATE_CARS=1<<8,
- SCENE_FLAG_CREATE_WHEELS=1<<9,
- SCENE_FLAG_DETECT_ALPHA=1<<15,
- SCENE_FLAG_DETECT_VCOLOR=1<<16,
- SCENE_FLAG_CREATE_NAVMESH=1<<17,
- SCENE_FLAG_DETECT_LIGHTMAP_LAYER=1<<18,
-
- SCENE_FLAG_MERGE_KEEP_MATERIALS=1<<20,
- SCENE_FLAG_MERGE_KEEP_EXTRA_ANIM_TRACKS=1<<21,
-
- SCENE_FLAG_REMOVE_NOIMP=1<<24,
- SCENE_FLAG_IMPORT_ANIMATIONS=1<<25,
- SCENE_FLAG_COMPRESS_GEOMETRY=1<<26,
- SCENE_FLAG_GENERATE_TANGENT_ARRAYS=1<<27,
- SCENE_FLAG_LINEARIZE_DIFFUSE_TEXTURES=1<<28,
- SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS=1<<29,
- SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY=1<<30,
- };
-
-
-
- virtual String get_name() const;
- virtual String get_visible_name() const;
- virtual void import_dialog(const String& p_from="");
- virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
-
- Error import1(const Ref<ResourceImportMetadata>& p_from,Node**r_node,List<String> *r_missing=NULL);
- Error import2(Node* p_scene,const String& p_path, const Ref<ResourceImportMetadata>& p_from);
-
- void add_importer(const Ref<EditorSceneImporter>& p_importer);
- const Vector<Ref<EditorSceneImporter> >& get_importers() { return importers; }
-
- virtual void import_from_drop(const Vector<String>& p_drop,const String& p_dest_path);
-
- EditorSceneImportPlugin(EditorNode* p_editor=NULL);
-
-
-};
-
-
-class EditorSceneAnimationImportPlugin : public EditorImportPlugin {
-
- GDCLASS(EditorSceneAnimationImportPlugin,EditorImportPlugin);
-public:
-
-
- enum AnimationFlags {
-
- ANIMATION_DETECT_LOOP=1,
- ANIMATION_KEEP_VALUE_TRACKS=2,
- ANIMATION_OPTIMIZE=4,
- ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS=8
- };
-
- virtual String get_name() const;
- virtual String get_visible_name() const;
- virtual void import_dialog(const String& p_from="");
- virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
-
- EditorSceneAnimationImportPlugin(EditorNode* p_editor=NULL);
-
-
-};
-
-#endif
-#endif // EDITOR_SCENE_IMPORT_PLUGIN_H
diff --git a/editor/io_plugins/editor_scene_importer_fbxconv.cpp b/editor/io_plugins/editor_scene_importer_fbxconv.cpp
deleted file mode 100644
index 48172520c7..0000000000
--- a/editor/io_plugins/editor_scene_importer_fbxconv.cpp
+++ /dev/null
@@ -1,1137 +0,0 @@
-/*************************************************************************/
-/* editor_scene_importer_fbxconv.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 "editor_scene_importer_fbxconv.h"
-
-#include "editor/editor_settings.h"
-#include "os/file_access.h"
-#include "os/os.h"
-#include "scene/3d/mesh_instance.h"
-#include "scene/animation/animation_player.h"
-
-#if 0
-String EditorSceneImporterFBXConv::_id(const String& p_id) const {
-
- return p_id.replace(":","_").replace("/","_");
-}
-
-uint32_t EditorSceneImporterFBXConv::get_import_flags() const {
-
- return IMPORT_SCENE|IMPORT_ANIMATION;
-}
-void EditorSceneImporterFBXConv::get_extensions(List<String> *r_extensions) const{
-
- r_extensions->push_back("fbx");
- r_extensions->push_back("g3dj");
-}
-
-
-Color EditorSceneImporterFBXConv::_get_color(const Array& a) {
-
- if (a.size()<3)
- return Color();
- Color c;
- c.r=a[0];
- c.g=a[1];
- c.b=a[2];
- if (a.size()>=4)
- c.a=a[3];
- return c;
-
-}
-
-Transform EditorSceneImporterFBXConv::_get_transform_mixed(const Dictionary& d,const Dictionary& dbase) {
-
-
-
-
- Array translation;
-
- if (d.has("translation"))
- translation=d["translation"];
- else if (dbase.has("translation"))
- translation=dbase["translation"];
-
- Array rotation;
-
- if (d.has("rotation"))
- rotation=d["rotation"];
- else if (dbase.has("rotation"))
- rotation=dbase["rotation"];
-
- Array scale;
-
- if (d.has("scale"))
- scale=d["scale"];
- else if (dbase.has("scale"))
- scale=dbase["scale"];
-
- Transform t;
-
-
- if (translation.size()) {
- Array tr = translation;
- if (tr.size()>=3) {
- t.origin.x=tr[0];
- t.origin.y=tr[1];
- t.origin.z=tr[2];
- }
- }
-
- if (rotation.size()) {
-
- Array r = rotation;
- if (r.size()>=4) {
-
- Quat q;
- q.x = r[0];
- q.y = r[1];
- q.z = r[2];
- q.w = r[3];
- t.basis=Matrix3(q);
- }
- }
-
-
- if (scale.size()) {
-
- Array sc = scale;
- if (sc.size()>=3) {
- Vector3 s;
- s.x=sc[0];
- s.y=sc[1];
- s.z=sc[2];
- t.basis.scale(s);
- }
- }
-
- return t;
-
-
-}
-
-Transform EditorSceneImporterFBXConv::_get_transform(const Dictionary& d) {
-
-
- Transform t;
-
- if (d.has("translation")) {
- Array tr = d["translation"];
- if (tr.size()>=3) {
- t.origin.x=tr[0];
- t.origin.y=tr[1];
- t.origin.z=tr[2];
- }
- }
-
- if (d.has("rotation")) {
-
- Array r = d["rotation"];
- if (r.size()>=4) {
-
- Quat q;
- q.x = r[0];
- q.y = r[1];
- q.z = r[2];
- q.w = r[3];
- t.basis=Matrix3(q);
- }
- }
-
-
- if (d.has("scale")) {
-
- Array sc = d["scale"];
- if (sc.size()>=3) {
- Vector3 s;
- s.x=sc[0];
- s.y=sc[1];
- s.z=sc[2];
- t.basis.scale(s);
- }
- }
-
- return t;
-}
-
-
-void EditorSceneImporterFBXConv::_detect_bones_in_nodes(State& state,const Array& p_nodes) {
-
-
- for(int i=0;i<p_nodes.size();i++) {
-
- Dictionary d = p_nodes[i];
- if (d.has("isBone") && bool(d["isBone"])) {
-
- String bone_name=_id(d["id"]);
- print_line("IS BONE: "+bone_name);
- if (!state.bones.has(bone_name)) {
- state.bones.insert(bone_name,BoneInfo());
- }
-
- if (!state.bones[bone_name].has_rest) {
- state.bones[bone_name].rest=_get_transform(d).affine_inverse();
- }
-
- state.bones[bone_name].node=d;
-
- //state.bones[name].rest=_get_transform(b);
- }
-
- if (d.has("parts")) {
-
- Array parts=d["parts"];
- for(int j=0;j<parts.size();j++) {
-
- Dictionary p=parts[j];
- if (p.has("bones")) {
- Array bones=p["bones"];
- //omfg
- for(int k=0;k<bones.size();k++) {
-
- Dictionary b = bones[k];
- if (b.has("node")) {
-
- String name = _id(b["node"]);
- if (!state.bones.has(name)) {
- state.bones.insert(name,BoneInfo());
- }
-
- state.bones[name].rest=_get_transform(b);
- state.bones[name].has_rest=true;
- }
- }
- }
-
- }
- }
-
- if (d.has("children")) {
-
- _detect_bones_in_nodes(state,d["children"]);
- }
- }
-
-}
-
-void EditorSceneImporterFBXConv::_parse_skeletons(const String& p_name,State& state, const Array &p_nodes, Skeleton *p_skeleton,int p_parent) {
-
-
-
- for(int i=0;i<p_nodes.size();i++) {
-
-
- Dictionary d = p_nodes[i];
- int bone_idx=-1;
- String id;
- Skeleton* skeleton=p_skeleton;
- if (d.has("id")) {
-
- id=_id(d["id"]);
- if (state.bones.has(id)) {
- //BONER
- if (!skeleton) {
- skeleton=memnew( Skeleton );
- state.skeletons[id]=skeleton;
- }
- bone_idx = skeleton->get_bone_count();
- skeleton->add_bone(id);
- skeleton->set_bone_parent(bone_idx,p_parent);
- skeleton->set_bone_rest(bone_idx,state.bones[id].rest);
- state.bones[id].skeleton=skeleton;
- }
- }
-
- if (d.has("children")) {
-
- _parse_skeletons(id,state,d["children"],skeleton,bone_idx);
- }
- }
-
-}
-
-void EditorSceneImporterFBXConv::_detect_bones(State& state) {
- //This format should mark when a node is a bone,
- //which is the only thing that Collada does right.
- //think about others implementing a parser.
- //Just _one_ string and you avoid loads of lines of code to other people.
-
- for(int i=0;i<state.animations.size();i++) {
-
- Dictionary an = state.animations[i];
- if (an.has("bones")) {
-
- Array bo=an["bones"];
- for(int j=0;j<bo.size();j++) {
-
- Dictionary b=bo[j];
- if (b.has("boneId")) {
-
- String id = b["boneId"];
- if (!state.bones.has(id)) {
- state.bones.insert(id,BoneInfo());
- }
- state.bones[id].has_anim_chan=true; //used in anim
-
-
- }
- }
- }
- }
-
- _detect_bones_in_nodes(state,state.nodes);
- _parse_skeletons("",state,state.nodes,NULL,-1);
-
- print_line("found bones: "+itos(state.bones.size()));
- print_line("found skeletons: "+itos(state.skeletons.size()));
-}
-
-Error EditorSceneImporterFBXConv::_parse_bones(State& state,const Array &p_bones,Skeleton* p_skeleton) {
-
-
-
- return OK;
-}
-
-
-void EditorSceneImporterFBXConv::_add_surface(State& state,Ref<Mesh>& m,const Dictionary &part) {
-
- if (part.has("meshpartid")) {
-
- String id = part["meshpartid"];
- ERR_FAIL_COND(!state.surface_cache.has(id));
-
-
- Ref<Material> mat;
- if (part.has("materialid")) {
- String matid=part["materialid"];
- if (state.material_cache.has(matid)) {
- mat=state.material_cache[matid];
- }
- }
- int idx = m->get_surface_count();
-
- Array array = state.surface_cache[id].array;
- PoolVector<float> indices = array[Mesh::ARRAY_BONES];
- if (indices.size() && part.has("bones")) {
-
-
- Map<int,int> index_map;
-
- Array bones=part["bones"];
-
- for(int i=0;i<bones.size();i++) {
-
- Dictionary bone=bones[i];
- String name=_id(bone["node"]);
-
- if (state.bones.has(name)) {
- int idx=state.bones[name].skeleton->find_bone(name);
- if (idx==-1)
- idx=0;
- index_map[i]=idx;
- }
- }
-
-
-
- int ilen=indices.size();
- {
- PoolVector<float>::Write iw=indices.write();
- for(int j=0;j<ilen;j++) {
- int b = iw[j];
- ERR_CONTINUE(!index_map.has(b));
- b=index_map[b];
- iw[j]=b;
- }
- }
-
- array[Mesh::ARRAY_BONES]=indices;
-
-
- }
-
- m->add_surface(state.surface_cache[id].primitive,array);
- m->surface_set_material(idx,mat);
- m->surface_set_name(idx,id);
- }
-
-}
-
-Error EditorSceneImporterFBXConv::_parse_nodes(State& state,const Array &p_nodes,Node* p_base) {
-
- for(int i=0;i<p_nodes.size();i++) {
-
- Dictionary n = p_nodes[i];
- Spatial *node=NULL;
- bool skip=false;
-
- String id;
- if (n.has("id")) {
- id=_id(n["id"]);
- }
-
- print_line("ID: "+id);
-
- if (state.skeletons.has(id)) {
-
- Skeleton *skeleton = state.skeletons[id];
- node=skeleton;
- skeleton->localize_rests();
- print_line("IS SKELETON! ");
- } else if (state.bones.has(id)) {
- if (p_base)
- node=Object::cast_to<Spatial>(p_base);
- if (!state.bones[id].has_anim_chan) {
- print_line("no has anim "+id);
- }
- skip=true;
- } else if (n.has("parts")) {
- //is a mesh
- MeshInstance *mesh = memnew( MeshInstance );
- node=mesh;
-
- Array parts=n["parts"];
- String long_identifier;
- for(int j=0;j<parts.size();j++) {
-
- Dictionary part=parts[j];
- if (part.has("meshpartid")) {
- String partid=part["meshpartid"];
- long_identifier+=partid;
- }
- }
-
- Ref<Mesh> m;
-
- if (state.mesh_cache.has(long_identifier)) {
- m=state.mesh_cache[long_identifier];
- } else {
- m = Ref<Mesh>( memnew( Mesh ) );
-
- //and parts are surfaces
- for(int j=0;j<parts.size();j++) {
-
- Dictionary part=parts[j];
- if (part.has("meshpartid")) {
- _add_surface(state,m,part);
- }
- }
-
-
- state.mesh_cache[long_identifier]=m;
- }
-
- mesh->set_mesh(m);
- }
-
- if (!skip) {
-
- if (!node) {
- node = memnew( Spatial );
- }
-
- node->set_name(id);
- node->set_transform(_get_transform(n));
- p_base->add_child(node);
- node->set_owner(state.scene);
- }
-
-
- if (n.has("children")) {
- Error err = _parse_nodes(state,n["children"],node);
- if (err)
- return err;
- }
- }
-
- return OK;
-}
-
-
-void EditorSceneImporterFBXConv::_parse_materials(State& state) {
-
- for(int i=0;i<state.materials.size();i++) {
-
- Dictionary material = state.materials[i];
-
- ERR_CONTINUE(!material.has("id"));
- String id = _id(material["id"]);
-
- Ref<SpatialMaterial> mat = memnew( SpatialMaterial );
-
- if (material.has("diffuse")) {
- mat->set_parameter(SpatialMaterial::PARAM_DIFFUSE,_get_color(material["diffuse"]));
- }
-
- if (material.has("specular")) {
- mat->set_parameter(SpatialMaterial::PARAM_SPECULAR,_get_color(material["specular"]));
- }
-
- if (material.has("emissive")) {
- mat->set_parameter(SpatialMaterial::PARAM_EMISSION,_get_color(material["emissive"]));
- }
-
- if (material.has("shininess")) {
- float exp = material["shininess"];
- mat->set_parameter(SpatialMaterial::PARAM_SPECULAR_EXP,exp);
- }
-
- if (material.has("opacity")) {
- Color c = mat->get_parameter(SpatialMaterial::PARAM_DIFFUSE);
- c.a=material["opacity"];
- mat->set_parameter(SpatialMaterial::PARAM_DIFFUSE,c);
- }
-
-
- if (material.has("textures")) {
-
- Array textures = material["textures"];
- for(int j=0;j<textures.size();j++) {
-
- Dictionary texture=textures[j];
- Ref<Texture> tex;
- if (texture.has("filename")) {
-
-
- String filename=texture["filename"];
- String path=state.base_path+"/"+filename.replace("\\","/");
- if (state.texture_cache.has(path)) {
- tex=state.texture_cache[path];
- } else {
- tex = ResourceLoader::load(path,"ImageTexture");
- if (tex.is_null()) {
- if (state.missing_deps)
- state.missing_deps->push_back(path);
- }
- state.texture_cache[path]=tex; //add anyway
- }
- }
-
- if (tex.is_valid() && texture.has("type")) {
-
- String type=texture["type"];
- if (type=="DIFFUSE")
- mat->set_texture(SpatialMaterial::PARAM_DIFFUSE,tex);
- else if (type=="SPECULAR")
- mat->set_texture(SpatialMaterial::PARAM_SPECULAR,tex);
- else if (type=="SHININESS")
- mat->set_texture(SpatialMaterial::PARAM_SPECULAR_EXP,tex);
- else if (type=="NORMAL")
- mat->set_texture(SpatialMaterial::PARAM_NORMAL,tex);
- else if (type=="EMISSIVE")
- mat->set_texture(SpatialMaterial::PARAM_EMISSION,tex);
- }
-
- }
- }
-
- state.material_cache[id]=mat;
-
- }
-
-}
-
-void EditorSceneImporterFBXConv::_parse_surfaces(State& state) {
-
- for(int i=0;i<state.meshes.size();i++) {
-
- Dictionary mesh = state.meshes[i];
-
- ERR_CONTINUE(!mesh.has("attributes"));
- ERR_CONTINUE(!mesh.has("vertices"));
- ERR_CONTINUE(!mesh.has("parts"));
-
- print_line("MESH #"+itos(i));
-
- Array attrlist=mesh["attributes"];
- Array vertices=mesh["vertices"];
- bool exists[Mesh::ARRAY_MAX];
- int ofs[Mesh::ARRAY_MAX];
- int weight_max=0;
- int binormal_ofs=-1;
- int weight_ofs[4];
-
- for(int j=0;j<Mesh::ARRAY_MAX;j++) {
- exists[j]=false;
- ofs[j]=0;
- }
- exists[Mesh::ARRAY_INDEX]=true;
- float stride=0;
-
- for(int j=0;j<attrlist.size();j++) {
-
- String attr=attrlist[j];
- if (attr=="POSITION") {
- exists[Mesh::ARRAY_VERTEX]=true;
- ofs[Mesh::ARRAY_VERTEX]=stride;
- stride+=3;
- } else if (attr=="NORMAL") {
- exists[Mesh::ARRAY_NORMAL]=true;
- ofs[Mesh::ARRAY_NORMAL]=stride;
- stride+=3;
- } else if (attr=="COLOR") {
- exists[Mesh::ARRAY_COLOR]=true;
- ofs[Mesh::ARRAY_COLOR]=stride;
- stride+=4;
- } else if (attr=="COLORPACKED") {
- stride+=1; //ignore
- } else if (attr=="TANGENT") {
- exists[Mesh::ARRAY_TANGENT]=true;
- ofs[Mesh::ARRAY_TANGENT]=stride;
- stride+=3;
- } else if (attr=="BINORMAL") {
- binormal_ofs=stride;
- stride+=3;
- } else if (attr=="TEXCOORD0") {
- exists[Mesh::ARRAY_TEX_UV]=true;
- ofs[Mesh::ARRAY_TEX_UV]=stride;
- stride+=2;
- } else if (attr=="TEXCOORD1") {
- exists[Mesh::ARRAY_TEX_UV2]=true;
- ofs[Mesh::ARRAY_TEX_UV2]=stride;
- stride+=2;
- } else if (attr.begins_with("TEXCOORD")) {
- stride+=2;
- } else if (attr.begins_with("BLENDWEIGHT")) {
- int idx=attr.replace("BLENDWEIGHT","").to_int();
- if (idx==0) {
- exists[Mesh::ARRAY_BONES]=true;
- ofs[Mesh::ARRAY_BONES]=stride;
- exists[Mesh::ARRAY_WEIGHTS]=true;
- ofs[Mesh::ARRAY_WEIGHTS]=stride+1;
- } if (idx<4) {
- weight_ofs[idx]=stride;
- weight_max=MAX(weight_max,idx+1);
- }
-
- stride+=2;
- }
-
- print_line("ATTR "+attr+" OFS: "+itos(stride));
-
- }
-
- Array parts=mesh["parts"];
-
- for(int j=0;j<parts.size();j++) {
-
-
-
- Dictionary part=parts[j];
- ERR_CONTINUE(!part.has("indices"));
- ERR_CONTINUE(!part.has("id"));
-
- print_line("PART: "+String(part["id"]));
- Array indices=part["indices"];
- Map<int,int> iarray;
- Map<int,int> array;
-
- for(int k=0;k<indices.size();k++) {
-
- int idx = indices[k];
- if (!iarray.has(idx)) {
- int map_to=array.size();
- iarray[idx]=map_to;
- array[map_to]=idx;
- }
- }
-
- print_line("indices total "+itos(indices.size())+" vertices used: "+itos(array.size()));
-
- Array arrays;
- arrays.resize(Mesh::ARRAY_MAX);
-
-
-
- for(int k=0;k<Mesh::ARRAY_MAX;k++) {
-
-
- if (!exists[k])
- continue;
- print_line("exists: "+itos(k));
- int lofs = ofs[k];
- switch(k) {
-
- case Mesh::ARRAY_VERTEX:
- case Mesh::ARRAY_NORMAL: {
-
- PoolVector<Vector3> vtx;
- vtx.resize(array.size());
- {
- int len=array.size();
- PoolVector<Vector3>::Write w = vtx.write();
- for(int l=0;l<len;l++) {
-
- int pos = array[l];
- w[l].x=vertices[pos*stride+lofs+0];
- w[l].y=vertices[pos*stride+lofs+1];
- w[l].z=vertices[pos*stride+lofs+2];
- }
- }
- arrays[k]=vtx;
-
- } break;
- case Mesh::ARRAY_TANGENT: {
-
- if (binormal_ofs<0)
- break;
-
- PoolVector<float> tangents;
- tangents.resize(array.size()*4);
- {
- int len=array.size();
-
- PoolVector<float>::Write w = tangents.write();
- for(int l=0;l<len;l++) {
-
- int pos = array[l];
- Vector3 n;
- n.x=vertices[pos*stride+ofs[Mesh::ARRAY_NORMAL]+0];
- n.y=vertices[pos*stride+ofs[Mesh::ARRAY_NORMAL]+1];
- n.z=vertices[pos*stride+ofs[Mesh::ARRAY_NORMAL]+2];
- Vector3 t;
- t.x=vertices[pos*stride+lofs+0];
- t.y=vertices[pos*stride+lofs+1];
- t.z=vertices[pos*stride+lofs+2];
- Vector3 bi;
- bi.x=vertices[pos*stride+binormal_ofs+0];
- bi.y=vertices[pos*stride+binormal_ofs+1];
- bi.z=vertices[pos*stride+binormal_ofs+2];
- float d = bi.dot(n.cross(t));
-
- w[l*4+0]=t.x;
- w[l*4+1]=t.y;
- w[l*4+2]=t.z;
- w[l*4+3]=d;
-
- }
- }
- arrays[k]=tangents;
-
- } break;
- case Mesh::ARRAY_COLOR: {
-
- PoolVector<Color> cols;
- cols.resize(array.size());
- {
- int len=array.size();
- PoolVector<Color>::Write w = cols.write();
- for(int l=0;l<len;l++) {
-
- int pos = array[l];
- w[l].r=vertices[pos*stride+lofs+0];
- w[l].g=vertices[pos*stride+lofs+1];
- w[l].b=vertices[pos*stride+lofs+2];
- w[l].a=vertices[pos*stride+lofs+3];
- }
- }
- arrays[k]=cols;
-
- } break;
- case Mesh::ARRAY_TEX_UV:
- case Mesh::ARRAY_TEX_UV2: {
-
- PoolVector<Vector2> uvs;
- uvs.resize(array.size());
- {
- int len=array.size();
- PoolVector<Vector2>::Write w = uvs.write();
- for(int l=0;l<len;l++) {
-
- int pos = array[l];
- w[l].x=vertices[pos*stride+lofs+0];
- w[l].y=vertices[pos*stride+lofs+1];
- w[l].y=1.0-w[l].y;
- }
- }
- arrays[k]=uvs;
-
- } break;
- case Mesh::ARRAY_BONES:
- case Mesh::ARRAY_WEIGHTS: {
-
- PoolVector<float> arr;
- arr.resize(array.size()*4);
- int po=k==Mesh::ARRAY_WEIGHTS?1:0;
- lofs=ofs[Mesh::ARRAY_BONES];
- {
- int len=array.size();
-
- PoolVector<float>::Write w = arr.write();
- for(int l=0;l<len;l++) {
-
- int pos = array[l];
-
- for(int m=0;m<4;m++) {
-
- float val=0;
- if (m<=weight_max)
- val=vertices[pos*stride+lofs+m*2+po];
- w[l*4+m]=val;
- }
- }
- }
-
- arrays[k]=arr;
- } break;
- case Mesh::ARRAY_INDEX: {
-
- PoolVector<int> arr;
- arr.resize(indices.size());
- {
- int len=indices.size();
-
- PoolVector<int>::Write w = arr.write();
- for(int l=0;l<len;l++) {
-
- w[l]=iarray[ indices[l] ];
- }
- }
-
- arrays[k]=arr;
-
- } break;
-
-
- }
-
-
- }
-
- Mesh::PrimitiveType pt=Mesh::PRIMITIVE_TRIANGLES;
-
- if (part.has("type")) {
- String type=part["type"];
- if (type=="LINES")
- pt=Mesh::PRIMITIVE_LINES;
- else if (type=="POINTS")
- pt=Mesh::PRIMITIVE_POINTS;
- else if (type=="TRIANGLE_STRIP")
- pt=Mesh::PRIMITIVE_TRIANGLE_STRIP;
- else if (type=="LINE_STRIP")
- pt=Mesh::PRIMITIVE_LINE_STRIP;
- }
-
- if (pt==Mesh::PRIMITIVE_TRIANGLES) {
- PoolVector<int> ia=arrays[Mesh::ARRAY_INDEX];
- int len=ia.size();
- {
- PoolVector<int>::Write w=ia.write();
- for(int l=0;l<len;l+=3) {
- SWAP(w[l+1],w[l+2]);
- }
- }
- arrays[Mesh::ARRAY_INDEX]=ia;
-
-
- }
- SurfaceInfo si;
- si.array=arrays;
- si.primitive=pt;
- state.surface_cache[_id(part["id"])]=si;
-
- }
- }
-}
-
-
-Error EditorSceneImporterFBXConv::_parse_animations(State& state) {
-
- AnimationPlayer *ap = memnew( AnimationPlayer );
-
- state.scene->add_child(ap);
- ap->set_owner(state.scene);
-
- for(int i=0;i<state.animations.size();i++) {
-
- Dictionary anim = state.animations[i];
- ERR_CONTINUE(!anim.has("id"));
- Ref<Animation> an = memnew( Animation );
- an->set_name(_id(anim["id"]));
-
-
- if (anim.has("bones")) {
-
- Array bone_tracks = anim["bones"];
- for(int j=0;j<bone_tracks.size();j++) {
- Dictionary bone_track=bone_tracks[j];
- String bone = bone_track["boneId"];
- if (!bone_track.has("keyframes"))
- continue;
- if (!state.bones.has(bone))
- continue;
-
- Skeleton *sk = state.bones[bone].skeleton;
-
- if (!sk)
- continue;
- int bone_idx=sk->find_bone(bone);
- if (bone_idx==-1)
- continue;
-
-
-
- String path = state.scene->get_path_to(sk);
- path+=":"+bone;
- an->add_track(Animation::TYPE_TRANSFORM);
- int tidx = an->get_track_count()-1;
- an->track_set_path(tidx,path);
-
-
- Dictionary parent_xform_dict;
- Dictionary xform_dict;
-
- if (state.bones.has(bone)) {
- xform_dict=state.bones[bone].node;
- }
-
-
- Array parent_keyframes;
- if (sk->get_bone_parent(bone_idx)!=-1) {
- String parent_name = sk->get_bone_name(sk->get_bone_parent(bone_idx));
- if (state.bones.has(parent_name)) {
- parent_xform_dict=state.bones[parent_name].node;
- }
-
- print_line("parent for "+bone+"? "+parent_name+" XFD: "+String(Variant(parent_xform_dict)));
- for(int k=0;k<bone_tracks.size();k++) {
- Dictionary d = bone_tracks[k];
- if (d["boneId"]==parent_name) {
- parent_keyframes=d["keyframes"];
- print_line("found keyframes");
- break;
- }
- }
-
-
- }
-
- print_line("BONE XFD "+String(Variant(xform_dict)));
-
- Array keyframes=bone_track["keyframes"];
-
- for(int k=0;k<keyframes.size();k++) {
-
- Dictionary key=keyframes[k];
- Transform xform=_get_transform_mixed(key,xform_dict);
- float time = key["keytime"];
- time=time/1000.0;
-#if 0
- if (parent_keyframes.size()) {
- //localize
- print_line(itos(k)+" localizate for: "+bone);
-
- float prev_kt=-1;
- float kt;
- int idx=0;
-
- for(int l=0;l<parent_keyframes.size();l++) {
-
- Dictionary d=parent_keyframes[l];
- kt=d["keytime"];
- kt=kt/1000.0;
- if (kt>time)
- break;
- prev_kt=kt;
- idx++;
-
- }
-
- Transform t;
- if (idx==0) {
- t=_get_transform_mixed(parent_keyframes[0],parent_xform_dict);
- } else if (idx==parent_keyframes.size()){
- t=_get_transform_mixed(parent_keyframes[idx-1],parent_xform_dict);
- } else {
- t=_get_transform_mixed(parent_keyframes[idx-1],parent_xform_dict);
- float d = (time-prev_kt)/(kt-prev_kt);
- if (d>0) {
- Transform t2=_get_transform_mixed(parent_keyframes[idx],parent_xform_dict);
- t=t.interpolate_with(t2,d);
- } else {
- print_line("exact: "+rtos(kt));
- }
- }
-
- xform = t.affine_inverse() * xform; //localize
- } else if (!parent_xform_dict.empty()) {
- Transform t = _get_transform(parent_xform_dict);
- xform = t.affine_inverse() * xform; //localize
- }
-#endif
-
- xform = sk->get_bone_rest(bone_idx).affine_inverse() * xform;
-
-
- Quat q = xform.basis;
- q.normalize();
- Vector3 s = xform.basis.get_scale();
- Vector3 l = xform.origin;
-
-
-
- an->transform_track_insert_key(tidx,time,l,q,s);
-
- }
-
- }
-
-
- }
-
-
- ap->add_animation(_id(anim["id"]),an);
-
- }
-
- return OK;
-}
-
-Error EditorSceneImporterFBXConv::_parse_json(State& state, const String &p_path) {
-
- //not the happiest....
- Vector<uint8_t> data = FileAccess::get_file_as_array(p_path);
- ERR_FAIL_COND_V(!data.size(),ERR_FILE_CANT_OPEN);
- String str;
- bool utferr = str.parse_utf8((const char*)data.ptr(),data.size());
- ERR_FAIL_COND_V(utferr,ERR_PARSE_ERROR);
-
- Dictionary dict;
- Error err = dict.parse_json(str);
- str=String(); //free mem immediately
- ERR_FAIL_COND_V(err,err);
-
- if (dict.has("meshes"))
- state.meshes=dict["meshes"];
- if (dict.has("materials"))
- state.materials=dict["materials"];
- if (dict.has("nodes"))
- state.nodes=dict["nodes"];
- if (dict.has("animations"))
- state.animations=dict["animations"];
-
-
- state.scene = memnew( Spatial );
- _detect_bones(state);
- _parse_surfaces(state);
- _parse_materials(state);
- err = _parse_nodes(state,state.nodes,state.scene);
- if (err)
- return err;
-
- if (state.import_animations) {
- err = _parse_animations(state);
- if (err)
- return err;
- }
-
- print_line("JSON PARSED O-K!");
-
- return OK;
-}
-
-Error EditorSceneImporterFBXConv::_parse_fbx(State& state,const String& p_path) {
-
- state.base_path=p_path.get_base_dir();
-
- if (p_path.to_lower().ends_with("g3dj")) {
- return _parse_json(state,p_path.basename()+".g3dj");
- }
-
- String tool = EDITOR_DEF("fbxconv/path","");
- ERR_FAIL_COND_V( !FileAccess::exists(tool),ERR_UNCONFIGURED);
- String wine = EDITOR_DEF("fbxconv/use_wine","");
-
- List<String> args;
- String path=p_path;
- if (wine!="") {
- List<String> wpargs;
- wpargs.push_back("-w");
- wpargs.push_back(p_path);
- String pipe; //winepath to convert to windows path
- int wpres;
- Error wperr = OS::get_singleton()->execute(wine+"path",wpargs,true,NULL,&pipe,&wpres);
- ERR_FAIL_COND_V(wperr!=OK,ERR_CANT_CREATE);
- ERR_FAIL_COND_V(wpres!=0,ERR_CANT_CREATE);
- path=pipe.strip_edges();
- args.push_back(tool);
- tool=wine;
- }
-
- args.push_back("-o");
- args.push_back("G3DJ");
- args.push_back(path);
-
- int res;
- Error err = OS::get_singleton()->execute(tool,args,true,NULL,NULL,&res);
- ERR_FAIL_COND_V(err!=OK,ERR_CANT_CREATE);
- ERR_FAIL_COND_V(res!=0,ERR_CANT_CREATE);
-
- return _parse_json(state,p_path.basename()+".g3dj");
-
-
-}
-
-Node* EditorSceneImporterFBXConv::import_scene(const String& p_path,uint32_t p_flags,List<String> *r_missing_deps,Error* r_err){
-
- State state;
- state.scene=NULL;
- state.missing_deps=r_missing_deps;
- state.import_animations=p_flags&IMPORT_ANIMATION;
- Error err = _parse_fbx(state,p_path);
- if (err!=OK) {
- if (r_err)
- *r_err=err;
- return NULL;
- }
-
-
- return state.scene;
-}
-Ref<Animation> EditorSceneImporterFBXConv::import_animation(const String& p_path,uint32_t p_flags){
-
-
- return Ref<Animation>();
-}
-
-
-EditorSceneImporterFBXConv::EditorSceneImporterFBXConv() {
-
- EDITOR_DEF("fbxconv/path","");
-#ifndef WINDOWS_ENABLED
- EDITOR_DEF("fbxconv/use_wine","");
- EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"fbxconv/use_wine",PROPERTY_HINT_GLOBAL_FILE));
- EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"fbxconv/path",PROPERTY_HINT_GLOBAL_FILE));
-#else
- EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING,"fbxconv/path",PROPERTY_HINT_GLOBAL_FILE,"exe"));
-#endif
-
-}
-#endif
diff --git a/editor/io_plugins/editor_scene_importer_fbxconv.h b/editor/io_plugins/editor_scene_importer_fbxconv.h
deleted file mode 100644
index d7669db223..0000000000
--- a/editor/io_plugins/editor_scene_importer_fbxconv.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*************************************************************************/
-/* editor_scene_importer_fbxconv.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 EDITOR_SCENE_IMPORTER_FBXCONV_H
-#define EDITOR_SCENE_IMPORTER_FBXCONV_H
-
-#include "editor/io_plugins/editor_scene_import_plugin.h"
-#include "scene/3d/skeleton.h"
-
-#if 0
-
-class EditorSceneImporterFBXConv : public EditorSceneImporter {
-
- GDCLASS(EditorSceneImporterFBXConv,EditorSceneImporter );
-
-
- struct BoneInfo {
-
- Skeleton *skeleton;
- Transform rest;
- int index;
- bool has_anim_chan;
- bool has_rest;
- Dictionary node;
- BoneInfo() {
- has_rest=false;
- skeleton=NULL;
- index=-1;
- has_anim_chan=false;
- }
- };
-
- struct SurfaceInfo {
- Array array;
- Mesh::PrimitiveType primitive;
- };
-
- struct State {
-
- Node *scene;
- Array meshes;
- Array materials;
- Array nodes;
- Array animations;
- Map<String,BoneInfo > bones;
- Map<String,Skeleton*> skeletons;
- Map<String,Ref<Mesh> > mesh_cache;
- Map<String,SurfaceInfo> surface_cache;
- Map<String,Ref<Material> > material_cache;
- Map<String,Ref<Texture> > texture_cache;
- List<String> *missing_deps;
- String base_path;
- bool import_animations;
- };
-
- String _id(const String& p_id) const;
-
- Transform _get_transform_mixed(const Dictionary& d, const Dictionary& dbase);
- Transform _get_transform(const Dictionary& d);
- Color _get_color(const Array& a);
- void _detect_bones_in_nodes(State& state,const Array& p_nodes);
- void _detect_bones(State& state);
-
- Error _parse_bones(State& state,const Array &p_bones,Skeleton* p_skeleton);
- void _parse_skeletons(const String& p_name,State& state, const Array &p_nodes, Skeleton*p_skeleton=NULL, int p_parent=-1);
-
- void _add_surface(State& state,Ref<Mesh>& m,const Dictionary &part);
- Error _parse_nodes(State& state,const Array &p_nodes,Node* p_base);
- Error _parse_animations(State& state);
- void _parse_materials(State& state);
- void _parse_surfaces(State& state);
- Error _parse_json(State& state,const String& p_path);
- Error _parse_fbx(State &state, const String &p_path);
-
-public:
-
- virtual uint32_t get_import_flags() const;
- virtual void get_extensions(List<String> *r_extensions) const;
- virtual Node* import_scene(const String& p_path,uint32_t p_flags,List<String> *r_missing_deps=NULL,Error* r_err=NULL);
- virtual Ref<Animation> import_animation(const String& p_path,uint32_t p_flags);
-
- EditorSceneImporterFBXConv();
-};
-
-#endif // EDITOR_SCENE_IMPORTER_FBXCONV_H
-#endif
diff --git a/editor/io_plugins/editor_texture_import_plugin.cpp b/editor/io_plugins/editor_texture_import_plugin.cpp
deleted file mode 100644
index 43321a3217..0000000000
--- a/editor/io_plugins/editor_texture_import_plugin.cpp
+++ /dev/null
@@ -1,1896 +0,0 @@
-/*************************************************************************/
-/* editor_texture_import_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 "editor_texture_import_plugin.h"
-
-#if 0
-#include "editor/editor_node.h"
-#include "editor/editor_settings.h"
-#include "editor_atlas.h"
-#include "io/image_loader.h"
-#include "io/marshalls.h"
-#include "io/resource_saver.h"
-#include "project_settings.h"
-#include "scene/gui/button_group.h"
-#include "scene/gui/check_button.h"
-#include "scene/gui/margin_container.h"
-#include "scene/io/resource_format_image.h"
-
-#include "thirdparty/misc/md5.h"
-
-static const char *flag_names[]={
- ("Streaming Format"),
- ("Fix Border Alpha"),
- ("Alpha Bit Hint"),
- ("Compress Extra (PVRTC2)"),
- ("No MipMaps"),
- ("Repeat"),
- ("Filter (Magnifying)"),
- ("Premultiply Alpha"),
- ("Convert SRGB->Linear"),
- ("Convert NormalMap to XY"),
- ("Use Anisotropy"),
- NULL
-};
-
-#if 0 // not used
-static const char *flag_short_names[]={
- "Stream",
- "FixBorder",
- "AlphBit",
- "ExtComp",
- "NoMipMap",
- "Repeat",
- "Filter",
- "PMAlpha",
- "ToLinear",
- "ToRG",
- "Anisoropic",
- NULL
-};
-#endif
-
-
-void EditorImportTextureOptions::set_format(EditorTextureImportPlugin::ImageFormat p_format) {
-
- updating=true;
- format->select(p_format);
- if (p_format==EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY) {
- quality_vb->show();
- } else {
- quality_vb->hide();
- }
-
- updating=false;
-
-}
-
-EditorTextureImportPlugin::ImageFormat EditorImportTextureOptions::get_format() const{
-
- return (EditorTextureImportPlugin::ImageFormat)format->get_selected();
-
-}
-
-void EditorImportTextureOptions::set_flags(uint32_t p_flags){
-
- updating=true;
- for(int i=0;i<items.size();i++) {
-
- items[i]->set_checked(0,p_flags&(1<<i));
- }
- updating=false;
-
-}
-
-void EditorImportTextureOptions::set_quality(float p_quality) {
-
- quality->set_value(p_quality);
-}
-
-float EditorImportTextureOptions::get_quality() const {
-
- return quality->get_value();
-}
-
-
-uint32_t EditorImportTextureOptions::get_flags() const{
-
- uint32_t f=0;
- for(int i=0;i<items.size();i++) {
-
- if (items[i]->is_checked(0))
- f|=(1<<i);
- }
-
- return f;
-}
-
-void EditorImportTextureOptions::_changedp(int p_value) {
-
- _changed();
-}
-
-void EditorImportTextureOptions::_changed() {
-
- if (updating)
- return;
- if (format->get_selected()==EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY) {
- quality_vb->show();
- } else {
- quality_vb->hide();
- }
-
- emit_signal("changed");
-}
-
-
-void EditorImportTextureOptions::_bind_methods() {
-
- ClassDB::bind_method("_changed",&EditorImportTextureOptions::_changed);
- ClassDB::bind_method("_changedp",&EditorImportTextureOptions::_changedp);
-
- ADD_SIGNAL(MethodInfo("changed"));
-}
-
-
-void EditorImportTextureOptions::_notification(int p_what) {
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
-
- flags->connect("item_edited",this,"_changed");
- format->connect("item_selected",this,"_changedp");
- }
-}
-
-void EditorImportTextureOptions::show_2d_notice() {
-
- //notice_for_2d->show();
-}
-
-EditorImportTextureOptions::EditorImportTextureOptions() {
-
-
- add_constant_override("separation",3);
- updating=false;
- format = memnew( OptionButton );
-
- format->add_item(TTR("Uncompressed"),EditorTextureImportPlugin::IMAGE_FORMAT_UNCOMPRESSED);
- format->add_item(TTR("Compress Lossless (PNG)"),EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS);
- format->add_item(TTR("Compress Lossy (WebP)"),EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY);
- format->add_item(TTR("Compress (VRAM)"),EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM);
-
-
- add_margin_child(TTR("Texture Format"),format);
-
- quality_vb = memnew( VBoxContainer );
-
- HBoxContainer *quality_hb = memnew(HBoxContainer);
- HSlider *hs = memnew( HSlider );
- hs->set_h_size_flags(SIZE_EXPAND_FILL);
- hs->set_stretch_ratio(0.8);
- quality_hb->add_child(hs);
- quality_hb->set_h_size_flags(SIZE_EXPAND_FILL);
- SpinBox *sb = memnew( SpinBox );
- sb->set_h_size_flags(SIZE_EXPAND_FILL);
- sb->set_stretch_ratio(0.2);
- quality_hb->add_child(sb);
- sb->share(hs);
- hs->set_min(0);
- hs->set_max(1.0);
- hs->set_step(0.01);
- hs->set_value(0.7);
- quality=hs;
- quality_vb->add_margin_child(TTR("Texture Compression Quality (WebP):"),quality_hb);
-
- add_child(quality_vb);
-
- flags = memnew( Tree );
- flags->set_hide_root(true);
- TreeItem *root = flags->create_item();
-
-
-
- const char ** fname=flag_names;
-
- while( *fname ) {
-
- TreeItem*ti = flags->create_item(root);
- ti->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
- ti->set_text(0,*fname);
- ti->set_editable(0,true);
- items.push_back(ti);
- fname++;
- }
-
- add_margin_child(TTR("Texture Options"),flags,true);
-
-
-}
-
-///////////////////////////////////////////////////////////
-
-
-
-
-class EditorTextureImportDialog : public ConfirmationDialog {
-
- GDCLASS(EditorTextureImportDialog,ConfirmationDialog);
-
-
-
- HBoxContainer *mode_hb;
- CheckBox *mode_check[EditorTextureImportPlugin::MODE_MAX];
-
- EditorImportTextureOptions *texture_options;
-
- EditorTextureImportPlugin::Mode mode;
- //EditorNode *editor;
-
- LineEdit *import_path;
- LineEdit *save_path;
- EditorFileDialog *file_select;
- EditorFileDialog *save_file_select;
- EditorDirDialog *save_select;
- OptionButton *texture_action;
- ConfirmationDialog *error_dialog;
- CheckButton *crop_source;
- SpinBox *size;
-
- MarginContainer *size_mc;
- Label* size_label;
-
- Label* source_label;
- Label *notice_for_2d;
-
- EditorTextureImportPlugin *plugin;
-
- void _mode_changed(int p_mode);
- void _choose_files(const Vector<String>& p_path);
- void _choose_file(const String& p_path);
- void _choose_save_dir(const String& p_path);
- void _browse();
- void _browse_target();
- void _import();
-
-
-protected:
-
- void _notification(int p_what);
- static void _bind_methods();
-public:
-
-
- void setup_multiple_import_3d(const Vector<String>& p_path,const String& p_dest) {
-
- _mode_changed(EditorTextureImportPlugin::MODE_TEXTURE_3D);
- _choose_files(p_path);
- _choose_save_dir(p_dest);
- }
-
- void add_sources_and_dest(const Vector<String>& p_path,const String& p_dest) {
-
- _choose_files(p_path);
- _choose_save_dir(p_dest);
- }
-
- Error import(const String& p_from, const String& p_to, const String& p_preset);
- void popup_import(const String &p_from=String());
- EditorTextureImportDialog(EditorTextureImportPlugin *p_plugin=NULL);
-};
-
-
-/////////////////////////////////////////////////////////
-
-
-
-
-void EditorTextureImportDialog::_choose_files(const Vector<String>& p_path) {
-
- String files;
- for(int i=0;i<p_path.size();i++) {
-
- if (i>0)
- files+=",";
- files+=p_path[i];
- }
- /*
- if (p_path.size()) {
- String srctex=p_path[0];
- String ipath = EditorImportDB::get_singleton()->find_source_path(srctex);
-
- if (ipath!="")
- save_path->set_text(ipath.get_base_dir());
- }*/
- import_path->set_text(files);
-
-}
-
-
-
-void EditorTextureImportDialog::_choose_file(const String& p_path) {
-
-
- import_path->set_text(p_path);
-
-}
-void EditorTextureImportDialog::_choose_save_dir(const String& p_path) {
-
- save_path->set_text(p_path);
-}
-
-
-void EditorTextureImportDialog::_import() {
-
-
- //ImportMonitorBlock imb;
-
- Vector<String> files=import_path->get_text().split(",");
-
- if (!files.size()) {
-
- error_dialog->set_text(TTR("Please specify some files!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
- }
-
- String dst_path=save_path->get_text();
-
- if (save_path->get_text().strip_edges()=="") {
- error_dialog->set_text(TTR("Target path is empty."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (!save_path->get_text().begins_with("res://")) {
- error_dialog->set_text(TTR("Target path must be a complete resource path."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
-
- if (mode!=EditorTextureImportPlugin::MODE_ATLAS && mode!=EditorTextureImportPlugin::MODE_LARGE && !DirAccess::exists(save_path->get_text())) {
- error_dialog->set_text(TTR("Target path must exist."));
- error_dialog->popup_centered_minsize();
- return;
- }
-
- if (mode==EditorTextureImportPlugin::MODE_ATLAS) { //atlas
-
- if (files.size()==0) {
-
- error_dialog->set_text(TTR("At least one file needed for Atlas."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
-
- }
- String dst_file = dst_path;
- //dst_file=dst_file.basename()+".tex";
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- //imd->set_editor();
- for(int i=0;i<files.size();i++) {
- imd->add_source(EditorImportPlugin::validate_source_path(files[i]));
- }
- imd->set_option("format",texture_options->get_format());
- imd->set_option("flags",texture_options->get_flags());
- imd->set_option("quality",texture_options->get_quality());
- imd->set_option("atlas",true);
- imd->set_option("atlas_size",int(size->get_value()));
- imd->set_option("large",false);
- imd->set_option("crop",crop_source->is_pressed());
- imd->set_option("mode",mode);
-
- Error err = plugin->import(dst_file,imd);
- if (err) {
-
- error_dialog->set_text(TTR("Error importing:")+" "+dst_file.get_file());
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
-
- }
- } else if (mode==EditorTextureImportPlugin::MODE_LARGE) { //large
-
- if (files.size()!=1) {
-
- error_dialog->set_text(TTR("Only one file is required for large texture."));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
-
- }
- String dst_file = dst_path;
- //dst_file=dst_file.basename()+".tex";
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- //imd->set_editor();
- for(int i=0;i<files.size();i++) {
- imd->add_source(EditorImportPlugin::validate_source_path(files[i]));
- }
- imd->set_option("format",texture_options->get_format());
- imd->set_option("flags",texture_options->get_flags());
- imd->set_option("quality",texture_options->get_quality());
- imd->set_option("atlas",false);
- imd->set_option("large",true);
- imd->set_option("large_cell_size",int(size->get_value()));
- imd->set_option("crop",crop_source->is_pressed());
- imd->set_option("mode",mode);
-
- Error err = plugin->import(dst_file,imd);
- if (err) {
-
- error_dialog->set_text(TTR("Error importing:")+" "+dst_file.get_file());
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
-
- }
- } else {
-
-
- for(int i=0;i<files.size();i++) {
-
- String dst_file = dst_path.plus_file(files[i].get_file());
- dst_file=dst_file.get_basename()+".tex";
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- //imd->set_editor();
- imd->add_source(EditorImportPlugin::validate_source_path(files[i]));
- imd->set_option("format",texture_options->get_format());
- imd->set_option("flags",texture_options->get_flags());
- imd->set_option("quality",texture_options->get_quality());
- imd->set_option("atlas",false);
- imd->set_option("large",false);
- imd->set_option("mode",mode);
-
- Error err = plugin->import(dst_file,imd);
- if (err) {
-
- error_dialog->set_text(TTR("Error importing:")+" "+dst_file.get_file());
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
-
- }
- }
- }
-
- hide();
-}
-
-void EditorTextureImportDialog::_browse() {
-
- file_select->popup_centered_ratio();
-}
-
-void EditorTextureImportDialog::_browse_target() {
-
- if (mode==EditorTextureImportPlugin::MODE_ATLAS || mode==EditorTextureImportPlugin::MODE_LARGE) {
- save_file_select->popup_centered_ratio();
- } else {
- save_select->popup_centered_ratio();
- }
-
-}
-
-
-void EditorTextureImportDialog::popup_import(const String& p_from) {
-
- popup_centered(Size2(600,500)*EDSCALE);
- if (p_from!="") {
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from);
- ERR_FAIL_COND(!rimd.is_valid());
-
- if (rimd->has_option("mode")) {
- //new imported stuff uses this option
- _mode_changed(rimd->get_option("mode"));
- } else {
- //this one is for compatibility, will have to guess it
- if (rimd->has_option("atlas") && rimd->get_option("atlas")) {
- _mode_changed(EditorTextureImportPlugin::MODE_ATLAS);
- } else if (rimd->has_option("large") && rimd->get_option("large")) {
- _mode_changed(EditorTextureImportPlugin::MODE_LARGE);
- } else {
- //guess by usage of mipmaps..?
- _mode_changed(EditorTextureImportPlugin::MODE_TEXTURE_2D);
- }
-
- }
-
- if (mode==EditorTextureImportPlugin::MODE_ATLAS || mode==EditorTextureImportPlugin::MODE_LARGE)
- save_path->set_text(p_from);
- else
- save_path->set_text(p_from.get_base_dir());
-
- texture_options->set_format(EditorTextureImportPlugin::ImageFormat(int(rimd->get_option("format"))));
- texture_options->set_flags(rimd->get_option("flags"));
- texture_options->set_quality(rimd->get_option("quality"));
- String src = "";
- for(int i=0;i<rimd->get_source_count();i++) {
- if (i>0)
- src+=",";
- src+=EditorImportPlugin::expand_source_path(rimd->get_source_path(i));
- }
- import_path->set_text(src);
- }
-}
-
-
-void EditorTextureImportDialog::_notification(int p_what) {
-
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
-
-
- List<String> extensions;
- ImageLoader::get_recognized_extensions(&extensions);
- //ResourceLoader::get_recognized_extensions_for_type("PackedTexture",&extensions);
- file_select->clear_filters();
- for(int i=0;i<extensions.size();i++) {
-
- file_select->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
- }
- }
-}
-
-Error EditorTextureImportDialog::import(const String& p_from, const String& p_to, const String& p_preset) {
-
-
- import_path->set_text(p_from);
- save_path->set_text(p_to);
- _import();
-
- return OK;
-}
-
-void EditorTextureImportDialog::_mode_changed(int p_mode) {
-
- mode = EditorTextureImportPlugin::Mode(p_mode);
-
- for(int i=0;i<EditorTextureImportPlugin::MODE_MAX;i++) {
- mode_check[i]->set_pressed(i==mode);
- }
-
- if (p_mode==EditorTextureImportPlugin::MODE_ATLAS) {
-
- size_label->set_text(TTR("Max Texture Size:"));
- size->set_value(2048);
- crop_source->show();
- size_label->show();
- size->show();
-
- texture_options->set_flags(EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA|EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS|EditorTextureImportPlugin::IMAGE_FLAG_FILTER);
- texture_options->set_quality(0.7);
- texture_options->set_format(EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY);
- set_title(TTR("Import Textures for Atlas (2D)"));
-
- } else {
- crop_source->hide();
- }
-
-
- if (p_mode==EditorTextureImportPlugin::MODE_LARGE) {
-
- size_label->set_text(TTR("Cell Size:"));
- size->set_value(256);
- size_label->show();
- size->show();
-
- file_select->set_mode(EditorFileDialog::MODE_OPEN_FILE);
- save_file_select->add_filter("*.largetex;"+TTR("Large Texture"));
-
- texture_options->set_flags(EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA|EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS|EditorTextureImportPlugin::IMAGE_FLAG_FILTER);
- texture_options->set_quality(0.7);
- texture_options->set_format(EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS);
- set_title(TTR("Import Large Textures (2D)"));
- source_label->set_text(TTR("Source Texture"));
-
- } else {
- file_select->set_mode(EditorFileDialog::MODE_OPEN_FILES);
- save_file_select->add_filter("*.tex;"+TTR("Base Atlas Texture"));
- source_label->set_text(TTR("Source Texture(s)"));
- }
-
- if (p_mode==EditorTextureImportPlugin::MODE_TEXTURE_2D) {
-
- size_label->hide();
- size->hide();
-
- texture_options->set_flags(EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS|EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA|EditorTextureImportPlugin::IMAGE_FLAG_FILTER);
- texture_options->set_quality(0.7);
- texture_options->set_format(EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY);
- notice_for_2d->show();
- set_title(TTR("Import Textures for 2D"));
-
- } else {
- notice_for_2d->hide();
- }
-
- if (p_mode==EditorTextureImportPlugin::MODE_TEXTURE_3D) {
-
- size_label->hide();
- size->hide();
- //texture_options->set_flags(EditorTextureImportPlugin::IMAGE_FLAG_);
- //texture_options->set_flags(EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS);
- texture_options->set_flags(EditorTextureImportPlugin::IMAGE_FLAG_FIX_BORDER_ALPHA|EditorTextureImportPlugin::IMAGE_FLAG_FILTER|EditorTextureImportPlugin::IMAGE_FLAG_REPEAT);
- texture_options->set_format(EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM);
- set_title(TTR("Import Textures for 3D"));
- }
-}
-
-void EditorTextureImportDialog::_bind_methods() {
-
-
- ClassDB::bind_method("_choose_files",&EditorTextureImportDialog::_choose_files);
- ClassDB::bind_method("_choose_file",&EditorTextureImportDialog::_choose_file);
- ClassDB::bind_method("_choose_save_dir",&EditorTextureImportDialog::_choose_save_dir);
- ClassDB::bind_method("_import",&EditorTextureImportDialog::_import);
- ClassDB::bind_method("_browse",&EditorTextureImportDialog::_browse);
- ClassDB::bind_method("_browse_target",&EditorTextureImportDialog::_browse_target);
- ClassDB::bind_method("_mode_changed",&EditorTextureImportDialog::_mode_changed);
- //ADD_SIGNAL( MethodInfo("imported",PropertyInfo(Variant::OBJECT,"scene")) );
-}
-
-EditorTextureImportDialog::EditorTextureImportDialog(EditorTextureImportPlugin* p_plugin) {
-
-
-
-
-
- plugin=p_plugin;
- set_title(TTR("Import Textures"));
-
- mode_hb = memnew( HBoxContainer );
- add_child(mode_hb);
- //set_child_rect(mode_hb);
-
- VBoxContainer *vbcg = memnew( VBoxContainer);
-
-
- mode_hb->add_child(vbcg);
- mode_hb->add_constant_override("separation",15);
- VBoxContainer *bg = memnew( VBoxContainer );
- vbcg->add_margin_child("Import Mode",bg);
-
- for(int i=0;i<EditorTextureImportPlugin::MODE_MAX;i++) {
- String mode_name[EditorTextureImportPlugin::MODE_MAX]={
- TTR("2D Texture"),
- TTR("3D Texture"),
- TTR("Atlas Texture"),
- TTR("Large Texture")
- };
-
-
- mode_check[i]=memnew(CheckBox);
- bg->add_child(mode_check[i]);
- mode_check[i]->set_text(mode_name[i]);
- mode_check[i]->connect("pressed",this,"_mode_changed",varray(i));
- }
-
- VBoxContainer *vbc = memnew(VBoxContainer);
- mode_hb->add_child(vbc);
- vbc->set_h_size_flags(SIZE_EXPAND_FILL);
- vbc->add_constant_override("separation",4);
-
- notice_for_2d = memnew( Label );
- notice_for_2d->set_text(TTR("NOTICE: Importing 2D textures is not mandatory. Just copy png/jpg files to the project."));
- //notice_for_2d->set_custom_minimum_size(Size2(0,50));
- notice_for_2d->set_autowrap(true);
- notice_for_2d->hide();
- vbcg->add_child(notice_for_2d);
- notice_for_2d->set_v_size_flags(SIZE_EXPAND_FILL);
- notice_for_2d->set_valign(Label::VALIGN_BOTTOM);
-
- VBoxContainer *source_vb=memnew(VBoxContainer);
- MarginContainer *source_mc = vbc->add_margin_child(TTR("Source Texture(s):"),source_vb);
-
- source_label = Object::cast_to<Label>(vbc->get_child(source_mc->get_index()-1));
-
- HBoxContainer *hbc = memnew( HBoxContainer );
- source_vb->add_child(hbc);
-
- import_path = memnew( LineEdit );
- import_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(import_path);
- crop_source = memnew( CheckButton );
- crop_source->set_pressed(true);
- source_vb->add_child(crop_source);
- crop_source->set_text(TTR("Crop empty space."));
-
-
- Button * import_choose = memnew( Button );
- import_choose->set_text(" .. ");
- hbc->add_child(import_choose);
-
- import_choose->connect("pressed", this,"_browse");
-
- hbc = memnew( HBoxContainer );
- vbc->add_margin_child(TTR("Target Path:"),hbc);
-
- size = memnew( SpinBox );
- size->set_min(128);
- size->set_max(16384);
-
-
- size->set_value(256);
- size_mc=vbc->add_margin_child(TTR("Cell Size:"),size);
- size_label=Object::cast_to<Label>(vbc->get_child(size_mc->get_index()-1));
-
-
- save_path = memnew( LineEdit );
- save_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(save_path);
-
- Button * save_choose = memnew( Button );
- save_choose->set_text(" .. ");
- hbc->add_child(save_choose);
-
- save_choose->connect("pressed", this,"_browse_target");
-
- file_select = memnew(EditorFileDialog);
- file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
- add_child(file_select);
-
- file_select->connect("files_selected", this,"_choose_files");
- file_select->connect("file_selected", this,"_choose_file");
-
- save_file_select = memnew(EditorFileDialog);
- save_file_select->set_access(EditorFileDialog::ACCESS_RESOURCES);
- add_child(save_file_select);
- save_file_select->set_mode(EditorFileDialog::MODE_SAVE_FILE);
- save_file_select->clear_filters();
-
- save_file_select->connect("file_selected", this,"_choose_save_dir");
-
- save_select = memnew( EditorDirDialog );
- add_child(save_select);
-
- //save_select->set_mode(EditorFileDialog::MODE_OPEN_DIR);
- save_select->connect("dir_selected", this,"_choose_save_dir");
-
- get_ok()->connect("pressed", this,"_import");
- get_ok()->set_text(TTR("Import"));
-
- //move stuff up
- /*
- for(int i=0;i<4;i++)
- vbc->move_child( vbc->get_child( vbc->get_child_count() -1), 0);
- */
-
- error_dialog = memnew ( ConfirmationDialog );
- add_child(error_dialog);
- error_dialog->get_ok()->set_text(TTR("Accept"));
- //error_dialog->get_cancel()->hide();
-
- set_hide_on_ok(false);
-
- texture_options = memnew( EditorImportTextureOptions );
- vbc->add_child(texture_options);
- texture_options->set_v_size_flags(SIZE_EXPAND_FILL);
-
- _mode_changed(EditorTextureImportPlugin::MODE_TEXTURE_3D);
-
-
- //GLOBAL_DEF("import/shared_textures","res://");
- //Globals::get_singleton()->set_custom_property_info("import/shared_textures",PropertyInfo(Variant::STRING,"import/shared_textures",PROPERTY_HINT_DIR));
-
-
-}
-
-
-
-///////////////////////////////////////////////////////////
-
-
-String EditorTextureImportPlugin::get_name() const {
-
- return "texture";
-#if 0 //old names, kept for compatibility reference
- switch(mode) {
- case MODE_TEXTURE_2D: {
-
- return "texture_2d";
- } break;
- case MODE_TEXTURE_3D: {
-
- return "texture_3d";
-
- } break;
- case MODE_ATLAS: {
-
- return "texture_atlas";
- } break;
- case MODE_LARGE: {
-
- return "texture_large";
- } break;
-
- }
-
-
- return "";
-#endif
-}
-
-String EditorTextureImportPlugin::get_visible_name() const {
-
- return TTR("Texture");
-
-}
-void EditorTextureImportPlugin::import_dialog(const String& p_from) {
-
- dialog->popup_import(p_from);
-}
-
-void EditorTextureImportPlugin::compress_image(EditorExportPlatform::ImageCompression p_mode,Image& image,bool p_smaller) {
-
-
- switch(p_mode) {
- case EditorExportPlatform::IMAGE_COMPRESSION_NONE: {
-
- //do absolutely nothing
-
- } break;
- case EditorExportPlatform::IMAGE_COMPRESSION_BC: {
-
-
- // for maximum compatibility, BC shall always use mipmaps and be PO2
- image.resize_to_po2();
- if (!image.has_mipmaps())
- image.generate_mipmaps();
-
- image.compress(Image::COMPRESS_S3TC);
- /*
- if (has_alpha) {
-
- if (flags&IMAGE_FLAG_ALPHA_BIT) {
- image.convert(Image::FORMAT_DXT5);
- } else {
- image.convert(Image::FORMAT_DXT3);
- }
- } else {
-
- image.convert(Image::FORMAT_DXT1);
- }*/
-
-
- } break;
- case EditorExportPlatform::IMAGE_COMPRESSION_PVRTC:
- case EditorExportPlatform::IMAGE_COMPRESSION_PVRTC_SQUARE: {
-
- // for maximum compatibility (hi apple!), PVRT shall always
- // use mipmaps, be PO2 and square
-
- if (!image.has_mipmaps())
- image.generate_mipmaps();
- image.resize_to_po2(true);
-
- if (p_smaller) {
-
- image.compress(Image::COMPRESS_PVRTC2);
- //image.convert(has_alpha ? Image::FORMAT_PVRTC2A : Image::FORMAT_PVRTC2);
- } else {
- image.compress(Image::COMPRESS_PVRTC4);
- //image.convert(has_alpha ? Image::FORMAT_PVRTC4A : Image::FORMAT_PVRTC4);
- }
-
- } break;
- case EditorExportPlatform::IMAGE_COMPRESSION_ETC1: {
-
- image.resize_to_po2(); //square or not?
- if (!image.has_mipmaps())
- image.generate_mipmaps();
- if (!image.detect_alpha()) {
- //ETC1 is only opaque
- image.compress(Image::COMPRESS_ETC);
- }
-
- } break;
- case EditorExportPlatform::IMAGE_COMPRESSION_ETC2: {
-
-
- } break;
- }
-
-
-}
-
-Error EditorTextureImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from) {
-
-
- return import2(p_path,p_from,EditorExportPlatform::IMAGE_COMPRESSION_BC,false);
-}
-
-
-Error EditorTextureImportPlugin::_process_texture_data(Ref<ImageTexture> &texture,int format, float quality,int flags,EditorExportPlatform::ImageCompression p_compr,int tex_flags,float shrink) {
-
-
- if (format==IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS || format==IMAGE_FORMAT_COMPRESS_DISK_LOSSY) {
-
- Image image=texture->get_data();
- ERR_FAIL_COND_V(image.empty(),ERR_INVALID_DATA);
-
- bool has_alpha=image.detect_alpha();
- if (!has_alpha && image.get_format()==Image::FORMAT_RGBA8) {
-
- image.convert(Image::FORMAT_RGB8);
-
- }
-
- if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
-
- image.fix_alpha_edges();
- }
-
- if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_PREMULT_ALPHA) {
-
- image.premultiply_alpha();
- }
-
- if (flags&IMAGE_FLAG_CONVERT_NORMAL_TO_XY) {
- image.normalmap_to_xy();
- }
-
- /*
- if ((image.get_format()==Image::FORMAT_RGB8 || image.get_format()==Image::FORMAT_RGBA8) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
-
- image.srgb_to_linear();
- }
- */
-
- if (shrink>1) {
-
- int orig_w=image.get_width();
- int orig_h=image.get_height();
- image.resize(orig_w/shrink,orig_h/shrink,Image::INTERPOLATE_CUBIC);
- texture->create_from_image(image,tex_flags);
- texture->set_size_override(Size2(orig_w,orig_h));
-
-
- } else {
-
- texture->create_from_image(image,tex_flags);
- }
-
-
- if (format==IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS) {
- texture->set_storage(ImageTexture::STORAGE_COMPRESS_LOSSLESS);
- } else {
- texture->set_storage(ImageTexture::STORAGE_COMPRESS_LOSSY);
- }
-
-
-
- texture->set_lossy_storage_quality(quality);
-
-
- } else {
-
-
- Image image=texture->get_data();
- ERR_FAIL_COND_V(image.empty(),ERR_INVALID_DATA);
-
-
- bool has_alpha=image.detect_alpha();
- if (!has_alpha && image.get_format()==Image::FORMAT_RGBA8) {
-
- image.convert(Image::FORMAT_RGB8);
-
- }
-
- if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
-
- image.fix_alpha_edges();
- }
-
- if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_PREMULT_ALPHA) {
-
- image.premultiply_alpha();
- }
-
- if (flags&IMAGE_FLAG_CONVERT_NORMAL_TO_XY) {
- image.normalmap_to_xy();
- }
-
- /*
- if ((image.get_format()==Image::FORMAT_RGB8 || image.get_format()==Image::FORMAT_RGBA8) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
-
- print_line("CONVERT BECAUSE: "+itos(flags));
- image.srgb_to_linear();
- }
- */
-
- int orig_w=image.get_width();
- int orig_h=image.get_height();
-
- if (shrink>1) {
- image.resize(orig_w/shrink,orig_h/shrink,Image::INTERPOLATE_CUBIC);
- texture->create_from_image(image,tex_flags);
- texture->set_size_override(Size2(orig_w,orig_h));
- }
-
- if (!(flags&IMAGE_FLAG_NO_MIPMAPS)) {
- image.generate_mipmaps();
-
- }
-
- if (format!=IMAGE_FORMAT_UNCOMPRESSED) {
-
- compress_image(p_compr,image,flags&IMAGE_FLAG_COMPRESS_EXTRA);
- }
-
-
- texture->create_from_image(image,tex_flags);
-
-
- if (shrink>1 || (format!=IMAGE_FORMAT_UNCOMPRESSED && (image.get_width()!=orig_w || image.get_height()!=orig_h))) {
- texture->set_size_override(Size2(orig_w,orig_h));
- }
-
- //uint32_t save_flags=ResourceSaver::FLAG_COMPRESS;
- }
-
- return OK;
-}
-
-
-Error EditorTextureImportPlugin::import2(const String& p_path, const Ref<ResourceImportMetadata>& p_from,EditorExportPlatform::ImageCompression p_compr, bool p_external){
-
-
-
- ERR_FAIL_COND_V(p_from->get_source_count()==0,ERR_INVALID_PARAMETER);
-
- Ref<ResourceImportMetadata> from=p_from;
-
- Ref<ImageTexture> texture;
- Vector<Ref<AtlasTexture> > atlases;
- bool atlas = from->get_option("atlas");
- bool large = from->get_option("large");
-
- int flags=from->get_option("flags");
- int format=from->get_option("format");
- float quality=from->get_option("quality");
-
- uint32_t tex_flags=0;
-
- if (flags&EditorTextureImportPlugin::IMAGE_FLAG_REPEAT)
- tex_flags|=Texture::FLAG_REPEAT;
- if (flags&EditorTextureImportPlugin::IMAGE_FLAG_FILTER)
- tex_flags|=Texture::FLAG_FILTER;
- if (!(flags&EditorTextureImportPlugin::IMAGE_FLAG_NO_MIPMAPS))
- tex_flags|=Texture::FLAG_MIPMAPS;
- if (flags&EditorTextureImportPlugin::IMAGE_FLAG_CONVERT_TO_LINEAR)
- tex_flags|=Texture::FLAG_CONVERT_TO_LINEAR;
- if (flags&EditorTextureImportPlugin::IMAGE_FLAG_USE_ANISOTROPY)
- tex_flags|=Texture::FLAG_ANISOTROPIC_FILTER;
-
- print_line("path: "+p_path+" flags: "+itos(tex_flags));
- float shrink=1;
- if (from->has_option("shrink"))
- shrink=from->get_option("shrink");
-
- if (large) {
- ERR_FAIL_COND_V(from->get_source_count()!=1,ERR_INVALID_PARAMETER);
-
- String src_path = EditorImportPlugin::expand_source_path(from->get_source_path(0));
-
-
- int cell_size=from->get_option("large_cell_size");
- ERR_FAIL_COND_V(cell_size<128 || cell_size>16384,ERR_CANT_OPEN);
-
- EditorProgress pg("largetex",TTR("Import Large Texture"),3);
-
- pg.step(TTR("Load Source Image"),0);
- Image img;
- Error err = ImageLoader::load_image(src_path,&img);
- if (err) {
- return err;
- }
-
- pg.step(TTR("Slicing"),1);
-
- Map<Vector2,Image> pieces;
- for(int i=0;i<img.get_width();i+=cell_size) {
- int w = MIN(img.get_width()-i,cell_size);
- for(int j=0;j<img.get_height();j+=cell_size) {
- int h = MIN(img.get_height()-j,cell_size);
-
- Image piece(w,h,0,img.get_format());
- piece.blit_rect(img,Rect2(i,j,w,h),Point2(0,0));
- if (!piece.is_invisible()) {
- pieces[Vector2(i,j)]=piece;
- //print_line("ADDING PIECE AT "+Vector2(i,j));
- }
- }
- }
-
- Ref<LargeTexture> existing;
- if (ResourceCache::has(p_path)) {
- existing = ResourceCache::get(p_path);
- }
-
- if (existing.is_valid()) {
- existing->clear();
- } else {
- existing = Ref<LargeTexture>(memnew( LargeTexture ));
- }
-
- existing->set_size(Size2(img.get_width(),img.get_height()));
- pg.step(TTR("Inserting"),2);
-
- for (Map<Vector2,Image>::Element *E=pieces.front();E;E=E->next()) {
-
- Ref<ImageTexture> imgtex = Ref<ImageTexture>( memnew( ImageTexture ) );
- imgtex->create_from_image(E->get(),tex_flags);
- _process_texture_data(imgtex,format,quality,flags,p_compr,tex_flags,shrink);
- existing->add_piece(E->key(),imgtex);
- }
-
- if (!p_external) {
- from->set_editor(get_name());
- from->set_source_md5(0,FileAccess::get_md5(src_path));
- existing->set_path(p_path);
- existing->set_import_metadata(from);
- }
- pg.step(TTR("Saving"),3);
-
- err = ResourceSaver::save(p_path,existing);
- if (err!=OK) {
- EditorNode::add_io_error(TTR("Couldn't save large texture:")+" "+p_path);
- return err;
- }
-
- return OK;
-
-
- } else if (atlas) {
-
- //prepare atlas!
- Vector< Image > sources;
- Vector< Image > tsources;
- bool alpha=false;
- bool crop = from->get_option("crop");
-
- EditorProgress ep("make_atlas",TTR("Build Atlas For:")+" "+p_path.get_file(),from->get_source_count()+3);
-
- print_line("sources: "+itos(from->get_source_count()));
-
- for(int i=0;i<from->get_source_count();i++) {
-
- String path = EditorImportPlugin::expand_source_path(from->get_source_path(i));
- String md5 = FileAccess::get_md5(path);
- from->set_source_md5(i,FileAccess::get_md5(path));
- ep.step(TTR("Loading Image:")+" "+path,i);
- print_line("source path: "+path+" md5 "+md5);
- Image src;
- Error err = ImageLoader::load_image(path,&src);
- if (err) {
- EditorNode::add_io_error(TTR("Couldn't load image:")+" "+path);
- return err;
- }
-
- if (src.detect_alpha())
- alpha=true;
-
- tsources.push_back(src);
- }
- ep.step(TTR("Converting Images"),sources.size());
-
-
- Map<uint64_t,int> source_md5;
- Map<int,List<int> > source_map;
-
- for(int i=0;i<tsources.size();i++) {
-
- Image src = tsources[i];
-
- if (alpha) {
- src.convert(Image::FORMAT_RGBA8);
- } else {
- src.convert(Image::FORMAT_RGB8);
- }
-
- PoolVector<uint8_t> data = src.get_data();
- MD5_CTX md5;
- PoolVector<uint8_t>::Read r=data.read();
- MD5Init(&md5);
- int len=data.size();
- for(int j=0;j<len;j++) {
- uint8_t b = r[j];
- b>>=2; //to aid in comparing
- MD5Update(&md5,(unsigned char*)&b,1);
- }
- MD5Final(&md5);
- uint64_t *cmp = (uint64_t*)md5.digest; //less bits, but still useful for this
-
- tsources[i]=Image(); //clear
-
- if (source_md5.has(*cmp)) {
- int sidx=source_md5[*cmp];
- source_map[sidx].push_back(i);
- print_line("REUSING "+from->get_source_path(i));
-
- } else {
- int sidx=sources.size();
- source_md5[*cmp]=sidx;
- sources.push_back(src);
- List<int> sm;
- sm.push_back(i);
- source_map[sidx]=sm;
-
- }
-
-
- }
-
- //texturepacker is not really good for optimizing, so..
- //will at some point likely replace with my own
- //first, will find the nearest to a square packing
- int border=1;
-
- Vector<Size2i> src_sizes;
- Vector<Rect2> crops;
-
- ep.step(TTR("Cropping Images"),sources.size()+1);
-
- for(int j=0;j<sources.size();j++) {
-
- Size2i s;
- if (crop) {
- Rect2 crop = sources[j].get_used_rect();
- print_line("CROP: "+crop);
- s=crop.size;
- crops.push_back(crop);
- } else {
-
- s=Size2i(sources[j].get_width(),sources[j].get_height());
- }
- s+=Size2i(border*2,border*2);
- src_sizes.push_back(s); //add a line to constraint width
- }
-
- Vector<Point2i> dst_positions;
- Size2i dst_size;
- EditorAtlas::fit(src_sizes,dst_positions,dst_size);
-
- print_line("size that worked: "+itos(dst_size.width)+","+itos(dst_size.height));
-
- ep.step(TTR("Blitting Images"),sources.size()+2);
-
- bool blit_to_po2=tex_flags&Texture::FLAG_MIPMAPS;
- int atlas_w=dst_size.width;
- int atlas_h=dst_size.height;
- if (blit_to_po2) {
- atlas_w=next_power_of_2(dst_size.width);
- atlas_h=next_power_of_2(dst_size.height);
- }
- Image atlas;
- atlas.create(atlas_w,atlas_h,0,alpha?Image::FORMAT_RGBA8:Image::FORMAT_RGB8);
-
-
- atlases.resize(from->get_source_count());
-
- for(int i=0;i<sources.size();i++) {
-
- int x=dst_positions[i].x;
- int y=dst_positions[i].y;
-
- Size2 sz = Size2(sources[i].get_width(),sources[i].get_height());
-
- Rect2 region;
- Rect2 margin;
-
- if (crop && sz!=crops[i].size) {
- Rect2 rect = crops[i];
- rect.size=sz-rect.size;
- region=Rect2(x+border,y+border,crops[i].size.width,crops[i].size.height);
- margin=rect;
- atlas.blit_rect(sources[i],crops[i],Point2(x+border,y+border));
- } else {
- region=Rect2(x+border,y+border,sz.x,sz.y);
- atlas.blit_rect(sources[i],Rect2(0,0,sources[i].get_width(),sources[i].get_height()),Point2(x+border,y+border));
- }
-
- ERR_CONTINUE( !source_map.has(i) );
- for (List<int>::Element *E=source_map[i].front();E;E=E->next()) {
-
- String apath;
- String spath = from->get_source_path(E->get()).get_file();
-
- if (p_external) {
- apath = p_path.get_base_dir().plus_file(spath.get_basename()+"."+from->get_source_path(E->get()).md5_text()+".atlastex");
- } else {
- apath = p_path.get_base_dir().plus_file(spath.get_basename()+".atlastex");
- }
-
- Ref<AtlasTexture> at;
-
- if (ResourceCache::has(apath)) {
-
- at = Ref<AtlasTexture>( Object::cast_to<AtlasTexture>(ResourceCache::get(apath)) );
- } else {
-
- at = Ref<AtlasTexture>( memnew( AtlasTexture ) );
-
- }
- at->set_region(region);
- at->set_margin(margin);
- at->set_path(apath);
- atlases[E->get()]=at;
-
- }
- }
- if (ResourceCache::has(p_path)) {
- texture = Ref<ImageTexture> ( Object::cast_to<ImageTexture>(ResourceCache::get(p_path)) );
- } else {
- texture = Ref<ImageTexture>( memnew( ImageTexture ) );
- }
- texture->create_from_image(atlas,tex_flags);
-
- } else {
- ERR_FAIL_COND_V(from->get_source_count()!=1,ERR_INVALID_PARAMETER);
-
- String src_path = EditorImportPlugin::expand_source_path(from->get_source_path(0));
-
- if (ResourceCache::has(p_path)) {
- Resource *r = ResourceCache::get(p_path);
-
- texture = Ref<ImageTexture> ( Object::cast_to<ImageTexture>(r) );
-
- Image img;
- Error err = img.load(src_path);
- ERR_FAIL_COND_V(err!=OK,ERR_CANT_OPEN);
- texture->create_from_image(img);
- } else {
- texture=ResourceLoader::load(src_path,"ImageTexture");
- }
-
- ERR_FAIL_COND_V(texture.is_null(),ERR_CANT_OPEN);
- if (!p_external)
- from->set_source_md5(0,FileAccess::get_md5(src_path));
-
- }
-
-
-
- if (!p_external) {
- from->set_editor(get_name());
- texture->set_path(p_path);
- texture->set_import_metadata(from);
- }
-
- if (atlas) {
-
- if (p_external) {
- //used by exporter
- Array rects;
- for(int i=0;i<atlases.size();i++) {
- rects.push_back(atlases[i]->get_region());
- rects.push_back(atlases[i]->get_margin());
- }
- from->set_option("rects",rects);
-
- } else {
- //used by importer
- for(int i=0;i<atlases.size();i++) {
- String apath = atlases[i]->get_path();
- atlases[i]->set_atlas(texture);
- Error err = ResourceSaver::save(apath,atlases[i]);
- if (err) {
- EditorNode::add_io_error(TTR("Couldn't save atlas image:")+" "+apath);
- return err;
- }
- //from->set_source_md5(i,FileAccess::get_md5(apath));
- }
- }
- }
-
- bool compress=false;
-#if 1
-
- _process_texture_data(texture,format,quality,flags,p_compr,tex_flags,shrink);
-#else
- if (format==IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS || format==IMAGE_FORMAT_COMPRESS_DISK_LOSSY) {
-
- Image image=texture->get_data();
- ERR_FAIL_COND_V(image.empty(),ERR_INVALID_DATA);
-
- bool has_alpha=image.detect_alpha();
- if (!has_alpha && image.get_format()==Image::FORMAT_RGBA8) {
-
- image.convert(Image::FORMAT_RGB8);
-
- }
-
- if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
-
- image.fix_alpha_edges();
- }
-
- if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_PREMULT_ALPHA) {
-
- image.premultiply_alpha();
- }
-
- if (flags&IMAGE_FLAG_CONVERT_NORMAL_TO_XY) {
- image.normalmap_to_xy();
- }
-
- /*
- if ((image.get_format()==Image::FORMAT_RGB8 || image.get_format()==Image::FORMAT_RGBA8) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
-
- image.srgb_to_linear();
- }
- */
-
- if (shrink>1) {
-
- int orig_w=image.get_width();
- int orig_h=image.get_height();
- image.resize(orig_w/shrink,orig_h/shrink);
- texture->create_from_image(image,tex_flags);
- texture->set_size_override(Size2(orig_w,orig_h));
-
-
- } else {
-
- texture->create_from_image(image,tex_flags);
- }
-
-
- if (format==IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS) {
- texture->set_storage(ImageTexture::STORAGE_COMPRESS_LOSSLESS);
- } else {
- texture->set_storage(ImageTexture::STORAGE_COMPRESS_LOSSY);
- }
-
-
-
- texture->set_lossy_storage_quality(quality);
-
-
- } else {
-
-
- Image image=texture->get_data();
- ERR_FAIL_COND_V(image.empty(),ERR_INVALID_DATA);
-
-
- bool has_alpha=image.detect_alpha();
- if (!has_alpha && image.get_format()==Image::FORMAT_RGBA8) {
-
- image.convert(Image::FORMAT_RGB8);
-
- }
-
- if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_FIX_BORDER_ALPHA) {
-
- image.fix_alpha_edges();
- }
-
- if (image.get_format()==Image::FORMAT_RGBA8 && flags&IMAGE_FLAG_PREMULT_ALPHA) {
-
- image.premultiply_alpha();
- }
-
- if (flags&IMAGE_FLAG_CONVERT_NORMAL_TO_XY) {
- image.normalmap_to_xy();
- }
-
- /*
- if ((image.get_format()==Image::FORMAT_RGB8 || image.get_format()==Image::FORMAT_RGBA8) && flags&IMAGE_FLAG_CONVERT_TO_LINEAR) {
-
- print_line("CONVERT BECAUSE: "+itos(flags));
- image.srgb_to_linear();
- }
- */
-
- int orig_w=image.get_width();
- int orig_h=image.get_height();
-
- if (shrink>1) {
- image.resize(orig_w/shrink,orig_h/shrink);
- texture->create_from_image(image,tex_flags);
- texture->set_size_override(Size2(orig_w,orig_h));
- }
-
- if (!(flags&IMAGE_FLAG_NO_MIPMAPS)) {
- image.generate_mipmaps();
-
- }
-
- if (format!=IMAGE_FORMAT_UNCOMPRESSED) {
-
- compress_image(p_compr,image,flags&IMAGE_FLAG_COMPRESS_EXTRA);
- }
-
-
- texture->create_from_image(image,tex_flags);
-
-
- if (shrink>1 || (format!=IMAGE_FORMAT_UNCOMPRESSED && (image.get_width()!=orig_w || image.get_height()!=orig_h))) {
- texture->set_size_override(Size2(orig_w,orig_h));
- }
-
- compress=true;
-
-
- }
-#endif
- uint32_t save_flags=0;
- if (compress)
- save_flags=ResourceSaver::FLAG_COMPRESS;
-
- Error err = ResourceSaver::save(p_path,texture,save_flags);
- if (err!=OK) {
- EditorNode::add_io_error(TTR("Couldn't save converted texture:")+" "+p_path);
- return err;
- }
-
- return OK;
-}
-
-Vector<uint8_t> EditorTextureImportPlugin::custom_export(const String& p_path, const Ref<EditorExportPlatform> &p_platform) {
-
-
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
-
- if (rimd.is_null()) {
-
- StringName group = EditorImportExport::get_singleton()->image_get_export_group(p_path);
-
- if (group!=StringName()) {
- //handled by export group
- rimd = Ref<ResourceImportMetadata>( memnew( ResourceImportMetadata ) );
-
- int group_format=0;
- float group_lossy_quality=EditorImportExport::get_singleton()->image_export_group_get_lossy_quality(group);
- int group_shrink=EditorImportExport::get_singleton()->image_export_group_get_shrink(group);
- group_shrink*=EditorImportExport::get_singleton()->get_export_image_shrink();
-
- switch(EditorImportExport::get_singleton()->image_export_group_get_image_action(group)) {
- case EditorImportExport::IMAGE_ACTION_NONE: {
-
- switch(EditorImportExport::get_singleton()->get_export_image_action()) {
- case EditorImportExport::IMAGE_ACTION_NONE: {
-
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS; //?
-
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: {
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY;
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: {
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM;
- } break; //use default
- }
-
- group_lossy_quality=EditorImportExport::get_singleton()->get_export_image_quality();
-
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: {
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_DISK_LOSSY;
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: {
- group_format=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM;
- } break; //use default
- case EditorImportExport::IMAGE_ACTION_KEEP: {
- return Vector<uint8_t>();
- } break; //use default
- }
-
- String validated_path=EditorImportPlugin::validate_source_path(p_path);
-
- int flags=texture_flags_to_export_flags(ResourceFormatLoaderImage::load_image_flags(validated_path));
- flags|=IMAGE_FLAG_FIX_BORDER_ALPHA;
-
- print_line("group format"+itos(group_format));
- rimd->set_option("format",group_format);
- rimd->set_option("flags",flags);
- rimd->set_option("quality",group_lossy_quality);
- rimd->set_option("atlas",false);
- rimd->set_option("shrink",group_shrink);
- rimd->add_source(validated_path,FileAccess::get_md5(p_path));
-
- } else if (EditorImportExport::get_singleton()->get_image_formats().has(p_path.get_extension().to_lower()) && EditorImportExport::get_singleton()->get_export_image_action()!=EditorImportExport::IMAGE_ACTION_NONE) {
- //handled by general image export settings
-
- rimd = Ref<ResourceImportMetadata>( memnew( ResourceImportMetadata ) );
-
- switch(EditorImportExport::get_singleton()->get_export_image_action()) {
- case EditorImportExport::IMAGE_ACTION_COMPRESS_DISK: rimd->set_option("format",IMAGE_FORMAT_COMPRESS_DISK_LOSSY); break;
- case EditorImportExport::IMAGE_ACTION_COMPRESS_RAM: rimd->set_option("format",IMAGE_FORMAT_COMPRESS_RAM); break;
- }
-
- String validated_path=EditorImportPlugin::validate_source_path(p_path);
-
- int flags=texture_flags_to_export_flags(ResourceFormatLoaderImage::load_image_flags(validated_path));
- flags|=IMAGE_FLAG_FIX_BORDER_ALPHA;
-
- rimd->set_option("shrink",EditorImportExport::get_singleton()->get_export_image_shrink());
- rimd->set_option("flags",flags);
- rimd->set_option("quality",EditorImportExport::get_singleton()->get_export_image_quality());
- rimd->set_option("atlas",false);
- rimd->add_source(validated_path,FileAccess::get_md5(p_path));
-
- } else {
- return Vector<uint8_t>();
- }
- }
-
- int fmt = rimd->get_option("format");
-
- if (fmt!=IMAGE_FORMAT_COMPRESS_RAM && fmt!=IMAGE_FORMAT_COMPRESS_DISK_LOSSY) {
- print_line("no compress ram or lossy");
- return Vector<uint8_t>(); //pointless to do anything, since no need to reconvert
- }
-
- uint32_t flags = rimd->get_option("flags");
- uint8_t shrink = rimd->has_option("shrink") ? rimd->get_option("shrink"): Variant(1);
- uint8_t format = rimd->get_option("format");
- uint8_t comp = (format==EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM)?uint8_t(p_platform->get_image_compression()):uint8_t(255);
-
- MD5_CTX ctx;
- uint8_t f4[4];
- encode_uint32(flags,&f4[0]);
- MD5Init(&ctx);
- String gp = ProjectSettings::get_singleton()->globalize_path(p_path);
- CharString cs = gp.utf8();
- MD5Update(&ctx,(unsigned char*)cs.get_data(),cs.length());
- MD5Update(&ctx,f4,4);
- MD5Update(&ctx,&format,1);
- MD5Update(&ctx,&comp,1);
- MD5Update(&ctx,&shrink,1);
- MD5Final(&ctx);
-
-
-
- uint64_t sd=0;
- String smd5;
-
- String md5 = String::md5(ctx.digest);
- print_line(p_path+" MD5: "+md5+" FLAGS: "+itos(flags));
-
- String tmp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp/");
-
- bool valid=false;
- {
- //if existing, make sure it's valid
- FileAccessRef f = FileAccess::open(tmp_path+"imgexp-"+md5+".txt",FileAccess::READ);
- if (f) {
-
- uint64_t d = f->get_line().strip_edges().to_int64();
- sd = FileAccess::get_modified_time(p_path);
-
- if (d==sd) {
- valid=true;
- } else {
- String cmd5 = f->get_line().strip_edges();
- smd5 = FileAccess::get_md5(p_path);
- if (cmd5==smd5) {
- valid=true;
- }
- }
-
-
- }
- }
-
- if (!valid) {
- //cache failed, convert
- Error err = import2(tmp_path+"imgexp-"+md5+".tex",rimd,p_platform->get_image_compression(),true);
- ERR_FAIL_COND_V(err!=OK,Vector<uint8_t>());
- FileAccessRef f = FileAccess::open(tmp_path+"imgexp-"+md5+".txt",FileAccess::WRITE);
-
- if (sd==0)
- sd = FileAccess::get_modified_time(p_path);
- if (smd5==String())
- smd5 = FileAccess::get_md5(p_path);
-
- f->store_line(String::num(sd));
- f->store_line(smd5);
- f->store_line(gp); //source path for reference
- }
-
-
- Vector<uint8_t> ret;
- FileAccessRef f = FileAccess::open(tmp_path+"imgexp-"+md5+".tex",FileAccess::READ);
- ERR_FAIL_COND_V(!f,ret);
-
- ret.resize(f->get_len());
- f->get_buffer(ret.ptr(),ret.size());
-
- return ret;
-}
-
-uint32_t EditorTextureImportPlugin::texture_flags_to_export_flags(uint32_t p_tex_flags) const {
-
- uint32_t flags=0;
-
- if (!(p_tex_flags&Texture::FLAG_MIPMAPS)) {
- flags|=IMAGE_FLAG_NO_MIPMAPS;
- }
- if (p_tex_flags&Texture::FLAG_REPEAT) {
- flags|=IMAGE_FLAG_REPEAT;
- }
- if (p_tex_flags&Texture::FLAG_FILTER) {
- flags|=IMAGE_FLAG_FILTER;
- }
- if (p_tex_flags&Texture::FLAG_ANISOTROPIC_FILTER) {
- flags|=IMAGE_FLAG_USE_ANISOTROPY;
- }
- if (p_tex_flags&Texture::FLAG_CONVERT_TO_LINEAR) {
- flags|=IMAGE_FLAG_CONVERT_TO_LINEAR;
- }
- /* // no correspondence yet
- if (p_tex_flags&Texture::TEXTURE_FLAG_MIRRORED_REPEAT) {
- flags|=;
- }*/
-
- return flags;
-}
-
-void EditorTextureImportPlugin::import_from_drop(const Vector<String>& p_drop,const String& p_dest_path) {
-
- Vector<String> valid;
-
- List<String> valid_extensions;
- ImageLoader::get_recognized_extensions(&valid_extensions);
- for(int i=0;i<p_drop.size();i++) {
-
- String extension=p_drop[i].get_extension().to_lower();
-
- for (List<String>::Element *E=valid_extensions.front();E;E=E->next()) {
-
- if (E->get()==extension) {
- valid.push_back(p_drop[i]);
- break;
- }
- }
- }
-
- if (valid.size()) {
- dialog->popup_import();
- dialog->setup_multiple_import_3d(valid,p_dest_path);
- }
-}
-
-void EditorTextureImportPlugin::reimport_multiple_files(const Vector<String>& p_list) {
-
- Vector<String> valid;
-
-
- for(int i=0;i<p_list.size();i++) {
-
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_list[i]);
- String type = rimd->get_editor();
- if (type=="texture" || type.begins_with("texture_")) {
-
- if ((rimd->has_option("atlas") && rimd->get_option("atlas")) || (rimd->has_option("large") && rimd->get_option("large"))) {
- continue;
- }
-
- valid.push_back(p_list[i]);
- }
- }
-
- if (valid.size()) {
-
- dialog->popup_import(valid[0]);
-
- Vector<String> sources;
- for(int i=0;i<valid.size();i++) {
- int idx;
- EditorFileSystemDirectory *efsd = EditorFileSystem::get_singleton()->find_file(valid[i],&idx);
- if (efsd) {
- for(int j=0;j<efsd->get_source_count(idx);j++) {
- String file = expand_source_path(efsd->get_source_file(idx,j));
- if (sources.find(file)==-1) {
- sources.push_back(file);
- }
-
- }
- }
- }
-
- if (sources.size()) {
-
- dialog->add_sources_and_dest(sources,valid[0].get_base_dir());
- }
- }
-}
-
-bool EditorTextureImportPlugin::can_reimport_multiple_files() const {
-
- return true;
-
-}
-
-
-
-EditorTextureImportPlugin *EditorTextureImportPlugin::singleton=NULL;
-
-EditorTextureImportPlugin::EditorTextureImportPlugin(EditorNode *p_editor) {
-
- singleton=this;
- editor=p_editor;
- dialog = memnew( EditorTextureImportDialog(this) );
- editor->get_gui_base()->add_child(dialog);
-
-}
-
-////////////////////////////
-
-
- Vector<uint8_t> EditorTextureExportPlugin::custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform) {
-
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_path);
-
- if (rimd.is_valid()) {
-
- if (rimd->get_editor()!="") {
- int compression = rimd->get_option("format");
- if (compression!=EditorTextureImportPlugin::IMAGE_FORMAT_COMPRESS_RAM)
- return Vector<uint8_t>(); //only useful for RAM compression to reconvert
- Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name(rimd->get_editor());
- if (pl.is_valid()) {
- Vector<uint8_t> ce = pl->custom_export(p_path,p_platform);
- if (ce.size())
- return ce;
- }
- }
- } else if (EditorImportExport::get_singleton()->image_get_export_group(p_path)) {
-
-
- Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture");
- if (pl.is_valid()) {
- Vector<uint8_t> ce = pl->custom_export(p_path,p_platform);
- if (ce.size()) {
- p_path=p_path.get_basename()+".converted.tex";
- return ce;
- }
- }
-
- } else if (EditorImportExport::get_singleton()->get_export_image_action()!=EditorImportExport::IMAGE_ACTION_NONE){
-
- String xt = p_path.get_extension().to_lower();
- if (EditorImportExport::get_singleton()->get_image_formats().has(xt)) { //should check for more I guess?
-
- Ref<EditorImportPlugin> pl = EditorImportExport::get_singleton()->get_import_plugin_by_name("texture");
- if (pl.is_valid()) {
- Vector<uint8_t> ce = pl->custom_export(p_path,p_platform);
- if (ce.size()) {
- p_path=p_path.get_basename()+".converted.tex";
- return ce;
- }
- }
- }
- }
-
- return Vector<uint8_t>();
-}
-
-EditorTextureExportPlugin::EditorTextureExportPlugin() {
-
-
-}
-#endif
diff --git a/editor/io_plugins/editor_texture_import_plugin.h b/editor/io_plugins/editor_texture_import_plugin.h
deleted file mode 100644
index d49ea10619..0000000000
--- a/editor/io_plugins/editor_texture_import_plugin.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/*************************************************************************/
-/* editor_texture_import_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 EDITOR_TEXTURE_IMPORT_PLUGIN_H
-#define EDITOR_TEXTURE_IMPORT_PLUGIN_H
-
-#if 0
-#include "editor/editor_dir_dialog.h"
-#include "editor/editor_file_system.h"
-#include "editor/editor_import_export.h"
-#include "scene/gui/dialogs.h"
-#include "scene/gui/file_dialog.h"
-#include "scene/gui/label.h"
-#include "scene/gui/line_edit.h"
-#include "scene/gui/option_button.h"
-#include "scene/gui/progress_bar.h"
-#include "scene/gui/slider.h"
-#include "scene/gui/spin_box.h"
-#include "scene/gui/tree.h"
-
-
-
-class EditorNode;
-class EditorTextureImportDialog;
-
-class EditorTextureImportPlugin : public EditorImportPlugin {
-
- GDCLASS(EditorTextureImportPlugin,EditorImportPlugin);
-public:
-
-
- enum Mode {
- MODE_TEXTURE_2D,
- MODE_TEXTURE_3D,
- MODE_ATLAS,
- MODE_LARGE,
- MODE_MAX
- };
-
-
-
-private:
-
- EditorNode *editor;
- EditorTextureImportDialog *dialog;
- static EditorTextureImportPlugin *singleton;
- //used by other importers such as mesh
-
- Error _process_texture_data(Ref<ImageTexture> &texture, int format, float quality, int flags,EditorExportPlatform::ImageCompression p_compr,int tex_flags,float shrink);
- void compress_image(EditorExportPlatform::ImageCompression p_mode,Image& image,bool p_smaller);
-
- uint32_t texture_flags_to_export_flags(uint32_t p_tex_flags) const;
-public:
-
-
- static EditorTextureImportPlugin *get_singleton() { return singleton; }
-
- enum ImageFormat {
-
- IMAGE_FORMAT_UNCOMPRESSED,
- IMAGE_FORMAT_COMPRESS_DISK_LOSSLESS,
- IMAGE_FORMAT_COMPRESS_DISK_LOSSY,
- IMAGE_FORMAT_COMPRESS_RAM,
- };
-
- enum ImageFlags {
-
- IMAGE_FLAG_STREAM_FORMAT=1,
- IMAGE_FLAG_FIX_BORDER_ALPHA=2,
- IMAGE_FLAG_ALPHA_BIT=4, //hint for compressions that use a bit for alpha
- IMAGE_FLAG_COMPRESS_EXTRA=8, // used for pvrtc2
- IMAGE_FLAG_NO_MIPMAPS=16, //normal for 2D games
- IMAGE_FLAG_REPEAT=32, //usually disabled in 2D
- IMAGE_FLAG_FILTER=64, //almost always enabled
- IMAGE_FLAG_PREMULT_ALPHA=128,//almost always enabled
- IMAGE_FLAG_CONVERT_TO_LINEAR=256, //convert image to linear
- IMAGE_FLAG_CONVERT_NORMAL_TO_XY=512, //convert image to linear
- IMAGE_FLAG_USE_ANISOTROPY=1024, //convert image to linear
- };
-
- virtual String get_name() const;
- virtual String get_visible_name() const;
- virtual void import_dialog(const String& p_from="");
- virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
- virtual Error import2(const String& p_path, const Ref<ResourceImportMetadata>& p_from,EditorExportPlatform::ImageCompression p_compr, bool p_external=false);
- virtual Vector<uint8_t> custom_export(const String& p_path,const Ref<EditorExportPlatform> &p_platform);
-
- virtual void import_from_drop(const Vector<String>& p_drop,const String& p_dest_path);
- virtual void reimport_multiple_files(const Vector<String>& p_list);
- virtual bool can_reimport_multiple_files() const;
-
- EditorTextureImportPlugin(EditorNode* p_editor=NULL);
-};
-
-
-class EditorTextureExportPlugin : public EditorExportPlugin {
-
- GDCLASS( EditorTextureExportPlugin, EditorExportPlugin);
-
-
-public:
-
- virtual Vector<uint8_t> custom_export(String& p_path,const Ref<EditorExportPlatform> &p_platform);
- EditorTextureExportPlugin();
-};
-
-class EditorImportTextureOptions : public VBoxContainer {
-
- GDCLASS( EditorImportTextureOptions, VBoxContainer );
-
-
- OptionButton *format;
- VBoxContainer *quality_vb;
- HSlider *quality;
- Tree *flags;
- Vector<TreeItem*> items;
-
-
- bool updating;
-
- void _changedp(int p_value);
- void _changed();
-
-
-protected:
- static void _bind_methods();
- void _notification(int p_what);
-
-public:
-
-
-
- void set_format(EditorTextureImportPlugin::ImageFormat p_format);
- EditorTextureImportPlugin::ImageFormat get_format() const;
-
- void set_flags(uint32_t p_flags);
- uint32_t get_flags() const;
-
- void set_quality(float p_quality);
- float get_quality() const;
-
- void show_2d_notice();
-
- EditorImportTextureOptions();
-
-
-};
-#endif // EDITOR_TEXTURE_IMPORT_PLUGIN_H
-#endif
diff --git a/editor/io_plugins/editor_translation_import_plugin.cpp b/editor/io_plugins/editor_translation_import_plugin.cpp
deleted file mode 100644
index 8b8efe5518..0000000000
--- a/editor/io_plugins/editor_translation_import_plugin.cpp
+++ /dev/null
@@ -1,480 +0,0 @@
-/*************************************************************************/
-/* editor_translation_import_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 "editor_translation_import_plugin.h"
-
-#if 0
-#include "editor/editor_dir_dialog.h"
-#include "editor/editor_node.h"
-#include "editor/property_editor.h"
-#include "scene/gui/file_dialog.h"
-//#include "scene/resources/sample.h"
-#include "compressed_translation.h"
-#include "editor/project_settings.h"
-#include "io/resource_saver.h"
-#include "os/file_access.h"
-#include "translation.h"
-
-
-class EditorTranslationImportDialog : public ConfirmationDialog {
-
- GDCLASS(EditorTranslationImportDialog,ConfirmationDialog);
-
- EditorTranslationImportPlugin *plugin;
-
- LineEdit *import_path;
- LineEdit *save_path;
- EditorFileDialog *file_select;
- CheckButton *ignore_first;
- CheckButton *compress;
- CheckButton *add_to_project;
- EditorDirDialog *save_select;
- ConfirmationDialog *error_dialog;
- Vector<TreeItem*> items;
- Tree *columns;
-
-public:
-
- void _choose_file(const String& p_path) {
-
- import_path->set_text(p_path);
- FileAccess *f = FileAccess::open(p_path,FileAccess::READ);
- if (!f) {
-
- error_dialog->set_text(TTR("Invalid source!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
-
- }
-
- Vector<String> csvh = f->get_csv_line();
- memdelete(f);
-
- if (csvh.size()<2) {
-
- error_dialog->set_text(TTR("Invalid translation source!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- return;
-
- }
-
- columns->clear();
- columns->set_columns(2);
- TreeItem *root = columns->create_item();
- columns->set_hide_root(true);
- columns->set_column_titles_visible(true);
- columns->set_column_title(0,TTR("Column"));
- columns->set_column_title(1,TTR("Language"));
- Vector<String> langs = TranslationServer::get_all_locales();
- Vector<String> names = TranslationServer::get_all_locale_names();
- if (csvh[0]=="")
- ignore_first->set_pressed(true);
-
-
- items.clear();
-
- for(int i=1;i<csvh.size();i++) {
-
- TreeItem *ti = columns->create_item(root);
-
- ti->set_editable(0,true);
- ti->set_selectable(0,false);
- ti->set_cell_mode(0,TreeItem::CELL_MODE_CHECK);
- ti->set_checked(0,true);
- ti->set_text(0,itos(i));
- items.push_back(ti);
-
- String lname = csvh[i].to_lower().strip_edges();
- int idx=-1;
- String hint;
- for(int j=0;j<langs.size();j++) {
-
- if (langs[j]==lname.substr(0,langs[j].length()).to_lower()) {
- idx=j;
- }
- if (j>0) {
- hint+=",";
- }
- hint+=names[j].replace(","," ");
- }
-
- ti->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
- ti->set_text(1,hint);
- ti->set_editable(1,true);
-
-
- if (idx!=-1) {
- ignore_first->set_pressed(true);
- ti->set_range(1,idx);
- } else {
-
- //not found, maybe used stupid name
- if (lname.begins_with("br")) //brazilian
- ti->set_range(1,langs.find("pt"));
- else if (lname.begins_with("ch")) //chinese
- ti->set_range(1,langs.find("zh"));
- else if (lname.begins_with("sp")) //spanish
- ti->set_range(1,langs.find("es"));
- else if (lname.begins_with("kr"))// kprean
- ti->set_range(1,langs.find("ko"));
- else if (i==0)
- ti->set_range(1,langs.find("en"));
- else
- ti->set_range(1,langs.find("es"));
- }
-
- ti->set_metadata(1,names[ti->get_range(1)]);
- }
-
-
-
- }
- void _choose_save_dir(const String& p_path) {
-
- save_path->set_text(p_path);
- }
-
- void _browse() {
-
- file_select->popup_centered_ratio();
- }
-
- void _browse_target() {
-
- save_select->popup_centered_ratio();
-
- }
-
-
- void popup_import(const String& p_from) {
-
- popup_centered(Size2(400,400)*EDSCALE);
-
- if (p_from!="") {
-
- Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(p_from);
- ERR_FAIL_COND(!rimd.is_valid());
- ERR_FAIL_COND(rimd->get_source_count()!=1);
- _choose_file(EditorImportPlugin::expand_source_path(rimd->get_source_path(0)));
- _choose_save_dir(p_from.get_base_dir());
- String locale = rimd->get_option("locale");
- bool skip_first=rimd->get_option("skip_first");
- bool compressed = rimd->get_option("compress");
-
- int idx=-1;
-
- for(int i=0;i<items.size();i++) {
-
- String il = TranslationServer::get_all_locales()[items[i]->get_range(1)];
- if (il==locale) {
- idx=i;
- break;
- }
- }
-
- if (idx!=-1) {
- idx=rimd->get_option("index");
- }
-
- for(int i=0;i<items.size();i++) {
-
- if (i==idx) {
-
- Vector<String> locs = TranslationServer::get_all_locales();
- for(int j=0;j<locs.size();j++) {
- if (locs[j]==locale) {
- items[i]->set_range(1,j);
- }
-
- }
- items[i]->set_checked(0,true);
- } else {
- items[i]->set_checked(0,false);
-
- }
- }
-
- ignore_first->set_pressed(skip_first);
- compress->set_pressed(compressed);
-
-
-
- }
-
- }
-
-
- void _import() {
-
-
- if (items.size()==0) {
- error_dialog->set_text(TTR("No items to import!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- }
-
- if (!save_path->get_text().begins_with("res://")) {
- error_dialog->set_text(TTR("No target path!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- }
-
- EditorProgress progress("import_xl",TTR("Import Translations"),items.size());
- for(int i=0;i<items.size();i++) {
-
- progress.step(items[i]->get_metadata(1),i);
- if (!items[i]->is_checked(0))
- continue;
-
- String locale = TranslationServer::get_all_locales()[items[i]->get_range(1)];
- Ref<ResourceImportMetadata> imd = memnew( ResourceImportMetadata );
- imd->add_source(EditorImportPlugin::validate_source_path(import_path->get_text()));
- imd->set_option("locale",locale);
- imd->set_option("index",i);
- imd->set_option("skip_first",ignore_first->is_pressed());
- imd->set_option("compress",compress->is_pressed());
-
- String savefile = save_path->get_text().plus_file(import_path->get_text().get_file().get_basename()+"."+locale+".translation");
- Error err = plugin->import(savefile,imd);
- if (err!=OK) {
- error_dialog->set_text(TTR("Couldn't import!"));
- error_dialog->popup_centered(Size2(200,100)*EDSCALE);
- } else if (add_to_project->is_pressed()) {
-
- ProjectSettings::get_singleton()->add_translation(savefile);
- }
- }
- hide();
-
- }
-
-
- void _notification(int p_what) {
-
-
- if (p_what==NOTIFICATION_ENTER_TREE) {
-
-
- }
- }
-
- static void _bind_methods() {
-
-
- ClassDB::bind_method("_choose_file",&EditorTranslationImportDialog::_choose_file);
- ClassDB::bind_method("_choose_save_dir",&EditorTranslationImportDialog::_choose_save_dir);
- ClassDB::bind_method("_import",&EditorTranslationImportDialog::_import);
- ClassDB::bind_method("_browse",&EditorTranslationImportDialog::_browse);
- ClassDB::bind_method("_browse_target",&EditorTranslationImportDialog::_browse_target);
- //ADD_SIGNAL( MethodInfo("imported",PropertyInfo(Variant::OBJECT,"scene")) );
- }
-
- EditorTranslationImportDialog(EditorTranslationImportPlugin *p_plugin) {
-
- plugin=p_plugin;
-
-
- set_title(TTR("Import Translation"));
-
- VBoxContainer *vbc = memnew( VBoxContainer );
- add_child(vbc);
- //set_child_rect(vbc);
-
-
-
- VBoxContainer *csvb = memnew( VBoxContainer );
-
- HBoxContainer *hbc = memnew( HBoxContainer );
- csvb->add_child(hbc);
- vbc->add_margin_child(TTR("Source CSV:"),csvb);
-
- import_path = memnew( LineEdit );
- import_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(import_path);
- ignore_first = memnew( CheckButton );
- ignore_first->set_text(TTR("Ignore First Row"));
- csvb->add_child(ignore_first);
-
- Button * import_choose = memnew( Button );
- import_choose->set_text(" .. ");
- hbc->add_child(import_choose);
-
- import_choose->connect("pressed", this,"_browse");
-
- VBoxContainer *tcomp = memnew( VBoxContainer);
- hbc = memnew( HBoxContainer );
- tcomp->add_child(hbc);
- vbc->add_margin_child(TTR("Target Path:"),tcomp);
-
- save_path = memnew( LineEdit );
- save_path->set_h_size_flags(SIZE_EXPAND_FILL);
- hbc->add_child(save_path);
-
- Button * save_choose = memnew( Button );
- save_choose->set_text(" .. ");
- hbc->add_child(save_choose);
-
- save_choose->connect("pressed", this,"_browse_target");
-
- compress = memnew( CheckButton);
- compress->set_pressed(true);
- compress->set_text(TTR("Compress"));
- tcomp->add_child(compress);
-
- add_to_project = memnew( CheckButton);
- add_to_project->set_pressed(true);
- add_to_project->set_text(TTR("Add to Project (project.godot)"));
- tcomp->add_child(add_to_project);
-
- file_select = memnew(EditorFileDialog);
- file_select->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
- add_child(file_select);
- file_select->set_mode(EditorFileDialog::MODE_OPEN_FILE);
- file_select->connect("file_selected", this,"_choose_file");
- file_select->add_filter("*.csv ; Translation CSV");
- save_select = memnew( EditorDirDialog );
- add_child(save_select);
-
- //save_select->set_mode(EditorFileDialog::MODE_OPEN_DIR);
- save_select->connect("dir_selected", this,"_choose_save_dir");
-
- get_ok()->connect("pressed", this,"_import");
- get_ok()->set_text(TTR("Import"));
-
-
- error_dialog = memnew ( ConfirmationDialog );
- add_child(error_dialog);
- error_dialog->get_ok()->set_text(TTR("Accept"));
- //error_dialog->get_cancel()->hide();
-
- set_hide_on_ok(false);
-
- columns = memnew( Tree );
- vbc->add_margin_child(TTR("Import Languages:"),columns,true);
- }
-
- ~EditorTranslationImportDialog() {
-
- }
-
-};
-
-
-String EditorTranslationImportPlugin::get_name() const {
-
- return "translation";
-}
-String EditorTranslationImportPlugin::get_visible_name() const {
-
- return TTR("Translation");
-}
-void EditorTranslationImportPlugin::import_dialog(const String& p_from) {
-
- dialog->popup_import(p_from);
-}
-
-
-
-void EditorTranslationImportPlugin::import_from_drop(const Vector<String>& p_drop, const String &p_dest_path) {
-
-
- for(int i=0;i<p_drop.size();i++) {
- String ext = p_drop[i].get_extension().to_lower();
-
- if (ext=="csv") {
-
- import_dialog();
- dialog->_choose_file(p_drop[i]);
- dialog->_choose_save_dir(p_dest_path);
- break;
- }
- }
-
-
-}
-
-Error EditorTranslationImportPlugin::import(const String& p_path, const Ref<ResourceImportMetadata>& p_from) {
-
- Ref<ResourceImportMetadata> from = p_from;
- ERR_FAIL_COND_V( from->get_source_count()!=1, ERR_INVALID_PARAMETER);
-
- String source = EditorImportPlugin::expand_source_path( from->get_source_path(0) );
-
- FileAccessRef f = FileAccess::open(source,FileAccess::READ);
-
- ERR_FAIL_COND_V( !f, ERR_INVALID_PARAMETER );
-
- bool skip_first = from->get_option("skip_first");
- int index = from->get_option("index");
- index+=1;
- String locale = from->get_option("locale");
-
- Ref<Translation> translation = memnew( Translation );
-
- translation->set_locale( locale );
-
- Vector<String> line = f->get_csv_line();
-
- while(line.size()>1) {
-
- if (!skip_first) {
- ERR_FAIL_INDEX_V(index,line.size(),ERR_INVALID_DATA );
- translation->add_message(line[0].strip_edges(),line[index]);
-
- } else {
-
- skip_first=false;
- }
-
- line = f->get_csv_line();
- }
-
- from->set_source_md5(0,FileAccess::get_md5(source));
- from->set_editor(get_name());
-
- String dst_path = p_path;
-
- if (from->get_option("compress")) {
-
- Ref<PHashTranslation> cxl = memnew( PHashTranslation );
- cxl->generate( translation );
- translation=cxl;
- }
-
- translation->set_import_metadata(from);
- return ResourceSaver::save(dst_path,translation);
-
-}
-
-
-EditorTranslationImportPlugin::EditorTranslationImportPlugin(EditorNode* p_editor) {
-
- dialog = memnew(EditorTranslationImportDialog(this));
- p_editor->get_gui_base()->add_child(dialog);
-}
-
-#endif
diff --git a/editor/io_plugins/editor_translation_import_plugin.h b/editor/io_plugins/editor_translation_import_plugin.h
deleted file mode 100644
index 39815f04e8..0000000000
--- a/editor/io_plugins/editor_translation_import_plugin.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*************************************************************************/
-/* editor_translation_import_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 EDITOR_TRANSLATION_IMPORT_PLUGIN_H
-#define EDITOR_TRANSLATION_IMPORT_PLUGIN_H
-
-#include "editor/editor_export.h"
-#include "scene/resources/font.h"
-#if 0
-class EditorNode;
-class EditorTranslationImportDialog;
-
-class EditorTranslationImportPlugin : public EditorImportPlugin {
-
- GDCLASS(EditorTranslationImportPlugin,EditorImportPlugin);
-
- EditorTranslationImportDialog *dialog;
-public:
-
- virtual String get_name() const;
- virtual String get_visible_name() const;
- virtual void import_dialog(const String& p_from="");
- virtual Error import(const String& p_path, const Ref<ResourceImportMetadata>& p_from);
- void import_from_drop(const Vector<String>& p_drop, const String &p_dest_path);
-
-
- EditorTranslationImportPlugin(EditorNode* p_editor);
-};
-
-#endif
-#endif // EDITOR_TRANSLATION_IMPORT_PLUGIN_H
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index 05d926dcc8..cc7fc57cde 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -965,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) {
diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp
index 2d2e5ec3f8..054124da8f 100644
--- a/editor/plugins/animation_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_tree_editor_plugin.cpp
@@ -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;
diff --git a/editor/plugins/baked_light_baker.cpp b/editor/plugins/baked_light_baker.cpp
deleted file mode 100644
index 3abf31c8eb..0000000000
--- a/editor/plugins/baked_light_baker.cpp
+++ /dev/null
@@ -1,2727 +0,0 @@
-/*************************************************************************/
-/* baked_light_baker.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 "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 (MeshInstance *meshi=Object::cast_to<MeshInstance>(p_node)) {
-
- 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 (Light *dl=Object::cast_to<Light>(p_node)) {
-
- 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 (Spatial *sp = Object::cast_to<Spatial>(p_node)){
-
- 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=Object::cast_to<Spatial>(p_node)->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 1181772251..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 */
-/* 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 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 e16ad0ecbf..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 */
-/* 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 "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 fc5d691223..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 */
-/* 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 "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(Object::cast_to<BakedLightInstance>(p_object));
-}
-
-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 2f8ffd5e89..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 */
-/* 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 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/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 112df4496a..329395d9c4 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -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 = Object::cast_to<CanvasItem>(c);
- 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() {
@@ -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();
@@ -2392,14 +2348,6 @@ void CanvasItemEditor::_notification(int p_what) {
AnimationPlayerEditor::singleton->get_key_editor()->connect("visibility_changed", this, "_keying_changed");
_keying_changed();
}
-
- if (p_what == NOTIFICATION_READY) {
-
- get_tree()->connect("node_removed", this, "_node_removed");
- }
-
- if (p_what == NOTIFICATION_DRAW) {
- }
}
void CanvasItemEditor::edit(CanvasItem *p_canvas_item) {
@@ -2774,50 +2722,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;
@@ -3154,34 +3058,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);
@@ -3238,10 +3114,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);
@@ -3257,74 +3131,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 = Object::cast_to<EditorNode>(get_scene()->get_root_node())->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);
@@ -3495,12 +3301,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);
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 2508c44d33..8f67d641f5 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -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);
diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/editor/plugins/collision_polygon_2d_editor_plugin.cpp
index fd1e9559ba..c90462db1d 100644
--- a/editor/plugins/collision_polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_polygon_2d_editor_plugin.cpp
@@ -386,17 +386,6 @@ CollisionPolygon2DEditor::CollisionPolygon2DEditor(EditorNode *p_editor) {
button_edit->set_toggle_mode(true);
button_edit->set_tooltip(TTR("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
-
mode = MODE_EDIT;
wip_active = false;
}
diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp
index e737e94412..3ac055e650 100644
--- a/editor/plugins/collision_polygon_editor_plugin.cpp
+++ b/editor/plugins/collision_polygon_editor_plugin.cpp
@@ -510,17 +510,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);
diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp
index 5b1b4df3d1..e6b921c539 100644
--- a/editor/plugins/light_occluder_2d_editor_plugin.cpp
+++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp
@@ -424,17 +424,6 @@ 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;
}
diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp
index e943071af2..79345754b6 100644
--- a/editor/plugins/multimesh_editor_plugin.cpp
+++ b/editor/plugins/multimesh_editor_plugin.cpp
@@ -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 = Object::cast_to<VisualInstance>(get_parent());
- 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();
diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp
index 544301c194..76e969a339 100644
--- a/editor/plugins/navigation_polygon_editor_plugin.cpp
+++ b/editor/plugins/navigation_polygon_editor_plugin.cpp
@@ -468,17 +468,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;
diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp
index 45140e32e3..adc8d4f091 100644
--- a/editor/plugins/path_2d_editor_plugin.cpp
+++ b/editor/plugins/path_2d_editor_plugin.cpp
@@ -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;
@@ -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);
diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp
index 32c3d8e480..88158d4b20 100644
--- a/editor/plugins/polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/polygon_2d_editor_plugin.cpp
@@ -770,17 +770,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;
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index ab9e065df4..316c76e4b2 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -1192,117 +1192,6 @@ 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 = Object::cast_to<ScriptTextEditor>(tab_container->get_child(i));
- 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 = Object::cast_to<ScriptTextEditor>(tab_container->get_child(i));
- 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++) {
@@ -2361,19 +2250,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);
@@ -2542,20 +2418,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 f9f877807c..17209de681 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -344,14 +344,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 +392,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_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp
index 2cdddd577b..069a0c4292 100644
--- a/editor/plugins/shader_editor_plugin.cpp
+++ b/editor/plugins/shader_editor_plugin.cpp
@@ -252,9 +252,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());
@@ -274,90 +271,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->Object::cast_to<ShaderTextEditor>(get_child(i));
- 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();
@@ -519,20 +432,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 6c8ea5a6ec..ab18784d9f 100644
--- a/editor/plugins/shader_editor_plugin.h
+++ b/editor/plugins/shader_editor_plugin.h
@@ -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 392ab2c8c6..732344cb78 100644
--- a/editor/plugins/shader_graph_editor_plugin.cpp
+++ b/editor/plugins/shader_graph_editor_plugin.cpp
@@ -541,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);
}
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 1ef3146594..01dd7a0031 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -3585,21 +3585,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()) {
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index aaebabe04b..c2c26bfe6c 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -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() {
@@ -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;
diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h
index fbf81fabbf..0d1ab9fd8c 100644
--- a/editor/plugins/sprite_frames_editor_plugin.h
+++ b/editor/plugins/sprite_frames_editor_plugin.h
@@ -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 9da0f2267d..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 */
-/* 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 "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(Object::cast_to<Node>(p_object));
-}
-
-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 807318b06e..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 */
-/* 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 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/project_export.cpp b/editor/project_export.cpp
index 71b1ca580d..d649afc594 100644
--- a/editor/project_export.cpp
+++ b/editor/project_export.cpp
@@ -35,7 +35,6 @@
#include "io/image_loader.h"
#include "io/resource_loader.h"
#include "io/resource_saver.h"
-#include "io_plugins/editor_texture_import_plugin.h"
#include "os/dir_access.h"
#include "os/file_access.h"
#include "os/os.h"
diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp
index 45f49186a8..fb5143b486 100644
--- a/editor/spatial_editor_gizmos.cpp
+++ b/editor/spatial_editor_gizmos.cpp
@@ -238,7 +238,6 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi
Instance ins;
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
-#if 1
Array a;
a.resize(VS::ARRAY_MAX);
@@ -273,61 +272,6 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi
}
}
-#else
- for (int ih = 0; ih < p_handles.size(); ih++) {
-
- Vector<Vector3> vertices;
- Vector<Vector3> normals;
-
- int vtx_idx = 0;
-
-#define ADD_VTX(m_idx) \
- vertices.push_back((face_points[m_idx] * HANDLE_HALF_SIZE + p_handles[ih])); \
- normals.push_back(normal_points[m_idx]); \
- vtx_idx++;
-
- for (int i = 0; i < 6; i++) {
-
- Vector3 face_points[4];
- Vector3 normal_points[4];
- float uv_points[8] = { 0, 0, 0, 1, 1, 1, 1, 0 };
-
- for (int j = 0; j < 4; j++) {
-
- float v[3];
- v[0] = 1.0;
- v[1] = 1 - 2 * ((j >> 1) & 1);
- v[2] = v[1] * (1 - 2 * (j & 1));
-
- for (int k = 0; k < 3; k++) {
-
- if (i < 3)
- face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
- else
- face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1);
- }
- normal_points[j] = Vector3();
- normal_points[j][i % 3] = (i >= 3 ? -1 : 1);
- }
- //tri 1
- ADD_VTX(0);
- ADD_VTX(1);
- ADD_VTX(2);
- //tri 2
- ADD_VTX(2);
- ADD_VTX(3);
- ADD_VTX(0);
- }
-
- Array d;
- d.resize(VS::ARRAY_MAX);
- d[VisualServer::ARRAY_NORMAL] = normals;
- d[VisualServer::ARRAY_VERTEX] = vertices;
-
- mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES, d);
- mesh->surface_set_material(ih, SpatialEditorGizmos::singleton->handle_material);
- }
-#endif
ins.mesh = mesh;
ins.billboard = p_billboard;
ins.extra_margin = true;