Fix shape tool issues:

Fix #1620 Incorrect numbers in status bar when using shape tool
Fix fading corners on hollow rectangles
Fix visual errors after flipping groups
This commit is contained in:
JannisX11 2022-10-29 18:21:20 +02:00
parent 7a3f948a3d
commit 3b7466962f
3 changed files with 24 additions and 26 deletions

View File

@ -176,34 +176,32 @@ function mirrorSelected(axis) {
}
if (Group.selected && Group.selected.matchesSelection()) {
function flipGroup(group) {
if (group.type === 'group') {
for (var i = 0; i < 3; i++) {
if (i === axis) {
group.origin[i] *= -1
} else {
group.rotation[i] *= -1
}
for (var i = 0; i < 3; i++) {
if (i === axis) {
group.origin[i] *= -1
} else {
group.rotation[i] *= -1
}
function matchAndReplace(a, b) {
if (group.name.includes(a)) {
let name = group._original_name
? group._original_name.replace(a, b)
: group.name.replace(a, b).replace(/2/, '');
if (!Group.all.find(g => g.name == name)) group.name = name;
return true;
}
}
let pairs = flip_pairs[axis];
for (let a in pairs) {
let b = pairs[a];
if (matchAndReplace(a, b)) break;
if (matchAndReplace(b, a)) break;
}
function matchAndReplace(a, b) {
if (group.name.includes(a)) {
let name = group._original_name
? group._original_name.replace(a, b)
: group.name.replace(a, b).replace(/2/, '');
if (!Group.all.find(g => g.name == name)) group.name = name;
return true;
}
}
let pairs = flip_pairs[axis];
for (let a in pairs) {
let b = pairs[a];
if (matchAndReplace(a, b)) break;
if (matchAndReplace(b, a)) break;
}
Canvas.updateAllBones([group]);
}
flipGroup(Group.selected)
Group.selected.forEachChild(flipGroup)
Group.selected.forEachChild(flipGroup, Group)
}
}
selected.forEach(function(obj) {

View File

@ -954,7 +954,7 @@ const Canvas = {
if (Project) Project.model_3d.scale.set(1, 1, 1);
bones.forEach((obj) => {
let bone = obj.mesh
if (bone) {
if (bone && obj instanceof Group) {
bone.rotation.order = 'ZYX';
bone.rotation.setFromDegreeArray(obj.rotation);

View File

@ -881,7 +881,7 @@ const Painter = {
ctx.beginPath();
var rect = getRectangle(start_x, start_y, start_x+diff_x, start_y+diff_y);
if (hollow) {
if (hollow && rect.w > 0 && rect.h > 0) {
ctx.rect(rect.ax+(width%2 ? 0.5 : 1), rect.ay+(width%2 ? 0.5 : 1), rect.x, rect.y);
ctx.stroke();
} else {
@ -969,9 +969,9 @@ const Painter = {
}
if (shape === 'ellipse') {
Blockbench.setStatusBarText(`${diff_x*2 + 1} x ${diff_y*2 + 1}`);
Blockbench.setStatusBarText(`${Math.abs(diff_x*2) + 1} x ${Math.abs(diff_y*2) + 1}`);
} else {
Blockbench.setStatusBarText(`${diff_x + 1} x ${diff_y + 1}`);
Blockbench.setStatusBarText(`${Math.abs(diff_x) + 1} x ${Math.abs(diff_y) + 1}`);
}
}