From 23a40fb00d704920fb8b1eccac01f12fb639216e Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 10 Jul 2024 09:31:10 +0200 Subject: [PATCH] Rename Material to AlbedoFactor --- .../definitions/rerun/archetypes/mesh3d.fbs | 4 +- .../re_types/definitions/rerun/components.fbs | 2 +- .../rerun/components/albedo_factor.fbs | 19 ++ .../definitions/rerun/components/material.fbs | 18 -- .../re_types/definitions/rerun/datatypes.fbs | 1 - .../definitions/rerun/datatypes/material.fbs | 18 -- .../store/re_types/src/archetypes/mesh3d.rs | 33 +-- .../re_types/src/components/.gitattributes | 2 +- .../{material.rs => albedo_factor.rs} | 51 +++-- .../src/components/albedo_factor_ext.rs | 10 + .../re_types/src/components/material_ext.rs | 11 - crates/store/re_types/src/components/mod.rs | 6 +- .../re_types/src/datatypes/.gitattributes | 1 - .../store/re_types/src/datatypes/material.rs | 210 ------------------ .../re_types/src/datatypes/material_ext.rs | 24 -- crates/store/re_types/src/datatypes/mod.rs | 3 - crates/store/re_types/tests/mesh3d.rs | 13 +- crates/top/rerun/src/sdk.rs | 2 +- crates/viewer/re_edit_ui/src/albedo_factor.rs | 21 ++ crates/viewer/re_edit_ui/src/lib.rs | 4 +- crates/viewer/re_edit_ui/src/material.rs | 26 --- .../re_space_view_spatial/src/mesh_loader.rs | 6 +- .../src/visualizers/meshes.rs | 14 +- crates/viewer/re_viewer/src/reflection/mod.rs | 14 +- docs/content/howto/ros2-nav-turtlebot.md | 2 +- .../reference/types/archetypes/mesh3d.md | 2 +- docs/content/reference/types/components.md | 2 +- .../reference/types/components/.gitattributes | 2 +- .../types/components/albedo_factor.md | 20 ++ .../reference/types/components/material.md | 20 -- docs/content/reference/types/datatypes.md | 1 - .../reference/types/datatypes/.gitattributes | 1 - .../reference/types/datatypes/material.md | 20 -- .../reference/types/datatypes/rgba32.md | 2 +- examples/python/raw_mesh/README.md | 2 +- examples/python/raw_mesh/raw_mesh/__main__.py | 8 +- examples/python/ros_node/rerun_urdf.py | 8 +- examples/rust/raw_mesh/src/main.rs | 7 +- rerun_cpp/src/rerun.hpp | 2 +- rerun_cpp/src/rerun/archetypes/mesh3d.cpp | 4 +- rerun_cpp/src/rerun/archetypes/mesh3d.hpp | 12 +- rerun_cpp/src/rerun/components.hpp | 2 +- rerun_cpp/src/rerun/components/.gitattributes | 2 +- .../src/rerun/components/albedo_factor.hpp | 64 ++++++ rerun_cpp/src/rerun/components/material.hpp | 74 ------ .../src/rerun/components/material_ext.cpp | 23 -- rerun_cpp/src/rerun/datatypes.hpp | 1 - rerun_cpp/src/rerun/datatypes/.gitattributes | 2 - rerun_cpp/src/rerun/datatypes/material.cpp | 78 ------- rerun_cpp/src/rerun/datatypes/material.hpp | 67 ------ rerun_cpp/tests/archetypes/mesh3d.cpp | 10 +- rerun_py/rerun_sdk/rerun/__init__.py | 2 +- rerun_py/rerun_sdk/rerun/archetypes/mesh3d.py | 8 +- .../rerun_sdk/rerun/archetypes/mesh3d_ext.py | 8 +- .../rerun_sdk/rerun/components/.gitattributes | 2 +- .../rerun_sdk/rerun/components/__init__.py | 8 +- .../rerun/components/albedo_factor.py | 36 +++ .../rerun_sdk/rerun/components/material.py | 36 --- .../rerun_sdk/rerun/datatypes/.gitattributes | 1 - .../rerun_sdk/rerun/datatypes/__init__.py | 6 - .../rerun_sdk/rerun/datatypes/material.py | 81 ------- .../rerun_sdk/rerun/datatypes/material_ext.py | 31 --- rerun_py/tests/unit/test_mesh3d.py | 44 +--- .../check_all_components_ui.py | 2 +- 64 files changed, 303 insertions(+), 913 deletions(-) create mode 100644 crates/store/re_types/definitions/rerun/components/albedo_factor.fbs delete mode 100644 crates/store/re_types/definitions/rerun/components/material.fbs delete mode 100644 crates/store/re_types/definitions/rerun/datatypes/material.fbs rename crates/store/re_types/src/components/{material.rs => albedo_factor.rs} (58%) create mode 100644 crates/store/re_types/src/components/albedo_factor_ext.rs delete mode 100644 crates/store/re_types/src/components/material_ext.rs delete mode 100644 crates/store/re_types/src/datatypes/material.rs delete mode 100644 crates/store/re_types/src/datatypes/material_ext.rs create mode 100644 crates/viewer/re_edit_ui/src/albedo_factor.rs delete mode 100644 crates/viewer/re_edit_ui/src/material.rs create mode 100644 docs/content/reference/types/components/albedo_factor.md delete mode 100644 docs/content/reference/types/components/material.md delete mode 100644 docs/content/reference/types/datatypes/material.md create mode 100644 rerun_cpp/src/rerun/components/albedo_factor.hpp delete mode 100644 rerun_cpp/src/rerun/components/material.hpp delete mode 100644 rerun_cpp/src/rerun/components/material_ext.cpp delete mode 100644 rerun_cpp/src/rerun/datatypes/material.cpp delete mode 100644 rerun_cpp/src/rerun/datatypes/material.hpp create mode 100644 rerun_py/rerun_sdk/rerun/components/albedo_factor.py delete mode 100644 rerun_py/rerun_sdk/rerun/components/material.py delete mode 100644 rerun_py/rerun_sdk/rerun/datatypes/material.py delete mode 100644 rerun_py/rerun_sdk/rerun/datatypes/material_ext.py diff --git a/crates/store/re_types/definitions/rerun/archetypes/mesh3d.fbs b/crates/store/re_types/definitions/rerun/archetypes/mesh3d.fbs index eec6ce93c5dd1..ee65d85200698 100644 --- a/crates/store/re_types/definitions/rerun/archetypes/mesh3d.fbs +++ b/crates/store/re_types/definitions/rerun/archetypes/mesh3d.fbs @@ -42,8 +42,8 @@ table Mesh3D ( /// An optional uv texture coordinate for each vertex. vertex_texcoords: [rerun.components.Texcoord2D] ("attr.rerun.component_optional", nullable, order: 3200); - /// Optional material properties for the mesh as a whole. - mesh_material: rerun.components.Material ("attr.rerun.component_optional", nullable, order: 3300); + /// A color multiplier applied to the whole mesh. + albedo_factor: rerun.components.AlbedoFactor ("attr.rerun.component_optional", nullable, order: 3300); /// Optional albedo texture. /// diff --git a/crates/store/re_types/definitions/rerun/components.fbs b/crates/store/re_types/definitions/rerun/components.fbs index edeae9a586bfa..39e4ae2149deb 100644 --- a/crates/store/re_types/definitions/rerun/components.fbs +++ b/crates/store/re_types/definitions/rerun/components.fbs @@ -1,4 +1,5 @@ include "./components/aggregation_policy.fbs"; +include "./components/albedo_factor.fbs"; include "./components/annotation_context.fbs"; include "./components/axis_length.fbs"; include "./components/blob.fbs"; @@ -20,7 +21,6 @@ include "./components/line_strip3d.fbs"; include "./components/magnification_filter.fbs"; include "./components/marker_shape.fbs"; include "./components/marker_size.fbs"; -include "./components/material.fbs"; include "./components/media_type.fbs"; include "./components/name.fbs"; include "./components/opacity.fbs"; diff --git a/crates/store/re_types/definitions/rerun/components/albedo_factor.fbs b/crates/store/re_types/definitions/rerun/components/albedo_factor.fbs new file mode 100644 index 0000000000000..ba97cf53af729 --- /dev/null +++ b/crates/store/re_types/definitions/rerun/components/albedo_factor.fbs @@ -0,0 +1,19 @@ +include "arrow/attributes.fbs"; +include "python/attributes.fbs"; +include "rust/attributes.fbs"; + +include "rerun/datatypes.fbs"; +include "rerun/attributes.fbs"; + +namespace rerun.components; + +// --- + +/// A color multiplier, usually applied to a whole entity, e.g. a mesh. +table AlbedoFactor ( + "attr.rust.derive": "Copy, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck::Pod, bytemuck::Zeroable", + "attr.rust.repr": "transparent" +) { + albedo_factor: rerun.datatypes.Rgba32 (order: 100); +} + diff --git a/crates/store/re_types/definitions/rerun/components/material.fbs b/crates/store/re_types/definitions/rerun/components/material.fbs deleted file mode 100644 index e53955aa3f3a3..0000000000000 --- a/crates/store/re_types/definitions/rerun/components/material.fbs +++ /dev/null @@ -1,18 +0,0 @@ -include "arrow/attributes.fbs"; -include "python/attributes.fbs"; -include "rust/attributes.fbs"; - -include "rerun/datatypes.fbs"; -include "rerun/attributes.fbs"; - -namespace rerun.components; - -// --- - -/// Material properties of a mesh, e.g. its color multiplier. -table Material ( - "attr.rust.derive": "Default, PartialEq, Eq" -) { - material: rerun.datatypes.Material (order: 100); -} - diff --git a/crates/store/re_types/definitions/rerun/datatypes.fbs b/crates/store/re_types/definitions/rerun/datatypes.fbs index cff57723cc7b8..1c95662a0bfae 100644 --- a/crates/store/re_types/definitions/rerun/datatypes.fbs +++ b/crates/store/re_types/definitions/rerun/datatypes.fbs @@ -10,7 +10,6 @@ include "./datatypes/keypoint_id.fbs"; include "./datatypes/keypoint_pair.fbs"; include "./datatypes/mat3x3.fbs"; include "./datatypes/mat4x4.fbs"; -include "./datatypes/material.fbs"; include "./datatypes/quaternion.fbs"; include "./datatypes/range1d.fbs"; include "./datatypes/range2d.fbs"; diff --git a/crates/store/re_types/definitions/rerun/datatypes/material.fbs b/crates/store/re_types/definitions/rerun/datatypes/material.fbs deleted file mode 100644 index 608384eaec286..0000000000000 --- a/crates/store/re_types/definitions/rerun/datatypes/material.fbs +++ /dev/null @@ -1,18 +0,0 @@ -include "arrow/attributes.fbs"; -include "python/attributes.fbs"; -include "rust/attributes.fbs"; - -include "rerun/attributes.fbs"; -include "rerun/datatypes/rgba32.fbs"; - -namespace rerun.datatypes; - -// --- - -/// Material properties of a mesh, e.g. its color multiplier. -struct Material ( - "attr.rust.derive": "Copy, PartialEq, Eq, Hash" -) { - /// Optional color multiplier. - albedo_factor: rerun.datatypes.Rgba32 (nullable, order: 100); -} diff --git a/crates/store/re_types/src/archetypes/mesh3d.rs b/crates/store/re_types/src/archetypes/mesh3d.rs index 594ba25a0445f..33792b24c035b 100644 --- a/crates/store/re_types/src/archetypes/mesh3d.rs +++ b/crates/store/re_types/src/archetypes/mesh3d.rs @@ -68,8 +68,8 @@ pub struct Mesh3D { /// An optional uv texture coordinate for each vertex. pub vertex_texcoords: Option>, - /// Optional material properties for the mesh as a whole. - pub mesh_material: Option, + /// A color multiplier applied to the whole mesh. + pub albedo_factor: Option, /// Optional albedo texture. /// @@ -92,7 +92,7 @@ impl ::re_types_core::SizeBytes for Mesh3D { + self.vertex_normals.heap_size_bytes() + self.vertex_colors.heap_size_bytes() + self.vertex_texcoords.heap_size_bytes() - + self.mesh_material.heap_size_bytes() + + self.albedo_factor.heap_size_bytes() + self.albedo_texture.heap_size_bytes() + self.class_ids.heap_size_bytes() } @@ -104,7 +104,7 @@ impl ::re_types_core::SizeBytes for Mesh3D { && >>::is_pod() && >>::is_pod() && >>::is_pod() - && >::is_pod() + && >::is_pod() && >::is_pod() && >>::is_pod() } @@ -127,7 +127,7 @@ static OPTIONAL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 5usize]> = [ "rerun.components.Color".into(), "rerun.components.Texcoord2D".into(), - "rerun.components.Material".into(), + "rerun.components.AlbedoFactor".into(), "rerun.components.TensorData".into(), "rerun.components.ClassId".into(), ] @@ -142,7 +142,7 @@ static ALL_COMPONENTS: once_cell::sync::Lazy<[ComponentName; 9usize]> = "rerun.components.Mesh3DIndicator".into(), "rerun.components.Color".into(), "rerun.components.Texcoord2D".into(), - "rerun.components.Material".into(), + "rerun.components.AlbedoFactor".into(), "rerun.components.TensorData".into(), "rerun.components.ClassId".into(), ] @@ -267,9 +267,10 @@ impl ::re_types_core::Archetype for Mesh3D { } else { None }; - let mesh_material = if let Some(array) = arrays_by_name.get("rerun.components.Material") { - ::from_arrow_opt(&**array) - .with_context("rerun.archetypes.Mesh3D#mesh_material")? + let albedo_factor = if let Some(array) = arrays_by_name.get("rerun.components.AlbedoFactor") + { + ::from_arrow_opt(&**array) + .with_context("rerun.archetypes.Mesh3D#albedo_factor")? .into_iter() .next() .flatten() @@ -304,7 +305,7 @@ impl ::re_types_core::Archetype for Mesh3D { vertex_normals, vertex_colors, vertex_texcoords, - mesh_material, + albedo_factor, albedo_texture, class_ids, }) @@ -330,7 +331,7 @@ impl ::re_types_core::AsComponents for Mesh3D { self.vertex_texcoords .as_ref() .map(|comp_batch| (comp_batch as &dyn ComponentBatch).into()), - self.mesh_material + self.albedo_factor .as_ref() .map(|comp| (comp as &dyn ComponentBatch).into()), self.albedo_texture @@ -358,7 +359,7 @@ impl Mesh3D { vertex_normals: None, vertex_colors: None, vertex_texcoords: None, - mesh_material: None, + albedo_factor: None, albedo_texture: None, class_ids: None, } @@ -404,13 +405,13 @@ impl Mesh3D { self } - /// Optional material properties for the mesh as a whole. + /// A color multiplier applied to the whole mesh. #[inline] - pub fn with_mesh_material( + pub fn with_albedo_factor( mut self, - mesh_material: impl Into, + albedo_factor: impl Into, ) -> Self { - self.mesh_material = Some(mesh_material.into()); + self.albedo_factor = Some(albedo_factor.into()); self } diff --git a/crates/store/re_types/src/components/.gitattributes b/crates/store/re_types/src/components/.gitattributes index 4443e3b057987..1393cc86c665d 100644 --- a/crates/store/re_types/src/components/.gitattributes +++ b/crates/store/re_types/src/components/.gitattributes @@ -2,6 +2,7 @@ .gitattributes linguist-generated=true aggregation_policy.rs linguist-generated=true +albedo_factor.rs linguist-generated=true annotation_context.rs linguist-generated=true axis_length.rs linguist-generated=true blob.rs linguist-generated=true @@ -22,7 +23,6 @@ line_strip3d.rs linguist-generated=true magnification_filter.rs linguist-generated=true marker_shape.rs linguist-generated=true marker_size.rs linguist-generated=true -material.rs linguist-generated=true media_type.rs linguist-generated=true mod.rs linguist-generated=true name.rs linguist-generated=true diff --git a/crates/store/re_types/src/components/material.rs b/crates/store/re_types/src/components/albedo_factor.rs similarity index 58% rename from crates/store/re_types/src/components/material.rs rename to crates/store/re_types/src/components/albedo_factor.rs index 8758cb4637097..ceb765af3c48d 100644 --- a/crates/store/re_types/src/components/material.rs +++ b/crates/store/re_types/src/components/albedo_factor.rs @@ -1,5 +1,5 @@ // DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs -// Based on "crates/store/re_types/definitions/rerun/components/material.fbs". +// Based on "crates/store/re_types/definitions/rerun/components/albedo_factor.fbs". #![allow(unused_imports)] #![allow(unused_parens)] @@ -18,11 +18,14 @@ use ::re_types_core::SerializationResult; use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; use ::re_types_core::{DeserializationError, DeserializationResult}; -/// **Component**: Material properties of a mesh, e.g. its color multiplier. -#[derive(Clone, Debug, Default, PartialEq, Eq)] -pub struct Material(pub crate::datatypes::Material); +/// **Component**: A color multiplier, usually applied to a whole entity, e.g. a mesh. +#[derive( + Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, bytemuck::Pod, bytemuck::Zeroable, +)] +#[repr(transparent)] +pub struct AlbedoFactor(pub crate::datatypes::Rgba32); -impl ::re_types_core::SizeBytes for Material { +impl ::re_types_core::SizeBytes for AlbedoFactor { #[inline] fn heap_size_bytes(&self) -> u64 { self.0.heap_size_bytes() @@ -30,52 +33,52 @@ impl ::re_types_core::SizeBytes for Material { #[inline] fn is_pod() -> bool { - ::is_pod() + ::is_pod() } } -impl> From for Material { +impl> From for AlbedoFactor { fn from(v: T) -> Self { Self(v.into()) } } -impl std::borrow::Borrow for Material { +impl std::borrow::Borrow for AlbedoFactor { #[inline] - fn borrow(&self) -> &crate::datatypes::Material { + fn borrow(&self) -> &crate::datatypes::Rgba32 { &self.0 } } -impl std::ops::Deref for Material { - type Target = crate::datatypes::Material; +impl std::ops::Deref for AlbedoFactor { + type Target = crate::datatypes::Rgba32; #[inline] - fn deref(&self) -> &crate::datatypes::Material { + fn deref(&self) -> &crate::datatypes::Rgba32 { &self.0 } } -impl std::ops::DerefMut for Material { +impl std::ops::DerefMut for AlbedoFactor { #[inline] - fn deref_mut(&mut self) -> &mut crate::datatypes::Material { + fn deref_mut(&mut self) -> &mut crate::datatypes::Rgba32 { &mut self.0 } } -::re_types_core::macros::impl_into_cow!(Material); +::re_types_core::macros::impl_into_cow!(AlbedoFactor); -impl ::re_types_core::Loggable for Material { +impl ::re_types_core::Loggable for AlbedoFactor { type Name = ::re_types_core::ComponentName; #[inline] fn name() -> Self::Name { - "rerun.components.Material".into() + "rerun.components.AlbedoFactor".into() } #[inline] fn arrow_datatype() -> arrow2::datatypes::DataType { - crate::datatypes::Material::arrow_datatype() + crate::datatypes::Rgba32::arrow_datatype() } fn to_arrow_opt<'a>( @@ -84,7 +87,7 @@ impl ::re_types_core::Loggable for Material { where Self: Clone + 'a, { - crate::datatypes::Material::to_arrow_opt(data.into_iter().map(|datum| { + crate::datatypes::Rgba32::to_arrow_opt(data.into_iter().map(|datum| { datum.map(|datum| match datum.into() { ::std::borrow::Cow::Borrowed(datum) => ::std::borrow::Cow::Borrowed(&datum.0), ::std::borrow::Cow::Owned(datum) => ::std::borrow::Cow::Owned(datum.0), @@ -98,7 +101,15 @@ impl ::re_types_core::Loggable for Material { where Self: Sized, { - crate::datatypes::Material::from_arrow_opt(arrow_data) + crate::datatypes::Rgba32::from_arrow_opt(arrow_data) .map(|v| v.into_iter().map(|v| v.map(Self)).collect()) } + + #[inline] + fn from_arrow(arrow_data: &dyn arrow2::array::Array) -> DeserializationResult> + where + Self: Sized, + { + crate::datatypes::Rgba32::from_arrow(arrow_data).map(bytemuck::cast_vec) + } } diff --git a/crates/store/re_types/src/components/albedo_factor_ext.rs b/crates/store/re_types/src/components/albedo_factor_ext.rs new file mode 100644 index 0000000000000..122d33ec95fa2 --- /dev/null +++ b/crates/store/re_types/src/components/albedo_factor_ext.rs @@ -0,0 +1,10 @@ +use crate::datatypes::Rgba32; + +use super::AlbedoFactor; + +impl Default for AlbedoFactor { + #[inline] + fn default() -> Self { + Self(Rgba32::WHITE) + } +} diff --git a/crates/store/re_types/src/components/material_ext.rs b/crates/store/re_types/src/components/material_ext.rs deleted file mode 100644 index f5a4a1fd2f2e2..0000000000000 --- a/crates/store/re_types/src/components/material_ext.rs +++ /dev/null @@ -1,11 +0,0 @@ -use crate::datatypes::Rgba32; - -use super::Material; - -impl Material { - /// A new material using a given color multiplier. - #[inline] - pub fn from_albedo_factor(color: impl Into) -> Self { - Self(crate::datatypes::Material::from_albedo_factor(color)) - } -} diff --git a/crates/store/re_types/src/components/mod.rs b/crates/store/re_types/src/components/mod.rs index da7bdac526faf..e30cc99d8b5e0 100644 --- a/crates/store/re_types/src/components/mod.rs +++ b/crates/store/re_types/src/components/mod.rs @@ -1,6 +1,8 @@ // DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs mod aggregation_policy; +mod albedo_factor; +mod albedo_factor_ext; mod annotation_context; mod axis_length; mod axis_length_ext; @@ -38,8 +40,6 @@ mod marker_shape; mod marker_shape_ext; mod marker_size; mod marker_size_ext; -mod material; -mod material_ext; mod media_type; mod media_type_ext; mod name; @@ -88,6 +88,7 @@ mod view_coordinates; mod view_coordinates_ext; pub use self::aggregation_policy::AggregationPolicy; +pub use self::albedo_factor::AlbedoFactor; pub use self::annotation_context::AnnotationContext; pub use self::axis_length::AxisLength; pub use self::blob::Blob; @@ -108,7 +109,6 @@ pub use self::line_strip3d::LineStrip3D; pub use self::magnification_filter::MagnificationFilter; pub use self::marker_shape::MarkerShape; pub use self::marker_size::MarkerSize; -pub use self::material::Material; pub use self::media_type::MediaType; pub use self::name::Name; pub use self::opacity::Opacity; diff --git a/crates/store/re_types/src/datatypes/.gitattributes b/crates/store/re_types/src/datatypes/.gitattributes index afabb7a21d9cf..4ddf094376837 100644 --- a/crates/store/re_types/src/datatypes/.gitattributes +++ b/crates/store/re_types/src/datatypes/.gitattributes @@ -11,7 +11,6 @@ keypoint_id.rs linguist-generated=true keypoint_pair.rs linguist-generated=true mat3x3.rs linguist-generated=true mat4x4.rs linguist-generated=true -material.rs linguist-generated=true mod.rs linguist-generated=true quaternion.rs linguist-generated=true range1d.rs linguist-generated=true diff --git a/crates/store/re_types/src/datatypes/material.rs b/crates/store/re_types/src/datatypes/material.rs deleted file mode 100644 index d49b5d7e7950c..0000000000000 --- a/crates/store/re_types/src/datatypes/material.rs +++ /dev/null @@ -1,210 +0,0 @@ -// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/rust/api.rs -// Based on "crates/store/re_types/definitions/rerun/datatypes/material.fbs". - -#![allow(unused_imports)] -#![allow(unused_parens)] -#![allow(clippy::clone_on_copy)] -#![allow(clippy::cloned_instead_of_copied)] -#![allow(clippy::map_flatten)] -#![allow(clippy::needless_question_mark)] -#![allow(clippy::new_without_default)] -#![allow(clippy::redundant_closure)] -#![allow(clippy::too_many_arguments)] -#![allow(clippy::too_many_lines)] - -use ::re_types_core::external::arrow2; -use ::re_types_core::ComponentName; -use ::re_types_core::SerializationResult; -use ::re_types_core::{ComponentBatch, MaybeOwnedComponentBatch}; -use ::re_types_core::{DeserializationError, DeserializationResult}; - -/// **Datatype**: Material properties of a mesh, e.g. its color multiplier. -#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash)] -pub struct Material { - /// Optional color multiplier. - pub albedo_factor: Option, -} - -impl ::re_types_core::SizeBytes for Material { - #[inline] - fn heap_size_bytes(&self) -> u64 { - self.albedo_factor.heap_size_bytes() - } - - #[inline] - fn is_pod() -> bool { - >::is_pod() - } -} - -impl>> From for Material { - fn from(v: T) -> Self { - Self { - albedo_factor: v.into(), - } - } -} - -impl std::borrow::Borrow> for Material { - #[inline] - fn borrow(&self) -> &Option { - &self.albedo_factor - } -} - -impl std::ops::Deref for Material { - type Target = Option; - - #[inline] - fn deref(&self) -> &Option { - &self.albedo_factor - } -} - -impl std::ops::DerefMut for Material { - #[inline] - fn deref_mut(&mut self) -> &mut Option { - &mut self.albedo_factor - } -} - -::re_types_core::macros::impl_into_cow!(Material); - -impl ::re_types_core::Loggable for Material { - type Name = ::re_types_core::DatatypeName; - - #[inline] - fn name() -> Self::Name { - "rerun.datatypes.Material".into() - } - - #[inline] - fn arrow_datatype() -> arrow2::datatypes::DataType { - #![allow(clippy::wildcard_imports)] - use arrow2::datatypes::*; - DataType::Struct(std::sync::Arc::new(vec![Field::new( - "albedo_factor", - ::arrow_datatype(), - true, - )])) - } - - fn to_arrow_opt<'a>( - data: impl IntoIterator>>>, - ) -> SerializationResult> - where - Self: Clone + 'a, - { - #![allow(clippy::wildcard_imports)] - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, datatypes::*}; - Ok({ - let (somes, data): (Vec<_>, Vec<_>) = data - .into_iter() - .map(|datum| { - let datum: Option<::std::borrow::Cow<'a, Self>> = datum.map(Into::into); - (datum.is_some(), datum) - }) - .unzip(); - let bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - StructArray::new( - Self::arrow_datatype(), - vec![{ - let (somes, albedo_factor): (Vec<_>, Vec<_>) = data - .iter() - .map(|datum| { - let datum = datum - .as_ref() - .map(|datum| datum.albedo_factor.clone()) - .flatten(); - (datum.is_some(), datum) - }) - .unzip(); - let albedo_factor_bitmap: Option = { - let any_nones = somes.iter().any(|some| !*some); - any_nones.then(|| somes.into()) - }; - PrimitiveArray::new( - DataType::UInt32, - albedo_factor - .into_iter() - .map(|datum| datum.map(|datum| datum.0).unwrap_or_default()) - .collect(), - albedo_factor_bitmap, - ) - .boxed() - }], - bitmap, - ) - .boxed() - }) - } - - fn from_arrow_opt( - arrow_data: &dyn arrow2::array::Array, - ) -> DeserializationResult>> - where - Self: Sized, - { - #![allow(clippy::wildcard_imports)] - use ::re_types_core::{Loggable as _, ResultExt as _}; - use arrow2::{array::*, buffer::*, datatypes::*}; - Ok({ - let arrow_data = arrow_data - .as_any() - .downcast_ref::() - .ok_or_else(|| { - let expected = Self::arrow_datatype(); - let actual = arrow_data.data_type().clone(); - DeserializationError::datatype_mismatch(expected, actual) - }) - .with_context("rerun.datatypes.Material")?; - if arrow_data.is_empty() { - Vec::new() - } else { - let (arrow_data_fields, arrow_data_arrays) = - (arrow_data.fields(), arrow_data.values()); - let arrays_by_name: ::std::collections::HashMap<_, _> = arrow_data_fields - .iter() - .map(|field| field.name.as_str()) - .zip(arrow_data_arrays) - .collect(); - let albedo_factor = { - if !arrays_by_name.contains_key("albedo_factor") { - return Err(DeserializationError::missing_struct_field( - Self::arrow_datatype(), - "albedo_factor", - )) - .with_context("rerun.datatypes.Material"); - } - let arrow_data = &**arrays_by_name["albedo_factor"]; - arrow_data - .as_any() - .downcast_ref::() - .ok_or_else(|| { - let expected = DataType::UInt32; - let actual = arrow_data.data_type().clone(); - DeserializationError::datatype_mismatch(expected, actual) - }) - .with_context("rerun.datatypes.Material#albedo_factor")? - .into_iter() - .map(|opt| opt.copied()) - .map(|res_or_opt| res_or_opt.map(crate::datatypes::Rgba32)) - }; - arrow2::bitmap::utils::ZipValidity::new_with_validity( - ::itertools::izip!(albedo_factor), - arrow_data.validity(), - ) - .map(|opt| { - opt.map(|(albedo_factor)| Ok(Self { albedo_factor })) - .transpose() - }) - .collect::>>() - .with_context("rerun.datatypes.Material")? - } - }) - } -} diff --git a/crates/store/re_types/src/datatypes/material_ext.rs b/crates/store/re_types/src/datatypes/material_ext.rs deleted file mode 100644 index 18732b20f8d38..0000000000000 --- a/crates/store/re_types/src/datatypes/material_ext.rs +++ /dev/null @@ -1,24 +0,0 @@ -use crate::datatypes::Rgba32; - -use super::Material; - -impl Material { - /// A new material using a given color multiplier. - #[inline] - pub fn from_albedo_factor(color: impl Into) -> Self { - Self { - albedo_factor: Some(color.into()), - } - } -} - -#[allow(clippy::derivable_impls)] // Soon no longer be derivable, also wanted to comment on choices here. -impl Default for Material { - #[inline] - fn default() -> Self { - Self { - // TODO(andreas): Would be nicer to not make this optional and just use white as default factor. - albedo_factor: None, - } - } -} diff --git a/crates/store/re_types/src/datatypes/mod.rs b/crates/store/re_types/src/datatypes/mod.rs index c67ff92517e5e..32eb635e23345 100644 --- a/crates/store/re_types/src/datatypes/mod.rs +++ b/crates/store/re_types/src/datatypes/mod.rs @@ -20,8 +20,6 @@ mod mat3x3; mod mat3x3_ext; mod mat4x4; mod mat4x4_ext; -mod material; -mod material_ext; mod quaternion; mod quaternion_ext; mod range1d; @@ -76,7 +74,6 @@ pub use self::keypoint_id::KeypointId; pub use self::keypoint_pair::KeypointPair; pub use self::mat3x3::Mat3x3; pub use self::mat4x4::Mat4x4; -pub use self::material::Material; pub use self::quaternion::Quaternion; pub use self::range1d::Range1D; pub use self::range2d::Range2D; diff --git a/crates/store/re_types/tests/mesh3d.rs b/crates/store/re_types/tests/mesh3d.rs index eb5f159aa145d..fd003ac5d09e6 100644 --- a/crates/store/re_types/tests/mesh3d.rs +++ b/crates/store/re_types/tests/mesh3d.rs @@ -3,9 +3,7 @@ use std::collections::HashMap; use re_types::{ archetypes::Mesh3D, components::{ClassId, Position3D, Texcoord2D, TriangleIndices, Vector3D}, - datatypes::{ - Material, Rgba32, TensorBuffer, TensorData, TensorDimension, UVec3D, Vec2D, Vec3D, - }, + datatypes::{Rgba32, TensorBuffer, TensorData, TensorDimension, UVec3D, Vec2D, Vec3D}, Archetype as _, AsComponents as _, }; @@ -47,12 +45,7 @@ fn roundtrip() { Texcoord2D(Vec2D([0.0, 1.0])), // Texcoord2D(Vec2D([2.0, 3.0])), // ]), - mesh_material: Some( - Material { - albedo_factor: Some(Rgba32::from_unmultiplied_rgba(0xEE, 0x11, 0x22, 0x33)), - } - .into(), - ), + albedo_factor: Some(Rgba32::from_unmultiplied_rgba(0xEE, 0x11, 0x22, 0x33).into()), albedo_texture: Some(tensor_data.clone()), class_ids: Some(vec![ ClassId::from(126), // @@ -65,7 +58,7 @@ fn roundtrip() { .with_vertex_normals([[4.0, 5.0, 6.0], [40.0, 50.0, 60.0]]) .with_vertex_colors([0xAA0000CC, 0x00BB00DD]) .with_vertex_texcoords([[0.0, 1.0], [2.0, 3.0]]) - .with_mesh_material(Material::from_albedo_factor(0xEE112233)) + .with_albedo_factor(0xEE112233) .with_class_ids([126, 127]) .with_albedo_texture(tensor_data); similar_asserts::assert_eq!(expected, arch); diff --git a/crates/top/rerun/src/sdk.rs b/crates/top/rerun/src/sdk.rs index 6ce29379ff104..ed8970b66f7f2 100644 --- a/crates/top/rerun/src/sdk.rs +++ b/crates/top/rerun/src/sdk.rs @@ -24,7 +24,7 @@ mod prelude { // Also import any component or datatype that has a unique name: pub use re_chunk::ChunkTimeline; pub use re_types::components::{ - Color, HalfSize2D, HalfSize3D, LineStrip2D, LineStrip3D, Material, MediaType, + AlbedoFactor, Color, HalfSize2D, HalfSize3D, LineStrip2D, LineStrip3D, MediaType, OutOfTreeTransform3D, Position2D, Position3D, Radius, Text, TextLogLevel, TriangleIndices, Vector2D, Vector3D, }; diff --git a/crates/viewer/re_edit_ui/src/albedo_factor.rs b/crates/viewer/re_edit_ui/src/albedo_factor.rs new file mode 100644 index 0000000000000..cbe77491c65bb --- /dev/null +++ b/crates/viewer/re_edit_ui/src/albedo_factor.rs @@ -0,0 +1,21 @@ +use re_types::{components::AlbedoFactor, components::Color}; +use re_viewer_context::{MaybeMutRef, ViewerContext}; + +use crate::color::edit_color_ui; + +pub fn edit_albedo_factor_ui( + ctx: &ViewerContext<'_>, + ui: &mut egui::Ui, + value: &mut MaybeMutRef<'_, AlbedoFactor>, +) -> egui::Response { + let rgba = value.as_ref().0; + + if let Some(value) = value.as_mut() { + let mut edit_color = Color(rgba); + let response = edit_color_ui(ctx, ui, &mut MaybeMutRef::MutRef(&mut edit_color)); + value.0 = edit_color.0; + response + } else { + edit_color_ui(ctx, ui, &mut MaybeMutRef::Ref(&Color(rgba))) + } +} diff --git a/crates/viewer/re_edit_ui/src/lib.rs b/crates/viewer/re_edit_ui/src/lib.rs index 802e8e6c3b721..327a0561d2544 100644 --- a/crates/viewer/re_edit_ui/src/lib.rs +++ b/crates/viewer/re_edit_ui/src/lib.rs @@ -3,10 +3,10 @@ //! The only entry point is [`register_editors`], which registers all editors in the component UI registry. //! This should be called by `re_viewer` on startup. +mod albedo_factor; mod color; mod datatype_editors; mod marker_shape; -mod material; mod radius; mod range1d; mod response_utils; @@ -38,7 +38,7 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) { registry.add_singleline_edit_or_view(radius::edit_radius_ui); registry.add_singleline_edit_or_view(marker_shape::edit_marker_shape_ui); - registry.add_singleline_edit_or_view(material::edit_material_ui); + registry.add_singleline_edit_or_view(albedo_factor::edit_albedo_factor_ui); registry.add_singleline_edit_or_view(range1d::edit_range1d); registry.add_singleline_edit_or_view::(edit_f32_zero_to_max); diff --git a/crates/viewer/re_edit_ui/src/material.rs b/crates/viewer/re_edit_ui/src/material.rs deleted file mode 100644 index 172cd4e834691..0000000000000 --- a/crates/viewer/re_edit_ui/src/material.rs +++ /dev/null @@ -1,26 +0,0 @@ -use re_types::{components::Material, datatypes::Rgba32}; -use re_viewer_context::{MaybeMutRef, ViewerContext}; - -use crate::color::edit_color_ui; - -// TODO(andreas): as we add more elements to the Material struct, we'll need a multi-line editor. -// begs the question though if a material struct is really the right way to go! -pub fn edit_material_ui( - ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut MaybeMutRef<'_, Material>, -) -> egui::Response { - ui.label("Albedo"); // "Albedo factor" makes the UI too wide. - - let re_types::datatypes::Material { albedo_factor } = value.as_ref().0; - let albedo_factor = albedo_factor.unwrap_or(Rgba32::WHITE).into(); - - if let Some(value) = value.as_mut() { - let mut edit_color = albedo_factor; - let response = edit_color_ui(ctx, ui, &mut MaybeMutRef::MutRef(&mut edit_color)); - value.albedo_factor = Some(edit_color.0); - response - } else { - edit_color_ui(ctx, ui, &mut MaybeMutRef::Ref(&albedo_factor)) - } -} diff --git a/crates/viewer/re_space_view_spatial/src/mesh_loader.rs b/crates/viewer/re_space_view_spatial/src/mesh_loader.rs index 108516c1ad070..2e8dc1ce20f40 100644 --- a/crates/viewer/re_space_view_spatial/src/mesh_loader.rs +++ b/crates/viewer/re_space_view_spatial/src/mesh_loader.rs @@ -100,7 +100,7 @@ impl LoadedMesh { vertex_colors, vertex_texcoords, triangle_indices, - mesh_material, + albedo_factor, class_ids: _, albedo_texture, } = mesh3d; @@ -147,8 +147,6 @@ impl LoadedMesh { vec![glam::Vec2::ZERO; num_positions] }; - let albedo_factor = mesh_material.as_ref().and_then(|mat| mat.albedo_factor); - let bbox = { re_tracing::profile_scope!("bbox"); macaw::BoundingBox::from_points(vertex_positions.iter().copied()) @@ -174,7 +172,7 @@ impl LoadedMesh { label: name.clone().into(), index_range: 0..num_indices as _, albedo, - albedo_multiplier: albedo_factor.map_or(re_renderer::Rgba::WHITE, |c| c.into()), + albedo_multiplier: albedo_factor.map_or(re_renderer::Rgba::WHITE, |c| c.0.into()), }], }; diff --git a/crates/viewer/re_space_view_spatial/src/visualizers/meshes.rs b/crates/viewer/re_space_view_spatial/src/visualizers/meshes.rs index 652cbe7be81bf..d77e2533e4292 100644 --- a/crates/viewer/re_space_view_spatial/src/visualizers/meshes.rs +++ b/crates/viewer/re_space_view_spatial/src/visualizers/meshes.rs @@ -7,7 +7,7 @@ use re_renderer::RenderContext; use re_types::{ archetypes::Mesh3D, components::{ - ClassId, Color, Material, Position3D, TensorData, Texcoord2D, TriangleIndices, Vector3D, + AlbedoFactor, ClassId, Color, Position3D, TensorData, Texcoord2D, TriangleIndices, Vector3D, }, }; use re_viewer_context::{ @@ -47,7 +47,7 @@ struct Mesh3DComponentData<'a> { vertex_texcoords: &'a [Texcoord2D], triangle_indices: Option<&'a [TriangleIndices]>, - mesh_material: Option<&'a Material>, + albedo_factor: Option<&'a AlbedoFactor>, albedo_texture: Option<&'a TensorData>, class_ids: &'a [ClassId], @@ -106,7 +106,7 @@ impl Mesh3DVisualizer { vertex_colors: (!vertex_colors.is_empty()).then_some(vertex_colors), vertex_texcoords: (!vertex_texcoords.is_empty()) .then_some(vertex_texcoords), - mesh_material: data.mesh_material.cloned(), + albedo_factor: data.albedo_factor.cloned(), albedo_texture: data.albedo_texture.cloned(), class_ids: (!data.class_ids.is_empty()) .then(|| data.class_ids.to_owned()), @@ -194,7 +194,7 @@ impl VisualizerSystem for Mesh3DVisualizer { let vertex_colors = results.get_or_empty_dense(resolver)?; let vertex_texcoords = 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_factors = results.get_or_empty_dense(resolver)?; let albedo_textures = results.get_or_empty_dense(resolver)?; let class_ids = results.get_or_empty_dense(resolver)?; @@ -206,7 +206,7 @@ impl VisualizerSystem for Mesh3DVisualizer { vertex_colors.range_indexed(), vertex_texcoords.range_indexed(), triangle_indices.range_indexed(), - mesh_materials.range_indexed(), + albedo_factors.range_indexed(), albedo_textures.range_indexed(), class_ids.range_indexed(), ) @@ -218,7 +218,7 @@ impl VisualizerSystem for Mesh3DVisualizer { vertex_colors, vertex_texcoords, triangle_indices, - mesh_material, + albedo_factor, albedo_texture, class_ids, )| { @@ -230,7 +230,7 @@ impl VisualizerSystem for Mesh3DVisualizer { vertex_colors: vertex_colors.unwrap_or_default(), vertex_texcoords: vertex_texcoords.unwrap_or_default(), triangle_indices, - mesh_material: mesh_material.and_then(|v| v.first()), + albedo_factor: albedo_factor.and_then(|v| v.first()), albedo_texture: albedo_texture.and_then(|v| v.first()), class_ids: class_ids.unwrap_or_default(), } diff --git a/crates/viewer/re_viewer/src/reflection/mod.rs b/crates/viewer/re_viewer/src/reflection/mod.rs index 98b9e0c9da0e4..83d414852019c 100644 --- a/crates/viewer/re_viewer/src/reflection/mod.rs +++ b/crates/viewer/re_viewer/src/reflection/mod.rs @@ -223,6 +223,13 @@ fn generate_component_reflection() -> Result::name(), + ComponentReflection { + docstring_md: "A color multiplier, usually applied to a whole entity, e.g. a mesh.", + placeholder: Some(AlbedoFactor::default().to_arrow()?), + }, + ), ( ::name(), ComponentReflection { @@ -370,13 +377,6 @@ fn generate_component_reflection() -> Result::name(), - ComponentReflection { - docstring_md: "Material properties of a mesh, e.g. its color multiplier.", - placeholder: Some(Material::default().to_arrow()?), - }, - ), ( ::name(), ComponentReflection { diff --git a/docs/content/howto/ros2-nav-turtlebot.md b/docs/content/howto/ros2-nav-turtlebot.md index a58bfcf9e2c57..a8cf516c9520a 100644 --- a/docs/content/howto/ros2-nav-turtlebot.md +++ b/docs/content/howto/ros2-nav-turtlebot.md @@ -457,7 +457,7 @@ if node_data: vertex_positions=mesh.vertices, triangle_indices=mesh.faces, vertex_normals=mesh.vertex_normals, - mesh_material=rr.Material(albedo_factor=albedo_factor), + albedo_factor=albedo_factor, ), timeless=timeless, ) diff --git a/docs/content/reference/types/archetypes/mesh3d.md b/docs/content/reference/types/archetypes/mesh3d.md index 048e765d30fe7..87c8320e44667 100644 --- a/docs/content/reference/types/archetypes/mesh3d.md +++ b/docs/content/reference/types/archetypes/mesh3d.md @@ -11,7 +11,7 @@ A 3D triangle mesh as specified by its per-mesh and per-vertex properties. **Recommended**: [`TriangleIndices`](../components/triangle_indices.md), [`Vector3D`](../components/vector3d.md) -**Optional**: [`Color`](../components/color.md), [`Texcoord2D`](../components/texcoord2d.md), [`Material`](../components/material.md), [`TensorData`](../components/tensor_data.md), [`ClassId`](../components/class_id.md) +**Optional**: [`Color`](../components/color.md), [`Texcoord2D`](../components/texcoord2d.md), [`AlbedoFactor`](../components/albedo_factor.md), [`TensorData`](../components/tensor_data.md), [`ClassId`](../components/class_id.md) ## Shown in * [Spatial3DView](../views/spatial3d_view.md) diff --git a/docs/content/reference/types/components.md b/docs/content/reference/types/components.md index 806392704a9e1..9f95ad3928894 100644 --- a/docs/content/reference/types/components.md +++ b/docs/content/reference/types/components.md @@ -14,6 +14,7 @@ on [Entities and Components](../../concepts/entity-component.md). * [`AggregationPolicy`](components/aggregation_policy.md): Policy for aggregation of multiple scalar plot values. +* [`AlbedoFactor`](components/albedo_factor.md): A color multiplier, usually applied to a whole entity, e.g. a mesh. * [`AnnotationContext`](components/annotation_context.md): The `AnnotationContext` provides additional information on how to display entities. * [`AxisLength`](components/axis_length.md): The length of an axis in local units of the space. * [`Blob`](components/blob.md): A binary blob of data. @@ -35,7 +36,6 @@ on [Entities and Components](../../concepts/entity-component.md). * [`MagnificationFilter`](components/magnification_filter.md): Filter used when magnifying an image/texture such that a single pixel/texel is displayed as multiple pixels on screen. * [`MarkerShape`](components/marker_shape.md): The visual appearance of a point in e.g. a 2D plot. * [`MarkerSize`](components/marker_size.md): Radius of a marker of a point in e.g. a 2D plot, measured in UI points. -* [`Material`](components/material.md): Material properties of a mesh, e.g. its color multiplier. * [`MediaType`](components/media_type.md): A standardized media type (RFC2046, formerly known as MIME types), encoded as a utf8 string. * [`Name`](components/name.md): A display name, typically for an entity or a item like a plot series. * [`Opacity`](components/opacity.md): Degree of transparency ranging from 0.0 (fully transparent) to 1.0 (fully opaque). diff --git a/docs/content/reference/types/components/.gitattributes b/docs/content/reference/types/components/.gitattributes index 8414aa31234d4..956bb88f67126 100644 --- a/docs/content/reference/types/components/.gitattributes +++ b/docs/content/reference/types/components/.gitattributes @@ -2,6 +2,7 @@ .gitattributes linguist-generated=true aggregation_policy.md linguist-generated=true +albedo_factor.md linguist-generated=true annotation_context.md linguist-generated=true axis_length.md linguist-generated=true blob.md linguist-generated=true @@ -23,7 +24,6 @@ line_strip3d.md linguist-generated=true magnification_filter.md linguist-generated=true marker_shape.md linguist-generated=true marker_size.md linguist-generated=true -material.md linguist-generated=true media_type.md linguist-generated=true name.md linguist-generated=true opacity.md linguist-generated=true diff --git a/docs/content/reference/types/components/albedo_factor.md b/docs/content/reference/types/components/albedo_factor.md new file mode 100644 index 0000000000000..179ee779f7860 --- /dev/null +++ b/docs/content/reference/types/components/albedo_factor.md @@ -0,0 +1,20 @@ +--- +title: "AlbedoFactor" +--- + + +A color multiplier, usually applied to a whole entity, e.g. a mesh. + +## Fields + +* albedo_factor: [`Rgba32`](../datatypes/rgba32.md) + +## API reference links + * 🌊 [C++ API docs for `AlbedoFactor`](https://ref.rerun.io/docs/cpp/stable/structrerun_1_1components_1_1AlbedoFactor.html) + * 🐍 [Python API docs for `AlbedoFactor`](https://ref.rerun.io/docs/python/stable/common/components#rerun.components.AlbedoFactor) + * πŸ¦€ [Rust API docs for `AlbedoFactor`](https://docs.rs/rerun/latest/rerun/components/struct.AlbedoFactor.html) + + +## Used by + +* [`Mesh3D`](../archetypes/mesh3d.md) diff --git a/docs/content/reference/types/components/material.md b/docs/content/reference/types/components/material.md deleted file mode 100644 index ddfae17bab8b4..0000000000000 --- a/docs/content/reference/types/components/material.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "Material" ---- - - -Material properties of a mesh, e.g. its color multiplier. - -## Fields - -* material: [`Material`](../datatypes/material.md) - -## API reference links - * 🌊 [C++ API docs for `Material`](https://ref.rerun.io/docs/cpp/stable/structrerun_1_1components_1_1Material.html) - * 🐍 [Python API docs for `Material`](https://ref.rerun.io/docs/python/stable/common/components#rerun.components.Material) - * πŸ¦€ [Rust API docs for `Material`](https://docs.rs/rerun/latest/rerun/components/struct.Material.html) - - -## Used by - -* [`Mesh3D`](../archetypes/mesh3d.md) diff --git a/docs/content/reference/types/datatypes.md b/docs/content/reference/types/datatypes.md index 84100ceacbea1..bf35dfdb771a7 100644 --- a/docs/content/reference/types/datatypes.md +++ b/docs/content/reference/types/datatypes.md @@ -19,7 +19,6 @@ Data types are the lowest layer of the data model hierarchy. They are re-usable * [`KeypointPair`](datatypes/keypoint_pair.md): A connection between two `Keypoints`. * [`Mat3x3`](datatypes/mat3x3.md): A 3x3 Matrix. * [`Mat4x4`](datatypes/mat4x4.md): A 4x4 Matrix. -* [`Material`](datatypes/material.md): Material properties of a mesh, e.g. its color multiplier. * [`Quaternion`](datatypes/quaternion.md): A Quaternion represented by 4 real numbers. * [`Range1D`](datatypes/range1d.md): A 1D range, specifying a lower and upper bound. * [`Range2D`](datatypes/range2d.md): An Axis-Aligned Bounding Box in 2D space, implemented as the minimum and maximum corners. diff --git a/docs/content/reference/types/datatypes/.gitattributes b/docs/content/reference/types/datatypes/.gitattributes index 7d1b1d3b2927f..a3a5dab9758d2 100644 --- a/docs/content/reference/types/datatypes/.gitattributes +++ b/docs/content/reference/types/datatypes/.gitattributes @@ -13,7 +13,6 @@ keypoint_id.md linguist-generated=true keypoint_pair.md linguist-generated=true mat3x3.md linguist-generated=true mat4x4.md linguist-generated=true -material.md linguist-generated=true quaternion.md linguist-generated=true range1d.md linguist-generated=true range2d.md linguist-generated=true diff --git a/docs/content/reference/types/datatypes/material.md b/docs/content/reference/types/datatypes/material.md deleted file mode 100644 index 32d03bc0ac5ea..0000000000000 --- a/docs/content/reference/types/datatypes/material.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "Material" ---- - - -Material properties of a mesh, e.g. its color multiplier. - -## Fields - -* albedo_factor: [`Rgba32`](../datatypes/rgba32.md) - -## API reference links - * 🌊 [C++ API docs for `Material`](https://ref.rerun.io/docs/cpp/stable/structrerun_1_1datatypes_1_1Material.html) - * 🐍 [Python API docs for `Material`](https://ref.rerun.io/docs/python/stable/common/datatypes#rerun.datatypes.Material) - * πŸ¦€ [Rust API docs for `Material`](https://docs.rs/rerun/latest/rerun/datatypes/struct.Material.html) - - -## Used by - -* [`Material`](../components/material.md) diff --git a/docs/content/reference/types/datatypes/rgba32.md b/docs/content/reference/types/datatypes/rgba32.md index c8e9fb53dca91..6ed57e991d5a7 100644 --- a/docs/content/reference/types/datatypes/rgba32.md +++ b/docs/content/reference/types/datatypes/rgba32.md @@ -20,6 +20,6 @@ byte is `R` and the least significant byte is `A`. ## Used by +* [`AlbedoFactor`](../components/albedo_factor.md) * [`AnnotationInfo`](../datatypes/annotation_info.md) * [`Color`](../components/color.md) -* [`Material`](../datatypes/material.md) diff --git a/examples/python/raw_mesh/README.md b/examples/python/raw_mesh/README.md index c0a6d1ac607f5..65e4646a96dd7 100644 --- a/examples/python/raw_mesh/README.md +++ b/examples/python/raw_mesh/README.md @@ -42,7 +42,7 @@ rr.log( vertex_texcoords=vertex_texcoords, albedo_texture=albedo_texture, triangle_indices=mesh.faces, - mesh_material=mesh_material, + albedo_factor=albedo_factor, ), ) ``` diff --git a/examples/python/raw_mesh/raw_mesh/__main__.py b/examples/python/raw_mesh/raw_mesh/__main__.py index dfbd0590b531f..e929e107e24d6 100755 --- a/examples/python/raw_mesh/raw_mesh/__main__.py +++ b/examples/python/raw_mesh/raw_mesh/__main__.py @@ -11,7 +11,7 @@ import rerun as rr # pip install rerun-sdk import rerun.blueprint as rrb import trimesh -from rerun.components import Material +from rerun.components import AlbedoFactor from .download_dataset import AVAILABLE_MESHES, ensure_mesh_downloaded @@ -56,7 +56,7 @@ def log_scene(scene: trimesh.Scene, node: str, path: str | None = None) -> None: if mesh is not None: vertex_colors = None vertex_texcoords = None - mesh_material = None + albedo_factor = None albedo_texture = None try: @@ -78,7 +78,7 @@ def log_scene(scene: trimesh.Scene, node: str, path: str | None = None) -> None: if len(colors) == 4: # If trimesh gives us a single vertex color for the entire mesh, we can interpret that # as an albedo factor for the whole primitive. - mesh_material = Material(albedo_factor=np.array(colors)) + albedo_factor = np.array(colors) else: vertex_colors = colors except Exception: @@ -93,7 +93,7 @@ def log_scene(scene: trimesh.Scene, node: str, path: str | None = None) -> None: vertex_texcoords=vertex_texcoords, albedo_texture=albedo_texture, triangle_indices=mesh.faces, - mesh_material=mesh_material, + albedo_factor=albedo_factor, ), ) diff --git a/examples/python/ros_node/rerun_urdf.py b/examples/python/ros_node/rerun_urdf.py index e9012ae7cfd13..57c071de4dae0 100644 --- a/examples/python/ros_node/rerun_urdf.py +++ b/examples/python/ros_node/rerun_urdf.py @@ -54,11 +54,11 @@ def log_scene(scene: trimesh.Scene, node: str, path: str | None = None, static: if mesh: # If vertex colors are set, use the average color as the albedo factor # for the whole mesh. - vertex_colors = None + mean_vertex_color = None try: colors = np.mean(mesh.visual.vertex_colors, axis=0) if len(colors) == 4: - vertex_colors = np.array(colors) / 255.0 + mean_vertex_color = np.array(colors) / 255.0 except Exception: pass @@ -72,7 +72,7 @@ def log_scene(scene: trimesh.Scene, node: str, path: str | None = None, static: except Exception: pass - albedo_factor = vertex_colors if vertex_colors is not None else visual_color + albedo_factor = mean_vertex_color or visual_color rr.log( path, @@ -80,7 +80,7 @@ def log_scene(scene: trimesh.Scene, node: str, path: str | None = None, static: vertex_positions=mesh.vertices, triangle_indices=mesh.faces, vertex_normals=mesh.vertex_normals, - mesh_material=rr.Material(albedo_factor=albedo_factor), + albedo_factor=albedo_factor, ), static=static, ) diff --git a/examples/rust/raw_mesh/src/main.rs b/examples/rust/raw_mesh/src/main.rs index 1674a427a48c2..17489991d3a48 100644 --- a/examples/rust/raw_mesh/src/main.rs +++ b/examples/rust/raw_mesh/src/main.rs @@ -14,7 +14,7 @@ use bytes::Bytes; use rerun::{ components::Transform3D, external::{ecolor, re_log}, - Color, Mesh3D, RecordingStream, + Color, Mesh3D, RecordingStream, Rgba32, }; // TODO(cmc): This example needs to support animations to showcase Rerun's time capabilities. @@ -51,10 +51,7 @@ impl From for Mesh3D { mesh = mesh.with_vertex_texcoords(vertex_texcoords); } if albedo_factor.is_some() { - mesh = mesh.with_mesh_material(rerun::datatypes::Material { - albedo_factor: albedo_factor - .map(|[r, g, b, a]| ecolor::Rgba::from_rgba_unmultiplied(r, g, b, a).into()), - }); + mesh = mesh.with_albedo_factor(Rgba32::from_unmultiplied_rgba(r, g, b, a).into()); } mesh.sanity_check().unwrap(); diff --git a/rerun_cpp/src/rerun.hpp b/rerun_cpp/src/rerun.hpp index 803682896285f..2ef9115d109e7 100644 --- a/rerun_cpp/src/rerun.hpp +++ b/rerun_cpp/src/rerun.hpp @@ -29,12 +29,12 @@ namespace rerun { using namespace archetypes; // Also import any component or datatype that has a unique name: + using components::AlbedoFactor; using components::Color; using components::HalfSize2D; using components::HalfSize3D; using components::LineStrip2D; using components::LineStrip3D; - using components::Material; using components::MediaType; using components::OutOfTreeTransform3D; using components::Position2D; diff --git a/rerun_cpp/src/rerun/archetypes/mesh3d.cpp b/rerun_cpp/src/rerun/archetypes/mesh3d.cpp index 65beb892deda1..e8c46900da4f0 100644 --- a/rerun_cpp/src/rerun/archetypes/mesh3d.cpp +++ b/rerun_cpp/src/rerun/archetypes/mesh3d.cpp @@ -41,8 +41,8 @@ namespace rerun { RR_RETURN_NOT_OK(result.error); cells.push_back(std::move(result.value)); } - if (archetype.mesh_material.has_value()) { - auto result = DataCell::from_loggable(archetype.mesh_material.value()); + if (archetype.albedo_factor.has_value()) { + auto result = DataCell::from_loggable(archetype.albedo_factor.value()); RR_RETURN_NOT_OK(result.error); cells.push_back(std::move(result.value)); } diff --git a/rerun_cpp/src/rerun/archetypes/mesh3d.hpp b/rerun_cpp/src/rerun/archetypes/mesh3d.hpp index 8ed4db0397224..fb977af0e8a40 100644 --- a/rerun_cpp/src/rerun/archetypes/mesh3d.hpp +++ b/rerun_cpp/src/rerun/archetypes/mesh3d.hpp @@ -5,9 +5,9 @@ #include "../collection.hpp" #include "../compiler_utils.hpp" +#include "../components/albedo_factor.hpp" #include "../components/class_id.hpp" #include "../components/color.hpp" -#include "../components/material.hpp" #include "../components/position3d.hpp" #include "../components/tensor_data.hpp" #include "../components/texcoord2d.hpp" @@ -77,8 +77,8 @@ namespace rerun::archetypes { /// An optional uv texture coordinate for each vertex. std::optional> vertex_texcoords; - /// Optional material properties for the mesh as a whole. - std::optional mesh_material; + /// A color multiplier applied to the whole mesh. + std::optional albedo_factor; /// Optional albedo texture. /// @@ -136,9 +136,9 @@ namespace rerun::archetypes { RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } - /// Optional material properties for the mesh as a whole. - Mesh3D with_mesh_material(rerun::components::Material _mesh_material) && { - mesh_material = std::move(_mesh_material); + /// A color multiplier applied to the whole mesh. + Mesh3D with_albedo_factor(rerun::components::AlbedoFactor _albedo_factor) && { + albedo_factor = std::move(_albedo_factor); // See: https://github.com/rerun-io/rerun/issues/4027 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);) } diff --git a/rerun_cpp/src/rerun/components.hpp b/rerun_cpp/src/rerun/components.hpp index 051d6be94addd..2613da9217b6f 100644 --- a/rerun_cpp/src/rerun/components.hpp +++ b/rerun_cpp/src/rerun/components.hpp @@ -3,6 +3,7 @@ #pragma once #include "components/aggregation_policy.hpp" +#include "components/albedo_factor.hpp" #include "components/annotation_context.hpp" #include "components/axis_length.hpp" #include "components/blob.hpp" @@ -24,7 +25,6 @@ #include "components/magnification_filter.hpp" #include "components/marker_shape.hpp" #include "components/marker_size.hpp" -#include "components/material.hpp" #include "components/media_type.hpp" #include "components/name.hpp" #include "components/opacity.hpp" diff --git a/rerun_cpp/src/rerun/components/.gitattributes b/rerun_cpp/src/rerun/components/.gitattributes index 86cdb7e361ec7..cce11bf85a87f 100644 --- a/rerun_cpp/src/rerun/components/.gitattributes +++ b/rerun_cpp/src/rerun/components/.gitattributes @@ -3,6 +3,7 @@ .gitattributes linguist-generated=true aggregation_policy.cpp linguist-generated=true aggregation_policy.hpp linguist-generated=true +albedo_factor.hpp linguist-generated=true annotation_context.cpp linguist-generated=true annotation_context.hpp linguist-generated=true axis_length.hpp linguist-generated=true @@ -36,7 +37,6 @@ marker_shape.cpp linguist-generated=true marker_shape.hpp linguist-generated=true marker_size.cpp linguist-generated=true marker_size.hpp linguist-generated=true -material.hpp linguist-generated=true media_type.hpp linguist-generated=true name.hpp linguist-generated=true opacity.hpp linguist-generated=true diff --git a/rerun_cpp/src/rerun/components/albedo_factor.hpp b/rerun_cpp/src/rerun/components/albedo_factor.hpp new file mode 100644 index 0000000000000..0e0d0247b9a6e --- /dev/null +++ b/rerun_cpp/src/rerun/components/albedo_factor.hpp @@ -0,0 +1,64 @@ +// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs +// Based on "crates/store/re_types/definitions/rerun/components/albedo_factor.fbs". + +#pragma once + +#include "../datatypes/rgba32.hpp" +#include "../result.hpp" + +#include +#include + +namespace rerun::components { + /// **Component**: A color multiplier, usually applied to a whole entity, e.g. a mesh. + struct AlbedoFactor { + rerun::datatypes::Rgba32 albedo_factor; + + public: + AlbedoFactor() = default; + + AlbedoFactor(rerun::datatypes::Rgba32 albedo_factor_) : albedo_factor(albedo_factor_) {} + + AlbedoFactor& operator=(rerun::datatypes::Rgba32 albedo_factor_) { + albedo_factor = albedo_factor_; + return *this; + } + + AlbedoFactor(uint32_t rgba_) : albedo_factor(rgba_) {} + + AlbedoFactor& operator=(uint32_t rgba_) { + albedo_factor = rgba_; + return *this; + } + + /// Cast to the underlying Rgba32 datatype + operator rerun::datatypes::Rgba32() const { + return albedo_factor; + } + }; +} // namespace rerun::components + +namespace rerun { + static_assert(sizeof(rerun::datatypes::Rgba32) == sizeof(components::AlbedoFactor)); + + /// \private + template <> + struct Loggable { + static constexpr const char Name[] = "rerun.components.AlbedoFactor"; + + /// Returns the arrow data type this type corresponds to. + static const std::shared_ptr& arrow_datatype() { + return Loggable::arrow_datatype(); + } + + /// Serializes an array of `rerun::components::AlbedoFactor` into an arrow array. + static Result> to_arrow( + const components::AlbedoFactor* instances, size_t num_instances + ) { + return Loggable::to_arrow( + &instances->albedo_factor, + num_instances + ); + } + }; +} // namespace rerun diff --git a/rerun_cpp/src/rerun/components/material.hpp b/rerun_cpp/src/rerun/components/material.hpp deleted file mode 100644 index 70c3e07a1192d..0000000000000 --- a/rerun_cpp/src/rerun/components/material.hpp +++ /dev/null @@ -1,74 +0,0 @@ -// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs -// Based on "crates/store/re_types/definitions/rerun/components/material.fbs". - -#pragma once - -#include "../datatypes/material.hpp" -#include "../datatypes/rgba32.hpp" -#include "../result.hpp" - -#include -#include -#include - -namespace rerun::components { - /// **Component**: Material properties of a mesh, e.g. its color multiplier. - struct Material { - rerun::datatypes::Material material; - - public: - // Extensions to generated type defined in 'material_ext.cpp' - - static Material from_albedo_factor(rerun::datatypes::Rgba32 color) { - return Material(color); - } - - public: - Material() = default; - - Material(rerun::datatypes::Material material_) : material(material_) {} - - Material& operator=(rerun::datatypes::Material material_) { - material = material_; - return *this; - } - - Material(std::optional albedo_factor_) - : material(albedo_factor_) {} - - Material& operator=(std::optional albedo_factor_) { - material = albedo_factor_; - return *this; - } - - /// Cast to the underlying Material datatype - operator rerun::datatypes::Material() const { - return material; - } - }; -} // namespace rerun::components - -namespace rerun { - static_assert(sizeof(rerun::datatypes::Material) == sizeof(components::Material)); - - /// \private - template <> - struct Loggable { - static constexpr const char Name[] = "rerun.components.Material"; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype() { - return Loggable::arrow_datatype(); - } - - /// Serializes an array of `rerun::components::Material` into an arrow array. - static Result> to_arrow( - const components::Material* instances, size_t num_instances - ) { - return Loggable::to_arrow( - &instances->material, - num_instances - ); - } - }; -} // namespace rerun diff --git a/rerun_cpp/src/rerun/components/material_ext.cpp b/rerun_cpp/src/rerun/components/material_ext.cpp deleted file mode 100644 index ed321d39f547f..0000000000000 --- a/rerun_cpp/src/rerun/components/material_ext.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "material.hpp" - -// Uncomment for better auto-complete while editing the extension. -// #define EDIT_EXTENSION - -namespace rerun { - namespace components { - -#ifdef EDIT_EXTENSION - struct MaterialExt { -#define Material MaterialExt - - // - - static Material from_albedo_factor(rerun::datatypes::Rgba32 color) { - return Material(color); - } - - // - }; -#endif - } // namespace components -} // namespace rerun diff --git a/rerun_cpp/src/rerun/datatypes.hpp b/rerun_cpp/src/rerun/datatypes.hpp index 9c7e07bc45980..1aefeecbe844a 100644 --- a/rerun_cpp/src/rerun/datatypes.hpp +++ b/rerun_cpp/src/rerun/datatypes.hpp @@ -14,7 +14,6 @@ #include "datatypes/keypoint_pair.hpp" #include "datatypes/mat3x3.hpp" #include "datatypes/mat4x4.hpp" -#include "datatypes/material.hpp" #include "datatypes/quaternion.hpp" #include "datatypes/range1d.hpp" #include "datatypes/range2d.hpp" diff --git a/rerun_cpp/src/rerun/datatypes/.gitattributes b/rerun_cpp/src/rerun/datatypes/.gitattributes index bf5f7a01f10db..037ce0dd4f0ed 100644 --- a/rerun_cpp/src/rerun/datatypes/.gitattributes +++ b/rerun_cpp/src/rerun/datatypes/.gitattributes @@ -25,8 +25,6 @@ mat3x3.cpp linguist-generated=true mat3x3.hpp linguist-generated=true mat4x4.cpp linguist-generated=true mat4x4.hpp linguist-generated=true -material.cpp linguist-generated=true -material.hpp linguist-generated=true quaternion.cpp linguist-generated=true quaternion.hpp linguist-generated=true range1d.cpp linguist-generated=true diff --git a/rerun_cpp/src/rerun/datatypes/material.cpp b/rerun_cpp/src/rerun/datatypes/material.cpp deleted file mode 100644 index a212b33c5313e..0000000000000 --- a/rerun_cpp/src/rerun/datatypes/material.cpp +++ /dev/null @@ -1,78 +0,0 @@ -// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs -// Based on "crates/store/re_types/definitions/rerun/datatypes/material.fbs". - -#include "material.hpp" - -#include "rgba32.hpp" - -#include -#include - -namespace rerun::datatypes {} - -namespace rerun { - const std::shared_ptr& Loggable::arrow_datatype() { - static const auto datatype = arrow::struct_({ - arrow::field( - "albedo_factor", - Loggable::arrow_datatype(), - true - ), - }); - return datatype; - } - - Result> Loggable::to_arrow( - const datatypes::Material* instances, size_t num_instances - ) { - // TODO(andreas): Allow configuring the memory pool. - arrow::MemoryPool* pool = arrow::default_memory_pool(); - auto datatype = arrow_datatype(); - - ARROW_ASSIGN_OR_RAISE(auto builder, arrow::MakeBuilder(datatype, pool)) - if (instances && num_instances > 0) { - RR_RETURN_NOT_OK(Loggable::fill_arrow_array_builder( - static_cast(builder.get()), - instances, - num_instances - )); - } - std::shared_ptr array; - ARROW_RETURN_NOT_OK(builder->Finish(&array)); - return array; - } - - rerun::Error Loggable::fill_arrow_array_builder( - arrow::StructBuilder* builder, const datatypes::Material* elements, size_t num_elements - ) { - if (builder == nullptr) { - return rerun::Error(ErrorCode::UnexpectedNullArgument, "Passed array builder is null."); - } - if (elements == nullptr) { - return rerun::Error( - ErrorCode::UnexpectedNullArgument, - "Cannot serialize null pointer to arrow array." - ); - } - - { - auto field_builder = static_cast(builder->field_builder(0)); - ARROW_RETURN_NOT_OK(field_builder->Reserve(static_cast(num_elements))); - for (size_t elem_idx = 0; elem_idx < num_elements; elem_idx += 1) { - const auto& element = elements[elem_idx]; - if (element.albedo_factor.has_value()) { - RR_RETURN_NOT_OK(Loggable::fill_arrow_array_builder( - field_builder, - &element.albedo_factor.value(), - 1 - )); - } else { - ARROW_RETURN_NOT_OK(field_builder->AppendNull()); - } - } - } - ARROW_RETURN_NOT_OK(builder->AppendValues(static_cast(num_elements), nullptr)); - - return Error::ok(); - } -} // namespace rerun diff --git a/rerun_cpp/src/rerun/datatypes/material.hpp b/rerun_cpp/src/rerun/datatypes/material.hpp deleted file mode 100644 index b2492e0244b35..0000000000000 --- a/rerun_cpp/src/rerun/datatypes/material.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs -// Based on "crates/store/re_types/definitions/rerun/datatypes/material.fbs". - -#pragma once - -#include "../result.hpp" -#include "rgba32.hpp" - -#include -#include -#include - -namespace arrow { - class Array; - class DataType; - class StructBuilder; -} // namespace arrow - -namespace rerun::datatypes { - /// **Datatype**: Material properties of a mesh, e.g. its color multiplier. - struct Material { - /// Optional color multiplier. - std::optional albedo_factor; - - public: - Material() = default; - - Material(std::optional albedo_factor_) - : albedo_factor(albedo_factor_) {} - - Material& operator=(std::optional albedo_factor_) { - albedo_factor = albedo_factor_; - return *this; - } - - Material(uint32_t rgba_) : albedo_factor(rgba_) {} - - Material& operator=(uint32_t rgba_) { - albedo_factor = rgba_; - return *this; - } - }; -} // namespace rerun::datatypes - -namespace rerun { - template - struct Loggable; - - /// \private - template <> - struct Loggable { - static constexpr const char Name[] = "rerun.datatypes.Material"; - - /// Returns the arrow data type this type corresponds to. - static const std::shared_ptr& arrow_datatype(); - - /// Serializes an array of `rerun::datatypes::Material` into an arrow array. - static Result> to_arrow( - const datatypes::Material* instances, size_t num_instances - ); - - /// Fills an arrow array builder with an array of this type. - static rerun::Error fill_arrow_array_builder( - arrow::StructBuilder* builder, const datatypes::Material* elements, size_t num_elements - ); - }; -} // namespace rerun diff --git a/rerun_cpp/tests/archetypes/mesh3d.cpp b/rerun_cpp/tests/archetypes/mesh3d.cpp index 34e0d8c21f6d7..8c7d05787fbae 100644 --- a/rerun_cpp/tests/archetypes/mesh3d.cpp +++ b/rerun_cpp/tests/archetypes/mesh3d.cpp @@ -18,21 +18,15 @@ SCENARIO( .with_vertex_normals({{4.0, 5.0, 6.0}, {40.0, 50.0, 60.0}}) .with_vertex_colors({{0xAA, 0x00, 0x00, 0xCC}, {0x00, 0xBB, 0x00, 0xDD}}) .with_triangle_indices({{1, 2, 3}, {4, 5, 6}}) - .with_mesh_material(Material::from_albedo_factor(0xEE112233)) + .with_albedo_factor(0xEE112233) .with_class_ids({126, 127}); - rerun::datatypes::Material mesh_material_inner_manual; - mesh_material_inner_manual.albedo_factor = {0xEE, 0x11, 0x22, 0x33}; - - Material mesh_material_manual; - mesh_material_manual.material = mesh_material_inner_manual; - Mesh3D from_manual; from_manual.vertex_positions = {{1.0, 2.0, 3.0}, {10.0, 20.0, 30.0}}; from_manual.vertex_normals = {{4.0, 5.0, 6.0}, {40.0, 50.0, 60.0}}; from_manual.vertex_colors = {{0xAA, 0x00, 0x00, 0xCC}, {0x00, 0xBB, 0x00, 0xDD}}; from_manual.triangle_indices = {{1, 2, 3}, {4, 5, 6}}; - from_manual.mesh_material = {mesh_material_manual}; + from_manual.albedo_factor = {0xEE, 0x11, 0x22, 0x33}; from_manual.class_ids = {126, 127}; test_compare_archetype_serialization(from_manual, from_builder); diff --git a/rerun_py/rerun_sdk/rerun/__init__.py b/rerun_py/rerun_sdk/rerun/__init__.py index 77c4223e6fd1c..fb91da4e20b74 100644 --- a/rerun_py/rerun_sdk/rerun/__init__.py +++ b/rerun_py/rerun_sdk/rerun/__init__.py @@ -72,7 +72,7 @@ BlueprintLike as BlueprintLike, ) from .components import ( - Material as Material, + AlbedoFactor as AlbedoFactor, MediaType as MediaType, OutOfTreeTransform3D as OutOfTreeTransform3D, OutOfTreeTransform3DBatch as OutOfTreeTransform3DBatch, diff --git a/rerun_py/rerun_sdk/rerun/archetypes/mesh3d.py b/rerun_py/rerun_sdk/rerun/archetypes/mesh3d.py index e7619d5e60f0c..c3b1c2090049a 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/mesh3d.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/mesh3d.py @@ -63,7 +63,7 @@ def __attrs_clear__(self) -> None: vertex_normals=None, # type: ignore[arg-type] vertex_colors=None, # type: ignore[arg-type] vertex_texcoords=None, # type: ignore[arg-type] - mesh_material=None, # type: ignore[arg-type] + albedo_factor=None, # type: ignore[arg-type] albedo_texture=None, # type: ignore[arg-type] class_ids=None, # type: ignore[arg-type] ) @@ -121,12 +121,12 @@ def _clear(cls) -> Mesh3D: # # (Docstring intentionally commented out to hide this field from the docs) - mesh_material: components.MaterialBatch | None = field( + albedo_factor: components.AlbedoFactorBatch | None = field( metadata={"component": "optional"}, default=None, - converter=components.MaterialBatch._optional, # type: ignore[misc] + converter=components.AlbedoFactorBatch._optional, # type: ignore[misc] ) - # Optional material properties for the mesh as a whole. + # A color multiplier applied to the whole mesh. # # (Docstring intentionally commented out to hide this field from the docs) diff --git a/rerun_py/rerun_sdk/rerun/archetypes/mesh3d_ext.py b/rerun_py/rerun_sdk/rerun/archetypes/mesh3d_ext.py index 6329b528dd245..812eb503d3423 100644 --- a/rerun_py/rerun_sdk/rerun/archetypes/mesh3d_ext.py +++ b/rerun_py/rerun_sdk/rerun/archetypes/mesh3d_ext.py @@ -18,7 +18,7 @@ def __init__( vertex_colors: datatypes.Rgba32ArrayLike | None = None, vertex_texcoords: datatypes.Vec2DArrayLike | None = None, albedo_texture: datatypes.TensorDataLike | None = None, - mesh_material: datatypes.MaterialLike | None = None, + albedo_factor: datatypes.Rgba32Like | None = None, class_ids: datatypes.ClassIdArrayLike | None = None, ): """ @@ -39,8 +39,8 @@ def __init__( If specified, this must have as many elements as `vertex_positions`. vertex_colors: An optional color for each vertex. - mesh_material: - Optional material properties for the mesh as a whole. + albedo_factor: + Optional color multiplier for the whole mesh albedo_texture: Optional albedo texture. Used with `vertex_texcoords` on `Mesh3D`. Currently supports only sRGB(A) textures, ignoring alpha. @@ -58,7 +58,7 @@ def __init__( vertex_colors=vertex_colors, vertex_texcoords=vertex_texcoords, albedo_texture=albedo_texture, - mesh_material=mesh_material, + albedo_factor=albedo_factor, class_ids=class_ids, ) return diff --git a/rerun_py/rerun_sdk/rerun/components/.gitattributes b/rerun_py/rerun_sdk/rerun/components/.gitattributes index c83b49339b017..f0dc6e6593002 100644 --- a/rerun_py/rerun_sdk/rerun/components/.gitattributes +++ b/rerun_py/rerun_sdk/rerun/components/.gitattributes @@ -3,6 +3,7 @@ .gitattributes linguist-generated=true __init__.py linguist-generated=true aggregation_policy.py linguist-generated=true +albedo_factor.py linguist-generated=true annotation_context.py linguist-generated=true axis_length.py linguist-generated=true blob.py linguist-generated=true @@ -24,7 +25,6 @@ line_strip3d.py linguist-generated=true magnification_filter.py linguist-generated=true marker_shape.py linguist-generated=true marker_size.py linguist-generated=true -material.py linguist-generated=true media_type.py linguist-generated=true name.py linguist-generated=true opacity.py linguist-generated=true diff --git a/rerun_py/rerun_sdk/rerun/components/__init__.py b/rerun_py/rerun_sdk/rerun/components/__init__.py index 54e493b75d7af..30f169b82b42b 100644 --- a/rerun_py/rerun_sdk/rerun/components/__init__.py +++ b/rerun_py/rerun_sdk/rerun/components/__init__.py @@ -9,6 +9,7 @@ AggregationPolicyLike, AggregationPolicyType, ) +from .albedo_factor import AlbedoFactor, AlbedoFactorBatch, AlbedoFactorType from .annotation_context import ( AnnotationContext, AnnotationContextArrayLike, @@ -54,7 +55,6 @@ ) from .marker_shape import MarkerShape, MarkerShapeArrayLike, MarkerShapeBatch, MarkerShapeLike, MarkerShapeType from .marker_size import MarkerSize, MarkerSizeArrayLike, MarkerSizeBatch, MarkerSizeLike, MarkerSizeType -from .material import Material, MaterialBatch, MaterialType from .media_type import MediaType, MediaTypeBatch, MediaTypeType from .name import Name, NameBatch, NameType from .opacity import Opacity, OpacityBatch, OpacityType @@ -97,6 +97,9 @@ "AggregationPolicyBatch", "AggregationPolicyLike", "AggregationPolicyType", + "AlbedoFactor", + "AlbedoFactorBatch", + "AlbedoFactorType", "AnnotationContext", "AnnotationContextArrayLike", "AnnotationContextBatch", @@ -184,9 +187,6 @@ "MarkerSizeBatch", "MarkerSizeLike", "MarkerSizeType", - "Material", - "MaterialBatch", - "MaterialType", "MediaType", "MediaTypeBatch", "MediaTypeType", diff --git a/rerun_py/rerun_sdk/rerun/components/albedo_factor.py b/rerun_py/rerun_sdk/rerun/components/albedo_factor.py new file mode 100644 index 0000000000000..f0b8a7d0173ce --- /dev/null +++ b/rerun_py/rerun_sdk/rerun/components/albedo_factor.py @@ -0,0 +1,36 @@ +# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs +# Based on "crates/store/re_types/definitions/rerun/components/albedo_factor.fbs". + +# You can extend this class by creating a "AlbedoFactorExt" class in "albedo_factor_ext.py". + +from __future__ import annotations + +from .. import datatypes +from .._baseclasses import ( + ComponentBatchMixin, + ComponentMixin, +) + +__all__ = ["AlbedoFactor", "AlbedoFactorBatch", "AlbedoFactorType"] + + +class AlbedoFactor(datatypes.Rgba32, ComponentMixin): + """**Component**: A color multiplier, usually applied to a whole entity, e.g. a mesh.""" + + _BATCH_TYPE = None + # You can define your own __init__ function as a member of AlbedoFactorExt in albedo_factor_ext.py + + # Note: there are no fields here because AlbedoFactor delegates to datatypes.Rgba32 + pass + + +class AlbedoFactorType(datatypes.Rgba32Type): + _TYPE_NAME: str = "rerun.components.AlbedoFactor" + + +class AlbedoFactorBatch(datatypes.Rgba32Batch, ComponentBatchMixin): + _ARROW_TYPE = AlbedoFactorType() + + +# This is patched in late to avoid circular dependencies. +AlbedoFactor._BATCH_TYPE = AlbedoFactorBatch # type: ignore[assignment] diff --git a/rerun_py/rerun_sdk/rerun/components/material.py b/rerun_py/rerun_sdk/rerun/components/material.py deleted file mode 100644 index a88785ed53336..0000000000000 --- a/rerun_py/rerun_sdk/rerun/components/material.py +++ /dev/null @@ -1,36 +0,0 @@ -# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs -# Based on "crates/store/re_types/definitions/rerun/components/material.fbs". - -# You can extend this class by creating a "MaterialExt" class in "material_ext.py". - -from __future__ import annotations - -from .. import datatypes -from .._baseclasses import ( - ComponentBatchMixin, - ComponentMixin, -) - -__all__ = ["Material", "MaterialBatch", "MaterialType"] - - -class Material(datatypes.Material, ComponentMixin): - """**Component**: Material properties of a mesh, e.g. its color multiplier.""" - - _BATCH_TYPE = None - # You can define your own __init__ function as a member of MaterialExt in material_ext.py - - # Note: there are no fields here because Material delegates to datatypes.Material - pass - - -class MaterialType(datatypes.MaterialType): - _TYPE_NAME: str = "rerun.components.Material" - - -class MaterialBatch(datatypes.MaterialBatch, ComponentBatchMixin): - _ARROW_TYPE = MaterialType() - - -# This is patched in late to avoid circular dependencies. -Material._BATCH_TYPE = MaterialBatch # type: ignore[assignment] diff --git a/rerun_py/rerun_sdk/rerun/datatypes/.gitattributes b/rerun_py/rerun_sdk/rerun/datatypes/.gitattributes index 5785b817bb751..537e676c3cf16 100644 --- a/rerun_py/rerun_sdk/rerun/datatypes/.gitattributes +++ b/rerun_py/rerun_sdk/rerun/datatypes/.gitattributes @@ -14,7 +14,6 @@ keypoint_id.py linguist-generated=true keypoint_pair.py linguist-generated=true mat3x3.py linguist-generated=true mat4x4.py linguist-generated=true -material.py linguist-generated=true quaternion.py linguist-generated=true range1d.py linguist-generated=true range2d.py linguist-generated=true diff --git a/rerun_py/rerun_sdk/rerun/datatypes/__init__.py b/rerun_py/rerun_sdk/rerun/datatypes/__init__.py index 9b6bb1f148a53..2f5747e8ff39c 100644 --- a/rerun_py/rerun_sdk/rerun/datatypes/__init__.py +++ b/rerun_py/rerun_sdk/rerun/datatypes/__init__.py @@ -32,7 +32,6 @@ from .keypoint_pair import KeypointPair, KeypointPairArrayLike, KeypointPairBatch, KeypointPairLike, KeypointPairType from .mat3x3 import Mat3x3, Mat3x3ArrayLike, Mat3x3Batch, Mat3x3Like, Mat3x3Type from .mat4x4 import Mat4x4, Mat4x4ArrayLike, Mat4x4Batch, Mat4x4Like, Mat4x4Type -from .material import Material, MaterialArrayLike, MaterialBatch, MaterialLike, MaterialType from .quaternion import Quaternion, QuaternionArrayLike, QuaternionBatch, QuaternionLike, QuaternionType from .range1d import Range1D, Range1DArrayLike, Range1DBatch, Range1DLike, Range1DType from .range2d import Range2D, Range2DArrayLike, Range2DBatch, Range2DLike, Range2DType @@ -172,11 +171,6 @@ "Mat4x4Batch", "Mat4x4Like", "Mat4x4Type", - "Material", - "MaterialArrayLike", - "MaterialBatch", - "MaterialLike", - "MaterialType", "Quaternion", "QuaternionArrayLike", "QuaternionBatch", diff --git a/rerun_py/rerun_sdk/rerun/datatypes/material.py b/rerun_py/rerun_sdk/rerun/datatypes/material.py deleted file mode 100644 index 77ed8127a9715..0000000000000 --- a/rerun_py/rerun_sdk/rerun/datatypes/material.py +++ /dev/null @@ -1,81 +0,0 @@ -# DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/python/mod.rs -# Based on "crates/store/re_types/definitions/rerun/datatypes/material.fbs". - -# You can extend this class by creating a "MaterialExt" class in "material_ext.py". - -from __future__ import annotations - -from typing import Any, Sequence, Union - -import pyarrow as pa -from attrs import define, field - -from .. import datatypes -from .._baseclasses import ( - BaseBatch, - BaseExtensionType, -) -from .material_ext import MaterialExt - -__all__ = ["Material", "MaterialArrayLike", "MaterialBatch", "MaterialLike", "MaterialType"] - - -def _material__albedo_factor__special_field_converter_override( - x: datatypes.Rgba32Like | None, -) -> datatypes.Rgba32 | None: - if x is None: - return None - elif isinstance(x, datatypes.Rgba32): - return x - else: - return datatypes.Rgba32(x) - - -@define(init=False) -class Material(MaterialExt): - """**Datatype**: Material properties of a mesh, e.g. its color multiplier.""" - - def __init__(self: Any, albedo_factor: datatypes.Rgba32Like | None = None): - """ - Create a new instance of the Material datatype. - - Parameters - ---------- - albedo_factor: - Optional color multiplier. - - """ - - # You can define your own __init__ function as a member of MaterialExt in material_ext.py - self.__attrs_init__(albedo_factor=albedo_factor) - - albedo_factor: datatypes.Rgba32 | None = field( - default=None, converter=_material__albedo_factor__special_field_converter_override - ) - # Optional color multiplier. - # - # (Docstring intentionally commented out to hide this field from the docs) - - -MaterialLike = Material -MaterialArrayLike = Union[ - Material, - Sequence[MaterialLike], -] - - -class MaterialType(BaseExtensionType): - _TYPE_NAME: str = "rerun.datatypes.Material" - - def __init__(self) -> None: - pa.ExtensionType.__init__( - self, pa.struct([pa.field("albedo_factor", pa.uint32(), nullable=True, metadata={})]), self._TYPE_NAME - ) - - -class MaterialBatch(BaseBatch[MaterialArrayLike]): - _ARROW_TYPE = MaterialType() - - @staticmethod - def _native_to_pa_array(data: MaterialArrayLike, data_type: pa.DataType) -> pa.Array: - return MaterialExt.native_to_pa_array_override(data, data_type) diff --git a/rerun_py/rerun_sdk/rerun/datatypes/material_ext.py b/rerun_py/rerun_sdk/rerun/datatypes/material_ext.py deleted file mode 100644 index 1771142c3c842..0000000000000 --- a/rerun_py/rerun_sdk/rerun/datatypes/material_ext.py +++ /dev/null @@ -1,31 +0,0 @@ -from __future__ import annotations - -from typing import TYPE_CHECKING - -import pyarrow as pa - -if TYPE_CHECKING: - from . import MaterialArrayLike - - -class MaterialExt: - """Extension for [Material][rerun.datatypes.Material].""" - - @staticmethod - def native_to_pa_array_override(data: MaterialArrayLike, data_type: pa.DataType) -> pa.Array: - from . import Material, Rgba32Type - - if isinstance(data, Material): - data = [data] - - field_albedo_factors = data_type.field("albedo_factor") - - albedo_factors = pa.array( - [datum.albedo_factor.rgba if datum.albedo_factor is not None else None for datum in data], - type=Rgba32Type().storage_type, - ) - - return pa.StructArray.from_arrays( - arrays=[albedo_factors], - fields=[field_albedo_factors], - ) diff --git a/rerun_py/tests/unit/test_mesh3d.py b/rerun_py/tests/unit/test_mesh3d.py index 7ccc1129da0f0..f65341df27fb8 100644 --- a/rerun_py/tests/unit/test_mesh3d.py +++ b/rerun_py/tests/unit/test_mesh3d.py @@ -7,9 +7,9 @@ from rerun.components import MaterialBatch, Position3DBatch, TriangleIndicesBatch, Vector3DBatch from rerun.components.texcoord2d import Texcoord2DBatch from rerun.datatypes import ( + Rgba32, + Rgba32Like, ClassIdArrayLike, - Material, - MaterialLike, Rgba32ArrayLike, UVec3DArrayLike, Vec2DArrayLike, @@ -30,14 +30,14 @@ vec3ds_expected, ) -mesh_materials: list[MaterialLike | None] = [ +albedo_factors: list[Rgba32Like | None] = [ None, - Material(albedo_factor=0xAA0000CC), + Rgba32(0xAA0000CC), ] -def mesh_material_expected(obj: Any) -> Any: - expected = none_empty_or_value(obj, Material(albedo_factor=0xAA0000CC)) +def albedo_factor_expected(obj: Any) -> Any: + expected = none_empty_or_value(obj, Rgba32(0xAA0000CC)) return MaterialBatch._optional(expected) @@ -55,7 +55,7 @@ def test_mesh3d() -> None: vertex_colors_arrays, vertex_texcoord_arrays, triangle_indices_arrays, - mesh_materials, + albedo_factors, class_ids_arrays, ) @@ -65,7 +65,7 @@ def test_mesh3d() -> None: vertex_colors, vertex_texcoords, triangle_indices, - mesh_material, + albedo_factor, class_ids, ) in all_arrays: vertex_positions = vertex_positions if vertex_positions is not None else vertex_positions_arrays[-1] @@ -76,7 +76,7 @@ def test_mesh3d() -> None: vertex_colors = cast(Optional[Rgba32ArrayLike], vertex_colors) vertex_texcoords = cast(Optional[Vec2DArrayLike], vertex_texcoords) triangle_indices = cast(Optional[UVec3DArrayLike], triangle_indices) - mesh_material = cast(Optional[MaterialLike], mesh_material) + albedo_factor = cast(Optional[Rgba32Like], albedo_factor) class_ids = cast(Optional[ClassIdArrayLike], class_ids) print( @@ -86,7 +86,7 @@ def test_mesh3d() -> None: f" vertex_colors={vertex_colors}\n" f" vertex_texcoords={vertex_texcoords}\n" f" triangle_indices={triangle_indices}\n" - f" mesh_material={mesh_material}\n" + f" albedo_factor={albedo_factor}\n" f" class_ids={class_ids}\n" f")" ) @@ -96,7 +96,7 @@ def test_mesh3d() -> None: vertex_colors=vertex_colors, vertex_texcoords=vertex_texcoords, triangle_indices=triangle_indices, - mesh_material=mesh_material, + albedo_factor=albedo_factor, class_ids=class_ids, ) print(f"A: {arch}\n") @@ -106,29 +106,9 @@ def test_mesh3d() -> None: assert arch.vertex_colors == colors_expected(vertex_colors) assert arch.vertex_texcoords == vec2ds_expected(vertex_texcoords, Texcoord2DBatch) assert arch.triangle_indices == uvec3ds_expected(triangle_indices, TriangleIndicesBatch) - assert arch.mesh_material == mesh_material_expected(mesh_material) + assert arch.albedo_factor == albedo_factor_expected(albedo_factor) assert arch.class_ids == class_ids_expected(class_ids) -def test_nullable_albedo_factor() -> None: - # NOTE: We're just making sure that this doesn't crash… trust me, it used to. - assert ( - len( - MaterialBatch([ - Material(albedo_factor=[0xCC, 0x00, 0xCC, 0xFF]), - ]) - ) - == 1 - ) - assert ( - len( - MaterialBatch([ - Material(), - ]) - ) - == 1 - ) - - if __name__ == "__main__": test_mesh3d() diff --git a/tests/python/release_checklist/check_all_components_ui.py b/tests/python/release_checklist/check_all_components_ui.py index faace78552207..47b2597be4155 100644 --- a/tests/python/release_checklist/check_all_components_ui.py +++ b/tests/python/release_checklist/check_all_components_ui.py @@ -76,6 +76,7 @@ def alternatives(self) -> list[Any] | None: ALL_COMPONENTS: dict[str, TestCase] = { "AggregationPolicyBatch": TestCase(rr.components.AggregationPolicy.Average), + "AlbedoFactor": TestCase(rr.components.AlbedoFactor((255, 255, 0, 255))), "AnnotationContextBatch": TestCase([ rr.datatypes.ClassDescriptionMapElem( class_id=1, @@ -119,7 +120,6 @@ def alternatives(self) -> list[Any] | None: batch=[rr.components.MarkerShape.Plus, rr.components.MarkerShape.Cross, rr.components.MarkerShape.Circle] ), "MarkerSizeBatch": TestCase(batch=[5.0, 1.0, 2.0]), - "MaterialBatch": TestCase(rr.datatypes.Material((255, 255, 0, 255))), "MediaTypeBatch": TestCase("application/jpg"), "NameBatch": TestCase(batch=["Hello World", "Foo Bar", "Baz Qux"]), "OutOfTreeTransform3DBatch": TestCase(