blockbench/js/transform.js

1043 lines
25 KiB
JavaScript
Raw Normal View History

2018-03-29 02:48:11 +08:00
//Actions
function origin2geometry() {
2019-02-04 04:09:35 +08:00
2018-10-18 01:50:25 +08:00
if (Blockbench.entity_mode) {
2019-02-04 04:09:35 +08:00
Undo.initEdit({group: selected_group})
2018-10-18 01:50:25 +08:00
if (!selected_group || selected_group.children.length === 0) return;
var position = [0, 0, 0]
selected_group.children.forEach(function(obj) {
2019-02-04 04:09:35 +08:00
if (obj.type === 'cube') {
position[0] += obj.from[0] + obj.size(0)/2
position[1] += obj.from[1] + obj.size(1)/2
position[2] += obj.from[2] + obj.size(2)/2
}
2018-10-18 01:50:25 +08:00
})
position.forEach(function(p, pi) {
position[pi] = p / selected_group.children.length
})
selected_group.origin = position
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
} else {
2019-02-04 04:09:35 +08:00
Undo.initEdit({cubes: selected})
2018-03-29 02:48:11 +08:00
2019-02-04 04:09:35 +08:00
var center = getSelectionCenter()
selected.forEach(cube => {
cube.transferOrigin(center)
})
}
Canvas.updatePositions()
Undo.finishEdit('origin to geometry')
}
function getSelectionCenter() {
var center = [0, 0, 0]
var i = 0;
selected.forEach(cube => {
var m = cube.mesh
if (cube.visibility && m) {
2018-03-29 02:48:11 +08:00
2019-02-04 04:09:35 +08:00
var pos = cube.getWorldCenter()
center[0] += pos.x
center[1] += pos.y
center[2] += pos.z
2018-04-15 22:06:43 +08:00
}
2019-02-04 04:09:35 +08:00
})
for (var i = 0; i < 3; i++) {
center[i] = center[i] / selected.length
2018-03-29 02:48:11 +08:00
}
2019-02-04 04:09:35 +08:00
return center;
2018-03-29 02:48:11 +08:00
}
2018-10-18 01:50:25 +08:00
function isMovementGlobal() {
2018-10-24 03:49:04 +08:00
if (selected.length === 0 || (!settings.local_move.value && Toolbox.selected.id !== 'resize_tool')) {
2018-10-18 01:50:25 +08:00
return true;
}
if (!Blockbench.entity_mode) {
2018-03-29 02:48:11 +08:00
if (selected.length > 1) {
2018-10-18 01:50:25 +08:00
if (selected[0].rotation.equals([0,0,0])) return true;
2018-03-29 02:48:11 +08:00
var i = 0;
while (i < selected.length) {
2018-10-18 01:50:25 +08:00
if (!selected[0].rotation.equals(selected[i].rotation)) {
return true;
2018-03-29 02:48:11 +08:00
}
i++;
}
}
return false;
} else {
2018-10-18 01:50:25 +08:00
if (selected[0] && selected[0].parent.type === 'group') {
var ref_group = selected[0].parent
var i = 0;
while (i < selected.length) {
var obj = selected[i]
if (
obj.parent.type !== 'group' ||
!obj.parent.rotation.equals(ref_group.rotation)
) {
return true;
}
i++;
}
return false
}
return true;
2018-03-29 02:48:11 +08:00
}
}
//Canvas Restriction
function isInBox(val) {
2018-10-18 01:50:25 +08:00
return (val < 32 && val > -16 || isCanvasRestricted() === false)
2018-03-29 02:48:11 +08:00
}
function isCanvasRestricted() {
2018-10-18 01:50:25 +08:00
return (settings.restricted_canvas.value === true && Blockbench.entity_mode === false)
2018-03-29 02:48:11 +08:00
}
function limitToBox(val) {
2018-10-18 01:50:25 +08:00
if (!isCanvasRestricted()) {
return val;
} else if (val > 32) {
return 32;
} else if (val < -16) {
return -16;
} else {
return val;
}
2018-03-29 02:48:11 +08:00
}
2018-10-18 01:50:25 +08:00
function moveIntoBox(list, value_before) {
if (!list) list = elements
if (list.length === 0) return;
Undo.initEdit({cubes: selected, settings: {restricted_canvas: !!value_before}})
list.forEach(function(s, i) {
//Push elements into 3x3 block box
[0, 1, 2].forEach(function(ax) {
var overlap = s.to[ax] - 32
if (overlap > 0) {
//If positive site overlaps
s.from[ax] -= overlap
s.to[ax] -= overlap
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
overlap = 16 + s.from[ax]
if (overlap < 0) {
s.from[ax] = -16
}
} else {
overlap = s.from[ax] + 16
if (overlap < 0) {
s.from[ax] -= overlap
s.to[ax] -= overlap
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
if (s.to[ax] > 32) {
s.to[ax] = 32
}
}
}
})
Canvas.adaptObjectPosition(s)
})
updateSelection()
Undo.finishEdit('restrict', {cubes: selected, settings: {restricted_canvas: true}})
2018-03-29 02:48:11 +08:00
}
//Movement
2018-12-27 21:03:04 +08:00
function moveCube(obj, val, axis, move_origin) {
2018-10-18 01:50:25 +08:00
//Obj = Direct - val = Total - Axis = Number
val = limitToBox(val)
val = limitToBox(val + obj.size(axis))
var size = obj.size(axis)
var difference = val - obj.to[axis]
2018-10-24 03:49:04 +08:00
2018-12-27 21:03:04 +08:00
//Move
if (Blockbench.globalMovement && Blockbench.entity_mode && !move_origin) {
var m = new THREE.Vector3()
m[getAxisLetter(axis)] = difference
2018-10-24 03:49:04 +08:00
2018-12-27 21:03:04 +08:00
var rotation = new THREE.Quaternion()
2019-01-09 22:54:35 +08:00
obj.mesh.getWorldQuaternion(rotation)
2018-12-27 21:03:04 +08:00
m.applyQuaternion(rotation.inverse())
2018-10-24 03:49:04 +08:00
2018-12-27 21:03:04 +08:00
obj.from[0] += m.x;
obj.from[1] += m.y;
obj.from[2] += m.z;
obj.to[0] += m.x;
obj.to[1] += m.y;
obj.to[2] += m.z;
2018-10-24 03:49:04 +08:00
2018-12-27 21:03:04 +08:00
} else {
obj.to[axis] = val
obj.from[axis] = val - size
}
//Origin
if (Blockbench.globalMovement && !Blockbench.entity_mode) {
obj.origin[axis] += difference
2018-10-18 01:50:25 +08:00
}
obj.mapAutoUV()
2018-03-29 02:48:11 +08:00
}
function scaleCube(obj, val, axis) {
2018-10-18 01:50:25 +08:00
obj.to[axis] = limitToBox(val + obj.from[axis])
obj.mapAutoUV()
2018-03-29 02:48:11 +08:00
}
function scaleCubeNegative(obj, val, axis) {
2018-10-18 01:50:25 +08:00
obj.from[axis] = limitToBox(obj.to[axis] - val)
obj.mapAutoUV()
2018-03-29 02:48:11 +08:00
}
2018-10-24 03:49:04 +08:00
function moveCubesRelative(difference, index, event) { //Multiple
2018-11-12 04:19:08 +08:00
if (!quad_previews.current || !selected.length) {
2018-10-24 03:49:04 +08:00
return;
}
Undo.initEdit({cubes: selected})
var axes = []
// < >
// PageUpDown
// ^ v
var facing = quad_previews.current.getFacingDirection()
var height = quad_previews.current.getFacingHeight()
switch (facing) {
case 'north': axes = [0, 2, 1]; break;
case 'south': axes = [0, 2, 1]; break;
case 'west': axes = [2, 0, 1]; break;
case 'east': axes = [2, 0, 1]; break;
}
if (height !== 'middle') {
if (index === 1) {
index = 2
} else if (index === 2) {
index = 1
}
}
if (facing === 'south' && (index === 0 || index === 1)) difference *= -1
if (facing === 'west' && index === 0) difference *= -1
if (facing === 'east' && index === 1) difference *= -1
if (index === 2 && height !== 'down') difference *= -1
if (index === 1 && height === 'up') difference *= -1
if (event) {
difference *= canvasGridSize(event.shiftKey, event.ctrlKey);
}
selected.forEach(function(s) {
moveCube(s, s.from[axes[index]]+difference, axes[index])
})
Canvas.updatePositions()
Undo.finishEdit('move')
}
2018-03-29 02:48:11 +08:00
//Rotate
2018-10-18 01:50:25 +08:00
function rotateSelected(axis, steps) {
2018-11-12 04:19:08 +08:00
if (!selected.length) return;
2018-10-18 01:50:25 +08:00
Undo.initEdit({cubes: selected});
if (!steps) steps = 1
var origin = [8, 8, 8]
if (selected_group && Blockbench.entity_mode) {
origin = selected_group.origin.slice()
} else if (Blockbench.entity_mode) {
origin = [0, 0, 0]
} else {
origin = selected[0].origin.slice()
}
selected.forEach(function(obj) {
obj.roll(axis, steps, origin)
})
updateSelection()
Undo.finishEdit('rotate')
2018-03-29 02:48:11 +08:00
}
//Mirror
2018-10-18 01:50:25 +08:00
function mirrorSelected(axis) {
2018-11-12 04:19:08 +08:00
if (!selected.length) return;
2018-10-18 01:50:25 +08:00
Undo.initEdit({cubes: selected})
var center = 8
2018-12-16 23:18:20 +08:00
if (Blockbench.entity_mode) {
2018-10-18 01:50:25 +08:00
center = 0
2018-12-16 23:18:20 +08:00
if (selected_group && selected_group.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
}
}
}
}
flipGroup(selected_group)
selected_group.forEachChild(flipGroup)
}
2018-10-18 01:50:25 +08:00
}
selected.forEach(function(obj) {
obj.flip(axis, center, false)
if (Blockbench.entity_mode && axis === 0) {
obj.shade = !obj.shade
Canvas.updateUV(obj)
}
})
updateSelection()
Undo.finishEdit('mirror')
2018-12-16 23:18:20 +08:00
/*
Conditions:
Selection equals group cubes:
all selected cubes have group as parent
*/
2018-03-29 02:48:11 +08:00
}
//Scale
function scaleAll(save, size) {
2018-10-18 01:50:25 +08:00
if (save === true) {
hideDialog()
}
if (size === undefined) {
size = $('#model_scale_label').val()
}
var origin = [8, 8, 8]
if (Blockbench.entity_mode) {
origin = [0, 0, 0]
} else if (selected_group) {
origin = selected_group.origin
}
var clip = false
selected.forEach(function(obj) {
obj.autouv = 0;
origin.forEach(function(ogn, i) {
if ($('#model_scale_'+getAxisLetter(i)+'_axis').is(':checked')) {
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
obj.from[i] = (obj.before.from[i] - ogn) * size
if (obj.from[i] + ogn > 32 || obj.from[i] + ogn < -16) clip = true
obj.from[i] = limitToBox(obj.from[i] + ogn)
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
obj.to[i] = (obj.before.to[i] - ogn) * size
if (obj.to[i] + ogn > 32 || obj.to[i] + ogn < -16) clip = true
obj.to[i] = limitToBox(obj.to[i] + ogn)
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
obj.origin[i] = (obj.before.origin[i] - ogn) * size
obj.origin[i] = obj.origin[i] + ogn
} else {
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
obj.from[i] = obj.before.from[i]
obj.to[i] = obj.before.to[i]
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
obj.origin[i] = obj.before.origin[i]
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
}
})
if (save === true) {
delete obj.before
}
if (Blockbench.entity_mode) {
Canvas.updateUV(obj)
}
})
2018-12-29 19:26:02 +08:00
if (Blockbench.entity_mode && selected_group) {
selected_group.forEachChild((g) => {
g.origin[0] = g.old_origin[0] * size
g.origin[1] = g.old_origin[1] * size
g.origin[2] = g.old_origin[2] * size
if (save === true) {
delete g.old_origin
}
}, 'group')
}
2018-10-18 01:50:25 +08:00
if (clip && Blockbench.entity_mode === false) {
$('#scaling_clipping_warning').text('Model clipping: Your model is too large for the canvas')
2019-02-04 04:09:35 +08:00
$('#scale_overflow_btn').css('display', 'inline-block')
2018-10-18 01:50:25 +08:00
} else {
$('#scaling_clipping_warning').text('')
2019-02-04 04:09:35 +08:00
$('#scale_overflow_btn').hide()
2018-10-18 01:50:25 +08:00
}
Canvas.updatePositions()
if (save === true) {
Undo.finishEdit('scale')
}
2018-03-29 02:48:11 +08:00
}
function modelScaleSync(label) {
2018-10-18 01:50:25 +08:00
if (label) {
var size = $('#model_scale_label').val()
$('#model_scale_range').val(size)
} else {
var size = $('#model_scale_range').val()
$('#model_scale_label').val(size)
}
scaleAll(false, size)
2018-03-29 02:48:11 +08:00
}
function cancelScaleAll() {
2018-10-18 01:50:25 +08:00
selected.forEach(function(obj) {
if (obj === undefined) return;
obj.from = obj.before.from
obj.to = obj.before.to
obj.origin = obj.before.origin
delete obj.before
})
2018-12-29 19:26:02 +08:00
if (Blockbench.entity_mode && selected_group) {
selected_group.forEachChild((g) => {
g.origin[0] = g.old_origin[0]
g.origin[1] = g.old_origin[1]
g.origin[2] = g.old_origin[2]
delete g.old_origin
}, 'group')
}
2018-10-18 01:50:25 +08:00
Canvas.updatePositions()
hideDialog()
2018-03-29 02:48:11 +08:00
}
2019-02-04 04:09:35 +08:00
function scaleAllSelectOverflow() {
var overflow = [];
selected.forEach(function(obj) {
var clip = false
obj.from.forEach(function(ogn, i) {
if (obj.from[i] > 32 || obj.from[i] < -16) clip = true
if (obj.to[i] > 32 || obj.to[i] < -16) clip = true
})
if (clip) {
overflow.push(obj)
}
})
cancelScaleAll()
selected.length = 0;
overflow.forEach(cube => {
selected.push(cube)
})
updateSelection();
}
2018-03-29 02:48:11 +08:00
//Center
function centerCubesAll(axis) {
2018-10-18 01:50:25 +08:00
centerCubes(0, false)
centerCubes(1, false)
centerCubes(2, false)
Canvas.updatePositions()
2018-03-29 02:48:11 +08:00
}
function centerCubes(axis, update) {
2018-11-12 04:19:08 +08:00
if (!selected.length) return;
2018-10-18 01:50:25 +08:00
var average = 0;
selected.forEach(function(obj) {
average += obj.from[axis]
average += obj.to[axis]
})
average = average / (selected.length * 2)
var difference = (Blockbench.entity_mode ? 0 : 8) - average
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
selected.forEach(function(obj) {
obj.from[axis] = limitToBox(obj.from[axis] + difference);
obj.to[axis] = limitToBox(obj.to[axis] + difference);
obj.origin[axis] += difference;
})
2018-03-29 02:48:11 +08:00
2018-10-18 01:50:25 +08:00
if (update !== false) {
Canvas.updatePositions()
}
2018-03-29 02:48:11 +08:00
}
2018-11-12 04:19:08 +08:00
2018-12-27 21:03:04 +08:00
function getRotationInterval(event) {
if (settings.limited_rotation.value && !Blockbench.entity_mode) {
return 22.5;
} else if (event.shiftKey && event.ctrlKey) {
return 0.25;
} else if (event.shiftKey) {
return 45;
} else if (event.ctrlKey) {
return 1;
} else {
return 5;
}
}
function rotateOnAxis(value, fixed, axis) {
if (Blockbench.entity_mode) {
if (!selected_group) return;
if (!fixed) {
value = value + selected_group.rotation[axis]
}
value = Math.trimDeg(value)
selected_group.rotation[axis] = value
Canvas.updateAllBones()
return;
}
//Warning
if (settings.limited_rotation.value && settings.dialog_rotation_limit.value) {
var i = 0;
while (i < selected.length) {
if (selected[i].rotation[(axis+1)%3] ||
selected[i].rotation[(axis+2)%3]
) {
i = Infinity
Blockbench.showMessageBox({
title: tl('message.rotation_limit.title'),
icon: 'rotate_right',
message: tl('message.rotation_limit.message'),
buttons: [tl('dialog.ok'), tl('dialog.dontshowagain')]
}, function(r) {
if (r === 1) {
settings.dialog_rotation_limit.value = false
saveSettings()
}
})
return;
//Gotta stop the numslider here
}
i++;
}
}
var axis_letter = getAxisLetter(axis)
var origin = selected[0].origin
selected.forEach(function(obj, i) {
2019-02-04 04:09:35 +08:00
if (!obj.rotation.allEqual(0)) {
2018-12-27 21:03:04 +08:00
origin = obj.origin
}
})
2019-02-04 04:09:35 +08:00
if (origin.allEqual(8)) {
origin = getSelectionCenter()
origin.forEach((n, ni) => {
origin[ni] = Math.round(n*2)/2
})
}
2018-12-27 21:03:04 +08:00
selected.forEach(function(obj, i) {
2019-02-04 04:09:35 +08:00
if (obj.rotation.allEqual(0)) {
2018-12-29 19:26:02 +08:00
obj.origin = origin.slice()
2018-12-27 21:03:04 +08:00
}
var obj_val = value;
if (!fixed) {
obj_val += obj.rotation[axis]
}
2018-12-29 19:26:02 +08:00
obj_val = Math.trimDeg(obj_val)
2018-12-27 21:03:04 +08:00
if (settings.limited_rotation.value) {
//Limit To 1 Axis
obj.rotation[(axis+1)%3] = 0
obj.rotation[(axis+2)%3] = 0
//Limit Angle
obj_val = Math.round(obj_val/22.5)*22.5
if (obj_val > 45 || obj_val < -45) {
let f = obj_val > 45
obj.roll(axis, f!=(axis==1) ? 1 : 3)
obj_val = f ? -22.5 : 22.5;
}
} else {
obj_val = Math.trimDeg(obj_val)
}
obj.rotation[axis] = obj_val
obj.rotation_axis = axis_letter
})
}
2018-11-12 04:19:08 +08:00
BARS.defineActions(function() {
function moveOnAxis(value, fixed, axis) {
selected.forEach(function(obj, i) {
var number = value
if (fixed) {
number -= obj.from[axis]
}
number = limitToBox(obj.to [axis] + number) - obj.to [axis];
number = limitToBox(obj.from[axis] + number) - obj.from[axis];
obj.from[axis] += number
obj.to[axis] += number
obj.mapAutoUV()
})
Canvas.updatePositions()
}
new NumSlider({
id: 'slider_pos_x',
2018-12-29 19:26:02 +08:00
condition: () => (selected.length && Modes.id === 'edit'),
2018-11-12 04:19:08 +08:00
get: function() {
return selected[0].from[0]
},
change: function(value, fixed) {
moveOnAxis(value, fixed, 0)
},
onBefore: function() {
Undo.initEdit({cubes: selected})
},
onAfter: function() {
Undo.finishEdit('move')
}
})
new NumSlider({
id: 'slider_pos_y',
2018-12-29 19:26:02 +08:00
condition: () => (selected.length && Modes.id === 'edit'),
2018-11-12 04:19:08 +08:00
get: function() {
return selected[0].from[1]
},
change: function(value, fixed) {
moveOnAxis(value, fixed, 1)
},
onBefore: function() {
Undo.initEdit({cubes: selected})
},
onAfter: function() {
Undo.finishEdit('move')
}
})
new NumSlider({
id: 'slider_pos_z',
2018-12-29 19:26:02 +08:00
condition: () => (selected.length && Modes.id === 'edit'),
2018-11-12 04:19:08 +08:00
get: function() {
return selected[0].from[2]
},
change: function(value, fixed) {
moveOnAxis(value, fixed, 2)
},
onBefore: function() {
Undo.initEdit({cubes: selected})
},
onAfter: function() {
Undo.finishEdit('move')
}
})
function scaleOnAxis(value, fixed, axis) {
selected.forEach(function(obj, i) {
var diff = value
if (fixed) {
diff -= obj.size(axis)
}
obj.to[axis] = limitToBox(obj.to[axis] + diff)
obj.mapAutoUV()
})
Canvas.updatePositions()
2018-12-03 02:37:06 +08:00
if (Blockbench.entity_mode) {
Canvas.updateUVs()
}
2018-11-12 04:19:08 +08:00
}
new NumSlider({
id: 'slider_size_x',
2018-12-29 19:26:02 +08:00
condition: () => (selected.length && Modes.id === 'edit'),
2018-11-12 04:19:08 +08:00
get: function() {
return selected[0].to[0] - selected[0].from[0]
},
change: function(value, fixed) {
scaleOnAxis(value, fixed, 0)
},
onBefore: function() {
Undo.initEdit({cubes: selected})
},
onAfter: function() {
Undo.finishEdit('resize')
}
})
new NumSlider({
id: 'slider_size_y',
2018-12-29 19:26:02 +08:00
condition: () => (selected.length && Modes.id === 'edit'),
2018-11-12 04:19:08 +08:00
get: function() {
return selected[0].to[1] - selected[0].from[1]
},
change: function(value, fixed) {
scaleOnAxis(value, fixed, 1)
},
onBefore: function() {
Undo.initEdit({cubes: selected})
},
onAfter: function() {
Undo.finishEdit('resize')
}
})
new NumSlider({
id: 'slider_size_z',
2018-12-29 19:26:02 +08:00
condition: () => (selected.length && Modes.id === 'edit'),
2018-11-12 04:19:08 +08:00
get: function() {
return selected[0].to[2] - selected[0].from[2]
},
change: function(value, fixed) {
scaleOnAxis(value, fixed, 2)
},
onBefore: function() {
Undo.initEdit({cubes: selected})
},
onAfter: function() {
Undo.finishEdit('resize')
}
})
2018-12-27 21:03:04 +08:00
//Inflage
2018-11-12 04:19:08 +08:00
new NumSlider({
id: 'slider_inflate',
2019-03-10 05:06:35 +08:00
condition: function() {return selected.length && Modes.id === 'edit'},
2018-11-12 04:19:08 +08:00
get: function() {
return selected[0].inflate
},
change: function(value, fixed) {
selected.forEach(function(obj, i) {
var diff = value
if (fixed) {
diff -= obj.inflate
}
obj.inflate = obj.inflate + diff
})
Canvas.updatePositions()
},
onBefore: function() {
Undo.initEdit({cubes: selected})
},
onAfter: function() {
Undo.finishEdit('inflate')
}
})
2018-12-27 21:03:04 +08:00
//Rotation
2018-11-12 04:19:08 +08:00
new NumSlider({
id: 'slider_rotation_x',
2018-12-29 19:26:02 +08:00
condition: function() {return !!(Blockbench.entity_mode ? selected_group : selected.length) && Modes.id === 'edit'},
2018-11-12 04:19:08 +08:00
get: function() {
var obj = Blockbench.entity_mode ? selected_group : selected[0]
return obj ? obj.rotation[0] : ''
},
change: function(value, fixed) {
rotateOnAxis(value, fixed, 0)
2018-12-27 21:03:04 +08:00
Canvas.updatePositions()
2018-11-12 04:19:08 +08:00
},
onBefore: function() {
Undo.initEdit({cubes: selected, group: selected_group})
},
onAfter: function() {
Undo.finishEdit('rotate')
},
getInterval: getRotationInterval
})
new NumSlider({
id: 'slider_rotation_y',
2018-12-29 19:26:02 +08:00
condition: function() {return !!(Blockbench.entity_mode ? selected_group : selected.length) && Modes.id === 'edit'},
2018-11-12 04:19:08 +08:00
get: function() {
var obj = Blockbench.entity_mode ? selected_group : selected[0]
return obj ? obj.rotation[1] : ''
},
change: function(value, fixed) {
rotateOnAxis(value, fixed, 1)
2018-12-27 21:03:04 +08:00
Canvas.updatePositions()
2018-11-12 04:19:08 +08:00
},
onBefore: function() {
Undo.initEdit({cubes: selected, group: selected_group})
},
onAfter: function() {
Undo.finishEdit('rotate')
},
getInterval: getRotationInterval
})
new NumSlider({
id: 'slider_rotation_z',
2018-12-29 19:26:02 +08:00
condition: function() {return !!(Blockbench.entity_mode ? selected_group : selected.length) && Modes.id === 'edit'},
2018-11-12 04:19:08 +08:00
get: function() {
var obj = Blockbench.entity_mode ? selected_group : selected[0]
return obj ? obj.rotation[2] : ''
},
change: function(value, fixed) {
rotateOnAxis(value, fixed, 2)
2018-12-27 21:03:04 +08:00
Canvas.updatePositions()
2018-11-12 04:19:08 +08:00
},
onBefore: function() {
Undo.initEdit({cubes: selected, group: selected_group})
},
onAfter: function() {
Undo.finishEdit('rotate')
},
getInterval: getRotationInterval
})
function moveOriginOnAxis(value, fixed, axis) {
if (selected_group) {
var diff = value
if (fixed) {
diff -= selected_group.origin[axis]
}
selected_group.origin[axis] += diff
Canvas.updatePositions()
return;
}
selected.forEach(function(obj, i) {
var diff = value
if (fixed) {
diff -= obj.origin[axis]
}
obj.origin[axis] += diff
})
Canvas.updatePositions()
}
new NumSlider({
id: 'slider_origin_x',
2018-12-29 19:26:02 +08:00
condition: function() {return !!(Blockbench.entity_mode ? selected_group : selected.length) && Modes.id === 'edit'},
2018-11-12 04:19:08 +08:00
get: function() {
var obj = Blockbench.entity_mode ? selected_group : selected[0]
return obj ? obj.origin[0] : ''
},
change: function(value, fixed) {
moveOriginOnAxis(value, fixed, 0)
},
onBefore: function() {
Undo.initEdit({cubes: selected, group: selected_group})
},
onAfter: function() {
Undo.finishEdit('origin')
}
})
new NumSlider({
id: 'slider_origin_y',
2018-12-29 19:26:02 +08:00
condition: function() {return !!(Blockbench.entity_mode ? selected_group : selected.length) && Modes.id === 'edit'},
2018-11-12 04:19:08 +08:00
get: function() {
var obj = Blockbench.entity_mode ? selected_group : selected[0]
return obj ? obj.origin[1] : ''
},
change: function(value, fixed) {
moveOriginOnAxis(value, fixed, 1)
},
onBefore: function() {
Undo.initEdit({cubes: selected, group: selected_group})
},
onAfter: function() {
Undo.finishEdit('origin')
}
})
new NumSlider({
id: 'slider_origin_z',
2018-12-29 19:26:02 +08:00
condition: function() {return !!(Blockbench.entity_mode ? selected_group : selected.length) && Modes.id === 'edit'},
2018-11-12 04:19:08 +08:00
get: function() {
var obj = Blockbench.entity_mode ? selected_group : selected[0]
return obj ? obj.origin[2] : ''
},
change: function(value, fixed) {
moveOriginOnAxis(value, fixed, 2)
},
onBefore: function() {
Undo.initEdit({cubes: selected, group: selected_group})
},
onAfter: function() {
Undo.finishEdit('origin')
}
})
new Action({
id: 'scale',
icon: 'settings_overscan',
category: 'transform',
click: function () {
2018-12-03 02:37:06 +08:00
$('#model_scale_range, #model_scale_label').val(1)
$('#scaling_clipping_warning').text('')
2018-11-12 04:19:08 +08:00
2018-12-29 19:26:02 +08:00
Undo.initEdit({cubes: selected, outliner: Blockbench.entity_mode})
2018-11-12 04:19:08 +08:00
selected.forEach(function(obj) {
obj.before = {
from: obj.from.slice(),
to: obj.to.slice(),
origin: obj.origin.slice()
}
})
2018-12-29 19:26:02 +08:00
if (Blockbench.entity_mode && selected_group) {
selected_group.forEachChild((g) => {
g.old_origin = g.origin.slice();
}, 'group', true)
}
2018-11-12 04:19:08 +08:00
showDialog('scaling')
2019-02-04 04:09:35 +08:00
scaleAll(false, 1)
2018-11-12 04:19:08 +08:00
}
})
new Action({
id: 'rotate_x_cw',
icon: 'rotate_right',
color: 'x',
category: 'transform',
click: function () {
rotateSelected(0, 1);
}
})
new Action({
id: 'rotate_x_ccw',
icon: 'rotate_left',
color: 'x',
category: 'transform',
click: function () {
rotateSelected(0, 3);
}
})
new Action({
id: 'rotate_y_cw',
icon: 'rotate_right',
color: 'y',
category: 'transform',
click: function () {
rotateSelected(1, 1);
}
})
new Action({
id: 'rotate_y_ccw',
icon: 'rotate_left',
color: 'y',
category: 'transform',
click: function () {
rotateSelected(1, 3);
}
})
new Action({
id: 'rotate_z_cw',
icon: 'rotate_right',
color: 'z',
category: 'transform',
click: function () {
rotateSelected(2, 1);
}
})
new Action({
id: 'rotate_z_ccw',
icon: 'rotate_left',
color: 'z',
category: 'transform',
click: function () {
rotateSelected(2, 3);
}
})
new Action({
id: 'flip_x',
icon: 'icon-mirror_x',
color: 'x',
category: 'transform',
click: function () {
mirrorSelected(0);
}
})
new Action({
id: 'flip_y',
icon: 'icon-mirror_y',
color: 'y',
category: 'transform',
click: function () {
mirrorSelected(1);
}
})
new Action({
id: 'flip_z',
icon: 'icon-mirror_z',
color: 'z',
category: 'transform',
click: function () {
mirrorSelected(2);
}
})
new Action({
id: 'center_x',
icon: 'vertical_align_center',
color: 'x',
category: 'transform',
click: function () {
Undo.initEdit({cubes: selected});
centerCubes(0);
Undo.finishEdit('center')
}
})
new Action({
id: 'center_y',
icon: 'vertical_align_center',
color: 'y',
category: 'transform',
click: function () {
Undo.initEdit({cubes: selected});
centerCubes(1);
Undo.finishEdit('center')
}
})
new Action({
id: 'center_z',
icon: 'vertical_align_center',
color: 'z',
category: 'transform',
click: function () {
Undo.initEdit({cubes: selected});
centerCubes(2);
Undo.finishEdit('center')
}
})
new Action({
id: 'center_all',
icon: 'filter_center_focus',
category: 'transform',
click: function () {
Undo.initEdit({cubes: selected});
centerCubesAll();
Undo.finishEdit('center')
}
})
new Action({
id: 'toggle_visibility',
icon: 'visibility',
category: 'transform',
click: function () {toggleCubeProperty('visibility')}
})
new Action({
id: 'toggle_export',
icon: 'save',
category: 'transform',
click: function () {toggleCubeProperty('export')}
})
new Action({
id: 'toggle_autouv',
icon: 'fullscreen_exit',
category: 'transform',
click: function () {toggleCubeProperty('autouv')}
})
new Action({
id: 'toggle_shade',
icon: 'wb_sunny',
category: 'transform',
2019-02-04 04:09:35 +08:00
condition: () => !Blockbench.entity_mode,
click: function () {toggleCubeProperty('shade')}
})
new Action({
id: 'toggle_mirror_uv',
icon: 'icon-mirror_x',
category: 'transform',
condition: () => Blockbench.entity_mode,
2018-11-12 04:19:08 +08:00
click: function () {toggleCubeProperty('shade')}
})
new Action({
id: 'rename',
icon: 'text_format',
category: 'transform',
keybind: new Keybind({key: 113}),
click: function () {renameCubes()}
})
new Action({
id: 'update_autouv',
icon: 'brightness_auto',
category: 'transform',
condition: () => !Blockbench.entity_mode,
click: function () {
if (selected.length) {
Undo.initEdit({cubes: selected[0].forSelected(), selection: true})
selected[0].forSelected(function(cube) {
cube.mapAutoUV()
})
Undo.finishEdit('update_autouv')
}
}
})
new Action({
id: 'origin_to_geometry',
icon: 'filter_center_focus',
category: 'transform',
click: function () {origin2geometry()}
})
new Action({
id: 'rescale_toggle',
icon: 'check_box_outline_blank',
category: 'transform',
condition: function() {return !Blockbench.entity_mode && selected.length;},
click: function () {
Undo.initEdit({cubes: selected})
var value = !selected[0].rescale
selected.forEach(function(cube) {
cube.rescale = value
})
Canvas.updatePositions()
updateNslideValues()
Undo.finishEdit('rescale')
}
})
new Action({
id: 'bone_reset_toggle',
icon: 'check_box_outline_blank',
category: 'transform',
condition: function() {return Blockbench.entity_mode && selected_group;},
click: function () {
Undo.initEdit({group: selected_group})
selected_group.reset = !selected_group.reset
updateNslideValues()
Undo.finishEdit('bone_reset')
}
})
})