@pixiv/three-vrm 3.0.0-beta.0 → 3.0.0-beta.2

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
  /*! (c) 2019-2024 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
2
- "use strict";var Ur=Object.create;var Oe=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var Fr=Object.getOwnPropertyNames;var Dr=Object.getPrototypeOf,Br=Object.prototype.hasOwnProperty;var Wr=(e,t)=>{for(var n in t)Oe(e,n,{get:t[n],enumerable:!0})},Ln=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Fr(t))!Br.call(e,r)&&r!==n&&Oe(e,r,{get:()=>t[r],enumerable:!(i=Or(t,r))||i.enumerable});return e};var v=(e,t,n)=>(n=e!=null?Ur(Dr(e)):{},Ln(t||!e||!e.__esModule?Oe(n,"default",{value:e,enumerable:!0}):n,e)),kr=e=>Ln(Oe({},"__esModule",{value:!0}),e);var ye=(e,t,n)=>new Promise((i,r)=>{var o=s=>{try{a(n.next(s))}catch(u){r(u)}},l=s=>{try{a(n.throw(s))}catch(u){r(u)}},a=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,l);a((n=n.apply(e,t)).next())});var Ds={};Wr(Ds,{MToonAnimatedUVNode:()=>xi,MToonLightingModel:()=>wi,MToonMaterial:()=>Ri,MToonMaterialDebugMode:()=>Ei,MToonMaterialLoaderPlugin:()=>Ke,MToonMaterialOutlineWidthMode:()=>Z,MToonNodeMaterial:()=>Li,MToonNodeMaterialLoaderPlugin:()=>ns,VRM:()=>Ee,VRMAimConstraint:()=>Fi,VRMCore:()=>$e,VRMCoreLoaderPlugin:()=>go,VRMExpression:()=>ct,VRMExpressionLoaderPlugin:()=>je,VRMExpressionManager:()=>mt,VRMExpressionMaterialColorBind:()=>pt,VRMExpressionMaterialColorType:()=>_e,VRMExpressionMorphTargetBind:()=>ft,VRMExpressionOverrideType:()=>Qr,VRMExpressionPresetName:()=>ke,VRMExpressionTextureTransformBind:()=>gt,VRMFirstPerson:()=>_t,VRMFirstPersonLoaderPlugin:()=>Ge,VRMFirstPersonMeshAnnotationType:()=>Xr,VRMHumanBoneList:()=>Be,VRMHumanBoneName:()=>$r,VRMHumanBoneParentMap:()=>ni,VRMHumanoid:()=>Mt,VRMHumanoidHelper:()=>vt,VRMHumanoidLoaderPlugin:()=>qe,VRMLoaderPlugin:()=>rt,VRMLookAt:()=>di,VRMLookAtBoneApplier:()=>Pe,VRMLookAtExpressionApplier:()=>ze,VRMLookAtHelper:()=>ai,VRMLookAtLoaderPlugin:()=>Xe,VRMLookAtRangeMap:()=>xt,VRMLookAtTypeName:()=>mo,VRMMetaLoaderPlugin:()=>Ye,VRMNodeConstraint:()=>nt,VRMNodeConstraintHelper:()=>et,VRMNodeConstraintLoaderPlugin:()=>It,VRMNodeConstraintManager:()=>Di,VRMRequiredHumanBoneName:()=>si,VRMRollConstraint:()=>Wi,VRMRotationConstraint:()=>Bi,VRMSpringBoneCollider:()=>Ot,VRMSpringBoneColliderHelper:()=>Ut,VRMSpringBoneColliderShape:()=>Dt,VRMSpringBoneColliderShapeCapsule:()=>Bt,VRMSpringBoneColliderShapeSphere:()=>Wt,VRMSpringBoneJoint:()=>Zi,VRMSpringBoneJointHelper:()=>Qi,VRMSpringBoneLoaderPlugin:()=>kt,VRMSpringBoneManager:()=>Ft,VRMUtils:()=>fe});module.exports=kr(Ds);var jn=v(require("three"),1),te=v(require("three"),1),Qn=v(require("three"),1),yt=v(require("three"),1),Zn=v(require("three"),1),z=v(require("three"),1),$=v(require("three"),1),Qe=v(require("three"),1),j=v(require("three"),1),A=v(require("three"),1),we=v(require("three"),1),ne=v(require("three"),1),I=v(require("three"),1),Pt=v(require("three"),1),H=v(require("three"),1),Tt=v(require("three"),1),hi=v(require("three"),1);var w=(e,t,n)=>new Promise((i,r)=>{var o=s=>{try{a(n.next(s))}catch(u){r(u)}},l=s=>{try{a(n.throw(s))}catch(u){r(u)}},a=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,l);a((n=n.apply(e,t)).next())}),ct=class extends jn.Object3D{constructor(e){super(),this.weight=0,this.isBinary=!1,this.overrideBlink="none",this.overrideLookAt="none",this.overrideMouth="none",this._binds=[],this.name=`VRMExpression_${e}`,this.expressionName=e,this.type="VRMExpression",this.visible=!1}get overrideBlinkAmount(){return this.overrideBlink==="block"?0<this.weight?1:0:this.overrideBlink==="blend"?this.weight:0}get overrideLookAtAmount(){return this.overrideLookAt==="block"?0<this.weight?1:0:this.overrideLookAt==="blend"?this.weight:0}get overrideMouthAmount(){return this.overrideMouth==="block"?0<this.weight?1:0:this.overrideMouth==="blend"?this.weight:0}addBind(e){this._binds.push(e)}applyWeight(e){var t;let n=this.isBinary?this.weight<=.5?0:1:this.weight;n*=(t=e==null?void 0:e.multiplier)!=null?t:1,this._binds.forEach(i=>i.applyWeight(n))}clearAppliedWeight(){this._binds.forEach(e=>e.clearAppliedWeight())}};function Gn(e,t,n){var i,r;let o=e.parser.json,l=(i=o.nodes)==null?void 0:i[t];if(l==null)return console.warn(`extractPrimitivesInternal: Attempt to use nodes[${t}] of glTF but the node doesn't exist`),null;let a=l.mesh;if(a==null)return null;let s=(r=o.meshes)==null?void 0:r[a];if(s==null)return console.warn(`extractPrimitivesInternal: Attempt to use meshes[${a}] of glTF but the mesh doesn't exist`),null;let u=s.primitives.length,d=[];return n.traverse(c=>{d.length<u&&c.isMesh&&d.push(c)}),d}function An(e,t){return w(this,null,function*(){let n=yield e.parser.getDependency("node",t);return Gn(e,t,n)})}function Nn(e){return w(this,null,function*(){let t=yield e.parser.getDependencies("node"),n=new Map;return t.forEach((i,r)=>{let o=Gn(e,r,i);o!=null&&n.set(r,o)}),n})}function Hn(e,t){var n,i;let r=parseInt(Qn.REVISION,10),o=null;if(r>=133)o=(i=(n=e.associations.get(t))==null?void 0:n.materials)!=null?i:null;else{let a=e.associations.get(t);(a==null?void 0:a.type)==="materials"&&(o=a.index)}return o}var ke={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 qn(e){return Math.max(Math.min(e,1),0)}var mt=class Xn{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 t={},n=new Set(Object.values(ke));return Object.entries(this._expressionMap).forEach(([i,r])=>{n.has(i)&&(t[i]=r)}),t}get customExpressionMap(){let t={},n=new Set(Object.values(ke));return Object.entries(this._expressionMap).forEach(([i,r])=>{n.has(i)||(t[i]=r)}),t}copy(t){return this._expressions.concat().forEach(i=>{this.unregisterExpression(i)}),t._expressions.forEach(i=>{this.registerExpression(i)}),this.blinkExpressionNames=t.blinkExpressionNames.concat(),this.lookAtExpressionNames=t.lookAtExpressionNames.concat(),this.mouthExpressionNames=t.mouthExpressionNames.concat(),this}clone(){return new Xn().copy(this)}getExpression(t){var n;return(n=this._expressionMap[t])!=null?n:null}registerExpression(t){this._expressions.push(t),this._expressionMap[t.expressionName]=t}unregisterExpression(t){let n=this._expressions.indexOf(t);n===-1&&console.warn("VRMExpressionManager: The specified expressions is not registered"),this._expressions.splice(n,1),delete this._expressionMap[t.expressionName]}getValue(t){var n;let i=this.getExpression(t);return(n=i==null?void 0:i.weight)!=null?n:null}setValue(t,n){let i=this.getExpression(t);i&&(i.weight=qn(n))}getExpressionTrackName(t){let n=this.getExpression(t);return n?`${n.name}.weight`:null}update(){let t=this._calculateWeightMultipliers();this._expressions.forEach(n=>{n.clearAppliedWeight()}),this._expressions.forEach(n=>{let i=1,r=n.expressionName;this.blinkExpressionNames.indexOf(r)!==-1&&(i*=t.blink),this.lookAtExpressionNames.indexOf(r)!==-1&&(i*=t.lookAt),this.mouthExpressionNames.indexOf(r)!==-1&&(i*=t.mouth),n.applyWeight({multiplier:i})})}_calculateWeightMultipliers(){let t=1,n=1,i=1;return this._expressions.forEach(r=>{t-=r.overrideBlinkAmount,n-=r.overrideLookAtAmount,i-=r.overrideMouthAmount}),t=Math.max(0,t),n=Math.max(0,n),i=Math.max(0,i),{blink:t,lookAt:n,mouth:i}}},_e={Color:"color",EmissionColor:"emissionColor",ShadeColor:"shadeColor",MatcapColor:"matcapColor",RimColor:"rimColor",OutlineColor:"outlineColor"},zr={_Color:_e.Color,_EmissionColor:_e.EmissionColor,_ShadeColor:_e.ShadeColor,_RimColor:_e.RimColor,_OutlineColor:_e.OutlineColor},jr=new yt.Color,Yn=class $n{constructor({material:t,type:n,targetValue:i,targetAlpha:r}){this.material=t,this.type=n,this.targetValue=i,this.targetAlpha=r!=null?r:1;let o=this._initColorBindState(),l=this._initAlphaBindState();this._state={color:o,alpha:l}}applyWeight(t){let{color:n,alpha:i}=this._state;if(n!=null){let{propertyName:r,deltaValue:o}=n,l=this.material[r];l!=null&&l.add(jr.copy(o).multiplyScalar(t))}if(i!=null){let{propertyName:r,deltaValue:o}=i;this.material[r]!=null&&(this.material[r]+=o*t)}}clearAppliedWeight(){let{color:t,alpha:n}=this._state;if(t!=null){let{propertyName:i,initialValue:r}=t,o=this.material[i];o!=null&&o.copy(r)}if(n!=null){let{propertyName:i,initialValue:r}=n;this.material[i]!=null&&(this.material[i]=r)}}_initColorBindState(){var t,n,i;let{material:r,type:o,targetValue:l}=this,a=this._getPropertyNameMap(),s=(n=(t=a==null?void 0:a[o])==null?void 0:t[0])!=null?n:null;if(s==null)return console.warn(`Tried to add a material color bind to the material ${(i=r.name)!=null?i:"(no name)"}, the type ${o} but the material or the type is not supported.`),null;let d=r[s].clone(),c=new yt.Color(l.r-d.r,l.g-d.g,l.b-d.b);return{propertyName:s,initialValue:d,deltaValue:c}}_initAlphaBindState(){var t,n,i;let{material:r,type:o,targetAlpha:l}=this,a=this._getPropertyNameMap(),s=(n=(t=a==null?void 0:a[o])==null?void 0:t[1])!=null?n:null;if(s==null&&l!==1)return console.warn(`Tried to add a material alpha bind to the material ${(i=r.name)!=null?i:"(no name)"}, the type ${o} but the material or the type does not support alpha.`),null;if(s==null)return null;let u=r[s],d=l-u;return{propertyName:s,initialValue:u,deltaValue:d}}_getPropertyNameMap(){var t,n;return(n=(t=Object.entries($n._propertyNameMapMap).find(([i])=>this.material[i]===!0))==null?void 0:t[1])!=null?n:null}};Yn._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 pt=Yn,ft=class{constructor({primitives:e,index:t,weight:n}){this.primitives=e,this.index=t,this.weight=n}applyWeight(e){this.primitives.forEach(t=>{var n;((n=t.morphTargetInfluences)==null?void 0:n[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)})}},Vn=new Zn.Vector2,Jn=class Kn{constructor({material:t,scale:n,offset:i}){var r,o;this.material=t,this.scale=n,this.offset=i;let l=(r=Object.entries(Kn._propertyNamesMap).find(([a])=>t[a]===!0))==null?void 0:r[1];l==null?(console.warn(`Tried to add a texture transform bind to the material ${(o=t.name)!=null?o:"(no name)"} but the material is not supported.`),this._properties=[]):(this._properties=[],l.forEach(a=>{var s;let u=(s=t[a])==null?void 0:s.clone();if(!u)return null;t[a]=u;let d=u.offset.clone(),c=u.repeat.clone(),f=i.clone().sub(d),m=n.clone().sub(c);this._properties.push({name:a,initialOffset:d,deltaOffset:f,initialScale:c,deltaScale:m})}))}applyWeight(t){this._properties.forEach(n=>{let i=this.material[n.name];i!==void 0&&(i.offset.add(Vn.copy(n.deltaOffset).multiplyScalar(t)),i.repeat.add(Vn.copy(n.deltaScale).multiplyScalar(t)))})}clearAppliedWeight(){this._properties.forEach(t=>{let n=this.material[t.name];n!==void 0&&(n.offset.copy(t.initialOffset),n.repeat.copy(t.initialScale))})}};Jn._propertyNamesMap={isMeshStandardMaterial:["map","emissiveMap","bumpMap","normalMap","displacementMap","roughnessMap","metalnessMap","alphaMap"],isMeshBasicMaterial:["map","specularMap","alphaMap"],isMToonMaterial:["map","normalMap","emissiveMap","shadeMultiplyTexture","rimMultiplyTexture","outlineWidthMultiplyTexture","uvAnimationMaskTexture"]};var gt=Jn,Gr=new Set(["1.0","1.0-beta"]),ei=class ti{get name(){return"VRMExpressionLoaderPlugin"}constructor(t){this.parser=t}afterRoot(t){return w(this,null,function*(){t.userData.vrmExpressionManager=yield this._import(t)})}_import(t){return w(this,null,function*(){let n=yield this._v1Import(t);if(n)return n;let i=yield this._v0Import(t);return i||null})}_v1Import(t){return w(this,null,function*(){var n,i;let r=this.parser.json;if(!(((n=r.extensionsUsed)==null?void 0:n.indexOf("VRMC_vrm"))!==-1))return null;let l=(i=r.extensions)==null?void 0:i.VRMC_vrm;if(!l)return null;let a=l.specVersion;if(!Gr.has(a))return console.warn(`VRMExpressionLoaderPlugin: Unknown VRMC_vrm specVersion "${a}"`),null;let s=l.expressions;if(!s)return null;let u=new Set(Object.values(ke)),d=new Map;s.preset!=null&&Object.entries(s.preset).forEach(([f,m])=>{if(m!=null){if(!u.has(f)){console.warn(`VRMExpressionLoaderPlugin: Unknown preset name "${f}" detected. Ignoring the expression`);return}d.set(f,m)}}),s.custom!=null&&Object.entries(s.custom).forEach(([f,m])=>{if(u.has(f)){console.warn(`VRMExpressionLoaderPlugin: Custom expression cannot have preset name "${f}". Ignoring the expression`);return}d.set(f,m)});let c=new mt;return yield Promise.all(Array.from(d.entries()).map(f=>w(this,[f],function*([m,p]){var h,g,_,T,M,E,y;let R=new ct(m);if(t.scene.add(R),R.isBinary=(h=p.isBinary)!=null?h:!1,R.overrideBlink=(g=p.overrideBlink)!=null?g:"none",R.overrideLookAt=(_=p.overrideLookAt)!=null?_:"none",R.overrideMouth=(T=p.overrideMouth)!=null?T:"none",(M=p.morphTargetBinds)==null||M.forEach(x=>w(this,null,function*(){var V;if(x.node===void 0||x.index===void 0)return;let O=yield An(t,x.node),b=x.index;if(!O.every(C=>Array.isArray(C.morphTargetInfluences)&&b<C.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${p.name} attempts to index morph #${b} but not found.`);return}R.addBind(new ft({primitives:O,index:b,weight:(V=x.weight)!=null?V:1}))})),p.materialColorBinds||p.textureTransformBinds){let x=[];t.scene.traverse(V=>{let O=V.material;O&&x.push(O)}),(E=p.materialColorBinds)==null||E.forEach(V=>w(this,null,function*(){x.filter(b=>{let C=Hn(this.parser,b);return V.material===C}).forEach(b=>{R.addBind(new pt({material:b,type:V.type,targetValue:new te.Color().fromArray(V.targetValue),targetAlpha:V.targetValue[3]}))})})),(y=p.textureTransformBinds)==null||y.forEach(V=>w(this,null,function*(){x.filter(b=>{let C=Hn(this.parser,b);return V.material===C}).forEach(b=>{var C,G;R.addBind(new gt({material:b,offset:new te.Vector2().fromArray((C=V.offset)!=null?C:[0,0]),scale:new te.Vector2().fromArray((G=V.scale)!=null?G:[1,1])}))})}))}c.registerExpression(R)}))),c})}_v0Import(t){return w(this,null,function*(){var n;let i=this.parser.json,r=(n=i.extensions)==null?void 0:n.VRM;if(!r)return null;let o=r.blendShapeMaster;if(!o)return null;let l=new mt,a=o.blendShapeGroups;if(!a)return l;let s=new Set;return yield Promise.all(a.map(u=>w(this,null,function*(){var d;let c=u.presetName,f=c!=null&&ti.v0v1PresetNameMap[c]||null,m=f!=null?f:u.name;if(m==null){console.warn("VRMExpressionLoaderPlugin: One of custom expressions has no name. Ignoring the expression");return}if(s.has(m)){console.warn(`VRMExpressionLoaderPlugin: An expression preset ${c} has duplicated entries. Ignoring the expression`);return}s.add(m);let p=new ct(m);t.scene.add(p),p.isBinary=(d=u.isBinary)!=null?d:!1,u.binds&&u.binds.forEach(g=>w(this,null,function*(){var _;if(g.mesh===void 0||g.index===void 0)return;let T=[];(_=i.nodes)==null||_.forEach((E,y)=>{E.mesh===g.mesh&&T.push(y)});let M=g.index;yield Promise.all(T.map(E=>w(this,null,function*(){var y;let R=yield An(t,E);if(!R.every(x=>Array.isArray(x.morphTargetInfluences)&&M<x.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${u.name} attempts to index ${M}th morph but not found.`);return}p.addBind(new ft({primitives:R,index:M,weight:.01*((y=g.weight)!=null?y:100)}))})))}));let h=u.materialValues;h&&h.length!==0&&h.forEach(g=>{if(g.materialName===void 0||g.propertyName===void 0||g.targetValue===void 0)return;let _=[];t.scene.traverse(M=>{if(M.material){let E=M.material;Array.isArray(E)?_.push(...E.filter(y=>(y.name===g.materialName||y.name===g.materialName+" (Outline)")&&_.indexOf(y)===-1)):E.name===g.materialName&&_.indexOf(E)===-1&&_.push(E)}});let T=g.propertyName;_.forEach(M=>{if(T==="_MainTex_ST"){let y=new te.Vector2(g.targetValue[0],g.targetValue[1]),R=new te.Vector2(g.targetValue[2],g.targetValue[3]);R.y=1-R.y-y.y,p.addBind(new gt({material:M,scale:y,offset:R}));return}let E=zr[T];if(E){p.addBind(new pt({material:M,type:E,targetValue:new te.Color().fromArray(g.targetValue),targetAlpha:g.targetValue[3]}));return}console.warn(T+" is not supported")})}),l.registerExpression(p)}))),l})}};ei.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 je=ei,Qr={None:"none",Block:"block",Blend:"blend"},St=class ve{constructor(t,n){this._firstPersonOnlyLayer=ve.DEFAULT_FIRSTPERSON_ONLY_LAYER,this._thirdPersonOnlyLayer=ve.DEFAULT_THIRDPERSON_ONLY_LAYER,this._initializedLayers=!1,this.humanoid=t,this.meshAnnotations=n}copy(t){if(this.humanoid!==t.humanoid)throw new Error("VRMFirstPerson: humanoid must be same in order to copy");return this.meshAnnotations=t.meshAnnotations.map(n=>({meshes:n.meshes.concat(),type:n.type})),this}clone(){return new ve(this.humanoid,this.meshAnnotations).copy(this)}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}setup({firstPersonOnlyLayer:t=ve.DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:n=ve.DEFAULT_THIRDPERSON_ONLY_LAYER}={}){this._initializedLayers||(this._firstPersonOnlyLayer=t,this._thirdPersonOnlyLayer=n,this.meshAnnotations.forEach(i=>{i.meshes.forEach(r=>{i.type==="firstPersonOnly"?(r.layers.set(this._firstPersonOnlyLayer),r.traverse(o=>o.layers.set(this._firstPersonOnlyLayer))):i.type==="thirdPersonOnly"?(r.layers.set(this._thirdPersonOnlyLayer),r.traverse(o=>o.layers.set(this._thirdPersonOnlyLayer))):i.type==="auto"&&this._createHeadlessModel(r)})}),this._initializedLayers=!0)}_excludeTriangles(t,n,i,r){let o=0;if(n!=null&&n.length>0)for(let l=0;l<t.length;l+=3){let a=t[l],s=t[l+1],u=t[l+2],d=n[a],c=i[a];if(d[0]>0&&r.includes(c[0])||d[1]>0&&r.includes(c[1])||d[2]>0&&r.includes(c[2])||d[3]>0&&r.includes(c[3]))continue;let f=n[s],m=i[s];if(f[0]>0&&r.includes(m[0])||f[1]>0&&r.includes(m[1])||f[2]>0&&r.includes(m[2])||f[3]>0&&r.includes(m[3]))continue;let p=n[u],h=i[u];p[0]>0&&r.includes(h[0])||p[1]>0&&r.includes(h[1])||p[2]>0&&r.includes(h[2])||p[3]>0&&r.includes(h[3])||(t[o++]=a,t[o++]=s,t[o++]=u)}return o}_createErasedMesh(t,n){let i=new z.SkinnedMesh(t.geometry.clone(),t.material);i.name=`${t.name}(erase)`,i.frustumCulled=t.frustumCulled,i.layers.set(this._firstPersonOnlyLayer);let r=i.geometry,o=r.getAttribute("skinIndex"),l=o instanceof z.GLBufferAttribute?[]:o.array,a=[];for(let h=0;h<l.length;h+=4)a.push([l[h],l[h+1],l[h+2],l[h+3]]);let s=r.getAttribute("skinWeight"),u=s instanceof z.GLBufferAttribute?[]:s.array,d=[];for(let h=0;h<u.length;h+=4)d.push([u[h],u[h+1],u[h+2],u[h+3]]);let c=r.getIndex();if(!c)throw new Error("The geometry doesn't have an index buffer");let f=Array.from(c.array),m=this._excludeTriangles(f,d,a,n),p=[];for(let h=0;h<m;h++)p[h]=f[h];return r.setIndex(p),t.onBeforeRender&&(i.onBeforeRender=t.onBeforeRender),i.bind(new z.Skeleton(t.skeleton.bones,t.skeleton.boneInverses),new z.Matrix4),i}_createHeadlessModelForSkinnedMesh(t,n){let i=[];if(n.skeleton.bones.forEach((o,l)=>{this._isEraseTarget(o)&&i.push(l)}),!i.length){n.layers.enable(this._thirdPersonOnlyLayer),n.layers.enable(this._firstPersonOnlyLayer);return}n.layers.set(this._thirdPersonOnlyLayer);let r=this._createErasedMesh(n,i);t.add(r)}_createHeadlessModel(t){if(t.type==="Group")if(t.layers.set(this._thirdPersonOnlyLayer),this._isEraseTarget(t))t.traverse(n=>n.layers.set(this._thirdPersonOnlyLayer));else{let n=new z.Group;n.name=`_headless_${t.name}`,n.layers.set(this._firstPersonOnlyLayer),t.parent.add(n),t.children.filter(i=>i.type==="SkinnedMesh").forEach(i=>{let r=i;this._createHeadlessModelForSkinnedMesh(n,r)})}else if(t.type==="SkinnedMesh"){let n=t;this._createHeadlessModelForSkinnedMesh(t.parent,n)}else this._isEraseTarget(t)&&(t.layers.set(this._thirdPersonOnlyLayer),t.traverse(n=>n.layers.set(this._thirdPersonOnlyLayer)))}_isEraseTarget(t){return t===this.humanoid.getRawBoneNode("head")?!0:t.parent?this._isEraseTarget(t.parent):!1}};St.DEFAULT_FIRSTPERSON_ONLY_LAYER=9;St.DEFAULT_THIRDPERSON_ONLY_LAYER=10;var _t=St,qr=new Set(["1.0","1.0-beta"]),Ge=class{get name(){return"VRMFirstPersonLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return w(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 w(this,null,function*(){if(t==null)return null;let n=yield this._v1Import(e,t);if(n)return n;let i=yield this._v0Import(e,t);return i||null})}_v1Import(e,t){return w(this,null,function*(){var n,i;let r=this.parser.json;if(!(((n=r.extensionsUsed)==null?void 0:n.indexOf("VRMC_vrm"))!==-1))return null;let l=(i=r.extensions)==null?void 0:i.VRMC_vrm;if(!l)return null;let a=l.specVersion;if(!qr.has(a))return console.warn(`VRMFirstPersonLoaderPlugin: Unknown VRMC_vrm specVersion "${a}"`),null;let s=l.firstPerson;if(!s)return null;let u=[],d=yield Nn(e);return Array.from(d.entries()).forEach(([c,f])=>{var m;let p=s.meshAnnotations?s.meshAnnotations.find(h=>h.node===c):void 0;u.push({meshes:f,type:(m=p==null?void 0:p.type)!=null?m:"both"})}),new _t(t,u)})}_v0Import(e,t){return w(this,null,function*(){var n;let i=this.parser.json,r=(n=i.extensions)==null?void 0:n.VRM;if(!r)return null;let o=r.firstPerson;if(!o)return null;let l=[],a=yield Nn(e);return Array.from(a.entries()).forEach(([s,u])=>{let d=i.nodes[s],c=o.meshAnnotations?o.meshAnnotations.find(f=>f.mesh===d.mesh):void 0;l.push({meshes:u,type:this._convertV0FlagToV1Type(c==null?void 0:c.firstPersonFlag)})}),new _t(t,l)})}_convertV0FlagToV1Type(e){return e==="FirstPersonOnly"?"firstPersonOnly":e==="ThirdPersonOnly"?"thirdPersonOnly":e==="Auto"?"auto":"both"}},Xr={Auto:"auto",Both:"both",ThirdPersonOnly:"thirdPersonOnly",FirstPersonOnly:"firstPersonOnly"},bn=new $.Vector3,In=new $.Vector3,Yr=new $.Quaternion,vt=class extends $.Group{constructor(e){super(),this.vrmHumanoid=e,this._boneAxesMap=new Map,Object.values(e.humanBones).forEach(t=>{let n=new $.AxesHelper(1);n.matrixAutoUpdate=!1,n.material.depthTest=!1,n.material.depthWrite=!1,this.add(n),this._boneAxesMap.set(t,n)})}dispose(){Array.from(this._boneAxesMap.values()).forEach(e=>{e.geometry.dispose(),e.material.dispose()})}updateMatrixWorld(e){Array.from(this._boneAxesMap.entries()).forEach(([t,n])=>{t.node.updateWorldMatrix(!0,!1),t.node.matrixWorld.decompose(bn,Yr,In);let i=bn.set(.1,.1,.1).divide(In);n.matrix.copy(t.node.matrixWorld).scale(i)}),super.updateMatrixWorld(e)}},Be=["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"],$r={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"},ni={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"};function ii(e){return e.invert?e.invert():e.inverse(),e}var le=new Qe.Vector3,ue=new Qe.Quaternion,Et=class{constructor(e){this.humanBones=e,this.restPose=this.getAbsolutePose()}getAbsolutePose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let n=t,i=this.getBoneNode(n);i&&(le.copy(i.position),ue.copy(i.quaternion),e[n]={position:le.toArray(),rotation:ue.toArray()})}),e}getPose(){let e={};return Object.keys(this.humanBones).forEach(t=>{let n=t,i=this.getBoneNode(n);if(!i)return;le.set(0,0,0),ue.identity();let r=this.restPose[n];r!=null&&r.position&&le.fromArray(r.position).negate(),r!=null&&r.rotation&&ii(ue.fromArray(r.rotation)),le.add(i.position),ue.premultiply(i.quaternion),e[n]={position:le.toArray(),rotation:ue.toArray()}}),e}setPose(e){Object.entries(e).forEach(([t,n])=>{let i=t,r=this.getBoneNode(i);if(!r)return;let o=this.restPose[i];o&&(n!=null&&n.position&&(r.position.fromArray(n.position),o.position&&r.position.add(le.fromArray(o.position))),n!=null&&n.rotation&&(r.quaternion.fromArray(n.rotation),o.rotation&&r.quaternion.multiply(ue.fromArray(o.rotation))))})}resetPose(){Object.entries(this.restPose).forEach(([e,t])=>{let n=this.getBoneNode(e);n&&(t!=null&&t.position&&n.position.fromArray(t.position),t!=null&&t.rotation&&n.quaternion.fromArray(t.rotation))})}getBone(e){var t;return(t=this.humanBones[e])!=null?t:void 0}getBoneNode(e){var t,n;return(n=(t=this.humanBones[e])==null?void 0:t.node)!=null?n:null}},ut=new j.Vector3,Zr=new j.Quaternion,Jr=new j.Vector3,Cn=class ri extends Et{static _setupTransforms(t){let n=new j.Object3D;n.name="VRMHumanoidRig";let i={},r={},o={},l={};Be.forEach(s=>{var u;let d=t.getBoneNode(s);if(d){let c=new j.Vector3,f=new j.Quaternion;d.updateWorldMatrix(!0,!1),d.matrixWorld.decompose(c,f,ut),i[s]=c,r[s]=f,o[s]=d.quaternion.clone();let m=new j.Quaternion;(u=d.parent)==null||u.matrixWorld.decompose(ut,m,ut),l[s]=m}});let a={};return Be.forEach(s=>{var u;let d=t.getBoneNode(s);if(d){let c=i[s],f=s,m;for(;m==null&&(f=ni[f],f!=null);)m=i[f];let p=new j.Object3D;p.name="Normalized_"+d.name,(f?(u=a[f])==null?void 0:u.node:n).add(p),p.position.copy(c),m&&p.position.sub(m),a[s]={node:p}}}),{rigBones:a,root:n,parentWorldRotations:l,boneRotations:o}}constructor(t){let{rigBones:n,root:i,parentWorldRotations:r,boneRotations:o}=ri._setupTransforms(t);super(n),this.original=t,this.root=i,this._parentWorldRotations=r,this._boneRotations=o}update(){Be.forEach(t=>{let n=this.original.getBoneNode(t);if(n!=null){let i=this.getBoneNode(t),r=this._parentWorldRotations[t],o=Zr.copy(r).invert(),l=this._boneRotations[t];if(n.quaternion.copy(i.quaternion).multiply(r).premultiply(o).multiply(l),t==="hips"){let a=i.getWorldPosition(Jr);n.parent.updateWorldMatrix(!0,!1);let s=n.parent.matrixWorld,u=a.applyMatrix4(s.invert());n.position.copy(u)}}})}},Mt=class oi{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(t,n){var i;this.autoUpdateHumanBones=(i=n==null?void 0:n.autoUpdateHumanBones)!=null?i:!0,this._rawHumanBones=new Et(t),this._normalizedHumanBones=new Cn(this._rawHumanBones)}copy(t){return this.autoUpdateHumanBones=t.autoUpdateHumanBones,this._rawHumanBones=new Et(t.humanBones),this._normalizedHumanBones=new Cn(this._rawHumanBones),this}clone(){return new oi(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(t){return console.warn("VRMHumanoid: setPose() is deprecated. Use either setRawPose() or setNormalizedPose() instead."),this.setRawPose(t)}setRawPose(t){return this._rawHumanBones.setPose(t)}setNormalizedPose(t){return this._normalizedHumanBones.setPose(t)}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(t){return console.warn("VRMHumanoid: getBone() is deprecated. Use either getRawBone() or getNormalizedBone() instead."),this.getRawBone(t)}getRawBone(t){return this._rawHumanBones.getBone(t)}getNormalizedBone(t){return this._normalizedHumanBones.getBone(t)}getBoneNode(t){return console.warn("VRMHumanoid: getBoneNode() is deprecated. Use either getRawBoneNode() or getNormalizedBoneNode() instead."),this.getRawBoneNode(t)}getRawBoneNode(t){return this._rawHumanBones.getBoneNode(t)}getNormalizedBoneNode(t){return this._normalizedHumanBones.getBoneNode(t)}update(){this.autoUpdateHumanBones&&this._normalizedHumanBones.update()}},si={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"},Kr=new Set(["1.0","1.0-beta"]),Un={leftThumbProximal:"leftThumbMetacarpal",leftThumbIntermediate:"leftThumbProximal",rightThumbProximal:"rightThumbMetacarpal",rightThumbIntermediate:"rightThumbProximal"},qe=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 w(this,null,function*(){e.userData.vrmHumanoid=yield this._import(e)})}_import(e){return w(this,null,function*(){let t=yield this._v1Import(e);if(t)return t;let n=yield this._v0Import(e);return n||null})}_v1Import(e){return w(this,null,function*(){var t,n;let i=this.parser.json;if(!(((t=i.extensionsUsed)==null?void 0:t.indexOf("VRMC_vrm"))!==-1))return null;let o=(n=i.extensions)==null?void 0:n.VRMC_vrm;if(!o)return null;let l=o.specVersion;if(!Kr.has(l))return console.warn(`VRMHumanoidLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let a=o.humanoid;if(!a)return null;let s=a.humanBones.leftThumbIntermediate!=null||a.humanBones.rightThumbIntermediate!=null,u={};a.humanBones!=null&&(yield Promise.all(Object.entries(a.humanBones).map(c=>w(this,[c],function*([f,m]){let p=f,h=m.node;if(s){let _=Un[p];_!=null&&(p=_)}let g=yield this.parser.getDependency("node",h);if(g==null){console.warn(`A glTF node bound to the humanoid bone ${p} (index = ${h}) does not exist`);return}u[p]={node:g}}))));let d=new Mt(this._ensureRequiredBonesExist(u),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(d.normalizedHumanBonesRoot),this.helperRoot){let c=new vt(d);this.helperRoot.add(c),c.renderOrder=this.helperRoot.renderOrder}return d})}_v0Import(e){return w(this,null,function*(){var t;let i=(t=this.parser.json.extensions)==null?void 0:t.VRM;if(!i)return null;let r=i.humanoid;if(!r)return null;let o={};r.humanBones!=null&&(yield Promise.all(r.humanBones.map(a=>w(this,null,function*(){let s=a.bone,u=a.node;if(s==null||u==null)return;let d=yield this.parser.getDependency("node",u);if(d==null){console.warn(`A glTF node bound to the humanoid bone ${s} (index = ${u}) does not exist`);return}let c=Un[s],f=c!=null?c:s;if(o[f]!=null){console.warn(`Multiple bone entries for ${f} detected (index = ${u}), ignoring duplicated entries.`);return}o[f]={node:d}}))));let l=new Mt(this._ensureRequiredBonesExist(o),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(e.scene.add(l.normalizedHumanBonesRoot),this.helperRoot){let a=new vt(l);this.helperRoot.add(a),a.renderOrder=this.helperRoot.renderOrder}return l})}_ensureRequiredBonesExist(e){let t=Object.values(si).filter(n=>e[n]==null);if(t.length>0)throw new Error(`VRMHumanoidLoaderPlugin: These humanoid bones are required but not exist: ${t.join(", ")}`);return e}},On=class extends we.BufferGeometry{constructor(){super(),this._currentTheta=0,this._currentRadius=0,this.theta=0,this.radius=0,this._currentTheta=0,this._currentRadius=0,this._attrPos=new we.BufferAttribute(new Float32Array(65*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new we.BufferAttribute(new Uint16Array(3*63),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;this._currentTheta!==this.theta&&(this._currentTheta=this.theta,e=!0),this._currentRadius!==this.radius&&(this._currentRadius=this.radius,e=!0),e&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,0,0,0);for(let e=0;e<64;e++){let t=e/63*this._currentTheta;this._attrPos.setXYZ(e+1,this._currentRadius*Math.sin(t),0,this._currentRadius*Math.cos(t))}this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<63;e++)this._attrIndex.setXYZ(e*3,0,e+1,e+2);this._attrIndex.needsUpdate=!0}},eo=class extends ne.BufferGeometry{constructor(){super(),this.radius=0,this._currentRadius=0,this.tail=new ne.Vector3,this._currentTail=new ne.Vector3,this._attrPos=new ne.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new ne.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}},Fe=new A.Quaternion,Fn=new A.Quaternion,Se=new A.Vector3,Dn=new A.Vector3,Bn=Math.sqrt(2)/2,to=new A.Quaternion(0,0,-Bn,Bn),no=new A.Vector3(0,1,0),ai=class extends A.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.vrmLookAt=e;{let t=new On;t.radius=.5;let n=new A.MeshBasicMaterial({color:65280,transparent:!0,opacity:.5,side:A.DoubleSide,depthTest:!1,depthWrite:!1});this._meshPitch=new A.Mesh(t,n),this.add(this._meshPitch)}{let t=new On;t.radius=.5;let n=new A.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.5,side:A.DoubleSide,depthTest:!1,depthWrite:!1});this._meshYaw=new A.Mesh(t,n),this.add(this._meshYaw)}{let t=new eo;t.radius=.1;let n=new A.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1});this._lineTarget=new A.LineSegments(t,n),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=A.MathUtils.DEG2RAD*this.vrmLookAt.yaw;this._meshYaw.geometry.theta=t,this._meshYaw.geometry.update();let n=A.MathUtils.DEG2RAD*this.vrmLookAt.pitch;this._meshPitch.geometry.theta=n,this._meshPitch.geometry.update(),this.vrmLookAt.getLookAtWorldPosition(Se),this.vrmLookAt.getLookAtWorldQuaternion(Fe),Fe.multiply(this.vrmLookAt.getFaceFrontQuaternion(Fn)),this._meshYaw.position.copy(Se),this._meshYaw.quaternion.copy(Fe),this._meshPitch.position.copy(Se),this._meshPitch.quaternion.copy(Fe),this._meshPitch.quaternion.multiply(Fn.setFromAxisAngle(no,t)),this._meshPitch.quaternion.multiply(to);let{target:i,autoUpdate:r}=this.vrmLookAt;i!=null&&r&&(i.getWorldPosition(Dn).sub(Se),this._lineTarget.geometry.tail.copy(Dn),this._lineTarget.geometry.update(),this._lineTarget.position.copy(Se)),super.updateMatrixWorld(e)}},io=new Pt.Vector3,ro=new Pt.Vector3;function Rt(e,t){return e.matrixWorld.decompose(io,t,ro),t}function We(e){return[Math.atan2(-e.z,e.x),Math.atan2(e.y,Math.sqrt(e.x*e.x+e.z*e.z))]}function Wn(e){let t=Math.round(e/2/Math.PI);return e-2*Math.PI*t}var kn=new I.Vector3(0,0,1),oo=new I.Vector3,so=new I.Vector3,ao=new I.Vector3,lo=new I.Quaternion,dt=new I.Quaternion,zn=new I.Quaternion,uo=new I.Quaternion,ht=new I.Euler,li=class ui{constructor(t,n){this.offsetFromHeadBone=new I.Vector3,this.autoUpdate=!0,this.faceFront=new I.Vector3(0,0,1),this.humanoid=t,this.applier=n,this._yaw=0,this._pitch=0,this._needsUpdate=!0,this._restHeadWorldQuaternion=this.getLookAtWorldQuaternion(new I.Quaternion)}get yaw(){return this._yaw}set yaw(t){this._yaw=t,this._needsUpdate=!0}get pitch(){return this._pitch}set pitch(t){this._pitch=t,this._needsUpdate=!0}get euler(){return console.warn("VRMLookAt: euler is deprecated. use getEuler() instead."),this.getEuler(new I.Euler)}getEuler(t){return t.set(I.MathUtils.DEG2RAD*this._pitch,I.MathUtils.DEG2RAD*this._yaw,0,"YXZ")}copy(t){if(this.humanoid!==t.humanoid)throw new Error("VRMLookAt: humanoid must be same in order to copy");return this.offsetFromHeadBone.copy(t.offsetFromHeadBone),this.applier=t.applier,this.autoUpdate=t.autoUpdate,this.target=t.target,this.faceFront.copy(t.faceFront),this}clone(){return new ui(this.humanoid,this.applier).copy(this)}reset(){this._yaw=0,this._pitch=0,this._needsUpdate=!0}getLookAtWorldPosition(t){let n=this.humanoid.getRawBoneNode("head");return t.copy(this.offsetFromHeadBone).applyMatrix4(n.matrixWorld)}getLookAtWorldQuaternion(t){let n=this.humanoid.getRawBoneNode("head");return Rt(n,t)}getFaceFrontQuaternion(t){if(this.faceFront.distanceToSquared(kn)<.01)return t.copy(this._restHeadWorldQuaternion).invert();let[n,i]=We(this.faceFront);return ht.set(0,.5*Math.PI+n,i,"YZX"),t.setFromEuler(ht).premultiply(uo.copy(this._restHeadWorldQuaternion).invert())}getLookAtWorldDirection(t){return this.getLookAtWorldQuaternion(dt),this.getFaceFrontQuaternion(zn),t.copy(kn).applyQuaternion(dt).applyQuaternion(zn).applyEuler(this.getEuler(ht))}lookAt(t){let n=lo.copy(this._restHeadWorldQuaternion).multiply(ii(this.getLookAtWorldQuaternion(dt))),i=this.getLookAtWorldPosition(so),r=ao.copy(t).sub(i).applyQuaternion(n).normalize(),[o,l]=We(this.faceFront),[a,s]=We(r),u=Wn(a-o),d=Wn(l-s);this._yaw=I.MathUtils.RAD2DEG*u,this._pitch=I.MathUtils.RAD2DEG*d,this._needsUpdate=!0}update(t){this.target!=null&&this.autoUpdate&&this.lookAt(this.target.getWorldPosition(oo)),this._needsUpdate&&(this._needsUpdate=!1,this.applier.applyYawPitch(this._yaw,this._pitch))}};li.EULER_ORDER="YXZ";var di=li,ho=new H.Vector3(0,0,1),Q=new H.Quaternion,ge=new H.Quaternion,k=new H.Euler(0,0,0,"YXZ"),Pe=class{constructor(e,t,n,i,r){this.humanoid=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=n,this.rangeMapVerticalDown=i,this.rangeMapVerticalUp=r,this.faceFront=new H.Vector3(0,0,1),this._restQuatLeftEye=new H.Quaternion,this._restQuatRightEye=new H.Quaternion,this._restLeftEyeParentWorldQuat=new H.Quaternion,this._restRightEyeParentWorldQuat=new H.Quaternion;let o=this.humanoid.getRawBoneNode("leftEye"),l=this.humanoid.getRawBoneNode("rightEye");o&&(this._restQuatLeftEye.copy(o.quaternion),Rt(o.parent,this._restLeftEyeParentWorldQuat)),l&&(this._restQuatRightEye.copy(l.quaternion),Rt(l.parent,this._restRightEyeParentWorldQuat))}applyYawPitch(e,t){let n=this.humanoid.getRawBoneNode("leftEye"),i=this.humanoid.getRawBoneNode("rightEye"),r=this.humanoid.getNormalizedBoneNode("leftEye"),o=this.humanoid.getNormalizedBoneNode("rightEye");n&&(t<0?k.x=-H.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):k.x=H.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?k.y=-H.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(-e):k.y=H.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(e),Q.setFromEuler(k),this._getWorldFaceFrontQuat(ge),r.quaternion.copy(ge).multiply(Q).multiply(ge.invert()),Q.copy(this._restLeftEyeParentWorldQuat),n.quaternion.copy(r.quaternion).multiply(Q).premultiply(Q.invert()).multiply(this._restQuatLeftEye)),i&&(t<0?k.x=-H.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-t):k.x=H.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(t),e<0?k.y=-H.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(-e):k.y=H.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(e),Q.setFromEuler(k),this._getWorldFaceFrontQuat(ge),o.quaternion.copy(ge).multiply(Q).multiply(ge.invert()),Q.copy(this._restRightEyeParentWorldQuat),i.quaternion.copy(o.quaternion).multiply(Q).premultiply(Q.invert()).multiply(this._restQuatRightEye))}lookAt(e){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let t=H.MathUtils.RAD2DEG*e.y,n=H.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,n)}_getWorldFaceFrontQuat(e){if(this.faceFront.distanceToSquared(ho)<.01)return e.identity();let[t,n]=We(this.faceFront);return k.set(0,.5*Math.PI+t,n,"YZX"),e.setFromEuler(k)}};Pe.type="bone";var ze=class{constructor(e,t,n,i,r){this.expressions=e,this.rangeMapHorizontalInner=t,this.rangeMapHorizontalOuter=n,this.rangeMapVerticalDown=i,this.rangeMapVerticalUp=r}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=Tt.MathUtils.RAD2DEG*e.y,n=Tt.MathUtils.RAD2DEG*e.x;this.applyYawPitch(t,n)}};ze.type="expression";var xt=class{constructor(e,t){this.inputMaxValue=e,this.outputScale=t}map(e){return this.outputScale*qn(e/this.inputMaxValue)}},co=new Set(["1.0","1.0-beta"]),De=.01,Xe=class{get name(){return"VRMLookAtLoaderPlugin"}constructor(e,t){this.parser=e,this.helperRoot=t==null?void 0:t.helperRoot}afterRoot(e){return w(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 n=e.userData.vrmExpressionManager;if(n!==null){if(n===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmExpressionManager is undefined. VRMExpressionLoaderPlugin have to be used first");e.userData.vrmLookAt=yield this._import(e,t,n)}})}_import(e,t,n){return w(this,null,function*(){if(t==null||n==null)return null;let i=yield this._v1Import(e,t,n);if(i)return i;let r=yield this._v0Import(e,t,n);return r||null})}_v1Import(e,t,n){return w(this,null,function*(){var i,r,o;let l=this.parser.json;if(!(((i=l.extensionsUsed)==null?void 0:i.indexOf("VRMC_vrm"))!==-1))return null;let s=(r=l.extensions)==null?void 0:r.VRMC_vrm;if(!s)return null;let u=s.specVersion;if(!co.has(u))return console.warn(`VRMLookAtLoaderPlugin: Unknown VRMC_vrm specVersion "${u}"`),null;let d=s.lookAt;if(!d)return null;let c=d.type==="expression"?1:10,f=this._v1ImportRangeMap(d.rangeMapHorizontalInner,c),m=this._v1ImportRangeMap(d.rangeMapHorizontalOuter,c),p=this._v1ImportRangeMap(d.rangeMapVerticalDown,c),h=this._v1ImportRangeMap(d.rangeMapVerticalUp,c),g;d.type==="expression"?g=new ze(n,f,m,p,h):g=new Pe(t,f,m,p,h);let _=this._importLookAt(t,g);return _.offsetFromHeadBone.fromArray((o=d.offsetFromHeadBone)!=null?o:[0,.06,0]),_})}_v1ImportRangeMap(e,t){var n,i;let r=(n=e==null?void 0:e.inputMaxValue)!=null?n:90,o=(i=e==null?void 0:e.outputScale)!=null?i:t;return r<De&&(console.warn("VRMLookAtLoaderPlugin: inputMaxValue of a range map is too small. Consider reviewing the range map!"),r=De),new xt(r,o)}_v0Import(e,t,n){return w(this,null,function*(){var i,r,o,l;let s=(i=this.parser.json.extensions)==null?void 0:i.VRM;if(!s)return null;let u=s.firstPerson;if(!u)return null;let d=u.lookAtTypeName==="BlendShape"?1:10,c=this._v0ImportDegreeMap(u.lookAtHorizontalInner,d),f=this._v0ImportDegreeMap(u.lookAtHorizontalOuter,d),m=this._v0ImportDegreeMap(u.lookAtVerticalDown,d),p=this._v0ImportDegreeMap(u.lookAtVerticalUp,d),h;u.lookAtTypeName==="BlendShape"?h=new ze(n,c,f,m,p):h=new Pe(t,c,f,m,p);let g=this._importLookAt(t,h);return u.firstPersonBoneOffset?g.offsetFromHeadBone.set((r=u.firstPersonBoneOffset.x)!=null?r:0,(o=u.firstPersonBoneOffset.y)!=null?o:.06,-((l=u.firstPersonBoneOffset.z)!=null?l:0)):g.offsetFromHeadBone.set(0,.06,0),g.faceFront.set(0,0,-1),h instanceof Pe&&h.faceFront.set(0,0,-1),g})}_v0ImportDegreeMap(e,t){var n,i;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,l=(i=e==null?void 0:e.yRange)!=null?i:t;return o<De&&(console.warn("VRMLookAtLoaderPlugin: xRange of a degree map is too small. Consider reviewing the degree map!"),o=De),new xt(o,l)}_importLookAt(e,t){let n=new di(e,t);if(this.helperRoot){let i=new ai(n);this.helperRoot.add(i),i.renderOrder=this.helperRoot.renderOrder}return n}},mo={Bone:"bone",Expression:"expression"};function po(e,t){return typeof e!="string"||e===""?"":(/^https?:\/\//i.test(t)&&/^\//.test(e)&&(t=t.replace(/(^https?:\/\/[^/]+).*/i,"$1")),/^(https?:)?\/\//i.test(e)||/^data:.*,.*$/i.test(e)||/^blob:.*$/i.test(e)?e:t+e)}var fo=new Set(["1.0","1.0-beta"]),Ye=class{get name(){return"VRMMetaLoaderPlugin"}constructor(e,t){var n,i,r;this.parser=e,this.needThumbnailImage=(n=t==null?void 0:t.needThumbnailImage)!=null?n:!1,this.acceptLicenseUrls=(i=t==null?void 0:t.acceptLicenseUrls)!=null?i:["https://vrm.dev/licenses/1.0/"],this.acceptV0Meta=(r=t==null?void 0:t.acceptV0Meta)!=null?r:!0}afterRoot(e){return w(this,null,function*(){e.userData.vrmMeta=yield this._import(e)})}_import(e){return w(this,null,function*(){let t=yield this._v1Import(e);if(t!=null)return t;let n=yield this._v0Import(e);return n!=null?n:null})}_v1Import(e){return w(this,null,function*(){var t,n,i;let r=this.parser.json;if(!(((t=r.extensionsUsed)==null?void 0:t.indexOf("VRMC_vrm"))!==-1))return null;let l=(n=r.extensions)==null?void 0:n.VRMC_vrm;if(l==null)return null;let a=l.specVersion;if(!fo.has(a))return console.warn(`VRMMetaLoaderPlugin: Unknown VRMC_vrm specVersion "${a}"`),null;let s=l.meta;if(!s)return null;let u=s.licenseUrl;if(!new Set(this.acceptLicenseUrls).has(u))throw new Error(`VRMMetaLoaderPlugin: The license url "${u}" is not accepted`);let c;return this.needThumbnailImage&&s.thumbnailImage!=null&&(c=(i=yield this._extractGLTFImage(s.thumbnailImage))!=null?i:void 0),{metaVersion:"1",name:s.name,version:s.version,authors:s.authors,copyrightInformation:s.copyrightInformation,contactInformation:s.contactInformation,references:s.references,thirdPartyLicenses:s.thirdPartyLicenses,thumbnailImage:c,licenseUrl:s.licenseUrl,avatarPermission:s.avatarPermission,allowExcessivelyViolentUsage:s.allowExcessivelyViolentUsage,allowExcessivelySexualUsage:s.allowExcessivelySexualUsage,commercialUsage:s.commercialUsage,allowPoliticalOrReligiousUsage:s.allowPoliticalOrReligiousUsage,allowAntisocialOrHateUsage:s.allowAntisocialOrHateUsage,creditNotation:s.creditNotation,allowRedistribution:s.allowRedistribution,modification:s.modification,otherLicenseUrl:s.otherLicenseUrl}})}_v0Import(e){return w(this,null,function*(){var t;let i=(t=this.parser.json.extensions)==null?void 0:t.VRM;if(!i)return null;let r=i.meta;if(!r)return null;if(!this.acceptV0Meta)throw new Error("VRMMetaLoaderPlugin: Attempted to load VRM0.0 meta but acceptV0Meta is false");let o;return this.needThumbnailImage&&r.texture!=null&&r.texture!==-1&&(o=yield this.parser.getDependency("texture",r.texture)),{metaVersion:"0",allowedUserName:r.allowedUserName,author:r.author,commercialUssageName:r.commercialUssageName,contactInformation:r.contactInformation,licenseName:r.licenseName,otherLicenseUrl:r.otherLicenseUrl,otherPermissionUrl:r.otherPermissionUrl,reference:r.reference,sexualUssageName:r.sexualUssageName,texture:o!=null?o:void 0,title:r.title,version:r.version,violentUssageName:r.violentUssageName}})}_extractGLTFImage(e){return w(this,null,function*(){var t;let i=(t=this.parser.json.images)==null?void 0:t[e];if(i==null)return console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image doesn't exist`),null;let r=i.uri;if(i.bufferView!=null){let l=yield this.parser.getDependency("bufferView",i.bufferView),a=new Blob([l],{type:i.mimeType});r=URL.createObjectURL(a)}return r==null?(console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${e}] of glTF as a thumbnail but the image couldn't load properly`),null):yield new hi.ImageLoader().loadAsync(po(r,this.parser.options.path)).catch(l=>(console.error(l),console.warn("VRMMetaLoaderPlugin: Failed to load a thumbnail image"),null))})}},$e=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()}},go=class{get name(){return"VRMC_vrm"}constructor(e,t){var n,i,r,o,l;this.parser=e;let a=t==null?void 0:t.helperRoot,s=t==null?void 0:t.autoUpdateHumanBones;this.expressionPlugin=(n=t==null?void 0:t.expressionPlugin)!=null?n:new je(e),this.firstPersonPlugin=(i=t==null?void 0:t.firstPersonPlugin)!=null?i:new Ge(e),this.humanoidPlugin=(r=t==null?void 0:t.humanoidPlugin)!=null?r:new qe(e,{helperRoot:a,autoUpdateHumanBones:s}),this.lookAtPlugin=(o=t==null?void 0:t.lookAtPlugin)!=null?o:new Xe(e,{helperRoot:a}),this.metaPlugin=(l=t==null?void 0:t.metaPlugin)!=null?l:new Ye(e)}afterRoot(e){return w(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,n=e.userData.vrmHumanoid;if(t&&n){let i=new $e({scene:e.scene,expressionManager:e.userData.vrmExpressionManager,firstPerson:e.userData.vrmFirstPerson,humanoid:n,lookAt:e.userData.vrmLookAt,meta:t});e.userData.vrmCore=i}})}};var Ee=class extends $e{constructor(t){super(t),this.materials=t.materials,this.springBoneManager=t.springBoneManager,this.nodeConstraintManager=t.nodeConstraintManager}update(t){super.update(t),this.nodeConstraintManager&&this.nodeConstraintManager.update(),this.springBoneManager&&this.springBoneManager.update(t),this.materials&&this.materials.forEach(n=>{n.update&&n.update(t)})}};var Je=v(require("three"),1),_i=v(require("three"),1),vi=v(require("three"),1),P=v(require("three"),1),Mi=v(require("three"),1),F=v(require("three/addons/nodes/Nodes.js"),1),L=v(require("three/addons/nodes/Nodes.js"),1),N=v(require("three/addons/nodes/Nodes.js"),1),D=v(require("three/addons/nodes/Nodes.js"),1),W=v(require("three"),1),S=v(require("three/addons/nodes/Nodes.js"),1),ie=v(require("three/addons/nodes/Nodes.js"),1);var _o=Object.defineProperty,ci=Object.getOwnPropertySymbols,vo=Object.prototype.hasOwnProperty,Eo=Object.prototype.propertyIsEnumerable,mi=(e,t,n)=>t in e?_o(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,pi=(e,t)=>{for(var n in t||(t={}))vo.call(t,n)&&mi(e,n,t[n]);if(ci)for(var n of ci(t))Eo.call(t,n)&&mi(e,n,t[n]);return e},de=(e,t,n)=>new Promise((i,r)=>{var o=s=>{try{a(n.next(s))}catch(u){r(u)}},l=s=>{try{a(n.throw(s))}catch(u){r(u)}},a=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,l);a((n=n.apply(e,t)).next())}),Mo={"":3e3,srgb:3001};function Ro(e,t){parseInt(vi.REVISION,10)>=152?e.colorSpace=t:e.encoding=Mo[t]}var To=class{get pending(){return Promise.all(this._pendings)}constructor(e,t){this._parser=e,this._materialParams=t,this._pendings=[]}assignPrimitive(e,t){t!=null&&(this._materialParams[e]=t)}assignColor(e,t,n){t!=null&&(this._materialParams[e]=new _i.Color().fromArray(t),n&&this._materialParams[e].convertSRGBToLinear())}assignTexture(e,t,n){return de(this,null,function*(){let i=de(this,null,function*(){t!=null&&(yield this._parser.assignTexture(this._materialParams,e,t),n&&Ro(this._materialParams[e],"srgb"))});return this._pendings.push(i),i})}assignTextureByIndex(e,t,n){return de(this,null,function*(){return this.assignTexture(e,t!=null?{index:t}:void 0,n)})}},xo=`// #define PHONG
2
+ "use strict";var fr=Object.create;var Le=Object.defineProperty;var _r=Object.getOwnPropertyDescriptor;var gr=Object.getOwnPropertyNames;var vr=Object.getPrototypeOf,Er=Object.prototype.hasOwnProperty;var Mr=(t,e)=>{for(var n in e)Le(t,n,{get:e[n],enumerable:!0})},gn=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of gr(e))!Er.call(t,r)&&r!==n&&Le(t,r,{get:()=>e[r],enumerable:!(i=_r(e,r))||i.enumerable});return t};var M=(t,e,n)=>(n=t!=null?fr(vr(t)):{},gn(e||!t||!t.__esModule?Le(n,"default",{value:t,enumerable:!0}):n,t)),Rr=t=>gn(Le({},"__esModule",{value:!0}),t);var _e=(t,e,n)=>new Promise((i,r)=>{var s=o=>{try{l(n.next(o))}catch(u){r(u)}},a=o=>{try{l(n.throw(o))}catch(u){r(u)}},l=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);l((n=n.apply(t,e)).next())});var ko={};Mr(ko,{MToonMaterial:()=>si,MToonMaterialDebugMode:()=>ri,MToonMaterialLoaderPlugin:()=>Mt,MToonMaterialOutlineWidthMode:()=>ze,VRM:()=>he,VRMAimConstraint:()=>gi,VRMCore:()=>ke,VRMCoreLoaderPlugin:()=>Xr,VRMExpression:()=>rt,VRMExpressionLoaderPlugin:()=>Oe,VRMExpressionManager:()=>ot,VRMExpressionMaterialColorBind:()=>st,VRMExpressionMaterialColorType:()=>ue,VRMExpressionMorphTargetBind:()=>at,VRMExpressionOverrideType:()=>wr,VRMExpressionPresetName:()=>Ue,VRMExpressionTextureTransformBind:()=>lt,VRMFirstPerson:()=>ut,VRMFirstPersonLoaderPlugin:()=>Ne,VRMFirstPersonMeshAnnotationType:()=>Sr,VRMHumanBoneList:()=>Ve,VRMHumanBoneName:()=>Lr,VRMHumanBoneParentMap:()=>zn,VRMHumanoid:()=>ct,VRMHumanoidHelper:()=>dt,VRMHumanoidLoaderPlugin:()=>Be,VRMLoaderPlugin:()=>$e,VRMLookAt:()=>Zn,VRMLookAtBoneApplier:()=>ve,VRMLookAtExpressionApplier:()=>Ce,VRMLookAtHelper:()=>Xn,VRMLookAtLoaderPlugin:()=>Fe,VRMLookAtRangeMap:()=>ft,VRMLookAtTypeName:()=>Gr,VRMMetaLoaderPlugin:()=>We,VRMNodeConstraint:()=>Xe,VRMNodeConstraintHelper:()=>Qe,VRMNodeConstraintLoaderPlugin:()=>xt,VRMNodeConstraintManager:()=>vi,VRMRequiredHumanBoneName:()=>qn,VRMRollConstraint:()=>Mi,VRMRotationConstraint:()=>Ei,VRMSpringBoneCollider:()=>Pt,VRMSpringBoneColliderHelper:()=>wt,VRMSpringBoneColliderShape:()=>At,VRMSpringBoneColliderShapeCapsule:()=>Lt,VRMSpringBoneColliderShapeSphere:()=>Ht,VRMSpringBoneJoint:()=>Hi,VRMSpringBoneJointHelper:()=>wi,VRMSpringBoneLoaderPlugin:()=>bt,VRMSpringBoneManager:()=>St,VRMUtils:()=>ae});module.exports=Rr(ko);var Vn=M(require("three"),1),X=M(require("three"),1),_t=M(require("three"),1),Dn=M(require("three"),1),D=M(require("three"),1),j=M(require("three"),1),De=M(require("three"),1),B=M(require("three"),1),S=M(require("three"),1),Ee=M(require("three"),1),Y=M(require("three"),1),V=M(require("three"),1),vt=M(require("three"),1),A=M(require("three"),1),mt=M(require("three"),1),Jn=M(require("three"),1);var w=(t,e,n)=>new Promise((i,r)=>{var s=o=>{try{l(n.next(o))}catch(u){r(u)}},a=o=>{try{l(n.throw(o))}catch(u){r(u)}},l=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);l((n=n.apply(t,e)).next())}),rt=class extends Vn.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 overrideBlinkAmount(){return this.overrideBlink==="block"?0<this.weight?1:0:this.overrideBlink==="blend"?this.weight:0}get overrideLookAtAmount(){return this.overrideLookAt==="block"?0<this.weight?1:0:this.overrideLookAt==="blend"?this.weight:0}get overrideMouthAmount(){return this.overrideMouth==="block"?0<this.weight?1:0:this.overrideMouth==="blend"?this.weight:0}addBind(t){this._binds.push(t)}applyWeight(t){var e;let n=this.isBinary?this.weight<=.5?0:1:this.weight;n*=(e=t==null?void 0:t.multiplier)!=null?e:1,this._binds.forEach(i=>i.applyWeight(n))}clearAppliedWeight(){this._binds.forEach(t=>t.clearAppliedWeight())}};function In(t,e,n){var i,r;let s=t.parser.json,a=(i=s.nodes)==null?void 0:i[e];if(a==null)return console.warn(`extractPrimitivesInternal: Attempt to use nodes[${e}] of glTF but the node doesn't exist`),null;let l=a.mesh;if(l==null)return null;let o=(r=s.meshes)==null?void 0:r[l];if(o==null)return console.warn(`extractPrimitivesInternal: Attempt to use meshes[${l}] of glTF but the mesh doesn't exist`),null;let u=o.primitives.length,d=[];return n.traverse(c=>{d.length<u&&c.isMesh&&d.push(c)}),d}function vn(t,e){return w(this,null,function*(){let n=yield t.parser.getDependency("node",e);return In(t,e,n)})}function En(t){return w(this,null,function*(){let e=yield t.parser.getDependencies("node"),n=new Map;return e.forEach((i,r)=>{let s=In(t,r,i);s!=null&&n.set(r,s)}),n})}var Ue={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 Un(t){return Math.max(Math.min(t,1),0)}var ot=class Cn{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={},n=new Set(Object.values(Ue));return Object.entries(this._expressionMap).forEach(([i,r])=>{n.has(i)&&(e[i]=r)}),e}get customExpressionMap(){let e={},n=new Set(Object.values(Ue));return Object.entries(this._expressionMap).forEach(([i,r])=>{n.has(i)||(e[i]=r)}),e}copy(e){return this._expressions.concat().forEach(i=>{this.unregisterExpression(i)}),e._expressions.forEach(i=>{this.registerExpression(i)}),this.blinkExpressionNames=e.blinkExpressionNames.concat(),this.lookAtExpressionNames=e.lookAtExpressionNames.concat(),this.mouthExpressionNames=e.mouthExpressionNames.concat(),this}clone(){return new Cn().copy(this)}getExpression(e){var n;return(n=this._expressionMap[e])!=null?n:null}registerExpression(e){this._expressions.push(e),this._expressionMap[e.expressionName]=e}unregisterExpression(e){let n=this._expressions.indexOf(e);n===-1&&console.warn("VRMExpressionManager: The specified expressions is not registered"),this._expressions.splice(n,1),delete this._expressionMap[e.expressionName]}getValue(e){var n;let i=this.getExpression(e);return(n=i==null?void 0:i.weight)!=null?n:null}setValue(e,n){let i=this.getExpression(e);i&&(i.weight=Un(n))}resetValues(){this._expressions.forEach(e=>{e.weight=0})}getExpressionTrackName(e){let n=this.getExpression(e);return n?`${n.name}.weight`:null}update(){let e=this._calculateWeightMultipliers();this._expressions.forEach(n=>{n.clearAppliedWeight()}),this._expressions.forEach(n=>{let i=1,r=n.expressionName;this.blinkExpressionNames.indexOf(r)!==-1&&(i*=e.blink),this.lookAtExpressionNames.indexOf(r)!==-1&&(i*=e.lookAt),this.mouthExpressionNames.indexOf(r)!==-1&&(i*=e.mouth),n.applyWeight({multiplier:i})})}_calculateWeightMultipliers(){let e=1,n=1,i=1;return this._expressions.forEach(r=>{e-=r.overrideBlinkAmount,n-=r.overrideLookAtAmount,i-=r.overrideMouthAmount}),e=Math.max(0,e),n=Math.max(0,n),i=Math.max(0,i),{blink:e,lookAt:n,mouth:i}}},ue={Color:"color",EmissionColor:"emissionColor",ShadeColor:"shadeColor",MatcapColor:"matcapColor",RimColor:"rimColor",OutlineColor:"outlineColor"},Tr={_Color:ue.Color,_EmissionColor:ue.EmissionColor,_ShadeColor:ue.ShadeColor,_RimColor:ue.RimColor,_OutlineColor:ue.OutlineColor},xr=new _t.Color,On=class Nn{constructor({material:e,type:n,targetValue:i,targetAlpha:r}){this.material=e,this.type=n,this.targetValue=i,this.targetAlpha=r!=null?r:1;let s=this._initColorBindState(),a=this._initAlphaBindState();this._state={color:s,alpha:a}}applyWeight(e){let{color:n,alpha:i}=this._state;if(n!=null){let{propertyName:r,deltaValue:s}=n,a=this.material[r];a!=null&&a.add(xr.copy(s).multiplyScalar(e))}if(i!=null){let{propertyName:r,deltaValue:s}=i;this.material[r]!=null&&(this.material[r]+=s*e)}}clearAppliedWeight(){let{color:e,alpha:n}=this._state;if(e!=null){let{propertyName:i,initialValue:r}=e,s=this.material[i];s!=null&&s.copy(r)}if(n!=null){let{propertyName:i,initialValue:r}=n;this.material[i]!=null&&(this.material[i]=r)}}_initColorBindState(){var e,n,i;let{material:r,type:s,targetValue:a}=this,l=this._getPropertyNameMap(),o=(n=(e=l==null?void 0:l[s])==null?void 0:e[0])!=null?n:null;if(o==null)return console.warn(`Tried to add a material color bind to the material ${(i=r.name)!=null?i:"(no name)"}, the type ${s} but the material or the type is not supported.`),null;let d=r[o].clone(),c=new _t.Color(a.r-d.r,a.g-d.g,a.b-d.b);return{propertyName:o,initialValue:d,deltaValue:c}}_initAlphaBindState(){var e,n,i;let{material:r,type:s,targetAlpha:a}=this,l=this._getPropertyNameMap(),o=(n=(e=l==null?void 0:l[s])==null?void 0:e[1])!=null?n:null;if(o==null&&a!==1)return console.warn(`Tried to add a material alpha bind to the material ${(i=r.name)!=null?i:"(no name)"}, the type ${s} but the material or the type does not support alpha.`),null;if(o==null)return null;let u=r[o],d=a-u;return{propertyName:o,initialValue:u,deltaValue:d}}_getPropertyNameMap(){var e,n;return(n=(e=Object.entries(Nn._propertyNameMapMap).find(([i])=>this.material[i]===!0))==null?void 0:e[1])!=null?n:null}};On._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 st=On,at=class{constructor({primitives:t,index:e,weight:n}){this.primitives=t,this.index=e,this.weight=n}applyWeight(t){this.primitives.forEach(e=>{var n;((n=e.morphTargetInfluences)==null?void 0:n[this.index])!=null&&(e.morphTargetInfluences[this.index]+=this.weight*t)})}clearAppliedWeight(){this.primitives.forEach(t=>{var e;((e=t.morphTargetInfluences)==null?void 0:e[this.index])!=null&&(t.morphTargetInfluences[this.index]=0)})}},Mn=new Dn.Vector2,Bn=class Fn{constructor({material:e,scale:n,offset:i}){var r,s;this.material=e,this.scale=n,this.offset=i;let a=(r=Object.entries(Fn._propertyNamesMap).find(([l])=>e[l]===!0))==null?void 0:r[1];a==null?(console.warn(`Tried to add a texture transform bind to the material ${(s=e.name)!=null?s:"(no name)"} but the material is not supported.`),this._properties=[]):(this._properties=[],a.forEach(l=>{var o;let u=(o=e[l])==null?void 0:o.clone();if(!u)return null;e[l]=u;let d=u.offset.clone(),c=u.repeat.clone(),f=i.clone().sub(d),p=n.clone().sub(c);this._properties.push({name:l,initialOffset:d,deltaOffset:f,initialScale:c,deltaScale:p})}))}applyWeight(e){this._properties.forEach(n=>{let i=this.material[n.name];i!==void 0&&(i.offset.add(Mn.copy(n.deltaOffset).multiplyScalar(e)),i.repeat.add(Mn.copy(n.deltaScale).multiplyScalar(e)))})}clearAppliedWeight(){this._properties.forEach(e=>{let n=this.material[e.name];n!==void 0&&(n.offset.copy(e.initialOffset),n.repeat.copy(e.initialScale))})}};Bn._propertyNamesMap={isMeshStandardMaterial:["map","emissiveMap","bumpMap","normalMap","displacementMap","roughnessMap","metalnessMap","alphaMap"],isMeshBasicMaterial:["map","specularMap","alphaMap"],isMToonMaterial:["map","normalMap","emissiveMap","shadeMultiplyTexture","rimMultiplyTexture","outlineWidthMultiplyTexture","uvAnimationMaskTexture"]};var lt=Bn,yr=new Set(["1.0","1.0-beta"]),Wn=class kn{get name(){return"VRMExpressionLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return w(this,null,function*(){e.userData.vrmExpressionManager=yield this._import(e)})}_import(e){return w(this,null,function*(){let n=yield this._v1Import(e);if(n)return n;let i=yield this._v0Import(e);return i||null})}_v1Import(e){return w(this,null,function*(){var n,i;let r=this.parser.json;if(!(((n=r.extensionsUsed)==null?void 0:n.indexOf("VRMC_vrm"))!==-1))return null;let a=(i=r.extensions)==null?void 0:i.VRMC_vrm;if(!a)return null;let l=a.specVersion;if(!yr.has(l))return console.warn(`VRMExpressionLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let o=a.expressions;if(!o)return null;let u=new Set(Object.values(Ue)),d=new Map;o.preset!=null&&Object.entries(o.preset).forEach(([f,p])=>{if(p!=null){if(!u.has(f)){console.warn(`VRMExpressionLoaderPlugin: Unknown preset name "${f}" detected. Ignoring the expression`);return}d.set(f,p)}}),o.custom!=null&&Object.entries(o.custom).forEach(([f,p])=>{if(u.has(f)){console.warn(`VRMExpressionLoaderPlugin: Custom expression cannot have preset name "${f}". Ignoring the expression`);return}d.set(f,p)});let c=new ot;return yield Promise.all(Array.from(d.entries()).map(f=>w(this,[f],function*([p,m]){var h,_,g,y,x,v,T;let E=new rt(p);if(e.scene.add(E),E.isBinary=(h=m.isBinary)!=null?h:!1,E.overrideBlink=(_=m.overrideBlink)!=null?_:"none",E.overrideLookAt=(g=m.overrideLookAt)!=null?g:"none",E.overrideMouth=(y=m.overrideMouth)!=null?y:"none",(x=m.morphTargetBinds)==null||x.forEach(R=>w(this,null,function*(){var L;if(R.node===void 0||R.index===void 0)return;let U=yield vn(e,R.node),H=R.index;if(!U.every(b=>Array.isArray(b.morphTargetInfluences)&&H<b.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${m.name} attempts to index morph #${H} but not found.`);return}E.addBind(new at({primitives:U,index:H,weight:(L=R.weight)!=null?L:1}))})),m.materialColorBinds||m.textureTransformBinds){let R=[];e.scene.traverse(L=>{let U=L.material;U&&R.push(U)}),(v=m.materialColorBinds)==null||v.forEach(L=>w(this,null,function*(){R.filter(H=>{var b;let C=(b=this.parser.associations.get(H))==null?void 0:b.materials;return L.material===C}).forEach(H=>{E.addBind(new st({material:H,type:L.type,targetValue:new X.Color().fromArray(L.targetValue),targetAlpha:L.targetValue[3]}))})})),(T=m.textureTransformBinds)==null||T.forEach(L=>w(this,null,function*(){R.filter(H=>{var b;let C=(b=this.parser.associations.get(H))==null?void 0:b.materials;return L.material===C}).forEach(H=>{var b,C;E.addBind(new lt({material:H,offset:new X.Vector2().fromArray((b=L.offset)!=null?b:[0,0]),scale:new X.Vector2().fromArray((C=L.scale)!=null?C:[1,1])}))})}))}c.registerExpression(E)}))),c})}_v0Import(e){return w(this,null,function*(){var n;let i=this.parser.json,r=(n=i.extensions)==null?void 0:n.VRM;if(!r)return null;let s=r.blendShapeMaster;if(!s)return null;let a=new ot,l=s.blendShapeGroups;if(!l)return a;let o=new Set;return yield Promise.all(l.map(u=>w(this,null,function*(){var d;let c=u.presetName,f=c!=null&&kn.v0v1PresetNameMap[c]||null,p=f!=null?f:u.name;if(p==null){console.warn("VRMExpressionLoaderPlugin: One of custom expressions has no name. Ignoring the expression");return}if(o.has(p)){console.warn(`VRMExpressionLoaderPlugin: An expression preset ${c} has duplicated entries. Ignoring the expression`);return}o.add(p);let m=new rt(p);e.scene.add(m),m.isBinary=(d=u.isBinary)!=null?d:!1,u.binds&&u.binds.forEach(_=>w(this,null,function*(){var g;if(_.mesh===void 0||_.index===void 0)return;let y=[];(g=i.nodes)==null||g.forEach((v,T)=>{v.mesh===_.mesh&&y.push(T)});let x=_.index;yield Promise.all(y.map(v=>w(this,null,function*(){var T;let E=yield vn(e,v);if(!E.every(R=>Array.isArray(R.morphTargetInfluences)&&x<R.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${u.name} attempts to index ${x}th morph but not found.`);return}m.addBind(new at({primitives:E,index:x,weight:.01*((T=_.weight)!=null?T:100)}))})))}));let h=u.materialValues;h&&h.length!==0&&h.forEach(_=>{if(_.materialName===void 0||_.propertyName===void 0||_.targetValue===void 0)return;let g=[];e.scene.traverse(x=>{if(x.material){let v=x.material;Array.isArray(v)?g.push(...v.filter(T=>(T.name===_.materialName||T.name===_.materialName+" (Outline)")&&g.indexOf(T)===-1)):v.name===_.materialName&&g.indexOf(v)===-1&&g.push(v)}});let y=_.propertyName;g.forEach(x=>{if(y==="_MainTex_ST"){let T=new X.Vector2(_.targetValue[0],_.targetValue[1]),E=new X.Vector2(_.targetValue[2],_.targetValue[3]);E.y=1-E.y-T.y,m.addBind(new lt({material:x,scale:T,offset:E}));return}let v=Tr[y];if(v){m.addBind(new st({material:x,type:v,targetValue:new X.Color().fromArray(_.targetValue),targetAlpha:_.targetValue[3]}));return}console.warn(y+" is not supported")})}),a.registerExpression(m)}))),a})}};Wn.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 Oe=Wn,wr={None:"none",Block:"block",Blend:"blend"},gt=class de{constructor(e,n){this._firstPersonOnlyLayer=de.DEFAULT_FIRSTPERSON_ONLY_LAYER,this._thirdPersonOnlyLayer=de.DEFAULT_THIRDPERSON_ONLY_LAYER,this._initializedLayers=!1,this.humanoid=e,this.meshAnnotations=n}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(n=>({meshes:n.meshes.concat(),type:n.type})),this}clone(){return new de(this.humanoid,this.meshAnnotations).copy(this)}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}setup({firstPersonOnlyLayer:e=de.DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:n=de.DEFAULT_THIRDPERSON_ONLY_LAYER}={}){this._initializedLayers||(this._firstPersonOnlyLayer=e,this._thirdPersonOnlyLayer=n,this.meshAnnotations.forEach(i=>{i.meshes.forEach(r=>{i.type==="firstPersonOnly"?(r.layers.set(this._firstPersonOnlyLayer),r.traverse(s=>s.layers.set(this._firstPersonOnlyLayer))):i.type==="thirdPersonOnly"?(r.layers.set(this._thirdPersonOnlyLayer),r.traverse(s=>s.layers.set(this._thirdPersonOnlyLayer))):i.type==="auto"&&this._createHeadlessModel(r)})}),this._initializedLayers=!0)}_excludeTriangles(e,n,i,r){let s=0;if(n!=null&&n.length>0)for(let a=0;a<e.length;a+=3){let l=e[a],o=e[a+1],u=e[a+2],d=n[l],c=i[l];if(d[0]>0&&r.includes(c[0])||d[1]>0&&r.includes(c[1])||d[2]>0&&r.includes(c[2])||d[3]>0&&r.includes(c[3]))continue;let f=n[o],p=i[o];if(f[0]>0&&r.includes(p[0])||f[1]>0&&r.includes(p[1])||f[2]>0&&r.includes(p[2])||f[3]>0&&r.includes(p[3]))continue;let m=n[u],h=i[u];m[0]>0&&r.includes(h[0])||m[1]>0&&r.includes(h[1])||m[2]>0&&r.includes(h[2])||m[3]>0&&r.includes(h[3])||(e[s++]=l,e[s++]=o,e[s++]=u)}return s}_createErasedMesh(e,n){let i=new D.SkinnedMesh(e.geometry.clone(),e.material);i.name=`${e.name}(erase)`,i.frustumCulled=e.frustumCulled,i.layers.set(this._firstPersonOnlyLayer);let r=i.geometry,s=r.getAttribute("skinIndex"),a=s instanceof D.GLBufferAttribute?[]:s.array,l=[];for(let h=0;h<a.length;h+=4)l.push([a[h],a[h+1],a[h+2],a[h+3]]);let o=r.getAttribute("skinWeight"),u=o instanceof D.GLBufferAttribute?[]:o.array,d=[];for(let h=0;h<u.length;h+=4)d.push([u[h],u[h+1],u[h+2],u[h+3]]);let c=r.getIndex();if(!c)throw new Error("The geometry doesn't have an index buffer");let f=Array.from(c.array),p=this._excludeTriangles(f,d,l,n),m=[];for(let h=0;h<p;h++)m[h]=f[h];return r.setIndex(m),e.onBeforeRender&&(i.onBeforeRender=e.onBeforeRender),i.bind(new D.Skeleton(e.skeleton.bones,e.skeleton.boneInverses),new D.Matrix4),i}_createHeadlessModelForSkinnedMesh(e,n){let i=[];if(n.skeleton.bones.forEach((s,a)=>{this._isEraseTarget(s)&&i.push(a)}),!i.length){n.layers.enable(this._thirdPersonOnlyLayer),n.layers.enable(this._firstPersonOnlyLayer);return}n.layers.set(this._thirdPersonOnlyLayer);let r=this._createErasedMesh(n,i);e.add(r)}_createHeadlessModel(e){if(e.type==="Group")if(e.layers.set(this._thirdPersonOnlyLayer),this._isEraseTarget(e))e.traverse(n=>n.layers.set(this._thirdPersonOnlyLayer));else{let n=new D.Group;n.name=`_headless_${e.name}`,n.layers.set(this._firstPersonOnlyLayer),e.parent.add(n),e.children.filter(i=>i.type==="SkinnedMesh").forEach(i=>{let r=i;this._createHeadlessModelForSkinnedMesh(n,r)})}else if(e.type==="SkinnedMesh"){let n=e;this._createHeadlessModelForSkinnedMesh(e.parent,n)}else this._isEraseTarget(e)&&(e.layers.set(this._thirdPersonOnlyLayer),e.traverse(n=>n.layers.set(this._thirdPersonOnlyLayer)))}_isEraseTarget(e){return e===this.humanoid.getRawBoneNode("head")?!0:e.parent?this._isEraseTarget(e.parent):!1}};gt.DEFAULT_FIRSTPERSON_ONLY_LAYER=9;gt.DEFAULT_THIRDPERSON_ONLY_LAYER=10;var ut=gt,Pr=new Set(["1.0","1.0-beta"]),Ne=class{get name(){return"VRMFirstPersonLoaderPlugin"}constructor(t){this.parser=t}afterRoot(t){return w(this,null,function*(){let e=t.userData.vrmHumanoid;if(e!==null){if(e===void 0)throw new Error("VRMFirstPersonLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");t.userData.vrmFirstPerson=yield this._import(t,e)}})}_import(t,e){return w(this,null,function*(){if(e==null)return null;let n=yield this._v1Import(t,e);if(n)return n;let i=yield this._v0Import(t,e);return i||null})}_v1Import(t,e){return w(this,null,function*(){var n,i;let r=this.parser.json;if(!(((n=r.extensionsUsed)==null?void 0:n.indexOf("VRMC_vrm"))!==-1))return null;let a=(i=r.extensions)==null?void 0:i.VRMC_vrm;if(!a)return null;let l=a.specVersion;if(!Pr.has(l))return console.warn(`VRMFirstPersonLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let o=a.firstPerson;if(!o)return null;let u=[],d=yield En(t);return Array.from(d.entries()).forEach(([c,f])=>{var p;let m=o.meshAnnotations?o.meshAnnotations.find(h=>h.node===c):void 0;u.push({meshes:f,type:(p=m==null?void 0:m.type)!=null?p:"both"})}),new ut(e,u)})}_v0Import(t,e){return w(this,null,function*(){var n;let i=this.parser.json,r=(n=i.extensions)==null?void 0:n.VRM;if(!r)return null;let s=r.firstPerson;if(!s)return null;let a=[],l=yield En(t);return Array.from(l.entries()).forEach(([o,u])=>{let d=i.nodes[o],c=s.meshAnnotations?s.meshAnnotations.find(f=>f.mesh===d.mesh):void 0;a.push({meshes:u,type:this._convertV0FlagToV1Type(c==null?void 0:c.firstPersonFlag)})}),new ut(e,a)})}_convertV0FlagToV1Type(t){return t==="FirstPersonOnly"?"firstPersonOnly":t==="ThirdPersonOnly"?"thirdPersonOnly":t==="Auto"?"auto":"both"}},Sr={Auto:"auto",Both:"both",ThirdPersonOnly:"thirdPersonOnly",FirstPersonOnly:"firstPersonOnly"},Rn=new j.Vector3,Tn=new j.Vector3,Ar=new j.Quaternion,dt=class extends j.Group{constructor(t){super(),this.vrmHumanoid=t,this._boneAxesMap=new Map,Object.values(t.humanBones).forEach(e=>{let n=new j.AxesHelper(1);n.matrixAutoUpdate=!1,n.material.depthTest=!1,n.material.depthWrite=!1,this.add(n),this._boneAxesMap.set(e,n)})}dispose(){Array.from(this._boneAxesMap.values()).forEach(t=>{t.geometry.dispose(),t.material.dispose()})}updateMatrixWorld(t){Array.from(this._boneAxesMap.entries()).forEach(([e,n])=>{e.node.updateWorldMatrix(!0,!1),e.node.matrixWorld.decompose(Rn,Ar,Tn);let i=Rn.set(.1,.1,.1).divide(Tn);n.matrix.copy(e.node.matrixWorld).scale(i)}),super.updateMatrixWorld(t)}},Ve=["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"],Lr={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"},zn={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"};function jn(t){return t.invert?t.invert():t.inverse(),t}var ee=new De.Vector3,te=new De.Quaternion,ht=class{constructor(t){this.humanBones=t,this.restPose=this.getAbsolutePose()}getAbsolutePose(){let t={};return Object.keys(this.humanBones).forEach(e=>{let n=e,i=this.getBoneNode(n);i&&(ee.copy(i.position),te.copy(i.quaternion),t[n]={position:ee.toArray(),rotation:te.toArray()})}),t}getPose(){let t={};return Object.keys(this.humanBones).forEach(e=>{let n=e,i=this.getBoneNode(n);if(!i)return;ee.set(0,0,0),te.identity();let r=this.restPose[n];r!=null&&r.position&&ee.fromArray(r.position).negate(),r!=null&&r.rotation&&jn(te.fromArray(r.rotation)),ee.add(i.position),te.premultiply(i.quaternion),t[n]={position:ee.toArray(),rotation:te.toArray()}}),t}setPose(t){Object.entries(t).forEach(([e,n])=>{let i=e,r=this.getBoneNode(i);if(!r)return;let s=this.restPose[i];s&&(n!=null&&n.position&&(r.position.fromArray(n.position),s.position&&r.position.add(ee.fromArray(s.position))),n!=null&&n.rotation&&(r.quaternion.fromArray(n.rotation),s.rotation&&r.quaternion.multiply(te.fromArray(s.rotation))))})}resetPose(){Object.entries(this.restPose).forEach(([t,e])=>{let n=this.getBoneNode(t);n&&(e!=null&&e.position&&n.position.fromArray(e.position),e!=null&&e.rotation&&n.quaternion.fromArray(e.rotation))})}getBone(t){var e;return(e=this.humanBones[t])!=null?e:void 0}getBoneNode(t){var e,n;return(n=(e=this.humanBones[t])==null?void 0:e.node)!=null?n:null}},tt=new B.Vector3,Hr=new B.Quaternion,br=new B.Vector3,xn=class Gn extends ht{static _setupTransforms(e){let n=new B.Object3D;n.name="VRMHumanoidRig";let i={},r={},s={},a={};Ve.forEach(o=>{var u;let d=e.getBoneNode(o);if(d){let c=new B.Vector3,f=new B.Quaternion;d.updateWorldMatrix(!0,!1),d.matrixWorld.decompose(c,f,tt),i[o]=c,r[o]=f,s[o]=d.quaternion.clone();let p=new B.Quaternion;(u=d.parent)==null||u.matrixWorld.decompose(tt,p,tt),a[o]=p}});let l={};return Ve.forEach(o=>{var u;let d=e.getBoneNode(o);if(d){let c=i[o],f=o,p;for(;p==null&&(f=zn[f],f!=null);)p=i[f];let m=new B.Object3D;m.name="Normalized_"+d.name,(f?(u=l[f])==null?void 0:u.node:n).add(m),m.position.copy(c),p&&m.position.sub(p),l[o]={node:m}}}),{rigBones:l,root:n,parentWorldRotations:a,boneRotations:s}}constructor(e){let{rigBones:n,root:i,parentWorldRotations:r,boneRotations:s}=Gn._setupTransforms(e);super(n),this.original=e,this.root=i,this._parentWorldRotations=r,this._boneRotations=s}update(){Ve.forEach(e=>{let n=this.original.getBoneNode(e);if(n!=null){let i=this.getBoneNode(e),r=this._parentWorldRotations[e],s=Hr.copy(r).invert(),a=this._boneRotations[e];if(n.quaternion.copy(i.quaternion).multiply(r).premultiply(s).multiply(a),e==="hips"){let l=i.getWorldPosition(br);n.parent.updateWorldMatrix(!0,!1);let o=n.parent.matrixWorld,u=l.applyMatrix4(o.invert());n.position.copy(u)}}})}},ct=class Qn{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,n){var i;this.autoUpdateHumanBones=(i=n==null?void 0:n.autoUpdateHumanBones)!=null?i:!0,this._rawHumanBones=new ht(e),this._normalizedHumanBones=new xn(this._rawHumanBones)}copy(e){return this.autoUpdateHumanBones=e.autoUpdateHumanBones,this._rawHumanBones=new ht(e.humanBones),this._normalizedHumanBones=new xn(this._rawHumanBones),this}clone(){return new Qn(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()}},qn={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"},Vr=new Set(["1.0","1.0-beta"]),yn={leftThumbProximal:"leftThumbMetacarpal",leftThumbIntermediate:"leftThumbProximal",rightThumbProximal:"rightThumbMetacarpal",rightThumbIntermediate:"rightThumbProximal"},Be=class{get name(){return"VRMHumanoidLoaderPlugin"}constructor(t,e){this.parser=t,this.helperRoot=e==null?void 0:e.helperRoot,this.autoUpdateHumanBones=e==null?void 0:e.autoUpdateHumanBones}afterRoot(t){return w(this,null,function*(){t.userData.vrmHumanoid=yield this._import(t)})}_import(t){return w(this,null,function*(){let e=yield this._v1Import(t);if(e)return e;let n=yield this._v0Import(t);return n||null})}_v1Import(t){return w(this,null,function*(){var e,n;let i=this.parser.json;if(!(((e=i.extensionsUsed)==null?void 0:e.indexOf("VRMC_vrm"))!==-1))return null;let s=(n=i.extensions)==null?void 0:n.VRMC_vrm;if(!s)return null;let a=s.specVersion;if(!Vr.has(a))return console.warn(`VRMHumanoidLoaderPlugin: Unknown VRMC_vrm specVersion "${a}"`),null;let l=s.humanoid;if(!l)return null;let o=l.humanBones.leftThumbIntermediate!=null||l.humanBones.rightThumbIntermediate!=null,u={};l.humanBones!=null&&(yield Promise.all(Object.entries(l.humanBones).map(c=>w(this,[c],function*([f,p]){let m=f,h=p.node;if(o){let g=yn[m];g!=null&&(m=g)}let _=yield this.parser.getDependency("node",h);if(_==null){console.warn(`A glTF node bound to the humanoid bone ${m} (index = ${h}) does not exist`);return}u[m]={node:_}}))));let d=new ct(this._ensureRequiredBonesExist(u),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(t.scene.add(d.normalizedHumanBonesRoot),this.helperRoot){let c=new dt(d);this.helperRoot.add(c),c.renderOrder=this.helperRoot.renderOrder}return d})}_v0Import(t){return w(this,null,function*(){var e;let i=(e=this.parser.json.extensions)==null?void 0:e.VRM;if(!i)return null;let r=i.humanoid;if(!r)return null;let s={};r.humanBones!=null&&(yield Promise.all(r.humanBones.map(l=>w(this,null,function*(){let o=l.bone,u=l.node;if(o==null||u==null)return;let d=yield this.parser.getDependency("node",u);if(d==null){console.warn(`A glTF node bound to the humanoid bone ${o} (index = ${u}) does not exist`);return}let c=yn[o],f=c!=null?c:o;if(s[f]!=null){console.warn(`Multiple bone entries for ${f} detected (index = ${u}), ignoring duplicated entries.`);return}s[f]={node:d}}))));let a=new ct(this._ensureRequiredBonesExist(s),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(t.scene.add(a.normalizedHumanBonesRoot),this.helperRoot){let l=new dt(a);this.helperRoot.add(l),l.renderOrder=this.helperRoot.renderOrder}return a})}_ensureRequiredBonesExist(t){let e=Object.values(qn).filter(n=>t[n]==null);if(e.length>0)throw new Error(`VRMHumanoidLoaderPlugin: These humanoid bones are required but not exist: ${e.join(", ")}`);return t}},wn=class extends Ee.BufferGeometry{constructor(){super(),this._currentTheta=0,this._currentRadius=0,this.theta=0,this.radius=0,this._currentTheta=0,this._currentRadius=0,this._attrPos=new Ee.BufferAttribute(new Float32Array(65*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new Ee.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 e=t/63*this._currentTheta;this._attrPos.setXYZ(t+1,this._currentRadius*Math.sin(e),0,this._currentRadius*Math.cos(e))}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}},Ir=class extends Y.BufferGeometry{constructor(){super(),this.radius=0,this._currentRadius=0,this.tail=new Y.Vector3,this._currentTail=new Y.Vector3,this._attrPos=new Y.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new Y.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this.radius&&(this._currentRadius=this.radius,t=!0),this._currentTail.equals(this.tail)||(this._currentTail.copy(this.tail),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){let e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}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 t=0;t<32;t++){let e=(t+1)%32;this._attrIndex.setXY(t*2,t,e),this._attrIndex.setXY(64+t*2,32+t,32+e),this._attrIndex.setXY(128+t*2,64+t,64+e)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}},He=new S.Quaternion,Pn=new S.Quaternion,ge=new S.Vector3,Sn=new S.Vector3,An=Math.sqrt(2)/2,Ur=new S.Quaternion(0,0,-An,An),Cr=new S.Vector3(0,1,0),Xn=class extends S.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.vrmLookAt=t;{let e=new wn;e.radius=.5;let n=new S.MeshBasicMaterial({color:65280,transparent:!0,opacity:.5,side:S.DoubleSide,depthTest:!1,depthWrite:!1});this._meshPitch=new S.Mesh(e,n),this.add(this._meshPitch)}{let e=new wn;e.radius=.5;let n=new S.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.5,side:S.DoubleSide,depthTest:!1,depthWrite:!1});this._meshYaw=new S.Mesh(e,n),this.add(this._meshYaw)}{let e=new Ir;e.radius=.1;let n=new S.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1});this._lineTarget=new S.LineSegments(e,n),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(t){let e=S.MathUtils.DEG2RAD*this.vrmLookAt.yaw;this._meshYaw.geometry.theta=e,this._meshYaw.geometry.update();let n=S.MathUtils.DEG2RAD*this.vrmLookAt.pitch;this._meshPitch.geometry.theta=n,this._meshPitch.geometry.update(),this.vrmLookAt.getLookAtWorldPosition(ge),this.vrmLookAt.getLookAtWorldQuaternion(He),He.multiply(this.vrmLookAt.getFaceFrontQuaternion(Pn)),this._meshYaw.position.copy(ge),this._meshYaw.quaternion.copy(He),this._meshPitch.position.copy(ge),this._meshPitch.quaternion.copy(He),this._meshPitch.quaternion.multiply(Pn.setFromAxisAngle(Cr,e)),this._meshPitch.quaternion.multiply(Ur);let{target:i,autoUpdate:r}=this.vrmLookAt;i!=null&&r&&(i.getWorldPosition(Sn).sub(ge),this._lineTarget.geometry.tail.copy(Sn),this._lineTarget.geometry.update(),this._lineTarget.position.copy(ge)),super.updateMatrixWorld(t)}},Or=new vt.Vector3,Nr=new vt.Vector3;function pt(t,e){return t.matrixWorld.decompose(Or,e,Nr),e}function Ie(t){return[Math.atan2(-t.z,t.x),Math.atan2(t.y,Math.sqrt(t.x*t.x+t.z*t.z))]}function Ln(t){let e=Math.round(t/2/Math.PI);return t-2*Math.PI*e}var Hn=new V.Vector3(0,0,1),Dr=new V.Vector3,Br=new V.Vector3,Fr=new V.Vector3,Wr=new V.Quaternion,nt=new V.Quaternion,bn=new V.Quaternion,kr=new V.Quaternion,it=new V.Euler,Yn=class $n{constructor(e,n){this.offsetFromHeadBone=new V.Vector3,this.autoUpdate=!0,this.faceFront=new V.Vector3(0,0,1),this.humanoid=e,this.applier=n,this._yaw=0,this._pitch=0,this._needsUpdate=!0,this._restHeadWorldQuaternion=this.getLookAtWorldQuaternion(new V.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 V.Euler)}getEuler(e){return e.set(V.MathUtils.DEG2RAD*this._pitch,V.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 $n(this.humanoid,this.applier).copy(this)}reset(){this._yaw=0,this._pitch=0,this._needsUpdate=!0}getLookAtWorldPosition(e){let n=this.humanoid.getRawBoneNode("head");return e.copy(this.offsetFromHeadBone).applyMatrix4(n.matrixWorld)}getLookAtWorldQuaternion(e){let n=this.humanoid.getRawBoneNode("head");return pt(n,e)}getFaceFrontQuaternion(e){if(this.faceFront.distanceToSquared(Hn)<.01)return e.copy(this._restHeadWorldQuaternion).invert();let[n,i]=Ie(this.faceFront);return it.set(0,.5*Math.PI+n,i,"YZX"),e.setFromEuler(it).premultiply(kr.copy(this._restHeadWorldQuaternion).invert())}getLookAtWorldDirection(e){return this.getLookAtWorldQuaternion(nt),this.getFaceFrontQuaternion(bn),e.copy(Hn).applyQuaternion(nt).applyQuaternion(bn).applyEuler(this.getEuler(it))}lookAt(e){let n=Wr.copy(this._restHeadWorldQuaternion).multiply(jn(this.getLookAtWorldQuaternion(nt))),i=this.getLookAtWorldPosition(Br),r=Fr.copy(e).sub(i).applyQuaternion(n).normalize(),[s,a]=Ie(this.faceFront),[l,o]=Ie(r),u=Ln(l-s),d=Ln(a-o);this._yaw=V.MathUtils.RAD2DEG*u,this._pitch=V.MathUtils.RAD2DEG*d,this._needsUpdate=!0}update(e){this.target!=null&&this.autoUpdate&&this.lookAt(this.target.getWorldPosition(Dr)),this._needsUpdate&&(this._needsUpdate=!1,this.applier.applyYawPitch(this._yaw,this._pitch))}};Yn.EULER_ORDER="YXZ";var Zn=Yn,zr=new A.Vector3(0,0,1),F=new A.Quaternion,le=new A.Quaternion,N=new A.Euler(0,0,0,"YXZ"),ve=class{constructor(t,e,n,i,r){this.humanoid=t,this.rangeMapHorizontalInner=e,this.rangeMapHorizontalOuter=n,this.rangeMapVerticalDown=i,this.rangeMapVerticalUp=r,this.faceFront=new A.Vector3(0,0,1),this._restQuatLeftEye=new A.Quaternion,this._restQuatRightEye=new A.Quaternion,this._restLeftEyeParentWorldQuat=new A.Quaternion,this._restRightEyeParentWorldQuat=new A.Quaternion;let s=this.humanoid.getRawBoneNode("leftEye"),a=this.humanoid.getRawBoneNode("rightEye");s&&(this._restQuatLeftEye.copy(s.quaternion),pt(s.parent,this._restLeftEyeParentWorldQuat)),a&&(this._restQuatRightEye.copy(a.quaternion),pt(a.parent,this._restRightEyeParentWorldQuat))}applyYawPitch(t,e){let n=this.humanoid.getRawBoneNode("leftEye"),i=this.humanoid.getRawBoneNode("rightEye"),r=this.humanoid.getNormalizedBoneNode("leftEye"),s=this.humanoid.getNormalizedBoneNode("rightEye");n&&(e<0?N.x=-A.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-e):N.x=A.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(e),t<0?N.y=-A.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(-t):N.y=A.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(t),F.setFromEuler(N),this._getWorldFaceFrontQuat(le),r.quaternion.copy(le).multiply(F).multiply(le.invert()),F.copy(this._restLeftEyeParentWorldQuat),n.quaternion.copy(r.quaternion).multiply(F).premultiply(F.invert()).multiply(this._restQuatLeftEye)),i&&(e<0?N.x=-A.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-e):N.x=A.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(e),t<0?N.y=-A.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(-t):N.y=A.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(t),F.setFromEuler(N),this._getWorldFaceFrontQuat(le),s.quaternion.copy(le).multiply(F).multiply(le.invert()),F.copy(this._restRightEyeParentWorldQuat),i.quaternion.copy(s.quaternion).multiply(F).premultiply(F.invert()).multiply(this._restQuatRightEye))}lookAt(t){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let e=A.MathUtils.RAD2DEG*t.y,n=A.MathUtils.RAD2DEG*t.x;this.applyYawPitch(e,n)}_getWorldFaceFrontQuat(t){if(this.faceFront.distanceToSquared(zr)<.01)return t.identity();let[e,n]=Ie(this.faceFront);return N.set(0,.5*Math.PI+e,n,"YZX"),t.setFromEuler(N)}};ve.type="bone";var Ce=class{constructor(t,e,n,i,r){this.expressions=t,this.rangeMapHorizontalInner=e,this.rangeMapHorizontalOuter=n,this.rangeMapVerticalDown=i,this.rangeMapVerticalUp=r}applyYawPitch(t,e){e<0?(this.expressions.setValue("lookDown",0),this.expressions.setValue("lookUp",this.rangeMapVerticalUp.map(-e))):(this.expressions.setValue("lookUp",0),this.expressions.setValue("lookDown",this.rangeMapVerticalDown.map(e))),t<0?(this.expressions.setValue("lookLeft",0),this.expressions.setValue("lookRight",this.rangeMapHorizontalOuter.map(-t))):(this.expressions.setValue("lookRight",0),this.expressions.setValue("lookLeft",this.rangeMapHorizontalOuter.map(t)))}lookAt(t){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let e=mt.MathUtils.RAD2DEG*t.y,n=mt.MathUtils.RAD2DEG*t.x;this.applyYawPitch(e,n)}};Ce.type="expression";var ft=class{constructor(t,e){this.inputMaxValue=t,this.outputScale=e}map(t){return this.outputScale*Un(t/this.inputMaxValue)}},jr=new Set(["1.0","1.0-beta"]),be=.01,Fe=class{get name(){return"VRMLookAtLoaderPlugin"}constructor(t,e){this.parser=t,this.helperRoot=e==null?void 0:e.helperRoot}afterRoot(t){return w(this,null,function*(){let e=t.userData.vrmHumanoid;if(e===null)return;if(e===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmHumanoid is undefined. VRMHumanoidLoaderPlugin have to be used first");let n=t.userData.vrmExpressionManager;if(n!==null){if(n===void 0)throw new Error("VRMLookAtLoaderPlugin: vrmExpressionManager is undefined. VRMExpressionLoaderPlugin have to be used first");t.userData.vrmLookAt=yield this._import(t,e,n)}})}_import(t,e,n){return w(this,null,function*(){if(e==null||n==null)return null;let i=yield this._v1Import(t,e,n);if(i)return i;let r=yield this._v0Import(t,e,n);return r||null})}_v1Import(t,e,n){return w(this,null,function*(){var i,r,s;let a=this.parser.json;if(!(((i=a.extensionsUsed)==null?void 0:i.indexOf("VRMC_vrm"))!==-1))return null;let o=(r=a.extensions)==null?void 0:r.VRMC_vrm;if(!o)return null;let u=o.specVersion;if(!jr.has(u))return console.warn(`VRMLookAtLoaderPlugin: Unknown VRMC_vrm specVersion "${u}"`),null;let d=o.lookAt;if(!d)return null;let c=d.type==="expression"?1:10,f=this._v1ImportRangeMap(d.rangeMapHorizontalInner,c),p=this._v1ImportRangeMap(d.rangeMapHorizontalOuter,c),m=this._v1ImportRangeMap(d.rangeMapVerticalDown,c),h=this._v1ImportRangeMap(d.rangeMapVerticalUp,c),_;d.type==="expression"?_=new Ce(n,f,p,m,h):_=new ve(e,f,p,m,h);let g=this._importLookAt(e,_);return g.offsetFromHeadBone.fromArray((s=d.offsetFromHeadBone)!=null?s:[0,.06,0]),g})}_v1ImportRangeMap(t,e){var n,i;let r=(n=t==null?void 0:t.inputMaxValue)!=null?n:90,s=(i=t==null?void 0:t.outputScale)!=null?i:e;return r<be&&(console.warn("VRMLookAtLoaderPlugin: inputMaxValue of a range map is too small. Consider reviewing the range map!"),r=be),new ft(r,s)}_v0Import(t,e,n){return w(this,null,function*(){var i,r,s,a;let o=(i=this.parser.json.extensions)==null?void 0:i.VRM;if(!o)return null;let u=o.firstPerson;if(!u)return null;let d=u.lookAtTypeName==="BlendShape"?1:10,c=this._v0ImportDegreeMap(u.lookAtHorizontalInner,d),f=this._v0ImportDegreeMap(u.lookAtHorizontalOuter,d),p=this._v0ImportDegreeMap(u.lookAtVerticalDown,d),m=this._v0ImportDegreeMap(u.lookAtVerticalUp,d),h;u.lookAtTypeName==="BlendShape"?h=new Ce(n,c,f,p,m):h=new ve(e,c,f,p,m);let _=this._importLookAt(e,h);return u.firstPersonBoneOffset?_.offsetFromHeadBone.set((r=u.firstPersonBoneOffset.x)!=null?r:0,(s=u.firstPersonBoneOffset.y)!=null?s:.06,-((a=u.firstPersonBoneOffset.z)!=null?a:0)):_.offsetFromHeadBone.set(0,.06,0),_.faceFront.set(0,0,-1),h instanceof ve&&h.faceFront.set(0,0,-1),_})}_v0ImportDegreeMap(t,e){var n,i;let r=t==null?void 0:t.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 s=(n=t==null?void 0:t.xRange)!=null?n:90,a=(i=t==null?void 0:t.yRange)!=null?i:e;return s<be&&(console.warn("VRMLookAtLoaderPlugin: xRange of a degree map is too small. Consider reviewing the degree map!"),s=be),new ft(s,a)}_importLookAt(t,e){let n=new Zn(t,e);if(this.helperRoot){let i=new Xn(n);this.helperRoot.add(i),i.renderOrder=this.helperRoot.renderOrder}return n}},Gr={Bone:"bone",Expression:"expression"};function Qr(t,e){return typeof t!="string"||t===""?"":(/^https?:\/\//i.test(e)&&/^\//.test(t)&&(e=e.replace(/(^https?:\/\/[^/]+).*/i,"$1")),/^(https?:)?\/\//i.test(t)||/^data:.*,.*$/i.test(t)||/^blob:.*$/i.test(t)?t:e+t)}var qr=new Set(["1.0","1.0-beta"]),We=class{get name(){return"VRMMetaLoaderPlugin"}constructor(t,e){var n,i,r;this.parser=t,this.needThumbnailImage=(n=e==null?void 0:e.needThumbnailImage)!=null?n:!1,this.acceptLicenseUrls=(i=e==null?void 0:e.acceptLicenseUrls)!=null?i:["https://vrm.dev/licenses/1.0/"],this.acceptV0Meta=(r=e==null?void 0:e.acceptV0Meta)!=null?r:!0}afterRoot(t){return w(this,null,function*(){t.userData.vrmMeta=yield this._import(t)})}_import(t){return w(this,null,function*(){let e=yield this._v1Import(t);if(e!=null)return e;let n=yield this._v0Import(t);return n!=null?n:null})}_v1Import(t){return w(this,null,function*(){var e,n,i;let r=this.parser.json;if(!(((e=r.extensionsUsed)==null?void 0:e.indexOf("VRMC_vrm"))!==-1))return null;let a=(n=r.extensions)==null?void 0:n.VRMC_vrm;if(a==null)return null;let l=a.specVersion;if(!qr.has(l))return console.warn(`VRMMetaLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let o=a.meta;if(!o)return null;let u=o.licenseUrl;if(!new Set(this.acceptLicenseUrls).has(u))throw new Error(`VRMMetaLoaderPlugin: The license url "${u}" is not accepted`);let c;return this.needThumbnailImage&&o.thumbnailImage!=null&&(c=(i=yield this._extractGLTFImage(o.thumbnailImage))!=null?i:void 0),{metaVersion:"1",name:o.name,version:o.version,authors:o.authors,copyrightInformation:o.copyrightInformation,contactInformation:o.contactInformation,references:o.references,thirdPartyLicenses:o.thirdPartyLicenses,thumbnailImage:c,licenseUrl:o.licenseUrl,avatarPermission:o.avatarPermission,allowExcessivelyViolentUsage:o.allowExcessivelyViolentUsage,allowExcessivelySexualUsage:o.allowExcessivelySexualUsage,commercialUsage:o.commercialUsage,allowPoliticalOrReligiousUsage:o.allowPoliticalOrReligiousUsage,allowAntisocialOrHateUsage:o.allowAntisocialOrHateUsage,creditNotation:o.creditNotation,allowRedistribution:o.allowRedistribution,modification:o.modification,otherLicenseUrl:o.otherLicenseUrl}})}_v0Import(t){return w(this,null,function*(){var e;let i=(e=this.parser.json.extensions)==null?void 0:e.VRM;if(!i)return null;let r=i.meta;if(!r)return null;if(!this.acceptV0Meta)throw new Error("VRMMetaLoaderPlugin: Attempted to load VRM0.0 meta but acceptV0Meta is false");let s;return this.needThumbnailImage&&r.texture!=null&&r.texture!==-1&&(s=yield this.parser.getDependency("texture",r.texture)),{metaVersion:"0",allowedUserName:r.allowedUserName,author:r.author,commercialUssageName:r.commercialUssageName,contactInformation:r.contactInformation,licenseName:r.licenseName,otherLicenseUrl:r.otherLicenseUrl,otherPermissionUrl:r.otherPermissionUrl,reference:r.reference,sexualUssageName:r.sexualUssageName,texture:s!=null?s:void 0,title:r.title,version:r.version,violentUssageName:r.violentUssageName}})}_extractGLTFImage(t){return w(this,null,function*(){var e;let i=(e=this.parser.json.images)==null?void 0:e[t];if(i==null)return console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${t}] of glTF as a thumbnail but the image doesn't exist`),null;let r=i.uri;if(i.bufferView!=null){let a=yield this.parser.getDependency("bufferView",i.bufferView),l=new Blob([a],{type:i.mimeType});r=URL.createObjectURL(l)}return r==null?(console.warn(`VRMMetaLoaderPlugin: Attempt to use images[${t}] of glTF as a thumbnail but the image couldn't load properly`),null):yield new Jn.ImageLoader().loadAsync(Qr(r,this.parser.options.path)).catch(a=>(console.error(a),console.warn("VRMMetaLoaderPlugin: Failed to load a thumbnail image"),null))})}},ke=class{constructor(t){this.scene=t.scene,this.meta=t.meta,this.humanoid=t.humanoid,this.expressionManager=t.expressionManager,this.firstPerson=t.firstPerson,this.lookAt=t.lookAt}update(t){this.humanoid.update(),this.lookAt&&this.lookAt.update(t),this.expressionManager&&this.expressionManager.update()}},Xr=class{get name(){return"VRMC_vrm"}constructor(t,e){var n,i,r,s,a;this.parser=t;let l=e==null?void 0:e.helperRoot,o=e==null?void 0:e.autoUpdateHumanBones;this.expressionPlugin=(n=e==null?void 0:e.expressionPlugin)!=null?n:new Oe(t),this.firstPersonPlugin=(i=e==null?void 0:e.firstPersonPlugin)!=null?i:new Ne(t),this.humanoidPlugin=(r=e==null?void 0:e.humanoidPlugin)!=null?r:new Be(t,{helperRoot:l,autoUpdateHumanBones:o}),this.lookAtPlugin=(s=e==null?void 0:e.lookAtPlugin)!=null?s:new Fe(t,{helperRoot:l}),this.metaPlugin=(a=e==null?void 0:e.metaPlugin)!=null?a:new We(t)}afterRoot(t){return w(this,null,function*(){yield this.metaPlugin.afterRoot(t),yield this.humanoidPlugin.afterRoot(t),yield this.expressionPlugin.afterRoot(t),yield this.lookAtPlugin.afterRoot(t),yield this.firstPersonPlugin.afterRoot(t);let e=t.userData.vrmMeta,n=t.userData.vrmHumanoid;if(e&&n){let i=new ke({scene:t.scene,expressionManager:t.userData.vrmExpressionManager,firstPerson:t.userData.vrmFirstPerson,humanoid:n,lookAt:t.userData.vrmLookAt,meta:e});t.userData.vrmCore=i}})}};var he=class extends ke{constructor(e){super(e),this.materials=e.materials,this.springBoneManager=e.springBoneManager,this.nodeConstraintManager=e.nodeConstraintManager}update(e){super.update(e),this.nodeConstraintManager&&this.nodeConstraintManager.update(),this.springBoneManager&&this.springBoneManager.update(e),this.materials&&this.materials.forEach(n=>{n.update&&n.update(e)})}};var Ge=M(require("three"),1),ni=M(require("three"),1),ii=M(require("three"),1),P=M(require("three"),1),oi=M(require("three"),1);var Yr=Object.defineProperty,Kn=Object.getOwnPropertySymbols,$r=Object.prototype.hasOwnProperty,Zr=Object.prototype.propertyIsEnumerable,ei=(t,e,n)=>e in t?Yr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ti=(t,e)=>{for(var n in e||(e={}))$r.call(e,n)&&ei(t,n,e[n]);if(Kn)for(var n of Kn(e))Zr.call(e,n)&&ei(t,n,e[n]);return t},ne=(t,e,n)=>new Promise((i,r)=>{var s=o=>{try{l(n.next(o))}catch(u){r(u)}},a=o=>{try{l(n.throw(o))}catch(u){r(u)}},l=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);l((n=n.apply(t,e)).next())}),Jr={"":3e3,srgb:3001};function Kr(t,e){parseInt(ii.REVISION,10)>=152?t.colorSpace=e:t.encoding=Jr[e]}var eo=class{get pending(){return Promise.all(this._pendings)}constructor(t,e){this._parser=t,this._materialParams=e,this._pendings=[]}assignPrimitive(t,e){e!=null&&(this._materialParams[t]=e)}assignColor(t,e,n){e!=null&&(this._materialParams[t]=new ni.Color().fromArray(e),n&&this._materialParams[t].convertSRGBToLinear())}assignTexture(t,e,n){return ne(this,null,function*(){let i=ne(this,null,function*(){e!=null&&(yield this._parser.assignTexture(this._materialParams,t,e),n&&Kr(this._materialParams[t],"srgb"))});return this._pendings.push(i),i})}assignTextureByIndex(t,e,n){return ne(this,null,function*(){return this.assignTexture(t,e!=null?{index:e}:void 0,n)})}},to=`// #define PHONG
3
3
 
4
4
  varying vec3 vViewPosition;
5
5
 
@@ -122,7 +122,7 @@ void main() {
122
122
  #include <shadowmap_vertex>
123
123
  #include <fog_vertex>
124
124
 
125
- }`,yo=`// #define PHONG
125
+ }`,no=`// #define PHONG
126
126
 
127
127
  uniform vec3 litFactor;
128
128
 
@@ -201,9 +201,7 @@ uniform float uvAnimationRotationPhase;
201
201
 
202
202
  // #include <alphamap_pars_fragment>
203
203
 
204
- #if THREE_VRM_THREE_REVISION >= 132
205
- #include <alphatest_pars_fragment>
206
- #endif
204
+ #include <alphatest_pars_fragment>
207
205
 
208
206
  #include <aomap_pars_fragment>
209
207
  // #include <lightmap_pars_fragment>
@@ -228,19 +226,11 @@ uniform float uvAnimationRotationPhase;
228
226
 
229
227
  #include <lights_pars_begin>
230
228
 
231
- #if THREE_VRM_THREE_REVISION >= 132
232
- #include <normal_pars_fragment>
233
- #endif
229
+ #include <normal_pars_fragment>
234
230
 
235
231
  // #include <lights_phong_pars_fragment>
236
232
  varying vec3 vViewPosition;
237
233
 
238
- #if THREE_VRM_THREE_REVISION < 132
239
- #ifndef FLAT_SHADED
240
- varying vec3 vNormal;
241
- #endif
242
- #endif
243
-
244
234
  struct MToonMaterial {
245
235
  vec3 diffuseColor;
246
236
  vec3 shadeColor;
@@ -278,12 +268,6 @@ vec3 getDiffuse(
278
268
  return vec3( BRDF_Lambert( shading * lightColor ) );
279
269
  #endif
280
270
 
281
- #if THREE_VRM_THREE_REVISION < 132
282
- #ifndef PHYSICALLY_CORRECT_LIGHTS
283
- lightColor *= PI;
284
- #endif
285
- #endif
286
-
287
271
  vec3 col = lightColor * BRDF_Lambert( mix( material.shadeColor, material.diffuseColor, shading ) );
288
272
 
289
273
  // The "comment out if you want to PBR absolutely" line
@@ -323,12 +307,6 @@ vec3 getDiffuse(
323
307
  float dotNL = clamp( dot( geometry.normal, directLight.direction ), -1.0, 1.0 );
324
308
  vec3 irradiance = directLight.color;
325
309
 
326
- #if THREE_VRM_THREE_REVISION < 132
327
- #ifndef PHYSICALLY_CORRECT_LIGHTS
328
- irradiance *= PI;
329
- #endif
330
- #endif
331
-
332
310
  // directSpecular will be used for rim lighting, not an actual specular
333
311
  reflectedLight.directSpecular += irradiance;
334
312
 
@@ -365,14 +343,16 @@ vec3 getDiffuse(
365
343
 
366
344
  #endif
367
345
 
368
- // COMPAT: USE_NORMALMAP_OBJECTSPACE used to be OBJECTSPACE_NORMALMAP in pre-r151
346
+ // COMPAT: pre-r151
347
+ // USE_NORMALMAP_OBJECTSPACE used to be OBJECTSPACE_NORMALMAP in pre-r151
369
348
  #if defined( USE_NORMALMAP_OBJECTSPACE ) || defined( OBJECTSPACE_NORMALMAP )
370
349
 
371
350
  uniform mat3 normalMatrix;
372
351
 
373
352
  #endif
374
353
 
375
- // COMPAT: USE_NORMALMAP_TANGENTSPACE used to be TANGENTSPACE_NORMALMAP in pre-r151
354
+ // COMPAT: pre-r151
355
+ // USE_NORMALMAP_TANGENTSPACE used to be TANGENTSPACE_NORMALMAP in pre-r151
376
356
  #if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( TANGENTSPACE_NORMALMAP ) )
377
357
 
378
358
  // Per-Pixel Tangent Space Normal Mapping
@@ -405,7 +385,7 @@ vec3 getDiffuse(
405
385
 
406
386
  }
407
387
 
408
- #elif THREE_VRM_THREE_REVISION >= 126
388
+ #else
409
389
 
410
390
  vec3 perturbNormal2Arb( vec2 uv, vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {
411
391
 
@@ -435,52 +415,6 @@ vec3 getDiffuse(
435
415
 
436
416
  }
437
417
 
438
- #else
439
-
440
- vec3 perturbNormal2Arb( vec2 uv, vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {
441
-
442
- // Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988
443
-
444
- vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
445
- vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
446
- vec2 st0 = dFdx( uv.st );
447
- vec2 st1 = dFdy( uv.st );
448
-
449
- float scale = sign( st1.t * st0.s - st0.t * st1.s ); // we do not care about the magnitude
450
-
451
- vec3 S = ( q0 * st1.t - q1 * st0.t ) * scale;
452
- vec3 T = ( - q0 * st1.s + q1 * st0.s ) * scale;
453
-
454
- // three-vrm specific change: Workaround for the issue that happens when delta of uv = 0.0
455
- // TODO: Is this still required? Or shall I make a PR about it?
456
-
457
- if ( length( S ) == 0.0 || length( T ) == 0.0 ) {
458
- return surf_norm;
459
- }
460
-
461
- S = normalize( S );
462
- T = normalize( T );
463
- vec3 N = normalize( surf_norm );
464
-
465
- #ifdef DOUBLE_SIDED
466
-
467
- // Workaround for Adreno GPUs gl_FrontFacing bug. See #15850 and #10331
468
-
469
- bool frontFacing = dot( cross( S, T ), N ) > 0.0;
470
-
471
- mapN.xy *= ( float( frontFacing ) * 2.0 - 1.0 );
472
-
473
- #else
474
-
475
- mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
476
-
477
- #endif
478
-
479
- mat3 tsn = mat3( S, T, N );
480
- return normalize( tsn * mapN );
481
-
482
- }
483
-
484
418
  #endif
485
419
 
486
420
  #endif
@@ -633,7 +567,8 @@ void main() {
633
567
 
634
568
  // #include <normal_fragment_maps>
635
569
 
636
- // COMPAT: USE_NORMALMAP_OBJECTSPACE used to be OBJECTSPACE_NORMALMAP in pre-r151
570
+ // COMPAT: pre-r151
571
+ // USE_NORMALMAP_OBJECTSPACE used to be OBJECTSPACE_NORMALMAP in pre-r151
637
572
  #if defined( USE_NORMALMAP_OBJECTSPACE ) || defined( OBJECTSPACE_NORMALMAP )
638
573
 
639
574
  normal = texture2D( normalMap, normalMapUv ).xyz * 2.0 - 1.0; // overrides both flatShading and attribute normals
@@ -646,23 +581,14 @@ void main() {
646
581
 
647
582
  #ifdef DOUBLE_SIDED
648
583
 
649
- // Temporary compat against shader change @ Three.js r126
650
- // See: #21205, #21307, #21299
651
- #if THREE_VRM_THREE_REVISION >= 126
652
-
653
- normal = normal * faceDirection;
654
-
655
- #else
656
-
657
- normal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );
658
-
659
- #endif
584
+ normal = normal * faceDirection;
660
585
 
661
586
  #endif
662
587
 
663
588
  normal = normalize( normalMatrix * normal );
664
589
 
665
- // COMPAT: USE_NORMALMAP_TANGENTSPACE used to be TANGENTSPACE_NORMALMAP in pre-r151
590
+ // COMPAT: pre-r151
591
+ // USE_NORMALMAP_TANGENTSPACE used to be TANGENTSPACE_NORMALMAP in pre-r151
666
592
  #elif defined( USE_NORMALMAP_TANGENTSPACE ) || defined( TANGENTSPACE_NORMALMAP )
667
593
 
668
594
  vec3 mapN = texture2D( normalMap, normalMapUv ).xyz * 2.0 - 1.0;
@@ -675,16 +601,7 @@ void main() {
675
601
 
676
602
  #else
677
603
 
678
- // pre-r126
679
- #if THREE_VRM_THREE_REVISION >= 126
680
-
681
- normal = perturbNormal2Arb( uv, -vViewPosition, normal, mapN, faceDirection );
682
-
683
- #else
684
-
685
- normal = perturbNormal2Arb( uv, -vViewPosition, normal, mapN );
686
-
687
- #endif
604
+ normal = perturbNormal2Arb( uv, -vViewPosition, normal, mapN, faceDirection );
688
605
 
689
606
  #endif
690
607
 
@@ -777,16 +694,20 @@ void main() {
777
694
  // COMPAT: pre-r156 uses a struct GeometricContext
778
695
  #if THREE_VRM_THREE_REVISION >= 157
779
696
  getPointLightInfo( pointLight, geometryPosition, directLight );
780
- #elif THREE_VRM_THREE_REVISION >= 132
781
- getPointLightInfo( pointLight, geometry, directLight );
782
697
  #else
783
- getPointDirectLightIrradiance( pointLight, geometry, directLight );
698
+ getPointLightInfo( pointLight, geometry, directLight );
784
699
  #endif
785
700
 
786
701
  shadow = 1.0;
787
702
  #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
788
703
  pointLightShadow = pointLightShadows[ i ];
789
- shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
704
+ // COMPAT: pre-r166
705
+ // r166 introduced shadowIntensity
706
+ #if THREE_VRM_THREE_REVISION >= 166
707
+ shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
708
+ #else
709
+ shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
710
+ #endif
790
711
  #endif
791
712
 
792
713
  // COMPAT: pre-r156 uses a struct GeometricContext
@@ -816,16 +737,20 @@ void main() {
816
737
  // COMPAT: pre-r156 uses a struct GeometricContext
817
738
  #if THREE_VRM_THREE_REVISION >= 157
818
739
  getSpotLightInfo( spotLight, geometryPosition, directLight );
819
- #elif THREE_VRM_THREE_REVISION >= 132
820
- getSpotLightInfo( spotLight, geometry, directLight );
821
740
  #else
822
- getSpotDirectLightIrradiance( spotLight, geometry, directLight );
741
+ getSpotLightInfo( spotLight, geometry, directLight );
823
742
  #endif
824
743
 
825
744
  shadow = 1.0;
826
745
  #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
827
746
  spotLightShadow = spotLightShadows[ i ];
828
- shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
747
+ // COMPAT: pre-r166
748
+ // r166 introduced shadowIntensity
749
+ #if THREE_VRM_THREE_REVISION >= 166
750
+ shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
751
+ #else
752
+ shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;
753
+ #endif
829
754
  #endif
830
755
 
831
756
  // COMPAT: pre-r156 uses a struct GeometricContext
@@ -855,16 +780,20 @@ void main() {
855
780
  // COMPAT: pre-r156 uses a struct GeometricContext
856
781
  #if THREE_VRM_THREE_REVISION >= 157
857
782
  getDirectionalLightInfo( directionalLight, directLight );
858
- #elif THREE_VRM_THREE_REVISION >= 132
859
- getDirectionalLightInfo( directionalLight, geometry, directLight );
860
783
  #else
861
- getDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );
784
+ getDirectionalLightInfo( directionalLight, geometry, directLight );
862
785
  #endif
863
786
 
864
787
  shadow = 1.0;
865
788
  #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
866
789
  directionalLightShadow = directionalLightShadows[ i ];
867
- shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
790
+ // COMPAT: pre-r166
791
+ // r166 introduced shadowIntensity
792
+ #if THREE_VRM_THREE_REVISION >= 166
793
+ shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
794
+ #else
795
+ shadow = all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
796
+ #endif
868
797
  #endif
869
798
 
870
799
  // COMPAT: pre-r156 uses a struct GeometricContext
@@ -906,10 +835,8 @@ void main() {
906
835
  #if defined( USE_LIGHT_PROBES )
907
836
  irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
908
837
  #endif
909
- #elif THREE_VRM_THREE_REVISION >= 133
910
- irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
911
838
  #else
912
- irradiance += getLightProbeIrradiance( lightProbe, geometry );
839
+ irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
913
840
  #endif
914
841
 
915
842
  #if ( NUM_HEMI_LIGHTS > 0 )
@@ -920,10 +847,8 @@ void main() {
920
847
  // COMPAT: pre-r156 uses a struct GeometricContext
921
848
  #if THREE_VRM_THREE_REVISION >= 157
922
849
  irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
923
- #elif THREE_VRM_THREE_REVISION >= 133
924
- irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
925
850
  #else
926
- irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );
851
+ irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
927
852
  #endif
928
853
 
929
854
  }
@@ -999,11 +924,11 @@ void main() {
999
924
  gl_FragColor = vec4( col, diffuseColor.a );
1000
925
  postCorrection();
1001
926
  }
1002
- `,Ei={None:"none",Normal:"normal",LitShadeRate:"litShadeRate",UV:"uv"},Z={None:"none",WorldCoordinates:"worldCoordinates",ScreenCoordinates:"screenCoordinates"},So={3e3:"",3001:"srgb"};function wt(e){return parseInt(Mi.REVISION,10)>=152?e.colorSpace:So[e.encoding]}var Ri=class extends P.ShaderMaterial{constructor(e={}){var t;super({vertexShader:xo,fragmentShader:yo}),this.uvAnimationScrollXSpeedFactor=0,this.uvAnimationScrollYSpeedFactor=0,this.uvAnimationRotationSpeedFactor=0,this.fog=!0,this.normalMapType=P.TangentSpaceNormalMap,this._ignoreVertexColor=!0,this._v0CompatShade=!1,this._debugMode=Ei.None,this._outlineWidthMode=Z.None,this._isOutline=!1,e.transparentWithZWrite&&(e.depthWrite=!0),delete e.transparentWithZWrite,e.fog=!0,e.lights=!0,e.clipping=!0,parseInt(P.REVISION,10)<129&&(e.skinning=e.skinning||!1),parseInt(P.REVISION,10)<131&&(e.morphTargets=e.morphTargets||!1,e.morphNormals=e.morphNormals||!1),this.uniforms=P.UniformsUtils.merge([P.UniformsLib.common,P.UniformsLib.normalmap,P.UniformsLib.emissivemap,P.UniformsLib.fog,P.UniformsLib.lights,{litFactor:{value:new P.Color(1,1,1)},mapUvTransform:{value:new P.Matrix3},colorAlpha:{value:1},normalMapUvTransform:{value:new P.Matrix3},shadeColorFactor:{value:new P.Color(0,0,0)},shadeMultiplyTexture:{value:null},shadeMultiplyTextureUvTransform:{value:new P.Matrix3},shadingShiftFactor:{value:0},shadingShiftTexture:{value:null},shadingShiftTextureUvTransform:{value:new P.Matrix3},shadingShiftTextureScale:{value:1},shadingToonyFactor:{value:.9},giEqualizationFactor:{value:.9},matcapFactor:{value:new P.Color(1,1,1)},matcapTexture:{value:null},matcapTextureUvTransform:{value:new P.Matrix3},parametricRimColorFactor:{value:new P.Color(0,0,0)},rimMultiplyTexture:{value:null},rimMultiplyTextureUvTransform:{value:new P.Matrix3},rimLightingMixFactor:{value:1},parametricRimFresnelPowerFactor:{value:5},parametricRimLiftFactor:{value:0},emissive:{value:new P.Color(0,0,0)},emissiveIntensity:{value:1},emissiveMapUvTransform:{value:new P.Matrix3},outlineWidthMultiplyTexture:{value:null},outlineWidthMultiplyTextureUvTransform:{value:new P.Matrix3},outlineWidthFactor:{value:0},outlineColorFactor:{value:new P.Color(0,0,0)},outlineLightingMixFactor:{value:1},uvAnimationMaskTexture:{value:null},uvAnimationMaskTextureUvTransform:{value:new P.Matrix3},uvAnimationScrollXOffset:{value:0},uvAnimationScrollYOffset:{value:0},uvAnimationRotationPhase:{value:0}},(t=e.uniforms)!=null?t:{}]),this.setValues(e),this._uploadUniformsWorkaround(),this.customProgramCacheKey=()=>[...Object.entries(this._generateDefines()).map(([n,i])=>`${n}:${i}`),this.matcapTexture?`matcapTextureColorSpace:${wt(this.matcapTexture)}`:"",this.shadeMultiplyTexture?`shadeMultiplyTextureColorSpace:${wt(this.shadeMultiplyTexture)}`:"",this.rimMultiplyTexture?`rimMultiplyTextureColorSpace:${wt(this.rimMultiplyTexture)}`:""].join(","),this.onBeforeCompile=n=>{let i=parseInt(P.REVISION,10),r=Object.entries(pi(pi({},this._generateDefines()),this.defines)).filter(([o,l])=>!!l).map(([o,l])=>`#define ${o} ${l}`).join(`
927
+ `,ri={None:"none",Normal:"normal",LitShadeRate:"litShadeRate",UV:"uv"},ze={None:"none",WorldCoordinates:"worldCoordinates",ScreenCoordinates:"screenCoordinates"},io={3e3:"",3001:"srgb"};function Et(t){return parseInt(oi.REVISION,10)>=152?t.colorSpace:io[t.encoding]}var si=class extends P.ShaderMaterial{constructor(t={}){var e;super({vertexShader:to,fragmentShader:no}),this.uvAnimationScrollXSpeedFactor=0,this.uvAnimationScrollYSpeedFactor=0,this.uvAnimationRotationSpeedFactor=0,this.fog=!0,this.normalMapType=P.TangentSpaceNormalMap,this._ignoreVertexColor=!0,this._v0CompatShade=!1,this._debugMode=ri.None,this._outlineWidthMode=ze.None,this._isOutline=!1,t.transparentWithZWrite&&(t.depthWrite=!0),delete t.transparentWithZWrite,t.fog=!0,t.lights=!0,t.clipping=!0,this.uniforms=P.UniformsUtils.merge([P.UniformsLib.common,P.UniformsLib.normalmap,P.UniformsLib.emissivemap,P.UniformsLib.fog,P.UniformsLib.lights,{litFactor:{value:new P.Color(1,1,1)},mapUvTransform:{value:new P.Matrix3},colorAlpha:{value:1},normalMapUvTransform:{value:new P.Matrix3},shadeColorFactor:{value:new P.Color(0,0,0)},shadeMultiplyTexture:{value:null},shadeMultiplyTextureUvTransform:{value:new P.Matrix3},shadingShiftFactor:{value:0},shadingShiftTexture:{value:null},shadingShiftTextureUvTransform:{value:new P.Matrix3},shadingShiftTextureScale:{value:1},shadingToonyFactor:{value:.9},giEqualizationFactor:{value:.9},matcapFactor:{value:new P.Color(1,1,1)},matcapTexture:{value:null},matcapTextureUvTransform:{value:new P.Matrix3},parametricRimColorFactor:{value:new P.Color(0,0,0)},rimMultiplyTexture:{value:null},rimMultiplyTextureUvTransform:{value:new P.Matrix3},rimLightingMixFactor:{value:1},parametricRimFresnelPowerFactor:{value:5},parametricRimLiftFactor:{value:0},emissive:{value:new P.Color(0,0,0)},emissiveIntensity:{value:1},emissiveMapUvTransform:{value:new P.Matrix3},outlineWidthMultiplyTexture:{value:null},outlineWidthMultiplyTextureUvTransform:{value:new P.Matrix3},outlineWidthFactor:{value:0},outlineColorFactor:{value:new P.Color(0,0,0)},outlineLightingMixFactor:{value:1},uvAnimationMaskTexture:{value:null},uvAnimationMaskTextureUvTransform:{value:new P.Matrix3},uvAnimationScrollXOffset:{value:0},uvAnimationScrollYOffset:{value:0},uvAnimationRotationPhase:{value:0}},(e=t.uniforms)!=null?e:{}]),this.setValues(t),this._uploadUniformsWorkaround(),this.customProgramCacheKey=()=>[...Object.entries(this._generateDefines()).map(([n,i])=>`${n}:${i}`),this.matcapTexture?`matcapTextureColorSpace:${Et(this.matcapTexture)}`:"",this.shadeMultiplyTexture?`shadeMultiplyTextureColorSpace:${Et(this.shadeMultiplyTexture)}`:"",this.rimMultiplyTexture?`rimMultiplyTextureColorSpace:${Et(this.rimMultiplyTexture)}`:""].join(","),this.onBeforeCompile=n=>{let i=parseInt(P.REVISION,10),r=Object.entries(ti(ti({},this._generateDefines()),this.defines)).filter(([s,a])=>!!a).map(([s,a])=>`#define ${s} ${a}`).join(`
1003
928
  `)+`
1004
- `;n.vertexShader=r+n.vertexShader,n.fragmentShader=r+n.fragmentShader,i<154&&(n.fragmentShader=n.fragmentShader.replace("#include <colorspace_fragment>","#include <encodings_fragment>")),i<132&&(n.fragmentShader=n.fragmentShader.replace("#include <normal_pars_fragment>",""),n.fragmentShader=n.fragmentShader.replace("#include <alphatest_pars_fragment>",""))}}get color(){return this.uniforms.litFactor.value}set color(e){this.uniforms.litFactor.value=e}get map(){return this.uniforms.map.value}set map(e){this.uniforms.map.value=e}get normalMap(){return this.uniforms.normalMap.value}set normalMap(e){this.uniforms.normalMap.value=e}get normalScale(){return this.uniforms.normalScale.value}set normalScale(e){this.uniforms.normalScale.value=e}get emissive(){return this.uniforms.emissive.value}set emissive(e){this.uniforms.emissive.value=e}get emissiveIntensity(){return this.uniforms.emissiveIntensity.value}set emissiveIntensity(e){this.uniforms.emissiveIntensity.value=e}get emissiveMap(){return this.uniforms.emissiveMap.value}set emissiveMap(e){this.uniforms.emissiveMap.value=e}get shadeColorFactor(){return this.uniforms.shadeColorFactor.value}set shadeColorFactor(e){this.uniforms.shadeColorFactor.value=e}get shadeMultiplyTexture(){return this.uniforms.shadeMultiplyTexture.value}set shadeMultiplyTexture(e){this.uniforms.shadeMultiplyTexture.value=e}get shadingShiftFactor(){return this.uniforms.shadingShiftFactor.value}set shadingShiftFactor(e){this.uniforms.shadingShiftFactor.value=e}get shadingShiftTexture(){return this.uniforms.shadingShiftTexture.value}set shadingShiftTexture(e){this.uniforms.shadingShiftTexture.value=e}get shadingShiftTextureScale(){return this.uniforms.shadingShiftTextureScale.value}set shadingShiftTextureScale(e){this.uniforms.shadingShiftTextureScale.value=e}get shadingToonyFactor(){return this.uniforms.shadingToonyFactor.value}set shadingToonyFactor(e){this.uniforms.shadingToonyFactor.value=e}get giEqualizationFactor(){return this.uniforms.giEqualizationFactor.value}set giEqualizationFactor(e){this.uniforms.giEqualizationFactor.value=e}get matcapFactor(){return this.uniforms.matcapFactor.value}set matcapFactor(e){this.uniforms.matcapFactor.value=e}get matcapTexture(){return this.uniforms.matcapTexture.value}set matcapTexture(e){this.uniforms.matcapTexture.value=e}get parametricRimColorFactor(){return this.uniforms.parametricRimColorFactor.value}set parametricRimColorFactor(e){this.uniforms.parametricRimColorFactor.value=e}get rimMultiplyTexture(){return this.uniforms.rimMultiplyTexture.value}set rimMultiplyTexture(e){this.uniforms.rimMultiplyTexture.value=e}get rimLightingMixFactor(){return this.uniforms.rimLightingMixFactor.value}set rimLightingMixFactor(e){this.uniforms.rimLightingMixFactor.value=e}get parametricRimFresnelPowerFactor(){return this.uniforms.parametricRimFresnelPowerFactor.value}set parametricRimFresnelPowerFactor(e){this.uniforms.parametricRimFresnelPowerFactor.value=e}get parametricRimLiftFactor(){return this.uniforms.parametricRimLiftFactor.value}set parametricRimLiftFactor(e){this.uniforms.parametricRimLiftFactor.value=e}get outlineWidthMultiplyTexture(){return this.uniforms.outlineWidthMultiplyTexture.value}set outlineWidthMultiplyTexture(e){this.uniforms.outlineWidthMultiplyTexture.value=e}get outlineWidthFactor(){return this.uniforms.outlineWidthFactor.value}set outlineWidthFactor(e){this.uniforms.outlineWidthFactor.value=e}get outlineColorFactor(){return this.uniforms.outlineColorFactor.value}set outlineColorFactor(e){this.uniforms.outlineColorFactor.value=e}get outlineLightingMixFactor(){return this.uniforms.outlineLightingMixFactor.value}set outlineLightingMixFactor(e){this.uniforms.outlineLightingMixFactor.value=e}get uvAnimationMaskTexture(){return this.uniforms.uvAnimationMaskTexture.value}set uvAnimationMaskTexture(e){this.uniforms.uvAnimationMaskTexture.value=e}get uvAnimationScrollXOffset(){return this.uniforms.uvAnimationScrollXOffset.value}set uvAnimationScrollXOffset(e){this.uniforms.uvAnimationScrollXOffset.value=e}get uvAnimationScrollYOffset(){return this.uniforms.uvAnimationScrollYOffset.value}set uvAnimationScrollYOffset(e){this.uniforms.uvAnimationScrollYOffset.value=e}get uvAnimationRotationPhase(){return this.uniforms.uvAnimationRotationPhase.value}set uvAnimationRotationPhase(e){this.uniforms.uvAnimationRotationPhase.value=e}get ignoreVertexColor(){return this._ignoreVertexColor}set ignoreVertexColor(e){this._ignoreVertexColor=e,this.needsUpdate=!0}get v0CompatShade(){return this._v0CompatShade}set v0CompatShade(e){this._v0CompatShade=e,this.needsUpdate=!0}get debugMode(){return this._debugMode}set debugMode(e){this._debugMode=e,this.needsUpdate=!0}get outlineWidthMode(){return this._outlineWidthMode}set outlineWidthMode(e){this._outlineWidthMode=e,this.needsUpdate=!0}get isOutline(){return this._isOutline}set isOutline(e){this._isOutline=e,this.needsUpdate=!0}get isMToonMaterial(){return!0}update(e){this._uploadUniformsWorkaround(),this._updateUVAnimation(e)}copy(e){return super.copy(e),this.map=e.map,this.normalMap=e.normalMap,this.emissiveMap=e.emissiveMap,this.shadeMultiplyTexture=e.shadeMultiplyTexture,this.shadingShiftTexture=e.shadingShiftTexture,this.matcapTexture=e.matcapTexture,this.rimMultiplyTexture=e.rimMultiplyTexture,this.outlineWidthMultiplyTexture=e.outlineWidthMultiplyTexture,this.uvAnimationMaskTexture=e.uvAnimationMaskTexture,this.normalMapType=e.normalMapType,this.uvAnimationScrollXSpeedFactor=e.uvAnimationScrollXSpeedFactor,this.uvAnimationScrollYSpeedFactor=e.uvAnimationScrollYSpeedFactor,this.uvAnimationRotationSpeedFactor=e.uvAnimationRotationSpeedFactor,this.ignoreVertexColor=e.ignoreVertexColor,this.v0CompatShade=e.v0CompatShade,this.debugMode=e.debugMode,this.outlineWidthMode=e.outlineWidthMode,this.isOutline=e.isOutline,this.needsUpdate=!0,this}_updateUVAnimation(e){this.uniforms.uvAnimationScrollXOffset.value+=e*this.uvAnimationScrollXSpeedFactor,this.uniforms.uvAnimationScrollYOffset.value+=e*this.uvAnimationScrollYSpeedFactor,this.uniforms.uvAnimationRotationPhase.value+=e*this.uvAnimationRotationSpeedFactor,this.uniformsNeedUpdate=!0}_uploadUniformsWorkaround(){this.uniforms.opacity.value=this.opacity,this._updateTextureMatrix(this.uniforms.map,this.uniforms.mapUvTransform),this._updateTextureMatrix(this.uniforms.normalMap,this.uniforms.normalMapUvTransform),this._updateTextureMatrix(this.uniforms.emissiveMap,this.uniforms.emissiveMapUvTransform),this._updateTextureMatrix(this.uniforms.shadeMultiplyTexture,this.uniforms.shadeMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.shadingShiftTexture,this.uniforms.shadingShiftTextureUvTransform),this._updateTextureMatrix(this.uniforms.matcapTexture,this.uniforms.matcapTextureUvTransform),this._updateTextureMatrix(this.uniforms.rimMultiplyTexture,this.uniforms.rimMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.outlineWidthMultiplyTexture,this.uniforms.outlineWidthMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.uvAnimationMaskTexture,this.uniforms.uvAnimationMaskTextureUvTransform),parseInt(P.REVISION,10)>=132&&(this.uniforms.alphaTest.value=this.alphaTest),this.uniformsNeedUpdate=!0}_generateDefines(){let e=parseInt(P.REVISION,10),t=this.outlineWidthMultiplyTexture!==null,n=this.map!==null||this.normalMap!==null||this.emissiveMap!==null||this.shadeMultiplyTexture!==null||this.shadingShiftTexture!==null||this.rimMultiplyTexture!==null||this.uvAnimationMaskTexture!==null;return{THREE_VRM_THREE_REVISION:e,OUTLINE:this._isOutline,MTOON_USE_UV:t||n,MTOON_UVS_VERTEX_ONLY:t&&!n,V0_COMPAT_SHADE:this._v0CompatShade,USE_SHADEMULTIPLYTEXTURE:this.shadeMultiplyTexture!==null,USE_SHADINGSHIFTTEXTURE:this.shadingShiftTexture!==null,USE_MATCAPTEXTURE:this.matcapTexture!==null,USE_RIMMULTIPLYTEXTURE:this.rimMultiplyTexture!==null,USE_OUTLINEWIDTHMULTIPLYTEXTURE:this._isOutline&&this.outlineWidthMultiplyTexture!==null,USE_UVANIMATIONMASKTEXTURE:this.uvAnimationMaskTexture!==null,IGNORE_VERTEX_COLOR:this._ignoreVertexColor===!0,DEBUG_NORMAL:this._debugMode==="normal",DEBUG_LITSHADERATE:this._debugMode==="litShadeRate",DEBUG_UV:this._debugMode==="uv",OUTLINE_WIDTH_WORLD:this._isOutline&&this._outlineWidthMode===Z.WorldCoordinates,OUTLINE_WIDTH_SCREEN:this._isOutline&&this._outlineWidthMode===Z.ScreenCoordinates}}_updateTextureMatrix(e,t){e.value&&(e.value.matrixAutoUpdate&&e.value.updateMatrix(),t.value.copy(e.value.matrix))}},Po=new Set(["1.0","1.0-beta"]),Ti=class Ze{get name(){return Ze.EXTENSION_NAME}constructor(t,n={}){var i,r,o;this.parser=t,this.renderOrderOffset=(i=n.renderOrderOffset)!=null?i:0,this.v0CompatShade=(r=n.v0CompatShade)!=null?r:!1,this.debugMode=(o=n.debugMode)!=null?o:"none",this._mToonMaterialSet=new Set}beforeRoot(){return de(this,null,function*(){this._removeUnlitExtensionIfMToonExists()})}afterRoot(t){return de(this,null,function*(){t.userData.vrmMToonMaterials=Array.from(this._mToonMaterialSet)})}getMaterialType(t){return this._getMToonExtension(t)?Ri:null}extendMaterialParams(t,n){let i=this._getMToonExtension(t);return i?this._extendMaterialParams(i,n):null}loadMesh(t){return de(this,null,function*(){var n;let i=this.parser,o=(n=i.json.meshes)==null?void 0:n[t];if(o==null)throw new Error(`MToonMaterialLoaderPlugin: Attempt to use meshes[${t}] of glTF but the mesh doesn't exist`);let l=o.primitives,a=yield i.loadMesh(t);if(l.length===1){let s=a,u=l[0].material;u!=null&&this._setupPrimitive(s,u)}else{let s=a;for(let u=0;u<l.length;u++){let d=s.children[u],c=l[u].material;c!=null&&this._setupPrimitive(d,c)}}return a})}_removeUnlitExtensionIfMToonExists(){let i=this.parser.json.materials;i==null||i.map((r,o)=>{var l;this._getMToonExtension(o)&&((l=r.extensions)!=null&&l.KHR_materials_unlit)&&delete r.extensions.KHR_materials_unlit})}_getMToonExtension(t){var n,i;let l=(n=this.parser.json.materials)==null?void 0:n[t];if(l==null){console.warn(`MToonMaterialLoaderPlugin: Attempt to use materials[${t}] of glTF but the material doesn't exist`);return}let a=(i=l.extensions)==null?void 0:i[Ze.EXTENSION_NAME];if(a==null)return;let s=a.specVersion;if(!Po.has(s)){console.warn(`MToonMaterialLoaderPlugin: Unknown ${Ze.EXTENSION_NAME} specVersion "${s}"`);return}return a}_extendMaterialParams(t,n){return de(this,null,function*(){var i;delete n.metalness,delete n.roughness;let r=new To(this.parser,n);r.assignPrimitive("transparentWithZWrite",t.transparentWithZWrite),r.assignColor("shadeColorFactor",t.shadeColorFactor),r.assignTexture("shadeMultiplyTexture",t.shadeMultiplyTexture,!0),r.assignPrimitive("shadingShiftFactor",t.shadingShiftFactor),r.assignTexture("shadingShiftTexture",t.shadingShiftTexture,!0),r.assignPrimitive("shadingShiftTextureScale",(i=t.shadingShiftTexture)==null?void 0:i.scale),r.assignPrimitive("shadingToonyFactor",t.shadingToonyFactor),r.assignPrimitive("giEqualizationFactor",t.giEqualizationFactor),r.assignColor("matcapFactor",t.matcapFactor),r.assignTexture("matcapTexture",t.matcapTexture,!0),r.assignColor("parametricRimColorFactor",t.parametricRimColorFactor),r.assignTexture("rimMultiplyTexture",t.rimMultiplyTexture,!0),r.assignPrimitive("rimLightingMixFactor",t.rimLightingMixFactor),r.assignPrimitive("parametricRimFresnelPowerFactor",t.parametricRimFresnelPowerFactor),r.assignPrimitive("parametricRimLiftFactor",t.parametricRimLiftFactor),r.assignPrimitive("outlineWidthMode",t.outlineWidthMode),r.assignPrimitive("outlineWidthFactor",t.outlineWidthFactor),r.assignTexture("outlineWidthMultiplyTexture",t.outlineWidthMultiplyTexture,!1),r.assignColor("outlineColorFactor",t.outlineColorFactor),r.assignPrimitive("outlineLightingMixFactor",t.outlineLightingMixFactor),r.assignTexture("uvAnimationMaskTexture",t.uvAnimationMaskTexture,!1),r.assignPrimitive("uvAnimationScrollXSpeedFactor",t.uvAnimationScrollXSpeedFactor),r.assignPrimitive("uvAnimationScrollYSpeedFactor",t.uvAnimationScrollYSpeedFactor),r.assignPrimitive("uvAnimationRotationSpeedFactor",t.uvAnimationRotationSpeedFactor),r.assignPrimitive("v0CompatShade",this.v0CompatShade),r.assignPrimitive("debugMode",this.debugMode),yield r.pending})}_setupPrimitive(t,n){let i=this._getMToonExtension(n);if(i){let r=this._parseRenderOrder(i);t.renderOrder=r+this.renderOrderOffset,this._generateOutline(t),this._addToMaterialSet(t);return}}_generateOutline(t){let n=t.material;if(!(n instanceof Je.Material)||typeof n.outlineWidthMode!="string"||n.outlineWidthMode==="none"||typeof n.outlineWidthFactor!="number"||n.outlineWidthFactor<=0)return;t.material=[n];let i=n.clone();i.name+=" (Outline)",i.isOutline=!0,i.side=Je.BackSide,t.material.push(i);let r=t.geometry,o=r.index?r.index.count:r.attributes.position.count/3;r.addGroup(0,o,0),r.addGroup(0,o,1)}_addToMaterialSet(t){let n=t.material,i=new Set;Array.isArray(n)?n.forEach(r=>i.add(r)):i.add(n);for(let r of i)this._mToonMaterialSet.add(r)}_parseRenderOrder(t){var n;return(t.transparentWithZWrite?0:19)+((n=t.renderQueueOffsetNumber)!=null?n:0)}};Ti.EXTENSION_NAME="VRMC_materials_mtoon";var Ke=Ti,wo=L.materialReference("color","color"),Lo=L.materialReference("map","texture"),Ao=L.materialReference("normalMap","texture"),No=L.materialReference("normalScale","vec2"),Ho=L.materialReference("emissive","color"),Vo=L.materialReference("emissiveIntensity","float"),bo=L.materialReference("emissiveMap","texture"),Io=L.materialReference("shadeColorFactor","color"),Co=L.materialReference("shadingShiftFactor","float"),fi=L.materialReference("shadeMultiplyTexture","texture"),Uo=L.materialReference("shadeMultiplyTextureScale","float"),Oo=L.materialReference("shadingToonyFactor","float"),Fo=L.materialReference("rimLightingMixFactor","float"),Do=L.materialReference("rimMultiplyTexture","texture"),Bo=L.materialReference("matcapFactor","color"),Wo=L.materialReference("matcapTexture","texture"),ko=L.materialReference("parametricRimColorFactor","color"),zo=L.materialReference("parametricRimLiftFactor","float"),jo=L.materialReference("parametricRimFresnelPowerFactor","float"),Go=L.materialReference("outlineWidthMultiplyTexture","texture"),Qo=L.materialReference("outlineWidthFactor","float"),gi=L.materialReference("outlineColorFactor","color"),qo=L.materialReference("outlineLightingMixFactor","float"),Xo=L.materialReference("uvAnimationMaskTexture","texture"),Yo=L.materialReference("uvAnimationScrollXOffset","float"),$o=L.materialReference("uvAnimationScrollYOffset","float"),Zo=L.materialReference("uvAnimationRotationPhase","float"),xi=class extends F.TempNode{constructor(e){super("vec2"),this.hasMaskTexture=e}setup(){let e=1;this.hasMaskTexture&&(e=F.vec4(Xo).context({getUV:()=>F.uv()}).r);let t=F.uv(),n=Zo.mul(e),i=F.cos(n),r=F.sin(n);t=t.sub(F.vec2(.5,.5)),t=t.mul(F.mat2(i,r,r.negate(),i)),t=t.add(F.vec2(.5,.5));let o=F.vec2(Yo,$o).mul(e);return t=t.add(o),t.temp("AnimatedUV")}},yi=D.nodeImmutable(D.PropertyNode,"vec3").temp("ShadeColor"),Si=D.nodeImmutable(D.PropertyNode,"float").temp("ShadingShift"),Pi=D.nodeImmutable(D.PropertyNode,"float").temp("ShadingToony"),Lt=D.nodeImmutable(D.PropertyNode,"float").temp("RimLightingMix"),At=D.nodeImmutable(D.PropertyNode,"vec3").temp("RimMultiply"),Nt=D.nodeImmutable(D.PropertyNode,"vec3").temp("matcap"),Ht=D.nodeImmutable(D.PropertyNode,"vec3").temp("ParametricRim"),Jo=N.tslFn(({a:e,b:t,t:n})=>{let i=n.sub(e),r=t.sub(e);return i.div(r).clamp()}),Ko=N.tslFn(({dotNL:e})=>{let n=N.float(1).sub(Pi),i=e.add(Si);return i=Jo({a:n.negate(),b:n,t:i}),i=i.mul(1),i}),es=N.tslFn(({shading:e,lightColor:t})=>{let n=N.mix(yi,N.diffuseColor,e);return t.mul(N.BRDF_Lambert({diffuseColor:n}))}),wi=class extends N.LightingModel{constructor(){super()}direct({lightDirection:e,lightColor:t,reflectedLight:n}){let i=N.transformedNormalView.dot(e).clamp(-1,1),r=Ko({dotNL:i});n.directDiffuse.assign(n.directDiffuse.add(es({shading:r,lightColor:t}))),n.directSpecular.assign(n.directSpecular.add(Ht.add(Nt).mul(At).mul(N.mix(N.vec3(0),N.BRDF_Lambert({diffuseColor:t}),Lt))))}indirectDiffuse({irradiance:e,reflectedLight:t}){t.indirectDiffuse.assign(t.indirectDiffuse.add(e.mul(N.BRDF_Lambert({diffuseColor:N.diffuseColor}))))}indirectSpecular({reflectedLight:e}){e.indirectSpecular.assign(e.indirectSpecular.add(Ht.add(Nt).mul(At).mul(N.mix(N.vec3(1),N.vec3(0),Lt))))}},ts=ie.tslFn(({parametricRimLift:e,parametricRimFresnelPower:t,parametricRimColor:n})=>{let i=ie.modelViewPosition.normalize(),r=ie.transformedNormalView.dot(i.negate());return ie.float(1).sub(r).add(e).clamp().pow(t).mul(n)}),Li=class extends S.NodeMaterial{customProgramCacheKey(){let e=super.customProgramCacheKey();return e+=`isOutline:${this.isOutline},`,e}constructor(e={}){super(),parseInt(W.REVISION,10)<161&&console.warn("MToonNodeMaterial requires Three.js r161 or higher. This would not work correctly."),e.transparentWithZWrite&&(e.depthWrite=!0),delete e.transparentWithZWrite,this.emissiveNode=null,this.lights=!0,this.color=new W.Color(1,1,1),this.map=null,this.emissive=new W.Color(0,0,0),this.emissiveIntensity=1,this.emissiveMap=null,this.normalMap=null,this.normalScale=new W.Vector2(1,1),this.shadeColorFactor=new W.Color(0,0,0),this.shadeMultiplyTexture=null,this.shadingShiftFactor=0,this.shadingShiftTexture=null,this.shadingShiftTextureScale=1,this.shadingToonyFactor=.9,this.rimLightingMixFactor=1,this.rimMultiplyTexture=null,this.matcapFactor=new W.Color(1,1,1),this.matcapTexture=null,this.parametricRimColorFactor=new W.Color(0,0,0),this.parametricRimLiftFactor=0,this.parametricRimFresnelPowerFactor=5,this.outlineWidthMode=Z.None,this.outlineWidthMultiplyTexture=null,this.outlineWidthFactor=0,this.outlineColorFactor=new W.Color(0,0,0),this.outlineLightingMixFactor=1,this.uvAnimationScrollXSpeedFactor=0,this.uvAnimationScrollYSpeedFactor=0,this.uvAnimationRotationSpeedFactor=0,this.uvAnimationMaskTexture=null,this.shadeColorNode=null,this.shadingShiftNode=null,this.shadingToonyNode=null,this.rimLightingMixNode=null,this.rimMultiplyNode=null,this.matcapNode=null,this.parametricRimColorNode=null,this.parametricRimLiftNode=null,this.parametricRimFresnelPowerNode=null,this.uvAnimationScrollXOffset=0,this.uvAnimationScrollYOffset=0,this.uvAnimationRotationPhase=0,this.isOutline=!1,this._animatedUVNode=null,this.setValues(e)}setupLightingModel(){return new wi}setup(e){var t;this._animatedUVNode=new xi((t=this.uvAnimationMaskTexture&&this.uvAnimationMaskTexture.isTexture===!0)!=null?t:!1),super.setup(e)}setupDiffuseColor(e){let t=null;if(this.colorNode==null){if(t=wo,this.map&&this.map.isTexture===!0){let n=Lo.context({getUV:()=>this._animatedUVNode});t=t.mul(n)}this.colorNode=t}this.vertexColors===!0&&e.geometry.hasAttribute("color")&&(console.warn("MToonNodeMaterial: MToon ignores vertex colors. Consider using a model without vertex colors instead."),this.vertexColors=!1),super.setupDiffuseColor(e),this.colorNode===t&&(this.colorNode=null)}setupVariants({stack:e}){e.assign(yi,this._setupShadeColorNode()),e.assign(Si,this._setupShadingShiftNode()),e.assign(Pi,this._setupShadingToonyNode()),e.assign(Lt,this._setupRimLightingMixNode()),e.assign(At,this._setupRimMultiplyNode()),e.assign(Nt,this._setupMatcapNode()),e.assign(Ht,this._setupParametricRimNode())}setupNormal(e){let t=this.normalNode;if(this.normalNode==null){if(this.normalNode=S.materialNormal,this.normalMap&&this.normalMap.isTexture===!0){let n=Ao.context({getUV:()=>this._animatedUVNode});this.normalNode=n.normalMap(No)}this.isOutline&&(this.normalNode=this.normalNode.negate())}super.setupNormal(e),this.normalNode=t}setupLighting(e){let t=null;if(this.emissiveNode==null){if(t=Ho.mul(Vo),this.emissiveMap&&this.emissiveMap.isTexture===!0){let i=bo.context({getUV:()=>this._animatedUVNode});t=t.mul(i)}this.emissiveNode=t}let n=super.setupLighting(e);return this.emissiveNode===t&&(this.emissiveNode=null),n}setupOutput(e,t){return this.isOutline&&this.outlineWidthMode!==Z.None&&(t=S.vec4(S.mix(gi,t.xyz.mul(gi),qo),t.w)),this.transparent===!1&&this.blending===W.NormalBlending&&this.alphaToCoverage===!1&&t.a.assign(1),super.setupOutput(e,t)}setupPosition(e){var t,n;let i=this.positionNode;if(this.isOutline&&this.outlineWidthMode!==Z.None){(t=this.positionNode)!=null||(this.positionNode=S.positionLocal);let o=S.normalLocal.normalize(),l=Qo;if(this.outlineWidthMultiplyTexture&&this.outlineWidthMultiplyTexture.isTexture===!0){let u=Go.context({getUV:()=>this._animatedUVNode});l=l.mul(u)}let a=S.length(S.modelNormalMatrix.mul(o)),s=l.mul(a).mul(o);if(this.outlineWidthMode===Z.WorldCoordinates)this.positionNode=this.positionNode.add(s);else if(this.outlineWidthMode===Z.ScreenCoordinates){let u=S.cameraProjectionMatrix.element(1).element(1);this.positionNode=this.positionNode.add(s.div(u).mul(S.positionView.z.negate()))}(n=this.positionNode)!=null||(this.positionNode=S.positionLocal)}let r=super.setupPosition(e);return r.z.add(r.w.mul(1e-6)),this.positionNode=i,r}copy(e){var t,n,i,r,o,l,a,s,u,d,c,f,m,p,h,g,_,T,M;return this.color.copy(e.color),this.map=(t=e.map)!=null?t:null,this.emissive.copy(e.emissive),this.emissiveIntensity=e.emissiveIntensity,this.emissiveMap=(n=e.emissiveMap)!=null?n:null,this.normalMap=(i=e.normalMap)!=null?i:null,this.normalScale.copy(e.normalScale),this.shadeColorFactor.copy(e.shadeColorFactor),this.shadeMultiplyTexture=(r=e.shadeMultiplyTexture)!=null?r:null,this.shadingShiftFactor=e.shadingShiftFactor,this.shadingShiftTexture=(o=e.shadingShiftTexture)!=null?o:null,this.shadingShiftTextureScale=e.shadingShiftTextureScale,this.shadingToonyFactor=e.shadingToonyFactor,this.rimLightingMixFactor=e.rimLightingMixFactor,this.rimMultiplyTexture=(l=e.rimMultiplyTexture)!=null?l:null,this.matcapFactor.copy(e.matcapFactor),this.matcapTexture=(a=e.matcapTexture)!=null?a:null,this.parametricRimColorFactor.copy(e.parametricRimColorFactor),this.parametricRimLiftFactor=e.parametricRimLiftFactor,this.parametricRimFresnelPowerFactor=e.parametricRimFresnelPowerFactor,this.outlineWidthMode=e.outlineWidthMode,this.outlineWidthMultiplyTexture=(s=e.outlineWidthMultiplyTexture)!=null?s:null,this.outlineWidthFactor=e.outlineWidthFactor,this.outlineColorFactor.copy(e.outlineColorFactor),this.outlineLightingMixFactor=e.outlineLightingMixFactor,this.uvAnimationScrollXSpeedFactor=e.uvAnimationScrollXSpeedFactor,this.uvAnimationScrollYSpeedFactor=e.uvAnimationScrollYSpeedFactor,this.uvAnimationRotationSpeedFactor=e.uvAnimationRotationSpeedFactor,this.uvAnimationMaskTexture=(u=e.uvAnimationMaskTexture)!=null?u:null,this.shadeColorNode=(d=e.shadeColorNode)!=null?d:null,this.shadingShiftNode=(c=e.shadingShiftNode)!=null?c:null,this.shadingToonyNode=(f=e.shadingToonyNode)!=null?f:null,this.rimLightingMixNode=(m=e.rimLightingMixNode)!=null?m:null,this.rimMultiplyNode=(p=e.rimMultiplyNode)!=null?p:null,this.matcapNode=(h=e.matcapNode)!=null?h:null,this.parametricRimColorNode=(g=e.parametricRimColorNode)!=null?g:null,this.parametricRimLiftNode=(_=e.parametricRimLiftNode)!=null?_:null,this.parametricRimFresnelPowerNode=(T=e.parametricRimFresnelPowerNode)!=null?T:null,this.isOutline=(M=e.isOutline)!=null?M:null,super.copy(e)}update(e){this.uvAnimationScrollXOffset+=e*this.uvAnimationScrollXSpeedFactor,this.uvAnimationScrollYOffset+=e*this.uvAnimationScrollYSpeedFactor,this.uvAnimationRotationPhase+=e*this.uvAnimationRotationSpeedFactor}_setupShadeColorNode(){if(this.shadeColorNode!=null)return S.vec3(this.shadeColorNode);let e=Io;if(this.shadeMultiplyTexture&&this.shadeMultiplyTexture.isTexture===!0){let t=fi.context({getUV:()=>this._animatedUVNode});e=e.mul(t)}return e}_setupShadingShiftNode(){if(this.shadingShiftNode!=null)return S.float(this.shadingShiftNode);let e=Co;if(this.shadingShiftTexture&&this.shadingShiftTexture.isTexture===!0){let t=fi.context({getUV:()=>this._animatedUVNode});e=e.add(t.mul(Uo))}return e}_setupShadingToonyNode(){return this.shadingToonyNode!=null?S.float(this.shadingToonyNode):Oo}_setupRimLightingMixNode(){return this.rimLightingMixNode!=null?S.float(this.rimLightingMixNode):Fo}_setupRimMultiplyNode(){return this.rimMultiplyNode!=null?S.vec3(this.rimMultiplyNode):this.rimMultiplyTexture&&this.rimMultiplyTexture.isTexture===!0?Do.context({getUV:()=>this._animatedUVNode}):S.vec3(1)}_setupMatcapNode(){return this.matcapNode!=null?S.vec3(this.matcapNode):this.matcapTexture&&this.matcapTexture.isTexture===!0?Wo.context({getUV:()=>S.matcapUV.mul(1,-1).add(0,1)}).mul(Bo):S.vec3(0)}_setupParametricRimNode(){let e=this.parametricRimColorNode!=null?S.vec3(this.parametricRimColorNode):ko,t=this.parametricRimLiftNode!=null?S.float(this.parametricRimLiftNode):zo,n=this.parametricRimFresnelPowerNode!=null?S.float(this.parametricRimFresnelPowerNode):jo;return ts({parametricRimLift:t,parametricRimFresnelPower:n,parametricRimColor:e})}},ns=class extends Ke{constructor(e,t={}){super(e,t)}getMaterialType(e){return this._getMToonExtension(e)?Li:null}};var is=(e,t,n)=>new Promise((i,r)=>{var o=s=>{try{a(n.next(s))}catch(u){r(u)}},l=s=>{try{a(n.throw(s))}catch(u){r(u)}},a=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,l);a((n=n.apply(e,t)).next())}),Ai=class Vt{get name(){return Vt.EXTENSION_NAME}constructor(t){this.parser=t}extendMaterialParams(t,n){return is(this,null,function*(){let i=this._getHDREmissiveMultiplierExtension(t);if(i==null)return;console.warn("VRMMaterialsHDREmissiveMultiplierLoaderPlugin: `VRMC_materials_hdr_emissiveMultiplier` is archived. Use `KHR_materials_emissive_strength` instead.");let r=i.emissiveMultiplier;n.emissiveIntensity=r})}_getHDREmissiveMultiplierExtension(t){var n,i;let l=(n=this.parser.json.materials)==null?void 0:n[t];if(l==null){console.warn(`VRMMaterialsHDREmissiveMultiplierLoaderPlugin: Attempt to use materials[${t}] of glTF but the material doesn't exist`);return}let a=(i=l.extensions)==null?void 0:i[Vt.EXTENSION_NAME];if(a!=null)return a}};Ai.EXTENSION_NAME="VRMC_materials_hdr_emissiveMultiplier";var Ni=Ai;var Ii=v(require("three"),1);var rs=Object.defineProperty,os=Object.defineProperties,ss=Object.getOwnPropertyDescriptors,Hi=Object.getOwnPropertySymbols,as=Object.prototype.hasOwnProperty,ls=Object.prototype.propertyIsEnumerable,Vi=(e,t,n)=>t in e?rs(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,q=(e,t)=>{for(var n in t||(t={}))as.call(t,n)&&Vi(e,n,t[n]);if(Hi)for(var n of Hi(t))ls.call(t,n)&&Vi(e,n,t[n]);return e},bi=(e,t)=>os(e,ss(t)),us=(e,t,n)=>new Promise((i,r)=>{var o=s=>{try{a(n.next(s))}catch(u){r(u)}},l=s=>{try{a(n.throw(s))}catch(u){r(u)}},a=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,l);a((n=n.apply(e,t)).next())});function Me(e){return Math.pow(e,2.2)}var Ci=class{get name(){return"VRMMaterialsV0CompatPlugin"}constructor(e){var t;this.parser=e,this._renderQueueMapTransparent=new Map,this._renderQueueMapTransparentZWrite=new Map;let n=this.parser.json;n.extensionsUsed=(t=n.extensionsUsed)!=null?t:[],n.extensionsUsed.indexOf("KHR_texture_transform")===-1&&n.extensionsUsed.push("KHR_texture_transform")}beforeRoot(){return us(this,null,function*(){var e;let t=this.parser.json,n=(e=t.extensions)==null?void 0:e.VRM,i=n==null?void 0:n.materialProperties;i&&(this._populateRenderQueueMap(i),i.forEach((r,o)=>{var l,a;let s=(l=t.materials)==null?void 0:l[o];if(s==null){console.warn(`VRMMaterialsV0CompatPlugin: Attempt to use materials[${o}] of glTF but the material doesn't exist`);return}if(r.shader==="VRM/MToon"){let u=this._parseV0MToonProperties(r,s);t.materials[o]=u}else if((a=r.shader)!=null&&a.startsWith("VRM/Unlit")){let u=this._parseV0UnlitProperties(r,s);t.materials[o]=u}else r.shader==="VRM_USE_GLTFSHADER"||console.warn(`VRMMaterialsV0CompatPlugin: Unknown shader: ${r.shader}`)}))})}_parseV0MToonProperties(e,t){var n,i,r,o,l,a,s,u,d,c,f,m,p,h,g,_,T,M,E,y,R,x,V,O,b,C,G,xe,zt,jt,Gt,Qt,qt,Xt,Yt,$t,Zt,Jt,Kt,en,tn,nn,rn,on,sn,an,ln,un,dn,hn,cn,mn,pn,fn,gn;let _n=(i=(n=e.keywordMap)==null?void 0:n._ALPHABLEND_ON)!=null?i:!1,sr=((r=e.floatProperties)==null?void 0:r._ZWrite)===1&&_n,ar=this._v0ParseRenderQueue(e),vn=(l=(o=e.keywordMap)==null?void 0:o._ALPHATEST_ON)!=null?l:!1,lr=_n?"BLEND":vn?"MASK":"OPAQUE",ur=vn?(s=(a=e.floatProperties)==null?void 0:a._Cutoff)!=null?s:.5:void 0,dr=((d=(u=e.floatProperties)==null?void 0:u._CullMode)!=null?d:2)===0,ae=this._portTextureTransform(e),hr=((f=(c=e.vectorProperties)==null?void 0:c._Color)!=null?f:[1,1,1,1]).map((wn,Cr)=>Cr===3?wn:Me(wn)),En=(m=e.textureProperties)==null?void 0:m._MainTex,cr=En!=null?{index:En,extensions:q({},ae)}:void 0,mr=(h=(p=e.floatProperties)==null?void 0:p._BumpScale)!=null?h:1,Mn=(g=e.textureProperties)==null?void 0:g._BumpMap,pr=Mn!=null?{index:Mn,scale:mr,extensions:q({},ae)}:void 0,fr=((T=(_=e.vectorProperties)==null?void 0:_._EmissionColor)!=null?T:[0,0,0,1]).map(Me),Rn=(M=e.textureProperties)==null?void 0:M._EmissionMap,gr=Rn!=null?{index:Rn,extensions:q({},ae)}:void 0,_r=((y=(E=e.vectorProperties)==null?void 0:E._ShadeColor)!=null?y:[.97,.81,.86,1]).map(Me),Tn=(R=e.textureProperties)==null?void 0:R._ShadeTexture,vr=Tn!=null?{index:Tn,extensions:q({},ae)}:void 0,Ie=(V=(x=e.floatProperties)==null?void 0:x._ShadeShift)!=null?V:0,Ce=(b=(O=e.floatProperties)==null?void 0:O._ShadeToony)!=null?b:.9;Ce=Ii.MathUtils.lerp(Ce,1,.5+.5*Ie),Ie=-Ie-(1-Ce);let xn=(G=(C=e.floatProperties)==null?void 0:C._IndirectLightIntensity)!=null?G:.1,Er=xn?1-xn:void 0,at=(xe=e.textureProperties)==null?void 0:xe._SphereAdd,Mr=at!=null?[1,1,1]:void 0,Rr=at!=null?{index:at}:void 0,Tr=(jt=(zt=e.floatProperties)==null?void 0:zt._RimLightingMix)!=null?jt:0,yn=(Gt=e.textureProperties)==null?void 0:Gt._RimTexture,xr=yn!=null?{index:yn,extensions:q({},ae)}:void 0,yr=((qt=(Qt=e.vectorProperties)==null?void 0:Qt._RimColor)!=null?qt:[0,0,0,1]).map(Me),Sr=(Yt=(Xt=e.floatProperties)==null?void 0:Xt._RimFresnelPower)!=null?Yt:1,Pr=(Zt=($t=e.floatProperties)==null?void 0:$t._RimLift)!=null?Zt:0,wr=["none","worldCoordinates","screenCoordinates"][(Kt=(Jt=e.floatProperties)==null?void 0:Jt._OutlineWidthMode)!=null?Kt:0],lt=(tn=(en=e.floatProperties)==null?void 0:en._OutlineWidth)!=null?tn:0;lt=.01*lt;let Sn=(nn=e.textureProperties)==null?void 0:nn._OutlineWidthTexture,Lr=Sn!=null?{index:Sn,extensions:q({},ae)}:void 0,Ar=((on=(rn=e.vectorProperties)==null?void 0:rn._OutlineColor)!=null?on:[0,0,0]).map(Me),Nr=((an=(sn=e.floatProperties)==null?void 0:sn._OutlineColorMode)!=null?an:0)===1?(un=(ln=e.floatProperties)==null?void 0:ln._OutlineLightingMix)!=null?un:1:0,Pn=(dn=e.textureProperties)==null?void 0:dn._UvAnimMaskTexture,Hr=Pn!=null?{index:Pn,extensions:q({},ae)}:void 0,Vr=(cn=(hn=e.floatProperties)==null?void 0:hn._UvAnimScrollX)!=null?cn:0,Ue=(pn=(mn=e.floatProperties)==null?void 0:mn._UvAnimScrollY)!=null?pn:0;Ue!=null&&(Ue=-Ue);let br=(gn=(fn=e.floatProperties)==null?void 0:fn._UvAnimRotation)!=null?gn:0,Ir={specVersion:"1.0",transparentWithZWrite:sr,renderQueueOffsetNumber:ar,shadeColorFactor:_r,shadeMultiplyTexture:vr,shadingShiftFactor:Ie,shadingToonyFactor:Ce,giEqualizationFactor:Er,matcapFactor:Mr,matcapTexture:Rr,rimLightingMixFactor:Tr,rimMultiplyTexture:xr,parametricRimColorFactor:yr,parametricRimFresnelPowerFactor:Sr,parametricRimLiftFactor:Pr,outlineWidthMode:wr,outlineWidthFactor:lt,outlineWidthMultiplyTexture:Lr,outlineColorFactor:Ar,outlineLightingMixFactor:Nr,uvAnimationMaskTexture:Hr,uvAnimationScrollXSpeedFactor:Vr,uvAnimationScrollYSpeedFactor:Ue,uvAnimationRotationSpeedFactor:br};return bi(q({},t),{pbrMetallicRoughness:{baseColorFactor:hr,baseColorTexture:cr},normalTexture:pr,emissiveTexture:gr,emissiveFactor:fr,alphaMode:lr,alphaCutoff:ur,doubleSided:dr,extensions:{VRMC_materials_mtoon:Ir}})}_parseV0UnlitProperties(e,t){var n,i,r,o,l;let a=e.shader==="VRM/UnlitTransparentZWrite",s=e.shader==="VRM/UnlitTransparent"||a,u=this._v0ParseRenderQueue(e),d=e.shader==="VRM/UnlitCutout",c=s?"BLEND":d?"MASK":"OPAQUE",f=d?(i=(n=e.floatProperties)==null?void 0:n._Cutoff)!=null?i:.5:void 0,m=this._portTextureTransform(e),p=((o=(r=e.vectorProperties)==null?void 0:r._Color)!=null?o:[1,1,1,1]).map(Me),h=(l=e.textureProperties)==null?void 0:l._MainTex,g=h!=null?{index:h,extensions:q({},m)}:void 0,_={specVersion:"1.0",transparentWithZWrite:a,renderQueueOffsetNumber:u,shadeColorFactor:p,shadeMultiplyTexture:g};return bi(q({},t),{pbrMetallicRoughness:{baseColorFactor:p,baseColorTexture:g},alphaMode:c,alphaCutoff:f,extensions:{VRMC_materials_mtoon:_}})}_portTextureTransform(e){var t,n,i,r,o;let l=(t=e.vectorProperties)==null?void 0:t._MainTex;if(l==null)return{};let a=[(n=l==null?void 0:l[0])!=null?n:0,(i=l==null?void 0:l[1])!=null?i:0],s=[(r=l==null?void 0:l[2])!=null?r:1,(o=l==null?void 0:l[3])!=null?o:1];return a[1]=1-s[1]-a[1],{KHR_texture_transform:{offset:a,scale:s}}}_v0ParseRenderQueue(e){var t,n,i;let r=(n=(t=e.keywordMap)==null?void 0:t._ALPHABLEND_ON)!=null?n:!1,o=((i=e.floatProperties)==null?void 0:i._ZWrite)===1,l=0;if(r){let a=e.renderQueue;a!=null&&(o?l=this._renderQueueMapTransparentZWrite.get(a):l=this._renderQueueMapTransparent.get(a))}return l}_populateRenderQueueMap(e){let t=new Set,n=new Set;e.forEach(i=>{var r,o,l;let a=(o=(r=i.keywordMap)==null?void 0:r._ALPHABLEND_ON)!=null?o:!1,s=((l=i.floatProperties)==null?void 0:l._ZWrite)===1;if(a){let u=i.renderQueue;u!=null&&(s?n.add(u):t.add(u))}}),t.size>10&&console.warn(`VRMMaterialsV0CompatPlugin: This VRM uses ${t.size} render queues for Transparent materials while VRM 1.0 only supports up to 10 render queues. The model might not be rendered correctly.`),n.size>10&&console.warn(`VRMMaterialsV0CompatPlugin: This VRM uses ${n.size} render queues for TransparentZWrite materials while VRM 1.0 only supports up to 10 render queues. The model might not be rendered correctly.`),Array.from(t).sort().forEach((i,r)=>{let o=Math.min(Math.max(r-t.size+1,-9),0);this._renderQueueMapTransparent.set(i,o)}),Array.from(n).sort().forEach((i,r)=>{let o=Math.min(Math.max(r,0),9);this._renderQueueMapTransparentZWrite.set(i,o)})}};var B=v(require("three"),1),X=v(require("three"),1),bt=v(require("three"),1),Ae=v(require("three"),1),J=v(require("three"),1);var Ui=(e,t,n)=>new Promise((i,r)=>{var o=s=>{try{a(n.next(s))}catch(u){r(u)}},l=s=>{try{a(n.throw(s))}catch(u){r(u)}},a=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,l);a((n=n.apply(e,t)).next())}),re=new B.Vector3,et=class extends B.Group{constructor(e){super(),this._attrPosition=new B.BufferAttribute(new Float32Array([0,0,0,0,0,0]),3),this._attrPosition.setUsage(B.DynamicDrawUsage);let t=new B.BufferGeometry;t.setAttribute("position",this._attrPosition);let n=new B.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new B.Line(t,n),this.add(this._line),this.constraint=e}updateMatrixWorld(e){re.setFromMatrixPosition(this.constraint.destination.matrixWorld),this._attrPosition.setXYZ(0,re.x,re.y,re.z),this.constraint.source&&re.setFromMatrixPosition(this.constraint.source.matrixWorld),this._attrPosition.setXYZ(1,re.x,re.y,re.z),this._attrPosition.needsUpdate=!0,super.updateMatrixWorld(e)}};function Oi(e,t){return t.set(e.elements[12],e.elements[13],e.elements[14])}var ds=new bt.Vector3,hs=new bt.Vector3;function cs(e,t){return e.decompose(ds,t,hs),t}function tt(e){return e.invert?e.invert():e.inverse(),e}var nt=class{constructor(e,t){this.destination=e,this.source=t,this.weight=1}},ms=new X.Vector3,ps=new X.Vector3,fs=new X.Vector3,gs=new X.Quaternion,_s=new X.Quaternion,vs=new X.Quaternion,Fi=class extends nt{get aimAxis(){return this._aimAxis}set aimAxis(e){this._aimAxis=e,this._v3AimAxis.set(e==="PositiveX"?1:e==="NegativeX"?-1:0,e==="PositiveY"?1:e==="NegativeY"?-1:0,e==="PositiveZ"?1:e==="NegativeZ"?-1:0)}get dependencies(){let e=new Set([this.source]);return this.destination.parent&&e.add(this.destination.parent),e}constructor(e,t){super(e,t),this._aimAxis="PositiveX",this._v3AimAxis=new X.Vector3(1,0,0),this._dstRestQuat=new X.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion)}update(){this.destination.updateWorldMatrix(!0,!1),this.source.updateWorldMatrix(!0,!1);let e=gs.identity(),t=_s.identity();this.destination.parent&&(cs(this.destination.parent.matrixWorld,e),tt(t.copy(e)));let n=ms.copy(this._v3AimAxis).applyQuaternion(this._dstRestQuat).applyQuaternion(e),i=Oi(this.source.matrixWorld,ps).sub(Oi(this.destination.matrixWorld,fs)).normalize(),r=vs.setFromUnitVectors(n,i).premultiply(t).multiply(e).multiply(this._dstRestQuat);this.destination.quaternion.copy(this._dstRestQuat).slerp(r,this.weight)}};function Es(e,t){let n=[e],i=e.parent;for(;i!==null;)n.unshift(i),i=i.parent;n.forEach(r=>{t(r)})}var Di=class{constructor(){this._constraints=new Set,this._objectConstraintsMap=new Map}get constraints(){return this._constraints}addConstraint(e){this._constraints.add(e);let t=this._objectConstraintsMap.get(e.destination);t==null&&(t=new Set,this._objectConstraintsMap.set(e.destination,t)),t.add(e)}deleteConstraint(e){this._constraints.delete(e),this._objectConstraintsMap.get(e.destination).delete(e)}setInitState(){let e=new Set,t=new Set;for(let n of this._constraints)this._processConstraint(n,e,t,i=>i.setInitState())}update(){let e=new Set,t=new Set;for(let n of this._constraints)this._processConstraint(n,e,t,i=>i.update())}_processConstraint(e,t,n,i){if(n.has(e))return;if(t.has(e))throw new Error("VRMNodeConstraintManager: Circular dependency detected while updating constraints");t.add(e);let r=e.dependencies;for(let o of r)Es(o,l=>{let a=this._objectConstraintsMap.get(l);if(a)for(let s of a)this._processConstraint(s,t,n,i)});i(e),n.add(e)}},Ms=new Ae.Quaternion,Rs=new Ae.Quaternion,Bi=class extends nt{get dependencies(){return new Set([this.source])}constructor(e,t){super(e,t),this._dstRestQuat=new Ae.Quaternion,this._invSrcRestQuat=new Ae.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion),tt(this._invSrcRestQuat.copy(this.source.quaternion))}update(){let e=Ms.copy(this._invSrcRestQuat).multiply(this.source.quaternion),t=Rs.copy(this._dstRestQuat).multiply(e);this.destination.quaternion.copy(this._dstRestQuat).slerp(t,this.weight)}},Ts=new J.Vector3,xs=new J.Quaternion,ys=new J.Quaternion,Wi=class extends nt{get rollAxis(){return this._rollAxis}set rollAxis(e){this._rollAxis=e,this._v3RollAxis.set(e==="X"?1:0,e==="Y"?1:0,e==="Z"?1:0)}get dependencies(){return new Set([this.source])}constructor(e,t){super(e,t),this._rollAxis="X",this._v3RollAxis=new J.Vector3(1,0,0),this._dstRestQuat=new J.Quaternion,this._invDstRestQuat=new J.Quaternion,this._invSrcRestQuatMulDstRestQuat=new J.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion),tt(this._invDstRestQuat.copy(this._dstRestQuat)),tt(this._invSrcRestQuatMulDstRestQuat.copy(this.source.quaternion)).multiply(this._dstRestQuat)}update(){let e=xs.copy(this._invDstRestQuat).multiply(this.source.quaternion).multiply(this._invSrcRestQuatMulDstRestQuat),t=Ts.copy(this._v3RollAxis).applyQuaternion(e),i=ys.setFromUnitVectors(t,this._v3RollAxis).premultiply(this._dstRestQuat).multiply(e);this.destination.quaternion.copy(this._dstRestQuat).slerp(i,this.weight)}},Ss=new Set(["1.0","1.0-beta"]),ki=class Le{get name(){return Le.EXTENSION_NAME}constructor(t,n){this.parser=t,this.helperRoot=n==null?void 0:n.helperRoot}afterRoot(t){return Ui(this,null,function*(){t.userData.vrmNodeConstraintManager=yield this._import(t)})}_import(t){return Ui(this,null,function*(){var n;let i=this.parser.json;if(!(((n=i.extensionsUsed)==null?void 0:n.indexOf(Le.EXTENSION_NAME))!==-1))return null;let o=new Di,l=yield this.parser.getDependencies("node");return l.forEach((a,s)=>{var u;let d=i.nodes[s],c=(u=d==null?void 0:d.extensions)==null?void 0:u[Le.EXTENSION_NAME];if(c==null)return;let f=c.specVersion;if(!Ss.has(f)){console.warn(`VRMNodeConstraintLoaderPlugin: Unknown ${Le.EXTENSION_NAME} specVersion "${f}"`);return}let m=c.constraint;if(m.roll!=null){let p=this._importRollConstraint(a,l,m.roll);o.addConstraint(p)}else if(m.aim!=null){let p=this._importAimConstraint(a,l,m.aim);o.addConstraint(p)}else if(m.rotation!=null){let p=this._importRotationConstraint(a,l,m.rotation);o.addConstraint(p)}}),t.scene.updateMatrixWorld(),o.setInitState(),o})}_importRollConstraint(t,n,i){let{source:r,rollAxis:o,weight:l}=i,a=n[r],s=new Wi(t,a);if(o!=null&&(s.rollAxis=o),l!=null&&(s.weight=l),this.helperRoot){let u=new et(s);this.helperRoot.add(u)}return s}_importAimConstraint(t,n,i){let{source:r,aimAxis:o,weight:l}=i,a=n[r],s=new Fi(t,a);if(o!=null&&(s.aimAxis=o),l!=null&&(s.weight=l),this.helperRoot){let u=new et(s);this.helperRoot.add(u)}return s}_importRotationConstraint(t,n,i){let{source:r,weight:o}=i,l=n[r],a=new Bi(t,l);if(o!=null&&(a.weight=o),this.helperRoot){let s=new et(a);this.helperRoot.add(s)}return a}};ki.EXTENSION_NAME="VRMC_node_constraint";var It=ki;var oe=v(require("three"),1),be=v(require("three"),1),Gi=v(require("three"),1),ee=v(require("three"),1),me=v(require("three"),1),se=v(require("three"),1),pe=v(require("three"),1),qi=v(require("three"),1),U=v(require("three"),1),Xi=v(require("three"),1),$i=v(require("three"),1),ce=v(require("three"),1);var it=(e,t,n)=>new Promise((i,r)=>{var o=s=>{try{a(n.next(s))}catch(u){r(u)}},l=s=>{try{a(n.throw(s))}catch(u){r(u)}},a=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,l);a((n=n.apply(e,t)).next())}),Dt=class{},Ct=new be.Vector3,he=new be.Vector3,Bt=class extends Dt{get type(){return"capsule"}constructor(e){var t,n,i;super(),this.offset=(t=e==null?void 0:e.offset)!=null?t:new be.Vector3(0,0,0),this.tail=(n=e==null?void 0:e.tail)!=null?n:new be.Vector3(0,0,0),this.radius=(i=e==null?void 0:e.radius)!=null?i:0}calculateCollision(e,t,n,i){Ct.copy(this.offset).applyMatrix4(e),he.copy(this.tail).applyMatrix4(e),he.sub(Ct);let r=he.lengthSq();i.copy(t).sub(Ct);let o=he.dot(i);o<=0||(r<=o||he.multiplyScalar(o/r),i.sub(he));let l=n+this.radius,a=i.length()-l;return i.normalize(),a}},Wt=class extends Dt{get type(){return"sphere"}constructor(e){var t,n;super(),this.offset=(t=e==null?void 0:e.offset)!=null?t:new Gi.Vector3(0,0,0),this.radius=(n=e==null?void 0:e.radius)!=null?n:0}calculateCollision(e,t,n,i){i.copy(this.offset).applyMatrix4(e),i.negate().add(t);let r=n+this.radius,o=i.length()-r;return i.normalize(),o}},Y=new ee.Vector3,Ps=class extends ee.BufferGeometry{constructor(e){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new ee.Vector3,this._currentTail=new ee.Vector3,this._shape=e,this._attrPos=new ee.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new ee.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1,t=this._shape.radius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0);let n=Y.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(n)>1e-10&&(this._currentTail.copy(n),e=!0),e&&this._buildPosition()}_buildPosition(){Y.copy(this._currentTail).sub(this._currentOffset);let e=Y.length()/this._currentRadius;for(let i=0;i<=16;i++){let r=i/16*Math.PI;this._attrPos.setXYZ(i,-Math.sin(r),-Math.cos(r),0),this._attrPos.setXYZ(17+i,e+Math.sin(r),Math.cos(r),0),this._attrPos.setXYZ(34+i,-Math.sin(r),0,-Math.cos(r)),this._attrPos.setXYZ(51+i,e+Math.sin(r),0,Math.cos(r))}for(let i=0;i<32;i++){let r=i/16*Math.PI;this._attrPos.setXYZ(68+i,0,Math.sin(r),Math.cos(r)),this._attrPos.setXYZ(100+i,e,Math.sin(r),Math.cos(r))}let t=Math.atan2(Y.y,Math.sqrt(Y.x*Y.x+Y.z*Y.z)),n=-Math.atan2(Y.z,Y.x);this.rotateZ(t),this.rotateY(n),this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<34;e++){let t=(e+1)%34;this._attrIndex.setXY(e*2,e,t),this._attrIndex.setXY(68+e*2,34+e,34+t)}for(let e=0;e<32;e++){let t=(e+1)%32;this._attrIndex.setXY(136+e*2,68+e,68+t),this._attrIndex.setXY(200+e*2,100+e,100+t)}this._attrIndex.needsUpdate=!0}},ws=class extends me.BufferGeometry{constructor(e){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new me.Vector3,this._shape=e,this._attrPos=new me.BufferAttribute(new Float32Array(32*3*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new me.BufferAttribute(new Uint16Array(64*3),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1,t=this._shape.radius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),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._currentOffset.x,this._currentOffset.y,this._currentOffset.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.needsUpdate=!0}},Ls=new oe.Vector3,Ut=class extends oe.Group{constructor(e){if(super(),this.matrixAutoUpdate=!1,this.collider=e,this.collider.shape instanceof Wt)this._geometry=new ws(this.collider.shape);else if(this.collider.shape instanceof Bt)this._geometry=new Ps(this.collider.shape);else throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");let t=new oe.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new oe.LineSegments(this._geometry,t),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(e){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld);let t=this.matrix.elements;this._geometry.worldScale=Ls.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}},As=class extends pe.BufferGeometry{constructor(e){super(),this.worldScale=1,this._currentRadius=0,this._currentTail=new pe.Vector3,this._springBone=e,this._attrPos=new pe.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new pe.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1,t=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),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}},Ns=new se.Vector3,Qi=class extends se.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.springBone=e,this._geometry=new As(this.springBone);let t=new se.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new se.LineSegments(this._geometry,t),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(e){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld);let t=this.matrix.elements;this._geometry.worldScale=Ns.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}},Ot=class extends qi.Object3D{constructor(e){super(),this.shape=e}},Hs=new Xi.Matrix4;function Yi(e){return e.invert?e.invert():e.getInverse(Hs.copy(e)),e}var Vs=class{constructor(e){this._inverseCache=new $i.Matrix4,this._shouldUpdateInverse=!0,this.matrix=e;let t={set:(n,i,r)=>(this._shouldUpdateInverse=!0,n[i]=r,!0)};this._originalElements=e.elements,e.elements=new Proxy(e.elements,t)}get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),Yi(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}},bs=new U.Matrix4,K=new U.Vector3,Ne=new U.Vector3,Is=new U.Vector3,Re=new U.Vector3,zi=new U.Vector3,He=new U.Vector3,ji=new U.Quaternion,Te=new U.Matrix4,Cs=new U.Matrix4,Zi=class{constructor(e,t,n={},i=[]){this._currentTail=new U.Vector3,this._prevTail=new U.Vector3,this._boneAxis=new U.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new U.Matrix4,this._initialLocalRotation=new U.Quaternion,this._initialLocalChildPosition=new U.Vector3;var r,o,l,a,s,u;this.bone=e,this.bone.matrixAutoUpdate=!1,this.child=t,this.settings={hitRadius:(r=n.hitRadius)!=null?r:0,stiffness:(o=n.stiffness)!=null?o:1,gravityPower:(l=n.gravityPower)!=null?l:0,gravityDir:(s=(a=n.gravityDir)==null?void 0:a.clone())!=null?s:new U.Vector3(0,-1,0),dragForce:(u=n.dragForce)!=null?u:.4},this.colliderGroups=i}get center(){return this._center}set center(e){var t;(t=this._center)!=null&&t.userData.inverseCacheProxy&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=e,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new Vs(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:bs}setInitState(){this._initialLocalMatrix.copy(this.bone.matrix),this._initialLocalRotation.copy(this.bone.quaternion),this.child?this._initialLocalChildPosition.copy(this.child.position):this._initialLocalChildPosition.copy(this.bone.position).normalize().multiplyScalar(.07);let e=this._getMatrixWorldToCenter(Te);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);let e=this._getMatrixWorldToCenter(Te);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail)}update(e){if(e<=0)return;this._calcWorldSpaceBoneLength(),Re.setFromMatrixPosition(this.bone.matrixWorld);let t=this._getMatrixWorldToCenter(Te);zi.copy(Re).applyMatrix4(t);let n=ji.setFromRotationMatrix(t),i=Cs.copy(t).multiply(this._parentMatrixWorld),r=Ne.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(i).sub(zi).normalize(),o=Is.copy(this.settings.gravityDir).applyQuaternion(n).normalize(),l=this._getMatrixCenterToWorld(Te);He.copy(this._currentTail).add(K.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(K.copy(r).multiplyScalar(this.settings.stiffness*e)).add(K.copy(o).multiplyScalar(this.settings.gravityPower*e)).applyMatrix4(l),He.sub(Re).normalize().multiplyScalar(this._worldSpaceBoneLength).add(Re),this._collision(He),t=this._getMatrixWorldToCenter(Te),this._prevTail.copy(this._currentTail),this._currentTail.copy(K.copy(He).applyMatrix4(t));let a=Yi(Te.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),s=ji.setFromUnitVectors(this._boneAxis,K.copy(He).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(s),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(e){this.colliderGroups.forEach(t=>{t.colliders.forEach(n=>{let i=n.shape.calculateCollision(n.matrixWorld,e,this.settings.hitRadius,K);i<0&&(e.add(K.multiplyScalar(-i)),e.sub(Re).normalize().multiplyScalar(this._worldSpaceBoneLength).add(Re))})})}_calcWorldSpaceBoneLength(){K.setFromMatrixPosition(this.bone.matrixWorld),this.child?Ne.setFromMatrixPosition(this.child.matrixWorld):(Ne.copy(this._initialLocalChildPosition),Ne.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=K.sub(Ne).length()}_getMatrixCenterToWorld(e){return this._center?e.copy(this._center.matrixWorld):e.identity(),e}_getMatrixWorldToCenter(e){return this._center?e.copy(this._center.userData.inverseCacheProxy.inverse):e.identity(),e}};function Us(e,t){let n=[],i=e;for(;i!==null;)n.unshift(i),i=i.parent;n.forEach(r=>{t(r)})}function Ji(e,t){e.children.forEach(n=>{t(n)||Ji(n,t)})}var Ft=class{constructor(){this._joints=new Set,this._objectSpringBonesMap=new Map}get joints(){return this._joints}get springBones(){return console.warn("VRMSpringBoneManager: springBones is deprecated. use joints instead."),this._joints}get colliderGroups(){let e=new Set;return this._joints.forEach(t=>{t.colliderGroups.forEach(n=>{e.add(n)})}),Array.from(e)}get colliders(){let e=new Set;return this.colliderGroups.forEach(t=>{t.colliders.forEach(n=>{e.add(n)})}),Array.from(e)}addJoint(e){this._joints.add(e);let t=this._objectSpringBonesMap.get(e.bone);t==null&&(t=new Set,this._objectSpringBonesMap.set(e.bone,t)),t.add(e)}addSpringBone(e){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(e)}deleteJoint(e){this._joints.delete(e),this._objectSpringBonesMap.get(e.bone).delete(e)}deleteSpringBone(e){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(e)}setInitState(){let e=new Set,t=new Set,n=new Set;for(let i of this._joints)this._processSpringBone(i,e,t,n,r=>r.setInitState())}reset(){let e=new Set,t=new Set,n=new Set;for(let i of this._joints)this._processSpringBone(i,e,t,n,r=>r.reset())}update(e){let t=new Set,n=new Set,i=new Set;for(let r of this._joints)this._processSpringBone(r,t,n,i,o=>o.update(e)),Ji(r.bone,o=>{var l,a;return((a=(l=this._objectSpringBonesMap.get(o))==null?void 0:l.size)!=null?a:0)>0?!0:(o.updateWorldMatrix(!1,!1),!1)})}_processSpringBone(e,t,n,i,r){if(n.has(e))return;if(t.has(e))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");t.add(e);let o=this._getDependencies(e);for(let l of o)Us(l,a=>{let s=this._objectSpringBonesMap.get(a);if(s)for(let u of s)this._processSpringBone(u,t,n,i,r);else i.has(a)||(a.updateWorldMatrix(!1,!1),i.add(a))});e.bone.updateMatrix(),e.bone.updateWorldMatrix(!1,!1),r(e),i.add(e.bone),n.add(e)}_getDependencies(e){let t=new Set,n=e.bone.parent;return n&&t.add(n),e.colliderGroups.forEach(i=>{i.colliders.forEach(r=>{t.add(r)})}),t}},Os=new Set(["1.0","1.0-beta"]),Ki=class Ve{get name(){return Ve.EXTENSION_NAME}constructor(t,n){this.parser=t,this.jointHelperRoot=n==null?void 0:n.jointHelperRoot,this.colliderHelperRoot=n==null?void 0:n.colliderHelperRoot}afterRoot(t){return it(this,null,function*(){t.userData.vrmSpringBoneManager=yield this._import(t)})}_import(t){return it(this,null,function*(){let n=yield this._v1Import(t);if(n!=null)return n;let i=yield this._v0Import(t);return i!=null?i:null})}_v1Import(t){return it(this,null,function*(){var n,i,r,o,l;let a=t.parser.json;if(!(((n=a.extensionsUsed)==null?void 0:n.indexOf(Ve.EXTENSION_NAME))!==-1))return null;let u=new Ft,d=yield t.parser.getDependencies("node"),c=(i=a.extensions)==null?void 0:i[Ve.EXTENSION_NAME];if(!c)return null;let f=c.specVersion;if(!Os.has(f))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${Ve.EXTENSION_NAME} specVersion "${f}"`),null;let m=(r=c.colliders)==null?void 0:r.map((h,g)=>{var _,T,M,E,y;let R=d[h.node],x=h.shape;if(x.sphere)return this._importSphereCollider(R,{offset:new ce.Vector3().fromArray((_=x.sphere.offset)!=null?_:[0,0,0]),radius:(T=x.sphere.radius)!=null?T:0});if(x.capsule)return this._importCapsuleCollider(R,{offset:new ce.Vector3().fromArray((M=x.capsule.offset)!=null?M:[0,0,0]),radius:(E=x.capsule.radius)!=null?E:0,tail:new ce.Vector3().fromArray((y=x.capsule.tail)!=null?y:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${g} has no valid shape`)}),p=(o=c.colliderGroups)==null?void 0:o.map((h,g)=>{var _;return{colliders:((_=h.colliders)!=null?_:[]).map(M=>{let E=m==null?void 0:m[M];if(E==null)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${g} attempted to use a collider #${M} but not found`);return E}),name:h.name}});return(l=c.springs)==null||l.forEach((h,g)=>{var _;let T=h.joints,M=(_=h.colliderGroups)==null?void 0:_.map(R=>{let x=p==null?void 0:p[R];if(x==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${g} attempted to use a colliderGroup ${R} but not found`);return x}),E=h.center!=null?d[h.center]:void 0,y;T.forEach(R=>{if(y){let x=y.node,V=d[x],O=R.node,b=d[O],C={hitRadius:y.hitRadius,dragForce:y.dragForce,gravityPower:y.gravityPower,stiffness:y.stiffness,gravityDir:y.gravityDir!=null?new ce.Vector3().fromArray(y.gravityDir):void 0},G=this._importJoint(V,b,C,M);E&&(G.center=E),u.addJoint(G)}y=R})}),u.setInitState(),u})}_v0Import(t){return it(this,null,function*(){var n,i,r;let o=t.parser.json;if(!(((n=o.extensionsUsed)==null?void 0:n.indexOf("VRM"))!==-1))return null;let a=(i=o.extensions)==null?void 0:i.VRM,s=a==null?void 0:a.secondaryAnimation;if(!s)return null;let u=s==null?void 0:s.boneGroups;if(!u)return null;let d=new Ft,c=yield t.parser.getDependencies("node"),f=(r=s.colliderGroups)==null?void 0:r.map(m=>{var p;let h=c[m.node];return{colliders:((p=m.colliders)!=null?p:[]).map((_,T)=>{var M,E,y;let R=new ce.Vector3(0,0,0);return _.offset&&R.set((M=_.offset.x)!=null?M:0,(E=_.offset.y)!=null?E:0,_.offset.z?-_.offset.z:0),this._importSphereCollider(h,{offset:R,radius:(y=_.radius)!=null?y:0})})}});return u==null||u.forEach((m,p)=>{let h=m.bones;h&&h.forEach(g=>{var _,T,M,E;let y=c[g],R=new ce.Vector3;m.gravityDir?R.set((_=m.gravityDir.x)!=null?_:0,(T=m.gravityDir.y)!=null?T:0,(M=m.gravityDir.z)!=null?M:0):R.set(0,-1,0);let x=m.center!=null?c[m.center]:void 0,V={hitRadius:m.hitRadius,dragForce:m.dragForce,gravityPower:m.gravityPower,stiffness:m.stiffiness,gravityDir:R},O=(E=m.colliderGroups)==null?void 0:E.map(b=>{let C=f==null?void 0:f[b];if(C==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${p} attempted to use a colliderGroup ${b} but not found`);return C});y.traverse(b=>{var C;let G=(C=b.children[0])!=null?C:null,xe=this._importJoint(b,G,V,O);x&&(xe.center=x),d.addJoint(xe)})})}),t.scene.updateMatrixWorld(),d.setInitState(),d})}_importJoint(t,n,i,r){let o=new Zi(t,n,i,r);if(this.jointHelperRoot){let l=new Qi(o);this.jointHelperRoot.add(l),l.renderOrder=this.jointHelperRoot.renderOrder}return o}_importSphereCollider(t,n){let{offset:i,radius:r}=n,o=new Wt({offset:i,radius:r}),l=new Ot(o);if(t.add(l),this.colliderHelperRoot){let a=new Ut(l);this.colliderHelperRoot.add(a),a.renderOrder=this.colliderHelperRoot.renderOrder}return l}_importCapsuleCollider(t,n){let{offset:i,radius:r,tail:o}=n,l=new Bt({offset:i,radius:r,tail:o}),a=new Ot(l);if(t.add(a),this.colliderHelperRoot){let s=new Ut(a);this.colliderHelperRoot.add(s),s.renderOrder=this.colliderHelperRoot.renderOrder}return a}};Ki.EXTENSION_NAME="VRMC_springBone";var kt=Ki;var rt=class{get name(){return"VRMLoaderPlugin"}constructor(t,n){var o,l,a,s,u,d,c,f,m,p;this.parser=t;let i=n==null?void 0:n.helperRoot,r=n==null?void 0:n.autoUpdateHumanBones;this.expressionPlugin=(o=n==null?void 0:n.expressionPlugin)!=null?o:new je(t),this.firstPersonPlugin=(l=n==null?void 0:n.firstPersonPlugin)!=null?l:new Ge(t),this.humanoidPlugin=(a=n==null?void 0:n.humanoidPlugin)!=null?a:new qe(t,{helperRoot:i,autoUpdateHumanBones:r}),this.lookAtPlugin=(s=n==null?void 0:n.lookAtPlugin)!=null?s:new Xe(t,{helperRoot:i}),this.metaPlugin=(u=n==null?void 0:n.metaPlugin)!=null?u:new Ye(t),this.mtoonMaterialPlugin=(d=n==null?void 0:n.mtoonMaterialPlugin)!=null?d:new Ke(t),this.materialsHDREmissiveMultiplierPlugin=(c=n==null?void 0:n.materialsHDREmissiveMultiplierPlugin)!=null?c:new Ni(t),this.materialsV0CompatPlugin=(f=n==null?void 0:n.materialsV0CompatPlugin)!=null?f:new Ci(t),this.springBonePlugin=(m=n==null?void 0:n.springBonePlugin)!=null?m:new kt(t,{colliderHelperRoot:i,jointHelperRoot:i}),this.nodeConstraintPlugin=(p=n==null?void 0:n.nodeConstraintPlugin)!=null?p:new It(t,{helperRoot:i})}beforeRoot(){return ye(this,null,function*(){yield this.materialsV0CompatPlugin.beforeRoot(),yield this.mtoonMaterialPlugin.beforeRoot()})}loadMesh(t){return ye(this,null,function*(){return yield this.mtoonMaterialPlugin.loadMesh(t)})}getMaterialType(t){let n=this.mtoonMaterialPlugin.getMaterialType(t);return n!=null?n:null}extendMaterialParams(t,n){return ye(this,null,function*(){yield this.materialsHDREmissiveMultiplierPlugin.extendMaterialParams(t,n),yield this.mtoonMaterialPlugin.extendMaterialParams(t,n)})}afterRoot(t){return ye(this,null,function*(){yield this.metaPlugin.afterRoot(t),yield this.humanoidPlugin.afterRoot(t),yield this.expressionPlugin.afterRoot(t),yield this.lookAtPlugin.afterRoot(t),yield this.firstPersonPlugin.afterRoot(t),yield this.springBonePlugin.afterRoot(t),yield this.nodeConstraintPlugin.afterRoot(t),yield this.mtoonMaterialPlugin.afterRoot(t);let n=t.userData.vrmMeta,i=t.userData.vrmHumanoid;if(n&&i){let r=new Ee({scene:t.scene,expressionManager:t.userData.vrmExpressionManager,firstPerson:t.userData.vrmFirstPerson,humanoid:i,lookAt:t.userData.vrmLookAt,meta:n,materials:t.userData.vrmMToonMaterials,springBoneManager:t.userData.vrmSpringBoneManager,nodeConstraintManager:t.userData.vrmNodeConstraintManager});t.userData.vrm=r}})}};function er(e){if(Object.values(e).forEach(t=>{t!=null&&t.isTexture&&t.dispose()}),e.isShaderMaterial){let t=e.uniforms;t&&Object.values(t).forEach(n=>{let i=n.value;i!=null&&i.isTexture&&i.dispose()})}e.dispose()}function Fs(e){let t=e.geometry;t&&t.dispose();let n=e.skeleton;n&&n.dispose();let i=e.material;i&&(Array.isArray(i)?i.forEach(r=>er(r)):i&&er(i))}function tr(e){e.traverse(Fs)}var ot=v(require("three"),1);function nr(e,t){var l;let n=(l=t==null?void 0:t.experimentalSameBoneCounts)!=null?l:!1,i=[];e.traverse(a=>{a.type==="SkinnedMesh"&&i.push(a)});let r=new Map,o=0;for(let a of i){let u=a.geometry.getAttribute("skinIndex"),d=[],c=[],f={},m=u.array;for(let p=0;p<m.length;p++){let h=m[p];f[h]==null&&(f[h]=d.length,d.push(a.skeleton.bones[h]),c.push(a.skeleton.boneInverses[h])),m[p]=f[h]}u.copyArray(m),u.needsUpdate=!0,r.set(a,{bones:d,boneInverses:c}),o=Math.max(o,d.length)}for(let a of i){let{bones:s,boneInverses:u}=r.get(a);if(n)for(let c=s.length;c<o;c++)s[c]=s[0],u[c]=u[0];let d=new ot.Skeleton(s,u);a.bind(d,new ot.Matrix4)}}var ir=v(require("three"),1),st=require("three");function rr(e){let t=new Map;e.traverse(n=>{var c,f,m,p;if(!n.isMesh)return;let i=n,r=i.geometry,o=r.index;if(o==null)return;let l=t.get(r);if(l!=null){i.geometry=l;return}let a=new ir.BufferGeometry;a.name=r.name,a.morphTargetsRelative=r.morphTargetsRelative,r.groups.forEach(h=>{a.addGroup(h.start,h.count,h.materialIndex)}),a.boundingBox=(f=(c=r.boundingBox)==null?void 0:c.clone())!=null?f:null,a.boundingSphere=(p=(m=r.boundingSphere)==null?void 0:m.clone())!=null?p:null,a.setDrawRange(r.drawRange.start,r.drawRange.count),a.userData=r.userData,t.set(r,a);let s=[],u=[];{let h=o.array,g=new h.constructor(h.length),_=0;for(let T=0;T<h.length;T++){let M=h[T],E=s[M];E==null&&(s[M]=_,u[_]=M,E=_,_++),g[T]=E}a.setIndex(new st.BufferAttribute(g,1,!1))}Object.keys(r.attributes).forEach(h=>{let g=r.attributes[h];if(g.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");let _=g.array,{itemSize:T,normalized:M}=g,E=new _.constructor(u.length*T);u.forEach((y,R)=>{for(let x=0;x<T;x++)E[R*T+x]=_[y*T+x]}),a.setAttribute(h,new st.BufferAttribute(E,T,M))});let d=!0;Object.keys(r.morphAttributes).forEach(h=>{a.morphAttributes[h]=[];let g=r.morphAttributes[h];for(let _=0;_<g.length;_++){let T=g[_];if(T.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");let M=T.array,{itemSize:E,normalized:y}=T,R=new M.constructor(u.length*E);u.forEach((x,V)=>{for(let O=0;O<E;O++)R[V*E+O]=M[x*E+O]}),d=d&&R.every(x=>x===0),a.morphAttributes[h][_]=new st.BufferAttribute(R,E,y)}}),d&&(a.morphAttributes={}),i.geometry=a}),Array.from(t.keys()).forEach(n=>{n.dispose()})}function or(e){var t;((t=e.meta)==null?void 0:t.metaVersion)==="0"&&(e.scene.rotation.y=Math.PI)}var fe=class{constructor(){}};fe.deepDispose=tr,fe.removeUnnecessaryJoints=nr,fe.removeUnnecessaryVertices=rr,fe.rotateVRM0=or;
929
+ `;n.vertexShader=r+n.vertexShader,n.fragmentShader=r+n.fragmentShader,i<154&&(n.fragmentShader=n.fragmentShader.replace("#include <colorspace_fragment>","#include <encodings_fragment>"))}}get color(){return this.uniforms.litFactor.value}set color(t){this.uniforms.litFactor.value=t}get map(){return this.uniforms.map.value}set map(t){this.uniforms.map.value=t}get normalMap(){return this.uniforms.normalMap.value}set normalMap(t){this.uniforms.normalMap.value=t}get normalScale(){return this.uniforms.normalScale.value}set normalScale(t){this.uniforms.normalScale.value=t}get emissive(){return this.uniforms.emissive.value}set emissive(t){this.uniforms.emissive.value=t}get emissiveIntensity(){return this.uniforms.emissiveIntensity.value}set emissiveIntensity(t){this.uniforms.emissiveIntensity.value=t}get emissiveMap(){return this.uniforms.emissiveMap.value}set emissiveMap(t){this.uniforms.emissiveMap.value=t}get shadeColorFactor(){return this.uniforms.shadeColorFactor.value}set shadeColorFactor(t){this.uniforms.shadeColorFactor.value=t}get shadeMultiplyTexture(){return this.uniforms.shadeMultiplyTexture.value}set shadeMultiplyTexture(t){this.uniforms.shadeMultiplyTexture.value=t}get shadingShiftFactor(){return this.uniforms.shadingShiftFactor.value}set shadingShiftFactor(t){this.uniforms.shadingShiftFactor.value=t}get shadingShiftTexture(){return this.uniforms.shadingShiftTexture.value}set shadingShiftTexture(t){this.uniforms.shadingShiftTexture.value=t}get shadingShiftTextureScale(){return this.uniforms.shadingShiftTextureScale.value}set shadingShiftTextureScale(t){this.uniforms.shadingShiftTextureScale.value=t}get shadingToonyFactor(){return this.uniforms.shadingToonyFactor.value}set shadingToonyFactor(t){this.uniforms.shadingToonyFactor.value=t}get giEqualizationFactor(){return this.uniforms.giEqualizationFactor.value}set giEqualizationFactor(t){this.uniforms.giEqualizationFactor.value=t}get matcapFactor(){return this.uniforms.matcapFactor.value}set matcapFactor(t){this.uniforms.matcapFactor.value=t}get matcapTexture(){return this.uniforms.matcapTexture.value}set matcapTexture(t){this.uniforms.matcapTexture.value=t}get parametricRimColorFactor(){return this.uniforms.parametricRimColorFactor.value}set parametricRimColorFactor(t){this.uniforms.parametricRimColorFactor.value=t}get rimMultiplyTexture(){return this.uniforms.rimMultiplyTexture.value}set rimMultiplyTexture(t){this.uniforms.rimMultiplyTexture.value=t}get rimLightingMixFactor(){return this.uniforms.rimLightingMixFactor.value}set rimLightingMixFactor(t){this.uniforms.rimLightingMixFactor.value=t}get parametricRimFresnelPowerFactor(){return this.uniforms.parametricRimFresnelPowerFactor.value}set parametricRimFresnelPowerFactor(t){this.uniforms.parametricRimFresnelPowerFactor.value=t}get parametricRimLiftFactor(){return this.uniforms.parametricRimLiftFactor.value}set parametricRimLiftFactor(t){this.uniforms.parametricRimLiftFactor.value=t}get outlineWidthMultiplyTexture(){return this.uniforms.outlineWidthMultiplyTexture.value}set outlineWidthMultiplyTexture(t){this.uniforms.outlineWidthMultiplyTexture.value=t}get outlineWidthFactor(){return this.uniforms.outlineWidthFactor.value}set outlineWidthFactor(t){this.uniforms.outlineWidthFactor.value=t}get outlineColorFactor(){return this.uniforms.outlineColorFactor.value}set outlineColorFactor(t){this.uniforms.outlineColorFactor.value=t}get outlineLightingMixFactor(){return this.uniforms.outlineLightingMixFactor.value}set outlineLightingMixFactor(t){this.uniforms.outlineLightingMixFactor.value=t}get uvAnimationMaskTexture(){return this.uniforms.uvAnimationMaskTexture.value}set uvAnimationMaskTexture(t){this.uniforms.uvAnimationMaskTexture.value=t}get uvAnimationScrollXOffset(){return this.uniforms.uvAnimationScrollXOffset.value}set uvAnimationScrollXOffset(t){this.uniforms.uvAnimationScrollXOffset.value=t}get uvAnimationScrollYOffset(){return this.uniforms.uvAnimationScrollYOffset.value}set uvAnimationScrollYOffset(t){this.uniforms.uvAnimationScrollYOffset.value=t}get uvAnimationRotationPhase(){return this.uniforms.uvAnimationRotationPhase.value}set uvAnimationRotationPhase(t){this.uniforms.uvAnimationRotationPhase.value=t}get ignoreVertexColor(){return this._ignoreVertexColor}set ignoreVertexColor(t){this._ignoreVertexColor=t,this.needsUpdate=!0}get v0CompatShade(){return this._v0CompatShade}set v0CompatShade(t){this._v0CompatShade=t,this.needsUpdate=!0}get debugMode(){return this._debugMode}set debugMode(t){this._debugMode=t,this.needsUpdate=!0}get outlineWidthMode(){return this._outlineWidthMode}set outlineWidthMode(t){this._outlineWidthMode=t,this.needsUpdate=!0}get isOutline(){return this._isOutline}set isOutline(t){this._isOutline=t,this.needsUpdate=!0}get isMToonMaterial(){return!0}update(t){this._uploadUniformsWorkaround(),this._updateUVAnimation(t)}copy(t){return super.copy(t),this.map=t.map,this.normalMap=t.normalMap,this.emissiveMap=t.emissiveMap,this.shadeMultiplyTexture=t.shadeMultiplyTexture,this.shadingShiftTexture=t.shadingShiftTexture,this.matcapTexture=t.matcapTexture,this.rimMultiplyTexture=t.rimMultiplyTexture,this.outlineWidthMultiplyTexture=t.outlineWidthMultiplyTexture,this.uvAnimationMaskTexture=t.uvAnimationMaskTexture,this.normalMapType=t.normalMapType,this.uvAnimationScrollXSpeedFactor=t.uvAnimationScrollXSpeedFactor,this.uvAnimationScrollYSpeedFactor=t.uvAnimationScrollYSpeedFactor,this.uvAnimationRotationSpeedFactor=t.uvAnimationRotationSpeedFactor,this.ignoreVertexColor=t.ignoreVertexColor,this.v0CompatShade=t.v0CompatShade,this.debugMode=t.debugMode,this.outlineWidthMode=t.outlineWidthMode,this.isOutline=t.isOutline,this.needsUpdate=!0,this}_updateUVAnimation(t){this.uniforms.uvAnimationScrollXOffset.value+=t*this.uvAnimationScrollXSpeedFactor,this.uniforms.uvAnimationScrollYOffset.value+=t*this.uvAnimationScrollYSpeedFactor,this.uniforms.uvAnimationRotationPhase.value+=t*this.uvAnimationRotationSpeedFactor,this.uniforms.alphaTest.value=this.alphaTest,this.uniformsNeedUpdate=!0}_uploadUniformsWorkaround(){this.uniforms.opacity.value=this.opacity,this._updateTextureMatrix(this.uniforms.map,this.uniforms.mapUvTransform),this._updateTextureMatrix(this.uniforms.normalMap,this.uniforms.normalMapUvTransform),this._updateTextureMatrix(this.uniforms.emissiveMap,this.uniforms.emissiveMapUvTransform),this._updateTextureMatrix(this.uniforms.shadeMultiplyTexture,this.uniforms.shadeMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.shadingShiftTexture,this.uniforms.shadingShiftTextureUvTransform),this._updateTextureMatrix(this.uniforms.matcapTexture,this.uniforms.matcapTextureUvTransform),this._updateTextureMatrix(this.uniforms.rimMultiplyTexture,this.uniforms.rimMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.outlineWidthMultiplyTexture,this.uniforms.outlineWidthMultiplyTextureUvTransform),this._updateTextureMatrix(this.uniforms.uvAnimationMaskTexture,this.uniforms.uvAnimationMaskTextureUvTransform),this.uniformsNeedUpdate=!0}_generateDefines(){let t=parseInt(P.REVISION,10),e=this.outlineWidthMultiplyTexture!==null,n=this.map!==null||this.normalMap!==null||this.emissiveMap!==null||this.shadeMultiplyTexture!==null||this.shadingShiftTexture!==null||this.rimMultiplyTexture!==null||this.uvAnimationMaskTexture!==null;return{THREE_VRM_THREE_REVISION:t,OUTLINE:this._isOutline,MTOON_USE_UV:e||n,MTOON_UVS_VERTEX_ONLY:e&&!n,V0_COMPAT_SHADE:this._v0CompatShade,USE_SHADEMULTIPLYTEXTURE:this.shadeMultiplyTexture!==null,USE_SHADINGSHIFTTEXTURE:this.shadingShiftTexture!==null,USE_MATCAPTEXTURE:this.matcapTexture!==null,USE_RIMMULTIPLYTEXTURE:this.rimMultiplyTexture!==null,USE_OUTLINEWIDTHMULTIPLYTEXTURE:this._isOutline&&this.outlineWidthMultiplyTexture!==null,USE_UVANIMATIONMASKTEXTURE:this.uvAnimationMaskTexture!==null,IGNORE_VERTEX_COLOR:this._ignoreVertexColor===!0,DEBUG_NORMAL:this._debugMode==="normal",DEBUG_LITSHADERATE:this._debugMode==="litShadeRate",DEBUG_UV:this._debugMode==="uv",OUTLINE_WIDTH_WORLD:this._isOutline&&this._outlineWidthMode===ze.WorldCoordinates,OUTLINE_WIDTH_SCREEN:this._isOutline&&this._outlineWidthMode===ze.ScreenCoordinates}}_updateTextureMatrix(t,e){t.value&&(t.value.matrixAutoUpdate&&t.value.updateMatrix(),e.value.copy(t.value.matrix))}},ro=new Set(["1.0","1.0-beta"]),ai=class je{get name(){return je.EXTENSION_NAME}constructor(e,n={}){var i,r,s,a;this.parser=e,this.materialType=(i=n.materialType)!=null?i:si,this.renderOrderOffset=(r=n.renderOrderOffset)!=null?r:0,this.v0CompatShade=(s=n.v0CompatShade)!=null?s:!1,this.debugMode=(a=n.debugMode)!=null?a:"none",this._mToonMaterialSet=new Set}beforeRoot(){return ne(this,null,function*(){this._removeUnlitExtensionIfMToonExists()})}afterRoot(e){return ne(this,null,function*(){e.userData.vrmMToonMaterials=Array.from(this._mToonMaterialSet)})}getMaterialType(e){return this._getMToonExtension(e)?this.materialType:null}extendMaterialParams(e,n){let i=this._getMToonExtension(e);return i?this._extendMaterialParams(i,n):null}loadMesh(e){return ne(this,null,function*(){var n;let i=this.parser,s=(n=i.json.meshes)==null?void 0:n[e];if(s==null)throw new Error(`MToonMaterialLoaderPlugin: Attempt to use meshes[${e}] of glTF but the mesh doesn't exist`);let a=s.primitives,l=yield i.loadMesh(e);if(a.length===1){let o=l,u=a[0].material;u!=null&&this._setupPrimitive(o,u)}else{let o=l;for(let u=0;u<a.length;u++){let d=o.children[u],c=a[u].material;c!=null&&this._setupPrimitive(d,c)}}return l})}_removeUnlitExtensionIfMToonExists(){let i=this.parser.json.materials;i==null||i.map((r,s)=>{var a;this._getMToonExtension(s)&&((a=r.extensions)!=null&&a.KHR_materials_unlit)&&delete r.extensions.KHR_materials_unlit})}_getMToonExtension(e){var n,i;let a=(n=this.parser.json.materials)==null?void 0:n[e];if(a==null){console.warn(`MToonMaterialLoaderPlugin: Attempt to use materials[${e}] of glTF but the material doesn't exist`);return}let l=(i=a.extensions)==null?void 0:i[je.EXTENSION_NAME];if(l==null)return;let o=l.specVersion;if(!ro.has(o)){console.warn(`MToonMaterialLoaderPlugin: Unknown ${je.EXTENSION_NAME} specVersion "${o}"`);return}return l}_extendMaterialParams(e,n){return ne(this,null,function*(){var i;delete n.metalness,delete n.roughness;let r=new eo(this.parser,n);r.assignPrimitive("transparentWithZWrite",e.transparentWithZWrite),r.assignColor("shadeColorFactor",e.shadeColorFactor),r.assignTexture("shadeMultiplyTexture",e.shadeMultiplyTexture,!0),r.assignPrimitive("shadingShiftFactor",e.shadingShiftFactor),r.assignTexture("shadingShiftTexture",e.shadingShiftTexture,!0),r.assignPrimitive("shadingShiftTextureScale",(i=e.shadingShiftTexture)==null?void 0:i.scale),r.assignPrimitive("shadingToonyFactor",e.shadingToonyFactor),r.assignPrimitive("giEqualizationFactor",e.giEqualizationFactor),r.assignColor("matcapFactor",e.matcapFactor),r.assignTexture("matcapTexture",e.matcapTexture,!0),r.assignColor("parametricRimColorFactor",e.parametricRimColorFactor),r.assignTexture("rimMultiplyTexture",e.rimMultiplyTexture,!0),r.assignPrimitive("rimLightingMixFactor",e.rimLightingMixFactor),r.assignPrimitive("parametricRimFresnelPowerFactor",e.parametricRimFresnelPowerFactor),r.assignPrimitive("parametricRimLiftFactor",e.parametricRimLiftFactor),r.assignPrimitive("outlineWidthMode",e.outlineWidthMode),r.assignPrimitive("outlineWidthFactor",e.outlineWidthFactor),r.assignTexture("outlineWidthMultiplyTexture",e.outlineWidthMultiplyTexture,!1),r.assignColor("outlineColorFactor",e.outlineColorFactor),r.assignPrimitive("outlineLightingMixFactor",e.outlineLightingMixFactor),r.assignTexture("uvAnimationMaskTexture",e.uvAnimationMaskTexture,!1),r.assignPrimitive("uvAnimationScrollXSpeedFactor",e.uvAnimationScrollXSpeedFactor),r.assignPrimitive("uvAnimationScrollYSpeedFactor",e.uvAnimationScrollYSpeedFactor),r.assignPrimitive("uvAnimationRotationSpeedFactor",e.uvAnimationRotationSpeedFactor),r.assignPrimitive("v0CompatShade",this.v0CompatShade),r.assignPrimitive("debugMode",this.debugMode),yield r.pending})}_setupPrimitive(e,n){let i=this._getMToonExtension(n);if(i){let r=this._parseRenderOrder(i);e.renderOrder=r+this.renderOrderOffset,this._generateOutline(e),this._addToMaterialSet(e);return}}_shouldGenerateOutline(e){return typeof e.outlineWidthMode=="string"&&e.outlineWidthMode!=="none"&&typeof e.outlineWidthFactor=="number"&&e.outlineWidthFactor>0}_generateOutline(e){let n=e.material;if(!(n instanceof Ge.Material)||!this._shouldGenerateOutline(n))return;e.material=[n];let i=n.clone();i.name+=" (Outline)",i.isOutline=!0,i.side=Ge.BackSide,e.material.push(i);let r=e.geometry,s=r.index?r.index.count:r.attributes.position.count/3;r.addGroup(0,s,0),r.addGroup(0,s,1)}_addToMaterialSet(e){let n=e.material,i=new Set;Array.isArray(n)?n.forEach(r=>i.add(r)):i.add(n);for(let r of i)this._mToonMaterialSet.add(r)}_parseRenderOrder(e){var n;return(e.transparentWithZWrite?0:19)+((n=e.renderQueueOffsetNumber)!=null?n:0)}};ai.EXTENSION_NAME="VRMC_materials_mtoon";var Mt=ai;var oo=(t,e,n)=>new Promise((i,r)=>{var s=o=>{try{l(n.next(o))}catch(u){r(u)}},a=o=>{try{l(n.throw(o))}catch(u){r(u)}},l=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);l((n=n.apply(t,e)).next())}),li=class Rt{get name(){return Rt.EXTENSION_NAME}constructor(e){this.parser=e}extendMaterialParams(e,n){return oo(this,null,function*(){let i=this._getHDREmissiveMultiplierExtension(e);if(i==null)return;console.warn("VRMMaterialsHDREmissiveMultiplierLoaderPlugin: `VRMC_materials_hdr_emissiveMultiplier` is archived. Use `KHR_materials_emissive_strength` instead.");let r=i.emissiveMultiplier;n.emissiveIntensity=r})}_getHDREmissiveMultiplierExtension(e){var n,i;let a=(n=this.parser.json.materials)==null?void 0:n[e];if(a==null){console.warn(`VRMMaterialsHDREmissiveMultiplierLoaderPlugin: Attempt to use materials[${e}] of glTF but the material doesn't exist`);return}let l=(i=a.extensions)==null?void 0:i[Rt.EXTENSION_NAME];if(l!=null)return l}};li.EXTENSION_NAME="VRMC_materials_hdr_emissiveMultiplier";var ui=li;var pi=M(require("three"),1);var so=Object.defineProperty,ao=Object.defineProperties,lo=Object.getOwnPropertyDescriptors,di=Object.getOwnPropertySymbols,uo=Object.prototype.hasOwnProperty,ho=Object.prototype.propertyIsEnumerable,hi=(t,e,n)=>e in t?so(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,W=(t,e)=>{for(var n in e||(e={}))uo.call(e,n)&&hi(t,n,e[n]);if(di)for(var n of di(e))ho.call(e,n)&&hi(t,n,e[n]);return t},ci=(t,e)=>ao(t,lo(e)),co=(t,e,n)=>new Promise((i,r)=>{var s=o=>{try{l(n.next(o))}catch(u){r(u)}},a=o=>{try{l(n.throw(o))}catch(u){r(u)}},l=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);l((n=n.apply(t,e)).next())});function ce(t){return Math.pow(t,2.2)}var mi=class{get name(){return"VRMMaterialsV0CompatPlugin"}constructor(t){var e;this.parser=t,this._renderQueueMapTransparent=new Map,this._renderQueueMapTransparentZWrite=new Map;let n=this.parser.json;n.extensionsUsed=(e=n.extensionsUsed)!=null?e:[],n.extensionsUsed.indexOf("KHR_texture_transform")===-1&&n.extensionsUsed.push("KHR_texture_transform")}beforeRoot(){return co(this,null,function*(){var t;let e=this.parser.json,n=(t=e.extensions)==null?void 0:t.VRM,i=n==null?void 0:n.materialProperties;i&&(this._populateRenderQueueMap(i),i.forEach((r,s)=>{var a,l;let o=(a=e.materials)==null?void 0:a[s];if(o==null){console.warn(`VRMMaterialsV0CompatPlugin: Attempt to use materials[${s}] of glTF but the material doesn't exist`);return}if(r.shader==="VRM/MToon"){let u=this._parseV0MToonProperties(r,o);e.materials[s]=u}else if((l=r.shader)!=null&&l.startsWith("VRM/Unlit")){let u=this._parseV0UnlitProperties(r,o);e.materials[s]=u}else r.shader==="VRM_USE_GLTFSHADER"||console.warn(`VRMMaterialsV0CompatPlugin: Unknown shader: ${r.shader}`)}))})}_parseV0MToonProperties(t,e){var n,i,r,s,a,l,o,u,d,c,f,p,m,h,_,g,y,x,v,T,E,R,L,U,H,b,C,fe,Vt,It,Ut,Ct,Ot,Nt,Dt,Bt,Ft,Wt,kt,zt,jt,Gt,Qt,qt,Xt,Yt,$t,Zt,Jt,Kt,en,tn,nn,rn,on;let sn=(i=(n=t.keywordMap)==null?void 0:n._ALPHABLEND_ON)!=null?i:!1,Bi=((r=t.floatProperties)==null?void 0:r._ZWrite)===1&&sn,Fi=this._v0ParseRenderQueue(t),an=(a=(s=t.keywordMap)==null?void 0:s._ALPHATEST_ON)!=null?a:!1,Wi=sn?"BLEND":an?"MASK":"OPAQUE",ki=an?(o=(l=t.floatProperties)==null?void 0:l._Cutoff)!=null?o:.5:void 0,zi=((d=(u=t.floatProperties)==null?void 0:u._CullMode)!=null?d:2)===0,K=this._portTextureTransform(t),ji=((f=(c=t.vectorProperties)==null?void 0:c._Color)!=null?f:[1,1,1,1]).map((_n,mr)=>mr===3?_n:ce(_n)),ln=(p=t.textureProperties)==null?void 0:p._MainTex,Gi=ln!=null?{index:ln,extensions:W({},K)}:void 0,Qi=(h=(m=t.floatProperties)==null?void 0:m._BumpScale)!=null?h:1,un=(_=t.textureProperties)==null?void 0:_._BumpMap,qi=un!=null?{index:un,scale:Qi,extensions:W({},K)}:void 0,Xi=((y=(g=t.vectorProperties)==null?void 0:g._EmissionColor)!=null?y:[0,0,0,1]).map(ce),dn=(x=t.textureProperties)==null?void 0:x._EmissionMap,Yi=dn!=null?{index:dn,extensions:W({},K)}:void 0,$i=((T=(v=t.vectorProperties)==null?void 0:v._ShadeColor)!=null?T:[.97,.81,.86,1]).map(ce),hn=(E=t.textureProperties)==null?void 0:E._ShadeTexture,Zi=hn!=null?{index:hn,extensions:W({},K)}:void 0,Pe=(L=(R=t.floatProperties)==null?void 0:R._ShadeShift)!=null?L:0,Se=(H=(U=t.floatProperties)==null?void 0:U._ShadeToony)!=null?H:.9;Se=pi.MathUtils.lerp(Se,1,.5+.5*Pe),Pe=-Pe-(1-Se);let cn=(C=(b=t.floatProperties)==null?void 0:b._IndirectLightIntensity)!=null?C:.1,Ji=cn?1-cn:void 0,Ke=(fe=t.textureProperties)==null?void 0:fe._SphereAdd,Ki=Ke!=null?[1,1,1]:void 0,er=Ke!=null?{index:Ke}:void 0,tr=(It=(Vt=t.floatProperties)==null?void 0:Vt._RimLightingMix)!=null?It:0,pn=(Ut=t.textureProperties)==null?void 0:Ut._RimTexture,nr=pn!=null?{index:pn,extensions:W({},K)}:void 0,ir=((Ot=(Ct=t.vectorProperties)==null?void 0:Ct._RimColor)!=null?Ot:[0,0,0,1]).map(ce),rr=(Dt=(Nt=t.floatProperties)==null?void 0:Nt._RimFresnelPower)!=null?Dt:1,or=(Ft=(Bt=t.floatProperties)==null?void 0:Bt._RimLift)!=null?Ft:0,sr=["none","worldCoordinates","screenCoordinates"][(kt=(Wt=t.floatProperties)==null?void 0:Wt._OutlineWidthMode)!=null?kt:0],et=(jt=(zt=t.floatProperties)==null?void 0:zt._OutlineWidth)!=null?jt:0;et=.01*et;let mn=(Gt=t.textureProperties)==null?void 0:Gt._OutlineWidthTexture,ar=mn!=null?{index:mn,extensions:W({},K)}:void 0,lr=((qt=(Qt=t.vectorProperties)==null?void 0:Qt._OutlineColor)!=null?qt:[0,0,0]).map(ce),ur=((Yt=(Xt=t.floatProperties)==null?void 0:Xt._OutlineColorMode)!=null?Yt:0)===1?(Zt=($t=t.floatProperties)==null?void 0:$t._OutlineLightingMix)!=null?Zt:1:0,fn=(Jt=t.textureProperties)==null?void 0:Jt._UvAnimMaskTexture,dr=fn!=null?{index:fn,extensions:W({},K)}:void 0,hr=(en=(Kt=t.floatProperties)==null?void 0:Kt._UvAnimScrollX)!=null?en:0,Ae=(nn=(tn=t.floatProperties)==null?void 0:tn._UvAnimScrollY)!=null?nn:0;Ae!=null&&(Ae=-Ae);let cr=(on=(rn=t.floatProperties)==null?void 0:rn._UvAnimRotation)!=null?on:0,pr={specVersion:"1.0",transparentWithZWrite:Bi,renderQueueOffsetNumber:Fi,shadeColorFactor:$i,shadeMultiplyTexture:Zi,shadingShiftFactor:Pe,shadingToonyFactor:Se,giEqualizationFactor:Ji,matcapFactor:Ki,matcapTexture:er,rimLightingMixFactor:tr,rimMultiplyTexture:nr,parametricRimColorFactor:ir,parametricRimFresnelPowerFactor:rr,parametricRimLiftFactor:or,outlineWidthMode:sr,outlineWidthFactor:et,outlineWidthMultiplyTexture:ar,outlineColorFactor:lr,outlineLightingMixFactor:ur,uvAnimationMaskTexture:dr,uvAnimationScrollXSpeedFactor:hr,uvAnimationScrollYSpeedFactor:Ae,uvAnimationRotationSpeedFactor:cr};return ci(W({},e),{pbrMetallicRoughness:{baseColorFactor:ji,baseColorTexture:Gi},normalTexture:qi,emissiveTexture:Yi,emissiveFactor:Xi,alphaMode:Wi,alphaCutoff:ki,doubleSided:zi,extensions:{VRMC_materials_mtoon:pr}})}_parseV0UnlitProperties(t,e){var n,i,r,s,a;let l=t.shader==="VRM/UnlitTransparentZWrite",o=t.shader==="VRM/UnlitTransparent"||l,u=this._v0ParseRenderQueue(t),d=t.shader==="VRM/UnlitCutout",c=o?"BLEND":d?"MASK":"OPAQUE",f=d?(i=(n=t.floatProperties)==null?void 0:n._Cutoff)!=null?i:.5:void 0,p=this._portTextureTransform(t),m=((s=(r=t.vectorProperties)==null?void 0:r._Color)!=null?s:[1,1,1,1]).map(ce),h=(a=t.textureProperties)==null?void 0:a._MainTex,_=h!=null?{index:h,extensions:W({},p)}:void 0,g={specVersion:"1.0",transparentWithZWrite:l,renderQueueOffsetNumber:u,shadeColorFactor:m,shadeMultiplyTexture:_};return ci(W({},e),{pbrMetallicRoughness:{baseColorFactor:m,baseColorTexture:_},alphaMode:c,alphaCutoff:f,extensions:{VRMC_materials_mtoon:g}})}_portTextureTransform(t){var e,n,i,r,s;let a=(e=t.vectorProperties)==null?void 0:e._MainTex;if(a==null)return{};let l=[(n=a==null?void 0:a[0])!=null?n:0,(i=a==null?void 0:a[1])!=null?i:0],o=[(r=a==null?void 0:a[2])!=null?r:1,(s=a==null?void 0:a[3])!=null?s:1];return l[1]=1-o[1]-l[1],{KHR_texture_transform:{offset:l,scale:o}}}_v0ParseRenderQueue(t){var e,n,i;let r=(n=(e=t.keywordMap)==null?void 0:e._ALPHABLEND_ON)!=null?n:!1,s=((i=t.floatProperties)==null?void 0:i._ZWrite)===1,a=0;if(r){let l=t.renderQueue;l!=null&&(s?a=this._renderQueueMapTransparentZWrite.get(l):a=this._renderQueueMapTransparent.get(l))}return a}_populateRenderQueueMap(t){let e=new Set,n=new Set;t.forEach(i=>{var r,s,a;let l=(s=(r=i.keywordMap)==null?void 0:r._ALPHABLEND_ON)!=null?s:!1,o=((a=i.floatProperties)==null?void 0:a._ZWrite)===1;if(l){let u=i.renderQueue;u!=null&&(o?n.add(u):e.add(u))}}),e.size>10&&console.warn(`VRMMaterialsV0CompatPlugin: This VRM uses ${e.size} render queues for Transparent materials while VRM 1.0 only supports up to 10 render queues. The model might not be rendered correctly.`),n.size>10&&console.warn(`VRMMaterialsV0CompatPlugin: This VRM uses ${n.size} render queues for TransparentZWrite materials while VRM 1.0 only supports up to 10 render queues. The model might not be rendered correctly.`),Array.from(e).sort().forEach((i,r)=>{let s=Math.min(Math.max(r-e.size+1,-9),0);this._renderQueueMapTransparent.set(i,s)}),Array.from(n).sort().forEach((i,r)=>{let s=Math.min(Math.max(r,0),9);this._renderQueueMapTransparentZWrite.set(i,s)})}};var O=M(require("three"),1),k=M(require("three"),1),Tt=M(require("three"),1),Re=M(require("three"),1),G=M(require("three"),1);var fi=(t,e,n)=>new Promise((i,r)=>{var s=o=>{try{l(n.next(o))}catch(u){r(u)}},a=o=>{try{l(n.throw(o))}catch(u){r(u)}},l=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);l((n=n.apply(t,e)).next())}),$=new O.Vector3,Qe=class extends O.Group{constructor(t){super(),this._attrPosition=new O.BufferAttribute(new Float32Array([0,0,0,0,0,0]),3),this._attrPosition.setUsage(O.DynamicDrawUsage);let e=new O.BufferGeometry;e.setAttribute("position",this._attrPosition);let n=new O.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new O.Line(e,n),this.add(this._line),this.constraint=t}updateMatrixWorld(t){$.setFromMatrixPosition(this.constraint.destination.matrixWorld),this._attrPosition.setXYZ(0,$.x,$.y,$.z),this.constraint.source&&$.setFromMatrixPosition(this.constraint.source.matrixWorld),this._attrPosition.setXYZ(1,$.x,$.y,$.z),this._attrPosition.needsUpdate=!0,super.updateMatrixWorld(t)}};function _i(t,e){return e.set(t.elements[12],t.elements[13],t.elements[14])}var po=new Tt.Vector3,mo=new Tt.Vector3;function fo(t,e){return t.decompose(po,e,mo),e}function qe(t){return t.invert?t.invert():t.inverse(),t}var Xe=class{constructor(t,e){this.destination=t,this.source=e,this.weight=1}},_o=new k.Vector3,go=new k.Vector3,vo=new k.Vector3,Eo=new k.Quaternion,Mo=new k.Quaternion,Ro=new k.Quaternion,gi=class extends Xe{get aimAxis(){return this._aimAxis}set aimAxis(t){this._aimAxis=t,this._v3AimAxis.set(t==="PositiveX"?1:t==="NegativeX"?-1:0,t==="PositiveY"?1:t==="NegativeY"?-1:0,t==="PositiveZ"?1:t==="NegativeZ"?-1:0)}get dependencies(){let t=new Set([this.source]);return this.destination.parent&&t.add(this.destination.parent),t}constructor(t,e){super(t,e),this._aimAxis="PositiveX",this._v3AimAxis=new k.Vector3(1,0,0),this._dstRestQuat=new k.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion)}update(){this.destination.updateWorldMatrix(!0,!1),this.source.updateWorldMatrix(!0,!1);let t=Eo.identity(),e=Mo.identity();this.destination.parent&&(fo(this.destination.parent.matrixWorld,t),qe(e.copy(t)));let n=_o.copy(this._v3AimAxis).applyQuaternion(this._dstRestQuat).applyQuaternion(t),i=_i(this.source.matrixWorld,go).sub(_i(this.destination.matrixWorld,vo)).normalize(),r=Ro.setFromUnitVectors(n,i).premultiply(e).multiply(t).multiply(this._dstRestQuat);this.destination.quaternion.copy(this._dstRestQuat).slerp(r,this.weight)}};function To(t,e){let n=[t],i=t.parent;for(;i!==null;)n.unshift(i),i=i.parent;n.forEach(r=>{e(r)})}var vi=class{constructor(){this._constraints=new Set,this._objectConstraintsMap=new Map}get constraints(){return this._constraints}addConstraint(t){this._constraints.add(t);let e=this._objectConstraintsMap.get(t.destination);e==null&&(e=new Set,this._objectConstraintsMap.set(t.destination,e)),e.add(t)}deleteConstraint(t){this._constraints.delete(t),this._objectConstraintsMap.get(t.destination).delete(t)}setInitState(){let t=new Set,e=new Set;for(let n of this._constraints)this._processConstraint(n,t,e,i=>i.setInitState())}update(){let t=new Set,e=new Set;for(let n of this._constraints)this._processConstraint(n,t,e,i=>i.update())}_processConstraint(t,e,n,i){if(n.has(t))return;if(e.has(t))throw new Error("VRMNodeConstraintManager: Circular dependency detected while updating constraints");e.add(t);let r=t.dependencies;for(let s of r)To(s,a=>{let l=this._objectConstraintsMap.get(a);if(l)for(let o of l)this._processConstraint(o,e,n,i)});i(t),n.add(t)}},xo=new Re.Quaternion,yo=new Re.Quaternion,Ei=class extends Xe{get dependencies(){return new Set([this.source])}constructor(t,e){super(t,e),this._dstRestQuat=new Re.Quaternion,this._invSrcRestQuat=new Re.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion),qe(this._invSrcRestQuat.copy(this.source.quaternion))}update(){let t=xo.copy(this._invSrcRestQuat).multiply(this.source.quaternion),e=yo.copy(this._dstRestQuat).multiply(t);this.destination.quaternion.copy(this._dstRestQuat).slerp(e,this.weight)}},wo=new G.Vector3,Po=new G.Quaternion,So=new G.Quaternion,Mi=class extends Xe{get rollAxis(){return this._rollAxis}set rollAxis(t){this._rollAxis=t,this._v3RollAxis.set(t==="X"?1:0,t==="Y"?1:0,t==="Z"?1:0)}get dependencies(){return new Set([this.source])}constructor(t,e){super(t,e),this._rollAxis="X",this._v3RollAxis=new G.Vector3(1,0,0),this._dstRestQuat=new G.Quaternion,this._invDstRestQuat=new G.Quaternion,this._invSrcRestQuatMulDstRestQuat=new G.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion),qe(this._invDstRestQuat.copy(this._dstRestQuat)),qe(this._invSrcRestQuatMulDstRestQuat.copy(this.source.quaternion)).multiply(this._dstRestQuat)}update(){let t=Po.copy(this._invDstRestQuat).multiply(this.source.quaternion).multiply(this._invSrcRestQuatMulDstRestQuat),e=wo.copy(this._v3RollAxis).applyQuaternion(t),i=So.setFromUnitVectors(e,this._v3RollAxis).premultiply(this._dstRestQuat).multiply(t);this.destination.quaternion.copy(this._dstRestQuat).slerp(i,this.weight)}},Ao=new Set(["1.0","1.0-beta"]),Ri=class Me{get name(){return Me.EXTENSION_NAME}constructor(e,n){this.parser=e,this.helperRoot=n==null?void 0:n.helperRoot}afterRoot(e){return fi(this,null,function*(){e.userData.vrmNodeConstraintManager=yield this._import(e)})}_import(e){return fi(this,null,function*(){var n;let i=this.parser.json;if(!(((n=i.extensionsUsed)==null?void 0:n.indexOf(Me.EXTENSION_NAME))!==-1))return null;let s=new vi,a=yield this.parser.getDependencies("node");return a.forEach((l,o)=>{var u;let d=i.nodes[o],c=(u=d==null?void 0:d.extensions)==null?void 0:u[Me.EXTENSION_NAME];if(c==null)return;let f=c.specVersion;if(!Ao.has(f)){console.warn(`VRMNodeConstraintLoaderPlugin: Unknown ${Me.EXTENSION_NAME} specVersion "${f}"`);return}let p=c.constraint;if(p.roll!=null){let m=this._importRollConstraint(l,a,p.roll);s.addConstraint(m)}else if(p.aim!=null){let m=this._importAimConstraint(l,a,p.aim);s.addConstraint(m)}else if(p.rotation!=null){let m=this._importRotationConstraint(l,a,p.rotation);s.addConstraint(m)}}),e.scene.updateMatrixWorld(),s.setInitState(),s})}_importRollConstraint(e,n,i){let{source:r,rollAxis:s,weight:a}=i,l=n[r],o=new Mi(e,l);if(s!=null&&(o.rollAxis=s),a!=null&&(o.weight=a),this.helperRoot){let u=new Qe(o);this.helperRoot.add(u)}return o}_importAimConstraint(e,n,i){let{source:r,aimAxis:s,weight:a}=i,l=n[r],o=new gi(e,l);if(s!=null&&(o.aimAxis=s),a!=null&&(o.weight=a),this.helperRoot){let u=new Qe(o);this.helperRoot.add(u)}return o}_importRotationConstraint(e,n,i){let{source:r,weight:s}=i,a=n[r],l=new Ei(e,a);if(s!=null&&(l.weight=s),this.helperRoot){let o=new Qe(l);this.helperRoot.add(o)}return l}};Ri.EXTENSION_NAME="VRMC_node_constraint";var xt=Ri;var Z=M(require("three"),1),we=M(require("three"),1),yi=M(require("three"),1),q=M(require("three"),1),oe=M(require("three"),1),J=M(require("three"),1),se=M(require("three"),1),Pi=M(require("three"),1),I=M(require("three"),1),Si=M(require("three"),1),Li=M(require("three"),1),re=M(require("three"),1);var Ye=(t,e,n)=>new Promise((i,r)=>{var s=o=>{try{l(n.next(o))}catch(u){r(u)}},a=o=>{try{l(n.throw(o))}catch(u){r(u)}},l=o=>o.done?i(o.value):Promise.resolve(o.value).then(s,a);l((n=n.apply(t,e)).next())}),At=class{},yt=new we.Vector3,ie=new we.Vector3,Lt=class extends At{get type(){return"capsule"}constructor(t){var e,n,i;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new we.Vector3(0,0,0),this.tail=(n=t==null?void 0:t.tail)!=null?n:new we.Vector3(0,0,0),this.radius=(i=t==null?void 0:t.radius)!=null?i:0}calculateCollision(t,e,n,i){yt.copy(this.offset).applyMatrix4(t),ie.copy(this.tail).applyMatrix4(t),ie.sub(yt);let r=ie.lengthSq();i.copy(e).sub(yt);let s=ie.dot(i);s<=0||(r<=s||ie.multiplyScalar(s/r),i.sub(ie));let a=n+this.radius,l=i.length()-a;return i.normalize(),l}},Ht=class extends At{get type(){return"sphere"}constructor(t){var e,n;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new yi.Vector3(0,0,0),this.radius=(n=t==null?void 0:t.radius)!=null?n:0}calculateCollision(t,e,n,i){i.copy(this.offset).applyMatrix4(t),i.negate().add(e);let r=n+this.radius,s=i.length()-r;return i.normalize(),s}},z=new q.Vector3,Lo=class extends q.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new q.Vector3,this._currentTail=new q.Vector3,this._shape=t,this._attrPos=new q.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new q.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1,e=this._shape.radius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0);let n=z.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(n)>1e-10&&(this._currentTail.copy(n),t=!0),t&&this._buildPosition()}_buildPosition(){z.copy(this._currentTail).sub(this._currentOffset);let t=z.length()/this._currentRadius;for(let i=0;i<=16;i++){let r=i/16*Math.PI;this._attrPos.setXYZ(i,-Math.sin(r),-Math.cos(r),0),this._attrPos.setXYZ(17+i,t+Math.sin(r),Math.cos(r),0),this._attrPos.setXYZ(34+i,-Math.sin(r),0,-Math.cos(r)),this._attrPos.setXYZ(51+i,t+Math.sin(r),0,Math.cos(r))}for(let i=0;i<32;i++){let r=i/16*Math.PI;this._attrPos.setXYZ(68+i,0,Math.sin(r),Math.cos(r)),this._attrPos.setXYZ(100+i,t,Math.sin(r),Math.cos(r))}let e=Math.atan2(z.y,Math.sqrt(z.x*z.x+z.z*z.z)),n=-Math.atan2(z.z,z.x);this.rotateZ(e),this.rotateY(n),this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<34;t++){let e=(t+1)%34;this._attrIndex.setXY(t*2,t,e),this._attrIndex.setXY(68+t*2,34+t,34+e)}for(let t=0;t<32;t++){let e=(t+1)%32;this._attrIndex.setXY(136+t*2,68+t,68+e),this._attrIndex.setXY(200+t*2,100+t,100+e)}this._attrIndex.needsUpdate=!0}},Ho=class extends oe.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new oe.Vector3,this._shape=t,this._attrPos=new oe.BufferAttribute(new Float32Array(32*3*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new oe.BufferAttribute(new Uint16Array(64*3),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1,e=this._shape.radius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){let e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){let e=(t+1)%32;this._attrIndex.setXY(t*2,t,e),this._attrIndex.setXY(64+t*2,32+t,32+e),this._attrIndex.setXY(128+t*2,64+t,64+e)}this._attrIndex.needsUpdate=!0}},bo=new Z.Vector3,wt=class extends Z.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof Ht)this._geometry=new Ho(this.collider.shape);else if(this.collider.shape instanceof Lt)this._geometry=new Lo(this.collider.shape);else throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");let e=new Z.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new Z.LineSegments(this._geometry,e),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld);let e=this.matrix.elements;this._geometry.worldScale=bo.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}},Vo=class extends se.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentTail=new se.Vector3,this._springBone=t,this._attrPos=new se.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new se.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1,e=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){let e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}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 t=0;t<32;t++){let e=(t+1)%32;this._attrIndex.setXY(t*2,t,e),this._attrIndex.setXY(64+t*2,32+t,32+e),this._attrIndex.setXY(128+t*2,64+t,64+e)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}},Io=new J.Vector3,wi=class extends J.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new Vo(this.springBone);let e=new J.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new J.LineSegments(this._geometry,e),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld);let e=this.matrix.elements;this._geometry.worldScale=Io.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}},Pt=class extends Pi.Object3D{constructor(t){super(),this.shape=t}},Uo=new Si.Matrix4;function Ai(t){return t.invert?t.invert():t.getInverse(Uo.copy(t)),t}var Co=class{constructor(t){this._inverseCache=new Li.Matrix4,this._shouldUpdateInverse=!0,this.matrix=t;let e={set:(n,i,r)=>(this._shouldUpdateInverse=!0,n[i]=r,!0)};this._originalElements=t.elements,t.elements=new Proxy(t.elements,e)}get inverse(){return this._shouldUpdateInverse&&(Ai(this._inverseCache.copy(this.matrix)),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}},Oo=new I.Matrix4,Q=new I.Vector3,Te=new I.Vector3,No=new I.Vector3,pe=new I.Vector3,Ti=new I.Vector3,xe=new I.Vector3,xi=new I.Quaternion,me=new I.Matrix4,Do=new I.Matrix4,Hi=class{constructor(t,e,n={},i=[]){this._currentTail=new I.Vector3,this._prevTail=new I.Vector3,this._boneAxis=new I.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new I.Matrix4,this._initialLocalRotation=new I.Quaternion,this._initialLocalChildPosition=new I.Vector3;var r,s,a,l,o,u;this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=e,this.settings={hitRadius:(r=n.hitRadius)!=null?r:0,stiffness:(s=n.stiffness)!=null?s:1,gravityPower:(a=n.gravityPower)!=null?a:0,gravityDir:(o=(l=n.gravityDir)==null?void 0:l.clone())!=null?o:new I.Vector3(0,-1,0),dragForce:(u=n.dragForce)!=null?u:.4},this.colliderGroups=i}get center(){return this._center}set center(t){var e;(e=this._center)!=null&&e.userData.inverseCacheProxy&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=t,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new Co(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:Oo}setInitState(){this._initialLocalMatrix.copy(this.bone.matrix),this._initialLocalRotation.copy(this.bone.quaternion),this.child?this._initialLocalChildPosition.copy(this.child.position):this._initialLocalChildPosition.copy(this.bone.position).normalize().multiplyScalar(.07);let t=this._getMatrixWorldToCenter(me);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);let t=this._getMatrixWorldToCenter(me);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength(),pe.setFromMatrixPosition(this.bone.matrixWorld);let e=this._getMatrixWorldToCenter(me);Ti.copy(pe).applyMatrix4(e);let n=xi.setFromRotationMatrix(e),i=Do.copy(e).multiply(this._parentMatrixWorld),r=Te.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(i).sub(Ti).normalize(),s=No.copy(this.settings.gravityDir).applyQuaternion(n).normalize(),a=this._getMatrixCenterToWorld(me);xe.copy(this._currentTail).add(Q.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(Q.copy(r).multiplyScalar(this.settings.stiffness*t)).add(Q.copy(s).multiplyScalar(this.settings.gravityPower*t)).applyMatrix4(a),xe.sub(pe).normalize().multiplyScalar(this._worldSpaceBoneLength).add(pe),this._collision(xe),e=this._getMatrixWorldToCenter(me),this._prevTail.copy(this._currentTail),this._currentTail.copy(Q.copy(xe).applyMatrix4(e));let l=Ai(me.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),o=xi.setFromUnitVectors(this._boneAxis,Q.copy(xe).applyMatrix4(l).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(o),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){this.colliderGroups.forEach(e=>{e.colliders.forEach(n=>{let i=n.shape.calculateCollision(n.matrixWorld,t,this.settings.hitRadius,Q);i<0&&(t.add(Q.multiplyScalar(-i)),t.sub(pe).normalize().multiplyScalar(this._worldSpaceBoneLength).add(pe))})})}_calcWorldSpaceBoneLength(){Q.setFromMatrixPosition(this.bone.matrixWorld),this.child?Te.setFromMatrixPosition(this.child.matrixWorld):(Te.copy(this._initialLocalChildPosition),Te.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=Q.sub(Te).length()}_getMatrixCenterToWorld(t){return this._center?t.copy(this._center.matrixWorld):t.identity(),t}_getMatrixWorldToCenter(t){return this._center?t.copy(this._center.userData.inverseCacheProxy.inverse):t.identity(),t}};function Bo(t,e){let n=[],i=t;for(;i!==null;)n.unshift(i),i=i.parent;n.forEach(r=>{e(r)})}function bi(t,e){t.children.forEach(n=>{e(n)||bi(n,e)})}var St=class{constructor(){this._joints=new Set,this._objectSpringBonesMap=new Map}get joints(){return this._joints}get springBones(){return console.warn("VRMSpringBoneManager: springBones is deprecated. use joints instead."),this._joints}get colliderGroups(){let t=new Set;return this._joints.forEach(e=>{e.colliderGroups.forEach(n=>{t.add(n)})}),Array.from(t)}get colliders(){let t=new Set;return this.colliderGroups.forEach(e=>{e.colliders.forEach(n=>{t.add(n)})}),Array.from(t)}addJoint(t){this._joints.add(t);let e=this._objectSpringBonesMap.get(t.bone);e==null&&(e=new Set,this._objectSpringBonesMap.set(t.bone,e)),e.add(t)}addSpringBone(t){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(t)}deleteJoint(t){this._joints.delete(t),this._objectSpringBonesMap.get(t.bone).delete(t)}deleteSpringBone(t){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(t)}setInitState(){let t=new Set,e=new Set,n=new Set;for(let i of this._joints)this._processSpringBone(i,t,e,n,r=>r.setInitState())}reset(){let t=new Set,e=new Set,n=new Set;for(let i of this._joints)this._processSpringBone(i,t,e,n,r=>r.reset())}update(t){let e=new Set,n=new Set,i=new Set;for(let r of this._joints)this._processSpringBone(r,e,n,i,s=>s.update(t)),bi(r.bone,s=>{var a,l;return((l=(a=this._objectSpringBonesMap.get(s))==null?void 0:a.size)!=null?l:0)>0?!0:(s.updateWorldMatrix(!1,!1),!1)})}_processSpringBone(t,e,n,i,r){if(n.has(t))return;if(e.has(t))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");e.add(t);let s=this._getDependencies(t);for(let a of s)Bo(a,l=>{let o=this._objectSpringBonesMap.get(l);if(o)for(let u of o)this._processSpringBone(u,e,n,i,r);else i.has(l)||(l.updateWorldMatrix(!1,!1),i.add(l))});t.bone.updateMatrix(),t.bone.updateWorldMatrix(!1,!1),r(t),i.add(t.bone),n.add(t)}_getDependencies(t){let e=new Set,n=t.bone.parent;return n&&e.add(n),t.colliderGroups.forEach(i=>{i.colliders.forEach(r=>{e.add(r)})}),e}},Fo=new Set(["1.0","1.0-beta"]),Vi=class ye{get name(){return ye.EXTENSION_NAME}constructor(e,n){this.parser=e,this.jointHelperRoot=n==null?void 0:n.jointHelperRoot,this.colliderHelperRoot=n==null?void 0:n.colliderHelperRoot}afterRoot(e){return Ye(this,null,function*(){e.userData.vrmSpringBoneManager=yield this._import(e)})}_import(e){return Ye(this,null,function*(){let n=yield this._v1Import(e);if(n!=null)return n;let i=yield this._v0Import(e);return i!=null?i:null})}_v1Import(e){return Ye(this,null,function*(){var n,i,r,s,a;let l=e.parser.json;if(!(((n=l.extensionsUsed)==null?void 0:n.indexOf(ye.EXTENSION_NAME))!==-1))return null;let u=new St,d=yield e.parser.getDependencies("node"),c=(i=l.extensions)==null?void 0:i[ye.EXTENSION_NAME];if(!c)return null;let f=c.specVersion;if(!Fo.has(f))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${ye.EXTENSION_NAME} specVersion "${f}"`),null;let p=(r=c.colliders)==null?void 0:r.map((h,_)=>{var g,y,x,v,T;let E=d[h.node],R=h.shape;if(R.sphere)return this._importSphereCollider(E,{offset:new re.Vector3().fromArray((g=R.sphere.offset)!=null?g:[0,0,0]),radius:(y=R.sphere.radius)!=null?y:0});if(R.capsule)return this._importCapsuleCollider(E,{offset:new re.Vector3().fromArray((x=R.capsule.offset)!=null?x:[0,0,0]),radius:(v=R.capsule.radius)!=null?v:0,tail:new re.Vector3().fromArray((T=R.capsule.tail)!=null?T:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${_} has no valid shape`)}),m=(s=c.colliderGroups)==null?void 0:s.map((h,_)=>{var g;return{colliders:((g=h.colliders)!=null?g:[]).map(x=>{let v=p==null?void 0:p[x];if(v==null)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${_} attempted to use a collider #${x} but not found`);return v}),name:h.name}});return(a=c.springs)==null||a.forEach((h,_)=>{var g;let y=h.joints,x=(g=h.colliderGroups)==null?void 0:g.map(E=>{let R=m==null?void 0:m[E];if(R==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${_} attempted to use a colliderGroup ${E} but not found`);return R}),v=h.center!=null?d[h.center]:void 0,T;y.forEach(E=>{if(T){let R=T.node,L=d[R],U=E.node,H=d[U],b={hitRadius:T.hitRadius,dragForce:T.dragForce,gravityPower:T.gravityPower,stiffness:T.stiffness,gravityDir:T.gravityDir!=null?new re.Vector3().fromArray(T.gravityDir):void 0},C=this._importJoint(L,H,b,x);v&&(C.center=v),u.addJoint(C)}T=E})}),u.setInitState(),u})}_v0Import(e){return Ye(this,null,function*(){var n,i,r;let s=e.parser.json;if(!(((n=s.extensionsUsed)==null?void 0:n.indexOf("VRM"))!==-1))return null;let l=(i=s.extensions)==null?void 0:i.VRM,o=l==null?void 0:l.secondaryAnimation;if(!o)return null;let u=o==null?void 0:o.boneGroups;if(!u)return null;let d=new St,c=yield e.parser.getDependencies("node"),f=(r=o.colliderGroups)==null?void 0:r.map(p=>{var m;let h=c[p.node];return{colliders:((m=p.colliders)!=null?m:[]).map((g,y)=>{var x,v,T;let E=new re.Vector3(0,0,0);return g.offset&&E.set((x=g.offset.x)!=null?x:0,(v=g.offset.y)!=null?v:0,g.offset.z?-g.offset.z:0),this._importSphereCollider(h,{offset:E,radius:(T=g.radius)!=null?T:0})})}});return u==null||u.forEach((p,m)=>{let h=p.bones;h&&h.forEach(_=>{var g,y,x,v;let T=c[_],E=new re.Vector3;p.gravityDir?E.set((g=p.gravityDir.x)!=null?g:0,(y=p.gravityDir.y)!=null?y:0,(x=p.gravityDir.z)!=null?x:0):E.set(0,-1,0);let R=p.center!=null?c[p.center]:void 0,L={hitRadius:p.hitRadius,dragForce:p.dragForce,gravityPower:p.gravityPower,stiffness:p.stiffiness,gravityDir:E},U=(v=p.colliderGroups)==null?void 0:v.map(H=>{let b=f==null?void 0:f[H];if(b==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${m} attempted to use a colliderGroup ${H} but not found`);return b});T.traverse(H=>{var b;let C=(b=H.children[0])!=null?b:null,fe=this._importJoint(H,C,L,U);R&&(fe.center=R),d.addJoint(fe)})})}),e.scene.updateMatrixWorld(),d.setInitState(),d})}_importJoint(e,n,i,r){let s=new Hi(e,n,i,r);if(this.jointHelperRoot){let a=new wi(s);this.jointHelperRoot.add(a),a.renderOrder=this.jointHelperRoot.renderOrder}return s}_importSphereCollider(e,n){let{offset:i,radius:r}=n,s=new Ht({offset:i,radius:r}),a=new Pt(s);if(e.add(a),this.colliderHelperRoot){let l=new wt(a);this.colliderHelperRoot.add(l),l.renderOrder=this.colliderHelperRoot.renderOrder}return a}_importCapsuleCollider(e,n){let{offset:i,radius:r,tail:s}=n,a=new Lt({offset:i,radius:r,tail:s}),l=new Pt(a);if(e.add(l),this.colliderHelperRoot){let o=new wt(l);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return l}};Vi.EXTENSION_NAME="VRMC_springBone";var bt=Vi;var $e=class{get name(){return"VRMLoaderPlugin"}constructor(e,n){var s,a,l,o,u,d,c,f,p,m;this.parser=e;let i=n==null?void 0:n.helperRoot,r=n==null?void 0:n.autoUpdateHumanBones;this.expressionPlugin=(s=n==null?void 0:n.expressionPlugin)!=null?s:new Oe(e),this.firstPersonPlugin=(a=n==null?void 0:n.firstPersonPlugin)!=null?a:new Ne(e),this.humanoidPlugin=(l=n==null?void 0:n.humanoidPlugin)!=null?l:new Be(e,{helperRoot:i,autoUpdateHumanBones:r}),this.lookAtPlugin=(o=n==null?void 0:n.lookAtPlugin)!=null?o:new Fe(e,{helperRoot:i}),this.metaPlugin=(u=n==null?void 0:n.metaPlugin)!=null?u:new We(e),this.mtoonMaterialPlugin=(d=n==null?void 0:n.mtoonMaterialPlugin)!=null?d:new Mt(e),this.materialsHDREmissiveMultiplierPlugin=(c=n==null?void 0:n.materialsHDREmissiveMultiplierPlugin)!=null?c:new ui(e),this.materialsV0CompatPlugin=(f=n==null?void 0:n.materialsV0CompatPlugin)!=null?f:new mi(e),this.springBonePlugin=(p=n==null?void 0:n.springBonePlugin)!=null?p:new bt(e,{colliderHelperRoot:i,jointHelperRoot:i}),this.nodeConstraintPlugin=(m=n==null?void 0:n.nodeConstraintPlugin)!=null?m:new xt(e,{helperRoot:i})}beforeRoot(){return _e(this,null,function*(){yield this.materialsV0CompatPlugin.beforeRoot(),yield this.mtoonMaterialPlugin.beforeRoot()})}loadMesh(e){return _e(this,null,function*(){return yield this.mtoonMaterialPlugin.loadMesh(e)})}getMaterialType(e){let n=this.mtoonMaterialPlugin.getMaterialType(e);return n!=null?n:null}extendMaterialParams(e,n){return _e(this,null,function*(){yield this.materialsHDREmissiveMultiplierPlugin.extendMaterialParams(e,n),yield this.mtoonMaterialPlugin.extendMaterialParams(e,n)})}afterRoot(e){return _e(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),yield this.springBonePlugin.afterRoot(e),yield this.nodeConstraintPlugin.afterRoot(e),yield this.mtoonMaterialPlugin.afterRoot(e);let n=e.userData.vrmMeta,i=e.userData.vrmHumanoid;if(n&&i){let r=new he({scene:e.scene,expressionManager:e.userData.vrmExpressionManager,firstPerson:e.userData.vrmFirstPerson,humanoid:i,lookAt:e.userData.vrmLookAt,meta:n,materials:e.userData.vrmMToonMaterials,springBoneManager:e.userData.vrmSpringBoneManager,nodeConstraintManager:e.userData.vrmNodeConstraintManager});e.userData.vrm=r}})}};function Ii(t){if(Object.values(t).forEach(e=>{e!=null&&e.isTexture&&e.dispose()}),t.isShaderMaterial){let e=t.uniforms;e&&Object.values(e).forEach(n=>{let i=n.value;i!=null&&i.isTexture&&i.dispose()})}t.dispose()}function Wo(t){let e=t.geometry;e&&e.dispose();let n=t.skeleton;n&&n.dispose();let i=t.material;i&&(Array.isArray(i)?i.forEach(r=>Ii(r)):i&&Ii(i))}function Ui(t){t.traverse(Wo)}var Ze=M(require("three"),1);function Ci(t,e){var a;let n=(a=e==null?void 0:e.experimentalSameBoneCounts)!=null?a:!1,i=[];t.traverse(l=>{l.type==="SkinnedMesh"&&i.push(l)});let r=new Map,s=0;for(let l of i){let u=l.geometry.getAttribute("skinIndex"),d=[],c=[],f={},p=u.array;for(let m=0;m<p.length;m++){let h=p[m];f[h]==null&&(f[h]=d.length,d.push(l.skeleton.bones[h]),c.push(l.skeleton.boneInverses[h])),p[m]=f[h]}u.copyArray(p),u.needsUpdate=!0,r.set(l,{bones:d,boneInverses:c}),s=Math.max(s,d.length)}for(let l of i){let{bones:o,boneInverses:u}=r.get(l);if(n)for(let c=o.length;c<s;c++)o[c]=o[0],u[c]=u[0];let d=new Ze.Skeleton(o,u);l.bind(d,new Ze.Matrix4)}}var Oi=M(require("three"),1),Je=require("three");function Ni(t){let e=new Map;t.traverse(n=>{var c,f,p,m;if(!n.isMesh)return;let i=n,r=i.geometry,s=r.index;if(s==null)return;let a=e.get(r);if(a!=null){i.geometry=a;return}let l=new Oi.BufferGeometry;l.name=r.name,l.morphTargetsRelative=r.morphTargetsRelative,r.groups.forEach(h=>{l.addGroup(h.start,h.count,h.materialIndex)}),l.boundingBox=(f=(c=r.boundingBox)==null?void 0:c.clone())!=null?f:null,l.boundingSphere=(m=(p=r.boundingSphere)==null?void 0:p.clone())!=null?m:null,l.setDrawRange(r.drawRange.start,r.drawRange.count),l.userData=r.userData,e.set(r,l);let o=[],u=[];{let h=s.array,_=new h.constructor(h.length),g=0;for(let y=0;y<h.length;y++){let x=h[y],v=o[x];v==null&&(o[x]=g,u[g]=x,v=g,g++),_[y]=v}l.setIndex(new Je.BufferAttribute(_,1,!1))}Object.keys(r.attributes).forEach(h=>{let _=r.attributes[h];if(_.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");let g=_.array,{itemSize:y,normalized:x}=_,v=new g.constructor(u.length*y);u.forEach((T,E)=>{for(let R=0;R<y;R++)v[E*y+R]=g[T*y+R]}),l.setAttribute(h,new Je.BufferAttribute(v,y,x))});let d=!0;Object.keys(r.morphAttributes).forEach(h=>{l.morphAttributes[h]=[];let _=r.morphAttributes[h];for(let g=0;g<_.length;g++){let y=_[g];if(y.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");let x=y.array,{itemSize:v,normalized:T}=y,E=new x.constructor(u.length*v);u.forEach((R,L)=>{for(let U=0;U<v;U++)E[L*v+U]=x[R*v+U]}),d=d&&E.every(R=>R===0),l.morphAttributes[h][g]=new Je.BufferAttribute(E,v,T)}}),d&&(l.morphAttributes={}),i.geometry=l}),Array.from(e.keys()).forEach(n=>{n.dispose()})}function Di(t){var e;((e=t.meta)==null?void 0:e.metaVersion)==="0"&&(t.scene.rotation.y=Math.PI)}var ae=class{constructor(){}};ae.deepDispose=Ui,ae.removeUnnecessaryJoints=Ci,ae.removeUnnecessaryVertices=Ni,ae.rotateVRM0=Di;
1005
930
  /*!
1006
- * @pixiv/three-vrm-core v3.0.0-beta.0
931
+ * @pixiv/three-vrm-core v3.0.0-beta.2
1007
932
  * The implementation of core features of VRM, for @pixiv/three-vrm
1008
933
  *
1009
934
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -1011,7 +936,7 @@ void main() {
1011
936
  * https://github.com/pixiv/three-vrm/blob/release/LICENSE
1012
937
  */
1013
938
  /*!
1014
- * @pixiv/three-vrm-materials-mtoon v3.0.0-beta.0
939
+ * @pixiv/three-vrm-materials-mtoon v3.0.0-beta.2
1015
940
  * MToon (toon material) module for @pixiv/three-vrm
1016
941
  *
1017
942
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -1019,7 +944,7 @@ void main() {
1019
944
  * https://github.com/pixiv/three-vrm/blob/release/LICENSE
1020
945
  */
1021
946
  /*!
1022
- * @pixiv/three-vrm-materials-hdr-emissive-multiplier v3.0.0-beta.0
947
+ * @pixiv/three-vrm-materials-hdr-emissive-multiplier v3.0.0-beta.2
1023
948
  * Support VRMC_hdr_emissiveMultiplier for @pixiv/three-vrm
1024
949
  *
1025
950
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -1027,7 +952,7 @@ void main() {
1027
952
  * https://github.com/pixiv/three-vrm/blob/release/LICENSE
1028
953
  */
1029
954
  /*!
1030
- * @pixiv/three-vrm-materials-v0compat v3.0.0-beta.0
955
+ * @pixiv/three-vrm-materials-v0compat v3.0.0-beta.2
1031
956
  * VRM0.0 materials compatibility layer plugin for @pixiv/three-vrm
1032
957
  *
1033
958
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -1035,7 +960,7 @@ void main() {
1035
960
  * https://github.com/pixiv/three-vrm/blob/release/LICENSE
1036
961
  */
1037
962
  /*!
1038
- * @pixiv/three-vrm-node-constraint v3.0.0-beta.0
963
+ * @pixiv/three-vrm-node-constraint v3.0.0-beta.2
1039
964
  * Node constraint module for @pixiv/three-vrm
1040
965
  *
1041
966
  * Copyright (c) 2019-2024 pixiv Inc.
@@ -1043,7 +968,7 @@ void main() {
1043
968
  * https://github.com/pixiv/three-vrm/blob/release/LICENSE
1044
969
  */
1045
970
  /*!
1046
- * @pixiv/three-vrm-springbone v3.0.0-beta.0
971
+ * @pixiv/three-vrm-springbone v3.0.0-beta.2
1047
972
  * Spring bone module for @pixiv/three-vrm
1048
973
  *
1049
974
  * Copyright (c) 2019-2024 pixiv Inc.