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