mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-04-20 10:23:11 +02:00
TerrainChunkDefault lod change code cleanups and improvements. Also set scenario on entering and exiting the tree.
This commit is contained in:
parent
61a43daa45
commit
556de2db50
@ -82,6 +82,10 @@ int TerrainChunkDefault::get_current_lod_level() const {
|
||||
void TerrainChunkDefault::set_current_lod_level(const int value) {
|
||||
_current_lod_level = value;
|
||||
|
||||
if (!is_in_tree()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ((_build_flags & BUILD_FLAG_CREATE_LODS) == 0) {
|
||||
return;
|
||||
}
|
||||
@ -108,8 +112,44 @@ void TerrainChunkDefault::set_current_lod_level(const int value) {
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_visible(rid, vis);
|
||||
}
|
||||
}
|
||||
|
||||
rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
lod_num = mesh_rid_get_count(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
int target_lod = _current_lod_level;
|
||||
|
||||
if (target_lod > lod_num - 1) {
|
||||
target_lod = lod_num - 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
bool vis = false;
|
||||
|
||||
if (i == target_lod) {
|
||||
vis = true;
|
||||
}
|
||||
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_visible(rid, vis);
|
||||
}
|
||||
}
|
||||
|
||||
lod_num = mesh_rid_get_count(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
target_lod = _current_lod_level;
|
||||
|
||||
if (target_lod > lod_num - 1) {
|
||||
target_lod = lod_num - 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
bool vis = false;
|
||||
|
||||
if (i == target_lod) {
|
||||
vis = true;
|
||||
}
|
||||
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_visible(rid, vis);
|
||||
@ -726,6 +766,12 @@ void TerrainChunkDefault::_visibility_changed(bool visible) {
|
||||
RenderingServer::get_singleton()->instance_set_visible(rid, true);
|
||||
}
|
||||
|
||||
rid = mesh_rid_get_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE, 0);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_visible(rid, true);
|
||||
}
|
||||
|
||||
rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, 0);
|
||||
|
||||
if (rid != RID()) {
|
||||
@ -748,14 +794,22 @@ void TerrainChunkDefault::_visibility_changed(bool visible) {
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_visible(rid, false);
|
||||
}
|
||||
}
|
||||
|
||||
rid = mesh_rid_get_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
lod_num = mesh_rid_get_count(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_visible(rid, false);
|
||||
}
|
||||
}
|
||||
|
||||
rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
lod_num = mesh_rid_get_count(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_visible(rid, false);
|
||||
@ -763,10 +817,74 @@ void TerrainChunkDefault::_visibility_changed(bool visible) {
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainChunkDefault::_enter_tree() {
|
||||
TerrainChunk::_enter_tree();
|
||||
|
||||
RID scenario = get_voxel_world()->get_world_3d()->get_scenario();
|
||||
|
||||
int lod_num = mesh_rid_get_count(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_scenario(rid, scenario);
|
||||
}
|
||||
}
|
||||
|
||||
lod_num = mesh_rid_get_count(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_scenario(rid, scenario);
|
||||
}
|
||||
}
|
||||
|
||||
lod_num = mesh_rid_get_count(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_scenario(rid, scenario);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainChunkDefault::_exit_tree() {
|
||||
TerrainChunk::_exit_tree();
|
||||
|
||||
visibility_changed(false);
|
||||
int lod_num = mesh_rid_get_count(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_scenario(rid, RID());
|
||||
}
|
||||
}
|
||||
|
||||
lod_num = mesh_rid_get_count(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_scenario(rid, RID());
|
||||
}
|
||||
}
|
||||
|
||||
lod_num = mesh_rid_get_count(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE);
|
||||
|
||||
for (int i = 0; i < lod_num; ++i) {
|
||||
RID rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, i);
|
||||
|
||||
if (rid != RID()) {
|
||||
RenderingServer::get_singleton()->instance_set_scenario(rid, RID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainChunkDefault::_world_transform_changed() {
|
||||
|
@ -189,6 +189,7 @@ protected:
|
||||
|
||||
virtual void _visibility_changed(bool visible);
|
||||
|
||||
virtual void _enter_tree();
|
||||
virtual void _exit_tree();
|
||||
virtual void _world_transform_changed();
|
||||
|
||||
|
@ -2057,8 +2057,6 @@ void TerrainChunk::_enter_tree() {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
visibility_changed(_is_visible);
|
||||
}
|
||||
|
||||
void TerrainChunk::_exit_tree() {
|
||||
|
Loading…
Reference in New Issue
Block a user