Skip to content

Commit

Permalink
use anyhow for load_rerun_mesh re_renderer example method
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Oct 22, 2024
1 parent c14fb00 commit 448a21d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
5 changes: 1 addition & 4 deletions crates/viewer/re_renderer/src/importer/stl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ use itertools::Itertools;
use smallvec::smallvec;
use tinystl::StlData;

use crate::{
mesh::{self},
CpuModel, RenderContext,
};
use crate::{mesh, CpuModel, RenderContext};

#[derive(thiserror::Error, Debug)]
pub enum StlImportError {
Expand Down
18 changes: 10 additions & 8 deletions crates/viewer/re_renderer_examples/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,18 @@ impl<E: Example + 'static> Application<E> {
}

#[allow(dead_code)]
pub fn load_rerun_mesh(re_ctx: &RenderContext) -> Vec<re_renderer::renderer::GpuMeshInstance> {
pub fn load_rerun_mesh(
re_ctx: &RenderContext,
) -> anyhow::Result<Vec<re_renderer::renderer::GpuMeshInstance>> {
let reader = std::io::Cursor::new(include_bytes!("../../../tests/assets/rerun.obj.zip"));
let mut zip = zip::ZipArchive::new(reader).unwrap();
let mut zipped_obj = zip.by_name("rerun.obj").unwrap();
let mut zip = zip::ZipArchive::new(reader)?;
let mut zipped_obj = zip.by_name("rerun.obj")?;
let mut obj_data = Vec::new();
std::io::Read::read_to_end(&mut zipped_obj, &mut obj_data).unwrap();
re_renderer::importer::obj::load_obj_from_buffer(&obj_data, re_ctx)
.unwrap()
.into_gpu_meshes(re_ctx)
.unwrap()
std::io::Read::read_to_end(&mut zipped_obj, &mut obj_data)?;
Ok(
re_renderer::importer::obj::load_obj_from_buffer(&obj_data, re_ctx)?
.into_gpu_meshes(re_ctx)?,
)
}

struct WrapApp<E: Example + 'static> {
Expand Down
5 changes: 3 additions & 2 deletions crates/viewer/re_renderer_examples/multiview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use re_math::IsoTransform;

use re_renderer::{
renderer::{
GenericSkyboxDrawData, LineDrawData, LineStripFlags, MeshDrawData, GpuMeshInstance,
GenericSkyboxDrawData, GpuMeshInstance, LineDrawData, LineStripFlags, MeshDrawData,
TestTriangleDrawData,
},
view_builder::{OrthographicCameraMode, Projection, TargetConfiguration, ViewBuilder},
Expand Down Expand Up @@ -276,7 +276,8 @@ impl Example for Multiview {
.map(|_| random_color(&mut rnd))
.collect_vec();

let model_mesh_instances = crate::framework::load_rerun_mesh(re_ctx);
let model_mesh_instances =
crate::framework::load_rerun_mesh(re_ctx).expect("Failed to load rerun mesh");

let mesh_instance_positions_and_colors = lorenz_points(10.0)
.iter()
Expand Down
3 changes: 2 additions & 1 deletion crates/viewer/re_renderer_examples/outlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ impl framework::Example for Outlines {
Self {
is_paused: false,
seconds_since_startup: 0.0,
model_mesh_instances: crate::framework::load_rerun_mesh(re_ctx),
model_mesh_instances: crate::framework::load_rerun_mesh(re_ctx)
.expect("Failed to load rerun mesh"),
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/viewer/re_renderer_examples/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ impl framework::Example for Picking {
})
.collect_vec();

let model_mesh_instances = crate::framework::load_rerun_mesh(re_ctx);
let model_mesh_instances =
crate::framework::load_rerun_mesh(re_ctx).expect("Failed to load rerun mesh");

Self {
point_sets,
Expand Down

0 comments on commit 448a21d

Please sign in to comment.