|
| 1 | +/* Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. |
| 2 | + * |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 the "License"; |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#pragma once |
| 19 | + |
| 20 | +#include "components/hpp_mesh.h" |
| 21 | +#include "scene.h" |
| 22 | +#include "scene_graph/script.h" |
| 23 | +#include "scene_graph/scripts/animation.h" |
| 24 | + |
| 25 | +namespace vkb |
| 26 | +{ |
| 27 | +namespace scene_graph |
| 28 | +{ |
| 29 | +/** |
| 30 | + * @brief facade class around vkb::sg::Scene, providing a vulkan.hpp-based interface |
| 31 | + * |
| 32 | + * See vkb::sb::Scene for documentation |
| 33 | + */ |
| 34 | +class HPPScene : private vkb::sg::Scene |
| 35 | +{ |
| 36 | + public: |
| 37 | + template <class T> |
| 38 | + std::vector<T *> get_components() const |
| 39 | + { |
| 40 | + if constexpr (std::is_same<T, vkb::sg::Script>::value) |
| 41 | + { |
| 42 | + return vkb::sg::Scene::get_components<T>(); |
| 43 | + } |
| 44 | + else if constexpr (std::is_same<T, vkb::scene_graph::components::HPPMesh>::value) |
| 45 | + { |
| 46 | + std::vector<vkb::sg::Mesh *> meshes = vkb::sg::Scene::get_components<vkb::sg::Mesh>(); |
| 47 | + return *reinterpret_cast<std::vector<T *> *>(&meshes); |
| 48 | + } |
| 49 | + else |
| 50 | + { |
| 51 | + assert(false); // path never passed -> Please add a type-check here! |
| 52 | + return {}; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + template <class T> |
| 57 | + bool has_component() const |
| 58 | + { |
| 59 | + if constexpr (std::is_same<T, vkb::sg::Animation>::value || std::is_same<T, vkb::sg::Script>::value) |
| 60 | + { |
| 61 | + return vkb::sg::Scene::has_component(typeid(T)); |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + assert(false); // path never passed -> Please add a type-check here! |
| 66 | + return false; |
| 67 | + } |
| 68 | + } |
| 69 | +}; |
| 70 | +} // namespace scene_graph |
| 71 | +} // namespace vkb |
0 commit comments