Struct gemini_engine::elements3d::Mesh3D

source ·
pub struct Mesh3D {
    pub transform: Transform3D,
    pub vertices: Vec<Vec3D>,
    pub faces: Vec<Face>,
}
Expand description

The struct for a Mesh3D object, containing a position, rotation, collection of vertices and collection of Faces with indices to the vertex collection.

Fields§

§transform: Transform3D

The mesh’s transform (position, rotation, scale) in 3D space

§vertices: Vec<Vec3D>

A vector of the Mesh3D’s

§faces: Vec<Face>

A vector of Faces of indexes into Mesh3D::vertices

Implementations§

source§

impl Mesh3D

source

pub fn default_cube() -> Self

The gemini_engine equivalent of Blender’s default cube. Has side lengths of 2

Examples found in repository?
examples/spinning-cube.rs (line 19)
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
fn main() {
    let mut view = View::new(200, 90, ColChar::BACKGROUND);

    let viewport = Viewport::new(
        Transform3D::new_tr(Vec3D::new(0.0, 1.5, 4.0), Vec3D::new(-0.4, 0.0, 0.0)),
        FOV,
        view.center(),
    );

    let mut cube = Mesh3D::default_cube();

    fps_gameloop!(
        {
            view.clear();
            cube.transform.rotation.y -= 0.05;
        },
        {
            view.blit(
                &viewport.render(vec![&cube], DisplayMode::Solid),
                Wrapping::Ignore,
            );
            let _ = view.display_render();
        },
        FPS,
        |elapsed: gameloop::Duration, frame_skip| {
            println!(
                "Elapsed: {:.2?}µs | Frame skip: {}",
                elapsed.as_micros(),
                frame_skip
            );
        }
    );
}
source

pub fn torus( outer_radius: f64, inner_radius: f64, outer_segments: usize, inner_segments: usize ) -> Self

Create a torus (donut shape)

Examples found in repository?
examples/donut.rs (line 27)
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
fn main() {
    let mut view = View::new(82, 32, ColChar::EMPTY);
    let viewport = Viewport::new(
        Transform3D::new_tr(Vec3D::new(0.0, 0.0, 20.0), Vec3D::ZERO),
        FOV,
        view.center(),
    );

    let lights = vec![
        Light::new_ambient(0.3),
        Light::new_directional(0.7, Vec3D::new(1.0, -1.0, -1.0)),
    ];

    let mut donut = Mesh3D::torus(1.8, 1.0, 32, 16);

    fps_gameloop!(
        {
            donut.transform.rotation.x += 0.05;
            donut.transform.rotation.z += 0.05;
        },
        {
            view.clear();
            view.blit(
                &viewport.render(
                    vec![&donut],
                    DisplayMode::Illuminated {
                        lights: lights.clone(),
                    },
                ),
                Wrapping::Ignore,
            );
            let _ = view.display_render();
        },
        FPS
    );
}
source

pub fn gimbal() -> Self

A gimbal to help you orient in gemini_engine’s 3D space. The orientation is as follows (from the default Viewport)

  • X (red) increases as you move to the right
  • Y (green) increases as you move up
  • Z (blue) increases as you move away from the viewport

Think of it like Blender’s axes but with Y and Z swapped. This Mesh does not render in DisplayMode::SOLID (see DisplayMode documentation)

source§

impl Mesh3D

source

pub const fn new( transform: Transform3D, vertices: Vec<Vec3D>, faces: Vec<Face> ) -> Self

Create a Mesh3D with a default Transform3D

source

pub const fn new_at_origin(vertices: Vec<Vec3D>, faces: Vec<Face>) -> Self

Create a Mesh3D with a default Transform3D

Trait Implementations§

source§

impl Clone for Mesh3D

source§

fn clone(&self) -> Mesh3D

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 Debug for Mesh3D

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Mesh3D

§

impl RefUnwindSafe for Mesh3D

§

impl Send for Mesh3D

§

impl Sync for Mesh3D

§

impl Unpin for Mesh3D

§

impl UnwindSafe for Mesh3D

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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 T
where 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.