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

glTF skinning and morphing animations #184

Merged
merged 20 commits into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod basic {
/// Renders triangle meshes with a solid color or texture.
#[derive(Clone, Hash, Debug, PartialEq, Eq)]
pub struct Basic {
/// Solid color applied in the absense of `map`.
/// Solid color applied in the absence of `map`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL.

///
/// Default: `WHITE`.
pub color: Color,
Expand Down Expand Up @@ -284,49 +284,49 @@ pub enum Material {
}

impl From<Basic> for Material {
fn from(params: Basic) -> Material {
fn from(params: Basic) -> Self {
Material::Basic(params)
}
}

impl From<basic::Custom> for Material {
fn from(params: basic::Custom) -> Material {
fn from(params: basic::Custom) -> Self {
Material::CustomBasic(params)
}
}

impl From<Lambert> for Material {
fn from(params: Lambert) -> Material {
fn from(params: Lambert) -> Self {
Material::Lambert(params)
}
}

impl From<Line> for Material {
fn from(params: Line) -> Material {
fn from(params: Line) -> Self {
Material::Line(params)
}
}

impl From<Phong> for Material {
fn from(params: Phong) -> Material {
fn from(params: Phong) -> Self {
Material::Phong(params)
}
}

impl From<Pbr> for Material {
fn from(params: Pbr) -> Material {
fn from(params: Pbr) -> Self {
Material::Pbr(params)
}
}

impl From<Sprite> for Material {
fn from(params: Sprite) -> Material {
fn from(params: Sprite) -> Self {
Material::Sprite(params)
}
}

impl From<Wireframe> for Material {
fn from(params: Wireframe) -> Material {
fn from(params: Wireframe) -> Self {
Material::Wireframe(params)
}
}
68 changes: 35 additions & 33 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,39 +335,39 @@ struct DebugQuad {
}

/// All pipeline state objects used by the `three` renderer.
pub struct PipelineStates {
pub struct PipelineStates<R: gfx::Resources> {
/// Corresponds to `Material::Basic`.
mesh_basic_fill: BasicPipelineState,
mesh_basic_fill: gfx::PipelineState<R, basic_pipe::Meta>,

/// Corresponds to `Material::Line`.
line_basic: BasicPipelineState,
line_basic: gfx::PipelineState<R, basic_pipe::Meta>,

/// Corresponds to `Material::Wireframe`.
mesh_basic_wireframe: BasicPipelineState,
mesh_basic_wireframe: gfx::PipelineState<R, basic_pipe::Meta>,

/// Corresponds to `Material::Gouraud`.
mesh_gouraud: BasicPipelineState,
mesh_gouraud: gfx::PipelineState<R, basic_pipe::Meta>,

/// Corresponds to `Material::Phong`.
mesh_phong: BasicPipelineState,
mesh_phong: gfx::PipelineState<R, basic_pipe::Meta>,

/// Corresponds to `Material::Sprite`.
sprite: BasicPipelineState,
sprite: gfx::PipelineState<R, basic_pipe::Meta>,

/// Used internally for shadow casting.
shadow: gfx::PipelineState<back::Resources, shadow_pipe::Meta>,
shadow: gfx::PipelineState<R, shadow_pipe::Meta>,

/// Used internally for rendering sprites.
quad: gfx::PipelineState<back::Resources, quad_pipe::Meta>,
quad: gfx::PipelineState<R, quad_pipe::Meta>,

/// Corresponds to `Material::Pbr`.
pbr: gfx::PipelineState<back::Resources, pbr_pipe::Meta>,
pbr: gfx::PipelineState<R, pbr_pipe::Meta>,

/// Used internally for rendering `Background::Skybox`.
skybox: gfx::PipelineState<back::Resources, quad_pipe::Meta>,
skybox: gfx::PipelineState<R, quad_pipe::Meta>,
}

impl PipelineStates {
impl PipelineStates<back::Resources> {
/// Creates the set of pipeline states needed by the `three` renderer.
pub fn new(
src: &source::Set,
Expand All @@ -376,10 +376,28 @@ impl PipelineStates {
Self::init(src, &mut factory.backend)
}

pub(crate) fn pso_by_material<'a>(
&'a self,
material: &'a Material,
) -> &'a BasicPipelineState {
match *material {
Material::Basic(_) => &self.mesh_basic_fill,
Material::CustomBasic(ref b) => &b.pipeline,
Material::Line(_) => &self.line_basic,
Material::Wireframe(_) => &self.mesh_basic_wireframe,
Material::Lambert(_) => &self.mesh_gouraud,
Material::Phong(_) => &self.mesh_phong,
Material::Sprite(_) => &self.sprite,
_ => unreachable!(),
}
}
}

impl<R: gfx::Resources> PipelineStates<R> {
/// Implementation of `PipelineStates::new`.
pub(crate) fn init(
pub(crate) fn init<F: gfx::Factory<R>>(
src: &source::Set,
backend: &mut back::Factory,
backend: &mut F,
) -> Result<Self, PipelineCreationError> {
let basic = backend.create_shader_set(&src.basic.vs, &src.basic.ps)?;
let gouraud = backend.create_shader_set(&src.gouraud.vs, &src.gouraud.ps)?;
Expand Down Expand Up @@ -481,22 +499,6 @@ impl PipelineStates {
skybox: pso_skybox,
})
}

pub(crate) fn pso_by_material<'a>(
&'a self,
material: &'a Material,
) -> &'a BasicPipelineState {
match *material {
Material::Basic(_) => &self.mesh_basic_fill,
Material::CustomBasic(ref b) => &b.pipeline,
Material::Line(_) => &self.line_basic,
Material::Wireframe(_) => &self.mesh_basic_wireframe,
Material::Lambert(_) => &self.mesh_gouraud,
Material::Phong(_) => &self.mesh_phong,
Material::Sprite(_) => &self.sprite,
_ => unreachable!(),
}
}
}

/// Handle for additional viewport to render some relevant debug information.
Expand All @@ -521,7 +523,7 @@ pub struct Renderer {
displacement_contributions_buf: gfx::handle::Buffer<back::Resources, DisplacementContribution>,
default_joint_buffer_view: gfx::handle::ShaderResourceView<back::Resources, [f32; 4]>,
default_displacement_buffer_view: gfx::handle::ShaderResourceView<back::Resources, [f32; 4]>,
pso: PipelineStates,
pso: PipelineStates<back::Resources>,
map_default: Texture<[f32; 4]>,
shadow_default: Texture<f32>,
debug_quads: froggy::Storage<DebugQuad>,
Expand Down Expand Up @@ -641,7 +643,7 @@ impl Renderer {
/// Reloads the shaders.
pub fn reload(
&mut self,
pipeline_states: PipelineStates,
pipeline_states: PipelineStates<back::Resources>,
) {
self.pso = pipeline_states;
}
Expand Down Expand Up @@ -1161,7 +1163,7 @@ impl Renderer {
displacement_contributions_buf: h::Buffer<back::Resources, DisplacementContribution>,
out_color: h::RenderTargetView<back::Resources, ColorFormat>,
out_depth: h::DepthStencilView<back::Resources, DepthFormat>,
pso: &PipelineStates,
pso: &PipelineStates<back::Resources>,
map_default: &Texture<[f32; 4]>,
instances: &[Instance],
vertex_buf: h::Buffer<back::Resources, Vertex>,
Expand Down