Re-center java block/item models when converting

Fix rotation issue when converting model with rotation axis restriction
Fix actions cannot be added to a menu without path
This commit is contained in:
JannisX11 2023-07-10 21:18:12 +02:00
parent 74cd419934
commit 3b859e477d
2 changed files with 17 additions and 4 deletions

View File

@ -545,14 +545,13 @@ class Menu {
conditionMet() {
return Condition(this.condition);
}
addAction(action, path) {
addAction(action, path = '') {
if (this.structure instanceof Array == false) return;
if (path === undefined) path = '';
if (typeof path !== 'string') path = path.toString();
let track = path.split('.')
function traverse(arr, layer) {
if (track.length === layer || !track[layer] === '' || !isNaN(parseInt(track[layer])) || (track[layer][0] == '#')) {
if (track.length === layer || track[layer] === '' || !isNaN(parseInt(track[layer])) || (track[layer][0] == '#')) {
let index = arr.length;
if (track[layer] !== '' && track.length !== layer) {
if (track[layer].startsWith('#')) {

View File

@ -145,6 +145,20 @@ class ModelFormat {
group.createUniqueName();
})
}
if (Format.centered_grid != old_format.centered_grid) {
let offset = Format.centered_grid ? -8 : 8;
Cube.all.forEach(cube => {
for (let axis of [0, 2]) {
cube.from[axis] += offset;
cube.to[axis] += offset;
cube.origin[axis] += offset;
}
})
Group.all.forEach(group => {
group.origin[0] += offset;
group.origin[2] += offset;
})
}
if (!Format.single_texture && old_format.single_texture && Texture.all.length) {
let texture = Texture.getDefault();
@ -195,7 +209,7 @@ class ModelFormat {
if (Format.rotation_limit && !old_format.rotation_limit && Format.rotate_cubes) {
Cube.all.forEach(cube => {
if (!cube.rotation.allEqual(0)) {
var axis = (cube.rotation_axis && getAxisNumber(cube.rotation_axis)) || 0;
var axis = (getAxisNumber(cube.rotationAxis())) || 0;
var cube_rotation = Format.rotation_snap ? Math.round(cube.rotation[axis]/22.5)*22.5 : cube.rotation[axis];
var angle = limitNumber( cube_rotation, -45, 45 );
cube.rotation.V3_set(0, 0, 0)