WIP intermediate result compiling pw::scene again

This commit is contained in:
Hartmut Seichter 2024-07-27 18:34:38 +02:00
parent 55189a70b5
commit 1fb8d25b31
8 changed files with 42 additions and 83 deletions

View file

@ -4,12 +4,12 @@ add_subdirectory(deps)
# build internal core # build internal core
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(scene) add_subdirectory(scene)
add_subdirectory(system) # add_subdirectory(system)
add_subdirectory(io) # add_subdirectory(io)
#add_subdirectory(ui) #add_subdirectory(ui)
add_subdirectory(binding) # add_subdirectory(binding)
add_subdirectory(visual) # add_subdirectory(visual)
# add_subdirectory(geometry) # add_subdirectory(geometry)
add_subdirectory(runtime) # add_subdirectory(runtime)

View file

@ -33,8 +33,8 @@ namespace pw {
struct camera { struct camera {
matrix4x4f projection = matrix4x4f::identity(); matrix4x4f projection = matrix4x4f::identity();
matrix4x4f view = matrix_transform<float>::look_at(vector3f{}, vector3f::x_axis(), matrix4x4f view = matrix_transform<float>::look_at_matrix(
vector3f::y_axis()); vector3f{}, vector3f::x_axis(), vector3f::y_axis());
matrix4x4f viewport = pw::rectangle{{0.f, 0.f} {1.f, 1.f}}; matrix4x4f viewport = pw::rectangle{{0.f, 0.f} {1.f, 1.f}};

View file

@ -25,7 +25,6 @@
#ifndef PW_SCENE_COMPONENTS_RELATIONSHIP_HPP #ifndef PW_SCENE_COMPONENTS_RELATIONSHIP_HPP
#define PW_SCENE_COMPONENTS_RELATIONSHIP_HPP #define PW_SCENE_COMPONENTS_RELATIONSHIP_HPP
#include <pw/scene/scene.hpp> #include <pw/scene/scene.hpp>
namespace pw { namespace pw {
@ -34,8 +33,6 @@ namespace pw {
* @brief entity relations are hidden and managed by the entity itself * @brief entity relations are hidden and managed by the entity itself
*/ */
struct parent { struct parent {
parent() = default;
parent(const parent&) = default;
entt::entity entity{entt::null}; entt::entity entity{entt::null};
@ -43,13 +40,9 @@ struct parent {
}; };
struct children { struct children {
children() = default;
children(const children&) = default;
std::vector<entt::entity> entities; std::vector<entt::entity> entities;
}; };
} // namespace pw
}
#endif #endif

View file

@ -33,12 +33,12 @@ struct transform final {
} }
inline transform& rotate(const quaternionf& q) { inline transform& rotate(const quaternionf& q) {
_local = _local * q.to_matrix(); _local = _local * q.to_matrix().unproject(1);
return *this; return *this;
} }
inline transform& set_rotation(const quaternionf& q) { inline transform& set_rotation(const quaternionf& q) {
_local = q.to_matrix(); _local = q.to_matrix().unproject(1);
return *this; return *this;
} }

View file

@ -150,6 +150,6 @@ private:
#include <pw/scene/components/relationship.hpp> #include <pw/scene/components/relationship.hpp>
#include <pw/scene/components/transform.hpp> #include <pw/scene/components/transform.hpp>
#include <pw/scene/components/camera.hpp> // #include <pw/scene/components/camera.hpp>
#endif #endif

View file

@ -33,9 +33,7 @@ namespace pw {
class entity; class entity;
class scene { struct scene final {
public:
using registry = entt::registry; using registry = entt::registry;

View file

@ -7,7 +7,6 @@ namespace pw {
namespace detail { namespace detail {
// entity identiy is hidden // entity identiy is hidden
struct identity { struct identity {
@ -21,19 +20,17 @@ struct identity {
std::vector<uint32_t> layers = {}; std::vector<uint32_t> layers = {};
}; };
} } // namespace detail
entity::entity(scene& s, const std::string& name) entity::entity(scene& s, const std::string& name)
: _registry(s._registry) : _registry(s._registry),
, _entity(s._registry ? _registry->create() : entt::null) _entity(s._registry ? _registry->create() : entt::null) {
{
if (s._registry) { if (s._registry) {
this->add_component<detail::identity>(name); this->add_component<detail::identity>(name);
} }
} }
bool entity::add_child(entity &child) bool entity::add_child(entity& child) {
{
// not mixing scenes (yet) // not mixing scenes (yet)
if (child._registry != this->_registry) { if (child._registry != this->_registry) {
debug::e() << "Cannot mix entities from different scenes"; debug::e() << "Cannot mix entities from different scenes";
@ -53,8 +50,7 @@ bool entity::add_child(entity &child)
return true; return true;
} }
bool entity::remove_child(entity& child) bool entity::remove_child(entity& child) {
{
// not mixing scenes (yet) // not mixing scenes (yet)
if (child._registry != this->_registry) { if (child._registry != this->_registry) {
debug::e() << "Cannot mix entities from different scenes"; debug::e() << "Cannot mix entities from different scenes";
@ -62,19 +58,17 @@ bool entity::remove_child(entity& child)
} }
// both need to have a relationship component // both need to have a relationship component
if (child.has_component<parent>() && if (child.has_component<parent>() && this->has_component<children>()) {
this->has_component<children>())
{
// we need to check if the child is related to the parent // we need to check if the child is related to the parent
auto r_p = child.get_component<parent>(); auto r_p = child.get_component<parent>();
if (r_p.entity == _entity) if (r_p.entity == _entity) {
{
// now go ahead delete parent // now go ahead delete parent
r_p.entity = entt::null; r_p.entity = entt::null;
// now remove all children // now remove all children
auto& c = this->get_component<children>(); auto& c = this->get_component<children>();
c.entities.erase(std::remove(c.entities.begin(),c.entities.end(),child._entity)); c.entities.erase(std::remove(c.entities.begin(), c.entities.end(),
child._entity));
// flag success // flag success
return true; return true;
@ -83,38 +77,24 @@ bool entity::remove_child(entity& child)
return false; return false;
} }
size_t entity::child_count() const {
size_t entity::child_count() const return this->has_component<children>()
{ ? get_component<children>().entities.size()
return this->has_component<children>() ? : 0;
get_component<children>().entities.size() :
0;
} }
void entity::set_name(const std::string& n) {
void entity::set_name(const std::string& n)
{
auto& ident = get_or_create_component<detail::identity>(); auto& ident = get_or_create_component<detail::identity>();
ident.name = n; ident.name = n;
} }
std::string entity::name() std::string entity::name() {
{
auto& ident = get_or_create_component<detail::identity>(); auto& ident = get_or_create_component<detail::identity>();
return ident.name; return ident.name;
} }
entity::~entity() { this->destroy(); }
void entity::destroy() { _registry->destroy(_entity); }
entity::~entity() } // namespace pw
{
this->destroy();
}
void entity::destroy()
{
_registry->destroy(_entity);
}
}

View file

@ -4,23 +4,11 @@
#include "pw/core/debug.hpp" #include "pw/core/debug.hpp"
#include "pw/core/serialize.hpp" #include "pw/core/serialize.hpp"
#include "pw/core/geometry.hpp" #include "pw/core/mesh.hpp"
#include "pw/core/matrix_transform.hpp" #include "pw/core/matrix_transform.hpp"
namespace pw { namespace pw {
struct mesh {
geometry geom;
};
struct renderer {
std::unique_ptr<int> state;
// std::vector<matrials> mat;
};
scene::scene() scene::scene()
: _registry{ std::make_shared<entt::registry>()} : _registry{ std::make_shared<entt::registry>()}
{ {
@ -39,7 +27,7 @@ void scene::update_transforms()
//auto [t,r] = view.get<transform,parent>(entity); //auto [t,r] = view.get<transform,parent>(entity);
#if 1 #if 0
// search for nodes with parent and transform (only find leaf nodes) // search for nodes with parent and transform (only find leaf nodes)
auto view = _registry->view<transform,parent>(entt::exclude<children>); auto view = _registry->view<transform,parent>(entt::exclude<children>);
@ -61,7 +49,7 @@ void scene::update_transforms()
debug::d() << "\tpath length " << path.size(); debug::d() << "\tpath length " << path.size();
std::reverse(path.begin(),path.end()); std::reverse(path.begin(),path.end());
auto m = pw::matrix4x4::identity(); auto m = pw::matrix4x4f::identity();
for (auto& transform : path) { for (auto& transform : path) {