Skip to content

Commit

Permalink
Post-rebase fallout fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Feb 22, 2018
1 parent 65f339c commit d5e0232
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 98 deletions.
21 changes: 12 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,27 @@ name = "sprite"
name = "tutorial"

[[example]]
name = "gltf-pbr-shader"
name = "group"

[[example]]
name = "gltf-node-animation"
name = "anim"

[[example]]
name = "gltf-vertex-skinning"
name = "aviator"
path = "examples/aviator/main.rs"

[[example]]
name = "gltf-morph-targets"
name = "gltf-pbr-shader"
required-features = ["gltf-loader"]

[[example]]
name = "group"
name = "gltf-node-animation"
required-features = ["gltf-loader"]

[[example]]
name = "anim"
name = "gltf-vertex-skinning"
required-features = ["gltf-loader"]

[[example]]
name = "aviator"
path = "examples/aviator/main.rs"

name = "gltf-morph-targets"
required-features = ["gltf-loader"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ If you a looking for something simple to prototype 3D graphics with, you found i

![Aviator](examples/aviator/shot.png)
![CarObj](https://raw.githubusercontent.com/three-rs/example-data/5d821bc9647a8db26888f8dd286f318eaabd2a52/obj-car.png)
![glTF-skinning](https://user-images.githubusercontent.com/107301/36550245-d878073e-17c2-11e8-87ca-68299dfff775.png)

## Motivation and Goals

Expand Down
2 changes: 1 addition & 1 deletion examples/gltf-node-animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn main() {
.position([3.0, 3.0, 3.0])
.target([0.0, 1.0, 0.0])
.build();

while window.update() && !window.input.hit(three::KEY_ESCAPE) {
mixer.update(window.input.delta_time());
controls.update(&window.input);
Expand Down
6 changes: 3 additions & 3 deletions examples/gltf-vertex-skinning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ fn main() {
mixer.action(clip);
}

let camera = window.factory.perspective_camera(60.0, 0.1 .. 100.0);
let camera = window.factory.perspective_camera(45.0, 0.1 .. 100.0);
window.scene.add(&camera);

let mut controls = three::controls::Orbit::builder(&camera)
.position([0.0, -3.0, 3.0])
.target([0.0, 0.0, -1.0])
.target([0.0, 0.0, 1.0])
.build();

while window.update() && !window.input.hit(three::KEY_ESCAPE) {
mixer.update(window.input.delta_time());
controls.update(&window.input);
Expand Down
9 changes: 1 addition & 8 deletions src/factory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use hub::{Hub, HubPtr, LightData, SubLight, SubNode};
use light::{Ambient, Directional, Hemisphere, Point, ShadowMap};
use material::{self, Material};
use mesh::{DynamicMesh, Mesh};
use object::{Group, Object};
use object;
use render::{basic_pipe,
BackendFactory, BackendResources, BasicPipelineState, DisplacementContribution,
DynamicData, GpuData, Instance, InstanceCacheKey, PipelineCreationError, ShadowFormat, Source, Vertex,
Expand Down Expand Up @@ -130,13 +130,6 @@ impl AsRef<object::Base> for Gltf {
}
}

#[cfg(feature = "gltf-loader")]
impl AsMut<object::Base> for Gltf {
fn as_mut(&mut self) -> &mut object::Base {
self.root.as_mut()
}
}

#[cfg(feature = "gltf-loader")]
impl object::Object for Gltf {}

Expand Down
105 changes: 31 additions & 74 deletions src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use light::{ShadowMap, ShadowProjection};
use material::Material;
use mesh::DynamicMesh;
use node::{NodeInternal, NodePointer, TransformInternal};
use object::Base;
use render::{BackendResources, GpuData};
use scene::Scene;
use skeleton::{Bone, Skeleton};
use text::{Operation as TextOperation, TextData};

Expand Down Expand Up @@ -228,46 +228,6 @@ impl Hub {
cur_ptr = node.next_sibling.clone(); //TODO: avoid clone
}
}
Operation::SetSkeleton(skeleton) => {
if let SubNode::Visual(_, _, ref mut s) = self.nodes[&ptr].sub_node {
*s = Some(skeleton);
}
},
Operation::SetShadow(map, proj) => {
if let SubNode::Light(ref mut data) = self.nodes[&ptr].sub_node {
data.shadow = Some((map, proj));
}
},
Operation::SetWeights(weights) => {
fn set_weights(
gpu_data: &mut GpuData,
weights: &[f32],
) {
use std::iter::repeat;
for (out, input) in gpu_data.displacement_contributions
.iter_mut()
.zip(weights.iter().chain(repeat(&0.0)))
{
out.weight = *input;
}
}

let mut x = match self.nodes[&ptr].sub_node {
SubNode::Visual(_, ref mut gpu_data, _) => {
set_weights(gpu_data, &weights);
continue;
}
SubNode::Group { ref first_child } => first_child.clone(),
_ => continue,
};

while let Some(ptr) = x {
if let SubNode::Visual(_, ref mut gpu_data, _) = self.nodes[&ptr].sub_node {
set_weights(gpu_data, &weights);
}
x = self.nodes[&ptr].next_sibling.clone();
}
}
Operation::SetText(operation) => {
match self.nodes[&ptr].sub_node {
SubNode::UiText(ref mut data) => {
Expand Down Expand Up @@ -308,8 +268,36 @@ impl Hub {
_ => unreachable!()
}
}
Operation::SetTargets(targets) => unimplemented!(),
Operation::SetWeights(weights) => unimplemented!(),
Operation::SetWeights(weights) => {
fn set_weights(
gpu_data: &mut GpuData,
weights: &[f32],
) {
use std::iter::repeat;
for (out, input) in gpu_data.displacement_contributions
.iter_mut()
.zip(weights.iter().chain(repeat(&0.0)))
{
out.weight = *input;
}
}

let mut x = match self.nodes[&ptr].sub_node {
SubNode::Visual(_, ref mut gpu_data, _) => {
set_weights(gpu_data, &weights);
continue;
}
SubNode::Group { ref first_child } => first_child.clone(),
_ => continue,
};

while let Some(ptr) = x {
if let SubNode::Visual(_, ref mut gpu_data, _) = self.nodes[&ptr].sub_node {
set_weights(gpu_data, &weights);
}
x = self.nodes[&ptr].next_sibling.clone();
}
}
}
}

Expand Down Expand Up @@ -350,37 +338,6 @@ impl Hub {
}
}

pub(crate) fn update_graph(
&mut self,
scene: &Scene,
) {
struct Item {
ptr: NodePointer,
xform: TransformInternal,
}

let mut stack = vec![];
if let Some(child_ptr) = scene.first_child.clone() {
stack.push(Item {
ptr: child_ptr,
xform: TransformInternal::one(),
});
}

while let Some(item) = stack.pop() {
let mut x = self.nodes[&item.ptr].next_sibling.clone();
while let Some(child_ptr) = x {
let local_xform = self.nodes[&child_ptr].transform.clone();
let global_xform = item.xform.concat(&local_xform);
x = self.nodes[&child_ptr].next_sibling.clone();
stack.push(Item {
ptr: child_ptr,
xform: global_xform,
});
}
}
}

pub(crate) fn update_mesh(
&mut self,
mesh: &DynamicMesh,
Expand Down
5 changes: 2 additions & 3 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod pso_data;

use color;

use std::{io, mem, str};
use std::{io, str};
use std::collections::HashMap;
use std::path::PathBuf;

Expand Down Expand Up @@ -624,7 +624,6 @@ impl Renderer {
out_color,
out_depth,
pso,
default_joint_buffer,
default_joint_buffer_view,
default_displacement_buffer_view,
map_default: Texture::new(srv_white, sampler, [1, 1]),
Expand Down Expand Up @@ -1193,7 +1192,7 @@ impl Renderer {
displacement_contributions
};
encoder.update_buffer(&displacement_contributions_buf, data, 0).unwrap();
params.pbr_flags |= pso_data::PbrFlags::DISPLACEMENT_BUFFER.bits();
params.pbr_flags |= PbrFlags::DISPLACEMENT_BUFFER.bits();
}
encoder.update_constant_buffer(&pbr_buf, &params);
let map_params = maps.into_params(map_default);
Expand Down

0 comments on commit d5e0232

Please sign in to comment.