@vincentt-xr/sdk 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/GROUNDING.md +537 -0
- package/LICENSE +7 -0
- package/README.md +85 -0
- package/dist/DebuggerUI-CEfdddkZ.cjs +1 -0
- package/dist/DebuggerUI-Dgop6Q6o.js +269 -0
- package/dist/audio/AudioEngine.d.ts +98 -0
- package/dist/audio/index.d.ts +34 -0
- package/dist/components/AspectRatioContainer/index.d.ts +10 -0
- package/dist/components/BodyTracker/index.d.ts +15 -0
- package/dist/components/Debugger/DebuggerProvider.d.ts +22 -0
- package/dist/components/Debugger/DebuggerUI.d.ts +13 -0
- package/dist/components/Debugger/index.d.ts +38 -0
- package/dist/components/Debugger/styles.d.ts +19 -0
- package/dist/components/FaceMesh/FaceMesh.d.ts +26 -0
- package/dist/components/FaceMesh/canonical/CanonicalFaceMeshRenderer.d.ts +34 -0
- package/dist/components/FaceMesh/canonical/parseCanonicalFaceModel.d.ts +16 -0
- package/dist/components/FaceMesh/canonical/useCanonicalFaceMesh.d.ts +15 -0
- package/dist/components/FaceMesh/deform.d.ts +36 -0
- package/dist/components/FaceMesh/index.d.ts +6 -0
- package/dist/components/FaceMesh/indices.d.ts +1 -0
- package/dist/components/FaceMesh/material/blendModes.d.ts +2 -0
- package/dist/components/FaceMesh/material/defaults.d.ts +3 -0
- package/dist/components/FaceMesh/material/index.d.ts +5 -0
- package/dist/components/FaceMesh/material/options.d.ts +25 -0
- package/dist/components/FaceMesh/material/support.d.ts +3 -0
- package/dist/components/FaceMesh/material/types.d.ts +23 -0
- package/dist/components/FaceMesh/uv.d.ts +1 -0
- package/dist/components/FaceRetouch/Background.d.ts +16 -0
- package/dist/components/FaceRetouch/index.d.ts +6 -0
- package/dist/components/FaceRetouch/landmarkMask.d.ts +23 -0
- package/dist/components/FaceRetouch/retouchRegions.d.ts +23 -0
- package/dist/components/FaceRetouch/useFaceRetouchMask.d.ts +14 -0
- package/dist/components/FaceRetouch/useFaceRetouchRegions.d.ts +12 -0
- package/dist/components/FaceTracker/BoundingBoxOverlay.d.ts +20 -0
- package/dist/components/FaceTracker/index.d.ts +54 -0
- package/dist/components/GestureTracker/index.d.ts +31 -0
- package/dist/components/GestureTrigger/index.d.ts +3 -0
- package/dist/components/HandTracker/index.d.ts +24 -0
- package/dist/components/HeadBinding/index.d.ts +31 -0
- package/dist/components/HeadBindingOccluder/index.d.ts +36 -0
- package/dist/components/HeadOccluder/index.d.ts +13 -0
- package/dist/components/Panel/index.d.ts +71 -0
- package/dist/components/PerspectiveCamera/index.d.ts +14 -0
- package/dist/components/ScreenSpaceUI/ScreenTransform.d.ts +54 -0
- package/dist/components/ScreenSpaceUI/context.d.ts +29 -0
- package/dist/components/ScreenSpaceUI/index.d.ts +40 -0
- package/dist/components/Segmentation/index.d.ts +44 -0
- package/dist/components/SpriteAnimation/index.d.ts +52 -0
- package/dist/components/TextLabel/index.d.ts +62 -0
- package/dist/components/TrackingAnchor/index.d.ts +74 -0
- package/dist/components/VideoBackground/index.d.ts +38 -0
- package/dist/components/XRCompositor/index.d.ts +5 -0
- package/dist/components/XRDebugView/index.d.ts +6 -0
- package/dist/components/XRLayer/index.d.ts +6 -0
- package/dist/components/XRMediaSurface/index.d.ts +27 -0
- package/dist/components/XRProvider/index.d.ts +13 -0
- package/dist/components/XRScene/defaults.d.ts +4 -0
- package/dist/components/XRScene/index.d.ts +15 -0
- package/dist/components/XRViewport/index.d.ts +101 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/constants/index.d.ts +25 -0
- package/dist/constants/renderLayers.d.ts +25 -0
- package/dist/entries/all.d.ts +15 -0
- package/dist/entries/core.d.ts +21 -0
- package/dist/entries/face-effects.d.ts +19 -0
- package/dist/entries/internal.d.ts +16 -0
- package/dist/entries/low-level.d.ts +30 -0
- package/dist/entries/tracking.d.ts +15 -0
- package/dist/face-effects.cjs +252 -0
- package/dist/face-effects.js +3542 -0
- package/dist/hasFullUnitUVBounds-BGvcFsQM.js +26 -0
- package/dist/hasFullUnitUVBounds-p1Dl0ejX.cjs +1 -0
- package/dist/hooks/faceResults.d.ts +39 -0
- package/dist/hooks/selectors.d.ts +33 -0
- package/dist/hooks/useCalibrationFaceTracker.d.ts +23 -0
- package/dist/hooks/useDebugger/index.d.ts +25 -0
- package/dist/hooks/useDebugger/types.d.ts +20 -0
- package/dist/hooks/useFaceBoundingBox.d.ts +11 -0
- package/dist/hooks/useFaceResults.d.ts +31 -0
- package/dist/hooks/useGestureEdge.d.ts +53 -0
- package/dist/hooks/useMediaRecorder.d.ts +40 -0
- package/dist/hooks/useTrackerContext.d.ts +35 -0
- package/dist/hooks/useXRModel.d.ts +15 -0
- package/dist/hooks/useXRSession/constants.d.ts +4 -0
- package/dist/hooks/useXRSession/facade.d.ts +39 -0
- package/dist/hooks/useXRSession/fns.d.ts +5 -0
- package/dist/hooks/useXRSession/index.d.ts +4 -0
- package/dist/hooks/useXRSession/registry.d.ts +52 -0
- package/dist/hooks/useXRSession/store.d.ts +40 -0
- package/dist/index-B5J4gzn2.cjs +1 -0
- package/dist/index-BD-JWMjE.js +1991 -0
- package/dist/index-BVBVg96G.cjs +1 -0
- package/dist/index-CYMj26Ej.js +1331 -0
- package/dist/index-DtwHElmG.js +157 -0
- package/dist/index-PtFmD6B8.cjs +1 -0
- package/dist/internal-DH5d1Xnq.cjs +1 -0
- package/dist/internal-KOKJDxCG.js +519 -0
- package/dist/internal.cjs +1 -0
- package/dist/internal.js +14 -0
- package/dist/low-level.cjs +1 -0
- package/dist/low-level.js +941 -0
- package/dist/main.cjs +1 -0
- package/dist/main.js +612 -0
- package/dist/models/Base/index.d.ts +25 -0
- package/dist/models/Body/index.d.ts +22 -0
- package/dist/models/Face/constants.d.ts +2 -0
- package/dist/models/Face/index.d.ts +45 -0
- package/dist/models/Face/landmarksData.d.ts +2 -0
- package/dist/models/Hand/GestureTracking.d.ts +21 -0
- package/dist/models/Hand/HandTracking.d.ts +21 -0
- package/dist/models/Segmentation/index.d.ts +75 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/modules/XRClient/index.d.ts +9 -0
- package/dist/modules/index.d.ts +1 -0
- package/dist/selectors-BHO6TnoC.js +59 -0
- package/dist/selectors-Bub0o3qy.cjs +1 -0
- package/dist/services/ApiService.d.ts +12 -0
- package/dist/services/MetricsCollector/CameraFPSTracker.d.ts +25 -0
- package/dist/services/MetricsCollector/MemoryTracker.d.ts +43 -0
- package/dist/services/MetricsCollector/RenderTimeTracker.d.ts +10 -0
- package/dist/services/MetricsCollector/ResolutionTracker.d.ts +26 -0
- package/dist/services/MetricsCollector/index.d.ts +59 -0
- package/dist/services/MetricsCollector/types.d.ts +47 -0
- package/dist/services/MetricsCollector/utils.d.ts +65 -0
- package/dist/texture/computeContainScale.d.ts +25 -0
- package/dist/texture/hasFullUnitUVBounds.d.ts +37 -0
- package/dist/texture/types.d.ts +20 -0
- package/dist/tracking.cjs +1 -0
- package/dist/tracking.js +344 -0
- package/dist/types/body.d.ts +3 -0
- package/dist/types/client.d.ts +3 -0
- package/dist/types/common.d.ts +9 -0
- package/dist/types/compositor.d.ts +23 -0
- package/dist/types/debugger.d.ts +83 -0
- package/dist/types/face.d.ts +67 -0
- package/dist/types/gesture-tracking.d.ts +15 -0
- package/dist/types/hand-tracking.d.ts +5 -0
- package/dist/types/headBinding.d.ts +67 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/logger.d.ts +4 -0
- package/dist/types/model.d.ts +46 -0
- package/dist/types/nodes.d.ts +35 -0
- package/dist/types/segmentation.d.ts +31 -0
- package/dist/types/session.d.ts +102 -0
- package/dist/types/tracking.d.ts +30 -0
- package/dist/types/util-types.d.ts +1 -0
- package/dist/useFaceResults-cpsSmKKc.js +81 -0
- package/dist/useFaceResults-hVUJYSEY.cjs +1 -0
- package/dist/utils/calibrationDebug.d.ts +9 -0
- package/dist/utils/dataURL.d.ts +6 -0
- package/dist/utils/drawMediaCover.d.ts +18 -0
- package/dist/utils/errors.d.ts +3 -0
- package/dist/utils/fns.d.ts +48 -0
- package/dist/utils/headBinding.d.ts +85 -0
- package/dist/utils/integrity.d.ts +43 -0
- package/dist/utils/landmarkBounds.d.ts +11 -0
- package/dist/utils/logger.d.ts +7 -0
- package/package.json +113 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@vincentt-xr/sdk/low-level` — the escape hatch.
|
|
3
|
+
*
|
|
4
|
+
* Raw model-node reads, the gen-3 selector layer, custom-tracker plumbing,
|
|
5
|
+
* compositor/viewport internals, and texture utilities. The door for "the
|
|
6
|
+
* blessed API can't express this." Prefer `/tracking` and `/face-effects`
|
|
7
|
+
* first; reach here only when they fall short.
|
|
8
|
+
*/
|
|
9
|
+
export { useXRContext } from '../components';
|
|
10
|
+
export { useTrackerContext } from '../hooks/useTrackerContext';
|
|
11
|
+
export type { TrackerContextValue, TrackerLandmarkResolver } from '../hooks/useTrackerContext';
|
|
12
|
+
export { useXRModel } from '../hooks/useXRModel';
|
|
13
|
+
export type { UseXRModelResult } from '../hooks/useXRModel';
|
|
14
|
+
export type { XRModelNodeSegmentation, XRModelNodeBodyTracking, XRModelNodeHandTracking, XRModelNodeGestureTracking, XRModelNodeFaceTracking, } from '../types/nodes';
|
|
15
|
+
export { useXRReady, useXRError, useXRCameraTexture, useXRRenderSize, useXRModelNode, useXRPipelineSnapshot, } from '../hooks/selectors';
|
|
16
|
+
export type { GestureName } from '../hooks/useGestureEdge';
|
|
17
|
+
export { useFaceBoundingBox } from '../hooks/useFaceBoundingBox';
|
|
18
|
+
export { computeLandmarkBounds } from '../utils/landmarkBounds';
|
|
19
|
+
export { useScreenSpace, ScreenRectAspectContext, computeScreenTransform } from '../components';
|
|
20
|
+
export type { ScreenAnchorEdges, ScreenOffsetEdges, ResolvedScreenTransform, ScreenDimensions, } from '../components/ScreenSpaceUI';
|
|
21
|
+
export { XRCompositor, XRLayer, XRMediaSurface, XRViewport, XRTrackingOverlay, useXRViewportState, PerspectiveCamera, HeadTracker, BoundingBoxOverlay, } from '../components';
|
|
22
|
+
export type { BoundingBoxOverlayProps } from '../components';
|
|
23
|
+
export type { XRViewportFitMode, XRViewportMediaAssetOption, XRViewportMediaStrategy, XRViewportMode, XRViewportRenderState, XRViewportSize, XRViewportSourceConfig, XRViewportSourceKind, } from '../components/XRViewport';
|
|
24
|
+
export type { XRLayerConfig } from '../types/compositor';
|
|
25
|
+
export type { XRMediaLayout, XRMediaSourceKind } from '../types/compositor';
|
|
26
|
+
export { resolveCalibrationFaceDisplayMirrored, useCalibrationFaceTracker, } from '../hooks/useCalibrationFaceTracker';
|
|
27
|
+
export type { CalibrationMediaSourceKind, CalibrationTrackerMode, } from '../hooks/useCalibrationFaceTracker';
|
|
28
|
+
export type { TextureFit } from '../texture/types';
|
|
29
|
+
export { TEXTURE_FITS } from '../texture/types';
|
|
30
|
+
export { hasFullUnitUVBounds } from '../texture/hasFullUnitUVBounds';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@vincentt-xr/sdk/tracking` — detect a face/hand/body and attach content.
|
|
3
|
+
*
|
|
4
|
+
* The most common non-core need: trackers (self-registering), the anchor and
|
|
5
|
+
* trigger primitives that read them, the bare deforming face mesh, and the
|
|
6
|
+
* blessed face reader. Deep face-filter config lives in `/face-effects`; raw
|
|
7
|
+
* model-node reads and selectors live in `/low-level`.
|
|
8
|
+
*/
|
|
9
|
+
export { FaceTracker, HandTracker, GestureTracker, BodyTracker, Segmentation, FaceMesh, TrackingAnchor, GestureTrigger, } from '../components';
|
|
10
|
+
export type { GestureTriggerProps } from '../components/GestureTrigger';
|
|
11
|
+
export { useFaceResults } from '../hooks/useFaceResults';
|
|
12
|
+
export type { FaceTarget, HandTarget, BodyTarget, TrackingTarget, TrackerType, } from '../types/tracking';
|
|
13
|
+
export { FACE_TARGETS, HAND_TARGETS, BODY_TARGETS, getTargetNamespace } from '../types/tracking';
|
|
14
|
+
export type { SegmentationType } from '../types/segmentation';
|
|
15
|
+
export { SEGMENTATION_TYPES } from '../types/segmentation';
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("three"),A=require("react/jsx-runtime"),re=require("@react-three/fiber"),S=require("react"),$=require("./index-PtFmD6B8.cjs"),je=require("./selectors-Bub0o3qy.cjs"),Xe=require("./index-B5J4gzn2.cjs"),Fe=require("@react-three/drei");function Ft(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const t in a)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>a[t]})}}return e.default=a,Object.freeze(e)}const E=Ft(d),Ke={normal:0,add:1,subtract:2,multiply:3,screen:4,overlay:5,softLight:6,hardLight:7,lighten:8,darken:9,difference:10,exclusion:11},Pe=new Set([61,146,91,181,84,17,314,405,321,375,291,78,95,88,178,87,14,317,402,318,324,308,191,80,81,82,13,312,311,310,415]),Ne=new Set([33,7,163,144,145,153,154,155,133,173,157,158,159,160,161,246]),Oe=new Set([362,382,381,380,374,373,390,249,263,466,388,387,386,385,384,398]),Pt=new Set([814,815,816,817,818,819,830,831,832,833]),Nt=(a,e,t)=>{const s=Pe.has(a)&&Pe.has(e)&&Pe.has(t),n=Ne.has(a)&&Ne.has(e)&&Ne.has(t),r=Oe.has(a)&&Oe.has(e)&&Oe.has(t);return s?"mouth":n||r?"eye":"base"},ht=a=>{const e=[],t=[],s=[],n=[],r=[],o=[];let c=0,i=0;a.split(`
|
|
2
|
+
`).forEach(u=>{const h=u.trim();if(!h)return;if(h.startsWith("v ")){c+=1;return}if(h.startsWith("vt ")){const[,x,g]=h.split(/\s+/);r.push([Number(x),Number(g)]);return}if(!h.startsWith("f "))return;const f=i;i+=1;const[,...m]=h.split(/\s+/),T=m.map(x=>{const[g,p]=x.split("/"),v=Number(g)-1,b=Number(p)-1;return b>=0&&r[b]&&!o[v]&&(o[v]=r[b]),v});if(!(T.length<3))for(let x=1;x<T.length-1;x+=1){const g=T[0],p=T[x],v=T[x+1],b=Nt(g,p,v);Pt.has(f)?n.push(g,p,v):b==="mouth"?t.push(g,p,v):b==="eye"?s.push(g,p,v):e.push(g,p,v)}});const l=[];for(let u=0;u<c;u+=1){const[h,f]=o[u]??[0,0];l.push(h,f)}return{baseIndices:new Uint16Array(e),mouthIndices:new Uint16Array(t),eyeIndices:new Uint16Array(s),noseIndices:new Uint16Array(n),uvs:new Float32Array(l),vertexCount:c}},Ot="canonical_face_model.obj",Dt=new TextDecoder("utf-8"),De=new Map,Bt=a=>{const e=De.get(a);if(e)return e;const t=$.fetchAndVerify(a).then(s=>ht(Dt.decode(s))).catch(s=>{throw De.delete(a),s});return De.set(a,t),t},dt=a=>{const{mesh:e,url:t}=a??{},s=t??`${$.libConfig.sdkAssetsBaseUrl}/${Ot}`,[n,r]=S.useState(e??null);return S.useEffect(()=>{if(e){r(e);return}let o=!1;return Bt(s).then(c=>{o||r(c)}).catch(c=>{o||console.error(`${$.libConfig.loggerPrefix} canonical face mesh load failed`,c)}),()=>{o=!0}},[e,s]),n},Ut={front:E.FrontSide,back:E.BackSide,double:E.DoubleSide},kt=`
|
|
3
|
+
attribute vec2 faceUv;
|
|
4
|
+
varying vec2 vUv;
|
|
5
|
+
varying vec2 vFaceUv;
|
|
6
|
+
varying vec3 vNormal;
|
|
7
|
+
|
|
8
|
+
void main() {
|
|
9
|
+
vUv = uv;
|
|
10
|
+
vFaceUv = faceUv;
|
|
11
|
+
vNormal = normalize(normalMatrix * normal);
|
|
12
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
13
|
+
}
|
|
14
|
+
`,Gt=`
|
|
15
|
+
uniform sampler2D cameraTexture;
|
|
16
|
+
uniform sampler2D canonicalTexture;
|
|
17
|
+
uniform sampler2D alphaMask;
|
|
18
|
+
uniform vec3 textureTint;
|
|
19
|
+
uniform float opacity;
|
|
20
|
+
uniform float blendMode;
|
|
21
|
+
uniform float useCanonicalTexture;
|
|
22
|
+
uniform float useAlphaMask;
|
|
23
|
+
uniform float alphaOpacity;
|
|
24
|
+
uniform float compositeShading;
|
|
25
|
+
uniform vec3 lightDirection;
|
|
26
|
+
uniform float ambientStrength;
|
|
27
|
+
uniform float directionalStrength;
|
|
28
|
+
varying vec2 vUv;
|
|
29
|
+
varying vec2 vFaceUv;
|
|
30
|
+
varying vec3 vNormal;
|
|
31
|
+
|
|
32
|
+
vec3 linearToSrgb(vec3 value) {
|
|
33
|
+
vec3 low = value * 12.92;
|
|
34
|
+
vec3 high = 1.055 * pow(max(value, vec3(0.0)), vec3(1.0 / 2.4)) - 0.055;
|
|
35
|
+
return mix(high, low, step(value, vec3(0.0031308)));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
vec3 srgbToLinear(vec3 value) {
|
|
39
|
+
vec3 low = value / 12.92;
|
|
40
|
+
vec3 high = pow(max((value + 0.055) / 1.055, vec3(0.0)), vec3(2.4));
|
|
41
|
+
return mix(high, low, step(value, vec3(0.04045)));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
float overlayChannel(float base, float blend) {
|
|
45
|
+
return base < 0.5 ? 2.0 * base * blend : 1.0 - 2.0 * (1.0 - base) * (1.0 - blend);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
float hardLightChannel(float base, float blend) {
|
|
49
|
+
return blend < 0.5 ? 2.0 * base * blend : 1.0 - 2.0 * (1.0 - base) * (1.0 - blend);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
float softLightChannel(float base, float blend) {
|
|
53
|
+
if (blend <= 0.5) {
|
|
54
|
+
return base - (1.0 - 2.0 * blend) * base * (1.0 - base);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
float d = base <= 0.25
|
|
58
|
+
? ((16.0 * base - 12.0) * base + 4.0) * base
|
|
59
|
+
: sqrt(base);
|
|
60
|
+
|
|
61
|
+
return base + (2.0 * blend - 1.0) * (d - base);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
vec3 applyBlendMode(vec3 base, vec3 blend, float mode) {
|
|
65
|
+
if (mode < 0.5) return blend;
|
|
66
|
+
if (mode < 1.5) return min(base + blend, 1.0);
|
|
67
|
+
if (mode < 2.5) return max(base - blend, 0.0);
|
|
68
|
+
if (mode < 3.5) return base * blend;
|
|
69
|
+
if (mode < 4.5) return 1.0 - (1.0 - base) * (1.0 - blend);
|
|
70
|
+
if (mode < 5.5) {
|
|
71
|
+
return vec3(
|
|
72
|
+
overlayChannel(base.r, blend.r),
|
|
73
|
+
overlayChannel(base.g, blend.g),
|
|
74
|
+
overlayChannel(base.b, blend.b)
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (mode < 6.5) {
|
|
78
|
+
return vec3(
|
|
79
|
+
softLightChannel(base.r, blend.r),
|
|
80
|
+
softLightChannel(base.g, blend.g),
|
|
81
|
+
softLightChannel(base.b, blend.b)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
if (mode < 7.5) {
|
|
85
|
+
return vec3(
|
|
86
|
+
hardLightChannel(base.r, blend.r),
|
|
87
|
+
hardLightChannel(base.g, blend.g),
|
|
88
|
+
hardLightChannel(base.b, blend.b)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
if (mode < 8.5) return max(base, blend);
|
|
92
|
+
if (mode < 9.5) return min(base, blend);
|
|
93
|
+
if (mode < 10.5) return abs(base - blend);
|
|
94
|
+
return base + blend - 2.0 * base * blend;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
void main() {
|
|
98
|
+
vec3 base = linearToSrgb(texture2D(cameraTexture, vFaceUv).rgb);
|
|
99
|
+
vec4 textureSample = texture2D(canonicalTexture, vUv);
|
|
100
|
+
vec3 blend = linearToSrgb(textureSample.rgb) * textureTint;
|
|
101
|
+
float light = ambientStrength + max(dot(normalize(vNormal), normalize(lightDirection)), 0.0) * directionalStrength;
|
|
102
|
+
blend *= mix(1.0, clamp(light, 0.35, 1.35), compositeShading);
|
|
103
|
+
float maskSample = texture2D(alphaMask, vUv).r;
|
|
104
|
+
float mask = useAlphaMask > 0.5 ? mix(1.0, maskSample, alphaOpacity) : 1.0;
|
|
105
|
+
float textureAlpha = useCanonicalTexture > 0.5 ? textureSample.a : 1.0;
|
|
106
|
+
vec3 color = useCanonicalTexture > 0.5 ? applyBlendMode(base, blend, blendMode) : base;
|
|
107
|
+
gl_FragColor = vec4(srgbToLinear(color), opacity * mask * textureAlpha);
|
|
108
|
+
}
|
|
109
|
+
`,Ht=`
|
|
110
|
+
varying vec2 vUv;
|
|
111
|
+
varying vec3 vNormal;
|
|
112
|
+
|
|
113
|
+
void main() {
|
|
114
|
+
vUv = uv;
|
|
115
|
+
vNormal = normalize(normalMatrix * normal);
|
|
116
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
117
|
+
}
|
|
118
|
+
`,jt=`
|
|
119
|
+
uniform vec3 color;
|
|
120
|
+
uniform float opacity;
|
|
121
|
+
varying vec3 vNormal;
|
|
122
|
+
|
|
123
|
+
void main() {
|
|
124
|
+
vec3 normalTint = 0.5 + 0.5 * normalize(vNormal);
|
|
125
|
+
vec3 base = color * mix(vec3(1.0), normalTint, 0.35);
|
|
126
|
+
|
|
127
|
+
gl_FragColor = vec4(base, opacity);
|
|
128
|
+
}
|
|
129
|
+
`,Xt=()=>{const a=new Uint8Array([32,32,32,255,96,96,96,255,176,176,176,255,255,255,255,255]),e=new E.DataTexture(a,4,1,E.RGBAFormat);return e.minFilter=E.NearestFilter,e.magFilter=E.NearestFilter,e.generateMipmaps=!1,e.needsUpdate=!0,e},Kt=()=>{const a=document.createElement("canvas");a.width=256,a.height=256;const e=a.getContext("2d");if(!e)return new E.CanvasTexture(a);const t=e.createRadialGradient(96,80,10,128,128,128);t.addColorStop(0,"#ffffff"),t.addColorStop(.18,"#f7d794"),t.addColorStop(.45,"#d97706"),t.addColorStop(.72,"#78350f"),t.addColorStop(1,"#120701"),e.fillStyle=t,e.fillRect(0,0,a.width,a.height);const s=new E.CanvasTexture(a);return s.needsUpdate=!0,s},Yt=({faceIndex:a=0,color:e="#38bdf8",opacity:t=.45,materialType:s="basic",shaderPreset:n="basicShader",textureMap:r="none",alphaMap:o="none",alphaOpacity:c=0,side:i="front",blendMode:l="normal",showMouthMask:u=!0,showEyeMask:h=!0,showNoseMask:f=!0,maskTextureSource:m="none",maskColor:T="#111111",maskOpacity:x=0,faceTextureUrl:g="",faceTextureStyle2Url:p="",faceAlphaMaskUrl:v="",compositeShading:b=!1,mesh:M,meshUrl:y})=>{const C=je.useXRModelNode($.XRModel.FACE_TRACKER),L=je.useXRCameraTexture(),{camera:D}=re.useThree(),w=dt({mesh:M,url:y}),P=re.useLoader(E.TextureLoader,g||"/placeholder.png"),J=re.useLoader(E.TextureLoader,p||g||"/placeholder.png"),I=re.useLoader(E.TextureLoader,v||"/placeholder.png"),K=S.useMemo(()=>Xt(),[]),_=S.useMemo(()=>Kt(),[]),ee=S.useRef(null),Y=S.useRef(null),V=S.useRef(null),ae=S.useRef(null),ie=S.useRef(null),ce=S.useRef(null),le=S.useRef(null),te=S.useRef(null),ne=S.useRef(null),ue=S.useRef(null),he=S.useRef(null),me=S.useRef(null),Lt=S.useRef(new E.Vector3),ge=S.useRef(!1),Z=Ut[i],se={side:Z,transparent:!0,opacity:t,wireframe:!1},Se=r==="style2"?J:P,de=r!=="none",Ae=S.useMemo(()=>({color:{value:new E.Color(e)},opacity:{value:t}}),[]),N=S.useMemo(()=>({cameraTexture:{value:null},canonicalTexture:{value:null},alphaMask:{value:null},textureTint:{value:new E.Color(e)},opacity:{value:t},blendMode:{value:Ke[l]},useCanonicalTexture:{value:de?1:0},useAlphaMask:{value:o==="canonical"?1:0},alphaOpacity:{value:c},compositeShading:{value:b?1:0},lightDirection:{value:new E.Vector3(.3,.65,.7).normalize()},ambientStrength:{value:.78},directionalStrength:{value:.38}}),[]);S.useEffect(()=>{Ae.color.value.set(e),Ae.opacity.value=t},[e,t,Ae]),S.useEffect(()=>{N.cameraTexture.value=L??P,N.canonicalTexture.value=Se,N.alphaMask.value=I,N.textureTint.value.set(e),N.opacity.value=t,N.blendMode.value=Ke[l],N.useCanonicalTexture.value=de?1:0,N.useAlphaMask.value=o==="canonical"?1:0,N.alphaOpacity.value=c,N.compositeShading.value=b?1:0},[o,I,c,l,L,e,b,N,P,de,t,Se,r]);const Te=F=>{if(F)return m==="canonical"?A.jsx("meshBasicMaterial",{color:T,alphaMap:I,transparent:!0,opacity:x,side:Z,depthWrite:!1,depthTest:!1,toneMapped:!1},"masked-canonical-material"):A.jsx("meshBasicMaterial",{color:T,transparent:!0,opacity:x,side:Z,depthWrite:!1,depthTest:!1,toneMapped:!1},"masked-solid-material");if(s==="wireframe")return A.jsx("meshBasicMaterial",{color:e,transparent:!0,opacity:t,side:Z,depthWrite:!1,depthTest:!1,wireframe:!0,toneMapped:!1},"wireframe-material");if(s==="shader"&&L&&(n==="originalFace"||n==="composite"&&r==="none"))return A.jsx("meshBasicMaterial",{map:L,alphaMap:I,transparent:!0,opacity:t,side:Z,depthWrite:!1,depthTest:!0,toneMapped:!1},"use-original-face-material");if(s==="shader"&&n==="composite"&&de&&L)return A.jsx("shaderMaterial",{uniforms:N,vertexShader:kt,fragmentShader:Gt,transparent:!0,side:Z,depthWrite:!1,depthTest:!0,toneMapped:!1},"composite-material");const B=de?Se:null,U=o==="canonical"&&c>0?I:null,k=`${s}-${r}-${o}-${c>0?"alpha-on":"alpha-off"}`;return s==="standard"?A.jsx("meshStandardMaterial",{...se,color:e,map:B??void 0,alphaMap:U??void 0,depthWrite:!0,depthTest:!0,metalness:.05,roughness:.72},k):s==="physical"?A.jsx("meshPhysicalMaterial",{...se,color:e,map:B??void 0,alphaMap:U??void 0,depthWrite:!0,depthTest:!0,roughness:.58,metalness:.08,clearcoat:.35,clearcoatRoughness:.4},k):s==="toon"?A.jsx("meshToonMaterial",{...se,color:e,map:B??void 0,alphaMap:U??void 0,gradientMap:K,depthWrite:!0,depthTest:!0},k):s==="normal"?A.jsx("meshNormalMaterial",{...se,depthWrite:!0,depthTest:!0,flatShading:!1},"normal-material"):s==="matcap"?A.jsx("meshMatcapMaterial",{...se,color:e,matcap:_,depthWrite:!0,depthTest:!0},"matcap-material"):s==="shader"?A.jsx("shaderMaterial",{uniforms:Ae,vertexShader:Ht,fragmentShader:jt,transparent:!0,side:Z,depthWrite:!1,depthTest:!0,toneMapped:!1},"generic-shader-material"):A.jsx("meshBasicMaterial",{...se,color:e,map:B??void 0,alphaMap:U??void 0,depthWrite:!1,depthTest:r!=="none"||o!=="none",toneMapped:!1},k)},Ct=F=>Xe.projectLandmarkWithDepth(F,D,Lt.current);return re.useFrame(()=>{var et,tt;const F=ee.current,B=Y.current,U=V.current,k=ae.current,we=ie.current,_e=ce.current,ye=le.current,Le=te.current,xe=(tt=(et=C==null?void 0:C.detectionResults)==null?void 0:et.faceLandmarks)==null?void 0:tt[a];if(!w||!F||!B||!U||!k||!we||!_e||!ye||!Le)return;if(!xe||xe.length<w.vertexCount){we.visible=!1,_e.visible=!1,ye.visible=!1,Le.visible=!1;return}if(me.current!==w){ne.current=new Float32Array(w.vertexCount*3),ue.current=new Float32Array(w.uvs),he.current=new Float32Array(w.vertexCount*2);const H=new E.BufferAttribute(ne.current,3),G=new E.BufferAttribute(ue.current,2),W=new E.BufferAttribute(he.current,2);F.setAttribute("position",H),F.setAttribute("uv",G),F.setAttribute("faceUv",W),F.setIndex(new E.BufferAttribute(w.baseIndices,1)),B.setAttribute("position",H),B.setAttribute("uv",G),B.setAttribute("faceUv",W),B.setIndex(new E.BufferAttribute(w.mouthIndices,1)),U.setAttribute("position",H),U.setAttribute("uv",G),U.setAttribute("faceUv",W),U.setIndex(new E.BufferAttribute(w.eyeIndices,1)),k.setAttribute("position",H),k.setAttribute("uv",G),k.setAttribute("faceUv",W),k.setIndex(new E.BufferAttribute(w.noseIndices,1)),G.needsUpdate=!0,me.current=w,ge.current=!1}const ve=ne.current,Ce=he.current,be=ue.current;if(!ve||!Ce||!be)return;const Je=s==="shader"&&(n==="originalFace"||n==="composite"&&r==="none"),It=Math.min(xe.length,w.vertexCount);for(let H=0;H<It;H++){const G=xe[H],W=H*3,Me=H*2,Ie=Ct(G);ve[W]=Ie.x,ve[W+1]=Ie.y,ve[W+2]=Ie.z,Ce[Me]=G.x,Ce[Me+1]=1-G.y,Je&&(be[Me]=G.x,be[Me+1]=1-G.y)}Je?(F.attributes.uv.needsUpdate=!0,ge.current=!0):ge.current&&(be.set(w.uvs),F.attributes.uv.needsUpdate=!0,ge.current=!1),we.visible=!0,_e.visible=!0,ye.visible=!0,Le.visible=!0,F.attributes.position.needsUpdate=!0,F.attributes.faceUv.needsUpdate=!0,F.computeVertexNormals(),B.computeVertexNormals(),U.computeVertexNormals(),k.computeVertexNormals()}),A.jsxs(A.Fragment,{children:[A.jsxs("mesh",{ref:ie,renderOrder:10,frustumCulled:!1,children:[A.jsx("bufferGeometry",{ref:ee}),Te(!1)]}),A.jsxs("mesh",{ref:ce,renderOrder:12,frustumCulled:!1,children:[A.jsx("bufferGeometry",{ref:Y}),Te(u)]}),A.jsxs("mesh",{ref:le,renderOrder:12,frustumCulled:!1,children:[A.jsx("bufferGeometry",{ref:V}),Te(h)]}),A.jsxs("mesh",{ref:te,renderOrder:12,frustumCulled:!1,children:[A.jsx("bufferGeometry",{ref:ae}),Te(f)]})]})},Vt={materialType:"basic",shaderPreset:"basicShader",textureMap:"none",alphaMap:"none",alphaOpacity:1,side:"front",blendMode:"normal",baseColor:"#38bdf8",opacity:.45},Wt={mouth:!0,eyes:!0,nose:!0},zt=[{label:"Wireframe",value:"wireframe"},{label:"Basic",value:"basic"},{label:"Standard",value:"standard"},{label:"Physical",value:"physical"},{label:"Toon",value:"toon"},{label:"Normal",value:"normal"},{label:"Matcap",value:"matcap"},{label:"Shader",value:"shader"}],qt=[{label:"Basic Shader",value:"basicShader"},{label:"Original Face",value:"originalFace"},{label:"Composite",value:"composite"}],Zt=[{label:"Front",value:"front"},{label:"Back",value:"back"},{label:"Double",value:"double"}],Qt=[{label:"None",value:"none"},{label:"UV Map 1",value:"canonical"},{label:"UV Map 2",value:"style2"}],$t=[{label:"None",value:"none"},{label:"Default Mask",value:"canonical"}],Jt=[{label:"Normal",value:"normal"},{label:"Add",value:"add"},{label:"Subtract",value:"subtract"},{label:"Multiply",value:"multiply"},{label:"Screen",value:"screen"},{label:"Overlay",value:"overlay"},{label:"Soft Light",value:"softLight"},{label:"Hard Light",value:"hardLight"},{label:"Lighten",value:"lighten"},{label:"Darken",value:"darken"},{label:"Difference",value:"difference"},{label:"Exclusion",value:"exclusion"}],en=(a,e)=>a==="basic"||a==="standard"||a==="physical"||a==="toon"||a==="shader"&&e==="composite",tn=(a,e)=>a==="shader"&&e==="composite",nn=`
|
|
130
|
+
varying vec2 vUv;
|
|
131
|
+
|
|
132
|
+
void main() {
|
|
133
|
+
vUv = uv;
|
|
134
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
135
|
+
}
|
|
136
|
+
`,sn=`
|
|
137
|
+
uniform sampler2D cameraTexture;
|
|
138
|
+
uniform sampler2D retouchMaskTexture;
|
|
139
|
+
uniform sampler2D mouthMaskTexture;
|
|
140
|
+
uniform vec2 texelSize;
|
|
141
|
+
uniform float retouchAmount;
|
|
142
|
+
uniform float blurRadius;
|
|
143
|
+
uniform float teethWhitening;
|
|
144
|
+
uniform float previewMask;
|
|
145
|
+
uniform float protectLandmarks;
|
|
146
|
+
varying vec2 vUv;
|
|
147
|
+
|
|
148
|
+
vec3 sampleCamera(vec2 uv) {
|
|
149
|
+
return texture2D(cameraTexture, clamp(uv, vec2(0.0), vec2(1.0))).rgb;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
vec3 readRetouchMask(vec2 uv) {
|
|
153
|
+
vec4 mask = texture2D(retouchMaskTexture, uv);
|
|
154
|
+
float faceRegion = clamp(mask.b, 0.0, 1.0);
|
|
155
|
+
float softFaceRegion = min(mask.r, faceRegion);
|
|
156
|
+
float protectedRegion = min(mask.g, faceRegion) * protectLandmarks;
|
|
157
|
+
float hardProtectedRegion = step(0.08, protectedRegion);
|
|
158
|
+
float softRetouchRegion = softFaceRegion * (1.0 - protectedRegion);
|
|
159
|
+
float hardRetouchRegion = step(0.5, faceRegion) * (1.0 - hardProtectedRegion);
|
|
160
|
+
|
|
161
|
+
return vec3(
|
|
162
|
+
clamp(softRetouchRegion, 0.0, 1.0),
|
|
163
|
+
clamp(protectedRegion, 0.0, 1.0),
|
|
164
|
+
clamp(hardRetouchRegion, 0.0, 1.0)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
float readMouthMask(vec2 uv) {
|
|
169
|
+
return clamp(texture2D(mouthMaskTexture, uv).r, 0.0, 1.0);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
float retouchCoverage(vec2 uv) {
|
|
173
|
+
return step(0.001, readRetouchMask(uv).x);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
void addMaskedBlurSample(inout vec3 color, inout float weightSum, vec2 centerUv, vec2 sampleUv, float weight) {
|
|
177
|
+
float coverage = retouchCoverage(sampleUv);
|
|
178
|
+
vec3 sampleColor = mix(sampleCamera(centerUv), sampleCamera(sampleUv), coverage);
|
|
179
|
+
color += sampleColor * weight;
|
|
180
|
+
weightSum += weight;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
vec3 maskedBlurCamera(vec2 uv, float radius) {
|
|
184
|
+
vec2 r = texelSize * radius;
|
|
185
|
+
vec3 color = sampleCamera(uv) * 0.2;
|
|
186
|
+
float weightSum = 0.2;
|
|
187
|
+
|
|
188
|
+
addMaskedBlurSample(color, weightSum, uv, uv + vec2(r.x, 0.0), 0.1);
|
|
189
|
+
addMaskedBlurSample(color, weightSum, uv, uv - vec2(r.x, 0.0), 0.1);
|
|
190
|
+
addMaskedBlurSample(color, weightSum, uv, uv + vec2(0.0, r.y), 0.1);
|
|
191
|
+
addMaskedBlurSample(color, weightSum, uv, uv - vec2(0.0, r.y), 0.1);
|
|
192
|
+
addMaskedBlurSample(color, weightSum, uv, uv + r, 0.075);
|
|
193
|
+
addMaskedBlurSample(color, weightSum, uv, uv - r, 0.075);
|
|
194
|
+
addMaskedBlurSample(color, weightSum, uv, uv + vec2(r.x, -r.y), 0.075);
|
|
195
|
+
addMaskedBlurSample(color, weightSum, uv, uv + vec2(-r.x, r.y), 0.075);
|
|
196
|
+
addMaskedBlurSample(color, weightSum, uv, uv + r * 2.0, 0.05);
|
|
197
|
+
addMaskedBlurSample(color, weightSum, uv, uv - r * 2.0, 0.05);
|
|
198
|
+
|
|
199
|
+
return color / max(weightSum, 0.001);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
vec3 whitenTeeth(vec3 color, float amount, float mouthRegion) {
|
|
203
|
+
float maxChannel = max(max(color.r, color.g), color.b);
|
|
204
|
+
float minChannel = min(min(color.r, color.g), color.b);
|
|
205
|
+
float saturation = maxChannel - minChannel;
|
|
206
|
+
float brightness = dot(color, vec3(0.299, 0.587, 0.114));
|
|
207
|
+
float redness = max(color.r - max(color.g, color.b), 0.0);
|
|
208
|
+
float greenBlueBalance = 1.0 - smoothstep(0.08, 0.24, abs(color.g - color.b));
|
|
209
|
+
float candidate =
|
|
210
|
+
smoothstep(0.34, 0.62, brightness) *
|
|
211
|
+
(1.0 - smoothstep(0.14, 0.32, redness)) *
|
|
212
|
+
(1.0 - smoothstep(0.18, 0.42, saturation)) *
|
|
213
|
+
greenBlueBalance;
|
|
214
|
+
float whiteningMask = clamp(mouthRegion * candidate, 0.0, 1.0);
|
|
215
|
+
vec3 desaturated = mix(color, vec3(brightness), 0.42);
|
|
216
|
+
vec3 brightened = min(desaturated + vec3(0.16), vec3(1.0));
|
|
217
|
+
|
|
218
|
+
return mix(color, brightened, clamp(amount * whiteningMask * 0.38, 0.0, 1.0));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
void main() {
|
|
222
|
+
vec3 original = sampleCamera(vUv);
|
|
223
|
+
vec3 masks = readRetouchMask(vUv);
|
|
224
|
+
float mouthMask = readMouthMask(vUv);
|
|
225
|
+
|
|
226
|
+
if (previewMask > 0.5) {
|
|
227
|
+
float sharpPreview = 1.0 - step(0.001, retouchAmount + blurRadius);
|
|
228
|
+
float retouchPreview = mix(masks.x, masks.z, sharpPreview);
|
|
229
|
+
float protectedPreview = mix(masks.y, step(0.08, masks.y), sharpPreview);
|
|
230
|
+
float whiteningPreview = mouthMask * teethWhitening;
|
|
231
|
+
vec3 facePreview = vec3(retouchPreview, 0.08, 0.08);
|
|
232
|
+
vec3 featurePreview = vec3(0.05, protectedPreview, 0.1);
|
|
233
|
+
vec3 whiteningMaskPreview = vec3(whiteningPreview, whiteningPreview, 0.05);
|
|
234
|
+
vec3 maskPreview = max(max(facePreview, featurePreview), whiteningMaskPreview);
|
|
235
|
+
vec3 debugColor = mix(original * 0.18, maskPreview, max(max(retouchPreview, protectedPreview), whiteningPreview));
|
|
236
|
+
gl_FragColor = vec4(debugColor, 1.0);
|
|
237
|
+
#include <colorspace_fragment>
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
float effectiveBlurRadius = min(blurRadius, 7.0);
|
|
242
|
+
vec3 smallBlur = maskedBlurCamera(vUv, max(0.0, effectiveBlurRadius * 0.45));
|
|
243
|
+
vec3 largeBlur = maskedBlurCamera(vUv, max(0.0, effectiveBlurRadius));
|
|
244
|
+
vec3 detail = original - smallBlur;
|
|
245
|
+
float detailAmount = mix(0.5, 0.9, masks.y);
|
|
246
|
+
vec3 smoothed = clamp(largeBlur + detail * detailAmount, 0.0, 1.0);
|
|
247
|
+
vec3 color = mix(original, smoothed, min(retouchAmount, 0.72) * masks.x);
|
|
248
|
+
color = whitenTeeth(color, teethWhitening, mouthMask);
|
|
249
|
+
gl_FragColor = vec4(color, 1.0);
|
|
250
|
+
#include <colorspace_fragment>
|
|
251
|
+
}
|
|
252
|
+
`,rn=({retouchMask:a,mouthMask:e,retouchAmount:t,blurRadius:s,teethWhitening:n,previewMask:r,protectLandmarks:o})=>{const{camera:c,size:i}=re.useThree(),l=je.useXRCameraTexture(),u=S.useMemo(()=>({cameraTexture:{value:null},retouchMaskTexture:{value:a},mouthMaskTexture:{value:e},texelSize:{value:new E.Vector2(1/1280,1/720)},retouchAmount:{value:t},blurRadius:{value:s},teethWhitening:{value:n},previewMask:{value:0},protectLandmarks:{value:1}}),[e,a]),h=S.useMemo(()=>{if(!(c instanceof E.PerspectiveCamera))return[10,10];const T=(c.position.z||5)- -1,x=E.MathUtils.degToRad(c.fov),g=2*Math.tan(x/2)*T;return[g*(i.width/i.height),g]},[c,i]);return S.useEffect(()=>{u.cameraTexture.value=l??null,u.retouchMaskTexture.value=a,u.mouthMaskTexture.value=e,u.texelSize.value.set(1/Math.max(i.width,1),1/Math.max(i.height,1)),u.retouchAmount.value=t,u.blurRadius.value=s,u.teethWhitening.value=n,u.previewMask.value=r?1:0,u.protectLandmarks.value=o?1:0},[s,l,r,o,t,e,a,n,i.height,i.width,u]),l?A.jsx("group",{position:[0,0,-1],children:A.jsxs("mesh",{renderOrder:-1e3,children:[A.jsx("planeGeometry",{args:h}),A.jsx("shaderMaterial",{uniforms:u,vertexShader:nn,fragmentShader:sn,depthTest:!1,depthWrite:!1,toneMapped:!1})]})}):null},Ee=512,We=[10,338,297,332,284,251,389,356,454,323,361,288,397,365,379,378,400,377,152,148,176,149,150,136,172,58,132,93,234,127,162,21,54,103,67,109],ft=[33,246,161,160,159,158,157,173,133,155,154,153,145,144,163,7],pt=[362,398,384,385,386,387,388,466,263,249,390,373,374,380,381,382],mt=[61,146,91,181,84,17,314,405,321,375,291,409,270,269,267,0,37,39,40,185],ze=[78,95,88,178,87,14,317,402,318,324,308,415,310,311,312,13,82,81,80,191],gt=[70,63,105,66,107,55,65,52,53,46],At=[336,296,334,293,300,276,283,282,295,285],on=[ft,pt,mt,ze,gt,At],nt=(a,e,t)=>{qe(a,e,We,t)},an=(a,e,t)=>{on.forEach(s=>qe(a,e,s,t))},st=(a,e,t)=>{const s=a[e];return s?{x:s.x*t,y:s.y*t}:null},qe=(a,e,t,s)=>{const n=st(e,t[0],s);if(n){a.beginPath(),a.moveTo(n.x,n.y);for(let r=1;r<t.length;r+=1){const o=st(e,t[r],s);o&&a.lineTo(o.x,o.y)}a.closePath(),a.fill()}},Tt=(a,e,t=Ee)=>{a.clearRect(0,0,t,t),e!=null&&e.length&&(a.save(),a.globalCompositeOperation="lighter",a.fillStyle="rgb(0, 0, 255)",nt(a,e,t),a.restore(),a.save(),a.globalCompositeOperation="lighter",a.filter="blur(8px)",a.fillStyle="rgb(255, 0, 0)",nt(a,e,t),a.restore(),a.save(),a.globalCompositeOperation="lighter",a.filter="blur(3px)",a.fillStyle="rgb(0, 255, 0)",an(a,e,t),a.restore())},xt=(a,e,t=Ee)=>{a.clearRect(0,0,t,t),e!=null&&e.length&&(a.save(),a.filter="blur(2px)",a.fillStyle="rgb(255, 255, 255)",qe(a,e,ze,t),a.restore())},cn=.1,ln=.48,un=.012,hn=1,dn=1.1,fn=1.15,pn=.04,mn=[61,146,91,181,84,17,314,405,321,375,291,78,95,88,178,87,14,317,402,318,324,308,191,80,81,82,13,312,311,310,415],gn=[33,7,163,144,145,153,154,155,133,173,157,158,159,160,161,246],An=[362,382,381,380,374,373,390,249,263,466,388,387,386,385,384,398],Tn=[70,63,105,66,107,55,65,52,53,46],xn=[336,296,334,293,300,285,295,282,283,276],vn=[1,2,4,5,6,19,94,97,98,99,102,129,168,195,197,240,279,326,327,328,331,344,358,440],vt=[mn,gn,An,Tn,xn,vn],bt=[61,91,84,17,314,321,291,78,178,14,402,308,80,13,312,0,33,144,145,153,155,133,157,159,161,246,362,382,374,373,263,466,388,386,384,398,70,105,107,55,52,46,336,334,300,285,282,276,1,4,5,94,97,98,327,326,2,195],Re=a=>Math.min(Math.max(a,0),1),rt=(a,e,t,s,n,r)=>{let o=1,c=1,i=0,l=0,u=0;if(e.forEach(b=>{const M=a[b];M&&(o=Math.min(o,M.x),c=Math.min(c,M.y),i=Math.max(i,M.x),l=Math.max(l,M.y),u+=1)}),u===0)return null;const h=i-o,f=l-c,m=Math.max(h*t,r),T=Math.max(f*t,r),x=Re(o-m),g=Re(c-T),p=Re(i+m),v=Re(l+T);return{centerX:(x+p)*.5,centerY:(g+v)*.5,radiusX:Math.max((p-x)*.5,r),radiusY:Math.max((v-g)*.5,r),strength:s,kind:n}},bn=(a,e,t)=>a?{centerX:a.x,centerY:a.y,radiusX:e,radiusY:e,strength:t,kind:"feature"}:null,Mt=(a,e)=>{if(!(a!=null&&a.length))return[];const t=(e==null?void 0:e.faceOvalIndices)??We,s=(e==null?void 0:e.featureGroups)??vt,n=(e==null?void 0:e.featurePointIndices)??bt,r=(e==null?void 0:e.faceBoundsExpansion)??cn,o=(e==null?void 0:e.featureBoundsExpansion)??ln,c=(e==null?void 0:e.minRegionRadius)??un,i=(e==null?void 0:e.faceRegionStrength)??hn,l=(e==null?void 0:e.featureRegionStrength)??dn,u=(e==null?void 0:e.featurePointRegionStrength)??fn,h=(e==null?void 0:e.featurePointRadiusRatio)??pn,f=[],m=rt(a,t,r,i,"face",c);m&&f.push(m);const T=Math.max(Math.max((m==null?void 0:m.radiusX)??0,(m==null?void 0:m.radiusY)??0)*h,c*1.35);return s.forEach(x=>{const g=rt(a,x,o,l,"feature",c);g&&f.push(g)}),n.forEach(x=>{const g=bn(a[x],T,u);g&&f.push(g)}),f},ot=a=>{const e=document.createElement("canvas");e.width=a,e.height=a;const t=e.getContext("2d",{willReadFrequently:!1});if(!t)throw new Error("Unable to create face retouch mask context");const s=new E.CanvasTexture(e);return s.colorSpace=E.NoColorSpace,s.minFilter=E.LinearFilter,s.magFilter=E.LinearFilter,s.generateMipmaps=!1,s.needsUpdate=!0,{canvas:e,context:t,texture:s}},Mn=(a,e=Ee)=>{const{mask:t,mouthMask:s}=S.useMemo(()=>({mask:ot(e),mouthMask:ot(e)}),[e]);return S.useEffect(()=>{let n=0;const r=()=>{var c,i;n=requestAnimationFrame(r);const o=(i=(c=a==null?void 0:a.detectionResults)==null?void 0:c.faceLandmarks)==null?void 0:i[0];Tt(t.context,o,e),xt(s.context,o,e),t.texture.needsUpdate=!0,s.texture.needsUpdate=!0};return r(),()=>{cancelAnimationFrame(n)}},[a,t.context,t.texture,s.context,s.texture,e]),{canvas:t.canvas,texture:t.texture,mouthTexture:s.texture}},Rn=a=>a.map(e=>[e.centerX.toFixed(4),e.centerY.toFixed(4),e.radiusX.toFixed(4),e.radiusY.toFixed(4),e.strength.toFixed(2),e.kind].join(",")).join("|"),En=(a,e)=>{const[t,s]=S.useState([]);return S.useEffect(()=>{let n=0,r="";const o=()=>{var u,h;n=requestAnimationFrame(o);const c=(h=(u=a==null?void 0:a.detectionResults)==null?void 0:u.faceLandmarks)==null?void 0:h[0],i=Mt(c,e),l=Rn(i);l!==r&&(r=l,s(i))};return o(),()=>{cancelAnimationFrame(n)}},[a]),t};function at(a,e){if(e===d.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),a;if(e===d.TriangleFanDrawMode||e===d.TriangleStripDrawMode){let t=a.getIndex();if(t===null){const o=[],c=a.getAttribute("position");if(c!==void 0){for(let i=0;i<c.count;i++)o.push(i);a.setIndex(o),t=a.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),a}const s=t.count-2,n=[];if(e===d.TriangleFanDrawMode)for(let o=1;o<=s;o++)n.push(t.getX(0)),n.push(t.getX(o)),n.push(t.getX(o+1));else for(let o=0;o<s;o++)o%2===0?(n.push(t.getX(o)),n.push(t.getX(o+1)),n.push(t.getX(o+2))):(n.push(t.getX(o+2)),n.push(t.getX(o+1)),n.push(t.getX(o)));n.length/3!==s&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const r=a.clone();return r.setIndex(n),r.clearGroups(),r}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),a}class Sn extends d.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new Cn(t)}),this.register(function(t){return new In(t)}),this.register(function(t){return new Gn(t)}),this.register(function(t){return new Hn(t)}),this.register(function(t){return new jn(t)}),this.register(function(t){return new Pn(t)}),this.register(function(t){return new Nn(t)}),this.register(function(t){return new On(t)}),this.register(function(t){return new Dn(t)}),this.register(function(t){return new Ln(t)}),this.register(function(t){return new Bn(t)}),this.register(function(t){return new Fn(t)}),this.register(function(t){return new kn(t)}),this.register(function(t){return new Un(t)}),this.register(function(t){return new _n(t)}),this.register(function(t){return new Xn(t)}),this.register(function(t){return new Kn(t)})}load(e,t,s,n){const r=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const l=d.LoaderUtils.extractUrlBase(e);o=d.LoaderUtils.resolveURL(l,this.path)}else o=d.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const c=function(l){n?n(l):console.error(l),r.manager.itemError(e),r.manager.itemEnd(e)},i=new d.FileLoader(this.manager);i.setPath(this.path),i.setResponseType("arraybuffer"),i.setRequestHeader(this.requestHeader),i.setWithCredentials(this.withCredentials),i.load(e,function(l){try{r.parse(l,o,function(u){t(u),r.manager.itemEnd(e)},c)}catch(u){c(u)}},s,c)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,s,n){let r;const o={},c={},i=new TextDecoder;if(typeof e=="string")r=JSON.parse(e);else if(e instanceof ArrayBuffer)if(i.decode(new Uint8Array(e,0,4))===Rt){try{o[R.KHR_BINARY_GLTF]=new Yn(e)}catch(h){n&&n(h);return}r=JSON.parse(o[R.KHR_BINARY_GLTF].content)}else r=JSON.parse(i.decode(e));else r=e;if(r.asset===void 0||r.asset.version[0]<2){n&&n(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const l=new rs(r,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});l.fileLoader.setRequestHeader(this.requestHeader);for(let u=0;u<this.pluginCallbacks.length;u++){const h=this.pluginCallbacks[u](l);h.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),c[h.name]=h,o[h.name]=!0}if(r.extensionsUsed)for(let u=0;u<r.extensionsUsed.length;++u){const h=r.extensionsUsed[u],f=r.extensionsRequired||[];switch(h){case R.KHR_MATERIALS_UNLIT:o[h]=new yn;break;case R.KHR_DRACO_MESH_COMPRESSION:o[h]=new Vn(r,this.dracoLoader);break;case R.KHR_TEXTURE_TRANSFORM:o[h]=new Wn;break;case R.KHR_MESH_QUANTIZATION:o[h]=new zn;break;default:f.indexOf(h)>=0&&c[h]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+h+'".')}}l.setExtensions(o),l.setPlugins(c),l.parse(s,n)}parseAsync(e,t){const s=this;return new Promise(function(n,r){s.parse(e,t,n,r)})}}function wn(){let a={};return{get:function(e){return a[e]},add:function(e,t){a[e]=t},remove:function(e){delete a[e]},removeAll:function(){a={}}}}const R={KHR_BINARY_GLTF:"KHR_binary_glTF",KHR_DRACO_MESH_COMPRESSION:"KHR_draco_mesh_compression",KHR_LIGHTS_PUNCTUAL:"KHR_lights_punctual",KHR_MATERIALS_CLEARCOAT:"KHR_materials_clearcoat",KHR_MATERIALS_DISPERSION:"KHR_materials_dispersion",KHR_MATERIALS_IOR:"KHR_materials_ior",KHR_MATERIALS_SHEEN:"KHR_materials_sheen",KHR_MATERIALS_SPECULAR:"KHR_materials_specular",KHR_MATERIALS_TRANSMISSION:"KHR_materials_transmission",KHR_MATERIALS_IRIDESCENCE:"KHR_materials_iridescence",KHR_MATERIALS_ANISOTROPY:"KHR_materials_anisotropy",KHR_MATERIALS_UNLIT:"KHR_materials_unlit",KHR_MATERIALS_VOLUME:"KHR_materials_volume",KHR_TEXTURE_BASISU:"KHR_texture_basisu",KHR_TEXTURE_TRANSFORM:"KHR_texture_transform",KHR_MESH_QUANTIZATION:"KHR_mesh_quantization",KHR_MATERIALS_EMISSIVE_STRENGTH:"KHR_materials_emissive_strength",EXT_MATERIALS_BUMP:"EXT_materials_bump",EXT_TEXTURE_WEBP:"EXT_texture_webp",EXT_TEXTURE_AVIF:"EXT_texture_avif",EXT_MESHOPT_COMPRESSION:"EXT_meshopt_compression",EXT_MESH_GPU_INSTANCING:"EXT_mesh_gpu_instancing"};class _n{constructor(e){this.parser=e,this.name=R.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let s=0,n=t.length;s<n;s++){const r=t[s];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){const t=this.parser,s="light:"+e;let n=t.cache.get(s);if(n)return n;const r=t.json,i=((r.extensions&&r.extensions[this.name]||{}).lights||[])[e];let l;const u=new d.Color(16777215);i.color!==void 0&&u.setRGB(i.color[0],i.color[1],i.color[2],d.LinearSRGBColorSpace);const h=i.range!==void 0?i.range:0;switch(i.type){case"directional":l=new d.DirectionalLight(u),l.target.position.set(0,0,-1),l.add(l.target);break;case"point":l=new d.PointLight(u),l.distance=h;break;case"spot":l=new d.SpotLight(u),l.distance=h,i.spot=i.spot||{},i.spot.innerConeAngle=i.spot.innerConeAngle!==void 0?i.spot.innerConeAngle:0,i.spot.outerConeAngle=i.spot.outerConeAngle!==void 0?i.spot.outerConeAngle:Math.PI/4,l.angle=i.spot.outerConeAngle,l.penumbra=1-i.spot.innerConeAngle/i.spot.outerConeAngle,l.target.position.set(0,0,-1),l.add(l.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+i.type)}return l.position.set(0,0,0),j(l,i),i.intensity!==void 0&&(l.intensity=i.intensity),l.name=t.createUniqueName(i.name||"light_"+e),n=Promise.resolve(l),t.cache.add(s,n),n}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,s=this.parser,r=s.json.nodes[e],c=(r.extensions&&r.extensions[this.name]||{}).light;return c===void 0?null:this._loadLight(c).then(function(i){return s._getNodeRef(t.cache,c,i)})}}class yn{constructor(){this.name=R.KHR_MATERIALS_UNLIT}getMaterialType(){return d.MeshBasicMaterial}extendParams(e,t,s){const n=[];e.color=new d.Color(1,1,1),e.opacity=1;const r=t.pbrMetallicRoughness;if(r){if(Array.isArray(r.baseColorFactor)){const o=r.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],d.LinearSRGBColorSpace),e.opacity=o[3]}r.baseColorTexture!==void 0&&n.push(s.assignTexture(e,"map",r.baseColorTexture,d.SRGBColorSpace))}return Promise.all(n)}}class Ln{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=n.extensions[this.name].emissiveStrength;return r!==void 0&&(t.emissiveIntensity=r),Promise.resolve()}}class Cn{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];if(o.clearcoatFactor!==void 0&&(t.clearcoat=o.clearcoatFactor),o.clearcoatTexture!==void 0&&r.push(s.assignTexture(t,"clearcoatMap",o.clearcoatTexture)),o.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=o.clearcoatRoughnessFactor),o.clearcoatRoughnessTexture!==void 0&&r.push(s.assignTexture(t,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),o.clearcoatNormalTexture!==void 0&&(r.push(s.assignTexture(t,"clearcoatNormalMap",o.clearcoatNormalTexture)),o.clearcoatNormalTexture.scale!==void 0)){const c=o.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new d.Vector2(c,c)}return Promise.all(r)}}class In{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_DISPERSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=n.extensions[this.name];return t.dispersion=r.dispersion!==void 0?r.dispersion:0,Promise.resolve()}}class Fn{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return o.iridescenceFactor!==void 0&&(t.iridescence=o.iridescenceFactor),o.iridescenceTexture!==void 0&&r.push(s.assignTexture(t,"iridescenceMap",o.iridescenceTexture)),o.iridescenceIor!==void 0&&(t.iridescenceIOR=o.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),o.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=o.iridescenceThicknessMinimum),o.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=o.iridescenceThicknessMaximum),o.iridescenceThicknessTexture!==void 0&&r.push(s.assignTexture(t,"iridescenceThicknessMap",o.iridescenceThicknessTexture)),Promise.all(r)}}class Pn{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_SHEEN}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[];t.sheenColor=new d.Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const o=n.extensions[this.name];if(o.sheenColorFactor!==void 0){const c=o.sheenColorFactor;t.sheenColor.setRGB(c[0],c[1],c[2],d.LinearSRGBColorSpace)}return o.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=o.sheenRoughnessFactor),o.sheenColorTexture!==void 0&&r.push(s.assignTexture(t,"sheenColorMap",o.sheenColorTexture,d.SRGBColorSpace)),o.sheenRoughnessTexture!==void 0&&r.push(s.assignTexture(t,"sheenRoughnessMap",o.sheenRoughnessTexture)),Promise.all(r)}}class Nn{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return o.transmissionFactor!==void 0&&(t.transmission=o.transmissionFactor),o.transmissionTexture!==void 0&&r.push(s.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(r)}}class On{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_VOLUME}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];t.thickness=o.thicknessFactor!==void 0?o.thicknessFactor:0,o.thicknessTexture!==void 0&&r.push(s.assignTexture(t,"thicknessMap",o.thicknessTexture)),t.attenuationDistance=o.attenuationDistance||1/0;const c=o.attenuationColor||[1,1,1];return t.attenuationColor=new d.Color().setRGB(c[0],c[1],c[2],d.LinearSRGBColorSpace),Promise.all(r)}}class Dn{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_IOR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=n.extensions[this.name];return t.ior=r.ior!==void 0?r.ior:1.5,Promise.resolve()}}class Bn{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_SPECULAR}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];t.specularIntensity=o.specularFactor!==void 0?o.specularFactor:1,o.specularTexture!==void 0&&r.push(s.assignTexture(t,"specularIntensityMap",o.specularTexture));const c=o.specularColorFactor||[1,1,1];return t.specularColor=new d.Color().setRGB(c[0],c[1],c[2],d.LinearSRGBColorSpace),o.specularColorTexture!==void 0&&r.push(s.assignTexture(t,"specularColorMap",o.specularColorTexture,d.SRGBColorSpace)),Promise.all(r)}}class Un{constructor(e){this.parser=e,this.name=R.EXT_MATERIALS_BUMP}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return t.bumpScale=o.bumpFactor!==void 0?o.bumpFactor:1,o.bumpTexture!==void 0&&r.push(s.assignTexture(t,"bumpMap",o.bumpTexture)),Promise.all(r)}}class kn{constructor(e){this.parser=e,this.name=R.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const s=this.parser.json.materials[e];return!s.extensions||!s.extensions[this.name]?null:d.MeshPhysicalMaterial}extendMaterialParams(e,t){const s=this.parser,n=s.json.materials[e];if(!n.extensions||!n.extensions[this.name])return Promise.resolve();const r=[],o=n.extensions[this.name];return o.anisotropyStrength!==void 0&&(t.anisotropy=o.anisotropyStrength),o.anisotropyRotation!==void 0&&(t.anisotropyRotation=o.anisotropyRotation),o.anisotropyTexture!==void 0&&r.push(s.assignTexture(t,"anisotropyMap",o.anisotropyTexture)),Promise.all(r)}}class Gn{constructor(e){this.parser=e,this.name=R.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,s=t.json,n=s.textures[e];if(!n.extensions||!n.extensions[this.name])return null;const r=n.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(s.extensionsRequired&&s.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,r.source,o)}}class Hn{constructor(e){this.parser=e,this.name=R.EXT_TEXTURE_WEBP,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,r=n.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],c=n.images[o.source];let i=s.textureLoader;if(c.uri){const l=s.options.manager.getHandler(c.uri);l!==null&&(i=l)}return this.detectSupport().then(function(l){if(l)return s.loadTextureImage(e,o.source,i);if(n.extensionsRequired&&n.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: WebP required by asset but unsupported.");return s.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA",t.onload=t.onerror=function(){e(t.height===1)}})),this.isSupported}}class jn{constructor(e){this.parser=e,this.name=R.EXT_TEXTURE_AVIF,this.isSupported=null}loadTexture(e){const t=this.name,s=this.parser,n=s.json,r=n.textures[e];if(!r.extensions||!r.extensions[t])return null;const o=r.extensions[t],c=n.images[o.source];let i=s.textureLoader;if(c.uri){const l=s.options.manager.getHandler(c.uri);l!==null&&(i=l)}return this.detectSupport().then(function(l){if(l)return s.loadTextureImage(e,o.source,i);if(n.extensionsRequired&&n.extensionsRequired.indexOf(t)>=0)throw new Error("THREE.GLTFLoader: AVIF required by asset but unsupported.");return s.loadTexture(e)})}detectSupport(){return this.isSupported||(this.isSupported=new Promise(function(e){const t=new Image;t.src="data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAABcAAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAEAAAABAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQAMAAAAABNjb2xybmNseAACAAIABoAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAAB9tZGF0EgAKCBgABogQEDQgMgkQAAAAB8dSLfI=",t.onload=t.onerror=function(){e(t.height===1)}})),this.isSupported}}class Xn{constructor(e){this.name=R.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,s=t.bufferViews[e];if(s.extensions&&s.extensions[this.name]){const n=s.extensions[this.name],r=this.parser.getDependency("buffer",n.buffer),o=this.parser.options.meshoptDecoder;if(!o||!o.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files");return null}return r.then(function(c){const i=n.byteOffset||0,l=n.byteLength||0,u=n.count,h=n.byteStride,f=new Uint8Array(c,i,l);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(u,h,f,n.mode,n.filter).then(function(m){return m.buffer}):o.ready.then(function(){const m=new ArrayBuffer(u*h);return o.decodeGltfBuffer(new Uint8Array(m),u,h,f,n.mode,n.filter),m})})}else return null}}class Kn{constructor(e){this.name=R.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,s=t.nodes[e];if(!s.extensions||!s.extensions[this.name]||s.mesh===void 0)return null;const n=t.meshes[s.mesh];for(const l of n.primitives)if(l.mode!==O.TRIANGLES&&l.mode!==O.TRIANGLE_STRIP&&l.mode!==O.TRIANGLE_FAN&&l.mode!==void 0)return null;const o=s.extensions[this.name].attributes,c=[],i={};for(const l in o)c.push(this.parser.getDependency("accessor",o[l]).then(u=>(i[l]=u,i[l])));return c.length<1?null:(c.push(this.parser.createNodeMesh(e)),Promise.all(c).then(l=>{const u=l.pop(),h=u.isGroup?u.children:[u],f=l[0].count,m=[];for(const T of h){const x=new d.Matrix4,g=new d.Vector3,p=new d.Quaternion,v=new d.Vector3(1,1,1),b=new d.InstancedMesh(T.geometry,T.material,f);for(let M=0;M<f;M++)i.TRANSLATION&&g.fromBufferAttribute(i.TRANSLATION,M),i.ROTATION&&p.fromBufferAttribute(i.ROTATION,M),i.SCALE&&v.fromBufferAttribute(i.SCALE,M),b.setMatrixAt(M,x.compose(g,p,v));for(const M in i)if(M==="_COLOR_0"){const y=i[M];b.instanceColor=new d.InstancedBufferAttribute(y.array,y.itemSize,y.normalized)}else M!=="TRANSLATION"&&M!=="ROTATION"&&M!=="SCALE"&&T.geometry.setAttribute(M,i[M]);d.Object3D.prototype.copy.call(b,T),this.parser.assignFinalMaterial(b),m.push(b)}return u.isGroup?(u.clear(),u.add(...m),u):m[0]}))}}const Rt="glTF",fe=12,it={JSON:1313821514,BIN:5130562};class Yn{constructor(e){this.name=R.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,fe),s=new TextDecoder;if(this.header={magic:s.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==Rt)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const n=this.header.length-fe,r=new DataView(e,fe);let o=0;for(;o<n;){const c=r.getUint32(o,!0);o+=4;const i=r.getUint32(o,!0);if(o+=4,i===it.JSON){const l=new Uint8Array(e,fe+o,c);this.content=s.decode(l)}else if(i===it.BIN){const l=fe+o;this.body=e.slice(l,l+c)}o+=c}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class Vn{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=R.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const s=this.json,n=this.dracoLoader,r=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,c={},i={},l={};for(const u in o){const h=Ye[u]||u.toLowerCase();c[h]=o[u]}for(const u in e.attributes){const h=Ye[u]||u.toLowerCase();if(o[u]!==void 0){const f=s.accessors[e.attributes[u]],m=oe[f.componentType];l[h]=m.name,i[h]=f.normalized===!0}}return t.getDependency("bufferView",r).then(function(u){return new Promise(function(h,f){n.decodeDracoFile(u,function(m){for(const T in m.attributes){const x=m.attributes[T],g=i[T];g!==void 0&&(x.normalized=g)}h(m)},c,l,d.LinearSRGBColorSpace,f)})})}}class Wn{constructor(){this.name=R.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0||(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0),e}}class zn{constructor(){this.name=R.KHR_MESH_QUANTIZATION}}class Et extends d.Interpolant{constructor(e,t,s,n){super(e,t,s,n)}copySampleValue_(e){const t=this.resultBuffer,s=this.sampleValues,n=this.valueSize,r=e*n*3+n;for(let o=0;o!==n;o++)t[o]=s[r+o];return t}interpolate_(e,t,s,n){const r=this.resultBuffer,o=this.sampleValues,c=this.valueSize,i=c*2,l=c*3,u=n-t,h=(s-t)/u,f=h*h,m=f*h,T=e*l,x=T-l,g=-2*m+3*f,p=m-f,v=1-g,b=p-f+h;for(let M=0;M!==c;M++){const y=o[x+M+c],C=o[x+M+i]*u,L=o[T+M+c],D=o[T+M]*u;r[M]=v*y+b*C+g*L+p*D}return r}}const qn=new d.Quaternion;class Zn extends Et{interpolate_(e,t,s,n){const r=super.interpolate_(e,t,s,n);return qn.fromArray(r).normalize().toArray(r),r}}const O={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},oe={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},ct={9728:d.NearestFilter,9729:d.LinearFilter,9984:d.NearestMipmapNearestFilter,9985:d.LinearMipmapNearestFilter,9986:d.NearestMipmapLinearFilter,9987:d.LinearMipmapLinearFilter},lt={33071:d.ClampToEdgeWrapping,33648:d.MirroredRepeatWrapping,10497:d.RepeatWrapping},Be={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ye={POSITION:"position",NORMAL:"normal",TANGENT:"tangent",TEXCOORD_0:"uv",TEXCOORD_1:"uv1",TEXCOORD_2:"uv2",TEXCOORD_3:"uv3",COLOR_0:"color",WEIGHTS_0:"skinWeight",JOINTS_0:"skinIndex"},z={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},Qn={CUBICSPLINE:void 0,LINEAR:d.InterpolateLinear,STEP:d.InterpolateDiscrete},Ue={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function $n(a){return a.DefaultMaterial===void 0&&(a.DefaultMaterial=new d.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:d.FrontSide})),a.DefaultMaterial}function Q(a,e,t){for(const s in t.extensions)a[s]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[s]=t.extensions[s])}function j(a,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(a.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function Jn(a,e,t){let s=!1,n=!1,r=!1;for(let l=0,u=e.length;l<u;l++){const h=e[l];if(h.POSITION!==void 0&&(s=!0),h.NORMAL!==void 0&&(n=!0),h.COLOR_0!==void 0&&(r=!0),s&&n&&r)break}if(!s&&!n&&!r)return Promise.resolve(a);const o=[],c=[],i=[];for(let l=0,u=e.length;l<u;l++){const h=e[l];if(s){const f=h.POSITION!==void 0?t.getDependency("accessor",h.POSITION):a.attributes.position;o.push(f)}if(n){const f=h.NORMAL!==void 0?t.getDependency("accessor",h.NORMAL):a.attributes.normal;c.push(f)}if(r){const f=h.COLOR_0!==void 0?t.getDependency("accessor",h.COLOR_0):a.attributes.color;i.push(f)}}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(i)]).then(function(l){const u=l[0],h=l[1],f=l[2];return s&&(a.morphAttributes.position=u),n&&(a.morphAttributes.normal=h),r&&(a.morphAttributes.color=f),a.morphTargetsRelative=!0,a})}function es(a,e){if(a.updateMorphTargets(),e.weights!==void 0)for(let t=0,s=e.weights.length;t<s;t++)a.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(a.morphTargetInfluences.length===t.length){a.morphTargetDictionary={};for(let s=0,n=t.length;s<n;s++)a.morphTargetDictionary[t[s]]=s}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function ts(a){let e;const t=a.extensions&&a.extensions[R.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+ke(t.attributes):e=a.indices+":"+ke(a.attributes)+":"+a.mode,a.targets!==void 0)for(let s=0,n=a.targets.length;s<n;s++)e+=":"+ke(a.targets[s]);return e}function ke(a){let e="";const t=Object.keys(a).sort();for(let s=0,n=t.length;s<n;s++)e+=t[s]+":"+a[t[s]]+";";return e}function Ve(a){switch(a){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw new Error("THREE.GLTFLoader: Unsupported normalized accessor component type.")}}function ns(a){return a.search(/\.jpe?g($|\?)/i)>0||a.search(/^data\:image\/jpeg/)===0?"image/jpeg":a.search(/\.webp($|\?)/i)>0||a.search(/^data\:image\/webp/)===0?"image/webp":a.search(/\.ktx2($|\?)/i)>0||a.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const ss=new d.Matrix4;class rs{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new wn,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let s=!1,n=-1,r=!1,o=-1;if(typeof navigator<"u"){const c=navigator.userAgent;s=/^((?!chrome|android).)*safari/i.test(c)===!0;const i=c.match(/Version\/(\d+)/);n=s&&i?parseInt(i[1],10):-1,r=c.indexOf("Firefox")>-1,o=r?c.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||s&&n<17||r&&o<98?this.textureLoader=new d.TextureLoader(this.options.manager):this.textureLoader=new d.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new d.FileLoader(this.options.manager),this.fileLoader.setResponseType("arraybuffer"),this.options.crossOrigin==="use-credentials"&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){const s=this,n=this.json,r=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(o){return o._markDefs&&o._markDefs()}),Promise.all(this._invokeAll(function(o){return o.beforeRoot&&o.beforeRoot()})).then(function(){return Promise.all([s.getDependencies("scene"),s.getDependencies("animation"),s.getDependencies("camera")])}).then(function(o){const c={scene:o[0][n.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:n.asset,parser:s,userData:{}};return Q(r,c,n),j(c,n),Promise.all(s._invokeAll(function(i){return i.afterRoot&&i.afterRoot(c)})).then(function(){for(const i of c.scenes)i.updateMatrixWorld();e(c)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],s=this.json.meshes||[];for(let n=0,r=t.length;n<r;n++){const o=t[n].joints;for(let c=0,i=o.length;c<i;c++)e[o[c]].isBone=!0}for(let n=0,r=e.length;n<r;n++){const o=e[n];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(s[o.mesh].isSkinnedMesh=!0)),o.camera!==void 0&&this._addNodeRef(this.cameraCache,o.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,s){if(e.refs[t]<=1)return s;const n=s.clone(),r=(o,c)=>{const i=this.associations.get(o);i!=null&&this.associations.set(c,i);for(const[l,u]of o.children.entries())r(u,c.children[l])};return r(s,n),n.name+="_instance_"+e.uses[t]++,n}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let s=0;s<t.length;s++){const n=e(t[s]);if(n)return n}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const s=[];for(let n=0;n<t.length;n++){const r=e(t[n]);r&&s.push(r)}return s}getDependency(e,t){const s=e+":"+t;let n=this.cache.get(s);if(!n){switch(e){case"scene":n=this.loadScene(t);break;case"node":n=this._invokeOne(function(r){return r.loadNode&&r.loadNode(t)});break;case"mesh":n=this._invokeOne(function(r){return r.loadMesh&&r.loadMesh(t)});break;case"accessor":n=this.loadAccessor(t);break;case"bufferView":n=this._invokeOne(function(r){return r.loadBufferView&&r.loadBufferView(t)});break;case"buffer":n=this.loadBuffer(t);break;case"material":n=this._invokeOne(function(r){return r.loadMaterial&&r.loadMaterial(t)});break;case"texture":n=this._invokeOne(function(r){return r.loadTexture&&r.loadTexture(t)});break;case"skin":n=this.loadSkin(t);break;case"animation":n=this._invokeOne(function(r){return r.loadAnimation&&r.loadAnimation(t)});break;case"camera":n=this.loadCamera(t);break;default:if(n=this._invokeOne(function(r){return r!=this&&r.getDependency&&r.getDependency(e,t)}),!n)throw new Error("Unknown type: "+e);break}this.cache.add(s,n)}return n}getDependencies(e){let t=this.cache.get(e);if(!t){const s=this,n=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(n.map(function(r,o){return s.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],s=this.fileLoader;if(t.type&&t.type!=="arraybuffer")throw new Error("THREE.GLTFLoader: "+t.type+" buffer type is not supported.");if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[R.KHR_BINARY_GLTF].body);const n=this.options;return new Promise(function(r,o){s.load(d.LoaderUtils.resolveURL(t.uri,n.path),r,void 0,function(){o(new Error('THREE.GLTFLoader: Failed to load buffer "'+t.uri+'".'))})})}loadBufferView(e){const t=this.json.bufferViews[e];return this.getDependency("buffer",t.buffer).then(function(s){const n=t.byteLength||0,r=t.byteOffset||0;return s.slice(r,r+n)})}loadAccessor(e){const t=this,s=this.json,n=this.json.accessors[e];if(n.bufferView===void 0&&n.sparse===void 0){const o=Be[n.type],c=oe[n.componentType],i=n.normalized===!0,l=new c(n.count*o);return Promise.resolve(new d.BufferAttribute(l,o,i))}const r=[];return n.bufferView!==void 0?r.push(this.getDependency("bufferView",n.bufferView)):r.push(null),n.sparse!==void 0&&(r.push(this.getDependency("bufferView",n.sparse.indices.bufferView)),r.push(this.getDependency("bufferView",n.sparse.values.bufferView))),Promise.all(r).then(function(o){const c=o[0],i=Be[n.type],l=oe[n.componentType],u=l.BYTES_PER_ELEMENT,h=u*i,f=n.byteOffset||0,m=n.bufferView!==void 0?s.bufferViews[n.bufferView].byteStride:void 0,T=n.normalized===!0;let x,g;if(m&&m!==h){const p=Math.floor(f/m),v="InterleavedBuffer:"+n.bufferView+":"+n.componentType+":"+p+":"+n.count;let b=t.cache.get(v);b||(x=new l(c,p*m,n.count*m/u),b=new d.InterleavedBuffer(x,m/u),t.cache.add(v,b)),g=new d.InterleavedBufferAttribute(b,i,f%m/u,T)}else c===null?x=new l(n.count*i):x=new l(c,f,n.count*i),g=new d.BufferAttribute(x,i,T);if(n.sparse!==void 0){const p=Be.SCALAR,v=oe[n.sparse.indices.componentType],b=n.sparse.indices.byteOffset||0,M=n.sparse.values.byteOffset||0,y=new v(o[1],b,n.sparse.count*p),C=new l(o[2],M,n.sparse.count*i);c!==null&&(g=new d.BufferAttribute(g.array.slice(),g.itemSize,g.normalized)),g.normalized=!1;for(let L=0,D=y.length;L<D;L++){const w=y[L];if(g.setX(w,C[L*i]),i>=2&&g.setY(w,C[L*i+1]),i>=3&&g.setZ(w,C[L*i+2]),i>=4&&g.setW(w,C[L*i+3]),i>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}g.normalized=T}return g})}loadTexture(e){const t=this.json,s=this.options,r=t.textures[e].source,o=t.images[r];let c=this.textureLoader;if(o.uri){const i=s.manager.getHandler(o.uri);i!==null&&(c=i)}return this.loadTextureImage(e,r,c)}loadTextureImage(e,t,s){const n=this,r=this.json,o=r.textures[e],c=r.images[t],i=(c.uri||c.bufferView)+":"+o.sampler;if(this.textureCache[i])return this.textureCache[i];const l=this.loadImageSource(t,s).then(function(u){u.flipY=!1,u.name=o.name||c.name||"",u.name===""&&typeof c.uri=="string"&&c.uri.startsWith("data:image/")===!1&&(u.name=c.uri);const f=(r.samplers||{})[o.sampler]||{};return u.magFilter=ct[f.magFilter]||d.LinearFilter,u.minFilter=ct[f.minFilter]||d.LinearMipmapLinearFilter,u.wrapS=lt[f.wrapS]||d.RepeatWrapping,u.wrapT=lt[f.wrapT]||d.RepeatWrapping,u.generateMipmaps=!u.isCompressedTexture&&u.minFilter!==d.NearestFilter&&u.minFilter!==d.LinearFilter,n.associations.set(u,{textures:e}),u}).catch(function(){return null});return this.textureCache[i]=l,l}loadImageSource(e,t){const s=this,n=this.json,r=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(h=>h.clone());const o=n.images[e],c=self.URL||self.webkitURL;let i=o.uri||"",l=!1;if(o.bufferView!==void 0)i=s.getDependency("bufferView",o.bufferView).then(function(h){l=!0;const f=new Blob([h],{type:o.mimeType});return i=c.createObjectURL(f),i});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const u=Promise.resolve(i).then(function(h){return new Promise(function(f,m){let T=f;t.isImageBitmapLoader===!0&&(T=function(x){const g=new d.Texture(x);g.needsUpdate=!0,f(g)}),t.load(d.LoaderUtils.resolveURL(h,r.path),T,void 0,m)})}).then(function(h){return l===!0&&c.revokeObjectURL(i),j(h,o),h.userData.mimeType=o.mimeType||ns(o.uri),h}).catch(function(h){throw console.error("THREE.GLTFLoader: Couldn't load texture",i),h});return this.sourceCache[e]=u,u}assignTexture(e,t,s,n){const r=this;return this.getDependency("texture",s.index).then(function(o){if(!o)return null;if(s.texCoord!==void 0&&s.texCoord>0&&(o=o.clone(),o.channel=s.texCoord),r.extensions[R.KHR_TEXTURE_TRANSFORM]){const c=s.extensions!==void 0?s.extensions[R.KHR_TEXTURE_TRANSFORM]:void 0;if(c){const i=r.associations.get(o);o=r.extensions[R.KHR_TEXTURE_TRANSFORM].extendTexture(o,c),r.associations.set(o,i)}}return n!==void 0&&(o.colorSpace=n),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let s=e.material;const n=t.attributes.tangent===void 0,r=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const c="PointsMaterial:"+s.uuid;let i=this.cache.get(c);i||(i=new d.PointsMaterial,d.Material.prototype.copy.call(i,s),i.color.copy(s.color),i.map=s.map,i.sizeAttenuation=!1,this.cache.add(c,i)),s=i}else if(e.isLine){const c="LineBasicMaterial:"+s.uuid;let i=this.cache.get(c);i||(i=new d.LineBasicMaterial,d.Material.prototype.copy.call(i,s),i.color.copy(s.color),i.map=s.map,this.cache.add(c,i)),s=i}if(n||r||o){let c="ClonedMaterial:"+s.uuid+":";n&&(c+="derivative-tangents:"),r&&(c+="vertex-colors:"),o&&(c+="flat-shading:");let i=this.cache.get(c);i||(i=s.clone(),r&&(i.vertexColors=!0),o&&(i.flatShading=!0),n&&(i.normalScale&&(i.normalScale.y*=-1),i.clearcoatNormalScale&&(i.clearcoatNormalScale.y*=-1)),this.cache.add(c,i),this.associations.set(i,this.associations.get(s))),s=i}e.material=s}getMaterialType(){return d.MeshStandardMaterial}loadMaterial(e){const t=this,s=this.json,n=this.extensions,r=s.materials[e];let o;const c={},i=r.extensions||{},l=[];if(i[R.KHR_MATERIALS_UNLIT]){const h=n[R.KHR_MATERIALS_UNLIT];o=h.getMaterialType(),l.push(h.extendParams(c,r,t))}else{const h=r.pbrMetallicRoughness||{};if(c.color=new d.Color(1,1,1),c.opacity=1,Array.isArray(h.baseColorFactor)){const f=h.baseColorFactor;c.color.setRGB(f[0],f[1],f[2],d.LinearSRGBColorSpace),c.opacity=f[3]}h.baseColorTexture!==void 0&&l.push(t.assignTexture(c,"map",h.baseColorTexture,d.SRGBColorSpace)),c.metalness=h.metallicFactor!==void 0?h.metallicFactor:1,c.roughness=h.roughnessFactor!==void 0?h.roughnessFactor:1,h.metallicRoughnessTexture!==void 0&&(l.push(t.assignTexture(c,"metalnessMap",h.metallicRoughnessTexture)),l.push(t.assignTexture(c,"roughnessMap",h.metallicRoughnessTexture))),o=this._invokeOne(function(f){return f.getMaterialType&&f.getMaterialType(e)}),l.push(Promise.all(this._invokeAll(function(f){return f.extendMaterialParams&&f.extendMaterialParams(e,c)})))}r.doubleSided===!0&&(c.side=d.DoubleSide);const u=r.alphaMode||Ue.OPAQUE;if(u===Ue.BLEND?(c.transparent=!0,c.depthWrite=!1):(c.transparent=!1,u===Ue.MASK&&(c.alphaTest=r.alphaCutoff!==void 0?r.alphaCutoff:.5)),r.normalTexture!==void 0&&o!==d.MeshBasicMaterial&&(l.push(t.assignTexture(c,"normalMap",r.normalTexture)),c.normalScale=new d.Vector2(1,1),r.normalTexture.scale!==void 0)){const h=r.normalTexture.scale;c.normalScale.set(h,h)}if(r.occlusionTexture!==void 0&&o!==d.MeshBasicMaterial&&(l.push(t.assignTexture(c,"aoMap",r.occlusionTexture)),r.occlusionTexture.strength!==void 0&&(c.aoMapIntensity=r.occlusionTexture.strength)),r.emissiveFactor!==void 0&&o!==d.MeshBasicMaterial){const h=r.emissiveFactor;c.emissive=new d.Color().setRGB(h[0],h[1],h[2],d.LinearSRGBColorSpace)}return r.emissiveTexture!==void 0&&o!==d.MeshBasicMaterial&&l.push(t.assignTexture(c,"emissiveMap",r.emissiveTexture,d.SRGBColorSpace)),Promise.all(l).then(function(){const h=new o(c);return r.name&&(h.name=r.name),j(h,r),t.associations.set(h,{materials:e}),r.extensions&&Q(n,h,r),h})}createUniqueName(e){const t=d.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,s=this.extensions,n=this.primitiveCache;function r(c){return s[R.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(c,t).then(function(i){return ut(i,c,t)})}const o=[];for(let c=0,i=e.length;c<i;c++){const l=e[c],u=ts(l),h=n[u];if(h)o.push(h.promise);else{let f;l.extensions&&l.extensions[R.KHR_DRACO_MESH_COMPRESSION]?f=r(l):f=ut(new d.BufferGeometry,l,t),n[u]={primitive:l,promise:f},o.push(f)}}return Promise.all(o)}loadMesh(e){const t=this,s=this.json,n=this.extensions,r=s.meshes[e],o=r.primitives,c=[];for(let i=0,l=o.length;i<l;i++){const u=o[i].material===void 0?$n(this.cache):this.getDependency("material",o[i].material);c.push(u)}return c.push(t.loadGeometries(o)),Promise.all(c).then(function(i){const l=i.slice(0,i.length-1),u=i[i.length-1],h=[];for(let m=0,T=u.length;m<T;m++){const x=u[m],g=o[m];let p;const v=l[m];if(g.mode===O.TRIANGLES||g.mode===O.TRIANGLE_STRIP||g.mode===O.TRIANGLE_FAN||g.mode===void 0)p=r.isSkinnedMesh===!0?new d.SkinnedMesh(x,v):new d.Mesh(x,v),p.isSkinnedMesh===!0&&p.normalizeSkinWeights(),g.mode===O.TRIANGLE_STRIP?p.geometry=at(p.geometry,d.TriangleStripDrawMode):g.mode===O.TRIANGLE_FAN&&(p.geometry=at(p.geometry,d.TriangleFanDrawMode));else if(g.mode===O.LINES)p=new d.LineSegments(x,v);else if(g.mode===O.LINE_STRIP)p=new d.Line(x,v);else if(g.mode===O.LINE_LOOP)p=new d.LineLoop(x,v);else if(g.mode===O.POINTS)p=new d.Points(x,v);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+g.mode);Object.keys(p.geometry.morphAttributes).length>0&&es(p,r),p.name=t.createUniqueName(r.name||"mesh_"+e),j(p,r),g.extensions&&Q(n,p,g),t.assignFinalMaterial(p),h.push(p)}for(let m=0,T=h.length;m<T;m++)t.associations.set(h[m],{meshes:e,primitives:m});if(h.length===1)return r.extensions&&Q(n,h[0],r),h[0];const f=new d.Group;r.extensions&&Q(n,f,r),t.associations.set(f,{meshes:e});for(let m=0,T=h.length;m<T;m++)f.add(h[m]);return f})}loadCamera(e){let t;const s=this.json.cameras[e],n=s[s.type];if(!n){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return s.type==="perspective"?t=new d.PerspectiveCamera(d.MathUtils.radToDeg(n.yfov),n.aspectRatio||1,n.znear||1,n.zfar||2e6):s.type==="orthographic"&&(t=new d.OrthographicCamera(-n.xmag,n.xmag,n.ymag,-n.ymag,n.znear,n.zfar)),s.name&&(t.name=this.createUniqueName(s.name)),j(t,s),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],s=[];for(let n=0,r=t.joints.length;n<r;n++)s.push(this._loadNodeShallow(t.joints[n]));return t.inverseBindMatrices!==void 0?s.push(this.getDependency("accessor",t.inverseBindMatrices)):s.push(null),Promise.all(s).then(function(n){const r=n.pop(),o=n,c=[],i=[];for(let l=0,u=o.length;l<u;l++){const h=o[l];if(h){c.push(h);const f=new d.Matrix4;r!==null&&f.fromArray(r.array,l*16),i.push(f)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[l])}return new d.Skeleton(c,i)})}loadAnimation(e){const t=this.json,s=this,n=t.animations[e],r=n.name?n.name:"animation_"+e,o=[],c=[],i=[],l=[],u=[];for(let h=0,f=n.channels.length;h<f;h++){const m=n.channels[h],T=n.samplers[m.sampler],x=m.target,g=x.node,p=n.parameters!==void 0?n.parameters[T.input]:T.input,v=n.parameters!==void 0?n.parameters[T.output]:T.output;x.node!==void 0&&(o.push(this.getDependency("node",g)),c.push(this.getDependency("accessor",p)),i.push(this.getDependency("accessor",v)),l.push(T),u.push(x))}return Promise.all([Promise.all(o),Promise.all(c),Promise.all(i),Promise.all(l),Promise.all(u)]).then(function(h){const f=h[0],m=h[1],T=h[2],x=h[3],g=h[4],p=[];for(let v=0,b=f.length;v<b;v++){const M=f[v],y=m[v],C=T[v],L=x[v],D=g[v];if(M===void 0)continue;M.updateMatrix&&M.updateMatrix();const w=s._createAnimationTracks(M,y,C,L,D);if(w)for(let P=0;P<w.length;P++)p.push(w[P])}return new d.AnimationClip(r,void 0,p)})}createNodeMesh(e){const t=this.json,s=this,n=t.nodes[e];return n.mesh===void 0?null:s.getDependency("mesh",n.mesh).then(function(r){const o=s._getNodeRef(s.meshCache,n.mesh,r);return n.weights!==void 0&&o.traverse(function(c){if(c.isMesh)for(let i=0,l=n.weights.length;i<l;i++)c.morphTargetInfluences[i]=n.weights[i]}),o})}loadNode(e){const t=this.json,s=this,n=t.nodes[e],r=s._loadNodeShallow(e),o=[],c=n.children||[];for(let l=0,u=c.length;l<u;l++)o.push(s.getDependency("node",c[l]));const i=n.skin===void 0?Promise.resolve(null):s.getDependency("skin",n.skin);return Promise.all([r,Promise.all(o),i]).then(function(l){const u=l[0],h=l[1],f=l[2];f!==null&&u.traverse(function(m){m.isSkinnedMesh&&m.bind(f,ss)});for(let m=0,T=h.length;m<T;m++)u.add(h[m]);return u})}_loadNodeShallow(e){const t=this.json,s=this.extensions,n=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const r=t.nodes[e],o=r.name?n.createUniqueName(r.name):"",c=[],i=n._invokeOne(function(l){return l.createNodeMesh&&l.createNodeMesh(e)});return i&&c.push(i),r.camera!==void 0&&c.push(n.getDependency("camera",r.camera).then(function(l){return n._getNodeRef(n.cameraCache,r.camera,l)})),n._invokeAll(function(l){return l.createNodeAttachment&&l.createNodeAttachment(e)}).forEach(function(l){c.push(l)}),this.nodeCache[e]=Promise.all(c).then(function(l){let u;if(r.isBone===!0?u=new d.Bone:l.length>1?u=new d.Group:l.length===1?u=l[0]:u=new d.Object3D,u!==l[0])for(let h=0,f=l.length;h<f;h++)u.add(l[h]);if(r.name&&(u.userData.name=r.name,u.name=o),j(u,r),r.extensions&&Q(s,u,r),r.matrix!==void 0){const h=new d.Matrix4;h.fromArray(r.matrix),u.applyMatrix4(h)}else r.translation!==void 0&&u.position.fromArray(r.translation),r.rotation!==void 0&&u.quaternion.fromArray(r.rotation),r.scale!==void 0&&u.scale.fromArray(r.scale);return n.associations.has(u)||n.associations.set(u,{}),n.associations.get(u).nodes=e,u}),this.nodeCache[e]}loadScene(e){const t=this.extensions,s=this.json.scenes[e],n=this,r=new d.Group;s.name&&(r.name=n.createUniqueName(s.name)),j(r,s),s.extensions&&Q(t,r,s);const o=s.nodes||[],c=[];for(let i=0,l=o.length;i<l;i++)c.push(n.getDependency("node",o[i]));return Promise.all(c).then(function(i){for(let u=0,h=i.length;u<h;u++)r.add(i[u]);const l=u=>{const h=new Map;for(const[f,m]of n.associations)(f instanceof d.Material||f instanceof d.Texture)&&h.set(f,m);return u.traverse(f=>{const m=n.associations.get(f);m!=null&&h.set(f,m)}),h};return n.associations=l(r),r})}_createAnimationTracks(e,t,s,n,r){const o=[],c=e.name?e.name:e.uuid,i=[];z[r.path]===z.weights?e.traverse(function(f){f.morphTargetInfluences&&i.push(f.name?f.name:f.uuid)}):i.push(c);let l;switch(z[r.path]){case z.weights:l=d.NumberKeyframeTrack;break;case z.rotation:l=d.QuaternionKeyframeTrack;break;case z.position:case z.scale:l=d.VectorKeyframeTrack;break;default:switch(s.itemSize){case 1:l=d.NumberKeyframeTrack;break;case 2:case 3:default:l=d.VectorKeyframeTrack;break}break}const u=n.interpolation!==void 0?Qn[n.interpolation]:d.InterpolateLinear,h=this._getArrayFromAccessor(s);for(let f=0,m=i.length;f<m;f++){const T=new l(i[f]+"."+z[r.path],t.array,h,u);n.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(T),o.push(T)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const s=Ve(t.constructor),n=new Float32Array(t.length);for(let r=0,o=t.length;r<o;r++)n[r]=t[r]*s;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(s){const n=this instanceof d.QuaternionKeyframeTrack?Zn:Et;return new n(this.times,this.values,this.getValueSize()/3,s)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function os(a,e,t){const s=e.attributes,n=new d.Box3;if(s.POSITION!==void 0){const c=t.json.accessors[s.POSITION],i=c.min,l=c.max;if(i!==void 0&&l!==void 0){if(n.set(new d.Vector3(i[0],i[1],i[2]),new d.Vector3(l[0],l[1],l[2])),c.normalized){const u=Ve(oe[c.componentType]);n.min.multiplyScalar(u),n.max.multiplyScalar(u)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const r=e.targets;if(r!==void 0){const c=new d.Vector3,i=new d.Vector3;for(let l=0,u=r.length;l<u;l++){const h=r[l];if(h.POSITION!==void 0){const f=t.json.accessors[h.POSITION],m=f.min,T=f.max;if(m!==void 0&&T!==void 0){if(i.setX(Math.max(Math.abs(m[0]),Math.abs(T[0]))),i.setY(Math.max(Math.abs(m[1]),Math.abs(T[1]))),i.setZ(Math.max(Math.abs(m[2]),Math.abs(T[2]))),f.normalized){const x=Ve(oe[f.componentType]);i.multiplyScalar(x)}c.max(i)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}n.expandByVector(c)}a.boundingBox=n;const o=new d.Sphere;n.getCenter(o.center),o.radius=n.min.distanceTo(n.max)/2,a.boundingSphere=o}function ut(a,e,t){const s=e.attributes,n=[];function r(o,c){return t.getDependency("accessor",o).then(function(i){a.setAttribute(c,i)})}for(const o in s){const c=Ye[o]||o.toLowerCase();c in a.attributes||n.push(r(s[o],c))}if(e.indices!==void 0&&!a.index){const o=t.getDependency("accessor",e.indices).then(function(c){a.setIndex(c)});n.push(o)}return d.ColorManagement.workingColorSpace!==d.LinearSRGBColorSpace&&"COLOR_0"in s&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${d.ColorManagement.workingColorSpace}" not supported.`),j(a,e),os(a,e,t),Promise.all(n).then(function(){return e.targets!==void 0?Jn(a,e.targets,t):a})}const pe=[0,0,-10],q=[.5,.5,.5],Ze=1,Ge=new Map,as=a=>{const e=Ge.get(a);if(e)return e;const t=new Sn,s=$.fetchAndVerify(a).then(n=>new Promise((r,o)=>{t.parse(n,"",r,o)})).catch(n=>{throw Ge.delete(a),n});return Ge.set(a,s),s},Qe=({position:a,rotation:e,scale:t,url:s,showDebugMaterial:n=!1,opacity:r=Ze})=>{const o=s??new URL("/assets/xr/3d-models/head-occluder-v2.glb",$.libConfig.assetStorageEndpoint).toString(),[c,i]=S.useState(null);S.useEffect(()=>{let u=!1;return as(o).then(h=>{u||i(h.scene)}).catch(h=>{u||console.error(`${$.libConfig.loggerPrefix} head occluder load failed`,h)}),()=>{u=!0}},[o]);const l=S.useMemo(()=>{if(!c)return null;const u=c.clone();return u.traverse(h=>{h instanceof E.Mesh&&(h.material=new E.MeshStandardMaterial({color:15132390,colorWrite:n,depthWrite:!0,opacity:n?r:1,side:E.DoubleSide,transparent:n}))}),u},[c,n,r]);return S.useEffect(()=>{if(l)return()=>{l.traverse(u=>{u instanceof E.Mesh&&u.material.dispose()})}},[l]),l?(a?l.position.set(a[0],a[1],a[2]):l.position.set(pe[0],pe[1],pe[2]),e&&l.rotation.set(e[0],e[1],e[2]),t?l.scale.set(t[0],t[1],t[2]):l.scale.set(q[0],q[1],q[2]),l.renderOrder=-1,A.jsx("primitive",{object:l})):null},is=4,cs=({children:a,faceIndex:e=0,numFaces:t=is,scaleWithFace:s=!0,occluder:n=!0,showFaceMesh:r=!1,faceMeshMaterial:o})=>{const c=S.useMemo(()=>new E.MeshBasicMaterial({color:"#22c55e",side:E.BackSide,transparent:!0,opacity:.35,depthWrite:!1}),[]),i=n===!1?null:n===!0?{}:n;return A.jsxs(Xe.FaceTracker,{faceIndex:e,numFaces:t,scaleWithFace:s,children:[i&&A.jsx(Qe,{position:i.position??pe,rotation:i.rotation,scale:i.scale??q,url:i.url,showDebugMaterial:i.showDebugMaterial,opacity:i.opacity??Ze}),a,r&&A.jsx(Xe.FaceMesh,{faceIndex:e,numFaces:t,material:o??c})]})},ls=57,us=15.5,He=ls/Math.PI/us,hs=-.134,ds=-.024,X=(a,e,t)=>Math.min(t,Math.max(e,a)),St=(a,e)=>a*e-e/2,wt=(a,e)=>-(a*e-e/2),fs=({eyeMidX:a,noseX:e,offsetX:t,rawYaw:s,sideMidX:n})=>{const r=X((Math.abs(s)-.18)/.42,0,1),o=n*.75+a*.25,c=a*.7+e*.3;return o*(1-r)+c*r+t},ps=({baseScale:a,pitchRadians:e})=>{const t=e*180/Math.PI,n=1+X((t-6)/22,0,1)*.22;return[a[0]*n,a[1]*n,a[2]*n]},ms=({yawRadians:a})=>{const e=Math.abs(a*180/Math.PI),s=.066*X((e-8)/12,0,1);return Math.sign(a)*s},gs=({pitchRadians:a})=>{const e=a*180/Math.PI;return-.026*X((-e-6)/18,0,1)},As=({baseOffset:a,yawRadians:e})=>{const t=Math.abs(e*180/Math.PI),s=X((t-8)/24,0,1);return a+s*.25},Ts=({baseOffsetY:a,baseScaleY:e,face:t})=>{if(!t||t.bounds.width<=0)return{aspectRatio:0,normalizedAspect:0,scaleY:e,offsetY:a};const s=t.bounds.height/t.bounds.width,n=X((s-1.55)/.35,-1,1);return{aspectRatio:s,normalizedAspect:n,scaleY:e+n*.06,offsetY:a+n*.005}},_t=({face:a,offsetX:e,offsetY:t,scaleX:s,scaleY:n})=>{const r=a.bounds.width*s,o=a.bounds.height*n,c=a.bounds.centerX+e,i=a.bounds.centerY+t;return{x:c-r*.5,y:i-o*.5,width:r,height:o,centerX:c,centerY:i}},xs=({face:a,height:e,lockDepth:t,lockRotation:s,model:n,offsetX:r,offsetY:o,scaleX:c,scaleY:i,scaleZ:l,width:u})=>{const h=_t({face:a,offsetX:r,offsetY:o,scaleX:c,scaleY:i}),f=a.landmarks[33],m=a.landmarks[263],T=a.landmarks[234],x=a.landmarks[454],g=a.landmarks[1],p=a.landmarks[10],v=a.landmarks[152],b=h.width*u,M=h.height*e,y=f&&m?(f.x+m.x)*.5:a.bounds.centerX,C=f&&m?(f.y+m.y)*.5:a.bounds.centerY-a.bounds.height*.15,L=T&&x?(T.x+x.x)*.5:y,D=(p==null?void 0:p.y)??a.bounds.minY,w=(v==null?void 0:v.y)??a.bounds.maxY,P=(D+w)*.5,J=f&&m?Math.atan2(m.y-f.y,m.x-f.x):0,I=g&&a.bounds.width>0?X((g.x-a.bounds.centerX)/(a.bounds.width*.5),-1,1)*.75:0,K=fs({eyeMidX:y,noseX:(g==null?void 0:g.x)??y,offsetX:r,rawYaw:I,sideMidX:L}),_=P*.75+C*.25+o,ee=n==="v2"?St(K,u):h.centerX*u-u/2,Y=n==="v2"?wt(a.bounds.centerY+o*.75,e):-(h.centerY*e-e/2),V=p&&g?Math.max(1e-4,g.y-p.y):a.bounds.height*.42,ae=g&&v?Math.max(1e-4,v.y-g.y):a.bounds.height*.58,ie=(ae-V)/(ae+V),ce=X((ie-hs)/.28,-1,1)*.58,le=g&&a.bounds.height>0?X((a.bounds.centerY-g.y)/(a.bounds.height*.5)-ds,-1,1)*.18:0,te=ce*.82+le*.18,ne=s?0:n==="v2"?I*.72:I,ue=s?0:n==="v2"?-te*.78:-te,he=s?0:-J,me=t?b*He:n==="v2"?b*(He+Math.abs(ne)*.18):b*He;return{centerXPx:ee,centerYPx:Y,depthPx:me*l,heightPx:M,pitch:ue,rawPitch:te,rawPitchFromBalance:ce,rawPitchFromCenter:le,rawYaw:I,rotationZ:he,roll:J,shape:h,skullAnchorX:K,skullAnchorY:_,verticalBalance:ie,widthPx:b,yaw:ne}},yt=({lockDepth:a,lockRotation:e,model:t,face:s,height:n,headDepthOffset:r,offsetX:o,offsetY:c,rotationOffsetX:i,rotationOffsetY:l,rotationOffsetZ:u,scaleX:h,scaleY:f,scaleZ:m,skullCenterMode:T,skullVerticalBias:x,width:g})=>$e({lockDepth:a,lockRotation:e,model:t,face:s,height:n,headDepthOffset:r,offsetX:o,offsetY:c,rotationOffsetX:i,rotationOffsetY:l,rotationOffsetZ:u,scaleX:h,scaleY:f,scaleZ:m,skullCenterMode:T,skullVerticalBias:x,width:g}).pose,$e=({lockDepth:a,lockRotation:e,model:t,face:s,height:n,headDepthOffset:r,offsetX:o,offsetY:c,rotationOffsetX:i,rotationOffsetY:l,rotationOffsetZ:u,scaleX:h,scaleY:f,scaleZ:m,skullCenterMode:T,skullVerticalBias:x,width:g})=>{const p=xs({face:s,height:n,lockDepth:a,lockRotation:e,model:t,offsetX:o,offsetY:c,scaleX:h,scaleY:f,scaleZ:m,width:g});if(T){const b=new d.Vector3(0,p.heightPx*x,-p.depthPx*r).applyEuler(new d.Euler(p.pitch,p.yaw,p.rotationZ,"XYZ")),M=St(p.skullAnchorX,g),y=wt(p.skullAnchorY,n);return{pose:{boxCenterZ:b.z,centerX:M+b.x,centerY:y+b.y,width:p.widthPx,height:p.heightPx,depth:p.depthPx,rotationX:p.pitch+i,rotationY:p.yaw+l,rotationZ:p.rotationZ+u},debugMetrics:{face:{centerX:p.shape.centerX,centerY:p.shape.centerY,width:p.shape.width,height:p.shape.height},normalized:{rawPitch:p.rawPitch,rawPitchFromBalance:p.rawPitchFromBalance,rawPitchFromCenter:p.rawPitchFromCenter,rawYaw:p.rawYaw,roll:p.roll,verticalBalance:p.verticalBalance},pose:{pitch:p.pitch,yaw:p.yaw,rotationX:p.pitch+i,rotationY:p.yaw+l,rotationZ:p.rotationZ+u},skullAnchor:{x:p.skullAnchorX,y:p.skullAnchorY},center:{x:M+b.x,y:y+b.y,z:b.z},depthPx:p.depthPx,screen:{widthPx:p.widthPx,heightPx:p.heightPx}}}}return{pose:{boxCenterZ:-p.depthPx*r,centerX:p.centerXPx,centerY:p.centerYPx,width:p.widthPx,height:p.heightPx,depth:p.depthPx,rotationX:p.pitch+i,rotationY:p.yaw+l,rotationZ:p.rotationZ+u},debugMetrics:{face:{centerX:p.shape.centerX,centerY:p.shape.centerY,width:p.shape.width,height:p.shape.height},normalized:{rawPitch:p.rawPitch,rawPitchFromBalance:p.rawPitchFromBalance,rawPitchFromCenter:p.rawPitchFromCenter,rawYaw:p.rawYaw,roll:p.roll,verticalBalance:p.verticalBalance},pose:{pitch:p.pitch,yaw:p.yaw,rotationX:p.pitch+i,rotationY:p.yaw+l,rotationZ:p.rotationZ+u},skullAnchor:{x:p.skullAnchorX,y:p.skullAnchorY},center:{x:p.centerXPx,y:p.centerYPx,z:-p.depthPx*r},depthPx:p.depthPx,screen:{widthPx:p.widthPx,heightPx:p.heightPx}}}},vs=({lockDepth:a,lockRotation:e,model:t,face:s,height:n,headDepthOffset:r,offsetX:o,offsetY:c,rotationOffsetX:i,rotationOffsetY:l,rotationOffsetZ:u,scaleX:h,scaleY:f,scaleZ:m,skullCenterMode:T,skullVerticalBias:x,width:g})=>$e({lockDepth:a,lockRotation:e,model:t,face:s,height:n,headDepthOffset:r,offsetX:o,offsetY:c,rotationOffsetX:i,rotationOffsetY:l,rotationOffsetZ:u,scaleX:h,scaleY:f,scaleZ:m,skullCenterMode:T,skullVerticalBias:x,width:g}).debugMetrics,bs=({boxColor:a,boxOpacity:e,face:t,headDepthOffset:s,lockDepth:n,lockRotation:r,model:o,occluderOffset:c,occluderOpacity:i,occluderScale:l,showOccluderProxy:u=!1,offsetX:h,offsetY:f,pose:m,rotationOffsetX:T,rotationOffsetY:x,rotationOffsetZ:g,scaleX:p,scaleY:v,scaleZ:b,show:M,showCenterDot:y,showFacePlaneReference:C,showGizmo:L,showHeadOccluder:D,skullCenterMode:w,skullVerticalBias:P,url:J,viewportHeight:I,viewportWidth:K})=>{const _=S.useMemo(()=>m||(!t||K<=0||I<=0?null:yt({face:t,width:K,height:I,headDepthOffset:s,lockDepth:n,lockRotation:r,model:o,offsetX:h,offsetY:f,rotationOffsetX:T,rotationOffsetY:x,rotationOffsetZ:g,scaleX:p,scaleY:v,scaleZ:b,skullCenterMode:w,skullVerticalBias:P})),[t,s,n,r,o,h,f,T,x,g,p,v,b,w,P,m,I,K]);if(!M||!_)return null;const ee=w?[0,-_.height*P,_.depth*s]:[0,0,0],Y=_.height,V=[q[0]*l[0]*Y,q[1]*l[1]*Y,q[2]*l[2]*Y];return A.jsxs(A.Fragment,{children:[A.jsxs("group",{position:[_.centerX,_.centerY,_.boxCenterZ],rotation:[_.rotationX,_.rotationY,_.rotationZ],children:[A.jsx("group",{scale:[_.width,_.height,_.depth],children:e>0&&A.jsxs("mesh",{children:[A.jsx("boxGeometry",{args:[1,1,1]}),A.jsx("meshBasicMaterial",{color:a,wireframe:!0,transparent:!0,opacity:e})]})}),y&&A.jsxs("mesh",{children:[A.jsx("sphereGeometry",{args:[6,20,20]}),A.jsx("meshBasicMaterial",{color:a})]}),C&&A.jsxs("group",{position:ee,children:[A.jsxs("mesh",{rotation:[0,0,Math.PI/4],children:[A.jsx("ringGeometry",{args:[6,8,24]}),A.jsx("meshBasicMaterial",{color:"#f8fafc",side:d.DoubleSide})]}),A.jsxs("mesh",{rotation:[0,0,Math.PI/2],children:[A.jsx("planeGeometry",{args:[3,16]}),A.jsx("meshBasicMaterial",{color:"#f8fafc",transparent:!0,opacity:.9,side:d.DoubleSide})]}),A.jsxs("mesh",{children:[A.jsx("planeGeometry",{args:[16,3]}),A.jsx("meshBasicMaterial",{color:"#f8fafc",transparent:!0,opacity:.9,side:d.DoubleSide})]})]}),D&&A.jsxs(A.Fragment,{children:[u&&A.jsxs("mesh",{position:c,scale:V,renderOrder:20,children:[A.jsx("sphereGeometry",{args:[1,24,16]}),A.jsx("meshBasicMaterial",{color:"#facc15",wireframe:!0,transparent:!0,opacity:.95,depthTest:!1,depthWrite:!1})]}),A.jsx(Qe,{opacity:i,position:c,scale:V,showDebugMaterial:!0,url:J})]})]}),L&&A.jsx("group",{position:[_.centerX,_.centerY,_.boxCenterZ],rotation:[_.rotationX,_.rotationY,_.rotationZ],renderOrder:10,children:A.jsxs("group",{children:[A.jsxs("mesh",{children:[A.jsx("sphereGeometry",{args:[6,20,20]}),A.jsx("meshBasicMaterial",{color:"#e2e8f0",depthTest:!1,depthWrite:!1})]}),A.jsxs("mesh",{position:[18,0,0],rotation:[0,0,-Math.PI/2],children:[A.jsx("cylinderGeometry",{args:[1.6,1.6,24,12]}),A.jsx("meshBasicMaterial",{color:"#ef4444",depthTest:!1,depthWrite:!1})]}),A.jsxs("mesh",{position:[34,0,0],rotation:[0,0,-Math.PI/2],children:[A.jsx("coneGeometry",{args:[4.2,12,16]}),A.jsx("meshBasicMaterial",{color:"#ef4444",depthTest:!1,depthWrite:!1})]}),A.jsxs("mesh",{position:[0,18,0],children:[A.jsx("cylinderGeometry",{args:[1.6,1.6,24,12]}),A.jsx("meshBasicMaterial",{color:"#22c55e",depthTest:!1,depthWrite:!1})]}),A.jsxs("mesh",{position:[0,34,0],children:[A.jsx("coneGeometry",{args:[4.2,12,16]}),A.jsx("meshBasicMaterial",{color:"#22c55e",depthTest:!1,depthWrite:!1})]}),A.jsxs("mesh",{position:[0,0,18],rotation:[Math.PI/2,0,0],children:[A.jsx("cylinderGeometry",{args:[1.6,1.6,24,12]}),A.jsx("meshBasicMaterial",{color:"#3b82f6",depthTest:!1,depthWrite:!1})]}),A.jsxs("mesh",{position:[0,0,34],rotation:[Math.PI/2,0,0],children:[A.jsx("coneGeometry",{args:[4.2,12,16]}),A.jsx("meshBasicMaterial",{color:"#3b82f6",depthTest:!1,depthWrite:!1})]}),A.jsx(Fe.Text,{position:[42,0,0],fontSize:10,color:"#ef4444",anchorX:"center",anchorY:"middle",renderOrder:11,"material-depthTest":!1,children:"X"}),A.jsx(Fe.Text,{position:[0,42,0],fontSize:10,color:"#22c55e",anchorX:"center",anchorY:"middle",renderOrder:11,"material-depthTest":!1,children:"Y"}),A.jsx(Fe.Text,{position:[0,0,42],fontSize:10,color:"#3b82f6",anchorX:"center",anchorY:"middle",renderOrder:11,"material-depthTest":!1,children:"Z"})]})})]})};exports.CanonicalFaceMeshRenderer=Yt;exports.DEFAULT_APPEARANCE=Vt;exports.DEFAULT_FEATURE_GROUPS=vt;exports.DEFAULT_FEATURE_POINT_INDICES=bt;exports.DEFAULT_MASKING=Wt;exports.FACE_MASK_SIZE=Ee;exports.FACE_OVAL=We;exports.FaceRetouchBackground=rn;exports.HEAD_OCCLUDER_DEFAULT_OPACITY=Ze;exports.HEAD_OCCLUDER_DEFAULT_POSITION=pe;exports.HEAD_OCCLUDER_DEFAULT_SCALE=q;exports.HeadBinding=cs;exports.HeadBindingOccluder=bs;exports.HeadOccluder=Qe;exports.INNER_MOUTH=ze;exports.LEFT_EYE=ft;exports.LEFT_EYEBROW=gt;exports.OUTER_LIPS=mt;exports.RIGHT_EYE=pt;exports.RIGHT_EYEBROW=At;exports.alphaMapOptions=$t;exports.blendModeIndices=Ke;exports.blendModeOptions=Jt;exports.computeAdaptiveVerticalFit=Ts;exports.computeHeadBindingCubePose=yt;exports.computeHeadBindingDebugMetrics=vs;exports.computeHeadBindingShape=_t;exports.computeUniversalHeadDepthOffset=As;exports.computeUniversalOccluderScale=ps;exports.computeUniversalPitchOffsetY=gs;exports.computeUniversalYawOffsetX=ms;exports.createFaceRetouchRegions=Mt;exports.drawFaceRetouchMask=Tt;exports.drawMouthRetouchMask=xt;exports.materialTypeOptions=zt;exports.parseCanonicalFaceModel=ht;exports.shaderPresetOptions=qt;exports.sideOptions=Zt;exports.solveHeadBinding=$e;exports.supportsBlendMode=tn;exports.supportsTexturePanel=en;exports.textureMapOptions=Qt;exports.useCanonicalFaceMesh=dt;exports.useFaceRetouchMask=Mn;exports.useFaceRetouchRegions=En;
|