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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use math::*;
use std::rc::Rc;
use std::sync::Arc;
use std::cell::RefCell;
use crate::core::geometry::*;
use crate::core::resource::*;
use util::uuid::OsRandNewV4;
#[derive(Debug)]
pub struct MeshGeometry
{
uuid: uuid::Uuid,
vertices:float3s,
normals:float3s,
texcoords:float2s,
indices:Vec<u16>,
}
impl MeshGeometry
{
pub fn new(vertices:float3s, normals:float3s, texcoords:float2s, indices:Vec<u16>) -> Self
{
Self
{
uuid:uuid::Uuid::new_v4_osrng(),
vertices:vertices,
normals:normals,
texcoords:texcoords,
indices:indices,
}
}
}
impl Geometry for MeshGeometry
{
fn vertices(&self) -> &[float3]
{
&self.vertices[..]
}
fn normals(&self) -> &[float3]
{
&self.normals[..]
}
fn texcoords(&self) -> &[float2]
{
&self.texcoords[..]
}
fn indices(&self) -> &[u16]
{
&self.indices[..]
}
}
impl Resource for MeshGeometry
{
#[inline]
fn uuid(&self) -> &uuid::Uuid
{
&self.uuid
}
}
impl From<MeshGeometry> for Rc<Geometry + 'static>
{
fn from(shape:MeshGeometry) -> Self
{
Rc::new(shape)
}
}
impl From<MeshGeometry> for Arc<Geometry + 'static>
{
fn from(shape:MeshGeometry) -> Self
{
Arc::new(shape)
}
}
impl From<MeshGeometry> for Rc<RefCell<Geometry + 'static>>
{
fn from(shape:MeshGeometry) -> Self
{
Rc::new(RefCell::new(shape))
}
}
impl From<MeshGeometry> for Arc<RefCell<Geometry + 'static>>
{
fn from(shape:MeshGeometry) -> Self
{
Arc::new(RefCell::new(shape))
}
}