Add frustum culling to statues example again
@@ -49,8 +49,15 @@ fn main() {
"examples/assets/pfboy.png",
],
move |loaded| {
+ let (statue_cpu_meshes, statue_cpu_materials) =
+ loaded.obj("examples/assets/COLOMBE.obj").unwrap();
+ let statue_material = PhongMaterial::new(&context, &statue_cpu_materials[0]).unwrap();
+ let mut statue =
+ PhongMesh::new(&context, &statue_cpu_meshes[0], &statue_material).unwrap();
+ statue.cull = CullType::Back;
+
+ let mut statues = Vec::new();
let scale = Mat4::from_scale(10.0);
- let mut statue_transforms = Vec::new();
for i in 0..8 {
let angle = i as f32 * 2.0 * std::f32::consts::PI / 8.0;
let rotation = Mat4::from_angle_y(radians(0.8 * std::f32::consts::PI - angle));
@@ -60,22 +67,10 @@ fn main() {
(1.2 * std::f32::consts::PI - angle).cos() * 21.0 - 33.0,
angle.sin() * dist,
));
- let transform = translation * scale * rotation;
- statue_transforms.push(transform);
+ statue.transformation = translation * scale * rotation;
+ statues.push(statue.clone());
}
- let (statue_cpu_meshes, statue_cpu_materials) =
- loaded.obj("examples/assets/COLOMBE.obj").unwrap();
- let statue_material = PhongMaterial::new(&context, &statue_cpu_materials[0]).unwrap();
- let mut statue = PhongInstancedMesh::new(
- &context,
- &statue_transforms,
- &statue_cpu_meshes[0],
- &statue_material,
- )
- .unwrap();
- statue.cull = CullType::Back;
-
let (fountain_cpu_meshes, fountain_cpu_materials) =
loaded.obj("examples/assets/pfboy.obj").unwrap();
let fountain_material =
@@ -152,6 +147,8 @@ fn main() {
&context,
ClearState::color_and_depth(0.8, 0.8, 0.7, 1.0, 1.0),
|| {
+ for statue in statues.iter() {
+ if statue.in_frustum(&primary_camera) {
statue.render_with_lighting(
RenderStates::default(),
frame_input.viewport,
@@ -165,6 +162,8 @@ fn main() {
&[],
&[],
)?;
+ }
+ }
fountain.render_with_lighting(
RenderStates::default(),
