Rerun C++ SDK
Loading...
Searching...
No Matches
mesh3d.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/build/re_type_definitions/rerun/archetypes/mesh3d.def.rs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/albedo_factor.hpp"
10#include "../components/class_id.hpp"
11#include "../components/color.hpp"
12#include "../components/image_buffer.hpp"
13#include "../components/image_format.hpp"
14#include "../components/mesh_face_rendering.hpp"
15#include "../components/position3d.hpp"
16#include "../components/texcoord2d.hpp"
17#include "../components/triangle_indices.hpp"
18#include "../components/vector3d.hpp"
19#include "../result.hpp"
20
21#include <cstdint>
22#include <optional>
23#include <utility>
24#include <vector>
25
26namespace rerun::archetypes {
27 /// **Archetype**: A 3D triangle mesh as specified by its per-mesh and per-vertex properties.
28 ///
29 /// See also `archetypes::Asset3D`.
30 ///
31 /// If there are multiple `archetypes::InstancePoses3D` instances logged to the same entity as a mesh,
32 /// an instance of the mesh will be drawn for each transform.
33 ///
34 /// For transparency ordering, as well as back face culling (disabled by default),
35 /// front faces are assumed to be those with counter clockwise triangle winding order
36 /// (this is the same as in the GLTF specification).
37 ///
38 /// ## Examples
39 ///
40 /// ### Simple indexed 3D mesh
41 /// ![image](https://static.rerun.io/mesh3d_indexed/57c70dc992e6dc0bd9c5222ca084f5b6240cea75/full.png)
42 ///
43 /// ```cpp
44 /// #include <rerun.hpp>
45 ///
46 /// #include <vector>
47 ///
48 /// int main(int argc, char* argv[]) {
49 /// const auto rec = rerun::RecordingStream("rerun_example_mesh3d_indexed");
50 /// rec.spawn().exit_on_failure();
51 ///
52 /// const rerun::Position3D vertex_positions[3] = {
53 /// {0.0f, 1.0f, 0.0f},
54 /// {1.0f, 0.0f, 0.0f},
55 /// {0.0f, 0.0f, 0.0f},
56 /// };
57 /// const rerun::Color vertex_colors[3] = {
58 /// {0, 0, 255},
59 /// {0, 255, 0},
60 /// {255, 0, 0},
61 /// };
62 ///
63 /// rec.log(
64 /// "triangle",
65 /// rerun::Mesh3D(vertex_positions)
66 /// .with_vertex_normals({{0.0, 0.0, 1.0}})
67 /// .with_vertex_colors(vertex_colors)
68 /// .with_triangle_indices({{2, 1, 0}})
69 /// );
70 /// }
71 /// ```
72 ///
73 /// ### 3D mesh with instancing
74 /// ![image](https://static.rerun.io/mesh3d_leaf_transforms3d/c2d0ee033129da53168f5705625a9b033f3a3d61/full.png)
75 ///
76 /// ```cpp
77 /// #include <rerun.hpp>
78 ///
79 /// int main(int argc, char* argv[]) {
80 /// const auto rec = rerun::RecordingStream("rerun_example_mesh3d_instancing");
81 /// rec.spawn().exit_on_failure();
82 ///
83 /// rec.set_time_sequence("frame", 0);
84 /// rec.log(
85 /// "shape",
86 /// rerun::Mesh3D({{1.0f, 1.0f, 1.0f},
87 /// {-1.0f, -1.0f, 1.0f},
88 /// {-1.0f, 1.0f, -1.0f},
89 /// {1.0f, -1.0f, -1.0f}})
90 /// .with_triangle_indices({{0, 2, 1}, {0, 3, 1}, {0, 3, 2}, {1, 3, 2}})
91 /// .with_vertex_colors(
92 /// {0xFF0000FF, 0x00FF00FF, 0x00000FFFF, 0xFFFF00FF}
93 /// )
94 /// );
95 /// // This box will not be affected by its parent's instance poses!
96 /// rec.log("shape/box", rerun::Boxes3D::from_half_sizes({{5.0f, 5.0f, 5.0f}}));
97 ///
98 /// for (int i = 0; i <100; ++i) {
99 /// rec.set_time_sequence("frame", i);
100 /// rec.log(
101 /// "shape",
102 /// rerun::InstancePoses3D()
103 /// .with_translations(
104 /// {{2.0f, 0.0f, 0.0f},
105 /// {0.0f, 2.0f, 0.0f},
106 /// {0.0f, -2.0f, 0.0f},
107 /// {-2.0f, 0.0f, 0.0f}}
108 /// )
109 /// .with_rotation_axis_angles({rerun::RotationAxisAngle(
110 /// {0.0f, 0.0f, 1.0f},
111 /// rerun::Angle::degrees(static_cast<float>(i) * 2.0f)
112 /// )})
113 /// );
114 /// }
115 /// }
116 /// ```
117 ///
118 /// ### Image as a 3D quad
119 /// ![image](https://static.rerun.io/mesh3d_image/98ffc9479275c150984959c4cb0a3b2266cf6026/full.png)
120 ///
121 /// ```cpp
122 /// #include <rerun.hpp>
123 ///
124 /// #include <vector>
125 ///
126 /// int main(int argc, char* argv[]) {
127 /// const auto rec = rerun::RecordingStream("rerun_example_mesh3d_image");
128 /// rec.spawn().exit_on_failure();
129 ///
130 /// const uint32_t width = 256;
131 /// const uint32_t height = 256;
132 ///
133 /// // Simple gradient image
134 /// std::vector<uint8_t> image(width * height * 3);
135 /// for (uint32_t y = 0; y <height; ++y) {
136 /// for (uint32_t x = 0; x <width; ++x) {
137 /// image[(y * width + x) * 3 + 0] = static_cast<uint8_t>(x);
138 /// image[(y * width + x) * 3 + 1] = static_cast<uint8_t>(y);
139 /// image[(y * width + x) * 3 + 2] = 0;
140 /// }
141 /// }
142 ///
143 /// const rerun::Position3D top_left = {1.0f, 1.0f, 1.0f};
144 /// const rerun::Position3D top_right = {1.0f, 0.0f, 1.0f};
145 /// const rerun::Position3D bottom_right = {1.0f, 0.0f, 0.0f};
146 /// const rerun::Position3D bottom_left = {1.0f, 1.0f, 0.0f};
147 /// const uint8_t alpha = 255;
148 ///
149 /// // Inset by half a pixel so the opposite edges of the image don't leak onto the border.
150 /// const float u0 = 0.5f / static_cast<float>(width);
151 /// const float v0 = 0.5f / static_cast<float>(height);
152 /// const float u1 = 1.0f - u0;
153 /// const float v1 = 1.0f - v0;
154 ///
155 /// rec.log(
156 /// "image",
157 /// rerun::Mesh3D({top_left, top_right, bottom_right, bottom_left})
158 /// .with_vertex_texcoords({{u0, v0}, {u1, v0}, {u1, v1}, {u0, v1}})
159 /// .with_triangle_indices({{0, 2, 1}, {0, 3, 2}})
160 /// .with_albedo_texture_buffer(rerun::ImageBuffer(image))
161 /// .with_albedo_texture_format(rerun::components::ImageFormat(
162 /// {width, height},
163 /// rerun::ColorModel::RGB,
164 /// rerun::ChannelDatatype::U8
165 /// ))
166 /// .with_albedo_factor(rerun::Rgba32(255, 255, 255, alpha))
167 /// );
168 /// }
169 /// ```
170 struct Mesh3D {
171 /// The positions of each vertex.
172 ///
173 /// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
174 std::optional<ComponentBatch> vertex_positions;
175
176 /// Optional indices for the triangles that make up the mesh.
177 std::optional<ComponentBatch> triangle_indices;
178
179 /// An optional normal for each vertex.
180 std::optional<ComponentBatch> vertex_normals;
181
182 /// An optional color for each vertex.
183 ///
184 /// The alpha channel is ignored.
185 std::optional<ComponentBatch> vertex_colors;
186
187 /// An optional uv texture coordinate for each vertex.
188 std::optional<ComponentBatch> vertex_texcoords;
189
190 /// A color multiplier applied to the whole mesh.
191 ///
192 /// Alpha channel governs the overall mesh transparency.
193 std::optional<ComponentBatch> albedo_factor;
194
195 /// Determines which faces of the mesh are rendered.
196 ///
197 /// The default is `components::MeshFaceRendering::DoubleSided`, meaning both front and back faces are shown.
198 std::optional<ComponentBatch> face_rendering;
199
200 /// Optional albedo texture.
201 ///
202 /// Used with the `components::Texcoord2D` of the mesh.
203 ///
204 /// Currently supports only sRGB(A) textures, ignoring alpha.
205 /// (meaning that the tensor must have 3 or 4 channels and use the `u8` format)
206 ///
207 /// The alpha channel is ignored.
208 std::optional<ComponentBatch> albedo_texture_buffer;
209
210 /// The format of the `albedo_texture_buffer`, if any.
211 std::optional<ComponentBatch> albedo_texture_format;
212
213 /// Optional class Ids for the vertices.
214 ///
215 /// The `components::ClassId` provides colors and labels if not specified explicitly.
216 std::optional<ComponentBatch> class_ids;
217
218 public:
219 /// The name of the archetype as used in `ComponentDescriptor`s.
220 static constexpr const char ArchetypeName[] = "rerun.archetypes.Mesh3D";
221
222 /// `ComponentDescriptor` for the `vertex_positions` field.
224 ArchetypeName, "Mesh3D:vertex_positions",
226 );
227 /// `ComponentDescriptor` for the `triangle_indices` field.
229 ArchetypeName, "Mesh3D:triangle_indices",
231 );
232 /// `ComponentDescriptor` for the `vertex_normals` field.
234 ArchetypeName, "Mesh3D:vertex_normals",
236 );
237 /// `ComponentDescriptor` for the `vertex_colors` field.
240 );
241 /// `ComponentDescriptor` for the `vertex_texcoords` field.
243 ArchetypeName, "Mesh3D:vertex_texcoords",
245 );
246 /// `ComponentDescriptor` for the `albedo_factor` field.
248 ArchetypeName, "Mesh3D:albedo_factor",
250 );
251 /// `ComponentDescriptor` for the `face_rendering` field.
253 ArchetypeName, "Mesh3D:face_rendering",
255 );
256 /// `ComponentDescriptor` for the `albedo_texture_buffer` field.
258 ArchetypeName, "Mesh3D:albedo_texture_buffer",
260 );
261 /// `ComponentDescriptor` for the `albedo_texture_format` field.
263 ArchetypeName, "Mesh3D:albedo_texture_format",
265 );
266 /// `ComponentDescriptor` for the `class_ids` field.
269 );
270
271 public:
272 Mesh3D() = default;
273 Mesh3D(Mesh3D&& other) = default;
274 Mesh3D(const Mesh3D& other) = default;
275 Mesh3D& operator=(const Mesh3D& other) = default;
276 Mesh3D& operator=(Mesh3D&& other) = default;
277
278 explicit Mesh3D(Collection<rerun::components::Position3D> _vertex_positions)
279 : vertex_positions(ComponentBatch::from_loggable(
280 std::move(_vertex_positions), Descriptor_vertex_positions
281 )
282 .value_or_throw()) {}
283
284 /// Update only some specific fields of a `Mesh3D`.
286 return Mesh3D();
287 }
288
289 /// Clear all the fields of a `Mesh3D`.
291
292 /// The positions of each vertex.
293 ///
294 /// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
296 const Collection<rerun::components::Position3D>& _vertex_positions
297 ) && {
300 .value_or_throw();
301 return std::move(*this);
302 }
303
304 /// Optional indices for the triangles that make up the mesh.
307 ) && {
310 .value_or_throw();
311 return std::move(*this);
312 }
313
314 /// An optional normal for each vertex.
316 ) && {
319 .value_or_throw();
320 return std::move(*this);
321 }
322
323 /// An optional color for each vertex.
324 ///
325 /// The alpha channel is ignored.
328 .value_or_throw();
329 return std::move(*this);
330 }
331
332 /// An optional uv texture coordinate for each vertex.
334 const Collection<rerun::components::Texcoord2D>& _vertex_texcoords
335 ) && {
338 .value_or_throw();
339 return std::move(*this);
340 }
341
342 /// A color multiplier applied to the whole mesh.
343 ///
344 /// Alpha channel governs the overall mesh transparency.
347 .value_or_throw();
348 return std::move(*this);
349 }
350
351 /// This method makes it possible to pack multiple `albedo_factor` in a single component batch.
352 ///
353 /// This only makes sense when used in conjunction with `columns`. `with_albedo_factor` should
354 /// be used when logging a single row's worth of data.
357 ) && {
359 .value_or_throw();
360 return std::move(*this);
361 }
362
363 /// Determines which faces of the mesh are rendered.
364 ///
365 /// The default is `components::MeshFaceRendering::DoubleSided`, meaning both front and back faces are shown.
369 .value_or_throw();
370 return std::move(*this);
371 }
372
373 /// This method makes it possible to pack multiple `face_rendering` in a single component batch.
374 ///
375 /// This only makes sense when used in conjunction with `columns`. `with_face_rendering` should
376 /// be used when logging a single row's worth of data.
379 ) && {
382 .value_or_throw();
383 return std::move(*this);
384 }
385
386 /// Optional albedo texture.
387 ///
388 /// Used with the `components::Texcoord2D` of the mesh.
389 ///
390 /// Currently supports only sRGB(A) textures, ignoring alpha.
391 /// (meaning that the tensor must have 3 or 4 channels and use the `u8` format)
392 ///
393 /// The alpha channel is ignored.
395 const rerun::components::ImageBuffer& _albedo_texture_buffer
396 ) && {
398 _albedo_texture_buffer,
400 )
401 .value_or_throw();
402 return std::move(*this);
403 }
404
405 /// This method makes it possible to pack multiple `albedo_texture_buffer` in a single component batch.
406 ///
407 /// This only makes sense when used in conjunction with `columns`. `with_albedo_texture_buffer` should
408 /// be used when logging a single row's worth of data.
410 const Collection<rerun::components::ImageBuffer>& _albedo_texture_buffer
411 ) && {
413 _albedo_texture_buffer,
415 )
416 .value_or_throw();
417 return std::move(*this);
418 }
419
420 /// The format of the `albedo_texture_buffer`, if any.
422 const rerun::components::ImageFormat& _albedo_texture_format
423 ) && {
425 _albedo_texture_format,
427 )
428 .value_or_throw();
429 return std::move(*this);
430 }
431
432 /// This method makes it possible to pack multiple `albedo_texture_format` in a single component batch.
433 ///
434 /// This only makes sense when used in conjunction with `columns`. `with_albedo_texture_format` should
435 /// be used when logging a single row's worth of data.
437 const Collection<rerun::components::ImageFormat>& _albedo_texture_format
438 ) && {
440 _albedo_texture_format,
442 )
443 .value_or_throw();
444 return std::move(*this);
445 }
446
447 /// Optional class Ids for the vertices.
448 ///
449 /// The `components::ClassId` provides colors and labels if not specified explicitly.
451 class_ids =
452 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
453 return std::move(*this);
454 }
455
456 /// Partitions the component data into multiple sub-batches.
457 ///
458 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
459 /// instead, via `ComponentBatch::partitioned`.
460 ///
461 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
462 ///
463 /// The specified `lengths` must sum to the total length of the component batch.
465
466 /// Partitions the component data into unit-length sub-batches.
467 ///
468 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
469 /// where `n` is automatically guessed.
471 };
472
473} // namespace rerun::archetypes
474
475namespace rerun {
476 /// \private
477 template <typename T>
478 struct AsComponents;
479
480 /// \private
481 template <>
482 struct AsComponents<archetypes::Mesh3D> {
483 /// Serialize all set component batches.
484 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Mesh3D& archetype);
485 };
486} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:90
MeshFaceRendering
Component: Determines which faces of a mesh are rendered.
Definition mesh_face_rendering.hpp:27
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
Arrow-encoded data of a single batch of components together with a component descriptor.
Definition component_batch.hpp:28
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: A 3D triangle mesh as specified by its per-mesh and per-vertex properties.
Definition mesh3d.hpp:170
static constexpr auto Descriptor_vertex_texcoords
ComponentDescriptor for the vertex_texcoords field.
Definition mesh3d.hpp:242
static constexpr auto Descriptor_albedo_texture_format
ComponentDescriptor for the albedo_texture_format field.
Definition mesh3d.hpp:262
Mesh3D with_albedo_texture_format(const rerun::components::ImageFormat &_albedo_texture_format) &&
The format of the albedo_texture_buffer, if any.
Definition mesh3d.hpp:421
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition mesh3d.hpp:267
Mesh3D with_triangle_indices(const Collection< rerun::components::TriangleIndices > &_triangle_indices) &&
Optional indices for the triangles that make up the mesh.
Definition mesh3d.hpp:305
static constexpr auto Descriptor_face_rendering
ComponentDescriptor for the face_rendering field.
Definition mesh3d.hpp:252
Mesh3D with_many_albedo_texture_format(const Collection< rerun::components::ImageFormat > &_albedo_texture_format) &&
This method makes it possible to pack multiple albedo_texture_format in a single component batch.
Definition mesh3d.hpp:436
static constexpr auto Descriptor_triangle_indices
ComponentDescriptor for the triangle_indices field.
Definition mesh3d.hpp:228
static constexpr auto Descriptor_vertex_colors
ComponentDescriptor for the vertex_colors field.
Definition mesh3d.hpp:238
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition mesh3d.hpp:220
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
std::optional< ComponentBatch > albedo_factor
A color multiplier applied to the whole mesh.
Definition mesh3d.hpp:193
Mesh3D with_many_face_rendering(const Collection< rerun::components::MeshFaceRendering > &_face_rendering) &&
This method makes it possible to pack multiple face_rendering in a single component batch.
Definition mesh3d.hpp:377
static Mesh3D update_fields()
Update only some specific fields of a Mesh3D.
Definition mesh3d.hpp:285
static Mesh3D clear_fields()
Clear all the fields of a Mesh3D.
Mesh3D with_vertex_texcoords(const Collection< rerun::components::Texcoord2D > &_vertex_texcoords) &&
An optional uv texture coordinate for each vertex.
Definition mesh3d.hpp:333
static constexpr auto Descriptor_vertex_normals
ComponentDescriptor for the vertex_normals field.
Definition mesh3d.hpp:233
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
std::optional< ComponentBatch > face_rendering
Determines which faces of the mesh are rendered.
Definition mesh3d.hpp:198
Mesh3D with_vertex_normals(const Collection< rerun::components::Vector3D > &_vertex_normals) &&
An optional normal for each vertex.
Definition mesh3d.hpp:315
Mesh3D with_many_albedo_texture_buffer(const Collection< rerun::components::ImageBuffer > &_albedo_texture_buffer) &&
This method makes it possible to pack multiple albedo_texture_buffer in a single component batch.
Definition mesh3d.hpp:409
static constexpr auto Descriptor_vertex_positions
ComponentDescriptor for the vertex_positions field.
Definition mesh3d.hpp:223
static constexpr auto Descriptor_albedo_texture_buffer
ComponentDescriptor for the albedo_texture_buffer field.
Definition mesh3d.hpp:257
std::optional< ComponentBatch > vertex_texcoords
An optional uv texture coordinate for each vertex.
Definition mesh3d.hpp:188
std::optional< ComponentBatch > vertex_positions
The positions of each vertex.
Definition mesh3d.hpp:174
Mesh3D with_albedo_factor(const rerun::components::AlbedoFactor &_albedo_factor) &&
A color multiplier applied to the whole mesh.
Definition mesh3d.hpp:345
Mesh3D with_many_albedo_factor(const Collection< rerun::components::AlbedoFactor > &_albedo_factor) &&
This method makes it possible to pack multiple albedo_factor in a single component batch.
Definition mesh3d.hpp:355
static constexpr auto Descriptor_albedo_factor
ComponentDescriptor for the albedo_factor field.
Definition mesh3d.hpp:247
std::optional< ComponentBatch > class_ids
Optional class Ids for the vertices.
Definition mesh3d.hpp:216
std::optional< ComponentBatch > albedo_texture_buffer
Optional albedo texture.
Definition mesh3d.hpp:208
std::optional< ComponentBatch > vertex_colors
An optional color for each vertex.
Definition mesh3d.hpp:185
Mesh3D with_vertex_colors(const Collection< rerun::components::Color > &_vertex_colors) &&
An optional color for each vertex.
Definition mesh3d.hpp:326
Mesh3D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the vertices.
Definition mesh3d.hpp:450
Mesh3D with_vertex_positions(const Collection< rerun::components::Position3D > &_vertex_positions) &&
The positions of each vertex.
Definition mesh3d.hpp:295
Mesh3D with_face_rendering(const rerun::components::MeshFaceRendering &_face_rendering) &&
Determines which faces of the mesh are rendered.
Definition mesh3d.hpp:366
std::optional< ComponentBatch > vertex_normals
An optional normal for each vertex.
Definition mesh3d.hpp:180
std::optional< ComponentBatch > triangle_indices
Optional indices for the triangles that make up the mesh.
Definition mesh3d.hpp:177
Mesh3D with_albedo_texture_buffer(const rerun::components::ImageBuffer &_albedo_texture_buffer) &&
Optional albedo texture.
Definition mesh3d.hpp:394
std::optional< ComponentBatch > albedo_texture_format
The format of the albedo_texture_buffer, if any.
Definition mesh3d.hpp:211
Component: A color multiplier, usually applied to a whole entity, e.g. a mesh.
Definition albedo_factor.hpp:14
Component: A buffer that is known to store image data.
Definition image_buffer.hpp:18
Component: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:14