feat: implement gltf loader
No files matched your search
@@ -94,6 +94,15 @@ version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||
|
||||
[[package]]
|
||||
name = "approx"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "approx"
|
||||
version = "0.5.1"
|
||||
@@ -220,6 +229,18 @@ dependencies = [
|
||||
"arrayvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.10.3"
|
||||
@@ -362,6 +383,16 @@ version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
|
||||
|
||||
[[package]]
|
||||
name = "cgmath"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317"
|
||||
dependencies = [
|
||||
"approx 0.4.0",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.57"
|
||||
@@ -552,6 +583,18 @@ version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
|
||||
|
||||
[[package]]
|
||||
name = "easy-gltf"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1203d5e3b06d11431cd680b7d89fe3565ea797e948a3869aa791f10855b02175"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"cgmath",
|
||||
"gltf",
|
||||
"image",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
@@ -876,6 +919,45 @@ version = "0.32.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f70749695b063ecbf6b62949ccccde2e733ec3ecbbd71d467dca4e5c6c97cca0"
|
||||
|
||||
[[package]]
|
||||
name = "gltf"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3ce1918195723ce6ac74e80542c5a96a40c2b26162c1957a5cd70799b8cacf7"
|
||||
dependencies = [
|
||||
"base64 0.13.1",
|
||||
"byteorder",
|
||||
"gltf-json",
|
||||
"image",
|
||||
"lazy_static",
|
||||
"serde_json",
|
||||
"urlencoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gltf-derive"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "14070e711538afba5d6c807edb74bcb84e5dbb9211a3bf5dea0dfab5b24f4c51"
|
||||
dependencies = [
|
||||
"inflections",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.117",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gltf-json"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6176f9d60a7eab0a877e8e96548605dedbde9190a7ae1e80bbcc1c9af03ab14"
|
||||
dependencies = [
|
||||
"gltf-derive",
|
||||
"serde",
|
||||
"serde_derive",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "2.7.1"
|
||||
@@ -1011,6 +1093,12 @@ dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "inflections"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a257582fdcde896fd96463bf2d40eefea0580021c0712a0e2b028b60b47a837a"
|
||||
|
||||
[[package]]
|
||||
name = "interpolate_name"
|
||||
version = "0.2.4"
|
||||
@@ -1079,6 +1167,12 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "leb128fmt"
|
||||
version = "0.1.0"
|
||||
@@ -1232,7 +1326,7 @@ version = "0.34.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df76ea0ff5c7e6b88689085804d6132ded0ddb9de5ca5b8aeb9eeadc0508a70a"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"approx 0.5.1",
|
||||
"glam 0.14.0",
|
||||
"glam 0.15.2",
|
||||
"glam 0.16.0",
|
||||
@@ -2253,7 +2347,7 @@ version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c99284beb21666094ba2b75bbceda012e610f5479dfcc2d6e2426f53197ffd95"
|
||||
dependencies = [
|
||||
"approx",
|
||||
"approx 0.5.1",
|
||||
"num-complex",
|
||||
"num-traits",
|
||||
"paste",
|
||||
@@ -2534,6 +2628,12 @@ version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "urlencoding"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.23.1"
|
||||
@@ -2635,6 +2735,7 @@ name = "vulkano-test"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"easy-gltf",
|
||||
"image",
|
||||
"log",
|
||||
"nalgebra",
|
||||
|
||||
@@ -17,3 +17,4 @@ serde_json = "1.0.149"
|
||||
anyhow = "1.0.104"
|
||||
thiserror = "2.0.19"
|
||||
log = "0.4.29"
|
||||
easy-gltf = "1.1.5"
|
||||
|
Before Width: | Height: | Size: 17 MiB |
|
Before Width: | Height: | Size: 15 MiB |
|
Before Width: | Height: | Size: 379 KiB |
|
Before Width: | Height: | Size: 6.3 MiB |
|
Before Width: | Height: | Size: 9.0 MiB |
|
Before Width: | Height: | Size: 15 MiB |
|
Before Width: | Height: | Size: 13 MiB |
@@ -1,54 +0,0 @@
|
||||
# MTL file - created by a modified js OBJExporter
|
||||
|
||||
newmtl LAAT_INT_EXT
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 1
|
||||
Pm 1
|
||||
Pr 1
|
||||
Pds 1
|
||||
Pl 1
|
||||
Ka 1 1 1
|
||||
Kd 1 1 1
|
||||
Ke 1 1 1
|
||||
map_Kd LAAT_INT_EXT.png
|
||||
map_Ke emissiveMap1.png
|
||||
map_Pm metalnessMap1.png
|
||||
map_Pr metalnessMap1.png
|
||||
norm normalMap1.png
|
||||
|
||||
newmtl LAAT_INT_EXT_Glass
|
||||
Tr 0.75
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 1
|
||||
Pr 0.5775255696017358
|
||||
Pds 1
|
||||
Pl 1
|
||||
Pccns 11
|
||||
Prfl 0.5
|
||||
Pior 1.5
|
||||
Pshc 0 0 0
|
||||
Pshr 1
|
||||
Psi 1
|
||||
Psc 1 1 1
|
||||
Ptr 0.88
|
||||
Ka 1 1 1
|
||||
Kd 0.028952469188477523 0.028952469188477523 0.028952469188477523
|
||||
Ke 0 0 0
|
||||
norm normalMap1.png
|
||||
|
||||
newmtl LAAT_HULL
|
||||
Tr 0.0000
|
||||
Tf 1.0000 1.0000 1.0000
|
||||
illum 1
|
||||
Pm 1
|
||||
Pr 1
|
||||
Pds 1
|
||||
Pl 1
|
||||
Ka 1 1 1
|
||||
Kd 1 1 1
|
||||
Ke 0 0 0
|
||||
map_Kd LAAT_HULL.png
|
||||
map_Pm metalnessMap3.png
|
||||
map_Pr metalnessMap3.png
|
||||
norm normalMap3.png
|
||||
@@ -81,7 +81,7 @@ impl MeshRegistry {
|
||||
let obj_num_idx = obj.indices.len();
|
||||
buf_indices.extend(obj.indices);
|
||||
|
||||
println!("Loaded mesh {} with {} vertices and {} indices", id, obj_num_verts, obj_num_idx);
|
||||
println!("Loaded mesh \"{}\" with {} vertices and {} indices", id, obj_num_verts, obj_num_idx);
|
||||
|
||||
// TODO Create bounding boxes for each mesh and associate them with the struct.
|
||||
mesh_list.insert(
|
||||
|
||||
@@ -21,7 +21,7 @@ impl RenderBatch {
|
||||
instance_registry: Arc<InstanceRegistry>
|
||||
) -> Vec<Self> {
|
||||
mesh_registry.meshes.iter()
|
||||
.map(|(id, mesh)| {
|
||||
.filter_map(|(id, mesh)| {
|
||||
let instances = instance_registry.get_instances_for(id);
|
||||
|
||||
let gpu_instances = instances.iter()
|
||||
@@ -31,6 +31,10 @@ impl RenderBatch {
|
||||
})
|
||||
.collect::<Vec<GpuInstance>>();
|
||||
|
||||
if gpu_instances.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// Build instances into a RenderBatch
|
||||
let instance_buffer = Buffer::from_iter(
|
||||
allocator.clone(),
|
||||
@@ -46,11 +50,11 @@ impl RenderBatch {
|
||||
gpu_instances
|
||||
).expect("Couldn't allocate instance buffer");
|
||||
|
||||
Self {
|
||||
Some(Self {
|
||||
mesh_id: id.clone(),
|
||||
instance_buffer,
|
||||
instance_count: instances.len() as u32,
|
||||
}
|
||||
})
|
||||
}).collect()
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,47 @@
|
||||
use std::path::Path;
|
||||
use anyhow::Result;
|
||||
use anyhow::{anyhow, Result};
|
||||
use crate::loaders::mesh_loader::{MeshFileLoader, MeshInfo};
|
||||
|
||||
pub struct GltfLoader;
|
||||
|
||||
impl MeshFileLoader for GltfLoader {
|
||||
fn load_mesh(&self, path: &Path) -> Result<MeshInfo> {
|
||||
todo!()
|
||||
let scenes = easy_gltf::load(path)
|
||||
.map_err(|e| anyhow!("could not load gltf file: {e}"))?;
|
||||
|
||||
println!("Found {} scene(s) in gltf file", scenes.len());
|
||||
|
||||
let scene = scenes.first()
|
||||
.ok_or(anyhow!("no scenes in gltf file"))?;
|
||||
|
||||
println!("Found {} model(s) in gltf file", scene.models.len());
|
||||
|
||||
let mut vertices = Vec::new();
|
||||
let mut normals = Vec::new();
|
||||
let mut uvs = Vec::new();
|
||||
let mut indices = Vec::<u32>::new();
|
||||
for model in &scene.models {
|
||||
// Indices must be offset by the number of vertices that are already registered.
|
||||
let idx_offset = vertices.len() as u32;
|
||||
|
||||
// Put all vertex info together for a MeshInfo struct
|
||||
for vertex in model.vertices() {
|
||||
vertices.push(*vertex.position.as_ref());
|
||||
normals.push(*vertex.normal.as_ref());
|
||||
uvs.push([vertex.tex_coords.x, vertex.tex_coords.y, 0.0]);
|
||||
}
|
||||
model.indices()
|
||||
.expect("failed to find indices")
|
||||
.iter()
|
||||
.map(|i| i + idx_offset)
|
||||
.for_each(|i| indices.push(i));
|
||||
}
|
||||
|
||||
Ok(MeshInfo {
|
||||
vertices,
|
||||
indices,
|
||||
normals,
|
||||
uvs
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,13 @@ use crate::loaders::obj_loader::ObjLoader;
|
||||
use super::gltf_loader::*;
|
||||
|
||||
pub struct MeshInfo {
|
||||
/// The mesh's vertices.
|
||||
pub vertices: Vec<[f32; 3]>,
|
||||
/// The mesh's vertex normals.
|
||||
pub normals: Vec<[f32; 3]>,
|
||||
/// The mesh's vertex indices.
|
||||
pub indices: Vec<u32>,
|
||||
/// The texture coordinates. Note that these may also be used on 3D textures.
|
||||
pub uvs: Vec<[f32; 3]>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
{
|
||||
"name": "Testing Scene",
|
||||
"mesh_paths": {
|
||||
"gunship": "laat_gunship/scene.obj"
|
||||
"gunship": "meshes/laat_gunship/scene.obj",
|
||||
"trooper": "meshes/clone_trooper/scene.gltf"
|
||||
},
|
||||
"instances": {
|
||||
"gunship": {
|
||||
"translation": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"rotation": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"scale": [
|
||||
1.0,
|
||||
1.0,
|
||||
1.0
|
||||
]
|
||||
"trooper": {
|
||||
"translation": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"rotation": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"scale": [
|
||||
20.0,
|
||||
20.0,
|
||||
20.0
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||