impl clone again for model
use crate::core::*;
use crate::renderer::*;
+use std::rc::Rc;
///
/// A 3D model consisting of a triangle mesh and any material that implements the `Material` trait.
///
pub struct Model<M: Material> {
context: Context,
- mesh: Mesh,
+ mesh: Rc<Mesh>,
aabb: AxisAlignedBoundingBox,
aabb_local: AxisAlignedBoundingBox,
transformation: Mat4,
@@ -33,7 +34,7 @@ impl<M: Material> Model<M> {
cpu_mesh: &CpuMesh,
material: M,
) -> ThreeDResult<Self> {
- let mesh = Mesh::new(context, cpu_mesh)?;
+ let mesh = Rc::new(Mesh::new(context, cpu_mesh)?);
let aabb = cpu_mesh.compute_aabb();
Ok(Self {
mesh,
@@ -230,3 +231,17 @@ impl<M: Material> Object for Model<M> {
self.material.is_transparent()
}
}
+
+impl<M: Material + Clone> Clone for Model<M> {
+ fn clone(&self) -> Self {
+ Self {
+ context: self.context.clone(),
+ mesh: self.mesh.clone(),
+ aabb: self.aabb.clone(),
+ aabb_local: self.aabb_local.clone(),
+ transformation: self.transformation,
+ texture_transform: self.texture_transform,
+ material: self.material.clone(),
+ }
+ }
+}
