mirror of
https://codeberg.org/icewind/vmdl.git
synced 2026-06-03 16:44:11 +02:00
add from_path to lib
This commit is contained in:
parent
44be60641b
commit
92449728fb
3 changed files with 22 additions and 31 deletions
17
src/lib.rs
17
src/lib.rs
|
|
@ -15,7 +15,9 @@ pub use error::*;
|
|||
pub use handle::Handle;
|
||||
pub use shared::*;
|
||||
use std::any::type_name;
|
||||
use std::fs;
|
||||
use std::mem::size_of;
|
||||
use std::path::Path;
|
||||
|
||||
pub struct Model {
|
||||
#[allow(dead_code)]
|
||||
|
|
@ -29,6 +31,21 @@ impl Model {
|
|||
Model { mdl, vtx, vvd }
|
||||
}
|
||||
|
||||
/// Load the model from path
|
||||
///
|
||||
/// Requires a path to the `.mdl` file and the `.dx90.vtx` and `.vvd` files for the model to be in the same directory.
|
||||
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, ModelError> {
|
||||
let path = path.as_ref();
|
||||
let data = fs::read(path)?;
|
||||
let mdl = Mdl::read(&data)?;
|
||||
let data = fs::read(path.with_extension("dx90.vtx"))?;
|
||||
let vtx = Vtx::read(&data)?;
|
||||
let data = fs::read(path.with_extension("vvd"))?;
|
||||
let vvd = Vvd::read(&data)?;
|
||||
|
||||
Ok(Model::from_parts(mdl, vtx, vvd))
|
||||
}
|
||||
|
||||
pub fn vertices(&self) -> &[Vertex] {
|
||||
&self.vvd.vertices
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue