add entity collision option
This commit is contained in:
@@ -37,32 +37,23 @@ func load_gltf(file, parent = self, hasCollision = false, trimesh = false):
|
||||
var node = gltf.generate_scene(gltf_state)
|
||||
parent.add_child(node)
|
||||
|
||||
get_all_entities(node)
|
||||
|
||||
var entity_count = 0;
|
||||
if not hasCollision:
|
||||
get_all_entities(node)
|
||||
return node
|
||||
|
||||
for o in get_all_children(node):
|
||||
if o.name.begins_with("entity_"):
|
||||
print("Loading entity ", o.name)
|
||||
if loadEntity(o):
|
||||
entity_count += 1;
|
||||
|
||||
if o is MeshInstance3D:
|
||||
if(trimesh):
|
||||
o.create_trimesh_collision()
|
||||
else:
|
||||
o.create_convex_collision()
|
||||
|
||||
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"):
|
||||
if o.name.begins_with("entity_"):
|
||||
print("Loading entity ", o.name)
|
||||
if loadEntity(o):
|
||||
entity_count += 1;
|
||||
@@ -80,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
|
||||
|
||||
Reference in New Issue
Block a user