PCK File loader

This commit is contained in:
2023-01-02 17:55:28 +01:00
parent 4de8162f48
commit 701bcfd39c
11 changed files with 100 additions and 49 deletions

View File

@@ -1,12 +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/"
print(PATH)
EXTERNAL_PATH = OS.get_executable_path().get_base_dir() + "/scoom/"
func _input(event):
if event is InputEventKey and event.is_pressed():
@@ -19,7 +19,7 @@ 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):
var gltf := GLTFDocument.new()
var gltf_state := GLTFState.new()
@@ -44,11 +44,20 @@ func load_gltf(file, hasCollision = false, trimesh = false):
o.create_trimesh_collision()
else:
o.create_convex_collision()
add_child(node)
parent.add_child(node)
if(entity_count > 0):
print("Loaded ", entity_count, " entities.")
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_") && not o.name.ends_with("_geometry"):
print("Loading entity ", o.name)
if loadEntity(o):
entity_count += 1;
if(entity_count > 0):
print("Loaded ", entity_count, " entities.")
func loadEntity(node):
var config = ConfigFile.new()
@@ -56,17 +65,23 @@ func loadEntity(node):
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()
printerr("NO CONFIG FOUND FOR ENTITY : ", node.name)
return false
var entity = load_gltf(config.get_value(node.name, "model")) as Node3D
var entity = load_gltf(config.get_value(node.name, "model"), node.get_parent()) as Node3D
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, parent = self):
var success = ProjectSettings.load_resource_pack(EXTERNAL_PATH + file)
if success:
print("Resource pack loaded ", EXTERNAL_PATH + file)