Skip to content

Commit

Permalink
Use a Buffer for ColorRGBA as well
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs committed Mar 23, 2023
1 parent 9c09c41 commit 01f537f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
13 changes: 5 additions & 8 deletions crates/re_log_types/src/component_types/mesh3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use arrow2_convert::{serialize::ArrowSerialize, ArrowDeserialize, ArrowField, Ar
use crate::msg_bundle::Component;

use super::arrow_convert_shims::BinaryBuffer;
use super::{ColorRGBA, FieldError, Vec4D};
use super::{FieldError, Vec4D};

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

Expand Down Expand Up @@ -144,12 +144,13 @@ pub struct RawMesh3D {
///
/// The length of this vector should always be divisible by three (since this is a 3D mesh).
///
/// If no indices are specified, then each triplet of vertex positions are intrpreted as a triangle
/// If no indices are specified, then each triplet of vertex positions are interpreted as a triangle
/// and the length of this must be divisible by 9.
pub vertex_positions: Buffer<f32>,

/// Per-vertex albedo colors.
pub vertex_colors: Option<Vec<ColorRGBA>>,
/// This is actually an encoded [`super::ColorRGBA`]
pub vertex_colors: Option<Buffer<u32>>,

/// Optionally, the flattened normals array for this mesh.
///
Expand Down Expand Up @@ -434,11 +435,7 @@ mod tests {
let mesh = RawMesh3D {
mesh_id: MeshId::random(),
vertex_positions: vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0].into(),
vertex_colors: Some(vec![
ColorRGBA(0xff0000ff),
ColorRGBA(0x00ff00ff),
ColorRGBA(0x0000ffff),
]),
vertex_colors: Some(vec![0xff0000ff, 0x00ff00ff, 0x0000ffff].into()),
indices: Some(vec![0, 1, 2].into()),
vertex_normals: Some(
vec![10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 80.0, 90.0, 100.0].into(),
Expand Down
4 changes: 2 additions & 2 deletions crates/re_viewer/src/misc/mesh_loader.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use re_log_types::{EncodedMesh3D, Mesh3D, MeshFormat, RawMesh3D};
use re_log_types::{component_types::ColorRGBA, EncodedMesh3D, Mesh3D, MeshFormat, RawMesh3D};
use re_renderer::{resource_managers::ResourceLifeTime, RenderContext, Rgba32Unmul};

pub struct LoadedMesh {
Expand Down Expand Up @@ -119,7 +119,7 @@ impl LoadedMesh {
let vertex_colors = if let Some(vertex_colors) = vertex_colors {
vertex_colors
.iter()
.map(|c| Rgba32Unmul::from_rgba_unmul_array(c.to_array()))
.map(|c| Rgba32Unmul::from_rgba_unmul_array(ColorRGBA(*c).to_array()))
.collect()
} else {
std::iter::repeat(Rgba32Unmul::WHITE)
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/raw_mesh/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl From<GltfPrimitive> for Mesh3D {
indices: indices.map(|i| i.into()),
vertex_positions: vertex_positions.into_iter().flatten().collect(),
vertex_normals: vertex_normals.map(|normals| normals.into_iter().flatten().collect()),
vertex_colors,
vertex_colors: vertex_colors.map(|colors| colors.into_iter().map(|c| c.0).collect()),
};

raw.sanity_check().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions rerun_py/src/python_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,13 @@ fn log_meshes(
[_, 3] => Some(
slice_from_np_array(&vertex_colors)
.chunks_exact(3)
.map(|c| ColorRGBA::from_rgb(c[0], c[1], c[2]))
.map(|c| ColorRGBA::from_rgb(c[0], c[1], c[2]).0)
.collect(),
),
[_, 4] => Some(
slice_from_np_array(&vertex_colors)
.chunks_exact(4)
.map(|c| ColorRGBA::from_unmultiplied_rgba(c[0], c[1], c[2], c[3]))
.map(|c| ColorRGBA::from_unmultiplied_rgba(c[0], c[1], c[2], c[3]).0)
.collect(),
),
shape => {
Expand Down

0 comments on commit 01f537f

Please sign in to comment.