added scene with new approach differing from other scenegraphs - more closely modelled after Unity
This commit is contained in:
parent
a99906317d
commit
59cb75513d
14 changed files with 212 additions and 15 deletions
Binary file not shown.
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
add_subdirectory(deps)
|
add_subdirectory(deps)
|
||||||
add_subdirectory(core)
|
add_subdirectory(core)
|
||||||
|
add_subdirectory(scene)
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
||||||
add_subdirectory(scripting)
|
add_subdirectory(scripting)
|
||||||
add_subdirectory(engine)
|
add_subdirectory(engine)
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
#ifndef PW_CORE_GLOBALS_HPP
|
#ifndef PW_CORE_GLOBALS_HPP
|
||||||
#define PW_CORE_GLOBALS_HPP
|
#define PW_CORE_GLOBALS_HPP
|
||||||
|
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
using std::shared_ptr;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
add_subdirectory(src)
|
||||||
|
add_subdirectory(tests)
|
62
src/scene/include/pw/scene/node.hpp
Normal file
62
src/scene/include/pw/scene/node.hpp
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#ifndef PW_SCENE_NODE_HPP
|
||||||
|
#define PW_SCENE_NODE_HPP
|
||||||
|
|
||||||
|
#include <pw/core/globals.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
class component;
|
||||||
|
|
||||||
|
class node {
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef shared_ptr<node> ref;
|
||||||
|
typedef std::vector<ref> ref_array;
|
||||||
|
typedef std::vector<node*> ptr_array;
|
||||||
|
|
||||||
|
//! standard c'tor
|
||||||
|
node(const std::string& name = "");
|
||||||
|
|
||||||
|
//! copy c'tor
|
||||||
|
node(const node& node);
|
||||||
|
|
||||||
|
//! cloning interface
|
||||||
|
virtual node* clone(const unsigned short& copymode) const;
|
||||||
|
|
||||||
|
std::string name() const;
|
||||||
|
void set_name(const std::string &name);
|
||||||
|
|
||||||
|
//! return list of parents
|
||||||
|
inline const ptr_array& parents() const { return _parents; }
|
||||||
|
|
||||||
|
//! check if this is the root node
|
||||||
|
inline bool is_root() const { return parents().empty(); }
|
||||||
|
|
||||||
|
//! add a child node
|
||||||
|
void add_child(node *anode);
|
||||||
|
|
||||||
|
//! get the list of children
|
||||||
|
inline const ref_array& children() const { return _children; }
|
||||||
|
|
||||||
|
//! get number of children
|
||||||
|
inline size_t child_count() const { return children().size(); }
|
||||||
|
|
||||||
|
//! check if this node is a leaf node
|
||||||
|
inline bool is_leaf() const { return children().empty(); }
|
||||||
|
|
||||||
|
virtual ~node();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
ref_array _children;
|
||||||
|
ptr_array _parents;
|
||||||
|
|
||||||
|
std::string _name;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,29 @@
|
||||||
|
|
||||||
|
set(hdrs
|
||||||
|
../include/pw/scene/node.hpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(srcs
|
||||||
|
node.cpp
|
||||||
|
nodepath.cpp
|
||||||
|
component.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(pwscene
|
||||||
|
STATIC
|
||||||
|
${hdrs}
|
||||||
|
${srcs}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
pwscene
|
||||||
|
PUBLIC
|
||||||
|
../include
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
pwscene
|
||||||
|
PUBLIC
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(pwscene pwcore)
|
30
src/scene/src/component.cpp
Normal file
30
src/scene/src/component.cpp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <pw/core/vector.hpp>
|
||||||
|
#include <pw/core/quaternion.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
class component {
|
||||||
|
|
||||||
|
std::string _name;
|
||||||
|
|
||||||
|
//! only very few components can be attached multiple times
|
||||||
|
virtual bool singular() const { return true; }
|
||||||
|
};
|
||||||
|
|
||||||
|
class transform : public component {
|
||||||
|
|
||||||
|
matrix44d _local;
|
||||||
|
matrix44d _global;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class trs : public transform {
|
||||||
|
|
||||||
|
vector3d _position;
|
||||||
|
vector3d _scale;
|
||||||
|
quaterniond _rotation;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
39
src/scene/src/node.cpp
Normal file
39
src/scene/src/node.cpp
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
#include "pw/scene/node.hpp"
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
node::node(const std::string &name)
|
||||||
|
: _name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
node *node::clone(const unsigned short ©mode) const
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string node::name() const
|
||||||
|
{
|
||||||
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void node::set_name(const std::string &name)
|
||||||
|
{
|
||||||
|
_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void node::add_child(node *anode)
|
||||||
|
{
|
||||||
|
_children.push_back(std::shared_ptr<node>(anode));
|
||||||
|
anode->_parents.push_back(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
node::~node()
|
||||||
|
{
|
||||||
|
_children.clear();
|
||||||
|
_parents.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
0
src/scene/src/nodepath.cpp
Normal file
0
src/scene/src/nodepath.cpp
Normal file
6
src/scene/tests/CMakeLists.txt
Normal file
6
src/scene/tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
add_executable(pwscene_test_node
|
||||||
|
pwscene_test_node.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(pwscene_test_node
|
||||||
|
pwcore pwscene)
|
29
src/scene/tests/pwscene_test_node.cpp
Normal file
29
src/scene/tests/pwscene_test_node.cpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#include <pw/core/vector.hpp>
|
||||||
|
#include <pw/core/serialize.hpp>
|
||||||
|
#include <pw/scene/node.hpp>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc,char **argv) {
|
||||||
|
|
||||||
|
using namespace pw;
|
||||||
|
|
||||||
|
node::ref n(new node("test"));
|
||||||
|
|
||||||
|
// check
|
||||||
|
{
|
||||||
|
n->add_child(new node("sub"));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "n name: " << n->name() << std::endl;
|
||||||
|
std::cout << "n leaf: " << n->is_leaf() << std::endl;
|
||||||
|
std::cout << "n root: " << n->is_root() << std::endl;
|
||||||
|
|
||||||
|
std::cout << "s name: " << n->children()[0]->name() << std::endl;
|
||||||
|
std::cout << "s leaf: " << n->children()[0]->is_leaf() << std::endl;
|
||||||
|
std::cout << "s root: " << n->children()[0]->is_root() << std::endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -22,7 +22,7 @@ target_include_directories(
|
||||||
|
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
pwscripting
|
pwscripting
|
||||||
PUBLIC
|
PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src
|
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/sol
|
${CMAKE_SOURCE_DIR}/src/deps/sol
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,10 +12,10 @@ struct lua_state : public pw::script::state {
|
||||||
pw::scripting::state _state;
|
pw::scripting::state _state;
|
||||||
pw::scripting::table _namespace;
|
pw::scripting::table _namespace;
|
||||||
|
|
||||||
|
|
||||||
void load_modules();
|
void load_modules();
|
||||||
|
|
||||||
lua_state() {
|
lua_state() {
|
||||||
|
|
||||||
// create global pw namespace
|
// create global pw namespace
|
||||||
_namespace = _state.create_named_table("pw");
|
_namespace = _state.create_named_table("pw");
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ void lua_state::load_modules() {
|
||||||
|
|
||||||
_namespace.set("pi",pw::Pi<Scalar>());
|
_namespace.set("pi",pw::Pi<Scalar>());
|
||||||
|
|
||||||
#if 0
|
using namespace pw;
|
||||||
|
|
||||||
_namespace.new_usertype<vector3d>("vector3",
|
_namespace.new_usertype<vector3d>("vector3",
|
||||||
"set",&vector3d::set,
|
"set",&vector3d::set,
|
||||||
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::x), &vector3d::set_x),
|
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::x), &vector3d::set_x),
|
||||||
|
@ -71,25 +72,20 @@ void lua_state::load_modules() {
|
||||||
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
|
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
|
||||||
);
|
);
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pw::script::script()
|
||||||
pw::script::script() {
|
{
|
||||||
|
_state.reset(new lua_state());
|
||||||
}
|
}
|
||||||
|
|
||||||
pw::script::~script()
|
pw::script::~script()
|
||||||
{
|
{
|
||||||
// _state.collect_garbage();
|
_state = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//bool pw::script::load(const std::string &s)
|
|
||||||
//{
|
|
||||||
// return _state.load(s.c_str());
|
|
||||||
//}
|
|
||||||
|
|
||||||
int pw::script::run(const std::string &s)
|
int pw::script::run(const std::string &s)
|
||||||
{
|
{
|
||||||
return _state->run(s);
|
return _state->run(s);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
-- loading our libraries
|
-- loading our libraries
|
||||||
pw.script:initialize()
|
pw.script:initialize()
|
||||||
|
|
||||||
print("hellow pixwerx")
|
print("hello pixwerx!")
|
||||||
|
|
||||||
local v = pw.vector3.new()
|
local v = pw.vector3.new()
|
||||||
v:set(0,1,2)
|
v:set(0,1,2)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue