Rerun C++ SDK
Loading...
Searching...
No Matches
asset3d.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/asset3d.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/blob.hpp"
11#include "../components/media_type.hpp"
12#include "../indicator_component.hpp"
13#include "../result.hpp"
14
15#include <cstdint>
16#include <filesystem>
17#include <optional>
18#include <utility>
19#include <vector>
20
21namespace rerun::archetypes {
22 /// **Archetype**: A prepacked 3D asset (`.gltf`, `.glb`, `.obj`, `.stl`, etc.).
23 ///
24 /// See also `archetypes::Mesh3D`.
25 ///
26 /// If there are multiple `archetypes::InstancePoses3D` instances logged to the same entity as a mesh,
27 /// an instance of the mesh will be drawn for each transform.
28 ///
29 /// ## Example
30 ///
31 /// ### Simple 3D asset
32 /// ![image](https://static.rerun.io/asset3d_simple/af238578188d3fd0de3e330212120e2842a8ddb2/full.png)
33 ///
34 /// ```cpp
35 /// #include <rerun.hpp>
36 ///
37 /// #include <iostream>
38 ///
39 /// int main(int argc, char* argv[]) {
40 /// if (argc <2) {
41 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_asset.[gltf|glb|obj|stl]>" <<std::endl;
42 /// return 1;
43 /// }
44 ///
45 /// const auto path = argv[1];
46 ///
47 /// const auto rec = rerun::RecordingStream("rerun_example_asset3d");
48 /// rec.spawn().exit_on_failure();
49 ///
50 /// rec.log_static("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis
51 /// rec.log("world/asset", rerun::Asset3D::from_file(path).value_or_throw());
52 /// }
53 /// ```
54 struct Asset3D {
55 /// The asset's bytes.
56 std::optional<ComponentBatch> blob;
57
58 /// The Media Type of the asset.
59 ///
60 /// Supported values:
61 /// * `model/gltf-binary`
62 /// * `model/gltf+json`
63 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
64 /// * `model/stl`
65 ///
66 /// If omitted, the viewer will try to guess from the data blob.
67 /// If it cannot guess, it won't be able to render the asset.
68 std::optional<ComponentBatch> media_type;
69
70 /// A color multiplier applied to the whole asset.
71 ///
72 /// For mesh who already have `albedo_factor` in materials,
73 /// it will be overwritten by actual `albedo_factor` of `archetypes::Asset3D` (if specified).
74 std::optional<ComponentBatch> albedo_factor;
75
76 public:
77 static constexpr const char IndicatorComponentName[] = "rerun.components.Asset3DIndicator";
78
79 /// Indicator component, used to identify the archetype when converting to a list of components.
81 /// The name of the archetype as used in `ComponentDescriptor`s.
82 static constexpr const char ArchetypeName[] = "rerun.archetypes.Asset3D";
83
84 /// `ComponentDescriptor` for the `blob` field.
85 static constexpr auto Descriptor_blob = ComponentDescriptor(
87 );
88 /// `ComponentDescriptor` for the `media_type` field.
90 ArchetypeName, "media_type",
92 );
93 /// `ComponentDescriptor` for the `albedo_factor` field.
95 ArchetypeName, "albedo_factor",
97 );
98
99 public: // START of extensions from asset3d_ext.cpp:
100 /// Creates a new `Asset3D` from the file contents at `path`.
101 ///
102 /// The `MediaType` will be guessed from the file extension.
103 ///
104 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
105 /// from the data at render-time. If it can't, rendering will fail with an error.
106 static Result<Asset3D> from_file(const std::filesystem::path& path);
107
108 /// Creates a new `Asset3D` from the given `bytes`.
109 ///
110 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
111 /// at render-time. If it can't, rendering will fail with an error.
114 std::optional<rerun::components::MediaType> media_type = {}
115 ) {
116 Asset3D asset = Asset3D(std::move(bytes));
117 // TODO(cmc): we could try and guess using magic bytes here, like rust does.
118 if (media_type.has_value()) {
119 return std::move(asset).with_media_type(media_type.value());
120 }
121 return asset;
122 }
123
124 // END of extensions from asset3d_ext.cpp, start of generated code:
125
126 public:
127 Asset3D() = default;
128 Asset3D(Asset3D&& other) = default;
129 Asset3D(const Asset3D& other) = default;
130 Asset3D& operator=(const Asset3D& other) = default;
131 Asset3D& operator=(Asset3D&& other) = default;
132
133 explicit Asset3D(rerun::components::Blob _blob)
134 : blob(ComponentBatch::from_loggable(std::move(_blob), Descriptor_blob).value_or_throw()
135 ) {}
136
137 /// Update only some specific fields of a `Asset3D`.
139 return Asset3D();
140 }
141
142 /// Clear all the fields of a `Asset3D`.
144
145 /// The asset's bytes.
147 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
148 return std::move(*this);
149 }
150
151 /// This method makes it possible to pack multiple `blob` in a single component batch.
152 ///
153 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
154 /// be used when logging a single row's worth of data.
156 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
157 return std::move(*this);
158 }
159
160 /// The Media Type of the asset.
161 ///
162 /// Supported values:
163 /// * `model/gltf-binary`
164 /// * `model/gltf+json`
165 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
166 /// * `model/stl`
167 ///
168 /// If omitted, the viewer will try to guess from the data blob.
169 /// If it cannot guess, it won't be able to render the asset.
171 media_type =
172 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
173 return std::move(*this);
174 }
175
176 /// This method makes it possible to pack multiple `media_type` in a single component batch.
177 ///
178 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
179 /// be used when logging a single row's worth of data.
181 ) && {
182 media_type =
183 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
184 return std::move(*this);
185 }
186
187 /// A color multiplier applied to the whole asset.
188 ///
189 /// For mesh who already have `albedo_factor` in materials,
190 /// it will be overwritten by actual `albedo_factor` of `archetypes::Asset3D` (if specified).
193 .value_or_throw();
194 return std::move(*this);
195 }
196
197 /// This method makes it possible to pack multiple `albedo_factor` in a single component batch.
198 ///
199 /// This only makes sense when used in conjunction with `columns`. `with_albedo_factor` should
200 /// be used when logging a single row's worth of data.
203 ) && {
205 .value_or_throw();
206 return std::move(*this);
207 }
208
209 /// Partitions the component data into multiple sub-batches.
210 ///
211 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
212 /// instead, via `ComponentBatch::partitioned`.
213 ///
214 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
215 ///
216 /// The specified `lengths` must sum to the total length of the component batch.
218
219 /// Partitions the component data into unit-length sub-batches.
220 ///
221 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
222 /// where `n` is automatically guessed.
224 };
225
226} // namespace rerun::archetypes
227
228namespace rerun {
229 /// \private
230 template <typename T>
231 struct AsComponents;
232
233 /// \private
234 template <>
235 struct AsComponents<archetypes::Asset3D> {
236 /// Serialize all set component batches.
237 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Asset3D& archetype);
238 };
239} // 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
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 prepacked 3D asset (.gltf, .glb, .obj, .stl, etc.).
Definition asset3d.hpp:54
static Asset3D from_bytes(rerun::Collection< uint8_t > bytes, std::optional< rerun::components::MediaType > media_type={})
Creates a new Asset3D from the given bytes.
Definition asset3d.hpp:112
static Asset3D update_fields()
Update only some specific fields of a Asset3D.
Definition asset3d.hpp:138
static Asset3D clear_fields()
Clear all the fields of a Asset3D.
static constexpr auto Descriptor_media_type
ComponentDescriptor for the media_type field.
Definition asset3d.hpp:89
static Result< Asset3D > from_file(const std::filesystem::path &path)
Creates a new Asset3D from the file contents at path.
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
static constexpr auto Descriptor_albedo_factor
ComponentDescriptor for the albedo_factor field.
Definition asset3d.hpp:94
static constexpr auto Descriptor_blob
ComponentDescriptor for the blob field.
Definition asset3d.hpp:85
Asset3D with_many_media_type(const Collection< rerun::components::MediaType > &_media_type) &&
This method makes it possible to pack multiple media_type in a single component batch.
Definition asset3d.hpp:180
Asset3D with_many_blob(const Collection< rerun::components::Blob > &_blob) &&
This method makes it possible to pack multiple blob in a single component batch.
Definition asset3d.hpp:155
std::optional< ComponentBatch > blob
The asset's bytes.
Definition asset3d.hpp:56
std::optional< ComponentBatch > media_type
The Media Type of the asset.
Definition asset3d.hpp:68
Asset3D 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 asset3d.hpp:201
Asset3D with_media_type(const rerun::components::MediaType &_media_type) &&
The Media Type of the asset.
Definition asset3d.hpp:170
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Asset3D with_blob(const rerun::components::Blob &_blob) &&
The asset's bytes.
Definition asset3d.hpp:146
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition asset3d.hpp:82
std::optional< ComponentBatch > albedo_factor
A color multiplier applied to the whole asset.
Definition asset3d.hpp:74
Asset3D with_albedo_factor(const rerun::components::AlbedoFactor &_albedo_factor) &&
A color multiplier applied to the whole asset.
Definition asset3d.hpp:191
Component: A color multiplier, usually applied to a whole entity, e.g. a mesh.
Definition albedo_factor.hpp:15
Component: A binary blob of data.
Definition blob.hpp:17
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:21