add modeltree:get_model(index)
This commit is contained in:
parent
28ceffde9e
commit
3fe66e134d
@ -14,7 +14,7 @@ function on_hud_open()
|
|||||||
(math.random() - 0.5) * 1
|
(math.random() - 0.5) * 1
|
||||||
}), DROP_FORCE)
|
}), DROP_FORCE)
|
||||||
|
|
||||||
local drop = entity.spawn("base:drop", ppos)
|
local drop = entities.spawn("base:drop", ppos)
|
||||||
drop.rigidbody:set_vel(vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
|
drop.rigidbody:set_vel(vec3.add(throw_force, vec3.add(pvel, DROP_INIT_VEL)))
|
||||||
drop.transform:set_rot(mat4.rotate(mat4.rotate(mat4.rotate({0, 1, 0}, math.random() * 360),
|
drop.transform:set_rot(mat4.rotate(mat4.rotate(mat4.rotate({0, 1, 0}, math.random() * 360),
|
||||||
{1, 0, 0}, math.random() * 360), {0, 0, 1}, math.random() * 360))
|
{1, 0, 0}, math.random() * 360), {0, 0, 1}, math.random() * 360))
|
||||||
|
|||||||
@ -24,6 +24,7 @@ function new_Rigidbody(eid)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local Modeltree = {__index={
|
local Modeltree = {__index={
|
||||||
|
get_model=function(self) return __modeltree.get_model(self.eid) end,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
function new_Modeltree(eid)
|
function new_Modeltree(eid)
|
||||||
@ -33,7 +34,7 @@ end
|
|||||||
-- Entity class
|
-- Entity class
|
||||||
|
|
||||||
local Entity = {__index={
|
local Entity = {__index={
|
||||||
despawn=function(self) return entity.despawn(self.eid) end,
|
despawn=function(self) return entities.despawn(self.eid) end,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
local entities = {}
|
local entities = {}
|
||||||
|
|||||||
@ -21,15 +21,18 @@ extern const luaL_Reg jsonlib [];
|
|||||||
extern const luaL_Reg mat4lib [];
|
extern const luaL_Reg mat4lib [];
|
||||||
extern const luaL_Reg packlib [];
|
extern const luaL_Reg packlib [];
|
||||||
extern const luaL_Reg playerlib [];
|
extern const luaL_Reg playerlib [];
|
||||||
extern const luaL_Reg rigidbodylib [];
|
|
||||||
extern const luaL_Reg timelib [];
|
extern const luaL_Reg timelib [];
|
||||||
extern const luaL_Reg tomllib [];
|
extern const luaL_Reg tomllib [];
|
||||||
extern const luaL_Reg transformlib [];
|
|
||||||
extern const luaL_Reg vec2lib [];
|
extern const luaL_Reg vec2lib [];
|
||||||
extern const luaL_Reg vec3lib [];
|
extern const luaL_Reg vec3lib [];
|
||||||
extern const luaL_Reg vec4lib [];
|
extern const luaL_Reg vec4lib [];
|
||||||
extern const luaL_Reg worldlib [];
|
extern const luaL_Reg worldlib [];
|
||||||
|
|
||||||
|
// Components
|
||||||
|
extern const luaL_Reg modeltreelib [];
|
||||||
|
extern const luaL_Reg rigidbodylib [];
|
||||||
|
extern const luaL_Reg transformlib [];
|
||||||
|
|
||||||
// Lua Overrides
|
// Lua Overrides
|
||||||
extern int l_print(lua::State* L);
|
extern int l_print(lua::State* L);
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include "../../../world/Level.hpp"
|
#include "../../../world/Level.hpp"
|
||||||
#include "../../../objects/Player.hpp"
|
#include "../../../objects/Player.hpp"
|
||||||
#include "../../../objects/Entities.hpp"
|
#include "../../../objects/Entities.hpp"
|
||||||
|
#include "../../../objects/rigging.hpp"
|
||||||
#include "../../../physics/Hitbox.hpp"
|
#include "../../../physics/Hitbox.hpp"
|
||||||
#include "../../../window/Camera.hpp"
|
#include "../../../window/Camera.hpp"
|
||||||
#include "../../../frontend/hud.hpp"
|
#include "../../../frontend/hud.hpp"
|
||||||
@ -110,6 +111,16 @@ static int l_get_size(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_modeltree_get_model(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
auto& rig = entity->getModeltree();
|
||||||
|
auto* rigConfig = rig.config;
|
||||||
|
auto index = lua::tointeger(L, 2);
|
||||||
|
return lua::pushstring(L, rigConfig->getNodes()[index]->getModelName());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg entitylib [] = {
|
const luaL_Reg entitylib [] = {
|
||||||
{"exists", lua::wrap<l_exists>},
|
{"exists", lua::wrap<l_exists>},
|
||||||
{"spawn", lua::wrap<l_spawn>},
|
{"spawn", lua::wrap<l_spawn>},
|
||||||
@ -117,6 +128,11 @@ const luaL_Reg entitylib [] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const luaL_Reg modeltreelib [] = {
|
||||||
|
{"get_model", lua::wrap<l_modeltree_get_model>},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
const luaL_Reg transformlib [] = {
|
const luaL_Reg transformlib [] = {
|
||||||
{"get_pos", lua::wrap<l_get_pos>},
|
{"get_pos", lua::wrap<l_get_pos>},
|
||||||
{"set_pos", lua::wrap<l_set_pos>},
|
{"set_pos", lua::wrap<l_set_pos>},
|
||||||
|
|||||||
@ -22,16 +22,15 @@ static void remove_lib_funcs(lua::State* L, const char* libname, const char* fun
|
|||||||
pushnil(L);
|
pushnil(L);
|
||||||
setfield(L, funcs[i], -2);
|
setfield(L, funcs[i], -2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
pop(L);
|
pop(L);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void create_libs(lua::State* L) {
|
static void create_libs(lua::State* L) {
|
||||||
openlib(L, "audio", audiolib);
|
openlib(L, "audio", audiolib);
|
||||||
openlib(L, "block", blocklib);
|
openlib(L, "block", blocklib);
|
||||||
openlib(L, "console", consolelib);
|
openlib(L, "console", consolelib);
|
||||||
openlib(L, "core", corelib);
|
openlib(L, "core", corelib);
|
||||||
openlib(L, "entity", entitylib);
|
|
||||||
openlib(L, "file", filelib);
|
openlib(L, "file", filelib);
|
||||||
openlib(L, "gui", guilib);
|
openlib(L, "gui", guilib);
|
||||||
openlib(L, "input", inputlib);
|
openlib(L, "input", inputlib);
|
||||||
@ -48,7 +47,10 @@ static void create_libs(lua::State* L) {
|
|||||||
openlib(L, "vec4", vec4lib);
|
openlib(L, "vec4", vec4lib);
|
||||||
openlib(L, "world", worldlib);
|
openlib(L, "world", worldlib);
|
||||||
|
|
||||||
|
openlib(L, "entities", entitylib);
|
||||||
|
|
||||||
// components
|
// components
|
||||||
|
openlib(L, "__modeltree", modeltreelib);
|
||||||
openlib(L, "__rigidbody", rigidbodylib);
|
openlib(L, "__rigidbody", rigidbodylib);
|
||||||
openlib(L, "__transform", transformlib);
|
openlib(L, "__transform", transformlib);
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,10 @@ void Entity::destroy() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rigging::Rig& Entity::getModeltree() const {
|
||||||
|
return registry.get<rigging::Rig>(entity);
|
||||||
|
}
|
||||||
|
|
||||||
Entities::Entities(Level* level) : level(level) {
|
Entities::Entities(Level* level) : level(level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,8 @@ class LineBatch;
|
|||||||
class ModelBatch;
|
class ModelBatch;
|
||||||
class Frustum;
|
class Frustum;
|
||||||
class Entities;
|
class Entities;
|
||||||
namespace riggining {
|
|
||||||
|
namespace rigging {
|
||||||
struct Rig;
|
struct Rig;
|
||||||
class RigConfig;
|
class RigConfig;
|
||||||
}
|
}
|
||||||
@ -112,6 +113,8 @@ public:
|
|||||||
return registry.get<Scripting>(entity);
|
return registry.get<Scripting>(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rigging::Rig& getModeltree() const;
|
||||||
|
|
||||||
entityid_t getUID() const {
|
entityid_t getUID() const {
|
||||||
return registry.get<EntityId>(entity).uid;
|
return registry.get<EntityId>(entity).uid;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -101,6 +101,10 @@ namespace rigging {
|
|||||||
std::string_view src,
|
std::string_view src,
|
||||||
std::string_view file
|
std::string_view file
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const std::vector<RigNode*>& getNodes() const {
|
||||||
|
return nodes;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user