-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++ example for asset3d_out_of_tree and related cleanup (#3913)
### What * part of #3751 * use Result for from_file * move heavy impl to c++ (codegen TODO: need to not leak heavy headers into public; make putting headers in _ext opt-in!) * (unrelated) rolled back some local vscode cmake settings that weren't that great after all <img width="1269" alt="image" src="https://github.com/rerun-io/rerun/assets/1220815/f98de83b-1f29-48a9-8703-39e05a9a4b26"> ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3913) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/3913) - [Docs preview](https://rerun.io/preview/317506389d3fc84a38d3c60db7843d35875898c2/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/317506389d3fc84a38d3c60db7843d35875898c2/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
- Loading branch information
Showing
10 changed files
with
136 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Log a simple 3D asset with an out-of-tree transform which will not affect its children. | ||
|
||
#include <exception> | ||
#include <rerun.hpp> | ||
#include <rerun/demo_utils.hpp> | ||
|
||
int main(int argc, char** argv) { | ||
if (argc < 2) { | ||
throw std::runtime_error("Usage: <path_to_asset.[gltf|glb]>"); | ||
} | ||
auto path = argv[1]; | ||
|
||
auto rec = rerun::RecordingStream("rerun_example_asset3d_out_of_tree"); | ||
rec.connect("127.0.0.1:9876").throw_on_failure(); | ||
|
||
rec.log_timeless("world", rerun::ViewCoordinates::RIGHT_HAND_Z_UP); // Set an up-axis | ||
|
||
rec.set_time_sequence("frame", 0); | ||
rec.log("world/asset", rerun::Asset3D::from_file(path).value_or_throw()); | ||
// Those points will not be affected by their parent's out-of-tree transform! | ||
rec.log( | ||
"world/asset/points", | ||
rerun::Points3D(rerun::demo::grid({-10.0f, -10.0f, -10.0f}, {10.0f, 10.0f, 10.0f}, 10)) | ||
); | ||
|
||
for (int64_t i = 1; i < 20; ++i) { | ||
rec.set_time_sequence("frame", i); | ||
|
||
// Modify the asset's out-of-tree transform: this will not affect its children (i.e. the points)! | ||
auto translation = | ||
rerun::TranslationRotationScale3D({0.0, 0.0, static_cast<float>(i) - 10.0f}); | ||
rec.log( | ||
"world/asset", | ||
rerun::ComponentBatch<rerun::OutOfTreeTransform3D>( | ||
rerun::OutOfTreeTransform3D(translation) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Utilities used in examples. | ||
|
||
#include <algorithm> | ||
#include <cmath> | ||
#include "components/position3d.hpp" | ||
|
||
namespace rerun { | ||
namespace demo { | ||
|
||
/// Linearly interpolates from `a` through `b` in `n` steps, returning the intermediate result at | ||
/// each step. | ||
template <typename T> | ||
std::vector<T> linspace(T start, T end, size_t num) { | ||
std::vector<T> linspaced(num); | ||
std::generate(linspaced.begin(), linspaced.end(), [&, i = 0]() mutable { | ||
return start + i++ * (end - start) / static_cast<T>(num - 1); | ||
}); | ||
return linspaced; | ||
} | ||
|
||
/// Given two 3D vectors `from` and `to`, linearly interpolates between them in `n` steps along | ||
/// the three axes, returning the intermediate result at each step. | ||
std::vector<components::Position3D> grid( | ||
components::Position3D from, components::Position3D to, size_t n | ||
) { | ||
std::vector<components::Position3D> output; | ||
for (float z : linspace(from.z(), to.z(), n)) { | ||
for (float y : linspace(from.y(), to.y(), n)) { | ||
for (float x : linspace(from.x(), to.x(), n)) { | ||
output.push_back({x, y, z}); | ||
} | ||
} | ||
} | ||
return output; | ||
} | ||
|
||
} // namespace demo | ||
} // namespace rerun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters