Merge pull request #524 from MihailRis/stairs-rotation-profile
Stairs rotation profile
This commit is contained in:
commit
43c76c92ff
@ -122,6 +122,8 @@ template<> void ContentUnitLoader<Block>::loadUnit(
|
|||||||
def.rotations = BlockRotProfile::PIPE;
|
def.rotations = BlockRotProfile::PIPE;
|
||||||
} else if (profile == BlockRotProfile::PANE_NAME) {
|
} else if (profile == BlockRotProfile::PANE_NAME) {
|
||||||
def.rotations = BlockRotProfile::PANE;
|
def.rotations = BlockRotProfile::PANE;
|
||||||
|
} else if (profile == BlockRotProfile::STAIRS_NAME) {
|
||||||
|
def.rotations = BlockRotProfile::STAIRS;
|
||||||
} else if (profile != "none") {
|
} else if (profile != "none") {
|
||||||
logger.error() << "unknown rotation profile " << profile;
|
logger.error() << "unknown rotation profile " << profile;
|
||||||
def.rotatable = false;
|
def.rotatable = false;
|
||||||
|
|||||||
@ -308,7 +308,14 @@ void BlocksRenderer::blockCustomModel(
|
|||||||
const auto& v0 = mesh.vertices[triangle * 3];
|
const auto& v0 = mesh.vertices[triangle * 3];
|
||||||
auto n = v0.normal.x * X + v0.normal.y * Y + v0.normal.z * Z;
|
auto n = v0.normal.x * X + v0.normal.y * Y + v0.normal.z * Z;
|
||||||
|
|
||||||
if (!isOpen(glm::floor(coord + n * 1e-4f), *block) && is_aligned(n)) {
|
auto vp = (mesh.vertices[triangle * 3].coord +
|
||||||
|
mesh.vertices[triangle * 3 + 1].coord +
|
||||||
|
mesh.vertices[triangle * 3 + 2].coord) *
|
||||||
|
0.3333f -
|
||||||
|
0.5f;
|
||||||
|
vp = vp.x * X + vp.y * Y + vp.z * Z;
|
||||||
|
|
||||||
|
if (!isOpen(glm::floor(coord + vp + 0.5f + n * 1e-3f), *block) && is_aligned(n)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -336,14 +336,15 @@ static int determine_rotation(
|
|||||||
if (norm.y < 0.0f) return BLOCK_DIR_DOWN;
|
if (norm.y < 0.0f) return BLOCK_DIR_DOWN;
|
||||||
if (norm.z > 0.0f) return BLOCK_DIR_NORTH;
|
if (norm.z > 0.0f) return BLOCK_DIR_NORTH;
|
||||||
if (norm.z < 0.0f) return BLOCK_DIR_SOUTH;
|
if (norm.z < 0.0f) return BLOCK_DIR_SOUTH;
|
||||||
} else if (name == "pane") {
|
} else if (name == "pane" || name == "stairs") {
|
||||||
|
int verticalBit = (name == "stairs" && (norm.y - camDir.y * 0.5f) < 0.0) ? 4 : 0;
|
||||||
if (abs(camDir.x) > abs(camDir.z)) {
|
if (abs(camDir.x) > abs(camDir.z)) {
|
||||||
if (camDir.x > 0.0f) return BLOCK_DIR_EAST;
|
if (camDir.x > 0.0f) return BLOCK_DIR_EAST | verticalBit;
|
||||||
if (camDir.x < 0.0f) return BLOCK_DIR_WEST;
|
if (camDir.x < 0.0f) return BLOCK_DIR_WEST | verticalBit;
|
||||||
}
|
}
|
||||||
if (abs(camDir.x) < abs(camDir.z)) {
|
if (abs(camDir.x) < abs(camDir.z)) {
|
||||||
if (camDir.z > 0.0f) return BLOCK_DIR_SOUTH;
|
if (camDir.z > 0.0f) return BLOCK_DIR_SOUTH | verticalBit;
|
||||||
if (camDir.z < 0.0f) return BLOCK_DIR_NORTH;
|
if (camDir.z < 0.0f) return BLOCK_DIR_NORTH | verticalBit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -421,7 +422,7 @@ void PlayerController::processRightClick(
|
|||||||
auto camera = player.fpCamera.get();
|
auto camera = player.fpCamera.get();
|
||||||
|
|
||||||
blockstate state {};
|
blockstate state {};
|
||||||
state.rotation = determine_rotation(&def, selection.normal, camera->dir);
|
state.rotation = determine_rotation(&def, selection.normal, camera->front);
|
||||||
|
|
||||||
if (!input.shift && target.rt.funcsset.oninteract) {
|
if (!input.shift && target.rt.funcsset.oninteract) {
|
||||||
if (scripting::on_block_interact(
|
if (scripting::on_block_interact(
|
||||||
|
|||||||
@ -91,6 +91,22 @@ const BlockRotProfile BlockRotProfile::PANE {
|
|||||||
4
|
4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const BlockRotProfile BlockRotProfile::STAIRS {
|
||||||
|
"stairs",
|
||||||
|
{
|
||||||
|
{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // North
|
||||||
|
{{0, 0, -1}, {0, 1, 0}, {1, 0, 0}}, // East
|
||||||
|
{{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, // South
|
||||||
|
{{0, 0, 1}, {0, 1, 0}, {-1, 0, 0}}, // West
|
||||||
|
|
||||||
|
{{-1, 0, 0}, {0, -1, 0}, {0, 0, 1}},
|
||||||
|
{{0, 0, 1}, {0, -1, 0}, {1, 0, 0}},
|
||||||
|
{{1, 0, 0}, {0, -1, 0}, {0, 0, -1}},
|
||||||
|
{{0, 0, -1}, {0, -1, 0}, {-1, 0, 0}},
|
||||||
|
},
|
||||||
|
8
|
||||||
|
};
|
||||||
|
|
||||||
Block::Block(const std::string& name)
|
Block::Block(const std::string& name)
|
||||||
: name(name),
|
: name(name),
|
||||||
caption(util::id_to_caption(name)),
|
caption(util::id_to_caption(name)),
|
||||||
|
|||||||
@ -77,8 +77,12 @@ struct BlockRotProfile {
|
|||||||
/// @brief Doors, signs and other panes
|
/// @brief Doors, signs and other panes
|
||||||
static const BlockRotProfile PANE;
|
static const BlockRotProfile PANE;
|
||||||
|
|
||||||
|
/// @brief Stairs, stairs and stairs
|
||||||
|
static const BlockRotProfile STAIRS;
|
||||||
|
|
||||||
static inline std::string PIPE_NAME = "pipe";
|
static inline std::string PIPE_NAME = "pipe";
|
||||||
static inline std::string PANE_NAME = "pane";
|
static inline std::string PANE_NAME = "pane";
|
||||||
|
static inline std::string STAIRS_NAME = "stairs";
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class BlockModelType {
|
enum class BlockModelType {
|
||||||
|
|||||||
@ -209,10 +209,13 @@ std::unique_ptr<VoxelFragment> VoxelFragment::rotated(const Content& content) co
|
|||||||
| ((voxel.state.segment & 0b100) >> 2);
|
| ((voxel.state.segment & 0b100) >> 2);
|
||||||
auto& def = content.blocks.require(blockNames[voxel.id]);
|
auto& def = content.blocks.require(blockNames[voxel.id]);
|
||||||
if (def.rotations.name == BlockRotProfile::PANE_NAME ||
|
if (def.rotations.name == BlockRotProfile::PANE_NAME ||
|
||||||
def.rotations.name == BlockRotProfile::PIPE_NAME){
|
def.rotations.name == BlockRotProfile::PIPE_NAME) {
|
||||||
if (voxel.state.rotation < 4) {
|
if (voxel.state.rotation < 4) {
|
||||||
voxel.state.rotation = (voxel.state.rotation + 3) & 0b11;
|
voxel.state.rotation = (voxel.state.rotation + 3) & 0b11;
|
||||||
}
|
}
|
||||||
|
} else if (def.rotations.name == BlockRotProfile::STAIRS_NAME) {
|
||||||
|
voxel.state.rotation = ((voxel.state.rotation + 3) & 0b11) |
|
||||||
|
(voxel.state.rotation & 0b100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user