PCK File loader
This commit is contained in:
@@ -90,7 +90,7 @@ func accelerate(delta : float, p_target_dir : Vector3, p_target_speed : float, p
|
||||
|
||||
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
|
||||
|
||||
@@ -39,12 +39,8 @@ func Init_Config(config):
|
||||
for weapon in config.get_sections():
|
||||
var root = Weapon.new()
|
||||
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 weapon_model = Runtimeloader.load_gltf(config.get_value(weapon, "MODEL"), root) as Node3D
|
||||
|
||||
root.position = config.get_value(weapon, "HAND_POS")
|
||||
root.rotation = config.get_value(weapon, "HAND_ROT")
|
||||
root.hide()
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user