@sage-rsc/talking-head-react 1.0.26 → 1.0.28
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/dist/{fbxAnimationLoader-DYwX3TQf.cjs → fbxAnimationLoader-BAdAJQ7P.cjs} +1 -1
- package/dist/{fbxAnimationLoader-BEp5N4LW.js → fbxAnimationLoader-xd44uqKF.js} +1 -1
- package/dist/index-Dx7mDKJm.cjs +13 -0
- package/dist/{index-R68Q6EcC.js → index-zMY6cyU2.js} +1407 -1377
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/components/CurriculumLearning.jsx +92 -13
- package/dist/index-BAyfuKmk.cjs +0 -13
package/dist/index-BAyfuKmk.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";const de=require("react/jsx-runtime"),E=require("react"),p=require("three");var We=typeof document<"u"?document.currentScript:null;function Dt(m){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(m){for(const t in m)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(m,t);Object.defineProperty(e,t,n.get?n:{enumerable:!0,get:()=>m[t]})}}return e.default=m,Object.freeze(e)}const v=Dt(p),lt={type:"change"},st={type:"start"},Rt={type:"end"},Fe=new p.Ray,ct=new p.Plane,Ot=Math.cos(70*p.MathUtils.DEG2RAD),K=new p.Vector3,te=2*Math.PI,B={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},Xe=1e-6;class _t extends p.Controls{constructor(e,t=null){super(e,t),this.state=B.NONE,this.target=new p.Vector3,this.cursor=new p.Vector3,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:"ArrowLeft",UP:"ArrowUp",RIGHT:"ArrowRight",BOTTOM:"ArrowDown"},this.mouseButtons={LEFT:p.MOUSE.ROTATE,MIDDLE:p.MOUSE.DOLLY,RIGHT:p.MOUSE.PAN},this.touches={ONE:p.TOUCH.ROTATE,TWO:p.TOUCH.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._domElementKeyEvents=null,this._lastPosition=new p.Vector3,this._lastQuaternion=new p.Quaternion,this._lastTargetPosition=new p.Vector3,this._quat=new p.Quaternion().setFromUnitVectors(e.up,new p.Vector3(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new p.Spherical,this._sphericalDelta=new p.Spherical,this._scale=1,this._panOffset=new p.Vector3,this._rotateStart=new p.Vector2,this._rotateEnd=new p.Vector2,this._rotateDelta=new p.Vector2,this._panStart=new p.Vector2,this._panEnd=new p.Vector2,this._panDelta=new p.Vector2,this._dollyStart=new p.Vector2,this._dollyEnd=new p.Vector2,this._dollyDelta=new p.Vector2,this._dollyDirection=new p.Vector3,this._mouse=new p.Vector2,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=Bt.bind(this),this._onPointerDown=Nt.bind(this),this._onPointerUp=Ut.bind(this),this._onContextMenu=Yt.bind(this),this._onMouseWheel=Wt.bind(this),this._onKeyDown=Xt.bind(this),this._onTouchStart=jt.bind(this),this._onTouchMove=Zt.bind(this),this._onMouseDown=Gt.bind(this),this._onMouseMove=Vt.bind(this),this._interceptControlDown=Kt.bind(this),this._interceptControlUp=Qt.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}connect(e){super.connect(e),this.domElement.addEventListener("pointerdown",this._onPointerDown),this.domElement.addEventListener("pointercancel",this._onPointerUp),this.domElement.addEventListener("contextmenu",this._onContextMenu),this.domElement.addEventListener("wheel",this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener("keydown",this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction="none"}disconnect(){this.domElement.removeEventListener("pointerdown",this._onPointerDown),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.domElement.removeEventListener("pointercancel",this._onPointerUp),this.domElement.removeEventListener("wheel",this._onMouseWheel),this.domElement.removeEventListener("contextmenu",this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener("keydown",this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction="auto"}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener("keydown",this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(lt),this.update(),this.state=B.NONE}update(e=null){const t=this.object.position;K.copy(t).sub(this.target),K.applyQuaternion(this._quat),this._spherical.setFromVector3(K),this.autoRotate&&this.state===B.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,i=this.maxAzimuthAngle;isFinite(n)&&isFinite(i)&&(n<-Math.PI?n+=te:n>Math.PI&&(n-=te),i<-Math.PI?i+=te:i>Math.PI&&(i-=te),n<=i?this._spherical.theta=Math.max(n,Math.min(i,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+i)/2?Math.max(n,this._spherical.theta):Math.min(i,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let s=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{const o=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),s=o!=this._spherical.radius}if(K.setFromSpherical(this._spherical),K.applyQuaternion(this._quatInverse),t.copy(this.target).add(K),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let o=null;if(this.object.isPerspectiveCamera){const a=K.length();o=this._clampDistance(a*this._scale);const l=a-o;this.object.position.addScaledVector(this._dollyDirection,l),this.object.updateMatrixWorld(),s=!!l}else if(this.object.isOrthographicCamera){const a=new p.Vector3(this._mouse.x,this._mouse.y,0);a.unproject(this.object);const l=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),s=l!==this.object.zoom;const r=new p.Vector3(this._mouse.x,this._mouse.y,0);r.unproject(this.object),this.object.position.sub(r).add(a),this.object.updateMatrixWorld(),o=K.length()}else console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."),this.zoomToCursor=!1;o!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(o).add(this.object.position):(Fe.origin.copy(this.object.position),Fe.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(Fe.direction))<Ot?this.object.lookAt(this.target):(ct.setFromNormalAndCoplanarPoint(this.object.up,this.target),Fe.intersectPlane(ct,this.target))))}else if(this.object.isOrthographicCamera){const o=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),o!==this.object.zoom&&(this.object.updateProjectionMatrix(),s=!0)}return this._scale=1,this._performCursorZoom=!1,s||this._lastPosition.distanceToSquared(this.object.position)>Xe||8*(1-this._lastQuaternion.dot(this.object.quaternion))>Xe||this._lastTargetPosition.distanceToSquared(this.target)>Xe?(this.dispatchEvent(lt),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e!==null?te/60*this.autoRotateSpeed*e:te/60/60*this.autoRotateSpeed}_getZoomScale(e){const t=Math.abs(e*.01);return Math.pow(.95,this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){K.setFromMatrixColumn(t,0),K.multiplyScalar(-e),this._panOffset.add(K)}_panUp(e,t){this.screenSpacePanning===!0?K.setFromMatrixColumn(t,1):(K.setFromMatrixColumn(t,0),K.crossVectors(this.object.up,K)),K.multiplyScalar(e),this._panOffset.add(K)}_pan(e,t){const n=this.domElement;if(this.object.isPerspectiveCamera){const i=this.object.position;K.copy(i).sub(this.target);let s=K.length();s*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*s/n.clientHeight,this.object.matrix),this._panUp(2*t*s/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;const n=this.domElement.getBoundingClientRect(),i=e-n.left,s=t-n.top,o=n.width,a=n.height;this._mouse.x=i/o*2-1,this._mouse.y=-(s/a)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(te*this._rotateDelta.x/t.clientHeight),this._rotateUp(te*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(te*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-te*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(te*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-te*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._rotateStart.set(n,i)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panStart.set(n,i)}}_handleTouchStartDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,i=e.pageY-t.y,s=Math.sqrt(n*n+i*i);this._dollyStart.set(0,s)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{const n=this._getSecondPointerPosition(e),i=.5*(e.pageX+n.x),s=.5*(e.pageY+n.y);this._rotateEnd.set(i,s)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);const t=this.domElement;this._rotateLeft(te*this._rotateDelta.x/t.clientHeight),this._rotateUp(te*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{const t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),i=.5*(e.pageY+t.y);this._panEnd.set(n,i)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){const t=this._getSecondPointerPosition(e),n=e.pageX-t.x,i=e.pageY-t.y,s=Math.sqrt(n*n+i*i);this._dollyEnd.set(0,s),this._dollyDelta.set(0,Math.pow(this._dollyEnd.y/this._dollyStart.y,this.zoomSpeed)),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);const o=(e.pageX+t.x)*.5,a=(e.pageY+t.y)*.5;this._updateZoomParameters(o,a)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new p.Vector2,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){const t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){const t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}}function Nt(m){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(m.pointerId),this.domElement.addEventListener("pointermove",this._onPointerMove),this.domElement.addEventListener("pointerup",this._onPointerUp)),!this._isTrackingPointer(m)&&(this._addPointer(m),m.pointerType==="touch"?this._onTouchStart(m):this._onMouseDown(m)))}function Bt(m){this.enabled!==!1&&(m.pointerType==="touch"?this._onTouchMove(m):this._onMouseMove(m))}function Ut(m){switch(this._removePointer(m),this._pointers.length){case 0:this.domElement.releasePointerCapture(m.pointerId),this.domElement.removeEventListener("pointermove",this._onPointerMove),this.domElement.removeEventListener("pointerup",this._onPointerUp),this.dispatchEvent(Rt),this.state=B.NONE;break;case 1:const e=this._pointers[0],t=this._pointerPositions[e];this._onTouchStart({pointerId:e,pageX:t.x,pageY:t.y});break}}function Gt(m){let e;switch(m.button){case 0:e=this.mouseButtons.LEFT;break;case 1:e=this.mouseButtons.MIDDLE;break;case 2:e=this.mouseButtons.RIGHT;break;default:e=-1}switch(e){case p.MOUSE.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(m),this.state=B.DOLLY;break;case p.MOUSE.ROTATE:if(m.ctrlKey||m.metaKey||m.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(m),this.state=B.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(m),this.state=B.ROTATE}break;case p.MOUSE.PAN:if(m.ctrlKey||m.metaKey||m.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(m),this.state=B.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(m),this.state=B.PAN}break;default:this.state=B.NONE}this.state!==B.NONE&&this.dispatchEvent(st)}function Vt(m){switch(this.state){case B.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(m);break;case B.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(m);break;case B.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(m);break}}function Wt(m){this.enabled===!1||this.enableZoom===!1||this.state!==B.NONE||(m.preventDefault(),this.dispatchEvent(st),this._handleMouseWheel(this._customWheelEvent(m)),this.dispatchEvent(Rt))}function Xt(m){this.enabled!==!1&&this._handleKeyDown(m)}function jt(m){switch(this._trackPointer(m),this._pointers.length){case 1:switch(this.touches.ONE){case p.TOUCH.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(m),this.state=B.TOUCH_ROTATE;break;case p.TOUCH.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(m),this.state=B.TOUCH_PAN;break;default:this.state=B.NONE}break;case 2:switch(this.touches.TWO){case p.TOUCH.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(m),this.state=B.TOUCH_DOLLY_PAN;break;case p.TOUCH.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(m),this.state=B.TOUCH_DOLLY_ROTATE;break;default:this.state=B.NONE}break;default:this.state=B.NONE}this.state!==B.NONE&&this.dispatchEvent(st)}function Zt(m){switch(this._trackPointer(m),this.state){case B.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(m),this.update();break;case B.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(m),this.update();break;case B.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(m),this.update();break;case B.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(m),this.update();break;default:this.state=B.NONE}}function Yt(m){this.enabled!==!1&&m.preventDefault()}function Kt(m){m.key==="Control"&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function Qt(m){m.key==="Control"&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener("keyup",this._interceptControlUp,{passive:!0,capture:!0}))}function ht(m,e){if(e===p.TrianglesDrawMode)return console.warn("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles."),m;if(e===p.TriangleFanDrawMode||e===p.TriangleStripDrawMode){let t=m.getIndex();if(t===null){const o=[],a=m.getAttribute("position");if(a!==void 0){for(let l=0;l<a.count;l++)o.push(l);m.setIndex(o),t=m.getIndex()}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible."),m}const n=t.count-2,i=[];if(e===p.TriangleFanDrawMode)for(let o=1;o<=n;o++)i.push(t.getX(0)),i.push(t.getX(o)),i.push(t.getX(o+1));else for(let o=0;o<n;o++)o%2===0?(i.push(t.getX(o)),i.push(t.getX(o+1)),i.push(t.getX(o+2))):(i.push(t.getX(o+2)),i.push(t.getX(o+1)),i.push(t.getX(o)));i.length/3!==n&&console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.");const s=m.clone();return s.setIndex(i),s.clearGroups(),s}else return console.error("THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:",e),m}class qt extends p.Loader{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(t){return new nn(t)}),this.register(function(t){return new sn(t)}),this.register(function(t){return new pn(t)}),this.register(function(t){return new mn(t)}),this.register(function(t){return new fn(t)}),this.register(function(t){return new an(t)}),this.register(function(t){return new rn(t)}),this.register(function(t){return new ln(t)}),this.register(function(t){return new cn(t)}),this.register(function(t){return new tn(t)}),this.register(function(t){return new hn(t)}),this.register(function(t){return new on(t)}),this.register(function(t){return new dn(t)}),this.register(function(t){return new un(t)}),this.register(function(t){return new $t(t)}),this.register(function(t){return new gn(t)}),this.register(function(t){return new yn(t)})}load(e,t,n,i){const s=this;let o;if(this.resourcePath!=="")o=this.resourcePath;else if(this.path!==""){const r=p.LoaderUtils.extractUrlBase(e);o=p.LoaderUtils.resolveURL(r,this.path)}else o=p.LoaderUtils.extractUrlBase(e);this.manager.itemStart(e);const a=function(r){i?i(r):console.error(r),s.manager.itemError(e),s.manager.itemEnd(e)},l=new p.FileLoader(this.manager);l.setPath(this.path),l.setResponseType("arraybuffer"),l.setRequestHeader(this.requestHeader),l.setWithCredentials(this.withCredentials),l.load(e,function(r){try{s.parse(r,o,function(h){t(h),s.manager.itemEnd(e)},a)}catch(h){a(h)}},n,a)}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,n,i){let s;const o={},a={},l=new TextDecoder;if(typeof e=="string")s=JSON.parse(e);else if(e instanceof ArrayBuffer)if(l.decode(new Uint8Array(e,0,4))===vt){try{o[D.KHR_BINARY_GLTF]=new xn(e)}catch(c){i&&i(c);return}s=JSON.parse(o[D.KHR_BINARY_GLTF].content)}else s=JSON.parse(l.decode(e));else s=e;if(s.asset===void 0||s.asset.version[0]<2){i&&i(new Error("THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported."));return}const r=new Mn(s,{path:t||this.resourcePath||"",crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});r.fileLoader.setRequestHeader(this.requestHeader);for(let h=0;h<this.pluginCallbacks.length;h++){const c=this.pluginCallbacks[h](r);c.name||console.error("THREE.GLTFLoader: Invalid plugin found: missing name"),a[c.name]=c,o[c.name]=!0}if(s.extensionsUsed)for(let h=0;h<s.extensionsUsed.length;++h){const c=s.extensionsUsed[h],u=s.extensionsRequired||[];switch(c){case D.KHR_MATERIALS_UNLIT:o[c]=new en;break;case D.KHR_DRACO_MESH_COMPRESSION:o[c]=new bn(s,this.dracoLoader);break;case D.KHR_TEXTURE_TRANSFORM:o[c]=new Rn;break;case D.KHR_MESH_QUANTIZATION:o[c]=new vn;break;default:u.indexOf(c)>=0&&a[c]===void 0&&console.warn('THREE.GLTFLoader: Unknown extension "'+c+'".')}}r.setExtensions(o),r.setPlugins(a),r.parse(n,i)}parseAsync(e,t){const n=this;return new Promise(function(i,s){n.parse(e,t,i,s)})}}function Jt(){let m={};return{get:function(e){return m[e]},add:function(e,t){m[e]=t},remove:function(e){delete m[e]},removeAll:function(){m={}}}}const D={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 $t{constructor(e){this.parser=e,this.name=D.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){const e=this.parser,t=this.parser.json.nodes||[];for(let n=0,i=t.length;n<i;n++){const s=t[n];s.extensions&&s.extensions[this.name]&&s.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,s.extensions[this.name].light)}}_loadLight(e){const t=this.parser,n="light:"+e;let i=t.cache.get(n);if(i)return i;const s=t.json,l=((s.extensions&&s.extensions[this.name]||{}).lights||[])[e];let r;const h=new p.Color(16777215);l.color!==void 0&&h.setRGB(l.color[0],l.color[1],l.color[2],p.LinearSRGBColorSpace);const c=l.range!==void 0?l.range:0;switch(l.type){case"directional":r=new p.DirectionalLight(h),r.target.position.set(0,0,-1),r.add(r.target);break;case"point":r=new p.PointLight(h),r.distance=c;break;case"spot":r=new p.SpotLight(h),r.distance=c,l.spot=l.spot||{},l.spot.innerConeAngle=l.spot.innerConeAngle!==void 0?l.spot.innerConeAngle:0,l.spot.outerConeAngle=l.spot.outerConeAngle!==void 0?l.spot.outerConeAngle:Math.PI/4,r.angle=l.spot.outerConeAngle,r.penumbra=1-l.spot.innerConeAngle/l.spot.outerConeAngle,r.target.position.set(0,0,-1),r.add(r.target);break;default:throw new Error("THREE.GLTFLoader: Unexpected light type: "+l.type)}return r.position.set(0,0,0),ue(r,l),l.intensity!==void 0&&(r.intensity=l.intensity),r.name=t.createUniqueName(l.name||"light_"+e),i=Promise.resolve(r),t.cache.add(n,i),i}getDependency(e,t){if(e==="light")return this._loadLight(t)}createNodeAttachment(e){const t=this,n=this.parser,s=n.json.nodes[e],a=(s.extensions&&s.extensions[this.name]||{}).light;return a===void 0?null:this._loadLight(a).then(function(l){return n._getNodeRef(t.cache,a,l)})}}class en{constructor(){this.name=D.KHR_MATERIALS_UNLIT}getMaterialType(){return p.MeshBasicMaterial}extendParams(e,t,n){const i=[];e.color=new p.Color(1,1,1),e.opacity=1;const s=t.pbrMetallicRoughness;if(s){if(Array.isArray(s.baseColorFactor)){const o=s.baseColorFactor;e.color.setRGB(o[0],o[1],o[2],p.LinearSRGBColorSpace),e.opacity=o[3]}s.baseColorTexture!==void 0&&i.push(n.assignTexture(e,"map",s.baseColorTexture,p.SRGBColorSpace))}return Promise.all(i)}}class tn{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){const i=this.parser.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=i.extensions[this.name].emissiveStrength;return s!==void 0&&(t.emissiveIntensity=s),Promise.resolve()}}class nn{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,i=n.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],o=i.extensions[this.name];if(o.clearcoatFactor!==void 0&&(t.clearcoat=o.clearcoatFactor),o.clearcoatTexture!==void 0&&s.push(n.assignTexture(t,"clearcoatMap",o.clearcoatTexture)),o.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=o.clearcoatRoughnessFactor),o.clearcoatRoughnessTexture!==void 0&&s.push(n.assignTexture(t,"clearcoatRoughnessMap",o.clearcoatRoughnessTexture)),o.clearcoatNormalTexture!==void 0&&(s.push(n.assignTexture(t,"clearcoatNormalMap",o.clearcoatNormalTexture)),o.clearcoatNormalTexture.scale!==void 0)){const a=o.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new p.Vector2(a,a)}return Promise.all(s)}}class sn{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_DISPERSION}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const i=this.parser.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=i.extensions[this.name];return t.dispersion=s.dispersion!==void 0?s.dispersion:0,Promise.resolve()}}class on{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,i=n.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],o=i.extensions[this.name];return o.iridescenceFactor!==void 0&&(t.iridescence=o.iridescenceFactor),o.iridescenceTexture!==void 0&&s.push(n.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&&s.push(n.assignTexture(t,"iridescenceThicknessMap",o.iridescenceThicknessTexture)),Promise.all(s)}}class an{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_SHEEN}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,i=n.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[];t.sheenColor=new p.Color(0,0,0),t.sheenRoughness=0,t.sheen=1;const o=i.extensions[this.name];if(o.sheenColorFactor!==void 0){const a=o.sheenColorFactor;t.sheenColor.setRGB(a[0],a[1],a[2],p.LinearSRGBColorSpace)}return o.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=o.sheenRoughnessFactor),o.sheenColorTexture!==void 0&&s.push(n.assignTexture(t,"sheenColorMap",o.sheenColorTexture,p.SRGBColorSpace)),o.sheenRoughnessTexture!==void 0&&s.push(n.assignTexture(t,"sheenRoughnessMap",o.sheenRoughnessTexture)),Promise.all(s)}}class rn{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,i=n.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],o=i.extensions[this.name];return o.transmissionFactor!==void 0&&(t.transmission=o.transmissionFactor),o.transmissionTexture!==void 0&&s.push(n.assignTexture(t,"transmissionMap",o.transmissionTexture)),Promise.all(s)}}class ln{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_VOLUME}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,i=n.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],o=i.extensions[this.name];t.thickness=o.thicknessFactor!==void 0?o.thicknessFactor:0,o.thicknessTexture!==void 0&&s.push(n.assignTexture(t,"thicknessMap",o.thicknessTexture)),t.attenuationDistance=o.attenuationDistance||1/0;const a=o.attenuationColor||[1,1,1];return t.attenuationColor=new p.Color().setRGB(a[0],a[1],a[2],p.LinearSRGBColorSpace),Promise.all(s)}}class cn{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_IOR}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const i=this.parser.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=i.extensions[this.name];return t.ior=s.ior!==void 0?s.ior:1.5,Promise.resolve()}}class hn{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_SPECULAR}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,i=n.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],o=i.extensions[this.name];t.specularIntensity=o.specularFactor!==void 0?o.specularFactor:1,o.specularTexture!==void 0&&s.push(n.assignTexture(t,"specularIntensityMap",o.specularTexture));const a=o.specularColorFactor||[1,1,1];return t.specularColor=new p.Color().setRGB(a[0],a[1],a[2],p.LinearSRGBColorSpace),o.specularColorTexture!==void 0&&s.push(n.assignTexture(t,"specularColorMap",o.specularColorTexture,p.SRGBColorSpace)),Promise.all(s)}}class un{constructor(e){this.parser=e,this.name=D.EXT_MATERIALS_BUMP}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,i=n.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],o=i.extensions[this.name];return t.bumpScale=o.bumpFactor!==void 0?o.bumpFactor:1,o.bumpTexture!==void 0&&s.push(n.assignTexture(t,"bumpMap",o.bumpTexture)),Promise.all(s)}}class dn{constructor(e){this.parser=e,this.name=D.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){const n=this.parser.json.materials[e];return!n.extensions||!n.extensions[this.name]?null:p.MeshPhysicalMaterial}extendMaterialParams(e,t){const n=this.parser,i=n.json.materials[e];if(!i.extensions||!i.extensions[this.name])return Promise.resolve();const s=[],o=i.extensions[this.name];return o.anisotropyStrength!==void 0&&(t.anisotropy=o.anisotropyStrength),o.anisotropyRotation!==void 0&&(t.anisotropyRotation=o.anisotropyRotation),o.anisotropyTexture!==void 0&&s.push(n.assignTexture(t,"anisotropyMap",o.anisotropyTexture)),Promise.all(s)}}class pn{constructor(e){this.parser=e,this.name=D.KHR_TEXTURE_BASISU}loadTexture(e){const t=this.parser,n=t.json,i=n.textures[e];if(!i.extensions||!i.extensions[this.name])return null;const s=i.extensions[this.name],o=t.options.ktx2Loader;if(!o){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw new Error("THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures");return null}return t.loadTextureImage(e,s.source,o)}}class mn{constructor(e){this.parser=e,this.name=D.EXT_TEXTURE_WEBP}loadTexture(e){const t=this.name,n=this.parser,i=n.json,s=i.textures[e];if(!s.extensions||!s.extensions[t])return null;const o=s.extensions[t],a=i.images[o.source];let l=n.textureLoader;if(a.uri){const r=n.options.manager.getHandler(a.uri);r!==null&&(l=r)}return n.loadTextureImage(e,o.source,l)}}class fn{constructor(e){this.parser=e,this.name=D.EXT_TEXTURE_AVIF}loadTexture(e){const t=this.name,n=this.parser,i=n.json,s=i.textures[e];if(!s.extensions||!s.extensions[t])return null;const o=s.extensions[t],a=i.images[o.source];let l=n.textureLoader;if(a.uri){const r=n.options.manager.getHandler(a.uri);r!==null&&(l=r)}return n.loadTextureImage(e,o.source,l)}}class gn{constructor(e){this.name=D.EXT_MESHOPT_COMPRESSION,this.parser=e}loadBufferView(e){const t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){const i=n.extensions[this.name],s=this.parser.getDependency("buffer",i.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 s.then(function(a){const l=i.byteOffset||0,r=i.byteLength||0,h=i.count,c=i.byteStride,u=new Uint8Array(a,l,r);return o.decodeGltfBufferAsync?o.decodeGltfBufferAsync(h,c,u,i.mode,i.filter).then(function(d){return d.buffer}):o.ready.then(function(){const d=new ArrayBuffer(h*c);return o.decodeGltfBuffer(new Uint8Array(d),h,c,u,i.mode,i.filter),d})})}else return null}}class yn{constructor(e){this.name=D.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){const t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;const i=t.meshes[n.mesh];for(const r of i.primitives)if(r.mode!==se.TRIANGLES&&r.mode!==se.TRIANGLE_STRIP&&r.mode!==se.TRIANGLE_FAN&&r.mode!==void 0)return null;const o=n.extensions[this.name].attributes,a=[],l={};for(const r in o)a.push(this.parser.getDependency("accessor",o[r]).then(h=>(l[r]=h,l[r])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(r=>{const h=r.pop(),c=h.isGroup?h.children:[h],u=r[0].count,d=[];for(const f of c){const x=new p.Matrix4,y=new p.Vector3,R=new p.Quaternion,I=new p.Vector3(1,1,1),g=new p.InstancedMesh(f.geometry,f.material,u);for(let T=0;T<u;T++)l.TRANSLATION&&y.fromBufferAttribute(l.TRANSLATION,T),l.ROTATION&&R.fromBufferAttribute(l.ROTATION,T),l.SCALE&&I.fromBufferAttribute(l.SCALE,T),g.setMatrixAt(T,x.compose(y,R,I));for(const T in l)if(T==="_COLOR_0"){const C=l[T];g.instanceColor=new p.InstancedBufferAttribute(C.array,C.itemSize,C.normalized)}else T!=="TRANSLATION"&&T!=="ROTATION"&&T!=="SCALE"&&f.geometry.setAttribute(T,l[T]);p.Object3D.prototype.copy.call(g,f),this.parser.assignFinalMaterial(g),d.push(g)}return h.isGroup?(h.clear(),h.add(...d),h):d[0]}))}}const vt="glTF",ke=12,ut={JSON:1313821514,BIN:5130562};class xn{constructor(e){this.name=D.KHR_BINARY_GLTF,this.content=null,this.body=null;const t=new DataView(e,0,ke),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==vt)throw new Error("THREE.GLTFLoader: Unsupported glTF-Binary header.");if(this.header.version<2)throw new Error("THREE.GLTFLoader: Legacy binary file detected.");const i=this.header.length-ke,s=new DataView(e,ke);let o=0;for(;o<i;){const a=s.getUint32(o,!0);o+=4;const l=s.getUint32(o,!0);if(o+=4,l===ut.JSON){const r=new Uint8Array(e,ke+o,a);this.content=n.decode(r)}else if(l===ut.BIN){const r=ke+o;this.body=e.slice(r,r+a)}o+=a}if(this.content===null)throw new Error("THREE.GLTFLoader: JSON content not found.")}}class bn{constructor(e,t){if(!t)throw new Error("THREE.GLTFLoader: No DRACOLoader instance provided.");this.name=D.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){const n=this.json,i=this.dracoLoader,s=e.extensions[this.name].bufferView,o=e.extensions[this.name].attributes,a={},l={},r={};for(const h in o){const c=et[h]||h.toLowerCase();a[c]=o[h]}for(const h in e.attributes){const c=et[h]||h.toLowerCase();if(o[h]!==void 0){const u=n.accessors[e.attributes[h]],d=Se[u.componentType];r[c]=d.name,l[c]=u.normalized===!0}}return t.getDependency("bufferView",s).then(function(h){return new Promise(function(c,u){i.decodeDracoFile(h,function(d){for(const f in d.attributes){const x=d.attributes[f],y=l[f];y!==void 0&&(x.normalized=y)}c(d)},a,r,p.LinearSRGBColorSpace,u)})})}}class Rn{constructor(){this.name=D.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 vn{constructor(){this.name=D.KHR_MESH_QUANTIZATION}}class At extends p.Interpolant{constructor(e,t,n,i){super(e,t,n,i)}copySampleValue_(e){const t=this.resultBuffer,n=this.sampleValues,i=this.valueSize,s=e*i*3+i;for(let o=0;o!==i;o++)t[o]=n[s+o];return t}interpolate_(e,t,n,i){const s=this.resultBuffer,o=this.sampleValues,a=this.valueSize,l=a*2,r=a*3,h=i-t,c=(n-t)/h,u=c*c,d=u*c,f=e*r,x=f-r,y=-2*d+3*u,R=d-u,I=1-y,g=R-u+c;for(let T=0;T!==a;T++){const C=o[x+T+a],L=o[x+T+l]*h,P=o[f+T+a],z=o[f+T]*h;s[T]=I*C+g*L+y*P+R*z}return s}}const An=new p.Quaternion;class Ln extends At{interpolate_(e,t,n,i){const s=super.interpolate_(e,t,n,i);return An.fromArray(s).normalize().toArray(s),s}}const se={POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6},Se={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},dt={9728:p.NearestFilter,9729:p.LinearFilter,9984:p.NearestMipmapNearestFilter,9985:p.LinearMipmapNearestFilter,9986:p.NearestMipmapLinearFilter,9987:p.LinearMipmapLinearFilter},pt={33071:p.ClampToEdgeWrapping,33648:p.MirroredRepeatWrapping,10497:p.RepeatWrapping},je={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},et={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"},fe={scale:"scale",translation:"position",rotation:"quaternion",weights:"morphTargetInfluences"},In={CUBICSPLINE:void 0,LINEAR:p.InterpolateLinear,STEP:p.InterpolateDiscrete},Ze={OPAQUE:"OPAQUE",MASK:"MASK",BLEND:"BLEND"};function wn(m){return m.DefaultMaterial===void 0&&(m.DefaultMaterial=new p.MeshStandardMaterial({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:p.FrontSide})),m.DefaultMaterial}function be(m,e,t){for(const n in t.extensions)m[n]===void 0&&(e.userData.gltfExtensions=e.userData.gltfExtensions||{},e.userData.gltfExtensions[n]=t.extensions[n])}function ue(m,e){e.extras!==void 0&&(typeof e.extras=="object"?Object.assign(m.userData,e.extras):console.warn("THREE.GLTFLoader: Ignoring primitive type .extras, "+e.extras))}function Sn(m,e,t){let n=!1,i=!1,s=!1;for(let r=0,h=e.length;r<h;r++){const c=e[r];if(c.POSITION!==void 0&&(n=!0),c.NORMAL!==void 0&&(i=!0),c.COLOR_0!==void 0&&(s=!0),n&&i&&s)break}if(!n&&!i&&!s)return Promise.resolve(m);const o=[],a=[],l=[];for(let r=0,h=e.length;r<h;r++){const c=e[r];if(n){const u=c.POSITION!==void 0?t.getDependency("accessor",c.POSITION):m.attributes.position;o.push(u)}if(i){const u=c.NORMAL!==void 0?t.getDependency("accessor",c.NORMAL):m.attributes.normal;a.push(u)}if(s){const u=c.COLOR_0!==void 0?t.getDependency("accessor",c.COLOR_0):m.attributes.color;l.push(u)}}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(l)]).then(function(r){const h=r[0],c=r[1],u=r[2];return n&&(m.morphAttributes.position=h),i&&(m.morphAttributes.normal=c),s&&(m.morphAttributes.color=u),m.morphTargetsRelative=!0,m})}function Tn(m,e){if(m.updateMorphTargets(),e.weights!==void 0)for(let t=0,n=e.weights.length;t<n;t++)m.morphTargetInfluences[t]=e.weights[t];if(e.extras&&Array.isArray(e.extras.targetNames)){const t=e.extras.targetNames;if(m.morphTargetInfluences.length===t.length){m.morphTargetDictionary={};for(let n=0,i=t.length;n<i;n++)m.morphTargetDictionary[t[n]]=n}else console.warn("THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.")}}function kn(m){let e;const t=m.extensions&&m.extensions[D.KHR_DRACO_MESH_COMPRESSION];if(t?e="draco:"+t.bufferView+":"+t.indices+":"+Ye(t.attributes):e=m.indices+":"+Ye(m.attributes)+":"+m.mode,m.targets!==void 0)for(let n=0,i=m.targets.length;n<i;n++)e+=":"+Ye(m.targets[n]);return e}function Ye(m){let e="";const t=Object.keys(m).sort();for(let n=0,i=t.length;n<i;n++)e+=t[n]+":"+m[t[n]]+";";return e}function tt(m){switch(m){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 Cn(m){return m.search(/\.jpe?g($|\?)/i)>0||m.search(/^data\:image\/jpeg/)===0?"image/jpeg":m.search(/\.webp($|\?)/i)>0||m.search(/^data\:image\/webp/)===0?"image/webp":m.search(/\.ktx2($|\?)/i)>0||m.search(/^data\:image\/ktx2/)===0?"image/ktx2":"image/png"}const En=new p.Matrix4;class Mn{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new Jt,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 n=!1,i=-1,s=!1,o=-1;if(typeof navigator<"u"){const a=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(a)===!0;const l=a.match(/Version\/(\d+)/);i=n&&l?parseInt(l[1],10):-1,s=a.indexOf("Firefox")>-1,o=s?a.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>"u"||n&&i<17||s&&o<98?this.textureLoader=new p.TextureLoader(this.options.manager):this.textureLoader=new p.ImageBitmapLoader(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new p.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 n=this,i=this.json,s=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([n.getDependencies("scene"),n.getDependencies("animation"),n.getDependencies("camera")])}).then(function(o){const a={scene:o[0][i.scene||0],scenes:o[0],animations:o[1],cameras:o[2],asset:i.asset,parser:n,userData:{}};return be(s,a,i),ue(a,i),Promise.all(n._invokeAll(function(l){return l.afterRoot&&l.afterRoot(a)})).then(function(){for(const l of a.scenes)l.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){const e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let i=0,s=t.length;i<s;i++){const o=t[i].joints;for(let a=0,l=o.length;a<l;a++)e[o[a]].isBone=!0}for(let i=0,s=e.length;i<s;i++){const o=e[i];o.mesh!==void 0&&(this._addNodeRef(this.meshCache,o.mesh),o.skin!==void 0&&(n[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,n){if(e.refs[t]<=1)return n;const i=n.clone(),s=(o,a)=>{const l=this.associations.get(o);l!=null&&this.associations.set(a,l);for(const[r,h]of o.children.entries())s(h,a.children[r])};return s(n,i),i.name+="_instance_"+e.uses[t]++,i}_invokeOne(e){const t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){const i=e(t[n]);if(i)return i}return null}_invokeAll(e){const t=Object.values(this.plugins);t.unshift(this);const n=[];for(let i=0;i<t.length;i++){const s=e(t[i]);s&&n.push(s)}return n}getDependency(e,t){const n=e+":"+t;let i=this.cache.get(n);if(!i){switch(e){case"scene":i=this.loadScene(t);break;case"node":i=this._invokeOne(function(s){return s.loadNode&&s.loadNode(t)});break;case"mesh":i=this._invokeOne(function(s){return s.loadMesh&&s.loadMesh(t)});break;case"accessor":i=this.loadAccessor(t);break;case"bufferView":i=this._invokeOne(function(s){return s.loadBufferView&&s.loadBufferView(t)});break;case"buffer":i=this.loadBuffer(t);break;case"material":i=this._invokeOne(function(s){return s.loadMaterial&&s.loadMaterial(t)});break;case"texture":i=this._invokeOne(function(s){return s.loadTexture&&s.loadTexture(t)});break;case"skin":i=this.loadSkin(t);break;case"animation":i=this._invokeOne(function(s){return s.loadAnimation&&s.loadAnimation(t)});break;case"camera":i=this.loadCamera(t);break;default:if(i=this._invokeOne(function(s){return s!=this&&s.getDependency&&s.getDependency(e,t)}),!i)throw new Error("Unknown type: "+e);break}this.cache.add(n,i)}return i}getDependencies(e){let t=this.cache.get(e);if(!t){const n=this,i=this.json[e+(e==="mesh"?"es":"s")]||[];t=Promise.all(i.map(function(s,o){return n.getDependency(e,o)})),this.cache.add(e,t)}return t}loadBuffer(e){const t=this.json.buffers[e],n=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[D.KHR_BINARY_GLTF].body);const i=this.options;return new Promise(function(s,o){n.load(p.LoaderUtils.resolveURL(t.uri,i.path),s,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(n){const i=t.byteLength||0,s=t.byteOffset||0;return n.slice(s,s+i)})}loadAccessor(e){const t=this,n=this.json,i=this.json.accessors[e];if(i.bufferView===void 0&&i.sparse===void 0){const o=je[i.type],a=Se[i.componentType],l=i.normalized===!0,r=new a(i.count*o);return Promise.resolve(new p.BufferAttribute(r,o,l))}const s=[];return i.bufferView!==void 0?s.push(this.getDependency("bufferView",i.bufferView)):s.push(null),i.sparse!==void 0&&(s.push(this.getDependency("bufferView",i.sparse.indices.bufferView)),s.push(this.getDependency("bufferView",i.sparse.values.bufferView))),Promise.all(s).then(function(o){const a=o[0],l=je[i.type],r=Se[i.componentType],h=r.BYTES_PER_ELEMENT,c=h*l,u=i.byteOffset||0,d=i.bufferView!==void 0?n.bufferViews[i.bufferView].byteStride:void 0,f=i.normalized===!0;let x,y;if(d&&d!==c){const R=Math.floor(u/d),I="InterleavedBuffer:"+i.bufferView+":"+i.componentType+":"+R+":"+i.count;let g=t.cache.get(I);g||(x=new r(a,R*d,i.count*d/h),g=new p.InterleavedBuffer(x,d/h),t.cache.add(I,g)),y=new p.InterleavedBufferAttribute(g,l,u%d/h,f)}else a===null?x=new r(i.count*l):x=new r(a,u,i.count*l),y=new p.BufferAttribute(x,l,f);if(i.sparse!==void 0){const R=je.SCALAR,I=Se[i.sparse.indices.componentType],g=i.sparse.indices.byteOffset||0,T=i.sparse.values.byteOffset||0,C=new I(o[1],g,i.sparse.count*R),L=new r(o[2],T,i.sparse.count*l);a!==null&&(y=new p.BufferAttribute(y.array.slice(),y.itemSize,y.normalized)),y.normalized=!1;for(let P=0,z=C.length;P<z;P++){const _=C[P];if(y.setX(_,L[P*l]),l>=2&&y.setY(_,L[P*l+1]),l>=3&&y.setZ(_,L[P*l+2]),l>=4&&y.setW(_,L[P*l+3]),l>=5)throw new Error("THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.")}y.normalized=f}return y})}loadTexture(e){const t=this.json,n=this.options,s=t.textures[e].source,o=t.images[s];let a=this.textureLoader;if(o.uri){const l=n.manager.getHandler(o.uri);l!==null&&(a=l)}return this.loadTextureImage(e,s,a)}loadTextureImage(e,t,n){const i=this,s=this.json,o=s.textures[e],a=s.images[t],l=(a.uri||a.bufferView)+":"+o.sampler;if(this.textureCache[l])return this.textureCache[l];const r=this.loadImageSource(t,n).then(function(h){h.flipY=!1,h.name=o.name||a.name||"",h.name===""&&typeof a.uri=="string"&&a.uri.startsWith("data:image/")===!1&&(h.name=a.uri);const u=(s.samplers||{})[o.sampler]||{};return h.magFilter=dt[u.magFilter]||p.LinearFilter,h.minFilter=dt[u.minFilter]||p.LinearMipmapLinearFilter,h.wrapS=pt[u.wrapS]||p.RepeatWrapping,h.wrapT=pt[u.wrapT]||p.RepeatWrapping,h.generateMipmaps=!h.isCompressedTexture&&h.minFilter!==p.NearestFilter&&h.minFilter!==p.LinearFilter,i.associations.set(h,{textures:e}),h}).catch(function(){return null});return this.textureCache[l]=r,r}loadImageSource(e,t){const n=this,i=this.json,s=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(c=>c.clone());const o=i.images[e],a=self.URL||self.webkitURL;let l=o.uri||"",r=!1;if(o.bufferView!==void 0)l=n.getDependency("bufferView",o.bufferView).then(function(c){r=!0;const u=new Blob([c],{type:o.mimeType});return l=a.createObjectURL(u),l});else if(o.uri===void 0)throw new Error("THREE.GLTFLoader: Image "+e+" is missing URI and bufferView");const h=Promise.resolve(l).then(function(c){return new Promise(function(u,d){let f=u;t.isImageBitmapLoader===!0&&(f=function(x){const y=new p.Texture(x);y.needsUpdate=!0,u(y)}),t.load(p.LoaderUtils.resolveURL(c,s.path),f,void 0,d)})}).then(function(c){return r===!0&&a.revokeObjectURL(l),ue(c,o),c.userData.mimeType=o.mimeType||Cn(o.uri),c}).catch(function(c){throw console.error("THREE.GLTFLoader: Couldn't load texture",l),c});return this.sourceCache[e]=h,h}assignTexture(e,t,n,i){const s=this;return this.getDependency("texture",n.index).then(function(o){if(!o)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(o=o.clone(),o.channel=n.texCoord),s.extensions[D.KHR_TEXTURE_TRANSFORM]){const a=n.extensions!==void 0?n.extensions[D.KHR_TEXTURE_TRANSFORM]:void 0;if(a){const l=s.associations.get(o);o=s.extensions[D.KHR_TEXTURE_TRANSFORM].extendTexture(o,a),s.associations.set(o,l)}}return i!==void 0&&(o.colorSpace=i),e[t]=o,o})}assignFinalMaterial(e){const t=e.geometry;let n=e.material;const i=t.attributes.tangent===void 0,s=t.attributes.color!==void 0,o=t.attributes.normal===void 0;if(e.isPoints){const a="PointsMaterial:"+n.uuid;let l=this.cache.get(a);l||(l=new p.PointsMaterial,p.Material.prototype.copy.call(l,n),l.color.copy(n.color),l.map=n.map,l.sizeAttenuation=!1,this.cache.add(a,l)),n=l}else if(e.isLine){const a="LineBasicMaterial:"+n.uuid;let l=this.cache.get(a);l||(l=new p.LineBasicMaterial,p.Material.prototype.copy.call(l,n),l.color.copy(n.color),l.map=n.map,this.cache.add(a,l)),n=l}if(i||s||o){let a="ClonedMaterial:"+n.uuid+":";i&&(a+="derivative-tangents:"),s&&(a+="vertex-colors:"),o&&(a+="flat-shading:");let l=this.cache.get(a);l||(l=n.clone(),s&&(l.vertexColors=!0),o&&(l.flatShading=!0),i&&(l.normalScale&&(l.normalScale.y*=-1),l.clearcoatNormalScale&&(l.clearcoatNormalScale.y*=-1)),this.cache.add(a,l),this.associations.set(l,this.associations.get(n))),n=l}e.material=n}getMaterialType(){return p.MeshStandardMaterial}loadMaterial(e){const t=this,n=this.json,i=this.extensions,s=n.materials[e];let o;const a={},l=s.extensions||{},r=[];if(l[D.KHR_MATERIALS_UNLIT]){const c=i[D.KHR_MATERIALS_UNLIT];o=c.getMaterialType(),r.push(c.extendParams(a,s,t))}else{const c=s.pbrMetallicRoughness||{};if(a.color=new p.Color(1,1,1),a.opacity=1,Array.isArray(c.baseColorFactor)){const u=c.baseColorFactor;a.color.setRGB(u[0],u[1],u[2],p.LinearSRGBColorSpace),a.opacity=u[3]}c.baseColorTexture!==void 0&&r.push(t.assignTexture(a,"map",c.baseColorTexture,p.SRGBColorSpace)),a.metalness=c.metallicFactor!==void 0?c.metallicFactor:1,a.roughness=c.roughnessFactor!==void 0?c.roughnessFactor:1,c.metallicRoughnessTexture!==void 0&&(r.push(t.assignTexture(a,"metalnessMap",c.metallicRoughnessTexture)),r.push(t.assignTexture(a,"roughnessMap",c.metallicRoughnessTexture))),o=this._invokeOne(function(u){return u.getMaterialType&&u.getMaterialType(e)}),r.push(Promise.all(this._invokeAll(function(u){return u.extendMaterialParams&&u.extendMaterialParams(e,a)})))}s.doubleSided===!0&&(a.side=p.DoubleSide);const h=s.alphaMode||Ze.OPAQUE;if(h===Ze.BLEND?(a.transparent=!0,a.depthWrite=!1):(a.transparent=!1,h===Ze.MASK&&(a.alphaTest=s.alphaCutoff!==void 0?s.alphaCutoff:.5)),s.normalTexture!==void 0&&o!==p.MeshBasicMaterial&&(r.push(t.assignTexture(a,"normalMap",s.normalTexture)),a.normalScale=new p.Vector2(1,1),s.normalTexture.scale!==void 0)){const c=s.normalTexture.scale;a.normalScale.set(c,c)}if(s.occlusionTexture!==void 0&&o!==p.MeshBasicMaterial&&(r.push(t.assignTexture(a,"aoMap",s.occlusionTexture)),s.occlusionTexture.strength!==void 0&&(a.aoMapIntensity=s.occlusionTexture.strength)),s.emissiveFactor!==void 0&&o!==p.MeshBasicMaterial){const c=s.emissiveFactor;a.emissive=new p.Color().setRGB(c[0],c[1],c[2],p.LinearSRGBColorSpace)}return s.emissiveTexture!==void 0&&o!==p.MeshBasicMaterial&&r.push(t.assignTexture(a,"emissiveMap",s.emissiveTexture,p.SRGBColorSpace)),Promise.all(r).then(function(){const c=new o(a);return s.name&&(c.name=s.name),ue(c,s),t.associations.set(c,{materials:e}),s.extensions&&be(i,c,s),c})}createUniqueName(e){const t=p.PropertyBinding.sanitizeNodeName(e||"");return t in this.nodeNamesUsed?t+"_"+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){const t=this,n=this.extensions,i=this.primitiveCache;function s(a){return n[D.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(a,t).then(function(l){return mt(l,a,t)})}const o=[];for(let a=0,l=e.length;a<l;a++){const r=e[a],h=kn(r),c=i[h];if(c)o.push(c.promise);else{let u;r.extensions&&r.extensions[D.KHR_DRACO_MESH_COMPRESSION]?u=s(r):u=mt(new p.BufferGeometry,r,t),i[h]={primitive:r,promise:u},o.push(u)}}return Promise.all(o)}loadMesh(e){const t=this,n=this.json,i=this.extensions,s=n.meshes[e],o=s.primitives,a=[];for(let l=0,r=o.length;l<r;l++){const h=o[l].material===void 0?wn(this.cache):this.getDependency("material",o[l].material);a.push(h)}return a.push(t.loadGeometries(o)),Promise.all(a).then(function(l){const r=l.slice(0,l.length-1),h=l[l.length-1],c=[];for(let d=0,f=h.length;d<f;d++){const x=h[d],y=o[d];let R;const I=r[d];if(y.mode===se.TRIANGLES||y.mode===se.TRIANGLE_STRIP||y.mode===se.TRIANGLE_FAN||y.mode===void 0)R=s.isSkinnedMesh===!0?new p.SkinnedMesh(x,I):new p.Mesh(x,I),R.isSkinnedMesh===!0&&R.normalizeSkinWeights(),y.mode===se.TRIANGLE_STRIP?R.geometry=ht(R.geometry,p.TriangleStripDrawMode):y.mode===se.TRIANGLE_FAN&&(R.geometry=ht(R.geometry,p.TriangleFanDrawMode));else if(y.mode===se.LINES)R=new p.LineSegments(x,I);else if(y.mode===se.LINE_STRIP)R=new p.Line(x,I);else if(y.mode===se.LINE_LOOP)R=new p.LineLoop(x,I);else if(y.mode===se.POINTS)R=new p.Points(x,I);else throw new Error("THREE.GLTFLoader: Primitive mode unsupported: "+y.mode);Object.keys(R.geometry.morphAttributes).length>0&&Tn(R,s),R.name=t.createUniqueName(s.name||"mesh_"+e),ue(R,s),y.extensions&&be(i,R,y),t.assignFinalMaterial(R),c.push(R)}for(let d=0,f=c.length;d<f;d++)t.associations.set(c[d],{meshes:e,primitives:d});if(c.length===1)return s.extensions&&be(i,c[0],s),c[0];const u=new p.Group;s.extensions&&be(i,u,s),t.associations.set(u,{meshes:e});for(let d=0,f=c.length;d<f;d++)u.add(c[d]);return u})}loadCamera(e){let t;const n=this.json.cameras[e],i=n[n.type];if(!i){console.warn("THREE.GLTFLoader: Missing camera parameters.");return}return n.type==="perspective"?t=new p.PerspectiveCamera(p.MathUtils.radToDeg(i.yfov),i.aspectRatio||1,i.znear||1,i.zfar||2e6):n.type==="orthographic"&&(t=new p.OrthographicCamera(-i.xmag,i.xmag,i.ymag,-i.ymag,i.znear,i.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),ue(t,n),Promise.resolve(t)}loadSkin(e){const t=this.json.skins[e],n=[];for(let i=0,s=t.joints.length;i<s;i++)n.push(this._loadNodeShallow(t.joints[i]));return t.inverseBindMatrices!==void 0?n.push(this.getDependency("accessor",t.inverseBindMatrices)):n.push(null),Promise.all(n).then(function(i){const s=i.pop(),o=i,a=[],l=[];for(let r=0,h=o.length;r<h;r++){const c=o[r];if(c){a.push(c);const u=new p.Matrix4;s!==null&&u.fromArray(s.array,r*16),l.push(u)}else console.warn('THREE.GLTFLoader: Joint "%s" could not be found.',t.joints[r])}return new p.Skeleton(a,l)})}loadAnimation(e){const t=this.json,n=this,i=t.animations[e],s=i.name?i.name:"animation_"+e,o=[],a=[],l=[],r=[],h=[];for(let c=0,u=i.channels.length;c<u;c++){const d=i.channels[c],f=i.samplers[d.sampler],x=d.target,y=x.node,R=i.parameters!==void 0?i.parameters[f.input]:f.input,I=i.parameters!==void 0?i.parameters[f.output]:f.output;x.node!==void 0&&(o.push(this.getDependency("node",y)),a.push(this.getDependency("accessor",R)),l.push(this.getDependency("accessor",I)),r.push(f),h.push(x))}return Promise.all([Promise.all(o),Promise.all(a),Promise.all(l),Promise.all(r),Promise.all(h)]).then(function(c){const u=c[0],d=c[1],f=c[2],x=c[3],y=c[4],R=[];for(let g=0,T=u.length;g<T;g++){const C=u[g],L=d[g],P=f[g],z=x[g],_=y[g];if(C===void 0)continue;C.updateMatrix&&C.updateMatrix();const U=n._createAnimationTracks(C,L,P,z,_);if(U)for(let S=0;S<U.length;S++)R.push(U[S])}const I=new p.AnimationClip(s,void 0,R);return ue(I,i),I})}createNodeMesh(e){const t=this.json,n=this,i=t.nodes[e];return i.mesh===void 0?null:n.getDependency("mesh",i.mesh).then(function(s){const o=n._getNodeRef(n.meshCache,i.mesh,s);return i.weights!==void 0&&o.traverse(function(a){if(a.isMesh)for(let l=0,r=i.weights.length;l<r;l++)a.morphTargetInfluences[l]=i.weights[l]}),o})}loadNode(e){const t=this.json,n=this,i=t.nodes[e],s=n._loadNodeShallow(e),o=[],a=i.children||[];for(let r=0,h=a.length;r<h;r++)o.push(n.getDependency("node",a[r]));const l=i.skin===void 0?Promise.resolve(null):n.getDependency("skin",i.skin);return Promise.all([s,Promise.all(o),l]).then(function(r){const h=r[0],c=r[1],u=r[2];u!==null&&h.traverse(function(d){d.isSkinnedMesh&&d.bind(u,En)});for(let d=0,f=c.length;d<f;d++)h.add(c[d]);return h})}_loadNodeShallow(e){const t=this.json,n=this.extensions,i=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];const s=t.nodes[e],o=s.name?i.createUniqueName(s.name):"",a=[],l=i._invokeOne(function(r){return r.createNodeMesh&&r.createNodeMesh(e)});return l&&a.push(l),s.camera!==void 0&&a.push(i.getDependency("camera",s.camera).then(function(r){return i._getNodeRef(i.cameraCache,s.camera,r)})),i._invokeAll(function(r){return r.createNodeAttachment&&r.createNodeAttachment(e)}).forEach(function(r){a.push(r)}),this.nodeCache[e]=Promise.all(a).then(function(r){let h;if(s.isBone===!0?h=new p.Bone:r.length>1?h=new p.Group:r.length===1?h=r[0]:h=new p.Object3D,h!==r[0])for(let c=0,u=r.length;c<u;c++)h.add(r[c]);if(s.name&&(h.userData.name=s.name,h.name=o),ue(h,s),s.extensions&&be(n,h,s),s.matrix!==void 0){const c=new p.Matrix4;c.fromArray(s.matrix),h.applyMatrix4(c)}else s.translation!==void 0&&h.position.fromArray(s.translation),s.rotation!==void 0&&h.quaternion.fromArray(s.rotation),s.scale!==void 0&&h.scale.fromArray(s.scale);if(!i.associations.has(h))i.associations.set(h,{});else if(s.mesh!==void 0&&i.meshCache.refs[s.mesh]>1){const c=i.associations.get(h);i.associations.set(h,{...c})}return i.associations.get(h).nodes=e,h}),this.nodeCache[e]}loadScene(e){const t=this.extensions,n=this.json.scenes[e],i=this,s=new p.Group;n.name&&(s.name=i.createUniqueName(n.name)),ue(s,n),n.extensions&&be(t,s,n);const o=n.nodes||[],a=[];for(let l=0,r=o.length;l<r;l++)a.push(i.getDependency("node",o[l]));return Promise.all(a).then(function(l){for(let h=0,c=l.length;h<c;h++)s.add(l[h]);const r=h=>{const c=new Map;for(const[u,d]of i.associations)(u instanceof p.Material||u instanceof p.Texture)&&c.set(u,d);return h.traverse(u=>{const d=i.associations.get(u);d!=null&&c.set(u,d)}),c};return i.associations=r(s),s})}_createAnimationTracks(e,t,n,i,s){const o=[],a=e.name?e.name:e.uuid,l=[];fe[s.path]===fe.weights?e.traverse(function(u){u.morphTargetInfluences&&l.push(u.name?u.name:u.uuid)}):l.push(a);let r;switch(fe[s.path]){case fe.weights:r=p.NumberKeyframeTrack;break;case fe.rotation:r=p.QuaternionKeyframeTrack;break;case fe.translation:case fe.scale:r=p.VectorKeyframeTrack;break;default:switch(n.itemSize){case 1:r=p.NumberKeyframeTrack;break;case 2:case 3:default:r=p.VectorKeyframeTrack;break}break}const h=i.interpolation!==void 0?In[i.interpolation]:p.InterpolateLinear,c=this._getArrayFromAccessor(n);for(let u=0,d=l.length;u<d;u++){const f=new r(l[u]+"."+fe[s.path],t.array,c,h);i.interpolation==="CUBICSPLINE"&&this._createCubicSplineTrackInterpolant(f),o.push(f)}return o}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){const n=tt(t.constructor),i=new Float32Array(t.length);for(let s=0,o=t.length;s<o;s++)i[s]=t[s]*n;t=i}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(n){const i=this instanceof p.QuaternionKeyframeTrack?Ln:At;return new i(this.times,this.values,this.getValueSize()/3,n)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}}function zn(m,e,t){const n=e.attributes,i=new p.Box3;if(n.POSITION!==void 0){const a=t.json.accessors[n.POSITION],l=a.min,r=a.max;if(l!==void 0&&r!==void 0){if(i.set(new p.Vector3(l[0],l[1],l[2]),new p.Vector3(r[0],r[1],r[2])),a.normalized){const h=tt(Se[a.componentType]);i.min.multiplyScalar(h),i.max.multiplyScalar(h)}}else{console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.");return}}else return;const s=e.targets;if(s!==void 0){const a=new p.Vector3,l=new p.Vector3;for(let r=0,h=s.length;r<h;r++){const c=s[r];if(c.POSITION!==void 0){const u=t.json.accessors[c.POSITION],d=u.min,f=u.max;if(d!==void 0&&f!==void 0){if(l.setX(Math.max(Math.abs(d[0]),Math.abs(f[0]))),l.setY(Math.max(Math.abs(d[1]),Math.abs(f[1]))),l.setZ(Math.max(Math.abs(d[2]),Math.abs(f[2]))),u.normalized){const x=tt(Se[u.componentType]);l.multiplyScalar(x)}a.max(l)}else console.warn("THREE.GLTFLoader: Missing min/max properties for accessor POSITION.")}}i.expandByVector(a)}m.boundingBox=i;const o=new p.Sphere;i.getCenter(o.center),o.radius=i.min.distanceTo(i.max)/2,m.boundingSphere=o}function mt(m,e,t){const n=e.attributes,i=[];function s(o,a){return t.getDependency("accessor",o).then(function(l){m.setAttribute(a,l)})}for(const o in n){const a=et[o]||o.toLowerCase();a in m.attributes||i.push(s(n[o],a))}if(e.indices!==void 0&&!m.index){const o=t.getDependency("accessor",e.indices).then(function(a){m.setIndex(a)});i.push(o)}return p.ColorManagement.workingColorSpace!==p.LinearSRGBColorSpace&&"COLOR_0"in n&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${p.ColorManagement.workingColorSpace}" not supported.`),ue(m,e),zn(m,e,t),Promise.all(i).then(function(){return e.targets!==void 0?Sn(m,e.targets,t):m})}const Ke=new WeakMap;class Hn extends p.Loader{constructor(e){super(e),this.decoderPath="",this.decoderConfig={},this.decoderBinary=null,this.decoderPending=null,this.workerLimit=4,this.workerPool=[],this.workerNextTaskID=1,this.workerSourceURL="",this.defaultAttributeIDs={position:"POSITION",normal:"NORMAL",color:"COLOR",uv:"TEX_COORD"},this.defaultAttributeTypes={position:"Float32Array",normal:"Float32Array",color:"Float32Array",uv:"Float32Array"}}setDecoderPath(e){return this.decoderPath=e,this}setDecoderConfig(e){return this.decoderConfig=e,this}setWorkerLimit(e){return this.workerLimit=e,this}load(e,t,n,i){const s=new p.FileLoader(this.manager);s.setPath(this.path),s.setResponseType("arraybuffer"),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,o=>{this.parse(o,t,i)},n,i)}parse(e,t,n=()=>{}){this.decodeDracoFile(e,t,null,null,p.SRGBColorSpace,n).catch(n)}decodeDracoFile(e,t,n,i,s=p.LinearSRGBColorSpace,o=()=>{}){const a={attributeIDs:n||this.defaultAttributeIDs,attributeTypes:i||this.defaultAttributeTypes,useUniqueIDs:!!n,vertexColorSpace:s};return this.decodeGeometry(e,a).then(t).catch(o)}decodeGeometry(e,t){const n=JSON.stringify(t);if(Ke.has(e)){const l=Ke.get(e);if(l.key===n)return l.promise;if(e.byteLength===0)throw new Error("THREE.DRACOLoader: Unable to re-decode a buffer with different settings. Buffer has already been transferred.")}let i;const s=this.workerNextTaskID++,o=e.byteLength,a=this._getWorker(s,o).then(l=>(i=l,new Promise((r,h)=>{i._callbacks[s]={resolve:r,reject:h},i.postMessage({type:"decode",id:s,taskConfig:t,buffer:e},[e])}))).then(l=>this._createGeometry(l.geometry));return a.catch(()=>!0).then(()=>{i&&s&&this._releaseTask(i,s)}),Ke.set(e,{key:n,promise:a}),a}_createGeometry(e){const t=new p.BufferGeometry;e.index&&t.setIndex(new p.BufferAttribute(e.index.array,1));for(let n=0;n<e.attributes.length;n++){const i=e.attributes[n],s=i.name,o=i.array,a=i.itemSize,l=new p.BufferAttribute(o,a);s==="color"&&(this._assignVertexColorSpace(l,i.vertexColorSpace),l.normalized=!(o instanceof Float32Array)),t.setAttribute(s,l)}return t}_assignVertexColorSpace(e,t){if(t!==p.SRGBColorSpace)return;const n=new p.Color;for(let i=0,s=e.count;i<s;i++)n.fromBufferAttribute(e,i),p.ColorManagement.colorSpaceToWorking(n,p.SRGBColorSpace),e.setXYZ(i,n.r,n.g,n.b)}_loadLibrary(e,t){const n=new p.FileLoader(this.manager);return n.setPath(this.decoderPath),n.setResponseType(t),n.setWithCredentials(this.withCredentials),new Promise((i,s)=>{n.load(e,i,void 0,s)})}preload(){return this._initDecoder(),this}_initDecoder(){if(this.decoderPending)return this.decoderPending;const e=typeof WebAssembly!="object"||this.decoderConfig.type==="js",t=[];return e?t.push(this._loadLibrary("draco_decoder.js","text")):(t.push(this._loadLibrary("draco_wasm_wrapper.js","text")),t.push(this._loadLibrary("draco_decoder.wasm","arraybuffer"))),this.decoderPending=Promise.all(t).then(n=>{const i=n[0];e||(this.decoderConfig.wasmBinary=n[1]);const s=Pn.toString(),o=["/* draco decoder */",i,"","/* worker */",s.substring(s.indexOf("{")+1,s.lastIndexOf("}"))].join(`
|
|
2
|
-
`);this.workerSourceURL=URL.createObjectURL(new Blob([o]))}),this.decoderPending}_getWorker(e,t){return this._initDecoder().then(()=>{if(this.workerPool.length<this.workerLimit){const i=new Worker(this.workerSourceURL);i._callbacks={},i._taskCosts={},i._taskLoad=0,i.postMessage({type:"init",decoderConfig:this.decoderConfig}),i.onmessage=function(s){const o=s.data;switch(o.type){case"decode":i._callbacks[o.id].resolve(o);break;case"error":i._callbacks[o.id].reject(o);break;default:console.error('THREE.DRACOLoader: Unexpected message, "'+o.type+'"')}},this.workerPool.push(i)}else this.workerPool.sort(function(i,s){return i._taskLoad>s._taskLoad?-1:1});const n=this.workerPool[this.workerPool.length-1];return n._taskCosts[e]=t,n._taskLoad+=t,n})}_releaseTask(e,t){e._taskLoad-=e._taskCosts[t],delete e._callbacks[t],delete e._taskCosts[t]}debug(){console.log("Task load: ",this.workerPool.map(e=>e._taskLoad))}dispose(){for(let e=0;e<this.workerPool.length;++e)this.workerPool[e].terminate();return this.workerPool.length=0,this.workerSourceURL!==""&&URL.revokeObjectURL(this.workerSourceURL),this}}function Pn(){let m,e;onmessage=function(o){const a=o.data;switch(a.type){case"init":m=a.decoderConfig,e=new Promise(function(h){m.onModuleLoaded=function(c){h({draco:c})},DracoDecoderModule(m)});break;case"decode":const l=a.buffer,r=a.taskConfig;e.then(h=>{const c=h.draco,u=new c.Decoder;try{const d=t(c,u,new Int8Array(l),r),f=d.attributes.map(x=>x.array.buffer);d.index&&f.push(d.index.array.buffer),self.postMessage({type:"decode",id:a.id,geometry:d},f)}catch(d){console.error(d),self.postMessage({type:"error",id:a.id,error:d.message})}finally{c.destroy(u)}});break}};function t(o,a,l,r){const h=r.attributeIDs,c=r.attributeTypes;let u,d;const f=a.GetEncodedGeometryType(l);if(f===o.TRIANGULAR_MESH)u=new o.Mesh,d=a.DecodeArrayToMesh(l,l.byteLength,u);else if(f===o.POINT_CLOUD)u=new o.PointCloud,d=a.DecodeArrayToPointCloud(l,l.byteLength,u);else throw new Error("THREE.DRACOLoader: Unexpected geometry type.");if(!d.ok()||u.ptr===0)throw new Error("THREE.DRACOLoader: Decoding failed: "+d.error_msg());const x={index:null,attributes:[]};for(const y in h){const R=self[c[y]];let I,g;if(r.useUniqueIDs)g=h[y],I=a.GetAttributeByUniqueId(u,g);else{if(g=a.GetAttributeId(u,o[h[y]]),g===-1)continue;I=a.GetAttribute(u,g)}const T=i(o,a,u,y,R,I);y==="color"&&(T.vertexColorSpace=r.vertexColorSpace),x.attributes.push(T)}return f===o.TRIANGULAR_MESH&&(x.index=n(o,a,u)),o.destroy(u),x}function n(o,a,l){const h=l.num_faces()*3,c=h*4,u=o._malloc(c);a.GetTrianglesUInt32Array(l,c,u);const d=new Uint32Array(o.HEAPF32.buffer,u,h).slice();return o._free(u),{array:d,itemSize:1}}function i(o,a,l,r,h,c){const u=c.num_components(),f=l.num_points()*u,x=f*h.BYTES_PER_ELEMENT,y=s(o,h),R=o._malloc(x);a.GetAttributeDataArrayForAllPoints(l,c,y,x,R);const I=new h(o.HEAPF32.buffer,R,f).slice();return o._free(R),{name:r,array:I,itemSize:u}}function s(o,a){switch(a){case Float32Array:return o.DT_FLOAT32;case Int8Array:return o.DT_INT8;case Int16Array:return o.DT_INT16;case Int32Array:return o.DT_INT32;case Uint8Array:return o.DT_UINT8;case Uint16Array:return o.DT_UINT16;case Uint32Array:return o.DT_UINT32}}}/*!
|
|
3
|
-
fflate - fast JavaScript compression/decompression
|
|
4
|
-
<https://101arrowz.github.io/fflate>
|
|
5
|
-
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
|
|
6
|
-
version 0.8.2
|
|
7
|
-
*/var oe=Uint8Array,Ie=Uint16Array,Fn=Int32Array,Lt=new oe([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),It=new oe([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),Dn=new oe([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),wt=function(m,e){for(var t=new Ie(31),n=0;n<31;++n)t[n]=e+=1<<m[n-1];for(var i=new Fn(t[30]),n=1;n<30;++n)for(var s=t[n];s<t[n+1];++s)i[s]=s-t[n]<<5|n;return{b:t,r:i}},St=wt(Lt,2),Tt=St.b,On=St.r;Tt[28]=258,On[258]=28;var _n=wt(It,0),Nn=_n.b,nt=new Ie(32768);for(var G=0;G<32768;++G){var ge=(G&43690)>>1|(G&21845)<<1;ge=(ge&52428)>>2|(ge&13107)<<2,ge=(ge&61680)>>4|(ge&3855)<<4,nt[G]=((ge&65280)>>8|(ge&255)<<8)>>1}var Ce=(function(m,e,t){for(var n=m.length,i=0,s=new Ie(e);i<n;++i)m[i]&&++s[m[i]-1];var o=new Ie(e);for(i=1;i<e;++i)o[i]=o[i-1]+s[i-1]<<1;var a;if(t){a=new Ie(1<<e);var l=15-e;for(i=0;i<n;++i)if(m[i])for(var r=i<<4|m[i],h=e-m[i],c=o[m[i]-1]++<<h,u=c|(1<<h)-1;c<=u;++c)a[nt[c]>>l]=r}else for(a=new Ie(n),i=0;i<n;++i)m[i]&&(a[i]=nt[o[m[i]-1]++]>>15-m[i]);return a}),ze=new oe(288);for(var G=0;G<144;++G)ze[G]=8;for(var G=144;G<256;++G)ze[G]=9;for(var G=256;G<280;++G)ze[G]=7;for(var G=280;G<288;++G)ze[G]=8;var kt=new oe(32);for(var G=0;G<32;++G)kt[G]=5;var Bn=Ce(ze,9,1),Un=Ce(kt,5,1),Qe=function(m){for(var e=m[0],t=1;t<m.length;++t)m[t]>e&&(e=m[t]);return e},ae=function(m,e,t){var n=e/8|0;return(m[n]|m[n+1]<<8)>>(e&7)&t},qe=function(m,e){var t=e/8|0;return(m[t]|m[t+1]<<8|m[t+2]<<16)>>(e&7)},Gn=function(m){return(m+7)/8|0},Vn=function(m,e,t){return(t==null||t>m.length)&&(t=m.length),new oe(m.subarray(e,t))},Wn=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],re=function(m,e,t){var n=new Error(e||Wn[m]);if(n.code=m,Error.captureStackTrace&&Error.captureStackTrace(n,re),!t)throw n;return n},Xn=function(m,e,t,n){var i=m.length,s=0;if(!i||e.f&&!e.l)return t||new oe(0);var o=!t,a=o||e.i!=2,l=e.i;o&&(t=new oe(i*3));var r=function(Pe){var ve=t.length;if(Pe>ve){var rt=new oe(Math.max(ve*2,Pe));rt.set(t),t=rt}},h=e.f||0,c=e.p||0,u=e.b||0,d=e.l,f=e.d,x=e.m,y=e.n,R=i*8;do{if(!d){h=ae(m,c,1);var I=ae(m,c+1,3);if(c+=3,I)if(I==1)d=Bn,f=Un,x=9,y=5;else if(I==2){var L=ae(m,c,31)+257,P=ae(m,c+10,15)+4,z=L+ae(m,c+5,31)+1;c+=14;for(var _=new oe(z),U=new oe(19),S=0;S<P;++S)U[Dn[S]]=ae(m,c+S*3,7);c+=P*3;for(var A=Qe(U),w=(1<<A)-1,O=Ce(U,A,1),S=0;S<z;){var Q=O[ae(m,c,w)];c+=Q&15;var g=Q>>4;if(g<16)_[S++]=g;else{var Y=0,xe=0;for(g==16?(xe=3+ae(m,c,3),c+=2,Y=_[S-1]):g==17?(xe=3+ae(m,c,7),c+=3):g==18&&(xe=11+ae(m,c,127),c+=7);xe--;)_[S++]=Y}}var He=_.subarray(0,L),le=_.subarray(L);x=Qe(He),y=Qe(le),d=Ce(He,x,1),f=Ce(le,y,1)}else re(1);else{var g=Gn(c)+4,T=m[g-4]|m[g-3]<<8,C=g+T;if(C>i){l&&re(0);break}a&&r(u+T),t.set(m.subarray(g,C),u),e.b=u+=T,e.p=c=C*8,e.f=h;continue}if(c>R){l&&re(0);break}}a&&r(u+131072);for(var Ue=(1<<x)-1,Ge=(1<<y)-1,Te=c;;Te=c){var Y=d[qe(m,c)&Ue],M=Y>>4;if(c+=Y&15,c>R){l&&re(0);break}if(Y||re(2),M<256)t[u++]=M;else if(M==256){Te=c,d=null;break}else{var W=M-254;if(M>264){var S=M-257,X=Lt[S];W=ae(m,c,(1<<X)-1)+Tt[S],c+=X}var V=f[qe(m,c)&Ge],pe=V>>4;V||re(3),c+=V&15;var le=Nn[pe];if(pe>3){var X=It[pe];le+=qe(m,c)&(1<<X)-1,c+=X}if(c>R){l&&re(0);break}a&&r(u+131072);var ee=u+W;if(u<le){var Re=s-le,Ve=Math.min(le,ee);for(Re+u<0&&re(3);u<Ve;++u)t[u]=n[Re+u]}for(;u<ee;++u)t[u]=t[u-le]}}e.l=d,e.p=Te,e.b=u,e.f=h,d&&(h=1,e.m=x,e.d=f,e.n=y)}while(!h);return u!=t.length&&o?Vn(t,0,u):t.subarray(0,u)},jn=new oe(0),Zn=function(m,e){return((m[0]&15)!=8||m[0]>>4>7||(m[0]<<8|m[1])%31)&&re(6,"invalid zlib data"),(m[1]>>5&1)==1&&re(6,"invalid zlib data: "+(m[1]&32?"need":"unexpected")+" dictionary"),(m[1]>>3&4)+2};function Yn(m,e){return Xn(m.subarray(Zn(m),-4),{i:2},e,e)}var Kn=typeof TextDecoder<"u"&&new TextDecoder,Qn=0;try{Kn.decode(jn,{stream:!0}),Qn=1}catch{}function Ct(m,e,t){const n=t.length-m-1;if(e>=t[n])return n-1;if(e<=t[m])return m;let i=m,s=n,o=Math.floor((i+s)/2);for(;e<t[o]||e>=t[o+1];)e<t[o]?s=o:i=o,o=Math.floor((i+s)/2);return o}function qn(m,e,t,n){const i=[],s=[],o=[];i[0]=1;for(let a=1;a<=t;++a){s[a]=e-n[m+1-a],o[a]=n[m+a]-e;let l=0;for(let r=0;r<a;++r){const h=o[r+1],c=s[a-r],u=i[r]/(h+c);i[r]=l+h*u,l=c*u}i[a]=l}return i}function Jn(m,e,t,n){const i=Ct(m,n,e),s=qn(i,n,m,e),o=new p.Vector4(0,0,0,0);for(let a=0;a<=m;++a){const l=t[i-m+a],r=s[a],h=l.w*r;o.x+=l.x*h,o.y+=l.y*h,o.z+=l.z*h,o.w+=l.w*r}return o}function $n(m,e,t,n,i){const s=[];for(let c=0;c<=t;++c)s[c]=0;const o=[];for(let c=0;c<=n;++c)o[c]=s.slice(0);const a=[];for(let c=0;c<=t;++c)a[c]=s.slice(0);a[0][0]=1;const l=s.slice(0),r=s.slice(0);for(let c=1;c<=t;++c){l[c]=e-i[m+1-c],r[c]=i[m+c]-e;let u=0;for(let d=0;d<c;++d){const f=r[d+1],x=l[c-d];a[c][d]=f+x;const y=a[d][c-1]/a[c][d];a[d][c]=u+f*y,u=x*y}a[c][c]=u}for(let c=0;c<=t;++c)o[0][c]=a[c][t];for(let c=0;c<=t;++c){let u=0,d=1;const f=[];for(let x=0;x<=t;++x)f[x]=s.slice(0);f[0][0]=1;for(let x=1;x<=n;++x){let y=0;const R=c-x,I=t-x;c>=x&&(f[d][0]=f[u][0]/a[I+1][R],y=f[d][0]*a[R][I]);const g=R>=-1?1:-R,T=c-1<=I?x-1:t-c;for(let L=g;L<=T;++L)f[d][L]=(f[u][L]-f[u][L-1])/a[I+1][R+L],y+=f[d][L]*a[R+L][I];c<=I&&(f[d][x]=-f[u][x-1]/a[I+1][c],y+=f[d][x]*a[c][I]),o[x][c]=y;const C=u;u=d,d=C}}let h=t;for(let c=1;c<=n;++c){for(let u=0;u<=t;++u)o[c][u]*=h;h*=t-c}return o}function ei(m,e,t,n,i){const s=i<m?i:m,o=[],a=Ct(m,n,e),l=$n(a,n,m,s,e),r=[];for(let h=0;h<t.length;++h){const c=t[h].clone(),u=c.w;c.x*=u,c.y*=u,c.z*=u,r[h]=c}for(let h=0;h<=s;++h){const c=r[a-m].clone().multiplyScalar(l[h][0]);for(let u=1;u<=m;++u)c.add(r[a-m+u].clone().multiplyScalar(l[h][u]));o[h]=c}for(let h=s+1;h<=i+1;++h)o[h]=new p.Vector4(0,0,0);return o}function ti(m,e){let t=1;for(let i=2;i<=m;++i)t*=i;let n=1;for(let i=2;i<=e;++i)n*=i;for(let i=2;i<=m-e;++i)n*=i;return t/n}function ni(m){const e=m.length,t=[],n=[];for(let s=0;s<e;++s){const o=m[s];t[s]=new p.Vector3(o.x,o.y,o.z),n[s]=o.w}const i=[];for(let s=0;s<e;++s){const o=t[s].clone();for(let a=1;a<=s;++a)o.sub(i[s-a].clone().multiplyScalar(ti(s,a)*n[a]));i[s]=o.divideScalar(n[0])}return i}function ii(m,e,t,n,i){const s=ei(m,e,t,n,i);return ni(s)}class si extends p.Curve{constructor(e,t,n,i,s){super();const o=t?t.length-1:0,a=n?n.length:0;this.degree=e,this.knots=t,this.controlPoints=[],this.startKnot=i||0,this.endKnot=s||o;for(let l=0;l<a;++l){const r=n[l];this.controlPoints[l]=new p.Vector4(r.x,r.y,r.z,r.w)}}getPoint(e,t=new p.Vector3){const n=t,i=this.knots[this.startKnot]+e*(this.knots[this.endKnot]-this.knots[this.startKnot]),s=Jn(this.degree,this.knots,this.controlPoints,i);return s.w!==1&&s.divideScalar(s.w),n.set(s.x,s.y,s.z)}getTangent(e,t=new p.Vector3){const n=t,i=this.knots[0]+e*(this.knots[this.knots.length-1]-this.knots[0]),s=ii(this.degree,this.knots,this.controlPoints,i,1);return n.copy(s[1]).normalize(),n}toJSON(){const e=super.toJSON();return e.degree=this.degree,e.knots=[...this.knots],e.controlPoints=this.controlPoints.map(t=>t.toArray()),e.startKnot=this.startKnot,e.endKnot=this.endKnot,e}fromJSON(e){return super.fromJSON(e),this.degree=e.degree,this.knots=[...e.knots],this.controlPoints=e.controlPoints.map(t=>new p.Vector4(t[0],t[1],t[2],t[3])),this.startKnot=e.startKnot,this.endKnot=e.endKnot,this}}let F,Z,$;class it extends p.Loader{constructor(e){super(e)}load(e,t,n,i){const s=this,o=s.path===""?p.LoaderUtils.extractUrlBase(e):s.path,a=new p.FileLoader(this.manager);a.setPath(s.path),a.setResponseType("arraybuffer"),a.setRequestHeader(s.requestHeader),a.setWithCredentials(s.withCredentials),a.load(e,function(l){try{t(s.parse(l,o))}catch(r){i?i(r):console.error(r),s.manager.itemError(e)}},n,i)}parse(e,t){if(hi(e))F=new ci().parse(e);else{const i=zt(e);if(!ui(i))throw new Error("THREE.FBXLoader: Unknown format.");if(gt(i)<7e3)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+gt(i));F=new li().parse(i)}const n=new p.TextureLoader(this.manager).setPath(this.resourcePath||t).setCrossOrigin(this.crossOrigin);return new oi(n,this.manager).parse(F)}}class oi{constructor(e,t){this.textureLoader=e,this.manager=t}parse(){Z=this.parseConnections();const e=this.parseImages(),t=this.parseTextures(e),n=this.parseMaterials(t),i=this.parseDeformers(),s=new ai().parse(i);return this.parseScene(i,s,n),$}parseConnections(){const e=new Map;return"Connections"in F&&F.Connections.connections.forEach(function(n){const i=n[0],s=n[1],o=n[2];e.has(i)||e.set(i,{parents:[],children:[]});const a={ID:s,relationship:o};e.get(i).parents.push(a),e.has(s)||e.set(s,{parents:[],children:[]});const l={ID:i,relationship:o};e.get(s).children.push(l)}),e}parseImages(){const e={},t={};if("Video"in F.Objects){const n=F.Objects.Video;for(const i in n){const s=n[i],o=parseInt(i);if(e[o]=s.RelativeFilename||s.Filename,"Content"in s){const a=s.Content instanceof ArrayBuffer&&s.Content.byteLength>0,l=typeof s.Content=="string"&&s.Content!=="";if(a||l){const r=this.parseImage(n[i]);t[s.RelativeFilename||s.Filename]=r}}}}for(const n in e){const i=e[n];t[i]!==void 0?e[n]=t[i]:e[n]=e[n].split("\\").pop()}return e}parseImage(e){const t=e.Content,n=e.RelativeFilename||e.Filename,i=n.slice(n.lastIndexOf(".")+1).toLowerCase();let s;switch(i){case"bmp":s="image/bmp";break;case"jpg":case"jpeg":s="image/jpeg";break;case"png":s="image/png";break;case"tif":s="image/tiff";break;case"tga":this.manager.getHandler(".tga")===null&&console.warn("FBXLoader: TGA loader not found, skipping ",n),s="image/tga";break;case"webp":s="image/webp";break;default:console.warn('FBXLoader: Image type "'+i+'" is not supported.');return}if(typeof t=="string")return"data:"+s+";base64,"+t;{const o=new Uint8Array(t);return window.URL.createObjectURL(new Blob([o],{type:s}))}}parseTextures(e){const t=new Map;if("Texture"in F.Objects){const n=F.Objects.Texture;for(const i in n){const s=this.parseTexture(n[i],e);t.set(parseInt(i),s)}}return t}parseTexture(e,t){const n=this.loadTexture(e,t);n.ID=e.id,n.name=e.attrName;const i=e.WrapModeU,s=e.WrapModeV,o=i!==void 0?i.value:0,a=s!==void 0?s.value:0;if(n.wrapS=o===0?p.RepeatWrapping:p.ClampToEdgeWrapping,n.wrapT=a===0?p.RepeatWrapping:p.ClampToEdgeWrapping,"Scaling"in e){const l=e.Scaling.value;n.repeat.x=l[0],n.repeat.y=l[1]}if("Translation"in e){const l=e.Translation.value;n.offset.x=l[0],n.offset.y=l[1]}return n}loadTexture(e,t){const n=e.FileName.split(".").pop().toLowerCase();let i=this.manager.getHandler(`.${n}`);i===null&&(i=this.textureLoader);const s=i.path;s||i.setPath(this.textureLoader.path);const o=Z.get(e.id).children;let a;if(o!==void 0&&o.length>0&&t[o[0].ID]!==void 0&&(a=t[o[0].ID],(a.indexOf("blob:")===0||a.indexOf("data:")===0)&&i.setPath(void 0)),a===void 0)return console.warn("FBXLoader: Undefined filename, creating placeholder texture."),new p.Texture;const l=i.load(a);return i.setPath(s),l}parseMaterials(e){const t=new Map;if("Material"in F.Objects){const n=F.Objects.Material;for(const i in n){const s=this.parseMaterial(n[i],e);s!==null&&t.set(parseInt(i),s)}}return t}parseMaterial(e,t){const n=e.id,i=e.attrName;let s=e.ShadingModel;if(typeof s=="object"&&(s=s.value),!Z.has(n))return null;const o=this.parseParameters(e,t,n);let a;switch(s.toLowerCase()){case"phong":a=new p.MeshPhongMaterial;break;case"lambert":a=new p.MeshLambertMaterial;break;default:console.warn('THREE.FBXLoader: unknown material type "%s". Defaulting to MeshPhongMaterial.',s),a=new p.MeshPhongMaterial;break}return a.setValues(o),a.name=i,a}parseParameters(e,t,n){const i={};e.BumpFactor&&(i.bumpScale=e.BumpFactor.value),e.Diffuse?i.color=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(e.Diffuse.value),p.SRGBColorSpace):e.DiffuseColor&&(e.DiffuseColor.type==="Color"||e.DiffuseColor.type==="ColorRGB")&&(i.color=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(e.DiffuseColor.value),p.SRGBColorSpace)),e.DisplacementFactor&&(i.displacementScale=e.DisplacementFactor.value),e.Emissive?i.emissive=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(e.Emissive.value),p.SRGBColorSpace):e.EmissiveColor&&(e.EmissiveColor.type==="Color"||e.EmissiveColor.type==="ColorRGB")&&(i.emissive=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(e.EmissiveColor.value),p.SRGBColorSpace)),e.EmissiveFactor&&(i.emissiveIntensity=parseFloat(e.EmissiveFactor.value)),i.opacity=1-(e.TransparencyFactor?parseFloat(e.TransparencyFactor.value):0),(i.opacity===1||i.opacity===0)&&(i.opacity=e.Opacity?parseFloat(e.Opacity.value):null,i.opacity===null&&(i.opacity=1-(e.TransparentColor?parseFloat(e.TransparentColor.value[0]):0))),i.opacity<1&&(i.transparent=!0),e.ReflectionFactor&&(i.reflectivity=e.ReflectionFactor.value),e.Shininess&&(i.shininess=e.Shininess.value),e.Specular?i.specular=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(e.Specular.value),p.SRGBColorSpace):e.SpecularColor&&e.SpecularColor.type==="Color"&&(i.specular=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(e.SpecularColor.value),p.SRGBColorSpace));const s=this;return Z.get(n).children.forEach(function(o){const a=o.relationship;switch(a){case"Bump":i.bumpMap=s.getTexture(t,o.ID);break;case"Maya|TEX_ao_map":i.aoMap=s.getTexture(t,o.ID);break;case"DiffuseColor":case"Maya|TEX_color_map":i.map=s.getTexture(t,o.ID),i.map!==void 0&&(i.map.colorSpace=p.SRGBColorSpace);break;case"DisplacementColor":i.displacementMap=s.getTexture(t,o.ID);break;case"EmissiveColor":i.emissiveMap=s.getTexture(t,o.ID),i.emissiveMap!==void 0&&(i.emissiveMap.colorSpace=p.SRGBColorSpace);break;case"NormalMap":case"Maya|TEX_normal_map":i.normalMap=s.getTexture(t,o.ID);break;case"ReflectionColor":i.envMap=s.getTexture(t,o.ID),i.envMap!==void 0&&(i.envMap.mapping=p.EquirectangularReflectionMapping,i.envMap.colorSpace=p.SRGBColorSpace);break;case"SpecularColor":i.specularMap=s.getTexture(t,o.ID),i.specularMap!==void 0&&(i.specularMap.colorSpace=p.SRGBColorSpace);break;case"TransparentColor":case"TransparencyFactor":i.alphaMap=s.getTexture(t,o.ID),i.transparent=!0;break;case"AmbientColor":case"ShininessExponent":case"SpecularFactor":case"VectorDisplacementColor":default:console.warn("THREE.FBXLoader: %s map is not supported in three.js, skipping texture.",a);break}}),i}getTexture(e,t){return"LayeredTexture"in F.Objects&&t in F.Objects.LayeredTexture&&(console.warn("THREE.FBXLoader: layered textures are not supported in three.js. Discarding all but first layer."),t=Z.get(t).children[0].ID),e.get(t)}parseDeformers(){const e={},t={};if("Deformer"in F.Objects){const n=F.Objects.Deformer;for(const i in n){const s=n[i],o=Z.get(parseInt(i));if(s.attrType==="Skin"){const a=this.parseSkeleton(o,n);a.ID=i,o.parents.length>1&&console.warn("THREE.FBXLoader: skeleton attached to more than one geometry is not supported."),a.geometryID=o.parents[0].ID,e[i]=a}else if(s.attrType==="BlendShape"){const a={id:i};a.rawTargets=this.parseMorphTargets(o,n),a.id=i,o.parents.length>1&&console.warn("THREE.FBXLoader: morph target attached to more than one geometry is not supported."),t[i]=a}}}return{skeletons:e,morphTargets:t}}parseSkeleton(e,t){const n=[];return e.children.forEach(function(i){const s=t[i.ID];if(s.attrType!=="Cluster")return;const o={ID:i.ID,indices:[],weights:[],transformLink:new p.Matrix4().fromArray(s.TransformLink.a)};"Indexes"in s&&(o.indices=s.Indexes.a,o.weights=s.Weights.a),n.push(o)}),{rawBones:n,bones:[]}}parseMorphTargets(e,t){const n=[];for(let i=0;i<e.children.length;i++){const s=e.children[i],o=t[s.ID],a={name:o.attrName,initialWeight:o.DeformPercent,id:o.id,fullWeights:o.FullWeights.a};if(o.attrType!=="BlendShapeChannel")return;a.geoID=Z.get(parseInt(s.ID)).children.filter(function(l){return l.relationship===void 0})[0].ID,n.push(a)}return n}parseScene(e,t,n){$=new p.Group;const i=this.parseModels(e.skeletons,t,n),s=F.Objects.Model,o=this;i.forEach(function(l){const r=s[l.ID];o.setLookAtProperties(l,r),Z.get(l.ID).parents.forEach(function(c){const u=i.get(c.ID);u!==void 0&&u.add(l)}),l.parent===null&&$.add(l)}),this.bindSkeleton(e.skeletons,t,i),this.addGlobalSceneSettings(),$.traverse(function(l){if(l.userData.transformData){l.parent&&(l.userData.transformData.parentMatrix=l.parent.matrix,l.userData.transformData.parentMatrixWorld=l.parent.matrixWorld);const r=Mt(l.userData.transformData);l.applyMatrix4(r),l.updateWorldMatrix()}});const a=new ri().parse();$.children.length===1&&$.children[0].isGroup&&($.children[0].animations=a,$=$.children[0]),$.animations=a}parseModels(e,t,n){const i=new Map,s=F.Objects.Model;for(const o in s){const a=parseInt(o),l=s[o],r=Z.get(a);let h=this.buildSkeleton(r,e,a,l.attrName);if(!h){switch(l.attrType){case"Camera":h=this.createCamera(r);break;case"Light":h=this.createLight(r);break;case"Mesh":h=this.createMesh(r,t,n);break;case"NurbsCurve":h=this.createCurve(r,t);break;case"LimbNode":case"Root":h=new p.Bone;break;case"Null":default:h=new p.Group;break}h.name=l.attrName?p.PropertyBinding.sanitizeNodeName(l.attrName):"",h.userData.originalName=l.attrName,h.ID=a}this.getTransformData(h,l),i.set(a,h)}return i}buildSkeleton(e,t,n,i){let s=null;return e.parents.forEach(function(o){for(const a in t){const l=t[a];l.rawBones.forEach(function(r,h){if(r.ID===o.ID){const c=s;s=new p.Bone,s.matrixWorld.copy(r.transformLink),s.name=i?p.PropertyBinding.sanitizeNodeName(i):"",s.userData.originalName=i,s.ID=n,l.bones[h]=s,c!==null&&s.add(c)}})}}),s}createCamera(e){let t,n;if(e.children.forEach(function(i){const s=F.Objects.NodeAttribute[i.ID];s!==void 0&&(n=s)}),n===void 0)t=new p.Object3D;else{let i=0;n.CameraProjectionType!==void 0&&n.CameraProjectionType.value===1&&(i=1);let s=1;n.NearPlane!==void 0&&(s=n.NearPlane.value/1e3);let o=1e3;n.FarPlane!==void 0&&(o=n.FarPlane.value/1e3);let a=window.innerWidth,l=window.innerHeight;n.AspectWidth!==void 0&&n.AspectHeight!==void 0&&(a=n.AspectWidth.value,l=n.AspectHeight.value);const r=a/l;let h=45;n.FieldOfView!==void 0&&(h=n.FieldOfView.value);const c=n.FocalLength?n.FocalLength.value:null;switch(i){case 0:t=new p.PerspectiveCamera(h,r,s,o),c!==null&&t.setFocalLength(c);break;case 1:console.warn("THREE.FBXLoader: Orthographic cameras not supported yet."),t=new p.Object3D;break;default:console.warn("THREE.FBXLoader: Unknown camera type "+i+"."),t=new p.Object3D;break}}return t}createLight(e){let t,n;if(e.children.forEach(function(i){const s=F.Objects.NodeAttribute[i.ID];s!==void 0&&(n=s)}),n===void 0)t=new p.Object3D;else{let i;n.LightType===void 0?i=0:i=n.LightType.value;let s=16777215;n.Color!==void 0&&(s=p.ColorManagement.colorSpaceToWorking(new p.Color().fromArray(n.Color.value),p.SRGBColorSpace));let o=n.Intensity===void 0?1:n.Intensity.value/100;n.CastLightOnObject!==void 0&&n.CastLightOnObject.value===0&&(o=0);let a=0;n.FarAttenuationEnd!==void 0&&(n.EnableFarAttenuation!==void 0&&n.EnableFarAttenuation.value===0?a=0:a=n.FarAttenuationEnd.value);const l=1;switch(i){case 0:t=new p.PointLight(s,o,a,l);break;case 1:t=new p.DirectionalLight(s,o);break;case 2:let r=Math.PI/3;n.InnerAngle!==void 0&&(r=p.MathUtils.degToRad(n.InnerAngle.value));let h=0;n.OuterAngle!==void 0&&(h=p.MathUtils.degToRad(n.OuterAngle.value),h=Math.max(h,1)),t=new p.SpotLight(s,o,a,r,h,l);break;default:console.warn("THREE.FBXLoader: Unknown light type "+n.LightType.value+", defaulting to a PointLight."),t=new p.PointLight(s,o);break}n.CastShadows!==void 0&&n.CastShadows.value===1&&(t.castShadow=!0)}return t}createMesh(e,t,n){let i,s=null,o=null;const a=[];if(e.children.forEach(function(l){t.has(l.ID)&&(s=t.get(l.ID)),n.has(l.ID)&&a.push(n.get(l.ID))}),a.length>1?o=a:a.length>0?o=a[0]:(o=new p.MeshPhongMaterial({name:p.Loader.DEFAULT_MATERIAL_NAME,color:13421772}),a.push(o)),"color"in s.attributes&&a.forEach(function(l){l.vertexColors=!0}),s.groups.length>0){let l=!1;for(let r=0,h=s.groups.length;r<h;r++){const c=s.groups[r];(c.materialIndex<0||c.materialIndex>=a.length)&&(c.materialIndex=a.length,l=!0)}if(l){const r=new p.MeshPhongMaterial;a.push(r)}}return s.FBX_Deformer?(i=new p.SkinnedMesh(s,o),i.normalizeSkinWeights()):i=new p.Mesh(s,o),i}createCurve(e,t){const n=e.children.reduce(function(s,o){return t.has(o.ID)&&(s=t.get(o.ID)),s},null),i=new p.LineBasicMaterial({name:p.Loader.DEFAULT_MATERIAL_NAME,color:3342591,linewidth:1});return new p.Line(n,i)}getTransformData(e,t){const n={};"InheritType"in t&&(n.inheritType=parseInt(t.InheritType.value)),"RotationOrder"in t?n.eulerOrder=Me(t.RotationOrder.value):n.eulerOrder=Me(0),"Lcl_Translation"in t&&(n.translation=t.Lcl_Translation.value),"PreRotation"in t&&(n.preRotation=t.PreRotation.value),"Lcl_Rotation"in t&&(n.rotation=t.Lcl_Rotation.value),"PostRotation"in t&&(n.postRotation=t.PostRotation.value),"Lcl_Scaling"in t&&(n.scale=t.Lcl_Scaling.value),"ScalingOffset"in t&&(n.scalingOffset=t.ScalingOffset.value),"ScalingPivot"in t&&(n.scalingPivot=t.ScalingPivot.value),"RotationOffset"in t&&(n.rotationOffset=t.RotationOffset.value),"RotationPivot"in t&&(n.rotationPivot=t.RotationPivot.value),e.userData.transformData=n}setLookAtProperties(e,t){"LookAtProperty"in t&&Z.get(e.ID).children.forEach(function(i){if(i.relationship==="LookAtProperty"){const s=F.Objects.Model[i.ID];if("Lcl_Translation"in s){const o=s.Lcl_Translation.value;e.target!==void 0?(e.target.position.fromArray(o),$.add(e.target)):e.lookAt(new p.Vector3().fromArray(o))}}})}bindSkeleton(e,t,n){const i=this.parsePoseNodes();for(const s in e){const o=e[s];Z.get(parseInt(o.ID)).parents.forEach(function(l){if(t.has(l.ID)){const r=l.ID;Z.get(r).parents.forEach(function(c){n.has(c.ID)&&n.get(c.ID).bind(new p.Skeleton(o.bones),i[c.ID])})}})}}parsePoseNodes(){const e={};if("Pose"in F.Objects){const t=F.Objects.Pose;for(const n in t)if(t[n].attrType==="BindPose"&&t[n].NbPoseNodes>0){const i=t[n].PoseNode;Array.isArray(i)?i.forEach(function(s){e[s.Node]=new p.Matrix4().fromArray(s.Matrix.a)}):e[i.Node]=new p.Matrix4().fromArray(i.Matrix.a)}}return e}addGlobalSceneSettings(){if("GlobalSettings"in F){if("AmbientColor"in F.GlobalSettings){const e=F.GlobalSettings.AmbientColor.value,t=e[0],n=e[1],i=e[2];if(t!==0||n!==0||i!==0){const s=new p.Color().setRGB(t,n,i,p.SRGBColorSpace);$.add(new p.AmbientLight(s,1))}}"UnitScaleFactor"in F.GlobalSettings&&($.userData.unitScaleFactor=F.GlobalSettings.UnitScaleFactor.value)}}}class ai{constructor(){this.negativeMaterialIndices=!1}parse(e){const t=new Map;if("Geometry"in F.Objects){const n=F.Objects.Geometry;for(const i in n){const s=Z.get(parseInt(i)),o=this.parseGeometry(s,n[i],e);t.set(parseInt(i),o)}}return this.negativeMaterialIndices===!0&&console.warn("THREE.FBXLoader: The FBX file contains invalid (negative) material indices. The asset might not render as expected."),t}parseGeometry(e,t,n){switch(t.attrType){case"Mesh":return this.parseMeshGeometry(e,t,n);case"NurbsCurve":return this.parseNurbsGeometry(t)}}parseMeshGeometry(e,t,n){const i=n.skeletons,s=[],o=e.parents.map(function(c){return F.Objects.Model[c.ID]});if(o.length===0)return;const a=e.children.reduce(function(c,u){return i[u.ID]!==void 0&&(c=i[u.ID]),c},null);e.children.forEach(function(c){n.morphTargets[c.ID]!==void 0&&s.push(n.morphTargets[c.ID])});const l=o[0],r={};"RotationOrder"in l&&(r.eulerOrder=Me(l.RotationOrder.value)),"InheritType"in l&&(r.inheritType=parseInt(l.InheritType.value)),"GeometricTranslation"in l&&(r.translation=l.GeometricTranslation.value),"GeometricRotation"in l&&(r.rotation=l.GeometricRotation.value),"GeometricScaling"in l&&(r.scale=l.GeometricScaling.value);const h=Mt(r);return this.genGeometry(t,a,s,h)}genGeometry(e,t,n,i){const s=new p.BufferGeometry;e.attrName&&(s.name=e.attrName);const o=this.parseGeoNode(e,t),a=this.genBuffers(o),l=new p.Float32BufferAttribute(a.vertex,3);if(l.applyMatrix4(i),s.setAttribute("position",l),a.colors.length>0&&s.setAttribute("color",new p.Float32BufferAttribute(a.colors,3)),t&&(s.setAttribute("skinIndex",new p.Uint16BufferAttribute(a.weightsIndices,4)),s.setAttribute("skinWeight",new p.Float32BufferAttribute(a.vertexWeights,4)),s.FBX_Deformer=t),a.normal.length>0){const r=new p.Matrix3().getNormalMatrix(i),h=new p.Float32BufferAttribute(a.normal,3);h.applyNormalMatrix(r),s.setAttribute("normal",h)}if(a.uvs.forEach(function(r,h){const c=h===0?"uv":`uv${h}`;s.setAttribute(c,new p.Float32BufferAttribute(a.uvs[h],2))}),o.material&&o.material.mappingType!=="AllSame"){let r=a.materialIndex[0],h=0;if(a.materialIndex.forEach(function(c,u){c!==r&&(s.addGroup(h,u-h,r),r=c,h=u)}),s.groups.length>0){const c=s.groups[s.groups.length-1],u=c.start+c.count;u!==a.materialIndex.length&&s.addGroup(u,a.materialIndex.length-u,r)}s.groups.length===0&&s.addGroup(0,a.materialIndex.length,a.materialIndex[0])}return this.addMorphTargets(s,e,n,i),s}parseGeoNode(e,t){const n={};if(n.vertexPositions=e.Vertices!==void 0?e.Vertices.a:[],n.vertexIndices=e.PolygonVertexIndex!==void 0?e.PolygonVertexIndex.a:[],e.LayerElementColor&&e.LayerElementColor[0].Colors&&(n.color=this.parseVertexColors(e.LayerElementColor[0])),e.LayerElementMaterial&&(n.material=this.parseMaterialIndices(e.LayerElementMaterial[0])),e.LayerElementNormal&&(n.normal=this.parseNormals(e.LayerElementNormal[0])),e.LayerElementUV){n.uv=[];let i=0;for(;e.LayerElementUV[i];)e.LayerElementUV[i].UV&&n.uv.push(this.parseUVs(e.LayerElementUV[i])),i++}return n.weightTable={},t!==null&&(n.skeleton=t,t.rawBones.forEach(function(i,s){i.indices.forEach(function(o,a){n.weightTable[o]===void 0&&(n.weightTable[o]=[]),n.weightTable[o].push({id:s,weight:i.weights[a]})})})),n}genBuffers(e){const t={vertex:[],normal:[],colors:[],uvs:[],materialIndex:[],vertexWeights:[],weightsIndices:[]};let n=0,i=0,s=!1,o=[],a=[],l=[],r=[],h=[],c=[];const u=this;return e.vertexIndices.forEach(function(d,f){let x,y=!1;d<0&&(d=d^-1,y=!0);let R=[],I=[];if(o.push(d*3,d*3+1,d*3+2),e.color){const g=De(f,n,d,e.color);l.push(g[0],g[1],g[2])}if(e.skeleton){if(e.weightTable[d]!==void 0&&e.weightTable[d].forEach(function(g){I.push(g.weight),R.push(g.id)}),I.length>4){s||(console.warn("THREE.FBXLoader: Vertex has more than 4 skinning weights assigned to vertex. Deleting additional weights."),s=!0);const g=[0,0,0,0],T=[0,0,0,0];I.forEach(function(C,L){let P=C,z=R[L];T.forEach(function(_,U,S){if(P>_){S[U]=P,P=_;const A=g[U];g[U]=z,z=A}})}),R=g,I=T}for(;I.length<4;)I.push(0),R.push(0);for(let g=0;g<4;++g)h.push(I[g]),c.push(R[g])}if(e.normal){const g=De(f,n,d,e.normal);a.push(g[0],g[1],g[2])}e.material&&e.material.mappingType!=="AllSame"&&(x=De(f,n,d,e.material)[0],x<0&&(u.negativeMaterialIndices=!0,x=0)),e.uv&&e.uv.forEach(function(g,T){const C=De(f,n,d,g);r[T]===void 0&&(r[T]=[]),r[T].push(C[0]),r[T].push(C[1])}),i++,y&&(u.genFace(t,e,o,x,a,l,r,h,c,i),n++,i=0,o=[],a=[],l=[],r=[],h=[],c=[])}),t}getNormalNewell(e){const t=new p.Vector3(0,0,0);for(let n=0;n<e.length;n++){const i=e[n],s=e[(n+1)%e.length];t.x+=(i.y-s.y)*(i.z+s.z),t.y+=(i.z-s.z)*(i.x+s.x),t.z+=(i.x-s.x)*(i.y+s.y)}return t.normalize(),t}getNormalTangentAndBitangent(e){const t=this.getNormalNewell(e),i=(Math.abs(t.z)>.5?new p.Vector3(0,1,0):new p.Vector3(0,0,1)).cross(t).normalize(),s=t.clone().cross(i).normalize();return{normal:t,tangent:i,bitangent:s}}flattenVertex(e,t,n){return new p.Vector2(e.dot(t),e.dot(n))}genFace(e,t,n,i,s,o,a,l,r,h){let c;if(h>3){const u=[],d=t.baseVertexPositions||t.vertexPositions;for(let R=0;R<n.length;R+=3)u.push(new p.Vector3(d[n[R]],d[n[R+1]],d[n[R+2]]));const{tangent:f,bitangent:x}=this.getNormalTangentAndBitangent(u),y=[];for(const R of u)y.push(this.flattenVertex(R,f,x));c=p.ShapeUtils.triangulateShape(y,[])}else c=[[0,1,2]];for(const[u,d,f]of c)e.vertex.push(t.vertexPositions[n[u*3]]),e.vertex.push(t.vertexPositions[n[u*3+1]]),e.vertex.push(t.vertexPositions[n[u*3+2]]),e.vertex.push(t.vertexPositions[n[d*3]]),e.vertex.push(t.vertexPositions[n[d*3+1]]),e.vertex.push(t.vertexPositions[n[d*3+2]]),e.vertex.push(t.vertexPositions[n[f*3]]),e.vertex.push(t.vertexPositions[n[f*3+1]]),e.vertex.push(t.vertexPositions[n[f*3+2]]),t.skeleton&&(e.vertexWeights.push(l[u*4]),e.vertexWeights.push(l[u*4+1]),e.vertexWeights.push(l[u*4+2]),e.vertexWeights.push(l[u*4+3]),e.vertexWeights.push(l[d*4]),e.vertexWeights.push(l[d*4+1]),e.vertexWeights.push(l[d*4+2]),e.vertexWeights.push(l[d*4+3]),e.vertexWeights.push(l[f*4]),e.vertexWeights.push(l[f*4+1]),e.vertexWeights.push(l[f*4+2]),e.vertexWeights.push(l[f*4+3]),e.weightsIndices.push(r[u*4]),e.weightsIndices.push(r[u*4+1]),e.weightsIndices.push(r[u*4+2]),e.weightsIndices.push(r[u*4+3]),e.weightsIndices.push(r[d*4]),e.weightsIndices.push(r[d*4+1]),e.weightsIndices.push(r[d*4+2]),e.weightsIndices.push(r[d*4+3]),e.weightsIndices.push(r[f*4]),e.weightsIndices.push(r[f*4+1]),e.weightsIndices.push(r[f*4+2]),e.weightsIndices.push(r[f*4+3])),t.color&&(e.colors.push(o[u*3]),e.colors.push(o[u*3+1]),e.colors.push(o[u*3+2]),e.colors.push(o[d*3]),e.colors.push(o[d*3+1]),e.colors.push(o[d*3+2]),e.colors.push(o[f*3]),e.colors.push(o[f*3+1]),e.colors.push(o[f*3+2])),t.material&&t.material.mappingType!=="AllSame"&&(e.materialIndex.push(i),e.materialIndex.push(i),e.materialIndex.push(i)),t.normal&&(e.normal.push(s[u*3]),e.normal.push(s[u*3+1]),e.normal.push(s[u*3+2]),e.normal.push(s[d*3]),e.normal.push(s[d*3+1]),e.normal.push(s[d*3+2]),e.normal.push(s[f*3]),e.normal.push(s[f*3+1]),e.normal.push(s[f*3+2])),t.uv&&t.uv.forEach(function(x,y){e.uvs[y]===void 0&&(e.uvs[y]=[]),e.uvs[y].push(a[y][u*2]),e.uvs[y].push(a[y][u*2+1]),e.uvs[y].push(a[y][d*2]),e.uvs[y].push(a[y][d*2+1]),e.uvs[y].push(a[y][f*2]),e.uvs[y].push(a[y][f*2+1])})}addMorphTargets(e,t,n,i){if(n.length===0)return;e.morphTargetsRelative=!0,e.morphAttributes.position=[];const s=this;n.forEach(function(o){o.rawTargets.forEach(function(a){const l=F.Objects.Geometry[a.geoID];l!==void 0&&s.genMorphGeometry(e,t,l,i,a.name)})})}genMorphGeometry(e,t,n,i,s){const o=t.Vertices!==void 0?t.Vertices.a:[],a=t.PolygonVertexIndex!==void 0?t.PolygonVertexIndex.a:[],l=n.Vertices!==void 0?n.Vertices.a:[],r=n.Indexes!==void 0?n.Indexes.a:[],h=e.attributes.position.count*3,c=new Float32Array(h);for(let x=0;x<r.length;x++){const y=r[x]*3;c[y]=l[x*3],c[y+1]=l[x*3+1],c[y+2]=l[x*3+2]}const u={vertexIndices:a,vertexPositions:c,baseVertexPositions:o},d=this.genBuffers(u),f=new p.Float32BufferAttribute(d.vertex,3);f.name=s||n.attrName,f.applyMatrix4(i),e.morphAttributes.position.push(f)}parseNormals(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,i=e.Normals.a;let s=[];return n==="IndexToDirect"&&("NormalIndex"in e?s=e.NormalIndex.a:"NormalsIndex"in e&&(s=e.NormalsIndex.a)),{dataSize:3,buffer:i,indices:s,mappingType:t,referenceType:n}}parseUVs(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,i=e.UV.a;let s=[];return n==="IndexToDirect"&&(s=e.UVIndex.a),{dataSize:2,buffer:i,indices:s,mappingType:t,referenceType:n}}parseVertexColors(e){const t=e.MappingInformationType,n=e.ReferenceInformationType,i=e.Colors.a;let s=[];n==="IndexToDirect"&&(s=e.ColorIndex.a);for(let o=0,a=new p.Color;o<i.length;o+=4)a.fromArray(i,o),p.ColorManagement.colorSpaceToWorking(a,p.SRGBColorSpace),a.toArray(i,o);return{dataSize:4,buffer:i,indices:s,mappingType:t,referenceType:n}}parseMaterialIndices(e){const t=e.MappingInformationType,n=e.ReferenceInformationType;if(t==="NoMappingInformation")return{dataSize:1,buffer:[0],indices:[0],mappingType:"AllSame",referenceType:n};const i=e.Materials.a,s=[];for(let o=0;o<i.length;++o)s.push(o);return{dataSize:1,buffer:i,indices:s,mappingType:t,referenceType:n}}parseNurbsGeometry(e){const t=parseInt(e.Order);if(isNaN(t))return console.error("THREE.FBXLoader: Invalid Order %s given for geometry ID: %s",e.Order,e.id),new p.BufferGeometry;const n=t-1,i=e.KnotVector.a,s=[],o=e.Points.a;for(let c=0,u=o.length;c<u;c+=4)s.push(new p.Vector4().fromArray(o,c));let a,l;if(e.Form==="Closed")s.push(s[0]);else if(e.Form==="Periodic"){a=n,l=i.length-1-a;for(let c=0;c<n;++c)s.push(s[c])}const h=new si(n,i,s,a,l).getPoints(s.length*12);return new p.BufferGeometry().setFromPoints(h)}}class ri{parse(){const e=[],t=this.parseClips();if(t!==void 0)for(const n in t){const i=t[n],s=this.addClip(i);e.push(s)}return e}parseClips(){if(F.Objects.AnimationCurve===void 0)return;const e=this.parseAnimationCurveNodes();this.parseAnimationCurves(e);const t=this.parseAnimationLayers(e);return this.parseAnimStacks(t)}parseAnimationCurveNodes(){const e=F.Objects.AnimationCurveNode,t=new Map;for(const n in e){const i=e[n];if(i.attrName.match(/S|R|T|DeformPercent/)!==null){const s={id:i.id,attr:i.attrName,curves:{}};t.set(s.id,s)}}return t}parseAnimationCurves(e){const t=F.Objects.AnimationCurve;for(const n in t){const i={id:t[n].id,times:t[n].KeyTime.a.map(di),values:t[n].KeyValueFloat.a},s=Z.get(i.id);if(s!==void 0){const o=s.parents[0].ID,a=s.parents[0].relationship;a.match(/X/)?e.get(o).curves.x=i:a.match(/Y/)?e.get(o).curves.y=i:a.match(/Z/)?e.get(o).curves.z=i:a.match(/DeformPercent/)&&e.has(o)&&(e.get(o).curves.morph=i)}}}parseAnimationLayers(e){const t=F.Objects.AnimationLayer,n=new Map;for(const i in t){const s=[],o=Z.get(parseInt(i));o!==void 0&&(o.children.forEach(function(l,r){if(e.has(l.ID)){const h=e.get(l.ID);if(h.curves.x!==void 0||h.curves.y!==void 0||h.curves.z!==void 0){if(s[r]===void 0){const c=Z.get(l.ID).parents.filter(function(u){return u.relationship!==void 0})[0].ID;if(c!==void 0){const u=F.Objects.Model[c.toString()];if(u===void 0){console.warn("THREE.FBXLoader: Encountered a unused curve.",l);return}const d={modelName:u.attrName?p.PropertyBinding.sanitizeNodeName(u.attrName):"",ID:u.id,initialPosition:[0,0,0],initialRotation:[0,0,0],initialScale:[1,1,1]};$.traverse(function(f){f.ID===u.id&&(d.transform=f.matrix,f.userData.transformData&&(d.eulerOrder=f.userData.transformData.eulerOrder))}),d.transform||(d.transform=new p.Matrix4),"PreRotation"in u&&(d.preRotation=u.PreRotation.value),"PostRotation"in u&&(d.postRotation=u.PostRotation.value),s[r]=d}}s[r]&&(s[r][h.attr]=h)}else if(h.curves.morph!==void 0){if(s[r]===void 0){const c=Z.get(l.ID).parents.filter(function(R){return R.relationship!==void 0})[0].ID,u=Z.get(c).parents[0].ID,d=Z.get(u).parents[0].ID,f=Z.get(d).parents[0].ID,x=F.Objects.Model[f],y={modelName:x.attrName?p.PropertyBinding.sanitizeNodeName(x.attrName):"",morphName:F.Objects.Deformer[c].attrName};s[r]=y}s[r][h.attr]=h}}}),n.set(parseInt(i),s))}return n}parseAnimStacks(e){const t=F.Objects.AnimationStack,n={};for(const i in t){const s=Z.get(parseInt(i)).children;s.length>1&&console.warn("THREE.FBXLoader: Encountered an animation stack with multiple layers, this is currently not supported. Ignoring subsequent layers.");const o=e.get(s[0].ID);n[i]={name:t[i].attrName,layer:o}}return n}addClip(e){let t=[];const n=this;return e.layer.forEach(function(i){t=t.concat(n.generateTracks(i))}),new p.AnimationClip(e.name,-1,t)}generateTracks(e){const t=[];let n=new p.Vector3,i=new p.Vector3;if(e.transform&&e.transform.decompose(n,new p.Quaternion,i),n=n.toArray(),i=i.toArray(),e.T!==void 0&&Object.keys(e.T.curves).length>0){const s=this.generateVectorTrack(e.modelName,e.T.curves,n,"position");s!==void 0&&t.push(s)}if(e.R!==void 0&&Object.keys(e.R.curves).length>0){const s=this.generateRotationTrack(e.modelName,e.R.curves,e.preRotation,e.postRotation,e.eulerOrder);s!==void 0&&t.push(s)}if(e.S!==void 0&&Object.keys(e.S.curves).length>0){const s=this.generateVectorTrack(e.modelName,e.S.curves,i,"scale");s!==void 0&&t.push(s)}if(e.DeformPercent!==void 0){const s=this.generateMorphTrack(e);s!==void 0&&t.push(s)}return t}generateVectorTrack(e,t,n,i){const s=this.getTimesForAllAxes(t),o=this.getKeyframeTrackValues(s,t,n);return new p.VectorKeyframeTrack(e+"."+i,s,o)}generateRotationTrack(e,t,n,i,s){let o,a;if(t.x!==void 0&&t.y!==void 0&&t.z!==void 0){const u=this.interpolateRotations(t.x,t.y,t.z,s);o=u[0],a=u[1]}const l=Me(0);n!==void 0&&(n=n.map(p.MathUtils.degToRad),n.push(l),n=new p.Euler().fromArray(n),n=new p.Quaternion().setFromEuler(n)),i!==void 0&&(i=i.map(p.MathUtils.degToRad),i.push(l),i=new p.Euler().fromArray(i),i=new p.Quaternion().setFromEuler(i).invert());const r=new p.Quaternion,h=new p.Euler,c=[];if(!a||!o)return new p.QuaternionKeyframeTrack(e+".quaternion",[0],[0]);for(let u=0;u<a.length;u+=3)h.set(a[u],a[u+1],a[u+2],s),r.setFromEuler(h),n!==void 0&&r.premultiply(n),i!==void 0&&r.multiply(i),u>2&&new p.Quaternion().fromArray(c,(u-3)/3*4).dot(r)<0&&r.set(-r.x,-r.y,-r.z,-r.w),r.toArray(c,u/3*4);return new p.QuaternionKeyframeTrack(e+".quaternion",o,c)}generateMorphTrack(e){const t=e.DeformPercent.curves.morph,n=t.values.map(function(s){return s/100}),i=$.getObjectByName(e.modelName).morphTargetDictionary[e.morphName];return new p.NumberKeyframeTrack(e.modelName+".morphTargetInfluences["+i+"]",t.times,n)}getTimesForAllAxes(e){let t=[];if(e.x!==void 0&&(t=t.concat(e.x.times)),e.y!==void 0&&(t=t.concat(e.y.times)),e.z!==void 0&&(t=t.concat(e.z.times)),t=t.sort(function(n,i){return n-i}),t.length>1){let n=1,i=t[0];for(let s=1;s<t.length;s++){const o=t[s];o!==i&&(t[n]=o,i=o,n++)}t=t.slice(0,n)}return t}getKeyframeTrackValues(e,t,n){const i=n,s=[];let o=-1,a=-1,l=-1;return e.forEach(function(r){if(t.x&&(o=t.x.times.indexOf(r)),t.y&&(a=t.y.times.indexOf(r)),t.z&&(l=t.z.times.indexOf(r)),o!==-1){const h=t.x.values[o];s.push(h),i[0]=h}else s.push(i[0]);if(a!==-1){const h=t.y.values[a];s.push(h),i[1]=h}else s.push(i[1]);if(l!==-1){const h=t.z.values[l];s.push(h),i[2]=h}else s.push(i[2])}),s}interpolateRotations(e,t,n,i){const s=[],o=[];s.push(e.times[0]),o.push(p.MathUtils.degToRad(e.values[0])),o.push(p.MathUtils.degToRad(t.values[0])),o.push(p.MathUtils.degToRad(n.values[0]));for(let a=1;a<e.values.length;a++){const l=[e.values[a-1],t.values[a-1],n.values[a-1]];if(isNaN(l[0])||isNaN(l[1])||isNaN(l[2]))continue;const r=l.map(p.MathUtils.degToRad),h=[e.values[a],t.values[a],n.values[a]];if(isNaN(h[0])||isNaN(h[1])||isNaN(h[2]))continue;const c=h.map(p.MathUtils.degToRad),u=[h[0]-l[0],h[1]-l[1],h[2]-l[2]],d=[Math.abs(u[0]),Math.abs(u[1]),Math.abs(u[2])];if(d[0]>=180||d[1]>=180||d[2]>=180){const x=Math.max(...d)/180,y=new p.Euler(...r,i),R=new p.Euler(...c,i),I=new p.Quaternion().setFromEuler(y),g=new p.Quaternion().setFromEuler(R);I.dot(g)&&g.set(-g.x,-g.y,-g.z,-g.w);const T=e.times[a-1],C=e.times[a]-T,L=new p.Quaternion,P=new p.Euler;for(let z=0;z<1;z+=1/x)L.copy(I.clone().slerp(g.clone(),z)),s.push(T+z*C),P.setFromQuaternion(L,i),o.push(P.x),o.push(P.y),o.push(P.z)}else s.push(e.times[a]),o.push(p.MathUtils.degToRad(e.values[a])),o.push(p.MathUtils.degToRad(t.values[a])),o.push(p.MathUtils.degToRad(n.values[a]))}return[s,o]}}class li{getPrevNode(){return this.nodeStack[this.currentIndent-2]}getCurrentNode(){return this.nodeStack[this.currentIndent-1]}getCurrentProp(){return this.currentProp}pushStack(e){this.nodeStack.push(e),this.currentIndent+=1}popStack(){this.nodeStack.pop(),this.currentIndent-=1}setCurrentProp(e,t){this.currentProp=e,this.currentPropName=t}parse(e){this.currentIndent=0,this.allNodes=new Et,this.nodeStack=[],this.currentProp=[],this.currentPropName="";const t=this,n=e.split(/[\r\n]+/);return n.forEach(function(i,s){const o=i.match(/^[\s\t]*;/),a=i.match(/^[\s\t]*$/);if(o||a)return;const l=i.match("^\\t{"+t.currentIndent+"}(\\w+):(.*){",""),r=i.match("^\\t{"+t.currentIndent+"}(\\w+):[\\s\\t\\r\\n](.*)"),h=i.match("^\\t{"+(t.currentIndent-1)+"}}");l?t.parseNodeBegin(i,l):r?t.parseNodeProperty(i,r,n[++s]):h?t.popStack():i.match(/^[^\s\t}]/)&&t.parseNodePropertyContinued(i)}),this.allNodes}parseNodeBegin(e,t){const n=t[1].trim().replace(/^"/,"").replace(/"$/,""),i=t[2].split(",").map(function(l){return l.trim().replace(/^"/,"").replace(/"$/,"")}),s={name:n},o=this.parseNodeAttr(i),a=this.getCurrentNode();this.currentIndent===0?this.allNodes.add(n,s):n in a?(n==="PoseNode"?a.PoseNode.push(s):a[n].id!==void 0&&(a[n]={},a[n][a[n].id]=a[n]),o.id!==""&&(a[n][o.id]=s)):typeof o.id=="number"?(a[n]={},a[n][o.id]=s):n!=="Properties70"&&(n==="PoseNode"?a[n]=[s]:a[n]=s),typeof o.id=="number"&&(s.id=o.id),o.name!==""&&(s.attrName=o.name),o.type!==""&&(s.attrType=o.type),this.pushStack(s)}parseNodeAttr(e){let t=e[0];e[0]!==""&&(t=parseInt(e[0]),isNaN(t)&&(t=e[0]));let n="",i="";return e.length>1&&(n=e[1].replace(/^(\w+)::/,""),i=e[2]),{id:t,name:n,type:i}}parseNodeProperty(e,t,n){let i=t[1].replace(/^"/,"").replace(/"$/,"").trim(),s=t[2].replace(/^"/,"").replace(/"$/,"").trim();i==="Content"&&s===","&&(s=n.replace(/"/g,"").replace(/,$/,"").trim());const o=this.getCurrentNode();if(o.name==="Properties70"){this.parseNodeSpecialProperty(e,i,s);return}if(i==="C"){const l=s.split(",").slice(1),r=parseInt(l[0]),h=parseInt(l[1]);let c=s.split(",").slice(3);c=c.map(function(u){return u.trim().replace(/^"/,"")}),i="connections",s=[r,h],mi(s,c),o[i]===void 0&&(o[i]=[])}i==="Node"&&(o.id=s),i in o&&Array.isArray(o[i])?o[i].push(s):i!=="a"?o[i]=s:o.a=s,this.setCurrentProp(o,i),i==="a"&&s.slice(-1)!==","&&(o.a=$e(s))}parseNodePropertyContinued(e){const t=this.getCurrentNode();t.a+=e,e.slice(-1)!==","&&(t.a=$e(t.a))}parseNodeSpecialProperty(e,t,n){const i=n.split('",').map(function(h){return h.trim().replace(/^\"/,"").replace(/\s/,"_")}),s=i[0],o=i[1],a=i[2],l=i[3];let r=i[4];switch(o){case"int":case"enum":case"bool":case"ULongLong":case"double":case"Number":case"FieldOfView":r=parseFloat(r);break;case"Color":case"ColorRGB":case"Vector3D":case"Lcl_Translation":case"Lcl_Rotation":case"Lcl_Scaling":r=$e(r);break}this.getPrevNode()[s]={type:o,type2:a,flag:l,value:r},this.setCurrentProp(this.getPrevNode(),s)}}class ci{parse(e){const t=new ft(e);t.skip(23);const n=t.getUint32();if(n<6400)throw new Error("THREE.FBXLoader: FBX version not supported, FileVersion: "+n);const i=new Et;for(;!this.endOfContent(t);){const s=this.parseNode(t,n);s!==null&&i.add(s.name,s)}return i}endOfContent(e){return e.size()%16===0?(e.getOffset()+160+16&-16)>=e.size():e.getOffset()+160+16>=e.size()}parseNode(e,t){const n={},i=t>=7500?e.getUint64():e.getUint32(),s=t>=7500?e.getUint64():e.getUint32();t>=7500?e.getUint64():e.getUint32();const o=e.getUint8(),a=e.getString(o);if(i===0)return null;const l=[];for(let u=0;u<s;u++)l.push(this.parseProperty(e));const r=l.length>0?l[0]:"",h=l.length>1?l[1]:"",c=l.length>2?l[2]:"";for(n.singleProperty=s===1&&e.getOffset()===i;i>e.getOffset();){const u=this.parseNode(e,t);u!==null&&this.parseSubNode(a,n,u)}return n.propertyList=l,typeof r=="number"&&(n.id=r),h!==""&&(n.attrName=h),c!==""&&(n.attrType=c),a!==""&&(n.name=a),n}parseSubNode(e,t,n){if(n.singleProperty===!0){const i=n.propertyList[0];Array.isArray(i)?(t[n.name]=n,n.a=i):t[n.name]=i}else if(e==="Connections"&&n.name==="C"){const i=[];n.propertyList.forEach(function(s,o){o!==0&&i.push(s)}),t.connections===void 0&&(t.connections=[]),t.connections.push(i)}else if(n.name==="Properties70")Object.keys(n).forEach(function(s){t[s]=n[s]});else if(e==="Properties70"&&n.name==="P"){let i=n.propertyList[0],s=n.propertyList[1];const o=n.propertyList[2],a=n.propertyList[3];let l;i.indexOf("Lcl ")===0&&(i=i.replace("Lcl ","Lcl_")),s.indexOf("Lcl ")===0&&(s=s.replace("Lcl ","Lcl_")),s==="Color"||s==="ColorRGB"||s==="Vector"||s==="Vector3D"||s.indexOf("Lcl_")===0?l=[n.propertyList[4],n.propertyList[5],n.propertyList[6]]:l=n.propertyList[4],t[i]={type:s,type2:o,flag:a,value:l}}else t[n.name]===void 0?typeof n.id=="number"?(t[n.name]={},t[n.name][n.id]=n):t[n.name]=n:n.name==="PoseNode"?(Array.isArray(t[n.name])||(t[n.name]=[t[n.name]]),t[n.name].push(n)):t[n.name][n.id]===void 0&&(t[n.name][n.id]=n)}parseProperty(e){const t=e.getString(1);let n;switch(t){case"C":return e.getBoolean();case"D":return e.getFloat64();case"F":return e.getFloat32();case"I":return e.getInt32();case"L":return e.getInt64();case"R":return n=e.getUint32(),e.getArrayBuffer(n);case"S":return n=e.getUint32(),e.getString(n);case"Y":return e.getInt16();case"b":case"c":case"d":case"f":case"i":case"l":const i=e.getUint32(),s=e.getUint32(),o=e.getUint32();if(s===0)switch(t){case"b":case"c":return e.getBooleanArray(i);case"d":return e.getFloat64Array(i);case"f":return e.getFloat32Array(i);case"i":return e.getInt32Array(i);case"l":return e.getInt64Array(i)}const a=Yn(new Uint8Array(e.getArrayBuffer(o))),l=new ft(a.buffer);switch(t){case"b":case"c":return l.getBooleanArray(i);case"d":return l.getFloat64Array(i);case"f":return l.getFloat32Array(i);case"i":return l.getInt32Array(i);case"l":return l.getInt64Array(i)}break;default:throw new Error("THREE.FBXLoader: Unknown property type "+t)}}}class ft{constructor(e,t){this.dv=new DataView(e),this.offset=0,this.littleEndian=t!==void 0?t:!0,this._textDecoder=new TextDecoder}getOffset(){return this.offset}size(){return this.dv.buffer.byteLength}skip(e){this.offset+=e}getBoolean(){return(this.getUint8()&1)===1}getBooleanArray(e){const t=[];for(let n=0;n<e;n++)t.push(this.getBoolean());return t}getUint8(){const e=this.dv.getUint8(this.offset);return this.offset+=1,e}getInt16(){const e=this.dv.getInt16(this.offset,this.littleEndian);return this.offset+=2,e}getInt32(){const e=this.dv.getInt32(this.offset,this.littleEndian);return this.offset+=4,e}getInt32Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getInt32());return t}getUint32(){const e=this.dv.getUint32(this.offset,this.littleEndian);return this.offset+=4,e}getInt64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),t&2147483648?(t=~t&4294967295,e=~e&4294967295,e===4294967295&&(t=t+1&4294967295),e=e+1&4294967295,-(t*4294967296+e)):t*4294967296+e}getInt64Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getInt64());return t}getUint64(){let e,t;return this.littleEndian?(e=this.getUint32(),t=this.getUint32()):(t=this.getUint32(),e=this.getUint32()),t*4294967296+e}getFloat32(){const e=this.dv.getFloat32(this.offset,this.littleEndian);return this.offset+=4,e}getFloat32Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getFloat32());return t}getFloat64(){const e=this.dv.getFloat64(this.offset,this.littleEndian);return this.offset+=8,e}getFloat64Array(e){const t=[];for(let n=0;n<e;n++)t.push(this.getFloat64());return t}getArrayBuffer(e){const t=this.dv.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}getString(e){const t=this.offset;let n=new Uint8Array(this.dv.buffer,t,e);this.skip(e);const i=n.indexOf(0);return i>=0&&(n=new Uint8Array(this.dv.buffer,t,i)),this._textDecoder.decode(n)}}class Et{add(e,t){this[e]=t}}function hi(m){const e="Kaydara FBX Binary \0";return m.byteLength>=e.length&&e===zt(m,0,e.length)}function ui(m){const e=["K","a","y","d","a","r","a","\\","F","B","X","\\","B","i","n","a","r","y","\\","\\"];let t=0;function n(i){const s=m[i-1];return m=m.slice(t+i),t++,s}for(let i=0;i<e.length;++i)if(n(1)===e[i])return!1;return!0}function gt(m){const e=/FBXVersion: (\d+)/,t=m.match(e);if(t)return parseInt(t[1]);throw new Error("THREE.FBXLoader: Cannot find the version number for the file given.")}function di(m){return m/46186158e3}const pi=[];function De(m,e,t,n){let i;switch(n.mappingType){case"ByPolygonVertex":i=m;break;case"ByPolygon":i=e;break;case"ByVertice":i=t;break;case"AllSame":i=n.indices[0];break;default:console.warn("THREE.FBXLoader: unknown attribute mapping type "+n.mappingType)}n.referenceType==="IndexToDirect"&&(i=n.indices[i]);const s=i*n.dataSize,o=s+n.dataSize;return fi(pi,n.buffer,s,o)}const Je=new p.Euler,Ae=new p.Vector3;function Mt(m){const e=new p.Matrix4,t=new p.Matrix4,n=new p.Matrix4,i=new p.Matrix4,s=new p.Matrix4,o=new p.Matrix4,a=new p.Matrix4,l=new p.Matrix4,r=new p.Matrix4,h=new p.Matrix4,c=new p.Matrix4,u=new p.Matrix4,d=m.inheritType?m.inheritType:0;m.translation&&e.setPosition(Ae.fromArray(m.translation));const f=Me(0);if(m.preRotation){const S=m.preRotation.map(p.MathUtils.degToRad);S.push(f),t.makeRotationFromEuler(Je.fromArray(S))}if(m.rotation){const S=m.rotation.map(p.MathUtils.degToRad);S.push(m.eulerOrder||f),n.makeRotationFromEuler(Je.fromArray(S))}if(m.postRotation){const S=m.postRotation.map(p.MathUtils.degToRad);S.push(f),i.makeRotationFromEuler(Je.fromArray(S)),i.invert()}m.scale&&s.scale(Ae.fromArray(m.scale)),m.scalingOffset&&a.setPosition(Ae.fromArray(m.scalingOffset)),m.scalingPivot&&o.setPosition(Ae.fromArray(m.scalingPivot)),m.rotationOffset&&l.setPosition(Ae.fromArray(m.rotationOffset)),m.rotationPivot&&r.setPosition(Ae.fromArray(m.rotationPivot)),m.parentMatrixWorld&&(c.copy(m.parentMatrix),h.copy(m.parentMatrixWorld));const x=t.clone().multiply(n).multiply(i),y=new p.Matrix4;y.extractRotation(h);const R=new p.Matrix4;R.copyPosition(h);const I=R.clone().invert().multiply(h),g=y.clone().invert().multiply(I),T=s,C=new p.Matrix4;if(d===0)C.copy(y).multiply(x).multiply(g).multiply(T);else if(d===1)C.copy(y).multiply(g).multiply(x).multiply(T);else{const A=new p.Matrix4().scale(new p.Vector3().setFromMatrixScale(c)).clone().invert(),w=g.clone().multiply(A);C.copy(y).multiply(x).multiply(w).multiply(T)}const L=r.clone().invert(),P=o.clone().invert();let z=e.clone().multiply(l).multiply(r).multiply(t).multiply(n).multiply(i).multiply(L).multiply(a).multiply(o).multiply(s).multiply(P);const _=new p.Matrix4().copyPosition(z),U=h.clone().multiply(_);return u.copyPosition(U),z=u.clone().multiply(C),z.premultiply(h.invert()),z}function Me(m){m=m||0;const e=["ZYX","YZX","XZY","ZXY","YXZ","XYZ"];return m===6?(console.warn("THREE.FBXLoader: unsupported Euler Order: Spherical XYZ. Animations and rotations may be incorrect."),e[0]):e[m]}function $e(m){return m.split(",").map(function(t){return parseFloat(t)})}function zt(m,e,t){return e===void 0&&(e=0),t===void 0&&(t=m.byteLength),new TextDecoder().decode(new Uint8Array(m,e,t))}function mi(m,e){for(let t=0,n=m.length,i=e.length;t<i;t++,n++)m[n]=e[t]}function fi(m,e,t,n){for(let i=t,s=0;i<n;i++,s++)m[s]=e[i];return m}class gi extends p.Scene{constructor(){super();const e=new p.BoxGeometry;e.deleteAttribute("uv");const t=new p.MeshStandardMaterial({side:p.BackSide}),n=new p.MeshStandardMaterial,i=new p.PointLight(16777215,900,28,2);i.position.set(.418,16.199,.3),this.add(i);const s=new p.Mesh(e,t);s.position.set(-.757,13.219,.717),s.scale.set(31.713,28.305,28.591),this.add(s);const o=new p.InstancedMesh(e,n,6),a=new p.Object3D;a.position.set(-10.906,2.009,1.846),a.rotation.set(0,-.195,0),a.scale.set(2.328,7.905,4.651),a.updateMatrix(),o.setMatrixAt(0,a.matrix),a.position.set(-5.607,-.754,-.758),a.rotation.set(0,.994,0),a.scale.set(1.97,1.534,3.955),a.updateMatrix(),o.setMatrixAt(1,a.matrix),a.position.set(6.167,.857,7.803),a.rotation.set(0,.561,0),a.scale.set(3.927,6.285,3.687),a.updateMatrix(),o.setMatrixAt(2,a.matrix),a.position.set(-2.017,.018,6.124),a.rotation.set(0,.333,0),a.scale.set(2.002,4.566,2.064),a.updateMatrix(),o.setMatrixAt(3,a.matrix),a.position.set(2.291,-.756,-2.621),a.rotation.set(0,-.286,0),a.scale.set(1.546,1.552,1.496),a.updateMatrix(),o.setMatrixAt(4,a.matrix),a.position.set(-2.193,-.369,-5.547),a.rotation.set(0,.516,0),a.scale.set(3.875,3.487,2.986),a.updateMatrix(),o.setMatrixAt(5,a.matrix),this.add(o);const l=new p.Mesh(e,Le(50));l.position.set(-16.116,14.37,8.208),l.scale.set(.1,2.428,2.739),this.add(l);const r=new p.Mesh(e,Le(50));r.position.set(-16.109,18.021,-8.207),r.scale.set(.1,2.425,2.751),this.add(r);const h=new p.Mesh(e,Le(17));h.position.set(14.904,12.198,-1.832),h.scale.set(.15,4.265,6.331),this.add(h);const c=new p.Mesh(e,Le(43));c.position.set(-.462,8.89,14.52),c.scale.set(4.38,5.441,.088),this.add(c);const u=new p.Mesh(e,Le(20));u.position.set(3.235,11.486,-12.541),u.scale.set(2.5,2,.1),this.add(u);const d=new p.Mesh(e,Le(100));d.position.set(0,20,0),d.scale.set(1,.1,1),this.add(d)}dispose(){const e=new Set;this.traverse(t=>{t.isMesh&&(e.add(t.geometry),e.add(t.material))});for(const t of e)t.dispose()}}function Le(m){return new p.MeshLambertMaterial({color:0,emissive:16777215,emissiveIntensity:m})}var Ee=function(){var m=0,e=document.createElement("div");e.style.cssText="position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000",e.addEventListener("click",function(h){h.preventDefault(),n(++m%e.children.length)},!1);function t(h){return e.appendChild(h.dom),h}function n(h){for(var c=0;c<e.children.length;c++)e.children[c].style.display=c===h?"block":"none";m=h}var i=(performance||Date).now(),s=i,o=0,a=t(new Ee.Panel("FPS","#0ff","#002")),l=t(new Ee.Panel("MS","#0f0","#020"));if(self.performance&&self.performance.memory)var r=t(new Ee.Panel("MB","#f08","#201"));return n(0),{REVISION:16,dom:e,addPanel:t,showPanel:n,begin:function(){i=(performance||Date).now()},end:function(){o++;var h=(performance||Date).now();if(l.update(h-i,200),h>=s+1e3&&(a.update(o*1e3/(h-s),100),s=h,o=0,r)){var c=performance.memory;r.update(c.usedJSHeapSize/1048576,c.jsHeapSizeLimit/1048576)}return h},update:function(){i=this.end()},domElement:e,setMode:n}};Ee.Panel=function(m,e,t){var n=1/0,i=0,s=Math.round,o=s(window.devicePixelRatio||1),a=80*o,l=48*o,r=3*o,h=2*o,c=3*o,u=15*o,d=74*o,f=30*o,x=document.createElement("canvas");x.width=a,x.height=l,x.style.cssText="width:80px;height:48px";var y=x.getContext("2d");return y.font="bold "+9*o+"px Helvetica,Arial,sans-serif",y.textBaseline="top",y.fillStyle=t,y.fillRect(0,0,a,l),y.fillStyle=e,y.fillText(m,r,h),y.fillRect(c,u,d,f),y.fillStyle=t,y.globalAlpha=.9,y.fillRect(c,u,d,f),{dom:x,update:function(R,I){n=Math.min(n,R),i=Math.max(i,R),y.fillStyle=t,y.globalAlpha=1,y.fillRect(0,0,a,u),y.fillStyle=e,y.fillText(s(R)+" "+m+" ("+s(n)+"-"+s(i)+")",r,h),y.drawImage(x,c+o,u,d-o,f,c,u,d-o,f),y.fillRect(c+d-o,u,o,f),y.fillStyle=t,y.globalAlpha=.9,y.fillRect(c+d-o,u,o,s((1-R/I)*f))}}};let b,ne,ie;const k=[0,0,0,0],H=new v.Vector3,Oe=new v.Vector3,q=new v.Vector3,_e=new v.Vector3;new v.Plane;new v.Ray;new v.Euler;const J=new v.Quaternion,yt=new v.Quaternion,ce=new v.Matrix4,he=new v.Matrix4;new v.Vector3;const Ne=new v.Vector3(0,0,1),yi=new v.Vector3(1,0,0),xi=new v.Vector3(0,1,0),bi=new v.Vector3(0,0,1);class Ri{constructor(e=null){this.opt=Object.assign({warmupMs:2e3,sensitivityFactor:1,movementFactor:1,isExcludes:!0,isPivots:!0,isLimits:!0,helperBoneColor1:16711680,helperBoneColor2:16238028,helperLinkColor1:16711680,helperLinkColor2:255,helperExcludesColor:11184895},e||{}),this.scene=null,this.armature=null,this.config=[],this.data=[],this.dict={},this.objectsUpdate=[],this.helpers={isActive:!1,isShowAll:!1,points:{bones:[],pivots:[],object:null},lines:{bones:[],object:null},excludes:{bones:[],deltaLocals:[],radii:[],objects:[]}},this.running=!1,this.timerMs=0}getOptionValue(e){return this.opt[e]}setOptionValue(e,t){this.opt[e]=t,this.helpers.isActive&&this.showHelpers()}getBoneNames(){return this.data.map(e=>e.name)}getValue(e,t){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");if(!this.dict.hasOwnProperty(e))throw new Error("Dynamic bone '"+e+"' not found.");const n=this.dict[e];let i;if(t==="type")i=n.type;else if(t==="stiffness")i=n.k.every(s=>s===n.k[0])?n.k[0]:[...n.k];else if(t==="damping")i=n.c.every(s=>s===n.c[0])?n.c[0]:[...n.c];else if(t==="external")i=n.ext<1?n.ext:null;else if(t==="limits")i=n.limits?.map(s=>s===null?null:[...s]);else if(t==="deltaLocal")i=n.dl?[...n.dl]:null;else if(t==="excludes")i=n.excludes?[...n.excludes.map(s=>{const o={bone:s.bone.name.slice(),radius:s.radius};return s.deltaLocal&&(o.deltaLocal=[...s.deltaLocal]),o})]:null;else if(t==="deltaWorld")i=n.dw?[...n.dw]:null;else if(t==="pivot")i=n.pivot;else if(t==="helper")i=n.helper;else throw new Error("Unsupported property '"+t+"'.");return i}setValue(e,t,n){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");if(!this.dict.hasOwnProperty(e))throw new Error("Dynamic bone '"+e+"' not found.");const i=this.dict[e];if(t==="type"){if(!n)throw new Error("Parameter 'type' not set.");if(typeof n!="string")throw new Error("Type must be a string.");switch(n){case"point":i.isPoint=!0,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!1;break;case"link":i.isPoint=!1,i.isX=!0,i.isY=!1,i.isZ=!0,i.isT=!1;break;case"mix1":i.isPoint=!1,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!1;break;case"mix2":i.isPoint=!1,i.isX=!0,i.isY=!1,i.isZ=!0,i.isT=!0;break;case"full":i.isPoint=!1,i.isX=!0,i.isY=!0,i.isZ=!0,i.isT=!0;break;default:throw new Error("Unknown type'"+n+"'.")}i.type=n.slice()}else if(t==="stiffness"){if(!n)throw new Error("Parameter 'stiffness' not set.");if(!Number.isNaN(n)&&n>=0)i.k=Array(4).fill(n);else if(Array.isArray(n)&&n.length===4&&n.every(s=>s>=0))i.k=[...n];else throw new Error("Stiffness must be a non-negative number or an array of four non-negative numbers.")}else if(t==="damping"){if(!n)throw new Error("Parameter 'damping' not set.");if(!Number.isNaN(n)&&n>=0)i.c=Array(4).fill(n);else if(Array.isArray(n)&&n.length===4&&n.every(s=>s>=0))i.c=[...n];else throw new Error("Damping must be a non-negative number or an array of four non-negative numbers.")}else if(t==="external")if(n==null)i.ext=1;else if(!Number.isNaN(n)&&n>=0&&n<=1)i.ext=n;else throw new Error("External (if set) must be a number between [0,1].");else if(t==="limits")if(n==null)i.limits=null;else{if(!Array.isArray(n)||n.length!==4)throw new Error("Limits (if set) must null, or an array of four arrays.");if(!n.every(s=>s===null||Array.isArray(s)&&s.length===2&&(s[0]===null||!Number.isNaN(s[0]))&&(s[1]===null||!Number.isNaN(s))))throw new Error("Limit values must be null or numbers.");i.limits=[n[0]?[...n[0]]:null,n[1]?[...n[1]]:null,n[2]?[...n[2]]:null,n[3]?[...n[3]]:null]}else if(t==="excludes"){if(n==null)i.excludes=null;else{if(!Array.isArray(n))throw new Error("Excludes (if set) must null, or an array.");i.excludes=[],n.forEach((s,o)=>{if(!s.bone)throw new Error("Bone not specified in #"+o+" exclude.");if(typeof s.bone!="string"||s.bone.length===0)throw new Error("Bone name must be a non-empty string in #"+o+" exclude.");const a=this.armature.getObjectByName(s.bone);if(!a)throw new Error("Bone '"+s.bone+"' not found in #"+o+" exclude.");if(Number.isNaN(s.radius)&&s.radius>=0)throw new Error("Radius must be a non-negative number in #"+o+" exclude.");const l={bone:a,radius:s.radius,radiusSq:s.radius*s.radius,deltaLocal:null};if(s.deltaLocal){if(!Array.isArray(s.deltaLocal)||s.deltaLocal.length!==3||s.deltaLocal.some(r=>Number.isNaN(r)))throw new Error("deltaLocal must be an array of three numbers in #"+o+" exclude.");l.deltaLocal=[...s.deltaLocal]}i.excludes.push(l)})}this.showHelpers()}else if(t==="helper"){if(n==null)i.helper=null;else{if(n!==!1&&n!==!0)throw new Error("Helper, if set, must be false or true.");i.helper=n}this.showHelpers()}else if(t==="pivot")if(n==null)i.pivot=null;else{if(n!==!1&&n!==!0)throw new Error("Pivot, if set, must be false or true.");if(n===!0&&i.type===0)throw new Error("Point type bone can't be a pivot.");i.pivot=n}else if(t==="deltaLocal")if(n==null)i.dl=null;else{if(!Array.isArray(n)||n.length!==3)throw new Error("deltaLocal, is set, must be an array of three numbers.");if(!n.every(s=>!Number.isNaN(s)))throw new Error("deltaLocal values must be numbers.");i.dl=[...n]}else if(t==="deltaWorld")if(n==null)i.dw=null;else{if(!Array.isArray(n)||n.length!==3)throw new Error("deltaWorld, is set, must be an array of three values.");if(!n.every(s=>!Number.isNaN(s)))throw new Error("deltaWorld values must be numbers.");i.dw=[...n]}else throw new Error("Unsupported property "+t)}getConfig(){return this.data.map(e=>{const t={bone:e.name.slice()};return["type","stiffness","damping","external","deltaLocal","deltaWorld","limits","excludes","pivot","helper"].forEach(n=>{b=this.getValue(e.name,n),b&&(t[n]=b)}),t})}sortBones(){if(this.scene===null)throw new Error("Dynamic bones has not been setup yet.");let e=0;const t=new WeakMap;this.armature.traverse(o=>{t.has(o)||(t.set(o,e),e++)}),this.data.sort((o,a)=>t.get(o.bone)-t.get(a.bone)),this.data.forEach(o=>{b=this.dict[o.boneParent.name],b&&(b.children||(b.children=[]),b.children.push(o))}),this.objectsUpdate=[];const n=new WeakSet,i=o=>o.parent?.isBone?[o,...i(o.parent)]:[o],s=o=>{i(o).forEach(l=>{n.has(l)||(this.objectsUpdate.push(l),n.add(l))})};this.data.forEach(o=>{s(o.bone),o.excludes&&o.excludes.forEach(a=>{s(a.bone)})}),this.objectsUpdate.sort((o,a)=>t.get(o)-t.get(a))}setup(e,t,n){this.dispose();const i=(s,o)=>{if(!s)throw this.dispose(),new Error(o)};i(e?.isScene,"First parameter must be Scene."),this.scene=e,i(t?.isObject3D,"Second parameter must be the armature Object3D."),this.armature=t,i(Array.isArray(n),"Third parameter must be an array of bone configs."),this.config=n,this.config.forEach((s,o)=>{const a="Config item #"+o+": ";i(s.bone,a+"Bone not specified.");const l=s.bone;i(typeof l=="string"&&l.length>0,a+"Bone name must be a non-empty string.");const r=this.armature.getObjectByName(l);i(r,a+"Bone '"+l+"' not found."),i(r.parent?.isBone,a+"Bone must have a parent bone."),i(this.data.every(c=>c.bone!==r),a+"Bone '"+l+"' already exists."),r.updateMatrixWorld(!0);const h={name:l,bone:r,boneParent:r.parent,vBasis:r.position.clone(),vWorld:r.parent.getWorldPosition(H).clone(),qBasis:r.parent.quaternion.clone(),l:r.position.length(),p:[0,0,0,0],v:[0,0,0,0],a:[0,0,0,0],ev:[0,0,0,0],ea:[0,0,0,0]};h.boneParent.matrixWorld.decompose(H,J,q),H.copy(Ne).applyQuaternion(J).setY(0).normalize(),J.premultiply(yt.setFromUnitVectors(Ne,H).invert()).normalize(),h.qWorldInverseYaw=J.clone().normalize(),this.data.push(h),this.dict[l]=h;try{this.setValue(l,"type",s.type),this.setValue(l,"stiffness",s.stiffness),this.setValue(l,"damping",s.damping),this.setValue(l,"external",s.external),this.setValue(l,"limits",s.limits),this.setValue(l,"excludes",s.excludes),this.setValue(l,"deltaLocal",s.deltaLocal),this.setValue(l,"deltaWorld",s.deltaWorld),this.setValue(l,"pivot",s.pivot),this.setValue(l,"helper",s.helper)}catch(c){i(!1,a+c)}}),this.sortBones(),this.start()}update(e){if(!this.running)return;let t,n,i,s,o;for(this.timerMs+=e,e>1e3&&(this.timerMs=0),e/=1e3,t=0,i=this.objectsUpdate.length;t<i;t++)o=this.objectsUpdate[t],o.updateMatrix(),o.parent===null?o.matrixWorld.copy(o.matrix):o.matrixWorld.multiplyMatrices(o.parent.matrixWorld,o.matrix),o.matrixWorldNeedsUpdate=!1;for(t=0,i=this.data.length;t<i;t++){if(o=this.data[t],H.copy(o.vWorld),ce.copy(o.boneParent.matrixWorld),he.copy(ce).invert(),o.vWorld.setFromMatrixPosition(ce),H.applyMatrix4(he),H.length()>.5&&(console.info("Info: Unrealistic jump of "+H.length().toFixed(2)+" meters."),H.setLength(.5)),H.applyQuaternion(o.bone.quaternion),k[0]=H.x,k[1]=H.y,k[2]=-H.z,k[3]=H.length()/3,o.children)for(n=0,s=o.children.length;n<s;n++)b=o.children[n],k[0]-=b.v[0]*e/3,k[1]-=b.v[1]*e/3,k[2]+=b.v[2]*e/3,k[3]-=b.v[3]*e/3;if(b=this.opt.sensitivityFactor,k[0]*=o.ext*b,k[1]*=o.ext*b,k[2]*=o.ext*b,k[3]*=o.ext*b,o.isX&&(b=k[0]/e,o.ea[0]=(b-o.ev[0])/e,o.ev[0]=b,o.a[0]=-o.k[0]*o.p[0]-o.c[0]*o.v[0]-o.ea[0],o.p[0]+=o.v[0]*e+o.a[0]*e*e/2+k[0],b=o.v[0]+o.a[0]*e/2,b=-o.k[0]*o.p[0]-o.c[0]*b-o.ea[0],o.v[0]=o.v[0]+(b+o.a[0])*e/2),o.isY&&(b=k[1]/e,o.ea[1]=(b-o.ev[1])/e,o.ev[1]=b,o.a[1]=-o.k[1]*o.p[1]-o.c[1]*o.v[1]-o.ea[1],o.p[1]+=o.v[1]*e+o.a[1]*e*e/2+k[1],b=o.v[1]+o.a[1]*e/2,b=-o.k[1]*o.p[1]-o.c[1]*b-o.ea[1],o.v[1]=o.v[1]+(b+o.a[1])*e/2),o.isZ&&(b=k[2]/e,o.ea[2]=(b-o.ev[2])/e,o.ev[2]=b,o.a[2]=-o.k[2]*o.p[2]-o.c[2]*o.v[2]-o.ea[2],o.p[2]+=o.v[2]*e+o.a[2]*e*e/2+k[2],b=o.v[2]+o.a[2]*e/2,b=-o.k[2]*o.p[2]-o.c[2]*b-o.ea[2],o.v[2]=o.v[2]+(b+o.a[2])*e/2),o.isT&&(b=k[3]/e,o.ea[3]=(b-o.ev[3])/e,o.ev[3]=b,o.a[3]=-o.k[3]*o.p[3]-o.c[3]*o.v[3]-o.ea[3],o.p[3]+=o.v[3]*e+o.a[3]*e*e/2+k[3],b=o.v[3]+o.a[3]*e/2,b=-o.k[3]*o.p[3]-o.c[3]*b-o.ea[3],o.v[3]=o.v[3]+(b+o.a[3])*e/2),this.timerMs<this.opt.warmupMs&&(o.v[0]*=1e-4,o.p[0]*=1e-4,o.v[1]*=1e-4,o.p[1]*=1e-4,o.v[2]*=1e-4,o.p[2]*=1e-4,o.v[3]*=1e-4,o.p[3]*=1e-4),k[0]=o.p[0],k[1]=o.p[1],k[2]=o.p[2],k[3]=o.p[3],b=this.opt.movementFactor,k[0]*=b,k[1]*=b,k[2]*=b,k[3]*=b,o.dl&&(b=o.dl,k[0]+=b[0],k[1]+=b[1],k[2]+=b[2]),o.dw&&(b=o.dw,H.set(o.vBasis.x+k[0],o.vBasis.y+k[1],o.vBasis.z+k[2]),H.applyMatrix4(ce),H.x+=b[0],H.y+=b[1],H.z+=b[2],H.applyMatrix4(he),k[0]+=H.x-o.vBasis.x,k[1]+=H.y-o.vBasis.y,k[2]+=H.z-o.vBasis.z),o.limits&&this.opt.isLimits&&(b=o.limits,b[0]&&(b[0][0]!==null&&k[0]<b[0][0]&&(k[0]=b[0][0]),b[0][1]!==null&&k[0]>b[0][1]&&(k[0]=b[0][1])),b[1]&&(b[1][0]!==null&&k[1]<b[1][0]&&(k[1]=b[1][0]),b[1][1]!==null&&k[1]>b[1][1]&&(k[1]=b[1][1])),b[2]&&(b[2][0]!==null&&k[2]<b[2][0]&&(k[2]=b[2][0]),b[2][1]!==null&&k[2]>b[2][1]&&(k[2]=b[2][1])),b[3]&&(b[3][0]!==null&&k[3]<b[3][0]&&(k[3]=b[3][0]),b[3][1]!==null&&k[3]>b[3][1]&&(k[3]=b[3][1]))),o.isPoint)o.bone.position.set(o.vBasis.x+k[0],o.vBasis.y+k[1],o.vBasis.z-k[2]);else if(o.boneParent.quaternion.copy(o.qBasis),o.pivot&&this.opt.isPivots&&(o.boneParent.updateWorldMatrix(!1,!1),o.boneParent.matrixWorld.decompose(H,J,q),H.copy(Ne).applyQuaternion(J).setY(0).normalize(),J.premultiply(yt.setFromUnitVectors(Ne,H).invert()).normalize(),o.boneParent.quaternion.multiply(J.invert()),o.boneParent.quaternion.multiply(o.qWorldInverseYaw)),o.isZ&&(b=Math.atan(k[0]/o.l),J.setFromAxisAngle(bi,-b),o.boneParent.quaternion.multiply(J)),o.isY&&(b=o.l/3,b=b*Math.tanh(k[1]/b),o.bone.position.setLength(o.l+b)),o.isX&&(b=Math.atan(k[2]/o.l),J.setFromAxisAngle(yi,-b),o.boneParent.quaternion.multiply(J)),o.isT&&(b=1.5*Math.tanh(k[3]*1.5),J.setFromAxisAngle(xi,-b),o.boneParent.quaternion.multiply(J)),o.boneParent.updateWorldMatrix(!1,!0),o.excludes&&this.opt.isExcludes)for(n=0,s=o.excludes.length;n<s;n++)b=o.excludes[n],q.set(0,0,0),b.deltaLocal&&(q.x+=b.deltaLocal[0],q.y+=b.deltaLocal[1],q.z+=b.deltaLocal[2]),q.applyMatrix4(b.bone.matrixWorld),he.copy(o.boneParent.matrixWorld).invert(),q.applyMatrix4(he),H.copy(o.bone.position),!(H.distanceToSquared(q)>=b.radiusSq)&&(ie=H.length(),ne=q.length(),!(ne>b.radius+ie)&&(ne<Math.abs(b.radius-ie)||(ne=(ne*ne+ie*ie-b.radiusSq)/(2*ne),q.normalize(),_e.copy(q).multiplyScalar(ne),ne=Math.sqrt(ie*ie-ne*ne),H.subVectors(H,_e).projectOnPlane(q).normalize().multiplyScalar(ne),Oe.subVectors(o.vBasis,_e).projectOnPlane(q).normalize(),ie=Oe.dot(H),ie<0&&(ie=Math.sqrt(ne*ne-ie*ie),Oe.multiplyScalar(ie),H.add(Oe)),H.add(_e).normalize(),q.copy(o.bone.position).normalize(),J.setFromUnitVectors(q,H),o.boneParent.quaternion.premultiply(J),o.boneParent.updateWorldMatrix(!1,!0))))}this.helpers.isActive&&this.updateHelpers()}showHelpers(e){if(this.hideHelpers(),this.helpers.isShowAll=e===void 0?this.helpers.isShowAll:e===!0,b=this.helpers,this.data.forEach(t=>{(this.helpers.isShowAll||t.helper===!0)&&(b.points.bones.push(t.bone),b.points.pivots.push(t.pivot),t.type!==0&&b.lines.bones.push(t.bone),t.excludes&&t.excludes.forEach(n=>{let i=!1;for(let s=0;s<b.excludes.bones.length;s++)if(b.excludes.bones[s]===n.bone&&b.excludes.radii[s]===n.radius&&!(b.excludes.deltaLocals[s]===null&&n.deltaLocal!==null)&&!(b.excludes.deltaLocals[s]!==null&&n.deltaLocal===null)&&!(b.excludes.deltaLocals[s]!==null&&b.excludes.deltaLocals[s].some((o,a)=>o!==n.deltaLocal[a]))){i=!0;break}i||(b.excludes.bones.push(n.bone),b.excludes.radii.push(n.radius),b.excludes.deltaLocals.push(n.deltaLocal?[...n.deltaLocal]:null),b.excludes.objects.push(null))}))}),b=this.helpers.excludes,this.opt.isExcludes&&b.bones.length&&b.bones.forEach((t,n)=>{const i=new v.SphereGeometry(b.radii[n],6,6),s=new v.MeshBasicMaterial({depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0,wireframe:!0,color:this.opt.helperExcludesColor});b.objects[n]=new v.Mesh(i,s),b.objects[n].renderOrder=997,t.add(b.objects[n]),b.deltaLocals[n]&&b.objects[n].position.set(b.deltaLocals[n][0],b.deltaLocals[n][1],b.deltaLocals[n][2])}),b=this.helpers.points,b.bones.length){this.helpers.isActive=!0;const t=new v.BufferGeometry,n=b.bones.map(l=>[0,0,0]).flat();t.setAttribute("position",new v.Float32BufferAttribute(n,3));const i=new v.Color(this.opt.helperBoneColor1),s=new v.Color(this.opt.helperBoneColor2),o=b.pivots.map(l=>l&&this.opt.isPivots?[s.r,s.g,s.b]:[i.r,i.g,i.b]).flat();t.setAttribute("color",new v.Float32BufferAttribute(o,3));const a=new v.PointsMaterial({depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0,size:.2,vertexColors:!0});b.object=new v.Points(t,a),b.object.renderOrder=998,b.object.matrix=this.armature.matrixWorld,b.object.matrixAutoUpdate=!1,this.scene.add(b.object)}if(b=this.helpers.lines,b.bones.length){const t=new v.BufferGeometry,n=b.bones.map(l=>[0,0,0,0,0,0]).flat();t.setAttribute("position",new v.Float32BufferAttribute(n,3));const i=new v.Color(this.opt.helperLinkColor1),s=new v.Color(this.opt.helperLinkColor2),o=b.bones.map(l=>[i.r,i.g,i.b,s.r,s.g,s.b]).flat();t.setAttribute("color",new v.Float32BufferAttribute(o,3));const a=new v.LineBasicMaterial({vertexColors:!0,depthTest:!1,depthWrite:!1,toneMapped:!1,transparent:!0});b.object=new v.LineSegments(t,a),b.object.renderOrder=999,b.object.matrix=this.armature.matrixWorld,b.object.matrixAutoUpdate=!1,this.scene.add(b.object)}}updateHelpers(){if(b=this.helpers.points,b.bones.length){he.copy(this.armature.matrixWorld).invert();const e=b.object.geometry.getAttribute("position");for(let t=0,n=b.bones.length;t<n;t++)ce.multiplyMatrices(he,b.bones[t].matrixWorld),H.setFromMatrixPosition(ce),e.setXYZ(t,H.x,H.y,H.z);e.needsUpdate=!0,b.object.updateMatrixWorld()}if(b=this.helpers.lines,b.bones.length){he.copy(this.armature.matrixWorld).invert();const e=b.object.geometry.getAttribute("position");for(let t=0,n=0,i=b.bones.length;t<i;t++,n+=2)ce.multiplyMatrices(he,b.bones[t].matrixWorld),H.setFromMatrixPosition(ce),e.setXYZ(n,H.x,H.y,H.z),ce.multiplyMatrices(he,b.bones[t].parent.matrixWorld),H.setFromMatrixPosition(ce),e.setXYZ(n+1,H.x,H.y,H.z);e.needsUpdate=!0,b.object.updateMatrixWorld()}}hideHelpers(){[this.helpers.points,this.helpers.lines].forEach(e=>{e.bones=[],e.object&&(this.scene.remove(e.object),e.object.geometry.dispose(),e.object.material.dispose(),e.object=null)}),b=this.helpers.excludes,b.objects.forEach((e,t)=>{e&&(b.bones[t].remove(e),e.geometry.dispose(),e.material.dispose())}),b.bones=[],b.deltaLocals=[],b.radii=[],b.objects=[],this.helpers.isActive=!1}start(){this.data.length&&(this.running=!0,this.timerMs=0,this.showHelpers())}stop(){this.running=!1,this.hideHelpers();for(let e=0,t=this.data.length;e<t;e++){const n=this.data[e];n.bone.position.copy(n.vBasis),n.boneParent.quaternion.copy(n.qBasis)}}dispose(){this.stop(),this.scene=null,this.armature=null,this.config=[],this.data=[],this.dict={},this.objectsUpdate=[],this.timerMs=0}}class vi{constructor(e){this.audioContext=e,this.analyzer=null,this.dataArray=null,this.bufferLength=0}async analyzeAudio(e,t){const n=e.sampleRate,i=e.duration,s=e.getChannelData(0),o=this.extractAudioFeatures(s,n);return this.generateTimingData(o,t,i)}extractAudioFeatures(e,t){const n={energy:[],spectralCentroid:[],zeroCrossingRate:[],mfcc:[],onsets:[],phonemeBoundaries:[]},i=1024,s=512,o=Math.floor((e.length-i)/s)+1;for(let a=0;a<o;a++){const l=a*s,r=Math.min(l+i,e.length),h=e.slice(l,r),c=this.calculateEnergy(h);n.energy.push(c);const u=this.calculateSpectralCentroid(h);n.spectralCentroid.push(u);const d=this.calculateZeroCrossingRate(h);n.zeroCrossingRate.push(d);const f=this.calculateMFCC(h);n.mfcc.push(f)}return n.onsets=this.detectOnsets(n.energy),n.phonemeBoundaries=this.detectPhonemeBoundaries(n),n}calculateEnergy(e){let t=0;for(let n=0;n<e.length;n++)t+=e[n]*e[n];return t/e.length}calculateSpectralCentroid(e){const t=this.fft(e);let n=0,i=0;for(let s=0;s<t.length/2;s++){const o=Math.sqrt(t[s*2]*t[s*2]+t[s*2+1]*t[s*2+1]);n+=s*o,i+=o}return i>0?n/i:0}calculateZeroCrossingRate(e){let t=0;for(let n=1;n<e.length;n++)e[n]>=0!=e[n-1]>=0&&t++;return t/(e.length-1)}calculateMFCC(e){const t=this.fft(e),n=[];for(let i=0;i<13;i++){let s=0;for(let o=0;o<t.length/2;o++){const a=Math.sqrt(t[o*2]*t[o*2]+t[o*2+1]*t[o*2+1]);s+=a*Math.cos(Math.PI*i*(o+.5)/(t.length/2))}n.push(s)}return n}fft(e){const t=e.length,n=new Float32Array(t*2);for(let i=0;i<t;i++)n[i*2]=e[i],n[i*2+1]=0;for(let i=1,s=0;i<t;i++){let o=t>>1;for(;s&o;)s^=o,o>>=1;if(s^=o,i<s){const a=n[i*2],l=n[i*2+1];n[i*2]=n[s*2],n[i*2+1]=n[s*2+1],n[s*2]=a,n[s*2+1]=l}}for(let i=2;i<=t;i<<=1){const s=-2*Math.PI/i,o=Math.cos(s),a=Math.sin(s);for(let l=0;l<t;l+=i){let r=1,h=0;for(let c=0;c<i/2;c++){const u=n[(l+c)*2],d=n[(l+c)*2+1],f=n[(l+c+i/2)*2]*r-n[(l+c+i/2)*2+1]*h,x=n[(l+c+i/2)*2]*h+n[(l+c+i/2)*2+1]*r;n[(l+c)*2]=u+f,n[(l+c)*2+1]=d+x,n[(l+c+i/2)*2]=u-f,n[(l+c+i/2)*2+1]=d-x;const y=r*o-h*a,R=r*a+h*o;r=y,h=R}}}return n}detectOnsets(e){const t=[];let s=-.1;for(let o=1;o<e.length;o++){const a=e[o]-e[o-1],l=o*.023;a>.1&&l-s>.1&&(t.push(l),s=l)}return t}detectPhonemeBoundaries(e){const t=[],{energy:n,spectralCentroid:i,zeroCrossingRate:s}=e;for(let o=1;o<n.length;o++){const a=o*.023,l=Math.abs(n[o]-n[o-1]),r=Math.abs(i[o]-i[o-1]),h=Math.abs(s[o]-s[o-1]);l+r*.1+h*.5>.2&&t.push(a)}return t}generateTimingData(e,t,n){const i=t.toLowerCase().split(/\s+/);e.phonemeBoundaries,e.onsets;const s=[];let o=0;for(let l=0;l<i.length;l++){const r=i[l],h=this.estimateWordDuration(r,n/i.length);s.push({word:r,startTime:o,endTime:o+h,duration:h}),o+=h}const a=this.generateVisemeTimings(e,t,n);return{words:s,visemes:a,duration:n,features:e}}estimateWordDuration(e,t){const n=Math.max(.5,Math.min(2,e.length/5)),i=this.getWordComplexity(e);return t*n*i}getWordComplexity(e){const t=(e.match(/[bcdfghjklmnpqrstvwxyz]{2,}/g)||[]).length,n=(e.match(/[aeiou]{2,}/g)||[]).length;return 1+t*.2+n*.1}generateVisemeTimings(e,t,n){const i=[],s=e.phonemeBoundaries;e.onsets;const o=this.textToVisemes(t);let a=0,l=0;for(let r=0;r<s.length&&a<o.length;r++){const h=s[r],c=o[a],u=e.energy[Math.floor(h/.023)]||0,d=this.calculateVisemeDuration(c,u);i.push({viseme:c,startTime:l,endTime:l+d,duration:d,intensity:Math.min(1,u*2)}),l+=d,a++}for(;a<o.length;){const r=o[a],h=this.calculateVisemeDuration(r,.5);i.push({viseme:r,startTime:l,endTime:l+h,duration:h,intensity:.6}),l+=h,a++}return i}textToVisemes(e){const t={a:"aa",e:"E",i:"I",o:"O",u:"U",ae:"aa",ai:"aa",au:"O",ea:"E",ee:"E",ei:"E",ie:"I",oa:"O",oo:"U",ou:"U",b:"PP",p:"PP",m:"PP",f:"FF",v:"FF",th:"SS",s:"SS",z:"SS",sh:"SS",ch:"SS",d:"DD",t:"DD",n:"nn",l:"nn",k:"kk",g:"kk",ng:"kk",r:"RR",w:"RR",y:"I",h:"kk"},n=[],i=e.toLowerCase().replace(/[^a-z\s]/g,"").split(/\s+/);for(const s of i){let o=0;for(;o<s.length;){let a=!1;for(let l=3;l>=2;l--){const r=s.substr(o,l);if(t[r]){n.push(t[r]),o+=l,a=!0;break}}if(!a){const l=s[o];t[l]&&n.push(t[l]),o++}}}return n}calculateVisemeDuration(e,t){const i={aa:.15,E:.12,I:.1,O:.14,U:.13,PP:.08,FF:.1,SS:.12,DD:.11,kk:.09,nn:.1,RR:.11}[e]||.1,s=.5+t*.5;return i*s}}class Ai{constructor(){this.rules={A:["[A] =aa"," [ARE] =aa RR"," [AR]O=aa RR","[AR]#=E RR"," ^[AS]#=E SS","[A]WA=aa","[AW]=aa"," :[ANY]=E nn I","[A]^+#=E","#:[ALLY]=aa nn I"," [AL]#=aa nn","[AGAIN]=aa kk E nn","#:[AG]E=I kk","[A]^+:#=aa",":[A]^+ =E","[A]^%=E"," [ARR]=aa RR","[ARR]=aa RR"," :[AR] =aa RR","[AR] =E","[AR]=aa RR","[AIR]=E RR","[AI]=E","[AY]=E","[AU]=aa","#:[AL] =aa nn","#:[ALS] =aa nn SS","[ALK]=aa kk","[AL]^=aa nn"," :[ABLE]=E PP aa nn","[ABLE]=aa PP aa nn","[ANG]+=E nn kk","[A]=aa"],B:[" [BE]^#=PP I","[BEING]=PP I I nn"," [BOTH] =PP O TH"," [BUS]#=PP I SS","[BUIL]=PP I nn","[B]=PP"],C:[" [CH]^=kk","^E[CH]=kk","[CH]=CH"," S[CI]#=SS aa","[CI]A=SS","[CI]O=SS","[CI]EN=SS","[C]+=SS","[CK]=kk","[COM]%=kk aa PP","[C]=kk"],D:["#:[DED] =DD I DD",".E[D] =DD","#^:E[D] =DD"," [DE]^#=DD I"," [DO] =DD U"," [DOES]=DD aa SS"," [DOING]=DD U I nn"," [DOW]=DD aa","[DU]A=kk U","[D]=DD"],E:["#:[E] =","'^:[E] ="," :[E] =I","#[ED] =DD","#:[E]D =","[EV]ER=E FF","[E]^%=I","[ERI]#=I RR I","[ERI]=E RR I","#:[ER]#=E","[ER]#=E RR","[ER]=E"," [EVEN]=I FF E nn","#:[E]W=","@[EW]=U","[EW]=I U","[E]O=I","#:&[ES] =I SS","#:[E]S =","#:[ELY] =nn I","#:[EMENT]=PP E nn DD","[EFUL]=FF U nn","[EE]=I","[EARN]=E nn"," [EAR]^=E","[EAD]=E DD","#:[EA] =I aa","[EA]SU=E","[EA]=I","[EIGH]=E","[EI]=I"," [EYE]=aa","[EY]=I","[EU]=I U","[E]=E"],F:["[FUL]=FF U nn","[F]=FF"],G:["[GIV]=kk I FF"," [G]I^=kk","[GE]T=kk E","SU[GGES]=kk kk E SS","[GG]=kk"," B#[G]=kk","[G]+=kk","[GREAT]=kk RR E DD","#[GH]=","[G]=kk"],H:[" [HAV]=I aa FF"," [HERE]=I I RR"," [HOUR]=aa EE","[HOW]=I aa","[H]#=I","[H]="],I:[" [IN]=I nn"," [I] =aa","[IN]D=aa nn","[IER]=I E","#:R[IED] =I DD","[IED] =aa DD","[IEN]=I E nn","[IE]T=aa E"," :[I]%=aa","[I]%=I","[IE]=I","[I]^+:#=I","[IR]#=aa RR","[IZ]%=aa SS","[IS]%=aa SS","[I]D%=aa","+^[I]^+=I","[I]T%=aa","#^:[I]^+=I","[I]^+=aa","[IR]=E","[IGH]=aa","[ILD]=aa nn DD","[IGN] =aa nn","[IGN]^=aa nn","[IGN]%=aa nn","[IQUE]=I kk","[I]=I"],J:["[J]=kk"],K:[" [K]N=","[K]=kk"],L:["[LO]C#=nn O","L[L]=","#^:[L]%=aa nn","[LEAD]=nn I DD","[L]=nn"],M:["[MOV]=PP U FF","[M]=PP"],N:["E[NG]+=nn kk","[NG]R=nn kk","[NG]#=nn kk","[NGL]%=nn kk aa nn","[NG]=nn","[NK]=nn kk"," [NOW] =nn aa","[N]=nn"],O:["[OF] =aa FF","[OROUGH]=E O","#:[OR] =E","#:[ORS] =E SS","[OR]=aa RR"," [ONE]=FF aa nn","[OW]=O"," [OVER]=O FF E","[OV]=aa FF","[O]^%=O","[O]^EN=O","[O]^I#=O","[OL]D=O nn","[OUGHT]=aa DD","[OUGH]=aa FF"," [OU]=aa","H[OU]S#=aa","[OUS]=aa SS","[OUR]=aa RR","[OULD]=U DD","^[OU]^L=aa","[OUP]=U OO","[OU]=aa","[OY]=O","[OING]=O I nn","[OI]=O","[OOR]=aa RR","[OOK]=U kk","[OOD]=U DD","[OO]=U","[O]E=O","[O] =O","[OA]=O"," [ONLY]=O nn nn I"," [ONCE]=FF aa nn SS","[ON'T]=O nn DD","C[O]N=aa","[O]NG=aa"," ^:[O]N=aa","I[ON]=aa nn","#:[ON] =aa nn","#^[ON]=aa nn","[O]ST =O","[OF]^=aa FF","[OTHER]=aa TH E","[OSS] =aa SS","#^:[OM]=aa PP","[O]=aa"],P:["[PH]=FF","[PEOP]=PP I PP","[POW]=PP aa","[PUT] =PP U DD","[P]=PP"],Q:["[QUAR]=kk FF aa RR","[QU]=kk FF","[Q]=kk"],R:[" [RE]^#=RR I","[R]=RR"],S:["[SH]=SS","#[SION]=SS aa nn","[SOME]=SS aa PP","#[SUR]#=SS E","[SUR]#=SS E","#[SU]#=SS U","#[SSU]#=SS U","#[SED] =SS DD","#[S]#=SS","[SAID]=SS E DD","^[SION]=SS aa nn","[S]S=",".[S] =SS","#:.E[S] =SS","#^:##[S] =SS","#^:#[S] =SS","U[S] =SS"," :#[S] =SS"," [SCH]=SS kk","[S]C+=","#[SM]=SS PP","#[SN]'=SS aa nn","[S]=SS"],T:[" [THE] =TH aa","[TO] =DD U","[THAT] =TH aa DD"," [THIS] =TH I SS"," [THEY]=TH E"," [THERE]=TH E RR","[THER]=TH E","[THEIR]=TH E RR"," [THAN] =TH aa nn"," [THEM] =TH E PP","[THESE] =TH I SS"," [THEN]=TH E nn","[THROUGH]=TH RR U","[THOSE]=TH O SS","[THOUGH] =TH O"," [THUS]=TH aa SS","[TH]=TH","#:[TED] =DD I DD","S[TI]#N=CH","[TI]O=SS","[TI]A=SS","[TIEN]=SS aa nn","[TUR]#=CH E","[TU]A=CH U"," [TWO]=DD U","[T]=DD"],U:[" [UN]I=I U nn"," [UN]=aa nn"," [UPON]=aa PP aa nn","@[UR]#=U RR","[UR]#=I U RR","[UR]=E","[U]^ =aa","[U]^^=aa","[UY]=aa"," G[U]#=","G[U]%=","G[U]#=FF","#N[U]=I U","@[U]=I","[U]=I U"],V:["[VIEW]=FF I U","[V]=FF"],W:[" [WERE]=FF E","[WA]S=FF aa","[WA]T=FF aa","[WHERE]=FF E RR","[WHAT]=FF aa DD","[WHOL]=I O nn","[WHO]=I U","[WH]=FF","[WAR]=FF aa RR","[WOR]^=FF E","[WR]=RR","[W]=FF"],X:[" [X]=SS","[X]=kk SS"],Y:["[YOUNG]=I aa nn"," [YOU]=I U"," [YES]=I E SS"," [Y]=I","#^:[Y] =I","#^:[Y]I=I"," :[Y] =aa"," :[Y]#=aa"," :[Y]^+:#=I"," :[Y]^#=I","[Y]=I"],Z:["[Z]=SS"]};const e={"#":"[AEIOUY]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ED|ING|ELY)","&":"(?:[SCGZXJ]|CH|SH)","@":"(?:[TSRDLZNJ]|TH|CH|SH)","^":"[BCDFGHJKLMNPQRSTVWXZ]","+":"[EIY]",":":"[BCDFGHJKLMNPQRSTVWXZ]*"," ":"\\b"};Object.keys(this.rules).forEach(t=>{this.rules[t]=this.rules[t].map(n=>{const i=n.indexOf("["),s=n.indexOf("]"),o=n.indexOf("="),a=n.substring(0,i),l=n.substring(i+1,s),r=n.substring(s+1,o),h=n.substring(o+1),c={regex:"",move:0,visemes:[]};let u="";u+=[...a].map(f=>e[f]||f).join("");const d=[...l];return d[0]=d[0].toLowerCase(),u+=d.join(""),c.move=d.length,u+=[...r].map(f=>e[f]||f).join(""),c.regex=new RegExp(u),h.length&&h.split(" ").forEach(f=>{c.visemes.push(f)}),c})}),this.visemeDurations={aa:.95,E:.9,I:.92,O:.96,U:.95,PP:1.08,SS:1.23,TH:1,DD:1.05,FF:1,kk:1.21,nn:.88,RR:.88,DD:1.05,sil:1},this.specialDurations={" ":1,",":3,"-":.5,"'":.5},this.digits=["oh","one","two","three","four","five","six","seven","eight","nine"],this.ones=["","one","two","three","four","five","six","seven","eight","nine"],this.tens=["","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"],this.teens=["ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"],this.decades={20:"twenties",30:"thirties",40:"forties",50:"fifties",60:"sixties",70:"seventies",80:"eighties",90:"nineties"},this.ordinals={1:"first",2:"second",3:"third",4:"fourth",5:"fifth",6:"sixth",7:"seventh",8:"eighth",9:"ninth",10:"tenth",11:"eleventh",12:"twelfth",13:"thirteenth",14:"fourteenth",15:"fifteenth",16:"sixteenth",17:"seventeeth",18:"eighteenth",19:"nineteenth",20:"twentieth",30:"thirtieth",40:"fortieth",50:"fiftieth",60:"sixtieth",70:"seventieth",80:"eightieth",90:"ninetieth"},this.symbols={"%":"percent","€":"euros","&":"and","+":"plus",$:"dollars"},this.symbolsReg=/[%€&\+\$]/g}convert_digit_by_digit(e){e=String(e).split("");let t="";for(let n=0;n<e.length;n++)t+=this.digits[e[n]]+" ";return t=t.substring(0,t.length-1),t}convert_sets_of_two(e){let t=String(e).substring(0,2),n=String(e).substring(2,4),i=this.convert_tens(t);return i+=" "+this.convert_tens(n),i}convert_millions(e){return e>=1e6?this.convert_millions(Math.floor(e/1e6))+" million "+this.convert_thousands(e%1e6):this.convert_thousands(e)}convert_thousands(e){return e>=1e3?this.convert_hundreds(Math.floor(e/1e3))+" thousand "+this.convert_hundreds(e%1e3):this.convert_hundreds(e)}convert_hundreds(e){return e>99?this.ones[Math.floor(e/100)]+" hundred "+this.convert_tens(e%100):this.convert_tens(e)}convert_tens(e){return e<10?(Number(e)!=0&&e.toString().startsWith("0")?"oh ":"")+this.ones[Number(e)]:e>=10&&e<20?this.teens[e-10]:(this.tens[Math.floor(e/10)]+" "+this.ones[e%10]).trim()}convertNumberToWords(e,t=!1){const n=parseFloat(e);if(e=="0")return"zero";if(e<0)return" minus "+this.convertNumberToWords(Math.abs(e).toString(),t).trim();if(n&&!Number.isInteger(n)){const i=n.toString().split(".");return this.convertNumberToWords(i[0],t).trim()+" point "+this.convert_digit_by_digit(i[1]).trim()}else return e.toString().startsWith("0")?this.convert_digit_by_digit(e).trim():!t&&(e<1e3&&e>99&&e%100!==0||e>1e4&&e<1e6)?this.convert_digit_by_digit(e).trim():!t&&(e>1e3&&e<2e3||e>2009&&e<3e3)?e%100!=0?this.convert_sets_of_two(e).trim():this.convert_tens(e.toString().substring(0,2)).trim()+" hundred":this.convert_millions(e).trim()}convertDecade(e){const t=parseInt(e),n=!isNaN(t)&&e.length===2,i=!isNaN(t)&&e.length>2&&t>0&&t<=3e3,s=i&&t%1e3===0?Math.floor(t/1e3):null,o=i&&!s?Math.floor(t/100):null,a=n||i?Math.floor(t%100/10)*10:null;let l=[];return s?l.push(this.convertNumberToWords(s).trim(),"thousands"):(o&&l.push(this.convertNumberToWords(o).trim()),a?l.push(this.decades[a]||this.convertNumberToWords(a).trim()+"s"):o?l.push("hundreds"):l.push(e)),l.join(" ")}convertOrdinal(e){if(this.ordinals.hasOwnProperty(e))return this.ordinals[e];const t=Math.floor(e/100),n=Math.floor(e%100/10)*10,i=e%10;let s=[];return t&&(s.push(this.convertNumberToWords(t).trim()),n||i?s.push("hundred"):s.push("hundredth")),n&&(i?s.push(this.convertNumberToWords(n).trim()):s.push(this.ordinals[n])),i&&s.push(this.ordinals[i]),s.join(" ")}preProcessText(e){let t=e.replace('/[#_*":;]/g',"");return t=t.replace(this.symbolsReg,n=>" "+this.symbols[n]+" "),/\d/.test(t)&&(t=t.replace(/\b(\d{2,4})[''']?\s?[sS](?=\s|[.,!?;:]|$)/g,(n,i)=>{const s=this.convertDecade(i);return s===i?n:s}),t=t.replace(/\b(\d+)\s*(st|nd|rd|th)(?=\s|[.,!?;:]|$)/gi,(n,i)=>this.convertOrdinal(Number(i))),t=t.replace(/\b(\w*?)(\d+)([A-Za-z]+)\b/g,(n,i,s,o)=>{const a=this.convertNumberToWords(s);return`${i}${a} ${o}`}).replace(/\b([A-Za-z]+)(\d+)(\w*?)\b/g,(n,i,s,o)=>{const a=this.convertNumberToWords(s);return`${i} ${a}${o}`}),t=t.replace(/-?(?:\d{1,3}(?:,\d{3})+|\d+)(\.\d+)?/g,(n,i)=>{let s=n,o=!1;return/,/.test(s)&&(s=s.replace(/,/g,""),o=!0),i&&(o=!0),this.convertNumberToWords(s,o)})),t=t.replace(/(\D)\1\1+/g,"$1$1").replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u036f]/g,"").normalize("NFC").trim(),t}wordsToVisemes(e){let t={words:e.toUpperCase(),visemes:[],times:[],durations:[],i:0},n=0;const i=[...t.words];for(;t.i<i.length;){const s=i[t.i],o=this.rules[s];if(o)for(let a=0;a<o.length;a++){const l=o[a];if((t.words.substring(0,t.i)+s.toLowerCase()+t.words.substring(t.i+1)).match(l.regex)){l.visemes.forEach(c=>{if(t.visemes.length&&t.visemes[t.visemes.length-1]===c){const u=.7*(this.visemeDurations[c]||1);t.durations[t.durations.length-1]+=u,n+=u}else{const u=this.visemeDurations[c]||1;t.visemes.push(c),t.times.push(n),t.durations.push(u),n+=u}}),t.i+=l.move;break}}else t.i++,n+=this.specialDurations[s]||0}return t}}const Li=Object.freeze(Object.defineProperty({__proto__:null,LipsyncEn:Ai},Symbol.toStringTag,{value:"Module"}));class Ii{constructor(){this.rules={A:["[AH]=aa","[AU]=aa U","[AI]=aa I","[AE]=E","[A]H=aa","[A]U=aa U","[A]I=aa I"," [AN] =aa nn"," [AM] =aa PP","[ARR]=aa RR","[AR]=aa RR"," [ALS]=aa nn SS","[AL]=aa nn","[AUCH]=aa U kk","[ABER]=aa PP E RR","[A]=aa"],Ä:["[Ä]H=E","[ÄU]=O","[Ä]=E"],B:["[B]=PP"],C:["[CH]S=kk SS","[CH]=kk"," [CH]=kk","#[CH]=kk","[CK]=kk","[C]H=kk","[C]=kk"],D:[" [DAS] =DD aa SS"," [DEN] =DD E nn"," [DER] =DD E RR"," [DIE] =DD I"," [DU] =DD U"," [DURCH]=DD U RR kk","[D]=DD"],E:["[EI]=aa I","[EU]=O","[EH]=E"," [ER] =E RR"," [ES] =E SS"," [EIN] =aa I nn"," [EINE]=aa I nn aa","[ER]#=E","[ER]=E RR","[EN]#=aa nn","[E]=E"],F:["[F]=FF"],G:["[G]=kk"],H:[" [HAT] =I aa DD"," [HABEN]=I aa PP aa nn"," [HIER]=I I RR"," [HEUTE]=I O DD aa","[H]="],I:[" [ICH] =I kk"," [IHR] =I RR"," [IN] =I nn"," [IST] =I SS DD"," [IM] =I PP","[IE]=I","[IH]=I","[I]=I"],J:["[J]=I"],K:["[K]=kk"],L:["[L]=nn"],M:[" [MIT] =PP I DD"," [MAN] =PP aa nn"," [MEHR]=PP E RR"," [MICH]=PP I kk","[M]=PP"],N:[" [NICHT]=nn I kk DD"," [NUR] =nn U RR"," [NACH]=nn aa kk"," [NOCH]=nn aa kk","[NG]=nn kk","[N]=nn"],O:["[OO]=U","[OH]=O","[OU]=aa U"," [ODER]=O DD E RR"," [OHNE]=O nn aa","[Ö]=E","[O]=aa"],Ö:["[ÖH]=E","[Ö]=E"],P:["[PF]=FF FF","[PH]=FF","[P]=PP"],Q:["[QU]=kk FF","[Q]=kk"],R:["[R]=RR"],S:["[SCH]=SS","[SP]=SS PP","[ST]=SS DD","[SS]=SS","[S]=SS"],ß:["[ß]=SS"],T:["[TZ]=DD SS","[TH]=DD","[T]=DD"],U:[" [UND] =U nn DD"," [UM] =U PP"," [UNTER]=U nn DD E RR"," [UNS] =U nn SS","[UH]=U","[ÜH]=I U","[Ü]=I U","[U]=U"],Ü:["[ÜH]=I U","[Ü]=I U"],V:[" [VON] =FF aa nn"," [VOR] =FF aa RR"," [VIEL]=FF I nn","[V]=FF"],W:[" [WAS] =FF aa SS"," [WIR] =FF I RR"," [WIE] =FF I"," [WENN]=FF E nn"," [WILL]=FF I nn"," [WO] =FF aa"," [WIEDER]=FF I DD E RR","[W]=FF"],X:["[X]=kk SS"],Y:["[Y]=I"],Z:[" [ZU] =DD SS U"," [ZUM] =DD SS U PP"," [ZUR] =DD SS U RR"," [ZEIT]=DD SS aa I DD","[Z]=DD SS"]};const e={"#":"[AEIOUÄÖÜ]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ED|ING|ELY|EN|TE|ST)","&":"(?:[SCGZXJ]|CH|SCH|TZ)","@":"(?:[TSRDLZNJ]|TH|CH|SCH)","^":"[BCDFGHJKLMNPQRSTVWXYZß]","+":"[EIY]",":":"[BCDFGHJKLMNPQRSTVWXYZß]*"," ":"\\b"};Object.keys(this.rules).forEach(t=>{this.rules[t]=this.rules[t].map(n=>{const i=n.indexOf("["),s=n.indexOf("]"),o=n.indexOf("="),a=n.substring(0,i),l=n.substring(i+1,s),r=n.substring(s+1,o),h=n.substring(o+1),c={regex:"",move:0,visemes:[]};let u="";u+=[...a].map(f=>e[f]||f).join("");const d=[...l];return d[0]=d[0].toLowerCase(),u+=d.join(""),c.move=d.length,u+=[...r].map(f=>e[f]||f).join(""),c.regex=new RegExp(u),h.length&&h.split(" ").forEach(f=>{c.visemes.push(f)}),c})}),this.visemeDurations={aa:1,E:.85,I:.9,O:1.05,U:1,PP:1.15,SS:1.2,TH:1,DD:1.1,FF:1.05,kk:1.25,nn:.85,RR:.9,sil:1},this.specialDurations={" ":1,",":3,"-":.5,"'":.5,".":4,"!":3,"?":3},this.digits=["null","eins","zwei","drei","vier","fünf","sechs","sieben","acht","neun"],this.ones=["","ein","zwei","drei","vier","fünf","sechs","sieben","acht","neun"],this.tens=["","","zwanzig","dreißig","vierzig","fünfzig","sechzig","siebzig","achtzig","neunzig"],this.teens=["zehn","elf","zwölf","dreizehn","vierzehn","fünfzehn","sechzehn","siebzehn","achtzehn","neunzehn"],this.symbols={"%":"prozent","€":"euro","&":"und","+":"plus",$:"dollar","=":"gleich","@":"at","#":"hashtag"},this.symbolsReg=/[%€&\+\$=@#]/g}convert_digit_by_digit(e){e=String(e).split("");let t="";for(let n=0;n<e.length;n++)t+=this.digits[e[n]]+" ";return t=t.substring(0,t.length-1),t}convert_millions(e){if(e>=1e6){const t=Math.floor(e/1e6),n=e%1e6;let i=this.convert_thousands(t);return i+=t===1?" million ":" millionen ",n>0&&(i+=this.convert_thousands(n)),i}else return this.convert_thousands(e)}convert_thousands(e){if(e>=1e3){const t=Math.floor(e/1e3),n=e%1e3;let i="";return t===1?i="eintausend":i=this.convert_hundreds(t)+"tausend",n>0&&(i+=this.convert_hundreds(n)),i}else return this.convert_hundreds(e)}convert_hundreds(e){if(e>99){const t=Math.floor(e/100),n=e%100;let i="";return t===1?i="einhundert":i=this.ones[t]+"hundert",n>0&&(i+=this.convert_tens(n)),i}else return this.convert_tens(e)}convert_tens(e){if(e<10)return this.ones[Number(e)]||"";if(e>=10&&e<20)return this.teens[e-10];{const t=Math.floor(e/10),n=e%10;return n===0?this.tens[t]:this.ones[n]+"und"+this.tens[t]}}convertNumberToWords(e){const t=String(e);return e=="0"?"null":t.startsWith("0")?this.convert_digit_by_digit(e):t.length===4&&(e<1e3||e>2100)?this.convert_digit_by_digit(e):this.convert_millions(Number(e))}preProcessText(e){return e.replace(/[#_*\":;]/g,"").replace(this.symbolsReg,t=>" "+this.symbols[t]+" ").replace(/(\d)\.(\d)/g,"$1 komma $2").replace(/(\d),(\d)/g,"$1 komma $2").replace(/\d+/g,this.convertNumberToWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replace(/\s+/g," ").toLowerCase().trim()}wordsToVisemes(e){let t={words:e.toUpperCase(),visemes:[],times:[],durations:[],i:0},n=0;const i=[...t.words];for(;t.i<i.length;){const s=i[t.i],o=this.rules[s];if(o){let a=!1;for(let l=0;l<o.length;l++){const r=o[l];if((t.words.substring(0,t.i)+s.toLowerCase()+t.words.substring(t.i+1)).match(r.regex)){r.visemes.forEach(u=>{if(t.visemes.length&&t.visemes[t.visemes.length-1]===u){const d=.7*(this.visemeDurations[u]||1);t.durations[t.durations.length-1]+=d,n+=d}else{const d=this.visemeDurations[u]||1;t.visemes.push(u),t.times.push(n),t.durations.push(d),n+=d}}),t.i+=r.move,a=!0;break}}a||(t.i++,n+=this.specialDurations[s]||0)}else t.i++,n+=this.specialDurations[s]||0}return t}}const wi=Object.freeze(Object.defineProperty({__proto__:null,LipsyncDe:Ii},Symbol.toStringTag,{value:"Module"}));class Si{constructor(){this.rules={A:["[AN]C=aa nn","[AN]G=aa nn","[AN]T=aa nn","[AN]D=aa nn","[AN] =aa nn","[AN]$=aa nn","[AM]P=aa nn","[AM]B=aa nn","[AM] =aa nn","[AM]$=aa nn","[AI]N=E nn","[AIM]=E nn","[AIN]=E nn","[AU]=O","[AUX]=O","[AUT]=O","[AI]=E","[AY]=E","[A]=aa"],À:["[À]=aa"],Â:["[Â]=aa"],B:[" [B] =PP","[BB]=PP","[B]=PP"],C:["[C]E=SS","[C]I=SS","[C]Y=SS","[C]È=SS","[C]É=SS","[C]Ê=SS","[CH]=SS","[C]A=kk","[C]O=kk","[C]U=kk","[C]L=kk","[C]R=kk","[CK]=kk","[C]=kk"],Ç:["[Ç]=SS"],D:["[D]=DD"],E:["[EN]C=aa nn","[EN]T=aa nn","[EN]D=aa nn","[EN] =aa nn","[EN]$=aa nn","[EM]P=aa nn","[EM]B=aa nn","[EM] =aa nn","[EM]$=aa nn","[EAU]=O","[EAU]X=O","[EU]=U","[EUX]=U","[EUR]=U RR","[EI]=E","[EIN]=E nn","[ER] =E","[ER]$=E","[EZ] =E","[EZ]$=E","[ED] =E","[ED]$=E"," [E] =","[E] =","[E]$=","[E]S =","[E]S$=","[E]NT =","[E]NT$=","[È]=E","[É]=E","[Ê]=E","[Ë]=E","[E]=E"],È:["[È]=E"],É:["[É]=E"],Ê:["[Ê]=E"],Ë:["[Ë]=E"],F:["[FF]=FF","[F]=FF","[PH]=FF"],G:["[G]E=SS","[G]I=SS","[G]Y=SS","[G]È=SS","[G]É=SS","[G]Ê=SS","[GN]=nn I","[GN]E=nn","[GN]A=nn aa","[GN]O=nn O","[GU]E=kk","[GU]I=kk","[GU]A=kk FF aa","[GU]O=kk FF O","[G]A=kk","[G]O=kk","[G]U=kk","[G]L=kk","[G]R=kk","[GG]=kk","[G]=kk"],H:["[H]="],I:["[IN]C=E nn","[IN]T=E nn","[IN]D=E nn","[IN] =E nn","[IN]$=E nn","[IM]P=E nn","[IM]B=E nn","[IM] =E nn","[IM]$=E nn","[IEN]=I E nn","[IER]=I E","[IEU]=I U","[IEZ]=I E","[ILL]E=I","[ILLE]=I","[ILL]=I","[Î]=I","[Ï]=I","[I]=I"],Î:["[Î]=I"],Ï:["[Ï]=I"],J:["[J]=SS"],K:["[K]=kk"],L:["[LL]E=","[LLE]=","[LL]A=I aa","[LL]O=I O","[LL]U=I U","[LL]I=I","[LL]=I","[L]=nn"],M:["[MM]=PP","[M]=PP"],N:["[NN]=nn","[N]=nn"],O:["[ON]C=O nn","[ON]T=O nn","[ON]D=O nn","[ON] =O nn","[ON]$=O nn","[OM]P=O nn","[OM]B=O nn","[OM] =O nn","[OM]$=O nn","[OI]N=FF E nn","[OI]G=FF aa","[OI]S=FF aa","[OI]T=FF aa","[OI]X=FF aa","[OI]=FF aa","[OU]=U","[OÙ]=U","[OÛ]=U","[OEU]=U","[OEUR]=U RR","[OUGH]=U FF","[OUGH]T=U","[Ô]=O","[O]=O"],Ô:["[Ô]=O"],Ù:["[Ù]=U"],Û:["[Û]=U"],P:["[PH]=FF","[PP]=PP","[P]=PP"],Q:["[QU]=kk","[Q]=kk"],R:["[RR]=RR","[R]=RR"],S:["#[S]#=SS"," [S]=SS","[SS]=SS","[S] =","[S]$=","[SC]E=SS","[SC]I=SS","[SC]Y=SS","[S]=SS"],T:["[TI]A=SS I aa","[TI]E=SS I E","[TI]O=SS I O","[TI]ON=SS I O nn","[TH]=DD","[TT]=DD","[T] =","[T]$=","[T]=DD"],U:["[UN]C=U nn","[UN]T=U nn","[UN]D=U nn","[UN] =U nn","[UN]$=U nn","[UM]=U nn","[UE]=I","[UEI]=I E","[UEIL]=I I","[UILL]=I","[Ù]=U","[Û]=U","[Ü]=I U","[U]=I U"],Ü:["[Ü]=I U"],V:["[V]=FF"],W:["[W]=FF"],X:["[X] =","[X]$=","#[X]#=kk SS"," [X]=kk SS","[X]=kk SS"],Y:["[Y]=I"," [Y]=I","[YE]=I E","[YA]=I aa","[YO]=I O","[YU]=I U"],Z:["[Z]=SS"]};const e={"#":"[AEIOUYÀÂÈÉÊËÎÏÔÙÛÜ]+",".":"[BDVGJLMNRWZ]","%":"(?:ER|E|ES|ÉS|ÈS|ÊS|ENT|MENT|TION|SION)","&":"(?:[SCGZXJ]|CH|SH|GN)","@":"(?:[TSRDLZNJ]|TH|CH|SH|GN)","^":"[BCDFGHJKLMNPQRSTVWXZÇ]+","+":"[EIYÈÉÊËÎÏ]",":":"[BCDFGHJKLMNPQRSTVWXZÇ]*"," ":"\\b",$:"$"};Object.keys(this.rules).forEach(t=>{this.rules[t]=this.rules[t].map(n=>{const i=n.indexOf("["),s=n.indexOf("]"),o=n.indexOf("="),a=n.substring(0,i),l=n.substring(i+1,s),r=n.substring(s+1,o),h=n.substring(o+1),c={regex:"",move:0,visemes:[]};let u="";u+=[...a].map(f=>e[f]||f).join("");const d=[...l];return d[0]=d[0].toLowerCase(),u+=d.join(""),c.move=d.length,u+=[...r].map(f=>e[f]||f).join(""),c.regex=new RegExp(u,"i"),h.length&&h.split(" ").forEach(f=>{f&&c.visemes.push(f)}),c})}),this.visemeDurations={aa:1,E:.95,I:.9,O:1.05,U:.95,PP:1.1,SS:1.25,TH:1,DD:1.05,FF:1,kk:1.2,nn:.88,RR:1.15,sil:1},this.specialDurations={" ":1,",":2.5,".":3.5,";":2.8,":":2.2,"!":3.2,"?":3.2,"-":.8,"'":.3,'"':.3,"(":1.5,")":1.5},this.digits=["zéro","un","deux","trois","quatre","cinq","six","sept","huit","neuf"],this.ones=["","un","deux","trois","quatre","cinq","six","sept","huit","neuf"],this.teens=["dix","onze","douze","treize","quatorze","quinze","seize","dix-sept","dix-huit","dix-neuf"],this.tens=["","dix","vingt","trente","quarante","cinquante","soixante","soixante-dix","quatre-vingts","quatre-vingt-dix"],this.symbols={"%":"pourcent","€":"euros","&":"et","+":"plus",$:"dollars","=":"égale","@":"arobase","#":"dièse","°":"degrés"},this.symbolsReg=/[%€&\+\$=@#°]/g}convert_digit_by_digit(e){e=String(e).split("");let t="";for(let n=0;n<e.length;n++)t+=this.digits[e[n]]+" ";return t=t.substring(0,t.length-1),t}convert_tens(e){if(e<10)return this.ones[e]||"";if(e>=10&&e<20)return this.teens[e-10];if(e>=70&&e<80){const t=e-60;return t===11?"soixante et onze":"soixante-"+this.teens[t-10]}else if(e>=90){const t=e-80;return t===11?"quatre-vingt-onze":"quatre-vingt-"+this.teens[t-10]}else{const t=Math.floor(e/10),n=e%10;return t===8&&n===0?"quatre-vingts":t===8?"quatre-vingt-"+this.ones[n]:(t===2||t===3||t===4||t===5||t===6)&&n===1?this.tens[t]+" et un":n===0?this.tens[t]:this.tens[t]+"-"+this.ones[n]}}convert_hundreds(e){if(e>=100){const t=Math.floor(e/100),n=e%100;let i="";return t===1?i="cent":(i=this.ones[t]+" cent",n===0&&(i+="s")),n>0&&(i+=" "+this.convert_tens(n)),i}else return this.convert_tens(e)}convert_thousands(e){if(e>=1e3){const t=Math.floor(e/1e3),n=e%1e3;let i="";return t===1?i="mille":i=this.convert_hundreds(t)+" mille",n>0&&(i+=" "+this.convert_hundreds(n)),i}else return this.convert_hundreds(e)}convert_millions(e){if(e>=1e6){const t=Math.floor(e/1e6),n=e%1e6;let i="";return t===1?i="un million":i=this.convert_hundreds(t)+" millions",n>0&&(i+=" "+this.convert_thousands(n)),i}else return this.convert_thousands(e)}convertNumberToWords(e){const t=String(e);return e==="0"||e===0?"zéro":t.startsWith("0")?this.convert_digit_by_digit(e):this.convert_millions(Number(e))}preProcessText(e){return e.replace(/[#_*\":;]/g,"").replace(this.symbolsReg,t=>" "+this.symbols[t]+" ").replace(/(\d)[,.](\d)/g,"$1 virgule $2").replace(/\d+/g,this.convertNumberToWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replace(/\s+/g," ").replace(/'/g,"'").trim()}wordsToVisemes(e){let t={words:e.toUpperCase(),visemes:[],times:[],durations:[],i:0},n=0;const i=[...t.words];for(;t.i<i.length;){const s=i[t.i],o=this.rules[s];if(o){let a=!1;for(let l=0;l<o.length;l++){const r=o[l];if((t.words.substring(0,t.i)+s.toLowerCase()+t.words.substring(t.i+1)).match(r.regex)){r.visemes.forEach(u=>{if(t.visemes.length&&t.visemes[t.visemes.length-1]===u){const d=.7*(this.visemeDurations[u]||1);t.durations[t.durations.length-1]+=d,n+=d}else{const d=this.visemeDurations[u]||1;t.visemes.push(u),t.times.push(n),t.durations.push(d),n+=d}}),t.i+=r.move,a=!0;break}}a||(t.i++,n+=this.specialDurations[s]||0)}else t.i++,n+=this.specialDurations[s]||0}return t}}const Ti=Object.freeze(Object.defineProperty({__proto__:null,LipsyncFr:Si},Symbol.toStringTag,{value:"Module"}));class ki{constructor(){this.visemes={a:"aa",e:"E",i:"I",o:"O",u:"U",y:"U",ä:"aa",ö:"O",å:"O",b:"PP",c:"SS",d:"DD",f:"FF",g:"kk",h:"kk",j:"I",k:"kk",l:"nn",m:"PP",n:"nn",p:"PP",q:"kk",r:"RR",s:"SS",t:"DD",v:"FF",w:"FF",x:"SS",z:"SS"},this.visemeDurations={aa:.95,E:.9,I:.92,O:.96,U:.95,PP:1.08,SS:1.23,DD:1.05,FF:1,kk:1.21,nn:.88,RR:.88,DD:1.05,sil:1},this.specialDurations={" ":1,",":3,"-":.5},this.numbers=["nolla","yksi","kaksi","kolme","neljä","viisi","kuusi","seitsemän","kahdeksan","yhdeksän","kymmenen","yksitoista","kaksitoista","kolmetoista","neljätoista","viisitoista","kuusitoista","seitsemäntoista","kahdeksantoista","yhdeksäntoista"],this.symbols={"%":"prosenttia","€":"euroa","&":"ja","+":"plus",$:"dollaria"},this.symbolsReg=/[%€&\+\$]/g}numberToFinnishWords(e){const t=[];let n=parseFloat(e);if(n===void 0)return e;let i=(s,o,a,l,r)=>{if(s<o)return s;const h=Math.floor(s/o);return t.push(a+(h===1?l:this.numberToFinnishWords(h.toString())+r)),s-h*o};if(n<0&&(t.push("miinus "),n=Math.abs(n)),n=i(n,1e9," ","miljardi"," miljardia"),n=i(n,1e6," ","miljoona"," miljoonaa"),n=i(n,1e3,"","tuhat","tuhatta"),n=i(n,100," ","sata","sataa"),n>20&&(n=i(n,10,"","","kymmentä")),n>=1){let s=Math.floor(n);t.push(this.numbers[s]),n-=s}if(n>=0&&Math.abs(parseFloat(e))<1&&t.push("nolla"),n>0){let s=e.split(".");if(s.length>1){t.push(" pilkku");let o=[...s[s.length-1]];for(let a=0;a<o.length;a++)t.push(" "+this.numbers[o[a]])}}return t.join("").trim()}preProcessText(e){return e.replace(/[#_*\'\":;]/g,"").replace(this.symbolsReg,t=>" "+this.symbols[t]+" ").replace(/(\d)\,(\d)/g,"$1 pilkku $2").replace(/\d+/g,this.numberToFinnishWords.bind(this)).replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u0307\u0309\u030b-\u036f]/g,"").normalize("NFC").trim()}wordsToVisemes(e){let t={words:e,visemes:[],times:[],durations:[]},n=0;const i=[...e];for(let s=0;s<i.length;s++){const o=this.visemes[i[s].toLowerCase()];if(o)if(t.visemes.length&&t.visemes[t.visemes.length-1]===o){const a=.7*(this.visemeDurations[o]||1);t.durations[t.durations.length-1]+=a,n+=a}else{const a=this.visemeDurations[o]||1;t.visemes.push(o),t.times.push(n),t.durations.push(a),n+=a}else n+=this.specialDurations[i[s]]||0}return t}}const Ci=Object.freeze(Object.defineProperty({__proto__:null,LipsyncFi:ki},Symbol.toStringTag,{value:"Module"}));class Ei{constructor(){this.visemes={a:"aa",ą:"O",e:"E",ę:"E",ė:"E",i:"I",į:"I",o:"O",u:"U",ū:"U",ų:"U",y:"I",b:"PP",c:"SS",č:"SS",d:"DD",f:"FF",g:"kk",h:"kk",j:"I",k:"kk",l:"nn",m:"PP",n:"nn",p:"PP",q:"kk",r:"RR",s:"SS",š:"CH",t:"DD",v:"FF",w:"FF",x:"SS",z:"SS",ž:"SS"},this.durations={a:.95,ą:1.5,e:.9,ę:1.5,ė:1.5,i:.92,į:1.5,o:.96,u:.95,ū:1.5,ų:1.5,y:1.5,b:1.08,c:1.23,d:1.05,f:1,g:1.21,h:1.21,j:.92,k:1.21,l:.88,m:1.08,n:.88,p:1.08,q:1.21,r:.88,s:1.23,š:1.23,t:1.05,v:1,w:1,x:1.23,z:1.23,ž:1.23},this.pauses={" ":1,",":3,"-":.5},this.numbers=["nulis","vienas","du","trys","keturi","penki","šeši","septyni","aštuoni","devyni","dešimt","vienuolika","dvylika","trylika","keturiolika","penkiolika","šešiolika","septyniolika","aštuoniolika","devyniolika"],this.tens=[this.numbers[0],this.numbers[10],"dvidešimt","trisdešimt","keturiasdešimt","penkiasdešimt","šešiasdešimt","septyniasdešimt","aštuoniasdešimt","devyniasdešimt"]}numberToLithuanianWords(e){const t=[];let n=parseFloat(e);if(n===void 0)return e;let i=(s,o,a,l,r)=>{if(s<o)return s;const h=Math.floor(s/o);return h===1?t.push(this.numbers[1]):t.push(this.numberToLithuanianWords(h.toString())),h%10===1?t.push(a):h%10===0||h%100>10&&h%100<20?t.push(r):t.push(l),s-h*o};n<0&&(t.push("minus"),n=Math.abs(n)),n=i(n,1e9,"milijardas","milijardai","milijardų"),n=i(n,1e6,"milijonas","milijonai","milijonų"),n=i(n,1e3,"tūkstantis","tūkstančiai","tūkstančių"),n=i(n,100,"šimtas","šimtai","šimtų");for(let s=this.tens.length-1;s>=1;s--)if(n>=10*s){t.push(this.tens[s]),n=n-10*s;break}if(n>=1){let s=Math.floor(n);t.push(this.numbers[s]),n-=s}if(n>=0&&Math.abs(parseFloat(e))<1&&t.push(this.numbers[0]),n>0){let s=e.split(".");if(s.length>1){t.push("kablelis");let o=[...s[s.length-1]];for(let a=0;a<o.length;a++)t.push(this.numbers[o[a]])}}return t.join(" ").trim()}preProcessText(e){return e.replace(`/[#_*'":;]/g`,"").replaceAll("0 %","0 procentų ").replaceAll("1 %","1 procentas ").replaceAll("%"," procentai ").replaceAll("0 €","0 eurų ").replaceAll("1 €","1 euras ").replaceAll("€"," eurai ").replaceAll("0 $","0 dolerių ").replaceAll("1 $","1 doleris ").replaceAll("$"," doleriai ").replaceAll("&"," ir ").replaceAll("+"," pliusas ").replace(/(\d)\,(\d)/g,"$1 kablelis $2").replace(/\d+/g,this.numberToLithuanianWords.bind(this)).replace(/(\D)\1\1+/g,"$1$1").replaceAll(" "," ").normalize("NFD").replace(/[\u0300-\u0303\u0305\u0306\u0308-\u0327\u0329-\u036f]/g,"").normalize("NFC").trim()}wordsToVisemes(e){let t={words:e,visemes:[],times:[],durations:[]},n=0;const i=[...e];for(let s=0;s<i.length;s++){const o=i[s].toLowerCase(),a=this.visemes[o];if(a)if(t.visemes.length&&t.visemes[t.visemes.length-1]===a){const l=.7*(this.durations[o]||1);t.durations[t.durations.length-1]+=l,n+=l}else{const l=this.durations[o]||1;t.visemes.push(a),t.times.push(n),t.durations.push(l),n+=l}else n+=this.pauses[i[s]]||0}return t}}const Mi=Object.freeze(Object.defineProperty({__proto__:null,LipsyncLt:Ei},Symbol.toStringTag,{value:"Module"})),zi=new URL("data:text/javascript;base64,Y2xhc3MgUGxheWJhY2tXb3JrbGV0IGV4dGVuZHMgQXVkaW9Xb3JrbGV0UHJvY2Vzc29yIHsKICBzdGF0aWMgRlNNID0gewogICAgSURMRTogMCwKICAgIFBMQVlJTkc6IDEsCiAgfTsKCiAgY29uc3RydWN0b3Iob3B0aW9ucykgewogICAgc3VwZXIoKTsKICAgIHRoaXMucG9ydC5vbm1lc3NhZ2UgPSB0aGlzLmhhbmRsZU1lc3NhZ2UuYmluZCh0aGlzKTsKCiAgICB0aGlzLl9zYW1wbGVSYXRlID0gb3B0aW9ucz8ucHJvY2Vzc29yT3B0aW9ucz8uc2FtcGxlUmF0ZSB8fCBzYW1wbGVSYXRlOwogICAgdGhpcy5fc2NhbGUgPSAxIC8gMzI3Njg7IC8vIFBDTTE2IC0+IGZsb2F0CgogICAgLy8gU2lsZW5jZSBkZXRlY3Rpb24gdGhyZXNob2xkICgxIHNlY29uZCkgYXMgYSBmYWxsYmFjayBzYWZldHkgbmV0CiAgICBjb25zdCBzaWxlbmNlRHVyYXRpb25TZWNvbmRzID0gMS4wOwogICAgdGhpcy5fc2lsZW5jZVRocmVzaG9sZEJsb2NrcyA9IE1hdGguY2VpbCgodGhpcy5fc2FtcGxlUmF0ZSAqIHNpbGVuY2VEdXJhdGlvblNlY29uZHMpIC8gMTI4KTsKCiAgICAvLyBNZXRyaWNzIGNvbmZpZ3VyYXRpb24gdmlhIG9wdGlvbnMKICAgIGNvbnN0IG1ldHJpY3NDZmcgPSBvcHRpb25zPy5wcm9jZXNzb3JPcHRpb25zPy5tZXRyaWNzIHx8IHt9OwogICAgdGhpcy5fbWV0cmljc0VuYWJsZWQgPSBtZXRyaWNzQ2ZnLmVuYWJsZWQgIT09IGZhbHNlOwogICAgY29uc3QgaW50ZXJ2YWxIeiA9ICh0eXBlb2YgbWV0cmljc0NmZy5pbnRlcnZhbEh6ID09PSAibnVtYmVyIiAmJiBtZXRyaWNzQ2ZnLmludGVydmFsSHogPiAwKQogICAgICA/IG1ldHJpY3NDZmcuaW50ZXJ2YWxIeiA6IDI7CiAgICAvLyBNZXRyaWNzIHN0YXRlIChsb3ctb3ZlcmhlYWQpCiAgICB0aGlzLl9mcmFtZXNQcm9jZXNzZWQgPSAwOwogICAgdGhpcy5fdW5kZXJydW5CbG9ja3MgPSAwOwogICAgdGhpcy5fbWF4UXVldWVTYW1wbGVzID0gMDsKICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSAwOwogICAgLy8gQ29udmVydCB0byBmcmFtZXMgYmV0d2VlbiByZXBvcnRzCiAgICB0aGlzLl9tZXRyaWNzSW50ZXJ2YWxGcmFtZXMgPSBNYXRoLm1heCgxMjgsIE1hdGgucm91bmQodGhpcy5fc2FtcGxlUmF0ZSAvIGludGVydmFsSHopKTsKCiAgICB0aGlzLnJlc2V0KCk7CiAgfQoKICAvKioKICAgKiBSZXNldHMgdGhlIHdvcmtsZXQgdG8gaXRzIGluaXRpYWwgSURMRSBzdGF0ZS4KICAgKi8KICByZXNldCgpIHsKICAgIHRoaXMuX2J1ZmZlclF1ZXVlID0gW107CiAgICB0aGlzLl9jdXJyZW50Q2h1bmsgPSBudWxsOwogICAgdGhpcy5fY3VycmVudENodW5rT2Zmc2V0ID0gMDsKICAgIHRoaXMuX3N0YXRlID0gUGxheWJhY2tXb3JrbGV0LkZTTS5JRExFOwoKICAgIHRoaXMuX25vTW9yZURhdGFSZWNlaXZlZCA9IGZhbHNlOwogICAgdGhpcy5fc2lsZW5jZUZyYW1lc0NvdW50ID0gMDsKICAgIHRoaXMuX2hhc1NlbnRFbmRlZCA9IGZhbHNlOwogICAgLy8gUmVzZXQgbWF4IHF1ZXVlIHRyYWNrZXIgb25seSB3aGVuIGdvaW5nIGlkbGUKICAgIHRoaXMuX21heFF1ZXVlU2FtcGxlcyA9IDA7CiAgfQoKICBoYW5kbGVNZXNzYWdlKGV2ZW50KSB7CiAgICBjb25zdCB7IHR5cGUsIGRhdGEgfSA9IGV2ZW50LmRhdGE7CgogICAgLy8gSU5URVJSVVBUOiBUaGUgbWFpbiB0aHJlYWQgd2FudHMgdG8gc3RvcCBpbW1lZGlhdGVseS4KICAgIGlmICh0eXBlID09PSAic3RvcCIpIHsKICAgICAgdGhpcy5yZXNldCgpOwogICAgICAvLyBTZW5kIGZpbmFsIG1ldHJpY3Mgc2hvd2luZyBjbGVhcmVkIHN0YXRlCiAgICAgIGlmICh0aGlzLl9tZXRyaWNzRW5hYmxlZCkgewogICAgICAgIHRyeSB7CiAgICAgICAgICB0aGlzLnBvcnQucG9zdE1lc3NhZ2UoewogICAgICAgICAgICB0eXBlOiAibWV0cmljcyIsCiAgICAgICAgICAgIGRhdGE6IHsKICAgICAgICAgICAgICBzdGF0ZTogUGxheWJhY2tXb3JrbGV0LkZTTS5JRExFLAogICAgICAgICAgICAgIHF1ZXVlZFNhbXBsZXM6IDAsCiAgICAgICAgICAgICAgcXVldWVkTXM6IDAsCiAgICAgICAgICAgICAgbWF4UXVldWVkTXM6IE1hdGgucm91bmQoKHRoaXMuX21heFF1ZXVlU2FtcGxlcyAvIHRoaXMuX3NhbXBsZVJhdGUpICogMTAwMCksCiAgICAgICAgICAgICAgdW5kZXJydW5CbG9ja3M6IHRoaXMuX3VuZGVycnVuQmxvY2tzLAogICAgICAgICAgICAgIGZyYW1lc1Byb2Nlc3NlZDogdGhpcy5fZnJhbWVzUHJvY2Vzc2VkCiAgICAgICAgICAgIH0KICAgICAgICAgIH0pOwogICAgICAgIH0gY2F0Y2ggKF8pIHsgfQogICAgICB9CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBNYWluIHRocmVhZCBoYXMgc2lnbmFsZWQgdGhhdCBubyBtb3JlIGF1ZGlvIGNodW5rcyB3aWxsIGJlIHNlbnQgZm9yIHRoaXMgdXR0ZXJhbmNlLgogICAgaWYgKHR5cGUgPT09ICJuby1tb3JlLWRhdGEiKSB7CiAgICAgIHRoaXMuX25vTW9yZURhdGFSZWNlaXZlZCA9IHRydWU7CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBVcGRhdGUgbWV0cmljcyBjb25maWd1cmF0aW9uIGF0IHJ1bnRpbWUKICAgIGlmICh0eXBlID09PSAiY29uZmlnLW1ldHJpY3MiICYmIGRhdGEgJiYgdHlwZW9mIGRhdGEgPT09ICJvYmplY3QiKSB7CiAgICAgIGlmICgiZW5hYmxlZCIgaW4gZGF0YSkgdGhpcy5fbWV0cmljc0VuYWJsZWQgPSAhIWRhdGEuZW5hYmxlZDsKICAgICAgaWYgKHR5cGVvZiBkYXRhLmludGVydmFsSHogPT09ICJudW1iZXIiICYmIGRhdGEuaW50ZXJ2YWxIeiA+IDApIHsKICAgICAgICBjb25zdCBpbnRlcnZhbEh6ID0gZGF0YS5pbnRlcnZhbEh6OwogICAgICAgIHRoaXMuX21ldHJpY3NJbnRlcnZhbEZyYW1lcyA9IE1hdGgubWF4KDEyOCwgTWF0aC5yb3VuZCh0aGlzLl9zYW1wbGVSYXRlIC8gaW50ZXJ2YWxIeikpOwogICAgICB9CiAgICAgIC8vIFJlc2V0IHBhY2luZyBzbyB0aGUgbmV4dCByZXBvcnQgYWxpZ25zIHdpdGggbmV3IGludGVydmFsCiAgICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSB0aGlzLl9mcmFtZXNQcm9jZXNzZWQ7CiAgICAgIHJldHVybjsKICAgIH0KCiAgICAvLyBOZXcgYXVkaW8gZGF0YSBoYXMgYXJyaXZlZC4KICAgIGlmICh0eXBlID09PSAiYXVkaW9EYXRhIiAmJiBkYXRhIGluc3RhbmNlb2YgQXJyYXlCdWZmZXIpIHsKICAgICAgdGhpcy5fbm9Nb3JlRGF0YVJlY2VpdmVkID0gZmFsc2U7CiAgICAgIC8vIElmIHdlIHdlcmUgaWRsZSwgdGhpcyBuZXcgZGF0YSBraWNrcyBvZmYgdGhlIHBsYXliYWNrLgogICAgICBpZiAodGhpcy5fc3RhdGUgPT09IFBsYXliYWNrV29ya2xldC5GU00uSURMRSkgewogICAgICAgIHRoaXMuX3N0YXRlID0gUGxheWJhY2tXb3JrbGV0LkZTTS5QTEFZSU5HOwogICAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZSh7IHR5cGU6ICJwbGF5YmFjay1zdGFydGVkIiB9KTsKICAgICAgfQoKICAgICAgLy8gV2Ugb25seSBxdWV1ZSBkYXRhIGlmIHdlIGFyZSBpbiB0aGUgUExBWUlORyBzdGF0ZS4gVGhpcyBwcmV2ZW50cwogICAgICAvLyBkYXRhIGZyb20gYSBwcmV2aW91cywgaW50ZXJydXB0ZWQgc3RyZWFtIGZyb20gbGluZ2VyaW5nLgogICAgICBpZiAodGhpcy5fc3RhdGUgPT09IFBsYXliYWNrV29ya2xldC5GU00uUExBWUlORykgewogICAgICAgIC8vIFN0b3JlIGFzIEludDE2QXJyYXkgdmlldyB0byBhdm9pZCBjb25zdHJ1Y3RpbmcgaXQgaW4gcHJvY2VzcygpCiAgICAgICAgdGhpcy5fYnVmZmVyUXVldWUucHVzaChuZXcgSW50MTZBcnJheShkYXRhKSk7CiAgICAgICAgdGhpcy5fc2lsZW5jZUZyYW1lc0NvdW50ID0gMDsgLy8gUmVzZXQgc2lsZW5jZSBjb3VudGVyIG9uIG5ldyBkYXRhCiAgICAgIH0KICAgIH0KICB9CgogIHByb2Nlc3MoaW5wdXRzLCBvdXRwdXRzLCBwYXJhbWV0ZXJzKSB7CiAgICBjb25zdCBvdXRwdXRDaGFubmVsID0gb3V0cHV0c1swXT8uWzBdOwogICAgaWYgKCFvdXRwdXRDaGFubmVsKSB7CiAgICAgIHJldHVybiB0cnVlOyAvLyBLZWVwIGFsaXZlIGV2ZW4gaWYgb3V0cHV0IGlzIHRlbXBvcmFyaWx5IGRpc2Nvbm5lY3RlZAogICAgfQoKICAgIC8vIElmIHdlIGFyZSBub3QgcGxheWluZywganVzdCBvdXRwdXQgc2lsZW5jZSBhbmQgd2FpdC4KICAgIGlmICh0aGlzLl9zdGF0ZSAhPT0gUGxheWJhY2tXb3JrbGV0LkZTTS5QTEFZSU5HKSB7CiAgICAgIG91dHB1dENoYW5uZWwuZmlsbCgwKTsKICAgICAgcmV0dXJuIHRydWU7IC8vIEFsd2F5cyByZXR1cm4gdHJ1ZSB0byBrZWVwIHRoZSBwcm9jZXNzb3IgYWxpdmUKICAgIH0KCiAgICAvLyBDb3JlIFBMQVlJTkcgTG9naWMKICAgIGNvbnN0IGJsb2NrU2l6ZSA9IG91dHB1dENoYW5uZWwubGVuZ3RoOwogICAgbGV0IHNhbXBsZXNDb3BpZWQgPSAwOwoKICAgIHdoaWxlIChzYW1wbGVzQ29waWVkIDwgYmxvY2tTaXplKSB7CiAgICAgIGlmICghdGhpcy5fY3VycmVudENodW5rIHx8IHRoaXMuX2N1cnJlbnRDaHVua09mZnNldCA+PSB0aGlzLl9jdXJyZW50Q2h1bmsubGVuZ3RoKSB7CiAgICAgICAgaWYgKHRoaXMuX2J1ZmZlclF1ZXVlLmxlbmd0aCA+IDApIHsKICAgICAgICAgIHRoaXMuX2N1cnJlbnRDaHVuayA9IHRoaXMuX2J1ZmZlclF1ZXVlLnNoaWZ0KCk7CiAgICAgICAgICB0aGlzLl9jdXJyZW50Q2h1bmtPZmZzZXQgPSAwOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAvLyBCdWZmZXIgaXMgZW1wdHkuIENoZWNrIGZvciBlbmQgY29uZGl0aW9ucy4KICAgICAgICAgIGNvbnN0IGlzVGltZWRPdXQgPSB0aGlzLl9zaWxlbmNlRnJhbWVzQ291bnQgPiB0aGlzLl9zaWxlbmNlVGhyZXNob2xkQmxvY2tzOwoKICAgICAgICAgIGlmICh0aGlzLl9ub01vcmVEYXRhUmVjZWl2ZWQgfHwgaXNUaW1lZE91dCkgewogICAgICAgICAgICAvLyBFTkQgT0YgUExBWUJBQ0s6IEVpdGhlciBleHBsaWNpdGx5IHNpZ25hbGVkIG9yIHRpbWVkIG91dC4KICAgICAgICAgICAgaWYgKCF0aGlzLl9oYXNTZW50RW5kZWQpIHsKICAgICAgICAgICAgICB0aGlzLnBvcnQucG9zdE1lc3NhZ2UoeyB0eXBlOiAicGxheWJhY2stZW5kZWQiIH0pOwogICAgICAgICAgICAgIHRoaXMuX2hhc1NlbnRFbmRlZCA9IHRydWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgLy8gU2VuZCBmaW5hbCBtZXRyaWNzIHNob3dpbmcgY2xlYXJlZCBzdGF0ZQogICAgICAgICAgICBpZiAodGhpcy5fbWV0cmljc0VuYWJsZWQpIHsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgdGhpcy5wb3J0LnBvc3RNZXNzYWdlKHsKICAgICAgICAgICAgICAgICAgdHlwZTogIm1ldHJpY3MiLAogICAgICAgICAgICAgICAgICBkYXRhOiB7CiAgICAgICAgICAgICAgICAgICAgc3RhdGU6IFBsYXliYWNrV29ya2xldC5GU00uSURMRSwKICAgICAgICAgICAgICAgICAgICBxdWV1ZWRTYW1wbGVzOiAwLAogICAgICAgICAgICAgICAgICAgIHF1ZXVlZE1zOiAwLAogICAgICAgICAgICAgICAgICAgIG1heFF1ZXVlZE1zOiBNYXRoLnJvdW5kKCh0aGlzLl9tYXhRdWV1ZVNhbXBsZXMgLyB0aGlzLl9zYW1wbGVSYXRlKSAqIDEwMDApLAogICAgICAgICAgICAgICAgICAgIHVuZGVycnVuQmxvY2tzOiB0aGlzLl91bmRlcnJ1bkJsb2NrcywKICAgICAgICAgICAgICAgICAgICBmcmFtZXNQcm9jZXNzZWQ6IHRoaXMuX2ZyYW1lc1Byb2Nlc3NlZAogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgICB9IGNhdGNoIChfKSB7IH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnJlc2V0KCk7IC8vIFJlc2V0IHRvIElETEUgc3RhdGUgZm9yIHJldXNlCiAgICAgICAgICAgIGJyZWFrOyAvLyBFeGl0IHdoaWxlIGxvb3AKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIC8vIEJVRkZFUiBVTkRFUlJVTiAoTEFHKTogUGxheSBzaWxlbmNlIGFuZCB3YWl0IGZvciBtb3JlIGRhdGEuCiAgICAgICAgICAgIHRoaXMuX3NpbGVuY2VGcmFtZXNDb3VudCsrOwogICAgICAgICAgICBpZiAodGhpcy5fbWV0cmljc0VuYWJsZWQpIHRoaXMuX3VuZGVycnVuQmxvY2tzKys7CiAgICAgICAgICAgIGJyZWFrOyAvLyBFeGl0IHdoaWxlIGxvb3AKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KCiAgICAgIC8vIElmIHdlIGhhdmUgYSBjaHVuayAoY291bGQgYmUgYSBuZXcgb25lIGZyb20gdGhlIGxvZ2ljIGFib3ZlKSwgcHJvY2VzcyBpdC4KICAgICAgaWYgKHRoaXMuX2N1cnJlbnRDaHVuaykgewogICAgICAgIGNvbnN0IHNhbXBsZXNUb0NvcHkgPSBNYXRoLm1pbigKICAgICAgICAgIGJsb2NrU2l6ZSAtIHNhbXBsZXNDb3BpZWQsCiAgICAgICAgICB0aGlzLl9jdXJyZW50Q2h1bmsubGVuZ3RoIC0gdGhpcy5fY3VycmVudENodW5rT2Zmc2V0CiAgICAgICAgKTsKICAgICAgICAvLyBEaXJlY3RseSB3cml0ZSB0byBvdXRwdXRDaGFubmVsIHRvIGF2b2lkIGV4dHJhIGNvcHkKICAgICAgICBjb25zdCBzcmMgPSB0aGlzLl9jdXJyZW50Q2h1bms7CiAgICAgICAgY29uc3QgYmFzZVNyYyA9IHRoaXMuX2N1cnJlbnRDaHVua09mZnNldDsKICAgICAgICBjb25zdCBiYXNlRHN0ID0gc2FtcGxlc0NvcGllZDsKICAgICAgICBjb25zdCBzY2FsZSA9IHRoaXMuX3NjYWxlOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc2FtcGxlc1RvQ29weTsgaSsrKSB7CiAgICAgICAgICBvdXRwdXRDaGFubmVsW2Jhc2VEc3QgKyBpXSA9IHNyY1tiYXNlU3JjICsgaV0gKiBzY2FsZTsKICAgICAgICB9CgogICAgICAgIHRoaXMuX2N1cnJlbnRDaHVua09mZnNldCArPSBzYW1wbGVzVG9Db3B5OwogICAgICAgIHNhbXBsZXNDb3BpZWQgKz0gc2FtcGxlc1RvQ29weTsKICAgICAgfQogICAgfQoKICAgIC8vIFplcm8tZmlsbCB0aGUgcmVtYWluZGVyLCBpZiBhbnksIG9uY2UgcGVyIGJsb2NrCiAgICBpZiAoc2FtcGxlc0NvcGllZCA8IGJsb2NrU2l6ZSkgewogICAgICBvdXRwdXRDaGFubmVsLmZpbGwoMCwgc2FtcGxlc0NvcGllZCk7CiAgICB9CgogICAgLy8gVXBkYXRlIG1ldHJpY3MgKG9wdGlvbmFsKQogICAgaWYgKHRoaXMuX21ldHJpY3NFbmFibGVkKSB7CiAgICAgIHRoaXMuX2ZyYW1lc1Byb2Nlc3NlZCArPSBibG9ja1NpemU7CgogICAgICAvLyBUcmFjayBxdWV1ZSBkZXB0aCBpbiBzYW1wbGVzIChhcHByb3hpbWF0ZSkKICAgICAgbGV0IHF1ZXVlZFNhbXBsZXMgPSAwOwogICAgICBpZiAodGhpcy5fY3VycmVudENodW5rKSBxdWV1ZWRTYW1wbGVzICs9IE1hdGgubWF4KDAsIHRoaXMuX2N1cnJlbnRDaHVuay5sZW5ndGggLSB0aGlzLl9jdXJyZW50Q2h1bmtPZmZzZXQpOwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHRoaXMuX2J1ZmZlclF1ZXVlLmxlbmd0aDsgaSsrKSBxdWV1ZWRTYW1wbGVzICs9IHRoaXMuX2J1ZmZlclF1ZXVlW2ldLmxlbmd0aDsKICAgICAgaWYgKHF1ZXVlZFNhbXBsZXMgPiB0aGlzLl9tYXhRdWV1ZVNhbXBsZXMpIHRoaXMuX21heFF1ZXVlU2FtcGxlcyA9IHF1ZXVlZFNhbXBsZXM7CgogICAgICAvLyBQZXJpb2RpY2FsbHkgc2VuZCBtZXRyaWNzIHRvIG1haW4gdGhyZWFkCiAgICAgIGlmICh0aGlzLl9mcmFtZXNQcm9jZXNzZWQgLSB0aGlzLl9sYXN0TWV0cmljc1NlbnRBdEZyYW1lID49IHRoaXMuX21ldHJpY3NJbnRlcnZhbEZyYW1lcykgewogICAgICAgIHRoaXMuX2xhc3RNZXRyaWNzU2VudEF0RnJhbWUgPSB0aGlzLl9mcmFtZXNQcm9jZXNzZWQ7CiAgICAgICAgdHJ5IHsKICAgICAgICAgIHRoaXMucG9ydC5wb3N0TWVzc2FnZSh7CiAgICAgICAgICAgIHR5cGU6ICJtZXRyaWNzIiwKICAgICAgICAgICAgZGF0YTogewogICAgICAgICAgICAgIHN0YXRlOiB0aGlzLl9zdGF0ZSwKICAgICAgICAgICAgICBxdWV1ZWRTYW1wbGVzLAogICAgICAgICAgICAgIHF1ZXVlZE1zOiBNYXRoLnJvdW5kKChxdWV1ZWRTYW1wbGVzIC8gdGhpcy5fc2FtcGxlUmF0ZSkgKiAxMDAwKSwKICAgICAgICAgICAgICBtYXhRdWV1ZWRNczogTWF0aC5yb3VuZCgodGhpcy5fbWF4UXVldWVTYW1wbGVzIC8gdGhpcy5fc2FtcGxlUmF0ZSkgKiAxMDAwKSwKICAgICAgICAgICAgICB1bmRlcnJ1bkJsb2NrczogdGhpcy5fdW5kZXJydW5CbG9ja3MsCiAgICAgICAgICAgICAgZnJhbWVzUHJvY2Vzc2VkOiB0aGlzLl9mcmFtZXNQcm9jZXNzZWQKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgfSBjYXRjaCAoXykgeyB9CiAgICAgICAgLy8gRG9uJ3QgcmVzZXQgbWF4IHRyYWNrZXIgLSBrZWVwIHNlc3Npb24gcGVhayB1bnRpbCBpZGxlCiAgICAgIH0KICAgIH0KCiAgICAvLyBBTFdBWVMgcmV0dXJuIHRydWUgdG8ga2VlcCB0aGUgcHJvY2Vzc29yIGFsaXZlIGZvciByZXVzZS4KICAgIHJldHVybiB0cnVlOwogIH0KfQoKcmVnaXN0ZXJQcm9jZXNzb3IoInBsYXliYWNrLXdvcmtsZXQiLCBQbGF5YmFja1dvcmtsZXQpOwo=",typeof document>"u"?require("url").pathToFileURL(__filename).href:We&&We.tagName.toUpperCase()==="SCRIPT"&&We.src||new URL("index-BAyfuKmk.cjs",document.baseURI).href),xt={en:Li,de:wi,fr:Ti,fi:Ci,lt:Mi},j=new v.Quaternion,N=new v.Euler,me=new v.Vector3,ye=new v.Vector3,bt=new v.Box3;new v.Matrix4;new v.Matrix4;new v.Vector3;new v.Vector3(0,0,1);const Hi=new v.Vector3(1,0,0);new v.Vector3(0,1,0);new v.Vector3(0,0,1);class Ht{constructor(e,t=null){this.nodeAvatar=e,this.opt={jwtGet:null,ttsEndpoint:"",ttsApikey:null,ttsTrimStart:0,ttsTrimEnd:400,ttsLang:"fi-FI",ttsVoice:"fi-FI-Standard-A",ttsRate:1,ttsPitch:0,ttsVolume:0,mixerGainSpeech:null,mixerGainBackground:null,lipsyncLang:"fi",lipsyncModules:["fi","en","lt"],pcmSampleRate:22050,modelRoot:"Armature",modelPixelRatio:1,modelFPS:30,modelMovementFactor:1,cameraView:"full",dracoEnabled:!1,dracoDecoderPath:"https://www.gstatic.com/draco/v1/decoders/",cameraDistance:0,cameraX:0,cameraY:0,cameraRotateX:0,cameraRotateY:0,cameraRotateEnable:!0,cameraPanEnable:!1,cameraZoomEnable:!1,lightAmbientColor:16777215,lightAmbientIntensity:2,lightDirectColor:8947882,lightDirectIntensity:30,lightDirectPhi:1,lightDirectTheta:2,lightSpotIntensity:0,lightSpotColor:3377407,lightSpotPhi:.1,lightSpotTheta:4,lightSpotDispersion:1,avatarMood:"neutral",avatarMute:!1,avatarIdleEyeContact:.2,avatarIdleHeadMove:.5,avatarSpeakingEyeContact:.5,avatarSpeakingHeadMove:.5,avatarIgnoreCamera:!1,listeningSilenceThresholdLevel:40,listeningSilenceThresholdMs:2e3,listeningSilenceDurationMax:1e4,listeningActiveThresholdLevel:75,listeningActiveThresholdMs:300,listeningActiveDurationMax:24e4,update:null,avatarOnly:!1,avatarOnlyScene:null,avatarOnlyCamera:null,statsNode:null,statsStyle:null},Object.assign(this.opt,t||{}),this.opt.statsNode&&(this.stats=new Ee,this.opt.statsStyle&&(this.stats.dom.style.cssText=this.opt.statsStyle),this.opt.statsNode.appendChild(this.stats.dom)),this.poseTemplates={side:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.003,y:-.017,z:.1},"Spine.rotation":{x:-.103,y:-.002,z:-.063},"Spine1.rotation":{x:.042,y:-.02,z:-.069},"Spine2.rotation":{x:.131,y:-.012,z:-.065},"Neck.rotation":{x:.027,y:.006,z:0},"Head.rotation":{x:.077,y:-.065,z:0},"LeftShoulder.rotation":{x:1.599,y:.084,z:-1.77},"LeftArm.rotation":{x:1.364,y:.052,z:-.044},"LeftForeArm.rotation":{x:.002,y:-.007,z:.331},"LeftHand.rotation":{x:.104,y:-.067,z:-.174},"LeftHandThumb1.rotation":{x:.231,y:.258,z:.355},"LeftHandThumb2.rotation":{x:-.106,y:-.339,z:-.454},"LeftHandThumb3.rotation":{x:-.02,y:-.142,z:-.004},"LeftHandIndex1.rotation":{x:.148,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.326,y:-.049,z:-.029},"LeftHandIndex3.rotation":{x:.247,y:-.053,z:-.073},"LeftHandMiddle1.rotation":{x:.238,y:-.057,z:-.089},"LeftHandMiddle2.rotation":{x:.469,y:-.036,z:-.081},"LeftHandMiddle3.rotation":{x:.206,y:-.015,z:-.017},"LeftHandRing1.rotation":{x:.187,y:-.118,z:-.157},"LeftHandRing2.rotation":{x:.579,y:.02,z:-.097},"LeftHandRing3.rotation":{x:.272,y:.021,z:-.063},"LeftHandPinky1.rotation":{x:.405,y:-.182,z:-.138},"LeftHandPinky2.rotation":{x:.613,y:.128,z:-.144},"LeftHandPinky3.rotation":{x:.268,y:.094,z:-.081},"RightShoulder.rotation":{x:1.541,y:.192,z:1.775},"RightArm.rotation":{x:1.273,y:-.352,z:-.067},"RightForeArm.rotation":{x:-.011,y:-.031,z:-.357},"RightHand.rotation":{x:-.008,y:.312,z:-.028},"RightHandThumb1.rotation":{x:.23,y:-.258,z:-.355},"RightHandThumb2.rotation":{x:-.107,y:.339,z:.454},"RightHandThumb3.rotation":{x:-.02,y:.142,z:.004},"RightHandIndex1.rotation":{x:.148,y:-.031,z:.069},"RightHandIndex2.rotation":{x:.326,y:.049,z:.029},"RightHandIndex3.rotation":{x:.247,y:.053,z:.073},"RightHandMiddle1.rotation":{x:.237,y:.057,z:.089},"RightHandMiddle2.rotation":{x:.469,y:.036,z:.081},"RightHandMiddle3.rotation":{x:.206,y:.015,z:.017},"RightHandRing1.rotation":{x:.204,y:.086,z:.135},"RightHandRing2.rotation":{x:.579,y:-.02,z:.098},"RightHandRing3.rotation":{x:.272,y:-.021,z:.063},"RightHandPinky1.rotation":{x:.404,y:.182,z:.137},"RightHandPinky2.rotation":{x:.613,y:-.128,z:.144},"RightHandPinky3.rotation":{x:.268,y:-.094,z:.081},"LeftUpLeg.rotation":{x:.096,y:.209,z:2.983},"LeftLeg.rotation":{x:-.053,y:.042,z:-.017},"LeftFoot.rotation":{x:1.091,y:.15,z:.026},"LeftToeBase.rotation":{x:.469,y:-.07,z:-.015},"RightUpLeg.rotation":{x:-.307,y:-.219,z:2.912},"RightLeg.rotation":{x:-.359,y:.164,z:.015},"RightFoot.rotation":{x:1.035,y:.11,z:.005},"RightToeBase.rotation":{x:.467,y:.07,z:.015}}},hip:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.036,y:.09,z:.135},"Spine.rotation":{x:.076,y:-.035,z:.01},"Spine1.rotation":{x:-.096,y:.013,z:-.094},"Spine2.rotation":{x:-.014,y:.002,z:-.097},"Neck.rotation":{x:.034,y:-.051,z:-.075},"Head.rotation":{x:.298,y:-.1,z:.154},"LeftShoulder.rotation":{x:1.694,y:.011,z:-1.68},"LeftArm.rotation":{x:1.343,y:.177,z:-.153},"LeftForeArm.rotation":{x:-.049,y:.134,z:.351},"LeftHand.rotation":{x:.057,y:-.189,z:-.026},"LeftHandThumb1.rotation":{x:.368,y:-.066,z:.438},"LeftHandThumb2.rotation":{x:-.156,y:.029,z:-.369},"LeftHandThumb3.rotation":{x:.034,y:-.009,z:.016},"LeftHandIndex1.rotation":{x:.157,y:-.002,z:-.171},"LeftHandIndex2.rotation":{x:.099,y:0,z:0},"LeftHandIndex3.rotation":{x:.1,y:0,z:0},"LeftHandMiddle1.rotation":{x:.222,y:-.019,z:-.16},"LeftHandMiddle2.rotation":{x:.142,y:0,z:0},"LeftHandMiddle3.rotation":{x:.141,y:0,z:0},"LeftHandRing1.rotation":{x:.333,y:-.039,z:-.174},"LeftHandRing2.rotation":{x:.214,y:0,z:0},"LeftHandRing3.rotation":{x:.213,y:0,z:0},"LeftHandPinky1.rotation":{x:.483,y:-.069,z:-.189},"LeftHandPinky2.rotation":{x:.312,y:0,z:0},"LeftHandPinky3.rotation":{x:.309,y:0,z:0},"RightShoulder.rotation":{x:1.597,y:.012,z:1.816},"RightArm.rotation":{x:.618,y:-1.274,z:-.266},"RightForeArm.rotation":{x:-.395,y:-.097,z:-1.342},"RightHand.rotation":{x:-.816,y:-.057,z:-.976},"RightHandThumb1.rotation":{x:.42,y:.23,z:-1.172},"RightHandThumb2.rotation":{x:-.027,y:.361,z:.122},"RightHandThumb3.rotation":{x:.076,y:.125,z:-.371},"RightHandIndex1.rotation":{x:-.158,y:-.045,z:.033},"RightHandIndex2.rotation":{x:.391,y:.051,z:.025},"RightHandIndex3.rotation":{x:.317,y:.058,z:.07},"RightHandMiddle1.rotation":{x:.486,y:.066,z:.014},"RightHandMiddle2.rotation":{x:.718,y:.055,z:.07},"RightHandMiddle3.rotation":{x:.453,y:.019,z:.013},"RightHandRing1.rotation":{x:.591,y:.241,z:.11},"RightHandRing2.rotation":{x:1.014,y:.023,z:.097},"RightHandRing3.rotation":{x:.708,y:.008,z:.066},"RightHandPinky1.rotation":{x:1.02,y:.305,z:.051},"RightHandPinky2.rotation":{x:1.187,y:-.028,z:.191},"RightHandPinky3.rotation":{x:.872,y:-.031,z:.121},"LeftUpLeg.rotation":{x:-.095,y:-.058,z:-3.338},"LeftLeg.rotation":{x:-.366,y:.287,z:-.021},"LeftFoot.rotation":{x:1.131,y:.21,z:.176},"LeftToeBase.rotation":{x:.739,y:-.068,z:-.001},"RightUpLeg.rotation":{x:-.502,y:.362,z:3.153},"RightLeg.rotation":{x:-1.002,y:.109,z:.008},"RightFoot.rotation":{x:.626,y:-.097,z:-.194},"RightToeBase.rotation":{x:1.33,y:.288,z:-.078}}},turn:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.07,y:-.604,z:-.004},"Spine.rotation":{x:-.007,y:.003,z:.071},"Spine1.rotation":{x:-.053,y:.024,z:-.06},"Spine2.rotation":{x:.074,y:.013,z:-.068},"Neck.rotation":{x:.03,y:.186,z:-.077},"Head.rotation":{x:.045,y:.243,z:-.086},"LeftShoulder.rotation":{x:1.717,y:-.085,z:-1.761},"LeftArm.rotation":{x:1.314,y:.07,z:-.057},"LeftForeArm.rotation":{x:-.151,y:.714,z:.302},"LeftHand.rotation":{x:-.069,y:.003,z:-.118},"LeftHandThumb1.rotation":{x:.23,y:.258,z:.354},"LeftHandThumb2.rotation":{x:-.107,y:-.338,z:-.455},"LeftHandThumb3.rotation":{x:-.015,y:-.142,z:.002},"LeftHandIndex1.rotation":{x:.145,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.323,y:-.049,z:-.028},"LeftHandIndex3.rotation":{x:.249,y:-.053,z:-.074},"LeftHandMiddle1.rotation":{x:.235,y:-.057,z:-.088},"LeftHandMiddle2.rotation":{x:.468,y:-.036,z:-.081},"LeftHandMiddle3.rotation":{x:.203,y:-.015,z:-.017},"LeftHandRing1.rotation":{x:.185,y:-.118,z:-.157},"LeftHandRing2.rotation":{x:.578,y:.02,z:-.097},"LeftHandRing3.rotation":{x:.27,y:.021,z:-.063},"LeftHandPinky1.rotation":{x:.404,y:-.182,z:-.138},"LeftHandPinky2.rotation":{x:.612,y:.128,z:-.144},"LeftHandPinky3.rotation":{x:.267,y:.094,z:-.081},"RightShoulder.rotation":{x:1.605,y:.17,z:1.625},"RightArm.rotation":{x:1.574,y:-.655,z:.388},"RightForeArm.rotation":{x:-.36,y:-.849,z:-.465},"RightHand.rotation":{x:.114,y:.416,z:-.069},"RightHandThumb1.rotation":{x:.486,y:.009,z:-.492},"RightHandThumb2.rotation":{x:-.073,y:-.01,z:.284},"RightHandThumb3.rotation":{x:-.054,y:-.006,z:.209},"RightHandIndex1.rotation":{x:.245,y:-.014,z:.052},"RightHandIndex2.rotation":{x:.155,y:0,z:0},"RightHandIndex3.rotation":{x:.153,y:0,z:0},"RightHandMiddle1.rotation":{x:.238,y:.004,z:.028},"RightHandMiddle2.rotation":{x:.15,y:0,z:0},"RightHandMiddle3.rotation":{x:.149,y:0,z:0},"RightHandRing1.rotation":{x:.267,y:.012,z:.007},"RightHandRing2.rotation":{x:.169,y:0,z:0},"RightHandRing3.rotation":{x:.167,y:0,z:0},"RightHandPinky1.rotation":{x:.304,y:.018,z:-.021},"RightHandPinky2.rotation":{x:.192,y:0,z:0},"RightHandPinky3.rotation":{x:.19,y:0,z:0},"LeftUpLeg.rotation":{x:-.001,y:-.058,z:-3.238},"LeftLeg.rotation":{x:-.29,y:.058,z:-.021},"LeftFoot.rotation":{x:1.288,y:.168,z:.183},"LeftToeBase.rotation":{x:.363,y:-.09,z:-.01},"RightUpLeg.rotation":{x:-.1,y:.36,z:3.062},"RightLeg.rotation":{x:-.67,y:-.304,z:.043},"RightFoot.rotation":{x:1.195,y:-.159,z:-.294},"RightToeBase.rotation":{x:.737,y:.164,z:-.002}}},bend:{bend:!0,standing:!0,props:{"Hips.position":{x:-.007,y:.943,z:-.001},"Hips.rotation":{x:1.488,y:-.633,z:1.435},"Spine.rotation":{x:-.126,y:.007,z:-.057},"Spine1.rotation":{x:-.134,y:.009,z:.01},"Spine2.rotation":{x:-.019,y:0,z:-.002},"Neck.rotation":{x:-.159,y:.572,z:-.108},"Head.rotation":{x:-.064,y:.716,z:-.257},"RightShoulder.rotation":{x:1.625,y:-.043,z:1.382},"RightArm.rotation":{x:.746,y:-.96,z:-1.009},"RightForeArm.rotation":{x:-.199,y:-.528,z:-.38},"RightHand.rotation":{x:-.261,y:-.043,z:-.027},"RightHandThumb1.rotation":{x:.172,y:-.138,z:-.445},"RightHandThumb2.rotation":{x:-.158,y:.327,z:.545},"RightHandThumb3.rotation":{x:-.062,y:.138,z:.152},"RightHandIndex1.rotation":{x:.328,y:-.005,z:.132},"RightHandIndex2.rotation":{x:.303,y:.049,z:.028},"RightHandIndex3.rotation":{x:.241,y:.046,z:.077},"RightHandMiddle1.rotation":{x:.309,y:.074,z:.089},"RightHandMiddle2.rotation":{x:.392,y:.036,z:.081},"RightHandMiddle3.rotation":{x:.199,y:.014,z:.019},"RightHandRing1.rotation":{x:.239,y:.143,z:.091},"RightHandRing2.rotation":{x:.275,y:-.02,z:.097},"RightHandRing3.rotation":{x:.248,y:-.023,z:.061},"RightHandPinky1.rotation":{x:.211,y:.154,z:.029},"RightHandPinky2.rotation":{x:.348,y:-.128,z:.144},"RightHandPinky3.rotation":{x:.21,y:-.091,z:.065},"LeftShoulder.rotation":{x:1.626,y:-.027,z:-1.367},"LeftArm.rotation":{x:1.048,y:.737,z:.712},"LeftForeArm.rotation":{x:-.508,y:.879,z:.625},"LeftHand.rotation":{x:.06,y:-.243,z:-.079},"LeftHandThumb1.rotation":{x:.187,y:-.072,z:.346},"LeftHandThumb2.rotation":{x:-.066,y:.008,z:-.256},"LeftHandThumb3.rotation":{x:-.085,y:.014,z:-.334},"LeftHandIndex1.rotation":{x:-.1,y:.016,z:-.058},"LeftHandIndex2.rotation":{x:.334,y:0,z:0},"LeftHandIndex3.rotation":{x:.281,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.056,y:0,z:0},"LeftHandMiddle2.rotation":{x:.258,y:0,z:0},"LeftHandMiddle3.rotation":{x:.26,y:0,z:0},"LeftHandRing1.rotation":{x:-.067,y:-.002,z:.008},"LeftHandRing2.rotation":{x:.259,y:0,z:0},"LeftHandRing3.rotation":{x:.276,y:0,z:0},"LeftHandPinky1.rotation":{x:-.128,y:-.007,z:.042},"LeftHandPinky2.rotation":{x:.227,y:0,z:0},"LeftHandPinky3.rotation":{x:.145,y:0,z:0},"RightUpLeg.rotation":{x:-1.507,y:.2,z:-3.043},"RightLeg.rotation":{x:-.689,y:-.124,z:.017},"RightFoot.rotation":{x:.909,y:.008,z:-.093},"RightToeBase.rotation":{x:.842,y:.075,z:-.008},"LeftUpLeg.rotation":{x:-1.449,y:-.2,z:3.018},"LeftLeg.rotation":{x:-.74,y:-.115,z:-.008},"LeftFoot.rotation":{x:1.048,y:-.058,z:.117},"LeftToeBase.rotation":{x:.807,y:-.067,z:.003}}},back:{standing:!0,props:{"Hips.position":{x:0,y:1,z:0},"Hips.rotation":{x:-.732,y:-1.463,z:-.637},"Spine.rotation":{x:-.171,y:.106,z:.157},"Spine1.rotation":{x:-.044,y:.138,z:-.059},"Spine2.rotation":{x:.082,y:.133,z:-.074},"Neck.rotation":{x:.39,y:.591,z:-.248},"Head.rotation":{x:-.001,y:.596,z:-.057},"LeftShoulder.rotation":{x:1.676,y:.007,z:-1.892},"LeftArm.rotation":{x:-5.566,y:1.188,z:-.173},"LeftForeArm.rotation":{x:-.673,y:-.105,z:1.702},"LeftHand.rotation":{x:-.469,y:-.739,z:.003},"LeftHandThumb1.rotation":{x:.876,y:.274,z:.793},"LeftHandThumb2.rotation":{x:.161,y:-.23,z:-.172},"LeftHandThumb3.rotation":{x:.078,y:.027,z:.156},"LeftHandIndex1.rotation":{x:-.085,y:-.002,z:.009},"LeftHandIndex2.rotation":{x:.176,y:0,z:-.002},"LeftHandIndex3.rotation":{x:-.036,y:.001,z:-.035},"LeftHandMiddle1.rotation":{x:.015,y:.144,z:-.076},"LeftHandMiddle2.rotation":{x:.378,y:-.007,z:-.077},"LeftHandMiddle3.rotation":{x:-.141,y:-.001,z:.031},"LeftHandRing1.rotation":{x:.039,y:.02,z:-.2},"LeftHandRing2.rotation":{x:.25,y:-.002,z:-.073},"LeftHandRing3.rotation":{x:.236,y:.006,z:-.075},"LeftHandPinky1.rotation":{x:.172,y:-.033,z:-.275},"LeftHandPinky2.rotation":{x:.216,y:.043,z:-.054},"LeftHandPinky3.rotation":{x:.325,y:.078,z:-.13},"RightShoulder.rotation":{x:2.015,y:-.168,z:1.706},"RightArm.rotation":{x:.203,y:-1.258,z:-.782},"RightForeArm.rotation":{x:-.658,y:-.133,z:-1.401},"RightHand.rotation":{x:-1.504,y:.375,z:-.005},"RightHandThumb1.rotation":{x:.413,y:-.158,z:-1.121},"RightHandThumb2.rotation":{x:-.142,y:-.008,z:.209},"RightHandThumb3.rotation":{x:-.091,y:.021,z:.142},"RightHandIndex1.rotation":{x:-.167,y:.014,z:-.072},"RightHandIndex2.rotation":{x:.474,y:.009,z:.051},"RightHandIndex3.rotation":{x:.115,y:.006,z:.047},"RightHandMiddle1.rotation":{x:.385,y:.019,z:.144},"RightHandMiddle2.rotation":{x:.559,y:.035,z:.101},"RightHandMiddle3.rotation":{x:.229,y:0,z:.027},"RightHandRing1.rotation":{x:.48,y:.026,z:.23},"RightHandRing2.rotation":{x:.772,y:.038,z:.109},"RightHandRing3.rotation":{x:.622,y:.039,z:.106},"RightHandPinky1.rotation":{x:.767,y:.288,z:.353},"RightHandPinky2.rotation":{x:.886,y:.049,z:.122},"RightHandPinky3.rotation":{x:.662,y:.044,z:.113},"LeftUpLeg.rotation":{x:-.206,y:-.268,z:-3.343},"LeftLeg.rotation":{x:-.333,y:.757,z:-.043},"LeftFoot.rotation":{x:1.049,y:.167,z:.287},"LeftToeBase.rotation":{x:.672,y:-.069,z:-.004},"RightUpLeg.rotation":{x:.055,y:-.226,z:3.037},"RightLeg.rotation":{x:-.559,y:.39,z:-.001},"RightFoot.rotation":{x:1.2,y:.133,z:.085},"RightToeBase.rotation":{x:.92,y:.093,z:-.013}}},straight:{standing:!0,props:{"Hips.position":{x:0,y:.989,z:.001},"Hips.rotation":{x:.047,y:.007,z:-.007},"Spine.rotation":{x:-.143,y:-.007,z:.005},"Spine1.rotation":{x:-.043,y:-.014,z:.012},"Spine2.rotation":{x:.072,y:-.013,z:.013},"Neck.rotation":{x:.048,y:-.003,z:.012},"Head.rotation":{x:.05,y:-.02,z:-.017},"LeftShoulder.rotation":{x:1.62,y:-.166,z:-1.605},"LeftArm.rotation":{x:1.275,y:.544,z:-.092},"LeftForeArm.rotation":{x:0,y:0,z:.302},"LeftHand.rotation":{x:-.225,y:-.154,z:.11},"LeftHandThumb1.rotation":{x:.435,y:-.044,z:.457},"LeftHandThumb2.rotation":{x:-.028,y:.002,z:-.246},"LeftHandThumb3.rotation":{x:-.236,y:-.025,z:.113},"LeftHandIndex1.rotation":{x:.218,y:.008,z:-.081},"LeftHandIndex2.rotation":{x:.165,y:-.001,z:-.017},"LeftHandIndex3.rotation":{x:.165,y:-.001,z:-.017},"LeftHandMiddle1.rotation":{x:.235,y:-.011,z:-.065},"LeftHandMiddle2.rotation":{x:.182,y:-.002,z:-.019},"LeftHandMiddle3.rotation":{x:.182,y:-.002,z:-.019},"LeftHandRing1.rotation":{x:.316,y:-.017,z:.008},"LeftHandRing2.rotation":{x:.253,y:-.003,z:-.026},"LeftHandRing3.rotation":{x:.255,y:-.003,z:-.026},"LeftHandPinky1.rotation":{x:.336,y:-.062,z:.088},"LeftHandPinky2.rotation":{x:.276,y:-.004,z:-.028},"LeftHandPinky3.rotation":{x:.276,y:-.004,z:-.028},"RightShoulder.rotation":{x:1.615,y:.064,z:1.53},"RightArm.rotation":{x:1.313,y:-.424,z:.131},"RightForeArm.rotation":{x:0,y:0,z:-.317},"RightHand.rotation":{x:-.158,y:-.639,z:-.196},"RightHandThumb1.rotation":{x:.44,y:.048,z:-.549},"RightHandThumb2.rotation":{x:-.056,y:-.008,z:.274},"RightHandThumb3.rotation":{x:-.258,y:.031,z:-.095},"RightHandIndex1.rotation":{x:.169,y:-.011,z:.105},"RightHandIndex2.rotation":{x:.134,y:.001,z:.011},"RightHandIndex3.rotation":{x:.134,y:.001,z:.011},"RightHandMiddle1.rotation":{x:.288,y:.014,z:.092},"RightHandMiddle2.rotation":{x:.248,y:.003,z:.02},"RightHandMiddle3.rotation":{x:.249,y:.003,z:.02},"RightHandRing1.rotation":{x:.369,y:.019,z:.006},"RightHandRing2.rotation":{x:.321,y:.004,z:.026},"RightHandRing3.rotation":{x:.323,y:.004,z:.026},"RightHandPinky1.rotation":{x:.468,y:.085,z:-.03},"RightHandPinky2.rotation":{x:.427,y:.007,z:.034},"RightHandPinky3.rotation":{x:.142,y:.001,z:.012},"LeftUpLeg.rotation":{x:-.077,y:-.058,z:3.126},"LeftLeg.rotation":{x:-.252,y:.001,z:-.018},"LeftFoot.rotation":{x:1.315,y:-.064,z:.315},"LeftToeBase.rotation":{x:.577,y:-.07,z:-.009},"RightUpLeg.rotation":{x:-.083,y:-.032,z:3.124},"RightLeg.rotation":{x:-.272,y:-.003,z:.021},"RightFoot.rotation":{x:1.342,y:.076,z:-.222},"RightToeBase.rotation":{x:.44,y:.069,z:.016}}},wide:{standing:!0,props:{"Hips.position":{x:0,y:1.017,z:.016},"Hips.rotation":{x:.064,y:-.048,z:.059},"Spine.rotation":{x:-.123,y:0,z:-.018},"Spine1.rotation":{x:.014,y:.003,z:-.006},"Spine2.rotation":{x:.04,y:.003,z:-.007},"Neck.rotation":{x:.101,y:.007,z:-.035},"Head.rotation":{x:-.091,y:-.049,z:.105},"RightShoulder.rotation":{x:1.831,y:.017,z:1.731},"RightArm.rotation":{x:-1.673,y:-1.102,z:-3.132},"RightForeArm.rotation":{x:.265,y:.23,z:-.824},"RightHand.rotation":{x:-.52,y:.345,z:-.061},"RightHandThumb1.rotation":{x:.291,y:.056,z:-.428},"RightHandThumb2.rotation":{x:.025,y:.005,z:.166},"RightHandThumb3.rotation":{x:-.089,y:.009,z:.068},"RightHandIndex1.rotation":{x:.392,y:-.015,z:.11},"RightHandIndex2.rotation":{x:.391,y:.001,z:.004},"RightHandIndex3.rotation":{x:.326,y:0,z:.003},"RightHandMiddle1.rotation":{x:.285,y:.068,z:.081},"RightHandMiddle2.rotation":{x:.519,y:.004,z:.011},"RightHandMiddle3.rotation":{x:.252,y:0,z:.001},"RightHandRing1.rotation":{x:.207,y:.133,z:.146},"RightHandRing2.rotation":{x:.597,y:.004,z:.004},"RightHandRing3.rotation":{x:.292,y:.002,z:.012},"RightHandPinky1.rotation":{x:.338,y:.182,z:.136},"RightHandPinky2.rotation":{x:.533,y:.002,z:.004},"RightHandPinky3.rotation":{x:.194,y:0,z:.002},"LeftShoulder.rotation":{x:1.83,y:-.063,z:-1.808},"LeftArm.rotation":{x:-1.907,y:1.228,z:-2.959},"LeftForeArm.rotation":{x:-.159,y:.268,z:.572},"LeftHand.rotation":{x:.069,y:-.498,z:-.025},"LeftHandThumb1.rotation":{x:.738,y:.123,z:.178},"LeftHandThumb2.rotation":{x:-.26,y:.028,z:-.477},"LeftHandThumb3.rotation":{x:-.448,y:.093,z:-.661},"LeftHandIndex1.rotation":{x:1.064,y:.005,z:-.13},"LeftHandIndex2.rotation":{x:1.55,y:-.143,z:-.136},"LeftHandIndex3.rotation":{x:.722,y:-.076,z:-.127},"LeftHandMiddle1.rotation":{x:1.095,y:-.091,z:.006},"LeftHandMiddle2.rotation":{x:1.493,y:-.174,z:-.151},"LeftHandMiddle3.rotation":{x:.651,y:-.031,z:-.087},"LeftHandRing1.rotation":{x:1.083,y:-.224,z:.072},"LeftHandRing2.rotation":{x:1.145,y:-.107,z:-.195},"LeftHandRing3.rotation":{x:1.208,y:-.134,z:-.158},"LeftHandPinky1.rotation":{x:.964,y:-.383,z:.128},"LeftHandPinky2.rotation":{x:1.457,y:-.146,z:-.159},"LeftHandPinky3.rotation":{x:1.019,y:-.102,z:-.141},"RightUpLeg.rotation":{x:-.221,y:-.233,z:2.87},"RightLeg.rotation":{x:-.339,y:-.043,z:-.041},"RightFoot.rotation":{x:1.081,y:.177,z:.114},"RightToeBase.rotation":{x:.775,y:0,z:0},"LeftUpLeg.rotation":{x:-.185,y:.184,z:3.131},"LeftLeg.rotation":{x:-.408,y:.129,z:.02},"LeftFoot.rotation":{x:1.167,y:-.002,z:-.007},"LeftToeBase.rotation":{x:.723,y:0,z:0}}},oneknee:{kneeling:!0,props:{"Hips.position":{x:-.005,y:.415,z:-.017},"Hips.rotation":{x:-.25,y:.04,z:-.238},"Spine.rotation":{x:.037,y:.043,z:.047},"Spine1.rotation":{x:.317,y:.103,z:.066},"Spine2.rotation":{x:.433,y:.109,z:.054},"Neck.rotation":{x:-.156,y:-.092,z:.059},"Head.rotation":{x:-.398,y:-.032,z:.018},"RightShoulder.rotation":{x:1.546,y:.119,z:1.528},"RightArm.rotation":{x:.896,y:-.247,z:-.512},"RightForeArm.rotation":{x:.007,y:0,z:-1.622},"RightHand.rotation":{x:1.139,y:-.853,z:.874},"RightHandThumb1.rotation":{x:.176,y:.107,z:-.311},"RightHandThumb2.rotation":{x:-.047,y:-.003,z:.12},"RightHandThumb3.rotation":{x:0,y:0,z:0},"RightHandIndex1.rotation":{x:.186,y:.005,z:.125},"RightHandIndex2.rotation":{x:.454,y:.005,z:.015},"RightHandIndex3.rotation":{x:0,y:0,z:0},"RightHandMiddle1.rotation":{x:.444,y:.035,z:.127},"RightHandMiddle2.rotation":{x:.403,y:-.006,z:-.04},"RightHandMiddle3.rotation":{x:0,y:0,z:0},"RightHandRing1.rotation":{x:.543,y:.074,z:.121},"RightHandRing2.rotation":{x:.48,y:-.018,z:-.063},"RightHandRing3.rotation":{x:0,y:0,z:0},"RightHandPinky1.rotation":{x:.464,y:.086,z:.113},"RightHandPinky2.rotation":{x:.667,y:-.06,z:-.128},"RightHandPinky3.rotation":{x:0,y:0,z:0},"LeftShoulder.rotation":{x:1.545,y:-.116,z:-1.529},"LeftArm.rotation":{x:.799,y:.631,z:.556},"LeftForeArm.rotation":{x:-.002,y:.007,z:.926},"LeftHand.rotation":{x:-.508,y:.439,z:.502},"LeftHandThumb1.rotation":{x:.651,y:-.035,z:.308},"LeftHandThumb2.rotation":{x:-.053,y:.008,z:-.11},"LeftHandThumb3.rotation":{x:0,y:0,z:0},"LeftHandIndex1.rotation":{x:.662,y:-.053,z:-.116},"LeftHandIndex2.rotation":{x:.309,y:-.004,z:-.02},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:.501,y:-.062,z:-.12},"LeftHandMiddle2.rotation":{x:.144,y:-.002,z:.016},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.397,y:-.029,z:-.143},"LeftHandRing2.rotation":{x:.328,y:.01,z:.059},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.194,y:.008,z:-.164},"LeftHandPinky2.rotation":{x:.38,y:.031,z:.128},"LeftHandPinky3.rotation":{x:0,y:0,z:0},"RightUpLeg.rotation":{x:-1.594,y:-.251,z:2.792},"RightLeg.rotation":{x:-2.301,y:-.073,z:.055},"RightFoot.rotation":{x:1.553,y:-.207,z:-.094},"RightToeBase.rotation":{x:.459,y:.069,z:.016},"LeftUpLeg.rotation":{x:-.788,y:-.236,z:-2.881},"LeftLeg.rotation":{x:-2.703,y:.012,z:-.047},"LeftFoot.rotation":{x:2.191,y:-.102,z:.019},"LeftToeBase.rotation":{x:1.215,y:-.027,z:.01}}},kneel:{kneeling:!0,lying:!0,props:{"Hips.position":{x:0,y:.532,z:-.002},"Hips.rotation":{x:.018,y:-.008,z:-.017},"Spine.rotation":{x:-.139,y:-.01,z:.002},"Spine1.rotation":{x:.002,y:-.002,z:.001},"Spine2.rotation":{x:.028,y:-.002,z:.001},"Neck.rotation":{x:-.007,y:0,z:-.002},"Head.rotation":{x:-.02,y:-.008,z:-.004},"LeftShoulder.rotation":{x:1.77,y:-.428,z:-1.588},"LeftArm.rotation":{x:.911,y:.343,z:.083},"LeftForeArm.rotation":{x:0,y:0,z:.347},"LeftHand.rotation":{x:.033,y:-.052,z:-.105},"LeftHandThumb1.rotation":{x:.508,y:-.22,z:.708},"LeftHandThumb2.rotation":{x:-.323,y:-.139,z:-.56},"LeftHandThumb3.rotation":{x:-.328,y:.16,z:-.301},"LeftHandIndex1.rotation":{x:.178,y:.248,z:.045},"LeftHandIndex2.rotation":{x:.236,y:-.002,z:-.019},"LeftHandIndex3.rotation":{x:-.062,y:0,z:.005},"LeftHandMiddle1.rotation":{x:.123,y:-.005,z:-.019},"LeftHandMiddle2.rotation":{x:.589,y:-.014,z:-.045},"LeftHandMiddle3.rotation":{x:.231,y:-.002,z:-.019},"LeftHandRing1.rotation":{x:.196,y:-.008,z:-.091},"LeftHandRing2.rotation":{x:.483,y:-.009,z:-.038},"LeftHandRing3.rotation":{x:.367,y:-.005,z:-.029},"LeftHandPinky1.rotation":{x:.191,y:-.269,z:-.246},"LeftHandPinky2.rotation":{x:.37,y:-.006,z:-.029},"LeftHandPinky3.rotation":{x:.368,y:-.005,z:-.029},"RightShoulder.rotation":{x:1.73,y:.434,z:1.715},"RightArm.rotation":{x:.841,y:-.508,z:-.155},"RightForeArm.rotation":{x:0,y:0,z:-.355},"RightHand.rotation":{x:.091,y:.137,z:.197},"RightHandThumb1.rotation":{x:.33,y:.051,z:-.753},"RightHandThumb2.rotation":{x:-.113,y:.075,z:.612},"RightHandThumb3.rotation":{x:-.271,y:-.166,z:.164},"RightHandIndex1.rotation":{x:.073,y:.001,z:-.093},"RightHandIndex2.rotation":{x:.338,y:.006,z:.034},"RightHandIndex3.rotation":{x:.131,y:.001,z:.013},"RightHandMiddle1.rotation":{x:.13,y:.005,z:-.017},"RightHandMiddle2.rotation":{x:.602,y:.018,z:.058},"RightHandMiddle3.rotation":{x:-.031,y:0,z:-.003},"RightHandRing1.rotation":{x:.351,y:.019,z:.045},"RightHandRing2.rotation":{x:.19,y:.002,z:.019},"RightHandRing3.rotation":{x:.21,y:.002,z:.021},"RightHandPinky1.rotation":{x:.256,y:.17,z:.118},"RightHandPinky2.rotation":{x:.451,y:.01,z:.045},"RightHandPinky3.rotation":{x:.346,y:.006,z:.035},"LeftUpLeg.rotation":{x:-.06,y:.1,z:-2.918},"LeftLeg.rotation":{x:-1.933,y:-.01,z:.011},"LeftFoot.rotation":{x:.774,y:-.162,z:-.144},"LeftToeBase.rotation":{x:1.188,y:0,z:0},"RightUpLeg.rotation":{x:-.099,y:-.057,z:2.922},"RightLeg.rotation":{x:-1.93,y:.172,z:-.02},"RightFoot.rotation":{x:.644,y:.251,z:.212},"RightToeBase.rotation":{x:.638,y:-.034,z:-.001}}},sitting:{sitting:!0,lying:!0,props:{"Hips.position":{x:0,y:.117,z:.005},"Hips.rotation":{x:-.411,y:-.049,z:.056},"Spine.rotation":{x:.45,y:-.039,z:-.116},"Spine1.rotation":{x:.092,y:-.076,z:.08},"Spine2.rotation":{x:.073,y:.035,z:.066},"Neck.rotation":{x:.051,y:.053,z:-.079},"Head.rotation":{x:-.169,y:.009,z:.034},"LeftShoulder.rotation":{x:1.756,y:-.037,z:-1.301},"LeftArm.rotation":{x:-.098,y:.016,z:1.006},"LeftForeArm.rotation":{x:-.089,y:.08,z:.837},"LeftHand.rotation":{x:.262,y:-.399,z:.3},"LeftHandThumb1.rotation":{x:.149,y:-.043,z:.452},"LeftHandThumb2.rotation":{x:.032,y:.006,z:-.162},"LeftHandThumb3.rotation":{x:-.086,y:-.005,z:-.069},"LeftHandIndex1.rotation":{x:.145,y:.032,z:-.069},"LeftHandIndex2.rotation":{x:.325,y:-.001,z:-.004},"LeftHandIndex3.rotation":{x:.253,y:0,z:-.003},"LeftHandMiddle1.rotation":{x:.186,y:-.051,z:-.091},"LeftHandMiddle2.rotation":{x:.42,y:-.003,z:-.011},"LeftHandMiddle3.rotation":{x:.153,y:.001,z:-.001},"LeftHandRing1.rotation":{x:.087,y:-.19,z:-.078},"LeftHandRing2.rotation":{x:.488,y:-.004,z:-.005},"LeftHandRing3.rotation":{x:.183,y:-.001,z:-.012},"LeftHandPinky1.rotation":{x:.205,y:-.262,z:.051},"LeftHandPinky2.rotation":{x:.407,y:-.002,z:-.004},"LeftHandPinky3.rotation":{x:.068,y:0,z:-.002},"RightShoulder.rotation":{x:1.619,y:-.139,z:1.179},"RightArm.rotation":{x:.17,y:-.037,z:-1.07},"RightForeArm.rotation":{x:-.044,y:-.056,z:-.665},"RightHand.rotation":{x:.278,y:.454,z:-.253},"RightHandThumb1.rotation":{x:.173,y:.089,z:-.584},"RightHandThumb2.rotation":{x:-.003,y:-.004,z:.299},"RightHandThumb3.rotation":{x:-.133,y:-.002,z:.235},"RightHandIndex1.rotation":{x:.393,y:-.023,z:.108},"RightHandIndex2.rotation":{x:.391,y:.001,z:.004},"RightHandIndex3.rotation":{x:.326,y:0,z:.003},"RightHandMiddle1.rotation":{x:.285,y:.062,z:.086},"RightHandMiddle2.rotation":{x:.519,y:.003,z:.011},"RightHandMiddle3.rotation":{x:.252,y:-.001,z:.001},"RightHandRing1.rotation":{x:.207,y:.122,z:.155},"RightHandRing2.rotation":{x:.597,y:.004,z:.005},"RightHandRing3.rotation":{x:.292,y:.001,z:.012},"RightHandPinky1.rotation":{x:.338,y:.171,z:.149},"RightHandPinky2.rotation":{x:.533,y:.002,z:.004},"RightHandPinky3.rotation":{x:.194,y:0,z:.002},"LeftUpLeg.rotation":{x:-1.957,y:.083,z:-2.886},"LeftLeg.rotation":{x:-1.46,y:.123,z:.005},"LeftFoot.rotation":{x:-.013,y:.016,z:.09},"LeftToeBase.rotation":{x:.744,y:0,z:0},"RightUpLeg.rotation":{x:-1.994,y:.125,z:2.905},"RightLeg.rotation":{x:-1.5,y:-.202,z:-.006},"RightFoot.rotation":{x:-.012,y:-.065,z:.081},"RightToeBase.rotation":{x:.758,y:0,z:0}}}},this.gestureTemplates={handup:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.815,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.529,y:-.2,z:.022},"LeftHandThumb1.rotation":{x:.745,y:-.526,z:.604},"LeftHandThumb2.rotation":{x:-.107,y:-.01,z:-.142},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:-.126,y:-.035,z:-.087},"LeftHandIndex2.rotation":{x:.255,y:.007,z:-.085},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.019,y:-.128,z:-.082},"LeftHandMiddle2.rotation":{x:.233,y:.019,z:-.074},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.005,y:-.241,z:-.122},"LeftHandRing2.rotation":{x:.261,y:.021,z:-.076},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.059,y:-.336,z:-.2},"LeftHandPinky2.rotation":{x:.153,y:.019,z:.001},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},index:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.815,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.276,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.579,y:.228,z:.363},"LeftHandThumb2.rotation":{x:-.027,y:-.04,z:-.662},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:0,y:-.105,z:.225},"LeftHandIndex2.rotation":{x:.256,y:-.103,z:-.213},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:1.453,y:.07,z:.021},"LeftHandMiddle2.rotation":{x:1.599,y:.062,z:.07},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:1.528,y:-.073,z:.052},"LeftHandRing2.rotation":{x:1.386,y:.044,z:.053},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:1.65,y:-.204,z:.031},"LeftHandPinky2.rotation":{x:1.302,y:.071,z:.085},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},ok:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,1],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.415,y:[-.4,0,1,2],z:1.575},"LeftHand.rotation":{x:-.476,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.703,y:.445,z:.899},"LeftHandThumb2.rotation":{x:-.312,y:-.04,z:-.938},"LeftHandThumb3.rotation":{x:-.37,y:.024,z:-.393},"LeftHandIndex1.rotation":{x:.8,y:-.086,z:-.091},"LeftHandIndex2.rotation":{x:1.123,y:-.046,z:-.074},"LeftHandIndex3.rotation":{x:.562,y:-.013,z:-.043},"LeftHandMiddle1.rotation":{x:-.019,y:-.128,z:-.082},"LeftHandMiddle2.rotation":{x:.233,y:.019,z:-.074},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.005,y:-.241,z:-.122},"LeftHandRing2.rotation":{x:.261,y:.021,z:-.076},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.059,y:-.336,z:-.2},"LeftHandPinky2.rotation":{x:.153,y:.019,z:.001},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},thumbup:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-.415,y:.206,z:1.575},"LeftHand.rotation":{x:-.276,y:-.506,z:-.208},"LeftHandThumb1.rotation":{x:.208,y:-.189,z:.685},"LeftHandThumb2.rotation":{x:.129,y:-.285,z:-.163},"LeftHandThumb3.rotation":{x:-.047,y:.068,z:.401},"LeftHandIndex1.rotation":{x:1.412,y:-.102,z:-.152},"LeftHandIndex2.rotation":{x:1.903,y:-.16,z:-.114},"LeftHandIndex3.rotation":{x:.535,y:-.017,z:-.062},"LeftHandMiddle1.rotation":{x:1.424,y:-.103,z:-.12},"LeftHandMiddle2.rotation":{x:1.919,y:-.162,z:-.114},"LeftHandMiddle3.rotation":{x:.44,y:-.012,z:-.051},"LeftHandRing1.rotation":{x:1.619,y:-.127,z:-.053},"LeftHandRing2.rotation":{x:1.898,y:-.16,z:-.115},"LeftHandRing3.rotation":{x:.262,y:-.004,z:-.031},"LeftHandPinky1.rotation":{x:1.661,y:-.131,z:-.016},"LeftHandPinky2.rotation":{x:1.715,y:-.067,z:-.13},"LeftHandPinky3.rotation":{x:.627,y:-.023,z:-.071}},thumbdown:{"LeftShoulder.rotation":{x:[1.5,2,1,2],y:[.2,.4,1,2],z:[-1.5,-1.3,1,2]},"LeftArm.rotation":{x:[1.5,1.7,1,2],y:[-.6,-.4,1,2],z:[1,1.2,1,2]},"LeftForeArm.rotation":{x:-2.015,y:.406,z:1.575},"LeftHand.rotation":{x:-.176,y:-.206,z:-.208},"LeftHandThumb1.rotation":{x:.208,y:-.189,z:.685},"LeftHandThumb2.rotation":{x:.129,y:-.285,z:-.163},"LeftHandThumb3.rotation":{x:-.047,y:.068,z:.401},"LeftHandIndex1.rotation":{x:1.412,y:-.102,z:-.152},"LeftHandIndex2.rotation":{x:1.903,y:-.16,z:-.114},"LeftHandIndex3.rotation":{x:.535,y:-.017,z:-.062},"LeftHandMiddle1.rotation":{x:1.424,y:-.103,z:-.12},"LeftHandMiddle2.rotation":{x:1.919,y:-.162,z:-.114},"LeftHandMiddle3.rotation":{x:.44,y:-.012,z:-.051},"LeftHandRing1.rotation":{x:1.619,y:-.127,z:-.053},"LeftHandRing2.rotation":{x:1.898,y:-.16,z:-.115},"LeftHandRing3.rotation":{x:.262,y:-.004,z:-.031},"LeftHandPinky1.rotation":{x:1.661,y:-.131,z:-.016},"LeftHandPinky2.rotation":{x:1.715,y:-.067,z:-.13},"LeftHandPinky3.rotation":{x:.627,y:-.023,z:-.071}},side:{"LeftShoulder.rotation":{x:1.755,y:-.035,z:-1.63},"LeftArm.rotation":{x:1.263,y:-.955,z:1.024},"LeftForeArm.rotation":{x:0,y:0,z:.8},"LeftHand.rotation":{x:-.36,y:-1.353,z:-.184},"LeftHandThumb1.rotation":{x:.137,y:-.049,z:.863},"LeftHandThumb2.rotation":{x:-.293,y:.153,z:-.193},"LeftHandThumb3.rotation":{x:-.271,y:-.17,z:.18},"LeftHandIndex1.rotation":{x:-.018,y:.007,z:.28},"LeftHandIndex2.rotation":{x:.247,y:-.003,z:-.025},"LeftHandIndex3.rotation":{x:.13,y:-.001,z:-.013},"LeftHandMiddle1.rotation":{x:.333,y:-.015,z:.182},"LeftHandMiddle2.rotation":{x:.313,y:-.005,z:-.032},"LeftHandMiddle3.rotation":{x:.294,y:-.004,z:-.03},"LeftHandRing1.rotation":{x:.456,y:-.028,z:-.092},"LeftHandRing2.rotation":{x:.53,y:-.014,z:-.052},"LeftHandRing3.rotation":{x:.478,y:-.012,z:-.047},"LeftHandPinky1.rotation":{x:.647,y:-.049,z:-.184},"LeftHandPinky2.rotation":{x:.29,y:-.004,z:-.029},"LeftHandPinky3.rotation":{x:.501,y:-.013,z:-.049}},shrug:{"Neck.rotation":{x:[-.3,.3,1,2],y:[-.3,.3,1,2],z:[-.1,.1]},"Head.rotation":{x:[-.3,.3],y:[-.3,.3],z:[-.1,.1]},"RightShoulder.rotation":{x:1.732,y:-.058,z:1.407},"RightArm.rotation":{x:1.305,y:.46,z:.118},"RightForeArm.rotation":{x:[0,2],y:[-1,.2],z:-1.637},"RightHand.rotation":{x:-.048,y:.165,z:-.39},"RightHandThumb1.rotation":{x:1.467,y:.599,z:-1.315},"RightHandThumb2.rotation":{x:-.255,y:-.123,z:.119},"RightHandThumb3.rotation":{x:0,y:-.002,z:0},"RightHandIndex1.rotation":{x:-.293,y:-.066,z:-.112},"RightHandIndex2.rotation":{x:.181,y:.007,z:.069},"RightHandIndex3.rotation":{x:0,y:0,z:0},"RightHandMiddle1.rotation":{x:-.063,y:-.041,z:.032},"RightHandMiddle2.rotation":{x:.149,y:.005,z:.05},"RightHandMiddle3.rotation":{x:0,y:0,z:0},"RightHandRing1.rotation":{x:.152,y:-.03,z:.132},"RightHandRing2.rotation":{x:.194,y:.007,z:.058},"RightHandRing3.rotation":{x:0,y:0,z:0},"RightHandPinky1.rotation":{x:.306,y:-.015,z:.257},"RightHandPinky2.rotation":{x:.15,y:-.003,z:-.003},"RightHandPinky3.rotation":{x:0,y:0,z:0},"LeftShoulder.rotation":{x:1.713,y:.141,z:-1.433},"LeftArm.rotation":{x:1.136,y:-.422,z:-.416},"LeftForeArm.rotation":{x:1.42,y:.123,z:1.506},"LeftHand.rotation":{x:.073,y:-.138,z:.064},"LeftHandThumb1.rotation":{x:1.467,y:-.599,z:1.314},"LeftHandThumb2.rotation":{x:-.255,y:.123,z:-.119},"LeftHandThumb3.rotation":{x:0,y:.001,z:0},"LeftHandIndex1.rotation":{x:-.293,y:.066,z:.112},"LeftHandIndex2.rotation":{x:.181,y:-.007,z:-.069},"LeftHandIndex3.rotation":{x:0,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.062,y:.041,z:-.032},"LeftHandMiddle2.rotation":{x:.149,y:-.005,z:-.05},"LeftHandMiddle3.rotation":{x:0,y:0,z:0},"LeftHandRing1.rotation":{x:.152,y:.03,z:-.132},"LeftHandRing2.rotation":{x:.194,y:-.007,z:-.058},"LeftHandRing3.rotation":{x:0,y:0,z:0},"LeftHandPinky1.rotation":{x:.306,y:.015,z:-.257},"LeftHandPinky2.rotation":{x:.15,y:.003,z:.003},"LeftHandPinky3.rotation":{x:0,y:0,z:0}},namaste:{"RightShoulder.rotation":{x:1.758,y:.099,z:1.604},"RightArm.rotation":{x:.862,y:-.292,z:-.932},"RightForeArm.rotation":{x:.083,y:.066,z:-1.791},"RightHand.rotation":{x:-.52,y:-.001,z:-.176},"RightHandThumb1.rotation":{x:.227,y:.418,z:-.776},"RightHandThumb2.rotation":{x:-.011,y:-.003,z:.171},"RightHandThumb3.rotation":{x:-.041,y:-.001,z:-.013},"RightHandIndex1.rotation":{x:-.236,y:.003,z:-.028},"RightHandIndex2.rotation":{x:.004,y:0,z:.001},"RightHandIndex3.rotation":{x:.002,y:0,z:0},"RightHandMiddle1.rotation":{x:-.236,y:.003,z:-.028},"RightHandMiddle2.rotation":{x:.004,y:0,z:.001},"RightHandMiddle3.rotation":{x:.002,y:0,z:0},"RightHandRing1.rotation":{x:-.236,y:.003,z:-.028},"RightHandRing2.rotation":{x:.004,y:0,z:.001},"RightHandRing3.rotation":{x:.002,y:0,z:0},"RightHandPinky1.rotation":{x:-.236,y:.003,z:-.028},"RightHandPinky2.rotation":{x:.004,y:0,z:.001},"RightHandPinky3.rotation":{x:.002,y:0,z:0},"LeftShoulder.rotation":{x:1.711,y:-.002,z:-1.625},"LeftArm.rotation":{x:.683,y:.334,z:.977},"LeftForeArm.rotation":{x:.086,y:-.066,z:1.843},"LeftHand.rotation":{x:-.595,y:-.229,z:.096},"LeftHandThumb1.rotation":{x:.404,y:-.05,z:.537},"LeftHandThumb2.rotation":{x:-.02,y:.004,z:-.154},"LeftHandThumb3.rotation":{x:-.049,y:.002,z:-.019},"LeftHandIndex1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandIndex2.rotation":{x:.003,y:0,z:0},"LeftHandIndex3.rotation":{x:.002,y:0,z:0},"LeftHandMiddle1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandMiddle2.rotation":{x:.004,y:0,z:0},"LeftHandMiddle3.rotation":{x:.002,y:0,z:0},"LeftHandRing1.rotation":{x:-.113,y:-.001,z:.014},"LeftHandRing2.rotation":{x:.003,y:0,z:0},"LeftHandRing3.rotation":{x:.002,y:0,z:0},"LeftHandPinky1.rotation":{x:-.122,y:-.001,z:-.057},"LeftHandPinky2.rotation":{x:.012,y:.001,z:.07},"LeftHandPinky3.rotation":{x:.002,y:0,z:0}}},this.poseDelta={props:{"Hips.quaternion":{x:0,y:0,z:0},"Spine.quaternion":{x:0,y:0,z:0},"Spine1.quaternion":{x:0,y:0,z:0},"Neck.quaternion":{x:0,y:0,z:0},"Head.quaternion":{x:0,y:0,z:0},"Spine1.scale":{x:0,y:0,z:0},"Neck.scale":{x:0,y:0,z:0},"LeftArm.scale":{x:0,y:0,z:0},"RightArm.scale":{x:0,y:0,z:0}}},["Left","Right"].forEach(a=>{["Leg","UpLeg","Arm","ForeArm","Hand"].forEach(l=>{this.poseDelta.props[a+l+".quaternion"]={x:0,y:0,z:0}}),["HandThumb","HandIndex","HandMiddle","HandRing","HandPinky"].forEach(l=>{this.poseDelta.props[a+l+"1.quaternion"]={x:0,y:0,z:0},this.poseDelta.props[a+l+"2.quaternion"]={x:0,y:0,z:0},this.poseDelta.props[a+l+"3.quaternion"]={x:0,y:0,z:0}})});const n=new Set;Object.values(this.poseTemplates).forEach(a=>{Object.keys(this.propsToThreeObjects(a.props)).forEach(l=>n.add(l))}),Object.keys(this.poseDelta.props).forEach(a=>{n.add(a)}),this.posePropNames=[...n],this.poseName="side",this.poseWeightOnLeft=!0,this.gesture=null,this.poseCurrentTemplate=this.poseTemplates[this.poseName],this.poseStraight=this.propsToThreeObjects(this.poseTemplates.straight.props),this.poseBase=this.poseFactory(this.poseCurrentTemplate),this.poseTarget=this.poseFactory(this.poseCurrentTemplate),this.poseAvatar=null,this.avatarHeight=1.7,this.animTemplateEyes={name:"eyes",idle:{alt:[{p:()=>this.avatar?.hasOwnProperty("avatarIdleEyeContact")?this.avatar.avatarIdleEyeContact:this.opt.avatarIdleEyeContact,delay:[200,5e3],dt:[200,[2e3,5e3],[3e3,1e4,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarIdleHeadMove")?this.avatar.avatarIdleHeadMove:this.opt.avatarIdleHeadMove],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]],eyeContact:[null,1]}},{delay:[200,5e3],dt:[200,[2e3,5e3,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarIdleHeadMove")?this.avatar.avatarIdleHeadMove:this.opt.avatarIdleHeadMove],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]]}}]},speaking:{alt:[{p:()=>this.avatar?.hasOwnProperty("avatarSpeakingEyeContact")?this.avatar.avatarSpeakingEyeContact:this.opt.avatarSpeakingEyeContact,delay:[200,5e3],dt:[0,[3e3,1e4,1,2],[2e3,5e3]],vs:{eyeContact:[1,null],headMove:[null,this.avatar?.hasOwnProperty("avatarSpeakingHeadMove")?this.avatar.avatarSpeakingHeadMove:this.opt.avatarSpeakingHeadMove,null],eyesRotateY:[null,[-.6,.6]],eyesRotateX:[null,[-.2,.6]]}},{delay:[200,5e3],dt:[200,[2e3,5e3,1,2]],vs:{headMove:[this.avatar?.hasOwnProperty("avatarSpeakingHeadMove")?this.avatar.avatarSpeakingHeadMove:this.opt.avatarSpeakingHeadMove,null],eyesRotateY:[[-.6,.6]],eyesRotateX:[[-.2,.6]]}}]}},this.animTemplateBlink={name:"blink",alt:[{p:.85,delay:[1e3,8e3,1,2],dt:[50,[100,300],100],vs:{eyeBlinkLeft:[1,1,0],eyeBlinkRight:[1,1,0]}},{delay:[1e3,4e3,1,2],dt:[50,[100,200],100,[10,400,0],50,[100,200],100],vs:{eyeBlinkLeft:[1,1,0,0,1,1,0],eyeBlinkRight:[1,1,0,0,1,1,0]}}]},this.animMoods={neutral:{baseline:{eyesLookDown:.1},speech:{deltaRate:0,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1200,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",alt:[{p:.5,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.3,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}},{delay:[5e3,3e4],vs:{pose:["straight"]}}]},{name:"head",idle:{delay:[0,1e3],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},happy:{baseline:{mouthSmile:.2,eyesLookDown:.1},speech:{deltaRate:0,deltaPitch:.1,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1200,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",idle:{alt:[{p:.6,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["side"]}}},{p:.1,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,1e4],vs:{pose:["wide"]}},{delay:[1e3,3e3],vs:{pose:["turn"]}}]},speaking:{alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}}]}},{name:"head",idle:{dt:[[1e3,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthLeft:[[0,.3,2]],mouthSmile:[[0,.2,3]],mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},angry:{baseline:{eyesLookDown:.1,browDownLeft:.6,browDownRight:.6,jawForward:.3,mouthFrownLeft:.7,mouthFrownRight:.7,mouthRollLower:.2,mouthShrugLower:.3,handFistLeft:1,handFistRight:1},speech:{deltaRate:-.2,deltaPitch:.2,deltaVolume:0},anims:[{name:"breathing",delay:500,dt:[1e3,500,1e3],vs:{chestInhale:[.7,.7,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["wide"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},sad:{baseline:{eyesLookDown:.2,browDownRight:.1,browInnerUp:.6,browOuterUpRight:.2,eyeSquintLeft:.7,eyeSquintRight:.7,mouthFrownLeft:.8,mouthFrownRight:.8,mouthLeft:.2,mouthPucker:.5,mouthRollLower:.2,mouthRollUpper:.2,mouthShrugLower:.2,mouthShrugUpper:.2,mouthStretchLeft:.4},speech:{deltaRate:-.2,deltaPitch:-.2,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.3,.3,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.4,delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["side"]},full:{delay:[5e3,2e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},fear:{baseline:{browInnerUp:.7,eyeSquintLeft:.5,eyeSquintRight:.5,eyeWideLeft:.6,eyeWideRight:.6,mouthClose:.1,mouthFunnel:.3,mouthShrugLower:.5,mouthShrugUpper:.5},speech:{deltaRate:-.2,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:500,dt:[1e3,500,1e3],vs:{chestInhale:[.7,.7,0]}},{name:"pose",alt:[{p:.8,delay:[5e3,3e4],vs:{pose:["side"]}},{delay:[5e3,3e4],vs:{pose:["straight"]}},{delay:[5e3,2e4],vs:{pose:["wide"]}},{delay:[5e3,2e4],vs:{pose:["side"]},full:{delay:[5e3,2e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{delay:[100,500],dt:[[200,3e3]],vs:{bodyRotateX:[[-.06,.12]],bodyRotateY:[[-.7,.7]],bodyRotateZ:[[-.1,.1]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},disgust:{baseline:{browDownLeft:.7,browDownRight:.1,browInnerUp:.3,eyeSquintLeft:1,eyeSquintRight:1,eyeWideLeft:.5,eyeWideRight:.5,eyesRotateX:.05,mouthLeft:.4,mouthPressLeft:.3,mouthRollLower:.3,mouthShrugLower:.3,mouthShrugUpper:.8,mouthUpperUpLeft:.3,noseSneerLeft:1,noseSneerRight:.7},speech:{deltaRate:-.2,deltaPitch:0,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.5,.5,0]}},{name:"pose",alt:[{delay:[5e3,2e4],vs:{pose:["side"]}}]},{name:"head",idle:{delay:[100,500],dt:[[200,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.2,.2]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.animTemplateBlink,{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[100,500],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[0,.3,2]],browOuterUpLeft:[[0,.3,2]],browOuterUpRight:[[0,.3,2]]}}]},love:{baseline:{browInnerUp:.4,browOuterUpLeft:.2,browOuterUpRight:.2,mouthSmile:.2,eyeBlinkLeft:.6,eyeBlinkRight:.6,eyeWideLeft:.7,eyeWideRight:.7,bodyRotateX:.1,mouthDimpleLeft:.1,mouthDimpleRight:.1,mouthPressLeft:.2,mouthShrugUpper:.2,mouthUpperUpLeft:.1,mouthUpperUpRight:.1},speech:{deltaRate:-.1,deltaPitch:-.7,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1500,500,1500],vs:{chestInhale:[.8,.8,0]}},{name:"pose",alt:[{p:.4,delay:[5e3,3e4],vs:{pose:["side"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["straight"]}},{p:.2,delay:[5e3,3e4],vs:{pose:["hip"]},M:{delay:[5e3,3e4],vs:{pose:["side"]}}},{delay:[5e3,1e4],vs:{pose:["side"]},full:{delay:[5e3,1e4],vs:{pose:["kneel"]}}},{delay:[1e3,3e3],vs:{pose:["turn"]},M:{delay:[1e3,3e3],vs:{pose:["wide"]}}},{delay:[1e3,3e3],vs:{pose:["back"]},M:{delay:[1e3,3e3],vs:{pose:["wide"]}}},{delay:[5e3,2e4],vs:{pose:["side"]},M:{delay:[5e3,2e4],vs:{pose:["side"]}},full:{delay:[5e3,2e4],vs:{pose:["bend"]}}},{delay:[1e3,3e3],vs:{pose:["side"]},full:{delay:[5e3,1e4],vs:{pose:["oneknee"]}}}]},{name:"head",idle:{dt:[[1e3,5e3]],vs:{bodyRotateX:[[-.04,.1]],bodyRotateY:[[-.3,.3]],bodyRotateZ:[[-.08,.08]]}},speaking:{dt:[[0,1e3,0]],vs:{bodyRotateX:[[-.05,.15,1,2]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.1,.1]]}}},this.animTemplateEyes,this.deepCopy(this.animTemplateBlink,a=>{a.alt[0].delay[0]=a.alt[1].delay[0]=2e3}),{name:"mouth",delay:[1e3,5e3],dt:[[100,500],[100,5e3,2]],vs:{mouthLeft:[[0,.3,2]],mouthRollLower:[[0,.3,2]],mouthRollUpper:[[0,.3,2]],mouthStretchLeft:[[0,.3]],mouthStretchRight:[[0,.3]],mouthPucker:[[0,.3]]}},{name:"misc",delay:[100,5e3],dt:[[500,1e3],[1e3,5e3,2]],vs:{eyeSquintLeft:[[0,.3,2]],eyeSquintRight:[[0,.3,2]],browInnerUp:[[.3,.6,2]],browOuterUpLeft:[[.1,.3,2]],browOuterUpRight:[[.1,.3,2]]}}]},sleep:{baseline:{eyeBlinkLeft:1,eyeBlinkRight:1,eyesClosed:.6},speech:{deltaRate:0,deltaPitch:-.2,deltaVolume:0},anims:[{name:"breathing",delay:1500,dt:[1e3,500,1e3],vs:{chestInhale:[.6,.6,0]}},{name:"pose",alt:[{delay:[5e3,2e4],vs:{pose:["side"]}}]},{name:"head",delay:[1e3,5e3],dt:[[2e3,1e4]],vs:{bodyRotateX:[[0,.4]],bodyRotateY:[[-.1,.1]],bodyRotateZ:[[-.04,.04]]}},{name:"eyes",delay:10010,dt:[],vs:{}},{name:"blink",delay:10020,dt:[],vs:{}},{name:"mouth",delay:10030,dt:[],vs:{}},{name:"misc",delay:10040,dt:[],vs:{}}]}},this.moodName=this.opt.avatarMood||"neutral",this.mood=this.animMoods[this.moodName],this.mood||(this.moodName="neutral",this.mood=this.animMoods.neutral),this.animEmojis={"😐":{dt:[300,2e3],rescale:[0,1],vs:{pose:["straight"],browInnerUp:[.4],eyeWideLeft:[.7],eyeWideRight:[.7],mouthPressLeft:[.6],mouthPressRight:[.6],mouthRollLower:[.3],mouthStretchLeft:[1],mouthStretchRight:[1]}},"😶":{link:"😐"},"😏":{dt:[300,2e3],rescale:[0,1],vs:{eyeContact:[0],browDownRight:[.1],browInnerUp:[.7],browOuterUpRight:[.2],eyeLookInRight:[.7],eyeLookOutLeft:[.7],eyeSquintLeft:[1],eyeSquintRight:[.8],eyesRotateY:[.7],mouthLeft:[.4],mouthPucker:[.4],mouthShrugLower:[.3],mouthShrugUpper:[.2],mouthSmile:[.2],mouthSmileLeft:[.4],mouthSmileRight:[.2],mouthStretchLeft:[.5],mouthUpperUpLeft:[.6],noseSneerLeft:[.7]}},"🙂":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5]}},"🙃":{link:"🙂"},"😊":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeSquintLeft:[1],eyeSquintRight:[1],mouthSmile:[.7],noseSneerLeft:[.7],noseSneerRight:[.7]}},"😇":{link:"😊"},"😀":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😃":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeWideLeft:[.7],eyeWideRight:[.7],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😄":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],jawOpen:[.2],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😁":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😆":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.6],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"😝":{dt:[300,100,1500,500,500],rescale:[0,0,1,0,0],vs:{browInnerUp:[.8],eyesClosed:[1],jawOpen:[.7],mouthFunnel:[.5],mouthSmile:[1],tongueOut:[0,1,1,0]}},"😋":{link:"😝"},"😛":{link:"😝"},"😛":{link:"😝"},"😜":{link:"😝"},"🤪":{link:"😝"},"😂":{dt:[300,2e3],rescale:[0,1],vs:{browInnerUp:[.3],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.6],jawOpen:[.3],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthPressLeft:[.5],mouthPressRight:[.5],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"🤣":{link:"😂"},"😅":{link:"😂"},"😉":{dt:[500,200,500,500],rescale:[0,0,0,1],vs:{mouthSmile:[.5],mouthOpen:[.2],mouthSmileLeft:[0,.5,0],eyeBlinkLeft:[0,.7,0],eyeBlinkRight:[0,0,0],bodyRotateX:[.05,.05,.05,0],bodyRotateZ:[-.05,-.05,-.05,0],browDownLeft:[0,.7,0],cheekSquintLeft:[0,.7,0],eyeSquintLeft:[0,1,0],eyesClosed:[0]}},"😭":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.1],jawOpen:[0],mouthFrownLeft:[1],mouthFrownRight:[1],mouthOpen:[.5],mouthPucker:[.5],mouthUpperUpLeft:[.6],mouthUpperUpRight:[.6]}},"🥺":{dt:[1e3,1e3],rescale:[0,1],vs:{browDownLeft:[.2],browDownRight:[.2],browInnerUp:[1],eyeWideLeft:[.9],eyeWideRight:[.9],eyesClosed:[.1],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[1],mouthRollLower:[.6],mouthRollUpper:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😞":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.7],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.5],bodyRotateX:[.3],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPucker:[1],mouthRollLower:[1],mouthShrugLower:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😔":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeSquintLeft:[1],eyeSquintRight:[1],eyesClosed:[.5],bodyRotateX:[.3],mouthClose:[.2],mouthFrownLeft:[1],mouthFrownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[1],mouthRollLower:[.6],mouthRollUpper:[.2],mouthUpperUpLeft:[.8],mouthUpperUpRight:[.8]}},"😳":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[1],eyeWideLeft:[.5],eyeWideRight:[.5],eyesRotateY:[.05],eyesRotateX:[.05],mouthClose:[.2],mouthFunnel:[.5],mouthPucker:[.4],mouthRollLower:[.4],mouthRollUpper:[.4]}},"☹️":{dt:[500,1500],rescale:[0,1],vs:{mouthFrownLeft:[1],mouthFrownRight:[1],mouthPucker:[.1],mouthRollLower:[.8]}},"😚":{dt:[500,1e3,1e3],rescale:[0,1,0],vs:{browInnerUp:[.6],eyeBlinkLeft:[1],eyeBlinkRight:[1],eyeSquintLeft:[1],eyeSquintRight:[1],mouthPucker:[0,.5],noseSneerLeft:[0,.7],noseSneerRight:[0,.7],viseme_U:[0,1]}},"😘":{dt:[500,500,200,500],rescale:[0,0,0,1],vs:{browInnerUp:[.6],eyeBlinkLeft:[0,0,1,0],eyeBlinkRight:[0],eyesRotateY:[0],bodyRotateY:[0],bodyRotateX:[0,.05,.05,0],bodyRotateZ:[0,-.05,-.05,0],eyeSquintLeft:[1],eyeSquintRight:[1],mouthPucker:[0,.5,0],noseSneerLeft:[0,.7],noseSneerRight:[.7],viseme_U:[0,1]}},"🥰":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.6],eyeSquintLeft:[1],eyeSquintRight:[1],mouthSmile:[.7],noseSneerLeft:[.7],noseSneerRight:[.7]}},"😍":{dt:[1e3,1e3],rescale:[0,1],vs:{browInnerUp:[.6],jawOpen:[.1],mouthDimpleLeft:[.2],mouthDimpleRight:[.2],mouthOpen:[.3],mouthPressLeft:[.3],mouthPressRight:[.3],mouthRollLower:[.4],mouthShrugUpper:[.4],mouthSmile:[.7],mouthUpperUpLeft:[.3],mouthUpperUpRight:[.3],noseSneerLeft:[.4],noseSneerRight:[.4]}},"🤩":{link:"😍"},"😡":{dt:[1e3,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15]}},"😠":{dt:[1e3,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15]}},"🤬":{link:"😠"},"😒":{dt:[1e3,1e3],rescale:[0,1],vs:{eyeContact:[0],browDownRight:[.1],browInnerUp:[.7],browOuterUpRight:[.2],eyeLookInRight:[.7],eyeLookOutLeft:[.7],eyeSquintLeft:[1],eyeSquintRight:[.8],eyesRotateY:[.7],mouthFrownLeft:[1],mouthFrownRight:[1],mouthLeft:[.2],mouthPucker:[.5],mouthRollLower:[.2],mouthRollUpper:[.2],mouthShrugLower:[.2],mouthShrugUpper:[.2],mouthStretchLeft:[.5]}},"😱":{dt:[500,1500],rescale:[0,1],vs:{browInnerUp:[.8],eyeWideLeft:[.5],eyeWideRight:[.5],jawOpen:[.7],mouthFunnel:[.5]}},"😬":{dt:[500,1500],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],browInnerUp:[1],mouthDimpleLeft:[.5],mouthDimpleRight:[.5],mouthLowerDownLeft:[1],mouthLowerDownRight:[1],mouthPressLeft:[.4],mouthPressRight:[.4],mouthPucker:[.5],mouthSmile:[.1],mouthSmileLeft:[.2],mouthSmileRight:[.2],mouthStretchLeft:[1],mouthStretchRight:[1],mouthUpperUpLeft:[1],mouthUpperUpRight:[1]}},"🙄":{dt:[500,1500],rescale:[0,1],vs:{browInnerUp:[.8],eyeWideLeft:[1],eyeWideRight:[1],eyesRotateX:[-.8],bodyRotateX:[.15],mouthPucker:[.5],mouthRollLower:[.6],mouthRollUpper:[.5],mouthShrugLower:[0],mouthSmile:[0]}},"🤔":{dt:[500,1500],rescale:[0,1],vs:{browDownLeft:[1],browOuterUpRight:[1],eyeSquintLeft:[.6],mouthFrownLeft:[.7],mouthFrownRight:[.7],mouthLowerDownLeft:[.3],mouthPressRight:[.4],mouthPucker:[.1],mouthRight:[.5],mouthRollLower:[.5],mouthRollUpper:[.2],handRight:[{x:.1,y:.1,z:.1,d:1e3},{d:1e3}],handFistRight:[.1]}},"👀":{dt:[500,1500],rescale:[0,1],vs:{eyesRotateY:[-.8]}},"😴":{dt:[5e3,5e3],rescale:[0,1],vs:{eyeBlinkLeft:[1],eyeBlinkRight:[1],bodyRotateX:[.2],bodyRotateZ:[.1]}},"✋":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["handup",2,!0],null]}},"🤚":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["handup",2],null]}},"👋":{link:"✋"},"👍":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["thumbup",2],null]}},"👎":{dt:[300,2e3],rescale:[0,1],vs:{browDownLeft:[1],browDownRight:[1],eyesLookUp:[.2],jawForward:[.3],mouthFrownLeft:[1],mouthFrownRight:[1],bodyRotateX:[.15],gesture:[["thumbdown",2],null]}},"👌":{dt:[300,2e3],rescale:[0,1],vs:{mouthSmile:[.5],gesture:[["ok",2],null]}},"🤷♂️":{dt:[1e3,1500],rescale:[0,1],vs:{gesture:[["shrug",2],null]}},"🤷♀️":{link:"🤷♂️"},"🤷":{link:"🤷♂️"},"🙏":{dt:[1500,300,1e3],rescale:[0,1,0],vs:{eyeBlinkLeft:[0,1],eyeBlinkRight:[0,1],bodyRotateX:[0],bodyRotateZ:[.1],gesture:[["namaste",2],null]}},yes:{dt:[[200,500],[200,500],[200,500],[200,500]],vs:{headMove:[0],headRotateX:[[.1,.2],.1,[.1,.2],0],headRotateZ:[[-.2,.2]]}},no:{dt:[[200,500],[200,500],[200,500],[200,500],[200,500]],vs:{headMove:[0],headRotateY:[[-.1,-.05],[.05,.1],[-.1,-.05],[.05,.1],0],headRotateZ:[[-.2,.2]]}}},this.mtAvatar={},this.mtCustoms=["handFistLeft","handFistRight","bodyRotateX","bodyRotateY","bodyRotateZ","headRotateX","headRotateY","headRotateZ","chestInhale"],this.mtEasingDefault=this.sigmoidFactory(5),this.mtAccDefault=.01,this.mtAccExceptions={eyeBlinkLeft:.1,eyeBlinkRight:.1,eyeLookOutLeft:.1,eyeLookInLeft:.1,eyeLookOutRight:.1,eyeLookInRight:.1},this.mtMaxVDefault=5,this.mtMaxVExceptions={bodyRotateX:1,bodyRotateY:1,bodyRotateZ:1},this.mtBaselineDefault=0,this.mtBaselineExceptions={bodyRotateX:null,bodyRotateY:null,bodyRotateZ:null,eyeLookOutLeft:null,eyeLookInLeft:null,eyeLookOutRight:null,eyeLookInRight:null,eyesLookDown:null,eyesLookUp:null},this.mtMinDefault=0,this.mtMinExceptions={bodyRotateX:-1,bodyRotateY:-1,bodyRotateZ:-1,headRotateX:-1,headRotateY:-1,headRotateZ:-1},this.mtMaxDefault=1,this.mtMaxExceptions={},this.mtLimits={eyeBlinkLeft:a=>Math.max(a,(this.mtAvatar.eyesLookDown.value+this.mtAvatar.browDownLeft.value)/2),eyeBlinkRight:a=>Math.max(a,(this.mtAvatar.eyesLookDown.value+this.mtAvatar.browDownRight.value)/2)},this.mtOnchange={eyesLookDown:()=>{this.mtAvatar.eyeBlinkLeft.needsUpdate=!0,this.mtAvatar.eyeBlinkRight.needsUpdate=!0},browDownLeft:()=>{this.mtAvatar.eyeBlinkLeft.needsUpdate=!0},browDownRight:()=>{this.mtAvatar.eyeBlinkRight.needsUpdate=!0}},this.mtRandomized=["mouthDimpleLeft","mouthDimpleRight","mouthLeft","mouthPressLeft","mouthPressRight","mouthStretchLeft","mouthStretchRight","mouthShrugLower","mouthShrugUpper","noseSneerLeft","noseSneerRight","mouthRollLower","mouthRollUpper","browDownLeft","browDownRight","browOuterUpLeft","browOuterUpRight","cheekPuff","cheekSquintLeft","cheekSquintRight"],this.mtExtras=[{key:"mouthOpen",mix:{jawOpen:.5}},{key:"mouthSmile",mix:{mouthSmileLeft:.8,mouthSmileRight:.8}},{key:"eyesClosed",mix:{eyeBlinkLeft:1,eyeBlinkRight:1}},{key:"eyesLookUp",mix:{eyeLookUpLeft:1,eyeLookUpRight:1}},{key:"eyesLookDown",mix:{eyeLookDownLeft:1,eyeLookDownRight:1}}],this.animQueue=[],this.animClips=[],this.animPoses=[],this.animFrameDur=1e3/this.opt.modelFPS,this.animClock=0,this.animSlowdownRate=1,this.animTimeLast=0,this.easing=this.sigmoidFactory(5),this.lipsync={},this.opt.lipsyncModules.forEach(a=>{this.lipsyncGetProcessor(a)}),this.visemeNames=["aa","E","I","O","U","PP","SS","TH","DD","FF","kk","nn","RR","CH","sil"],this.segmenter=new Intl.Segmenter("en",{granularity:"grapheme"}),this.initAudioGraph(),this.audioPlaylist=[],this.volumeFrequencyData=new Uint8Array(16),this.volumeMax=0,this.volumeHeadBase=0,this.volumeHeadTarget=0,this.volumeHeadCurrent=0,this.volumeHeadVelocity=.15,this.volumeHeadEasing=this.sigmoidFactory(3),this.isListening=!1,this.listeningAnalyzer=null,this.listeningActive=!1,this.listeningVolume=0,this.listeningSilenceThresholdLevel=this.opt.listeningSilenceThresholdLevel,this.listeningSilenceThresholdMs=this.opt.listeningSilenceThresholdMs,this.listeningSilenceDurationMax=this.opt.listeningSilenceDurationMax,this.listeningActiveThresholdLevel=this.opt.listeningActiveThresholdLevel,this.listeningActiveThresholdMs=this.opt.listeningActiveThresholdMs,this.listeningActiveDurationMax=this.opt.listeningActiveDurationMax,this.listeningTimer=0,this.listeningTimerTotal=0,this.dracoEnabled=this.opt.dracoEnabled,this.dracoDecoderPath=this.opt.dracoDecoderPath;const i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";this.b64Lookup=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let a=0;a<i.length;a++)this.b64Lookup[i.charCodeAt(a)]=a;if(this.stateName="idle",this.speechQueue=[],this.isSpeaking=!1,this.isListening=!1,this.opt.ttsEndpoint){let a=new Audio;if(a.canPlayType("audio/ogg"))this.ttsAudioEncoding="OGG-OPUS";else if(a.canPlayType("audio/mp3"))this.ttsAudioEncoding="MP3";else throw new Error("There was no support for either OGG or MP3 audio.")}if(this.isAvatarOnly=this.opt.avatarOnly,this.isAvatarOnly)this.scene=this.opt.avatarOnlyScene,this.camera=this.opt.avatarOnlyCamera;else{this.renderer=new v.WebGLRenderer({antialias:!0,alpha:!0}),this.renderer.setPixelRatio(this.opt.modelPixelRatio*window.devicePixelRatio),this.renderer.setSize(this.nodeAvatar.clientWidth,this.nodeAvatar.clientHeight),this.renderer.outputColorSpace=v.SRGBColorSpace,this.renderer.toneMapping=v.ACESFilmicToneMapping,this.renderer.shadowMap.enabled=!1,this.nodeAvatar.appendChild(this.renderer.domElement),this.camera=new v.PerspectiveCamera(10,this.nodeAvatar.clientWidth/this.nodeAvatar.clientHeight,.1,2e3),this.scene=new v.Scene,this.lightAmbient=new v.AmbientLight(new v.Color(this.opt.lightAmbientColor),this.opt.lightAmbientIntensity),this.lightDirect=new v.DirectionalLight(new v.Color(this.opt.lightDirectColor),this.opt.lightDirectIntensity),this.lightSpot=new v.SpotLight(new v.Color(this.opt.lightSpotColor),this.opt.lightSpotIntensity,0,this.opt.lightSpotDispersion),this.setLighting(this.opt);const a=new v.PMREMGenerator(this.renderer);a.compileEquirectangularShader(),this.scene.environment=a.fromScene(new gi).texture,this.resizeobserver=new ResizeObserver(this.onResize.bind(this)),this.resizeobserver.observe(this.nodeAvatar),this.controls=new _t(this.camera,this.renderer.domElement),this.controls.enableZoom=this.opt.cameraZoomEnable,this.controls.enableRotate=this.opt.cameraRotateEnable,this.controls.enablePan=this.opt.cameraPanEnable,this.controls.minDistance=2,this.controls.maxDistance=2e3,this.controls.autoRotateSpeed=0,this.controls.autoRotate=!1,this.controls.update(),this.cameraClock=null}this.ikMesh=new v.SkinnedMesh;const s={LeftShoulder:null,LeftArm:"LeftShoulder",LeftForeArm:"LeftArm",LeftHand:"LeftForeArm",LeftHandMiddle1:"LeftHand",RightShoulder:null,RightArm:"RightShoulder",RightForeArm:"RightArm",RightHand:"RightForeArm",RightHandMiddle1:"RightHand"},o=[];Object.entries(s).forEach((a,l)=>{const r=new v.Bone;r.name=a[0],a[1]?this.ikMesh.getObjectByName(a[1]).add(r):this.ikMesh.add(r),o.push(r)}),this.ikMesh.bind(new v.Skeleton(o)),this.dynamicbones=new Ri,this.isStreaming=!1,this.streamWorkletNode=null,this.streamAudioStartTime=null,this.streamWaitForAudioChunks=!0,this.streamLipsyncLang=null,this.streamLipsyncType="visemes",this.streamLipsyncQueue=[]}initAudioGraph(e=null){if(this.audioCtx&&this.audioCtx.state!=="closed"&&this.audioCtx.close(),e?this.audioCtx=new AudioContext({sampleRate:e}):this.audioCtx=new AudioContext,this.audioSpeechSource=this.audioCtx.createBufferSource(),this.audioBackgroundSource=this.audioCtx.createBufferSource(),this.audioBackgroundGainNode=this.audioCtx.createGain(),this.audioSpeechGainNode=this.audioCtx.createGain(),this.audioStreamGainNode=this.audioCtx.createGain(),this.audioAnalyzerNode=this.audioCtx.createAnalyser(),this.audioAnalyzerNode.fftSize=256,this.audioAnalyzerNode.smoothingTimeConstant=.1,this.audioAnalyzerNode.minDecibels=-70,this.audioAnalyzerNode.maxDecibels=-10,this.audioAnalyzer=new vi(this.audioCtx),this.audioReverbNode=this.audioCtx.createConvolver(),this.audioBackgroundGainNode.connect(this.audioReverbNode),this.audioAnalyzerNode.connect(this.audioSpeechGainNode),this.audioSpeechGainNode.connect(this.audioReverbNode),this.audioStreamGainNode.connect(this.audioReverbNode),this.audioReverbNode.connect(this.audioCtx.destination),this.setReverb(this.currentReverb||null),this.setMixerGain(this.opt.mixerGainSpeech,this.opt.mixerGainBackground),this.workletLoaded=!1,this.streamWorkletNode){try{this.streamWorkletNode.port.postMessage({type:"stop"}),this.streamWorkletNode.disconnect(),this.isStreaming=!1}catch(t){console.error("Error disconnecting streamWorkletNode:",t)}this.streamWorkletNode=null}}valueFn(e){return typeof e=="function"?e():e}deepCopy(e,t=null){const n=JSON.parse(JSON.stringify(e));return t&&typeof t=="function"&&t(n),n}b64ToArrayBuffer(e){let t=3*e.length/4;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);const n=new ArrayBuffer(t),i=new Uint8Array(n);let s,o=0,a,l,r,h;for(s=0;s<e.length;s+=4)a=this.b64Lookup[e.charCodeAt(s)],l=this.b64Lookup[e.charCodeAt(s+1)],r=this.b64Lookup[e.charCodeAt(s+2)],h=this.b64Lookup[e.charCodeAt(s+3)],i[o++]=a<<2|l>>4,i[o++]=(l&15)<<4|r>>2,i[o++]=(r&3)<<6|h&63;return n}concatArrayBuffers(e){if(e.length===1)return e[0];let t=0;for(let o=0;o<e.length;o++)t+=e[o].byteLength;let n=new ArrayBuffer(t),i=new Uint8Array(n),s=0;for(let o=0;o<e.length;o++)i.set(new Uint8Array(e[o]),s),s+=e[o].byteLength;return n}pcmToAudioBuffer(e){const t=new Int16Array(e),n=new Float32Array(t.length);for(let s=0;s<t.length;s++)n[s]=t[s]>=32768?-(65536-t[s])/32768:t[s]/32767;const i=this.audioCtx.createBuffer(1,n.length,this.opt.pcmSampleRate);return i.copyToChannel(n,0,0),i}propsToThreeObjects(e){const t={};for(let[n,i]of Object.entries(e)){const s=n.split(".");let o=Array.isArray(i.x)?this.gaussianRandom(...i.x):i.x,a=Array.isArray(i.y)?this.gaussianRandom(...i.y):i.y,l=Array.isArray(i.z)?this.gaussianRandom(...i.z):i.z;s[1]==="position"||s[1]==="scale"?t[n]=new v.Vector3(o,a,l):s[1]==="rotation"?(n=s[0]+".quaternion",t[n]=new v.Quaternion().setFromEuler(new v.Euler(o,a,l,"XYZ")).normalize()):s[1]==="quaternion"&&(t[n]=new v.Quaternion(o,a,l,i.w).normalize())}return t}clearThree(e){for(;e.children.length;)this.clearThree(e.children[0]),e.remove(e.children[0]);e.geometry&&e.geometry.dispose(),e.material&&(Object.keys(e.material).forEach(t=>{e.material[t]&&e.material[t]!==null&&typeof e.material[t].dispose=="function"&&e.material[t].dispose()}),e.material.dispose())}addMixedMorphTarget(e,t,n,i=!1){e.forEach(s=>{if(!i&&s.morphTargetDictionary.hasOwnProperty(t))return;const o=s.geometry;let a=null,l=null;for(const[r,h]of Object.entries(n))if(s.morphTargetDictionary.hasOwnProperty(r)){const c=s.morphTargetDictionary[r],u=o.morphAttributes.position[c],d=o.morphAttributes.normal?.[c];a||(a=new v.Float32BufferAttribute(u.count*3,3),d&&(l=new v.Float32BufferAttribute(u.count*3,3)));for(let f=0;f<u.count;f++){const x=a.getX(f)+u.getX(f)*h,y=a.getY(f)+u.getY(f)*h,R=a.getZ(f)+u.getZ(f)*h;a.setXYZ(f,x,y,R)}if(d)for(let f=0;f<u.count;f++){const x=l.getX(f)+d.getX(f)*h,y=l.getY(f)+d.getY(f)*h,R=l.getZ(f)+d.getZ(f)*h;l.setXYZ(f,x,y,R)}}if(a){o.morphAttributes.position.push(a),l&&o.morphAttributes.normal.push(l);const r=o.morphAttributes.position.length-1;s.morphTargetInfluences[r]=0,s.morphTargetDictionary[t]=r}})}async showAvatar(e,t=null){if(!e||!e.hasOwnProperty("url"))throw new Error("Invalid parameter. The avatar must have at least 'url' specified.");const n=new qt;if(this.dracoEnabled){const r=new Hn;r.setDecoderPath(this.dracoDecoderPath),n.setDRACOLoader(r)}let i=await n.loadAsync(e.url,t);const s=[this.opt.modelRoot];if(this.posePropNames.forEach(r=>s.push(r.split(".")[0])),s.forEach(r=>{if(!i.scene.getObjectByName(r))throw new Error("Avatar object "+r+" not found")}),this.stop(),this.avatar=e,this.bodyMovement=e.bodyMovement||"idle",this.movementIntensity=e.movementIntensity||.5,this.showFullAvatar=e.showFullAvatar||!1,this.fbxAnimationLoader=null,this.dynamicbones.dispose(),this.mixer=null,this.isAvatarOnly?this.armature&&this.clearThree(this.armature):this.armature&&this.clearThree(this.scene),this.armature=i.scene.getObjectByName(this.opt.modelRoot),this.armature.scale.setScalar(1),this.animations=i.animations,this.userData=i.userData,this.morphs=[],this.armature.traverse(r=>{r.morphTargetInfluences&&r.morphTargetInfluences.length&&r.morphTargetDictionary&&this.morphs.push(r),r.frustumCulled=!1}),this.morphs.length===0)throw new Error("Blend shapes not found");const o=new Set(this.mtCustoms);this.morphs.forEach(r=>{Object.keys(r.morphTargetDictionary).forEach(h=>o.add(h))}),this.mtExtras.forEach(r=>{o.has(r.key)||(this.addMixedMorphTarget(this.morphs,r.key,r.mix),o.add(r.key))});const a={};if(o.forEach(r=>{a[r]={fixed:null,realtime:null,system:null,systemd:null,newvalue:null,ref:null,min:this.mtMinExceptions.hasOwnProperty(r)?this.mtMinExceptions[r]:this.mtMinDefault,max:this.mtMaxExceptions.hasOwnProperty(r)?this.mtMaxExceptions[r]:this.mtMaxDefault,easing:this.mtEasingDefault,base:null,v:0,needsUpdate:!0,acc:(this.mtAccExceptions.hasOwnProperty(r)?this.mtAccExceptions[r]:this.mtAccDefault)/1e3,maxv:(this.mtMaxVExceptions.hasOwnProperty(r)?this.mtMaxVExceptions[r]:this.mtMaxVDefault)/1e3,limit:this.mtLimits.hasOwnProperty(r)?this.mtLimits[r]:null,onchange:this.mtOnchange.hasOwnProperty(r)?this.mtOnchange[r]:null,baseline:this.avatar.baseline?.hasOwnProperty(r)?this.avatar.baseline[r]:this.mtBaselineExceptions.hasOwnProperty(r)?this.mtBaselineExceptions[r]:this.mtBaselineDefault,ms:[],is:[]},a[r].value=a[r].baseline,a[r].applied=a[r].baseline;const h=this.mtAvatar[r];h&&["fixed","system","systemd","realtime","base","v","value","applied"].forEach(c=>{a[r][c]=h[c]}),this.morphs.forEach(c=>{const u=c.morphTargetDictionary[r];u!==void 0&&(a[r].ms.push(c.morphTargetInfluences),a[r].is.push(u),c.morphTargetInfluences[u]=a[r].applied)})}),this.mtAvatar=a,this.poseAvatar={props:{}},this.posePropNames.forEach(r=>{const h=r.split("."),c=this.armature.getObjectByName(h[0]);this.poseAvatar.props[r]=c[h[1]],this.poseBase.props.hasOwnProperty(r)?this.poseAvatar.props[r].copy(this.poseBase.props[r]):this.poseBase.props[r]=this.poseAvatar.props[r].clone(),this.poseDelta.props.hasOwnProperty(r)&&!this.poseTarget.props.hasOwnProperty(r)&&(this.poseTarget.props[r]=this.poseAvatar.props[r].clone()),this.poseTarget.props[r].t=this.animClock,this.poseTarget.props[r].d=2e3}),this.ikMesh.traverse(r=>{r.isBone&&r.position.copy(this.armature.getObjectByName(r.name).position)}),this.isAvatarOnly?this.scene&&this.scene.add(this.armature):(this.scene.add(i.scene),this.scene.add(this.lightAmbient),this.scene.add(this.lightDirect),this.scene.add(this.lightSpot),this.lightSpot.target=this.armature.getObjectByName("Head")),e.hasOwnProperty("modelDynamicBones"))try{this.dynamicbones.setup(this.scene,this.armature,e.modelDynamicBones)}catch(r){console.error("Dynamic bones setup failed: "+r)}this.objectLeftToeBase=this.armature.getObjectByName("LeftToeBase"),this.objectRightToeBase=this.armature.getObjectByName("RightToeBase"),this.objectLeftEye=this.armature.getObjectByName("LeftEye"),this.objectRightEye=this.armature.getObjectByName("RightEye"),this.objectLeftArm=this.armature.getObjectByName("LeftArm"),this.objectRightArm=this.armature.getObjectByName("RightArm"),this.objectHips=this.armature.getObjectByName("Hips"),this.objectHead=this.armature.getObjectByName("Head"),this.objectNeck=this.armature.getObjectByName("Neck");const l=new v.Vector3;this.objectLeftEye.getWorldPosition(l),this.avatarHeight=l.y+.2,this.viewName||this.setView(this.opt.cameraView),this.setMood(this.avatar.avatarMood||this.moodName||this.opt.avatarMood),this.initializeFBXAnimationLoader(),this.bodyMovement&&this.bodyMovement!=="idle"&&this.applyBodyMovementAnimation(),this.start()}getViewNames(){return["full","mid","upper","head"]}getView(){return this.viewName}setView(e,t=null){if(e=e||this.viewName,e!=="full"&&e!=="upper"&&e!=="head"&&e!=="mid")return;if(!this.armature){this.opt.cameraView=e;return}if(this.viewName=e||this.viewName,t=t||{},this.isAvatarOnly)return;const n=t.hasOwnProperty("cameraX")?t.cameraX:this.opt.cameraX,i=t.hasOwnProperty("cameraY")?t.cameraY:this.opt.cameraY,s=t.hasOwnProperty("cameraDistance")?t.cameraDistance:this.opt.cameraDistance,o=t.hasOwnProperty("cameraRotateX")?t.cameraRotateX:this.opt.cameraRotateX,a=t.hasOwnProperty("cameraRotateY")?t.cameraRotateY:this.opt.cameraRotateY,l=this.camera.fov*(Math.PI/180);let r=-n*Math.tan(l/2),h=(1-i)*Math.tan(l/2),c=s;switch(this.viewName){case"head":c+=2,h=h*c+4*this.avatarHeight/5;break;case"upper":c+=4.5,h=h*c+2*this.avatarHeight/3;break;case"mid":c+=8,h=h*c+this.avatarHeight/3;break;default:c+=12,h=h*c}r=r*c,this.controlsEnd=new v.Vector3(r,h,0),this.cameraEnd=new v.Vector3(r,h,c).applyEuler(new v.Euler(o,a,0)),this.cameraClock===null&&(this.controls.target.copy(this.controlsEnd),this.camera.position.copy(this.cameraEnd)),this.controlsStart=this.controls.target.clone(),this.cameraStart=this.camera.position.clone(),this.cameraClock=0}setLighting(e){this.isAvatarOnly||(e=e||{},e.hasOwnProperty("lightAmbientColor")&&this.lightAmbient.color.set(new v.Color(e.lightAmbientColor)),e.hasOwnProperty("lightAmbientIntensity")&&(this.lightAmbient.intensity=e.lightAmbientIntensity,this.lightAmbient.visible=e.lightAmbientIntensity!==0),e.hasOwnProperty("lightDirectColor")&&this.lightDirect.color.set(new v.Color(e.lightDirectColor)),e.hasOwnProperty("lightDirectIntensity")&&(this.lightDirect.intensity=e.lightDirectIntensity,this.lightDirect.visible=e.lightDirectIntensity!==0),e.hasOwnProperty("lightDirectPhi")&&e.hasOwnProperty("lightDirectTheta")&&this.lightDirect.position.setFromSphericalCoords(2,e.lightDirectPhi,e.lightDirectTheta),e.hasOwnProperty("lightSpotColor")&&this.lightSpot.color.set(new v.Color(e.lightSpotColor)),e.hasOwnProperty("lightSpotIntensity")&&(this.lightSpot.intensity=e.lightSpotIntensity,this.lightSpot.visible=e.lightSpotIntensity!==0),e.hasOwnProperty("lightSpotPhi")&&e.hasOwnProperty("lightSpotTheta")&&(this.lightSpot.position.setFromSphericalCoords(2,e.lightSpotPhi,e.lightSpotTheta),this.lightSpot.position.add(new v.Vector3(0,1.5,0))),e.hasOwnProperty("lightSpotDispersion")&&(this.lightSpot.angle=e.lightSpotDispersion))}render(){this.isRunning&&!this.isAvatarOnly&&this.renderer&&this.renderer.render(this.scene,this.camera)}onResize(){!this.isAvatarOnly&&this.renderer&&(this.camera.aspect=this.nodeAvatar.clientWidth/this.nodeAvatar.clientHeight,this.camera.updateProjectionMatrix(),this.renderer.setSize(this.nodeAvatar.clientWidth,this.nodeAvatar.clientHeight),this.controls.update(),this.render())}updatePoseBase(e){for(const[t,n]of Object.entries(this.poseTarget.props)){const i=this.poseAvatar.props[t];if(i){let s=(e-n.t)/n.d;s>1||!this.poseBase.props.hasOwnProperty(t)?i.copy(n):i.isQuaternion?i.copy(this.poseBase.props[t].slerp(n,this.easing(s))):i.isVector3&&i.copy(this.poseBase.props[t].lerp(n,this.easing(s)))}}}updatePoseDelta(){for(const[e,t]of Object.entries(this.poseDelta.props)){if(t.x===0&&t.y===0&&t.z===0)continue;N.set(t.x,t.y,t.z);const n=this.poseAvatar.props[e];n.isQuaternion?(j.setFromEuler(N),n.multiply(j)):n.isVector3&&n.add(N)}}updateMorphTargets(e){for(let[t,n]of Object.entries(this.mtAvatar)){if(!n.needsUpdate)continue;let i=null,s=null;if(n.fixed!==null){if(i=n.fixed,n.system=null,n.systemd=null,n.newvalue=null,n.ref&&n.ref.hasOwnProperty(t)&&delete n.ref[t],n.ref=null,n.base=null,n.value===i){n.needsUpdate=!1;continue}}else n.realtime!==null?(n.ref=null,n.base=null,s=n.realtime):n.system!==null?(i=n.system,n.newvalue=null,n.ref&&n.ref.hasOwnProperty(t)&&delete n.ref[t],n.ref=null,n.base=null,n.systemd!==null?n.systemd===0?(i=null,n.system=null,n.systemd=null):(n.systemd-=e,n.systemd<0&&(n.systemd=0),n.value===i&&(i=null)):n.value===i&&(i=null,n.system=null)):n.newvalue!==null?(n.ref=null,n.base=null,s=n.newvalue,n.newvalue=null):n.base!==null?(i=n.base,n.ref=null,n.value===i&&(i=null,n.base=null,n.needsUpdate=!1)):(n.ref=null,n.baseline!==null&&n.value!==n.baseline?(i=n.baseline,n.base=n.baseline):n.needsUpdate=!1);if(i!==null){let o=i-n.value;o>=0?o<.005?(s=i,n.v=0):(n.v<n.maxv&&(n.v+=n.acc*e),n.v>=0?s=n.value+o*(1-Math.exp(-n.v*e)):s=n.value+n.v*e*(1-Math.exp(n.v*e))):o>-.005?(s=i,n.v=0):(n.v>-n.maxv&&(n.v-=n.acc*e),n.v>=0?s=n.value+n.v*e*(1-Math.exp(-n.v*e)):s=n.value+o*(1-Math.exp(n.v*e)))}if(n.limit!==null){if(s!==null&&s!==n.value&&(n.value=s,n.onchange!==null&&n.onchange(s)),s=n.limit(n.value),s===n.applied)continue}else{if(s===null||s===n.value)continue;n.value=s,n.onchange!==null&&n.onchange(s)}switch(n.applied=s,n.applied<n.min&&(n.applied=n.min),n.applied>n.max&&(n.applied=n.max),t){case"headRotateX":this.poseDelta.props["Head.quaternion"].x=n.applied+this.mtAvatar.bodyRotateX.applied;break;case"headRotateY":this.poseDelta.props["Head.quaternion"].y=n.applied+this.mtAvatar.bodyRotateY.applied;break;case"headRotateZ":this.poseDelta.props["Head.quaternion"].z=n.applied+this.mtAvatar.bodyRotateZ.applied;break;case"bodyRotateX":this.poseDelta.props["Head.quaternion"].x=n.applied+this.mtAvatar.headRotateX.applied,this.poseDelta.props["Spine1.quaternion"].x=n.applied/2,this.poseDelta.props["Spine.quaternion"].x=n.applied/8,this.poseDelta.props["Hips.quaternion"].x=n.applied/24;break;case"bodyRotateY":this.poseDelta.props["Head.quaternion"].y=n.applied+this.mtAvatar.headRotateY.applied,this.poseDelta.props["Spine1.quaternion"].y=n.applied/2,this.poseDelta.props["Spine.quaternion"].y=n.applied/2,this.poseDelta.props["Hips.quaternion"].y=n.applied/4,this.poseDelta.props["LeftUpLeg.quaternion"].y=n.applied/2,this.poseDelta.props["RightUpLeg.quaternion"].y=n.applied/2,this.poseDelta.props["LeftLeg.quaternion"].y=n.applied/4,this.poseDelta.props["RightLeg.quaternion"].y=n.applied/4;break;case"bodyRotateZ":this.poseDelta.props["Head.quaternion"].z=n.applied+this.mtAvatar.headRotateZ.applied,this.poseDelta.props["Spine1.quaternion"].z=n.applied/12,this.poseDelta.props["Spine.quaternion"].z=n.applied/12,this.poseDelta.props["Hips.quaternion"].z=n.applied/24;break;case"handFistLeft":case"handFistRight":const o=t.substring(8);["HandThumb","HandIndex","HandMiddle","HandRing","HandPinky"].forEach((h,c)=>{c===0?(this.poseDelta.props[o+h+"1.quaternion"].x=0,this.poseDelta.props[o+h+"2.quaternion"].z=(o==="Left"?-1:1)*n.applied,this.poseDelta.props[o+h+"3.quaternion"].z=(o==="Left"?-1:1)*n.applied):(this.poseDelta.props[o+h+"1.quaternion"].x=n.applied,this.poseDelta.props[o+h+"2.quaternion"].x=1.5*n.applied,this.poseDelta.props[o+h+"3.quaternion"].x=1.5*n.applied)});break;case"chestInhale":const a=n.applied/20,l={x:a,y:a/2,z:3*a},r={x:1/(1+a)-1,y:1/(1+a/2)-1,z:1/(1+3*a)-1};this.poseDelta.props["Spine1.scale"]=l,this.poseDelta.props["Neck.scale"]=r,this.poseDelta.props["LeftArm.scale"]=r,this.poseDelta.props["RightArm.scale"]=r;break;default:for(let h=0,c=n.ms.length;h<c;h++)n.ms[h][n.is[h]]=n.applied}}}getPoseString(e,t=1e3){let n="{";return Object.entries(e).forEach((i,s)=>{const o=i[0].split(".");if(o[1]==="position"||o[1]==="rotation"||o[1]==="quaternion"){const a=o[1]==="quaternion"?o[0]+".rotation":i[0],l=i[1].isQuaternion?new v.Euler().setFromQuaternion(i[1]):i[1];n+=(s?", ":"")+"'"+a+"':{",n+="x:"+Math.round(l.x*t)/t,n+=", y:"+Math.round(l.y*t)/t,n+=", z:"+Math.round(l.z*t)/t,n+="}"}}),n+="}",n}getPoseTemplateProp(e){const t=e.split(".");let n=t[0]+"."+(t[1]==="rotation"?"quaternion":t[1]);if(this.gesture&&this.gesture.hasOwnProperty(n))return this.gesture[n].clone();{let i=t[0]+"."+(t[1]==="quaternion"?"rotation":t[1]);this.poseWeightOnLeft||(i.startsWith("Left")?(i="Right"+i.substring(4),n="Right"+n.substring(4)):i.startsWith("Right")&&(i="Left"+i.substring(5),n="Left"+n.substring(5)));let s;if(this.poseTarget.template.props.hasOwnProperty(n)){const o={};o[n]=this.poseTarget.template.props[n],s=this.propsToThreeObjects(o)[n]}else if(this.poseTarget.template.props.hasOwnProperty(i)){const o={};o[i]=this.poseTarget.template.props[i],s=this.propsToThreeObjects(o)[n]}return s&&!this.poseWeightOnLeft&&s.isQuaternion&&(s.x*=-1,s.w*=-1),s}}mirrorPose(e){const t={};for(let[n,i]of Object.entries(e))i.isQuaternion&&(n.startsWith("Left")?n="Right"+n.substring(4):n.startsWith("Right")&&(n="Left"+n.substring(5)),i.x*=-1,i.w*=-1),t[n]=i.clone(),t[n].t=i.t,t[n].d=i.d;return t}poseFactory(e,t=2e3){const n={template:e,props:this.propsToThreeObjects(e.props)};for(const[i,s]of Object.entries(n.props)){if(this.opt.modelMovementFactor<1&&e.standing&&(i==="Hips.quaternion"||i==="Spine.quaternion"||i==="Spine1.quaternion"||i==="Spine2.quaternion"||i==="Neck.quaternion"||i==="LeftUpLeg.quaternion"||i==="LeftLeg.quaternion"||i==="RightUpLeg.quaternion"||i==="RightLeg.quaternion")){const o=this.poseStraight[i],a=s.angleTo(o);s.rotateTowards(o,(1-this.opt.modelMovementFactor)*a)}s.t=this.animClock,s.d=t}return n}setPoseFromTemplate(e,t=2e3){const n=e&&this.poseTarget&&this.poseTarget.template&&(this.poseTarget.template.standing&&e.lying||this.poseTarget.template.lying&&e.standing),i=e&&e===this.poseCurrentTemplate,s=this.poseWeightOnLeft;let o=n?1e3:t;if(n?(this.poseCurrentTemplate=this.poseTemplates.oneknee,setTimeout(()=>{this.setPoseFromTemplate(e,t)},o)):this.poseCurrentTemplate=e||this.poseCurrentTemplate,this.poseTarget=this.poseFactory(this.poseCurrentTemplate,o),this.poseWeightOnLeft=!0,(!i&&!s||i&&s)&&(this.poseTarget.props=this.mirrorPose(this.poseTarget.props),this.poseWeightOnLeft=!this.poseWeightOnLeft),this.gesture)for(let[a,l]of Object.entries(this.gesture))this.poseTarget.props.hasOwnProperty(a)&&(this.poseTarget.props[a].copy(l),this.poseTarget.props[a].t=l.t,this.poseTarget.props[a].d=l.d);Object.keys(this.poseDelta.props).forEach(a=>{this.poseTarget.props.hasOwnProperty(a)||(this.poseTarget.props[a]=this.poseBase.props[a].clone(),this.poseTarget.props[a].t=this.animClock,this.poseTarget.props[a].d=o)})}getValue(e){return this.mtAvatar[e]?.value}setValue(e,t,n=null){this.mtAvatar.hasOwnProperty(e)&&Object.assign(this.mtAvatar[e],{system:t,systemd:n,needsUpdate:!0})}getMoodNames(){return Object.keys(this.animMoods)}getMood(){return this.opt.avatarMood}setMood(e){if(e=(e||"").trim().toLowerCase(),!this.animMoods.hasOwnProperty(e))throw new Error("Unknown mood.");this.moodName=e,this.mood=this.animMoods[this.moodName];for(let t of Object.keys(this.mtAvatar)){let n=this.mtBaselineExceptions.hasOwnProperty(t)?this.mtBaselineExceptions[t]:this.mtBaselineDefault;this.mood.baseline.hasOwnProperty(t)?n=this.mood.baseline[t]:this.avatar.baseline?.hasOwnProperty(t)&&(n=this.avatar.baseline[t]),this.setBaselineValue(t,n)}this.mood.anims.forEach(t=>{let n=this.animQueue.findIndex(i=>i.template.name===t.name);n!==-1&&this.animQueue.splice(n,1),this.animQueue.push(this.animFactory(t,-1))})}async initializeFBXAnimationLoader(){try{const{FBXAnimationLoader:e}=await Promise.resolve().then(()=>require("./fbxAnimationLoader-DYwX3TQf.cjs"));this.fbxAnimationLoader=new e(this.armature),console.log("FBX Animation Loader initialized")}catch(e){console.warn("FBX Animation Loader not available:",e),this.fbxAnimationLoader=null}}setBodyMovement(e){this.bodyMovement=e,this.avatar&&(this.avatar.bodyMovement=e),console.log("Body movement set to:",e),e!=="idle"?this.setShowFullAvatar(!0):this.unlockAvatarPosition(),this.applyBodyMovementAnimation()}async applyBodyMovementAnimation(){if(!this.armature||!this.animQueue){console.log("Avatar not ready for body movement animations");return}console.log("Avatar is running:",this.isRunning),console.log("Animation queue exists:",!!this.animQueue);const e=this.animQueue.length;this.animQueue=this.animQueue.filter(i=>!i.template.name.startsWith("bodyMovement"));const t=this.animQueue.length;if(console.log(`Filtered animation queue: ${e} -> ${t} animations`),this.bodyMovement==="idle"){this.fbxAnimationLoader&&this.fbxAnimationLoader.stopCurrentAnimation();return}if(this.fbxAnimationLoader)try{await this.fbxAnimationLoader.playGestureAnimation(this.bodyMovement,this.movementIntensity),console.log("Applied FBX body movement animation:",this.bodyMovement);return}catch(i){console.warn("FBX animation failed, falling back to code animation:",i)}const n=this.createBodyMovementAnimation(this.bodyMovement);if(console.log("Created movement animation:",n),n)try{const i=this.animFactory(n,!0);i&&i.ts&&i.ts.length>0?(this.animQueue.push(i),console.log("Applied code-based body movement animation:",this.bodyMovement),console.log("Animation queue length:",this.animQueue.length),console.log("Animation object:",i)):(console.error("Invalid animation object created for:",this.bodyMovement),console.error("Animation object:",i))}catch(i){console.error("Error creating body movement animation:",i)}}lockAvatarPosition(){if(!this.armature){console.warn("Cannot lock position: armature not available");return}this.originalPosition||(this.originalPosition={x:this.armature.position.x,y:this.armature.position.y,z:this.armature.position.z},console.log("Original position stored:",this.originalPosition));const e=2;this.lockedPosition={x:0,y:e,z:0},this.armature.position.set(this.lockedPosition.x,this.lockedPosition.y,this.lockedPosition.z),console.log("BEFORE: Avatar position was:",this.armature.position.x,this.armature.position.y,this.armature.position.z),console.log("AFTER: Avatar position moved up and locked at:",this.lockedPosition),console.log("Current view:",this.viewName)}unlockAvatarPosition(){this.armature&&(this.armature.position.set(0,0,0),console.log("Avatar position reset to center (0,0,0)")),this.lockedPosition=null,console.log("Avatar position unlocked")}maintainLockedPosition(){if(this.lockedPosition&&this.armature){const e=this.armature.position.y,t=this.lockedPosition.y-2,n=this.lockedPosition.y+.1;e<t?this.armature.position.set(this.lockedPosition.x,t,this.lockedPosition.z):e>n&&this.armature.position.set(this.lockedPosition.x,n,this.lockedPosition.z),this.armature.position.x=this.lockedPosition.x,this.armature.position.z=this.lockedPosition.z}}createBodyMovementAnimation(e){const t=this.movementIntensity||.5,n={walking:{name:"bodyMovement_walking",delay:[500,2e3],dt:[800,1200],vs:{bodyRotateY:[-.1*t,.1*t,0],bodyRotateZ:[-.05*t,.05*t,0],bodyRotateX:[-.02*t,.02*t,0]}},prancing:{name:"bodyMovement_prancing",delay:[300,1e3],dt:[400,800],vs:{bodyRotateY:[-.15*t,.15*t,0],bodyRotateZ:[-.08*t,.08*t,0],bodyRotateX:[-.05*t,.05*t,0]}},gesturing:{name:"bodyMovement_gesturing",delay:[400,1500],dt:[600,1e3],vs:{bodyRotateY:[-.08*t,.08*t,0],bodyRotateZ:[-.03*t,.03*t,0]}},dancing:{name:"bodyMovement_dancing",delay:[200,600],dt:[400,800],vs:{bodyRotateY:[-.25*t,.25*t,0],bodyRotateZ:[-.15*t,.15*t,0],bodyRotateX:[-.1*t,.1*t,0]}},dancing2:{name:"bodyMovement_dancing2",delay:[150,500],dt:[300,700],vs:{bodyRotateY:[-.3*t,.3*t,0],bodyRotateZ:[-.2*t,.2*t,0],bodyRotateX:[-.12*t,.12*t,0]}},dancing3:{name:"bodyMovement_dancing3",delay:[100,400],dt:[200,600],vs:{bodyRotateY:[-.35*t,.35*t,0],bodyRotateZ:[-.25*t,.25*t,0],bodyRotateX:[-.15*t,.15*t,0]}},excited:{name:"bodyMovement_excited",delay:[200,600],dt:[300,700],vs:{bodyRotateY:[-.12*t,.12*t,0],bodyRotateZ:[-.06*t,.06*t,0],bodyRotateX:[-.04*t,.04*t,0]}},happy:{name:"bodyMovement_happy",delay:[300,800],dt:[500,1e3],vs:{bodyRotateY:[-.08*t,.08*t,0],bodyRotateZ:[-.04*t,.04*t,0],bodyRotateX:[-.02*t,.02*t,0]}},surprised:{name:"bodyMovement_surprised",delay:[100,300],dt:[200,500],vs:{bodyRotateY:[-.05*t,.05*t,0],bodyRotateZ:[-.03*t,.03*t,0],bodyRotateX:[-.01*t,.01*t,0]}},thinking:{name:"bodyMovement_thinking",delay:[800,2e3],dt:[1e3,1500],vs:{bodyRotateY:[-.06*t,.06*t,0],bodyRotateZ:[-.03*t,.03*t,0],bodyRotateX:[-.02*t,.02*t,0]}},nodding:{name:"bodyMovement_nodding",delay:[400,800],dt:[300,600],vs:{bodyRotateX:[-.1*t,.1*t,0],bodyRotateY:[-.02*t,.02*t,0]}},shaking:{name:"bodyMovement_shaking",delay:[200,400],dt:[150,300],vs:{bodyRotateY:[-.15*t,.15*t,0],bodyRotateZ:[-.05*t,.05*t,0]}},celebration:{name:"bodyMovement_celebration",delay:[100,300],dt:[200,500],vs:{bodyRotateY:[-.2*t,.2*t,0],bodyRotateZ:[-.1*t,.1*t,0],bodyRotateX:[-.08*t,.08*t,0]}},energetic:{name:"bodyMovement_energetic",delay:[150,400],dt:[250,500],vs:{bodyRotateY:[-.18*t,.18*t,0],bodyRotateZ:[-.12*t,.12*t,0],bodyRotateX:[-.08*t,.08*t,0]}},swaying:{name:"bodyMovement_swaying",delay:[600,1200],dt:[800,1e3],vs:{bodyRotateY:[-.1*t,.1*t,0],bodyRotateZ:[-.05*t,.05*t,0]}},bouncing:{name:"bodyMovement_bouncing",delay:[300,600],dt:[400,700],vs:{bodyRotateY:[-.05*t,.05*t,0]}}};if(e==="dancing"){const i=["dancing","dancing2","dancing3"],s=i[Math.floor(Math.random()*i.length)];return n[s]||n.dancing}return n[e]||null}playRandomDance(){const e=["dancing","dancing2","dancing3"],t=e[Math.floor(Math.random()*e.length)];this.setBodyMovement(t)}playReaction(e){["happy","surprised","thinking","nodding","shaking","celebration","energetic","swaying","bouncing"].includes(e)?(this.setBodyMovement(e),["surprised","nodding","shaking","celebration"].includes(e)&&setTimeout(()=>{this.setBodyMovement("idle")},3e3)):console.warn("Invalid reaction type:",e)}playCelebration(){this.playReaction("celebration"),setTimeout(()=>{this.playRandomDance()},2e3)}setMovementIntensity(e){this.movementIntensity=Math.max(0,Math.min(1,e)),this.avatar&&(this.avatar.movementIntensity=this.movementIntensity),console.log("Movement intensity set to:",this.movementIntensity),this.fbxAnimationLoader&&this.fbxAnimationLoader.setIntensity(this.movementIntensity),this.applyBodyMovementAnimation()}setShowFullAvatar(e){this.showFullAvatar=e,this.avatar&&(this.avatar.showFullAvatar=e),console.log("Show full avatar set to:",e),e&&this.viewName!=="full"?(console.log("Changing camera view to full"),this.setView("full")):!e&&this.viewName!=="upper"?(console.log("Changing camera view to upper"),this.setView("upper")):console.log("Camera view already set to:",this.viewName)}getMorphTargetNames(){return["eyesRotateX","eyesRotateY",...Object.keys(this.mtAvatar)].sort()}getBaselineValue(e){if(e==="eyesRotateY"){const t=this.getBaselineValue("eyeLookOutLeft");if(t===void 0)return;const n=this.getBaselineValue("eyeLookInLeft");return n===void 0||this.getBaselineValue("eyeLookOutRight")===void 0||this.getBaselineValue("eyeLookInRight")===void 0?void 0:t-n}else if(e==="eyesRotateX"){const t=this.getBaselineValue("eyesLookDown");if(t===void 0)return;const n=this.getBaselineValue("eyesLookUp");return n===void 0?void 0:t-n}else return this.mtAvatar[e]?.baseline}setBaselineValue(e,t){e==="eyesRotateY"?(this.setBaselineValue("eyeLookOutLeft",t===null?null:t>0?t:0),this.setBaselineValue("eyeLookInLeft",t===null?null:t>0?0:-t),this.setBaselineValue("eyeLookOutRight",t===null?null:t>0?0:-t),this.setBaselineValue("eyeLookInRight",t===null?null:t>0?t:0)):e==="eyesRotateX"?(this.setBaselineValue("eyesLookDown",t===null?null:t>0?t:0),this.setBaselineValue("eyesLookUp",t===null?null:t>0?0:-t)):this.mtAvatar.hasOwnProperty(e)&&Object.assign(this.mtAvatar[e],{base:null,baseline:t,needsUpdate:!0})}getFixedValue(e){if(e==="eyesRotateY"){const t=this.getFixedValue("eyeLookOutLeft");if(t===null)return null;const n=this.getFixedValue("eyeLookInLeft");return n===null||this.getFixedValue("eyeLookOutRight")===null||this.getFixedValue("eyeLookInRight")===null?null:t-n}else if(e==="eyesRotateX"){const t=this.getFixedValue("eyesLookDown");if(t===null)return null;const n=this.getFixedValue("eyesLookUp");return n===null?null:t-n}else return this.mtAvatar[e]?.fixed}setFixedValue(e,t,n=null){e==="eyesRotateY"?(this.setFixedValue("eyeLookOutLeft",t===null?null:t>0?t:0,n),this.setFixedValue("eyeLookInLeft",t===null?null:t>0?0:-t,n),this.setFixedValue("eyeLookOutRight",t===null?null:t>0?0:-t,n),this.setFixedValue("eyeLookInRight",t===null?null:t>0?t:0,n)):e==="eyesRotateX"?(this.setFixedValue("eyesLookDown",t===null?null:t>0?t:0,n),this.setFixedValue("eyesLookUp",t===null?null:t>0?0:-t,n)):this.mtAvatar.hasOwnProperty(e)&&Object.assign(this.mtAvatar[e],{fixed:t,needsUpdate:!0})}animFactory(e,t=!1,n=1,i=1,s=!1){const o={template:e,ts:[0],vs:{}};let a=e;for(;;)if(a.hasOwnProperty(this.stateName))a=a[this.stateName];else if(a.hasOwnProperty(this.moodName))a=a[this.moodName];else if(a.hasOwnProperty(this.poseName))a=a[this.poseName];else if(a.hasOwnProperty(this.viewName))a=a[this.viewName];else if(this.avatar.body&&a.hasOwnProperty(this.avatar.body))a=a[this.avatar.body];else if(a.hasOwnProperty("alt")){let r=a.alt[0];if(a.alt.length>1){const h=Math.random();let c=0;for(let u=0;u<a.alt.length;u++){let d=this.valueFn(a.alt[u].p);if(c+=d===void 0?(1-c)/(a.alt.length-1-u):d,h<c){r=a.alt[u];break}}}a=r}else break;let l=this.valueFn(a.delay)||0;if(Array.isArray(l)&&(l=this.gaussianRandom(...l)),a.hasOwnProperty("dt"))a.dt.forEach((r,h)=>{let c=this.valueFn(r);Array.isArray(c)&&(c=this.gaussianRandom(...c)),o.ts[h+1]=o.ts[h]+c});else{let r=Object.values(a.vs).reduce((h,c)=>c.length>h?c.length:h,0);o.ts=Array(r+1).fill(0)}s?o.ts=o.ts.map(r=>l+r*n):o.ts=o.ts.map(r=>this.animClock+l+r*n);for(let[r,h]of Object.entries(a.vs)){const c=this.getBaselineValue(r),u=h.map(d=>(d=this.valueFn(d),d===null?null:typeof d=="function"?d:typeof d=="string"||d instanceof String?d.slice():Array.isArray(d)?r==="gesture"?d.slice():(c===void 0?0:c)+i*this.gaussianRandom(...d):typeof d=="boolean"?d:d instanceof Object&&d.constructor===Object?Object.assign({},d):(c===void 0?0:c)+i*d));r==="eyesRotateY"?(o.vs.eyeLookOutLeft=[null,...u.map(d=>d>0?d:0)],o.vs.eyeLookInLeft=[null,...u.map(d=>d>0?0:-d)],o.vs.eyeLookOutRight=[null,...u.map(d=>d>0?0:-d)],o.vs.eyeLookInRight=[null,...u.map(d=>d>0?d:0)]):r==="eyesRotateX"?(o.vs.eyesLookDown=[null,...u.map(d=>d>0?d:0)],o.vs.eyesLookUp=[null,...u.map(d=>d>0?0:-d)]):o.vs[r]=[null,...u]}for(let r of Object.keys(o.vs))for(;o.vs[r].length<=o.ts.length;)o.vs[r].push(o.vs[r][o.vs[r].length-1]);return e.hasOwnProperty("mood")&&(o.mood=this.valueFn(e.mood).slice()),t&&(o.loop=t),o}valueAnimationSeq(e,t,n,i,s,o=null){e=this.valueFn(e),t=this.valueFn(t),s<n&&(s=n),s>i&&(s=i);let a=(t-e)/(i-n);return o&&(a*=o((s-n)/(i-n))),a*s+(e-a*n)}gaussianRandom(e,t,n=1,i=5){let s=0;for(let o=0;o<i;o++)s+=Math.random();return e+Math.pow(s/i,n)*(t-e)}sigmoidFactory(e){function t(i){return 1/(1+Math.exp(-e*i))-.5}var n=.5/t(1);return function(i){return n*t(2*Math.max(Math.min(i,1),0)-1)+.5}}convertRange(e,t,n){return(e-t[0])*(n[1]-n[0])/(t[1]-t[0])+n[0]}animate(e){if(!this.isRunning)return;let t;if(this.isAvatarOnly)t=e;else{if(requestAnimationFrame(this.animate.bind(this)),t=e-this.animTimeLast,t<this.animFrameDur)return;this.animTimeLast=e}t=t/this.animSlowdownRate,this.animClock+=t,this.maintainLockedPosition();let n,i,s,o,a=0;if(this.stats&&this.stats.begin(),this.isListening){for(this.listeningAnalyzer.getByteFrequencyData(this.volumeFrequencyData),n=2,s=10;n<s;n++)this.volumeFrequencyData[n]>a&&(a=this.volumeFrequencyData[n]);this.listeningVolume=(this.listeningVolume+a)/2,this.listeningActive?(this.listeningTimerTotal+=t,this.listeningVolume<this.listeningSilenceThresholdLevel?(this.listeningTimer+=t,this.listeningTimer>this.listeningSilenceThresholdMs&&(this.listeningOnchange&&this.listeningOnchange("stop",this.listeningTimer),this.listeningActive=!1,this.listeningTimer=0,this.listeningTimerTotal=0)):this.listeningTimer*=.5,this.listeningTimerTotal>this.listeningActiveDurationMax&&(this.listeningOnchange&&this.listeningOnchange("maxactive"),this.listeningTimerTotal=0)):(this.listeningTimerTotal+=t,this.listeningVolume>this.listeningActiveThresholdLevel?(this.listeningTimer+=t,this.listeningTimer>this.listeningActiveThresholdMs&&(this.listeningOnchange&&this.listeningOnchange("start"),this.listeningActive=!0,this.listeningTimer=0,this.listeningTimerTotal=0)):this.listeningTimer*=.5,this.listeningTimerTotal>this.listeningSilenceDurationMax&&(this.listeningOnchange&&this.listeningOnchange("maxsilence"),this.listeningTimerTotal=0))}if(this.isSpeaking)for(a=0,this.audioAnalyzerNode.getByteFrequencyData(this.volumeFrequencyData),n=2,s=10;n<s;n++)this.volumeFrequencyData[n]>a&&(a=this.volumeFrequencyData[n]);let l=null,r=null;const h=[];for(n=0,s=this.animQueue.length;n<s;n++){const c=this.animQueue[n];if(!(!c||!c.ts||!c.ts.length||this.animClock<c.ts[0])){for(i=c.ndx||0,o=c.ts.length;i<o&&!(this.animClock<c.ts[i]);i++)for(let[u,d]of Object.entries(c.vs))if(this.mtAvatar.hasOwnProperty(u)){if(d[i+1]===null)continue;const f=this.mtAvatar[u];if(d[i]===null&&(d[i]=f.value),i===o-1)f.newvalue=d[i];else{f.newvalue=d[i+1];const x=c.ts[i+1]-c.ts[i];let y=1;x>1e-4&&(y=(this.animClock-c.ts[i])/x),y<1&&(f.easing&&(y=f.easing(y)),f.newvalue=(1-y)*d[i]+y*f.newvalue),f.ref&&f.ref!==c.vs&&f.ref.hasOwnProperty(u)&&delete f.ref[u],f.ref=c.vs}if(a)switch(u){case"viseme_aa":case"viseme_E":case"viseme_I":case"viseme_O":case"viseme_U":f.newvalue*=1+a/255-.5}f.needsUpdate=!0}else u==="eyeContact"&&d[i]!==null&&l!==!1?l=!!d[i]:u==="headMove"&&d[i]!==null&&r!==!1?d[i]===0?r=!1:(Math.random()<d[i]&&(r=!0),d[i]=null):d[i]!==null&&(h.push({mt:u,val:d[i]}),d[i]=null);i===o?(c.hasOwnProperty("mood")&&this.setMood(c.mood),c.loop?(o=this.isSpeaking&&(c.template.name==="head"||c.template.name==="eyes")?4:1,this.animQueue[n]=this.animFactory(c.template,c.loop>0?c.loop-1:c.loop,1,1/o)):(this.animQueue.splice(n--,1),s--)):c.ndx=i-1}}for(let c=0,u=h.length;c<u;c++)switch(i=h[c].val,h[c].mt){case"speak":this.speakText(i);break;case"subtitles":this.onSubtitles&&typeof this.onSubtitles=="function"&&this.onSubtitles(i);break;case"pose":this.poseName=i,this.setPoseFromTemplate(this.poseTemplates[this.poseName]);break;case"gesture":this.playGesture(...i);break;case"function":i&&typeof i=="function"&&i();break;case"moveto":Object.entries(i.props).forEach(d=>{d[1]?this.poseTarget.props[d[0]].copy(d[1]):this.poseTarget.props[d[0]].copy(this.getPoseTemplateProp(d[0])),this.poseTarget.props[d[0]].t=this.animClock,this.poseTarget.props[d[0]].d=d[1]&&d[1].d?d[1].d:d.duration||2e3});break;case"handLeft":this.ikSolve({iterations:20,root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},i.x?new v.Vector3(i.x,i.y,i.z):null,!0,i.d);break;case"handRight":this.ikSolve({iterations:20,root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5,maxAngle:.2},{link:"RightArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},i.x?new v.Vector3(i.x,i.y,i.z):null,!0,i.d);break}if((l||r)&&(N.setFromQuaternion(this.poseAvatar.props["Head.quaternion"]),N.x=Math.max(-.9,Math.min(.9,2*N.x-.5)),N.y=Math.max(-.9,Math.min(.9,-2.5*N.y)),l?(Object.assign(this.mtAvatar.eyesLookDown,{system:N.x<0?-N.x:0,needsUpdate:!0}),Object.assign(this.mtAvatar.eyesLookUp,{system:N.x<0?0:N.x,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookInLeft,{system:N.y<0?-N.y:0,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookOutLeft,{system:N.y<0?0:N.y,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookInRight,{system:N.y<0?0:N.y,needsUpdate:!0}),Object.assign(this.mtAvatar.eyeLookOutRight,{system:N.y<0?-N.y:0,needsUpdate:!0}),r&&(n=-this.mtAvatar.bodyRotateY.value,i=this.gaussianRandom(-.2,.2),this.animQueue.push(this.animFactory({name:"headmove",dt:[[1e3,2e3],[1e3,2e3,1,2],[1e3,2e3],[1e3,2e3,1,2]],vs:{headRotateY:[n,n,0],headRotateX:[i,i,0],headRotateZ:[-n/4,-n/4,0]}})))):(n=this.mtAvatar.eyeLookInLeft.value-this.mtAvatar.eyeLookOutLeft.value,i=this.gaussianRandom(-.2,.2),this.animQueue.push(this.animFactory({name:"headmove",dt:[[1e3,2e3],[1e3,2e3,1,2],[1e3,2e3],[1e3,2e3,1,2]],vs:{headRotateY:[null,n,n,0],headRotateX:[null,i,i,0],headRotateZ:[null,-n/4,-n/4,0],eyeLookInLeft:[null,0],eyeLookOutLeft:[null,0],eyeLookInRight:[null,0],eyeLookOutRight:[null,0],eyeContact:[0]}})))),t>2*this.animFrameDur&&(t=2*this.animFrameDur),(this.viewName!=="full"||this.isAvatarOnly)&&(n=this.mtRandomized[Math.floor(Math.random()*this.mtRandomized.length)],i=this.mtAvatar[n],i.needsUpdate||Object.assign(i,{base:(this.mood.baseline[n]||0)+(1+a/255)*Math.random()/5,needsUpdate:!0})),this.updatePoseBase(this.animClock),this.mixer&&this.mixer.update(t/1e3*this.mixer.timeScale),this.updatePoseDelta(),(this.isSpeaking||this.isListening)&&l?a>this.volumeMax?(this.volumeHeadBase=.05,Math.random()>.6&&(this.volumeHeadTarget=-.05-Math.random()/15),this.volumeMax=a):(this.volumeMax*=.92,this.volumeHeadTarget=this.volumeHeadBase-.9*(this.volumeHeadBase-this.volumeHeadTarget)):(this.volumeHeadTarget=0,this.volumeMax=0),n=this.volumeHeadTarget-this.volumeHeadCurrent,i=Math.abs(n),i>1e-4&&(o=i*(this.volumeHeadEasing(Math.min(1,this.volumeHeadVelocity*t/1e3/i)/2+.5)-.5),this.volumeHeadCurrent+=Math.sign(n)*Math.min(i,o)),Math.abs(this.volumeHeadCurrent)>1e-4&&(j.setFromAxisAngle(Hi,this.volumeHeadCurrent),this.objectNeck.quaternion.multiply(j)),bt.setFromObject(this.armature),this.objectLeftToeBase.getWorldPosition(me),me.sub(this.armature.position),this.objectRightToeBase.getWorldPosition(ye),ye.sub(this.armature.position),this.objectHips.position.y-=bt.min.y/2,this.objectHips.position.x-=(me.x+ye.x)/4,this.objectHips.position.z-=(me.z+ye.z)/2,this.dynamicbones.update(t),this.fbxAnimationLoader&&this.fbxAnimationLoader.update(),this.opt.update&&this.opt.update(t),this.updateMorphTargets(t),this.isAvatarOnly)this.stats&&this.stats.end();else{if(this.cameraClock!==null&&this.cameraClock<1e3){this.cameraClock+=t,this.cameraClock>1e3&&(this.cameraClock=1e3);let c=new v.Spherical().setFromVector3(this.cameraStart),u=new v.Spherical().setFromVector3(this.cameraEnd);c.phi+=this.easing(this.cameraClock/1e3)*(u.phi-c.phi),c.theta+=this.easing(this.cameraClock/1e3)*(u.theta-c.theta),c.radius+=this.easing(this.cameraClock/1e3)*(u.radius-c.radius),c.makeSafe(),this.camera.position.setFromSpherical(c),this.controlsStart.x!==this.controlsEnd.x?this.controls.target.copy(this.controlsStart.lerp(this.controlsEnd,this.easing(this.cameraClock/1e3))):(c.setFromVector3(this.controlsStart),u.setFromVector3(this.controlsEnd),c.phi+=this.easing(this.cameraClock/1e3)*(u.phi-c.phi),c.theta+=this.easing(this.cameraClock/1e3)*(u.theta-c.theta),c.radius+=this.easing(this.cameraClock/1e3)*(u.radius-c.radius),c.makeSafe(),this.controls.target.setFromSpherical(c)),this.controls.update()}this.controls.autoRotate&&this.controls.update(),this.stats&&this.stats.end(),this.render()}}resetLips(){this.visemeNames.forEach(e=>{this.morphs.forEach(t=>{const n=t.morphTargetDictionary["viseme_"+e];n!==void 0&&(t.morphTargetInfluences[n]=0)})})}lipsyncGetProcessor(e,t="./"){if(!this.lipsync.hasOwnProperty(e)){const n=e.toLowerCase(),i="Lipsync"+e.charAt(0).toUpperCase()+e.slice(1);try{const s=xt[n];s&&s[i]?(this.lipsync[e]=new s[i],console.log(`Loaded lip-sync module for ${e}`)):console.warn(`Lip-sync module for ${e} not found. Available modules:`,Object.keys(xt))}catch(s){console.warn(`Failed to load lip-sync module for ${e}:`,s)}}}lipsyncPreProcessText(e,t){return(this.lipsync[t]||Object.values(this.lipsync)[0]).preProcessText(e)}lipsyncWordsToVisemes(e,t){return(this.lipsync[t]||Object.values(this.lipsync)[0]).wordsToVisemes(e)}speakText(e,t=null,n=null,i=null){t=t||{};const s=/[!\.\?\n\p{Extended_Pictographic}]/ug,o=/[ ]/ug,a=/[\p{L}\p{N},\.\p{Quotation_Mark}!€\$\+\p{Dash_Punctuation}%&\?]/ug,l=/[\p{Extended_Pictographic}]/ug,r=t.lipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang;let h="",c="",u=0,d=[],f=[];const x=Array.from(this.segmenter.segment(e),y=>y.segment);for(let y=0;y<x.length;y++){const R=y===x.length-1,I=x[y].match(a);let g=x[y].match(s);const T=x[y].match(l),C=x[y].match(o);if(g&&!R&&!T&&x[y+1].match(s)&&(g=!1),n&&(h+=x[y]),I&&(!i||i.every(L=>y<L[0]||y>L[1]))&&(c+=x[y]),(C||g||R)&&(c.length&&(c=this.lipsyncPreProcessText(c,r),c.length&&d.push({mark:u,word:c})),h.length&&(f.push({mark:u,template:{name:"subtitles"},ts:[0],vs:{subtitles:[h]}}),h=""),c.length)){const L=this.lipsyncWordsToVisemes(c,r);if(L&&L.visemes&&L.visemes.length){const P=L.times[L.visemes.length-1]+L.durations[L.visemes.length-1];for(let z=0;z<L.visemes.length;z++)f.push({mark:u,template:{name:"viseme"},ts:[(L.times[z]-.6)/P,(L.times[z]+.5)/P,(L.times[z]+L.durations[z]+.5)/P],vs:{["viseme_"+L.visemes[z]]:[null,L.visemes[z]==="PP"||L.visemes[z]==="FF"?.9:.6,0]}})}c="",u++}if(g||R){if(d.length||R&&f.length){const L={anim:f};n&&(L.onSubtitles=n),d.length&&!t.avatarMute&&(L.text=d,t.avatarMood&&(L.mood=t.avatarMood),t.ttsLang&&(L.lang=t.ttsLang),t.ttsVoice&&(L.voice=t.ttsVoice),t.ttsRate&&(L.rate=t.ttsRate),t.ttsVoice&&(L.pitch=t.ttsPitch),t.ttsVolume&&(L.volume=t.ttsVolume)),this.speechQueue.push(L),d=[],c="",u=0,f=[]}if(T){let L=this.animEmojis[x[y]];L&&L.link&&(L=this.animEmojis[L.link]),L&&this.speechQueue.push({emoji:L})}this.speechQueue.push({break:100})}}this.speechQueue.push({break:1e3}),this.startSpeaking()}async speakEmoji(e){let t=this.animEmojis[e];t&&t.link&&(t=this.animEmojis[t.link]),t&&this.speechQueue.push({emoji:t}),this.startSpeaking()}async speakBreak(e){this.speechQueue.push({break:e}),this.startSpeaking()}async speakMarker(e){this.speechQueue.push({marker:e}),this.startSpeaking()}async playBackgroundAudio(e){let n=await(await fetch(e)).arrayBuffer();this.stopBackgroundAudio(),this.audioBackgroundSource=this.audioCtx.createBufferSource(),this.audioBackgroundSource.loop=!0,this.audioBackgroundSource.buffer=await this.audioCtx.decodeAudioData(n),this.audioBackgroundSource.playbackRate.value=1/this.animSlowdownRate,this.audioBackgroundSource.connect(this.audioBackgroundGainNode),this.audioBackgroundSource.start(0)}stopBackgroundAudio(){try{this.audioBackgroundSource.stop()}catch{}this.audioBackgroundSource.disconnect()}async setReverb(e=null){if(e){let n=await(await fetch(e)).arrayBuffer();this.audioReverbNode.buffer=await this.audioCtx.decodeAudioData(n)}else{const t=this.audioCtx.sampleRate,n=this.audioCtx.createBuffer(2,t,t);n.getChannelData(0)[0]=1,n.getChannelData(1)[0]=1,this.audioReverbNode.buffer=n}}setMixerGain(e,t=null,n=0){e!==null&&(this.audioSpeechGainNode.gain.cancelScheduledValues(this.audioCtx.currentTime),n?(this.audioSpeechGainNode.gain.setValueAtTime(Math.max(this.audioSpeechGainNode.gain.value,1e-4),this.audioCtx.currentTime),this.audioSpeechGainNode.gain.exponentialRampToValueAtTime(Math.max(e,1e-4),this.audioCtx.currentTime+n)):this.audioSpeechGainNode.gain.setValueAtTime(e,this.audioCtx.currentTime)),t!==null&&(this.audioBackgroundGainNode.gain.cancelScheduledValues(this.audioCtx.currentTime),n?(this.audioBackgroundGainNode.gain.setValueAtTime(Math.max(this.audioBackgroundGainNode.gain.value,1e-4),this.audioCtx.currentTime),this.audioBackgroundGainNode.gain.exponentialRampToValueAtTime(Math.max(t,1e-4),this.audioCtx.currentTime+n)):this.audioBackgroundGainNode.gain.setValueAtTime(t,this.audioCtx.currentTime))}speakAudio(e,t=null,n=null){t=t||{};const i=t.lipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,s={};if(e.words){let o=[];for(let a=0;a<e.words.length;a++){const l=e.words[a],r=e.wtimes[a];let h=e.wdurations[a];if(l.length&&(n&&o.push({template:{name:"subtitles"},ts:[r],vs:{subtitles:[" "+l]}}),!e.visemes)){const c=this.lipsyncPreProcessText(l,i),u=this.lipsyncWordsToVisemes(c,i);if(u&&u.visemes&&u.visemes.length){const d=u.times[u.visemes.length-1]+u.durations[u.visemes.length-1],f=Math.min(h,Math.max(0,h-u.visemes.length*150));let x=.6+this.convertRange(f,[0,h],[0,.4]);if(h=Math.min(h,u.visemes.length*200),d>0)for(let y=0;y<u.visemes.length;y++){const R=r+u.times[y]/d*h,I=u.durations[y]/d*h;o.push({template:{name:"viseme"},ts:[R-Math.min(60,2*I/3),R+Math.min(25,I/2),R+I+Math.min(60,I/2)],vs:{["viseme_"+u.visemes[y]]:[null,u.visemes[y]==="PP"||u.visemes[y]==="FF"?.9:x,0]}})}}}}if(e.visemes)for(let a=0;a<e.visemes.length;a++){const l=e.visemes[a],r=e.vtimes[a],h=e.vdurations[a];o.push({template:{name:"viseme"},ts:[r-2*h/3,r+h/2,r+h+h/2],vs:{["viseme_"+l]:[null,l==="PP"||l==="FF"?.9:.6,0]}})}if(e.markers)for(let a=0;a<e.markers.length;a++){const l=e.markers[a],r=e.mtimes[a];o.push({template:{name:"markers"},ts:[r],vs:{function:[l]}})}o.length&&(s.anim=o)}if(e.audio&&(s.audio=e.audio),e.anim?.name){let o=this.animFactory(e.anim,!1,1,1,!0);s.anim?s.anim.push(o):s.anim=[o]}n&&(s.onSubtitles=n),t.isRaw&&(s.isRaw=!0),Object.keys(s).length&&(this.speechQueue.push(s),s.isRaw||this.speechQueue.push({break:300}),this.startSpeaking())}async playAudio(e=!1){if(!(!this.armature||this.isAudioPlaying&&!e))if(this.isAudioPlaying=!0,this.audioPlaylist.length){const t=this.audioPlaylist.shift();if(this.audioCtx.state==="suspended"||this.audioCtx.state==="interrupted"){const s=this.audioCtx.resume(),o=new Promise((a,l)=>setTimeout(()=>l("p2"),1e3));try{await Promise.race([s,o])}catch{console.log("Can't play audio. Web Audio API suspended. This is often due to calling some speak method before the first user action, which is typically prevented by the browser."),this.playAudio(!0);return}}let n;if(Array.isArray(t.audio)){let s=this.concatArrayBuffers(t.audio);n=this.pcmToAudioBuffer(s)}else n=t.audio;this.audioSpeechSource=this.audioCtx.createBufferSource(),this.audioSpeechSource.buffer=n,this.audioSpeechSource.playbackRate.value=1/this.animSlowdownRate,this.audioSpeechSource.connect(this.audioAnalyzerNode),this.audioSpeechSource.addEventListener("ended",()=>{this.audioSpeechSource.disconnect(),this.playAudio(!0)},{once:!0});let i=0;t.anim&&(t.isRaw||(i=Math.abs(Math.min(0,...t.anim.map(s=>Math.min(...s.ts))))),t.anim.forEach(s=>{for(let o=0;o<s.ts.length;o++)s.ts[o]=this.animClock+s.ts[o]+i;this.animQueue.push(s)})),this.audioSpeechSource.start(i/1e3)}else this.isAudioPlaying=!1,this.startSpeaking(!0)}async synthesizeWithBrowserTTS(e){return new Promise((t,n)=>{const i=e.text.map(g=>g.word).join(" "),s=new SpeechSynthesisUtterance(i),o=e.lang||this.avatar.ttsLang||this.opt.ttsLang||"en-US",a=(e.rate||this.avatar.ttsRate||this.opt.ttsRate||1)+this.mood.speech.deltaRate,l=(e.pitch||this.avatar.ttsPitch||this.opt.ttsPitch||1)+this.mood.speech.deltaPitch,r=(e.volume||this.avatar.ttsVolume||this.opt.ttsVolume||1)+this.mood.speech.deltaVolume;s.lang=o,s.rate=Math.max(.1,Math.min(10,a)),s.pitch=Math.max(0,Math.min(2,l)),s.volume=Math.max(0,Math.min(1,r));const h=speechSynthesis.getVoices(),c=e.voice||this.avatar.ttsVoice||this.opt.ttsVoice;if(c&&h.length>0){const g=h.find(T=>T.name.includes(c)||T.lang===o);g&&(s.voice=g)}const u=i.length*100/s.rate,d=this.audioCtx.createBuffer(1,this.audioCtx.sampleRate*(u/1e3),this.audioCtx.sampleRate),f=this.avatar.lipsyncLang||this.opt.lipsyncLang||"en",x=this.lipsyncPreProcessText(i,f),y=this.lipsyncWordsToVisemes(x,f);console.log("Browser TTS Lip-sync Debug:",{text:i,lipsyncLang:f,processedText:x,lipsyncData:y,hasVisemes:y&&y.visemes&&y.visemes.length>0,estimatedDuration:u});const R=[];if(y&&y.visemes&&y.visemes.length>0){const g=y.times[y.visemes.length-1]+y.durations[y.visemes.length-1];for(let T=0;T<y.visemes.length;T++){const C=y.visemes[T],L=y.times[T]/g,P=y.durations[T]/g,z=L*u,_=P*u;R.push({template:{name:"viseme"},ts:[z-Math.min(60,2*_/3),z+Math.min(25,_/2),z+_+Math.min(60,_/2)],vs:{["viseme_"+C]:[null,C==="PP"||C==="FF"?.9:.6,0]}})}}const I=[...e.anim,...R];this.audioPlaylist.push({anim:I,audio:d}),this.onSubtitles=e.onSubtitles||null,this.resetLips(),e.mood&&this.setMood(e.mood),this.playAudio(),s.onend=()=>{t()},s.onerror=g=>{console.error("Speech synthesis error:",g.error),n(g.error)},speechSynthesis.speak(s)})}async synthesizeWithElevenLabsTTS(e){const t=e.text.map(u=>u.word).join(" "),n=e.voice||this.avatar.ttsVoice||this.opt.ttsVoice||"21m00Tcm4TlvDq8ikWAM",i={text:t,model_id:"eleven_monolingual_v1",voice_settings:{stability:.5,similarity_boost:.5,style:0,use_speaker_boost:!0}},s=await fetch(`${this.opt.ttsEndpoint}/${n}`,{method:"POST",headers:{Accept:"audio/mpeg","Content-Type":"application/json","xi-api-key":this.opt.ttsApikey},body:JSON.stringify(i)});if(!s.ok)throw new Error(`ElevenLabs TTS error: ${s.status} ${s.statusText}`);const o=await s.arrayBuffer(),a=await this.audioCtx.decodeAudioData(o);console.log("Using text-based lip-sync for debugging...");const l=this.avatar.lipsyncLang||this.opt.lipsyncLang||"en";let r;try{console.log("Lip-sync modules available:",{hasLipsync:!!this.lipsync,lipsyncKeys:this.lipsync?Object.keys(this.lipsync):[],lipsyncLang:l});const u=this.lipsyncPreProcessText(t,l),d=this.lipsyncWordsToVisemes(u,l);if(console.log("Lip-sync data:",{processedText:u,lipsyncData:d,hasVisemes:d&&d.visemes&&d.visemes.length>0}),d&&d.visemes&&d.visemes.length>0)r={visemes:d.visemes.map((f,x)=>({viseme:f,startTime:x*a.duration/d.visemes.length,endTime:(x+1)*a.duration/d.visemes.length,duration:a.duration/d.visemes.length,intensity:.7})),words:[],duration:a.duration,features:{onsets:[],boundaries:[]}};else throw new Error("No visemes generated from text")}catch(u){console.error("Text-based lip-sync failed, using fallback:",u);const d=t.toLowerCase().split(/\s+/),f=[];for(const x of d)for(const y of x){let R="aa";"aeiou".includes(y)?R="aa":"bp".includes(y)?R="PP":"fv".includes(y)?R="FF":"st".includes(y)?R="SS":"dln".includes(y)?R="DD":"kg".includes(y)?R="kk":"rw".includes(y)&&(R="RR"),f.push(R)}r={visemes:f.map((x,y)=>({viseme:x,startTime:y*a.duration/f.length,endTime:(y+1)*a.duration/f.length,duration:a.duration/f.length,intensity:.6})),words:[],duration:a.duration,features:{onsets:[],boundaries:[]}}}console.log("ElevenLabs TTS Audio Analysis:",{text:t,audioDuration:a.duration,visemeCount:r.visemes?r.visemes.length:0,wordCount:r.words?r.words.length:0,features:{onsets:r.features&&r.features.onsets?r.features.onsets.length:0,boundaries:r.features&&r.features.phonemeBoundaries?r.features.phonemeBoundaries.length:0},visemes:r.visemes?r.visemes.slice(0,3):[]});const h=[];if(r.visemes&&r.visemes.length>0){console.log("ElevenLabs: Generating lip-sync animation from",r.visemes.length,"visemes");for(let u=0;u<r.visemes.length;u++){const d=r.visemes[u],f=d.startTime*1e3,x=d.duration*1e3,y=d.intensity;h.push({template:{name:"viseme"},ts:[f-Math.min(60,2*x/3),f+Math.min(25,x/2),f+x+Math.min(60,x/2)],vs:{["viseme_"+d.viseme]:[null,y,0]}})}console.log("ElevenLabs: Generated",h.length,"lip-sync animation frames")}else console.warn("ElevenLabs: No visemes available for lip-sync animation");const c=[...e.anim,...h];console.log("ElevenLabs: Combined animation frames:",c.length,"(original:",e.anim.length,"+ lipsync:",h.length,")"),this.audioPlaylist.push({anim:c,audio:a}),this.onSubtitles=e.onSubtitles||null,this.resetLips(),e.mood&&this.setMood(e.mood),this.playAudio()}async synthesizeWithAzureTTS(e){const t=e.text.map(c=>c.word).join(" "),i=`
|
|
8
|
-
<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xml:lang="en-US">
|
|
9
|
-
<voice name="${e.voice||this.avatar.ttsVoice||this.opt.ttsVoice||"en-US-AriaNeural"}">
|
|
10
|
-
${t}
|
|
11
|
-
</voice>
|
|
12
|
-
</speak>
|
|
13
|
-
`,s=await fetch(this.opt.ttsEndpoint,{method:"POST",headers:{"Ocp-Apim-Subscription-Key":this.opt.ttsApikey,"Content-Type":"application/ssml+xml","X-Microsoft-OutputFormat":"audio-16khz-128kbitrate-mono-mp3"},body:i});if(!s.ok)throw new Error(`Azure TTS error: ${s.status} ${s.statusText}`);const o=await s.arrayBuffer(),a=await this.audioCtx.decodeAudioData(o);console.log("Analyzing audio for precise lip-sync...");const l=await this.audioAnalyzer.analyzeAudio(a,t);console.log("Azure TTS Audio Analysis:",{text:t,audioDuration:a.duration,visemeCount:l.visemes.length,wordCount:l.words.length,features:{onsets:l.features.onsets.length,boundaries:l.features.phonemeBoundaries.length}});const r=[];for(let c=0;c<l.visemes.length;c++){const u=l.visemes[c],d=u.startTime*1e3,f=u.duration*1e3,x=u.intensity;r.push({template:{name:"viseme"},ts:[d-Math.min(60,2*f/3),d+Math.min(25,f/2),d+f+Math.min(60,f/2)],vs:{["viseme_"+u.viseme]:[null,x,0]}})}const h=[...e.anim,...r];this.audioPlaylist.push({anim:h,audio:a}),this.onSubtitles=e.onSubtitles||null,this.resetLips(),e.mood&&this.setMood(e.mood),this.playAudio()}async synthesizeWithExternalTTS(e){let t="<speak>";e.text.forEach((o,a)=>{a>0&&(t+=" <mark name='"+o.mark+"'/>"),t+=o.word.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'").replace(new RegExp("^\\p{Dash_Punctuation}$","ug"),'<break time="750ms"/>')}),t+="</speak>";const n={method:"POST",headers:{"Content-Type":"application/json; charset=utf-8"},body:JSON.stringify({input:{ssml:t},voice:{languageCode:e.lang||this.avatar.ttsLang||this.opt.ttsLang,name:e.voice||this.avatar.ttsVoice||this.opt.ttsVoice},audioConfig:{audioEncoding:this.ttsAudioEncoding,speakingRate:(e.rate||this.avatar.ttsRate||this.opt.ttsRate)+this.mood.speech.deltaRate,pitch:(e.pitch||this.avatar.ttsPitch||this.opt.ttsPitch)+this.mood.speech.deltaPitch,volumeGainDb:(e.volume||this.avatar.ttsVolume||this.opt.ttsVolume)+this.mood.speech.deltaVolume},enableTimePointing:[1]})};this.opt.jwtGet&&typeof this.opt.jwtGet=="function"&&(n.headers.Authorization="Bearer "+await this.opt.jwtGet());const i=await fetch(this.opt.ttsEndpoint+(this.opt.ttsApikey?"?key="+this.opt.ttsApikey:""),n),s=await i.json();if(i.status===200&&s&&s.audioContent){const o=this.b64ToArrayBuffer(s.audioContent),a=await this.audioCtx.decodeAudioData(o);this.speakWithHands();const l=[0];let r=0;e.text.forEach((u,d)=>{if(d>0){let f=l[l.length-1];s.timepoints[r]&&(f=s.timepoints[r].timeSeconds*1e3,s.timepoints[r].markName===""+u.mark&&r++),l.push(f)}});const h=[{mark:0,time:0}];l.forEach((u,d)=>{if(d>0){let f=u-l[d-1];h[d-1].duration=f,h.push({mark:d,time:u})}});let c=1e3*a.duration;c>this.opt.ttsTrimEnd&&(c=c-this.opt.ttsTrimEnd),h[h.length-1].duration=c-h[h.length-1].time,e.anim.forEach(u=>{const d=h[u.mark];if(d)for(let f=0;f<u.ts.length;f++)u.ts[f]=d.time+u.ts[f]*d.duration+this.opt.ttsTrimStart}),this.audioPlaylist.push({anim:e.anim,audio:a}),this.onSubtitles=e.onSubtitles||null,this.resetLips(),e.mood&&this.setMood(e.mood),this.playAudio()}else this.startSpeaking(!0)}async startSpeaking(e=!1){if(!(!this.armature||this.isSpeaking&&!e))if(this.stateName="speaking",this.isSpeaking=!0,this.speechQueue.length){let t=this.speechQueue.shift();if(t.emoji){this.lookAtCamera(500);let n=t.emoji.dt.reduce((i,s)=>i+s,0);this.animQueue.push(this.animFactory(t.emoji)),setTimeout(this.startSpeaking.bind(this),n,!0)}else if(t.break)setTimeout(this.startSpeaking.bind(this),t.break,!0);else if(t.audio)t.isRaw||(this.lookAtCamera(500),this.speakWithHands(),this.resetLips()),this.audioPlaylist.push({anim:t.anim,audio:t.audio,isRaw:t.isRaw}),this.onSubtitles=t.onSubtitles||null,t.mood&&this.setMood(t.mood),this.playAudio();else if(t.text){this.lookAtCamera(500);try{!this.opt.ttsEndpoint||this.opt.ttsEndpoint===""?await this.synthesizeWithBrowserTTS(t):this.opt.ttsService==="elevenlabs"?await this.synthesizeWithElevenLabsTTS(t):this.opt.ttsService==="azure"?await this.synthesizeWithAzureTTS(t):await this.synthesizeWithExternalTTS(t)}catch(n){console.error("Error:",n),this.startSpeaking(!0)}}else t.anim?(this.onSubtitles=t.onSubtitles||null,this.resetLips(),t.mood&&this.setMood(t.mood),t.anim.forEach((n,i)=>{for(let s=0;s<n.ts.length;s++)n.ts[s]=this.animClock+10*i;this.animQueue.push(n)}),setTimeout(this.startSpeaking.bind(this),10*t.anim.length,!0)):t.marker?(typeof t.marker=="function"&&t.marker(),this.startSpeaking(!0)):this.startSpeaking(!0)}else this.stateName="idle",this.isSpeaking=!1}pauseSpeaking(){try{this.audioSpeechSource.stop()}catch{}this.audioPlaylist.length=0,this.stateName="idle",this.isSpeaking=!1,this.isAudioPlaying=!1,this.animQueue=this.animQueue.filter(e=>e.template.name!=="viseme"&&e.template.name!=="subtitles"&&e.template.name!=="blendshapes"),this.armature&&(this.resetLips(),this.render())}stopSpeaking(){try{this.audioSpeechSource.stop()}catch{}this.audioPlaylist.length=0,this.speechQueue.length=0,this.animQueue=this.animQueue.filter(e=>e.template.name!=="viseme"&&e.template.name!=="subtitles"&&e.template.name!=="blendshapes"),this.stateName="idle",this.isSpeaking=!1,this.isAudioPlaying=!1,this.armature&&(this.resetLips(),this.render())}async streamStart(e={},t=null,n=null,i=null,s=null){if(this.stopSpeaking(),this.isStreaming=!0,e.waitForAudioChunks!==void 0&&(this.streamWaitForAudioChunks=e.waitForAudioChunks),this.streamWaitForAudioChunks||(this.streamAudioStartTime=this.animClock),this.streamLipsyncQueue=[],this.streamLipsyncType=e.lipsyncType||this.streamLipsyncType||"visemes",this.streamLipsyncLang=e.lipsyncLang||this.streamLipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,this.onAudioStart=t,this.onAudioEnd=n,this.onMetrics=s,e.sampleRate!==void 0){const a=e.sampleRate;typeof a=="number"&&a>=8e3&&a<=96e3?a!==this.audioCtx.sampleRate&&this.initAudioGraph(a):console.warn("Invalid sampleRate provided. It must be a number between 8000 and 96000 Hz.")}if(e.gain!==void 0&&(this.audioStreamGainNode.gain.value=e.gain),!this.streamWorkletNode||!this.streamWorkletNode.port||this.streamWorkletNode.numberOfOutputs===0||this.streamWorkletNode.context!==this.audioCtx){if(this.streamWorkletNode)try{this.streamWorkletNode.disconnect(),this.streamWorkletNode=null}catch{}if(!this.workletLoaded)try{const a=this.audioCtx.audioWorklet.addModule(zi.href),l=new Promise((r,h)=>setTimeout(()=>h(new Error("Worklet loading timed out")),5e3));await Promise.race([a,l]),this.workletLoaded=!0}catch(a){throw console.error("Failed to load audio worklet:",a),new Error("Failed to initialize streaming speech")}this.streamWorkletNode=new AudioWorkletNode(this.audioCtx,"playback-worklet",{processorOptions:{sampleRate:this.audioCtx.sampleRate,metrics:e.metrics||{enabled:!1}}}),this.streamWorkletNode.connect(this.audioStreamGainNode),this.streamWorkletNode.connect(this.audioAnalyzerNode),this.streamWorkletNode.port.onmessage=a=>{if(a.data.type==="playback-started"&&(this.isSpeaking=!0,this.stateName="speaking",this.streamWaitForAudioChunks&&(this.streamAudioStartTime=this.animClock),this._processStreamLipsyncQueue(),this.speakWithHands(),this.onAudioStart))try{this.onAudioStart?.()}catch(l){console.error(l)}if(a.data.type==="playback-ended"&&(this._streamPause(),this.onAudioEnd))try{this.onAudioEnd()}catch{}if(this.onMetrics&&a.data.type==="metrics")try{this.onMetrics(a.data)}catch{}}}if(e.metrics)try{this.streamWorkletNode.port.postMessage({type:"config-metrics",data:e.metrics})}catch{}if(this.resetLips(),this.lookAtCamera(500),e.mood&&this.setMood(e.mood),this.onSubtitles=i||null,this.audioCtx.state==="suspended"||this.audioCtx.state==="interrupted"){const a=this.audioCtx.resume(),l=new Promise((r,h)=>setTimeout(()=>h("p2"),1e3));try{await Promise.race([a,l])}catch{console.warn("Can't play audio. Web Audio API suspended. This is often due to calling some speak method before the first user action, which is typically prevented by the browser.");return}}}streamNotifyEnd(){!this.isStreaming||!this.streamWorkletNode||this.streamWorkletNode.port.postMessage({type:"no-more-data"})}streamInterrupt(){if(!this.isStreaming)return;const e=this.isSpeaking;if(this.streamWorkletNode)try{this.streamWorkletNode.port.postMessage({type:"stop"})}catch{}if(this._streamPause(!0),e&&this.onAudioEnd)try{this.onAudioEnd()}catch{}}streamStop(){if(this.isStreaming){if(this.streamInterrupt(),this.streamWorkletNode){try{this.streamWorkletNode.disconnect()}catch{}this.streamWorkletNode=null}this.isStreaming=!1}}_streamPause(e=!1){this.isSpeaking=!1,this.stateName="idle",e&&(this.streamWaitForAudioChunks&&(this.streamAudioStartTime=null),this.streamLipsyncQueue=[],this.animQueue=this.animQueue.filter(t=>t.template.name!=="viseme"&&t.template.name!=="subtitles"&&t.template.name!=="blendshapes"),this.armature&&(this.resetLips(),this.render()))}_processStreamLipsyncQueue(){if(this.isStreaming)for(;this.streamLipsyncQueue.length>0;){const e=this.streamLipsyncQueue.shift();this._processLipsyncData(e,this.streamAudioStartTime)}}_processLipsyncData(e,t){if(this.isStreaming){if(e.visemes&&this.streamLipsyncType=="visemes")for(let n=0;n<e.visemes.length;n++){const i=e.visemes[n],s=t+e.vtimes[n],o=e.vdurations[n],a={template:{name:"viseme"},ts:[s-2*o/3,s+o/2,s+o+o/2],vs:{["viseme_"+i]:[null,i==="PP"||i==="FF"?.9:.6,0]}};this.animQueue.push(a)}if(e.words&&(this.onSubtitles||this.streamLipsyncType=="words"))for(let n=0;n<e.words.length;n++){const i=e.words[n],s=e.wtimes[n];let o=e.wdurations[n];if(i.length&&(this.onSubtitles&&this.animQueue.push({template:{name:"subtitles"},ts:[t+s],vs:{subtitles:[" "+i]}}),this.streamLipsyncType=="words")){const a=this.streamLipsyncLang||this.avatar.lipsyncLang||this.opt.lipsyncLang,l=this.lipsyncPreProcessText(i,a),r=this.lipsyncWordsToVisemes(l,a);if(r&&r.visemes&&r.visemes.length){const h=r.times[r.visemes.length-1]+r.durations[r.visemes.length-1],c=Math.min(o,Math.max(0,o-r.visemes.length*150));let u=.6+this.convertRange(c,[0,o],[0,.4]);if(o=Math.min(o,r.visemes.length*200),h>0)for(let d=0;d<r.visemes.length;d++){const f=t+s+r.times[d]/h*o,x=r.durations[d]/h*o;this.animQueue.push({template:{name:"viseme"},ts:[f-Math.min(60,2*x/3),f+Math.min(25,x/2),f+x+Math.min(60,x/2)],vs:{["viseme_"+r.visemes[d]]:[null,r.visemes[d]==="PP"||r.visemes[d]==="FF"?.9:u,0]}})}}}}if(e.anims&&this.streamLipsyncType=="blendshapes")for(let n=0;n<e.anims.length;n++){let i=e.anims[n];i.delay+=t;let s=this.animFactory(i,!1,1,1,!0);this.animQueue.push(s)}}}streamAudio(e){if(!(!this.isStreaming||!this.streamWorkletNode)){if(this.isSpeaking||(this.streamLipsyncQueue=[],this.streamAudioStartTime=null),this.isSpeaking=!0,this.stateName="speaking",e.audio!==void 0){const t={type:"audioData",data:null};if(e.audio instanceof ArrayBuffer)t.data=e.audio,this.streamWorkletNode.port.postMessage(t,[t.data]);else if(e.audio instanceof Int16Array||e.audio instanceof Uint8Array){const n=e.audio.buffer.slice(e.audio.byteOffset,e.audio.byteOffset+e.audio.byteLength);t.data=n,this.streamWorkletNode.port.postMessage(t,[t.data])}else if(e.audio instanceof Float32Array){const n=new Int16Array(e.audio.length);for(let i=0;i<e.audio.length;i++){let s=Math.max(-1,Math.min(1,e.audio[i]));n[i]=s<0?s*32768:s*32767}t.data=n.buffer,this.streamWorkletNode.port.postMessage(t,[t.data])}else console.error("r.audio is not a supported type. Must be ArrayBuffer, Int16Array, Uint8Array, or Float32Array:",e.audio)}if(e.visemes||e.anims||e.words){if(this.streamWaitForAudioChunks&&!this.streamAudioStartTime){this.streamLipsyncQueue.length>=200&&this.streamLipsyncQueue.shift(),this.streamLipsyncQueue.push(e);return}else!this.streamWaitForAudioChunks&&!this.streamAudioStartTime&&(this.streamAudioStartTime=this.animClock);this._processLipsyncData(e,this.streamAudioStartTime)}}}makeEyeContact(e){this.animQueue.push(this.animFactory({name:"eyecontact",dt:[0,e],vs:{eyeContact:[1]}}))}lookAhead(e){if(e){let t=(Math.random()-.5)/4,n=(Math.random()-.5)/4,i=this.animQueue.findIndex(o=>o.template.name==="lookat");i!==-1&&this.animQueue.splice(i,1);const s={name:"lookat",dt:[750,e],vs:{bodyRotateX:[t],bodyRotateY:[n],eyesRotateX:[-3*t+.1],eyesRotateY:[-5*n],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(s))}}lookAtCamera(e){let t;if(this.speakTo&&(t=new v.Vector3,this.speakTo.objectLeftEye?.isObject3D?(this.speakTo.armature.objectHead,this.speakTo.objectLeftEye.updateMatrixWorld(!0),this.speakTo.objectRightEye.updateMatrixWorld(!0),me.setFromMatrixPosition(this.speakTo.objectLeftEye.matrixWorld),ye.setFromMatrixPosition(this.speakTo.objectRightEye.matrixWorld),t.addVectors(me,ye).divideScalar(2)):this.speakTo.isObject3D?this.speakTo.getWorldPosition(t):this.speakTo.isVector3?t.set(this.speakTo):this.speakTo.x&&this.speakTo.y&&this.speakTo.z&&t.set(this.speakTo.x,this.speakTo.y,this.speakTo.z)),!t){if(this.avatar.hasOwnProperty("avatarIgnoreCamera")){if(this.avatar.avatarIgnoreCamera){this.lookAhead(e);return}}else if(this.opt.avatarIgnoreCamera){this.lookAhead(e);return}this.lookAt(null,null,e);return}this.objectLeftEye.updateMatrixWorld(!0),this.objectRightEye.updateMatrixWorld(!0),me.setFromMatrixPosition(this.objectLeftEye.matrixWorld),ye.setFromMatrixPosition(this.objectRightEye.matrixWorld),me.add(ye).divideScalar(2),j.copy(this.armature.quaternion),j.multiply(this.poseTarget.props["Hips.quaternion"]),j.multiply(this.poseTarget.props["Spine.quaternion"]),j.multiply(this.poseTarget.props["Spine1.quaternion"]),j.multiply(this.poseTarget.props["Spine2.quaternion"]),j.multiply(this.poseTarget.props["Neck.quaternion"]),j.multiply(this.poseTarget.props["Head.quaternion"]);const n=new v.Vector3().subVectors(t,me).normalize(),i=Math.atan2(n.x,n.z),s=Math.asin(-n.y);N.set(s,i,0,"YXZ");const a=new v.Quaternion().setFromEuler(N),l=new v.Quaternion().copy(a).multiply(j.clone().invert());N.setFromQuaternion(l,"YXZ");let r=N.x/(40/24)+.2,h=N.y/(9/4),c=Math.min(.6,Math.max(-.3,r)),u=Math.min(.8,Math.max(-.8,h)),d=(Math.random()-.5)/4,f=(Math.random()-.5)/4;if(e){let x=this.animQueue.findIndex(R=>R.template.name==="lookat");x!==-1&&this.animQueue.splice(x,1);const y={name:"lookat",dt:[750,e],vs:{bodyRotateX:[c+d],bodyRotateY:[u+f],eyesRotateX:[-3*d+.1],eyesRotateY:[-5*f],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(y))}}lookAt(e,t,n){if(!this.camera)return;const i=this.nodeAvatar.getBoundingClientRect();this.objectLeftEye.updateMatrixWorld(!0),this.objectRightEye.updateMatrixWorld(!0);const s=new v.Vector3().setFromMatrixPosition(this.objectLeftEye.matrixWorld),o=new v.Vector3().setFromMatrixPosition(this.objectRightEye.matrixWorld),a=new v.Vector3().addVectors(s,o).divideScalar(2);a.project(this.camera);let l=(a.x+1)/2*i.width+i.left,r=-(a.y-1)/2*i.height+i.top;e===null&&(e=l),t===null&&(t=r),j.copy(this.armature.quaternion),j.multiply(this.poseTarget.props["Hips.quaternion"]),j.multiply(this.poseTarget.props["Spine.quaternion"]),j.multiply(this.poseTarget.props["Spine1.quaternion"]),j.multiply(this.poseTarget.props["Spine2.quaternion"]),j.multiply(this.poseTarget.props["Neck.quaternion"]),j.multiply(this.poseTarget.props["Head.quaternion"]),N.setFromQuaternion(j);let h=N.x/(40/24),c=N.y/(9/4),u=Math.min(.4,Math.max(-.4,this.camera.rotation.x)),d=Math.min(.4,Math.max(-.4,this.camera.rotation.y)),f=Math.max(window.innerWidth-l,l),x=Math.max(window.innerHeight-r,r),y=this.convertRange(t,[r-x,r+x],[-.3,.6])-h+u,R=this.convertRange(e,[l-f,l+f],[-.8,.8])-c+d;y=Math.min(.6,Math.max(-.3,y)),R=Math.min(.8,Math.max(-.8,R));let I=(Math.random()-.5)/4,g=(Math.random()-.5)/4;if(n){let T=this.animQueue.findIndex(L=>L.template.name==="lookat");T!==-1&&this.animQueue.splice(T,1);const C={name:"lookat",dt:[750,n],vs:{bodyRotateX:[y+I],bodyRotateY:[R+g],eyesRotateX:[-3*I+.1],eyesRotateY:[-5*g],browInnerUp:[[0,.7]],mouthLeft:[[0,.7]],mouthRight:[[0,.7]],eyeContact:[0],headMove:[0]}};this.animQueue.push(this.animFactory(C))}}touchAt(e,t){if(!this.camera)return;const n=this.nodeAvatar.getBoundingClientRect(),i=new v.Vector2((e-n.left)/n.width*2-1,-((t-n.top)/n.height)*2+1),s=new v.Raycaster;s.setFromCamera(i,this.camera);const o=s.intersectObject(this.armature);if(o.length>0){const a=o[0].point,l=new v.Vector3,r=new v.Vector3;this.objectLeftArm.getWorldPosition(l),this.objectRightArm.getWorldPosition(r);const h=l.distanceToSquared(a),c=r.distanceToSquared(a);h<c?(this.ikSolve({iterations:20,root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3,maxAngle:.2},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},a,!1,1e3),this.setValue("handFistLeft",0)):(this.ikSolve({iterations:20,root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5,maxAngle:.1},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5,maxAngle:.2},{link:"RightArm",minx:-1.5,maxx:1.5,miny:0,maxy:0,minz:-1,maxz:3}]},a,!1,1e3),this.setValue("handFistRight",0))}else["LeftArm","LeftForeArm","LeftHand","RightArm","RightForeArm","RightHand"].forEach(a=>{let l=a+".quaternion";this.poseTarget.props[l].copy(this.getPoseTemplateProp(l)),this.poseTarget.props[l].t=this.animClock,this.poseTarget.props[l].d=1e3});return o.length>0}speakWithHands(e=0,t=.5){if(this.mixer||this.gesture||!this.poseTarget.template.standing||this.poseTarget.template.bend||Math.random()>t)return;this.ikSolve({root:"LeftShoulder",effector:"LeftHandMiddle1",links:[{link:"LeftHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"LeftForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-.5,maxz:3},{link:"LeftArm",minx:-1.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-1,maxz:3}]},new v.Vector3(this.gaussianRandom(0,.5),this.gaussianRandom(-.8,-.2),this.gaussianRandom(0,.5)),!0),this.ikSolve({root:"RightShoulder",effector:"RightHandMiddle1",links:[{link:"RightHand",minx:-.5,maxx:.5,miny:-1,maxy:1,minz:-.5,maxz:.5},{link:"RightForeArm",minx:-.5,maxx:1.5,miny:-1.5,maxy:1.5,minz:-3,maxz:.5},{link:"RightArm"}]},new v.Vector3(this.gaussianRandom(-.5,0),this.gaussianRandom(-.8,-.2),this.gaussianRandom(0,.5)),!0);const n=[],i=[];n.push(100+Math.round(Math.random()*500)),i.push({duration:1e3,props:{"LeftHand.quaternion":new v.Quaternion().setFromEuler(new v.Euler(0,-1-Math.random(),0)),"RightHand.quaternion":new v.Quaternion().setFromEuler(new v.Euler(0,1+Math.random(),0))}}),["LeftArm","LeftForeArm","RightArm","RightForeArm"].forEach(o=>{i[0].props[o+".quaternion"]=this.ikMesh.getObjectByName(o).quaternion.clone()}),n.push(1e3+Math.round(Math.random()*500)),i.push({duration:2e3,props:{}}),["LeftArm","LeftForeArm","RightArm","RightForeArm","LeftHand","RightHand"].forEach(o=>{i[1].props[o+".quaternion"]=null});const s=this.animFactory({name:"talkinghands",delay:e,dt:n,vs:{moveto:i}});this.animQueue.push(s)}getSlowdownRate(e){return this.animSlowdownRate}setSlowdownRate(e){this.animSlowdownRate=e,this.audioSpeechSource.playbackRate.value=1/this.animSlowdownRate,this.audioBackgroundSource.playbackRate.value=1/this.animSlowdownRate}getAutoRotateSpeed(e){return this.controls.autoRotateSpeed}setAutoRotateSpeed(e){this.controls.autoRotateSpeed=e,this.controls.autoRotate=e>0}start(){this.armature&&this.isRunning===!1&&(this.audioCtx.resume(),this.animTimeLast=performance.now(),this.isRunning=!0,this.isAvatarOnly||requestAnimationFrame(this.animate.bind(this)))}stop(){this.isRunning=!1,this.audioCtx.suspend()}startListening(e,t={},n=null){this.listeningAnalyzer=e,this.listeningAnalyzer.fftSize=256,this.listeningAnalyzer.smoothingTimeConstant=.1,this.listeningAnalyzer.minDecibels=-70,this.listeningAnalyzer.maxDecibels=-10,this.listeningOnchange=n&&typeof n=="function"?n:null,this.listeningSilenceThresholdLevel=t?.hasOwnProperty("listeningSilenceThresholdLevel")?t.listeningSilenceThresholdLevel:this.opt.listeningSilenceThresholdLevel,this.listeningSilenceThresholdMs=t?.hasOwnProperty("listeningSilenceThresholdMs")?t.listeningSilenceThresholdMs:this.opt.listeningSilenceThresholdMs,this.listeningSilenceDurationMax=t?.hasOwnProperty("listeningSilenceDurationMax")?t.listeningSilenceDurationMax:this.opt.listeningSilenceDurationMax,this.listeningActiveThresholdLevel=t?.hasOwnProperty("listeningActiveThresholdLevel")?t.listeningActiveThresholdLevel:this.opt.listeningActiveThresholdLevel,this.listeningActiveThresholdMs=t?.hasOwnProperty("listeningActiveThresholdMs")?t.listeningActiveThresholdMs:this.opt.listeningActiveThresholdMs,this.listeningActiveDurationMax=t?.hasOwnProperty("listeningActiveDurationMax")?t.listeningActiveDurationMax:this.opt.listeningActiveDurationMax,this.listeningActive=!1,this.listeningVolume=0,this.listeningTimer=0,this.listeningTimerTotal=0,this.isListening=!0}stopListening(){this.isListening=!1}async playAnimation(e,t=null,n=10,i=0,s=.01,o=!1){if(!this.armature)return;this.positionWasLocked=!o,o?console.log("Position locking disabled for FBX animation:",e):(this.lockAvatarPosition(),console.log("Position locked immediately before FBX animation:",e));let a=this.animClips.find(l=>l.url===e+"-"+i);if(a){let l=this.animQueue.find(c=>c.template.name==="pose");l&&(l.ts[0]=1/0),Object.entries(a.pose.props).forEach(c=>{this.poseBase.props[c[0]]=c[1].clone(),this.poseTarget.props[c[0]]=c[1].clone(),this.poseTarget.props[c[0]].t=0,this.poseTarget.props[c[0]].d=1e3}),this.mixer?console.log("Using existing mixer for FBX animation, preserving morph targets"):(this.mixer=new v.AnimationMixer(this.armature),console.log("Created new mixer for FBX animation")),this.mixer.addEventListener("finished",this.stopAnimation.bind(this),{once:!0});const r=Math.ceil(n/a.clip.duration),h=this.mixer.clipAction(a.clip);h.setLoop(v.LoopRepeat,r),h.clampWhenFinished=!0,this.currentFBXAction=h;try{h.fadeIn(.5).play(),console.log("FBX animation started successfully:",e)}catch(c){console.warn("FBX animation failed to start:",c),this.stopAnimation();return}if(h.getClip().tracks.length===0){console.warn("FBX animation has no valid tracks, stopping"),this.stopAnimation();return}}else{if(e.split(".").pop().toLowerCase()!=="fbx"){console.error(`Invalid file type for FBX animation: ${e}. Expected .fbx file.`);return}let r=!1;try{const u=await fetch(e,{method:"HEAD"});if(r=u.ok,!r){console.error(`FBX file not found at ${e}. Status: ${u.status}`),console.error("Please check:"),console.error("1. File path is correct (note: path is case-sensitive)"),console.error("2. File exists in your public folder"),console.error("3. File is accessible (not blocked by server)");return}}catch(u){console.warn(`Could not verify file existence for ${e}, attempting to load anyway:`,u)}const h=new it;let c;try{c=await h.loadAsync(e,t)}catch(u){console.error(`Failed to load FBX animation from ${e}:`,u),console.error("Error details:",{message:u.message,url:e,suggestion:"Make sure the file is a valid FBX file and the path is correct"}),u.message&&u.message.includes("version number")&&(console.error("FBX Loader Error: Cannot find version number"),console.error("This error usually means:"),console.error("1. The file is not a valid FBX file (might be GLB, corrupted, or wrong format)"),console.error("2. The file might be corrupted"),console.error("3. The file path might be incorrect"),console.error("4. The server returned an HTML error page instead of the FBX file"),console.error("5. The file might not exist at that path"),console.error(""),console.error("Solution: Please verify:"),console.error(` - File exists at: ${e}`),console.error(" - File is a valid FBX binary file"),console.error(" - File path matches your public folder structure"),console.error(" - File is not corrupted"));try{const d=await fetch(e),f=d.headers.get("content-type"),x=await d.text();console.error("Response details:",{status:d.status,contentType:f,firstBytes:x.substring(0,100),isHTML:x.trim().startsWith("<!DOCTYPE")||x.trim().startsWith("<html")}),(x.trim().startsWith("<!DOCTYPE")||x.trim().startsWith("<html"))&&console.error("The server returned an HTML page instead of an FBX file. The file path is likely incorrect.")}catch(d){console.error("Could not fetch file for debugging:",d)}return}if(c&&c.animations&&c.animations[i]){let u=c.animations[i];const d={};u.tracks.forEach(x=>{x.name=x.name.replaceAll("mixamorig","");const y=x.name.split(".");if(y[1]==="position"){for(let R=0;R<x.values.length;R++)x.values[R]=x.values[R]*s;d[x.name]=new v.Vector3(x.values[0],x.values[1],x.values[2])}else y[1]==="quaternion"?d[x.name]=new v.Quaternion(x.values[0],x.values[1],x.values[2],x.values[3]):y[1]==="rotation"&&(d[y[0]+".quaternion"]=new v.Quaternion().setFromEuler(new v.Euler(x.values[0],x.values[1],x.values[2],"XYZ")).normalize())});const f={props:d};d["Hips.position"]&&(d["Hips.position"].y<.5?f.lying=!0:f.standing=!0),this.animClips.push({url:e+"-"+i,clip:u,pose:f}),this.playAnimation(e,t,n,i,s)}else{const u="Animation "+e+" (ndx="+i+") not found";console.error(u),c&&c.animations?console.error(`FBX file loaded but has ${c.animations.length} animation(s), requested index ${i}`):console.error(c?"FBX file loaded but contains no animations":"FBX file failed to load or is invalid")}}}stopAnimation(){if(this.currentFBXAction&&(this.currentFBXAction.stop(),this.currentFBXAction=null,console.log("FBX animation action stopped, mixer preserved for lip-sync")),this.mixer&&this.mixer._actions.length===0&&(this.mixer=null,console.log("Mixer destroyed as no actions remain")),this.positionWasLocked?(this.unlockAvatarPosition(),console.log("Position unlocked after FBX animation stopped")):console.log("Position was not locked, no unlock needed"),this.gesture)for(let[t,n]of Object.entries(this.gesture))n.t=this.animClock,n.d=1e3,this.poseTarget.props.hasOwnProperty(t)&&(this.poseTarget.props[t].copy(n),this.poseTarget.props[t].t=this.animClock,this.poseTarget.props[t].d=1e3);let e=this.animQueue.find(t=>t.template.name==="pose");e&&(e.ts[0]=this.animClock),this.setPoseFromTemplate(null)}async playPose(e,t=null,n=5,i=0,s=.01){if(!this.armature)return;let o=this.poseTemplates[e];if(!o){const a=this.animPoses.find(l=>l.url===e+"-"+i);a&&(o=a.pose)}if(o){this.poseName=e,this.mixer=null;let a=this.animQueue.find(l=>l.template.name==="pose");a&&(a.ts[0]=this.animClock+n*1e3+2e3),this.setPoseFromTemplate(o)}else{let l=await new it().loadAsync(e,t);if(l&&l.animations&&l.animations[i]){let r=l.animations[i];const h={};r.tracks.forEach(u=>{u.name=u.name.replaceAll("mixamorig","");const d=u.name.split(".");d[1]==="position"?h[u.name]=new v.Vector3(u.values[0]*s,u.values[1]*s,u.values[2]*s):d[1]==="quaternion"?h[u.name]=new v.Quaternion(u.values[0],u.values[1],u.values[2],u.values[3]):d[1]==="rotation"&&(h[d[0]+".quaternion"]=new v.Quaternion().setFromEuler(new v.Euler(u.values[0],u.values[1],u.values[2],"XYZ")).normalize())});const c={props:h};h["Hips.position"]&&(h["Hips.position"].y<.5?c.lying=!0:c.standing=!0),this.animPoses.push({url:e+"-"+i,pose:c}),this.playPose(e,t,n,i,s)}else{const r="Pose "+e+" (ndx="+i+") not found";console.error(r)}}}stopPose(){this.stopAnimation()}playGesture(e,t=3,n=!1,i=1e3){if(!this.armature)return;let s=this.gestureTemplates[e];if(s){this.gestureTimeout&&(clearTimeout(this.gestureTimeout),this.gestureTimeout=null);let a=this.animQueue.findIndex(l=>l.template.name==="talkinghands");a!==-1&&(this.animQueue[a].ts=this.animQueue[a].ts.map(l=>0)),this.gesture=this.propsToThreeObjects(s),n&&(this.gesture=this.mirrorPose(this.gesture)),e==="namaste"&&this.avatar.body==="M"&&(this.gesture["RightArm.quaternion"].rotateTowards(new v.Quaternion(0,1,0,0),-.25),this.gesture["LeftArm.quaternion"].rotateTowards(new v.Quaternion(0,1,0,0),-.25));for(let[l,r]of Object.entries(this.gesture))r.t=this.animClock,r.d=i,this.poseTarget.props.hasOwnProperty(l)&&(this.poseTarget.props[l].copy(r),this.poseTarget.props[l].t=this.animClock,this.poseTarget.props[l].d=i);t&&Number.isFinite(t)&&(this.gestureTimeout=setTimeout(this.stopGesture.bind(this,i),1e3*t))}let o=this.animEmojis[e];if(o&&(o&&o.link&&(o=this.animEmojis[o.link]),o)){this.lookAtCamera(500);const a=this.animFactory(o);if(a.gesture=!0,t&&Number.isFinite(t)){const l=a.ts[0],h=a.ts[a.ts.length-1]-l;if(t*1e3-h>0){const u=[];for(let x=1;x<a.ts.length;x++)u.push(a.ts[x]-a.ts[x-1]);const d=o.template?.rescale||u.map(x=>x/h),f=t*1e3-h;a.ts=a.ts.map((x,y,R)=>y===0?l:R[y-1]+u[y-1]+d[y-1]*f)}else{const u=t*1e3/h;a.ts=a.ts.map(d=>l+u*(d-l))}}this.animQueue.push(a)}}stopGesture(e=1e3){if(this.gestureTimeout&&(clearTimeout(this.gestureTimeout),this.gestureTimeout=null),this.gesture){const n=Object.entries(this.gesture);this.gesture=null;for(const[i,s]of n)this.poseTarget.props.hasOwnProperty(i)&&(this.poseTarget.props[i].copy(this.getPoseTemplateProp(i)),this.poseTarget.props[i].t=this.animClock,this.poseTarget.props[i].d=e)}let t=this.animQueue.findIndex(n=>n.gesture);t!==-1&&this.animQueue.splice(t,1)}ikSolve(e,t=null,n=!1,i=null){const s=new v.Vector3,o=new v.Vector3,a=new v.Vector3,l=new v.Vector3,r=new v.Quaternion,h=new v.Vector3,c=new v.Vector3,u=new v.Vector3,d=this.ikMesh.getObjectByName(e.root);d.position.setFromMatrixPosition(this.armature.getObjectByName(e.root).matrixWorld),d.quaternion.setFromRotationMatrix(this.armature.getObjectByName(e.root).matrixWorld),t&&n&&t.applyQuaternion(this.armature.quaternion).add(d.position);const f=this.ikMesh.getObjectByName(e.effector),x=e.links;x.forEach(R=>{R.bone=this.ikMesh.getObjectByName(R.link),R.bone.quaternion.copy(this.getPoseTemplateProp(R.link+".quaternion"))}),d.updateMatrixWorld(!0);const y=e.iterations||10;if(t)for(let R=0;R<y;R++){let I=!1;for(let g=0,T=x.length;g<T;g++){const C=x[g].bone;C.matrixWorld.decompose(l,r,h),r.invert(),o.setFromMatrixPosition(f.matrixWorld),a.subVectors(o,l),a.applyQuaternion(r),a.normalize(),s.subVectors(t,l),s.applyQuaternion(r),s.normalize();let L=s.dot(a);L>1?L=1:L<-1&&(L=-1),L=Math.acos(L),!(L<1e-5)&&(x[g].minAngle!==void 0&&L<x[g].minAngle&&(L=x[g].minAngle),x[g].maxAngle!==void 0&&L>x[g].maxAngle&&(L=x[g].maxAngle),c.crossVectors(a,s),c.normalize(),j.setFromAxisAngle(c,L),C.quaternion.multiply(j),C.rotation.setFromVector3(u.setFromEuler(C.rotation).clamp(new v.Vector3(x[g].minx!==void 0?x[g].minx:-1/0,x[g].miny!==void 0?x[g].miny:-1/0,x[g].minz!==void 0?x[g].minz:-1/0),new v.Vector3(x[g].maxx!==void 0?x[g].maxx:1/0,x[g].maxy!==void 0?x[g].maxy:1/0,x[g].maxz!==void 0?x[g].maxz:1/0))),C.updateMatrixWorld(!0),I=!0)}if(!I)break}i&&x.forEach(R=>{this.poseTarget.props[R.link+".quaternion"].copy(R.bone.quaternion),this.poseTarget.props[R.link+".quaternion"].t=this.animClock,this.poseTarget.props[R.link+".quaternion"].d=i})}dispose(){this.isRunning=!1,this.stop(),this.stopSpeaking(),this.streamStop(),this.isAvatarOnly?this.armature&&(this.armature.parent&&this.armature.parent.remove(this.armature),this.clearThree(this.armature)):(this.clearThree(this.scene),this.resizeobserver.disconnect(),this.renderer&&(this.renderer.dispose(),this.renderer.domElement&&this.renderer.domElement.parentNode&&this.renderer.domElement.parentNode.removeChild(this.renderer.domElement),this.renderer=null)),this.clearThree(this.ikMesh),this.dynamicbones.dispose()}}const we={apiKey:"sk_ace57ef3ef65a92b9d3bee2a00183b78ca790bc3e10964f2",endpoint:"https://api.elevenlabs.io/v1/text-to-speech",defaultVoice:"21m00Tcm4TlvDq8ikWAM",voices:{rachel:"21m00Tcm4TlvDq8ikWAM",drew:"29vD33N1CtxCmqQRPOHJ",bella:"EXAVITQu4vr4xnSDxMaL",antoni:"ErXwobaYiN019PkySvjV",elli:"MF3mGyEYCl7XYWbV9V6O",josh:"VR6AewLTigWG4xSOukaG"}};function Be(){return{service:"elevenlabs",endpoint:we.endpoint,apiKey:we.apiKey,defaultVoice:we.defaultVoice,voices:we.voices}}function Pi(){const m=Be(),e=[];return Object.entries(m.voices).forEach(([t,n])=>{e.push({value:n,label:`${t.charAt(0).toUpperCase()+t.slice(1)} (${m.service})`})}),e}const ot=E.forwardRef(({avatarUrl:m="/avatars/brunette.glb",avatarBody:e="F",mood:t="neutral",ttsLang:n="en",ttsService:i=null,ttsVoice:s=null,ttsApiKey:o=null,bodyMovement:a="idle",movementIntensity:l=.5,showFullAvatar:r=!0,cameraView:h="upper",onReady:c=()=>{},onLoading:u=()=>{},onError:d=()=>{},className:f="",style:x={},animations:y={}},R)=>{const I=E.useRef(null),g=E.useRef(null),[T,C]=E.useState(!0),[L,P]=E.useState(null),[z,_]=E.useState(!1),U=Be(),S=i||U.service;let A;S==="browser"?A={service:"browser",endpoint:"",apiKey:null,defaultVoice:"Google US English"}:S==="elevenlabs"?A={service:"elevenlabs",endpoint:"https://api.elevenlabs.io/v1/text-to-speech",apiKey:o||U.apiKey,defaultVoice:s||U.defaultVoice||we.defaultVoice,voices:U.voices||we.voices}:A={...U,apiKey:o!==null?o:U.apiKey};const w={url:m,body:e,avatarMood:t,ttsLang:S==="browser"?"en-US":n,ttsVoice:s||A.defaultVoice,lipsyncLang:"en",showFullAvatar:r,bodyMovement:a,movementIntensity:l},O={ttsEndpoint:A.endpoint,ttsApikey:A.apiKey,ttsService:S,lipsyncModules:["en"],cameraView:h},Q=E.useCallback(async()=>{if(!(!I.current||g.current))try{if(C(!0),P(null),g.current=new Ht(I.current,O),g.current.controls&&(g.current.controls.enableRotate=!1,g.current.controls.enableZoom=!1,g.current.controls.enablePan=!1,g.current.controls.enableDamping=!1),y&&Object.keys(y).length>0&&(g.current.customAnimations=y),await g.current.showAvatar(w,X=>{if(X.lengthComputable){const V=Math.min(100,Math.round(X.loaded/X.total*100));u(V)}}),await new Promise(X=>{const V=()=>{g.current.lipsync&&Object.keys(g.current.lipsync).length>0?X():setTimeout(V,100)};V()}),g.current&&g.current.setShowFullAvatar)try{g.current.setShowFullAvatar(r)}catch(X){console.warn("Error setting full body mode on initialization:",X)}g.current&&g.current.controls&&(g.current.controls.enableRotate=!1,g.current.controls.enableZoom=!1,g.current.controls.enablePan=!1,g.current.controls.enableDamping=!1,g.current.controls.update()),C(!1),_(!0),c(g.current);const W=()=>{document.visibilityState==="visible"?g.current?.start():g.current?.stop()};return document.addEventListener("visibilitychange",W),()=>{document.removeEventListener("visibilitychange",W)}}catch(M){console.error("Error initializing TalkingHead:",M),P(M.message||"Failed to initialize avatar"),C(!1),d(M)}},[m,e,t,n,i,s,o,r,a,l,h]);E.useEffect(()=>(Q(),()=>{g.current&&(g.current.stop(),g.current.dispose(),g.current=null)}),[Q]),E.useEffect(()=>{if(!I.current||!g.current)return;const M=new ResizeObserver(X=>{for(const V of X)g.current&&g.current.onResize&&g.current.onResize()});M.observe(I.current);const W=()=>{g.current&&g.current.onResize&&g.current.onResize()};return window.addEventListener("resize",W),()=>{M.disconnect(),window.removeEventListener("resize",W)}},[z]);const Y=E.useCallback(async()=>{if(g.current&&g.current.audioCtx)try{(g.current.audioCtx.state==="suspended"||g.current.audioCtx.state==="interrupted")&&(await g.current.audioCtx.resume(),console.log("Audio context resumed"))}catch(M){console.warn("Failed to resume audio context:",M)}},[]),xe=E.useCallback(async(M,W={})=>{if(g.current&&z)try{await Y();const X={...W,lipsyncLang:W.lipsyncLang||w.lipsyncLang||"en"};if(W.onSpeechEnd&&g.current){const V=g.current,pe=V.onAudioEnd;let ee=null,Re=0;const Ve=600,Pe=()=>{if(Re++,Re>Ve){ee&&(clearInterval(ee),ee=null);try{W.onSpeechEnd()}catch(ve){console.error("Error in onSpeechEnd callback:",ve)}return}V&&(!V.isSpeaking||V.isSpeaking===!1)&&(!V.audioPlaylist||V.audioPlaylist.length===0)&&(!V.isAudioPlaying||V.isAudioPlaying===!1)&&(ee&&(clearInterval(ee),ee=null),setTimeout(()=>{try{W.onSpeechEnd()}catch(ve){console.error("Error in onSpeechEnd callback:",ve)}},100))};setTimeout(()=>{ee=setInterval(Pe,100)},500)}g.current.lipsync&&Object.keys(g.current.lipsync).length>0?(g.current.setSlowdownRate&&g.current.setSlowdownRate(1.05),g.current.speakText(M,X)):setTimeout(async()=>{await Y(),g.current&&g.current.lipsync&&(g.current.setSlowdownRate&&g.current.setSlowdownRate(1.05),g.current.speakText(M,X))},500)}catch(X){console.error("Error speaking text:",X),P(X.message||"Failed to speak text")}},[z,Y,w.lipsyncLang]),He=E.useCallback(()=>{g.current&&(g.current.stopSpeaking(),g.current.setSlowdownRate&&g.current.setSlowdownRate(1))},[]),le=E.useCallback(M=>{g.current&&g.current.setMood(M)},[]),Ue=E.useCallback(M=>{g.current&&g.current.setSlowdownRate&&g.current.setSlowdownRate(M)},[]),Ge=E.useCallback((M,W=!1)=>{if(g.current&&g.current.playAnimation){if(y&&y[M]&&(M=y[M]),g.current.setShowFullAvatar)try{g.current.setShowFullAvatar(!0)}catch(V){console.warn("Error setting full body mode:",V)}if(M.includes("."))try{g.current.playAnimation(M,null,10,0,.01,W)}catch(V){console.warn(`Failed to play ${M}:`,V);try{g.current.setBodyMovement("idle")}catch(pe){console.warn("Fallback animation also failed:",pe)}}else{const V=[".fbx",".glb",".gltf"];let pe=!1;for(const ee of V)try{g.current.playAnimation(M+ee,null,10,0,.01,W),pe=!0;break}catch{}if(!pe){console.warn("Animation not found:",M);try{g.current.setBodyMovement("idle")}catch(ee){console.warn("Fallback animation also failed:",ee)}}}}},[y]),Te=E.useCallback(()=>{g.current&&g.current.onResize&&g.current.onResize()},[]);return E.useImperativeHandle(R,()=>({speakText:xe,stopSpeaking:He,resumeAudioContext:Y,setMood:le,setTimingAdjustment:Ue,playAnimation:Ge,isReady:z,talkingHead:g.current,handleResize:Te,setBodyMovement:M=>{if(g.current&&g.current.setShowFullAvatar&&g.current.setBodyMovement)try{g.current.setShowFullAvatar(!0),g.current.setBodyMovement(M)}catch(W){console.warn("Error setting body movement:",W)}},setMovementIntensity:M=>g.current?.setMovementIntensity(M),playRandomDance:()=>{if(g.current&&g.current.setShowFullAvatar&&g.current.playRandomDance)try{g.current.setShowFullAvatar(!0),g.current.playRandomDance()}catch(M){console.warn("Error playing random dance:",M)}},playReaction:M=>{if(g.current&&g.current.setShowFullAvatar&&g.current.playReaction)try{g.current.setShowFullAvatar(!0),g.current.playReaction(M)}catch(W){console.warn("Error playing reaction:",W)}},playCelebration:()=>{if(g.current&&g.current.setShowFullAvatar&&g.current.playCelebration)try{g.current.setShowFullAvatar(!0),g.current.playCelebration()}catch(M){console.warn("Error playing celebration:",M)}},setShowFullAvatar:M=>{if(g.current&&g.current.setShowFullAvatar)try{g.current.setShowFullAvatar(M)}catch(W){console.warn("Error setting showFullAvatar:",W)}},lockAvatarPosition:()=>{if(g.current&&g.current.lockAvatarPosition)try{g.current.lockAvatarPosition()}catch(M){console.warn("Error locking avatar position:",M)}},unlockAvatarPosition:()=>{if(g.current&&g.current.unlockAvatarPosition)try{g.current.unlockAvatarPosition()}catch(M){console.warn("Error unlocking avatar position:",M)}}})),de.jsxs("div",{className:`talking-head-avatar ${f}`,style:{width:"100%",height:"100%",position:"relative",...x},children:[de.jsx("div",{ref:I,className:"talking-head-viewer",style:{width:"100%",height:"100%",minHeight:"400px"}}),T&&de.jsx("div",{className:"loading-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",fontSize:"18px",zIndex:10},children:"Loading avatar..."}),L&&de.jsx("div",{className:"error-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"#ff6b6b",fontSize:"16px",textAlign:"center",zIndex:10,padding:"20px",borderRadius:"8px"},children:L})]})});ot.displayName="TalkingHeadAvatar";const Pt=E.forwardRef(({text:m="Hello! I'm a talking avatar. How are you today?",onLoading:e=()=>{},onError:t=()=>{},onReady:n=()=>{},className:i="",style:s={},avatarConfig:o={}},a)=>{const l=E.useRef(null),r=E.useRef(null),[h,c]=E.useState(!0),[u,d]=E.useState(null),[f,x]=E.useState(!1),y=Be(),R=o.ttsService||y.service,I=R==="browser"?{endpoint:"",apiKey:null,defaultVoice:"Google US English"}:{...y,apiKey:o.ttsApiKey!==void 0&&o.ttsApiKey!==null?o.ttsApiKey:y.apiKey,endpoint:R==="elevenlabs"&&o.ttsApiKey?"https://api.elevenlabs.io/v1/text-to-speech":y.endpoint},g={url:"/avatars/brunette.glb",body:"F",avatarMood:"neutral",ttsLang:R==="browser"?"en-US":"en",ttsVoice:o.ttsVoice||I.defaultVoice,lipsyncLang:"en",showFullAvatar:!0,bodyMovement:"idle",movementIntensity:.5,...o},T={ttsEndpoint:I.endpoint,ttsApikey:I.apiKey,ttsService:R,lipsyncModules:["en"],cameraView:"upper"},C=E.useCallback(async()=>{if(!(!l.current||r.current))try{if(c(!0),d(null),r.current=new Ht(l.current,T),await r.current.showAvatar(g,w=>{if(w.lengthComputable){const O=Math.min(100,Math.round(w.loaded/w.total*100));e(O)}}),r.current.morphs&&r.current.morphs.length>0){const w=r.current.morphs[0].morphTargetDictionary;console.log("Available morph targets:",Object.keys(w));const O=Object.keys(w).filter(Q=>Q.startsWith("viseme_"));console.log("Viseme morph targets found:",O),O.length===0&&(console.warn("No viseme morph targets found! Lip-sync will not work properly."),console.log("Expected viseme targets: viseme_aa, viseme_E, viseme_I, viseme_O, viseme_U, viseme_PP, viseme_SS, viseme_TH, viseme_DD, viseme_FF, viseme_kk, viseme_nn, viseme_RR, viseme_CH, viseme_sil"))}if(await new Promise(w=>{const O=()=>{r.current.lipsync&&Object.keys(r.current.lipsync).length>0?(console.log("Lip-sync modules loaded:",Object.keys(r.current.lipsync)),w()):(console.log("Waiting for lip-sync modules to load..."),setTimeout(O,100))};O()}),r.current&&r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(!0),console.log("Avatar initialized in full body mode")}catch(w){console.warn("Error setting full body mode on initialization:",w)}c(!1),x(!0),n(r.current);const A=()=>{document.visibilityState==="visible"?r.current?.start():r.current?.stop()};return document.addEventListener("visibilitychange",A),()=>{document.removeEventListener("visibilitychange",A)}}catch(S){console.error("Error initializing TalkingHead:",S),d(S.message||"Failed to initialize avatar"),c(!1),t(S)}},[]);E.useEffect(()=>(C(),()=>{r.current&&(r.current.stop(),r.current.dispose(),r.current=null)}),[C]);const L=E.useCallback(S=>{if(r.current&&f)try{console.log("Speaking text:",S),console.log("Avatar config:",g),console.log("TalkingHead instance:",r.current),r.current.lipsync&&Object.keys(r.current.lipsync).length>0?(console.log("Lip-sync modules loaded:",Object.keys(r.current.lipsync)),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1.05),console.log("Applied timing adjustment for better lip-sync")),r.current.speakText(S)):(console.warn("Lip-sync modules not ready, waiting..."),setTimeout(()=>{r.current&&r.current.lipsync?(console.log("Lip-sync now ready, speaking..."),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1.05),console.log("Applied timing adjustment for better lip-sync")),r.current.speakText(S)):console.error("Lip-sync still not ready after waiting")},500))}catch(A){console.error("Error speaking text:",A),d(A.message||"Failed to speak text")}else console.warn("Avatar not ready for speaking. isReady:",f,"talkingHeadRef:",!!r.current)},[f,g]),P=E.useCallback(()=>{r.current&&(r.current.stopSpeaking(),r.current.setSlowdownRate&&(r.current.setSlowdownRate(1),console.log("Reset timing to normal")))},[]),z=E.useCallback(S=>{r.current&&r.current.setMood(S)},[]),_=E.useCallback(S=>{r.current&&r.current.setSlowdownRate&&(r.current.setSlowdownRate(S),console.log("Timing adjustment set to:",S))},[]),U=E.useCallback((S,A=!1)=>{if(r.current&&r.current.playAnimation){if(r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(!0)}catch(O){console.warn("Error setting full body mode:",O)}if(S.includes("."))try{r.current.playAnimation(S,null,10,0,.01,A),console.log("Playing animation:",S)}catch(O){console.log(`Failed to play ${S}:`,O);try{r.current.setBodyMovement("idle"),console.log("Fallback to idle animation")}catch(Q){console.warn("Fallback animation also failed:",Q)}}else{const O=[".fbx",".glb",".gltf"];let Q=!1;for(const Y of O)try{r.current.playAnimation(S+Y,null,10,0,.01,A),console.log("Playing animation:",S+Y),Q=!0;break}catch{console.log(`Failed to play ${S}${Y}, trying next format...`)}if(!Q){console.warn("Animation system not available or animation not found:",S);try{r.current.setBodyMovement("idle"),console.log("Fallback to idle animation")}catch(Y){console.warn("Fallback animation also failed:",Y)}}}}else console.warn("Animation system not available or animation not found:",S)},[]);return E.useImperativeHandle(a,()=>({speakText:L,stopSpeaking:P,setMood:z,setTimingAdjustment:_,playAnimation:U,isReady:f,talkingHead:r.current,setBodyMovement:S=>{if(r.current&&r.current.setShowFullAvatar&&r.current.setBodyMovement)try{r.current.setShowFullAvatar(!0),r.current.setBodyMovement(S),console.log("Body movement set with full body mode:",S)}catch(A){console.warn("Error setting body movement:",A)}},setMovementIntensity:S=>r.current?.setMovementIntensity(S),playRandomDance:()=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playRandomDance)try{r.current.setShowFullAvatar(!0),r.current.playRandomDance(),console.log("Random dance played with full body mode")}catch(S){console.warn("Error playing random dance:",S)}},playReaction:S=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playReaction)try{r.current.setShowFullAvatar(!0),r.current.playReaction(S),console.log("Reaction played with full body mode:",S)}catch(A){console.warn("Error playing reaction:",A)}},playCelebration:()=>{if(r.current&&r.current.setShowFullAvatar&&r.current.playCelebration)try{r.current.setShowFullAvatar(!0),r.current.playCelebration(),console.log("Celebration played with full body mode")}catch(S){console.warn("Error playing celebration:",S)}},setShowFullAvatar:S=>{if(r.current&&r.current.setShowFullAvatar)try{r.current.setShowFullAvatar(S),console.log("Show full avatar set to:",S)}catch(A){console.warn("Error setting showFullAvatar:",A)}},lockAvatarPosition:()=>{if(r.current&&r.current.lockAvatarPosition)try{r.current.lockAvatarPosition()}catch(S){console.warn("Error locking avatar position:",S)}},unlockAvatarPosition:()=>{if(r.current&&r.current.unlockAvatarPosition)try{r.current.unlockAvatarPosition()}catch(S){console.warn("Error unlocking avatar position:",S)}}})),de.jsxs("div",{className:`talking-head-container ${i}`,style:s,children:[de.jsx("div",{ref:l,className:"talking-head-viewer",style:{width:"100%",height:"100%",minHeight:"400px"}}),h&&de.jsx("div",{className:"loading-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"white",fontSize:"18px",zIndex:10},children:"Loading avatar..."}),u&&de.jsx("div",{className:"error-overlay",style:{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",color:"#ff6b6b",fontSize:"16px",textAlign:"center",zIndex:10,padding:"20px",borderRadius:"8px"},children:u})]})});Pt.displayName="TalkingHeadComponent";const Ft=E.forwardRef(({curriculumData:m=null,avatarConfig:e={},animations:t={},onLessonStart:n=()=>{},onLessonComplete:i=()=>{},onQuestionAnswer:s=()=>{},onCurriculumComplete:o=()=>{},onCustomAction:a=()=>{},autoStart:l=!1},r)=>{const h=E.useRef(null),c=E.useRef({currentModuleIndex:0,currentLessonIndex:0,currentQuestionIndex:0,isTeaching:!1,isQuestionMode:!1,lessonCompleted:!1,curriculumCompleted:!1,score:0,totalQuestions:0}),u=E.useRef({onLessonStart:n,onLessonComplete:i,onQuestionAnswer:s,onCurriculumComplete:o,onCustomAction:a});E.useEffect(()=>{u.current={onLessonStart:n,onLessonComplete:i,onQuestionAnswer:s,onCurriculumComplete:o,onCustomAction:a}},[n,i,s,o,a]);const d=m?.curriculum||{title:"Default Curriculum",description:"No curriculum data provided",language:"en",modules:[]},f={avatarUrl:e.avatarUrl||"/avatars/brunette.glb",avatarBody:e.avatarBody||"F",mood:e.mood||"happy",ttsLang:e.ttsLang||"en",ttsService:e.ttsService||null,ttsVoice:e.ttsVoice||null,ttsApiKey:e.ttsApiKey||null,bodyMovement:e.bodyMovement||"gesturing",movementIntensity:e.movementIntensity||.7,showFullAvatar:e.showFullAvatar!==void 0?e.showFullAvatar:!0,animations:t,lipsyncLang:"en"},x=E.useCallback(()=>d.modules[c.current.currentModuleIndex]?.lessons[c.current.currentLessonIndex],[d]),y=E.useCallback(()=>x()?.questions[c.current.currentQuestionIndex],[x]),R=E.useCallback((A,w)=>w.type==="multiple_choice"||w.type==="true_false"?A===w.answer:w.type==="code_test"&&typeof A=="object"&&A!==null?A.passed===!0:!1,[]),I=E.useCallback(()=>{c.current.lessonCompleted=!0,c.current.isQuestionMode=!1;const A=Math.round(c.current.score/c.current.totalQuestions*100);let w=`Congratulations! You've completed this lesson with a score of ${c.current.score} out of ${c.current.totalQuestions} (${A}%). `;if(A>=80?w+="Excellent work! You have a great understanding of this topic.":A>=60?w+="Good job! You understand most of the concepts.":w+="Keep practicing! You're making progress.",u.current.onLessonComplete({moduleIndex:c.current.currentModuleIndex,lessonIndex:c.current.currentLessonIndex,score:c.current.score,totalQuestions:c.current.totalQuestions,percentage:A}),h.current){if(h.current.setMood("happy"),t.lessonComplete)try{h.current.playAnimation(t.lessonComplete,!0)}catch{h.current.playCelebration()}h.current.speakText(w,{lipsyncLang:f.lipsyncLang})}},[t.lessonComplete,f]),g=E.useCallback(()=>{if(c.current.curriculumCompleted=!0,u.current.onCurriculumComplete({modules:d.modules.length,totalLessons:d.modules.reduce((A,w)=>A+w.lessons.length,0)}),h.current){if(h.current.setMood("celebrating"),t.curriculumComplete)try{h.current.playAnimation(t.curriculumComplete,!0)}catch{h.current.playCelebration()}h.current.speakText("Amazing! You've completed the entire curriculum! You're now ready to move on to more advanced topics. Well done!",{lipsyncLang:f.lipsyncLang})}},[t.curriculumComplete,d,f]),T=E.useCallback(()=>{const A=x();c.current.isQuestionMode=!0,c.current.currentQuestionIndex=0,c.current.totalQuestions=A?.questions?.length||0;const w=y();if(w&&u.current.onCustomAction({type:"questionStart",moduleIndex:c.current.currentModuleIndex,lessonIndex:c.current.currentLessonIndex,questionIndex:c.current.currentQuestionIndex,totalQuestions:c.current.totalQuestions,question:w}),h.current&&w){if(h.current.setMood("curious"),t.questionStart)try{h.current.playAnimation(t.questionStart,!0)}catch(O){console.warn("Failed to play questionStart animation:",O)}w.type==="code_test"?h.current.speakText(`Let's test your coding skills! Here's your first challenge: ${w.question}`,{lipsyncLang:f.lipsyncLang}):w.type==="multiple_choice"?h.current.speakText(`Now let me ask you some questions. Here's the first one: ${w.question}`,{lipsyncLang:f.lipsyncLang}):w.type==="true_false"?h.current.speakText(`Let's start with some true or false questions. First question: ${w.question}`,{lipsyncLang:f.lipsyncLang}):h.current.speakText(`Now let me ask you some questions. Here's the first one: ${w.question}`,{lipsyncLang:f.lipsyncLang})}else h.current&&h.current.speakText("Now let me ask you some questions to test your understanding.",{lipsyncLang:f.lipsyncLang})},[t.questionStart,x,y,f]),C=E.useCallback(()=>{const A=x();if(c.current.currentQuestionIndex<(A?.questions?.length||0)-1){c.current.currentQuestionIndex+=1;const w=y();if(w&&u.current.onCustomAction({type:"nextQuestion",moduleIndex:c.current.currentModuleIndex,lessonIndex:c.current.currentLessonIndex,questionIndex:c.current.currentQuestionIndex,totalQuestions:c.current.totalQuestions,question:w}),h.current&&w){if(h.current.setMood("happy"),h.current.setBodyMovement("idle"),t.nextQuestion)try{h.current.playAnimation(t.nextQuestion,!0)}catch(O){console.warn("Failed to play nextQuestion animation:",O)}w.type==="code_test"?h.current.speakText(`Great! Now let's move on to your next coding challenge: ${w.question}`,{lipsyncLang:f.lipsyncLang}):w.type==="multiple_choice"?h.current.speakText(`Alright! Here's your next question: ${w.question}`,{lipsyncLang:f.lipsyncLang}):w.type==="true_false"?h.current.speakText(`Now let's try this one: ${w.question}`,{lipsyncLang:f.lipsyncLang}):h.current.speakText(`Here's the next question: ${w.question}`,{lipsyncLang:f.lipsyncLang})}}else I()},[t.nextQuestion,x,I,y,f]),L=E.useCallback(()=>{const A=d.modules[c.current.currentModuleIndex];c.current.currentLessonIndex<(A?.lessons?.length||0)-1?(c.current.currentLessonIndex+=1,c.current.currentQuestionIndex=0,c.current.lessonCompleted=!1,c.current.score=0,c.current.totalQuestions=0,h.current&&h.current.speakText("Let's move on to the next lesson!",{lipsyncLang:f.lipsyncLang})):g()},[d,g,f]),P=E.useCallback(()=>{const A=x();if(h.current&&h.current.isReady&&A?.avatar_script){c.current.isTeaching=!0,c.current.isQuestionMode=!1,h.current.setMood("happy");let w=!1;if(t.teaching)try{h.current.playAnimation(t.teaching,!0),w=!0}catch(O){console.warn("Failed to play teaching animation:",O)}w||h.current.setBodyMovement("gesturing"),h.current.speakText(A.avatar_script,{lipsyncLang:f.lipsyncLang}),u.current.onLessonStart({moduleIndex:c.current.currentModuleIndex,lessonIndex:c.current.currentLessonIndex,lesson:A}),u.current.onCustomAction({type:"teachingStart",moduleIndex:c.current.currentModuleIndex,lessonIndex:c.current.currentLessonIndex,lesson:A}),setTimeout(()=>{c.current.isTeaching=!1,A.questions&&A.questions.length>0?T():I()},8e3)}},[t.teaching,x,T,I,f]),z=E.useCallback(A=>{const w=y(),O=R(A,w);if(O&&(c.current.score+=1),u.current.onQuestionAnswer({moduleIndex:c.current.currentModuleIndex,lessonIndex:c.current.currentLessonIndex,questionIndex:c.current.currentQuestionIndex,answer:A,isCorrect:O,question:w}),h.current)if(O){if(h.current.setMood("happy"),t.correct)try{h.current.playReaction("happy")}catch{h.current.setBodyMovement("happy")}h.current.setBodyMovement("gesturing");const Q=w.type==="code_test"?`Great job! Your code passed all the tests! ${w.explanation||""}`:`Excellent! That's correct! ${w.explanation||""}`;h.current.speakText(Q,{lipsyncLang:f.lipsyncLang,onSpeechEnd:()=>{setTimeout(()=>{C()},500)}})}else{if(h.current.setMood("sad"),t.incorrect)try{h.current.playAnimation(t.incorrect,!0)}catch{h.current.setBodyMovement("idle")}h.current.setBodyMovement("gesturing");const Q=w.type==="code_test"?`Your code didn't pass all the tests. ${w.explanation||"Try again!"}`:`Not quite right, but don't worry! ${w.explanation||""} Let's move on to the next question.`;h.current.speakText(Q,{lipsyncLang:f.lipsyncLang,onSpeechEnd:()=>{setTimeout(()=>{C()},500)}})}else C()},[t.correct,t.incorrect,y,R,C,f]),_=E.useCallback(A=>{const w=y();if(!A||typeof A!="object"){console.error("Invalid code test result format. Expected object with {passed: boolean, ...}");return}if(w?.type!=="code_test"){console.warn("Current question is not a code test. Use handleAnswerSelect for other question types.");return}const O={passed:A.passed===!0,results:A.results||[],output:A.output||"",error:A.error||null,executionTime:A.executionTime||null,testCount:A.testCount||0,passedCount:A.passedCount||0,failedCount:A.failedCount||0};u.current.onCustomAction({type:"codeTestSubmitted",moduleIndex:c.current.currentModuleIndex,lessonIndex:c.current.currentLessonIndex,questionIndex:c.current.currentQuestionIndex,testResult:O,question:w}),z(O)},[y,z]),U=E.useCallback(()=>{c.current.currentModuleIndex=0,c.current.currentLessonIndex=0,c.current.currentQuestionIndex=0,c.current.isTeaching=!1,c.current.isQuestionMode=!1,c.current.lessonCompleted=!1,c.current.curriculumCompleted=!1,c.current.score=0,c.current.totalQuestions=0},[]),S=E.useCallback(A=>{console.log("Avatar is ready!",A);const w=x();l&&w?.avatar_script&&setTimeout(()=>{P()},1e3)},[l,x,P]);return E.useImperativeHandle(r,()=>({startTeaching:P,startQuestions:T,handleAnswerSelect:z,handleCodeTestResult:_,nextQuestion:C,nextLesson:L,completeLesson:I,completeCurriculum:g,resetCurriculum:U,getState:()=>({...c.current}),getCurrentQuestion:()=>y(),getCurrentLesson:()=>x(),getAvatarRef:()=>h.current,speakText:async(A,w={})=>{await h.current?.resumeAudioContext?.(),h.current?.speakText(A,{...w,lipsyncLang:w.lipsyncLang||f.lipsyncLang})},resumeAudioContext:async()=>{if(h.current?.resumeAudioContext)return await h.current.resumeAudioContext();const A=h.current?.talkingHead;if(A?.audioCtx){const w=A.audioCtx;if(w.state==="suspended"||w.state==="interrupted")try{await w.resume(),console.log("Audio context resumed via talkingHead")}catch(O){console.warn("Failed to resume audio context:",O)}}else console.warn("Audio context not available yet")},stopSpeaking:()=>h.current?.stopSpeaking(),setMood:A=>h.current?.setMood(A),playAnimation:(A,w)=>h.current?.playAnimation(A,w),setBodyMovement:A=>h.current?.setBodyMovement(A),setMovementIntensity:A=>h.current?.setMovementIntensity(A),playRandomDance:()=>h.current?.playRandomDance(),playReaction:A=>h.current?.playReaction(A),playCelebration:()=>h.current?.playCelebration(),setShowFullAvatar:A=>h.current?.setShowFullAvatar(A),setTimingAdjustment:A=>h.current?.setTimingAdjustment(A),lockAvatarPosition:()=>h.current?.lockAvatarPosition(),unlockAvatarPosition:()=>h.current?.unlockAvatarPosition(),triggerCustomAction:(A,w)=>{u.current.onCustomAction({type:A,...w,state:{...c.current}})},handleResize:()=>h.current?.handleResize(),isAvatarReady:()=>h.current?.isReady||!1}),[P,T,z,_,C,L,I,g,U,y,x]),de.jsx("div",{style:{width:"100%",height:"100%"},children:de.jsx(ot,{ref:h,avatarUrl:f.avatarUrl,avatarBody:f.avatarBody,mood:f.mood,ttsLang:f.ttsLang,ttsService:f.ttsService,ttsVoice:f.ttsVoice,ttsApiKey:f.ttsApiKey,bodyMovement:f.bodyMovement,movementIntensity:f.movementIntensity,showFullAvatar:f.showFullAvatar,cameraView:"upper",animations:f.animations,onReady:S,onLoading:()=>{},onError:A=>{console.error("Avatar error:",A)}})})});Ft.displayName="CurriculumLearning";const at={dance:{name:"dance",type:"code-based",variations:["dancing","dancing2","dancing3"],loop:!0,duration:1e4,description:"Celebration dance animation with multiple variations"},happy:{name:"happy",type:"code-based",loop:!0,duration:5e3,description:"Happy, upbeat body movement"},surprised:{name:"surprised",type:"code-based",loop:!1,duration:3e3,description:"Surprised reaction with quick movements"},thinking:{name:"thinking",type:"code-based",loop:!0,duration:8e3,description:"Thoughtful, contemplative movement"},nodding:{name:"nodding",type:"code-based",loop:!1,duration:2e3,description:"Nodding agreement gesture"},shaking:{name:"shaking",type:"code-based",loop:!1,duration:2e3,description:"Shaking head disagreement gesture"},celebration:{name:"celebration",type:"code-based",loop:!1,duration:3e3,description:"Celebration animation for achievements"},energetic:{name:"energetic",type:"code-based",loop:!0,duration:6e3,description:"High-energy, enthusiastic movement"},swaying:{name:"swaying",type:"code-based",loop:!0,duration:8e3,description:"Gentle swaying motion"},bouncing:{name:"bouncing",type:"code-based",loop:!0,duration:4e3,description:"Bouncy, playful movement"},gesturing:{name:"gesturing",type:"code-based",loop:!0,duration:5e3,description:"Teaching gesture animation"},walking:{name:"walking",type:"code-based",loop:!0,duration:6e3,description:"Walking motion"},prancing:{name:"prancing",type:"code-based",loop:!0,duration:4e3,description:"Playful prancing movement"},excited:{name:"excited",type:"code-based",loop:!0,duration:5e3,description:"Excited, energetic movement"}},Fi=m=>at[m]||null,Di=m=>at.hasOwnProperty(m);exports.CurriculumLearning=Ft;exports.FBXLoader=it;exports.TalkingHeadAvatar=ot;exports.TalkingHeadComponent=Pt;exports.animations=at;exports.getActiveTTSConfig=Be;exports.getAnimation=Fi;exports.getVoiceOptions=Pi;exports.hasAnimation=Di;
|