From 6f64dd33b9e5fc85e383ed87feae544b4675b498 Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Sat, 23 Sep 2017 11:27:26 +0200 Subject: [PATCH 1/8] update readme, clean Cargo.toml --- Cargo.toml | 12 +----------- README.md | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e425249..cbd0eca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Benjamin Wasty "] categories = ["rendering"] -description = "Simple glTF 2.0 viewer (WIP)" +description = "Simple glTF 2.0 viewer" include = [ "Cargo.toml", "Cargo.lock", # Note: currently ignored by `cargo package`, see rust-lang/cargo#2263 @@ -37,23 +37,13 @@ itertools = "0.6.1" [dependencies.gltf] version = "0.9.2" -# git = "https://github.com/alteous/gltf" -# branch = "simplify" features = ["names"] [dependencies.gltf-importer] version = "0.9.2" -# git = "https://github.com/alteous/gltf" -# branch = "simplify" [dependencies.gltf-utils] version = "0.9.2" -# git = "https://github.com/alteous/gltf" -# branch = "simplify" - -# [patch.crates-io] -# gltf = { git = "https://github.com/bwasty/gltf", branch = "bounds"} -# gltf-json = { git = "https://github.com/bwasty/gltf", branch = "bounds"} # [profile.dev] # opt-level = 2 diff --git a/README.md b/README.md index 0ba90d5..d0f38a8 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,19 @@ [![GitHub release](https://img.shields.io/github/release/bwasty/gltf-viewer.svg)](https://github.com/bwasty/gltf-viewer/releases/latest) [![](https://tokei.rs/b1/github/bwasty/gltf-viewer)](https://github.com/Aaronepower/tokei) [![Build Status](https://travis-ci.org/bwasty/gltf-viewer.svg?branch=master)](https://travis-ci.org/bwasty/gltf-viewer) - [![Build status](https://ci.appveyor.com/api/projects/status/51ukh02thpb0r9cf/branch/master?svg=true)](https://ci.appveyor.com/project/bwasty/gltf-viewer/branch/master)
+ [![Build status](https://ci.appveyor.com/api/projects/status/51ukh02thpb0r9cf/branch/master?svg=true)](https://ci.appveyor.com/project/bwasty/gltf-viewer/branch/master)
+ -glTF Viewer written in Rust (WIP). +[glTF](https://github.com/KhronosGroup/glTF) 2.0 Viewer written in Rust. -**Current state** (master): All sample models can be loaded, but there is no lighting yet: +**Current state** : All sample models can be loaded: -gltf-viewer-fish +gltf-viewer-0.1 + +Some glTF features are not implemented yet, most notably animations. See [#3](https://github.com/bwasty/gltf-viewer/issues/3) for details. ## Installation ### Binaries (Win/Linux/macOS) @@ -26,33 +30,36 @@ git clone https://github.com/bwasty/gltf-viewer.git cd gltf-viewer cargo install gltf-viewer ``` - + ## Usage ```shell USAGE: - gltf-viewer [OPTIONS] + gltf-viewer [OPTIONS] OPTIONS: -s, --screenshot Create screenshot (PNG) - -v, --verbose Enable verbose logging. + -v, --verbose Enable verbose logging (log level INFO). Can be repeated multiple times to increase log level to DEBUG/TRACE -w, --width Width in pixels [default: 800] -h, --height Height in pixels [default: 600] --help Prints help information -V, --version Prints version information ARGS: - glTF file name or URL + glTF file name ``` Both .gltf and .glb files are supported. Navigate the scene with `WASD` + Mouse. ### Example ``` -gltf-viewer https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/BarramundiFish/glTF/BarramundiFish.gltf +$ curl -O https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/Box/glTF-Binary/Box.glb +$ gltf-viewer Box.glb ``` +For more models, see [KhronosGroup/glTF-Sample-Models](https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0). ## Goals * Complete gltF 2.0 support @@ -61,6 +68,7 @@ gltf-viewer https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/ma * Platforms: Windows, Linux, macOS, Browser (via WebAssembly) * Graphics backends: - OpenGL ES 3.0 (-> WebGL 2.0 via WebAssembly) + - currently OpenGL 3.3 is used - Vulkan? * VR support * Focus: OpenVR (HTC Vive) From b4d1c015f311025ca55b5ffb73da3c193666f7e9 Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Sat, 23 Sep 2017 12:11:54 +0200 Subject: [PATCH 2/8] clippy + update cli docs --- src/main.rs | 15 +++++++++------ src/render/material.rs | 4 ++-- src/render/node.rs | 2 +- src/render/primitive.rs | 8 ++++---- src/shader.rs | 6 +++--- src/utils.rs | 4 ++-- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index ffe9fa6..4f2b445 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ #![allow(dead_code)] +#![allow(unknown_lints)] // #![allow(unused_features)] // #![feature(test)] #[macro_use] extern crate clap; @@ -62,10 +63,10 @@ pub fn main() { .version(crate_version!()) .setting(AppSettings::UnifiedHelpMessage) .setting(AppSettings::DeriveDisplayOrder) - .arg(Arg::with_name("FILE/URL") + .arg(Arg::with_name("FILE") // TODO!: re-add URL when fixed... .required(true) .takes_value(true) - .help("glTF file name or URL")) + .help("glTF file name")) .arg(Arg::with_name("screenshot") .long("screenshot") .short("s") @@ -75,7 +76,7 @@ pub fn main() { .long("verbose") .short("v") .multiple(true) - .help("Enable verbose logging (log level INFO). Can be repeated multiple times to increase to log level DEBUG/TRACE)")) + .help("Enable verbose logging (log level INFO). Can be repeated multiple times to increase log level to DEBUG/TRACE)")) .arg(Arg::with_name("WIDTH") .long("width") .short("w") @@ -89,7 +90,7 @@ pub fn main() { .help("Height in pixels") .validator(|value| value.parse::().map(|_| ()).map_err(|err| err.to_string()))) .get_matches(); - let source = args.value_of("FILE/URL").unwrap(); + let source = args.value_of("FILE").unwrap(); let width: u32 = args.value_of("WIDTH").unwrap().parse().unwrap(); let height: u32 = args.value_of("HEIGHT").unwrap().parse().unwrap(); @@ -250,7 +251,7 @@ impl GltfViewer { Ok((gltf, buffers)) => (gltf, buffers), Err(err) => { error!("glTF import failed: {}", err); - std::process::exit(1); + std::process::exit(1) }, }; @@ -297,7 +298,7 @@ impl GltfViewer { loop { // per-frame time logic // NOTE: Deliberately ignoring the seconds of `elapsed()` - self.delta_time = (self.last_frame.elapsed().subsec_nanos() as f64) / 1_000_000_000.0; + self.delta_time = f64::from(self.last_frame.elapsed().subsec_nanos()) / 1_000_000_000.0; self.last_frame = Instant::now(); // events @@ -355,6 +356,7 @@ impl GltfViewer { } } +#[allow(too_many_arguments)] fn process_events( events_loop: &mut glutin::EventsLoop, gl_window: &glutin::GlWindow, @@ -366,6 +368,7 @@ fn process_events( height: &mut u32) -> bool { let mut keep_running = true; + #[allow(single_match)] events_loop.poll_events(|event| { match event { glutin::Event::WindowEvent{ event, .. } => match event { diff --git a/src/render/material.rs b/src/render/material.rs index 4355fc5..53b9630 100644 --- a/src/render/material.rs +++ b/src/render/material.rs @@ -126,10 +126,10 @@ fn load_texture( assert_eq!(tex_coord, 0, "not yet implemented: tex coord set must be 0 (Material::from_gltf)"); if let Some(tex) = scene.textures.iter().find(|tex| (***tex).index == g_texture.index()) { - return tex.clone() + return Rc::clone(tex) } let texture = Rc::new(Texture::from_gltf(g_texture, tex_coord, buffers, base_path)); - scene.textures.push(texture.clone()); + scene.textures.push(Rc::clone(&texture)); texture } diff --git a/src/render/node.rs b/src/render/node.rs index e27ffd9..e707010 100644 --- a/src/render/node.rs +++ b/src/render/node.rs @@ -45,7 +45,7 @@ impl Node { let mut mesh = None; if let Some(g_mesh) = g_node.mesh() { if let Some(existing_mesh) = scene.meshes.iter().find(|mesh| (***mesh).index == g_mesh.index()) { - mesh = Some(existing_mesh.clone()); + mesh = Some(Rc::clone(existing_mesh)); } if mesh.is_none() { // not using else due to borrow-checking madness diff --git a/src/render/primitive.rs b/src/render/primitive.rs index 4060126..f2df731 100644 --- a/src/render/primitive.rs +++ b/src/render/primitive.rs @@ -184,12 +184,12 @@ impl Primitive { let mut material = None; if let Some(mat) = scene.materials.iter().find(|m| (***m).index == g_material.index()) { - material = mat.clone().into() + material = Rc::clone(mat).into() } if material.is_none() { // no else due to borrow checker madness let mat = Rc::new(Material::from_gltf(&g_material, scene, buffers, base_path)); - scene.materials.push(mat.clone()); + scene.materials.push(Rc::clone(&mat)); material = Some(mat); }; let material = material.unwrap(); @@ -198,7 +198,7 @@ impl Primitive { let mut new_shader = false; // borrow checker workaround let shader = if let Some(shader) = scene.shaders.get(&shader_flags) { - shader.clone() + Rc::clone(shader) } else { new_shader = true; @@ -206,7 +206,7 @@ impl Primitive { }; if new_shader { - scene.shaders.insert(shader_flags, shader.clone()); + scene.shaders.insert(shader_flags, Rc::clone(&shader)); } Primitive::new(bounds.into(), vertices, indices, material, shader) diff --git a/src/shader.rs b/src/shader.rs index 1c75609..322ab24 100644 --- a/src/shader.rs +++ b/src/shader.rs @@ -146,12 +146,12 @@ impl Shader { /// utility function for checking shader compilation/linking errors. /// ------------------------------------------------------------------------ unsafe fn check_compile_errors(&self, shader: u32, type_: &str) { - let mut success = gl::FALSE as GLint; + let mut success = i32::from(gl::FALSE); let mut info_log = Vec::with_capacity(1024); info_log.set_len(1024 - 1); // subtract 1 to skip the trailing null character if type_ != "PROGRAM" { gl::GetShaderiv(shader, gl::COMPILE_STATUS, &mut success); - let log_type = if success == gl::TRUE as GLint { "WARNING" } else { "ERROR" }; + let log_type = if success == i32::from(gl::TRUE) { "WARNING" } else { "ERROR" }; let mut length = 0; gl::GetShaderInfoLog(shader, 1024, &mut length, info_log.as_mut_ptr() as *mut GLchar); if length == 0 { return } @@ -162,7 +162,7 @@ impl Shader { } else { gl::GetProgramiv(shader, gl::LINK_STATUS, &mut success); - let log_type = if success == gl::TRUE as GLint { "WARNING" } else { "ERROR" }; + let log_type = if success == i32::from(gl::TRUE) { "WARNING" } else { "ERROR" }; let mut length = 0; gl::GetProgramInfoLog(shader, 1024, &mut length, info_log.as_mut_ptr() as *mut GLchar); if length == 0 { return } diff --git a/src/utils.rs b/src/utils.rs index 57a6895..6935b50 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -12,7 +12,7 @@ pub fn elapsed(start_time: &Instant) -> String { fn format_duration(duration: Duration) -> String { let secs = duration.as_secs(); let nanos = duration.subsec_nanos(); - let ms = nanos as f64 / 1_000_000.0; + let ms = f64::from(nanos) / 1_000_000.0; if secs > 0 { let secs = secs as f64 + ms / 1000.0; format!("{:<4.*} s", 1, secs) @@ -22,7 +22,7 @@ fn format_duration(duration: Duration) -> String { if ms >= 20.0 { 0 } else if ms >= 1.0 { 1 } else { - let micros = nanos as f64 / 1000.0; + let micros = f64::from(nanos) / 1000.0; let places = if micros >= 10.0 { 0 } else { 2 }; return format!("{:>3.*} µs", places, micros) }; From 70e29bff3c774dd548190ffe15630c86215f76c2 Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Sat, 23 Sep 2017 13:39:33 +0200 Subject: [PATCH 3/8] allow deprecated transform functions, but add TODO --- src/render/node.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/render/node.rs b/src/render/node.rs index e707010..c8c10fc 100644 --- a/src/render/node.rs +++ b/src/render/node.rs @@ -27,7 +27,10 @@ pub struct Node { pub bounds: Bounds, } + impl Node { + // TODO!: refactor transformations using mint and non-deprecated functions + #[allow(deprecated)] pub fn from_gltf( g_node: gltf::Node, scene: &mut Scene, @@ -62,7 +65,6 @@ impl Node { matrix, mesh, rotation, - // TODO!!: use of deprecated item: Use `transform().decomposed()` instead. scale: g_node.scale().into(), translation: g_node.translation().into(), name: g_node.name().map(|s| s.into()), From f9d6b1d4c226ec9f3316890cd2f97da38eb045e0 Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Sat, 23 Sep 2017 14:02:13 +0200 Subject: [PATCH 4/8] better error message for missing files --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 4f2b445..f52cd8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -250,7 +250,10 @@ impl GltfViewer { let (gltf, buffers) = match gltf_importer::import_with_config(source, config) { Ok((gltf, buffers)) => (gltf, buffers), Err(err) => { - error!("glTF import failed: {}", err); + error!("glTF import failed: {:?}", err); + if let gltf_importer::Error::Io(_) = err { + error!("Hint: Are the .bin file(s) referenced by the .gltf file available?") + } std::process::exit(1) }, }; From e381f2d324e15a972ec1558f40228c7e7282e2b8 Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Sat, 23 Sep 2017 14:07:47 +0200 Subject: [PATCH 5/8] fully remove simple shader --- src/shaders/simple-frag.glsl | 29 ----------------------------- src/shaders/simple-vert.glsl | 27 --------------------------- 2 files changed, 56 deletions(-) delete mode 100644 src/shaders/simple-frag.glsl delete mode 100644 src/shaders/simple-vert.glsl diff --git a/src/shaders/simple-frag.glsl b/src/shaders/simple-frag.glsl deleted file mode 100644 index 01a8f55..0000000 --- a/src/shaders/simple-frag.glsl +++ /dev/null @@ -1,29 +0,0 @@ -#version 330 core -out vec4 FragColor; - -// in vec3 Normal; -in vec4 Tangent; -in vec2 TexCoords_0; -in vec2 TexCoords_1; -in vec3 Color; - -uniform sampler2D base_color_texture; -uniform vec4 base_color_factor; - -void main() -{ - vec4 baseColor = texture(base_color_texture, TexCoords_0); - // TODO!: HACK - if (baseColor.x > 0 || baseColor.y > 0 || baseColor.z > 0) { - FragColor = baseColor * base_color_factor; - } - else { - FragColor = base_color_factor; - } - - // FragColor = vec4(Normal, 1.0); - // FragColor = vec4(Tangent.xyz, 1.0); - // FragColor = vec4(TexCoords_0, 0.0, 1.0); - // FragColor = vec4(TexCoords_1, 0,0, 1.0); - // FragColor = vec4(Color, 1.0); -} diff --git a/src/shaders/simple-vert.glsl b/src/shaders/simple-vert.glsl deleted file mode 100644 index e75b9bc..0000000 --- a/src/shaders/simple-vert.glsl +++ /dev/null @@ -1,27 +0,0 @@ -#version 330 core -layout (location = 0) in vec3 aPos; -layout (location = 1) in vec3 aNormal; -layout (location = 2) in vec4 aTangent; -layout (location = 3) in vec2 aTexCoords_0; -layout (location = 4) in vec2 aTexCoords_1; -layout (location = 5) in vec3 aColor; - -// out vec3 Normal; -// out vec4 Tangent; -out vec2 TexCoords_0; -// out vec2 TexCoords_1; -// out vec3 Color; - -uniform mat4 model; -uniform mat4 view; -uniform mat4 projection; - -void main() -{ - // Normal = aNormal; // TODO: transform - // Tangent = aTangent; - TexCoords_0 = aTexCoords_0; - // TexCoords_1 = aTexCoords_1; - // Color = aColor; - gl_Position = projection * view * model * vec4(aPos, 1.0); -} From 81cd756eb67314682bd4ac12e7c7ba6122f87141 Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Sat, 23 Sep 2017 14:34:22 +0200 Subject: [PATCH 6/8] fix for broken japaric/cross release --- ci/install.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ci/install.sh b/ci/install.sh index 97100e5..40346d6 100644 --- a/ci/install.sh +++ b/ci/install.sh @@ -18,6 +18,9 @@ main() { | grep -E '^v[0.1.0-9.]+$' \ | $sort --version-sort \ | tail -n1) + # TODO!: temporary workaround for https://github.com/japaric/cross/issues/126 + tag=v0.1.11 + curl -LSfs https://japaric.github.io/trust/install.sh | \ sh -s -- \ --force \ From ea48d3456a6da0b5434607443809ee5806b40495 Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Sat, 23 Sep 2017 15:09:44 +0200 Subject: [PATCH 7/8] appveyor: skip_branch_with_pr --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 2e6c592..5205712 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -82,3 +82,5 @@ notifications: # Building is done in the test phase, so we disable Appveyor's build phase. build: false + +skip_branch_with_pr: true From 4ad5938ec4db200e1aa810342b3818353cc9b597 Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Sat, 23 Sep 2017 14:38:43 +0200 Subject: [PATCH 8/8] remove obsolete rls.toml --- rls.toml | 1 - 1 file changed, 1 deletion(-) delete mode 100644 rls.toml diff --git a/rls.toml b/rls.toml deleted file mode 100644 index a5e1c6c..0000000 --- a/rls.toml +++ /dev/null @@ -1 +0,0 @@ -unstable_features = true \ No newline at end of file