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