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/build/re_type_definitions/rerun/archetypes/asset3d.def.rs".
3
4#pragma once
5
6#include "../archetype_utils.hpp"
7#include "../collection.hpp"
8#include "../component_batch.hpp"
9#include "../component_column.hpp"
10#include "../components/albedo_factor.hpp"
11#include "../components/blob.hpp"
12#include "../components/media_type.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 /// Meshes, or parts of meshes, without vertex normals get flat normals computed by the Viewer,
30 /// i.e. each triangle is shaded with its own face normal.
31 /// To render an asset unlit instead, give it all-zero vertex normals.
32 ///
33 /// ## Example
34 ///
35 /// ### Simple 3D asset
36 /// ![image](https://static.rerun.io/asset3d_simple/af238578188d3fd0de3e330212120e2842a8ddb2/full.png)
37 ///
38 /// ```cpp
39 /// #include <rerun.hpp>
40 ///
41 /// #include <iostream>
42 ///
43 /// int main(int argc, char* argv[]) {
44 /// if (argc <2) {
45 /// std::cerr <<"Usage: " <<argv[0]
46 /// <<" <path_to_asset.[gltf|glb|obj|stl]>" <<std::endl;
47 /// return 1;
48 /// }
49 ///
50 /// const auto path = argv[1];
51 ///
52 /// const auto rec = rerun::RecordingStream("rerun_example_asset3d");
53 /// rec.spawn().exit_on_failure();
54 ///
55 /// // Set the 3D view's up direction:
56 /// rec.log_static("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP);
57 /// rec.log(
58 /// "world/asset",
59 /// rerun::Asset3D::from_file_path(path).value_or_throw()
60 /// );
61 /// }
62 /// ```
63 struct Asset3D {
64 /// The asset's bytes.
65 std::optional<ComponentBatch> blob;
66
67 /// The Media Type of the asset.
68 ///
69 /// Supported values:
70 /// * `application/x-ply`
71 /// * `model/gltf-binary`
72 /// * `model/gltf+json`
73 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
74 /// * `model/stl`
75 ///
76 /// If omitted, the viewer will try to guess from the data blob.
77 /// If it cannot guess, it won't be able to render the asset.
78 std::optional<ComponentBatch> media_type;
79
80 /// A color multiplier applied to the whole asset.
81 ///
82 /// For mesh who already have `albedo_factor` in materials,
83 /// it will be overwritten by actual `albedo_factor` of `archetypes::Asset3D` (if specified).
84 std::optional<ComponentBatch> albedo_factor;
85
86 public:
87 /// The name of the archetype as used in `ComponentDescriptor`s.
88 static constexpr const char ArchetypeName[] = "rerun.archetypes.Asset3D";
89
90 /// `ComponentDescriptor` for the `blob` field.
91 static constexpr auto Descriptor_blob = ComponentDescriptor(
93 );
94 /// `ComponentDescriptor` for the `media_type` field.
96 ArchetypeName, "Asset3D:media_type",
98 );
99 /// `ComponentDescriptor` for the `albedo_factor` field.
101 ArchetypeName, "Asset3D:albedo_factor",
103 );
104
105 public: // START of extensions from asset3d_ext.cpp:
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 /// \deprecated Use `from_file_path` instead.
113 [[deprecated("Use `from_file_path` instead")]] static Result<Asset3D> from_file(
114 const std::filesystem::path& path
115 );
116
117 /// Creates a new `Asset3D` from the file contents at `path`.
118 ///
119 /// The `MediaType` will be guessed from the file extension.
120 ///
121 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
122 /// from the data at render-time. If it can't, rendering will fail with an error.
123 static Result<Asset3D> from_file_path(const std::filesystem::path& path);
124
125 /// Creates a new `Asset3D` from the given `bytes`.
126 ///
127 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
128 /// at render-time. If it can't, rendering will fail with an error.
129 /// \deprecated Use `from_file_contents` instead.
130 [[deprecated("Use `from_file_contents` instead")]] static Asset3D from_bytes(
132 std::optional<rerun::components::MediaType> media_type = {}
133 ) {
134 return from_file_contents(bytes, media_type);
135 }
136
137 /// Creates a new `Asset3D` from the given `bytes`.
138 ///
139 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
140 /// at render-time. If it can't, rendering will fail with an error.
143 std::optional<rerun::components::MediaType> media_type = {}
144 ) {
145 Asset3D asset = Asset3D(std::move(bytes));
146 // TODO(cmc): we could try and guess using magic bytes here, like rust does.
147 if (media_type.has_value()) {
148 return std::move(asset).with_media_type(media_type.value());
149 }
150 return asset;
151 }
152
153 // END of extensions from asset3d_ext.cpp, start of generated code:
154
155 public:
156 Asset3D() = default;
157 Asset3D(Asset3D&& other) = default;
158 Asset3D(const Asset3D& other) = default;
159 Asset3D& operator=(const Asset3D& other) = default;
160 Asset3D& operator=(Asset3D&& other) = default;
161
162 explicit Asset3D(rerun::components::Blob _blob)
163 : blob(ComponentBatch::from_loggable(std::move(_blob), Descriptor_blob).value_or_throw()
164 ) {}
165
166 /// Update only some specific fields of a `Asset3D`.
168 return Asset3D();
169 }
170
171 /// Clear all the fields of a `Asset3D`.
173
174 /// The asset's bytes.
176 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
177 return std::move(*this);
178 }
179
180 /// This method makes it possible to pack multiple `blob` in a single component batch.
181 ///
182 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
183 /// be used when logging a single row's worth of data.
185 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
186 return std::move(*this);
187 }
188
189 /// The Media Type of the asset.
190 ///
191 /// Supported values:
192 /// * `application/x-ply`
193 /// * `model/gltf-binary`
194 /// * `model/gltf+json`
195 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
196 /// * `model/stl`
197 ///
198 /// If omitted, the viewer will try to guess from the data blob.
199 /// If it cannot guess, it won't be able to render the asset.
201 media_type =
202 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
203 return std::move(*this);
204 }
205
206 /// This method makes it possible to pack multiple `media_type` in a single component batch.
207 ///
208 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
209 /// be used when logging a single row's worth of data.
211 ) && {
212 media_type =
213 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
214 return std::move(*this);
215 }
216
217 /// A color multiplier applied to the whole asset.
218 ///
219 /// For mesh who already have `albedo_factor` in materials,
220 /// it will be overwritten by actual `albedo_factor` of `archetypes::Asset3D` (if specified).
223 .value_or_throw();
224 return std::move(*this);
225 }
226
227 /// This method makes it possible to pack multiple `albedo_factor` in a single component batch.
228 ///
229 /// This only makes sense when used in conjunction with `columns`. `with_albedo_factor` should
230 /// be used when logging a single row's worth of data.
233 ) && {
235 .value_or_throw();
236 return std::move(*this);
237 }
238
239 /// Partitions the component data into multiple sub-batches.
240 ///
241 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
242 /// instead, via `ComponentBatch::partitioned`.
243 ///
244 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
245 ///
246 /// The specified `lengths` must sum to the total length of the component batch.
248 return detail::partition_batches({&blob, &media_type, &albedo_factor}, lengths_)
249 .value_or_throw();
250 }
251
252 /// Partitions the component data into unit-length sub-batches.
253 ///
254 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
255 /// where `n` is automatically guessed.
257 return detail::partition_batches_of_unit_length({&blob, &media_type, &albedo_factor})
258 .value_or_throw();
259 }
260 };
261
262} // namespace rerun::archetypes
263
264namespace rerun {
265 /// \private
266 template <typename T>
267 struct AsComponents;
268
269 /// \private
270 template <>
271 struct AsComponents<archetypes::Asset3D> {
272 /// Serialize all set component batches.
273 static Result<Collection<ComponentBatch>> as_batches(const archetypes::Asset3D& archetype) {
274 return detail::collect_batches(
275 {&archetype.blob, &archetype.media_type, &archetype.albedo_factor}
276 );
277 }
278 };
279} // 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:90
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
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:63
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:130
static Asset3D update_fields()
Update only some specific fields of a Asset3D.
Definition asset3d.hpp:167
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:95
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.
Definition asset3d.hpp:256
static constexpr auto Descriptor_albedo_factor
ComponentDescriptor for the albedo_factor field.
Definition asset3d.hpp:100
static constexpr auto Descriptor_blob
ComponentDescriptor for the blob field.
Definition asset3d.hpp:91
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:210
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:184
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:141
std::optional< ComponentBatch > blob
The asset's bytes.
Definition asset3d.hpp:65
std::optional< ComponentBatch > media_type
The Media Type of the asset.
Definition asset3d.hpp:78
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:231
Asset3D with_media_type(const rerun::components::MediaType &_media_type) &&
The Media Type of the asset.
Definition asset3d.hpp:200
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Definition asset3d.hpp:247
Asset3D with_blob(const rerun::components::Blob &_blob) &&
The asset's bytes.
Definition asset3d.hpp:175
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition asset3d.hpp:88
std::optional< ComponentBatch > albedo_factor
A color multiplier applied to the whole asset.
Definition asset3d.hpp:84
Asset3D with_albedo_factor(const rerun::components::AlbedoFactor &_albedo_factor) &&
A color multiplier applied to the whole asset.
Definition asset3d.hpp:221
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