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