Added texture properties to the libraries.

This commit is contained in:
Relintai 2022-02-24 10:16:02 +01:00
parent b4cd63847f
commit 40478dda74
3 changed files with 57 additions and 1 deletions

View File

@ -159,6 +159,29 @@ bool Terrain2DLibrary::_supports_caching() {
return false; return false;
} }
//Textures
Ref<Texture> Terrain2DLibrary::texture_get() {
return _texture;
}
void Terrain2DLibrary::texture_set(const Ref<Texture> &value) {
_texture = value;
}
Ref<Texture> Terrain2DLibrary::liquid_texture_get() {
return _liquid_texture;
}
void Terrain2DLibrary::liquid_texture_set(const Ref<Texture> &value) {
_liquid_texture = value;
}
Ref<Texture> Terrain2DLibrary::prop_texture_get() {
return _prop_texture;
}
void Terrain2DLibrary::prop_texture_set(const Ref<Texture> &value) {
_prop_texture = value;
}
//Materials //Materials
void Terrain2DLibrary::material_cache_get_key(Ref<Terrain2DChunk> chunk) { void Terrain2DLibrary::material_cache_get_key(Ref<Terrain2DChunk> chunk) {
@ -355,6 +378,18 @@ void Terrain2DLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("_supports_caching"), &Terrain2DLibrary::_supports_caching); ClassDB::bind_method(D_METHOD("_supports_caching"), &Terrain2DLibrary::_supports_caching);
ClassDB::bind_method(D_METHOD("supports_caching"), &Terrain2DLibrary::supports_caching); ClassDB::bind_method(D_METHOD("supports_caching"), &Terrain2DLibrary::supports_caching);
ClassDB::bind_method(D_METHOD("texture_get"), &Terrain2DLibrary::texture_get);
ClassDB::bind_method(D_METHOD("texture_set", "value"), &Terrain2DLibrary::texture_set);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "texture_set", "texture_get");
ClassDB::bind_method(D_METHOD("liquid_texture_get"), &Terrain2DLibrary::liquid_texture_get);
ClassDB::bind_method(D_METHOD("liquid_texture_set", "value"), &Terrain2DLibrary::liquid_texture_set);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "liquid_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "liquid_texture_set", "liquid_texture_get");
ClassDB::bind_method(D_METHOD("prop_texture_get"), &Terrain2DLibrary::prop_texture_get);
ClassDB::bind_method(D_METHOD("prop_texture_set", "value"), &Terrain2DLibrary::prop_texture_set);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "prop_texture_set", "prop_texture_get");
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
BIND_VMETHOD(MethodInfo("_setup_material_albedo", PropertyInfo(Variant::INT, "material_index"), PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"))); BIND_VMETHOD(MethodInfo("_setup_material_albedo", PropertyInfo(Variant::INT, "material_index"), PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture")));
#else #else
@ -421,7 +456,9 @@ void Terrain2DLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("_prop_material_cache_unref", "key"), &Terrain2DLibrary::_prop_material_cache_unref); ClassDB::bind_method(D_METHOD("_prop_material_cache_unref", "key"), &Terrain2DLibrary::_prop_material_cache_unref);
ClassDB::bind_method(D_METHOD("prop_material_get"), &Terrain2DLibrary::prop_material_get); ClassDB::bind_method(D_METHOD("prop_material_get"), &Terrain2DLibrary::prop_material_get);
ClassDB::bind_method(D_METHOD("prop_material_set" "value"), &Terrain2DLibrary::prop_material_set); ClassDB::bind_method(D_METHOD("prop_material_set"
"value"),
&Terrain2DLibrary::prop_material_set);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "prop_material_set", "prop_material_get"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "prop_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "prop_material_set", "prop_material_get");
ClassDB::bind_method(D_METHOD("terra_surface_get", "index"), &Terrain2DLibrary::terra_surface_get); ClassDB::bind_method(D_METHOD("terra_surface_get", "index"), &Terrain2DLibrary::terra_surface_get);

View File

@ -88,6 +88,15 @@ public:
bool supports_caching(); bool supports_caching();
virtual bool _supports_caching(); virtual bool _supports_caching();
Ref<Texture> texture_get();
void texture_set(const Ref<Texture> &value);
Ref<Texture> liquid_texture_get();
void liquid_texture_set(const Ref<Texture> &value);
Ref<Texture> prop_texture_get();
void prop_texture_set(const Ref<Texture> &value);
void material_cache_get_key(Ref<Terrain2DChunk> chunk); void material_cache_get_key(Ref<Terrain2DChunk> chunk);
virtual void _material_cache_get_key(Ref<Terrain2DChunk> chunk); virtual void _material_cache_get_key(Ref<Terrain2DChunk> chunk);
Ref<Terrain2DMaterialCache> material_cache_get(const int key); Ref<Terrain2DMaterialCache> material_cache_get(const int key);
@ -173,6 +182,11 @@ protected:
static void _bind_methods(); static void _bind_methods();
bool _initialized; bool _initialized;
Ref<Texture> _texture;
Ref<Texture> _liquid_texture;
Ref<Texture> _prop_texture;
Ref<Material> _material; Ref<Material> _material;
Ref<Material> _liquid_material; Ref<Material> _liquid_material;
Ref<Material> _prop_material; Ref<Material> _prop_material;

View File

@ -256,6 +256,9 @@ void Terrain2DLibraryMerger::refresh_rects() {
Ref<Texture> tex = _packer->get_generated_texture(0); Ref<Texture> tex = _packer->get_generated_texture(0);
texture_set(tex);
liquid_texture_set(tex);
setup_material_albedo(MATERIAL_INDEX_TERRAIN, tex); setup_material_albedo(MATERIAL_INDEX_TERRAIN, tex);
setup_material_albedo(MATERIAL_INDEX_LIQUID, tex); setup_material_albedo(MATERIAL_INDEX_LIQUID, tex);
} }
@ -280,6 +283,8 @@ void Terrain2DLibraryMerger::refresh_rects() {
Ref<Texture> tex = _prop_packer->get_generated_texture(0); Ref<Texture> tex = _prop_packer->get_generated_texture(0);
prop_texture_set(tex);
setup_material_albedo(MATERIAL_INDEX_PROP, tex); setup_material_albedo(MATERIAL_INDEX_PROP, tex);
} }
#endif #endif