Struct cgl_rs::graphics::MeshCPU

source ·
pub struct MeshCPU { /* private fields */ }

Implementations§

source§

impl MeshCPU

source

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 mesh
  • index_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();
source

pub fn load_obj(path: &str) -> Result<MeshCPU, &'static str>

Loads a mesh from an OBJ file

Arguments
  • path - The path to the OBJ file
Returns
  • Result<MeshCPU, &'static str> - The loaded MeshCPU object, or an error message
Example
cgl_rs::init();
{
    let mesh = cgl_rs::graphics::MeshCPU::load_obj("path/to/mesh.obj").unwrap();
}
cgl_rs::shutdown();
source

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 triangle
  • b - The second vertex of the triangle
  • c - 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();
source

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 plane
  • right - The right vector of the plane
  • resolution - The number of subdivisions along each axis of the plane
  • scale - 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();
source

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 quad
  • b - The second vertex of the quad
  • c - The third vertex of the quad
  • d - 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();
source

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();
source

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 sphere
  • res_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();
source

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 cylinder
  • end - The end position of the cylinder
  • radius0 - The radius of the cylinder at the start position
  • radius1 - The radius of the cylinder at the end position
  • resolution - 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();
source

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();
source

pub fn add_cube(&self, use_3d_tex_coords: bool)

Adds the vertices and indices of a cube to this MeshCPU object.

Arguments
  • use_3d_tex_coords - Whether or not to use 3D texture coordinates
Example
cgl_rs::init();
{
   let mesh = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
   mesh.add_cube(true);
}
cgl_rs::shutdown();
source

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 sphere
  • res_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();
source

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 triangle
  • b - The second vertex of the triangle
  • c - 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();
source

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 quad
  • b - The second vertex of the quad
  • c - The third vertex of the quad
  • d - 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();
source

pub fn add_cylinder( &self, start: Vector3, end: Vector3, radius0: f32, radius1: f32, resolution: i32 )

Arguments
  • start - The starting point of the cylinder
  • end - The ending point of the cylinder
  • radius0 - The radius of the cylinder at the starting point
  • radius1 - The radius of the cylinder at the ending point
  • resolution - 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();
source

pub fn offset_vertices(&self, offset: Vector3)

Arguments
  • offset - The vector by which to offset the vertices
Example
use cgl_rs::math::*;
cgl_rs::init();
{
   let mesh = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
   mesh.offset_vertices(Vector3::new(1.0, 0.0, 0.0));
}
cgl_rs::shutdown();
source

pub fn scale_vertices(&self, scale: f32)

Arguments
  • scale - The factor by which to scale the vertices
Example
cgl_rs::init();
{
   let mesh = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
   mesh.scale_vertices(2.0);
}
cgl_rs::shutdown();
source

pub fn transform_vertices(&self, transform: &Matrix4x4)

Arguments
  • transform - The transformation matrix by which to transform the vertices
Example
use cgl_rs::math::*;
cgl_rs::init();
{
   let mesh = cgl_rs::graphics::MeshCPU::new(100, 100).unwrap();
   let transform = Matrix4x4::identity();
   mesh.transform_vertices(&transform);
}
cgl_rs::shutdown();
source

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();
source

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();
source

pub fn get_vertex(&self, index: usize) -> &MeshVertex

Arguments
  • index - The index of the vertex to retrieve
Example
cgl_rs::init();
{
    let mesh = cgl_rs::graphics::MeshCPU::new(3, 3).unwrap();
    let vertex = mesh.get_vertex(0);
}
cgl_rs::shutdown();
source

pub fn set_vertex(&self, index: usize, vertex: &MeshVertex)

Arguments
  • index - The index of the vertex to set
  • vertex - The vertex to set
Example
cgl_rs::init();
{
    let mesh = cgl_rs::graphics::MeshCPU::new(3, 3).unwrap();
    let vertex = cgl_rs::graphics::MeshVertex::new();
    mesh.set_vertex(0, &vertex);
}
cgl_rs::shutdown();
source

pub fn get_index(&self, index: usize) -> u32

Arguments
  • index - The index of the index to retrieve
Example
cgl_rs::init();
{
    let mesh = cgl_rs::graphics::MeshCPU::new(3, 3).unwrap();
    let index = mesh.get_index(0);
}
cgl_rs::shutdown();
source

pub fn set_index(&self, index: usize, value: u32)

Arguments
  • index - The index of the index to set
  • value - The value to set
Example
cgl_rs::init();
{
    let mesh = cgl_rs::graphics::MeshCPU::new(3, 3).unwrap();
    mesh.set_index(0, 1);
}
cgl_rs::shutdown();

Trait Implementations§

source§

impl Clone for MeshCPU

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Drop for MeshCPU

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.