new bones, update asset repo

Former-commit-id: 4dbed55af4a9532051025a797349e77bd937dff2
This commit is contained in:
Imbris 2019-04-08 22:57:02 -04:00 committed by Pfauenauge90
parent fb83c836a1
commit 07a4cb268e
4 changed files with 84 additions and 104 deletions

View File

@ -7,14 +7,12 @@ pub use self::run::RunAnimation;
use crate::render::FigureBoneData; use crate::render::FigureBoneData;
// Local // Local
use super::{ use super::{Bone, Skeleton};
Skeleton,
Bone,
};
pub struct CharacterSkeleton { pub struct CharacterSkeleton {
head: Bone, head: Bone,
chest: Bone, chest: Bone,
shoulders: Bone,
belt: Bone, belt: Bone,
shorts: Bone, shorts: Bone,
l_hand: Bone, l_hand: Bone,
@ -22,6 +20,8 @@ pub struct CharacterSkeleton {
l_foot: Bone, l_foot: Bone,
r_foot: Bone, r_foot: Bone,
back: Bone, back: Bone,
eyes: Bone,
hair: Bone,
} }
impl CharacterSkeleton { impl CharacterSkeleton {
@ -29,6 +29,7 @@ impl CharacterSkeleton {
Self { Self {
head: Bone::default(), head: Bone::default(),
chest: Bone::default(), chest: Bone::default(),
shoulders: Bone::default(),
belt: Bone::default(), belt: Bone::default(),
shorts: Bone::default(), shorts: Bone::default(),
l_hand: Bone::default(), l_hand: Bone::default(),
@ -36,6 +37,8 @@ impl CharacterSkeleton {
l_foot: Bone::default(), l_foot: Bone::default(),
r_foot: Bone::default(), r_foot: Bone::default(),
back: Bone::default(), back: Bone::default(),
eyes: Bone::default(),
hair: Bone::default(),
} }
} }
} }
@ -54,9 +57,9 @@ impl Skeleton for CharacterSkeleton {
FigureBoneData::new(self.l_foot.compute_base_matrix()), FigureBoneData::new(self.l_foot.compute_base_matrix()),
FigureBoneData::new(self.r_foot.compute_base_matrix()), FigureBoneData::new(self.r_foot.compute_base_matrix()),
FigureBoneData::new(chest_mat * self.back.compute_base_matrix()), FigureBoneData::new(chest_mat * self.back.compute_base_matrix()),
FigureBoneData::default(), FigureBoneData::new(self.shoulders.compute_base_matrix()),
FigureBoneData::default(), FigureBoneData::new(self.eyes.compute_base_matrix()),
FigureBoneData::default(), FigureBoneData::new(self.hair.compute_base_matrix()),
FigureBoneData::default(), FigureBoneData::default(),
FigureBoneData::default(), FigureBoneData::default(),
FigureBoneData::default(), FigureBoneData::default(),

View File

@ -5,10 +5,7 @@ use std::f32::consts::PI;
use vek::*; use vek::*;
// Local // Local
use super::{ use super::{super::Animation, CharacterSkeleton};
CharacterSkeleton,
super::Animation,
};
pub struct RunAnimation; pub struct RunAnimation;
@ -16,11 +13,8 @@ impl Animation for RunAnimation {
type Skeleton = CharacterSkeleton; type Skeleton = CharacterSkeleton;
type Dependency = f64; type Dependency = f64;
fn update_skeleton( fn update_skeleton(skeleton: &mut Self::Skeleton, time: f64) {
skeleton: &mut Self::Skeleton, /*let wave = (time as f32 * 12.0).sin();
time: f64,
) {
let wave = (time as f32 * 12.0).sin();
let wave_slow = (time as f32 * 6.0 + PI).sin(); let wave_slow = (time as f32 * 6.0 + PI).sin();
let wave_dip = (wave_slow.abs() - 0.5).abs(); let wave_dip = (wave_slow.abs() - 0.5).abs();
@ -44,7 +38,7 @@ impl Animation for RunAnimation {
skeleton.r_foot.offset = Vec3::new(3.5, 1.0 + wave * 8.0, 3.5 - wave_dip * 4.0); skeleton.r_foot.offset = Vec3::new(3.5, 1.0 + wave * 8.0, 3.5 - wave_dip * 4.0);
skeleton.r_foot.ori = Quaternion::rotation_x(wave + 1.0); skeleton.r_foot.ori = Quaternion::rotation_x(wave + 1.0);
skeleton.back.offset = Vec3::new(-9.0, 5.0, 18.0); skeleton.back.offset = Vec3::new(-9.0, 5.0, 18.0);*/
skeleton.back.ori = Quaternion::rotation_y(2.5); skeleton.back.ori = Quaternion::rotation_y(2.5);
} }
} }

View File

@ -1,19 +1,12 @@
use crate::{
anim::Skeleton,
render::{
Consts, FigureBoneData, FigureLocals, FigurePipeline, Globals, Mesh, Model, Renderer,
},
Error,
};
use specs::{Component, VecStorage}; use specs::{Component, VecStorage};
use vek::*; use vek::*;
use crate::{
Error,
render::{
Consts,
Globals,
Mesh,
Model,
Renderer,
FigurePipeline,
FigureBoneData,
FigureLocals,
},
anim::Skeleton,
};
pub struct Figure<S: Skeleton> { pub struct Figure<S: Skeleton> {
// GPU data // GPU data
@ -64,18 +57,17 @@ impl<S: Skeleton> Figure<S> {
Ok(()) Ok(())
} }
pub fn update_locals(&mut self, renderer: &mut Renderer, locals: FigureLocals) -> Result<(), Error> { pub fn update_locals(
&mut self,
renderer: &mut Renderer,
locals: FigureLocals,
) -> Result<(), Error> {
renderer.update_consts(&mut self.locals, &[locals])?; renderer.update_consts(&mut self.locals, &[locals])?;
Ok(()) Ok(())
} }
pub fn render(&self, renderer: &mut Renderer, globals: &Consts<Globals>) { pub fn render(&self, renderer: &mut Renderer, globals: &Consts<Globals>) {
renderer.render_figure( renderer.render_figure(&self.model, globals, &self.locals, &self.bone_consts);
&self.model,
globals,
&self.locals,
&self.bone_consts,
);
} }
} }

View File

@ -2,36 +2,23 @@ pub mod camera;
pub mod figure; pub mod figure;
pub mod terrain; pub mod terrain;
use vek::*; use self::{camera::Camera, figure::Figure, terrain::Terrain};
use dot_vox;
use common::{
comp,
figure::Segment,
};
use client::Client;
use crate::{ use crate::{
anim::{
character::{CharacterSkeleton, RunAnimation},
Animation,
},
mesh::Meshable,
render::{ render::{
Consts, create_skybox_mesh, Consts, FigureLocals, Globals, Model, Renderer, SkyboxLocals,
Globals,
Model,
Renderer,
SkyboxPipeline, SkyboxPipeline,
SkyboxLocals,
FigureLocals,
create_skybox_mesh,
}, },
window::Event, window::Event,
mesh::Meshable,
anim::{
Animation,
character::{CharacterSkeleton, RunAnimation},
},
};
use self::{
camera::Camera,
figure::Figure,
terrain::Terrain,
}; };
use client::Client;
use common::{comp, figure::Segment};
use dot_vox;
use vek::*;
// TODO: Don't hard-code this // TODO: Don't hard-code this
const CURSOR_PAN_SCALE: f32 = 0.005; const CURSOR_PAN_SCALE: f32 = 0.005;
@ -53,25 +40,25 @@ pub struct Scene {
// TODO: Make a proper asset loading system // TODO: Make a proper asset loading system
fn load_segment(filename: &'static str) -> Segment { fn load_segment(filename: &'static str) -> Segment {
Segment::from(dot_vox::load(&(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/voxel/").to_string() + filename)).unwrap()) Segment::from(
dot_vox::load(
&(concat!(env!("CARGO_MANIFEST_DIR"), "/../assets/voxygen/voxel/").to_string()
+ filename),
)
.unwrap(),
)
} }
impl Scene { impl Scene {
/// Create a new `Scene` with default parameters. /// Create a new `Scene` with default parameters.
pub fn new(renderer: &mut Renderer, client: &Client) -> Self { pub fn new(renderer: &mut Renderer, client: &Client) -> Self {
Self { Self {
globals: renderer globals: renderer.create_consts(&[Globals::default()]).unwrap(),
.create_consts(&[Globals::default()])
.unwrap(),
camera: Camera::new(), camera: Camera::new(),
skybox: Skybox { skybox: Skybox {
model: renderer model: renderer.create_model(&create_skybox_mesh()).unwrap(),
.create_model(&create_skybox_mesh()) locals: renderer.create_consts(&[SkyboxLocals::default()]).unwrap(),
.unwrap(),
locals: renderer
.create_consts(&[SkyboxLocals::default()])
.unwrap(),
}, },
terrain: Terrain::new(), terrain: Terrain::new(),
@ -97,15 +84,19 @@ impl Scene {
], ],
CharacterSkeleton::new(), CharacterSkeleton::new(),
) )
.unwrap(), .unwrap(),
} }
} }
/// Get a reference to the scene's camera. /// Get a reference to the scene's camera.
pub fn camera(&self) -> &Camera { &self.camera } pub fn camera(&self) -> &Camera {
&self.camera
}
/// Get a mutable reference to the scene's camera. /// Get a mutable reference to the scene's camera.
pub fn camera_mut(&mut self) -> &mut Camera { &mut self.camera } pub fn camera_mut(&mut self) -> &mut Camera {
&mut self.camera
}
/// Handle an incoming user input event (i.e: cursor moved, key pressed, window closed, etc.). /// Handle an incoming user input event (i.e: cursor moved, key pressed, window closed, etc.).
/// ///
@ -116,17 +107,17 @@ impl Scene {
Event::Resize(dims) => { Event::Resize(dims) => {
self.camera.set_aspect_ratio(dims.x as f32 / dims.y as f32); self.camera.set_aspect_ratio(dims.x as f32 / dims.y as f32);
true true
}, }
// Panning the cursor makes the camera rotate // Panning the cursor makes the camera rotate
Event::CursorPan(delta) => { Event::CursorPan(delta) => {
self.camera.rotate_by(Vec3::from(delta) * CURSOR_PAN_SCALE); self.camera.rotate_by(Vec3::from(delta) * CURSOR_PAN_SCALE);
true true
}, }
// Zoom the camera when a zoom event occurs // Zoom the camera when a zoom event occurs
Event::Zoom(delta) => { Event::Zoom(delta) => {
self.camera.zoom_by(-delta); self.camera.zoom_by(-delta);
true true
}, }
// All other events are unhandled // All other events are unhandled
_ => false, _ => false,
} }
@ -137,13 +128,14 @@ impl Scene {
// Get player position // Get player position
let player_pos = client let player_pos = client
.player() .player()
.and_then(|ent| client .and_then(|ent| {
.state() client
.ecs_world() .state()
.read_storage::<comp::phys::Pos>() .ecs_world()
.get(ent) .read_storage::<comp::phys::Pos>()
.map(|pos| pos.0) .get(ent)
) .map(|pos| pos.0)
})
.unwrap_or(Vec3::zero()); .unwrap_or(Vec3::zero());
// Alter camera position to match player // Alter camera position to match player
@ -153,41 +145,40 @@ impl Scene {
let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents(); let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents();
// Update global constants // Update global constants
renderer.update_consts(&mut self.globals, &[Globals::new( renderer
view_mat, .update_consts(
proj_mat, &mut self.globals,
cam_pos, &[Globals::new(
self.camera.get_focus_pos(), view_mat,
10.0, proj_mat,
client.state().get_time_of_day(), cam_pos,
client.state().get_time(), self.camera.get_focus_pos(),
)]) 10.0,
client.state().get_time_of_day(),
client.state().get_time(),
)],
)
.expect("Failed to update global constants"); .expect("Failed to update global constants");
// Maintain the terrain // Maintain the terrain
self.terrain.maintain(renderer, client); self.terrain.maintain(renderer, client);
// TODO: Don't do this here // TODO: Don't do this here
RunAnimation::update_skeleton( RunAnimation::update_skeleton(&mut self.test_figure.skeleton, client.state().get_time());
&mut self.test_figure.skeleton,
client.state().get_time(),
);
// Calculate player model matrix // Calculate player model matrix
let model_mat = Mat4::<f32>::translation_3d(player_pos); let model_mat = Mat4::<f32>::translation_3d(player_pos);
self.test_figure.update_locals(renderer, FigureLocals::new(model_mat)).unwrap(); self.test_figure
.update_locals(renderer, FigureLocals::new(model_mat))
.unwrap();
self.test_figure.update_skeleton(renderer).unwrap(); self.test_figure.update_skeleton(renderer).unwrap();
} }
/// Render the scene using the provided `Renderer` /// Render the scene using the provided `Renderer`
pub fn render_to(&self, renderer: &mut Renderer) { pub fn render_to(&self, renderer: &mut Renderer) {
// Render the skybox first (it appears over everything else so must be rendered first) // Render the skybox first (it appears over everything else so must be rendered first)
renderer.render_skybox( renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
&self.skybox.model,
&self.globals,
&self.skybox.locals,
);
// Render terrain // Render terrain
self.terrain.render(renderer, &self.globals); self.terrain.render(renderer, &self.globals);