Skip to content

Commit

Permalink
Added basic swim demo from work performed by pietru2004.
Browse files Browse the repository at this point in the history
Added swim demo into main menu level.

Co-Authored-By: pietru2004 <[email protected]>
  • Loading branch information
Malcolmnixon and pietru2004 committed Sep 22, 2024
1 parent 7c6d455 commit 40618ac
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 0 deletions.
24 changes: 24 additions & 0 deletions scenes/swim_demo/objects/instructions.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[gd_scene load_steps=5 format=3 uid="uid://cap4i60th5v7v"]

[ext_resource type="PackedScene" uid="uid://clujaf3u776a3" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn" id="1_ppayj"]
[ext_resource type="PackedScene" uid="uid://b45jxqo2nss1h" path="res://scenes/swim_demo/objects/instructions_2d.tscn" id="2_m8jyc"]
[ext_resource type="Material" path="res://assets/wahooney.itch.io/brown_grid_triplanar.tres" id="3_corps"]

[sub_resource type="BoxMesh" id="1"]
material = ExtResource("3_corps")
size = Vector3(4.2, 2.7, 0.1)

[node name="Instructions" type="Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, -4)

[node name="Viewport2Din3D" parent="." instance=ExtResource("1_ppayj")]
screen_size = Vector2(4, 2.5)
viewport_size = Vector2(400, 250)
unshaded = true
scene = ExtResource("2_m8jyc")
update_mode = 0
collision_layer = 0

[node name="MeshInstance" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.1)
mesh = SubResource("1")
36 changes: 36 additions & 0 deletions scenes/swim_demo/objects/instructions_2d.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[gd_scene format=3 uid="uid://b45jxqo2nss1h"]

[node name="Instructions" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="ColorRect" type="ColorRect" parent="."]
layout_mode = 1
offset_right = 400.0
offset_bottom = 250.0
color = Color(0, 0, 0, 0.87451)

[node name="Description" type="RichTextLabel" parent="."]
layout_mode = 0
offset_left = 10.0
offset_top = 10.0
offset_right = 390.0
offset_bottom = 240.0
theme_override_constants/line_separation = -3
theme_override_font_sizes/normal_font_size = 12
text = "Swim Demo
This scene demonstrates example swimming. Advanced rendering options such as Volume Fog can be added based on the choice of renderer.
> Left Controller:
- Direct Movement: U/D/L/R Joystick
- Flight Movement: U/D/L/R Joystick
> Right Controller:
- Direct Movement: U/D Joystick
- Turning: L/R Joystick
"
16 changes: 16 additions & 0 deletions scenes/swim_demo/objects/swim_area.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
extends Area3D

func _on_body_entered(body):
if body is XRToolsPlayerBody:
if !body.get_parent().has_node("MovementFlight"):
printerr("Flight Area tried to find MovementFlight, but it could not...")
return
body.get_parent().get_node("MovementFlight").set_flying(true)


func _on_body_exited(body):
if body is XRToolsPlayerBody:
if !body.get_parent().has_node("MovementFlight"):
printerr("Flight Area tried to find MovementFlight, but it could not...")
return
body.get_parent().get_node("MovementFlight").set_flying(false)
114 changes: 114 additions & 0 deletions scenes/swim_demo/objects/swim_map.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[gd_scene load_steps=6 format=3 uid="uid://bjuel0yobnb7l"]

[ext_resource type="Material" path="res://assets/wahooney.itch.io/green_grid_triplanar.tres" id="1_isyto"]
[ext_resource type="Material" path="res://assets/wahooney.itch.io/brown_grid_triplanar.tres" id="2_bp8ee"]

[sub_resource type="QuadMesh" id="7"]
size = Vector2(96, 96)

[sub_resource type="QuadMesh" id="8"]
size = Vector2(96, 16)

[sub_resource type="BoxShape3D" id="4"]
size = Vector3(100, 16, 2)

[node name="SwimMap" type="Node3D"]

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.866025, -0.321394, 0.383022, 0, 0.766044, 0.642788, -0.5, -0.55667, 0.663414, 0, 5, 0)
light_energy = 0.8

[node name="CSGCombiner3D" type="CSGCombiner3D" parent="."]
use_collision = true

[node name="CSGMesh3D" type="CSGMesh3D" parent="CSGCombiner3D"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)
mesh = SubResource("7")
material = ExtResource("1_isyto")

[node name="CSGBox3D" type="CSGBox3D" parent="CSGCombiner3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, -12)
size = Vector3(8, 4, 16)
material = ExtResource("2_bp8ee")

[node name="CSGBox3D2" type="CSGBox3D" parent="CSGCombiner3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.7, -12)
operation = 2
size = Vector3(6, 3.6, 14)
material = ExtResource("2_bp8ee")

[node name="CSGBox3D3" type="CSGBox3D" parent="CSGCombiner3D"]
transform = Transform3D(0.642788, 0.766045, 0, -0.766045, 0.642788, 0, 0, 0, 1, 3.1, 0, -12)
operation = 2
size = Vector3(1, 1.4, 14)
material = ExtResource("2_bp8ee")

[node name="CSGBox3D4" type="CSGBox3D" parent="CSGCombiner3D"]
transform = Transform3D(0.766045, 0.642788, 0, -0.642788, 0.766045, 0, 0, 0, 1, -3.1, 0, -12)
operation = 2
size = Vector3(1.4, 1, 14)
material = ExtResource("2_bp8ee")

[node name="CSGBox3D5" type="CSGBox3D" parent="CSGCombiner3D"]
transform = Transform3D(-3.09086e-08, -3.09086e-08, -1, -0.766045, 0.642788, 3.8097e-09, 0.642788, 0.766045, -4.35451e-08, -1.31134e-07, 0, -4.9)
operation = 2
size = Vector3(1, 1.4, 6)
material = ExtResource("2_bp8ee")

[node name="CSGBox3D6" type="CSGBox3D" parent="CSGCombiner3D"]
transform = Transform3D(-3.09086e-08, -3.09086e-08, -1, -0.642788, 0.766045, -3.8097e-09, 0.766045, 0.642788, -4.35451e-08, 1.31134e-07, 0, -19.1)
operation = 2
size = Vector3(1.4, 1, 6)
material = ExtResource("2_bp8ee")

[node name="Wall1" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -48)

[node name="MeshInstance3D" type="MeshInstance3D" parent="Wall1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, 0)
mesh = SubResource("8")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("1_isyto")

[node name="CollisionShape3D" type="CollisionShape3D" parent="Wall1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, -1)
shape = SubResource("4")

[node name="Wall2" type="StaticBody3D" parent="."]
transform = Transform3D(-4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 48, 0, 0)

[node name="MeshInstance3D" type="MeshInstance3D" parent="Wall2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, 0)
mesh = SubResource("8")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("1_isyto")

[node name="CollisionShape3D" type="CollisionShape3D" parent="Wall2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, -1)
shape = SubResource("4")

[node name="Wall3" type="StaticBody3D" parent="."]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 48)

[node name="MeshInstance3D" type="MeshInstance3D" parent="Wall3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, 0)
mesh = SubResource("8")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("1_isyto")

[node name="CollisionShape3D" type="CollisionShape3D" parent="Wall3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, -1)
shape = SubResource("4")

[node name="Wall4" type="StaticBody3D" parent="."]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -48, 0, 0)

[node name="MeshInstance3D" type="MeshInstance3D" parent="Wall4"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, 0)
mesh = SubResource("8")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("1_isyto")

[node name="CollisionShape3D" type="CollisionShape3D" parent="Wall4"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 8, -1)
shape = SubResource("4")
33 changes: 33 additions & 0 deletions scenes/swim_demo/objects/water_shader.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
shader_type spatial;
render_mode cull_disabled;

// Water material properties
uniform vec3 albedo : source_color = vec3(0.0, 0.0, 0.4);
uniform float metallic : hint_range(0.0, 1.0) = 0.0;
uniform float roughness : hint_range(0.0, 1.0) = 0.02;
uniform float alpha = 0.7;

// Noise scale and texture
uniform float scale = 0.05;
uniform sampler2D normal_texture;

void fragment() {
// Get the world X/Z coordinates
vec2 world = (INV_VIEW_MATRIX * vec4(VERTEX, 1.0)).xz * scale;

// Calculate two time-varying offsets to the noise texture
vec2 offset1 = vec2(0.05, 0.0) * sin(TIME / 5.0 * PI);
vec2 offset2 = vec2(0.0, 0.05) * cos(TIME / 5.0 * PI);

// Sample the noise texture at the two offsets and blend
vec3 normal1v = texture(normal_texture, world + offset1).rgb;
vec3 normal2v = texture(normal_texture, world + offset2).rgb;
vec3 normal = mix(normal1v, normal2v, 0.5);

// Set the outputs
ALBEDO = albedo;
METALLIC = metallic;
ROUGHNESS = roughness;
NORMAL_MAP = normal;
ALPHA = alpha;
}
Binary file added scenes/swim_demo/swim demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions scenes/swim_demo/swim demo.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dd2u7l7q2de65"
path.s3tc="res://.godot/imported/swim demo.png-68e418131c0f315222da038696c9d228.s3tc.ctex"
path.etc2="res://.godot/imported/swim demo.png-68e418131c0f315222da038696c9d228.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}

[deps]

source_file="res://scenes/swim_demo/swim demo.png"
dest_files=["res://.godot/imported/swim demo.png-68e418131c0f315222da038696c9d228.s3tc.ctex", "res://.godot/imported/swim demo.png-68e418131c0f315222da038696c9d228.etc2.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
114 changes: 114 additions & 0 deletions scenes/swim_demo/swim_demo.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[gd_scene load_steps=23 format=3 uid="uid://cup0itbt0cr3a"]

[ext_resource type="PackedScene" uid="uid://qbmx03iibuuu" path="res://addons/godot-xr-tools/staging/scene_base.tscn" id="1_hh5kg"]
[ext_resource type="Script" path="res://scenes/demo_scene_base.gd" id="2_oyddf"]
[ext_resource type="PackedScene" uid="uid://b4kad2kuba1yn" path="res://addons/godot-xr-tools/hands/scenes/lowpoly/left_hand_low.tscn" id="3_pllxu"]
[ext_resource type="PackedScene" uid="uid://bl2nuu3qhlb5k" path="res://addons/godot-xr-tools/functions/movement_direct.tscn" id="4_nrdle"]
[ext_resource type="PackedScene" uid="uid://c2q5phg8w08o" path="res://addons/godot-xr-tools/functions/movement_jump.tscn" id="5_fq8ff"]
[ext_resource type="PackedScene" uid="uid://clt88d5d1dje4" path="res://addons/godot-xr-tools/functions/movement_crouch.tscn" id="6_7hgaq"]
[ext_resource type="PackedScene" uid="uid://l2n30mpbkdyw" path="res://addons/godot-xr-tools/hands/scenes/lowpoly/right_hand_low.tscn" id="7_4gmht"]
[ext_resource type="PackedScene" uid="uid://b6bk2pj8vbj28" path="res://addons/godot-xr-tools/functions/movement_turn.tscn" id="8_0mkhw"]
[ext_resource type="PackedScene" uid="uid://diyu06cw06syv" path="res://addons/godot-xr-tools/player/player_body.tscn" id="9_8t4w8"]
[ext_resource type="PackedScene" uid="uid://bjuel0yobnb7l" path="res://scenes/swim_demo/objects/swim_map.tscn" id="10_1enq8"]
[ext_resource type="PackedScene" uid="uid://kyhaogt0a4q8" path="res://addons/godot-xr-tools/functions/movement_flight.tscn" id="10_a44gs"]
[ext_resource type="PackedScene" uid="uid://3a6wjr3a13vd" path="res://assets/meshes/teleport/teleport.tscn" id="11_2rbjy"]
[ext_resource type="Texture2D" uid="uid://ckw6nliyayo6a" path="res://scenes/main_menu/return to main menu.png" id="12_qpg8h"]
[ext_resource type="PackedScene" uid="uid://cap4i60th5v7v" path="res://scenes/swim_demo/objects/instructions.tscn" id="14_eqdep"]
[ext_resource type="Script" path="res://scenes/swim_demo/objects/swim_area.gd" id="15_pjwfr"]
[ext_resource type="Shader" path="res://scenes/swim_demo/objects/water_shader.gdshader" id="16_k8nhe"]
[ext_resource type="Environment" uid="uid://c75hc5t2ml5re" path="res://default_env.tres" id="17_sr5p1"]

[sub_resource type="BoxShape3D" id="BoxShape3D_nkslp"]
size = Vector3(8, 3, 16)

[sub_resource type="PlaneMesh" id="PlaneMesh_26y0g"]
size = Vector2(6, 14)

[sub_resource type="FastNoiseLite" id="FastNoiseLite_kifw3"]
noise_type = 3
fractal_type = 2

[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_jc332"]
generate_mipmaps = false
seamless = true
as_normal_map = true
bump_strength = 1.5
noise = SubResource("FastNoiseLite_kifw3")

[sub_resource type="ShaderMaterial" id="ShaderMaterial_u86hi"]
render_priority = 0
shader = ExtResource("16_k8nhe")
shader_parameter/albedo = Color(0, 0, 0.4, 1)
shader_parameter/metallic = 0.0
shader_parameter/roughness = 0.02
shader_parameter/alpha = 0.7
shader_parameter/scale = 0.2
shader_parameter/normal_texture = SubResource("NoiseTexture2D_jc332")

[node name="SwimDemo" instance=ExtResource("1_hh5kg")]
script = ExtResource("2_oyddf")

[node name="LeftHand" parent="XROrigin3D/LeftHand" index="0" instance=ExtResource("3_pllxu")]

[node name="MovementDirect" parent="XROrigin3D/LeftHand" index="1" instance=ExtResource("4_nrdle")]
max_speed = 3.0
strafe = true

[node name="MovementJump" parent="XROrigin3D/LeftHand" index="2" instance=ExtResource("5_fq8ff")]
jump_button_action = "ax_button"

[node name="MovementCrouch" parent="XROrigin3D/LeftHand" index="3" instance=ExtResource("6_7hgaq")]
crouch_height = 1.3
crouch_button_action = "by_button"

[node name="RightHand" parent="XROrigin3D/RightHand" index="0" instance=ExtResource("7_4gmht")]

[node name="MovementDirect" parent="XROrigin3D/RightHand" index="1" instance=ExtResource("4_nrdle")]
max_speed = 3.0

[node name="MovementTurn" parent="XROrigin3D/RightHand" index="2" instance=ExtResource("8_0mkhw")]

[node name="MovementJump" parent="XROrigin3D/RightHand" index="3" instance=ExtResource("5_fq8ff")]
jump_button_action = "ax_button"

[node name="MovementCrouch" parent="XROrigin3D/RightHand" index="4" instance=ExtResource("6_7hgaq")]
crouch_height = 1.3
crouch_button_action = "by_button"
crouch_type = 1

[node name="PlayerBody" parent="XROrigin3D" index="3" instance=ExtResource("9_8t4w8")]

[node name="MovementFlight" parent="XROrigin3D" index="4" instance=ExtResource("10_a44gs")]
flight_button = "none"
speed_scale = 3.0

[node name="SwimMap" parent="." index="1" instance=ExtResource("10_1enq8")]

[node name="MainMenuTeleport" parent="." index="2" instance=ExtResource("11_2rbjy")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 7)
scene_base = NodePath("..")
title = ExtResource("12_qpg8h")

[node name="Instructions" parent="." index="3" instance=ExtResource("14_eqdep")]

[node name="SwimArea" type="Area3D" parent="." index="4"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, -12)
collision_layer = 0
collision_mask = 524288
monitorable = false
script = ExtResource("15_pjwfr")

[node name="CollisionShape3D" type="CollisionShape3D" parent="SwimArea" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.2, 0)
shape = SubResource("BoxShape3D_nkslp")

[node name="WaterPlane" type="MeshInstance3D" parent="." index="5"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.7, -12)
mesh = SubResource("PlaneMesh_26y0g")
surface_material_override/0 = SubResource("ShaderMaterial_u86hi")

[node name="WorldEnvironment" type="WorldEnvironment" parent="." index="6"]
environment = ExtResource("17_sr5p1")

[connection signal="body_entered" from="SwimArea" to="SwimArea" method="_on_body_entered"]
[connection signal="body_exited" from="SwimArea" to="SwimArea" method="_on_body_exited"]

0 comments on commit 40618ac

Please sign in to comment.