add skeleton:is_visible(...), skeleton:set_visible(...)
This commit is contained in:
@@ -69,6 +69,31 @@ static int l_index(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_visible(lua::State* L) {
|
||||
if (auto entity = get_entity(L, 1)) {
|
||||
auto& skeleton = entity->getSkeleton();
|
||||
if (!lua::isnoneornil(L, 2)) {
|
||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
||||
return lua::pushboolean(L, skeleton.flags.at(index).visible);
|
||||
}
|
||||
return lua::pushboolean(L, skeleton.visible);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_set_visible(lua::State* L) {
|
||||
if (auto entity = get_entity(L, 1)) {
|
||||
auto& skeleton = entity->getSkeleton();
|
||||
if (!lua::isnoneornil(L, 3)) {
|
||||
auto index = index_range_check(skeleton, lua::tointeger(L, 2));
|
||||
skeleton.flags.at(index).visible = lua::toboolean(L, 3);
|
||||
} else {
|
||||
skeleton.visible = lua::toboolean(L, 2);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg skeletonlib [] = {
|
||||
{"get_model", lua::wrap<l_get_model>},
|
||||
{"get_matrix", lua::wrap<l_get_matrix>},
|
||||
@@ -76,5 +101,7 @@ const luaL_Reg skeletonlib [] = {
|
||||
{"get_texture", lua::wrap<l_get_texture>},
|
||||
{"set_texture", lua::wrap<l_set_texture>},
|
||||
{"index", lua::wrap<l_index>},
|
||||
{"is_visible", lua::wrap<l_is_visible>},
|
||||
{"set_visible", lua::wrap<l_set_visible>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
+13
-3
@@ -9,6 +9,7 @@
|
||||
#include "../window/Camera.hpp"
|
||||
#include "../items/Inventory.hpp"
|
||||
#include "../objects/Entities.hpp"
|
||||
#include "../objects/rigging.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <utility>
|
||||
@@ -66,9 +67,18 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
||||
return;
|
||||
}
|
||||
auto& hitbox = entity->getRigidbody().hitbox;
|
||||
auto& transform = entity->getTransform();
|
||||
transform.setRot(
|
||||
glm::rotate(glm::mat4(1.0f), glm::radians(cam.x), glm::vec3(0, 1, 0)));
|
||||
auto& skeleton = entity->getSkeleton();
|
||||
|
||||
skeleton.visible = currentCamera != camera;
|
||||
|
||||
size_t bodyIndex = skeleton.config->find("body")->getIndex();
|
||||
size_t headIndex = skeleton.config->find("head")->getIndex();
|
||||
|
||||
skeleton.pose.matrices[bodyIndex] =
|
||||
glm::rotate(glm::mat4(1.0f), glm::radians(cam.x-90), glm::vec3(0, 1, 0));
|
||||
skeleton.pose.matrices[headIndex] = glm::rotate(glm::rotate(
|
||||
glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.6f, 0.0f)),
|
||||
glm::radians(-cam.y), glm::vec3(0, 0, 1)), glm::radians(90.0f), glm::vec3(0, 1, 0));
|
||||
|
||||
bool crouch = input.shift && hitbox.grounded && !input.sprint;
|
||||
float speed = this->speed;
|
||||
|
||||
@@ -70,9 +70,16 @@ void SkeletonConfig::render(
|
||||
const glm::mat4& matrix) const
|
||||
{
|
||||
update(skeleton, matrix);
|
||||
|
||||
if (!skeleton.visible) {
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0; i < nodes.size(); i++) {
|
||||
auto* node = nodes[i];
|
||||
node->refreshModel(assets);
|
||||
if (!skeleton.flags[i].visible) {
|
||||
continue;
|
||||
}
|
||||
if (auto model = node->getModel()) {
|
||||
batch.pushMatrix(skeleton.calculated.matrices[i]);
|
||||
batch.draw(model, &skeleton.textures);
|
||||
|
||||
+12
-2
@@ -67,11 +67,17 @@ namespace rigging {
|
||||
}
|
||||
};
|
||||
|
||||
struct BoneFlags {
|
||||
bool visible: 1;
|
||||
};
|
||||
|
||||
struct Skeleton {
|
||||
const SkeletonConfig* config;
|
||||
Pose pose;
|
||||
Pose calculated;
|
||||
std::vector<BoneFlags> flags;
|
||||
std::unordered_map<std::string, std::string> textures;
|
||||
bool visible;
|
||||
};
|
||||
|
||||
class SkeletonConfig {
|
||||
@@ -104,9 +110,13 @@ namespace rigging {
|
||||
const glm::mat4& matrix) const;
|
||||
|
||||
Skeleton instance() const {
|
||||
return Skeleton {
|
||||
this, Pose(nodes.size()), Pose(nodes.size()), {}
|
||||
auto rig = Skeleton {
|
||||
this, Pose(nodes.size()), Pose(nodes.size()), {}, {}, true
|
||||
};
|
||||
for (size_t i = 0; i < nodes.size(); i++) {
|
||||
rig.flags.push_back({true});
|
||||
}
|
||||
return rig;
|
||||
}
|
||||
|
||||
Bone* find(std::string_view str) const;
|
||||
|
||||
Reference in New Issue
Block a user