clay_core/shape/shape.rs
1use crate::{
2 prelude::*,
3 map::Map,
4 shape::ShapeMapper,
5 material::Material,
6 object::Covered,
7};
8
9
10/// Shape of an object.
11///
12/// It defines the search of the point where ray intersects this shape.
13pub trait Shape: Pack + Instance<ShapeClass> {
14 /// Creates a new shape by applying some kind of mapping to previous one.
15 ///
16 /// Most common use case is applying affine transform to some unit shape.
17 /// (*see `map::Affine`*)
18 fn map<M: Map>(self, map: M) -> ShapeMapper<Self, M> {
19 ShapeMapper { shape: self, map }
20 }
21 /// Transforms the shape in an object by covering it with material.
22 fn cover<M: Material>(self, material: M) -> Covered<Self, M> {
23 Covered::new(self, material)
24 }
25}
26
27/// Device interface for shape.
28///
29/// How to implement in OpenCL:
30/// ```c
31/// #include <clay_core/shape/shape.h>
32///
33/// SHAPE_HIT_RET <shape>_hit(
34/// SHAPE_HIT_ARGS_DEF
35/// ) {
36/// ...
37/// }
38/// ```
39pub enum ShapeClass {}
40impl Class for ShapeClass {
41 fn name() -> String {
42 "shape".to_string()
43 }
44 fn methods() -> Vec<String> {
45 vec!["hit".to_string()]
46 }
47}