Update picking example
@@ -25,29 +25,40 @@ fn main() {
.unwrap();
let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0);
- let pick_mesh_material = Material {
+ let mut sphere = CPUMesh::sphere();
+ sphere.transform(&Mat4::from_scale(0.05));
+ let mut pick_mesh = Glue {
+ geometry: Model::new(&context, &sphere).unwrap(),
+ material: PhysicalMaterial {
albedo: Color::RED,
..Default::default()
+ },
};
- let mut sphere = CPUMesh::sphere();
- sphere.transform(&Mat4::from_scale(0.05));
- let mut pick_mesh = Model::new(&context, &sphere).unwrap();
Loader::load(
&["examples/assets/suzanne.obj", "examples/assets/suzanne.mtl"],
move |mut loaded| {
let (meshes, materials) = loaded.obj("examples/assets/suzanne.obj").unwrap();
- let monkey_material = Material::new(&context, &materials[0]).unwrap();
- let mut monkey = Model::new(&context, &meshes[0]).unwrap();
- monkey.cull = Cull::Back;
+ let mut monkey = Glue {
+ geometry: Model::new(&context, &meshes[0]).unwrap(),
+ material: PhysicalMaterial::new(&context, &materials[0]).unwrap(),
+ };
+ monkey.material.opaque_render_states.cull = Cull::Back;
- let ambient_light = AmbientLight {
+ let lights = Lights {
+ ambient: Some(AmbientLight {
intensity: 0.4,
color: Color::WHITE,
+ }),
+ directional: vec![DirectionalLight::new(
+ &context,
+ 2.0,
+ Color::WHITE,
+ &vec3(-1.0, -1.0, -1.0),
+ )
+ .unwrap()],
+ ..Default::default()
};
- let directional_light =
- DirectionalLight::new(&context, 2.0, Color::WHITE, &vec3(-1.0, -1.0, -1.0))
- .unwrap();
// main loop
window
@@ -66,9 +77,11 @@ fn main() {
(frame_input.device_pixel_ratio * position.1) as f32,
);
if let Some(pick) =
- camera.pick(pixel, 100.0, &[&monkey]).unwrap()
+ pick(&context, &camera, pixel, &[&monkey]).unwrap()
{
- pick_mesh.set_transformation(Mat4::from_translation(pick));
+ pick_mesh
+ .geometry
+ .set_transformation(Mat4::from_translation(pick));
change = true;
}
}
@@ -86,20 +99,7 @@ fn main() {
Screen::write(
&context,
ClearState::color_and_depth(1.0, 1.0, 1.0, 1.0, 1.0),
- || {
- pipeline.light_pass(
- &camera,
- &[
- (&monkey, &monkey_material),
- (&pick_mesh, &pick_mesh_material),
- ],
- Some(&ambient_light),
- &[&directional_light],
- &[],
- &[],
- )?;
- Ok(())
- },
+ || pipeline.render_pass(&camera, &[&monkey, &pick_mesh], &lights),
)
.unwrap();
}
