pub struct M2Model {Show 45 fields
pub header: M2Header,
pub name: Option<String>,
pub global_sequences: Vec<u32>,
pub animations: Vec<M2Animation>,
pub animation_lookup: Vec<u16>,
pub bones: Vec<M2Bone>,
pub key_bone_lookup: Vec<u16>,
pub vertices: Vec<M2Vertex>,
pub textures: Vec<M2Texture>,
pub materials: Vec<M2Material>,
pub particle_emitters: Vec<M2ParticleEmitter>,
pub ribbon_emitters: Vec<M2RibbonEmitter>,
pub texture_animations: Vec<M2TextureAnimation>,
pub color_animations: Vec<M2ColorAnimation>,
pub transparency_animations: Vec<M2TransparencyAnimation>,
pub events: Vec<M2Event>,
pub attachments: Vec<M2Attachment>,
pub cameras: Vec<M2Camera>,
pub lights: Vec<M2Light>,
pub raw_data: M2RawData,
pub skin_file_ids: Option<SkinFileIds>,
pub animation_file_ids: Option<AnimationFileIds>,
pub texture_file_ids: Option<TextureFileIds>,
pub physics_file_id: Option<PhysicsFileId>,
pub skeleton_file_id: Option<SkeletonFileId>,
pub bone_file_ids: Option<BoneFileIds>,
pub lod_data: Option<LodData>,
pub extended_particle_data: Option<ExtendedParticleData>,
pub parent_animation_blacklist: Option<ParentAnimationBlacklist>,
pub parent_animation_data: Option<ParentAnimationData>,
pub waterfall_effect: Option<WaterfallEffect>,
pub edge_fade_data: Option<EdgeFadeData>,
pub model_alpha_data: Option<ModelAlphaData>,
pub lighting_details: Option<LightingDetails>,
pub recursive_particle_ids: Option<RecursiveParticleIds>,
pub geometry_particle_ids: Option<GeometryParticleIds>,
pub texture_animation_chunk: Option<TextureAnimationChunk>,
pub particle_geoset_data: Option<ParticleGeosetData>,
pub dboc_chunk: Option<DbocChunk>,
pub afra_chunk: Option<AfraChunk>,
pub dpiv_chunk: Option<DpivChunk>,
pub parent_sequence_bounds: Option<ParentSequenceBounds>,
pub parent_event_data: Option<ParentEventData>,
pub collision_mesh_data: Option<CollisionMeshData>,
pub physics_file_data: Option<PhysicsFileDataChunk>,
}Expand description
Main M2 model structure
Fields§
§header: M2HeaderM2 header
name: Option<String>Model name
global_sequences: Vec<u32>Global sequences
animations: Vec<M2Animation>Animations
animation_lookup: Vec<u16>Animation lookups
bones: Vec<M2Bone>Bones
key_bone_lookup: Vec<u16>Key bone lookups
vertices: Vec<M2Vertex>Vertices
textures: Vec<M2Texture>Textures
materials: Vec<M2Material>Materials (render flags)
particle_emitters: Vec<M2ParticleEmitter>Particle emitters
ribbon_emitters: Vec<M2RibbonEmitter>Ribbon emitters
texture_animations: Vec<M2TextureAnimation>Texture animations
color_animations: Vec<M2ColorAnimation>Color animations
transparency_animations: Vec<M2TransparencyAnimation>Transparency animations
events: Vec<M2Event>Events
attachments: Vec<M2Attachment>Attachments
cameras: Vec<M2Camera>Cameras
lights: Vec<M2Light>Lights
raw_data: M2RawDataRaw data for other sections This is used to preserve data that we don’t fully parse yet
skin_file_ids: Option<SkinFileIds>Chunked format data (Legion+ only) Contains FileDataID references for external files
animation_file_ids: Option<AnimationFileIds>Animation file IDs (Legion+ only)
texture_file_ids: Option<TextureFileIds>Texture file IDs (Legion+ only)
physics_file_id: Option<PhysicsFileId>Physics file ID (Legion+ only)
skeleton_file_id: Option<SkeletonFileId>Skeleton file ID (Legion+ only)
bone_file_ids: Option<BoneFileIds>Bone file IDs (Legion+ only)
lod_data: Option<LodData>Level of detail data (Legion+ only)
extended_particle_data: Option<ExtendedParticleData>Advanced rendering features (Legion+ only) Extended particle data (EXPT/EXP2 chunks)
parent_animation_blacklist: Option<ParentAnimationBlacklist>Parent animation blacklist (PABC chunk)
parent_animation_data: Option<ParentAnimationData>Parent animation data (PADC chunk)
waterfall_effect: Option<WaterfallEffect>Waterfall effects (WFV1/WFV2/WFV3 chunks)
edge_fade_data: Option<EdgeFadeData>Edge fade rendering (EDGF chunk)
model_alpha_data: Option<ModelAlphaData>Model alpha calculations (NERF chunk)
lighting_details: Option<LightingDetails>Lighting details (DETL chunk)
recursive_particle_ids: Option<RecursiveParticleIds>Recursive particle model IDs (RPID chunk)
geometry_particle_ids: Option<GeometryParticleIds>Geometry particle model IDs (GPID chunk)
texture_animation_chunk: Option<TextureAnimationChunk>Phase 7 specialized chunks TXAC texture animation chunk
particle_geoset_data: Option<ParticleGeosetData>PGD1 particle geoset data
dboc_chunk: Option<DbocChunk>DBOC chunk (purpose unknown)
afra_chunk: Option<AfraChunk>AFRA chunk (purpose unknown)
dpiv_chunk: Option<DpivChunk>DPIV chunk (collision mesh for player housing)
parent_sequence_bounds: Option<ParentSequenceBounds>PSBC chunk (parent sequence bounds)
parent_event_data: Option<ParentEventData>PEDC chunk (parent event data)
collision_mesh_data: Option<CollisionMeshData>PCOL chunk (collision mesh data)
physics_file_data: Option<PhysicsFileDataChunk>PFDC chunk (physics file data)
Implementations§
Source§impl M2Model
impl M2Model
Sourcepub fn parse_embedded_skin(
&self,
original_m2_data: &[u8],
skin_index: usize,
) -> Result<SkinFile>
pub fn parse_embedded_skin( &self, original_m2_data: &[u8], skin_index: usize, ) -> Result<SkinFile>
Parse embedded skin profiles from pre-WotLK M2 models
For models with version <= 260, skin data is embedded in the M2 file itself. The views array contains ModelView structures with direct offsets to skin data.
Note: Many character models only have the first skin profile (index 0) properly embedded. Additional skin profiles may contain invalid data.
§Arguments
original_m2_data- The complete original M2 file dataskin_index- Index of the skin profile to extract (0-based)
§Returns
Returns the parsed SkinFile for the requested skin profile index
§Errors
Returns an error if the skin index is out of range or contains invalid data
§Example
// Load a pre-WotLK model
let m2_data = fs::read("HumanMale.m2")?;
let m2_format = parse_m2(&mut Cursor::new(&m2_data))?;
let model = m2_format.model();
if model.header.version <= 260 {
// Parse the first embedded skin profile
let skin = model.parse_embedded_skin(&m2_data, 0)?;
println!("Embedded skin has {} submeshes", skin.submeshes().len());
}Sourcepub fn embedded_skin_count(&self) -> Option<u32>
pub fn embedded_skin_count(&self) -> Option<u32>
Get the number of embedded skin profiles in a pre-WotLK model
Returns None if the model uses external skin files (version > 260)
Sourcepub fn has_embedded_skins(&self) -> bool
pub fn has_embedded_skins(&self) -> bool
Check if this model uses embedded skins (pre-WotLK) or external skin files
Source§impl M2Model
impl M2Model
Sourcepub fn parse_legacy<R: Read + Seek>(reader: &mut R) -> Result<Self>
pub fn parse_legacy<R: Read + Seek>(reader: &mut R) -> Result<Self>
Parse a legacy M2 model from a reader (MD20 format)
Sourcepub fn parse_chunked<R: Read + Seek>(reader: &mut R) -> Result<Self>
pub fn parse_chunked<R: Read + Seek>(reader: &mut R) -> Result<Self>
Parse a chunked M2 model from a reader (MD21 format)
Sourcepub fn load<P: AsRef<Path>>(path: P) -> Result<M2Format>
pub fn load<P: AsRef<Path>>(path: P) -> Result<M2Format>
Load an M2 model from a file with format detection
Sourcepub fn load_legacy<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn load_legacy<P: AsRef<Path>>(path: P) -> Result<Self>
Load a legacy M2 model from a file
Sourcepub fn write<W: Write + Seek>(&self, writer: &mut W) -> Result<()>
pub fn write<W: Write + Seek>(&self, writer: &mut W) -> Result<()>
Write an M2 model to a writer
Sourcepub fn convert(&self, target_version: M2Version) -> Result<Self>
pub fn convert(&self, target_version: M2Version) -> Result<Self>
Convert this model to a different version
Sourcepub fn has_external_files(&self) -> bool
pub fn has_external_files(&self) -> bool
Check if this model has external file references (Legion+ chunked format)
Sourcepub fn skin_file_count(&self) -> usize
pub fn skin_file_count(&self) -> usize
Get the number of skin files referenced
Sourcepub fn animation_file_count(&self) -> usize
pub fn animation_file_count(&self) -> usize
Get the number of animation files referenced
Sourcepub fn texture_file_count(&self) -> usize
pub fn texture_file_count(&self) -> usize
Get the number of texture files referenced
Sourcepub fn resolve_skin_path(
&self,
index: usize,
resolver: &dyn FileResolver,
) -> Result<String>
pub fn resolve_skin_path( &self, index: usize, resolver: &dyn FileResolver, ) -> Result<String>
Resolve a skin file path by index using a FileResolver
Sourcepub fn load_skin_file(
&self,
index: usize,
resolver: &dyn FileResolver,
) -> Result<Vec<u8>>
pub fn load_skin_file( &self, index: usize, resolver: &dyn FileResolver, ) -> Result<Vec<u8>>
Load a skin file by index using a FileResolver
Sourcepub fn resolve_animation_path(
&self,
index: usize,
resolver: &dyn FileResolver,
) -> Result<String>
pub fn resolve_animation_path( &self, index: usize, resolver: &dyn FileResolver, ) -> Result<String>
Resolve an animation file path by index using a FileResolver
Sourcepub fn load_animation_file(
&self,
index: usize,
resolver: &dyn FileResolver,
) -> Result<Vec<u8>>
pub fn load_animation_file( &self, index: usize, resolver: &dyn FileResolver, ) -> Result<Vec<u8>>
Load an animation file by index using a FileResolver
Sourcepub fn resolve_texture_path(
&self,
index: usize,
resolver: &dyn FileResolver,
) -> Result<String>
pub fn resolve_texture_path( &self, index: usize, resolver: &dyn FileResolver, ) -> Result<String>
Resolve a texture file path by index using a FileResolver Falls back to embedded texture names for pre-Legion models
Sourcepub fn load_texture_file(
&self,
index: usize,
resolver: &dyn FileResolver,
) -> Result<Vec<u8>>
pub fn load_texture_file( &self, index: usize, resolver: &dyn FileResolver, ) -> Result<Vec<u8>>
Load a texture file by index using a FileResolver Falls back to embedded texture names for pre-Legion models
Sourcepub fn get_skin_file_ids(&self) -> Option<&[u32]>
pub fn get_skin_file_ids(&self) -> Option<&[u32]>
Get all skin file IDs
Sourcepub fn get_animation_file_ids(&self) -> Option<&[u32]>
pub fn get_animation_file_ids(&self) -> Option<&[u32]>
Get all animation file IDs
Sourcepub fn get_texture_file_ids(&self) -> Option<&[u32]>
pub fn get_texture_file_ids(&self) -> Option<&[u32]>
Get all texture file IDs
Sourcepub fn get_physics_file_id(&self) -> Option<u32>
pub fn get_physics_file_id(&self) -> Option<u32>
Get the physics file ID
Sourcepub fn get_skeleton_file_id(&self) -> Option<u32>
pub fn get_skeleton_file_id(&self) -> Option<u32>
Get the skeleton file ID
Sourcepub fn get_bone_file_ids(&self) -> Option<&[u32]>
pub fn get_bone_file_ids(&self) -> Option<&[u32]>
Get all bone file IDs
Sourcepub fn get_lod_data(&self) -> Option<&LodData>
pub fn get_lod_data(&self) -> Option<&LodData>
Get the LOD data
Sourcepub fn load_physics(
&self,
resolver: &dyn FileResolver,
) -> Result<Option<PhysicsData>>
pub fn load_physics( &self, resolver: &dyn FileResolver, ) -> Result<Option<PhysicsData>>
Load physics data using a FileResolver
Sourcepub fn load_skeleton(
&self,
resolver: &dyn FileResolver,
) -> Result<Option<SkeletonData>>
pub fn load_skeleton( &self, resolver: &dyn FileResolver, ) -> Result<Option<SkeletonData>>
Load skeleton data using a FileResolver
Sourcepub fn load_bone_data(
&self,
index: usize,
resolver: &dyn FileResolver,
) -> Result<Option<BoneData>>
pub fn load_bone_data( &self, index: usize, resolver: &dyn FileResolver, ) -> Result<Option<BoneData>>
Load bone data by index using a FileResolver
Sourcepub fn bone_file_count(&self) -> usize
pub fn bone_file_count(&self) -> usize
Get the number of bone files referenced
Sourcepub fn select_lod(&self, distance: f32) -> Option<&LodLevel>
pub fn select_lod(&self, distance: f32) -> Option<&LodLevel>
Select the appropriate LOD level for a given distance
Sourcepub fn has_lod_data(&self) -> bool
pub fn has_lod_data(&self) -> bool
Check if the model has LOD data
Sourcepub fn is_animation_blacklisted(&self, sequence_id: u16) -> bool
pub fn is_animation_blacklisted(&self, sequence_id: u16) -> bool
Check if an animation sequence is blacklisted
Sourcepub fn get_extended_particle_data(&self) -> Option<&ExtendedParticleData>
pub fn get_extended_particle_data(&self) -> Option<&ExtendedParticleData>
Get extended particle data
Sourcepub fn get_parent_animation_blacklist(
&self,
) -> Option<&ParentAnimationBlacklist>
pub fn get_parent_animation_blacklist( &self, ) -> Option<&ParentAnimationBlacklist>
Get parent animation blacklist
Sourcepub fn get_parent_animation_data(&self) -> Option<&ParentAnimationData>
pub fn get_parent_animation_data(&self) -> Option<&ParentAnimationData>
Get parent animation data
Sourcepub fn get_waterfall_effect(&self) -> Option<&WaterfallEffect>
pub fn get_waterfall_effect(&self) -> Option<&WaterfallEffect>
Get waterfall effect data
Sourcepub fn get_edge_fade_data(&self) -> Option<&EdgeFadeData>
pub fn get_edge_fade_data(&self) -> Option<&EdgeFadeData>
Get edge fade data
Sourcepub fn get_model_alpha_data(&self) -> Option<&ModelAlphaData>
pub fn get_model_alpha_data(&self) -> Option<&ModelAlphaData>
Get model alpha data
Sourcepub fn get_lighting_details(&self) -> Option<&LightingDetails>
pub fn get_lighting_details(&self) -> Option<&LightingDetails>
Get lighting details
Sourcepub fn get_recursive_particle_ids(&self) -> Option<&[u32]>
pub fn get_recursive_particle_ids(&self) -> Option<&[u32]>
Get recursive particle model IDs
Sourcepub fn get_geometry_particle_ids(&self) -> Option<&[u32]>
pub fn get_geometry_particle_ids(&self) -> Option<&[u32]>
Get geometry particle model IDs
Sourcepub fn load_particle_models(
&self,
file_resolver: &dyn FileResolver,
) -> Result<Vec<M2Model>>
pub fn load_particle_models( &self, file_resolver: &dyn FileResolver, ) -> Result<Vec<M2Model>>
Load particle models using a FileResolver This method implements recursion protection to avoid infinite loops
Sourcepub fn get_parent_sequence_bounds(&self) -> Option<&ParentSequenceBounds>
pub fn get_parent_sequence_bounds(&self) -> Option<&ParentSequenceBounds>
Check if the model has any advanced rendering features Get parent sequence bounds data (PSBC chunk)
Sourcepub fn get_parent_event_data(&self) -> Option<&ParentEventData>
pub fn get_parent_event_data(&self) -> Option<&ParentEventData>
Get parent event data (PEDC chunk)
Sourcepub fn get_collision_mesh_data(&self) -> Option<&CollisionMeshData>
pub fn get_collision_mesh_data(&self) -> Option<&CollisionMeshData>
Get collision mesh data (PCOL chunk)
Sourcepub fn get_physics_file_data(&self) -> Option<&PhysicsFileDataChunk>
pub fn get_physics_file_data(&self) -> Option<&PhysicsFileDataChunk>
Get physics file data (PFDC chunk)
Sourcepub fn has_advanced_features(&self) -> bool
pub fn has_advanced_features(&self) -> bool
Check if model has advanced features (Legion+)
Source§impl M2Model
impl M2Model
Sourcepub fn parse_all_data(&self, original_data: &[u8]) -> Result<EnhancedModelData>
pub fn parse_all_data(&self, original_data: &[u8]) -> Result<EnhancedModelData>
Parse all available data from the M2 model
This method extracts all vertices, bones, animations, textures, and materials from the model, and for vanilla models (version 256), also extracts embedded skin data.
§Arguments
original_data- The complete original M2 file data (required for embedded skins)
§Returns
Returns EnhancedModelData containing all extracted model information
§Example
let m2_data = fs::read("HumanMale.m2")?;
let m2_format = parse_m2(&mut Cursor::new(&m2_data))?;
let model = m2_format.model();
// Extract all model data
let enhanced_data = model.parse_all_data(&m2_data)?;
println!("Model has {} vertices, {} bones, {} animations",
enhanced_data.vertices.len(),
enhanced_data.bones.len(),
enhanced_data.animations.len());Sourcepub fn display_info(&self, enhanced_data: &EnhancedModelData)
pub fn display_info(&self, enhanced_data: &EnhancedModelData)
Display comprehensive model information
This method prints detailed information about the model including all its components.
§Arguments
enhanced_data- The enhanced model data to display
§Example
let m2_data = fs::read("HumanMale.m2")?;
let m2_format = parse_m2(&mut Cursor::new(&m2_data))?;
let model = m2_format.model();
let enhanced_data = model.parse_all_data(&m2_data)?;
model.display_info(&enhanced_data);Trait Implementations§
Source§impl M2ModelAnimationExt for M2Model
impl M2ModelAnimationExt for M2Model
Source§fn resolve_bone_animations(
&self,
data: &[u8],
) -> Result<Vec<ResolvedBoneAnimation>>
fn resolve_bone_animations( &self, data: &[u8], ) -> Result<Vec<ResolvedBoneAnimation>>
Source§fn get_bind_pose(&self, data: &[u8]) -> Result<Vec<ResolvedBoneAnimation>>
fn get_bind_pose(&self, data: &[u8]) -> Result<Vec<ResolvedBoneAnimation>>
Auto Trait Implementations§
impl Freeze for M2Model
impl RefUnwindSafe for M2Model
impl Send for M2Model
impl Sync for M2Model
impl Unpin for M2Model
impl UnwindSafe for M2Model
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 moreSource§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().