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

View File

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

View File

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