summaryrefslogtreecommitdiff
path: root/engine/src/model/asset.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/model/asset.rs')
-rw-r--r--engine/src/model/asset.rs42
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);