pub struct MeshCPU { /* private fields */ }
Implementations§
source§impl MeshCPU
impl MeshCPU
sourcepub fn new(
vertex_count: usize,
index_count: usize
) -> Result<MeshCPU, &'static str>
pub fn new( vertex_count: usize, index_count: usize ) -> Result<MeshCPU, &'static str>
Create a new MeshCPU object with the given vertex and index count
Arguments
vertex_count
- The number of vertices in the meshindex_count
- The number of indices in the mesh
Returns
Result<MeshCPU, &'static str>
- The new MeshCPU object, or an error message
Example
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::new(3, 3).unwrap();
}
cgl_rs::shutdown();
sourcepub fn triangle(
a: Vector3,
b: Vector3,
c: Vector3
) -> Result<MeshCPU, &'static str>
pub fn triangle( a: Vector3, b: Vector3, c: Vector3 ) -> Result<MeshCPU, &'static str>
Creates a new MeshCPU object with a single triangle
Arguments
a
- The first vertex of the triangleb
- The second vertex of the trianglec
- The third vertex of the triangle
Returns
Result<MeshCPU, &'static str>
- The new MeshCPU object, or an error message
Example
use cgl_rs::math::*;
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::triangle(
Vector3::new(0.0, 0.0, 0.0),
Vector3::new(1.0, 0.0, 0.0),
Vector3::new(0.0, 1.0, 0.0)
).unwrap();
}
cgl_rs::shutdown();
sourcepub fn plane(
front: Vector3,
right: Vector3,
resolution: i32,
scale: f32
) -> Result<MeshCPU, &'static str>
pub fn plane( front: Vector3, right: Vector3, resolution: i32, scale: f32 ) -> Result<MeshCPU, &'static str>
Creates a new MeshCPU object representing a plane with the given front and right vectors, resolution, and scale.
Arguments
front
- The front vector of the planeright
- The right vector of the planeresolution
- The number of subdivisions along each axis of the planescale
- The scale of the plane
Returns
Result<MeshCPU, &'static str>
- The new MeshCPU object, or an error message
Example
use cgl_rs::math::*;
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::plane(
Vector3::new(0.0, 0.0, 1.0),
Vector3::new(1.0, 0.0, 0.0),
10,
1.0
).unwrap();
}
cgl_rs::shutdown();
sourcepub fn quad(
a: Vector3,
b: Vector3,
c: Vector3,
d: Vector3
) -> Result<MeshCPU, &'static str>
pub fn quad( a: Vector3, b: Vector3, c: Vector3, d: Vector3 ) -> Result<MeshCPU, &'static str>
Creates a new MeshCPU object representing a quad with the given vertices.
Arguments
a
- The first vertex of the quadb
- The second vertex of the quadc
- The third vertex of the quadd
- The fourth vertex of the quad
Returns
Result<MeshCPU, &'static str>
- The new MeshCPU object, or an error message
Example
use cgl_rs::math::*;
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::quad(
Vector3::new(-1.0, -1.0, 0.0),
Vector3::new(1.0, -1.0, 0.0),
Vector3::new(1.0, 1.0, 0.0),
Vector3::new(-1.0, 1.0, 0.0)
).unwrap();
}
cgl_rs::shutdown();
sourcepub fn cube(use_3d_tex_coords: bool) -> Result<MeshCPU, &'static str>
pub fn cube(use_3d_tex_coords: bool) -> Result<MeshCPU, &'static str>
Creates a new MeshCPU object representing a cube.
Arguments
use_3d_tex_coords
- Whether to use 3D texture coordinates
Returns
Result<MeshCPU, &'static str>
- The new MeshCPU object, or an error message
Example
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::cube(true).unwrap();
}
cgl_rs::shutdown();
sourcepub fn sphere(res_u: i32, res_v: i32) -> Result<MeshCPU, &'static str>
pub fn sphere(res_u: i32, res_v: i32) -> Result<MeshCPU, &'static str>
Creates a new MeshCPU object representing a sphere.
Arguments
res_u
- The number of subdivisions along the u-axis of the sphereres_v
- The number of subdivisions along the v-axis of the sphere
Returns
Result<MeshCPU, &'static str>
- The new MeshCPU object, or an error message
Example
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::sphere(10, 10).unwrap();
}
cgl_rs::shutdown();
sourcepub fn cylinder(
start: Vector3,
end: Vector3,
radius0: f32,
radius1: f32,
resolution: i32
) -> Result<MeshCPU, &'static str>
pub fn cylinder( start: Vector3, end: Vector3, radius0: f32, radius1: f32, resolution: i32 ) -> Result<MeshCPU, &'static str>
Creates a new MeshCPU object representing a cylinder.
Arguments
start
- The start position of the cylinderend
- The end position of the cylinderradius0
- The radius of the cylinder at the start positionradius1
- The radius of the cylinder at the end positionresolution
- The number of subdivisions around the cylinder
Returns
Result<MeshCPU, &'static str>
- The new MeshCPU object, or an error message
Example
use cgl_rs::math::*;
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::cylinder(
Vector3::new(0.0, 0.0, 0.0),
Vector3::new(0.0, 1.0, 0.0),
1.0,
1.0,
10
).unwrap();
}
cgl_rs::shutdown();
sourcepub fn add_mesh(&self, other: &MeshCPU)
pub fn add_mesh(&self, other: &MeshCPU)
Adds the vertices and indices of another MeshCPU object to this MeshCPU object.
Arguments
other
- The MeshCPU object to add to this MeshCPU object
Example
cgl_rs::init();
{
let mesh1 = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
let mesh2 = cgl_rs::graphics::MeshCPU::sphere(3, 3).unwrap();
mesh1.add_mesh(&mesh2);
}
cgl_rs::shutdown();
sourcepub fn add_sphere(&self, res_u: i32, res_v: i32)
pub fn add_sphere(&self, res_u: i32, res_v: i32)
Adds the vertices and indices of a sphere to this MeshCPU object.
Arguments
res_u
- The number of subdivisions along the u-axis of the sphereres_v
- The number of subdivisions along the v-axis of the sphere
Example
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
mesh.add_sphere(2, 2);
}
cgl_rs::shutdown();
sourcepub fn add_triangle(&self, a: Vector3, b: Vector3, c: Vector3)
pub fn add_triangle(&self, a: Vector3, b: Vector3, c: Vector3)
Adds a triangle to this MeshCPU object.
Arguments
a
- The first vertex of the triangleb
- The second vertex of the trianglec
- The third vertex of the triangle
Example
use cgl_rs::math::*;
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
mesh.add_triangle(Vector3::new(0.0, 0.0, 0.0), Vector3::new(1.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 0.0));
}
cgl_rs::shutdown();
sourcepub fn add_quad(&self, a: Vector3, b: Vector3, c: Vector3, d: Vector3)
pub fn add_quad(&self, a: Vector3, b: Vector3, c: Vector3, d: Vector3)
Adds a quad to this MeshCPU object.
Arguments
a
- The first vertex of the quadb
- The second vertex of the quadc
- The third vertex of the quadd
- The fourth vertex of the quad
Example
use cgl_rs::math::*;
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
mesh.add_quad(Vector3::new(0.0, 0.0, 0.0), Vector3::new(1.0, 0.0, 0.0), Vector3::new(1.0, 1.0, 0.0), Vector3::new(0.0, 1.0, 0.0));
}
cgl_rs::shutdown();
sourcepub fn add_cylinder(
&self,
start: Vector3,
end: Vector3,
radius0: f32,
radius1: f32,
resolution: i32
)
pub fn add_cylinder( &self, start: Vector3, end: Vector3, radius0: f32, radius1: f32, resolution: i32 )
Arguments
start
- The starting point of the cylinderend
- The ending point of the cylinderradius0
- The radius of the cylinder at the starting pointradius1
- The radius of the cylinder at the ending pointresolution
- The number of subdivisions around the circumference of the cylinder
Example
use cgl_rs::math::*;
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
mesh.add_cylinder(Vector3::new(0.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 0.0), 0.5, 0.5, 10);
}
cgl_rs::shutdown();
sourcepub fn offset_vertices(&self, offset: Vector3)
pub fn offset_vertices(&self, offset: Vector3)
sourcepub fn scale_vertices(&self, scale: f32)
pub fn scale_vertices(&self, scale: f32)
sourcepub fn transform_vertices(&self, transform: &Matrix4x4)
pub fn transform_vertices(&self, transform: &Matrix4x4)
sourcepub fn destroy(&mut self)
pub fn destroy(&mut self)
Destroy the MeshCPU object
Example
cgl_rs::init();
{
let mut mesh = cgl_rs::graphics::MeshCPU::new(3, 3).unwrap();
mesh.destroy(); // or just let the mesh go out of scope
}
cgl_rs::shutdown();
sourcepub fn recalculate_normals(&self)
pub fn recalculate_normals(&self)
Recalculates the normals of the mesh
Example
cgl_rs::init();
{
let mesh = cgl_rs::graphics::MeshCPU::new(3, 3).unwrap();
mesh.recalculate_normals();
}
cgl_rs::shutdown();
sourcepub fn get_vertex(&self, index: usize) -> &MeshVertex
pub fn get_vertex(&self, index: usize) -> &MeshVertex
sourcepub fn set_vertex(&self, index: usize, vertex: &MeshVertex)
pub fn set_vertex(&self, index: usize, vertex: &MeshVertex)
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for MeshCPU
impl !Send for MeshCPU
impl !Sync for MeshCPU
impl Unpin for MeshCPU
impl UnwindSafe for MeshCPU
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more