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_sdk_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/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 struct Mesh3D {
118 /// The positions of each vertex.
119 ///
120 /// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
121 std::optional<ComponentBatch> vertex_positions;
122
123 /// Optional indices for the triangles that make up the mesh.
124 std::optional<ComponentBatch> triangle_indices;
125
126 /// An optional normal for each vertex.
127 std::optional<ComponentBatch> vertex_normals;
128
129 /// An optional color for each vertex.
130 ///
131 /// The alpha channel is ignored.
132 std::optional<ComponentBatch> vertex_colors;
133
134 /// An optional uv texture coordinate for each vertex.
135 std::optional<ComponentBatch> vertex_texcoords;
136
137 /// A color multiplier applied to the whole mesh.
138 ///
139 /// Alpha channel governs the overall mesh transparency.
140 std::optional<ComponentBatch> albedo_factor;
141
142 /// Determines which faces of the mesh are rendered.
143 ///
144 /// The default is `components::MeshFaceRendering::DoubleSided`, meaning both front and back faces are shown.
145 std::optional<ComponentBatch> face_rendering;
146
147 /// Optional albedo texture.
148 ///
149 /// Used with the `components::Texcoord2D` of the mesh.
150 ///
151 /// Currently supports only sRGB(A) textures, ignoring alpha.
152 /// (meaning that the tensor must have 3 or 4 channels and use the `u8` format)
153 ///
154 /// The alpha channel is ignored.
155 std::optional<ComponentBatch> albedo_texture_buffer;
156
157 /// The format of the `albedo_texture_buffer`, if any.
158 std::optional<ComponentBatch> albedo_texture_format;
159
160 /// Optional class Ids for the vertices.
161 ///
162 /// The `components::ClassId` provides colors and labels if not specified explicitly.
163 std::optional<ComponentBatch> class_ids;
164
165 public:
166 /// The name of the archetype as used in `ComponentDescriptor`s.
167 static constexpr const char ArchetypeName[] = "rerun.archetypes.Mesh3D";
168
169 /// `ComponentDescriptor` for the `vertex_positions` field.
171 ArchetypeName, "Mesh3D:vertex_positions",
173 );
174 /// `ComponentDescriptor` for the `triangle_indices` field.
176 ArchetypeName, "Mesh3D:triangle_indices",
178 );
179 /// `ComponentDescriptor` for the `vertex_normals` field.
181 ArchetypeName, "Mesh3D:vertex_normals",
183 );
184 /// `ComponentDescriptor` for the `vertex_colors` field.
187 );
188 /// `ComponentDescriptor` for the `vertex_texcoords` field.
190 ArchetypeName, "Mesh3D:vertex_texcoords",
192 );
193 /// `ComponentDescriptor` for the `albedo_factor` field.
195 ArchetypeName, "Mesh3D:albedo_factor",
197 );
198 /// `ComponentDescriptor` for the `face_rendering` field.
200 ArchetypeName, "Mesh3D:face_rendering",
202 );
203 /// `ComponentDescriptor` for the `albedo_texture_buffer` field.
205 ArchetypeName, "Mesh3D:albedo_texture_buffer",
207 );
208 /// `ComponentDescriptor` for the `albedo_texture_format` field.
210 ArchetypeName, "Mesh3D:albedo_texture_format",
212 );
213 /// `ComponentDescriptor` for the `class_ids` field.
216 );
217
218 public:
219 Mesh3D() = default;
220 Mesh3D(Mesh3D&& other) = default;
221 Mesh3D(const Mesh3D& other) = default;
222 Mesh3D& operator=(const Mesh3D& other) = default;
223 Mesh3D& operator=(Mesh3D&& other) = default;
224
225 explicit Mesh3D(Collection<rerun::components::Position3D> _vertex_positions)
226 : vertex_positions(ComponentBatch::from_loggable(
227 std::move(_vertex_positions), Descriptor_vertex_positions
228 )
229 .value_or_throw()) {}
230
231 /// Update only some specific fields of a `Mesh3D`.
233 return Mesh3D();
234 }
235
236 /// Clear all the fields of a `Mesh3D`.
238
239 /// The positions of each vertex.
240 ///
241 /// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
243 const Collection<rerun::components::Position3D>& _vertex_positions
244 ) && {
247 .value_or_throw();
248 return std::move(*this);
249 }
250
251 /// Optional indices for the triangles that make up the mesh.
254 ) && {
257 .value_or_throw();
258 return std::move(*this);
259 }
260
261 /// An optional normal for each vertex.
263 ) && {
266 .value_or_throw();
267 return std::move(*this);
268 }
269
270 /// An optional color for each vertex.
271 ///
272 /// The alpha channel is ignored.
275 .value_or_throw();
276 return std::move(*this);
277 }
278
279 /// An optional uv texture coordinate for each vertex.
281 const Collection<rerun::components::Texcoord2D>& _vertex_texcoords
282 ) && {
285 .value_or_throw();
286 return std::move(*this);
287 }
288
289 /// A color multiplier applied to the whole mesh.
290 ///
291 /// Alpha channel governs the overall mesh transparency.
294 .value_or_throw();
295 return std::move(*this);
296 }
297
298 /// This method makes it possible to pack multiple `albedo_factor` in a single component batch.
299 ///
300 /// This only makes sense when used in conjunction with `columns`. `with_albedo_factor` should
301 /// be used when logging a single row's worth of data.
304 ) && {
306 .value_or_throw();
307 return std::move(*this);
308 }
309
310 /// Determines which faces of the mesh are rendered.
311 ///
312 /// The default is `components::MeshFaceRendering::DoubleSided`, meaning both front and back faces are shown.
316 .value_or_throw();
317 return std::move(*this);
318 }
319
320 /// This method makes it possible to pack multiple `face_rendering` in a single component batch.
321 ///
322 /// This only makes sense when used in conjunction with `columns`. `with_face_rendering` should
323 /// be used when logging a single row's worth of data.
326 ) && {
329 .value_or_throw();
330 return std::move(*this);
331 }
332
333 /// Optional albedo texture.
334 ///
335 /// Used with the `components::Texcoord2D` of the mesh.
336 ///
337 /// Currently supports only sRGB(A) textures, ignoring alpha.
338 /// (meaning that the tensor must have 3 or 4 channels and use the `u8` format)
339 ///
340 /// The alpha channel is ignored.
342 const rerun::components::ImageBuffer& _albedo_texture_buffer
343 ) && {
345 _albedo_texture_buffer,
347 )
348 .value_or_throw();
349 return std::move(*this);
350 }
351
352 /// This method makes it possible to pack multiple `albedo_texture_buffer` in a single component batch.
353 ///
354 /// This only makes sense when used in conjunction with `columns`. `with_albedo_texture_buffer` should
355 /// be used when logging a single row's worth of data.
357 const Collection<rerun::components::ImageBuffer>& _albedo_texture_buffer
358 ) && {
360 _albedo_texture_buffer,
362 )
363 .value_or_throw();
364 return std::move(*this);
365 }
366
367 /// The format of the `albedo_texture_buffer`, if any.
369 const rerun::components::ImageFormat& _albedo_texture_format
370 ) && {
372 _albedo_texture_format,
374 )
375 .value_or_throw();
376 return std::move(*this);
377 }
378
379 /// This method makes it possible to pack multiple `albedo_texture_format` in a single component batch.
380 ///
381 /// This only makes sense when used in conjunction with `columns`. `with_albedo_texture_format` should
382 /// be used when logging a single row's worth of data.
384 const Collection<rerun::components::ImageFormat>& _albedo_texture_format
385 ) && {
387 _albedo_texture_format,
389 )
390 .value_or_throw();
391 return std::move(*this);
392 }
393
394 /// Optional class Ids for the vertices.
395 ///
396 /// The `components::ClassId` provides colors and labels if not specified explicitly.
398 class_ids =
399 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
400 return std::move(*this);
401 }
402
403 /// Partitions the component data into multiple sub-batches.
404 ///
405 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
406 /// instead, via `ComponentBatch::partitioned`.
407 ///
408 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
409 ///
410 /// The specified `lengths` must sum to the total length of the component batch.
412
413 /// Partitions the component data into unit-length sub-batches.
414 ///
415 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
416 /// where `n` is automatically guessed.
418 };
419
420} // namespace rerun::archetypes
421
422namespace rerun {
423 /// \private
424 template <typename T>
425 struct AsComponents;
426
427 /// \private
428 template <>
429 struct AsComponents<archetypes::Mesh3D> {
430 /// Serialize all set component batches.
431 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Mesh3D& archetype);
432 };
433} // 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:87
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: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:117
static constexpr auto Descriptor_vertex_texcoords
ComponentDescriptor for the vertex_texcoords field.
Definition mesh3d.hpp:189
static constexpr auto Descriptor_albedo_texture_format
ComponentDescriptor for the albedo_texture_format field.
Definition mesh3d.hpp:209
Mesh3D with_albedo_texture_format(const rerun::components::ImageFormat &_albedo_texture_format) &&
The format of the albedo_texture_buffer, if any.
Definition mesh3d.hpp:368
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition mesh3d.hpp:214
Mesh3D with_triangle_indices(const Collection< rerun::components::TriangleIndices > &_triangle_indices) &&
Optional indices for the triangles that make up the mesh.
Definition mesh3d.hpp:252
static constexpr auto Descriptor_face_rendering
ComponentDescriptor for the face_rendering field.
Definition mesh3d.hpp:199
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:383
static constexpr auto Descriptor_triangle_indices
ComponentDescriptor for the triangle_indices field.
Definition mesh3d.hpp:175
static constexpr auto Descriptor_vertex_colors
ComponentDescriptor for the vertex_colors field.
Definition mesh3d.hpp:185
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition mesh3d.hpp:167
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:140
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:324
static Mesh3D update_fields()
Update only some specific fields of a Mesh3D.
Definition mesh3d.hpp:232
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:280
static constexpr auto Descriptor_vertex_normals
ComponentDescriptor for the vertex_normals field.
Definition mesh3d.hpp:180
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:145
Mesh3D with_vertex_normals(const Collection< rerun::components::Vector3D > &_vertex_normals) &&
An optional normal for each vertex.
Definition mesh3d.hpp:262
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:356
static constexpr auto Descriptor_vertex_positions
ComponentDescriptor for the vertex_positions field.
Definition mesh3d.hpp:170
static constexpr auto Descriptor_albedo_texture_buffer
ComponentDescriptor for the albedo_texture_buffer field.
Definition mesh3d.hpp:204
std::optional< ComponentBatch > vertex_texcoords
An optional uv texture coordinate for each vertex.
Definition mesh3d.hpp:135
std::optional< ComponentBatch > vertex_positions
The positions of each vertex.
Definition mesh3d.hpp:121
Mesh3D with_albedo_factor(const rerun::components::AlbedoFactor &_albedo_factor) &&
A color multiplier applied to the whole mesh.
Definition mesh3d.hpp:292
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:302
static constexpr auto Descriptor_albedo_factor
ComponentDescriptor for the albedo_factor field.
Definition mesh3d.hpp:194
std::optional< ComponentBatch > class_ids
Optional class Ids for the vertices.
Definition mesh3d.hpp:163
std::optional< ComponentBatch > albedo_texture_buffer
Optional albedo texture.
Definition mesh3d.hpp:155
std::optional< ComponentBatch > vertex_colors
An optional color for each vertex.
Definition mesh3d.hpp:132
Mesh3D with_vertex_colors(const Collection< rerun::components::Color > &_vertex_colors) &&
An optional color for each vertex.
Definition mesh3d.hpp:273
Mesh3D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the vertices.
Definition mesh3d.hpp:397
Mesh3D with_vertex_positions(const Collection< rerun::components::Position3D > &_vertex_positions) &&
The positions of each vertex.
Definition mesh3d.hpp:242
Mesh3D with_face_rendering(const rerun::components::MeshFaceRendering &_face_rendering) &&
Determines which faces of the mesh are rendered.
Definition mesh3d.hpp:313
std::optional< ComponentBatch > vertex_normals
An optional normal for each vertex.
Definition mesh3d.hpp:127
std::optional< ComponentBatch > triangle_indices
Optional indices for the triangles that make up the mesh.
Definition mesh3d.hpp:124
Mesh3D with_albedo_texture_buffer(const rerun::components::ImageBuffer &_albedo_texture_buffer) &&
Optional albedo texture.
Definition mesh3d.hpp:341
std::optional< ComponentBatch > albedo_texture_format
The format of the albedo_texture_buffer, if any.
Definition mesh3d.hpp:158
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