Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ set(SCENE_GRAPH_FILES
scene_graph/hpp_scene.h
# Source Files
scene_graph/component.cpp
scene_graph/node.cpp
scene_graph/scene.cpp
scene_graph/script.cpp)

Expand Down
5 changes: 3 additions & 2 deletions framework/common/hpp_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ namespace vkb
{
namespace common
{
inline sg::Node &add_free_camera(vkb::scene_graph::HPPScene &scene, const std::string &node_name, vk::Extent2D const &extent)
inline vkb::scene_graph::NodeCpp &add_free_camera(vkb::scene_graph::HPPScene &scene, const std::string &node_name, vk::Extent2D const &extent)
{
return vkb::add_free_camera(reinterpret_cast<vkb::sg::Scene &>(scene), node_name, static_cast<VkExtent2D>(extent));
return reinterpret_cast<vkb::scene_graph::NodeCpp &>(
vkb::add_free_camera(reinterpret_cast<vkb::sg::Scene &>(scene), node_name, static_cast<VkExtent2D>(extent)));
}

inline void screenshot(vkb::rendering::RenderContextCpp &render_context, const std::string &filename)
Expand Down
17 changes: 11 additions & 6 deletions framework/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,15 @@ std::string to_snake_case(const std::string &text)
return result.str();
}

sg::Light &add_light(sg::Scene &scene, sg::LightType type, const glm::vec3 &position, const glm::quat &rotation, const sg::LightProperties &props, sg::Node *parent_node)
sg::Light &add_light(sg::Scene &scene,
sg::LightType type,
const glm::vec3 &position,
const glm::quat &rotation,
const sg::LightProperties &props,
vkb::scene_graph::NodeC *parent_node)
{
auto light_ptr = std::make_unique<sg::Light>("light");
auto node = std::make_unique<sg::Node>(-1, "light node");
auto node = std::make_unique<vkb::scene_graph::NodeC>(-1, "light node");

if (parent_node)
{
Expand All @@ -244,22 +249,22 @@ sg::Light &add_light(sg::Scene &scene, sg::LightType type, const glm::vec3 &posi
return light;
}

sg::Light &add_point_light(sg::Scene &scene, const glm::vec3 &position, const sg::LightProperties &props, sg::Node *parent_node)
sg::Light &add_point_light(sg::Scene &scene, const glm::vec3 &position, const sg::LightProperties &props, vkb::scene_graph::NodeC *parent_node)
{
return add_light(scene, sg::LightType::Point, position, {}, props, parent_node);
}

sg::Light &add_directional_light(sg::Scene &scene, const glm::quat &rotation, const sg::LightProperties &props, sg::Node *parent_node)
sg::Light &add_directional_light(sg::Scene &scene, const glm::quat &rotation, const sg::LightProperties &props, vkb::scene_graph::NodeC *parent_node)
{
return add_light(scene, sg::LightType::Directional, {}, rotation, props, parent_node);
}

sg::Light &add_spot_light(sg::Scene &scene, const glm::vec3 &position, const glm::quat &rotation, const sg::LightProperties &props, sg::Node *parent_node)
sg::Light &add_spot_light(sg::Scene &scene, const glm::vec3 &position, const glm::quat &rotation, const sg::LightProperties &props, vkb::scene_graph::NodeC *parent_node)
{
return add_light(scene, sg::LightType::Spot, position, rotation, props, parent_node);
}

sg::Node &add_free_camera(sg::Scene &scene, const std::string &node_name, VkExtent2D extent)
vkb::scene_graph::NodeC &add_free_camera(sg::Scene &scene, const std::string &node_name, VkExtent2D extent)
{
auto camera_node = scene.find_node(node_name);

Expand Down
23 changes: 18 additions & 5 deletions framework/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ void screenshot(vkb::rendering::RenderContextC &render_context, const std::strin
* @param parent_node The parent node for the line, defaults to root
* @return The newly created light component
*/
sg::Light &add_light(sg::Scene &scene, sg::LightType type, const glm::vec3 &position, const glm::quat &rotation = {}, const sg::LightProperties &props = {}, sg::Node *parent_node = nullptr);
sg::Light &add_light(sg::Scene &scene,
sg::LightType type,
const glm::vec3 &position,
const glm::quat &rotation = {},
const sg::LightProperties &props = {},
vkb::scene_graph::NodeC *parent_node = nullptr);

/**
* @brief Adds a point light to the scene with the specified parameters
Expand All @@ -76,7 +81,8 @@ sg::Light &add_light(sg::Scene &scene, sg::LightType type, const glm::vec3 &posi
* @param parent_node The parent node for the line, defaults to root
* @return The newly created light component
*/
sg::Light &add_point_light(sg::Scene &scene, const glm::vec3 &position, const sg::LightProperties &props = {}, sg::Node *parent_node = nullptr);
sg::Light &
add_point_light(sg::Scene &scene, const glm::vec3 &position, const sg::LightProperties &props = {}, vkb::scene_graph::NodeC *parent_node = nullptr);

/**
* @brief Adds a directional light to the scene with the specified parameters
Expand All @@ -86,7 +92,10 @@ sg::Light &add_point_light(sg::Scene &scene, const glm::vec3 &position, const sg
* @param parent_node The parent node for the line, defaults to root
* @return The newly created light component
*/
sg::Light &add_directional_light(sg::Scene &scene, const glm::quat &rotation, const sg::LightProperties &props = {}, sg::Node *parent_node = nullptr);
sg::Light &add_directional_light(sg::Scene &scene,
const glm::quat &rotation,
const sg::LightProperties &props = {},
vkb::scene_graph::NodeC *parent_node = nullptr);

/**
* @brief Adds a spot light to the scene with the specified parameters
Expand All @@ -97,7 +106,11 @@ sg::Light &add_directional_light(sg::Scene &scene, const glm::quat &rotation, co
* @param parent_node The parent node for the line, defaults to root
* @return The newly created light component
*/
sg::Light &add_spot_light(sg::Scene &scene, const glm::vec3 &position, const glm::quat &rotation, const sg::LightProperties &props = {}, sg::Node *parent_node = nullptr);
sg::Light &add_spot_light(sg::Scene &scene,
const glm::vec3 &position,
const glm::quat &rotation,
const sg::LightProperties &props = {},
vkb::scene_graph::NodeC *parent_node = nullptr);

/**
* @brief Add free camera script to a node with a camera object.
Expand All @@ -107,6 +120,6 @@ sg::Light &add_spot_light(sg::Scene &scene, const glm::vec3 &position, const glm
* @param extent The initial resolution of the camera
* @return Node where the script was attached as component
*/
sg::Node &add_free_camera(sg::Scene &scene, const std::string &node_name, VkExtent2D extent);
vkb::scene_graph::NodeC &add_free_camera(sg::Scene &scene, const std::string &node_name, VkExtent2D extent);

} // namespace vkb
12 changes: 6 additions & 6 deletions framework/gltf_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_
// Load nodes
auto meshes = scene.get_components<sg::Mesh>();

std::vector<std::unique_ptr<sg::Node>> nodes;
std::vector<std::unique_ptr<vkb::scene_graph::NodeC>> nodes;

for (size_t node_index = 0; node_index < model.nodes.size(); ++node_index)
{
Expand Down Expand Up @@ -1016,7 +1016,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_
scene.set_components(std::move(animations));

// Load scenes
std::queue<std::pair<sg::Node &, int>> traverse_nodes;
std::queue<std::pair<vkb::scene_graph::NodeC &, int>> traverse_nodes;

tinygltf::Scene *gltf_scene{nullptr};

Expand All @@ -1038,7 +1038,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_
throw std::runtime_error("Couldn't determine which scene to load!");
}

auto root_node = std::make_unique<sg::Node>(0, gltf_scene->name);
auto root_node = std::make_unique<vkb::scene_graph::NodeC>(0, gltf_scene->name);

for (auto node_index : gltf_scene->nodes)
{
Expand Down Expand Up @@ -1075,7 +1075,7 @@ sg::Scene GLTFLoader::load_scene(int scene_index, VkBufferUsageFlags additional_
scene.set_nodes(std::move(nodes));

// Create node for the default camera
auto camera_node = std::make_unique<sg::Node>(-1, "default_camera");
auto camera_node = std::make_unique<vkb::scene_graph::NodeC>(-1, "default_camera");

auto default_camera = create_default_camera();
default_camera->set_node(*camera_node);
Expand Down Expand Up @@ -1320,9 +1320,9 @@ std::unique_ptr<sg::SubMesh> GLTFLoader::load_model(uint32_t index, bool storage
return std::move(submesh);
}

std::unique_ptr<sg::Node> GLTFLoader::parse_node(const tinygltf::Node &gltf_node, size_t index) const
std::unique_ptr<vkb::scene_graph::NodeC> GLTFLoader::parse_node(const tinygltf::Node &gltf_node, size_t index) const
{
auto node = std::make_unique<sg::Node>(index, gltf_node.name);
auto node = std::make_unique<vkb::scene_graph::NodeC>(index, gltf_node.name);

auto &transform = node->get_component<sg::Transform>();

Expand Down
3 changes: 2 additions & 1 deletion framework/gltf_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#define TINYGLTF_NO_EXTERNAL_IMAGE
#include <tiny_gltf.h>

#include "scene_graph/node.h"
#include "timer.h"

#include "vulkan/vulkan.h"
Expand Down Expand Up @@ -91,7 +92,7 @@ class GLTFLoader
std::unique_ptr<sg::SubMesh> read_model_from_file(const std::string &file_name, uint32_t index, bool storage_buffer = false, VkBufferUsageFlags additional_buffer_usage_flags = 0);

protected:
virtual std::unique_ptr<sg::Node> parse_node(const tinygltf::Node &gltf_node, size_t index) const;
virtual std::unique_ptr<vkb::scene_graph::NodeC> parse_node(const tinygltf::Node &gltf_node, size_t index) const;

virtual std::unique_ptr<sg::Camera> parse_camera(const tinygltf::Camera &gltf_camera) const;

Expand Down
9 changes: 5 additions & 4 deletions framework/rendering/subpasses/geometry_subpass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void GeometrySubpass::prepare()
}
}

void GeometrySubpass::get_sorted_nodes(std::multimap<float, std::pair<sg::Node *, sg::SubMesh *>> &opaque_nodes, std::multimap<float, std::pair<sg::Node *, sg::SubMesh *>> &transparent_nodes)
void GeometrySubpass::get_sorted_nodes(std::multimap<float, std::pair<vkb::scene_graph::NodeC *, sg::SubMesh *>> &opaque_nodes,
std::multimap<float, std::pair<vkb::scene_graph::NodeC *, sg::SubMesh *>> &transparent_nodes)
{
auto camera_transform = camera.get_node()->get_transform().get_world_matrix();

Expand Down Expand Up @@ -90,8 +91,8 @@ void GeometrySubpass::get_sorted_nodes(std::multimap<float, std::pair<sg::Node *

void GeometrySubpass::draw(vkb::core::CommandBufferC &command_buffer)
{
std::multimap<float, std::pair<sg::Node *, sg::SubMesh *>> opaque_nodes;
std::multimap<float, std::pair<sg::Node *, sg::SubMesh *>> transparent_nodes;
std::multimap<float, std::pair<vkb::scene_graph::NodeC *, sg::SubMesh *>> opaque_nodes;
std::multimap<float, std::pair<vkb::scene_graph::NodeC *, sg::SubMesh *>> transparent_nodes;

get_sorted_nodes(opaque_nodes, transparent_nodes);

Expand Down Expand Up @@ -142,7 +143,7 @@ void GeometrySubpass::draw(vkb::core::CommandBufferC &command_buffer)
}
}

void GeometrySubpass::update_uniform(vkb::core::CommandBufferC &command_buffer, sg::Node &node, size_t thread_index)
void GeometrySubpass::update_uniform(vkb::core::CommandBufferC &command_buffer, vkb::scene_graph::NodeC &node, size_t thread_index)
{
GlobalUniform global_uniform;

Expand Down
7 changes: 3 additions & 4 deletions framework/rendering/subpasses/geometry_subpass.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ using CommandBufferC = CommandBuffer<vkb::BindingType::C>;
namespace sg
{
class Scene;
class Node;
class Mesh;
class SubMesh;
class Camera;
Expand Down Expand Up @@ -97,7 +96,7 @@ class GeometrySubpass : public vkb::rendering::SubpassC
void set_thread_index(uint32_t index);

protected:
virtual void update_uniform(vkb::core::CommandBufferC &command_buffer, sg::Node &node, size_t thread_index);
virtual void update_uniform(vkb::core::CommandBufferC &command_buffer, vkb::scene_graph::NodeC &node, size_t thread_index);

void draw_submesh(vkb::core::CommandBufferC &command_buffer, sg::SubMesh &sub_mesh, VkFrontFace front_face = VK_FRONT_FACE_COUNTER_CLOCKWISE);

Expand All @@ -114,8 +113,8 @@ class GeometrySubpass : public vkb::rendering::SubpassC
* @brief Sorts objects based on distance from camera and classifies them
* into opaque and transparent in the arrays provided
*/
void get_sorted_nodes(std::multimap<float, std::pair<sg::Node *, sg::SubMesh *>> &opaque_nodes,
std::multimap<float, std::pair<sg::Node *, sg::SubMesh *>> &transparent_nodes);
void get_sorted_nodes(std::multimap<float, std::pair<vkb::scene_graph::NodeC *, sg::SubMesh *>> &opaque_nodes,
std::multimap<float, std::pair<vkb::scene_graph::NodeC *, sg::SubMesh *>> &transparent_nodes);

sg::Camera &camera;

Expand Down
6 changes: 3 additions & 3 deletions framework/scene_graph/components/camera.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019-2020, Arm Limited and Contributors
/* Copyright (c) 2019-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -44,12 +44,12 @@ glm::mat4 Camera::get_view()
return glm::inverse(transform.get_world_matrix());
}

void Camera::set_node(Node &n)
void Camera::set_node(vkb::scene_graph::NodeC &n)
{
node = &n;
}

Node *Camera::get_node()
vkb::scene_graph::NodeC *Camera::get_node()
{
return node;
}
Expand Down
9 changes: 5 additions & 4 deletions framework/scene_graph/components/camera.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2019-2024, Arm Limited and Contributors
/* Copyright (c) 2019-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -28,6 +28,7 @@

#include "common/helpers.h"
#include "scene_graph/component.h"
#include "scene_graph/node.h"

namespace vkb
{
Expand All @@ -46,16 +47,16 @@ class Camera : public Component

glm::mat4 get_view();

void set_node(Node &node);
void set_node(vkb::scene_graph::NodeC &node);

Node *get_node();
vkb::scene_graph::NodeC *get_node();

const glm::mat4 get_pre_rotation();

void set_pre_rotation(const glm::mat4 &pre_rotation);

private:
Node *node{nullptr};
vkb::scene_graph::NodeC *node{nullptr};

glm::mat4 pre_rotation{1.0f};
};
Expand Down
7 changes: 4 additions & 3 deletions framework/scene_graph/components/light.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018-2019, Arm Limited and Contributors
/* Copyright (c) 2018-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -16,6 +16,7 @@
*/

#include "light.h"
#include "scene_graph/node.h"

namespace vkb
{
Expand All @@ -30,12 +31,12 @@ std::type_index Light::get_type()
return typeid(Light);
}

void Light::set_node(Node &n)
void Light::set_node(vkb::scene_graph::NodeC &n)
{
node = &n;
}

Node *Light::get_node()
vkb::scene_graph::NodeC *Light::get_node()
{
return node;
}
Expand Down
9 changes: 5 additions & 4 deletions framework/scene_graph/components/light.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018-2024, Arm Limited and Contributors
/* Copyright (c) 2018-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -28,6 +28,7 @@

#include "core/shader_module.h"
#include "scene_graph/component.h"
#include "scene_graph/node.h"

namespace vkb
{
Expand Down Expand Up @@ -68,9 +69,9 @@ class Light : public Component

virtual std::type_index get_type() override;

void set_node(Node &node);
void set_node(vkb::scene_graph::NodeC &node);

Node *get_node();
vkb::scene_graph::NodeC *get_node();

void set_light_type(const LightType &type);

Expand All @@ -81,7 +82,7 @@ class Light : public Component
const LightProperties &get_properties();

private:
Node *node{nullptr};
vkb::scene_graph::NodeC *node = nullptr;

LightType light_type;

Expand Down
6 changes: 3 additions & 3 deletions framework/scene_graph/components/mesh.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2018-2019, Arm Limited and Contributors
/* Copyright (c) 2018-2025, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -50,12 +50,12 @@ const std::vector<SubMesh *> &Mesh::get_submeshes() const
return submeshes;
}

void Mesh::add_node(Node &node)
void Mesh::add_node(vkb::scene_graph::NodeC &node)
{
nodes.push_back(&node);
}

const std::vector<Node *> &Mesh::get_nodes() const
const std::vector<vkb::scene_graph::NodeC *> &Mesh::get_nodes() const
{
return nodes;
}
Expand Down
Loading
Loading