Skip to main content

InstanceDesc3D

Struct InstanceDesc3D 

Source
pub struct InstanceDesc3D {
    pub pos_attr: Pos3DATTR,
    pub rot_attr: Rot3DATTR,
    pub scale_attr: Scale3DATTR,
    pub col_attr: ColATTR,
    pub cus_attrs: Vec<CustomATTR>,
}
Expand description

Descriptor for preparing 3D instance data before uploading it to the GPU.

An instance buffer packs per-instance attributes (position, rotation, scale, colour, and custom attributes) into a single interleaved GPU buffer. This type collects attribute data on the CPU side and interleaves them when ship is called.

§Attribute layout

Attributes appear in this fixed order within the interleaved stride:

  1. pos — 3 × f32 (12 bytes)
  2. rot — 4 × f32 quaternion (16 bytes)
  3. scale — 3 × f32 (12 bytes)
  4. col — 4 × f32 RGBA (16 bytes)
  5. custom attributes, in insertion order

Any of these may be omitted (left empty). The stride shrinks accordingly.

§Example

let mut desc = InstanceDesc3D::empty();

for i in 0..100 {
    desc.pos_attr.push([i as f32 * 2.0, 0.0, 0.0]);
    desc.col_attr.push([1.0, 0.0, 0.0, 1.0]);
}

// desc.ship() transfers the interleaved data to a GPU buffer.

Fields§

§pos_attr: Pos3DATTR§rot_attr: Rot3DATTR§scale_attr: Scale3DATTR§col_attr: ColATTR§cus_attrs: Vec<CustomATTR>

Implementations§

Source§

impl InstanceDesc3D

Source

pub fn empty() -> Self

Creates an empty descriptor with no attributes.

Push per-instance data into the individual attribute fields before calling ship.

Source

pub fn from_positions(positions: &[Vector3<f32>]) -> Self

Builds a descriptor from an array of 3D positions.

All other attribute fields remain empty.

Source

pub fn from_transforms(transforms: &[Matrix4<f32>]) -> Self

Decomposes a slice of 4×4 transformation matrices into position, rotation (quaternion), and scale attributes.

This is a convenience constructor for users who already have transform matrices. It assumes no shear and extracts a unit quaternion from the upper-left 3×3 sub-matrix.

§Panics

May produce degenerate quaternions when a scale component is zero.

Source

pub fn attach_custom_attr(&mut self, attr: CustomATTR) -> &mut Self

Appends a custom (user-defined) attribute.

Custom attribute names must not collide with the reserved names iPos, iRot, iScale, or iColor, and must be unique among themselves.

Returns &mut self for chaining.

Source

pub fn ship(&self) -> OpticResult<InstanceBuffer>

Interleaves all non-empty attributes and uploads them to a new GPU buffer.

Returns an InstanceBuffer ready for use in instanced draws.

§Errors
  • Returns an error if all attributes are empty (no data to upload).
  • Returns an error if non-empty attributes have mismatched element counts.
  • Returns an error if custom attribute names collide with reserved names or each other.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

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

impl<T> Upcast<T> for T

Source§

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