Compare commits

12 Commits

Author SHA1 Message Date
ce7b74c832 Networking 2023-01-17 22:30:12 +01:00
9893bc45b4 fully sync player movements over network 2023-01-17 13:54:26 +01:00
1ef5d54d6c start Multiplayer 2023-01-15 23:59:12 +01:00
5cfc0839f7 add entity collision option 2023-01-03 23:43:30 +01:00
2e4c378991 small fix 2023-01-03 23:29:55 +01:00
40d73f2590 improve runtimeloader for glb files 2023-01-03 23:28:43 +01:00
a7118b3d77 update scoom data 2023-01-03 23:18:52 +01:00
b2b82271f7 fix weapon draw bug 2023-01-03 23:16:05 +01:00
b5286a5f54 extend PCK support 2023-01-03 01:00:11 +01:00
4c8499f4f0 add Scoom-Data submodule 2023-01-02 22:10:27 +01:00
5a891a5636 delete unwanted files 2023-01-02 22:07:30 +01:00
701bcfd39c PCK File loader 2023-01-02 17:55:28 +01:00
36 changed files with 722 additions and 427 deletions

34
.exr.import Normal file
View File

@@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bpsjhyhlis3ov"
path="res://.godot/imported/.exr-a7725c7e971a9679cf60303f5fa7defa.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://.exr"
dest_files=["res://.godot/imported/.exr-a7725c7e971a9679cf60303f5fa7defa.ctex"]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
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=1

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "scoom"]
path = scoom
url = ssh://git@git.peroxy.dev:222/kookroach/Scoom-Data.git

30
Game.gd
View File

@@ -1,19 +1,30 @@
extends Node3D
class_name Game
signal game_loaded
@onready var label : Label = $CanvasLayer/Label
@onready var player : CharacterBody3D = $PlayerQ3
var init_config
var weapon_config
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
Runtimeloader.load_gltf("maps/Map.glb", true, true)
weapon_config = Runtimeloader.loadConfig("weapons.cfg") as ConfigFile
init_config = Runtimeloader.loadConfig("init.cfg") as ConfigFile
print("Loading PCK...")
for map_list in init_config.get_section_keys("MAPS"):
for map in init_config.get_value("MAPS", map_list):
Runtimeloader.loadPCK(map)
func _process(_delta):
label.text = "H Velocity: %3.2f" % [Vector2(player.velocity.x, player.velocity.z).length()]
label.text += "\nV Velocity: %3.2f" % [player.velocity.y]
label.text += "\nOn floor: %s" % player.is_on_floor()
for weapons_list in init_config.get_section_keys("WEAPONS"):
for weapon in init_config.get_value("WEAPONS", weapons_list):
Runtimeloader.loadPCK(weapon)
print("Loading Resources Done.")
func load_map():
Runtimeloader.loadScene("maps/test_map.tscn", self)
#Runtimeloader.get_all_entities(node)
game_loaded.emit()
func _input(event):
@@ -25,3 +36,4 @@ func _input(event):
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
elif event.keycode == KEY_ESCAPE:
get_tree().quit()

View File

@@ -1,6 +1,9 @@
shader_type spatial;
render_mode cull_back;
uniform float z_offset : hint_range(-1, 1);
void fragment() {
// Place fragment code here.
// write the final depth value to the depth buffer
DEPTH = 0.9;
}

14
assets/shader/test.tscn Normal file
View File

@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://tojfiub8y1f6"]
[ext_resource type="Shader" path="res://assets/shader/no_depth.gdshader" id="2_lklwv"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_5pubw"]
render_priority = 0
shader = ExtResource("2_lklwv")
shader_parameter/z_offset = null
[node name="Chainsaw_test"]
[node name="Cube014" parent="." index="0"]
material_override = SubResource("ShaderMaterial_5pubw")
transparency = 0.02

View File

@@ -1,12 +1,20 @@
[gd_scene load_steps=6 format=3 uid="uid://bl7jynld7s25o"]
[gd_scene load_steps=11 format=3 uid="uid://bl7jynld7s25o"]
[ext_resource type="Script" path="res://scripts/player/PlayerQ3.gd" id="1"]
[ext_resource type="Script" path="res://scripts/player/Weapons.gd" id="2_dl1i1"]
[ext_resource type="Texture2D" uid="uid://17b1nu8spjfi" path="res://textures/icon.png" id="2_mxb5i"]
[ext_resource type="Shader" path="res://assets/shader/crosshair.gdshader" id="3_3vnqi"]
[ext_resource type="Script" path="res://entities/PlayerSync.gd" id="5_828co"]
[sub_resource type="CylinderShape3D" id="1"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_6d8kk"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mqdp4"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ikq67"]
albedo_texture = ExtResource("2_mxb5i")
uv1_scale = Vector3(3, 2, 1)
[sub_resource type="CylinderMesh" id="CylinderMesh_4e7dm"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_08bwh"]
shader = ExtResource("3_3vnqi")
shader_parameter/center_enabled = null
shader_parameter/legs_enabled = null
@@ -21,15 +29,38 @@ shader_parameter/len = null
shader_parameter/spacing = null
shader_parameter/spread = null
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_rfdcv"]
properties/0/path = NodePath("Body/Head:rotation")
properties/0/spawn = true
properties/0/sync = true
properties/1/path = NodePath("Body:rotation")
properties/1/spawn = true
properties/1/sync = true
properties/2/path = NodePath("Networking:player_state")
properties/2/spawn = false
properties/2/sync = true
properties/3/path = NodePath("Networking:sync_position")
properties/3/spawn = true
properties/3/sync = false
properties/4/path = NodePath("Networking:sync_velocity")
properties/4/spawn = true
properties/4/sync = false
[node name="PlayerQ3" type="CharacterBody3D"]
script = ExtResource("1")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("1")
shape = SubResource("CylinderShape3D_6d8kk")
[node name="Body" type="Node3D" parent="."]
[node name="MeshInstance3D" type="MeshInstance3D" parent="Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
material_override = SubResource("StandardMaterial3D_ikq67")
mesh = SubResource("CylinderMesh_4e7dm")
skeleton = NodePath("../../CollisionShape3D")
[node name="Head" type="Node3D" parent="Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0)
@@ -37,12 +68,14 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0)
script = ExtResource("2_dl1i1")
[node name="Crosshair" type="ColorRect" parent="Body/Head/Hand"]
material = SubResource("ShaderMaterial_mqdp4")
material = SubResource("ShaderMaterial_08bwh")
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="Camera3D" type="Camera3D" parent="Body/Head"]
cull_mask = 1048573
@@ -51,3 +84,17 @@ current = true
[node name="AimCast" type="RayCast3D" parent="Body/Head/Camera3D"]
target_position = Vector3(0, 0, -1)
collision_mask = 512
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="Label" type="Label" parent="CanvasLayer"]
offset_right = 40.0
offset_bottom = 14.0
metadata/_edit_use_anchors_ = true
[node name="Networking" type="Node" parent="."]
script = ExtResource("5_828co")
[node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="Networking"]
root_path = NodePath("../..")
replication_config = SubResource("SceneReplicationConfig_rfdcv")

31
entities/PlayerSync.gd Normal file
View File

@@ -0,0 +1,31 @@
extends Node
###SYNC PLAYER###
const PLAYER_STATE_SIZE = 13
var player_state:
get:
var buf = PackedByteArray()
buf.resize(PLAYER_STATE_SIZE)
buf.encode_half(0, sync_position.x)
buf.encode_half(2, sync_position.y)
buf.encode_half(4, sync_position.z)
buf.encode_half(6, sync_velocity.x)
buf.encode_half(8, sync_velocity.y)
buf.encode_half(10, sync_velocity.z)
return buf
set(value):
assert(typeof(value) == TYPE_PACKED_BYTE_ARRAY and value.size() == PLAYER_STATE_SIZE,
"Invalid `player_state` array type or size (must be TYPE_PACKED_BYTE_ARRAY of size 11).")
sync_position = Vector3(value.decode_half(0), value.decode_half(2), value.decode_half(4))
sync_velocity = Vector3(value.decode_half(6), value.decode_half(8), value.decode_half(10))
var sync_position : Vector3:
set(value):
sync_position = value
processed_position = false
var sync_velocity : Vector3
var sync_is_jumping : bool
var processed_position : bool

BIN
entities/Weapon.scn Normal file

Binary file not shown.

View File

@@ -9,6 +9,11 @@
config_version=5
_global_script_classes=[{
"base": "Node3D",
"class": &"Game",
"language": &"GDScript",
"path": "res://Game.gd"
}, {
"base": "Node",
"class": &"Hitable",
"language": &"GDScript",
@@ -25,6 +30,7 @@ _global_script_classes=[{
"path": "res://scripts/player/Weapon.gd"
}]
_global_script_class_icons={
"Game": "",
"Hitable": "",
"TBPlugin": "",
"Weapon": ""
@@ -40,6 +46,7 @@ config/icon="res://textures/icon.png"
[autoload]
Runtimeloader="*res://scripts/utils/runtimeloader.gd"
Network="*res://scripts/utils/network.gd"
[display]

57
scenes/GUI/MAIN.tscn Normal file
View File

@@ -0,0 +1,57 @@
[gd_scene load_steps=2 format=3 uid="uid://3o430r2kys4k"]
[ext_resource type="Script" path="res://scenes/GUI/main.gd" id="1_i8nr4"]
[node name="MAIN" type="Control"]
layout_mode = 3
anchors_preset = 0
script = ExtResource("1_i8nr4")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -198.0
offset_top = -104.0
offset_right = 199.0
offset_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 2
[node name="Start" type="Button" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Start Game"
[node name="ModsMenu" type="MenuButton" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Select Mod"
flat = false
item_count = 2
popup/item_0/text = "test1"
popup/item_0/id = 0
popup/item_1/text = "test2"
popup/item_1/id = 1
[node name="VBoxContainer2" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 10
[node name="SettingsButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Game Settings"
icon_alignment = 1
[node name="ExitButton" type="Button" parent="VBoxContainer/VBoxContainer2"]
layout_mode = 2
text = "Exit"
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Start" to="." method="_on_start_pressed"]

26
scenes/GUI/Main Menu.tscn Normal file
View File

@@ -0,0 +1,26 @@
[gd_scene load_steps=4 format=3 uid="uid://dsnlwjofq6psf"]
[ext_resource type="Script" path="res://scenes/GUI/MainMenu.gd" id="1_23sw7"]
[ext_resource type="PackedScene" uid="uid://3o430r2kys4k" path="res://scenes/GUI/MAIN.tscn" id="1_sojs8"]
[ext_resource type="PackedScene" uid="uid://d0kkhtesg83g" path="res://scenes/GUI/START_GAME.tscn" id="2_ipoll"]
[node name="Main Menu" type="Control"]
layout_mode = 3
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_23sw7")
metadata/_edit_use_anchors_ = true
[node name="MAIN" parent="." instance=ExtResource("1_sojs8")]
[node name="START GAME" parent="." instance=ExtResource("2_ipoll")]
visible = false
[connection signal="start_game" from="MAIN" to="." method="_on_main_start_game"]
[connection signal="back" from="START GAME" to="." method="_on_start_game_back"]
[connection signal="start_game" from="START GAME" to="." method="_on_start_game_start_game"]

25
scenes/GUI/MainMenu.gd Normal file
View File

@@ -0,0 +1,25 @@
extends Control
@onready var game = get_tree().get_current_scene() as Game
@onready var previous = $MAIN
@onready var current = $MAIN
func _on_main_start_game():
previous = current
current = $"START GAME"
$"START GAME".show()
func back():
current.hide()
previous.show()
var tmp = current
current = previous
previous = tmp
func _on_start_game_start_game():
game.load_map()
self.hide()
func _on_start_game_back():
previous = $MAIN
back()

View File

@@ -0,0 +1,62 @@
[gd_scene load_steps=2 format=3 uid="uid://d0kkhtesg83g"]
[ext_resource type="Script" path="res://scenes/GUI/start_game.gd" id="1_amknd"]
[node name="START GAME" type="Control"]
layout_mode = 3
anchors_preset = 0
script = ExtResource("1_amknd")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -198.0
offset_top = -104.0
offset_right = 199.0
offset_bottom = 64.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
metadata/_edit_use_anchors_ = true
[node name="HostContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 2
[node name="HostButton" type="Button" parent="VBoxContainer/HostContainer"]
layout_mode = 2
text = "Host"
[node name="JoinContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_vertical = 2
[node name="IPAdress" type="TextEdit" parent="VBoxContainer/JoinContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_font_sizes/font_size = 13
placeholder_text = "localhost"
[node name="JoinButton" type="Button" parent="VBoxContainer/JoinContainer"]
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 0
text = "Join
"
[node name="BackContainer" type="VBoxContainer" parent="VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 4
[node name="BackButton" type="Button" parent="VBoxContainer/BackContainer"]
layout_mode = 2
text = "Back"
[connection signal="pressed" from="VBoxContainer/HostContainer/HostButton" to="." method="_on_host_button_pressed"]
[connection signal="pressed" from="VBoxContainer/JoinContainer/JoinButton" to="." method="_on_join_button_pressed"]
[connection signal="pressed" from="VBoxContainer/BackContainer/BackButton" to="." method="_on_back_button_pressed"]

7
scenes/GUI/main.gd Normal file
View File

@@ -0,0 +1,7 @@
extends Control
signal start_game;
func _on_start_pressed():
start_game.emit()
hide()

27
scenes/GUI/start_game.gd Normal file
View File

@@ -0,0 +1,27 @@
extends Control
@onready var IPAdress_Field = $VBoxContainer/JoinContainer/IPAdress as TextEdit
signal start_game
signal back
func _on_join_button_pressed():
if not try_connection():
return
Network.start_network(false, IPAdress_Field.text)
start_game.emit()
func try_connection():
if IPAdress_Field.text.is_empty():
return false
return true
func _on_host_button_pressed():
Network.start_network(true)
start_game.emit()
func _on_back_button_pressed():
hide()
back.emit()

View File

@@ -0,0 +1,5 @@
extends MultiplayerSpawner
func _spawn_custom(data):
return

View File

@@ -1,8 +1,7 @@
[gd_scene load_steps=7 format=3 uid="uid://8g7w4uv2xsck"]
[gd_scene load_steps=6 format=3 uid="uid://8g7w4uv2xsck"]
[ext_resource type="Script" path="res://Game.gd" id="1_71dcv"]
[ext_resource type="PackedScene" uid="uid://bp5ekvan8qsmc" path="res://entities/enemy/dummy.tscn" id="2_13e86"]
[ext_resource type="PackedScene" uid="uid://bl7jynld7s25o" path="res://entities/Player.tscn" id="3_ngdfc"]
[ext_resource type="PackedScene" uid="uid://dsnlwjofq6psf" path="res://scenes/GUI/Main Menu.tscn" id="2_448f8"]
[sub_resource type="PhysicalSkyMaterial" id="PhysicalSkyMaterial_2n8qo"]
@@ -31,15 +30,10 @@ shadow_enabled = true
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_oqaam")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="Main Menu" parent="." instance=ExtResource("2_448f8")]
[node name="Label" type="Label" parent="CanvasLayer"]
offset_right = 40.0
offset_bottom = 14.0
metadata/_edit_use_anchors_ = true
[node name="Networking" type="Node" parent="."]
[node name="Enemy" parent="." instance=ExtResource("2_13e86")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 23.8087, 0.346554, -28.3203)
[node name="PlayerQ3" parent="." instance=ExtResource("3_ngdfc")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 3.52828, 2.64918, -22.0849)
[node name="PlayerSpawner" type="MultiplayerSpawner" parent="Networking"]
_spawnable_scenes = PackedStringArray("res://entities/Player.tscn")
spawn_path = NodePath("..")

View File

@@ -1,21 +1,22 @@
[gd_scene load_steps=11 format=3 uid="uid://bq7p576e7a17i"]
[gd_scene load_steps=12 format=3 uid="uid://bq7p576e7a17i"]
[ext_resource type="Texture2D" uid="uid://bx4pdgghucl4k" path="res://textures/concrete_15.jpg" id="3_0q1g3"]
[ext_resource type="Texture2D" uid="uid://bj2qm3joiywso" path="res://textures/dark.png" id="4_mcb4j"]
[ext_resource type="Texture2D" uid="uid://bt671xkej3a2s" path="res://textures/shipping_container_01_side.jpg" id="5_wj0e7"]
[ext_resource type="Texture2D" uid="uid://c52qu6ad3taix" path="res://textures/shipping_container_01_front.jpg" id="6_g7sga"]
[ext_resource type="Texture2D" uid="uid://bx4pdgghucl4k" path="res://textures/concrete_15.jpg" id="1_37wdm"]
[ext_resource type="Texture2D" uid="uid://bj2qm3joiywso" path="res://textures/dark.png" id="2_f8syx"]
[ext_resource type="Texture2D" uid="uid://bt671xkej3a2s" path="res://textures/shipping_container_01_side.jpg" id="3_vf5qg"]
[ext_resource type="Texture2D" uid="uid://c52qu6ad3taix" path="res://textures/shipping_container_01_front.jpg" id="4_70w0l"]
[ext_resource type="PackedScene" uid="uid://bp5ekvan8qsmc" path="res://entities/enemy/dummy.tscn" id="5_1x24o"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_yhpph"]
albedo_texture = ExtResource("3_0q1g3")
albedo_texture = ExtResource("1_37wdm")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_plg37"]
albedo_texture = ExtResource("4_mcb4j")
albedo_texture = ExtResource("2_f8syx")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8xybu"]
albedo_texture = ExtResource("5_wj0e7")
albedo_texture = ExtResource("3_vf5qg")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_rri1d"]
albedo_texture = ExtResource("6_g7sga")
albedo_texture = ExtResource("4_70w0l")
[sub_resource type="ArrayMesh" id="ArrayMesh_bdgr3"]
lightmap_size_hint = Vector2i(2802, 2814)
@@ -67,10 +68,16 @@ data = PackedVector3Array(-31.1636, -2.5938, -36.3203, -31.1636, -4.5938, -36.32
[node name="Map" type="Node3D"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 22.8341, -0.0932, -2.1058)
[node name="entity_0_geometry" type="MeshInstance3D" parent="."]
[node name="0_geometry" type="MeshInstance3D" parent="."]
mesh = SubResource("ArrayMesh_bdgr3")
[node name="entity_0_geometry_col" type="StaticBody3D" parent="."]
[node name="0_geometry_col" type="StaticBody3D" parent="."]
[node name="CollisionShape3D" type="CollisionShape3D" parent="entity_0_geometry_col"]
[node name="CollisionShape3D" type="CollisionShape3D" parent="0_geometry_col"]
shape = SubResource("ConcavePolygonShape3D_2ub2n")
[node name="entity_test" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -11.7493, -0.748922, -3.17036)
[node name="Enemy" parent="." instance=ExtResource("5_1x24o")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.47822, -2.5938, -7.02456)

1
scoom Submodule

Submodule scoom added at 81bf2c532a

View File

@@ -1,5 +0,0 @@
[entity_test]
model="models/Chainsaw.glb"
type="pickup"
scale=1.5

Binary file not shown.

View File

@@ -1,30 +0,0 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://dll7swpo3b8o3"
path="res://.godot/imported/Map.glb-2d6fdb0ff78945164666e9514502f2ad.scn"
[deps]
source_file="res://scoom/maps/Map.glb"
dest_files=["res://.godot/imported/Map.glb-2d6fdb0ff78945164666e9514502f2ad.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
import_script/path=""
_subresources={}

Binary file not shown.

View File

@@ -1,30 +0,0 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://66n2a8aqv58t"
path="res://.godot/imported/Chainsaw.glb-c08aa7bf55e47ba09148044ca4ad23d8.scn"
[deps]
source_file="res://scoom/models/Chainsaw.glb"
dest_files=["res://.godot/imported/Chainsaw.glb-c08aa7bf55e47ba09148044ca4ad23d8.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
import_script/path=""
_subresources={}

Binary file not shown.

View File

@@ -1,30 +0,0 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://cgs12i70gkdwd"
path="res://.godot/imported/Revolver.glb-ddad34c191d08664fd8bf25eed817ec8.scn"
[deps]
source_file="res://scoom/models/Revolver.glb"
dest_files=["res://.godot/imported/Revolver.glb-ddad34c191d08664fd8bf25eed817ec8.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
import_script/path=""
_subresources={}

Binary file not shown.

View File

@@ -1,30 +0,0 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://bjhvrtd86fadx"
path="res://.godot/imported/Uzi.glb-6a3fe279c43b5f5a4fab57615a8f66b3.scn"
[deps]
source_file="res://scoom/models/Uzi.glb"
dest_files=["res://.godot/imported/Uzi.glb-6a3fe279c43b5f5a4fab57615a8f66b3.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
import_script/path=""
_subresources={}

Binary file not shown.

View File

@@ -1,30 +0,0 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://bbio7jgrrlluc"
path="res://.godot/imported/runtime_loader_test.glb-579d9bb609ead0ddc6264feb2468757b.scn"
[deps]
source_file="res://scoom/models/runtime_loader_test.glb"
dest_files=["res://.godot/imported/runtime_loader_test.glb-579d9bb609ead0ddc6264feb2468757b.scn"]
[params]
nodes/root_type="Node3D"
nodes/root_name="Scene Root"
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
import_script/path=""
_subresources={}

View File

@@ -1,74 +0,0 @@
[REVOLVER]
;Model data
HAND_POS=Vector3(0.4,-0.45,-1.0) ;Initial Position of the weapon
HAND_ROT=Vector3(0,3.14159265359,0) ;Initial Rotation of the weapon in Radians
MODEL="models/Revolver.glb" ;Model file
;Weapon data
MELEE=0 ;is weapon mele 0 = false, 1 = true
MAX_CLIP=5 ;Max clip capacity
DAMAGE=45 ;Weapon damage
RPM=120 ;Fire rate
FIREMODE=0 ;is firemode automatic 0 = false, 1 = true
HITSCAN=true ;Hit registry mode 1 = Hitscan, 0 = Projectile
RAY_LEN=1000 ;Hitscan ray length
;Animation data
MOMENTUM=Vector2(0.3, -0.25)
ANGULAR_MOMENTUM=Vector3(-60, 7, 10)
RECOIL_COOLDOWN=0.35
RELOAD_MOMENTUM=Vector3(-5, -9, 7)
RELOAD_ANGULAR_MOMENTUM=Vector3(10.472, -13.9626, -17.4533)
RELOAD_TIME=0.35
DRAW_POS=Vector3(0,-0.5,-0.3)
DRAW_ROT=Vector3(1.3, 0, 0)
[UZI]
;Model data
HAND_POS=Vector3(0.4,-0.45,-1.0)
HAND_ROT=Vector3(0,3.14159265359,0)
MODEL="models/Uzi.glb"
;Weapon data
MELEE=0
MAX_CLIP=30
DAMAGE=10
RPM=600
FIREMODE=1
HITSCAN=true
RAY_LEN=1000
;Animation data
MOMENTUM=Vector2(0.05, -0.15)
ANGULAR_MOMENTUM=Vector3(-4, 1, 2)
RECOIL_COOLDOWN=0.35
RELOAD_MOMENTUM=Vector3(-7, -9, 7)
RELOAD_ANGULAR_MOMENTUM=Vector3(10.472, -13.9626, -17.4533)
RELOAD_TIME=0.35
DRAW_POS=Vector3(0,-0.5,-0.3)
DRAW_ROT=Vector3(1.3, 0, 0)
[CHAINSAW]
;Model data
HAND_POS=Vector3(0.4,-0.45,-1)
HAND_ROT=Vector3(-15,0.261799,3.14159265359)
MODEL="models/Chainsaw.glb"
;Weapon data
MELEE=1
MAX_CLIP=1
DAMAGE=2
RPM=3000
FIREMODE=1
HITSCAN=true
RAY_LEN=2
;Animation data
MOMENTUM=Vector2(0.05, -0.05)
ANGULAR_MOMENTUM=Vector3(15, 1, 2)
RECOIL_COOLDOWN=0.35
RELOAD_MOMENTUM=Vector3(-7, -9, 7)
RELOAD_ANGULAR_MOMENTUM=Vector3(10.472, -13.9626, -17.4533)
RELOAD_TIME=0.35
DRAW_POS=Vector3(0,-0.5,-0.3)
DRAW_ROT=Vector3(1.3, 0, 0)

View File

@@ -2,6 +2,9 @@ extends CharacterBody3D
const DIST_FLOOR_SNAP := Vector3.DOWN * 0.2
@onready var label : Label = $CanvasLayer/Label
@onready var networking = $Networking
@onready var body : Node3D = $Body
@onready var head : Node3D = $Body/Head
@onready var cam : Camera3D = $Body/Head/Camera3D
@@ -26,9 +29,27 @@ const DIST_FLOOR_SNAP := Vector3.DOWN * 0.2
var floor_snap := Vector3.ZERO
func _enter_tree():
$Networking/MultiplayerSynchronizer.set_multiplayer_authority(str(name).to_int())
$Body/Head/Camera3D.current = is_local_authority()
if is_local_authority():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func init():
$Body/Head/Hand.set_weapons()
func is_local_authority():
return $Networking/MultiplayerSynchronizer.get_multiplayer_authority() == multiplayer.get_unique_id()
func _process(_delta):
if not is_local_authority():
return
label.text = "H Velocity: %3.2f" % [Vector2(velocity.x, velocity.z).length()]
label.text += "\nV Velocity: %3.2f" % [velocity.y]
label.text += "\nOn floor: %s" % is_on_floor()
label.text += "\nNetwork ID: %d" % multiplayer.get_unique_id()
func get_move_direction() -> Vector3:
var input_dir := Vector2(
Input.get_action_strength("move_backward") - Input.get_action_strength("move_forward"),
Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
@@ -36,18 +57,24 @@ func get_move_direction() -> Vector3:
return input_dir.x * body.global_transform.basis.z + input_dir.y * body.global_transform.basis.x
func _input(event):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and event is InputEventMouseMotion:
rotate_look(event.relative * 0.001 * mouse_sensitivity)
if is_local_authority():
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED and event is InputEventMouseMotion:
rotate_look(event.relative * 0.001 * mouse_sensitivity)
func rotate_look(amount : Vector2) -> void:
body.rotation.y -= amount.x
head.rotation.x = clamp(head.rotation.x - amount.y, -PI * 0.5, PI * 0.5)
func _physics_process(delta):
if !is_local_authority():
if not networking.processed_position:
position = networking.sync_position
networking.processed_position = true
velocity = networking.sync_velocity
move_and_slide()
return
var was_on_floor : bool = is_on_floor()
var h_target_dir : Vector3 = get_move_direction()
@@ -79,6 +106,8 @@ func _physics_process(delta):
elif was_on_floor and !is_on_floor():
floor_snap = Vector3.ZERO
networking.sync_position = position
networking.sync_velocity = velocity
func accelerate(delta : float, p_target_dir : Vector3, p_target_speed : float, p_accel : float):
var current_speed : float = velocity.dot(p_target_dir)
@@ -87,10 +116,9 @@ func accelerate(delta : float, p_target_dir : Vector3, p_target_speed : float, p
var accel_speed : float = min(add_speed, p_accel * delta * p_target_speed)
velocity += p_target_dir * accel_speed
func apply_friction(delta : float):
var vec : Vector3 = velocity
#var vec : Vector3 = velocity
var speed : float = velocity.length()
if is_zero_approx(speed):
velocity = Vector3.ZERO

View File

@@ -29,55 +29,68 @@ var SHOOTING_SPEED: float
var can_shoot : bool
var clip : int
var state = DEFAULT
var tween : Tween
func stop_tween():
if(tween.is_running()):
tween.stop()
func init():
visible = true
state = DEFAULT
SHOOTING_SPEED = 60.0 / RPM
var tween = create_tween()
if(tween != null && tween.is_running()):
tween.stop()
MODEL.position = DRAW_POS
MODEL.rotation = DRAW_ROT
can_shoot = true
tween.tween_callback(InitialPos).set_delay(DRAW_TIME)
InitialPos(DRAW_TIME, DRAW_TIME)
func InitialPos():
var tween = create_tween()
func InitialPos(draw_time, ready_time):
tween = create_tween()
tween.set_trans(Tween.TRANS_QUAD)
tween.set_parallel(true)
tween.tween_property(MODEL, "position", Vector3.ZERO, RECOIL_COOLDOWN / 2)
tween.tween_property(MODEL, "rotation", Vector3.ZERO, RECOIL_COOLDOWN / 2)
tween.tween_callback(func(): state = INITIAL).set_delay(SHOOTING_SPEED / 2)
tween.tween_property(MODEL, "position", Vector3.ZERO, draw_time)
tween.tween_property(MODEL, "rotation", Vector3.ZERO, draw_time)
tween.tween_callback(func(): state = INITIAL).set_delay(ready_time)
@rpc
func Shoot():
if CanShoot():
if not FIREMODE:
can_shoot = false
if not MELEE:
clip -= 1
state = SHOOT;
var tween = create_tween()
tween.set_trans(Tween.TRANS_ELASTIC)
tween.set_ease(Tween.EASE_OUT)
tween.set_parallel(true)
tween.tween_property(MODEL, "position", Vector3(.0, MOMENTUM.x, MOMENTUM.y), RECOIL_COOLDOWN / 2)
var rand_rot_y = randi_range(-ANGULAR_MOMENTUM.y,ANGULAR_MOMENTUM.y)
var rand_rot_z = randi_range(-ANGULAR_MOMENTUM.z,ANGULAR_MOMENTUM.z)
tween.tween_property(MODEL, "rotation", Vector3(deg_to_rad(ANGULAR_MOMENTUM.x),deg_to_rad(rand_rot_y),deg_to_rad(rand_rot_z)),RECOIL_COOLDOWN /2)
tween.tween_callback(InitialPos).set_delay(SHOOTING_SPEED / 2)
rpc("rpc_AnimShoot")
return true
return false
@rpc(call_local, any_peer)
func rpc_AnimShoot():
state = SHOOT;
tween = create_tween()
tween.set_trans(Tween.TRANS_ELASTIC)
tween.set_ease(Tween.EASE_OUT)
tween.set_parallel(true)
tween.tween_property(MODEL, "position", Vector3(.0, MOMENTUM.x, MOMENTUM.y), RECOIL_COOLDOWN / 2)
var rand_rot_y = randf_range(-ANGULAR_MOMENTUM.y,ANGULAR_MOMENTUM.y)
var rand_rot_z = randf_range(-ANGULAR_MOMENTUM.z,ANGULAR_MOMENTUM.z)
tween.tween_property(MODEL, "rotation", Vector3(deg_to_rad(ANGULAR_MOMENTUM.x),deg_to_rad(rand_rot_y),deg_to_rad(rand_rot_z)),RECOIL_COOLDOWN /2)
tween.tween_callback(func(): InitialPos(RECOIL_COOLDOWN / 2, SHOOTING_SPEED / 2)).set_delay(SHOOTING_SPEED / 2)
func CanShoot():
return clip > 0 && state == INITIAL && can_shoot
@rpc
func Release():
rpc("rpc_Release")
@rpc(call_local, any_peer)
func rpc_Release():
if !FIREMODE:
can_shoot = true
@@ -85,7 +98,7 @@ func Release():
func Reload():
if(clip < MAX_CLIP && state == INITIAL):
state = RELOAD
var tween = create_tween()
tween = create_tween()
tween.set_trans(Tween.TRANS_CIRC)
tween.set_ease(Tween.EASE_IN)
tween.set_parallel(true)

View File

@@ -1,50 +1,156 @@
extends Node3D
const CONFIG_PATH = "weapons.cfg"
const REVOLVER = 0
const UZI = 1
const CHAINSAW = 2
const WEAPON_SCENE = preload("res://entities/Weapon.scn")
var state = 0
@onready var player_root = get_node("../../../../PlayerQ3") as CharacterBody3D
@onready var player_root = get_node("../../..")
@onready var raycast = get_node("../Camera3D/AimCast") as RayCast3D
#@onready var crosshair = $Crosshair
var ALL_WEAPONS = []
var weapons = []
var current_weapon = 0
var current_weapon_index = 0
var current_weapon = null
var mouse_mov : Vector3
var sway_lerp = 5
@onready var game = get_node("/root/Game") as Game
func _ready():
var config = load_data() as ConfigFile
Init_Config(config)
Init_Config(game.weapon_config)
if not player_root.is_local_authority():
for w_name in game.init_config.get_value("PLAYER", "starting_weapons"):
GiveWeapon(w_name)
weapons[current_weapon].init()
raycast.target_position.z = -weapons[current_weapon].RAY_LEN
func set_weapons():
for w_name in game.init_config.get_value("PLAYER", "starting_weapons"):
rpc("GiveWeapon",w_name)
func load_data():
var path = Runtimeloader.PATH
@rpc(call_local, any_peer)
func GiveWeapon(weapon_name):
for i in ALL_WEAPONS.size():
if(ALL_WEAPONS[i].name != weapon_name):
continue
if(weapons.has(i)):
return
var config = ConfigFile.new()
var err = config.load(path + CONFIG_PATH)
weapons.append(i)
if(current_weapon == null):
rpc("ChangeWeapon", ((posmod(current_weapon_index, weapons.size()))))
return
if err != OK:
printerr("FAILED LOADING WEAPONS DATA @ ",path + CONFIG_PATH)
@rpc(call_local, any_peer)
func TakeWeapon(weapon_name):
for i in ALL_WEAPONS.size():
if(ALL_WEAPONS[i].name != weapon_name):
continue
weapons.erase(i)
if(current_weapon == ALL_WEAPONS[i]):
rpc("ChangeWeapon", ((posmod(current_weapon_index, weapons.size()))))
func _input(event):
if not player_root.is_local_authority():
return
if event is InputEventMouseMotion:
mouse_mov.y = clampf(-event.relative.x, -0.1, 0.1)
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
if event is InputEventKey and event.is_pressed():
if event.keycode == KEY_T:
rpc("GiveWeapon","CHAINSAW")
func _unhandled_input(_event):
if not player_root.is_local_authority():
return
if(weapons.size() == 0):
return
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
rpc("ChangeWeapon", (posmod((current_weapon_index + 1),weapons.size())))
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
rpc("ChangeWeapon", (posmod((current_weapon_index - 1),weapons.size())))
if Input.is_action_just_pressed("reload"):
current_weapon.Reload()
@rpc(call_local, any_peer)
func ChangeWeapon(i):
if(current_weapon):
current_weapon.hide()
if(weapons.size() == 0):
current_weapon = null
return
current_weapon_index = i
var w_index = weapons[current_weapon_index]
current_weapon = ALL_WEAPONS[w_index]
current_weapon.show()
current_weapon.init()
raycast.target_position.z = -current_weapon.RAY_LEN
var time = 0
func _process(delta):
if not player_root.is_local_authority():
return
if(current_weapon == null):
return
if Input.is_action_pressed("shoot") && current_weapon.Shoot():
if(current_weapon.HITSCAN):
HitScan()
else:
Projectile()
if Input.is_action_just_released("shoot"):
current_weapon.Release()
#SWAY
if mouse_mov != null && mouse_mov.length() > 0:
current_weapon.MODEL.rotation = current_weapon.MODEL.rotation.lerp(mouse_mov, sway_lerp * delta)
mouse_mov = Vector3.ZERO
else:
current_weapon.MODEL.rotation = current_weapon.MODEL.rotation.lerp(Vector3.ZERO, sway_lerp * delta)
#BOB
if player_root.velocity.length() > 0:
time += delta
var bobOscillate = sin(time * 4 * (2 * PI)) * 0.01
position.y = bobOscillate
bobOscillate = sin(time * 4 * (PI) + PI/4) * 0.015
position.x = bobOscillate
@rpc(call_local, any_peer)
func HitScan():
if(raycast.is_colliding()):
var target = raycast.get_collider()
print_debug("Hit target ", target.name, " with ", current_weapon.name, " ",current_weapon_index, ". Dealt damage ", current_weapon.DAMAGE)
if(raycast.get_collision_mask_value(10)):
if(target is Hitable):
target.Hit(current_weapon.DAMAGE)
func Projectile():
pass
return config
func Init_Config(config):
for weapon in config.get_sections():
var root = Weapon.new()
var root = WEAPON_SCENE.instantiate()
root.name = weapon
var weapon_model = Runtimeloader.load_gltf(config.get_value(weapon, "MODEL")) as Node3D
var old_parent = weapon_model.get_parent()
old_parent.remove_child(weapon_model)
#Set Weapon nodes
root.add_child(weapon_model)
var model_path = config.get_value(weapon, "MODEL") as String
var weapon_model
if(model_path.ends_with(".glb") or model_path.ends_with(".gltf")):
weapon_model = Runtimeloader.load_gltf(model_path, root) as Node3D
elif(model_path.ends_with(".tscn") or model_path.ends_with(".scn")):
weapon_model = Runtimeloader.loadScene(model_path, root)
else:
printerr("Invalid file extension for "+ model_path)
continue
root.position = config.get_value(weapon, "HAND_POS")
root.rotation = config.get_value(weapon, "HAND_ROT")
root.hide()
@@ -74,69 +180,4 @@ func Init_Config(config):
root.RELOAD_ANGULAR_MOMENTUM = config.get_value(weapon, "RELOAD_ANGULAR_MOMENTUM")
root.RELOAD_TIME = config.get_value(weapon, "RELOAD_TIME")
weapons.append(root)
func _input(event):
if event is InputEventMouseMotion:
mouse_mov.y = clampf(-event.relative.x, -0.1, 0.1)
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
func _unhandled_input(_event):
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
ChangeWeapon((current_weapon + 1) % weapons.size())
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
ChangeWeapon((current_weapon - 1) % weapons.size())
if Input.is_action_just_pressed("reload"):
weapons[current_weapon].Reload()
func ChangeWeapon(i):
weapons[current_weapon].hide()
current_weapon = i
weapons[current_weapon].init()
raycast.target_position.z = -weapons[current_weapon].RAY_LEN
var time = 0
func _process(delta):
if Input.is_action_pressed("shoot") && weapons[current_weapon].Shoot():
if(weapons[current_weapon].HITSCAN):
HitScan()
else:
Projectile()
if Input.is_action_just_released("shoot"):
weapons[current_weapon].Release()
#SWAY
if mouse_mov != null && mouse_mov.length() > 0:
weapons[current_weapon].MODEL.rotation = weapons[current_weapon].MODEL.rotation.lerp(mouse_mov, sway_lerp * delta)
mouse_mov = Vector3.ZERO
else:
weapons[current_weapon].MODEL.rotation = weapons[current_weapon].MODEL.rotation.lerp(Vector3.ZERO, sway_lerp * delta)
#BOB
if player_root.velocity.length() > 0:
time += delta
var bobOscillate = sin(time * 4 * (2 * PI)) * 0.01
position.y = bobOscillate
bobOscillate = sin(time * 4 * (PI) + PI/4) * 0.015
position.x = bobOscillate
func HitScan():
if(raycast.is_colliding()):
var target = raycast.get_collider()
print_debug("Hit target ", target.name, " with ", weapons[current_weapon].MODEL.name, " ",current_weapon, ". Dealt damage ", weapons[current_weapon].DAMAGE)
if(raycast.get_collision_mask_value(10)):
if(target is Hitable):
target.Hit(weapons[current_weapon].DAMAGE)
func Projectile():
pass
ALL_WEAPONS.append(root)

45
scripts/utils/network.gd Normal file
View File

@@ -0,0 +1,45 @@
extends Node
signal player_spawn
# The player scene (which we want to configure for replication).
const Player = preload("res://entities/Player.tscn")
@onready var NetworkingRoot = get_node("/root/Game/Networking")
func start_network(server: bool, ip="localhost"):
var peer = ENetMultiplayerPeer.new()
if server:
peer.create_server(27015)
# Listen to peer connections, and create new player for them
multiplayer.peer_connected.connect(create_player)
# Listen to peer disconnections, and destroy their players
multiplayer.peer_disconnected.connect(destroy_player)
multiplayer.set_multiplayer_peer(peer)
create_player()
else:
peer.create_client(ip, 27015)
multiplayer.set_multiplayer_peer(peer)
func add_network_entity(path):
var spawner = NetworkingRoot.get_node("Networking") as MultiplayerSpawner
spawner.add_spawnable_scene(path)
func create_player(id=1):
# Instantiate a new player for this client.
var p = Player.instantiate()
# Sets the player name (only sent during spawn).
#p.player_name = "Player %d" % id
# Set a random position (sent on every replicator update).
#p.position = Vector2(randi() % 500, randi() % 500)
# Add it to the "Players" node.
# We give the new Node a name for easy retrieval, but that's not necessary.
p.name = str(id)
#p.set_multiplayer_authority(id)
NetworkingRoot.add_child(p)
p.init()
func destroy_player(id):
# Delete this peer's node.
NetworkingRoot.get_node(str(id)).queue_free()

View File

@@ -1,17 +1,12 @@
extends Node
var PATH = "res://scoom/"
var EXTERNAL_PATH = "res://scoom/"
const ENTITY_CONFIG = "entity.cfg"
func _ready():
if(not OS.has_feature("editor")):
PATH = OS.get_executable_path().get_base_dir() + "/scoom/"
EXTERNAL_PATH = OS.get_executable_path().get_base_dir() + "/scoom/"
print(PATH)
func _input(event):
if event is InputEventKey and event.is_pressed():
if event.keycode == KEY_T:
load_gltf("models/runtime_loader_test.glb")
func get_all_children(in_node, arr = []):
arr.push_back(in_node)
@@ -19,54 +14,94 @@ func get_all_children(in_node, arr = []):
arr = get_all_children(child,arr)
return arr
func load_gltf(file, hasCollision = false, trimesh = false):
func load_gltf(file, parent = self, hasCollision = false, trimesh = false):
if(file == null):
printerr("No model provided to load")
return
var gltf := GLTFDocument.new()
var gltf_state := GLTFState.new()
var snd_file = FileAccess.open(PATH + file, FileAccess.READ)
var snd_file = FileAccess.open(EXTERNAL_PATH + file, FileAccess.READ)
var fileBytes = PackedByteArray()
fileBytes = snd_file.get_buffer(snd_file.get_length())
gltf.append_from_buffer(fileBytes, "", gltf_state)
print("Loading ", PATH + file)
var node = gltf.generate_scene(gltf_state)
var entity_count = 0;
print("Loading ", EXTERNAL_PATH + file)
var node = gltf.generate_scene(gltf_state) as Node
parent.add_child(node)
get_all_entities(node)
if not hasCollision:
return node
for o in get_all_children(node):
if o.name.begins_with("entity_") && not o.name.ends_with("_geometry"):
if o is MeshInstance3D:
if(trimesh):
o.create_trimesh_collision()
else:
o.create_convex_collision()
return node
func get_all_entities(at_node):
var entity_count = 0
for o in get_all_children(at_node):
if o.name.begins_with("entity_"):
print("Loading entity ", o.name)
if loadEntity(o):
entity_count += 1;
elif o is MeshInstance3D:
if hasCollision:
if(trimesh):
o.create_trimesh_collision()
else:
o.create_convex_collision()
add_child(node)
if(entity_count > 0):
print("Loaded ", entity_count, " entities.")
return node
func loadEntity(node):
var config = ConfigFile.new()
var err = config.load(PATH + ENTITY_CONFIG)
if err != OK:
printerr("COULD NOT LOAD ENTITY : ", node.name)
node.queue_free()
return false
var x = config.get_section_keys(node.name)
if(x.size() < 1):
node.queue_free()
if(not config.has_section(node.name)):
printerr("NO CONFIG FOUND FOR ENTITY : ", node.name)
return false
var entity = load_gltf(config.get_value(node.name, "model")) as Node3D
var model = config.get_value(node.name, "model")
var has_collision = config.get_value(node.name, "has_collision")
var has_trimesh_col = config.get_value(node.name, "has_trimesh_col")
var entity = load_gltf(model, node.get_parent(), has_collision, has_trimesh_col) as Node3D
if(entity == null):
printerr("ENTITY COULD NOT BE CREATED : ", node.name)
return false
entity.transform.origin = node.transform.origin
entity.scale = (Vector3(1.5,1.5,1.5))
entity.scale = config.get_value(node.name, "scale")
node.queue_free()
return true
func loadPCK(file):
var success = ProjectSettings.load_resource_pack(EXTERNAL_PATH + file)
if success:
print("Resource pack loaded ", EXTERNAL_PATH + file)
func loadConfig(file):
var config = ConfigFile.new()
var err = config.load(EXTERNAL_PATH + file)
if err != OK:
printerr("FAILED LOADING CONFIG DATA @ ",EXTERNAL_PATH + file)
return config
func loadScene(file, parent = self):
var res = load(PATH + file) as PackedScene
var scene = res.instantiate()
get_all_entities(scene)
parent.add_child(scene)
return scene