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/albedo_factor.hpp"
10#include "../components/blob.hpp"
11#include "../components/media_type.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 /// See also `archetypes::Mesh3D`.
25 ///
26 /// If there are multiple `archetypes::InstancePoses3D` instances logged to the same entity as a mesh,
27 /// an instance of the mesh will be drawn for each transform.
28 ///
29 /// ## Example
30 ///
31 /// ### Simple 3D asset
32 /// ![image](https://static.rerun.io/asset3d_simple/af238578188d3fd0de3e330212120e2842a8ddb2/full.png)
33 ///
34 /// ```cpp
35 /// #include <rerun.hpp>
36 ///
37 /// #include <iostream>
38 ///
39 /// int main(int argc, char* argv[]) {
40 /// if (argc <2) {
41 /// std::cerr <<"Usage: " <<argv[0] <<" <path_to_asset.[gltf|glb|obj|stl]>" <<std::endl;
42 /// return 1;
43 /// }
44 ///
45 /// const auto path = argv[1];
46 ///
47 /// const auto rec = rerun::RecordingStream("rerun_example_asset3d");
48 /// rec.spawn().exit_on_failure();
49 ///
50 /// rec.log_static("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis
51 /// rec.log("world/asset", rerun::Asset3D::from_file(path).value_or_throw());
52 /// }
53 /// ```
54 struct Asset3D {
55 /// The asset's bytes.
57
58 /// The Media Type of the asset.
59 ///
60 /// Supported values:
61 /// * `model/gltf-binary`
62 /// * `model/gltf+json`
63 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
64 /// * `model/stl`
65 ///
66 /// If omitted, the viewer will try to guess from the data blob.
67 /// If it cannot guess, it won't be able to render the asset.
68 std::optional<rerun::components::MediaType> media_type;
69
70 /// A color multiplier applied to the whole asset.
71 ///
72 /// For mesh who already have `albedo_factor` in materials,
73 /// it will be overwritten by actual `albedo_factor` of `archetypes::Asset3D` (if specified).
74 std::optional<rerun::components::AlbedoFactor> albedo_factor;
75
76 public:
77 static constexpr const char IndicatorComponentName[] = "rerun.components.Asset3DIndicator";
78
79 /// Indicator component, used to identify the archetype when converting to a list of components.
81
82 public: // START of extensions from asset3d_ext.cpp:
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.
97 std::optional<rerun::components::MediaType> media_type = {}
98 ) {
99 // TODO(cmc): we could try and guess using magic bytes here, like rust does.
100 Asset3D asset = Asset3D(std::move(bytes));
101 asset.media_type = media_type;
102 return asset;
103 }
104
105 // END of extensions from asset3d_ext.cpp, start of generated code:
106
107 public:
108 Asset3D() = default;
109 Asset3D(Asset3D&& other) = default;
110
111 explicit Asset3D(rerun::components::Blob _blob) : blob(std::move(_blob)) {}
112
113 /// The Media Type of the asset.
114 ///
115 /// Supported values:
116 /// * `model/gltf-binary`
117 /// * `model/gltf+json`
118 /// * `model/obj` (.mtl material files are not supported yet, references are silently ignored)
119 /// * `model/stl`
120 ///
121 /// If omitted, the viewer will try to guess from the data blob.
122 /// If it cannot guess, it won't be able to render the asset.
124 media_type = std::move(_media_type);
125 // See: https://github.com/rerun-io/rerun/issues/4027
126 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
127 }
128
129 /// A color multiplier applied to the whole asset.
130 ///
131 /// For mesh who already have `albedo_factor` in materials,
132 /// it will be overwritten by actual `albedo_factor` of `archetypes::Asset3D` (if specified).
134 albedo_factor = std::move(_albedo_factor);
135 // See: https://github.com/rerun-io/rerun/issues/4027
136 RR_WITH_MAYBE_UNINITIALIZED_DISABLED(return std::move(*this);)
137 }
138 };
139
140} // namespace rerun::archetypes
141
142namespace rerun {
143 /// \private
144 template <typename T>
145 struct AsComponents;
146
147 /// \private
148 template <>
149 struct AsComponents<archetypes::Asset3D> {
150 /// Serialize all set component batches.
151 static Result<std::vector<ComponentBatch>> serialize(const archetypes::Asset3D& archetype);
152 };
153} // 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:77
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:23
Archetype: A prepacked 3D asset (.gltf, .glb, .obj, .stl, etc.).
Definition asset3d.hpp:54
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
std::optional< rerun::components::MediaType > media_type
The Media Type of the asset.
Definition asset3d.hpp:68
static Result< Asset3D > from_file(const std::filesystem::path &path)
Creates a new Asset3D from the file contents at path.
std::optional< rerun::components::AlbedoFactor > albedo_factor
A color multiplier applied to the whole asset.
Definition asset3d.hpp:74
rerun::components::Blob blob
The asset's bytes.
Definition asset3d.hpp:56
Asset3D with_media_type(rerun::components::MediaType _media_type) &&
The Media Type of the asset.
Definition asset3d.hpp:123
Asset3D with_albedo_factor(rerun::components::AlbedoFactor _albedo_factor) &&
A color multiplier applied to the whole asset.
Definition asset3d.hpp:133
Component: A color multiplier, usually applied to a whole entity, e.g. a mesh.
Definition albedo_factor.hpp:15
Component: A binary blob of data.
Definition blob.hpp:17
Indicator component used by archetypes when converting them to component lists.
Definition indicator_component.hpp:32
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:21