Compare commits

..

3 Commits

Author SHA1 Message Date
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

View File

@@ -35,27 +35,25 @@ func load_gltf(file, parent = self, hasCollision = false, trimesh = false):
print("Loading ", EXTERNAL_PATH + file)
var node = gltf.generate_scene(gltf_state)
var entity_count = 0;
for o in get_all_children(node):
if o.name.begins_with("entity_") && not o.name.ends_with("_geometry"):
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()
parent.add_child(node)
if(entity_count > 0):
print("Loaded ", entity_count, " entities.")
get_all_entities(node)
if not hasCollision:
return node
for o in get_all_children(node):
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_") && not o.name.ends_with("_geometry"):
if o.name.begins_with("entity_"):
print("Loading entity ", o.name)
if loadEntity(o):
entity_count += 1;
@@ -73,8 +71,13 @@ func loadEntity(node):
if(not config.has_section(node.name)):
printerr("NO CONFIG FOUND FOR ENTITY : ", node.name)
return false
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
var entity = load_gltf(config.get_value(node.name, "model"), node.get_parent()) as Node3D
if(entity == null):
printerr("ENTITY COULD NOT BE CREATED : ", node.name)
return false