mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-03-07 16:47:50 +08:00
Change selection center calculation behavior
Fix animated texture frame slider only affecting selected texture Make animated texture frame slider loop animation
This commit is contained in:
parent
9cdab6bab1
commit
31cb4535ea
js
@ -1616,11 +1616,15 @@ BARS.defineActions(function() {
|
|||||||
return tex ? tex.currentFrame+1 : 0;
|
return tex ? tex.currentFrame+1 : 0;
|
||||||
},
|
},
|
||||||
change: function(modify) {
|
change: function(modify) {
|
||||||
let tex = getSliderTexture()
|
let slider_tex = getSliderTexture()
|
||||||
if (tex) {
|
if (!slider_tex) return;
|
||||||
tex.currentFrame = Math.clamp(modify(tex.currentFrame+1), 1, tex.frameCount) - 1;
|
slider_tex.currentFrame = (modify(slider_tex.currentFrame + slider_tex.frameCount) % slider_tex.frameCount);
|
||||||
TextureAnimator.update([tex]);
|
|
||||||
}
|
let textures = Texture.all.filter(tex => tex.frameCount > 1);
|
||||||
|
Texture.all.forEach(tex => {
|
||||||
|
tex.currentFrame = slider_tex.currentFrame % tex.frameCount;
|
||||||
|
})
|
||||||
|
TextureAnimator.update(textures);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -56,22 +56,20 @@ function getSelectionCenter(all = false) {
|
|||||||
let vec = THREE.fastWorldPosition(Group.selected.mesh, new THREE.Vector3());
|
let vec = THREE.fastWorldPosition(Group.selected.mesh, new THREE.Vector3());
|
||||||
return vec.toArray();
|
return vec.toArray();
|
||||||
}
|
}
|
||||||
var center = [0, 0, 0]
|
|
||||||
var i = 0;
|
let max = [-Infinity, -Infinity, -Infinity];
|
||||||
let items = (selected.length == 0 || all) ? elements : selected;
|
let min = [ Infinity, Infinity, Infinity];
|
||||||
items.forEach(obj => {
|
let elements = Outliner.selected.length ? Outliner.selected : Outliner.elements;
|
||||||
if (obj.getWorldCenter) {
|
elements.forEach(element => {
|
||||||
var pos = obj.getWorldCenter();
|
if (element.getWorldCenter) {
|
||||||
center[0] += pos.x
|
var pos = element.getWorldCenter();
|
||||||
center[1] += pos.y
|
min[0] = Math.min(pos.x, min[0]); max[0] = Math.max(pos.x, max[0]);
|
||||||
center[2] += pos.z
|
min[1] = Math.min(pos.y, min[1]); max[1] = Math.max(pos.y, max[1]);
|
||||||
|
min[2] = Math.min(pos.z, min[2]); max[2] = Math.max(pos.z, max[2]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (items.length) {
|
let center = max.V3_add(min).V3_divide(2);
|
||||||
for (var i = 0; i < 3; i++) {
|
|
||||||
center[i] = center[i] / items.length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!Format.centered_grid) {
|
if (!Format.centered_grid) {
|
||||||
center.V3_add(8, 8, 8)
|
center.V3_add(8, 8, 8)
|
||||||
}
|
}
|
||||||
@ -598,7 +596,6 @@ function centerElementsAll(axis) {
|
|||||||
centerElements(0, false)
|
centerElements(0, false)
|
||||||
centerElements(1, false)
|
centerElements(1, false)
|
||||||
centerElements(2, false)
|
centerElements(2, false)
|
||||||
Canvas.updatePositions()
|
|
||||||
}
|
}
|
||||||
function centerElements(axis, update) {
|
function centerElements(axis, update) {
|
||||||
if (!Outliner.selected.length) return;
|
if (!Outliner.selected.length) return;
|
||||||
@ -610,10 +607,17 @@ function centerElements(axis, update) {
|
|||||||
if (obj.to) obj.to[axis] = limitToBox(obj.to[axis] + difference, obj.inflate);
|
if (obj.to) obj.to[axis] = limitToBox(obj.to[axis] + difference, obj.inflate);
|
||||||
if (obj instanceof Cube) obj.from[axis] = limitToBox(obj.from[axis] + difference, obj.inflate);
|
if (obj instanceof Cube) obj.from[axis] = limitToBox(obj.from[axis] + difference, obj.inflate);
|
||||||
})
|
})
|
||||||
|
Group.all.forEach(group => {
|
||||||
if (update !== false) {
|
if (!group.selected) return;
|
||||||
Canvas.updatePositions()
|
group.origin[axis] += difference;
|
||||||
}
|
})
|
||||||
|
Canvas.updateView({
|
||||||
|
elements: Outliner.selected,
|
||||||
|
groups: Group.all.filter(g => g.selected),
|
||||||
|
element_aspects: {transform: true},
|
||||||
|
group_aspects: {transform: true},
|
||||||
|
selection: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//Move
|
//Move
|
||||||
@ -1549,7 +1553,7 @@ BARS.defineActions(function() {
|
|||||||
color: 'x',
|
color: 'x',
|
||||||
category: 'transform',
|
category: 'transform',
|
||||||
click: function () {
|
click: function () {
|
||||||
Undo.initEdit({elements: selected});
|
Undo.initEdit({elements: Outliner.selected, outliner: true});
|
||||||
centerElements(0);
|
centerElements(0);
|
||||||
Undo.finishEdit('Center selection on X axis')
|
Undo.finishEdit('Center selection on X axis')
|
||||||
}
|
}
|
||||||
@ -1560,7 +1564,7 @@ BARS.defineActions(function() {
|
|||||||
color: 'y',
|
color: 'y',
|
||||||
category: 'transform',
|
category: 'transform',
|
||||||
click: function () {
|
click: function () {
|
||||||
Undo.initEdit({elements: selected});
|
Undo.initEdit({elements: Outliner.selected, outliner: true});
|
||||||
centerElements(1);
|
centerElements(1);
|
||||||
Undo.finishEdit('Center selection on Y axis')
|
Undo.finishEdit('Center selection on Y axis')
|
||||||
}
|
}
|
||||||
@ -1571,7 +1575,7 @@ BARS.defineActions(function() {
|
|||||||
color: 'z',
|
color: 'z',
|
||||||
category: 'transform',
|
category: 'transform',
|
||||||
click: function () {
|
click: function () {
|
||||||
Undo.initEdit({elements: selected});
|
Undo.initEdit({elements: Outliner.selected, outliner: true});
|
||||||
centerElements(2);
|
centerElements(2);
|
||||||
Undo.finishEdit('Center selection on Z axis')
|
Undo.finishEdit('Center selection on Z axis')
|
||||||
}
|
}
|
||||||
@ -1580,7 +1584,7 @@ BARS.defineActions(function() {
|
|||||||
icon: 'filter_center_focus',
|
icon: 'filter_center_focus',
|
||||||
category: 'transform',
|
category: 'transform',
|
||||||
click: function () {
|
click: function () {
|
||||||
Undo.initEdit({elements: selected});
|
Undo.initEdit({elements: Outliner.selected, outliner: true});
|
||||||
centerElementsAll();
|
centerElementsAll();
|
||||||
Undo.finishEdit('Center selection')
|
Undo.finishEdit('Center selection')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user