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)
|
var node = gltf.generate_scene(gltf_state)
|
||||||
parent.add_child(node)
|
parent.add_child(node)
|
||||||
|
|
||||||
|
|
||||||
var entity_count = 0;
|
|
||||||
if not hasCollision:
|
|
||||||
get_all_entities(node)
|
get_all_entities(node)
|
||||||
|
|
||||||
|
if not hasCollision:
|
||||||
return node
|
return node
|
||||||
|
|
||||||
for o in get_all_children(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 o is MeshInstance3D:
|
||||||
if(trimesh):
|
if(trimesh):
|
||||||
o.create_trimesh_collision()
|
o.create_trimesh_collision()
|
||||||
else:
|
else:
|
||||||
o.create_convex_collision()
|
o.create_convex_collision()
|
||||||
|
|
||||||
if(entity_count > 0):
|
|
||||||
print("Loaded ", entity_count, " entities.")
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
func get_all_entities(at_node):
|
func get_all_entities(at_node):
|
||||||
var entity_count = 0
|
var entity_count = 0
|
||||||
for o in get_all_children(at_node):
|
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)
|
print("Loading entity ", o.name)
|
||||||
if loadEntity(o):
|
if loadEntity(o):
|
||||||
entity_count += 1;
|
entity_count += 1;
|
||||||
@@ -81,7 +72,12 @@ func loadEntity(node):
|
|||||||
printerr("NO CONFIG FOUND FOR ENTITY : ", node.name)
|
printerr("NO CONFIG FOUND FOR ENTITY : ", node.name)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
var entity = load_gltf(config.get_value(node.name, "model"), node.get_parent()) 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):
|
if(entity == null):
|
||||||
printerr("ENTITY COULD NOT BE CREATED : ", node.name)
|
printerr("ENTITY COULD NOT BE CREATED : ", node.name)
|
||||||
return false
|
return false
|
||||||
|
|||||||
Reference in New Issue
Block a user