ObjectData

Struct ObjectData 

Source
pub struct ObjectData { /* private fields */ }
Expand description

The type that is used to construct mod3d_base from a Gltf

The objects from the Gltf that are required by the client must be added to this, so that the node hierarchy can be interrogated to determine which buffers, views, accessors, meshes, images, samples, and textures are required

Once the objects are added the uses must be derived (no more objects can be added at this point).

Once derived the mod3d_base::Buffer required must be generated; then the mod3d_base::BufferData; then the mod3d_base::BufferDataAccessor. These generate Vec of the relevant types, which must remain live until any object is made into an Instantiable; the ObjectData maintains indiices into these Vec for the Gltf buffers (etc) that are used by the required objects.

Then the Vertices are created; these borrow from the previous Vec of Buffer-related structures

Finally a mod3d_base::Object can be created, from which the client can create a mod3d_base::Instantiable; at this point the buffer data and vertices can be dropped (if the mod3d_base::Renderable permits it)

Implementations§

Source§

impl ObjectData

Source

pub fn new(gltf: &Gltf) -> Self

Create a new ObjectData

Source

pub fn add_object(&mut self, gltf: &Gltf, node: NodeIndex)

Add an object to the ObjectData; adds all the nodes in the hierarchy of the specified node

Source

pub fn derive_uses(&mut self, gltf: &Gltf)

Derive which parts of the Gltf (and which parts of its buffers) are required for the selected objects

Source

pub fn uses_buffer_zero(&self) -> bool

Returns true if buffer index 0 is used by the objects

This is only valid after derive_uses has been invoked

Source

pub fn gen_buffers<B, BP>( &mut self, gltf: &mut Gltf, buf_parse: &BP, opt_buffer_0: Option<B>, ) -> Result<Vec<B>>
where BP: Fn(&str, usize) -> Result<B>,

Generate a Vec of all the buffers required for the objects used in Gltf

Drop the buffer descriptors in the GltfJsonValue as we go

The first comes from opt_buffer_0 if Some; this may come from a Glb file binary chunk, for example.

The rest are created by invoking buf_parse on the Uri and byte_length specified in the [GltfJsonValue]

Source

pub fn gen_byte_buffers<BP>( &mut self, gltf: &mut Gltf, buf_parse: &BP, opt_buffer_0: Option<Vec<u8>>, ) -> Result<Vec<Vec<u8>>>
where BP: Fn(&str, usize) -> Result<Vec<u8>>,

Generate a Vec of all the Vec buffers required for the objects used in the Gltf

This is the same as [gen_buffers] except that it requires the buffer type by Vec, and it also implicitly supports base64 decode of data: URIs

Source

pub fn gen_buffer_data<'buffers, B, F, R>( &mut self, buffer: &F, ) -> Vec<BufferData<'buffers, R>>
where B: ByteBuffer + ?Sized + 'buffers, F: Fn(usize) -> &'buffers B, R: Renderable,

Generate BufferData from all of the buffer views (one BufferData per view)

Should be invoked after gen_buffers has returned a Vec<> of the buffers used by the data

Source

pub fn gen_images<Image, F>( &mut self, gltf: &Gltf, get_image: &F, ) -> Result<Vec<Image>>
where F: for<'a> Fn((usize, usize, usize), &'a str) -> Result<Image, String>,

Generate a Vec of all the images

Source

pub fn gen_descriptors<'buffers, F, R>( &mut self, gltf: &Gltf, buffer_data: &F, ) -> Vec<BufferDescriptor<'buffers, R>>
where F: Fn(usize) -> &'buffers BufferData<'buffers, R>, R: Renderable,

Generate BufferDescriptor from all of the GltfBufferView

Should be invoked after gen_buffer_data has returned a Vec<> of the BufferData

This creates a vec of (ViewIndex, VecVertexDesc), from which an array of BufferDescriptor are created and returned

It also creates the something array which is then

Source

pub fn gen_accessors<'buffers, F, G, R>( &mut self, gltf: &Gltf, buffer_data: &F, buffer_desc: &G, ) -> (Vec<BufferIndexAccessor<'buffers, R>>, Vec<BufferDataAccessor<'buffers, R>>)
where F: Fn(usize) -> &'buffers BufferData<'buffers, R>, G: Fn(usize) -> &'buffers BufferDescriptor<'buffers, R>, R: Renderable,

Generate [BufferAccessor] from all of the accessors used by the mesh primitives used in the objects used in the Gltf

Should be invoked after gen_buffer_data has returned a Vec<> of the BufferData

Source

pub fn gen_vertices<'vertices, F, G, R>( &mut self, gltf: &Gltf, buffer_index_accessor: &F, buffer_data_accessor: &G, ) -> Vec<Vertices<'vertices, R>>
where F: Fn(usize) -> &'vertices BufferIndexAccessor<'vertices, R>, G: Fn(usize) -> &'vertices BufferDataAccessor<'vertices, R>, R: Renderable,

Generate vertices from the objects in the Gltf, given buffer accessors that have been generated already

Source

pub fn gen_textures<'call, 'textures, F, I, R, T>( &mut self, gltf: &Gltf, image: F, texture_of_image: T, ) -> Vec<Texture<'textures, R>>
where F: Fn(usize) -> &'call I, I: 'call, T: Fn(&'call I) -> Texture<'textures, R>, R: Renderable,

Generate textures from the objects in the Gltf, given images that have been generated already

Source

pub fn gen_materials(&mut self, gltf: &Gltf) -> Vec<PbrMaterial>

Source

pub fn gen_object<'object, M, R>( &mut self, gltf: &Gltf, vertices: &'object [Vertices<'object, R>], textures: &'object [Texture<'object, R>], materials: &'object [M], ) -> Object<'object, M, R>
where M: Material + 'object, R: Renderable,

Create object

Trait Implementations§

Source§

impl Debug for ObjectData

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Index<AccessorIndex> for ObjectData

Source§

type Output = Option<ODAccIndex>

The returned type after indexing.
Source§

fn index(&self, index: AccessorIndex) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<BufferIndex> for ObjectData

Source§

type Output = BufferUsage

The returned type after indexing.
Source§

fn index(&self, index: BufferIndex) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<MeshIndex> for ObjectData

Source§

type Output = Option<Vec<Option<ODVerticesIndex>>>

The returned type after indexing.
Source§

fn index(&self, index: MeshIndex) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Index<ViewIndex> for ObjectData

Source§

type Output = Option<ODBufDescIndex>

The returned type after indexing.
Source§

fn index(&self, index: ViewIndex) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl IndexMut<AccessorIndex> for ObjectData

Source§

fn index_mut(&mut self, index: AccessorIndex) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<BufferIndex> for ObjectData

Source§

fn index_mut(&mut self, index: BufferIndex) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<MeshIndex> for ObjectData

Source§

fn index_mut(&mut self, index: MeshIndex) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl IndexMut<ViewIndex> for ObjectData

Source§

fn index_mut(&mut self, index: ViewIndex) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more

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