[][src]Struct blender_mesh::BlenderMesh

pub struct BlenderMesh {
    pub vertex_positions: Vec<f32>,
    pub vertex_position_indices: Vec<u16>,
    pub num_vertices_in_each_face: Vec<u8>,
    pub vertex_normals: Vec<f32>,
    pub vertex_normal_indices: Option<Vec<u16>>,
    pub vertex_uvs: Option<Vec<f32>>,
    pub vertex_uv_indices: Option<Vec<u16>>,
    pub armature_name: Option<String>,
    pub vertex_group_indices: Option<Vec<u8>>,
    pub vertex_group_weights: Option<Vec<f32>>,
    pub bounding_box: BoundingBox,
    // some fields omitted
}

All of the data about a Blender mesh

Fields

vertex_positions: Vec<f32>

All of the mesh's vertices. Three items in the vector make one vertex. So indices 0, 1 and 2 are a vertex, 3, 4 and 5 are a vertex.. etc. [v1x, v1y, v1z, v2x, v2y, v2z, ...]

vertex_position_indices: Vec<u16>

The indices within vertex positions that make up each triangle in our mesh. Three vertex position indices correspond to one triangle [0, 1, 2, 0, 2, 3, ...]

num_vertices_in_each_face: Vec<u8>

TODO: enum..? if they're all equal we replace the MyEnum::PerVertex(Vec) with MyEnum::Equal(4)

vertex_normals: Vec<f32>vertex_normal_indices: Option<Vec<u16>>vertex_uvs: Option<Vec<f32>>

If your mesh is textured these will be all of the mesh's vertices' uv coordinates. Every vertex has two UV coordinates. [v1s, v1t, v2s, v2t, v3s, v3t] TODO: Combine vertex_uvs, vertex_uv_indices, texture_name into texture_info

vertex_uv_indices: Option<Vec<u16>>armature_name: Option<String>vertex_group_indices: Option<Vec<u8>>

TODO: When we move to single index triangulate and add new vertices give those vertices the same group indices / weights TODO: A function that trims this down to n weights and indices per vertex. Similar to our triangulate function TODO: Make sure that when we combine vertex indices we expand our group weights

vertex_group_weights: Option<Vec<f32>>bounding_box: BoundingBox

Methods

impl BlenderMesh[src]

pub fn combine_vertex_indices(&mut self, config: &CreateSingleIndexConfig)[src]

We export our models with indices for positions, normals and uvs because

  1. Easier because we we can unit test that here vs. a blender python script that's much trickier to test.
  2. Reduces amount of data required to represent the model on disk.

OpenGL only supports one index buffer, we convert our vertex data from having three indices to having one. This usually requires some duplication of vertex data. We duplicate the minimum amount of vertex data necessary.

TODO: Need to continue refactoring

TODO: Make this function set BlenderMesh.vertex_data = VertexData::SingleIndexVertexData

TODO: Don't work on additionally functionality until we've broken up these tests and implementation into smaller, specific pieces.

impl BlenderMesh[src]

pub fn materials(&self) -> &HashMap<String, PrincipledBSDF>[src]

Get the materials for this mesh, indexed by their name

impl BlenderMesh[src]

pub fn vertex_tangents(&self) -> Option<&Vec<f32>>[src]

Get the tangent vector for each vertex

impl BlenderMesh[src]

pub fn triangulate(&mut self)[src]

When exporting a mesh from Blender, faces will usually have 4 vertices (quad) but some faces might have 3 (triangle).

We read self.num_vertices_in_each_face to check how many vertices each face has.

If a face has 4 vertices we convert it into two triangles, each with 3 vertices.

Panics

Panics if a face has more than 4 vertices. In the future we might support 5+ vertices, but I haven't run into that yet. Not even sure if Blender can have faces with 5 vertices..

impl BlenderMesh[src]

pub fn y_up(&mut self)[src]

Blender meshes get exported with a Z up coordinate system. Here we flip our coordinate system to be y up

@see https://gamedev.stackexchange.com/a/7932

TODO: When we have bone data we'll need to change them to port change-mat4-coordinate-system into here. https://github.com/chinedufn/change-mat4-coordinate-system/blob/master/change-mat4-coordinate-system.js

impl BlenderMesh[src]

pub fn from_json(json_str: &str) -> Result<BlenderMesh, Error>[src]

Trait Implementations

impl PartialEq<BlenderMesh> for BlenderMesh[src]

impl Debug for BlenderMesh[src]

impl Serialize for BlenderMesh[src]

impl<'de> Deserialize<'de> for BlenderMesh[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>,