From d0b4506d80ec922681418c0ed90c3c0e6277c957 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Tue, 7 Jan 2025 11:59:09 -0700 Subject: [PATCH] Terrain surface material is defined using terrain markers instead of abusing the collision bit fields --- .gdlintrc | 2 +- assets/ui/ball_icons/basic_icon.png.import | 14 +-- levels/debug_level/debug_level.tscn | 23 +++- project.godot | 9 +- src/equipment/balls/physics_ball/game_ball.gd | 69 +++++++----- .../balls/physics_ball/physics_ball.tscn | 72 ++++++++++++- .../terrain_physics/terrain_parameters.gd | 5 + .../terrain_physics/terrain_physics.gd | 50 +++++++++ src/game/game.gd | 2 +- src/game/game.tscn | 1 + src/props/scenery/beach/sailboat.tscn | 10 +- .../scenery/city/concrete_building_1.tscn | 9 +- src/props/scenery/city/kana_signboard.tscn | 13 ++- .../highway/guard_rail/guard_rail.tscn | 15 ++- src/props/scenery/highway/highway_road.tscn | 7 +- .../scenery/trees/palm_tree/palm_tree.tscn | 30 ++++-- src/shaders/spatial_shine.gdshader | 14 +-- src/world/effects/splash/splash_effect.tscn | 102 +++++++++--------- src/world/terrain.gd | 40 +++---- src/world/terrain_marker.gd | 4 + 20 files changed, 343 insertions(+), 148 deletions(-) create mode 100644 src/equipment/balls/physics_ball/terrain_physics/terrain_parameters.gd create mode 100644 src/equipment/balls/physics_ball/terrain_physics/terrain_physics.gd create mode 100644 src/world/terrain_marker.gd diff --git a/.gdlintrc b/.gdlintrc index e8c2cf6..be50b7d 100644 --- a/.gdlintrc +++ b/.gdlintrc @@ -36,7 +36,7 @@ loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)* max-file-lines: 1000 max-line-length: 100 max-public-methods: 40 -max-returns: 6 +max-returns: 99 mixed-tabs-and-spaces: null no-elif-return: null no-else-return: null diff --git a/assets/ui/ball_icons/basic_icon.png.import b/assets/ui/ball_icons/basic_icon.png.import index 3b82c5b..a8710dd 100644 --- a/assets/ui/ball_icons/basic_icon.png.import +++ b/assets/ui/ball_icons/basic_icon.png.import @@ -3,25 +3,27 @@ importer="texture" type="CompressedTexture2D" uid="uid://tancoet1lih5" -path="res://.godot/imported/basic_icon.png-bc904292cc126e1d3e1fd0eb1ba5acc2.ctex" +path.s3tc="res://.godot/imported/basic_icon.png-bc904292cc126e1d3e1fd0eb1ba5acc2.s3tc.ctex" +path.etc2="res://.godot/imported/basic_icon.png-bc904292cc126e1d3e1fd0eb1ba5acc2.etc2.ctex" metadata={ -"vram_texture": false +"imported_formats": ["s3tc_bptc", "etc2_astc"], +"vram_texture": true } [deps] source_file="res://assets/ui/ball_icons/basic_icon.png" -dest_files=["res://.godot/imported/basic_icon.png-bc904292cc126e1d3e1fd0eb1ba5acc2.ctex"] +dest_files=["res://.godot/imported/basic_icon.png-bc904292cc126e1d3e1fd0eb1ba5acc2.s3tc.ctex", "res://.godot/imported/basic_icon.png-bc904292cc126e1d3e1fd0eb1ba5acc2.etc2.ctex"] [params] -compress/mode=0 +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=false +mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" @@ -31,4 +33,4 @@ process/normal_map_invert_y=false process/hdr_as_srgb=false process/hdr_clamp_exposure=false process/size_limit=0 -detect_3d/compress_to=1 +detect_3d/compress_to=0 diff --git a/levels/debug_level/debug_level.tscn b/levels/debug_level/debug_level.tscn index dda425c..bece75a 100644 --- a/levels/debug_level/debug_level.tscn +++ b/levels/debug_level/debug_level.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=64 format=3 uid="uid://bm2o3mex10v11"] +[gd_scene load_steps=65 format=3 uid="uid://bm2o3mex10v11"] [ext_resource type="Terrain3DAssets" uid="uid://cwl34gstabgrx" path="res://levels/debug_level/terrain_assets.res" id="1_5smdk"] [ext_resource type="Material" uid="uid://drxnue0xsen13" path="res://assets/materials/tropical_water.tres" id="4_bwkbv"] @@ -24,6 +24,7 @@ [ext_resource type="Texture2D" uid="uid://bq8dxuxfw1rwu" path="res://assets/textures/wood/lacquered_planks.png" id="17_xciuf"] [ext_resource type="Texture2D" path="res://assets/textures/grass_green/grass_green_albedo.dds" id="18_scall"] [ext_resource type="PackedScene" uid="uid://cblsayfgirexr" path="res://src/characters/umineko/umineko.tscn" id="21_ch6qk"] +[ext_resource type="Script" path="res://src/world/terrain_marker.gd" id="23_7p8cl"] [sub_resource type="FastNoiseLite" id="FastNoiseLite_rpgb7"] noise_type = 0 @@ -67,12 +68,12 @@ auto_shader = true [sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_h8tes"] panorama = ExtResource("6_ectru") -[sub_resource type="Sky" id="Sky_3yoab"] +[sub_resource type="Sky" id="Sky_x5sbg"] sky_material = SubResource("PanoramaSkyMaterial_h8tes") [sub_resource type="Environment" id="Environment_k6wwx"] background_mode = 2 -sky = SubResource("Sky_3yoab") +sky = SubResource("Sky_x5sbg") ambient_light_source = 2 ambient_light_color = Color(0.78, 0.78, 0.78, 1) ssao_enabled = true @@ -573,6 +574,10 @@ mesh = SubResource("BoxMesh_jpetf") [node name="StaticBody3D" type="StaticBody3D" parent="GravityCube/MeshInstance3D"] +[node name="TerrainMarker" type="Node" parent="GravityCube/MeshInstance3D/StaticBody3D"] +script = ExtResource("23_7p8cl") +type = 9 + [node name="CollisionShape3D" type="CollisionShape3D" parent="GravityCube/MeshInstance3D/StaticBody3D"] shape = SubResource("BoxShape3D_74f5g") @@ -639,6 +644,10 @@ mesh = SubResource("SphereMesh_ooxtq") [node name="StaticBody3D" type="StaticBody3D" parent="GravityOrb/MeshInstance3D"] +[node name="TerrainMarker" type="Node" parent="GravityOrb/MeshInstance3D/StaticBody3D"] +script = ExtResource("23_7p8cl") +type = 5 + [node name="CollisionShape3D" type="CollisionShape3D" parent="GravityOrb/MeshInstance3D/StaticBody3D"] shape = SubResource("SphereShape3D_ne5nm") @@ -658,6 +667,10 @@ transform = Transform3D(2.33934e-08, 0.535178, -0.844739, 1, -4.37114e-08, 0, -3 [node name="CSGCombiner3D" type="CSGCombiner3D" parent="GravityBowl"] use_collision = true +[node name="TerrainMarker" type="Node" parent="GravityBowl/CSGCombiner3D"] +script = ExtResource("23_7p8cl") +type = 7 + [node name="OuterCylinder" type="CSGCylinder3D" parent="GravityBowl/CSGCombiner3D"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 16, 0) radius = 32.0 @@ -689,6 +702,10 @@ transform = Transform3D(0.688355, -0.285755, 0.666717, 0, 0.919135, 0.393942, -0 [node name="CSGCombiner3D" type="CSGCombiner3D" parent="GravityHalo"] use_collision = true +[node name="TerrainMarker" type="Node" parent="GravityHalo/CSGCombiner3D"] +script = ExtResource("23_7p8cl") +type = 7 + [node name="OuterShell" type="CSGTorus3D" parent="GravityHalo/CSGCombiner3D"] inner_radius = 32.0 outer_radius = 108.0 diff --git a/project.godot b/project.godot index b979655..a2606e2 100644 --- a/project.godot +++ b/project.godot @@ -248,14 +248,6 @@ locale/translations=PackedStringArray("res://assets/text/text.en.translation") 3d_physics/layer_1="Collision Geometry" 3d_physics/layer_2="Water" -3d_physics/layer_25="Green Material" -3d_physics/layer_26="Fairway Material" -3d_physics/layer_27="Glass Material" -3d_physics/layer_28="Metal Material" -3d_physics/layer_29="Rock Material" -3d_physics/layer_30="Wood Material" -3d_physics/layer_31="Sand Material" -3d_physics/layer_32="Grass Material" [physics] @@ -263,6 +255,7 @@ locale/translations=PackedStringArray("res://assets/text/text.en.translation") 3d/sleep_threshold_angular=2.0 jolt_3d/sleep/velocity_threshold=0.1 jolt_3d/sleep/time_threshold=1.0 +jolt_3d/limits/max_angular_velocity=270000.0 jolt_3d/limits/max_temporary_memory=64 [rendering] diff --git a/src/equipment/balls/physics_ball/game_ball.gd b/src/equipment/balls/physics_ball/game_ball.gd index 6c6b0fa..f6442b8 100644 --- a/src/equipment/balls/physics_ball/game_ball.gd +++ b/src/equipment/balls/physics_ball/game_ball.gd @@ -20,10 +20,14 @@ const MAGNUS_EPSILON := 1e-3 ## If enabled, ball ability cooldown is only reset at end of shot. @export var once_per_shot_ability := false -## Angular damping while in air -@export var air_damping := 0.0 -## Angular damping while in collision with rough terrain -@export var rough_damping := 8.0 +## Linear damping while in the air. +@export var aerial_linear_damping := 0.0 + +## Angular damping while in the air. +@export var aerial_angular_damping := 0.0 + +## Material physics configuration for this ball. +@export var terrain_physics: TerrainPhysics #@export var fluid_density := 1.225 #@export var lift_coefficient := 0.05 @@ -58,6 +62,8 @@ var _position_on_last_wake: Vector3 var _awake := false var _ability_triggered := false var _zones: Array[BallZone] = [] +var _shot_time_s := 0.0 +var _surface_time_s := 0.0 @onready var ability_cooldown: Timer = %AbilityCooldown @onready var manual_sleep_timer: Timer = %ManualSleepTimer @@ -68,6 +74,9 @@ var _zones: Array[BallZone] = [] "res://src/equipment/balls/physics_ball/normal_physics.tres" ) +@onready var default_surface_linear_damping := linear_damp +@onready var default_surface_angular_damping := angular_damp + ## Should this ball stick to surfaces, rather than bounce? func is_sticky() -> bool: @@ -102,12 +111,6 @@ func get_damage() -> float: return base_damage + linear_velocity.length_squared() * damage_force_scale -func _total_terrain_angular_damping() -> float: - return _zones.reduce( - func(a: float, b: BallZone) -> float: return a + b.terrain_angular_damping, 0.0 - ) - - func _magnus_force() -> Vector3: return magnus_coefficient * radius * angular_velocity.cross(linear_velocity) @@ -120,11 +123,11 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: _ability_triggered = false _position_on_last_wake = global_position _last_contact_normal = Vector3.UP + _shot_time_s = 0.0 # TODO something's fucky here... I think this gets called once after the ball sleeps - var damping := air_damping if state.get_contact_count(): - constant_force = Vector3.ZERO + # Ball is in contact with a surface # We want the contact normal which minimizes the angle to the up vector var min_dot := -1.0 @@ -135,18 +138,39 @@ func _integrate_forces(state: PhysicsDirectBodyState3D) -> void: min_dot = dot _last_contact_normal = norm - damping = _total_terrain_angular_damping() - if damping <= TERRAIN_DAMPING_EPSILON: - damping = rough_damping - angular_damp = damping + # Use first contact to determine terrain properties + var primary_body: Node = state.get_contact_collider_object(0) + + var terrain := Terrain.from_collision(global_position, primary_body) + var params := terrain_physics.get_params(terrain) + if params: + linear_damp = params.linear_damping + angular_damp = params.angular_damping + else: + linear_damp = default_surface_linear_damping + angular_damp = default_surface_angular_damping + + var decay := 1.0 + terrain_physics.get_decay_factor(_surface_time_s) + #linear_damp *= decay + #angular_damp *= decay + + _surface_time_s += state.step + else: + # Ball is in the air + linear_damp = aerial_linear_damping + angular_damp = aerial_angular_damping + _surface_time_s = 0.0 -func _physics_process(_delta: float) -> void: +func _physics_process(delta: float) -> void: # Simulate magnus effect var magnus := _magnus_force() if magnus.length_squared() > MAGNUS_EPSILON: apply_central_force(magnus) + # Keep shot time + _shot_time_s += delta + func enter_zone(zone: BallZone) -> void: _zones.push_back(zone) @@ -182,15 +206,8 @@ func _on_collision(body: Node) -> void: freeze = true manual_sleep_timer.start() - var terrain: Terrain.Type - if body is Terrain3D: - terrain = Terrain.at_position(global_position, body as Terrain3D) - elif body is CSGShape3D: - terrain = Terrain.from_physical_layer((body as CSGShape3D).collision_layer) - elif body is CollisionObject3D: - terrain = Terrain.from_physical_layer((body as CollisionObject3D).collision_layer) - else: - print_debug("COLLIDER: ", body) + var terrain := Terrain.from_collision(global_position, body) + print_debug("Collision terrain: ", Terrain.Type.keys()[terrain]) if terrain: sfx.play_sfx(terrain) diff --git a/src/equipment/balls/physics_ball/physics_ball.tscn b/src/equipment/balls/physics_ball/physics_ball.tscn index 293a7e6..0bdbfec 100644 --- a/src/equipment/balls/physics_ball/physics_ball.tscn +++ b/src/equipment/balls/physics_ball/physics_ball.tscn @@ -1,8 +1,10 @@ -[gd_scene load_steps=25 format=3 uid="uid://dfttci386ohip"] +[gd_scene load_steps=38 format=3 uid="uid://dfttci386ohip"] [ext_resource type="Script" path="res://src/equipment/balls/physics_ball/game_ball.gd" id="1_iwh2u"] [ext_resource type="PhysicsMaterial" uid="uid://3bih72l068ic" path="res://src/equipment/balls/physics_ball/normal_physics.tres" id="1_l23pw"] +[ext_resource type="Script" path="res://src/equipment/balls/physics_ball/terrain_physics/terrain_physics.gd" id="3_52hui"] [ext_resource type="Material" uid="uid://dpsmjlhjpc7vs" path="res://assets/materials/basic_ball_material.tres" id="3_rc7m1"] +[ext_resource type="Script" path="res://src/equipment/balls/physics_ball/terrain_physics/terrain_parameters.gd" id="4_onl6o"] [ext_resource type="Script" path="res://src/equipment/balls/physics_ball/ball_sfx.gd" id="5_bhshl"] [ext_resource type="AudioStream" uid="uid://cayyndwmxua5x" path="res://assets/sound/sfx/ball/grass2.wav" id="7_l22cv"] [ext_resource type="AudioStream" uid="uid://orisjdcj3mes" path="res://assets/sound/sfx/ball/concrete3.wav" id="7_t2ak2"] @@ -15,6 +17,71 @@ [ext_resource type="Texture2D" uid="uid://c47bkx508biqr" path="res://assets/sprites/particles/plasma.png" id="12_guipt"] [ext_resource type="PackedScene" uid="uid://cm4bb3lg4mfd2" path="res://src/world/effects/splash/splash_effect.tscn" id="12_qlrvx"] +[sub_resource type="Resource" id="Resource_casfi"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 0.5 + +[sub_resource type="Resource" id="Resource_3k63c"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 8.0 + +[sub_resource type="Resource" id="Resource_xf73q"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 2.0 + +[sub_resource type="Resource" id="Resource_nhn3l"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 0.1 + +[sub_resource type="Resource" id="Resource_m3wjo"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 1.0 + +[sub_resource type="Resource" id="Resource_h4rld"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 0.1 + +[sub_resource type="Resource" id="Resource_j6lib"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 2.0 + +[sub_resource type="Resource" id="Resource_7f7ql"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 8.0 + +[sub_resource type="Resource" id="Resource_pusmf"] +script = ExtResource("4_onl6o") +linear_damping = 1.0 +angular_damping = 24.0 + +[sub_resource type="Resource" id="Resource_edkxb"] +script = ExtResource("4_onl6o") +linear_damping = 0.0 +angular_damping = 1.0 + +[sub_resource type="Resource" id="Resource_3ngau"] +script = ExtResource("3_52hui") +damping_decay_curve = 12.0 +damping_decay_scale = 8.0 +default = SubResource("Resource_3k63c") +rough = SubResource("Resource_7f7ql") +fairway = SubResource("Resource_xf73q") +green = SubResource("Resource_m3wjo") +sand = SubResource("Resource_pusmf") +concrete = SubResource("Resource_casfi") +rock = SubResource("Resource_j6lib") +wood = SubResource("Resource_edkxb") +metal = SubResource("Resource_h4rld") +glass = SubResource("Resource_nhn3l") + [sub_resource type="SphereMesh" id="SphereMesh_y0d13"] material = ExtResource("3_rc7m1") radius = 0.05 @@ -132,14 +199,15 @@ size = Vector2(0.2, 0.2) [node name="PhysicsBall" type="RigidBody3D"] mass = 0.05 physics_material_override = ExtResource("1_l23pw") +sleeping = true freeze = true continuous_cd = true contact_monitor = true max_contacts_reported = 3 linear_damp_mode = 1 angular_damp_mode = 1 -angular_damp = 8.0 script = ExtResource("1_iwh2u") +terrain_physics = SubResource("Resource_3ngau") [node name="BallMesh" type="MeshInstance3D" parent="."] mesh = SubResource("SphereMesh_y0d13") diff --git a/src/equipment/balls/physics_ball/terrain_physics/terrain_parameters.gd b/src/equipment/balls/physics_ball/terrain_physics/terrain_parameters.gd new file mode 100644 index 0000000..7558b32 --- /dev/null +++ b/src/equipment/balls/physics_ball/terrain_physics/terrain_parameters.gd @@ -0,0 +1,5 @@ +class_name TerrainParameters extends Resource +## Physical parameters for an individual terrain type. + +@export var linear_damping := 0.0 +@export var angular_damping := 0.0 diff --git a/src/equipment/balls/physics_ball/terrain_physics/terrain_physics.gd b/src/equipment/balls/physics_ball/terrain_physics/terrain_physics.gd new file mode 100644 index 0000000..4c07b81 --- /dev/null +++ b/src/equipment/balls/physics_ball/terrain_physics/terrain_physics.gd @@ -0,0 +1,50 @@ +class_name TerrainPhysics extends Resource +## Container for ball behavior parameters when in contact with different terrain types + +@export_exp_easing() var damping_decay_curve := 1.0 +@export var damping_decay_scale := 8.0 + +@export var default: TerrainParameters + +@export var rough: TerrainParameters +@export var fairway: TerrainParameters +@export var green: TerrainParameters +@export var sand: TerrainParameters +@export var concrete: TerrainParameters +@export var rock: TerrainParameters +@export var wood: TerrainParameters +@export var metal: TerrainParameters +@export var glass: TerrainParameters + + +func get_params(type: Terrain.Type) -> TerrainParameters: + # NOTE: sure would be nice to just store this in a dict, + # but that makes editing physics through the editor unweildy. + match type: + Terrain.Type.ROUGH: + return rough + Terrain.Type.FAIRWAY: + return fairway + Terrain.Type.GREEN: + return green + Terrain.Type.SAND: + return sand + Terrain.Type.CONCRETE: + return concrete + Terrain.Type.ROCK: + return rock + Terrain.Type.WOOD: + return wood + Terrain.Type.METAL: + return metal + Terrain.Type.GLASS: + return glass + _: + return default + + +func get_decay_factor(time: float) -> float: + var x := time / damping_decay_scale + if damping_decay_curve < 1.0: + return 1.0 - pow(1.0 - x, 1.0 / damping_decay_curve) + return pow(x, damping_decay_curve) diff --git a/src/game/game.gd b/src/game/game.gd index 7c1aac2..a3e498c 100644 --- a/src/game/game.gd +++ b/src/game/game.gd @@ -1,7 +1,7 @@ class_name Game extends Node ## Wrapper for the game application -@export var start_scene: String = "res://src/ui/menus/title_screen/title_screen.tscn" +@export_file("*.tscn") var start_scene: String = "res://src/ui/menus/title_screen/title_screen.tscn" var _loading_resources := {} diff --git a/src/game/game.tscn b/src/game/game.tscn index 6e09999..8bb2df8 100644 --- a/src/game/game.tscn +++ b/src/game/game.tscn @@ -119,6 +119,7 @@ _data = { [node name="Game" type="Node" groups=["GameGroup"]] process_mode = 3 script = ExtResource("1_4qa87") +start_scene = "res://src/world/world.tscn" [node name="RootControl" type="Control" parent="."] unique_name_in_owner = true diff --git a/src/props/scenery/beach/sailboat.tscn b/src/props/scenery/beach/sailboat.tscn index 5c02636..d5efe90 100644 --- a/src/props/scenery/beach/sailboat.tscn +++ b/src/props/scenery/beach/sailboat.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://cl0goj38u7r72"] +[gd_scene load_steps=4 format=3 uid="uid://cl0goj38u7r72"] [ext_resource type="PackedScene" uid="uid://ddale58s8aepy" path="res://assets/models/scenery/beach/sailboat/sailboat.gltf" id="1_ivu5q"] +[ext_resource type="Script" path="res://src/world/terrain_marker.gd" id="2_h1xau"] [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_mrf68"] data = PackedVector3Array(0, 0, -5.2392, -1.2315, 0, -2.5941, 1.2315, 0, -2.5941, -1.0788, 1.3998, 6.187, -1.4102, 0, 2.4777, -1.8871, 1.4596, 2.4617, -0.4131, 1.9542, -6.7379, 1.648, 1.6838, -3.1548, -1.648, 1.6838, -3.1548, -0.4131, 1.9542, -6.7379, 0.4131, 1.9542, -6.7379, 1.648, 1.6838, -3.1548, 0.4131, 1.9542, -6.7379, 1.2315, 0, -2.5941, 1.648, 1.6838, -3.1548, -0.4131, 1.9542, -6.7379, 0, 0, -5.2392, 0.4131, 1.9542, -6.7379, 0.3552, 0.8645, 5.9507, -0.3552, 0, 5.2425, -0.3552, 0.8645, 5.9507, 0.3552, 0.8645, 5.9507, 0.3552, 0, 5.2425, -0.3552, 0, 5.2425, 1.8871, 1.4596, 2.4617, 1.2315, 0, -2.5941, 1.4101, 0, 2.4777, 1.0788, 1.3998, 6.187, 0.3552, 0, 5.2425, 0.3552, 0.8645, 5.9507, -1.8871, 1.4596, 2.4617, -1.2315, 0, -2.5941, -1.648, 1.6838, -3.1548, -0.4131, 1.9542, -6.7379, -1.2315, 0, -2.5941, 0, 0, -5.2392, 1.2315, 0, -2.5941, -1.4102, 0, 2.4777, 1.4101, 0, 2.4777, 1.2315, 0, -2.5941, -1.2315, 0, -2.5941, -1.4102, 0, 2.4777, 1.4101, 0, 2.4777, -0.3552, 0, 5.2425, 0.3552, 0, 5.2425, 1.4101, 0, 2.4777, -1.4102, 0, 2.4777, -0.3552, 0, 5.2425, -1.2529, 1.5958, 2.1008, -0.7558, 1.9268, -2.2077, -0.9157, 1.9742, 1.5513, -1.2529, 1.5958, 2.1008, -1.0341, 1.6467, -2.2245, -0.7558, 1.9268, -2.2077, -1.8871, 1.4596, 2.4617, 1.0788, 1.3998, 6.187, -1.0788, 1.3998, 6.187, -1.8871, 1.4596, 2.4617, 1.8871, 1.4596, 2.4617, 1.0788, 1.3998, 6.187, 1.2528, 1.5958, 2.1008, 1.648, 1.6838, -3.1548, 1.8871, 1.4596, 2.4617, 1.2528, 1.5958, 2.1008, 1.034, 1.6467, -2.2245, 1.648, 1.6838, -3.1548, -1.0341, 1.6467, -2.2245, -1.8871, 1.4596, 2.4617, -1.648, 1.6838, -3.1548, -1.0341, 1.6467, -2.2245, -1.2529, 1.5958, 2.1008, -1.8871, 1.4596, 2.4617, -1.2529, 1.5958, 2.1008, 1.8871, 1.4596, 2.4617, -1.8871, 1.4596, 2.4617, -1.2529, 1.5958, 2.1008, 1.2528, 1.5958, 2.1008, 1.8871, 1.4596, 2.4617, 1.034, 1.6467, -2.2245, -1.648, 1.6838, -3.1548, 1.648, 1.6838, -3.1548, 1.034, 1.6467, -2.2245, -1.0341, 1.6467, -2.2245, -1.648, 1.6838, -3.1548, -0.0643, 14.8576, -1.0043, 0, 18.1405, -0.9761, -0.0643, 18.1405, -0.8568, -0.0643, 14.8576, -1.0043, 0, 14.8576, -1.1238, 0, 18.1405, -0.9761, 1.2528, 1.5958, 2.1008, -0.9157, 1.9742, 1.5513, 0.9156, 1.9742, 1.5513, 1.2528, 1.5958, 2.1008, -1.2529, 1.5958, 2.1008, -0.9157, 1.9742, 1.5513, 1.034, 1.6467, -2.2245, 0.9156, 1.9742, 1.5513, 0.7557, 1.9268, -2.2077, 1.034, 1.6467, -2.2245, 1.2528, 1.5958, 2.1008, 0.9156, 1.9742, 1.5513, -1.0341, 1.6467, -2.2245, 0.7557, 1.9268, -2.2077, -0.7558, 1.9268, -2.2077, -1.0341, 1.6467, -2.2245, 1.034, 1.6467, -2.2245, 0.7557, 1.9268, -2.2077, 0.0642, 1.9531, -1.5845, 0.7557, 1.9268, -2.2077, 0.9156, 1.9742, 1.5513, 0.0642, 1.9531, -1.5845, 0, 1.9531, -1.704, 0.7557, 1.9268, -2.2077, 0, 1.9531, -1.704, -0.0643, 1.9531, -1.5845, -0.7558, 1.9268, -2.2077, -0.7558, 1.9268, -2.2077, -0.0643, 1.9531, -1.5845, -0.9157, 1.9742, 1.5513, -0.0643, 1.9531, -1.5845, 0.9156, 1.9742, 1.5513, -0.9157, 1.9742, 1.5513, -0.0643, 1.9531, -1.5845, 0.0642, 1.9531, -1.5845, 0.9156, 1.9742, 1.5513, 0, 1.9531, -1.704, -0.7558, 1.9268, -2.2077, 0.7557, 1.9268, -2.2077, 0, 18.1405, -0.9761, 0.0642, 18.1405, -0.8568, -0.0643, 18.1405, -0.8568, 0.0642, 14.8576, -1.0043, -0.0643, 18.1405, -0.8568, 0.0642, 18.1405, -0.8568, 0.0642, 14.8576, -1.0043, -0.0643, 14.8576, -1.0043, -0.0643, 18.1405, -0.8568, 0, 14.8576, -1.1238, 0.0642, 18.1405, -0.8568, 0, 18.1405, -0.9761, 0, 14.8576, -1.1238, 0.0642, 14.8576, -1.0043, 0.0642, 18.1405, -0.8568, 0, 2.7354, -1.6687, 0.0642, 14.8576, -1.0043, 0, 14.8576, -1.1238, 0, 2.7354, -1.6687, 0.0642, 2.7354, -1.5494, 0.0642, 14.8576, -1.0043, 0.0642, 2.7354, -1.5494, -0.0643, 14.8576, -1.0043, 0.0642, 14.8576, -1.0043, 0.0642, 2.7354, -1.5494, -0.0643, 2.7354, -1.5494, -0.0643, 14.8576, -1.0043, -0.0643, 2.7354, -1.5494, 0, 14.8576, -1.1238, -0.0643, 14.8576, -1.0043, -0.0643, 2.7354, -1.5494, 0, 2.7354, -1.6687, 0, 14.8576, -1.1238, -0.0643, 1.9531, -1.5845, 0, 2.7354, -1.6687, -0.0643, 2.7354, -1.5494, -0.0643, 1.9531, -1.5845, 0, 1.9531, -1.704, 0, 2.7354, -1.6687, 0.0642, 1.9531, -1.5845, -0.0643, 2.7354, -1.5494, 0.0642, 2.7354, -1.5494, 0.0642, 1.9531, -1.5845, -0.0643, 1.9531, -1.5845, -0.0643, 2.7354, -1.5494, 0, 1.9531, -1.704, 0.0642, 2.7354, -1.5494, 0, 2.7354, -1.6687, 0, 1.9531, -1.704, 0.0642, 1.9531, -1.5845, 0.0642, 2.7354, -1.5494, 0.4009, 4.025, -1.0982, 0.0642, 2.7343, 4.4586, 0.0642, 11.1949, 2.3311, 0.0642, 2.7343, 4.4586, 0.4009, 4.025, -1.0982, 0.0642, 2.7354, -1.5494, 0, 2.3279, -5.8547, 0.3366, 3.7543, -2.0024, 0, 14.8576, -1.1238, 0.0642, 18.1405, -0.8568, 0.4009, 4.025, -1.0982, 0.0642, 11.1949, 2.3311, 0, 1.9531, -1.704, 0.3366, 3.7543, -2.0024, 0, 2.3279, -5.8547, 1.0788, 1.3998, 6.187, -0.3552, 0.8645, 5.9507, -1.0788, 1.3998, 6.187, 1.0788, 1.3998, 6.187, 0.3552, 0.8645, 5.9507, -0.3552, 0.8645, 5.9507, 1.0788, 1.3998, 6.187, 1.4101, 0, 2.4777, 0.3552, 0, 5.2425, -0.3552, 0.8645, 5.9507, -0.3552, 0, 5.2425, -1.0788, 1.3998, 6.187, 1.8871, 1.4596, 2.4617, 1.4101, 0, 2.4777, 1.0788, 1.3998, 6.187, -0.3552, 0, 5.2425, -1.4102, 0, 2.4777, -1.0788, 1.3998, 6.187, 1.648, 1.6838, -3.1548, 1.2315, 0, -2.5941, 1.8871, 1.4596, 2.4617, -1.4102, 0, 2.4777, -1.2315, 0, -2.5941, -1.8871, 1.4596, 2.4617, 0, 0, -5.2392, 1.2315, 0, -2.5941, 0.4131, 1.9542, -6.7379, -1.648, 1.6838, -3.1548, -1.2315, 0, -2.5941, -0.4131, 1.9542, -6.7379) @@ -8,7 +9,10 @@ data = PackedVector3Array(0, 0, -5.2392, -1.2315, 0, -2.5941, 1.2315, 0, -2.5941 [node name="Sailboat" instance=ExtResource("1_ivu5q")] [node name="StaticBody3D" type="StaticBody3D" parent="." index="1"] -collision_layer = 536870913 -[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"] +[node name="TerrainMarker" type="Node" parent="StaticBody3D" index="0"] +script = ExtResource("2_h1xau") +type = 7 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="1"] shape = SubResource("ConcavePolygonShape3D_mrf68") diff --git a/src/props/scenery/city/concrete_building_1.tscn b/src/props/scenery/city/concrete_building_1.tscn index deb487f..4e97cad 100644 --- a/src/props/scenery/city/concrete_building_1.tscn +++ b/src/props/scenery/city/concrete_building_1.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://dagh38vap4t1d"] +[gd_scene load_steps=4 format=3 uid="uid://dagh38vap4t1d"] [ext_resource type="PackedScene" uid="uid://mhycq1tk1bpm" path="res://assets/models/scenery/city/concrete_building_1/concrete_building_1.gltf" id="1_id6ph"] +[ext_resource type="Script" path="res://src/world/terrain_marker.gd" id="2_5x2lp"] [sub_resource type="BoxShape3D" id="BoxShape3D_5g4vq"] size = Vector3(16, 24, 16) @@ -9,6 +10,10 @@ size = Vector3(16, 24, 16) [node name="StaticBody3D" type="StaticBody3D" parent="." index="1"] -[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"] +[node name="TerrainMarker" type="Node" parent="StaticBody3D" index="0"] +script = ExtResource("2_5x2lp") +type = 5 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="1"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 12, 0) shape = SubResource("BoxShape3D_5g4vq") diff --git a/src/props/scenery/city/kana_signboard.tscn b/src/props/scenery/city/kana_signboard.tscn index fbf8472..9a39a43 100644 --- a/src/props/scenery/city/kana_signboard.tscn +++ b/src/props/scenery/city/kana_signboard.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=5 format=3 uid="uid://cjubxs7peir5k"] +[gd_scene load_steps=6 format=3 uid="uid://cjubxs7peir5k"] [ext_resource type="PackedScene" uid="uid://hwc1px831dgm" path="res://assets/models/scenery/city/kana_signboard/kana_signboard.gltf" id="1_o4tvg"] [ext_resource type="Texture2D" uid="uid://d0lsrrx0r5wnu" path="res://assets/models/scenery/city/kana_signboard/kana_signboard.png" id="2_85s5u"] +[ext_resource type="Script" path="res://src/world/terrain_marker.gd" id="3_dllon"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_dwyvb"] albedo_texture = ExtResource("2_85s5u") @@ -18,13 +19,17 @@ surface_material_override/0 = SubResource("StandardMaterial3D_dwyvb") [node name="StaticBody3D" type="StaticBody3D" parent="." index="3"] -[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"] +[node name="TerrainMarker" type="Node" parent="StaticBody3D" index="0"] +script = ExtResource("3_dllon") +type = 8 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="1"] shape = SubResource("BoxShape3D_kp4b0") -[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D" index="1"] +[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D" index="2"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 1.2) shape = SubResource("BoxShape3D_kp4b0") -[node name="CollisionShape3D3" type="CollisionShape3D" parent="StaticBody3D" index="2"] +[node name="CollisionShape3D3" type="CollisionShape3D" parent="StaticBody3D" index="3"] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.5, 1.2) shape = SubResource("BoxShape3D_kp4b0") diff --git a/src/props/scenery/highway/guard_rail/guard_rail.tscn b/src/props/scenery/highway/guard_rail/guard_rail.tscn index 20f5bec..2fdbc01 100644 --- a/src/props/scenery/highway/guard_rail/guard_rail.tscn +++ b/src/props/scenery/highway/guard_rail/guard_rail.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=5 format=3 uid="uid://nqar1qcun8ax"] +[gd_scene load_steps=6 format=3 uid="uid://nqar1qcun8ax"] [ext_resource type="Script" path="res://src/props/scenery/highway/guard_rail/guard_rail.gd" id="1_imntf"] [ext_resource type="Material" uid="uid://cift6p0wn1oce" path="res://assets/materials/guard_rail.tres" id="2_1s4wy"] [ext_resource type="PlaneMesh" uid="uid://bdcmgvgpj1e0w" path="res://src/props/scenery/highway/guard_rail/guard_rail_post_mesh.tres" id="3_hha2c"] +[ext_resource type="Script" path="res://src/world/terrain_marker.gd" id="3_nfjvf"] -[sub_resource type="MultiMesh" id="MultiMesh_1o4mq"] +[sub_resource type="MultiMesh" id="MultiMesh_1dcl6"] transform_format = 1 mesh = ExtResource("3_hha2c") @@ -26,6 +27,10 @@ path_u_distance = 1.0 path_joined = false material = ExtResource("2_1s4wy") +[node name="TerrainMarker" type="Node" parent="UpperRail"] +script = ExtResource("3_nfjvf") +type = 8 + [node name="LowerRail" type="CSGPolygon3D" parent="."] use_collision = true polygon = PackedVector2Array(0, 0.4, -0.01, 0.5, 0, 0.6, 0.01, 0.5) @@ -41,7 +46,11 @@ path_u_distance = 1.0 path_joined = false material = ExtResource("2_1s4wy") +[node name="TerrainMarker" type="Node" parent="LowerRail"] +script = ExtResource("3_nfjvf") +type = 8 + [node name="PostMultiMesh" type="MultiMeshInstance3D" parent="."] -multimesh = SubResource("MultiMesh_1o4mq") +multimesh = SubResource("MultiMesh_1dcl6") [connection signal="curve_changed" from="." to="." method="_on_curve_changed"] diff --git a/src/props/scenery/highway/highway_road.tscn b/src/props/scenery/highway/highway_road.tscn index 4feb016..e218621 100644 --- a/src/props/scenery/highway/highway_road.tscn +++ b/src/props/scenery/highway/highway_road.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://d0tcr6uijpym5"] +[gd_scene load_steps=4 format=3 uid="uid://d0tcr6uijpym5"] [ext_resource type="Texture2D" uid="uid://dloe67udf7fpd" path="res://assets/textures/highway/highway_road_grass.png" id="1_f3xui"] +[ext_resource type="Script" path="res://src/world/terrain_marker.gd" id="2_4f0hb"] [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_nkovu"] transparency = 1 @@ -25,3 +26,7 @@ path_continuous_u = true path_u_distance = 1.0 path_joined = false material = SubResource("StandardMaterial3D_nkovu") + +[node name="TerrainMarker" type="Node" parent="CSGPolygon3D"] +script = ExtResource("2_4f0hb") +type = 5 diff --git a/src/props/scenery/trees/palm_tree/palm_tree.tscn b/src/props/scenery/trees/palm_tree/palm_tree.tscn index 63bb384..4c660b4 100644 --- a/src/props/scenery/trees/palm_tree/palm_tree.tscn +++ b/src/props/scenery/trees/palm_tree/palm_tree.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=8 format=3 uid="uid://di7aql54lksn7"] +[gd_scene load_steps=9 format=3 uid="uid://di7aql54lksn7"] [ext_resource type="PackedScene" uid="uid://bgdgd3lky5w60" path="res://assets/models/scenery/trees/palm_tree/palm_tree.gltf" id="1_o3thn"] +[ext_resource type="Script" path="res://src/world/terrain_marker.gd" id="2_1lamy"] [sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_bp5t6"] data = PackedVector3Array(-0.6467, 5.2727, -3.6037, -0.7678, 3.663, -4.1571, 0.0705, 4.1529, -5.0529, 0.1793, 5.4514, -3.9613, 1.1035, 5.3325, -3.712, 0.2063, 5.6673, -3.3214, 0.2063, 5.6673, -3.3214, 1.1035, 5.3325, -3.712, 0.2526, 6.0382, -2.2225, -0.102, 1.5632, -4.5545, 0.9292, 3.4191, -4.4363, 0.0705, 4.1529, -5.0529, 0.0705, 4.1529, -5.0529, -0.7379, 3.4651, -4.2526, -0.102, 1.5632, -4.5545, 0.0705, 4.1529, -5.0529, 0.992, 3.6309, -4.3423, 1.1035, 5.3325, -3.712, 0.0705, 4.1529, -5.0529, 1.1035, 5.3325, -3.712, 0.1793, 5.4514, -3.9613, 0.0705, 4.1529, -5.0529, 0.1793, 5.4514, -3.9613, -0.6467, 5.2727, -3.6037, 0.2063, 5.6673, -3.3214, 0.2526, 6.0382, -2.2225, -0.4953, 5.4015, -3.3712, 0.2063, 5.6673, -3.3214, -0.6467, 5.2727, -3.6037, 0.1793, 5.4514, -3.9613) @@ -44,26 +45,35 @@ bones/10/rotation = Quaternion(0.183326, -0.237737, -0.342496, 0.890264) bones/10/scale = Vector3(1, 1, 1) bones/11/rotation = Quaternion(-0.13894, 0.0183908, 0.000355869, 0.99013) -[node name="StaticBody3D" type="StaticBody3D" parent="." index="2"] -collision_layer = 2147483649 +[node name="LeafBody" type="StaticBody3D" parent="." index="2"] -[node name="CollisionShape3D2" type="CollisionShape3D" parent="StaticBody3D" index="0"] +[node name="TerrainMarker" type="Node" parent="LeafBody" index="0"] +script = ExtResource("2_1lamy") +type = 1 + +[node name="CollisionShape3D2" type="CollisionShape3D" parent="LeafBody" index="1"] shape = SubResource("ConcavePolygonShape3D_bp5t6") -[node name="CollisionShape3D3" type="CollisionShape3D" parent="StaticBody3D" index="1"] +[node name="CollisionShape3D3" type="CollisionShape3D" parent="LeafBody" index="2"] shape = SubResource("ConcavePolygonShape3D_j5qxc") -[node name="CollisionShape3D4" type="CollisionShape3D" parent="StaticBody3D" index="2"] +[node name="CollisionShape3D4" type="CollisionShape3D" parent="LeafBody" index="3"] shape = SubResource("ConcavePolygonShape3D_eopyd") -[node name="CollisionShape3D5" type="CollisionShape3D" parent="StaticBody3D" index="3"] +[node name="CollisionShape3D5" type="CollisionShape3D" parent="LeafBody" index="4"] shape = SubResource("ConcavePolygonShape3D_npgp7") -[node name="CollisionShape3D6" type="CollisionShape3D" parent="StaticBody3D" index="4"] +[node name="CollisionShape3D6" type="CollisionShape3D" parent="LeafBody" index="5"] shape = SubResource("ConcavePolygonShape3D_xl1fh") -[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="5"] +[node name="TrunkBody" type="StaticBody3D" parent="." index="3"] + +[node name="TerrainMarker" type="Node" parent="TrunkBody" index="0"] +script = ExtResource("2_1lamy") +type = 7 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="TrunkBody" index="1"] shape = SubResource("ConcavePolygonShape3D_lol7j") -[node name="AnimationPlayer" parent="." index="3"] +[node name="AnimationPlayer" parent="." index="4"] autoplay = "sway_circle" diff --git a/src/shaders/spatial_shine.gdshader b/src/shaders/spatial_shine.gdshader index 47a6ac5..d982e7d 100644 --- a/src/shaders/spatial_shine.gdshader +++ b/src/shaders/spatial_shine.gdshader @@ -64,25 +64,25 @@ void fragment() { vec2 centered_uv = (UV - 0.5) * size; float radius = length(centered_uv); float angle = atan(centered_uv.y, centered_uv.x) + PI; // Add PI to fix left side cutoff - + vec2 ray1 = vec2(angle * ray1_density + TIME * speed + seed + sin(angle * 3.0), radius * 2.0); vec2 ray2 = vec2(angle * ray2_density + TIME * speed * 1.5 + seed + cos(angle * 2.0), radius * 2.0); - + float cut = 1.0 - smoothstep(cutoff, cutoff + 0.2, radius); ray1 *= cut; ray2 *= cut; - - float rays = hdr ? + + float rays = hdr ? noise(ray1) + (noise(ray2) * ray2_intensity) : clamp(noise(ray1) + (noise(ray2) * ray2_intensity), 0., 1.); - + rays *= smoothstep(spread, spread * 0.3, radius); float core = smoothstep(0.2, 0.0, radius) * core_intensity; rays += core; - + vec4 gradient_color = texture(gradient, vec2(rays, 0.5)); vec3 shine = vec3(rays) * gradient_color.rgb; - + float blur_amount = radius * 0.1; vec2 blur_uv = SCREEN_UV + centered_uv * blur_amount; vec4 blurred = texture(SCREEN_TEXTURE, blur_uv); diff --git a/src/world/effects/splash/splash_effect.tscn b/src/world/effects/splash/splash_effect.tscn index 57c6de6..a854df9 100644 --- a/src/world/effects/splash/splash_effect.tscn +++ b/src/world/effects/splash/splash_effect.tscn @@ -110,6 +110,57 @@ particles_anim_loop = false material = SubResource("StandardMaterial3D_l1irr") size = Vector2(0.1, 0.1) +[sub_resource type="Animation" id="Animation_mg6va"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("Decal:size") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(2, 4, 2)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("Decal:modulate") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Color(1, 1, 1, 1)] +} +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("SprayParticles:emitting") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} +tracks/3/type = "value" +tracks/3/imported = false +tracks/3/enabled = true +tracks/3/path = NodePath("BubbleParticles:emitting") +tracks/3/interp = 1 +tracks/3/loop_wrap = true +tracks/3/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} + [sub_resource type="Animation" id="Animation_ifddj"] resource_name = "effect" length = 2.0 @@ -176,57 +227,6 @@ tracks/4/keys = { }] } -[sub_resource type="Animation" id="Animation_mg6va"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("Decal:size") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Vector3(2, 4, 2)] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath("Decal:modulate") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Color(1, 1, 1, 1)] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath("SprayParticles:emitting") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [false] -} -tracks/3/type = "value" -tracks/3/imported = false -tracks/3/enabled = true -tracks/3/path = NodePath("BubbleParticles:emitting") -tracks/3/interp = 1 -tracks/3/loop_wrap = true -tracks/3/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 1, -"values": [false] -} - [sub_resource type="AnimationLibrary" id="AnimationLibrary_87fye"] _data = { "RESET": SubResource("Animation_mg6va"), diff --git a/src/world/terrain.gd b/src/world/terrain.gd index 1bf0700..39b6c38 100644 --- a/src/world/terrain.gd +++ b/src/world/terrain.gd @@ -16,17 +16,7 @@ enum Type { GLASS, } -## We use the upper bits of collision layers to encode material data -const PHYSICAL_LAYERS := { - 1 << 31: Type.ROUGH, - 1 << 30: Type.SAND, - 1 << 29: Type.WOOD, - 1 << 28: Type.ROCK, - 1 << 27: Type.METAL, - 1 << 26: Type.GLASS, - 1 << 25: Type.FAIRWAY, - 1 << 24: Type.GREEN, -} +const DEFAULT_MATERIAL := Type.CONCRETE ## Get the `Terrain.Type` value which corresponds to the given Terrain3D texture ID. @@ -46,18 +36,18 @@ static func from_texture_id(tex_id: int) -> Type: 4: return Type.ROCK _: - return Type.NONE + return DEFAULT_MATERIAL -## Get the `Terrain.Type` value encoded in the given collision layer setting. +## Get the `Terrain.Type` value associated with a collision body. ## -## We use the upper bits in the collision layer to encode material data. -## Check the collision layer descriptions for more information. -static func from_physical_layer(collision_layer: int) -> Type: - for bit: int in PHYSICAL_LAYERS: - if collision_layer & bit: - return PHYSICAL_LAYERS[bit] - return Type.CONCRETE +## This returns the type stored in the first `TerrainMarker` direct child of the body. +## Use this method to set the terrain type of arbitrary bodies! +static func from_body(body: Node) -> Type: + for n: Node in body.get_children(): + if n is TerrainMarker: + return (n as TerrainMarker).type + return DEFAULT_MATERIAL ## Get the `Terrain.Type` value at the given position in a Terrain3D node. @@ -69,3 +59,13 @@ static func at_position(global_position: Vector3, terrain3d: Terrain3D) -> Type: else: id = int(blend.x) return from_texture_id(id) + + +## Get the Terrain.Type value at the given position for the given body. +## +## Position is only used when colliding with a Terrain3D node. +## Other bodies will have one material type for the entire body node. +static func from_collision(global_position: Vector3, body: Node) -> Type: + if body is Terrain3D: + return Terrain.at_position(global_position, body as Terrain3D) + return Terrain.from_body(body) diff --git a/src/world/terrain_marker.gd b/src/world/terrain_marker.gd new file mode 100644 index 0000000..6776eb0 --- /dev/null +++ b/src/world/terrain_marker.gd @@ -0,0 +1,4 @@ +class_name TerrainMarker extends Node +## Marks the terrain type of a parent collision body. + +@export var type: Terrain.Type