1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//! Geometric shapes that can be placed into the scene.

pub use bvh::BVH;
pub use mesh::Mesh;
pub use object::Object;
pub use sphere::Sphere;
pub use triangle::Triangle;
pub use triangle_mesh::TriangleMesh;

use crate::math::{Bounds3, Hit, Ray};

mod bvh;
mod mesh;
mod object;
mod sphere;
mod triangle;
mod triangle_mesh;

/// A general representation of shapes.
///
/// This allows performing ray intersections against them and accessing their bounding volumes.
pub trait Shape: Send + Sync {
    /// Return the corresponding hit, if self and ray intersect.
    /// Otherwise return [`None`].
    fn intersects(&self, ray: Ray) -> Option<Hit>;

    /// Return the shape's bounding volume.
    fn bounds(&self) -> Bounds3;
}