auto reapply textures when selecting texture
This commit is contained in:
@@ -34,7 +34,12 @@ function harness() {
|
||||
class Cube {
|
||||
static all = [];
|
||||
static preview_controller = {
|
||||
on(names, listener) { for (const name of names.split(' ')) previewEvents.set(name, listener); },
|
||||
on(names, listener) {
|
||||
for (const name of names.split(' ')) {
|
||||
const previous = previewEvents.get(name);
|
||||
previewEvents.set(name, (event) => { previous?.(event); listener(event); });
|
||||
}
|
||||
},
|
||||
};
|
||||
constructor(data) {
|
||||
Object.assign(this, data, { uuid: `cube-${++sequence}`, mesh: {},
|
||||
|
||||
@@ -8,7 +8,7 @@ const vm = require('node:vm');
|
||||
function harness() {
|
||||
const source = fs.readFileSync(path.join(__dirname, '..', 'AnimationDirector.js'), 'utf8').replace(
|
||||
' Plugin.register(PLUGIN_ID, {',
|
||||
' globalThis.uvTest = { normalizeActorUvs, expandProjectUvs, scaleCubeUvs, getActorUvBasis, tryLoadImportedActorTexture, applyActorTexturePreview, importGeometryIntoCurrentProject, applyAllActorTexturePreviews, setProjectActorTextures, setProjectBoneTextureOverrides };\n Plugin.register(PLUGIN_ID, {'
|
||||
' globalThis.uvTest = { normalizeActorUvs, expandProjectUvs, scaleCubeUvs, getActorUvBasis, tryLoadImportedActorTexture, applyActorTexturePreview, importGeometryIntoCurrentProject, applyAllActorTexturePreviews, setProjectActorTextures, setProjectBoneTextureOverrides, restoreActorTextureMaterial };\n Plugin.register(PLUGIN_ID, {'
|
||||
);
|
||||
class Group {
|
||||
static all = [];
|
||||
@@ -69,6 +69,35 @@ 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('preview material rebuild restores actor overrides without modifying faces or UVs', () => {
|
||||
const h = harness(), cube = new h.Cube('actor1_body');
|
||||
const material = {}, replacement = {};
|
||||
new h.Texture({ name: 'actor.png', material }).add();
|
||||
h.setProjectActorTextures({ 1: 'actor.png' });
|
||||
cube.mesh = { material: replacement };
|
||||
const before = JSON.stringify(cube.faces);
|
||||
h.restoreActorTextureMaterial({ element: cube });
|
||||
assert.equal(cube.mesh.material, material);
|
||||
assert.equal(JSON.stringify(cube.faces), before);
|
||||
const other = new h.Cube('actor2_body');
|
||||
other.mesh = { material: replacement };
|
||||
h.restoreActorTextureMaterial({ element: other });
|
||||
assert.equal(other.mesh.material, replacement);
|
||||
});
|
||||
|
||||
test('folder overrides take priority when restoring preview materials', () => {
|
||||
const h = harness(), cube = new h.Cube('actor1_body');
|
||||
const actorMaterial = {}, folderMaterial = {};
|
||||
new h.Texture({ name: 'actor.png', material: actorMaterial }).add();
|
||||
new h.Texture({ name: 'folder.png', material: folderMaterial }).add();
|
||||
cube.parent = new h.context.Group({ name: 'actor1_details', uuid: 'details' });
|
||||
cube.mesh = { material: {} };
|
||||
h.setProjectActorTextures({ 1: 'actor.png' });
|
||||
h.setProjectBoneTextureOverrides({ details: { uuid: 'details', name: 'actor1_details', texture: 'folder.png' } });
|
||||
h.restoreActorTextureMaterial({ element: cube });
|
||||
assert.equal(cube.mesh.material, folderMaterial);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user