add modeltree component
This commit is contained in:
@@ -23,6 +23,13 @@ function new_Rigidbody(eid)
|
|||||||
return setmetatable({eid=eid}, Rigidbody)
|
return setmetatable({eid=eid}, Rigidbody)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local Modeltree = {__index={
|
||||||
|
}}
|
||||||
|
|
||||||
|
function new_Modeltree(eid)
|
||||||
|
return setmetatable({eid=eid}, Modeltree)
|
||||||
|
end
|
||||||
|
|
||||||
-- Entity class
|
-- Entity class
|
||||||
|
|
||||||
local Entity = {__index={
|
local Entity = {__index={
|
||||||
@@ -36,6 +43,7 @@ return {
|
|||||||
local entity = setmetatable({eid=eid}, Entity)
|
local entity = setmetatable({eid=eid}, Entity)
|
||||||
entity.transform = new_Transform(eid)
|
entity.transform = new_Transform(eid)
|
||||||
entity.rigidbody = new_Rigidbody(eid)
|
entity.rigidbody = new_Rigidbody(eid)
|
||||||
|
entity.modeltree = new_Modeltree(eid)
|
||||||
entity.data = {}
|
entity.data = {}
|
||||||
entities[eid] = entity;
|
entities[eid] = entity;
|
||||||
return entity
|
return entity
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "../../../window/Camera.hpp"
|
#include "../../../window/Camera.hpp"
|
||||||
#include "../../../frontend/hud.hpp"
|
#include "../../../frontend/hud.hpp"
|
||||||
#include "../../../content/Content.hpp"
|
#include "../../../content/Content.hpp"
|
||||||
|
#include "../../../engine.hpp"
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ static int l_spawn(lua::State* L) {
|
|||||||
if (lua::gettop(L) > 2) {
|
if (lua::gettop(L) > 2) {
|
||||||
args = lua::tovalue(L, 3);
|
args = lua::tovalue(L, 3);
|
||||||
}
|
}
|
||||||
level->entities->spawn(def, pos, args);
|
level->entities->spawn(scripting::engine->getAssets(), def, pos, args);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "../graphics/core/Model.hpp"
|
#include "../graphics/core/Model.hpp"
|
||||||
#include "../maths/FrustumCulling.hpp"
|
#include "../maths/FrustumCulling.hpp"
|
||||||
#include "../objects/EntityDef.hpp"
|
#include "../objects/EntityDef.hpp"
|
||||||
|
#include "../objects/rigging.hpp"
|
||||||
#include "../logic/scripting/scripting.hpp"
|
#include "../logic/scripting/scripting.hpp"
|
||||||
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
@@ -30,7 +31,16 @@ void Entity::destroy() {
|
|||||||
Entities::Entities(Level* level) : level(level) {
|
Entities::Entities(Level* level) : level(level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
entityid_t Entities::spawn(EntityDef& def, glm::vec3 pos, dynamic::Value args) {
|
entityid_t Entities::spawn(
|
||||||
|
Assets* assets,
|
||||||
|
EntityDef& def,
|
||||||
|
glm::vec3 pos,
|
||||||
|
dynamic::Value args)
|
||||||
|
{
|
||||||
|
auto rig = assets->get<rigging::RigConfig>(def.rigName);
|
||||||
|
if (rig == nullptr) {
|
||||||
|
throw std::runtime_error("rig "+def.rigName+" not found");
|
||||||
|
}
|
||||||
auto entity = registry.create();
|
auto entity = registry.create();
|
||||||
glm::vec3 size(1);
|
glm::vec3 size(1);
|
||||||
auto id = nextID++;
|
auto id = nextID++;
|
||||||
@@ -54,9 +64,12 @@ entityid_t Entities::spawn(EntityDef& def, glm::vec3 pos, dynamic::Value args) {
|
|||||||
}
|
}
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
auto& scripting = registry.emplace<Scripting>(entity, entity_funcs_set {}, nullptr);
|
auto& scripting = registry.emplace<Scripting>(
|
||||||
|
entity, entity_funcs_set {}, nullptr);
|
||||||
entities[id] = entity;
|
entities[id] = entity;
|
||||||
scripting.env = scripting::on_entity_spawn(def, id, scripting.funcsset, std::move(args));
|
scripting.env = scripting::on_entity_spawn(
|
||||||
|
def, id, scripting.funcsset, std::move(args));
|
||||||
|
registry.emplace<rigging::Rig>(entity, rig->instance());
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +186,10 @@ void Entities::renderDebug(LineBatch& batch, const Frustum& frustum) {
|
|||||||
batch.box(hitbox.position, hitbox.halfsize * 2.0f, glm::vec4(1.0f));
|
batch.box(hitbox.position, hitbox.halfsize * 2.0f, glm::vec4(1.0f));
|
||||||
|
|
||||||
for (auto& trigger : rigidbody.triggers) {
|
for (auto& trigger : rigidbody.triggers) {
|
||||||
batch.box(trigger.calculated.center(), trigger.calculated.size(), glm::vec4(1.0f, 1.0f, 0.0f, 1.0f));
|
batch.box(
|
||||||
|
trigger.calculated.center(),
|
||||||
|
trigger.calculated.size(),
|
||||||
|
glm::vec4(1.0f, 1.0f, 0.0f, 1.0f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,11 @@ public:
|
|||||||
void renderDebug(LineBatch& batch, const Frustum& frustum);
|
void renderDebug(LineBatch& batch, const Frustum& frustum);
|
||||||
void render(Assets* assets, ModelBatch& batch, const Frustum& frustum);
|
void render(Assets* assets, ModelBatch& batch, const Frustum& frustum);
|
||||||
|
|
||||||
entityid_t spawn(EntityDef& def, glm::vec3 pos, dynamic::Value args=dynamic::NONE);
|
entityid_t spawn(
|
||||||
|
Assets* assets,
|
||||||
|
EntityDef& def,
|
||||||
|
glm::vec3 pos,
|
||||||
|
dynamic::Value args=dynamic::NONE);
|
||||||
|
|
||||||
std::optional<Entity> get(entityid_t id) {
|
std::optional<Entity> get(entityid_t id) {
|
||||||
const auto& found = entities.find(id);
|
const auto& found = entities.find(id);
|
||||||
|
|||||||
+18
-7
@@ -17,9 +17,14 @@ namespace model {
|
|||||||
|
|
||||||
namespace rigging {
|
namespace rigging {
|
||||||
struct Rig;
|
struct Rig;
|
||||||
|
class RigConfig;
|
||||||
|
|
||||||
struct Pose {
|
struct Pose {
|
||||||
std::vector<glm::mat4> matrices;
|
std::vector<glm::mat4> matrices;
|
||||||
|
|
||||||
|
Pose(size_t size) : matrices(size) {
|
||||||
|
matrices.resize(size);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class RigNode {
|
class RigNode {
|
||||||
@@ -49,6 +54,13 @@ namespace rigging {
|
|||||||
return subnodes;
|
return subnodes;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Rig {
|
||||||
|
RigConfig* config;
|
||||||
|
Pose pose;
|
||||||
|
Pose calculated;
|
||||||
|
std::vector<std::string> textures;
|
||||||
|
};
|
||||||
|
|
||||||
class RigConfig {
|
class RigConfig {
|
||||||
std::unique_ptr<RigNode> root;
|
std::unique_ptr<RigNode> root;
|
||||||
@@ -66,18 +78,17 @@ namespace rigging {
|
|||||||
void update(Rig& rig, glm::mat4 matrix);
|
void update(Rig& rig, glm::mat4 matrix);
|
||||||
void setup(const Assets* assets, RigNode* node=nullptr);
|
void setup(const Assets* assets, RigNode* node=nullptr);
|
||||||
|
|
||||||
|
Rig instance() {
|
||||||
|
return Rig {
|
||||||
|
this, Pose(nodes.size()), Pose(nodes.size()), {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static std::unique_ptr<RigConfig> parse(
|
static std::unique_ptr<RigConfig> parse(
|
||||||
std::string_view src,
|
std::string_view src,
|
||||||
std::string_view file
|
std::string_view file
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Rig {
|
|
||||||
RigConfig* config;
|
|
||||||
Pose pose;
|
|
||||||
Pose calculated;
|
|
||||||
std::vector<std::string> textures;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // OBJECTS_SKELETON_HPP_
|
#endif // OBJECTS_SKELETON_HPP_
|
||||||
|
|||||||
Reference in New Issue
Block a user