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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
use math::*;

use std::rc::Rc;
use std::sync::Arc;
use std::cell::RefCell;
use std::any::Any;

use crate::core::object::*;
use crate::core::resource::*;
use crate::core::material::*;
use crate::core::shape::*;
use crate::core::event::*;
use crate::core::geometry::*;
use crate::core::transform::*;
use crate::core::downcast::Downcast;

use util::uuid::OsRandNewV4;

pub struct MeshShape
{
	pub uuid:uuid::Uuid,
	pub transform: Transform,
	pub geometry: Arc<Geometry + 'static>,
	pub material: Arc<Material + 'static>
}

impl MeshShape 
{
	pub fn new(geometry:Arc<Geometry + 'static>, material: Arc<Material + 'static>) -> Self 
	{
		Self
		{
			uuid:uuid::Uuid::new_v4_osrng(),
			geometry:geometry,
			material:material,
			transform:Transform::new(),
		}
	}
}

impl Shape for MeshShape
{
    #[inline]
    fn geometry(&self) -> Arc<Geometry + 'static>
    {
        self.geometry.clone()
    }

    #[inline]
    fn set_geometry(&mut self, geometry: Arc<Geometry + 'static>) 
    {
        self.geometry = geometry;
    }

    #[inline]
    fn material(&self) -> Arc<Material + 'static>
    {
        self.material.clone()
    }

    #[inline]
    fn set_material(&mut self, material: Arc<Material + 'static>) 
    {
        self.material = material;
    }
}

impl Object for MeshShape
{
	#[inline]
	fn translate(&self) -> &float3
	{
		self.transform.translate()
	}

	#[inline]
	fn scale(&self) -> &float3
	{
		self.transform.scale()
	}

	#[inline]
	fn rotation(&self) -> &float3
	{
		self.transform.rotation()
	}

	#[inline]
	fn transform(&self) -> &float4x4
	{
		self.transform.transform()
	}

	#[inline]
	fn transform_inverse(&self) -> &float4x4
	{
		self.transform.transform_inverse()
	}

	#[inline]
	fn set_translate(&mut self, pos:float3)
	{
		self.transform.set_translate(pos)
	}

	#[inline]
	fn set_scale(&mut self, sz:float3)
	{
		self.transform.set_scale(sz)
	}

	#[inline]
	fn set_rotation(&mut self, rot:float3)
	{
		self.transform.set_rotation(rot)
	}
}

impl Resource for MeshShape
{
	#[inline]
	fn uuid(&self) -> &uuid::Uuid
	{
		&self.uuid
	}
}

impl Downcast for MeshShape
{
    fn as_any(&self) -> &Any { self }
    fn as_any_mut(&mut self) -> &mut Any { self }
}

impl UpdateEvent for MeshShape 
{
	fn update(&mut self)
	{
		self.transform.update();
	}
}

impl From<MeshShape> for Rc<Shape + 'static>
{
	fn from(shape:MeshShape) -> Self
	{
		Rc::new(shape)
	}
}

impl From<MeshShape> for Arc<Shape + 'static>
{
	fn from(shape:MeshShape) -> Self
	{
		Arc::new(shape)
	}
}

impl From<MeshShape> for Rc<RefCell<Shape + 'static>>
{
	fn from(shape:MeshShape) -> Self
	{
		Rc::new(RefCell::new(shape))
	}
}

impl From<MeshShape> for Arc<RefCell<Shape + 'static>>
{
	fn from(shape:MeshShape) -> Self
	{
		Arc::new(RefCell::new(shape))
	}
}