add base 3d

pull/7/head
Valentin Stark 3 years ago
parent 770bf370fe
commit 987cb61c1f
  1. 2
      project.godot
  2. 1
      utils/terrain/Terrain.gd
  3. 35
      world/World.gd
  4. 0
      world/default_env.tres
  5. 2
      world/game.gd
  6. 26
      world/game.tscn
  7. 4
      world/world.tres

@ -46,4 +46,4 @@ common/enable_pause_aware_picking=true
[rendering]
environment/default_environment="res://default_env.tres"
environment/default_environment="res://world/default_env.tres"

@ -62,6 +62,7 @@ class Triangle:
var list_points = []
for edge in edges():
list_points.append(Point.new(_terrain._triangles[edge._idx], _terrain))
list_points.invert()
return list_points
func triangles_adjacent():

@ -0,0 +1,35 @@
extends Spatial
var terrain
func _ready():
pass
func draw_world():
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_smooth_group(true)
for triangle in terrain.get_triangles():
for point in triangle.points():
st.add_vertex(point.point3d())
st.generate_normals()
st.generate_tangents()
st.index()
# Commit to a mesh.
var mesh = st.commit()
var mi = MeshInstance.new()
mi.mesh = mesh
var material = load("res://world/world.tres")
mi.set_surface_material(0, material)
mi.create_trimesh_collision()
mi.cast_shadow = GeometryInstance.SHADOW_CASTING_SETTING_ON
print(mi)
add_child(mi)
func _on_Game_world_loaded(game_terrain):
terrain = game_terrain
draw_world()

@ -1,4 +1,4 @@
extends Spatial
extends Node
signal world_loaded

@ -1,16 +1,34 @@
[gd_scene load_steps=3 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://ui/ui.tscn" type="PackedScene" id=1]
[ext_resource path="res://world/game.gd" type="Script" id=2]
[ext_resource path="res://world/default_env.tres" type="Environment" id=3]
[ext_resource path="res://world/World.gd" type="Script" id=4]
[node name="Game" type="Spatial"]
[sub_resource type="PlaneMesh" id=1]
size = Vector2( 2000, 2000 )
[node name="Game" type="Node"]
script = ExtResource( 2 )
[node name="UI" parent="." instance=ExtResource( 1 )]
[node name="Map" parent="UI" index="0"]
scale = Vector2( 0.5, 0.5 )
[node name="World" type="Spatial" parent="."]
script = ExtResource( 4 )
[node name="Water" type="MeshInstance" parent="World"]
visible = false
mesh = SubResource( 1 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="World"]
environment = ExtResource( 3 )
[node name="Camera" type="Camera" parent="World"]
transform = Transform( 1, 0, 0, 0, 0.509837, 0.860271, 0, -0.860271, 0.509837, 0, 5.05008, 66.6125 )
near = 0.01
far = 8192.0
[connection signal="world_loaded" from="." to="UI/Map" method="_on_Game_world_loaded"]
[connection signal="world_loaded" from="." to="World" method="_on_Game_world_loaded"]
[editable path="UI"]

@ -0,0 +1,4 @@
[gd_resource type="SpatialMaterial" format=2]
[resource]
albedo_color = Color( 0.109804, 0.305882, 0.0745098, 1 )
Loading…
Cancel
Save