Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@pixiv/three-vrm-core

Package Overview
Dependencies
Maintainers
0
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixiv/three-vrm-core - npm Package Compare versions

Comparing version 3.1.4 to 3.1.5

2

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

@@ -54,4 +54,4 @@ "license": "MIT",

"dependencies": {
"@pixiv/types-vrm-0.0": "3.1.4",
"@pixiv/types-vrmc-vrm-1.0": "3.1.4"
"@pixiv/types-vrm-0.0": "3.1.5",
"@pixiv/types-vrmc-vrm-1.0": "3.1.5"
},

@@ -65,3 +65,3 @@ "devDependencies": {

},
"gitHead": "bb91a237a743c31dfa3f05ccb7a285469d54bd30"
"gitHead": "ff9ce6c5068e3ec903f2bed55f74ed1c4acaad54"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc