Some update with bulk map edition
parent
6ee6f222b1
commit
98e8290217
|
@ -47,16 +47,18 @@ func _physics_process(delta):
|
|||
|
||||
if Input.is_action_just_pressed("action1") and has_cube:
|
||||
var pos = hit.position
|
||||
_terrain.get_storage().set_voxel_v(0, pos)
|
||||
_terrain.make_voxel_dirty(pos)
|
||||
do_sphere(pos, 5, 0)
|
||||
#_terrain.get_storage().set_voxel_v(0, pos)
|
||||
#_terrain.make_voxel_dirty(pos)
|
||||
|
||||
elif Input.is_action_just_pressed("action2"):
|
||||
var pos = hit.prev_position
|
||||
if has_cube == false:
|
||||
pos = hit.position
|
||||
if can_place_voxel_at(pos):
|
||||
_terrain.get_storage().set_voxel_v(1, pos)
|
||||
_terrain.make_voxel_dirty(pos)
|
||||
do_sphere(pos, 4, 2)
|
||||
#_terrain.get_storage().set_voxel_v(2, pos)
|
||||
#_terrain.make_voxel_dirty(pos)
|
||||
print("Place voxel at ", pos)
|
||||
else:
|
||||
print("Can't place here!")
|
||||
|
@ -88,6 +90,19 @@ func _make_cursor():
|
|||
return mesh_instance
|
||||
|
||||
|
||||
func do_sphere(center, r, type):
|
||||
var storage = _terrain.get_storage()
|
||||
|
||||
for z in range(-r, r):
|
||||
for x in range(-r, r):
|
||||
for y in range(-r, r):
|
||||
var pos = Vector3(x, y, z)
|
||||
if pos.length() <= r:
|
||||
storage.set_voxel_v(type, center + pos, 0)
|
||||
|
||||
_terrain.make_area_dirty(AABB(center - Vector3(r,r,r), 2*Vector3(r,r,r)))
|
||||
|
||||
|
||||
static func _add_wireframe_cube(st, pos, step, color):
|
||||
|
||||
st.add_color(color)
|
||||
|
|
|
@ -63,7 +63,7 @@ subdivide_depth = 0
|
|||
[node name="CharacterAvatar" type="Spatial"]
|
||||
|
||||
script = ExtResource( 1 )
|
||||
speed = 5.0
|
||||
speed = 10.0
|
||||
gravity = 40.0
|
||||
jump_force = 8.0
|
||||
head = NodePath("Camera")
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
extends Spatial
|
||||
|
||||
const BoxPhysics = preload("res://box_physics.gd")
|
||||
|
||||
export var speed = 5.0
|
||||
export var gravity = 9.8
|
||||
export var jump_force = 5.0
|
||||
|
@ -14,6 +12,7 @@ export(NodePath) var terrain = null
|
|||
var _velocity = Vector3()
|
||||
var _grounded = false
|
||||
var _head = null
|
||||
var _box_mover = VoxelBoxMover.new()
|
||||
|
||||
|
||||
func _ready():
|
||||
|
@ -64,8 +63,12 @@ func _physics_process(delta):
|
|||
|
||||
var motion = _velocity * delta
|
||||
|
||||
motion = move_with_box_physics(motion)
|
||||
|
||||
if has_node(terrain):
|
||||
var aabb = AABB(Vector3(-0.4, -0.9, -0.4), Vector3(0.8, 1.8, 0.8))
|
||||
var terrain_node = get_node(terrain)
|
||||
motion = _box_mover.get_motion(get_translation(), motion, aabb, terrain_node)
|
||||
global_translate(motion)
|
||||
|
||||
assert(delta > 0)
|
||||
_velocity = motion / delta
|
||||
|
||||
|
@ -86,61 +89,4 @@ func _physics_process(delta):
|
|||
#get_node("debug").set_text("Grounded=" + str(_grounded))
|
||||
|
||||
|
||||
# TODO There is room for optimization, but I'll leave it like this for now, it doesn't cause any lag
|
||||
func move_with_box_physics(motion):
|
||||
#var debug3d = get_node("../Debug3D")
|
||||
|
||||
var pos = get_translation()
|
||||
var box = BoxPhysics.box_from_center_extents(pos, Vector3(0.4, 0.9, 0.4))
|
||||
|
||||
var expanded_box = BoxPhysics.expand_with_vector(box, motion)
|
||||
#debug3d.draw_wire_box(expanded_box, Color(0,1,0,1))
|
||||
|
||||
var potential_boxes = []
|
||||
|
||||
# Collect collisions with the terrain
|
||||
if has_node(terrain):
|
||||
var voxel_terrain = get_node(terrain)
|
||||
var voxels = voxel_terrain.get_storage()
|
||||
|
||||
var min_x = int(floor(expanded_box.position.x))
|
||||
var min_y = int(floor(expanded_box.position.y))
|
||||
var min_z = int(floor(expanded_box.position.z))
|
||||
|
||||
var max_x = int(ceil(expanded_box.end.x))
|
||||
var max_y = int(ceil(expanded_box.end.y))
|
||||
var max_z = int(ceil(expanded_box.end.z))
|
||||
|
||||
var x = min_x
|
||||
var y = min_y
|
||||
var z = min_z
|
||||
|
||||
while z < max_z:
|
||||
while y < max_y:
|
||||
while x < max_x:
|
||||
|
||||
var voxel_type = voxels.get_voxel(x,y,z, 0)
|
||||
if voxel_type != 0:
|
||||
var voxel_box = AABB(Vector3(x,y,z), Vector3(1,1,1))
|
||||
potential_boxes.append(voxel_box)
|
||||
#debug3d.draw_wire_box(voxel_box)
|
||||
|
||||
x += 1
|
||||
x = min_x
|
||||
y += 1
|
||||
y = min_y
|
||||
z += 1
|
||||
|
||||
motion = BoxPhysics.get_motion(box, motion, potential_boxes)
|
||||
# TODO If any Godot physics is used here, it will break box physics and you'll fall through the map!
|
||||
# TODO Latest KinematicBody fucks up my motion, no idea why. Changed to Spatial
|
||||
#move_and_slide(motion)
|
||||
global_translate(motion)
|
||||
return motion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[gd_scene load_steps=18 format=2]
|
||||
[gd_scene load_steps=20 format=2]
|
||||
|
||||
[ext_resource path="res://provider_heightmap.tres" type="VoxelProvider" id=1]
|
||||
[ext_resource path="res://noise_distorted.png" type="Image" id=1]
|
||||
[ext_resource path="res://terrain_material.tres" type="Material" id=2]
|
||||
[ext_resource path="res://terrain_marerial_transparent.tres" type="Material" id=3]
|
||||
[ext_resource path="res://voxel_map.gd" type="Script" id=4]
|
||||
|
@ -112,7 +112,13 @@ adjustment_contrast = 1.0
|
|||
adjustment_saturation = 1.0
|
||||
_sections_unfolded = [ "Ambient Light", "Background", "Fog", "Glow" ]
|
||||
|
||||
[sub_resource type="Voxel" id=3]
|
||||
[sub_resource type="VoxelProviderImage" id=3]
|
||||
|
||||
image = ExtResource( 1 )
|
||||
channel = 0
|
||||
_sections_unfolded = [ "image" ]
|
||||
|
||||
[sub_resource type="Voxel" id=4]
|
||||
|
||||
voxel_name = ""
|
||||
color = Color( 1, 1, 1, 1 )
|
||||
|
@ -120,7 +126,7 @@ transparent = true
|
|||
material_id = 0
|
||||
geometry_type = 0
|
||||
|
||||
[sub_resource type="Voxel" id=4]
|
||||
[sub_resource type="Voxel" id=5]
|
||||
|
||||
voxel_name = ""
|
||||
color = Color( 1, 1, 1, 1 )
|
||||
|
@ -128,20 +134,38 @@ transparent = false
|
|||
material_id = 0
|
||||
geometry_type = 1
|
||||
cube_geometry/padding_y = 0.0
|
||||
cube_tiles/left = null
|
||||
cube_tiles/right = null
|
||||
cube_tiles/bottom = null
|
||||
cube_tiles/top = null
|
||||
cube_tiles/back = null
|
||||
cube_tiles/front = null
|
||||
cube_tiles/left = Vector2( 0, 0 )
|
||||
cube_tiles/right = Vector2( 0, 0 )
|
||||
cube_tiles/bottom = Vector2( 0, 0 )
|
||||
cube_tiles/top = Vector2( 0, 0 )
|
||||
cube_tiles/back = Vector2( 0, 0 )
|
||||
cube_tiles/front = Vector2( 0, 0 )
|
||||
|
||||
[sub_resource type="VoxelLibrary" id=5]
|
||||
[sub_resource type="Voxel" id=6]
|
||||
|
||||
voxel_name = ""
|
||||
color = Color( 1, 1, 1, 1 )
|
||||
transparent = false
|
||||
material_id = 0
|
||||
geometry_type = 1
|
||||
cube_geometry/padding_y = 0.0
|
||||
cube_tiles/left = Vector2( 1, 0 )
|
||||
cube_tiles/right = Vector2( 1, 0 )
|
||||
cube_tiles/bottom = Vector2( 1, 0 )
|
||||
cube_tiles/top = Vector2( 1, 0 )
|
||||
cube_tiles/back = Vector2( 1, 0 )
|
||||
cube_tiles/front = Vector2( 1, 0 )
|
||||
_sections_unfolded = [ "cube_tiles" ]
|
||||
|
||||
[sub_resource type="VoxelLibrary" id=7]
|
||||
|
||||
atlas_size = 4
|
||||
voxels/0 = SubResource( 3 )
|
||||
voxels/1 = SubResource( 4 )
|
||||
voxels/0 = SubResource( 4 )
|
||||
voxels/1 = SubResource( 5 )
|
||||
voxels/2 = SubResource( 6 )
|
||||
_sections_unfolded = [ "voxels" ]
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=6]
|
||||
[sub_resource type="SpatialMaterial" id=8]
|
||||
|
||||
render_priority = 0
|
||||
flags_transparent = false
|
||||
|
@ -196,7 +220,7 @@ uv2_triplanar_sharpness = 1.0
|
|||
proximity_fade_enable = false
|
||||
distance_fade_mode = 0
|
||||
|
||||
[sub_resource type="SpatialMaterial" id=7]
|
||||
[sub_resource type="SpatialMaterial" id=9]
|
||||
|
||||
render_priority = 0
|
||||
flags_transparent = false
|
||||
|
@ -252,7 +276,7 @@ proximity_fade_enable = false
|
|||
distance_fade_mode = 0
|
||||
_sections_unfolded = [ "Emission", "Flags", "Vertex Color" ]
|
||||
|
||||
[sub_resource type="QuadMesh" id=8]
|
||||
[sub_resource type="QuadMesh" id=10]
|
||||
|
||||
custom_aabb = AABB( 0, 0, 0, 0, 0, 0 )
|
||||
flip_faces = false
|
||||
|
@ -264,8 +288,8 @@ size = Vector2( 1, 1 )
|
|||
environment = SubResource( 2 )
|
||||
|
||||
[node name="VoxelTerrain" type="VoxelTerrain" parent="."]
|
||||
provider = ExtResource( 1 )
|
||||
voxel_library = SubResource( 5 )
|
||||
provider = SubResource( 3 )
|
||||
voxel_library = SubResource( 7 )
|
||||
view_distance = 256
|
||||
viewer_path = NodePath("../CharacterAvatar")
|
||||
generate_collisions = true
|
||||
|
@ -278,11 +302,12 @@ material/5 = null
|
|||
material/6 = null
|
||||
material/7 = null
|
||||
script = ExtResource( 4 )
|
||||
_sections_unfolded = [ "provider" ]
|
||||
|
||||
[node name="Grid" type="MeshInstance" parent="."]
|
||||
visible = false
|
||||
layers = 1
|
||||
material_override = SubResource( 6 )
|
||||
material_override = SubResource( 8 )
|
||||
cast_shadow = 1
|
||||
extra_cull_margin = 0.0
|
||||
use_in_baked_light = false
|
||||
|
@ -351,7 +376,7 @@ script = ExtResource( 8 )
|
|||
|
||||
[node name="Debug3D" type="MeshInstance" parent="."]
|
||||
layers = 1
|
||||
material_override = SubResource( 7 )
|
||||
material_override = SubResource( 9 )
|
||||
cast_shadow = 1
|
||||
extra_cull_margin = 0.0
|
||||
use_in_baked_light = false
|
||||
|
@ -375,7 +400,7 @@ lod_min_distance = 0.0
|
|||
lod_min_hysteresis = 0.0
|
||||
lod_max_distance = 0.0
|
||||
lod_max_hysteresis = 0.0
|
||||
mesh = SubResource( 8 )
|
||||
mesh = SubResource( 10 )
|
||||
skeleton = NodePath("..")
|
||||
material/0 = null
|
||||
|
||||
|
|
|
@ -1,31 +1,13 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/noise_distorted.png-a3823ac1452b83d7bf69c4608544df15.stex"
|
||||
importer="image"
|
||||
type="Image"
|
||||
path="res://.import/noise_distorted.png-a3823ac1452b83d7bf69c4608544df15.image"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://noise_distorted.png"
|
||||
dest_files=[ "res://.import/noise_distorted.png-a3823ac1452b83d7bf69c4608544df15.stex" ]
|
||||
dest_files=[ "res://.import/noise_distorted.png-a3823ac1452b83d7bf69c4608544df15.image" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=true
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
||||
|
|
|
@ -1,35 +1,88 @@
|
|||
extends Label
|
||||
|
||||
|
||||
func _input(event):
|
||||
if event is InputEventKey and event.pressed == false:
|
||||
if event.scancode == KEY_F4:
|
||||
var terrain = get_parent().get_node("VoxelTerrain")
|
||||
if terrain.has_method("get_profiling_info") == false:
|
||||
return
|
||||
var terrain_infos = terrain.get_profiling_info()
|
||||
var mesher_infos = terrain.get_mesher().get_profiling_info()
|
||||
save_json(terrain_infos, "profiling_terrain.json")
|
||||
save_json(mesher_infos, "profiling_mesher.json")
|
||||
|
||||
|
||||
func save_json(infos, path):
|
||||
var f = File.new()
|
||||
var ret = f.open(path, File.WRITE)
|
||||
if ret == 0:
|
||||
f.store_string(to_json(infos))
|
||||
f.close()
|
||||
else:
|
||||
print("Could not dump profiling info (error " + str(ret) + ")")
|
||||
# Deferred because stats are reset everytime the terrain is processing,
|
||||
# so we make sure we get them always at the same point in time
|
||||
var _deferred_print_stats = false
|
||||
|
||||
|
||||
func _process(delta):
|
||||
var dm = OS.get_dynamic_memory_usage()
|
||||
var sm = OS.get_static_memory_usage()
|
||||
set_text(_format_memory(dm) + "\n" + _format_memory(sm))
|
||||
|
||||
var terrain = get_parent().get_node("VoxelTerrain")
|
||||
var stats = terrain.get_statistics()
|
||||
|
||||
var s = str("Dynamic memory: ", _format_memory(dm), \
|
||||
"\nStatic memory: ", _format_memory(sm), \
|
||||
"\nProvider: ", stats.provider.remaining_blocks, \
|
||||
"\nUpdater (thread): ", stats.updater.remaining_blocks, \
|
||||
"\nUpdater (main thread): ", stats.updater.remaining_main_thread_blocks)
|
||||
|
||||
set_text(s)
|
||||
|
||||
if stats.updater.mesh_alloc_time > 15:
|
||||
print("Mesh alloc time is ", stats.updater.mesh_alloc_time, " for ", stats.updater.updated_blocks)
|
||||
|
||||
if _deferred_print_stats:
|
||||
_deferred_print_stats = false
|
||||
|
||||
print(str("Time stats:", \
|
||||
"\t\n", "time_detect_required_blocks: ", stats.time_detect_required_blocks, " usec", \
|
||||
"\t\n", "time_send_load_requests: ", stats.time_send_load_requests, " usec", \
|
||||
"\t\n", "time_process_load_responses: ", stats.time_process_load_responses, " usec", \
|
||||
"\t\n", "time_send_update_requests: ", stats.time_send_update_requests, " usec", \
|
||||
"\t\n", "time_process_update_responses: ", stats.time_process_update_responses, " usec", \
|
||||
"\t\n"))
|
||||
|
||||
|
||||
func _format_memory(m):
|
||||
func _input(event):
|
||||
if event is InputEventKey:
|
||||
if event.pressed:
|
||||
if event.scancode == KEY_F4:
|
||||
_deferred_print_stats = true
|
||||
|
||||
|
||||
func _draw():
|
||||
if not Input.is_key_pressed(KEY_F3):
|
||||
return
|
||||
var terrain = get_parent().get_node("VoxelTerrain")
|
||||
var avatar = get_parent().get_node("CharacterAvatar")
|
||||
|
||||
var center_bpos = terrain.voxel_to_block(avatar.translation)
|
||||
var ry = 1
|
||||
var rx = 20
|
||||
var rz = 20
|
||||
|
||||
var gui_origin = Vector2(400, 100)
|
||||
var a = 0.3
|
||||
var w = 4
|
||||
|
||||
for y in range(-ry, ry):
|
||||
for z in range(-rz, rz):
|
||||
for x in range(-rx, rx):
|
||||
|
||||
var bpos = center_bpos + Vector3(x, y, z)
|
||||
var state = terrain.get_block_state(bpos)
|
||||
var col
|
||||
|
||||
match state:
|
||||
VoxelTerrain.BLOCK_NONE:
|
||||
col = Color(0, 0, 0, a)
|
||||
|
||||
VoxelTerrain.BLOCK_LOAD:
|
||||
col = Color(1, 0, 0, a)
|
||||
|
||||
VoxelTerrain.BLOCK_UPDATE_NOT_SENT, \
|
||||
VoxelTerrain.BLOCK_UPDATE_SENT:
|
||||
col = Color(1, 0.5, 0, a)
|
||||
|
||||
_:
|
||||
col = Color(1, 1, 1, a)
|
||||
|
||||
draw_rect(Rect2(gui_origin + Vector2(x, z) * w, Vector2(w, w)), col)
|
||||
|
||||
|
||||
static func _format_memory(m):
|
||||
var mb = m / 1000000
|
||||
var mbr = m % 1000000
|
||||
return str(mb) + "." + str(mbr) + " Mb"
|
||||
return str(mb, ".", mbr, " Mb")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
tool
|
||||
extends VoxelProvider
|
||||
|
||||
# IMPORTANT: This can run in a thread.
|
||||
# If you access it from outside, it's your job to make sure it's safe
|
||||
|
||||
class OsnNoise:
|
||||
var iamaproxy = null
|
||||
|
@ -10,7 +12,7 @@ class OsnFractalNoise:
|
|||
|
||||
var _noise = OsnNoise.new()
|
||||
var _noise2 = OsnNoise.new()
|
||||
var channel = Voxel.CHANNEL_TYPE
|
||||
var _channel = Voxel.CHANNEL_TYPE
|
||||
var _image = preload("res://noise_distorted.png")
|
||||
|
||||
|
||||
|
@ -51,7 +53,7 @@ func emerge_block_im(out_buffer, origin_in_voxels):
|
|||
if h > 0:
|
||||
if h > bs:
|
||||
h = bs
|
||||
out_buffer.fill_area(dirt, Vector3(x,0,z), Vector3(x+1,h,z+1), channel)
|
||||
out_buffer.fill_area(dirt, Vector3(x,0,z), Vector3(x+1,h,z+1), _channel)
|
||||
|
||||
x += 1
|
||||
z += 1
|
||||
|
|
|
@ -20,7 +20,7 @@ flags/repeat=true
|
|||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=0
|
||||
flags/srgb=1
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
|
|
|
@ -27,7 +27,7 @@ albedo_texture = ExtResource( 1 )
|
|||
metallic = 0.0
|
||||
metallic_specular = 0.0
|
||||
metallic_texture_channel = 0
|
||||
roughness = 0.0
|
||||
roughness = 1.0
|
||||
roughness_texture_channel = 0
|
||||
emission_enabled = false
|
||||
normal_enabled = false
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
extends VoxelTerrain
|
||||
|
||||
func _ready():
|
||||
pass
|
||||
# TODO Should be in editor
|
||||
var mesher = get_mesher()
|
||||
mesher.set_occlusion_enabled(true)
|
||||
mesher.set_occlusion_darkness(1.0)
|
||||
#var mesher = get_mesher()
|
||||
#mesher.set_occlusion_enabled(true)
|
||||
#mesher.set_occlusion_darkness(1.0)
|
||||
|
||||
|
|
Loading…
Reference in New Issue