pub struct Vertex { /* private fields */ }Expand description
Universal vertex structure containing all possible vertex attributes.
Not all fields are used by all vertex formats - the format and material type determine which fields contain valid data. Fields are stored with various compression techniques in the binary format.
§Field Usage by Format
- Static: position, UVs, normal, tangent, bitangent
- Weighted: Static fields + bone_indices (2) + weights (2)
- Cinematic: Static fields + bone_indices (4) + weights (4)
- Collision: position only
- Grass: position, UVs, normal, + grass-specific data
- ClothSim: Similar to Weighted with cloth data
§Compression Notes
When reading from file:
- Position is often stored as Vector4 of f16 (half-precision)
- UVs stored as f16
- Normals/tangents/bitangents stored as u8 normalized vectors
- Bone weights stored as u8 percentages
Implementations§
Source§impl Vertex
impl Vertex
Sourcepub fn position(&self) -> &Vector4<f32>
pub fn position(&self) -> &Vector4<f32>
3D position of the vertex (x, y, z, w). Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn texture_coordinate(&self) -> &Vector2<f32>
pub fn texture_coordinate(&self) -> &Vector2<f32>
Primary texture UV coordinates (u, v). Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn texture_coordinate2(&self) -> &Vector2<f32>
pub fn texture_coordinate2(&self) -> &Vector2<f32>
Secondary texture UV coordinates (u, v) for multi-texturing. Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn normal(&self) -> &Vector4<f32>
pub fn normal(&self) -> &Vector4<f32>
Vertex normal vector for lighting calculations (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn tangent(&self) -> &Vector4<f32>
pub fn tangent(&self) -> &Vector4<f32>
Tangent vector for normal mapping (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn bitangent(&self) -> &Vector4<f32>
pub fn bitangent(&self) -> &Vector4<f32>
Bitangent vector for normal mapping (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn color(&self) -> &Vector4<f32>
pub fn color(&self) -> &Vector4<f32>
Vertex color (r, g, b, a). Typically unused in modern rendering (textures used instead).
Sourcepub fn bone_indices(&self) -> &Vector4<u8>
pub fn bone_indices(&self) -> &Vector4<u8>
Bone indices for skeletal animation (up to 4 bones). For Weighted format: only first 2 are used. For Cinematic format: all 4 are used.
Source§impl Vertex
impl Vertex
Sourcepub fn position_mut(&mut self) -> &mut Vector4<f32>
pub fn position_mut(&mut self) -> &mut Vector4<f32>
3D position of the vertex (x, y, z, w). Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn texture_coordinate_mut(&mut self) -> &mut Vector2<f32>
pub fn texture_coordinate_mut(&mut self) -> &mut Vector2<f32>
Primary texture UV coordinates (u, v). Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn texture_coordinate2_mut(&mut self) -> &mut Vector2<f32>
pub fn texture_coordinate2_mut(&mut self) -> &mut Vector2<f32>
Secondary texture UV coordinates (u, v) for multi-texturing. Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn normal_mut(&mut self) -> &mut Vector4<f32>
pub fn normal_mut(&mut self) -> &mut Vector4<f32>
Vertex normal vector for lighting calculations (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn tangent_mut(&mut self) -> &mut Vector4<f32>
pub fn tangent_mut(&mut self) -> &mut Vector4<f32>
Tangent vector for normal mapping (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn bitangent_mut(&mut self) -> &mut Vector4<f32>
pub fn bitangent_mut(&mut self) -> &mut Vector4<f32>
Bitangent vector for normal mapping (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn color_mut(&mut self) -> &mut Vector4<f32>
pub fn color_mut(&mut self) -> &mut Vector4<f32>
Vertex color (r, g, b, a). Typically unused in modern rendering (textures used instead).
Sourcepub fn bone_indices_mut(&mut self) -> &mut Vector4<u8>
pub fn bone_indices_mut(&mut self) -> &mut Vector4<u8>
Bone indices for skeletal animation (up to 4 bones). For Weighted format: only first 2 are used. For Cinematic format: all 4 are used.
Sourcepub fn weights_mut(&mut self) -> &mut Vector4<f32>
pub fn weights_mut(&mut self) -> &mut Vector4<f32>
Bone weights for skeletal animation (up to 4 weights, should sum to 1.0). Often stored as u8 percentages in file, expanded to f32 in memory.
Source§impl Vertex
impl Vertex
Sourcepub fn set_position(&mut self, val: Vector4<f32>) -> &mut Self
pub fn set_position(&mut self, val: Vector4<f32>) -> &mut Self
3D position of the vertex (x, y, z, w). Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn set_texture_coordinate(&mut self, val: Vector2<f32>) -> &mut Self
pub fn set_texture_coordinate(&mut self, val: Vector2<f32>) -> &mut Self
Primary texture UV coordinates (u, v). Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn set_texture_coordinate2(&mut self, val: Vector2<f32>) -> &mut Self
pub fn set_texture_coordinate2(&mut self, val: Vector2<f32>) -> &mut Self
Secondary texture UV coordinates (u, v) for multi-texturing. Often stored as f16 in file, expanded to f32 in memory.
Sourcepub fn set_normal(&mut self, val: Vector4<f32>) -> &mut Self
pub fn set_normal(&mut self, val: Vector4<f32>) -> &mut Self
Vertex normal vector for lighting calculations (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn set_tangent(&mut self, val: Vector4<f32>) -> &mut Self
pub fn set_tangent(&mut self, val: Vector4<f32>) -> &mut Self
Tangent vector for normal mapping (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn set_bitangent(&mut self, val: Vector4<f32>) -> &mut Self
pub fn set_bitangent(&mut self, val: Vector4<f32>) -> &mut Self
Bitangent vector for normal mapping (x, y, z, w). Often stored as u8 normalized in file, expanded to f32 in memory.
Sourcepub fn set_color(&mut self, val: Vector4<f32>) -> &mut Self
pub fn set_color(&mut self, val: Vector4<f32>) -> &mut Self
Vertex color (r, g, b, a). Typically unused in modern rendering (textures used instead).
Sourcepub fn set_bone_indices(&mut self, val: Vector4<u8>) -> &mut Self
pub fn set_bone_indices(&mut self, val: Vector4<u8>) -> &mut Self
Bone indices for skeletal animation (up to 4 bones). For Weighted format: only first 2 are used. For Cinematic format: all 4 are used.
Sourcepub fn set_weights(&mut self, val: Vector4<f32>) -> &mut Self
pub fn set_weights(&mut self, val: Vector4<f32>) -> &mut Self
Bone weights for skeletal animation (up to 4 weights, should sum to 1.0). Often stored as u8 percentages in file, expanded to f32 in memory.
Source§impl Vertex
impl Vertex
Sourcepub fn read<R: ReadBytes>(
data: &mut R,
version: u32,
vtype: VertexFormat,
mtype: MaterialType,
) -> Result<Self>
pub fn read<R: ReadBytes>( data: &mut R, version: u32, vtype: VertexFormat, mtype: MaterialType, ) -> Result<Self>
Reads a vertex from binary data based on the vertex format and material type.
Different combinations of vertex format and material type have different binary layouts. This function dispatches to the appropriate reading logic based on the format/material combination.
§Arguments
data- Binary data source.version- RigidModel version (affects layout for some formats).vtype- Vertex format specifying the data layout.mtype- Material type (affects layout for static vertices).
§Errors
Returns an error if:
- The vertex format is unknown (
RLibError::DecodingRigidModelUnknownVertexFormat) - The vertex format is unsupported for the material type
(
RLibError::DecodingRigidModelUnsupportedVertexFormatForMaterial)
Sourcepub fn write<W: WriteBytes>(
&self,
data: &mut W,
version: u32,
vtype: VertexFormat,
mtype: MaterialType,
) -> Result<()>
pub fn write<W: WriteBytes>( &self, data: &mut W, version: u32, vtype: VertexFormat, mtype: MaterialType, ) -> Result<()>
Writes a vertex to binary data based on the vertex format and material type.
Different combinations of vertex format and material type have different binary layouts. This function dispatches to the appropriate writing logic based on the format/material combination.
§Arguments
data- Output buffer.version- RigidModel version (affects layout for some formats).vtype- Vertex format specifying the data layout.mtype- Material type (affects layout for static vertices).
§Errors
Returns an error if:
- The vertex format is unknown (
RLibError::DecodingRigidModelUnknownVertexFormat) - The vertex format is unsupported for the material type
(
RLibError::DecodingRigidModelUnsupportedVertexFormatForMaterial)
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Vertex
impl<'de> Deserialize<'de> for Vertex
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Vertex
Auto Trait Implementations§
impl Freeze for Vertex
impl RefUnwindSafe for Vertex
impl Send for Vertex
impl Sync for Vertex
impl Unpin for Vertex
impl UnsafeUnpin for Vertex
impl UnwindSafe for Vertex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.