Rerun C++ SDK
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
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(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 /// \deprecated Use `from_file_path` instead.
107 [[deprecated("Use `from_file_path` instead")]] static Result<Asset3D> from_file(
108 const std::filesystem::path& path
109 );
110
111 /// Creates a new `Asset3D` from the file contents at `path`.
112 ///
113 /// The `MediaType` will be guessed from the file extension.
114 ///
115 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
116 /// from the data at render-time. If it can't, rendering will fail with an error.
117 static Result<Asset3D> from_file_path(const std::filesystem::path& path);
118
119 /// Creates a new `Asset3D` from the given `bytes`.
120 ///
121 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
122 /// at render-time. If it can't, rendering will fail with an error.
123 /// \deprecated Use `from_file_contents` instead.
124 [[deprecated("Use `from_file_contents` instead")]] static Asset3D from_bytes(
126 std::optional<rerun::components::MediaType> media_type = {}
127 ) {
128 return from_file_contents(bytes, media_type);
129 }
130
131 /// Creates a new `Asset3D` from the given `bytes`.
132 ///
133 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
134 /// at render-time. If it can't, rendering will fail with an error.
137 std::optional<rerun::components::MediaType> media_type = {}
138 ) {
139 Asset3D asset = Asset3D(std::move(bytes));
140 // TODO(cmc): we could try and guess using magic bytes here, like rust does.
141 if (media_type.has_value()) {
142 return std::move(asset).with_media_type(media_type.value());
143 }
144 return asset;
145 }
146
147 // END of extensions from asset3d_ext.cpp, start of generated code:
148
149 public:
150 Asset3D() = default;
151 Asset3D(Asset3D&& other) = default;
152 Asset3D(const Asset3D& other) = default;
153 Asset3D& operator=(const Asset3D& other) = default;
154 Asset3D& operator=(Asset3D&& other) = default;
155
156 explicit Asset3D(rerun::components::Blob _blob)
157 : blob(ComponentBatch::from_loggable(std::move(_blob), Descriptor_blob).value_or_throw()
158 ) {}
159
160 /// Update only some specific fields of a `Asset3D`.
162 return Asset3D();
163 }
164
165 /// Clear all the fields of a `Asset3D`.
167
168 /// The asset's bytes.
170 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
171 return std::move(*this);
172 }
173
174 /// This method makes it possible to pack multiple `blob` in a single component batch.
175 ///
176 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
177 /// be used when logging a single row's worth of data.
179 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
180 return std::move(*this);
181 }
182
183 /// The Media Type of the asset.
184 ///
185 /// Supported values:
186 /// * `model/gltf-binary`
187 /// * `model/gltf+json`
188 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
189 /// * `model/stl`
190 ///
191 /// If omitted, the viewer will try to guess from the data blob.
192 /// If it cannot guess, it won't be able to render the asset.
194 media_type =
195 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
196 return std::move(*this);
197 }
198
199 /// This method makes it possible to pack multiple `media_type` in a single component batch.
200 ///
201 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
202 /// be used when logging a single row's worth of data.
204 ) && {
205 media_type =
206 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
207 return std::move(*this);
208 }
209
210 /// A color multiplier applied to the whole asset.
211 ///
212 /// For mesh who already have `albedo_factor` in materials,
213 /// it will be overwritten by actual `albedo_factor` of `archetypes::Asset3D` (if specified).
216 .value_or_throw();
217 return std::move(*this);
218 }
219
220 /// This method makes it possible to pack multiple `albedo_factor` in a single component batch.
221 ///
222 /// This only makes sense when used in conjunction with `columns`. `with_albedo_factor` should
223 /// be used when logging a single row's worth of data.
226 ) && {
228 .value_or_throw();
229 return std::move(*this);
230 }
231
232 /// Partitions the component data into multiple sub-batches.
233 ///
234 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
235 /// instead, via `ComponentBatch::partitioned`.
236 ///
237 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
238 ///
239 /// The specified `lengths` must sum to the total length of the component batch.
241
242 /// Partitions the component data into unit-length sub-batches.
243 ///
244 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
245 /// where `n` is automatically guessed.
247 };
248
249} // namespace rerun::archetypes
250
251namespace rerun {
252 /// \private
253 template <typename T>
254 struct AsComponents;
255
256 /// \private
257 template <>
258 struct AsComponents<archetypes::Asset3D> {
259 /// Serialize all set component batches.
260 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Asset3D& archetype);
261 };
262} // 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:124
static Asset3D update_fields()
Update only some specific fields of a Asset3D.
Definition asset3d.hpp:161
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:203
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:178
static Result< Asset3D > from_file_path(const std::filesystem::path &path)
Creates a new Asset3D from the file contents at path.
static Asset3D from_file_contents(rerun::Collection< uint8_t > bytes, std::optional< rerun::components::MediaType > media_type={})
Creates a new Asset3D from the given bytes.
Definition asset3d.hpp:135
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:224
Asset3D with_media_type(const rerun::components::MediaType &_media_type) &&
The Media Type of the asset.
Definition asset3d.hpp:193
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:169
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:214
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