Merge pull request #937 from MihailRis/fix

fixes
This commit is contained in:
MihailRis 2026-08-18 00:11:23 +03:00 • committed by GitHub
commit 4111da1230
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 118 additions and 30 deletions

View file

@ -192,12 +192,12 @@ An array of 6 numbers describing an offset an size of a block hitbox.
The numbers are specified in the range [0.0, 1.0] - i.e. within the block (in the case of an extended block, the hitbox can be larger than one, but must not go beyond the "size" property). The numbers are specified in the range [0.0, 1.0] - i.e. within the block (in the case of an extended block, the hitbox can be larger than one, but must not go beyond the "size" property).
Array *\[0.25, 0.0, 0.5, 0.75, 0.4, 0.3\]* describes hitbox width: Array *\[0.25, 0.0, 0.5, 0.75, 0.4, 0.3\]* describes hitbox width:
- offset 0.25m east - offset 0.25m west
- offset 0.0m up - offset 0.0m up
- offset 0.5m north - offset 0.5m south
- 0.75m width (from east to west) - 0.75m width (from west to east)
- 0.4m height - 0.4m height
- 0.3m length (from south to north) - 0.3m length (from north to south)
For composite hitboxes, the *hitboxes* property is used - an array of hitboxes, for example: For composite hitboxes, the *hitboxes* property is used - an array of hitboxes, for example:

View file

@ -194,12 +194,12 @@
Числа указываются в диапазоне [0.0, 1.0] - т.е в пределах блока (в случае расширенного блока хитбокс может быть больше единицы, но не должен выходить за пределы size). Числа указываются в диапазоне [0.0, 1.0] - т.е в пределах блока (в случае расширенного блока хитбокс может быть больше единицы, но не должен выходить за пределы size).
Массив `[0.25, 0.0, 0.5, 0.75, 0.4, 0.3]` описывает хитбокс: Массив `[0.25, 0.0, 0.5, 0.75, 0.4, 0.3]` описывает хитбокс:
- смещен на 0.25 м на запад - смещен на 0.25 м на восток
- смещен на 0.0 м вверх - смещен на 0.0 м вверх
- смещен на 0.5 м на север - смещен на 0.5 м на юг
- шириной (с востока на запад) 0.75 м - шириной (с запада на восток) 0.75 м
- высотой 0.4 м - высотой 0.4 м
- длиной (с юга на север) 0.3 м - длиной (с севера на юг) 0.3 м
Для составных хитбоксов используется свойство *hitboxes* - массив хитбоксов, например: Для составных хитбоксов используется свойство *hitboxes* - массив хитбоксов, например:

View file

@ -17,7 +17,7 @@
color="#FFFFFF80" size="16" pos="4,6" color="#FFFFFF80" size="16" pos="4,6"
hover-color="#1080FF"></image> hover-color="#1080FF"></image>
<panel orientation="horizontal" gravity="top-right" <panel orientation="horizontal" gravity="top-right"
size="76,24" padding="8" interval="8" color="0"> size="76,24" padding="8,6,8,2" interval="8" color="0">
<image id="saveIcon" src="gui/save" tooltip="@Save" <image id="saveIcon" src="gui/save" tooltip="@Save"
enabled="false" interactive="true" enabled="false" interactive="true"
hover-color="#1080FF" hover-color="#1080FF"
@ -31,6 +31,12 @@
hover-color="#1080FF" hover-color="#1080FF"
onclick="run_current_file()" onclick="run_current_file()"
color="#FFFFFF80" size="16"></image> color="#FFFFFF80" size="16"></image>
<!-- TODO: remove after 0.32-->
<image src="gui/item" size="16"
enabled="true" interactive="true"
hover-color="#1080FF"
tooltip="Fix old VCM regions (0.31 bug)"
onclick="fix_vcm_regions()"></image>
</panel> </panel>
<label id="title" pos="26,8"></label> <label id="title" pos="26,8"></label>
</container> </container>

View file

@ -113,6 +113,78 @@ local function reload_model(filename, name)
assets.parse_model(file.ext(filename), document.editor.text, name) assets.parse_model(file.ext(filename), document.editor.text, name)
end end
-- === TODO: remove after 0.32 ===
local pattern =
"region %(%s*"
.. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*"
.. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*"
.. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)%s*,%s*"
.. "([+-]?%d+%.?%d*[eE]?[+-]?%d*)"
.. "%s*%)"
local function replace1(x1, y1, x2, y2)
return string.format("region (%s, %s, %s, %s)", x2, y2, x1, y1)
end
local function replace2(x1, y1, x2, y2)
return string.format("region (%s, %s, %s, %s)", x2, y1, x1, y2)
end
function convert_vcm(text)
local lines = {}
local zpairs = {
{"%(north%)", "%(south%)", "(TMPS)", "(TMPN)"},
{"%,north", "%,south", ",TMPS", ",TMPN"},
{"north%,", "south%,", "TMPS,", "TMPN,"},
}
local xpairs = {
{"%(west%)", "%(east%)", "(TMPE)", "(TMPW)"},
{"%,west", "%,east", ",TMPE", ",TMPW"},
{"west%,", "east%,", "TMPE,", "TMPW,"},
}
for i, pair in ipairs(zpairs) do
text = text:gsub(pair[1], pair[3])
text = text:gsub(pair[2], pair[4])
end
text = text:gsub("TMPS", "south")
text = text:gsub("TMPN", "north")
for i, pair in ipairs(xpairs) do
text = text:gsub(pair[1], pair[3])
text = text:gsub(pair[2], pair[4])
end
text = text:gsub("TMPW", "west")
text = text:gsub("TMPE", "east")
for line in text:gmatch("[^\n]*\n?") do
if line == "" then
break
end
if line:find("(top)", 1, true) then
line = line:gsub(pattern, replace1)
end
if line:find("(bottom)", 1, true)
or line:find("(east)", 1, true) then
line = line:gsub(pattern, replace2)
end
table.insert(lines, line)
end
return table.concat(lines)
end
function fix_vcm_regions()
if not current_file.filename then
return
end
document.editor.text = convert_vcm(document.editor.text)
end
-- ===============================
function run_current_file() function run_current_file()
if not current_file.filename then if not current_file.filename then
return return

View file

@ -1,4 +1,4 @@
@box from (0,0,0) to (1,0.5,1) delete (top,south) @box from (0,0,0) to (1,0.5,1) delete (top,north)
@box from (0,0.5,0) to (1,1,0.5) delete (bottom,south) @box from (0,0.5,0) to (1,1,0.5) delete (bottom,north)
@rect from (0,0.5,0.5) right (1,0,0) up (0,0,0.5) texture "$2" @rect from (0,0.5,0.5) right (1,0,0) up (0,0,0.5) texture "$2"
@rect from (0,0,0) right (1,0,0) up (0,1,0) texture "$1" @rect from (0,0,0) right (1,0,0) up (0,1,0) texture "$1"

View file

@ -55,12 +55,12 @@ model::Model VcmModel::squashed() const {
} }
static const std::unordered_map<std::string, int> side_indices { static const std::unordered_map<std::string, int> side_indices {
{"east", 0}, {"west", 0}, // -X
{"west", 1}, {"east", 1}, // +X
{"bottom", 2}, {"bottom", 2}, // -Y
{"top", 3}, {"top", 3}, // +Y
{"south", 4}, {"north", 4}, // -Z
{"north", 5}, {"south", 5}, // +Z
}; };
static bool to_boolean(const xml::Attribute& attr) { static bool to_boolean(const xml::Attribute& attr) {
@ -267,12 +267,12 @@ static void perform_box(const xmlelement& root, ModelBuilder& builder) {
} }
UVRegion regions[6] {}; UVRegion regions[6] {};
regions[0].scale(to.x - from.x, to.y - from.y); regions[0].scale(to.z - from.z, to.y - from.y);
regions[1].scale(from.x - to.x, to.y - from.y); regions[1].scale(from.z - to.z, to.y - from.y);
regions[2].scale(to.x - from.x, to.z - from.z); regions[2].scale(to.x - from.x, to.z - from.z);
regions[3].scale(from.x - to.x, to.z - from.z); regions[3].scale(from.x - to.x, to.z - from.z);
regions[4].scale(to.z - from.z, to.y - from.y); regions[4].scale(to.x - from.x, to.y - from.y);
regions[5].scale(from.z - to.z, to.y - from.y); regions[5].scale(from.x - to.x, to.y - from.y);
auto center = (from + to) * 0.5f; auto center = (from + to) * 0.5f;
auto halfsize = (to - from) * 0.5f; auto halfsize = (to - from) * 0.5f;
@ -306,7 +306,11 @@ static void perform_box(const xmlelement& root, ModelBuilder& builder) {
texfaces[idx] = elem->attr("texture").getText(); texfaces[idx] = elem->attr("texture").getText();
} }
if (elem->has("region")) { if (elem->has("region")) {
regions[idx].set(elem->attr("region").asVec4()); auto region = elem->attr("region").asVec4();
if (idx % 2 == 1) {
std::swap(region[0], region[2]);
}
regions[idx].set(region);
} }
if (elem->has("region-scale")) { if (elem->has("region-scale")) {
regions[idx].scale(elem->attr("region-scale").asVec2()); regions[idx].scale(elem->attr("region-scale").asVec2());

View file

@ -39,16 +39,18 @@ std::unique_ptr<Content> ContentBuilder::build() {
} else { } else {
def.defaults.rt.solid = isSolid(def.defaults) || def.explictlySolid; def.defaults.rt.solid = isSolid(def.defaults) || def.explictlySolid;
} }
if (def.material.empty()) { def.rt.solid = def.defaults.rt.solid;
defaults.at("block-material").get(def.material);
}
const float EPSILON = 0.01f; const float EPSILON = 0.01f;
def.rt.solid = def.rt.solid = def.rt.solid &&
def.obstacle && def.obstacle &&
(glm::i8vec3(def.hitboxes[0].size() + EPSILON) == def.size); (glm::i8vec3(def.hitboxes[0].size() + EPSILON) == def.size);
def.rt.extended = def.size.x > 1 || def.size.y > 1 || def.size.z > 1; def.rt.extended = def.size.x > 1 || def.size.y > 1 || def.size.z > 1;
if (def.material.empty()) {
defaults.at("block-material").get(def.material);
}
if (def.rotatable) { if (def.rotatable) {
for (uint i = 0; i < BlockRotProfile::MAX_COUNT; i++) { for (uint i = 0; i < BlockRotProfile::MAX_COUNT; i++) {
def.rt.hitboxes[i].reserve(def.hitboxes.size()); def.rt.hitboxes[i].reserve(def.hitboxes.size());

View file

@ -48,10 +48,14 @@ void gui::Frame::draw(const DrawContext& pctx, const Assets& assets) {
void gui::Frame::updateOutput(Assets& assets) { void gui::Frame::updateOutput(Assets& assets) {
if (fbo && (fbo->getWidth() != size.x || fbo->getHeight() != size.y)) { if (fbo && (fbo->getWidth() != size.x || fbo->getHeight() != size.y)) {
fbo->resize(size.x, size.y); fbo->resize(size.x, size.y);
assets.store(fbo->getSharedTexture(), outputTexture); if (!outputTexture.empty()) {
assets.store(fbo->getSharedTexture(), outputTexture);
}
} else if (fbo == nullptr) { } else if (fbo == nullptr) {
fbo = std::make_unique<Framebuffer>(size.x, size.y, true); fbo = std::make_unique<Framebuffer>(size.x, size.y, true);
assets.store(fbo->getSharedTexture(), outputTexture); if (!outputTexture.empty()) {
assets.store(fbo->getSharedTexture(), outputTexture);
}
} }
} }

View file

@ -83,12 +83,12 @@ static util::TextureRegion determine_texture_region(
const Assets& assets, const std::string& texture const Assets& assets, const std::string& texture
) { ) {
static std::array<std::string, 6> faces { static std::array<std::string, 6> faces {
"blocks:dbg_east",
"blocks:dbg_west", "blocks:dbg_west",
"blocks:dbg_east",
"blocks:dbg_bottom", "blocks:dbg_bottom",
"blocks:dbg_top", "blocks:dbg_top",
"blocks:dbg_south",
"blocks:dbg_north", "blocks:dbg_north",
"blocks:dbg_south",
}; };
if (texture.length() < 2 || texture.at(0) != '$') { if (texture.length() < 2 || texture.at(0) != '$') {