Struct Mesh3D

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

A 3D mesh made up of vertices, faces made of indices into vertices, and a transformation.

Fields§

§transform: Transform3D

The mesh’s transform matrix in 3D space

§vertices: Vec<Vec3D>

A vector of the Mesh3D’s vertices

§faces: Vec<Face>

A vector of Faces of indexes into vertices

Implementations§

Source§

impl Mesh3D

Source

pub fn default_cube() -> Self

The gemini_engine equivalent of Blender’s default cube. Has sides of length 2

Examples found in repository?
examples/spinning-cube.rs (line 22)
14fn main() {
15    let mut view = View::new(100, 50, ColChar::EMPTY);
16
17    let mut viewport = Viewport::new(
18        Transform3D::look_at_lh(Vec3D::new(0.0, -1.5, 4.3), Vec3D::ZERO, Vec3D::Y),
19        FOV,
20        view.center(),
21    );
22    viewport.objects.push(Mesh3D::default_cube());
23
24    viewport.display_mode = DisplayMode::Illuminated {
25        lights: vec![
26            Light::new_ambient(0.3),
27            Light::new_directional(0.6, Vec3D::new(0.5, 1.0, 1.0)),
28        ],
29    };
30
31    fps_gameloop!(
32        {
33            viewport.objects[0].transform = viewport.objects[0]
34                .transform
35                .mul_mat4(&Transform3D::from_rotation_y(-0.05));
36        },
37        {
38            view.clear();
39            view.draw(&viewport);
40            let _ = view.display_render();
41        },
42        FPS,
43        |elapsed: Duration, frame_skip| {
44            println!(
45                "Elapsed: {:.2?}µs | Frame skip: {}",
46                elapsed.as_micros(),
47                frame_skip
48            );
49        }
50    );
51}
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 28)
13fn main() {
14    let mut view = View::new(100, 45, ColChar::EMPTY);
15    let mut viewport = Viewport::new(
16        Transform3D::look_at_lh(Vec3D::new(0.0, -3.0, 6.0), Vec3D::ZERO, Vec3D::Y),
17        FOV,
18        view.center(),
19    );
20
21    viewport.display_mode = DisplayMode::Illuminated {
22        lights: vec![
23            Light::new_ambient(0.3),
24            Light::new_directional(0.7, Vec3D::new(1.0, 1.0, 1.0)),
25        ],
26    };
27
28    viewport.objects.push(Mesh3D::torus(1.8, 1.0, 32, 16));
29
30    loop {
31        let donut_tr = &mut viewport.objects[0].transform;
32        *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_y(-0.03));
33        *donut_tr = donut_tr.mul_mat4(&Transform3D::from_rotation_x(0.03));
34
35        view.clear();
36        view.draw(&viewport);
37        let _ = view.display_render();
38
39        thread::sleep(Duration::from_secs_f32(1.0 / FPS));
40    }
41}
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. Since this Mesh does not have a real triangle mesh, it is only visible in DisplayMode::Wireframe

Source§

impl Mesh3D

Source

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

Create a Mesh3D with an identity Transform3D

Source

pub const fn with_transform(self, transform: Transform3D) -> Self

Return the Mesh3D with an updated transform property. Consumes the original Mesh3D

Trait Implementations§

Source§

impl Clone for Mesh3D

Source§

fn clone(&self) -> Mesh3D

Returns a duplicate 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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>,

Source§

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>,

Source§

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.