Removed lod code from TVVoxelChunk as it got ported to Voxelman. Update HEADS to get the new version.

This commit is contained in:
Relintai 2020-03-30 19:48:41 +02:00
parent 29e61139a8
commit 874891cbe9
2 changed files with 97 additions and 133 deletions

2
HEADS
View File

@ -1 +1 @@
{"engine": {"3.2": "da4eb7101d986af0ba6a15efaaed3dee77370d80", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "533c25e96fe0e5c46f68e6a532da6583cf86f4e2"}, "entity_spell_system": {"master": "0bc136962658731bac3e9e1b23bd9677f4dea9de"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "393ee1fb1b0a4ef66343942134b2104b378e9d77"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "ea3b34d972fb5f76474daabd7c1e192419811348"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "16d0ff1ed1e986202ed7f743d3c70666e0859b28"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "dc598c59322185032835f964db069964244e58bc"}} {"engine": {"3.2": "da4eb7101d986af0ba6a15efaaed3dee77370d80", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "533c25e96fe0e5c46f68e6a532da6583cf86f4e2"}, "entity_spell_system": {"master": "0bc136962658731bac3e9e1b23bd9677f4dea9de"}, "ui_extensions": {"master": "38acc650db260a831dc26ca96fe9d9a087230bdc"}, "voxelman": {"master": "f26fe74fc47bc1c448c9d3888caf67aa53e8f5a4"}, "texture_packer": {"master": "b17c174906f84de93d84aa60d010ffe603efaa28"}, "fastnoise": {"master": "ea3b34d972fb5f76474daabd7c1e192419811348"}, "mesh_data_resource": {"master": "4bda19b12be2c2a79a6121de6d22e48f3934e726"}, "procedural_animations": {"master": "16d0ff1ed1e986202ed7f743d3c70666e0859b28"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "dc598c59322185032835f964db069964244e58bc"}}

View File

@ -30,10 +30,6 @@ var _textures : Array
var _prop_material : SpatialMaterial var _prop_material : SpatialMaterial
var _entities_spawned : bool var _entities_spawned : bool
const GENERATE_LOD = true
const LOD_NUM = 3
var current_lod_level : int = 0 setget set_current_lod_level, get_current_lod_level
#func _enter_tree(): #func _enter_tree():
# create_debug_immediate_geometry() # create_debug_immediate_geometry()
@ -80,7 +76,7 @@ func build_phase_prop_mesh() -> void:
return return
if has_meshes(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH): if has_meshes(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH):
create_meshes(MESH_INDEX_PROP, LOD_NUM + 1) create_meshes(MESH_INDEX_PROP, lod_num + 1)
# if _prop_material == null: # if _prop_material == null:
# _prop_material = SpatialMaterial.new() # _prop_material = SpatialMaterial.new()
@ -205,111 +201,106 @@ func _build_phase(phase):
#set_physics_process_internal(true) #set_physics_process_internal(true)
active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_PHYSICS_PROCESS active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_PHYSICS_PROCESS
return return
elif phase == VoxelChunkDefault.BUILD_PHASE_TERRARIN_MESH: # elif phase == VoxelChunkDefault.BUILD_PHASE_TERRARIN_MESH:
for i in range(get_mesher_count()): # for i in range(get_mesher_count()):
var mesher : VoxelMesher = get_mesher(i) # var mesher : VoxelMesher = get_mesher(i)
mesher.bake_colors(self) # mesher.bake_colors(self)
for i in range(get_mesher_count()):
var mesher : VoxelMesher = get_mesher(i)
mesher.set_library(library)
var mesh_rid : RID = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
if mesh_rid == RID():
create_meshes(MESH_INDEX_TERRARIN, LOD_NUM + 1)
mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
var mesher : VoxelMesher = null
for i in range(get_mesher_count()):
var m : VoxelMesher = get_mesher(i)
if mesher == null:
mesher = m
continue
mesher.set_material(library.material)
mesher.add_mesher(m)
if (mesh_rid != RID()):
VisualServer.mesh_clear(mesh_rid)
if mesher.get_vertex_count() == 0:
next_phase()
return true
if (mesh_rid == RID()):
create_meshes(MESH_INDEX_TERRARIN, LOD_NUM + 1)
mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
var arr : Array = mesher.build_mesh()
VisualServer.mesh_add_surface_from_arrays(mesh_rid, VisualServer.PRIMITIVE_TRIANGLES, arr)
if library.get_material(0) != null:
VisualServer.mesh_surface_set_material(mesh_rid, 0, library.get_material(0).get_rid())
# VisualServer.instance_set_visible(get_mesh_instance_rid(), false)
if GENERATE_LOD and LOD_NUM >= 1:
#for lod 1 just remove uv2
arr[VisualServer.ARRAY_TEX_UV2] = null
VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 1), VisualServer.PRIMITIVE_TRIANGLES, arr)
if library.get_material(1) != null:
VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 1), 0, library.get_material(1).get_rid())
if LOD_NUM >= 2:
arr = merge_mesh_array(arr)
VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 2), VisualServer.PRIMITIVE_TRIANGLES, arr)
if library.get_material(2) != null:
VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 2), 0, library.get_material(2).get_rid())
if LOD_NUM >= 3:
var mat : ShaderMaterial = library.get_material(0) as ShaderMaterial
var tex : Texture = mat.get_shader_param("texture_albedo")
arr = bake_mesh_array_uv(arr, tex)
arr[VisualServer.ARRAY_TEX_UV] = null
VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), VisualServer.PRIMITIVE_TRIANGLES, arr)
if library.get_material(3) != null:
VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), 0, library.get_material(3).get_rid())
# if LOD_NUM > 4:
# var fqms : FastQuadraticMeshSimplifier = FastQuadraticMeshSimplifier.new()
# fqms.initialize(merged)
# #
# var arr_merged_simplified : Array = merged # for i in range(get_mesher_count()):
# var mesher : VoxelMesher = get_mesher(i)
# for i in range(2, _lod_meshes.size()): # mesher.set_library(library)
# fqms.simplify_mesh(arr_merged_simplified[0].size() * 0.8, 7) #
# arr_merged_simplified = fqms.get_arrays() # var mesh_rid : RID = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
#
# if arr_merged_simplified[0].size() == 0: # if mesh_rid == RID():
# break # create_meshes(MESH_INDEX_TERRARIN, lod_num + 1)
# mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
# VisualServer.mesh_add_surface_from_arrays(_lod_meshes[i], VisualServer.PRIMITIVE_TRIANGLES, arr_merged_simplified) #
# var mesher : VoxelMesher = null
# if library.get_material(i) != null: # for i in range(get_mesher_count()):
# VisualServer.mesh_surface_set_material(_lod_meshes[i], 0, library.get_material(i).get_rid()) # var m : VoxelMesher = get_mesher(i)
#
next_phase(); # if mesher == null:
# mesher = m
return # continue
#
# mesher.set_material(library.material)
# mesher.add_mesher(m)
#
# if (mesh_rid != RID()):
# VisualServer.mesh_clear(mesh_rid)
#
# if mesher.get_vertex_count() == 0:
# next_phase()
# return true
#
# if (mesh_rid == RID()):
# create_meshes(MESH_INDEX_TERRARIN, lod_num + 1)
# mesh_rid = get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 0)
#
# var arr : Array = mesher.build_mesh()
#
# VisualServer.mesh_add_surface_from_arrays(mesh_rid, VisualServer.PRIMITIVE_TRIANGLES, arr)
#
# if library.get_material(0) != null:
# VisualServer.mesh_surface_set_material(mesh_rid, 0, library.get_material(0).get_rid())
#
## VisualServer.instance_set_visible(get_mesh_instance_rid(), false)
#
# if generate_lod and lod_num >= 1:
# #for lod 1 just remove uv2
#
# arr[VisualServer.ARRAY_TEX_UV2] = null
#
# VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 1), VisualServer.PRIMITIVE_TRIANGLES, arr)
#
# if library.get_material(1) != null:
# VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 1), 0, library.get_material(1).get_rid())
#
# if lod_num >= 2:
# arr = merge_mesh_array(arr)
#
# VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 2), VisualServer.PRIMITIVE_TRIANGLES, arr)
#
# if library.get_material(2) != null:
# VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 2), 0, library.get_material(2).get_rid())
#
# if lod_num >= 3:
# var mat : ShaderMaterial = library.get_material(0) as ShaderMaterial
# var tex : Texture = mat.get_shader_param("texture_albedo")
#
# arr = bake_mesh_array_uv(arr, tex)
# arr[VisualServer.ARRAY_TEX_UV] = null
#
# VisualServer.mesh_add_surface_from_arrays(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), VisualServer.PRIMITIVE_TRIANGLES, arr)
#
# if library.get_material(3) != null:
# VisualServer.mesh_surface_set_material(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH, 3), 0, library.get_material(3).get_rid())
## if lod_num > 4:
## var fqms : FastQuadraticMeshSimplifier = FastQuadraticMeshSimplifier.new()
## fqms.initialize(merged)
##
## var arr_merged_simplified : Array = merged
#
## for i in range(2, _lod_meshes.size()):
## fqms.simplify_mesh(arr_merged_simplified[0].size() * 0.8, 7)
## arr_merged_simplified = fqms.get_arrays()
#
## if arr_merged_simplified[0].size() == 0:
## break
#
## VisualServer.mesh_add_surface_from_arrays(_lod_meshes[i], VisualServer.PRIMITIVE_TRIANGLES, arr_merged_simplified)
#
## if library.get_material(i) != null:
## VisualServer.mesh_surface_set_material(_lod_meshes[i], 0, library.get_material(i).get_rid())
#
# next_phase();
#
# return
elif phase == VoxelChunkDefault.BUILD_PHASE_PROP_MESH: elif phase == VoxelChunkDefault.BUILD_PHASE_PROP_MESH:
# set_physics_process_internal(true) # set_physics_process_internal(true)
active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_PHYSICS_PROCESS active_build_phase_type = VoxelChunkDefault.BUILD_PHASE_TYPE_PHYSICS_PROCESS
return return
elif phase == BUILD_PHASE_FINALIZE:
._build_phase(phase)
set_current_lod_level(current_lod_level)
else: else:
._build_phase(phase) ._build_phase(phase)
@ -353,30 +344,3 @@ func _build_phase_physics_process(phase):
else: else:
._build_phase_physics_process(phase) ._build_phase_physics_process(phase)
func _visibility_changed(visible):
._visibility_changed(visible)
set_current_lod_level(current_lod_level)
func get_current_lod_level():
return current_lod_level
func set_current_lod_level(val):
current_lod_level = val
if not GENERATE_LOD:
return
if current_lod_level < 0:
current_lod_level = 0
if current_lod_level > LOD_NUM:
current_lod_level = LOD_NUM
for i in range(LOD_NUM + 1):
var vis : bool = false
if i == current_lod_level:
vis = true
VisualServer.instance_set_visible(get_mesh_rid_index(MESH_INDEX_TERRARIN, MESH_TYPE_INDEX_MESH_INSTANCE, i), vis)