mirror of
https://github.com/Relintai/terraman_2d.git
synced 2024-11-12 10:15:18 +01:00
Removed multiple (lod) material support.
This commit is contained in:
parent
193b5dee93
commit
f077cb218e
@ -160,25 +160,6 @@ bool Terrain2DLibrary::_supports_caching() {
|
||||
}
|
||||
|
||||
//Materials
|
||||
Ref<Material> Terrain2DLibrary::material_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _materials.size(), Ref<Material>());
|
||||
|
||||
return _materials[index];
|
||||
}
|
||||
|
||||
Ref<Material> Terrain2DLibrary::material_lod_get(const int index) {
|
||||
ERR_FAIL_COND_V_MSG(_materials.size() == 0, Ref<Material>(), "Error! You should to add at least one material to Terrain2DLibrary! (By default it will use up to 5. See VoxelWorldDefault::_create_chunk().)");
|
||||
|
||||
if (index < 0) {
|
||||
return _materials[0];
|
||||
}
|
||||
|
||||
if (index >= _materials.size()) {
|
||||
return _materials[_materials.size() - 1];
|
||||
}
|
||||
|
||||
return _materials[index];
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::material_cache_get_key(Ref<Terrain2DChunk> chunk) {
|
||||
CALL(_material_cache_get_key, chunk);
|
||||
@ -201,65 +182,15 @@ void Terrain2DLibrary::material_cache_unref(const int key) {
|
||||
void Terrain2DLibrary::_material_cache_unref(const int key) {
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::material_add(const Ref<Material> &value) {
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_materials.push_back(value);
|
||||
Ref<Material> Terrain2DLibrary::material_get() {
|
||||
return _material;
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::material_set(const int index, const Ref<Material> &value) {
|
||||
ERR_FAIL_INDEX(index, _materials.size());
|
||||
|
||||
_materials.set(index, value);
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::material_remove(const int index) {
|
||||
_materials.VREMOVE(index);
|
||||
}
|
||||
|
||||
int Terrain2DLibrary::material_get_num() const {
|
||||
return _materials.size();
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::materials_clear() {
|
||||
_materials.clear();
|
||||
}
|
||||
|
||||
Vector<Variant> Terrain2DLibrary::materials_get() {
|
||||
VARIANT_ARRAY_GET(_materials);
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::materials_set(const Vector<Variant> &materials) {
|
||||
_materials.clear();
|
||||
|
||||
for (int i = 0; i < materials.size(); i++) {
|
||||
Ref<Material> material = Ref<Material>(materials[i]);
|
||||
|
||||
_materials.push_back(material);
|
||||
}
|
||||
void Terrain2DLibrary::material_set(const Ref<Material> &value) {
|
||||
_material = value;
|
||||
}
|
||||
|
||||
//Liquid Materials
|
||||
Ref<Material> Terrain2DLibrary::liquid_material_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _liquid_materials.size(), Ref<Material>());
|
||||
|
||||
return _liquid_materials[index];
|
||||
}
|
||||
|
||||
Ref<Material> Terrain2DLibrary::liquid_material_lod_get(const int index) {
|
||||
ERR_FAIL_COND_V_MSG(_liquid_materials.size() == 0, Ref<Material>(), "Error! You should to add at least one liquid to Terrain2DLibrary! (By default it will use up to 5. See VoxelWorldDefault::_create_chunk().)");
|
||||
|
||||
if (index < 0) {
|
||||
return _liquid_materials[0];
|
||||
}
|
||||
|
||||
if (index >= _liquid_materials.size()) {
|
||||
return _liquid_materials[_liquid_materials.size() - 1];
|
||||
}
|
||||
|
||||
return _liquid_materials[index];
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::liquid_material_cache_get_key(Ref<Terrain2DChunk> chunk) {
|
||||
CALL(_liquid_material_cache_get_key, chunk);
|
||||
}
|
||||
@ -281,64 +212,15 @@ void Terrain2DLibrary::liquid_material_cache_unref(const int key) {
|
||||
void Terrain2DLibrary::_liquid_material_cache_unref(const int key) {
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::liquid_material_add(const Ref<Material> &value) {
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_liquid_materials.push_back(value);
|
||||
Ref<Material> Terrain2DLibrary::liquid_material_get() {
|
||||
return _liquid_material;
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::liquid_material_set(const int index, const Ref<Material> &value) {
|
||||
ERR_FAIL_INDEX(index, _liquid_materials.size());
|
||||
|
||||
_liquid_materials.set(index, value);
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::liquid_material_remove(const int index) {
|
||||
_liquid_materials.VREMOVE(index);
|
||||
}
|
||||
|
||||
int Terrain2DLibrary::liquid_material_get_num() const {
|
||||
return _liquid_materials.size();
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::liquid_materials_clear() {
|
||||
_liquid_materials.clear();
|
||||
}
|
||||
|
||||
Vector<Variant> Terrain2DLibrary::liquid_materials_get() {
|
||||
VARIANT_ARRAY_GET(_liquid_materials);
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::liquid_materials_set(const Vector<Variant> &materials) {
|
||||
_liquid_materials.clear();
|
||||
|
||||
for (int i = 0; i < materials.size(); i++) {
|
||||
Ref<Material> material = Ref<Material>(materials[i]);
|
||||
|
||||
_liquid_materials.push_back(material);
|
||||
}
|
||||
void Terrain2DLibrary::liquid_material_set(const Ref<Material> &value) {
|
||||
_liquid_material = value;
|
||||
}
|
||||
|
||||
//Prop2D Materials
|
||||
Ref<Material> Terrain2DLibrary::prop_material_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _prop_materials.size(), Ref<Material>());
|
||||
|
||||
return _prop_materials[index];
|
||||
}
|
||||
|
||||
Ref<Material> Terrain2DLibrary::prop_material_lod_get(const int index) {
|
||||
ERR_FAIL_COND_V_MSG(_prop_materials.size() == 0, Ref<Material>(), "Error! You should to add at least one prop material to Terrain2DLibrary! (By default it will use up to 5. See VoxelWorldDefault::_create_chunk().)");
|
||||
|
||||
if (index < 0) {
|
||||
return _prop_materials[0];
|
||||
}
|
||||
|
||||
if (index >= _prop_materials.size()) {
|
||||
return _prop_materials[_prop_materials.size() - 1];
|
||||
}
|
||||
|
||||
return _prop_materials[index];
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::prop_material_cache_get_key(Ref<Terrain2DChunk> chunk) {
|
||||
CALL(_prop_material_cache_get_key, chunk);
|
||||
@ -361,36 +243,12 @@ void Terrain2DLibrary::prop_material_cache_unref(const int key) {
|
||||
void Terrain2DLibrary::_prop_material_cache_unref(const int key) {
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::prop_material_add(const Ref<Material> &value) {
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_prop_materials.push_back(value);
|
||||
Ref<Material> Terrain2DLibrary::prop_material_get() {
|
||||
return _prop_material;
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::prop_material_set(const int index, const Ref<Material> &value) {
|
||||
ERR_FAIL_INDEX(index, _prop_materials.size());
|
||||
|
||||
_prop_materials.set(index, value);
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::prop_material_remove(const int index) {
|
||||
_prop_materials.VREMOVE(index);
|
||||
}
|
||||
|
||||
int Terrain2DLibrary::prop_material_get_num() const {
|
||||
return _prop_materials.size();
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::prop_materials_clear() {
|
||||
_prop_materials.clear();
|
||||
}
|
||||
|
||||
Vector<Variant> Terrain2DLibrary::prop_materials_get() {
|
||||
VARIANT_ARRAY_GET(_prop_materials);
|
||||
}
|
||||
|
||||
void Terrain2DLibrary::prop_materials_set(const Vector<Variant> &materials) {
|
||||
VARIANT_ARRAY_SET(materials, _prop_materials, Material);
|
||||
void Terrain2DLibrary::prop_material_set(const Ref<Material> &value) {
|
||||
_prop_material = value;
|
||||
}
|
||||
|
||||
//Surfaces
|
||||
@ -464,9 +322,9 @@ Terrain2DLibrary::Terrain2DLibrary() {
|
||||
}
|
||||
|
||||
Terrain2DLibrary::~Terrain2DLibrary() {
|
||||
_materials.clear();
|
||||
_liquid_materials.clear();
|
||||
_prop_materials.clear();
|
||||
_material.unref();
|
||||
_liquid_material.unref();
|
||||
_prop_material.unref();
|
||||
}
|
||||
|
||||
#if VERSION_MAJOR >= 4
|
||||
@ -513,9 +371,6 @@ void Terrain2DLibrary::_bind_methods() {
|
||||
GDVIRTUAL_BIND(_material_cache_unref, "key");
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("material_get", "index"), &Terrain2DLibrary::material_get);
|
||||
ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &Terrain2DLibrary::material_lod_get);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("material_cache_get_key", "chunk"), &Terrain2DLibrary::material_cache_get_key);
|
||||
ClassDB::bind_method(D_METHOD("_material_cache_get_key", "chunk"), &Terrain2DLibrary::_material_cache_get_key);
|
||||
ClassDB::bind_method(D_METHOD("material_cache_get", "key"), &Terrain2DLibrary::material_cache_get);
|
||||
@ -523,15 +378,9 @@ void Terrain2DLibrary::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("material_cache_unref", "key"), &Terrain2DLibrary::material_cache_unref);
|
||||
ClassDB::bind_method(D_METHOD("_material_cache_unref", "key"), &Terrain2DLibrary::_material_cache_unref);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("material_add", "value"), &Terrain2DLibrary::material_add);
|
||||
ClassDB::bind_method(D_METHOD("material_set", "index", "value"), &Terrain2DLibrary::material_set);
|
||||
ClassDB::bind_method(D_METHOD("material_remove", "index"), &Terrain2DLibrary::material_remove);
|
||||
ClassDB::bind_method(D_METHOD("material_get_num"), &Terrain2DLibrary::material_get_num);
|
||||
ClassDB::bind_method(D_METHOD("materials_clear"), &Terrain2DLibrary::materials_clear);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("materials_get"), &Terrain2DLibrary::materials_get);
|
||||
ClassDB::bind_method(D_METHOD("materials_set"), &Terrain2DLibrary::materials_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "materials_set", "materials_get");
|
||||
ClassDB::bind_method(D_METHOD("material_get"), &Terrain2DLibrary::material_get);
|
||||
ClassDB::bind_method(D_METHOD("material_set", "value"), &Terrain2DLibrary::material_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "material_set", "material_get");
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_liquid_material_cache_get_key", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DChunk")));
|
||||
@ -543,9 +392,6 @@ void Terrain2DLibrary::_bind_methods() {
|
||||
GDVIRTUAL_BIND(_liquid_material_cache_unref, "key");
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_get", "index"), &Terrain2DLibrary::liquid_material_get);
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_lod_get", "index"), &Terrain2DLibrary::liquid_material_lod_get);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_cache_get_key", "chunk"), &Terrain2DLibrary::liquid_material_cache_get_key);
|
||||
ClassDB::bind_method(D_METHOD("_liquid_material_cache_get_key", "chunk"), &Terrain2DLibrary::_liquid_material_cache_get_key);
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_cache_get", "key"), &Terrain2DLibrary::liquid_material_cache_get);
|
||||
@ -553,15 +399,9 @@ void Terrain2DLibrary::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_cache_unref", "key"), &Terrain2DLibrary::liquid_material_cache_unref);
|
||||
ClassDB::bind_method(D_METHOD("_liquid_material_cache_unref", "key"), &Terrain2DLibrary::_liquid_material_cache_unref);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_add", "value"), &Terrain2DLibrary::liquid_material_add);
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_set", "index", "value"), &Terrain2DLibrary::liquid_material_set);
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_remove", "index"), &Terrain2DLibrary::liquid_material_remove);
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_get_num"), &Terrain2DLibrary::liquid_material_get_num);
|
||||
ClassDB::bind_method(D_METHOD("liquid_materials_clear"), &Terrain2DLibrary::liquid_materials_clear);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("liquid_materials_get"), &Terrain2DLibrary::liquid_materials_get);
|
||||
ClassDB::bind_method(D_METHOD("liquid_materials_set"), &Terrain2DLibrary::liquid_materials_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "liquid_materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "liquid_materials_set", "liquid_materials_get");
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_get"), &Terrain2DLibrary::liquid_material_get);
|
||||
ClassDB::bind_method(D_METHOD("liquid_material_set", "value"), &Terrain2DLibrary::liquid_material_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "liquid_material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "liquid_material_set", "liquid_material_get");
|
||||
|
||||
#if VERSION_MAJOR < 4
|
||||
BIND_VMETHOD(MethodInfo("_prop_material_cache_get_key", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "Terrain2DChunk")));
|
||||
@ -573,9 +413,6 @@ void Terrain2DLibrary::_bind_methods() {
|
||||
GDVIRTUAL_BIND(_prop_material_cache_unref, "key");
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("prop_material_get", "index"), &Terrain2DLibrary::prop_material_get);
|
||||
ClassDB::bind_method(D_METHOD("prop_material_lod_get", "index"), &Terrain2DLibrary::prop_material_lod_get);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("prop_material_cache_get_key", "chunk"), &Terrain2DLibrary::prop_material_cache_get_key);
|
||||
ClassDB::bind_method(D_METHOD("_prop_material_cache_get_key", "chunk"), &Terrain2DLibrary::_prop_material_cache_get_key);
|
||||
ClassDB::bind_method(D_METHOD("prop_material_cache_get", "key"), &Terrain2DLibrary::prop_material_cache_get);
|
||||
@ -583,15 +420,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_add", "value"), &Terrain2DLibrary::prop_material_add);
|
||||
ClassDB::bind_method(D_METHOD("prop_material_set", "index", "value"), &Terrain2DLibrary::prop_material_set);
|
||||
ClassDB::bind_method(D_METHOD("prop_material_remove", "index"), &Terrain2DLibrary::prop_material_remove);
|
||||
ClassDB::bind_method(D_METHOD("prop_material_get_num"), &Terrain2DLibrary::prop_material_get_num);
|
||||
ClassDB::bind_method(D_METHOD("prop_materials_clear"), &Terrain2DLibrary::prop_materials_clear);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("prop_materials_get"), &Terrain2DLibrary::prop_materials_get);
|
||||
ClassDB::bind_method(D_METHOD("prop_materials_set"), &Terrain2DLibrary::prop_materials_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "prop_materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "prop_materials_set", "prop_materials_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);
|
||||
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_add", "value"), &Terrain2DLibrary::terra_surface_add);
|
||||
|
@ -88,9 +88,6 @@ public:
|
||||
bool supports_caching();
|
||||
virtual bool _supports_caching();
|
||||
|
||||
Ref<Material> material_get(const int index);
|
||||
Ref<Material> material_lod_get(const int index);
|
||||
|
||||
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);
|
||||
@ -98,17 +95,8 @@ public:
|
||||
void material_cache_unref(const int key);
|
||||
virtual void _material_cache_unref(const int key);
|
||||
|
||||
void material_add(const Ref<Material> &value);
|
||||
void material_set(const int index, const Ref<Material> &value);
|
||||
void material_remove(const int index);
|
||||
int material_get_num() const;
|
||||
void materials_clear();
|
||||
|
||||
Vector<Variant> materials_get();
|
||||
void materials_set(const Vector<Variant> &materials);
|
||||
|
||||
Ref<Material> liquid_material_get(const int index);
|
||||
Ref<Material> liquid_material_lod_get(const int index);
|
||||
Ref<Material> material_get();
|
||||
void material_set(const Ref<Material> &value);
|
||||
|
||||
void liquid_material_cache_get_key(Ref<Terrain2DChunk> chunk);
|
||||
virtual void _liquid_material_cache_get_key(Ref<Terrain2DChunk> chunk);
|
||||
@ -117,17 +105,8 @@ public:
|
||||
void liquid_material_cache_unref(const int key);
|
||||
virtual void _liquid_material_cache_unref(const int key);
|
||||
|
||||
void liquid_material_add(const Ref<Material> &value);
|
||||
void liquid_material_set(const int index, const Ref<Material> &value);
|
||||
void liquid_material_remove(const int index);
|
||||
int liquid_material_get_num() const;
|
||||
void liquid_materials_clear();
|
||||
|
||||
Vector<Variant> liquid_materials_get();
|
||||
void liquid_materials_set(const Vector<Variant> &materials);
|
||||
|
||||
Ref<Material> prop_material_get(const int index);
|
||||
Ref<Material> prop_material_lod_get(const int index);
|
||||
Ref<Material> liquid_material_get();
|
||||
void liquid_material_set(const Ref<Material> &value);
|
||||
|
||||
void prop_material_cache_get_key(Ref<Terrain2DChunk> chunk);
|
||||
virtual void _prop_material_cache_get_key(Ref<Terrain2DChunk> chunk);
|
||||
@ -136,14 +115,8 @@ public:
|
||||
void prop_material_cache_unref(const int key);
|
||||
virtual void _prop_material_cache_unref(const int key);
|
||||
|
||||
void prop_material_add(const Ref<Material> &value);
|
||||
void prop_material_set(const int index, const Ref<Material> &value);
|
||||
void prop_material_remove(const int index);
|
||||
int prop_material_get_num() const;
|
||||
void prop_materials_clear();
|
||||
|
||||
Vector<Variant> prop_materials_get();
|
||||
void prop_materials_set(const Vector<Variant> &materials);
|
||||
Ref<Material> prop_material_get();
|
||||
void prop_material_set(const Ref<Material> &value);
|
||||
|
||||
virtual Ref<Terrain2DSurface> terra_surface_get(const int index);
|
||||
virtual void terra_surface_add(Ref<Terrain2DSurface> value);
|
||||
@ -200,9 +173,9 @@ protected:
|
||||
static void _bind_methods();
|
||||
|
||||
bool _initialized;
|
||||
Vector<Ref<Material>> _materials;
|
||||
Vector<Ref<Material>> _liquid_materials;
|
||||
Vector<Ref<Material>> _prop_materials;
|
||||
Ref<Material> _material;
|
||||
Ref<Material> _liquid_material;
|
||||
Ref<Material> _prop_material;
|
||||
};
|
||||
|
||||
#endif // TERRAIN_2D_LIBRARY_H
|
||||
|
@ -296,65 +296,17 @@ void Terrain2DLibraryMerger::refresh_rects() {
|
||||
}
|
||||
|
||||
void Terrain2DLibraryMerger::_setup_material_albedo(const int material_index, const Ref<Texture> &texture) {
|
||||
Ref<SpatialMaterial> mat;
|
||||
|
||||
int count = 0;
|
||||
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_TERRAIN:
|
||||
count = material_get_num();
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
count = liquid_material_get_num();
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
count = prop_material_get_num();
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_TERRAIN:
|
||||
mat = material_get(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
mat = liquid_material_get(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
mat = prop_material_get(i);
|
||||
break;
|
||||
}
|
||||
|
||||
Ref<SpatialMaterial> spmat;
|
||||
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_TERRAIN:
|
||||
spmat = material_get(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
spmat = liquid_material_get(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
spmat = prop_material_get(i);
|
||||
break;
|
||||
}
|
||||
|
||||
if (spmat.is_valid()) {
|
||||
spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<ShaderMaterial> shmat;
|
||||
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_TERRAIN:
|
||||
shmat = material_get(i);
|
||||
shmat = material_get();
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
shmat = liquid_material_get(i);
|
||||
shmat = liquid_material_get();
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
shmat = prop_material_get(i);
|
||||
shmat = prop_material_get();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -362,7 +314,6 @@ void Terrain2DLibraryMerger::_setup_material_albedo(const int material_index, co
|
||||
shmat->set_shader_param("texture_albedo", texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Terrain2DLibraryMerger::Terrain2DLibraryMerger() {
|
||||
_packer.instance();
|
||||
|
@ -172,16 +172,9 @@ void Terrain2DLibraryMergerPCM::_material_cache_get_key(Ref<Terrain2DChunk> chun
|
||||
cache->surface_add(nms);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _materials.size(); ++i) {
|
||||
Ref<Material> m = _materials[i];
|
||||
|
||||
if (!m.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Ref<Material> nm = m->duplicate();
|
||||
|
||||
cache->material_add(nm);
|
||||
if (_material.is_valid()) {
|
||||
Ref<Material> nm = _material->duplicate();
|
||||
cache->material_set(nm);
|
||||
}
|
||||
|
||||
_material_cache[hash] = cache;
|
||||
@ -338,16 +331,10 @@ void Terrain2DLibraryMergerPCM::_prop_material_cache_get_key(Ref<Terrain2DChunk>
|
||||
cache->set_background_color(get_background_color());
|
||||
cache->set_margin(get_margin());
|
||||
|
||||
for (int i = 0; i < _prop_materials.size(); ++i) {
|
||||
Ref<Material> m = _prop_materials[i];
|
||||
if (_prop_material.is_valid()) {
|
||||
Ref<Material> nm = _prop_material->duplicate();
|
||||
|
||||
if (!m.is_valid()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Ref<Material> nm = m->duplicate();
|
||||
|
||||
cache->material_add(nm);
|
||||
cache->material_set(nm);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -684,65 +671,17 @@ void Terrain2DLibraryMergerPCM::refresh_rects() {
|
||||
}
|
||||
|
||||
void Terrain2DLibraryMergerPCM::_setup_material_albedo(const int material_index, const Ref<Texture> &texture) {
|
||||
Ref<SpatialMaterial> mat;
|
||||
|
||||
int count = 0;
|
||||
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_TERRAIN:
|
||||
count = material_get_num();
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
count = liquid_material_get_num();
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
count = prop_material_get_num();
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_TERRAIN:
|
||||
mat = material_get(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
mat = liquid_material_get(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
mat = prop_material_get(i);
|
||||
break;
|
||||
}
|
||||
|
||||
Ref<SpatialMaterial> spmat;
|
||||
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_TERRAIN:
|
||||
spmat = material_get(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
spmat = liquid_material_get(i);
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
spmat = prop_material_get(i);
|
||||
break;
|
||||
}
|
||||
|
||||
if (spmat.is_valid()) {
|
||||
spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
|
||||
return;
|
||||
}
|
||||
|
||||
Ref<ShaderMaterial> shmat;
|
||||
|
||||
switch (material_index) {
|
||||
case MATERIAL_INDEX_TERRAIN:
|
||||
shmat = material_get(i);
|
||||
shmat = material_get();
|
||||
break;
|
||||
case MATERIAL_INDEX_LIQUID:
|
||||
shmat = liquid_material_get(i);
|
||||
shmat = liquid_material_get();
|
||||
break;
|
||||
case MATERIAL_INDEX_PROP:
|
||||
shmat = prop_material_get(i);
|
||||
shmat = prop_material_get();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -750,7 +689,6 @@ void Terrain2DLibraryMergerPCM::_setup_material_albedo(const int material_index,
|
||||
shmat->set_shader_param("texture_albedo", texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Terrain2DLibraryMergerPCM::Terrain2DLibraryMergerPCM() {
|
||||
_packer.instance();
|
||||
|
@ -54,62 +54,12 @@ void Terrain2DMaterialCache::dec_ref_count() {
|
||||
}
|
||||
|
||||
//Materials
|
||||
Ref<Material> Terrain2DMaterialCache::material_get(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _materials.size(), Ref<Material>(NULL));
|
||||
|
||||
return _materials[index];
|
||||
Ref<Material> Terrain2DMaterialCache::material_get() {
|
||||
return _material;
|
||||
}
|
||||
|
||||
Ref<Material> Terrain2DMaterialCache::material_lod_get(const int index) {
|
||||
ERR_FAIL_COND_V(_materials.size() == 0, Ref<Material>(NULL));
|
||||
|
||||
if (index < 0) {
|
||||
return _materials[0];
|
||||
}
|
||||
|
||||
if (index >= _materials.size()) {
|
||||
return _materials[_materials.size() - 1];
|
||||
}
|
||||
|
||||
return _materials[index];
|
||||
}
|
||||
|
||||
void Terrain2DMaterialCache::material_add(const Ref<Material> &value) {
|
||||
ERR_FAIL_COND(!value.is_valid());
|
||||
|
||||
_materials.push_back(value);
|
||||
}
|
||||
|
||||
void Terrain2DMaterialCache::material_set(const int index, const Ref<Material> &value) {
|
||||
ERR_FAIL_INDEX(index, _materials.size());
|
||||
|
||||
_materials.set(index, value);
|
||||
}
|
||||
|
||||
void Terrain2DMaterialCache::material_remove(const int index) {
|
||||
_materials.VREMOVE(index);
|
||||
}
|
||||
|
||||
int Terrain2DMaterialCache::material_get_num() const {
|
||||
return _materials.size();
|
||||
}
|
||||
|
||||
void Terrain2DMaterialCache::materials_clear() {
|
||||
_materials.clear();
|
||||
}
|
||||
|
||||
Vector<Variant> Terrain2DMaterialCache::materials_get() {
|
||||
VARIANT_ARRAY_GET(_materials);
|
||||
}
|
||||
|
||||
void Terrain2DMaterialCache::materials_set(const Vector<Variant> &materials) {
|
||||
_materials.clear();
|
||||
|
||||
for (int i = 0; i < materials.size(); i++) {
|
||||
Ref<Material> material = Ref<Material>(materials[i]);
|
||||
|
||||
_materials.push_back(material);
|
||||
}
|
||||
void Terrain2DMaterialCache::material_set(const Ref<Material> &value) {
|
||||
_material = value;
|
||||
}
|
||||
|
||||
//Surfaces
|
||||
@ -271,7 +221,7 @@ Terrain2DMaterialCache::Terrain2DMaterialCache() {
|
||||
}
|
||||
|
||||
Terrain2DMaterialCache::~Terrain2DMaterialCache() {
|
||||
_materials.clear();
|
||||
_material.unref();
|
||||
_surfaces.clear();
|
||||
}
|
||||
|
||||
@ -292,17 +242,9 @@ void Terrain2DMaterialCache::_bind_methods() {
|
||||
GDVIRTUAL_BIND(_setup_material_albedo, "texture");
|
||||
#endif
|
||||
|
||||
ClassDB::bind_method(D_METHOD("material_get", "index"), &Terrain2DMaterialCache::material_get);
|
||||
ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &Terrain2DMaterialCache::material_lod_get);
|
||||
ClassDB::bind_method(D_METHOD("material_add", "value"), &Terrain2DMaterialCache::material_add);
|
||||
ClassDB::bind_method(D_METHOD("material_set", "index", "value"), &Terrain2DMaterialCache::material_set);
|
||||
ClassDB::bind_method(D_METHOD("material_remove", "index"), &Terrain2DMaterialCache::material_remove);
|
||||
ClassDB::bind_method(D_METHOD("material_get_num"), &Terrain2DMaterialCache::material_get_num);
|
||||
ClassDB::bind_method(D_METHOD("materials_clear"), &Terrain2DMaterialCache::materials_clear);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("materials_get"), &Terrain2DMaterialCache::materials_get);
|
||||
ClassDB::bind_method(D_METHOD("materials_set"), &Terrain2DMaterialCache::materials_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "materials_set", "materials_get");
|
||||
ClassDB::bind_method(D_METHOD("material_get"), &Terrain2DMaterialCache::material_get);
|
||||
ClassDB::bind_method(D_METHOD("material_set", "value"), &Terrain2DMaterialCache::material_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "material_set", "material_get");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("surface_get", "index"), &Terrain2DMaterialCache::surface_get);
|
||||
ClassDB::bind_method(D_METHOD("surface_id_get", "index"), &Terrain2DMaterialCache::surface_id_get);
|
||||
|
@ -56,16 +56,8 @@ public:
|
||||
void inc_ref_count();
|
||||
void dec_ref_count();
|
||||
|
||||
Ref<Material> material_get(const int index);
|
||||
Ref<Material> material_lod_get(const int index);
|
||||
void material_add(const Ref<Material> &value);
|
||||
void material_set(const int index, const Ref<Material> &value);
|
||||
void material_remove(const int index);
|
||||
int material_get_num() const;
|
||||
void materials_clear();
|
||||
|
||||
Vector<Variant> materials_get();
|
||||
void materials_set(const Vector<Variant> &materials);
|
||||
Ref<Material> material_get();
|
||||
void material_set(const Ref<Material> &value);
|
||||
|
||||
virtual Ref<Terrain2DSurface> surface_get(const int index);
|
||||
virtual Ref<Terrain2DSurface> surface_id_get(const int id);
|
||||
@ -107,7 +99,7 @@ protected:
|
||||
bool _initialized;
|
||||
|
||||
Vector<Ref<Terrain2DSurface>> _surfaces;
|
||||
Vector<Ref<Material>> _materials;
|
||||
Ref<Material> _material;
|
||||
Vector<Ref<Texture>> _additional_textures;
|
||||
|
||||
int _ref_count;
|
||||
|
@ -158,17 +158,7 @@ void Terrain2DMaterialCachePCM::refresh_rects() {
|
||||
}
|
||||
|
||||
void Terrain2DMaterialCachePCM::_setup_material_albedo(Ref<Texture> texture) {
|
||||
int count = material_get_num();
|
||||
|
||||
for (int i = 0; i < count; ++i) {
|
||||
Ref<Material> m = material_get(i);
|
||||
|
||||
Ref<SpatialMaterial> spmat = m;
|
||||
|
||||
if (spmat.is_valid()) {
|
||||
spmat->set_texture(SpatialMaterial::TEXTURE_ALBEDO, texture);
|
||||
return;
|
||||
}
|
||||
Ref<Material> m = material_get();
|
||||
|
||||
Ref<ShaderMaterial> shmat = m;
|
||||
|
||||
@ -176,7 +166,6 @@ void Terrain2DMaterialCachePCM::_setup_material_albedo(Ref<Texture> texture) {
|
||||
shmat->set_shader_param("texture_albedo", texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Terrain2DMaterialCachePCM::Terrain2DMaterialCachePCM() {
|
||||
_packer.instance();
|
||||
|
@ -252,9 +252,6 @@ void Terrain2DMesher::build_mesh_into(RID mesh) {
|
||||
Array arr = build_mesh();
|
||||
|
||||
VS::get_singleton()->mesh_add_surface_from_arrays(mesh, VisualServer::PRIMITIVE_TRIANGLES, arr);
|
||||
|
||||
if (_material.is_valid())
|
||||
VS::get_singleton()->mesh_surface_set_material(mesh, 0, _library->material_lod_get(0)->get_rid());
|
||||
}
|
||||
|
||||
void Terrain2DMesher::remove_doubles() {
|
||||
|
@ -364,18 +364,6 @@ void Terrain2DProp2DJob::step_type_normal() {
|
||||
RID mesh_rid = chunk->mesh_rid_get_index(Terrain2DChunkDefault::MESH_INDEX_PROP, Terrain2DChunkDefault::MESH_TYPE_INDEX_MESH, 0);
|
||||
|
||||
VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
|
||||
|
||||
Ref<Material> lmat;
|
||||
|
||||
if (chunk->prop_material_cache_key_has()) {
|
||||
lmat = chunk->get_library()->prop_material_cache_get(_chunk->prop_material_cache_key_get())->material_lod_get(0);
|
||||
} else {
|
||||
lmat = chunk->get_library()->prop_material_lod_get(0);
|
||||
}
|
||||
|
||||
if (lmat.is_valid()) {
|
||||
VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, lmat->get_rid());
|
||||
}
|
||||
}
|
||||
|
||||
Terrain2DProp2DJob::Terrain2DProp2DJob() {
|
||||
|
@ -297,14 +297,6 @@ void Terrain2DTerrain2DJob::phase_terrain_mesh() {
|
||||
|
||||
// if (should_do()) {
|
||||
VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
|
||||
|
||||
if (chunk->get_library()->liquid_material_lod_get(0).is_valid())
|
||||
VS::get_singleton()->mesh_surface_set_material(mesh_rid, 0, chunk->get_library()->liquid_material_lod_get(0)->get_rid());
|
||||
|
||||
// if (should_return()) {
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
reset_stages();
|
||||
@ -389,18 +381,6 @@ void Terrain2DTerrain2DJob::step_type_normal() {
|
||||
RID mesh_rid = chunk->mesh_rid_get_index(Terrain2DChunkDefault::MESH_INDEX_TERRAIN, Terrain2DChunkDefault::MESH_TYPE_INDEX_MESH, 0);
|
||||
|
||||
VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
|
||||
|
||||
Ref<Material> lmat;
|
||||
|
||||
if (chunk->material_cache_key_has()) {
|
||||
lmat = chunk->get_library()->material_cache_get(_chunk->material_cache_key_get())->material_lod_get(0);
|
||||
} else {
|
||||
lmat = chunk->get_library()->material_lod_get(0);
|
||||
}
|
||||
|
||||
if (lmat.is_valid()) {
|
||||
VisualServer::get_singleton()->mesh_surface_set_material(mesh_rid, 0, lmat->get_rid());
|
||||
}
|
||||
}
|
||||
|
||||
Terrain2DTerrain2DJob::Terrain2DTerrain2DJob() {
|
||||
|
Loading…
Reference in New Issue
Block a user