Rerun C++ SDK
Loading...
Searching...
No Matches
asset3d.hpp
1// DO NOT EDIT! This file was auto-generated by crates/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/re_types/definitions/rerun/archetypes/asset3d.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../components/blob.hpp"
9#include "../components/media_type.hpp"
10#include "../components/out_of_tree_transform3d.hpp"
11#include "../data_cell.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`, etc.).
23 ///
24 /// ## Example
25 ///
26 /// ### Simple 3D asset
27 /// ![image](https://static.rerun.io/asset3d_simple/af238578188d3fd0de3e330212120e2842a8ddb2/full.png)
28 ///
29 /// ```cpp
30 /// #include <rerun.hpp>
31 ///
32 /// #include <filesystem>
33 /// #include <iostream>
34 /// #include <string>
35 ///
36 /// int main(int argc, char* argv[]) {
37 /// if (argc <2) {
38 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_asset.[gltf|glb|obj]>" <<std::endl;
39 /// return 1;
40 /// }
41 ///
42 /// const auto path = argv[1];
43 ///
44 /// const auto rec = rerun::RecordingStream("rerun_example_asset3d_simple");
45 /// rec.spawn().exit_on_failure();
46 ///
47 /// rec.log_timeless("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis
48 /// rec.log("world/asset", rerun::Asset3D::from_file(path).value_or_throw());
49 /// }
50 /// ```
51 struct Asset3D {
52 /// The asset's bytes.
54
55 /// The Media Type of the asset.
56 ///
57 /// Supported values:
58 /// * `model/gltf-binary`
59 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
60 ///
61 /// If omitted, the viewer will try to guess from the data blob.
62 /// If it cannot guess, it won't be able to render the asset.
63 std::optional<rerun::components::MediaType> media_type;
64
65 /// An out-of-tree transform.
66 ///
67 /// Applies a transformation to the asset itself without impacting its children.
68 std::optional<rerun::components::OutOfTreeTransform3D> transform;
69
70 public:
71 static constexpr const char IndicatorComponentName[] = "rerun.components.Asset3DIndicator";
72
73 /// Indicator component, used to identify the archetype when converting to a list of components.
75
76 public:
77 // Extensions to generated type defined in 'asset3d_ext.cpp'
78
79 static std::optional<rerun::components::MediaType> guess_media_type(
80 const std::filesystem::path& path
81 );
82
83 /// Creates a new `Asset3D` from the file contents at `path`.
84 ///
85 /// The `MediaType` will be guessed from the file extension.
86 ///
87 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
88 /// from the data at render-time. If it can't, rendering will fail with an error.
89 static Result<Asset3D> from_file(const std::filesystem::path& path);
90
91 /// Creates a new `Asset3D` from the given `bytes`.
92 ///
93 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
94 /// at render-time. If it can't, rendering will fail with an error.
96 rerun::Collection<uint8_t> bytes, std::optional<rerun::components::MediaType> media_type
97 ) {
98 // TODO(cmc): we could try and guess using magic bytes here, like rust does.
99 Asset3D asset = Asset3D(std::move(bytes));
100 asset.media_type = media_type;
101 return asset;
102 }
103
104 public:
105 Asset3D() = default;
106 Asset3D(Asset3D&& other) = default;
107
108 explicit Asset3D(rerun::components::Blob _blob) : blob(std::move(_blob)) {}
109
110 /// The Media Type of the asset.
111 ///
112 /// Supported values:
113 /// * `model/gltf-binary`
114 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
115 ///
116 /// If omitted, the viewer will try to guess from the data blob.
117 /// If it cannot guess, it won't be able to render the asset.
119 media_type = std::move(_media_type);
120 // See: https://github.com/rerun-io/rerun/issues/4027
121 RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
122 }
123
124 /// An out-of-tree transform.
125 ///
126 /// Applies a transformation to the asset itself without impacting its children.
128 transform = std::move(_transform);
129 // See: https://github.com/rerun-io/rerun/issues/4027
130 RERUN_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
131 }
132
133 /// Returns the number of primary instances of this archetype.
134 size_t num_instances() const {
135 return 1;
136 }
137 };
138
139} // namespace rerun::archetypes
140
141namespace rerun {
142 /// \private
143 template <typename T>
144 struct AsComponents;
145
146 /// \private
147 template <>
148 struct AsComponents<archetypes::Asset3D> {
149 /// Serialize all set component batches.
150 static Result<std::vector<DataCell>> serialize(const archetypes::Asset3D& archetype);
151 };
152} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:47
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:66
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:20
Archetype: A prepacked 3D asset (.gltf, .glb, .obj, etc.).
Definition asset3d.hpp:51
Asset3D with_transform(rerun::components::OutOfTreeTransform3D _transform) &&
An out-of-tree transform.
Definition asset3d.hpp:127
std::optional< rerun::components::MediaType > media_type
The Media Type of the asset.
Definition asset3d.hpp:63
static Result< Asset3D > from_file(const std::filesystem::path &path)
Creates a new Asset3D from the file contents at path.
std::optional< rerun::components::OutOfTreeTransform3D > transform
An out-of-tree transform.
Definition asset3d.hpp:68
rerun::components::Blob blob
The asset's bytes.
Definition asset3d.hpp:53
Asset3D with_media_type(rerun::components::MediaType _media_type) &&
The Media Type of the asset.
Definition asset3d.hpp:118
size_t num_instances() const
Returns the number of primary instances of this archetype.
Definition asset3d.hpp:134
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:95
Component: A binary blob of data.
Definition blob.hpp:21
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:23
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a utf8 strin...
Definition media_type.hpp:25
Component: An out-of-tree affine transform between two 3D spaces, represented in a given direction.
Definition out_of_tree_transform3d.hpp:22