summaryrefslogtreecommitdiff
path: root/editor/import
diff options
context:
space:
mode:
Diffstat (limited to 'editor/import')
-rw-r--r--editor/import/editor_import_plugin.cpp152
-rw-r--r--editor/import/editor_import_plugin.h54
-rw-r--r--editor/import/resource_importer_texture.cpp67
-rw-r--r--editor/import/resource_importer_texture.h4
4 files changed, 243 insertions, 34 deletions
diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp
new file mode 100644
index 0000000000..6dee5da538
--- /dev/null
+++ b/editor/import/editor_import_plugin.cpp
@@ -0,0 +1,152 @@
+/*************************************************************************/
+/* editor_import_plugin.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#include "editor_import_plugin.h"
+#include "core/script_language.h"
+
+EditorImportPlugin::EditorImportPlugin() {
+}
+
+String EditorImportPlugin::get_importer_name() const {
+ ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_importer_name")), "");
+ return get_script_instance()->call("get_importer_name");
+}
+
+String EditorImportPlugin::get_visible_name() const {
+ ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_visible_name")), "");
+ return get_script_instance()->call("get_visible_name");
+}
+
+void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) const {
+ ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("get_recognized_extensions")));
+ Array extensions = get_script_instance()->call("get_recognized_extensions");
+ for (int i = 0; i < extensions.size(); i++) {
+ p_extensions->push_back(extensions[i]);
+ }
+}
+
+String EditorImportPlugin::get_preset_name(int p_idx) const {
+ ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_preset_name")), "");
+ return get_script_instance()->call("get_preset_name", p_idx);
+}
+
+int EditorImportPlugin::get_preset_count() {
+ ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_preset_count")), 0);
+ return get_script_instance()->call("get_preset_count");
+}
+
+String EditorImportPlugin::get_save_extension() const {
+ ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_save_extension")), "");
+ return get_script_instance()->call("get_save_extension");
+}
+
+String EditorImportPlugin::get_resource_type() const {
+ ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_resource_type")), "");
+ return get_script_instance()->call("get_resource_type");
+}
+
+void EditorImportPlugin::get_import_options(List<ResourceImporter::ImportOption> *r_options, int p_preset) const {
+
+ ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("get_import_options")));
+ Array needed;
+ needed.push_back("name");
+ needed.push_back("default_value");
+ Array options = get_script_instance()->call("get_import_options", p_preset);
+ for (int i = 0; i < options.size(); i++) {
+ Dictionary d = options[i];
+ ERR_FAIL_COND(!d.has_all(needed));
+ String name = d["name"];
+ Variant default_value = d["default_value"];
+
+ PropertyHint hint = PROPERTY_HINT_NONE;
+ if (d.has("property_hint")) {
+ hint = (PropertyHint)d["property_hint"].operator int64_t();
+ }
+
+ String hint_string;
+ if (d.has("hint_string")) {
+ hint_string = d["hint_string"];
+ }
+
+ uint32_t usage = PROPERTY_USAGE_DEFAULT;
+ if (d.has("usage")) {
+ usage = d["usage"];
+ }
+
+ ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value);
+ r_options->push_back(option);
+ }
+}
+
+bool EditorImportPlugin::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
+ ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("get_option_visibility")), true);
+ Dictionary d;
+ Map<StringName, Variant>::Element *E = p_options.front();
+ while (E) {
+ d[E->key()] = E->get();
+ E = E->next();
+ }
+ return get_script_instance()->call("get_option_visibility", p_option, d);
+}
+
+Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files) {
+
+ ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("import")), ERR_UNAVAILABLE);
+ Dictionary options;
+ Array platform_variants, gen_files;
+
+ Map<StringName, Variant>::Element *E = p_options.front();
+ while (E) {
+ options[E->key()] = E->get();
+ E = E->next();
+ }
+ Error err = (Error)get_script_instance()->call("import", p_source_file, p_save_path, options, platform_variants, gen_files).operator int64_t();
+
+ for (int i = 0; i < platform_variants.size(); i++) {
+ r_platform_variants->push_back(platform_variants[i]);
+ }
+ for (int i = 0; i < gen_files.size(); i++) {
+ r_gen_files->push_back(gen_files[i]);
+ }
+ return err;
+}
+
+void EditorImportPlugin::_bind_methods() {
+
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_importer_name"));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_visible_name"));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "get_preset_count"));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_preset_name", PropertyInfo(Variant::INT, "preset")));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_recognized_extensions"));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::ARRAY, "get_import_options", PropertyInfo(Variant::INT, "preset")));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_save_extension"));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::STRING, "get_resource_type"));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options")));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::INT, "import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "r_platform_variants"), PropertyInfo(Variant::ARRAY, "r_gen_files")));
+}
diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h
new file mode 100644
index 0000000000..3c16b79713
--- /dev/null
+++ b/editor/import/editor_import_plugin.h
@@ -0,0 +1,54 @@
+/*************************************************************************/
+/* editor_import_plugin.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#ifndef EDITOR_IMPORT_PLUGIN_H
+#define EDITOR_IMPORT_PLUGIN_H
+
+#include "io/resource_import.h"
+
+class EditorImportPlugin : public ResourceImporter {
+ GDCLASS(EditorImportPlugin, Reference)
+protected:
+ static void _bind_methods();
+
+public:
+ EditorImportPlugin();
+ virtual String get_importer_name() const;
+ virtual String get_visible_name() const;
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ virtual String get_preset_name(int p_idx) const;
+ virtual int get_preset_count();
+ virtual String get_save_extension() const;
+ virtual String get_resource_type() const;
+ virtual void get_import_options(List<ImportOption> *r_options, int p_preset) const;
+ virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
+ virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files);
+};
+
+#endif //EDITOR_IMPORT_PLUGIN_H
diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp
index f0dcc4a298..c115f0014a 100644
--- a/editor/import/resource_importer_texture.cpp
+++ b/editor/import/resource_importer_texture.cpp
@@ -181,7 +181,7 @@ void ResourceImporterTexture::get_import_options(List<ImportOption> *r_options,
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "detect_3d"), p_preset == PRESET_DETECT));
}
-void ResourceImporterTexture::_save_stex(const Image &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb) {
+void ResourceImporterTexture::_save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb) {
FileAccess *f = FileAccess::open(p_to_path, FileAccess::WRITE);
f->store_8('G');
@@ -189,8 +189,8 @@ void ResourceImporterTexture::_save_stex(const Image &p_image, const String &p_t
f->store_8('S');
f->store_8('T'); //godot streamable texture
- f->store_32(p_image.get_width());
- f->store_32(p_image.get_height());
+ f->store_32(p_image->get_width());
+ f->store_32(p_image->get_height());
f->store_32(p_texture_flags);
uint32_t format = 0;
@@ -207,14 +207,14 @@ void ResourceImporterTexture::_save_stex(const Image &p_image, const String &p_t
switch (p_compress_mode) {
case COMPRESS_LOSSLESS: {
- Image image = p_image;
+ Ref<Image> image = p_image->duplicate();
if (p_mipmaps) {
- image.generate_mipmaps();
+ image->generate_mipmaps();
} else {
- image.clear_mipmaps();
+ image->clear_mipmaps();
}
- int mmc = image.get_mipmap_count() + 1;
+ int mmc = image->get_mipmap_count() + 1;
format |= StreamTexture::FORMAT_BIT_LOSSLESS;
f->store_32(format);
@@ -223,7 +223,7 @@ void ResourceImporterTexture::_save_stex(const Image &p_image, const String &p_t
for (int i = 0; i < mmc; i++) {
if (i > 0) {
- image.shrink_x2();
+ image->shrink_x2();
}
PoolVector<uint8_t> data = Image::lossless_packer(image);
@@ -236,14 +236,14 @@ void ResourceImporterTexture::_save_stex(const Image &p_image, const String &p_t
} break;
case COMPRESS_LOSSY: {
- Image image = p_image;
+ Ref<Image> image = p_image->duplicate();
if (p_mipmaps) {
- image.generate_mipmaps();
+ image->generate_mipmaps();
} else {
- image.clear_mipmaps();
+ image->clear_mipmaps();
}
- int mmc = image.get_mipmap_count() + 1;
+ int mmc = image->get_mipmap_count() + 1;
format |= StreamTexture::FORMAT_BIT_LOSSY;
f->store_32(format);
@@ -252,7 +252,7 @@ void ResourceImporterTexture::_save_stex(const Image &p_image, const String &p_t
for (int i = 0; i < mmc; i++) {
if (i > 0) {
- image.shrink_x2();
+ image->shrink_x2();
}
PoolVector<uint8_t> data = Image::lossy_packer(image, p_lossy_quality);
@@ -265,15 +265,15 @@ void ResourceImporterTexture::_save_stex(const Image &p_image, const String &p_t
} break;
case COMPRESS_VIDEO_RAM: {
- Image image = p_image;
- image.generate_mipmaps();
- image.compress(p_vram_compression);
+ Ref<Image> image = p_image->duplicate();
+ image->generate_mipmaps();
+ image->compress(p_vram_compression);
- format |= image.get_format();
+ format |= image->get_format();
f->store_32(format);
- PoolVector<uint8_t> data = image.get_data();
+ PoolVector<uint8_t> data = image->get_data();
int dl = data.size();
PoolVector<uint8_t>::Read r = data.read();
f->store_buffer(r.ptr(), dl);
@@ -281,17 +281,17 @@ void ResourceImporterTexture::_save_stex(const Image &p_image, const String &p_t
} break;
case COMPRESS_UNCOMPRESSED: {
- Image image = p_image;
+ Ref<Image> image = p_image->duplicate();
if (p_mipmaps) {
- image.generate_mipmaps();
+ image->generate_mipmaps();
} else {
- image.clear_mipmaps();
+ image->clear_mipmaps();
}
- format |= image.get_format();
+ format |= image->get_format();
f->store_32(format);
- PoolVector<uint8_t> data = image.get_data();
+ PoolVector<uint8_t> data = image->get_data();
int dl = data.size();
PoolVector<uint8_t>::Read r = data.read();
@@ -317,8 +317,9 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
bool stream = p_options["stream"];
int size_limit = p_options["size_limit"];
- Image image;
- Error err = ImageLoader::load_image(p_source_file, &image);
+ Ref<Image> image;
+ image.instance();
+ Error err = ImageLoader::load_image(p_source_file, image);
if (err != OK)
return err;
@@ -336,28 +337,28 @@ Error ResourceImporterTexture::import(const String &p_source_file, const String
if (srgb == 1)
tex_flags |= Texture::FLAG_CONVERT_TO_LINEAR;
- if (size_limit > 0 && (image.get_width() > size_limit || image.get_height() > size_limit)) {
+ if (size_limit > 0 && (image->get_width() > size_limit || image->get_height() > size_limit)) {
//limit size
- if (image.get_width() >= image.get_height()) {
+ if (image->get_width() >= image->get_height()) {
int new_width = size_limit;
- int new_height = image.get_height() * new_width / image.get_width();
+ int new_height = image->get_height() * new_width / image->get_width();
- image.resize(new_width, new_height, Image::INTERPOLATE_CUBIC);
+ image->resize(new_width, new_height, Image::INTERPOLATE_CUBIC);
} else {
int new_height = size_limit;
- int new_width = image.get_width() * new_height / image.get_height();
+ int new_width = image->get_width() * new_height / image->get_height();
- image.resize(new_width, new_height, Image::INTERPOLATE_CUBIC);
+ image->resize(new_width, new_height, Image::INTERPOLATE_CUBIC);
}
}
if (fix_alpha_border) {
- image.fix_alpha_edges();
+ image->fix_alpha_edges();
}
if (premult_alpha) {
- image.premultiply_alpha();
+ image->premultiply_alpha();
}
bool detect_3d = p_options["detect_3d"];
diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h
index 196eb48469..e782fc2978 100644
--- a/editor/import/resource_importer_texture.h
+++ b/editor/import/resource_importer_texture.h
@@ -30,7 +30,9 @@
#ifndef RESOURCEIMPORTTEXTURE_H
#define RESOURCEIMPORTTEXTURE_H
+#include "image.h"
#include "io/resource_import.h"
+
class StreamTexture;
class ResourceImporterTexture : public ResourceImporter {
@@ -78,7 +80,7 @@ public:
virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
- void _save_stex(const Image &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb);
+ void _save_stex(const Ref<Image> &p_image, const String &p_to_path, int p_compress_mode, float p_lossy_quality, Image::CompressMode p_vram_compression, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb);
virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL);