mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
new bones, update asset repo
Former-commit-id: 4dbed55af4a9532051025a797349e77bd937dff2
This commit is contained in:
parent
fb83c836a1
commit
07a4cb268e
@ -7,14 +7,12 @@ pub use self::run::RunAnimation;
|
||||
use crate::render::FigureBoneData;
|
||||
|
||||
// Local
|
||||
use super::{
|
||||
Skeleton,
|
||||
Bone,
|
||||
};
|
||||
use super::{Bone, Skeleton};
|
||||
|
||||
pub struct CharacterSkeleton {
|
||||
head: Bone,
|
||||
chest: Bone,
|
||||
shoulders: Bone,
|
||||
belt: Bone,
|
||||
shorts: Bone,
|
||||
l_hand: Bone,
|
||||
@ -22,6 +20,8 @@ pub struct CharacterSkeleton {
|
||||
l_foot: Bone,
|
||||
r_foot: Bone,
|
||||
back: Bone,
|
||||
eyes: Bone,
|
||||
hair: Bone,
|
||||
}
|
||||
|
||||
impl CharacterSkeleton {
|
||||
@ -29,6 +29,7 @@ impl CharacterSkeleton {
|
||||
Self {
|
||||
head: Bone::default(),
|
||||
chest: Bone::default(),
|
||||
shoulders: Bone::default(),
|
||||
belt: Bone::default(),
|
||||
shorts: Bone::default(),
|
||||
l_hand: Bone::default(),
|
||||
@ -36,6 +37,8 @@ impl CharacterSkeleton {
|
||||
l_foot: Bone::default(),
|
||||
r_foot: 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.r_foot.compute_base_matrix()),
|
||||
FigureBoneData::new(chest_mat * self.back.compute_base_matrix()),
|
||||
FigureBoneData::default(),
|
||||
FigureBoneData::default(),
|
||||
FigureBoneData::default(),
|
||||
FigureBoneData::new(self.shoulders.compute_base_matrix()),
|
||||
FigureBoneData::new(self.eyes.compute_base_matrix()),
|
||||
FigureBoneData::new(self.hair.compute_base_matrix()),
|
||||
FigureBoneData::default(),
|
||||
FigureBoneData::default(),
|
||||
FigureBoneData::default(),
|
||||
|
@ -5,10 +5,7 @@ use std::f32::consts::PI;
|
||||
use vek::*;
|
||||
|
||||
// Local
|
||||
use super::{
|
||||
CharacterSkeleton,
|
||||
super::Animation,
|
||||
};
|
||||
use super::{super::Animation, CharacterSkeleton};
|
||||
|
||||
pub struct RunAnimation;
|
||||
|
||||
@ -16,11 +13,8 @@ impl Animation for RunAnimation {
|
||||
type Skeleton = CharacterSkeleton;
|
||||
type Dependency = f64;
|
||||
|
||||
fn update_skeleton(
|
||||
skeleton: &mut Self::Skeleton,
|
||||
time: f64,
|
||||
) {
|
||||
let wave = (time as f32 * 12.0).sin();
|
||||
fn update_skeleton(skeleton: &mut Self::Skeleton, time: f64) {
|
||||
/*let wave = (time as f32 * 12.0).sin();
|
||||
let wave_slow = (time as f32 * 6.0 + PI).sin();
|
||||
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.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);
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,12 @@
|
||||
use crate::{
|
||||
anim::Skeleton,
|
||||
render::{
|
||||
Consts, FigureBoneData, FigureLocals, FigurePipeline, Globals, Mesh, Model, Renderer,
|
||||
},
|
||||
Error,
|
||||
};
|
||||
use specs::{Component, VecStorage};
|
||||
use vek::*;
|
||||
use crate::{
|
||||
Error,
|
||||
render::{
|
||||
Consts,
|
||||
Globals,
|
||||
Mesh,
|
||||
Model,
|
||||
Renderer,
|
||||
FigurePipeline,
|
||||
FigureBoneData,
|
||||
FigureLocals,
|
||||
},
|
||||
anim::Skeleton,
|
||||
};
|
||||
|
||||
pub struct Figure<S: Skeleton> {
|
||||
// GPU data
|
||||
@ -64,18 +57,17 @@ impl<S: Skeleton> Figure<S> {
|
||||
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])?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn render(&self, renderer: &mut Renderer, globals: &Consts<Globals>) {
|
||||
renderer.render_figure(
|
||||
&self.model,
|
||||
globals,
|
||||
&self.locals,
|
||||
&self.bone_consts,
|
||||
);
|
||||
renderer.render_figure(&self.model, globals, &self.locals, &self.bone_consts);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,36 +2,23 @@ pub mod camera;
|
||||
pub mod figure;
|
||||
pub mod terrain;
|
||||
|
||||
use vek::*;
|
||||
use dot_vox;
|
||||
use common::{
|
||||
comp,
|
||||
figure::Segment,
|
||||
};
|
||||
use client::Client;
|
||||
use self::{camera::Camera, figure::Figure, terrain::Terrain};
|
||||
use crate::{
|
||||
anim::{
|
||||
character::{CharacterSkeleton, RunAnimation},
|
||||
Animation,
|
||||
},
|
||||
mesh::Meshable,
|
||||
render::{
|
||||
Consts,
|
||||
Globals,
|
||||
Model,
|
||||
Renderer,
|
||||
create_skybox_mesh, Consts, FigureLocals, Globals, Model, Renderer, SkyboxLocals,
|
||||
SkyboxPipeline,
|
||||
SkyboxLocals,
|
||||
FigureLocals,
|
||||
create_skybox_mesh,
|
||||
},
|
||||
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
|
||||
const CURSOR_PAN_SCALE: f32 = 0.005;
|
||||
@ -53,25 +40,25 @@ pub struct Scene {
|
||||
|
||||
// TODO: Make a proper asset loading system
|
||||
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 {
|
||||
/// Create a new `Scene` with default parameters.
|
||||
pub fn new(renderer: &mut Renderer, client: &Client) -> Self {
|
||||
Self {
|
||||
globals: renderer
|
||||
.create_consts(&[Globals::default()])
|
||||
.unwrap(),
|
||||
globals: renderer.create_consts(&[Globals::default()]).unwrap(),
|
||||
camera: Camera::new(),
|
||||
|
||||
skybox: Skybox {
|
||||
model: renderer
|
||||
.create_model(&create_skybox_mesh())
|
||||
.unwrap(),
|
||||
locals: renderer
|
||||
.create_consts(&[SkyboxLocals::default()])
|
||||
.unwrap(),
|
||||
model: renderer.create_model(&create_skybox_mesh()).unwrap(),
|
||||
locals: renderer.create_consts(&[SkyboxLocals::default()]).unwrap(),
|
||||
},
|
||||
terrain: Terrain::new(),
|
||||
|
||||
@ -97,15 +84,19 @@ impl Scene {
|
||||
],
|
||||
CharacterSkeleton::new(),
|
||||
)
|
||||
.unwrap(),
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
/// 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.
|
||||
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.).
|
||||
///
|
||||
@ -116,17 +107,17 @@ impl Scene {
|
||||
Event::Resize(dims) => {
|
||||
self.camera.set_aspect_ratio(dims.x as f32 / dims.y as f32);
|
||||
true
|
||||
},
|
||||
}
|
||||
// Panning the cursor makes the camera rotate
|
||||
Event::CursorPan(delta) => {
|
||||
self.camera.rotate_by(Vec3::from(delta) * CURSOR_PAN_SCALE);
|
||||
true
|
||||
},
|
||||
}
|
||||
// Zoom the camera when a zoom event occurs
|
||||
Event::Zoom(delta) => {
|
||||
self.camera.zoom_by(-delta);
|
||||
true
|
||||
},
|
||||
}
|
||||
// All other events are unhandled
|
||||
_ => false,
|
||||
}
|
||||
@ -137,13 +128,14 @@ impl Scene {
|
||||
// Get player position
|
||||
let player_pos = client
|
||||
.player()
|
||||
.and_then(|ent| client
|
||||
.state()
|
||||
.ecs_world()
|
||||
.read_storage::<comp::phys::Pos>()
|
||||
.get(ent)
|
||||
.map(|pos| pos.0)
|
||||
)
|
||||
.and_then(|ent| {
|
||||
client
|
||||
.state()
|
||||
.ecs_world()
|
||||
.read_storage::<comp::phys::Pos>()
|
||||
.get(ent)
|
||||
.map(|pos| pos.0)
|
||||
})
|
||||
.unwrap_or(Vec3::zero());
|
||||
|
||||
// Alter camera position to match player
|
||||
@ -153,41 +145,40 @@ impl Scene {
|
||||
let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents();
|
||||
|
||||
// Update global constants
|
||||
renderer.update_consts(&mut self.globals, &[Globals::new(
|
||||
view_mat,
|
||||
proj_mat,
|
||||
cam_pos,
|
||||
self.camera.get_focus_pos(),
|
||||
10.0,
|
||||
client.state().get_time_of_day(),
|
||||
client.state().get_time(),
|
||||
)])
|
||||
renderer
|
||||
.update_consts(
|
||||
&mut self.globals,
|
||||
&[Globals::new(
|
||||
view_mat,
|
||||
proj_mat,
|
||||
cam_pos,
|
||||
self.camera.get_focus_pos(),
|
||||
10.0,
|
||||
client.state().get_time_of_day(),
|
||||
client.state().get_time(),
|
||||
)],
|
||||
)
|
||||
.expect("Failed to update global constants");
|
||||
|
||||
// Maintain the terrain
|
||||
self.terrain.maintain(renderer, client);
|
||||
|
||||
// TODO: Don't do this here
|
||||
RunAnimation::update_skeleton(
|
||||
&mut self.test_figure.skeleton,
|
||||
client.state().get_time(),
|
||||
);
|
||||
RunAnimation::update_skeleton(&mut self.test_figure.skeleton, client.state().get_time());
|
||||
|
||||
// Calculate player model matrix
|
||||
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();
|
||||
}
|
||||
|
||||
/// Render the scene using the provided `Renderer`
|
||||
pub fn render_to(&self, renderer: &mut Renderer) {
|
||||
// Render the skybox first (it appears over everything else so must be rendered first)
|
||||
renderer.render_skybox(
|
||||
&self.skybox.model,
|
||||
&self.globals,
|
||||
&self.skybox.locals,
|
||||
);
|
||||
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
|
||||
|
||||
// Render terrain
|
||||
self.terrain.render(renderer, &self.globals);
|
||||
|
Loading…
Reference in New Issue
Block a user