Fixed some bugs where instances without transforms would crash.

This commit is contained in:
Nathan Vegdahl 2016-07-07 23:32:19 -07:00
parent 3ef84f9f5f
commit aff8d24f55
2 changed files with 18 additions and 1 deletions

View File

@ -91,6 +91,17 @@ impl AssemblyBuilder {
panic!("Attempted to add instance with a name that doesn't exist."); panic!("Attempted to add instance with a name that doesn't exist.");
} }
// Map zero-length transforms to None
let xforms = if let Some(xf) = xforms {
if xf.len() > 0 {
Some(xf)
} else {
None
}
} else {
None
};
// Create instance // Create instance
let instance = if self.object_map.contains_key(name) { let instance = if self.object_map.contains_key(name) {
Instance { Instance {

View File

@ -75,7 +75,13 @@ impl Surface for TriangleMesh {
|a, b, t| { |a, b, t| {
(lerp(a.0, b.0, t), lerp(a.1, b.1, t), lerp(a.2, b.2, t)) (lerp(a.0, b.0, t), lerp(a.1, b.1, t), lerp(a.2, b.2, t))
}); });
let mat_space = lerp_slice(space, wr.time); // TODO: when there's no transforms, we don't have to
// transform the triangles at all.
let mat_space = if space.len() > 0 {
lerp_slice(space, wr.time)
} else {
Matrix4x4::new()
};
let mat_inv = mat_space.inverse(); let mat_inv = mat_space.inverse();
let tri = (tri.0 * mat_inv, tri.1 * mat_inv, tri.2 * mat_inv); let tri = (tri.0 * mat_inv, tri.1 * mat_inv, tri.2 * mat_inv);
if let Some((t, _, _)) = triangle::intersect_ray(wr, tri) { if let Some((t, _, _)) = triangle::intersect_ray(wr, tri) {