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/store/re_types/definitions/rerun/archetypes/mesh3d.fbs".
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/position3d.hpp"
15#include "../components/texcoord2d.hpp"
16#include "../components/triangle_indices.hpp"
17#include "../components/vector3d.hpp"
18#include "../indicator_component.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 /// ## Examples
35 ///
36 /// ### Simple indexed 3D mesh
37 /// ![image](https://static.rerun.io/mesh3d_indexed/57c70dc992e6dc0bd9c5222ca084f5b6240cea75/full.png)
38 ///
39 /// ```cpp
40 /// #include <rerun.hpp>
41 ///
42 /// #include <vector>
43 ///
44 /// int main() {
45 /// const auto rec = rerun::RecordingStream("rerun_example_mesh3d_indexed");
46 /// rec.spawn().exit_on_failure();
47 ///
48 /// const rerun::Position3D vertex_positions[3] = {
49 /// {0.0f, 1.0f, 0.0f},
50 /// {1.0f, 0.0f, 0.0f},
51 /// {0.0f, 0.0f, 0.0f},
52 /// };
53 /// const rerun::Color vertex_colors[3] = {
54 /// {0, 0, 255},
55 /// {0, 255, 0},
56 /// {255, 0, 0},
57 /// };
58 ///
59 /// rec.log(
60 /// "triangle",
61 /// rerun::Mesh3D(vertex_positions)
62 /// .with_vertex_normals({{0.0, 0.0, 1.0}})
63 /// .with_vertex_colors(vertex_colors)
64 /// .with_triangle_indices({{2, 1, 0}})
65 /// );
66 /// }
67 /// ```
68 ///
69 /// ### 3D mesh with instancing
70 /// ![image](https://static.rerun.io/mesh3d_leaf_transforms3d/c2d0ee033129da53168f5705625a9b033f3a3d61/full.png)
71 ///
72 /// ```cpp
73 /// #include <rerun.hpp>
74 ///
75 /// int main() {
76 /// const auto rec = rerun::RecordingStream("rerun_example_mesh3d_instancing");
77 /// rec.spawn().exit_on_failure();
78 ///
79 /// rec.set_time_sequence("frame", 0);
80 /// rec.log(
81 /// "shape",
82 /// rerun::Mesh3D(
83 /// {{1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}}
84 /// )
85 /// .with_triangle_indices({{0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3}})
86 /// .with_vertex_colors({0xFF0000FF, 0x00FF00FF, 0x00000FFFF, 0xFFFF00FF})
87 /// );
88 /// // This box will not be affected by its parent's instance poses!
89 /// rec.log("shape/box", rerun::Boxes3D::from_half_sizes({{5.0f, 5.0f, 5.0f}}));
90 ///
91 /// for (int i = 0; i <100; ++i) {
92 /// rec.set_time_sequence("frame", i);
93 /// rec.log(
94 /// "shape",
95 /// rerun::InstancePoses3D()
96 /// .with_translations(
97 /// {{2.0f, 0.0f, 0.0f},
98 /// {0.0f, 2.0f, 0.0f},
99 /// {0.0f, -2.0f, 0.0f},
100 /// {-2.0f, 0.0f, 0.0f}}
101 /// )
102 /// .with_rotation_axis_angles({rerun::RotationAxisAngle(
103 /// {0.0f, 0.0f, 1.0f},
104 /// rerun::Angle::degrees(static_cast<float>(i) * 2.0f)
105 /// )})
106 /// );
107 /// }
108 /// }
109 /// ```
110 struct Mesh3D {
111 /// The positions of each vertex.
112 ///
113 /// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
114 std::optional<ComponentBatch> vertex_positions;
115
116 /// Optional indices for the triangles that make up the mesh.
117 std::optional<ComponentBatch> triangle_indices;
118
119 /// An optional normal for each vertex.
120 std::optional<ComponentBatch> vertex_normals;
121
122 /// An optional color for each vertex.
123 std::optional<ComponentBatch> vertex_colors;
124
125 /// An optional uv texture coordinate for each vertex.
126 std::optional<ComponentBatch> vertex_texcoords;
127
128 /// A color multiplier applied to the whole mesh.
129 std::optional<ComponentBatch> albedo_factor;
130
131 /// Optional albedo texture.
132 ///
133 /// Used with the `components::Texcoord2D` of the mesh.
134 ///
135 /// Currently supports only sRGB(A) textures, ignoring alpha.
136 /// (meaning that the tensor must have 3 or 4 channels and use the `u8` format)
137 std::optional<ComponentBatch> albedo_texture_buffer;
138
139 /// The format of the `albedo_texture_buffer`, if any.
140 std::optional<ComponentBatch> albedo_texture_format;
141
142 /// Optional class Ids for the vertices.
143 ///
144 /// The `components::ClassId` provides colors and labels if not specified explicitly.
145 std::optional<ComponentBatch> class_ids;
146
147 public:
148 static constexpr const char IndicatorComponentName[] = "rerun.components.Mesh3DIndicator";
149
150 /// Indicator component, used to identify the archetype when converting to a list of components.
152 /// The name of the archetype as used in `ComponentDescriptor`s.
153 static constexpr const char ArchetypeName[] = "rerun.archetypes.Mesh3D";
154
155 /// `ComponentDescriptor` for the `vertex_positions` field.
157 ArchetypeName, "vertex_positions",
159 );
160 /// `ComponentDescriptor` for the `triangle_indices` field.
162 ArchetypeName, "triangle_indices",
164 );
165 /// `ComponentDescriptor` for the `vertex_normals` field.
167 ArchetypeName, "vertex_normals",
169 );
170 /// `ComponentDescriptor` for the `vertex_colors` field.
172 ArchetypeName, "vertex_colors",
174 );
175 /// `ComponentDescriptor` for the `vertex_texcoords` field.
177 ArchetypeName, "vertex_texcoords",
179 );
180 /// `ComponentDescriptor` for the `albedo_factor` field.
182 ArchetypeName, "albedo_factor",
184 );
185 /// `ComponentDescriptor` for the `albedo_texture_buffer` field.
187 ArchetypeName, "albedo_texture_buffer",
189 );
190 /// `ComponentDescriptor` for the `albedo_texture_format` field.
192 ArchetypeName, "albedo_texture_format",
194 );
195 /// `ComponentDescriptor` for the `class_ids` field.
197 ArchetypeName, "class_ids",
199 );
200
201 public:
202 Mesh3D() = default;
203 Mesh3D(Mesh3D&& other) = default;
204 Mesh3D(const Mesh3D& other) = default;
205 Mesh3D& operator=(const Mesh3D& other) = default;
206 Mesh3D& operator=(Mesh3D&& other) = default;
207
208 explicit Mesh3D(Collection<rerun::components::Position3D> _vertex_positions)
209 : vertex_positions(ComponentBatch::from_loggable(
210 std::move(_vertex_positions), Descriptor_vertex_positions
211 )
212 .value_or_throw()) {}
213
214 /// Update only some specific fields of a `Mesh3D`.
216 return Mesh3D();
217 }
218
219 /// Clear all the fields of a `Mesh3D`.
221
222 /// The positions of each vertex.
223 ///
224 /// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
226 const Collection<rerun::components::Position3D>& _vertex_positions
227 ) && {
230 .value_or_throw();
231 return std::move(*this);
232 }
233
234 /// Optional indices for the triangles that make up the mesh.
237 ) && {
240 .value_or_throw();
241 return std::move(*this);
242 }
243
244 /// An optional normal for each vertex.
246 ) && {
249 .value_or_throw();
250 return std::move(*this);
251 }
252
253 /// An optional color for each vertex.
256 .value_or_throw();
257 return std::move(*this);
258 }
259
260 /// An optional uv texture coordinate for each vertex.
262 const Collection<rerun::components::Texcoord2D>& _vertex_texcoords
263 ) && {
266 .value_or_throw();
267 return std::move(*this);
268 }
269
270 /// A color multiplier applied to the whole mesh.
273 .value_or_throw();
274 return std::move(*this);
275 }
276
277 /// This method makes it possible to pack multiple `albedo_factor` in a single component batch.
278 ///
279 /// This only makes sense when used in conjunction with `columns`. `with_albedo_factor` should
280 /// be used when logging a single row's worth of data.
283 ) && {
285 .value_or_throw();
286 return std::move(*this);
287 }
288
289 /// Optional albedo texture.
290 ///
291 /// Used with the `components::Texcoord2D` of the mesh.
292 ///
293 /// Currently supports only sRGB(A) textures, ignoring alpha.
294 /// (meaning that the tensor must have 3 or 4 channels and use the `u8` format)
296 const rerun::components::ImageBuffer& _albedo_texture_buffer
297 ) && {
299 _albedo_texture_buffer,
301 )
302 .value_or_throw();
303 return std::move(*this);
304 }
305
306 /// This method makes it possible to pack multiple `albedo_texture_buffer` in a single component batch.
307 ///
308 /// This only makes sense when used in conjunction with `columns`. `with_albedo_texture_buffer` should
309 /// be used when logging a single row's worth of data.
311 const Collection<rerun::components::ImageBuffer>& _albedo_texture_buffer
312 ) && {
314 _albedo_texture_buffer,
316 )
317 .value_or_throw();
318 return std::move(*this);
319 }
320
321 /// The format of the `albedo_texture_buffer`, if any.
323 const rerun::components::ImageFormat& _albedo_texture_format
324 ) && {
326 _albedo_texture_format,
328 )
329 .value_or_throw();
330 return std::move(*this);
331 }
332
333 /// This method makes it possible to pack multiple `albedo_texture_format` in a single component batch.
334 ///
335 /// This only makes sense when used in conjunction with `columns`. `with_albedo_texture_format` should
336 /// be used when logging a single row's worth of data.
338 const Collection<rerun::components::ImageFormat>& _albedo_texture_format
339 ) && {
341 _albedo_texture_format,
343 )
344 .value_or_throw();
345 return std::move(*this);
346 }
347
348 /// Optional class Ids for the vertices.
349 ///
350 /// The `components::ClassId` provides colors and labels if not specified explicitly.
352 class_ids =
353 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
354 return std::move(*this);
355 }
356
357 /// Partitions the component data into multiple sub-batches.
358 ///
359 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
360 /// instead, via `ComponentBatch::partitioned`.
361 ///
362 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
363 ///
364 /// The specified `lengths` must sum to the total length of the component batch.
366
367 /// Partitions the component data into unit-length sub-batches.
368 ///
369 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
370 /// where `n` is automatically guessed.
372 };
373
374} // namespace rerun::archetypes
375
376namespace rerun {
377 /// \private
378 template <typename T>
379 struct AsComponents;
380
381 /// \private
382 template <>
383 struct AsComponents<archetypes::Mesh3D> {
384 /// Serialize all set component batches.
385 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Mesh3D& archetype);
386 };
387} // 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:76
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
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=rerun::Loggable< T >::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:14
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:110
static constexpr auto Descriptor_vertex_texcoords
ComponentDescriptor for the vertex_texcoords field.
Definition mesh3d.hpp:176
static constexpr auto Descriptor_albedo_texture_format
ComponentDescriptor for the albedo_texture_format field.
Definition mesh3d.hpp:191
Mesh3D with_albedo_texture_format(const rerun::components::ImageFormat &_albedo_texture_format) &&
The format of the albedo_texture_buffer, if any.
Definition mesh3d.hpp:322
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition mesh3d.hpp:196
Mesh3D with_triangle_indices(const Collection< rerun::components::TriangleIndices > &_triangle_indices) &&
Optional indices for the triangles that make up the mesh.
Definition mesh3d.hpp:235
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:337
static constexpr auto Descriptor_triangle_indices
ComponentDescriptor for the triangle_indices field.
Definition mesh3d.hpp:161
static constexpr auto Descriptor_vertex_colors
ComponentDescriptor for the vertex_colors field.
Definition mesh3d.hpp:171
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition mesh3d.hpp:153
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:129
static Mesh3D update_fields()
Update only some specific fields of a Mesh3D.
Definition mesh3d.hpp:215
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:261
static constexpr auto Descriptor_vertex_normals
ComponentDescriptor for the vertex_normals field.
Definition mesh3d.hpp:166
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
Mesh3D with_vertex_normals(const Collection< rerun::components::Vector3D > &_vertex_normals) &&
An optional normal for each vertex.
Definition mesh3d.hpp:245
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:310
static constexpr auto Descriptor_vertex_positions
ComponentDescriptor for the vertex_positions field.
Definition mesh3d.hpp:156
static constexpr auto Descriptor_albedo_texture_buffer
ComponentDescriptor for the albedo_texture_buffer field.
Definition mesh3d.hpp:186
std::optional< ComponentBatch > vertex_texcoords
An optional uv texture coordinate for each vertex.
Definition mesh3d.hpp:126
std::optional< ComponentBatch > vertex_positions
The positions of each vertex.
Definition mesh3d.hpp:114
Mesh3D with_albedo_factor(const rerun::components::AlbedoFactor &_albedo_factor) &&
A color multiplier applied to the whole mesh.
Definition mesh3d.hpp:271
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:281
static constexpr auto Descriptor_albedo_factor
ComponentDescriptor for the albedo_factor field.
Definition mesh3d.hpp:181
std::optional< ComponentBatch > class_ids
Optional class Ids for the vertices.
Definition mesh3d.hpp:145
std::optional< ComponentBatch > albedo_texture_buffer
Optional albedo texture.
Definition mesh3d.hpp:137
std::optional< ComponentBatch > vertex_colors
An optional color for each vertex.
Definition mesh3d.hpp:123
Mesh3D with_vertex_colors(const Collection< rerun::components::Color > &_vertex_colors) &&
An optional color for each vertex.
Definition mesh3d.hpp:254
Mesh3D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the vertices.
Definition mesh3d.hpp:351
Mesh3D with_vertex_positions(const Collection< rerun::components::Position3D > &_vertex_positions) &&
The positions of each vertex.
Definition mesh3d.hpp:225
std::optional< ComponentBatch > vertex_normals
An optional normal for each vertex.
Definition mesh3d.hpp:120
std::optional< ComponentBatch > triangle_indices
Optional indices for the triangles that make up the mesh.
Definition mesh3d.hpp:117
Mesh3D with_albedo_texture_buffer(const rerun::components::ImageBuffer &_albedo_texture_buffer) &&
Optional albedo texture.
Definition mesh3d.hpp:295
std::optional< ComponentBatch > albedo_texture_format
The format of the albedo_texture_buffer, if any.
Definition mesh3d.hpp:140
Component: A color multiplier, usually applied to a whole entity, e.g. a mesh.
Definition albedo_factor.hpp:15
Component: A buffer that is known to store image data.
Definition image_buffer.hpp:19
Component: The metadata describing the contents of a components::ImageBuffer.
Definition image_format.hpp:15
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32