clipoox-render 0.4.1 → 0.4.3
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.
- package/package.json +1 -1
- package/scripts/render-local.mjs +1322 -1320
- package/web/assets/{FxEmbed-CGqGi2Lw.js → FxEmbed-BCmj9Q5C.js} +1 -1
- package/web/assets/{MotionEmbed-C3CZ3_y_.js → MotionEmbed-CEmbcq8Z.js} +1 -1
- package/web/assets/PluginStore-C5hyahvG.js +3 -0
- package/web/assets/{ShotComposer-DFfaYLoV.js → ShotComposer-0DUtMTVI.js} +4 -4
- package/web/assets/{TemplateEmbed-C8pXcPsc.js → TemplateEmbed-ANxSs7H5.js} +1 -1
- package/web/assets/{TimelinePlugins-DnkV3i4G.js → TimelinePlugins-BYZ9y4m3.js} +4 -4
- package/web/assets/{TimelinePlugins-DYarX9RK.css → TimelinePlugins-D841ngau.css} +1 -1
- package/web/assets/{TimelineShotFx-foiuuogg.js → TimelineShotFx-q5PQwq-V.js} +2 -2
- package/web/assets/{TransitionEmbed-BueDilY0.js → TransitionEmbed-O6LInGWq.js} +1 -1
- package/web/assets/{Whiteboard-zBsNHh5h.js → Whiteboard-BP_DvIAV.js} +1 -1
- package/web/assets/{aerial-z34Nww_T.js → aerial-CGLDKKtP.js} +2 -2
- package/web/assets/{agentTools-ALxghYpf.js → agentTools-2Ghb80VH.js} +2 -2
- package/web/assets/{analyzerRun-DNwryAlU.js → analyzerRun-DRgxrcJA.js} +1 -1
- package/web/assets/{analyzerSandbox-A1oFsCrO.js → analyzerSandbox-DuIVFnsk.js} +1 -1
- package/web/assets/{api-DUp403BK.js → api-CJ8PdbfZ.js} +5 -5
- package/web/assets/{auraTrack-BKVZCwNt.js → auraTrack-DQw9sVU6.js} +1 -1
- package/web/assets/{breakthrough-Cwt8gEwK.js → breakthrough-BNj_iTDr.js} +2 -2
- package/web/assets/{cameraPresets-DSOPj4oy.js → cameraPresets-CYw0OdM3.js} +1 -1
- package/web/assets/{captionLayout-EuB59pN_.js → captionLayout-DvDPTwO9.js} +1 -1
- package/web/assets/{clientExport-BL1XMTF0.js → clientExport-xhoXY6Dh.js} +1 -1
- package/web/assets/conversion-4rhF3xRJ.js +17 -0
- package/web/assets/{depthEstimate-DOvsY8mn.js → depthEstimate-DEpeCojm.js} +1 -1
- package/web/assets/{directorTools-BkbNYbSq.js → directorTools-C5CpTmci.js} +1 -1
- package/web/assets/{distortFrames-Drch0LhT.js → distortFrames-Dia8O1NM.js} +2 -2
- package/web/assets/{distortGL-BlmBZKRU.js → distortGL-QalhICvi.js} +1 -1
- package/web/assets/{editTools-BcGinqHC.js → editTools-CY_JrQfw.js} +1 -1
- package/web/assets/engine-BedcnK45.js +1 -0
- package/web/assets/{exportEncode-MUwVTI52.js → exportEncode-QYsT9JBO.js} +1 -1
- package/web/assets/{exportGlb-SIXFRRJM.js → exportGlb-TSj09XoV.js} +1 -1
- package/web/assets/{faceTracker-DCbZbLMc.js → faceTracker-CnCWOwnJ.js} +1 -1
- package/web/assets/{fightDirector-hlF1JS_z.js → fightDirector-DCI_FWTh.js} +1 -1
- package/web/assets/{fightDrama-fHN5EXk3.js → fightDrama-Bg7uP_2Q.js} +2 -2
- package/web/assets/{frameSink-BvOXjLuw.js → frameSink-DeM8xC8_.js} +3 -3
- package/web/assets/{gpuCompose-CNkLwpbZ.js → gpuCompose-CA3UmOl4.js} +1 -1
- package/web/assets/{gpuExport-DQB6x4eh.js → gpuExport-D31azOQA.js} +13 -9
- package/web/assets/{handMatte-BD7OE3Zc.js → handMatte-Dl-xVXFR.js} +1 -1
- package/web/assets/{handTracker-BumGtRCW.js → handTracker-CplBsAFg.js} +2 -2
- package/web/assets/{id3-BCR9Bqgo.js → id3-arvEpAg7.js} +1 -1
- package/web/assets/{index-CuaB7Y0L.js → index-D5oyVCRl.js} +1 -1
- package/web/assets/index-_tSTJnL9.js +8 -0
- package/web/assets/layer-worker-DFuo32bk.js +5 -0
- package/web/assets/library-BufgA-Pl.js +1 -0
- package/web/assets/{lottieLayer-1ET89OUr.js → lottieLayer-DzbA3bHV.js} +4 -4
- package/web/assets/{lottie_light_canvas-DD9pkFL8.js → lottie_light_canvas-B-d7-ATe.js} +1 -1
- package/web/assets/main-VVYiW8XD.js +309 -0
- package/web/assets/{mapBake-DLoBt_k5.js → mapBake-BKOcEd0w.js} +1 -1
- package/web/assets/maskTrack-CHGXtBRy.js +1 -0
- package/web/assets/{matteFixRun-BdHKC3m5.js → matteFixRun-vgYrINet.js} +1 -1
- package/web/assets/{objectLocate-bZtc5AJo.js → objectLocate-BJltm8Ob.js} +1 -1
- package/web/assets/{output-BwZzMbp-.js → output-p-Q7qous.js} +1 -1
- package/web/assets/{pendingMatte-mlyLLZCT.js → pendingMatte-BPyzzx4y.js} +2 -2
- package/web/assets/{personAi-CUNQeseG.js → personAi-gJu03SjU.js} +2 -2
- package/web/assets/{plateCamera-_jP1xXnj.js → plateCamera-B2JvhjJw.js} +1 -1
- package/web/assets/{plateCameraMatch-rr0oUwQ2.js → plateCameraMatch-ByB9nVQT.js} +2 -2
- package/web/assets/{plateFollow-BjvtcT8q.js → plateFollow-C9S-l7RH.js} +2 -2
- package/web/assets/{plateMatte-BqyL8cQZ.js → plateMatte-J4qlNHnY.js} +2 -2
- package/web/assets/{pluginAutomation-Dp188qm7.js → pluginAutomation-CkP3tA9r.js} +1 -1
- package/web/assets/{poseTracker-DDGDhhMF.js → poseTracker-DGLbouqt.js} +1 -1
- package/web/assets/{productTools-CRgI88-O.js → productTools-CkaWF1bM.js} +2 -2
- package/web/assets/remote-C7J0Tqhb.js +1433 -0
- package/web/assets/{rigTrack-UYZU4P-e.js → rigTrack-urT3nDK0.js} +1 -1
- package/web/assets/{rotoMaskStore-BxyxB2bD.js → rotoMaskStore-DPziPKAN.js} +1 -1
- package/web/assets/{rotoMatte-BdYa8FSB.js → rotoMatte-C-2o3vv0.js} +1 -1
- package/web/assets/{rotoscope-DDixNQCt.js → rotoscope-GvPFRUBg.js} +1 -1
- package/web/assets/{shot-worker-D9sZS6bn.js → shot-worker-6dYkHPoL.js} +1 -1
- package/web/assets/{shotFxAgent-7RQNtEe4.js → shotFxAgent-BFLkqs8v.js} +1 -1
- package/web/assets/{skin-CVwmK130.js → skin-DY4QLaBI.js} +1 -1
- package/web/assets/{spark.module-B34aiScb.js → spark.module-DzziUgOj.js} +1 -1
- package/web/assets/{spellDuel-BkweL6pI.js → spellDuel-BD3m2ebA.js} +2 -2
- package/web/assets/store-Cug4GGcP.js +1 -0
- package/web/assets/{store-75tQUvPT.js → store-DW4E9xnW.js} +1 -1
- package/web/assets/{surfaceLight-DhU-zgNL.js → surfaceLight-aDSYU8Jg.js} +1 -1
- package/web/assets/surfacePin-m83hCgGP.js +2 -0
- package/web/assets/{textAnimators-nVSz_sZo.js → textAnimators-DUZjhVGO.js} +1 -1
- package/web/assets/{thumb-r6dlZprA.js → thumb-CS0ZuiGS.js} +1 -1
- package/web/assets/{timeline3d-246tBEJl.js → timeline3d-DOw-CpZI.js} +2 -2
- package/web/assets/{timeline3dExport-T57qnWi9.js → timeline3dExport-BtYLU1pw.js} +1 -1
- package/web/assets/{timelineComp-BcewYGR2.js → timelineComp-B4GtoH2f.js} +1 -1
- package/web/assets/{timelineProps-CJzzAWWO.js → timelineProps-D7MVutxu.js} +1 -1
- package/web/assets/{timelineText-BzUhNWPB.js → timelineText-BH09jfSM.js} +1 -1
- package/web/assets/{titleArt-B8DVR58F.js → titleArt-Drsrtfiv.js} +3 -3
- package/web/assets/{titleFrameBudget-BYRZAQPs.js → titleFrameBudget-CLZWaFHO.js} +1 -1
- package/web/assets/{titleFrames-BVgm601q.js → titleFrames-BI1DnLBn.js} +1 -1
- package/web/assets/{tool-CAGU3dUa.js → tool-DktQYmS6.js} +1 -1
- package/web/assets/{tools-DVaOkokV.js → tools-Co9aRDiT.js} +1 -1
- package/web/assets/{toonTools-CfGTR_H1.js → toonTools-CD9clJvN.js} +2 -2
- package/web/assets/{trackAnchor-DzUt1r5Q.js → trackAnchor-sOjTtd3I.js} +1 -1
- package/web/assets/{userFonts-DzY0A4bD.js → userFonts-CwlKh9NR.js} +1 -1
- package/web/assets/{vfxAlpha-DQJOaZ9v.js → vfxAlpha-71tSN86T.js} +2 -2
- package/web/assets/{vfxBackground-DiktQFOD.js → vfxBackground-Bq7lJvmZ.js} +2 -2
- package/web/assets/{videoExport-Ce0ElSQR.js → videoExport-D4KbireJ.js} +1 -1
- package/web/assets/{views-V3si1lOz.js → views-ozVF4ABO.js} +1 -1
- package/web/assets/{weaponDuel-D6sLVGmG.js → weaponDuel-ZhX-tjGZ.js} +1 -1
- package/web/assets/{windowFrames-D_2QJCJJ.js → windowFrames-CpqX3kOM.js} +1 -1
- package/web/layer-worker.html +3 -3
- package/web/assets/PluginStore-DKXZ-jBj.js +0 -3
- package/web/assets/index-DYa7fEK0.js +0 -24
- package/web/assets/layer-worker-DxPMMKIZ.js +0 -5
- package/web/assets/library-CyjJ8nGG.js +0 -1
- package/web/assets/main-BKjBWQik.js +0 -309
- package/web/assets/maskTrack-C2SJbDGO.js +0 -1
- package/web/assets/remote-Dva2qg58.js +0 -1241
- package/web/assets/surfacePin-ObK6QgDm.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
import{f as l,e as v}from"./lottieLayer-
|
|
1
|
+
import{f as l,e as v}from"./lottieLayer-DzbA3bHV.js";import{c as b,h}from"./api-CJ8PdbfZ.js";import{c1 as g}from"./titleFrameBudget-CLZWaFHO.js";import{g as y}from"./gpuCompose-CA3UmOl4.js";import{c as M}from"./id3-arvEpAg7.js";import{B as k,O as B,a as F,W as O,C as x}from"./output-p-Q7qous.js";import"./rigTrack-urT3nDK0.js";async function E(a,d,s){if(!a.geo)throw Error("Not a map layer");const{width:t,height:o,fps:e}=g({...d,resolution:"720p"}),m=Math.max(1,Math.round(a.duration*e)),r=await M("avc",{width:t,height:o}).catch(()=>!1),c=Object.assign(document.createElement("canvas"),{width:t,height:o}),i=`bake:${a.id}`,f=new k,u=new B({format:r?new F({fastStart:"in-memory"}):new O,target:f}),w=new x(c,{codec:r?"avc":"vp9",bitrate:y(t,o,e),keyFrameInterval:2});u.addVideoTrack(w,{frameRate:e}),await u.start();try{for(let n=0;n<m;n++)await l(i,a.geo,{W:t,H:o},n/e,c,{wait:2e4,lang:h()==="en"?"en":"vi",duration:a.duration}),await w.add(n/e,1/e),s?.((n+1)/m);await u.finalize()}finally{v(i)}const p=r?"video/mp4":"video/webm";return{blob:new Blob([f.buffer],{type:p}),type:p,ext:r?"mp4":"webm"}}async function T(a,d,s){const{blob:t,type:o,ext:e}=await E(a,d,i=>s?.(i*.9)),{url:m,gcsUri:r}=await b(new File([t],`map-${a.id.slice(0,8)}.${e}`,{type:o}),i=>s?.(.9+i/1e3)),c=(a.label||"Map").replace(/^Bản đồ/,"Bản đồ (video)").slice(0,80);return{kind:"video",url:m,gcsUri:r,inPoint:0,sourceDuration:a.duration,volume:0,label:c,geo:void 0}}export{T as bakeMap,E as renderMapVideo};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{cz as g,cI as y}from"./titleFrameBudget-CLZWaFHO.js";import{i8 as w}from"./remote-C7J0Tqhb.js";import{$ as f}from"./main-VVYiW8XD.js";import{t as k}from"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";import"./spark.module-DzziUgOj.js";import"./userFonts-CwlKh9NR.js";import"./lottieLayer-DzbA3bHV.js";import"./timeline3d-DOw-CpZI.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-QYsT9JBO.js";import"./captionLayout-DvDPTwO9.js";import"./timelineText-BH09jfSM.js";import"./titleArt-Drsrtfiv.js";import"./rotoMatte-C-2o3vv0.js";import"./distortGL-QalhICvi.js";import"./motionBlur-uAm030t9.js";const v=r=>document.querySelector(`video[data-clip-media="${r.id}"]`)?.currentSrc||r.url;async function N(r,d){const e=d.params?.masks??[];if(!r.mask||!("masks"in r.mask||r.mask.v===1))throw Error(k("Clip không còn mask cần bám"));let m=g(r.mask);const i=Math.max(0,r.duration-1/60);let n=0;for(const t of e){if(!m.find(a=>a.id===t.id))continue;const o=Math.max(0,Math.min(i,t.at)),c=v(r);try{const a=o<i?await f({clip:r,url:c,quad:t.region,mode:t.mode,from:o,to:i}):{frames:[]},p=o>0?await f({clip:r,url:c,quad:t.region,mode:t.mode,from:o,to:0}):{frames:[]},u=[o,...t.region.flat(),1],h=[...[...p.frames].reverse(),u,...a.frames];m=m.map(s=>s.id===t.id?{...s,keys:w(s,h,o,t.mode)}:s),n++}catch(a){if(a.name==="AbortError")throw a}}if(e.length&&!n)throw Error(k("Không bám được vùng của mask (vùng quá phẳng) — mask giữ nguyên chỗ đã vẽ."));return{mask:y(r.mask,m)}}export{N as runMaskTrack};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as g}from"./store-
|
|
1
|
+
import{u as g}from"./store-DW4E9xnW.js";import{t as v}from"./api-CJ8PdbfZ.js";import{ad as L,ae as U}from"./main-VVYiW8XD.js";import{a7 as P,c1 as G,c2 as J,cx as H}from"./titleFrameBudget-CLZWaFHO.js";import{bd as E,iL as W,iK as j}from"./remote-C7J0Tqhb.js";import{fillCapsule as N}from"./handMatte-Dl-xVXFR.js";import"./three.module-Bx43vjkH.js";import"./spark.module-DzziUgOj.js";import"./GLTFLoader-BHWu1lKg.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";import"./userFonts-CwlKh9NR.js";import"./lottieLayer-DzbA3bHV.js";import"./timeline3d-DOw-CpZI.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-QYsT9JBO.js";import"./captionLayout-DvDPTwO9.js";import"./timelineText-BH09jfSM.js";import"./titleArt-Drsrtfiv.js";import"./rotoMatte-C-2o3vv0.js";import"./distortGL-QalhICvi.js";import"./motionBlur-uAm030t9.js";const x=Object.freeze({max:200,points:120,size:[.002,.3],handSize:[.02,1.5],spread:[0,60]}),M=t=>Math.round(t*1e4)/1e4;function I(t,e,n){const o=[t[0][0]*e,t[0][1]*n],i=[t[9][0]*e,t[9][1]*n],c=Math.hypot(i[0]-o[0],i[1]-o[1])||1,s=[(i[0]-o[0])/c,(i[1]-o[1])/c],r=[-s[1],s[0]];return{o,ex:s,ey:r,S:c}}const X=(t,e)=>{const n=e[0]-t.o[0],o=e[1]-t.o[1];return[(n*t.ex[0]+o*t.ex[1])/t.S,(n*t.ey[0]+o*t.ey[1])/t.S]},Y=(t,e)=>[t.o[0]+(e[0]*t.ex[0]+e[1]*t.ey[0])*t.S,t.o[1]+(e[0]*t.ex[1]+e[1]*t.ey[1])*t.S],O=t=>{const e=Math.max(1,Math.ceil(t.length/x.points));return t.filter((n,o)=>o%e===0||o===t.length-1).slice(0,x.points)};function $(t,e,n,{mode:o="add",points:i,size:c=.02,spread:s=8}={}){const r=E(t,n),a=e.mw,h=e.mh;let m=null;for(const p of[0,1]){const u=W(e,r,p);if(!u)continue;const w=I(u,a,h),d=Math.hypot(i[0][0]*a-w.o[0],i[0][1]*h-w.o[1])/w.S;(!m||d<m.d)&&(m={slot:p,F:w,d})}if(!m)return null;const l=Math.max(x.handSize[0],Math.min(x.handSize[1],c*a/m.F.S));return{anchor:"hand",s:M(r),slot:m.slot,mode:o,pts:O(i).map(p=>X(m.F,[p[0]*a,p[1]*h]).map(M)),r:M(l),spread:R(s)}}function B(t,{mode:e="add",points:n,size:o=.02,spread:i=0,moves:c=null}={}){const s=R(i),r=Array.isArray(c)&&c.length===2*s+1?c.map(a=>a?[M(a[0]),M(a[1])]:null):Array.from({length:2*s+1},(a,h)=>h===s?[0,0]:null);return{anchor:"track",s:M(t),mode:e,pts:O(n).map(a=>a.map(M)),r:M(Math.max(x.size[0],Math.min(x.size[1],o))),spread:s,moves:r}}const R=t=>Math.round(Math.max(x.spread[0],Math.min(x.spread[1],Number(t)||0)));function Q(t,e,n,o,{dec:i=null,s:c,k:s=0}={}){let r,a;if(o.anchor==="hand"){const m=i&&W(i,c,o.slot);if(!m)return!1;const l=I(m,e,n);r=o.pts.map(p=>Y(l,p)),a=o.r*l.S}else{const m=o.moves[s+o.spread];if(!m)return!1;r=o.pts.map(l=>[(l[0]+m[0])*e,(l[1]+m[1])*n]),a=o.r*e}r.length===1&&r.push(r[0]);const h=new Uint8Array(e*n);for(let m=1;m<r.length;m++)N(h,r[m-1],r[m],a,e,n);for(let m=0;m<t.length;m++)h[m]&&(t[m]=o.mode==="add"?255:0);return!0}function V(t,e,n,o=null){const i=t.length,c=new Array(i),s=new Set;for(let r=0;r<i;r++)c[r]=t[r];for(const r of n||[]){const a=Math.round((r.s-e.s0)*e.fps);for(let h=Math.max(0,a-r.spread);h<=Math.min(i-1,a+r.spread);h++)s.has(h)||(c[h]=new Uint8Array(t[h]),s.add(h)),Q(c[h],e.w,e.h,r,{dec:o,s:e.s0+h/e.fps,k:h-a})}return{frames:c,changed:s.size}}const T=(t,e)=>t.hands?t:e.find(n=>n.id===t.hud?.src)??e.find(n=>n.hands&&n.url===t.url&&n.id!==t.id);async function K(t,e,n){if(!e.length)return t;const o=await P(t),i=V(o,{w:t.w,h:t.h,fps:t.fps,s0:t.s0},e,n?j(n):null);return U(Array.from({length:t.n},(c,s)=>i.frames[s]),{mw:t.mw,mh:t.mh,w:t.w,h:t.h,fps:t.fps,s0:t.s0},{feather:t.feather??0,grow:t.grow??0,...t.lv?{lv:t.lv}:{},...t.src?{src:t.src}:{}})}const Z=320;async function q(t,e,n,o,i){const c=Array.from({length:2*o+1},(r,a)=>a===o?[0,0]:null);if(!o)return c;const s=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});s.src=t;try{await new Promise((d,y)=>{s.onloadeddata=()=>d(),s.onerror=()=>y(Error(v("Không đọc được video để bám nét sửa")))});const r=Math.min(Z,s.videoWidth),a=Math.max(2,Math.round(r*s.videoHeight/s.videoWidth)),h=Object.assign(document.createElement("canvas"),{width:r,height:a}),m=h.getContext("2d",{willReadFrequently:!0}),l=async d=>{await new Promise(S=>{s.onseeked=()=>S(),s.currentTime=Math.max(0,Math.min(s.duration-1/60,d))}),m.drawImage(s,0,0,r,a);const y=m.getImageData(0,0,r,a).data,k=new Float32Array(r*a);for(let S=0,f=0;S<k.length;S++,f+=4)k[S]=.299*y[f]+.587*y[f+1]+.114*y[f+2];return k},p=await l(e),u=n[0]*r,w=n[1]*a;for(const d of[1,-1]){let y=p,k=u,S=w,f=u,A=w;for(let b=1;b<=o;b++){const _=await l(e+d*b/i);let F=H(y,_,r,a,k,S,{near:{x:f,y:A}});if(!F||F.score<.5){const C=await l(e+d*(b-1)/i),z=H(C,_,r,a,f,A);if(z&&z.score>=.5)y=C,k=f,S=A,F=z;else break}f=F.x,A=F.y,c[o+d*b]=[(f-u)/r,(A-w)/a]}}return c}finally{s.removeAttribute("src"),s.load()}}async function tt(t,{local:e,mode:n,points:o,size:i,spread:c}){const s=g.getState(),r=s.clips.find(l=>l.id===t);if(!r?.person)throw Error(v("Clip chưa có phần tách bằng AI"));const a=T(r,s.clips),h=r.person.fps||30;let m=a?.hands?$(r,j(a.hands),e,{mode:n,points:o,size:i,spread:c}):null;if(!m){const l=o[Math.floor(o.length/2)],p=document.querySelector(`video[data-clip-media="${r.id}"]`)?.currentSrc||r.url;m=B(E(r,e),{mode:n,points:o,size:i,spread:c,moves:await q(p,E(r,e),l,c,h)})}return D(t,[...r.matteFix?.fixes??[],m])}async function D(t,e){const n=g.getState(),o=n.clips.find(a=>a.id===t);if(!o?.person)throw Error(v("Clip chưa có phần tách bằng AI"));const i=o.matteFix?.auto??o.person,c=T(o,n.clips),s=await K(i,e,c?.hands),r=e.length?{auto:i,fixes:e}:void 0;return g.setState(a=>({clips:a.clips.map(h=>h.id===t?{...h,person:s,matteFix:r}:h)})),e.length}async function Ft(t,e){const n=e.params??{};n.clear&&await D(t.id,[]);const{width:o,height:i}=G(g.getState().timelineFormat);for(const c of n.strokes??[]){const s=g.getState().clips.find(l=>l.id===t.id);if(!s?.person)throw Error(v("Clip chưa có phần tách bằng AI"));const r=s.crop||{left:0,right:0,top:0,bottom:0},a=1-r.left-r.right,h=1-r.top-r.bottom,m=c.points.map(([l,p])=>{const u=J(s,l*o,p*i,c.local,o,i,s.person.mw,s.person.mh);return[r.left+u.u*a,r.top+u.v*h]});await tt(t.id,{local:c.local,mode:c.mode,points:m,size:c.size,spread:c.spread})}return n.roto&&await rt(t.id),{}}async function rt(t){const e=g.getState(),n=e.clips.find(r=>r.id===t);if(!n?.person)throw Error(v("Clip chưa có phần tách bằng AI"));const o=n.matteFix?.auto??n.person,i=n.person,c=await P(i),s=L(c,{w:i.w,h:i.h,fps:i.fps,s0:i.s0},n,{mw:i.mw,mh:i.mh});if(!s)throw Error(v("Không tìm thấy vùng nào để chuyển thành đường Roto"));return g.setState(r=>({clips:r.clips.map(a=>{if(a.id!==t)return a;const{person:h,...m}=a;return{...m,mask:s,matteFix:{auto:o,fixes:n.matteFix?.fixes??[]}}})})),s.masks.length}async function zt(t){const e=g.getState(),n=e.clips.find(c=>c.id===t);if(!n?.matteFix)return;const o=T(n,e.clips),i=await K(n.matteFix.auto,n.matteFix.fixes,o?.hands);g.setState(c=>({clips:c.clips.map(s=>{if(s.id!==t)return s;const{mask:r,...a}=s;return{...a,person:i,...n.matteFix.fixes.length?{}:{matteFix:void 0}}})}))}export{tt as addMatteFix,zt as backToAi,rt as convertToRoto,K as fixedMatte,T as handsSource,Ft as runMatteFixJob,D as setFixes,q as trackStroke};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as d,c1 as h}from"./api-
|
|
1
|
+
import{t as d,c1 as h}from"./api-CJ8PdbfZ.js";import"./titleFrameBudget-CLZWaFHO.js";const g=r=>document.querySelector(`video[data-clip-media="${r.id}"]`)?.currentSrc||r.url;async function l(r,i,o=1024){const t=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});t.src=g(r);try{await new Promise((a,c)=>{t.onloadeddata=()=>a(),t.onerror=()=>c(Error(d("Không đọc được video để tách vật thể (CORS / định dạng)")))});const n=Math.max(0,Math.min(t.duration-1/60,i));Math.abs(t.currentTime-n)>1e-4&&await new Promise((a,c)=>{const u=window.setTimeout(()=>c(Error(d("Seek video quá lâu"))),8e3);t.onseeked=()=>{window.clearTimeout(u),a()},t.currentTime=n});const e=Math.min(o,t.videoWidth),s=Math.max(2,Math.round(e*t.videoHeight/t.videoWidth)),m=Object.assign(document.createElement("canvas"),{width:e,height:s});return m.getContext("2d").drawImage(t,0,0,e,s),m.toDataURL("image/jpeg",.85).split(",")[1]}finally{t.removeAttribute("src"),t.load()}}async function v(r,i,o,t){const n=await l(i,t),e=await h(r,{image:n,name:o});if(!e.points.length)throw Object.assign(Error(e.error||d("Không thấy “{0}” trong khung hình",[o])),{credits:e.credits});return e}export{l as clipFrameJpeg,v as findObjectPoints};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{d as ct,m as Ee,e as dt,v as K,p as lt,t as V,f as hi,g as u,w as fi,
|
|
1
|
+
import{d as ct,m as Ee,e as dt,v as K,p as lt,t as V,f as hi,g as u,w as fi,h as Y,F as qe,i as J,j as B,k as nt,l as xe,r as Yi,n as Zi,o as Ji,q as es,s as le,u as ue,x as $e,y as ut,R as ts,z as re,C as Te,D as mi,P as be,E as pi,G as ht,T as ft,M as mt,H as is,J as ss,K as rs,L as ns,N as pt,O as as,S as gi,W as vt,X as we,Y as os,Z as ve,_ as cs,$ as ds,a0 as ls,a1 as us,a2 as hs,a3 as wi,a4 as Ne,a5 as Ti,a6 as yi,a7 as gt,a8 as bi,a9 as ki,aa as fs,ab as Si,ac as _i,ad as It,ae as Ke,af as ms,ag as g,ah as Mt,ai as ps,aj as he,ak as gs,al as Ft,am as ws,an as Ts,ao as ys,ap as bs,aq as ks,ar as He,as as Ss,at as _s,au as Ci,av as Ot,aw as Ei,ax as xi,ay as je,az as zt,aA as Rt,aB as Cs,aC as Es,aD as xs,aE as Ps,aF as As,aG as vs,aH as Is,aI as Ms,aJ as Fs,aK as Bt,aL as Os,aM as zs,aN as Rs,aO as Wt,aP as Ut,aQ as Vt,aR as ke,aS as Lt,aT as Bs,aU as Pi,aV as Nt,aW as ze,aX as Re,aY as Be,aZ as Ws,a_ as Z,a$ as de,b0 as wt,b1 as me,b2 as ne,b3 as pe,b4 as ge,b5 as Ai,b6 as Ht,b7 as Ce,b8 as Dt,b9 as vi,ba as Us,bb as Vs,bc as Ii,bd as Ls,be as se,bf as Ns,bg as Hs,bh as Tt,bi as Ds,bj as $s,bk as Qs,bl as qs,bm as j,bn as Ks,bo as js,bp as Gs,bq as Xs,br as Ys,bs as Le,bt as Zs,bu as Js,bv as te,bw as ye,bx as yt,by as bt,bz as er,bA as tr,bB as ir}from"./id3-arvEpAg7.js";/*!
|
|
2
2
|
* Copyright (c) 2026-present, Vanilagy and contributors
|
|
3
3
|
*
|
|
4
4
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/main-
|
|
2
|
-
import{dz as O,dA as C,_ as B,dv as S,na as H,hB as x,c1 as M,lk as j}from"./titleFrameBudget-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/main-VVYiW8XD.js","assets/titleFrameBudget-CLZWaFHO.js","assets/remote-C7J0Tqhb.js","assets/api-CJ8PdbfZ.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/store-DW4E9xnW.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js","assets/spark.module-DzziUgOj.js","assets/userFonts-CwlKh9NR.js","assets/lottieLayer-DzbA3bHV.js","assets/timeline3d-DOw-CpZI.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/exportEncode-QYsT9JBO.js","assets/captionLayout-DvDPTwO9.js","assets/timelineText-BH09jfSM.js","assets/titleArt-Drsrtfiv.js","assets/rotoMatte-C-2o3vv0.js","assets/distortGL-QalhICvi.js","assets/motionBlur-uAm030t9.js","assets/main-Ca_CVxMz.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{dz as O,dA as C,_ as B,dv as S,na as H,hB as x,c1 as M,lk as j}from"./titleFrameBudget-CLZWaFHO.js";import{am as T}from"./remote-C7J0Tqhb.js";import{a2 as D,a3 as z,a4 as R,a5 as W}from"./main-VVYiW8XD.js";import{u as m}from"./store-DW4E9xnW.js";import{t as p,af as A}from"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";import"./spark.module-DzziUgOj.js";import"./userFonts-CwlKh9NR.js";import"./lottieLayer-DzbA3bHV.js";import"./timeline3d-DOw-CpZI.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-QYsT9JBO.js";import"./captionLayout-DvDPTwO9.js";import"./timelineText-BH09jfSM.js";import"./titleArt-Drsrtfiv.js";import"./rotoMatte-C-2o3vv0.js";import"./distortGL-QalhICvi.js";import"./motionBlur-uAm030t9.js";const _=e=>document.querySelector(`video[data-clip-media="${e.id}"]`)?.currentSrc||e.url;function $(e,s=!1,t=!1){let g=null,d=-1;const a=(h,o="info")=>{const r=m.getState();g!==null&&r.dismissToast(g),r.toast(h,o),g=m.getState().toasts.at(-1)?.id??null};return a(s?p("Đang chạy Pro Cut cho “{0}” trên máy chủ… (khoảng 2 phút cho 1 phút video)",[e]):t?p("Đang tách vật thể AI cho “{0}”… (chạy trên máy, không tốn credit)",[e]):p("Đang tách người AI cho “{0}”… (chạy trên máy, không tốn credit)",[e])),{progress:h=>{const o=Math.floor(h.done/h.total*4)*25;o>d&&o<100&&o>0&&(d=o,a(s?p("Đang giữ lại người trong kết quả Pro Cut “{0}”… {1}%",[e,o]):t?p("Đang tách vật thể AI cho “{0}”… {1}%",[e,o]):p("Đang tách người AI cho “{0}”… {1}%",[e,o])))},done:(h,o="ok")=>a(h,o)}}const E=e=>{const s=document.querySelector(`video[data-clip-media="${e.id}"]`);return{duration:e.duration,sourceDuration:e.sourceDuration,width:s?.videoWidth||void 0,height:s?.videoHeight||void 0}};async function F(e,s,t){if(e.kind!=="video")throw Error(p("Chỉ tách người được trên clip video"));const g=await D({clip:e,url:_(e),signal:t,onProgress:s}),d=O(m.getState().clips.filter(a=>a.id!==e.id));if(g.data&&d+g.data.length>C)throw Error(p("Timeline đã chứa quá nhiều mặt nạ người AI (giới hạn lưu của dự án). Hãy xoá bớt mặt nạ ở clip khác hoặc cắt ngắn clip."));return g}async function L(e,s,t,g){const{segmentObject:d}=await B(async()=>{const{segmentObject:o}=await import("./main-VVYiW8XD.js").then(r=>r.aL);return{segmentObject:o}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])),a=await d({clip:e,url:_(e),pts:s.pts.map(([o,r])=>({x:o,y:r})),at:s.at,signal:g,onProgress:t}),h=O(m.getState().clips.filter(o=>o.id!==e.id));if(a.data&&h+a.data.length>C)throw Error(p("Timeline đã chứa quá nhiều mặt nạ người AI (giới hạn lưu của dự án). Hãy xoá bớt mặt nạ ở clip khác hoặc cắt ngắn clip."));return a}const I=(e,s)=>e.map(t=>{if(t.id!==s||!t.personPending)return t;const g={...t};return delete g.personPending,g}),w=new Set,ut=e=>w.has(e);function ft(e,s){for(const t of e)t.personPending&&t.kind==="video"&&!w.has(t.id)&&(w.add(t.id),N(t.id,s).finally(()=>w.delete(t.id)))}async function N(e,s){let t=m.getState().clips.find(i=>i.id===e);if(!t?.personPending||m.getState().timelineTracks[t.track]?.locked||S(t.personPending).length&&(await V(t,s),t=m.getState().clips.find(i=>i.id===e),!t?.personPending||!H(t.personPending)))return;const d=t.personPending.job,a=$(t.label,!!d);let h;try{if(d){const i=await z(t,await R(d),{onProgress:a.progress}),n=t.person&&t.person.src!=="object"?t.person.pick:void 0;h=n?{...i,pick:n}:i}else h=t.person&&t.person.src!=="object"?t.person:await F(t,a.progress)}catch(i){A(d?"person-matte-hq":"person-matte",i.message,{op:"pending",...E(t)}),a.done(d?p("Chưa chạy Pro Cut được cho “{0}”: {1}",[t.label,i.message]):p("Chưa tách được người cho “{0}”: {1} — mở Roto → Tách người rồi “Đặt ra sau người”.",[t.label,i.message]),"error"),m.getState().clips.find(n=>n.id===e)?.personPending&&m.setState(n=>({clips:I(n.clips,e)}));return}const o=m.getState(),r=o.clips.find(i=>i.id===e);if(!r||!r.personPending&&!d)return;const f=x(o.clips,new Map([[e,h]])),u=[...(r.personPending?.behind??[]).filter(i=>f.some(n=>n.id===i)).map(i=>({op:"placeBehindPerson",clipId:i,sourceClipId:e})),...(r.personPending?.then??[]).map(i=>({...i,clipId:e}))],P=M({...o.timelineFormat,resolution:"720p"}),b=f.find(i=>i.id===e);for(let i=0;i<u.length;i++){const n=u[i];if(n.op!=="clonePerson"||n.feet!=null||!b)continue;const l=await W(b,Math.max(0,(n.start??b.start)-b.start),P.width,P.height).catch(()=>null);l&&(u[i]={...n,feet:l.feet,...n.horizon==null?{horizon:l.horizon}:{}})}const c=u.length?T(f,u,[],o.timelineTracks,o.timelineCamera,{noPendingMatte:!0,W:P.width,H:P.height}):null;m.setState({clips:I(o.clips,e)}),s(),m.setState({clips:c?c.clips:f,...c?{timelineTracks:c.tracks}:{}});const k=c?c.applied.filter(i=>i.startsWith("placeBehindPerson")).length:0,v=c?c.applied.filter(i=>/^(personEcho|clonePerson|personElectric|speedBolt)/.test(i)).length:0;a.done(c?.errors.length?p("Đã tách người cho “{0}”; {1} lớp chưa đặt ra sau người được: {2}",[r.label,c.errors.length,c.errors.join(" · ")]):v&&!k?p("Đã tách người cho “{0}” và tạo {1} hiệu ứng (vệt bóng / nhân bản).",[r.label,v]):u.length?p("Đã tách người cho “{0}” và đặt {1} lớp ra sau người.",[r.label,k]):d?p("Đã Pro Cut cho “{0}” ({1} khung).",[r.label,h.n]):p("Đã tách người cho “{0}” ({1} khung).",[r.label,h.n]),c?.errors.length?"error":"ok")}async function V(e,s){const t=e.id,g=S(e.personPending),d=$(e.label,!1,!0),a=new Map,h=[];for(const n of g)try{a.set(`${t}|${n.id}`,await L(e,{pts:n.pts,at:n.at},d.progress))}catch(l){h.push(`${n.name}: ${l.message}`),A("object-matte",l.message,{op:"pending",...E(e)})}const o=m.getState(),r=o.clips.find(n=>n.id===t);if(!r?.personPending)return;const f=S(r.personPending);let u=o.clips;for(const n of f)a.has(`${t}|${n.id}`)||(u=u.map(l=>l.id===t?j(l,n.id):l));const P=f.filter(n=>a.has(`${t}|${n.id}`)).flatMap(n=>{const l=n.behind.filter(y=>u.some(q=>q.id===y));return l.length?l.map(y=>({op:"placeBehindObject",clipId:y,sourceClipId:t,objectId:n.id})):[{op:"cutOutObject",clipId:t,objectId:n.id}]}),b=M({...o.timelineFormat,resolution:"720p"}),c=P.length?T(u,P,[],o.timelineTracks,o.timelineCamera,{noPendingMatte:!0,objectMattes:a,W:b.width,H:b.height}):null;let k=u;for(const n of f)k=k.map(l=>l.id===t?j(l,n.id):l);m.setState({clips:k}),c&&(s(),m.setState({clips:c.clips,timelineTracks:c.tracks}));const v=c?c.clips.filter(n=>!o.clips.some(l=>l.id===n.id)).length:0,i=[...h,...c?.errors??[]];d.done(i.length?p("Đã tách {0} vật thể của “{1}”; chưa tách được: {2}",[v,r.label,i.join(" · ")]):p("Đã tách {0} vật thể của “{1}”, mỗi vật thể một layer riêng.",[v,r.label]),i.length?"error":"ok")}export{E as clipDetail,ut as matteRunning,$ as progressToast,ft as resumePendingMattes,F as segmentClipMatte,L as segmentClipObject};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-
|
|
2
|
-
import{_ as K}from"./titleFrameBudget-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-DGLbouqt.js","assets/titleFrameBudget-CLZWaFHO.js","assets/store-DW4E9xnW.js","assets/api-CJ8PdbfZ.js","assets/main-VVYiW8XD.js","assets/remote-C7J0Tqhb.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js","assets/spark.module-DzziUgOj.js","assets/userFonts-CwlKh9NR.js","assets/lottieLayer-DzbA3bHV.js","assets/timeline3d-DOw-CpZI.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/exportEncode-QYsT9JBO.js","assets/captionLayout-DvDPTwO9.js","assets/timelineText-BH09jfSM.js","assets/titleArt-Drsrtfiv.js","assets/rotoMatte-C-2o3vv0.js","assets/distortGL-QalhICvi.js","assets/motionBlur-uAm030t9.js","assets/main-Ca_CVxMz.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as K}from"./titleFrameBudget-CLZWaFHO.js";import{ak as ht,al as nt,am as ut,an as yt,ao as xt,ap as gt,aq as Mt,ar as _t,as as bt,a6 as Pt,at as Et}from"./main-VVYiW8XD.js";import"./remote-C7J0Tqhb.js";import"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";import"./spark.module-DzziUgOj.js";import"./userFonts-CwlKh9NR.js";import"./lottieLayer-DzbA3bHV.js";import"./timeline3d-DOw-CpZI.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-QYsT9JBO.js";import"./captionLayout-DvDPTwO9.js";import"./timelineText-BH09jfSM.js";import"./titleArt-Drsrtfiv.js";import"./rotoMatte-C-2o3vv0.js";import"./distortGL-QalhICvi.js";import"./motionBlur-uAm030t9.js";const wt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${Pt}/wasm`,Ot=[0,11,12,13,14,23,24,25,26],rt=512,B=512;async function Rt(){if(typeof window<"u"&&window.__personPoseStub)return{detect:window.__personPoseStub,close:()=>{}};const[{FilesetResolver:b,PoseLandmarker:P},{POSE_MODEL_URL:n}]=await Promise.all([K(()=>import("./vision_bundle-9zIsgJJP.js"),[]),K(()=>import("./poseTracker-DGLbouqt.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]))]),r=await b.forVisionTasks(wt),R=await P.createFromOptions(r,{baseOptions:{modelAssetPath:n,delegate:"CPU"},runningMode:"VIDEO",numPoses:4,minPoseDetectionConfidence:.4,minPosePresenceConfidence:.4,minTrackingConfidence:.4});let w=0;return{detect:(p,h)=>(w=Math.max(w+1,Math.round(h)),(R.detectForVideo(p,w).landmarks??[]).map(M=>M.map(u=>[u.x,u.y,u.visibility??1]))),close:()=>R.close()}}async function Kt(b,P,n,r){const[{detect:R,close:w},{objectProbability:p}]=await Promise.all([Rt(),K(()=>import("./main-VVYiW8XD.js").then(S=>S.aL),__vite__mapDeps([4,1,5,3,6,7,2,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24]))]),h=Object.assign(document.createElement("canvas"),{width:rt,height:Math.max(2,Math.round(rt*P/b))}),A=h.getContext("2d",{willReadFrequently:!0}),M=Object.assign(document.createElement("canvas"),{width:B,height:B}),u=M.getContext("2d",{willReadFrequently:!0}),at=Object.assign(document.createElement("canvas"),{width:n,height:r}),Q=at.getContext("2d",{willReadFrequently:!0}),G=n*r,v={frames:0,ai:0,rejected:0,tPose:0,tPrep:0,tRead:0,tMap:0,tClean:0};return{stats:v,close:()=>{window.__cutoutDebug&&console.log("# ai stats",JSON.stringify(v)),w()},async frame(S,L,st){v.frames++;let Z=performance.now();const C=t=>{const s=performance.now();v[t]+=s-Z,Z=s};A.drawImage(S,0,0,h.width,h.height);const tt=R(h,st).filter(t=>Array.isArray(t)&&t.length>=33);C("tPose");const{label:T,regions:it}=ht(L,n,r,128),V=it.filter(t=>t.area>=.002*G).sort((t,s)=>s.area-t.area);if(!V.length)return null;const J=nt(L,n,r,3,!0),$=t=>[Math.max(0,Math.min(n-1,Math.floor(t[0]*n))),Math.max(0,Math.min(r-1,Math.floor(t[1]*r)))],j=t=>t[2]>.6&&t[0]>=0&&t[0]<1&&t[1]>=0&&t[1]<1,ct=t=>{const s=new Map;for(const d of t)if(j(d)){const[l,O]=$(d),i=T[O*n+l]||(J[O*n+l]>=128?At(T,n,r,l,O,3):0);i&&s.set(i,(s.get(i)??0)+1)}let f=0,y=1;for(const[d,l]of s)l>y&&(y=l,f=d);return f},N=new Map;for(const t of tt){const s=ct(t);s&&N.set(s,[...N.get(s)??[],t])}const I=(tt.length?V.filter(t=>N.has(t.id)):V.filter(t=>t.area>=.25*V[0].area)).slice(0,4);if(!I.length)return null;const U=new Float32Array(G),et=new Uint8Array(G),lt=(t,s)=>{for(let f=-2;f<=2;f++)for(let y=-2;y<=2;y++){const d=t+y,l=s+f;d>=0&&l>=0&&d<n&&l<r&&(et[l*n+d]=1)}};C("tPrep");for(const t of I){const s=N.get(t.id)??[],f=[];for(const e of s){for(const o of Ot)if(j(e[o])){const[c,m]=$(e[o]);J[m*n+c]>=128&&f.push([e[o][0]*n,e[o][1]*r])}if(j(e[11])&&j(e[12])){const o=(e[11][0]+e[12][0])/2,c=(e[11][1]+e[12][1])/2,[m,x]=$([o,c]);J[x*n+m]>=128&&f.push([o*n,c*r])}}{const e=t.x1-t.x0+3,o=t.y1-t.y0+3,c=t.x0-1,m=t.y0-1,x=g=>{const F=g%e+c,H=(g/e|0)+m;return F>=0&&H>=0&&F<n&&H<r&&T[H*n+F]===t.id},Y=new Int32Array(e*o);for(let g=0;g<Y.length;g++)Y[g]=x(g)?1:0;for(const g of ut(yt(F=>Y[F]===1,e,o),Y,1,e,o,6))f.push([g[0]+c+.5,g[1]+m+.5])}if(!f.length)continue;let y=t.x0,d=t.y0,l=t.x1+1,O=t.y1+1;for(const e of s)for(const o of e)j(o)&&(y=Math.min(y,o[0]*n),d=Math.min(d,o[1]*r),l=Math.max(l,o[0]*n),O=Math.max(O,o[1]*r));const i=b/n,a=Et(y*i,d*i,l*i,O*i,b,P);C("tPrep"),u.drawImage(S,a.sx,a.sy,a.sw,a.sh,0,0,B,B);const E=await p(M,f.map(([e,o])=>({x:(e*i-a.sx)/a.sw,y:(o*i-a.sy)/a.sh})).filter(e=>e.x>0&&e.x<1&&e.y>0&&e.y<1).slice(0,24));C("tRead");const k=Math.max(4,Math.round(.15*Math.max(t.x1-t.x0,t.y1-t.y0))),q=Math.max(0,t.x0-k,Math.floor(a.sx/i)),W=Math.max(0,t.y0-k,Math.floor(a.sy/i)),mt=Math.min(n-1,t.x1+k,Math.ceil((a.sx+a.sw)/i)),dt=Math.min(r-1,t.y1+k,Math.ceil((a.sy+a.sh)/i)),_=mt-q+1,D=dt-W+1,X=new Uint8Array(_*D);for(let e=0;e<D;e++)for(let o=0;o<_;o++)T[(e+W)*n+o+q]===t.id&&(X[e*_+o]=255);const pt=nt(X,_,D,k,!0),z=new Float32Array(_*D);for(let e=0;e<D;e++){const o=((e+W+.5)*i-a.sy)/a.sh*E.height-.5;if(!(o<-.5||o>E.height-.5))for(let c=0;c<_;c++){const m=e*_+c;if(!pt[m])continue;const x=((c+q+.5)*i-a.sx)/a.sw*E.width-.5;x<-.5||x>E.width-.5||(z[m]=xt(E.data,E.width,E.height,x,o))}}const ot=gt(E.data,.8)||Mt(z,X,.5,128).inB<.5;ot?v.rejected++:v.ai++;for(let e=0;e<D;e++)for(let o=0;o<_;o++){const c=e*_+o,m=(e+W)*n+o+q,x=ot?X[c]?L[m]/255:0:z[c];x>U[m]&&(U[m]=x)}for(const[e,o]of f)lt(Math.floor(e),Math.floor(o));C("tMap")}_t(U,L,n,r,Math.max(2,Math.round(.012*Math.max(I[0].x1-I[0].x0,I[0].y1-I[0].y0)))),Q.drawImage(S,0,0,n,r);const ft=bt(U,Q.getImageData(0,0,n,r).data,n,r,{seeds:et});return C("tClean"),ft}}}function At(b,P,n,r,R,w){for(let p=1;p<=w;p++)for(let h=-p;h<=p;h++)for(let A=-p;A<=p;A++){const M=r+A,u=R+h;if(M>=0&&u>=0&&M<P&&u<n&&b[u*P+M])return b[u*P+M]}return 0}export{Kt as personAiReader};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ek as T,g$ as R,je as q,gS as F,dG as O,jf as W,eV as C}from"./remote-
|
|
1
|
+
import{ek as T,g$ as R,je as q,gS as F,dG as O,jf as W,eV as C}from"./remote-C7J0Tqhb.js";import{nx as j,mV as k,mW as _,ny as D,nz as B,nA as H,nB as U,jg as V}from"./titleFrameBudget-CLZWaFHO.js";import{plateMatte as $,matteAt as z}from"./plateMatte-J4qlNHnY.js";import{t as I}from"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";import"./rotoMatte-C-2o3vv0.js";const G=15,L=240,X=480;async function Y(i,n,e,o,s,M){const a=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});a.src=i;try{await new Promise((h,w)=>{a.onloadeddata=()=>h(),a.onerror=()=>w(new Error(I("Không đọc được video nền (CORS / định dạng)")))});const f=a.videoWidth||1280,p=a.videoHeight||720,r=Math.min(X,f),m=Math.max(2,Math.round(r*p/f)),c=Object.assign(document.createElement("canvas"),{width:r,height:m}),x=c.getContext("2d",{willReadFrequently:!0}),g=Math.max(2,Math.round(e*o)+1),v=[],u=[];for(let h=0;h<g;h++){if(s?.aborted)throw new DOMException("Đã huỷ","AbortError");const w=Math.min(e,h/o),S=Math.max(0,Math.min(a.duration-1/60,n+w));Math.abs(a.currentTime-S)>1e-4&&await new Promise((d,b)=>{const E=window.setTimeout(()=>b(new Error(I("Seek video quá lâu"))),8e3);a.onseeked=()=>{window.clearTimeout(E),d()},a.currentTime=S}),x.drawImage(a,0,0,r,m),v.push(U(x.getImageData(0,0,r,m).data,r,m)),u.push(w),M?.(h+1,g)}return{frames:v,times:u,W:r,H:m}}finally{a.removeAttribute("src"),a.load()}}function J(i){const n=O(i,0),e=W(n);return{position:[...n.position],q:e.quaternion.toArray(),distance:Math.max(.5,Math.hypot(...n.target.map((s,M)=>s-n.position[M]))),lens:n.lens}}async function lt(i,n){const e=i.plate,o=i.shots.find(t=>t.id===i.activeShot);if(!e||!o)throw new Error("no-plate");const s=C.plateUrl?await C.plateUrl(e).catch(()=>e.url):e.url,M=n.fps??G,a=Math.min(o.duration,e.duration),{frames:f,times:p,W:r}=await Y(s,e.inPoint,a,M,n.signal,n.progress),m=R(o.aspect),c=J(o),x=V(c.lens,r,m),g=await $(i,s,{signal:n.signal}),v=g?t=>{const l=z(g,e.inPoint+p[t]);return l.box?(y,A)=>l.at(y,A)>.05||l.at(y+.02,A)>.05||l.at(y-.02,A)>.05:null}:null,u=k(f,x,{skip:v}),h=u.filter(t=>t.lost).length;if(h>u.length/2)throw new Error("camera-not-found");const w=_(f,x,{skip:v}),S=Math.ceil(u.length/L);let d,b="turn",E=null,K=0;if(w?.mode==="free"){const t=D(w,c);d=B(t.cams,p,o.duration,{distance:c.distance,lens:c.lens,every:S,newId:n.newId}),b="travel",E=t.by;for(let l=1;l<t.cams.length;l++)K+=Math.hypot(...t.cams[l].position.map((y,A)=>y-t.cams[l-1].position[A]))}else d=H(u,p,o.duration,c,{W:r,aspect:m,every:S,newId:n.newId});const P=d.map(t=>Math.atan2(t.target[0]-t.position[0],-(t.target[2]-t.position[2]))*180/Math.PI);return{stage:{...i,shots:i.shots.map(t=>{if(t.id!==o.id)return t;const{handheld:l,...y}=t;return{...y,...F(d)}})},keys:d.length,frames:u.length,lost:h,mode:b,scale:E,travel:Math.round(K*100)/100,matte:g?g.made?"made":"timeline":"none",pan:Math.round((Math.max(...P)-Math.min(...P))*10)/10,lens:[Math.min(...d.map(t=>t.lens)),Math.max(...d.map(t=>t.lens))]}}function ht(i,n={}){const e=i.shots.find(r=>r.id===i.activeShot),o=T(e),s=R(e.aspect),M=s>=1?1920:Math.round(1920*s/2)*2,a=s>=1?Math.round(1920/s/2)*2:1920,f=Math.max(2,Math.round(e.duration*o)+1),p=[];for(let r=0;r<f;r++){const m=Math.min(e.duration,r/o),c=q(e,e.duration?m/e.duration:0);p.push({t:m,position:c.position.toArray(),q:c.quaternion.toArray(),lens:c.getFocalLength()})}return j(p,{fps:o,width:M,height:a,name:`${e.name} · Clipoox`,plate:n.plate??"",maxKeys:n.maxKeys})}export{G as TRACK_FPS,L as TRACK_MAX_KEYS,ht as shotBlenderScript,lt as trackPlateCamera};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/plateFollow-
|
|
2
|
-
import{_ as st}from"./titleFrameBudget-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/plateFollow-C9S-l7RH.js","assets/titleFrameBudget-CLZWaFHO.js","assets/remote-C7J0Tqhb.js","assets/api-CJ8PdbfZ.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/store-DW4E9xnW.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as st}from"./titleFrameBudget-CLZWaFHO.js";import{n as rt,jf as at}from"./remote-C7J0Tqhb.js";import{mainBody as it,worldOf as ct,smooth as ht,depthOf as ut,lowestFoot as ft,rayOf as nt,FOOT_HEIGHT as mt,median as W}from"./plateFollow-C9S-l7RH.js";import"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const B=Math.PI/180,et=(t,n)=>[t[1]*n[2]-t[2]*n[1],t[2]*n[0]-t[0]*n[2],t[0]*n[1]-t[1]*n[0]],pt=(t,n)=>t[0]*n[0]+t[1]*n[1]+t[2]*n[2],Q=t=>{const n=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/n,t[1]/n,t[2]/n]},z=Object.freeze({lean:25,lines:60,minShare:.06,agree:.7,maxTilt:40,minLines:6,minSupport:1});function dt(t,n,s,{lean:r=z.lean,minShare:M=z.minShare,max:i=z.lines}={}){const y=n*s,E=new Float32Array(y),A=new Float32Array(y),f=new Float32Array(y);let x=0,v=0;for(let c=1;c<s-1;c++)for(let h=1;h<n-1;h++){const a=c*n+h,d=t[a-n-1],H=t[a-n],_=t[a-n+1],b=t[a-1],w=t[a+1],q=t[a+n-1],R=t[a+n],S=t[a+n+1],V=_+2*w+S-d-2*b-q,I=q+2*R+S-d-2*H-_,G=Math.hypot(V,I);E[a]=V,A[a]=I,f[a]=G,x+=G,v+=G*G}const p=x/y,T=Math.max(48,p+1.2*Math.sqrt(Math.max(0,v/y-p*p))),P=.5,g=Math.round(2*r/P)+1,u=Math.ceil(Math.hypot(n,s)/2)+2,F=new Uint16Array(g*(2*u+1)),o=new Float32Array(g),l=new Float32Array(g);for(let c=0;c<g;c++){const h=(-r+c*P)*B;o[c]=Math.cos(h),l[c]=Math.sin(h)}const e=[];for(let c=1;c<s-1;c++)for(let h=1;h<n-1;h++){const a=c*n+h;if(f[a]<T||f[a]<f[a-1]||f[a]<=f[a+1])continue;let d=Math.atan2(A[a],E[a])/B;if(d>90?d-=180:d<-90&&(d+=180),Math.abs(d)>r)continue;const H=f[a-1]-2*f[a]+f[a+1],_=H<-1e-6?Math.max(-.5,Math.min(.5,.5*(f[a-1]-f[a+1])/H)):0;e.push(h+_-n/2,c-s/2,d);const b=Math.max(0,Math.round((d-3+r)/P)),w=Math.min(g-1,Math.round((d+3+r)/P));for(let q=b;q<=w;q++)F[q*(2*u+1)+Math.round(e[e.length-3]*o[q]+e[e.length-2]*l[q])+u]++}const O=[],C=Math.max(12,M*s*.6);for(let c=0;c<g;c++)for(let h=0;h<=2*u;h++){const a=F[c*(2*u+1)+h];a>=C&&O.push([a,c,h])}O.sort((c,h)=>h[0]-c[0]);const L=e.length/3,j=new Uint8Array(L),N=[],D=c=>{let h=0,a=0,d=0,H=0;for(const q of c){const R=e[q*3],S=e[q*3+1];h+=S,a+=R,d+=S*S,H+=R*S}const _=c.length,b=_*d-h*h;if(_<2||Math.abs(b)<1e-6)return null;const w=(_*H-a*h)/b;return{p:(a-w*h)/_,q:w}};let K=0;for(const[,c,h]of O){if(N.length>=i||K++>i*6)break;const a=o[c],d=l[c],H=h-u,_=-r+c*P;let b=[];for(let m=0;m<L;m++)!j[m]&&Math.abs(e[m*3]*a+e[m*3+1]*d-H)<=1.6&&Math.abs(e[m*3+2]-_)<=7&&b.push(m);if(b.length<C)continue;let w=D(b);if(!w)continue;const q=(m,J)=>{const lt=Math.hypot(1,m.q),tt=[];for(let U=0;U<L;U++)!j[U]&&Math.abs(e[U*3]-m.p-m.q*e[U*3+1])/lt<=J&&Math.abs(e[U*3+2]-_)<=10&&tt.push(U);return tt};b=q(w,1.2),w=D(b)??w,b.sort((m,J)=>e[m*3+1]-e[J*3+1]);let R=0,S=0,V=0;for(let m=1;m<=b.length;m++)(m===b.length||e[b[m]*3+1]-e[b[m-1]*3+1]>6)&&(e[b[m-1]*3+1]-e[b[V]*3+1]>e[b[S]*3+1]-e[b[R]*3+1]&&(R=V,S=m-1),V=m);const I=b.slice(R,S+1);if(I.length<C)continue;w=D(I)??w;const G=Math.hypot(1,w.q),X=e[I[0]*3+1],Y=e[I[I.length-1]*3+1],Z=(Y-X)*G;let $=0;for(const m of I)$+=((e[m*3]-w.p-w.q*e[m*3+1])/G)**2;if(!(Z<M*s||Math.sqrt($/I.length)>.8||Math.abs(Math.atan(-w.q)/B-_)>2.5)){for(const m of q(w,2))e[m*3+1]>=X-2&&e[m*3+1]<=Y+2&&(j[m]=1);N.push({x0:w.p+w.q*X+n/2,y0:X+s/2,x1:w.p+w.q*Y+n/2,y1:Y+s/2,length:Z})}}return N.sort((c,h)=>h.length-c.length).slice(0,i)}function Mt(t,n,s,r,{agree:M=z.agree,maxTilt:i=z.maxTilt}={}){const y=t.map(o=>({n:Q(et([o.x0-n/2,o.y0-s/2,r],[o.x1-n/2,o.y1-s/2,r])),length:o.length}));if(y.length<3)return null;const E=Math.sin(M*B),A=o=>{let l=0;const e=[];for(const O of y)Math.abs(pt(O.n,o))<E&&(l+=O.length,e.push(O));return{score:l,inl:e}},f=o=>o[1]>0?[-o[0],-o[1],-o[2]]:o;let x=null;const v=[[0,-1,0]];for(let o=0;o<y.length;o++)for(let l=o+1;l<y.length;l++){const e=et(y[o].n,y[l].n);Math.hypot(...e)>1e-4&&v.push(f(Q(e)))}for(const o of v){if(Math.acos(Math.min(1,-o[1]))>i*B)continue;const l=A(o);(!x||l.score>x.score)&&(x={...l,U:o})}if(!x||x.inl.length<3)return null;const p=[0,0,0,0,0,0,0,0,0];for(const o of x.inl)for(let l=0;l<3;l++)for(let e=0;e<3;e++)p[l*3+e]+=o.length*o.n[l]*o.n[e];const T=p[0]+p[4]+p[8];p[0]+=T*1e-6,p[4]+=T*1e-6,p[8]+=T*1e-6;const g=(o=>{const[l,e,O,C,L,j,N,D,K]=o,c=L*K-j*D,h=-(C*K-j*N),a=C*D-L*N,d=l*c+e*h+O*a;return Math.abs(d)<1e-18?null:[c/d,-(e*K-O*D)/d,(e*j-O*L)/d,h/d,(l*K-O*N)/d,-(l*j-O*C)/d,a/d,-(l*D-e*N)/d,(l*L-e*C)/d]})(p);let u=x.U;if(g)for(let o=0;o<12;o++)u=f(Q([g[0]*u[0]+g[1]*u[1]+g[2]*u[2],g[3]*u[0]+g[4]*u[1]+g[5]*u[2],g[6]*u[0]+g[7]*u[1]+g[8]*u[2]]));Math.acos(Math.min(1,-u[1]))>i*B&&(u=x.U);const F=x.inl.reduce((o,l)=>o+l.length,0)/s;return{tilt:Math.asin(Math.max(-1,Math.min(1,u[2])))/B,roll:Math.atan2(u[0],-u[1])/B,lines:x.inl.length,support:F,up:u}}function gt(t,n,s,r){const M=dt(t,n,s),i=Mt(M,n,s,r/36*n);return i&&i.lines>=z.minLines&&i.support>=z.minSupport?{...i,found:M.length}:null}const ot=28,yt=1.5,k=t=>Math.round(t*1e3)/1e3,bt=(t,n)=>{const s=t.filter(Number.isFinite).sort((r,M)=>r-M);return s.length?s[Math.min(s.length-1,Math.floor(s.length*n))]:NaN},wt=(t,n,s,r)=>{const M=n*Math.PI/180;return at({position:[0,0,0],target:[0,Math.sin(M),-Math.cos(M)],lens:t,roll:s,aspect:r})};function xt(t,n="16:9"){const s=t.lens??ot,r=t.tilt??t.seen?.tilt??0,M=t.roll??(t.tilt==null?t.seen?.roll:null)??0,i={lens:t.lens!=null?"given":"assumed",tilt:t.tilt!=null?"given":t.seen?"lines":"level",height:t.height!=null?"given":"default",place:"default"},y=wt(s,r,M,n),E=it(t.frames.filter(p=>p.lm&&p.lm.length>=33),t.aspect).filter(p=>p.lm);let A=t.height??yt,f=[0,-4];if(E.length>=2){const p=E.map(l=>l.wl&&l.wl.length>=33?l.wl:ct(l.lm,t.aspect)),T=ht(E.map((l,e)=>ut(y,l.lm,p[e]))),P=E.map((l,e)=>{const O=ft(l.lm);return-nt(y,l.lm[O][0],l.lm[O][1]).y*T[e]+mt[O]}),g=bt(P,.7);t.height==null&&g>.15&&g<30&&(A=g,i.height="feet");const u=E.map((l,e)=>nt(y,(l.lm[23][0]+l.lm[24][0])/2,(l.lm[23][1]+l.lm[24][1])/2).multiplyScalar(T[e])),F=u.filter((l,e)=>Math.abs(P[e]-A)<.2*A),o=F.length>=2?F:u;f=[W(o.map(l=>l.x)),W(o.map(l=>l.z))],i.place="person"}const x=r*Math.PI/180,v=[k(-f[0]),k(A),k(-f[1])];return{lens:k(s),height:k(A),tilt:k(r),roll:k(M),distance:k(Math.hypot(f[0],f[1])),position:v,target:[k(v[0]),k(v[1]+Math.sin(x)*4),k(v[2]-Math.cos(x)*4)],by:i,lines:t.tilt==null?t.seen?.lines??0:0}}function At(t,n){const s={...t.plate,match:{lens:n.lens,height:n.height,tilt:n.tilt,roll:n.roll}};return{...t,plate:s,shots:t.shots.map(r=>r.id!==t.activeShot?r:{...r,position:n.position,target:n.target,lens:n.lens,roll:n.roll,endPosition:n.position,endTarget:n.target,endLens:n.lens,motion:"static",cameraKeys:[]})}}const vt=t=>{const n=t.shots.find(s=>s.id===t.activeShot);return!!t.plate&&!!n&&!n.cameraKeys?.length};function jt(t){const n=t.shots.find(M=>M.id===t.activeShot),s=rt().shots[0],r=(M,i)=>M.every((y,E)=>Math.abs(y-i[E])<1e-6);return!!n&&r(n.position,s.position)&&r(n.target,s.target)&&Math.abs(n.lens-s.lens)<1e-6&&!n.roll}async function Nt(t,n={},s={}){const r=t.plate,M=t.shots.find(v=>v.id===t.activeShot);if(!r||!M)throw new Error("no-plate");if(!vt(t))throw new Error("camera-keyed");const[i,y]=(M.aspect||"16:9").split(":").map(Number);let E=[],A=i/y||16/9,f=null;if(!(n.lens!=null&&n.height!=null&&n.tilt!=null)){const{readPlate:v}=await st(async()=>{const{readPlate:T}=await import("./plateFollow-C9S-l7RH.js");return{readPlate:T}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),p=await v(t,s);E=p.tracked.frames,A=i/y||p.tracked.aspect,n.tilt==null&&(f=await Et(p.url,r.inPoint,p.span,n.lens??ot,s.signal).catch(T=>{if(T.name==="AbortError")throw T;return null}))}const x=xt({frames:E,aspect:A,lens:n.lens??null,tilt:n.tilt??null,roll:n.roll??null,height:n.height??null,seen:f},M.aspect);return{stage:At(t,x),match:x,found:E.filter(v=>v.lm).length}}async function Et(t,n,s,r,M){const i=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});i.src=t;try{await new Promise((T,P)=>{i.onloadeddata=()=>T(),i.onerror=()=>P(new Error("plate-unreadable"))});const y=i.videoWidth||1280,E=i.videoHeight||720,A=Math.min(960,y),f=Math.max(2,Math.round(A*E/y)),x=Object.assign(document.createElement("canvas"),{width:A,height:f}),v=x.getContext("2d",{willReadFrequently:!0}),p=[];for(const T of[.1,.3,.5,.7,.9]){if(M?.aborted)throw new DOMException("Đã huỷ","AbortError");const P=Math.max(0,Math.min(i.duration-1/60,n+s*T));Math.abs(i.currentTime-P)>1e-4&&await new Promise((o,l)=>{const e=window.setTimeout(()=>l(new Error("plate-seek")),8e3);i.onseeked=()=>{window.clearTimeout(e),o()},i.currentTime=P}),v.drawImage(i,0,0,A,f);const g=v.getImageData(0,0,A,f).data,u=new Uint8Array(A*f);for(let o=0;o<u.length;o++)u[o]=g[o*4]*77+g[o*4+1]*150+g[o*4+2]*29>>8;const F=gt(u,A,f,r);F&&p.push({tilt:F.tilt,roll:F.roll,lines:F.lines})}return Tt(p)}finally{i.removeAttribute("src"),i.load()}}function Tt(t){if(t.length<2)return null;const n=W(t.map(r=>r.tilt)),s=W(t.map(r=>r.roll));return t.filter(r=>Math.abs(r.tilt-n)<=5).length<Math.max(2,t.length*.6)?null:{tilt:k(n),roll:k(s),lines:Math.round(W(t.map(r=>r.lines)))}}export{yt as MATCH_HEIGHT,ot as MATCH_LENS,At as applyCameraMatch,xt as matchCamera,Nt as matchPlateCamera,vt as matchable,Tt as tiltOfReads,Et as tiltOfStills,jt as untouchedCamera};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-
|
|
2
|
-
import{_ as U}from"./titleFrameBudget-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/poseTracker-DGLbouqt.js","assets/titleFrameBudget-CLZWaFHO.js","assets/store-DW4E9xnW.js","assets/api-CJ8PdbfZ.js","assets/main-VVYiW8XD.js","assets/remote-C7J0Tqhb.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js","assets/spark.module-DzziUgOj.js","assets/userFonts-CwlKh9NR.js","assets/lottieLayer-DzbA3bHV.js","assets/timeline3d-DOw-CpZI.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/exportEncode-QYsT9JBO.js","assets/captionLayout-DvDPTwO9.js","assets/timelineText-BH09jfSM.js","assets/titleArt-Drsrtfiv.js","assets/rotoMatte-C-2o3vv0.js","assets/distortGL-QalhICvi.js","assets/motionBlur-uAm030t9.js","assets/main-Ca_CVxMz.css","assets/plateMatte-J4qlNHnY.js","assets/plateCameraMatch-ByB9nVQT.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as U}from"./titleFrameBudget-CLZWaFHO.js";import{jd as Z,hD as $,je as tt,hE as nt,eV as G}from"./remote-C7J0Tqhb.js";import{F as et}from"./rigTrack-urT3nDK0.js";import{Quaternion as ot,Vector3 as v}from"./three.module-Bx43vjkH.js";import"./api-CJ8PdbfZ.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";const n={eyeL:2,eyeR:5,earL:7,earR:8,shL:11,shR:12,elL:13,elR:14,wrL:15,wrR:16,hipL:23,hipR:24,knL:25,knR:26,anL:27,anR:28},at=[[n.shL,n.hipL],[n.shR,n.hipR],[n.hipL,n.knL],[n.hipR,n.knR],[n.shL,n.shR]],rt=15,O=(e,r)=>e.map((t,i)=>(t+r[i])/2),j=e=>{const r=e.filter(Number.isFinite).sort((t,i)=>t-i);return r.length?r[r.length>>1]:NaN};function J(e,r,t){return new v(r*2-1,1-t*2,.5).unproject(e).sub(e.position).normalize()}const C=(e,r)=>new v(e[0],-e[1],-e[2]).applyQuaternion(r);function it(e,r){const t=O(e[n.hipL],e[n.hipR]),i=O(e[n.shL],e[n.shR]),c=.5/Math.max(.001,Math.hypot((i[0]-t[0])*r,i[1]-t[1]));return e.map(f=>[(f[0]-t[0])*r*c,(f[1]-t[1])*c,f[2]*r*c])}function st(e,r,t){return j(at.map(([i,c])=>{if(Math.min(r[i][3]??1,r[c][3]??1)<.5)return NaN;const f=Math.hypot(t[i][0]-t[c][0],t[i][1]-t[c][1]);if(f<.12)return NaN;const w=J(e,r[i][0],r[i][1]).angleTo(J(e,r[c][0],r[c][1]));return w>1e-4?f/Math.tan(w):NaN}))}const lt=e=>{const r=e.filter(Number.isFinite);return r.length?r.reduce((t,i)=>t+i,0)/r.length:NaN};function W(e){const r=e.map((i,c)=>j(e.slice(Math.max(0,c-2),c+3))),t=r.map((i,c)=>lt(r.slice(Math.max(0,c-1),c+2)));return t.map((i,c)=>{if(Number.isFinite(i))return i;for(let f=1;f<t.length;f++)for(const w of[c-f,c+f])if(Number.isFinite(t[w]))return t[w];return 4})}const ct=[[1,4],[2,5],[3,6],[7,8],[9,10],[11,12],[13,14],[15,16],[17,18],[19,20],[21,22],[23,24],[25,26],[27,28],[29,30],[31,32]],q=e=>{const r=[...e];for(const[t,i]of ct)r[t]=e[i],r[i]=e[t];return r},H=e=>(e%360+540)%360-180;function Q(e){const r=e[n.hipL][0]-e[n.hipR][0]+e[n.shL][0]-e[n.shR][0],t=e[n.hipL][2]-e[n.hipR][2]+e[n.shL][2]-e[n.shR][2];return{yaw:Math.atan2(t,r)*180/Math.PI,side:Math.abs(r)<.35*Math.hypot(r,t)}}function ht(e){const r=e.map(t=>{const{yaw:i,side:c}=Q(t.w),f=t.w[0][2]-(t.w[n.earL][2]+t.w[n.earR][2])/2,w=f<-.03?!0:f>.03?!1:null;return!c&&w!==null&&Math.abs(i)<90!==w?{lm:q(t.lm),w:q(t.w)}:t});for(let t=1;t<r.length;t++){const i=Q(r[t-1].w).yaw,c=Q(r[t].w).yaw;Math.abs(H(c-i))>110&&Math.abs(H(c+180-i))<Math.abs(H(c-i))&&(r[t]={lm:q(r[t].lm),w:q(r[t].w)})}return r}function mt(e,r=16/9){const t=[n.shL,n.shR,n.elL,n.elR,n.wrL,n.wrR,n.hipL,n.hipR,n.knL,n.knR,n.anL,n.anR],i=e.map((a,s)=>{if(!a.lm||a.lm.length<33)return null;const x=a.lm,y=O(x[n.hipL],x[n.hipR]),m=O(x[n.shL],x[n.shR]);return{i:s,t:a.t,x:y[0]*r,y:y[1],s:Math.max(.01,Math.hypot((m[0]-y[0])*r,m[1]-y[1])),vis:t.reduce((h,g)=>h+(x[g][3]??1),0)/t.length}}).filter(a=>!!a);if(i.length<4)return e;const c=i.map((a,s)=>s),f=a=>c[a]===a?a:c[a]=f(c[a]);for(let a=0;a<i.length;a++)for(let s=a+1;s<i.length;s++)Math.hypot(i[a].x-i[s].x,i[a].y-i[s].y)<=.7*Math.min(i[a].s,i[s].s)&&(c[f(a)]=f(s));const w=new Map;i.forEach((a,s)=>{const x=f(s);w.set(x,[...w.get(x)??[],a])});const M=[...w.values()].filter(a=>a.length>=3).map(a=>({g:a,t0:a[0].t,t1:a[a.length-1].t,score:a.length*j(a.map(s=>s.vis))**2}));if(!M.length||M.length===1&&M[0].g.length===i.length)return e;M.sort((a,s)=>s.score-a.score);const k=[M[0]],S=(a,s)=>Math.min(a.t1,s.t1)-Math.max(a.t0,s.t0)>.3*Math.max(.2,Math.min(a.t1-a.t0,s.t1-s.t0));for(let a=!0;a;){a=!1;for(const s of M){if(k.includes(s)||k.some(h=>S(h,s)))continue;const x=k.flatMap(h=>h.g);let y=1/0,m=!1;for(const h of[s.g[0],s.g[s.g.length-1]])for(const g of x){const R=Math.abs(g.t-h.t);R<y&&(y=R,m=Math.hypot(g.x-h.x,g.y-h.y)<=(.6+8*R)*Math.min(g.s,h.s))}m&&(k.push(s),a=!0)}}const E=new Set(k.flatMap(a=>a.g.map(s=>s.i)));return e.map((a,s)=>a.lm&&!E.has(s)?{...a,lm:null}:a)}const K=[27,28,29,30,31,32],pt={27:.09,28:.09,29:.035,30:.035,31:.03,32:.03},ut={27:"ankleR",28:"ankleL",29:"heelR",30:"heelL",31:"toeR",32:"toeL"},ft=e=>K.reduce((r,t)=>(e[t][3]??1)>=.3&&e[t][1]>e[r][1]?t:r,K[0]);function dt(e,r,t,i=16/9,c={}){const f=mt(e.filter(o=>o.lm&&o.lm.length>=33),i).filter(o=>o.lm),w=ht(f.map(o=>({lm:o.lm,w:o.wl&&o.wl.length>=33?o.wl:it(o.lm,i)}))),M=f.map((o,l)=>({...o,lm:w[l].lm})),k=w.map(o=>o.w),S=M.map(o=>r(o.t)),E=W(M.map((o,l)=>st(S[l],o.lm,k[l]))),a=(o,l,d)=>Math.hypot(o[l][0]-o[d][0],o[l][1]-o[d][1],o[l][2]-o[d][2]),s=j(k.map(o=>(a(o,n.hipL,n.knL)+a(o,n.knL,n.anL)+a(o,n.hipR,n.knR)+a(o,n.knR,n.anR))/2)),x=t/Math.max(.3,Number.isFinite(s)?s:.9),y=t/.93,m=M.map((o,l)=>{const d=k[l],u=S[l].getWorldQuaternion(new ot),b=O(d[n.hipL],d[n.hipR]),p=Y=>C(d[Y],u).multiplyScalar(x),N={hips:C(b,u).multiplyScalar(x),neck:C(O(d[n.shL],d[n.shR]),u).multiplyScalar(x),upL:p(n.shR),foreL:p(n.elR),handL:p(n.wrR),thighL:p(n.hipR),shinL:p(n.knR),footL:p(n.anR),upR:p(n.shL),foreR:p(n.elL),handR:p(n.wrL),thighR:p(n.hipL),shinR:p(n.knL),footR:p(n.anL)},{pose:F,yaw:A}=Z(N,{head:p(n.earL).add(p(n.earR)).multiplyScalar(.5),eyeA:p(n.eyeR),eyeB:p(n.eyeL)},{legTwist:!0}),z=et(F),_=O(z.hipL,z.hipR),T=Math.cos(A*Math.PI/180),I=Math.sin(A*Math.PI/180),B=new v((_[0]*T+_[2]*I)*y,_[1]*y,(-_[0]*I+_[2]*T)*y),X=J(S[l],...O(o.lm[n.hipL],o.lm[n.hipR]));return{pose:F,yaw:A,off:B,ray:X,cam:S[l],q:u,w:d,J:z}}),h=M.length,g=[...E],R=Array(h).fill(!1);if(c.floor&&h){const o=m.map((u,b)=>{const p=M[b].lm,N=ft(p),F=J(u.cam,p[N][0],p[N][1]);if(F.y>-.03)return NaN;const z=(Math.max(pt[N],u.J[ut[N]][1])*y-u.cam.position.y)/F.y;if(!(z>.3))return NaN;const _=O(u.w[n.hipL],u.w[n.hipR]),I=u.cam.position.clone().addScaledVector(F,z).add(C([_[0]-u.w[N][0],_[1]-u.w[N][1],_[2]-u.w[N][2]],u.q)).sub(u.cam.position).dot(u.ray);return I>.3?I:NaN}),l=o.map((u,b)=>u/E[b]),d=j(l.filter(u=>u>.6&&u<1.6));if(Number.isFinite(d)){const u=l.map(b=>Number.isFinite(b)&&Math.abs(b/d-1)<.12);if(u.filter(Boolean).length>=Math.max(3,h*.1)){const b=W(o.map((p,N)=>u[N]?p:NaN));for(let p=0;p<h;p++)R[p]=u[p],g[p]=u[p]?b[p]:E[p]*d}}}const V=(o,l)=>m[o].cam.position.clone().addScaledVector(m[o].ray,l).sub(m[o].off),L=m.map((o,l)=>V(l,g[l]));if(R.some(Boolean)){for(let o=0;o<h;o++)R[o]&&(L[o].y=0);for(let o=0;o<h;o++){if(R[o])continue;let l=o-1,d=o+1;for(;l>=0&&!R[l];)l--;for(;d<h&&!R[d];)d++;const u=l>=0?M[o].t-M[l].t:1/0,b=d<h?M[d].t-M[o].t:1/0;if(Math.min(u,b)>8)continue;const p=l>=0&&d<h?u/(u+b):l>=0?0:1,N=L[l>=0?l:d],F=L[d<h?d:l],A=N.x+(F.x-N.x)*p+m[o].off.x,z=N.z+(F.z-N.z)*p+m[o].off.z,{ray:_,cam:T}=m[o],I=_.x*_.x+_.z*_.z;if(I<.04)continue;const B=((A-T.position.x)*_.x+(z-T.position.z)*_.z)/I;B>.3&&(L[o]=V(o,B),g[o]=B,L[o].y<.02&&(L[o].y=0,R[o]=!0))}}const P=o=>Math.round(o*1e3)/1e3;return M.map((o,l)=>{const d=m[l].cam.position.clone().addScaledVector(m[l].ray,g[l]);return{time:o.t,pose:m[l].pose,position:[P(L[l].x),P(L[l].y),P(L[l].z)],yaw:m[l].yaw,hips:[P(d.x),P(d.y),P(d.z)],...c.floor&&R.some(Boolean)?R[l]?{grounded:!0}:{air:!0}:{}}})}let D=null;async function yt(e,r={}){const t=e.plate,i=e.shots.find(m=>m.id===e.activeShot);if(!t||!i)throw new Error("no-plate");const c=G.plateUrl?await G.plateUrl(t).catch(()=>t.url):t.url,f=r.fps??rt,w=Math.min(i.duration,t.duration),M=[t.gcsUri||t.url,t.inPoint,w,f].join("|");if(D?.key===M)return D;const[{trackPose:k},{matteAt:S,plateMatte:E}]=await Promise.all([U(()=>import("./poseTracker-DGLbouqt.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24])),U(()=>import("./plateMatte-J4qlNHnY.js"),__vite__mapDeps([25,1,21,3,2]))]),a=await E(e,c,{signal:r.signal,coarse:!0});let s;if(a){const m=g=>{const R=S(a,g).box;return R?{box:R}:null},h=Array.from({length:9},(g,R)=>S(a,t.inPoint+w*R/8).box?.h).filter(g=>g!=null).sort((g,R)=>g-R);s=Object.assign(m,{crop:h.length>3&&h[h.length>>1]<.4})}const x=m=>k({clip:{inPoint:t.inPoint,playbackRate:1},url:c,from:0,duration:w,fps:f,signal:r.signal,onProgress:r.progress,focus:m});let y=await x(s);if(s&&y.frames.filter(m=>m.lm).length<y.frames.length*.85){const m=await x();m.frames.filter(h=>h.lm).length>y.frames.filter(h=>h.lm).length&&(y=m,s=void 0)}return D={key:M,url:c,span:w,tracked:y,matte:a&&s?a.made?"made":"timeline":"none"},D}async function St(e,r,t){const i=e.plate,c=e.shots.find(L=>L.id===e.activeShot),f=e.items.find(L=>L.id===r);if(!i||!c)throw new Error("no-plate");if(!f||f.kind!=="person")throw new Error("no-person");const{url:w,span:M,tracked:k,matte:S}=await yt(e,t),E=k.frames.filter(L=>L.lm).length;if(E<2)throw new Error("no-person-in-plate");const[a,s]=(c.aspect||"16:9").split(":").map(Number),x=a/s||k.aspect;let y=e,m;const h=await U(()=>import("./plateCameraMatch-ByB9nVQT.js"),__vite__mapDeps([26,1,5,3,6,7,2,8,9,10,11]));if(t.match!==!1&&h.matchable(e)&&(t.match===!0||t.lens!=null||!i.match&&h.untouchedCamera(e))){const L=typeof document>"u"?null:await h.tiltOfStills(w,i.inPoint,M,t.lens??i.match?.lens??h.MATCH_LENS,t.signal).catch(P=>{if(P.name==="AbortError")throw P;return null});m=h.matchCamera({frames:k.frames,aspect:x,lens:t.lens??null,seen:L},c.aspect),y=h.applyCameraMatch(e,m)}const g=y.shots.find(L=>L.id===y.activeShot),R=dt(k.frames,L=>tt(g,Math.min(1,L/g.duration)),.93*$(f)*(f.scale[1]||1),x,{floor:!!y.plate?.match}),V=nt(y,r,R,0,t.newId,{replace:"all"});return{stage:V.stage,keys:V.keys,found:E,frames:k.frames.length,hips:R.map(L=>({time:L.time/g.duration,at:L.hips})),matte:S,...m?{camera:m}:{}}}export{K as FEET,rt as FOLLOW_FPS,pt as FOOT_HEIGHT,n as LM,dt as bakeFollow,st as depthOf,ht as fixSides,St as followPlate,ft as lowestFoot,mt as mainBody,j as median,J as rayOf,yt as readPlate,W as smooth,it as worldOf};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/main-
|
|
2
|
-
import{b_ as c,a7 as m,_ as h}from"./titleFrameBudget-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/main-VVYiW8XD.js","assets/titleFrameBudget-CLZWaFHO.js","assets/remote-C7J0Tqhb.js","assets/api-CJ8PdbfZ.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/store-DW4E9xnW.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js","assets/spark.module-DzziUgOj.js","assets/userFonts-CwlKh9NR.js","assets/lottieLayer-DzbA3bHV.js","assets/timeline3d-DOw-CpZI.js","assets/RoomEnvironment-Dmv_G5ka.js","assets/exportEncode-QYsT9JBO.js","assets/captionLayout-DvDPTwO9.js","assets/timelineText-BH09jfSM.js","assets/titleArt-Drsrtfiv.js","assets/rotoMatte-C-2o3vv0.js","assets/distortGL-QalhICvi.js","assets/motionBlur-uAm030t9.js","assets/main-Ca_CVxMz.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{b_ as c,a7 as m,_ as h}from"./titleFrameBudget-CLZWaFHO.js";import"./rotoMatte-C-2o3vv0.js";import{u as w}from"./store-DW4E9xnW.js";import"./api-CJ8PdbfZ.js";function M(r){const l=r.plate,n=l?.timelineClipId;if(!l||!n)return null;const a=w.getState().clips,t=a.find(e=>e.id===n),o=e=>e?.person&&e.person.src!=="object"?e.person:null;return o(t)??o(a.find(e=>e.id!==n&&e.kind==="video"&&!!e.person&&(e.id===`${n}-person`||!!t&&e.url===t.url&&e.start===t.start)))}async function b(r,l,n={}){const a=M(r);try{if(a)return{p:a,frames:await m(a),made:!1};const t=r.plate,o=r.shots.find(u=>u.id===r.activeShot),{segmentPerson:e}=await h(async()=>{const{segmentPerson:u}=await import("./main-VVYiW8XD.js").then(d=>d.aK);return{segmentPerson:u}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])),f={id:"plate",nodeId:"",kind:"video",url:l,label:t.label,track:0,start:0,inPoint:t.inPoint,duration:Math.min(o.duration,t.duration),volume:0},p=await e({clip:f,url:l,signal:n.signal,...n.coarse?{fps:6}:{},quality:{store:!1,...n.coarse?{ai:!1}:{}}});return{p,frames:await m(p),made:!0}}catch(t){if(t.name==="AbortError")throw t;return null}}function v(r,l){const n=c(r.frames,r.p,l),{w:a,h:t}=r.p;let o=a,e=t,f=-1,p=-1,u=0;for(let i=0;i<t;i++)for(let s=0;s<a;s++)n[i*a+s]>127&&(u++,s<o&&(o=s),s>f&&(f=s),i<e&&(e=i),i>p&&(p=i));const d=f<0||u>a*t*.3?null:{x:o/a,y:e/t,w:(f-o+1)/a,h:(p-e+1)/t};return{a:n,w:a,h:t,box:d,at:(i,s)=>n[Math.min(t-1,Math.max(0,Math.floor(s*t)))*a+Math.min(a-1,Math.max(0,Math.floor(i*a)))]/255}}export{v as matteAt,b as plateMatte,M as plateMatteRef};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as r,E as c}from"./api-
|
|
1
|
+
import{h as r,E as c}from"./api-CJ8PdbfZ.js";async function t(o,e={}){const a=await c(),i=await fetch(o,{...e,headers:{"Content-Type":"application/json","Accept-Language":r(),...a?{"X-Firebase-Token":a}:{},...e.headers||{}}}),s=await i.json().catch(()=>({}));if(!i.ok){const n=new Error(s.error||`${i.status}`);throw n.status=i.status,n.code=s.code,n.args=s.args,n.data=s,n}return s}const h=o=>t("/api/ai-templates/run",{method:"POST",body:JSON.stringify({...o,dry_run:!0,locale:r()})}),p=(o,e)=>t("/api/ai-templates/run",{method:"POST",body:JSON.stringify({...o,max_credits:e,locale:r()})}).then(a=>a.doc),m=()=>t("/api/webhooks"),b=(o,e)=>t("/api/webhooks",{method:"POST",body:JSON.stringify({url:o,events:e})}).then(a=>a.endpoint),k=o=>t(`/api/webhooks/${encodeURIComponent(o)}`,{method:"PATCH",body:JSON.stringify({rotate:!0})}).then(e=>e.endpoint),l=o=>t(`/api/webhooks/${encodeURIComponent(o)}`,{method:"DELETE"}),y=o=>t(`/api/webhooks/${encodeURIComponent(o)}/test`,{method:"POST"}),u=(o,e)=>t("/api/webhooks/emit",{method:"POST",body:JSON.stringify({event:o,data:e})}).catch(()=>({sent:0}));export{b as a,l as b,p as c,u as e,m as l,h as p,k as r,y as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as vt}from"./titleFrameBudget-BYRZAQPs.js";import{u as _t}from"./store-75tQUvPT.js";import{t as et}from"./api-DUp403BK.js";import{a5 as Ft}from"./main-BKjBWQik.js";import{k as Et,Y as Ot,_ as Tt,v as Bt}from"./rigTrack-UYZU4P-e.js";import"./remote-Dva2qg58.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./rotoMaskStore-BxyxB2bD.js";import"./textAnimators-nVSz_sZo.js";import"./timelineComp-BcewYGR2.js";import"./spark.module-B34aiScb.js";import"./userFonts-DzY0A4bD.js";import"./lottieLayer-1ET89OUr.js";import"./timeline3d-246tBEJl.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-MUwVTI52.js";import"./captionLayout-EuB59pN_.js";import"./timelineText-BzUhNWPB.js";import"./titleArt-B8DVR58F.js";import"./rotoMatte-BdYa8FSB.js";import"./distortGL-BlmBZKRU.js";import"./motionBlur-uAm030t9.js";const Pt=Object.freeze({nose:0,earL:7,earR:8,shL:11,shR:12,elL:13,elR:14,wrL:15,wrR:16,hipL:23,hipR:24,knL:25,knR:26,anL:27,anR:28,toL:31,toR:32}),it=Object.freeze({frames:1800,people:2,seconds:60}),V=(l,s,h)=>l+(s-l)*h,st=l=>{const s=l.filter(Number.isFinite).sort((h,a)=>h-a);return s.length?s[Math.floor(s.length/2)]:NaN},mt=(l,s)=>Math.hypot(l[0]-s[0],l[1]-s[1]);function dt(l,s,{minCutoff:h=1.6,beta:a=.015,dCutoff:r=1}={}){const d=y=>{const O=1/(2*Math.PI*y),p=1/s;return 1/(1+O/p)},k=[];let w=l[0],u=0;for(let y=0;y<l.length;y++){if(y===0){k.push(w);continue}const O=(l[y]-w)*s,p=d(r);u=V(u,O,p);const R=d(h+a*Math.abs(u));w=V(w,l[y],R),k.push(w)}return k}function At(l){const s=l.slice(),h=s.length;let a=-1;for(let r=0;r<h;r++)if(s[r]){if(a<0)for(let d=0;d<r;d++)s[d]=s[r];else if(r-a>1)for(let d=a+1;d<r;d++){const k=(d-a)/(r-a);s[d]=[V(s[a][0],s[r][0],k),V(s[a][1],s[r][1],k),V(s[a][2]??0,s[r][2]??0,k)]}a=r}if(a>=0)for(let r=a+1;r<h;r++)s[r]=s[a];return s}function St(l,{rate:s=30,rect:h={x:0,y:0,w:1,h:1},W:a=1280,H:r=720,character:d="stickman",style:k={},place:w=null,minVisibility:u=.35}={}){if(!Array.isArray(l)||l.length<2)throw Error("Not enough of the person was seen in the video to follow (at least 2 frames)");const y=Math.min(l.length,it.frames),O=t=>[(h.x+t[0]*h.w)*a,(h.y+t[1]*h.h)*r,t[2]??0],p=Object.fromEntries(Object.entries(Pt).map(([t,o])=>[t,l.slice(0,y).map(c=>{const e=c?.lm?.[o];return e&&(e[3]??1)>=u&&Number.isFinite(e[0])&&Number.isFinite(e[1])?O(e):null})]));if(p.hipL.filter(Boolean).length+p.hipR.filter(Boolean).length<y*.3)throw Error("The person is hidden in most of the video — choose a clip where the whole body shows");const m={};for(const[t,o]of Object.entries(p)){const c=At(o);if(!c[0]){m[t]=null;continue}const e=dt(c.map(i=>i[0]),s),g=dt(c.map(i=>i[1]),s),n=c.map(i=>i[2]??0);m[t]=e.map((i,_)=>[i,g[_],n[_]])}for(const t of["shL","shR","hipL","hipR","anL","anR"])if(!m[t])throw Error("The whole body has to show in the video (shoulders, hips and feet)");const b=(t,o,c)=>[(m[t][c][0]+m[o][c][0])/2,(m[t][c][1]+m[o][c][1])/2];let B="L",j=0;const W=[];for(let t=0;t<y;t++){const o=m.shL[t][2]+m.hipL[t][2],c=m.shR[t][2]+m.hipR[t][2],e=o<=c?"L":"R";j=e===B?0:j+1,j>Math.round(s*.3)&&(B=e,j=0),W.push(B)}const x=(t,o)=>st(Array.from({length:y},(c,e)=>m[t]&&m[o]?mt(m[t][e],m[o][e]):NaN)),U=t=>b("hipL","hipR",t),D=t=>b("shL","shR",t),J=st(Array.from({length:y},(t,o)=>mt(U(o),D(o))))*1.12,I=(x("hipL","knL")+x("hipR","knR"))/2+(x("knL","anL")+x("knR","anR"))/2;if(!(J>4&&I>4))throw Error("The person is too small in the video to follow");const v=(J+I)/264,f={ua:(x("shL","elL")+x("shR","elR"))/2/v||56,fa:(x("elL","wrL")+x("elR","wrR"))/2/v||52,th:(x("hipL","knL")+x("hipR","knR"))/2/v,sh:(x("knL","anL")+x("knR","anR"))/2/v},P=Array.from({length:y},(t,o)=>Math.max(m.anL[o][1],m.anR[o][1])).sort((t,o)=>t-o),T=P[Math.floor(P.length*.8)],L=t=>[t[0]/v,(t[1]-T)/v],F=(t,o,c)=>{const e=[o[0]-t[0],o[1]-t[1]],g=Math.hypot(e[0],e[1])||1;return[t[0]+e[0]*c/g,t[1]+e[1]*c/g]},E=[];for(let t=0;t<y;t++){const o=W[t],c=o==="L"?"R":"L",e=$=>m[$]?L(m[$][t]):null,g=L(U(t)),n=L(D(t)),i=F(g,[n[0]+(n[0]-g[0])*.12,n[1]+(n[1]-g[1])*.12],108),_=m.earL&&m.earR?L(b("earL","earR",t)):e("nose")??[i[0],i[1]-21],z=F(i,_,21),G=e(`sh${o}`),K=e(`sh${c}`),S=e(`hip${o}`),X=e(`hip${c}`),Y=($,C,tt)=>[C[0]+($[0]-C[0])*tt,C[1]+($[1]-C[1])*tt],at=Y(G,[i[0],i[1]+8],.22),ct=Y(K,[i[0],i[1]+8],.22),lt=Y(S,g,.35),ht=Y(X,g,.35),H=($,C,tt,xt,Mt)=>{const nt=F($,C??$,xt),bt=F(nt,tt??nt,Mt);return[nt,bt]},[pt,ut]=H(at,e(`el${o}`),e(`wr${o}`),f.ua,f.fa),[ft,wt]=H(ct,e(`el${c}`),e(`wr${c}`),f.ua,f.fa),[yt,Q]=H(lt,e(`kn${o}`),e(`an${o}`),f.th,f.sh),[kt,Z]=H(ht,e(`kn${c}`),e(`an${c}`),f.th,f.sh),Lt=e(`to${o}`)?F(Q,e(`to${o}`),16):[Q[0]+16,Q[1]-2],gt=e(`to${c}`)?F(Z,e(`to${c}`),16):[Z[0]+16,Z[1]-2],Rt={pelvis:g,neck:i,head:z,shF:at,shB:ct,elF:pt,elB:ft,haF:ut,haB:wt,hiF:lt,hiB:ht,knF:yt,knB:kt,anF:Q,anB:Z,toF:Lt,toB:gt,sides:{handL:o==="L"?"haF":"haB",handR:o==="L"?"haB":"haF",footL:o==="L"?"anF":"anB",footR:o==="L"?"anB":"anF"}};E.push({J:Rt,tt:(l[t]?.t??t/s)-(l[0]?.t??0),sh:[0,0]})}for(const t of E){const o={...t.J};let c=!1;for(const e of["anF","anB"])if(o[e][1]>0){const g=-o[e][1];o[e]=[o[e][0],0];const n=e==="anF"?"toF":"toB";o[n]=[o[n][0],o[n][1]+g],c=!0}c&&(t.J=Et(o,t.J))}Ot(E);const{ch:M,C:ot}=Tt(d,k);let A=[0,T],N=v;if(w){N=(w.size??.5)*r/300;const t=st(E.map(o=>o.J.pelvis[0]));A=[(w.x??.5)*a-t*N,(w.ground??.9)*r]}return{v:1,character:d,style:k,ch:M,C:ot,W:a,H:r,size:N*300/r,k:N,fs:1,base:A,fps:Math.round(s),trails:null,frames:E,skip:[],total:E.length/s}}const $t="https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task",jt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${Ft}/wasm`,It=512;let rt=null;async function Nt(){if(typeof window<"u"&&window.__poseTrackerStub)return{detect:window.__poseTrackerStub,close:()=>{}};const{FilesetResolver:l,PoseLandmarker:s}=await vt(async()=>{const{FilesetResolver:r,PoseLandmarker:d}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:r,PoseLandmarker:d}},[]);rt??=l.forVisionTasks(jt).catch(r=>{throw rt=null,r});const h=await s.createFromOptions(await rt,{baseOptions:{modelAssetPath:$t,delegate:"CPU"},runningMode:"VIDEO",numPoses:it.people,minPoseDetectionConfidence:.5,minPosePresenceConfidence:.5,minTrackingConfidence:.5});let a=0;return{detect:(r,d)=>{a=Math.max(a+1,Math.round(d));const k=h.detectForVideo(r,a);return{landmarks:(k.landmarks??[]).map(w=>w.map(u=>[u.x,u.y,u.z,u.visibility??1])),world:(k.worldLandmarks??[]).map(w=>w.map(u=>[u.x,u.y,u.z]))}},close:()=>h.close()}}const q=448;async function zt({clip:l,url:s,from:h,duration:a,fps:r,person:d=1,signal:k,onProgress:w,focus:u}){const{detect:y,close:O}=await Nt(),p=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});p.src=s;try{await new Promise((L,F)=>{p.onloadeddata=()=>L(),p.onerror=()=>F(Error(et("Không đọc được video để học chuyển động (CORS / định dạng)")))});const R=p.videoWidth||1280,m=p.videoHeight||720,b=Math.min(It,R),B=Math.max(2,Math.round(b*m/R)),j=Object.assign(document.createElement("canvas"),{width:b,height:B}),W=j.getContext("2d",{willReadFrequently:!0}),x=l.playbackRate||1,U=(l.inPoint||0)+h*x,D=Math.min(it.frames,Math.max(2,Math.round(a*r))),J=[],I=u?.crop&&!window.__poseTrackerStub?Object.assign(document.createElement("canvas"),{width:q,height:q}):null,v=I?.getContext("2d",{willReadFrequently:!0});let f=null,P=null;const T=L=>[(L[23][0]+L[24][0])/2,(L[23][1]+L[24][1])/2];for(let L=0;L<D;L++){if(k?.aborted)throw new DOMException("Đã huỷ","AbortError");const F=Math.max(0,Math.min(p.duration-1/60,U+L/r*x));Math.abs(p.currentTime-F)>1e-4&&await new Promise((n,i)=>{const _=window.setTimeout(()=>i(Error(et("Seek video quá lâu"))),8e3);p.onseeked=()=>{window.clearTimeout(_),n()},p.currentTime=F});const E=u?u(F):null;let M=null;if(E&&I){const n=E.box,i={cx:(n.x+n.w/2)*R,cy:(n.y+n.h/2)*m,s:Math.max(n.w*R,n.h*m,Math.min(R,m)*.25)*1.35};f=f?{cx:f.cx*.5+i.cx*.5,cy:f.cy*.5+i.cy*.5,s:Math.max(i.s,f.s*.85)}:i,M={sx:f.cx-f.s/2,sy:f.cy-f.s/2,s:f.s}}else f=null;const ot=M&&I&&v?I:j;M&&v?(v.fillStyle="#000",v.fillRect(0,0,q,q),v.drawImage(p,M.sx,M.sy,M.s,M.s,0,0,q,q)):W.drawImage(p,0,0,b,B);const A=y(ot,(L+1)*1e3/r),N=n=>M?n.map(i=>[(M.sx+i[0]*M.s)/R,(M.sy+i[1]*M.s)/m,i[2]*M.s/R,i[3]]):n,t=(Array.isArray(A)?A:A.landmarks).map(N),o=Array.isArray(A)?[]:A.world??[],c=t.filter(n=>Array.isArray(n)&&n.length>=33);let e=null;if(c.length&&E){const n=E.box,i=Math.max(n.w*.25,n.h*m/R*.5),_=n.x+n.w/2,z=n.y+n.h/2;let G=1/0;for(const K of c){const S=T(K);if(S[0]<n.x-i||S[0]>n.x+n.w+i||S[1]<n.y||S[1]>n.y+n.h)continue;const X=Math.hypot(S[0]-_,S[1]-z);X<G&&(G=X,e=K)}e&&(P=T(e))}else if(c.length){if(P){let n=1/0;for(const i of c){const _=T(i),z=Math.hypot(_[0]-P[0],_[1]-P[1]);z<n&&(n=z,e=i)}n>.25&&(e=null)}else{const n=[...c].sort((i,_)=>T(i)[0]-T(_)[0]);e=n[Math.min(n.length-1,d-1)]}e&&(P=T(e))}const g=e?o[t.indexOf(e)]:null;J.push({t:L/r,lm:e,...g&&g.length>=33?{wl:g}:{}}),w?.(L+1,D)}return{frames:J,aspect:R/m}}finally{p.removeAttribute("src"),p.load(),O()}}function Ct(l,s,h="contain"){if(h==="cover"?l<s:l>s){const d=s/l;return{x:0,y:(1-d)/2,w:1,h:d}}const r=l/s;return{x:(1-r)/2,y:0,w:r,h:1}}async function he(l,s){const h=s.params??{},a=_t.getState().clips.find(b=>b.id===h.source);if(!a||a.kind!=="video")throw Error(et("Không tìm thấy clip video để học chuyển động"));const r=document.querySelector(`video[data-clip-media="${a.id}"]`)?.currentSrc||a.url,d=h.fps??30,k=h.W??1280,w=h.H??720,{frames:u,aspect:y}=await zt({clip:a,url:r,from:h.from??0,duration:h.duration??a.duration,fps:d,person:h.person??1}),O=St(u,{rate:d,rect:Ct(y,k/w,a.fit??"contain"),W:k,H:w,character:h.character??"stickman",style:h.style??{},place:h.place??null}),p=Bt(O),R=l.shape;if(!R?.items?.[0])throw Error(et("Lớp người que không còn"));const m=R.items.map((b,B)=>B?b:{...b,params:{...b.params,rig:p},opacity:1,span:[0,Math.round(p.n/p.fps*1e4)/1e4]});return{shape:{...R,items:m}}}export{$t as POSE_MODEL_URL,Ct as pictureRect,he as runPoseTrack,zt as trackPose};
|
|
1
|
+
import{_ as vt}from"./titleFrameBudget-CLZWaFHO.js";import{u as _t}from"./store-DW4E9xnW.js";import{t as et}from"./api-CJ8PdbfZ.js";import{a6 as Ft}from"./main-VVYiW8XD.js";import{k as Et,Y as Ot,_ as Tt,v as Bt}from"./rigTrack-urT3nDK0.js";import"./remote-C7J0Tqhb.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./spark.module-DzziUgOj.js";import"./userFonts-CwlKh9NR.js";import"./lottieLayer-DzbA3bHV.js";import"./timeline3d-DOw-CpZI.js";import"./RoomEnvironment-Dmv_G5ka.js";import"./exportEncode-QYsT9JBO.js";import"./captionLayout-DvDPTwO9.js";import"./timelineText-BH09jfSM.js";import"./titleArt-Drsrtfiv.js";import"./rotoMatte-C-2o3vv0.js";import"./distortGL-QalhICvi.js";import"./motionBlur-uAm030t9.js";const Pt=Object.freeze({nose:0,earL:7,earR:8,shL:11,shR:12,elL:13,elR:14,wrL:15,wrR:16,hipL:23,hipR:24,knL:25,knR:26,anL:27,anR:28,toL:31,toR:32}),it=Object.freeze({frames:1800,people:2,seconds:60}),V=(l,s,h)=>l+(s-l)*h,st=l=>{const s=l.filter(Number.isFinite).sort((h,a)=>h-a);return s.length?s[Math.floor(s.length/2)]:NaN},mt=(l,s)=>Math.hypot(l[0]-s[0],l[1]-s[1]);function dt(l,s,{minCutoff:h=1.6,beta:a=.015,dCutoff:r=1}={}){const d=y=>{const O=1/(2*Math.PI*y),p=1/s;return 1/(1+O/p)},k=[];let w=l[0],u=0;for(let y=0;y<l.length;y++){if(y===0){k.push(w);continue}const O=(l[y]-w)*s,p=d(r);u=V(u,O,p);const R=d(h+a*Math.abs(u));w=V(w,l[y],R),k.push(w)}return k}function At(l){const s=l.slice(),h=s.length;let a=-1;for(let r=0;r<h;r++)if(s[r]){if(a<0)for(let d=0;d<r;d++)s[d]=s[r];else if(r-a>1)for(let d=a+1;d<r;d++){const k=(d-a)/(r-a);s[d]=[V(s[a][0],s[r][0],k),V(s[a][1],s[r][1],k),V(s[a][2]??0,s[r][2]??0,k)]}a=r}if(a>=0)for(let r=a+1;r<h;r++)s[r]=s[a];return s}function St(l,{rate:s=30,rect:h={x:0,y:0,w:1,h:1},W:a=1280,H:r=720,character:d="stickman",style:k={},place:w=null,minVisibility:u=.35}={}){if(!Array.isArray(l)||l.length<2)throw Error("Not enough of the person was seen in the video to follow (at least 2 frames)");const y=Math.min(l.length,it.frames),O=t=>[(h.x+t[0]*h.w)*a,(h.y+t[1]*h.h)*r,t[2]??0],p=Object.fromEntries(Object.entries(Pt).map(([t,o])=>[t,l.slice(0,y).map(c=>{const e=c?.lm?.[o];return e&&(e[3]??1)>=u&&Number.isFinite(e[0])&&Number.isFinite(e[1])?O(e):null})]));if(p.hipL.filter(Boolean).length+p.hipR.filter(Boolean).length<y*.3)throw Error("The person is hidden in most of the video — choose a clip where the whole body shows");const m={};for(const[t,o]of Object.entries(p)){const c=At(o);if(!c[0]){m[t]=null;continue}const e=dt(c.map(i=>i[0]),s),g=dt(c.map(i=>i[1]),s),n=c.map(i=>i[2]??0);m[t]=e.map((i,_)=>[i,g[_],n[_]])}for(const t of["shL","shR","hipL","hipR","anL","anR"])if(!m[t])throw Error("The whole body has to show in the video (shoulders, hips and feet)");const b=(t,o,c)=>[(m[t][c][0]+m[o][c][0])/2,(m[t][c][1]+m[o][c][1])/2];let B="L",j=0;const W=[];for(let t=0;t<y;t++){const o=m.shL[t][2]+m.hipL[t][2],c=m.shR[t][2]+m.hipR[t][2],e=o<=c?"L":"R";j=e===B?0:j+1,j>Math.round(s*.3)&&(B=e,j=0),W.push(B)}const x=(t,o)=>st(Array.from({length:y},(c,e)=>m[t]&&m[o]?mt(m[t][e],m[o][e]):NaN)),U=t=>b("hipL","hipR",t),D=t=>b("shL","shR",t),J=st(Array.from({length:y},(t,o)=>mt(U(o),D(o))))*1.12,I=(x("hipL","knL")+x("hipR","knR"))/2+(x("knL","anL")+x("knR","anR"))/2;if(!(J>4&&I>4))throw Error("The person is too small in the video to follow");const v=(J+I)/264,f={ua:(x("shL","elL")+x("shR","elR"))/2/v||56,fa:(x("elL","wrL")+x("elR","wrR"))/2/v||52,th:(x("hipL","knL")+x("hipR","knR"))/2/v,sh:(x("knL","anL")+x("knR","anR"))/2/v},P=Array.from({length:y},(t,o)=>Math.max(m.anL[o][1],m.anR[o][1])).sort((t,o)=>t-o),T=P[Math.floor(P.length*.8)],L=t=>[t[0]/v,(t[1]-T)/v],F=(t,o,c)=>{const e=[o[0]-t[0],o[1]-t[1]],g=Math.hypot(e[0],e[1])||1;return[t[0]+e[0]*c/g,t[1]+e[1]*c/g]},E=[];for(let t=0;t<y;t++){const o=W[t],c=o==="L"?"R":"L",e=$=>m[$]?L(m[$][t]):null,g=L(U(t)),n=L(D(t)),i=F(g,[n[0]+(n[0]-g[0])*.12,n[1]+(n[1]-g[1])*.12],108),_=m.earL&&m.earR?L(b("earL","earR",t)):e("nose")??[i[0],i[1]-21],z=F(i,_,21),G=e(`sh${o}`),K=e(`sh${c}`),S=e(`hip${o}`),X=e(`hip${c}`),Y=($,C,tt)=>[C[0]+($[0]-C[0])*tt,C[1]+($[1]-C[1])*tt],at=Y(G,[i[0],i[1]+8],.22),ct=Y(K,[i[0],i[1]+8],.22),lt=Y(S,g,.35),ht=Y(X,g,.35),H=($,C,tt,xt,Mt)=>{const nt=F($,C??$,xt),bt=F(nt,tt??nt,Mt);return[nt,bt]},[pt,ut]=H(at,e(`el${o}`),e(`wr${o}`),f.ua,f.fa),[ft,wt]=H(ct,e(`el${c}`),e(`wr${c}`),f.ua,f.fa),[yt,Q]=H(lt,e(`kn${o}`),e(`an${o}`),f.th,f.sh),[kt,Z]=H(ht,e(`kn${c}`),e(`an${c}`),f.th,f.sh),Lt=e(`to${o}`)?F(Q,e(`to${o}`),16):[Q[0]+16,Q[1]-2],gt=e(`to${c}`)?F(Z,e(`to${c}`),16):[Z[0]+16,Z[1]-2],Rt={pelvis:g,neck:i,head:z,shF:at,shB:ct,elF:pt,elB:ft,haF:ut,haB:wt,hiF:lt,hiB:ht,knF:yt,knB:kt,anF:Q,anB:Z,toF:Lt,toB:gt,sides:{handL:o==="L"?"haF":"haB",handR:o==="L"?"haB":"haF",footL:o==="L"?"anF":"anB",footR:o==="L"?"anB":"anF"}};E.push({J:Rt,tt:(l[t]?.t??t/s)-(l[0]?.t??0),sh:[0,0]})}for(const t of E){const o={...t.J};let c=!1;for(const e of["anF","anB"])if(o[e][1]>0){const g=-o[e][1];o[e]=[o[e][0],0];const n=e==="anF"?"toF":"toB";o[n]=[o[n][0],o[n][1]+g],c=!0}c&&(t.J=Et(o,t.J))}Ot(E);const{ch:M,C:ot}=Tt(d,k);let A=[0,T],N=v;if(w){N=(w.size??.5)*r/300;const t=st(E.map(o=>o.J.pelvis[0]));A=[(w.x??.5)*a-t*N,(w.ground??.9)*r]}return{v:1,character:d,style:k,ch:M,C:ot,W:a,H:r,size:N*300/r,k:N,fs:1,base:A,fps:Math.round(s),trails:null,frames:E,skip:[],total:E.length/s}}const $t="https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/1/pose_landmarker_lite.task",jt=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${Ft}/wasm`,It=512;let rt=null;async function Nt(){if(typeof window<"u"&&window.__poseTrackerStub)return{detect:window.__poseTrackerStub,close:()=>{}};const{FilesetResolver:l,PoseLandmarker:s}=await vt(async()=>{const{FilesetResolver:r,PoseLandmarker:d}=await import("./vision_bundle-9zIsgJJP.js");return{FilesetResolver:r,PoseLandmarker:d}},[]);rt??=l.forVisionTasks(jt).catch(r=>{throw rt=null,r});const h=await s.createFromOptions(await rt,{baseOptions:{modelAssetPath:$t,delegate:"CPU"},runningMode:"VIDEO",numPoses:it.people,minPoseDetectionConfidence:.5,minPosePresenceConfidence:.5,minTrackingConfidence:.5});let a=0;return{detect:(r,d)=>{a=Math.max(a+1,Math.round(d));const k=h.detectForVideo(r,a);return{landmarks:(k.landmarks??[]).map(w=>w.map(u=>[u.x,u.y,u.z,u.visibility??1])),world:(k.worldLandmarks??[]).map(w=>w.map(u=>[u.x,u.y,u.z]))}},close:()=>h.close()}}const q=448;async function zt({clip:l,url:s,from:h,duration:a,fps:r,person:d=1,signal:k,onProgress:w,focus:u}){const{detect:y,close:O}=await Nt(),p=Object.assign(document.createElement("video"),{muted:!0,playsInline:!0,preload:"auto",crossOrigin:"anonymous"});p.src=s;try{await new Promise((L,F)=>{p.onloadeddata=()=>L(),p.onerror=()=>F(Error(et("Không đọc được video để học chuyển động (CORS / định dạng)")))});const R=p.videoWidth||1280,m=p.videoHeight||720,b=Math.min(It,R),B=Math.max(2,Math.round(b*m/R)),j=Object.assign(document.createElement("canvas"),{width:b,height:B}),W=j.getContext("2d",{willReadFrequently:!0}),x=l.playbackRate||1,U=(l.inPoint||0)+h*x,D=Math.min(it.frames,Math.max(2,Math.round(a*r))),J=[],I=u?.crop&&!window.__poseTrackerStub?Object.assign(document.createElement("canvas"),{width:q,height:q}):null,v=I?.getContext("2d",{willReadFrequently:!0});let f=null,P=null;const T=L=>[(L[23][0]+L[24][0])/2,(L[23][1]+L[24][1])/2];for(let L=0;L<D;L++){if(k?.aborted)throw new DOMException("Đã huỷ","AbortError");const F=Math.max(0,Math.min(p.duration-1/60,U+L/r*x));Math.abs(p.currentTime-F)>1e-4&&await new Promise((n,i)=>{const _=window.setTimeout(()=>i(Error(et("Seek video quá lâu"))),8e3);p.onseeked=()=>{window.clearTimeout(_),n()},p.currentTime=F});const E=u?u(F):null;let M=null;if(E&&I){const n=E.box,i={cx:(n.x+n.w/2)*R,cy:(n.y+n.h/2)*m,s:Math.max(n.w*R,n.h*m,Math.min(R,m)*.25)*1.35};f=f?{cx:f.cx*.5+i.cx*.5,cy:f.cy*.5+i.cy*.5,s:Math.max(i.s,f.s*.85)}:i,M={sx:f.cx-f.s/2,sy:f.cy-f.s/2,s:f.s}}else f=null;const ot=M&&I&&v?I:j;M&&v?(v.fillStyle="#000",v.fillRect(0,0,q,q),v.drawImage(p,M.sx,M.sy,M.s,M.s,0,0,q,q)):W.drawImage(p,0,0,b,B);const A=y(ot,(L+1)*1e3/r),N=n=>M?n.map(i=>[(M.sx+i[0]*M.s)/R,(M.sy+i[1]*M.s)/m,i[2]*M.s/R,i[3]]):n,t=(Array.isArray(A)?A:A.landmarks).map(N),o=Array.isArray(A)?[]:A.world??[],c=t.filter(n=>Array.isArray(n)&&n.length>=33);let e=null;if(c.length&&E){const n=E.box,i=Math.max(n.w*.25,n.h*m/R*.5),_=n.x+n.w/2,z=n.y+n.h/2;let G=1/0;for(const K of c){const S=T(K);if(S[0]<n.x-i||S[0]>n.x+n.w+i||S[1]<n.y||S[1]>n.y+n.h)continue;const X=Math.hypot(S[0]-_,S[1]-z);X<G&&(G=X,e=K)}e&&(P=T(e))}else if(c.length){if(P){let n=1/0;for(const i of c){const _=T(i),z=Math.hypot(_[0]-P[0],_[1]-P[1]);z<n&&(n=z,e=i)}n>.25&&(e=null)}else{const n=[...c].sort((i,_)=>T(i)[0]-T(_)[0]);e=n[Math.min(n.length-1,d-1)]}e&&(P=T(e))}const g=e?o[t.indexOf(e)]:null;J.push({t:L/r,lm:e,...g&&g.length>=33?{wl:g}:{}}),w?.(L+1,D)}return{frames:J,aspect:R/m}}finally{p.removeAttribute("src"),p.load(),O()}}function Ct(l,s,h="contain"){if(h==="cover"?l<s:l>s){const d=s/l;return{x:0,y:(1-d)/2,w:1,h:d}}const r=l/s;return{x:(1-r)/2,y:0,w:r,h:1}}async function he(l,s){const h=s.params??{},a=_t.getState().clips.find(b=>b.id===h.source);if(!a||a.kind!=="video")throw Error(et("Không tìm thấy clip video để học chuyển động"));const r=document.querySelector(`video[data-clip-media="${a.id}"]`)?.currentSrc||a.url,d=h.fps??30,k=h.W??1280,w=h.H??720,{frames:u,aspect:y}=await zt({clip:a,url:r,from:h.from??0,duration:h.duration??a.duration,fps:d,person:h.person??1}),O=St(u,{rate:d,rect:Ct(y,k/w,a.fit??"contain"),W:k,H:w,character:h.character??"stickman",style:h.style??{},place:h.place??null}),p=Bt(O),R=l.shape;if(!R?.items?.[0])throw Error(et("Lớp người que không còn"));const m=R.items.map((b,B)=>B?b:{...b,params:{...b.params,rig:p},opacity:1,span:[0,Math.round(p.n/p.fps*1e4)/1e4]});return{shape:{...R,items:m}}}export{$t as POSE_MODEL_URL,Ct as pictureRect,he as runPoseTrack,zt as trackPose};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/remote-
|
|
2
|
-
import{_ as P}from"./titleFrameBudget-BYRZAQPs.js";import{eg as C,ef as X}from"./remote-Dva2qg58.js";import"./api-DUp403BK.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-75tQUvPT.js";import"./rotoMaskStore-BxyxB2bD.js";import"./textAnimators-nVSz_sZo.js";import"./timelineComp-BcewYGR2.js";import"./rigTrack-UYZU4P-e.js";const j=(r,h,c)=>r<h?h:r>c?c:r,B=r=>{if(!r.length)return 0;const h=[...r].sort((c,b)=>c-b);return h[Math.floor(h.length/2)]};function W(r,{tolerance:h}={}){const{width:c,height:b,data:m}=r,i=c*b,u=new Uint8Array(i);let y=0;for(let t=0;t<i;t++)m[t*4+3]<250&&y++;if(y>i*.02){for(let t=0;t<i;t++)u[t]=m[t*4+3]>=128?1:0;return{mask:u,background:null}}const p=[[],[],[]],e=(t,g)=>{const k=(g*c+t)*4;p[0].push(m[k]),p[1].push(m[k+1]),p[2].push(m[k+2])};for(let t=0;t<c;t++)e(t,0),e(t,b-1);for(let t=0;t<b;t++)e(0,t),e(c-1,t);const l=p.map(B),x=Math.sqrt(p[0].reduce((t,g,k)=>t+(g-l[0])**2+(p[1][k]-l[1])**2+(p[2][k]-l[2])**2,0)/p[0].length),w=h??Math.min(40,Math.max(10,3*x+8)),s=w*w,_=t=>{const g=t*4,k=m[g]-l[0],I=m[g+1]-l[1],E=m[g+2]-l[2];return k*k+I*I+E*E<=s},U=(w*.6)**2,A=(t,g)=>{const k=t*4,I=g*4,E=m[k]-m[I],v=m[k+1]-m[I+1],z=m[k+2]-m[I+2];return E*E+v*v+z*z<=U},R=new Uint8Array(i),F=[],o=(t,g)=>{!R[t]&&_(t)&&(g<0||A(t,g))&&(R[t]=1,F.push(t))};for(let t=0;t<c;t++)o(t,-1),o((b-1)*c+t,-1);for(let t=0;t<b;t++)o(t*c,-1),o(t*c+c-1,-1);for(;F.length;){const t=F.pop(),g=t%c,k=t/c|0;g>0&&o(t-1,t),g<c-1&&o(t+1,t),k>0&&o(t-c,t),k<b-1&&o(t+c,t)}for(let t=0;t<i;t++)u[t]=R[t]?0:1;return{mask:u,background:l}}function Z(r,h,c){const b=new Int32Array(c).fill(-1),m=new Int32Array(c).fill(-1);for(let i=0;i<c;i++){let u=0,y=-1,p=-1,e=0,l=0;for(let x=0;x<=h;x++)x<h&&r[i*h+x]?(e||(l=x),e++):e&&(e>u&&(u=e,y=l,p=x-1),e=0);b[i]=y,m[i]=p}return{L:b,R:m}}function V(r,{height_m:h=.15,rows:c=160,tolerance:b}={}){const{width:m,height:i,data:u}=r,{mask:y,background:p}=W(r,{tolerance:b}),{L:e,R:l}=Z(y,m,i);let x=0;for(let a=0;a<i;a++)e[a]>=0&&(x=Math.max(x,l[a]-e[a]+1));if(x<4)return null;const w=a=>e[a]>=0&&l[a]-e[a]+1>=x*.015;let s=0,_=i-1;for(;s<i&&!w(s);)s++;for(;_>s&&!w(_);)_--;if(_-s<8)return null;const U=[];for(let a=s;a<=_;a++)w(a)&&U.push((e[a]+l[a]+1)/2);const A=B(U);let R=m,F=0;for(let a=s;a<=_;a++)w(a)&&(R=Math.min(R,e[a]),F=Math.max(F,l[a]+1));const o=_-s+1,t=o/h,g=new Float32Array(i);for(let a=s;a<=_;a++)g[a]=w(a)?(A-e[a]+(l[a]+1-A))/2:0;const k=[],I=Math.max(4,Math.round(o*.12)),E=g.slice(),v=new Uint8Array(i);for(let a=s;a<=_;a++){let d=1/0,f=1/0;for(let S=1;S<=I;S++)a-S>=s&&(d=Math.min(d,g[a-S])),a+S<=_&&(f=Math.min(f,g[a+S]));d<1/0&&f<1/0&&g[a]>1.25*Math.max(d,f)+2&&(v[a]=1)}for(let a=s;a<=_;a++){if(!v[a])continue;let d=a,f=a;for(;f+1<=_&&v[f+1];)f++;let S=1/0,O=1/0;for(let N=1;N<=I;N++)d-N>=s&&(S=Math.min(S,g[d-N])),f+N<=_&&(O=Math.min(O,g[f+N]));for(;d-1>s&&g[d-1]>S*1.04+1;)d--;for(;f+1<_&&g[f+1]>O*1.04+1;)f++;const D=g[Math.max(s,d-1)],T=g[Math.min(_,f+1)];let $=m,L=0;for(let N=d;N<=f;N++)E[N]=D+(T-D)*(N-d+1)/(f-d+2),$=Math.min($,e[N]),L=Math.max(L,l[N]+1);k.push({rect:[$,d,L,f+1],from_m:+((_-f)/t).toFixed(4),to_m:+((_+1-d)/t).toFixed(4),x_m:+((($+L)/2-A)/t).toFixed(4),width_m:+((L-$)/t).toFixed(4),z_m:+(Math.max(D,T)/t).toFixed(4)}),a=f}const z=a=>a>=s&&a<=_?E[a]:0,n=[],M=Math.max(8,Math.min(c,o));for(let a=0;a<=M;a++){const d=_+1-a/M*o,f=j(Math.floor(d-o/M/2),s,_),S=j(Math.ceil(d+o/M/2),s,_);let O=0;for(let D=f;D<=S;D++)O=Math.max(O,z(D));n.push([+(O/t).toFixed(5),+((_+1-d)/t).toFixed(5)])}for(let a=0;a<2;a++){const d=n.map(f=>f[0]);for(let f=2;f<n.length-2;f++){const S=(d[f-2]+d[f-1]+d[f]+d[f+1]+d[f+2])/5;Math.abs(S-d[f])<Math.max(1.5/t,d[f]*.02)&&(n[f][0]=+S.toFixed(5))}}return n[0][0]>0&&n.unshift([0,0]),n[n.length-1][0]>0&&n.push([0,n[n.length-1][1]]),{bbox:[R,s,F,_+1],axis:A,pxPerM:t,height_m:h,profile:n,segments:J(r,y,e,l,s,_,A,z,t),cards:k,background:p,size:[m,i]}}function J(r,h,c,b,m,i,u,y,p){const{width:e,data:l}=r,x=[];for(let o=m;o<=i;o++){const t=y(o);if(t<=0){x.push(null);continue}const g=Math.round(u-t*.7),k=Math.round(u+t*.7);let I=[0,0,0],E=[],v=0,z=0,n=-1;for(let d=Math.max(0,g);d<=Math.min(e-1,k);d++){const f=o*e+d;if(!h[f])continue;const S=f*4,O=.2126*l[S]+.7152*l[S+1]+.0722*l[S+2];I[0]+=l[S],I[1]+=l[S+1],I[2]+=l[S+2],E.push(O),n>=0&&(z+=Math.abs(O-n)),n=O,v++}if(!v){x.push(null);continue}const M=[...E].sort((d,f)=>d-f),a=M[Math.floor(v*.95)]-M[Math.floor(v*.05)];x.push({y:o,w:t,c:I.map(d=>d/v),spread:a,hi:M[Math.floor(v*.98)],rough:a>0?z/a:0})}const w=[];let s=null;const _=(o,t)=>Math.hypot(o[0]-t[0],o[1]-t[1],o[2]-t[2]);for(const o of x)if(o)if(s&&(_(o.c,s.c)>55||Math.abs(o.w-s.w)>Math.max(3,s.w*.12))&&(w.push(s),s=null),!s)s={y0:o.y,y1:o.y,c:[...o.c],n:1,spread:o.spread,hi:o.hi,w:o.w,rough:o.rough};else{s.y1=o.y,s.n++;for(let t=0;t<3;t++)s.c[t]+=(o.c[t]-s.c[t])/s.n;s.spread+=(o.spread-s.spread)/s.n,s.hi=Math.max(s.hi,o.hi),s.w+=(o.w-s.w)/s.n,s.rough+=(o.rough-s.rough)/s.n}s&&w.push(s);const U=Math.max(3,(i-m+1)*.02);for(let o=w.length-1;o>=0&&w.length>1;o--)if(w[o].y1-w[o].y0+1<U){const t=o>0?o-1:o+1;w[t].y0=Math.min(w[t].y0,w[o].y0),w[t].y1=Math.max(w[t].y1,w[o].y1),w.splice(o,1)}const A=w.map(o=>{const t=o.c.map(v=>Math.round(v)),g=Math.max(...t),k=Math.min(...t),I=g?(g-k)/g:0,E=o.spread>90&&o.hi>190&&o.rough<2.2;return{from_m:+((i+1-(o.y1+1))/p).toFixed(4),to_m:+((i+1-o.y0)/p).toFixed(4),color:"#"+t.map(v=>v.toString(16).padStart(2,"0")).join(""),material:E?I>.35&&t[0]>t[2]?"gold":"chrome":"printed"}}),R=(i+1-m)/p;for(const o of A)o.material!=="printed"&&o.to_m-o.from_m<R*.04&&(o.material="printed");A.sort((o,t)=>o.from_m-t.from_m);const F=[];for(const o of A){const t=F[F.length-1];t&&t.material===o.material?t.to_m=Math.max(t.to_m,o.to_m):F.push({...o})}return F.forEach((o,t)=>{t&&(o.from_m=F[t-1].to_m)}),F.length&&(F[0].from_m=0,F[F.length-1].to_m=+((i+1-m)/p).toFixed(4)),F}const K=1600;function q(r){const h=/^https:\/\/storage\.googleapis\.com\/([^/?]+)\/([^?]+)\?.*X-Goog-Signature/.exec(r);return h?`gs://${h[1]}/${decodeURIComponent(h[2])}`:r}const Q={gold:"gold",chrome:"chrome",steel:"brushed_steel",printed:"plastic_glossy",plastic:"plastic_glossy",matte:"plastic_matte",glass:"glass_clear",frosted:"glass_frosted",paper:"paper",ceramic:"ceramic"};async function G(r){const h=await fetch(r,{mode:"cors"});if(!h.ok)throw new Error(`the image could not be loaded (HTTP ${h.status})`);const c=await createImageBitmap(await h.blob()),b=Math.min(1,K/Math.max(c.width,c.height)),m=Math.max(1,Math.round(c.width*b)),i=Math.max(1,Math.round(c.height*b)),u=document.createElement("canvas");u.width=m,u.height=i;const y=u.getContext("2d",{willReadFrequently:!0});y.drawImage(c,0,0,m,i);const p=y.getImageData(0,0,m,i);return{img:{width:m,height:i,data:p.data},full:[c.width,c.height],k:b}}function H(r,h,c){const b=u=>{for(let y=1;y<r.length;y++){const p=r[y-1],e=r[y];if(p[1]<=u&&u<=e[1]&&e[1]>p[1]){const l=(u-p[1])/(e[1]-p[1]);return[+(p[0]+(e[0]-p[0])*l).toFixed(5),+u.toFixed(5)]}}return[0,u]},m=r[r.length-1][1],i=[];h<=1e-6&&i.push([0,0]),i.push(b(h));for(const u of r)u[1]>h+1e-6&&u[1]<c-1e-6&&u[0]>0&&i.push(u);return i.push(b(c)),c>=m-1e-6&&i.push([0,+m.toFixed(5)]),i.length>=2?i:[[0,h],[0,c]]}function Y(r,h,c={}){const b=(e,l)=>({url:q(l.url),axis:+(e.axis/l.k).toFixed(2),base:+(e.bbox[3]/l.k).toFixed(2),ppm:+(e.pxPerM/l.k).toFixed(2),size:l.full}),m=b(r,h),i=c.back?b(c.back.scan,c.back):void 0,u=r.segments.length?r.segments:[{from_m:0,to_m:r.height_m,color:"#888888",material:"printed"}],y=u.map((e,l)=>{const x=c.finishes?.[l]??e.material;return{name:l===u.length-1&&u.length>1?"cap":u.length===1?"body":`part ${l+1}`,shape:"lathe",profile:H(r.profile,e.from_m,e.to_m),material:Q[x]??"plastic_glossy",photo:{...m,...i?{back:i}:{}}}}),p=r.background?"#"+r.background.map(e=>Math.round(e).toString(16).padStart(2,"0")).join(""):void 0;return r.cards.forEach((e,l)=>y.push({name:`tag ${l+1}`,shape:"box",size:[e.width_m,+(e.to_m-e.from_m).toFixed(4),.0015],position:[e.x_m,e.from_m,+(e.z_m+.002).toFixed(4)],material:"paper",photo:{...m,...p?{keyout:p}:{}}})),(c.labels??[]).forEach((e,l)=>{const x=e.bottom+e.height,w=H(r.profile,Math.max(0,e.bottom),Math.min(r.height_m,x)).filter(_=>_[0]>0).map(([_,U])=>[+(_+4e-4).toFixed(5),U]);if(w.length<2)return;const s=e.width??e.height*(e.size[0]/e.size[1]);y.push({name:`label ${l+1}`,shape:"lathe",profile:w,wrap:{url:q(e.url),size:e.size,bottom:e.bottom,height:e.height,width:+s.toFixed(4),center:e.center??0,finish:e.finish??"matte"}})}),X({v:1,parts:y})}async function ht(r,h){const c=String(r.image??"").trim(),b=Number(r.height_m);if(!c)return{ok:!1,error:"image: the URL of a photo of the product (front, square-on, plain background)"};if(!(b>.005&&b<=5))return{ok:!1,error:"height_m: the real height of the product in metres (e.g. 0.12 for a 12 cm bottle)"};let m,i;try{m=await G(c),r.back_image&&(i=await G(String(r.back_image)))}catch(n){return{ok:!1,error:n.message}}const u=V(m.img,{height_m:b});if(!u)return{ok:!1,error:"no product found in the photo: use a photo of the product alone, square-on, on a plain background (or a transparent PNG)"};const y=i?V(i.img,{height_m:b}):null,p=Array.isArray(r.finishes)?r.finishes.map(String):void 0,e=[];for(const n of Array.isArray(r.labels)?r.labels:[]){const M=String(n?.image??"").trim(),a=Number(n?.bottom_m),d=Number(n?.height_m);if(!M||!(d>0)||!(a>=0))return{ok:!1,error:"labels: each needs image, bottom_m (height of its lower edge above the base) and height_m"};let f;try{f=(await G(M)).full}catch(S){return{ok:!1,error:`label ${M}: ${S.message}`}}e.push({url:M,size:f,bottom:a,height:d,...Number(n.width_m)>0?{width:Number(n.width_m)}:{},...n.center_deg!=null?{center:Number(n.center_deg)||0}:{},...["matte","gloss","foil"].includes(String(n.finish))?{finish:String(n.finish)}:{}})}let l;try{l=Y(u,{url:c,full:m.full,k:m.k},{...i&&y?{back:{url:String(r.back_image),scan:y,full:i.full,k:i.k}}:{},...p?{finishes:p}:{},labels:e})}catch(n){return{ok:!1,error:n.message}}const{makeItem:x,saveSetOf:w,onGround:s,GROUND_NOTE:_}=await P(async()=>{const{makeItem:n,saveSetOf:M,onGround:a,GROUND_NOTE:d}=await import("./remote-Dva2qg58.js").then(f=>f.jA);return{makeItem:n,saveSetOf:M,onGround:a,GROUND_NOTE:d}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),U=h.getStage(),A=String(r.name||"Sản phẩm").trim().slice(0,60)||"Sản phẩm",R=U.items.find(n=>n.kind==="set"&&n.name===A&&n.set),F=R?.set?.id??crypto.randomUUID();await w(h)(F,A,l),h.engine()?.cacheSet(F,l);const o=C(l),t={id:F,name:A,parts:l.parts.length,min:o.min,max:o.max},g=r.position!=null&&Array.isArray(r.position)?s(r.position.slice(0,3).map(Number)):null,k={...g?{position:g.position}:{},...r.yaw_deg!=null?{rotation:[0,Number(r.yaw_deg)||0,0]}:{}};let I=A,E=R?.id;if(R)h.setStage(n=>({...n,items:n.items.map(M=>M.id===R.id?{...M,...k,set:t}:M)}));else{const n=x(h.getStage(),{kind:"set",name:A,color:"#9aa3a8",set:t,...k});I=n.name,E=n.id,h.setStage(M=>({...M,items:[...M.items,n]}))}const v=2*Math.max(...u.profile.map(n=>n[0])),z=r.save_glb?await tt({name:I},h):null;return{ok:!0,name:I,id:E,rebuilt:!!R,size_m:o.size,height_m:b,diameter_m:+v.toFixed(4),parts:u.segments.map((n,M)=>({from_m:n.from_m,to_m:n.to_m,colour:n.color,finish:p?.[M]??n.material})),...g?.lifted?{note:_}:{},...z?{glb:z.ok?{url:z.url,gcsUri:z.gcsUri,file:z.file}:{error:z.error}}:{},...e.length?{labels:e.map(n=>({bottom_m:n.bottom,height_m:n.height,width_m:+(n.width??n.height*(n.size[0]/n.size[1])).toFixed(4),center_deg:n.center??0}))}:{},hint:"seen from the front (+Z) the model shows the photo itself; put the camera square-on for a pack shot. finishes: one per part (gold, chrome, steel, printed, matte, glass, frosted, paper, ceramic) to correct a guess."}}async function tt(r,h){const{findItem:c}=await P(async()=>{const{findItem:e}=await import("./remote-Dva2qg58.js").then(l=>l.jz);return{findItem:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),{loadSetOf:b}=await P(async()=>{const{loadSetOf:e}=await import("./remote-Dva2qg58.js").then(l=>l.jA);return{loadSetOf:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));let m;try{m=c(h.getStage(),String(r.name??""))}catch(e){return{ok:!1,error:e.message}}if(m.kind!=="set"||!m.set)return{ok:!1,error:`'${m.name}' is not a modelled object (a product, a kit model or a built set); a GLB library model is already a .glb`};let i=h.engine()?.setRecipe(m.set.id)??null;try{i||(i=await b(h)(m.set.id))}catch(e){return{ok:!1,error:e.message}}if(!i)return{ok:!1,error:"the model could not be loaded"};const{recipeGlb:u}=await P(async()=>{const{recipeGlb:e}=await import("./exportGlb-SIXFRRJM.js");return{recipeGlb:e}},__vite__mapDeps([10,2,0,1,3,4,5,6,7,8,9]));let y;try{y=await u(i)}catch(e){return{ok:!1,error:`export failed: ${e.message}`}}const p=`${(String(r.file_name||m.name).trim()||"model").replace(/[^\p{L}\p{N} _.-]+/gu,"").slice(0,60)||"model"}.glb`;try{const l=await(h.uploadFile??(async x=>(await P(async()=>{const{uploadFile:w}=await import("./api-DUp403BK.js").then(s=>s.c2);return{uploadFile:w}},__vite__mapDeps([1,2]))).uploadFile(x)))(new File([y],p,{type:"model/gltf-binary"}));return{ok:!0,name:m.name,file:p,bytes:y.size,url:l.url,gcsUri:l.gcsUri,note:"saved in My assets (Models); it can be downloaded or added to any scene from there"}}catch(e){return{ok:!1,error:`upload failed: ${e.message}`,bytes:y.size}}}export{q as durableUrl,G as loadPixels,ht as modelProduct,Y as productRecipe,tt as saveGlb};
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/remote-C7J0Tqhb.js","assets/api-CJ8PdbfZ.js","assets/titleFrameBudget-CLZWaFHO.js","assets/three.module-Bx43vjkH.js","assets/GLTFLoader-BHWu1lKg.js","assets/store-DW4E9xnW.js","assets/rotoMaskStore-DPziPKAN.js","assets/textAnimators-DUZjhVGO.js","assets/timelineComp-B4GtoH2f.js","assets/rigTrack-urT3nDK0.js","assets/exportGlb-TSj09XoV.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{_ as P}from"./titleFrameBudget-CLZWaFHO.js";import{eg as C,ef as X}from"./remote-C7J0Tqhb.js";import"./api-CJ8PdbfZ.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-DW4E9xnW.js";import"./rotoMaskStore-DPziPKAN.js";import"./textAnimators-DUZjhVGO.js";import"./timelineComp-B4GtoH2f.js";import"./rigTrack-urT3nDK0.js";const j=(r,h,c)=>r<h?h:r>c?c:r,B=r=>{if(!r.length)return 0;const h=[...r].sort((c,b)=>c-b);return h[Math.floor(h.length/2)]};function W(r,{tolerance:h}={}){const{width:c,height:b,data:m}=r,i=c*b,u=new Uint8Array(i);let y=0;for(let t=0;t<i;t++)m[t*4+3]<250&&y++;if(y>i*.02){for(let t=0;t<i;t++)u[t]=m[t*4+3]>=128?1:0;return{mask:u,background:null}}const p=[[],[],[]],e=(t,g)=>{const k=(g*c+t)*4;p[0].push(m[k]),p[1].push(m[k+1]),p[2].push(m[k+2])};for(let t=0;t<c;t++)e(t,0),e(t,b-1);for(let t=0;t<b;t++)e(0,t),e(c-1,t);const l=p.map(B),x=Math.sqrt(p[0].reduce((t,g,k)=>t+(g-l[0])**2+(p[1][k]-l[1])**2+(p[2][k]-l[2])**2,0)/p[0].length),w=h??Math.min(40,Math.max(10,3*x+8)),s=w*w,_=t=>{const g=t*4,k=m[g]-l[0],I=m[g+1]-l[1],E=m[g+2]-l[2];return k*k+I*I+E*E<=s},U=(w*.6)**2,A=(t,g)=>{const k=t*4,I=g*4,E=m[k]-m[I],v=m[k+1]-m[I+1],z=m[k+2]-m[I+2];return E*E+v*v+z*z<=U},R=new Uint8Array(i),F=[],o=(t,g)=>{!R[t]&&_(t)&&(g<0||A(t,g))&&(R[t]=1,F.push(t))};for(let t=0;t<c;t++)o(t,-1),o((b-1)*c+t,-1);for(let t=0;t<b;t++)o(t*c,-1),o(t*c+c-1,-1);for(;F.length;){const t=F.pop(),g=t%c,k=t/c|0;g>0&&o(t-1,t),g<c-1&&o(t+1,t),k>0&&o(t-c,t),k<b-1&&o(t+c,t)}for(let t=0;t<i;t++)u[t]=R[t]?0:1;return{mask:u,background:l}}function Z(r,h,c){const b=new Int32Array(c).fill(-1),m=new Int32Array(c).fill(-1);for(let i=0;i<c;i++){let u=0,y=-1,p=-1,e=0,l=0;for(let x=0;x<=h;x++)x<h&&r[i*h+x]?(e||(l=x),e++):e&&(e>u&&(u=e,y=l,p=x-1),e=0);b[i]=y,m[i]=p}return{L:b,R:m}}function V(r,{height_m:h=.15,rows:c=160,tolerance:b}={}){const{width:m,height:i,data:u}=r,{mask:y,background:p}=W(r,{tolerance:b}),{L:e,R:l}=Z(y,m,i);let x=0;for(let a=0;a<i;a++)e[a]>=0&&(x=Math.max(x,l[a]-e[a]+1));if(x<4)return null;const w=a=>e[a]>=0&&l[a]-e[a]+1>=x*.015;let s=0,_=i-1;for(;s<i&&!w(s);)s++;for(;_>s&&!w(_);)_--;if(_-s<8)return null;const U=[];for(let a=s;a<=_;a++)w(a)&&U.push((e[a]+l[a]+1)/2);const A=B(U);let R=m,F=0;for(let a=s;a<=_;a++)w(a)&&(R=Math.min(R,e[a]),F=Math.max(F,l[a]+1));const o=_-s+1,t=o/h,g=new Float32Array(i);for(let a=s;a<=_;a++)g[a]=w(a)?(A-e[a]+(l[a]+1-A))/2:0;const k=[],I=Math.max(4,Math.round(o*.12)),E=g.slice(),v=new Uint8Array(i);for(let a=s;a<=_;a++){let d=1/0,f=1/0;for(let S=1;S<=I;S++)a-S>=s&&(d=Math.min(d,g[a-S])),a+S<=_&&(f=Math.min(f,g[a+S]));d<1/0&&f<1/0&&g[a]>1.25*Math.max(d,f)+2&&(v[a]=1)}for(let a=s;a<=_;a++){if(!v[a])continue;let d=a,f=a;for(;f+1<=_&&v[f+1];)f++;let S=1/0,O=1/0;for(let N=1;N<=I;N++)d-N>=s&&(S=Math.min(S,g[d-N])),f+N<=_&&(O=Math.min(O,g[f+N]));for(;d-1>s&&g[d-1]>S*1.04+1;)d--;for(;f+1<_&&g[f+1]>O*1.04+1;)f++;const D=g[Math.max(s,d-1)],T=g[Math.min(_,f+1)];let $=m,L=0;for(let N=d;N<=f;N++)E[N]=D+(T-D)*(N-d+1)/(f-d+2),$=Math.min($,e[N]),L=Math.max(L,l[N]+1);k.push({rect:[$,d,L,f+1],from_m:+((_-f)/t).toFixed(4),to_m:+((_+1-d)/t).toFixed(4),x_m:+((($+L)/2-A)/t).toFixed(4),width_m:+((L-$)/t).toFixed(4),z_m:+(Math.max(D,T)/t).toFixed(4)}),a=f}const z=a=>a>=s&&a<=_?E[a]:0,n=[],M=Math.max(8,Math.min(c,o));for(let a=0;a<=M;a++){const d=_+1-a/M*o,f=j(Math.floor(d-o/M/2),s,_),S=j(Math.ceil(d+o/M/2),s,_);let O=0;for(let D=f;D<=S;D++)O=Math.max(O,z(D));n.push([+(O/t).toFixed(5),+((_+1-d)/t).toFixed(5)])}for(let a=0;a<2;a++){const d=n.map(f=>f[0]);for(let f=2;f<n.length-2;f++){const S=(d[f-2]+d[f-1]+d[f]+d[f+1]+d[f+2])/5;Math.abs(S-d[f])<Math.max(1.5/t,d[f]*.02)&&(n[f][0]=+S.toFixed(5))}}return n[0][0]>0&&n.unshift([0,0]),n[n.length-1][0]>0&&n.push([0,n[n.length-1][1]]),{bbox:[R,s,F,_+1],axis:A,pxPerM:t,height_m:h,profile:n,segments:J(r,y,e,l,s,_,A,z,t),cards:k,background:p,size:[m,i]}}function J(r,h,c,b,m,i,u,y,p){const{width:e,data:l}=r,x=[];for(let o=m;o<=i;o++){const t=y(o);if(t<=0){x.push(null);continue}const g=Math.round(u-t*.7),k=Math.round(u+t*.7);let I=[0,0,0],E=[],v=0,z=0,n=-1;for(let d=Math.max(0,g);d<=Math.min(e-1,k);d++){const f=o*e+d;if(!h[f])continue;const S=f*4,O=.2126*l[S]+.7152*l[S+1]+.0722*l[S+2];I[0]+=l[S],I[1]+=l[S+1],I[2]+=l[S+2],E.push(O),n>=0&&(z+=Math.abs(O-n)),n=O,v++}if(!v){x.push(null);continue}const M=[...E].sort((d,f)=>d-f),a=M[Math.floor(v*.95)]-M[Math.floor(v*.05)];x.push({y:o,w:t,c:I.map(d=>d/v),spread:a,hi:M[Math.floor(v*.98)],rough:a>0?z/a:0})}const w=[];let s=null;const _=(o,t)=>Math.hypot(o[0]-t[0],o[1]-t[1],o[2]-t[2]);for(const o of x)if(o)if(s&&(_(o.c,s.c)>55||Math.abs(o.w-s.w)>Math.max(3,s.w*.12))&&(w.push(s),s=null),!s)s={y0:o.y,y1:o.y,c:[...o.c],n:1,spread:o.spread,hi:o.hi,w:o.w,rough:o.rough};else{s.y1=o.y,s.n++;for(let t=0;t<3;t++)s.c[t]+=(o.c[t]-s.c[t])/s.n;s.spread+=(o.spread-s.spread)/s.n,s.hi=Math.max(s.hi,o.hi),s.w+=(o.w-s.w)/s.n,s.rough+=(o.rough-s.rough)/s.n}s&&w.push(s);const U=Math.max(3,(i-m+1)*.02);for(let o=w.length-1;o>=0&&w.length>1;o--)if(w[o].y1-w[o].y0+1<U){const t=o>0?o-1:o+1;w[t].y0=Math.min(w[t].y0,w[o].y0),w[t].y1=Math.max(w[t].y1,w[o].y1),w.splice(o,1)}const A=w.map(o=>{const t=o.c.map(v=>Math.round(v)),g=Math.max(...t),k=Math.min(...t),I=g?(g-k)/g:0,E=o.spread>90&&o.hi>190&&o.rough<2.2;return{from_m:+((i+1-(o.y1+1))/p).toFixed(4),to_m:+((i+1-o.y0)/p).toFixed(4),color:"#"+t.map(v=>v.toString(16).padStart(2,"0")).join(""),material:E?I>.35&&t[0]>t[2]?"gold":"chrome":"printed"}}),R=(i+1-m)/p;for(const o of A)o.material!=="printed"&&o.to_m-o.from_m<R*.04&&(o.material="printed");A.sort((o,t)=>o.from_m-t.from_m);const F=[];for(const o of A){const t=F[F.length-1];t&&t.material===o.material?t.to_m=Math.max(t.to_m,o.to_m):F.push({...o})}return F.forEach((o,t)=>{t&&(o.from_m=F[t-1].to_m)}),F.length&&(F[0].from_m=0,F[F.length-1].to_m=+((i+1-m)/p).toFixed(4)),F}const K=1600;function q(r){const h=/^https:\/\/storage\.googleapis\.com\/([^/?]+)\/([^?]+)\?.*X-Goog-Signature/.exec(r);return h?`gs://${h[1]}/${decodeURIComponent(h[2])}`:r}const Q={gold:"gold",chrome:"chrome",steel:"brushed_steel",printed:"plastic_glossy",plastic:"plastic_glossy",matte:"plastic_matte",glass:"glass_clear",frosted:"glass_frosted",paper:"paper",ceramic:"ceramic"};async function G(r){const h=await fetch(r,{mode:"cors"});if(!h.ok)throw new Error(`the image could not be loaded (HTTP ${h.status})`);const c=await createImageBitmap(await h.blob()),b=Math.min(1,K/Math.max(c.width,c.height)),m=Math.max(1,Math.round(c.width*b)),i=Math.max(1,Math.round(c.height*b)),u=document.createElement("canvas");u.width=m,u.height=i;const y=u.getContext("2d",{willReadFrequently:!0});y.drawImage(c,0,0,m,i);const p=y.getImageData(0,0,m,i);return{img:{width:m,height:i,data:p.data},full:[c.width,c.height],k:b}}function H(r,h,c){const b=u=>{for(let y=1;y<r.length;y++){const p=r[y-1],e=r[y];if(p[1]<=u&&u<=e[1]&&e[1]>p[1]){const l=(u-p[1])/(e[1]-p[1]);return[+(p[0]+(e[0]-p[0])*l).toFixed(5),+u.toFixed(5)]}}return[0,u]},m=r[r.length-1][1],i=[];h<=1e-6&&i.push([0,0]),i.push(b(h));for(const u of r)u[1]>h+1e-6&&u[1]<c-1e-6&&u[0]>0&&i.push(u);return i.push(b(c)),c>=m-1e-6&&i.push([0,+m.toFixed(5)]),i.length>=2?i:[[0,h],[0,c]]}function Y(r,h,c={}){const b=(e,l)=>({url:q(l.url),axis:+(e.axis/l.k).toFixed(2),base:+(e.bbox[3]/l.k).toFixed(2),ppm:+(e.pxPerM/l.k).toFixed(2),size:l.full}),m=b(r,h),i=c.back?b(c.back.scan,c.back):void 0,u=r.segments.length?r.segments:[{from_m:0,to_m:r.height_m,color:"#888888",material:"printed"}],y=u.map((e,l)=>{const x=c.finishes?.[l]??e.material;return{name:l===u.length-1&&u.length>1?"cap":u.length===1?"body":`part ${l+1}`,shape:"lathe",profile:H(r.profile,e.from_m,e.to_m),material:Q[x]??"plastic_glossy",photo:{...m,...i?{back:i}:{}}}}),p=r.background?"#"+r.background.map(e=>Math.round(e).toString(16).padStart(2,"0")).join(""):void 0;return r.cards.forEach((e,l)=>y.push({name:`tag ${l+1}`,shape:"box",size:[e.width_m,+(e.to_m-e.from_m).toFixed(4),.0015],position:[e.x_m,e.from_m,+(e.z_m+.002).toFixed(4)],material:"paper",photo:{...m,...p?{keyout:p}:{}}})),(c.labels??[]).forEach((e,l)=>{const x=e.bottom+e.height,w=H(r.profile,Math.max(0,e.bottom),Math.min(r.height_m,x)).filter(_=>_[0]>0).map(([_,U])=>[+(_+4e-4).toFixed(5),U]);if(w.length<2)return;const s=e.width??e.height*(e.size[0]/e.size[1]);y.push({name:`label ${l+1}`,shape:"lathe",profile:w,wrap:{url:q(e.url),size:e.size,bottom:e.bottom,height:e.height,width:+s.toFixed(4),center:e.center??0,finish:e.finish??"matte"}})}),X({v:1,parts:y})}async function ht(r,h){const c=String(r.image??"").trim(),b=Number(r.height_m);if(!c)return{ok:!1,error:"image: the URL of a photo of the product (front, square-on, plain background)"};if(!(b>.005&&b<=5))return{ok:!1,error:"height_m: the real height of the product in metres (e.g. 0.12 for a 12 cm bottle)"};let m,i;try{m=await G(c),r.back_image&&(i=await G(String(r.back_image)))}catch(n){return{ok:!1,error:n.message}}const u=V(m.img,{height_m:b});if(!u)return{ok:!1,error:"no product found in the photo: use a photo of the product alone, square-on, on a plain background (or a transparent PNG)"};const y=i?V(i.img,{height_m:b}):null,p=Array.isArray(r.finishes)?r.finishes.map(String):void 0,e=[];for(const n of Array.isArray(r.labels)?r.labels:[]){const M=String(n?.image??"").trim(),a=Number(n?.bottom_m),d=Number(n?.height_m);if(!M||!(d>0)||!(a>=0))return{ok:!1,error:"labels: each needs image, bottom_m (height of its lower edge above the base) and height_m"};let f;try{f=(await G(M)).full}catch(S){return{ok:!1,error:`label ${M}: ${S.message}`}}e.push({url:M,size:f,bottom:a,height:d,...Number(n.width_m)>0?{width:Number(n.width_m)}:{},...n.center_deg!=null?{center:Number(n.center_deg)||0}:{},...["matte","gloss","foil"].includes(String(n.finish))?{finish:String(n.finish)}:{}})}let l;try{l=Y(u,{url:c,full:m.full,k:m.k},{...i&&y?{back:{url:String(r.back_image),scan:y,full:i.full,k:i.k}}:{},...p?{finishes:p}:{},labels:e})}catch(n){return{ok:!1,error:n.message}}const{makeItem:x,saveSetOf:w,onGround:s,GROUND_NOTE:_}=await P(async()=>{const{makeItem:n,saveSetOf:M,onGround:a,GROUND_NOTE:d}=await import("./remote-C7J0Tqhb.js").then(f=>f.jA);return{makeItem:n,saveSetOf:M,onGround:a,GROUND_NOTE:d}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),U=h.getStage(),A=String(r.name||"Sản phẩm").trim().slice(0,60)||"Sản phẩm",R=U.items.find(n=>n.kind==="set"&&n.name===A&&n.set),F=R?.set?.id??crypto.randomUUID();await w(h)(F,A,l),h.engine()?.cacheSet(F,l);const o=C(l),t={id:F,name:A,parts:l.parts.length,min:o.min,max:o.max},g=r.position!=null&&Array.isArray(r.position)?s(r.position.slice(0,3).map(Number)):null,k={...g?{position:g.position}:{},...r.yaw_deg!=null?{rotation:[0,Number(r.yaw_deg)||0,0]}:{}};let I=A,E=R?.id;if(R)h.setStage(n=>({...n,items:n.items.map(M=>M.id===R.id?{...M,...k,set:t}:M)}));else{const n=x(h.getStage(),{kind:"set",name:A,color:"#9aa3a8",set:t,...k});I=n.name,E=n.id,h.setStage(M=>({...M,items:[...M.items,n]}))}const v=2*Math.max(...u.profile.map(n=>n[0])),z=r.save_glb?await tt({name:I},h):null;return{ok:!0,name:I,id:E,rebuilt:!!R,size_m:o.size,height_m:b,diameter_m:+v.toFixed(4),parts:u.segments.map((n,M)=>({from_m:n.from_m,to_m:n.to_m,colour:n.color,finish:p?.[M]??n.material})),...g?.lifted?{note:_}:{},...z?{glb:z.ok?{url:z.url,gcsUri:z.gcsUri,file:z.file}:{error:z.error}}:{},...e.length?{labels:e.map(n=>({bottom_m:n.bottom,height_m:n.height,width_m:+(n.width??n.height*(n.size[0]/n.size[1])).toFixed(4),center_deg:n.center??0}))}:{},hint:"seen from the front (+Z) the model shows the photo itself; put the camera square-on for a pack shot. finishes: one per part (gold, chrome, steel, printed, matte, glass, frosted, paper, ceramic) to correct a guess."}}async function tt(r,h){const{findItem:c}=await P(async()=>{const{findItem:e}=await import("./remote-C7J0Tqhb.js").then(l=>l.jz);return{findItem:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),{loadSetOf:b}=await P(async()=>{const{loadSetOf:e}=await import("./remote-C7J0Tqhb.js").then(l=>l.jA);return{loadSetOf:e}},__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));let m;try{m=c(h.getStage(),String(r.name??""))}catch(e){return{ok:!1,error:e.message}}if(m.kind!=="set"||!m.set)return{ok:!1,error:`'${m.name}' is not a modelled object (a product, a kit model or a built set); a GLB library model is already a .glb`};let i=h.engine()?.setRecipe(m.set.id)??null;try{i||(i=await b(h)(m.set.id))}catch(e){return{ok:!1,error:e.message}}if(!i)return{ok:!1,error:"the model could not be loaded"};const{recipeGlb:u}=await P(async()=>{const{recipeGlb:e}=await import("./exportGlb-TSj09XoV.js");return{recipeGlb:e}},__vite__mapDeps([10,2,0,1,3,4,5,6,7,8,9]));let y;try{y=await u(i)}catch(e){return{ok:!1,error:`export failed: ${e.message}`}}const p=`${(String(r.file_name||m.name).trim()||"model").replace(/[^\p{L}\p{N} _.-]+/gu,"").slice(0,60)||"model"}.glb`;try{const l=await(h.uploadFile??(async x=>(await P(async()=>{const{uploadFile:w}=await import("./api-CJ8PdbfZ.js").then(s=>s.c2);return{uploadFile:w}},__vite__mapDeps([1,2]))).uploadFile(x)))(new File([y],p,{type:"model/gltf-binary"}));return{ok:!0,name:m.name,file:p,bytes:y.size,url:l.url,gcsUri:l.gcsUri,note:"saved in My assets (Models); it can be downloaded or added to any scene from there"}}catch(e){return{ok:!1,error:`upload failed: ${e.message}`,bytes:y.size}}}export{q as durableUrl,G as loadPixels,ht as modelProduct,Y as productRecipe,tt as saveGlb};
|