Improved normal test
@@ -13,24 +13,34 @@ fn main() {
let context = window.gl().unwrap();
// Model source: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/
- let model = Loading::new(
+ let models = Loading::new(
&context,
- &["examples/assets/gltf/NormalTangentMirrorTest.glb"],
+ &[
+ "examples/assets/gltf/NormalTangentTest.glb",
+ "examples/assets/gltf/NormalTangentMirrorTest.glb",
+ ],
move |context, mut loaded| {
- let (mut cpu_meshes, cpu_materials) =
- loaded.gltf("NormalTangentMirrorTest.glb").unwrap();
- let mut material = PhysicalMaterial::new(&context, &cpu_materials[0]).unwrap();
- let mut model =
+ let (mut cpu_meshes, cpu_materials) = loaded.gltf("NormalTangentTest.glb").unwrap();
+ let material = PhysicalMaterial::new(&context, &cpu_materials[0]).unwrap();
+ cpu_meshes[0].compute_tangents();
+ let mut model1 =
Model::new_with_material(&context, &cpu_meshes[0], material.clone()).unwrap();
- Ok(model)
+ model1.set_transformation(Mat4::from_translation(vec3(1.4, 0.0, 0.0)));
+
+ let (cpu_meshes, cpu_materials) = loaded.gltf("NormalTangentMirrorTest.glb").unwrap();
+ let material = PhysicalMaterial::new(&context, &cpu_materials[0]).unwrap();
+ let mut model2 =
+ Model::new_with_material(&context, &cpu_meshes[0], material.clone()).unwrap();
+ model2.set_transformation(Mat4::from_translation(vec3(-1.4, 0.0, 0.0)));
+ Ok((model1, model2))
},
);
let mut camera = Camera::new_perspective(
&context,
window.viewport().unwrap(),
- vec3(3.0, 1.0, 2.5),
- vec3(0.0, 0.0, -0.5),
+ vec3(0.0, 0.0, 5.0),
+ vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
degrees(45.0),
0.1,
@@ -38,7 +48,7 @@ fn main() {
)
.unwrap();
let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0);
- let mut lights = Lights {
+ let lights = Lights {
ambient: Some(AmbientLight {
color: Color::WHITE,
intensity: 0.4,
@@ -70,8 +80,13 @@ fn main() {
&context,
ClearState::color_and_depth(0.5, 0.5, 0.5, 1.0, 1.0),
|| {
- if let Some(Ok(ref model)) = *model.borrow() {
- model.render(&camera, &lights)?;
+ if let Some(Ok((
+ ref model_with_computed_tangents,
+ ref model_with_loaded_tangents,
+ ))) = *models.borrow()
+ {
+ model_with_computed_tangents.render(&camera, &lights)?;
+ model_with_loaded_tangents.render(&camera, &lights)?;
}
Ok(())
},
