mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-21 18:09:46 +00:00
feat: variant-based hitboxes
This commit is contained in:
parent
563001351b
commit
b8b2e4f451
16 changed files with 145 additions and 102 deletions
|
|
@ -70,9 +70,7 @@ void BlockWrapsRenderer::draw(BlockWrapper& wrapper, const Texture* texture) {
|
|||
);
|
||||
break;
|
||||
case BlockModelType::AABB: {
|
||||
const auto& aabb =
|
||||
(def.rotatable ? def.rt.hitboxes[vox->state.rotation]
|
||||
: def.hitboxes).at(0);
|
||||
const auto& aabb = def.getHitboxes(vox->state).at(0);
|
||||
const auto& size = aabb.size();
|
||||
batch->cube(
|
||||
glm::vec3(wrapper.position) + aabb.center(),
|
||||
|
|
@ -121,9 +119,7 @@ void BlockWrapsRenderer::refreshWrapper(BlockWrapper& wrapper) {
|
|||
wrapper.modelType = def.getModel(vox->state.userbits).type;
|
||||
switch (wrapper.modelType) {
|
||||
case BlockModelType::AABB: {
|
||||
const auto& aabb =
|
||||
(def.rotatable ? def.rt.hitboxes[vox->state.rotation]
|
||||
: def.hitboxes).at(0);
|
||||
const auto& aabb = def.getHitboxes(vox->state).at(0);
|
||||
const auto& size = aabb.size();
|
||||
wrapper.uvRegions[0].scale(size.z, size.y);
|
||||
wrapper.uvRegions[1].scale(size.z, size.y);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ std::unique_ptr<ImageData> BlocksPreview::draw(
|
|||
case BlockModelType::AABB:
|
||||
{
|
||||
glm::vec3 hitbox {};
|
||||
for (const auto& box : def.hitboxes) {
|
||||
for (const auto& box : def.defaults.hitboxes) {
|
||||
hitbox = glm::max(hitbox, box.size());
|
||||
}
|
||||
offset = glm::vec3(1, 1, 0.0f);
|
||||
|
|
|
|||
|
|
@ -224,15 +224,16 @@ void BlocksRenderer::blockAABB(
|
|||
const glm::ivec3& icoord,
|
||||
const UVRegion(&texfaces)[6],
|
||||
const Block* block,
|
||||
ubyte rotation,
|
||||
blockstate states,
|
||||
bool lights,
|
||||
bool ao
|
||||
) {
|
||||
if (block->hitboxes.empty()) {
|
||||
const auto& hitboxes = block->getVariantByBits(states.userbits).hitboxes;
|
||||
if (hitboxes.empty()) {
|
||||
return;
|
||||
}
|
||||
AABB hitbox = block->hitboxes[0];
|
||||
for (const auto& box : block->hitboxes) {
|
||||
AABB hitbox = hitboxes[0];
|
||||
for (const auto& box : hitboxes) {
|
||||
hitbox.a = glm::min(hitbox.a, box.a);
|
||||
hitbox.b = glm::max(hitbox.b, box.b);
|
||||
}
|
||||
|
|
@ -243,7 +244,7 @@ void BlocksRenderer::blockAABB(
|
|||
glm::vec3 coord(icoord);
|
||||
if (block->rotatable) {
|
||||
auto& rotations = block->rotations;
|
||||
auto& orient = rotations.variants[rotation];
|
||||
auto& orient = rotations.variants[states.rotation];
|
||||
X = orient.axes[0];
|
||||
Y = orient.axes[1];
|
||||
Z = orient.axes[2];
|
||||
|
|
@ -537,7 +538,7 @@ void BlocksRenderer::render(
|
|||
}
|
||||
case BlockModelType::AABB: {
|
||||
if (!denseRender)
|
||||
blockAABB({x, y, z}, texfaces, &def, vox.state.rotation,
|
||||
blockAABB({x, y, z}, texfaces, &def, vox.state,
|
||||
!def.shadeless, def.ambientOcclusion && enableAO);
|
||||
break;
|
||||
}
|
||||
|
|
@ -609,7 +610,7 @@ SortingMeshData BlocksRenderer::renderTranslucent(
|
|||
{x, y, z},
|
||||
texfaces,
|
||||
&def,
|
||||
vox.state.rotation,
|
||||
vox.state,
|
||||
!def.shadeless,
|
||||
def.ambientOcclusion && enableAO
|
||||
);
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ private:
|
|||
const glm::ivec3& coord,
|
||||
const UVRegion(&faces)[6],
|
||||
const Block* block,
|
||||
ubyte rotation,
|
||||
blockstate states,
|
||||
bool lights,
|
||||
bool ambientOcclusion
|
||||
);
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ model::Model ModelsGenerator::generate(
|
|||
mesh.shading = !blockDef.shadeless;
|
||||
switch (blockModel.type) {
|
||||
case BlockModelType::AABB: {
|
||||
glm::vec3 size = blockDef.hitboxes.at(0).size();
|
||||
glm::vec3 size = variant.hitboxes.at(0).size();
|
||||
float m = glm::max(size.x, glm::max(size.y, size.z));
|
||||
m = glm::min(1.0f, m);
|
||||
mesh.scale(size / m);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
#include "voxels/Block.hpp"
|
||||
#include "voxels/Chunk.hpp"
|
||||
#include "voxels/Chunks.hpp"
|
||||
#include "voxels/blocks_agent.hpp"
|
||||
#include "voxels/Pathfinding.hpp"
|
||||
#include "window/Window.hpp"
|
||||
#include "world/Level.hpp"
|
||||
|
|
@ -322,9 +323,9 @@ void WorldRenderer::renderBlockSelection() {
|
|||
const glm::vec3 point = selection.hitPosition;
|
||||
const glm::vec3 norm = selection.normal;
|
||||
|
||||
const std::vector<AABB>& hitboxes =
|
||||
block.rotatable ? block.rt.hitboxes[selection.vox.state.rotation]
|
||||
: block.hitboxes;
|
||||
const auto& hitboxes = block.getHitboxes(
|
||||
blocks_agent::hitbox_state(*player.chunks, pos, selection.vox.state)
|
||||
);
|
||||
|
||||
lineBatch->lineWidth(2.0f);
|
||||
for (auto& hitbox : hitboxes) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue