Update tutorial 11 to tobj 3.0.x

This commit is contained in:
Hugo Woodiwiss 2021-06-01 14:27:13 +01:00
parent 67c9246b2f
commit 08fc3e41d0
No known key found for this signature in database
GPG Key ID: DA90F48139594E88
3 changed files with 50 additions and 11 deletions

49
Cargo.lock generated
View File

@ -18,6 +18,17 @@ version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]]
name = "ahash"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43bb833f0bf979d8475d38fbf09ed3b8a55e1885fe93ad3f93239fc6a4f17b98"
dependencies = [
"getrandom",
"once_cell",
"version_check",
]
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "0.7.13" version = "0.7.13"
@ -308,7 +319,7 @@ dependencies = [
"log", "log",
"rayon", "rayon",
"shaderc", "shaderc",
"tobj", "tobj 2.0.2",
"wgpu", "wgpu",
"winit", "winit",
] ]
@ -613,7 +624,7 @@ dependencies = [
"rayon", "rayon",
"shaderc", "shaderc",
"thiserror", "thiserror",
"tobj", "tobj 2.0.2",
"wgpu", "wgpu",
"wgpu-subscriber", "wgpu-subscriber",
"winit", "winit",
@ -758,6 +769,17 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "getrandom"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi",
]
[[package]] [[package]]
name = "gfx-auxil" name = "gfx-auxil"
version = "0.9.0" version = "0.9.0"
@ -934,7 +956,7 @@ dependencies = [
"image", "image",
"log", "log",
"shaderc", "shaderc",
"tobj", "tobj 2.0.2",
"wgpu", "wgpu",
"winit", "winit",
] ]
@ -1002,7 +1024,7 @@ version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
dependencies = [ dependencies = [
"ahash", "ahash 0.4.7",
] ]
[[package]] [[package]]
@ -2038,6 +2060,15 @@ version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6172100cd5b17cdd085c94f261e31101ca31886c86a2337a6687dac6d2fb3cf1" checksum = "6172100cd5b17cdd085c94f261e31101ca31886c86a2337a6687dac6d2fb3cf1"
[[package]]
name = "tobj"
version = "3.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8985733c6a9b851f289747c1c3ee7a962a642787e248a97b6e04185d8d536d70"
dependencies = [
"ahash 0.7.4",
]
[[package]] [[package]]
name = "toml" name = "toml"
version = "0.5.6" version = "0.5.6"
@ -2153,7 +2184,7 @@ dependencies = [
"glob", "glob",
"image", "image",
"log", "log",
"tobj", "tobj 3.0.1",
"wgpu", "wgpu",
"winit", "winit",
] ]
@ -2171,7 +2202,7 @@ dependencies = [
"glob", "glob",
"image", "image",
"log", "log",
"tobj", "tobj 3.0.1",
"wgpu", "wgpu",
"winit", "winit",
] ]
@ -2189,7 +2220,7 @@ dependencies = [
"glob", "glob",
"image", "image",
"log", "log",
"tobj", "tobj 2.0.2",
"wgpu", "wgpu",
"winit", "winit",
] ]
@ -2208,7 +2239,7 @@ dependencies = [
"image", "image",
"log", "log",
"rayon", "rayon",
"tobj", "tobj 2.0.2",
"wgpu", "wgpu",
"winit", "winit",
] ]
@ -2340,7 +2371,7 @@ dependencies = [
"glob", "glob",
"image", "image",
"log", "log",
"tobj", "tobj 3.0.1",
"wgpu", "wgpu",
"winit", "winit",
] ]

View File

@ -12,7 +12,7 @@ env_logger = "0.8"
futures = "0.3" futures = "0.3"
image = "0.23" image = "0.23"
log = "0.4" log = "0.4"
tobj = "2.0" tobj = "3.0"
wgpu = "0.8" wgpu = "0.8"
winit = "0.24" winit = "0.24"

View File

@ -1,3 +1,4 @@
use tobj::LoadOptions;
use anyhow::*; use anyhow::*;
use std::ops::Range; use std::ops::Range;
use std::path::Path; use std::path::Path;
@ -124,7 +125,14 @@ impl Model {
layout: &wgpu::BindGroupLayout, layout: &wgpu::BindGroupLayout,
path: P, path: P,
) -> Result<Self> { ) -> Result<Self> {
let (obj_models, obj_materials) = tobj::load_obj(path.as_ref(), true)?; let (obj_models, obj_materials) = tobj::load_obj(path.as_ref(), &LoadOptions {
triangulate: true,
single_index: true,
..Default::default()
},
)?;
let obj_materials = obj_materials?;
// We're assuming that the texture files are stored with the obj file // We're assuming that the texture files are stored with the obj file
let containing_folder = path.as_ref().parent().context("Directory has no parent")?; let containing_folder = path.as_ref().parent().context("Directory has no parent")?;