Multiple worlds absolutely do work

This commit is contained in:
Vojtěch Struhár 2025-02-27 18:57:27 +01:00
parent da87b39b3d
commit 5012b5f73e
6 changed files with 189 additions and 9 deletions

31
levels/level_hermione.gd Normal file
View File

@ -0,0 +1,31 @@
extends Node
@onready var player: CharacterBody3D = %Player
@onready var outside_world: SubViewport = %OutsideWorld
@onready var inside_world: SubViewport = %InsideWorld
@onready var sub_viewport_container: SubViewportContainer = $SubViewportContainer
var current_world: Node
func _ready() -> void:
current_world = outside_world
func _process(delta: float) -> void:
if Input.is_action_just_pressed("debug_teleport"):
_on_teleport_button_pressed()
func _on_teleport_button_pressed() -> void:
if current_world == outside_world:
outside_world.reparent(self)
inside_world.reparent(sub_viewport_container)
current_world = inside_world
else:
inside_world.reparent(self)
outside_world.reparent(sub_viewport_container)
current_world = outside_world
player.reparent(current_world.get_child(0))

View File

@ -0,0 +1 @@
uid://ca45js46kc0l7

View File

@ -1,7 +1,48 @@
[gd_scene load_steps=2 format=3 uid="uid://dgvdetmbv5jya"]
[gd_scene load_steps=6 format=3 uid="uid://dgvdetmbv5jya"]
[ext_resource type="PackedScene" uid="uid://b5x7fmpwck335" path="res://hud.tscn" id="1_2k7q4"]
[ext_resource type="Script" uid="uid://ca45js46kc0l7" path="res://levels/level_hermione.gd" id="1_gyvwl"]
[ext_resource type="PackedScene" uid="uid://drhaqr78kv1o2" path="res://levels/room_hermione_outside.tscn" id="2_empe6"]
[ext_resource type="PackedScene" uid="uid://ci81nttn6foio" path="res://levels/room_hermione_inside.tscn" id="2_lv1mc"]
[ext_resource type="PackedScene" uid="uid://cgdlowfuuorvi" path="res://player.tscn" id="3_gyvwl"]
[node name="level_hermione" type="Node"]
script = ExtResource("1_gyvwl")
[node name="SubViewportContainer" type="SubViewportContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="OutsideWorld" type="SubViewport" parent="SubViewportContainer"]
unique_name_in_owner = true
handle_input_locally = false
size = Vector2i(1920, 1080)
render_target_update_mode = 4
[node name="OutsideWorldContainer" type="Node3D" parent="SubViewportContainer/OutsideWorld"]
[node name="room_hermione_outside" parent="SubViewportContainer/OutsideWorld/OutsideWorldContainer" instance=ExtResource("2_empe6")]
[node name="Player" parent="SubViewportContainer/OutsideWorld/OutsideWorldContainer" instance=ExtResource("3_gyvwl")]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6.08041, 1.41104, 0)
[node name="HUD" parent="." instance=ExtResource("1_2k7q4")]
[node name="TeleportButton" type="Button" parent="HUD"]
layout_mode = 2
text = "Switch Worlds (T)"
[node name="InsideWorld" type="SubViewport" parent="."]
unique_name_in_owner = true
own_world_3d = true
size = Vector2i(1920, 1080)
[node name="InsideWorldContainer" type="Node3D" parent="InsideWorld"]
[node name="room_hermione_inside" parent="InsideWorld/InsideWorldContainer" instance=ExtResource("2_lv1mc")]
[connection signal="pressed" from="HUD/TeleportButton" to="." method="_on_teleport_button_pressed"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=3 uid="uid://ci81nttn6foio"]
[gd_scene load_steps=21 format=4 uid="uid://ci81nttn6foio"]
[ext_resource type="Material" uid="uid://b7kc8jfs4fowj" path="res://addons/kenney_prototype_tools/materials/green/material_02.tres" id="1_ofsgw"]
[ext_resource type="PackedScene" uid="uid://dve8bvx87r1mm" path="res://models/kenney-house/wall-doorway-square.glb" id="2_4aydi"]
@ -10,8 +10,6 @@
[ext_resource type="PackedScene" uid="uid://d3yk6et3d4yw3" path="res://models/kenney-house/border.glb" id="8_rmadb"]
[ext_resource type="PackedScene" uid="uid://dsogp3m6bedxp" path="res://models/kenney-house/column.glb" id="9_jpxld"]
[ext_resource type="PackedScene" uid="uid://b4mndlgalycyh" path="res://models/kenney-house/roof-flat-center.glb" id="10_5h2gx"]
[ext_resource type="PackedScene" uid="uid://b5x7fmpwck335" path="res://hud.tscn" id="11_r7yoc"]
[ext_resource type="PackedScene" uid="uid://cgdlowfuuorvi" path="res://player.tscn" id="12_sb86j"]
[sub_resource type="BoxShape3D" id="BoxShape3D_w2gbp"]
size = Vector3(40, 1, 40)
@ -20,7 +18,49 @@ size = Vector3(40, 1, 40)
material = ExtResource("1_ofsgw")
size = Vector3(40, 1, 40)
[node name="room_hermione_outside" type="Node3D"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_soise"]
sky_top_color = Color(0.220994, 0.465185, 0.685758, 1)
sky_horizon_color = Color(0.775585, 0.617199, 0.525157, 1)
ground_bottom_color = Color(0.0327392, 0.0238974, 0.0155985, 1)
ground_horizon_color = Color(0.67988, 0.550619, 0.418075, 1)
[sub_resource type="Sky" id="Sky_m1tf4"]
sky_material = SubResource("ProceduralSkyMaterial_soise")
[sub_resource type="Environment" id="Environment_p5xd2"]
background_mode = 2
sky = SubResource("Sky_m1tf4")
tonemap_mode = 1
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_soise"]
albedo_color = Color(1, 0.6, 0.235294, 1)
[sub_resource type="PrismMesh" id="PrismMesh_p5xd2"]
material = SubResource("StandardMaterial3D_soise")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_p5xd2"]
shading_mode = 0
albedo_color = Color(0, 0, 0, 1)
[sub_resource type="ArrayMesh" id="ArrayMesh_km368"]
_surfaces = [{
"aabb": AABB(-0.51069, -0.511952, -0.512309, 1.02138, 1.02626, 1.02462),
"attribute_data": PackedByteArray("q6oqPgAAAABWVVU/AAAAAKuqKj4AAAAAVlVVPwAAAAAAAAAAAAAAP6uqKj8AAAA/q6qqPgAAAD8AAIA/AAAAP6uqqj4AAAAAAAAAAAAAAD+rqio/AAAAAKuqqj4AAAA/q6qqPgAAAD8AAAAAAACAP6uqKj8AAAA/q6qqPgAAgD+rqio/AAAAPwAAgD8AAAA/q6oqPwAAgD8AAIA/AACAPw=="),
"format": 34359742487,
"index_count": 24,
"index_data": PackedByteArray("AgAEAAYAAwAFAAcACAAMAAoACgAMAA4ACQANAAsACwANAA8AEAASABEAEQASABMA"),
"material": SubResource("StandardMaterial3D_p5xd2"),
"name": "Outline",
"primitive": 3,
"uv_scale": Vector4(0, 0, 0, 0),
"vertex_count": 20,
"vertex_data": PackedByteArray("VHXYu/ypAz+xJgM/U3XYu/ypAz+xJgO/VHXYu/ypAz+xJgM/U3XYu/ypAz+xJgO/nLwCv04PA79ODwM/nLwCP04PA79ODwO/nLwCP04PA79ODwM/nLwCv04PA79ODwO/VHXYu/ypAz+xJgM/U3XYu/ypAz+xJgO/U3XYu/ypAz+xJgO/VHXYu/ypAz+xJgM/nLwCP04PA79ODwM/nLwCv04PA79ODwO/nLwCP04PA79ODwO/nLwCv04PA79ODwM/nLwCv04PA79ODwM/nLwCP04PA79ODwM/nLwCv04PA79ODwO/nLwCP04PA79ODwO//3//f////7//////AAD/v/9//3////+//////wAA/7//f/9/////v/////8AAP+//3//f////7//////AAD/v1TVqqr/////qiqqqv9//79U1aqq/////6oqqqr/f/+/VNWqqv////+qKqqq/3//v1TVqqr/////qiqqqv9//78AgAAA////vwCAAAD///+/AIAAAP///78AgAAA////vw==")
}]
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_soise"]
data = PackedVector3Array(0, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0, 0.5, 0.5, 0, 0.5, -0.5, 0.5, -0.5, 0.5, 0, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0, 0.5, -0.5, 0, 0.5, 0.5, -0.5, -0.5, -0.5, 0, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5)
[node name="room_hermione_inside" type="Node3D"]
[node name="StaticBody3D" type="StaticBody3D" parent="."]
@ -460,7 +500,21 @@ transform = Transform3D(1, 0, -1.74846e-07, 0, 1, 0, 1.74846e-07, 0, 1, -1, 5.3,
[node name="roof-flat-center2" parent="House" instance=ExtResource("10_5h2gx")]
transform = Transform3D(5, 0, 0, 0, 1, 0, 0, 0, 5, -6.5, 5.3, 1.5)
[node name="HUD" parent="." instance=ExtResource("11_r7yoc")]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_p5xd2")
[node name="Player" parent="." instance=ExtResource("12_sb86j")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.77486, 1.66069, 0)
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.69407, -0.512887, 0.505188, 0.0341743, 0.724421, 0.68851, -0.719096, -0.46061, 0.520327, 6.21356, 1.32592, -0.575947)
shadow_enabled = true
[node name="Prism" type="MeshInstance3D" parent="."]
transform = Transform3D(0.679275, 0, 0.733884, 0, 1, 0, -0.733884, 0, 0.679275, 6.21356, 1.32592, -0.575947)
mesh = SubResource("PrismMesh_p5xd2")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Prism"]
mesh = SubResource("ArrayMesh_km368")
[node name="StaticBody3D" type="StaticBody3D" parent="Prism"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Prism/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_soise")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=9 format=3 uid="uid://drhaqr78kv1o2"]
[gd_scene load_steps=15 format=4 uid="uid://drhaqr78kv1o2"]
[ext_resource type="Material" uid="uid://b7kc8jfs4fowj" path="res://addons/kenney_prototype_tools/materials/green/material_02.tres" id="1_2frux"]
[ext_resource type="PackedScene" uid="uid://dve8bvx87r1mm" path="res://models/kenney-house/wall-doorway-square.glb" id="2_hytsl"]
@ -6,6 +6,7 @@
[ext_resource type="PackedScene" uid="uid://d3qx51q66eftg" path="res://models/kenney-house/roof-flat-corner.glb" id="4_iniy3"]
[ext_resource type="PackedScene" uid="uid://b0k0k4heruf3t" path="res://models/kenney-house/wall-window-square-detailed.glb" id="5_tbp4y"]
[ext_resource type="PackedScene" uid="uid://d347ojn6kwgn2" path="res://models/kenney-house/floor.glb" id="6_hytsl"]
[ext_resource type="PackedScene" uid="uid://birikia38m0g7" path="res://skybox_world_environment.tscn" id="7_m1tf4"]
[sub_resource type="BoxMesh" id="BoxMesh_blkr4"]
material = ExtResource("1_2frux")
@ -14,6 +15,34 @@ size = Vector3(20, 1, 20)
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_2frux"]
data = PackedVector3Array(-10, 0.5, 10, 10, 0.5, 10, -10, -0.5, 10, 10, 0.5, 10, 10, -0.5, 10, -10, -0.5, 10, 10, 0.5, -10, -10, 0.5, -10, 10, -0.5, -10, -10, 0.5, -10, -10, -0.5, -10, 10, -0.5, -10, 10, 0.5, 10, 10, 0.5, -10, 10, -0.5, 10, 10, 0.5, -10, 10, -0.5, -10, 10, -0.5, 10, -10, 0.5, -10, -10, 0.5, 10, -10, -0.5, -10, -10, 0.5, 10, -10, -0.5, 10, -10, -0.5, -10, 10, 0.5, 10, -10, 0.5, 10, 10, 0.5, -10, -10, 0.5, 10, -10, 0.5, -10, 10, 0.5, -10, -10, -0.5, 10, 10, -0.5, 10, -10, -0.5, -10, 10, -0.5, 10, 10, -0.5, -10, -10, -0.5, -10)
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_m1tf4"]
albedo_color = Color(0.733333, 0.552941, 1, 1)
[sub_resource type="BoxMesh" id="BoxMesh_iniy3"]
material = SubResource("StandardMaterial3D_m1tf4")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_tbp4y"]
shading_mode = 0
albedo_color = Color(0, 0, 0, 1)
[sub_resource type="ArrayMesh" id="ArrayMesh_b8r5k"]
_surfaces = [{
"aabb": AABB(-0.511547, -0.511547, -0.511547, 1.02309, 1.02309, 1.02309),
"attribute_data": PackedByteArray("AAAAAAAAAACrqio/AAAAAKuqqj4AAAAAAACAPwAAAAAAAAAAAAAAP6uqKj8AAAA/q6qqPgAAAD8AAIA/AAAAP6uqqj4AAAAAAAAAAAAAAD+rqio/AAAAAKuqqj4AAAA/q6qqPgAAAD8AAAAAAACAP6uqKj8AAAA/q6qqPgAAgD+rqqo+AAAAP6uqKj8AAAA/q6oqPwAAAD8AAIA/AAAAP6uqqj4AAIA/q6oqPwAAgD+rqio/AACAPwAAgD8AAIA/"),
"format": 34359742487,
"index_count": 36,
"index_data": PackedByteArray("AAAEAAIAAgAEAAYAAQAFAAMAAwAFAAcACAAMAAoACgAMAA4ACQANAAsACwANAA8AEAAUABIAEgAUABYAEQAVABMAEwAVABcA"),
"material": SubResource("StandardMaterial3D_tbp4y"),
"name": "Outline",
"primitive": 3,
"uv_scale": Vector4(0, 0, 0, 0),
"vertex_count": 24,
"vertex_data": PackedByteArray("v/QCv7/0Aj+/9AI/v/QCP7/0Aj+/9AK/v/QCP7/0Aj+/9AI/v/QCv7/0Aj+/9AK/v/QCv7/0Ar+/9AI/v/QCP7/0Ar+/9AK/v/QCP7/0Ar+/9AI/v/QCv7/0Ar+/9AK/v/QCP7/0Aj+/9AI/v/QCv7/0Aj+/9AK/v/QCP7/0Aj+/9AK/v/QCv7/0Aj+/9AI/v/QCP7/0Ar+/9AI/v/QCv7/0Ar+/9AK/v/QCP7/0Ar+/9AK/v/QCv7/0Ar+/9AI/v/QCP7/0Aj+/9AI/v/QCv7/0Ar+/9AI/v/QCv7/0Aj+/9AI/v/QCP7/0Ar+/9AI/v/QCP7/0Aj+/9AK/v/QCv7/0Ar+/9AK/v/QCv7/0Aj+/9AK/v/QCP7/0Ar+/9AK//3//f////7//////AAD/v/9//3////+//////wAA/7//f/9/////v/////8AAP+//3//f////7//////AAD/v///AID/////AAAAgP9//7///wCA/////wAAAID/f/+///8AgP////8AAACA/3//v///AID/////AAAAgP9//78AgP//AAD/vwCAAAD///+/AID//wAA/78AgAAA////vwCA//8AAP+/AIAAAP///78AgP//AAD/vwCAAAD///+/")
}]
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_m1tf4"]
data = PackedVector3Array(-0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5)
[node name="room_hermione_outside" type="Node3D"]
[node name="Ground" type="MeshInstance3D" parent="."]
@ -74,3 +103,22 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0.5, 0.5)
[node name="floor5" parent="." instance=ExtResource("6_hytsl")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0.5, 2.5)
[node name="WorldEnvironment2" parent="." instance=ExtResource("7_m1tf4")]
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.999197, -0.0103569, -0.0386982, 0.0341743, 0.724421, 0.68851, 0.0209029, -0.68928, 0.724194, 0, 0, 0)
shadow_enabled = true
[node name="Cube" type="MeshInstance3D" parent="."]
transform = Transform3D(0.823869, 0, 0.56678, 0, 1, 0, -0.56678, 0, 0.823869, 6.09669, 1.73711, 3.18691)
mesh = SubResource("BoxMesh_iniy3")
metadata/_edit_group_ = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="Cube"]
mesh = SubResource("ArrayMesh_b8r5k")
[node name="StaticBody3D" type="StaticBody3D" parent="Cube"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="Cube/StaticBody3D"]
shape = SubResource("ConcavePolygonShape3D_m1tf4")

View File

@ -52,6 +52,11 @@ move_back={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
]
}
debug_teleport={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":84,"key_label":0,"unicode":116,"location":0,"echo":false,"script":null)
]
}
[layer_names]