From f7c0c38ec2b617e76c7257c1dfb9f0d7525409c5 Mon Sep 17 00:00:00 2001 From: L1Z0 <2grif484d@mozmail.com> Date: Tue, 29 Sep 2026 14:23:43 +0200 Subject: [PATCH] tweaks --- AnimationDirector.js | 4 ++++ test/uv-normalization.test.js | 22 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/AnimationDirector.js b/AnimationDirector.js index a7c8e17..35eba4f 100644 --- a/AnimationDirector.js +++ b/AnimationDirector.js @@ -594,6 +594,7 @@ } function scaleCubeUvs(cube, x, y) { + if (typeof Format === 'undefined' || Format?.id !== 'geckolib_model') return; if (x === 1 && y === 1) return; if (cube.box_uv) { 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) { + if (typeof Format === 'undefined' || Format?.id !== 'geckolib_model') return false; const oldWidth = validUvDimension(Project.texture_width), oldHeight = validUvDimension(Project.texture_height); const nextWidth = Math.max(oldWidth, width), nextHeight = Math.max(oldHeight, height); if (nextWidth === oldWidth && nextHeight === oldHeight) return false; @@ -623,6 +625,7 @@ } function normalizeCubeUvs(cube, actorIndex, width, height, original = null) { + if (typeof Format === 'undefined' || Format?.id !== 'geckolib_model') return false; width = validUvDimension(width); height = validUvDimension(height); const all = getActorUvBasis(), actor = all[actorIndex]; const key = cube.uuid || cube.name; @@ -641,6 +644,7 @@ } function normalizeActorUvs(actorIndex, width, height, original = null) { + if (typeof Format === 'undefined' || Format?.id !== 'geckolib_model') return false; let changed = false; for (const cube of Cube.all) { if (cubeBelongsToActor(cube, actorIndex)) changed = normalizeCubeUvs(cube, actorIndex, width, height, original) || changed; diff --git a/test/uv-normalization.test.js b/test/uv-normalization.test.js index 3df1b06..b2f916e 100644 --- a/test/uv-normalization.test.js +++ b/test/uv-normalization.test.js @@ -42,7 +42,7 @@ function harness() { fromDataURL(url) { this.source = url; 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(); }, Undo: { initEdit() {}, finishEdit() {}, cancelEdit() {} }, 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'); }); +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', () => { 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);