clipoox-render 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/package.json +1 -1
  2. package/scripts/render-local.mjs +1480 -1479
  3. package/web/assets/FxEmbed-BymBArNa.js +1 -0
  4. package/web/assets/MotionEmbed-PmXWSWe5.js +1 -0
  5. package/web/assets/PluginStore-BVsm6n6N.js +3 -0
  6. package/web/assets/{ShotComposer-AHScyNYv.js → ShotComposer-Dprx-Yi7.js} +4 -4
  7. package/web/assets/TemplateEmbed-CrZXoUk_.js +2 -0
  8. package/web/assets/{TimelinePlugins-CkP5P9b_.js → TimelinePlugins-B1KGtbmb.js} +3 -3
  9. package/web/assets/TimelineShotFx-DoLx312Y.js +2 -0
  10. package/web/assets/TransitionEmbed-C5SUosv2.js +1 -0
  11. package/web/assets/{Whiteboard-C9Mwa3nF.js → Whiteboard-DybaKCdo.js} +3 -3
  12. package/web/assets/aerial-DSt_mJNA.js +2 -0
  13. package/web/assets/agentTools-CxZqRLeR.js +2 -0
  14. package/web/assets/analyzerRun-DCJwb_-Z.js +1 -0
  15. package/web/assets/{analyzerSandbox-DQGHjUCa.js → analyzerSandbox-DO5ZTv5q.js} +2 -2
  16. package/web/assets/{api-C5pOWyBM.js → api-BsKbf3l3.js} +4 -4
  17. package/web/assets/auraTrack-QR0WqBHp.js +1 -0
  18. package/web/assets/breakthrough-Dv1bndQb.js +2 -0
  19. package/web/assets/{cameraPresets-CeStHDvF.js → cameraPresets-B234aNzE.js} +1 -1
  20. package/web/assets/{captionLayout-BAdmqwdS.js → captionLayout-CNgb471H.js} +1 -1
  21. package/web/assets/clientExport-NtJmxOYP.js +1 -0
  22. package/web/assets/{depthEstimate-1OjTo_pb.js → depthEstimate-wVYSJtW8.js} +1 -1
  23. package/web/assets/directorTools-BqFcShgT.js +1 -0
  24. package/web/assets/{distortFrames-D39fkQ_H.js → distortFrames-D3TQNcJA.js} +2 -2
  25. package/web/assets/{distortGL-5uNfls9s.js → distortGL-BklPDXPq.js} +1 -1
  26. package/web/assets/editTools-BQlG5WB_.js +1 -0
  27. package/web/assets/exportEncode-CaKEPgsy.js +1 -0
  28. package/web/assets/exportGlb-DstxwzH5.js +2 -0
  29. package/web/assets/faceTracker-DWxxieVC.js +1 -0
  30. package/web/assets/fightDirector-OMlPZgjv.js +1 -0
  31. package/web/assets/fightDrama-G7bXfpQu.js +2 -0
  32. package/web/assets/{frameSink-CB1EghW0.js → frameSink-Dj71jCRb.js} +3 -3
  33. package/web/assets/{gpuCompose-EfzSAeMh.js → gpuCompose-DIxBHlTa.js} +1 -1
  34. package/web/assets/gpuExport-CPSw_dmq.js +189 -0
  35. package/web/assets/handMatte-DHsHHz4m.js +1 -0
  36. package/web/assets/handTracker-D_O-C4Dw.js +2 -0
  37. package/web/assets/{index-BGZJld3s.js → index-CZn97Ygs.js} +1 -1
  38. package/web/assets/layer-worker-Bar7WgOA.js +5 -0
  39. package/web/assets/library-BtBrCaFk.js +1 -0
  40. package/web/assets/{lottieLayer-BhLbZOpr.js → lottieLayer-CfUPParC.js} +4 -4
  41. package/web/assets/{lottie_light_canvas-D9fsNLID.js → lottie_light_canvas-7iv3btPX.js} +1 -1
  42. package/web/assets/main-BPmr0TOL.css +1 -0
  43. package/web/assets/{main-BNZrzSIG.js → main-M1vRa-gd.js} +32 -32
  44. package/web/assets/{mapBake-BAG6i5fI.js → mapBake-lPNhNZgv.js} +1 -1
  45. package/web/assets/maskTrack-D2jUh7aw.js +1 -0
  46. package/web/assets/matteFixRun-B7tWV9Y1.js +1 -0
  47. package/web/assets/motionBlur-uAm030t9.js +1 -0
  48. package/web/assets/{objectLocate-Dhktxe5z.js → objectLocate-BDqfSo9J.js} +1 -1
  49. package/web/assets/pendingMatte-q35zVaiB.js +2 -0
  50. package/web/assets/personAi-ZjQVo-80.js +2 -0
  51. package/web/assets/plateCamera-A2E_WO_x.js +1 -0
  52. package/web/assets/plateCameraMatch-D41LQrsm.js +2 -0
  53. package/web/assets/plateFollow-CNfi4xuP.js +2 -0
  54. package/web/assets/plateMatte-BdIxGhw5.js +2 -0
  55. package/web/assets/{pluginAutomation-DdZOnpoV.js → pluginAutomation-BtQ_w2TB.js} +1 -1
  56. package/web/assets/poseTracker-DVX__OK7.js +1 -0
  57. package/web/assets/productTools-r2RgILaA.js +2 -0
  58. package/web/assets/{remote-DXG553d8.js → remote-sTZauTqM.js} +77 -77
  59. package/web/assets/rigTrack-Bx9QHlFv.js +1 -0
  60. package/web/assets/{rotoMaskStore-DrRawyH9.js → rotoMaskStore-pxpRt5Cj.js} +1 -1
  61. package/web/assets/{rotoMatte-2EcyuvBX.js → rotoMatte-DyXlW4jK.js} +1 -1
  62. package/web/assets/rotoscope-GORCSVBr.js +1 -0
  63. package/web/assets/shot-worker-B8JWkmBz.js +1 -0
  64. package/web/assets/{shotFxAgent-CETPcjzU.js → shotFxAgent-CzHfe75S.js} +2 -2
  65. package/web/assets/{skin-BQG1Iz6Q.js → skin-BkaT2QuX.js} +1 -1
  66. package/web/assets/{spark.module-CMSPLU2n.js → spark.module-BRT8yMS4.js} +10 -10
  67. package/web/assets/spellDuel-BUy289OT.js +2 -0
  68. package/web/assets/{store-Dxq3MZF3.js → store-BSSbvpzr.js} +1 -1
  69. package/web/assets/{surfaceLight-B_OSTxcx.js → surfaceLight-CMaBhZ_d.js} +1 -1
  70. package/web/assets/surfacePin-DM9b9ubh.js +2 -0
  71. package/web/assets/textAnimators-Cihw35O8.js +1 -0
  72. package/web/assets/{thumb-xLFX6lDN.js → thumb-Cs636sYt.js} +1 -1
  73. package/web/assets/{timeline3d-DqXTKdEK.js → timeline3d-BEuZZOxM.js} +2 -2
  74. package/web/assets/{timeline3dExport-MWomW4fF.js → timeline3dExport-CmSI_pjv.js} +1 -1
  75. package/web/assets/timelineComp-CRRzLazc.js +1 -0
  76. package/web/assets/timelineProps-tN2YsMYN.js +1 -0
  77. package/web/assets/timelineText-CkoUgWcY.js +1 -0
  78. package/web/assets/{titleArt-CAOxtyHl.js → titleArt-CcTdJuOC.js} +5 -5
  79. package/web/assets/{titleFrameBudget-BjW--v_T.js → titleFrameBudget-3MFHWIT6.js} +1 -1
  80. package/web/assets/titleFrames-w-iWje9N.js +1 -0
  81. package/web/assets/{tool-DEWWeyCz.js → tool-BhIsq238.js} +1 -1
  82. package/web/assets/tools-DMUnabc_.js +1 -0
  83. package/web/assets/toonTools-CICrV3QB.js +2 -0
  84. package/web/assets/trackAnchor-D2bB5mZE.js +1 -0
  85. package/web/assets/userFonts-BZ4QL-zq.js +1 -0
  86. package/web/assets/{vfxAlpha-vbbI-03F.js → vfxAlpha-D3Dk1tfF.js} +2 -2
  87. package/web/assets/vfxBackground-CHlCg8lb.js +2 -0
  88. package/web/assets/{vfxTrack-BmxWjlDi.js → vfxTrack-CqiQDEYm.js} +1 -1
  89. package/web/assets/videoExport-l5MGvMn_.js +1 -0
  90. package/web/assets/views-BdWnG2xK.js +1 -0
  91. package/web/assets/weaponDuel-B2wTffPC.js +1 -0
  92. package/web/assets/{windowFrames-DydW5Al5.js → windowFrames-CoIyWqxr.js} +1 -1
  93. package/web/layer-worker.html +3 -3
  94. package/web/assets/FxEmbed-B5TQxKxk.js +0 -1
  95. package/web/assets/MotionEmbed-Catb_GgA.js +0 -1
  96. package/web/assets/PluginStore-8TjQawtB.js +0 -3
  97. package/web/assets/TemplateEmbed-Cao8Z5fY.js +0 -2
  98. package/web/assets/TimelineShotFx-DvmPZQXM.js +0 -2
  99. package/web/assets/TransitionEmbed-o4UxJ35e.js +0 -1
  100. package/web/assets/aerial-BPRLPci2.js +0 -2
  101. package/web/assets/agentTools-CSnN-LvS.js +0 -2
  102. package/web/assets/analyzerRun-5zJsmMS1.js +0 -1
  103. package/web/assets/auraTrack-pF-WhpH3.js +0 -1
  104. package/web/assets/breakthrough-DQN1i-Pw.js +0 -2
  105. package/web/assets/clientExport-Ca9a3Jiy.js +0 -1
  106. package/web/assets/directorTools-CvmghG_6.js +0 -1
  107. package/web/assets/editTools-CUoVvupD.js +0 -1
  108. package/web/assets/exportEncode-pFxeatJt.js +0 -1
  109. package/web/assets/exportGlb-MK05aKqH.js +0 -2
  110. package/web/assets/faceTracker-_rQOgBvX.js +0 -1
  111. package/web/assets/fightDirector-Dt60kfbV.js +0 -1
  112. package/web/assets/fightDrama-py4jxSdn.js +0 -2
  113. package/web/assets/gpuExport-Cnv2NfEb.js +0 -189
  114. package/web/assets/handMatte-DZCsuqD2.js +0 -1
  115. package/web/assets/handTracker-Btr9L-Hu.js +0 -2
  116. package/web/assets/layer-worker-Rbo-YZv-.js +0 -5
  117. package/web/assets/library-CdukL2BW.js +0 -1
  118. package/web/assets/main-By_IEoB_.css +0 -1
  119. package/web/assets/maskTrack-AZwAVz1c.js +0 -1
  120. package/web/assets/matteFixRun-wTHGiGGf.js +0 -1
  121. package/web/assets/pendingMatte-iKz2-XBZ.js +0 -2
  122. package/web/assets/personAi-BEVyjCii.js +0 -2
  123. package/web/assets/plateCamera-D_J3-X06.js +0 -1
  124. package/web/assets/plateCameraMatch-C0peOvBn.js +0 -2
  125. package/web/assets/plateFollow-BbJMVxfg.js +0 -2
  126. package/web/assets/plateMatte-u5wKpsUN.js +0 -2
  127. package/web/assets/poseTracker--VJYw-hX.js +0 -1
  128. package/web/assets/productTools-DbhbyJxx.js +0 -2
  129. package/web/assets/rigTrack-CW9_kg5j.js +0 -1
  130. package/web/assets/rotoscope-_CYT-9ry.js +0 -1
  131. package/web/assets/shot-worker-BxIzQRZh.js +0 -1
  132. package/web/assets/spellDuel-eZvRwaxi.js +0 -2
  133. package/web/assets/surfacePin-CfLBhSrm.js +0 -2
  134. package/web/assets/timelineProps-KL6XCR4Q.js +0 -1
  135. package/web/assets/timelineText-DEK2BRyU.js +0 -1
  136. package/web/assets/titleFrames-WfiLHzjf.js +0 -1
  137. package/web/assets/tools-CBfIZX8_.js +0 -1
  138. package/web/assets/toonTools-D7jucq3t.js +0 -2
  139. package/web/assets/trackAnchor-DFqKIb8a.js +0 -1
  140. package/web/assets/userFonts-txN4I-eo.js +0 -1
  141. package/web/assets/vfxBackground-C1dHlJN6.js +0 -2
  142. package/web/assets/videoExport-DiNI9GY1.js +0 -1
  143. package/web/assets/views-sH39zgjD.js +0 -1
  144. package/web/assets/weaponDuel-CEvRDeuE.js +0 -1
@@ -1,2 +1,2 @@
1
- import{fO as G,ic as T,eA as J,fS as j,eS as z,fn as U,fT as H,fU as X,eG as K,fW as L,eQ as A,fY as Z,eC as O,io as V,ip as g,ez as tt,ev as ot,iq as et,dG as nt,ir as it,is as rt}from"./remote-DXG553d8.js";const D=Math.PI/180,W=t=>[Math.sin(t*D),0,Math.cos(t*D)],_=t=>t.map(o=>+o.toFixed(2)),S=t=>t.kind==="person";function I(t,o){const e=t.filter(i=>S(i)&&!i.hidden&&i.id!==o.id);if(!e.length)return null;const r=W(o.rotation?.[1]??0),n=i=>Math.hypot(i.position[0]-o.position[0],i.position[2]-o.position[2]),l=e.filter(i=>(i.position[0]-o.position[0])*r[0]+(i.position[2]-o.position[2])*r[2]>0);return(l.length?l:e).sort((i,s)=>n(i)-n(s))[0]}function q(t,{items:o=[],selected:e=null,ground:r=[0,0,0],reach:n=8,anchor:l=null}={}){const i=(u,c)=>l?.(u,c)??j(u,c),s=e&&e.kind!=="fx"&&!e.hidden?e:null,f=s&&S(s)?s:null;let m=[...r],d=[0,0,0],a,p;if(t.wantsTarget&&s&&!S(s))return{position:[...s.position],rotation:d,attach:{to:s.id,offset:[0,0,0]},target:{to:s.id,part:"center"}};if(t.attach==="gun"&&f){const u=I(o,f);return{position:[...f.position],rotation:d,attach:{to:f.id,hand:"R",tip:!0},...u?{target:{to:u.id,part:"chest"}}:{}}}switch(t.attach){case"hand":f?(a={to:f.id,hand:"R"},m=[...f.position]):m=[r[0],1.2,r[2]];break;case"body":case"ground":s&&(a={to:s.id,offset:[0,0,0]},m=[...s.position]);break;case"path":case"sky":case"gun":{const u=f?I(o,f):null;let c,x;if(f){c=i(f,t.attach==="sky"?"head":"hand_right");const b=W(f.rotation?.[1]??0);x=u?i(u,"chest"):[c[0]+b[0]*n,Math.max(.6,c[1]-.2),c[2]+b[2]*n]}else s?(c=i(s,"chest"),x=[c[0]+n,c[1],c[2]]):(c=[r[0]-n/2,1.2,r[2]],x=[r[0]+n/2,1,r[2]]);t.attach==="sky"&&(c=[x[0],x[1]+8,x[2]]),p=[_(c),_(x)],m=_(t.attach==="sky"?x:c);break}default:m=[r[0],t.attach==="free"?1.2:0,r[2]]}return{position:m,rotation:d,...a?{attach:a}:{},...p?{path:p}:{}}}const at=[...T.map(t=>t.id),...g.filter(t=>!tt[t].internal&&!T.some(o=>o.id===t))];T.map(t=>`${t.id} (${t.preset}${t.attach==="path"?", needs from/to":t.attach==="sky"?', strikes the "to" point from above':""}: ${t.desc})`).join("; ");const P=/^(.*?)(?:\.(feet|chest|head|hand_right|hand_left|center))?$/,v=t=>P.exec(String(t??"").trim())?.[1]?.trim()??"",F=t=>Array.isArray(t)&&t.length===3&&t.every(o=>typeof o=="number"&&Number.isFinite(o)&&Math.abs(o)<=1e3),B=t=>typeof t=="string"&&/^#[0-9a-f]{6}$/i.test(t),y=(t,o)=>{const e=String(o??"").trim().toLowerCase();return t.find(r=>r.id===o||r.name===o)??t.find(r=>r.name.toLowerCase()===e)};function st(t,o,e){const r=[];if(t.from!=null&&r.push(t.from),Array.isArray(t.via)&&r.push(...t.via),t.to!=null&&r.push(t.to),!r.length)return null;if(r.length<2)throw new Error("give both from and to for a flight path (or neither)");return V(r,{find:n=>y(o.items.filter(l=>l.kind!=="fx"),n),at:n=>o.at(n,e),anchor:o.anchor?(n,l)=>o.anchor(n,l,e):void 0})}function ut(t,o){try{const e=G(t.effect)??T.find(h=>h.preset===t.effect);if(!e)throw new Error(`unknown effect '${String(t.effect)}'; use one of ${at.join(", ")}`);const r=o.shot.duration,n=t.start==null?0:Number(t.start);if(!Number.isFinite(n)||n<0||n>=r)throw new Error(`start must be 0..${r} s (the shot is ${r} s long)`);const l=q(e,{items:o.items,selected:t.attach_to?y(o.items,t.attach_to)??null:null,ground:[0,0,0]}),i={preset:e.preset,cat:e.id,intensity:t.intensity??1,seed:t.seed??Math.abs(Q(`${t.name??e.id}${n}`))%1e9+1,start:n,duration:t.duration??(e.fill?Math.max(e.duration,r-n):e.duration),loop:t.loop===!0,params:{...J(e.preset),...e.params||{},...t.params&&typeof t.params=="object"?t.params:{}}};if(t.attach_to!=null){const h=y(o.items.filter(M=>M.kind!=="fx"),t.attach_to);if(!h)throw new Error(`unknown object '${t.attach_to}' to attach to`);const w=t.hand==="right"?"R":t.hand==="left"?"L":void 0;if(t.hand&&t.hand!=="none"&&!w)throw new Error("hand must be 'right', 'left' or 'none'");if(w&&!S(h))throw new Error(`'${h.name}' is not a person: hands exist only on mannequins`);i.attach={to:h.id,...w?{hand:w}:{},...F(t.offset)?{offset:t.offset}:{}},e.attach==="gun"&&S(h)?(i.attach.hand??="R",i.attach.tip=t.tip!==!1):t.tip===!0&&i.attach.hand&&(i.attach.tip=!0)}const s=typeof t.to=="string"?t.to:null,f=s?y(o.items.filter(h=>h.kind!=="fx"),v(s)):null;if(e.wantsTarget){const h=f??(t.attach_to?y(o.items.filter(w=>w.kind!=="fx"),t.attach_to):null);if(h)i.target={to:h.id,part:"center",...t.target_part?{name:String(t.target_part).slice(0,60)}:{}};else if(s)throw new Error(`unknown object '${s}' for to`)}else if(f)i.target={to:f.id,part:P.exec(s)?.[2]??"chest"};else if(s&&!e.wantsTarget)throw new Error(`unknown object '${s}' for to`);const m=t.from!=null?st(t,o,n):null;if(m)i.path=m;else if(e.attach==="gun"&&i.attach?.tip){if(!i.target){const h=I(o.items,o.items.find(w=>w.id===i.attach.to));h&&(i.target={to:h.id,part:"chest"})}}else if(!(t.from==null&&t.to!=null&&!(e.attach==="path"||e.attach==="sky"))){if(e.attach==="path"||e.attach==="sky"){const h=i.attach?o.items.find(E=>E.id===i.attach.to):null;if(!h||!S(h))throw new Error(`${e.id} flies between two points: give from and to (an object name, "Name.hand_right", "Name.chest", or [x, y, z]) or attach_to a person`);const w=o.at(h,n),M=q(e,{items:o.items.map(E=>E.id===h.id?{...E,position:w.position??E.position,rotation:w.rotation??E.rotation}:E),selected:{...h,position:w.position??h.position,rotation:w.rotation??h.rotation},anchor:o.anchor?(E,R)=>o.anchor(E,R,n):null});i.path=M.path,f&&(i.path=[M.path[0],_(j(f,i.target.part,o.at(f,n)))])}}const d=z(i,{strict:!0});if(!d.ok)throw new Error(d.errors.join("; "));const a=B(t.color)?t.color:e.color,p=t.size==null?1:Number(t.size);if(!Number.isFinite(p)||p<.1||p>6)throw new Error("size must be 0.1..6");let u=t.at==null?i.path?e.attach==="sky"?i.path[1]:i.path[0]:F(t.to)&&t.from==null?t.to:f&&!i.attach?_(j(f,"feet",o.at(f,n))):l.position:null;if(t.at!=null)if(F(t.at))u=t.at;else{const h=y(o.items.filter(w=>w.kind!=="fx"),v(t.at));if(!h)throw new Error(`unknown object '${String(t.at)}' for at`);u=j(h,P.exec(String(t.at))?.[2]??"feet",o.at(h,n))}const c=ft(o.items,String(t.name||e.name).slice(0,60)),x={id:o.uid(),name:c,kind:"fx",position:_(u),rotation:[0,Number(t.yaw_deg)||0,0],scale:[p,p,p],color:a,hidden:!1,locked:!1,pose:o.restPose??{},reference:null,fx:d.fx},b=U(o.items,d.fx);if(!b.ok)throw new Error(b.errors.join("; "));const $=H({start:n,duration:d.fx.duration,...d.fx.loop?{loop:!0}:{}},r);return x.fx={...d.fx,start:$.start??n,duration:$.duration??d.fx.duration},{ok:!0,item:x,timing:{start:$.start??n,duration:$.duration??d.fx.duration,...d.fx.loop?{loop:!0}:{}}}}catch(e){return{ok:!1,error:e.message||String(e)}}}const Q=t=>{let o=0;for(let e=0;e<t.length;e++)o=Math.imul(o,31)+t.charCodeAt(e)|0;return o},ft=(t,o)=>{let e=o,r=2;for(;t.some(n=>n.name===e);)e=`${o} ${r++}`;return e};function pt(t,o,e){try{const r={...t.fx},n={},i={...e.timing??{start:r.start,duration:r.duration,loop:r.loop}};if(o.start!=null&&(i.start=Number(o.start),!(i.start>=0&&i.start<e.shot.duration)))throw new Error(`start must be 0..${e.shot.duration} s`);if(o.duration!=null&&(i.duration=Number(o.duration)),o.loop!=null&&(i.loop=o.loop===!0),o.color!=null){if(!B(o.color))throw new Error("color must be a CSS hex like #7fe9ff");n.color=o.color}if(o.intensity!=null&&(r.intensity=o.intensity),o.seed!=null&&(r.seed=o.seed),o.params&&typeof o.params=="object"&&(r.params={...r.params,...o.params}),o.size!=null){const a=Number(o.size);if(!(a>=.1&&a<=6))throw new Error("size must be 0.1..6");n.scale=[a,a,a]}o.yaw_deg!=null&&(n.rotation=[t.rotation[0],Number(o.yaw_deg)||0,t.rotation[2]]);const s=e.items.filter(a=>a.kind!=="fx"&&a.id!==t.id);if(o.attach_to!=null)if(o.attach_to==="none")delete r.attach;else{const a=y(s,o.attach_to);if(!a)throw new Error(`unknown object '${o.attach_to}' to attach to`);const p=o.hand==="right"?"R":o.hand==="left"?"L":void 0;if(p&&!S(a))throw new Error(`'${a.name}' is not a person`);r.attach={to:a.id,...p?{hand:p}:{},...F(o.offset)?{offset:o.offset}:{}}}else if(o.hand!=null&&r.attach){const a=o.hand==="right"?"R":o.hand==="left"?"L":void 0;r.attach={...r.attach,hand:a},a||delete r.attach.hand}if(o.at!=null)if(F(o.at))n.position=o.at;else{const a=y(s,v(o.at));if(!a)throw new Error(`unknown object '${String(o.at)}' for at`);n.position=_(j(a,P.exec(String(o.at))?.[2]??"feet",e.at(a,i.start)))}if(o.from!=null||o.to!=null||o.via!=null){const a=r.path??[],p=[o.from??a[0],...Array.isArray(o.via)?o.via:a.slice(1,-1),o.to??a.at(-1)];if(p.some(u=>u==null))throw new Error("give both from and to the first time you set a path");r.path=V(p,{find:u=>y(s,u),at:u=>e.at(u,i.start),anchor:e.anchor?(u,c)=>e.anchor(u,c,i.start):void 0})}if(typeof o.to=="string"){const a=y(s,v(o.to));a&&(r.target={to:a.id,part:P.exec(o.to)?.[2]??"chest"})}o.clear_path===!0&&delete r.path;const f=z({...r,start:i.start,duration:i.duration,loop:i.loop},{strict:!0});if(!f.ok)throw new Error(f.errors.join("; "));const m=U(e.items.filter(a=>a.id!==t.id),f.fx);if(!m.ok)throw new Error(m.errors.join("; "));const d=H(i,e.shot.duration);return{ok:!0,itemPatch:n,fx:{...f.fx,start:d.start??i.start,duration:d.duration??i.duration},timing:{...d,start:d.start??i.start,duration:d.duration??i.duration}}}catch(r){return{ok:!1,error:r.message||String(r)}}}function lt(t){const[o,e,r]=it(rt(t)),n=o*360;return r>.88||e<.12?r<.3?"dark grey":"white":r<.2?"dark":n<15||n>=345?"red":n<40?"orange":n<62?"golden":n<95?"lime green":n<160?"green":n<195?"cyan":n<225?"sky blue":n<255?"blue":n<285?"purple":n<330?"magenta":"pink"}function mt(t,o){const e=n=>{let l=null,i=2;for(const s of t){if(s.kind==="fx"||s.hidden)continue;const f=nt.dist(j(s,"chest"),n);f<i&&(i=f,l=s)}return l?.name},r=[];for(const n of t){if(n.kind!=="fx"||!n.fx||n.hidden)continue;const l=ot(n,o);if(l.off)continue;if(n.fx.preset===A){const a=n.fx.target&&t.find(p=>p.id===n.fx.target.to);a&&r.push(et(n,a.name,l));continue}const i=G(n.fx.cat)??T.find(a=>a.preset===n.fx.preset);if(!i)continue;const s=n.fx.attach?t.find(a=>a.id===n.fx.attach.to):null,f=n.fx.path?e(n.fx.path[0]):null,m=n.fx.path?e(n.fx.path.at(-1)):null,d=f&&m&&f!==m?` from ${f} to ${m}`:n.fx.path&&m?` toward ${m}`:s?` on ${s.name}${n.fx.attach.hand?`'s ${n.fx.attach.hand==="R"?"right":"left"} hand`:""}`:"";r.push(`${i.prompt} (${lt(n.color)} tint)${d}, from ${l.start.toFixed(1)}s to ${(l.start+l.duration).toFixed(1)}s`)}return r.length?`VISUAL EFFECTS
2
- The previs shows each effect as glowing placeholder light. Recreate them as real, high-quality cinematic VFX with the same colour, timing, size and path (never render text or UI): ${r.slice(0,12).join("; ")}.`:""}const ht=["model","proxy","box","wall","platform","floor","sphere","cylinder","set","prop"];function dt(t){const o=t.scale??[1,1,1];if(t.kind==="proxy"&&t.proxy?.dims)return t.proxy.dims.map((e,r)=>e*o[r]);if(t.kind==="model"){const e=(t.model?.height??2)*o[1];return[e*.6,e,e*.6]}return[...o]}function wt(t,o){try{const e=y(o.items.filter(k=>ht.includes(k.kind)&&!k.hidden),t.target);if(!e)throw new Error(`unknown target '${String(t.target)}': use the name of a model, proxy, box, wall or platform from scene_summary`);const r=t.recipe??"collapse";if(!X.includes(r))throw new Error(`recipe must be one of ${X.join(", ")}`);const n=K.has(r),l=o.shot.duration,i=t.start==null?0:Number(t.start),s=t.end==null?Math.min(l,i+(n?4:Math.max(1,l*.5))):Number(t.end);if(!(i>=0&&i<l))throw new Error(`start must be 0..${l} s`);if(!(s>i&&s<=l+1e-6))throw new Error(`end must be after start and at most ${l} s`);if(t.mode!=null&&!L.includes(t.mode))throw new Error(`mode must be one of ${L.join(", ")}`);const f=dt(e),m=t.radius??Math.min(6,Math.max(.6,Math.max(...f)/5)),d=o.items.find(k=>k.fx?.preset===A&&k.fx.target?.to===e.id),a={radius:m,...Object.fromEntries(["strength","chunks","debris","collapse","falloff","shake","mode"].filter(k=>t[k]!=null).map(k=>[k,t[k]])),...t.direction!=null?{yaw:Number(t.direction)}:{}};d&&t.chunks==null&&(a.chunks=d.fx.params.chunks);const p=t.seed??d?.fx.seed??Math.abs(Q(`${e.name}${i}`))%1e9+1,u=Z({target:e.id,recipe:r,seed:p,start:i,duration:n?s-i:l-i,params:a}),c=z(u,{strict:!0});if(!c.ok)throw new Error(c.errors.join("; "));if(n){const k=o.items.filter(Y=>Y.fx?.preset===A).length,N=e.position;return{ok:!0,item:{id:o.uid(),name:t.name?String(t.name).slice(0,60):`Mix FX ${k+1}`,kind:"fx",position:[N[0],+(N[1]+f[1]+.6).toFixed(2),N[2]],rotation:[0,0,0],scale:[1,1,1],color:O[r].color,hidden:!1,locked:!1,pose:o.restPose,reference:null,fx:c.fx},timing:{start:i,duration:+(s-i).toFixed(2)},keys:[]}}const x=c.fx.params.radius+c.fx.params.falloff+.3,b=e.position,$=+(b[1]+f[1]/2).toFixed(2),h=F(t.from)?t.from.map(Number):[+(b[0]-f[0]/2-x).toFixed(2),$,b[2]],w=F(t.to)?t.to.map(Number):[+(b[0]+f[0]/2+x).toFixed(2),$,b[2]],M=o.items.filter(k=>k.fx?.preset===A).length,E={id:o.uid(),name:t.name?String(t.name).slice(0,60):`Mix FX ${M+1}`,kind:"fx",position:h,rotation:[0,0,0],scale:[1,1,1],color:O[r].color,hidden:!1,locked:!1,pose:o.restPose,reference:null,fx:c.fx},R=(k,N,C)=>({id:k,time:+N.toFixed(4),position:C,rotation:[0,0,0],scale:[1,1,1]});return{ok:!0,item:E,timing:{start:i,duration:+(l-i).toFixed(2)},keys:[R(o.uid(),i/l,h),R(o.uid(),s/l,w)]}}catch(e){return{ok:!1,error:e.message}}}export{y as a,ut as b,wt as c,pt as d,mt as f,q as p};
1
+ import{fA as G,hZ as T,em as J,fE as j,eE as z,f9 as H,fF as U,fG as X,es as Q,fI as L,eC as A,fK as Y,eo as D,i7 as V,i8 as g,el as tt,eh as ot,i9 as et,ds as nt,ia as it,ib as rt}from"./remote-sTZauTqM.js";const O=Math.PI/180,B=t=>[Math.sin(t*O),0,Math.cos(t*O)],_=t=>t.map(o=>+o.toFixed(2)),S=t=>t.kind==="person";function v(t,o){const e=t.filter(i=>S(i)&&!i.hidden&&i.id!==o.id);if(!e.length)return null;const r=B(o.rotation?.[1]??0),n=i=>Math.hypot(i.position[0]-o.position[0],i.position[2]-o.position[2]),l=e.filter(i=>(i.position[0]-o.position[0])*r[0]+(i.position[2]-o.position[2])*r[2]>0);return(l.length?l:e).sort((i,s)=>n(i)-n(s))[0]}function q(t,{items:o=[],selected:e=null,ground:r=[0,0,0],reach:n=8,anchor:l=null}={}){const i=(u,c)=>l?.(u,c)??j(u,c),s=e&&e.kind!=="fx"&&!e.hidden?e:null,f=s&&S(s)?s:null;let m=[...r],d=[0,0,0],a,p;if(t.wantsTarget&&s&&!S(s))return{position:[...s.position],rotation:d,attach:{to:s.id,offset:[0,0,0]},target:{to:s.id,part:"center"}};if(t.attach==="gun"&&f){const u=v(o,f);return{position:[...f.position],rotation:d,attach:{to:f.id,hand:"R",tip:!0},...u?{target:{to:u.id,part:"chest"}}:{}}}switch(t.attach){case"hand":f?(a={to:f.id,hand:"R"},m=[...f.position]):m=[r[0],1.2,r[2]];break;case"body":case"ground":s&&(a={to:s.id,offset:[0,0,0]},m=[...s.position]);break;case"path":case"sky":case"gun":{const u=f?v(o,f):null;let c,b;if(f){c=i(f,t.attach==="sky"?"head":"hand_right");const x=B(f.rotation?.[1]??0);b=u?i(u,"chest"):[c[0]+x[0]*n,Math.max(.6,c[1]-.2),c[2]+x[2]*n]}else s?(c=i(s,"chest"),b=[c[0]+n,c[1],c[2]]):(c=[r[0]-n/2,1.2,r[2]],b=[r[0]+n/2,1,r[2]]);t.attach==="sky"&&(c=[b[0],b[1]+8,b[2]]),p=[_(c),_(b)],m=_(t.attach==="sky"?b:c);break}default:m=[r[0],t.attach==="free"?1.2:0,r[2]]}return{position:m,rotation:d,...a?{attach:a}:{},...p?{path:p}:{}}}const at=[...T.map(t=>t.id),...g.filter(t=>!tt[t].internal&&!T.some(o=>o.id===t))];T.map(t=>`${t.id} (${t.preset}${t.attach==="path"?", needs from/to":t.attach==="sky"?', strikes the "to" point from above':""}: ${t.desc})`).join("; ");const P=/^(.*?)(?:\.(feet|chest|head|hand_right|hand_left|center))?$/,I=t=>P.exec(String(t??"").trim())?.[1]?.trim()??"",F=t=>Array.isArray(t)&&t.length===3&&t.every(o=>typeof o=="number"&&Number.isFinite(o)&&Math.abs(o)<=1e3),K=t=>typeof t=="string"&&/^#[0-9a-f]{6}$/i.test(t),y=(t,o)=>{const e=String(o??"").trim().toLowerCase();return t.find(r=>r.id===o||r.name===o)??t.find(r=>r.name.toLowerCase()===e)};function st(t,o,e){const r=[];if(t.from!=null&&r.push(t.from),Array.isArray(t.via)&&r.push(...t.via),t.to!=null&&r.push(t.to),!r.length)return null;if(r.length<2)throw new Error("give both from and to for a flight path (or neither)");return V(r,{find:n=>y(o.items.filter(l=>l.kind!=="fx"),n),at:n=>o.at(n,e),anchor:o.anchor?(n,l)=>o.anchor(n,l,e):void 0})}function ut(t,o){try{const e=G(t.effect)??T.find(h=>h.preset===t.effect);if(!e)throw new Error(`unknown effect '${String(t.effect)}'; use one of ${at.join(", ")}`);const r=o.shot.duration,n=t.start==null?0:Number(t.start);if(!Number.isFinite(n)||n<0||n>=r)throw new Error(`start must be 0..${r} s (the shot is ${r} s long)`);const l=q(e,{items:o.items,selected:t.attach_to?y(o.items,t.attach_to)??null:null,ground:[0,0,0]}),i={preset:e.preset,cat:e.id,intensity:t.intensity??1,seed:t.seed??Math.abs(W(`${t.name??e.id}${n}`))%1e9+1,start:n,duration:t.duration??(e.fill?Math.max(e.duration,r-n):e.duration),loop:t.loop===!0,params:{...J(e.preset),...e.params||{},...t.params&&typeof t.params=="object"?t.params:{}}};if(t.attach_to!=null){const h=y(o.items.filter(M=>M.kind!=="fx"),t.attach_to);if(!h)throw new Error(`unknown object '${t.attach_to}' to attach to`);const w=t.hand==="right"?"R":t.hand==="left"?"L":void 0;if(t.hand&&t.hand!=="none"&&!w)throw new Error("hand must be 'right', 'left' or 'none'");if(w&&!S(h))throw new Error(`'${h.name}' is not a person: hands exist only on mannequins`);i.attach={to:h.id,...w?{hand:w}:{},...F(t.offset)?{offset:t.offset}:{}},e.attach==="gun"&&S(h)?(i.attach.hand??="R",i.attach.tip=t.tip!==!1):t.tip===!0&&i.attach.hand&&(i.attach.tip=!0)}const s=typeof t.to=="string"?t.to:null,f=s?y(o.items.filter(h=>h.kind!=="fx"),I(s)):null;if(e.wantsTarget){const h=f??(t.attach_to?y(o.items.filter(w=>w.kind!=="fx"),t.attach_to):null);if(h)i.target={to:h.id,part:"center",...t.target_part?{name:String(t.target_part).slice(0,60)}:{}};else if(s)throw new Error(`unknown object '${s}' for to`)}else if(f)i.target={to:f.id,part:P.exec(s)?.[2]??"chest"};else if(s&&!e.wantsTarget)throw new Error(`unknown object '${s}' for to`);const m=t.from!=null?st(t,o,n):null;if(m)i.path=m;else if(e.attach==="gun"&&i.attach?.tip){if(!i.target){const h=v(o.items,o.items.find(w=>w.id===i.attach.to));h&&(i.target={to:h.id,part:"chest"})}}else if(!(t.from==null&&t.to!=null&&!(e.attach==="path"||e.attach==="sky"))){if(e.attach==="path"||e.attach==="sky"){const h=i.attach?o.items.find(E=>E.id===i.attach.to):null;if(!h||!S(h))throw new Error(`${e.id} flies between two points: give from and to (an object name, "Name.hand_right", "Name.chest", or [x, y, z]) or attach_to a person`);const w=o.at(h,n),M=q(e,{items:o.items.map(E=>E.id===h.id?{...E,position:w.position??E.position,rotation:w.rotation??E.rotation}:E),selected:{...h,position:w.position??h.position,rotation:w.rotation??h.rotation},anchor:o.anchor?(E,R)=>o.anchor(E,R,n):null});i.path=M.path,f&&(i.path=[M.path[0],_(j(f,i.target.part,o.at(f,n)))])}}const d=z(i,{strict:!0});if(!d.ok)throw new Error(d.errors.join("; "));const a=K(t.color)?t.color:e.color,p=t.size==null?1:Number(t.size);if(!Number.isFinite(p)||p<.1||p>6)throw new Error("size must be 0.1..6");let u=t.at==null?i.path?e.attach==="sky"?i.path[1]:i.path[0]:F(t.to)&&t.from==null?t.to:f&&!i.attach?_(j(f,"feet",o.at(f,n))):l.position:null;if(t.at!=null)if(F(t.at))u=t.at;else{const h=y(o.items.filter(w=>w.kind!=="fx"),I(t.at));if(!h)throw new Error(`unknown object '${String(t.at)}' for at`);u=j(h,P.exec(String(t.at))?.[2]??"feet",o.at(h,n))}const c=ft(o.items,String(t.name||e.name).slice(0,60)),b={id:o.uid(),name:c,kind:"fx",position:_(u),rotation:[0,Number(t.yaw_deg)||0,0],scale:[p,p,p],color:a,hidden:!1,locked:!1,pose:o.restPose??{},reference:null,fx:d.fx},x=H(o.items,d.fx);if(!x.ok)throw new Error(x.errors.join("; "));const $=U({start:n,duration:d.fx.duration,...d.fx.loop?{loop:!0}:{}},r);return b.fx={...d.fx,start:$.start??n,duration:$.duration??d.fx.duration},{ok:!0,item:b,timing:{start:$.start??n,duration:$.duration??d.fx.duration,...d.fx.loop?{loop:!0}:{}}}}catch(e){return{ok:!1,error:e.message||String(e)}}}const W=t=>{let o=0;for(let e=0;e<t.length;e++)o=Math.imul(o,31)+t.charCodeAt(e)|0;return o},ft=(t,o)=>{let e=o,r=2;for(;t.some(n=>n.name===e);)e=`${o} ${r++}`;return e};function pt(t,o,e){try{const r={...t.fx},n={},i={...e.timing??{start:r.start,duration:r.duration,loop:r.loop}};if(o.start!=null&&(i.start=Number(o.start),!(i.start>=0&&i.start<e.shot.duration)))throw new Error(`start must be 0..${e.shot.duration} s`);if(o.duration!=null&&(i.duration=Number(o.duration)),o.loop!=null&&(i.loop=o.loop===!0),o.color!=null){if(!K(o.color))throw new Error("color must be a CSS hex like #7fe9ff");n.color=o.color}if(o.intensity!=null&&(r.intensity=o.intensity),o.seed!=null&&(r.seed=o.seed),o.params&&typeof o.params=="object"&&(r.params={...r.params,...o.params}),o.size!=null){const a=Number(o.size);if(!(a>=.1&&a<=6))throw new Error("size must be 0.1..6");n.scale=[a,a,a]}o.yaw_deg!=null&&(n.rotation=[t.rotation[0],Number(o.yaw_deg)||0,t.rotation[2]]);const s=e.items.filter(a=>a.kind!=="fx"&&a.id!==t.id);if(o.attach_to!=null)if(o.attach_to==="none")delete r.attach;else{const a=y(s,o.attach_to);if(!a)throw new Error(`unknown object '${o.attach_to}' to attach to`);const p=o.hand==="right"?"R":o.hand==="left"?"L":void 0;if(p&&!S(a))throw new Error(`'${a.name}' is not a person`);r.attach={to:a.id,...p?{hand:p}:{},...F(o.offset)?{offset:o.offset}:{}}}else if(o.hand!=null&&r.attach){const a=o.hand==="right"?"R":o.hand==="left"?"L":void 0;r.attach={...r.attach,hand:a},a||delete r.attach.hand}if(o.at!=null)if(F(o.at))n.position=o.at;else{const a=y(s,I(o.at));if(!a)throw new Error(`unknown object '${String(o.at)}' for at`);n.position=_(j(a,P.exec(String(o.at))?.[2]??"feet",e.at(a,i.start)))}if(o.from!=null||o.to!=null||o.via!=null){const a=r.path??[],p=[o.from??a[0],...Array.isArray(o.via)?o.via:a.slice(1,-1),o.to??a.at(-1)];if(p.some(u=>u==null))throw new Error("give both from and to the first time you set a path");r.path=V(p,{find:u=>y(s,u),at:u=>e.at(u,i.start),anchor:e.anchor?(u,c)=>e.anchor(u,c,i.start):void 0})}if(typeof o.to=="string"){const a=y(s,I(o.to));a&&(r.target={to:a.id,part:P.exec(o.to)?.[2]??"chest"})}o.clear_path===!0&&delete r.path;const f=z({...r,start:i.start,duration:i.duration,loop:i.loop},{strict:!0});if(!f.ok)throw new Error(f.errors.join("; "));const m=H(e.items.filter(a=>a.id!==t.id),f.fx);if(!m.ok)throw new Error(m.errors.join("; "));const d=U(i,e.shot.duration);return{ok:!0,itemPatch:n,fx:{...f.fx,start:d.start??i.start,duration:d.duration??i.duration},timing:{...d,start:d.start??i.start,duration:d.duration??i.duration}}}catch(r){return{ok:!1,error:r.message||String(r)}}}function lt(t){const[o,e,r]=it(rt(t)),n=o*360;return r>.88||e<.12?r<.3?"dark grey":"white":r<.2?"dark":n<15||n>=345?"red":n<40?"orange":n<62?"golden":n<95?"lime green":n<160?"green":n<195?"cyan":n<225?"sky blue":n<255?"blue":n<285?"purple":n<330?"magenta":"pink"}function mt(t,o){const e=n=>{let l=null,i=2;for(const s of t){if(s.kind==="fx"||s.hidden)continue;const f=nt.dist(j(s,"chest"),n);f<i&&(i=f,l=s)}return l?.name},r=[];for(const n of t){if(n.kind!=="fx"||!n.fx||n.hidden)continue;const l=ot(n,o);if(l.off)continue;if(n.fx.preset===A){const a=n.fx.target&&t.find(p=>p.id===n.fx.target.to);a&&r.push(et(n,a.name,l));continue}const i=G(n.fx.cat)??T.find(a=>a.preset===n.fx.preset);if(!i)continue;const s=n.fx.attach?t.find(a=>a.id===n.fx.attach.to):null,f=n.fx.path?e(n.fx.path[0]):null,m=n.fx.path?e(n.fx.path.at(-1)):null,d=f&&m&&f!==m?` from ${f} to ${m}`:n.fx.path&&m?` toward ${m}`:s?` on ${s.name}${n.fx.attach.hand?`'s ${n.fx.attach.hand==="R"?"right":"left"} hand`:""}`:"";r.push(`${i.prompt} (${lt(n.color)} tint)${d}, from ${l.start.toFixed(1)}s to ${(l.start+l.duration).toFixed(1)}s`)}return r.length?`VISUAL EFFECTS
2
+ The previs shows each effect as glowing placeholder light. Recreate them as real, high-quality cinematic VFX with the same colour, timing, size and path (never render text or UI): ${r.slice(0,12).join("; ")}.`:""}const ht=["model","proxy","box","wall","platform","floor","sphere","cylinder","set","prop"];function dt(t){const o=t.scale??[1,1,1];if(t.kind==="proxy"&&t.proxy?.dims)return t.proxy.dims.map((e,r)=>e*o[r]);if(t.kind==="model"){const e=(t.model?.height??2)*o[1];return[e*.6,e,e*.6]}return[...o]}function wt(t,o){try{const e=y(o.items.filter(k=>ht.includes(k.kind)&&!k.hidden),t.target);if(!e)throw new Error(`unknown target '${String(t.target)}': use the name of a model, proxy, box, wall or platform from scene_summary`);const r=t.recipe??"collapse";if(!X.includes(r))throw new Error(`recipe must be one of ${X.join(", ")}`);const n=Q.has(r),l=o.shot.duration,i=t.start==null?0:Number(t.start),s=t.end==null?Math.min(l,i+(n?4:Math.max(1,l*.5))):Number(t.end);if(!(i>=0&&i<l))throw new Error(`start must be 0..${l} s`);if(!(s>i&&s<=l+1e-6))throw new Error(`end must be after start and at most ${l} s`);if(t.mode!=null&&!L.includes(t.mode))throw new Error(`mode must be one of ${L.join(", ")}`);const f=dt(e),m=t.radius??Math.min(6,Math.max(.6,Math.max(...f)/5)),d=o.items.find(k=>k.fx?.preset===A&&k.fx.target?.to===e.id),a={radius:m,...Object.fromEntries(["strength","chunks","debris","collapse","falloff","shake","mode"].filter(k=>t[k]!=null).map(k=>[k,t[k]])),...t.direction!=null?{yaw:Number(t.direction)}:{}};d&&t.chunks==null&&(a.chunks=d.fx.params.chunks);const p=t.seed??d?.fx.seed??Math.abs(W(`${e.name}${i}`))%1e9+1,u=Y({target:e.id,recipe:r,seed:p,start:i,duration:n?s-i:l-i,params:a}),c=z(u,{strict:!0});if(!c.ok)throw new Error(c.errors.join("; "));if(n){const k=o.items.filter(Z=>Z.fx?.preset===A).length,N=e.position;return{ok:!0,item:{id:o.uid(),name:t.name?String(t.name).slice(0,60):`Mix FX ${k+1}`,kind:"fx",position:[N[0],+(N[1]+f[1]+.6).toFixed(2),N[2]],rotation:[0,0,0],scale:[1,1,1],color:D[r].color,hidden:!1,locked:!1,pose:o.restPose,reference:null,fx:c.fx},timing:{start:i,duration:+(s-i).toFixed(2)},keys:[]}}const b=c.fx.params.radius+c.fx.params.falloff+.3,x=e.position,$=+(x[1]+f[1]/2).toFixed(2),h=F(t.from)?t.from.map(Number):[+(x[0]-f[0]/2-b).toFixed(2),$,x[2]],w=F(t.to)?t.to.map(Number):[+(x[0]+f[0]/2+b).toFixed(2),$,x[2]],M=o.items.filter(k=>k.fx?.preset===A).length,E={id:o.uid(),name:t.name?String(t.name).slice(0,60):`Mix FX ${M+1}`,kind:"fx",position:h,rotation:[0,0,0],scale:[1,1,1],color:D[r].color,hidden:!1,locked:!1,pose:o.restPose,reference:null,fx:c.fx},R=(k,N,C)=>({id:k,time:+N.toFixed(4),position:C,rotation:[0,0,0],scale:[1,1,1]});return{ok:!0,item:E,timing:{start:i,duration:+(l-i).toFixed(2)},keys:[R(o.uid(),i/l,h),R(o.uid(),s/l,w)]}}catch(e){return{ok:!1,error:e.message}}}export{y as a,ut as b,wt as c,pt as d,mt as f,q as p};
@@ -1 +1 @@
1
- import{iw as N,ix as C,d_ as Q,iy as X,iz as Y,iA as V,iB as Z,iC as K,dY as W,iD as ee}from"./remote-DXG553d8.js";import{Vector3 as w,Line as _,SphereGeometry as te,Mesh as B,BufferGeometry as ne,Euler as oe,MathUtils as re,Box3 as F,LineBasicMaterial as se,MeshBasicMaterial as ie,Matrix4 as H,Bone as ae,Object3D as ce,Skeleton as ue,Uint16BufferAttribute as le,Float32BufferAttribute as de,SkinnedMesh as fe,Quaternion as pe,Sphere as he}from"./three.module-Bx43vjkH.js";const ye="clipoox-rig-weights",k="weights",ge=8;function R(){return new Promise(e=>{try{if(typeof indexedDB>"u")return e(null);const t=indexedDB.open(ye,1);t.onupgradeneeded=()=>{try{t.result.createObjectStore(k)}catch{}},t.onsuccess=()=>e(t.result),t.onerror=()=>e(null),t.onblocked=()=>e(null)}catch{e(null)}})}async function me(e){const t=await R();if(!t)return null;try{return await new Promise(n=>{try{const r=t.transaction(k,"readonly").objectStore(k).get(e);r.onsuccess=()=>{const o=r.result;n(o?.data?.skinIndex instanceof Uint16Array?o.data:null)},r.onerror=()=>n(null)}catch{n(null)}})}finally{try{t.close()}catch{}}}async function we(e,t){const n=await R();if(n)try{await new Promise(r=>{try{const o=n.transaction(k,"readwrite"),i=o.objectStore(k);i.put({at:Date.now(),data:t},e);const s=[],c=i.openCursor();c.onsuccess=()=>{const u=c.result;u?(s.push({key:u.key,at:u.value.at||0}),u.continue()):s.sort((a,p)=>p.at-a.at).slice(ge).forEach(a=>i.delete(a.key))},o.oncomplete=()=>r(),o.onerror=()=>r(),o.onabort=()=>r()}catch{r()}})}finally{try{n.close()}catch{}}}async function be(){const e=await R();if(e)try{await new Promise(t=>{try{const n=e.transaction(k,"readwrite");n.objectStore(k).clear(),n.oncomplete=()=>t(),n.onerror=()=>t()}catch{t()}})}finally{try{e.close()}catch{}}}async function xe(e,t,n=!0){const r=`${N(e.positions,e.index)}|${e.rigKey}`;if(n){const i=await me(r).catch(()=>null);if(i)return t?.(1),{...i,source:"disk",key:r}}const o=C({positions:e.positions,index:e.index,joints:e.joints,onProgress:t});return n&&await we(r,o).catch(()=>{}),{...o,source:"computed",key:r}}function ve(e,t,n=!0){const r=async()=>({...await xe(e,t,n),via:"main"});if(typeof Worker>"u")return new Promise((s,c)=>setTimeout(()=>r().then(s,c),0));let o;try{o=new Worker(new URL("/assets/weights.worker-r1GBeQWE.js",import.meta.url),{type:"module"})}catch{return r()}const i={...e,positions:e.positions.slice(),index:e.index.slice()};return new Promise((s,c)=>{let u=!1;const a=()=>{if(!u){u=!0;try{o.terminate()}catch{}r().then(s,c)}};o.onmessage=p=>{p.data.type==="progress"?t?.(p.data.fraction??0):p.data.type==="done"&&!u?(u=!0,o.terminate(),s({...p.data.result,via:"worker"})):p.data.type==="error"&&a()},o.onerror=p=>{p.preventDefault?.(),a()};try{o.postMessage({input:i,disk:n},[i.positions.buffer,i.index.buffer])}catch{a()}})}const M=new Map,Me=12,ke=3e4,j=new Map,O=new Set,A=()=>O.forEach(e=>{try{e()}catch{}});function Be(e){return O.add(e),()=>{O.delete(e)}}function Oe(e){for(const n of j.values())if(n.modelKey===e)return{progress:n.progress,vertices:n.vertices};const t=L.get(e);return t&&Date.now()-t.at<G?{progress:1,vertices:t.vertices,done:!0}:null}const L=new Map,G=6e3;function Re(e){if(!e)M.clear();else for(const t of[...M.keys()])t.startsWith(`${e}|`)&&M.delete(t);be()}function S(e){e.updateMatrixWorld(!0);const t=e.matrixWorld.clone().invert(),n=[];return e.traverse(r=>{r instanceof B&&!r.userData.rigOverlay&&r.geometry?.getAttribute("position")&&n.push({mesh:r,matrix:t.clone().multiply(r.matrixWorld)})}),n}function je(e){const t=new F,n=new w;for(const{mesh:r,matrix:o}of S(e)){const i=r.geometry.getAttribute("position"),s=Math.max(1,Math.floor(i.count/2e4));for(let c=0;c<i.count;c+=s)t.expandByPoint(n.fromBufferAttribute(i,c).applyMatrix4(o))}return t}function Ie(e){let t=null,n=null;const r=new w;for(const{mesh:o,matrix:i}of S(e)){const s=o.geometry.getAttribute("position");for(let c=0;c<s.count;c++)r.fromBufferAttribute(s,c).applyMatrix4(i),(!t||r.x<t[0])&&(t=[r.x,r.y,r.z]),(!n||r.x>n[0])&&(n=[r.x,r.y,r.z])}return t&&n?{L:t,R:n}:null}function Ae(e,t=S(e)){const n=t.reduce((a,{mesh:p})=>a+p.geometry.getAttribute("position").count,0),r=t.reduce((a,{mesh:p})=>a+(p.geometry.index?.count??p.geometry.getAttribute("position").count),0),o=new Float32Array(n*3),i=new Uint32Array(r),s=new w;let c=0,u=0;for(const{mesh:a,matrix:p}of t){const l=a.geometry,g=l.getAttribute("position");for(let y=0;y<g.count;y++)s.fromBufferAttribute(g,y).applyMatrix4(p),o[(c+y)*3]=s.x,o[(c+y)*3+1]=s.y,o[(c+y)*3+2]=s.z;if(l.index)for(let y=0;y<l.index.count;y++)i[u++]=c+l.index.getX(y);else for(let y=0;y<g.count;y++)i[u++]=c+y;c+=g.count}return{positions:o,index:i}}function D(e,t,n,r,o){const i=[];let s=0;for(const{mesh:u}of t){const a=u.geometry.getAttribute("position").count;i.push({skinIndex:n.skinIndex.slice(s*4,(s+a)*4),skinWeight:n.skinWeight.slice(s*4,(s+a)*4)}),s+=a}const c={perMesh:i,radius:n.boneRadius,spheres:n.boneSpheres,vertices:n.vertices,ms:n.ms,source:r,via:o};for(M.set(e,c);M.size>Me;)M.delete(M.keys().next().value);return c}function Se(e,t,n,r={}){const o=S(e),i=o.map(({mesh:f})=>`${f.geometry.getAttribute("position").count}:${f.geometry.index?.count??0}`).join(","),s=`${n}|${i}|${W(t)}`,c=M.get(s);if(c)return{meshes:o,weights:c,cached:!0,key:s,job:null};const u=j.get(s);if(u)return{meshes:o,weights:null,cached:!1,key:s,job:u.promise};const a=o.reduce((f,{mesh:h})=>f+h.geometry.getAttribute("position").count,0),p=Ae(e,o),l=W(t);if(o.length&&o.every(({mesh:f})=>f.geometry.userData.rigWeights===l&&f.geometry.getAttribute("skinIndex"))){const f=new Uint16Array(a*4),h=new Float32Array(a*4);let d=0;for(const{mesh:m}of o){const v=m.geometry;f.set(v.getAttribute("skinIndex").array,d*4),h.set(v.getAttribute("skinWeight").array,d*4),d+=v.getAttribute("position").count}const x=ee({positions:p.positions,skinIndex:f,skinWeight:h,joints:t.joints});return{meshes:o,weights:D(s,o,{skinIndex:f,skinWeight:h,...x,vertices:a,ms:0},"computed","main"),cached:!1,key:s,job:null}}if(a<=ke&&r.background!==!0){const f=C({...p,joints:t.joints});return f.vertices,Math.round(f.ms),{meshes:o,weights:D(s,o,f,"computed","main"),cached:!1,key:s,job:null}}const g={promise:Promise.resolve(),progress:0,vertices:a,modelKey:n};let y=0;return g.promise=ve({...p,joints:t.joints,rigKey:W(t)},f=>{g.progress=f,y++,A()}).then(f=>{D(s,o,f,f.source,f.via),g.via=f.via,f.via,f.source,f.vertices,Math.round(f.ms)}).catch(f=>{console.warn("[rig] weights",f.message)}).finally(()=>{j.delete(s),L.set(n,{at:Date.now(),vertices:a}),A(),setTimeout(A,G+50)}),j.set(s,g),A(),{meshes:o,weights:null,cached:!1,key:s,job:g.promise}}function Pe(e,t,n,r){if(!t.joints.length)return null;const{meshes:o,weights:i,cached:s,key:c,job:u}=Se(e,t,n);if(!o.length)return null;u&&r?.(`rig:${c}`,u);const a=t.joints.map(h=>{const d=new ae;return d.name=h.name,d.userData.rigBone=h.name,d});if(t.joints.forEach((h,d)=>{const x=h.parent?t.joints.findIndex(v=>v.name===h.parent):-1,m=new w(...h.pos);x<0?(a[d].position.copy(m),e.add(a[d])):(a[d].position.copy(m.sub(new w(...t.joints[x].pos))),a[x].add(a[d]))}),t.kind==="humanoid")for(const h of["L","R"]){const d=V(t,h),x=t.joints.findIndex(v=>v.name===`wrist${h}`);if(!d||x<0)continue;const m=new ce;m.name=`rigHold${h}`,m.userData.rigHold=h,m.position.copy(d.position),m.quaternion.copy(d.quaternion),m.scale.setScalar(d.scale),a[x].add(m)}e.updateMatrixWorld(!0);const p=[];if(i){const h=new ue(a);o.forEach(({mesh:d},x)=>{const m=d.geometry,v=i.perMesh[x];m.setAttribute("skinIndex",new le(v.skinIndex,4)),m.setAttribute("skinWeight",new de(v.skinWeight,4));const b=new fe(m,d.material);b.name=d.name,b.castShadow=d.castShadow,b.receiveShadow=d.receiveShadow,b.position.copy(d.position),b.quaternion.copy(d.quaternion),b.scale.copy(d.scale),b.frustumCulled=!0,b.userData.rigSkinned=!0,b.userData.slots=d.userData.slots;const I=d.parent;I.add(b),I.remove(d);for(const J of[...d.children])b.add(J);p.push(b)}),e.updateMatrixWorld(!0);for(const d of p)d.bind(h,d.matrixWorld)}const l=je(e),g=Math.max(.001,...l.getSize(new w).toArray()),y=i?void 0:[...j.values()].find(h=>h.promise===u),f={rig:t,bones:a,poser:Z(t,i?.radius??null),meshes:p,rootRest:a[0].position.clone(),size:g,center:l.getCenter(new w),info:i?{vertices:i.vertices,ms:Math.round(i.ms),cached:s,source:s?i.source==="disk"?"disk":"memory":i.source,via:i.via}:{vertices:y?.vertices??0,ms:0,cached:!1,source:"pending",progress:y?.progress??0},spheres:i?.spheres??null};return e.userData.rig=f,f}const E=new H,P=new H,q=new w,We=new w;function U(e){const t=e.spheres;if(!(!t||!e.meshes.length))for(const n of e.meshes){n.updateMatrixWorld(!0),P.copy(n.matrixWorld).invert();const r=[],o=[];if(e.bones.forEach((u,a)=>{const p=t[a*4+3];if(!(p>0))return;const l=e.rig.joints[a].pos;E.multiplyMatrices(P,u.matrixWorld),r.push(We.set(t[a*4]-l[0],t[a*4+1]-l[1],t[a*4+2]-l[2]).applyMatrix4(E).clone()),o.push(p*E.getMaxScaleOnAxis())}),!r.length)continue;const i=new F;r.forEach((u,a)=>{i.expandByPoint(q.copy(u).addScalar(o[a])),i.expandByPoint(q.copy(u).addScalar(-o[a]))});const s=i.getCenter(new w);let c=0;r.forEach((u,a)=>{c=Math.max(c,u.distanceTo(s)+o[a])}),n.boundingSphere=new he(s,c),n.boundingBox=i}}function qe(e,t,n,r=!1){if(r)e.bones.forEach(o=>o.quaternion.identity()),e.bones[0].position.copy(e.rootRest);else{const{local:o,shift:i}=e.poser.solve(t,n||{});e.bones.forEach((s,c)=>s.quaternion.copy(o[c])),e.bones[0].position.copy(e.rootRest),e.bones[0].position.y+=i}e.bones[0].updateMatrixWorld(!0),U(e)}function Te(e,t){const n=Y(e.rig),r=l=>l?e.bones[e.rig.joints.findIndex(g=>g.name===l)]:void 0,o=r(n.head),i=e.rig.joints.find(l=>l.name==="headTop"),s=e.rig.joints.find(l=>l.name===n.head),c=i&&s?Math.max(.05,i.pos[1]-s.pos[1]):.25,u=new w(0,.55*c,.3*c),a=(l,g,y,f,h)=>{if(!l)return;l.updateWorldMatrix(!0,!1);const d=l.worldToLocal(t.clone()).sub(h);l.quaternion.multiply(new pe().setFromEuler(K(d,y,f,g))),l.updateMatrixWorld(!0)},p=r(n.neck);p&&a(p,.4,30,15,u.clone().add(new w(0,.3*c,0))),a(o,1,70,35,u);for(const l of n.eyes)a(r(l),1,45,35,new w);U(e)}function $e(e,t,n){const r=e.rig.joints.findIndex(c=>c.name===t);if(r<0)return[0,0,0];const i=e.poser.solve(n,{}).local[r].clone().invert().multiply(e.bones[r].quaternion),s=new oe().setFromQuaternion(i,"XYZ");return[s.x,s.y,s.z].map(c=>Math.round(re.radToDeg(c)*10)/10)}const T=new Map;function $(e){let t=T.get(e);return t||(t=e==="line"?new se({color:"#b8df78",depthTest:!1,transparent:!0,opacity:.9}):new ie({color:e==="picked"?"#ffad52":e==="end"?"#7fd6ff":"#b8df78",depthTest:!1,transparent:!0,opacity:.95}),t.userData.shared=!0,t.dispose=()=>{},T.set(e,t)),t}let z=null;function ze(e){const t=[];e.traverse(n=>{n.userData.rigOverlay&&t.push(n)});for(const n of t)n.parent?.remove(n),n instanceof _&&n.geometry.dispose()}function Ce(e,t,n=1){const r=e.size*.014*n;z??=(()=>{const o=new te(1,12,8);return o.userData.shared=!0,o.dispose=()=>{},o})(),e.rig.joints.forEach((o,i)=>{const s=e.bones[i],c=Q(e.rig.joints,o),u=new B(z,$(o.name===t?"picked":c?"end":"joint")),a=X(o.name)?.3:1;u.scale.setScalar(a*(o.name===t?r*1.5:c?r*.75:r)),u.userData.rigOverlay=!0,u.userData.rigJoint=o.name,u.renderOrder=1e3,u.layers.set(1),u.raycast=B.prototype.raycast,s.add(u);for(const p of e.bones.filter(l=>l.parent===s)){const l=new _(new ne().setFromPoints([new w,p.position.clone()]),$("line"));l.userData.rigOverlay=!0,l.renderOrder=999,l.layers.set(1),l.raycast=()=>{},s.add(l)}})}export{Ce as a,$e as b,Re as c,Ie as d,Ae as e,je as f,Te as g,Pe as h,Be as o,qe as p,ze as r,Oe as w};
1
+ import{ig as N,ih as C,dM as Q,ii as X,ij as V,ik as Y,il as K,im as Z,dK as W,io as ee}from"./remote-sTZauTqM.js";import{Vector3 as w,Line as F,SphereGeometry as te,Mesh as B,BufferGeometry as ne,Euler as oe,MathUtils as re,Box3 as _,LineBasicMaterial as se,MeshBasicMaterial as ie,Matrix4 as H,Bone as ae,Object3D as ce,Skeleton as ue,Uint16BufferAttribute as le,Float32BufferAttribute as de,SkinnedMesh as fe,Quaternion as pe,Sphere as he}from"./three.module-Bx43vjkH.js";const ge="clipoox-rig-weights",k="weights",ye=8;function R(){return new Promise(e=>{try{if(typeof indexedDB>"u")return e(null);const t=indexedDB.open(ge,1);t.onupgradeneeded=()=>{try{t.result.createObjectStore(k)}catch{}},t.onsuccess=()=>e(t.result),t.onerror=()=>e(null),t.onblocked=()=>e(null)}catch{e(null)}})}async function me(e){const t=await R();if(!t)return null;try{return await new Promise(n=>{try{const r=t.transaction(k,"readonly").objectStore(k).get(e);r.onsuccess=()=>{const o=r.result;n(o?.data?.skinIndex instanceof Uint16Array?o.data:null)},r.onerror=()=>n(null)}catch{n(null)}})}finally{try{t.close()}catch{}}}async function we(e,t){const n=await R();if(n)try{await new Promise(r=>{try{const o=n.transaction(k,"readwrite"),i=o.objectStore(k);i.put({at:Date.now(),data:t},e);const s=[],c=i.openCursor();c.onsuccess=()=>{const u=c.result;u?(s.push({key:u.key,at:u.value.at||0}),u.continue()):s.sort((a,p)=>p.at-a.at).slice(ye).forEach(a=>i.delete(a.key))},o.oncomplete=()=>r(),o.onerror=()=>r(),o.onabort=()=>r()}catch{r()}})}finally{try{n.close()}catch{}}}async function be(){const e=await R();if(e)try{await new Promise(t=>{try{const n=e.transaction(k,"readwrite");n.objectStore(k).clear(),n.oncomplete=()=>t(),n.onerror=()=>t()}catch{t()}})}finally{try{e.close()}catch{}}}async function xe(e,t,n=!0){const r=`${N(e.positions,e.index)}|${e.rigKey}`;if(n){const i=await me(r).catch(()=>null);if(i)return t?.(1),{...i,source:"disk",key:r}}const o=C({positions:e.positions,index:e.index,joints:e.joints,onProgress:t});return n&&await we(r,o).catch(()=>{}),{...o,source:"computed",key:r}}function ve(e,t,n=!0){const r=async()=>({...await xe(e,t,n),via:"main"});if(typeof Worker>"u")return new Promise((s,c)=>setTimeout(()=>r().then(s,c),0));let o;try{o=new Worker(new URL("/assets/weights.worker-r1GBeQWE.js",import.meta.url),{type:"module"})}catch{return r()}const i={...e,positions:e.positions.slice(),index:e.index.slice()};return new Promise((s,c)=>{let u=!1;const a=()=>{if(!u){u=!0;try{o.terminate()}catch{}r().then(s,c)}};o.onmessage=p=>{p.data.type==="progress"?t?.(p.data.fraction??0):p.data.type==="done"&&!u?(u=!0,o.terminate(),s({...p.data.result,via:"worker"})):p.data.type==="error"&&a()},o.onerror=p=>{p.preventDefault?.(),a()};try{o.postMessage({input:i,disk:n},[i.positions.buffer,i.index.buffer])}catch{a()}})}const M=new Map,Me=12,ke=3e4,j=new Map,O=new Set,S=()=>O.forEach(e=>{try{e()}catch{}});function Be(e){return O.add(e),()=>{O.delete(e)}}function Oe(e){for(const n of j.values())if(n.modelKey===e)return{progress:n.progress,vertices:n.vertices};const t=L.get(e);return t&&Date.now()-t.at<G?{progress:1,vertices:t.vertices,done:!0}:null}const L=new Map,G=6e3;function Re(e){if(!e)M.clear();else for(const t of[...M.keys()])t.startsWith(`${e}|`)&&M.delete(t);be()}function A(e){e.updateMatrixWorld(!0);const t=e.matrixWorld.clone().invert(),n=[];return e.traverse(r=>{r instanceof B&&!r.userData.rigOverlay&&r.geometry?.getAttribute("position")&&n.push({mesh:r,matrix:t.clone().multiply(r.matrixWorld)})}),n}function je(e){const t=new _,n=new w;for(const{mesh:r,matrix:o}of A(e)){const i=r.geometry.getAttribute("position"),s=Math.max(1,Math.floor(i.count/2e4));for(let c=0;c<i.count;c+=s)t.expandByPoint(n.fromBufferAttribute(i,c).applyMatrix4(o))}return t}function Ie(e){let t=null,n=null;const r=new w;for(const{mesh:o,matrix:i}of A(e)){const s=o.geometry.getAttribute("position");for(let c=0;c<s.count;c++)r.fromBufferAttribute(s,c).applyMatrix4(i),(!t||r.x<t[0])&&(t=[r.x,r.y,r.z]),(!n||r.x>n[0])&&(n=[r.x,r.y,r.z])}return t&&n?{L:t,R:n}:null}function Se(e,t=A(e)){const n=t.reduce((a,{mesh:p})=>a+p.geometry.getAttribute("position").count,0),r=t.reduce((a,{mesh:p})=>a+(p.geometry.index?.count??p.geometry.getAttribute("position").count),0),o=new Float32Array(n*3),i=new Uint32Array(r),s=new w;let c=0,u=0;for(const{mesh:a,matrix:p}of t){const l=a.geometry,y=l.getAttribute("position");for(let g=0;g<y.count;g++)s.fromBufferAttribute(y,g).applyMatrix4(p),o[(c+g)*3]=s.x,o[(c+g)*3+1]=s.y,o[(c+g)*3+2]=s.z;if(l.index)for(let g=0;g<l.index.count;g++)i[u++]=c+l.index.getX(g);else for(let g=0;g<y.count;g++)i[u++]=c+g;c+=y.count}return{positions:o,index:i}}function E(e,t,n,r,o){const i=[];let s=0;for(const{mesh:u}of t){const a=u.geometry.getAttribute("position").count;i.push({skinIndex:n.skinIndex.slice(s*4,(s+a)*4),skinWeight:n.skinWeight.slice(s*4,(s+a)*4)}),s+=a}const c={perMesh:i,radius:n.boneRadius,spheres:n.boneSpheres,vertices:n.vertices,ms:n.ms,source:r,via:o};for(M.set(e,c);M.size>Me;)M.delete(M.keys().next().value);return c}function Ae(e,t,n,r={}){const o=A(e),i=o.map(({mesh:f})=>`${f.geometry.getAttribute("position").count}:${f.geometry.index?.count??0}`).join(","),s=`${n}|${i}|${W(t)}`,c=M.get(s);if(c)return{meshes:o,weights:c,cached:!0,key:s,job:null};const u=j.get(s);if(u)return{meshes:o,weights:null,cached:!1,key:s,job:u.promise};const a=o.reduce((f,{mesh:h})=>f+h.geometry.getAttribute("position").count,0),p=Se(e,o),l=W(t);if(o.length&&o.every(({mesh:f})=>f.geometry.userData.rigWeights===l&&f.geometry.getAttribute("skinIndex"))){const f=new Uint16Array(a*4),h=new Float32Array(a*4);let d=0;for(const{mesh:m}of o){const v=m.geometry;f.set(v.getAttribute("skinIndex").array,d*4),h.set(v.getAttribute("skinWeight").array,d*4),d+=v.getAttribute("position").count}const x=ee({positions:p.positions,skinIndex:f,skinWeight:h,joints:t.joints});return{meshes:o,weights:E(s,o,{skinIndex:f,skinWeight:h,...x,vertices:a,ms:0},"computed","main"),cached:!1,key:s,job:null}}if(a<=ke&&r.background!==!0){const f=C({...p,joints:t.joints});return f.vertices,Math.round(f.ms),{meshes:o,weights:E(s,o,f,"computed","main"),cached:!1,key:s,job:null}}const y={promise:Promise.resolve(),progress:0,vertices:a,modelKey:n};let g=0;return y.promise=ve({...p,joints:t.joints,rigKey:W(t)},f=>{y.progress=f,g++,S()}).then(f=>{E(s,o,f,f.source,f.via),y.via=f.via,f.via,f.source,f.vertices,Math.round(f.ms)}).catch(f=>{console.warn("[rig] weights",f.message)}).finally(()=>{j.delete(s),L.set(n,{at:Date.now(),vertices:a}),S(),setTimeout(S,G+50)}),j.set(s,y),S(),{meshes:o,weights:null,cached:!1,key:s,job:y.promise}}function Pe(e,t,n,r){if(!t.joints.length)return null;const{meshes:o,weights:i,cached:s,key:c,job:u}=Ae(e,t,n);if(!o.length)return null;u&&r?.(`rig:${c}`,u);const a=t.joints.map(h=>{const d=new ae;return d.name=h.name,d.userData.rigBone=h.name,d});if(t.joints.forEach((h,d)=>{const x=h.parent?t.joints.findIndex(v=>v.name===h.parent):-1,m=new w(...h.pos);x<0?(a[d].position.copy(m),e.add(a[d])):(a[d].position.copy(m.sub(new w(...t.joints[x].pos))),a[x].add(a[d]))}),t.kind==="humanoid")for(const h of["L","R"]){const d=Y(t,h),x=t.joints.findIndex(v=>v.name===`wrist${h}`);if(!d||x<0)continue;const m=new ce;m.name=`rigHold${h}`,m.userData.rigHold=h,m.position.copy(d.position),m.quaternion.copy(d.quaternion),m.scale.setScalar(d.scale),a[x].add(m)}e.updateMatrixWorld(!0);const p=[];if(i){const h=new ue(a);o.forEach(({mesh:d},x)=>{const m=d.geometry,v=i.perMesh[x];m.setAttribute("skinIndex",new le(v.skinIndex,4)),m.setAttribute("skinWeight",new de(v.skinWeight,4));const b=new fe(m,d.material);b.name=d.name,b.castShadow=d.castShadow,b.receiveShadow=d.receiveShadow,b.position.copy(d.position),b.quaternion.copy(d.quaternion),b.scale.copy(d.scale),b.frustumCulled=!0,b.userData.rigSkinned=!0,b.userData.slots=d.userData.slots;const I=d.parent;I.add(b),I.remove(d);for(const J of[...d.children])b.add(J);p.push(b)}),e.updateMatrixWorld(!0);for(const d of p)d.bind(h,d.matrixWorld)}const l=je(e),y=Math.max(.001,...l.getSize(new w).toArray()),g=i?void 0:[...j.values()].find(h=>h.promise===u),f={rig:t,bones:a,poser:K(t,i?.radius??null),meshes:p,rootRest:a[0].position.clone(),size:y,center:l.getCenter(new w),info:i?{vertices:i.vertices,ms:Math.round(i.ms),cached:s,source:s?i.source==="disk"?"disk":"memory":i.source,via:i.via}:{vertices:g?.vertices??0,ms:0,cached:!1,source:"pending",progress:g?.progress??0},spheres:i?.spheres??null};return e.userData.rig=f,f}const D=new H,P=new H,q=new w,We=new w;function U(e){const t=e.spheres;if(!(!t||!e.meshes.length))for(const n of e.meshes){n.updateMatrixWorld(!0),P.copy(n.matrixWorld).invert();const r=[],o=[];if(e.bones.forEach((u,a)=>{const p=t[a*4+3];if(!(p>0))return;const l=e.rig.joints[a].pos;D.multiplyMatrices(P,u.matrixWorld),r.push(We.set(t[a*4]-l[0],t[a*4+1]-l[1],t[a*4+2]-l[2]).applyMatrix4(D).clone()),o.push(p*D.getMaxScaleOnAxis())}),!r.length)continue;const i=new _;r.forEach((u,a)=>{i.expandByPoint(q.copy(u).addScalar(o[a])),i.expandByPoint(q.copy(u).addScalar(-o[a]))});const s=i.getCenter(new w);let c=0;r.forEach((u,a)=>{c=Math.max(c,u.distanceTo(s)+o[a])}),n.boundingSphere=new he(s,c),n.boundingBox=i}}function qe(e,t,n,r=!1){if(r)e.bones.forEach(o=>o.quaternion.identity()),e.bones[0].position.copy(e.rootRest);else{const{local:o,shift:i}=e.poser.solve(t,n||{});e.bones.forEach((s,c)=>s.quaternion.copy(o[c])),e.bones[0].position.copy(e.rootRest),e.bones[0].position.y+=i}e.bones[0].updateMatrixWorld(!0),U(e)}function Te(e,t){const n=V(e.rig),r=l=>l?e.bones[e.rig.joints.findIndex(y=>y.name===l)]:void 0,o=r(n.head),i=e.rig.joints.find(l=>l.name==="headTop"),s=e.rig.joints.find(l=>l.name===n.head),c=i&&s?Math.max(.05,i.pos[1]-s.pos[1]):.25,u=new w(0,.55*c,.3*c),a=(l,y,g,f,h)=>{if(!l)return;l.updateWorldMatrix(!0,!1);const d=l.worldToLocal(t.clone()).sub(h);l.quaternion.multiply(new pe().setFromEuler(Z(d,g,f,y))),l.updateMatrixWorld(!0)},p=r(n.neck);p&&a(p,.4,30,15,u.clone().add(new w(0,.3*c,0))),a(o,1,70,35,u);for(const l of n.eyes)a(r(l),1,45,35,new w);U(e)}function $e(e,t,n){const r=e.rig.joints.findIndex(c=>c.name===t);if(r<0)return[0,0,0];const i=e.poser.solve(n,{}).local[r].clone().invert().multiply(e.bones[r].quaternion),s=new oe().setFromQuaternion(i,"XYZ");return[s.x,s.y,s.z].map(c=>Math.round(re.radToDeg(c)*10)/10)}const T=new Map;function $(e){let t=T.get(e);return t||(t=e==="line"?new se({color:"#b8df78",depthTest:!1,transparent:!0,opacity:.9}):new ie({color:e==="picked"?"#ffad52":e==="end"?"#7fd6ff":"#b8df78",depthTest:!1,transparent:!0,opacity:.95}),t.userData.shared=!0,t.dispose=()=>{},T.set(e,t)),t}let z=null;function ze(e){const t=[];e.traverse(n=>{n.userData.rigOverlay&&t.push(n)});for(const n of t)n.parent?.remove(n),n instanceof F&&n.geometry.dispose()}function Ce(e,t,n=1){const r=e.size*.014*n;z??=(()=>{const o=new te(1,12,8);return o.userData.shared=!0,o.dispose=()=>{},o})(),e.rig.joints.forEach((o,i)=>{const s=e.bones[i],c=Q(e.rig.joints,o),u=new B(z,$(o.name===t?"picked":c?"end":"joint")),a=X(o.name)?.3:1;u.scale.setScalar(a*(o.name===t?r*1.5:c?r*.75:r)),u.userData.rigOverlay=!0,u.userData.rigJoint=o.name,u.renderOrder=1e3,u.layers.set(1),u.raycast=B.prototype.raycast,s.add(u);for(const p of e.bones.filter(l=>l.parent===s)){const l=new F(new ne().setFromPoints([new w,p.position.clone()]),$("line"));l.userData.rigOverlay=!0,l.renderOrder=999,l.layers.set(1),l.raycast=()=>{},s.add(l)}})}export{Ce as a,$e as b,Re as c,Ie as d,Se as e,je as f,Te as g,Pe as h,Be as o,qe as p,ze as r,Oe as w};