Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #70

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,644 changes: 1,885 additions & 759 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,33 @@ branch = "master"
repository = "bwasty/gltf-viewer"

[dependencies]
base64 = "0.11.0"
bitflags = "1.2.1"
base64 = "0.20.0"
bitflags = "1.3.2"
cgmath = "0.17.0"
clap = "2.33.0"
collision = "0.20.1"
# futures = "0.1.14"
# futures-cpupool = "0.1.5"
gl = "0.14.0"
glutin = "0.18.0"
image = "0.21.0"
glutin = "0.31"
image = "0.24.5"
# reqwest = "0.7.3"
log = "0.4.8"
num-traits = "0.2.11"
simplelog = "0.7.4"
log = "0.4.17"
num-traits = "0.2.15"
raw-window-handle = "0.5"
simplelog = "0.12.0"
# itertools = "0.6.3"
winit = { version = "0.30", features = ["rwh_05"] }

[dependencies.gltf]
version = "0.15.0"
version = "1.0.0"
features = ["names"]

# [dependencies.mikktspace]
# git = "https://github.com/gltf-rs/mikktspace"

[build-dependencies]
git-version = "0.2.1"
git-version = "0.3.5"

# [profile.dev]
# opt-level = 2
Expand Down
20 changes: 13 additions & 7 deletions src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use num_traits::clamp;
use crate::render::Camera;
use crate::render::math::*;

use glutin::dpi::PhysicalPosition;
use glutin::dpi::PhysicalSize;
use winit::dpi::PhysicalPosition;
use winit::dpi::PhysicalSize;

// Defines several possible options for camera movement. Used as abstraction to stay away from window-system specific input methods
#[derive(PartialEq, Clone, Copy)]
Expand Down Expand Up @@ -79,11 +79,11 @@ pub struct OrbitControls {
pub moving_forward: bool,
pub moving_backward: bool,

pub screen_size: PhysicalSize,
pub screen_size: PhysicalSize<f64>,
}

impl OrbitControls {
pub fn new(position: Point3, screen_size: PhysicalSize) -> Self {
pub fn new(position: Point3, screen_size: PhysicalSize<f64>) -> Self {
OrbitControls {
camera: Camera::default(),

Expand Down Expand Up @@ -129,15 +129,15 @@ impl OrbitControls {
Matrix4::look_at(self.position, self.target, vec3(0.0, 1.0, 0.0))
}

pub fn handle_mouse_move(&mut self, pos: PhysicalPosition) {
pub fn handle_mouse_move(&mut self, pos: PhysicalPosition<f64>) {
match self.state {
NavState::Rotating => self.handle_mouse_move_rotate(pos),
NavState::Panning => self.handle_mouse_move_pan(pos),
NavState::None => ()
}
}

fn handle_mouse_move_rotate(&mut self, pos: PhysicalPosition) {
fn handle_mouse_move_rotate(&mut self, pos: PhysicalPosition<f64>) {
self.rotate_end.x = pos.x as f32;
self.rotate_end.y = pos.y as f32;
let rotate_delta = if let Some(rotate_start) = self.rotate_start {
Expand Down Expand Up @@ -177,7 +177,7 @@ impl OrbitControls {
self.spherical_delta.phi -= angle;
}

fn handle_mouse_move_pan(&mut self, pos: PhysicalPosition) {
fn handle_mouse_move_pan(&mut self, pos: PhysicalPosition<f64>) {
self.pan_end.x = pos.x as f32;
self.pan_end.y = pos.y as f32;

Expand Down Expand Up @@ -221,6 +221,12 @@ impl OrbitControls {
self.pan_offset.y -= distance
}

pub fn pan_both(&mut self, delta: PhysicalPosition<f32>) {
self.pan_offset.x += delta.x;
self.pan_offset.y += delta.y;
self.update();
}

// Processes input received from a mouse scroll-wheel event. Only requires input on the vertical wheel-axis
pub fn process_mouse_scroll(&mut self, mut yoffset: f32) {
yoffset *= ZOOM_SENSITIVITY;
Expand Down
13 changes: 9 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use clap::{Arg, App, AppSettings};

use log::warn;

use simplelog::{TermLogger, LevelFilter, ConfigBuilder as LogConfigBuilder, TerminalMode};
use simplelog::{ColorChoice, TermLogger, LevelFilter, ConfigBuilder as
LogConfigBuilder, TerminalMode};

mod utils;
mod viewer;
Expand Down Expand Up @@ -135,9 +136,13 @@ pub fn main() {
.set_target_level(LevelFilter::Off)
.set_thread_level(LevelFilter::Off)
.build(),
TerminalMode::Stdout);
TerminalMode::Stdout,
ColorChoice::Auto);

let mut viewer = GltfViewer::new(source, width, height,
let mut event_loop = winit::event_loop::EventLoop::new().unwrap();
event_loop.set_control_flow(winit::event_loop::ControlFlow::Wait);

let mut viewer = GltfViewer::new(&mut event_loop, source, width, height,
args.is_present("headless"),
!args.is_present("screenshot"),
camera_options,
Expand All @@ -157,7 +162,7 @@ pub fn main() {
return;
}

viewer.start_render_loop();
event_loop.run_app(&mut viewer).unwrap();
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/render/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct Material {
pub emissive_factor: Vector3,
pub emissive_texture: Option<Rc<Texture>>,

pub alpha_cutoff: f32,
pub alpha_cutoff: Option<f32>,
pub alpha_mode: gltf::material::AlphaMode,

pub double_sided: bool,
Expand Down
4 changes: 3 additions & 1 deletion src/render/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ impl Primitive {
shader.set_float(uniforms.u_AlphaBlend, 1.0);

if mat.alpha_mode == gltf::material::AlphaMode::Mask {
shader.set_float(uniforms.u_AlphaCutoff, mat.alpha_cutoff);
if let Some(alpha_cutoff) = mat.alpha_cutoff.as_ref() {
shader.set_float(uniforms.u_AlphaCutoff, *alpha_cutoff);
}
}
}

Expand Down
35 changes: 19 additions & 16 deletions src/render/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use gltf::json::texture::MinFilter;
use gltf::image::Source;

use image;
use image::ImageFormat::{JPEG, PNG};
use image::ImageFormat::{Jpeg, Png};
use image::DynamicImage::*;
use image::GenericImageView;
use image::FilterType;
use image::imageops::FilterType;

use crate::importdata::ImportData;

Expand Down Expand Up @@ -45,8 +45,8 @@ impl Texture {
let end = begin + view.length();
let data = &parent_buffer_data[begin..end];
match mime_type {
"image/jpeg" => image::load_from_memory_with_format(data, JPEG),
"image/png" => image::load_from_memory_with_format(data, PNG),
"image/jpeg" => image::load_from_memory_with_format(data, Jpeg),
"image/png" => image::load_from_memory_with_format(data, Png),
_ => panic!(format!("unsupported image type (image: {}, mime_type: {})",
g_img.index(), mime_type)),
}
Expand All @@ -67,8 +67,8 @@ impl Texture {
};

match mime_type {
"image/jpeg" => image::load_from_memory_with_format(&data, JPEG),
"image/png" => image::load_from_memory_with_format(&data, PNG),
"image/jpeg" => image::load_from_memory_with_format(&data, Jpeg),
"image/png" => image::load_from_memory_with_format(&data, Png),
_ => panic!(format!("unsupported image type (image: {}, mime_type: {})",
g_img.index(), mime_type)),
}
Expand All @@ -78,8 +78,8 @@ impl Texture {
let file = fs::File::open(path).unwrap();
let reader = io::BufReader::new(file);
match mime_type {
"image/jpeg" => image::load(reader, JPEG),
"image/png" => image::load(reader, PNG),
"image/jpeg" => image::load(reader, Jpeg),
"image/png" => image::load(reader, Png),
_ => panic!(format!("unsupported image type (image: {}, mime_type: {})",
g_img.index(), mime_type)),
}
Expand All @@ -95,12 +95,11 @@ impl Texture {
let dyn_img = img.expect("Image loading failed.");

let format = match dyn_img {
ImageLuma8(_) => gl::RED,
ImageLumaA8(_) => gl::RG,
ImageRgb8(_) => gl::RGB,
ImageRgba8(_) => gl::RGBA,
ImageBgr8(_) => gl::BGR,
ImageBgra8(_) => gl::BGRA,
ImageLuma8(_) | ImageLuma16(_) => gl::RED,
ImageLumaA8(_) | ImageLumaA16(_) => gl::RG,
ImageRgb8(_) | ImageRgb16(_) | ImageRgb32F(_) => gl::RGB,
ImageRgba8(_) | ImageRgba16(_) | ImageRgba32F(_) => gl::RGBA,
_ => unimplemented!("non exhaustive")
};

// **Non-Power-Of-Two Texture Implementation Note**: glTF does not guarantee that a texture's
Expand All @@ -116,10 +115,14 @@ impl Texture {
let nwidth = width.next_power_of_two();
let nheight = height.next_power_of_two();
let resized = dyn_img.resize(nwidth, nheight, FilterType::Lanczos3);
(resized.raw_pixels(), resized.width(), resized.height())
let width = resized.width();
let height = resized.height();
(resized.into_bytes(), width, height)
}
else {
(dyn_img.raw_pixels(), dyn_img.width(), dyn_img.height())
let width = dyn_img.width();
let height = dyn_img.height();
(dyn_img.into_bytes(), width, height)
};

unsafe {
Expand Down
Loading