Now the trees are spawned with terraman's prop system. It does need some fixes though.

This commit is contained in:
Relintai 2021-08-07 10:14:17 +02:00
parent 885ba9e4d4
commit f29445bdf6
6 changed files with 73 additions and 1081 deletions

View File

@ -1,8 +1,8 @@
[gd_resource type="Biome" load_steps=3 format=2]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome.gd" type="Script" id=1]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t1.tscn" type="PackedScene" id=2]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t1.tres" type="PropData" id=2]
[resource]
script = ExtResource( 1 )
tree = ExtResource( 2 )
prop_tree = ExtResource( 2 )

View File

@ -2,9 +2,9 @@
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome.gd" type="Script" id=1]
[ext_resource path="res://modules/planets/test_planet/villages/village.tres" type="Building" id=2]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t1.tscn" type="PackedScene" id=3]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t1.tres" type="PropData" id=3]
[resource]
buildings = [ ExtResource( 2 ) ]
script = ExtResource( 1 )
tree = ExtResource( 3 )
prop_tree = ExtResource( 3 )

View File

@ -22,6 +22,7 @@ extends Biome
# SOFTWARE.
export(PackedScene) var tree : PackedScene
export(PropData) var prop_tree : PropData
var terrarin_gen : BiomeTerrarinGenerator = BiomeTerrarinGenerator.new()
@ -36,6 +37,7 @@ func _setup():
func _instance(p_seed, p_instance):
p_instance.tree = tree
p_instance.prop_tree = prop_tree
return ._instance(p_seed, p_instance)
@ -103,15 +105,28 @@ func gen_terra_chunk(chunk: TerraChunk) -> void:
else:
#Todo use the prop system for this
if randf() > 0.992:
var t = tree.instance()
var spat : Spatial = t as Spatial
# var t = tree.instance()
#
# var spat : Spatial = t as Spatial
#
# spat.rotate(Vector3(0, 1, 0), randf() * PI)
# spat.rotate(Vector3(1, 0, 0), randf() * 0.2 - 0.1)
# spat.rotate(Vector3(0, 0, 1), randf() * 0.2 - 0.1)
# spat.transform = spat.transform.scaled(Vector3(0.9 + 0.8 - randf(), 0.9 + 0.8 - randf(), 0.9 + 0.8 - randf()))
# spat.transform.origin = Vector3((x + chunk.position_x * chunk.size_x) * chunk.voxel_scale, ((val - 2) / 255.0) * chunk.world_height * chunk.voxel_scale, (z + chunk.position_z * chunk.size_z) * chunk.voxel_scale)
# chunk.voxel_world.call_deferred("add_child", spat)
var tr : Transform = Transform()
tr = tr.rotated(Vector3(0, 1, 0), randf() * PI)
tr = tr.rotated(Vector3(1, 0, 0), randf() * 0.2 - 0.1)
tr = tr.rotated(Vector3(0, 0, 1), randf() * 0.2 - 0.1)
tr = tr.scaled(Vector3(0.9 + 0.8 - randf(), 0.9 + 0.8 - randf(), 0.9 + 0.8 - randf()))
tr.origin = Vector3((x + chunk.position_x * chunk.size_x) * chunk.voxel_scale, ((val - 2) / 255.0) * chunk.world_height * chunk.voxel_scale, (z + chunk.position_z * chunk.size_z) * chunk.voxel_scale)
chunk.voxel_world.prop_add(tr, prop_tree, false)
spat.rotate(Vector3(0, 1, 0), randf() * PI)
spat.rotate(Vector3(1, 0, 0), randf() * 0.2 - 0.1)
spat.rotate(Vector3(0, 0, 1), randf() * 0.2 - 0.1)
spat.transform = spat.transform.scaled(Vector3(0.9 + 0.8 - randf(), 0.9 + 0.8 - randf(), 0.9 + 0.8 - randf()))
spat.transform.origin = Vector3((x + chunk.position_x * chunk.size_x) * chunk.voxel_scale, ((val - 2) / 255.0) * chunk.world_height * chunk.voxel_scale, (z + chunk.position_z * chunk.size_z) * chunk.voxel_scale)
chunk.voxel_world.call_deferred("add_child", spat)

View File

@ -0,0 +1,11 @@
[gd_resource type="PropData" load_steps=4 format=2]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/tree256.png" type="Texture" id=1]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t1.gltf" type="MeshDataResource" id=2]
[sub_resource type="PropDataMeshData" id=1]
mesh = ExtResource( 2 )
texture = ExtResource( 1 )
[resource]
props = [ SubResource( 1 ) ]

View File

@ -1,17 +1,28 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=5 format=2]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t1.gltf" type="PackedScene" id=1]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/tree.material" type="Material" id=1]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/t1.gltf" type="MeshDataResource" id=2]
[ext_resource path="res://modules/planets/test_planet/biomes/simple_biome/low_poly_rpg_item_collection_3/tree256.png" type="Texture" id=3]
[sub_resource type="BoxShape" id=1]
extents = Vector3( 2.83986, 5.77297, 2.95146 )
[sub_resource type="ArrayMesh" id=1]
surfaces/0 = {
"aabb": AABB( 0, 0, 0, 0, 0, 0 ),
"array_data": PoolByteArray( ),
"array_index_data": PoolByteArray( ),
"blend_shape_data": [ ],
"format": 0,
"index_count": 0,
"material": ExtResource( 1 ),
"primitive": 7,
"skeleton_aabb": [ ],
"vertex_count": 0
}
[node name="t1" instance=ExtResource( 1 )]
[node name="Spatial" type="Spatial"]
[node name="tree" parent="." index="0"]
transform = Transform( 3, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0 )
[node name="StaticBody" type="StaticBody" parent="." index="1"]
[node name="CollisionShape" type="CollisionShape" parent="StaticBody" index="0"]
transform = Transform( 0.934838, 0, 0.355074, 0, 1, 0, -0.355074, 0, 0.934838, -0.170427, 5.15623, -0.4485 )
shape = SubResource( 1 )
[node name="MeshDataInstance" type="MeshDataInstance" parent="."]
mesh = SubResource( 1 )
material/0 = null
mesh_data = ExtResource( 2 )
texture = ExtResource( 3 )
material = ExtResource( 1 )