pub fn export_to_file<P: AsRef<Path>>(obj_set: &ObjSet, path: P) -> Result<()>
Expand description
Exports ObjSet
to file.
Examples found in repository?
examples/export_obj_single.rs (line 51)
5pub fn main() {
6 let set = ObjSet {
7 material_library: None,
8 objects: vec![
9 Object {
10 name: "Square".to_owned(),
11 vertices: vec![
12 (-1.0, -1.0, 0.0),
13 (1.0, -1.0, 0.0),
14 (1.0, 1.0, 0.0),
15 (-1.0, 1.0, 0.0),
16 ].into_iter()
17 .map(|(x, y, z)| Vertex { x, y, z })
18 .collect(),
19 tex_vertices: vec![(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
20 .into_iter()
21 .map(|(u, v)| TVertex { u, v, w: 0.0 })
22 .collect(),
23 normals: vec![
24 Vertex {
25 x: 0.0,
26 y: 0.0,
27 z: -1.0,
28 },
29 ],
30 geometry: vec![
31 Geometry {
32 material_name: None,
33 shapes: vec![(0, 1, 2), (0, 2, 3)]
34 .into_iter()
35 .map(|(x, y, z)| Shape {
36 primitive: Primitive::Triangle(
37 (x, Some(x), Some(0)),
38 (y, Some(y), Some(0)),
39 (z, Some(z), Some(0)),
40 ),
41 groups: vec![],
42 smoothing_groups: vec![],
43 })
44 .collect(),
45 },
46 ],
47 },
48 ],
49 };
50
51 obj::export_to_file(&set, "output_single.obj").unwrap();
52}
More examples
examples/export_obj_multiple.rs (line 64)
5pub fn main() {
6 let set = ObjSet {
7 material_library: None,
8 objects: vec![
9 Object {
10 name: "Square1".to_owned(),
11 vertices: vec![
12 (-1.0, -1.0, 0.0),
13 (1.0, -1.0, 0.0),
14 (1.0, 1.0, 0.0),
15 (-1.0, 1.0, 0.0),
16 ].into_iter()
17 .map(|(x, y, z)| Vertex { x, y, z })
18 .collect(),
19 tex_vertices: vec![],
20 normals: vec![],
21 geometry: vec![
22 Geometry {
23 material_name: None,
24 shapes: vec![(0, 1, 2), (0, 2, 3)]
25 .into_iter()
26 .map(|(x, y, z)| Shape {
27 primitive: Primitive::Triangle((x, None, None), (y, None, None), (z, None, None)),
28 groups: vec![],
29 smoothing_groups: vec![],
30 })
31 .collect(),
32 },
33 ],
34 },
35 Object {
36 name: "Square2".to_owned(),
37 vertices: vec![
38 (1.0, -1.0, 0.0),
39 (2.0, -1.0, 0.0),
40 (2.0, 1.0, 0.0),
41 (1.0, 1.0, 0.0),
42 ].into_iter()
43 .map(|(x, y, z)| Vertex { x, y, z })
44 .collect(),
45 tex_vertices: vec![],
46 normals: vec![],
47 geometry: vec![
48 Geometry {
49 material_name: None,
50 shapes: vec![(0, 1, 2), (0, 2, 3)]
51 .into_iter()
52 .map(|(x, y, z)| Shape {
53 primitive: Primitive::Triangle((x, None, None), (y, None, None), (z, None, None)),
54 groups: vec![],
55 smoothing_groups: vec![],
56 })
57 .collect(),
58 },
59 ],
60 },
61 ],
62 };
63
64 obj::export_to_file(&set, "output_multiple.obj").unwrap();
65}