summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shared/src/resources.rs5
-rw-r--r--world/src/main.rs30
-rw-r--r--world/src/physics.rs42
3 files changed, 43 insertions, 34 deletions
diff --git a/shared/src/resources.rs b/shared/src/resources.rs
index b3d9414..4cfc6fa 100644
--- a/shared/src/resources.rs
+++ b/shared/src/resources.rs
@@ -98,6 +98,7 @@ pub struct ArmaturePart {
#[derive(Debug, Default, Clone)]
pub struct CollisionPart {
+ pub name: Option<String>,
pub restitution_coeff: Option<f32>,
pub friction_kinetic: Option<f32>,
pub friction_static: Option<f32>,
@@ -105,7 +106,7 @@ pub struct CollisionPart {
pub sh_sphere: Option<f32>,
pub sh_cylinder: Option<(f32, f32, f32)>,
pub sh_capsule: Option<(f32, f32, f32)>,
- pub sh_convex_hull: Option<Resource>,
+ pub sh_convex_hull: Option<Resource<Vec<Vec3A>>>,
pub sh_mesh: Option<(Resource<Vec<[u32; 3]>>, Resource<Vec<Vec3A>>)>,
}
@@ -158,6 +159,7 @@ impl ReadWrite for ArmaturePart {
}
impl ReadWrite for CollisionPart {
fn write(&self, w: &mut dyn Write) -> Result<()> {
+ write_kv_opt(w, b"name", &self.name)?;
write_kv_opt(w, b"restitution_coeff", &self.restitution_coeff)?;
write_kv_opt(w, b"friction_kinetic", &self.friction_kinetic)?;
write_kv_opt(w, b"friction_static", &self.friction_static)?;
@@ -172,6 +174,7 @@ impl ReadWrite for CollisionPart {
fn read(r: &mut dyn Read) -> Result<Self> {
let mut s = Self::default();
read_kv_iter(r, |k, v| match k {
+ b"name" => Ok(s.name = Some(read_slice(v)?)),
b"restitution_coeff" => Ok(s.restitution_coeff = Some(read_slice(v)?)),
b"friction_kinetic" => Ok(s.friction_kinetic = Some(read_slice(v)?)),
b"friction_static" => Ok(s.friction_static = Some(read_slice(v)?)),
diff --git a/world/src/main.rs b/world/src/main.rs
index 278cfb3..9dded85 100644
--- a/world/src/main.rs
+++ b/world/src/main.rs
@@ -212,19 +212,21 @@ fn main() -> Result<()> {
.map(|(trans, node)| {
let mut prefab = Prefab::default();
- if let Some(mesh) = node.mesh() {
- import_mesh(
- mesh,
- *trans,
- &buffers,
- &store,
- path_base,
- node,
- &mut prefab,
- &args,
- &texture_cache,
- &skin_index_to_arm_index,
- )?;
+ if !node.name().unwrap_or_default().ends_with("-collider") {
+ if let Some(mesh) = node.mesh() {
+ import_mesh(
+ mesh,
+ *trans,
+ &buffers,
+ &store,
+ path_base,
+ node,
+ &mut prefab,
+ &args,
+ &texture_cache,
+ &skin_index_to_arm_index,
+ )?;
+ }
}
let (position, _, _) = node.transform().decomposed();
if let Some(light) = node.light() {
@@ -319,7 +321,7 @@ fn main() -> Result<()> {
info!("adding object {ob}");
Packet::Add(ob, p.clone()).write(&mut sock)?;
if args.line_up {
- Packet::Position(ob, vec3a(i as f32, 0., i as f32 * 0.3), Vec3A::ZERO)
+ Packet::Position(ob, vec3a(i as f32 * 1.2, 0., i as f32 * 0.0), Vec3A::ZERO)
.write(&mut sock)?;
}
obs.push(ob);
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)?));
}
}
}