@ssafy-mhk/e-ver 1.0.6 → 1.0.7
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/README.md +15 -25
- package/dist/components/EverFittingScene.d.ts +2 -2
- package/dist/garment/trackedGarmentMotion.d.ts +2 -0
- package/dist/garment/trackedModelTransform.d.ts +5 -0
- package/dist/humanoid/numberedBoneAliases.d.ts +12 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.es.js +1144 -900
- package/dist/index.umd.js +1 -1
- package/dist/math.d.ts +8 -0
- package/dist/pose/detectionCadence.d.ts +21 -0
- package/dist/pose/frameSmoothing.d.ts +14 -0
- package/dist/pose/landmarkerFactory.d.ts +2 -1
- package/dist/pose/poseSolver.d.ts +2 -0
- package/dist/pose/poseSolver.test.d.ts +1 -0
- package/dist/pose/trackingConfidence.d.ts +6 -0
- package/dist/pose/trackingConfidence.test.d.ts +1 -0
- package/package.json +3 -3
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@react-three/fiber`),require(`@react-three/drei`),require(`react/jsx-runtime`),require(`@mediapipe/tasks-vision`),require(`three`),require(`three/examples/jsm/utils/SkeletonUtils.js`),require(`@pixiv/three-vrm`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@react-three/fiber`,`@react-three/drei`,`react/jsx-runtime`,`@mediapipe/tasks-vision`,`three`,`three/examples/jsm/utils/SkeletonUtils.js`,`@pixiv/three-vrm`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`e-ver`]={},e.React,e.ReactThreeFiber,e.ReactThreeDrei,e.react_jsx_runtime,e.MediaPipeVision,e.THREE,e.three_examples_jsm_utils_SkeletonUtils_js,e.PixivThreeVRM))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e},g=(e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e));t=g(t),o=g(o);var _=({children:e,showEnvironment:a=!0,useDefaultLights:o=!0,enableOrbitControls:s=!0})=>(0,i.jsx)(n.Canvas,{camera:{position:[0,1.5,3],fov:45},style:{width:`100%`,height:`100%`,position:`absolute`,top:0,left:0},gl:{alpha:!0,antialias:!0,preserveDrawingBuffer:!0},children:(0,i.jsxs)(t.Suspense,{fallback:null,children:[o?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`ambientLight`,{intensity:.7}),(0,i.jsx)(`directionalLight`,{position:[2,5,2],intensity:1.5,castShadow:!0}),(0,i.jsx)(`directionalLight`,{position:[-2,5,-2],intensity:.5})]}):null,a&&(0,i.jsx)(r.Environment,{preset:`city`}),e,s?(0,i.jsx)(r.OrbitControls,{enablePan:!1,minPolarAngle:Math.PI/4,maxPolarAngle:Math.PI/1.5,minDistance:1,maxDistance:5}):null]})}),v={refShoulderWidthCm:44,refHeightCm:170,refArmLengthCm:58,refChestCircumferenceCm:96,refWaistCircumferenceCm:84,refHipWidthCm:36,refTorsoLengthCm:52,shoulderEaseCm:4.5,chestEaseCm:10,waistEaseCm:8,hipEaseCm:5,torsoEaseCm:2.5,armEaseCm:2,fitEaseScale:1.03};function y(e,t,n){return!e||t<=0?1:(e+n)/t}function b(e,t,n){return Math.max(t,Math.min(n,e))}function x(e,t=v){let n=y(e.shoulderWidthCm,t.refShoulderWidthCm,t.shoulderEaseCm),r=y(e.chestCircumferenceCm,t.refChestCircumferenceCm,t.chestEaseCm),i=y(e.waistCircumferenceCm,t.refWaistCircumferenceCm,t.waistEaseCm),a=y(e.hipWidthCm,t.refHipWidthCm,t.hipEaseCm),o=y(e.torsoLengthCm,t.refTorsoLengthCm,t.torsoEaseCm),s=t.refHeightCm>0?e.heightCm/t.refHeightCm:1,c=y(e.armLengthCm,t.refArmLengthCm,t.armEaseCm),l=Math.max(n,r,a),u=Math.max(r,i,a*.98),d=Math.max(s,o,l*.94);return{scaleX:b(l,.82,1.85),scaleY:b(d,.85,1.55),scaleZ:b(u,.84,1.9),sleeveScale:b(c,.8,1.55),fitEaseScale:b(t.fitEaseScale,1,1.2)}}var S=.82,C=2.1,w=.85,T=1.8,E=.84,D=2.1,O=.8,k=1.7,A=1,j=1.25,M={scaleX:1,scaleY:1,scaleZ:1,sleeveScale:1,fitEaseScale:1.02},ee={scaleX:1,scaleY:1,scaleZ:1,sleeveScale:1,fitEaseScale:1},N={slim:{x:.95,y:.95,z:1,ease:.99},regular:{x:1,y:1,z:1,ease:1},oversize:{x:1.08,y:1.08,z:1.02,ease:1.03}},P={narrow:{width:.97,shoulder:.97},balanced:{width:1,shoulder:1},broad:{width:1.03,shoulder:1.04}},F={tapered:{depth:.98,vertical:.995,hip:.99},balanced:{depth:1,vertical:1,hip:1},full:{depth:1.04,vertical:1.015,hip:1.03}};function I(e,t,n){return Math.max(t,Math.min(n,e))}function L(e,t,n,r){return!e||!t||t<=0?1:I(e/t,n,r)}function R(e,t,n,r,i){return!e||t<=0?1:I((e+n)/t,r,i)}function z(e){return P[e?.taxonomy.upperBodySilhouette??`balanced`]??P.balanced}function B(e){return F[e?.taxonomy.torsoOrPelvisProfile??`balanced`]??F.balanced}function te(e){if(!e)return!1;let{metrics:t}=e;return!!(t.heightCm||t.chestCm||t.waistCm||t.shoulderWidthCm||t.armLengthCm||t.torsoLengthCm||t.neckToHipCm)}function ne(e,t){let{metrics:n}=e,r=z(e),i=B(e),a=Math.max(R(n.shoulderWidthCm,t.refShoulderWidthCm,t.shoulderEaseCm*.55,.88,1.3),R(n.chestCm,t.refChestCircumferenceCm,t.chestEaseCm*.35,.9,1.34),R(n.waistCm,t.refWaistCircumferenceCm,t.waistEaseCm*.3,.9,1.3))*r.width,o=Math.max(L(n.heightCm,t.refHeightCm,.9,1.18),R(n.torsoLengthCm??n.neckToHipCm,t.refTorsoLengthCm,t.torsoEaseCm*.2,.9,1.16))*i.vertical,s=Math.max(R(n.chestCm,t.refChestCircumferenceCm,t.chestEaseCm*.15,.9,1.34),R(n.waistCm,t.refWaistCircumferenceCm,t.waistEaseCm*.1,.9,1.28))*i.depth;return{scaleX:I(a,S,C),scaleY:I(o,w,T),scaleZ:I(s,E,D),sleeveScale:I(L(n.armLengthCm,t.refArmLengthCm,.9,1.16),O,k),fitEaseScale:I(t.fitEaseScale*(r.width*.5+i.depth*.5),A,j)}}function re(e,t){let{metrics:n}=t,r=z(t),i=B(t),a=L(e.shoulderWidthCm,n.shoulderWidthCm,.9,1.14)*r.shoulder,o=L(e.chestCircumferenceCm,n.chestCm,.9,1.15),s=L(e.waistCircumferenceCm,n.waistCm,.9,1.15);return{torsoScale:L(e.torsoLengthCm,n.torsoLengthCm??n.neckToHipCm,.9,1.14),chestScale:o,waistScale:s,hipScale:I(s*.6+i.hip*.4,.92,1.14),shoulderAdjust:I(a-1,-.12,.12),postureAdjust:`neutral`}}function ie(e,t,n){let r=B(t),i=I(1+n.shoulderAdjust,.92,1.14)*.3+n.chestScale*.45+n.waistScale*.25,a=n.chestScale*.45+n.waistScale*.25+n.hipScale*.3,o=L(e.armLengthCm,t.metrics.armLengthCm,.9,1.16),s=Math.max(n.chestScale,n.waistScale,n.hipScale);return{scaleX:I(i,.92,1.16),scaleY:I(n.torsoScale*r.vertical,.92,1.14),scaleZ:I(a*r.depth,.92,1.18),sleeveScale:I(o,O,k),fitEaseScale:I(1+(s-1)*.22,.99,1.08)}}function ae(e,t){if(!t||!Number.isFinite(t)||t<=0)return e;let n=I(t,.88,1.2),r=1+(n-1)*.35;return{scaleX:I(e.scaleX*n,S,C),scaleY:I(e.scaleY*r,w,T),scaleZ:I(e.scaleZ*n,E,D),sleeveScale:I(e.sleeveScale*r,O,k),fitEaseScale:I(e.fitEaseScale*n,A,j)}}function oe(e,t){let n=N[t];return{scaleX:I(e.scaleX*n.x,S,C),scaleY:I(e.scaleY*n.y,w,T),scaleZ:I(e.scaleZ*n.z,E,D),sleeveScale:e.sleeveScale,fitEaseScale:I(e.fitEaseScale*n.ease,A,j)}}function se(e,t){return{scaleX:I(e.scaleX*t.scaleX,S,C),scaleY:I(e.scaleY*t.scaleY,w,T),scaleZ:I(e.scaleZ*t.scaleZ,E,D),sleeveScale:I(e.sleeveScale*t.sleeveScale,O,k),fitEaseScale:I(e.fitEaseScale*t.fitEaseScale,A,j)}}function ce({measurements:e,measurementScale:t,presetSelection:n,fitType:r=`regular`,garmentScaleHint:i=null,spec:a=v}){let o=te(n),s=o&&n?ne(n,a):t??M,c=o&&n&&e?re(e,n):null;return{scale:oe(ae(se(s,e&&n&&c?ie(e,n,c):ee),i),r),morph:c}}var le=`http://localhost:8000/api/v1`;function ue(e){return e.replace(/\/+$/,``)}function de(e){try{return new URL(e).origin}catch{return``}}var fe=class{baseUrl;apiOrigin;apiKey;constructor(e){let t=typeof e==`string`?{baseUrl:e}:e??{},n=ue(t.baseUrl??`http://localhost:8000/api/v1`);this.baseUrl=n,this.apiOrigin=de(n),this.apiKey=t.apiKey}resolveAssetUrl(e){return e?e.startsWith(`http://`)||e.startsWith(`https://`)?e:e.startsWith(`/`)?this.apiOrigin?`${this.apiOrigin}${e}`:e:this.apiOrigin?`${this.apiOrigin}/${e}`:`/${e}`:null}async listBodyPresets(e){return(await this.request(`body-presets/`,{params:e?{gender:e}:void 0})).map(e=>this.normalizeBodyPreset(e))}async matchBodyPreset(e){let t=await this.request(`body-presets/match`,{method:`POST`,body:e});return this.normalizeBodyPreset(t)}async listGarments(e){let t=await this.request(`garment/`,{params:e});return{...t,items:t.items.map(e=>this.normalizeGarmentSummary(e))}}async getGarment(e){let t=await this.request(`garment/${e}`);return this.normalizeGarmentDetail(t)}async getPipelineStatus(e){return this.request(`pipeline/${e}`)}async createGarment(e){let t=await this.request(`garment/`,{method:`POST`,body:e});return this.normalizeGarmentSummary(t)}async uploadGarmentImage(e,t,n){let r=new FormData;return r.append(`files`,t,`${n}_image.png`),r.append(`image_type`,n),(await this.request(`garment/${e}/images`,{method:`POST`,body:r})).map(e=>({...e,image_url:this.resolveAssetUrl(e.image_url)??e.image_url}))}async generateGarment3D(e,t){return this.request(`garment/${e}/generate-3d`,{method:`POST`,body:{include_measurements:t?.include_measurements??!1,target_fit_types:t?.target_fit_types??[`regular`]}})}async waitForGarmentModel(e,t){let n=t?.intervalMs??2e3,r=t?.timeoutMs??12e4,i=Date.now();for(;Date.now()-i<=r;){let t=await this.getGarment(e);if(this.pickGarmentModelUrl(t))return t;if(t.asset_status===`rigging_failed`)throw Error(`Garment 3D generation failed on backend.`);await new Promise(e=>globalThis.setTimeout(e,n))}throw Error(`Timed out while waiting for garment 3D model.`)}pickGarmentModelUrl(e){if(e.model_url)return e.model_url;let t=e.variants.find(e=>e.is_default&&e.model_url);return t?.model_url?t.model_url:e.variants.find(e=>e.model_url)?.model_url??null}normalizeBodyPreset(e){return{...e,model_url:this.resolveAssetUrl(e.model_url)}}normalizeGarmentSummary(e){return{...e,thumbnail_url:this.resolveAssetUrl(e.thumbnail_url),model_url:this.resolveAssetUrl(e.model_url)}}normalizeGarmentDetail(e){return{...this.normalizeGarmentSummary(e),brand:e.brand?{...e.brand,logo_url:this.resolveAssetUrl(e.brand.logo_url)}:null,images:e.images.map(e=>({...e,image_url:this.resolveAssetUrl(e.image_url)??e.image_url})),sizes:e.sizes,variants:e.variants.map(e=>({...e,model_url:this.resolveAssetUrl(e.model_url)}))}}async request(e,t){let n=this.apiKey?`sdk/public/${e}`:e,r=this.buildUrl(n,t?.params),i=new Headers,a;this.apiKey&&i.set(`X-API-Key`,this.apiKey),t?.body instanceof FormData?a=t.body:t?.body!==void 0&&(i.set(`Content-Type`,`application/json`),a=JSON.stringify(t.body));let o=await fetch(r.toString(),{method:t?.method??`GET`,body:a,headers:i,credentials:this.apiKey?`omit`:`include`});if(!o.ok)throw Error(await this.getResponseErrorMessage(o));if(o.status!==204)return await o.json()}buildUrl(e,t){let n=this.baseUrl.startsWith(`http://`)||this.baseUrl.startsWith(`https://`)?`${this.baseUrl}/`:typeof window<`u`?new URL(`${this.baseUrl}/`,window.location.origin).toString():`http://localhost${this.baseUrl}/`,r=new URL(e.replace(/^\/+/,``),n);return t&&Object.entries(t).forEach(([e,t])=>{t!==void 0&&r.searchParams.set(e,String(t))}),r}async getResponseErrorMessage(e){try{let t=await e.json();return t.detail||t.message||t.error||`Request failed with status ${e.status}`}catch{return`Request failed with status ${e.status}`}}},pe=`M`,me=`male-m-balanced-balanced`,he=`female-m-balanced-balanced`,ge=`rigged_avatar`;function _e(e,t){if(!t)return``;if(/^https?:\/\//.test(t))return t;let n=t.startsWith(`/`)?t:`/${t}`;return n.startsWith(`/assets/`)||n.startsWith(`/static/`)?n:e.resolveAssetUrl(n)??n}function ve(e){return e===`female`?`female`:`male`}function ye(e,t={}){let n=t.renderMode??`rigged_avatar`,r=t.legacyPresetId??`rigged_avatar`,i=`/assets/body-presets/${r}.glb`;return e===r||n!==`preset-native`?i:`/assets/body-presets/archive/${e}.glb`}function be(e){return e===`female`?he:me}function xe(e,t){return{id:e.id,presetId:e.preset_id,baseGender:ve(e.base_gender),sizeBand:e.size_band,upperBodySilhouette:e.upper_body_silhouette,torsoOrPelvisProfile:e.torso_or_pelvis_profile,modelUrl:_e(t,e.model_url),heightCm:e.height_cm??null,chestCm:e.chest_cm??null,waistCm:e.waist_cm??null,hipCm:e.hip_cm??null,shoulderWidthCm:e.shoulder_width_cm??null,armLengthCm:e.arm_length_cm??null,inseamCm:e.inseam_cm??null,torsoLengthCm:e.torso_length_cm??null,neckToHipCm:e.neck_to_hip_cm??null}}function Se(e,t={}){return{...e,modelUrl:e.modelUrl||ye(e.presetId,t)}}function Ce(e,t={}){return e.length===0?null:Se(e.find(e=>e.sizeBand===pe)||e[Math.floor(e.length/2)],t)}function we(e,t={}){let n=be(e);return{id:null,presetId:n,label:`${e===`female`?`여성`:`남성`} 기본 ${pe}`,modelUrl:ye(n,t),gender:e,source:`fallback`,taxonomy:{sizeBand:pe,upperBodySilhouette:`balanced`,torsoOrPelvisProfile:`balanced`},metrics:{heightCm:null,chestCm:null,waistCm:null,hipCm:null,shoulderWidthCm:null,armLengthCm:null,inseamCm:null,torsoLengthCm:null,neckToHipCm:null}}}function Te(e,t,n={}){let r=Se(e,n);return{id:r.id,presetId:r.presetId,label:`${r.baseGender===`female`?`여성`:`남성`} ${r.sizeBand}`,modelUrl:r.modelUrl,gender:r.baseGender,source:t,taxonomy:{sizeBand:r.sizeBand,upperBodySilhouette:r.upperBodySilhouette,torsoOrPelvisProfile:r.torsoOrPelvisProfile},metrics:{heightCm:r.heightCm,chestCm:r.chestCm,waistCm:r.waistCm,hipCm:r.hipCm,shoulderWidthCm:r.shoulderWidthCm,armLengthCm:r.armLengthCm,inseamCm:r.inseamCm,torsoLengthCm:r.torsoLengthCm,neckToHipCm:r.neckToHipCm}}}function Ee(e,t){let n={gender:t};return Number.isFinite(e.heightCm)&&(n.height_cm=e.heightCm),e.chestCircumferenceCm!==null&&(n.chest_cm=e.chestCircumferenceCm),e.waistCircumferenceCm!==null&&(n.waist_cm=e.waistCircumferenceCm),e.shoulderWidthCm!==null&&(n.shoulder_width_cm=e.shoulderWidthCm),n}var De=new fe;function Oe(e,t){return{selection:we(e,t),loading:!0,error:null}}function ke(e,n={}){let r=ve(n.gender),i=n.renderMode,a=n.legacyPresetId,o=(0,t.useMemo)(()=>({gender:r,renderMode:i,legacyPresetId:a}),[r,a,i]),[s,c]=(0,t.useState)(()=>Oe(r,o));return(0,t.useEffect)(()=>{let t=new AbortController;async function n(){c(e=>({...e,loading:!0,error:null}));try{if(e){let n=Te(xe(await De.matchBodyPreset(Ee(e,o.gender)),De),`match`,o);if(t.signal.aborted)return;c({selection:n,loading:!1,error:null});return}let n=(await De.listBodyPresets(o.gender)).map(e=>xe(e,De));if(t.signal.aborted)return;let r=Ce(n,o);if(r){c({selection:Te(r,`default`,o),loading:!1,error:null});return}c({selection:we(o.gender,o),loading:!1,error:`바디 프리셋 응답이 비어 있어 기본 프리셋으로 대체했습니다.`})}catch(e){if(t.signal.aborted)return;c({selection:we(o.gender,o),loading:!1,error:e instanceof Error?e.message:`바디 프리셋을 불러오지 못해 기본 프리셋으로 대체했습니다.`})}}return n(),()=>{t.abort()}},[e,o]),s}var V={NOSE:0,LEFT_EYE_INNER:1,LEFT_EYE:2,LEFT_EYE_OUTER:3,RIGHT_EYE_INNER:4,RIGHT_EYE:5,RIGHT_EYE_OUTER:6,LEFT_EAR:7,RIGHT_EAR:8,MOUTH_LEFT:9,MOUTH_RIGHT:10,LEFT_SHOULDER:11,RIGHT_SHOULDER:12,LEFT_ELBOW:13,RIGHT_ELBOW:14,LEFT_WRIST:15,RIGHT_WRIST:16,LEFT_PINKY:17,RIGHT_PINKY:18,LEFT_INDEX:19,RIGHT_INDEX:20,LEFT_THUMB:21,RIGHT_THUMB:22,LEFT_HIP:23,RIGHT_HIP:24,LEFT_KNEE:25,RIGHT_KNEE:26,LEFT_ANKLE:27,RIGHT_ANKLE:28,LEFT_HEEL:29,RIGHT_HEEL:30,LEFT_FOOT_INDEX:31,RIGHT_FOOT_INDEX:32},Ae={positionAlpha:.7,rotationAlpha:.6,visibilityThreshold:.5},je=.5;function Me(e){return e?(e.visibility??1)>=je:!1}function Ne(e,t){let n=e[V.NOSE],r=e[V.LEFT_EYE],i=e[V.LEFT_ANKLE],a=e[V.RIGHT_ANKLE];if(!Me(n)||!Me(r)||!Me(i)||!Me(a))return 0;let o=n.y-(r.y-n.y)*2,s=(Math.max(i.y,a.y)-o)*t;return Number.isFinite(s)&&s>0?s:0}function Pe(e,t,n=720){let r=Ne(e,n);return r<=0||t<=0?0:t/r}function Fe(e){let t=[[15,.8],[18.5,.84],[22,.88],[25,.91],[30,.94],[40,.96]];if(e<=t[0][0])return t[0][1];if(e>=t[t.length-1][0])return t[t.length-1][1];for(let n=0;n<t.length-1;n+=1){let[r,i]=t[n],[a,o]=t[n+1];if(e>=r&&e<=a)return i+(e-r)/(a-r)*(o-i)}return .88}function H(e,t,n,r){if(!Me(e)||!Me(t))return null;let i=(e.x-t.x)*n,a=(e.y-t.y)*r,o=Math.hypot(i,a);return Number.isFinite(o)&&o>0?o:null}function Ie(e){return Math.round(e*10)/10}function U(e){return e===null||!Number.isFinite(e)||e<=0?null:Ie(e)}function Le(e){let t=e.filter(e=>e!==null);return t.length===0?null:t.reduce((e,t)=>e+t,0)/t.length}function Re(e,t){return e&&t!==null&&t>0?`silhouette_bmi`:`keypoint`}function ze(e,t,n){return n&&t>0&&e/t>=.85?`standard`:`estimate`}function Be(e,t,n,r){if(t<=0||e<=0)return 0;let i=e/t*.8,a=n?.15:0,o=r!==null&&r>0?.05:0;return Math.min(.99,Ie((i+a+o)*10)/10)}function Ve(e,t){if(e<=0||t<=0)return 0;let n=(e-t)**2/(e+t)**2;return Math.PI*(e+t)*(1+3*n/(10+Math.sqrt(4-3*n)))}function He(e,t,n=null,r=null,i=1280,a=720){let o=Pe(e,t,a),s=Re(r,n);if(o<=0)return{heightCm:t,shoulderWidthCm:null,chestCircumferenceCm:null,waistCircumferenceCm:null,hipWidthCm:null,armLengthCm:null,legLengthCm:null,torsoLengthCm:null,accuracyGrade:`estimate`,confidenceScore:0,measurementMethod:s,measuredAt:null};let c=H(e[V.LEFT_SHOULDER],e[V.RIGHT_SHOULDER],i,a),l=H(e[V.LEFT_HIP],e[V.RIGHT_HIP],i,a),u=H(e[V.LEFT_SHOULDER],e[V.LEFT_ELBOW],i,a),d=H(e[V.LEFT_ELBOW],e[V.LEFT_WRIST],i,a),f=H(e[V.RIGHT_SHOULDER],e[V.RIGHT_ELBOW],i,a),p=H(e[V.RIGHT_ELBOW],e[V.RIGHT_WRIST],i,a),m=u!==null&&d!==null?u+d:null,h=f!==null&&p!==null?f+p:null,g=H(e[V.LEFT_HIP],e[V.LEFT_KNEE],i,a),_=H(e[V.LEFT_KNEE],e[V.LEFT_ANKLE],i,a),v=H(e[V.RIGHT_HIP],e[V.RIGHT_KNEE],i,a),y=H(e[V.RIGHT_KNEE],e[V.RIGHT_ANKLE],i,a),b=g!==null&&_!==null?g+_:null,x=v!==null&&y!==null?v+y:null,S=Le([H(e[V.LEFT_SHOULDER],e[V.LEFT_HIP],i,a),H(e[V.RIGHT_SHOULDER],e[V.RIGHT_HIP],i,a)]),C=U(c===null?null:c*o),w=U(l===null?null:l*o),T=U(Le([m===null?null:m*o,h===null?null:h*o])),E=U(Le([b===null?null:b*o,x===null?null:x*o])),D=U(S===null?null:S*o),O=C===null?null:C*2.2,k=w===null?null:w*2.1;if(r){let e=r.shoulderWidthPx*o;if(O=U(Ve(Math.max(r.chestWidthPx*o/2,0),Math.max(e*.28/2,0))),k=U(Ve(Math.max(r.waistWidthPx*o/2,0),Math.max(r.hipWidthPx*o*.26/2,0))),n!==null&&n>0){let e=Fe(n/(t/100)**2);O=U(O===null?null:O/e),k=U(k===null?null:k/e)}}else O=U(O),k=U(k);let A=[C,O,k,w,T,E,D].filter(e=>e!==null).length;return{heightCm:Ie(t),shoulderWidthCm:C,chestCircumferenceCm:O,waistCircumferenceCm:k,hipWidthCm:w,armLengthCm:T,legLengthCm:E,torsoLengthCm:D,accuracyGrade:ze(A,7,r),confidenceScore:Be(A,7,r,n),measurementMethod:s,measuredAt:null}}var Ue={S:{shoulder:[40,42],chest:[86,92],waist:[72,78]},M:{shoulder:[42,44],chest:[92,98],waist:[78,84]},L:{shoulder:[44,46],chest:[98,104],waist:[84,90]},XL:{shoulder:[46,48],chest:[104,110],waist:[90,96]},"2XL":{shoulder:[48,50],chest:[110,118],waist:[96,104]}};function We(e){let t=[`S`,`M`,`L`,`XL`,`2XL`],n=`M`,r=-1/0,i=!1;for(let a of t){let t=Ue[a],o=0,s=0;if(e.shoulderWidthCm!==null){let n=(t.shoulder[0]+t.shoulder[1])/2;o-=Math.abs(e.shoulderWidthCm-n),s+=1,i=!0}if(e.chestCircumferenceCm!==null){let n=(t.chest[0]+t.chest[1])/2;o-=Math.abs(e.chestCircumferenceCm-n),s+=1,i=!0}if(e.waistCircumferenceCm!==null){let n=(t.waist[0]+t.waist[1])/2;o-=Math.abs(e.waistCircumferenceCm-n),s+=1,i=!0}s>0&&(o/=s),o>r&&(r=o,n=a)}if(!i)return null;let a=Ue[n],o=`true-to-size`;if(e.chestCircumferenceCm!==null){let t=(a.chest[0]+a.chest[1])/2;e.chestCircumferenceCm>t+3?o=`slim`:e.chestCircumferenceCm<t-3&&(o=`relaxed`)}return{size:n,confidence:Math.min(1,Math.max(0,1+r/10)),fitDescription:o}}var Ge={referenceHeightCm:170,weightKg:null,stableFrameCount:15,motionThreshold:.015};function Ke(e){return e.map(e=>({...e}))}function qe(e,t){let n=0;for(let r=0;r<33;r+=1){let i=e[r],a=t[r];n+=Math.abs(a.x-i.x)+Math.abs(a.y-i.y)}return n/33}function Je(){let[e,n]=(0,t.useState)(Ge),[r,i]=(0,t.useState)(null),[a,o]=(0,t.useState)(null),[s,c]=(0,t.useState)(null),[l,u]=(0,t.useState)(!1),d=(0,t.useRef)(0),f=(0,t.useRef)(null),p=(0,t.useCallback)(()=>{d.current=0,f.current=null},[]),m=(0,t.useCallback)(()=>{i(null),o(null),c(null)},[]),h=(0,t.useCallback)(()=>{p(),m(),u(!0)},[m,p]);return{measure:(0,t.useCallback)((t,n={})=>{if(!l||t.length<33)return;let r=Ke(t);if(!f.current){f.current=r,d.current=1;return}if(d.current=qe(f.current,r)<e.motionThreshold?d.current+1:1,f.current=r,d.current<e.stableFrameCount)return;let a=He(t,e.referenceHeightCm,e.weightKg,n.silhouetteWidths??null,n.imageWidth??1280,n.imageHeight??720),s=new Date().toISOString(),m=We(a),h=x(a);i({...a,measuredAt:s}),o(m),c(h),u(!1),p()},[e,l,p]),startMeasurement:h,measurements:r,sizeRecommendation:a,garmentScale:s,isMeasuring:l,updateConfig:(0,t.useCallback)(e=>{n(t=>({...t,...e})),p(),m(),u(!1)},[m,p]),config:e}}function Ye(e,t,n,r){if(e<=0||t<=0||n<=0||r<=0)return{x:0,y:0,width:Math.max(0,e),height:Math.max(0,t)};let i=e/t,a=n/r;if(i>a){let n=e,r=n/a;return{x:0,y:(t-r)*.5,width:n,height:r}}let o=t,s=o*a;return{x:(e-s)*.5,y:0,width:s,height:o}}function Xe(e,t,n,r){if(e<=0||t<=0||n<=0||r<=0)return{xMin:0,xMax:1,yMin:0,yMax:1};let i=e/t,a=n/r;if(i>a){let e=(1-a/i)/2;return{xMin:0,xMax:1,yMin:e,yMax:1-e}}let o=(1-i/a)/2;return{xMin:o,xMax:1-o,yMin:0,yMax:1}}var Ze=5,Qe=.5;function $e(e,t,n,r,i=Ze,a=Qe){if(t<=0||n<=0||e.length!==t*n)return null;let o=Math.round(r),s=Math.floor(i/2),c=Math.max(0,o-s),l=Math.min(n-1,o+s),u=0,d=0,f=0;for(let n=c;n<=l;n+=1){let r=-1,i=-1,o=n*t;for(let n=0;n<t;n+=1)e[o+n]>=a&&(r<0&&(r=n),i=n);r>=0&&i>r&&(u+=r,d+=i,f+=1)}if(f===0)return null;let p=u/f;return d/f-p}function et(e,t,n,r){if(r.length<33)return null;let i=r[V.LEFT_SHOULDER],a=r[V.RIGHT_SHOULDER],o=r[V.LEFT_HIP],s=r[V.RIGHT_HIP],c=r[V.LEFT_KNEE],l=r[V.RIGHT_KNEE];if(!i||!a||!o||!s)return null;let u=(i.y+a.y)/2*n,d=(o.y+s.y)/2*n,f=u+(d-u)*.4,p=c&&l?d+((c.y+l.y)/2*n-d)*.2:d,m=$e(e,t,n,u),h=$e(e,t,n,f),g=$e(e,t,n,d),_=$e(e,t,n,p);return m===null||h===null||g===null||_===null?null:{shoulderWidthPx:m,chestWidthPx:h,waistWidthPx:g,hipWidthPx:_}}function W(e,t,n){return e+(t-e)*n}function tt(e,t,n){return t?!e||e.length!==t.length?t:e.map((e,r)=>{let i=t[r];return{x:W(e.x,i.x,n),y:W(e.y,i.y,n),z:W(e.z??0,i.z??0,n),visibility:W(e.visibility??0,i.visibility??0,n)}}):null}function G(e,t,n){return{x:W(e.x,t.x,n),y:W(e.y,t.y,n),z:W(e.z,t.z,n)}}function nt(e,t,n){return!e||!t?t??e:G(e,t,n)}function rt(e,t,n){return t?e?{hips:{position:{x:W(e.hips.position.x,t.hips.position.x,n),y:W(e.hips.position.y,t.hips.position.y,n),z:W(e.hips.position.z,t.hips.position.z,n)},rotation:G(e.hips.rotation,t.hips.rotation,n)},spine:G(e.spine,t.spine,n),chest:G(e.chest,t.chest,n),leftUpperArm:G(e.leftUpperArm,t.leftUpperArm,n),leftLowerArm:G(e.leftLowerArm,t.leftLowerArm,n),rightUpperArm:G(e.rightUpperArm,t.rightUpperArm,n),rightLowerArm:G(e.rightLowerArm,t.rightLowerArm,n),leftUpperLeg:nt(e.leftUpperLeg,t.leftUpperLeg,n),leftLowerLeg:nt(e.leftLowerLeg,t.leftLowerLeg,n),rightUpperLeg:nt(e.rightUpperLeg,t.rightUpperLeg,n),rightLowerLeg:nt(e.rightLowerLeg,t.rightLowerLeg,n)}:t:null}function it(e,t,n){return t?e?{shoulderWidthPx:W(e.shoulderWidthPx,t.shoulderWidthPx,n),chestWidthPx:W(e.chestWidthPx,t.chestWidthPx,n),waistWidthPx:W(e.waistWidthPx,t.waistWidthPx,n),hipWidthPx:W(e.hipWidthPx,t.hipWidthPx,n)}:t:null}function at(){return{landmarks:null,worldLandmarks:null,poseRig:null,confidence:0,isTracking:!1,silhouetteWidths:null}}function ot(e,t,n){return!e||!e.isTracking||!t.isTracking||!t.landmarks?t:{landmarks:tt(e.landmarks,t.landmarks,n),worldLandmarks:tt(e.worldLandmarks,t.worldLandmarks,n),poseRig:rt(e.poseRig,t.poseRig,n),confidence:W(e.confidence,t.confidence,n),isTracking:t.isTracking,silhouetteWidths:it(e.silhouetteWidths,t.silhouetteWidths,n)}}var st=`0.10.32`,ct=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${st}/wasm`,lt=2,ut=3,dt=.5,ft={lite:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/latest/pose_landmarker_lite.task`,full:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_full/float16/latest/pose_landmarker_full.task`,heavy:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_heavy/float16/latest/pose_landmarker_heavy.task`};async function pt(e,t,n,r,i=3){let o=await a.FilesetResolver.forVisionTasks(ct),s={baseOptions:{modelAssetPath:e},runningMode:`VIDEO`,numPoses:i,outputSegmentationMasks:r,minPoseDetectionConfidence:t,minPosePresenceConfidence:n,minTrackingConfidence:n};try{return await a.PoseLandmarker.createFromOptions(o,{...s,baseOptions:{...s.baseOptions,delegate:`GPU`}})}catch{return a.PoseLandmarker.createFromOptions(o,{...s,baseOptions:{...s.baseOptions,delegate:`CPU`}})}}var mt=new o.Vector3,ht=new o.Vector3,gt=new o.Vector3,_t=new o.Quaternion,vt=new o.Vector3,yt=new o.Vector3,bt=new o.Vector3(0,-1,0),xt=new o.Vector3(1,0,0),St=new o.Vector3(-1,0,0),Ct=new o.Vector3(0,1,0),wt=[V.LEFT_SHOULDER,V.RIGHT_SHOULDER],Tt=[V.LEFT_HIP,V.RIGHT_HIP],Et=[V.LEFT_EAR,V.RIGHT_EAR],Dt=[V.LEFT_INDEX,V.LEFT_PINKY],Ot=[V.RIGHT_INDEX,V.RIGHT_PINKY],kt={Hips:{from:Tt,to:wt,restDir:Ct,influence:.35},Spine:{from:Tt,to:wt,restDir:Ct,influence:.55},Chest:{from:wt,to:Et,restDir:Ct,influence:.7},LeftShoulder:{from:wt,to:V.LEFT_SHOULDER,restDir:xt,influence:.45},LeftUpperArm:{from:V.LEFT_SHOULDER,to:V.LEFT_ELBOW,restDir:xt},LeftLowerArm:{from:V.LEFT_ELBOW,to:V.LEFT_WRIST,restDir:xt},LeftHand:{from:V.LEFT_WRIST,to:Dt,restDir:xt,influence:.65},RightShoulder:{from:wt,to:V.RIGHT_SHOULDER,restDir:St,influence:.45},RightUpperArm:{from:V.RIGHT_SHOULDER,to:V.RIGHT_ELBOW,restDir:St},RightLowerArm:{from:V.RIGHT_ELBOW,to:V.RIGHT_WRIST,restDir:St},RightHand:{from:V.RIGHT_WRIST,to:Ot,restDir:St,influence:.65},LeftUpperLeg:{from:V.LEFT_HIP,to:V.LEFT_KNEE,restDir:bt},LeftLowerLeg:{from:V.LEFT_KNEE,to:V.LEFT_ANKLE,restDir:bt},LeftFoot:{from:V.LEFT_ANKLE,to:V.LEFT_FOOT_INDEX,restDir:new o.Vector3(0,0,1)},RightUpperLeg:{from:V.RIGHT_HIP,to:V.RIGHT_KNEE,restDir:bt},RightLowerLeg:{from:V.RIGHT_KNEE,to:V.RIGHT_ANKLE,restDir:bt},RightFoot:{from:V.RIGHT_ANKLE,to:V.RIGHT_FOOT_INDEX,restDir:new o.Vector3(0,0,1)}};function At(e,t,n){return n===`world`?(t.set(-e.x,-e.y,-(e.z??0)),t):(t.set(-(e.x-.5),-(e.y-.5),-(e.z??0)*.5),t)}function jt(e,t,n,r){if(typeof e==`number`){let i=t[e];return!i||(i.visibility??0)<.4?!1:(At(i,n,r),!0)}let i=t[e[0]],a=t[e[1]];return!i||!a||(i.visibility??0)<.4||(a.visibility??0)<.4?!1:(At(i,vt,r),At(a,yt,r),n.copy(vt).add(yt).multiplyScalar(.5),!0)}function Mt(e,t,n,r,i=`normalized`){if(!jt(e,n,mt,i)||!jt(t,n,ht,i))return!1;r.subVectors(ht,mt);let a=r.length();return a<.001?!1:(r.divideScalar(a),!0)}function Nt(e,t,n,r=`normalized`){let i=kt[e];return i?Mt(i.from,i.to,t,n,r):!1}function Pt(e){return kt[e]?.influence}function Ft(e,t,n,r=`normalized`){let i=kt[e];return!i||!Nt(e,t,gt,r)?!1:(n.setFromUnitVectors(i.restDir,gt),i.influence!==void 0&&n.slerp(_t.identity(),1-i.influence),!0)}function It(e){return e in kt}var Lt=new o.Quaternion,Rt=new o.Euler;function zt(){return{x:0,y:0,z:0}}function Bt(e){return Rt.setFromQuaternion(e,`XYZ`),{x:Rt.x,y:Rt.y,z:Rt.z}}function K(e,t,n){return Ft(e,t,Lt,n)?Bt(Lt):zt()}function Vt(e,t,n){if(Ft(e,t,Lt,n))return Bt(Lt)}function Ht(e){let t=e[V.LEFT_HIP],n=e[V.RIGHT_HIP];return{x:((t?.x??0)+(n?.x??0))*.5,y:((t?.y??0)+(n?.y??0))*.5,z:((t?.z??0)+(n?.z??0))*.5}}function Ut(e,t){if(e.length<33)return null;let n=t&&t.length>=33?t:e,r=t&&t.length>=33?`world`:`normalized`;return{hips:{position:Ht(e),rotation:K(`Hips`,n,r)},spine:K(`Spine`,n,r),chest:K(`Chest`,n,r),leftUpperArm:K(`LeftUpperArm`,n,r),leftLowerArm:K(`LeftLowerArm`,n,r),rightUpperArm:K(`RightUpperArm`,n,r),rightLowerArm:K(`RightLowerArm`,n,r),leftUpperLeg:Vt(`LeftUpperLeg`,n,r),leftLowerLeg:Vt(`LeftLowerLeg`,n,r),rightUpperLeg:Vt(`RightUpperLeg`,n,r),rightLowerLeg:Vt(`RightLowerLeg`,n,r)}}function Wt(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.width!=`number`||typeof t.height!=`number`||typeof t.getAsFloat32Array!=`function`?null:t}function Gt(e){if(e)for(let t of e)t&&typeof t==`object`&&`close`in t&&typeof t.close==`function`&&t.close()}function Kt(e,t,n){let r=t/n;return{shoulderWidthPx:e.shoulderWidthPx*r,chestWidthPx:e.chestWidthPx*r,waistWidthPx:e.waistWidthPx*r,hipWidthPx:e.hipWidthPx*r}}var qt=`pose-0`;function Jt(e){return typeof e==`number`?e:0}function Yt(e){return{x:e.x,y:e.y,z:e.z,visibility:Jt(e.visibility)}}function Xt(e){return e.map(Yt)}function Zt(e){return Yt(e)}function Qt(e){let t=Math.PI*2,n=(e+Math.PI)%t;return n<0&&(n+=t),n-Math.PI}function $t(e,t,n){return Qt(e+Qt(t-e)*n)}var en=class{prev=null;config;constructor(e=Ae){this.config=e}smooth(e){if(e.length===0)return this.prev=null,[];let t=Xt(e);if(!this.prev||this.prev.length!==t.length)return this.prev=t.map(Zt),t.map(Zt);let n=this.config.positionAlpha,r=t.map((e,t)=>{let r=this.prev[t];return(e.visibility??0)<this.config.visibilityThreshold?{...Zt(r),visibility:e.visibility}:{x:r.x+n*(e.x-r.x),y:r.y+n*(e.y-r.y),z:r.z+n*(e.z-r.z),visibility:e.visibility}});return this.prev=r.map(Zt),r}reset(){this.prev=null}};function q(e,t,n){return{x:$t(e.x,t.x,n),y:$t(e.y,t.y,n),z:$t(e.z,t.z,n)}}function tn(e,t,n){return t?e?q(e,t,n):t:e}function nn(e,t,n=Ae.rotationAlpha){return e?{hips:{position:{x:e.hips.position.x+n*(t.hips.position.x-e.hips.position.x),y:e.hips.position.y+n*(t.hips.position.y-e.hips.position.y),z:e.hips.position.z+n*(t.hips.position.z-e.hips.position.z)},rotation:q(e.hips.rotation,t.hips.rotation,n)},spine:q(e.spine,t.spine,n),chest:q(e.chest,t.chest,n),leftUpperArm:q(e.leftUpperArm,t.leftUpperArm,n),leftLowerArm:q(e.leftLowerArm,t.leftLowerArm,n),rightUpperArm:q(e.rightUpperArm,t.rightUpperArm,n),rightLowerArm:q(e.rightLowerArm,t.rightLowerArm,n),leftUpperLeg:tn(e.leftUpperLeg,t.leftUpperLeg,n),leftLowerLeg:tn(e.leftLowerLeg,t.leftLowerLeg,n),rightUpperLeg:tn(e.rightUpperLeg,t.rightUpperLeg,n),rightLowerLeg:tn(e.rightLowerLeg,t.rightLowerLeg,n)}:t}var rn=.12,an=.35,on=.05,sn=[11,12,23,24],cn=2,ln=.3;function un(e){if(!e)return null;let t=Math.max(0,Math.min(1,e.x)),n=Math.max(0,Math.min(1,e.y));return{x:t,y:n,w:Math.max(.01,Math.min(1-t,e.w)),h:Math.max(.01,Math.min(1-n,e.h))}}function dn(e){if(!Array.isArray(e)||e.length===0)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0,a=0;return e.forEach(e=>{!e||typeof e.x!=`number`||typeof e.y!=`number`||(e.visibility??0)<an||(t=Math.min(t,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x),i=Math.max(i,e.y),a+=1)}),a<4||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)?null:un({x:t,y:n,w:Math.max(.01,r-t),h:Math.max(.01,i-n)})}function fn(e,t=rn){if(!e)return null;let n=e.w*t,r=e.h*t;return un({x:e.x-n/2,y:e.y-r/2,w:e.w+n,h:e.h+r})}function pn(e,t){if(!e||!t)return 0;let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.w,t.x+t.w),a=Math.min(e.y+e.h,t.y+t.h),o=Math.max(0,i-n)*Math.max(0,a-r);if(o<=0)return 0;let s=e.w*e.h+t.w*t.h-o;return s<=0?0:o/s}function mn(e){return e.length===0?0:e.reduce((e,t)=>e+(t.visibility??0),0)/e.length}function hn(e,t=[]){return e.flatMap((e,n)=>{let r=dn(e),i=fn(r);return!r||!i?[]:[{poseIndex:n,personId:`pose-${n}`,landmarks:e,worldLandmarks:t[n]??null,bounds:r,expandedBounds:i,meanVisibility:mn(e),area:i.w*i.h}]})}function gn(e,t){let n=pn(e.expandedBounds,t.expandedBounds);return{iou:n,score:n*.75+e.area*.25}}function _n(e,{previousCandidate:t,allowRelock:n=!1,minIouToKeep:r=on}){if(e.length===0)return null;let i=[...e].sort((e,t)=>t.area*t.meanVisibility-e.area*e.meanVisibility);if(!t)return i[0];let a=null,o=-1/0,s=0;return e.forEach(e=>{let{iou:n,score:r}=gn(e,t);r>o&&(a=e,o=r,s=n)}),a&&s>=r?a:n?i[0]:null}function vn(e,t){if(!t)return!0;let n=0,r=0,i=0;for(let t of sn){let a=e.landmarks[t];a&&(a.visibility??0)>ln&&(n+=a.x,r+=a.y,i+=1)}if(i<cn)return!0;let a=n/i,o=r/i;return a>=t.xMin&&a<=t.xMax&&o>=t.yMin&&o<=t.yMax}function yn(e,t){return t?e.filter(e=>vn(e,t)):e}function bn(e){return e?{poseIndex:e.poseIndex,personId:e.personId,bounds:e.bounds,expandedBounds:e.expandedBounds}:null}var xn=.55,Sn=640,Cn=360;function wn(e=null){return{level:`idle`,reasons:[`no_person_detected`],updatedAt:e}}function Tn({detectedPersonCount:e,isTracking:t,lockedPersonId:n=null,meanVisibility:r=null,frameWidth:i=0,frameHeight:a=0,updatedAt:o=Date.now()}){if(e<1)return wn(o);let s=[];return e>1&&s.push(`multi_person_detected`),i>0&&a>0&&(i<Sn||a<Cn)&&s.push(`resolution_too_low`),r!==null&&r<xn&&s.push(`low_visibility`),(!n||!t)&&s.push(`pose_not_locked`),s.length===0?{level:`good`,reasons:[],updatedAt:o}:{level:s.includes(`resolution_too_low`)?`blocked`:`degraded`,reasons:s,updatedAt:o}}function En(){return{detectedPersonCount:0,lockedPersonId:null,trackingQuality:wn()}}function Dn({detectedPersonCount:e,isTracking:t,lockedPersonId:n,meanVisibility:r,frameWidth:i,frameHeight:a,updatedAt:o}){let s=n??(t&&e>0?`pose-0`:null);return{detectedPersonCount:e,lockedPersonId:s,trackingQuality:Tn({detectedPersonCount:e,isTracking:t,lockedPersonId:s,meanVisibility:r,frameWidth:i,frameHeight:a,updatedAt:o})}}var On=180;function kn(e,t,n=180){return e===null?!1:t-e<=n}function An(e){return!e||!e.isTracking||!e.landmarks||!e.poseRig?null:{...e,isTracking:!0}}function jn(e,t,n=qt){return{detectedPersonCount:e,lockedPersonId:n,trackingQuality:{level:`degraded`,reasons:[`tracking_lost`],updatedAt:t}}}function Mn(){return{landmarks:null,worldLandmarks:null,poseRig:null,confidence:0,fps:0,isTracking:!1}}var Nn=(e,n={})=>{let{enabled:r=!0,modelComplexity:i=`lite`,numPoses:o=3,minDetectionConfidence:s=.5,minTrackingConfidence:c=.5,outputSegmentationMasks:l=!1,viewportWidth:u=0,viewportHeight:d=0}=n,f=(0,t.useRef)(null),p=(0,t.useRef)(new en(Ae)),m=(0,t.useRef)(null),h=(0,t.useRef)(null),g=(0,t.useRef)(null),_=(0,t.useRef)(-1),v=(0,t.useRef)({width:0,height:0}),y=(0,t.useRef)(0),b=(0,t.useRef)(null),x=(0,t.useRef)(null),S=(0,t.useRef)(null),C=(0,t.useRef)(null),w=(0,t.useRef)(null),T=(0,t.useRef)(En()),E=(0,t.useRef)({frames:0,lastMeasuredAt:0}),D=(0,t.useRef)(null),O=(0,t.useRef)({width:0,height:0}),[k,A]=(0,t.useState)(!1),[j,M]=(0,t.useState)(Mn),[ee,N]=(0,t.useState)(null),[P,F]=(0,t.useState)({width:0,height:0}),[I,L]=(0,t.useState)(En()),R=(0,t.useCallback)((e,t=T.current)=>{h.current=e.landmarks,T.current=t,M(t=>({...t,landmarks:e.landmarks,worldLandmarks:e.worldLandmarks,poseRig:e.poseRig,confidence:e.confidence,isTracking:e.isTracking})),N(e.silhouetteWidths),L(t)},[]),z=(0,t.useCallback)(()=>{p.current.reset(),m.current=null,h.current=null,_.current=-1,v.current={width:0,height:0},y.current=0,b.current=null,x.current=null,S.current=null,C.current=null,w.current=null,T.current=En(),E.current={frames:0,lastMeasuredAt:0},M(Mn()),N(null),F({width:0,height:0}),L(En())},[]);(0,t.useEffect)(()=>{if(!r){A(!1),z();return}let e=!1;async function t(){try{let t=await pt(ft[i],s,c,l,o);if(e){t.close();return}f.current=t,E.current.lastMeasuredAt=performance.now(),A(!0)}catch(e){console.error(`Failed to initialize MediaPipe Pose Landmarker:`,e)}}return t(),()=>{e=!0,A(!1),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),f.current?.close(),f.current=null,z()}},[r,s,c,i,o,l,z]),O.current={width:u,height:d},(0,t.useEffect)(()=>{if(!r||!k)return;let t=()=>{let n=e.current,r=f.current;if(!n||!r||n.readyState<HTMLMediaElement.HAVE_CURRENT_DATA){g.current=requestAnimationFrame(t);return}if(n.currentTime===_.current){g.current=requestAnimationFrame(t);return}_.current=n.currentTime;let i=n.videoWidth||n.clientWidth||1280,a=n.videoHeight||n.clientHeight||720;(i!==v.current.width||a!==v.current.height)&&(v.current={width:i,height:a},F({width:i,height:a}));let o=O.current;D.current=o.width>0&&o.height>0?Xe(o.width,o.height,i,a):null;let s=performance.now();try{let e=b.current===null||y.current===0;if(y.current=(y.current+1)%2,e){let e=r.detectForVideo(n,s);try{let t=yn(hn(e.landmarks,e.worldLandmarks),D.current),n=t.length,r=!kn(C.current,s),o=_n(t,{previousCandidate:w.current,allowRelock:r}),u=o?.landmarks??null,d=o?.worldLandmarks??null,f=o||w.current?qt:null,h=at(),g=Dn({detectedPersonCount:n,isTracking:!1,lockedPersonId:f,frameWidth:i,frameHeight:a,updatedAt:s}),_=kn(C.current,s)?An(S.current):null;if(!u)_?(h=_,g=jn(n,s,f)):(p.current.reset(),m.current=null,S.current=null,C.current=null,w.current=null,g=Dn({detectedPersonCount:n,isTracking:!1,lockedPersonId:null,frameWidth:i,frameHeight:a,updatedAt:s}));else{r&&o&&(p.current.reset(),m.current=null);let t=p.current.smooth(Xt(u)),v=d?Xt(d):null,y=Ut(t,v),b=t.reduce((e,t)=>e+(t.visibility??0),0)/t.length,x=b>=c?y?nn(m.current,y,Ae.rotationAlpha):m.current:null,T=x!==null,E=null;if(w.current=o?bn(o):w.current,l){let n=Wt(o?e.segmentationMasks?.[o.poseIndex]:void 0);if(n){let e=et(new Float32Array(n.getAsFloat32Array()),n.width,n.height,t);e&&(E=Kt(e,i,n.width))}}T&&x?(m.current=x,h={landmarks:t,worldLandmarks:v,poseRig:x,confidence:b,isTracking:T,silhouetteWidths:E},S.current=h,C.current=s,g=Dn({detectedPersonCount:n,isTracking:T,lockedPersonId:qt,meanVisibility:o?.meanVisibility??b,frameWidth:i,frameHeight:a,updatedAt:s})):_?(h=_,g=jn(n,s,f)):(m.current=null,S.current=null,C.current=null,h={landmarks:t,worldLandmarks:v,poseRig:null,confidence:b,isTracking:!1,silhouetteWidths:E},g=Dn({detectedPersonCount:n,isTracking:!1,lockedPersonId:o?qt:null,meanVisibility:o?.meanVisibility??b,frameWidth:i,frameHeight:a,updatedAt:s}))}let v=b.current;b.current=h,T.current=g;let y=ot(v,h,dt);x.current=y,R(y,g)}finally{Gt(e.segmentationMasks)}}else x.current&&R(x.current,T.current)}catch{}let u=E.current;if(u.frames+=1,u.lastMeasuredAt===0&&(u.lastMeasuredAt=s),s-u.lastMeasuredAt>=1e3){let e=u.frames;u.frames=0,u.lastMeasuredAt=s,M(t=>({...t,fps:e}))}g.current=requestAnimationFrame(t)};return g.current=requestAnimationFrame(t),()=>{g.current!==null&&(cancelAnimationFrame(g.current),g.current=null)}},[r,k,c,l,R,e]);let B=(0,t.useCallback)(t=>{let n=e.current,r=t.getContext(`2d`);if(!n||!r)return;t.width=n.videoWidth||t.clientWidth||1280,t.height=n.videoHeight||t.clientHeight||720,r.clearRect(0,0,t.width,t.height);let i=h.current;if(!i)return;let o=Xt(i),s=new a.DrawingUtils(r);s.drawLandmarks(o,{radius:3,color:`#00FF88`,fillColor:`#00FF88`}),s.drawConnectors(o,a.PoseLandmarker.POSE_CONNECTIONS,{color:`#00C8FF`,lineWidth:2})},[e]);return{...j,isTrackerReady:k,drawLandmarks:B,silhouetteWidths:ee,poseFrameWidth:P.width,poseFrameHeight:P.height,detectedPersonCount:I.detectedPersonCount,lockedPersonId:I.lockedPersonId,trackingQuality:I.trackingQuality}};function Pn(e){if(!(e instanceof DOMException))return`Failed to start the camera.`;switch(e.name){case`NotAllowedError`:return`Camera permission was denied.`;case`NotFoundError`:return`No available camera was found.`;case`NotReadableError`:return`The camera is already in use by another app.`;case`OverconstrainedError`:return`The requested camera settings are not supported.`;default:return`Failed to start the camera.`}}function Fn(e={}){let{width:n=1280,height:r=720,facingMode:i=`user`,enabled:a=!0,mockMode:o=!1,videoRef:s,onReadyChange:c,onErrorChange:l}=e,u=(0,t.useRef)(null),d=(0,t.useMemo)(()=>({get current(){return u.current},set current(e){u.current=e,s&&(s.current=e)}}),[s]),f=(0,t.useRef)(null),p=(0,t.useRef)(!1),m=(0,t.useRef)(0),[h,g]=(0,t.useState)(!1),[_,v]=(0,t.useState)(null),y=(0,t.useCallback)(e=>{g(e),c?.(e)},[c]),b=(0,t.useCallback)(e=>{v(e),l?.(e)},[l]),x=(0,t.useCallback)(()=>{f.current&&=(f.current.getTracks().forEach(e=>e.stop()),null),d.current&&(d.current.pause(),d.current.srcObject=null),y(!1)},[y,d]),S=(0,t.useCallback)(()=>{m.current+=1,x()},[x]),C=(0,t.useCallback)(()=>{if(d.current)return d.current;let e=document.createElement(`video`);return e.playsInline=!0,e.autoplay=!0,e.muted=!0,e.setAttribute(`playsinline`,`true`),d.current=e,e},[d]),w=(0,t.useCallback)(async()=>{let e=m.current+1;if(m.current=e,x(),b(null),o){C(),y(!0);return}if(!navigator.mediaDevices?.getUserMedia){b(`This browser does not support camera access.`);return}try{let t=C(),a=await navigator.mediaDevices.getUserMedia({video:{width:n,height:r,facingMode:i},audio:!1});if(!p.current||m.current!==e){a.getTracks().forEach(e=>e.stop());return}if(f.current=a,t.srcObject=a,await t.play(),!p.current||m.current!==e){a.getTracks().forEach(e=>e.stop());return}y(!0)}catch(t){if(m.current!==e)return;x(),b(Pn(t))}},[C,i,r,o,b,y,x,n]);return(0,t.useEffect)(()=>(p.current=!0,()=>{p.current=!1,S()}),[S]),(0,t.useEffect)(()=>{if(p.current){if(!a){S();return}w()}},[a,w,S]),{videoRef:d,isReady:h,error:_,start:w,stop:S}}function In(e={}){let{width:n=1280,height:r=720,facingMode:i=`user`,enabled:a=!0,mockMode:o=!1,modelComplexity:s=`lite`,numPoses:c,minDetectionConfidence:l,minTrackingConfidence:u,outputSegmentationMasks:d=!0,viewportWidth:f=0,viewportHeight:p=0,measurementEnabled:m=!0,autoStartMeasurement:h=!1,measurementConfig:g,bodyPresetOptions:_,fitType:v=`regular`,garmentScaleHint:y=null}=e,b=Fn({width:n,height:r,facingMode:i,enabled:a,mockMode:o}),x=Nn(b.videoRef,{enabled:a,modelComplexity:s,numPoses:c,minDetectionConfidence:l,minTrackingConfidence:u,outputSegmentationMasks:d,viewportWidth:f,viewportHeight:p}),{config:S,measurements:C,sizeRecommendation:w,garmentScale:T,isMeasuring:E,measure:D,startMeasurement:O,updateConfig:k}=Je(),A=a&&b.isReady&&x.isTracking,j=ke(C,_),M=(0,t.useMemo)(()=>ce({measurements:C,measurementScale:T,presetSelection:j.selection,fitType:v,garmentScaleHint:y}),[j.selection,v,T,y,C]);return(0,t.useEffect)(()=>{g&&k(g)},[g,k]),(0,t.useEffect)(()=>{!m||!h||!A||C||E||O()},[h,A,m,C,E,O]),(0,t.useEffect)(()=>{!m||!E||!x.landmarks||D(x.landmarks,{silhouetteWidths:x.silhouetteWidths,imageWidth:x.poseFrameWidth||n,imageHeight:x.poseFrameHeight||r})},[r,m,E,D,x.landmarks,x.poseFrameHeight,x.poseFrameWidth,x.silhouetteWidths,n]),(0,t.useMemo)(()=>({videoRef:b.videoRef,webcamReady:b.isReady,webcamError:b.error,startWebcam:b.start,stopWebcam:b.stop,isTrackerReady:x.isTrackerReady,landmarks:x.landmarks,worldLandmarks:x.worldLandmarks,poseRig:x.poseRig,confidence:x.confidence,fps:x.fps,isTracking:x.isTracking,drawLandmarks:x.drawLandmarks,silhouetteWidths:x.silhouetteWidths,poseFrameWidth:x.poseFrameWidth,poseFrameHeight:x.poseFrameHeight,detectedPersonCount:x.detectedPersonCount,lockedPersonId:x.lockedPersonId,trackingQuality:x.trackingQuality,config:S,measurements:C,sizeRecommendation:w,garmentScale:T,finalGarmentScale:M.scale,bodyMorphResult:M.morph,isMeasuring:E,canMeasure:A,startMeasurement:O,updateConfig:k,bodyPresetSelection:j.selection,bodyPresetLoading:j.loading,bodyPresetError:j.error}),[M.morph,M.scale,j.error,j.loading,j.selection,A,S,T,E,C,w,O,x.confidence,x.detectedPersonCount,x.drawLandmarks,x.fps,x.isTrackerReady,x.isTracking,x.landmarks,x.lockedPersonId,x.poseFrameHeight,x.poseFrameWidth,x.poseRig,x.silhouetteWidths,x.trackingQuality,x.worldLandmarks,k,b.error,b.isReady,b.start,b.stop,b.videoRef])}function Ln(e){let t=new o.Vector3,n=new o.Quaternion,r=new o.Quaternion;return e.updateWorldMatrix(!0,!1),e.getWorldPosition(t),e.getWorldQuaternion(n),e.parent?e.parent.getWorldQuaternion(r):r.identity(),{bone:e,restQuaternion:e.quaternion.clone(),restScale:e.scale.clone(),restWorldPosition:t,restWorldQuaternion:n,restParentWorldQuaternion:r}}function Rn(e){let t=new o.Box3,n={current:!1},r=new o.Vector3,i=new o.Box3;return e.updateMatrixWorld(!0),e.traverse(e=>{if(!(e instanceof o.Mesh)||e.name.startsWith(`Collision`)||!e.visible)return;let a=e.geometry.getAttribute(`skinIndex`)&&e.geometry.getAttribute(`skinWeight`);if(e instanceof o.SkinnedMesh&&a){if(e.computeBoundingBox(),!e.boundingBox)return;i.copy(e.boundingBox)}else{if(e.geometry.computeBoundingBox(),!e.geometry.boundingBox)return;i.copy(e.geometry.boundingBox)}let{min:s,max:c}=i;[[s.x,s.y,s.z],[s.x,s.y,c.z],[s.x,c.y,s.z],[s.x,c.y,c.z],[c.x,s.y,s.z],[c.x,s.y,c.z],[c.x,c.y,s.z],[c.x,c.y,c.z]].forEach(([i,a,o])=>{if(r.set(i,a,o).applyMatrix4(e.matrixWorld),!n.current){t.min.copy(r),t.max.copy(r),n.current=!0;return}t.expandByPoint(r)})}),n.current||t.makeEmpty(),t}function zn(e){if(!e||e.length===0)return null;let t=new o.Vector3,n=new o.Vector3;return e.forEach(({bone:e})=>{e.getWorldPosition(n),t.add(n)}),t.multiplyScalar(1/e.length)}function Bn(e,t){for(let n=0;n<t.length;n+=1){let r=zn(e.get(t[n]));if(r)return r}return null}function Vn(e,t,n=1){e.updateMatrixWorld(!0);let r=Rn(e),i=r.getCenter(new o.Vector3),a=r.getSize(new o.Vector3),s=new o.Vector3(i.x,r.min.y+a.y*.74,i.z),c=new o.Vector3(i.x,r.min.y+a.y*.42,i.z),l=Bn(t,[`LeftUpperArm`,`LeftShoulder`]),u=Bn(t,[`RightUpperArm`,`RightShoulder`]),d=Bn(t,[`Hips`]),f=Bn(t,[`LeftUpperLeg`]),p=Bn(t,[`RightUpperLeg`]),m=l??s.clone().setX(i.x+a.x*.18),h=u??s.clone().setX(i.x-a.x*.18),g=d??c,_=m.clone().add(h).multiplyScalar(.5),v=f&&p?f.clone().add(p).multiplyScalar(.5):g.clone(),y=!!(l&&u),b=y&&!!(d||f&&p),x=m.distanceTo(h),S=_.distanceTo(v),C=y?Math.max(x,1e-4):Math.max(x,a.x*.3,n),w=b?Math.max(S,1e-4):Math.max(S,a.y*.28,1e-4),T=b?_.clone().add(v).multiplyScalar(.5):i.clone(),E=r.clone();if(b){let e=Math.min(_.y,v.y),t=Math.max(_.y,v.y);E.min.y=Math.max(E.min.y,e),E.max.y=Math.min(E.max.y,t),E.max.y<=E.min.y&&E.copy(r)}let D=E.getCenter(new o.Vector3),O=E.getSize(new o.Vector3);return{anchor:T,shoulderCenter:_,hipCenter:v,referenceWidth:C,referenceTorsoHeight:w,trackingHeight:Math.max(a.y,w,1e-4),boundsCenter:D,boundsSize:O,hasBoneAnchors:b}}function Hn(e){for(let t of e.values())t.forEach(({bone:e,restQuaternion:t,restScale:n})=>{e.quaternion.copy(t),e.scale.copy(n)})}var Un=`__nativeVRMPrepared`;function Wn(e){try{return new URL(e,`https://avatar.local`).pathname}catch{return e}}function Gn(e){return Wn(e).toLowerCase().endsWith(`.vrm`)}function Kn(e){return Gn(e)?`vrm`:`gltf`}function qn(e,t){Gn(t)&&e.register(e=>new c.VRMLoaderPlugin(e))}function Jn(e){if(Gn(e))return t=>{qn(t,e)}}function Yn(e){e.traverse(e=>{e.frustumCulled=!1})}function Xn(e){let t=e.scene.userData;t[Un]||(c.VRMUtils.rotateVRM0(e),t[Un]=!0),Yn(e.scene)}var Zn={Hips:[`hips`],Spine:[`spine`],Chest:[`chest`,`upperChest`],Neck:[`neck`],Head:[`head`],LeftShoulder:[`leftShoulder`],LeftUpperArm:[`leftUpperArm`],LeftLowerArm:[`leftLowerArm`],LeftHand:[`leftHand`],RightShoulder:[`rightShoulder`],RightUpperArm:[`rightUpperArm`],RightLowerArm:[`rightLowerArm`],RightHand:[`rightHand`],LeftUpperLeg:[`leftUpperLeg`],LeftLowerLeg:[`leftLowerLeg`],LeftFoot:[`leftFoot`],RightUpperLeg:[`rightUpperLeg`],RightLowerLeg:[`rightLowerLeg`],RightFoot:[`rightFoot`]};function Qn(e){let t=new Map;return Object.entries(Zn).forEach(([n,r])=>{for(let i=0;i<r.length;i+=1){let a=e.getNormalizedBoneNode(r[i]);if(a){t.set(n,[Ln(a)]);break}}}),t}var $n={root:`hips`,c_spine0:`spine`,c_spine1:`spine`,c_spine2:`chest`,c_spine3:`upperChest`,c_neck:`neck`,c_head:`head`,l_clavicle:`leftShoulder`,l_uparm:`leftUpperArm`,l_lowarm:`leftLowerArm`,l_wrist:`leftHand`,r_clavicle:`rightShoulder`,r_uparm:`rightUpperArm`,r_lowarm:`rightLowerArm`,r_wrist:`rightHand`,l_upleg:`leftUpperLeg`,l_lowleg:`leftLowerLeg`,l_foot:`leftFoot`,r_upleg:`rightUpperLeg`,r_lowleg:`rightLowerLeg`,r_foot:`rightFoot`},er={bone_0:`hips`,bone_1:`spine`,bone_2:`chest`,bone_3:`upperChest`,bone_4:`neck`,bone_5:`head`,bone_6:`leftShoulder`,bone_7:`leftUpperArm`,bone_8:`leftLowerArm`,bone_9:`leftHand`,bone_25:`rightShoulder`,bone_26:`rightUpperArm`,bone_27:`rightLowerArm`,bone_28:`rightHand`,bone_44:`leftUpperLeg`,bone_45:`leftLowerLeg`,bone_46:`leftFoot`,bone_48:`rightUpperLeg`,bone_49:`rightLowerLeg`,bone_50:`rightFoot`},tr={Root:`hips`,Hips:`hips`,Spine:`spine`,Chest:`chest`,Neck:`neck`,Head:`head`,LeftShoulder:`leftShoulder`,LeftUpperArm:`leftUpperArm`,LeftLowerArm:`leftLowerArm`,LeftHand:`leftHand`,RightShoulder:`rightShoulder`,RightUpperArm:`rightUpperArm`,RightLowerArm:`rightLowerArm`,RightHand:`rightHand`,LeftUpperLeg:`leftUpperLeg`,LeftLowerLeg:`leftLowerLeg`,LeftFoot:`leftFoot`,RightUpperLeg:`rightUpperLeg`,RightLowerLeg:`rightLowerLeg`,RightFoot:`rightFoot`};function nr(e,t){if(t?.humanoid)return{getNormalizedBoneNode:e=>t.humanoid.getNormalizedBoneNode(e)??null,update:e=>t.update(e),vrm:t};let n=new Map;return e.traverse(e=>{if(!(e instanceof o.Bone))return;let t=e.name,r=$n[t];r&&!n.has(r)&&n.set(r,e);let i=tr[t];i&&!n.has(i)&&n.set(i,e);let a=er[t];a&&!n.has(a)&&n.set(a,e)}),{getNormalizedBoneNode:e=>n.get(e)??null,update:()=>{},vrm:null}}function rr(e){let t=(0,s.clone)(e);return Yn(t),t.traverse(e=>{if(e instanceof o.Mesh){if(Array.isArray(e.material)){e.material=e.material.map(e=>e.clone());return}e.material=e.material.clone()}}),t}function ir({url:e}){let n=(0,r.useGLTF)(e,`/draco/`,!0,(0,t.useMemo)(()=>Jn(e),[e])),i=n.userData?.vrm??null,a=(0,t.useMemo)(()=>i?(Xn(i),i.scene):rr(n.scene),[n.scene,i]),o=(0,t.useMemo)(()=>nr(a,i),[a,i]);return{scene:a,humanoid:o,bones:(0,t.useMemo)(()=>Qn(o),[o])}}var J=Math.PI/180,ar={min:-70*J,max:70*J},or={min:-45*J,max:45*J},sr={min:-150*J,max:150*J},cr={min:-90*J,max:90*J},lr={min:0,max:150*J},ur={Hips:{rigKey:`hips`,rotationScale:{x:.7,y:.3,z:.7}},Spine:{rigKey:`spine`,rotationScale:{x:.85,y:.4,z:.85}},Chest:{rigKey:`chest`,rotationScale:{x:.75,y:.35,z:.75}},Neck:{rigKey:null},Head:{rigKey:null},LeftShoulder:{rigKey:`leftUpperArm`,rotationScale:.45,rotationLimits:{x:ar,z:or}},LeftUpperArm:{rigKey:`leftUpperArm`,rotationScale:1,rotationLimits:{x:sr,z:cr}},LeftLowerArm:{rigKey:`leftLowerArm`,rotationScale:1,rotationLimits:{x:lr}},LeftHand:{rigKey:`leftLowerArm`,rotationScale:.5},RightShoulder:{rigKey:`rightUpperArm`,rotationScale:.45,rotationLimits:{x:ar,z:or}},RightUpperArm:{rigKey:`rightUpperArm`,rotationScale:1,rotationLimits:{x:sr,z:cr}},RightLowerArm:{rigKey:`rightLowerArm`,rotationScale:1,rotationLimits:{x:lr}},RightHand:{rigKey:`rightLowerArm`,rotationScale:.5},LeftUpperLeg:{rigKey:`leftUpperLeg`,rotationScale:.9},LeftLowerLeg:{rigKey:`leftLowerLeg`,rotationScale:.9},LeftFoot:{rigKey:null},RightUpperLeg:{rigKey:`rightUpperLeg`,rotationScale:.9},RightLowerLeg:{rigKey:`rightLowerLeg`,rotationScale:.9},RightFoot:{rigKey:null}},dr={Root:`Hips`,root:`Hips`,c_spine0:`Spine`,c_spine1:`Spine`,c_spine2:`Chest`,c_spine3:`Chest`,c_neck:`Neck`,c_head:`Head`,l_clavicle:`LeftShoulder`,l_uparm:`LeftUpperArm`,l_lowarm:`LeftLowerArm`,l_wrist:`LeftHand`,r_clavicle:`RightShoulder`,r_uparm:`RightUpperArm`,r_lowarm:`RightLowerArm`,r_wrist:`RightHand`,l_upleg:`LeftUpperLeg`,l_lowleg:`LeftLowerLeg`,l_foot:`LeftFoot`,r_upleg:`RightUpperLeg`,r_lowleg:`RightLowerLeg`,r_foot:`RightFoot`,mixamorig_Hips:`Hips`,mixamorig_Spine:`Spine`,mixamorig_Spine1:`Chest`,mixamorig_Neck:`Neck`,mixamorig_Head:`Head`,mixamorig_LeftShoulder:`LeftShoulder`,mixamorig_LeftArm:`LeftUpperArm`,mixamorig_LeftForeArm:`LeftLowerArm`,mixamorig_LeftHand:`LeftHand`,mixamorig_RightShoulder:`RightShoulder`,mixamorig_RightArm:`RightUpperArm`,mixamorig_RightForeArm:`RightLowerArm`,mixamorig_RightHand:`RightHand`,mixamorig_LeftUpLeg:`LeftUpperLeg`,mixamorig_LeftLeg:`LeftLowerLeg`,mixamorig_LeftFoot:`LeftFoot`,mixamorig_RightUpLeg:`RightUpperLeg`,mixamorig_RightLeg:`RightLowerLeg`,mixamorig_RightFoot:`RightFoot`};function fr(e){return ur[e]?e:dr[e]??e}function pr(e,t){let n=ur[fr(e)];if(!n||!n.rigKey)return null;let r=t[n.rigKey];if(!r)return null;let i=mr(n.rigKey===`hips`&&`rotation`in r?r.rotation:r,n.rotationScale);return{x:hr(i.x,n.rotationLimits?.x),y:hr(i.y,n.rotationLimits?.y),z:hr(i.z,n.rotationLimits?.z)}}function mr(e,t=1){return typeof t==`number`?{x:e.x*t,y:e.y*t,z:e.z*t}:{x:e.x*(t.x??1),y:e.y*(t.y??1),z:e.z*(t.z??1)}}function hr(e,t){return t?Math.min(t.max,Math.max(t.min,e)):e}var gr=12,_r=new o.Quaternion,Y=new o.Quaternion,vr=new o.Quaternion,yr=new o.Vector3,br=new o.Vector3,X=new o.Vector3,xr=new o.Vector3,Sr=new o.Vector3,Cr=new o.Vector3,wr=new o.Vector3,Tr=new o.Vector3,Er=new o.Vector3,Dr=new o.Quaternion,Or=new o.Quaternion,kr=new o.Quaternion,Ar=new o.Quaternion,jr={Hips:[`Spine`,`Chest`,`Neck`],Spine:[`Chest`,`Neck`],Chest:[`Neck`,`Head`],Neck:[`Head`],LeftShoulder:[`LeftUpperArm`],LeftUpperArm:[`LeftLowerArm`],LeftLowerArm:[`LeftHand`],RightShoulder:[`RightUpperArm`],RightUpperArm:[`RightLowerArm`],RightLowerArm:[`RightHand`],LeftUpperLeg:[`LeftLowerLeg`],LeftLowerLeg:[`LeftFoot`],RightUpperLeg:[`RightLowerLeg`],RightLowerLeg:[`RightFoot`]},Mr={Hips:[[`LeftUpperLeg`,`RightUpperLeg`],[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`]],Spine:[[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`],[`LeftUpperLeg`,`RightUpperLeg`]],Chest:[[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`],[`LeftUpperLeg`,`RightUpperLeg`]]},Nr={Hips:[V.RIGHT_HIP,V.LEFT_HIP],Spine:[V.RIGHT_SHOULDER,V.LEFT_SHOULDER],Chest:[V.RIGHT_SHOULDER,V.LEFT_SHOULDER]};function Pr(e){return e.startsWith(`Left`)?`Right${e.slice(4)}`:e.startsWith(`Right`)?`Left${e.slice(5)}`:e}function Fr(e,t,n,r){let i=jr[e];if(!i)return!1;for(let e=0;e<i.length;e+=1){let a=n.get(i[e])?.[0];if(!(!a||a.bone===t.bone||!t.restWorldPosition||!t.restParentWorldQuaternion||!a.restWorldPosition)&&(r.copy(a.restWorldPosition).sub(t.restWorldPosition),!(r.lengthSq()<1e-6)))return r.applyQuaternion(Dr.copy(t.restParentWorldQuaternion).invert()).normalize(),!0}return!1}function Ir(e){return e in Mr}function Lr(e,t,n,r){let i=Mr[e];if(!i||!t.restParentWorldQuaternion)return!1;for(let e=0;e<i.length;e+=1){let[a,o]=i[e],s=n.get(a)?.[0],c=n.get(o)?.[0];if(!(!s?.restWorldPosition||!c?.restWorldPosition)&&(r.copy(c.restWorldPosition).sub(s.restWorldPosition).applyQuaternion(Dr.copy(t.restParentWorldQuaternion).invert()),!(r.lengthSq()<1e-6)))return r.normalize(),!0}return!1}function Rr(e,t,n,r,i){let a=Nr[e];return!a||!Mt(a[0],a[1],t,i,n)?!1:(i.applyQuaternion(kr.copy(r).invert()).normalize(),i.lengthSq()>=1e-6)}function zr(e,t,n,r,i,a,o,s){if(!Lr(e,t,n,xr)||!Rr(e,r,i,a,Sr)||(Cr.copy(xr).applyQuaternion(Y),wr.copy(Cr).projectOnPlane(X).normalize(),Tr.copy(Sr).projectOnPlane(X).normalize(),wr.lengthSq()<1e-6||Tr.lengthSq()<1e-6))return s.copy(Y),!1;Er.crossVectors(wr,Tr);let c=Math.atan2(X.dot(Er),wr.dot(Tr));return Ar.setFromAxisAngle(X,c),s.copy(Ar).multiply(Y),o!==void 0&&s.slerp(vr,1-o),!0}function Br(){let e=(0,t.useRef)(new o.Timer),n=(0,t.useRef)(new Map);return(0,t.useMemo)(()=>({clockRef:e,prevRotationsRef:n}),[])}function Vr(e,t,n,r={}){if(t.size===0)return;let{coordinateSpace:i=`normalized`,excludeBones:a}=r;n.clockRef.current.update();let o=n.clockRef.current.getDelta(),s=Math.min(1,o*gr);for(let[n,r]of t){let o=fr(n);if(a?.has(o))continue;let c=Pr(o);if(o!==n&&t.has(o))continue;let l=It(c);if(!l)continue;let u=l&&Nt(c,e,yr,i);if(!u)continue;let d=!1,f=Pt(c);for(let n of r){let{bone:r,restQuaternion:a}=n;if(u&&Fr(o,n,t,br))r.parent?(r.parent.updateWorldMatrix(!0,!1),r.parent.getWorldQuaternion(Or)):(r.updateWorldMatrix(!0,!1),Or.identity()),X.copy(yr).applyQuaternion(kr.copy(Or).invert()).normalize(),Y.setFromUnitVectors(br,X),Ir(o)&&zr(o,n,t,e,i,Or,f,Y)||f!==void 0&&Y.slerp(vr,1-f),_r.copy(Y).multiply(a);else{if(d||=Ft(c,e,Y,i),!d)continue;_r.copy(a).multiply(Y)}r.quaternion.slerp(_r,s),r.updateWorldMatrix(!1,!0)}}}function Hr(e,t){Hn(e),t.prevRotationsRef.current.clear()}function Ur(e,t,n,r){let i=Math.min(1,n*gr);for(let[n,a]of e){let e=fr(n);if(!(r&&!r.has(e)))for(let{bone:e,restQuaternion:n}of a)e.quaternion.slerp(n,t*i)}}var Wr=50*Math.PI/180,Gr=30*Math.PI/180,Kr=3;function qr(e){return Math.abs(e)<Wr?`unknown`:e>=0?`positive`:`negative`}function Jr(e){return e===`positive`?1:e===`negative`?-1:0}var Yr=class{_committedYawDirection=`unknown`;_pendingYawDirection=`unknown`;_pendingCount=0;update(e,t){let n=Math.abs(t),r=qr(t);return e===`back`||n<Gr?(this.reset(),this._buildState(r,`unknown`,t)):this._committedYawDirection===`unknown`?r===`unknown`?(this._clearPending(),this._buildState(r,`unknown`,t)):(this._pendingYawDirection===r?this._pendingCount+=1:(this._pendingYawDirection=r,this._pendingCount=1),this._pendingCount>=Kr?(this._committedYawDirection=this._pendingYawDirection,this._clearPending(),this._buildState(r,this._committedYawDirection,n*Jr(this._committedYawDirection))):this._buildState(r,r,t)):this._buildState(r,this._committedYawDirection,n*Jr(this._committedYawDirection))}reset(){this._committedYawDirection=`unknown`,this._clearPending()}_buildState(e,t,n){return{rawYawDirection:e,yawDirection:t,committedYawDirection:this._committedYawDirection,pendingYawDirection:this._pendingYawDirection,pendingCount:this._pendingCount,stableYaw:n}}_clearPending(){this._pendingYawDirection=`unknown`,this._pendingCount=0}},Xr=80*Math.PI/180,Zr=100*Math.PI/180,Qr=25*Math.PI/180,$r=8,ei=5,ti=5,ni=5,ri=.5,ii=.3,ai=.2,oi=5,si=8;function ci(e){return e?.visibility??0}function li(e){if(!e||e.length<33)return{shoulderOrder:!1,noseVisible:!1,earSymmetry:!1};let t=e[V.LEFT_SHOULDER],n=e[V.RIGHT_SHOULDER],r=e[V.NOSE],i=e[V.LEFT_EAR],a=e[V.RIGHT_EAR],o=t.x<n.x,s=ci(r)>ri,c=ci(i),l=ci(a);return{shoulderOrder:o,noseVisible:s,earSymmetry:Math.abs(c-l)<ii&&Math.max(c,l)>ai}}function ui(e){let t=0;return e.shoulderOrder&&(t+=1),e.noseVisible&&(t+=1),e.earSymmetry&&(t+=1),t>=2}function di(e){return e<Xr?`front`:e<Zr?`side`:`back`}var fi=class{_zone=`front`;_consecutiveCount=0;_lastRawZone=`front`;_2dFrontCount=0;_2dBackCount=0;_2dIsFront=!0;_yawDirectionStabilizer=new Yr;update(e,t,n){let r=t??0,i=n??0,a=Math.abs(i)>Qr,o;t===void 0?o=this._resolve2dFallback(e):(o=di(Math.abs(t)),o===`front`&&this._zone!==`front`&&(ui(li(e))||(o=`back`))),this._applyHysteresis(o);let s=t===void 0?null:this._yawDirectionStabilizer.update(this._zone,r);return t===void 0&&this._yawDirectionStabilizer.reset(),{zone:this._zone,rawZone:o,isFrontFacing:this._zone===`front`,pitchClamped:a,bodyYaw:s?.stableYaw??r,bodyPitch:i,rawYawDirection:s?.rawYawDirection??`unknown`,yawDirection:s?.yawDirection??`unknown`,committedYawDirection:s?.committedYawDirection??`unknown`}}reset(){this._zone=`front`,this._consecutiveCount=0,this._lastRawZone=`front`,this._2dFrontCount=0,this._2dBackCount=0,this._2dIsFront=!0,this._yawDirectionStabilizer.reset()}_resolve2dFallback(e){return ui(li(e))?(this._2dFrontCount+=1,this._2dBackCount=0):(this._2dBackCount+=1,this._2dFrontCount=0),this._2dIsFront?this._2dBackCount>=oi&&(this._2dIsFront=!1):this._2dFrontCount>=si&&(this._2dIsFront=!0),this._2dIsFront?`front`:`back`}_applyHysteresis(e){e===this._lastRawZone?this._consecutiveCount+=1:(this._lastRawZone=e,this._consecutiveCount=1);let t=this._getTransitionThreshold(this._zone,e);t!==null&&this._consecutiveCount>=t&&(this._zone=e)}_getTransitionThreshold(e,t){return e===t?null:e===`front`&&t===`side`||e===`front`&&t===`back`?$r:e===`side`&&t===`back`?ei:e===`back`&&t===`side`?ti:e===`side`&&t===`front`?ni:e===`back`&&t===`front`?ti:$r}},pi=Math.PI/2;function mi(e){return e>=0?pi:-pi}var hi=class{_isFrozen=!1;_frozenYaw=null;update(e,t){let n=Math.abs(t);return this._isFrozen?e!==`back`&&n<pi&&this.reset():e!==`front`&&n>=pi&&(this._isFrozen=!0,this._frozenYaw=mi(t)),{isFrozen:this._isFrozen,frozenYaw:this._frozenYaw}}reset(){this._isFrozen=!1,this._frozenYaw=null}};function gi(e,t){return typeof e==`boolean`?{mirrorX:e,sourceWidth:0,sourceHeight:0,target:t??new o.Vector3}:{mirrorX:e.mirrorX??!1,sourceWidth:e.sourceWidth??0,sourceHeight:e.sourceHeight??0,target:e.target??t??new o.Vector3}}function Z(e,t,n,r=!1,i){let a=gi(r,i),o=Ye(t,n,a.sourceWidth||t,a.sourceHeight||n),s=a.mirrorX?1-e.x:e.x,c=o.x+s*o.width,l=o.y+e.y*o.height,u=c-t*.5,d=n*.5-l,f=-(e.z??0)*o.width*.5;return a.target.set(u,d,f)}function _i(e,t,n,r,i=!1,a){return Z({x:(e.x+t.x)/2,y:(e.y+t.y)/2,z:((e.z??0)+(t.z??0))/2,visibility:Math.min(e.visibility??0,t.visibility??0)},n,r,i,a)}function vi(e,t,n,r){let i=(e.x-t.x)*n,a=(e.y-t.y)*r;return Math.sqrt(i*i+a*a)}var yi=.45,bi=.72,xi=1.02,Si=1.1,Ci=Math.PI/6,wi=1e-4,Ti=wi*wi,Ei=.35,Di=.6,Oi=new o.Vector3,ki=new o.Vector3,Q=new o.Vector3,$=new o.Vector3,Ai=new o.Vector3,ji=new o.Vector3,Mi=new o.Matrix4;function Ni(e,t,n){let r=Math.min(Math.abs(n),Si),i=1/Math.max(Math.cos(r),yi)*e,a=t*bi;return Math.max(i,a,e)}function Pi({projectedShoulderWidth:e,projectedTorsoHeight:t,bodyYaw:n,worldLandmarks:r}){let i=Ni(e,t,n),a=Ri(t,r);if(!a)return i;let o=Vi((Math.abs(n)-Ei)/Di,0,1);return i+(Math.max(i,a)-i)*o}function Fi(e){return e?Vi(e.hips.rotation.y*.85+e.chest.y*.15,-Si,Si):0}function Ii(e,t,n){let r=e.x<=t.x?e:t,i=e.x<=t.x?t:e,a=i.x-r.x;if(a<=wi)return 0;let o=-(i.y-r.y);return Vi(Math.atan2(o,a)*Vi(1-Math.abs(n)/Si,0,1),-Ci,Ci)}function Li({leftShoulder:e,rightShoulder:t,leftHip:n,rightHip:r},i=new o.Quaternion){return Oi.copy(e).add(t).multiplyScalar(.5),ki.copy(n).add(r).multiplyScalar(.5),Q.copy(t).sub(e),Q.lengthSq()<=Ti||(Q.normalize(),$.copy(Oi).sub(ki),Ai.copy(Q).multiplyScalar($.dot(Q)),$.sub(Ai),$.lengthSq()<=Ti)||($.normalize(),ji.crossVectors(Q,$),ji.lengthSq()<=Ti)?null:(ji.normalize(),$.crossVectors(ji,Q).normalize(),Mi.makeBasis(Q,$,ji),i.setFromRotationMatrix(Mi))}function Ri(e,t){if(!t||t.length<=V.RIGHT_HIP||e<=wi)return null;let n=t[V.LEFT_SHOULDER],r=t[V.RIGHT_SHOULDER],i=t[V.LEFT_HIP],a=t[V.RIGHT_HIP];if(!n||!r||!i||!a)return null;let o=Bi(n,r),s=Bi(zi(n,r),zi(i,a));return o<=wi||s<=wi?null:e*Vi(o/s,bi,xi)}function zi(e,t){return{x:(e.x+t.x)*.5,y:(e.y+t.y)*.5,z:((e.z??0)+(t.z??0))*.5}}function Bi(e,t){let n=e.x-t.x,r=e.y-t.y,i=(e.z??0)-(t.z??0);return Math.sqrt(n*n+r*r+i*i)}function Vi(e,t,n){return Math.max(t,Math.min(n,e))}var Hi=1e-4,Ui=.15,Wi=8,Gi=1e-4,Ki=1.45,qi=.35,Ji=10,Yi=.18,Xi=.55,Zi=6,Qi=.3,$i=.08,ea=.05,ta=1.35,na=.7,ra=new o.Quaternion,ia=new o.Vector3,aa=[[V.LEFT_EAR,V.RIGHT_EAR],V.NOSE,[V.LEFT_SHOULDER,V.RIGHT_SHOULDER]],oa=[[V.LEFT_ANKLE,V.RIGHT_ANKLE],[V.LEFT_HEEL,V.RIGHT_HEEL],[V.LEFT_FOOT_INDEX,V.RIGHT_FOOT_INDEX]];function sa(e,t,n){return Math.max(t,Math.min(n,e))}function ca(){return{leftShoulder:new o.Vector3,rightShoulder:new o.Vector3,leftHip:new o.Vector3,rightHip:new o.Vector3,shoulderCenter:new o.Vector3,hipCenter:new o.Vector3,bodyTop:new o.Vector3,bodyBottom:new o.Vector3,anchor:new o.Vector3,scaledAnchor:new o.Vector3,position:new o.Vector3,scale:new o.Vector3(1,1,1),stabilizedBodyHeightScale:null,missingBodyHeightFrames:0,smoothedGlobalScale:1,hasSmoothedGlobalScale:!1,effectiveYaw:0,previousDepthProxy:0,scaleVelocity:0,smoothedXDeviation:1,smoothedAnchor:new o.Vector3,hasSmoothedAnchor:!1}}function la(e,t,n,r,i,a={}){if(t.length<33)return!1;Z(t[V.LEFT_SHOULDER],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.leftShoulder}),Z(t[V.RIGHT_SHOULDER],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.rightShoulder}),Z(t[V.LEFT_HIP],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.leftHip}),Z(t[V.RIGHT_HIP],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.rightHip}),i.shoulderCenter.copy(i.leftShoulder).add(i.rightShoulder).multiplyScalar(.5),i.hipCenter.copy(i.leftHip).add(i.rightHip).multiplyScalar(.5);let s=Li({leftShoulder:i.rightShoulder,rightShoulder:i.leftShoulder,leftHip:i.rightHip,rightHip:i.leftHip},ra),c=s?da(s):0,l=ma(a.bodyYaw,c);i.effectiveYaw=l;let u=ga(i.leftShoulder,i.rightShoulder),d=ga(i.shoulderCenter,i.hipCenter),f=Pi({projectedShoulderWidth:u,projectedTorsoHeight:d,bodyYaw:l,worldLandmarks:a.worldLandmarks}),p=d/Math.max(e.referenceTorsoHeight,Hi),m=ha(t,n,r,d,i,a),h=fa(m===null?null:m/Math.max(e.trackingHeight,Hi),i),g=h!==null&&p>Hi?sa(h,p*na,p*ta):h,_=pa(sa(g===null?p:p*.55+g*.45,Ui,Wi)*(a.scaleMultiplier??1),i,d),v=.1,y=e.referenceWidth/Math.max(e.referenceTorsoHeight,Hi),b=d>Hi?f/d:y,x=sa(y>Hi?b/y:1,1-v,1+v);return i.smoothedXDeviation=o.MathUtils.lerp(i.smoothedXDeviation,x,.35),i.scale.set(_*i.smoothedXDeviation*(a.scaleX??1),_*(a.scaleY??1),_*(a.scaleZ??1)),i.anchor.copy(i.shoulderCenter).add(i.hipCenter).multiplyScalar(.5),i.hasSmoothedAnchor?i.smoothedAnchor.lerp(i.anchor,.4):(i.smoothedAnchor.copy(i.anchor),i.hasSmoothedAnchor=!0),i.scaledAnchor.set(e.anchor.x*_,e.anchor.y*_,e.anchor.z*_),i.position.copy(i.smoothedAnchor).sub(i.scaledAnchor),i.position.z+=a.depthOffset??0,!0}function ua(e,t){e.position.copy(t.position),e.scale.copy(t.scale)}function da(e){return ia.set(0,0,1).applyQuaternion(e),ia.y=0,ia.lengthSq()<=Gi?0:(ia.normalize(),Math.atan2(ia.x,ia.z))}function fa(e,t){return e===null?t.stabilizedBodyHeightScale===null?(t.missingBodyHeightFrames=0,null):(t.missingBodyHeightFrames+=1,t.missingBodyHeightFrames>Ji?(t.stabilizedBodyHeightScale=null,null):t.stabilizedBodyHeightScale):(t.missingBodyHeightFrames=0,t.stabilizedBodyHeightScale=t.stabilizedBodyHeightScale===null?e:o.MathUtils.lerp(t.stabilizedBodyHeightScale,e,qi),t.stabilizedBodyHeightScale)}function pa(e,t,n){if(!t.hasSmoothedGlobalScale)return t.smoothedGlobalScale=e,t.previousDepthProxy=n,t.scaleVelocity=0,t.hasSmoothedGlobalScale=!0,e;let r=t.previousDepthProxy,i=1;r>ea&&n>ea&&(i=sa(n/r,1-$i,1+$i)),t.previousDepthProxy=n;let a=t.smoothedGlobalScale*i,s=a>0?Math.abs(e-a)/a:0;t.scaleVelocity=o.MathUtils.lerp(t.scaleVelocity,s,Qi);let c=sa(Yi+t.scaleVelocity*Zi,Yi,Xi);return t.smoothedGlobalScale=o.MathUtils.lerp(a,e,c),t.smoothedGlobalScale}function ma(e,t){let n=e??0;return Math.abs(n)>=Math.abs(t)?n:t}function ha(e,t,n,r,i,a){let o=_a(aa,e,t,n,i.bodyTop,a),s=_a(oa,e,t,n,i.bodyBottom,a);if(!o||!s)return null;let c=ga(i.bodyTop,i.bodyBottom);return c<=r*Ki?null:c}function ga(e,t){let n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function _a(e,t,n,r,i,a){for(let o=0;o<e.length;o+=1)if(va(e[o],t,n,r,i,a))return!0;return!1}function va(e,t,n,r,i,a){if(typeof e==`number`){let o=t[e];return!o||(o.visibility??0)<.4?!1:(Z(o,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i}),!0)}let o=t[e[0]],s=t[e[1]];if(!o||!s||(o.visibility??0)<.4||(s.visibility??0)<.4)return!1;Z(o,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i});let c=Z(s,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight});return i.add(c).multiplyScalar(.5),!0}var ya=new o.Vector3(0,1,0),ba=new Set([`LeftHand`,`RightHand`]),xa=new Set([`Hips`,`Spine`,`Chest`]),Sa=20,Ca=.436,wa=.175,Ta=1.396,Ea=.349,Da=.35;function Oa(e,t,n){return Math.max(t,Math.min(n,e))}function ka(e){let t=e;for(;t<=-Math.PI;)t+=Math.PI*2;for(;t>Math.PI;)t-=Math.PI*2;return t}function Aa(e,t,n){let r=ka(t-e);return ka(Math.abs(r)<=n?t:e+Math.sign(r)*n)}function ja(){return{transformScratch:ca(),facingDetector:new fi,yawFreezeController:new hi,displayYaw:null,lastFacingState:null,hasInitialPosition:!1}}function Ma(e){e.transformScratch=ca(),e.facingDetector.reset(),e.yawFreezeController.reset(),e.displayYaw=null,e.lastFacingState=null,e.hasInitialPosition=!1}function Na({fitProfile:e,garmentRoot:t,boneBindingMap:n,poseRefs:r,motionState:i,landmarks:a,worldLandmarks:o=null,viewportWidth:s,viewportHeight:c,poseFrameWidth:l,poseFrameHeight:u,delta:d}){if(!a||a.length<33)return null;let f=i.transformScratch;la(e,a,s,c,f,{sourceWidth:l,sourceHeight:u,worldLandmarks:o});let p=f.shoulderCenter.y-f.hipCenter.y,m=f.shoulderCenter.distanceTo(f.hipCenter),h=Math.acos(Oa(Math.abs(p)/Math.max(m,.001),0,1)),g=f.effectiveYaw,_=g>0?g-Math.PI:g+Math.PI,v=i.facingDetector.update(a,_,h),y=v.bodyYaw,b=i.displayYaw===null?y:Aa(i.displayYaw,y,Sa*d),x=i.yawFreezeController.update(v.zone,y),S=x.isFrozen,C=S?x.frozenYaw??b:b;return i.displayYaw=C,i.lastFacingState=v,v.zone!==`back`&&(S||(t.scale.copy(f.scale),i.hasInitialPosition?t.position.lerp(f.position,Da):(t.position.copy(f.position),i.hasInitialPosition=!0)),t.quaternion.setFromAxisAngle(ya,C)),v.zone===`front`&&!S?(Vr(a,n,r,{coordinateSpace:`normalized`,excludeBones:ba}),v.pitchClamped&&Ur(n,Oa((Math.abs(h)-Ca)/wa,0,1),d,xa)):v.zone===`side`&&!S&&(Vr(a,n,r,{coordinateSpace:`normalized`,excludeBones:ba}),Ur(n,Oa((Math.abs(y)-Ta)/Ea,0,1),d)),v}function Pa({garmentRootRef:e,boneBindingMap:r,fitProfile:i,landmarks:a,worldLandmarks:o,poseFrameWidth:s,poseFrameHeight:c}){let{viewport:l}=(0,n.useThree)(),u=Br(),d=(0,t.useRef)(ja());return(0,t.useEffect)(()=>{let t=e.current,n=d.current;return t&&(t.position.set(0,0,0),t.scale.set(1,1,1),t.quaternion.identity()),Hr(r,u),Ma(n),()=>{Hr(r,u),Ma(n)}},[r,i,e,u]),(0,n.useFrame)((t,n)=>{let f=e.current;!f||!i||Na({fitProfile:i,garmentRoot:f,boneBindingMap:r,poseRefs:u,motionState:d.current,landmarks:a,worldLandmarks:o,viewportWidth:l.width,viewportHeight:l.height,poseFrameWidth:s,poseFrameHeight:c,delta:n})}),null}function Fa(e){return e?e.map(e=>({x:e.x,y:e.y,z:e.z,visibility:typeof e.visibility==`number`?e.visibility:0})):null}function Ia({url:e,landmarks:n,worldLandmarks:r,poseFrameWidth:a,poseFrameHeight:s,debugMaterials:c=!1,onLoadStateChange:l}){let u=(0,t.useRef)(null),{scene:d,bones:f}=ir({url:e}),p=(0,t.useMemo)(()=>Fa(n),[n]),m=(0,t.useMemo)(()=>Fa(r),[r]),h=(0,t.useMemo)(()=>(d.updateMatrixWorld(!0),Vn(d,f,1)),[f,d]);return(0,t.useEffect)(()=>{d.traverse(e=>{if(e instanceof o.Mesh){if(e.name.startsWith(`Collision`)){e.visible=!1;return}e.visible=!0,(Array.isArray(e.material)?e.material:[e.material]).forEach(e=>{`opacity`in e&&(c?(e.transparent=!0,e.opacity=.34,e.depthWrite=!1,e.side=o.DoubleSide):(e.transparent=!1,e.opacity=1,e.depthWrite=!0,e.side=o.FrontSide),e.needsUpdate=!0)})}})},[d,c]),(0,t.useEffect)(()=>(l?.({loaded:!0,error:null}),()=>{l?.({loaded:!1,error:null})}),[l,e]),(0,i.jsxs)(`group`,{ref:u,children:[(0,i.jsx)(`primitive`,{object:d}),(0,i.jsx)(Pa,{garmentRootRef:u,boneBindingMap:f,fitProfile:h,landmarks:p,worldLandmarks:m,poseFrameWidth:a,poseFrameHeight:s})]})}var La=1;function Ra(e){let t=new o.VideoTexture(e);return t.minFilter=o.NearestFilter,t.magFilter=o.NearestFilter,t.generateMipmaps=!1,t.colorSpace=o.SRGBColorSpace,t.needsUpdate=!0,t}function za(e,t,n){if(!n||n.width===0||n.height===0)return[e,t];let r=e/t,i=n.width/n.height;return r>i?[e,e/i]:[t*i,t]}function Ba({videoElement:e,webcamReady:r}){let{viewport:a}=(0,n.useThree)(),[o,s]=(0,t.useState)(null),[c,l]=(0,t.useState)(null),u=(0,t.useRef)(null),d=(0,t.useRef)(null),f=(0,t.useRef)(0);(0,t.useEffect)(()=>{let t=e;if(!r||!t){d.current!==null&&(clearTimeout(d.current),d.current=null),f.current=0;return}let n=!1,i=()=>{if(n||u.current)return;if(t.videoWidth===0||t.videoHeight===0){d.current=setTimeout(i,100);return}let e=Ra(t);u.current=e,f.current=0,l({width:t.videoWidth,height:t.videoHeight}),s(e)};return t.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&t.videoWidth>0&&t.videoHeight>0?i():(t.addEventListener(`loadeddata`,i),t.addEventListener(`loadedmetadata`,i),t.addEventListener(`playing`,i),d.current=setTimeout(i,200)),()=>{n=!0,d.current!==null&&(clearTimeout(d.current),d.current=null),t.removeEventListener(`loadeddata`,i),t.removeEventListener(`loadedmetadata`,i),t.removeEventListener(`playing`,i),u.current&&=(u.current.dispose(),null),f.current=0,s(null),l(null)}},[e,r]),(0,n.useFrame)(()=>{!u.current||!u.current.image||(f.current=(f.current+1)%La,f.current===0&&(u.current.needsUpdate=!0))});let[p,m]=(0,t.useMemo)(()=>za(a.width,a.height,c),[c,a.height,a.width]);return!r||!o?null:(0,i.jsxs)(`mesh`,{position:[0,0,-20],renderOrder:-1,scale:[-1,1,1],children:[(0,i.jsx)(`planeGeometry`,{args:[p,m]}),(0,i.jsx)(`meshBasicMaterial`,{map:o,depthTest:!1,depthWrite:!1,toneMapped:!1})]})}function Va({onReady:e}){return(0,t.useEffect)(()=>(e?.(!0),()=>{e?.(!1)}),[e]),null}function Ha(){return(0,i.jsx)(`color`,{attach:`background`,args:[`#000000`]})}function Ua({garmentUrl:e,enabled:n=!0,width:a=1280,height:o=720,facingMode:s=`user`,mockMode:c=!1,viewportWidth:l=0,viewportHeight:u=0,measurementEnabled:d=!0,autoStartMeasurement:f=!1,measurementConfig:p,fitType:m=`regular`,garmentScaleHint:h=null,bodyPresetOptions:g,className:v,style:y,debugMaterials:b=!1,showEnvironment:x=!1,showStats:S=!1,showWebcamBackground:C=!0,onCanvasReadyChange:w,onRuntimeStateChange:T,onGarmentLoadStateChange:E}){let{videoRef:D,webcamReady:O,webcamError:k,startWebcam:A,stopWebcam:j,isTrackerReady:M,landmarks:ee,worldLandmarks:N,poseRig:P,confidence:F,fps:I,isTracking:L,drawLandmarks:R,silhouetteWidths:z,poseFrameWidth:B,poseFrameHeight:te,detectedPersonCount:ne,lockedPersonId:re,trackingQuality:ie,config:ae,measurements:oe,sizeRecommendation:se,garmentScale:ce,finalGarmentScale:le,bodyMorphResult:ue,isMeasuring:de,canMeasure:fe,startMeasurement:pe,updateConfig:me,bodyPresetSelection:he,bodyPresetLoading:ge,bodyPresetError:_e}=In({enabled:n,width:a,height:o,facingMode:s,mockMode:c,viewportWidth:l,viewportHeight:u,measurementEnabled:d,autoStartMeasurement:f,measurementConfig:p,bodyPresetOptions:g,fitType:m,garmentScaleHint:h}),[ve,ye]=(0,t.useState)(null),be=(0,t.useCallback)(e=>{D.current=e,ye(e)},[D]),xe=(0,t.useMemo)(()=>({videoRef:D,webcamReady:O,webcamError:k,startWebcam:A,stopWebcam:j,isTrackerReady:M,landmarks:ee,worldLandmarks:N,poseRig:P,confidence:F,fps:I,isTracking:L,drawLandmarks:R,silhouetteWidths:z,poseFrameWidth:B,poseFrameHeight:te,detectedPersonCount:ne,lockedPersonId:re,trackingQuality:ie,config:ae,measurements:oe,sizeRecommendation:se,garmentScale:ce,finalGarmentScale:le,bodyMorphResult:ue,isMeasuring:de,canMeasure:fe,startMeasurement:pe,updateConfig:me,bodyPresetSelection:he,bodyPresetLoading:ge,bodyPresetError:_e}),[D,O,k,A,j,M,ee,N,P,F,I,L,R,z,B,te,ne,re,ie,ae,oe,se,ce,le,ue,de,fe,pe,me,he,ge,_e]);return(0,t.useEffect)(()=>{T?.(xe)},[T,xe]),(0,i.jsxs)(`div`,{className:v,style:{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,...y},children:[(0,i.jsx)(`video`,{ref:be,autoPlay:!0,playsInline:!0,muted:!0,style:{display:`none`}}),(0,i.jsxs)(_,{showEnvironment:x,useDefaultLights:!1,enableOrbitControls:!1,children:[(0,i.jsx)(Va,{onReady:w}),(0,i.jsx)(Ha,{}),(0,i.jsx)(r.OrthographicCamera,{makeDefault:!0,position:[0,0,100],zoom:180,near:.1,far:1e3}),(0,i.jsx)(`ambientLight`,{intensity:.95}),(0,i.jsx)(`directionalLight`,{position:[4,6,8],intensity:1.15}),(0,i.jsx)(`directionalLight`,{position:[-5,4,6],intensity:.45}),(0,i.jsx)(`hemisphereLight`,{args:[`#ffffff`,`#7d8aa6`,.35]}),C?(0,i.jsx)(Ba,{videoElement:ve,webcamReady:O}):null,n&&e?(0,i.jsx)(Ia,{url:e,landmarks:ee,worldLandmarks:N,poseFrameWidth:B,poseFrameHeight:te,debugMaterials:b,onLoadStateChange:E}):null,S?(0,i.jsx)(r.Stats,{}):null]})]})}var Wa={gender:`female`};function Ga(e,t){return e instanceof Error&&e.message?e.message:t}function Ka(e){let n=(0,t.useMemo)(()=>new fe(e),[e]),[r,i]=(0,t.useState)(`idle`),[a,o]=(0,t.useState)(null),[s,c]=(0,t.useState)(null);return{status:r,resultUrl:a,error:s,generateAvatar:(0,t.useCallback)(async(e=Wa)=>{i(`processing`),c(null);try{let t=e instanceof Blob?Wa:e,r=await n.matchBodyPreset(t);if(!r.model_url)throw Error(`Matched body preset does not have a 3D model URL.`);return o(r.model_url),i(`ready`),r.model_url}catch(e){throw c(Ga(e,`Failed to load avatar model`)),i(`error`),e}},[n]),createGarment:(0,t.useCallback)(async(e,t,r,a)=>{i(`uploading`),c(null);try{let s=await n.createGarment(e);await n.uploadGarmentImage(s.id,t,`front`),r&&await n.uploadGarmentImage(s.id,r,`back`),i(`processing`),await n.generateGarment3D(s.id,{include_measurements:!!a,target_fit_types:[`regular`]});let c=await n.waitForGarmentModel(s.id),l=n.pickGarmentModelUrl(c);if(!l)throw Error(`Backend did not return a garment 3D model URL.`);return o(l),i(`ready`),l}catch(e){throw c(Ga(e,`Failed to generate garment`)),i(`error`),e}},[n]),reset:()=>{i(`idle`),o(null),c(null)}}}var qa={Hips:[V.LEFT_HIP,V.RIGHT_HIP],Spine:[V.LEFT_SHOULDER,V.RIGHT_SHOULDER,V.LEFT_HIP,V.RIGHT_HIP],Chest:[V.LEFT_SHOULDER,V.RIGHT_SHOULDER],LeftShoulder:[V.LEFT_SHOULDER,V.LEFT_ELBOW],LeftUpperArm:[V.LEFT_SHOULDER,V.LEFT_ELBOW],LeftLowerArm:[V.LEFT_ELBOW,V.LEFT_WRIST],RightShoulder:[V.RIGHT_SHOULDER,V.RIGHT_ELBOW],RightUpperArm:[V.RIGHT_SHOULDER,V.RIGHT_ELBOW],RightLowerArm:[V.RIGHT_ELBOW,V.RIGHT_WRIST],LeftUpperLeg:[V.LEFT_HIP,V.LEFT_KNEE],LeftLowerLeg:[V.LEFT_KNEE,V.LEFT_ANKLE],RightUpperLeg:[V.RIGHT_HIP,V.RIGHT_KNEE],RightLowerLeg:[V.RIGHT_KNEE,V.RIGHT_ANKLE]};e.BONE_MAPPING=ur,e.BONE_VISIBILITY_MAP=qa,e.DEFAULT_EVER_API_BASE_URL=le,e.DEFAULT_FEMALE_BODY_PRESET_ID=he,e.DEFAULT_GARMENT_SPEC=v,e.DEFAULT_LOCKED_PERSON_ID=qt,e.DEFAULT_MALE_BODY_PRESET_ID=me,e.DEFAULT_MEASUREMENT_CONFIG=Ge,e.DEFAULT_NUM_POSES=ut,e.DEFAULT_SMOOTHING=Ae,e.EverCanvas=_,e.EverClient=fe,e.EverFittingScene=Ua,e.EverTrackedGarment=Ia,e.FacingDetector=fi,e.INTERPOLATION_ALPHA=dt,e.LANDMARK=V,e.LEGACY_RIGGED_BODY_PRESET_ID=ge,e.LandmarkSmoother=en,e.MEDIAPIPE_TASKS_VISION_VERSION=st,e.MODEL_ASSET_PATHS=ft,e.POSE_DETECTION_INTERVAL=lt,e.TRACKING_SNAPSHOT_HOLD_MS=On,e.TrackedGarmentPoseDriver=Pa,e.WASM_FILES_URL=ct,e.WebcamPlaneBackground=Ba,e.YawDirectionStabilizer=Yr,e.YawFreezeController=hi,e.applyLandmarkPoseToGarment=Vr,e.applyTrackedModelTransform=ua,e.blendBonesToRest=Ur,e.buildBodyPresetAssetUrl=ye,e.buildBodyPresetMatchRequest=Ee,e.calcRectIoU=pn,e.captureBoneBinding=Ln,e.clampNormalizedRect=un,e.closeSegmentationMasks=Gt,e.computeBmiCorrectionFactor=Fe,e.computeBodyFirstFitting=ce,e.computeBoneDirectionFromLandmarks=Nt,e.computeBoneRotationFromLandmarks=Ft,e.computeCoverRect=Ye,e.computeFacingAwareShoulderWidth=Ni,e.computeGarmentFitProfile=Vn,e.computeGarmentGroupRoll=Ii,e.computeGarmentGroupYaw=Fi,e.computeGarmentRootQuaternion=Li,e.computeGarmentScale=x,e.computeLandmarkBoundsNormalized=dn,e.computeLandmarkSegmentDirection=Mt,e.computeScale=Pe,e.computeStableShoulderWidth=Pi,e.computeVisibleNormalizedRegion=Xe,e.configureAvatarLoader=qn,e.createAvatarLoaderExtension=Jn,e.createFallbackBodyPresetSelection=we,e.createHeldTrackingSnapshot=An,e.createHumanoidBoneBindings=Qn,e.createIdleTrackingQuality=wn,e.createInitialPoseSnapshot=at,e.createInitialTrackingRuntimeState=En,e.createPoseCandidates=hn,e.createPoseLandmarker=pt,e.createTrackedGarmentMotionState=ja,e.createTrackedModelTransformScratch=ca,e.createTrackingLostRuntimeState=jn,e.createTrackingQuality=Tn,e.createTrackingRuntimeState=Dn,e.createVRMCompat=nr,e.deriveBodyMorphResult=re,e.ensureBodyPresetModelUrl=Se,e.expandNormalizedRect=fn,e.extractFacingSignals=li,e.extractSilhouetteWidths=et,e.filterCandidatesByVisibleRegion=yn,e.getAvatarAssetKind=Kn,e.getBoneLandmarkInfluence=Pt,e.getBoneRotation=pr,e.getDefaultBodyPresetId=be,e.getSegmentationMaskData=Wt,e.hasLandmarkMapping=It,e.interpolateLandmarks=tt,e.interpolatePoseRig=rt,e.interpolatePoseSnapshot=ot,e.interpolateSilhouetteWidths=it,e.isCandidateInVisibleRegion=vn,e.isRawFrontFacing=ui,e.isVRMAssetUrl=Gn,e.landmarkDistance=vi,e.landmarkToThreePosition=Z,e.lerpRotation=q,e.lerpValue=W,e.measureBody=He,e.midpointToThree=_i,e.normalizeBodyPresetGender=ve,e.normalizeBoneName=fr,e.normalizeLandmark=Yt,e.normalizeLandmarks=Xt,e.pickDefaultBodyPreset=Ce,e.prepareAvatarScene=Yn,e.prepareNativeVRM=Xn,e.recommendSize=We,e.resetBoneRotations=Hn,e.resetPoseState=Hr,e.resetTrackedGarmentMotionState=Ma,e.scaleSilhouetteWidths=Kt,e.selectLockedPoseCandidate=_n,e.shouldHoldTrackingSnapshot=kn,e.smoothPoseRig=nn,e.solvePose=Ut,e.toBodyPresetSelection=Te,e.toBodyPresetSummary=xe,e.toLockedPoseCandidate=bn,e.updateTrackedGarmentMotion=Na,e.updateTrackedModelTransform=la,e.useAvatarVariant=ir,e.useBodyPresetSelection=ke,e.useEverFitting=In,e.useEverGeneration=Ka,e.useMeasurement=Je,e.usePoseApplicationRefs=Br,e.usePoseTracker=Nn,e.useWebcam=Fn});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`react`),require(`@react-three/fiber`),require(`@react-three/drei`),require(`react/jsx-runtime`),require(`@mediapipe/tasks-vision`),require(`three`),require(`three/examples/jsm/utils/SkeletonUtils.js`),require(`@pixiv/three-vrm`)):typeof define==`function`&&define.amd?define([`exports`,`react`,`@react-three/fiber`,`@react-three/drei`,`react/jsx-runtime`,`@mediapipe/tasks-vision`,`three`,`three/examples/jsm/utils/SkeletonUtils.js`,`@pixiv/three-vrm`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`e-ver`]={},e.React,e.ReactThreeFiber,e.ReactThreeDrei,e.react_jsx_runtime,e.MediaPipeVision,e.THREE,e.three_examples_jsm_utils_SkeletonUtils_js,e.PixivThreeVRM))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var l=Object.create,u=Object.defineProperty,d=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,p=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,h=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=f(t),a=0,o=i.length,s;a<o;a++)s=i[a],!m.call(e,s)&&s!==n&&u(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=d(t,s))||r.enumerable});return e},g=(e,t,n)=>(n=e==null?{}:l(p(e)),h(t||!e||!e.__esModule?u(n,`default`,{value:e,enumerable:!0}):n,e));t=g(t),o=g(o);var _=({children:e,showEnvironment:a=!0,useDefaultLights:o=!0,enableOrbitControls:s=!0})=>(0,i.jsx)(n.Canvas,{camera:{position:[0,1.5,3],fov:45},style:{width:`100%`,height:`100%`,position:`absolute`,top:0,left:0},gl:{alpha:!0,antialias:!0,preserveDrawingBuffer:!0},children:(0,i.jsxs)(t.Suspense,{fallback:null,children:[o?(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(`ambientLight`,{intensity:.7}),(0,i.jsx)(`directionalLight`,{position:[2,5,2],intensity:1.5,castShadow:!0}),(0,i.jsx)(`directionalLight`,{position:[-2,5,-2],intensity:.5})]}):null,a&&(0,i.jsx)(r.Environment,{preset:`city`}),e,s?(0,i.jsx)(r.OrbitControls,{enablePan:!1,minPolarAngle:Math.PI/4,maxPolarAngle:Math.PI/1.5,minDistance:1,maxDistance:5}):null]})});function v(e,t,n){return Math.max(t,Math.min(n,e))}function y(e){let t=e;for(;t<=-Math.PI;)t+=Math.PI*2;for(;t>Math.PI;)t-=Math.PI*2;return t}var b={refShoulderWidthCm:44,refHeightCm:170,refArmLengthCm:58,refChestCircumferenceCm:96,refWaistCircumferenceCm:84,refHipWidthCm:36,refTorsoLengthCm:52,shoulderEaseCm:4.5,chestEaseCm:10,waistEaseCm:8,hipEaseCm:5,torsoEaseCm:2.5,armEaseCm:2,fitEaseScale:1.03};function x(e,t,n){return!e||t<=0?1:(e+n)/t}function S(e,t=b){let n=x(e.shoulderWidthCm,t.refShoulderWidthCm,t.shoulderEaseCm),r=x(e.chestCircumferenceCm,t.refChestCircumferenceCm,t.chestEaseCm),i=x(e.waistCircumferenceCm,t.refWaistCircumferenceCm,t.waistEaseCm),a=x(e.hipWidthCm,t.refHipWidthCm,t.hipEaseCm),o=x(e.torsoLengthCm,t.refTorsoLengthCm,t.torsoEaseCm),s=t.refHeightCm>0?e.heightCm/t.refHeightCm:1,c=x(e.armLengthCm,t.refArmLengthCm,t.armEaseCm),l=Math.max(n,r,a),u=Math.max(r,i,a*.98),d=Math.max(s,o,l*.94);return{scaleX:v(l,.82,1.85),scaleY:v(d,.85,1.55),scaleZ:v(u,.84,1.9),sleeveScale:v(c,.8,1.55),fitEaseScale:v(t.fitEaseScale,1,1.2)}}var C=.82,w=2.1,T=.85,E=1.8,D=.84,O=2.1,k=.8,A=1.7,j=1,M=1.25,ee={scaleX:1,scaleY:1,scaleZ:1,sleeveScale:1,fitEaseScale:1.02},te={scaleX:1,scaleY:1,scaleZ:1,sleeveScale:1,fitEaseScale:1},ne={slim:{x:.95,y:.95,z:1,ease:.99},regular:{x:1,y:1,z:1,ease:1},oversize:{x:1.08,y:1.08,z:1.02,ease:1.03}},re={narrow:{width:.97,shoulder:.97},balanced:{width:1,shoulder:1},broad:{width:1.03,shoulder:1.04}},N={tapered:{depth:.98,vertical:.995,hip:.99},balanced:{depth:1,vertical:1,hip:1},full:{depth:1.04,vertical:1.015,hip:1.03}};function P(e,t,n,r){return!e||!t||t<=0?1:v(e/t,n,r)}function F(e,t,n,r,i){return!e||t<=0?1:v((e+n)/t,r,i)}function I(e){return re[e?.taxonomy.upperBodySilhouette??`balanced`]??re.balanced}function ie(e){return N[e?.taxonomy.torsoOrPelvisProfile??`balanced`]??N.balanced}function ae(e){if(!e)return!1;let{metrics:t}=e;return!!(t.heightCm||t.chestCm||t.waistCm||t.shoulderWidthCm||t.armLengthCm||t.torsoLengthCm||t.neckToHipCm)}function oe(e,t){let{metrics:n}=e,r=I(e),i=ie(e),a=Math.max(F(n.shoulderWidthCm,t.refShoulderWidthCm,t.shoulderEaseCm*.55,.88,1.3),F(n.chestCm,t.refChestCircumferenceCm,t.chestEaseCm*.35,.9,1.34),F(n.waistCm,t.refWaistCircumferenceCm,t.waistEaseCm*.3,.9,1.3))*r.width,o=Math.max(P(n.heightCm,t.refHeightCm,.9,1.18),F(n.torsoLengthCm??n.neckToHipCm,t.refTorsoLengthCm,t.torsoEaseCm*.2,.9,1.16))*i.vertical,s=Math.max(F(n.chestCm,t.refChestCircumferenceCm,t.chestEaseCm*.15,.9,1.34),F(n.waistCm,t.refWaistCircumferenceCm,t.waistEaseCm*.1,.9,1.28))*i.depth;return{scaleX:v(a,C,w),scaleY:v(o,T,E),scaleZ:v(s,D,O),sleeveScale:v(P(n.armLengthCm,t.refArmLengthCm,.9,1.16),k,A),fitEaseScale:v(t.fitEaseScale*(r.width*.5+i.depth*.5),j,M)}}function se(e,t){let{metrics:n}=t,r=I(t),i=ie(t),a=P(e.shoulderWidthCm,n.shoulderWidthCm,.9,1.14)*r.shoulder,o=P(e.chestCircumferenceCm,n.chestCm,.9,1.15),s=P(e.waistCircumferenceCm,n.waistCm,.9,1.15);return{torsoScale:P(e.torsoLengthCm,n.torsoLengthCm??n.neckToHipCm,.9,1.14),chestScale:o,waistScale:s,hipScale:v(s*.6+i.hip*.4,.92,1.14),shoulderAdjust:v(a-1,-.12,.12),postureAdjust:`neutral`}}function ce(e,t,n){let r=ie(t),i=v(1+n.shoulderAdjust,.92,1.14)*.3+n.chestScale*.45+n.waistScale*.25,a=n.chestScale*.45+n.waistScale*.25+n.hipScale*.3,o=P(e.armLengthCm,t.metrics.armLengthCm,.9,1.16),s=Math.max(n.chestScale,n.waistScale,n.hipScale);return{scaleX:v(i,.92,1.16),scaleY:v(n.torsoScale*r.vertical,.92,1.14),scaleZ:v(a*r.depth,.92,1.18),sleeveScale:v(o,k,A),fitEaseScale:v(1+(s-1)*.22,.99,1.08)}}function le(e,t){if(!t||!Number.isFinite(t)||t<=0)return e;let n=v(t,.88,1.2),r=1+(n-1)*.35;return{scaleX:v(e.scaleX*n,C,w),scaleY:v(e.scaleY*r,T,E),scaleZ:v(e.scaleZ*n,D,O),sleeveScale:v(e.sleeveScale*r,k,A),fitEaseScale:v(e.fitEaseScale*n,j,M)}}function ue(e,t){let n=ne[t];return{scaleX:v(e.scaleX*n.x,C,w),scaleY:v(e.scaleY*n.y,T,E),scaleZ:v(e.scaleZ*n.z,D,O),sleeveScale:e.sleeveScale,fitEaseScale:v(e.fitEaseScale*n.ease,j,M)}}function de(e,t){return{scaleX:v(e.scaleX*t.scaleX,C,w),scaleY:v(e.scaleY*t.scaleY,T,E),scaleZ:v(e.scaleZ*t.scaleZ,D,O),sleeveScale:v(e.sleeveScale*t.sleeveScale,k,A),fitEaseScale:v(e.fitEaseScale*t.fitEaseScale,j,M)}}function fe({measurements:e,measurementScale:t,presetSelection:n,fitType:r=`regular`,garmentScaleHint:i=null,spec:a=b}){let o=ae(n),s=o&&n?oe(n,a):t??ee,c=o&&n&&e?se(e,n):null;return{scale:ue(le(de(s,e&&n&&c?ce(e,n,c):te),i),r),morph:c}}var pe=`http://localhost:8000/api/v1`;function me(e){return e.replace(/\/+$/,``)}function he(e){try{return new URL(e).origin}catch{return``}}var ge=class{baseUrl;apiOrigin;apiKey;constructor(e){let t=typeof e==`string`?{baseUrl:e}:e??{},n=me(t.baseUrl??`http://localhost:8000/api/v1`);this.baseUrl=n,this.apiOrigin=he(n),this.apiKey=t.apiKey}resolveAssetUrl(e){return e?e.startsWith(`http://`)||e.startsWith(`https://`)?e:e.startsWith(`/`)?this.apiOrigin?`${this.apiOrigin}${e}`:e:this.apiOrigin?`${this.apiOrigin}/${e}`:`/${e}`:null}async listBodyPresets(e){return(await this.request(`body-presets/`,{params:e?{gender:e}:void 0})).map(e=>this.normalizeBodyPreset(e))}async matchBodyPreset(e){let t=await this.request(`body-presets/match`,{method:`POST`,body:e});return this.normalizeBodyPreset(t)}async listGarments(e){let t=await this.request(`garment/`,{params:e});return{...t,items:t.items.map(e=>this.normalizeGarmentSummary(e))}}async getGarment(e){let t=await this.request(`garment/${e}`);return this.normalizeGarmentDetail(t)}async getPipelineStatus(e){return this.request(`pipeline/${e}`)}async createGarment(e){let t=await this.request(`garment/`,{method:`POST`,body:e});return this.normalizeGarmentSummary(t)}async uploadGarmentImage(e,t,n){let r=new FormData;return r.append(`files`,t,`${n}_image.png`),r.append(`image_type`,n),(await this.request(`garment/${e}/images`,{method:`POST`,body:r})).map(e=>({...e,image_url:this.resolveAssetUrl(e.image_url)??e.image_url}))}async generateGarment3D(e,t){return this.request(`garment/${e}/generate-3d`,{method:`POST`,body:{include_measurements:t?.include_measurements??!1,target_fit_types:t?.target_fit_types??[`regular`]}})}async waitForGarmentModel(e,t){let n=t?.intervalMs??2e3,r=t?.timeoutMs??12e4,i=Date.now();for(;Date.now()-i<=r;){let t=await this.getGarment(e);if(this.pickGarmentModelUrl(t))return t;if(t.asset_status===`rigging_failed`)throw Error(`Garment 3D generation failed on backend.`);await new Promise(e=>globalThis.setTimeout(e,n))}throw Error(`Timed out while waiting for garment 3D model.`)}pickGarmentModelUrl(e){if(e.model_url)return e.model_url;let t=e.variants.find(e=>e.is_default&&e.model_url);return t?.model_url?t.model_url:e.variants.find(e=>e.model_url)?.model_url??null}normalizeBodyPreset(e){return{...e,model_url:this.resolveAssetUrl(e.model_url)}}normalizeGarmentSummary(e){return{...e,thumbnail_url:this.resolveAssetUrl(e.thumbnail_url),model_url:this.resolveAssetUrl(e.model_url)}}normalizeGarmentDetail(e){return{...this.normalizeGarmentSummary(e),brand:e.brand?{...e.brand,logo_url:this.resolveAssetUrl(e.brand.logo_url)}:null,images:e.images.map(e=>({...e,image_url:this.resolveAssetUrl(e.image_url)??e.image_url})),sizes:e.sizes,variants:e.variants.map(e=>({...e,model_url:this.resolveAssetUrl(e.model_url)}))}}async request(e,t){let n=this.apiKey?`sdk/public/${e}`:e,r=this.buildUrl(n,t?.params),i=new Headers,a;this.apiKey&&i.set(`X-API-Key`,this.apiKey),t?.body instanceof FormData?a=t.body:t?.body!==void 0&&(i.set(`Content-Type`,`application/json`),a=JSON.stringify(t.body));let o=await fetch(r.toString(),{method:t?.method??`GET`,body:a,headers:i,credentials:this.apiKey?`omit`:`include`});if(!o.ok)throw Error(await this.getResponseErrorMessage(o));if(o.status!==204)return await o.json()}buildUrl(e,t){let n=this.baseUrl.startsWith(`http://`)||this.baseUrl.startsWith(`https://`)?`${this.baseUrl}/`:typeof window<`u`?new URL(`${this.baseUrl}/`,window.location.origin).toString():`http://localhost${this.baseUrl}/`,r=new URL(e.replace(/^\/+/,``),n);return t&&Object.entries(t).forEach(([e,t])=>{t!==void 0&&r.searchParams.set(e,String(t))}),r}async getResponseErrorMessage(e){try{let t=await e.json();return t.detail||t.message||t.error||`Request failed with status ${e.status}`}catch{return`Request failed with status ${e.status}`}}},_e=`M`,ve=`male-m-balanced-balanced`,ye=`female-m-balanced-balanced`,be=`rigged_avatar`;function xe(e,t){if(!t)return``;if(/^https?:\/\//.test(t))return t;let n=t.startsWith(`/`)?t:`/${t}`;return n.startsWith(`/assets/`)||n.startsWith(`/static/`)?n:e.resolveAssetUrl(n)??n}function Se(e){return e===`female`?`female`:`male`}function Ce(e,t={}){let n=t.renderMode??`rigged_avatar`,r=t.legacyPresetId??`rigged_avatar`,i=`/assets/body-presets/${r}.glb`;return e===r||n!==`preset-native`?i:`/assets/body-presets/archive/${e}.glb`}function we(e){return e===`female`?ye:ve}function Te(e,t){return{id:e.id,presetId:e.preset_id,baseGender:Se(e.base_gender),sizeBand:e.size_band,upperBodySilhouette:e.upper_body_silhouette,torsoOrPelvisProfile:e.torso_or_pelvis_profile,modelUrl:xe(t,e.model_url),heightCm:e.height_cm??null,chestCm:e.chest_cm??null,waistCm:e.waist_cm??null,hipCm:e.hip_cm??null,shoulderWidthCm:e.shoulder_width_cm??null,armLengthCm:e.arm_length_cm??null,inseamCm:e.inseam_cm??null,torsoLengthCm:e.torso_length_cm??null,neckToHipCm:e.neck_to_hip_cm??null}}function Ee(e,t={}){return{...e,modelUrl:e.modelUrl||Ce(e.presetId,t)}}function De(e,t={}){return e.length===0?null:Ee(e.find(e=>e.sizeBand===_e)||e[Math.floor(e.length/2)],t)}function Oe(e,t={}){let n=we(e);return{id:null,presetId:n,label:`${e===`female`?`여성`:`남성`} 기본 ${_e}`,modelUrl:Ce(n,t),gender:e,source:`fallback`,taxonomy:{sizeBand:_e,upperBodySilhouette:`balanced`,torsoOrPelvisProfile:`balanced`},metrics:{heightCm:null,chestCm:null,waistCm:null,hipCm:null,shoulderWidthCm:null,armLengthCm:null,inseamCm:null,torsoLengthCm:null,neckToHipCm:null}}}function ke(e,t,n={}){let r=Ee(e,n);return{id:r.id,presetId:r.presetId,label:`${r.baseGender===`female`?`여성`:`남성`} ${r.sizeBand}`,modelUrl:r.modelUrl,gender:r.baseGender,source:t,taxonomy:{sizeBand:r.sizeBand,upperBodySilhouette:r.upperBodySilhouette,torsoOrPelvisProfile:r.torsoOrPelvisProfile},metrics:{heightCm:r.heightCm,chestCm:r.chestCm,waistCm:r.waistCm,hipCm:r.hipCm,shoulderWidthCm:r.shoulderWidthCm,armLengthCm:r.armLengthCm,inseamCm:r.inseamCm,torsoLengthCm:r.torsoLengthCm,neckToHipCm:r.neckToHipCm}}}function Ae(e,t){let n={gender:t};return Number.isFinite(e.heightCm)&&(n.height_cm=e.heightCm),e.chestCircumferenceCm!==null&&(n.chest_cm=e.chestCircumferenceCm),e.waistCircumferenceCm!==null&&(n.waist_cm=e.waistCircumferenceCm),e.shoulderWidthCm!==null&&(n.shoulder_width_cm=e.shoulderWidthCm),n}var je=new ge;function Me(e,t){return{selection:Oe(e,t),loading:!0,error:null}}function Ne(e,n={}){let r=Se(n.gender),i=n.renderMode,a=n.legacyPresetId,o=(0,t.useMemo)(()=>({gender:r,renderMode:i,legacyPresetId:a}),[r,a,i]),[s,c]=(0,t.useState)(()=>Me(r,o));return(0,t.useEffect)(()=>{let t=new AbortController;async function n(){c(e=>({...e,loading:!0,error:null}));try{if(e){let n=ke(Te(await je.matchBodyPreset(Ae(e,o.gender)),je),`match`,o);if(t.signal.aborted)return;c({selection:n,loading:!1,error:null});return}let n=(await je.listBodyPresets(o.gender)).map(e=>Te(e,je));if(t.signal.aborted)return;let r=De(n,o);if(r){c({selection:ke(r,`default`,o),loading:!1,error:null});return}c({selection:Oe(o.gender,o),loading:!1,error:`바디 프리셋 응답이 비어 있어 기본 프리셋으로 대체했습니다.`})}catch(e){if(t.signal.aborted)return;c({selection:Oe(o.gender,o),loading:!1,error:e instanceof Error?e.message:`바디 프리셋을 불러오지 못해 기본 프리셋으로 대체했습니다.`})}}return n(),()=>{t.abort()}},[e,o]),s}var L={NOSE:0,LEFT_EYE_INNER:1,LEFT_EYE:2,LEFT_EYE_OUTER:3,RIGHT_EYE_INNER:4,RIGHT_EYE:5,RIGHT_EYE_OUTER:6,LEFT_EAR:7,RIGHT_EAR:8,MOUTH_LEFT:9,MOUTH_RIGHT:10,LEFT_SHOULDER:11,RIGHT_SHOULDER:12,LEFT_ELBOW:13,RIGHT_ELBOW:14,LEFT_WRIST:15,RIGHT_WRIST:16,LEFT_PINKY:17,RIGHT_PINKY:18,LEFT_INDEX:19,RIGHT_INDEX:20,LEFT_THUMB:21,RIGHT_THUMB:22,LEFT_HIP:23,RIGHT_HIP:24,LEFT_KNEE:25,RIGHT_KNEE:26,LEFT_ANKLE:27,RIGHT_ANKLE:28,LEFT_HEEL:29,RIGHT_HEEL:30,LEFT_FOOT_INDEX:31,RIGHT_FOOT_INDEX:32},Pe={positionAlpha:.7,rotationAlpha:.6,visibilityThreshold:.5},Fe=.5;function Ie(e){return e?(e.visibility??1)>=Fe:!1}function Le(e,t){let n=e[L.NOSE],r=e[L.LEFT_EYE],i=e[L.LEFT_ANKLE],a=e[L.RIGHT_ANKLE];if(!Ie(n)||!Ie(r)||!Ie(i)||!Ie(a))return 0;let o=n.y-(r.y-n.y)*2,s=(Math.max(i.y,a.y)-o)*t;return Number.isFinite(s)&&s>0?s:0}function Re(e,t,n=720){let r=Le(e,n);return r<=0||t<=0?0:t/r}function ze(e){let t=[[15,.8],[18.5,.84],[22,.88],[25,.91],[30,.94],[40,.96]];if(e<=t[0][0])return t[0][1];if(e>=t[t.length-1][0])return t[t.length-1][1];for(let n=0;n<t.length-1;n+=1){let[r,i]=t[n],[a,o]=t[n+1];if(e>=r&&e<=a)return i+(e-r)/(a-r)*(o-i)}return .88}function R(e,t,n,r){if(!Ie(e)||!Ie(t))return null;let i=(e.x-t.x)*n,a=(e.y-t.y)*r,o=Math.hypot(i,a);return Number.isFinite(o)&&o>0?o:null}function Be(e){return Math.round(e*10)/10}function z(e){return e===null||!Number.isFinite(e)||e<=0?null:Be(e)}function Ve(e){let t=e.filter(e=>e!==null);return t.length===0?null:t.reduce((e,t)=>e+t,0)/t.length}function He(e,t){return e&&t!==null&&t>0?`silhouette_bmi`:`keypoint`}function Ue(e,t,n){return n&&t>0&&e/t>=.85?`standard`:`estimate`}function We(e,t,n,r){if(t<=0||e<=0)return 0;let i=e/t*.8,a=n?.15:0,o=r!==null&&r>0?.05:0;return Math.min(.99,Be((i+a+o)*10)/10)}function Ge(e,t){if(e<=0||t<=0)return 0;let n=(e-t)**2/(e+t)**2;return Math.PI*(e+t)*(1+3*n/(10+Math.sqrt(4-3*n)))}function Ke(e,t,n=null,r=null,i=1280,a=720){let o=Re(e,t,a),s=He(r,n);if(o<=0)return{heightCm:t,shoulderWidthCm:null,chestCircumferenceCm:null,waistCircumferenceCm:null,hipWidthCm:null,armLengthCm:null,legLengthCm:null,torsoLengthCm:null,accuracyGrade:`estimate`,confidenceScore:0,measurementMethod:s,measuredAt:null};let c=R(e[L.LEFT_SHOULDER],e[L.RIGHT_SHOULDER],i,a),l=R(e[L.LEFT_HIP],e[L.RIGHT_HIP],i,a),u=R(e[L.LEFT_SHOULDER],e[L.LEFT_ELBOW],i,a),d=R(e[L.LEFT_ELBOW],e[L.LEFT_WRIST],i,a),f=R(e[L.RIGHT_SHOULDER],e[L.RIGHT_ELBOW],i,a),p=R(e[L.RIGHT_ELBOW],e[L.RIGHT_WRIST],i,a),m=u!==null&&d!==null?u+d:null,h=f!==null&&p!==null?f+p:null,g=R(e[L.LEFT_HIP],e[L.LEFT_KNEE],i,a),_=R(e[L.LEFT_KNEE],e[L.LEFT_ANKLE],i,a),v=R(e[L.RIGHT_HIP],e[L.RIGHT_KNEE],i,a),y=R(e[L.RIGHT_KNEE],e[L.RIGHT_ANKLE],i,a),b=g!==null&&_!==null?g+_:null,x=v!==null&&y!==null?v+y:null,S=Ve([R(e[L.LEFT_SHOULDER],e[L.LEFT_HIP],i,a),R(e[L.RIGHT_SHOULDER],e[L.RIGHT_HIP],i,a)]),C=z(c===null?null:c*o),w=z(l===null?null:l*o),T=z(Ve([m===null?null:m*o,h===null?null:h*o])),E=z(Ve([b===null?null:b*o,x===null?null:x*o])),D=z(S===null?null:S*o),O=C===null?null:C*2.2,k=w===null?null:w*2.1;if(r){let e=r.shoulderWidthPx*o;if(O=z(Ge(Math.max(r.chestWidthPx*o/2,0),Math.max(e*.28/2,0))),k=z(Ge(Math.max(r.waistWidthPx*o/2,0),Math.max(r.hipWidthPx*o*.26/2,0))),n!==null&&n>0){let e=ze(n/(t/100)**2);O=z(O===null?null:O/e),k=z(k===null?null:k/e)}}else O=z(O),k=z(k);let A=[C,O,k,w,T,E,D].filter(e=>e!==null).length;return{heightCm:Be(t),shoulderWidthCm:C,chestCircumferenceCm:O,waistCircumferenceCm:k,hipWidthCm:w,armLengthCm:T,legLengthCm:E,torsoLengthCm:D,accuracyGrade:Ue(A,7,r),confidenceScore:We(A,7,r,n),measurementMethod:s,measuredAt:null}}var qe={S:{shoulder:[40,42],chest:[86,92],waist:[72,78]},M:{shoulder:[42,44],chest:[92,98],waist:[78,84]},L:{shoulder:[44,46],chest:[98,104],waist:[84,90]},XL:{shoulder:[46,48],chest:[104,110],waist:[90,96]},"2XL":{shoulder:[48,50],chest:[110,118],waist:[96,104]}};function Je(e){let t=[`S`,`M`,`L`,`XL`,`2XL`],n=`M`,r=-1/0,i=!1;for(let a of t){let t=qe[a],o=0,s=0;if(e.shoulderWidthCm!==null){let n=(t.shoulder[0]+t.shoulder[1])/2;o-=Math.abs(e.shoulderWidthCm-n),s+=1,i=!0}if(e.chestCircumferenceCm!==null){let n=(t.chest[0]+t.chest[1])/2;o-=Math.abs(e.chestCircumferenceCm-n),s+=1,i=!0}if(e.waistCircumferenceCm!==null){let n=(t.waist[0]+t.waist[1])/2;o-=Math.abs(e.waistCircumferenceCm-n),s+=1,i=!0}s>0&&(o/=s),o>r&&(r=o,n=a)}if(!i)return null;let a=qe[n],o=`true-to-size`;if(e.chestCircumferenceCm!==null){let t=(a.chest[0]+a.chest[1])/2;e.chestCircumferenceCm>t+3?o=`slim`:e.chestCircumferenceCm<t-3&&(o=`relaxed`)}return{size:n,confidence:Math.min(1,Math.max(0,1+r/10)),fitDescription:o}}var Ye={referenceHeightCm:170,weightKg:null,stableFrameCount:15,motionThreshold:.015};function Xe(e){return e.map(e=>({...e}))}function Ze(e,t){let n=0;for(let r=0;r<33;r+=1){let i=e[r],a=t[r];n+=Math.abs(a.x-i.x)+Math.abs(a.y-i.y)}return n/33}function Qe(){let[e,n]=(0,t.useState)(Ye),[r,i]=(0,t.useState)(null),[a,o]=(0,t.useState)(null),[s,c]=(0,t.useState)(null),[l,u]=(0,t.useState)(!1),d=(0,t.useRef)(0),f=(0,t.useRef)(null),p=(0,t.useCallback)(()=>{d.current=0,f.current=null},[]),m=(0,t.useCallback)(()=>{i(null),o(null),c(null)},[]),h=(0,t.useCallback)(()=>{p(),m(),u(!0)},[m,p]);return{measure:(0,t.useCallback)((t,n={})=>{if(!l||t.length<33)return;let r=Xe(t);if(!f.current){f.current=r,d.current=1;return}if(d.current=Ze(f.current,r)<e.motionThreshold?d.current+1:1,f.current=r,d.current<e.stableFrameCount)return;let a=Ke(t,e.referenceHeightCm,e.weightKg,n.silhouetteWidths??null,n.imageWidth??1280,n.imageHeight??720),s=new Date().toISOString(),m=Je(a),h=S(a);i({...a,measuredAt:s}),o(m),c(h),u(!1),p()},[e,l,p]),startMeasurement:h,measurements:r,sizeRecommendation:a,garmentScale:s,isMeasuring:l,updateConfig:(0,t.useCallback)(e=>{n(t=>({...t,...e})),p(),m(),u(!1)},[m,p]),config:e}}function $e(e,t,n,r){if(e<=0||t<=0||n<=0||r<=0)return{x:0,y:0,width:Math.max(0,e),height:Math.max(0,t)};let i=e/t,a=n/r;if(i>a){let n=e,r=n/a;return{x:0,y:(t-r)*.5,width:n,height:r}}let o=t,s=o*a;return{x:(e-s)*.5,y:0,width:s,height:o}}function et(e,t,n,r){if(e<=0||t<=0||n<=0||r<=0)return{xMin:0,xMax:1,yMin:0,yMax:1};let i=e/t,a=n/r;if(i>a){let e=(1-a/i)/2;return{xMin:0,xMax:1,yMin:e,yMax:1-e}}let o=(1-i/a)/2;return{xMin:o,xMax:1-o,yMin:0,yMax:1}}var tt=5,nt=.5;function rt(e,t,n,r,i=tt,a=nt){if(t<=0||n<=0||e.length!==t*n)return null;let o=Math.round(r),s=Math.floor(i/2),c=Math.max(0,o-s),l=Math.min(n-1,o+s),u=0,d=0,f=0;for(let n=c;n<=l;n+=1){let r=-1,i=-1,o=n*t;for(let n=0;n<t;n+=1)e[o+n]>=a&&(r<0&&(r=n),i=n);r>=0&&i>r&&(u+=r,d+=i,f+=1)}if(f===0)return null;let p=u/f;return d/f-p}function it(e,t,n,r){if(r.length<33)return null;let i=r[L.LEFT_SHOULDER],a=r[L.RIGHT_SHOULDER],o=r[L.LEFT_HIP],s=r[L.RIGHT_HIP],c=r[L.LEFT_KNEE],l=r[L.RIGHT_KNEE];if(!i||!a||!o||!s)return null;let u=(i.y+a.y)/2*n,d=(o.y+s.y)/2*n,f=u+(d-u)*.4,p=c&&l?d+((c.y+l.y)/2*n-d)*.2:d,m=rt(e,t,n,u),h=rt(e,t,n,f),g=rt(e,t,n,d),_=rt(e,t,n,p);return m===null||h===null||g===null||_===null?null:{shoulderWidthPx:m,chestWidthPx:h,waistWidthPx:g,hipWidthPx:_}}function B(e,t,n){return e+(t-e)*n}function at(e,t,n){return t?!e||e.length!==t.length?t:e.map((e,r)=>{let i=t[r];return{x:B(e.x,i.x,n),y:B(e.y,i.y,n),z:B(e.z??0,i.z??0,n),visibility:B(e.visibility??0,i.visibility??0,n)}}):null}function V(e,t,n){return{x:B(e.x,t.x,n),y:B(e.y,t.y,n),z:B(e.z,t.z,n)}}function ot(e,t,n){return!e||!t?t??e:V(e,t,n)}function st(e,t,n){return t?e?{hips:{position:{x:B(e.hips.position.x,t.hips.position.x,n),y:B(e.hips.position.y,t.hips.position.y,n),z:B(e.hips.position.z,t.hips.position.z,n)},rotation:V(e.hips.rotation,t.hips.rotation,n)},spine:V(e.spine,t.spine,n),chest:V(e.chest,t.chest,n),leftUpperArm:V(e.leftUpperArm,t.leftUpperArm,n),leftLowerArm:V(e.leftLowerArm,t.leftLowerArm,n),rightUpperArm:V(e.rightUpperArm,t.rightUpperArm,n),rightLowerArm:V(e.rightLowerArm,t.rightLowerArm,n),leftUpperLeg:ot(e.leftUpperLeg,t.leftUpperLeg,n),leftLowerLeg:ot(e.leftLowerLeg,t.leftLowerLeg,n),rightUpperLeg:ot(e.rightUpperLeg,t.rightUpperLeg,n),rightLowerLeg:ot(e.rightLowerLeg,t.rightLowerLeg,n)}:t:null}function ct(e,t,n){return t?e?{shoulderWidthPx:B(e.shoulderWidthPx,t.shoulderWidthPx,n),chestWidthPx:B(e.chestWidthPx,t.chestWidthPx,n),waistWidthPx:B(e.waistWidthPx,t.waistWidthPx,n),hipWidthPx:B(e.hipWidthPx,t.hipWidthPx,n)}:t:null}function lt(){return{landmarks:null,worldLandmarks:null,poseRig:null,confidence:0,isTracking:!1,silhouetteWidths:null}}function ut(e,t,n){return!e||!e.isTracking||!t.isTracking||!t.landmarks?t:{landmarks:at(e.landmarks,t.landmarks,n),worldLandmarks:at(e.worldLandmarks,t.worldLandmarks,n),poseRig:st(e.poseRig,t.poseRig,n),confidence:B(e.confidence,t.confidence,n),isTracking:t.isTracking,silhouetteWidths:ct(e.silhouetteWidths,t.silhouetteWidths,n)}}var dt=`0.10.32`,ft=`https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@${dt}/wasm`,pt=1,mt=3,ht=.5,gt={lite:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_lite/float16/latest/pose_landmarker_lite.task`,full:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_full/float16/latest/pose_landmarker_full.task`,heavy:`https://storage.googleapis.com/mediapipe-models/pose_landmarker/pose_landmarker_heavy/float16/latest/pose_landmarker_heavy.task`};async function _t(e,t,n,r,i=3){let o=await a.FilesetResolver.forVisionTasks(ft),s={baseOptions:{modelAssetPath:e},runningMode:`VIDEO`,numPoses:i,outputSegmentationMasks:r,minPoseDetectionConfidence:t,minPosePresenceConfidence:n,minTrackingConfidence:n};try{return await a.PoseLandmarker.createFromOptions(o,{...s,baseOptions:{...s.baseOptions,delegate:`GPU`}})}catch{return a.PoseLandmarker.createFromOptions(o,{...s,baseOptions:{...s.baseOptions,delegate:`CPU`}})}}var vt=new o.Vector3,yt=new o.Vector3,bt=new o.Vector3,xt=new o.Quaternion,St=new o.Vector3,Ct=new o.Vector3,wt=new o.Vector3(0,-1,0),Tt=new o.Vector3(1,0,0),Et=new o.Vector3(-1,0,0),Dt=new o.Vector3(0,1,0),Ot=[L.LEFT_SHOULDER,L.RIGHT_SHOULDER],kt=[L.LEFT_HIP,L.RIGHT_HIP],At=[L.LEFT_EAR,L.RIGHT_EAR],jt=[L.LEFT_INDEX,L.LEFT_PINKY],Mt=[L.RIGHT_INDEX,L.RIGHT_PINKY],Nt={Hips:{from:kt,to:Ot,restDir:Dt,influence:.35},Spine:{from:kt,to:Ot,restDir:Dt,influence:.55},Chest:{from:Ot,to:At,restDir:Dt,influence:.7},LeftShoulder:{from:Ot,to:L.LEFT_SHOULDER,restDir:Tt,influence:.45},LeftUpperArm:{from:L.LEFT_SHOULDER,to:L.LEFT_ELBOW,restDir:Tt},LeftLowerArm:{from:L.LEFT_ELBOW,to:L.LEFT_WRIST,restDir:Tt},LeftHand:{from:L.LEFT_WRIST,to:jt,restDir:Tt,influence:.65},RightShoulder:{from:Ot,to:L.RIGHT_SHOULDER,restDir:Et,influence:.45},RightUpperArm:{from:L.RIGHT_SHOULDER,to:L.RIGHT_ELBOW,restDir:Et},RightLowerArm:{from:L.RIGHT_ELBOW,to:L.RIGHT_WRIST,restDir:Et},RightHand:{from:L.RIGHT_WRIST,to:Mt,restDir:Et,influence:.65},LeftUpperLeg:{from:L.LEFT_HIP,to:L.LEFT_KNEE,restDir:wt},LeftLowerLeg:{from:L.LEFT_KNEE,to:L.LEFT_ANKLE,restDir:wt},LeftFoot:{from:L.LEFT_ANKLE,to:L.LEFT_FOOT_INDEX,restDir:new o.Vector3(0,0,1)},RightUpperLeg:{from:L.RIGHT_HIP,to:L.RIGHT_KNEE,restDir:wt},RightLowerLeg:{from:L.RIGHT_KNEE,to:L.RIGHT_ANKLE,restDir:wt},RightFoot:{from:L.RIGHT_ANKLE,to:L.RIGHT_FOOT_INDEX,restDir:new o.Vector3(0,0,1)}};function Pt(e,t,n){return n===`world`?(t.set(-e.x,-e.y,-(e.z??0)),t):(t.set(-(e.x-.5),-(e.y-.5),-(e.z??0)*.5),t)}function Ft(e,t,n,r){if(typeof e==`number`){let i=t[e];return!i||(i.visibility??0)<.4?!1:(Pt(i,n,r),!0)}let i=t[e[0]],a=t[e[1]];return!i||!a||(i.visibility??0)<.4||(a.visibility??0)<.4?!1:(Pt(i,St,r),Pt(a,Ct,r),n.copy(St).add(Ct).multiplyScalar(.5),!0)}function It(e,t,n,r,i=`normalized`){if(!Ft(e,n,vt,i)||!Ft(t,n,yt,i))return!1;r.subVectors(yt,vt);let a=r.length();return a<.001?!1:(r.divideScalar(a),!0)}function Lt(e,t,n,r=`normalized`){let i=Nt[e];return i?It(i.from,i.to,t,n,r):!1}function Rt(e){return Nt[e]?.influence}function zt(e,t,n,r=`normalized`){let i=Nt[e];return!i||!Lt(e,t,bt,r)?!1:(n.setFromUnitVectors(i.restDir,bt),i.influence!==void 0&&n.slerp(xt.identity(),1-i.influence),!0)}function Bt(e){return e in Nt}var Vt=new o.Quaternion,Ht=new o.Euler,Ut=[`Hips`,`Spine`];function Wt(){return{x:0,y:0,z:0}}function Gt(e){return Ht.setFromQuaternion(e,`XYZ`),{x:Ht.x,y:Ht.y,z:Ht.z}}function H(e,t,n){return zt(e,t,Vt,n)?Gt(Vt):Wt()}function Kt(e,t,n){if(zt(e,t,Vt,n))return Gt(Vt)}function qt(e){let t=e[L.LEFT_HIP],n=e[L.RIGHT_HIP];return{x:((t?.x??0)+(n?.x??0))*.5,y:((t?.y??0)+(n?.y??0))*.5,z:((t?.z??0)+(n?.z??0))*.5}}function Jt(e,t=`normalized`){return e.length<33?!1:Ut.every(n=>zt(n,e,Vt,t))}function Yt(e,t){if(e.length<33)return null;let n=t&&t.length>=33?t:e,r=t&&t.length>=33?`world`:`normalized`;return Jt(n,r)?{hips:{position:qt(e),rotation:H(`Hips`,n,r)},spine:H(`Spine`,n,r),chest:H(`Chest`,n,r),leftUpperArm:H(`LeftUpperArm`,n,r),leftLowerArm:H(`LeftLowerArm`,n,r),rightUpperArm:H(`RightUpperArm`,n,r),rightLowerArm:H(`RightLowerArm`,n,r),leftUpperLeg:Kt(`LeftUpperLeg`,n,r),leftLowerLeg:Kt(`LeftLowerLeg`,n,r),rightUpperLeg:Kt(`RightUpperLeg`,n,r),rightLowerLeg:Kt(`RightLowerLeg`,n,r)}:null}function Xt(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.width!=`number`||typeof t.height!=`number`||typeof t.getAsFloat32Array!=`function`?null:t}function Zt(e){if(e)for(let t of e)t&&typeof t==`object`&&`close`in t&&typeof t.close==`function`&&t.close()}function Qt(e,t,n){let r=t/n;return{shoulderWidthPx:e.shoulderWidthPx*r,chestWidthPx:e.chestWidthPx*r,waistWidthPx:e.waistWidthPx*r,hipWidthPx:e.hipWidthPx*r}}var $t=[L.LEFT_SHOULDER,L.RIGHT_SHOULDER,L.LEFT_HIP,L.RIGHT_HIP],en=[L.NOSE,L.LEFT_EAR,L.RIGHT_EAR,L.LEFT_ELBOW,L.RIGHT_ELBOW,L.LEFT_WRIST,L.RIGHT_WRIST],tn=.35,nn=.05,rn=2,an=.72,on=.28;function sn(e){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):0}function cn(e,t,n){let r=0,i=0;return t.forEach(t=>{let a=sn(e[t]?.visibility);a<n||(r+=a,i+=1)}),i===0?null:r/i}function ln(e,t,n){return t.reduce((t,r)=>sn(e[r]?.visibility)>=n?t+1:t,0)}function un(e){if(!Array.isArray(e)||e.length<33)return 0;let t=cn(e,$t,0);if(t===null)return 0;let n=cn(e,en,nn)??t,r=ln(e,$t,tn),i=r>=rn?1:r/rn;return(t*an+n*on)*i}var dn=`pose-0`;function fn(e){return typeof e==`number`?e:0}function pn(e){return{x:e.x,y:e.y,z:e.z,visibility:fn(e.visibility)}}function mn(e){return e.map(pn)}function hn(e){return pn(e)}function gn(e,t,n){return y(e+y(t-e)*n)}var _n=class{prev=null;config;constructor(e=Pe){this.config=e}smooth(e){if(e.length===0)return this.prev=null,[];let t=mn(e);if(!this.prev||this.prev.length!==t.length)return this.prev=t.map(hn),t.map(hn);let n=this.config.positionAlpha,r=t.map((e,t)=>{let r=this.prev[t];return(e.visibility??0)<this.config.visibilityThreshold?{...hn(r),visibility:e.visibility}:{x:r.x+n*(e.x-r.x),y:r.y+n*(e.y-r.y),z:r.z+n*(e.z-r.z),visibility:e.visibility}});return this.prev=r.map(hn),r}reset(){this.prev=null}};function U(e,t,n){return{x:gn(e.x,t.x,n),y:gn(e.y,t.y,n),z:gn(e.z,t.z,n)}}function vn(e,t,n){return t?e?U(e,t,n):t:e}function yn(e,t,n=Pe.rotationAlpha){return e?{hips:{position:{x:e.hips.position.x+n*(t.hips.position.x-e.hips.position.x),y:e.hips.position.y+n*(t.hips.position.y-e.hips.position.y),z:e.hips.position.z+n*(t.hips.position.z-e.hips.position.z)},rotation:U(e.hips.rotation,t.hips.rotation,n)},spine:U(e.spine,t.spine,n),chest:U(e.chest,t.chest,n),leftUpperArm:U(e.leftUpperArm,t.leftUpperArm,n),leftLowerArm:U(e.leftLowerArm,t.leftLowerArm,n),rightUpperArm:U(e.rightUpperArm,t.rightUpperArm,n),rightLowerArm:U(e.rightLowerArm,t.rightLowerArm,n),leftUpperLeg:vn(e.leftUpperLeg,t.leftUpperLeg,n),leftLowerLeg:vn(e.leftLowerLeg,t.leftLowerLeg,n),rightUpperLeg:vn(e.rightUpperLeg,t.rightUpperLeg,n),rightLowerLeg:vn(e.rightLowerLeg,t.rightLowerLeg,n)}:t}var bn=.12,xn=.35,Sn=.05,Cn=[11,12,23,24],wn=2,Tn=.3;function En(e){if(!e)return null;let t=Math.max(0,Math.min(1,e.x)),n=Math.max(0,Math.min(1,e.y));return{x:t,y:n,w:Math.max(.01,Math.min(1-t,e.w)),h:Math.max(.01,Math.min(1-n,e.h))}}function Dn(e){if(!Array.isArray(e)||e.length===0)return null;let t=1/0,n=1/0,r=-1/0,i=-1/0,a=0;return e.forEach(e=>{!e||typeof e.x!=`number`||typeof e.y!=`number`||(e.visibility??0)<xn||(t=Math.min(t,e.x),n=Math.min(n,e.y),r=Math.max(r,e.x),i=Math.max(i,e.y),a+=1)}),a<4||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)?null:En({x:t,y:n,w:Math.max(.01,r-t),h:Math.max(.01,i-n)})}function On(e,t=bn){if(!e)return null;let n=e.w*t,r=e.h*t;return En({x:e.x-n/2,y:e.y-r/2,w:e.w+n,h:e.h+r})}function kn(e,t){if(!e||!t)return 0;let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y),i=Math.min(e.x+e.w,t.x+t.w),a=Math.min(e.y+e.h,t.y+t.h),o=Math.max(0,i-n)*Math.max(0,a-r);if(o<=0)return 0;let s=e.w*e.h+t.w*t.h-o;return s<=0?0:o/s}function An(e){return e.length===0?0:e.reduce((e,t)=>e+(t.visibility??0),0)/e.length}function jn(e,t=[]){return e.flatMap((e,n)=>{let r=Dn(e),i=On(r);return!r||!i?[]:[{poseIndex:n,personId:`pose-${n}`,landmarks:e,worldLandmarks:t[n]??null,bounds:r,expandedBounds:i,meanVisibility:An(e),area:i.w*i.h}]})}function Mn(e,t){let n=kn(e.expandedBounds,t.expandedBounds);return{iou:n,score:n*.75+e.area*.25}}function Nn(e,{previousCandidate:t,allowRelock:n=!1,minIouToKeep:r=Sn}){if(e.length===0)return null;let i=[...e].sort((e,t)=>t.area*t.meanVisibility-e.area*e.meanVisibility);if(!t)return i[0];let a=null,o=-1/0,s=0;return e.forEach(e=>{let{iou:n,score:r}=Mn(e,t);r>o&&(a=e,o=r,s=n)}),a&&s>=r?a:n?i[0]:null}function Pn(e,t){if(!t)return!0;let n=0,r=0,i=0;for(let t of Cn){let a=e.landmarks[t];a&&(a.visibility??0)>Tn&&(n+=a.x,r+=a.y,i+=1)}if(i<wn)return!0;let a=n/i,o=r/i;return a>=t.xMin&&a<=t.xMax&&o>=t.yMin&&o<=t.yMax}function Fn(e,t){return t?e.filter(e=>Pn(e,t)):e}function In(e){return e?{poseIndex:e.poseIndex,personId:e.personId,bounds:e.bounds,expandedBounds:e.expandedBounds}:null}var Ln=.55,Rn=640,zn=360;function Bn(e=null){return{level:`idle`,reasons:[`no_person_detected`],updatedAt:e}}function Vn({detectedPersonCount:e,isTracking:t,lockedPersonId:n=null,meanVisibility:r=null,frameWidth:i=0,frameHeight:a=0,updatedAt:o=Date.now()}){if(e<1)return Bn(o);let s=[];return e>1&&s.push(`multi_person_detected`),i>0&&a>0&&(i<Rn||a<zn)&&s.push(`resolution_too_low`),r!==null&&r<Ln&&s.push(`low_visibility`),(!n||!t)&&s.push(`pose_not_locked`),s.length===0?{level:`good`,reasons:[],updatedAt:o}:{level:s.includes(`resolution_too_low`)?`blocked`:`degraded`,reasons:s,updatedAt:o}}function Hn(){return{detectedPersonCount:0,lockedPersonId:null,trackingQuality:Bn()}}function Un({detectedPersonCount:e,isTracking:t,lockedPersonId:n,meanVisibility:r,frameWidth:i,frameHeight:a,updatedAt:o}){let s=n??(t&&e>0?`pose-0`:null);return{detectedPersonCount:e,lockedPersonId:s,trackingQuality:Vn({detectedPersonCount:e,isTracking:t,lockedPersonId:s,meanVisibility:r,frameWidth:i,frameHeight:a,updatedAt:o})}}var Wn=180;function Gn(e,t,n=180){return e===null?!1:t-e<=n}function Kn(e){return!e||!e.isTracking||!e.landmarks||!e.poseRig?null:{...e,isTracking:!0}}function qn(e,t,n=dn){return{detectedPersonCount:e,lockedPersonId:n,trackingQuality:{level:`degraded`,reasons:[`tracking_lost`],updatedAt:t}}}function Jn(){return{landmarks:null,worldLandmarks:null,poseRig:null,confidence:0,fps:0,isTracking:!1}}var Yn=(e,n={})=>{let{enabled:r=!0,modelComplexity:i=`lite`,numPoses:o=3,minDetectionConfidence:s=.5,minTrackingConfidence:c=.5,outputSegmentationMasks:l=!1,viewportWidth:u=0,viewportHeight:d=0}=n,f=(0,t.useRef)(null),p=(0,t.useRef)(new _n(Pe)),m=(0,t.useRef)(null),h=(0,t.useRef)(null),g=(0,t.useRef)(null),_=(0,t.useRef)(-1),v=(0,t.useRef)({width:0,height:0}),y=(0,t.useRef)(0),b=(0,t.useRef)(null),x=(0,t.useRef)(null),S=(0,t.useRef)(null),C=(0,t.useRef)(null),w=(0,t.useRef)(null),T=(0,t.useRef)(Hn()),E=(0,t.useRef)({frames:0,lastMeasuredAt:0}),D=(0,t.useRef)(null),O=(0,t.useRef)({width:0,height:0}),[k,A]=(0,t.useState)(!1),[j,M]=(0,t.useState)(Jn),[ee,te]=(0,t.useState)(null),[ne,re]=(0,t.useState)({width:0,height:0}),[N,P]=(0,t.useState)(Hn()),F=(0,t.useCallback)((e,t=T.current)=>{h.current=e.landmarks,T.current=t,M(t=>({...t,landmarks:e.landmarks,worldLandmarks:e.worldLandmarks,poseRig:e.poseRig,confidence:e.confidence,isTracking:e.isTracking})),te(e.silhouetteWidths),P(t)},[]),I=(0,t.useCallback)(()=>{p.current.reset(),m.current=null,h.current=null,_.current=-1,v.current={width:0,height:0},y.current=0,b.current=null,x.current=null,S.current=null,C.current=null,w.current=null,T.current=Hn(),E.current={frames:0,lastMeasuredAt:0},M(Jn()),te(null),re({width:0,height:0}),P(Hn())},[]);(0,t.useEffect)(()=>{if(!r){A(!1),I();return}let e=!1;async function t(){try{let t=await _t(gt[i],s,c,l,o);if(e){t.close();return}f.current=t,E.current.lastMeasuredAt=performance.now(),A(!0)}catch(e){console.error(`Failed to initialize MediaPipe Pose Landmarker:`,e)}}return t(),()=>{e=!0,A(!1),g.current!==null&&(cancelAnimationFrame(g.current),g.current=null),f.current?.close(),f.current=null,I()}},[r,s,c,i,o,l,I]),O.current={width:u,height:d},(0,t.useEffect)(()=>{if(!r||!k)return;let t=()=>{let n=e.current,r=f.current;if(!n||!r||n.readyState<HTMLMediaElement.HAVE_CURRENT_DATA){g.current=requestAnimationFrame(t);return}if(n.currentTime===_.current){g.current=requestAnimationFrame(t);return}_.current=n.currentTime;let i=n.videoWidth||n.clientWidth||1280,a=n.videoHeight||n.clientHeight||720;(i!==v.current.width||a!==v.current.height)&&(v.current={width:i,height:a},re({width:i,height:a}));let o=O.current;D.current=o.width>0&&o.height>0?et(o.width,o.height,i,a):null;let s=performance.now();try{let e=b.current===null||y.current===0;if(y.current=(y.current+1)%1,e){let e=r.detectForVideo(n,s);try{let t=Fn(jn(e.landmarks,e.worldLandmarks),D.current),n=t.length,r=!Gn(C.current,s),o=Nn(t,{previousCandidate:w.current,allowRelock:r}),u=o?.landmarks??null,d=o?.worldLandmarks??null,f=o||w.current?dn:null,h=lt(),g=Un({detectedPersonCount:n,isTracking:!1,lockedPersonId:f,frameWidth:i,frameHeight:a,updatedAt:s}),_=Gn(C.current,s)?Kn(S.current):null;if(!u)_?(h=_,g=qn(n,s,f)):(p.current.reset(),m.current=null,S.current=null,C.current=null,w.current=null,g=Un({detectedPersonCount:n,isTracking:!1,lockedPersonId:null,frameWidth:i,frameHeight:a,updatedAt:s}));else{r&&o&&(p.current.reset(),m.current=null);let t=p.current.smooth(u),v=d?mn(d):null,y=Yt(t,v),b=un(t),x=b>=c&&y?yn(m.current,y,Pe.rotationAlpha):null,T=x!==null,E=null;if(w.current=o?In(o):w.current,l){let n=Xt(o?e.segmentationMasks?.[o.poseIndex]:void 0);if(n){let e=it(new Float32Array(n.getAsFloat32Array()),n.width,n.height,t);e&&(E=Qt(e,i,n.width))}}T&&x?(m.current=x,h={landmarks:t,worldLandmarks:v,poseRig:x,confidence:b,isTracking:T,silhouetteWidths:E},S.current=h,C.current=s,g=Un({detectedPersonCount:n,isTracking:T,lockedPersonId:dn,meanVisibility:b,frameWidth:i,frameHeight:a,updatedAt:s})):_?(h=_,g=qn(n,s,f)):(m.current=null,S.current=null,C.current=null,h={landmarks:t,worldLandmarks:v,poseRig:null,confidence:b,isTracking:!1,silhouetteWidths:E},g=Un({detectedPersonCount:n,isTracking:!1,lockedPersonId:o?dn:null,meanVisibility:b,frameWidth:i,frameHeight:a,updatedAt:s}))}let v=b.current;b.current=h,T.current=g;let y=ut(v,h,ht);x.current=y,F(y,g)}finally{Zt(e.segmentationMasks)}}else if(b.current&&x.current){let e=ut(x.current,b.current,ht);x.current=e,F(e,T.current)}}catch{}let u=E.current;if(u.frames+=1,u.lastMeasuredAt===0&&(u.lastMeasuredAt=s),s-u.lastMeasuredAt>=1e3){let e=u.frames;u.frames=0,u.lastMeasuredAt=s,M(t=>({...t,fps:e}))}g.current=requestAnimationFrame(t)};return g.current=requestAnimationFrame(t),()=>{g.current!==null&&(cancelAnimationFrame(g.current),g.current=null)}},[r,k,c,l,F,e]);let ie=(0,t.useCallback)(t=>{let n=e.current,r=t.getContext(`2d`);if(!n||!r)return;t.width=n.videoWidth||t.clientWidth||1280,t.height=n.videoHeight||t.clientHeight||720,r.clearRect(0,0,t.width,t.height);let i=h.current;if(!i)return;let o=mn(i),s=new a.DrawingUtils(r);s.drawLandmarks(o,{radius:3,color:`#00FF88`,fillColor:`#00FF88`}),s.drawConnectors(o,a.PoseLandmarker.POSE_CONNECTIONS,{color:`#00C8FF`,lineWidth:2})},[e]);return{...j,isTrackerReady:k,drawLandmarks:ie,silhouetteWidths:ee,poseFrameWidth:ne.width,poseFrameHeight:ne.height,detectedPersonCount:N.detectedPersonCount,lockedPersonId:N.lockedPersonId,trackingQuality:N.trackingQuality}};function Xn(e){if(!(e instanceof DOMException))return`Failed to start the camera.`;switch(e.name){case`NotAllowedError`:return`Camera permission was denied.`;case`NotFoundError`:return`No available camera was found.`;case`NotReadableError`:return`The camera is already in use by another app.`;case`OverconstrainedError`:return`The requested camera settings are not supported.`;default:return`Failed to start the camera.`}}function Zn(e={}){let{width:n=1280,height:r=720,facingMode:i=`user`,enabled:a=!0,mockMode:o=!1,videoRef:s,onReadyChange:c,onErrorChange:l}=e,u=(0,t.useRef)(null),d=(0,t.useMemo)(()=>({get current(){return u.current},set current(e){u.current=e,s&&(s.current=e)}}),[s]),f=(0,t.useRef)(null),p=(0,t.useRef)(!1),m=(0,t.useRef)(0),[h,g]=(0,t.useState)(!1),[_,v]=(0,t.useState)(null),y=(0,t.useCallback)(e=>{g(e),c?.(e)},[c]),b=(0,t.useCallback)(e=>{v(e),l?.(e)},[l]),x=(0,t.useCallback)(()=>{f.current&&=(f.current.getTracks().forEach(e=>e.stop()),null),d.current&&(d.current.pause(),d.current.srcObject=null),y(!1)},[y,d]),S=(0,t.useCallback)(()=>{m.current+=1,x()},[x]),C=(0,t.useCallback)(()=>{if(d.current)return d.current;let e=document.createElement(`video`);return e.playsInline=!0,e.autoplay=!0,e.muted=!0,e.setAttribute(`playsinline`,`true`),d.current=e,e},[d]),w=(0,t.useCallback)(async()=>{let e=m.current+1;if(m.current=e,x(),b(null),o){C(),y(!0);return}if(!navigator.mediaDevices?.getUserMedia){b(`This browser does not support camera access.`);return}try{let t=C(),a=await navigator.mediaDevices.getUserMedia({video:{width:n,height:r,facingMode:i},audio:!1});if(!p.current||m.current!==e){a.getTracks().forEach(e=>e.stop());return}if(f.current=a,t.srcObject=a,await t.play(),!p.current||m.current!==e){a.getTracks().forEach(e=>e.stop());return}y(!0)}catch(t){if(m.current!==e)return;x(),b(Xn(t))}},[C,i,r,o,b,y,x,n]);return(0,t.useEffect)(()=>(p.current=!0,()=>{p.current=!1,S()}),[S]),(0,t.useEffect)(()=>{if(p.current){if(!a){S();return}w()}},[a,w,S]),{videoRef:d,isReady:h,error:_,start:w,stop:S}}function Qn(e={}){let{width:n=1280,height:r=720,facingMode:i=`user`,enabled:a=!0,mockMode:o=!1,modelComplexity:s=`lite`,numPoses:c,minDetectionConfidence:l,minTrackingConfidence:u,outputSegmentationMasks:d=!0,viewportWidth:f=0,viewportHeight:p=0,measurementEnabled:m=!0,autoStartMeasurement:h=!1,measurementConfig:g,bodyPresetOptions:_,fitType:v=`regular`,garmentScaleHint:y=null}=e,b=Zn({width:n,height:r,facingMode:i,enabled:a,mockMode:o}),x=Yn(b.videoRef,{enabled:a,modelComplexity:s,numPoses:c,minDetectionConfidence:l,minTrackingConfidence:u,outputSegmentationMasks:d,viewportWidth:f,viewportHeight:p}),{config:S,measurements:C,sizeRecommendation:w,garmentScale:T,isMeasuring:E,measure:D,startMeasurement:O,updateConfig:k}=Qe(),A=a&&b.isReady&&x.isTracking,j=Ne(C,_),M=(0,t.useMemo)(()=>fe({measurements:C,measurementScale:T,presetSelection:j.selection,fitType:v,garmentScaleHint:y}),[j.selection,v,T,y,C]);return(0,t.useEffect)(()=>{g&&k(g)},[g,k]),(0,t.useEffect)(()=>{!m||!h||!A||C||E||O()},[h,A,m,C,E,O]),(0,t.useEffect)(()=>{!m||!E||!x.landmarks||D(x.landmarks,{silhouetteWidths:x.silhouetteWidths,imageWidth:x.poseFrameWidth||n,imageHeight:x.poseFrameHeight||r})},[r,m,E,D,x.landmarks,x.poseFrameHeight,x.poseFrameWidth,x.silhouetteWidths,n]),(0,t.useMemo)(()=>({videoRef:b.videoRef,webcamReady:b.isReady,webcamError:b.error,startWebcam:b.start,stopWebcam:b.stop,isTrackerReady:x.isTrackerReady,landmarks:x.landmarks,worldLandmarks:x.worldLandmarks,poseRig:x.poseRig,confidence:x.confidence,fps:x.fps,isTracking:x.isTracking,drawLandmarks:x.drawLandmarks,silhouetteWidths:x.silhouetteWidths,poseFrameWidth:x.poseFrameWidth,poseFrameHeight:x.poseFrameHeight,detectedPersonCount:x.detectedPersonCount,lockedPersonId:x.lockedPersonId,trackingQuality:x.trackingQuality,config:S,measurements:C,sizeRecommendation:w,garmentScale:T,finalGarmentScale:M.scale,bodyMorphResult:M.morph,isMeasuring:E,canMeasure:A,startMeasurement:O,updateConfig:k,bodyPresetSelection:j.selection,bodyPresetLoading:j.loading,bodyPresetError:j.error}),[M.morph,M.scale,j.error,j.loading,j.selection,A,S,T,E,C,w,O,x.confidence,x.detectedPersonCount,x.drawLandmarks,x.fps,x.isTrackerReady,x.isTracking,x.landmarks,x.lockedPersonId,x.poseFrameHeight,x.poseFrameWidth,x.poseRig,x.silhouetteWidths,x.trackingQuality,x.worldLandmarks,k,b.error,b.isReady,b.start,b.stop,b.videoRef])}function $n(e){let t=new o.Vector3,n=new o.Quaternion,r=new o.Quaternion;return e.updateWorldMatrix(!0,!1),e.getWorldPosition(t),e.getWorldQuaternion(n),e.parent?e.parent.getWorldQuaternion(r):r.identity(),{bone:e,restQuaternion:e.quaternion.clone(),restScale:e.scale.clone(),restWorldPosition:t,restWorldQuaternion:n,restParentWorldQuaternion:r}}function er(e){let t=new o.Box3,n={current:!1},r=new o.Vector3,i=new o.Box3;return e.updateMatrixWorld(!0),e.traverse(e=>{if(!(e instanceof o.Mesh)||e.name.startsWith(`Collision`)||!e.visible)return;let a=e.geometry.getAttribute(`skinIndex`)&&e.geometry.getAttribute(`skinWeight`);if(e instanceof o.SkinnedMesh&&a){if(e.computeBoundingBox(),!e.boundingBox)return;i.copy(e.boundingBox)}else{if(e.geometry.computeBoundingBox(),!e.geometry.boundingBox)return;i.copy(e.geometry.boundingBox)}let{min:s,max:c}=i;[[s.x,s.y,s.z],[s.x,s.y,c.z],[s.x,c.y,s.z],[s.x,c.y,c.z],[c.x,s.y,s.z],[c.x,s.y,c.z],[c.x,c.y,s.z],[c.x,c.y,c.z]].forEach(([i,a,o])=>{if(r.set(i,a,o).applyMatrix4(e.matrixWorld),!n.current){t.min.copy(r),t.max.copy(r),n.current=!0;return}t.expandByPoint(r)})}),n.current||t.makeEmpty(),t}function tr(e){if(!e||e.length===0)return null;let t=new o.Vector3,n=new o.Vector3;return e.forEach(({bone:e})=>{e.getWorldPosition(n),t.add(n)}),t.multiplyScalar(1/e.length)}function nr(e,t){for(let n=0;n<t.length;n+=1){let r=tr(e.get(t[n]));if(r)return r}return null}function rr(e,t,n=1){e.updateMatrixWorld(!0);let r=er(e),i=r.getCenter(new o.Vector3),a=r.getSize(new o.Vector3),s=new o.Vector3(i.x,r.min.y+a.y*.74,i.z),c=new o.Vector3(i.x,r.min.y+a.y*.42,i.z),l=nr(t,[`LeftUpperArm`,`LeftShoulder`]),u=nr(t,[`RightUpperArm`,`RightShoulder`]),d=nr(t,[`Hips`]),f=nr(t,[`LeftUpperLeg`]),p=nr(t,[`RightUpperLeg`]),m=l??s.clone().setX(i.x+a.x*.18),h=u??s.clone().setX(i.x-a.x*.18),g=d??c,_=m.clone().add(h).multiplyScalar(.5),v=f&&p?f.clone().add(p).multiplyScalar(.5):g.clone(),y=!!(l&&u),b=y&&!!(d||f&&p),x=m.distanceTo(h),S=_.distanceTo(v),C=y?Math.max(x,1e-4):Math.max(x,a.x*.3,n),w=b?Math.max(S,1e-4):Math.max(S,a.y*.28,1e-4),T=b?_.clone().add(v).multiplyScalar(.5):i.clone(),E=r.clone();if(b){let e=Math.min(_.y,v.y),t=Math.max(_.y,v.y);E.min.y=Math.max(E.min.y,e),E.max.y=Math.min(E.max.y,t),E.max.y<=E.min.y&&E.copy(r)}let D=E.getCenter(new o.Vector3),O=E.getSize(new o.Vector3);return{anchor:T,shoulderCenter:_,hipCenter:v,referenceWidth:C,referenceTorsoHeight:w,trackingHeight:Math.max(a.y,w,1e-4),boundsCenter:D,boundsSize:O,hasBoneAnchors:b}}function ir(e){for(let t of e.values())t.forEach(({bone:e,restQuaternion:t,restScale:n})=>{e.quaternion.copy(t),e.scale.copy(n)})}var ar=`__nativeVRMPrepared`;function or(e){try{return new URL(e,`https://avatar.local`).pathname}catch{return e}}function sr(e){return or(e).toLowerCase().endsWith(`.vrm`)}function cr(e){return sr(e)?`vrm`:`gltf`}function lr(e,t){sr(t)&&e.register(e=>new c.VRMLoaderPlugin(e))}function ur(e){if(sr(e))return t=>{lr(t,e)}}function dr(e){e.traverse(e=>{e.frustumCulled=!1})}function fr(e){let t=e.scene.userData;t[ar]||(c.VRMUtils.rotateVRM0(e),t[ar]=!0),dr(e.scene)}var pr={Hips:[`hips`],Spine:[`spine`],Chest:[`chest`,`upperChest`],Neck:[`neck`],Head:[`head`],LeftShoulder:[`leftShoulder`],LeftUpperArm:[`leftUpperArm`],LeftLowerArm:[`leftLowerArm`],LeftHand:[`leftHand`],RightShoulder:[`rightShoulder`],RightUpperArm:[`rightUpperArm`],RightLowerArm:[`rightLowerArm`],RightHand:[`rightHand`],LeftUpperLeg:[`leftUpperLeg`],LeftLowerLeg:[`leftLowerLeg`],LeftFoot:[`leftFoot`],RightUpperLeg:[`rightUpperLeg`],RightLowerLeg:[`rightLowerLeg`],RightFoot:[`rightFoot`]};function mr(e){let t=new Map;return Object.entries(pr).forEach(([n,r])=>{for(let i=0;i<r.length;i+=1){let a=e.getNormalizedBoneNode(r[i]);if(a){t.set(n,[$n(a)]);break}}}),t}var W=Math.PI/180,hr={min:-70*W,max:70*W},gr={min:-45*W,max:45*W},_r={min:-150*W,max:150*W},vr={min:-90*W,max:90*W},yr={min:0,max:150*W},br={Hips:{rigKey:`hips`,rotationScale:{x:.7,y:.3,z:.7}},Spine:{rigKey:`spine`,rotationScale:{x:.85,y:.4,z:.85}},Chest:{rigKey:`chest`,rotationScale:{x:.75,y:.35,z:.75}},Neck:{rigKey:null},Head:{rigKey:null},LeftShoulder:{rigKey:`leftUpperArm`,rotationScale:.45,rotationLimits:{x:hr,z:gr}},LeftUpperArm:{rigKey:`leftUpperArm`,rotationScale:1,rotationLimits:{x:_r,z:vr}},LeftLowerArm:{rigKey:`leftLowerArm`,rotationScale:1,rotationLimits:{x:yr}},LeftHand:{rigKey:`leftLowerArm`,rotationScale:.5},RightShoulder:{rigKey:`rightUpperArm`,rotationScale:.45,rotationLimits:{x:hr,z:gr}},RightUpperArm:{rigKey:`rightUpperArm`,rotationScale:1,rotationLimits:{x:_r,z:vr}},RightLowerArm:{rigKey:`rightLowerArm`,rotationScale:1,rotationLimits:{x:yr}},RightHand:{rigKey:`rightLowerArm`,rotationScale:.5},LeftUpperLeg:{rigKey:`leftUpperLeg`,rotationScale:.9},LeftLowerLeg:{rigKey:`leftLowerLeg`,rotationScale:.9},LeftFoot:{rigKey:null},RightUpperLeg:{rigKey:`rightUpperLeg`,rotationScale:.9},RightLowerLeg:{rigKey:`rightLowerLeg`,rotationScale:.9},RightFoot:{rigKey:null}},xr={Root:`Hips`,root:`Hips`,c_spine0:`Spine`,c_spine1:`Spine`,c_spine2:`Chest`,c_spine3:`Chest`,c_neck:`Neck`,c_head:`Head`,l_clavicle:`LeftShoulder`,l_uparm:`LeftUpperArm`,l_lowarm:`LeftLowerArm`,l_wrist:`LeftHand`,r_clavicle:`RightShoulder`,r_uparm:`RightUpperArm`,r_lowarm:`RightLowerArm`,r_wrist:`RightHand`,l_upleg:`LeftUpperLeg`,l_lowleg:`LeftLowerLeg`,l_foot:`LeftFoot`,r_upleg:`RightUpperLeg`,r_lowleg:`RightLowerLeg`,r_foot:`RightFoot`,mixamorig_Hips:`Hips`,mixamorig_Spine:`Spine`,mixamorig_Spine1:`Chest`,mixamorig_Neck:`Neck`,mixamorig_Head:`Head`,mixamorig_LeftShoulder:`LeftShoulder`,mixamorig_LeftArm:`LeftUpperArm`,mixamorig_LeftForeArm:`LeftLowerArm`,mixamorig_LeftHand:`LeftHand`,mixamorig_RightShoulder:`RightShoulder`,mixamorig_RightArm:`RightUpperArm`,mixamorig_RightForeArm:`RightLowerArm`,mixamorig_RightHand:`RightHand`,mixamorig_LeftUpLeg:`LeftUpperLeg`,mixamorig_LeftLeg:`LeftLowerLeg`,mixamorig_LeftFoot:`LeftFoot`,mixamorig_RightUpLeg:`RightUpperLeg`,mixamorig_RightLeg:`RightLowerLeg`,mixamorig_RightFoot:`RightFoot`};function Sr(e){return br[e]?e:xr[e]??e}function Cr(e,t){let n=br[Sr(e)];if(!n||!n.rigKey)return null;let r=t[n.rigKey];if(!r)return null;let i=wr(n.rigKey===`hips`&&`rotation`in r?r.rotation:r,n.rotationScale);return{x:Tr(i.x,n.rotationLimits?.x),y:Tr(i.y,n.rotationLimits?.y),z:Tr(i.z,n.rotationLimits?.z)}}function wr(e,t=1){return typeof t==`number`?{x:e.x*t,y:e.y*t,z:e.z*t}:{x:e.x*(t.x??1),y:e.y*(t.y??1),z:e.z*(t.z??1)}}function Tr(e,t){return t?Math.min(t.max,Math.max(t.min,e)):e}var Er=/^bone_\d+$/,Dr=1e-4,Or=12,kr=8;function G(e,t){return e.children.filter(e=>e instanceof o.Bone&&t.has(e))}function K(e,t){let n=t.get(e);if(n)return n;let r=new o.Vector3;return e.getWorldPosition(r),t.set(e,r),r}function Ar(e,t,n){let r=n.get(e);if(r!==void 0)return r;let i=G(e,t).reduce((e,r)=>e+1+Ar(r,t,n),0);return n.set(e,i),i}function q(e,t,n){!t||e.has(t)||e.set(t,n)}function jr(e,t,n,r,i){let a=K(e,r),o=null,s=-1/0;return G(e,n).forEach(e=>{let c=K(e,r).clone().sub(a),l=Ar(e,n,i)*.4;t===`up`?l+=c.y*6-Math.abs(c.x)*1.5-Math.abs(c.z)*.8:t===`positiveX`?l+=c.x*5-Math.max(c.y,0)*.5-Math.abs(c.z)*.5:l+=-c.x*5-Math.max(c.y,0)*.5-Math.abs(c.z)*.5,!(l<=s)&&(o=e,s=l)}),o}function Mr(e,t,n,r){let i=null,a=-1/0;return e.bones.forEach(e=>{let s=K(e,n),c=G(e,t);if(c.length<2)return;let l=0,u=0,d=0,f=0;c.forEach(e=>{let t=K(e,n).clone().sub(s);t.y>Dr&&(l+=1),t.y<-Dr&&(f+=1),t.x>Dr&&(d+=1),t.x<-Dr&&(u+=1)});let p=e.parent instanceof o.Bone&&t.has(e.parent)?0:2.5,m=(l>0?6:0)+(f>=2?6:0)+(u>0?2:0)+(d>0?2:0)+c.length*.6+Ar(e,t,r)*.12+p;m<=a||(i=e,a=m)}),i}function Nr(e,t,n){if(!e)return[];let r=[e];for(;r.length<kr;){let e=r[r.length-1],i=G(e,t);if(i.length!==1)break;let a=i[0],o=K(e,n);if(K(a,n).y<=o.y+Dr)break;r.push(a)}return r}function Pr(e,t,n,r){if(!e)return null;let i=K(e,r),a=null,o=-1/0;return G(e,n).forEach(e=>{if(t.has(e))return;let n=K(e,r).clone().sub(i),s=n.y*3-Math.abs(n.x)*12-Math.abs(n.z)*4;s<=o||(a=e,o=s)}),a}function Fr(e,t,n,r,i,a){if(!e)return null;let o=K(e,i),s=null,c=-1/0,l=t===`Left`?1:-1;return G(e,r).forEach(e=>{if(n.has(e))return;let t=K(e,i).clone().sub(o),u=Ar(e,r,a),d=t.x*l*6+Math.max(t.y,0)*1.5-Math.abs(t.z)*.8+u*.25;d<=c||(s=e,c=d)}),s}function Ir(e,t,n,r,i){let a=G(e,n);if(a.length===0||a.length>=3)return null;let o=K(e,r),s=null,c=-1/0;return a.forEach(e=>{let a=K(e,r).clone().sub(o),l=Ar(e,n,i)*12;t===`positiveX`?l+=a.x*5-Math.abs(a.y)*.8-Math.abs(a.z)*.8:t===`negativeX`?l+=-a.x*5-Math.abs(a.y)*.8-Math.abs(a.z)*.8:t===`up`?l+=a.y*6-Math.abs(a.x)*1.2-Math.abs(a.z)*.8:l+=-a.y*6+Math.abs(a.x)*.8-Math.abs(a.z)*.8,!(l<=c)&&(s=e,c=l)}),s}function Lr(e,t,n,r,i){if(!e)return[];let a=[e],o=new Set(a);for(;a.length<kr;){let e=a[a.length-1],s=Ir(e,t,n,r,i);if(!s||o.has(s))break;a.push(s),o.add(s)}return a}function Rr(e,t,n,r,i,a){if(!e)return null;let o=K(e,i),s=null,c=-1/0,l=t===`Left`?1:-1;return G(e,r).forEach(e=>{if(n.has(e))return;let t=K(e,i).clone().sub(o),u=Ar(e,r,a),d=-t.y*6+t.x*l*4-Math.abs(t.z)*.6+u*.2;d<=c||(s=e,c=d)}),s}function zr(e,t,n){if(t.length===0)return;let r=`${n}Shoulder`,i=`${n}UpperArm`,a=`${n}LowerArm`,o=`${n}Hand`;if(t.length>=4){q(e,t[0],r),q(e,t[1],i),q(e,t[2],a),q(e,t[3],o);return}if(t.length===3){q(e,t[0],i),q(e,t[1],a),q(e,t[2],o);return}if(t.length===2){q(e,t[0],i),q(e,t[1],a);return}q(e,t[0],i)}function Br(e,t,n){t.length!==0&&(q(e,t[0],`${n}UpperLeg`),t.length>=2&&q(e,t[1],`${n}LowerLeg`),t.length>=3&&q(e,t[2],`${n}Foot`))}function Vr(e){let t=e.bones.reduce((e,t)=>Er.test(t.name)?e+1:e,0);return t>=Or&&t/Math.max(e.bones.length,1)>=.6}function Hr(e){if(!Vr(e))return new Map;let t=new Map,n=new Set(e.bones),r=new Map,i=new Map,a=Mr(e,n,r,i),o=a?jr(a,`up`,n,r,i):null,s=Nr(o,n,r),c=s[s.length-1]??null,l=new Set,u=Pr(c,l,n,r);u&&l.add(u);let d=Fr(c,`Left`,l,n,r,i);d&&l.add(d);let f=Fr(c,`Right`,l,n,r,i),p=Lr(u,`up`,n,r,i),m=Lr(d,`positiveX`,n,r,i),h=Lr(f,`negativeX`,n,r,i),g=new Set;o&&g.add(o);let _=Rr(a,`Left`,g,n,r,i);_&&g.add(_);let v=Rr(a,`Right`,g,n,r,i),y=Lr(_,`down`,n,r,i),b=Lr(v,`down`,n,r,i);return q(t,a,`Hips`),s.length>=2?(q(t,s[0],`Spine`),q(t,c,`Chest`)):s.length===1&&q(t,c,`Chest`),p.length>=1&&q(t,p[0],`Neck`),p.length>=2&&q(t,p[1],`Head`),zr(t,m,`Left`),zr(t,h,`Right`),Br(t,y,`Left`),Br(t,b,`Right`),t}var Ur={root:`hips`,c_spine0:`spine`,c_spine1:`spine`,c_spine2:`chest`,c_spine3:`upperChest`,c_neck:`neck`,c_head:`head`,l_clavicle:`leftShoulder`,l_uparm:`leftUpperArm`,l_lowarm:`leftLowerArm`,l_wrist:`leftHand`,r_clavicle:`rightShoulder`,r_uparm:`rightUpperArm`,r_lowarm:`rightLowerArm`,r_wrist:`rightHand`,l_upleg:`leftUpperLeg`,l_lowleg:`leftLowerLeg`,l_foot:`leftFoot`,r_upleg:`rightUpperLeg`,r_lowleg:`rightLowerLeg`,r_foot:`rightFoot`},Wr={Root:`hips`,Hips:`hips`,Spine:`spine`,Chest:`chest`,Neck:`neck`,Head:`head`,LeftShoulder:`leftShoulder`,LeftUpperArm:`leftUpperArm`,LeftLowerArm:`leftLowerArm`,LeftHand:`leftHand`,RightShoulder:`rightShoulder`,RightUpperArm:`rightUpperArm`,RightLowerArm:`rightLowerArm`,RightHand:`rightHand`,LeftUpperLeg:`leftUpperLeg`,LeftLowerLeg:`leftLowerLeg`,LeftFoot:`leftFoot`,RightUpperLeg:`rightUpperLeg`,RightLowerLeg:`rightLowerLeg`,RightFoot:`rightFoot`};function Gr(e,t){if(t?.humanoid)return{getNormalizedBoneNode:e=>t.humanoid.getNormalizedBoneNode(e)??null,update:e=>t.update(e),vrm:t};let n=new Map,r=[];return e.traverse(e=>{if(e instanceof o.SkinnedMesh&&r.push(e.skeleton),!(e instanceof o.Bone))return;let t=e.name,i=Ur[t];i&&!n.has(i)&&n.set(i,e);let a=Wr[t];a&&!n.has(a)&&n.set(a,e)}),r.forEach(e=>{Hr(e).forEach((e,t)=>{let r=Wr[e];r&&!n.has(r)&&n.set(r,t)})}),{getNormalizedBoneNode:e=>n.get(e)??null,update:()=>{},vrm:null}}function Kr(e){let t=(0,s.clone)(e);return dr(t),t.traverse(e=>{if(e instanceof o.Mesh){if(Array.isArray(e.material)){e.material=e.material.map(e=>e.clone());return}e.material=e.material.clone()}}),t}function qr({url:e}){let n=(0,r.useGLTF)(e,`/draco/`,!0,(0,t.useMemo)(()=>ur(e),[e])),i=n.userData?.vrm??null,a=(0,t.useMemo)(()=>i?(fr(i),i.scene):Kr(n.scene),[n.scene,i]),o=(0,t.useMemo)(()=>Gr(a,i),[a,i]);return{scene:a,humanoid:o,bones:(0,t.useMemo)(()=>mr(o),[o])}}var Jr=12,Yr=new o.Quaternion,J=new o.Quaternion,Xr=new o.Quaternion,Zr=new o.Vector3,Qr=new o.Vector3,$r=new o.Vector3,ei=new o.Vector3,ti=new o.Vector3,ni=new o.Vector3,ri=new o.Vector3,ii=new o.Vector3,ai=new o.Vector3,oi=new o.Quaternion,si=new o.Quaternion,ci=new o.Quaternion,li=new o.Quaternion,ui={Hips:[`Spine`,`Chest`,`Neck`],Spine:[`Chest`,`Neck`],Chest:[`Neck`,`Head`],Neck:[`Head`],LeftShoulder:[`LeftUpperArm`],LeftUpperArm:[`LeftLowerArm`],LeftLowerArm:[`LeftHand`],RightShoulder:[`RightUpperArm`],RightUpperArm:[`RightLowerArm`],RightLowerArm:[`RightHand`],LeftUpperLeg:[`LeftLowerLeg`],LeftLowerLeg:[`LeftFoot`],RightUpperLeg:[`RightLowerLeg`],RightLowerLeg:[`RightFoot`]},di={Hips:[[`LeftUpperLeg`,`RightUpperLeg`],[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`]],Spine:[[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`],[`LeftUpperLeg`,`RightUpperLeg`]],Chest:[[`LeftShoulder`,`RightShoulder`],[`LeftUpperArm`,`RightUpperArm`],[`LeftUpperLeg`,`RightUpperLeg`]]},fi={Hips:[L.RIGHT_HIP,L.LEFT_HIP],Spine:[L.RIGHT_SHOULDER,L.LEFT_SHOULDER],Chest:[L.RIGHT_SHOULDER,L.LEFT_SHOULDER]};function pi(e){return e.startsWith(`Left`)?`Right${e.slice(4)}`:e.startsWith(`Right`)?`Left${e.slice(5)}`:e}function mi(e,t,n,r){let i=ui[e];if(!i)return!1;for(let e=0;e<i.length;e+=1){let a=n.get(i[e])?.[0];if(!(!a||a.bone===t.bone||!t.restWorldPosition||!t.restParentWorldQuaternion||!a.restWorldPosition)&&(r.copy(a.restWorldPosition).sub(t.restWorldPosition),!(r.lengthSq()<1e-6)))return r.applyQuaternion(oi.copy(t.restParentWorldQuaternion).invert()).normalize(),!0}return!1}function hi(e){return e in di}function gi(e,t,n,r){let i=di[e];if(!i||!t.restParentWorldQuaternion)return!1;for(let e=0;e<i.length;e+=1){let[a,o]=i[e],s=n.get(a)?.[0],c=n.get(o)?.[0];if(!(!s?.restWorldPosition||!c?.restWorldPosition)&&(r.copy(c.restWorldPosition).sub(s.restWorldPosition).applyQuaternion(oi.copy(t.restParentWorldQuaternion).invert()),!(r.lengthSq()<1e-6)))return r.normalize(),!0}return!1}function _i(e,t,n,r,i){let a=fi[e];return!a||!It(a[0],a[1],t,i,n)?!1:(i.applyQuaternion(ci.copy(r).invert()).normalize(),i.lengthSq()>=1e-6)}function vi(e,t,n,r,i,a,o,s){if(!gi(e,t,n,ei)||!_i(e,r,i,a,ti)||(ni.copy(ei).applyQuaternion(J),ri.copy(ni).projectOnPlane($r).normalize(),ii.copy(ti).projectOnPlane($r).normalize(),ri.lengthSq()<1e-6||ii.lengthSq()<1e-6))return s.copy(J),!1;ai.crossVectors(ri,ii);let c=Math.atan2($r.dot(ai),ri.dot(ii));return li.setFromAxisAngle($r,c),s.copy(li).multiply(J),o!==void 0&&s.slerp(Xr,1-o),!0}function yi(){let e=(0,t.useRef)(new o.Timer),n=(0,t.useRef)(new Map);return(0,t.useMemo)(()=>({clockRef:e,prevRotationsRef:n}),[])}function bi(e,t,n,r={}){if(t.size===0)return;let{coordinateSpace:i=`normalized`,excludeBones:a}=r;n.clockRef.current.update();let o=n.clockRef.current.getDelta(),s=Math.min(1,o*Jr);for(let[n,r]of t){let o=Sr(n);if(a?.has(o))continue;let c=pi(o);if(o!==n&&t.has(o))continue;let l=Bt(c);if(!l)continue;let u=l&&Lt(c,e,Zr,i);if(!u)continue;let d=!1,f=Rt(c);for(let n of r){let{bone:r,restQuaternion:a}=n;if(u&&mi(o,n,t,Qr))r.parent?(r.parent.updateWorldMatrix(!0,!1),r.parent.getWorldQuaternion(si)):(r.updateWorldMatrix(!0,!1),si.identity()),$r.copy(Zr).applyQuaternion(ci.copy(si).invert()).normalize(),J.setFromUnitVectors(Qr,$r),hi(o)&&vi(o,n,t,e,i,si,f,J)||f!==void 0&&J.slerp(Xr,1-f),Yr.copy(J).multiply(a);else{if(d||=zt(c,e,J,i),!d)continue;Yr.copy(a).multiply(J)}r.quaternion.slerp(Yr,s),r.updateWorldMatrix(!1,!0)}}}function xi(e,t){ir(e),t.prevRotationsRef.current.clear()}function Si(e,t,n,r){let i=Math.min(1,n*Jr);for(let[n,a]of e){let e=Sr(n);if(!(r&&!r.has(e)))for(let{bone:e,restQuaternion:n}of a)e.quaternion.slerp(n,t*i)}}var Ci=1/60,wi=1/240,Ti=1/12;function Ei(e){return Number.isFinite(e)?v(e,wi,Ti):Ci}function Y(e,t){let n=v(e,0,1);if(n===0||n===1)return n;let r=Ei(t)/Ci;return 1-(1-n)**r}var Di=50*Math.PI/180,Oi=30*Math.PI/180,ki=3;function Ai(e){return Math.abs(e)<Di?`unknown`:e>=0?`positive`:`negative`}function ji(e){return e===`positive`?1:e===`negative`?-1:0}var Mi=class{_committedYawDirection=`unknown`;_pendingYawDirection=`unknown`;_pendingCount=0;update(e,t){let n=Math.abs(t),r=Ai(t);return e===`back`||n<Oi?(this.reset(),this._buildState(r,`unknown`,t)):this._committedYawDirection===`unknown`?r===`unknown`?(this._clearPending(),this._buildState(r,`unknown`,t)):(this._pendingYawDirection===r?this._pendingCount+=1:(this._pendingYawDirection=r,this._pendingCount=1),this._pendingCount>=ki?(this._committedYawDirection=this._pendingYawDirection,this._clearPending(),this._buildState(r,this._committedYawDirection,n*ji(this._committedYawDirection))):this._buildState(r,r,t)):this._buildState(r,this._committedYawDirection,n*ji(this._committedYawDirection))}reset(){this._committedYawDirection=`unknown`,this._clearPending()}_buildState(e,t,n){return{rawYawDirection:e,yawDirection:t,committedYawDirection:this._committedYawDirection,pendingYawDirection:this._pendingYawDirection,pendingCount:this._pendingCount,stableYaw:n}}_clearPending(){this._pendingYawDirection=`unknown`,this._pendingCount=0}},Ni=80*Math.PI/180,Pi=100*Math.PI/180,Fi=25*Math.PI/180,Ii=8,Li=5,Ri=5,zi=5,Bi=.5,Vi=.3,Hi=.2,Ui=5,Wi=8;function Gi(e){return e?.visibility??0}function Ki(e){if(!e||e.length<33)return{shoulderOrder:!1,noseVisible:!1,earSymmetry:!1};let t=e[L.LEFT_SHOULDER],n=e[L.RIGHT_SHOULDER],r=e[L.NOSE],i=e[L.LEFT_EAR],a=e[L.RIGHT_EAR],o=t.x<n.x,s=Gi(r)>Bi,c=Gi(i),l=Gi(a);return{shoulderOrder:o,noseVisible:s,earSymmetry:Math.abs(c-l)<Vi&&Math.max(c,l)>Hi}}function qi(e){let t=0;return e.shoulderOrder&&(t+=1),e.noseVisible&&(t+=1),e.earSymmetry&&(t+=1),t>=2}function Ji(e){return e<Ni?`front`:e<Pi?`side`:`back`}var Yi=class{_zone=`front`;_consecutiveCount=0;_lastRawZone=`front`;_2dFrontCount=0;_2dBackCount=0;_2dIsFront=!0;_yawDirectionStabilizer=new Mi;update(e,t,n){let r=t??0,i=n??0,a=Math.abs(i)>Fi,o;t===void 0?o=this._resolve2dFallback(e):(o=Ji(Math.abs(t)),o===`front`&&this._zone!==`front`&&(qi(Ki(e))||(o=`back`))),this._applyHysteresis(o);let s=t===void 0?null:this._yawDirectionStabilizer.update(this._zone,r);return t===void 0&&this._yawDirectionStabilizer.reset(),{zone:this._zone,rawZone:o,isFrontFacing:this._zone===`front`,pitchClamped:a,bodyYaw:s?.stableYaw??r,bodyPitch:i,rawYawDirection:s?.rawYawDirection??`unknown`,yawDirection:s?.yawDirection??`unknown`,committedYawDirection:s?.committedYawDirection??`unknown`}}reset(){this._zone=`front`,this._consecutiveCount=0,this._lastRawZone=`front`,this._2dFrontCount=0,this._2dBackCount=0,this._2dIsFront=!0,this._yawDirectionStabilizer.reset()}_resolve2dFallback(e){return qi(Ki(e))?(this._2dFrontCount+=1,this._2dBackCount=0):(this._2dBackCount+=1,this._2dFrontCount=0),this._2dIsFront?this._2dBackCount>=Ui&&(this._2dIsFront=!1):this._2dFrontCount>=Wi&&(this._2dIsFront=!0),this._2dIsFront?`front`:`back`}_applyHysteresis(e){e===this._lastRawZone?this._consecutiveCount+=1:(this._lastRawZone=e,this._consecutiveCount=1);let t=this._getTransitionThreshold(this._zone,e);t!==null&&this._consecutiveCount>=t&&(this._zone=e)}_getTransitionThreshold(e,t){return e===t?null:e===`front`&&t===`side`||e===`front`&&t===`back`?Ii:e===`side`&&t===`back`?Li:e===`back`&&t===`side`?Ri:e===`side`&&t===`front`?zi:e===`back`&&t===`front`?Ri:Ii}},Xi=Math.PI/2;function Zi(e){return e>=0?Xi:-Xi}var Qi=class{_isFrozen=!1;_frozenYaw=null;update(e,t){let n=Math.abs(t);return this._isFrozen?e!==`back`&&n<Xi&&this.reset():e!==`front`&&n>=Xi&&(this._isFrozen=!0,this._frozenYaw=Zi(t)),{isFrozen:this._isFrozen,frozenYaw:this._frozenYaw}}reset(){this._isFrozen=!1,this._frozenYaw=null}};function $i(e,t){return typeof e==`boolean`?{mirrorX:e,sourceWidth:0,sourceHeight:0,target:t??new o.Vector3}:{mirrorX:e.mirrorX??!1,sourceWidth:e.sourceWidth??0,sourceHeight:e.sourceHeight??0,target:e.target??t??new o.Vector3}}function X(e,t,n,r=!1,i){let a=$i(r,i),o=$e(t,n,a.sourceWidth||t,a.sourceHeight||n),s=a.mirrorX?1-e.x:e.x,c=o.x+s*o.width,l=o.y+e.y*o.height,u=c-t*.5,d=n*.5-l,f=-(e.z??0)*o.width*.5;return a.target.set(u,d,f)}function ea(e,t,n,r,i=!1,a){return X({x:(e.x+t.x)/2,y:(e.y+t.y)/2,z:((e.z??0)+(t.z??0))/2,visibility:Math.min(e.visibility??0,t.visibility??0)},n,r,i,a)}function ta(e,t,n,r){let i=(e.x-t.x)*n,a=(e.y-t.y)*r;return Math.sqrt(i*i+a*a)}var na=.45,ra=.72,ia=1.02,aa=1.1,oa=Math.PI/6,sa=1e-4,ca=sa*sa,la=.35,ua=.6,da=new o.Vector3,fa=new o.Vector3,Z=new o.Vector3,Q=new o.Vector3,pa=new o.Vector3,ma=new o.Vector3,ha=new o.Matrix4;function ga(e,t,n){let r=Math.min(Math.abs(n),aa),i=1/Math.max(Math.cos(r),na)*e,a=t*ra;return Math.max(i,a,e)}function _a({projectedShoulderWidth:e,projectedTorsoHeight:t,bodyYaw:n,worldLandmarks:r}){let i=ga(e,t,n),a=xa(t,r);if(!a)return i;let o=v((Math.abs(n)-la)/ua,0,1);return i+(Math.max(i,a)-i)*o}function va(e){return e?v(e.hips.rotation.y*.85+e.chest.y*.15,-aa,aa):0}function ya(e,t,n){let r=e.x<=t.x?e:t,i=e.x<=t.x?t:e,a=i.x-r.x;if(a<=sa)return 0;let o=-(i.y-r.y);return v(Math.atan2(o,a)*v(1-Math.abs(n)/aa,0,1),-oa,oa)}function ba({leftShoulder:e,rightShoulder:t,leftHip:n,rightHip:r},i=new o.Quaternion){return da.copy(e).add(t).multiplyScalar(.5),fa.copy(n).add(r).multiplyScalar(.5),Z.copy(t).sub(e),Z.lengthSq()<=ca||(Z.normalize(),Q.copy(da).sub(fa),pa.copy(Z).multiplyScalar(Q.dot(Z)),Q.sub(pa),Q.lengthSq()<=ca)||(Q.normalize(),ma.crossVectors(Z,Q),ma.lengthSq()<=ca)?null:(ma.normalize(),Q.crossVectors(ma,Z).normalize(),ha.makeBasis(Z,Q,ma),i.setFromRotationMatrix(ha))}function xa(e,t){if(!t||t.length<=L.RIGHT_HIP||e<=sa)return null;let n=t[L.LEFT_SHOULDER],r=t[L.RIGHT_SHOULDER],i=t[L.LEFT_HIP],a=t[L.RIGHT_HIP];if(!n||!r||!i||!a)return null;let o=Ca(n,r),s=Ca(Sa(n,r),Sa(i,a));return o<=sa||s<=sa?null:e*v(o/s,ra,ia)}function Sa(e,t){return{x:(e.x+t.x)*.5,y:(e.y+t.y)*.5,z:((e.z??0)+(t.z??0))*.5}}function Ca(e,t){let n=e.x-t.x,r=e.y-t.y,i=(e.z??0)-(t.z??0);return Math.sqrt(n*n+r*r+i*i)}var $=1e-4,wa=.15,Ta=8,Ea=1e-4,Da=1.45,Oa=.35,ka=10,Aa=.08,ja=.42,Ma=.82,Na=Math.PI/4,Pa=.76,Fa=.88,Ia=1.32,La=.2,Ra=1.3,za=.08,Ba=.14,Va=.55,Ha=.2,Ua=.18,Wa=.55,Ga=6,Ka=.3,qa=.08,Ja=.05,Ya=1.35,Xa=.7,Za=new o.Vector3(0,1,0),Qa=new o.Quaternion,$a=new o.Vector3,eo=new o.Quaternion,to=new o.Euler(0,0,0,`YXZ`),no=[[L.LEFT_EAR,L.RIGHT_EAR],L.NOSE,[L.LEFT_SHOULDER,L.RIGHT_SHOULDER]],ro=[[L.LEFT_ANKLE,L.RIGHT_ANKLE],[L.LEFT_HEEL,L.RIGHT_HEEL],[L.LEFT_FOOT_INDEX,L.RIGHT_FOOT_INDEX]];function io(){return{leftShoulder:new o.Vector3,rightShoulder:new o.Vector3,leftHip:new o.Vector3,rightHip:new o.Vector3,shoulderCenter:new o.Vector3,hipCenter:new o.Vector3,bodyTop:new o.Vector3,bodyBottom:new o.Vector3,anchor:new o.Vector3,scaledAnchor:new o.Vector3,position:new o.Vector3,scale:new o.Vector3(1,1,1),rootQuaternion:new o.Quaternion,bodyPitch:0,bodyRoll:0,stabilizedBodyHeightScale:null,missingBodyHeightFrames:0,stableTorsoHeightToShoulderRatio:null,smoothedGlobalScale:1,hasSmoothedGlobalScale:!1,effectiveYaw:0,previousDepthProxy:0,scaleVelocity:0,smoothedXDeviation:1,smoothedAnchor:new o.Vector3,hasSmoothedAnchor:!1}}function ao(e,t,n,r,i,a={}){if(t.length<33)return!1;let s=a.deltaSeconds;X(t[L.LEFT_SHOULDER],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.leftShoulder}),X(t[L.RIGHT_SHOULDER],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.rightShoulder}),X(t[L.LEFT_HIP],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.leftHip}),X(t[L.RIGHT_HIP],n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i.rightHip}),i.shoulderCenter.copy(i.leftShoulder).add(i.rightShoulder).multiplyScalar(.5),i.hipCenter.copy(i.leftHip).add(i.rightHip).multiplyScalar(.5);let c=ba({leftShoulder:i.rightShoulder,rightShoulder:i.leftShoulder,leftHip:i.rightHip,rightHip:i.leftHip},Qa),l=c?so(c):0,u=_o(a.bodyYaw,l);c?(i.rootQuaternion.copy(c),co(i.rootQuaternion,i)):(i.rootQuaternion.identity(),i.bodyPitch=0,i.bodyRoll=0),i.effectiveYaw=u;let d=yo(i.leftShoulder,i.rightShoulder),f=po(yo(i.shoulderCenter,i.hipCenter),i.shoulderCenter.distanceTo(i.hipCenter),i.bodyPitch),p=_a({projectedShoulderWidth:d,projectedTorsoHeight:f,bodyYaw:u,worldLandmarks:a.worldLandmarks}),{torsoHeight:m,leanInfluence:h}=mo(f,p,e,i,s),g=m/Math.max(e.referenceTorsoHeight,$),_=vo(t,n,r,m,i,a),y=ho(_===null?null:_/Math.max(e.trackingHeight,$),i,s),b=y!==null&&g>$?v(y,g*Xa,g*Ya):y,x=b===null?1:v(Va+h*Ha,Va,Va+Ha),S=1-x,C=go(v(b===null?g:g*x+b*S,wa,Ta)*(a.scaleMultiplier??1),i,m,s),w=.1,T=e.referenceWidth/Math.max(e.referenceTorsoHeight,$),E=m>$?p/m:T,D=v(T>$?E/T:1,1-w,1+w),O=Y(.35,s);i.smoothedXDeviation=o.MathUtils.lerp(i.smoothedXDeviation,D,O),i.scale.set(C*i.smoothedXDeviation*(a.scaleX??1),C*(a.scaleY??1),C*(a.scaleZ??1)),i.anchor.copy(i.shoulderCenter).add(i.hipCenter).multiplyScalar(.5);let k=Y(.4,s);return i.hasSmoothedAnchor?i.smoothedAnchor.lerp(i.anchor,k):(i.smoothedAnchor.copy(i.anchor),i.hasSmoothedAnchor=!0),i.scaledAnchor.set(e.anchor.x*C,e.anchor.y*C,e.anchor.z*C),i.position.copy(i.smoothedAnchor).sub(i.scaledAnchor),i.position.z+=a.depthOffset??0,!0}function oo(e,t){e.position.copy(t.position),e.scale.copy(t.scale)}function so(e){return $a.set(0,0,1).applyQuaternion(e),$a.y=0,$a.lengthSq()<=Ea?0:($a.normalize(),Math.atan2($a.x,$a.z))}function co(e,t){eo.copy(e).premultiply(Qa.setFromAxisAngle(Za,-Math.PI)),to.setFromQuaternion(eo,`YXZ`),t.bodyPitch=-y(to.x),t.bodyRoll=-y(to.z)}function lo(e,t){if(e<=$)return e;let n=Math.min(Math.abs(t),Na),r=uo(n);if(r<=0)return e;let i=1/Math.max(Math.cos(n),Pa);return e*o.MathUtils.lerp(1,i,r*Ma)}function uo(e){return v((e-Aa)/ja,0,1)}function fo(e,t){if(e<=$||!Number.isFinite(t)||t<=e)return e;let n=v(t,e,e*Ia);return o.MathUtils.lerp(e,n,Fa)}function po(e,t,n){return Math.max(e,lo(e,n),fo(e,t))}function mo(e,t,n,r,i){if(e<=$||t<=$)return{torsoHeight:e,leanInfluence:0};let a=n.referenceWidth>$?n.referenceTorsoHeight/n.referenceWidth:1,s=e/t,c=uo(Math.abs(r.bodyPitch));r.stableTorsoHeightToShoulderRatio===null&&(r.stableTorsoHeightToShoulderRatio=a);let l=Y(La,i),u=c>.18?Math.max(r.stableTorsoHeightToShoulderRatio,s):s;r.stableTorsoHeightToShoulderRatio=o.MathUtils.lerp(r.stableTorsoHeightToShoulderRatio,u,l);let d=v(t*r.stableTorsoHeightToShoulderRatio,e,e*Ra),f=v((d/Math.max(e,$)-1-za)/Ba,0,1),p=Math.max(c,f);return{torsoHeight:o.MathUtils.lerp(e,d,p),leanInfluence:p}}function ho(e,t,n){if(e!==null){t.missingBodyHeightFrames=0;let r=Y(Oa,n);return t.stabilizedBodyHeightScale=t.stabilizedBodyHeightScale===null?e:o.MathUtils.lerp(t.stabilizedBodyHeightScale,e,r),t.stabilizedBodyHeightScale}return t.stabilizedBodyHeightScale===null?(t.missingBodyHeightFrames=0,null):(t.missingBodyHeightFrames+=1,t.missingBodyHeightFrames>ka?(t.stabilizedBodyHeightScale=null,null):t.stabilizedBodyHeightScale)}function go(e,t,n,r){if(!t.hasSmoothedGlobalScale)return t.smoothedGlobalScale=e,t.previousDepthProxy=n,t.scaleVelocity=0,t.hasSmoothedGlobalScale=!0,e;let i=t.previousDepthProxy,a=1;i>Ja&&n>Ja&&(a=v(n/i,1-qa,1+qa)),t.previousDepthProxy=n;let s=t.smoothedGlobalScale*a,c=s>0?Math.abs(e-s)/s:0,l=Y(Ka,r);t.scaleVelocity=o.MathUtils.lerp(t.scaleVelocity,c,l);let u=Y(v(Ua+t.scaleVelocity*Ga,Ua,Wa),r);return t.smoothedGlobalScale=o.MathUtils.lerp(s,e,u),t.smoothedGlobalScale}function _o(e,t){let n=e??0;return Math.abs(n)>=Math.abs(t)?n:t}function vo(e,t,n,r,i,a){let o=bo(no,e,t,n,i.bodyTop,a),s=bo(ro,e,t,n,i.bodyBottom,a);if(!o||!s)return null;let c=po(yo(i.bodyTop,i.bodyBottom),i.bodyTop.distanceTo(i.bodyBottom),i.bodyPitch);return c<=r*Da?null:c}function yo(e,t){let n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function bo(e,t,n,r,i,a){for(let o=0;o<e.length;o+=1)if(xo(e[o],t,n,r,i,a))return!0;return!1}function xo(e,t,n,r,i,a){if(typeof e==`number`){let o=t[e];return!o||(o.visibility??0)<.4?!1:(X(o,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i}),!0)}let o=t[e[0]],s=t[e[1]];if(!o||!s||(o.visibility??0)<.4||(s.visibility??0)<.4)return!1;X(o,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight,target:i});let c=X(s,n,r,{mirrorX:!0,sourceWidth:a.sourceWidth,sourceHeight:a.sourceHeight});return i.add(c).multiplyScalar(.5),!0}var So=new Set([`LeftHand`,`RightHand`]),Co=new Set([`Hips`,`Spine`,`Chest`]),wo=20,To=.436,Eo=.175,Do=1.396,Oo=.349,ko=.28,Ao=.55,jo=.7,Mo=24*Math.PI/180,No=22*Math.PI/180,Po=.35,Fo=new o.Euler(0,0,0,`YXZ`);function Io(e,t,n){let r=y(t-e);return y(Math.abs(r)<=n?t:e+Math.sign(r)*n)}function Lo(){return{transformScratch:io(),facingDetector:new Yi,yawFreezeController:new Qi,displayYaw:null,displayPitch:null,displayRoll:null,lastFacingState:null,hasInitialPosition:!1}}function Ro(e){e.transformScratch=io(),e.facingDetector.reset(),e.yawFreezeController.reset(),e.displayYaw=null,e.displayPitch=null,e.displayRoll=null,e.lastFacingState=null,e.hasInitialPosition=!1}function zo({fitProfile:e,garmentRoot:t,boneBindingMap:n,poseRefs:r,motionState:i,landmarks:a,worldLandmarks:s=null,viewportWidth:c,viewportHeight:l,poseFrameWidth:u,poseFrameHeight:d,delta:f}){if(!a||a.length<33)return null;let p=i.transformScratch;ao(e,a,c,l,p,{sourceWidth:u,sourceHeight:d,worldLandmarks:s,deltaSeconds:f});let m=p.shoulderCenter.y-p.hipCenter.y,h=p.shoulderCenter.distanceTo(p.hipCenter),g=Math.acos(v(Math.abs(m)/Math.max(h,.001),0,1)),_=p.effectiveYaw,y=_>0?_-Math.PI:_+Math.PI,b=i.facingDetector.update(a,y,g),x=b.bodyYaw,S=i.displayYaw===null?x:Io(i.displayYaw,x,wo*f),C=i.yawFreezeController.update(b.zone,x),w=C.isFrozen,T=w?C.frozenYaw??S:S,E=b.zone===`side`?.6:1,D=v(p.bodyPitch*Ao,-Mo,Mo),O=v(p.bodyRoll*jo*E,-No,No);if(i.displayYaw=T,i.lastFacingState=b,b.zone!==`back`){if(!w){t.scale.copy(p.scale),i.hasInitialPosition?t.position.lerp(p.position,Y(Po,f)):(t.position.copy(p.position),i.hasInitialPosition=!0);let e=Y(ko,f);i.displayPitch=i.displayPitch===null?D:o.MathUtils.lerp(i.displayPitch,D,e),i.displayRoll=i.displayRoll===null?O:o.MathUtils.lerp(i.displayRoll,O,e)}t.quaternion.setFromEuler(Fo.set(i.displayPitch??0,T,i.displayRoll??0))}return b.zone===`front`&&!w?(bi(a,n,r,{coordinateSpace:`normalized`,excludeBones:So}),b.pitchClamped&&Si(n,v((Math.abs(g)-To)/Eo,0,1),f,Co)):b.zone===`side`&&!w&&(bi(a,n,r,{coordinateSpace:`normalized`,excludeBones:So}),Si(n,v((Math.abs(x)-Do)/Oo,0,1),f)),b}function Bo({garmentRootRef:e,boneBindingMap:r,fitProfile:i,landmarks:a,worldLandmarks:o,poseFrameWidth:s,poseFrameHeight:c}){let{viewport:l}=(0,n.useThree)(),u=yi(),d=(0,t.useRef)(Lo());return(0,t.useEffect)(()=>{let t=e.current,n=d.current;return t&&(t.position.set(0,0,0),t.scale.set(1,1,1),t.quaternion.identity()),xi(r,u),Ro(n),()=>{xi(r,u),Ro(n)}},[r,i,e,u]),(0,n.useFrame)((t,n)=>{let f=e.current;!f||!i||zo({fitProfile:i,garmentRoot:f,boneBindingMap:r,poseRefs:u,motionState:d.current,landmarks:a,worldLandmarks:o,viewportWidth:l.width,viewportHeight:l.height,poseFrameWidth:s,poseFrameHeight:c,delta:n})}),null}function Vo(e){return e?e.map(e=>({x:e.x,y:e.y,z:e.z,visibility:typeof e.visibility==`number`?e.visibility:0})):null}function Ho({url:e,landmarks:n,worldLandmarks:r,poseFrameWidth:a,poseFrameHeight:s,debugMaterials:c=!1,onLoadStateChange:l}){let u=(0,t.useRef)(null),{scene:d,bones:f}=qr({url:e}),p=(0,t.useMemo)(()=>Vo(n),[n]),m=(0,t.useMemo)(()=>Vo(r),[r]),h=(0,t.useMemo)(()=>(d.updateMatrixWorld(!0),rr(d,f,1)),[f,d]);return(0,t.useEffect)(()=>{d.traverse(e=>{if(e instanceof o.Mesh){if(e.name.startsWith(`Collision`)){e.visible=!1;return}e.visible=!0,(Array.isArray(e.material)?e.material:[e.material]).forEach(e=>{`opacity`in e&&(c?(e.transparent=!0,e.opacity=.34,e.depthWrite=!1,e.side=o.DoubleSide):(e.transparent=!1,e.opacity=1,e.depthWrite=!0,e.side=o.FrontSide),e.needsUpdate=!0)})}})},[d,c]),(0,t.useEffect)(()=>(l?.({loaded:!0,error:null}),()=>{l?.({loaded:!1,error:null})}),[l,e]),(0,i.jsxs)(`group`,{ref:u,children:[(0,i.jsx)(`primitive`,{object:d}),(0,i.jsx)(Bo,{garmentRootRef:u,boneBindingMap:f,fitProfile:h,landmarks:p,worldLandmarks:m,poseFrameWidth:a,poseFrameHeight:s})]})}var Uo=1;function Wo(e){let t=new o.VideoTexture(e);return t.minFilter=o.NearestFilter,t.magFilter=o.NearestFilter,t.generateMipmaps=!1,t.colorSpace=o.SRGBColorSpace,t.needsUpdate=!0,t}function Go(e,t,n){if(!n||n.width===0||n.height===0)return[e,t];let r=e/t,i=n.width/n.height;return r>i?[e,e/i]:[t*i,t]}function Ko({videoElement:e,webcamReady:r}){let{viewport:a}=(0,n.useThree)(),[o,s]=(0,t.useState)(null),[c,l]=(0,t.useState)(null),u=(0,t.useRef)(null),d=(0,t.useRef)(null),f=(0,t.useRef)(0);(0,t.useEffect)(()=>{let t=e;if(!r||!t){d.current!==null&&(clearTimeout(d.current),d.current=null),f.current=0;return}let n=!1,i=()=>{if(n||u.current)return;if(t.videoWidth===0||t.videoHeight===0){d.current=setTimeout(i,100);return}let e=Wo(t);u.current=e,f.current=0,l({width:t.videoWidth,height:t.videoHeight}),s(e)};return t.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA&&t.videoWidth>0&&t.videoHeight>0?i():(t.addEventListener(`loadeddata`,i),t.addEventListener(`loadedmetadata`,i),t.addEventListener(`playing`,i),d.current=setTimeout(i,200)),()=>{n=!0,d.current!==null&&(clearTimeout(d.current),d.current=null),t.removeEventListener(`loadeddata`,i),t.removeEventListener(`loadedmetadata`,i),t.removeEventListener(`playing`,i),u.current&&=(u.current.dispose(),null),f.current=0,s(null),l(null)}},[e,r]),(0,n.useFrame)(()=>{!u.current||!u.current.image||(f.current=(f.current+1)%Uo,f.current===0&&(u.current.needsUpdate=!0))});let[p,m]=(0,t.useMemo)(()=>Go(a.width,a.height,c),[c,a.height,a.width]);return!r||!o?null:(0,i.jsxs)(`mesh`,{position:[0,0,-20],renderOrder:-1,scale:[-1,1,1],children:[(0,i.jsx)(`planeGeometry`,{args:[p,m]}),(0,i.jsx)(`meshBasicMaterial`,{map:o,depthTest:!1,depthWrite:!1,toneMapped:!1})]})}function qo({onReady:e}){return(0,t.useEffect)(()=>(e?.(!0),()=>{e?.(!1)}),[e]),null}function Jo(){return(0,i.jsx)(`color`,{attach:`background`,args:[`#000000`]})}function Yo({garmentUrl:e,enabled:n=!0,width:a=1280,height:o=720,facingMode:s=`user`,mockMode:c=!1,modelComplexity:l,numPoses:u,minDetectionConfidence:d,minTrackingConfidence:f,outputSegmentationMasks:p,viewportWidth:m=0,viewportHeight:h=0,measurementEnabled:g=!0,autoStartMeasurement:v=!1,measurementConfig:y,fitType:b=`regular`,garmentScaleHint:x=null,bodyPresetOptions:S,className:C,style:w,debugMaterials:T=!1,showEnvironment:E=!1,showStats:D=!1,showWebcamBackground:O=!0,onCanvasReadyChange:k,onRuntimeStateChange:A,onGarmentLoadStateChange:j}){let{videoRef:M,webcamReady:ee,webcamError:te,startWebcam:ne,stopWebcam:re,isTrackerReady:N,landmarks:P,worldLandmarks:F,poseRig:I,confidence:ie,fps:ae,isTracking:oe,drawLandmarks:se,silhouetteWidths:ce,poseFrameWidth:le,poseFrameHeight:ue,detectedPersonCount:de,lockedPersonId:fe,trackingQuality:pe,config:me,measurements:he,sizeRecommendation:ge,garmentScale:_e,finalGarmentScale:ve,bodyMorphResult:ye,isMeasuring:be,canMeasure:xe,startMeasurement:Se,updateConfig:Ce,bodyPresetSelection:we,bodyPresetLoading:Te,bodyPresetError:Ee}=Qn({enabled:n,width:a,height:o,facingMode:s,mockMode:c,modelComplexity:l,numPoses:u,minDetectionConfidence:d,minTrackingConfidence:f,outputSegmentationMasks:p,viewportWidth:m,viewportHeight:h,measurementEnabled:g,autoStartMeasurement:v,measurementConfig:y,bodyPresetOptions:S,fitType:b,garmentScaleHint:x}),[De,Oe]=(0,t.useState)(null),ke=(0,t.useCallback)(e=>{M.current=e,Oe(e)},[M]),Ae=(0,t.useMemo)(()=>({videoRef:M,webcamReady:ee,webcamError:te,startWebcam:ne,stopWebcam:re,isTrackerReady:N,landmarks:P,worldLandmarks:F,poseRig:I,confidence:ie,fps:ae,isTracking:oe,drawLandmarks:se,silhouetteWidths:ce,poseFrameWidth:le,poseFrameHeight:ue,detectedPersonCount:de,lockedPersonId:fe,trackingQuality:pe,config:me,measurements:he,sizeRecommendation:ge,garmentScale:_e,finalGarmentScale:ve,bodyMorphResult:ye,isMeasuring:be,canMeasure:xe,startMeasurement:Se,updateConfig:Ce,bodyPresetSelection:we,bodyPresetLoading:Te,bodyPresetError:Ee}),[M,ee,te,ne,re,N,P,F,I,ie,ae,oe,se,ce,le,ue,de,fe,pe,me,he,ge,_e,ve,ye,be,xe,Se,Ce,we,Te,Ee]);return(0,t.useEffect)(()=>{A?.(Ae)},[A,Ae]),(0,i.jsxs)(`div`,{className:C,style:{position:`relative`,width:`100%`,height:`100%`,overflow:`hidden`,...w},children:[(0,i.jsx)(`video`,{ref:ke,autoPlay:!0,playsInline:!0,muted:!0,style:{display:`none`}}),(0,i.jsxs)(_,{showEnvironment:E,useDefaultLights:!1,enableOrbitControls:!1,children:[(0,i.jsx)(qo,{onReady:k}),(0,i.jsx)(Jo,{}),(0,i.jsx)(r.OrthographicCamera,{makeDefault:!0,position:[0,0,100],zoom:180,near:.1,far:1e3}),(0,i.jsx)(`ambientLight`,{intensity:.95}),(0,i.jsx)(`directionalLight`,{position:[4,6,8],intensity:1.15}),(0,i.jsx)(`directionalLight`,{position:[-5,4,6],intensity:.45}),(0,i.jsx)(`hemisphereLight`,{args:[`#ffffff`,`#7d8aa6`,.35]}),O?(0,i.jsx)(Ko,{videoElement:De,webcamReady:ee}):null,n&&e?(0,i.jsx)(Ho,{url:e,landmarks:P,worldLandmarks:F,poseFrameWidth:le,poseFrameHeight:ue,debugMaterials:T,onLoadStateChange:j}):null,D?(0,i.jsx)(r.Stats,{}):null]})]})}var Xo={gender:`female`};function Zo(e,t){return e instanceof Error&&e.message?e.message:t}function Qo(e){let n=(0,t.useMemo)(()=>new ge(e),[e]),[r,i]=(0,t.useState)(`idle`),[a,o]=(0,t.useState)(null),[s,c]=(0,t.useState)(null);return{status:r,resultUrl:a,error:s,generateAvatar:(0,t.useCallback)(async(e=Xo)=>{i(`processing`),c(null);try{let t=e instanceof Blob?Xo:e,r=await n.matchBodyPreset(t);if(!r.model_url)throw Error(`Matched body preset does not have a 3D model URL.`);return o(r.model_url),i(`ready`),r.model_url}catch(e){throw c(Zo(e,`Failed to load avatar model`)),i(`error`),e}},[n]),createGarment:(0,t.useCallback)(async(e,t,r,a)=>{i(`uploading`),c(null);try{let s=await n.createGarment(e);await n.uploadGarmentImage(s.id,t,`front`),r&&await n.uploadGarmentImage(s.id,r,`back`),i(`processing`),await n.generateGarment3D(s.id,{include_measurements:!!a,target_fit_types:[`regular`]});let c=await n.waitForGarmentModel(s.id),l=n.pickGarmentModelUrl(c);if(!l)throw Error(`Backend did not return a garment 3D model URL.`);return o(l),i(`ready`),l}catch(e){throw c(Zo(e,`Failed to generate garment`)),i(`error`),e}},[n]),reset:()=>{i(`idle`),o(null),c(null)}}}var $o={Hips:[L.LEFT_HIP,L.RIGHT_HIP],Spine:[L.LEFT_SHOULDER,L.RIGHT_SHOULDER,L.LEFT_HIP,L.RIGHT_HIP],Chest:[L.LEFT_SHOULDER,L.RIGHT_SHOULDER],LeftShoulder:[L.LEFT_SHOULDER,L.LEFT_ELBOW],LeftUpperArm:[L.LEFT_SHOULDER,L.LEFT_ELBOW],LeftLowerArm:[L.LEFT_ELBOW,L.LEFT_WRIST],RightShoulder:[L.RIGHT_SHOULDER,L.RIGHT_ELBOW],RightUpperArm:[L.RIGHT_SHOULDER,L.RIGHT_ELBOW],RightLowerArm:[L.RIGHT_ELBOW,L.RIGHT_WRIST],LeftUpperLeg:[L.LEFT_HIP,L.LEFT_KNEE],LeftLowerLeg:[L.LEFT_KNEE,L.LEFT_ANKLE],RightUpperLeg:[L.RIGHT_HIP,L.RIGHT_KNEE],RightLowerLeg:[L.RIGHT_KNEE,L.RIGHT_ANKLE]},es=2,ts=.2,ns=26,rs=18;function is(e){return{interval:Math.max(1,e),averageDetectionDurationMs:0,framesUntilNextDetection:0}}function as(e,t){return!t||e.framesUntilNextDetection<=0?(e.framesUntilNextDetection=Math.max(e.interval-1,0),!0):(--e.framesUntilNextDetection,!1)}function os(e,t,n,r=2){let i=Math.max(1,n),a=Math.max(i,r),o=Number.isFinite(t)?Math.max(0,t):0;if(e.averageDetectionDurationMs=e.averageDetectionDurationMs===0?o:e.averageDetectionDurationMs+(o-e.averageDetectionDurationMs)*ts,e.averageDetectionDurationMs>=ns){e.interval=a,e.framesUntilNextDetection=Math.min(e.framesUntilNextDetection,Math.max(e.interval-1,0));return}e.averageDetectionDurationMs<=rs&&(e.interval=i,e.framesUntilNextDetection=Math.min(e.framesUntilNextDetection,Math.max(e.interval-1,0)))}e.BONE_MAPPING=br,e.BONE_VISIBILITY_MAP=$o,e.DEFAULT_EVER_API_BASE_URL=pe,e.DEFAULT_FEMALE_BODY_PRESET_ID=ye,e.DEFAULT_GARMENT_SPEC=b,e.DEFAULT_LOCKED_PERSON_ID=dn,e.DEFAULT_MALE_BODY_PRESET_ID=ve,e.DEFAULT_MEASUREMENT_CONFIG=Ye,e.DEFAULT_NUM_POSES=mt,e.DEFAULT_SMOOTHING=Pe,e.EverCanvas=_,e.EverClient=ge,e.EverFittingScene=Yo,e.EverTrackedGarment=Ho,e.FacingDetector=Yi,e.INTERPOLATION_ALPHA=ht,e.LANDMARK=L,e.LEGACY_RIGGED_BODY_PRESET_ID=be,e.LandmarkSmoother=_n,e.MEDIAPIPE_TASKS_VISION_VERSION=dt,e.MODEL_ASSET_PATHS=gt,e.POSE_DETECTION_INTERVAL=pt,e.POSE_DETECTION_INTERVAL_FALLBACK=es,e.TRACKING_SNAPSHOT_HOLD_MS=Wn,e.TrackedGarmentPoseDriver=Bo,e.WASM_FILES_URL=ft,e.WebcamPlaneBackground=Ko,e.YawDirectionStabilizer=Mi,e.YawFreezeController=Qi,e.applyLandmarkPoseToGarment=bi,e.applyTrackedModelTransform=oo,e.blendBonesToRest=Si,e.buildBodyPresetAssetUrl=Ce,e.buildBodyPresetMatchRequest=Ae,e.calcRectIoU=kn,e.canSolvePoseTorso=Jt,e.captureBoneBinding=$n,e.clampNormalizedRect=En,e.closeSegmentationMasks=Zt,e.computeBmiCorrectionFactor=ze,e.computeBodyFirstFitting=fe,e.computeBoneDirectionFromLandmarks=Lt,e.computeBoneRotationFromLandmarks=zt,e.computeCoverRect=$e,e.computeFacingAwareShoulderWidth=ga,e.computeFrameRateIndependentBlendFactor=Y,e.computeGarmentFitProfile=rr,e.computeGarmentGroupRoll=ya,e.computeGarmentGroupYaw=va,e.computeGarmentRootQuaternion=ba,e.computeGarmentScale=S,e.computeLandmarkBoundsNormalized=Dn,e.computeLandmarkSegmentDirection=It,e.computeScale=Re,e.computeStableShoulderWidth=_a,e.computeVisibleNormalizedRegion=et,e.configureAvatarLoader=lr,e.createAvatarLoaderExtension=ur,e.createFallbackBodyPresetSelection=Oe,e.createHeldTrackingSnapshot=Kn,e.createHumanoidBoneBindings=mr,e.createIdleTrackingQuality=Bn,e.createInitialPoseSnapshot=lt,e.createInitialTrackingRuntimeState=Hn,e.createPoseCandidates=jn,e.createPoseDetectionCadenceState=is,e.createPoseLandmarker=_t,e.createTrackedGarmentMotionState=Lo,e.createTrackedModelTransformScratch=io,e.createTrackingLostRuntimeState=qn,e.createTrackingQuality=Vn,e.createTrackingRuntimeState=Un,e.createVRMCompat=Gr,e.deriveBodyMorphResult=se,e.ensureBodyPresetModelUrl=Ee,e.expandNormalizedRect=On,e.extractFacingSignals=Ki,e.extractSilhouetteWidths=it,e.filterCandidatesByVisibleRegion=Fn,e.getAvatarAssetKind=cr,e.getBoneLandmarkInfluence=Rt,e.getBoneRotation=Cr,e.getDefaultBodyPresetId=we,e.getSegmentationMaskData=Xt,e.hasLandmarkMapping=Bt,e.inferNumberedHumanoidBoneAliases=Hr,e.interpolateLandmarks=at,e.interpolatePoseRig=st,e.interpolatePoseSnapshot=ut,e.interpolateSilhouetteWidths=ct,e.isCandidateInVisibleRegion=Pn,e.isLikelyNumberedHumanoidSkeleton=Vr,e.isRawFrontFacing=qi,e.isVRMAssetUrl=sr,e.landmarkDistance=ta,e.landmarkToThreePosition=X,e.lerpRotation=U,e.lerpValue=B,e.measureBody=Ke,e.midpointToThree=ea,e.normalizeBodyPresetGender=Se,e.normalizeBoneName=Sr,e.normalizeLandmark=pn,e.normalizeLandmarks=mn,e.pickDefaultBodyPreset=De,e.prepareAvatarScene=dr,e.prepareNativeVRM=fr,e.recommendSize=Je,e.resetBoneRotations=ir,e.resetPoseState=xi,e.resetTrackedGarmentMotionState=Ro,e.resolvePoseTrackingConfidence=un,e.resolveSmoothingDeltaSeconds=Ei,e.scaleSilhouetteWidths=Qt,e.selectLockedPoseCandidate=Nn,e.shouldHoldTrackingSnapshot=Gn,e.shouldRunPoseDetection=as,e.smoothPoseRig=yn,e.solvePose=Yt,e.toBodyPresetSelection=ke,e.toBodyPresetSummary=Te,e.toLockedPoseCandidate=In,e.updatePoseDetectionCadence=os,e.updateTrackedGarmentMotion=zo,e.updateTrackedModelTransform=ao,e.useAvatarVariant=qr,e.useBodyPresetSelection=Ne,e.useEverFitting=Qn,e.useEverGeneration=Qo,e.useMeasurement=Qe,e.usePoseApplicationRefs=yi,e.usePoseTracker=Yn,e.useWebcam=Zn});
|
package/dist/math.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK 전역에서 사용하는 기본 수학 유틸리티.
|
|
3
|
+
*
|
|
4
|
+
* Three.js `MathUtils.clamp`과 동일하지만, Three.js를 임포트하지 않는
|
|
5
|
+
* 순수 연산 모듈에서도 사용할 수 있도록 별도 제공한다.
|
|
6
|
+
*/
|
|
7
|
+
export declare function clamp(value: number, minimum: number, maximum: number): number;
|
|
8
|
+
export declare function normalizeAngle(angle: number): number;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare const POSE_DETECTION_INTERVAL_FALLBACK = 2;
|
|
2
|
+
export interface PoseDetectionCadenceState {
|
|
3
|
+
interval: number;
|
|
4
|
+
averageDetectionDurationMs: number;
|
|
5
|
+
framesUntilNextDetection: number;
|
|
6
|
+
}
|
|
7
|
+
/** 실시간 추적에 사용하는 감지 cadence 상태를 생성한다. */
|
|
8
|
+
export declare function createPoseDetectionCadenceState(defaultInterval: number): PoseDetectionCadenceState;
|
|
9
|
+
/**
|
|
10
|
+
* 현재 프레임에서 실제 감지를 수행할지 결정한다.
|
|
11
|
+
*
|
|
12
|
+
* 첫 감지는 항상 즉시 수행하고, 이후에는 현재 interval만큼만 프레임을 건너뛴다.
|
|
13
|
+
*/
|
|
14
|
+
export declare function shouldRunPoseDetection(state: PoseDetectionCadenceState, hasPreviousDetection: boolean): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 실제 감지 시간에 따라 interval을 동적으로 조정한다.
|
|
17
|
+
*
|
|
18
|
+
* 기본은 모든 비디오 프레임을 처리하고, 감지 시간이 지속적으로 길어질 때만
|
|
19
|
+
* fallback interval로 낮춰 안정성을 지킨다.
|
|
20
|
+
*/
|
|
21
|
+
export declare function updatePoseDetectionCadence(state: PoseDetectionCadenceState, detectionDurationMs: number, defaultInterval: number, fallbackInterval?: number): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 프레임 간 경과 시간을 안전한 범위로 정규화한다.
|
|
3
|
+
*
|
|
4
|
+
* 탭 비활성화나 일시 정지 직후에는 비정상적으로 큰 delta가 들어올 수 있으므로
|
|
5
|
+
* 스무딩 계산에 사용할 값을 제한해 과도한 snap을 방지한다.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveSmoothingDeltaSeconds(deltaSeconds?: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* 60fps 기준 블렌딩 계수를 임의의 프레임 간격에서도 동일한 시간 응답으로 변환한다.
|
|
10
|
+
*
|
|
11
|
+
* 예를 들어 60fps에서 alpha=0.35를 쓰던 스무딩은 30fps에서
|
|
12
|
+
* 1 - (1 - 0.35)^2 만큼 보정되어 같은 실제 시간 동안 동일하게 수렴한다.
|
|
13
|
+
*/
|
|
14
|
+
export declare function computeFrameRateIndependentBlendFactor(blendFactorAt60Fps: number, deltaSeconds?: number): number;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { PoseLandmarker } from "@mediapipe/tasks-vision";
|
|
2
2
|
export declare const MEDIAPIPE_TASKS_VISION_VERSION = "0.10.32";
|
|
3
3
|
export declare const WASM_FILES_URL = "https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@0.10.32/wasm";
|
|
4
|
-
|
|
4
|
+
/** 기본 프레임 감지 주기. 기본값은 모든 비디오 프레임을 처리한다. */
|
|
5
|
+
export declare const POSE_DETECTION_INTERVAL = 1;
|
|
5
6
|
export declare const DEFAULT_NUM_POSES = 3;
|
|
6
7
|
export declare const INTERPOLATION_ALPHA = 0.5;
|
|
7
8
|
export declare const MODEL_ASSET_PATHS: {
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import type { PoseLandmarkLike, PoseRig } from "../types/pose";
|
|
2
|
+
import { type LandmarkCoordinateSpace } from "./landmarkPoseSolver";
|
|
3
|
+
export declare function canSolvePoseTorso(landmarks: PoseLandmarkLike[], coordinateSpace?: LandmarkCoordinateSpace): boolean;
|
|
2
4
|
export declare function solvePose(landmarks: PoseLandmarkLike[], worldLandmarks?: PoseLandmarkLike[] | null): PoseRig | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -30,14 +30,13 @@
|
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
32
|
"import": "./dist/index.es.js",
|
|
33
|
-
"require": "./dist/index.umd.js",
|
|
34
33
|
"types": "./dist/index.d.ts"
|
|
35
34
|
}
|
|
36
35
|
},
|
|
37
36
|
"files": [
|
|
38
37
|
"dist"
|
|
39
38
|
],
|
|
40
|
-
"main": "./dist/index.
|
|
39
|
+
"main": "./dist/index.es.js",
|
|
41
40
|
"module": "./dist/index.es.js",
|
|
42
41
|
"name": "@ssafy-mhk/e-ver",
|
|
43
42
|
"peerDependencies": {
|
|
@@ -51,6 +50,7 @@
|
|
|
51
50
|
},
|
|
52
51
|
"scripts": {
|
|
53
52
|
"build": "vite build && tsc -p tsconfig.app.json",
|
|
53
|
+
"check:dist": "node ./scripts/verify-dist-contract.mjs",
|
|
54
54
|
"dev": "vite",
|
|
55
55
|
"lint": "eslint .",
|
|
56
56
|
"preview": "vite preview",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
},
|
|
60
60
|
"type": "module",
|
|
61
61
|
"types": "./dist/index.d.ts",
|
|
62
|
-
"version": "1.0.
|
|
62
|
+
"version": "1.0.7"
|
|
63
63
|
}
|