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