Work on an image resource class, and a custom importer.

This commit is contained in:
Relintai 2019-10-22 04:22:32 +02:00
parent 8d8e20a396
commit b731f18615
6 changed files with 216 additions and 0 deletions

View File

@ -0,0 +1,22 @@
#include "editor_plugin_packer_image_resource.h"
void EditorPluginPackerImageResource::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
_importer.instance();
add_import_plugin(_importer);
break;
case NOTIFICATION_EXIT_TREE:
remove_import_plugin(_importer);
_importer.unref();
break;
}
}
EditorPluginPackerImageResource::EditorPluginPackerImageResource(EditorNode *node) {
_node = node;
}

View File

@ -0,0 +1,25 @@
#ifndef EDITOR_PLUGIN_PACKER_IMAGE_RESOURCE_H
#define EDITOR_PLUGIN_PACKER_IMAGE_RESOURCE_H
#include "editor/editor_plugin.h"
#include "core/ustring.h"
#include "packer_image_resource_importer.h"
class EditorPluginPackerImageResource : public EditorPlugin {
GDCLASS(EditorPluginPackerImageResource, EditorPlugin);
public:
EditorPluginPackerImageResource(EditorNode *node);
protected:
void _notification(int p_what);
private:
EditorNode *_node;
Ref<PackerImageResourceImporter> _importer;
};
#endif

View File

@ -0,0 +1,44 @@
#include "packer_image_resource.h"
void PackerImageResource::set_data(const Ref<Image> &p_image) {
ERR_FAIL_COND(p_image.is_null());
_image = p_image;
}
void PackerImageResource::_resource_path_changed() {
String path = get_path();
}
Ref<Image> PackerImageResource::get_data() const {
return _image;
}
int PackerImageResource::get_width() const {
return w;
}
int PackerImageResource::get_height() const {
return h;
}
void PackerImageResource::_set_data(Dictionary p_data) {
Ref<Image> img = p_data["image"];
ERR_FAIL_COND(!img.is_valid());
uint32_t flags = p_data["flags"];
};
void PackerImageResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_data", "image"), &PackerImageResource::set_data);
}
PackerImageResource::PackerImageResource() {
w = h = 0;
}
PackerImageResource::~PackerImageResource() {
_image.unref();
}

View File

@ -0,0 +1,30 @@
#ifndef PACKER_IMAGE_REOURCE_H
#define PACKER_IMAGE_REOURCE_H
#include "core/image.h"
#include "scene/resources/texture.h"
class PackerImageResource : public Texture {
GDCLASS(PackerImageResource, Texture);
RES_BASE_EXTENSION("tres");
public:
void set_data(const Ref<Image> &p_image);
Ref<Image> get_data() const;
int get_width() const;
int get_height() const;
ImageTexture();
~ImageTexture();
protected:
static void _bind_methods();
private:
Ref<Image> _image;
};
#endif

View File

@ -0,0 +1,59 @@
#include "editor_import_collada_mdr.h"
String PackerImageResourceImporter::get_importer_name() const {
return "packer_image_resource";
}
String PackerImageResourceImporter::get_visible_name() const {
return "Packer Image Resource";
}
void PackerImageResourceImporter::get_recognized_extensions(List<String> *p_extensions) const {
ImageLoader::get_recognized_extensions(p_extensions);
}
String PackerImageResourceImporter::get_save_extension() const {
return "tres";
}
String PackerImageResourceImporter::get_resource_type() const {
return "PackerImageResource";
}
float PackerImageResourceImporter::get_priority() const {
return 1.0;
}
int PackerImageResourceImporter::get_preset_count() const {
return 0;
}
String PackerImageResourceImporter::get_preset_name(int p_idx) const {
return "";
}
void PackerImageResourceImporter::get_import_options(List<ImportOption> *r_options, int p_preset) const {
}
bool PackerImageResourceImporter::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const {
return true;
}
Error PackerImageResourceImporter::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, Variant *r_metadata) {
Ref<Image> image;
image.instance();
Error err = ImageLoader::load_image(p_source_file, image, NULL, hdr_as_srgb, scale);
if (err != OK)
return err;
}
PackerImageResourceImporter::PackerImageResourceImporter() {
_importer.instance();
}
PackerImageResourceImporter::~PackerImageResourceImporter() {
_importer.unref();
}

View File

@ -0,0 +1,36 @@
#ifndef EDITOR_IMPORT_COLLADA_MDR
#define EDITOR_IMPORT_COLLADA_MDR
#include "editor/import/editor_import_plugin.h"
#include "core/ustring.h"
class PackerImageResourceImporter : public EditorImportPlugin {
GDCLASS(PackerImageResourceImporter, EditorImportPlugin);
public:
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_save_extension() const;
virtual String get_resource_type() const;
virtual float get_priority() const;
virtual int get_preset_count() const;
virtual String get_preset_name(int p_idx) const;
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;
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, Variant *r_metadata = NULL);
PackerImageResourceImporter();
~PackerImageResourceImporter();
private:
Ref<EditorSceneImporterCollada> _importer;
};
#endif