python/src/values.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstddef> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <span> | ||
| 7 | #include <string> | ||
| 8 | #include <string_view> | ||
| 9 | #include <type_traits> | ||
| 10 | #include <vector> | ||
| 11 | |||
| 12 | #include <nanobind/nanobind.h> | ||
| 13 | #include <nanobind/stl/string.h> | ||
| 14 | |||
| 15 | #include "bindings.h" | ||
| 16 | |||
| 17 | namespace chrono::batch_render::python { | ||
| 18 | |||
| 19 | 124965 | struct ScenePrim { | |
| 20 | Ref<Scene> scene; | ||
| 21 | Prim prim; | ||
| 22 | }; | ||
| 23 | |||
| 24 | 10 | template <class T> std::vector<std::byte> Bytes(const std::vector<T>& values) { | |
| 25 | 10 | const auto bytes = std::as_bytes(std::span(values)); | |
| 26 | 10 | return {bytes.begin(), bytes.end()}; | |
| 27 | } | ||
| 28 | |||
| 29 | std::vector<std::byte> NumpyBytes(nanobind::handle value, const std::string& dtype); | ||
| 30 | std::vector<std::string> Strings(nanobind::handle value); | ||
| 31 | uint32_t EnumIndex(nanobind::handle value, std::span<const std::string_view> tokens); | ||
| 32 | |||
| 33 | void Assign(bool& out, nanobind::handle value); | ||
| 34 | void Assign(int32_t& out, nanobind::handle value); | ||
| 35 | void Assign(uint32_t& out, nanobind::handle value); | ||
| 36 | void Assign(float& out, nanobind::handle value); | ||
| 37 | void Assign(Float2& out, nanobind::handle value); | ||
| 38 | void Assign(Uint2& out, nanobind::handle value); | ||
| 39 | void Assign(Float3& out, nanobind::handle value); | ||
| 40 | void Assign(Float4& out, nanobind::handle value); | ||
| 41 | void Assign(Double3& out, nanobind::handle value); | ||
| 42 | void Assign(Quatd& out, nanobind::handle value); | ||
| 43 | void Assign(std::string& out, nanobind::handle value); | ||
| 44 | void Assign(std::vector<std::string>& out, nanobind::handle value); | ||
| 45 | void Assign(std::vector<int32_t>& out, nanobind::handle value); | ||
| 46 | void Assign(std::vector<int64_t>& out, nanobind::handle value); | ||
| 47 | void Assign(std::vector<Float3>& out, nanobind::handle value); | ||
| 48 | void Assign(std::vector<float>& out, nanobind::handle value); | ||
| 49 | void Assign(std::vector<Float2>& out, nanobind::handle value); | ||
| 50 | void Assign(std::vector<Float4>& out, nanobind::handle value); | ||
| 51 | void Assign(std::vector<Primvar>& out, nanobind::handle value); | ||
| 52 | |||
| 53 | template <class E> | ||
| 54 | requires std::is_enum_v<E> | ||
| 55 | 12 | void Assign(E& out, nanobind::handle value, std::span<const std::string_view> tokens) { | |
| 56 | 12 | out = E(EnumIndex(value, tokens)); | |
| 57 | 12 | } | |
| 58 | |||
| 59 | Prim DefineSchema(Scene& scene, std::string_view path, SchemaId schema, | ||
| 60 | const nanobind::dict& values, const nanobind::dict& apis); | ||
| 61 | void ApplySchema(Scene& scene, Span<const Prim> prims, SchemaId schema, std::string_view instance, | ||
| 62 | const nanobind::dict& values); | ||
| 63 | |||
| 64 | } | ||
| 65 |