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
add_subdirectory(core)
add_subdirectory(scene)
add_subdirectory(system)
add_subdirectory(io)
# add_subdirectory(system)
# add_subdirectory(io)
#add_subdirectory(ui)
add_subdirectory(binding)
add_subdirectory(visual)
# add_subdirectory(binding)
# add_subdirectory(visual)
# add_subdirectory(geometry)
add_subdirectory(runtime)
# add_subdirectory(runtime)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -7,7 +7,6 @@ namespace pw {
namespace detail {
// entity identiy is hidden
struct identity {
@ -15,25 +14,23 @@ struct identity {
identity(const std::string& name) : name(name) {}
identity(const identity&) = default;
bool enabled = true;
std::string name = "";
std::vector<u_int32_t> tags = {};
bool enabled = true;
std::string name = "";
std::vector<u_int32_t> tags = {};
std::vector<uint32_t> layers = {};
};
}
} // namespace detail
entity::entity(scene &s,const std::string& name)
: _registry(s._registry)
, _entity(s._registry ? _registry->create() : entt::null)
{
entity::entity(scene& s, const std::string& name)
: _registry(s._registry),
_entity(s._registry ? _registry->create() : entt::null) {
if (s._registry) {
this->add_component<detail::identity>(name);
}
}
bool entity::add_child(entity &child)
{
bool entity::add_child(entity& child) {
// not mixing scenes (yet)
if (child._registry != this->_registry) {
debug::e() << "Cannot mix entities from different scenes";
@ -47,14 +44,13 @@ bool entity::add_child(entity &child)
c.entities.push_back(child._entity);
// declare parent
auto& p_r = child.get_or_create_component<parent>();
auto& p_r = child.get_or_create_component<parent>();
p_r.entity = _entity;
return true;
}
bool entity::remove_child(entity& child)
{
bool entity::remove_child(entity& child) {
// not mixing scenes (yet)
if (child._registry != this->_registry) {
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
if (child.has_component<parent>() &&
this->has_component<children>())
{
if (child.has_component<parent>() && this->has_component<children>()) {
// we need to check if the child is related to the parent
auto r_p = child.get_component<parent>();
if (r_p.entity == _entity)
{
if (r_p.entity == _entity) {
// now go ahead delete parent
r_p.entity = entt::null;
// now remove all 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
return true;
@ -83,38 +77,24 @@ bool entity::remove_child(entity& child)
return false;
}
size_t entity::child_count() const
{
return this->has_component<children>() ?
get_component<children>().entities.size() :
0;
size_t entity::child_count() const {
return this->has_component<children>()
? get_component<children>().entities.size()
: 0;
}
void entity::set_name(const std::string& n)
{
auto &ident = get_or_create_component<detail::identity>();
ident.name = n;
void entity::set_name(const std::string& n) {
auto& ident = get_or_create_component<detail::identity>();
ident.name = n;
}
std::string entity::name()
{
auto &ident = get_or_create_component<detail::identity>();
std::string entity::name() {
auto& ident = get_or_create_component<detail::identity>();
return ident.name;
}
entity::~entity() { this->destroy(); }
void entity::destroy() { _registry->destroy(_entity); }
entity::~entity()
{
this->destroy();
}
void entity::destroy()
{
_registry->destroy(_entity);
}
}
} // namespace pw

View file

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