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 <iostream>
37 ///
38 /// int main(int argc, char* argv[]) {
39 /// if (argc <2) {
40 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_asset.[gltf|glb|obj|stl]>" <<std::endl;
41 /// return 1;
42 /// }
43 ///
44 /// const auto path = argv[1];
45 ///
46 /// const auto rec = rerun::RecordingStream("rerun_example_asset3d");
47 /// rec.spawn().exit_on_failure();
48 ///
49 /// rec.log_static("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis
50 /// rec.log("world/asset", rerun::Asset3D::from_file(path).value_or_throw());
51 /// }
52 /// ```
53 struct Asset3D {
54 /// The asset's bytes.
56
57 /// The Media Type of the asset.
58 ///
59 /// Supported values:
60 /// * `model/gltf-binary`
61 /// * `model/gltf+json`
62 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
63 /// * `model/stl`
64 ///
65 /// If omitted, the viewer will try to guess from the data blob.
66 /// If it cannot guess, it won't be able to render the asset.
67 std::optional<rerun::components::MediaType> media_type;
68
69 public:
70 static constexpr const char IndicatorComponentName[] = "rerun.components.Asset3DIndicator";
71
72 /// Indicator component, used to identify the archetype when converting to a list of components.
74
75 public: // START of extensions from asset3d_ext.cpp:
76 /// Creates a new `Asset3D` from the file contents at `path`.
77 ///
78 /// The `MediaType` will be guessed from the file extension.
79 ///
80 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
81 /// from the data at render-time. If it can't, rendering will fail with an error.
82 static Result<Asset3D> from_file(const std::filesystem::path& path);
83
84 /// Creates a new `Asset3D` from the given `bytes`.
85 ///
86 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
87 /// at render-time. If it can't, rendering will fail with an error.
90 std::optional<rerun::components::MediaType> media_type = {}
91 ) {
92 // TODO(cmc): we could try and guess using magic bytes here, like rust does.
93 Asset3D asset = Asset3D(std::move(bytes));
94 asset.media_type = media_type;
95 return asset;
96 }
97
98 // END of extensions from asset3d_ext.cpp, start of generated code:
99
100 public:
101 Asset3D() = default;
102 Asset3D(Asset3D&& other) = default;
103
104 explicit Asset3D(rerun::components::Blob _blob) : blob(std::move(_blob)) {}
105
106 /// The Media Type of the asset.
107 ///
108 /// Supported values:
109 /// * `model/gltf-binary`
110 /// * `model/gltf+json`
111 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
112 /// * `model/stl`
113 ///
114 /// If omitted, the viewer will try to guess from the data blob.
115 /// If it cannot guess, it won't be able to render the asset.
117 media_type = std::move(_media_type);
118 // See: https://github.com/rerun-io/rerun/issues/4027
119 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
120 }
121 };
122
123} // namespace rerun::archetypes
124
125namespace rerun {
126 /// \private
127 template <typename T>
128 struct AsComponents;
129
130 /// \private
131 template <>
132 struct AsComponents<archetypes::Asset3D> {
133 /// Serialize all set component batches.
134 static Result<std::vector<ComponentBatch>> serialize(const archetypes::Asset3D& archetype);
135 };
136} // 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:73
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:53
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:88
std::optional< rerun::components::MediaType > media_type
The Media Type of the asset.
Definition asset3d.hpp:67
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:55
Asset3D with_media_type(rerun::components::MediaType _media_type) &&
The Media Type of the asset.
Definition asset3d.hpp:116
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:20