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