Update (nature, engine changes)

This commit is contained in:
Segey Lapin
2021-11-22 01:09:02 +03:00
parent 8bb1c26ecd
commit 8a3b4987e8
94 changed files with 6919 additions and 51 deletions

View File

@@ -16,20 +16,22 @@ onready var male = preload("res://characters/vroid1-man.tscn")
onready var face_ctrl = preload("res://scenes/face/head_comtrol.tscn") onready var face_ctrl = preload("res://scenes/face/head_comtrol.tscn")
onready var modules = { onready var modules = {
# "physics": load("res://scripts/modules/character_physics.gd"), # "physics": load("res://scripts/modules/character_physics.gd"),
"cmdq": load("res://scripts/modules/cmdq.gd"), "cmdq": preload("res://scripts/modules/cmdq.gd"),
"marker": load("res://scripts/modules/npc_marker.gd"), "marker": preload("res://scripts/modules/npc_marker.gd"),
"sacrifice": load("res://scripts/modules/npc_sacrifice.gd"), "sacrifice": preload("res://scripts/modules/npc_sacrifice.gd"),
"nun": load("res://scripts/modules/npc_nun.gd"), "nun": preload("res://scripts/modules/npc_nun.gd"),
"player": load("res://scripts/modules/player_controls.gd"), "player": preload("res://scripts/modules/player_controls.gd"),
"player_clothes": load("res://scripts/modules/player_clothes.gd"), "player_clothes": preload("res://scripts/modules/player_clothes.gd"),
"hurtboxes": load("res://scripts/modules/character_hurtboxes.gd"), "hurtboxes": preload("res://scripts/modules/character_hurtboxes.gd"),
"student": load("res://scripts/modules/npc_student.gd") "student": preload("res://scripts/modules/npc_student.gd")
} }
var face_data_path = "res://scenes/face/" var face_data_path = "res://scenes/face/"
var hair_data_path = "res://scenes/hair/" var hair_data_path = "res://scenes/hair/"
var female_faces = [] var female_faces = []
var mesh_female_faces = {}
var male_faces = [] var male_faces = []
var mesh_male_faces = {}
var female_hairs = [] var female_hairs = []
var male_hairs = [] var male_hairs = []
var hair_materials = [] var hair_materials = []
@@ -56,8 +58,11 @@ func _ready():
match g: match g:
"female": "female":
female_faces.push_back(fp) female_faces.push_back(fp)
mesh_female_faces[fp] = load(fp)
"male": "male":
male_faces.push_back(fp) male_faces.push_back(fp)
mesh_male_faces[fp] = load(fp)
for id in range(10000): for id in range(10000):
var fp_m = face_data_path + "male-face" + str(id) + ".tscn" var fp_m = face_data_path + "male-face" + str(id) + ".tscn"
var fp_f = face_data_path + "female-face" + str(id) + ".tscn" var fp_f = face_data_path + "female-face" + str(id) + ".tscn"
@@ -66,8 +71,10 @@ func _ready():
var mat = hair_data_path + "hair" + str(id) + ".tres" var mat = hair_data_path + "hair" + str(id) + ".tres"
if data_fd.file_exists(fp_m): if data_fd.file_exists(fp_m):
male_faces.push_back(fp_m) male_faces.push_back(fp_m)
mesh_male_faces[fp_m] = load(fp_m)
if data_fd.file_exists(fp_f): if data_fd.file_exists(fp_f):
female_faces.push_back(fp_f) female_faces.push_back(fp_f)
mesh_female_faces[fp_f] = load(fp_f)
if data_fd.file_exists(hp_m): if data_fd.file_exists(hp_m):
male_hairs.push_back(hp_m) male_hairs.push_back(hp_m)
if data_fd.file_exists(hp_f): if data_fd.file_exists(hp_f):
@@ -153,7 +160,7 @@ func compose_kinematic_character(g, enable_modules = [], face = -1, hair = -1, h
face = rnd.randi() % female_faces.size() face = rnd.randi() % female_faces.size()
if hair == -1: if hair == -1:
hair = rnd.randi() % female_hairs.size() hair = rnd.randi() % female_hairs.size()
face_scene = load(female_faces[face]) face_scene = mesh_female_faces[female_faces[face]]
hair_scene = load(female_hairs[hair]) hair_scene = load(female_hairs[hair])
capsule.radius = 0.2 capsule.radius = 0.2
capsule.height = 1.1 capsule.height = 1.1
@@ -172,7 +179,7 @@ func compose_kinematic_character(g, enable_modules = [], face = -1, hair = -1, h
face = rnd.randi() % male_faces.size() face = rnd.randi() % male_faces.size()
if hair == -1: if hair == -1:
hair = rnd.randi() % male_hairs.size() hair = rnd.randi() % male_hairs.size()
face_scene = load(male_faces[face]) face_scene = mesh_male_faces[male_faces[face]]
hair_scene = load(male_hairs[hair]) hair_scene = load(male_hairs[hair])
capsule.radius = 0.3 capsule.radius = 0.3
capsule.height = 1.2 capsule.height = 1.2

View File

@@ -80,6 +80,8 @@ func setup_town(site):
center += p center += p
center /= poly.size() center /= poly.size()
center.y = height center.y = height
var infl = RoadsData.get_influence_cached(center.x, center.y, 256)
center.y = infl.y
var radial_points = RoadsData.get_site_radial_points(site, 32.0, 64.0) var radial_points = RoadsData.get_site_radial_points(site, 32.0, 64.0)
var max_r = 0.0 var max_r = 0.0
for p in range(radial_points.size()): for p in range(radial_points.size()):
@@ -89,18 +91,26 @@ func setup_town(site):
max_r = dst max_r = dst
for p in range(radial_points.size()): for p in range(radial_points.size()):
var ep = radial_points[p] var ep = radial_points[p]
var miff = RoadsData.get_influence_cached(ep.x, ep.z, 256.0)
ep.y = center.y
var d = (center - ep).normalized() var d = (center - ep).normalized()
assert(d.length_squared() > 0) assert(d.length_squared() > 0)
var dst = ep.distance_to(center) var dst = ep.distance_to(center)
print(dst) print(dst)
if dst < 64.0 + 12 + 8 + 4: if dst < 64.0 + 12 + 8 + 4:
continue continue
var step = 16.0 var step = 32.0
var pstart = ep var pstart = ep + d * 32.0
dst -= 32.0
while dst > 0.0: while dst > 0.0:
var ok = true var ok = true
if !Geometry.is_point_in_polygon(Vector2(pstart.x, pstart.z), poly2): miff = RoadsData.get_influence_cached(pstart.x, pstart.z, 256.0)
if miff.x > 0.0:
ok = false ok = false
if ok:
pstart.y = miff.y
if !Geometry.is_point_in_polygon(Vector2(pstart.x, pstart.z), poly2):
ok = false
if ok: if ok:
for b in aabbs: for b in aabbs:
if b.has_point(pstart): if b.has_point(pstart):
@@ -133,7 +143,9 @@ func setup_first_town():
center += p center += p
center /= poly.size() center /= poly.size()
center.y = height center.y = height
# grid.build(border2, center) var infl = RoadsData.get_influence_cached(center.x, center.z, 256)
center.y = infl.y
print("first town center: ", center)
var radial_points = RoadsData.get_site_radial_points(0, 32.0, 64.0) var radial_points = RoadsData.get_site_radial_points(0, 32.0, 64.0)
var max_r = 0.0 var max_r = 0.0
for p in range(radial_points.size()): for p in range(radial_points.size()):
@@ -161,18 +173,26 @@ func setup_first_town():
for p in range(radial_points.size()): for p in range(radial_points.size()):
var ep = radial_points[p] var ep = radial_points[p]
var miff = RoadsData.get_influence_cached(ep.x, ep.z, 256.0)
ep.y = center.y
var d = (center - ep).normalized() var d = (center - ep).normalized()
assert(d.length_squared() > 0) assert(d.length_squared() > 0)
var dst = ep.distance_to(center) var dst = ep.distance_to(center)
print(dst) print(dst)
if dst < 64.0 + 12 + 8 + 4: if dst < 64.0 + 12 + 8 + 4:
continue continue
var step = 16.0 var step = 32.0
var pstart = ep var pstart = ep + d * 32.0
dst -= 32.0
while dst > 0.0: while dst > 0.0:
var ok = true var ok = true
if !Geometry.is_point_in_polygon(Vector2(pstart.x, pstart.z), poly2): miff = RoadsData.get_influence_cached(pstart.x, pstart.z, 256.0)
if miff.x > 0.0:
ok = false ok = false
if ok:
pstart.y = miff.y
if !Geometry.is_point_in_polygon(Vector2(pstart.x, pstart.z), poly2):
ok = false
if ok: if ok:
for b in aabbs: for b in aabbs:
if b.has_point(pstart): if b.has_point(pstart):

View File

@@ -0,0 +1,54 @@
extends Reference
static func build_house(main_xform: Transform):
var rnd = streaming.get_place_rnd(main_xform)
print(main_xform.origin, " seed = ", rnd.state)
var l = 5 + 2 * (rnd.randi() % 5) - 1
var h = l - 1
var d = 3 + rnd.randi() % (l - 4 + 1)
var range_used = false
var objects = []
for k in range(l + 1):
var pos = Vector3(0, 0, k * 2)
var xform = Transform(Basis(), pos)
if k > 0:
var what
if k != d && rnd.randf() > 0.5 && !range_used:
what = "roof_floor_range"
range_used = true
else:
what = "roof_floor"
objects.push_back({"xform": xform, "data": [what]})
var xt = [Transform(Basis(), pos), Transform(Basis().rotated(Vector3.UP, PI), pos - Vector3(0, 0, 2))]
for x in range(xt.size()):
if x == 0 && k == d:
continue
if rnd.randf() > 0.5:
what = "wall_solid"
elif rnd.randf() > 0.5:
what = "window_narrow"
else:
what = "window_wide"
objects.push_back({"xform": xt[x], "data": [what]})
var obj_data = []
if k > 1 && k < l && rnd.randf() > 0.6:
objects.push_back({"xform": xform, "data": ["wall_internal"]})
match k:
0:
obj_data = ["side_wall", "bottom_side"]
1:
obj_data = ["bottom"]
2:
obj_data = ["bottom_wheels"]
d:
obj_data = ["entry", "bottom"]
h:
obj_data = ["bottom_wheels"]
l:
obj_data = ["side_wall_rotated", "bottom_side_rotated", "bottom"]
_:
obj_data = ["bottom"]
objects.push_back({"xform": xform, "data": obj_data})
return objects

8
bush.tscn Normal file
View File

@@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://terrain-objects/terrain-bushes_p1_l0.mesh" type="ArrayMesh" id=1]
[node name="bush" type="StaticBody"]
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = ExtResource( 1 )

View File

@@ -74,6 +74,7 @@ func _ready():
car.add_to_group("keep") car.add_to_group("keep")
car.add_to_group("car") car.add_to_group("car")
add_child(car) add_child(car)
car.global_transform.origin = Vector3(-3, 0, -3)
for e in range(5): for e in range(5):
var major_f = Spatial.new() var major_f = Spatial.new()
major_f.add_to_group("spawn") major_f.add_to_group("spawn")

View File

@@ -1,21 +1,8 @@
extends Spatial extends Spatial
onready var rnd = RandomNumberGenerator.new()
var spawn = []
func _ready():
pass
func spawn_child(n: String, xform: Transform) -> void:
var x = xform
if n.ends_with("_rotated"):
x.basis = x.basis.rotated(Vector3(0, 1, 0), PI)
n = n.replace("_rotated", "")
streaming.spawn_child(n, global_transform * x)
static func build_house(main_xform: Transform): static func build_house(main_xform: Transform):
var rnd = RandomNumberGenerator.new() var rnd = streaming.get_place_rnd(main_xform)
var s = int(main_xform.origin.x + 100 * main_xform.origin.z * 2) % 0x1ffffff print(main_xform.origin, " seed = ", rnd.state)
rnd.seed = s
print(main_xform.origin, " seed = ", s)
var l = 6 + 2 * rnd.randi() % 7 - 1 var l = 6 + 2 * rnd.randi() % 7 - 1
var h = l - 1 var h = l - 1
var d = 3 + rnd.randi() % (l - 5 + 1) var d = 3 + rnd.randi() % (l - 5 + 1)
@@ -73,10 +60,7 @@ func _process(delta):
state = 1 state = 1
1: 1:
var objects = build_house(global_transform) var objects = build_house(global_transform)
for obj in objects: streaming.spawn_house_objects(global_transform, objects)
var x = obj.xform
for w in obj.data:
call_deferred("spawn_child", w, x)
state = 2 state = 2
2: 2:
set_process(false) set_process(false)

View File

@@ -84,4 +84,9 @@ fps_mode={
quality/driver/fallback_to_gles2=true quality/driver/fallback_to_gles2=true
quality/spatial_partitioning/render_tree_balance=0.22 quality/spatial_partitioning/render_tree_balance=0.22
batching/options/use_batching=false
[voxel]
threads/count/minimum=2
threads/count/margin_below_max=2
threads/main/time_budget_ms=1.0

View File

@@ -102,7 +102,10 @@ func _physics_process(delta):
vehicle.steering = -xmotion.x * 0.7 vehicle.steering = -xmotion.x * 0.7
else: else:
vehicle.brake = 0 vehicle.brake = 0
vehicle.engine_force = 4000 * xmotion.y if vehicle.linear_velocity.length() < 16.6:
vehicle.engine_force = 4000 * xmotion.y
else:
vehicle.engine_force = 500 * xmotion.y
var accel = vehicle.angular_velocity * 350.0 * delta var accel = vehicle.angular_velocity * 350.0 * delta
vehicle.steering = -xmotion.x * 0.7 vehicle.steering = -xmotion.x * 0.7

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,560 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.5.17",
"version" : "2.0"
},
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
0,
1,
2,
3,
4
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "p1_l0",
"translation" : [
-2.9100000858306885,
0,
-3.072000026702881
]
},
{
"mesh" : 1,
"name" : "p2_l0",
"translation" : [
-2,
0,
-3.072000026702881
]
},
{
"mesh" : 2,
"name" : "p3_l0",
"translation" : [
-1.0899999141693115,
0,
-3.072000026702881
]
},
{
"mesh" : 3,
"name" : "p4_l0",
"translation" : [
-2.9100000858306885,
0,
-4.8919997215271
]
},
{
"mesh" : 4,
"name" : "p5_l0",
"translation" : [
-1.0899999141693115,
0,
-4.8919997215271
]
}
],
"materials" : [
{
"doubleSided" : true,
"name" : "Green.004",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.06995400041341782,
0.12185700237751007,
0.047887999564409256,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Wood",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.12234099954366684,
0.05628800019621849,
0.04760900139808655,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Leaves",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.12185700237751007,
0.09563499689102173,
0.07339099794626236,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "DarkGreen",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.042527999728918076,
0.07266899943351746,
0.02957800030708313,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Green.005",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.06995400041341782,
0.12185700237751007,
0.047887999564409256,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Yellow.001",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.358379989862442,
0.2837910056114197,
0.0901150032877922,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
},
{
"doubleSided" : true,
"name" : "Pink",
"pbrMetallicRoughness" : {
"baseColorFactor" : [
0.373759001493454,
0.09044600278139114,
0.22160300612449646,
1
],
"metallicFactor" : 0,
"roughnessFactor" : 0.6732679605484009
}
}
],
"meshes" : [
{
"name" : "p1_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1
},
"indices" : 2,
"material" : 0
}
]
},
{
"name" : "p2_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 3,
"NORMAL" : 4
},
"indices" : 5,
"material" : 1
},
{
"attributes" : {
"POSITION" : 6,
"NORMAL" : 7
},
"indices" : 8,
"material" : 2
}
]
},
{
"name" : "p3_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 9,
"NORMAL" : 10
},
"indices" : 11,
"material" : 3
}
]
},
{
"name" : "p4_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 12,
"NORMAL" : 13
},
"indices" : 14,
"material" : 4
}
]
},
{
"name" : "p5_l0",
"primitives" : [
{
"attributes" : {
"POSITION" : 15,
"NORMAL" : 16
},
"indices" : 17,
"material" : 5
},
{
"attributes" : {
"POSITION" : 18,
"NORMAL" : 19
},
"indices" : 20,
"material" : 6
}
]
}
],
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5126,
"count" : 624,
"max" : [
0.5527048110961914,
0.4361256957054138,
0.5199175477027893
],
"min" : [
-0.540502667427063,
-0.025527318939566612,
-0.34054291248321533
],
"type" : "VEC3"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 624,
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5123,
"count" : 888,
"type" : "SCALAR"
},
{
"bufferView" : 3,
"componentType" : 5126,
"count" : 80,
"max" : [
0.018657727167010307,
1.6145683526992798,
0.04910542815923691
],
"min" : [
-0.03639454022049904,
-0.00018746100249700248,
-0.020252957940101624
],
"type" : "VEC3"
},
{
"bufferView" : 4,
"componentType" : 5126,
"count" : 80,
"type" : "VEC3"
},
{
"bufferView" : 5,
"componentType" : 5123,
"count" : 114,
"type" : "SCALAR"
},
{
"bufferView" : 6,
"componentType" : 5126,
"count" : 420,
"max" : [
0.2818242609500885,
1.4256141185760498,
0.3100934326648712
],
"min" : [
-0.3423629105091095,
0.26863014698028564,
-0.3140755295753479
],
"type" : "VEC3"
},
{
"bufferView" : 7,
"componentType" : 5126,
"count" : 420,
"type" : "VEC3"
},
{
"bufferView" : 8,
"componentType" : 5123,
"count" : 540,
"type" : "SCALAR"
},
{
"bufferView" : 9,
"componentType" : 5126,
"count" : 1134,
"max" : [
0.45378240942955017,
0.8412840366363525,
0.4951355457305908
],
"min" : [
-0.5378227233886719,
-0.017499301582574844,
-0.3897447884082794
],
"type" : "VEC3"
},
{
"bufferView" : 10,
"componentType" : 5126,
"count" : 1134,
"type" : "VEC3"
},
{
"bufferView" : 11,
"componentType" : 5123,
"count" : 1800,
"type" : "SCALAR"
},
{
"bufferView" : 12,
"componentType" : 5126,
"count" : 932,
"max" : [
0.7841669917106628,
0.7323634624481201,
0.8904631733894348
],
"min" : [
-0.9583673477172852,
-0.005544625222682953,
-1.0364927053451538
],
"type" : "VEC3"
},
{
"bufferView" : 13,
"componentType" : 5126,
"count" : 932,
"type" : "VEC3"
},
{
"bufferView" : 14,
"componentType" : 5123,
"count" : 1536,
"type" : "SCALAR"
},
{
"bufferView" : 15,
"componentType" : 5126,
"count" : 1196,
"max" : [
0.7932196855545044,
0.8964381814002991,
0.7817763686180115
],
"min" : [
-0.7932196855545044,
-0.02066883072257042,
-0.7817763686180115
],
"type" : "VEC3"
},
{
"bufferView" : 16,
"componentType" : 5126,
"count" : 1196,
"type" : "VEC3"
},
{
"bufferView" : 17,
"componentType" : 5123,
"count" : 1806,
"type" : "SCALAR"
},
{
"bufferView" : 18,
"componentType" : 5126,
"count" : 36,
"max" : [
0.05127303674817085,
1.2399932146072388,
0.05427424982190132
],
"min" : [
-0.05127303674817085,
0.5572494268417358,
-0.05427418276667595
],
"type" : "VEC3"
},
{
"bufferView" : 19,
"componentType" : 5126,
"count" : 36,
"type" : "VEC3"
},
{
"bufferView" : 20,
"componentType" : 5123,
"count" : 54,
"type" : "SCALAR"
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 7488,
"byteOffset" : 0
},
{
"buffer" : 0,
"byteLength" : 7488,
"byteOffset" : 7488
},
{
"buffer" : 0,
"byteLength" : 1776,
"byteOffset" : 14976
},
{
"buffer" : 0,
"byteLength" : 960,
"byteOffset" : 16752
},
{
"buffer" : 0,
"byteLength" : 960,
"byteOffset" : 17712
},
{
"buffer" : 0,
"byteLength" : 228,
"byteOffset" : 18672
},
{
"buffer" : 0,
"byteLength" : 5040,
"byteOffset" : 18900
},
{
"buffer" : 0,
"byteLength" : 5040,
"byteOffset" : 23940
},
{
"buffer" : 0,
"byteLength" : 1080,
"byteOffset" : 28980
},
{
"buffer" : 0,
"byteLength" : 13608,
"byteOffset" : 30060
},
{
"buffer" : 0,
"byteLength" : 13608,
"byteOffset" : 43668
},
{
"buffer" : 0,
"byteLength" : 3600,
"byteOffset" : 57276
},
{
"buffer" : 0,
"byteLength" : 11184,
"byteOffset" : 60876
},
{
"buffer" : 0,
"byteLength" : 11184,
"byteOffset" : 72060
},
{
"buffer" : 0,
"byteLength" : 3072,
"byteOffset" : 83244
},
{
"buffer" : 0,
"byteLength" : 14352,
"byteOffset" : 86316
},
{
"buffer" : 0,
"byteLength" : 14352,
"byteOffset" : 100668
},
{
"buffer" : 0,
"byteLength" : 3612,
"byteOffset" : 115020
},
{
"buffer" : 0,
"byteLength" : 432,
"byteOffset" : 118632
},
{
"buffer" : 0,
"byteLength" : 432,
"byteOffset" : 119064
},
{
"buffer" : 0,
"byteLength" : 108,
"byteOffset" : 119496
}
],
"buffers" : [
{
"byteLength" : 119604,
"uri" : "terrain-bushes.bin"
}
]
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,7 +1,49 @@
shader_type spatial; shader_type spatial;
uniform sampler2D u_texture_top : hint_albedo;
uniform sampler2D u_texture_sides : hint_albedo;
// Bitmask telling which of the 6 faces of the block are bordered by a block of lower resolution // Bitmask telling which of the 6 faces of the block are bordered by a block of lower resolution
uniform int u_transition_mask; uniform int u_transition_mask;
// We'll need to pass data from the vertex shader to the fragment shader
varying vec3 v_world_pos;
varying vec3 v_world_normal;
varying vec4 v_weights;
varying vec4 v_indices;
// We'll use a utility function to decode components.
// It returns 4 values in the range [0..255].
vec4 decode_8bit_vec4(float v) {
uint i = floatBitsToUint(v);
return vec4(
float(i & uint(0xff)),
float((i >> uint(8)) & uint(0xff)),
float((i >> uint(16)) & uint(0xff)),
float((i >> uint(24)) & uint(0xff)));
}
// A voxel mesh can have overhangs in any direction,
// so we may have to use triplanar mapping functions.
vec3 get_triplanar_blend(vec3 world_normal) {
vec3 blending = abs(world_normal);
blending = normalize(max(blending, vec3(0.00001))); // Force weights to sum to 1.0
float b = blending.x + blending.y + blending.z;
return blending / vec3(b, b, b);
}
vec4 texture_triplanar(sampler2D tex, vec3 world_pos, vec3 blend) {
vec4 xaxis = texture(tex, world_pos.yz);
vec4 yaxis = texture(tex, world_pos.xz);
vec4 zaxis = texture(tex, world_pos.xy);
// blend the results of the 3 planar projections.
return xaxis * blend.x + yaxis * blend.y + zaxis * blend.z;
}
float get_hash(vec2 c) {
return fract(sin(dot(c.xy, vec2(12.9898,78.233))) * 43758.5453);
}
vec3 get_transvoxel_position(vec3 vertex_pos, vec4 vertex_col) { vec3 get_transvoxel_position(vec3 vertex_pos, vec4 vertex_col) {
int border_mask = int(vertex_col.a); int border_mask = int(vertex_col.a);
@@ -23,9 +65,42 @@ vec3 get_transvoxel_position(vec3 vertex_pos, vec4 vertex_col) {
} }
void vertex() { void vertex() {
VERTEX = get_transvoxel_position(VERTEX, COLOR); // Indices are integer values so we can decode them as-is
v_indices = decode_8bit_vec4(UV.x);
// Weights must be in [0..1] so we divide them
v_weights = decode_8bit_vec4(UV.y) / 255.0;
//v_normal = NORMAL;
vec3 world_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0)).xyz;
v_world_pos = world_pos;
v_world_normal = NORMAL;
VERTEX = get_transvoxel_position(VERTEX, COLOR);
} }
void fragment() { void fragment() {
ALBEDO = vec3(1, 1, 0); vec3 normal = v_world_normal;//normalize(v_world_normal);
vec3 wpos = v_world_pos * 0.2;
// Sample the 4 blending textures, all with triplanar mapping.
// We can re-use the same triplanar blending factors for all of them so separating that part
// of the function improves performance a little.
vec3 blending = get_triplanar_blend(v_world_normal);
vec3 top_col = texture_triplanar(u_texture_top, wpos, blending).rgb;
vec3 side_col = texture_triplanar(u_texture_sides, wpos, blending).rgb;
// Get weights and make sure they are normalized.
// We may add a tiny safety margin so we can afford some degree of error.
vec4 weights = v_weights;
weights /= (weights.x + weights.y + weights.z + weights.w + 0.00001);
// Calculate albedo
//vec3 col =
// col0 * weights.r +
// col1 * weights.g +
// col2 * weights.b +
// col3 * weights.a;
float r = top_col.r;
ALBEDO = mix(side_col, top_col, clamp(normal.y * 10.0 - 4.0 - 8.0*r, 0.0, 1.0));
} }

31
tree.tscn Normal file
View File

@@ -0,0 +1,31 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://terrain-objects/terrain-trees_t1_l0.mesh" type="ArrayMesh" id=1]
[sub_resource type="CylinderShape" id=1]
radius = 0.3
height = 2.25014
[sub_resource type="SphereShape" id=2]
radius = 1.4
[node name="tree" type="StaticBody"]
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 0.995445, -0.0953419, 0, 0.0953419, 0.995445, 0, 1.0768, 0 )
shape = SubResource( 1 )
[node name="CollisionShape2" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.59792, 1.42922 )
shape = SubResource( 2 )
[node name="CollisionShape3" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.74276, -1.29866 )
shape = SubResource( 2 )
[node name="CollisionShape4" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0707073, 2.96499, 0.0801156 )
shape = SubResource( 2 )

View File

@@ -23,11 +23,14 @@ func _ready():
characters.set_navmesh(null, Transform()) characters.set_navmesh(null, Transform())
var start_delay0 = 2.0 var start_delay0 = 2.0
var start_delay1 = 3.0 var start_delay1 = 3.0
var start_delay2 = 9.0 var start_delay2 = 30.0
var start_delay3 = 2.0 var start_delay3 = 2.0
var state = 0 var state = 0
var viewer var viewer
var player_place_intended
var player_place_fact
func _process(delta): func _process(delta):
match state: match state:
0: 0:
@@ -44,13 +47,21 @@ func _process(delta):
else: else:
streaming.setup_town(site) streaming.setup_town(site)
streaming.setup_traffic(site) streaming.setup_traffic(site)
if (streaming.towns > 2):
break
print("towns done: ", streaming.towns) print("towns done: ", streaming.towns)
var v = RoadsData.get_site_pos(0) var poly = RoadsData.get_site_polygon_3d(0)
var sdf = RoadsData.get_sdf(v.x, 300, v.y) var center = Vector3()
var d = 300 - sdf for p in poly:
center += p
center /= poly.size()
var infl = RoadsData.get_influence_cached(center.x, center.z, 256)
center.y = infl.y
var v = center
$player.global_transform.origin.x = v.x $player.global_transform.origin.x = v.x
$player.global_transform.origin.y = d + 12 $player.global_transform.origin.y = v.y + 1.0
$player.global_transform.origin.z = v.y $player.global_transform.origin.z = v.z
player_place_intended = $player.global_transform.origin
viewer = VoxelViewer.new() viewer = VoxelViewer.new()
$player.add_child(viewer) $player.add_child(viewer)
state = 2 state = 2
@@ -107,12 +118,14 @@ func _process(delta):
print(player) print(player)
controls.switch_fps_mode(false) controls.switch_fps_mode(false)
print("configured player") print("configured player")
player_place_fact = player.global_transform.origin
state = 3 state = 3
3: 3:
start_delay3 -= delta start_delay3 -= delta
if start_delay3 < 0: if start_delay3 < 0:
$waiting.hide() $waiting.hide()
print("starting game") print("starting game")
print("intended: ", player_place_intended, " fact: ", player_place_fact)
state = 4 state = 4
4: 4:
RoadsData.save_json("user://world-gen.json") RoadsData.save_json("user://world-gen.json")

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=2] [gd_scene load_steps=71 format=2]
[ext_resource path="res://world.gd" type="Script" id=1] [ext_resource path="res://world.gd" type="Script" id=1]
[ext_resource path="res://terrain.gdshader" type="Shader" id=2] [ext_resource path="res://terrain.gdshader" type="Shader" id=2]
@@ -6,17 +6,220 @@
[ext_resource path="res://camera/camera_pos.tscn" type="PackedScene" id=4] [ext_resource path="res://camera/camera_pos.tscn" type="PackedScene" id=4]
[ext_resource path="res://scenes/waiting.gd" type="Script" id=5] [ext_resource path="res://scenes/waiting.gd" type="Script" id=5]
[ext_resource path="res://camera/fps_cam_pos.tscn" type="PackedScene" id=6] [ext_resource path="res://camera/fps_cam_pos.tscn" type="PackedScene" id=6]
[ext_resource path="res://terrain-objects/terrain-trees_t1_l0.mesh" type="ArrayMesh" id=7]
[ext_resource path="res://terrain-objects/terrain-trees_t1_l1.mesh" type="ArrayMesh" id=8]
[ext_resource path="res://terrain-objects/terrain-trees_t1_l3.mesh" type="ArrayMesh" id=9]
[ext_resource path="res://terrain-objects/terrain-trees_t2_l1.mesh" type="ArrayMesh" id=10]
[ext_resource path="res://terrain-objects/terrain-trees_t2_l0.mesh" type="ArrayMesh" id=11]
[ext_resource path="res://terrain-objects/terrain-trees_t3_l0.mesh" type="ArrayMesh" id=12]
[ext_resource path="res://terrain-objects/terrain-trees_t3_l1.mesh" type="ArrayMesh" id=13]
[ext_resource path="res://terrain-objects/terrain-trees_t3_l3.mesh" type="ArrayMesh" id=14]
[ext_resource path="res://terrain-objects/terrain-bushes_p1_l0.mesh" type="ArrayMesh" id=15]
[ext_resource path="res://terrain-objects/terrain-bushes_p2_l0.mesh" type="ArrayMesh" id=16]
[ext_resource path="res://terrain-objects/terrain-bushes_p3_l0.mesh" type="ArrayMesh" id=17]
[ext_resource path="res://terrain-objects/terrain-bushes_p4_l0.mesh" type="ArrayMesh" id=18]
[ext_resource path="res://terrain-objects/terrain-bushes_p5_l0.mesh" type="ArrayMesh" id=19]
[ext_resource path="res://terrain-objects/terrain-grass_f1_l0.mesh" type="ArrayMesh" id=20]
[ext_resource path="res://terrain-objects/terrain-grass_f1_l1.mesh" type="ArrayMesh" id=21]
[ext_resource path="res://terrain-objects/terrain-grass_g1_l1.mesh" type="ArrayMesh" id=22]
[ext_resource path="res://terrain-objects/terrain-grass_g1_l0.mesh" type="ArrayMesh" id=23]
[ext_resource path="res://terrain-objects/terrain-grass_g1_l2.mesh" type="ArrayMesh" id=24]
[ext_resource path="res://terrain-objects/terrain-grass_g2_l1.mesh" type="ArrayMesh" id=25]
[ext_resource path="res://terrain-objects/terrain-grass_g2_l0.mesh" type="ArrayMesh" id=26]
[ext_resource path="res://terrain-objects/terrain-grass_g2_l2.mesh" type="ArrayMesh" id=27]
[ext_resource path="res://terrain-objects/terrain-grass_g3_l1.mesh" type="ArrayMesh" id=28]
[ext_resource path="res://terrain-objects/terrain-grass_g3_l0.mesh" type="ArrayMesh" id=29]
[sub_resource type="WorldGenerator" id=7] [sub_resource type="WorldGenerator" id=7]
iso_scale = 0.01 iso_scale = 0.01
[sub_resource type="VoxelMesherTransvoxel" id=4] [sub_resource type="VoxelMesherTransvoxel" id=4]
[sub_resource type="Gradient" id=12]
colors = PoolColorArray( 0.27451, 0.27451, 0.27451, 1, 0.541176, 0.541176, 0.541176, 1 )
[sub_resource type="GradientTexture" id=13]
gradient = SubResource( 12 )
width = 64
[sub_resource type="Gradient" id=10]
offsets = PoolRealArray( 0, 0.473458 )
colors = PoolColorArray( 0.101961, 0.0588235, 0.0588235, 1, 0.188235, 0.109804, 0.109804, 1 )
[sub_resource type="GradientTexture" id=11]
gradient = SubResource( 10 )
width = 64
[sub_resource type="ShaderMaterial" id=6] [sub_resource type="ShaderMaterial" id=6]
shader = ExtResource( 2 ) shader = ExtResource( 2 )
shader_param/u_transition_mask = null shader_param/u_transition_mask = null
shader_param/u_texture_top = SubResource( 11 )
shader_param/u_texture_sides = SubResource( 13 )
[sub_resource type="Curve" id=1] [sub_resource type="CylinderShape" id=1]
radius = 0.3
height = 2.25014
[sub_resource type="SphereShape" id=2]
radius = 1.4
[sub_resource type="TreeInstanceGenerator" id=19]
step = 8
[sub_resource type="VoxelInstanceLibraryItem" id=17]
name = "tree1"
lod_index = 2
generator = SubResource( 19 )
mesh = ExtResource( 7 )
mesh_lod1 = ExtResource( 8 )
mesh_lod2 = ExtResource( 8 )
mesh_lod3 = ExtResource( 9 )
collision_shapes = [ SubResource( 1 ), Transform( 1, 0, 0, 0, 0.995445, -0.0953419, 0, 0.0953419, 0.995445, 0, 1.0768, 0 ), SubResource( 2 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.59792, 1.42922 ), SubResource( 2 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.74276, -1.29866 ), SubResource( 2 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0707073, 2.96499, 0.0801156 ) ]
[sub_resource type="TreeInstanceGenerator" id=43]
step = 1
[sub_resource type="VoxelInstanceLibraryItem" id=44]
name = "grass1"
generator = SubResource( 43 )
mesh = ExtResource( 23 )
mesh_lod1 = ExtResource( 22 )
mesh_lod2 = ExtResource( 24 )
[sub_resource type="TreeInstanceGenerator" id=45]
item = 1
[sub_resource type="VoxelInstanceLibraryItem" id=46]
name = "grass2"
generator = SubResource( 45 )
mesh = ExtResource( 26 )
mesh_lod1 = ExtResource( 25 )
mesh_lod2 = ExtResource( 27 )
[sub_resource type="TreeInstanceGenerator" id=47]
step = 1
[sub_resource type="VoxelInstanceLibraryItem" id=48]
name = "grass3"
generator = SubResource( 47 )
mesh = ExtResource( 29 )
mesh_lod1 = ExtResource( 28 )
[sub_resource type="CylinderShape" id=21]
radius = 0.3
height = 2.25014
[sub_resource type="SphereShape" id=22]
radius = 1.4
[sub_resource type="TreeInstanceGenerator" id=25]
step = 8
item = 4
[sub_resource type="VoxelInstanceLibraryItem" id=24]
name = "tree2"
lod_index = 2
generator = SubResource( 25 )
mesh = ExtResource( 11 )
mesh_lod1 = ExtResource( 10 )
mesh_lod2 = ExtResource( 10 )
mesh_lod3 = ExtResource( 10 )
collision_shapes = [ SubResource( 21 ), Transform( 1, 0, 0, 0, 0.995445, -0.0953419, 0, 0.0953419, 0.995445, 0, 1.0768, 0 ), SubResource( 22 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.59792, 1.42922 ), SubResource( 22 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.74276, -1.29866 ), SubResource( 22 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0707073, 2.96499, 0.0801156 ) ]
[sub_resource type="CylinderShape" id=26]
radius = 0.3
height = 2.25014
[sub_resource type="SphereShape" id=27]
radius = 1.4
[sub_resource type="TreeInstanceGenerator" id=30]
step = 8
item = 6
[sub_resource type="VoxelInstanceLibraryItem" id=29]
lod_index = 2
generator = SubResource( 30 )
mesh = ExtResource( 12 )
mesh_lod1 = ExtResource( 13 )
mesh_lod2 = ExtResource( 14 )
mesh_lod3 = ExtResource( 14 )
collision_shapes = [ SubResource( 26 ), Transform( 1, 0, 0, 0, 0.995445, -0.0953419, 0, 0.0953419, 0.995445, 0, 1.0768, 0 ), SubResource( 27 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.59792, 1.42922 ), SubResource( 27 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.74276, -1.29866 ), SubResource( 27 ), Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0707073, 2.96499, 0.0801156 ) ]
[sub_resource type="TreeInstanceGenerator" id=31]
step = 16
item = 8
[sub_resource type="VoxelInstanceLibraryItem" id=32]
name = "bush1"
lod_index = 1
generator = SubResource( 31 )
mesh = ExtResource( 15 )
[sub_resource type="TreeInstanceGenerator" id=33]
step = 16
item = 9
[sub_resource type="VoxelInstanceLibraryItem" id=34]
name = "bush2"
lod_index = 1
generator = SubResource( 33 )
mesh = ExtResource( 16 )
[sub_resource type="TreeInstanceGenerator" id=35]
step = 16
item = 10
[sub_resource type="VoxelInstanceLibraryItem" id=36]
lod_index = 2
generator = SubResource( 35 )
mesh = ExtResource( 17 )
[sub_resource type="TreeInstanceGenerator" id=37]
step = 16
item = 11
[sub_resource type="VoxelInstanceLibraryItem" id=38]
name = "bush4"
lod_index = 1
generator = SubResource( 37 )
mesh = ExtResource( 18 )
[sub_resource type="TreeInstanceGenerator" id=39]
step = 16
item = 12
[sub_resource type="VoxelInstanceLibraryItem" id=40]
name = "bush5"
lod_index = 1
generator = SubResource( 39 )
mesh = ExtResource( 19 )
[sub_resource type="TreeInstanceGenerator" id=41]
step = 64
item = 16
[sub_resource type="VoxelInstanceLibraryItem" id=42]
name = "flower1"
generator = SubResource( 41 )
mesh = ExtResource( 20 )
mesh_lod1 = ExtResource( 21 )
[sub_resource type="VoxelInstanceLibrary" id=18]
item_1 = SubResource( 17 )
item_2 = SubResource( 24 )
item_3 = SubResource( 29 )
item_4 = SubResource( 32 )
item_5 = SubResource( 34 )
item_6 = SubResource( 36 )
item_7 = SubResource( 38 )
item_8 = SubResource( 40 )
item_9 = SubResource( 42 )
item_10 = SubResource( 44 )
item_11 = SubResource( 46 )
item_12 = SubResource( 48 )
[sub_resource type="Curve" id=20]
min_value = -300.0 min_value = -300.0
max_value = 300.0 max_value = 300.0
bake_resolution = 200 bake_resolution = 200
@@ -55,11 +258,16 @@ fps_camera_scene = ExtResource( 6 )
[node name="VoxelLodTerrain" type="VoxelLodTerrain" parent="." groups=["navigation"]] [node name="VoxelLodTerrain" type="VoxelLodTerrain" parent="." groups=["navigation"]]
generator = SubResource( 7 ) generator = SubResource( 7 )
mesher = SubResource( 4 ) mesher = SubResource( 4 )
lod_count = 5 view_distance = 300
lod_distance = 64.0 lod_count = 7
lod_distance = 60.0
lod_fade_duration = 1.0 lod_fade_duration = 1.0
material = SubResource( 6 ) material = SubResource( 6 )
run_stream_in_editor = false run_stream_in_editor = false
mesh_block_size = 32
[node name="VoxelInstancer" type="VoxelInstancer" parent="VoxelLodTerrain"]
library = SubResource( 18 )
[node name="DirectionalLight" type="DirectionalLight" parent="."] [node name="DirectionalLight" type="DirectionalLight" parent="."]
transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 100, 0 ) transform = Transform( 1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 100, 0 )
@@ -71,7 +279,7 @@ far = 600.0
[node name="Roads" type="Roads" parent="."] [node name="Roads" type="Roads" parent="."]
road_data = ExtResource( 3 ) road_data = ExtResource( 3 )
curve = SubResource( 1 ) curve = SubResource( 20 )
noise = SubResource( 8 ) noise = SubResource( 8 )
[node name="camera_pos" parent="." instance=ExtResource( 4 )] [node name="camera_pos" parent="." instance=ExtResource( 4 )]