Skip to content

Commit 63e46c3

Browse files
committed
Enhance VRM UI and animation handling
- Added tabindex attribute to checkbox for improved accessibility. - Implemented a check to prevent toggling when the checkbox is disabled. - Ensured change event is dispatched after checkbox state update. - Updated comments in model_manager.js for clarity on idle animation loading and error handling during playback.
1 parent a3f6e33 commit 63e46c3

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

static/js/model_manager.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2205,10 +2205,28 @@ document.addEventListener('DOMContentLoaded', async () => {
22052205
}
22062206

22072207
// 使用 URL 加载模型,而不是本地文件路径(浏览器不允许加载 file:// 路径)
2208-
// 传入 { autoPlay: false } 让模型保持 T-Pose 静止
2208+
// 传入 { autoPlay: false } 以便在此处统一播放待机动画,避免先露出 T-pose
22092209
//增加 addShadow: false
22102210
// 【注意】朝向会自动从preferences中加载(在vrm-core.js的loadModel中处理)
22112211
await vrmManager.loadModel(modelUrl, { autoPlay: false, addShadow: false });
2212+
// 加载后立即播默认待机动画,避免 T-pose 显得生硬
2213+
const defaultIdleUrl = '/static/vrm/animation/wait03.vrma';
2214+
const idleSel = document.getElementById('idle-animation-select');
2215+
const idleUrl = (idleSel && idleSel.value) ? idleSel.value : defaultIdleUrl;
2216+
if (idleUrl && vrmManager.animation) {
2217+
try {
2218+
await vrmManager.playVRMAAnimation(idleUrl, { loop: true, immediate: true, isIdle: true });
2219+
} catch (e) {
2220+
console.warn('[VRM] 播放默认待机动画失败,使用内置默认:', e);
2221+
if (idleUrl !== defaultIdleUrl) {
2222+
try {
2223+
await vrmManager.playVRMAAnimation(defaultIdleUrl, { loop: true, immediate: true, isIdle: true });
2224+
} catch (e2) {
2225+
console.warn('[VRM] 播放 wait03 待机动画失败:', e2);
2226+
}
2227+
}
2228+
}
2229+
}
22122230
// 加载新模型后,重置播放状态
22132231
isVrmAnimationPlaying = false;
22142232
updateVRMAnimationPlayButtonIcon();

static/vrm-ui-popup.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ VRMManager.prototype._createSettingsToggleItem = function (toggle) {
10141014
border: '0'
10151015
});
10161016
checkbox.setAttribute('aria-hidden', 'true');
1017+
checkbox.setAttribute('tabindex', '-1');
10171018

10181019
if (toggle.id === 'merge-messages') {
10191020
if (typeof window.mergeMessagesEnabled !== 'undefined') {
@@ -1143,6 +1144,10 @@ VRMManager.prototype._createSettingsToggleItem = function (toggle) {
11431144
};
11441145

11451146
const performToggle = () => {
1147+
if (checkbox.disabled) {
1148+
return;
1149+
}
1150+
11461151
if (checkbox._processing) {
11471152
const elapsed = Date.now() - (checkbox._processingTime || 0);
11481153
if (elapsed < 500) {
@@ -1156,6 +1161,7 @@ VRMManager.prototype._createSettingsToggleItem = function (toggle) {
11561161
const newChecked = !checkbox.checked;
11571162
checkbox.checked = newChecked;
11581163
handleToggleChange(newChecked);
1164+
checkbox.dispatchEvent(new Event('change', { bubbles: true }));
11591165

11601166
setTimeout(() => {
11611167
checkbox._processing = false;

0 commit comments

Comments
 (0)