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):
var val : float = noise.get_noise_2d(x + (chunk.position_x * chunk.size_x), z + (chunk.position_z * chunk.size_z))
val *= val
val *= 100
val *= 200
val += 2
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):
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:
chunk.set_voxel(1, x, y, z, VoxelChunk.DEFAULT_CHANNEL_TYPE)
elif v == 2:
@ -79,18 +80,24 @@ func generate_terrarin(chunk : VoxelChunk, spawn_mobs: bool) -> void:
else:
chunk.set_voxel(2, x, y, z, VoxelChunk.DEFAULT_CHANNEL_TYPE)
var val2 : float = (val - int(val)) * 4.0
val2 = int(val2)
val2 /= 4.0
if y == v - 1:
chunk.set_voxel(int(255.0 * (val - int(val))), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
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))), x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
# box_blur(chunk)
# chunk.build()
if not Engine.editor_hint and chunk.position_y == 0 and spawn_mobs:
Entities.spawn_mob(1, randi() % 3, Vector3(chunk.position_x * chunk.size_x * chunk.voxel_scale - chunk.size_x / 2,\
(chunk.position_y + 1) * chunk.size_y * chunk.voxel_scale, \
@ -102,17 +109,59 @@ func box_blur(chunk : VoxelChunk):
for y in range(0, chunk.size_z):
var avg : float = 0
var avgc : int = 0
avg += 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)
avg += chunk.get_voxel(x + 1, y, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
avg += chunk.get_voxel(x, y + 1, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
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)
avg += chunk.get_voxel(x + 1, y + 1, z + 1, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
var curr : int = chunk.get_voxel(x, y, z, VoxelChunk.DEFAULT_CHANNEL_ISOLEVEL)
if curr > 0:
avg += curr
avgc += 1
curr = chunk.get_voxel(x + 1, y, z, 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)
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
]
func _create_mesher():
mesher = VoxelMesherCubic.new()
# mesher = CubicVoxelMesher.new()
func _create_meshers():
# mesher = VoxelMesherCubic.new()
add_mesher(GDCubicVoxelMesher.new())
# mesher.base_light_value = 0.45
# mesher.ao_strength = 0.05
# 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
func _add_chunk(buffer : VoxelChunk) -> void:
buffer.generate_ao();
func _add_chunk(chunk : VoxelChunk) -> void:
chunk.generate_ao();
var x_size : int = buffer.get_size_x() - 1
var y_size : int = buffer.get_size_y() - 1
var z_size : int = buffer.get_size_z() - 1
var x_size : int = chunk.get_size_x() - 1
var y_size : int = chunk.get_size_y() - 1
var z_size : int = chunk.get_size_z() - 1
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 base_light : Color = Color(0.4, 0.4, 0.4)
for y in range(lod_size, y_size - lod_size, lod_size):
for z in range(lod_size, z_size - lod_size, lod_size):
for x in range(lod_size, x_size - lod_size, lod_size):
for y in range(chunk.get_margin_start() + lod_size, y_size, lod_size):
for z in range(chunk.get_margin_start() + lod_size, z_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():
continue
@ -77,6 +77,7 @@ func _add_chunk(buffer : VoxelChunk) -> void:
var face_light_direction : Vector3 = cube_points.get_face_light_direction(face)
for i in range(4):
add_normal(normals[i])
var light : Color = cube_points.get_face_point_light_color(face, i)
light += base_light
@ -93,7 +94,7 @@ func _add_chunk(buffer : VoxelChunk) -> void:
light.b = clamp(light.b, 0, 1.0)
add_uv((cube_points.get_point_uv_direction(face, i) + Vector2(0.5, 0.5)) * Vector2(tile_uv_size, tile_uv_size))
add_vertex((vertices[i] * voxel_size + Vector3(x, y, z)) * voxel_scale)

View File

@ -27,8 +27,6 @@ enum GenType {
TEST, NORMAL
}
signal generation_finished
export(int) var gen_type : int = GenType.NORMAL
export(Array, MeshDataResource) var meshes : Array
@ -39,22 +37,26 @@ var spawned : bool = false
var generation_queue : Array
func _ready() -> void:
if level_generator != null:
level_generator.setup(self, 80, false, library)
spawn()
set_process(true)
func _process(delta : float) -> void:
if not generation_queue.empty():
var chunk : VoxelChunk = generation_queue.front()
if gen_type == GenType.NORMAL:
# generate(chunk)
pass
else:
generate_terrarin(chunk)
generation_queue.remove(0)
if generation_queue.empty():
emit_signal("generation_finished")
#func _process(delta : float) -> void:
# if not generation_queue.empty():
# var chunk : VoxelChunk = generation_queue.front()
#
# if gen_type == GenType.NORMAL:
## generate(chunk)
# pass
# else:
# generate_terrarin(chunk)
#
# generation_queue.remove(0)
#
# if generation_queue.empty():
# emit_signal("generation_finished")
func generate_terrarin(chunk : VoxelChunk) -> void:
var buffer : VoxelChunk = chunk.get_buffer()
@ -122,35 +124,42 @@ func generate_terrarin(chunk : VoxelChunk) -> void:
chunk.draw_debug_voxel_lights()
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 chunk : VoxelChunk = VoxelChunk.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
#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 chunk : VoxelChunk = VoxelChunk.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)
chunks[name] = chunk
func _create_chunk(x : int, y : int, z : int, pchunk : Node) -> VoxelChunk:
var chunk : VoxelChunk = CubicVoxelChunk.new()
generation_queue.append(chunk)
#chunk.lod_size = 1
return ._create_chunk(x, y, z, chunk)
func spawn() -> void:
var hsize : int = 4
var hsize : int = 5
# if gen_type == GenType.NORMAL:
for x 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, 1)
# spawn_chunk(x, y, z, 1)
create_chunk(x, y, z)
#func set_player(p_player : Spatial) -> void:
# 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://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"]
use_threads = false
max_concurrent_generations = 1
library = ExtResource( 2 )
voxel_scale = 2.0
player_path = NodePath("Camera")
level_generator = SubResource( 1 )
voxel_scale = 4.0
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)
func _create_mesher():
mesher = TVVoxelMesher.new()
func _create_meshers():
var mesher : TVVoxelMesher = TVVoxelMesher.new()
mesher.base_light_value = 0.45
mesher.ao_strength = 0.2
# var m : float = 1.0 / 16.0
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.max_atlas_size = 1024
_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)
func build_phase_prop_mesh() -> void:
mesher.reset()
for i in range(get_mesher_count()):
get_mesher(i).reset()
if get_prop_count() == 0:
next_phase()
@ -94,7 +97,9 @@ func build_phase_prop_mesh() -> void:
_prop_material.metallic = 0
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()):
var prop : VoxelChunkPropData = get_prop(i)
@ -117,17 +122,20 @@ func build_phase_prop_mesh() -> void:
if prop.mesh != null:
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:
var vmanpp : PropData = prop.prop as PropData
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)
mesher.build_mesh(get_prop_mesh_rid())
mesher.material = null
for i in range(get_mesher_count()):
get_mesher(i).bake_colors(self)
get_mesher(i).build_mesh(get_prop_mesh_rid())
get_mesher(i).material = null
if not _entities_spawned:
for i in range(get_prop_count()):

View File

@ -66,6 +66,9 @@ func _ready():
func _generation_finished():
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:
get_node("..").hide_loading_screen()

View File

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

View File

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