auto reapply textures when selecting texture

This commit is contained in:
2026-10-01 02:04:46 +02:00
parent 8aa71244b6
commit 9241b35291
3 changed files with 57 additions and 3 deletions
+21 -1
View File
@@ -72,7 +72,7 @@
let importAction, replaceActorAction, importConjoinedAnimationAction, exportConjoinedAction, createAnimationDefinitionAction, actorPreferencesAction, boneTextureOverridesAction, exportGeckoModelAction;
let actorNamesProjectProperty, actorTexturesProjectProperty, actorUvBasisProjectProperty, boneTextureOverridesProjectProperty, actorAnimdefMetadataProjectProperty, animdefAnimatorsProjectProperty, animdefDefinitionsProjectProperty;
let actorTexturePreviewProjectListener;
const ACTOR_TEXTURE_PREVIEW_EVENTS = ['load_project', 'select_project', 'setup_project', 'load_from_recent_project_data', 'add_texture', 'change_texture_path'];
const ACTOR_TEXTURE_PREVIEW_EVENTS = ['load_project', 'select_project', 'setup_project', 'load_from_recent_project_data', 'add_texture', 'change_texture_path', 'select_texture'];
let actorTexturePreviewTimeouts = [];
// ----------------------------
@@ -1964,6 +1964,23 @@
return true;
}
function restoreActorTextureMaterial({ element } = {}) {
if (!Project || !element?.mesh || isBlockRequirementGuide(element)) return;
const override = getNearestBoneTextureOverride(element, getProjectBoneTextureOverrides());
let texture = override?.texture ? findTextureByActorTextureName(override.texture) : null;
if (!texture) {
let node = element;
let actorIndex;
while (node && !actorIndex) {
actorIndex = readActorIndexFromName(node.name);
node = node.parent;
}
if (actorIndex) texture = findTextureByActorTextureName(getProjectActorTextures()[actorIndex]);
}
// Only restore the preview material; do not rebuild faces or trigger another update.
if (texture) forceActorTextureMaterial(element, texture);
}
function applyTextureToCube(cube, texture) {
if (!cube || !texture) return;
@@ -7221,6 +7238,7 @@ Features without a reference need no additional addon. Whole-animation import an
});
actorTexturePreviewProjectListener = scheduleActorTexturePreviewApply;
Cube.preview_controller.on('setup update_faces', restoreActorTextureMaterial);
for (const eventName of ACTOR_TEXTURE_PREVIEW_EVENTS) {
Blockbench.on(eventName, actorTexturePreviewProjectListener);
}
@@ -7250,6 +7268,8 @@ Features without a reference need no additional addon. Whole-animation import an
if (propListener) for (const event of ['select_animation','select_project','load_project','unselect_project','undo','redo','render_frame']) Blockbench.removeListener(event, propListener);
propDialog = undefined; propListener = undefined;
clearScheduledActorTexturePreviewApplies();
Cube.preview_controller.removeListener('setup', restoreActorTextureMaterial);
Cube.preview_controller.removeListener('update_faces', restoreActorTextureMaterial);
if (actorTexturePreviewProjectListener) {
for (const eventName of ACTOR_TEXTURE_PREVIEW_EVENTS) {
Blockbench.removeListener(eventName, actorTexturePreviewProjectListener);