initial gltf example

This commit is contained in:
Carter Anderson 2020-01-07 23:03:09 -08:00
parent f27942e961
commit 86a467f0f3
9 changed files with 630 additions and 4 deletions

View file

@ -15,6 +15,7 @@ zerocopy = "0.2"
log = "0.4"
env_logger = "0.7"
rand = "0.7.2"
gltf = "0.14.0"
[profile.release]
debug = true

BIN
examples/assets/Box.glb Normal file

Binary file not shown.

142
examples/assets/Box.gltf Normal file
View file

@ -0,0 +1,142 @@
{
"asset": {
"generator": "COLLADA2GLTF",
"version": "2.0"
},
"scene": 0,
"scenes": [
{
"nodes": [
0
]
}
],
"nodes": [
{
"children": [
1
],
"matrix": [
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
-1.0,
0.0,
0.0,
1.0,
0.0,
0.0,
0.0,
0.0,
0.0,
1.0
]
},
{
"mesh": 0
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"NORMAL": 1,
"POSITION": 2
},
"indices": 0,
"mode": 4,
"material": 0
}
],
"name": "Mesh"
}
],
"accessors": [
{
"bufferView": 0,
"byteOffset": 0,
"componentType": 5123,
"count": 36,
"max": [
23
],
"min": [
0
],
"type": "SCALAR"
},
{
"bufferView": 1,
"byteOffset": 0,
"componentType": 5126,
"count": 24,
"max": [
1.0,
1.0,
1.0
],
"min": [
-1.0,
-1.0,
-1.0
],
"type": "VEC3"
},
{
"bufferView": 1,
"byteOffset": 288,
"componentType": 5126,
"count": 24,
"max": [
0.5,
0.5,
0.5
],
"min": [
-0.5,
-0.5,
-0.5
],
"type": "VEC3"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorFactor": [
0.800000011920929,
0.0,
0.0,
1.0
],
"metallicFactor": 0.0
},
"name": "Red"
}
],
"bufferViews": [
{
"buffer": 0,
"byteOffset": 576,
"byteLength": 72,
"target": 34963
},
{
"buffer": 0,
"byteOffset": 0,
"byteLength": 576,
"byteStride": 12,
"target": 34962
}
],
"buffers": [
{
"byteLength": 648,
"uri": "Box0.bin"
}
]
}

BIN
examples/assets/Box0.bin Normal file

Binary file not shown.

View file

@ -0,0 +1,468 @@
{
"accessors": [
{
"bufferView": 0,
"componentType": 5126,
"count": 926,
"type": "VEC2",
"max": [
0.992169142,
-0.007998445
],
"min": [
0.0107366741,
-0.992534757
]
},
{
"bufferView": 1,
"componentType": 5126,
"count": 926,
"type": "VEC3",
"max": [
1.0,
1.0,
1.0
],
"min": [
-1.0,
-1.0,
-1.0
]
},
{
"bufferView": 2,
"componentType": 5126,
"count": 926,
"type": "VEC4",
"max": [
1.0,
0.9999658,
1.0,
1.0
],
"min": [
-1.0,
-0.962171,
-1.0,
1.0
]
},
{
"bufferView": 3,
"componentType": 5126,
"count": 926,
"type": "VEC3",
"max": [
7.74559927,
12.8321095,
2.31570983
],
"min": [
-7.74559927,
-12.8321095,
-2.31570983
]
},
{
"bufferView": 4,
"componentType": 5123,
"count": 2616,
"type": "SCALAR",
"max": [
925
],
"min": [
0
]
},
{
"bufferView": 5,
"componentType": 5126,
"count": 756,
"type": "VEC2",
"max": [
0.8007193,
-0.0581455827
],
"min": [
0.351246148,
-0.361011624
]
},
{
"bufferView": 6,
"componentType": 5126,
"count": 756,
"type": "VEC3",
"max": [
1.0,
1.0,
0.999998
],
"min": [
-1.0,
-1.0,
-0.999998
]
},
{
"bufferView": 7,
"componentType": 5126,
"count": 756,
"type": "VEC4",
"max": [
0.9997526,
1.0,
0.999752462,
1.0
],
"min": [
-0.9995128,
-1.0,
-0.999752462,
1.0
]
},
{
"bufferView": 8,
"componentType": 5126,
"count": 756,
"type": "VEC3",
"max": [
0.129208073,
0.6523504,
0.129208073
],
"min": [
-0.129208073,
-0.6523504,
-0.129208073
]
},
{
"bufferView": 9,
"componentType": 5123,
"count": 3744,
"type": "SCALAR",
"max": [
755
],
"min": [
0
]
},
{
"bufferView": 10,
"componentType": 5126,
"count": 2463,
"type": "VEC2",
"max": [
0.9923278,
-0.00728821754
],
"min": [
0.3673209,
-0.413352221
]
},
{
"bufferView": 11,
"componentType": 5126,
"count": 2463,
"type": "VEC3",
"max": [
1.0,
1.0,
1.0
],
"min": [
-1.0,
-1.0,
-1.0
]
},
{
"bufferView": 12,
"componentType": 5126,
"count": 2463,
"type": "VEC4",
"max": [
1.0,
1.0,
1.0,
1.0
],
"min": [
-1.0,
-1.0,
-1.0,
-1.0
]
},
{
"bufferView": 13,
"componentType": 5126,
"count": 2463,
"type": "VEC3",
"max": [
1.03408229,
2.529281,
1.03408468
],
"min": [
-1.03408229,
-2.529281,
-1.03408468
]
},
{
"bufferView": 14,
"componentType": 5123,
"count": 9822,
"type": "SCALAR",
"max": [
2462
],
"min": [
0
]
}
],
"asset": {
"generator": "glTF Tools for Unity",
"version": "2.0"
},
"bufferViews": [
{
"buffer": 0,
"byteLength": 7408
},
{
"buffer": 0,
"byteOffset": 7408,
"byteLength": 11112
},
{
"buffer": 0,
"byteOffset": 18520,
"byteLength": 14816
},
{
"buffer": 0,
"byteOffset": 33336,
"byteLength": 11112
},
{
"buffer": 0,
"byteOffset": 44448,
"byteLength": 5232
},
{
"buffer": 0,
"byteOffset": 49680,
"byteLength": 6048
},
{
"buffer": 0,
"byteOffset": 55728,
"byteLength": 9072
},
{
"buffer": 0,
"byteOffset": 64800,
"byteLength": 12096
},
{
"buffer": 0,
"byteOffset": 76896,
"byteLength": 9072
},
{
"buffer": 0,
"byteOffset": 85968,
"byteLength": 7488
},
{
"buffer": 0,
"byteOffset": 93456,
"byteLength": 19704
},
{
"buffer": 0,
"byteOffset": 113160,
"byteLength": 29556
},
{
"buffer": 0,
"byteOffset": 142716,
"byteLength": 39408
},
{
"buffer": 0,
"byteOffset": 182124,
"byteLength": 29556
},
{
"buffer": 0,
"byteOffset": 211680,
"byteLength": 19644
}
],
"buffers": [
{
"uri": "Lantern.bin",
"byteLength": 231324
}
],
"images": [
{
"uri": "Lantern_baseColor.png"
},
{
"uri": "Lantern_roughnessMetallic.png"
},
{
"uri": "Lantern_normal.png"
},
{
"uri": "Lantern_emissive.png"
}
],
"meshes": [
{
"primitives": [
{
"attributes": {
"TEXCOORD_0": 0,
"NORMAL": 1,
"TANGENT": 2,
"POSITION": 3
},
"indices": 4,
"material": 0
}
],
"name": "LanternPole_Body"
},
{
"primitives": [
{
"attributes": {
"TEXCOORD_0": 5,
"NORMAL": 6,
"TANGENT": 7,
"POSITION": 8
},
"indices": 9,
"material": 0
}
],
"name": "LanternPole_Chain"
},
{
"primitives": [
{
"attributes": {
"TEXCOORD_0": 10,
"NORMAL": 11,
"TANGENT": 12,
"POSITION": 13
},
"indices": 14,
"material": 0
}
],
"name": "LanternPole_Lantern"
}
],
"materials": [
{
"pbrMetallicRoughness": {
"baseColorFactor": [
0.214041144,
0.214041144,
0.214041144,
1.0
],
"baseColorTexture": {
"index": 0
},
"metallicRoughnessTexture": {
"index": 1
}
},
"normalTexture": {
"index": 2
},
"emissiveFactor": [
1.0,
1.0,
1.0
],
"emissiveTexture": {
"index": 3
},
"name": "LanternPost_Mat"
}
],
"nodes": [
{
"mesh": 0,
"translation": [
-3.82315421,
13.01603,
0.0
],
"name": "LanternPole_Body"
},
{
"mesh": 1,
"translation": [
-9.582001,
21.0378723,
0.0
],
"name": "LanternPole_Chain"
},
{
"mesh": 2,
"translation": [
-9.582007,
18.0091515,
0.0
],
"name": "LanternPole_Lantern"
},
{
"children": [
0,
1,
2
],
"name": "Lantern"
}
],
"scene": 0,
"scenes": [
{
"nodes": [
3
]
}
],
"textures": [
{
"source": 0
},
{
"source": 1
},
{
"source": 2
},
{
"source": 3
}
]
}

11
examples/load_model.rs Normal file
View file

@ -0,0 +1,11 @@
use bevy::*;
fn main() {
// let universe = Universe::new();
// let world = universe.create_world();
// let scheduler = SystemScheduler::<ApplicationStage>::new();
// asset::load_gltf(get_path("examples/assets/Box.gltf").to_str().unwrap()).unwrap();
asset::load_gltf("examples/assets/Box.gltf").unwrap();
// Application::run(universe, world, scheduler);
}

View file

@ -2,15 +2,15 @@ use std::{fs, io};
use std::boxed::Box;
use std::error::Error;
// use crate::render::Mesh;
pub fn load_gltf(path: &str) -> Result<(), Box<dyn Error>> {
println!("{}", path);
let file = fs::File::open(&path)?;
let reader = io::BufReader::new(file);
let gltf = gltf::Gltf::from_reader(reader)?;
for scene in gltf.scenes() {
for mesh in scene.nodes() {
for _mesh in scene.nodes() {
}
}

View file

@ -1,3 +1,7 @@
mod gltf;
pub use self::gltf::load_gltf;
use std::{sync::{Arc, RwLock}, marker::PhantomData, ops::Drop, collections::HashMap};
pub struct Handle<T>

View file

@ -6,7 +6,7 @@ pub enum MeshType {
Cube,
Plane {
size: f32
}
},
}
pub struct Mesh {