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