mirror of
https://github.com/JannisX11/blockbench.git
synced 2025-01-18 15:26:19 +08:00
Make "Resolve" apply group rotation to children
Fix Undo issue with editing groups Fix undo label for rotating selection with gizmo
This commit is contained in:
parent
72f9c2d493
commit
db2f1e47cd
@ -220,12 +220,55 @@ class Group extends OutlinerElement {
|
||||
resolve() {
|
||||
var array = this.children.slice();
|
||||
var index = this.getParentArray().indexOf(this)
|
||||
|
||||
array.forEach((s, i) => {
|
||||
s.addTo(this.parent, index)
|
||||
let all_elements = [];
|
||||
this.forEachChild(obj => {
|
||||
if (obj instanceof Group == false) {
|
||||
all_elements.push(obj);
|
||||
}
|
||||
})
|
||||
TickUpdates.outliner = true;
|
||||
|
||||
Undo.initEdit({outliner: true, elements: all_elements})
|
||||
|
||||
array.forEach((obj, i) => {
|
||||
obj.addTo(this.parent, index)
|
||||
|
||||
if ((obj instanceof Cube && Format.rotate_cubes) || (obj instanceof Group && Format.bone_rig)) {
|
||||
let quat = new THREE.Quaternion().copy(obj.mesh.quaternion);
|
||||
quat.premultiply(obj.mesh.parent.quaternion);
|
||||
let e = new THREE.Euler().setFromQuaternion(quat, obj.mesh.rotation.order);
|
||||
obj.extend({
|
||||
rotation: [
|
||||
Math.roundTo(Math.radToDeg(e.x), 4),
|
||||
Math.roundTo(Math.radToDeg(e.y), 4),
|
||||
Math.roundTo(Math.radToDeg(e.z), 4),
|
||||
]
|
||||
})
|
||||
}
|
||||
if (obj.mesh) {
|
||||
let pos = new THREE.Vector3().copy(obj.mesh.position);
|
||||
pos.applyQuaternion(this.mesh.quaternion).sub(obj.mesh.position);
|
||||
let diff = pos.toArray();
|
||||
|
||||
if (obj.movable) obj.from.V3_add(diff);
|
||||
if (obj.resizable) obj.to.V3_add(diff);
|
||||
if (obj.rotatable || obj instanceof Group) obj.origin.V3_add(diff);
|
||||
|
||||
if (obj instanceof Group) {
|
||||
obj.forEachChild(child => {
|
||||
if (child.movable) child.from.V3_add(diff);
|
||||
if (child.resizable) child.to.V3_add(diff);
|
||||
if (obj.rotatable || obj instanceof Group) child.origin.V3_add(diff);
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
Canvas.updateAllPositions();
|
||||
if (Format.bone_rig) {
|
||||
Canvas.updateAllBones();
|
||||
}
|
||||
this.remove(false);
|
||||
Undo.finishEdit('resolve group')
|
||||
TickUpdates.outliner = true;
|
||||
return array;
|
||||
}
|
||||
showContextMenu(event) {
|
||||
@ -414,11 +457,7 @@ class Group extends OutlinerElement {
|
||||
'add_locator',
|
||||
'rename',
|
||||
{icon: 'sort_by_alpha', name: 'menu.group.sort', condition: {modes: ['edit']}, click: function(group) {group.sortContent()}},
|
||||
{icon: 'fa-leaf', name: 'menu.group.resolve', condition: {modes: ['edit']}, click: function(group) {
|
||||
Undo.initEdit({outliner: true})
|
||||
group.resolve()
|
||||
Undo.finishEdit('group resolve')
|
||||
}},
|
||||
{icon: 'fa-leaf', name: 'menu.group.resolve', condition: {modes: ['edit']}, click: function(group) {group.resolve()}},
|
||||
'delete'
|
||||
]);
|
||||
Group.selected;
|
||||
|
@ -84,11 +84,11 @@ var markerColors = [
|
||||
class OutlinerElement {
|
||||
constructor(uuid) {
|
||||
this.uuid = uuid || guid()
|
||||
OutlinerElement.uuids[this.uuid] = this;
|
||||
this.export = true;
|
||||
this.locked = false;
|
||||
}
|
||||
init() {
|
||||
OutlinerElement.uuids[this.uuid] = this;
|
||||
this.constructor.all.safePush(this);
|
||||
return this;
|
||||
}
|
||||
@ -212,7 +212,7 @@ class OutlinerElement {
|
||||
}
|
||||
remove() {
|
||||
this.constructor.all.remove(this);
|
||||
delete OutlinerElement.uuids[this.uuid];
|
||||
if (OutlinerElement.uuids[this.uuid] == this) delete OutlinerElement.uuids[this.uuid];
|
||||
this.removeFromParent()
|
||||
}
|
||||
rename() {
|
||||
|
@ -1515,8 +1515,10 @@
|
||||
|
||||
if (Toolbox.selected.id == 'pivot_tool') {
|
||||
Undo.finishEdit('move pivot')
|
||||
} else if (Toolbox.selected.id == 'rotate_tool') {
|
||||
Undo.finishEdit('rotate selection')
|
||||
} else {
|
||||
Undo.finishEdit('move elements')
|
||||
Undo.finishEdit('move selection')
|
||||
}
|
||||
}
|
||||
updateSelection()
|
||||
|
@ -301,10 +301,8 @@ var Undo = {
|
||||
group.extend(save.group)
|
||||
if (Format.bone_rig) {
|
||||
group.forEachChild(function(obj) {
|
||||
if (obj.type === 'cube') {
|
||||
Canvas.adaptObjectPosition(obj)
|
||||
}
|
||||
})
|
||||
Canvas.adaptObjectPosition(obj)
|
||||
}, Cube)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user