This commit is contained in:
2026-09-29 14:23:43 +02:00
parent b61142f9bd
commit f7c0c38ec2
2 changed files with 25 additions and 1 deletions
+4
View File
@@ -594,6 +594,7 @@
} }
function scaleCubeUvs(cube, x, y) { function scaleCubeUvs(cube, x, y) {
if (typeof Format === 'undefined' || Format?.id !== 'geckolib_model') return;
if (x === 1 && y === 1) return; if (x === 1 && y === 1) return;
if (cube.box_uv) { if (cube.box_uv) {
if (typeof cube.setUVMode !== 'function') throw new Error('Box UV conversion is unavailable in this Blockbench version.'); if (typeof cube.setUVMode !== 'function') throw new Error('Box UV conversion is unavailable in this Blockbench version.');
@@ -611,6 +612,7 @@
} }
function expandProjectUvs(width, height) { function expandProjectUvs(width, height) {
if (typeof Format === 'undefined' || Format?.id !== 'geckolib_model') return false;
const oldWidth = validUvDimension(Project.texture_width), oldHeight = validUvDimension(Project.texture_height); const oldWidth = validUvDimension(Project.texture_width), oldHeight = validUvDimension(Project.texture_height);
const nextWidth = Math.max(oldWidth, width), nextHeight = Math.max(oldHeight, height); const nextWidth = Math.max(oldWidth, width), nextHeight = Math.max(oldHeight, height);
if (nextWidth === oldWidth && nextHeight === oldHeight) return false; if (nextWidth === oldWidth && nextHeight === oldHeight) return false;
@@ -623,6 +625,7 @@
} }
function normalizeCubeUvs(cube, actorIndex, width, height, original = null) { function normalizeCubeUvs(cube, actorIndex, width, height, original = null) {
if (typeof Format === 'undefined' || Format?.id !== 'geckolib_model') return false;
width = validUvDimension(width); height = validUvDimension(height); width = validUvDimension(width); height = validUvDimension(height);
const all = getActorUvBasis(), actor = all[actorIndex]; const all = getActorUvBasis(), actor = all[actorIndex];
const key = cube.uuid || cube.name; const key = cube.uuid || cube.name;
@@ -641,6 +644,7 @@
} }
function normalizeActorUvs(actorIndex, width, height, original = null) { function normalizeActorUvs(actorIndex, width, height, original = null) {
if (typeof Format === 'undefined' || Format?.id !== 'geckolib_model') return false;
let changed = false; let changed = false;
for (const cube of Cube.all) { for (const cube of Cube.all) {
if (cubeBelongsToActor(cube, actorIndex)) changed = normalizeCubeUvs(cube, actorIndex, width, height, original) || changed; if (cubeBelongsToActor(cube, actorIndex)) changed = normalizeCubeUvs(cube, actorIndex, width, height, original) || changed;
+21 -1
View File
@@ -42,7 +42,7 @@ function harness() {
fromDataURL(url) { this.source = url; return this; } fromDataURL(url) { this.source = url; return this; }
add() { Texture.all.push(this); return this; } add() { Texture.all.push(this); return this; }
} }
const context = { Buffer, requireNativeModule: require, Group, Cube, Texture, console, const context = { Buffer, requireNativeModule: require, Group, Cube, Texture, console, Format: { id: 'geckolib_model' },
setTimeout(callback) { callback(); }, setTimeout(callback) { callback(); },
Undo: { initEdit() {}, finishEdit() {}, cancelEdit() {} }, Undo: { initEdit() {}, finishEdit() {}, cancelEdit() {} },
Project: { texture_width: 64, texture_height: 64, box_uv: true }, Project: { texture_width: 64, texture_height: 64, box_uv: true },
@@ -69,6 +69,26 @@ test('growing the project UV canvas preserves other actors and converts box UVs'
assert.deepEqual(Array.from(actor1.faces.north.uv), [0, 0, 64, 16], 'Repeated refreshes must not rescale UVs'); assert.deepEqual(Array.from(actor1.faces.north.uv), [0, 0, 64, 16], 'Repeated refreshes must not rescale UVs');
}); });
test('non-GeckoLib projects keep UVs, canvas dimensions and box UV mode while still assigning textures', () => {
for (const format of ['optifine_entity', 'optifine_part', 'bedrock', 'free', 'java_block']) {
const h = harness(), cube = new h.Cube('actor1_body', true);
h.context.Format.id = format;
const before = JSON.stringify(cube.faces.north.uv);
const texture = new h.Texture({ name: 'custom.png', uv_width: 128, uv_height: 128 });
texture.add();
assert.equal(h.expandProjectUvs(128, 128), false);
assert.equal(h.normalizeActorUvs(1, 128, 128), false);
h.scaleCubeUvs(cube, 2, 2);
h.applyActorTexturePreview(1, 'custom.png');
assert.equal(JSON.stringify(cube.faces.north.uv), before);
assert.equal(cube.faces.north.texture, texture.uuid);
assert.equal(cube.box_uv, true);
assert.equal(h.context.Project.texture_width, 64);
assert.equal(h.context.Project.texture_height, 64);
assert.equal(h.context.Project.animationdirector_actor_uv_basis, undefined);
}
});
test('assigning a manually imported texture to an actor normalizes only that actor once', () => { test('assigning a manually imported texture to an actor normalizes only that actor once', () => {
const h = harness(), selected = new h.Cube('actor1_body'), other = new h.Cube('actor2_body'); const h = harness(), selected = new h.Cube('actor1_body'), other = new h.Cube('actor2_body');
h.normalizeActorUvs(1, 64, 64); h.normalizeActorUvs(2, 64, 64); h.normalizeActorUvs(1, 64, 64); h.normalizeActorUvs(2, 64, 64);