add skeleton:index(...) and player test model
This commit is contained in:
parent
e8e3626c63
commit
055781eeaf
@ -128,4 +128,7 @@ rig:get_texture(key: str) -> str
|
|||||||
|
|
||||||
-- Assigns texture by key
|
-- Assigns texture by key
|
||||||
rig:set_texture(key: str, value: str)
|
rig:set_texture(key: str, value: str)
|
||||||
|
|
||||||
|
-- Returns the bone index by name or nil
|
||||||
|
rig:index(name: str) -> int
|
||||||
```
|
```
|
||||||
|
|||||||
@ -129,4 +129,7 @@ rig:get_texture(key: str) -> str
|
|||||||
|
|
||||||
-- Назначает текстуру по ключу
|
-- Назначает текстуру по ключу
|
||||||
rig:set_texture(key: str, value: str)
|
rig:set_texture(key: str, value: str)
|
||||||
|
|
||||||
|
-- Возвращает индекс кости по имени или nil
|
||||||
|
rig:index(name: str) -> int
|
||||||
```
|
```
|
||||||
|
|||||||
79
res/content/base/models/player.obj
Normal file
79
res/content/base/models/player.obj
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
o Cube
|
||||||
|
v 0.125000 -0.900000 -0.125000
|
||||||
|
v 0.125000 -0.900000 0.125000
|
||||||
|
v -0.125000 -0.900000 0.125000
|
||||||
|
v -0.125000 -0.900000 -0.125000
|
||||||
|
v 0.125000 0.700000 -0.125000
|
||||||
|
v 0.125000 0.700000 0.125000
|
||||||
|
v -0.125000 0.700000 0.125000
|
||||||
|
v -0.125000 0.700000 -0.125000
|
||||||
|
v -0.238204 0.898288 -0.238204
|
||||||
|
v -0.238204 0.421881 -0.238204
|
||||||
|
v -0.238204 0.898288 0.238204
|
||||||
|
v -0.238204 0.421881 0.238204
|
||||||
|
v 0.238204 0.421881 0.238204
|
||||||
|
v 0.238204 0.898288 0.238204
|
||||||
|
v 0.238204 0.421881 -0.238204
|
||||||
|
v 0.238204 0.898288 -0.238204
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vt 0.735873 0.213345
|
||||||
|
vt 0.735873 0.739780
|
||||||
|
vt 0.209439 0.739780
|
||||||
|
vt 0.209439 0.213345
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.982503 0.209065
|
||||||
|
vt 0.783122 0.009685
|
||||||
|
vt 0.982503 0.009685
|
||||||
|
vt 0.783122 0.209065
|
||||||
|
vn 0.0000 -1.0000 -0.0000
|
||||||
|
vn 0.0000 1.0000 0.0000
|
||||||
|
vn 1.0000 0.0000 0.0000
|
||||||
|
vn -0.0000 -0.0000 1.0000
|
||||||
|
vn -1.0000 -0.0000 -0.0000
|
||||||
|
vn 0.0000 0.0000 -1.0000
|
||||||
|
usemtl entities/player
|
||||||
|
s off
|
||||||
|
f 1/1/1 2/2/1 3/3/1 4/4/1
|
||||||
|
f 5/5/2 8/6/2 7/7/2 6/8/2
|
||||||
|
f 1/1/3 5/9/3 6/10/3 2/11/3
|
||||||
|
f 2/12/4 6/13/4 7/7/4 3/14/4
|
||||||
|
f 3/15/5 7/16/5 8/17/5 4/4/5
|
||||||
|
f 5/5/6 1/18/6 4/19/6 8/20/6
|
||||||
|
f 12/21/5 11/22/5 9/23/5 10/24/5
|
||||||
|
f 10/25/6 9/26/6 16/27/6 15/28/6
|
||||||
|
f 15/29/3 16/30/3 14/31/3 13/32/3
|
||||||
|
f 13/33/4 14/34/4 11/35/4 12/36/4
|
||||||
|
f 10/37/1 15/38/1 13/39/1 12/36/1
|
||||||
|
f 16/40/2 9/41/2 11/35/2 14/42/2
|
||||||
@ -7,6 +7,7 @@
|
|||||||
"models": [
|
"models": [
|
||||||
"block",
|
"block",
|
||||||
"drop-block",
|
"drop-block",
|
||||||
"drop-item"
|
"drop-item",
|
||||||
|
"player"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,9 @@
|
|||||||
{
|
{
|
||||||
"root": {}
|
"root": {
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"model": "player"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
res/content/base/textures/entities/player.png
Normal file
BIN
res/content/base/textures/entities/player.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 579 B |
@ -43,6 +43,7 @@ local Skeleton = {__index={
|
|||||||
set_matrix=function(self, i, m) return __skeleton.set_matrix(self.eid, i, m) end,
|
set_matrix=function(self, i, m) return __skeleton.set_matrix(self.eid, i, m) end,
|
||||||
get_texture=function(self, s) return __skeleton.get_texture(self.eid, s) end,
|
get_texture=function(self, s) return __skeleton.get_texture(self.eid, s) end,
|
||||||
set_texture=function(self, s, s2) return __skeleton.set_texture(self.eid, s, s2) end,
|
set_texture=function(self, s, s2) return __skeleton.set_texture(self.eid, s, s2) end,
|
||||||
|
index=function(self, s) return __skeleton.index(self.eid, s) end,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
local function new_Skeleton(eid)
|
local function new_Skeleton(eid)
|
||||||
|
|||||||
@ -59,11 +59,22 @@ static int l_set_texture(lua::State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_index(lua::State* L) {
|
||||||
|
if (auto entity = get_entity(L, 1)) {
|
||||||
|
auto& skeleton = entity->getSkeleton();
|
||||||
|
if (auto bone = skeleton.config->find(lua::require_string(L, 2))) {
|
||||||
|
return lua::tointeger(L, bone->getIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg skeletonlib [] = {
|
const luaL_Reg skeletonlib [] = {
|
||||||
{"get_model", lua::wrap<l_get_model>},
|
{"get_model", lua::wrap<l_get_model>},
|
||||||
{"get_matrix", lua::wrap<l_get_matrix>},
|
{"get_matrix", lua::wrap<l_get_matrix>},
|
||||||
{"set_matrix", lua::wrap<l_set_matrix>},
|
{"set_matrix", lua::wrap<l_set_matrix>},
|
||||||
{"get_texture", lua::wrap<l_get_texture>},
|
{"get_texture", lua::wrap<l_get_texture>},
|
||||||
{"set_texture", lua::wrap<l_set_texture>},
|
{"set_texture", lua::wrap<l_set_texture>},
|
||||||
|
{"index", lua::wrap<l_index>},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -49,7 +49,7 @@ void Player::updateEntity() {
|
|||||||
} else if (auto entity = level->entities->get(eid)) {
|
} else if (auto entity = level->entities->get(eid)) {
|
||||||
position = entity->getTransform().pos;
|
position = entity->getTransform().pos;
|
||||||
} else {
|
} else {
|
||||||
// check if chunk loaded
|
// TODO: check if chunk loaded
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,11 +61,16 @@ Hitbox* Player::getHitbox() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Player::updateInput(PlayerInput& input, float delta) {
|
void Player::updateInput(PlayerInput& input, float delta) {
|
||||||
auto hitbox = getHitbox();
|
auto entity = level->entities->get(eid);
|
||||||
if (hitbox == nullptr) {
|
if (!entity.has_value()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool crouch = input.shift && hitbox->grounded && !input.sprint;
|
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)));
|
||||||
|
|
||||||
|
bool crouch = input.shift && hitbox.grounded && !input.sprint;
|
||||||
float speed = this->speed;
|
float speed = this->speed;
|
||||||
if (flight){
|
if (flight){
|
||||||
speed *= FLIGHT_SPEED_MUL;
|
speed *= FLIGHT_SPEED_MUL;
|
||||||
@ -74,7 +79,7 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
|||||||
speed *= CHEAT_SPEED_MUL;
|
speed *= CHEAT_SPEED_MUL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hitbox->crouching = crouch;
|
hitbox.crouching = crouch;
|
||||||
if (crouch) {
|
if (crouch) {
|
||||||
speed *= CROUCH_SPEED_MUL;
|
speed *= CROUCH_SPEED_MUL;
|
||||||
} else if (input.sprint) {
|
} else if (input.sprint) {
|
||||||
@ -96,37 +101,37 @@ void Player::updateInput(PlayerInput& input, float delta) {
|
|||||||
}
|
}
|
||||||
if (glm::length(dir) > 0.0f){
|
if (glm::length(dir) > 0.0f){
|
||||||
dir = glm::normalize(dir);
|
dir = glm::normalize(dir);
|
||||||
hitbox->velocity += dir * speed * delta * 9.0f;
|
hitbox.velocity += dir * speed * delta * 9.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
hitbox->linearDamping = PLAYER_GROUND_DAMPING;
|
hitbox.linearDamping = PLAYER_GROUND_DAMPING;
|
||||||
hitbox->verticalDamping = flight;
|
hitbox.verticalDamping = flight;
|
||||||
hitbox->gravityScale = flight ? 0.0f : 1.0f;
|
hitbox.gravityScale = flight ? 0.0f : 1.0f;
|
||||||
if (flight){
|
if (flight){
|
||||||
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
hitbox.linearDamping = PLAYER_AIR_DAMPING;
|
||||||
if (input.jump){
|
if (input.jump){
|
||||||
hitbox->velocity.y += speed * delta * 9;
|
hitbox.velocity.y += speed * delta * 9;
|
||||||
}
|
}
|
||||||
if (input.shift){
|
if (input.shift){
|
||||||
hitbox->velocity.y -= speed * delta * 9;
|
hitbox.velocity.y -= speed * delta * 9;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hitbox->grounded) {
|
if (!hitbox.grounded) {
|
||||||
hitbox->linearDamping = PLAYER_AIR_DAMPING;
|
hitbox.linearDamping = PLAYER_AIR_DAMPING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.jump && hitbox->grounded){
|
if (input.jump && hitbox.grounded){
|
||||||
hitbox->velocity.y = JUMP_FORCE;
|
hitbox.velocity.y = JUMP_FORCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((input.flight && !noclip) ||
|
if ((input.flight && !noclip) ||
|
||||||
(input.noclip && flight == noclip)){
|
(input.noclip && flight == noclip)){
|
||||||
flight = !flight;
|
flight = !flight;
|
||||||
if (flight){
|
if (flight){
|
||||||
hitbox->velocity.y += 1.0f;
|
hitbox.velocity.y += 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hitbox->type = noclip ? BodyType::KINEMATIC : BodyType::DYNAMIC;
|
hitbox.type = noclip ? BodyType::KINEMATIC : BodyType::DYNAMIC;
|
||||||
if (input.noclip) {
|
if (input.noclip) {
|
||||||
noclip = !noclip;
|
noclip = !noclip;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -81,6 +81,16 @@ void SkeletonConfig::render(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bone* SkeletonConfig::find(std::string_view str) const {
|
||||||
|
for (size_t i = 0; i < nodes.size(); i++) {
|
||||||
|
auto* node = nodes[i];
|
||||||
|
if (node->getName() == str) {
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
static std::tuple<size_t, std::unique_ptr<Bone>> read_node(
|
static std::tuple<size_t, std::unique_ptr<Bone>> read_node(
|
||||||
dynamic::Map* root, size_t index
|
dynamic::Map* root, size_t index
|
||||||
) {
|
) {
|
||||||
@ -88,19 +98,19 @@ static std::tuple<size_t, std::unique_ptr<Bone>> read_node(
|
|||||||
std::string model;
|
std::string model;
|
||||||
root->str("name", name);
|
root->str("name", name);
|
||||||
root->str("model", model);
|
root->str("model", model);
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Bone>> bones;
|
std::vector<std::unique_ptr<Bone>> bones;
|
||||||
size_t count = 1;
|
size_t count = 1;
|
||||||
if (auto nodesList = root->list("nodes")) {
|
if (auto nodesList = root->list("nodes")) {
|
||||||
for (size_t i = 0; i < nodesList->size(); i++) {
|
for (size_t i = 0; i < nodesList->size(); i++) {
|
||||||
if (const auto& map = nodesList->map(i)) {
|
if (const auto& map = nodesList->map(i)) {
|
||||||
auto [subcount, subNode] = read_node(map.get(), index+count);
|
auto [subcount, subNode] = read_node(map.get(), index+count);
|
||||||
subcount += count;
|
count += subcount;
|
||||||
bones.push_back(std::move(subNode));
|
bones.push_back(std::move(subNode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {index + count, std::make_unique<Bone>(index, name, model, std::move(bones))};
|
return {count, std::make_unique<Bone>(index, name, model, std::move(bones))};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<SkeletonConfig> SkeletonConfig::parse(
|
std::unique_ptr<SkeletonConfig> SkeletonConfig::parse(
|
||||||
|
|||||||
@ -46,6 +46,10 @@ namespace rigging {
|
|||||||
|
|
||||||
void refreshModel(const Assets* assets);
|
void refreshModel(const Assets* assets);
|
||||||
|
|
||||||
|
const std::string& getName() const {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& getModelName() const {
|
const std::string& getModelName() const {
|
||||||
return modelName;
|
return modelName;
|
||||||
}
|
}
|
||||||
@ -105,6 +109,8 @@ namespace rigging {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bone* find(std::string_view str) const;
|
||||||
|
|
||||||
static std::unique_ptr<SkeletonConfig> parse(
|
static std::unique_ptr<SkeletonConfig> parse(
|
||||||
std::string_view src,
|
std::string_view src,
|
||||||
std::string_view file,
|
std::string_view file,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user