Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
JannisX11 committed Sep 28, 2024
2 parents 637a415 + 114fefd commit e33736c
Show file tree
Hide file tree
Showing 19 changed files with 212 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dist: trusty

language: node_js
node:
- 16
- 20

if: tag IS blank AND commit_message =~ ci-build

Expand Down
3 changes: 3 additions & 0 deletions css/panels.css
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@
width: 100%;
padding: 2px;
box-sizing: border-box;
}
div.outliner_object { /* Higher prio to override older themes */
padding-left: calc(var(--indentation) * var(--indentation-offset));
}
.outliner_object:active {
Expand Down Expand Up @@ -472,6 +474,7 @@
}
#cubes_list .outliner_line_guide {
position: absolute;
left: calc(var(--indentation) * var(--indentation-offset) - 1px);
top: -4px;
bottom: 4px;
width: 4px;
Expand Down
15 changes: 13 additions & 2 deletions js/animations/animation_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,26 @@ const Animator = {
scene.add(Animator.onion_skin_object);
},
stackAnimations(animations, in_loop, controller_blend_values = 0) {
if (animations.length > 1 && Animation.selected && animations.includes(Animation.selected)) {
// Ensure selected animation is applied last so that transform gizmo gets correct pre rotation
animations = animations.slice();
animations.remove(Animation.selected);
animations.push(Animation.selected);
}
[...Group.all, ...Outliner.elements].forEach(node => {
if (!node.constructor.animator) return;
Animator.resetLastValues();
animations.forEach(animation => {
animations.forEach((animation, anim_i) => {
if (animation.loop == 'once' && Timeline.time > animation.length && animation.length) {
return;
}
let multiplier = animation.blend_weight ? Math.clamp(Animator.MolangParser.parse(animation.blend_weight), 0, Infinity) : 1;
if (typeof controller_blend_values[animation.uuid] == 'number') multiplier *= controller_blend_values[animation.uuid];
if (anim_i == animations.length - 1) {
let mesh = node.mesh;
if (!mesh.pre_rotation) mesh.pre_rotation = new THREE.Euler();
mesh.pre_rotation.copy(mesh.rotation);
}
animation.getBoneAnimator(node).displayFrame(multiplier);
})
})
Expand Down Expand Up @@ -446,7 +457,7 @@ const Animator = {
let new_animations = [];
function multilinify(string) {
return typeof string == 'string'
? string.replace(/;(?!$)/, ';\n')
? string.replace(/;\s*(?!$)/g, ';\n')
: string
}
if (!json) return new_animations;
Expand Down
24 changes: 12 additions & 12 deletions js/display_mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ class refModel {
case 'monitor':
this.updateBasePosition = function() {
var side = display_slot.includes('left') ? -1 : 1;
setDisplayArea(side*9.039, -8.318, 20.8, 0, 0, 0, 1,1,1)
setDisplayArea(side*9.039, -8.318+24, 20.8, 0, 0, 0, 1,1,1)
}
break;
case 'frame':
Expand All @@ -349,21 +349,21 @@ class refModel {
case 'bow':
this.updateBasePosition = function() {
var side = display_slot.includes('left') ? -1 : 1;
setDisplayArea(side*4.2, -4.9, 25, -20, -19, -8, 1,1,1)
setDisplayArea(side*4.2, -4.9+24, 25, -20, -19, -8, 1,1,1)
}
break;
case 'crossbow':
this.updateBasePosition = function() {
var side = display_slot.includes('left') ? -1 : 1;
setDisplayArea(side*-1.2, -6.75, 23, 0, side*10, 0, 1, 1, 1)
setDisplayArea(side*-1.2, -6.75+24, 23, 0, side*10, 0, 1, 1, 1)
}
break;

case 'eating':
this.updateBasePosition = function() {
var side = display_slot.includes('left') ? -1 : 1;
DisplayMode.setBase(
side*-1.7, -6.1, 23.4,
side*-1.7, -6.1+24, 23.4,
-92, side*100, side*119,
0.8, 0.8, 0.8)
}
Expand Down Expand Up @@ -1155,10 +1155,10 @@ class refModel {
}
buildMonitor() {
this.buildModel(JSON.parse(`[
{"size": [8, 8, 0.1], "pos": [0, 4.93, 31.20], "origin": [0, 0, 0], "north":{"uv":[0,0,0,0]},"east":{"uv":[0,0,0,0]},"south":{"uv":[0,0,0,0]},"west":{"uv":[0,0,16,16]},"up":{"uv":[0,0,0,0]},"down":{"uv":[0,0,0,0]}},
{"size": [8, 8, 0.1], "pos": [0, -4.93, 31.20], "origin": [0, 0, 0], "north":{"uv":[0,0,0,0]},"east":{"uv":[0,0,0,0]},"south":{"uv":[0,0,0,0]},"west":{"uv":[0,0,16,16]},"up":{"uv":[0,0,0,0]},"down":{"uv":[0,0,0,0]}},
{"size": [8, 8, 0.1], "pos": [5.65, 0, 31.2], "origin": [0, 0, 0], "north":{"uv":[0,0,0,0]},"east":{"uv":[0,0,0,0]},"south":{"uv":[0,0,0,0]},"west":{"uv":[0,0,16,16]},"up":{"uv":[0,0,0,0]},"down":{"uv":[0,0,0,0]}},
{"size": [8, 8, 0.1], "pos": [-5.65, 0, 31.2], "origin": [0, 0, 0], "north":{"uv":[0,0,0,0]},"east":{"uv":[0,0,0,0]},"south":{"uv":[0,0,0,0]},"west":{"uv":[0,0,16,16]},"up":{"uv":[0,0,0,0]},"down":{"uv":[0,0,0,0]}}
{"size": [8, 8, 0.1], "pos": [0, 28.93, 31.20], "origin": [0, 0, 0], "north":{"uv":[0,0,0,0]},"east":{"uv":[0,0,0,0]},"south":{"uv":[0,0,0,0]},"west":{"uv":[0,0,16,16]},"up":{"uv":[0,0,0,0]},"down":{"uv":[0,0,0,0]}},
{"size": [8, 8, 0.1], "pos": [0, 19.07, 31.20], "origin": [0, 0, 0], "north":{"uv":[0,0,0,0]},"east":{"uv":[0,0,0,0]},"south":{"uv":[0,0,0,0]},"west":{"uv":[0,0,16,16]},"up":{"uv":[0,0,0,0]},"down":{"uv":[0,0,0,0]}},
{"size": [8, 8, 0.1], "pos": [5.65, 24, 31.2], "origin": [0, 0, 0], "north":{"uv":[0,0,0,0]},"east":{"uv":[0,0,0,0]},"south":{"uv":[0,0,0,0]},"west":{"uv":[0,0,16,16]},"up":{"uv":[0,0,0,0]},"down":{"uv":[0,0,0,0]}},
{"size": [8, 8, 0.1], "pos": [-5.65, 24, 31.2], "origin": [0, 0, 0], "north":{"uv":[0,0,0,0]},"east":{"uv":[0,0,0,0]},"south":{"uv":[0,0,0,0]},"west":{"uv":[0,0,16,16]},"up":{"uv":[0,0,0,0]},"down":{"uv":[0,0,0,0]}}
]`), 'black')
}
buildBlock() {
Expand Down Expand Up @@ -1530,8 +1530,8 @@ function getOptimalFocalLength() {
DisplayMode.loadFirstRight = function() { //Loader
loadDisp('firstperson_righthand')
display_preview.loadAnglePreset({
position: [0, 0, 32.4],
target: [0, 0, 0],
position: [0, 24, 32.4],
target: [0, 24, 0],
focal_length: getOptimalFocalLength(),
})
display_preview.controls.enabled = false
Expand All @@ -1542,8 +1542,8 @@ DisplayMode.loadFirstRight = function() { //Loader
DisplayMode.loadFirstLeft = function() { //Loader
loadDisp('firstperson_lefthand')
display_preview.loadAnglePreset({
position: [0, 0, 32.4],
target: [0, 0, 0],
position: [0, 24, 32.4],
target: [0, 24, 0],
focal_length: getOptimalFocalLength(),
})
display_preview.controls.enabled = false
Expand Down
13 changes: 8 additions & 5 deletions js/interface/panels.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ class Panel extends EventSystem {
this.update();
let height_difference = this.position_data.height - height1;

let panel_b = other_panels.find(p => p != this && p.resizable && p.min_height < p.height);
let panel_b = other_panels.find(p => p != this && p.resizable && p.min_height < (p.height??p.node.clientHeight));
if (sidebar_gap < 1 && panel_b && change_amount > 0) {
if (!other_panel_height_before[panel_b.id]) other_panel_height_before[panel_b.id] = panel_b.height;
if (!other_panel_height_before[panel_b.id]) other_panel_height_before[panel_b.id] = (panel_b.height??panel_b.node.clientHeight);
panel_b.position_data.fixed_height = true;
panel_b.position_data.height = Math.max(panel_b.position_data.height - height_difference, this.min_height);
panel_b.update();
Expand Down Expand Up @@ -662,6 +662,7 @@ class Panel extends EventSystem {
let work_screen = document.querySelector('div#work_screen');
let center_screen = document.querySelector('div#center');
let slot = this.slot;
let is_sidebar = slot == 'left_bar' || slot == 'right_bar';
if (show) {
this.node.classList.remove('hidden');
if (slot == 'float') {
Expand All @@ -681,7 +682,7 @@ class Panel extends EventSystem {
this.node.classList.remove('bottommost_panel');
this.node.classList.remove('topmost_panel');
} else {
this.node.style.width = this.node.style.height = this.node.style.left = this.node.style.top = null;
this.node.style.width = this.node.style.left = this.node.style.top = null;
}
if (Blockbench.isMobile) {
this.width = this.node.clientWidth;
Expand All @@ -704,20 +705,22 @@ class Panel extends EventSystem {
}
this.node.style.width = this.width + 'px';
this.node.style.height = this.height + 'px';
} else if (slot == 'left_bar' || slot == 'right_bar') {
} else if (is_sidebar) {
if (this.fixed_height) {
//let other_panels = slot == 'left_bar' ? Interface.getLeftPanels() : Interface.getRightPanels();
//let available_height = (slot == 'left_bar' ? Interface.left_bar : Interface.right_bar).clientHeight;
//let min_height = other_panels.reduce((sum, panel) => (panel == this ? sum : (sum - panel.node.clientHeight)), available_height);
this.height = Math.clamp(this.position_data.height, 30, Interface.work_screen.clientHeight);
this.node.style.height = this.height + 'px';
this.node.classList.add('fixed_height');
} else {
this.node.style.height = null;
}
}
if (!this.fixed_height) this.node.classList.remove('fixed_height');

if (this.sidebar_resize_handle) {
this.sidebar_resize_handle.style.display = (slot == 'left_bar' || slot == 'right_bar') ? 'block' : 'none';
this.sidebar_resize_handle.style.display = (is_sidebar) ? 'block' : 'none';
}
if ((slot == 'right_bar' && Interface.getRightPanels().last() == this) || (slot == 'left_bar' && Interface.getLeftPanels().last() == this)) {
this.node.parentElement?.childNodes.forEach(n => n.classList.remove('bottommost_panel'));
Expand Down
13 changes: 10 additions & 3 deletions js/io/formats/modded_entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ const Templates = {
}
}`,
field: `private final ModelPart %(bone);`,
model_part: `this.%(bone) = root.getChild("%(bone)");`,
model_part: `?(has_no_parent)this.%(bone) = root.getChild("%(bone)");
?(has_parent)this.%(bone) = this.%(parent).getChild("%(bone)");`,
bone:
`?(has_no_parent)PartDefinition %(bone) = partdefinition.addOrReplaceChild("%(bone)", CubeListBuilder.create()
?(has_parent)PartDefinition %(bone) = %(parent).addOrReplaceChild("%(bone)", CubeListBuilder.create()
Expand Down Expand Up @@ -312,7 +313,8 @@ const Templates = {
}
}`,
field: `private final ModelPart %(bone);`,
model_part: `this.%(bone) = root.getChild("%(bone)");`,
model_part: `?(has_no_parent)this.%(bone) = root.getChild("%(bone)");
?(has_parent)this.%(bone) = this.%(parent).getChild("%(bone)");`,
bone:
`?(has_no_parent)ModelPartData %(bone) = modelPartData.addChild("%(bone)", ModelPartBuilder.create()
?(has_parent)ModelPartData %(bone) = %(parent).addChild("%(bone)", ModelPartBuilder.create()
Expand Down Expand Up @@ -609,7 +611,12 @@ var codec = new Codec('modded_entity', {
if (group.is_rotation_subgroup) continue;
//if (usesLayerDef && group.parent instanceof Group) continue;
let modelPart = snippet
.replace(R('bone'), group.name);
.replace(R('bone'), group.name)
.replace(/\t+/, '')
.replace(/(?:\n|^)\?\(has_parent\).+/, group.parent instanceof Group ? Templates.keepLine : '')
.replace(/(?:\n|^)\?\(has_no_parent\).+/, group.parent instanceof Group ? '' : Templates.keepLine)
.trim()
.replace(R('parent'), group.parent.name)
group_snippets.push(modelPart);
}
return group_snippets.join('\n\t\t')
Expand Down
35 changes: 0 additions & 35 deletions js/io/formats/optifine_jem.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,39 +383,4 @@ BARS.defineActions(function() {
})
})

new ValidatorCheck('zero_wide_uv_faces', {
condition: {formats: ['optifine_entity', 'java_block']},
update_triggers: ['update_selection'],
run() {
for (let cube of Cube.all) {
if (cube.box_uv && Format.id == 'optifine_entity') continue;
let select_cube_button = {
name: 'Select Cube',
icon: 'fa-cube',
click() {
Validator.dialog.hide();
cube.select();
}
};
for (let fkey in cube.faces) {
let face = cube.faces[fkey];
let uv_size = face.uv_size;
let size_issue;
for (let i of [0, 1]) {
let size = uv_size[i];
if (Math.abs(size) < 0.00005) {
size_issue = true;
}
}
if (size_issue) {
this.warn({
message: `The face "${fkey}" on cube "${cube.name}" has invalid UV sizes. UV sizes cannot be 0.`,
buttons: [select_cube_button]
})
}
}
}
}
})

})()
14 changes: 8 additions & 6 deletions js/modeling/transform_gizmo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@

if (Toolbox.selected.id === 'rotate_tool' && (BarItems.rotation_space.value === 'global' || scope.axis == 'E' || (Timeline.selected_animator?.rotation_global && Transformer.getTransformSpace() == 2))) {

let old_rotation = mesh.pre_rotation ?? mesh.fix_rotation;
let normal = scope.axis == 'E'
? rotate_normal
: axisNumber == 0 ? THREE.NormalX : (axisNumber == 1 ? THREE.NormalY : THREE.NormalZ);
Expand All @@ -1505,22 +1506,23 @@
mesh.setRotationFromMatrix(rotWorldMatrix)
let e = mesh.rotation;

scope.keyframes[0].offset('x', Math.trimDeg( (-Math.radToDeg(e.x - mesh.fix_rotation.x)) - scope.keyframes[0].calc('x') ));
scope.keyframes[0].offset('y', Math.trimDeg( (-Math.radToDeg(e.y - mesh.fix_rotation.y)) - scope.keyframes[0].calc('y') ));
scope.keyframes[0].offset('z', Math.trimDeg( ( Math.radToDeg(e.z - mesh.fix_rotation.z)) - scope.keyframes[0].calc('z') ));
scope.keyframes[0].offset('x', Math.trimDeg( (-Math.radToDeg(e.x - old_rotation.x)) - scope.keyframes[0].calc('x') ));
scope.keyframes[0].offset('y', Math.trimDeg( (-Math.radToDeg(e.y - old_rotation.y)) - scope.keyframes[0].calc('y') ));
scope.keyframes[0].offset('z', Math.trimDeg( ( Math.radToDeg(e.z - old_rotation.z)) - scope.keyframes[0].calc('z') ));

} else if (Toolbox.selected.id === 'rotate_tool' && Transformer.getTransformSpace() == 2 && [0, 1, 2].find(axis => axis !== axisNumber && scope.keyframes[0].get(getAxisLetter(axis))) !== undefined) {
if (axisNumber != 2) difference *= -1;

let old_rotation = mesh.pre_rotation ?? mesh.fix_rotation;
let old_order = mesh.rotation.order;
mesh.rotation.reorder(axisNumber == 0 ? 'ZYX' : (axisNumber == 1 ? 'ZXY' : 'XYZ'))
var obj_val = Math.trimDeg(Math.radToDeg(mesh.rotation[axis]) + difference);
mesh.rotation[axis] = Math.degToRad(obj_val);
mesh.rotation.reorder(old_order);

scope.keyframes[0].offset('x', Math.trimDeg( (-Math.radToDeg(mesh.rotation.x - mesh.fix_rotation.x)) - scope.keyframes[0].calc('x') ));
scope.keyframes[0].offset('y', Math.trimDeg( (-Math.radToDeg(mesh.rotation.y - mesh.fix_rotation.y)) - scope.keyframes[0].calc('y') ));
scope.keyframes[0].offset('z', Math.trimDeg( ( Math.radToDeg(mesh.rotation.z - mesh.fix_rotation.z)) - scope.keyframes[0].calc('z') ));
scope.keyframes[0].offset('x', Math.trimDeg( (-Math.radToDeg(mesh.rotation.x - old_rotation.x)) - scope.keyframes[0].calc('x') ));
scope.keyframes[0].offset('y', Math.trimDeg( (-Math.radToDeg(mesh.rotation.y - old_rotation.y)) - scope.keyframes[0].calc('y') ));
scope.keyframes[0].offset('z', Math.trimDeg( ( Math.radToDeg(mesh.rotation.z - old_rotation.z)) - scope.keyframes[0].calc('z') ));

} else if (Toolbox.selected.id === 'move_tool' && BarItems.transform_space.value === 'global') {

Expand Down
5 changes: 2 additions & 3 deletions js/outliner/outliner.js
Original file line number Diff line number Diff line change
Expand Up @@ -1406,11 +1406,10 @@ Interface.definePanels(function() {

var VueTreeItem = Vue.extend({
template:
'<li class="outliner_node" v-bind:class="{ parent_li: node.children && node.children.length > 0}" v-bind:id="node.uuid">' +
`<li class="outliner_node" v-bind:class="{ parent_li: node.children && node.children.length > 0}" v-bind:id="node.uuid" v-bind:style="{'--indentation': indentation}">` +
`<div
class="outliner_object"
v-bind:class="{ cube: node.type === 'cube', group: node.type === 'group', selected: node.selected }"
v-bind:style="{'--indentation': indentation}"
@contextmenu.prevent.stop="node.showContextMenu($event)"
@click="node.select($event, true)"
:title="node.title"
Expand All @@ -1437,7 +1436,7 @@ Interface.definePanels(function() {
//Other Entries
'<ul v-if="node.isOpen">' +
'<vue-tree-item v-for="item in visible_children" :node="item" :depth="depth + 1" :options="options" :key="item.uuid"></vue-tree-item>' +
`<div class="outliner_line_guide" v-if="node.constructor.selected == node" v-bind:style="{left: 'calc(var(--indentation) * ' + indentation + ')'}"></div>` +
`<div class="outliner_line_guide" v-if="node.constructor.selected == node"></div>` +
'</ul>' +
'</li>',
props: {
Expand Down
6 changes: 5 additions & 1 deletion js/preview/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ class Preview {
Transformer.dispatchPointerHover(event);
}
if (Transformer.hoverAxis !== null) return;
let is_canvas_click = Keybinds.extra.preview_select.keybind.isTriggered(event) || event.which === 0 || (Modes.paint && Keybinds.extra.paint_secondary_color.keybind.isTriggered(event));
let is_canvas_click = Keybinds.extra.preview_select.keybind.key == event.which || event.which === 0 || (Modes.paint && Keybinds.extra.paint_secondary_color.keybind.isTriggered(event));

var data = is_canvas_click && this.raycast(event);
if (data) {
Expand All @@ -770,6 +770,10 @@ class Preview {
let group_select = Keybinds.extra.preview_select.keybind.additionalModifierTriggered(event, 'group_select');
let loop_select = Keybinds.extra.preview_select.keybind.additionalModifierTriggered(event, 'loop_select');

if (Toolbox.selected.paintTool) {
multi_select = group_select = loop_select = false;
}

function unselectOtherNodes() {
if (Group.selected) Group.selected.unselect();
Outliner.elements.forEach(el => {
Expand Down
4 changes: 2 additions & 2 deletions js/preview/preview_scenes.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class PreviewScene {
Canvas.global_light_side = this.light_side;
scene.background = this.cubemap;
scene.fog = this.fog;
if (this.fov) {
if (this.fov && !(Modes.display && display_slot.startsWith('firstperson'))) {
Preview.selected.setFOV(this.fov);
}
// Update independent models
Expand All @@ -129,7 +129,7 @@ class PreviewScene {
Canvas.global_light_side = 0;
if (this.cubemap) scene.background = null;
if (this.fog) scene.fog = null;
if (this.fov) {
if (this.fov && !(Modes.display && display_slot.startsWith('firstperson'))) {
Preview.all.forEach(preview => preview.setFOV(settings.fov.value));
}
Blockbench.dispatchEvent('unselect_preview_scene', {scene: this});
Expand Down
10 changes: 5 additions & 5 deletions js/texturing/edit_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ BARS.defineActions(function() {
click() {
let textures = getTextures();
let original_image_data = textures.map(tex => {
let canvas = Painter.getCanvas(tex);
let image_data = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height);
let {canvas, ctx} = tex.getActiveCanvas();
let image_data = ctx.getImageData(0, 0, canvas.width, canvas.height);
image_data.original_data = image_data.data.slice();
return image_data;
})
Expand Down Expand Up @@ -342,13 +342,13 @@ BARS.defineActions(function() {
}

textures.forEach((texture, i) => {
texture.edit((canvas) => {
texture.edit((canvas, {offset}) => {
let ctx = canvas.getContext('2d');
let image_data = original_image_data[i];

if (this.preview_changes) {
for (let i = 0; i < image_data.data.length; i += 4) {
if (!texture.selection.allow((i/4) % image_data.width, Math.floor((i/4) / image_data.width))) continue;
if (!texture.selection.allow(offset[0] + (i/4) % image_data.width, offset[1] + Math.floor((i/4) / image_data.width))) continue;

let R = image_data.original_data[i+0]
let G = image_data.original_data[i+1]
Expand All @@ -370,7 +370,7 @@ BARS.defineActions(function() {
}
} else {
for (let i = 0; i < image_data.data.length; i += 4) {
if (!texture.selection.allow((i/4) % image_data.width, Math.floor((i/4) / image_data.width))) continue;
if (!texture.selection.allow(offset[0] + (i/4) % image_data.width, offset[1] + Math.floor((i/4) / image_data.width))) continue;
image_data.data[i+0] = image_data.original_data[i+0];
image_data.data[i+1] = image_data.original_data[i+1];
image_data.data[i+2] = image_data.original_data[i+2];
Expand Down
Loading

0 comments on commit e33736c

Please sign in to comment.