summaryrefslogtreecommitdiff
path: root/world/src/physics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'world/src/physics.rs')
-rw-r--r--world/src/physics.rs42
1 files changed, 23 insertions, 19 deletions
diff --git a/world/src/physics.rs b/world/src/physics.rs
index 84f1095..23b3303 100644
--- a/world/src/physics.rs
+++ b/world/src/physics.rs
@@ -36,47 +36,51 @@ pub fn import_physics(
.extensions()
.and_then(|e| e.get("KHR_physics_rigid_bodies"))
{
- info!("--- COLLISION ---");
+ debug!("--- COLLISION ---");
if let Some(collider) = physics.get("collider") {
if let Some(geometry) = collider.get("geometry") {
- if geometry.get("convexHull") == Some(&Value::Bool(true)) {
+ if let Some(&Value::Bool(chull)) = geometry.get("convexHull") {
let node = geometry
.get("node")
.and_then(|n| n.as_u64())
- .ok_or(anyhow!("convexHull node missing"))?;
+ .ok_or(anyhow!("coll geom node missing"))?;
let node = gltf
.nodes()
.nth(node as usize)
- .ok_or(anyhow!("convexHull node reference invalid"))?;
- let mesh = node.mesh().ok_or(anyhow!("convexHull node has no mesh"))?;
+ .ok_or(anyhow!("coll geom node reference invalid"))?;
+ let mesh = node.mesh().ok_or(anyhow!("coll geom node has no mesh"))?;
for p in mesh.primitives() {
let reader = p.reader(|buf| Some(&buffers[buf.index()]));
let index = reader
.read_indices()
- .ok_or(anyhow!("convexHull no index buffer"))?
+ .ok_or(anyhow!("coll geom no index buffer"))?
.into_u32()
.array_chunks::<3>()
.collect::<Vec<_>>();
let position = reader
.read_positions()
- .ok_or(anyhow!("convexHull no positions"))?
+ .ok_or(anyhow!("coll geom no positions"))?
.map(|[x, y, z]| vec3a(x, y, z))
.collect::<Vec<_>>();
- debug!(
- "convex hull has {} indecies and {} positions",
- index.len(),
- position.len()
- );
+ let mut collpart = CollisionPart::default();
+ collpart.name = node.name().map(|s| s.to_string());
- prefab.collision.push((
- trans,
- store.set(&CollisionPart {
- sh_mesh: Some((store.set(&index)?, store.set(&position)?)),
- ..Default::default()
- })?,
- ));
+ if chull {
+ debug!("convex hull has {} positions", position.len());
+ collpart.sh_convex_hull = Some(store.set(&position)?);
+ } else {
+ debug!(
+ "mesh has {} indecies and {} positions",
+ index.len(),
+ position.len()
+ );
+ collpart.sh_mesh = Some((store.set(&index)?, store.set(&position)?));
+ }
+
+ info!("added collision {:?}", node.name().unwrap_or_default());
+ prefab.collision.push((trans, store.set(&collpart)?));
}
}
}