2019-05-12 13:02:47 +00:00
|
|
|
use crate::{
|
2019-05-12 19:57:39 +00:00
|
|
|
anim::{
|
|
|
|
character::{CharacterSkeleton, IdleAnimation},
|
2019-05-18 19:03:13 +00:00
|
|
|
fixture::FixtureSkeleton,
|
2019-05-12 19:57:39 +00:00
|
|
|
Animation, Skeleton,
|
|
|
|
},
|
2019-05-12 13:02:47 +00:00
|
|
|
render::{
|
2019-05-12 19:57:39 +00:00
|
|
|
create_pp_mesh, create_skybox_mesh, Consts, FigurePipeline, Globals, Model,
|
|
|
|
PostProcessLocals, PostProcessPipeline, Renderer, SkyboxLocals, SkyboxPipeline,
|
2019-05-12 13:02:47 +00:00
|
|
|
},
|
|
|
|
scene::{
|
|
|
|
camera::Camera,
|
|
|
|
figure::{FigureModelCache, FigureState},
|
|
|
|
},
|
|
|
|
};
|
2019-05-12 21:34:20 +00:00
|
|
|
use client::Client;
|
2019-06-16 17:45:01 +00:00
|
|
|
use common::{comp, state::DeltaTime};
|
2019-06-06 14:48:41 +00:00
|
|
|
use log::error;
|
2019-05-12 21:34:20 +00:00
|
|
|
use vek::*;
|
2019-05-12 13:02:47 +00:00
|
|
|
|
|
|
|
struct Skybox {
|
|
|
|
model: Model<SkyboxPipeline>,
|
|
|
|
locals: Consts<SkyboxLocals>,
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PostProcess {
|
|
|
|
model: Model<PostProcessPipeline>,
|
|
|
|
locals: Consts<PostProcessLocals>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Scene {
|
|
|
|
globals: Consts<Globals>,
|
|
|
|
camera: Camera,
|
|
|
|
|
|
|
|
skybox: Skybox,
|
|
|
|
postprocess: PostProcess,
|
|
|
|
backdrop_model: Model<FigurePipeline>,
|
2019-05-18 19:03:13 +00:00
|
|
|
backdrop_state: FigureState<FixtureSkeleton>,
|
2019-05-12 13:02:47 +00:00
|
|
|
|
|
|
|
figure_model_cache: FigureModelCache,
|
|
|
|
figure_state: FigureState<CharacterSkeleton>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Scene {
|
|
|
|
pub fn new(renderer: &mut Renderer) -> Self {
|
|
|
|
let resolution = renderer.get_resolution().map(|e| e as f32);
|
|
|
|
|
|
|
|
Self {
|
|
|
|
globals: renderer.create_consts(&[Globals::default()]).unwrap(),
|
|
|
|
camera: Camera::new(resolution.x / resolution.y),
|
|
|
|
|
|
|
|
skybox: Skybox {
|
|
|
|
model: renderer.create_model(&create_skybox_mesh()).unwrap(),
|
|
|
|
locals: renderer.create_consts(&[SkyboxLocals::default()]).unwrap(),
|
|
|
|
},
|
|
|
|
postprocess: PostProcess {
|
|
|
|
model: renderer.create_model(&create_pp_mesh()).unwrap(),
|
|
|
|
locals: renderer
|
|
|
|
.create_consts(&[PostProcessLocals::default()])
|
|
|
|
.unwrap(),
|
|
|
|
},
|
|
|
|
figure_model_cache: FigureModelCache::new(),
|
|
|
|
figure_state: FigureState::new(renderer, CharacterSkeleton::new()),
|
|
|
|
|
2019-05-12 19:57:39 +00:00
|
|
|
backdrop_model: renderer
|
2019-05-18 19:03:13 +00:00
|
|
|
.create_model(&FigureModelCache::load_mesh(
|
|
|
|
"fixture/selection_bg.vox",
|
|
|
|
Vec3::new(-55.0, -50.0, -1.0),
|
|
|
|
))
|
2019-05-12 19:57:39 +00:00
|
|
|
.unwrap(),
|
2019-05-18 19:03:13 +00:00
|
|
|
backdrop_state: FigureState::new(renderer, FixtureSkeleton::new()),
|
2019-05-12 13:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 06:43:07 +00:00
|
|
|
pub fn globals(&self) -> &Consts<Globals> {
|
|
|
|
&self.globals
|
|
|
|
}
|
|
|
|
|
2019-05-12 13:02:47 +00:00
|
|
|
pub fn maintain(&mut self, renderer: &mut Renderer, client: &Client) {
|
2019-05-18 19:03:13 +00:00
|
|
|
self.camera.set_focus_pos(Vec3::unit_z() * 2.0);
|
2019-05-12 13:02:47 +00:00
|
|
|
self.camera.update(client.state().get_time());
|
2019-05-18 19:03:13 +00:00
|
|
|
self.camera.set_distance(4.2);
|
2019-05-12 19:57:39 +00:00
|
|
|
self.camera
|
2019-05-18 19:03:13 +00:00
|
|
|
.set_orientation(Vec3::new(client.state().get_time() as f32 * 0.0, 0.0, 0.0));
|
2019-05-12 13:02:47 +00:00
|
|
|
|
|
|
|
let (view_mat, proj_mat, cam_pos) = self.camera.compute_dependents(client);
|
|
|
|
|
2019-06-06 14:48:41 +00:00
|
|
|
if let Err(err) = renderer.update_consts(
|
2019-05-12 13:02:47 +00:00
|
|
|
&mut self.globals,
|
|
|
|
&[Globals::new(
|
|
|
|
view_mat,
|
|
|
|
proj_mat,
|
|
|
|
cam_pos,
|
|
|
|
self.camera.get_focus_pos(),
|
|
|
|
100.0,
|
|
|
|
client.state().get_time_of_day(),
|
|
|
|
client.state().get_time(),
|
|
|
|
renderer.get_resolution(),
|
|
|
|
)],
|
2019-06-06 14:48:41 +00:00
|
|
|
) {
|
|
|
|
error!("Renderer failed to update: {:?}", err);
|
|
|
|
}
|
2019-05-12 13:02:47 +00:00
|
|
|
|
|
|
|
self.figure_model_cache.clean(client.get_tick());
|
|
|
|
|
|
|
|
let tgt_skeleton = IdleAnimation::update_skeleton(
|
|
|
|
self.figure_state.skeleton_mut(),
|
|
|
|
client.state().get_time(),
|
|
|
|
client.state().get_time(),
|
|
|
|
);
|
2019-06-16 17:45:01 +00:00
|
|
|
self.figure_state.skeleton_mut().interpolate(
|
|
|
|
&tgt_skeleton,
|
|
|
|
client.state().ecs().read_resource::<DeltaTime>().0,
|
|
|
|
);
|
2019-05-12 13:02:47 +00:00
|
|
|
|
2019-05-16 19:23:45 +00:00
|
|
|
self.figure_state.update(
|
|
|
|
renderer,
|
|
|
|
Vec3::zero(),
|
|
|
|
-Vec3::unit_y(),
|
|
|
|
Rgba::broadcast(1.0),
|
|
|
|
);
|
2019-05-12 13:02:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-16 17:45:01 +00:00
|
|
|
pub fn render(&mut self, renderer: &mut Renderer, client: &Client, body: comp::HumanoidBody) {
|
2019-05-12 13:02:47 +00:00
|
|
|
renderer.render_skybox(&self.skybox.model, &self.globals, &self.skybox.locals);
|
|
|
|
|
|
|
|
let model = self.figure_model_cache.get_or_create_model(
|
|
|
|
renderer,
|
2019-05-18 19:03:13 +00:00
|
|
|
comp::Body::Humanoid(body),
|
2019-05-12 13:02:47 +00:00
|
|
|
client.get_tick(),
|
|
|
|
);
|
2019-05-18 19:03:13 +00:00
|
|
|
|
2019-05-12 13:02:47 +00:00
|
|
|
renderer.render_figure(
|
|
|
|
model,
|
|
|
|
&self.globals,
|
|
|
|
self.figure_state.locals(),
|
|
|
|
self.figure_state.bone_consts(),
|
|
|
|
);
|
|
|
|
|
|
|
|
renderer.render_figure(
|
|
|
|
&self.backdrop_model,
|
|
|
|
&self.globals,
|
|
|
|
self.backdrop_state.locals(),
|
|
|
|
self.backdrop_state.bone_consts(),
|
|
|
|
);
|
|
|
|
|
|
|
|
renderer.render_post_process(
|
|
|
|
&self.postprocess.model,
|
|
|
|
&self.globals,
|
|
|
|
&self.postprocess.locals,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|