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_types/definitions/rerun/archetypes/asset3d.fbs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../compiler_utils.hpp"
8#include "../component_batch.hpp"
9#include "../components/blob.hpp"
10#include "../components/media_type.hpp"
11#include "../indicator_component.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 <filesystem>
37 /// #include <iostream>
38 /// #include <string>
39 ///
40 /// int main(int argc, char* argv[]) {
41 /// if (argc <2) {
42 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_asset.[gltf|glb|obj|stl]>" <<std::endl;
43 /// return 1;
44 /// }
45 ///
46 /// const auto path = argv[1];
47 ///
48 /// const auto rec = rerun::RecordingStream("rerun_example_asset3d");
49 /// rec.spawn().exit_on_failure();
50 ///
51 /// rec.log_static("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis
52 /// rec.log("world/asset", rerun::Asset3D::from_file(path).value_or_throw());
53 /// }
54 /// ```
55 struct Asset3D {
56 /// The asset's bytes.
58
59 /// The Media Type of the asset.
60 ///
61 /// Supported values:
62 /// * `model/gltf-binary`
63 /// * `model/gltf+json`
64 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
65 /// * `model/stl`
66 ///
67 /// If omitted, the viewer will try to guess from the data blob.
68 /// If it cannot guess, it won't be able to render the asset.
69 std::optional<rerun::components::MediaType> media_type;
70
71 public:
72 static constexpr const char IndicatorComponentName[] = "rerun.components.Asset3DIndicator";
73
74 /// Indicator component, used to identify the archetype when converting to a list of components.
76
77 public: // START of extensions from asset3d_ext.cpp:
78 /// Creates a new `Asset3D` from the file contents at `path`.
79 ///
80 /// The `MediaType` will be guessed from the file extension.
81 ///
82 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
83 /// from the data at render-time. If it can't, rendering will fail with an error.
84 static Result<Asset3D> from_file(const std::filesystem::path& path);
85
86 /// Creates a new `Asset3D` from the given `bytes`.
87 ///
88 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
89 /// at render-time. If it can't, rendering will fail with an error.
92 std::optional<rerun::components::MediaType> media_type = {}
93 ) {
94 // TODO(cmc): we could try and guess using magic bytes here, like rust does.
95 Asset3D asset = Asset3D(std::move(bytes));
96 asset.media_type = media_type;
97 return asset;
98 }
99
100 static std::optional<rerun::components::MediaType> guess_media_type(
101 const std::filesystem::path& path
102 );
103
104 // END of extensions from asset3d_ext.cpp, start of generated code:
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
129} // namespace rerun::archetypes
130
131namespace rerun {
132 /// \private
133 template <typename T>
134 struct AsComponents;
135
136 /// \private
137 template <>
138 struct AsComponents<archetypes::Asset3D> {
139 /// Serialize all set component batches.
140 static Result<std::vector<ComponentBatch>> serialize(const archetypes::Asset3D& archetype);
141 };
142} // 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:72
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:22
Archetype: A prepacked 3D asset (.gltf, .glb, .obj, .stl, etc.).
Definition asset3d.hpp:55
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:90
std::optional< rerun::components::MediaType > media_type
The Media Type of the asset.
Definition asset3d.hpp:69
static Result< Asset3D > from_file(const std::filesystem::path &path)
Creates a new Asset3D from the file contents at path.
rerun::components::Blob blob
The asset's bytes.
Definition asset3d.hpp:57
Asset3D with_media_type(rerun::components::MediaType _media_type) &&
The Media Type of the asset.
Definition asset3d.hpp:122
Component: A binary blob of data.
Definition blob.hpp:16
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:30
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:19