@pixiv/three-vrm 3.3.2 → 3.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/lib/nodes/index.cjs +4 -4
- package/lib/nodes/index.min.cjs +3 -3
- package/lib/nodes/index.module.js +4 -4
- package/lib/nodes/index.module.min.js +3 -3
- package/lib/three-vrm.cjs +64 -25
- package/lib/three-vrm.min.cjs +17 -17
- package/lib/three-vrm.module.js +64 -25
- package/lib/three-vrm.module.min.js +17 -17
- package/package.json +8 -8
package/lib/three-vrm.min.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/*! (c) 2019-
|
|
2
|
-
"use strict";var xr=Object.create;var Be=Object.defineProperty;var yr=Object.getOwnPropertyDescriptor;var wr=Object.getOwnPropertyNames;var Sr=Object.getPrototypeOf,Pr=Object.prototype.hasOwnProperty;var Ar=(t,e)=>{for(var n in e)Be(t,n,{get:e[n],enumerable:!0})},wn=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of wr(e))!Pr.call(t,r)&&r!==n&&Be(t,r,{get:()=>e[r],enumerable:!(i=yr(e,r))||i.enumerable});return t};var R=(t,e,n)=>(n=t!=null?xr(Sr(t)):{},wn(e||!t||!t.__esModule?Be(n,"default",{value:t,enumerable:!0}):n,t)),Lr=t=>wn(Be({},"__esModule",{value:!0}),t);var we=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())});var as={};Ar(as,{MToonMaterial:()=>mi,MToonMaterialDebugMode:()=>ci,MToonMaterialLoaderPlugin:()=>Vt,MToonMaterialOutlineWidthMode:()=>It,VRM:()=>ve,VRMAimConstraint:()=>wi,VRMCore:()=>$e,VRMCoreLoaderPlugin:()=>no,VRMExpression:()=>gt,VRMExpressionLoaderPlugin:()=>je,VRMExpressionManager:()=>vt,VRMExpressionMaterialColorBind:()=>Et,VRMExpressionMaterialColorType:()=>fe,VRMExpressionMorphTargetBind:()=>ge,VRMExpressionOverrideType:()=>Vr,VRMExpressionPresetName:()=>ze,VRMExpressionTextureTransformBind:()=>Mt,VRMFirstPerson:()=>Rt,VRMFirstPersonLoaderPlugin:()=>Xe,VRMFirstPersonMeshAnnotationType:()=>Ur,VRMHumanBoneList:()=>ke,VRMHumanBoneName:()=>Nr,VRMHumanBoneParentMap:()=>$n,VRMHumanoid:()=>yt,VRMHumanoidHelper:()=>Tt,VRMHumanoidLoaderPlugin:()=>Ye,VRMLoaderPlugin:()=>lt,VRMLookAt:()=>oi,VRMLookAtBoneApplier:()=>Pe,VRMLookAtExpressionApplier:()=>Ge,VRMLookAtHelper:()=>ni,VRMLookAtLoaderPlugin:()=>qe,VRMLookAtRangeMap:()=>Pt,VRMLookAtTypeName:()=>Kr,VRMMetaLoaderPlugin:()=>Ze,VRMNodeConstraint:()=>nt,VRMNodeConstraintHelper:()=>et,VRMNodeConstraintLoaderPlugin:()=>Ot,VRMNodeConstraintManager:()=>Si,VRMRequiredHumanBoneName:()=>ti,VRMRollConstraint:()=>Ai,VRMRotationConstraint:()=>Pi,VRMSpringBoneCollider:()=>ot,VRMSpringBoneColliderHelper:()=>rt,VRMSpringBoneColliderShape:()=>st,VRMSpringBoneColliderShapeCapsule:()=>Wt,VRMSpringBoneColliderShapePlane:()=>zt,VRMSpringBoneColliderShapeSphere:()=>jt,VRMSpringBoneJoint:()=>Ui,VRMSpringBoneJointHelper:()=>Ii,VRMSpringBoneLoaderPlugin:()=>Xt,VRMSpringBoneManager:()=>kt,VRMUtils:()=>K});module.exports=Lr(as);var Fn=R(require("three"),1),ee=R(require("three"),1),At=R(require("three"),1),Xn=R(require("three"),1),F=R(require("three"),1),Z=R(require("three"),1),Qe=R(require("three"),1),k=R(require("three"),1),b=R(require("three"),1),Ae=R(require("three"),1),te=R(require("three"),1),C=R(require("three"),1),Ht=R(require("three"),1),V=R(require("three"),1),St=R(require("three"),1),si=R(require("three"),1);var x=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),gt=class extends Fn.Object3D{constructor(t){super(),this.weight=0,this.isBinary=!1,this.overrideBlink="none",this.overrideLookAt="none",this.overrideMouth="none",this._binds=[],this.name=`VRMExpression_${t}`,this.expressionName=t,this.type="VRMExpression",this.visible=!1}get binds(){return this._binds}get overrideBlinkAmount(){return this.overrideBlink==="block"?0<this.outputWeight?1:0:this.overrideBlink==="blend"?this.outputWeight:0}get overrideLookAtAmount(){return this.overrideLookAt==="block"?0<this.outputWeight?1:0:this.overrideLookAt==="blend"?this.outputWeight:0}get overrideMouthAmount(){return this.overrideMouth==="block"?0<this.outputWeight?1:0:this.overrideMouth==="blend"?this.outputWeight:0}get outputWeight(){return this.isBinary?this.weight>.5?1:0:this.weight}addBind(t){this._binds.push(t)}deleteBind(t){let e=this._binds.indexOf(t);e>=0&&this._binds.splice(e,1)}applyWeight(t){var e;let n=this.outputWeight;n*=(e=t==null?void 0:t.multiplier)!=null?e:1,this.isBinary&&n<1&&(n=0),this._binds.forEach(i=>i.applyWeight(n))}clearAppliedWeight(){this._binds.forEach(t=>t.clearAppliedWeight())}};function kn(t,e,n){var i,r;let o=t.parser.json,a=(i=o.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 s=(r=o.meshes)==null?void 0:r[l];if(s==null)return console.warn(`extractPrimitivesInternal: Attempt to use meshes[${l}] of glTF but the mesh doesn't exist`),null;let u=s.primitives.length,d=[];return n.traverse(h=>{d.length<u&&h.isMesh&&d.push(h)}),d}function Sn(t,e){return x(this,null,function*(){let n=yield t.parser.getDependency("node",e);return kn(t,e,n)})}function Pn(t){return x(this,null,function*(){let e=yield t.parser.getDependencies("node"),n=new Map;return e.forEach((i,r)=>{let o=kn(t,r,i);o!=null&&n.set(r,o)}),n})}var ze={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 Wn(t){return Math.max(Math.min(t,1),0)}var vt=class zn{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(ze));return Object.entries(this._expressionMap).forEach(([i,r])=>{n.has(i)&&(e[i]=r)}),e}get customExpressionMap(){let e={},n=new Set(Object.values(ze));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 zn().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=Wn(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}}},fe={Color:"color",EmissionColor:"emissionColor",ShadeColor:"shadeColor",MatcapColor:"matcapColor",RimColor:"rimColor",OutlineColor:"outlineColor"},Hr={_Color:fe.Color,_EmissionColor:fe.EmissionColor,_ShadeColor:fe.ShadeColor,_RimColor:fe.RimColor,_OutlineColor:fe.OutlineColor},br=new At.Color,Gn=class jn{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 o=this._initColorBindState(),a=this._initAlphaBindState();this._state={color:o,alpha:a}}applyWeight(e){let{color:n,alpha:i}=this._state;if(n!=null){let{propertyName:r,deltaValue:o}=n,a=this.material[r];a!=null&&a.add(br.copy(o).multiplyScalar(e))}if(i!=null){let{propertyName:r,deltaValue:o}=i;this.material[r]!=null&&(this.material[r]+=o*e)}}clearAppliedWeight(){let{color:e,alpha:n}=this._state;if(e!=null){let{propertyName:i,initialValue:r}=e,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 e,n,i;let{material:r,type:o,targetValue:a}=this,l=this._getPropertyNameMap(),s=(n=(e=l==null?void 0:l[o])==null?void 0:e[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(),h=new At.Color(a.r-d.r,a.g-d.g,a.b-d.b);return{propertyName:s,initialValue:d,deltaValue:h}}_initAlphaBindState(){var e,n,i;let{material:r,type:o,targetAlpha:a}=this,l=this._getPropertyNameMap(),s=(n=(e=l==null?void 0:l[o])==null?void 0:e[1])!=null?n:null;if(s==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 ${o} but the material or the type does not support alpha.`),null;if(s==null)return null;let u=r[s],d=a-u;return{propertyName:s,initialValue:u,deltaValue:d}}_getPropertyNameMap(){var e,n;return(n=(e=Object.entries(jn._propertyNameMapMap).find(([i])=>this.material[i]===!0))==null?void 0:e[1])!=null?n:null}};Gn._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 Et=Gn,ge=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)})}},An=new Xn.Vector2,Qn=class Yn{constructor({material:e,scale:n,offset:i}){var r,o;this.material=e,this.scale=n,this.offset=i;let a=(r=Object.entries(Yn._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 ${(o=e.name)!=null?o:"(no name)"} but the material is not supported.`),this._properties=[]):(this._properties=[],a.forEach(l=>{var s;let u=(s=e[l])==null?void 0:s.clone();if(!u)return null;e[l]=u;let d=u.offset.clone(),h=u.repeat.clone(),p=i.clone().sub(d),m=n.clone().sub(h);this._properties.push({name:l,initialOffset:d,deltaOffset:p,initialScale:h,deltaScale:m})}))}applyWeight(e){this._properties.forEach(n=>{let i=this.material[n.name];i!==void 0&&(i.offset.add(An.copy(n.deltaOffset).multiplyScalar(e)),i.repeat.add(An.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))})}};Qn._propertyNamesMap={isMeshStandardMaterial:["map","emissiveMap","bumpMap","normalMap","displacementMap","roughnessMap","metalnessMap","alphaMap"],isMeshBasicMaterial:["map","specularMap","alphaMap"],isMToonMaterial:["map","normalMap","emissiveMap","shadeMultiplyTexture","rimMultiplyTexture","outlineWidthMultiplyTexture","uvAnimationMaskTexture"]};var Mt=Qn,Ir=new Set(["1.0","1.0-beta"]),qn=class Zn{get name(){return"VRMExpressionLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return x(this,null,function*(){e.userData.vrmExpressionManager=yield this._import(e)})}_import(e){return x(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 x(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(!Ir.has(l))return console.warn(`VRMExpressionLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let s=a.expressions;if(!s)return null;let u=new Set(Object.values(ze)),d=new Map;s.preset!=null&&Object.entries(s.preset).forEach(([p,m])=>{if(m!=null){if(!u.has(p)){console.warn(`VRMExpressionLoaderPlugin: Unknown preset name "${p}" detected. Ignoring the expression`);return}d.set(p,m)}}),s.custom!=null&&Object.entries(s.custom).forEach(([p,m])=>{if(u.has(p)){console.warn(`VRMExpressionLoaderPlugin: Custom expression cannot have preset name "${p}". Ignoring the expression`);return}d.set(p,m)});let h=new vt;return yield Promise.all(Array.from(d.entries()).map(p=>x(this,[p],function*([m,c]){var f,_,E,I,y,g,v;let M=new gt(m);if(e.scene.add(M),M.isBinary=(f=c.isBinary)!=null?f:!1,M.overrideBlink=(_=c.overrideBlink)!=null?_:"none",M.overrideLookAt=(E=c.overrideLookAt)!=null?E:"none",M.overrideMouth=(I=c.overrideMouth)!=null?I:"none",(y=c.morphTargetBinds)==null||y.forEach(T=>x(this,null,function*(){var P;if(T.node===void 0||T.index===void 0)return;let L=yield Sn(e,T.node),A=T.index;if(!L.every(S=>Array.isArray(S.morphTargetInfluences)&&A<S.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${c.name} attempts to index morph #${A} but not found.`);return}M.addBind(new ge({primitives:L,index:A,weight:(P=T.weight)!=null?P:1}))})),c.materialColorBinds||c.textureTransformBinds){let T=[];e.scene.traverse(P=>{let L=P.material;L&&(Array.isArray(L)?T.push(...L):T.push(L))}),(g=c.materialColorBinds)==null||g.forEach(P=>x(this,null,function*(){T.filter(A=>{var S;let H=(S=this.parser.associations.get(A))==null?void 0:S.materials;return P.material===H}).forEach(A=>{M.addBind(new Et({material:A,type:P.type,targetValue:new ee.Color().fromArray(P.targetValue),targetAlpha:P.targetValue[3]}))})})),(v=c.textureTransformBinds)==null||v.forEach(P=>x(this,null,function*(){T.filter(A=>{var S;let H=(S=this.parser.associations.get(A))==null?void 0:S.materials;return P.material===H}).forEach(A=>{var S,H;M.addBind(new Mt({material:A,offset:new ee.Vector2().fromArray((S=P.offset)!=null?S:[0,0]),scale:new ee.Vector2().fromArray((H=P.scale)!=null?H:[1,1])}))})}))}h.registerExpression(M)}))),h})}_v0Import(e){return x(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 a=new vt,l=o.blendShapeGroups;if(!l)return a;let s=new Set;return yield Promise.all(l.map(u=>x(this,null,function*(){var d;let h=u.presetName,p=h!=null&&Zn.v0v1PresetNameMap[h]||null,m=p!=null?p: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 ${h} has duplicated entries. Ignoring the expression`);return}s.add(m);let c=new gt(m);e.scene.add(c),c.isBinary=(d=u.isBinary)!=null?d:!1,u.binds&&u.binds.forEach(_=>x(this,null,function*(){var E;if(_.mesh===void 0||_.index===void 0)return;let I=[];(E=i.nodes)==null||E.forEach((g,v)=>{g.mesh===_.mesh&&I.push(v)});let y=_.index;yield Promise.all(I.map(g=>x(this,null,function*(){var v;let M=yield Sn(e,g);if(!M.every(T=>Array.isArray(T.morphTargetInfluences)&&y<T.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${u.name} attempts to index ${y}th morph but not found.`);return}c.addBind(new ge({primitives:M,index:y,weight:.01*((v=_.weight)!=null?v:100)}))})))}));let f=u.materialValues;f&&f.length!==0&&f.forEach(_=>{if(_.materialName===void 0||_.propertyName===void 0||_.targetValue===void 0)return;let E=[];e.scene.traverse(y=>{if(y.material){let g=y.material;Array.isArray(g)?E.push(...g.filter(v=>(v.name===_.materialName||v.name===_.materialName+" (Outline)")&&E.indexOf(v)===-1)):g.name===_.materialName&&E.indexOf(g)===-1&&E.push(g)}});let I=_.propertyName;E.forEach(y=>{if(I==="_MainTex_ST"){let v=new ee.Vector2(_.targetValue[0],_.targetValue[1]),M=new ee.Vector2(_.targetValue[2],_.targetValue[3]);M.y=1-M.y-v.y,c.addBind(new Mt({material:y,scale:v,offset:M}));return}let g=Hr[I];if(g){c.addBind(new Et({material:y,type:g,targetValue:new ee.Color().fromArray(_.targetValue),targetAlpha:_.targetValue[3]}));return}console.warn(I+" is not supported")})}),a.registerExpression(c)}))),a})}};qn.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=qn,Vr={None:"none",Block:"block",Blend:"blend"},Lt=class _e{constructor(e,n){this._firstPersonOnlyLayer=_e.DEFAULT_FIRSTPERSON_ONLY_LAYER,this._thirdPersonOnlyLayer=_e.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 _e(this.humanoid,this.meshAnnotations).copy(this)}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}setup({firstPersonOnlyLayer:e=_e.DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:n=_e.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(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(e,n,i,r){let o=0;if(n!=null&&n.length>0)for(let a=0;a<e.length;a+=3){let l=e[a],s=e[a+1],u=e[a+2],d=n[l],h=i[l];if(d[0]>0&&r.includes(h[0])||d[1]>0&&r.includes(h[1])||d[2]>0&&r.includes(h[2])||d[3]>0&&r.includes(h[3]))continue;let p=n[s],m=i[s];if(p[0]>0&&r.includes(m[0])||p[1]>0&&r.includes(m[1])||p[2]>0&&r.includes(m[2])||p[3]>0&&r.includes(m[3]))continue;let c=n[u],f=i[u];c[0]>0&&r.includes(f[0])||c[1]>0&&r.includes(f[1])||c[2]>0&&r.includes(f[2])||c[3]>0&&r.includes(f[3])||(e[o++]=l,e[o++]=s,e[o++]=u)}return o}_createErasedMesh(e,n){let i=new F.SkinnedMesh(e.geometry.clone(),e.material);i.name=`${e.name}(erase)`,i.frustumCulled=e.frustumCulled,i.layers.set(this._firstPersonOnlyLayer);let r=i.geometry,o=r.getAttribute("skinIndex"),a=o instanceof F.GLBufferAttribute?[]:o.array,l=[];for(let f=0;f<a.length;f+=4)l.push([a[f],a[f+1],a[f+2],a[f+3]]);let s=r.getAttribute("skinWeight"),u=s instanceof F.GLBufferAttribute?[]:s.array,d=[];for(let f=0;f<u.length;f+=4)d.push([u[f],u[f+1],u[f+2],u[f+3]]);let h=r.getIndex();if(!h)throw new Error("The geometry doesn't have an index buffer");let p=Array.from(h.array),m=this._excludeTriangles(p,d,l,n),c=[];for(let f=0;f<m;f++)c[f]=p[f];return r.setIndex(c),e.onBeforeRender&&(i.onBeforeRender=e.onBeforeRender),i.bind(new F.Skeleton(e.skeleton.bones,e.skeleton.boneInverses),new F.Matrix4),i}_createHeadlessModelForSkinnedMesh(e,n){let i=[];if(n.skeleton.bones.forEach((o,a)=>{this._isEraseTarget(o)&&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 F.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}};Lt.DEFAULT_FIRSTPERSON_ONLY_LAYER=9;Lt.DEFAULT_THIRDPERSON_ONLY_LAYER=10;var Rt=Lt,Cr=new Set(["1.0","1.0-beta"]),Xe=class{get name(){return"VRMFirstPersonLoaderPlugin"}constructor(t){this.parser=t}afterRoot(t){return x(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 x(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 x(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(!Cr.has(l))return console.warn(`VRMFirstPersonLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let s=a.firstPerson,u=[],d=yield Pn(t);return Array.from(d.entries()).forEach(([h,p])=>{var m,c;let f=(m=s==null?void 0:s.meshAnnotations)==null?void 0:m.find(_=>_.node===h);u.push({meshes:p,type:(c=f==null?void 0:f.type)!=null?c:"auto"})}),new Rt(e,u)})}_v0Import(t,e){return x(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 a=[],l=yield Pn(t);return Array.from(l.entries()).forEach(([s,u])=>{let d=i.nodes[s],h=o.meshAnnotations?o.meshAnnotations.find(p=>p.mesh===d.mesh):void 0;a.push({meshes:u,type:this._convertV0FlagToV1Type(h==null?void 0:h.firstPersonFlag)})}),new Rt(e,a)})}_convertV0FlagToV1Type(t){return t==="FirstPersonOnly"?"firstPersonOnly":t==="ThirdPersonOnly"?"thirdPersonOnly":t==="Both"?"both":"auto"}},Ur={Auto:"auto",Both:"both",ThirdPersonOnly:"thirdPersonOnly",FirstPersonOnly:"firstPersonOnly"},Ln=new Z.Vector3,Hn=new Z.Vector3,Or=new Z.Quaternion,Tt=class extends Z.Group{constructor(t){super(),this.vrmHumanoid=t,this._boneAxesMap=new Map,Object.values(t.humanBones).forEach(e=>{let n=new Z.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(Ln,Or,Hn);let i=Ln.set(.1,.1,.1).divide(Hn);n.matrix.copy(e.node.matrixWorld).scale(i)}),super.updateMatrixWorld(t)}},ke=["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"],Nr={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"},$n={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 ae=new Qe.Vector3,le=new Qe.Quaternion,xt=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&&(ae.copy(i.position),le.copy(i.quaternion),t[n]={position:ae.toArray(),rotation:le.toArray()})}),t}getPose(){let t={};return Object.keys(this.humanBones).forEach(e=>{let n=e,i=this.getBoneNode(n);if(!i)return;ae.set(0,0,0),le.identity();let r=this.restPose[n];r!=null&&r.position&&ae.fromArray(r.position).negate(),r!=null&&r.rotation&&Jn(le.fromArray(r.rotation)),ae.add(i.position),le.premultiply(i.quaternion),t[n]={position:ae.toArray(),rotation:le.toArray()}}),t}setPose(t){Object.entries(t).forEach(([e,n])=>{let i=e,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(ae.fromArray(o.position))),n!=null&&n.rotation&&(r.quaternion.fromArray(n.rotation),o.rotation&&r.quaternion.multiply(le.fromArray(o.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}},mt=new k.Vector3,Br=new k.Quaternion,Dr=new k.Vector3,bn=class Kn extends xt{static _setupTransforms(e){let n=new k.Object3D;n.name="VRMHumanoidRig";let i={},r={},o={},a={};ke.forEach(s=>{var u;let d=e.getBoneNode(s);if(d){let h=new k.Vector3,p=new k.Quaternion;d.updateWorldMatrix(!0,!1),d.matrixWorld.decompose(h,p,mt),i[s]=h,r[s]=p,o[s]=d.quaternion.clone();let m=new k.Quaternion;(u=d.parent)==null||u.matrixWorld.decompose(mt,m,mt),a[s]=m}});let l={};return ke.forEach(s=>{var u;let d=e.getBoneNode(s);if(d){let h=i[s],p=s,m;for(;m==null&&(p=$n[p],p!=null);)m=i[p];let c=new k.Object3D;c.name="Normalized_"+d.name,(p?(u=l[p])==null?void 0:u.node:n).add(c),c.position.copy(h),m&&c.position.sub(m),l[s]={node:c}}}),{rigBones:l,root:n,parentWorldRotations:a,boneRotations:o}}constructor(e){let{rigBones:n,root:i,parentWorldRotations:r,boneRotations:o}=Kn._setupTransforms(e);super(n),this.original=e,this.root=i,this._parentWorldRotations=r,this._boneRotations=o}update(){ke.forEach(e=>{let n=this.original.getBoneNode(e);if(n!=null){let i=this.getBoneNode(e),r=this._parentWorldRotations[e],o=Br.copy(r).invert(),a=this._boneRotations[e];if(n.quaternion.copy(i.quaternion).multiply(r).premultiply(o).multiply(a),e==="hips"){let l=i.getWorldPosition(Dr);n.parent.updateWorldMatrix(!0,!1);let s=n.parent.matrixWorld,u=l.applyMatrix4(s.invert());n.position.copy(u)}}})}},yt=class ei{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 xt(e),this._normalizedHumanBones=new bn(this._rawHumanBones)}copy(e){return this.autoUpdateHumanBones=e.autoUpdateHumanBones,this._rawHumanBones=new xt(e.humanBones),this._normalizedHumanBones=new bn(this._rawHumanBones),this}clone(){return new ei(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()}},ti={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"},Fr=new Set(["1.0","1.0-beta"]),In={leftThumbProximal:"leftThumbMetacarpal",leftThumbIntermediate:"leftThumbProximal",rightThumbProximal:"rightThumbMetacarpal",rightThumbIntermediate:"rightThumbProximal"},Ye=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 x(this,null,function*(){t.userData.vrmHumanoid=yield this._import(t)})}_import(t){return x(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 x(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 o=(n=i.extensions)==null?void 0:n.VRMC_vrm;if(!o)return null;let a=o.specVersion;if(!Fr.has(a))return console.warn(`VRMHumanoidLoaderPlugin: Unknown VRMC_vrm specVersion "${a}"`),null;let l=o.humanoid;if(!l)return null;let s=l.humanBones.leftThumbIntermediate!=null||l.humanBones.rightThumbIntermediate!=null,u={};l.humanBones!=null&&(yield Promise.all(Object.entries(l.humanBones).map(h=>x(this,[h],function*([p,m]){let c=p,f=m.node;if(s){let E=In[c];E!=null&&(c=E)}let _=yield this.parser.getDependency("node",f);if(_==null){console.warn(`A glTF node bound to the humanoid bone ${c} (index = ${f}) does not exist`);return}u[c]={node:_}}))));let d=new yt(this._ensureRequiredBonesExist(u),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(t.scene.add(d.normalizedHumanBonesRoot),this.helperRoot){let h=new Tt(d);this.helperRoot.add(h),h.renderOrder=this.helperRoot.renderOrder}return d})}_v0Import(t){return x(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 o={};r.humanBones!=null&&(yield Promise.all(r.humanBones.map(l=>x(this,null,function*(){let s=l.bone,u=l.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 h=In[s],p=h!=null?h:s;if(o[p]!=null){console.warn(`Multiple bone entries for ${p} detected (index = ${u}), ignoring duplicated entries.`);return}o[p]={node:d}}))));let a=new yt(this._ensureRequiredBonesExist(o),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(t.scene.add(a.normalizedHumanBonesRoot),this.helperRoot){let l=new Tt(a);this.helperRoot.add(l),l.renderOrder=this.helperRoot.renderOrder}return a})}_ensureRequiredBonesExist(t){let e=Object.values(ti).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}},Vn=class extends Ae.BufferGeometry{constructor(){super(),this._currentTheta=0,this._currentRadius=0,this.theta=0,this.radius=0,this._currentTheta=0,this._currentRadius=0,this._attrPos=new Ae.BufferAttribute(new Float32Array(65*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new Ae.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}},kr=class extends te.BufferGeometry{constructor(){super(),this.radius=0,this._currentRadius=0,this.tail=new te.Vector3,this._currentTail=new te.Vector3,this._attrPos=new te.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new te.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}},De=new b.Quaternion,Cn=new b.Quaternion,Se=new b.Vector3,Un=new b.Vector3,On=Math.sqrt(2)/2,Wr=new b.Quaternion(0,0,-On,On),zr=new b.Vector3(0,1,0),ni=class extends b.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.vrmLookAt=t;{let e=new Vn;e.radius=.5;let n=new b.MeshBasicMaterial({color:65280,transparent:!0,opacity:.5,side:b.DoubleSide,depthTest:!1,depthWrite:!1});this._meshPitch=new b.Mesh(e,n),this.add(this._meshPitch)}{let e=new Vn;e.radius=.5;let n=new b.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.5,side:b.DoubleSide,depthTest:!1,depthWrite:!1});this._meshYaw=new b.Mesh(e,n),this.add(this._meshYaw)}{let e=new kr;e.radius=.1;let n=new b.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1});this._lineTarget=new b.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=b.MathUtils.DEG2RAD*this.vrmLookAt.yaw;this._meshYaw.geometry.theta=e,this._meshYaw.geometry.update();let n=b.MathUtils.DEG2RAD*this.vrmLookAt.pitch;this._meshPitch.geometry.theta=n,this._meshPitch.geometry.update(),this.vrmLookAt.getLookAtWorldPosition(Se),this.vrmLookAt.getLookAtWorldQuaternion(De),De.multiply(this.vrmLookAt.getFaceFrontQuaternion(Cn)),this._meshYaw.position.copy(Se),this._meshYaw.quaternion.copy(De),this._meshPitch.position.copy(Se),this._meshPitch.quaternion.copy(De),this._meshPitch.quaternion.multiply(Cn.setFromAxisAngle(zr,e)),this._meshPitch.quaternion.multiply(Wr);let{target:i,autoUpdate:r}=this.vrmLookAt;i!=null&&r&&(i.getWorldPosition(Un).sub(Se),this._lineTarget.geometry.tail.copy(Un),this._lineTarget.geometry.update(),this._lineTarget.position.copy(Se)),super.updateMatrixWorld(t)}},Gr=new Ht.Vector3,jr=new Ht.Vector3;function wt(t,e){return t.matrixWorld.decompose(Gr,e,jr),e}function We(t){return[Math.atan2(-t.z,t.x),Math.atan2(t.y,Math.sqrt(t.x*t.x+t.z*t.z))]}function Nn(t){let e=Math.round(t/2/Math.PI);return t-2*Math.PI*e}var Bn=new C.Vector3(0,0,1),Xr=new C.Vector3,Qr=new C.Vector3,Yr=new C.Vector3,qr=new C.Quaternion,ft=new C.Quaternion,Dn=new C.Quaternion,Zr=new C.Quaternion,_t=new C.Euler,ii=class ri{constructor(e,n){this.offsetFromHeadBone=new C.Vector3,this.autoUpdate=!0,this.faceFront=new C.Vector3(0,0,1),this.humanoid=e,this.applier=n,this._yaw=0,this._pitch=0,this._needsUpdate=!0,this._restHeadWorldQuaternion=this.getLookAtWorldQuaternion(new C.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 C.Euler)}getEuler(e){return e.set(C.MathUtils.DEG2RAD*this._pitch,C.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 ri(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 wt(n,e)}getFaceFrontQuaternion(e){if(this.faceFront.distanceToSquared(Bn)<.01)return e.copy(this._restHeadWorldQuaternion).invert();let[n,i]=We(this.faceFront);return _t.set(0,.5*Math.PI+n,i,"YZX"),e.setFromEuler(_t).premultiply(Zr.copy(this._restHeadWorldQuaternion).invert())}getLookAtWorldDirection(e){return this.getLookAtWorldQuaternion(ft),this.getFaceFrontQuaternion(Dn),e.copy(Bn).applyQuaternion(ft).applyQuaternion(Dn).applyEuler(this.getEuler(_t))}lookAt(e){let n=qr.copy(this._restHeadWorldQuaternion).multiply(Jn(this.getLookAtWorldQuaternion(ft))),i=this.getLookAtWorldPosition(Qr),r=Yr.copy(e).sub(i).applyQuaternion(n).normalize(),[o,a]=We(this.faceFront),[l,s]=We(r),u=Nn(l-o),d=Nn(a-s);this._yaw=C.MathUtils.RAD2DEG*u,this._pitch=C.MathUtils.RAD2DEG*d,this._needsUpdate=!0}update(e){this.target!=null&&this.autoUpdate&&this.lookAt(this.target.getWorldPosition(Xr)),this._needsUpdate&&(this._needsUpdate=!1,this.applier.applyYawPitch(this._yaw,this._pitch))}};ii.EULER_ORDER="YXZ";var oi=ii,$r=new V.Vector3(0,0,1),j=new V.Quaternion,me=new V.Quaternion,B=new V.Euler(0,0,0,"YXZ"),Pe=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 V.Vector3(0,0,1),this._restQuatLeftEye=new V.Quaternion,this._restQuatRightEye=new V.Quaternion,this._restLeftEyeParentWorldQuat=new V.Quaternion,this._restRightEyeParentWorldQuat=new V.Quaternion;let o=this.humanoid.getRawBoneNode("leftEye"),a=this.humanoid.getRawBoneNode("rightEye");o&&(this._restQuatLeftEye.copy(o.quaternion),wt(o.parent,this._restLeftEyeParentWorldQuat)),a&&(this._restQuatRightEye.copy(a.quaternion),wt(a.parent,this._restRightEyeParentWorldQuat))}applyYawPitch(t,e){let n=this.humanoid.getRawBoneNode("leftEye"),i=this.humanoid.getRawBoneNode("rightEye"),r=this.humanoid.getNormalizedBoneNode("leftEye"),o=this.humanoid.getNormalizedBoneNode("rightEye");n&&(e<0?B.x=-V.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-e):B.x=V.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(e),t<0?B.y=-V.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(-t):B.y=V.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(t),j.setFromEuler(B),this._getWorldFaceFrontQuat(me),r.quaternion.copy(me).multiply(j).multiply(me.invert()),j.copy(this._restLeftEyeParentWorldQuat),n.quaternion.copy(r.quaternion).multiply(j).premultiply(j.invert()).multiply(this._restQuatLeftEye)),i&&(e<0?B.x=-V.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-e):B.x=V.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(e),t<0?B.y=-V.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(-t):B.y=V.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(t),j.setFromEuler(B),this._getWorldFaceFrontQuat(me),o.quaternion.copy(me).multiply(j).multiply(me.invert()),j.copy(this._restRightEyeParentWorldQuat),i.quaternion.copy(o.quaternion).multiply(j).premultiply(j.invert()).multiply(this._restQuatRightEye))}lookAt(t){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let e=V.MathUtils.RAD2DEG*t.y,n=V.MathUtils.RAD2DEG*t.x;this.applyYawPitch(e,n)}_getWorldFaceFrontQuat(t){if(this.faceFront.distanceToSquared($r)<.01)return t.identity();let[e,n]=We(this.faceFront);return B.set(0,.5*Math.PI+e,n,"YZX"),t.setFromEuler(B)}};Pe.type="bone";var Ge=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=St.MathUtils.RAD2DEG*t.y,n=St.MathUtils.RAD2DEG*t.x;this.applyYawPitch(e,n)}};Ge.type="expression";var Pt=class{constructor(t,e){this.inputMaxValue=t,this.outputScale=e}map(t){return this.outputScale*Wn(t/this.inputMaxValue)}},Jr=new Set(["1.0","1.0-beta"]),Fe=.01,qe=class{get name(){return"VRMLookAtLoaderPlugin"}constructor(t,e){this.parser=t,this.helperRoot=e==null?void 0:e.helperRoot}afterRoot(t){return x(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 x(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 x(this,null,function*(){var i,r,o;let a=this.parser.json;if(!(((i=a.extensionsUsed)==null?void 0:i.indexOf("VRMC_vrm"))!==-1))return null;let s=(r=a.extensions)==null?void 0:r.VRMC_vrm;if(!s)return null;let u=s.specVersion;if(!Jr.has(u))return console.warn(`VRMLookAtLoaderPlugin: Unknown VRMC_vrm specVersion "${u}"`),null;let d=s.lookAt;if(!d)return null;let h=d.type==="expression"?1:10,p=this._v1ImportRangeMap(d.rangeMapHorizontalInner,h),m=this._v1ImportRangeMap(d.rangeMapHorizontalOuter,h),c=this._v1ImportRangeMap(d.rangeMapVerticalDown,h),f=this._v1ImportRangeMap(d.rangeMapVerticalUp,h),_;d.type==="expression"?_=new Ge(n,p,m,c,f):_=new Pe(e,p,m,c,f);let E=this._importLookAt(e,_);return E.offsetFromHeadBone.fromArray((o=d.offsetFromHeadBone)!=null?o:[0,.06,0]),E})}_v1ImportRangeMap(t,e){var n,i;let r=(n=t==null?void 0:t.inputMaxValue)!=null?n:90,o=(i=t==null?void 0:t.outputScale)!=null?i:e;return r<Fe&&(console.warn("VRMLookAtLoaderPlugin: inputMaxValue of a range map is too small. Consider reviewing the range map!"),r=Fe),new Pt(r,o)}_v0Import(t,e,n){return x(this,null,function*(){var i,r,o,a;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,h=this._v0ImportDegreeMap(u.lookAtHorizontalInner,d),p=this._v0ImportDegreeMap(u.lookAtHorizontalOuter,d),m=this._v0ImportDegreeMap(u.lookAtVerticalDown,d),c=this._v0ImportDegreeMap(u.lookAtVerticalUp,d),f;u.lookAtTypeName==="BlendShape"?f=new Ge(n,h,p,m,c):f=new Pe(e,h,p,m,c);let _=this._importLookAt(e,f);return u.firstPersonBoneOffset?_.offsetFromHeadBone.set((r=u.firstPersonBoneOffset.x)!=null?r:0,(o=u.firstPersonBoneOffset.y)!=null?o:.06,-((a=u.firstPersonBoneOffset.z)!=null?a:0)):_.offsetFromHeadBone.set(0,.06,0),_.faceFront.set(0,0,-1),f instanceof Pe&&f.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 o=(n=t==null?void 0:t.xRange)!=null?n:90,a=(i=t==null?void 0:t.yRange)!=null?i:e;return o<Fe&&(console.warn("VRMLookAtLoaderPlugin: xRange of a degree map is too small. Consider reviewing the degree map!"),o=Fe),new Pt(o,a)}_importLookAt(t,e){let n=new oi(t,e);if(this.helperRoot){let i=new ni(n);this.helperRoot.add(i),i.renderOrder=this.helperRoot.renderOrder}return n}},Kr={Bone:"bone",Expression:"expression"};function eo(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 to=new Set(["1.0","1.0-beta"]),Ze=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 x(this,null,function*(){t.userData.vrmMeta=yield this._import(t)})}_import(t){return x(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 x(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(!to.has(l))return console.warn(`VRMMetaLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let s=a.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 h;return this.needThumbnailImage&&s.thumbnailImage!=null&&(h=(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:h,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(t){return x(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 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(t){return x(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 si.ImageLoader().loadAsync(eo(r,this.parser.options.path)).catch(a=>(console.error(a),console.warn("VRMMetaLoaderPlugin: Failed to load a thumbnail image"),null))})}},$e=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()}},no=class{get name(){return"VRMC_vrm"}constructor(t,e){var n,i,r,o,a;this.parser=t;let l=e==null?void 0:e.helperRoot,s=e==null?void 0:e.autoUpdateHumanBones;this.expressionPlugin=(n=e==null?void 0:e.expressionPlugin)!=null?n:new je(t),this.firstPersonPlugin=(i=e==null?void 0:e.firstPersonPlugin)!=null?i:new Xe(t),this.humanoidPlugin=(r=e==null?void 0:e.humanoidPlugin)!=null?r:new Ye(t,{helperRoot:l,autoUpdateHumanBones:s}),this.lookAtPlugin=(o=e==null?void 0:e.lookAtPlugin)!=null?o:new qe(t,{helperRoot:l}),this.metaPlugin=(a=e==null?void 0:e.metaPlugin)!=null?a:new Ze(t)}afterRoot(t){return x(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 $e({scene:t.scene,expressionManager:t.userData.vrmExpressionManager,firstPerson:t.userData.vrmFirstPerson,humanoid:n,lookAt:t.userData.vrmLookAt,meta:e});t.userData.vrmCore=i}})}};var ve=class extends $e{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 Ke=R(require("three"),1),di=R(require("three"),1),hi=R(require("three"),1),w=R(require("three"),1),pi=R(require("three"),1);var io=Object.defineProperty,ai=Object.getOwnPropertySymbols,ro=Object.prototype.hasOwnProperty,oo=Object.prototype.propertyIsEnumerable,li=(t,e,n)=>e in t?io(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ui=(t,e)=>{for(var n in e||(e={}))ro.call(e,n)&&li(t,n,e[n]);if(ai)for(var n of ai(e))oo.call(e,n)&&li(t,n,e[n]);return t},ue=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),so={"":3e3,srgb:3001};function ao(t,e){parseInt(hi.REVISION,10)>=152?t.colorSpace=e:t.encoding=so[e]}var lo=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 di.Color().fromArray(e),n&&this._materialParams[t].convertSRGBToLinear())}assignTexture(t,e,n){return ue(this,null,function*(){let i=ue(this,null,function*(){e!=null&&(yield this._parser.assignTexture(this._materialParams,t,e),n&&ao(this._materialParams[t],"srgb"))});return this._pendings.push(i),i})}assignTextureByIndex(t,e,n){return ue(this,null,function*(){return this.assignTexture(t,e!=null?{index:e}:void 0,n)})}},uo=`// #define PHONG
|
|
1
|
+
/*! (c) 2019-2025 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
|
|
2
|
+
"use strict";var yr=Object.create;var De=Object.defineProperty;var wr=Object.getOwnPropertyDescriptor;var Sr=Object.getOwnPropertyNames;var Pr=Object.getPrototypeOf,Ar=Object.prototype.hasOwnProperty;var Lr=(t,e)=>{for(var n in e)De(t,n,{get:e[n],enumerable:!0})},Sn=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Sr(e))!Ar.call(t,r)&&r!==n&&De(t,r,{get:()=>e[r],enumerable:!(i=wr(e,r))||i.enumerable});return t};var T=(t,e,n)=>(n=t!=null?yr(Pr(t)):{},Sn(e||!t||!t.__esModule?De(n,"default",{value:t,enumerable:!0}):n,t)),br=t=>Sn(De({},"__esModule",{value:!0}),t);var we=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())});var ls={};Lr(ls,{MToonMaterial:()=>fi,MToonMaterialDebugMode:()=>pi,MToonMaterialLoaderPlugin:()=>Ct,MToonMaterialOutlineWidthMode:()=>Vt,VRM:()=>ve,VRMAimConstraint:()=>Si,VRMCore:()=>Je,VRMCoreLoaderPlugin:()=>io,VRMExpression:()=>vt,VRMExpressionLoaderPlugin:()=>Xe,VRMExpressionManager:()=>Et,VRMExpressionMaterialColorBind:()=>Mt,VRMExpressionMaterialColorType:()=>fe,VRMExpressionMorphTargetBind:()=>_e,VRMExpressionOverrideType:()=>Cr,VRMExpressionPresetName:()=>Ge,VRMExpressionTextureTransformBind:()=>Rt,VRMFirstPerson:()=>Tt,VRMFirstPersonLoaderPlugin:()=>Qe,VRMFirstPersonMeshAnnotationType:()=>Or,VRMHumanBoneList:()=>We,VRMHumanBoneName:()=>Br,VRMHumanBoneParentMap:()=>Jn,VRMHumanoid:()=>wt,VRMHumanoidHelper:()=>xt,VRMHumanoidLoaderPlugin:()=>qe,VRMLoaderPlugin:()=>ut,VRMLookAt:()=>si,VRMLookAtBoneApplier:()=>Pe,VRMLookAtExpressionApplier:()=>je,VRMLookAtHelper:()=>ii,VRMLookAtLoaderPlugin:()=>$e,VRMLookAtRangeMap:()=>At,VRMLookAtTypeName:()=>eo,VRMMetaLoaderPlugin:()=>Ze,VRMNodeConstraint:()=>it,VRMNodeConstraintHelper:()=>tt,VRMNodeConstraintLoaderPlugin:()=>Nt,VRMNodeConstraintManager:()=>Pi,VRMRequiredHumanBoneName:()=>ni,VRMRollConstraint:()=>Li,VRMRotationConstraint:()=>Ai,VRMSpringBoneCollider:()=>st,VRMSpringBoneColliderHelper:()=>ot,VRMSpringBoneColliderShape:()=>at,VRMSpringBoneColliderShapeCapsule:()=>zt,VRMSpringBoneColliderShapePlane:()=>Gt,VRMSpringBoneColliderShapeSphere:()=>Xt,VRMSpringBoneJoint:()=>Oi,VRMSpringBoneJointHelper:()=>Vi,VRMSpringBoneLoaderPlugin:()=>Qt,VRMSpringBoneManager:()=>Wt,VRMUtils:()=>K});module.exports=br(ls);var kn=T(require("three"),1),ee=T(require("three"),1),Lt=T(require("three"),1),Qn=T(require("three"),1),F=T(require("three"),1),$=T(require("three"),1),Ye=T(require("three"),1),k=T(require("three"),1),I=T(require("three"),1),Ae=T(require("three"),1),te=T(require("three"),1),C=T(require("three"),1),Ht=T(require("three"),1),V=T(require("three"),1),Pt=T(require("three"),1),ai=T(require("three"),1);var y=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),vt=class extends kn.Object3D{constructor(t){super(),this.weight=0,this.isBinary=!1,this.overrideBlink="none",this.overrideLookAt="none",this.overrideMouth="none",this._binds=[],this.name=`VRMExpression_${t}`,this.expressionName=t,this.type="VRMExpression",this.visible=!1}get binds(){return this._binds}get overrideBlinkAmount(){return this.overrideBlink==="block"?0<this.outputWeight?1:0:this.overrideBlink==="blend"?this.outputWeight:0}get overrideLookAtAmount(){return this.overrideLookAt==="block"?0<this.outputWeight?1:0:this.overrideLookAt==="blend"?this.outputWeight:0}get overrideMouthAmount(){return this.overrideMouth==="block"?0<this.outputWeight?1:0:this.overrideMouth==="blend"?this.outputWeight:0}get outputWeight(){return this.isBinary?this.weight>.5?1:0:this.weight}addBind(t){this._binds.push(t)}deleteBind(t){let e=this._binds.indexOf(t);e>=0&&this._binds.splice(e,1)}applyWeight(t){var e;let n=this.outputWeight;n*=(e=t==null?void 0:t.multiplier)!=null?e:1,this.isBinary&&n<1&&(n=0),this._binds.forEach(i=>i.applyWeight(n))}clearAppliedWeight(){this._binds.forEach(t=>t.clearAppliedWeight())}};function Wn(t,e,n){var i,r;let o=t.parser.json,a=(i=o.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 s=(r=o.meshes)==null?void 0:r[l];if(s==null)return console.warn(`extractPrimitivesInternal: Attempt to use meshes[${l}] of glTF but the mesh doesn't exist`),null;let u=s.primitives.length,d=[];return n.traverse(h=>{d.length<u&&h.isMesh&&d.push(h)}),d}function Pn(t,e){return y(this,null,function*(){let n=yield t.parser.getDependency("node",e);return Wn(t,e,n)})}function An(t){return y(this,null,function*(){let e=yield t.parser.getDependencies("node"),n=new Map;return e.forEach((i,r)=>{let o=Wn(t,r,i);o!=null&&n.set(r,o)}),n})}var Ge={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 zn(t){return Math.max(Math.min(t,1),0)}var Et=class Gn{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(Ge));return Object.entries(this._expressionMap).forEach(([i,r])=>{n.has(i)&&(e[i]=r)}),e}get customExpressionMap(){let e={},n=new Set(Object.values(Ge));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 Gn().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=zn(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}}},fe={Color:"color",EmissionColor:"emissionColor",ShadeColor:"shadeColor",MatcapColor:"matcapColor",RimColor:"rimColor",OutlineColor:"outlineColor"},Hr={_Color:fe.Color,_EmissionColor:fe.EmissionColor,_ShadeColor:fe.ShadeColor,_RimColor:fe.RimColor,_OutlineColor:fe.OutlineColor},Ir=new Lt.Color,jn=class Xn{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 o=this._initColorBindState(),a=this._initAlphaBindState();this._state={color:o,alpha:a}}applyWeight(e){let{color:n,alpha:i}=this._state;if(n!=null){let{propertyName:r,deltaValue:o}=n,a=this.material[r];a!=null&&a.add(Ir.copy(o).multiplyScalar(e))}if(i!=null){let{propertyName:r,deltaValue:o}=i;this.material[r]!=null&&(this.material[r]+=o*e)}}clearAppliedWeight(){let{color:e,alpha:n}=this._state;if(e!=null){let{propertyName:i,initialValue:r}=e,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 e,n,i;let{material:r,type:o,targetValue:a}=this,l=this._getPropertyNameMap(),s=(n=(e=l==null?void 0:l[o])==null?void 0:e[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(),h=new Lt.Color(a.r-d.r,a.g-d.g,a.b-d.b);return{propertyName:s,initialValue:d,deltaValue:h}}_initAlphaBindState(){var e,n,i;let{material:r,type:o,targetAlpha:a}=this,l=this._getPropertyNameMap(),s=(n=(e=l==null?void 0:l[o])==null?void 0:e[1])!=null?n:null;if(s==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 ${o} but the material or the type does not support alpha.`),null;if(s==null)return null;let u=r[s],d=a-u;return{propertyName:s,initialValue:u,deltaValue:d}}_getPropertyNameMap(){var e,n;return(n=(e=Object.entries(Xn._propertyNameMapMap).find(([i])=>this.material[i]===!0))==null?void 0:e[1])!=null?n:null}};jn._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 Mt=jn,_e=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)})}},Ln=new Qn.Vector2,Yn=class qn{constructor({material:e,scale:n,offset:i}){var r,o;this.material=e,this.scale=n,this.offset=i;let a=(r=Object.entries(qn._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 ${(o=e.name)!=null?o:"(no name)"} but the material is not supported.`),this._properties=[]):(this._properties=[],a.forEach(l=>{var s;let u=(s=e[l])==null?void 0:s.clone();if(!u)return null;e[l]=u;let d=u.offset.clone(),h=u.repeat.clone(),m=i.clone().sub(d),p=n.clone().sub(h);this._properties.push({name:l,initialOffset:d,deltaOffset:m,initialScale:h,deltaScale:p})}))}applyWeight(e){this._properties.forEach(n=>{let i=this.material[n.name];i!==void 0&&(i.offset.add(Ln.copy(n.deltaOffset).multiplyScalar(e)),i.repeat.add(Ln.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))})}};Yn._propertyNamesMap={isMeshStandardMaterial:["map","emissiveMap","bumpMap","normalMap","displacementMap","roughnessMap","metalnessMap","alphaMap"],isMeshBasicMaterial:["map","specularMap","alphaMap"],isMToonMaterial:["map","normalMap","emissiveMap","shadeMultiplyTexture","rimMultiplyTexture","outlineWidthMultiplyTexture","uvAnimationMaskTexture"]};var Rt=Yn,Vr=new Set(["1.0","1.0-beta"]),$n=class Zn{get name(){return"VRMExpressionLoaderPlugin"}constructor(e){this.parser=e}afterRoot(e){return y(this,null,function*(){e.userData.vrmExpressionManager=yield this._import(e)})}_import(e){return y(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 y(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(!Vr.has(l))return console.warn(`VRMExpressionLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let s=a.expressions;if(!s)return null;let u=new Set(Object.values(Ge)),d=new Map;s.preset!=null&&Object.entries(s.preset).forEach(([m,p])=>{if(p!=null){if(!u.has(m)){console.warn(`VRMExpressionLoaderPlugin: Unknown preset name "${m}" detected. Ignoring the expression`);return}d.set(m,p)}}),s.custom!=null&&Object.entries(s.custom).forEach(([m,p])=>{if(u.has(m)){console.warn(`VRMExpressionLoaderPlugin: Custom expression cannot have preset name "${m}". Ignoring the expression`);return}d.set(m,p)});let h=new Et;return yield Promise.all(Array.from(d.entries()).map(m=>y(this,[m],function*([p,c]){var f,g,v,L,x,_,E;let M=new vt(p);if(e.scene.add(M),M.isBinary=(f=c.isBinary)!=null?f:!1,M.overrideBlink=(g=c.overrideBlink)!=null?g:"none",M.overrideLookAt=(v=c.overrideLookAt)!=null?v:"none",M.overrideMouth=(L=c.overrideMouth)!=null?L:"none",(x=c.morphTargetBinds)==null||x.forEach(R=>y(this,null,function*(){var w;if(R.node===void 0||R.index===void 0)return;let b=yield Pn(e,R.node),A=R.index;if(!b.every(P=>Array.isArray(P.morphTargetInfluences)&&A<P.morphTargetInfluences.length)){console.warn(`VRMExpressionLoaderPlugin: ${c.name} attempts to index morph #${A} but not found.`);return}M.addBind(new _e({primitives:b,index:A,weight:(w=R.weight)!=null?w:1}))})),c.materialColorBinds||c.textureTransformBinds){let R=[];e.scene.traverse(w=>{let b=w.material;b&&(Array.isArray(b)?R.push(...b):R.push(b))}),(_=c.materialColorBinds)==null||_.forEach(w=>y(this,null,function*(){R.filter(A=>{var P;let H=(P=this.parser.associations.get(A))==null?void 0:P.materials;return w.material===H}).forEach(A=>{M.addBind(new Mt({material:A,type:w.type,targetValue:new ee.Color().fromArray(w.targetValue),targetAlpha:w.targetValue[3]}))})})),(E=c.textureTransformBinds)==null||E.forEach(w=>y(this,null,function*(){R.filter(A=>{var P;let H=(P=this.parser.associations.get(A))==null?void 0:P.materials;return w.material===H}).forEach(A=>{var P,H;M.addBind(new Rt({material:A,offset:new ee.Vector2().fromArray((P=w.offset)!=null?P:[0,0]),scale:new ee.Vector2().fromArray((H=w.scale)!=null?H:[1,1])}))})}))}h.registerExpression(M)}))),h})}_v0Import(e){return y(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 a=new Et,l=o.blendShapeGroups;if(!l)return a;let s=new Set;return yield Promise.all(l.map(u=>y(this,null,function*(){var d;let h=u.presetName,m=h!=null&&Zn.v0v1PresetNameMap[h]||null,p=m!=null?m:u.name;if(p==null){console.warn("VRMExpressionLoaderPlugin: One of custom expressions has no name. Ignoring the expression");return}if(s.has(p)){console.warn(`VRMExpressionLoaderPlugin: An expression preset ${h} has duplicated entries. Ignoring the expression`);return}s.add(p);let c=new vt(p);e.scene.add(c),c.isBinary=(d=u.isBinary)!=null?d:!1,u.binds&&u.binds.forEach(g=>y(this,null,function*(){var v;if(g.mesh===void 0||g.index===void 0)return;let L=[];(v=i.nodes)==null||v.forEach((_,E)=>{_.mesh===g.mesh&&L.push(E)});let x=g.index;yield Promise.all(L.map(_=>y(this,null,function*(){var E;let M=yield Pn(e,_);if(!M.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}c.addBind(new _e({primitives:M,index:x,weight:.01*((E=g.weight)!=null?E:100)}))})))}));let f=u.materialValues;f&&f.length!==0&&f.forEach(g=>{if(g.materialName===void 0||g.propertyName===void 0||g.targetValue===void 0)return;let v=[];e.scene.traverse(x=>{if(x.material){let _=x.material;Array.isArray(_)?v.push(..._.filter(E=>(E.name===g.materialName||E.name===g.materialName+" (Outline)")&&v.indexOf(E)===-1)):_.name===g.materialName&&v.indexOf(_)===-1&&v.push(_)}});let L=g.propertyName;v.forEach(x=>{if(L==="_MainTex_ST"){let E=new ee.Vector2(g.targetValue[0],g.targetValue[1]),M=new ee.Vector2(g.targetValue[2],g.targetValue[3]);M.y=1-M.y-E.y,c.addBind(new Rt({material:x,scale:E,offset:M}));return}let _=Hr[L];if(_){c.addBind(new Mt({material:x,type:_,targetValue:new ee.Color().fromArray(g.targetValue),targetAlpha:g.targetValue[3]}));return}console.warn(L+" is not supported")})}),a.registerExpression(c)}))),a})}};$n.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 Xe=$n,Cr={None:"none",Block:"block",Blend:"blend"},bt=class ge{constructor(e,n){this._firstPersonOnlyLayer=ge.DEFAULT_FIRSTPERSON_ONLY_LAYER,this._thirdPersonOnlyLayer=ge.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 ge(this.humanoid,this.meshAnnotations).copy(this)}get firstPersonOnlyLayer(){return this._firstPersonOnlyLayer}get thirdPersonOnlyLayer(){return this._thirdPersonOnlyLayer}setup({firstPersonOnlyLayer:e=ge.DEFAULT_FIRSTPERSON_ONLY_LAYER,thirdPersonOnlyLayer:n=ge.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(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(e,n,i,r){let o=0;if(n!=null&&n.length>0)for(let a=0;a<e.length;a+=3){let l=e[a],s=e[a+1],u=e[a+2],d=n[l],h=i[l];if(d[0]>0&&r.includes(h[0])||d[1]>0&&r.includes(h[1])||d[2]>0&&r.includes(h[2])||d[3]>0&&r.includes(h[3]))continue;let m=n[s],p=i[s];if(m[0]>0&&r.includes(p[0])||m[1]>0&&r.includes(p[1])||m[2]>0&&r.includes(p[2])||m[3]>0&&r.includes(p[3]))continue;let c=n[u],f=i[u];c[0]>0&&r.includes(f[0])||c[1]>0&&r.includes(f[1])||c[2]>0&&r.includes(f[2])||c[3]>0&&r.includes(f[3])||(e[o++]=l,e[o++]=s,e[o++]=u)}return o}_createErasedMesh(e,n){let i=new F.SkinnedMesh(e.geometry.clone(),e.material);i.name=`${e.name}(erase)`,i.frustumCulled=e.frustumCulled,i.layers.set(this._firstPersonOnlyLayer);let r=i.geometry,o=r.getAttribute("skinIndex"),a=o instanceof F.GLBufferAttribute?[]:o.array,l=[];for(let f=0;f<a.length;f+=4)l.push([a[f],a[f+1],a[f+2],a[f+3]]);let s=r.getAttribute("skinWeight"),u=s instanceof F.GLBufferAttribute?[]:s.array,d=[];for(let f=0;f<u.length;f+=4)d.push([u[f],u[f+1],u[f+2],u[f+3]]);let h=r.getIndex();if(!h)throw new Error("The geometry doesn't have an index buffer");let m=Array.from(h.array),p=this._excludeTriangles(m,d,l,n),c=[];for(let f=0;f<p;f++)c[f]=m[f];return r.setIndex(c),e.onBeforeRender&&(i.onBeforeRender=e.onBeforeRender),i.bind(new F.Skeleton(e.skeleton.bones,e.skeleton.boneInverses),new F.Matrix4),i}_createHeadlessModelForSkinnedMesh(e,n){let i=[];if(n.skeleton.bones.forEach((o,a)=>{this._isEraseTarget(o)&&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 F.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}};bt.DEFAULT_FIRSTPERSON_ONLY_LAYER=9;bt.DEFAULT_THIRDPERSON_ONLY_LAYER=10;var Tt=bt,Ur=new Set(["1.0","1.0-beta"]),Qe=class{get name(){return"VRMFirstPersonLoaderPlugin"}constructor(t){this.parser=t}afterRoot(t){return y(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 y(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 y(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(!Ur.has(l))return console.warn(`VRMFirstPersonLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let s=a.firstPerson,u=[],d=yield An(t);return Array.from(d.entries()).forEach(([h,m])=>{var p,c;let f=(p=s==null?void 0:s.meshAnnotations)==null?void 0:p.find(g=>g.node===h);u.push({meshes:m,type:(c=f==null?void 0:f.type)!=null?c:"auto"})}),new Tt(e,u)})}_v0Import(t,e){return y(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 a=[],l=yield An(t);return Array.from(l.entries()).forEach(([s,u])=>{let d=i.nodes[s],h=o.meshAnnotations?o.meshAnnotations.find(m=>m.mesh===d.mesh):void 0;a.push({meshes:u,type:this._convertV0FlagToV1Type(h==null?void 0:h.firstPersonFlag)})}),new Tt(e,a)})}_convertV0FlagToV1Type(t){return t==="FirstPersonOnly"?"firstPersonOnly":t==="ThirdPersonOnly"?"thirdPersonOnly":t==="Both"?"both":"auto"}},Or={Auto:"auto",Both:"both",ThirdPersonOnly:"thirdPersonOnly",FirstPersonOnly:"firstPersonOnly"},bn=new $.Vector3,Hn=new $.Vector3,Nr=new $.Quaternion,xt=class extends $.Group{constructor(t){super(),this.vrmHumanoid=t,this._boneAxesMap=new Map,Object.values(t.humanBones).forEach(e=>{let n=new $.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(bn,Nr,Hn);let i=bn.set(.1,.1,.1).divide(Hn);n.matrix.copy(e.node.matrixWorld).scale(i)}),super.updateMatrixWorld(t)}},We=["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"],Br={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"},Jn={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 Kn(t){return t.invert?t.invert():t.inverse(),t}var ae=new Ye.Vector3,le=new Ye.Quaternion,yt=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&&(ae.copy(i.position),le.copy(i.quaternion),t[n]={position:ae.toArray(),rotation:le.toArray()})}),t}getPose(){let t={};return Object.keys(this.humanBones).forEach(e=>{let n=e,i=this.getBoneNode(n);if(!i)return;ae.set(0,0,0),le.identity();let r=this.restPose[n];r!=null&&r.position&&ae.fromArray(r.position).negate(),r!=null&&r.rotation&&Kn(le.fromArray(r.rotation)),ae.add(i.position),le.premultiply(i.quaternion),t[n]={position:ae.toArray(),rotation:le.toArray()}}),t}setPose(t){Object.entries(t).forEach(([e,n])=>{let i=e,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(ae.fromArray(o.position))),n!=null&&n.rotation&&(r.quaternion.fromArray(n.rotation),o.rotation&&r.quaternion.multiply(le.fromArray(o.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}},ft=new k.Vector3,Dr=new k.Quaternion,Fr=new k.Vector3,In=class ei extends yt{static _setupTransforms(e){let n=new k.Object3D;n.name="VRMHumanoidRig";let i={},r={},o={},a={};We.forEach(s=>{var u;let d=e.getBoneNode(s);if(d){let h=new k.Vector3,m=new k.Quaternion;d.updateWorldMatrix(!0,!1),d.matrixWorld.decompose(h,m,ft),i[s]=h,r[s]=m,o[s]=d.quaternion.clone();let p=new k.Quaternion;(u=d.parent)==null||u.matrixWorld.decompose(ft,p,ft),a[s]=p}});let l={};return We.forEach(s=>{var u;let d=e.getBoneNode(s);if(d){let h=i[s],m=s,p;for(;p==null&&(m=Jn[m],m!=null);)p=i[m];let c=new k.Object3D;c.name="Normalized_"+d.name,(m?(u=l[m])==null?void 0:u.node:n).add(c),c.position.copy(h),p&&c.position.sub(p),l[s]={node:c}}}),{rigBones:l,root:n,parentWorldRotations:a,boneRotations:o}}constructor(e){let{rigBones:n,root:i,parentWorldRotations:r,boneRotations:o}=ei._setupTransforms(e);super(n),this.original=e,this.root=i,this._parentWorldRotations=r,this._boneRotations=o}update(){We.forEach(e=>{let n=this.original.getBoneNode(e);if(n!=null){let i=this.getBoneNode(e),r=this._parentWorldRotations[e],o=Dr.copy(r).invert(),a=this._boneRotations[e];if(n.quaternion.copy(i.quaternion).multiply(r).premultiply(o).multiply(a),e==="hips"){let l=i.getWorldPosition(Fr);n.parent.updateWorldMatrix(!0,!1);let s=n.parent.matrixWorld,u=l.applyMatrix4(s.invert());n.position.copy(u)}}})}},wt=class ti{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 yt(e),this._normalizedHumanBones=new In(this._rawHumanBones)}copy(e){return this.autoUpdateHumanBones=e.autoUpdateHumanBones,this._rawHumanBones=new yt(e.humanBones),this._normalizedHumanBones=new In(this._rawHumanBones),this}clone(){return new ti(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()}},ni={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"]),Vn={leftThumbProximal:"leftThumbMetacarpal",leftThumbIntermediate:"leftThumbProximal",rightThumbProximal:"rightThumbMetacarpal",rightThumbIntermediate:"rightThumbProximal"},qe=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 y(this,null,function*(){t.userData.vrmHumanoid=yield this._import(t)})}_import(t){return y(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 y(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 o=(n=i.extensions)==null?void 0:n.VRMC_vrm;if(!o)return null;let a=o.specVersion;if(!kr.has(a))return console.warn(`VRMHumanoidLoaderPlugin: Unknown VRMC_vrm specVersion "${a}"`),null;let l=o.humanoid;if(!l)return null;let s=l.humanBones.leftThumbIntermediate!=null||l.humanBones.rightThumbIntermediate!=null,u={};l.humanBones!=null&&(yield Promise.all(Object.entries(l.humanBones).map(h=>y(this,[h],function*([m,p]){let c=m,f=p.node;if(s){let v=Vn[c];v!=null&&(c=v)}let g=yield this.parser.getDependency("node",f);if(g==null){console.warn(`A glTF node bound to the humanoid bone ${c} (index = ${f}) does not exist`);return}u[c]={node:g}}))));let d=new wt(this._ensureRequiredBonesExist(u),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(t.scene.add(d.normalizedHumanBonesRoot),this.helperRoot){let h=new xt(d);this.helperRoot.add(h),h.renderOrder=this.helperRoot.renderOrder}return d})}_v0Import(t){return y(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 o={};r.humanBones!=null&&(yield Promise.all(r.humanBones.map(l=>y(this,null,function*(){let s=l.bone,u=l.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 h=Vn[s],m=h!=null?h:s;if(o[m]!=null){console.warn(`Multiple bone entries for ${m} detected (index = ${u}), ignoring duplicated entries.`);return}o[m]={node:d}}))));let a=new wt(this._ensureRequiredBonesExist(o),{autoUpdateHumanBones:this.autoUpdateHumanBones});if(t.scene.add(a.normalizedHumanBonesRoot),this.helperRoot){let l=new xt(a);this.helperRoot.add(l),l.renderOrder=this.helperRoot.renderOrder}return a})}_ensureRequiredBonesExist(t){let e=Object.values(ni).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}},Cn=class extends Ae.BufferGeometry{constructor(){super(),this._currentTheta=0,this._currentRadius=0,this.theta=0,this.radius=0,this._currentTheta=0,this._currentRadius=0,this._attrPos=new Ae.BufferAttribute(new Float32Array(65*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new Ae.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}},Wr=class extends te.BufferGeometry{constructor(){super(),this.radius=0,this._currentRadius=0,this.tail=new te.Vector3,this._currentTail=new te.Vector3,this._attrPos=new te.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new te.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}},Fe=new I.Quaternion,Un=new I.Quaternion,Se=new I.Vector3,On=new I.Vector3,Nn=Math.sqrt(2)/2,zr=new I.Quaternion(0,0,-Nn,Nn),Gr=new I.Vector3(0,1,0),ii=class extends I.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.vrmLookAt=t;{let e=new Cn;e.radius=.5;let n=new I.MeshBasicMaterial({color:65280,transparent:!0,opacity:.5,side:I.DoubleSide,depthTest:!1,depthWrite:!1});this._meshPitch=new I.Mesh(e,n),this.add(this._meshPitch)}{let e=new Cn;e.radius=.5;let n=new I.MeshBasicMaterial({color:16711680,transparent:!0,opacity:.5,side:I.DoubleSide,depthTest:!1,depthWrite:!1});this._meshYaw=new I.Mesh(e,n),this.add(this._meshYaw)}{let e=new Wr;e.radius=.1;let n=new I.LineBasicMaterial({color:16777215,depthTest:!1,depthWrite:!1});this._lineTarget=new I.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=I.MathUtils.DEG2RAD*this.vrmLookAt.yaw;this._meshYaw.geometry.theta=e,this._meshYaw.geometry.update();let n=I.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(Un)),this._meshYaw.position.copy(Se),this._meshYaw.quaternion.copy(Fe),this._meshPitch.position.copy(Se),this._meshPitch.quaternion.copy(Fe),this._meshPitch.quaternion.multiply(Un.setFromAxisAngle(Gr,e)),this._meshPitch.quaternion.multiply(zr);let{target:i,autoUpdate:r}=this.vrmLookAt;i!=null&&r&&(i.getWorldPosition(On).sub(Se),this._lineTarget.geometry.tail.copy(On),this._lineTarget.geometry.update(),this._lineTarget.position.copy(Se)),super.updateMatrixWorld(t)}},jr=new Ht.Vector3,Xr=new Ht.Vector3;function St(t,e){return t.matrixWorld.decompose(jr,e,Xr),e}function ze(t){return[Math.atan2(-t.z,t.x),Math.atan2(t.y,Math.sqrt(t.x*t.x+t.z*t.z))]}function Bn(t){let e=Math.round(t/2/Math.PI);return t-2*Math.PI*e}var Dn=new C.Vector3(0,0,1),Qr=new C.Vector3,Yr=new C.Vector3,qr=new C.Vector3,$r=new C.Quaternion,gt=new C.Quaternion,Fn=new C.Quaternion,Zr=new C.Quaternion,_t=new C.Euler,ri=class oi{constructor(e,n){this.offsetFromHeadBone=new C.Vector3,this.autoUpdate=!0,this.faceFront=new C.Vector3(0,0,1),this.humanoid=e,this.applier=n,this._yaw=0,this._pitch=0,this._needsUpdate=!0,this._restHeadWorldQuaternion=this.getLookAtWorldQuaternion(new C.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 C.Euler)}getEuler(e){return e.set(C.MathUtils.DEG2RAD*this._pitch,C.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 oi(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 St(n,e)}getFaceFrontQuaternion(e){if(this.faceFront.distanceToSquared(Dn)<.01)return e.copy(this._restHeadWorldQuaternion).invert();let[n,i]=ze(this.faceFront);return _t.set(0,.5*Math.PI+n,i,"YZX"),e.setFromEuler(_t).premultiply(Zr.copy(this._restHeadWorldQuaternion).invert())}getLookAtWorldDirection(e){return this.getLookAtWorldQuaternion(gt),this.getFaceFrontQuaternion(Fn),e.copy(Dn).applyQuaternion(gt).applyQuaternion(Fn).applyEuler(this.getEuler(_t))}lookAt(e){let n=$r.copy(this._restHeadWorldQuaternion).multiply(Kn(this.getLookAtWorldQuaternion(gt))),i=this.getLookAtWorldPosition(Yr),r=qr.copy(e).sub(i).applyQuaternion(n).normalize(),[o,a]=ze(this.faceFront),[l,s]=ze(r),u=Bn(l-o),d=Bn(a-s);this._yaw=C.MathUtils.RAD2DEG*u,this._pitch=C.MathUtils.RAD2DEG*d,this._needsUpdate=!0}update(e){this.target!=null&&this.autoUpdate&&this.lookAt(this.target.getWorldPosition(Qr)),this._needsUpdate&&(this._needsUpdate=!1,this.applier.applyYawPitch(this._yaw,this._pitch))}};ri.EULER_ORDER="YXZ";var si=ri,Jr=new V.Vector3(0,0,1),j=new V.Quaternion,me=new V.Quaternion,B=new V.Euler(0,0,0,"YXZ"),Pe=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 V.Vector3(0,0,1),this._restQuatLeftEye=new V.Quaternion,this._restQuatRightEye=new V.Quaternion,this._restLeftEyeParentWorldQuat=new V.Quaternion,this._restRightEyeParentWorldQuat=new V.Quaternion;let o=this.humanoid.getRawBoneNode("leftEye"),a=this.humanoid.getRawBoneNode("rightEye");o&&(this._restQuatLeftEye.copy(o.quaternion),St(o.parent,this._restLeftEyeParentWorldQuat)),a&&(this._restQuatRightEye.copy(a.quaternion),St(a.parent,this._restRightEyeParentWorldQuat))}applyYawPitch(t,e){let n=this.humanoid.getRawBoneNode("leftEye"),i=this.humanoid.getRawBoneNode("rightEye"),r=this.humanoid.getNormalizedBoneNode("leftEye"),o=this.humanoid.getNormalizedBoneNode("rightEye");n&&(e<0?B.x=-V.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-e):B.x=V.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(e),t<0?B.y=-V.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(-t):B.y=V.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(t),j.setFromEuler(B),this._getWorldFaceFrontQuat(me),r.quaternion.copy(me).multiply(j).multiply(me.invert()),j.copy(this._restLeftEyeParentWorldQuat),n.quaternion.copy(r.quaternion).multiply(j).premultiply(j.invert()).multiply(this._restQuatLeftEye)),i&&(e<0?B.x=-V.MathUtils.DEG2RAD*this.rangeMapVerticalDown.map(-e):B.x=V.MathUtils.DEG2RAD*this.rangeMapVerticalUp.map(e),t<0?B.y=-V.MathUtils.DEG2RAD*this.rangeMapHorizontalOuter.map(-t):B.y=V.MathUtils.DEG2RAD*this.rangeMapHorizontalInner.map(t),j.setFromEuler(B),this._getWorldFaceFrontQuat(me),o.quaternion.copy(me).multiply(j).multiply(me.invert()),j.copy(this._restRightEyeParentWorldQuat),i.quaternion.copy(o.quaternion).multiply(j).premultiply(j.invert()).multiply(this._restQuatRightEye))}lookAt(t){console.warn("VRMLookAtBoneApplier: lookAt() is deprecated. use apply() instead.");let e=V.MathUtils.RAD2DEG*t.y,n=V.MathUtils.RAD2DEG*t.x;this.applyYawPitch(e,n)}_getWorldFaceFrontQuat(t){if(this.faceFront.distanceToSquared(Jr)<.01)return t.identity();let[e,n]=ze(this.faceFront);return B.set(0,.5*Math.PI+e,n,"YZX"),t.setFromEuler(B)}};Pe.type="bone";var je=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=Pt.MathUtils.RAD2DEG*t.y,n=Pt.MathUtils.RAD2DEG*t.x;this.applyYawPitch(e,n)}};je.type="expression";var At=class{constructor(t,e){this.inputMaxValue=t,this.outputScale=e}map(t){return this.outputScale*zn(t/this.inputMaxValue)}},Kr=new Set(["1.0","1.0-beta"]),ke=.01,$e=class{get name(){return"VRMLookAtLoaderPlugin"}constructor(t,e){this.parser=t,this.helperRoot=e==null?void 0:e.helperRoot}afterRoot(t){return y(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 y(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 y(this,null,function*(){var i,r,o;let a=this.parser.json;if(!(((i=a.extensionsUsed)==null?void 0:i.indexOf("VRMC_vrm"))!==-1))return null;let s=(r=a.extensions)==null?void 0:r.VRMC_vrm;if(!s)return null;let u=s.specVersion;if(!Kr.has(u))return console.warn(`VRMLookAtLoaderPlugin: Unknown VRMC_vrm specVersion "${u}"`),null;let d=s.lookAt;if(!d)return null;let h=d.type==="expression"?1:10,m=this._v1ImportRangeMap(d.rangeMapHorizontalInner,h),p=this._v1ImportRangeMap(d.rangeMapHorizontalOuter,h),c=this._v1ImportRangeMap(d.rangeMapVerticalDown,h),f=this._v1ImportRangeMap(d.rangeMapVerticalUp,h),g;d.type==="expression"?g=new je(n,m,p,c,f):g=new Pe(e,m,p,c,f);let v=this._importLookAt(e,g);return v.offsetFromHeadBone.fromArray((o=d.offsetFromHeadBone)!=null?o:[0,.06,0]),v})}_v1ImportRangeMap(t,e){var n,i;let r=(n=t==null?void 0:t.inputMaxValue)!=null?n:90,o=(i=t==null?void 0:t.outputScale)!=null?i:e;return r<ke&&(console.warn("VRMLookAtLoaderPlugin: inputMaxValue of a range map is too small. Consider reviewing the range map!"),r=ke),new At(r,o)}_v0Import(t,e,n){return y(this,null,function*(){var i,r,o,a;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,h=this._v0ImportDegreeMap(u.lookAtHorizontalInner,d),m=this._v0ImportDegreeMap(u.lookAtHorizontalOuter,d),p=this._v0ImportDegreeMap(u.lookAtVerticalDown,d),c=this._v0ImportDegreeMap(u.lookAtVerticalUp,d),f;u.lookAtTypeName==="BlendShape"?f=new je(n,h,m,p,c):f=new Pe(e,h,m,p,c);let g=this._importLookAt(e,f);return u.firstPersonBoneOffset?g.offsetFromHeadBone.set((r=u.firstPersonBoneOffset.x)!=null?r:0,(o=u.firstPersonBoneOffset.y)!=null?o:.06,-((a=u.firstPersonBoneOffset.z)!=null?a:0)):g.offsetFromHeadBone.set(0,.06,0),g.faceFront.set(0,0,-1),f instanceof Pe&&f.faceFront.set(0,0,-1),g})}_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 o=(n=t==null?void 0:t.xRange)!=null?n:90,a=(i=t==null?void 0:t.yRange)!=null?i:e;return o<ke&&(console.warn("VRMLookAtLoaderPlugin: xRange of a degree map is too small. Consider reviewing the degree map!"),o=ke),new At(o,a)}_importLookAt(t,e){let n=new si(t,e);if(this.helperRoot){let i=new ii(n);this.helperRoot.add(i),i.renderOrder=this.helperRoot.renderOrder}return n}},eo={Bone:"bone",Expression:"expression"};function to(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 no=new Set(["1.0","1.0-beta"]),Ze=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 y(this,null,function*(){t.userData.vrmMeta=yield this._import(t)})}_import(t){return y(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 y(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(!no.has(l))return console.warn(`VRMMetaLoaderPlugin: Unknown VRMC_vrm specVersion "${l}"`),null;let s=a.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 h;return this.needThumbnailImage&&s.thumbnailImage!=null&&(h=(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:h,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(t){return y(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 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(t){return y(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 ai.ImageLoader().loadAsync(to(r,this.parser.options.path)).catch(a=>(console.error(a),console.warn("VRMMetaLoaderPlugin: Failed to load a thumbnail image"),null))})}},Je=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()}},io=class{get name(){return"VRMC_vrm"}constructor(t,e){var n,i,r,o,a;this.parser=t;let l=e==null?void 0:e.helperRoot,s=e==null?void 0:e.autoUpdateHumanBones;this.expressionPlugin=(n=e==null?void 0:e.expressionPlugin)!=null?n:new Xe(t),this.firstPersonPlugin=(i=e==null?void 0:e.firstPersonPlugin)!=null?i:new Qe(t),this.humanoidPlugin=(r=e==null?void 0:e.humanoidPlugin)!=null?r:new qe(t,{helperRoot:l,autoUpdateHumanBones:s}),this.lookAtPlugin=(o=e==null?void 0:e.lookAtPlugin)!=null?o:new $e(t,{helperRoot:l}),this.metaPlugin=(a=e==null?void 0:e.metaPlugin)!=null?a:new Ze(t)}afterRoot(t){return y(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 Je({scene:t.scene,expressionManager:t.userData.vrmExpressionManager,firstPerson:t.userData.vrmFirstPerson,humanoid:n,lookAt:t.userData.vrmLookAt,meta:e});t.userData.vrmCore=i}})}};var ve=class extends Je{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 et=T(require("three"),1),hi=T(require("three"),1),ci=T(require("three"),1),S=T(require("three"),1),mi=T(require("three"),1);var ro=Object.defineProperty,li=Object.getOwnPropertySymbols,oo=Object.prototype.hasOwnProperty,so=Object.prototype.propertyIsEnumerable,ui=(t,e,n)=>e in t?ro(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,di=(t,e)=>{for(var n in e||(e={}))oo.call(e,n)&&ui(t,n,e[n]);if(li)for(var n of li(e))so.call(e,n)&&ui(t,n,e[n]);return t},ue=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),ao={"":3e3,srgb:3001};function lo(t,e){parseInt(ci.REVISION,10)>=152?t.colorSpace=e:t.encoding=ao[e]}var uo=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 hi.Color().fromArray(e),n&&this._materialParams[t].convertSRGBToLinear())}assignTexture(t,e,n){return ue(this,null,function*(){let i=ue(this,null,function*(){e!=null&&(yield this._parser.assignTexture(this._materialParams,t,e),n&&lo(this._materialParams[t],"srgb"))});return this._pendings.push(i),i})}assignTextureByIndex(t,e,n){return ue(this,null,function*(){return this.assignTexture(t,e!=null?{index:e}:void 0,n)})}},ho=`// #define PHONG
|
|
3
3
|
|
|
4
4
|
varying vec3 vViewPosition;
|
|
5
5
|
|
|
@@ -117,7 +117,7 @@ void main() {
|
|
|
117
117
|
#include <shadowmap_vertex>
|
|
118
118
|
#include <fog_vertex>
|
|
119
119
|
|
|
120
|
-
}`,
|
|
120
|
+
}`,co=`// #define PHONG
|
|
121
121
|
|
|
122
122
|
uniform vec3 litFactor;
|
|
123
123
|
|
|
@@ -919,54 +919,54 @@ void main() {
|
|
|
919
919
|
gl_FragColor = vec4( col, diffuseColor.a );
|
|
920
920
|
postCorrection();
|
|
921
921
|
}
|
|
922
|
-
`,
|
|
922
|
+
`,pi={None:"none",Normal:"normal",LitShadeRate:"litShadeRate",UV:"uv"},Vt={None:"none",WorldCoordinates:"worldCoordinates",ScreenCoordinates:"screenCoordinates"},po={3e3:"",3001:"srgb"};function It(t){return parseInt(mi.REVISION,10)>=152?t.colorSpace:po[t.encoding]}var fi=class extends S.ShaderMaterial{constructor(t={}){var e;super({vertexShader:ho,fragmentShader:co}),this.uvAnimationScrollXSpeedFactor=0,this.uvAnimationScrollYSpeedFactor=0,this.uvAnimationRotationSpeedFactor=0,this.fog=!0,this.normalMapType=S.TangentSpaceNormalMap,this._ignoreVertexColor=!0,this._v0CompatShade=!1,this._debugMode=pi.None,this._outlineWidthMode=Vt.None,this._isOutline=!1,t.transparentWithZWrite&&(t.depthWrite=!0),delete t.transparentWithZWrite,t.fog=!0,t.lights=!0,t.clipping=!0,this.uniforms=S.UniformsUtils.merge([S.UniformsLib.common,S.UniformsLib.normalmap,S.UniformsLib.emissivemap,S.UniformsLib.fog,S.UniformsLib.lights,{litFactor:{value:new S.Color(1,1,1)},mapUvTransform:{value:new S.Matrix3},colorAlpha:{value:1},normalMapUvTransform:{value:new S.Matrix3},shadeColorFactor:{value:new S.Color(0,0,0)},shadeMultiplyTexture:{value:null},shadeMultiplyTextureUvTransform:{value:new S.Matrix3},shadingShiftFactor:{value:0},shadingShiftTexture:{value:null},shadingShiftTextureUvTransform:{value:new S.Matrix3},shadingShiftTextureScale:{value:1},shadingToonyFactor:{value:.9},giEqualizationFactor:{value:.9},matcapFactor:{value:new S.Color(1,1,1)},matcapTexture:{value:null},matcapTextureUvTransform:{value:new S.Matrix3},parametricRimColorFactor:{value:new S.Color(0,0,0)},rimMultiplyTexture:{value:null},rimMultiplyTextureUvTransform:{value:new S.Matrix3},rimLightingMixFactor:{value:1},parametricRimFresnelPowerFactor:{value:5},parametricRimLiftFactor:{value:0},emissive:{value:new S.Color(0,0,0)},emissiveIntensity:{value:1},emissiveMapUvTransform:{value:new S.Matrix3},outlineWidthMultiplyTexture:{value:null},outlineWidthMultiplyTextureUvTransform:{value:new S.Matrix3},outlineWidthFactor:{value:0},outlineColorFactor:{value:new S.Color(0,0,0)},outlineLightingMixFactor:{value:1},uvAnimationMaskTexture:{value:null},uvAnimationMaskTextureUvTransform:{value:new S.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:${It(this.matcapTexture)}`:"",this.shadeMultiplyTexture?`shadeMultiplyTextureColorSpace:${It(this.shadeMultiplyTexture)}`:"",this.rimMultiplyTexture?`rimMultiplyTextureColorSpace:${It(this.rimMultiplyTexture)}`:""].join(","),this.onBeforeCompile=n=>{let i=parseInt(S.REVISION,10),r=Object.entries(di(di({},this._generateDefines()),this.defines)).filter(([o,a])=>!!a).map(([o,a])=>`#define ${o} ${a}`).join(`
|
|
923
923
|
`)+`
|
|
924
|
-
`;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(w.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_SCREEN:this._isOutline&&this._outlineWidthMode===It.ScreenCoordinates}}_updateTextureMatrix(t,e){t.value&&(t.value.matrixAutoUpdate&&t.value.updateMatrix(),e.value.copy(t.value.matrix))}},po=new Set(["1.0","1.0-beta"]),fi=class Je{get name(){return Je.EXTENSION_NAME}constructor(e,n={}){var i,r,o,a;this.parser=e,this.materialType=(i=n.materialType)!=null?i:mi,this.renderOrderOffset=(r=n.renderOrderOffset)!=null?r:0,this.v0CompatShade=(o=n.v0CompatShade)!=null?o:!1,this.debugMode=(a=n.debugMode)!=null?a:"none",this._mToonMaterialSet=new Set}beforeRoot(){return ue(this,null,function*(){this._removeUnlitExtensionIfMToonExists()})}afterRoot(e){return ue(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 ue(this,null,function*(){var n;let i=this.parser,o=(n=i.json.meshes)==null?void 0:n[e];if(o==null)throw new Error(`MToonMaterialLoaderPlugin: Attempt to use meshes[${e}] of glTF but the mesh doesn't exist`);let a=o.primitives,l=yield i.loadMesh(e);if(a.length===1){let s=l,u=a[0].material;u!=null&&this._setupPrimitive(s,u)}else{let s=l;for(let u=0;u<a.length;u++){let d=s.children[u],h=a[u].material;h!=null&&this._setupPrimitive(d,h)}}return l})}_removeUnlitExtensionIfMToonExists(){let i=this.parser.json.materials;i==null||i.map((r,o)=>{var a;this._getMToonExtension(o)&&((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 s=l.specVersion;if(!po.has(s)){console.warn(`MToonMaterialLoaderPlugin: Unknown ${Je.EXTENSION_NAME} specVersion "${s}"`);return}return l}_extendMaterialParams(e,n){return ue(this,null,function*(){var i;delete n.metalness,delete n.roughness;let r=new lo(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 Ke.Material)||!this._shouldGenerateOutline(n))return;e.material=[n];let i=n.clone();i.name+=" (Outline)",i.isOutline=!0,i.side=Ke.BackSide,e.material.push(i);let r=e.geometry,o=r.index?r.index.count:r.attributes.position.count/3;r.addGroup(0,o,0),r.addGroup(0,o,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)}};fi.EXTENSION_NAME="VRMC_materials_mtoon";var Vt=fi;var mo=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),_i=class Ct{get name(){return Ct.EXTENSION_NAME}constructor(e){this.parser=e}extendMaterialParams(e,n){return mo(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[Ct.EXTENSION_NAME];if(l!=null)return l}};_i.EXTENSION_NAME="VRMC_materials_hdr_emissiveMultiplier";var gi=_i;var Ri=R(require("three"),1);var fo=Object.defineProperty,_o=Object.defineProperties,go=Object.getOwnPropertyDescriptors,vi=Object.getOwnPropertySymbols,vo=Object.prototype.hasOwnProperty,Eo=Object.prototype.propertyIsEnumerable,Ei=(t,e,n)=>e in t?fo(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,X=(t,e)=>{for(var n in e||(e={}))vo.call(e,n)&&Ei(t,n,e[n]);if(vi)for(var n of vi(e))Eo.call(e,n)&&Ei(t,n,e[n]);return t},Mi=(t,e)=>_o(t,go(e)),Mo=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())});function Ee(t){return Math.pow(t,2.2)}var Ti=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 Mo(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,o)=>{var a,l;let s=(a=e.materials)==null?void 0:a[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);e.materials[o]=u}else if((l=r.shader)!=null&&l.startsWith("VRM/Unlit")){let u=this._parseV0UnlitProperties(r,s);e.materials[o]=u}else r.shader==="VRM_USE_GLTFSHADER"||console.warn(`VRMMaterialsV0CompatPlugin: Unknown shader: ${r.shader}`)}))})}_parseV0MToonProperties(t,e){var n,i,r,o,a,l,s,u,d,h,p,m,c,f,_,E,I,y,g,v,M,T,P,L,A,S,H,W,z,xe,q,G,pe,ye,O,Qt,Yt,qt,Zt,$t,Jt,Kt,en,tn,nn,rn,on,sn,an,ln,un,dn,hn,cn,pn;let mn=(i=(n=t.keywordMap)==null?void 0:n._ALPHABLEND_ON)!=null?i:!1,Qi=((r=t.floatProperties)==null?void 0:r._ZWrite)===1&&mn,Yi=this._v0ParseRenderQueue(t),fn=(a=(o=t.keywordMap)==null?void 0:o._ALPHATEST_ON)!=null?a:!1,qi=mn?"BLEND":fn?"MASK":"OPAQUE",Zi=fn?(s=(l=t.floatProperties)==null?void 0:l._Cutoff)!=null?s:.5:void 0,$i=((d=(u=t.floatProperties)==null?void 0:u._CullMode)!=null?d:2)===0,se=this._portTextureTransform(t),Ji=((p=(h=t.vectorProperties)==null?void 0:h._Color)!=null?p:[1,1,1,1]).map((yn,Tr)=>Tr===3?yn:Ee(yn)),_n=(m=t.textureProperties)==null?void 0:m._MainTex,Ki=_n!=null?{index:_n,extensions:X({},se)}:void 0,er=(f=(c=t.floatProperties)==null?void 0:c._BumpScale)!=null?f:1,gn=(_=t.textureProperties)==null?void 0:_._BumpMap,tr=gn!=null?{index:gn,scale:er,extensions:X({},se)}:void 0,nr=((I=(E=t.vectorProperties)==null?void 0:E._EmissionColor)!=null?I:[0,0,0,1]).map(Ee),vn=(y=t.textureProperties)==null?void 0:y._EmissionMap,ir=vn!=null?{index:vn,extensions:X({},se)}:void 0,rr=((v=(g=t.vectorProperties)==null?void 0:g._ShadeColor)!=null?v:[.97,.81,.86,1]).map(Ee),En=(M=t.textureProperties)==null?void 0:M._ShadeTexture,or=En!=null?{index:En,extensions:X({},se)}:void 0,Ue=(P=(T=t.floatProperties)==null?void 0:T._ShadeShift)!=null?P:0,Oe=(A=(L=t.floatProperties)==null?void 0:L._ShadeToony)!=null?A:.9;Oe=Ri.MathUtils.lerp(Oe,1,.5+.5*Ue),Ue=-Ue-(1-Oe);let Mn=(H=(S=t.floatProperties)==null?void 0:S._IndirectLightIntensity)!=null?H:.1,sr=Mn?1-Mn:void 0,ct=(W=t.textureProperties)==null?void 0:W._SphereAdd,ar=ct!=null?[1,1,1]:void 0,lr=ct!=null?{index:ct}:void 0,ur=(xe=(z=t.floatProperties)==null?void 0:z._RimLightingMix)!=null?xe:0,Rn=(q=t.textureProperties)==null?void 0:q._RimTexture,dr=Rn!=null?{index:Rn,extensions:X({},se)}:void 0,hr=((pe=(G=t.vectorProperties)==null?void 0:G._RimColor)!=null?pe:[0,0,0,1]).map(Ee),cr=(O=(ye=t.floatProperties)==null?void 0:ye._RimFresnelPower)!=null?O:1,pr=(Yt=(Qt=t.floatProperties)==null?void 0:Qt._RimLift)!=null?Yt:0,mr=["none","worldCoordinates","screenCoordinates"][(Zt=(qt=t.floatProperties)==null?void 0:qt._OutlineWidthMode)!=null?Zt:0],pt=(Jt=($t=t.floatProperties)==null?void 0:$t._OutlineWidth)!=null?Jt:0;pt=.01*pt;let Tn=(Kt=t.textureProperties)==null?void 0:Kt._OutlineWidthTexture,fr=Tn!=null?{index:Tn,extensions:X({},se)}:void 0,_r=((tn=(en=t.vectorProperties)==null?void 0:en._OutlineColor)!=null?tn:[0,0,0]).map(Ee),gr=((rn=(nn=t.floatProperties)==null?void 0:nn._OutlineColorMode)!=null?rn:0)===1?(sn=(on=t.floatProperties)==null?void 0:on._OutlineLightingMix)!=null?sn:1:0,xn=(an=t.textureProperties)==null?void 0:an._UvAnimMaskTexture,vr=xn!=null?{index:xn,extensions:X({},se)}:void 0,Er=(un=(ln=t.floatProperties)==null?void 0:ln._UvAnimScrollX)!=null?un:0,Ne=(hn=(dn=t.floatProperties)==null?void 0:dn._UvAnimScrollY)!=null?hn:0;Ne!=null&&(Ne=-Ne);let Mr=(pn=(cn=t.floatProperties)==null?void 0:cn._UvAnimRotation)!=null?pn:0,Rr={specVersion:"1.0",transparentWithZWrite:Qi,renderQueueOffsetNumber:Yi,shadeColorFactor:rr,shadeMultiplyTexture:or,shadingShiftFactor:Ue,shadingToonyFactor:Oe,giEqualizationFactor:sr,matcapFactor:ar,matcapTexture:lr,rimLightingMixFactor:ur,rimMultiplyTexture:dr,parametricRimColorFactor:hr,parametricRimFresnelPowerFactor:cr,parametricRimLiftFactor:pr,outlineWidthMode:mr,outlineWidthFactor:pt,outlineWidthMultiplyTexture:fr,outlineColorFactor:_r,outlineLightingMixFactor:gr,uvAnimationMaskTexture:vr,uvAnimationScrollXSpeedFactor:Er,uvAnimationScrollYSpeedFactor:Ne,uvAnimationRotationSpeedFactor:Mr};return Mi(X({},e),{pbrMetallicRoughness:{baseColorFactor:Ji,baseColorTexture:Ki},normalTexture:tr,emissiveTexture:ir,emissiveFactor:nr,alphaMode:qi,alphaCutoff:Zi,doubleSided:$i,extensions:{VRMC_materials_mtoon:Rr}})}_parseV0UnlitProperties(t,e){var n,i,r,o,a;let l=t.shader==="VRM/UnlitTransparentZWrite",s=t.shader==="VRM/UnlitTransparent"||l,u=this._v0ParseRenderQueue(t),d=t.shader==="VRM/UnlitCutout",h=s?"BLEND":d?"MASK":"OPAQUE",p=d?(i=(n=t.floatProperties)==null?void 0:n._Cutoff)!=null?i:.5:void 0,m=this._portTextureTransform(t),c=((o=(r=t.vectorProperties)==null?void 0:r._Color)!=null?o:[1,1,1,1]).map(Ee),f=(a=t.textureProperties)==null?void 0:a._MainTex,_=f!=null?{index:f,extensions:X({},m)}:void 0,E={specVersion:"1.0",transparentWithZWrite:l,renderQueueOffsetNumber:u,shadeColorFactor:c,shadeMultiplyTexture:_};return Mi(X({},e),{pbrMetallicRoughness:{baseColorFactor:c,baseColorTexture:_},alphaMode:h,alphaCutoff:p,extensions:{VRMC_materials_mtoon:E}})}_portTextureTransform(t){var e,n,i,r,o;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],s=[(r=a==null?void 0:a[2])!=null?r:1,(o=a==null?void 0:a[3])!=null?o:1];return l[1]=1-s[1]-l[1],{KHR_texture_transform:{offset:l,scale:s}}}_v0ParseRenderQueue(t){var e,n;let i=t.shader==="VRM/UnlitTransparentZWrite",r=((e=t.keywordMap)==null?void 0:e._ALPHABLEND_ON)!=null||t.shader==="VRM/UnlitTransparent"||i,o=((n=t.floatProperties)==null?void 0:n._ZWrite)===1||i,a=0;if(r){let l=t.renderQueue;l!=null&&(o?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,o;let a=i.shader==="VRM/UnlitTransparentZWrite",l=((r=i.keywordMap)==null?void 0:r._ALPHABLEND_ON)!=null||i.shader==="VRM/UnlitTransparent"||a,s=((o=i.floatProperties)==null?void 0:o._ZWrite)===1||a;if(l){let u=i.renderQueue;u!=null&&(s?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 o=Math.min(Math.max(r-e.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 N=R(require("three"),1),Q=R(require("three"),1),Ut=R(require("three"),1),He=R(require("three"),1),$=R(require("three"),1);var xi=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),ne=new N.Vector3,et=class extends N.Group{constructor(t){super(),this._attrPosition=new N.BufferAttribute(new Float32Array([0,0,0,0,0,0]),3),this._attrPosition.setUsage(N.DynamicDrawUsage);let e=new N.BufferGeometry;e.setAttribute("position",this._attrPosition);let n=new N.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new N.Line(e,n),this.add(this._line),this.constraint=t}updateMatrixWorld(t){ne.setFromMatrixPosition(this.constraint.destination.matrixWorld),this._attrPosition.setXYZ(0,ne.x,ne.y,ne.z),this.constraint.source&&ne.setFromMatrixPosition(this.constraint.source.matrixWorld),this._attrPosition.setXYZ(1,ne.x,ne.y,ne.z),this._attrPosition.needsUpdate=!0,super.updateMatrixWorld(t)}};function yi(t,e){return e.set(t.elements[12],t.elements[13],t.elements[14])}var Ro=new Ut.Vector3,To=new Ut.Vector3;function xo(t,e){return t.decompose(Ro,e,To),e}function tt(t){return t.invert?t.invert():t.inverse(),t}var nt=class{constructor(t,e){this.destination=t,this.source=e,this.weight=1}},yo=new Q.Vector3,wo=new Q.Vector3,So=new Q.Vector3,Po=new Q.Quaternion,Ao=new Q.Quaternion,Lo=new Q.Quaternion,wi=class extends nt{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 Q.Vector3(1,0,0),this._dstRestQuat=new Q.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion)}update(){this.destination.updateWorldMatrix(!0,!1),this.source.updateWorldMatrix(!0,!1);let t=Po.identity(),e=Ao.identity();this.destination.parent&&(xo(this.destination.parent.matrixWorld,t),tt(e.copy(t)));let n=yo.copy(this._v3AimAxis).applyQuaternion(this._dstRestQuat).applyQuaternion(t),i=yi(this.source.matrixWorld,wo).sub(yi(this.destination.matrixWorld,So)).normalize(),r=Lo.setFromUnitVectors(n,i).premultiply(e).multiply(t).multiply(this._dstRestQuat);this.destination.quaternion.copy(this._dstRestQuat).slerp(r,this.weight)}};function Ho(t,e){let n=[t],i=t.parent;for(;i!==null;)n.unshift(i),i=i.parent;n.forEach(r=>{e(r)})}var Si=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 o of r)Ho(o,a=>{let l=this._objectConstraintsMap.get(a);if(l)for(let s of l)this._processConstraint(s,e,n,i)});i(t),n.add(t)}},bo=new He.Quaternion,Io=new He.Quaternion,Pi=class extends nt{get dependencies(){return new Set([this.source])}constructor(t,e){super(t,e),this._dstRestQuat=new He.Quaternion,this._invSrcRestQuat=new He.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion),tt(this._invSrcRestQuat.copy(this.source.quaternion))}update(){let t=bo.copy(this._invSrcRestQuat).multiply(this.source.quaternion),e=Io.copy(this._dstRestQuat).multiply(t);this.destination.quaternion.copy(this._dstRestQuat).slerp(e,this.weight)}},Vo=new $.Vector3,Co=new $.Quaternion,Uo=new $.Quaternion,Ai=class extends nt{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 $.Vector3(1,0,0),this._dstRestQuat=new $.Quaternion,this._invDstRestQuat=new $.Quaternion,this._invSrcRestQuatMulDstRestQuat=new $.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 t=Co.copy(this._invDstRestQuat).multiply(this.source.quaternion).multiply(this._invSrcRestQuatMulDstRestQuat),e=Vo.copy(this._v3RollAxis).applyQuaternion(t),i=Uo.setFromUnitVectors(e,this._v3RollAxis).premultiply(this._dstRestQuat).multiply(t);this.destination.quaternion.copy(this._dstRestQuat).slerp(i,this.weight)}},Oo=new Set(["1.0","1.0-beta"]),Li=class Le{get name(){return Le.EXTENSION_NAME}constructor(e,n){this.parser=e,this.helperRoot=n==null?void 0:n.helperRoot}afterRoot(e){return xi(this,null,function*(){e.userData.vrmNodeConstraintManager=yield this._import(e)})}_import(e){return xi(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 Si,a=yield this.parser.getDependencies("node");return a.forEach((l,s)=>{var u;let d=i.nodes[s],h=(u=d==null?void 0:d.extensions)==null?void 0:u[Le.EXTENSION_NAME];if(h==null)return;let p=h.specVersion;if(!Oo.has(p)){console.warn(`VRMNodeConstraintLoaderPlugin: Unknown ${Le.EXTENSION_NAME} specVersion "${p}"`);return}let m=h.constraint;if(m.roll!=null){let c=this._importRollConstraint(l,a,m.roll);o.addConstraint(c)}else if(m.aim!=null){let c=this._importAimConstraint(l,a,m.aim);o.addConstraint(c)}else if(m.rotation!=null){let c=this._importRotationConstraint(l,a,m.rotation);o.addConstraint(c)}}),e.scene.updateMatrixWorld(),o.setInitState(),o})}_importRollConstraint(e,n,i){let{source:r,rollAxis:o,weight:a}=i,l=n[r],s=new Ai(e,l);if(o!=null&&(s.rollAxis=o),a!=null&&(s.weight=a),this.helperRoot){let u=new et(s);this.helperRoot.add(u)}return s}_importAimConstraint(e,n,i){let{source:r,aimAxis:o,weight:a}=i,l=n[r],s=new wi(e,l);if(o!=null&&(s.aimAxis=o),a!=null&&(s.weight=a),this.helperRoot){let u=new et(s);this.helperRoot.add(u)}return s}_importRotationConstraint(e,n,i){let{source:r,weight:o}=i,a=n[r],l=new Pi(e,a);if(o!=null&&(l.weight=o),this.helperRoot){let s=new et(l);this.helperRoot.add(s)}return l}};Li.EXTENSION_NAME="VRMC_node_constraint";var Ot=Li;var re=R(require("three"),1),Ce=R(require("three"),1),Te=R(require("three"),1),Gt=R(require("three"),1),J=R(require("three"),1),ie=R(require("three"),1),he=R(require("three"),1),oe=R(require("three"),1),ce=R(require("three"),1),at=R(require("three"),1),U=R(require("three"),1),Vi=R(require("three"),1),Ci=R(require("three"),1),D=R(require("three"),1);var it=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),st=class{},Nt=new Ce.Vector3,de=new Ce.Vector3,Wt=class extends st{get type(){return"capsule"}constructor(t){var e,n,i,r;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new Ce.Vector3(0,0,0),this.tail=(n=t==null?void 0:t.tail)!=null?n:new Ce.Vector3(0,0,0),this.radius=(i=t==null?void 0:t.radius)!=null?i:0,this.inside=(r=t==null?void 0:t.inside)!=null?r:!1}calculateCollision(t,e,n,i){Nt.setFromMatrixPosition(t),de.subVectors(this.tail,this.offset).applyMatrix4(t),de.sub(Nt);let r=de.lengthSq();i.copy(e).sub(Nt);let o=de.dot(i);o<=0||(r<=o||de.multiplyScalar(o/r),i.sub(de));let a=i.length(),l=this.inside?this.radius-n-a:a-n-this.radius;return l<0&&(i.multiplyScalar(1/a),this.inside&&i.negate()),l}},Bt=new Te.Vector3,Hi=new Te.Matrix3,zt=class extends st{get type(){return"plane"}constructor(t){var e,n;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new Te.Vector3(0,0,0),this.normal=(n=t==null?void 0:t.normal)!=null?n:new Te.Vector3(0,0,1)}calculateCollision(t,e,n,i){i.setFromMatrixPosition(t),i.negate().add(e),Hi.getNormalMatrix(t),Bt.copy(this.normal).applyNormalMatrix(Hi).normalize();let r=i.dot(Bt)-n;return i.copy(Bt),r}},No=new Gt.Vector3,jt=class extends st{get type(){return"sphere"}constructor(t){var e,n,i;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new Gt.Vector3(0,0,0),this.radius=(n=t==null?void 0:t.radius)!=null?n:0,this.inside=(i=t==null?void 0:t.inside)!=null?i:!1}calculateCollision(t,e,n,i){i.subVectors(e,No.setFromMatrixPosition(t));let r=i.length(),o=this.inside?this.radius-n-r:r-n-this.radius;return o<0&&(i.multiplyScalar(1/r),this.inside&&i.negate()),o}},Y=new J.Vector3,Bo=class extends J.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new J.Vector3,this._currentTail=new J.Vector3,this._shape=t,this._attrPos=new J.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new J.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=Y.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(n)>1e-10&&(this._currentTail.copy(n),t=!0),t&&this._buildPosition()}_buildPosition(){Y.copy(this._currentTail).sub(this._currentOffset);let t=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,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(Y.y,Math.sqrt(Y.x*Y.x+Y.z*Y.z)),n=-Math.atan2(Y.z,Y.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}},Do=class extends ie.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentOffset=new ie.Vector3,this._currentNormal=new ie.Vector3,this._shape=t,this._attrPos=new ie.BufferAttribute(new Float32Array(6*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new ie.BufferAttribute(new Uint16Array(10),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),this._currentNormal.equals(this._shape.normal)||(this._currentNormal.copy(this._shape.normal),t=!0),t&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,-.5,-.5,0),this._attrPos.setXYZ(1,.5,-.5,0),this._attrPos.setXYZ(2,.5,.5,0),this._attrPos.setXYZ(3,-.5,.5,0),this._attrPos.setXYZ(4,0,0,0),this._attrPos.setXYZ(5,0,0,.25),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this.lookAt(this._currentNormal),this._attrPos.needsUpdate=!0}_buildIndex(){this._attrIndex.setXY(0,0,1),this._attrIndex.setXY(2,1,2),this._attrIndex.setXY(4,2,3),this._attrIndex.setXY(6,3,0),this._attrIndex.setXY(8,4,5),this._attrIndex.needsUpdate=!0}},Fo=class extends he.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new he.Vector3,this._shape=t,this._attrPos=new he.BufferAttribute(new Float32Array(32*3*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new he.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}},ko=new re.Vector3,rt=class extends re.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof jt)this._geometry=new Fo(this.collider.shape);else if(this.collider.shape instanceof Wt)this._geometry=new Bo(this.collider.shape);else if(this.collider.shape instanceof zt)this._geometry=new Do(this.collider.shape);else throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");let e=new re.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new re.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=ko.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}},Wo=class extends ce.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentTail=new ce.Vector3,this._springBone=t,this._attrPos=new ce.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new ce.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}},zo=new oe.Vector3,Ii=class extends oe.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new Wo(this.springBone);let e=new oe.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new oe.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=zo.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}},ot=class extends at.Object3D{constructor(t){super(),this.colliderMatrix=new at.Matrix4,this.shape=t}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),Go(this.colliderMatrix,this.matrixWorld,this.shape.offset)}};function Go(t,e,n){let i=e.elements;t.copy(e),n&&(t.elements[12]=i[0]*n.x+i[4]*n.y+i[8]*n.z+i[12],t.elements[13]=i[1]*n.x+i[5]*n.y+i[9]*n.z+i[13],t.elements[14]=i[2]*n.x+i[6]*n.y+i[10]*n.z+i[14])}var jo=new Ci.Matrix4;function Xo(t){return t.invert?t.invert():t.getInverse(jo.copy(t)),t}var Qo=class{constructor(t){this._inverseCache=new Vi.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&&(Xo(this._inverseCache.copy(this.matrix)),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}},Dt=new U.Matrix4,Me=new U.Vector3,be=new U.Vector3,Ie=new U.Vector3,Ve=new U.Vector3,Yo=new U.Matrix4,Ui=class{constructor(t,e,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,a,l,s,u;this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=e,this.settings={hitRadius:(r=n.hitRadius)!=null?r:0,stiffness:(o=n.stiffness)!=null?o:1,gravityPower:(a=n.gravityPower)!=null?a:0,gravityDir:(s=(l=n.gravityDir)==null?void 0:l.clone())!=null?s:new U.Vector3(0,-1,0),dragForce:(u=n.dragForce)!=null?u:.4},this.colliderGroups=i}get dependencies(){let t=new Set,e=this.bone.parent;e&&t.add(e);for(let n=0;n<this.colliderGroups.length;n++)for(let i=0;i<this.colliderGroups[n].colliders.length;i++)t.add(this.colliderGroups[n].colliders[i]);return t}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 Qo(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:Dt}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();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();this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength();let e=be.copy(this._boneAxis).transformDirection(this._initialLocalMatrix).transformDirection(this._parentMatrixWorld);Ve.copy(this._currentTail).add(Me.subVectors(this._currentTail,this._prevTail).multiplyScalar(1-this.settings.dragForce)).applyMatrix4(this._getMatrixCenterToWorld()).addScaledVector(e,this.settings.stiffness*t).addScaledVector(this.settings.gravityDir,this.settings.gravityPower*t),Ie.setFromMatrixPosition(this.bone.matrixWorld),Ve.sub(Ie).normalize().multiplyScalar(this._worldSpaceBoneLength).add(Ie),this._collision(Ve),this._prevTail.copy(this._currentTail),this._currentTail.copy(Ve).applyMatrix4(this._getMatrixWorldToCenter());let n=Yo.multiplyMatrices(this._parentMatrixWorld,this._initialLocalMatrix).invert();this.bone.quaternion.setFromUnitVectors(this._boneAxis,Me.copy(Ve).applyMatrix4(n).normalize()).premultiply(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){for(let e=0;e<this.colliderGroups.length;e++)for(let n=0;n<this.colliderGroups[e].colliders.length;n++){let i=this.colliderGroups[e].colliders[n],r=i.shape.calculateCollision(i.colliderMatrix,t,this.settings.hitRadius,Me);if(r<0){t.addScaledVector(Me,-r),t.sub(Ie);let o=t.length();t.multiplyScalar(this._worldSpaceBoneLength/o).add(Ie)}}}_calcWorldSpaceBoneLength(){Me.setFromMatrixPosition(this.bone.matrixWorld),this.child?be.setFromMatrixPosition(this.child.matrixWorld):(be.copy(this._initialLocalChildPosition),be.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=Me.sub(be).length()}_getMatrixCenterToWorld(){return this._center?this._center.matrixWorld:Dt}_getMatrixWorldToCenter(){return this._center?this._center.userData.inverseCacheProxy.inverse:Dt}};function qo(t,e){let n=[],i=t;for(;i!==null;)n.unshift(i),i=i.parent;n.forEach(r=>{e(r)})}function Ft(t,e){t.children.forEach(n=>{e(n)||Ft(n,e)})}function Zo(t){var e;let n=new Map;for(let i of t){let r=i;do{let o=((e=n.get(r))!=null?e:0)+1;if(o===t.size)return r;n.set(r,o),r=r.parent}while(r!==null)}return null}var kt=class{constructor(){this._joints=new Set,this._sortedJoints=[],this._hasWarnedCircularDependency=!1,this._ancestors=[],this._objectSpringBonesMap=new Map,this._isSortedJointsDirty=!1,this._relevantChildrenUpdated=this._relevantChildrenUpdated.bind(this)}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),this._isSortedJointsDirty=!0}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),this._isSortedJointsDirty=!0}deleteSpringBone(t){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(t)}setInitState(){this._sortJoints();for(let t=0;t<this._sortedJoints.length;t++){let e=this._sortedJoints[t];e.bone.updateMatrix(),e.bone.updateWorldMatrix(!1,!1),e.setInitState()}}reset(){this._sortJoints();for(let t=0;t<this._sortedJoints.length;t++){let e=this._sortedJoints[t];e.bone.updateMatrix(),e.bone.updateWorldMatrix(!1,!1),e.reset()}}update(t){this._sortJoints();for(let e=0;e<this._ancestors.length;e++)this._ancestors[e].updateWorldMatrix(e===0,!1);for(let e=0;e<this._sortedJoints.length;e++){let n=this._sortedJoints[e];n.bone.updateMatrix(),n.bone.updateWorldMatrix(!1,!1),n.update(t),Ft(n.bone,this._relevantChildrenUpdated)}}_sortJoints(){if(!this._isSortedJointsDirty)return;let t=[],e=new Set,n=new Set,i=new Set;for(let o of this._joints)this._insertJointSort(o,e,n,t,i);this._sortedJoints=t;let r=Zo(i);this._ancestors=[],r&&(this._ancestors.push(r),Ft(r,o=>{var a,l;return((l=(a=this._objectSpringBonesMap.get(o))==null?void 0:a.size)!=null?l:0)>0?!0:(this._ancestors.push(o),!1)})),this._isSortedJointsDirty=!1}_insertJointSort(t,e,n,i,r){if(n.has(t))return;if(e.has(t)){this._hasWarnedCircularDependency||(console.warn("VRMSpringBoneManager: Circular dependency detected"),this._hasWarnedCircularDependency=!0);return}e.add(t);let o=t.dependencies;for(let a of o){let l=!1,s=null;qo(a,u=>{let d=this._objectSpringBonesMap.get(u);if(d)for(let h of d)l=!0,this._insertJointSort(h,e,n,i,r);else l||(s=u)}),s&&r.add(s)}i.push(t),n.add(t)}_relevantChildrenUpdated(t){var e,n;return((n=(e=this._objectSpringBonesMap.get(t))==null?void 0:e.size)!=null?n:0)>0?!0:(t.updateWorldMatrix(!1,!1),!1)}},bi="VRMC_springBone_extended_collider",$o=new Set(["1.0","1.0-beta"]),Jo=new Set(["1.0"]),Oi=class Re{get name(){return Re.EXTENSION_NAME}constructor(e,n){var i;this.parser=e,this.jointHelperRoot=n==null?void 0:n.jointHelperRoot,this.colliderHelperRoot=n==null?void 0:n.colliderHelperRoot,this.useExtendedColliders=(i=n==null?void 0:n.useExtendedColliders)!=null?i:!0}afterRoot(e){return it(this,null,function*(){e.userData.vrmSpringBoneManager=yield this._import(e)})}_import(e){return it(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 it(this,null,function*(){var n,i,r,o,a;let l=e.parser.json;if(!(((n=l.extensionsUsed)==null?void 0:n.indexOf(Re.EXTENSION_NAME))!==-1))return null;let u=new kt,d=yield e.parser.getDependencies("node"),h=(i=l.extensions)==null?void 0:i[Re.EXTENSION_NAME];if(!h)return null;let p=h.specVersion;if(!$o.has(p))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${Re.EXTENSION_NAME} specVersion "${p}"`),null;let m=(r=h.colliders)==null?void 0:r.map((f,_)=>{var E,I,y,g,v,M,T,P,L,A,S,H,W,z,xe;let q=d[f.node];if(q==null)return console.warn(`VRMSpringBoneLoaderPlugin: The collider #${_} attempted to use the node #${f.node} but not found`),null;let G=f.shape,pe=(E=f.extensions)==null?void 0:E[bi];if(this.useExtendedColliders&&pe!=null){let ye=pe.specVersion;if(!Jo.has(ye))console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${bi} specVersion "${ye}". Fallbacking to the ${Re.EXTENSION_NAME} definition`);else{let O=pe.shape;if(O.sphere)return this._importSphereCollider(q,{offset:new D.Vector3().fromArray((I=O.sphere.offset)!=null?I:[0,0,0]),radius:(y=O.sphere.radius)!=null?y:0,inside:(g=O.sphere.inside)!=null?g:!1});if(O.capsule)return this._importCapsuleCollider(q,{offset:new D.Vector3().fromArray((v=O.capsule.offset)!=null?v:[0,0,0]),radius:(M=O.capsule.radius)!=null?M:0,tail:new D.Vector3().fromArray((T=O.capsule.tail)!=null?T:[0,0,0]),inside:(P=O.capsule.inside)!=null?P:!1});if(O.plane)return this._importPlaneCollider(q,{offset:new D.Vector3().fromArray((L=O.plane.offset)!=null?L:[0,0,0]),normal:new D.Vector3().fromArray((A=O.plane.normal)!=null?A:[0,0,1])})}}if(G.sphere)return this._importSphereCollider(q,{offset:new D.Vector3().fromArray((S=G.sphere.offset)!=null?S:[0,0,0]),radius:(H=G.sphere.radius)!=null?H:0,inside:!1});if(G.capsule)return this._importCapsuleCollider(q,{offset:new D.Vector3().fromArray((W=G.capsule.offset)!=null?W:[0,0,0]),radius:(z=G.capsule.radius)!=null?z:0,tail:new D.Vector3().fromArray((xe=G.capsule.tail)!=null?xe:[0,0,0]),inside:!1});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${_} has no valid shape`)}),c=(o=h.colliderGroups)==null?void 0:o.map((f,_)=>{var E;return{colliders:((E=f.colliders)!=null?E:[]).flatMap(y=>{let g=m==null?void 0:m[y];return g==null?(console.warn(`VRMSpringBoneLoaderPlugin: The colliderGroup #${_} attempted to use a collider #${y} but not found`),[]):g}),name:f.name}});return(a=h.springs)==null||a.forEach((f,_)=>{var E;let I=f.joints,y=(E=f.colliderGroups)==null?void 0:E.map(M=>{let T=c==null?void 0:c[M];if(T==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${_} attempted to use a colliderGroup ${M} but not found`);return T}),g=f.center!=null?d[f.center]:void 0,v;I.forEach(M=>{if(v){let T=v.node,P=d[T],L=M.node,A=d[L],S={hitRadius:v.hitRadius,dragForce:v.dragForce,gravityPower:v.gravityPower,stiffness:v.stiffness,gravityDir:v.gravityDir!=null?new D.Vector3().fromArray(v.gravityDir):void 0},H=this._importJoint(P,A,S,y);g&&(H.center=g),u.addJoint(H)}v=M})}),u.setInitState(),u})}_v0Import(e){return it(this,null,function*(){var n,i,r;let o=e.parser.json;if(!(((n=o.extensionsUsed)==null?void 0:n.indexOf("VRM"))!==-1))return null;let l=(i=o.extensions)==null?void 0:i.VRM,s=l==null?void 0:l.secondaryAnimation;if(!s)return null;let u=s==null?void 0:s.boneGroups;if(!u)return null;let d=new kt,h=yield e.parser.getDependencies("node"),p=(r=s.colliderGroups)==null?void 0:r.map(m=>{var c;let f=h[m.node];return{colliders:((c=m.colliders)!=null?c:[]).map((E,I)=>{var y,g,v;let M=new D.Vector3(0,0,0);return E.offset&&M.set((y=E.offset.x)!=null?y:0,(g=E.offset.y)!=null?g:0,E.offset.z?-E.offset.z:0),this._importSphereCollider(f,{offset:M,radius:(v=E.radius)!=null?v:0,inside:!1})})}});return u==null||u.forEach((m,c)=>{let f=m.bones;f&&f.forEach(_=>{var E,I,y,g;let v=h[_],M=new D.Vector3;m.gravityDir?M.set((E=m.gravityDir.x)!=null?E:0,(I=m.gravityDir.y)!=null?I:0,(y=m.gravityDir.z)!=null?y:0):M.set(0,-1,0);let T=m.center!=null?h[m.center]:void 0,P={hitRadius:m.hitRadius,dragForce:m.dragForce,gravityPower:m.gravityPower,stiffness:m.stiffiness,gravityDir:M},L=(g=m.colliderGroups)==null?void 0:g.map(A=>{let S=p==null?void 0:p[A];if(S==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${c} attempted to use a colliderGroup ${A} but not found`);return S});v.traverse(A=>{var S;let H=(S=A.children[0])!=null?S:null,W=this._importJoint(A,H,P,L);T&&(W.center=T),d.addJoint(W)})})}),e.scene.updateMatrixWorld(),d.setInitState(),d})}_importJoint(e,n,i,r){let o=new Ui(e,n,i,r);if(this.jointHelperRoot){let a=new Ii(o);this.jointHelperRoot.add(a),a.renderOrder=this.jointHelperRoot.renderOrder}return o}_importSphereCollider(e,n){let i=new jt(n),r=new ot(i);if(e.add(r),this.colliderHelperRoot){let o=new rt(r);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return r}_importCapsuleCollider(e,n){let i=new Wt(n),r=new ot(i);if(e.add(r),this.colliderHelperRoot){let o=new rt(r);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return r}_importPlaneCollider(e,n){let i=new zt(n),r=new ot(i);if(e.add(r),this.colliderHelperRoot){let o=new rt(r);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return r}};Oi.EXTENSION_NAME="VRMC_springBone";var Xt=Oi;var lt=class{get name(){return"VRMLoaderPlugin"}constructor(e,n){var o,a,l,s,u,d,h,p,m,c;this.parser=e;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(e),this.firstPersonPlugin=(a=n==null?void 0:n.firstPersonPlugin)!=null?a:new Xe(e),this.humanoidPlugin=(l=n==null?void 0:n.humanoidPlugin)!=null?l:new Ye(e,{helperRoot:i,autoUpdateHumanBones:r}),this.lookAtPlugin=(s=n==null?void 0:n.lookAtPlugin)!=null?s:new qe(e,{helperRoot:i}),this.metaPlugin=(u=n==null?void 0:n.metaPlugin)!=null?u:new Ze(e),this.mtoonMaterialPlugin=(d=n==null?void 0:n.mtoonMaterialPlugin)!=null?d:new Vt(e),this.materialsHDREmissiveMultiplierPlugin=(h=n==null?void 0:n.materialsHDREmissiveMultiplierPlugin)!=null?h:new gi(e),this.materialsV0CompatPlugin=(p=n==null?void 0:n.materialsV0CompatPlugin)!=null?p:new Ti(e),this.springBonePlugin=(m=n==null?void 0:n.springBonePlugin)!=null?m:new Xt(e,{colliderHelperRoot:i,jointHelperRoot:i}),this.nodeConstraintPlugin=(c=n==null?void 0:n.nodeConstraintPlugin)!=null?c:new Ot(e,{helperRoot:i})}beforeRoot(){return we(this,null,function*(){yield this.materialsV0CompatPlugin.beforeRoot(),yield this.mtoonMaterialPlugin.beforeRoot()})}loadMesh(e){return we(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 we(this,null,function*(){yield this.materialsHDREmissiveMultiplierPlugin.extendMaterialParams(e,n),yield this.mtoonMaterialPlugin.extendMaterialParams(e,n)})}afterRoot(e){return we(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 ve({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}})}};var Bi=R(require("three"),1);function Ko(t){let e=new Set;return t.traverse(n=>{if(!n.isMesh)return;let i=n;e.add(i)}),e}function Ni(t,e,n){if(e.size===1){let a=e.values().next().value;if(a.weight===1)return t[a.index]}let i=new Float32Array(t[0].count*3),r=0;if(n)r=1;else for(let a of e)r+=a.weight;for(let a of e){let l=t[a.index],s=a.weight/r;for(let u=0;u<l.count;u++)i[u*3+0]+=l.getX(u)*s,i[u*3+1]+=l.getY(u)*s,i[u*3+2]+=l.getZ(u)*s}return new Bi.BufferAttribute(i,3)}function Di(t){var r;let e=Ko(t.scene),n=new Map,i=(r=t.expressionManager)==null?void 0:r.expressionMap;if(i!=null)for(let[o,a]of Object.entries(i)){let l=new Set;for(let s of a.binds)if(s instanceof ge){if(s.weight!==0)for(let u of s.primitives){let d=n.get(u);d==null&&(d=new Map,n.set(u,d));let h=d.get(o);h==null&&(h=new Set,d.set(o,h)),h.add(s)}l.add(s)}for(let s of l)a.deleteBind(s)}for(let o of e){let a=n.get(o);if(a==null)continue;let l=o.geometry.morphAttributes;o.geometry.morphAttributes={};let s=o.geometry.clone();o.geometry=s;let u=s.morphTargetsRelative,d=l.position!=null,h=l.normal!=null,p={},m={},c=[];if(d||h){d&&(p.position=[]),h&&(p.normal=[]);let f=0;for(let[_,E]of a)d&&(p.position[f]=Ni(l.position,E,u)),h&&(p.normal[f]=Ni(l.normal,E,u)),i==null||i[_].addBind(new ge({index:f,weight:1,primitives:[o]})),m[_]=f,c.push(0),f++}s.morphAttributes=p,o.morphTargetDictionary=m,o.morphTargetInfluences=c}}var ut=R(require("three"),1);function Fi(t){let e=es(t),n=new Map;for(let o of e){let a=o.geometry,l=a.getAttribute("skinIndex"),s=a.getAttribute("skinWeight"),u=ts(l,s);n.set(l,u)}let i=new Map;for(let o of e){let a=ns(o,n);i.set(o,a)}let r=[];for(let[o,a]of i){let l=!1;for(let s of r)if(is(a,s.boneInverseMap)){l=!0,s.meshes.add(o);for(let[d,h]of a)s.boneInverseMap.set(d,h);break}l||r.push({boneInverseMap:a,meshes:new Set([o])})}for(let{boneInverseMap:o,meshes:a}of r){let l=Array.from(o.keys()),s=Array.from(o.values()),u=new ut.Skeleton(l,s),d=new Set;for(let h of a){let p=h.geometry.getAttribute("skinIndex");d.has(p)||(rs(p,h.skeleton.bones,l),d.add(p)),h.bind(u,new ut.Matrix4)}}}function es(t){let e=new Set;return t.traverse(n=>{if(!n.isSkinnedMesh)return;let i=n;e.add(i)}),e}function ts(t,e){let n=new Set;for(let i=0;i<t.count;i++)for(let r=0;r<t.itemSize;r++){let o=t.getComponent(i,r);e.getComponent(i,r)!==0&&n.add(o)}return n}function ns(t,e){let n=new Map,i=t.skeleton,o=t.geometry.getAttribute("skinIndex"),a=e.get(o);if(!a)throw new Error("Unreachable. attributeUsedIndexSetMap does not know the skin index attribute");for(let l of a)n.set(i.bones[l],i.boneInverses[l]);return n}function is(t,e){for(let[n,i]of t.entries()){let r=e.get(n);if(r!=null&&!os(i,r))return!1}return!0}function rs(t,e,n){let i=new Map;for(let o of e)i.set(o,i.size);let r=new Map;for(let[o,a]of n.entries()){let l=i.get(a);r.set(l,o)}for(let o=0;o<t.count;o++)for(let a=0;a<t.itemSize;a++){let l=t.getComponent(o,a),s=r.get(l);t.setComponent(o,a,s)}t.needsUpdate=!0}function os(t,e,n){if(n=n||1e-4,t.elements.length!=e.elements.length)return!1;for(let i=0,r=t.elements.length;i<r;i++)if(Math.abs(t.elements[i]-e.elements[i])>n)return!1;return!0}function ki(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 ss(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=>ki(r)):i&&ki(i))}function Wi(t){t.traverse(ss)}var dt=R(require("three"),1);function zi(t,e){var a,l;console.warn("VRMUtils.removeUnnecessaryJoints: removeUnnecessaryJoints is deprecated. Use combineSkeletons instead. combineSkeletons contributes more to the performance improvement. This function will be removed in the next major version.");let n=(a=e==null?void 0:e.experimentalSameBoneCounts)!=null?a:!1,i=[];t.traverse(s=>{s.type==="SkinnedMesh"&&i.push(s)});let r=new Map,o=0;for(let s of i){let d=s.geometry.getAttribute("skinIndex");if(r.has(d))continue;let h=new Map,p=new Map;for(let m=0;m<d.count;m++)for(let c=0;c<d.itemSize;c++){let f=d.getComponent(m,c),_=h.get(f);_==null&&(_=h.size,h.set(f,_),p.set(_,f)),d.setComponent(m,c,_)}d.needsUpdate=!0,r.set(d,p),o=Math.max(o,h.size)}for(let s of i){let d=s.geometry.getAttribute("skinIndex"),h=r.get(d),p=[],m=[],c=n?o:h.size;for(let _=0;_<c;_++){let E=(l=h.get(_))!=null?l:0;p.push(s.skeleton.bones[E]),m.push(s.skeleton.boneInverses[E])}let f=new dt.Skeleton(p,m);s.bind(f,new dt.Matrix4)}}var Gi=R(require("three"),1),ht=require("three");function ji(t){let e=new Map;t.traverse(n=>{var _,E,I,y;if(!n.isMesh)return;let i=n,r=i.geometry,o=r.index;if(o==null)return;let a=e.get(r);if(a!=null){i.geometry=a;return}let l=Object.values(r.attributes)[0].count,s=new Array(l),u=0,d=o.array;for(let g=0;g<d.length;g++){let v=d[g];s[v]||(s[v]=!0,u++)}if(u===l)return;let h=[],p=[],m=0;for(let g=0;g<s.length;g++)if(s[g]){let v=m++;h[g]=v,p[v]=g}let c=new Gi.BufferGeometry;c.name=r.name,c.morphTargetsRelative=r.morphTargetsRelative,r.groups.forEach(g=>{c.addGroup(g.start,g.count,g.materialIndex)}),c.boundingBox=(E=(_=r.boundingBox)==null?void 0:_.clone())!=null?E:null,c.boundingSphere=(y=(I=r.boundingSphere)==null?void 0:I.clone())!=null?y:null,c.setDrawRange(r.drawRange.start,r.drawRange.count),c.userData=r.userData,e.set(r,c);{let g=o.array,v=new g.constructor(g.length);for(let M=0;M<g.length;M++){let T=g[M],P=h[T];v[M]=P}c.setIndex(new ht.BufferAttribute(v,1,!1))}Object.keys(r.attributes).forEach(g=>{let v=r.attributes[g];if(v.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");let M=v.array,{itemSize:T,normalized:P}=v,L=new M.constructor(p.length*T);p.forEach((A,S)=>{for(let H=0;H<T;H++)L[S*T+H]=M[A*T+H]}),c.setAttribute(g,new ht.BufferAttribute(L,T,P))});let f=!0;Object.keys(r.morphAttributes).forEach(g=>{c.morphAttributes[g]=[];let v=r.morphAttributes[g];for(let M=0;M<v.length;M++){let T=v[M];if(T.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");let P=T.array,{itemSize:L,normalized:A}=T,S=new P.constructor(p.length*L);p.forEach((H,W)=>{for(let z=0;z<L;z++)S[W*L+z]=P[H*L+z]}),f=f&&S.every(H=>H===0),c.morphAttributes[g][M]=new ht.BufferAttribute(S,L,A)}}),f&&(c.morphAttributes={}),i.geometry=c}),Array.from(e.keys()).forEach(n=>{n.dispose()})}function Xi(t){var e;((e=t.meta)==null?void 0:e.metaVersion)==="0"&&(t.scene.rotation.y=Math.PI)}var K=class{constructor(){}};K.combineMorphs=Di,K.combineSkeletons=Fi,K.deepDispose=Wi,K.removeUnnecessaryJoints=zi,K.removeUnnecessaryVertices=ji,K.rotateVRM0=Xi;
|
|
924
|
+
`;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(S.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_SCREEN:this._isOutline&&this._outlineWidthMode===Vt.ScreenCoordinates}}_updateTextureMatrix(t,e){t.value&&(t.value.matrixAutoUpdate&&t.value.updateMatrix(),e.value.copy(t.value.matrix))}},mo=new Set(["1.0","1.0-beta"]),gi=class Ke{get name(){return Ke.EXTENSION_NAME}constructor(e,n={}){var i,r,o,a;this.parser=e,this.materialType=(i=n.materialType)!=null?i:fi,this.renderOrderOffset=(r=n.renderOrderOffset)!=null?r:0,this.v0CompatShade=(o=n.v0CompatShade)!=null?o:!1,this.debugMode=(a=n.debugMode)!=null?a:"none",this._mToonMaterialSet=new Set}beforeRoot(){return ue(this,null,function*(){this._removeUnlitExtensionIfMToonExists()})}afterRoot(e){return ue(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 ue(this,null,function*(){var n;let i=this.parser,o=(n=i.json.meshes)==null?void 0:n[e];if(o==null)throw new Error(`MToonMaterialLoaderPlugin: Attempt to use meshes[${e}] of glTF but the mesh doesn't exist`);let a=o.primitives,l=yield i.loadMesh(e);if(a.length===1){let s=l,u=a[0].material;u!=null&&this._setupPrimitive(s,u)}else{let s=l;for(let u=0;u<a.length;u++){let d=s.children[u],h=a[u].material;h!=null&&this._setupPrimitive(d,h)}}return l})}_removeUnlitExtensionIfMToonExists(){let i=this.parser.json.materials;i==null||i.map((r,o)=>{var a;this._getMToonExtension(o)&&((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[Ke.EXTENSION_NAME];if(l==null)return;let s=l.specVersion;if(!mo.has(s)){console.warn(`MToonMaterialLoaderPlugin: Unknown ${Ke.EXTENSION_NAME} specVersion "${s}"`);return}return l}_extendMaterialParams(e,n){return ue(this,null,function*(){var i;delete n.metalness,delete n.roughness;let r=new uo(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 et.Material)||!this._shouldGenerateOutline(n))return;e.material=[n];let i=n.clone();i.name+=" (Outline)",i.isOutline=!0,i.side=et.BackSide,e.material.push(i);let r=e.geometry,o=r.index?r.index.count:r.attributes.position.count/3;r.addGroup(0,o,0),r.addGroup(0,o,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)}};gi.EXTENSION_NAME="VRMC_materials_mtoon";var Ct=gi;var fo=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),_i=class Ut{get name(){return Ut.EXTENSION_NAME}constructor(e){this.parser=e}extendMaterialParams(e,n){return fo(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[Ut.EXTENSION_NAME];if(l!=null)return l}};_i.EXTENSION_NAME="VRMC_materials_hdr_emissiveMultiplier";var vi=_i;var Ti=T(require("three"),1);var go=Object.defineProperty,_o=Object.defineProperties,vo=Object.getOwnPropertyDescriptors,Ei=Object.getOwnPropertySymbols,Eo=Object.prototype.hasOwnProperty,Mo=Object.prototype.propertyIsEnumerable,Mi=(t,e,n)=>e in t?go(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,X=(t,e)=>{for(var n in e||(e={}))Eo.call(e,n)&&Mi(t,n,e[n]);if(Ei)for(var n of Ei(e))Mo.call(e,n)&&Mi(t,n,e[n]);return t},Ri=(t,e)=>_o(t,vo(e)),Ro=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())});function Ee(t){return Math.pow(t,2.2)}var xi=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 Ro(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,o)=>{var a,l;let s=(a=e.materials)==null?void 0:a[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);e.materials[o]=u}else if((l=r.shader)!=null&&l.startsWith("VRM/Unlit")){let u=this._parseV0UnlitProperties(r,s);e.materials[o]=u}else r.shader==="VRM_USE_GLTFSHADER"||console.warn(`VRMMaterialsV0CompatPlugin: Unknown shader: ${r.shader}`)}))})}_parseV0MToonProperties(t,e){var n,i,r,o,a,l,s,u,d,h,m,p,c,f,g,v,L,x,_,E,M,R,w,b,A,P,H,W,z,xe,q,G,pe,ye,O,Yt,qt,$t,Zt,Jt,Kt,en,tn,nn,rn,on,sn,an,ln,un,dn,hn,cn,pn,mn;let fn=(i=(n=t.keywordMap)==null?void 0:n._ALPHABLEND_ON)!=null?i:!1,Yi=((r=t.floatProperties)==null?void 0:r._ZWrite)===1&&fn,qi=this._v0ParseRenderQueue(t),gn=(a=(o=t.keywordMap)==null?void 0:o._ALPHATEST_ON)!=null?a:!1,$i=fn?"BLEND":gn?"MASK":"OPAQUE",Zi=gn?(s=(l=t.floatProperties)==null?void 0:l._Cutoff)!=null?s:.5:void 0,Ji=((d=(u=t.floatProperties)==null?void 0:u._CullMode)!=null?d:2)===0,se=this._portTextureTransform(t),Ki=((m=(h=t.vectorProperties)==null?void 0:h._Color)!=null?m:[1,1,1,1]).map((wn,xr)=>xr===3?wn:Ee(wn)),_n=(p=t.textureProperties)==null?void 0:p._MainTex,er=_n!=null?{index:_n,extensions:X({},se)}:void 0,tr=(f=(c=t.floatProperties)==null?void 0:c._BumpScale)!=null?f:1,vn=(g=t.textureProperties)==null?void 0:g._BumpMap,nr=vn!=null?{index:vn,scale:tr,extensions:X({},se)}:void 0,ir=((L=(v=t.vectorProperties)==null?void 0:v._EmissionColor)!=null?L:[0,0,0,1]).map(Ee),En=(x=t.textureProperties)==null?void 0:x._EmissionMap,rr=En!=null?{index:En,extensions:X({},se)}:void 0,or=((E=(_=t.vectorProperties)==null?void 0:_._ShadeColor)!=null?E:[.97,.81,.86,1]).map(Ee),Mn=(M=t.textureProperties)==null?void 0:M._ShadeTexture,sr=Mn!=null?{index:Mn,extensions:X({},se)}:void 0,Oe=(w=(R=t.floatProperties)==null?void 0:R._ShadeShift)!=null?w:0,Ne=(A=(b=t.floatProperties)==null?void 0:b._ShadeToony)!=null?A:.9;Ne=Ti.MathUtils.lerp(Ne,1,.5+.5*Oe),Oe=-Oe-(1-Ne);let Rn=(H=(P=t.floatProperties)==null?void 0:P._IndirectLightIntensity)!=null?H:.1,ar=Rn?1-Rn:void 0,pt=(W=t.textureProperties)==null?void 0:W._SphereAdd,lr=pt!=null?[1,1,1]:void 0,ur=pt!=null?{index:pt}:void 0,dr=(xe=(z=t.floatProperties)==null?void 0:z._RimLightingMix)!=null?xe:0,Tn=(q=t.textureProperties)==null?void 0:q._RimTexture,hr=Tn!=null?{index:Tn,extensions:X({},se)}:void 0,cr=((pe=(G=t.vectorProperties)==null?void 0:G._RimColor)!=null?pe:[0,0,0,1]).map(Ee),pr=(O=(ye=t.floatProperties)==null?void 0:ye._RimFresnelPower)!=null?O:1,mr=(qt=(Yt=t.floatProperties)==null?void 0:Yt._RimLift)!=null?qt:0,fr=["none","worldCoordinates","screenCoordinates"][(Zt=($t=t.floatProperties)==null?void 0:$t._OutlineWidthMode)!=null?Zt:0],mt=(Kt=(Jt=t.floatProperties)==null?void 0:Jt._OutlineWidth)!=null?Kt:0;mt=.01*mt;let xn=(en=t.textureProperties)==null?void 0:en._OutlineWidthTexture,gr=xn!=null?{index:xn,extensions:X({},se)}:void 0,_r=((nn=(tn=t.vectorProperties)==null?void 0:tn._OutlineColor)!=null?nn:[0,0,0]).map(Ee),vr=((on=(rn=t.floatProperties)==null?void 0:rn._OutlineColorMode)!=null?on:0)===1?(an=(sn=t.floatProperties)==null?void 0:sn._OutlineLightingMix)!=null?an:1:0,yn=(ln=t.textureProperties)==null?void 0:ln._UvAnimMaskTexture,Er=yn!=null?{index:yn,extensions:X({},se)}:void 0,Mr=(dn=(un=t.floatProperties)==null?void 0:un._UvAnimScrollX)!=null?dn:0,Be=(cn=(hn=t.floatProperties)==null?void 0:hn._UvAnimScrollY)!=null?cn:0;Be!=null&&(Be=-Be);let Rr=(mn=(pn=t.floatProperties)==null?void 0:pn._UvAnimRotation)!=null?mn:0,Tr={specVersion:"1.0",transparentWithZWrite:Yi,renderQueueOffsetNumber:qi,shadeColorFactor:or,shadeMultiplyTexture:sr,shadingShiftFactor:Oe,shadingToonyFactor:Ne,giEqualizationFactor:ar,matcapFactor:lr,matcapTexture:ur,rimLightingMixFactor:dr,rimMultiplyTexture:hr,parametricRimColorFactor:cr,parametricRimFresnelPowerFactor:pr,parametricRimLiftFactor:mr,outlineWidthMode:fr,outlineWidthFactor:mt,outlineWidthMultiplyTexture:gr,outlineColorFactor:_r,outlineLightingMixFactor:vr,uvAnimationMaskTexture:Er,uvAnimationScrollXSpeedFactor:Mr,uvAnimationScrollYSpeedFactor:Be,uvAnimationRotationSpeedFactor:Rr};return Ri(X({},e),{pbrMetallicRoughness:{baseColorFactor:Ki,baseColorTexture:er},normalTexture:nr,emissiveTexture:rr,emissiveFactor:ir,alphaMode:$i,alphaCutoff:Zi,doubleSided:Ji,extensions:{VRMC_materials_mtoon:Tr}})}_parseV0UnlitProperties(t,e){var n,i,r,o,a;let l=t.shader==="VRM/UnlitTransparentZWrite",s=t.shader==="VRM/UnlitTransparent"||l,u=this._v0ParseRenderQueue(t),d=t.shader==="VRM/UnlitCutout",h=s?"BLEND":d?"MASK":"OPAQUE",m=d?(i=(n=t.floatProperties)==null?void 0:n._Cutoff)!=null?i:.5:void 0,p=this._portTextureTransform(t),c=((o=(r=t.vectorProperties)==null?void 0:r._Color)!=null?o:[1,1,1,1]).map(Ee),f=(a=t.textureProperties)==null?void 0:a._MainTex,g=f!=null?{index:f,extensions:X({},p)}:void 0,v={specVersion:"1.0",transparentWithZWrite:l,renderQueueOffsetNumber:u,shadeColorFactor:c,shadeMultiplyTexture:g};return Ri(X({},e),{pbrMetallicRoughness:{baseColorFactor:c,baseColorTexture:g},alphaMode:h,alphaCutoff:m,extensions:{VRMC_materials_mtoon:v}})}_portTextureTransform(t){var e,n,i,r,o;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],s=[(r=a==null?void 0:a[2])!=null?r:1,(o=a==null?void 0:a[3])!=null?o:1];return l[1]=1-s[1]-l[1],{KHR_texture_transform:{offset:l,scale:s}}}_v0ParseRenderQueue(t){var e,n;let i=t.shader==="VRM/UnlitTransparentZWrite",r=((e=t.keywordMap)==null?void 0:e._ALPHABLEND_ON)!=null||t.shader==="VRM/UnlitTransparent"||i,o=((n=t.floatProperties)==null?void 0:n._ZWrite)===1||i,a=0;if(r){let l=t.renderQueue;l!=null&&(o?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,o;let a=i.shader==="VRM/UnlitTransparentZWrite",l=((r=i.keywordMap)==null?void 0:r._ALPHABLEND_ON)!=null||i.shader==="VRM/UnlitTransparent"||a,s=((o=i.floatProperties)==null?void 0:o._ZWrite)===1||a;if(l){let u=i.renderQueue;u!=null&&(s?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 o=Math.min(Math.max(r-e.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 N=T(require("three"),1),Q=T(require("three"),1),Ot=T(require("three"),1),be=T(require("three"),1),Z=T(require("three"),1);var yi=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),ne=new N.Vector3,tt=class extends N.Group{constructor(t){super(),this._attrPosition=new N.BufferAttribute(new Float32Array([0,0,0,0,0,0]),3),this._attrPosition.setUsage(N.DynamicDrawUsage);let e=new N.BufferGeometry;e.setAttribute("position",this._attrPosition);let n=new N.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new N.Line(e,n),this.add(this._line),this.constraint=t}updateMatrixWorld(t){ne.setFromMatrixPosition(this.constraint.destination.matrixWorld),this._attrPosition.setXYZ(0,ne.x,ne.y,ne.z),this.constraint.source&&ne.setFromMatrixPosition(this.constraint.source.matrixWorld),this._attrPosition.setXYZ(1,ne.x,ne.y,ne.z),this._attrPosition.needsUpdate=!0,super.updateMatrixWorld(t)}};function wi(t,e){return e.set(t.elements[12],t.elements[13],t.elements[14])}var To=new Ot.Vector3,xo=new Ot.Vector3;function yo(t,e){return t.decompose(To,e,xo),e}function nt(t){return t.invert?t.invert():t.inverse(),t}var it=class{constructor(t,e){this.destination=t,this.source=e,this.weight=1}},wo=new Q.Vector3,So=new Q.Vector3,Po=new Q.Vector3,Ao=new Q.Quaternion,Lo=new Q.Quaternion,bo=new Q.Quaternion,Si=class extends it{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 Q.Vector3(1,0,0),this._dstRestQuat=new Q.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion)}update(){this.destination.updateWorldMatrix(!0,!1),this.source.updateWorldMatrix(!0,!1);let t=Ao.identity(),e=Lo.identity();this.destination.parent&&(yo(this.destination.parent.matrixWorld,t),nt(e.copy(t)));let n=wo.copy(this._v3AimAxis).applyQuaternion(this._dstRestQuat).applyQuaternion(t),i=wi(this.source.matrixWorld,So).sub(wi(this.destination.matrixWorld,Po)).normalize(),r=bo.setFromUnitVectors(n,i).premultiply(e).multiply(t).multiply(this._dstRestQuat);this.destination.quaternion.copy(this._dstRestQuat).slerp(r,this.weight)}};function Ho(t,e){let n=[t],i=t.parent;for(;i!==null;)n.unshift(i),i=i.parent;n.forEach(r=>{e(r)})}var Pi=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 o of r)Ho(o,a=>{let l=this._objectConstraintsMap.get(a);if(l)for(let s of l)this._processConstraint(s,e,n,i)});i(t),n.add(t)}},Io=new be.Quaternion,Vo=new be.Quaternion,Ai=class extends it{get dependencies(){return new Set([this.source])}constructor(t,e){super(t,e),this._dstRestQuat=new be.Quaternion,this._invSrcRestQuat=new be.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion),nt(this._invSrcRestQuat.copy(this.source.quaternion))}update(){let t=Io.copy(this._invSrcRestQuat).multiply(this.source.quaternion),e=Vo.copy(this._dstRestQuat).multiply(t);this.destination.quaternion.copy(this._dstRestQuat).slerp(e,this.weight)}},Co=new Z.Vector3,Uo=new Z.Quaternion,Oo=new Z.Quaternion,Li=class extends it{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 Z.Vector3(1,0,0),this._dstRestQuat=new Z.Quaternion,this._invDstRestQuat=new Z.Quaternion,this._invSrcRestQuatMulDstRestQuat=new Z.Quaternion}setInitState(){this._dstRestQuat.copy(this.destination.quaternion),nt(this._invDstRestQuat.copy(this._dstRestQuat)),nt(this._invSrcRestQuatMulDstRestQuat.copy(this.source.quaternion)).multiply(this._dstRestQuat)}update(){let t=Uo.copy(this._invDstRestQuat).multiply(this.source.quaternion).multiply(this._invSrcRestQuatMulDstRestQuat),e=Co.copy(this._v3RollAxis).applyQuaternion(t),i=Oo.setFromUnitVectors(e,this._v3RollAxis).premultiply(this._dstRestQuat).multiply(t);this.destination.quaternion.copy(this._dstRestQuat).slerp(i,this.weight)}},No=new Set(["1.0","1.0-beta"]),bi=class Le{get name(){return Le.EXTENSION_NAME}constructor(e,n){this.parser=e,this.helperRoot=n==null?void 0:n.helperRoot}afterRoot(e){return yi(this,null,function*(){e.userData.vrmNodeConstraintManager=yield this._import(e)})}_import(e){return yi(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 Pi,a=yield this.parser.getDependencies("node");return a.forEach((l,s)=>{var u;let d=i.nodes[s],h=(u=d==null?void 0:d.extensions)==null?void 0:u[Le.EXTENSION_NAME];if(h==null)return;let m=h.specVersion;if(!No.has(m)){console.warn(`VRMNodeConstraintLoaderPlugin: Unknown ${Le.EXTENSION_NAME} specVersion "${m}"`);return}let p=h.constraint;if(p.roll!=null){let c=this._importRollConstraint(l,a,p.roll);o.addConstraint(c)}else if(p.aim!=null){let c=this._importAimConstraint(l,a,p.aim);o.addConstraint(c)}else if(p.rotation!=null){let c=this._importRotationConstraint(l,a,p.rotation);o.addConstraint(c)}}),e.scene.updateMatrixWorld(),o.setInitState(),o})}_importRollConstraint(e,n,i){let{source:r,rollAxis:o,weight:a}=i,l=n[r],s=new Li(e,l);if(o!=null&&(s.rollAxis=o),a!=null&&(s.weight=a),this.helperRoot){let u=new tt(s);this.helperRoot.add(u)}return s}_importAimConstraint(e,n,i){let{source:r,aimAxis:o,weight:a}=i,l=n[r],s=new Si(e,l);if(o!=null&&(s.aimAxis=o),a!=null&&(s.weight=a),this.helperRoot){let u=new tt(s);this.helperRoot.add(u)}return s}_importRotationConstraint(e,n,i){let{source:r,weight:o}=i,a=n[r],l=new Ai(e,a);if(o!=null&&(l.weight=o),this.helperRoot){let s=new tt(l);this.helperRoot.add(s)}return l}};bi.EXTENSION_NAME="VRMC_node_constraint";var Nt=bi;var re=T(require("three"),1),Ce=T(require("three"),1),Te=T(require("three"),1),jt=T(require("three"),1),J=T(require("three"),1),ie=T(require("three"),1),he=T(require("three"),1),oe=T(require("three"),1),ce=T(require("three"),1),lt=T(require("three"),1),U=T(require("three"),1),Ci=T(require("three"),1),Ui=T(require("three"),1),D=T(require("three"),1);var rt=(t,e,n)=>new Promise((i,r)=>{var o=s=>{try{l(n.next(s))}catch(u){r(u)}},a=s=>{try{l(n.throw(s))}catch(u){r(u)}},l=s=>s.done?i(s.value):Promise.resolve(s.value).then(o,a);l((n=n.apply(t,e)).next())}),at=class{},Bt=new Ce.Vector3,de=new Ce.Vector3,zt=class extends at{get type(){return"capsule"}constructor(t){var e,n,i,r;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new Ce.Vector3(0,0,0),this.tail=(n=t==null?void 0:t.tail)!=null?n:new Ce.Vector3(0,0,0),this.radius=(i=t==null?void 0:t.radius)!=null?i:0,this.inside=(r=t==null?void 0:t.inside)!=null?r:!1}calculateCollision(t,e,n,i){Bt.setFromMatrixPosition(t),de.subVectors(this.tail,this.offset).applyMatrix4(t),de.sub(Bt);let r=de.lengthSq();i.copy(e).sub(Bt);let o=de.dot(i);o<=0||(r<=o||de.multiplyScalar(o/r),i.sub(de));let a=i.length(),l=this.inside?this.radius-n-a:a-n-this.radius;return l<0&&(i.multiplyScalar(1/a),this.inside&&i.negate()),l}},Dt=new Te.Vector3,Hi=new Te.Matrix3,Gt=class extends at{get type(){return"plane"}constructor(t){var e,n;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new Te.Vector3(0,0,0),this.normal=(n=t==null?void 0:t.normal)!=null?n:new Te.Vector3(0,0,1)}calculateCollision(t,e,n,i){i.setFromMatrixPosition(t),i.negate().add(e),Hi.getNormalMatrix(t),Dt.copy(this.normal).applyNormalMatrix(Hi).normalize();let r=i.dot(Dt)-n;return i.copy(Dt),r}},Bo=new jt.Vector3,Xt=class extends at{get type(){return"sphere"}constructor(t){var e,n,i;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new jt.Vector3(0,0,0),this.radius=(n=t==null?void 0:t.radius)!=null?n:0,this.inside=(i=t==null?void 0:t.inside)!=null?i:!1}calculateCollision(t,e,n,i){i.subVectors(e,Bo.setFromMatrixPosition(t));let r=i.length(),o=this.inside?this.radius-n-r:r-n-this.radius;return o<0&&(i.multiplyScalar(1/r),this.inside&&i.negate()),o}},Y=new J.Vector3,Do=class extends J.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new J.Vector3,this._currentTail=new J.Vector3,this._shape=t,this._attrPos=new J.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new J.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=Y.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(n)>1e-10&&(this._currentTail.copy(n),t=!0),t&&this._buildPosition()}_buildPosition(){Y.copy(this._currentTail).sub(this._currentOffset);let t=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,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(Y.y,Math.sqrt(Y.x*Y.x+Y.z*Y.z)),n=-Math.atan2(Y.z,Y.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}},Fo=class extends ie.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentOffset=new ie.Vector3,this._currentNormal=new ie.Vector3,this._shape=t,this._attrPos=new ie.BufferAttribute(new Float32Array(6*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new ie.BufferAttribute(new Uint16Array(10),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),this._currentNormal.equals(this._shape.normal)||(this._currentNormal.copy(this._shape.normal),t=!0),t&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,-.5,-.5,0),this._attrPos.setXYZ(1,.5,-.5,0),this._attrPos.setXYZ(2,.5,.5,0),this._attrPos.setXYZ(3,-.5,.5,0),this._attrPos.setXYZ(4,0,0,0),this._attrPos.setXYZ(5,0,0,.25),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this.lookAt(this._currentNormal),this._attrPos.needsUpdate=!0}_buildIndex(){this._attrIndex.setXY(0,0,1),this._attrIndex.setXY(2,1,2),this._attrIndex.setXY(4,2,3),this._attrIndex.setXY(6,3,0),this._attrIndex.setXY(8,4,5),this._attrIndex.needsUpdate=!0}},ko=class extends he.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new he.Vector3,this._shape=t,this._attrPos=new he.BufferAttribute(new Float32Array(32*3*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new he.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}},Wo=new re.Vector3,ot=class extends re.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof Xt)this._geometry=new ko(this.collider.shape);else if(this.collider.shape instanceof zt)this._geometry=new Do(this.collider.shape);else if(this.collider.shape instanceof Gt)this._geometry=new Fo(this.collider.shape);else throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");let e=new re.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new re.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=Wo.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}},zo=class extends ce.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentTail=new ce.Vector3,this._springBone=t,this._attrPos=new ce.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new ce.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}},Go=new oe.Vector3,Vi=class extends oe.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new zo(this.springBone);let e=new oe.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new oe.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=Go.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}},st=class extends lt.Object3D{constructor(t){super(),this.colliderMatrix=new lt.Matrix4,this.shape=t}updateWorldMatrix(t,e){super.updateWorldMatrix(t,e),jo(this.colliderMatrix,this.matrixWorld,this.shape.offset)}};function jo(t,e,n){let i=e.elements;t.copy(e),n&&(t.elements[12]=i[0]*n.x+i[4]*n.y+i[8]*n.z+i[12],t.elements[13]=i[1]*n.x+i[5]*n.y+i[9]*n.z+i[13],t.elements[14]=i[2]*n.x+i[6]*n.y+i[10]*n.z+i[14])}var Xo=new Ui.Matrix4;function Qo(t){return t.invert?t.invert():t.getInverse(Xo.copy(t)),t}var Yo=class{constructor(t){this._inverseCache=new Ci.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&&(Qo(this._inverseCache.copy(this.matrix)),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}},Ft=new U.Matrix4,Me=new U.Vector3,He=new U.Vector3,Ie=new U.Vector3,Ve=new U.Vector3,qo=new U.Matrix4,Oi=class{constructor(t,e,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,a,l,s,u;this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=e,this.settings={hitRadius:(r=n.hitRadius)!=null?r:0,stiffness:(o=n.stiffness)!=null?o:1,gravityPower:(a=n.gravityPower)!=null?a:0,gravityDir:(s=(l=n.gravityDir)==null?void 0:l.clone())!=null?s:new U.Vector3(0,-1,0),dragForce:(u=n.dragForce)!=null?u:.4},this.colliderGroups=i}get dependencies(){let t=new Set,e=this.bone.parent;e&&t.add(e);for(let n=0;n<this.colliderGroups.length;n++)for(let i=0;i<this.colliderGroups[n].colliders.length;i++)t.add(this.colliderGroups[n].colliders[i]);return t}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 Yo(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:Ft}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();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();this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength();let e=He.copy(this._boneAxis).transformDirection(this._initialLocalMatrix).transformDirection(this._parentMatrixWorld);Ve.copy(this._currentTail).add(Me.subVectors(this._currentTail,this._prevTail).multiplyScalar(1-this.settings.dragForce)).applyMatrix4(this._getMatrixCenterToWorld()).addScaledVector(e,this.settings.stiffness*t).addScaledVector(this.settings.gravityDir,this.settings.gravityPower*t),Ie.setFromMatrixPosition(this.bone.matrixWorld),Ve.sub(Ie).normalize().multiplyScalar(this._worldSpaceBoneLength).add(Ie),this._collision(Ve),this._prevTail.copy(this._currentTail),this._currentTail.copy(Ve).applyMatrix4(this._getMatrixWorldToCenter());let n=qo.multiplyMatrices(this._parentMatrixWorld,this._initialLocalMatrix).invert();this.bone.quaternion.setFromUnitVectors(this._boneAxis,Me.copy(Ve).applyMatrix4(n).normalize()).premultiply(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){for(let e=0;e<this.colliderGroups.length;e++)for(let n=0;n<this.colliderGroups[e].colliders.length;n++){let i=this.colliderGroups[e].colliders[n],r=i.shape.calculateCollision(i.colliderMatrix,t,this.settings.hitRadius,Me);if(r<0){t.addScaledVector(Me,-r),t.sub(Ie);let o=t.length();t.multiplyScalar(this._worldSpaceBoneLength/o).add(Ie)}}}_calcWorldSpaceBoneLength(){Me.setFromMatrixPosition(this.bone.matrixWorld),this.child?He.setFromMatrixPosition(this.child.matrixWorld):(He.copy(this._initialLocalChildPosition),He.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=Me.sub(He).length()}_getMatrixCenterToWorld(){return this._center?this._center.matrixWorld:Ft}_getMatrixWorldToCenter(){return this._center?this._center.userData.inverseCacheProxy.inverse:Ft}};function $o(t,e){let n=[],i=t;for(;i!==null;)n.unshift(i),i=i.parent;n.forEach(r=>{e(r)})}function kt(t,e){t.children.forEach(n=>{e(n)||kt(n,e)})}function Zo(t){var e;let n=new Map;for(let i of t){let r=i;do{let o=((e=n.get(r))!=null?e:0)+1;if(o===t.size)return r;n.set(r,o),r=r.parent}while(r!==null)}return null}var Wt=class{constructor(){this._joints=new Set,this._sortedJoints=[],this._hasWarnedCircularDependency=!1,this._ancestors=[],this._objectSpringBonesMap=new Map,this._isSortedJointsDirty=!1,this._relevantChildrenUpdated=this._relevantChildrenUpdated.bind(this)}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),this._isSortedJointsDirty=!0}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),this._isSortedJointsDirty=!0}deleteSpringBone(t){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(t)}setInitState(){this._sortJoints();for(let t=0;t<this._sortedJoints.length;t++){let e=this._sortedJoints[t];e.bone.updateMatrix(),e.bone.updateWorldMatrix(!1,!1),e.setInitState()}}reset(){this._sortJoints();for(let t=0;t<this._sortedJoints.length;t++){let e=this._sortedJoints[t];e.bone.updateMatrix(),e.bone.updateWorldMatrix(!1,!1),e.reset()}}update(t){this._sortJoints();for(let e=0;e<this._ancestors.length;e++)this._ancestors[e].updateWorldMatrix(e===0,!1);for(let e=0;e<this._sortedJoints.length;e++){let n=this._sortedJoints[e];n.bone.updateMatrix(),n.bone.updateWorldMatrix(!1,!1),n.update(t),kt(n.bone,this._relevantChildrenUpdated)}}_sortJoints(){if(!this._isSortedJointsDirty)return;let t=[],e=new Set,n=new Set,i=new Set;for(let o of this._joints)this._insertJointSort(o,e,n,t,i);this._sortedJoints=t;let r=Zo(i);this._ancestors=[],r&&(this._ancestors.push(r),kt(r,o=>{var a,l;return((l=(a=this._objectSpringBonesMap.get(o))==null?void 0:a.size)!=null?l:0)>0?!0:(this._ancestors.push(o),!1)})),this._isSortedJointsDirty=!1}_insertJointSort(t,e,n,i,r){if(n.has(t))return;if(e.has(t)){this._hasWarnedCircularDependency||(console.warn("VRMSpringBoneManager: Circular dependency detected"),this._hasWarnedCircularDependency=!0);return}e.add(t);let o=t.dependencies;for(let a of o){let l=!1,s=null;$o(a,u=>{let d=this._objectSpringBonesMap.get(u);if(d)for(let h of d)l=!0,this._insertJointSort(h,e,n,i,r);else l||(s=u)}),s&&r.add(s)}i.push(t),n.add(t)}_relevantChildrenUpdated(t){var e,n;return((n=(e=this._objectSpringBonesMap.get(t))==null?void 0:e.size)!=null?n:0)>0?!0:(t.updateWorldMatrix(!1,!1),!1)}},Ii="VRMC_springBone_extended_collider",Jo=new Set(["1.0","1.0-beta"]),Ko=new Set(["1.0"]),Ni=class Re{get name(){return Re.EXTENSION_NAME}constructor(e,n){var i;this.parser=e,this.jointHelperRoot=n==null?void 0:n.jointHelperRoot,this.colliderHelperRoot=n==null?void 0:n.colliderHelperRoot,this.useExtendedColliders=(i=n==null?void 0:n.useExtendedColliders)!=null?i:!0}afterRoot(e){return rt(this,null,function*(){e.userData.vrmSpringBoneManager=yield this._import(e)})}_import(e){return rt(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 rt(this,null,function*(){var n,i,r,o,a;let l=e.parser.json;if(!(((n=l.extensionsUsed)==null?void 0:n.indexOf(Re.EXTENSION_NAME))!==-1))return null;let u=new Wt,d=yield e.parser.getDependencies("node"),h=(i=l.extensions)==null?void 0:i[Re.EXTENSION_NAME];if(!h)return null;let m=h.specVersion;if(!Jo.has(m))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${Re.EXTENSION_NAME} specVersion "${m}"`),null;let p=(r=h.colliders)==null?void 0:r.map((f,g)=>{var v,L,x,_,E,M,R,w,b,A,P,H,W,z,xe;let q=d[f.node];if(q==null)return console.warn(`VRMSpringBoneLoaderPlugin: The collider #${g} attempted to use the node #${f.node} but not found`),null;let G=f.shape,pe=(v=f.extensions)==null?void 0:v[Ii];if(this.useExtendedColliders&&pe!=null){let ye=pe.specVersion;if(!Ko.has(ye))console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${Ii} specVersion "${ye}". Fallbacking to the ${Re.EXTENSION_NAME} definition`);else{let O=pe.shape;if(O.sphere)return this._importSphereCollider(q,{offset:new D.Vector3().fromArray((L=O.sphere.offset)!=null?L:[0,0,0]),radius:(x=O.sphere.radius)!=null?x:0,inside:(_=O.sphere.inside)!=null?_:!1});if(O.capsule)return this._importCapsuleCollider(q,{offset:new D.Vector3().fromArray((E=O.capsule.offset)!=null?E:[0,0,0]),radius:(M=O.capsule.radius)!=null?M:0,tail:new D.Vector3().fromArray((R=O.capsule.tail)!=null?R:[0,0,0]),inside:(w=O.capsule.inside)!=null?w:!1});if(O.plane)return this._importPlaneCollider(q,{offset:new D.Vector3().fromArray((b=O.plane.offset)!=null?b:[0,0,0]),normal:new D.Vector3().fromArray((A=O.plane.normal)!=null?A:[0,0,1])})}}if(G.sphere)return this._importSphereCollider(q,{offset:new D.Vector3().fromArray((P=G.sphere.offset)!=null?P:[0,0,0]),radius:(H=G.sphere.radius)!=null?H:0,inside:!1});if(G.capsule)return this._importCapsuleCollider(q,{offset:new D.Vector3().fromArray((W=G.capsule.offset)!=null?W:[0,0,0]),radius:(z=G.capsule.radius)!=null?z:0,tail:new D.Vector3().fromArray((xe=G.capsule.tail)!=null?xe:[0,0,0]),inside:!1});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${g} has no valid shape`)}),c=(o=h.colliderGroups)==null?void 0:o.map((f,g)=>{var v;return{colliders:((v=f.colliders)!=null?v:[]).flatMap(x=>{let _=p==null?void 0:p[x];return _==null?(console.warn(`VRMSpringBoneLoaderPlugin: The colliderGroup #${g} attempted to use a collider #${x} but not found`),[]):_}),name:f.name}});return(a=h.springs)==null||a.forEach((f,g)=>{var v;let L=f.joints,x=(v=f.colliderGroups)==null?void 0:v.map(M=>{let R=c==null?void 0:c[M];if(R==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${g} attempted to use a colliderGroup ${M} but not found`);return R}),_=f.center!=null?d[f.center]:void 0,E;L.forEach(M=>{if(E){let R=E.node,w=d[R],b=M.node,A=d[b],P={hitRadius:E.hitRadius,dragForce:E.dragForce,gravityPower:E.gravityPower,stiffness:E.stiffness,gravityDir:E.gravityDir!=null?new D.Vector3().fromArray(E.gravityDir):void 0},H=this._importJoint(w,A,P,x);_&&(H.center=_),u.addJoint(H)}E=M})}),u.setInitState(),u})}_v0Import(e){return rt(this,null,function*(){var n,i,r;let o=e.parser.json;if(!(((n=o.extensionsUsed)==null?void 0:n.indexOf("VRM"))!==-1))return null;let l=(i=o.extensions)==null?void 0:i.VRM,s=l==null?void 0:l.secondaryAnimation;if(!s)return null;let u=s==null?void 0:s.boneGroups;if(!u)return null;let d=new Wt,h=yield e.parser.getDependencies("node"),m=(r=s.colliderGroups)==null?void 0:r.map(p=>{var c;let f=h[p.node];return{colliders:((c=p.colliders)!=null?c:[]).map((v,L)=>{var x,_,E;let M=new D.Vector3(0,0,0);return v.offset&&M.set((x=v.offset.x)!=null?x:0,(_=v.offset.y)!=null?_:0,v.offset.z?-v.offset.z:0),this._importSphereCollider(f,{offset:M,radius:(E=v.radius)!=null?E:0,inside:!1})})}});return u==null||u.forEach((p,c)=>{let f=p.bones;f&&f.forEach(g=>{var v,L,x,_;let E=h[g],M=new D.Vector3;p.gravityDir?M.set((v=p.gravityDir.x)!=null?v:0,(L=p.gravityDir.y)!=null?L:0,(x=p.gravityDir.z)!=null?x:0):M.set(0,-1,0);let R=p.center!=null?h[p.center]:void 0,w={hitRadius:p.hitRadius,dragForce:p.dragForce,gravityPower:p.gravityPower,stiffness:p.stiffiness,gravityDir:M},b=(_=p.colliderGroups)==null?void 0:_.map(A=>{let P=m==null?void 0:m[A];if(P==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${c} attempted to use a colliderGroup ${A} but not found`);return P});E.traverse(A=>{var P;let H=(P=A.children[0])!=null?P:null,W=this._importJoint(A,H,w,b);R&&(W.center=R),d.addJoint(W)})})}),e.scene.updateMatrixWorld(),d.setInitState(),d})}_importJoint(e,n,i,r){let o=new Oi(e,n,i,r);if(this.jointHelperRoot){let a=new Vi(o);this.jointHelperRoot.add(a),a.renderOrder=this.jointHelperRoot.renderOrder}return o}_importSphereCollider(e,n){let i=new Xt(n),r=new st(i);if(e.add(r),this.colliderHelperRoot){let o=new ot(r);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return r}_importCapsuleCollider(e,n){let i=new zt(n),r=new st(i);if(e.add(r),this.colliderHelperRoot){let o=new ot(r);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return r}_importPlaneCollider(e,n){let i=new Gt(n),r=new st(i);if(e.add(r),this.colliderHelperRoot){let o=new ot(r);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return r}};Ni.EXTENSION_NAME="VRMC_springBone";var Qt=Ni;var ut=class{get name(){return"VRMLoaderPlugin"}constructor(e,n){var o,a,l,s,u,d,h,m,p,c;this.parser=e;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 Xe(e),this.firstPersonPlugin=(a=n==null?void 0:n.firstPersonPlugin)!=null?a:new Qe(e),this.humanoidPlugin=(l=n==null?void 0:n.humanoidPlugin)!=null?l:new qe(e,{helperRoot:i,autoUpdateHumanBones:r}),this.lookAtPlugin=(s=n==null?void 0:n.lookAtPlugin)!=null?s:new $e(e,{helperRoot:i}),this.metaPlugin=(u=n==null?void 0:n.metaPlugin)!=null?u:new Ze(e),this.mtoonMaterialPlugin=(d=n==null?void 0:n.mtoonMaterialPlugin)!=null?d:new Ct(e),this.materialsHDREmissiveMultiplierPlugin=(h=n==null?void 0:n.materialsHDREmissiveMultiplierPlugin)!=null?h:new vi(e),this.materialsV0CompatPlugin=(m=n==null?void 0:n.materialsV0CompatPlugin)!=null?m:new xi(e),this.springBonePlugin=(p=n==null?void 0:n.springBonePlugin)!=null?p:new Qt(e,{colliderHelperRoot:i,jointHelperRoot:i}),this.nodeConstraintPlugin=(c=n==null?void 0:n.nodeConstraintPlugin)!=null?c:new Nt(e,{helperRoot:i})}beforeRoot(){return we(this,null,function*(){yield this.materialsV0CompatPlugin.beforeRoot(),yield this.mtoonMaterialPlugin.beforeRoot()})}loadMesh(e){return we(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 we(this,null,function*(){yield this.materialsHDREmissiveMultiplierPlugin.extendMaterialParams(e,n),yield this.mtoonMaterialPlugin.extendMaterialParams(e,n)})}afterRoot(e){return we(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 ve({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}})}};var Di=T(require("three"),1);function es(t){let e=new Set;return t.traverse(n=>{if(!n.isMesh)return;let i=n;e.add(i)}),e}function Bi(t,e,n){if(e.size===1){let a=e.values().next().value;if(a.weight===1)return t[a.index]}let i=new Float32Array(t[0].count*3),r=0;if(n)r=1;else for(let a of e)r+=a.weight;for(let a of e){let l=t[a.index],s=a.weight/r;for(let u=0;u<l.count;u++)i[u*3+0]+=l.getX(u)*s,i[u*3+1]+=l.getY(u)*s,i[u*3+2]+=l.getZ(u)*s}return new Di.BufferAttribute(i,3)}function Fi(t){var r;let e=es(t.scene),n=new Map,i=(r=t.expressionManager)==null?void 0:r.expressionMap;if(i!=null)for(let[o,a]of Object.entries(i)){let l=new Set;for(let s of a.binds)if(s instanceof _e){if(s.weight!==0)for(let u of s.primitives){let d=n.get(u);d==null&&(d=new Map,n.set(u,d));let h=d.get(o);h==null&&(h=new Set,d.set(o,h)),h.add(s)}l.add(s)}for(let s of l)a.deleteBind(s)}for(let o of e){let a=n.get(o);if(a==null)continue;let l=o.geometry.morphAttributes;o.geometry.morphAttributes={};let s=o.geometry.clone();o.geometry=s;let u=s.morphTargetsRelative,d=l.position!=null,h=l.normal!=null,m={},p={},c=[];if(d||h){d&&(m.position=[]),h&&(m.normal=[]);let f=0;for(let[g,v]of a)d&&(m.position[f]=Bi(l.position,v,u)),h&&(m.normal[f]=Bi(l.normal,v,u)),i==null||i[g].addBind(new _e({index:f,weight:1,primitives:[o]})),p[g]=f,c.push(0),f++}s.morphAttributes=m,o.morphTargetDictionary=p,o.morphTargetInfluences=c}}var dt=T(require("three"),1);function ki(t){var u;let e=ts(t),n=new Map;for(let d of e){let h=d.geometry,m=h.getAttribute("skinIndex"),p=(u=n.get(m))!=null?u:new Map;n.set(m,p);let c=h.getAttribute("skinWeight"),f=ns(m,c);p.set(c,f)}let i=new Map;for(let d of e){let h=is(d,n);i.set(d,h)}let r=[];for(let[d,h]of i){let m=!1;for(let p of r)if(rs(h,p.boneInverseMap)){m=!0,p.meshes.add(d);for(let[f,g]of h)p.boneInverseMap.set(f,g);break}m||r.push({boneInverseMap:h,meshes:new Set([d])})}let o=new Map,a=new Ue,l=new Ue,s=new Ue;for(let d of r){let{boneInverseMap:h,meshes:m}=d,p=Array.from(h.keys()),c=Array.from(h.values()),f=new dt.Skeleton(p,c),g=l.getOrCreate(f);for(let v of m){let L=v.geometry.getAttribute("skinIndex"),x=a.getOrCreate(L),_=v.skeleton.bones,E=_.map(w=>s.getOrCreate(w)).join(","),M=`${x};${g};${E}`,R=o.get(M);R==null&&(R=L.clone(),os(R,_,p),o.set(M,R)),v.geometry.setAttribute("skinIndex",R)}for(let v of m)v.bind(f,new dt.Matrix4)}}function ts(t){let e=new Set;return t.traverse(n=>{if(!n.isSkinnedMesh)return;let i=n;e.add(i)}),e}function ns(t,e){let n=new Set;for(let i=0;i<t.count;i++)for(let r=0;r<t.itemSize;r++){let o=t.getComponent(i,r);e.getComponent(i,r)!==0&&n.add(o)}return n}function is(t,e){let n=new Map,i=t.skeleton,r=t.geometry,o=r.getAttribute("skinIndex"),a=r.getAttribute("skinWeight"),l=e.get(o),s=l==null?void 0:l.get(a);if(!s)throw new Error("Unreachable. attributeUsedIndexSetMap does not know the skin index attribute or the skin weight attribute.");for(let u of s)n.set(i.bones[u],i.boneInverses[u]);return n}function rs(t,e){for(let[n,i]of t.entries()){let r=e.get(n);if(r!=null&&!ss(i,r))return!1}return!0}function os(t,e,n){let i=new Map;for(let o of e)i.set(o,i.size);let r=new Map;for(let[o,a]of n.entries()){let l=i.get(a);r.set(l,o)}for(let o=0;o<t.count;o++)for(let a=0;a<t.itemSize;a++){let l=t.getComponent(o,a),s=r.get(l);t.setComponent(o,a,s)}t.needsUpdate=!0}function ss(t,e,n){if(n=n||1e-4,t.elements.length!=e.elements.length)return!1;for(let i=0,r=t.elements.length;i<r;i++)if(Math.abs(t.elements[i]-e.elements[i])>n)return!1;return!0}var Ue=class{constructor(){this._objectIndexMap=new Map;this._index=0}get(e){return this._objectIndexMap.get(e)}getOrCreate(e){let n=this._objectIndexMap.get(e);return n==null&&(n=this._index,this._objectIndexMap.set(e,n),this._index++),n}};function Wi(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 as(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=>Wi(r)):i&&Wi(i))}function zi(t){t.traverse(as)}var ht=T(require("three"),1);function Gi(t,e){var a,l;console.warn("VRMUtils.removeUnnecessaryJoints: removeUnnecessaryJoints is deprecated. Use combineSkeletons instead. combineSkeletons contributes more to the performance improvement. This function will be removed in the next major version.");let n=(a=e==null?void 0:e.experimentalSameBoneCounts)!=null?a:!1,i=[];t.traverse(s=>{s.type==="SkinnedMesh"&&i.push(s)});let r=new Map,o=0;for(let s of i){let d=s.geometry.getAttribute("skinIndex");if(r.has(d))continue;let h=new Map,m=new Map;for(let p=0;p<d.count;p++)for(let c=0;c<d.itemSize;c++){let f=d.getComponent(p,c),g=h.get(f);g==null&&(g=h.size,h.set(f,g),m.set(g,f)),d.setComponent(p,c,g)}d.needsUpdate=!0,r.set(d,m),o=Math.max(o,h.size)}for(let s of i){let d=s.geometry.getAttribute("skinIndex"),h=r.get(d),m=[],p=[],c=n?o:h.size;for(let g=0;g<c;g++){let v=(l=h.get(g))!=null?l:0;m.push(s.skeleton.bones[v]),p.push(s.skeleton.boneInverses[v])}let f=new ht.Skeleton(m,p);s.bind(f,new ht.Matrix4)}}var ji=T(require("three"),1),ct=require("three");function Xi(t){let e=new Map;t.traverse(n=>{var g,v,L,x;if(!n.isMesh)return;let i=n,r=i.geometry,o=r.index;if(o==null)return;let a=e.get(r);if(a!=null){i.geometry=a;return}let l=Object.values(r.attributes)[0].count,s=new Array(l),u=0,d=o.array;for(let _=0;_<d.length;_++){let E=d[_];s[E]||(s[E]=!0,u++)}if(u===l)return;let h=[],m=[],p=0;for(let _=0;_<s.length;_++)if(s[_]){let E=p++;h[_]=E,m[E]=_}let c=new ji.BufferGeometry;c.name=r.name,c.morphTargetsRelative=r.morphTargetsRelative,r.groups.forEach(_=>{c.addGroup(_.start,_.count,_.materialIndex)}),c.boundingBox=(v=(g=r.boundingBox)==null?void 0:g.clone())!=null?v:null,c.boundingSphere=(x=(L=r.boundingSphere)==null?void 0:L.clone())!=null?x:null,c.setDrawRange(r.drawRange.start,r.drawRange.count),c.userData=r.userData,e.set(r,c);{let _=o.array,E=new _.constructor(_.length);for(let M=0;M<_.length;M++){let R=_[M],w=h[R];E[M]=w}c.setIndex(new ct.BufferAttribute(E,1,!1))}Object.keys(r.attributes).forEach(_=>{let E=r.attributes[_];if(E.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");let M=E.array,{itemSize:R,normalized:w}=E,b=new M.constructor(m.length*R);m.forEach((A,P)=>{for(let H=0;H<R;H++)b[P*R+H]=M[A*R+H]}),c.setAttribute(_,new ct.BufferAttribute(b,R,w))});let f=!0;Object.keys(r.morphAttributes).forEach(_=>{c.morphAttributes[_]=[];let E=r.morphAttributes[_];for(let M=0;M<E.length;M++){let R=E[M];if(R.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");let w=R.array,{itemSize:b,normalized:A}=R,P=new w.constructor(m.length*b);m.forEach((H,W)=>{for(let z=0;z<b;z++)P[W*b+z]=w[H*b+z]}),f=f&&P.every(H=>H===0),c.morphAttributes[_][M]=new ct.BufferAttribute(P,b,A)}}),f&&(c.morphAttributes={}),i.geometry=c}),Array.from(e.keys()).forEach(n=>{n.dispose()})}function Qi(t){var e;((e=t.meta)==null?void 0:e.metaVersion)==="0"&&(t.scene.rotation.y=Math.PI)}var K=class{constructor(){}};K.combineMorphs=Fi,K.combineSkeletons=ki,K.deepDispose=zi,K.removeUnnecessaryJoints=Gi,K.removeUnnecessaryVertices=Xi,K.rotateVRM0=Qi;
|
|
925
925
|
/*!
|
|
926
|
-
* @pixiv/three-vrm-core v3.3.
|
|
926
|
+
* @pixiv/three-vrm-core v3.3.4
|
|
927
927
|
* The implementation of core features of VRM, for @pixiv/three-vrm
|
|
928
928
|
*
|
|
929
|
-
* Copyright (c) 2019-
|
|
929
|
+
* Copyright (c) 2019-2025 pixiv Inc.
|
|
930
930
|
* @pixiv/three-vrm-core is distributed under MIT License
|
|
931
931
|
* https://github.com/pixiv/three-vrm/blob/release/LICENSE
|
|
932
932
|
*/
|
|
933
933
|
/*!
|
|
934
|
-
* @pixiv/three-vrm-materials-mtoon v3.3.
|
|
934
|
+
* @pixiv/three-vrm-materials-mtoon v3.3.4
|
|
935
935
|
* MToon (toon material) module for @pixiv/three-vrm
|
|
936
936
|
*
|
|
937
|
-
* Copyright (c) 2019-
|
|
937
|
+
* Copyright (c) 2019-2025 pixiv Inc.
|
|
938
938
|
* @pixiv/three-vrm-materials-mtoon is distributed under MIT License
|
|
939
939
|
* https://github.com/pixiv/three-vrm/blob/release/LICENSE
|
|
940
940
|
*/
|
|
941
941
|
/*!
|
|
942
|
-
* @pixiv/three-vrm-materials-hdr-emissive-multiplier v3.3.
|
|
942
|
+
* @pixiv/three-vrm-materials-hdr-emissive-multiplier v3.3.4
|
|
943
943
|
* Support VRMC_hdr_emissiveMultiplier for @pixiv/three-vrm
|
|
944
944
|
*
|
|
945
|
-
* Copyright (c) 2019-
|
|
945
|
+
* Copyright (c) 2019-2025 pixiv Inc.
|
|
946
946
|
* @pixiv/three-vrm-materials-hdr-emissive-multiplier is distributed under MIT License
|
|
947
947
|
* https://github.com/pixiv/three-vrm/blob/release/LICENSE
|
|
948
948
|
*/
|
|
949
949
|
/*!
|
|
950
|
-
* @pixiv/three-vrm-materials-v0compat v3.3.
|
|
950
|
+
* @pixiv/three-vrm-materials-v0compat v3.3.4
|
|
951
951
|
* VRM0.0 materials compatibility layer plugin for @pixiv/three-vrm
|
|
952
952
|
*
|
|
953
|
-
* Copyright (c) 2019-
|
|
953
|
+
* Copyright (c) 2019-2025 pixiv Inc.
|
|
954
954
|
* @pixiv/three-vrm-materials-v0compat is distributed under MIT License
|
|
955
955
|
* https://github.com/pixiv/three-vrm/blob/release/LICENSE
|
|
956
956
|
*/
|
|
957
957
|
/*!
|
|
958
|
-
* @pixiv/three-vrm-node-constraint v3.3.
|
|
958
|
+
* @pixiv/three-vrm-node-constraint v3.3.4
|
|
959
959
|
* Node constraint module for @pixiv/three-vrm
|
|
960
960
|
*
|
|
961
|
-
* Copyright (c) 2019-
|
|
961
|
+
* Copyright (c) 2019-2025 pixiv Inc.
|
|
962
962
|
* @pixiv/three-vrm-node-constraint is distributed under MIT License
|
|
963
963
|
* https://github.com/pixiv/three-vrm/blob/release/LICENSE
|
|
964
964
|
*/
|
|
965
965
|
/*!
|
|
966
|
-
* @pixiv/three-vrm-springbone v3.3.
|
|
966
|
+
* @pixiv/three-vrm-springbone v3.3.4
|
|
967
967
|
* Spring bone module for @pixiv/three-vrm
|
|
968
968
|
*
|
|
969
|
-
* Copyright (c) 2019-
|
|
969
|
+
* Copyright (c) 2019-2025 pixiv Inc.
|
|
970
970
|
* @pixiv/three-vrm-springbone is distributed under MIT License
|
|
971
971
|
* https://github.com/pixiv/three-vrm/blob/release/LICENSE
|
|
972
972
|
*/
|