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_sdk_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]
41 /// <<" <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 /// // Set an up-axis:
51 /// rec.log_static("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP);
52 /// rec.log(
53 /// "world/asset",
54 /// rerun::Asset3D::from_file_path(path).value_or_throw()
55 /// );
56 /// }
57 /// ```
58 struct Asset3D {
59 /// The asset's bytes.
60 std::optional<ComponentBatch> blob;
61
62 /// The Media Type of the asset.
63 ///
64 /// Supported values:
65 /// * `model/gltf-binary`
66 /// * `model/gltf+json`
67 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
68 /// * `model/stl`
69 ///
70 /// If omitted, the viewer will try to guess from the data blob.
71 /// If it cannot guess, it won't be able to render the asset.
72 std::optional<ComponentBatch> media_type;
73
74 /// A color multiplier applied to the whole asset.
75 ///
76 /// For mesh who already have `albedo_factor` in materials,
77 /// it will be overwritten by actual `albedo_factor` of `archetypes::Asset3D` (if specified).
78 std::optional<ComponentBatch> albedo_factor;
79
80 public:
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, "Asset3D:media_type",
92 );
93 /// `ComponentDescriptor` for the `albedo_factor` field.
95 ArchetypeName, "Asset3D: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:87
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:58
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:60
std::optional< ComponentBatch > media_type
The Media Type of the asset.
Definition asset3d.hpp:72
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:78
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: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