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

Sunset MeshProperties, introduce TriangleIndices and friends #6169

Merged
merged 5 commits into from
May 2, 2024
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
1 change: 0 additions & 1 deletion crates/re_data_ui/src/component_ui_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub fn create_component_ui_registry() -> ComponentUiRegistry {
add_to_registry::<re_types::components::Resolution>(&mut registry);
add_to_registry::<re_types::components::Rotation3D>(&mut registry);
add_to_registry::<re_types::components::Material>(&mut registry);
add_to_registry::<re_types::components::MeshProperties>(&mut registry);
add_to_registry::<re_types::components::TensorData>(&mut registry);
add_to_registry::<re_types::components::Transform3D>(&mut registry);
add_to_registry::<re_types::components::OutOfTreeTransform3D>(&mut registry);
Expand Down
89 changes: 53 additions & 36 deletions crates/re_data_ui/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use egui::Vec2;

use re_format::format_f32;
use re_types::components::{Color, LineStrip2D, LineStrip3D, MeshProperties, ViewCoordinates};
use re_types::components::{Color, LineStrip2D, LineStrip3D, ViewCoordinates};
use re_viewer_context::{UiVerbosity, ViewerContext};

use super::{table_for_verbosity, DataUi};
Expand Down Expand Up @@ -126,6 +126,58 @@ impl DataUi for re_types::datatypes::Vec3D {
}
}

impl DataUi for re_types::datatypes::Vec4D {
fn data_ui(
&self,
_ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_verbosity: UiVerbosity,
_query: &re_data_store::LatestAtQuery,
_db: &re_entity_db::EntityDb,
) {
ui.label(self.to_string());
}
}

impl DataUi for re_types::datatypes::UVec2D {
fn data_ui(
&self,
_ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_verbosity: UiVerbosity,
_query: &re_data_store::LatestAtQuery,
_db: &re_entity_db::EntityDb,
) {
ui.label(self.to_string());
}
}

impl DataUi for re_types::datatypes::UVec3D {
fn data_ui(
&self,
_ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_verbosity: UiVerbosity,
_query: &re_data_store::LatestAtQuery,
_db: &re_entity_db::EntityDb,
) {
ui.label(self.to_string());
}
}

impl DataUi for re_types::datatypes::UVec4D {
fn data_ui(
&self,
_ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
_verbosity: UiVerbosity,
_query: &re_data_store::LatestAtQuery,
_db: &re_entity_db::EntityDb,
) {
ui.label(self.to_string());
}
}

impl DataUi for LineStrip2D {
fn data_ui(
&self,
Expand Down Expand Up @@ -225,38 +277,3 @@ impl DataUi for LineStrip3D {
}
}
}

impl DataUi for MeshProperties {
fn data_ui(
&self,
_ctx: &ViewerContext<'_>,
ui: &mut egui::Ui,
verbosity: UiVerbosity,
_query: &re_data_store::LatestAtQuery,
_db: &re_entity_db::EntityDb,
) {
let show_optional_indices = |ui: &mut egui::Ui| {
if let Some(indices) = self.indices.as_ref() {
ui.label(format!(
"{} triangles",
re_format::format_uint(indices.len() / 3)
));
} else {
ui.weak("(empty)");
}
};

match verbosity {
UiVerbosity::Small | UiVerbosity::Reduced => {
show_optional_indices(ui);
}
UiVerbosity::Full | UiVerbosity::LimitHeight => {
egui::Grid::new("material").num_columns(2).show(ui, |ui| {
ui.label("triangles");
show_optional_indices(ui);
ui.end_row();
});
}
}
}
}
10 changes: 5 additions & 5 deletions crates/re_query/src/latest_at/to_archetype/mesh3d.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions crates/re_query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ pub fn cacheable(component_name: re_types_core::ComponentName) -> bool {
re_types::components::TensorData::name(),
"rerun.components.TensorData"
);
assert_eq!(
re_types::components::MeshProperties::name(),
"rerun.components.MeshProperties"
);
assert_eq!(re_types::components::Blob::name(), "rerun.components.Blob");
}

Expand All @@ -147,9 +143,6 @@ pub fn cacheable(component_name: re_types_core::ComponentName) -> bool {
// TODO(#5974): tensors might already be cached in the ad-hoc JPEG cache, we don't
// want yet another copy.
re_types::components::TensorData::name(),
// TODO(#5974): meshes are already cached in the ad-hoc mesh cache, we don't
// want yet another copy.
re_types::components::MeshProperties::name(),
// TODO(#5974): blobs are used for assets, which are themselves already cached in
// the ad-hoc mesh cache -- we don't want yet another copy.
re_types::components::Blob::name(),
Expand All @@ -161,7 +154,6 @@ pub fn cacheable(component_name: re_types_core::ComponentName) -> bool {
#[cfg(not(feature = "to_archetype"))]
let component_names = [
"rerun.components.TensorData".into(),
"rerun.components.MeshProperties".into(),
"rerun.components.Blob".into(),
];

Expand Down
8 changes: 2 additions & 6 deletions crates/re_space_view_spatial/src/mesh_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ impl LoadedMesh {

let Mesh3D {
vertex_positions,
mesh_properties,
vertex_normals,
vertex_colors,
vertex_texcoords,
triangle_indices,
mesh_material,
class_ids: _,
albedo_texture,
Expand All @@ -108,12 +108,8 @@ impl LoadedMesh {
let vertex_positions: &[glam::Vec3] = bytemuck::cast_slice(vertex_positions.as_slice());
let num_positions = vertex_positions.len();

let triangle_indices = if let Some(indices) = mesh_properties
.as_ref()
.and_then(|props| props.indices.as_ref())
{
let triangle_indices = if let Some(indices) = triangle_indices {
re_tracing::profile_scope!("copy_indices");
anyhow::ensure!(indices.len() % 3 == 0);
let indices: &[glam::UVec3] = bytemuck::cast_slice(indices);
indices.to_vec()
} else {
Expand Down
14 changes: 7 additions & 7 deletions crates/re_space_view_spatial/src/visualizers/meshes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use re_renderer::renderer::MeshInstance;
use re_types::{
archetypes::Mesh3D,
components::{
ClassId, Color, Material, MeshProperties, Position3D, TensorData, Texcoord2D, Vector3D,
ClassId, Color, Material, Position3D, TensorData, Texcoord2D, TriangleIndices, Vector3D,
},
};
use re_viewer_context::{
Expand Down Expand Up @@ -44,7 +44,7 @@ struct Mesh3DComponentData<'a> {
vertex_colors: &'a [Color],
vertex_texcoords: &'a [Texcoord2D],

mesh_properties: Option<&'a MeshProperties>,
triangle_indices: Option<&'a [TriangleIndices]>,
mesh_material: Option<&'a Material>,
albedo_texture: Option<&'a TensorData>,

Expand Down Expand Up @@ -89,7 +89,7 @@ impl Mesh3DVisualizer {
AnyMesh::Mesh {
mesh: &Mesh3D {
vertex_positions: data.vertex_positions.to_owned(),
mesh_properties: data.mesh_properties.cloned(),
triangle_indices: data.triangle_indices.map(ToOwned::to_owned),
vertex_normals: (!vertex_normals.is_empty()).then_some(vertex_normals),
vertex_colors: (!vertex_colors.is_empty()).then_some(vertex_colors),
vertex_texcoords: (!vertex_texcoords.is_empty())
Expand Down Expand Up @@ -179,7 +179,7 @@ impl VisualizerSystem for Mesh3DVisualizer {
let vertex_normals = results.get_or_empty_dense(resolver)?;
let vertex_colors = results.get_or_empty_dense(resolver)?;
let vertex_texcoords = results.get_or_empty_dense(resolver)?;
let mesh_properties = results.get_or_empty_dense(resolver)?;
let triangle_indices = results.get_or_empty_dense(resolver)?;
let mesh_materials = results.get_or_empty_dense(resolver)?;
let albedo_textures = results.get_or_empty_dense(resolver)?;
let class_ids = results.get_or_empty_dense(resolver)?;
Expand All @@ -189,7 +189,7 @@ impl VisualizerSystem for Mesh3DVisualizer {
vertex_normals.range_indexed(),
vertex_colors.range_indexed(),
vertex_texcoords.range_indexed(),
mesh_properties.range_indexed(),
triangle_indices.range_indexed(),
mesh_materials.range_indexed(),
albedo_textures.range_indexed(),
class_ids.range_indexed(),
Expand All @@ -201,7 +201,7 @@ impl VisualizerSystem for Mesh3DVisualizer {
vertex_normals,
vertex_colors,
vertex_texcoords,
mesh_properties,
triangle_indices,
mesh_material,
albedo_texture,
class_ids,
Expand All @@ -212,7 +212,7 @@ impl VisualizerSystem for Mesh3DVisualizer {
vertex_normals: vertex_normals.unwrap_or_default(),
vertex_colors: vertex_colors.unwrap_or_default(),
vertex_texcoords: vertex_texcoords.unwrap_or_default(),
mesh_properties: mesh_properties.and_then(|v| v.first()),
triangle_indices,
mesh_material: mesh_material.and_then(|v| v.first()),
albedo_texture: albedo_texture.and_then(|v| v.first()),
class_ids: class_ids.unwrap_or_default(),
Expand Down
10 changes: 3 additions & 7 deletions crates/re_types/definitions/rerun/archetypes/mesh3d.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ table Mesh3D (

/// The positions of each vertex.
///
/// If no `indices` are specified, then each triplet of positions is interpreted as a triangle.
/// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
vertex_positions: [rerun.components.Position3D] ("attr.rerun.component_required", order: 1000);

// --- Recommended ---

/// Optional properties for the mesh as a whole (including indexed drawing).
//
// NOTE: We cannot have triangle indices here as that would break our instance key rules (either 0, 1 or N).
mesh_properties: rerun.components.MeshProperties ("attr.rerun.component_recommended", nullable, order: 2000);
/// Optional indices for the triangles that make up the mesh.
triangle_indices: [rerun.components.TriangleIndices] ("attr.rerun.component_recommended", nullable, order: 2000);

/// An optional normal for each vertex.
///
/// If specified, this must have as many elements as `vertex_positions`.
vertex_normals: [rerun.components.Vector3D] ("attr.rerun.component_recommended", nullable, order: 2100);

// --- Optional ---
Expand Down
6 changes: 3 additions & 3 deletions crates/re_types/definitions/rerun/components.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ include "./components/marker_shape.fbs";
include "./components/marker_size.fbs";
include "./components/material.fbs";
include "./components/media_type.fbs";
include "./components/mesh_properties.fbs";
include "./components/name.fbs";
include "./components/out_of_tree_transform3d.fbs";
include "./components/pinhole_projection.fbs";
Expand All @@ -26,14 +25,15 @@ include "./components/range1d.fbs";
include "./components/range2d.fbs";
include "./components/resolution.fbs";
include "./components/rotation3d.fbs";
include "./components/scalar_scattering.fbs";
include "./components/scalar.fbs";
include "./components/scalar_scattering.fbs";
include "./components/stroke_width.fbs";
include "./components/tensor_data.fbs";
include "./components/texcoord2d.fbs";
include "./components/text_log_level.fbs";
include "./components/text.fbs";
include "./components/text_log_level.fbs";
include "./components/transform3d.fbs";
include "./components/triangle_indices.fbs";
include "./components/vector2d.fbs";
include "./components/vector3d.fbs";
include "./components/view_coordinates.fbs";
Expand Down
17 changes: 0 additions & 17 deletions crates/re_types/definitions/rerun/components/mesh_properties.fbs

This file was deleted.

18 changes: 18 additions & 0 deletions crates/re_types/definitions/rerun/components/triangle_indices.fbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include "arrow/attributes.fbs";
include "python/attributes.fbs";
include "fbs/attributes.fbs";
include "rust/attributes.fbs";

include "../datatypes/uvec3d.fbs";

namespace rerun.components;

// ---

/// The three indices of a triangle mesh.
struct TriangleIndices (
"attr.rust.derive": "Copy, PartialEq, Eq, bytemuck::Pod, bytemuck::Zeroable",
"attr.rust.repr": "transparent"
) {
indices: rerun.datatypes.UVec3D (order: 100);
}
5 changes: 2 additions & 3 deletions crates/re_types/definitions/rerun/datatypes.fbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include "./datatypes/angle.fbs";
include "./datatypes/annotation_info.fbs";
include "./datatypes/bool.fbs";
include "./datatypes/class_description_map_elem.fbs";
include "./datatypes/class_description.fbs";
include "./datatypes/class_description_map_elem.fbs";
include "./datatypes/class_id.fbs";
include "./datatypes/entity_path.fbs";
include "./datatypes/float32.fbs";
Expand All @@ -11,13 +11,12 @@ include "./datatypes/keypoint_pair.fbs";
include "./datatypes/mat3x3.fbs";
include "./datatypes/mat4x4.fbs";
include "./datatypes/material.fbs";
include "./datatypes/mesh_properties.fbs";
include "./datatypes/quaternion.fbs";
include "./datatypes/range1d.fbs";
include "./datatypes/range2d.fbs";
include "./datatypes/rgba32.fbs";
include "./datatypes/rotation_axis_angle.fbs";
include "./datatypes/rotation3d.fbs";
include "./datatypes/rotation_axis_angle.fbs";
include "./datatypes/scale3d.fbs";
include "./datatypes/tensor_buffer.fbs";
include "./datatypes/tensor_data.fbs";
Expand Down
22 changes: 0 additions & 22 deletions crates/re_types/definitions/rerun/datatypes/mesh_properties.fbs

This file was deleted.

Loading
Loading