Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pure refactor] Remove unused MeshSourceData #2036

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 5 additions & 15 deletions crates/re_viewer/src/misc/caches/mesh_cache.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::sync::Arc;

use re_log_types::{MeshFormat, MeshId};
use re_log_types::{Mesh3D, MeshId};
use re_renderer::RenderContext;

use crate::{mesh_loader::LoadedMesh, ui::view_spatial::MeshSourceData};
use crate::mesh_loader::LoadedMesh;

// ----------------------------------------------------------------------------

Expand All @@ -14,29 +14,19 @@ impl MeshCache {
pub fn load(
&mut self,
name: &str,
mesh_data: &MeshSourceData,
mesh: &Mesh3D,
render_ctx: &mut RenderContext,
) -> Option<Arc<LoadedMesh>> {
crate::profile_function!();

let mesh_id = mesh_data.mesh_id();
let mesh_id = mesh.mesh_id();

self.0
.entry(mesh_id)
.or_insert_with(|| {
re_log::debug!("Loading CPU mesh {name:?}…");

let result = match mesh_data {
MeshSourceData::Mesh3D(mesh3d) => {
LoadedMesh::load(name.to_owned(), mesh3d, render_ctx)
}
MeshSourceData::StaticGlb(_mesh_id, glb_bytes) => LoadedMesh::load_raw(
name.to_owned(),
MeshFormat::Glb,
glb_bytes,
render_ctx,
),
};
let result = LoadedMesh::load(name.to_owned(), mesh, render_ctx);

match result {
Ok(cpu_mesh) => Some(Arc::new(cpu_mesh)),
Expand Down
4 changes: 2 additions & 2 deletions crates/re_viewer/src/misc/caches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ use re_log_types::component_types;
/// Does memoization of different things for the immediate mode UI.
#[derive(Default)]
pub struct Caches {
/// For displaying images efficiently in immediate mode.
/// Cached decoded tensors.
pub decode: tensor_decode_cache::DecodeCache,

/// For displaying meshes efficiently in immediate mode.
/// Cached loaded meshes (from file or converted from user data).
pub mesh: mesh_cache::MeshCache,

tensor_stats: nohash_hasher::IntMap<component_types::TensorId, TensorStats>,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_viewer/src/ui/view_spatial/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod ui_2d;
mod ui_3d;
pub mod ui_renderer_bridge;

pub use self::scene::{Image, MeshSource, MeshSourceData, SceneSpatial, UiLabel, UiLabelTarget};
pub use self::scene::{Image, MeshSource, SceneSpatial, UiLabel, UiLabelTarget};
pub use self::space_camera_3d::SpaceCamera3D;
pub use ui::{SpatialNavigationMode, ViewSpatialState};
pub use ui_2d::view_2d;
Expand Down
23 changes: 1 addition & 22 deletions crates/re_viewer/src/ui/view_spatial/scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use ahash::HashMap;
use re_data_store::{EntityPath, InstancePathHash};
use re_log_types::{
component_types::{ClassId, InstanceKey, KeypointId},
DecodedTensor, MeshId,
DecodedTensor,
};
use re_renderer::{renderer::TexturedRect, Color32, OutlineMaskPreference, Size};

Expand All @@ -27,27 +27,6 @@ pub use self::picking::{PickingContext, PickingHitType, PickingRayHit, PickingRe
pub use self::primitives::SceneSpatialPrimitives;
use scene_part::ScenePart;

// ----------------------------------------------------------------------------

pub enum MeshSourceData {
Mesh3D(re_log_types::Mesh3D),

/// Static meshes that are embedded in the player
///
/// Not used as of writing but may come back.
#[allow(dead_code)]
StaticGlb(MeshId, &'static [u8]),
}

impl MeshSourceData {
pub fn mesh_id(&self) -> MeshId {
match self {
MeshSourceData::Mesh3D(mesh) => mesh.mesh_id(),
MeshSourceData::StaticGlb(id, _) => *id,
}
}
}

/// TODO(andreas): Scene should only care about converted rendering primitive.
pub struct MeshSource {
pub picking_instance_hash: InstancePathHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
misc::{SpaceViewHighlights, TransformCache, ViewerContext},
ui::{
scene::SceneQuery,
view_spatial::{MeshSource, MeshSourceData, SceneSpatial},
view_spatial::{MeshSource, SceneSpatial},
DefaultColor,
},
};
Expand Down Expand Up @@ -49,11 +49,7 @@ impl MeshPart {
if let Some(mesh) = ctx
.cache
.mesh
.load(
&ent_path.to_string(),
&MeshSourceData::Mesh3D(mesh),
ctx.render_ctx,
)
.load(&ent_path.to_string(), &mesh, ctx.render_ctx)
.map(|cpu_mesh| MeshSource {
picking_instance_hash,
world_from_mesh: world_from_obj_affine,
Expand Down