Skip to main content

Model

Struct Model 

Source
pub struct Model {
    pub meshes: Vec<Mesh>,
    pub materials: Vec<Material>,
    pub transform: Mat4,
    pub highlight: Color,
    pub bounding_center: Vec3,
    pub bounding_radius: f32,
    /* private fields */
}

Fields§

§meshes: Vec<Mesh>§materials: Vec<Material>§transform: Mat4

Model matrix applied to every vertex in world space. Defaults to glam::Mat4::IDENTITY. Prefer building it up through the Transformable methods.

§highlight: Color

RGBA overlay blended over the model’s shaded color (mix(shaded, highlight.rgb, highlight.a) in the fragment shader). Alpha 0 (the default) means no highlight at all. Intended for editor-style hover/selection feedback rather than gameplay use.

§bounding_center: Vec3

Center of the model’s bounding sphere, in local (pre-transform) space.

§bounding_radius: f32

Radius of the model’s bounding sphere, in local (pre-transform) space. Computed once at load time since the raw vertex positions aren’t retained after upload to the GPU.

Implementations§

Source§

impl Model

Source

pub fn load(renderer: &Renderer<'_>, path: impl AsRef<Path>) -> Result<Self>

Loads a Wavefront OBJ model (and its referenced .mtl materials and textures) from path. Texture paths in the .mtl file are resolved relative to the OBJ’s directory.

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Transformable for Model

Source§

fn transform(&self) -> Mat4

The current model matrix.
Source§

fn transform_mut(&mut self) -> &mut Mat4

Mutable access to the model matrix.
Source§

fn pivot(&self) -> Vec3

Local-space point that rotations and scales turn around. Defaults to the local origin.
Source§

fn set_transform(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Replaces the model matrix outright, discarding any accumulated transforms.
Source§

fn reset_transform(&mut self) -> &mut Self
where Self: Sized,

Clears the model matrix back to the identity.
Source§

fn apply(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Composes transform onto the current matrix, about the local origin.
Source§

fn apply_about_pivot(&mut self, transform: Mat4) -> &mut Self
where Self: Sized,

Composes transform onto the current matrix, about Transformable::pivot.
Source§

fn translate(&mut self, x: f32, y: f32) -> &mut Self
where Self: Sized,

Moves along the local X and Y axes.
Source§

fn translate3(&mut self, offset: Vec3) -> &mut Self
where Self: Sized,

Moves by offset in local space.
Source§

fn rotate(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Z axis — the in-plane spin for 2D content.
Source§

fn rotate_degrees(&mut self, degrees: f32) -> &mut Self
where Self: Sized,

Transformable::rotate, taking degrees.
Source§

fn rotate_x(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the X axis.
Source§

fn rotate_y(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Y axis.
Source§

fn rotate_z(&mut self, radians: f32) -> &mut Self
where Self: Sized,

Rotates around the Z axis.
Source§

fn rotate_quat(&mut self, rotation: Quat) -> &mut Self
where Self: Sized,

Applies an arbitrary rotation.
Source§

fn scale(&mut self, x: f32, y: f32) -> &mut Self
where Self: Sized,

Scales the X and Y axes independently.
Source§

fn scale_uniform(&mut self, factor: f32) -> &mut Self
where Self: Sized,

Scales every axis by the same factor.
Source§

fn scale3(&mut self, scale: Vec3) -> &mut Self
where Self: Sized,

Scales by scale in local space.
Source§

fn flip_x(&mut self) -> &mut Self
where Self: Sized,

Mirrors across the pivot’s vertical axis.
Source§

fn flip_y(&mut self) -> &mut Self
where Self: Sized,

Mirrors across the pivot’s horizontal axis.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Model

§

impl !UnwindSafe for Model

§

impl Freeze for Model

§

impl Send for Model

§

impl Sync for Model

§

impl Unpin for Model

§

impl UnsafeUnpin for Model

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> Variant for T
where T: Any + Clone + SendSync,

§

fn as_any(&self) -> &(dyn Any + 'static)

Convert this [Variant] trait object to &dyn Any.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert this [Variant] trait object to &mut dyn Any.
§

fn as_boxed_any(self: Box<T>) -> Box<dyn Any>

Convert this [Variant] trait object to Box<dyn Any>.
§

fn type_name(&self) -> &'static str

Get the name of this type.
§

fn clone_object(&self) -> Box<dyn Variant>

Clone this [Variant] trait object.
§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more