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(
87 /// {{1.0f, 1.0f, 1.0f}, {-1.0f, -1.0f, 1.0f}, {-1.0f, 1.0f, -1.0f}, {1.0f, -1.0f, -1.0f}}
88 /// )
89 /// .with_triangle_indices({{0, 2, 1}, {0, 3, 1}, {0, 3, 2}, {1, 3, 2}})
90 /// .with_vertex_colors({0xFF0000FF, 0x00FF00FF, 0x00000FFFF, 0xFFFF00FF})
91 /// );
92 /// // This box will not be affected by its parent's instance poses!
93 /// rec.log("shape/box", rerun::Boxes3D::from_half_sizes({{5.0f, 5.0f, 5.0f}}));
94 ///
95 /// for (int i = 0; i <100; ++i) {
96 /// rec.set_time_sequence("frame", i);
97 /// rec.log(
98 /// "shape",
99 /// rerun::InstancePoses3D()
100 /// .with_translations(
101 /// {{2.0f, 0.0f, 0.0f},
102 /// {0.0f, 2.0f, 0.0f},
103 /// {0.0f, -2.0f, 0.0f},
104 /// {-2.0f, 0.0f, 0.0f}}
105 /// )
106 /// .with_rotation_axis_angles({rerun::RotationAxisAngle(
107 /// {0.0f, 0.0f, 1.0f},
108 /// rerun::Angle::degrees(static_cast<float>(i) * 2.0f)
109 /// )})
110 /// );
111 /// }
112 /// }
113 /// ```
114 struct Mesh3D {
115 /// The positions of each vertex.
116 ///
117 /// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
118 std::optional<ComponentBatch> vertex_positions;
119
120 /// Optional indices for the triangles that make up the mesh.
121 std::optional<ComponentBatch> triangle_indices;
122
123 /// An optional normal for each vertex.
124 std::optional<ComponentBatch> vertex_normals;
125
126 /// An optional color for each vertex.
127 ///
128 /// The alpha channel is ignored.
129 std::optional<ComponentBatch> vertex_colors;
130
131 /// An optional uv texture coordinate for each vertex.
132 std::optional<ComponentBatch> vertex_texcoords;
133
134 /// A color multiplier applied to the whole mesh.
135 ///
136 /// Alpha channel governs the overall mesh transparency.
137 std::optional<ComponentBatch> albedo_factor;
138
139 /// Determines which faces of the mesh are rendered.
140 ///
141 /// The default is `components::MeshFaceRendering::DoubleSided`, meaning both front and back faces are shown.
142 std::optional<ComponentBatch> face_rendering;
143
144 /// Optional albedo texture.
145 ///
146 /// Used with the `components::Texcoord2D` of the mesh.
147 ///
148 /// Currently supports only sRGB(A) textures, ignoring alpha.
149 /// (meaning that the tensor must have 3 or 4 channels and use the `u8` format)
150 ///
151 /// The alpha channel is ignored.
152 std::optional<ComponentBatch> albedo_texture_buffer;
153
154 /// The format of the `albedo_texture_buffer`, if any.
155 std::optional<ComponentBatch> albedo_texture_format;
156
157 /// Optional class Ids for the vertices.
158 ///
159 /// The `components::ClassId` provides colors and labels if not specified explicitly.
160 std::optional<ComponentBatch> class_ids;
161
162 public:
163 /// The name of the archetype as used in `ComponentDescriptor`s.
164 static constexpr const char ArchetypeName[] = "rerun.archetypes.Mesh3D";
165
166 /// `ComponentDescriptor` for the `vertex_positions` field.
168 ArchetypeName, "Mesh3D:vertex_positions",
170 );
171 /// `ComponentDescriptor` for the `triangle_indices` field.
173 ArchetypeName, "Mesh3D:triangle_indices",
175 );
176 /// `ComponentDescriptor` for the `vertex_normals` field.
178 ArchetypeName, "Mesh3D:vertex_normals",
180 );
181 /// `ComponentDescriptor` for the `vertex_colors` field.
184 );
185 /// `ComponentDescriptor` for the `vertex_texcoords` field.
187 ArchetypeName, "Mesh3D:vertex_texcoords",
189 );
190 /// `ComponentDescriptor` for the `albedo_factor` field.
192 ArchetypeName, "Mesh3D:albedo_factor",
194 );
195 /// `ComponentDescriptor` for the `face_rendering` field.
197 ArchetypeName, "Mesh3D:face_rendering",
199 );
200 /// `ComponentDescriptor` for the `albedo_texture_buffer` field.
202 ArchetypeName, "Mesh3D:albedo_texture_buffer",
204 );
205 /// `ComponentDescriptor` for the `albedo_texture_format` field.
207 ArchetypeName, "Mesh3D:albedo_texture_format",
209 );
210 /// `ComponentDescriptor` for the `class_ids` field.
213 );
214
215 public:
216 Mesh3D() = default;
217 Mesh3D(Mesh3D&& other) = default;
218 Mesh3D(const Mesh3D& other) = default;
219 Mesh3D& operator=(const Mesh3D& other) = default;
220 Mesh3D& operator=(Mesh3D&& other) = default;
221
222 explicit Mesh3D(Collection<rerun::components::Position3D> _vertex_positions)
223 : vertex_positions(ComponentBatch::from_loggable(
224 std::move(_vertex_positions), Descriptor_vertex_positions
225 )
226 .value_or_throw()) {}
227
228 /// Update only some specific fields of a `Mesh3D`.
230 return Mesh3D();
231 }
232
233 /// Clear all the fields of a `Mesh3D`.
235
236 /// The positions of each vertex.
237 ///
238 /// If no `triangle_indices` are specified, then each triplet of positions is interpreted as a triangle.
240 const Collection<rerun::components::Position3D>& _vertex_positions
241 ) && {
244 .value_or_throw();
245 return std::move(*this);
246 }
247
248 /// Optional indices for the triangles that make up the mesh.
251 ) && {
254 .value_or_throw();
255 return std::move(*this);
256 }
257
258 /// An optional normal for each vertex.
260 ) && {
263 .value_or_throw();
264 return std::move(*this);
265 }
266
267 /// An optional color for each vertex.
268 ///
269 /// The alpha channel is ignored.
272 .value_or_throw();
273 return std::move(*this);
274 }
275
276 /// An optional uv texture coordinate for each vertex.
278 const Collection<rerun::components::Texcoord2D>& _vertex_texcoords
279 ) && {
282 .value_or_throw();
283 return std::move(*this);
284 }
285
286 /// A color multiplier applied to the whole mesh.
287 ///
288 /// Alpha channel governs the overall mesh transparency.
291 .value_or_throw();
292 return std::move(*this);
293 }
294
295 /// This method makes it possible to pack multiple `albedo_factor` in a single component batch.
296 ///
297 /// This only makes sense when used in conjunction with `columns`. `with_albedo_factor` should
298 /// be used when logging a single row's worth of data.
301 ) && {
303 .value_or_throw();
304 return std::move(*this);
305 }
306
307 /// Determines which faces of the mesh are rendered.
308 ///
309 /// The default is `components::MeshFaceRendering::DoubleSided`, meaning both front and back faces are shown.
313 .value_or_throw();
314 return std::move(*this);
315 }
316
317 /// This method makes it possible to pack multiple `face_rendering` in a single component batch.
318 ///
319 /// This only makes sense when used in conjunction with `columns`. `with_face_rendering` should
320 /// be used when logging a single row's worth of data.
323 ) && {
326 .value_or_throw();
327 return std::move(*this);
328 }
329
330 /// Optional albedo texture.
331 ///
332 /// Used with the `components::Texcoord2D` of the mesh.
333 ///
334 /// Currently supports only sRGB(A) textures, ignoring alpha.
335 /// (meaning that the tensor must have 3 or 4 channels and use the `u8` format)
336 ///
337 /// The alpha channel is ignored.
339 const rerun::components::ImageBuffer& _albedo_texture_buffer
340 ) && {
342 _albedo_texture_buffer,
344 )
345 .value_or_throw();
346 return std::move(*this);
347 }
348
349 /// This method makes it possible to pack multiple `albedo_texture_buffer` in a single component batch.
350 ///
351 /// This only makes sense when used in conjunction with `columns`. `with_albedo_texture_buffer` should
352 /// be used when logging a single row's worth of data.
354 const Collection<rerun::components::ImageBuffer>& _albedo_texture_buffer
355 ) && {
357 _albedo_texture_buffer,
359 )
360 .value_or_throw();
361 return std::move(*this);
362 }
363
364 /// The format of the `albedo_texture_buffer`, if any.
366 const rerun::components::ImageFormat& _albedo_texture_format
367 ) && {
369 _albedo_texture_format,
371 )
372 .value_or_throw();
373 return std::move(*this);
374 }
375
376 /// This method makes it possible to pack multiple `albedo_texture_format` in a single component batch.
377 ///
378 /// This only makes sense when used in conjunction with `columns`. `with_albedo_texture_format` should
379 /// be used when logging a single row's worth of data.
381 const Collection<rerun::components::ImageFormat>& _albedo_texture_format
382 ) && {
384 _albedo_texture_format,
386 )
387 .value_or_throw();
388 return std::move(*this);
389 }
390
391 /// Optional class Ids for the vertices.
392 ///
393 /// The `components::ClassId` provides colors and labels if not specified explicitly.
395 class_ids =
396 ComponentBatch::from_loggable(_class_ids, Descriptor_class_ids).value_or_throw();
397 return std::move(*this);
398 }
399
400 /// Partitions the component data into multiple sub-batches.
401 ///
402 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
403 /// instead, via `ComponentBatch::partitioned`.
404 ///
405 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
406 ///
407 /// The specified `lengths` must sum to the total length of the component batch.
409
410 /// Partitions the component data into unit-length sub-batches.
411 ///
412 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
413 /// where `n` is automatically guessed.
415 };
416
417} // namespace rerun::archetypes
418
419namespace rerun {
420 /// \private
421 template <typename T>
422 struct AsComponents;
423
424 /// \private
425 template <>
426 struct AsComponents<archetypes::Mesh3D> {
427 /// Serialize all set component batches.
428 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Mesh3D& archetype);
429 };
430} // 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
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:114
static constexpr auto Descriptor_vertex_texcoords
ComponentDescriptor for the vertex_texcoords field.
Definition mesh3d.hpp:186
static constexpr auto Descriptor_albedo_texture_format
ComponentDescriptor for the albedo_texture_format field.
Definition mesh3d.hpp:206
Mesh3D with_albedo_texture_format(const rerun::components::ImageFormat &_albedo_texture_format) &&
The format of the albedo_texture_buffer, if any.
Definition mesh3d.hpp:365
static constexpr auto Descriptor_class_ids
ComponentDescriptor for the class_ids field.
Definition mesh3d.hpp:211
Mesh3D with_triangle_indices(const Collection< rerun::components::TriangleIndices > &_triangle_indices) &&
Optional indices for the triangles that make up the mesh.
Definition mesh3d.hpp:249
static constexpr auto Descriptor_face_rendering
ComponentDescriptor for the face_rendering field.
Definition mesh3d.hpp:196
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:380
static constexpr auto Descriptor_triangle_indices
ComponentDescriptor for the triangle_indices field.
Definition mesh3d.hpp:172
static constexpr auto Descriptor_vertex_colors
ComponentDescriptor for the vertex_colors field.
Definition mesh3d.hpp:182
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition mesh3d.hpp:164
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:137
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:321
static Mesh3D update_fields()
Update only some specific fields of a Mesh3D.
Definition mesh3d.hpp:229
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:277
static constexpr auto Descriptor_vertex_normals
ComponentDescriptor for the vertex_normals field.
Definition mesh3d.hpp:177
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:142
Mesh3D with_vertex_normals(const Collection< rerun::components::Vector3D > &_vertex_normals) &&
An optional normal for each vertex.
Definition mesh3d.hpp:259
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:353
static constexpr auto Descriptor_vertex_positions
ComponentDescriptor for the vertex_positions field.
Definition mesh3d.hpp:167
static constexpr auto Descriptor_albedo_texture_buffer
ComponentDescriptor for the albedo_texture_buffer field.
Definition mesh3d.hpp:201
std::optional< ComponentBatch > vertex_texcoords
An optional uv texture coordinate for each vertex.
Definition mesh3d.hpp:132
std::optional< ComponentBatch > vertex_positions
The positions of each vertex.
Definition mesh3d.hpp:118
Mesh3D with_albedo_factor(const rerun::components::AlbedoFactor &_albedo_factor) &&
A color multiplier applied to the whole mesh.
Definition mesh3d.hpp:289
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:299
static constexpr auto Descriptor_albedo_factor
ComponentDescriptor for the albedo_factor field.
Definition mesh3d.hpp:191
std::optional< ComponentBatch > class_ids
Optional class Ids for the vertices.
Definition mesh3d.hpp:160
std::optional< ComponentBatch > albedo_texture_buffer
Optional albedo texture.
Definition mesh3d.hpp:152
std::optional< ComponentBatch > vertex_colors
An optional color for each vertex.
Definition mesh3d.hpp:129
Mesh3D with_vertex_colors(const Collection< rerun::components::Color > &_vertex_colors) &&
An optional color for each vertex.
Definition mesh3d.hpp:270
Mesh3D with_class_ids(const Collection< rerun::components::ClassId > &_class_ids) &&
Optional class Ids for the vertices.
Definition mesh3d.hpp:394
Mesh3D with_vertex_positions(const Collection< rerun::components::Position3D > &_vertex_positions) &&
The positions of each vertex.
Definition mesh3d.hpp:239
Mesh3D with_face_rendering(const rerun::components::MeshFaceRendering &_face_rendering) &&
Determines which faces of the mesh are rendered.
Definition mesh3d.hpp:310
std::optional< ComponentBatch > vertex_normals
An optional normal for each vertex.
Definition mesh3d.hpp:124
std::optional< ComponentBatch > triangle_indices
Optional indices for the triangles that make up the mesh.
Definition mesh3d.hpp:121
Mesh3D with_albedo_texture_buffer(const rerun::components::ImageBuffer &_albedo_texture_buffer) &&
Optional albedo texture.
Definition mesh3d.hpp:338
std::optional< ComponentBatch > albedo_texture_format
The format of the albedo_texture_buffer, if any.
Definition mesh3d.hpp:155
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