aboutsummaryrefslogtreecommitdiff
path: root/crates/render-core/src/lib.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-02-19 12:46:23 +0300
committerValentin Popov <valentin@popov.link>2026-02-19 12:46:23 +0300
commitefab61a45c8837d3c2aaec464d8f6243fecb7a38 (patch)
treeb511f1cab917f5f2931d6bc2ae2676b553bb8ef9 /crates/render-core/src/lib.rs
parent0d7ae6a017b8b2bf26c5c14c39cb62b599e8262d (diff)
downloadfparkan-efab61a45c8837d3c2aaec464d8f6243fecb7a38.tar.xz
fparkan-efab61a45c8837d3c2aaec464d8f6243fecb7a38.zip
feat(render-core): add default UV scale and refactor UV mapping logic
- Introduced a constant `DEFAULT_UV_SCALE` for UV scaling. - Refactored UV mapping in `build_render_mesh` to use the new constant. - Simplified `compute_bounds` functions by extracting common logic into `compute_bounds_impl`. test(render-core): add tests for rendering with empty and multi-node models - Added tests to verify behavior when building render meshes from models with no slots and multiple nodes. - Ensured UV scaling is correctly applied in tests. feat(render-demo): add FOV argument and improve error handling - Added a `--fov` command-line argument to set the field of view. - Enhanced error messages for texture resolution failures. - Updated MVP computation to use the new FOV parameter. fix(rsli): improve error handling in LZH decompression - Added checks to prevent out-of-bounds access in LZH decoding logic. refactor(texm): streamline texture parsing and decoding tests - Created a helper function `build_texm_payload` for constructing test payloads. - Added tests for various texture formats including RGB565, RGB556, ARGB4444, and Luminance Alpha. - Improved error handling for invalid TEXM headers and mip bounds.
Diffstat (limited to 'crates/render-core/src/lib.rs')
-rw-r--r--crates/render-core/src/lib.rs51
1 files changed, 24 insertions, 27 deletions
diff --git a/crates/render-core/src/lib.rs b/crates/render-core/src/lib.rs
index ddb93fb..d06761a 100644
--- a/crates/render-core/src/lib.rs
+++ b/crates/render-core/src/lib.rs
@@ -1,5 +1,7 @@
use msh_core::Model;
+pub const DEFAULT_UV_SCALE: f32 = 1024.0;
+
#[derive(Clone, Debug)]
pub struct RenderVertex {
pub position: [f32; 3],
@@ -58,7 +60,12 @@ pub fn build_render_mesh(model: &Model, lod: usize, group: usize) -> RenderMesh
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])
+ .map(|packed| {
+ [
+ packed[0] as f32 / DEFAULT_UV_SCALE,
+ packed[1] as f32 / DEFAULT_UV_SCALE,
+ ]
+ })
.unwrap_or([0.0, 0.0]);
vertices.push(RenderVertex {
position: *pos,
@@ -76,38 +83,28 @@ pub fn build_render_mesh(model: &Model, lod: usize, group: usize) -> RenderMesh
}
pub fn compute_bounds(vertices: &[[f32; 3]]) -> Option<([f32; 3], [f32; 3])> {
- let mut iter = vertices.iter();
- let first = iter.next()?;
- let mut min_v = *first;
- let mut max_v = *first;
-
- for v in iter {
- for i in 0..3 {
- if v[i] < min_v[i] {
- min_v[i] = v[i];
- }
- if v[i] > max_v[i] {
- max_v[i] = v[i];
- }
- }
- }
-
- Some((min_v, max_v))
+ compute_bounds_impl(vertices.iter().copied())
}
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;
+ compute_bounds_impl(vertices.iter().map(|v| v.position))
+}
+
+fn compute_bounds_impl<I>(mut positions: I) -> Option<([f32; 3], [f32; 3])>
+where
+ I: Iterator<Item = [f32; 3]>,
+{
+ let first = positions.next()?;
+ let mut min_v = first;
+ let mut max_v = first;
- for v in iter {
+ for pos in positions {
for i in 0..3 {
- if v.position[i] < min_v[i] {
- min_v[i] = v.position[i];
+ if pos[i] < min_v[i] {
+ min_v[i] = pos[i];
}
- if v.position[i] > max_v[i] {
- max_v[i] = v.position[i];
+ if pos[i] > max_v[i] {
+ max_v[i] = pos[i];
}
}
}