diff --git a/library/terraman_library.cpp b/library/terraman_library.cpp index 40055e2..61a0676 100644 --- a/library/terraman_library.cpp +++ b/library/terraman_library.cpp @@ -37,13 +37,42 @@ void TerramanLibrary::set_initialized(const bool value) { _initialized = value; } +bool TerramanLibrary::supports_caching() { + return call("_supports_caching"); +} +bool TerramanLibrary::_supports_caching() { + return false; +} + //Materials Ref TerramanLibrary::material_get(const int index) { - ERR_FAIL_INDEX_V(index, _materials.size(), Ref(NULL)); + ERR_FAIL_INDEX_V(index, _materials.size(), Ref(NULL)); return _materials[index]; } +Ref TerramanLibrary::material_lod_get(const int index) { + ERR_FAIL_COND_V(_materials.size() == 0, Ref(NULL)); + + if (index < 0) { + return _materials[0]; + } + + if (index >= _materials.size()) { + return _materials[_materials.size() - 1]; + } + + return _materials[index]; +} + +Ref TerramanLibrary::material_lod_cached_get(const int index, const PoolIntArray &surfaces) { + return call("_material_lod_cached_get", index, surfaces); +} + +Ref TerramanLibrary::_material_lod_cached_get(const int index, const PoolIntArray &surfaces) { + ERR_FAIL_V_MSG(material_lod_get(index), "This TerramanLibrary doesn't support cached materials!"); +} + void TerramanLibrary::material_add(const Ref &value) { ERR_FAIL_COND(!value.is_valid()); @@ -84,11 +113,34 @@ void TerramanLibrary::materials_set(const Vector &materials) { //Liquid Materials Ref TerramanLibrary::liquid_material_get(const int index) { - ERR_FAIL_INDEX_V(index, _liquid_materials.size(), Ref(NULL)); + ERR_FAIL_INDEX_V(index, _liquid_materials.size(), Ref(NULL)); return _liquid_materials[index]; } +Ref TerramanLibrary::liquid_material_lod_get(const int index) { + ERR_FAIL_COND_V(_materials.size() == 0, Ref(NULL)); + + if (index < 0) { + return _liquid_materials[0]; + } + + if (index >= _liquid_materials.size()) { + return _liquid_materials[_liquid_materials.size() - 1]; + } + + return _liquid_materials[index]; +} + +Ref TerramanLibrary::liquid_material_lod_cached_get(const int index, const PoolIntArray &surfaces) { + return call("_liquid_material_lod_cached_get", index, surfaces); +} + +Ref TerramanLibrary::_liquid_material_lod_cached_get(const int index, const PoolIntArray &surfaces) { + ERR_FAIL_V_MSG(liquid_material_lod_get(index), "This TerramanLibrary doesn't support cached liquid materials!"); +} + + void TerramanLibrary::liquid_material_add(const Ref &value) { ERR_FAIL_COND(!value.is_valid()); @@ -129,11 +181,34 @@ void TerramanLibrary::liquid_materials_set(const Vector &materials) { //Prop Materials Ref TerramanLibrary::prop_material_get(const int index) { - ERR_FAIL_INDEX_V(index, _prop_materials.size(), Ref(NULL)); + ERR_FAIL_INDEX_V(index, _prop_materials.size(), Ref(NULL)); return _prop_materials[index]; } +Ref TerramanLibrary::prop_material_lod_get(const int index) { + ERR_FAIL_COND_V(_prop_materials.size() == 0, Ref(NULL)); + + if (index < 0) { + return _prop_materials[0]; + } + + if (index >= _prop_materials.size()) { + return _prop_materials[_prop_materials.size() - 1]; + } + + return _prop_materials[index]; +} + +Ref TerramanLibrary::prop_material_lod_cached_get(const int index, const PoolIntArray &surfaces) { + return call("_prop_material_lod_cached_get", index, surfaces); +} + +Ref TerramanLibrary::_prop_material_lod_cached_get(const int index, const PoolIntArray &surfaces) { + ERR_FAIL_V_MSG(prop_material_lod_get(index), "This TerramanLibrary doesn't support cached prop materials!"); +} + + void TerramanLibrary::prop_material_add(const Ref &value) { ERR_FAIL_COND(!value.is_valid()); @@ -248,7 +323,12 @@ void TerramanLibrary::_bind_methods() { BIND_VMETHOD(MethodInfo("_setup_material_albedo", PropertyInfo(Variant::INT, "material_index"), PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"))); + BIND_VMETHOD(MethodInfo("_material_lod_cached_get", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::POOL_INT_ARRAY, "surfaces"))); + ClassDB::bind_method(D_METHOD("material_get", "index"), &TerramanLibrary::material_get); + ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &TerramanLibrary::material_lod_get); + ClassDB::bind_method(D_METHOD("material_lod_cached_get", "index", "surfaces"), &TerramanLibrary::material_lod_cached_get); + ClassDB::bind_method(D_METHOD("_material_lod_cached_get", "index", "surfaces"), &TerramanLibrary::_material_lod_cached_get); ClassDB::bind_method(D_METHOD("material_add", "value"), &TerramanLibrary::material_add); ClassDB::bind_method(D_METHOD("material_set", "index", "value"), &TerramanLibrary::material_set); ClassDB::bind_method(D_METHOD("material_remove", "index"), &TerramanLibrary::material_remove); @@ -259,7 +339,12 @@ void TerramanLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("materials_set"), &TerramanLibrary::materials_set); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "materials_set", "materials_get"); + BIND_VMETHOD(MethodInfo("_liquid_material_lod_cached_get", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::POOL_INT_ARRAY, "surfaces"))); + ClassDB::bind_method(D_METHOD("liquid_material_get", "index"), &TerramanLibrary::liquid_material_get); + ClassDB::bind_method(D_METHOD("liquid_material_lod_get", "index"), &TerramanLibrary::liquid_material_lod_get); + ClassDB::bind_method(D_METHOD("liquid_material_lod_cached_get", "index", "surfaces"), &TerramanLibrary::liquid_material_lod_cached_get); + ClassDB::bind_method(D_METHOD("_liquid_material_lod_cached_get", "index", "surfaces"), &TerramanLibrary::_liquid_material_lod_cached_get); ClassDB::bind_method(D_METHOD("liquid_material_add", "value"), &TerramanLibrary::liquid_material_add); ClassDB::bind_method(D_METHOD("liquid_material_set", "index", "value"), &TerramanLibrary::liquid_material_set); ClassDB::bind_method(D_METHOD("liquid_material_remove", "index"), &TerramanLibrary::liquid_material_remove); @@ -270,7 +355,12 @@ void TerramanLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("liquid_materials_set"), &TerramanLibrary::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"); + BIND_VMETHOD(MethodInfo("_material_lod_cached_get", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::POOL_INT_ARRAY, "surfaces"))); + ClassDB::bind_method(D_METHOD("prop_material_get", "index"), &TerramanLibrary::prop_material_get); + ClassDB::bind_method(D_METHOD("prop_material_lod_get", "index"), &TerramanLibrary::prop_material_lod_get); + ClassDB::bind_method(D_METHOD("prop_material_lod_cached_get", "index", "surfaces"), &TerramanLibrary::prop_material_lod_cached_get); + ClassDB::bind_method(D_METHOD("_prop_material_lod_cached_get", "index", "surfaces"), &TerramanLibrary::_prop_material_lod_cached_get); ClassDB::bind_method(D_METHOD("prop_material_add", "value"), &TerramanLibrary::prop_material_add); ClassDB::bind_method(D_METHOD("prop_material_set", "index", "value"), &TerramanLibrary::prop_material_set); ClassDB::bind_method(D_METHOD("prop_material_remove", "index"), &TerramanLibrary::prop_material_remove); diff --git a/library/terraman_library.h b/library/terraman_library.h index 42eeba7..5b61bbe 100644 --- a/library/terraman_library.h +++ b/library/terraman_library.h @@ -64,7 +64,13 @@ public: bool get_initialized() const; void set_initialized(const bool value); + bool supports_caching(); + virtual bool _supports_caching(); + Ref material_get(const int index); + Ref material_lod_get(const int index); + Ref material_lod_cached_get(const int index, const PoolIntArray &surfaces); + virtual Ref _material_lod_cached_get(const int index, const PoolIntArray &surfaces); void material_add(const Ref &value); void material_set(const int index, const Ref &value); void material_remove(const int index); @@ -75,6 +81,9 @@ public: void materials_set(const Vector &materials); Ref liquid_material_get(const int index); + Ref liquid_material_lod_get(const int index); + Ref liquid_material_lod_cached_get(const int index, const PoolIntArray &surfaces); + virtual Ref _liquid_material_lod_cached_get(const int index, const PoolIntArray &surfaces); void liquid_material_add(const Ref &value); void liquid_material_set(const int index, const Ref &value); void liquid_material_remove(const int index); @@ -85,6 +94,9 @@ public: void liquid_materials_set(const Vector &materials); Ref prop_material_get(const int index); + Ref prop_material_lod_get(const int index); + Ref prop_material_lod_cached_get(const int index, const PoolIntArray &surfaces); + virtual Ref _prop_material_lod_cached_get(const int index, const PoolIntArray &surfaces); void prop_material_add(const Ref &value); void prop_material_set(const int index, const Ref &value); void prop_material_remove(const int index);