Port the new getters from props. Also added notes.

This commit is contained in:
Relintai 2022-02-24 00:05:29 +01:00
parent f077cb218e
commit ebc5449101
5 changed files with 31 additions and 17 deletions

View File

@ -142,10 +142,23 @@ Ref<AtlasTexture> Terrain2DMaterialCache::additional_texture_get_atlas(const int
Ref<AtlasTexture> Terrain2DMaterialCache::additional_texture_get_atlas_tex(const Ref<Texture> &texture) { Ref<AtlasTexture> Terrain2DMaterialCache::additional_texture_get_atlas_tex(const Ref<Texture> &texture) {
return Ref<AtlasTexture>(); return Ref<AtlasTexture>();
} }
Rect2 Terrain2DMaterialCache::additional_texture_get_rect(const Ref<Texture> &texture) {
Ref<AtlasTexture> at = additional_texture_get_atlas_tex(texture);
if (!at.is_valid()) {
return Rect2();
}
return at->get_region();
}
Rect2 Terrain2DMaterialCache::additional_texture_get_uv_rect(const Ref<Texture> &texture) { Rect2 Terrain2DMaterialCache::additional_texture_get_uv_rect(const Ref<Texture> &texture) {
return Rect2(0, 0, 1, 1); return Rect2(0, 0, 1, 1);
} }
Ref<Texture> Terrain2DMaterialCache::texture_get_merged() {
return Ref<Texture>();
}
#ifdef PROPS_2D_PRESENT #ifdef PROPS_2D_PRESENT
void Terrain2DMaterialCache::prop_add_textures(const Ref<Prop2DData> &prop) { void Terrain2DMaterialCache::prop_add_textures(const Ref<Prop2DData> &prop) {
if (!prop.is_valid()) { if (!prop.is_valid()) {
@ -263,8 +276,11 @@ void Terrain2DMaterialCache::_bind_methods() {
ClassDB::bind_method(D_METHOD("additional_texture_get", "index"), &Terrain2DMaterialCache::additional_texture_get); ClassDB::bind_method(D_METHOD("additional_texture_get", "index"), &Terrain2DMaterialCache::additional_texture_get);
ClassDB::bind_method(D_METHOD("additional_texture_get_atlas", "index"), &Terrain2DMaterialCache::additional_texture_get_atlas); ClassDB::bind_method(D_METHOD("additional_texture_get_atlas", "index"), &Terrain2DMaterialCache::additional_texture_get_atlas);
ClassDB::bind_method(D_METHOD("additional_texture_get_atlas_tex", "index"), &Terrain2DMaterialCache::additional_texture_get_atlas_tex); ClassDB::bind_method(D_METHOD("additional_texture_get_atlas_tex", "index"), &Terrain2DMaterialCache::additional_texture_get_atlas_tex);
ClassDB::bind_method(D_METHOD("additional_texture_get_rect", "texture"), &Terrain2DMaterialCache::additional_texture_get_rect);
ClassDB::bind_method(D_METHOD("additional_texture_get_uv_rect", "texture"), &Terrain2DMaterialCache::additional_texture_get_uv_rect); ClassDB::bind_method(D_METHOD("additional_texture_get_uv_rect", "texture"), &Terrain2DMaterialCache::additional_texture_get_uv_rect);
ClassDB::bind_method(D_METHOD("texture_get_merged"), &Terrain2DMaterialCache::texture_get_merged);
#ifdef PROPS_2D_PRESENT #ifdef PROPS_2D_PRESENT
ClassDB::bind_method(D_METHOD("prop_add_textures", "prop"), &Terrain2DMaterialCache::prop_add_textures); ClassDB::bind_method(D_METHOD("prop_add_textures", "prop"), &Terrain2DMaterialCache::prop_add_textures);
ClassDB::bind_method(D_METHOD("prop_remove_textures", "prop"), &Terrain2DMaterialCache::prop_remove_textures); ClassDB::bind_method(D_METHOD("prop_remove_textures", "prop"), &Terrain2DMaterialCache::prop_remove_textures);

View File

@ -75,8 +75,14 @@ public:
virtual Ref<Texture> additional_texture_get(const int index); virtual Ref<Texture> additional_texture_get(const int index);
virtual Ref<AtlasTexture> additional_texture_get_atlas(const int index); virtual Ref<AtlasTexture> additional_texture_get_atlas(const int index);
virtual Ref<AtlasTexture> additional_texture_get_atlas_tex(const Ref<Texture> &texture); virtual Ref<AtlasTexture> additional_texture_get_atlas_tex(const Ref<Texture> &texture);
virtual Rect2 additional_texture_get_rect(const Ref<Texture> &texture);
virtual Rect2 additional_texture_get_uv_rect(const Ref<Texture> &texture); virtual Rect2 additional_texture_get_uv_rect(const Ref<Texture> &texture);
//todo rename to get texture, and make it a property.
//mergers set it themselves
//Also do it for props
virtual Ref<Texture> texture_get_merged();
#ifdef PROPS_2D_PRESENT #ifdef PROPS_2D_PRESENT
void prop_add_textures(const Ref<Prop2DData> &prop); void prop_add_textures(const Ref<Prop2DData> &prop);
void prop_remove_textures(const Ref<Prop2DData> &prop); void prop_remove_textures(const Ref<Prop2DData> &prop);

View File

@ -141,9 +141,9 @@ void Terrain2DMaterialCachePCM::refresh_rects() {
ERR_FAIL_COND(_packer->get_texture_count() == 0); ERR_FAIL_COND(_packer->get_texture_count() == 0);
Ref<Texture> tex = _packer->get_generated_texture(0); _merged_texture = _packer->get_generated_texture(0);
setup_material_albedo(tex); setup_material_albedo(_merged_texture);
} }
for (int i = 0; i < _surfaces.size(); i++) { for (int i = 0; i < _surfaces.size(); i++) {
@ -157,6 +157,10 @@ void Terrain2DMaterialCachePCM::refresh_rects() {
_initialized = true; _initialized = true;
} }
Ref<Texture> Terrain2DMaterialCachePCM::texture_get_merged() {
return _merged_texture;
}
void Terrain2DMaterialCachePCM::_setup_material_albedo(Ref<Texture> texture) { void Terrain2DMaterialCachePCM::_setup_material_albedo(Ref<Texture> texture) {
Ref<Material> m = material_get(); Ref<Material> m = material_get();

View File

@ -70,6 +70,8 @@ public:
void refresh_rects(); void refresh_rects();
Ref<Texture> texture_get_merged();
void _setup_material_albedo(Ref<Texture> texture); void _setup_material_albedo(Ref<Texture> texture);
Terrain2DMaterialCachePCM(); Terrain2DMaterialCachePCM();
@ -79,6 +81,7 @@ protected:
static void _bind_methods(); static void _bind_methods();
Ref<TexturePacker> _packer; Ref<TexturePacker> _packer;
Ref<Texture> _merged_texture;
}; };
#endif #endif

View File

@ -184,12 +184,6 @@ void Terrain2DTerrain2DJob::phase_physics_process() {
chunk->colliders_create(Terrain2DChunkDefault::MESH_INDEX_LIQUID); chunk->colliders_create(Terrain2DChunkDefault::MESH_INDEX_LIQUID);
} }
} }
/*
else {
if (!has_meshes(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_AREA)) {
create_colliders_area(MESH_INDEX_LIQUID);
}
}*/
PhysicsServer::get_singleton()->shape_set_data(chunk->mesh_rid_get(Terrain2DChunkDefault::MESH_INDEX_LIQUID, Terrain2DChunkDefault::MESH_TYPE_INDEX_SHAPE), temp_arr_collider_liquid); PhysicsServer::get_singleton()->shape_set_data(chunk->mesh_rid_get(Terrain2DChunkDefault::MESH_INDEX_LIQUID, Terrain2DChunkDefault::MESH_TYPE_INDEX_SHAPE), temp_arr_collider_liquid);
@ -211,14 +205,6 @@ void Terrain2DTerrain2DJob::phase_terrain_mesh() {
} }
if ((chunk->get_build_flags() & Terrain2DChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0) { if ((chunk->get_build_flags() & Terrain2DChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0) {
//if (should_do()) {
// _mesher->bake_colors(_chunk);
// if (should_return()) {
// return;
// }
//}
if (should_do()) { if (should_do()) {
if (_liquid_mesher.is_valid()) { if (_liquid_mesher.is_valid()) {
_liquid_mesher->bake_colors(_chunk); _liquid_mesher->bake_colors(_chunk);
@ -295,7 +281,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); VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr);
} }