Use Loading in wireframe example
@@ -11,7 +11,6 @@ fn main() {
.unwrap();
let context = window.gl().unwrap();
- let pipeline = ForwardPipeline::new(&context).unwrap();
let target = vec3(0.0, 2.0, 0.0);
let scene_radius = 6.0;
let mut camera = Camera::new_perspective(
@@ -27,22 +26,20 @@ fn main() {
.unwrap();
let mut control = OrbitControl::new(*camera.target(), 0.1 * scene_radius, 100.0 * scene_radius);
- Loader::load(
- &[
- "./examples/assets/suzanne.obj",
- "./examples/assets/suzanne.mtl",
- ],
- move |mut loaded| {
- let (mut meshes, materials) = loaded.obj("./examples/assets/suzanne.obj").unwrap();
+ let scene = Loading::new(
+ &context,
+ &["examples/assets/suzanne.obj", "examples/assets/suzanne.mtl"],
+ move |context, mut loaded| {
+ let (mut meshes, materials) = loaded.obj("suzanne.obj").unwrap();
let mut cpu_mesh = meshes.remove(0);
cpu_mesh.transform(&Mat4::from_translation(vec3(0.0, 2.0, 0.0)));
- let model = Model::new_with_material(
+ let mut model = Model::new_with_material(
&context,
&cpu_mesh,
PhysicalMaterial::new(&context, &materials[0]).unwrap(),
)
.unwrap();
-
+ model.material.opaque_render_states.cull = Cull::Back;
let wireframe_material = PhysicalMaterial {
name: "wireframe".to_string(),
albedo: Color::new_opaque(220, 50, 50),
@@ -73,6 +70,9 @@ fn main() {
wireframe_material,
)
.unwrap();
+ Ok((model, vertices, edges))
+ },
+ );
let lights = Lights {
ambient: Some(AmbientLight {
@@ -80,10 +80,8 @@ fn main() {
..Default::default()
}),
directional: vec![
- DirectionalLight::new(&context, 2.0, Color::WHITE, &vec3(-1.0, -1.0, -1.0))
- .unwrap(),
- DirectionalLight::new(&context, 2.0, Color::WHITE, &vec3(1.0, 1.0, 1.0))
- .unwrap(),
+ DirectionalLight::new(&context, 2.0, Color::WHITE, &vec3(-1.0, -1.0, -1.0)).unwrap(),
+ DirectionalLight::new(&context, 2.0, Color::WHITE, &vec3(1.0, 1.0, 1.0)).unwrap(),
],
..Default::default()
};
@@ -102,11 +100,14 @@ fn main() {
&context,
ClearState::color_and_depth(1.0, 1.0, 1.0, 1.0, 1.0),
|| {
- pipeline.render_pass(
+ if let Some(ref scene) = *scene.borrow() {
+ let (model, vertices, edges) = scene.as_ref().unwrap();
+ render_pass(
&camera,
&[&model as &dyn Object, &vertices, &edges],
&lights,
)?;
+ }
Ok(())
},
)
@@ -129,8 +130,6 @@ fn main() {
}
})
.unwrap();
- },
- );
}
fn vertex_transformations(cpu_mesh: &CPUMesh) -> Vec<ModelInstance> {
