Back online. Major progress
This commit is contained in:
parent
73f6f4e138
commit
c2399094c4
19
godot/Camera3D.gd
Normal file
19
godot/Camera3D.gd
Normal file
@ -0,0 +1,19 @@
|
||||
extends Camera3D
|
||||
|
||||
var velocity: Vector3
|
||||
var acceleration: Vector3
|
||||
var g : float = 0.1
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
acceleration = -global_position.normalized()
|
||||
velocity = Vector3(0.05, 0, 0)
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
acceleration = -global_position.normalized() * g / global_position.length_squared()
|
||||
velocity += acceleration
|
||||
global_translate(velocity)
|
||||
look_at(Vector3(0,0,0))
|
||||
|
58
godot/PlanetData.gd
Normal file
58
godot/PlanetData.gd
Normal file
@ -0,0 +1,58 @@
|
||||
@tool
|
||||
|
||||
extends Resource
|
||||
|
||||
class_name PlanetData
|
||||
|
||||
@export var radius : float = 1:
|
||||
get:
|
||||
return radius
|
||||
set(value):
|
||||
radius = value
|
||||
emit_signal("changed")
|
||||
|
||||
@export var resolution : int = 50:
|
||||
get:
|
||||
return resolution
|
||||
set(value):
|
||||
resolution = value
|
||||
emit_signal("changed")
|
||||
|
||||
@export var noise_map : FastNoiseLite = FastNoiseLite.new():
|
||||
get:
|
||||
return noise_map
|
||||
set(value):
|
||||
noise_map = value
|
||||
emit_signal("changed")
|
||||
if noise_map != null and not noise_map.is_connected("changed", on_data_changed):
|
||||
noise_map.connect("changed", on_data_changed)
|
||||
|
||||
@export var amplitude : float = 1.0:
|
||||
get:
|
||||
return amplitude
|
||||
set(value):
|
||||
amplitude = value
|
||||
emit_signal("changed")
|
||||
|
||||
@export var min_height : float = 0.9:
|
||||
get:
|
||||
return min_height
|
||||
set(value):
|
||||
min_height = value
|
||||
emit_signal("changed")
|
||||
|
||||
@export var flatness : float = 6:
|
||||
get:
|
||||
return flatness
|
||||
set(value):
|
||||
flatness = value
|
||||
emit_signal("changed")
|
||||
|
||||
func on_data_changed():
|
||||
emit_signal("changed")
|
||||
|
||||
func point_on_planet(point_on_sphere : Vector3) -> Vector3:
|
||||
assert(noise_map != null, "Noise map not set")
|
||||
var elevation = 1 / (1 + exp(noise_map.get_noise_3dv(point_on_sphere) * -flatness))
|
||||
elevation = max(0.0, (elevation + 1)/2 - min_height)
|
||||
return point_on_sphere * radius * (elevation + 1)
|
@ -1,8 +1,24 @@
|
||||
@tool
|
||||
|
||||
extends Node3D
|
||||
|
||||
@export var planet_data : Resource = PlanetData.new():
|
||||
get:
|
||||
return planet_data
|
||||
set(value):
|
||||
planet_data = value
|
||||
on_data_changed()
|
||||
if planet_data != null and not planet_data.is_connected("changed", on_data_changed):
|
||||
planet_data.connect("changed", on_data_changed)
|
||||
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
planet_data = PlanetData.new()
|
||||
planet_data.noise_map = FastNoiseLite.new()
|
||||
planet_data.noise_map.set_noise_type(FastNoiseLite.NoiseType.TYPE_SIMPLEX)
|
||||
planet_data.noise_map.frequency = 1
|
||||
on_data_changed()
|
||||
|
||||
|
||||
func _process(delta):
|
||||
pass
|
||||
func on_data_changed():
|
||||
for child in get_children():
|
||||
var face := child as PlantetMeshFace
|
||||
face.regenerate_mesh(planet_data)
|
||||
|
4
godot/PlanetGeneration.tres
Normal file
4
godot/PlanetGeneration.tres
Normal file
@ -0,0 +1,4 @@
|
||||
[gd_resource type="StandardMaterial3D" format=3 uid="uid://bdomu4talxrt8"]
|
||||
|
||||
[resource]
|
||||
albedo_color = Color(0.0666667, 0.313726, 1, 1)
|
File diff suppressed because one or more lines are too long
@ -1,8 +1,11 @@
|
||||
@tool
|
||||
|
||||
extends MeshInstance3D
|
||||
class_name PlantetMeshFace
|
||||
|
||||
@export var normal : Vector3
|
||||
|
||||
func regenerate_mesh():
|
||||
func regenerate_mesh(planet_data):
|
||||
var arrays := []
|
||||
arrays.resize(Mesh.ARRAY_MAX)
|
||||
|
||||
@ -12,7 +15,7 @@ func regenerate_mesh():
|
||||
|
||||
var index_array := PackedInt32Array()
|
||||
|
||||
var resolution := 5
|
||||
var resolution : int = planet_data.resolution
|
||||
var num_vertices : int = resolution * resolution
|
||||
var num_indices : int = (resolution-1) * (resolution-1) * 6
|
||||
|
||||
@ -22,14 +25,16 @@ func regenerate_mesh():
|
||||
index_array.resize(num_indices)
|
||||
|
||||
var tri_index : int = 0
|
||||
var a_axis := Vector3(normal.y, normal.z, normal.z)
|
||||
var a_axis := Vector3(normal.y, normal.z, normal.x)
|
||||
var b_axis : Vector3 = normal.cross(a_axis)
|
||||
for y in range(resolution):
|
||||
for x in range(resolution):
|
||||
var i : int = x + y*resolution
|
||||
var percent := Vector2(x,y) / (resolution-1)
|
||||
var point_on_cube : Vector3 = normal + (percent.x - 0.5)*2.0*a_axis + (percent.y - 0.5)*2.0*b_axis
|
||||
vertex_array[i] = point_on_cube
|
||||
var point_on_sphere = point_on_cube.normalized()
|
||||
var point_on_planet = planet_data.point_on_planet(point_on_sphere)
|
||||
vertex_array[i] = point_on_planet
|
||||
if x != resolution-1 and y != resolution-1:
|
||||
index_array[tri_index + 2] = i
|
||||
index_array[tri_index + 1] = i+resolution+1
|
||||
@ -40,3 +45,33 @@ func regenerate_mesh():
|
||||
index_array[tri_index + 3] = i+resolution+1
|
||||
tri_index += 6
|
||||
|
||||
for a in range(0, index_array.size(), 3):
|
||||
var b : int = a + 1
|
||||
var c : int = a + 2
|
||||
|
||||
var ab : Vector3 = vertex_array[index_array[b]] - vertex_array[index_array[a]]
|
||||
var bc : Vector3 = vertex_array[index_array[c]] - vertex_array[index_array[b]]
|
||||
var ca : Vector3 = vertex_array[index_array[a]] - vertex_array[index_array[c]]
|
||||
|
||||
var cross_ab_bc : Vector3 = bc.cross(ab)
|
||||
var cross_bc_ca : Vector3 = ca.cross(bc)
|
||||
var cross_ca_ab : Vector3 = ab.cross(ca)
|
||||
|
||||
normal_array[index_array[a]] += cross_ab_bc + cross_bc_ca + cross_ca_ab
|
||||
normal_array[index_array[b]] += cross_ab_bc + cross_bc_ca + cross_ca_ab
|
||||
normal_array[index_array[c]] += cross_ab_bc + cross_bc_ca + cross_ca_ab
|
||||
|
||||
for i in range(normal_array.size()):
|
||||
normal_array[i] = normal_array[i].normalized()
|
||||
|
||||
arrays[Mesh.ARRAY_VERTEX] = vertex_array
|
||||
arrays[Mesh.ARRAY_NORMAL] = normal_array
|
||||
arrays[Mesh.ARRAY_TEX_UV] = uv_array
|
||||
arrays[Mesh.ARRAY_INDEX] = index_array
|
||||
|
||||
call_deferred("_update_mesh", arrays)
|
||||
|
||||
func _update_mesh(arrays : Array):
|
||||
var _mesh := ArrayMesh.new()
|
||||
_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, arrays)
|
||||
self.mesh = _mesh
|
||||
|
14
godot/PlanetShading.gdshader
Normal file
14
godot/PlanetShading.gdshader
Normal file
@ -0,0 +1,14 @@
|
||||
shader_type spatial;
|
||||
|
||||
void vertex() {
|
||||
// Called for every vertex the material is visible on.
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
// Called for every pixel the material is visible on.
|
||||
}
|
||||
|
||||
//void light() {
|
||||
// Called for every pixel for every light affecting the material.
|
||||
// Uncomment to replace the default light processing function with this one.
|
||||
//}
|
BIN
godot/cc71d02a-1e5a-4aa3-a8f2-44f262a17d38_scaled.jpg
Normal file
BIN
godot/cc71d02a-1e5a-4aa3-a8f2-44f262a17d38_scaled.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
35
godot/cc71d02a-1e5a-4aa3-a8f2-44f262a17d38_scaled.jpg.import
Normal file
35
godot/cc71d02a-1e5a-4aa3-a8f2-44f262a17d38_scaled.jpg.import
Normal file
@ -0,0 +1,35 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://osf4dpcksyxa"
|
||||
path.s3tc="res://.godot/imported/cc71d02a-1e5a-4aa3-a8f2-44f262a17d38_scaled.jpg-ebbed559ba54c70322c2c7ab480ed1c2.s3tc.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://cc71d02a-1e5a-4aa3-a8f2-44f262a17d38_scaled.jpg"
|
||||
dest_files=["res://.godot/imported/cc71d02a-1e5a-4aa3-a8f2-44f262a17d38_scaled.jpg-ebbed559ba54c70322c2c7ab480ed1c2.s3tc.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
52
godot/main.tscn
Normal file
52
godot/main.tscn
Normal file
@ -0,0 +1,52 @@
|
||||
[gd_scene load_steps=10 format=3 uid="uid://b4ssaqxtmkfpq"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://clkrjexk1mje0" path="res://PlanetGeneration.tscn" id="1_65in3"]
|
||||
[ext_resource type="Texture2D" uid="uid://osf4dpcksyxa" path="res://cc71d02a-1e5a-4aa3-a8f2-44f262a17d38_scaled.jpg" id="1_vooe1"]
|
||||
[ext_resource type="Script" path="res://Camera3D.gd" id="2_4ip6j"]
|
||||
[ext_resource type="Script" path="res://PlanetData.gd" id="2_gy4ke"]
|
||||
|
||||
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_vl6wy"]
|
||||
panorama = ExtResource("1_vooe1")
|
||||
|
||||
[sub_resource type="Sky" id="Sky_78gnh"]
|
||||
sky_material = SubResource("PanoramaSkyMaterial_vl6wy")
|
||||
|
||||
[sub_resource type="Environment" id="Environment_qj44i"]
|
||||
background_mode = 2
|
||||
background_energy_multiplier = 0.68
|
||||
sky = SubResource("Sky_78gnh")
|
||||
ambient_light_color = Color(0.14902, 0.14902, 0.14902, 1)
|
||||
ambient_light_sky_contribution = 0.75
|
||||
ambient_light_energy = 2.59
|
||||
tonemap_mode = 2
|
||||
glow_enabled = true
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_huf6x"]
|
||||
noise_type = 0
|
||||
frequency = 1.0
|
||||
fractal_octaves = 10
|
||||
|
||||
[sub_resource type="Resource" id="Resource_aso5l"]
|
||||
script = ExtResource("2_gy4ke")
|
||||
radius = 1.0
|
||||
resolution = 100
|
||||
noise_map = SubResource("FastNoiseLite_huf6x")
|
||||
amplitude = 1.0
|
||||
min_height = 0.9
|
||||
flatness = 6.0
|
||||
|
||||
[node name="Main" type="Node3D"]
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(0.408033, 0.826428, 0.387978, 0.660572, -0.560588, 0.499385, 0.630202, 0.0525216, -0.774653, 5.16053, 224.499, -333.943)
|
||||
shadow_enabled = true
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_qj44i")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, -13.8584)
|
||||
script = ExtResource("2_4ip6j")
|
||||
|
||||
[node name="Planet" parent="." instance=ExtResource("1_65in3")]
|
||||
planet_data = SubResource("Resource_aso5l")
|
Loading…
Reference in New Issue
Block a user