diff options
| author | HampusM <hampus@hampusmat.com> | 2026-09-16 12:42:45 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-09-16 12:42:45 +0200 |
| commit | f85f5afc5a4a50c5c87a236bc76f8a08d50e7137 (patch) | |
| tree | 335f55580ec706cd00ee937995355252b3304dfd /engine/src/model | |
| parent | edd3261058c3417cf04f95dbfbc51a64e35426aa (diff) | |
fix(engine): make textures not flipped
Diffstat (limited to 'engine/src/model')
| -rw-r--r-- | engine/src/model/asset.rs | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/engine/src/model/asset.rs b/engine/src/model/asset.rs index 69a06aa..5487203 100644 --- a/engine/src/model/asset.rs +++ b/engine/src/model/asset.rs @@ -7,7 +7,35 @@ use crate::model::{Materials, Spec}; #[derive(Debug, Clone)] #[non_exhaustive] -pub struct Settings {} +pub struct Settings +{ + /// Whether all UVs should be flipped on the Y axis. This is necessary if the UVs + /// have their origin at the bottom left corner of the image + /// + /// The default is `true`. + pub y_flip_uvs: bool, +} + +impl Settings +{ + /// Whether all UVs should be flipped on the Y axis. This is necessary if the UVs have + /// their origin at the bottom left corner of the image + /// + /// The default is `true`. + pub fn y_flip_uvs(mut self, y_flip_uvs: bool) -> Self + { + self.y_flip_uvs = y_flip_uvs; + self + } +} + +impl Default for Settings +{ + fn default() -> Self + { + Self { y_flip_uvs: true } + } +} pub fn add_importers(assets: &mut Assets) { @@ -17,9 +45,14 @@ pub fn add_importers(assets: &mut Assets) fn import_wavefront_obj_asset( asset_submitter: &mut AssetSubmitter<'_>, path: &Path, - _settings: Option<&'_ Settings>, + settings: Option<&Settings>, ) -> Result<(), Error> { + let settings = match settings { + Some(settings) => settings, + None => &Settings::default(), + }; + let parent_path = path .parent() .ok_or_else(|| Error::InvalidPath(path.to_path_buf()))?; @@ -29,7 +62,10 @@ fn import_wavefront_obj_asset( .map_err(|err| Error::ReadFailed(err, path.to_path_buf()))?, )?; - let mesh = obj.to_mesh()?; + let mesh = obj.to_mesh( + crate::file_format::wavefront::obj::ToMeshOptions::default() + .y_flip_uvs(settings.y_flip_uvs), + )?; let mesh_asset = asset_submitter.submit_store_named("mesh", mesh); |
