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`, `.stl`, 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|stl]>" <<std::endl;
39 /// return 1;
40 /// }
41 ///
42 /// const auto path = argv[1];
43 ///
44 /// const auto rec = rerun::RecordingStream("rerun_example_asset3d");
45 /// rec.spawn().exit_on_failure();
46 ///
47 /// rec.log_static("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/gltf+json`
60 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
61 /// * `model/stl`
62 ///
63 /// If omitted, the viewer will try to guess from the data blob.
64 /// If it cannot guess, it won't be able to render the asset.
65 std::optional<rerun::components::MediaType> media_type;
66
67 /// An out-of-tree transform.
68 ///
69 /// Applies a transformation to the asset itself without impacting its children.
70 std::optional<rerun::components::OutOfTreeTransform3D> transform;
71
72 public:
73 static constexpr const char IndicatorComponentName[] = "rerun.components.Asset3DIndicator";
74
75 /// Indicator component, used to identify the archetype when converting to a list of components.
77
78 public:
79 // Extensions to generated type defined in 'asset3d_ext.cpp'
80
81 static std::optional<rerun::components::MediaType> guess_media_type(
82 const std::filesystem::path& path
83 );
84
85 /// Creates a new `Asset3D` from the file contents at `path`.
86 ///
87 /// The `MediaType` will be guessed from the file extension.
88 ///
89 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
90 /// from the data at render-time. If it can't, rendering will fail with an error.
91 static Result<Asset3D> from_file(const std::filesystem::path& path);
92
93 /// Creates a new `Asset3D` from the given `bytes`.
94 ///
95 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
96 /// at render-time. If it can't, rendering will fail with an error.
98 rerun::Collection<uint8_t> bytes, std::optional<rerun::components::MediaType> media_type
99 ) {
100 // TODO(cmc): we could try and guess using magic bytes here, like rust does.
101 Asset3D asset = Asset3D(std::move(bytes));
102 asset.media_type = media_type;
103 return asset;
104 }
105
106 public:
107 Asset3D() = default;
108 Asset3D(Asset3D&& other) = default;
109
110 explicit Asset3D(rerun::components::Blob _blob) : blob(std::move(_blob)) {}
111
112 /// The Media Type of the asset.
113 ///
114 /// Supported values:
115 /// * `model/gltf-binary`
116 /// * `model/gltf+json`
117 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
118 /// * `model/stl`
119 ///
120 /// If omitted, the viewer will try to guess from the data blob.
121 /// If it cannot guess, it won't be able to render the asset.
123 media_type = std::move(_media_type);
124 // See: https://github.com/rerun-io/rerun/issues/4027
125 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
126 }
127
128 /// An out-of-tree transform.
129 ///
130 /// Applies a transformation to the asset itself without impacting its children.
132 transform = std::move(_transform);
133 // See: https://github.com/rerun-io/rerun/issues/4027
134 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
135 }
136 };
137
138} // namespace rerun::archetypes
139
140namespace rerun {
141 /// \private
142 template <typename T>
143 struct AsComponents;
144
145 /// \private
146 template <>
147 struct AsComponents<archetypes::Asset3D> {
148 /// Serialize all set component batches.
149 static Result<std::vector<DataCell>> serialize(const archetypes::Asset3D& archetype);
150 };
151} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:46
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:72
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:21
Archetype: A prepacked 3D asset (.gltf, .glb, .obj, .stl, etc.).
Definition asset3d.hpp:51
Asset3D with_transform(rerun::components::OutOfTreeTransform3D _transform) &&
An out-of-tree transform.
Definition asset3d.hpp:131
std::optional< rerun::components::MediaType > media_type
The Media Type of the asset.
Definition asset3d.hpp:65
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:70
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:122
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:97
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:19
Component: An out-of-tree affine transform between two 3D spaces, represented in a given direction.
Definition out_of_tree_transform3d.hpp:16