Now trees will spawn on grass. Currently it's done with nodes/mesh instances for testing. It actually looks a lot better that I anticipated, so I'll soon port it to use terraman's prop system (Which also needs to have material caches implemented).

This commit is contained in:
Relintai 2021-08-06 22:33:50 +02:00
parent c7938caaa8
commit 254fb23d98
3 changed files with 28 additions and 2 deletions

View File

@ -1,6 +1,8 @@
[gd_resource type="Biome" load_steps=2 format=2]
[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]
[resource]
script = ExtResource( 1 )
tree = ExtResource( 2 )

View File

@ -1,8 +1,10 @@
[gd_resource type="Biome" load_steps=3 format=2]
[gd_resource type="Biome" load_steps=4 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/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]
[resource]
buildings = [ ExtResource( 2 ) ]
script = ExtResource( 1 )
tree = ExtResource( 3 )

View File

@ -21,6 +21,8 @@ extends Biome
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
export(PackedScene) var tree : PackedScene
var terrarin_gen : BiomeTerrarinGenerator = BiomeTerrarinGenerator.new()
var voxel_scale : float = -1
@ -32,6 +34,11 @@ func _setup():
var d : Building = get_building(i)
d.setup()
func _instance(p_seed, p_instance):
p_instance.tree = tree
return ._instance(p_seed, p_instance)
func _generate_terra_chunk(chunk, spawn_mobs):
if voxel_scale < 0:
voxel_scale = chunk.voxel_scale
@ -93,3 +100,18 @@ func gen_terra_chunk(chunk: TerraChunk) -> void:
chunk.set_voxel(2, x, z, TerraChunkDefault.DEFAULT_CHANNEL_TYPE)
elif val > 90:
chunk.set_voxel(4, x, z, TerraChunkDefault.DEFAULT_CHANNEL_TYPE)
else:
#Todo use the prop system for this
if randf() > 0.992:
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)