@pixiv/three-vrm-core 3.4.3-alpha.0 → 3.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pixiv/three-vrm-core v3.4.3-alpha.0
2
+ * @pixiv/three-vrm-core v3.4.3
3
3
  * The implementation of core features of VRM, for @pixiv/three-vrm
4
4
  *
5
5
  * Copyright (c) 2019-2025 pixiv Inc.
@@ -1,2 +1,2 @@
1
1
  /*! (c) 2019-2025 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
2
- "use strict";var ut=Object.create;var Ve=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var dt=Object.getPrototypeOf,ht=Object.prototype.hasOwnProperty;var ct=(a,e)=>{for(var t in e)Ve(a,t,{get:e[t],enumerable:!0})},We=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of mt(e))!ht.call(a,o)&&o!==t&&Ve(a,o,{get:()=>e[o],enumerable:!(r=pt(e,o))||r.enumerable});return a};var T=(a,e,t)=>(t=a!=null?ut(dt(a)):{},We(e||!a||!a.__esModule?Ve(t,"default",{value:a,enumerable:!0}):t,a)),Rt=a=>We(Ve({},"__esModule",{value:!0}),a);var R=(a,e,t)=>new Promise((r,o)=>{var i=s=>{try{u(t.next(s))}catch(l){o(l)}},n=s=>{try{u(t.throw(s))}catch(l){o(l)}},u=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,n);u((t=t.apply(a,e)).next())});var It={};ct(It,{VRMCore:()=>ce,VRMCoreLoaderPlugin:()=>ke,VRMExpression:()=>j,VRMExpressionLoaderPlugin:()=>ne,VRMExpressionManager:()=>z,VRMExpressionMaterialColorBind:()=>Y,VRMExpressionMaterialColorType:()=>q,VRMExpressionMorphTargetBind:()=>$,VRMExpressionOverrideType:()=>$e,VRMExpressionPresetName:()=>Q,VRMExpressionTextureTransformBind:()=>X,VRMFirstPerson:()=>Z,VRMFirstPersonLoaderPlugin:()=>ie,VRMFirstPersonMeshAnnotationType:()=>Xe,VRMHumanBoneList:()=>se,VRMHumanBoneName:()=>Ke,VRMHumanBoneParentMap:()=>He,VRMHumanoid:()=>re,VRMHumanoidHelper:()=>J,VRMHumanoidLoaderPlugin:()=>ae,VRMLookAt:()=>pe,VRMLookAtBoneApplier:()=>S,VRMLookAtExpressionApplier:()=>W,VRMLookAtHelper:()=>le,VRMLookAtLoaderPlugin:()=>de,VRMLookAtRangeMap:()=>oe,VRMLookAtTypeName:()=>st,VRMMetaLoaderPlugin:()=>he,VRMRequiredHumanBoneName:()=>_e});module.exports=Rt(It);var je=T(require("three"),1),j=class extends je.Object3D{constructor(t){super();this.weight=0;this.isBinary=!1;this.overrideBlink="none";this.overrideLookAt="none";this.overrideMouth="none";this._binds=[];this.name=`VRMExpression_${t}`,this.expressionName=t,this.type="VRMExpression",this.visible=!1}get binds(){return this._binds}get overrideBlinkAmount(){return this.overrideBlink==="block"?0<this.outputWeight?1:0:this.overrideBlink==="blend"?this.outputWeight:0}get overrideLookAtAmount(){return this.overrideLookAt==="block"?0<this.outputWeight?1:0:this.overrideLookAt==="blend"?this.outputWeight:0}get overrideMouthAmount(){return this.overrideMouth==="block"?0<this.outputWeight?1:0:this.overrideMouth==="blend"?this.outputWeight:0}get outputWeight(){return this.isBinary?this.weight>.5?1:0:this.weight}addBind(t){this._binds.push(t)}deleteBind(t){let r=this._binds.indexOf(t);r>=0&&this._binds.splice(r,1)}applyWeight(t){var o;let r=this.outputWeight;r*=(o=t==null?void 0:t.multiplier)!=null?o:1,this.isBinary&&r<1&&(r=0),this._binds.forEach(i=>i.applyWeight(r))}clearAppliedWeight(){this._binds.forEach(t=>t.clearAppliedWeight())}};var G=T(require("three"),1);function Qe(a,e,t){var l,d;let r=a.parser.json,o=(l=r.nodes)==null?void 0:l[e];if(o==null)return console.warn(`extractPrimitivesInternal: Attempt to use nodes[${e}] of glTF but the node doesn't exist`),null;let i=o.mesh;if(i==null)return null;let n=(d=r.meshes)==null?void 0:d[i];if(n==null)return console.warn(`extractPrimitivesInternal: Attempt to use meshes[${i}] of glTF but the mesh doesn't exist`),null;let u=n.primitives.length,s=[];return t.traverse(c=>{s.length<u&&c.isMesh&&s.push(c)}),s}function Fe(a,e){return R(this,null,function*(){let t=yield a.parser.getDependency("node",e);return Qe(a,e,t)})}function Ie(a){return R(this,null,function*(){let e=yield a.parser.getDependencies("node"),t=new Map;return e.forEach((r,o)=>{let i=Qe(a,o,r);i!=null&&t.set(o,i)}),t})}var Q={Aa:"aa",Ih:"ih",Ou:"ou",Ee:"ee",Oh:"oh",Blink:"blink",Happy:"happy",Angry:"angry",Sad:"sad",Relaxed:"relaxed",LookUp:"lookUp",Surprised:"surprised",LookDown:"lookDown",LookLeft:"lookLeft",LookRight:"lookRight",BlinkLeft:"blinkLeft",BlinkRight:"blinkRight",Neutral:"neutral"};function ye(a){return Math.max(Math.min(a,1),0)}var z=class a{constructor(){this.blinkExpressionNames=["blink","blinkLeft","blinkRight"];this.lookAtExpressionNames=["lookLeft","lookRight","lookUp","lookDown"];this.mouthExpressionNames=["aa","ee","ih","oh","ou"];this._expressions=[];this._expressionMap={}}get expressions(){return this._expressions.concat()}get expressionMap(){return Object.assign({},this._expressionMap)}get presetExpressionMap(){let e={},t=new Set(Object.values(Q));return Object.entries(this._expressionMap).forEach(([r,o])=>{t.has(r)&&(e[r]=o)}),e}get customExpressionMap(){let e={},t=new Set(Object.values(Q));return Object.entries(this._expressionMap).forEach(([r,o])=>{t.has(r)||(e[r]=o)}),e}copy(e){return this._expressions.concat().forEach(r=>{this.unregisterExpression(r)}),e._expressions.forEach(r=>{this.registerExpression(r)}),this.blinkExpressionNames=e.blinkExpressionNames.concat(),this.lookAtExpressionNames=e.lookAtExpressionNames.concat(),this.mouthExpressionNames=e.mouthExpressionNames.concat(),this}clone(){return new a().copy(this)}getExpression(e){var t;return(t=this._expressionMap[e])!=null?t:null}registerExpression(e){this._expressions.push(e),this._expressionMap[e.expressionName]=e}unregisterExpression(e){let t=this._expressions.indexOf(e);t===-1&&console.warn("VRMExpressionManager: The specified expressions is not registered"),this._expressions.splice(t,1),delete this._expressionMap[e.expressionName]}getValue(e){var r;let t=this.getExpression(e);return(r=t==null?void 0:t.weight)!=null?r:null}setValue(e,t){let r=this.getExpression(e);r&&(r.weight=ye(t))}resetValues(){this._expressions.forEach(e=>{e.weight=0})}getExpressionTrackName(e){let t=this.getExpression(e);return t?`${t.name}.weight`:null}update(){let e=this._calculateWeightMultipliers();this._expressions.forEach(t=>{t.clearAppliedWeight()}),this._expressions.forEach(t=>{let r=1,o=t.expressionName;this.blinkExpressionNames.indexOf(o)!==-1&&(r*=e.blink),this.lookAtExpressionNames.indexOf(o)!==-1&&(r*=e.lookAt),this.mouthExpressionNames.indexOf(o)!==-1&&(r*=e.mouth),t.applyWeight({multiplier:r})})}_calculateWeightMultipliers(){let e=1,t=1,r=1;return this._expressions.forEach(o=>{e-=o.overrideBlinkAmount,t-=o.overrideLookAtAmount,r-=o.overrideMouthAmount}),e=Math.max(0,e),t=Math.max(0,t),r=Math.max(0,r),{blink:e,lookAt:t,mouth:r}}};var q={Color:"color",EmissionColor:"emissionColor",ShadeColor:"shadeColor",MatcapColor:"matcapColor",RimColor:"rimColor",OutlineColor:"outlineColor"},ze={_Color:q.Color,_EmissionColor:q.EmissionColor,_ShadeColor:q.ShadeColor,_RimColor:q.RimColor,_OutlineColor:q.OutlineColor};var Ne=T(require("three"),1),ft=new Ne.Color,xe=class xe{constructor({material:e,type:t,targetValue:r,targetAlpha:o}){this.material=e,this.type=t,this.targetValue=r,this.targetAlpha=o!=null?o:1;let i=this._initColorBindState(),n=this._initAlphaBindState();this._state={color:i,alpha:n}}applyWeight(e){let{color:t,alpha:r}=this._state;if(t!=null){let{propertyName:o,deltaValue:i}=t,n=this.material[o];n!=null&&n.add(ft.copy(i).multiplyScalar(e))}if(r!=null){let{propertyName:o,deltaValue:i}=r;this.material[o]!=null&&(this.material[o]+=i*e)}}clearAppliedWeight(){let{color:e,alpha:t}=this._state;if(e!=null){let{propertyName:r,initialValue:o}=e,i=this.material[r];i!=null&&i.copy(o)}if(t!=null){let{propertyName:r,initialValue:o}=t;this.material[r]!=null&&(this.material[r]=o)}}_initColorBindState(){var l,d,c;let{material:e,type:t,targetValue:r}=this,o=this._getPropertyNameMap(),i=(d=(l=o==null?void 0:o[t])==null?void 0:l[0])!=null?d:null;if(i==null)return console.warn(`Tried to add a material color bind to the material ${(c=e.name)!=null?c:"(no name)"}, the type ${t} but the material or the type is not supported.`),null;let u=e[i].clone(),s=new Ne.Color(r.r-u.r,r.g-u.g,r.b-u.b);return{propertyName:i,initialValue:u,deltaValue:s}}_initAlphaBindState(){var s,l,d;let{material:e,type:t,targetAlpha:r}=this,o=this._getPropertyNameMap(),i=(l=(s=o==null?void 0:o[t])==null?void 0:s[1])!=null?l:null;if(i==null&&r!==1)return console.warn(`Tried to add a material alpha bind to the material ${(d=e.name)!=null?d:"(no name)"}, the type ${t} but the material or the type does not support alpha.`),null;if(i==null)return null;let n=e[i],u=r-n;return{propertyName:i,initialValue:n,deltaValue:u}}_getPropertyNameMap(){var e,t;return(t=(e=Object.entries(xe._propertyNameMapMap).find(([r])=>this.material[r]===!0))==null?void 0:e[1])!=null?t:null}};xe._propertyNameMapMap={isMeshStandardMaterial:{color:["color","opacity"],emissionColor:["emissive",null]},isMeshBasicMaterial:{color:["color","opacity"]},isMToonMaterial:{color:["color","opacity"],emissionColor:["emissive",null],outlineColor:["outlineColorFactor",null],matcapColor:["matcapFactor",null],rimColor:["parametricRimColorFactor",null],shadeColor:["shadeColorFactor",null]}};var Y=xe;var $=class{constructor({primitives:e,index:t,weight:r}){this.primitives=e,this.index=t,this.weight=r}applyWeight(e){this.primitives.forEach(t=>{var r;((r=t.morphTargetInfluences)==null?void 0:r[this.index])!=null&&(t.morphTargetInfluences[this.index]+=this.weight*e)})}clearAppliedWeight(){this.primitives.forEach(e=>{var t;((t=e.morphTargetInfluences)==null?void 0:t[this.index])!=null&&(e.morphTargetInfluences[this.index]=0)})}};var Ye=T(require("three"),1),qe=new Ye.Vector2,Te=class Te{constructor({material:e,scale:t,offset:r}){var i,n;this.material=e,this.scale=t,this.offset=r;let o=(i=Object.entries(Te._propertyNamesMap).find(([u])=>e[u]===!0))==null?void 0:i[1];o==null?(console.warn(`Tried to add a texture transform bind to the material ${(n=e.name)!=null?n:"(no name)"} but the material is not supported.`),this._properties=[]):(this._properties=[],o.forEach(u=>{var m;let s=(m=e[u])==null?void 0:m.clone();if(!s)return null;e[u]=s;let l=s.offset.clone(),d=s.repeat.clone(),c=r.clone().sub(l),p=t.clone().sub(d);this._properties.push({name:u,initialOffset:l,deltaOffset:c,initialScale:d,deltaScale:p})}))}applyWeight(e){this._properties.forEach(t=>{let r=this.material[t.name];r!==void 0&&(r.offset.add(qe.copy(t.deltaOffset).multiplyScalar(e)),r.repeat.add(qe.copy(t.deltaScale).multiplyScalar(e)))})}clearAppliedWeight(){this._properties.forEach(e=>{let t=this.material[e.name];t!==void 0&&(t.offset.copy(e.initialOffset),t.repeat.copy(e.initialScale))})}};Te._propertyNamesMap={isMeshStandardMaterial:["map","emissiveMap","bumpMap","normalMap","displacementMap","roughnessMap","metalnessMap","alphaMap"],isMeshBasicMaterial:["map","specularMap","alphaMap"],isMToonMaterial:["map","normalMap","emissiveMap","shadeMultiplyTexture","rimMultiplyTexture","outlineWidthMultiplyTexture","uvAnimationMaskTexture"]};var X=Te;var Mt=new Set(["1.0","1.0-beta"]),be=class be{get name(){return"VRMExpressionLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return R(this,null,function*(){e.userData.vrmExpressionManager=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let r=yield this._v0Import(e);return r||null})}_v1Import(e){return R(this,null,function*(){var d,c;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(!o)return null;let i=o.specVersion;if(!Mt.has(i))return console.warn(`VRMExpressionLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.expressions;if(!n)return null;let u=new Set(Object.values(Q)),s=new Map;n.preset!=null&&Object.entries(n.preset).forEach(([p,m])=>{if(m!=null){if(!u.has(p)){console.warn(`VRMExpressionLoaderPlugin: Unknown preset name "${p}" detected. Ignoring the expression`);return}s.set(p,m)}}),n.custom!=null&&Object.entries(n.custom).forEach(([p,m])=>{if(u.has(p)){console.warn(`VRMExpressionLoaderPlugin: Custom expression cannot have preset name "${p}". Ignoring the expression`);return}s.set(p,m)});let l=new z;return yield Promise.all(Array.from(s.entries()).map(M=>R(this,[M],function*([p,m]){var f,V,x,A,b,H,I;let h=new j(p);if(e.scene.add(h),h.isBinary=(f=m.isBinary)!=null?f:!1,h.overrideBlink=(V=m.overrideBlink)!=null?V:"none",h.overrideLookAt=(x=m.overrideLookAt)!=null?x:"none",h.overrideMouth=(A=m.overrideMouth)!=null?A:"none",(b=m.morphTargetBinds)==null||b.forEach(L=>R(this,null,function*(){var k;if(L.node===void 0||L.index===void 0)return;let P=yield Fe(e,L.node),B=L.index;if(!P.every(N=>Array.isArray(N.morphTargetInfluences)&&B<N.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${m.name} attempts to index morph #${B} but not found.`);return}h.addBind(new $({primitives:P,index:B,weight:(k=L.weight)!=null?k:1}))})),m.materialColorBinds||m.textureTransformBinds){let L=[];e.scene.traverse(P=>{let B=P.material;B&&(Array.isArray(B)?L.push(...B):L.push(B))}),(H=m.materialColorBinds)==null||H.forEach(P=>R(this,null,function*(){L.filter(k=>{var D;let N=(D=this.parser.associations.get(k))==null?void 0:D.materials;return P.material===N}).forEach(k=>{h.addBind(new Y({material:k,type:P.type,targetValue:new G.Color().fromArray(P.targetValue),targetAlpha:P.targetValue[3]}))})})),(I=m.textureTransformBinds)==null||I.forEach(P=>R(this,null,function*(){L.filter(k=>{var D;let N=(D=this.parser.associations.get(k))==null?void 0:D.materials;return P.material===N}).forEach(k=>{var N,D;h.addBind(new X({material:k,offset:new G.Vector2().fromArray((N=P.offset)!=null?N:[0,0]),scale:new G.Vector2().fromArray((D=P.scale)!=null?D:[1,1])}))})}))}l.registerExpression(h)}))),l})}_v0Import(e){return R(this,null,function*(){var s;let t=this.parser.json,r=(s=t.extensions)==null?void 0:s.VRM;if(!r)return null;let o=r.blendShapeMaster;if(!o)return null;let i=new z,n=o.blendShapeGroups;if(!n)return i;let u=new Set;return yield Promise.all(n.map(l=>R(this,null,function*(){var h;let d=l.presetName,c=d!=null&&be.v0v1PresetNameMap[d]||null,p=c!=null?c:l.name;if(p==null){console.warn("VRMExpressionLoaderPlugin: One of custom expressions has no name. Ignoring the expression");return}if(u.has(p)){console.warn(`VRMExpressionLoaderPlugin: An expression preset ${d} has duplicated entries. Ignoring the expression`);return}u.add(p);let m=new j(p);e.scene.add(m),m.isBinary=(h=l.isBinary)!=null?h:!1,l.binds&&l.binds.forEach(f=>R(this,null,function*(){var A;if(f.mesh===void 0||f.index===void 0)return;let V=[];(A=t.nodes)==null||A.forEach((b,H)=>{b.mesh===f.mesh&&V.push(H)});let x=f.index;yield Promise.all(V.map(b=>R(this,null,function*(){var I;let H=yield Fe(e,b);if(!H.every(L=>Array.isArray(L.morphTargetInfluences)&&x<L.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${l.name} attempts to index ${x}th morph but not found.`);return}m.addBind(new $({primitives:H,index:x,weight:.01*((I=f.weight)!=null?I:100)}))})))}));let M=l.materialValues;M&&M.length!==0&&M.forEach(f=>{if(f.materialName===void 0||f.propertyName===void 0||f.targetValue===void 0)return;let V=[];e.scene.traverse(A=>{if(A.material){let b=A.material;Array.isArray(b)?V.push(...b.filter(H=>(H.name===f.materialName||H.name===f.materialName+" (Outline)")&&V.indexOf(H)===-1)):b.name===f.materialName&&V.indexOf(b)===-1&&V.push(b)}});let x=f.propertyName;V.forEach(A=>{if(x==="_MainTex_ST"){let H=new G.Vector2(f.targetValue[0],f.targetValue[1]),I=new G.Vector2(f.targetValue[2],f.targetValue[3]);I.y=1-I.y-H.y,m.addBind(new X({material:A,scale:H,offset:I}));return}let b=ze[x];if(b){m.addBind(new Y({material:A,type:b,targetValue:new G.Color().fromArray(f.targetValue),targetAlpha:f.targetValue[3]}));return}console.warn(x+" is not supported")})}),i.registerExpression(m)}))),i})}};be.v0v1PresetNameMap={a:"aa",e:"ee",i:"ih",o:"oh",u:"ou",blink:"blink",joy:"happy",angry:"angry",sorrow:"sad",fun:"relaxed",lookup:"lookUp",lookdown:"lookDown",lookleft:"lookLeft",lookright:"lookRight",blink_l:"blinkLeft",blink_r:"blinkRight",neutral:"neutral"};var ne=be;var $e={None:"none",Block:"block",Blend:"blend"};var w=T(require("three"),1),U=class U{constructor(e,t){this._firstPersonOnlyLayer=U.DEFAULT_FIRSTPERSON_ONLY_LAYER;this._thirdPersonOnlyLayer=U.DEFAULT_THIRDPERSON_ONLY_LAYER;this._initializedLayers=!1;this.humanoid=e,this.meshAnnotations=t}copy(e){if(this.humanoid!==e.humanoid)throw new Error("VRMFirstPerson: humanoid must be same in order to copy");return this.meshAnnotations=e.meshAnnotations.map(t=>({meshes:t.meshes.concat(),type:t.type})),this}clone(){return new U(this.humanoid,this.meshAnnotations).copy(this)}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}setup({firstPersonOnlyLayer:e=U.DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:t=U.DEFAULT_THIRDPERSON_ONLY_LAYER}={}){this._initializedLayers||(this._firstPersonOnlyLayer=e,this._thirdPersonOnlyLayer=t,this.meshAnnotations.forEach(r=>{r.meshes.forEach(o=>{r.type==="firstPersonOnly"?(o.layers.set(this._firstPersonOnlyLayer),o.traverse(i=>i.layers.set(this._firstPersonOnlyLayer))):r.type==="thirdPersonOnly"?(o.layers.set(this._thirdPersonOnlyLayer),o.traverse(i=>i.layers.set(this._thirdPersonOnlyLayer))):r.type==="auto"&&this._createHeadlessModel(o)})}),this._initializedLayers=!0)}_excludeTriangles(e,t,r,o){let i=0;if(t!=null&&t.length>0)for(let n=0;n<e.length;n+=3){let u=e[n],s=e[n+1],l=e[n+2],d=t[u],c=r[u];if(d[0]>0&&o.includes(c[0])||d[1]>0&&o.includes(c[1])||d[2]>0&&o.includes(c[2])||d[3]>0&&o.includes(c[3]))continue;let p=t[s],m=r[s];if(p[0]>0&&o.includes(m[0])||p[1]>0&&o.includes(m[1])||p[2]>0&&o.includes(m[2])||p[3]>0&&o.includes(m[3]))continue;let M=t[l],h=r[l];M[0]>0&&o.includes(h[0])||M[1]>0&&o.includes(h[1])||M[2]>0&&o.includes(h[2])||M[3]>0&&o.includes(h[3])||(e[i++]=u,e[i++]=s,e[i++]=l)}return i}_createErasedMesh(e,t){let r=new w.SkinnedMesh(e.geometry.clone(),e.material);r.name=`${e.name}(erase)`,r.frustumCulled=e.frustumCulled,r.layers.set(this._firstPersonOnlyLayer);let o=r.geometry,i=o.getAttribute("skinIndex"),n=i instanceof w.GLBufferAttribute?[]:i.array,u=[];for(let h=0;h<n.length;h+=4)u.push([n[h],n[h+1],n[h+2],n[h+3]]);let s=o.getAttribute("skinWeight"),l=s instanceof w.GLBufferAttribute?[]:s.array,d=[];for(let h=0;h<l.length;h+=4)d.push([l[h],l[h+1],l[h+2],l[h+3]]);let c=o.getIndex();if(!c)throw new Error("The geometry doesn't have an index buffer");let p=Array.from(c.array),m=this._excludeTriangles(p,d,u,t),M=[];for(let h=0;h<m;h++)M[h]=p[h];return o.setIndex(M),e.onBeforeRender&&(r.onBeforeRender=e.onBeforeRender),r.bind(new w.Skeleton(e.skeleton.bones,e.skeleton.boneInverses),new w.Matrix4),r}_createHeadlessModelForSkinnedMesh(e,t){let r=[];if(t.skeleton.bones.forEach((i,n)=>{this._isEraseTarget(i)&&r.push(n)}),!r.length){t.layers.enable(this._thirdPersonOnlyLayer),t.layers.enable(this._firstPersonOnlyLayer);return}t.layers.set(this._thirdPersonOnlyLayer);let o=this._createErasedMesh(t,r);e.add(o)}_createHeadlessModel(e){if(e.type==="Group")if(e.layers.set(this._thirdPersonOnlyLayer),this._isEraseTarget(e))e.traverse(t=>t.layers.set(this._thirdPersonOnlyLayer));else{let t=new w.Group;t.name=`_headless_${e.name}`,t.layers.set(this._firstPersonOnlyLayer),e.parent.add(t),e.children.filter(r=>r.type==="SkinnedMesh").forEach(r=>{let o=r;this._createHeadlessModelForSkinnedMesh(t,o)})}else if(e.type==="SkinnedMesh"){let t=e;this._createHeadlessModelForSkinnedMesh(e.parent,t)}else this._isEraseTarget(e)&&(e.layers.set(this._thirdPersonOnlyLayer),e.traverse(t=>t.layers.set(this._thirdPersonOnlyLayer)))}_isEraseTarget(e){return e===this.humanoid.getRawBoneNode("head")?!0:e.parent?this._isEraseTarget(e.parent):!1}};U.DEFAULT_FIRSTPERSON_ONLY_LAYER=9,U.DEFAULT_THIRDPERSON_ONLY_LAYER=10;var Z=U;var Et=new Set(["1.0","1.0-beta"]),ie=class{get name(){return"VRMFirstPersonLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return R(this,null,function*(){let t=e.userData.vrmHumanoid;if(t!==null){if(t===void 0)throw new Error("VRMFirstPersonLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");e.userData.vrmFirstPerson=yield this._import(e,t)}})}_import(e,t){return R(this,null,function*(){if(t==null)return null;let r=yield this._v1Import(e,t);if(r)return r;let o=yield this._v0Import(e,t);return o||null})}_v1Import(e,t){return R(this,null,function*(){var d,c;let r=this.parser.json;if(!(((d=r.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let i=(c=r.extensions)==null?void 0:c.VRMC_vrm;if(!i)return null;let n=i.specVersion;if(!Et.has(n))return console.warn(`VRMFirstPersonLoaderPlugin: Unknown VRMC_vrm specVersion "${n}"`),null;let u=i.firstPerson,s=[],l=yield Ie(e);return Array.from(l.entries()).forEach(([p,m])=>{var h,f;let M=(h=u==null?void 0:u.meshAnnotations)==null?void 0:h.find(V=>V.node===p);s.push({meshes:m,type:(f=M==null?void 0:M.type)!=null?f:"auto"})}),new Z(t,s)})}_v0Import(e,t){return R(this,null,function*(){var s;let r=this.parser.json,o=(s=r.extensions)==null?void 0:s.VRM;if(!o)return null;let i=o.firstPerson;if(!i)return null;let n=[],u=yield Ie(e);return Array.from(u.entries()).forEach(([l,d])=>{let c=r.nodes[l],p=i.meshAnnotations?i.meshAnnotations.find(m=>m.mesh===c.mesh):void 0;n.push({meshes:d,type:this._convertV0FlagToV1Type(p==null?void 0:p.firstPersonFlag)})}),new Z(t,n)})}_convertV0FlagToV1Type(e){return e==="FirstPersonOnly"?"firstPersonOnly":e==="ThirdPersonOnly"?"thirdPersonOnly":e==="Both"?"both":"auto"}};var Xe={Auto:"auto",Both:"both",ThirdPersonOnly:"thirdPersonOnly",FirstPersonOnly:"firstPersonOnly"};var O=T(require("three"),1),Ze=new O.Vector3,Je=new O.Vector3,gt=new O.Quaternion,J=class extends O.Group{constructor(e){super(),this.vrmHumanoid=e,this._boneAxesMap=new Map,Object.values(e.humanBones).forEach(t=>{let r=new O.AxesHelper(1);r.matrixAutoUpdate=!1,r.material.depthTest=!1,r.material.depthWrite=!1,this.add(r),this._boneAxesMap.set(t,r)})}dispose(){Array.from(this._boneAxesMap.values()).forEach(e=>{e.geometry.dispose(),e.material.dispose()})}updateMatrixWorld(e){Array.from(this._boneAxesMap.entries()).forEach(([t,r])=>{t.node.updateWorldMatrix(!0,!1),t.node.matrixWorld.decompose(Ze,gt,Je);let o=Ze.set(.1,.1,.1).divide(Je);r.matrix.copy(t.node.matrixWorld).scale(o)}),super.updateMatrixWorld(e)}};var se=["hips","spine","chest","upperChest","neck","head","leftEye","rightEye","jaw","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftThumbMetacarpal","leftThumbProximal","leftThumbDistal","leftIndexProximal","leftIndexIntermediate","leftIndexDistal","leftMiddleProximal","leftMiddleIntermediate","leftMiddleDistal","leftRingProximal","leftRingIntermediate","leftRingDistal","leftLittleProximal","leftLittleIntermediate","leftLittleDistal","rightThumbMetacarpal","rightThumbProximal","rightThumbDistal","rightIndexProximal","rightIndexIntermediate","rightIndexDistal","rightMiddleProximal","rightMiddleIntermediate","rightMiddleDistal","rightRingProximal","rightRingIntermediate","rightRingDistal","rightLittleProximal","rightLittleIntermediate","rightLittleDistal"];var Ke={Hips:"hips",Spine:"spine",Chest:"chest",UpperChest:"upperChest",Neck:"neck",Head:"head",LeftEye:"leftEye",RightEye:"rightEye",Jaw:"jaw",LeftUpperLeg:"leftUpperLeg",LeftLowerLeg:"leftLowerLeg",LeftFoot:"leftFoot",LeftToes:"leftToes",RightUpperLeg:"rightUpperLeg",RightLowerLeg:"rightLowerLeg",RightFoot:"rightFoot",RightToes:"rightToes",LeftShoulder:"leftShoulder",LeftUpperArm:"leftUpperArm",LeftLowerArm:"leftLowerArm",LeftHand:"leftHand",RightShoulder:"rightShoulder",RightUpperArm:"rightUpperArm",RightLowerArm:"rightLowerArm",RightHand:"rightHand",LeftThumbMetacarpal:"leftThumbMetacarpal",LeftThumbProximal:"leftThumbProximal",LeftThumbDistal:"leftThumbDistal",LeftIndexProximal:"leftIndexProximal",LeftIndexIntermediate:"leftIndexIntermediate",LeftIndexDistal:"leftIndexDistal",LeftMiddleProximal:"leftMiddleProximal",LeftMiddleIntermediate:"leftMiddleIntermediate",LeftMiddleDistal:"leftMiddleDistal",LeftRingProximal:"leftRingProximal",LeftRingIntermediate:"leftRingIntermediate",LeftRingDistal:"leftRingDistal",LeftLittleProximal:"leftLittleProximal",LeftLittleIntermediate:"leftLittleIntermediate",LeftLittleDistal:"leftLittleDistal",RightThumbMetacarpal:"rightThumbMetacarpal",RightThumbProximal:"rightThumbProximal",RightThumbDistal:"rightThumbDistal",RightIndexProximal:"rightIndexProximal",RightIndexIntermediate:"rightIndexIntermediate",RightIndexDistal:"rightIndexDistal",RightMiddleProximal:"rightMiddleProximal",RightMiddleIntermediate:"rightMiddleIntermediate",RightMiddleDistal:"rightMiddleDistal",RightRingProximal:"rightRingProximal",RightRingIntermediate:"rightRingIntermediate",RightRingDistal:"rightRingDistal",RightLittleProximal:"rightLittleProximal",RightLittleIntermediate:"rightLittleIntermediate",RightLittleDistal:"rightLittleDistal"};var He={hips:null,spine:"hips",chest:"spine",upperChest:"chest",neck:"upperChest",head:"neck",leftEye:"head",rightEye:"head",jaw:"head",leftUpperLeg:"hips",leftLowerLeg:"leftUpperLeg",leftFoot:"leftLowerLeg",leftToes:"leftFoot",rightUpperLeg:"hips",rightLowerLeg:"rightUpperLeg",rightFoot:"rightLowerLeg",rightToes:"rightFoot",leftShoulder:"upperChest",leftUpperArm:"leftShoulder",leftLowerArm:"leftUpperArm",leftHand:"leftLowerArm",rightShoulder:"upperChest",rightUpperArm:"rightShoulder",rightLowerArm:"rightUpperArm",rightHand:"rightLowerArm",leftThumbMetacarpal:"leftHand",leftThumbProximal:"leftThumbMetacarpal",leftThumbDistal:"leftThumbProximal",leftIndexProximal:"leftHand",leftIndexIntermediate:"leftIndexProximal",leftIndexDistal:"leftIndexIntermediate",leftMiddleProximal:"leftHand",leftMiddleIntermediate:"leftMiddleProximal",leftMiddleDistal:"leftMiddleIntermediate",leftRingProximal:"leftHand",leftRingIntermediate:"leftRingProximal",leftRingDistal:"leftRingIntermediate",leftLittleProximal:"leftHand",leftLittleIntermediate:"leftLittleProximal",leftLittleDistal:"leftLittleIntermediate",rightThumbMetacarpal:"rightHand",rightThumbProximal:"rightThumbMetacarpal",rightThumbDistal:"rightThumbProximal",rightIndexProximal:"rightHand",rightIndexIntermediate:"rightIndexProximal",rightIndexDistal:"rightIndexIntermediate",rightMiddleProximal:"rightHand",rightMiddleIntermediate:"rightMiddleProximal",rightMiddleDistal:"rightMiddleIntermediate",rightRingProximal:"rightHand",rightRingIntermediate:"rightRingProximal",rightRingDistal:"rightRingIntermediate",rightLittleProximal:"rightHand",rightLittleIntermediate:"rightLittleProximal",rightLittleDistal:"rightLittleIntermediate"};var Pe=T(require("three"),1);function Le(a){return a.invert?a.invert():a.inverse(),a}var K=new Pe.Vector3,ee=new Pe.Quaternion,te=class{constructor(e){this.humanBones=e,this.restPose=this.getAbsolutePose()}getAbsolutePose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let r=t,o=this.getBoneNode(r);o&&(K.copy(o.position),ee.copy(o.quaternion),e[r]={position:K.toArray(),rotation:ee.toArray()})}),e}getPose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let r=t,o=this.getBoneNode(r);if(!o)return;K.set(0,0,0),ee.identity();let i=this.restPose[r];i!=null&&i.position&&K.fromArray(i.position).negate(),i!=null&&i.rotation&&Le(ee.fromArray(i.rotation)),K.add(o.position),ee.premultiply(o.quaternion),e[r]={position:K.toArray(),rotation:ee.toArray()}}),e}setPose(e){Object.entries(e).forEach(([t,r])=>{let o=t,i=this.getBoneNode(o);if(!i)return;let n=this.restPose[o];n&&(r!=null&&r.position&&(i.position.fromArray(r.position),n.position&&i.position.add(K.fromArray(n.position))),r!=null&&r.rotation&&(i.quaternion.fromArray(r.rotation),n.rotation&&i.quaternion.multiply(ee.fromArray(n.rotation))))})}resetPose(){Object.entries(this.restPose).forEach(([e,t])=>{let r=this.getBoneNode(e);r&&(t!=null&&t.position&&r.position.fromArray(t.position),t!=null&&t.rotation&&r.quaternion.fromArray(t.rotation))})}getBone(e){var t;return(t=this.humanBones[e])!=null?t:void 0}getBoneNode(e){var t,r;return(r=(t=this.humanBones[e])==null?void 0:t.node)!=null?r:null}};var v=T(require("three"),1);var Ue=new v.Vector3,Vt=new v.Quaternion,yt=new v.Vector3,Re=class a extends te{static _setupTransforms(e){let t=new v.Object3D;t.name="VRMHumanoidRig";let r={},o={},i={},n={};se.forEach(s=>{var d;let l=e.getBoneNode(s);if(l){let c=new v.Vector3,p=new v.Quaternion;l.updateWorldMatrix(!0,!1),l.matrixWorld.decompose(c,p,Ue),r[s]=c,o[s]=p,i[s]=l.quaternion.clone();let m=new v.Quaternion;(d=l.parent)==null||d.matrixWorld.decompose(Ue,m,Ue),n[s]=m}});let u={};return se.forEach(s=>{var d;let l=e.getBoneNode(s);if(l){let c=r[s],p=s,m;for(;m==null&&(p=He[p],p!=null);)m=r[p];let M=new v.Object3D;M.name="Normalized_"+l.name,(p?(d=u[p])==null?void 0:d.node:t).add(M),M.position.copy(c),m&&M.position.sub(m),u[s]={node:M}}}),{rigBones:u,root:t,parentWorldRotations:n,boneRotations:i}}constructor(e){let{rigBones:t,root:r,parentWorldRotations:o,boneRotations:i}=a._setupTransforms(e);super(t),this.original=e,this.root=r,this._parentWorldRotations=o,this._boneRotations=i}update(){se.forEach(e=>{let t=this.original.getBoneNode(e);if(t!=null){let r=this.getBoneNode(e),o=this._parentWorldRotations[e],i=Vt.copy(o).invert(),n=this._boneRotations[e];if(t.quaternion.copy(r.quaternion).multiply(o).premultiply(i).multiply(n),e==="hips"){let u=r.getWorldPosition(yt);t.parent.updateWorldMatrix(!0,!1);let s=t.parent.matrixWorld,l=u.applyMatrix4(s.invert());t.position.copy(l)}}})}};var re=class a{get restPose(){return console.warn("VRMHumanoid: restPose is deprecated. Use either rawRestPose or normalizedRestPose instead."),this.rawRestPose}get rawRestPose(){return this._rawHumanBones.restPose}get normalizedRestPose(){return this._normalizedHumanBones.restPose}get humanBones(){return this._rawHumanBones.humanBones}get rawHumanBones(){return this._rawHumanBones.humanBones}get normalizedHumanBones(){return this._normalizedHumanBones.humanBones}get normalizedHumanBonesRoot(){return this._normalizedHumanBones.root}constructor(e,t){var r;this.autoUpdateHumanBones=(r=t==null?void 0:t.autoUpdateHumanBones)!=null?r:!0,this._rawHumanBones=new te(e),this._normalizedHumanBones=new Re(this._rawHumanBones)}copy(e){return this.autoUpdateHumanBones=e.autoUpdateHumanBones,this._rawHumanBones=new te(e.humanBones),this._normalizedHumanBones=new Re(this._rawHumanBones),this}clone(){return new a(this.humanBones,{autoUpdateHumanBones:this.autoUpdateHumanBones}).copy(this)}getAbsolutePose(){return console.warn("VRMHumanoid: getAbsolutePose() is deprecated. Use either getRawAbsolutePose() or getNormalizedAbsolutePose() instead."),this.getRawAbsolutePose()}getRawAbsolutePose(){return this._rawHumanBones.getAbsolutePose()}getNormalizedAbsolutePose(){return this._normalizedHumanBones.getAbsolutePose()}getPose(){return console.warn("VRMHumanoid: getPose() is deprecated. Use either getRawPose() or getNormalizedPose() instead."),this.getRawPose()}getRawPose(){return this._rawHumanBones.getPose()}getNormalizedPose(){return this._normalizedHumanBones.getPose()}setPose(e){return console.warn("VRMHumanoid: setPose() is deprecated. Use either setRawPose() or setNormalizedPose() instead."),this.setRawPose(e)}setRawPose(e){return this._rawHumanBones.setPose(e)}setNormalizedPose(e){return this._normalizedHumanBones.setPose(e)}resetPose(){return console.warn("VRMHumanoid: resetPose() is deprecated. Use either resetRawPose() or resetNormalizedPose() instead."),this.resetRawPose()}resetRawPose(){return this._rawHumanBones.resetPose()}resetNormalizedPose(){return this._normalizedHumanBones.resetPose()}getBone(e){return console.warn("VRMHumanoid: getBone() is deprecated. Use either getRawBone() or getNormalizedBone() instead."),this.getRawBone(e)}getRawBone(e){return this._rawHumanBones.getBone(e)}getNormalizedBone(e){return this._normalizedHumanBones.getBone(e)}getBoneNode(e){return console.warn("VRMHumanoid: getBoneNode() is deprecated. Use either getRawBoneNode() or getNormalizedBoneNode() instead."),this.getRawBoneNode(e)}getRawBoneNode(e){return this._rawHumanBones.getBoneNode(e)}getNormalizedBoneNode(e){return this._normalizedHumanBones.getBoneNode(e)}update(){this.autoUpdateHumanBones&&this._normalizedHumanBones.update()}};var _e={Hips:"hips",Spine:"spine",Head:"head",LeftUpperLeg:"leftUpperLeg",LeftLowerLeg:"leftLowerLeg",LeftFoot:"leftFoot",RightUpperLeg:"rightUpperLeg",RightLowerLeg:"rightLowerLeg",RightFoot:"rightFoot",LeftUpperArm:"leftUpperArm",LeftLowerArm:"leftLowerArm",LeftHand:"leftHand",RightUpperArm:"rightUpperArm",RightLowerArm:"rightLowerArm",RightHand:"rightHand"};var xt=new Set(["1.0","1.0-beta"]),et={leftThumbProximal:"leftThumbMetacarpal",leftThumbIntermediate:"leftThumbProximal",rightThumbProximal:"rightThumbMetacarpal",rightThumbIntermediate:"rightThumbProximal"},ae=class{get name(){return"VRMHumanoidLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot,this.autoUpdateHumanBones=t==null?void 0:t.autoUpdateHumanBones}afterRoot(e){return R(this,null,function*(){e.userData.vrmHumanoid=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let r=yield this._v0Import(e);return r||null})}_v1Import(e){return R(this,null,function*(){var d,c;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(!o)return null;let i=o.specVersion;if(!xt.has(i))return console.warn(`VRMHumanoidLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.humanoid;if(!n)return null;let u=n.humanBones.leftThumbIntermediate!=null||n.humanBones.rightThumbIntermediate!=null,s={};n.humanBones!=null&&(yield Promise.all(Object.entries(n.humanBones).map(M=>R(this,[M],function*([p,m]){let h=p,f=m.node;if(u){let x=et[h];x!=null&&(h=x)}let V=yield this.parser.getDependency("node",f);if(V==null){console.warn(`A glTF node bound to the humanoid bone ${h} (index = ${f}) does not exist`);return}s[h]={node:V}}))));let l=new re(this._ensureRequiredBonesExist(s),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(l.normalizedHumanBonesRoot),this.helperRoot){let p=new J(l);this.helperRoot.add(p),p.renderOrder=this.helperRoot.renderOrder}return l})}_v0Import(e){return R(this,null,function*(){var u;let r=(u=this.parser.json.extensions)==null?void 0:u.VRM;if(!r)return null;let o=r.humanoid;if(!o)return null;let i={};o.humanBones!=null&&(yield Promise.all(o.humanBones.map(s=>R(this,null,function*(){let l=s.bone,d=s.node;if(l==null||d==null)return;let c=yield this.parser.getDependency("node",d);if(c==null){console.warn(`A glTF node bound to the humanoid bone ${l} (index = ${d}) does not exist`);return}let p=et[l],m=p!=null?p:l;if(i[m]!=null){console.warn(`Multiple bone entries for ${m} detected (index = ${d}), ignoring duplicated entries.`);return}i[m]={node:c}}))));let n=new re(this._ensureRequiredBonesExist(i),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(n.normalizedHumanBonesRoot),this.helperRoot){let s=new J(n);this.helperRoot.add(s),s.renderOrder=this.helperRoot.renderOrder}return n})}_ensureRequiredBonesExist(e){let t=Object.values(_e).filter(r=>e[r]==null);if(t.length>0)throw new Error(`VRMHumanoidLoaderPlugin: These humanoid bones are required but not exist: ${t.join(", ")}`);return e}};var E=T(require("three"),1);var fe=T(require("three"),1),Me=class extends fe.BufferGeometry{constructor(){super();this._currentTheta=0;this._currentRadius=0;this.theta=0,this.radius=0,this._currentTheta=0,this._currentRadius=0,this._attrPos=new fe.BufferAttribute(new Float32Array(65*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new fe.BufferAttribute(new Uint16Array(3*63),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentTheta!==this.theta&&(this._currentTheta=this.theta,t=!0),this._currentRadius!==this.radius&&(this._currentRadius=this.radius,t=!0),t&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,0,0,0);for(let t=0;t<64;t++){let r=t/63*this._currentTheta;this._attrPos.setXYZ(t+1,this._currentRadius*Math.sin(r),0,this._currentRadius*Math.cos(r))}this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<63;t++)this._attrIndex.setXYZ(t*3,0,t+1,t+2);this._attrIndex.needsUpdate=!0}};var C=T(require("three"),1),Ae=class extends C.BufferGeometry{constructor(){super(),this.radius=0,this._currentRadius=0,this.tail=new C.Vector3,this._currentTail=new C.Vector3,this._attrPos=new C.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new C.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;this._currentRadius!==this.radius&&(this._currentRadius=this.radius,e=!0),this._currentTail.equals(this.tail)||(this._currentTail.copy(this.tail),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){let t=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(t),Math.sin(t),0),this._attrPos.setXYZ(32+e,0,Math.cos(t),Math.sin(t)),this._attrPos.setXYZ(64+e,Math.sin(t),0,Math.cos(t))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<32;e++){let t=(e+1)%32;this._attrIndex.setXY(e*2,e,t),this._attrIndex.setXY(64+e*2,32+e,32+t),this._attrIndex.setXY(128+e*2,64+e,64+t)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}};var we=new E.Quaternion,tt=new E.Quaternion,Ee=new E.Vector3,rt=new E.Vector3,ot=Math.sqrt(2)/2,Tt=new E.Quaternion(0,0,-ot,ot),bt=new E.Vector3(0,1,0),le=class extends E.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.vrmLookAt=e;{let t=new Me;t.radius=.5;let r=new E.MeshBasicMaterial({color:65280,transparent:!0,opacity:.5,side:E.DoubleSide,depthTest:!1,depthWrite:!1});this._meshPitch=new E.Mesh(t,r),this.add(this._meshPitch)}{let t=new Me;t.radius=.5;let r=new E.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.5,side:E.DoubleSide,depthTest:!1,depthWrite:!1});this._meshYaw=new E.Mesh(t,r),this.add(this._meshYaw)}{let t=new Ae;t.radius=.1;let r=new E.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1});this._lineTarget=new E.LineSegments(t,r),this._lineTarget.frustumCulled=!1,this.add(this._lineTarget)}}dispose(){this._meshYaw.geometry.dispose(),this._meshYaw.material.dispose(),this._meshPitch.geometry.dispose(),this._meshPitch.material.dispose(),this._lineTarget.geometry.dispose(),this._lineTarget.material.dispose()}updateMatrixWorld(e){let t=E.MathUtils.DEG2RAD*this.vrmLookAt.yaw;this._meshYaw.geometry.theta=t,this._meshYaw.geometry.update();let r=E.MathUtils.DEG2RAD*this.vrmLookAt.pitch;this._meshPitch.geometry.theta=r,this._meshPitch.geometry.update(),this.vrmLookAt.getLookAtWorldPosition(Ee),this.vrmLookAt.getLookAtWorldQuaternion(we),we.multiply(this.vrmLookAt.getFaceFrontQuaternion(tt)),this._meshYaw.position.copy(Ee),this._meshYaw.quaternion.copy(we),this._meshPitch.position.copy(Ee),this._meshPitch.quaternion.copy(we),this._meshPitch.quaternion.multiply(tt.setFromAxisAngle(bt,t)),this._meshPitch.quaternion.multiply(Tt);let{target:o,autoUpdate:i}=this.vrmLookAt;o!=null&&i&&(o.getWorldPosition(rt).sub(Ee),this._lineTarget.geometry.tail.copy(rt),this._lineTarget.geometry.update(),this._lineTarget.position.copy(Ee)),super.updateMatrixWorld(e)}};var y=T(require("three"),1);var Oe=T(require("three"),1),Ht=new Oe.Vector3,Lt=new Oe.Vector3;function ge(a,e){return a.matrixWorld.decompose(Ht,e,Lt),e}function ue(a){return[Math.atan2(-a.z,a.x),Math.atan2(a.y,Math.sqrt(a.x*a.x+a.z*a.z))]}function Se(a){let e=Math.round(a/2/Math.PI);return a-2*Math.PI*e}var nt=new y.Vector3(0,0,1),Pt=new y.Vector3,_t=new y.Vector3,At=new y.Vector3,wt=new y.Quaternion,De=new y.Quaternion,it=new y.Quaternion,vt=new y.Quaternion,Ge=new y.Euler,ve=class ve{constructor(e,t){this.offsetFromHeadBone=new y.Vector3;this.autoUpdate=!0;this.faceFront=new y.Vector3(0,0,1);this.humanoid=e,this.applier=t,this._yaw=0,this._pitch=0,this._needsUpdate=!0,this._restHeadWorldQuaternion=this.getLookAtWorldQuaternion(new y.Quaternion)}get yaw(){return this._yaw}set yaw(e){this._yaw=e,this._needsUpdate=!0}get pitch(){return this._pitch}set pitch(e){this._pitch=e,this._needsUpdate=!0}get euler(){return console.warn("VRMLookAt: euler is deprecated. use getEuler() instead."),this.getEuler(new y.Euler)}getEuler(e){return e.set(y.MathUtils.DEG2RAD*this._pitch,y.MathUtils.DEG2RAD*this._yaw,0,"YXZ")}copy(e){if(this.humanoid!==e.humanoid)throw new Error("VRMLookAt: humanoid must be same in order to copy");return this.offsetFromHeadBone.copy(e.offsetFromHeadBone),this.applier=e.applier,this.autoUpdate=e.autoUpdate,this.target=e.target,this.faceFront.copy(e.faceFront),this}clone(){return new ve(this.humanoid,this.applier).copy(this)}reset(){this._yaw=0,this._pitch=0,this._needsUpdate=!0}getLookAtWorldPosition(e){let t=this.humanoid.getRawBoneNode("head");return e.copy(this.offsetFromHeadBone).applyMatrix4(t.matrixWorld)}getLookAtWorldQuaternion(e){let t=this.humanoid.getRawBoneNode("head");return ge(t,e)}getFaceFrontQuaternion(e){if(this.faceFront.distanceToSquared(nt)<.01)return e.copy(this._restHeadWorldQuaternion).invert();let[t,r]=ue(this.faceFront);return Ge.set(0,.5*Math.PI+t,r,"YZX"),e.setFromEuler(Ge).premultiply(vt.copy(this._restHeadWorldQuaternion).invert())}getLookAtWorldDirection(e){return this.getLookAtWorldQuaternion(De),this.getFaceFrontQuaternion(it),e.copy(nt).applyQuaternion(De).applyQuaternion(it).applyEuler(this.getEuler(Ge))}lookAt(e){let t=wt.copy(this._restHeadWorldQuaternion).multiply(Le(this.getLookAtWorldQuaternion(De))),r=this.getLookAtWorldPosition(_t),o=At.copy(e).sub(r).applyQuaternion(t).normalize(),[i,n]=ue(this.faceFront),[u,s]=ue(o),l=Se(u-i),d=Se(n-s);this._yaw=y.MathUtils.RAD2DEG*l,this._pitch=y.MathUtils.RAD2DEG*d,this._needsUpdate=!0}update(e){this.target!=null&&this.autoUpdate&&this.lookAt(this.target.getWorldPosition(Pt)),this._needsUpdate&&(this._needsUpdate=!1,this.applier.applyYawPitch(this._yaw,this._pitch))}};ve.EULER_ORDER="YXZ";var pe=ve;var g=T(require("three"),1);var Bt=new g.Vector3(0,0,1),F=new g.Quaternion,me=new g.Quaternion,_=new g.Euler(0,0,0,"YXZ"),S=class{constructor(e,t,r,o,i){this.humanoid=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=r,this.rangeMapVerticalDown=o,this.rangeMapVerticalUp=i,this.faceFront=new g.Vector3(0,0,1),this._restQuatLeftEye=new g.Quaternion,this._restQuatRightEye=new g.Quaternion,this._restLeftEyeParentWorldQuat=new g.Quaternion,this._restRightEyeParentWorldQuat=new g.Quaternion;let n=this.humanoid.getRawBoneNode("leftEye"),u=this.humanoid.getRawBoneNode("rightEye");n&&(this._restQuatLeftEye.copy(n.quaternion),ge(n.parent,this._restLeftEyeParentWorldQuat)),u&&(this._restQuatRightEye.copy(u.quaternion),ge(u.parent,this._restRightEyeParentWorldQuat))}applyYawPitch(e,t){let r=this.humanoid.getRawBoneNode("leftEye"),o=this.humanoid.getRawBoneNode("rightEye"),i=this.humanoid.getNormalizedBoneNode("leftEye"),n=this.humanoid.getNormalizedBoneNode("rightEye");r&&(t<0?_.x=-g.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):_.x=g.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?_.y=-g.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(-e):_.y=g.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(e),F.setFromEuler(_),this._getWorldFaceFrontQuat(me),i.quaternion.copy(me).multiply(F).multiply(me.invert()),F.copy(this._restLeftEyeParentWorldQuat),r.quaternion.copy(i.quaternion).multiply(F).premultiply(F.invert()).multiply(this._restQuatLeftEye)),o&&(t<0?_.x=-g.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):_.x=g.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?_.y=-g.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(-e):_.y=g.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(e),F.setFromEuler(_),this._getWorldFaceFrontQuat(me),n.quaternion.copy(me).multiply(F).multiply(me.invert()),F.copy(this._restRightEyeParentWorldQuat),o.quaternion.copy(n.quaternion).multiply(F).premultiply(F.invert()).multiply(this._restQuatRightEye))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=g.MathUtils.RAD2DEG*e.y,r=g.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,r)}_getWorldFaceFrontQuat(e){if(this.faceFront.distanceToSquared(Bt)<.01)return e.identity();let[t,r]=ue(this.faceFront);return _.set(0,.5*Math.PI+t,r,"YZX"),e.setFromEuler(_)}};S.type="bone";var Ce=T(require("three"),1),W=class{constructor(e,t,r,o,i){this.expressions=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=r,this.rangeMapVerticalDown=o,this.rangeMapVerticalUp=i}applyYawPitch(e,t){t<0?(this.expressions.setValue("lookDown",0),this.expressions.setValue("lookUp",this.rangeMapVerticalUp.map(-t))):(this.expressions.setValue("lookUp",0),this.expressions.setValue("lookDown",this.rangeMapVerticalDown.map(t))),e<0?(this.expressions.setValue("lookLeft",0),this.expressions.setValue("lookRight",this.rangeMapHorizontalOuter.map(-e))):(this.expressions.setValue("lookRight",0),this.expressions.setValue("lookLeft",this.rangeMapHorizontalOuter.map(e)))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=Ce.MathUtils.RAD2DEG*e.y,r=Ce.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,r)}};W.type="expression";var oe=class{constructor(e,t){this.inputMaxValue=e,this.outputScale=t}map(e){return this.outputScale*ye(e/this.inputMaxValue)}};var kt=new Set(["1.0","1.0-beta"]),Be=.01,de=class{get name(){return"VRMLookAtLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot}afterRoot(e){return R(this,null,function*(){let t=e.userData.vrmHumanoid;if(t===null)return;if(t===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");let r=e.userData.vrmExpressionManager;if(r!==null){if(r===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmExpressionManager is undefined. VRMExpressionLoaderPlugin have to be used first");e.userData.vrmLookAt=yield this._import(e,t,r)}})}_import(e,t,r){return R(this,null,function*(){if(t==null||r==null)return null;let o=yield this._v1Import(e,t,r);if(o)return o;let i=yield this._v0Import(e,t,r);return i||null})}_v1Import(e,t,r){return R(this,null,function*(){var f,V,x;let o=this.parser.json;if(!(((f=o.extensionsUsed)==null?void 0:f.indexOf("VRMC_vrm"))!==-1))return null;let n=(V=o.extensions)==null?void 0:V.VRMC_vrm;if(!n)return null;let u=n.specVersion;if(!kt.has(u))return console.warn(`VRMLookAtLoaderPlugin: Unknown VRMC_vrm specVersion "${u}"`),null;let s=n.lookAt;if(!s)return null;let l=s.type==="expression"?1:10,d=this._v1ImportRangeMap(s.rangeMapHorizontalInner,l),c=this._v1ImportRangeMap(s.rangeMapHorizontalOuter,l),p=this._v1ImportRangeMap(s.rangeMapVerticalDown,l),m=this._v1ImportRangeMap(s.rangeMapVerticalUp,l),M;s.type==="expression"?M=new W(r,d,c,p,m):M=new S(t,d,c,p,m);let h=this._importLookAt(t,M);return h.offsetFromHeadBone.fromArray((x=s.offsetFromHeadBone)!=null?x:[0,.06,0]),h})}_v1ImportRangeMap(e,t){var i,n;let r=(i=e==null?void 0:e.inputMaxValue)!=null?i:90,o=(n=e==null?void 0:e.outputScale)!=null?n:t;return r<Be&&(console.warn("VRMLookAtLoaderPlugin: inputMaxValue of a range map is too small. Consider reviewing the range map!"),r=Be),new oe(r,o)}_v0Import(e,t,r){return R(this,null,function*(){var M,h,f,V;let i=(M=this.parser.json.extensions)==null?void 0:M.VRM;if(!i)return null;let n=i.firstPerson;if(!n)return null;let u=n.lookAtTypeName==="BlendShape"?1:10,s=this._v0ImportDegreeMap(n.lookAtHorizontalInner,u),l=this._v0ImportDegreeMap(n.lookAtHorizontalOuter,u),d=this._v0ImportDegreeMap(n.lookAtVerticalDown,u),c=this._v0ImportDegreeMap(n.lookAtVerticalUp,u),p;n.lookAtTypeName==="BlendShape"?p=new W(r,s,l,d,c):p=new S(t,s,l,d,c);let m=this._importLookAt(t,p);return n.firstPersonBoneOffset?m.offsetFromHeadBone.set((h=n.firstPersonBoneOffset.x)!=null?h:0,(f=n.firstPersonBoneOffset.y)!=null?f:.06,-((V=n.firstPersonBoneOffset.z)!=null?V:0)):m.offsetFromHeadBone.set(0,.06,0),m.faceFront.set(0,0,-1),p instanceof S&&p.faceFront.set(0,0,-1),m})}_v0ImportDegreeMap(e,t){var n,u;let r=e==null?void 0:e.curve;JSON.stringify(r)!=="[0,0,0,1,1,1,1,0]"&&console.warn("Curves of LookAtDegreeMap defined in VRM 0.0 are not supported");let o=(n=e==null?void 0:e.xRange)!=null?n:90,i=(u=e==null?void 0:e.yRange)!=null?u:t;return o<Be&&(console.warn("VRMLookAtLoaderPlugin: xRange of a degree map is too small. Consider reviewing the degree map!"),o=Be),new oe(o,i)}_importLookAt(e,t){let r=new pe(e,t);if(this.helperRoot){let o=new le(r);this.helperRoot.add(o),o.renderOrder=this.helperRoot.renderOrder}return r}};var st={Bone:"bone",Expression:"expression"};var lt=T(require("three"),1);function at(a,e){return typeof a!="string"||a===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(a)&&(e=e.replace(/(^https?:\/\/[^/]+).*/i,"$1")),/^(https?:)?\/\//i.test(a)||/^data:.*,.*$/i.test(a)||/^blob:.*$/i.test(a)?a:e+a)}var Ft=new Set(["1.0","1.0-beta"]),he=class{get name(){return"VRMMetaLoaderPlugin"}constructor(e,t){var r,o,i;this.parser=e,this.needThumbnailImage=(r=t==null?void 0:t.needThumbnailImage)!=null?r:!1,this.acceptLicenseUrls=(o=t==null?void 0:t.acceptLicenseUrls)!=null?o:["https://vrm.dev/licenses/1.0/"],this.acceptV0Meta=(i=t==null?void 0:t.acceptV0Meta)!=null?i:!0}afterRoot(e){return R(this,null,function*(){e.userData.vrmMeta=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t!=null)return t;let r=yield this._v0Import(e);return r!=null?r:null})}_v1Import(e){return R(this,null,function*(){var d,c,p;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(o==null)return null;let i=o.specVersion;if(!Ft.has(i))return console.warn(`VRMMetaLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.meta;if(!n)return null;let u=n.licenseUrl;if(!new Set(this.acceptLicenseUrls).has(u))throw new Error(`VRMMetaLoaderPlugin: The license url "${u}" is not accepted`);let l;return this.needThumbnailImage&&n.thumbnailImage!=null&&(l=(p=yield this._extractGLTFImage(n.thumbnailImage))!=null?p:void 0),{metaVersion:"1",name:n.name,version:n.version,authors:n.authors,copyrightInformation:n.copyrightInformation,contactInformation:n.contactInformation,references:n.references,thirdPartyLicenses:n.thirdPartyLicenses,thumbnailImage:l,licenseUrl:n.licenseUrl,avatarPermission:n.avatarPermission,allowExcessivelyViolentUsage:n.allowExcessivelyViolentUsage,allowExcessivelySexualUsage:n.allowExcessivelySexualUsage,commercialUsage:n.commercialUsage,allowPoliticalOrReligiousUsage:n.allowPoliticalOrReligiousUsage,allowAntisocialOrHateUsage:n.allowAntisocialOrHateUsage,creditNotation:n.creditNotation,allowRedistribution:n.allowRedistribution,modification:n.modification,otherLicenseUrl:n.otherLicenseUrl}})}_v0Import(e){return R(this,null,function*(){var n;let r=(n=this.parser.json.extensions)==null?void 0:n.VRM;if(!r)return null;let o=r.meta;if(!o)return null;if(!this.acceptV0Meta)throw new Error("VRMMetaLoaderPlugin: Attempted to load VRM0.0 meta but acceptV0Meta is false");let i;return this.needThumbnailImage&&o.texture!=null&&o.texture!==-1&&(i=yield this.parser.getDependency("texture",o.texture)),{metaVersion:"0",allowedUserName:o.allowedUserName,author:o.author,commercialUssageName:o.commercialUssageName,contactInformation:o.contactInformation,licenseName:o.licenseName,otherLicenseUrl:o.otherLicenseUrl,otherPermissionUrl:o.otherPermissionUrl,reference:o.reference,sexualUssageName:o.sexualUssageName,texture:i!=null?i:void 0,title:o.title,version:o.version,violentUssageName:o.violentUssageName}})}_extractGLTFImage(e){return R(this,null,function*(){var n;let r=(n=this.parser.json.images)==null?void 0:n[e];if(r==null)return console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image doesn't exist`),null;let o=r.uri;if(r.bufferView!=null){let u=yield this.parser.getDependency("bufferView",r.bufferView),s=new Blob([u],{type:r.mimeType});o=URL.createObjectURL(s)}return o==null?(console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image couldn't load properly`),null):yield new lt.ImageLoader().loadAsync(at(o,this.parser.options.path)).catch(u=>(console.error(u),console.warn("VRMMetaLoaderPlugin: Failed to load a thumbnail image"),null))})}};var ce=class{constructor(e){this.scene=e.scene,this.meta=e.meta,this.humanoid=e.humanoid,this.expressionManager=e.expressionManager,this.firstPerson=e.firstPerson,this.lookAt=e.lookAt}update(e){this.humanoid.update(),this.lookAt&&this.lookAt.update(e),this.expressionManager&&this.expressionManager.update()}};var ke=class{get name(){return"VRMC_vrm"}constructor(e,t){var i,n,u,s,l;this.parser=e;let r=t==null?void 0:t.helperRoot,o=t==null?void 0:t.autoUpdateHumanBones;this.expressionPlugin=(i=t==null?void 0:t.expressionPlugin)!=null?i:new ne(e),this.firstPersonPlugin=(n=t==null?void 0:t.firstPersonPlugin)!=null?n:new ie(e),this.humanoidPlugin=(u=t==null?void 0:t.humanoidPlugin)!=null?u:new ae(e,{helperRoot:r,autoUpdateHumanBones:o}),this.lookAtPlugin=(s=t==null?void 0:t.lookAtPlugin)!=null?s:new de(e,{helperRoot:r}),this.metaPlugin=(l=t==null?void 0:t.metaPlugin)!=null?l:new he(e)}afterRoot(e){return R(this,null,function*(){yield this.metaPlugin.afterRoot(e),yield this.humanoidPlugin.afterRoot(e),yield this.expressionPlugin.afterRoot(e),yield this.lookAtPlugin.afterRoot(e),yield this.firstPersonPlugin.afterRoot(e);let t=e.userData.vrmMeta,r=e.userData.vrmHumanoid;if(t&&r){let o=new ce({scene:e.scene,expressionManager:e.userData.vrmExpressionManager,firstPerson:e.userData.vrmFirstPerson,humanoid:r,lookAt:e.userData.vrmLookAt,meta:t});e.userData.vrmCore=o}})}};
2
+ "use strict";var ut=Object.create;var Ve=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var dt=Object.getPrototypeOf,ht=Object.prototype.hasOwnProperty;var ct=(a,e)=>{for(var t in e)Ve(a,t,{get:e[t],enumerable:!0})},We=(a,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of mt(e))!ht.call(a,o)&&o!==t&&Ve(a,o,{get:()=>e[o],enumerable:!(r=pt(e,o))||r.enumerable});return a};var T=(a,e,t)=>(t=a!=null?ut(dt(a)):{},We(e||!a||!a.__esModule?Ve(t,"default",{value:a,enumerable:!0}):t,a)),Rt=a=>We(Ve({},"__esModule",{value:!0}),a);var R=(a,e,t)=>new Promise((r,o)=>{var i=s=>{try{u(t.next(s))}catch(l){o(l)}},n=s=>{try{u(t.throw(s))}catch(l){o(l)}},u=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,n);u((t=t.apply(a,e)).next())});var It={};ct(It,{VRMCore:()=>ce,VRMCoreLoaderPlugin:()=>ke,VRMExpression:()=>j,VRMExpressionLoaderPlugin:()=>ne,VRMExpressionManager:()=>z,VRMExpressionMaterialColorBind:()=>Y,VRMExpressionMaterialColorType:()=>q,VRMExpressionMorphTargetBind:()=>$,VRMExpressionOverrideType:()=>$e,VRMExpressionPresetName:()=>Q,VRMExpressionTextureTransformBind:()=>X,VRMFirstPerson:()=>Z,VRMFirstPersonLoaderPlugin:()=>ie,VRMFirstPersonMeshAnnotationType:()=>Xe,VRMHumanBoneList:()=>se,VRMHumanBoneName:()=>Ke,VRMHumanBoneParentMap:()=>He,VRMHumanoid:()=>re,VRMHumanoidHelper:()=>J,VRMHumanoidLoaderPlugin:()=>ae,VRMLookAt:()=>pe,VRMLookAtBoneApplier:()=>S,VRMLookAtExpressionApplier:()=>W,VRMLookAtHelper:()=>le,VRMLookAtLoaderPlugin:()=>de,VRMLookAtRangeMap:()=>oe,VRMLookAtTypeName:()=>st,VRMMetaLoaderPlugin:()=>he,VRMRequiredHumanBoneName:()=>_e});module.exports=Rt(It);var je=T(require("three"),1),j=class extends je.Object3D{constructor(t){super();this.weight=0;this.isBinary=!1;this.overrideBlink="none";this.overrideLookAt="none";this.overrideMouth="none";this._binds=[];this.name=`VRMExpression_${t}`,this.expressionName=t,this.type="VRMExpression",this.visible=!1}get binds(){return this._binds}get overrideBlinkAmount(){return this.overrideBlink==="block"?0<this.outputWeight?1:0:this.overrideBlink==="blend"?this.outputWeight:0}get overrideLookAtAmount(){return this.overrideLookAt==="block"?0<this.outputWeight?1:0:this.overrideLookAt==="blend"?this.outputWeight:0}get overrideMouthAmount(){return this.overrideMouth==="block"?0<this.outputWeight?1:0:this.overrideMouth==="blend"?this.outputWeight:0}get outputWeight(){return this.isBinary?this.weight>.5?1:0:this.weight}addBind(t){this._binds.push(t)}deleteBind(t){let r=this._binds.indexOf(t);r>=0&&this._binds.splice(r,1)}applyWeight(t){var o;let r=this.outputWeight;r*=(o=t==null?void 0:t.multiplier)!=null?o:1,this.isBinary&&r<1&&(r=0),this._binds.forEach(i=>i.applyWeight(r))}clearAppliedWeight(){this._binds.forEach(t=>t.clearAppliedWeight())}};var G=T(require("three"),1);function Qe(a,e,t){var l,d;let r=a.parser.json,o=(l=r.nodes)==null?void 0:l[e];if(o==null)return console.warn(`extractPrimitivesInternal: Attempt to use nodes[${e}] of glTF but the node doesn't exist`),null;let i=o.mesh;if(i==null)return null;let n=(d=r.meshes)==null?void 0:d[i];if(n==null)return console.warn(`extractPrimitivesInternal: Attempt to use meshes[${i}] of glTF but the mesh doesn't exist`),null;let u=n.primitives.length,s=[];return t.traverse(c=>{s.length<u&&c.isMesh&&s.push(c)}),s}function Fe(a,e){return R(this,null,function*(){let t=yield a.parser.getDependency("node",e);return Qe(a,e,t)})}function Ie(a){return R(this,null,function*(){let e=yield a.parser.getDependencies("node"),t=new Map;return e.forEach((r,o)=>{let i=Qe(a,o,r);i!=null&&t.set(o,i)}),t})}var Q={Aa:"aa",Ih:"ih",Ou:"ou",Ee:"ee",Oh:"oh",Blink:"blink",Happy:"happy",Angry:"angry",Sad:"sad",Relaxed:"relaxed",LookUp:"lookUp",Surprised:"surprised",LookDown:"lookDown",LookLeft:"lookLeft",LookRight:"lookRight",BlinkLeft:"blinkLeft",BlinkRight:"blinkRight",Neutral:"neutral"};function ye(a){return Math.max(Math.min(a,1),0)}var z=class a{constructor(){this.blinkExpressionNames=["blink","blinkLeft","blinkRight"];this.lookAtExpressionNames=["lookLeft","lookRight","lookUp","lookDown"];this.mouthExpressionNames=["aa","ee","ih","oh","ou"];this._expressions=[];this._expressionMap={}}get expressions(){return this._expressions.concat()}get expressionMap(){return Object.assign({},this._expressionMap)}get presetExpressionMap(){let e={},t=new Set(Object.values(Q));return Object.entries(this._expressionMap).forEach(([r,o])=>{t.has(r)&&(e[r]=o)}),e}get customExpressionMap(){let e={},t=new Set(Object.values(Q));return Object.entries(this._expressionMap).forEach(([r,o])=>{t.has(r)||(e[r]=o)}),e}copy(e){return this._expressions.concat().forEach(r=>{this.unregisterExpression(r)}),e._expressions.forEach(r=>{this.registerExpression(r)}),this.blinkExpressionNames=e.blinkExpressionNames.concat(),this.lookAtExpressionNames=e.lookAtExpressionNames.concat(),this.mouthExpressionNames=e.mouthExpressionNames.concat(),this}clone(){return new a().copy(this)}getExpression(e){var t;return(t=this._expressionMap[e])!=null?t:null}registerExpression(e){this._expressions.push(e),this._expressionMap[e.expressionName]=e}unregisterExpression(e){let t=this._expressions.indexOf(e);t===-1&&console.warn("VRMExpressionManager: The specified expressions is not registered"),this._expressions.splice(t,1),delete this._expressionMap[e.expressionName]}getValue(e){var r;let t=this.getExpression(e);return(r=t==null?void 0:t.weight)!=null?r:null}setValue(e,t){let r=this.getExpression(e);r&&(r.weight=ye(t))}resetValues(){this._expressions.forEach(e=>{e.weight=0})}getExpressionTrackName(e){let t=this.getExpression(e);return t?`${t.name}.weight`:null}update(){let e=this._calculateWeightMultipliers();this._expressions.forEach(t=>{t.clearAppliedWeight()}),this._expressions.forEach(t=>{let r=1,o=t.expressionName;this.blinkExpressionNames.indexOf(o)!==-1&&(r*=e.blink),this.lookAtExpressionNames.indexOf(o)!==-1&&(r*=e.lookAt),this.mouthExpressionNames.indexOf(o)!==-1&&(r*=e.mouth),t.applyWeight({multiplier:r})})}_calculateWeightMultipliers(){let e=1,t=1,r=1;return this._expressions.forEach(o=>{e-=o.overrideBlinkAmount,t-=o.overrideLookAtAmount,r-=o.overrideMouthAmount}),e=Math.max(0,e),t=Math.max(0,t),r=Math.max(0,r),{blink:e,lookAt:t,mouth:r}}};var q={Color:"color",EmissionColor:"emissionColor",ShadeColor:"shadeColor",MatcapColor:"matcapColor",RimColor:"rimColor",OutlineColor:"outlineColor"},ze={_Color:q.Color,_EmissionColor:q.EmissionColor,_ShadeColor:q.ShadeColor,_RimColor:q.RimColor,_OutlineColor:q.OutlineColor};var Ne=T(require("three"),1),ft=new Ne.Color,xe=class xe{constructor({material:e,type:t,targetValue:r,targetAlpha:o}){this.material=e,this.type=t,this.targetValue=r,this.targetAlpha=o!=null?o:1;let i=this._initColorBindState(),n=this._initAlphaBindState();this._state={color:i,alpha:n}}applyWeight(e){let{color:t,alpha:r}=this._state;if(t!=null){let{propertyName:o,deltaValue:i}=t,n=this.material[o];n!=null&&n.add(ft.copy(i).multiplyScalar(e))}if(r!=null){let{propertyName:o,deltaValue:i}=r;this.material[o]!=null&&(this.material[o]+=i*e)}}clearAppliedWeight(){let{color:e,alpha:t}=this._state;if(e!=null){let{propertyName:r,initialValue:o}=e,i=this.material[r];i!=null&&i.copy(o)}if(t!=null){let{propertyName:r,initialValue:o}=t;this.material[r]!=null&&(this.material[r]=o)}}_initColorBindState(){var l,d,c;let{material:e,type:t,targetValue:r}=this,o=this._getPropertyNameMap(),i=(d=(l=o==null?void 0:o[t])==null?void 0:l[0])!=null?d:null;if(i==null)return console.warn(`Tried to add a material color bind to the material ${(c=e.name)!=null?c:"(no name)"}, the type ${t} but the material or the type is not supported.`),null;let u=e[i].clone(),s=new Ne.Color(r.r-u.r,r.g-u.g,r.b-u.b);return{propertyName:i,initialValue:u,deltaValue:s}}_initAlphaBindState(){var s,l,d;let{material:e,type:t,targetAlpha:r}=this,o=this._getPropertyNameMap(),i=(l=(s=o==null?void 0:o[t])==null?void 0:s[1])!=null?l:null;if(i==null&&r!==1)return console.warn(`Tried to add a material alpha bind to the material ${(d=e.name)!=null?d:"(no name)"}, the type ${t} but the material or the type does not support alpha.`),null;if(i==null)return null;let n=e[i],u=r-n;return{propertyName:i,initialValue:n,deltaValue:u}}_getPropertyNameMap(){var e,t;return(t=(e=Object.entries(xe._propertyNameMapMap).find(([r])=>this.material[r]===!0))==null?void 0:e[1])!=null?t:null}};xe._propertyNameMapMap={isMeshStandardMaterial:{color:["color","opacity"],emissionColor:["emissive",null]},isMeshBasicMaterial:{color:["color","opacity"]},isMToonMaterial:{color:["color","opacity"],emissionColor:["emissive",null],outlineColor:["outlineColorFactor",null],matcapColor:["matcapFactor",null],rimColor:["parametricRimColorFactor",null],shadeColor:["shadeColorFactor",null]}};var Y=xe;var $=class{constructor({primitives:e,index:t,weight:r}){this.primitives=e,this.index=t,this.weight=r}applyWeight(e){this.primitives.forEach(t=>{var r;((r=t.morphTargetInfluences)==null?void 0:r[this.index])!=null&&(t.morphTargetInfluences[this.index]+=this.weight*e)})}clearAppliedWeight(){this.primitives.forEach(e=>{var t;((t=e.morphTargetInfluences)==null?void 0:t[this.index])!=null&&(e.morphTargetInfluences[this.index]=0)})}};var Ye=T(require("three"),1),qe=new Ye.Vector2,Te=class Te{constructor({material:e,scale:t,offset:r}){var i,n;this.material=e,this.scale=t,this.offset=r;let o=(i=Object.entries(Te._propertyNamesMap).find(([u])=>e[u]===!0))==null?void 0:i[1];o==null?(console.warn(`Tried to add a texture transform bind to the material ${(n=e.name)!=null?n:"(no name)"} but the material is not supported.`),this._properties=[]):(this._properties=[],o.forEach(u=>{var m;let s=(m=e[u])==null?void 0:m.clone();if(!s)return null;e[u]=s;let l=s.offset.clone(),d=s.repeat.clone(),c=r.clone().sub(l),p=t.clone().sub(d);this._properties.push({name:u,initialOffset:l,deltaOffset:c,initialScale:d,deltaScale:p})}))}applyWeight(e){this._properties.forEach(t=>{let r=this.material[t.name];r!==void 0&&(r.offset.add(qe.copy(t.deltaOffset).multiplyScalar(e)),r.repeat.add(qe.copy(t.deltaScale).multiplyScalar(e)))})}clearAppliedWeight(){this._properties.forEach(e=>{let t=this.material[e.name];t!==void 0&&(t.offset.copy(e.initialOffset),t.repeat.copy(e.initialScale))})}};Te._propertyNamesMap={isMeshStandardMaterial:["map","emissiveMap","bumpMap","normalMap","displacementMap","roughnessMap","metalnessMap","alphaMap"],isMeshBasicMaterial:["map","specularMap","alphaMap"],isMToonMaterial:["map","normalMap","emissiveMap","shadeMultiplyTexture","rimMultiplyTexture","outlineWidthMultiplyTexture","uvAnimationMaskTexture"]};var X=Te;var Mt=new Set(["1.0","1.0-beta"]),be=class be{get name(){return"VRMExpressionLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return R(this,null,function*(){e.userData.vrmExpressionManager=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let r=yield this._v0Import(e);return r||null})}_v1Import(e){return R(this,null,function*(){var d,c;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(!o)return null;let i=o.specVersion;if(!Mt.has(i))return console.warn(`VRMExpressionLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.expressions;if(!n)return null;let u=new Set(Object.values(Q)),s=new Map;n.preset!=null&&Object.entries(n.preset).forEach(([p,m])=>{if(m!=null){if(!u.has(p)){console.warn(`VRMExpressionLoaderPlugin: Unknown preset name "${p}" detected. Ignoring the expression`);return}s.set(p,m)}}),n.custom!=null&&Object.entries(n.custom).forEach(([p,m])=>{if(u.has(p)){console.warn(`VRMExpressionLoaderPlugin: Custom expression cannot have preset name "${p}". Ignoring the expression`);return}s.set(p,m)});let l=new z;return yield Promise.all(Array.from(s.entries()).map(M=>R(this,[M],function*([p,m]){var f,V,x,A,b,H,I;let h=new j(p);if(e.scene.add(h),h.isBinary=(f=m.isBinary)!=null?f:!1,h.overrideBlink=(V=m.overrideBlink)!=null?V:"none",h.overrideLookAt=(x=m.overrideLookAt)!=null?x:"none",h.overrideMouth=(A=m.overrideMouth)!=null?A:"none",(b=m.morphTargetBinds)==null||b.forEach(L=>R(this,null,function*(){var k;if(L.node===void 0||L.index===void 0)return;let P=yield Fe(e,L.node),B=L.index;if(!P.every(N=>Array.isArray(N.morphTargetInfluences)&&B<N.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${m.name} attempts to index morph #${B} but not found.`);return}h.addBind(new $({primitives:P,index:B,weight:(k=L.weight)!=null?k:1}))})),m.materialColorBinds||m.textureTransformBinds){let L=[];e.scene.traverse(P=>{let B=P.material;B&&(Array.isArray(B)?L.push(...B):L.push(B))}),(H=m.materialColorBinds)==null||H.forEach(P=>R(this,null,function*(){L.filter(k=>{var D;let N=(D=this.parser.associations.get(k))==null?void 0:D.materials;return P.material===N}).forEach(k=>{h.addBind(new Y({material:k,type:P.type,targetValue:new G.Color().fromArray(P.targetValue),targetAlpha:P.targetValue[3]}))})})),(I=m.textureTransformBinds)==null||I.forEach(P=>R(this,null,function*(){L.filter(k=>{var D;let N=(D=this.parser.associations.get(k))==null?void 0:D.materials;return P.material===N}).forEach(k=>{var N,D;h.addBind(new X({material:k,offset:new G.Vector2().fromArray((N=P.offset)!=null?N:[0,0]),scale:new G.Vector2().fromArray((D=P.scale)!=null?D:[1,1])}))})}))}l.registerExpression(h)}))),l})}_v0Import(e){return R(this,null,function*(){var s;let t=this.parser.json,r=(s=t.extensions)==null?void 0:s.VRM;if(!r)return null;let o=r.blendShapeMaster;if(!o)return null;let i=new z,n=o.blendShapeGroups;if(!n)return i;let u=new Set;return yield Promise.all(n.map(l=>R(this,null,function*(){var h;let d=l.presetName,c=d!=null&&be.v0v1PresetNameMap[d]||null,p=c!=null?c:l.name;if(p==null){console.warn("VRMExpressionLoaderPlugin: One of custom expressions has no name. Ignoring the expression");return}if(u.has(p)){console.warn(`VRMExpressionLoaderPlugin: An expression preset ${d} has duplicated entries. Ignoring the expression`);return}u.add(p);let m=new j(p);e.scene.add(m),m.isBinary=(h=l.isBinary)!=null?h:!1,l.binds&&l.binds.forEach(f=>R(this,null,function*(){var A;if(f.mesh===void 0||f.index===void 0)return;let V=[];(A=t.nodes)==null||A.forEach((b,H)=>{b.mesh===f.mesh&&V.push(H)});let x=f.index;yield Promise.all(V.map(b=>R(this,null,function*(){var I;let H=yield Fe(e,b);if(!H.every(L=>Array.isArray(L.morphTargetInfluences)&&x<L.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${l.name} attempts to index ${x}th morph but not found.`);return}m.addBind(new $({primitives:H,index:x,weight:.01*((I=f.weight)!=null?I:100)}))})))}));let M=l.materialValues;M&&M.length!==0&&M.forEach(f=>{if(f.materialName===void 0||f.propertyName===void 0||f.targetValue===void 0)return;let V=[];e.scene.traverse(A=>{if(A.material){let b=A.material;Array.isArray(b)?V.push(...b.filter(H=>(H.name===f.materialName||H.name===f.materialName+" (Outline)")&&V.indexOf(H)===-1)):b.name===f.materialName&&V.indexOf(b)===-1&&V.push(b)}});let x=f.propertyName;V.forEach(A=>{if(x==="_MainTex_ST"){let H=new G.Vector2(f.targetValue[0],f.targetValue[1]),I=new G.Vector2(f.targetValue[2],f.targetValue[3]);I.y=1-I.y-H.y,m.addBind(new X({material:A,scale:H,offset:I}));return}let b=ze[x];if(b){m.addBind(new Y({material:A,type:b,targetValue:new G.Color().fromArray(f.targetValue),targetAlpha:f.targetValue[3]}));return}console.warn(x+" is not supported")})}),i.registerExpression(m)}))),i})}};be.v0v1PresetNameMap={a:"aa",e:"ee",i:"ih",o:"oh",u:"ou",blink:"blink",joy:"happy",angry:"angry",sorrow:"sad",fun:"relaxed",lookup:"lookUp",lookdown:"lookDown",lookleft:"lookLeft",lookright:"lookRight",blink_l:"blinkLeft",blink_r:"blinkRight",neutral:"neutral"};var ne=be;var $e={None:"none",Block:"block",Blend:"blend"};var w=T(require("three"),1),U=class U{constructor(e,t){this._firstPersonOnlyLayer=U.DEFAULT_FIRSTPERSON_ONLY_LAYER;this._thirdPersonOnlyLayer=U.DEFAULT_THIRDPERSON_ONLY_LAYER;this._initializedLayers=!1;this.humanoid=e,this.meshAnnotations=t}copy(e){if(this.humanoid!==e.humanoid)throw new Error("VRMFirstPerson: humanoid must be same in order to copy");return this.meshAnnotations=e.meshAnnotations.map(t=>({meshes:t.meshes.concat(),type:t.type})),this}clone(){return new U(this.humanoid,this.meshAnnotations).copy(this)}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}setup({firstPersonOnlyLayer:e=U.DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:t=U.DEFAULT_THIRDPERSON_ONLY_LAYER}={}){this._initializedLayers||(this._firstPersonOnlyLayer=e,this._thirdPersonOnlyLayer=t,this.meshAnnotations.forEach(r=>{r.meshes.forEach(o=>{r.type==="firstPersonOnly"?(o.layers.set(this._firstPersonOnlyLayer),o.traverse(i=>i.layers.set(this._firstPersonOnlyLayer))):r.type==="thirdPersonOnly"?(o.layers.set(this._thirdPersonOnlyLayer),o.traverse(i=>i.layers.set(this._thirdPersonOnlyLayer))):r.type==="auto"&&this._createHeadlessModel(o)})}),this._initializedLayers=!0)}_excludeTriangles(e,t,r,o){let i=0;if(t!=null&&t.length>0)for(let n=0;n<e.length;n+=3){let u=e[n],s=e[n+1],l=e[n+2],d=t[u],c=r[u];if(d[0]>0&&o.includes(c[0])||d[1]>0&&o.includes(c[1])||d[2]>0&&o.includes(c[2])||d[3]>0&&o.includes(c[3]))continue;let p=t[s],m=r[s];if(p[0]>0&&o.includes(m[0])||p[1]>0&&o.includes(m[1])||p[2]>0&&o.includes(m[2])||p[3]>0&&o.includes(m[3]))continue;let M=t[l],h=r[l];M[0]>0&&o.includes(h[0])||M[1]>0&&o.includes(h[1])||M[2]>0&&o.includes(h[2])||M[3]>0&&o.includes(h[3])||(e[i++]=u,e[i++]=s,e[i++]=l)}return i}_createErasedMesh(e,t){let r=new w.SkinnedMesh(e.geometry.clone(),e.material);r.name=`${e.name}(erase)`,r.frustumCulled=e.frustumCulled,r.layers.set(this._firstPersonOnlyLayer);let o=r.geometry,i=o.getAttribute("skinIndex"),n=i instanceof w.GLBufferAttribute?[]:i.array,u=[];for(let h=0;h<n.length;h+=4)u.push([n[h],n[h+1],n[h+2],n[h+3]]);let s=o.getAttribute("skinWeight"),l=s instanceof w.GLBufferAttribute?[]:s.array,d=[];for(let h=0;h<l.length;h+=4)d.push([l[h],l[h+1],l[h+2],l[h+3]]);let c=o.getIndex();if(!c)throw new Error("The geometry doesn't have an index buffer");let p=Array.from(c.array),m=this._excludeTriangles(p,d,u,t),M=[];for(let h=0;h<m;h++)M[h]=p[h];return o.setIndex(M),e.onBeforeRender&&(r.onBeforeRender=e.onBeforeRender),r.bind(new w.Skeleton(e.skeleton.bones,e.skeleton.boneInverses),new w.Matrix4),r}_createHeadlessModelForSkinnedMesh(e,t){let r=[];if(t.skeleton.bones.forEach((i,n)=>{this._isEraseTarget(i)&&r.push(n)}),!r.length){t.layers.enable(this._thirdPersonOnlyLayer),t.layers.enable(this._firstPersonOnlyLayer);return}t.layers.set(this._thirdPersonOnlyLayer);let o=this._createErasedMesh(t,r);e.add(o)}_createHeadlessModel(e){if(e.type==="Group")if(e.layers.set(this._thirdPersonOnlyLayer),this._isEraseTarget(e))e.traverse(t=>t.layers.set(this._thirdPersonOnlyLayer));else{let t=new w.Group;t.name=`_headless_${e.name}`,t.layers.set(this._firstPersonOnlyLayer),e.parent.add(t),e.children.filter(r=>r.type==="SkinnedMesh").forEach(r=>{let o=r;this._createHeadlessModelForSkinnedMesh(t,o)})}else if(e.type==="SkinnedMesh"){let t=e;this._createHeadlessModelForSkinnedMesh(e.parent,t)}else this._isEraseTarget(e)&&(e.layers.set(this._thirdPersonOnlyLayer),e.traverse(t=>t.layers.set(this._thirdPersonOnlyLayer)))}_isEraseTarget(e){return e===this.humanoid.getRawBoneNode("head")?!0:e.parent?this._isEraseTarget(e.parent):!1}};U.DEFAULT_FIRSTPERSON_ONLY_LAYER=9,U.DEFAULT_THIRDPERSON_ONLY_LAYER=10;var Z=U;var Et=new Set(["1.0","1.0-beta"]),ie=class{get name(){return"VRMFirstPersonLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return R(this,null,function*(){let t=e.userData.vrmHumanoid;if(t!==null){if(t===void 0)throw new Error("VRMFirstPersonLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");e.userData.vrmFirstPerson=yield this._import(e,t)}})}_import(e,t){return R(this,null,function*(){if(t==null)return null;let r=yield this._v1Import(e,t);if(r)return r;let o=yield this._v0Import(e,t);return o||null})}_v1Import(e,t){return R(this,null,function*(){var d,c;let r=this.parser.json;if(!(((d=r.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let i=(c=r.extensions)==null?void 0:c.VRMC_vrm;if(!i)return null;let n=i.specVersion;if(!Et.has(n))return console.warn(`VRMFirstPersonLoaderPlugin: Unknown VRMC_vrm specVersion "${n}"`),null;let u=i.firstPerson,s=[],l=yield Ie(e);return Array.from(l.entries()).forEach(([p,m])=>{var h,f;let M=(h=u==null?void 0:u.meshAnnotations)==null?void 0:h.find(V=>V.node===p);s.push({meshes:m,type:(f=M==null?void 0:M.type)!=null?f:"auto"})}),new Z(t,s)})}_v0Import(e,t){return R(this,null,function*(){var s;let r=this.parser.json,o=(s=r.extensions)==null?void 0:s.VRM;if(!o)return null;let i=o.firstPerson;if(!i)return null;let n=[],u=yield Ie(e);return Array.from(u.entries()).forEach(([l,d])=>{let c=r.nodes[l],p=i.meshAnnotations?i.meshAnnotations.find(m=>m.mesh===c.mesh):void 0;n.push({meshes:d,type:this._convertV0FlagToV1Type(p==null?void 0:p.firstPersonFlag)})}),new Z(t,n)})}_convertV0FlagToV1Type(e){return e==="FirstPersonOnly"?"firstPersonOnly":e==="ThirdPersonOnly"?"thirdPersonOnly":e==="Both"?"both":"auto"}};var Xe={Auto:"auto",Both:"both",ThirdPersonOnly:"thirdPersonOnly",FirstPersonOnly:"firstPersonOnly"};var O=T(require("three"),1),Ze=new O.Vector3,Je=new O.Vector3,gt=new O.Quaternion,J=class extends O.Group{constructor(e){super(),this.vrmHumanoid=e,this._boneAxesMap=new Map,Object.values(e.humanBones).forEach(t=>{let r=new O.AxesHelper(1);r.matrixAutoUpdate=!1,r.material.depthTest=!1,r.material.depthWrite=!1,this.add(r),this._boneAxesMap.set(t,r)})}dispose(){Array.from(this._boneAxesMap.values()).forEach(e=>{e.geometry.dispose(),e.material.dispose()})}updateMatrixWorld(e){Array.from(this._boneAxesMap.entries()).forEach(([t,r])=>{t.node.updateWorldMatrix(!0,!1),t.node.matrixWorld.decompose(Ze,gt,Je);let o=Ze.set(.1,.1,.1).divide(Je);r.matrix.copy(t.node.matrixWorld).scale(o)}),super.updateMatrixWorld(e)}};var se=["hips","spine","chest","upperChest","neck","head","leftEye","rightEye","jaw","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftThumbMetacarpal","leftThumbProximal","leftThumbDistal","leftIndexProximal","leftIndexIntermediate","leftIndexDistal","leftMiddleProximal","leftMiddleIntermediate","leftMiddleDistal","leftRingProximal","leftRingIntermediate","leftRingDistal","leftLittleProximal","leftLittleIntermediate","leftLittleDistal","rightThumbMetacarpal","rightThumbProximal","rightThumbDistal","rightIndexProximal","rightIndexIntermediate","rightIndexDistal","rightMiddleProximal","rightMiddleIntermediate","rightMiddleDistal","rightRingProximal","rightRingIntermediate","rightRingDistal","rightLittleProximal","rightLittleIntermediate","rightLittleDistal"];var Ke={Hips:"hips",Spine:"spine",Chest:"chest",UpperChest:"upperChest",Neck:"neck",Head:"head",LeftEye:"leftEye",RightEye:"rightEye",Jaw:"jaw",LeftUpperLeg:"leftUpperLeg",LeftLowerLeg:"leftLowerLeg",LeftFoot:"leftFoot",LeftToes:"leftToes",RightUpperLeg:"rightUpperLeg",RightLowerLeg:"rightLowerLeg",RightFoot:"rightFoot",RightToes:"rightToes",LeftShoulder:"leftShoulder",LeftUpperArm:"leftUpperArm",LeftLowerArm:"leftLowerArm",LeftHand:"leftHand",RightShoulder:"rightShoulder",RightUpperArm:"rightUpperArm",RightLowerArm:"rightLowerArm",RightHand:"rightHand",LeftThumbMetacarpal:"leftThumbMetacarpal",LeftThumbProximal:"leftThumbProximal",LeftThumbDistal:"leftThumbDistal",LeftIndexProximal:"leftIndexProximal",LeftIndexIntermediate:"leftIndexIntermediate",LeftIndexDistal:"leftIndexDistal",LeftMiddleProximal:"leftMiddleProximal",LeftMiddleIntermediate:"leftMiddleIntermediate",LeftMiddleDistal:"leftMiddleDistal",LeftRingProximal:"leftRingProximal",LeftRingIntermediate:"leftRingIntermediate",LeftRingDistal:"leftRingDistal",LeftLittleProximal:"leftLittleProximal",LeftLittleIntermediate:"leftLittleIntermediate",LeftLittleDistal:"leftLittleDistal",RightThumbMetacarpal:"rightThumbMetacarpal",RightThumbProximal:"rightThumbProximal",RightThumbDistal:"rightThumbDistal",RightIndexProximal:"rightIndexProximal",RightIndexIntermediate:"rightIndexIntermediate",RightIndexDistal:"rightIndexDistal",RightMiddleProximal:"rightMiddleProximal",RightMiddleIntermediate:"rightMiddleIntermediate",RightMiddleDistal:"rightMiddleDistal",RightRingProximal:"rightRingProximal",RightRingIntermediate:"rightRingIntermediate",RightRingDistal:"rightRingDistal",RightLittleProximal:"rightLittleProximal",RightLittleIntermediate:"rightLittleIntermediate",RightLittleDistal:"rightLittleDistal"};var He={hips:null,spine:"hips",chest:"spine",upperChest:"chest",neck:"upperChest",head:"neck",leftEye:"head",rightEye:"head",jaw:"head",leftUpperLeg:"hips",leftLowerLeg:"leftUpperLeg",leftFoot:"leftLowerLeg",leftToes:"leftFoot",rightUpperLeg:"hips",rightLowerLeg:"rightUpperLeg",rightFoot:"rightLowerLeg",rightToes:"rightFoot",leftShoulder:"upperChest",leftUpperArm:"leftShoulder",leftLowerArm:"leftUpperArm",leftHand:"leftLowerArm",rightShoulder:"upperChest",rightUpperArm:"rightShoulder",rightLowerArm:"rightUpperArm",rightHand:"rightLowerArm",leftThumbMetacarpal:"leftHand",leftThumbProximal:"leftThumbMetacarpal",leftThumbDistal:"leftThumbProximal",leftIndexProximal:"leftHand",leftIndexIntermediate:"leftIndexProximal",leftIndexDistal:"leftIndexIntermediate",leftMiddleProximal:"leftHand",leftMiddleIntermediate:"leftMiddleProximal",leftMiddleDistal:"leftMiddleIntermediate",leftRingProximal:"leftHand",leftRingIntermediate:"leftRingProximal",leftRingDistal:"leftRingIntermediate",leftLittleProximal:"leftHand",leftLittleIntermediate:"leftLittleProximal",leftLittleDistal:"leftLittleIntermediate",rightThumbMetacarpal:"rightHand",rightThumbProximal:"rightThumbMetacarpal",rightThumbDistal:"rightThumbProximal",rightIndexProximal:"rightHand",rightIndexIntermediate:"rightIndexProximal",rightIndexDistal:"rightIndexIntermediate",rightMiddleProximal:"rightHand",rightMiddleIntermediate:"rightMiddleProximal",rightMiddleDistal:"rightMiddleIntermediate",rightRingProximal:"rightHand",rightRingIntermediate:"rightRingProximal",rightRingDistal:"rightRingIntermediate",rightLittleProximal:"rightHand",rightLittleIntermediate:"rightLittleProximal",rightLittleDistal:"rightLittleIntermediate"};var Pe=T(require("three"),1);function Le(a){return a.invert?a.invert():a.inverse(),a}var K=new Pe.Vector3,ee=new Pe.Quaternion,te=class{constructor(e){this.humanBones=e,this.restPose=this.getAbsolutePose()}getAbsolutePose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let r=t,o=this.getBoneNode(r);o&&(K.copy(o.position),ee.copy(o.quaternion),e[r]={position:K.toArray(),rotation:ee.toArray()})}),e}getPose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let r=t,o=this.getBoneNode(r);if(!o)return;K.set(0,0,0),ee.identity();let i=this.restPose[r];i!=null&&i.position&&K.fromArray(i.position).negate(),i!=null&&i.rotation&&Le(ee.fromArray(i.rotation)),K.add(o.position),ee.premultiply(o.quaternion),e[r]={position:K.toArray(),rotation:ee.toArray()}}),e}setPose(e){Object.entries(e).forEach(([t,r])=>{let o=t,i=this.getBoneNode(o);if(!i)return;let n=this.restPose[o];n&&(r!=null&&r.position&&(i.position.fromArray(r.position),n.position&&i.position.add(K.fromArray(n.position))),r!=null&&r.rotation&&(i.quaternion.fromArray(r.rotation),n.rotation&&i.quaternion.multiply(ee.fromArray(n.rotation))))})}resetPose(){Object.entries(this.restPose).forEach(([e,t])=>{let r=this.getBoneNode(e);r&&(t!=null&&t.position&&r.position.fromArray(t.position),t!=null&&t.rotation&&r.quaternion.fromArray(t.rotation))})}getBone(e){var t;return(t=this.humanBones[e])!=null?t:void 0}getBoneNode(e){var t,r;return(r=(t=this.humanBones[e])==null?void 0:t.node)!=null?r:null}};var v=T(require("three"),1);var Ue=new v.Vector3,Vt=new v.Quaternion,yt=new v.Vector3,Re=class a extends te{static _setupTransforms(e){let t=new v.Object3D;t.name="VRMHumanoidRig";let r={},o={},i={},n={};se.forEach(s=>{var d;let l=e.getBoneNode(s);if(l){let c=new v.Vector3,p=new v.Quaternion;l.updateWorldMatrix(!0,!1),l.matrixWorld.decompose(c,p,Ue),r[s]=c,o[s]=p,i[s]=l.quaternion.clone();let m=new v.Quaternion;(d=l.parent)==null||d.matrixWorld.decompose(Ue,m,Ue),n[s]=m}});let u={};return se.forEach(s=>{var d;let l=e.getBoneNode(s);if(l){let c=r[s],p=s,m;for(;m==null&&(p=He[p],p!=null);)m=r[p];let M=new v.Object3D;M.name="Normalized_"+l.name,(p?(d=u[p])==null?void 0:d.node:t).add(M),M.position.copy(c),m&&M.position.sub(m),u[s]={node:M}}}),{rigBones:u,root:t,parentWorldRotations:n,boneRotations:i}}constructor(e){let{rigBones:t,root:r,parentWorldRotations:o,boneRotations:i}=a._setupTransforms(e);super(t),this.original=e,this.root=r,this._parentWorldRotations=o,this._boneRotations=i}update(){se.forEach(e=>{let t=this.original.getBoneNode(e);if(t!=null){let r=this.getBoneNode(e),o=this._parentWorldRotations[e],i=Vt.copy(o).invert(),n=this._boneRotations[e];if(t.quaternion.copy(r.quaternion).multiply(o).premultiply(i).multiply(n),e==="hips"){let u=r.getWorldPosition(yt);t.parent.updateWorldMatrix(!0,!1);let s=t.parent.matrixWorld,l=u.applyMatrix4(s.invert());t.position.copy(l)}}})}};var re=class a{get restPose(){return console.warn("VRMHumanoid: restPose is deprecated. Use either rawRestPose or normalizedRestPose instead."),this.rawRestPose}get rawRestPose(){return this._rawHumanBones.restPose}get normalizedRestPose(){return this._normalizedHumanBones.restPose}get humanBones(){return this._rawHumanBones.humanBones}get rawHumanBones(){return this._rawHumanBones.humanBones}get normalizedHumanBones(){return this._normalizedHumanBones.humanBones}get normalizedHumanBonesRoot(){return this._normalizedHumanBones.root}constructor(e,t){var r;this.autoUpdateHumanBones=(r=t==null?void 0:t.autoUpdateHumanBones)!=null?r:!0,this._rawHumanBones=new te(e),this._normalizedHumanBones=new Re(this._rawHumanBones)}copy(e){return this.autoUpdateHumanBones=e.autoUpdateHumanBones,this._rawHumanBones=new te(e.humanBones),this._normalizedHumanBones=new Re(this._rawHumanBones),this}clone(){return new a(this.humanBones,{autoUpdateHumanBones:this.autoUpdateHumanBones}).copy(this)}getAbsolutePose(){return console.warn("VRMHumanoid: getAbsolutePose() is deprecated. Use either getRawAbsolutePose() or getNormalizedAbsolutePose() instead."),this.getRawAbsolutePose()}getRawAbsolutePose(){return this._rawHumanBones.getAbsolutePose()}getNormalizedAbsolutePose(){return this._normalizedHumanBones.getAbsolutePose()}getPose(){return console.warn("VRMHumanoid: getPose() is deprecated. Use either getRawPose() or getNormalizedPose() instead."),this.getRawPose()}getRawPose(){return this._rawHumanBones.getPose()}getNormalizedPose(){return this._normalizedHumanBones.getPose()}setPose(e){return console.warn("VRMHumanoid: setPose() is deprecated. Use either setRawPose() or setNormalizedPose() instead."),this.setRawPose(e)}setRawPose(e){return this._rawHumanBones.setPose(e)}setNormalizedPose(e){return this._normalizedHumanBones.setPose(e)}resetPose(){return console.warn("VRMHumanoid: resetPose() is deprecated. Use either resetRawPose() or resetNormalizedPose() instead."),this.resetRawPose()}resetRawPose(){return this._rawHumanBones.resetPose()}resetNormalizedPose(){return this._normalizedHumanBones.resetPose()}getBone(e){return console.warn("VRMHumanoid: getBone() is deprecated. Use either getRawBone() or getNormalizedBone() instead."),this.getRawBone(e)}getRawBone(e){return this._rawHumanBones.getBone(e)}getNormalizedBone(e){return this._normalizedHumanBones.getBone(e)}getBoneNode(e){return console.warn("VRMHumanoid: getBoneNode() is deprecated. Use either getRawBoneNode() or getNormalizedBoneNode() instead."),this.getRawBoneNode(e)}getRawBoneNode(e){return this._rawHumanBones.getBoneNode(e)}getNormalizedBoneNode(e){return this._normalizedHumanBones.getBoneNode(e)}update(){this.autoUpdateHumanBones&&this._normalizedHumanBones.update()}};var _e={Hips:"hips",Spine:"spine",Head:"head",LeftUpperLeg:"leftUpperLeg",LeftLowerLeg:"leftLowerLeg",LeftFoot:"leftFoot",RightUpperLeg:"rightUpperLeg",RightLowerLeg:"rightLowerLeg",RightFoot:"rightFoot",LeftUpperArm:"leftUpperArm",LeftLowerArm:"leftLowerArm",LeftHand:"leftHand",RightUpperArm:"rightUpperArm",RightLowerArm:"rightLowerArm",RightHand:"rightHand"};var xt=new Set(["1.0","1.0-beta"]),et={leftThumbProximal:"leftThumbMetacarpal",leftThumbIntermediate:"leftThumbProximal",rightThumbProximal:"rightThumbMetacarpal",rightThumbIntermediate:"rightThumbProximal"},ae=class{get name(){return"VRMHumanoidLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot,this.autoUpdateHumanBones=t==null?void 0:t.autoUpdateHumanBones}afterRoot(e){return R(this,null,function*(){e.userData.vrmHumanoid=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let r=yield this._v0Import(e);return r||null})}_v1Import(e){return R(this,null,function*(){var d,c;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(!o)return null;let i=o.specVersion;if(!xt.has(i))return console.warn(`VRMHumanoidLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.humanoid;if(!n)return null;let u=n.humanBones.leftThumbIntermediate!=null||n.humanBones.rightThumbIntermediate!=null,s={};n.humanBones!=null&&(yield Promise.all(Object.entries(n.humanBones).map(M=>R(this,[M],function*([p,m]){let h=p,f=m.node;if(u){let x=et[h];x!=null&&(h=x)}let V=yield this.parser.getDependency("node",f);if(V==null){console.warn(`A glTF node bound to the humanoid bone ${h} (index = ${f}) does not exist`);return}s[h]={node:V}}))));let l=new re(this._ensureRequiredBonesExist(s),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(l.normalizedHumanBonesRoot),this.helperRoot){let p=new J(l);this.helperRoot.add(p),p.renderOrder=this.helperRoot.renderOrder}return l})}_v0Import(e){return R(this,null,function*(){var u;let r=(u=this.parser.json.extensions)==null?void 0:u.VRM;if(!r)return null;let o=r.humanoid;if(!o)return null;let i={};o.humanBones!=null&&(yield Promise.all(o.humanBones.map(s=>R(this,null,function*(){let l=s.bone,d=s.node;if(l==null||d==null)return;let c=yield this.parser.getDependency("node",d);if(c==null){console.warn(`A glTF node bound to the humanoid bone ${l} (index = ${d}) does not exist`);return}let p=et[l],m=p!=null?p:l;if(i[m]!=null){console.warn(`Multiple bone entries for ${m} detected (index = ${d}), ignoring duplicated entries.`);return}i[m]={node:c}}))));let n=new re(this._ensureRequiredBonesExist(i),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(n.normalizedHumanBonesRoot),this.helperRoot){let s=new J(n);this.helperRoot.add(s),s.renderOrder=this.helperRoot.renderOrder}return n})}_ensureRequiredBonesExist(e){let t=Object.values(_e).filter(r=>e[r]==null);if(t.length>0)throw new Error(`VRMHumanoidLoaderPlugin: These humanoid bones are required but not exist: ${t.join(", ")}`);return e}};var E=T(require("three"),1);var fe=T(require("three"),1),Me=class extends fe.BufferGeometry{constructor(){super();this._currentTheta=0;this._currentRadius=0;this.theta=0,this.radius=0,this._currentTheta=0,this._currentRadius=0,this._attrPos=new fe.BufferAttribute(new Float32Array(195),3),this.setAttribute("position",this._attrPos),this._attrIndex=new fe.BufferAttribute(new Uint16Array(189),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentTheta!==this.theta&&(this._currentTheta=this.theta,t=!0),this._currentRadius!==this.radius&&(this._currentRadius=this.radius,t=!0),t&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,0,0,0);for(let t=0;t<64;t++){let r=t/63*this._currentTheta;this._attrPos.setXYZ(t+1,this._currentRadius*Math.sin(r),0,this._currentRadius*Math.cos(r))}this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<63;t++)this._attrIndex.setXYZ(t*3,0,t+1,t+2);this._attrIndex.needsUpdate=!0}};var C=T(require("three"),1),Ae=class extends C.BufferGeometry{constructor(){super(),this.radius=0,this._currentRadius=0,this.tail=new C.Vector3,this._currentTail=new C.Vector3,this._attrPos=new C.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new C.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;this._currentRadius!==this.radius&&(this._currentRadius=this.radius,e=!0),this._currentTail.equals(this.tail)||(this._currentTail.copy(this.tail),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){let t=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(t),Math.sin(t),0),this._attrPos.setXYZ(32+e,0,Math.cos(t),Math.sin(t)),this._attrPos.setXYZ(64+e,Math.sin(t),0,Math.cos(t))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<32;e++){let t=(e+1)%32;this._attrIndex.setXY(e*2,e,t),this._attrIndex.setXY(64+e*2,32+e,32+t),this._attrIndex.setXY(128+e*2,64+e,64+t)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}};var we=new E.Quaternion,tt=new E.Quaternion,Ee=new E.Vector3,rt=new E.Vector3,ot=Math.sqrt(2)/2,Tt=new E.Quaternion(0,0,-ot,ot),bt=new E.Vector3(0,1,0),le=class extends E.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.vrmLookAt=e;{let t=new Me;t.radius=.5;let r=new E.MeshBasicMaterial({color:65280,transparent:!0,opacity:.5,side:E.DoubleSide,depthTest:!1,depthWrite:!1});this._meshPitch=new E.Mesh(t,r),this.add(this._meshPitch)}{let t=new Me;t.radius=.5;let r=new E.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.5,side:E.DoubleSide,depthTest:!1,depthWrite:!1});this._meshYaw=new E.Mesh(t,r),this.add(this._meshYaw)}{let t=new Ae;t.radius=.1;let r=new E.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1});this._lineTarget=new E.LineSegments(t,r),this._lineTarget.frustumCulled=!1,this.add(this._lineTarget)}}dispose(){this._meshYaw.geometry.dispose(),this._meshYaw.material.dispose(),this._meshPitch.geometry.dispose(),this._meshPitch.material.dispose(),this._lineTarget.geometry.dispose(),this._lineTarget.material.dispose()}updateMatrixWorld(e){let t=E.MathUtils.DEG2RAD*this.vrmLookAt.yaw;this._meshYaw.geometry.theta=t,this._meshYaw.geometry.update();let r=E.MathUtils.DEG2RAD*this.vrmLookAt.pitch;this._meshPitch.geometry.theta=r,this._meshPitch.geometry.update(),this.vrmLookAt.getLookAtWorldPosition(Ee),this.vrmLookAt.getLookAtWorldQuaternion(we),we.multiply(this.vrmLookAt.getFaceFrontQuaternion(tt)),this._meshYaw.position.copy(Ee),this._meshYaw.quaternion.copy(we),this._meshPitch.position.copy(Ee),this._meshPitch.quaternion.copy(we),this._meshPitch.quaternion.multiply(tt.setFromAxisAngle(bt,t)),this._meshPitch.quaternion.multiply(Tt);let{target:o,autoUpdate:i}=this.vrmLookAt;o!=null&&i&&(o.getWorldPosition(rt).sub(Ee),this._lineTarget.geometry.tail.copy(rt),this._lineTarget.geometry.update(),this._lineTarget.position.copy(Ee)),super.updateMatrixWorld(e)}};var y=T(require("three"),1);var Oe=T(require("three"),1),Ht=new Oe.Vector3,Lt=new Oe.Vector3;function ge(a,e){return a.matrixWorld.decompose(Ht,e,Lt),e}function ue(a){return[Math.atan2(-a.z,a.x),Math.atan2(a.y,Math.sqrt(a.x*a.x+a.z*a.z))]}function Se(a){let e=Math.round(a/2/Math.PI);return a-2*Math.PI*e}var nt=new y.Vector3(0,0,1),Pt=new y.Vector3,_t=new y.Vector3,At=new y.Vector3,wt=new y.Quaternion,De=new y.Quaternion,it=new y.Quaternion,vt=new y.Quaternion,Ge=new y.Euler,ve=class ve{constructor(e,t){this.offsetFromHeadBone=new y.Vector3;this.autoUpdate=!0;this.faceFront=new y.Vector3(0,0,1);this.humanoid=e,this.applier=t,this._yaw=0,this._pitch=0,this._needsUpdate=!0,this._restHeadWorldQuaternion=this.getLookAtWorldQuaternion(new y.Quaternion)}get yaw(){return this._yaw}set yaw(e){this._yaw=e,this._needsUpdate=!0}get pitch(){return this._pitch}set pitch(e){this._pitch=e,this._needsUpdate=!0}get euler(){return console.warn("VRMLookAt: euler is deprecated. use getEuler() instead."),this.getEuler(new y.Euler)}getEuler(e){return e.set(y.MathUtils.DEG2RAD*this._pitch,y.MathUtils.DEG2RAD*this._yaw,0,"YXZ")}copy(e){if(this.humanoid!==e.humanoid)throw new Error("VRMLookAt: humanoid must be same in order to copy");return this.offsetFromHeadBone.copy(e.offsetFromHeadBone),this.applier=e.applier,this.autoUpdate=e.autoUpdate,this.target=e.target,this.faceFront.copy(e.faceFront),this}clone(){return new ve(this.humanoid,this.applier).copy(this)}reset(){this._yaw=0,this._pitch=0,this._needsUpdate=!0}getLookAtWorldPosition(e){let t=this.humanoid.getRawBoneNode("head");return e.copy(this.offsetFromHeadBone).applyMatrix4(t.matrixWorld)}getLookAtWorldQuaternion(e){let t=this.humanoid.getRawBoneNode("head");return ge(t,e)}getFaceFrontQuaternion(e){if(this.faceFront.distanceToSquared(nt)<.01)return e.copy(this._restHeadWorldQuaternion).invert();let[t,r]=ue(this.faceFront);return Ge.set(0,.5*Math.PI+t,r,"YZX"),e.setFromEuler(Ge).premultiply(vt.copy(this._restHeadWorldQuaternion).invert())}getLookAtWorldDirection(e){return this.getLookAtWorldQuaternion(De),this.getFaceFrontQuaternion(it),e.copy(nt).applyQuaternion(De).applyQuaternion(it).applyEuler(this.getEuler(Ge))}lookAt(e){let t=wt.copy(this._restHeadWorldQuaternion).multiply(Le(this.getLookAtWorldQuaternion(De))),r=this.getLookAtWorldPosition(_t),o=At.copy(e).sub(r).applyQuaternion(t).normalize(),[i,n]=ue(this.faceFront),[u,s]=ue(o),l=Se(u-i),d=Se(n-s);this._yaw=y.MathUtils.RAD2DEG*l,this._pitch=y.MathUtils.RAD2DEG*d,this._needsUpdate=!0}update(e){this.target!=null&&this.autoUpdate&&this.lookAt(this.target.getWorldPosition(Pt)),this._needsUpdate&&(this._needsUpdate=!1,this.applier.applyYawPitch(this._yaw,this._pitch))}};ve.EULER_ORDER="YXZ";var pe=ve;var g=T(require("three"),1);var Bt=new g.Vector3(0,0,1),F=new g.Quaternion,me=new g.Quaternion,_=new g.Euler(0,0,0,"YXZ"),S=class{constructor(e,t,r,o,i){this.humanoid=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=r,this.rangeMapVerticalDown=o,this.rangeMapVerticalUp=i,this.faceFront=new g.Vector3(0,0,1),this._restQuatLeftEye=new g.Quaternion,this._restQuatRightEye=new g.Quaternion,this._restLeftEyeParentWorldQuat=new g.Quaternion,this._restRightEyeParentWorldQuat=new g.Quaternion;let n=this.humanoid.getRawBoneNode("leftEye"),u=this.humanoid.getRawBoneNode("rightEye");n&&(this._restQuatLeftEye.copy(n.quaternion),ge(n.parent,this._restLeftEyeParentWorldQuat)),u&&(this._restQuatRightEye.copy(u.quaternion),ge(u.parent,this._restRightEyeParentWorldQuat))}applyYawPitch(e,t){let r=this.humanoid.getRawBoneNode("leftEye"),o=this.humanoid.getRawBoneNode("rightEye"),i=this.humanoid.getNormalizedBoneNode("leftEye"),n=this.humanoid.getNormalizedBoneNode("rightEye");r&&(t<0?_.x=-g.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):_.x=g.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?_.y=-g.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(-e):_.y=g.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(e),F.setFromEuler(_),this._getWorldFaceFrontQuat(me),i.quaternion.copy(me).multiply(F).multiply(me.invert()),F.copy(this._restLeftEyeParentWorldQuat),r.quaternion.copy(i.quaternion).multiply(F).premultiply(F.invert()).multiply(this._restQuatLeftEye)),o&&(t<0?_.x=-g.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):_.x=g.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?_.y=-g.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(-e):_.y=g.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(e),F.setFromEuler(_),this._getWorldFaceFrontQuat(me),n.quaternion.copy(me).multiply(F).multiply(me.invert()),F.copy(this._restRightEyeParentWorldQuat),o.quaternion.copy(n.quaternion).multiply(F).premultiply(F.invert()).multiply(this._restQuatRightEye))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=g.MathUtils.RAD2DEG*e.y,r=g.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,r)}_getWorldFaceFrontQuat(e){if(this.faceFront.distanceToSquared(Bt)<.01)return e.identity();let[t,r]=ue(this.faceFront);return _.set(0,.5*Math.PI+t,r,"YZX"),e.setFromEuler(_)}};S.type="bone";var Ce=T(require("three"),1),W=class{constructor(e,t,r,o,i){this.expressions=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=r,this.rangeMapVerticalDown=o,this.rangeMapVerticalUp=i}applyYawPitch(e,t){t<0?(this.expressions.setValue("lookDown",0),this.expressions.setValue("lookUp",this.rangeMapVerticalUp.map(-t))):(this.expressions.setValue("lookUp",0),this.expressions.setValue("lookDown",this.rangeMapVerticalDown.map(t))),e<0?(this.expressions.setValue("lookLeft",0),this.expressions.setValue("lookRight",this.rangeMapHorizontalOuter.map(-e))):(this.expressions.setValue("lookRight",0),this.expressions.setValue("lookLeft",this.rangeMapHorizontalOuter.map(e)))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=Ce.MathUtils.RAD2DEG*e.y,r=Ce.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,r)}};W.type="expression";var oe=class{constructor(e,t){this.inputMaxValue=e,this.outputScale=t}map(e){return this.outputScale*ye(e/this.inputMaxValue)}};var kt=new Set(["1.0","1.0-beta"]),Be=.01,de=class{get name(){return"VRMLookAtLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot}afterRoot(e){return R(this,null,function*(){let t=e.userData.vrmHumanoid;if(t===null)return;if(t===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");let r=e.userData.vrmExpressionManager;if(r!==null){if(r===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmExpressionManager is undefined. VRMExpressionLoaderPlugin have to be used first");e.userData.vrmLookAt=yield this._import(e,t,r)}})}_import(e,t,r){return R(this,null,function*(){if(t==null||r==null)return null;let o=yield this._v1Import(e,t,r);if(o)return o;let i=yield this._v0Import(e,t,r);return i||null})}_v1Import(e,t,r){return R(this,null,function*(){var f,V,x;let o=this.parser.json;if(!(((f=o.extensionsUsed)==null?void 0:f.indexOf("VRMC_vrm"))!==-1))return null;let n=(V=o.extensions)==null?void 0:V.VRMC_vrm;if(!n)return null;let u=n.specVersion;if(!kt.has(u))return console.warn(`VRMLookAtLoaderPlugin: Unknown VRMC_vrm specVersion "${u}"`),null;let s=n.lookAt;if(!s)return null;let l=s.type==="expression"?1:10,d=this._v1ImportRangeMap(s.rangeMapHorizontalInner,l),c=this._v1ImportRangeMap(s.rangeMapHorizontalOuter,l),p=this._v1ImportRangeMap(s.rangeMapVerticalDown,l),m=this._v1ImportRangeMap(s.rangeMapVerticalUp,l),M;s.type==="expression"?M=new W(r,d,c,p,m):M=new S(t,d,c,p,m);let h=this._importLookAt(t,M);return h.offsetFromHeadBone.fromArray((x=s.offsetFromHeadBone)!=null?x:[0,.06,0]),h})}_v1ImportRangeMap(e,t){var i,n;let r=(i=e==null?void 0:e.inputMaxValue)!=null?i:90,o=(n=e==null?void 0:e.outputScale)!=null?n:t;return r<Be&&(console.warn("VRMLookAtLoaderPlugin: inputMaxValue of a range map is too small. Consider reviewing the range map!"),r=Be),new oe(r,o)}_v0Import(e,t,r){return R(this,null,function*(){var M,h,f,V;let i=(M=this.parser.json.extensions)==null?void 0:M.VRM;if(!i)return null;let n=i.firstPerson;if(!n)return null;let u=n.lookAtTypeName==="BlendShape"?1:10,s=this._v0ImportDegreeMap(n.lookAtHorizontalInner,u),l=this._v0ImportDegreeMap(n.lookAtHorizontalOuter,u),d=this._v0ImportDegreeMap(n.lookAtVerticalDown,u),c=this._v0ImportDegreeMap(n.lookAtVerticalUp,u),p;n.lookAtTypeName==="BlendShape"?p=new W(r,s,l,d,c):p=new S(t,s,l,d,c);let m=this._importLookAt(t,p);return n.firstPersonBoneOffset?m.offsetFromHeadBone.set((h=n.firstPersonBoneOffset.x)!=null?h:0,(f=n.firstPersonBoneOffset.y)!=null?f:.06,-((V=n.firstPersonBoneOffset.z)!=null?V:0)):m.offsetFromHeadBone.set(0,.06,0),m.faceFront.set(0,0,-1),p instanceof S&&p.faceFront.set(0,0,-1),m})}_v0ImportDegreeMap(e,t){var n,u;let r=e==null?void 0:e.curve;JSON.stringify(r)!=="[0,0,0,1,1,1,1,0]"&&console.warn("Curves of LookAtDegreeMap defined in VRM 0.0 are not supported");let o=(n=e==null?void 0:e.xRange)!=null?n:90,i=(u=e==null?void 0:e.yRange)!=null?u:t;return o<Be&&(console.warn("VRMLookAtLoaderPlugin: xRange of a degree map is too small. Consider reviewing the degree map!"),o=Be),new oe(o,i)}_importLookAt(e,t){let r=new pe(e,t);if(this.helperRoot){let o=new le(r);this.helperRoot.add(o),o.renderOrder=this.helperRoot.renderOrder}return r}};var st={Bone:"bone",Expression:"expression"};var lt=T(require("three"),1);function at(a,e){return typeof a!="string"||a===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(a)&&(e=e.replace(/(^https?:\/\/[^/]+).*/i,"$1")),/^(https?:)?\/\//i.test(a)||/^data:.*,.*$/i.test(a)||/^blob:.*$/i.test(a)?a:e+a)}var Ft=new Set(["1.0","1.0-beta"]),he=class{get name(){return"VRMMetaLoaderPlugin"}constructor(e,t){var r,o,i;this.parser=e,this.needThumbnailImage=(r=t==null?void 0:t.needThumbnailImage)!=null?r:!1,this.acceptLicenseUrls=(o=t==null?void 0:t.acceptLicenseUrls)!=null?o:["https://vrm.dev/licenses/1.0/"],this.acceptV0Meta=(i=t==null?void 0:t.acceptV0Meta)!=null?i:!0}afterRoot(e){return R(this,null,function*(){e.userData.vrmMeta=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t!=null)return t;let r=yield this._v0Import(e);return r!=null?r:null})}_v1Import(e){return R(this,null,function*(){var d,c,p;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(o==null)return null;let i=o.specVersion;if(!Ft.has(i))return console.warn(`VRMMetaLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.meta;if(!n)return null;let u=n.licenseUrl;if(!new Set(this.acceptLicenseUrls).has(u))throw new Error(`VRMMetaLoaderPlugin: The license url "${u}" is not accepted`);let l;return this.needThumbnailImage&&n.thumbnailImage!=null&&(l=(p=yield this._extractGLTFImage(n.thumbnailImage))!=null?p:void 0),{metaVersion:"1",name:n.name,version:n.version,authors:n.authors,copyrightInformation:n.copyrightInformation,contactInformation:n.contactInformation,references:n.references,thirdPartyLicenses:n.thirdPartyLicenses,thumbnailImage:l,licenseUrl:n.licenseUrl,avatarPermission:n.avatarPermission,allowExcessivelyViolentUsage:n.allowExcessivelyViolentUsage,allowExcessivelySexualUsage:n.allowExcessivelySexualUsage,commercialUsage:n.commercialUsage,allowPoliticalOrReligiousUsage:n.allowPoliticalOrReligiousUsage,allowAntisocialOrHateUsage:n.allowAntisocialOrHateUsage,creditNotation:n.creditNotation,allowRedistribution:n.allowRedistribution,modification:n.modification,otherLicenseUrl:n.otherLicenseUrl}})}_v0Import(e){return R(this,null,function*(){var n;let r=(n=this.parser.json.extensions)==null?void 0:n.VRM;if(!r)return null;let o=r.meta;if(!o)return null;if(!this.acceptV0Meta)throw new Error("VRMMetaLoaderPlugin: Attempted to load VRM0.0 meta but acceptV0Meta is false");let i;return this.needThumbnailImage&&o.texture!=null&&o.texture!==-1&&(i=yield this.parser.getDependency("texture",o.texture)),{metaVersion:"0",allowedUserName:o.allowedUserName,author:o.author,commercialUssageName:o.commercialUssageName,contactInformation:o.contactInformation,licenseName:o.licenseName,otherLicenseUrl:o.otherLicenseUrl,otherPermissionUrl:o.otherPermissionUrl,reference:o.reference,sexualUssageName:o.sexualUssageName,texture:i!=null?i:void 0,title:o.title,version:o.version,violentUssageName:o.violentUssageName}})}_extractGLTFImage(e){return R(this,null,function*(){var n;let r=(n=this.parser.json.images)==null?void 0:n[e];if(r==null)return console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image doesn't exist`),null;let o=r.uri;if(r.bufferView!=null){let u=yield this.parser.getDependency("bufferView",r.bufferView),s=new Blob([u],{type:r.mimeType});o=URL.createObjectURL(s)}return o==null?(console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image couldn't load properly`),null):yield new lt.ImageLoader().loadAsync(at(o,this.parser.options.path)).catch(u=>(console.error(u),console.warn("VRMMetaLoaderPlugin: Failed to load a thumbnail image"),null))})}};var ce=class{constructor(e){this.scene=e.scene,this.meta=e.meta,this.humanoid=e.humanoid,this.expressionManager=e.expressionManager,this.firstPerson=e.firstPerson,this.lookAt=e.lookAt}update(e){this.humanoid.update(),this.lookAt&&this.lookAt.update(e),this.expressionManager&&this.expressionManager.update()}};var ke=class{get name(){return"VRMC_vrm"}constructor(e,t){var i,n,u,s,l;this.parser=e;let r=t==null?void 0:t.helperRoot,o=t==null?void 0:t.autoUpdateHumanBones;this.expressionPlugin=(i=t==null?void 0:t.expressionPlugin)!=null?i:new ne(e),this.firstPersonPlugin=(n=t==null?void 0:t.firstPersonPlugin)!=null?n:new ie(e),this.humanoidPlugin=(u=t==null?void 0:t.humanoidPlugin)!=null?u:new ae(e,{helperRoot:r,autoUpdateHumanBones:o}),this.lookAtPlugin=(s=t==null?void 0:t.lookAtPlugin)!=null?s:new de(e,{helperRoot:r}),this.metaPlugin=(l=t==null?void 0:t.metaPlugin)!=null?l:new he(e)}afterRoot(e){return R(this,null,function*(){yield this.metaPlugin.afterRoot(e),yield this.humanoidPlugin.afterRoot(e),yield this.expressionPlugin.afterRoot(e),yield this.lookAtPlugin.afterRoot(e),yield this.firstPersonPlugin.afterRoot(e);let t=e.userData.vrmMeta,r=e.userData.vrmHumanoid;if(t&&r){let o=new ce({scene:e.scene,expressionManager:e.userData.vrmExpressionManager,firstPerson:e.userData.vrmFirstPerson,humanoid:r,lookAt:e.userData.vrmLookAt,meta:t});e.userData.vrmCore=o}})}};
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @pixiv/three-vrm-core v3.4.3-alpha.0
2
+ * @pixiv/three-vrm-core v3.4.3
3
3
  * The implementation of core features of VRM, for @pixiv/three-vrm
4
4
  *
5
5
  * Copyright (c) 2019-2025 pixiv Inc.
@@ -1,2 +1,2 @@
1
1
  /*! (c) 2019-2025 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
2
- var R=(u,e,t)=>new Promise((r,o)=>{var i=s=>{try{l(t.next(s))}catch(a){o(a)}},n=s=>{try{l(t.throw(s))}catch(a){o(a)}},l=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,n);l((t=t.apply(u,e)).next())});import*as Ge from"three";var z=class extends Ge.Object3D{constructor(t){super();this.weight=0;this.isBinary=!1;this.overrideBlink="none";this.overrideLookAt="none";this.overrideMouth="none";this._binds=[];this.name=`VRMExpression_${t}`,this.expressionName=t,this.type="VRMExpression",this.visible=!1}get binds(){return this._binds}get overrideBlinkAmount(){return this.overrideBlink==="block"?0<this.outputWeight?1:0:this.overrideBlink==="blend"?this.outputWeight:0}get overrideLookAtAmount(){return this.overrideLookAt==="block"?0<this.outputWeight?1:0:this.overrideLookAt==="blend"?this.outputWeight:0}get overrideMouthAmount(){return this.overrideMouth==="block"?0<this.outputWeight?1:0:this.overrideMouth==="blend"?this.outputWeight:0}get outputWeight(){return this.isBinary?this.weight>.5?1:0:this.weight}addBind(t){this._binds.push(t)}deleteBind(t){let r=this._binds.indexOf(t);r>=0&&this._binds.splice(r,1)}applyWeight(t){var o;let r=this.outputWeight;r*=(o=t==null?void 0:t.multiplier)!=null?o:1,this.isBinary&&r<1&&(r=0),this._binds.forEach(i=>i.applyWeight(r))}clearAppliedWeight(){this._binds.forEach(t=>t.clearAppliedWeight())}};import*as S from"three";function Ce(u,e,t){var a,d;let r=u.parser.json,o=(a=r.nodes)==null?void 0:a[e];if(o==null)return console.warn(`extractPrimitivesInternal: Attempt to use nodes[${e}] of glTF but the node doesn't exist`),null;let i=o.mesh;if(i==null)return null;let n=(d=r.meshes)==null?void 0:d[i];if(n==null)return console.warn(`extractPrimitivesInternal: Attempt to use meshes[${i}] of glTF but the mesh doesn't exist`),null;let l=n.primitives.length,s=[];return t.traverse(c=>{s.length<l&&c.isMesh&&s.push(c)}),s}function Ae(u,e){return R(this,null,function*(){let t=yield u.parser.getDependency("node",e);return Ce(u,e,t)})}function we(u){return R(this,null,function*(){let e=yield u.parser.getDependencies("node"),t=new Map;return e.forEach((r,o)=>{let i=Ce(u,o,r);i!=null&&t.set(o,i)}),t})}var q={Aa:"aa",Ih:"ih",Ou:"ou",Ee:"ee",Oh:"oh",Blink:"blink",Happy:"happy",Angry:"angry",Sad:"sad",Relaxed:"relaxed",LookUp:"lookUp",Surprised:"surprised",LookDown:"lookDown",LookLeft:"lookLeft",LookRight:"lookRight",BlinkLeft:"blinkLeft",BlinkRight:"blinkRight",Neutral:"neutral"};function ge(u){return Math.max(Math.min(u,1),0)}var Y=class u{constructor(){this.blinkExpressionNames=["blink","blinkLeft","blinkRight"];this.lookAtExpressionNames=["lookLeft","lookRight","lookUp","lookDown"];this.mouthExpressionNames=["aa","ee","ih","oh","ou"];this._expressions=[];this._expressionMap={}}get expressions(){return this._expressions.concat()}get expressionMap(){return Object.assign({},this._expressionMap)}get presetExpressionMap(){let e={},t=new Set(Object.values(q));return Object.entries(this._expressionMap).forEach(([r,o])=>{t.has(r)&&(e[r]=o)}),e}get customExpressionMap(){let e={},t=new Set(Object.values(q));return Object.entries(this._expressionMap).forEach(([r,o])=>{t.has(r)||(e[r]=o)}),e}copy(e){return this._expressions.concat().forEach(r=>{this.unregisterExpression(r)}),e._expressions.forEach(r=>{this.registerExpression(r)}),this.blinkExpressionNames=e.blinkExpressionNames.concat(),this.lookAtExpressionNames=e.lookAtExpressionNames.concat(),this.mouthExpressionNames=e.mouthExpressionNames.concat(),this}clone(){return new u().copy(this)}getExpression(e){var t;return(t=this._expressionMap[e])!=null?t:null}registerExpression(e){this._expressions.push(e),this._expressionMap[e.expressionName]=e}unregisterExpression(e){let t=this._expressions.indexOf(e);t===-1&&console.warn("VRMExpressionManager: The specified expressions is not registered"),this._expressions.splice(t,1),delete this._expressionMap[e.expressionName]}getValue(e){var r;let t=this.getExpression(e);return(r=t==null?void 0:t.weight)!=null?r:null}setValue(e,t){let r=this.getExpression(e);r&&(r.weight=ge(t))}resetValues(){this._expressions.forEach(e=>{e.weight=0})}getExpressionTrackName(e){let t=this.getExpression(e);return t?`${t.name}.weight`:null}update(){let e=this._calculateWeightMultipliers();this._expressions.forEach(t=>{t.clearAppliedWeight()}),this._expressions.forEach(t=>{let r=1,o=t.expressionName;this.blinkExpressionNames.indexOf(o)!==-1&&(r*=e.blink),this.lookAtExpressionNames.indexOf(o)!==-1&&(r*=e.lookAt),this.mouthExpressionNames.indexOf(o)!==-1&&(r*=e.mouth),t.applyWeight({multiplier:r})})}_calculateWeightMultipliers(){let e=1,t=1,r=1;return this._expressions.forEach(o=>{e-=o.overrideBlinkAmount,t-=o.overrideLookAtAmount,r-=o.overrideMouthAmount}),e=Math.max(0,e),t=Math.max(0,t),r=Math.max(0,r),{blink:e,lookAt:t,mouth:r}}};var $={Color:"color",EmissionColor:"emissionColor",ShadeColor:"shadeColor",MatcapColor:"matcapColor",RimColor:"rimColor",OutlineColor:"outlineColor"},We={_Color:$.Color,_EmissionColor:$.EmissionColor,_ShadeColor:$.ShadeColor,_RimColor:$.RimColor,_OutlineColor:$.OutlineColor};import*as ve from"three";var rt=new ve.Color,Ve=class Ve{constructor({material:e,type:t,targetValue:r,targetAlpha:o}){this.material=e,this.type=t,this.targetValue=r,this.targetAlpha=o!=null?o:1;let i=this._initColorBindState(),n=this._initAlphaBindState();this._state={color:i,alpha:n}}applyWeight(e){let{color:t,alpha:r}=this._state;if(t!=null){let{propertyName:o,deltaValue:i}=t,n=this.material[o];n!=null&&n.add(rt.copy(i).multiplyScalar(e))}if(r!=null){let{propertyName:o,deltaValue:i}=r;this.material[o]!=null&&(this.material[o]+=i*e)}}clearAppliedWeight(){let{color:e,alpha:t}=this._state;if(e!=null){let{propertyName:r,initialValue:o}=e,i=this.material[r];i!=null&&i.copy(o)}if(t!=null){let{propertyName:r,initialValue:o}=t;this.material[r]!=null&&(this.material[r]=o)}}_initColorBindState(){var a,d,c;let{material:e,type:t,targetValue:r}=this,o=this._getPropertyNameMap(),i=(d=(a=o==null?void 0:o[t])==null?void 0:a[0])!=null?d:null;if(i==null)return console.warn(`Tried to add a material color bind to the material ${(c=e.name)!=null?c:"(no name)"}, the type ${t} but the material or the type is not supported.`),null;let l=e[i].clone(),s=new ve.Color(r.r-l.r,r.g-l.g,r.b-l.b);return{propertyName:i,initialValue:l,deltaValue:s}}_initAlphaBindState(){var s,a,d;let{material:e,type:t,targetAlpha:r}=this,o=this._getPropertyNameMap(),i=(a=(s=o==null?void 0:o[t])==null?void 0:s[1])!=null?a:null;if(i==null&&r!==1)return console.warn(`Tried to add a material alpha bind to the material ${(d=e.name)!=null?d:"(no name)"}, the type ${t} but the material or the type does not support alpha.`),null;if(i==null)return null;let n=e[i],l=r-n;return{propertyName:i,initialValue:n,deltaValue:l}}_getPropertyNameMap(){var e,t;return(t=(e=Object.entries(Ve._propertyNameMapMap).find(([r])=>this.material[r]===!0))==null?void 0:e[1])!=null?t:null}};Ve._propertyNameMapMap={isMeshStandardMaterial:{color:["color","opacity"],emissionColor:["emissive",null]},isMeshBasicMaterial:{color:["color","opacity"]},isMToonMaterial:{color:["color","opacity"],emissionColor:["emissive",null],outlineColor:["outlineColorFactor",null],matcapColor:["matcapFactor",null],rimColor:["parametricRimColorFactor",null],shadeColor:["shadeColorFactor",null]}};var X=Ve;var Z=class{constructor({primitives:e,index:t,weight:r}){this.primitives=e,this.index=t,this.weight=r}applyWeight(e){this.primitives.forEach(t=>{var r;((r=t.morphTargetInfluences)==null?void 0:r[this.index])!=null&&(t.morphTargetInfluences[this.index]+=this.weight*e)})}clearAppliedWeight(){this.primitives.forEach(e=>{var t;((t=e.morphTargetInfluences)==null?void 0:t[this.index])!=null&&(e.morphTargetInfluences[this.index]=0)})}};import*as Qe from"three";var je=new Qe.Vector2,ye=class ye{constructor({material:e,scale:t,offset:r}){var i,n;this.material=e,this.scale=t,this.offset=r;let o=(i=Object.entries(ye._propertyNamesMap).find(([l])=>e[l]===!0))==null?void 0:i[1];o==null?(console.warn(`Tried to add a texture transform bind to the material ${(n=e.name)!=null?n:"(no name)"} but the material is not supported.`),this._properties=[]):(this._properties=[],o.forEach(l=>{var m;let s=(m=e[l])==null?void 0:m.clone();if(!s)return null;e[l]=s;let a=s.offset.clone(),d=s.repeat.clone(),c=r.clone().sub(a),p=t.clone().sub(d);this._properties.push({name:l,initialOffset:a,deltaOffset:c,initialScale:d,deltaScale:p})}))}applyWeight(e){this._properties.forEach(t=>{let r=this.material[t.name];r!==void 0&&(r.offset.add(je.copy(t.deltaOffset).multiplyScalar(e)),r.repeat.add(je.copy(t.deltaScale).multiplyScalar(e)))})}clearAppliedWeight(){this._properties.forEach(e=>{let t=this.material[e.name];t!==void 0&&(t.offset.copy(e.initialOffset),t.repeat.copy(e.initialScale))})}};ye._propertyNamesMap={isMeshStandardMaterial:["map","emissiveMap","bumpMap","normalMap","displacementMap","roughnessMap","metalnessMap","alphaMap"],isMeshBasicMaterial:["map","specularMap","alphaMap"],isMToonMaterial:["map","normalMap","emissiveMap","shadeMultiplyTexture","rimMultiplyTexture","outlineWidthMultiplyTexture","uvAnimationMaskTexture"]};var J=ye;var ot=new Set(["1.0","1.0-beta"]),xe=class xe{get name(){return"VRMExpressionLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return R(this,null,function*(){e.userData.vrmExpressionManager=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let r=yield this._v0Import(e);return r||null})}_v1Import(e){return R(this,null,function*(){var d,c;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(!o)return null;let i=o.specVersion;if(!ot.has(i))return console.warn(`VRMExpressionLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.expressions;if(!n)return null;let l=new Set(Object.values(q)),s=new Map;n.preset!=null&&Object.entries(n.preset).forEach(([p,m])=>{if(m!=null){if(!l.has(p)){console.warn(`VRMExpressionLoaderPlugin: Unknown preset name "${p}" detected. Ignoring the expression`);return}s.set(p,m)}}),n.custom!=null&&Object.entries(n.custom).forEach(([p,m])=>{if(l.has(p)){console.warn(`VRMExpressionLoaderPlugin: Custom expression cannot have preset name "${p}". Ignoring the expression`);return}s.set(p,m)});let a=new Y;return yield Promise.all(Array.from(s.entries()).map(M=>R(this,[M],function*([p,m]){var f,V,x,_,T,b,F;let h=new z(p);if(e.scene.add(h),h.isBinary=(f=m.isBinary)!=null?f:!1,h.overrideBlink=(V=m.overrideBlink)!=null?V:"none",h.overrideLookAt=(x=m.overrideLookAt)!=null?x:"none",h.overrideMouth=(_=m.overrideMouth)!=null?_:"none",(T=m.morphTargetBinds)==null||T.forEach(H=>R(this,null,function*(){var B;if(H.node===void 0||H.index===void 0)return;let L=yield Ae(e,H.node),v=H.index;if(!L.every(I=>Array.isArray(I.morphTargetInfluences)&&v<I.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${m.name} attempts to index morph #${v} but not found.`);return}h.addBind(new Z({primitives:L,index:v,weight:(B=H.weight)!=null?B:1}))})),m.materialColorBinds||m.textureTransformBinds){let H=[];e.scene.traverse(L=>{let v=L.material;v&&(Array.isArray(v)?H.push(...v):H.push(v))}),(b=m.materialColorBinds)==null||b.forEach(L=>R(this,null,function*(){H.filter(B=>{var O;let I=(O=this.parser.associations.get(B))==null?void 0:O.materials;return L.material===I}).forEach(B=>{h.addBind(new X({material:B,type:L.type,targetValue:new S.Color().fromArray(L.targetValue),targetAlpha:L.targetValue[3]}))})})),(F=m.textureTransformBinds)==null||F.forEach(L=>R(this,null,function*(){H.filter(B=>{var O;let I=(O=this.parser.associations.get(B))==null?void 0:O.materials;return L.material===I}).forEach(B=>{var I,O;h.addBind(new J({material:B,offset:new S.Vector2().fromArray((I=L.offset)!=null?I:[0,0]),scale:new S.Vector2().fromArray((O=L.scale)!=null?O:[1,1])}))})}))}a.registerExpression(h)}))),a})}_v0Import(e){return R(this,null,function*(){var s;let t=this.parser.json,r=(s=t.extensions)==null?void 0:s.VRM;if(!r)return null;let o=r.blendShapeMaster;if(!o)return null;let i=new Y,n=o.blendShapeGroups;if(!n)return i;let l=new Set;return yield Promise.all(n.map(a=>R(this,null,function*(){var h;let d=a.presetName,c=d!=null&&xe.v0v1PresetNameMap[d]||null,p=c!=null?c:a.name;if(p==null){console.warn("VRMExpressionLoaderPlugin: One of custom expressions has no name. Ignoring the expression");return}if(l.has(p)){console.warn(`VRMExpressionLoaderPlugin: An expression preset ${d} has duplicated entries. Ignoring the expression`);return}l.add(p);let m=new z(p);e.scene.add(m),m.isBinary=(h=a.isBinary)!=null?h:!1,a.binds&&a.binds.forEach(f=>R(this,null,function*(){var _;if(f.mesh===void 0||f.index===void 0)return;let V=[];(_=t.nodes)==null||_.forEach((T,b)=>{T.mesh===f.mesh&&V.push(b)});let x=f.index;yield Promise.all(V.map(T=>R(this,null,function*(){var F;let b=yield Ae(e,T);if(!b.every(H=>Array.isArray(H.morphTargetInfluences)&&x<H.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${a.name} attempts to index ${x}th morph but not found.`);return}m.addBind(new Z({primitives:b,index:x,weight:.01*((F=f.weight)!=null?F:100)}))})))}));let M=a.materialValues;M&&M.length!==0&&M.forEach(f=>{if(f.materialName===void 0||f.propertyName===void 0||f.targetValue===void 0)return;let V=[];e.scene.traverse(_=>{if(_.material){let T=_.material;Array.isArray(T)?V.push(...T.filter(b=>(b.name===f.materialName||b.name===f.materialName+" (Outline)")&&V.indexOf(b)===-1)):T.name===f.materialName&&V.indexOf(T)===-1&&V.push(T)}});let x=f.propertyName;V.forEach(_=>{if(x==="_MainTex_ST"){let b=new S.Vector2(f.targetValue[0],f.targetValue[1]),F=new S.Vector2(f.targetValue[2],f.targetValue[3]);F.y=1-F.y-b.y,m.addBind(new J({material:_,scale:b,offset:F}));return}let T=We[x];if(T){m.addBind(new X({material:_,type:T,targetValue:new S.Color().fromArray(f.targetValue),targetAlpha:f.targetValue[3]}));return}console.warn(x+" is not supported")})}),i.registerExpression(m)}))),i})}};xe.v0v1PresetNameMap={a:"aa",e:"ee",i:"ih",o:"oh",u:"ou",blink:"blink",joy:"happy",angry:"angry",sorrow:"sad",fun:"relaxed",lookup:"lookUp",lookdown:"lookDown",lookleft:"lookLeft",lookright:"lookRight",blink_l:"blinkLeft",blink_r:"blinkRight",neutral:"neutral"};var ie=xe;var nt={None:"none",Block:"block",Blend:"blend"};import*as A from"three";var N=class N{constructor(e,t){this._firstPersonOnlyLayer=N.DEFAULT_FIRSTPERSON_ONLY_LAYER;this._thirdPersonOnlyLayer=N.DEFAULT_THIRDPERSON_ONLY_LAYER;this._initializedLayers=!1;this.humanoid=e,this.meshAnnotations=t}copy(e){if(this.humanoid!==e.humanoid)throw new Error("VRMFirstPerson: humanoid must be same in order to copy");return this.meshAnnotations=e.meshAnnotations.map(t=>({meshes:t.meshes.concat(),type:t.type})),this}clone(){return new N(this.humanoid,this.meshAnnotations).copy(this)}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}setup({firstPersonOnlyLayer:e=N.DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:t=N.DEFAULT_THIRDPERSON_ONLY_LAYER}={}){this._initializedLayers||(this._firstPersonOnlyLayer=e,this._thirdPersonOnlyLayer=t,this.meshAnnotations.forEach(r=>{r.meshes.forEach(o=>{r.type==="firstPersonOnly"?(o.layers.set(this._firstPersonOnlyLayer),o.traverse(i=>i.layers.set(this._firstPersonOnlyLayer))):r.type==="thirdPersonOnly"?(o.layers.set(this._thirdPersonOnlyLayer),o.traverse(i=>i.layers.set(this._thirdPersonOnlyLayer))):r.type==="auto"&&this._createHeadlessModel(o)})}),this._initializedLayers=!0)}_excludeTriangles(e,t,r,o){let i=0;if(t!=null&&t.length>0)for(let n=0;n<e.length;n+=3){let l=e[n],s=e[n+1],a=e[n+2],d=t[l],c=r[l];if(d[0]>0&&o.includes(c[0])||d[1]>0&&o.includes(c[1])||d[2]>0&&o.includes(c[2])||d[3]>0&&o.includes(c[3]))continue;let p=t[s],m=r[s];if(p[0]>0&&o.includes(m[0])||p[1]>0&&o.includes(m[1])||p[2]>0&&o.includes(m[2])||p[3]>0&&o.includes(m[3]))continue;let M=t[a],h=r[a];M[0]>0&&o.includes(h[0])||M[1]>0&&o.includes(h[1])||M[2]>0&&o.includes(h[2])||M[3]>0&&o.includes(h[3])||(e[i++]=l,e[i++]=s,e[i++]=a)}return i}_createErasedMesh(e,t){let r=new A.SkinnedMesh(e.geometry.clone(),e.material);r.name=`${e.name}(erase)`,r.frustumCulled=e.frustumCulled,r.layers.set(this._firstPersonOnlyLayer);let o=r.geometry,i=o.getAttribute("skinIndex"),n=i instanceof A.GLBufferAttribute?[]:i.array,l=[];for(let h=0;h<n.length;h+=4)l.push([n[h],n[h+1],n[h+2],n[h+3]]);let s=o.getAttribute("skinWeight"),a=s instanceof A.GLBufferAttribute?[]:s.array,d=[];for(let h=0;h<a.length;h+=4)d.push([a[h],a[h+1],a[h+2],a[h+3]]);let c=o.getIndex();if(!c)throw new Error("The geometry doesn't have an index buffer");let p=Array.from(c.array),m=this._excludeTriangles(p,d,l,t),M=[];for(let h=0;h<m;h++)M[h]=p[h];return o.setIndex(M),e.onBeforeRender&&(r.onBeforeRender=e.onBeforeRender),r.bind(new A.Skeleton(e.skeleton.bones,e.skeleton.boneInverses),new A.Matrix4),r}_createHeadlessModelForSkinnedMesh(e,t){let r=[];if(t.skeleton.bones.forEach((i,n)=>{this._isEraseTarget(i)&&r.push(n)}),!r.length){t.layers.enable(this._thirdPersonOnlyLayer),t.layers.enable(this._firstPersonOnlyLayer);return}t.layers.set(this._thirdPersonOnlyLayer);let o=this._createErasedMesh(t,r);e.add(o)}_createHeadlessModel(e){if(e.type==="Group")if(e.layers.set(this._thirdPersonOnlyLayer),this._isEraseTarget(e))e.traverse(t=>t.layers.set(this._thirdPersonOnlyLayer));else{let t=new A.Group;t.name=`_headless_${e.name}`,t.layers.set(this._firstPersonOnlyLayer),e.parent.add(t),e.children.filter(r=>r.type==="SkinnedMesh").forEach(r=>{let o=r;this._createHeadlessModelForSkinnedMesh(t,o)})}else if(e.type==="SkinnedMesh"){let t=e;this._createHeadlessModelForSkinnedMesh(e.parent,t)}else this._isEraseTarget(e)&&(e.layers.set(this._thirdPersonOnlyLayer),e.traverse(t=>t.layers.set(this._thirdPersonOnlyLayer)))}_isEraseTarget(e){return e===this.humanoid.getRawBoneNode("head")?!0:e.parent?this._isEraseTarget(e.parent):!1}};N.DEFAULT_FIRSTPERSON_ONLY_LAYER=9,N.DEFAULT_THIRDPERSON_ONLY_LAYER=10;var K=N;var it=new Set(["1.0","1.0-beta"]),se=class{get name(){return"VRMFirstPersonLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return R(this,null,function*(){let t=e.userData.vrmHumanoid;if(t!==null){if(t===void 0)throw new Error("VRMFirstPersonLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");e.userData.vrmFirstPerson=yield this._import(e,t)}})}_import(e,t){return R(this,null,function*(){if(t==null)return null;let r=yield this._v1Import(e,t);if(r)return r;let o=yield this._v0Import(e,t);return o||null})}_v1Import(e,t){return R(this,null,function*(){var d,c;let r=this.parser.json;if(!(((d=r.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let i=(c=r.extensions)==null?void 0:c.VRMC_vrm;if(!i)return null;let n=i.specVersion;if(!it.has(n))return console.warn(`VRMFirstPersonLoaderPlugin: Unknown VRMC_vrm specVersion "${n}"`),null;let l=i.firstPerson,s=[],a=yield we(e);return Array.from(a.entries()).forEach(([p,m])=>{var h,f;let M=(h=l==null?void 0:l.meshAnnotations)==null?void 0:h.find(V=>V.node===p);s.push({meshes:m,type:(f=M==null?void 0:M.type)!=null?f:"auto"})}),new K(t,s)})}_v0Import(e,t){return R(this,null,function*(){var s;let r=this.parser.json,o=(s=r.extensions)==null?void 0:s.VRM;if(!o)return null;let i=o.firstPerson;if(!i)return null;let n=[],l=yield we(e);return Array.from(l.entries()).forEach(([a,d])=>{let c=r.nodes[a],p=i.meshAnnotations?i.meshAnnotations.find(m=>m.mesh===c.mesh):void 0;n.push({meshes:d,type:this._convertV0FlagToV1Type(p==null?void 0:p.firstPersonFlag)})}),new K(t,n)})}_convertV0FlagToV1Type(e){return e==="FirstPersonOnly"?"firstPersonOnly":e==="ThirdPersonOnly"?"thirdPersonOnly":e==="Both"?"both":"auto"}};var st={Auto:"auto",Both:"both",ThirdPersonOnly:"thirdPersonOnly",FirstPersonOnly:"firstPersonOnly"};import*as U from"three";var ze=new U.Vector3,qe=new U.Vector3,at=new U.Quaternion,ee=class extends U.Group{constructor(e){super(),this.vrmHumanoid=e,this._boneAxesMap=new Map,Object.values(e.humanBones).forEach(t=>{let r=new U.AxesHelper(1);r.matrixAutoUpdate=!1,r.material.depthTest=!1,r.material.depthWrite=!1,this.add(r),this._boneAxesMap.set(t,r)})}dispose(){Array.from(this._boneAxesMap.values()).forEach(e=>{e.geometry.dispose(),e.material.dispose()})}updateMatrixWorld(e){Array.from(this._boneAxesMap.entries()).forEach(([t,r])=>{t.node.updateWorldMatrix(!0,!1),t.node.matrixWorld.decompose(ze,at,qe);let o=ze.set(.1,.1,.1).divide(qe);r.matrix.copy(t.node.matrixWorld).scale(o)}),super.updateMatrixWorld(e)}};var ae=["hips","spine","chest","upperChest","neck","head","leftEye","rightEye","jaw","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftThumbMetacarpal","leftThumbProximal","leftThumbDistal","leftIndexProximal","leftIndexIntermediate","leftIndexDistal","leftMiddleProximal","leftMiddleIntermediate","leftMiddleDistal","leftRingProximal","leftRingIntermediate","leftRingDistal","leftLittleProximal","leftLittleIntermediate","leftLittleDistal","rightThumbMetacarpal","rightThumbProximal","rightThumbDistal","rightIndexProximal","rightIndexIntermediate","rightIndexDistal","rightMiddleProximal","rightMiddleIntermediate","rightMiddleDistal","rightRingProximal","rightRingIntermediate","rightRingDistal","rightLittleProximal","rightLittleIntermediate","rightLittleDistal"];var lt={Hips:"hips",Spine:"spine",Chest:"chest",UpperChest:"upperChest",Neck:"neck",Head:"head",LeftEye:"leftEye",RightEye:"rightEye",Jaw:"jaw",LeftUpperLeg:"leftUpperLeg",LeftLowerLeg:"leftLowerLeg",LeftFoot:"leftFoot",LeftToes:"leftToes",RightUpperLeg:"rightUpperLeg",RightLowerLeg:"rightLowerLeg",RightFoot:"rightFoot",RightToes:"rightToes",LeftShoulder:"leftShoulder",LeftUpperArm:"leftUpperArm",LeftLowerArm:"leftLowerArm",LeftHand:"leftHand",RightShoulder:"rightShoulder",RightUpperArm:"rightUpperArm",RightLowerArm:"rightLowerArm",RightHand:"rightHand",LeftThumbMetacarpal:"leftThumbMetacarpal",LeftThumbProximal:"leftThumbProximal",LeftThumbDistal:"leftThumbDistal",LeftIndexProximal:"leftIndexProximal",LeftIndexIntermediate:"leftIndexIntermediate",LeftIndexDistal:"leftIndexDistal",LeftMiddleProximal:"leftMiddleProximal",LeftMiddleIntermediate:"leftMiddleIntermediate",LeftMiddleDistal:"leftMiddleDistal",LeftRingProximal:"leftRingProximal",LeftRingIntermediate:"leftRingIntermediate",LeftRingDistal:"leftRingDistal",LeftLittleProximal:"leftLittleProximal",LeftLittleIntermediate:"leftLittleIntermediate",LeftLittleDistal:"leftLittleDistal",RightThumbMetacarpal:"rightThumbMetacarpal",RightThumbProximal:"rightThumbProximal",RightThumbDistal:"rightThumbDistal",RightIndexProximal:"rightIndexProximal",RightIndexIntermediate:"rightIndexIntermediate",RightIndexDistal:"rightIndexDistal",RightMiddleProximal:"rightMiddleProximal",RightMiddleIntermediate:"rightMiddleIntermediate",RightMiddleDistal:"rightMiddleDistal",RightRingProximal:"rightRingProximal",RightRingIntermediate:"rightRingIntermediate",RightRingDistal:"rightRingDistal",RightLittleProximal:"rightLittleProximal",RightLittleIntermediate:"rightLittleIntermediate",RightLittleDistal:"rightLittleDistal"};var Be={hips:null,spine:"hips",chest:"spine",upperChest:"chest",neck:"upperChest",head:"neck",leftEye:"head",rightEye:"head",jaw:"head",leftUpperLeg:"hips",leftLowerLeg:"leftUpperLeg",leftFoot:"leftLowerLeg",leftToes:"leftFoot",rightUpperLeg:"hips",rightLowerLeg:"rightUpperLeg",rightFoot:"rightLowerLeg",rightToes:"rightFoot",leftShoulder:"upperChest",leftUpperArm:"leftShoulder",leftLowerArm:"leftUpperArm",leftHand:"leftLowerArm",rightShoulder:"upperChest",rightUpperArm:"rightShoulder",rightLowerArm:"rightUpperArm",rightHand:"rightLowerArm",leftThumbMetacarpal:"leftHand",leftThumbProximal:"leftThumbMetacarpal",leftThumbDistal:"leftThumbProximal",leftIndexProximal:"leftHand",leftIndexIntermediate:"leftIndexProximal",leftIndexDistal:"leftIndexIntermediate",leftMiddleProximal:"leftHand",leftMiddleIntermediate:"leftMiddleProximal",leftMiddleDistal:"leftMiddleIntermediate",leftRingProximal:"leftHand",leftRingIntermediate:"leftRingProximal",leftRingDistal:"leftRingIntermediate",leftLittleProximal:"leftHand",leftLittleIntermediate:"leftLittleProximal",leftLittleDistal:"leftLittleIntermediate",rightThumbMetacarpal:"rightHand",rightThumbProximal:"rightThumbMetacarpal",rightThumbDistal:"rightThumbProximal",rightIndexProximal:"rightHand",rightIndexIntermediate:"rightIndexProximal",rightIndexDistal:"rightIndexIntermediate",rightMiddleProximal:"rightHand",rightMiddleIntermediate:"rightMiddleProximal",rightMiddleDistal:"rightMiddleIntermediate",rightRingProximal:"rightHand",rightRingIntermediate:"rightRingProximal",rightRingDistal:"rightRingIntermediate",rightLittleProximal:"rightHand",rightLittleIntermediate:"rightLittleProximal",rightLittleDistal:"rightLittleIntermediate"};import*as be from"three";function Te(u){return u.invert?u.invert():u.inverse(),u}var C=new be.Vector3,W=new be.Quaternion,j=class{constructor(e){this.humanBones=e,this.restPose=this.getAbsolutePose()}getAbsolutePose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let r=t,o=this.getBoneNode(r);o&&(C.copy(o.position),W.copy(o.quaternion),e[r]={position:C.toArray(),rotation:W.toArray()})}),e}getPose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let r=t,o=this.getBoneNode(r);if(!o)return;C.set(0,0,0),W.identity();let i=this.restPose[r];i!=null&&i.position&&C.fromArray(i.position).negate(),i!=null&&i.rotation&&Te(W.fromArray(i.rotation)),C.add(o.position),W.premultiply(o.quaternion),e[r]={position:C.toArray(),rotation:W.toArray()}}),e}setPose(e){Object.entries(e).forEach(([t,r])=>{let o=t,i=this.getBoneNode(o);if(!i)return;let n=this.restPose[o];n&&(r!=null&&r.position&&(i.position.fromArray(r.position),n.position&&i.position.add(C.fromArray(n.position))),r!=null&&r.rotation&&(i.quaternion.fromArray(r.rotation),n.rotation&&i.quaternion.multiply(W.fromArray(n.rotation))))})}resetPose(){Object.entries(this.restPose).forEach(([e,t])=>{let r=this.getBoneNode(e);r&&(t!=null&&t.position&&r.position.fromArray(t.position),t!=null&&t.rotation&&r.quaternion.fromArray(t.rotation))})}getBone(e){var t;return(t=this.humanBones[e])!=null?t:void 0}getBoneNode(e){var t,r;return(r=(t=this.humanBones[e])==null?void 0:t.node)!=null?r:null}};import*as w from"three";var ke=new w.Vector3,ut=new w.Quaternion,pt=new w.Vector3,le=class u extends j{static _setupTransforms(e){let t=new w.Object3D;t.name="VRMHumanoidRig";let r={},o={},i={},n={};ae.forEach(s=>{var d;let a=e.getBoneNode(s);if(a){let c=new w.Vector3,p=new w.Quaternion;a.updateWorldMatrix(!0,!1),a.matrixWorld.decompose(c,p,ke),r[s]=c,o[s]=p,i[s]=a.quaternion.clone();let m=new w.Quaternion;(d=a.parent)==null||d.matrixWorld.decompose(ke,m,ke),n[s]=m}});let l={};return ae.forEach(s=>{var d;let a=e.getBoneNode(s);if(a){let c=r[s],p=s,m;for(;m==null&&(p=Be[p],p!=null);)m=r[p];let M=new w.Object3D;M.name="Normalized_"+a.name,(p?(d=l[p])==null?void 0:d.node:t).add(M),M.position.copy(c),m&&M.position.sub(m),l[s]={node:M}}}),{rigBones:l,root:t,parentWorldRotations:n,boneRotations:i}}constructor(e){let{rigBones:t,root:r,parentWorldRotations:o,boneRotations:i}=u._setupTransforms(e);super(t),this.original=e,this.root=r,this._parentWorldRotations=o,this._boneRotations=i}update(){ae.forEach(e=>{let t=this.original.getBoneNode(e);if(t!=null){let r=this.getBoneNode(e),o=this._parentWorldRotations[e],i=ut.copy(o).invert(),n=this._boneRotations[e];if(t.quaternion.copy(r.quaternion).multiply(o).premultiply(i).multiply(n),e==="hips"){let l=r.getWorldPosition(pt);t.parent.updateWorldMatrix(!0,!1);let s=t.parent.matrixWorld,a=l.applyMatrix4(s.invert());t.position.copy(a)}}})}};var te=class u{get restPose(){return console.warn("VRMHumanoid: restPose is deprecated. Use either rawRestPose or normalizedRestPose instead."),this.rawRestPose}get rawRestPose(){return this._rawHumanBones.restPose}get normalizedRestPose(){return this._normalizedHumanBones.restPose}get humanBones(){return this._rawHumanBones.humanBones}get rawHumanBones(){return this._rawHumanBones.humanBones}get normalizedHumanBones(){return this._normalizedHumanBones.humanBones}get normalizedHumanBonesRoot(){return this._normalizedHumanBones.root}constructor(e,t){var r;this.autoUpdateHumanBones=(r=t==null?void 0:t.autoUpdateHumanBones)!=null?r:!0,this._rawHumanBones=new j(e),this._normalizedHumanBones=new le(this._rawHumanBones)}copy(e){return this.autoUpdateHumanBones=e.autoUpdateHumanBones,this._rawHumanBones=new j(e.humanBones),this._normalizedHumanBones=new le(this._rawHumanBones),this}clone(){return new u(this.humanBones,{autoUpdateHumanBones:this.autoUpdateHumanBones}).copy(this)}getAbsolutePose(){return console.warn("VRMHumanoid: getAbsolutePose() is deprecated. Use either getRawAbsolutePose() or getNormalizedAbsolutePose() instead."),this.getRawAbsolutePose()}getRawAbsolutePose(){return this._rawHumanBones.getAbsolutePose()}getNormalizedAbsolutePose(){return this._normalizedHumanBones.getAbsolutePose()}getPose(){return console.warn("VRMHumanoid: getPose() is deprecated. Use either getRawPose() or getNormalizedPose() instead."),this.getRawPose()}getRawPose(){return this._rawHumanBones.getPose()}getNormalizedPose(){return this._normalizedHumanBones.getPose()}setPose(e){return console.warn("VRMHumanoid: setPose() is deprecated. Use either setRawPose() or setNormalizedPose() instead."),this.setRawPose(e)}setRawPose(e){return this._rawHumanBones.setPose(e)}setNormalizedPose(e){return this._normalizedHumanBones.setPose(e)}resetPose(){return console.warn("VRMHumanoid: resetPose() is deprecated. Use either resetRawPose() or resetNormalizedPose() instead."),this.resetRawPose()}resetRawPose(){return this._rawHumanBones.resetPose()}resetNormalizedPose(){return this._normalizedHumanBones.resetPose()}getBone(e){return console.warn("VRMHumanoid: getBone() is deprecated. Use either getRawBone() or getNormalizedBone() instead."),this.getRawBone(e)}getRawBone(e){return this._rawHumanBones.getBone(e)}getNormalizedBone(e){return this._normalizedHumanBones.getBone(e)}getBoneNode(e){return console.warn("VRMHumanoid: getBoneNode() is deprecated. Use either getRawBoneNode() or getNormalizedBoneNode() instead."),this.getRawBoneNode(e)}getRawBoneNode(e){return this._rawHumanBones.getBoneNode(e)}getNormalizedBoneNode(e){return this._normalizedHumanBones.getBoneNode(e)}update(){this.autoUpdateHumanBones&&this._normalizedHumanBones.update()}};var Fe={Hips:"hips",Spine:"spine",Head:"head",LeftUpperLeg:"leftUpperLeg",LeftLowerLeg:"leftLowerLeg",LeftFoot:"leftFoot",RightUpperLeg:"rightUpperLeg",RightLowerLeg:"rightLowerLeg",RightFoot:"rightFoot",LeftUpperArm:"leftUpperArm",LeftLowerArm:"leftLowerArm",LeftHand:"leftHand",RightUpperArm:"rightUpperArm",RightLowerArm:"rightLowerArm",RightHand:"rightHand"};var mt=new Set(["1.0","1.0-beta"]),Ye={leftThumbProximal:"leftThumbMetacarpal",leftThumbIntermediate:"leftThumbProximal",rightThumbProximal:"rightThumbMetacarpal",rightThumbIntermediate:"rightThumbProximal"},ue=class{get name(){return"VRMHumanoidLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot,this.autoUpdateHumanBones=t==null?void 0:t.autoUpdateHumanBones}afterRoot(e){return R(this,null,function*(){e.userData.vrmHumanoid=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let r=yield this._v0Import(e);return r||null})}_v1Import(e){return R(this,null,function*(){var d,c;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(!o)return null;let i=o.specVersion;if(!mt.has(i))return console.warn(`VRMHumanoidLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.humanoid;if(!n)return null;let l=n.humanBones.leftThumbIntermediate!=null||n.humanBones.rightThumbIntermediate!=null,s={};n.humanBones!=null&&(yield Promise.all(Object.entries(n.humanBones).map(M=>R(this,[M],function*([p,m]){let h=p,f=m.node;if(l){let x=Ye[h];x!=null&&(h=x)}let V=yield this.parser.getDependency("node",f);if(V==null){console.warn(`A glTF node bound to the humanoid bone ${h} (index = ${f}) does not exist`);return}s[h]={node:V}}))));let a=new te(this._ensureRequiredBonesExist(s),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(a.normalizedHumanBonesRoot),this.helperRoot){let p=new ee(a);this.helperRoot.add(p),p.renderOrder=this.helperRoot.renderOrder}return a})}_v0Import(e){return R(this,null,function*(){var l;let r=(l=this.parser.json.extensions)==null?void 0:l.VRM;if(!r)return null;let o=r.humanoid;if(!o)return null;let i={};o.humanBones!=null&&(yield Promise.all(o.humanBones.map(s=>R(this,null,function*(){let a=s.bone,d=s.node;if(a==null||d==null)return;let c=yield this.parser.getDependency("node",d);if(c==null){console.warn(`A glTF node bound to the humanoid bone ${a} (index = ${d}) does not exist`);return}let p=Ye[a],m=p!=null?p:a;if(i[m]!=null){console.warn(`Multiple bone entries for ${m} detected (index = ${d}), ignoring duplicated entries.`);return}i[m]={node:c}}))));let n=new te(this._ensureRequiredBonesExist(i),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(n.normalizedHumanBonesRoot),this.helperRoot){let s=new ee(n);this.helperRoot.add(s),s.renderOrder=this.helperRoot.renderOrder}return n})}_ensureRequiredBonesExist(e){let t=Object.values(Fe).filter(r=>e[r]==null);if(t.length>0)throw new Error(`VRMHumanoidLoaderPlugin: These humanoid bones are required but not exist: ${t.join(", ")}`);return e}};import*as E from"three";import*as pe from"three";var me=class extends pe.BufferGeometry{constructor(){super();this._currentTheta=0;this._currentRadius=0;this.theta=0,this.radius=0,this._currentTheta=0,this._currentRadius=0,this._attrPos=new pe.BufferAttribute(new Float32Array(65*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new pe.BufferAttribute(new Uint16Array(3*63),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentTheta!==this.theta&&(this._currentTheta=this.theta,t=!0),this._currentRadius!==this.radius&&(this._currentRadius=this.radius,t=!0),t&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,0,0,0);for(let t=0;t<64;t++){let r=t/63*this._currentTheta;this._attrPos.setXYZ(t+1,this._currentRadius*Math.sin(r),0,this._currentRadius*Math.cos(r))}this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<63;t++)this._attrIndex.setXYZ(t*3,0,t+1,t+2);this._attrIndex.needsUpdate=!0}};import*as D from"three";var He=class extends D.BufferGeometry{constructor(){super(),this.radius=0,this._currentRadius=0,this.tail=new D.Vector3,this._currentTail=new D.Vector3,this._attrPos=new D.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new D.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;this._currentRadius!==this.radius&&(this._currentRadius=this.radius,e=!0),this._currentTail.equals(this.tail)||(this._currentTail.copy(this.tail),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){let t=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(t),Math.sin(t),0),this._attrPos.setXYZ(32+e,0,Math.cos(t),Math.sin(t)),this._attrPos.setXYZ(64+e,Math.sin(t),0,Math.cos(t))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<32;e++){let t=(e+1)%32;this._attrIndex.setXY(e*2,e,t),this._attrIndex.setXY(64+e*2,32+e,32+t),this._attrIndex.setXY(128+e*2,64+e,64+t)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}};var Le=new E.Quaternion,$e=new E.Quaternion,de=new E.Vector3,Xe=new E.Vector3,Ze=Math.sqrt(2)/2,dt=new E.Quaternion(0,0,-Ze,Ze),ht=new E.Vector3(0,1,0),he=class extends E.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.vrmLookAt=e;{let t=new me;t.radius=.5;let r=new E.MeshBasicMaterial({color:65280,transparent:!0,opacity:.5,side:E.DoubleSide,depthTest:!1,depthWrite:!1});this._meshPitch=new E.Mesh(t,r),this.add(this._meshPitch)}{let t=new me;t.radius=.5;let r=new E.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.5,side:E.DoubleSide,depthTest:!1,depthWrite:!1});this._meshYaw=new E.Mesh(t,r),this.add(this._meshYaw)}{let t=new He;t.radius=.1;let r=new E.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1});this._lineTarget=new E.LineSegments(t,r),this._lineTarget.frustumCulled=!1,this.add(this._lineTarget)}}dispose(){this._meshYaw.geometry.dispose(),this._meshYaw.material.dispose(),this._meshPitch.geometry.dispose(),this._meshPitch.material.dispose(),this._lineTarget.geometry.dispose(),this._lineTarget.material.dispose()}updateMatrixWorld(e){let t=E.MathUtils.DEG2RAD*this.vrmLookAt.yaw;this._meshYaw.geometry.theta=t,this._meshYaw.geometry.update();let r=E.MathUtils.DEG2RAD*this.vrmLookAt.pitch;this._meshPitch.geometry.theta=r,this._meshPitch.geometry.update(),this.vrmLookAt.getLookAtWorldPosition(de),this.vrmLookAt.getLookAtWorldQuaternion(Le),Le.multiply(this.vrmLookAt.getFaceFrontQuaternion($e)),this._meshYaw.position.copy(de),this._meshYaw.quaternion.copy(Le),this._meshPitch.position.copy(de),this._meshPitch.quaternion.copy(Le),this._meshPitch.quaternion.multiply($e.setFromAxisAngle(ht,t)),this._meshPitch.quaternion.multiply(dt);let{target:o,autoUpdate:i}=this.vrmLookAt;o!=null&&i&&(o.getWorldPosition(Xe).sub(de),this._lineTarget.geometry.tail.copy(Xe),this._lineTarget.geometry.update(),this._lineTarget.position.copy(de)),super.updateMatrixWorld(e)}};import*as y from"three";import*as Ie from"three";var ct=new Ie.Vector3,Rt=new Ie.Vector3;function ce(u,e){return u.matrixWorld.decompose(ct,e,Rt),e}function re(u){return[Math.atan2(-u.z,u.x),Math.atan2(u.y,Math.sqrt(u.x*u.x+u.z*u.z))]}function Ne(u){let e=Math.round(u/2/Math.PI);return u-2*Math.PI*e}var Je=new y.Vector3(0,0,1),ft=new y.Vector3,Mt=new y.Vector3,Et=new y.Vector3,gt=new y.Quaternion,Ue=new y.Quaternion,Ke=new y.Quaternion,Vt=new y.Quaternion,Oe=new y.Euler,Pe=class Pe{constructor(e,t){this.offsetFromHeadBone=new y.Vector3;this.autoUpdate=!0;this.faceFront=new y.Vector3(0,0,1);this.humanoid=e,this.applier=t,this._yaw=0,this._pitch=0,this._needsUpdate=!0,this._restHeadWorldQuaternion=this.getLookAtWorldQuaternion(new y.Quaternion)}get yaw(){return this._yaw}set yaw(e){this._yaw=e,this._needsUpdate=!0}get pitch(){return this._pitch}set pitch(e){this._pitch=e,this._needsUpdate=!0}get euler(){return console.warn("VRMLookAt: euler is deprecated. use getEuler() instead."),this.getEuler(new y.Euler)}getEuler(e){return e.set(y.MathUtils.DEG2RAD*this._pitch,y.MathUtils.DEG2RAD*this._yaw,0,"YXZ")}copy(e){if(this.humanoid!==e.humanoid)throw new Error("VRMLookAt: humanoid must be same in order to copy");return this.offsetFromHeadBone.copy(e.offsetFromHeadBone),this.applier=e.applier,this.autoUpdate=e.autoUpdate,this.target=e.target,this.faceFront.copy(e.faceFront),this}clone(){return new Pe(this.humanoid,this.applier).copy(this)}reset(){this._yaw=0,this._pitch=0,this._needsUpdate=!0}getLookAtWorldPosition(e){let t=this.humanoid.getRawBoneNode("head");return e.copy(this.offsetFromHeadBone).applyMatrix4(t.matrixWorld)}getLookAtWorldQuaternion(e){let t=this.humanoid.getRawBoneNode("head");return ce(t,e)}getFaceFrontQuaternion(e){if(this.faceFront.distanceToSquared(Je)<.01)return e.copy(this._restHeadWorldQuaternion).invert();let[t,r]=re(this.faceFront);return Oe.set(0,.5*Math.PI+t,r,"YZX"),e.setFromEuler(Oe).premultiply(Vt.copy(this._restHeadWorldQuaternion).invert())}getLookAtWorldDirection(e){return this.getLookAtWorldQuaternion(Ue),this.getFaceFrontQuaternion(Ke),e.copy(Je).applyQuaternion(Ue).applyQuaternion(Ke).applyEuler(this.getEuler(Oe))}lookAt(e){let t=gt.copy(this._restHeadWorldQuaternion).multiply(Te(this.getLookAtWorldQuaternion(Ue))),r=this.getLookAtWorldPosition(Mt),o=Et.copy(e).sub(r).applyQuaternion(t).normalize(),[i,n]=re(this.faceFront),[l,s]=re(o),a=Ne(l-i),d=Ne(n-s);this._yaw=y.MathUtils.RAD2DEG*a,this._pitch=y.MathUtils.RAD2DEG*d,this._needsUpdate=!0}update(e){this.target!=null&&this.autoUpdate&&this.lookAt(this.target.getWorldPosition(ft)),this._needsUpdate&&(this._needsUpdate=!1,this.applier.applyYawPitch(this._yaw,this._pitch))}};Pe.EULER_ORDER="YXZ";var Re=Pe;import*as g from"three";var yt=new g.Vector3(0,0,1),k=new g.Quaternion,oe=new g.Quaternion,P=new g.Euler(0,0,0,"YXZ"),G=class{constructor(e,t,r,o,i){this.humanoid=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=r,this.rangeMapVerticalDown=o,this.rangeMapVerticalUp=i,this.faceFront=new g.Vector3(0,0,1),this._restQuatLeftEye=new g.Quaternion,this._restQuatRightEye=new g.Quaternion,this._restLeftEyeParentWorldQuat=new g.Quaternion,this._restRightEyeParentWorldQuat=new g.Quaternion;let n=this.humanoid.getRawBoneNode("leftEye"),l=this.humanoid.getRawBoneNode("rightEye");n&&(this._restQuatLeftEye.copy(n.quaternion),ce(n.parent,this._restLeftEyeParentWorldQuat)),l&&(this._restQuatRightEye.copy(l.quaternion),ce(l.parent,this._restRightEyeParentWorldQuat))}applyYawPitch(e,t){let r=this.humanoid.getRawBoneNode("leftEye"),o=this.humanoid.getRawBoneNode("rightEye"),i=this.humanoid.getNormalizedBoneNode("leftEye"),n=this.humanoid.getNormalizedBoneNode("rightEye");r&&(t<0?P.x=-g.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):P.x=g.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?P.y=-g.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(-e):P.y=g.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(e),k.setFromEuler(P),this._getWorldFaceFrontQuat(oe),i.quaternion.copy(oe).multiply(k).multiply(oe.invert()),k.copy(this._restLeftEyeParentWorldQuat),r.quaternion.copy(i.quaternion).multiply(k).premultiply(k.invert()).multiply(this._restQuatLeftEye)),o&&(t<0?P.x=-g.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):P.x=g.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?P.y=-g.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(-e):P.y=g.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(e),k.setFromEuler(P),this._getWorldFaceFrontQuat(oe),n.quaternion.copy(oe).multiply(k).multiply(oe.invert()),k.copy(this._restRightEyeParentWorldQuat),o.quaternion.copy(n.quaternion).multiply(k).premultiply(k.invert()).multiply(this._restQuatRightEye))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=g.MathUtils.RAD2DEG*e.y,r=g.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,r)}_getWorldFaceFrontQuat(e){if(this.faceFront.distanceToSquared(yt)<.01)return e.identity();let[t,r]=re(this.faceFront);return P.set(0,.5*Math.PI+t,r,"YZX"),e.setFromEuler(P)}};G.type="bone";import*as Se from"three";var Q=class{constructor(e,t,r,o,i){this.expressions=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=r,this.rangeMapVerticalDown=o,this.rangeMapVerticalUp=i}applyYawPitch(e,t){t<0?(this.expressions.setValue("lookDown",0),this.expressions.setValue("lookUp",this.rangeMapVerticalUp.map(-t))):(this.expressions.setValue("lookUp",0),this.expressions.setValue("lookDown",this.rangeMapVerticalDown.map(t))),e<0?(this.expressions.setValue("lookLeft",0),this.expressions.setValue("lookRight",this.rangeMapHorizontalOuter.map(-e))):(this.expressions.setValue("lookRight",0),this.expressions.setValue("lookLeft",this.rangeMapHorizontalOuter.map(e)))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=Se.MathUtils.RAD2DEG*e.y,r=Se.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,r)}};Q.type="expression";var ne=class{constructor(e,t){this.inputMaxValue=e,this.outputScale=t}map(e){return this.outputScale*ge(e/this.inputMaxValue)}};var xt=new Set(["1.0","1.0-beta"]),_e=.01,fe=class{get name(){return"VRMLookAtLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot}afterRoot(e){return R(this,null,function*(){let t=e.userData.vrmHumanoid;if(t===null)return;if(t===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");let r=e.userData.vrmExpressionManager;if(r!==null){if(r===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmExpressionManager is undefined. VRMExpressionLoaderPlugin have to be used first");e.userData.vrmLookAt=yield this._import(e,t,r)}})}_import(e,t,r){return R(this,null,function*(){if(t==null||r==null)return null;let o=yield this._v1Import(e,t,r);if(o)return o;let i=yield this._v0Import(e,t,r);return i||null})}_v1Import(e,t,r){return R(this,null,function*(){var f,V,x;let o=this.parser.json;if(!(((f=o.extensionsUsed)==null?void 0:f.indexOf("VRMC_vrm"))!==-1))return null;let n=(V=o.extensions)==null?void 0:V.VRMC_vrm;if(!n)return null;let l=n.specVersion;if(!xt.has(l))return console.warn(`VRMLookAtLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let s=n.lookAt;if(!s)return null;let a=s.type==="expression"?1:10,d=this._v1ImportRangeMap(s.rangeMapHorizontalInner,a),c=this._v1ImportRangeMap(s.rangeMapHorizontalOuter,a),p=this._v1ImportRangeMap(s.rangeMapVerticalDown,a),m=this._v1ImportRangeMap(s.rangeMapVerticalUp,a),M;s.type==="expression"?M=new Q(r,d,c,p,m):M=new G(t,d,c,p,m);let h=this._importLookAt(t,M);return h.offsetFromHeadBone.fromArray((x=s.offsetFromHeadBone)!=null?x:[0,.06,0]),h})}_v1ImportRangeMap(e,t){var i,n;let r=(i=e==null?void 0:e.inputMaxValue)!=null?i:90,o=(n=e==null?void 0:e.outputScale)!=null?n:t;return r<_e&&(console.warn("VRMLookAtLoaderPlugin: inputMaxValue of a range map is too small. Consider reviewing the range map!"),r=_e),new ne(r,o)}_v0Import(e,t,r){return R(this,null,function*(){var M,h,f,V;let i=(M=this.parser.json.extensions)==null?void 0:M.VRM;if(!i)return null;let n=i.firstPerson;if(!n)return null;let l=n.lookAtTypeName==="BlendShape"?1:10,s=this._v0ImportDegreeMap(n.lookAtHorizontalInner,l),a=this._v0ImportDegreeMap(n.lookAtHorizontalOuter,l),d=this._v0ImportDegreeMap(n.lookAtVerticalDown,l),c=this._v0ImportDegreeMap(n.lookAtVerticalUp,l),p;n.lookAtTypeName==="BlendShape"?p=new Q(r,s,a,d,c):p=new G(t,s,a,d,c);let m=this._importLookAt(t,p);return n.firstPersonBoneOffset?m.offsetFromHeadBone.set((h=n.firstPersonBoneOffset.x)!=null?h:0,(f=n.firstPersonBoneOffset.y)!=null?f:.06,-((V=n.firstPersonBoneOffset.z)!=null?V:0)):m.offsetFromHeadBone.set(0,.06,0),m.faceFront.set(0,0,-1),p instanceof G&&p.faceFront.set(0,0,-1),m})}_v0ImportDegreeMap(e,t){var n,l;let r=e==null?void 0:e.curve;JSON.stringify(r)!=="[0,0,0,1,1,1,1,0]"&&console.warn("Curves of LookAtDegreeMap defined in VRM 0.0 are not supported");let o=(n=e==null?void 0:e.xRange)!=null?n:90,i=(l=e==null?void 0:e.yRange)!=null?l:t;return o<_e&&(console.warn("VRMLookAtLoaderPlugin: xRange of a degree map is too small. Consider reviewing the degree map!"),o=_e),new ne(o,i)}_importLookAt(e,t){let r=new Re(e,t);if(this.helperRoot){let o=new he(r);this.helperRoot.add(o),o.renderOrder=this.helperRoot.renderOrder}return r}};var Tt={Bone:"bone",Expression:"expression"};import*as tt from"three";function et(u,e){return typeof u!="string"||u===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(u)&&(e=e.replace(/(^https?:\/\/[^/]+).*/i,"$1")),/^(https?:)?\/\//i.test(u)||/^data:.*,.*$/i.test(u)||/^blob:.*$/i.test(u)?u:e+u)}var bt=new Set(["1.0","1.0-beta"]),Me=class{get name(){return"VRMMetaLoaderPlugin"}constructor(e,t){var r,o,i;this.parser=e,this.needThumbnailImage=(r=t==null?void 0:t.needThumbnailImage)!=null?r:!1,this.acceptLicenseUrls=(o=t==null?void 0:t.acceptLicenseUrls)!=null?o:["https://vrm.dev/licenses/1.0/"],this.acceptV0Meta=(i=t==null?void 0:t.acceptV0Meta)!=null?i:!0}afterRoot(e){return R(this,null,function*(){e.userData.vrmMeta=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t!=null)return t;let r=yield this._v0Import(e);return r!=null?r:null})}_v1Import(e){return R(this,null,function*(){var d,c,p;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(o==null)return null;let i=o.specVersion;if(!bt.has(i))return console.warn(`VRMMetaLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.meta;if(!n)return null;let l=n.licenseUrl;if(!new Set(this.acceptLicenseUrls).has(l))throw new Error(`VRMMetaLoaderPlugin: The license url "${l}" is not accepted`);let a;return this.needThumbnailImage&&n.thumbnailImage!=null&&(a=(p=yield this._extractGLTFImage(n.thumbnailImage))!=null?p:void 0),{metaVersion:"1",name:n.name,version:n.version,authors:n.authors,copyrightInformation:n.copyrightInformation,contactInformation:n.contactInformation,references:n.references,thirdPartyLicenses:n.thirdPartyLicenses,thumbnailImage:a,licenseUrl:n.licenseUrl,avatarPermission:n.avatarPermission,allowExcessivelyViolentUsage:n.allowExcessivelyViolentUsage,allowExcessivelySexualUsage:n.allowExcessivelySexualUsage,commercialUsage:n.commercialUsage,allowPoliticalOrReligiousUsage:n.allowPoliticalOrReligiousUsage,allowAntisocialOrHateUsage:n.allowAntisocialOrHateUsage,creditNotation:n.creditNotation,allowRedistribution:n.allowRedistribution,modification:n.modification,otherLicenseUrl:n.otherLicenseUrl}})}_v0Import(e){return R(this,null,function*(){var n;let r=(n=this.parser.json.extensions)==null?void 0:n.VRM;if(!r)return null;let o=r.meta;if(!o)return null;if(!this.acceptV0Meta)throw new Error("VRMMetaLoaderPlugin: Attempted to load VRM0.0 meta but acceptV0Meta is false");let i;return this.needThumbnailImage&&o.texture!=null&&o.texture!==-1&&(i=yield this.parser.getDependency("texture",o.texture)),{metaVersion:"0",allowedUserName:o.allowedUserName,author:o.author,commercialUssageName:o.commercialUssageName,contactInformation:o.contactInformation,licenseName:o.licenseName,otherLicenseUrl:o.otherLicenseUrl,otherPermissionUrl:o.otherPermissionUrl,reference:o.reference,sexualUssageName:o.sexualUssageName,texture:i!=null?i:void 0,title:o.title,version:o.version,violentUssageName:o.violentUssageName}})}_extractGLTFImage(e){return R(this,null,function*(){var n;let r=(n=this.parser.json.images)==null?void 0:n[e];if(r==null)return console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image doesn't exist`),null;let o=r.uri;if(r.bufferView!=null){let l=yield this.parser.getDependency("bufferView",r.bufferView),s=new Blob([l],{type:r.mimeType});o=URL.createObjectURL(s)}return o==null?(console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image couldn't load properly`),null):yield new tt.ImageLoader().loadAsync(et(o,this.parser.options.path)).catch(l=>(console.error(l),console.warn("VRMMetaLoaderPlugin: Failed to load a thumbnail image"),null))})}};var Ee=class{constructor(e){this.scene=e.scene,this.meta=e.meta,this.humanoid=e.humanoid,this.expressionManager=e.expressionManager,this.firstPerson=e.firstPerson,this.lookAt=e.lookAt}update(e){this.humanoid.update(),this.lookAt&&this.lookAt.update(e),this.expressionManager&&this.expressionManager.update()}};var De=class{get name(){return"VRMC_vrm"}constructor(e,t){var i,n,l,s,a;this.parser=e;let r=t==null?void 0:t.helperRoot,o=t==null?void 0:t.autoUpdateHumanBones;this.expressionPlugin=(i=t==null?void 0:t.expressionPlugin)!=null?i:new ie(e),this.firstPersonPlugin=(n=t==null?void 0:t.firstPersonPlugin)!=null?n:new se(e),this.humanoidPlugin=(l=t==null?void 0:t.humanoidPlugin)!=null?l:new ue(e,{helperRoot:r,autoUpdateHumanBones:o}),this.lookAtPlugin=(s=t==null?void 0:t.lookAtPlugin)!=null?s:new fe(e,{helperRoot:r}),this.metaPlugin=(a=t==null?void 0:t.metaPlugin)!=null?a:new Me(e)}afterRoot(e){return R(this,null,function*(){yield this.metaPlugin.afterRoot(e),yield this.humanoidPlugin.afterRoot(e),yield this.expressionPlugin.afterRoot(e),yield this.lookAtPlugin.afterRoot(e),yield this.firstPersonPlugin.afterRoot(e);let t=e.userData.vrmMeta,r=e.userData.vrmHumanoid;if(t&&r){let o=new Ee({scene:e.scene,expressionManager:e.userData.vrmExpressionManager,firstPerson:e.userData.vrmFirstPerson,humanoid:r,lookAt:e.userData.vrmLookAt,meta:t});e.userData.vrmCore=o}})}};export{Ee as VRMCore,De as VRMCoreLoaderPlugin,z as VRMExpression,ie as VRMExpressionLoaderPlugin,Y as VRMExpressionManager,X as VRMExpressionMaterialColorBind,$ as VRMExpressionMaterialColorType,Z as VRMExpressionMorphTargetBind,nt as VRMExpressionOverrideType,q as VRMExpressionPresetName,J as VRMExpressionTextureTransformBind,K as VRMFirstPerson,se as VRMFirstPersonLoaderPlugin,st as VRMFirstPersonMeshAnnotationType,ae as VRMHumanBoneList,lt as VRMHumanBoneName,Be as VRMHumanBoneParentMap,te as VRMHumanoid,ee as VRMHumanoidHelper,ue as VRMHumanoidLoaderPlugin,Re as VRMLookAt,G as VRMLookAtBoneApplier,Q as VRMLookAtExpressionApplier,he as VRMLookAtHelper,fe as VRMLookAtLoaderPlugin,ne as VRMLookAtRangeMap,Tt as VRMLookAtTypeName,Me as VRMMetaLoaderPlugin,Fe as VRMRequiredHumanBoneName};
2
+ var R=(u,e,t)=>new Promise((r,o)=>{var i=s=>{try{l(t.next(s))}catch(a){o(a)}},n=s=>{try{l(t.throw(s))}catch(a){o(a)}},l=s=>s.done?r(s.value):Promise.resolve(s.value).then(i,n);l((t=t.apply(u,e)).next())});import*as Ge from"three";var z=class extends Ge.Object3D{constructor(t){super();this.weight=0;this.isBinary=!1;this.overrideBlink="none";this.overrideLookAt="none";this.overrideMouth="none";this._binds=[];this.name=`VRMExpression_${t}`,this.expressionName=t,this.type="VRMExpression",this.visible=!1}get binds(){return this._binds}get overrideBlinkAmount(){return this.overrideBlink==="block"?0<this.outputWeight?1:0:this.overrideBlink==="blend"?this.outputWeight:0}get overrideLookAtAmount(){return this.overrideLookAt==="block"?0<this.outputWeight?1:0:this.overrideLookAt==="blend"?this.outputWeight:0}get overrideMouthAmount(){return this.overrideMouth==="block"?0<this.outputWeight?1:0:this.overrideMouth==="blend"?this.outputWeight:0}get outputWeight(){return this.isBinary?this.weight>.5?1:0:this.weight}addBind(t){this._binds.push(t)}deleteBind(t){let r=this._binds.indexOf(t);r>=0&&this._binds.splice(r,1)}applyWeight(t){var o;let r=this.outputWeight;r*=(o=t==null?void 0:t.multiplier)!=null?o:1,this.isBinary&&r<1&&(r=0),this._binds.forEach(i=>i.applyWeight(r))}clearAppliedWeight(){this._binds.forEach(t=>t.clearAppliedWeight())}};import*as S from"three";function Ce(u,e,t){var a,d;let r=u.parser.json,o=(a=r.nodes)==null?void 0:a[e];if(o==null)return console.warn(`extractPrimitivesInternal: Attempt to use nodes[${e}] of glTF but the node doesn't exist`),null;let i=o.mesh;if(i==null)return null;let n=(d=r.meshes)==null?void 0:d[i];if(n==null)return console.warn(`extractPrimitivesInternal: Attempt to use meshes[${i}] of glTF but the mesh doesn't exist`),null;let l=n.primitives.length,s=[];return t.traverse(c=>{s.length<l&&c.isMesh&&s.push(c)}),s}function Ae(u,e){return R(this,null,function*(){let t=yield u.parser.getDependency("node",e);return Ce(u,e,t)})}function we(u){return R(this,null,function*(){let e=yield u.parser.getDependencies("node"),t=new Map;return e.forEach((r,o)=>{let i=Ce(u,o,r);i!=null&&t.set(o,i)}),t})}var q={Aa:"aa",Ih:"ih",Ou:"ou",Ee:"ee",Oh:"oh",Blink:"blink",Happy:"happy",Angry:"angry",Sad:"sad",Relaxed:"relaxed",LookUp:"lookUp",Surprised:"surprised",LookDown:"lookDown",LookLeft:"lookLeft",LookRight:"lookRight",BlinkLeft:"blinkLeft",BlinkRight:"blinkRight",Neutral:"neutral"};function ge(u){return Math.max(Math.min(u,1),0)}var Y=class u{constructor(){this.blinkExpressionNames=["blink","blinkLeft","blinkRight"];this.lookAtExpressionNames=["lookLeft","lookRight","lookUp","lookDown"];this.mouthExpressionNames=["aa","ee","ih","oh","ou"];this._expressions=[];this._expressionMap={}}get expressions(){return this._expressions.concat()}get expressionMap(){return Object.assign({},this._expressionMap)}get presetExpressionMap(){let e={},t=new Set(Object.values(q));return Object.entries(this._expressionMap).forEach(([r,o])=>{t.has(r)&&(e[r]=o)}),e}get customExpressionMap(){let e={},t=new Set(Object.values(q));return Object.entries(this._expressionMap).forEach(([r,o])=>{t.has(r)||(e[r]=o)}),e}copy(e){return this._expressions.concat().forEach(r=>{this.unregisterExpression(r)}),e._expressions.forEach(r=>{this.registerExpression(r)}),this.blinkExpressionNames=e.blinkExpressionNames.concat(),this.lookAtExpressionNames=e.lookAtExpressionNames.concat(),this.mouthExpressionNames=e.mouthExpressionNames.concat(),this}clone(){return new u().copy(this)}getExpression(e){var t;return(t=this._expressionMap[e])!=null?t:null}registerExpression(e){this._expressions.push(e),this._expressionMap[e.expressionName]=e}unregisterExpression(e){let t=this._expressions.indexOf(e);t===-1&&console.warn("VRMExpressionManager: The specified expressions is not registered"),this._expressions.splice(t,1),delete this._expressionMap[e.expressionName]}getValue(e){var r;let t=this.getExpression(e);return(r=t==null?void 0:t.weight)!=null?r:null}setValue(e,t){let r=this.getExpression(e);r&&(r.weight=ge(t))}resetValues(){this._expressions.forEach(e=>{e.weight=0})}getExpressionTrackName(e){let t=this.getExpression(e);return t?`${t.name}.weight`:null}update(){let e=this._calculateWeightMultipliers();this._expressions.forEach(t=>{t.clearAppliedWeight()}),this._expressions.forEach(t=>{let r=1,o=t.expressionName;this.blinkExpressionNames.indexOf(o)!==-1&&(r*=e.blink),this.lookAtExpressionNames.indexOf(o)!==-1&&(r*=e.lookAt),this.mouthExpressionNames.indexOf(o)!==-1&&(r*=e.mouth),t.applyWeight({multiplier:r})})}_calculateWeightMultipliers(){let e=1,t=1,r=1;return this._expressions.forEach(o=>{e-=o.overrideBlinkAmount,t-=o.overrideLookAtAmount,r-=o.overrideMouthAmount}),e=Math.max(0,e),t=Math.max(0,t),r=Math.max(0,r),{blink:e,lookAt:t,mouth:r}}};var $={Color:"color",EmissionColor:"emissionColor",ShadeColor:"shadeColor",MatcapColor:"matcapColor",RimColor:"rimColor",OutlineColor:"outlineColor"},We={_Color:$.Color,_EmissionColor:$.EmissionColor,_ShadeColor:$.ShadeColor,_RimColor:$.RimColor,_OutlineColor:$.OutlineColor};import*as ve from"three";var rt=new ve.Color,Ve=class Ve{constructor({material:e,type:t,targetValue:r,targetAlpha:o}){this.material=e,this.type=t,this.targetValue=r,this.targetAlpha=o!=null?o:1;let i=this._initColorBindState(),n=this._initAlphaBindState();this._state={color:i,alpha:n}}applyWeight(e){let{color:t,alpha:r}=this._state;if(t!=null){let{propertyName:o,deltaValue:i}=t,n=this.material[o];n!=null&&n.add(rt.copy(i).multiplyScalar(e))}if(r!=null){let{propertyName:o,deltaValue:i}=r;this.material[o]!=null&&(this.material[o]+=i*e)}}clearAppliedWeight(){let{color:e,alpha:t}=this._state;if(e!=null){let{propertyName:r,initialValue:o}=e,i=this.material[r];i!=null&&i.copy(o)}if(t!=null){let{propertyName:r,initialValue:o}=t;this.material[r]!=null&&(this.material[r]=o)}}_initColorBindState(){var a,d,c;let{material:e,type:t,targetValue:r}=this,o=this._getPropertyNameMap(),i=(d=(a=o==null?void 0:o[t])==null?void 0:a[0])!=null?d:null;if(i==null)return console.warn(`Tried to add a material color bind to the material ${(c=e.name)!=null?c:"(no name)"}, the type ${t} but the material or the type is not supported.`),null;let l=e[i].clone(),s=new ve.Color(r.r-l.r,r.g-l.g,r.b-l.b);return{propertyName:i,initialValue:l,deltaValue:s}}_initAlphaBindState(){var s,a,d;let{material:e,type:t,targetAlpha:r}=this,o=this._getPropertyNameMap(),i=(a=(s=o==null?void 0:o[t])==null?void 0:s[1])!=null?a:null;if(i==null&&r!==1)return console.warn(`Tried to add a material alpha bind to the material ${(d=e.name)!=null?d:"(no name)"}, the type ${t} but the material or the type does not support alpha.`),null;if(i==null)return null;let n=e[i],l=r-n;return{propertyName:i,initialValue:n,deltaValue:l}}_getPropertyNameMap(){var e,t;return(t=(e=Object.entries(Ve._propertyNameMapMap).find(([r])=>this.material[r]===!0))==null?void 0:e[1])!=null?t:null}};Ve._propertyNameMapMap={isMeshStandardMaterial:{color:["color","opacity"],emissionColor:["emissive",null]},isMeshBasicMaterial:{color:["color","opacity"]},isMToonMaterial:{color:["color","opacity"],emissionColor:["emissive",null],outlineColor:["outlineColorFactor",null],matcapColor:["matcapFactor",null],rimColor:["parametricRimColorFactor",null],shadeColor:["shadeColorFactor",null]}};var X=Ve;var Z=class{constructor({primitives:e,index:t,weight:r}){this.primitives=e,this.index=t,this.weight=r}applyWeight(e){this.primitives.forEach(t=>{var r;((r=t.morphTargetInfluences)==null?void 0:r[this.index])!=null&&(t.morphTargetInfluences[this.index]+=this.weight*e)})}clearAppliedWeight(){this.primitives.forEach(e=>{var t;((t=e.morphTargetInfluences)==null?void 0:t[this.index])!=null&&(e.morphTargetInfluences[this.index]=0)})}};import*as Qe from"three";var je=new Qe.Vector2,ye=class ye{constructor({material:e,scale:t,offset:r}){var i,n;this.material=e,this.scale=t,this.offset=r;let o=(i=Object.entries(ye._propertyNamesMap).find(([l])=>e[l]===!0))==null?void 0:i[1];o==null?(console.warn(`Tried to add a texture transform bind to the material ${(n=e.name)!=null?n:"(no name)"} but the material is not supported.`),this._properties=[]):(this._properties=[],o.forEach(l=>{var m;let s=(m=e[l])==null?void 0:m.clone();if(!s)return null;e[l]=s;let a=s.offset.clone(),d=s.repeat.clone(),c=r.clone().sub(a),p=t.clone().sub(d);this._properties.push({name:l,initialOffset:a,deltaOffset:c,initialScale:d,deltaScale:p})}))}applyWeight(e){this._properties.forEach(t=>{let r=this.material[t.name];r!==void 0&&(r.offset.add(je.copy(t.deltaOffset).multiplyScalar(e)),r.repeat.add(je.copy(t.deltaScale).multiplyScalar(e)))})}clearAppliedWeight(){this._properties.forEach(e=>{let t=this.material[e.name];t!==void 0&&(t.offset.copy(e.initialOffset),t.repeat.copy(e.initialScale))})}};ye._propertyNamesMap={isMeshStandardMaterial:["map","emissiveMap","bumpMap","normalMap","displacementMap","roughnessMap","metalnessMap","alphaMap"],isMeshBasicMaterial:["map","specularMap","alphaMap"],isMToonMaterial:["map","normalMap","emissiveMap","shadeMultiplyTexture","rimMultiplyTexture","outlineWidthMultiplyTexture","uvAnimationMaskTexture"]};var J=ye;var ot=new Set(["1.0","1.0-beta"]),xe=class xe{get name(){return"VRMExpressionLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return R(this,null,function*(){e.userData.vrmExpressionManager=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let r=yield this._v0Import(e);return r||null})}_v1Import(e){return R(this,null,function*(){var d,c;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(!o)return null;let i=o.specVersion;if(!ot.has(i))return console.warn(`VRMExpressionLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.expressions;if(!n)return null;let l=new Set(Object.values(q)),s=new Map;n.preset!=null&&Object.entries(n.preset).forEach(([p,m])=>{if(m!=null){if(!l.has(p)){console.warn(`VRMExpressionLoaderPlugin: Unknown preset name "${p}" detected. Ignoring the expression`);return}s.set(p,m)}}),n.custom!=null&&Object.entries(n.custom).forEach(([p,m])=>{if(l.has(p)){console.warn(`VRMExpressionLoaderPlugin: Custom expression cannot have preset name "${p}". Ignoring the expression`);return}s.set(p,m)});let a=new Y;return yield Promise.all(Array.from(s.entries()).map(M=>R(this,[M],function*([p,m]){var f,V,x,_,T,b,F;let h=new z(p);if(e.scene.add(h),h.isBinary=(f=m.isBinary)!=null?f:!1,h.overrideBlink=(V=m.overrideBlink)!=null?V:"none",h.overrideLookAt=(x=m.overrideLookAt)!=null?x:"none",h.overrideMouth=(_=m.overrideMouth)!=null?_:"none",(T=m.morphTargetBinds)==null||T.forEach(H=>R(this,null,function*(){var B;if(H.node===void 0||H.index===void 0)return;let L=yield Ae(e,H.node),v=H.index;if(!L.every(I=>Array.isArray(I.morphTargetInfluences)&&v<I.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${m.name} attempts to index morph #${v} but not found.`);return}h.addBind(new Z({primitives:L,index:v,weight:(B=H.weight)!=null?B:1}))})),m.materialColorBinds||m.textureTransformBinds){let H=[];e.scene.traverse(L=>{let v=L.material;v&&(Array.isArray(v)?H.push(...v):H.push(v))}),(b=m.materialColorBinds)==null||b.forEach(L=>R(this,null,function*(){H.filter(B=>{var O;let I=(O=this.parser.associations.get(B))==null?void 0:O.materials;return L.material===I}).forEach(B=>{h.addBind(new X({material:B,type:L.type,targetValue:new S.Color().fromArray(L.targetValue),targetAlpha:L.targetValue[3]}))})})),(F=m.textureTransformBinds)==null||F.forEach(L=>R(this,null,function*(){H.filter(B=>{var O;let I=(O=this.parser.associations.get(B))==null?void 0:O.materials;return L.material===I}).forEach(B=>{var I,O;h.addBind(new J({material:B,offset:new S.Vector2().fromArray((I=L.offset)!=null?I:[0,0]),scale:new S.Vector2().fromArray((O=L.scale)!=null?O:[1,1])}))})}))}a.registerExpression(h)}))),a})}_v0Import(e){return R(this,null,function*(){var s;let t=this.parser.json,r=(s=t.extensions)==null?void 0:s.VRM;if(!r)return null;let o=r.blendShapeMaster;if(!o)return null;let i=new Y,n=o.blendShapeGroups;if(!n)return i;let l=new Set;return yield Promise.all(n.map(a=>R(this,null,function*(){var h;let d=a.presetName,c=d!=null&&xe.v0v1PresetNameMap[d]||null,p=c!=null?c:a.name;if(p==null){console.warn("VRMExpressionLoaderPlugin: One of custom expressions has no name. Ignoring the expression");return}if(l.has(p)){console.warn(`VRMExpressionLoaderPlugin: An expression preset ${d} has duplicated entries. Ignoring the expression`);return}l.add(p);let m=new z(p);e.scene.add(m),m.isBinary=(h=a.isBinary)!=null?h:!1,a.binds&&a.binds.forEach(f=>R(this,null,function*(){var _;if(f.mesh===void 0||f.index===void 0)return;let V=[];(_=t.nodes)==null||_.forEach((T,b)=>{T.mesh===f.mesh&&V.push(b)});let x=f.index;yield Promise.all(V.map(T=>R(this,null,function*(){var F;let b=yield Ae(e,T);if(!b.every(H=>Array.isArray(H.morphTargetInfluences)&&x<H.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${a.name} attempts to index ${x}th morph but not found.`);return}m.addBind(new Z({primitives:b,index:x,weight:.01*((F=f.weight)!=null?F:100)}))})))}));let M=a.materialValues;M&&M.length!==0&&M.forEach(f=>{if(f.materialName===void 0||f.propertyName===void 0||f.targetValue===void 0)return;let V=[];e.scene.traverse(_=>{if(_.material){let T=_.material;Array.isArray(T)?V.push(...T.filter(b=>(b.name===f.materialName||b.name===f.materialName+" (Outline)")&&V.indexOf(b)===-1)):T.name===f.materialName&&V.indexOf(T)===-1&&V.push(T)}});let x=f.propertyName;V.forEach(_=>{if(x==="_MainTex_ST"){let b=new S.Vector2(f.targetValue[0],f.targetValue[1]),F=new S.Vector2(f.targetValue[2],f.targetValue[3]);F.y=1-F.y-b.y,m.addBind(new J({material:_,scale:b,offset:F}));return}let T=We[x];if(T){m.addBind(new X({material:_,type:T,targetValue:new S.Color().fromArray(f.targetValue),targetAlpha:f.targetValue[3]}));return}console.warn(x+" is not supported")})}),i.registerExpression(m)}))),i})}};xe.v0v1PresetNameMap={a:"aa",e:"ee",i:"ih",o:"oh",u:"ou",blink:"blink",joy:"happy",angry:"angry",sorrow:"sad",fun:"relaxed",lookup:"lookUp",lookdown:"lookDown",lookleft:"lookLeft",lookright:"lookRight",blink_l:"blinkLeft",blink_r:"blinkRight",neutral:"neutral"};var ie=xe;var nt={None:"none",Block:"block",Blend:"blend"};import*as A from"three";var N=class N{constructor(e,t){this._firstPersonOnlyLayer=N.DEFAULT_FIRSTPERSON_ONLY_LAYER;this._thirdPersonOnlyLayer=N.DEFAULT_THIRDPERSON_ONLY_LAYER;this._initializedLayers=!1;this.humanoid=e,this.meshAnnotations=t}copy(e){if(this.humanoid!==e.humanoid)throw new Error("VRMFirstPerson: humanoid must be same in order to copy");return this.meshAnnotations=e.meshAnnotations.map(t=>({meshes:t.meshes.concat(),type:t.type})),this}clone(){return new N(this.humanoid,this.meshAnnotations).copy(this)}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}setup({firstPersonOnlyLayer:e=N.DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:t=N.DEFAULT_THIRDPERSON_ONLY_LAYER}={}){this._initializedLayers||(this._firstPersonOnlyLayer=e,this._thirdPersonOnlyLayer=t,this.meshAnnotations.forEach(r=>{r.meshes.forEach(o=>{r.type==="firstPersonOnly"?(o.layers.set(this._firstPersonOnlyLayer),o.traverse(i=>i.layers.set(this._firstPersonOnlyLayer))):r.type==="thirdPersonOnly"?(o.layers.set(this._thirdPersonOnlyLayer),o.traverse(i=>i.layers.set(this._thirdPersonOnlyLayer))):r.type==="auto"&&this._createHeadlessModel(o)})}),this._initializedLayers=!0)}_excludeTriangles(e,t,r,o){let i=0;if(t!=null&&t.length>0)for(let n=0;n<e.length;n+=3){let l=e[n],s=e[n+1],a=e[n+2],d=t[l],c=r[l];if(d[0]>0&&o.includes(c[0])||d[1]>0&&o.includes(c[1])||d[2]>0&&o.includes(c[2])||d[3]>0&&o.includes(c[3]))continue;let p=t[s],m=r[s];if(p[0]>0&&o.includes(m[0])||p[1]>0&&o.includes(m[1])||p[2]>0&&o.includes(m[2])||p[3]>0&&o.includes(m[3]))continue;let M=t[a],h=r[a];M[0]>0&&o.includes(h[0])||M[1]>0&&o.includes(h[1])||M[2]>0&&o.includes(h[2])||M[3]>0&&o.includes(h[3])||(e[i++]=l,e[i++]=s,e[i++]=a)}return i}_createErasedMesh(e,t){let r=new A.SkinnedMesh(e.geometry.clone(),e.material);r.name=`${e.name}(erase)`,r.frustumCulled=e.frustumCulled,r.layers.set(this._firstPersonOnlyLayer);let o=r.geometry,i=o.getAttribute("skinIndex"),n=i instanceof A.GLBufferAttribute?[]:i.array,l=[];for(let h=0;h<n.length;h+=4)l.push([n[h],n[h+1],n[h+2],n[h+3]]);let s=o.getAttribute("skinWeight"),a=s instanceof A.GLBufferAttribute?[]:s.array,d=[];for(let h=0;h<a.length;h+=4)d.push([a[h],a[h+1],a[h+2],a[h+3]]);let c=o.getIndex();if(!c)throw new Error("The geometry doesn't have an index buffer");let p=Array.from(c.array),m=this._excludeTriangles(p,d,l,t),M=[];for(let h=0;h<m;h++)M[h]=p[h];return o.setIndex(M),e.onBeforeRender&&(r.onBeforeRender=e.onBeforeRender),r.bind(new A.Skeleton(e.skeleton.bones,e.skeleton.boneInverses),new A.Matrix4),r}_createHeadlessModelForSkinnedMesh(e,t){let r=[];if(t.skeleton.bones.forEach((i,n)=>{this._isEraseTarget(i)&&r.push(n)}),!r.length){t.layers.enable(this._thirdPersonOnlyLayer),t.layers.enable(this._firstPersonOnlyLayer);return}t.layers.set(this._thirdPersonOnlyLayer);let o=this._createErasedMesh(t,r);e.add(o)}_createHeadlessModel(e){if(e.type==="Group")if(e.layers.set(this._thirdPersonOnlyLayer),this._isEraseTarget(e))e.traverse(t=>t.layers.set(this._thirdPersonOnlyLayer));else{let t=new A.Group;t.name=`_headless_${e.name}`,t.layers.set(this._firstPersonOnlyLayer),e.parent.add(t),e.children.filter(r=>r.type==="SkinnedMesh").forEach(r=>{let o=r;this._createHeadlessModelForSkinnedMesh(t,o)})}else if(e.type==="SkinnedMesh"){let t=e;this._createHeadlessModelForSkinnedMesh(e.parent,t)}else this._isEraseTarget(e)&&(e.layers.set(this._thirdPersonOnlyLayer),e.traverse(t=>t.layers.set(this._thirdPersonOnlyLayer)))}_isEraseTarget(e){return e===this.humanoid.getRawBoneNode("head")?!0:e.parent?this._isEraseTarget(e.parent):!1}};N.DEFAULT_FIRSTPERSON_ONLY_LAYER=9,N.DEFAULT_THIRDPERSON_ONLY_LAYER=10;var K=N;var it=new Set(["1.0","1.0-beta"]),se=class{get name(){return"VRMFirstPersonLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return R(this,null,function*(){let t=e.userData.vrmHumanoid;if(t!==null){if(t===void 0)throw new Error("VRMFirstPersonLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");e.userData.vrmFirstPerson=yield this._import(e,t)}})}_import(e,t){return R(this,null,function*(){if(t==null)return null;let r=yield this._v1Import(e,t);if(r)return r;let o=yield this._v0Import(e,t);return o||null})}_v1Import(e,t){return R(this,null,function*(){var d,c;let r=this.parser.json;if(!(((d=r.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let i=(c=r.extensions)==null?void 0:c.VRMC_vrm;if(!i)return null;let n=i.specVersion;if(!it.has(n))return console.warn(`VRMFirstPersonLoaderPlugin: Unknown VRMC_vrm specVersion "${n}"`),null;let l=i.firstPerson,s=[],a=yield we(e);return Array.from(a.entries()).forEach(([p,m])=>{var h,f;let M=(h=l==null?void 0:l.meshAnnotations)==null?void 0:h.find(V=>V.node===p);s.push({meshes:m,type:(f=M==null?void 0:M.type)!=null?f:"auto"})}),new K(t,s)})}_v0Import(e,t){return R(this,null,function*(){var s;let r=this.parser.json,o=(s=r.extensions)==null?void 0:s.VRM;if(!o)return null;let i=o.firstPerson;if(!i)return null;let n=[],l=yield we(e);return Array.from(l.entries()).forEach(([a,d])=>{let c=r.nodes[a],p=i.meshAnnotations?i.meshAnnotations.find(m=>m.mesh===c.mesh):void 0;n.push({meshes:d,type:this._convertV0FlagToV1Type(p==null?void 0:p.firstPersonFlag)})}),new K(t,n)})}_convertV0FlagToV1Type(e){return e==="FirstPersonOnly"?"firstPersonOnly":e==="ThirdPersonOnly"?"thirdPersonOnly":e==="Both"?"both":"auto"}};var st={Auto:"auto",Both:"both",ThirdPersonOnly:"thirdPersonOnly",FirstPersonOnly:"firstPersonOnly"};import*as U from"three";var ze=new U.Vector3,qe=new U.Vector3,at=new U.Quaternion,ee=class extends U.Group{constructor(e){super(),this.vrmHumanoid=e,this._boneAxesMap=new Map,Object.values(e.humanBones).forEach(t=>{let r=new U.AxesHelper(1);r.matrixAutoUpdate=!1,r.material.depthTest=!1,r.material.depthWrite=!1,this.add(r),this._boneAxesMap.set(t,r)})}dispose(){Array.from(this._boneAxesMap.values()).forEach(e=>{e.geometry.dispose(),e.material.dispose()})}updateMatrixWorld(e){Array.from(this._boneAxesMap.entries()).forEach(([t,r])=>{t.node.updateWorldMatrix(!0,!1),t.node.matrixWorld.decompose(ze,at,qe);let o=ze.set(.1,.1,.1).divide(qe);r.matrix.copy(t.node.matrixWorld).scale(o)}),super.updateMatrixWorld(e)}};var ae=["hips","spine","chest","upperChest","neck","head","leftEye","rightEye","jaw","leftUpperLeg","leftLowerLeg","leftFoot","leftToes","rightUpperLeg","rightLowerLeg","rightFoot","rightToes","leftShoulder","leftUpperArm","leftLowerArm","leftHand","rightShoulder","rightUpperArm","rightLowerArm","rightHand","leftThumbMetacarpal","leftThumbProximal","leftThumbDistal","leftIndexProximal","leftIndexIntermediate","leftIndexDistal","leftMiddleProximal","leftMiddleIntermediate","leftMiddleDistal","leftRingProximal","leftRingIntermediate","leftRingDistal","leftLittleProximal","leftLittleIntermediate","leftLittleDistal","rightThumbMetacarpal","rightThumbProximal","rightThumbDistal","rightIndexProximal","rightIndexIntermediate","rightIndexDistal","rightMiddleProximal","rightMiddleIntermediate","rightMiddleDistal","rightRingProximal","rightRingIntermediate","rightRingDistal","rightLittleProximal","rightLittleIntermediate","rightLittleDistal"];var lt={Hips:"hips",Spine:"spine",Chest:"chest",UpperChest:"upperChest",Neck:"neck",Head:"head",LeftEye:"leftEye",RightEye:"rightEye",Jaw:"jaw",LeftUpperLeg:"leftUpperLeg",LeftLowerLeg:"leftLowerLeg",LeftFoot:"leftFoot",LeftToes:"leftToes",RightUpperLeg:"rightUpperLeg",RightLowerLeg:"rightLowerLeg",RightFoot:"rightFoot",RightToes:"rightToes",LeftShoulder:"leftShoulder",LeftUpperArm:"leftUpperArm",LeftLowerArm:"leftLowerArm",LeftHand:"leftHand",RightShoulder:"rightShoulder",RightUpperArm:"rightUpperArm",RightLowerArm:"rightLowerArm",RightHand:"rightHand",LeftThumbMetacarpal:"leftThumbMetacarpal",LeftThumbProximal:"leftThumbProximal",LeftThumbDistal:"leftThumbDistal",LeftIndexProximal:"leftIndexProximal",LeftIndexIntermediate:"leftIndexIntermediate",LeftIndexDistal:"leftIndexDistal",LeftMiddleProximal:"leftMiddleProximal",LeftMiddleIntermediate:"leftMiddleIntermediate",LeftMiddleDistal:"leftMiddleDistal",LeftRingProximal:"leftRingProximal",LeftRingIntermediate:"leftRingIntermediate",LeftRingDistal:"leftRingDistal",LeftLittleProximal:"leftLittleProximal",LeftLittleIntermediate:"leftLittleIntermediate",LeftLittleDistal:"leftLittleDistal",RightThumbMetacarpal:"rightThumbMetacarpal",RightThumbProximal:"rightThumbProximal",RightThumbDistal:"rightThumbDistal",RightIndexProximal:"rightIndexProximal",RightIndexIntermediate:"rightIndexIntermediate",RightIndexDistal:"rightIndexDistal",RightMiddleProximal:"rightMiddleProximal",RightMiddleIntermediate:"rightMiddleIntermediate",RightMiddleDistal:"rightMiddleDistal",RightRingProximal:"rightRingProximal",RightRingIntermediate:"rightRingIntermediate",RightRingDistal:"rightRingDistal",RightLittleProximal:"rightLittleProximal",RightLittleIntermediate:"rightLittleIntermediate",RightLittleDistal:"rightLittleDistal"};var Be={hips:null,spine:"hips",chest:"spine",upperChest:"chest",neck:"upperChest",head:"neck",leftEye:"head",rightEye:"head",jaw:"head",leftUpperLeg:"hips",leftLowerLeg:"leftUpperLeg",leftFoot:"leftLowerLeg",leftToes:"leftFoot",rightUpperLeg:"hips",rightLowerLeg:"rightUpperLeg",rightFoot:"rightLowerLeg",rightToes:"rightFoot",leftShoulder:"upperChest",leftUpperArm:"leftShoulder",leftLowerArm:"leftUpperArm",leftHand:"leftLowerArm",rightShoulder:"upperChest",rightUpperArm:"rightShoulder",rightLowerArm:"rightUpperArm",rightHand:"rightLowerArm",leftThumbMetacarpal:"leftHand",leftThumbProximal:"leftThumbMetacarpal",leftThumbDistal:"leftThumbProximal",leftIndexProximal:"leftHand",leftIndexIntermediate:"leftIndexProximal",leftIndexDistal:"leftIndexIntermediate",leftMiddleProximal:"leftHand",leftMiddleIntermediate:"leftMiddleProximal",leftMiddleDistal:"leftMiddleIntermediate",leftRingProximal:"leftHand",leftRingIntermediate:"leftRingProximal",leftRingDistal:"leftRingIntermediate",leftLittleProximal:"leftHand",leftLittleIntermediate:"leftLittleProximal",leftLittleDistal:"leftLittleIntermediate",rightThumbMetacarpal:"rightHand",rightThumbProximal:"rightThumbMetacarpal",rightThumbDistal:"rightThumbProximal",rightIndexProximal:"rightHand",rightIndexIntermediate:"rightIndexProximal",rightIndexDistal:"rightIndexIntermediate",rightMiddleProximal:"rightHand",rightMiddleIntermediate:"rightMiddleProximal",rightMiddleDistal:"rightMiddleIntermediate",rightRingProximal:"rightHand",rightRingIntermediate:"rightRingProximal",rightRingDistal:"rightRingIntermediate",rightLittleProximal:"rightHand",rightLittleIntermediate:"rightLittleProximal",rightLittleDistal:"rightLittleIntermediate"};import*as be from"three";function Te(u){return u.invert?u.invert():u.inverse(),u}var C=new be.Vector3,W=new be.Quaternion,j=class{constructor(e){this.humanBones=e,this.restPose=this.getAbsolutePose()}getAbsolutePose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let r=t,o=this.getBoneNode(r);o&&(C.copy(o.position),W.copy(o.quaternion),e[r]={position:C.toArray(),rotation:W.toArray()})}),e}getPose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let r=t,o=this.getBoneNode(r);if(!o)return;C.set(0,0,0),W.identity();let i=this.restPose[r];i!=null&&i.position&&C.fromArray(i.position).negate(),i!=null&&i.rotation&&Te(W.fromArray(i.rotation)),C.add(o.position),W.premultiply(o.quaternion),e[r]={position:C.toArray(),rotation:W.toArray()}}),e}setPose(e){Object.entries(e).forEach(([t,r])=>{let o=t,i=this.getBoneNode(o);if(!i)return;let n=this.restPose[o];n&&(r!=null&&r.position&&(i.position.fromArray(r.position),n.position&&i.position.add(C.fromArray(n.position))),r!=null&&r.rotation&&(i.quaternion.fromArray(r.rotation),n.rotation&&i.quaternion.multiply(W.fromArray(n.rotation))))})}resetPose(){Object.entries(this.restPose).forEach(([e,t])=>{let r=this.getBoneNode(e);r&&(t!=null&&t.position&&r.position.fromArray(t.position),t!=null&&t.rotation&&r.quaternion.fromArray(t.rotation))})}getBone(e){var t;return(t=this.humanBones[e])!=null?t:void 0}getBoneNode(e){var t,r;return(r=(t=this.humanBones[e])==null?void 0:t.node)!=null?r:null}};import*as w from"three";var ke=new w.Vector3,ut=new w.Quaternion,pt=new w.Vector3,le=class u extends j{static _setupTransforms(e){let t=new w.Object3D;t.name="VRMHumanoidRig";let r={},o={},i={},n={};ae.forEach(s=>{var d;let a=e.getBoneNode(s);if(a){let c=new w.Vector3,p=new w.Quaternion;a.updateWorldMatrix(!0,!1),a.matrixWorld.decompose(c,p,ke),r[s]=c,o[s]=p,i[s]=a.quaternion.clone();let m=new w.Quaternion;(d=a.parent)==null||d.matrixWorld.decompose(ke,m,ke),n[s]=m}});let l={};return ae.forEach(s=>{var d;let a=e.getBoneNode(s);if(a){let c=r[s],p=s,m;for(;m==null&&(p=Be[p],p!=null);)m=r[p];let M=new w.Object3D;M.name="Normalized_"+a.name,(p?(d=l[p])==null?void 0:d.node:t).add(M),M.position.copy(c),m&&M.position.sub(m),l[s]={node:M}}}),{rigBones:l,root:t,parentWorldRotations:n,boneRotations:i}}constructor(e){let{rigBones:t,root:r,parentWorldRotations:o,boneRotations:i}=u._setupTransforms(e);super(t),this.original=e,this.root=r,this._parentWorldRotations=o,this._boneRotations=i}update(){ae.forEach(e=>{let t=this.original.getBoneNode(e);if(t!=null){let r=this.getBoneNode(e),o=this._parentWorldRotations[e],i=ut.copy(o).invert(),n=this._boneRotations[e];if(t.quaternion.copy(r.quaternion).multiply(o).premultiply(i).multiply(n),e==="hips"){let l=r.getWorldPosition(pt);t.parent.updateWorldMatrix(!0,!1);let s=t.parent.matrixWorld,a=l.applyMatrix4(s.invert());t.position.copy(a)}}})}};var te=class u{get restPose(){return console.warn("VRMHumanoid: restPose is deprecated. Use either rawRestPose or normalizedRestPose instead."),this.rawRestPose}get rawRestPose(){return this._rawHumanBones.restPose}get normalizedRestPose(){return this._normalizedHumanBones.restPose}get humanBones(){return this._rawHumanBones.humanBones}get rawHumanBones(){return this._rawHumanBones.humanBones}get normalizedHumanBones(){return this._normalizedHumanBones.humanBones}get normalizedHumanBonesRoot(){return this._normalizedHumanBones.root}constructor(e,t){var r;this.autoUpdateHumanBones=(r=t==null?void 0:t.autoUpdateHumanBones)!=null?r:!0,this._rawHumanBones=new j(e),this._normalizedHumanBones=new le(this._rawHumanBones)}copy(e){return this.autoUpdateHumanBones=e.autoUpdateHumanBones,this._rawHumanBones=new j(e.humanBones),this._normalizedHumanBones=new le(this._rawHumanBones),this}clone(){return new u(this.humanBones,{autoUpdateHumanBones:this.autoUpdateHumanBones}).copy(this)}getAbsolutePose(){return console.warn("VRMHumanoid: getAbsolutePose() is deprecated. Use either getRawAbsolutePose() or getNormalizedAbsolutePose() instead."),this.getRawAbsolutePose()}getRawAbsolutePose(){return this._rawHumanBones.getAbsolutePose()}getNormalizedAbsolutePose(){return this._normalizedHumanBones.getAbsolutePose()}getPose(){return console.warn("VRMHumanoid: getPose() is deprecated. Use either getRawPose() or getNormalizedPose() instead."),this.getRawPose()}getRawPose(){return this._rawHumanBones.getPose()}getNormalizedPose(){return this._normalizedHumanBones.getPose()}setPose(e){return console.warn("VRMHumanoid: setPose() is deprecated. Use either setRawPose() or setNormalizedPose() instead."),this.setRawPose(e)}setRawPose(e){return this._rawHumanBones.setPose(e)}setNormalizedPose(e){return this._normalizedHumanBones.setPose(e)}resetPose(){return console.warn("VRMHumanoid: resetPose() is deprecated. Use either resetRawPose() or resetNormalizedPose() instead."),this.resetRawPose()}resetRawPose(){return this._rawHumanBones.resetPose()}resetNormalizedPose(){return this._normalizedHumanBones.resetPose()}getBone(e){return console.warn("VRMHumanoid: getBone() is deprecated. Use either getRawBone() or getNormalizedBone() instead."),this.getRawBone(e)}getRawBone(e){return this._rawHumanBones.getBone(e)}getNormalizedBone(e){return this._normalizedHumanBones.getBone(e)}getBoneNode(e){return console.warn("VRMHumanoid: getBoneNode() is deprecated. Use either getRawBoneNode() or getNormalizedBoneNode() instead."),this.getRawBoneNode(e)}getRawBoneNode(e){return this._rawHumanBones.getBoneNode(e)}getNormalizedBoneNode(e){return this._normalizedHumanBones.getBoneNode(e)}update(){this.autoUpdateHumanBones&&this._normalizedHumanBones.update()}};var Fe={Hips:"hips",Spine:"spine",Head:"head",LeftUpperLeg:"leftUpperLeg",LeftLowerLeg:"leftLowerLeg",LeftFoot:"leftFoot",RightUpperLeg:"rightUpperLeg",RightLowerLeg:"rightLowerLeg",RightFoot:"rightFoot",LeftUpperArm:"leftUpperArm",LeftLowerArm:"leftLowerArm",LeftHand:"leftHand",RightUpperArm:"rightUpperArm",RightLowerArm:"rightLowerArm",RightHand:"rightHand"};var mt=new Set(["1.0","1.0-beta"]),Ye={leftThumbProximal:"leftThumbMetacarpal",leftThumbIntermediate:"leftThumbProximal",rightThumbProximal:"rightThumbMetacarpal",rightThumbIntermediate:"rightThumbProximal"},ue=class{get name(){return"VRMHumanoidLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot,this.autoUpdateHumanBones=t==null?void 0:t.autoUpdateHumanBones}afterRoot(e){return R(this,null,function*(){e.userData.vrmHumanoid=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let r=yield this._v0Import(e);return r||null})}_v1Import(e){return R(this,null,function*(){var d,c;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(!o)return null;let i=o.specVersion;if(!mt.has(i))return console.warn(`VRMHumanoidLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.humanoid;if(!n)return null;let l=n.humanBones.leftThumbIntermediate!=null||n.humanBones.rightThumbIntermediate!=null,s={};n.humanBones!=null&&(yield Promise.all(Object.entries(n.humanBones).map(M=>R(this,[M],function*([p,m]){let h=p,f=m.node;if(l){let x=Ye[h];x!=null&&(h=x)}let V=yield this.parser.getDependency("node",f);if(V==null){console.warn(`A glTF node bound to the humanoid bone ${h} (index = ${f}) does not exist`);return}s[h]={node:V}}))));let a=new te(this._ensureRequiredBonesExist(s),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(a.normalizedHumanBonesRoot),this.helperRoot){let p=new ee(a);this.helperRoot.add(p),p.renderOrder=this.helperRoot.renderOrder}return a})}_v0Import(e){return R(this,null,function*(){var l;let r=(l=this.parser.json.extensions)==null?void 0:l.VRM;if(!r)return null;let o=r.humanoid;if(!o)return null;let i={};o.humanBones!=null&&(yield Promise.all(o.humanBones.map(s=>R(this,null,function*(){let a=s.bone,d=s.node;if(a==null||d==null)return;let c=yield this.parser.getDependency("node",d);if(c==null){console.warn(`A glTF node bound to the humanoid bone ${a} (index = ${d}) does not exist`);return}let p=Ye[a],m=p!=null?p:a;if(i[m]!=null){console.warn(`Multiple bone entries for ${m} detected (index = ${d}), ignoring duplicated entries.`);return}i[m]={node:c}}))));let n=new te(this._ensureRequiredBonesExist(i),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(n.normalizedHumanBonesRoot),this.helperRoot){let s=new ee(n);this.helperRoot.add(s),s.renderOrder=this.helperRoot.renderOrder}return n})}_ensureRequiredBonesExist(e){let t=Object.values(Fe).filter(r=>e[r]==null);if(t.length>0)throw new Error(`VRMHumanoidLoaderPlugin: These humanoid bones are required but not exist: ${t.join(", ")}`);return e}};import*as E from"three";import*as pe from"three";var me=class extends pe.BufferGeometry{constructor(){super();this._currentTheta=0;this._currentRadius=0;this.theta=0,this.radius=0,this._currentTheta=0,this._currentRadius=0,this._attrPos=new pe.BufferAttribute(new Float32Array(195),3),this.setAttribute("position",this._attrPos),this._attrIndex=new pe.BufferAttribute(new Uint16Array(189),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentTheta!==this.theta&&(this._currentTheta=this.theta,t=!0),this._currentRadius!==this.radius&&(this._currentRadius=this.radius,t=!0),t&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,0,0,0);for(let t=0;t<64;t++){let r=t/63*this._currentTheta;this._attrPos.setXYZ(t+1,this._currentRadius*Math.sin(r),0,this._currentRadius*Math.cos(r))}this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<63;t++)this._attrIndex.setXYZ(t*3,0,t+1,t+2);this._attrIndex.needsUpdate=!0}};import*as D from"three";var He=class extends D.BufferGeometry{constructor(){super(),this.radius=0,this._currentRadius=0,this.tail=new D.Vector3,this._currentTail=new D.Vector3,this._attrPos=new D.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new D.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;this._currentRadius!==this.radius&&(this._currentRadius=this.radius,e=!0),this._currentTail.equals(this.tail)||(this._currentTail.copy(this.tail),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){let t=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(t),Math.sin(t),0),this._attrPos.setXYZ(32+e,0,Math.cos(t),Math.sin(t)),this._attrPos.setXYZ(64+e,Math.sin(t),0,Math.cos(t))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<32;e++){let t=(e+1)%32;this._attrIndex.setXY(e*2,e,t),this._attrIndex.setXY(64+e*2,32+e,32+t),this._attrIndex.setXY(128+e*2,64+e,64+t)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}};var Le=new E.Quaternion,$e=new E.Quaternion,de=new E.Vector3,Xe=new E.Vector3,Ze=Math.sqrt(2)/2,dt=new E.Quaternion(0,0,-Ze,Ze),ht=new E.Vector3(0,1,0),he=class extends E.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.vrmLookAt=e;{let t=new me;t.radius=.5;let r=new E.MeshBasicMaterial({color:65280,transparent:!0,opacity:.5,side:E.DoubleSide,depthTest:!1,depthWrite:!1});this._meshPitch=new E.Mesh(t,r),this.add(this._meshPitch)}{let t=new me;t.radius=.5;let r=new E.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.5,side:E.DoubleSide,depthTest:!1,depthWrite:!1});this._meshYaw=new E.Mesh(t,r),this.add(this._meshYaw)}{let t=new He;t.radius=.1;let r=new E.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1});this._lineTarget=new E.LineSegments(t,r),this._lineTarget.frustumCulled=!1,this.add(this._lineTarget)}}dispose(){this._meshYaw.geometry.dispose(),this._meshYaw.material.dispose(),this._meshPitch.geometry.dispose(),this._meshPitch.material.dispose(),this._lineTarget.geometry.dispose(),this._lineTarget.material.dispose()}updateMatrixWorld(e){let t=E.MathUtils.DEG2RAD*this.vrmLookAt.yaw;this._meshYaw.geometry.theta=t,this._meshYaw.geometry.update();let r=E.MathUtils.DEG2RAD*this.vrmLookAt.pitch;this._meshPitch.geometry.theta=r,this._meshPitch.geometry.update(),this.vrmLookAt.getLookAtWorldPosition(de),this.vrmLookAt.getLookAtWorldQuaternion(Le),Le.multiply(this.vrmLookAt.getFaceFrontQuaternion($e)),this._meshYaw.position.copy(de),this._meshYaw.quaternion.copy(Le),this._meshPitch.position.copy(de),this._meshPitch.quaternion.copy(Le),this._meshPitch.quaternion.multiply($e.setFromAxisAngle(ht,t)),this._meshPitch.quaternion.multiply(dt);let{target:o,autoUpdate:i}=this.vrmLookAt;o!=null&&i&&(o.getWorldPosition(Xe).sub(de),this._lineTarget.geometry.tail.copy(Xe),this._lineTarget.geometry.update(),this._lineTarget.position.copy(de)),super.updateMatrixWorld(e)}};import*as y from"three";import*as Ie from"three";var ct=new Ie.Vector3,Rt=new Ie.Vector3;function ce(u,e){return u.matrixWorld.decompose(ct,e,Rt),e}function re(u){return[Math.atan2(-u.z,u.x),Math.atan2(u.y,Math.sqrt(u.x*u.x+u.z*u.z))]}function Ne(u){let e=Math.round(u/2/Math.PI);return u-2*Math.PI*e}var Je=new y.Vector3(0,0,1),ft=new y.Vector3,Mt=new y.Vector3,Et=new y.Vector3,gt=new y.Quaternion,Ue=new y.Quaternion,Ke=new y.Quaternion,Vt=new y.Quaternion,Oe=new y.Euler,Pe=class Pe{constructor(e,t){this.offsetFromHeadBone=new y.Vector3;this.autoUpdate=!0;this.faceFront=new y.Vector3(0,0,1);this.humanoid=e,this.applier=t,this._yaw=0,this._pitch=0,this._needsUpdate=!0,this._restHeadWorldQuaternion=this.getLookAtWorldQuaternion(new y.Quaternion)}get yaw(){return this._yaw}set yaw(e){this._yaw=e,this._needsUpdate=!0}get pitch(){return this._pitch}set pitch(e){this._pitch=e,this._needsUpdate=!0}get euler(){return console.warn("VRMLookAt: euler is deprecated. use getEuler() instead."),this.getEuler(new y.Euler)}getEuler(e){return e.set(y.MathUtils.DEG2RAD*this._pitch,y.MathUtils.DEG2RAD*this._yaw,0,"YXZ")}copy(e){if(this.humanoid!==e.humanoid)throw new Error("VRMLookAt: humanoid must be same in order to copy");return this.offsetFromHeadBone.copy(e.offsetFromHeadBone),this.applier=e.applier,this.autoUpdate=e.autoUpdate,this.target=e.target,this.faceFront.copy(e.faceFront),this}clone(){return new Pe(this.humanoid,this.applier).copy(this)}reset(){this._yaw=0,this._pitch=0,this._needsUpdate=!0}getLookAtWorldPosition(e){let t=this.humanoid.getRawBoneNode("head");return e.copy(this.offsetFromHeadBone).applyMatrix4(t.matrixWorld)}getLookAtWorldQuaternion(e){let t=this.humanoid.getRawBoneNode("head");return ce(t,e)}getFaceFrontQuaternion(e){if(this.faceFront.distanceToSquared(Je)<.01)return e.copy(this._restHeadWorldQuaternion).invert();let[t,r]=re(this.faceFront);return Oe.set(0,.5*Math.PI+t,r,"YZX"),e.setFromEuler(Oe).premultiply(Vt.copy(this._restHeadWorldQuaternion).invert())}getLookAtWorldDirection(e){return this.getLookAtWorldQuaternion(Ue),this.getFaceFrontQuaternion(Ke),e.copy(Je).applyQuaternion(Ue).applyQuaternion(Ke).applyEuler(this.getEuler(Oe))}lookAt(e){let t=gt.copy(this._restHeadWorldQuaternion).multiply(Te(this.getLookAtWorldQuaternion(Ue))),r=this.getLookAtWorldPosition(Mt),o=Et.copy(e).sub(r).applyQuaternion(t).normalize(),[i,n]=re(this.faceFront),[l,s]=re(o),a=Ne(l-i),d=Ne(n-s);this._yaw=y.MathUtils.RAD2DEG*a,this._pitch=y.MathUtils.RAD2DEG*d,this._needsUpdate=!0}update(e){this.target!=null&&this.autoUpdate&&this.lookAt(this.target.getWorldPosition(ft)),this._needsUpdate&&(this._needsUpdate=!1,this.applier.applyYawPitch(this._yaw,this._pitch))}};Pe.EULER_ORDER="YXZ";var Re=Pe;import*as g from"three";var yt=new g.Vector3(0,0,1),k=new g.Quaternion,oe=new g.Quaternion,P=new g.Euler(0,0,0,"YXZ"),G=class{constructor(e,t,r,o,i){this.humanoid=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=r,this.rangeMapVerticalDown=o,this.rangeMapVerticalUp=i,this.faceFront=new g.Vector3(0,0,1),this._restQuatLeftEye=new g.Quaternion,this._restQuatRightEye=new g.Quaternion,this._restLeftEyeParentWorldQuat=new g.Quaternion,this._restRightEyeParentWorldQuat=new g.Quaternion;let n=this.humanoid.getRawBoneNode("leftEye"),l=this.humanoid.getRawBoneNode("rightEye");n&&(this._restQuatLeftEye.copy(n.quaternion),ce(n.parent,this._restLeftEyeParentWorldQuat)),l&&(this._restQuatRightEye.copy(l.quaternion),ce(l.parent,this._restRightEyeParentWorldQuat))}applyYawPitch(e,t){let r=this.humanoid.getRawBoneNode("leftEye"),o=this.humanoid.getRawBoneNode("rightEye"),i=this.humanoid.getNormalizedBoneNode("leftEye"),n=this.humanoid.getNormalizedBoneNode("rightEye");r&&(t<0?P.x=-g.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):P.x=g.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?P.y=-g.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(-e):P.y=g.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(e),k.setFromEuler(P),this._getWorldFaceFrontQuat(oe),i.quaternion.copy(oe).multiply(k).multiply(oe.invert()),k.copy(this._restLeftEyeParentWorldQuat),r.quaternion.copy(i.quaternion).multiply(k).premultiply(k.invert()).multiply(this._restQuatLeftEye)),o&&(t<0?P.x=-g.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):P.x=g.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?P.y=-g.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(-e):P.y=g.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(e),k.setFromEuler(P),this._getWorldFaceFrontQuat(oe),n.quaternion.copy(oe).multiply(k).multiply(oe.invert()),k.copy(this._restRightEyeParentWorldQuat),o.quaternion.copy(n.quaternion).multiply(k).premultiply(k.invert()).multiply(this._restQuatRightEye))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=g.MathUtils.RAD2DEG*e.y,r=g.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,r)}_getWorldFaceFrontQuat(e){if(this.faceFront.distanceToSquared(yt)<.01)return e.identity();let[t,r]=re(this.faceFront);return P.set(0,.5*Math.PI+t,r,"YZX"),e.setFromEuler(P)}};G.type="bone";import*as Se from"three";var Q=class{constructor(e,t,r,o,i){this.expressions=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=r,this.rangeMapVerticalDown=o,this.rangeMapVerticalUp=i}applyYawPitch(e,t){t<0?(this.expressions.setValue("lookDown",0),this.expressions.setValue("lookUp",this.rangeMapVerticalUp.map(-t))):(this.expressions.setValue("lookUp",0),this.expressions.setValue("lookDown",this.rangeMapVerticalDown.map(t))),e<0?(this.expressions.setValue("lookLeft",0),this.expressions.setValue("lookRight",this.rangeMapHorizontalOuter.map(-e))):(this.expressions.setValue("lookRight",0),this.expressions.setValue("lookLeft",this.rangeMapHorizontalOuter.map(e)))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=Se.MathUtils.RAD2DEG*e.y,r=Se.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,r)}};Q.type="expression";var ne=class{constructor(e,t){this.inputMaxValue=e,this.outputScale=t}map(e){return this.outputScale*ge(e/this.inputMaxValue)}};var xt=new Set(["1.0","1.0-beta"]),_e=.01,fe=class{get name(){return"VRMLookAtLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot}afterRoot(e){return R(this,null,function*(){let t=e.userData.vrmHumanoid;if(t===null)return;if(t===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");let r=e.userData.vrmExpressionManager;if(r!==null){if(r===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmExpressionManager is undefined. VRMExpressionLoaderPlugin have to be used first");e.userData.vrmLookAt=yield this._import(e,t,r)}})}_import(e,t,r){return R(this,null,function*(){if(t==null||r==null)return null;let o=yield this._v1Import(e,t,r);if(o)return o;let i=yield this._v0Import(e,t,r);return i||null})}_v1Import(e,t,r){return R(this,null,function*(){var f,V,x;let o=this.parser.json;if(!(((f=o.extensionsUsed)==null?void 0:f.indexOf("VRMC_vrm"))!==-1))return null;let n=(V=o.extensions)==null?void 0:V.VRMC_vrm;if(!n)return null;let l=n.specVersion;if(!xt.has(l))return console.warn(`VRMLookAtLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let s=n.lookAt;if(!s)return null;let a=s.type==="expression"?1:10,d=this._v1ImportRangeMap(s.rangeMapHorizontalInner,a),c=this._v1ImportRangeMap(s.rangeMapHorizontalOuter,a),p=this._v1ImportRangeMap(s.rangeMapVerticalDown,a),m=this._v1ImportRangeMap(s.rangeMapVerticalUp,a),M;s.type==="expression"?M=new Q(r,d,c,p,m):M=new G(t,d,c,p,m);let h=this._importLookAt(t,M);return h.offsetFromHeadBone.fromArray((x=s.offsetFromHeadBone)!=null?x:[0,.06,0]),h})}_v1ImportRangeMap(e,t){var i,n;let r=(i=e==null?void 0:e.inputMaxValue)!=null?i:90,o=(n=e==null?void 0:e.outputScale)!=null?n:t;return r<_e&&(console.warn("VRMLookAtLoaderPlugin: inputMaxValue of a range map is too small. Consider reviewing the range map!"),r=_e),new ne(r,o)}_v0Import(e,t,r){return R(this,null,function*(){var M,h,f,V;let i=(M=this.parser.json.extensions)==null?void 0:M.VRM;if(!i)return null;let n=i.firstPerson;if(!n)return null;let l=n.lookAtTypeName==="BlendShape"?1:10,s=this._v0ImportDegreeMap(n.lookAtHorizontalInner,l),a=this._v0ImportDegreeMap(n.lookAtHorizontalOuter,l),d=this._v0ImportDegreeMap(n.lookAtVerticalDown,l),c=this._v0ImportDegreeMap(n.lookAtVerticalUp,l),p;n.lookAtTypeName==="BlendShape"?p=new Q(r,s,a,d,c):p=new G(t,s,a,d,c);let m=this._importLookAt(t,p);return n.firstPersonBoneOffset?m.offsetFromHeadBone.set((h=n.firstPersonBoneOffset.x)!=null?h:0,(f=n.firstPersonBoneOffset.y)!=null?f:.06,-((V=n.firstPersonBoneOffset.z)!=null?V:0)):m.offsetFromHeadBone.set(0,.06,0),m.faceFront.set(0,0,-1),p instanceof G&&p.faceFront.set(0,0,-1),m})}_v0ImportDegreeMap(e,t){var n,l;let r=e==null?void 0:e.curve;JSON.stringify(r)!=="[0,0,0,1,1,1,1,0]"&&console.warn("Curves of LookAtDegreeMap defined in VRM 0.0 are not supported");let o=(n=e==null?void 0:e.xRange)!=null?n:90,i=(l=e==null?void 0:e.yRange)!=null?l:t;return o<_e&&(console.warn("VRMLookAtLoaderPlugin: xRange of a degree map is too small. Consider reviewing the degree map!"),o=_e),new ne(o,i)}_importLookAt(e,t){let r=new Re(e,t);if(this.helperRoot){let o=new he(r);this.helperRoot.add(o),o.renderOrder=this.helperRoot.renderOrder}return r}};var Tt={Bone:"bone",Expression:"expression"};import*as tt from"three";function et(u,e){return typeof u!="string"||u===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(u)&&(e=e.replace(/(^https?:\/\/[^/]+).*/i,"$1")),/^(https?:)?\/\//i.test(u)||/^data:.*,.*$/i.test(u)||/^blob:.*$/i.test(u)?u:e+u)}var bt=new Set(["1.0","1.0-beta"]),Me=class{get name(){return"VRMMetaLoaderPlugin"}constructor(e,t){var r,o,i;this.parser=e,this.needThumbnailImage=(r=t==null?void 0:t.needThumbnailImage)!=null?r:!1,this.acceptLicenseUrls=(o=t==null?void 0:t.acceptLicenseUrls)!=null?o:["https://vrm.dev/licenses/1.0/"],this.acceptV0Meta=(i=t==null?void 0:t.acceptV0Meta)!=null?i:!0}afterRoot(e){return R(this,null,function*(){e.userData.vrmMeta=yield this._import(e)})}_import(e){return R(this,null,function*(){let t=yield this._v1Import(e);if(t!=null)return t;let r=yield this._v0Import(e);return r!=null?r:null})}_v1Import(e){return R(this,null,function*(){var d,c,p;let t=this.parser.json;if(!(((d=t.extensionsUsed)==null?void 0:d.indexOf("VRMC_vrm"))!==-1))return null;let o=(c=t.extensions)==null?void 0:c.VRMC_vrm;if(o==null)return null;let i=o.specVersion;if(!bt.has(i))return console.warn(`VRMMetaLoaderPlugin: Unknown VRMC_vrm specVersion "${i}"`),null;let n=o.meta;if(!n)return null;let l=n.licenseUrl;if(!new Set(this.acceptLicenseUrls).has(l))throw new Error(`VRMMetaLoaderPlugin: The license url "${l}" is not accepted`);let a;return this.needThumbnailImage&&n.thumbnailImage!=null&&(a=(p=yield this._extractGLTFImage(n.thumbnailImage))!=null?p:void 0),{metaVersion:"1",name:n.name,version:n.version,authors:n.authors,copyrightInformation:n.copyrightInformation,contactInformation:n.contactInformation,references:n.references,thirdPartyLicenses:n.thirdPartyLicenses,thumbnailImage:a,licenseUrl:n.licenseUrl,avatarPermission:n.avatarPermission,allowExcessivelyViolentUsage:n.allowExcessivelyViolentUsage,allowExcessivelySexualUsage:n.allowExcessivelySexualUsage,commercialUsage:n.commercialUsage,allowPoliticalOrReligiousUsage:n.allowPoliticalOrReligiousUsage,allowAntisocialOrHateUsage:n.allowAntisocialOrHateUsage,creditNotation:n.creditNotation,allowRedistribution:n.allowRedistribution,modification:n.modification,otherLicenseUrl:n.otherLicenseUrl}})}_v0Import(e){return R(this,null,function*(){var n;let r=(n=this.parser.json.extensions)==null?void 0:n.VRM;if(!r)return null;let o=r.meta;if(!o)return null;if(!this.acceptV0Meta)throw new Error("VRMMetaLoaderPlugin: Attempted to load VRM0.0 meta but acceptV0Meta is false");let i;return this.needThumbnailImage&&o.texture!=null&&o.texture!==-1&&(i=yield this.parser.getDependency("texture",o.texture)),{metaVersion:"0",allowedUserName:o.allowedUserName,author:o.author,commercialUssageName:o.commercialUssageName,contactInformation:o.contactInformation,licenseName:o.licenseName,otherLicenseUrl:o.otherLicenseUrl,otherPermissionUrl:o.otherPermissionUrl,reference:o.reference,sexualUssageName:o.sexualUssageName,texture:i!=null?i:void 0,title:o.title,version:o.version,violentUssageName:o.violentUssageName}})}_extractGLTFImage(e){return R(this,null,function*(){var n;let r=(n=this.parser.json.images)==null?void 0:n[e];if(r==null)return console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image doesn't exist`),null;let o=r.uri;if(r.bufferView!=null){let l=yield this.parser.getDependency("bufferView",r.bufferView),s=new Blob([l],{type:r.mimeType});o=URL.createObjectURL(s)}return o==null?(console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image couldn't load properly`),null):yield new tt.ImageLoader().loadAsync(et(o,this.parser.options.path)).catch(l=>(console.error(l),console.warn("VRMMetaLoaderPlugin: Failed to load a thumbnail image"),null))})}};var Ee=class{constructor(e){this.scene=e.scene,this.meta=e.meta,this.humanoid=e.humanoid,this.expressionManager=e.expressionManager,this.firstPerson=e.firstPerson,this.lookAt=e.lookAt}update(e){this.humanoid.update(),this.lookAt&&this.lookAt.update(e),this.expressionManager&&this.expressionManager.update()}};var De=class{get name(){return"VRMC_vrm"}constructor(e,t){var i,n,l,s,a;this.parser=e;let r=t==null?void 0:t.helperRoot,o=t==null?void 0:t.autoUpdateHumanBones;this.expressionPlugin=(i=t==null?void 0:t.expressionPlugin)!=null?i:new ie(e),this.firstPersonPlugin=(n=t==null?void 0:t.firstPersonPlugin)!=null?n:new se(e),this.humanoidPlugin=(l=t==null?void 0:t.humanoidPlugin)!=null?l:new ue(e,{helperRoot:r,autoUpdateHumanBones:o}),this.lookAtPlugin=(s=t==null?void 0:t.lookAtPlugin)!=null?s:new fe(e,{helperRoot:r}),this.metaPlugin=(a=t==null?void 0:t.metaPlugin)!=null?a:new Me(e)}afterRoot(e){return R(this,null,function*(){yield this.metaPlugin.afterRoot(e),yield this.humanoidPlugin.afterRoot(e),yield this.expressionPlugin.afterRoot(e),yield this.lookAtPlugin.afterRoot(e),yield this.firstPersonPlugin.afterRoot(e);let t=e.userData.vrmMeta,r=e.userData.vrmHumanoid;if(t&&r){let o=new Ee({scene:e.scene,expressionManager:e.userData.vrmExpressionManager,firstPerson:e.userData.vrmFirstPerson,humanoid:r,lookAt:e.userData.vrmLookAt,meta:t});e.userData.vrmCore=o}})}};export{Ee as VRMCore,De as VRMCoreLoaderPlugin,z as VRMExpression,ie as VRMExpressionLoaderPlugin,Y as VRMExpressionManager,X as VRMExpressionMaterialColorBind,$ as VRMExpressionMaterialColorType,Z as VRMExpressionMorphTargetBind,nt as VRMExpressionOverrideType,q as VRMExpressionPresetName,J as VRMExpressionTextureTransformBind,K as VRMFirstPerson,se as VRMFirstPersonLoaderPlugin,st as VRMFirstPersonMeshAnnotationType,ae as VRMHumanBoneList,lt as VRMHumanBoneName,Be as VRMHumanBoneParentMap,te as VRMHumanoid,ee as VRMHumanoidHelper,ue as VRMHumanoidLoaderPlugin,Re as VRMLookAt,G as VRMLookAtBoneApplier,Q as VRMLookAtExpressionApplier,he as VRMLookAtHelper,fe as VRMLookAtLoaderPlugin,ne as VRMLookAtRangeMap,Tt as VRMLookAtTypeName,Me as VRMMetaLoaderPlugin,Fe as VRMRequiredHumanBoneName};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixiv/three-vrm-core",
3
- "version": "3.4.3-alpha.0",
3
+ "version": "3.4.3",
4
4
  "description": "The implementation of core features of VRM, for @pixiv/three-vrm",
5
5
  "license": "MIT",
6
6
  "author": "pixiv",
@@ -50,8 +50,8 @@
50
50
  ]
51
51
  },
52
52
  "dependencies": {
53
- "@pixiv/types-vrm-0.0": "3.4.3-alpha.0",
54
- "@pixiv/types-vrmc-vrm-1.0": "3.4.3-alpha.0"
53
+ "@pixiv/types-vrm-0.0": "3.4.3",
54
+ "@pixiv/types-vrmc-vrm-1.0": "3.4.3"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/three": "^0.177.0",
@@ -60,5 +60,5 @@
60
60
  "peerDependencies": {
61
61
  "three": ">=0.137"
62
62
  },
63
- "gitHead": "9a1814ade92e2617cb4b96e6210e15e45e2ff935"
63
+ "gitHead": "30666e076441ac493c3ba551d6b8dd113af6e6c6"
64
64
  }