Updated voxelman to the latest. Also experimented with meshing.

This commit is contained in:
Relintai 2020-01-13 00:43:45 +01:00
parent ded9fa08a9
commit f909042c09
11 changed files with 193 additions and 87 deletions

2
HEADS
View File

@ -1 +1 @@
{"engine": "478ab8b45b51ccaafb9db0251ff760e7136e33f6", "world_generator": "e5f5d205f8aea478294ad4796b0f3c771dd7e7cf", "entity_spell_system": "6f3744e2cbd4ba8c0ac7c331876c2d7a28beb4b2", "ui_extensions": "8a81cc53100c5a138fbaf927080410025c64c88e", "voxelman": "a67d0393ca22212be2c957ff3634e554242d70c9", "texture_packer": "8d3b160f02054323a1dc4a9bc8b7e1c44fc57753", "fastnoise": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e", "entity-spell-system-addons": "d60e746b158d3ebf9d2ea306af1dd24bcae49be5", "mesh_data_resource": "3fedb4c8534af36d89a1a1a34a6b5ed4d333927a", "ess_data": "3bd637fdd3304b64a18287a49a6b7387acf2f5de", "prop_tool": "df438053ebc900966f8f842fc65f0264f1271d49"} {"engine": "269eb5f06c8874e1257137eabe121d4501758ded", "world_generator": "e5f5d205f8aea478294ad4796b0f3c771dd7e7cf", "entity_spell_system": "6f3744e2cbd4ba8c0ac7c331876c2d7a28beb4b2", "ui_extensions": "8a81cc53100c5a138fbaf927080410025c64c88e", "voxelman": "01bb4927607e4bb937e9f8d066f3c1b5f6ba1e3b", "texture_packer": "8d3b160f02054323a1dc4a9bc8b7e1c44fc57753", "fastnoise": "41b7ea05a1f7aa2b8ecddaa1fd739e64d6970f7e", "entity-spell-system-addons": "d60e746b158d3ebf9d2ea306af1dd24bcae49be5", "mesh_data_resource": "3fedb4c8534af36d89a1a1a34a6b5ed4d333927a", "ess_data": "3bd637fdd3304b64a18287a49a6b7387acf2f5de", "prop_tool": "df438053ebc900966f8f842fc65f0264f1271d49"}

File diff suppressed because one or more lines are too long

View File

@ -51,7 +51,7 @@ func generate_terrarin(chunk : VoxelChunk, spawn_mobs: bool) -> void:
for z in range(0, chunk.size_z + 1): for z in range(0, chunk.size_z + 1):
var val : float = noise.get_noise_2d(x + (chunk.position_x * chunk.size_x), z + (chunk.position_z * chunk.size_z)) var val : float = noise.get_noise_2d(x + (chunk.position_x * chunk.size_x), z + (chunk.position_z * chunk.size_z))
val *= val val *= val
val *= 100 val *= 200
val += 2 val += 2
var tv : float = terr_noise.get_noise_2d(x + (chunk.position_x * chunk.size_x), z + (chunk.position_z * chunk.size_z)) var tv : float = terr_noise.get_noise_2d(x + (chunk.position_x * chunk.size_x), z + (chunk.position_z * chunk.size_z))
@ -72,6 +72,7 @@ func generate_terrarin(chunk : VoxelChunk, spawn_mobs: bool) -> void:
for y in range(0, v): for y in range(0, v):
seed(x + (chunk.position_x * chunk.size_x) + z + (chunk.position_z * chunk.size_z) + y + (chunk.position_y * chunk.size_y)) seed(x + (chunk.position_x * chunk.size_x) + z + (chunk.position_z * chunk.size_z) + y + (chunk.position_y * chunk.size_y))
if v < 2: if v < 2:
chunk.set_voxel(1, x, y, z, VoxelChunk.DEFAULT_CHANNEL_TYPE) chunk.set_voxel(1, x, y, z, VoxelChunk.DEFAULT_CHANNEL_TYPE)
elif v == 2: elif v == 2:
@ -79,11 +80,17 @@ func generate_terrarin(chunk : VoxelChunk, spawn_mobs: bool) -> void:
else: else:
chunk.set_voxel(2, x, y, z, VoxelChunk.DEFAULT_CHANNEL_TYPE) chunk.set_voxel(2, x, y, z, VoxelChunk.DEFAULT_CHANNEL_TYPE)
var val2 : float = (val - int(val)) * 4.0 if y == v - 1:
val2 = int(val2) chunk.set_voxel(int(255.0 * (val - int(val))), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
val2 /= 4.0 else:
chunk.set_voxel(255, x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
chunk.set_voxel(int(255.0 * val2), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
# var val2 : float = (val - int(val)) * 4.0
# val2 = int(val2)
# val2 /= 4.0
# chunk.set_voxel(int(255.0 * val2), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
# chunk.set_voxel(int(255.0 * (val - int(val)) / 180.0) * 180, x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL) # chunk.set_voxel(int(255.0 * (val - int(val)) / 180.0) * 180, x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
# chunk.set_voxel(int(255.0 * (val - int(val))), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL) # chunk.set_voxel(int(255.0 * (val - int(val))), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
@ -102,17 +109,59 @@ func box_blur(chunk : VoxelChunk):
for y in range(0, chunk.size_z): for y in range(0, chunk.size_z):
var avg : float = 0 var avg : float = 0
var avgc : int = 0
avg += chunk.get_voxel(x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL) var curr : int = chunk.get_voxel(x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
avg += chunk.get_voxel(x + 1, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
avg += chunk.get_voxel(x, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL) if curr > 0:
avg += chunk.get_voxel(x + 1, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL) avg += curr
avg += chunk.get_voxel(x, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL) avgc += 1
avg += chunk.get_voxel(x + 1, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
avg += chunk.get_voxel(x, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL) curr = chunk.get_voxel(x + 1, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
avg += chunk.get_voxel(x + 1, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
if curr > 0:
avg += curr
avgc += 1
curr = chunk.get_voxel(x, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
if curr > 0:
avg += curr
avgc += 1
curr = chunk.get_voxel(x + 1, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
if curr > 0:
avg += curr
avgc += 1
curr = chunk.get_voxel(x, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
if curr > 0:
avg += curr
avgc += 1
curr = chunk.get_voxel(x + 1, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
if curr > 0:
avg += curr
avgc += 1
curr = chunk.get_voxel(x, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
if curr > 0:
avg += curr
avgc += 1
curr = chunk.get_voxel(x + 1, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
if curr > 0:
avg += curr
avgc += 1
avg /= float(avgc)
avg /= 8.0
var aavg: int = int(avg) var aavg: int = int(avg)
chunk.set_voxel(aavg, x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL) chunk.set_voxel(aavg, x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)

View File

@ -33,9 +33,31 @@ var lod_data : Array = [
1 #CHUNK_INDEX_BACK 1 #CHUNK_INDEX_BACK
] ]
func _create_mesher(): func _create_meshers():
mesher = VoxelMesherCubic.new() # mesher = VoxelMesherCubic.new()
# mesher = CubicVoxelMesher.new() add_mesher(GDCubicVoxelMesher.new())
# mesher.base_light_value = 0.45 # mesher.base_light_value = 0.45
# mesher.ao_strength = 0.05 # mesher.ao_strength = 0.05
# mesher.ao_strength = 0.2 # mesher.ao_strength = 0.2
func a_build_phase(phase):
if phase == VoxelChunk.BUILD_PHASE_LIGHTS:
# clear_baked_lights()
# generate_random_ao()
#
## var vl : VoxelLight = VoxelLight.new()
#
# bake_lights()
#
# set_physics_process_internal(true)
# ._build_phase(phase)
pass
elif phase == VoxelChunk.BUILD_PHASE_PROP_MESH:
# set_physics_process_internal(true)
._build_phase(phase)
elif phase == VoxelChunk.BUILD_PHASE_FINALIZE:
._build_phase(phase)
notification(NOTIFICATION_TRANSFORM_CHANGED)
else:
._build_phase(phase)

View File

@ -26,12 +26,12 @@ class_name GDCubicVoxelMesher
var count : int = 0 var count : int = 0
func _add_chunk(buffer : VoxelChunk) -> void: func _add_chunk(chunk : VoxelChunk) -> void:
buffer.generate_ao(); chunk.generate_ao();
var x_size : int = buffer.get_size_x() - 1 var x_size : int = chunk.get_size_x() - 1
var y_size : int = buffer.get_size_y() - 1 var y_size : int = chunk.get_size_y() - 1
var z_size : int = buffer.get_size_z() - 1 var z_size : int = chunk.get_size_z() - 1
var voxel_size : float = lod_size var voxel_size : float = lod_size
@ -40,11 +40,11 @@ func _add_chunk(buffer : VoxelChunk) -> void:
var tile_uv_size : float = 1/4.0 var tile_uv_size : float = 1/4.0
var base_light : Color = Color(0.4, 0.4, 0.4) var base_light : Color = Color(0.4, 0.4, 0.4)
for y in range(lod_size, y_size - lod_size, lod_size): for y in range(chunk.get_margin_start() + lod_size, y_size, lod_size):
for z in range(lod_size, z_size - lod_size, lod_size): for z in range(chunk.get_margin_start() + lod_size, z_size, lod_size):
for x in range(lod_size, x_size - lod_size, lod_size): for x in range(chunk.get_margin_start() + lod_size, x_size, lod_size):
cube_points.setup(buffer, x, y, z, lod_size) cube_points.setup(chunk, x, y, z, lod_size)
if not cube_points.has_points(): if not cube_points.has_points():
continue continue
@ -77,6 +77,7 @@ func _add_chunk(buffer : VoxelChunk) -> void:
var face_light_direction : Vector3 = cube_points.get_face_light_direction(face) var face_light_direction : Vector3 = cube_points.get_face_light_direction(face)
for i in range(4): for i in range(4):
add_normal(normals[i])
var light : Color = cube_points.get_face_point_light_color(face, i) var light : Color = cube_points.get_face_point_light_color(face, i)
light += base_light light += base_light

View File

@ -27,8 +27,6 @@ enum GenType {
TEST, NORMAL TEST, NORMAL
} }
signal generation_finished
export(int) var gen_type : int = GenType.NORMAL export(int) var gen_type : int = GenType.NORMAL
export(Array, MeshDataResource) var meshes : Array export(Array, MeshDataResource) var meshes : Array
@ -39,22 +37,26 @@ var spawned : bool = false
var generation_queue : Array var generation_queue : Array
func _ready() -> void: func _ready() -> void:
if level_generator != null:
level_generator.setup(self, 80, false, library)
spawn() spawn()
set_process(true)
func _process(delta : float) -> void: #func _process(delta : float) -> void:
if not generation_queue.empty(): # if not generation_queue.empty():
var chunk : VoxelChunk = generation_queue.front() # var chunk : VoxelChunk = generation_queue.front()
#
if gen_type == GenType.NORMAL: # if gen_type == GenType.NORMAL:
# generate(chunk) ## generate(chunk)
pass # pass
else: # else:
generate_terrarin(chunk) # generate_terrarin(chunk)
#
generation_queue.remove(0) # generation_queue.remove(0)
#
if generation_queue.empty(): # if generation_queue.empty():
emit_signal("generation_finished") # emit_signal("generation_finished")
func generate_terrarin(chunk : VoxelChunk) -> void: func generate_terrarin(chunk : VoxelChunk) -> void:
var buffer : VoxelChunk = chunk.get_buffer() var buffer : VoxelChunk = chunk.get_buffer()
@ -122,35 +124,42 @@ func generate_terrarin(chunk : VoxelChunk) -> void:
chunk.draw_debug_voxel_lights() chunk.draw_debug_voxel_lights()
func spawn_chunk(x : int, y : int, z : int, lod_size : int = 1) -> void: #func spawn_chunk(x : int, y : int, z : int, lod_size : int = 1) -> void:
var name : String = "Chunk," + str(x) + "," + str(y) + "," + str(z) # var name : String = "Chunk," + str(x) + "," + str(y) + "," + str(z)
var chunk : VoxelChunk = VoxelChunk.new() # var chunk : VoxelChunk = VoxelChunk.new()
# var chunk : VoxelChunk = MarchingCubesVoxelChunk.new() ## var chunk : VoxelChunk = MarchingCubesVoxelChunk.new()
#
# chunk.voxel_world = self
# chunk.set_chunk_position(x, y, z)
# chunk.library = library
# chunk.voxel_scale = voxel_scale
# chunk.lod_size = lod_size
# chunk.set_chunk_size(int(chunk_size_x), int(chunk_size_y), int(chunk_size_z))
#
# chunk.create_mesher()
# chunk.mesher.base_light_value = 0.6
#
# chunks[name] = chunk
#
# generation_queue.append(chunk)
chunk.voxel_world = self func _create_chunk(x : int, y : int, z : int, pchunk : Node) -> VoxelChunk:
chunk.set_chunk_position(x, y, z) var chunk : VoxelChunk = CubicVoxelChunk.new()
chunk.library = library
chunk.voxel_scale = voxel_scale
chunk.lod_size = lod_size
chunk.set_chunk_size(int(chunk_size_x), int(chunk_size_y), int(chunk_size_z))
chunk.create_mesher() #chunk.lod_size = 1
chunk.mesher.base_light_value = 0.6
chunks[name] = chunk
generation_queue.append(chunk)
return ._create_chunk(x, y, z, chunk)
func spawn() -> void: func spawn() -> void:
var hsize : int = 4 var hsize : int = 5
# if gen_type == GenType.NORMAL: # if gen_type == GenType.NORMAL:
for x in range(-hsize, hsize): for x in range(-hsize, hsize):
for z in range(-hsize, hsize): for z in range(-hsize, hsize):
for y in range(1): for y in range(-4, 2):
# spawn_chunk(x, y, z, abs(int(ceil(x / 2))) + 1) # spawn_chunk(x, y, z, abs(int(ceil(x / 2))) + 1)
spawn_chunk(x, y, z, 1) # spawn_chunk(x, y, z, 1)
create_chunk(x, y, z)
#func set_player(p_player : Spatial) -> void: #func set_player(p_player : Spatial) -> void:
# player = p_player # player = p_player

View File

@ -1,11 +1,25 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://voxelman/cubic_mesher/CubicVoxelWorld.gd" type="Script" id=1] [ext_resource path="res://voxelman/cubic_mesher/CubicVoxelWorld.gd" type="Script" id=1]
[ext_resource path="res://data/voxel_libraries/1_main_lib_merger_empty.tres" type="VoxelmanLibraryMerger" id=2] [ext_resource path="res://data/voxel_libraries/1_main_lib_merger_empty.tres" type="VoxelmanLibraryMerger" id=2]
[ext_resource path="res://scripts/world_generators/MainPlanetGenerator.gd" type="Script" id=3]
[sub_resource type="VoxelmanLevelGenerator" id=1]
script = ExtResource( 3 )
_force_planet = -1
_level_seed = 0
_spawn_mobs = false
[node name="VoxelWorld" type="VoxelWorld"] [node name="VoxelWorld" type="VoxelWorld"]
use_threads = false
max_concurrent_generations = 1
library = ExtResource( 2 ) library = ExtResource( 2 )
voxel_scale = 2.0 level_generator = SubResource( 1 )
player_path = NodePath("Camera") voxel_scale = 4.0
script = ExtResource( 1 ) script = ExtResource( 1 )
gen_type = 2
[node name="Camera" type="Camera" parent="."]
current = true
[node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 0.751552, -0.185778, 0.632974, 0.622874, -0.116152, -0.773651, 0.217249, 0.975702, 0.028422, 0, 27.1286, 0 )

View File

@ -43,14 +43,16 @@ func _ready():
set_notify_transform(true) set_notify_transform(true)
func _create_mesher(): func _create_meshers():
mesher = TVVoxelMesher.new() var mesher : TVVoxelMesher = TVVoxelMesher.new()
mesher.base_light_value = 0.45 mesher.base_light_value = 0.45
mesher.ao_strength = 0.2 mesher.ao_strength = 0.2
# var m : float = 1.0 / 16.0 # var m : float = 1.0 / 16.0
mesher.uv_margin = Rect2(0.017, 0.017, 1 - 0.034, 1 - 0.034) mesher.uv_margin = Rect2(0.017, 0.017, 1 - 0.034, 1 - 0.034)
add_mesher(mesher)
_prop_texture_packer = TexturePacker.new() _prop_texture_packer = TexturePacker.new()
_prop_texture_packer.max_atlas_size = 1024 _prop_texture_packer.max_atlas_size = 1024
_prop_texture_packer.margin = 1 _prop_texture_packer.margin = 1
@ -77,7 +79,8 @@ func spawn_prop_entities(parent_transform : Transform, prop : PropData):
spawn_prop_entities(get_prop_mesh_transform(parent_transform * p.transform, vmanpp.snap_to_mesh, vmanpp.snap_axis), p.prop) spawn_prop_entities(get_prop_mesh_transform(parent_transform * p.transform, vmanpp.snap_to_mesh, vmanpp.snap_axis), p.prop)
func build_phase_prop_mesh() -> void: func build_phase_prop_mesh() -> void:
mesher.reset() for i in range(get_mesher_count()):
get_mesher(i).reset()
if get_prop_count() == 0: if get_prop_count() == 0:
next_phase() next_phase()
@ -94,7 +97,9 @@ func build_phase_prop_mesh() -> void:
_prop_material.metallic = 0 _prop_material.metallic = 0
VisualServer.instance_geometry_set_material_override(get_prop_mesh_instance_rid(), _prop_material.get_rid()) VisualServer.instance_geometry_set_material_override(get_prop_mesh_instance_rid(), _prop_material.get_rid())
mesher.material = _prop_material
for i in range(get_mesher_count()):
get_mesher(i).material = _prop_material
for i in range(get_prop_count()): for i in range(get_prop_count()):
var prop : VoxelChunkPropData = get_prop(i) var prop : VoxelChunkPropData = get_prop(i)
@ -117,17 +122,20 @@ func build_phase_prop_mesh() -> void:
if prop.mesh != null: if prop.mesh != null:
var t : Transform = get_prop_transform(prop, prop.snap_to_mesh, prop.snap_axis) var t : Transform = get_prop_transform(prop, prop.snap_to_mesh, prop.snap_axis)
prop.prop.add_meshes_into(mesher, _prop_texture_packer, t, self) for i in range(get_mesher_count()):
prop.prop.add_meshes_into(get_mesher(i), _prop_texture_packer, t, self)
if prop.prop != null: if prop.prop != null:
var vmanpp : PropData = prop.prop as PropData var vmanpp : PropData = prop.prop as PropData
var t : Transform = get_prop_transform(prop, vmanpp.snap_to_mesh, vmanpp.snap_axis) var t : Transform = get_prop_transform(prop, vmanpp.snap_to_mesh, vmanpp.snap_axis)
prop.prop.add_meshes_into(mesher, _prop_texture_packer, t, self) for i in range(get_mesher_count()):
prop.prop.add_meshes_into(get_mesher(i), _prop_texture_packer, t, self)
mesher.bake_colors(self) for i in range(get_mesher_count()):
mesher.build_mesh(get_prop_mesh_rid()) get_mesher(i).bake_colors(self)
mesher.material = null get_mesher(i).build_mesh(get_prop_mesh_rid())
get_mesher(i).material = null
if not _entities_spawned: if not _entities_spawned:
for i in range(get_prop_count()): for i in range(get_prop_count()):

View File

@ -67,6 +67,9 @@ func _ready():
func _generation_finished(): func _generation_finished():
initial_generation = false initial_generation = false
# for i in range(get_chunk_count()):
# get_chunk_index(i).draw_debug_voxels(555555)
if show_loading_screen and not Engine.editor_hint: if show_loading_screen and not Engine.editor_hint:
get_node("..").hide_loading_screen() get_node("..").hide_loading_screen()

View File

@ -30,5 +30,5 @@ class_name TVGUVoxelChunk
#func _ready(): #func _ready():
# world = get_node("..") # world = get_node("..")
func _create_mesher(): func _create_meshers():
mesher = TVGUVoxelMesher.new() add_mesher(TVGUVoxelMesher.new())

View File

@ -11,4 +11,4 @@ class_name TVNUVoxelChunk
# world = get_node("..") # world = get_node("..")
func _create_mesher(): func _create_mesher():
mesher = TVNUVoxelMesher.new() add_mesher(TVNUVoxelMesher.new())