pbrt_r3/shapes/
create_shape.rs

1use super::cone::create_cone_shape;
2use super::curve::create_curve_shape;
3use super::cylinder::create_cylinder_shape;
4use super::disk::create_disk_shape;
5use super::heightfield::create_heightfield;
6use super::hyperboloid::create_hyperboloid_shape;
7use super::loopsubdiv::create_loop_subdiv;
8use super::nurbs::create_nurbs;
9use super::paraboloid::create_paraboloid_shape;
10use super::plymesh::create_ply_mesh;
11use super::sphere::create_sphere_shape;
12use super::triangle::create_triangle_mesh_shape;
13use crate::core::prelude::*;
14
15use std::collections::HashMap;
16use std::sync::Arc;
17
18type FloatTextureMap = HashMap<String, Arc<dyn Texture<Float>>>;
19
20pub fn create_shapes(
21    name: &str,
22    object2world: &Transform,
23    reverse_orientation: bool,
24    params: &ParamSet,
25    float_textures: &FloatTextureMap,
26) -> Result<Vec<Arc<dyn Shape>>, PbrtError> {
27    //println!("{} shape create", name);
28    let mut shapes: Vec<Arc<dyn Shape>> = Vec::new();
29    match name {
30        "sphere" => {
31            let s = create_sphere_shape(
32                object2world,
33                &object2world.inverse(),
34                reverse_orientation,
35                params,
36            )?;
37            shapes.push(Arc::new(s));
38        }
39        "cylinder" => {
40            let s = create_cylinder_shape(
41                object2world,
42                &object2world.inverse(),
43                reverse_orientation,
44                params,
45            )?;
46            shapes.push(Arc::new(s));
47        }
48        "disk" => {
49            let s = create_disk_shape(
50                object2world,
51                &object2world.inverse(),
52                reverse_orientation,
53                params,
54            )?;
55            shapes.push(Arc::new(s));
56        }
57        "cone" => {
58            let s = create_cone_shape(
59                object2world,
60                &object2world.inverse(),
61                reverse_orientation,
62                params,
63            )?;
64            shapes.push(Arc::new(s));
65        }
66        "paraboloid" => {
67            let s = create_paraboloid_shape(
68                object2world,
69                &object2world.inverse(),
70                reverse_orientation,
71                params,
72            )?;
73            shapes.push(Arc::new(s));
74        }
75        "hyperboloid" => {
76            let s = create_hyperboloid_shape(
77                object2world,
78                &object2world.inverse(),
79                reverse_orientation,
80                params,
81            )?;
82            shapes.push(Arc::new(s));
83        }
84        "curve" => {
85            return create_curve_shape(
86                object2world,
87                &object2world.inverse(),
88                reverse_orientation,
89                params,
90            );
91        }
92        "trianglemesh" => {
93            return create_triangle_mesh_shape(
94                object2world,
95                &object2world.inverse(),
96                reverse_orientation,
97                params,
98                float_textures,
99            );
100        }
101        "plymesh" => {
102            return create_ply_mesh(
103                object2world,
104                &object2world.inverse(),
105                reverse_orientation,
106                params,
107                float_textures,
108            );
109        }
110        "heightfield" => {
111            return create_heightfield(
112                object2world,
113                &object2world.inverse(),
114                reverse_orientation,
115                params,
116            );
117        }
118        "loopsubdiv" => {
119            return create_loop_subdiv(
120                object2world,
121                &object2world.inverse(),
122                reverse_orientation,
123                params,
124            );
125        }
126        "nurbs" => {
127            return create_nurbs(
128                object2world,
129                &object2world.inverse(),
130                reverse_orientation,
131                params,
132            );
133        }
134        s => {
135            return Err(PbrtError::warning(&format!("{} shape cannot create", s)));
136        }
137    }
138    return Ok(shapes);
139}