diff options
| author | Valentin Popov <valentin@popov.link> | 2026-02-19 04:19:18 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-02-19 04:19:18 +0300 |
| commit | a281ffa32ea615670d369503692f057b2dc60e6f (patch) | |
| tree | 321bcc1bfc489e2e7d0ff10dae620864ab08d054 /crates/render-core/src/lib.rs | |
| parent | 18d4c6cf9fabc18282b29d103c8d30024f66e49b (diff) | |
| download | fparkan-a281ffa32ea615670d369503692f057b2dc60e6f.tar.xz fparkan-a281ffa32ea615670d369503692f057b2dc60e6f.zip | |
feat: Enhance model and texture loading with improved error handling and new features
- Introduced `LoadedModel` and `LoadedTexture` structs for better encapsulation of model and texture data.
- Added functions to load models and textures from archives, including support for resolving textures based on materials and wear entries.
- Implemented error handling for missing textures, materials, and wear entries.
- Updated the rendering pipeline to support texture loading and binding, including command-line arguments for texture customization.
- Enhanced the `texm` crate with new decoding capabilities for various pixel formats, including indexed textures.
- Added tests for texture decoding and loading to ensure reliability and correctness.
- Updated documentation to reflect changes in the material and texture resolution process.
Diffstat (limited to 'crates/render-core/src/lib.rs')
| -rw-r--r-- | crates/render-core/src/lib.rs | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/crates/render-core/src/lib.rs b/crates/render-core/src/lib.rs index 8e0b5e8..ddb93fb 100644 --- a/crates/render-core/src/lib.rs +++ b/crates/render-core/src/lib.rs @@ -1,8 +1,14 @@ use msh_core::Model; #[derive(Clone, Debug)] +pub struct RenderVertex { + pub position: [f32; 3], + pub uv0: [f32; 2], +} + +#[derive(Clone, Debug)] pub struct RenderMesh { - pub vertices: Vec<[f32; 3]>, + pub vertices: Vec<RenderVertex>, pub batch_count: usize, } @@ -18,6 +24,7 @@ impl RenderMesh { pub fn build_render_mesh(model: &Model, lod: usize, group: usize) -> RenderMesh { let mut vertices = Vec::new(); let mut batch_count = 0usize; + let uv0 = model.uv0.as_ref(); for node_index in 0..model.node_count { let Some(slot_idx) = model.slot_index(node_index, lod, group) else { @@ -48,7 +55,15 @@ pub fn build_render_mesh(model: &Model, lod: usize, group: usize) -> RenderMesh let Some(pos) = model.positions.get(final_idx) else { continue; }; - vertices.push(*pos); + let uv = uv0 + .and_then(|uvs| uvs.get(final_idx)) + .copied() + .map(|packed| [packed[0] as f32 / 1024.0, packed[1] as f32 / 1024.0]) + .unwrap_or([0.0, 0.0]); + vertices.push(RenderVertex { + position: *pos, + uv0: uv, + }); } batch_count += 1; } @@ -80,5 +95,25 @@ pub fn compute_bounds(vertices: &[[f32; 3]]) -> Option<([f32; 3], [f32; 3])> { Some((min_v, max_v)) } +pub fn compute_bounds_for_mesh(vertices: &[RenderVertex]) -> Option<([f32; 3], [f32; 3])> { + let mut iter = vertices.iter(); + let first = iter.next()?; + let mut min_v = first.position; + let mut max_v = first.position; + + for v in iter { + for i in 0..3 { + if v.position[i] < min_v[i] { + min_v[i] = v.position[i]; + } + if v.position[i] > max_v[i] { + max_v[i] = v.position[i]; + } + } + } + + Some((min_v, max_v)) +} + #[cfg(test)] mod tests; |
