导入上游源码,为所有面向用户的品牌显示处添加「增强版 / Enhanced」标识;包含 unitypackage→VRM 的纯色 Toon 材质、兽耳 SpringBone、Unity 描边、UV 接缝白边补偿修复,以及默认不强制 T-pose。146 个单元测试通过。
This commit is contained in:
+231
@@ -0,0 +1,231 @@
|
||||
:root {
|
||||
--left-w: 440px; --side-w: 300px; --side-wide-w: 380px;
|
||||
--bg: #f3f4f7; --card: #ffffff; --text: #1d2026; --muted: #6b7380; --line: #e3e6eb; --hover: #f2f4f8;
|
||||
--accent: #3a6ee8; --accent-soft: #e9f0fd; --ok: #1f9d55; --warn: #c27c0e; --err: #d64545;
|
||||
--viewport: #8a8f98; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
|
||||
}
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root { --bg: #15171b; --card: #1e2126; --text: #e6e8eb; --muted: #98a1ad; --line: #2e3238; --hover: #262a30;
|
||||
--accent: #7aa2ff; --accent-soft: #24324f; --ok: #45c47a; --warn: #e2a33a; --err: #f07272; --viewport: #3a3d43;
|
||||
--shadow: none; }
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
[hidden] { display: none !important; }
|
||||
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
|
||||
font: 13px/1.45 "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", "Segoe UI", system-ui, sans-serif; }
|
||||
body { display: flex; flex-direction: column; overflow: hidden; }
|
||||
button { font: inherit; color: inherit; }
|
||||
h2 { font-size: 13px; margin: 0; font-weight: 600; }
|
||||
h3 { font-size: 12px; margin: 14px 0 4px; color: var(--muted); font-weight: 600; }
|
||||
|
||||
/* top bar */
|
||||
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px;
|
||||
background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
|
||||
.brand { font-weight: 700; font-size: 14px; letter-spacing: .02em; }
|
||||
.logo { color: var(--accent); }
|
||||
.enh { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 1px 5px; margin-left: 4px; vertical-align: 1px; }
|
||||
.ver { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 4px; }
|
||||
|
||||
.layout { flex: 1; display: flex; min-height: 0; }
|
||||
.mode-note { flex: none; padding: 6px 16px; font-size: 12px; background: var(--accent-soft); color: var(--text, inherit);
|
||||
border-bottom: 1px solid var(--line); }
|
||||
.mode-note b { color: var(--warn); }
|
||||
.mode-note a { color: var(--accent); }
|
||||
/* left column: settings scroll, the run bar stays at the bottom */
|
||||
.left { width: var(--left-w); flex: none; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
|
||||
.left-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 12px; }
|
||||
.right { flex: 1; display: flex; flex-direction: column; min-width: 0; }
|
||||
|
||||
/* cards */
|
||||
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
|
||||
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px 8px; margin-bottom: 8px; flex-wrap: wrap; }
|
||||
.card-head h2 { white-space: nowrap; }
|
||||
.card-head .actions { display: flex; gap: 6px; }
|
||||
.log-card .card-head { margin-bottom: 0; }
|
||||
|
||||
/* buttons */
|
||||
.btn { background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
|
||||
.btn:hover { background: var(--hover); }
|
||||
.btn.ghost { border-color: transparent; color: var(--muted); }
|
||||
.btn.small { padding: 2px 8px; font-size: 12px; }
|
||||
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; padding: 7px 16px; }
|
||||
.btn.primary:disabled { opacity: .5; cursor: default; }
|
||||
.link { background: none; border: none; cursor: pointer; padding: 0; font-weight: 600; }
|
||||
.icon { background: none; border: none; cursor: pointer; color: var(--muted); padding: 2px 5px; border-radius: 5px; font-size: 12px; }
|
||||
.icon:hover { background: var(--hover); color: var(--text); }
|
||||
|
||||
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; flex-wrap: wrap; }
|
||||
.seg button { border: none; background: transparent; padding: 4px 10px; cursor: pointer; }
|
||||
.seg button + button { border-left: 1px solid var(--line); }
|
||||
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
|
||||
.seg.small button { padding: 2px 8px; font-size: 12px; }
|
||||
.tabs { display: inline-flex; gap: 2px; }
|
||||
.tabs button { border: none; background: none; padding: 3px 9px; border-radius: 6px; cursor: pointer; color: var(--muted); white-space: nowrap; }
|
||||
.tabs button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
|
||||
|
||||
/* form */
|
||||
.field { display: flex; align-items: center; gap: 8px; margin: 7px 0; }
|
||||
.field > label { width: 92px; flex: none; color: var(--muted); }
|
||||
.field input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); }
|
||||
.field output { width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
|
||||
.seg.nowrap { flex-wrap: nowrap; flex: none; }
|
||||
.input.jobs-num { flex: none; width: 64px; }
|
||||
.input.jobs-num:disabled { color: var(--muted); }
|
||||
.switch { display: flex; align-items: center; gap: 7px; margin: 6px 0; cursor: pointer; }
|
||||
.switch input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
|
||||
.switch.sub, .field.sub { margin-left: 22px; }
|
||||
.switch.small { margin: 0; font-size: 12px; }
|
||||
.hint { color: var(--muted); font-size: 12px; margin: -4px 0 4px 22px; }
|
||||
.grid2 { display: grid; grid-template-columns: 1fr 1fr; column-gap: 8px; }
|
||||
.folder-row .path { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted);
|
||||
border: 1px dashed var(--line); border-radius: 6px; padding: 3px 8px; }
|
||||
.input { flex: 1; min-width: 0; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font: inherit; }
|
||||
|
||||
/* files */
|
||||
.drop { border: 1.5px dashed var(--line); border-radius: 8px; padding: 18px 10px; text-align: center; color: var(--muted); cursor: pointer; }
|
||||
.drop.compact { padding: 6px; font-size: 12px; }
|
||||
.drop.over, body.dragging .drop { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
|
||||
.file-list { list-style: none; margin: 8px 0 0; padding: 0; max-height: 300px; overflow-y: auto; }
|
||||
.file-list:empty::before { content: attr(data-empty); display: block; color: var(--muted); text-align: center; padding: 6px; font-size: 12px; }
|
||||
.file { border-radius: 7px; padding: 6px 6px 6px 8px; }
|
||||
.file:hover { background: var(--hover); }
|
||||
.file.current { background: var(--accent-soft); }
|
||||
.file .row1 { display: flex; align-items: center; gap: 6px; }
|
||||
.file .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.kind { font-size: 10px; text-transform: uppercase; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
|
||||
.chip { font-size: 11px; border-radius: 10px; padding: 0 7px; background: var(--hover); color: var(--muted); white-space: nowrap; }
|
||||
.chip.running { background: var(--accent-soft); color: var(--accent); }
|
||||
.chip.done { color: var(--ok); }
|
||||
.chip.error { color: var(--err); }
|
||||
.file .outs { margin: 3px 0 0 4px; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 2px 10px; }
|
||||
.file .outs a { color: var(--accent); cursor: pointer; text-decoration: none; }
|
||||
.file .err { color: var(--err); font-size: 12px; margin: 2px 0 0 4px; word-break: break-all; }
|
||||
.file .note { color: var(--muted); font-size: 12px; margin: 2px 0 0 4px; }
|
||||
|
||||
/* run bar */
|
||||
.runbar { flex: none; display: grid; grid-template-columns: auto 1fr auto; /* start or stop · status · open output */ align-items: center; gap: 6px 10px; padding: 10px 12px;
|
||||
background: var(--card); border-top: 1px solid var(--line); }
|
||||
.progress { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
|
||||
.progress div { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
|
||||
.status { color: var(--muted); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.badge { background: var(--err); color: #fff; border-radius: 8px; padding: 0 6px; font-size: 11px; font-weight: 600; }
|
||||
.caret { display: inline-block; transition: transform .15s; }
|
||||
.log-card.open .caret { transform: rotate(90deg); }
|
||||
.log { margin: 8px 0 0; max-height: 260px; overflow: auto; font: 11.5px/1.5 Consolas, "Cascadia Mono", monospace; white-space: pre-wrap; word-break: break-all; }
|
||||
.log .ok { color: var(--ok); } .log .warn { color: var(--warn); } .log .err { color: var(--err); }
|
||||
.log .head { font-weight: 700; } .log .info { color: var(--muted); }
|
||||
.log .file-mark { color: var(--accent); margin-top: 2px; }
|
||||
|
||||
/* preview */
|
||||
.pv-toolbar { display: flex; align-items: center; gap: 8px; padding: 7px 12px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
|
||||
.pv-title { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.spacer { flex: 1; }
|
||||
.btn.on { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); font-weight: 600; }
|
||||
.stage { flex: 1; display: flex; min-height: 0; }
|
||||
.pv { flex: 1; position: relative; background: var(--viewport); min-height: 0; min-width: 0; }
|
||||
.pv canvas { position: absolute; inset: 0; }
|
||||
.pv-empty, .pv-busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
|
||||
color: #fff; text-shadow: 0 1px 3px #0008; pointer-events: none; font-size: 14px; }
|
||||
.pv-busy { background: #0003; }
|
||||
/* skeleton overlay: legend (bone roles with counts) and the hovered bone */
|
||||
.pv-legend { position: absolute; left: 10px; bottom: 10px; padding: 6px 10px; border-radius: 6px; background: #000a; color: #fff;
|
||||
font-size: 12px; line-height: 1.7; pointer-events: none; }
|
||||
.pv-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 0; }
|
||||
.pv-legend b { font-weight: 600; margin-left: 6px; }
|
||||
.pv-tip { position: absolute; padding: 4px 8px; border-radius: 4px; background: #000c; color: #fff; font-size: 12px;
|
||||
line-height: 1.5; pointer-events: none; white-space: nowrap; transform: translate(12px, 12px); }
|
||||
.pv-tip .k { opacity: 0.75; }
|
||||
.pv-hint { position: absolute; right: 10px; bottom: 8px; color: #fff; opacity: 0.6; font-size: 11px;
|
||||
text-shadow: 0 1px 2px #0009; pointer-events: none; }
|
||||
/* tune panel: chain rows with keep-shown / focus buttons */
|
||||
.chain-head { display: flex; align-items: center; gap: 2px; }
|
||||
.chain-head .switch { flex: 1; min-width: 0; }
|
||||
.ibtn { flex: none; width: 24px; height: 22px; padding: 0; border: 1px solid transparent; border-radius: 4px;
|
||||
background: none; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
|
||||
.ibtn:hover { background: var(--accent-soft); color: var(--accent); }
|
||||
.ibtn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
|
||||
.ibtn svg { width: 15px; height: 15px; }
|
||||
.chain.pinned { box-shadow: inset 3px 0 0 var(--accent); padding-left: 4px; }
|
||||
.spinner { width: 18px; height: 18px; border: 2px solid #fff6; border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
|
||||
@keyframes spin { to { transform: rotate(360deg); } }
|
||||
/* side column next to the preview (one panel at a time) */
|
||||
.side { width: var(--side-w); flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--card);
|
||||
border-left: 1px solid var(--line); }
|
||||
.side.wide { width: var(--side-wide-w); }
|
||||
/* drag handles between the columns (double-click resets) */
|
||||
.splitter { width: 6px; margin: 0 -3px; flex: none; cursor: col-resize; position: relative; z-index: 5; }
|
||||
.splitter::after { content: ""; position: absolute; top: 0; bottom: 0; left: 2px; width: 2px; background: transparent; transition: background .15s; }
|
||||
.splitter:hover::after, .splitter.dragging::after { background: var(--accent); }
|
||||
body.resizing { cursor: col-resize; user-select: none; }
|
||||
body.resizing .pv canvas { pointer-events: none; }
|
||||
/* narrow windows (the app allows 1000 px): give the preview more of the width */
|
||||
@media (max-width: 1200px) {
|
||||
:root { --left-w: 360px; --side-w: 260px; --side-wide-w: 330px; }
|
||||
.pv-title { max-width: 140px; }
|
||||
}
|
||||
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px 12px; overflow-y: auto; }
|
||||
.panel .field > label { width: 64px; }
|
||||
.expr-list { overflow-y: auto; flex: 1; min-height: 0; }
|
||||
.expr-list .field > label { width: 110px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.swatches { display: flex; gap: 6px; margin: 6px 0 2px; }
|
||||
.swatches button { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); cursor: pointer; padding: 0; }
|
||||
.swatches button.on { outline: 2px solid var(--accent); outline-offset: 1px; }
|
||||
.info { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 2px 0; font-size: 12px; }
|
||||
.info dt { color: var(--muted); } .info dd { margin: 0; font-variant-numeric: tabular-nums; }
|
||||
|
||||
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); background: #000c; color: #fff; padding: 6px 14px;
|
||||
border-radius: 8px; font-size: 12px; opacity: 0; transition: opacity .3s; pointer-events: none; max-width: 80vw; }
|
||||
.toast.show { opacity: 1; }
|
||||
|
||||
/* metadata tab / texture hint */
|
||||
.hint.flush { margin-left: 0; }
|
||||
.dim { opacity: .45; }
|
||||
.hint.warn { color: var(--warn); }
|
||||
.tab-body[data-panel=meta] .field > label { width: 80px; }
|
||||
.tab-body[data-panel=main] .field > label { width: 72px; }
|
||||
/* settings: Advanced fold, per-format sections, options that only apply to one target */
|
||||
details.adv { border-top: 1px solid var(--line); border-bottom: none; margin-top: 10px; padding-bottom: 0; }
|
||||
details.adv > summary { font-weight: 600; color: var(--text); }
|
||||
details.adv h3:first-of-type { margin-top: 6px; }
|
||||
.settings-card.pmx .vrm-only, .settings-card:not(.pmx) .pmx-only, .settings-card.pmx .pmx-hidden { display: none; }
|
||||
.fmt h3 { margin-top: 10px; }
|
||||
#metaReset { margin-top: 10px; }
|
||||
|
||||
/* tune panel */
|
||||
#tunePanel { overflow: hidden; }
|
||||
.tune-body { overflow-y: auto; flex: 1; min-height: 0; margin: 0 -4px; padding: 0 4px; }
|
||||
details.sec { border-bottom: 1px solid var(--line); padding: 2px 0 6px; }
|
||||
details.sec details.sec { border: none; padding: 0; }
|
||||
details.sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 6px; margin: 8px 0 4px;
|
||||
font-size: 12px; font-weight: 600; color: var(--muted); }
|
||||
details.sec > summary::-webkit-details-marker { display: none; }
|
||||
details.sec > summary::before { content: "▸"; display: inline-block; transition: transform .15s; }
|
||||
details.sec[open] > summary::before { transform: rotate(90deg); }
|
||||
details.sec > summary:hover { color: var(--text); }
|
||||
.tune-body .field > label { width: 96px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.tune-body select { flex: 1; min-width: 0; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 2px 4px; font: inherit; }
|
||||
.tune-body select.changed, .tune-body input.changed { border-color: var(--accent); }
|
||||
.tune-body .field.preset > label { width: 60px; }
|
||||
.tune-body .field.preset { gap: 6px; }
|
||||
.tune-body .field.preset.missing select { color: var(--muted); font-style: italic; }
|
||||
.tune-body input.strength { flex: none; width: 56px; }
|
||||
.tune-body output.strength { width: 36px; }
|
||||
.tune-body input.strength.changed { accent-color: var(--accent); filter: saturate(1.6); }
|
||||
.tune-msg { color: var(--muted); padding: 12px 2px; }
|
||||
.thumb-row { display: flex; align-items: center; gap: 8px; }
|
||||
.thumb-row img, .thumb-row .noimg { width: 64px; height: 64px; border-radius: 6px; border: 1px solid var(--line); object-fit: cover; flex: none;
|
||||
display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }
|
||||
.thumb-row .col { display: flex; flex-direction: column; gap: 4px; }
|
||||
.chain { border-top: 1px solid var(--line); padding: 4px 0; }
|
||||
.chain .switch { margin: 2px 0; }
|
||||
.chain .switch span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.chain .field { margin: 2px 0 2px 22px; }
|
||||
.chain .field > label { width: 40px; color: var(--muted); }
|
||||
.chain.off .field { display: none; }
|
||||
.chain-list { margin-top: 4px; }
|
||||
.tune-foot { display: flex; align-items: center; gap: 6px; padding-top: 8px; border-top: 1px solid var(--line); margin-top: 6px; }
|
||||
.tune-foot .muted { flex: 1; color: var(--muted); font-size: 12px; }
|
||||
.chip.tuned { background: var(--accent-soft); color: var(--accent); }
|
||||
.mini { background: none; border: 1px solid var(--line); border-radius: 5px; cursor: pointer; padding: 0 5px; font-size: 11px; color: var(--muted); }
|
||||
.mini:hover { color: var(--text); background: var(--hover); }
|
||||
.tune-foot .btn.primary { padding: 2px 10px; font-weight: 600; }
|
||||
@@ -0,0 +1,95 @@
|
||||
// VRMify Enhanced UI entry. Talks to ui/server.py over HTTP (same API in the pywebview window and a browser).
|
||||
// core.js shared state, i18n, api
|
||||
// files.js file list options.js conversion settings
|
||||
// run.js run bar + log preview.js 3D preview, toolbar, side column
|
||||
// tune.js tune panel (per-model adjustments written into the VRM)
|
||||
// layout.js drag handles for the column widths
|
||||
import { $, S, api, errText, esc, pick, t, toast } from './core.js';
|
||||
import { renderFiles } from './files.js';
|
||||
import { applyOptsToForm, renderOutFolder, syncDependents } from './options.js';
|
||||
import { appendLog, relocalizeLog, renderStatus } from './run.js';
|
||||
import { applyLayout } from './layout.js';
|
||||
import { fillPreviewPanels, loadModel, previewFile, showBusy, viewer } from './preview.js';
|
||||
import { T, loadTune, renderTune } from './tune.js';
|
||||
import { queueThumb, setOnThumb } from './thumbs.js';
|
||||
|
||||
function applyLang() {
|
||||
document.documentElement.lang = S.lang === 'en' ? 'en' : 'zh-CN';
|
||||
document.querySelectorAll('[data-i18n]').forEach((e) => { e.textContent = t(e.dataset.i18n); });
|
||||
document.querySelectorAll('[data-i18n-ph]').forEach((e) => { e.placeholder = t(e.dataset.i18nPh); });
|
||||
document.querySelectorAll('[data-i18n-title]').forEach((e) => { e.title = t(e.dataset.i18nTitle); });
|
||||
document.querySelectorAll('[data-lang]').forEach((b) => b.classList.toggle('on', b.dataset.lang === S.lang));
|
||||
$('fileList').dataset.empty = t('empty');
|
||||
renderModeNote();
|
||||
renderStatus(); renderOutFolder(); syncDependents(); relocalizeLog();
|
||||
fillPreviewPanels(viewer.info);
|
||||
if (!$('tunePanel').hidden) renderTune();
|
||||
}
|
||||
// why the app runs in the browser instead of its own window (ui/app.py), with what still works there
|
||||
function renderModeNote() {
|
||||
const n = S.modeNote, box = $('modeNote');
|
||||
box.hidden = S.native || !n;
|
||||
if (box.hidden) return;
|
||||
const link = n.kind === 'no_webview2'
|
||||
? ` <a href="https://developer.microsoft.com/microsoft-edge/webview2/" target="_blank" rel="noopener">${esc(t('getWebView2'))}</a>` : '';
|
||||
box.innerHTML = `<b>${esc(t('browserMode'))}</b> ${esc(pick(n.zh, n.en))}${link} ${esc(t('browserModeHint', { log: n.log }))}`;
|
||||
}
|
||||
|
||||
document.querySelectorAll('[data-lang]').forEach((b) => b.addEventListener('click', () => {
|
||||
S.lang = b.dataset.lang; applyLang(); api('/api/options', { lang: S.lang });
|
||||
}));
|
||||
|
||||
async function loadState() {
|
||||
const st = await api('/api/state');
|
||||
Object.assign(S, { files: st.files, opts: st.opts, lang: st.lang, busy: st.busy, seq: st.seq, native: st.native,
|
||||
features: st.features || {}, appOut: st.app_out || '', ui: st.ui || {}, modeNote: st.mode_note || null });
|
||||
applyLayout();
|
||||
$('ver').textContent = st.version ? 'v' + st.version : '';
|
||||
applyOptsToForm();
|
||||
applyLang();
|
||||
}
|
||||
|
||||
function handleEvent(ev) {
|
||||
if (ev.type === 'log') appendLog(ev.msg, ev.tag, ev.file, ev.en);
|
||||
else if (ev.type === 'file') {
|
||||
const i = S.files.findIndex((f) => f.id === ev.file.id);
|
||||
const was = i >= 0 ? S.files[i].status : null;
|
||||
if (i >= 0) S.files[i] = ev.file; else S.files.push(ev.file);
|
||||
renderFiles();
|
||||
// a file just finished converting → open it in the preview: the first one of each run (unless the Tune
|
||||
// panel has unsaved changes for the model on screen), and the one already on screen (show the real output)
|
||||
if (ev.file.status === 'done' && was === 'running') queueThumb(ev.file);
|
||||
if (ev.file.status === 'done' && was !== 'done' && ev.file.outputs.some((o) => o.url || o.previewable)) {
|
||||
const first = !S.autoOpened && !(T.dirty && T.fid === S.current && ev.file.id !== S.current);
|
||||
if (first) S.autoOpened = true;
|
||||
if (first || ev.file.id === S.current) previewFile(ev.file.id);
|
||||
}
|
||||
} else if (ev.type === 'files') loadState();
|
||||
else if (ev.type === 'busy') {
|
||||
S.busy = ev.busy;
|
||||
if (ev.busy) S.autoOpened = false;
|
||||
else { S.progress = null; S.result = { done: ev.done, failed: ev.failed, skipped: ev.skipped || 0 }; }
|
||||
renderStatus();
|
||||
} else if (ev.type === 'progress') { S.progress = ev; renderStatus(); }
|
||||
else if (ev.type === 'preview_busy') { if (ev.file === S.current) showBusy(t('pvMaking')); }
|
||||
else if (ev.type === 'preview') {
|
||||
if (ev.file !== S.current) return;
|
||||
if (ev.error) { showBusy(null); toast(t('pvFailed', { err: errText(ev.error, ev.error_en) })); } else { loadModel(ev.url, ev.name); loadTune(); }
|
||||
}
|
||||
}
|
||||
|
||||
// an automatic thumbnail was written: refresh the Tune panel when it shows that file (and has nothing unsaved)
|
||||
setOnThumb((id) => { if (T.fid === id && !$('tunePanel').hidden && !T.dirty) loadTune(); });
|
||||
|
||||
async function pollEvents() {
|
||||
for (;;) {
|
||||
try {
|
||||
const r = await api('/api/events?after=' + S.seq);
|
||||
for (const ev of r.events) { S.seq = Math.max(S.seq, ev.seq); handleEvent(ev); }
|
||||
} catch (e) { await new Promise((res) => setTimeout(res, 1500)); }
|
||||
}
|
||||
}
|
||||
|
||||
await loadState();
|
||||
pollEvents();
|
||||
window.__app = { S, T, viewer, previewFile };
|
||||
@@ -0,0 +1,43 @@
|
||||
// Shared state and helpers for the UI modules (files / options / run / preview / tune).
|
||||
import { STRINGS } from './i18n.js';
|
||||
|
||||
export const $ = (id) => document.getElementById(id);
|
||||
|
||||
// App state mirrored from ui/server.py (/api/state + events), plus UI-only bits.
|
||||
export const S = {
|
||||
files: [], opts: {}, lang: 'zh_CN', busy: false, seq: 0, native: false, features: {}, appOut: '',
|
||||
current: null, // file id shown in the preview
|
||||
logErrors: 0, progress: null, result: null,
|
||||
autoOpened: false, // first file of a run already opened in the preview
|
||||
autoTune: false, // open the tune panel by itself once the model on screen can be tuned
|
||||
ui: {}, // column widths from settings.json (layout.js)
|
||||
};
|
||||
|
||||
export function t(key, args) {
|
||||
let s = (STRINGS[S.lang] || STRINGS.zh_CN)[key] ?? key;
|
||||
for (const [k, v] of Object.entries(args || {})) s = s.replaceAll('{' + k + '}', v);
|
||||
return s;
|
||||
}
|
||||
export const presetLabel = (p) => ((STRINGS[S.lang] || STRINGS.zh_CN).preset || {})[p] || p;
|
||||
|
||||
// Text from the server comes in Chinese, with an English version next to it when there is one
|
||||
// (log lines, conversion errors: convert/logtext.py)
|
||||
export const pick = (zh, en) => (S.lang === 'en' && en) || zh;
|
||||
// an error from the server: a few fixed codes have their own strings, the rest come as zh + English version
|
||||
const ERR = { 'no such file': 'errNoFile', 'not previewable': 'errNoPreview', 'file not found': 'errNotFound' };
|
||||
export const errText = (e, en) => (ERR[e] ? t(ERR[e]) : pick(e, en));
|
||||
|
||||
export async function api(path, body) {
|
||||
const r = await fetch(path, body === undefined ? {} : { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
||||
return r.json();
|
||||
}
|
||||
|
||||
export function toast(s) {
|
||||
const e = $('toast');
|
||||
e.textContent = s; e.classList.add('show');
|
||||
clearTimeout(toast._t); toast._t = setTimeout(() => e.classList.remove('show'), 3000);
|
||||
}
|
||||
|
||||
export const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
|
||||
export const clone = (o) => JSON.parse(JSON.stringify(o || {}));
|
||||
export const num = (v, d) => (typeof v === 'number' && isFinite(v) ? v : d);
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
// File list: add / remove, per-file status and outputs, drag & drop.
|
||||
import { $, S, api, esc, pick, t, toast } from './core.js';
|
||||
import { loadModel, previewFile } from './preview.js';
|
||||
import { T, leaveTune, loadTune } from './tune.js';
|
||||
|
||||
const fmtSize = (n) => n > 1048576 ? (n / 1048576).toFixed(1) + ' MB' : Math.max(1, Math.round(n / 1024)) + ' KB';
|
||||
|
||||
export function renderFiles() {
|
||||
const ul = $('fileList');
|
||||
ul.innerHTML = '';
|
||||
for (const f of S.files) {
|
||||
const li = document.createElement('li');
|
||||
li.className = 'file' + (f.id === S.current ? ' current' : '');
|
||||
const btn = (act, icon, key) => `<button class="icon" data-act="${act}" title="${esc(t(key))}" aria-label="${esc(t(key))}">${icon}</button>`;
|
||||
li.innerHTML = `<div class="row1"><span class="kind">${f.kind}</span>
|
||||
<span class="name" title="${esc(f.path)} · ${fmtSize(f.size)}">${esc(f.name)}</span>
|
||||
${f.tuned ? `<span class="chip tuned" title="${esc(t('tuned'))}">✎</span>` : ''}<span class="chip ${f.status}">${t('st_' + f.status)}</span>
|
||||
${btn('preview', '👁', 'preview')}${btn('reveal', '📂', 'reveal')}${btn('remove', '✕', 'remove')}</div>`;
|
||||
if (f.outputs.length) {
|
||||
const d = document.createElement('div'); d.className = 'outs';
|
||||
d.innerHTML = t('outputs') + ':' + f.outputs.map((o, k) => `<a data-out="${k}" title="${esc(o.path)}">${esc(o.name)}</a>`).join('');
|
||||
li.append(d);
|
||||
}
|
||||
if (f.error) { const d = document.createElement('div'); d.className = 'err'; d.textContent = pick(f.error, f.error_en); li.append(d); }
|
||||
if (f.status === 'skipped') { const d = document.createElement('div'); d.className = 'note'; d.textContent = t('skippedNote'); li.append(d); }
|
||||
li.addEventListener('click', (e) => {
|
||||
const act = e.target.dataset.act, out = e.target.dataset.out;
|
||||
if (act === 'remove') api('/api/remove', { ids: [f.id] });
|
||||
else if (act === 'reveal') api('/api/open', { path: f.outputs.length ? f.outputs[f.outputs.length - 1].path : f.path });
|
||||
else if (out !== undefined) {
|
||||
const o = f.outputs[+out];
|
||||
if (!leaveTune(f.id)) return;
|
||||
if (o.url) { S.current = f.id; renderFiles(); loadModel(o.url, o.name); if (!T.dirty) loadTune(); }
|
||||
else if (o.previewable) previewFile(f.id, +out);
|
||||
else api('/api/open', { path: o.path });
|
||||
} else previewFile(f.id);
|
||||
});
|
||||
ul.append(li);
|
||||
}
|
||||
$('drop').classList.toggle('compact', S.files.length > 0);
|
||||
$('drop').firstElementChild.textContent = t(S.files.length ? 'dropHintShort' : 'dropHint');
|
||||
const conv = S.files.filter((f) => f.kind !== 'vrm' && f.status !== 'running');
|
||||
const todo = conv.filter((f) => f.status === 'pending' || f.status === 'error').length;
|
||||
const n = todo || conv.length; // nothing left to convert → the button converts everything again
|
||||
$('startLabel').textContent = t(todo || !n ? 'start' : 'restart');
|
||||
$('startCount').textContent = n ? `(${n})` : '';
|
||||
$('start').disabled = S.busy || !n;
|
||||
}
|
||||
|
||||
// In the pywebview window files come with their paths: the native dialog (/api/pick) and the backend's own drop
|
||||
// handler (ui/app.py). A plain browser never shows the page a path, so there the files are uploaded to the local
|
||||
// program instead (into a temp folder, folders keep their structure so a PMX still finds its textures) and added
|
||||
// from there (/api/upload, /api/upload/done).
|
||||
const pickFiles = () => (S.native ? api('/api/pick', { folder: false }) : $('upFiles').click());
|
||||
$('addFiles').onclick = pickFiles;
|
||||
$('drop').onclick = pickFiles;
|
||||
$('addFolder').onclick = () => (S.native ? api('/api/pick', { folder: true }) : $('upFolder').click());
|
||||
$('clearFiles').onclick = () => api('/api/clear', {});
|
||||
|
||||
// a group = what ends up in one upload folder: one dropped / picked folder, or all loose files of one drop / pick
|
||||
// (together, so a PMX dropped with its textures finds them). key: same content → same folder on every upload.
|
||||
async function groupKey(files) {
|
||||
const s = files.map((x) => `${x.rel}|${x.file.size}|${x.file.lastModified}`).sort().join('\n');
|
||||
const h = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(s));
|
||||
return [...new Uint8Array(h)].map((b) => b.toString(16).padStart(2, '0')).join('');
|
||||
}
|
||||
|
||||
async function upload(groups) {
|
||||
groups = groups.filter((g) => g.files.length);
|
||||
const total = groups.reduce((n, g) => n + g.files.length, 0);
|
||||
if (!total) return;
|
||||
let done = 0, failed = 0;
|
||||
const items = [];
|
||||
for (const g of groups) {
|
||||
const key = await groupKey(g.files);
|
||||
for (const x of g.files) {
|
||||
toast(t('uploading', { i: ++done, n: total, name: x.file.name }));
|
||||
try {
|
||||
const r = await (await fetch(`/api/upload?key=${encodeURIComponent(key)}&path=${encodeURIComponent(x.rel)}`,
|
||||
{ method: 'POST', body: x.file })).json();
|
||||
if (r.error) failed++;
|
||||
} catch (e) { failed++; }
|
||||
}
|
||||
items.push({ key, roots: g.roots });
|
||||
}
|
||||
const r = await api('/api/upload/done', { items });
|
||||
toast(failed ? t('uploadFailed', { n: failed }) : t('uploaded', { n: (r.added || []).length }));
|
||||
}
|
||||
|
||||
// files from <input type=file>: loose files are one group; with webkitdirectory each file carries its folder path
|
||||
function fromInput(list) {
|
||||
const loose = { roots: [], files: [] }, dirs = {};
|
||||
for (const file of list) {
|
||||
const rel = file.webkitRelativePath || file.name, top = rel.split('/')[0];
|
||||
if (rel === file.name) { loose.files.push({ file, rel }); loose.roots.push(file.name); continue; }
|
||||
(dirs[top] ||= { roots: [top], files: [] }).files.push({ file, rel });
|
||||
}
|
||||
return [loose, ...Object.values(dirs)];
|
||||
}
|
||||
for (const id of ['upFiles', 'upFolder']) {
|
||||
$(id).addEventListener('change', (e) => { const g = fromInput(e.target.files); e.target.value = ''; upload(g); });
|
||||
}
|
||||
|
||||
// dropped items: folders are walked with the entries API (readEntries returns at most 100 at a time)
|
||||
const entryFile = (en) => new Promise((res, rej) => en.file(res, rej));
|
||||
async function walk(entry, prefix, out) {
|
||||
if (entry.isFile) { out.push({ file: await entryFile(entry), rel: prefix + entry.name }); return; }
|
||||
const reader = entry.createReader();
|
||||
for (;;) {
|
||||
const batch = await new Promise((res, rej) => reader.readEntries(res, rej));
|
||||
if (!batch.length) break;
|
||||
for (const en of batch) await walk(en, prefix + entry.name + '/', out);
|
||||
}
|
||||
}
|
||||
async function fromDrop(dt) {
|
||||
// entries have to be taken while the drop event is running; reading them can wait
|
||||
const got = [...(dt.items || [])].filter((it) => it.kind === 'file')
|
||||
.map((it) => ({ entry: it.webkitGetAsEntry ? it.webkitGetAsEntry() : null, file: it.getAsFile() }));
|
||||
const loose = { roots: [], files: [] }, groups = [loose];
|
||||
for (const { entry, file } of got) {
|
||||
if (entry && entry.isDirectory) {
|
||||
const g = { roots: [entry.name], files: [] };
|
||||
await walk(entry, '', g.files);
|
||||
groups.push(g);
|
||||
} else if (file) { loose.files.push({ file, rel: file.name }); loose.roots.push(file.name); }
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
let dragDepth = 0;
|
||||
window.addEventListener('dragenter', (e) => { e.preventDefault(); dragDepth++; document.body.classList.add('dragging'); });
|
||||
window.addEventListener('dragleave', () => { if (--dragDepth <= 0) { dragDepth = 0; document.body.classList.remove('dragging'); } });
|
||||
window.addEventListener('dragover', (e) => e.preventDefault());
|
||||
window.addEventListener('drop', (e) => {
|
||||
e.preventDefault(); dragDepth = 0; document.body.classList.remove('dragging');
|
||||
if (!S.native && e.dataTransfer) fromDrop(e.dataTransfer).then(upload);
|
||||
});
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
// UI strings: Simplified Chinese and English. Keys used via t(key) and data-i18n attributes.
|
||||
export const STRINGS = {
|
||||
zh_CN: {
|
||||
files: '文件', addFiles: '添加文件', addFolder: '添加文件夹', clear: '清空',
|
||||
dropHint: '把 PMX / VRM / 压缩包(zip / 7z / rar)/ FBX / unitypackage / uemodel / psk / xps 拖到这里',
|
||||
dropHintShort: '拖入更多文件', uploading: '正在读入 {i} / {n}:{name}', uploaded: '已加入 {n} 个文件', uploadFailed: '有 {n} 个文件读入失败',
|
||||
browserMode: '浏览器模式:', getWebView2: '下载 WebView2', browserModeHint: '拖入和添加文件照常可用(文件会先复制一份)。详细信息:{log}',
|
||||
empty: '尚未添加文件',
|
||||
st_pending: '待转换', st_running: '转换中', st_done: '完成', st_error: '失败', st_preview: '仅预览', st_skipped: '已跳过',
|
||||
skippedNote: '未识别到人物模型(道具或仅含服装),已按「只转换人物」跳过,详见日志',
|
||||
preview: '预览', reveal: '打开所在位置', remove: '移除', outputs: '输出',
|
||||
settings: '转换设置', tabInput: '其它格式',
|
||||
spec: 'VRM 版本', spec0x: '0.x',
|
||||
spring: '物理(头发、裙摆摆动)',
|
||||
springSkirt: '裙摆物理', autoSpring: '无物理的模型按骨骼名自动添加', stiffness: '整体硬度', morphs: '表情', comboExpr: '情绪表情组合眉、眼、嘴', gaze: '补充视线表情', extraExpr: '补充高光消失、吐舌表情',
|
||||
outline: '描边(按 PMX 轮廓线)', tposeOpt: '转为 T 姿势(重摆骨架)',
|
||||
tposeHint: '默认关闭,原样保留模型的静止姿势。勾选后才会把 A-pose 手臂抬成 VRM 规范的 T-pose。',
|
||||
doubleSided: '所有材质双面',
|
||||
targetPmx: '只转 PMX',
|
||||
avatarOnly: '只转换人物',
|
||||
avatarOnlyHint: '跳过模型包中常附带的道具(剑、椅子等)以及仅含服装 / 配件的模型。',
|
||||
fbx: 'FBX / unitypackage', fbxAlpha: '贴图透明通道', alphaAuto: '自动判定', alphaKeep: '保留', alphaStrip: '全部去除',
|
||||
autoFacing: '自动判定朝向', face180: '额外旋转 180°', fbxMorphs: '导出表情',
|
||||
ue: 'uemodel', ueAlpha: '去除贴图透明通道', ueAlign: '对齐参考', clearRef: '清除', noRef: '(不对齐)',
|
||||
ueAlignHint: '部件分开导出时(头部、身体、服装各为一个 uemodel),选择同一个整身模型作为参考,部件将按其骨架对齐。',
|
||||
ueWeakRef: '该模型的骨架跨度仅约 {cm} cm,更像部件而非整身模型;用作参考可能导致模型整体下沉',
|
||||
psk: 'psk / pskx', xps: 'xps', jpBones: '骨骼名改为 MMD 日文名', ik: '补充 IK 骨', inMorphs: '导出表情',
|
||||
inAlpha: '去除贴图透明通道', hideUnused: '归类 unused 骨', xpsDouble: '材质双面', xpsEdge: '轮廓线',
|
||||
outLocation: '保存到', outApp: '程序目录', outBeside: '源文件旁', outFolder: '指定文件夹', choose: '选择…',
|
||||
noFolder: '(未选择)', subfolder: '每个文件的结果保存到单独的子文件夹',
|
||||
jobs: '并行数', jobsAuto: '自动', jobsManual: '手动', jobsNumTip: '同时转换的文件数(1–64)',
|
||||
jobsHint: '同时转换几个文件。「自动」为 CPU 物理核心数减一(最多 8),可用内存不足时再减少;转换在后台以较低优先级运行,不影响其它程序。通常无需修改。',
|
||||
start: '开始转换', restart: '重新转换', stop: '停止', idle: '就绪', converting: '正在转换 {i}/{n}:{name}',
|
||||
finished: '完成 {done} 个,失败 {failed} 个', finishedSkip: '完成 {done} 个,跳过 {skipped} 个,失败 {failed} 个',
|
||||
nothing: '没有可转换的文件',
|
||||
log: '日志', clearLog: '清空日志',
|
||||
pvEmpty: '在左侧点击「预览」查看模型', pvMaking: '正在生成预览(快速转换)…', pvLoading: '加载中…',
|
||||
pvFailed: '预览失败:{err}',
|
||||
errNoFile: '文件已不在列表中', errNoPreview: '这个输出无法预览', errNotFound: '找不到文件',
|
||||
body: '全身', upper: '上半身', face: '脸部', back: '背面',
|
||||
tpose: 'T 姿势', idleM: '待机', walk: '走路', run: '跑步', legRaise: '抬腿', turn: '转身',
|
||||
autoThumb: '转换后自动生成缩略图',
|
||||
autoThumbHint: '在预览器中截取脸部写入 VRM,每次转换后更新。在「调整」中手动设置过缩略图的模型不受影响;压缩包里有多个模型时分别生成。',
|
||||
thumbAuto: '自动生成',
|
||||
pvHint: '左键旋转 · 右键平移 · 滚轮缩放 · 双击设为旋转中心 · R 恢复视角', pinChain: '常驻显示这条链', focusChain: '镜头对准这条链',
|
||||
pvBones: '骨骼', bHumanoid: 'humanoid 骨骼', bHumanoidPmx: '标准骨骼', bWeighted: '带权重', bSpring: '物理',
|
||||
bControl: '控制 / 中间骨骼', bUnused: '无效骨骼', bParent: '父骨骼:{p}', bRoot: '(根)', iBones: '骨骼', iBonesV: '{n}(无效 {u})',
|
||||
physics: '物理', light: '灯光', expressions: '表情', shot: '截图', saved: '已保存:{path}',
|
||||
lightAz: '水平角度', lightEl: '高度', lightI: '主光', ambient: '环境光', shadow: '投影', reset: '重置',
|
||||
filter: '筛选…', info: '信息',
|
||||
tabMain: '转换', convertTo: '转换成', targetHint_vrm1: '推荐。Unity(UniVRM)、VSeeFace 和大多数游戏均支持。',
|
||||
targetHint_vrm0: '仅在软件不支持 VRM 1.0 时使用。物理按 0.x 的格式近似换算,效果比 1.0 略粗。', targetHint_pmx: 'FBX、unitypackage 等格式仅转换为 MMD 使用的 PMX;已添加的 PMX 文件不做处理。',
|
||||
fileSize: '文件大小', sizeOrig: '原样', sizeMid: '适中', sizeSmall: '最小', sizeHint_orig: '保留原始贴图,画质最佳,文件最大。',
|
||||
sizeHint_mid: '贴图最大 2048,不透明贴图存为 JPEG。文件通常可缩小一半以上,画质差异不明显。', sizeHint_small: '贴图最大 1024,不透明贴图存为 JPEG。文件最小,近距离观看略显模糊。',
|
||||
sizeCustom: '自定义:贴图最大 {max},不透明贴图存为 {fmt}(可在「高级设置」中修改)。', advanced: '高级设置', advPhysics: '物理', advExpr: '表情',
|
||||
advLook: '显示修正', advBones: '骨骼', collapseBones: '精简控制骨', advRun: '输出与转换', autoSpringHint: 'FBX 等格式的模型通常不含物理,将根据头发、裙摆、袖子等骨骼名自动添加。',
|
||||
comboExprHint: '开心、生气等预设像 VRoid 一样整张脸联动;关闭后每个预设只对应一个表情。',
|
||||
collapseBonesHint: '去掉没有权重的中间骨(全ての親、センター、グルーブ、腰、肩P 等),层级与 VRoid 一致(Root > Hips)。IK、末端骨等不起作用的骨始终会去掉。',
|
||||
extraExprHint: '添加自定义表情 hideHighlight(关掉眼睛高光)和 tongue(吐舌)。优先使用模型自带的对应表情;没有关闭高光的表情时,按材质名找到眼睛高光并生成。',
|
||||
gazeHint: '有眼骨时补充 lookUp / lookDown / lookLeft / lookRight,供直接播放这些表情的程序使用。',
|
||||
doubleSidedHint: '模型出现破洞,或薄片头发、裙摆从背面不可见时开启。', subfolderHint: '文件夹命名为「名称_日期_序号」,重新转换不会覆盖已有结果。',
|
||||
fbxAlphaHint: '游戏贴图的透明通道常存放其他数据,可能导致模型变透明。「自动判定」逐张判断;整块出现半透明时选择「全部去除」,蕾丝、发梢边缘变硬时选择「保留」。',
|
||||
inputVrmHint: '骨骼命名、IK 等仅影响 PMX 的选项,在「转换成」中选择「只转 PMX」后显示。', metaTerms: '使用许可',
|
||||
metaModHint: '「修改」针对修改后的模型,「允许且可再分发」表示修改后的版本也可发布;上方的「允许再分发」针对原样分享。', metaReset: '将许可恢复为默认(最严格)', openOut: '打开输出位置',
|
||||
texTitle: '贴图', texMax: '最大边长', texOrig: '原样', texJpeg: '不透明贴图存为 JPEG',
|
||||
texNoMip: '贴图不生成 mipmap(消除 UV 接缝白边)',
|
||||
texNoMipHint: '贴图 UV 岛之间没留边距时,mipmap 会把岛外的白底混进边缘,形成白边。开启后只按原图分辨率采样,白边基本消失;远景会有轻微锯齿。',
|
||||
noPillow: '缩小贴图和存为 JPEG 需要安装 Pillow(pip install pillow)。',
|
||||
tabMeta: 'VRM 信息', metaHint: '写入 VRM 的作者和使用许可,设置一次即可用于之后转换的所有模型。名称默认为模型文件名,可在预览的「调整」中修改。转换他人的模型时,请按原作者的使用规约填写。',
|
||||
metaAuthor: '作者', metaVersion: '模型版本', metaContact: '联系方式', metaCopyright: '版权', metaLicense: '许可 URL',
|
||||
metaAvatar: '使用权限', permEveryone: '所有人', permLicensed: '获得授权者', permAuthor: '仅作者',
|
||||
metaCommercial: '商用', comNone: '不可商用', comPersonal: '个人可商用', comCorp: '企业可商用',
|
||||
metaMod: '修改', modNo: '禁止', modYes: '允许', modRedist: '允许且可再分发',
|
||||
metaCredit: '署名', creditYes: '需要', creditNo: '不需要', metaRedist: '允许再分发(原样分享文件)',
|
||||
tune: '调整', tuneNotReady: '预览生成后即可调整(或先转换该模型)',
|
||||
tuneNotReadyPmx: '当前预览的是原始 PMX,转换为 VRM 后才能调整',
|
||||
tuneAutoSaved: '已保存对 {name} 的调整', tuneNoFile: '请在左侧选择一个模型',
|
||||
tuneNotEditable: '仅支持调整由本程序转换的模型', tuneTitle: '名称', tuneThumb: '缩略图', thumbFromView: '使用当前画面',
|
||||
thumbHint: '请先在上方选择取景(例如「脸部」)', thumbRemove: '移除', thumbNone: '无',
|
||||
tuneMeta: '名称和缩略图', tuneExpr: '预设表情', exprNone: '(不设)', exprMissing: '(模型中没有,可手动指定)', tryExpr: '试看', tunePhysics: '物理',
|
||||
exprStrength: '强度(拖动时试看)', exprHint: '右侧滑块为强度:形态键权重按比例缩放,单个权重最高 100%,因此超过 100% 仅对组合表情(权重未满)有效。',
|
||||
tuneLook: '视线范围', lookH: '左右', lookDown: '向下', lookUp: '向上', lookReset: '恢复自动',
|
||||
lookHint: '眼睛看向最边缘时的转动角度(根据眼球结构自动计算)。修改会同时作用于 VRM 视线(如看向镜头)和转换时补充的 lookLeft 等视线表情。点击箭头可试看。',
|
||||
lookTry: '试看:看向该方向的最大角度',
|
||||
allChains: '整体', chains: '各条链({n})', stiffMul: '硬度', dragMul: '阻尼', gravAdd: '重力',
|
||||
tuneSave: '保存并写入', tuneReset: '全部还原', tuneDirty: '有未保存的改动(转换或切换文件时会自动保存)', tuneClean: '将写入输出的 VRM,之后转换时自动应用',
|
||||
tuneSaved: '已写入 {n} 个文件', tuneSavedNone: '已保存,下次转换时应用', thumbSaved: '缩略图已更新',
|
||||
tuned: '已调整', dragResize: '拖动调整宽度,双击恢复默认',
|
||||
iFormat: '格式', iHeight: '身高', iMmdUnit: ' MMD 单位', iTris: '三角面', iMats: '材质', iTex: '贴图', iMorphs: '表情',
|
||||
iPhysics: '物理', iRigid: '{r} 刚体 / {j} 关节', iOff: '(未启用)', iHumanoid: 'humanoid 骨', iExpr: '表情',
|
||||
iChains: '{n} 条 / {j} 关节', iColliders: '碰撞体',
|
||||
preset: { happy: '开心', angry: '生气', sad: '悲伤', relaxed: '放松', surprised: '惊讶', neutral: '自然',
|
||||
aa: '口型 あ', ih: '口型 い', ou: '口型 う', ee: '口型 え', oh: '口型 お', blink: '眨眼', blinkLeft: '闭左眼', blinkRight: '闭右眼',
|
||||
joy: '开心', sorrow: '悲伤', fun: '愉快', a: '口型 あ', i: '口型 い', u: '口型 う', e: '口型 え', o: '口型 お',
|
||||
blink_l: '闭左眼', blink_r: '闭右眼' },
|
||||
},
|
||||
en: {
|
||||
files: 'Files', addFiles: 'Add files', addFolder: 'Add folder', clear: 'Clear',
|
||||
dropHint: 'Drop PMX / VRM / archives (zip / 7z / rar) / FBX / unitypackage / uemodel / psk / xps here',
|
||||
dropHintShort: 'Drop more files', uploading: 'Reading {i} / {n}: {name}', uploaded: 'Added {n} file(s)', uploadFailed: '{n} file(s) could not be read',
|
||||
browserMode: 'Browser mode:', getWebView2: 'Get WebView2', browserModeHint: 'Dropping and adding files still work (the files are copied first). Details: {log}',
|
||||
empty: 'No files yet',
|
||||
st_pending: 'Pending', st_running: 'Converting', st_done: 'Done', st_error: 'Failed', st_preview: 'Preview only', st_skipped: 'Skipped',
|
||||
skippedNote: 'No character model found (a prop or clothing only); skipped by \"Characters only\". See the log for details',
|
||||
preview: 'Preview', reveal: 'Show in folder', remove: 'Remove', outputs: 'Output',
|
||||
settings: 'Settings', tabInput: 'Other formats',
|
||||
spec: 'VRM version', spec0x: '0.x',
|
||||
spring: 'Physics (hair and skirt sway)',
|
||||
springSkirt: 'Skirt physics', autoSpring: 'Add physics by bone name to models without it', stiffness: 'Stiffness', morphs: 'Expressions', comboExpr: 'Combine brow, eye and mouth in emotion presets', gaze: 'Add gaze expressions', extraExpr: 'Add highlight-off and tongue expressions',
|
||||
outline: 'Outline (from PMX edges)', tposeOpt: 'Convert to T-pose (re-poses the skeleton)',
|
||||
tposeHint: 'Off by default: the model keeps its original rest pose. Enable only if you want the arms raised to the VRM-spec T-pose.',
|
||||
doubleSided: 'All materials double-sided',
|
||||
targetPmx: 'PMX only',
|
||||
avatarOnly: 'Characters only',
|
||||
avatarOnlyHint: 'Skips props (swords, chairs, etc.) and clothing- or accessory-only models often bundled in model packs.',
|
||||
fbx: 'FBX / unitypackage', fbxAlpha: 'Texture alpha', alphaAuto: 'Auto', alphaKeep: 'Keep', alphaStrip: 'Strip',
|
||||
autoFacing: 'Auto-detect facing', face180: 'Extra 180° turn', fbxMorphs: 'Export morphs',
|
||||
ue: 'uemodel', ueAlpha: 'Strip texture alpha', ueAlign: 'Align to', clearRef: 'Clear', noRef: '(no alignment)',
|
||||
ueAlignHint: 'For parts exported separately (head, body and outfit as separate uemodels), select the same full-body model as reference to align them to its skeleton.',
|
||||
ueWeakRef: 'This skeleton spans only about {cm} cm and looks like a part rather than a full body; using it as reference may sink the model',
|
||||
psk: 'psk / pskx', xps: 'xps', jpBones: 'MMD Japanese bone names', ik: 'Add IK bones', inMorphs: 'Export morphs',
|
||||
inAlpha: 'Strip texture alpha', hideUnused: 'Group unused bones', xpsDouble: 'Double-sided', xpsEdge: 'Outline',
|
||||
outLocation: 'Save to', outApp: 'App folder', outBeside: 'Next to source', outFolder: 'Folder', choose: 'Choose…',
|
||||
noFolder: '(none)', subfolder: 'Put each file\'s results in its own subfolder',
|
||||
jobs: 'Parallel jobs', jobsAuto: 'Auto', jobsManual: 'Manual', jobsNumTip: 'Files converted at the same time (1–64)',
|
||||
jobsHint: 'How many files are converted at the same time. Auto is the number of physical CPU cores minus one (at most 8), fewer when free memory is short; conversions run in the background at a lower priority so other programs stay responsive. Rarely needs changing.',
|
||||
start: 'Start conversion', restart: 'Convert again', stop: 'Stop', idle: 'Ready', converting: 'Converting {i}/{n}: {name}',
|
||||
finished: '{done} done, {failed} failed', finishedSkip: '{done} done, {skipped} skipped, {failed} failed',
|
||||
nothing: 'Nothing to convert',
|
||||
log: 'Log', clearLog: 'Clear log',
|
||||
pvEmpty: 'Click "Preview" on the left to view a model', pvMaking: 'Generating preview (quick conversion)…',
|
||||
pvLoading: 'Loading…', pvFailed: 'Preview failed: {err}',
|
||||
errNoFile: 'The file is no longer in the list', errNoPreview: "This output can't be previewed", errNotFound: 'File not found',
|
||||
body: 'Body', upper: 'Upper', face: 'Face', back: 'Back',
|
||||
tpose: 'T-pose', idleM: 'Idle', walk: 'Walk', run: 'Run', legRaise: 'Leg raise', turn: 'Turn',
|
||||
autoThumb: 'Generate a thumbnail after converting',
|
||||
autoThumbHint: 'Captures the face in the previewer and writes it into the VRM, refreshed on every conversion. Models with a thumbnail set by hand in Tune are left alone; each model in an archive gets its own.',
|
||||
thumbAuto: 'generated',
|
||||
pvHint: 'Left drag: rotate · Right drag: pan · Wheel: zoom · Double-click: orbit around that point · R: reset view', pinChain: 'Keep this chain shown', focusChain: 'Point the camera at this chain',
|
||||
pvBones: 'Bones', bHumanoid: 'Humanoid', bHumanoidPmx: 'Standard', bWeighted: 'Weighted', bSpring: 'Physics',
|
||||
bControl: 'Control / intermediate', bUnused: 'Unused', bParent: 'Parent: {p}', bRoot: '(root)', iBones: 'Bones', iBonesV: '{n} ({u} unused)',
|
||||
physics: 'Physics', light: 'Light', expressions: 'Expressions', shot: 'Snapshot', saved: 'Saved: {path}',
|
||||
lightAz: 'Azimuth', lightEl: 'Elevation', lightI: 'Key light', ambient: 'Ambient', shadow: 'Shadows', reset: 'Reset',
|
||||
filter: 'Filter…', info: 'Info',
|
||||
tabMain: 'Convert', convertTo: 'Convert to',
|
||||
targetHint_vrm1: 'Recommended. Supported by Unity (UniVRM), VSeeFace and most games.',
|
||||
targetHint_vrm0: 'Use only for apps that cannot read VRM 1.0. Physics is approximated in the 0.x format, a little coarser than in 1.0.',
|
||||
targetHint_pmx: 'FBX, unitypackage and other formats are converted to PMX for MMD only; added PMX files are not processed.',
|
||||
fileSize: 'File size', sizeOrig: 'Original', sizeMid: 'Medium', sizeSmall: 'Smallest',
|
||||
sizeHint_orig: 'Original textures: best quality, largest file.',
|
||||
sizeHint_mid: 'Textures up to 2048, opaque textures as JPEG. Files are usually less than half the size with no noticeable quality loss.',
|
||||
sizeHint_small: 'Textures up to 1024, opaque textures as JPEG. Smallest file; slightly blurry up close.',
|
||||
sizeCustom: 'Custom: textures up to {max}, opaque textures as {fmt} (change under Advanced).', advanced: 'Advanced',
|
||||
advPhysics: 'Physics', advExpr: 'Expressions', advLook: 'Display fixes', advBones: 'Skeleton', collapseBones: 'Remove control bones',
|
||||
advRun: 'Output and conversion',
|
||||
autoSpringHint: 'Models from FBX and similar formats usually have no physics; chains are added for hair, skirts, sleeves, etc. by bone name.',
|
||||
comboExprHint: 'Presets such as happy and angry move the whole face, as in VRoid. When off, each preset uses a single morph.',
|
||||
collapseBonesHint: 'Removes unweighted intermediate bones (全ての親, センター, グルーブ, 腰, 肩P, etc.) so the hierarchy matches VRoid (Root > Hips). IK, tip and other unused bones are always removed.',
|
||||
extraExprHint: 'Adds custom expressions hideHighlight (eye highlights off) and tongue. Uses matching morphs from the model when present; without a highlight-off morph, one is generated from the eye highlight materials.',
|
||||
gazeHint: 'With eye bones, adds lookUp / lookDown / lookLeft / lookRight for apps that play these expressions directly.',
|
||||
doubleSidedHint: 'Turn on if the model has holes, or thin hair or skirts disappear when seen from behind.',
|
||||
subfolderHint: 'Named \"name_date_n\"; converting again does not overwrite earlier results.',
|
||||
fbxAlphaHint: 'Game textures often store other data in the alpha channel, which can make the model transparent. Auto decides per texture; choose Strip if whole parts become translucent, or Keep if lace or hair tips get hard edges.',
|
||||
inputVrmHint: 'Options that only affect PMX (bone names, IK, etc.) appear when \"Convert to\" is set to PMX only.',
|
||||
metaTerms: 'License',
|
||||
metaModHint: 'Modification applies to edited versions: \"+ Redistribute\" allows publishing them. \"Allow redistribution\" above applies to sharing the file as is.',
|
||||
metaReset: 'Reset license to defaults (most restrictive)', openOut: 'Show output',
|
||||
texTitle: 'Textures', texMax: 'Max size', texOrig: 'Original', texJpeg: 'Store opaque textures as JPEG',
|
||||
texNoMip: 'Disable texture mipmaps (fixes white UV seams)',
|
||||
texNoMipHint: 'When UV islands have no gutter, mipmaps average the blank background into island edges and produce white seams. This samples the full-resolution texture instead; distant views may show slight aliasing.',
|
||||
noPillow: 'Resizing textures and saving JPEG require Pillow (pip install pillow).',
|
||||
tabMeta: 'Metadata', metaHint: 'Author and usage license written into the VRM; set once and used for every model you convert. The name defaults to the model file name and can be changed per model under Tune. When converting someone else\'s model, follow the original author\'s terms.',
|
||||
metaAuthor: 'Author', metaVersion: 'Model version', metaContact: 'Contact', metaCopyright: 'Copyright', metaLicense: 'License URL',
|
||||
metaAvatar: 'Who may use', permEveryone: 'Everyone', permLicensed: 'Licensed', permAuthor: 'Author only',
|
||||
metaCommercial: 'Commercial', comNone: 'No', comPersonal: 'Personal', comCorp: 'Corporate',
|
||||
metaMod: 'Modification', modNo: 'Prohibited', modYes: 'Allowed', modRedist: '+ Redistribute',
|
||||
metaCredit: 'Credit', creditYes: 'Required', creditNo: 'Not required', metaRedist: 'Allow redistribution (sharing the file as is)',
|
||||
tune: 'Tune', tuneNotReady: 'Tuning is available once the preview is ready (or after converting the model)',
|
||||
tuneNotReadyPmx: 'This preview shows the original PMX; convert it to VRM to tune it',
|
||||
tuneAutoSaved: 'Saved the tuning of {name}', tuneNoFile: 'Select a model on the left',
|
||||
tuneNotEditable: 'Only models converted by this program can be tuned', tuneTitle: 'Name', tuneThumb: 'Thumbnail', thumbFromView: 'Use current view',
|
||||
thumbHint: 'Choose the framing above first (e.g. Face)', thumbRemove: 'Remove', thumbNone: 'None',
|
||||
tuneMeta: 'Name and thumbnail', tuneExpr: 'Preset expressions', exprNone: '(none)', exprMissing: '(not in the model; select one manually)', tryExpr: 'Try', tunePhysics: 'Physics',
|
||||
exprStrength: 'Strength (previewed while dragging)', exprHint: 'The slider on the right sets strength: morph weights are scaled, each capped at 100%, so values above 100% only affect combined expressions (whose weights are below full).',
|
||||
tuneLook: 'Gaze range', lookH: 'Left/right', lookDown: 'Down', lookUp: 'Up', lookReset: 'Back to auto',
|
||||
lookHint: 'How far the eyes turn at the edge of their range (computed from the eye shape). Applies to both VRM look-at (e.g. looking at the camera) and the lookLeft etc. expressions added during conversion. Click an arrow to preview.',
|
||||
lookTry: 'Preview: full range in this direction',
|
||||
allChains: 'All', chains: 'Chains ({n})', stiffMul: 'Stiffness', dragMul: 'Drag', gravAdd: 'Gravity',
|
||||
tuneSave: 'Save & write', tuneReset: 'Reset all', tuneDirty: 'Unsaved changes (saved by themselves when you convert or switch files)', tuneClean: 'Will be written into the output VRM and applied to later conversions',
|
||||
tuneSaved: 'Written to {n} file(s)', tuneSavedNone: 'Saved; applied on the next conversion', thumbSaved: 'Thumbnail updated',
|
||||
tuned: 'Tuned', dragResize: 'Drag to resize, double-click to reset',
|
||||
iFormat: 'Format', iHeight: 'Height', iMmdUnit: ' MMD units', iTris: 'Triangles', iMats: 'Materials', iTex: 'Textures', iMorphs: 'Morphs',
|
||||
iPhysics: 'Physics', iRigid: '{r} rigid bodies / {j} joints', iOff: ' (off)', iHumanoid: 'Humanoid bones', iExpr: 'Expressions',
|
||||
iChains: '{n} chains / {j} joints', iColliders: 'Colliders',
|
||||
preset: { happy: 'Happy', angry: 'Angry', sad: 'Sad', relaxed: 'Relaxed', surprised: 'Surprised', neutral: 'Neutral',
|
||||
aa: 'Mouth A', ih: 'Mouth I', ou: 'Mouth U', ee: 'Mouth E', oh: 'Mouth O', blink: 'Blink', blinkLeft: 'Blink left', blinkRight: 'Blink right',
|
||||
joy: 'Joy', sorrow: 'Sorrow', fun: 'Fun', a: 'Mouth A', i: 'Mouth I', u: 'Mouth U', e: 'Mouth E', o: 'Mouth O',
|
||||
blink_l: 'Blink left', blink_r: 'Blink right' },
|
||||
},
|
||||
};
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
@@ -0,0 +1,307 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>VRMify 增强版 · VRMify Enhanced</title>
|
||||
<link rel="icon" href="icon.png">
|
||||
<link rel="stylesheet" href="app.css">
|
||||
<script type="importmap">
|
||||
{ "imports": {
|
||||
"three": "/viewer/vendor/three/three.module.min.js",
|
||||
"three/addons/": "/viewer/vendor/three/addons/",
|
||||
"@pixiv/three-vrm": "/viewer/vendor/three-vrm/three-vrm.module.min.js"
|
||||
} }
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<header class="topbar">
|
||||
<div class="brand"><span class="logo">◆</span> VRMify <span class="enh">增强版</span> <span class="ver" id="ver"></span></div>
|
||||
<div class="seg small" id="langSeg">
|
||||
<button data-lang="zh_CN">中文</button><button data-lang="en">EN</button>
|
||||
</div>
|
||||
</header>
|
||||
<div id="modeNote" class="mode-note" hidden></div>
|
||||
|
||||
<div class="layout">
|
||||
<aside class="left">
|
||||
<div class="left-scroll">
|
||||
<!-- files -->
|
||||
<section class="card files-card">
|
||||
<div class="card-head">
|
||||
<h2 data-i18n="files"></h2>
|
||||
<div class="actions">
|
||||
<button id="addFiles" class="btn" data-i18n="addFiles"></button>
|
||||
<button id="addFolder" class="btn" data-i18n="addFolder"></button>
|
||||
<button id="clearFiles" class="btn ghost" data-i18n="clear"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="drop" class="drop"><span data-i18n="dropHint"></span></div>
|
||||
<!-- browser mode: the page can't see file paths, so files are picked here and uploaded (files.js) -->
|
||||
<input type="file" id="upFiles" multiple hidden>
|
||||
<input type="file" id="upFolder" webkitdirectory hidden>
|
||||
<ul id="fileList" class="file-list"></ul>
|
||||
</section>
|
||||
|
||||
<!-- settings: the first tab holds what most conversions need; the rest folds into "Advanced" -->
|
||||
<section class="card settings-card">
|
||||
<div class="card-head">
|
||||
<h2 data-i18n="settings"></h2>
|
||||
<div class="tabs" id="tabs">
|
||||
<button data-tab="main" class="on" data-i18n="tabMain"></button>
|
||||
<button data-tab="input" data-i18n="tabInput"></button>
|
||||
<button data-tab="meta" data-i18n="tabMeta"></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tab-body" data-panel="main">
|
||||
<div class="field">
|
||||
<label data-i18n="convertTo"></label>
|
||||
<div class="seg" id="targetSeg">
|
||||
<button data-v="vrm1">VRM 1.0</button><button data-v="vrm0">VRM 0.x</button><button data-v="pmx" data-i18n="targetPmx"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hint flush" id="targetHint"></div>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.avatar_only"><span data-i18n="avatarOnly"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="avatarOnlyHint"></div>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.spring"><span data-i18n="spring"></span></label>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.morphs"><span data-i18n="morphs"></span></label>
|
||||
<div class="field vrm-only">
|
||||
<label data-i18n="fileSize"></label>
|
||||
<div class="seg" id="sizeSeg">
|
||||
<button data-v="orig" data-i18n="sizeOrig"></button><button data-v="mid" data-i18n="sizeMid"></button><button data-v="small" data-i18n="sizeSmall"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hint flush vrm-only" id="texHint"></div>
|
||||
<div class="field">
|
||||
<label data-i18n="outLocation"></label>
|
||||
<div class="seg" data-opt="output.mode">
|
||||
<button data-v="app" data-i18n="outApp"></button><button data-v="beside" data-i18n="outBeside"></button><button data-v="folder" data-i18n="outFolder"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field folder-row">
|
||||
<span id="outFolder" class="path"></span>
|
||||
<button id="chooseOut" class="btn" data-i18n="choose"></button>
|
||||
</div>
|
||||
|
||||
<details class="sec adv" id="advanced">
|
||||
<summary data-i18n="advanced"></summary>
|
||||
<h3 class="vrm-only" data-i18n="advPhysics"></h3>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.spring_skirt"><span data-i18n="springSkirt"></span></label>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.auto_spring"><span data-i18n="autoSpring"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="autoSpringHint"></div>
|
||||
<div class="field vrm-only">
|
||||
<label data-i18n="stiffness"></label>
|
||||
<input type="range" min="0.5" max="2" step="0.1" data-opt="vrm.spring_stiffness"><output data-for="vrm.spring_stiffness"></output>
|
||||
</div>
|
||||
<h3 class="vrm-only" data-i18n="advExpr"></h3>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.combo_expr"><span data-i18n="comboExpr"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="comboExprHint"></div>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.gaze"><span data-i18n="gaze"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="gazeHint"></div>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.extra_expr"><span data-i18n="extraExpr"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="extraExprHint"></div>
|
||||
<h3 data-i18n="advLook"></h3>
|
||||
<label class="switch"><input type="checkbox" data-opt="vrm.double_sided"><span data-i18n="doubleSided"></span></label>
|
||||
<div class="hint" data-i18n="doubleSidedHint"></div>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.outline"><span data-i18n="outline"></span></label>
|
||||
<h3 class="vrm-only" data-i18n="advBones"></h3>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.tpose"><span data-i18n="tposeOpt"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="tposeHint"></div>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.collapse_bones"><span data-i18n="collapseBones"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="collapseBonesHint"></div>
|
||||
<h3 class="vrm-only" data-i18n="texTitle"></h3>
|
||||
<div class="field vrm-only">
|
||||
<label data-i18n="texMax"></label>
|
||||
<div class="seg" data-opt="vrm.tex_max">
|
||||
<button data-v="0" data-i18n="texOrig"></button><button data-v="4096">4096</button><button data-v="2048">2048</button><button data-v="1024">1024</button>
|
||||
</div>
|
||||
</div>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.tex_jpeg"><span data-i18n="texJpeg"></span></label>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.tex_no_mip"><span data-i18n="texNoMip"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="texNoMipHint"></div>
|
||||
<h3 data-i18n="advRun"></h3>
|
||||
<label class="switch vrm-only"><input type="checkbox" data-opt="vrm.auto_thumb"><span data-i18n="autoThumb"></span></label>
|
||||
<div class="hint vrm-only" data-i18n="autoThumbHint"></div>
|
||||
<label class="switch"><input type="checkbox" data-opt="output.subfolder"><span data-i18n="subfolder"></span></label>
|
||||
<div class="hint" data-i18n="subfolderHint"></div>
|
||||
<div class="field">
|
||||
<label data-i18n="jobs"></label>
|
||||
<div class="seg nowrap" id="jobsSeg">
|
||||
<button data-v="auto" data-i18n="jobsAuto"></button><button data-v="manual" data-i18n="jobsManual"></button>
|
||||
</div>
|
||||
<input type="number" id="jobsNum" class="input jobs-num" min="1" max="64" step="1" data-i18n-title="jobsNumTip">
|
||||
</div>
|
||||
<div class="hint flush" data-i18n="jobsHint"></div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<!-- other input formats -->
|
||||
<div class="tab-body" data-panel="input" hidden>
|
||||
<section class="fmt">
|
||||
<h3 data-i18n="fbx"></h3>
|
||||
<div class="field">
|
||||
<label data-i18n="fbxAlpha"></label>
|
||||
<div class="seg" data-opt="fbx.alpha">
|
||||
<button data-v="auto" data-i18n="alphaAuto"></button><button data-v="keep" data-i18n="alphaKeep"></button><button data-v="strip" data-i18n="alphaStrip"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hint flush" data-i18n="fbxAlphaHint"></div>
|
||||
<div class="grid2">
|
||||
<label class="switch"><input type="checkbox" data-opt="fbx.auto_facing"><span data-i18n="autoFacing"></span></label>
|
||||
<label class="switch"><input type="checkbox" data-opt="fbx.face_180"><span data-i18n="face180"></span></label>
|
||||
<label class="switch pmx-only"><input type="checkbox" data-opt="fbx.morphs"><span data-i18n="fbxMorphs"></span></label>
|
||||
</div>
|
||||
</section>
|
||||
<section class="fmt">
|
||||
<h3 data-i18n="ue"></h3>
|
||||
<label class="switch"><input type="checkbox" data-opt="uemodel.alpha"><span data-i18n="ueAlpha"></span></label>
|
||||
<div class="field folder-row">
|
||||
<label data-i18n="ueAlign"></label>
|
||||
<span id="ueRef" class="path"></span>
|
||||
<button id="ueRefPick" class="btn" data-i18n="choose"></button>
|
||||
<button id="ueRefClear" class="btn ghost" data-i18n="clearRef"></button>
|
||||
</div>
|
||||
<div class="hint flush" data-i18n="ueAlignHint"></div>
|
||||
</section>
|
||||
<section class="fmt">
|
||||
<h3 data-i18n="psk"></h3>
|
||||
<div class="grid2">
|
||||
<label class="switch"><input type="checkbox" data-opt="psk.alpha"><span data-i18n="inAlpha"></span></label>
|
||||
<label class="switch pmx-only"><input type="checkbox" data-opt="psk.morphs"><span data-i18n="inMorphs"></span></label>
|
||||
<label class="switch pmx-only"><input type="checkbox" data-opt="psk.jp_bones"><span data-i18n="jpBones"></span></label>
|
||||
<label class="switch pmx-only"><input type="checkbox" data-opt="psk.ik"><span data-i18n="ik"></span></label>
|
||||
</div>
|
||||
</section>
|
||||
<section class="fmt">
|
||||
<h3 data-i18n="xps"></h3>
|
||||
<div class="grid2">
|
||||
<label class="switch"><input type="checkbox" data-opt="xps.double_sided"><span data-i18n="xpsDouble"></span></label>
|
||||
<label class="switch pmx-only"><input type="checkbox" data-opt="xps.jp_bones"><span data-i18n="jpBones"></span></label>
|
||||
<label class="switch pmx-only"><input type="checkbox" data-opt="xps.ik"><span data-i18n="ik"></span></label>
|
||||
<label class="switch pmx-only"><input type="checkbox" data-opt="xps.hide_unused"><span data-i18n="hideUnused"></span></label>
|
||||
<label class="switch pmx-only"><input type="checkbox" data-opt="xps.edge"><span data-i18n="xpsEdge"></span></label>
|
||||
</div>
|
||||
</section>
|
||||
<div class="hint flush pmx-hidden" data-i18n="inputVrmHint"></div>
|
||||
</div>
|
||||
|
||||
<div class="tab-body" data-panel="meta" hidden>
|
||||
<div class="hint flush" data-i18n="metaHint"></div>
|
||||
<div class="field"><label data-i18n="metaAuthor"></label><input type="text" class="input" data-opt="meta.author"></div>
|
||||
<div class="field"><label data-i18n="metaVersion"></label><input type="text" class="input" data-opt="meta.version" placeholder="1"></div>
|
||||
<div class="field"><label data-i18n="metaContact"></label><input type="text" class="input" data-opt="meta.contact"></div>
|
||||
<div class="field"><label data-i18n="metaCopyright"></label><input type="text" class="input" data-opt="meta.copyright"></div>
|
||||
<div class="field"><label data-i18n="metaLicense"></label><input type="text" class="input" data-opt="meta.license_url" placeholder="https://vrm.dev/licenses/1.0/"></div>
|
||||
<h3 data-i18n="metaTerms"></h3>
|
||||
<div class="field">
|
||||
<label data-i18n="metaAvatar"></label>
|
||||
<div class="seg" data-opt="meta.avatar_permission">
|
||||
<button data-v="everyone" data-i18n="permEveryone"></button><button data-v="onlySeparatelyLicensedPerson" data-i18n="permLicensed"></button><button data-v="onlyAuthor" data-i18n="permAuthor"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label data-i18n="metaCommercial"></label>
|
||||
<div class="seg" data-opt="meta.commercial_usage">
|
||||
<button data-v="personalNonProfit" data-i18n="comNone"></button><button data-v="personalProfit" data-i18n="comPersonal"></button><button data-v="corporation" data-i18n="comCorp"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label data-i18n="metaCredit"></label>
|
||||
<div class="seg" data-opt="meta.credit_notation">
|
||||
<button data-v="required" data-i18n="creditYes"></button><button data-v="unnecessary" data-i18n="creditNo"></button>
|
||||
</div>
|
||||
</div>
|
||||
<label class="switch"><input type="checkbox" data-opt="meta.allow_redistribution"><span data-i18n="metaRedist"></span></label>
|
||||
<div class="field">
|
||||
<label data-i18n="metaMod"></label>
|
||||
<div class="seg" data-opt="meta.modification">
|
||||
<button data-v="prohibited" data-i18n="modNo"></button><button data-v="allowModification" data-i18n="modYes"></button><button data-v="allowModificationRedistribution" data-i18n="modRedist"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hint flush" data-i18n="metaModHint"></div>
|
||||
<button class="btn ghost small" id="metaReset" data-i18n="metaReset"></button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card log-card" id="logCard">
|
||||
<div class="card-head">
|
||||
<button id="logToggle" class="link" aria-expanded="false"><span class="caret">▸</span> <span data-i18n="log"></span> <span id="logBadge" class="badge" hidden></span></button>
|
||||
<button id="clearLog" class="btn ghost small" data-i18n="clearLog"></button>
|
||||
</div>
|
||||
<pre id="log" class="log" hidden></pre>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<!-- run: pinned to the bottom of the left column -->
|
||||
<section class="runbar">
|
||||
<button id="start" class="btn primary"><span id="startLabel"></span> <span id="startCount"></span></button>
|
||||
<button id="stop" class="btn" data-i18n="stop" hidden></button>
|
||||
<div id="status" class="status"></div>
|
||||
<button id="openOut" class="btn ghost small" data-i18n="openOut" hidden></button>
|
||||
<div class="progress"><div id="progressFill"></div></div>
|
||||
</section>
|
||||
</aside>
|
||||
<div class="splitter" id="splitLeft" role="separator" aria-orientation="vertical" data-i18n-title="dragResize"></div>
|
||||
|
||||
<main class="right">
|
||||
<div class="pv-toolbar">
|
||||
<div class="pv-title" id="pvTitle"></div>
|
||||
<div class="seg small" id="frameSeg">
|
||||
<button data-frame="body" class="on" data-i18n="body"></button><button data-frame="upper" data-i18n="upper"></button>
|
||||
<button data-frame="face" data-i18n="face"></button><button data-frame="back" data-i18n="back"></button>
|
||||
</div>
|
||||
<div class="seg small" id="motionSeg">
|
||||
<button data-motion="tpose" data-i18n="tpose"></button><button data-motion="idle" class="on" data-i18n="idleM"></button>
|
||||
<button data-motion="walk" data-i18n="walk"></button><button data-motion="run" data-i18n="run"></button>
|
||||
<button data-motion="legRaise" data-i18n="legRaise"></button><button data-motion="turn" data-i18n="turn"></button>
|
||||
</div>
|
||||
<label class="switch small"><input type="checkbox" id="pvSpring" checked><span data-i18n="physics"></span></label>
|
||||
<label class="switch small"><input type="checkbox" id="pvBones"><span data-i18n="pvBones"></span></label>
|
||||
<span class="spacer"></span>
|
||||
<button class="btn small" id="lightBtn" data-i18n="light"></button>
|
||||
<button class="btn small" id="exprBtn" data-i18n="expressions"></button>
|
||||
<button class="btn small" id="tuneBtn" data-i18n="tune"></button>
|
||||
<button class="btn small" id="infoBtn" data-i18n="info"></button>
|
||||
<button class="btn small" id="shotBtn" data-i18n="shot"></button>
|
||||
</div>
|
||||
<div class="stage">
|
||||
<div class="pv" id="pv">
|
||||
<div class="pv-empty" id="pvEmpty"><span data-i18n="pvEmpty"></span></div>
|
||||
<div class="pv-busy" id="pvBusy" hidden><div class="spinner"></div><span id="pvBusyText"></span></div>
|
||||
<div class="pv-legend" id="pvLegend" hidden></div>
|
||||
<div class="pv-tip" id="pvTip" hidden></div>
|
||||
<div class="pv-hint" id="pvHint" data-i18n="pvHint" hidden></div>
|
||||
</div>
|
||||
<!-- side column: one panel at a time; the preview narrows instead of being covered -->
|
||||
<div class="splitter" id="splitSide" role="separator" aria-orientation="vertical" data-i18n-title="dragResize" hidden></div>
|
||||
<aside class="side" id="side" hidden>
|
||||
<div class="panel" id="lightPanel" hidden>
|
||||
<div class="field"><label data-i18n="lightAz"></label><input type="range" id="lAz" min="-180" max="180" step="5" value="35"><output id="lAzV"></output></div>
|
||||
<div class="field"><label data-i18n="lightEl"></label><input type="range" id="lEl" min="-10" max="90" step="5" value="40"><output id="lElV"></output></div>
|
||||
<div class="field"><label data-i18n="lightI"></label><input type="range" id="lI" min="0" max="3" step="0.1" value="1.4"><output id="lIV"></output></div>
|
||||
<div class="field"><label data-i18n="ambient"></label><input type="range" id="lAmb" min="0" max="2" step="0.05" value="0.6"><output id="lAmbV"></output></div>
|
||||
<label class="switch"><input type="checkbox" id="lShadow" checked><span data-i18n="shadow"></span></label>
|
||||
<div class="swatches" id="bgSeg"><button data-bg="#8a8f98" class="on" style="background:#8a8f98" aria-label="#8a8f98"></button><button data-bg="#2b2d31" style="background:#2b2d31" aria-label="#2b2d31"></button><button data-bg="#eef0f3" style="background:#eef0f3" aria-label="#eef0f3"></button></div>
|
||||
</div>
|
||||
<div class="panel" id="exprPanel" hidden>
|
||||
<div class="field"><input id="exprFilter" class="input" data-i18n-ph="filter"><button id="exprReset" class="btn small" data-i18n="reset"></button></div>
|
||||
<div id="exprList" class="expr-list"></div>
|
||||
</div>
|
||||
<div class="panel" id="infoPanel" hidden><dl id="infoList" class="info"></dl></div>
|
||||
<div class="panel" id="tunePanel" hidden>
|
||||
<div class="tune-body" id="tuneBody"></div>
|
||||
<div class="tune-foot" id="tuneFoot">
|
||||
<span id="tuneState" class="muted"></span>
|
||||
<button id="tuneReset" class="btn small" data-i18n="tuneReset"></button>
|
||||
<button id="tuneSave" class="btn small primary" data-i18n="tuneSave"></button>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<div id="toast" class="toast"></div>
|
||||
<script type="module" src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,44 @@
|
||||
// Drag handles to resize the left column and the side column (panels). Widths are saved in settings.json
|
||||
// (the pywebview window doesn't keep browser storage between launches); double-click a handle to reset.
|
||||
import { $, S, api } from './core.js';
|
||||
|
||||
const root = document.documentElement.style;
|
||||
const VARS = { left: '--left-w', side: '--side-w', sideWide: '--side-wide-w' };
|
||||
const MIN_PREVIEW = 240; // the preview never gets narrower than this while dragging
|
||||
|
||||
export function applyLayout() {
|
||||
for (const [k, v] of Object.entries(VARS)) {
|
||||
if (S.ui[k]) root.setProperty(v, S.ui[k] + 'px'); else root.removeProperty(v);
|
||||
}
|
||||
}
|
||||
|
||||
const sideKey = () => ($('side').classList.contains('wide') ? 'sideWide' : 'side');
|
||||
const width = (el) => el.getBoundingClientRect().width;
|
||||
|
||||
function drag(handle, key, measure) {
|
||||
handle.addEventListener('pointerdown', (e) => {
|
||||
e.preventDefault();
|
||||
handle.setPointerCapture(e.pointerId);
|
||||
handle.classList.add('dragging'); document.body.classList.add('resizing');
|
||||
const k = key(), x0 = e.clientX, w0 = measure.width(), room = measure.room();
|
||||
const move = (ev) => {
|
||||
const w = Math.round(Math.max(measure.min, Math.min(w0 + (ev.clientX - x0) * measure.dir, w0 + room - MIN_PREVIEW)));
|
||||
S.ui[k] = w; root.setProperty(VARS[k], w + 'px');
|
||||
};
|
||||
const up = () => {
|
||||
handle.removeEventListener('pointermove', move); handle.removeEventListener('pointerup', up);
|
||||
handle.classList.remove('dragging'); document.body.classList.remove('resizing');
|
||||
api('/api/options', { ui: { [k]: S.ui[k] } });
|
||||
};
|
||||
handle.addEventListener('pointermove', move); handle.addEventListener('pointerup', up);
|
||||
});
|
||||
handle.addEventListener('dblclick', () => {
|
||||
const k = key();
|
||||
delete S.ui[k]; root.removeProperty(VARS[k]);
|
||||
api('/api/options', { ui: { [k]: null } });
|
||||
});
|
||||
}
|
||||
|
||||
// left column: dragging right widens it; the side column: dragging left widens it
|
||||
drag($('splitLeft'), () => 'left', { dir: 1, min: 300, width: () => width(document.querySelector('.left')), room: () => width($('pv')) });
|
||||
drag($('splitSide'), sideKey, { dir: -1, min: 220, width: () => width($('side')), room: () => width($('pv')) });
|
||||
@@ -0,0 +1,155 @@
|
||||
// Conversion settings: form ↔ S.opts (saved to settings.json through /api/options), tabs.
|
||||
// The first tab shows what most conversions need; finer options sit in the "Advanced" fold.
|
||||
import { $, S, api, t, toast } from './core.js';
|
||||
|
||||
export const getOpt = (path) => path.split('.').reduce((o, k) => (o ? o[k] : undefined), S.opts);
|
||||
function setOpt(path, v) {
|
||||
const ks = path.split('.'); let o = S.opts;
|
||||
for (const k of ks.slice(0, -1)) o = o[k] = o[k] || {};
|
||||
o[ks[ks.length - 1]] = v;
|
||||
}
|
||||
|
||||
// "Convert to" combines two stored options: target (vrm / pmx) and vrm.spec (1.0 / 0.x)
|
||||
const targetValue = () => (getOpt('target') === 'pmx' ? 'pmx' : getOpt('vrm.spec') === '0.x' ? 'vrm0' : 'vrm1');
|
||||
// "File size" presets over the two texture options; anything else shows as custom (set under Advanced)
|
||||
const SIZES = { orig: [0, false], mid: [2048, true], small: [1024, true] };
|
||||
const sizeValue = () => Object.keys(SIZES).find((k) => SIZES[k][0] === +getOpt('vrm.tex_max') && SIZES[k][1] === !!getOpt('vrm.tex_jpeg'));
|
||||
|
||||
const markSeg = (seg, v) => seg.querySelectorAll('button').forEach((b) => {
|
||||
const on = b.dataset.v === v;
|
||||
b.classList.toggle('on', on); b.setAttribute('aria-pressed', on);
|
||||
});
|
||||
|
||||
export function applyOptsToForm() {
|
||||
document.querySelectorAll('[data-opt]').forEach((el) => {
|
||||
const v = getOpt(el.dataset.opt);
|
||||
if (el.classList.contains('seg')) markSeg(el, String(v));
|
||||
else if (el.type === 'checkbox') el.checked = !!v;
|
||||
else if (el.type === 'text') { if (document.activeElement !== el) el.value = v ?? ''; }
|
||||
else if (el.type === 'range') {
|
||||
el.value = v;
|
||||
const o = document.querySelector(`output[data-for="${el.dataset.opt}"]`);
|
||||
if (o) o.textContent = (+v).toFixed(1);
|
||||
}
|
||||
});
|
||||
markSeg($('targetSeg'), targetValue());
|
||||
markSeg($('sizeSeg'), sizeValue());
|
||||
// parallel jobs: Auto (the box shows how many that is here, greyed) or Manual (the box is the number)
|
||||
const jobs = Math.max(0, Math.round(+getOpt('jobs') || 0));
|
||||
markSeg($('jobsSeg'), jobs ? 'manual' : 'auto');
|
||||
$('jobsNum').disabled = !jobs;
|
||||
if (document.activeElement !== $('jobsNum')) $('jobsNum').value = jobs || S.features.auto_jobs || '';
|
||||
syncDependents();
|
||||
}
|
||||
|
||||
// greys out (and disables) options that don't apply with the current choices
|
||||
const dim = (el, off) => { el.disabled = off; el.closest('.switch, .field').classList.toggle('dim', off); };
|
||||
export function syncDependents() {
|
||||
const target = targetValue(), spring = getOpt('vrm.spring');
|
||||
document.querySelector('.settings-card').classList.toggle('pmx', target === 'pmx');
|
||||
$('targetHint').textContent = t('targetHint_' + target);
|
||||
document.querySelectorAll('[data-opt="vrm.spring"], [data-opt="vrm.spring_skirt"], [data-opt="vrm.auto_spring"], [data-opt="vrm.spring_stiffness"]')
|
||||
.forEach((el) => dim(el, el.dataset.opt !== 'vrm.spring' && !spring));
|
||||
document.querySelectorAll('[data-opt="vrm.gaze"], [data-opt="vrm.combo_expr"], [data-opt="vrm.extra_expr"]').forEach((el) => dim(el, !getOpt('vrm.morphs')));
|
||||
$('chooseOut').disabled = getOpt('output.mode') !== 'folder';
|
||||
// texture slimming needs Pillow on the Python side
|
||||
const pil = S.features.pillow !== false;
|
||||
for (const seg of [$('sizeSeg'), document.querySelector('[data-opt="vrm.tex_max"]')]) {
|
||||
seg.querySelectorAll('button').forEach((b) => { b.disabled = !pil && b.dataset.v !== 'orig' && b.dataset.v !== '0'; });
|
||||
}
|
||||
dim(document.querySelector('[data-opt="vrm.tex_jpeg"]'), !pil);
|
||||
const size = sizeValue();
|
||||
$('texHint').textContent = !pil ? t('noPillow') : size ? t('sizeHint_' + size)
|
||||
: t('sizeCustom', { max: +getOpt('vrm.tex_max') || t('texOrig'), fmt: getOpt('vrm.tex_jpeg') ? 'JPEG' : 'PNG' });
|
||||
$('texHint').classList.toggle('warn', !pil);
|
||||
renderUeRef();
|
||||
renderOutFolder();
|
||||
}
|
||||
|
||||
|
||||
function renderUeRef() {
|
||||
const f = getOpt('uemodel.align_ref');
|
||||
$('ueRef').textContent = f ? f.split(/[\\/]/).pop() : t('noRef');
|
||||
$('ueRef').title = f || '';
|
||||
$('ueRefClear').disabled = !f;
|
||||
}
|
||||
export function renderOutFolder() {
|
||||
const mode = getOpt('output.mode'), f = mode === 'app' ? S.appOut : getOpt('output.folder');
|
||||
$('outFolder').textContent = mode === 'beside' ? t('outBeside') : (f || t('noFolder'));
|
||||
$('outFolder').title = f || '';
|
||||
$('outFolder').classList.toggle('dim', mode === 'beside');
|
||||
}
|
||||
|
||||
let saveTimer = null;
|
||||
function saveOpts() { clearTimeout(saveTimer); saveTimer = setTimeout(flushOpts, 250); }
|
||||
// sends a pending change now (starting a conversion right after changing a setting must use the new value)
|
||||
export async function flushOpts() {
|
||||
if (saveTimer === null) return;
|
||||
clearTimeout(saveTimer); saveTimer = null;
|
||||
await api('/api/options', { opts: S.opts });
|
||||
}
|
||||
const changed = () => { applyOptsToForm(); saveOpts(); };
|
||||
|
||||
document.querySelectorAll('[data-opt]').forEach((el) => {
|
||||
if (el.classList.contains('seg')) {
|
||||
el.addEventListener('click', (e) => {
|
||||
const b = e.target.closest('button'); if (!b) return;
|
||||
setOpt(el.dataset.opt, b.dataset.v); changed();
|
||||
});
|
||||
} else {
|
||||
el.addEventListener('input', () => {
|
||||
setOpt(el.dataset.opt, el.type === 'checkbox' ? el.checked : el.type === 'text' ? el.value.trim() : +el.value);
|
||||
changed();
|
||||
});
|
||||
}
|
||||
});
|
||||
$('jobsSeg').addEventListener('click', (e) => {
|
||||
const v = e.target.closest('button')?.dataset.v; if (!v) return;
|
||||
const manual = v === 'manual';
|
||||
if (manual === !!(+getOpt('jobs'))) return;
|
||||
setOpt('jobs', manual ? Math.max(1, +$('jobsNum').value || S.features.auto_jobs || 1) : 0);
|
||||
changed();
|
||||
if (manual) $('jobsNum').focus();
|
||||
});
|
||||
$('jobsNum').addEventListener('change', (e) => {
|
||||
const n = Math.round(+e.target.value);
|
||||
if (n >= 1) setOpt('jobs', Math.min(64, n));
|
||||
changed();
|
||||
e.target.value = +getOpt('jobs') || S.features.auto_jobs || ''; // an invalid entry shows the stored number again
|
||||
});
|
||||
$('targetSeg').addEventListener('click', (e) => {
|
||||
const v = e.target.closest('button')?.dataset.v; if (!v) return;
|
||||
setOpt('target', v === 'pmx' ? 'pmx' : 'vrm');
|
||||
if (v !== 'pmx') setOpt('vrm.spec', v === 'vrm0' ? '0.x' : '1.0');
|
||||
changed();
|
||||
});
|
||||
$('sizeSeg').addEventListener('click', (e) => {
|
||||
const v = e.target.closest('button')?.dataset.v; if (!v || !SIZES[v]) return;
|
||||
setOpt('vrm.tex_max', String(SIZES[v][0])); setOpt('vrm.tex_jpeg', SIZES[v][1]);
|
||||
changed();
|
||||
});
|
||||
// license terms back to the conservative defaults (author / contact fields stay)
|
||||
const META_DEFAULTS = { avatar_permission: 'everyone', commercial_usage: 'personalNonProfit', credit_notation: 'required',
|
||||
allow_redistribution: false, modification: 'prohibited' };
|
||||
$('metaReset').onclick = () => { for (const [k, v] of Object.entries(META_DEFAULTS)) setOpt('meta.' + k, v); changed(); };
|
||||
|
||||
$('ueRefPick').onclick = async () => {
|
||||
const r = await api('/api/pick_ue_ref', {});
|
||||
if (!r.path) return;
|
||||
setOpt('uemodel.align_ref', r.path); renderUeRef(); saveOpts();
|
||||
if (r.warn) toast(t('ueWeakRef', { cm: r.warn }));
|
||||
};
|
||||
$('ueRefClear').onclick = () => { setOpt('uemodel.align_ref', ''); renderUeRef(); saveOpts(); };
|
||||
$('chooseOut').onclick = async () => {
|
||||
const r = await api('/api/pick_output', {});
|
||||
if (r.folder) { setOpt('output.folder', r.folder); renderOutFolder(); saveOpts(); }
|
||||
};
|
||||
document.querySelectorAll('[data-tab]').forEach((b) => b.addEventListener('click', () => {
|
||||
document.querySelectorAll('[data-tab]').forEach((x) => x.classList.toggle('on', x === b));
|
||||
document.querySelectorAll('[data-panel]').forEach((p) => { p.hidden = p.dataset.panel !== b.dataset.tab; });
|
||||
}));
|
||||
// the Advanced fold remembers whether it was open (per browser profile; harmless if storage is unavailable)
|
||||
try { $('advanced').open = localStorage.getItem('advancedOpen') === '1'; } catch (e) { /* no storage */ }
|
||||
$('advanced').addEventListener('toggle', () => {
|
||||
try { localStorage.setItem('advancedOpen', $('advanced').open ? '1' : '0'); } catch (e) { /* no storage */ }
|
||||
});
|
||||
@@ -0,0 +1,155 @@
|
||||
// 3D preview (viewer-core.js), its toolbar and the side column (light / expressions / tune / info).
|
||||
import { BONE_COLORS, Viewer } from '/viewer/viewer-core.js';
|
||||
import { $, S, api, errText, esc, t, toast } from './core.js';
|
||||
import { renderFiles } from './files.js';
|
||||
import { flushOpts } from './options.js';
|
||||
import { T, leaveTune, loadTune, springParams } from './tune.js';
|
||||
|
||||
export const viewer = new Viewer($('pv'));
|
||||
export let modelUrl = null;
|
||||
|
||||
viewer.onLoad = (info) => {
|
||||
fillPreviewPanels(info);
|
||||
fillLegend();
|
||||
// reload after saving tune edits keeps the camera
|
||||
if (S.keepView) { viewer.camera.position.copy(S.keepView.pos); viewer.controls.target.copy(S.keepView.tgt); viewer.controls.update(); S.keepView = null; }
|
||||
else viewer.frame(document.querySelector('[data-frame].on').dataset.frame);
|
||||
if (T.fid === S.current && T.info && T.info.ready && T.dirty) viewer.setSpringParams(springParams());
|
||||
};
|
||||
|
||||
export function showBusy(text) { $('pvBusy').hidden = !text; $('pvBusyText').textContent = text || ''; }
|
||||
|
||||
export async function previewFile(id, output) {
|
||||
if (!leaveTune(id)) return;
|
||||
S.current = id; renderFiles();
|
||||
// the tune panel opens with the preview once there is something to tune (a converted / preview VRM),
|
||||
// unless another panel (light / expressions / info) is open
|
||||
S.autoTune = !openPanel();
|
||||
loadTune();
|
||||
await flushOpts();
|
||||
const r = await api('/api/preview', output === undefined ? { id } : { id, output });
|
||||
if (r.url) loadModel(r.url, r.name);
|
||||
else if (r.pending) showBusy(t('pvMaking'));
|
||||
else if (r.error) toast(errText(r.error, r.error_en));
|
||||
}
|
||||
|
||||
export async function loadModel(url, name, keepView) {
|
||||
showBusy(t('pvLoading'));
|
||||
S.keepView = keepView && viewer.loaded ? { pos: viewer.camera.position.clone(), tgt: viewer.controls.target.clone() } : null;
|
||||
try {
|
||||
await viewer.loadUrl(url, name);
|
||||
modelUrl = url;
|
||||
$('pvEmpty').hidden = true;
|
||||
$('pvHint').hidden = false;
|
||||
$('pvTitle').textContent = name;
|
||||
if (!T.dirty) loadTune(); // the Tune panel shows the model on screen (an archive can hold several)
|
||||
} catch (e) { toast(t('pvFailed', { err: e.message })); }
|
||||
showBusy(null);
|
||||
}
|
||||
|
||||
// ---- side column: one panel at a time; the preview narrows instead of being covered
|
||||
const PANELS = { lightPanel: 'lightBtn', exprPanel: 'exprBtn', tunePanel: 'tuneBtn', infoPanel: 'infoBtn' };
|
||||
export const openPanel = () => Object.keys(PANELS).find((p) => !$(p).hidden) || null;
|
||||
export function showPanel(id) {
|
||||
for (const [p, btn] of Object.entries(PANELS)) {
|
||||
$(p).hidden = p !== id;
|
||||
$(btn).classList.toggle('on', p === id);
|
||||
$(btn).setAttribute('aria-pressed', p === id);
|
||||
}
|
||||
$('side').hidden = !id;
|
||||
if (id !== 'tunePanel') viewer.highlightChain(null);
|
||||
$('splitSide').hidden = !id;
|
||||
$('side').classList.toggle('wide', id === 'tunePanel');
|
||||
}
|
||||
for (const [p, btn] of Object.entries(PANELS)) {
|
||||
$(btn).onclick = () => {
|
||||
S.autoTune = false;
|
||||
const open = $(p).hidden;
|
||||
showPanel(open ? p : null);
|
||||
if (open && p === 'tunePanel') loadTune();
|
||||
};
|
||||
}
|
||||
|
||||
// ---- info + expression panels
|
||||
export function fillPreviewPanels(info) {
|
||||
if (!info) return;
|
||||
const rows = info.spec === 'PMX'
|
||||
? [[t('iFormat'), 'PMX'], [t('iHeight'), info.height.toFixed(1) + t('iMmdUnit')], [t('iTris'), info.triangles.toLocaleString()],
|
||||
[t('iMats'), info.materials], [t('iTex'), info.textures], [t('iMorphs'), info.expressions.length],
|
||||
[t('iPhysics'), info.rigidBodies ? t('iRigid', { r: info.rigidBodies, j: info.constraints }) + (info.physics ? '' : t('iOff')) : '—']]
|
||||
: [['VRM', info.spec], [t('iHeight'), info.height.toFixed(2) + ' m'], [t('iHumanoid'), info.humanBones],
|
||||
[t('iTris'), info.triangles.toLocaleString()], [t('iMats'), info.materials], [t('iTex'), info.textures],
|
||||
[t('iExpr'), info.expressions.length], ['SpringBone', info.springs ? t('iChains', { n: info.springs, j: info.joints }) : '—'],
|
||||
[t('iColliders'), info.colliders]];
|
||||
if (info.bones) rows.splice(info.spec === 'PMX' ? 1 : 2, 0, [t('iBones'), t('iBonesV', { n: info.bones.total, u: info.bones.unused })]);
|
||||
$('infoList').innerHTML = rows.map(([k, v]) => `<dt>${esc(k)}</dt><dd>${esc(v)}</dd>`).join('');
|
||||
const box = $('exprList'); box.innerHTML = '';
|
||||
for (const e of info.expressions) {
|
||||
const row = document.createElement('div'); row.className = 'field'; row.dataset.name = e.name.toLowerCase();
|
||||
row.innerHTML = `<label title="${esc(e.name)}">${esc(e.name)}</label><input type="range" min="0" max="1" step="0.01" value="0" aria-label="${esc(e.name)}">`;
|
||||
row.querySelector('input').addEventListener('input', (ev) => viewer.setExpression(e.name, +ev.target.value));
|
||||
box.append(row);
|
||||
}
|
||||
filterExpr();
|
||||
}
|
||||
function filterExpr() {
|
||||
const q = $('exprFilter').value.trim().toLowerCase();
|
||||
for (const r of $('exprList').children) r.style.display = !q || r.dataset.name.includes(q) ? '' : 'none';
|
||||
}
|
||||
$('exprFilter').addEventListener('input', filterExpr);
|
||||
$('exprReset').onclick = () => { viewer.resetExpressions(); $('exprList').querySelectorAll('input').forEach((i) => { i.value = 0; }); };
|
||||
|
||||
// ---- toolbar
|
||||
const segClick = (id, attr, fn) => $(id).addEventListener('click', (e) => {
|
||||
const b = e.target.closest('button'); if (!b) return;
|
||||
$(id).querySelectorAll('button').forEach((x) => { x.classList.toggle('on', x === b); x.setAttribute('aria-pressed', x === b); });
|
||||
fn(b.getAttribute(attr));
|
||||
});
|
||||
segClick('frameSeg', 'data-frame', (k) => viewer.frame(k));
|
||||
// R / Home: back to the selected framing (not while typing in a field)
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.ctrlKey || e.metaKey || e.altKey || e.target.closest('input, textarea, select, [contenteditable]')) return;
|
||||
if (e.key === 'r' || e.key === 'R' || e.key === 'Home') { viewer.resetView(); e.preventDefault(); }
|
||||
});
|
||||
segClick('motionSeg', 'data-motion', (m) => viewer.setMotion(m));
|
||||
segClick('bgSeg', 'data-bg', (c) => viewer.setBackground(c));
|
||||
$('pvSpring').addEventListener('change', () => viewer.setSpring($('pvSpring').checked));
|
||||
|
||||
// ---- skeleton overlay: bones coloured by role, legend with counts, name + parent of the bone under the pointer
|
||||
const BONE_KINDS = ['humanoid', 'weighted', 'spring', 'control', 'unused'];
|
||||
const kindLabel = (k) => t({ humanoid: viewer.kind === 'pmx' ? 'bHumanoidPmx' : 'bHumanoid', weighted: 'bWeighted',
|
||||
spring: 'bSpring', control: 'bControl', unused: 'bUnused' }[k]);
|
||||
function fillLegend() {
|
||||
const on = $('pvBones').checked && viewer.loaded;
|
||||
$('pvLegend').hidden = !on;
|
||||
$('pvTip').hidden = true;
|
||||
if (!on) return;
|
||||
const s = viewer.boneStats();
|
||||
$('pvLegend').innerHTML = BONE_KINDS.filter((k) => s[k]).map((k) =>
|
||||
`<div><i style="background:${BONE_COLORS[k]}"></i>${esc(kindLabel(k))}<b>${s[k]}</b></div>`).join('');
|
||||
}
|
||||
$('pvBones').addEventListener('change', () => { viewer.setBonesVisible($('pvBones').checked); fillLegend(); });
|
||||
$('pv').addEventListener('pointermove', (e) => {
|
||||
if (!$('pvBones').checked || e.buttons) { $('pvTip').hidden = true; viewer.boneHover = -1; return; }
|
||||
const b = viewer.boneAt(e.clientX, e.clientY), tip = $('pvTip');
|
||||
tip.hidden = !b;
|
||||
if (!b) return;
|
||||
const r = $('pv').getBoundingClientRect();
|
||||
tip.innerHTML = `<div>${esc(b.name)}</div><div class="k">${esc(kindLabel(b.kind))} · ${esc(t('bParent', { p: b.parent || t('bRoot') }))}</div>`;
|
||||
tip.style.left = (e.clientX - r.left) + 'px'; tip.style.top = (e.clientY - r.top) + 'px';
|
||||
});
|
||||
$('pv').addEventListener('pointerleave', () => { $('pvTip').hidden = true; viewer.boneHover = -1; });
|
||||
|
||||
function updateLight() {
|
||||
viewer.setLight({ az: +$('lAz').value, el: +$('lEl').value, intensity: +$('lI').value, ambient: +$('lAmb').value, shadow: $('lShadow').checked });
|
||||
$('lAzV').textContent = $('lAz').value + '°'; $('lElV').textContent = $('lEl').value + '°';
|
||||
$('lIV').textContent = (+$('lI').value).toFixed(1); $('lAmbV').textContent = (+$('lAmb').value).toFixed(2);
|
||||
}
|
||||
['lAz', 'lEl', 'lI', 'lAmb', 'lShadow'].forEach((id) => $(id).addEventListener('input', updateLight));
|
||||
updateLight();
|
||||
|
||||
$('shotBtn').onclick = async () => {
|
||||
if (!viewer.loaded) return;
|
||||
const r = await api('/api/snapshot', { name: (viewer.name || 'vrm').replace(/\.[^.]+$/, ''), data: viewer.snapshot(), model: modelUrl });
|
||||
if (r.path) toast(t('saved', { path: r.path }));
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
// Run bar (start / stop / progress) and the log.
|
||||
import { $, S, api, pick, t, toast } from './core.js';
|
||||
import { renderFiles } from './files.js';
|
||||
import { flushOpts } from './options.js';
|
||||
import { T, saveTune } from './tune.js';
|
||||
|
||||
$('start').onclick = async () => {
|
||||
await flushOpts();
|
||||
if (T.dirty && T.fid) await saveTune(T.edits); // unsaved tune edits go into this conversion
|
||||
const r = await api('/api/convert', {});
|
||||
if (!r.started) toast(t('nothing'));
|
||||
S.result = null; S.logErrors = 0; renderBadge();
|
||||
};
|
||||
$('stop').onclick = () => api('/api/stop', {});
|
||||
// after a run: show where the results went (the newest output, selected in the file manager)
|
||||
const lastOutput = () => [...S.files].reverse().flatMap((f) => f.outputs.slice(-1))[0];
|
||||
$('openOut').onclick = () => { const o = lastOutput(); if (o) api('/api/open', { path: o.path }); };
|
||||
|
||||
export function renderStatus() {
|
||||
$('start').hidden = S.busy; $('stop').hidden = !S.busy;
|
||||
let s = t('idle'), pct = 0;
|
||||
if (S.busy && S.progress) {
|
||||
s = t('converting', { i: S.progress.index + 1, n: S.progress.total, name: S.progress.name });
|
||||
pct = S.progress.index / S.progress.total * 100;
|
||||
} else if (S.result) { s = t(S.result.skipped ? 'finishedSkip' : 'finished', S.result); pct = 100; }
|
||||
$('status').textContent = s;
|
||||
$('openOut').hidden = S.busy || !lastOutput();
|
||||
$('progressFill').style.width = pct + '%';
|
||||
renderFiles();
|
||||
}
|
||||
|
||||
let lastFile = null;
|
||||
// fid: the file this line belongs to. When several files convert at once their lines interleave, so a short
|
||||
// "· name" line marks each switch (a file's own first line "→ name" already says it)
|
||||
// en: the English version of the line (null when there is none); both are kept so a language switch can redo the log
|
||||
export function appendLog(msg, tag, fid, en) {
|
||||
const log = $('log');
|
||||
if (fid && fid !== lastFile && !msg.startsWith('→')) {
|
||||
const f = S.files.find((x) => x.id === fid);
|
||||
if (f) { const h = document.createElement('div'); h.className = 'file-mark'; h.textContent = '· ' + f.name; log.append(h); }
|
||||
}
|
||||
lastFile = fid || lastFile;
|
||||
const line = document.createElement('div');
|
||||
if (tag) line.className = tag;
|
||||
line.dataset.zh = msg;
|
||||
if (en) line.dataset.en = en;
|
||||
line.textContent = pick(msg, en);
|
||||
log.append(line);
|
||||
while (log.childElementCount > 3000) log.firstElementChild.remove();
|
||||
log.scrollTop = log.scrollHeight;
|
||||
if (tag === 'err') { S.logErrors++; renderBadge(); }
|
||||
}
|
||||
// after a language switch
|
||||
export function relocalizeLog() {
|
||||
for (const line of $('log').children) if (line.dataset.zh !== undefined) line.textContent = pick(line.dataset.zh, line.dataset.en);
|
||||
}
|
||||
function renderBadge() { $('logBadge').hidden = !S.logErrors; $('logBadge').textContent = S.logErrors; }
|
||||
$('logToggle').onclick = () => {
|
||||
const open = $('log').hidden;
|
||||
$('log').hidden = !open; $('logCard').classList.toggle('open', open);
|
||||
$('logToggle').setAttribute('aria-expanded', open);
|
||||
};
|
||||
$('clearLog').onclick = () => { $('log').innerHTML = ''; S.logErrors = 0; renderBadge(); };
|
||||
@@ -0,0 +1,54 @@
|
||||
// Automatic VRM thumbnails: when a file finishes converting, each of its VRMs is loaded into a hidden viewer,
|
||||
// framed on the face and saved as that model's thumbnail (the same as the Tune panel's "use current view").
|
||||
// Option vrm.auto_thumb; the server keeps a thumbnail the user set by hand (see /api/tune/thumb auto).
|
||||
import { Viewer } from '/viewer/viewer-core.js';
|
||||
import { api } from './core.js';
|
||||
import { getOpt } from './options.js';
|
||||
import { viewer } from './preview.js';
|
||||
import { modelOf } from './tune.js';
|
||||
|
||||
let tv = null, running = false;
|
||||
const queue = [];
|
||||
export let onThumb = null; // (file id) → called after a thumbnail was written
|
||||
export function setOnThumb(fn) { onThumb = fn; }
|
||||
|
||||
function thumbViewer() {
|
||||
if (!tv) {
|
||||
const box = document.createElement('div');
|
||||
box.style.cssText = 'position:fixed;left:-20000px;top:0;width:1024px;height:1024px;pointer-events:none';
|
||||
box.setAttribute('aria-hidden', 'true');
|
||||
document.body.append(box);
|
||||
tv = new Viewer(box, { loop: false, pixelRatio: 1 });
|
||||
}
|
||||
return tv;
|
||||
}
|
||||
|
||||
// a file entry that just went from running to done: one thumbnail for each of its VRMs (an archive can hold several)
|
||||
export function queueThumb(entry) {
|
||||
if (!getOpt('vrm.auto_thumb')) return;
|
||||
for (const o of (entry.outputs || []).filter((x) => x.url)) {
|
||||
const model = modelOf(o.name);
|
||||
if (!queue.some((q) => q.id === entry.id && q.model === model)) queue.push({ id: entry.id, url: o.url, name: o.name, model });
|
||||
}
|
||||
if (queue.length && !running) run();
|
||||
}
|
||||
|
||||
async function run() {
|
||||
running = true;
|
||||
while (queue.length) {
|
||||
const job = queue.shift();
|
||||
try {
|
||||
const v = thumbViewer();
|
||||
v.setBackground(viewer.scene.background);
|
||||
v.setLight({ ...viewer.light });
|
||||
await v.loadUrl(job.url, job.name);
|
||||
if (v.vrm) v.vrm.update(0);
|
||||
v.frame('face');
|
||||
const data = v.snapshotSquare(1024);
|
||||
v.clear();
|
||||
const r = await api('/api/tune/thumb', { id: job.id, data, auto: true, model: job.model });
|
||||
if (r.ok && onThumb) onThumb(job.id);
|
||||
} catch (e) { console.warn('auto thumbnail failed', job.name, e); }
|
||||
}
|
||||
running = false;
|
||||
}
|
||||
+280
@@ -0,0 +1,280 @@
|
||||
// Tune panel: per-model adjustments written into the converted VRM (convert/vrm_edit.py) — name, thumbnail,
|
||||
// which expression drives each VRM preset and how strong, gaze range, SpringBone multipliers.
|
||||
// Physics changes preview live; everything else is written on "Save" — or by itself before converting and when
|
||||
// switching to another file, so edits aren't lost when "Save" is forgotten.
|
||||
import { $, S, api, clone, errText, esc, num, presetLabel, t, toast } from './core.js';
|
||||
import { loadModel, modelUrl, showPanel, viewer } from './preview.js';
|
||||
|
||||
export const T = {
|
||||
fid: null, info: null, edits: {}, dirty: false,
|
||||
open: { meta: true, expr: true, look: true, physics: true, chains: false }, // collapsible sections (kept across models)
|
||||
};
|
||||
|
||||
// three-vrm loads VRM 0.x presets under their 1.0 names
|
||||
const V0_TO_V1 = { a: 'aa', i: 'ih', u: 'ou', e: 'ee', o: 'oh', joy: 'happy', sorrow: 'sad', fun: 'relaxed', blink_l: 'blinkLeft', blink_r: 'blinkRight' };
|
||||
|
||||
// which model of the file a VRM / preview URL or file name is (vrm_edit.model_key): thumbnails are kept per model
|
||||
export const modelOf = (s) => (s ? decodeURIComponent(s.split('?')[0].split('/').pop()).replace(/\.[^.]+$/, '') : null);
|
||||
|
||||
// switching to another file: save the unsaved tune edits of the one on screen (in the background; that file's
|
||||
// VRM isn't on screen any more). Edits are per file, so other outputs of the same file keep them unsaved.
|
||||
export function leaveTune(id) {
|
||||
if (!T.dirty || !T.fid || T.fid === id) return true;
|
||||
const fid = T.fid, edits = clone(T.edits), f = S.files.find((x) => x.id === fid);
|
||||
T.dirty = false;
|
||||
api('/api/tune/save', { id: fid, edits }).then((r) =>
|
||||
toast(r.error ? errText(r.error, r.error_en) : t('tuneAutoSaved', { name: f ? f.name : '' })));
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function loadTune() {
|
||||
if ($('tunePanel').hidden && !S.autoTune) return;
|
||||
const fid = S.current;
|
||||
if (!fid) { T.fid = null; T.info = null; renderTune(); return; }
|
||||
const r = await api('/api/tune', { id: fid, model: modelOf(modelUrl) });
|
||||
if (fid !== S.current) return;
|
||||
T.fid = fid; T.info = r; T.edits = clone(r.edits); delete T.edits.thumbnail; delete T.edits.thumbnail_auto; delete T.edits.thumbnails;
|
||||
T.dirty = false;
|
||||
if (S.autoTune && r.ready && $('tunePanel').hidden) { showPanel('tunePanel'); S.autoTune = false; }
|
||||
if (!$('tunePanel').hidden) renderTune();
|
||||
}
|
||||
|
||||
function assigned(p, edits) {
|
||||
const e = (edits || T.edits).expressions || {};
|
||||
return p in e ? e[p] : (T.info.assign[p] || '');
|
||||
}
|
||||
|
||||
// name of a source expression in the currently loaded (saved) model, for the "Try" button
|
||||
function exprNameInModel(sid) {
|
||||
const saved = clone(T.info.edits);
|
||||
const is1 = T.info.spec === '1.0';
|
||||
for (const p of T.info.presets) if (assigned(p, saved) === sid) return is1 ? p : (V0_TO_V1[p] || p);
|
||||
return sid.startsWith('@') ? 'orig_' + sid.slice(1) : sid;
|
||||
}
|
||||
|
||||
export function springParams() {
|
||||
const sp = T.edits.spring || {}, gs = num(sp.stiffness, 1), gd = num(sp.drag, 1), gg = num(sp.gravity, 0), ch = sp.chains || {};
|
||||
const out = [];
|
||||
for (const c of T.info.springs || []) {
|
||||
const e = ch[c.key] || {}, cs = num(e.stiffness, 1), cg = num(e.gravity, 0);
|
||||
for (const j of c.joints) {
|
||||
out.push({ node: j.node, enabled: !e.off, stiffness: Math.max(0, j.stiffness * gs * cs),
|
||||
gravityPower: Math.max(0, j.gravityPower + gg + cg), dragForce: Math.min(1, Math.max(0, j.dragForce * gd)) });
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function markDirty() {
|
||||
T.dirty = true;
|
||||
$('tuneState').textContent = t('tuneDirty');
|
||||
$('tuneSave').disabled = false;
|
||||
}
|
||||
|
||||
function slider(label, val, min, max, step, onInput, fmt) {
|
||||
const d = document.createElement('div'); d.className = 'field';
|
||||
d.innerHTML = `<label>${esc(label)}</label><input type="range" min="${min}" max="${max}" step="${step}" value="${val}" aria-label="${esc(label)}"><output>${fmt(val)}</output>`;
|
||||
const inp = d.querySelector('input'), o = d.querySelector('output');
|
||||
inp.addEventListener('input', () => { o.textContent = fmt(inp.value); onInput(+inp.value); });
|
||||
return d;
|
||||
}
|
||||
const fmtMul = (v) => '×' + (+v).toFixed(2), fmtAdd = (v) => '+' + (+v).toFixed(2), fmtDeg = (v) => (+v).toFixed(1) + '°';
|
||||
const hint = (text) => { const d = document.createElement('div'); d.className = 'hint flush'; d.textContent = text; return d; };
|
||||
|
||||
// a collapsible section; its open / closed state is remembered in T.open
|
||||
function section(parent, key, title) {
|
||||
const d = document.createElement('details'); d.className = 'sec'; d.open = T.open[key];
|
||||
d.addEventListener('toggle', () => { T.open[key] = d.open; });
|
||||
const s = document.createElement('summary'); s.textContent = title;
|
||||
d.append(s); parent.append(d);
|
||||
return d;
|
||||
}
|
||||
|
||||
export function renderTune() {
|
||||
const body = $('tuneBody');
|
||||
const keep = T.renderedFid === T.fid ? body.scrollTop : 0; // re-render (reset / thumbnail …) stays in place
|
||||
T.renderedFid = T.fid;
|
||||
requestAnimationFrame(() => { body.scrollTop = keep; });
|
||||
body.innerHTML = '';
|
||||
const msg = (text) => { body.innerHTML = `<div class="tune-msg">${esc(text)}</div>`; $('tuneFoot').hidden = true; };
|
||||
if (!T.info || T.fid !== S.current) return msg(t('tuneNoFile'));
|
||||
if (T.info.error) return msg(errText(T.info.error, T.info.error_en));
|
||||
if (T.info.editable === false) return msg(t('tuneNotEditable'));
|
||||
if (!T.info.ready) {
|
||||
const f = S.files.find((x) => x.id === T.fid);
|
||||
return msg(t(f && f.kind === 'pmx' ? 'tuneNotReadyPmx' : 'tuneNotReady'));
|
||||
}
|
||||
$('tuneFoot').hidden = false;
|
||||
$('tuneState').textContent = T.dirty ? t('tuneDirty') : t('tuneClean');
|
||||
$('tuneSave').disabled = !T.dirty;
|
||||
renderMeta(section(body, 'meta', t('tuneMeta')));
|
||||
renderExpr(section(body, 'expr', t('tuneExpr')));
|
||||
if (T.info.look) renderLook(section(body, 'look', t('tuneLook')));
|
||||
if ((T.info.springs || []).length) renderPhysics(section(body, 'physics', t('tunePhysics')));
|
||||
}
|
||||
|
||||
// ---- name + thumbnail (the thumbnail is saved right away: it is a picture of the current view)
|
||||
function renderMeta(sec) {
|
||||
const nf = document.createElement('div'); nf.className = 'field';
|
||||
nf.innerHTML = `<label>${esc(t('tuneTitle'))}</label><input type="text" class="input" placeholder="${esc(T.info.title || '')}" value="${esc(T.edits.title || '')}">`;
|
||||
nf.querySelector('input').addEventListener('input', (e) => { T.edits.title = e.target.value.trim(); markDirty(); });
|
||||
const tr = document.createElement('div'); tr.className = 'thumb-row';
|
||||
tr.innerHTML = (T.info.thumbnail ? `<img src="${T.info.thumbnail}" alt="">` : `<div class="noimg">${t('thumbNone')}</div>`) +
|
||||
`<div class="col"><div><button class="btn small" data-a="shot">${t('thumbFromView')}</button> ` +
|
||||
(T.info.thumbnail ? `<button class="btn small ghost" data-a="rm">${t('thumbRemove')}</button>` : '') +
|
||||
(T.info.thumbnail && T.info.thumbnail_auto ? `<span class="hint">${t('thumbAuto')}</span>` : '') +
|
||||
`</div><div class="hint flush">${t('thumbHint')}</div></div>`;
|
||||
tr.addEventListener('click', async (e) => {
|
||||
const a = e.target.dataset.a;
|
||||
if (!a || !viewer.loaded) return;
|
||||
const r = await api('/api/tune/thumb', { id: T.fid, data: a === 'shot' ? viewer.snapshotSquare(1024) : '', model: modelOf(modelUrl) });
|
||||
if (r.error) return toast(errText(r.error, r.error_en));
|
||||
T.info.thumbnail = r.thumbnail || null;
|
||||
T.info.thumbnail_auto = false; // set by hand now: never replaced automatically
|
||||
toast(t('thumbSaved'));
|
||||
renderTune();
|
||||
});
|
||||
sec.append(nf, tr);
|
||||
}
|
||||
|
||||
// ---- which expression drives each preset, and how strong
|
||||
function renderExpr(sec) {
|
||||
sec.append(hint(t('exprHint')));
|
||||
const tryExpr = (sid, w) => {
|
||||
if (!sid) return;
|
||||
viewer.resetExpressions(); viewer.setExpression(exprNameInModel(sid), w);
|
||||
clearTimeout(renderTune.tryTimer); renderTune.tryTimer = setTimeout(() => viewer.resetExpressions(), 1500);
|
||||
};
|
||||
const choices = T.info.expressions.map((x) => `<option value="${esc(x.id)}">${esc(x.label)}</option>`).join('');
|
||||
// gaze presets are driven by the gaze range below, not picked here
|
||||
for (const p of (T.info.presets || []).filter((x) => !/^look/i.test(x))) {
|
||||
const base = T.info.assign[p] || '';
|
||||
const none = `<option value="">${esc(t(base ? 'exprNone' : 'exprMissing'))}</option>`;
|
||||
const d = document.createElement('div'); d.className = 'field preset';
|
||||
const k = num((T.edits.intensity || {})[p], 1);
|
||||
d.innerHTML = `<label title="${esc(p)}">${esc(presetLabel(p))}</label><select aria-label="${esc(presetLabel(p))}">${none}${choices}</select>` +
|
||||
`<input type="range" class="strength" min="0" max="1.5" step="0.05" value="${k}" title="${esc(t('exprStrength'))}" aria-label="${esc(t('exprStrength'))}">` +
|
||||
`<output class="strength">${Math.round(k * 100)}%</output><button class="mini" title="${esc(t('tryExpr'))}" aria-label="${esc(t('tryExpr'))}">▶</button>`;
|
||||
const sel = d.querySelector('select'), rng = d.querySelector('input'), out = d.querySelector('output');
|
||||
const sync = () => {
|
||||
sel.classList.toggle('changed', sel.value !== base);
|
||||
sel.title = sel.selectedOptions[0] ? sel.selectedOptions[0].textContent : ''; // combos are long: full text on hover
|
||||
d.classList.toggle('missing', !sel.value);
|
||||
rng.classList.toggle('changed', +rng.value !== 1);
|
||||
};
|
||||
sel.value = assigned(p);
|
||||
sync();
|
||||
rng.addEventListener('input', () => {
|
||||
const v = +rng.value;
|
||||
out.textContent = Math.round(v * 100) + '%';
|
||||
T.edits.intensity = T.edits.intensity || {};
|
||||
if (v === 1) delete T.edits.intensity[p]; else T.edits.intensity[p] = v;
|
||||
sync(); tryExpr(sel.value, v); markDirty();
|
||||
});
|
||||
sel.addEventListener('change', () => {
|
||||
T.edits.expressions = T.edits.expressions || {};
|
||||
if (sel.value === base) delete T.edits.expressions[p]; else T.edits.expressions[p] = sel.value;
|
||||
sync(); markDirty();
|
||||
});
|
||||
d.querySelector('button').addEventListener('click', () => tryExpr(sel.value, +rng.value));
|
||||
sec.append(d);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- gaze range (VRM look-at max angles; also re-weights the added gaze expressions)
|
||||
function renderLook(sec) {
|
||||
sec.append(hint(t('lookHint')));
|
||||
const cur = () => Object.assign({}, T.info.look, T.edits.lookAt || {});
|
||||
// yaw / pitch for each preview arrow, as seen on screen from the front (VRM look-at input:
|
||||
// +yaw = the model's own left = screen right; ±90 = full range)
|
||||
const peek = (dir) => {
|
||||
const [yaw, pitch] = { left: [-90, 0], right: [90, 0], up: [0, 90], down: [0, -90] }[dir];
|
||||
viewer.setLook(yaw, pitch, cur());
|
||||
clearTimeout(renderTune.lookTimer); renderTune.lookTimer = setTimeout(() => viewer.setLook(null), 1500);
|
||||
};
|
||||
const set = (key, v) => { T.edits.lookAt = Object.assign(cur(), { [key]: v }); markDirty(); };
|
||||
sec.append(slider(t('lookH'), cur().h, 0, 40, 0.5, (v) => { set('h', v); peek('left'); }, fmtDeg),
|
||||
slider(t('lookDown'), cur().down, 0, 30, 0.5, (v) => { set('down', v); peek('down'); }, fmtDeg),
|
||||
slider(t('lookUp'), cur().up, 0, 30, 0.5, (v) => { set('up', v); peek('up'); }, fmtDeg));
|
||||
const row = document.createElement('div'); row.className = 'field';
|
||||
row.innerHTML = `<label></label>` + ['left', 'right', 'up', 'down'].map((d) =>
|
||||
`<button class="mini" data-d="${d}" title="${esc(t('lookTry'))}" aria-label="${esc(t('lookTry'))}">${{ left: '◀', right: '▶', up: '▲', down: '▼' }[d]}</button>`).join(' ') +
|
||||
(T.edits.lookAt ? ` <button class="btn small ghost" data-d="reset">${esc(t('lookReset'))}</button>` : '');
|
||||
row.addEventListener('click', (e) => {
|
||||
const d = e.target.dataset.d;
|
||||
if (!d) return;
|
||||
if (d === 'reset') { delete T.edits.lookAt; markDirty(); renderTune(); return; }
|
||||
peek(d);
|
||||
});
|
||||
sec.append(row);
|
||||
}
|
||||
|
||||
// ---- physics (VRM 1.0 SpringBone / 0.x spring groups): overall multipliers, then each chain (collapsed by default)
|
||||
// the chain kept shown in the preview (pin button), per file; hovering another chain shows that one meanwhile
|
||||
let pinned = null; // { fid, key, nodes }
|
||||
const pinnedNodes = () => (pinned && pinned.fid === T.fid ? pinned.nodes : null);
|
||||
const ICON_EYE = '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M1 8s2.5-5 7-5 7 5 7 5-2.5 5-7 5-7-5-7-5z"/><circle cx="8" cy="8" r="2"/></svg>';
|
||||
const ICON_AIM = '<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="5"/><path d="M8 1v3M8 12v3M1 8h3M12 8h3"/></svg>';
|
||||
|
||||
function renderPhysics(sec) {
|
||||
if (pinned && (pinned.fid !== T.fid || !T.info.springs.some((c) => c.key === pinned.key))) pinned = null;
|
||||
viewer.highlightChain(pinnedNodes());
|
||||
const sp = T.edits.spring = T.edits.spring || {};
|
||||
sp.chains = sp.chains || {};
|
||||
const live = () => { viewer.setSpringParams(springParams()); markDirty(); };
|
||||
sec.append(hint(t('allChains')),
|
||||
slider(t('stiffMul'), num(sp.stiffness, 1), 0.2, 3, 0.05, (v) => { sp.stiffness = v; live(); }, fmtMul),
|
||||
slider(t('dragMul'), num(sp.drag, 1), 0.2, 2, 0.05, (v) => { sp.drag = v; live(); }, fmtMul),
|
||||
slider(t('gravAdd'), num(sp.gravity, 0), 0, 1, 0.02, (v) => { sp.gravity = v; live(); }, fmtAdd));
|
||||
const chains = section(sec, 'chains', t('chains', { n: T.info.springs.length }));
|
||||
const flt = document.createElement('div'); flt.className = 'field';
|
||||
flt.innerHTML = `<input class="input" placeholder="${esc(t('filter'))}" aria-label="${esc(t('filter'))}">`;
|
||||
const list = document.createElement('div'); list.className = 'chain-list';
|
||||
chains.append(flt, list);
|
||||
for (const c of T.info.springs) {
|
||||
const e = sp.chains[c.key] || {};
|
||||
const get = () => (sp.chains[c.key] = sp.chains[c.key] || {});
|
||||
const row = document.createElement('div'); row.className = 'chain' + (e.off ? ' off' : ''); row.dataset.name = c.name.toLowerCase();
|
||||
const nodes = c.joints.map((j) => j.node);
|
||||
row.classList.toggle('pinned', !!pinned && pinned.fid === T.fid && pinned.key === c.key);
|
||||
const head = document.createElement('div'); head.className = 'chain-head';
|
||||
const pin = document.createElement('button'); pin.className = 'ibtn' + (row.classList.contains('pinned') ? ' on' : '');
|
||||
pin.innerHTML = ICON_EYE; pin.title = t('pinChain'); pin.setAttribute('aria-label', t('pinChain'));
|
||||
pin.onclick = () => {
|
||||
const on = !row.classList.contains('pinned');
|
||||
list.querySelectorAll('.chain.pinned').forEach((r) => { r.classList.remove('pinned'); r.querySelector('.ibtn').classList.remove('on'); });
|
||||
pinned = on ? { fid: T.fid, key: c.key, nodes } : null;
|
||||
row.classList.toggle('pinned', on); pin.classList.toggle('on', on);
|
||||
viewer.highlightChain(on ? nodes : null);
|
||||
};
|
||||
const aim = document.createElement('button'); aim.className = 'ibtn';
|
||||
aim.innerHTML = ICON_AIM; aim.title = t('focusChain'); aim.setAttribute('aria-label', t('focusChain'));
|
||||
aim.onclick = () => viewer.focusChain(nodes);
|
||||
const sw = document.createElement('label'); sw.className = 'switch';
|
||||
sw.innerHTML = `<input type="checkbox" ${e.off ? '' : 'checked'}><span title="${esc(c.name)}">${esc(c.name)} · ${c.joints.length}</span>`;
|
||||
sw.querySelector('input').addEventListener('change', (ev) => { get().off = !ev.target.checked; row.classList.toggle('off', !ev.target.checked); live(); });
|
||||
head.append(sw, pin, aim);
|
||||
row.append(head,
|
||||
slider(t('stiffMul'), num(e.stiffness, 1), 0.2, 3, 0.05, (v) => { get().stiffness = v; live(); }, fmtMul),
|
||||
slider(t('gravAdd'), num(e.gravity, 0), 0, 1, 0.02, (v) => { get().gravity = v; live(); }, fmtAdd));
|
||||
// hovering a chain shows it in the preview (joints, hit radius, its colliders)
|
||||
row.addEventListener('pointerenter', () => viewer.highlightChain(nodes));
|
||||
row.addEventListener('pointerleave', () => viewer.highlightChain(pinnedNodes()));
|
||||
list.append(row);
|
||||
}
|
||||
flt.querySelector('input').addEventListener('input', (ev) => {
|
||||
const q = ev.target.value.trim().toLowerCase();
|
||||
for (const r of list.children) r.style.display = !q || r.dataset.name.includes(q) ? '' : 'none';
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveTune(edits) {
|
||||
const r = await api('/api/tune/save', { id: T.fid, edits });
|
||||
if (r.error) return toast(errText(r.error, r.error_en));
|
||||
toast(r.applied ? t('tuneSaved', { n: r.applied }) : t('tuneSavedNone'));
|
||||
T.dirty = false;
|
||||
if (modelUrl && r.applied) await loadModel(modelUrl, viewer.name, true);
|
||||
await loadTune();
|
||||
}
|
||||
$('tuneSave').onclick = () => saveTune(T.edits);
|
||||
$('tuneReset').onclick = () => { T.edits = {}; saveTune({}); };
|
||||
Reference in New Issue
Block a user