Spaces:
Running
Running
Fix v119 runtime: clone copy button and robust pose hold
Browse files- v119-runtime.js +24 -36
v119-runtime.js
CHANGED
|
@@ -1,52 +1,40 @@
|
|
| 1 |
-
// v119-runtime.js:
|
| 2 |
(function(){
|
| 3 |
const VER='v119';
|
|
|
|
| 4 |
function log(m,l){try{(window.__dbg||console.log)(m,l||'info')}catch(e){console.log(m)}}
|
| 5 |
function setVer(){try{document.title='MMD pmx Player '+VER;const v=document.getElementById('version-label');if(v)v.textContent=VER}catch(e){}}
|
| 6 |
-
function
|
| 7 |
function flash(btn,ok){try{btn.textContent=ok?'✅コピー完了':'⚠コピー失敗';btn.style.background=ok?'#064':'#700';btn.style.color='#fff';setTimeout(()=>{btn.textContent='📋 Copy All';btn.style.background='';btn.style.color=''},1800)}catch(e){}}
|
| 8 |
-
function fallbackCopy(txt){
|
| 9 |
-
try{
|
| 10 |
-
const ta=document.createElement('textarea');
|
| 11 |
-
ta.value=txt;ta.readOnly=true;ta.setAttribute('readonly','');
|
| 12 |
-
ta.style.position='fixed';ta.style.left='8px';ta.style.top='8px';ta.style.width='2px';ta.style.height='2px';ta.style.opacity='0.01';ta.style.zIndex='999999';
|
| 13 |
-
document.body.appendChild(ta);ta.focus({preventScroll:true});ta.select();ta.setSelectionRange(0,ta.value.length);
|
| 14 |
-
const ok=document.execCommand('copy');document.body.removeChild(ta);return !!ok;
|
| 15 |
-
}catch(e){return false}
|
| 16 |
-
}
|
| 17 |
function copyNow(e){
|
| 18 |
-
if(e){try{e.preventDefault()}catch(_){ }
|
|
|
|
| 19 |
const btn=document.getElementById('debug-copy-btn'); if(!btn)return;
|
| 20 |
-
const txt=
|
| 21 |
-
|
| 22 |
-
if(
|
| 23 |
-
|
| 24 |
-
navigator.clipboard.writeText(txt).then(()=>{flash(btn,true);log('[Copy:'+VER+'] clipboard copy ok len='+txt.length,'info')}).catch(err=>{flash(btn,false);log('[Copy:'+VER+'] copy failed '+(err&&err.message?err.message:String(err)),'warn')});
|
| 25 |
-
}else{flash(btn,false);log('[Copy:'+VER+'] copy failed no clipboard','warn')}
|
| 26 |
}
|
| 27 |
function bindCopy(){
|
| 28 |
-
const
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
}
|
| 32 |
function clearMotionInput(id,why){const el=document.getElementById(id);if(el){el.value='';log('[Motion:'+VER+'] '+id+' cleared ('+why+')','info')}}
|
|
|
|
|
|
|
| 33 |
function bindMotionInputs(){
|
| 34 |
-
[['file-input','vmd-input'],['file-input2','vmd-input2']].forEach(([modelId,motionId])=>{const m=document.getElementById(modelId);if(m&&!m.
|
| 35 |
-
['vmd-input','vmd-input2','cam-vmd-input'].forEach(id=>{const el=document.getElementById(id);if(!el||el.
|
| 36 |
-
}
|
| 37 |
-
function guessMeshFromInput(input){return input&&input.id==='vmd-input2'?window.mesh2:window.mesh}
|
| 38 |
-
function holdPose(mesh){
|
| 39 |
-
if(!mesh||!window.helper||!window.helper.objects)return;
|
| 40 |
-
try{
|
| 41 |
-
const obj=window.helper.objects.get(mesh);
|
| 42 |
-
if(obj&&obj.mixer){obj.mixer.stopAllAction();obj.mixer.time=0;obj.mixer.timeScale=0;log('[VPD:'+VER+'] stopped mixer for pose hold','info')}
|
| 43 |
-
mesh.userData.__v119PoseHold=true;
|
| 44 |
-
}catch(e){log('[VPD:'+VER+'] pose hold failed '+e.message,'warn')}
|
| 45 |
-
}
|
| 46 |
-
function bindVpdHold(){
|
| 47 |
-
['vmd-input','vmd-input2'].forEach(id=>{const el=document.getElementById(id);if(!el||el.__v119VpdHold)return;el.__v119VpdHold=true;el.addEventListener('change',()=>{const files=Array.from(el.files||[]);if(files.some(f=>/\.vpd$/i.test(f.name||''))){const mesh=guessMeshFromInput(el);setTimeout(()=>holdPose(mesh),900);setTimeout(()=>holdPose(mesh),1800);log('[VPD:'+VER+'] VPD detected, pose hold scheduled for '+id,'info')}},false)})
|
| 48 |
}
|
| 49 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
function wait(){if(window.__appReady)bind();else setTimeout(wait,100)}
|
| 51 |
wait();
|
| 52 |
})();
|
|
|
|
| 1 |
+
// v119-runtime.js FIXED: single copy handler via button clone + VPD pose hold. v117 stable internals untouched.
|
| 2 |
(function(){
|
| 3 |
const VER='v119';
|
| 4 |
+
let lastCopyAt=0;
|
| 5 |
function log(m,l){try{(window.__dbg||console.log)(m,l||'info')}catch(e){console.log(m)}}
|
| 6 |
function setVer(){try{document.title='MMD pmx Player '+VER;const v=document.getElementById('version-label');if(v)v.textContent=VER}catch(e){}}
|
| 7 |
+
function logText(){const el=document.getElementById('debug-log');return el?(el.innerText||el.textContent||''):''}
|
| 8 |
function flash(btn,ok){try{btn.textContent=ok?'✅コピー完了':'⚠コピー失敗';btn.style.background=ok?'#064':'#700';btn.style.color='#fff';setTimeout(()=>{btn.textContent='📋 Copy All';btn.style.background='';btn.style.color=''},1800)}catch(e){}}
|
| 9 |
+
function fallbackCopy(txt){try{const ta=document.createElement('textarea');ta.value=txt;ta.readOnly=true;ta.setAttribute('readonly','');ta.style.position='fixed';ta.style.left='8px';ta.style.top='8px';ta.style.width='2px';ta.style.height='2px';ta.style.opacity='0.01';ta.style.zIndex='999999';document.body.appendChild(ta);ta.focus({preventScroll:true});ta.select();ta.setSelectionRange(0,ta.value.length);const ok=document.execCommand('copy');document.body.removeChild(ta);return !!ok}catch(e){return false}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
function copyNow(e){
|
| 11 |
+
if(e){try{e.preventDefault()}catch(_){ }try{e.stopImmediatePropagation()}catch(_){ }try{e.stopPropagation()}catch(_){ }}
|
| 12 |
+
const now=Date.now(); if(now-lastCopyAt<1000)return; lastCopyAt=now;
|
| 13 |
const btn=document.getElementById('debug-copy-btn'); if(!btn)return;
|
| 14 |
+
const txt=logText();
|
| 15 |
+
if(fallbackCopy(txt)){flash(btn,true);log('[Copy:'+VER+'] copy ok len='+txt.length,'info');return}
|
| 16 |
+
if(navigator.clipboard&&navigator.clipboard.writeText){navigator.clipboard.writeText(txt).then(()=>{flash(btn,true);log('[Copy:'+VER+'] async copy ok len='+txt.length,'info')}).catch(err=>{flash(btn,false);log('[Copy:'+VER+'] copy failed '+(err&&err.message?err.message:String(err)),'warn')})}
|
| 17 |
+
else{flash(btn,false);log('[Copy:'+VER+'] copy failed no clipboard','warn')}
|
|
|
|
|
|
|
| 18 |
}
|
| 19 |
function bindCopy(){
|
| 20 |
+
const old=document.getElementById('debug-copy-btn'); if(!old||old.__v119FixedCopy)return;
|
| 21 |
+
const btn=old.cloneNode(true); btn.__v119FixedCopy=true; old.replaceWith(btn);
|
| 22 |
+
btn.addEventListener('touchend',copyNow,{capture:true,passive:false});
|
| 23 |
+
btn.addEventListener('click',copyNow,{capture:true,passive:false});
|
| 24 |
+
log('[Copy:'+VER+'] fixed single-handler copy enabled','info')
|
| 25 |
}
|
| 26 |
function clearMotionInput(id,why){const el=document.getElementById(id);if(el){el.value='';log('[Motion:'+VER+'] '+id+' cleared ('+why+')','info')}}
|
| 27 |
+
function targetFromInput(el){return el&&el.id==='vmd-input2'?window.mesh2:window.mesh}
|
| 28 |
+
function clearPoseMode(mesh,why){if(mesh&&mesh.userData){delete mesh.userData.__v119PoseHold;delete mesh.userData.__v119PoseBones;log('[VPD:'+VER+'] pose hold cleared '+why,'info')}}
|
| 29 |
function bindMotionInputs(){
|
| 30 |
+
[['file-input','vmd-input'],['file-input2','vmd-input2']].forEach(([modelId,motionId])=>{const m=document.getElementById(modelId);if(m&&!m.__v119FixedModelClear){m.__v119FixedModelClear=true;m.addEventListener('change',()=>clearMotionInput(motionId,'model slot changed'),true)}});
|
| 31 |
+
['vmd-input','vmd-input2','cam-vmd-input'].forEach(id=>{const el=document.getElementById(id);if(!el||el.__v119FixedSameFile)return;el.__v119FixedSameFile=true;['click','touchstart','pointerdown'].forEach(ev=>el.addEventListener(ev,()=>{try{el.value=''}catch(e){};log('[Motion:'+VER+'] '+id+' cleared before picker','info')},{capture:true,passive:true}));el.addEventListener('change',()=>{const files=Array.from(el.files||[]);if(files.some(f=>/\.vmd$/i.test(f.name||'')))clearPoseMode(targetFromInput(el),'because VMD selected');setTimeout(()=>{try{el.value=''}catch(e){}},0)},false)});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
}
|
| 33 |
+
function savePose(mesh){if(!mesh||!mesh.skeleton)return;mesh.userData.__v119PoseBones=mesh.skeleton.bones.map(b=>({b:b,p:b.position.clone(),q:b.quaternion.clone(),s:b.scale.clone()}));mesh.userData.__v119PoseHold=true;log('[VPD:'+VER+'] pose saved bones='+mesh.userData.__v119PoseBones.length,'info')}
|
| 34 |
+
function applySavedPose(mesh){const arr=mesh&&mesh.userData&&mesh.userData.__v119PoseBones;if(!arr)return;arr.forEach(d=>{if(!d.b)return;d.b.position.copy(d.p);d.b.quaternion.copy(d.q);d.b.scale.copy(d.s);d.b.updateMatrix()});if(mesh.skeleton)mesh.skeleton.update();mesh.updateMatrixWorld(true)}
|
| 35 |
+
function stopMixer(mesh){try{const obj=window.helper&&window.helper.objects&&window.helper.objects.get(mesh);if(obj&&obj.mixer){obj.mixer.stopAllAction();obj.mixer.timeScale=0;obj.mixer.time=0;log('[VPD:'+VER+'] mixer stopped for pose hold','info')}}catch(e){log('[VPD:'+VER+'] mixer stop failed '+e.message,'warn')}}
|
| 36 |
+
async function patchHelper(){try{const mod=await import('three/examples/jsm/animation/MMDAnimationHelper');const H=mod.MMDAnimationHelper;if(!H||H.prototype.__v119FixedPosePatch)return;H.prototype.__v119FixedPosePatch=true;const oldPose=H.prototype.pose;H.prototype.pose=function(mesh,vpd,params){const r=oldPose.call(this,mesh,vpd,params);setTimeout(()=>{stopMixer(mesh);savePose(mesh);applySavedPose(mesh)},0);setTimeout(()=>{stopMixer(mesh);applySavedPose(mesh)},250);return r};const oldUpdate=H.prototype.update;H.prototype.update=function(delta){const r=oldUpdate.call(this,delta);try{[window.mesh,window.mesh2].concat(window.__mmdMeshes||[]).filter(Boolean).forEach(m=>{if(m.userData&&m.userData.__v119PoseHold)applySavedPose(m)})}catch(e){}return r};log('[VPD:'+VER+'] helper pose/update fixed patch enabled','info')}catch(e){log('[VPD:'+VER+'] helper patch failed '+e.message,'error')}}
|
| 37 |
+
function bind(){setVer();setTimeout(setVer,500);setTimeout(setVer,1500);bindCopy();bindMotionInputs();patchHelper();log('[Runtime:'+VER+'] FIXED copy + motion + VPD pose-hold enabled','info')}
|
| 38 |
function wait(){if(window.__appReady)bind();else setTimeout(wait,100)}
|
| 39 |
wait();
|
| 40 |
})();
|