Testbed: don’t panic when trying to render an unknown custom shape.

This commit is contained in:
Sébastien Crozet
2021-10-20 16:44:39 +02:00
committed by Sébastien Crozet
parent b59e813fd3
commit 7cda2f05e2

View File

@@ -48,8 +48,7 @@ impl EntityWithGraphics {
let mesh = prefab_meshs let mesh = prefab_meshs
.get(&shape.shape_type()) .get(&shape.shape_type())
.cloned() .cloned()
.or_else(|| generate_collider_mesh(shape).map(|m| meshes.add(m))) .or_else(|| generate_collider_mesh(shape).map(|m| meshes.add(m)));
.expect("Could not build the collider's render mesh");
let opacity = 1.0; let opacity = 1.0;
let bevy_color = Color::rgba(color.x, color.y, color.z, opacity); let bevy_color = Color::rgba(color.x, color.y, color.z, opacity);
@@ -83,18 +82,21 @@ impl EntityWithGraphics {
}; };
let material_handle = materials.add(material); let material_handle = materials.add(material);
let material_weak_handle = material_handle.clone_weak(); let material_weak_handle = material_handle.clone_weak();
let pbr = PbrBundle {
mesh,
material: material_handle,
transform,
..Default::default()
};
let mut entity_commands = commands.entity(entity); if let Some(mesh) = mesh {
entity_commands.insert_bundle(pbr); let pbr = PbrBundle {
mesh,
material: material_handle,
transform,
..Default::default()
};
if sensor { let mut entity_commands = commands.entity(entity);
entity_commands.insert(Wireframe); entity_commands.insert_bundle(pbr);
if sensor {
entity_commands.insert(Wireframe);
}
} }
EntityWithGraphics { EntityWithGraphics {