Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seating_v1 #462

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scenes/basic_movement_demo/basic_movement_demo.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=17 format=3]
[gd_scene load_steps=17 format=3 uid="uid://dufjkkndqnsru"]

[ext_resource type="PackedScene" uid="uid://qbmx03iibuuu" path="res://addons/godot-xr-tools/staging/scene_base.tscn" id="1"]
[ext_resource type="Script" path="res://scenes/demo_scene_base.gd" id="2_5ptmo"]
Expand Down
4 changes: 2 additions & 2 deletions scenes/basic_movement_demo/objects/instructions.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://dipg8euybm3f1"]

[ext_resource type="PackedScene" uid="uid://px47xx1e0la2" path="res://scenes/basic_movement_demo/objects/instructions_2d.tscn" id="1"]
[ext_resource type="PackedScene" uid="uid://clujaf3u776a3" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn" id="2"]
[ext_resource type="PackedScene" uid="uid://dph2a2rn6yf8d" path="res://scenes/seating_demo/objects/instructions_2d.tscn" id="2_gtldi"]
[ext_resource type="Material" path="res://assets/wahooney.itch.io/brown_grid_triplanar.tres" id="3"]

[sub_resource type="BoxMesh" id="1"]
Expand All @@ -14,7 +14,7 @@ size = Vector3(4.2, 2.7, 0.1)
screen_size = Vector2(4, 2.5)
viewport_size = Vector2(400, 250)
unshaded = true
scene = ExtResource("1")
scene = ExtResource("2_gtldi")
update_mode = 0
collision_layer = 0

Expand Down
125 changes: 45 additions & 80 deletions scenes/main_menu/main_menu_level.tscn

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions scenes/seating_demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Seating Demo

This scene demonstrates example way to implement seating in chair

23 changes: 23 additions & 0 deletions scenes/seating_demo/objects/instructions.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[gd_scene load_steps=5 format=3 uid="uid://duooqcv6nalu8"]

[ext_resource type="PackedScene" uid="uid://clujaf3u776a3" path="res://addons/godot-xr-tools/objects/viewport_2d_in_3d.tscn" id="1_rtpir"]
[ext_resource type="PackedScene" uid="uid://px47xx1e0la2" path="res://scenes/basic_movement_demo/objects/instructions_2d.tscn" id="2_74yp0"]
[ext_resource type="Material" path="res://assets/wahooney.itch.io/brown_grid_triplanar.tres" id="3_egmka"]

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

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

[node name="Viewport2Din3D" parent="." instance=ExtResource("1_rtpir")]
screen_size = Vector2(4, 2.5)
viewport_size = Vector2(400, 250)
unshaded = true
scene = ExtResource("2_74yp0")
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")
34 changes: 34 additions & 0 deletions scenes/seating_demo/objects/instructions_2d.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[gd_scene format=3 uid="uid://dph2a2rn6yf8d"]

[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 = "Seating Demo

This scene demonstrates how you can make a seat, for example for car.

> Left Controller:
- Direct Movement: U/D/L/R Joystick

> Right Controller:
- Direct Movement: U/D Joystick
- Turning: L/R Joystick"
83 changes: 83 additions & 0 deletions scenes/seating_demo/objects/seat.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
extends StaticBody3D


var XROrigin :XROrigin3D
var PlayerBody : CharacterBody3D
var Exit_Node : Node3D
func _ready() -> void:
#Store current chair possition
last_chair_pos=self.global_transform.origin
last_chair_rot=self.global_rotation

#Assume XROrigin is named XROrigin3D and is accessible via unical name
var sb = XRTools.find_xr_ancestor(self,"*","XRToolsSceneBase")
XROrigin = XRTools.find_xr_child(sb,"*","XROrigin3D")

#Get Playerbody
PlayerBody = XROrigin.get_node("PlayerBody")

#Check and Retrive exit node if it exists
if has_node("Exit"):
Exit_Node = get_node("Exit")

#Storage for player enter position
var last_plr_pos := Vector3.ZERO
var last_plr_rot := Vector3.ZERO


var is_sitting := false

#For multiplayer to set should chair update local plr pos
var is_local := false

func seat(local:=true):
if !is_sitting:
is_sitting=true
is_local=local
if local:
last_plr_pos=XROrigin.global_transform.origin
last_plr_rot=XROrigin.global_rotation

PlayerBody.set_enabled(false)

if has_node("CamPos"):
XROrigin.global_transform.origin=get_node("CamPos").global_transform.origin
XROrigin.global_rotation=get_node("CamPos").global_rotation
return

XROrigin.global_transform.origin=self.global_transform.origin
XROrigin.global_rotation=self.global_rotation
XRServer.center_on_hmd(XRServer.DONT_RESET_ROTATION,true)

@export_range(-1,100) var max_last_pos_exit := 6
func unseat():
if is_sitting:
is_sitting=false
if is_local:
if is_instance_valid(Exit_Node) and Exit_Node!=null and global_transform.origin.distance_to(last_plr_pos)>max_last_pos_exit:
XROrigin.global_transform.origin=Exit_Node.global_transform.origin
XROrigin.global_rotation=Exit_Node.global_rotation
else:
XROrigin.global_transform.origin=last_plr_pos
XROrigin.global_rotation=last_plr_rot
PlayerBody.set_enabled(true)


var last_chair_pos := Vector3.ZERO
var last_chair_rot := Vector3.ZERO
func _process(_delta: float) -> void:
if is_sitting and is_local:
#calc seat pos change
var mov :Vector3= self.global_transform.origin-last_chair_pos
var rot :Vector3= self.global_rotation-last_chair_rot

#Update player position if seat global position changed
if !mov.is_equal_approx(Vector3.ZERO) or !rot.is_equal_approx(Vector3.ZERO):
if has_node("CamPos"):
XROrigin.global_transform=get_node("CamPos").global_transform
else:
XROrigin.global_transform=self.global_transform

#Store current position
last_chair_pos=self.global_transform.origin
last_chair_rot=self.global_rotation
55 changes: 55 additions & 0 deletions scenes/seating_demo/objects/seat.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[gd_scene load_steps=9 format=3 uid="uid://svmpofy8s8r"]

[ext_resource type="Texture2D" uid="uid://bskwc0drdadnd" path="res://assets/wahooney.itch.io/brown_grid.png" id="1_f7fwx"]
[ext_resource type="Script" path="res://scenes/seating_demo/objects/seat.gd" id="1_u35dq"]

[sub_resource type="BoxMesh" id="BoxMesh_gla1c"]
size = Vector3(0.5, 0.75, 0.5)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jmq7o"]
albedo_texture = ExtResource("1_f7fwx")
uv1_world_triplanar = true

[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_62n02"]
points = PackedVector3Array(0.25, 0.37202, 0.25, -0.25, -0.37202, -0.25, 0.25, -0.37202, -0.25, -0.25, -0.37202, 0.25, -0.25, 0.37202, -0.25, 0.25, -0.37202, 0.25, 0.25, 0.37202, -0.25, -0.25, 0.37202, 0.25)

[sub_resource type="BoxMesh" id="BoxMesh_2egd0"]
size = Vector3(0.6, 0.8, 0.05)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_j257r"]
albedo_texture = ExtResource("1_f7fwx")
uv1_world_triplanar = true

[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_j30s0"]
points = PackedVector3Array(0.303175, 0.406349, 0.0321304, -0.306349, -0.406349, -0.0313368, -0.306349, -0.406349, 0.0321304, -0.306349, 0.406349, -0.0313368, 0.303175, -0.406349, -0.0313368, 0.303175, -0.406349, 0.0321304, -0.306349, 0.406349, 0.0321304, 0.303175, 0.406349, -0.0313368)

[node name="Seat" type="StaticBody3D"]
script = ExtResource("1_u35dq")

[node name="Mesh" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.375, 0)
gi_mode = 0
mesh = SubResource("BoxMesh_gla1c")
skeleton = NodePath("")
surface_material_override/0 = SubResource("StandardMaterial3D_jmq7o")

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.375, 0)
shape = SubResource("ConvexPolygonShape3D_62n02")

[node name="Mesh2" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.984808, -0.173648, 0, 0.173648, 0.984808, 0, 1.1, 0.3)
gi_mode = 0
mesh = SubResource("BoxMesh_2egd0")
skeleton = NodePath("")
surface_material_override/0 = SubResource("StandardMaterial3D_j257r")

[node name="CollisionShape3D2" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.984808, -0.173648, 0, 0.173648, 0.984808, 0, 1.1, 0.3)
shape = SubResource("ConvexPolygonShape3D_j30s0")

[node name="Exit" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1)

[node name="CamPos" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.2, 0)
Binary file added scenes/seating_demo/seating 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/seating_demo/seating demo.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dj0fh2ojrqlvp"
path.s3tc="res://.godot/imported/seating demo.png-7ea83273c2f785e4ff2dda2082d3ccab.s3tc.ctex"
path.etc2="res://.godot/imported/seating demo.png-7ea83273c2f785e4ff2dda2082d3ccab.etc2.ctex"
metadata={
"imported_formats": ["s3tc_bptc", "etc2_astc"],
"vram_texture": true
}

[deps]

source_file="res://scenes/seating_demo/seating demo.png"
dest_files=["res://.godot/imported/seating demo.png-7ea83273c2f785e4ff2dda2082d3ccab.s3tc.ctex", "res://.godot/imported/seating demo.png-7ea83273c2f785e4ff2dda2082d3ccab.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
21 changes: 21 additions & 0 deletions scenes/seating_demo/seating_demo.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extends DemoSceneBase

func _seat_button_released(button) -> void:
get_node("Seat").seat()

func _unseat_button_released(button) -> void:
get_node("Seat").unseat()




func _seat2_button_released(button) -> void:
get_node("Seat2").seat()


func _unseat2_button_released(button) -> void:
get_node("Seat2").unseat()


func _seat2_animate_button_released(button) -> void:
get_node("Seat2/AnimationPlayer").play("move")
Loading