Added the new resource, and it's importer to the build, and fixed compile.

This commit is contained in:
Relintai 2019-10-22 11:53:49 +02:00
parent b731f18615
commit b0b34add3f
6 changed files with 82 additions and 33 deletions

6
SCsub
View File

@ -6,3 +6,9 @@ env.add_source_files(env.modules_sources,"texture_packer.cpp")
env.add_source_files(env.modules_sources,"rectpack2D/pack.cpp")
env.add_source_files(env.modules_sources,"texture_merger.cpp")
env.add_source_files(env.modules_sources,"texture_resource/packer_image_resource.cpp")
env.add_source_files(env.modules_sources,"texture_resource/editor_plugin_packer_image_resource.cpp")
env.add_source_files(env.modules_sources,"texture_resource/packer_image_resource_importer.cpp")

View File

@ -3,9 +3,23 @@
#include "texture_packer.h"
#include "texture_merger.h"
#include "texture_resource/packer_image_resource.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_plugin.h"
#include "texture_resource/editor_plugin_packer_image_resource.h"
#endif
void register_texture_packer_types() {
ClassDB::register_class<TexturePacker>();
ClassDB::register_class<TextureMerger>();
ClassDB::register_class<PackerImageResource>();
#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<EditorPluginPackerImageResource>();
#endif
}
void unregister_texture_packer_types() {

View File

@ -1,42 +1,60 @@
#include "packer_image_resource.h"
int PackerImageResource::get_width() const {
if (_image.is_valid()) {
return _image->get_width();
}
return 0;
}
int PackerImageResource::get_height() const {
if (_image.is_valid()) {
return _image->get_height();
}
return 0;
}
RID PackerImageResource::get_rid() const {
return RID();
}
bool PackerImageResource::has_alpha() const {
return true;
}
void PackerImageResource::set_flags(uint32_t p_flags) {
}
uint32_t PackerImageResource::get_flags() const {
return 0;
}
void PackerImageResource::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const {
}
void PackerImageResource::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const {
}
void PackerImageResource::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map, bool p_clip_uv) const {
}
bool PackerImageResource::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const {
return false;
}
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() {

View File

@ -11,14 +11,25 @@ class PackerImageResource : public 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();
RID get_rid() const;
bool has_alpha() const;
void set_flags(uint32_t p_flags);
uint32_t get_flags() const;
void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const;
void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const;
bool get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const;
void set_data(const Ref<Image> &p_image);
Ref<Image> get_data() const;
PackerImageResource();
~PackerImageResource();
protected:
static void _bind_methods();

View File

@ -1,4 +1,4 @@
#include "editor_import_collada_mdr.h"
#include "packer_image_resource_importer.h"
String PackerImageResourceImporter::get_importer_name() const {
return "packer_image_resource";
@ -40,20 +40,21 @@ bool PackerImageResourceImporter::get_option_visibility(const String &p_option,
}
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;
*/
return Error::FAILED;
}
PackerImageResourceImporter::PackerImageResourceImporter() {
_importer.instance();
}
PackerImageResourceImporter::~PackerImageResourceImporter() {
_importer.unref();
}

View File

@ -5,6 +5,8 @@
#include "editor/import/editor_import_plugin.h"
#include "core/ustring.h"
#include "core/image.h"
#include "core/io/image_loader.h"
class PackerImageResourceImporter : public EditorImportPlugin {
@ -28,9 +30,6 @@ public:
PackerImageResourceImporter();
~PackerImageResourceImporter();
private:
Ref<EditorSceneImporterCollada> _importer;
};
#endif