@pixiv/three-vrm 2.0.4 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*! (c) 2019-2023 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
2
2
  import*as e from"three";import{BufferAttribute as t}from"three";
3
3
  /*!
4
- * @pixiv/three-vrm-core v2.0.4
4
+ * @pixiv/three-vrm-core v2.0.5
5
5
  * The implementation of core features of VRM, for @pixiv/three-vrm
6
6
  *
7
7
  * Copyright (c) 2020-2023 pixiv Inc.
@@ -36,7 +36,7 @@ function We(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try
36
36
  */
37
37
  function Qe(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}l((n=n.apply(e,t||[])).next())}))}function je(e){return Math.pow(e,2.2)}ze.EXTENSION_NAME="VRMC_materials_hdr_emissiveMultiplier";class Xe{get name(){return"VRMMaterialsV0CompatPlugin"}constructor(e){var t;this.parser=e,this._renderQueueMapTransparent=new Map,this._renderQueueMapTransparentZWrite=new Map;const i=this.parser.json;i.extensionsUsed=null!==(t=i.extensionsUsed)&&void 0!==t?t:[],-1===i.extensionsUsed.indexOf("KHR_texture_transform")&&i.extensionsUsed.push("KHR_texture_transform")}beforeRoot(){var e;return Qe(this,void 0,void 0,(function*(){const t=this.parser.json,i=null===(e=t.extensions)||void 0===e?void 0:e.VRM,n=null==i?void 0:i.materialProperties;n&&(this._populateRenderQueueMap(n),n.forEach(((e,i)=>{var n,r;const o=null===(n=t.materials)||void 0===n?void 0:n[i];if(null!=o)if("VRM/MToon"===e.shader){const n=this._parseV0MToonProperties(e,o);t.materials[i]=n}else if(null===(r=e.shader)||void 0===r?void 0:r.startsWith("VRM/Unlit")){const n=this._parseV0UnlitProperties(e,o);t.materials[i]=n}else"VRM_USE_GLTFSHADER"===e.shader||console.warn(`VRMMaterialsV0CompatPlugin: Unknown shader: ${e.shader}`);else console.warn(`VRMMaterialsV0CompatPlugin: Attempt to use materials[${i}] of glTF but the material doesn't exist`)})))}))}_parseV0MToonProperties(t,i){var n,r,o,s,a,l,u,d,h,c,p,m,f,v,g,_,M,x,y,T,R,w,E,P,A,S,L,b,I,U,O,N,V,C,D,F,B,H,k,W,z,Q,j,X;const G=null!==(r=null===(n=t.keywordMap)||void 0===n?void 0:n._ALPHABLEND_ON)&&void 0!==r&&r,Y=1===(null===(o=t.floatProperties)||void 0===o?void 0:o._ZWrite)&&G,q=this._v0ParseRenderQueue(t),$=null!==(a=null===(s=t.keywordMap)||void 0===s?void 0:s._ALPHATEST_ON)&&void 0!==a&&a,Z=G?"BLEND":$?"MASK":"OPAQUE",J=$?null===(l=t.floatProperties)||void 0===l?void 0:l._Cutoff:void 0,K=0===(null!==(d=null===(u=t.floatProperties)||void 0===u?void 0:u._CullMode)&&void 0!==d?d:2),ee=this._portTextureTransform(t),te=null===(c=null===(h=t.vectorProperties)||void 0===h?void 0:h._Color)||void 0===c?void 0:c.map(((e,t)=>3===t?e:je(e))),ie=null===(p=t.textureProperties)||void 0===p?void 0:p._MainTex,ne=null!=ie?{index:ie,extensions:Object.assign({},ee)}:void 0,re=null===(m=t.floatProperties)||void 0===m?void 0:m._BumpScale,oe=null===(f=t.textureProperties)||void 0===f?void 0:f._BumpMap,se=null!=oe?{index:oe,scale:re,extensions:Object.assign({},ee)}:void 0,ae=null===(g=null===(v=t.vectorProperties)||void 0===v?void 0:v._EmissionColor)||void 0===g?void 0:g.map(je),le=null===(_=t.textureProperties)||void 0===_?void 0:_._EmissionMap,ue=null!=le?{index:le,extensions:Object.assign({},ee)}:void 0,de=null===(x=null===(M=t.vectorProperties)||void 0===M?void 0:M._ShadeColor)||void 0===x?void 0:x.map(je),he=null===(y=t.textureProperties)||void 0===y?void 0:y._ShadeTexture,ce=null!=he?{index:he,extensions:Object.assign({},ee)}:void 0;let pe=null!==(R=null===(T=t.floatProperties)||void 0===T?void 0:T._ShadeShift)&&void 0!==R?R:0,me=null!==(E=null===(w=t.floatProperties)||void 0===w?void 0:w._ShadeToony)&&void 0!==E?E:.9;me=e.MathUtils.lerp(me,1,.5+.5*pe),pe=-pe-(1-me);const fe=null===(P=t.floatProperties)||void 0===P?void 0:P._IndirectLightIntensity,ve=fe?1-fe:void 0,ge=null===(A=t.textureProperties)||void 0===A?void 0:A._SphereAdd,_e=null!=ge?[1,1,1]:void 0,Me=null!=ge?{index:ge}:void 0,xe=null===(S=t.floatProperties)||void 0===S?void 0:S._RimLightingMix,ye=null===(L=t.textureProperties)||void 0===L?void 0:L._RimTexture,Te=null!=ye?{index:ye,extensions:Object.assign({},ee)}:void 0,Re=null===(I=null===(b=t.vectorProperties)||void 0===b?void 0:b._RimColor)||void 0===I?void 0:I.map(je),we=null===(U=t.floatProperties)||void 0===U?void 0:U._RimFresnelPower,Ee=null===(O=t.floatProperties)||void 0===O?void 0:O._RimLift,Pe=["none","worldCoordinates","screenCoordinates"][null!==(V=null===(N=t.floatProperties)||void 0===N?void 0:N._OutlineWidthMode)&&void 0!==V?V:0];let Ae=null!==(D=null===(C=t.floatProperties)||void 0===C?void 0:C._OutlineWidth)&&void 0!==D?D:0;Ae*=.01;const Se=null===(F=t.textureProperties)||void 0===F?void 0:F._OutlineWidthTexture,Le=null!=Se?{index:Se,extensions:Object.assign({},ee)}:void 0,be=null===(H=null===(B=t.vectorProperties)||void 0===B?void 0:B._OutlineColor)||void 0===H?void 0:H.map(je),Ie=1===(null===(k=t.floatProperties)||void 0===k?void 0:k._OutlineColorMode)?null===(W=t.floatProperties)||void 0===W?void 0:W._OutlineLightingMix:0,Ue=null===(z=t.textureProperties)||void 0===z?void 0:z._UvAnimMaskTexture,Oe=null!=Ue?{index:Ue,extensions:Object.assign({},ee)}:void 0,Ne=null===(Q=t.floatProperties)||void 0===Q?void 0:Q._UvAnimScrollX;let Ve=null===(j=t.floatProperties)||void 0===j?void 0:j._UvAnimScrollY;null!=Ve&&(Ve=-Ve);const Ce={specVersion:"1.0",transparentWithZWrite:Y,renderQueueOffsetNumber:q,shadeColorFactor:de,shadeMultiplyTexture:ce,shadingShiftFactor:pe,shadingToonyFactor:me,giEqualizationFactor:ve,matcapFactor:_e,matcapTexture:Me,rimLightingMixFactor:xe,rimMultiplyTexture:Te,parametricRimColorFactor:Re,parametricRimFresnelPowerFactor:we,parametricRimLiftFactor:Ee,outlineWidthMode:Pe,outlineWidthFactor:Ae,outlineWidthMultiplyTexture:Le,outlineColorFactor:be,outlineLightingMixFactor:Ie,uvAnimationMaskTexture:Oe,uvAnimationScrollXSpeedFactor:Ne,uvAnimationScrollYSpeedFactor:Ve,uvAnimationRotationSpeedFactor:null===(X=t.floatProperties)||void 0===X?void 0:X._UvAnimRotation};return Object.assign(Object.assign({},i),{pbrMetallicRoughness:{baseColorFactor:te,baseColorTexture:ne},normalTexture:se,emissiveTexture:ue,emissiveFactor:ae,alphaMode:Z,alphaCutoff:J,doubleSided:K,extensions:{VRMC_materials_mtoon:Ce}})}_parseV0UnlitProperties(e,t){var i,n,r,o;const s="VRM/UnlitTransparentZWrite"===e.shader,a="VRM/UnlitTransparent"===e.shader||s,l=this._v0ParseRenderQueue(e),u="VRM/UnlitCutout"===e.shader,d=a?"BLEND":u?"MASK":"OPAQUE",h=u?null===(i=e.floatProperties)||void 0===i?void 0:i._Cutoff:void 0,c=this._portTextureTransform(e),p=null===(r=null===(n=e.vectorProperties)||void 0===n?void 0:n._Color)||void 0===r?void 0:r.map(je),m=null===(o=e.textureProperties)||void 0===o?void 0:o._MainTex,f=null!=m?{index:m,extensions:Object.assign({},c)}:void 0,v={specVersion:"1.0",transparentWithZWrite:s,renderQueueOffsetNumber:l,shadeColorFactor:p,shadeMultiplyTexture:f};return Object.assign(Object.assign({},t),{pbrMetallicRoughness:{baseColorFactor:p,baseColorTexture:f},alphaMode:d,alphaCutoff:h,extensions:{VRMC_materials_mtoon:v}})}_portTextureTransform(e){var t,i,n,r,o;const s=null===(t=e.vectorProperties)||void 0===t?void 0:t._MainTex;if(null==s)return{};const a=[null!==(i=null==s?void 0:s[0])&&void 0!==i?i:0,null!==(n=null==s?void 0:s[1])&&void 0!==n?n:0],l=[null!==(r=null==s?void 0:s[2])&&void 0!==r?r:1,null!==(o=null==s?void 0:s[3])&&void 0!==o?o:1];return a[1]=1-l[1]-a[1],{KHR_texture_transform:{offset:a,scale:l}}}_v0ParseRenderQueue(e){var t,i,n;const r=null!==(i=null===(t=e.keywordMap)||void 0===t?void 0:t._ALPHABLEND_ON)&&void 0!==i&&i,o=1===(null===(n=e.floatProperties)||void 0===n?void 0:n._ZWrite);let s=0;if(r){const t=e.renderQueue;null!=t&&(s=o?this._renderQueueMapTransparentZWrite.get(t):this._renderQueueMapTransparent.get(t))}return s}_populateRenderQueueMap(e){const t=new Set,i=new Set;e.forEach((e=>{var n,r,o;const s=null!==(r=null===(n=e.keywordMap)||void 0===n?void 0:n._ALPHABLEND_ON)&&void 0!==r&&r,a=1===(null===(o=e.floatProperties)||void 0===o?void 0:o._ZWrite);if(s){const n=e.renderQueue;null!=n&&(a?i.add(n):t.add(n))}})),t.size>10&&console.warn(`VRMMaterialsV0CompatPlugin: This VRM uses ${t.size} render queues for Transparent materials while VRM 1.0 only supports up to 10 render queues. The model might not be rendered correctly.`),i.size>10&&console.warn(`VRMMaterialsV0CompatPlugin: This VRM uses ${i.size} render queues for TransparentZWrite materials while VRM 1.0 only supports up to 10 render queues. The model might not be rendered correctly.`),Array.from(t).sort().forEach(((e,i)=>{const n=Math.min(Math.max(i-t.size+1,-9),0);this._renderQueueMapTransparent.set(e,n)})),Array.from(i).sort().forEach(((e,t)=>{const i=Math.min(Math.max(t,0),9);this._renderQueueMapTransparentZWrite.set(e,i)}))}}
38
38
  /*!
39
- * @pixiv/three-vrm-node-constraint v2.0.3
39
+ * @pixiv/three-vrm-node-constraint v2.0.5
40
40
  * Node constraint module for @pixiv/three-vrm
41
41
  *
42
42
  * Copyright (c) 2020-2023 pixiv Inc.
@@ -51,4 +51,4 @@ function Qe(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try
51
51
  * @pixiv/three-vrm-springbone is distributed under MIT License
52
52
  * https://github.com/pixiv/three-vrm/blob/release/LICENSE
53
53
  */
54
- class Mt{}const xt=new e.Vector3,yt=new e.Vector3;class Tt extends Mt{get type(){return"capsule"}constructor(t){var i,n,r;super(),this.offset=null!==(i=null==t?void 0:t.offset)&&void 0!==i?i:new e.Vector3(0,0,0),this.tail=null!==(n=null==t?void 0:t.tail)&&void 0!==n?n:new e.Vector3(0,0,0),this.radius=null!==(r=null==t?void 0:t.radius)&&void 0!==r?r:0}calculateCollision(e,t,i,n){xt.copy(this.offset).applyMatrix4(e),yt.copy(this.tail).applyMatrix4(e),yt.sub(xt);const r=yt.lengthSq();n.copy(t).sub(xt);const o=yt.dot(n);o<=0||(r<=o||yt.multiplyScalar(o/r),n.sub(yt));const s=i+this.radius,a=n.length()-s;return n.normalize(),a}}class Rt extends Mt{get type(){return"sphere"}constructor(t){var i,n;super(),this.offset=null!==(i=null==t?void 0:t.offset)&&void 0!==i?i:new e.Vector3(0,0,0),this.radius=null!==(n=null==t?void 0:t.radius)&&void 0!==n?n:0}calculateCollision(e,t,i,n){n.copy(this.offset).applyMatrix4(e),n.negate().add(t);const r=i+this.radius,o=n.length()-r;return n.normalize(),o}}const wt=new e.Vector3;class Et extends e.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new e.Vector3,this._currentTail=new e.Vector3,this._shape=t,this._attrPos=new e.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new e.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;const t=this._shape.radius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0);const i=wt.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(i)>1e-10&&(this._currentTail.copy(i),e=!0),e&&this._buildPosition()}_buildPosition(){wt.copy(this._currentTail).sub(this._currentOffset);const e=wt.length()/this._currentRadius;for(let t=0;t<=16;t++){const i=t/16*Math.PI;this._attrPos.setXYZ(t,-Math.sin(i),-Math.cos(i),0),this._attrPos.setXYZ(17+t,e+Math.sin(i),Math.cos(i),0),this._attrPos.setXYZ(34+t,-Math.sin(i),0,-Math.cos(i)),this._attrPos.setXYZ(51+t,e+Math.sin(i),0,Math.cos(i))}for(let t=0;t<32;t++){const i=t/16*Math.PI;this._attrPos.setXYZ(68+t,0,Math.sin(i),Math.cos(i)),this._attrPos.setXYZ(100+t,e,Math.sin(i),Math.cos(i))}const t=Math.atan2(wt.y,Math.sqrt(wt.x*wt.x+wt.z*wt.z)),i=-Math.atan2(wt.z,wt.x);this.rotateZ(t),this.rotateY(i),this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<34;e++){const t=(e+1)%34;this._attrIndex.setXY(2*e,e,t),this._attrIndex.setXY(68+2*e,34+e,34+t)}for(let e=0;e<32;e++){const t=(e+1)%32;this._attrIndex.setXY(136+2*e,68+e,68+t),this._attrIndex.setXY(200+2*e,100+e,100+t)}this._attrIndex.needsUpdate=!0}}class Pt extends e.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new e.Vector3,this._shape=t,this._attrPos=new e.BufferAttribute(new Float32Array(288),3),this.setAttribute("position",this._attrPos),this._attrIndex=new e.BufferAttribute(new Uint16Array(192),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;const t=this._shape.radius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){const t=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(t),Math.sin(t),0),this._attrPos.setXYZ(32+e,0,Math.cos(t),Math.sin(t)),this._attrPos.setXYZ(64+e,Math.sin(t),0,Math.cos(t))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<32;e++){const t=(e+1)%32;this._attrIndex.setXY(2*e,e,t),this._attrIndex.setXY(64+2*e,32+e,32+t),this._attrIndex.setXY(128+2*e,64+e,64+t)}this._attrIndex.needsUpdate=!0}}const At=new e.Vector3;class St extends e.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof Rt)this._geometry=new Pt(this.collider.shape);else{if(!(this.collider.shape instanceof Tt))throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");this._geometry=new Et(this.collider.shape)}const i=new e.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new e.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(e){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld);const t=this.matrix.elements;this._geometry.worldScale=At.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}}class Lt extends e.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentTail=new e.Vector3,this._springBone=t,this._attrPos=new e.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new e.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;const t=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){const 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++){const t=(e+1)%32;this._attrIndex.setXY(2*e,e,t),this._attrIndex.setXY(64+2*e,32+e,32+t),this._attrIndex.setXY(128+2*e,64+e,64+t)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}}const bt=new e.Vector3;class It extends e.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new Lt(this.springBone);const i=new e.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new e.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(e){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld);const t=this.matrix.elements;this._geometry.worldScale=bt.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}}class Ut extends e.Object3D{constructor(e){super(),this.shape=e}}const Ot=new e.Matrix4;function Nt(e){return e.invert?e.invert():e.getInverse(Ot.copy(e)),e}class Vt{get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),Nt(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}constructor(t){this._inverseCache=new e.Matrix4,this._shouldUpdateInverse=!0,this.matrix=t;const i={set:(e,t,i)=>(this._shouldUpdateInverse=!0,e[t]=i,!0)};this._originalElements=t.elements,t.elements=new Proxy(t.elements,i)}revert(){this.matrix.elements=this._originalElements}}const Ct=new e.Matrix4,Dt=new e.Vector3,Ft=new e.Vector3,Bt=new e.Vector3,Ht=new e.Vector3,kt=new e.Vector3,Wt=new e.Vector3,zt=new e.Quaternion,Qt=new e.Matrix4,jt=new e.Matrix4;class Xt{get center(){return this._center}set center(e){var t;(null===(t=this._center)||void 0===t?void 0:t.userData.inverseCacheProxy)&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=e,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new Vt(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:Ct}constructor(t,i,n={},r=[]){var o,s,a,l,u,d;this._currentTail=new e.Vector3,this._prevTail=new e.Vector3,this._boneAxis=new e.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new e.Matrix4,this._initialLocalRotation=new e.Quaternion,this._initialLocalChildPosition=new e.Vector3,this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=i,this.settings={hitRadius:null!==(o=n.hitRadius)&&void 0!==o?o:0,stiffness:null!==(s=n.stiffness)&&void 0!==s?s:1,gravityPower:null!==(a=n.gravityPower)&&void 0!==a?a:0,gravityDir:null!==(u=null===(l=n.gravityDir)||void 0===l?void 0:l.clone())&&void 0!==u?u:new e.Vector3(0,-1,0),dragForce:null!==(d=n.dragForce)&&void 0!==d?d:.4},this.colliderGroups=r}setInitState(){this._initialLocalMatrix.copy(this.bone.matrix),this._initialLocalRotation.copy(this.bone.quaternion),this.child?this._initialLocalChildPosition.copy(this.child.position):this._initialLocalChildPosition.copy(this.bone.position).normalize().multiplyScalar(.07);const e=this._getMatrixWorldToCenter(Qt);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);const e=this._getMatrixWorldToCenter(Qt);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail)}update(e){if(e<=0)return;this._calcWorldSpaceBoneLength(),Ht.setFromMatrixPosition(this.bone.matrixWorld);let t=this._getMatrixWorldToCenter(Qt);kt.copy(Ht).applyMatrix4(t);const i=zt.setFromRotationMatrix(t),n=jt.copy(t).multiply(this._parentMatrixWorld),r=Ft.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(n).sub(kt).normalize(),o=Bt.copy(this.settings.gravityDir).applyQuaternion(i).normalize(),s=this._getMatrixCenterToWorld(Qt);Wt.copy(this._currentTail).add(Dt.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(Dt.copy(r).multiplyScalar(this.settings.stiffness*e)).add(Dt.copy(o).multiplyScalar(this.settings.gravityPower*e)).applyMatrix4(s),Wt.sub(Ht).normalize().multiplyScalar(this._worldSpaceBoneLength).add(Ht),this._collision(Wt),t=this._getMatrixWorldToCenter(Qt),this._prevTail.copy(this._currentTail),this._currentTail.copy(Dt.copy(Wt).applyMatrix4(t));const a=Nt(Qt.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),l=zt.setFromUnitVectors(this._boneAxis,Dt.copy(Wt).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(l),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(e){this.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{const i=t.shape.calculateCollision(t.matrixWorld,e,this.settings.hitRadius,Dt);i<0&&(e.add(Dt.multiplyScalar(-i)),e.sub(Ht).normalize().multiplyScalar(this._worldSpaceBoneLength).add(Ht))}))}))}_calcWorldSpaceBoneLength(){Dt.setFromMatrixPosition(this.bone.matrixWorld),this.child?Ft.setFromMatrixPosition(this.child.matrixWorld):(Ft.copy(this._initialLocalChildPosition),Ft.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=Dt.sub(Ft).length()}_getMatrixCenterToWorld(e){return this._center?e.copy(this._center.matrixWorld):e.identity(),e}_getMatrixWorldToCenter(e){return this._center?e.copy(this._center.userData.inverseCacheProxy.inverse):e.identity(),e}}function Gt(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}l((n=n.apply(e,t||[])).next())}))}function Yt(e,t){const i=[];let n=e;for(;null!==n;)i.unshift(n),n=n.parent;i.forEach((e=>{t(e)}))}function qt(e,t){e.children.forEach((e=>{t(e)||qt(e,t)}))}class $t{constructor(){this._joints=new Set,this._objectSpringBonesMap=new Map}get joints(){return this._joints}get springBones(){return console.warn("VRMSpringBoneManager: springBones is deprecated. use joints instead."),this._joints}get colliderGroups(){const e=new Set;return this._joints.forEach((t=>{t.colliderGroups.forEach((t=>{e.add(t)}))})),Array.from(e)}get colliders(){const e=new Set;return this.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{e.add(t)}))})),Array.from(e)}addJoint(e){this._joints.add(e);let t=this._objectSpringBonesMap.get(e.bone);null==t&&(t=new Set,this._objectSpringBonesMap.set(e.bone,t)),t.add(e)}addSpringBone(e){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(e)}deleteJoint(e){this._joints.delete(e);this._objectSpringBonesMap.get(e.bone).delete(e)}deleteSpringBone(e){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(e)}setInitState(){const e=new Set,t=new Set,i=new Set;for(const n of this._joints)this._processSpringBone(n,e,t,i,(e=>e.setInitState()))}reset(){const e=new Set,t=new Set,i=new Set;for(const n of this._joints)this._processSpringBone(n,e,t,i,(e=>e.reset()))}update(e){const t=new Set,i=new Set,n=new Set;for(const r of this._joints)this._processSpringBone(r,t,i,n,(t=>t.update(e))),qt(r.bone,(e=>{var t,i;return(null!==(i=null===(t=this._objectSpringBonesMap.get(e))||void 0===t?void 0:t.size)&&void 0!==i?i:0)>0||(e.updateWorldMatrix(!1,!1),!1)}))}_processSpringBone(e,t,i,n,r){if(i.has(e))return;if(t.has(e))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");t.add(e);const o=this._getDependencies(e);for(const e of o)Yt(e,(e=>{const o=this._objectSpringBonesMap.get(e);if(o)for(const e of o)this._processSpringBone(e,t,i,n,r);else n.has(e)||(e.updateWorldMatrix(!1,!1),n.add(e))}));e.bone.updateMatrix(),e.bone.updateWorldMatrix(!1,!1),r(e),n.add(e.bone),i.add(e)}_getDependencies(e){const t=new Set,i=e.bone.parent;return i&&t.add(i),e.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{t.add(e)}))})),t}}const Zt=new Set(["1.0","1.0-beta"]);class Jt{get name(){return Jt.EXTENSION_NAME}constructor(e,t){this.parser=e,this.jointHelperRoot=null==t?void 0:t.jointHelperRoot,this.colliderHelperRoot=null==t?void 0:t.colliderHelperRoot}afterRoot(e){return Gt(this,void 0,void 0,(function*(){e.userData.vrmSpringBoneManager=yield this._import(e)}))}_import(e){return Gt(this,void 0,void 0,(function*(){const t=yield this._v1Import(e);if(null!=t)return t;const i=yield this._v0Import(e);return null!=i?i:null}))}_v1Import(t){var i,n,r,o,s;return Gt(this,void 0,void 0,(function*(){const a=t.parser.json;if(!(-1!==(null===(i=a.extensionsUsed)||void 0===i?void 0:i.indexOf(Jt.EXTENSION_NAME))))return null;const l=new $t,u=yield t.parser.getDependencies("node"),d=null===(n=a.extensions)||void 0===n?void 0:n[Jt.EXTENSION_NAME];if(!d)return null;const h=d.specVersion;if(!Zt.has(h))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${Jt.EXTENSION_NAME} specVersion "${h}"`),null;const c=null===(r=d.colliders)||void 0===r?void 0:r.map(((t,i)=>{var n,r,o,s,a;const l=u[t.node],d=t.shape;if(d.sphere)return this._importSphereCollider(l,{offset:(new e.Vector3).fromArray(null!==(n=d.sphere.offset)&&void 0!==n?n:[0,0,0]),radius:null!==(r=d.sphere.radius)&&void 0!==r?r:0});if(d.capsule)return this._importCapsuleCollider(l,{offset:(new e.Vector3).fromArray(null!==(o=d.capsule.offset)&&void 0!==o?o:[0,0,0]),radius:null!==(s=d.capsule.radius)&&void 0!==s?s:0,tail:(new e.Vector3).fromArray(null!==(a=d.capsule.tail)&&void 0!==a?a:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${i} has no valid shape`)})),p=null===(o=d.colliderGroups)||void 0===o?void 0:o.map(((e,t)=>{var i;return{colliders:(null!==(i=e.colliders)&&void 0!==i?i:[]).map((e=>{const i=null==c?void 0:c[e];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${t} attempted to use a collider #${e} but not found`);return i})),name:e.name}}));return null===(s=d.springs)||void 0===s||s.forEach(((t,i)=>{var n;const r=t.joints,o=null===(n=t.colliderGroups)||void 0===n?void 0:n.map((e=>{const t=null==p?void 0:p[e];if(null==t)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${e} but not found`);return t})),s=null!=t.center?u[t.center]:void 0;let a;r.forEach((t=>{if(a){const i=a.node,n=u[i],r=t.node,d=u[r],h={hitRadius:a.hitRadius,dragForce:a.dragForce,gravityPower:a.gravityPower,stiffness:a.stiffness,gravityDir:null!=a.gravityDir?(new e.Vector3).fromArray(a.gravityDir):void 0},c=this._importJoint(n,d,h,o);s&&(c.center=s),l.addJoint(c)}a=t}))})),l.setInitState(),l}))}_v0Import(t){var i,n,r;return Gt(this,void 0,void 0,(function*(){const o=t.parser.json;if(!(-1!==(null===(i=o.extensionsUsed)||void 0===i?void 0:i.indexOf("VRM"))))return null;const s=null===(n=o.extensions)||void 0===n?void 0:n.VRM,a=null==s?void 0:s.secondaryAnimation;if(!a)return null;const l=null==a?void 0:a.boneGroups;if(!l)return null;const u=new $t,d=yield t.parser.getDependencies("node"),h=null===(r=a.colliderGroups)||void 0===r?void 0:r.map((t=>{var i;const n=d[t.node],r=(null!==(i=t.colliders)&&void 0!==i?i:[]).map(((t,i)=>{var r,o,s;const a=new e.Vector3(0,0,0);return t.offset&&a.set(null!==(r=t.offset.x)&&void 0!==r?r:0,null!==(o=t.offset.y)&&void 0!==o?o:0,t.offset.z?-t.offset.z:0),this._importSphereCollider(n,{offset:a,radius:null!==(s=t.radius)&&void 0!==s?s:0})}));return{colliders:r}}));return null==l||l.forEach(((t,i)=>{const n=t.bones;n&&n.forEach((n=>{var r,o,s,a;const l=d[n],c=new e.Vector3;t.gravityDir?c.set(null!==(r=t.gravityDir.x)&&void 0!==r?r:0,null!==(o=t.gravityDir.y)&&void 0!==o?o:0,null!==(s=t.gravityDir.z)&&void 0!==s?s:0):c.set(0,-1,0);const p=null!=t.center?d[t.center]:void 0,m={hitRadius:t.hitRadius,dragForce:t.dragForce,gravityPower:t.gravityPower,stiffness:t.stiffiness,gravityDir:c},f=null===(a=t.colliderGroups)||void 0===a?void 0:a.map((e=>{const t=null==h?void 0:h[e];if(null==t)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${e} but not found`);return t}));l.traverse((e=>{var t;const i=null!==(t=e.children[0])&&void 0!==t?t:null,n=this._importJoint(e,i,m,f);p&&(n.center=p),u.addJoint(n)}))}))})),t.scene.updateMatrixWorld(),u.setInitState(),u}))}_importJoint(e,t,i,n){const r=new Xt(e,t,i,n);if(this.jointHelperRoot){const e=new It(r);this.jointHelperRoot.add(e),e.renderOrder=this.jointHelperRoot.renderOrder}return r}_importSphereCollider(e,t){const{offset:i,radius:n}=t,r=new Rt({offset:i,radius:n}),o=new Ut(r);if(e.add(o),this.colliderHelperRoot){const e=new St(o);this.colliderHelperRoot.add(e),e.renderOrder=this.colliderHelperRoot.renderOrder}return o}_importCapsuleCollider(e,t){const{offset:i,radius:n,tail:r}=t,o=new Tt({offset:i,radius:n,tail:r}),s=new Ut(o);if(e.add(s),this.colliderHelperRoot){const e=new St(s);this.colliderHelperRoot.add(e),e.renderOrder=this.colliderHelperRoot.renderOrder}return s}}Jt.EXTENSION_NAME="VRMC_springBone";class Kt{get name(){return"VRMLoaderPlugin"}constructor(e,t){var i,n,r,o,s,a,l,u,d,h;this.parser=e;const c=null==t?void 0:t.helperRoot,p=null==t?void 0:t.autoUpdateHumanBones;this.expressionPlugin=null!==(i=null==t?void 0:t.expressionPlugin)&&void 0!==i?i:new M(e),this.firstPersonPlugin=null!==(n=null==t?void 0:t.firstPersonPlugin)&&void 0!==n?n:new R(e),this.humanoidPlugin=null!==(r=null==t?void 0:t.humanoidPlugin)&&void 0!==r?r:new Q(e,{helperRoot:c,autoUpdateHumanBones:p}),this.lookAtPlugin=null!==(o=null==t?void 0:t.lookAtPlugin)&&void 0!==o?o:new we(e,{helperRoot:c}),this.metaPlugin=null!==(s=null==t?void 0:t.metaPlugin)&&void 0!==s?s:new Ae(e),this.mtoonMaterialPlugin=null!==(a=null==t?void 0:t.mtoonMaterialPlugin)&&void 0!==a?a:new ke(e),this.materialsHDREmissiveMultiplierPlugin=null!==(l=null==t?void 0:t.materialsHDREmissiveMultiplierPlugin)&&void 0!==l?l:new ze(e),this.materialsV0CompatPlugin=null!==(u=null==t?void 0:t.materialsV0CompatPlugin)&&void 0!==u?u:new Xe(e),this.springBonePlugin=null!==(d=null==t?void 0:t.springBonePlugin)&&void 0!==d?d:new Jt(e,{colliderHelperRoot:c,jointHelperRoot:c}),this.nodeConstraintPlugin=null!==(h=null==t?void 0:t.nodeConstraintPlugin)&&void 0!==h?h:new _t(e,{helperRoot:c})}beforeRoot(){return Ie(this,void 0,void 0,(function*(){yield this.materialsV0CompatPlugin.beforeRoot(),yield this.mtoonMaterialPlugin.beforeRoot()}))}loadMesh(e){return Ie(this,void 0,void 0,(function*(){return yield this.mtoonMaterialPlugin.loadMesh(e)}))}getMaterialType(e){const t=this.mtoonMaterialPlugin.getMaterialType(e);return null!=t?t:null}extendMaterialParams(e,t){return Ie(this,void 0,void 0,(function*(){yield this.materialsHDREmissiveMultiplierPlugin.extendMaterialParams(e,t),yield this.mtoonMaterialPlugin.extendMaterialParams(e,t)}))}afterRoot(e){return Ie(this,void 0,void 0,(function*(){yield this.metaPlugin.afterRoot(e),yield this.humanoidPlugin.afterRoot(e),yield this.expressionPlugin.afterRoot(e),yield this.lookAtPlugin.afterRoot(e),yield this.firstPersonPlugin.afterRoot(e),yield this.springBonePlugin.afterRoot(e),yield this.nodeConstraintPlugin.afterRoot(e),yield this.mtoonMaterialPlugin.afterRoot(e);const t=e.userData.vrmMeta,i=e.userData.vrmHumanoid;if(t&&i){const n=new be({scene:e.scene,expressionManager:e.userData.vrmExpressionManager,firstPerson:e.userData.vrmFirstPerson,humanoid:i,lookAt:e.userData.vrmLookAt,meta:t,materials:e.userData.vrmMToonMaterials,springBoneManager:e.userData.vrmSpringBoneManager,nodeConstraintManager:e.userData.vrmNodeConstraintManager});e.userData.vrm=n}}))}}function ei(e){if(Object.values(e).forEach((e=>{if(null==e?void 0:e.isTexture){e.dispose()}})),e.isShaderMaterial){const t=e.uniforms;t&&Object.values(t).forEach((e=>{const t=e.value;if(null==t?void 0:t.isTexture){t.dispose()}}))}e.dispose()}function ti(e){const t=e.geometry;t&&t.dispose();const i=e.skeleton;i&&i.dispose();const n=e.material;n&&(Array.isArray(n)?n.forEach((e=>ei(e))):n&&ei(n))}class ii{constructor(){}}ii.deepDispose=function(e){e.traverse(ti)},ii.removeUnnecessaryJoints=function(t){const i=new Map;t.traverse((t=>{if("SkinnedMesh"!==t.type)return;const n=t,r=n.geometry.getAttribute("skinIndex");let o=i.get(r);if(!o){const t=[],s=[],a={},l=r.array;for(let e=0;e<l.length;e++){const i=l[e];void 0===a[i]&&(a[i]=t.length,t.push(n.skeleton.bones[i]),s.push(n.skeleton.boneInverses[i])),l[e]=a[i]}r.copyArray(l),r.needsUpdate=!0,o=new e.Skeleton(t,s),i.set(r,o)}n.bind(o,new e.Matrix4)}))},ii.removeUnnecessaryVertices=function(i){const n=new Map;i.traverse((i=>{var r,o,s,a;if(!i.isMesh)return;const l=i,u=l.geometry,d=u.index;if(null==d)return;const h=n.get(u);if(null!=h)return void(l.geometry=h);const c=new e.BufferGeometry;c.name=u.name,c.morphTargetsRelative=u.morphTargetsRelative,u.groups.forEach((e=>{c.addGroup(e.start,e.count,e.materialIndex)})),c.boundingBox=null!==(o=null===(r=u.boundingBox)||void 0===r?void 0:r.clone())&&void 0!==o?o:null,c.boundingSphere=null!==(a=null===(s=u.boundingSphere)||void 0===s?void 0:s.clone())&&void 0!==a?a:null,c.setDrawRange(u.drawRange.start,u.drawRange.count),c.userData=u.userData,n.set(u,c);const p=[],m=[];{const e=d.array,i=new e.constructor(e.length);let n=0;for(let t=0;t<e.length;t++){const r=e[t];let o=p[r];null==o&&(p[r]=n,m[n]=r,o=n,n++),i[t]=o}c.setIndex(new t(i,1,!1))}Object.keys(u.attributes).forEach((e=>{const i=u.attributes[e];if(i.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");const n=i.array,{itemSize:r,normalized:o}=i,s=new n.constructor(m.length*r);m.forEach(((e,t)=>{for(let i=0;i<r;i++)s[t*r+i]=n[e*r+i]})),c.setAttribute(e,new t(s,r,o))}));let f=!0;Object.keys(u.morphAttributes).forEach((e=>{c.morphAttributes[e]=[];const i=u.morphAttributes[e];for(let n=0;n<i.length;n++){const r=i[n];if(r.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");const o=r.array,{itemSize:s,normalized:a}=r,l=new o.constructor(m.length*s);m.forEach(((e,t)=>{for(let i=0;i<s;i++)l[t*s+i]=o[e*s+i]})),f=f&&l.every((e=>0===e)),c.morphAttributes[e][n]=new t(l,s,a)}})),f&&(c.morphAttributes={}),l.geometry=c})),Array.from(n.keys()).forEach((e=>{e.dispose()}))},ii.rotateVRM0=function(e){var t;"0"===(null===(t=e.meta)||void 0===t?void 0:t.metaVersion)&&(e.scene.rotation.y=Math.PI)};export{De as MToonMaterial,Oe as MToonMaterialDebugMode,ke as MToonMaterialLoaderPlugin,Ne as MToonMaterialOutlineWidthMode,be as VRM,st as VRMAimConstraint,Se as VRMCore,Le as VRMCoreLoaderPlugin,i as VRMExpression,M as VRMExpressionLoaderPlugin,d as VRMExpressionManager,h as VRMExpressionMaterialColorType,x as VRMExpressionOverrideType,l as VRMExpressionPresetName,y as VRMFirstPerson,R as VRMFirstPersonLoaderPlugin,w as VRMFirstPersonMeshAnnotationType,L as VRMHumanBoneList,b as VRMHumanBoneName,I as VRMHumanBoneParentMap,H as VRMHumanoid,S as VRMHumanoidHelper,Q as VRMHumanoidLoaderPlugin,Kt as VRMLoaderPlugin,fe as VRMLookAt,xe as VRMLookAtBoneApplier,ye as VRMLookAtExpressionApplier,ee as VRMLookAtHelper,we as VRMLookAtLoaderPlugin,Te as VRMLookAtRangeMap,Ee as VRMLookAtTypeName,Ae as VRMMetaLoaderPlugin,Ke as VRMNodeConstraint,Ye as VRMNodeConstraintHelper,_t as VRMNodeConstraintLoaderPlugin,ut as VRMNodeConstraintManager,k as VRMRequiredHumanBoneName,vt as VRMRollConstraint,ct as VRMRotationConstraint,Ut as VRMSpringBoneCollider,St as VRMSpringBoneColliderHelper,Mt as VRMSpringBoneColliderShape,Tt as VRMSpringBoneColliderShapeCapsule,Rt as VRMSpringBoneColliderShapeSphere,Xt as VRMSpringBoneJoint,It as VRMSpringBoneJointHelper,Jt as VRMSpringBoneLoaderPlugin,$t as VRMSpringBoneManager,ii as VRMUtils};
54
+ class Mt{}const xt=new e.Vector3,yt=new e.Vector3;class Tt extends Mt{get type(){return"capsule"}constructor(t){var i,n,r;super(),this.offset=null!==(i=null==t?void 0:t.offset)&&void 0!==i?i:new e.Vector3(0,0,0),this.tail=null!==(n=null==t?void 0:t.tail)&&void 0!==n?n:new e.Vector3(0,0,0),this.radius=null!==(r=null==t?void 0:t.radius)&&void 0!==r?r:0}calculateCollision(e,t,i,n){xt.copy(this.offset).applyMatrix4(e),yt.copy(this.tail).applyMatrix4(e),yt.sub(xt);const r=yt.lengthSq();n.copy(t).sub(xt);const o=yt.dot(n);o<=0||(r<=o||yt.multiplyScalar(o/r),n.sub(yt));const s=i+this.radius,a=n.length()-s;return n.normalize(),a}}class Rt extends Mt{get type(){return"sphere"}constructor(t){var i,n;super(),this.offset=null!==(i=null==t?void 0:t.offset)&&void 0!==i?i:new e.Vector3(0,0,0),this.radius=null!==(n=null==t?void 0:t.radius)&&void 0!==n?n:0}calculateCollision(e,t,i,n){n.copy(this.offset).applyMatrix4(e),n.negate().add(t);const r=i+this.radius,o=n.length()-r;return n.normalize(),o}}const wt=new e.Vector3;class Et extends e.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new e.Vector3,this._currentTail=new e.Vector3,this._shape=t,this._attrPos=new e.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new e.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;const t=this._shape.radius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0);const i=wt.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(i)>1e-10&&(this._currentTail.copy(i),e=!0),e&&this._buildPosition()}_buildPosition(){wt.copy(this._currentTail).sub(this._currentOffset);const e=wt.length()/this._currentRadius;for(let t=0;t<=16;t++){const i=t/16*Math.PI;this._attrPos.setXYZ(t,-Math.sin(i),-Math.cos(i),0),this._attrPos.setXYZ(17+t,e+Math.sin(i),Math.cos(i),0),this._attrPos.setXYZ(34+t,-Math.sin(i),0,-Math.cos(i)),this._attrPos.setXYZ(51+t,e+Math.sin(i),0,Math.cos(i))}for(let t=0;t<32;t++){const i=t/16*Math.PI;this._attrPos.setXYZ(68+t,0,Math.sin(i),Math.cos(i)),this._attrPos.setXYZ(100+t,e,Math.sin(i),Math.cos(i))}const t=Math.atan2(wt.y,Math.sqrt(wt.x*wt.x+wt.z*wt.z)),i=-Math.atan2(wt.z,wt.x);this.rotateZ(t),this.rotateY(i),this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<34;e++){const t=(e+1)%34;this._attrIndex.setXY(2*e,e,t),this._attrIndex.setXY(68+2*e,34+e,34+t)}for(let e=0;e<32;e++){const t=(e+1)%32;this._attrIndex.setXY(136+2*e,68+e,68+t),this._attrIndex.setXY(200+2*e,100+e,100+t)}this._attrIndex.needsUpdate=!0}}class Pt extends e.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new e.Vector3,this._shape=t,this._attrPos=new e.BufferAttribute(new Float32Array(288),3),this.setAttribute("position",this._attrPos),this._attrIndex=new e.BufferAttribute(new Uint16Array(192),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;const t=this._shape.radius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){const t=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(t),Math.sin(t),0),this._attrPos.setXYZ(32+e,0,Math.cos(t),Math.sin(t)),this._attrPos.setXYZ(64+e,Math.sin(t),0,Math.cos(t))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let e=0;e<32;e++){const t=(e+1)%32;this._attrIndex.setXY(2*e,e,t),this._attrIndex.setXY(64+2*e,32+e,32+t),this._attrIndex.setXY(128+2*e,64+e,64+t)}this._attrIndex.needsUpdate=!0}}const At=new e.Vector3;class St extends e.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof Rt)this._geometry=new Pt(this.collider.shape);else{if(!(this.collider.shape instanceof Tt))throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");this._geometry=new Et(this.collider.shape)}const i=new e.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new e.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(e){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld);const t=this.matrix.elements;this._geometry.worldScale=At.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}}class Lt extends e.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentTail=new e.Vector3,this._springBone=t,this._attrPos=new e.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new e.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;const t=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==t&&(this._currentRadius=t,e=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){const 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++){const t=(e+1)%32;this._attrIndex.setXY(2*e,e,t),this._attrIndex.setXY(64+2*e,32+e,32+t),this._attrIndex.setXY(128+2*e,64+e,64+t)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}}const bt=new e.Vector3;class It extends e.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new Lt(this.springBone);const i=new e.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new e.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(e){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld);const t=this.matrix.elements;this._geometry.worldScale=bt.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}}class Ut extends e.Object3D{constructor(e){super(),this.shape=e}}const Ot=new e.Matrix4;function Nt(e){return e.invert?e.invert():e.getInverse(Ot.copy(e)),e}class Vt{get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),Nt(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}constructor(t){this._inverseCache=new e.Matrix4,this._shouldUpdateInverse=!0,this.matrix=t;const i={set:(e,t,i)=>(this._shouldUpdateInverse=!0,e[t]=i,!0)};this._originalElements=t.elements,t.elements=new Proxy(t.elements,i)}revert(){this.matrix.elements=this._originalElements}}const Ct=new e.Matrix4,Dt=new e.Vector3,Ft=new e.Vector3,Bt=new e.Vector3,Ht=new e.Vector3,kt=new e.Vector3,Wt=new e.Vector3,zt=new e.Quaternion,Qt=new e.Matrix4,jt=new e.Matrix4;class Xt{get center(){return this._center}set center(e){var t;(null===(t=this._center)||void 0===t?void 0:t.userData.inverseCacheProxy)&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=e,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new Vt(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:Ct}constructor(t,i,n={},r=[]){var o,s,a,l,u,d;this._currentTail=new e.Vector3,this._prevTail=new e.Vector3,this._boneAxis=new e.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new e.Matrix4,this._initialLocalRotation=new e.Quaternion,this._initialLocalChildPosition=new e.Vector3,this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=i,this.settings={hitRadius:null!==(o=n.hitRadius)&&void 0!==o?o:0,stiffness:null!==(s=n.stiffness)&&void 0!==s?s:1,gravityPower:null!==(a=n.gravityPower)&&void 0!==a?a:0,gravityDir:null!==(u=null===(l=n.gravityDir)||void 0===l?void 0:l.clone())&&void 0!==u?u:new e.Vector3(0,-1,0),dragForce:null!==(d=n.dragForce)&&void 0!==d?d:.4},this.colliderGroups=r}setInitState(){this._initialLocalMatrix.copy(this.bone.matrix),this._initialLocalRotation.copy(this.bone.quaternion),this.child?this._initialLocalChildPosition.copy(this.child.position):this._initialLocalChildPosition.copy(this.bone.position).normalize().multiplyScalar(.07);const e=this._getMatrixWorldToCenter(Qt);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);const e=this._getMatrixWorldToCenter(Qt);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail)}update(e){if(e<=0)return;this._calcWorldSpaceBoneLength(),Ht.setFromMatrixPosition(this.bone.matrixWorld);let t=this._getMatrixWorldToCenter(Qt);kt.copy(Ht).applyMatrix4(t);const i=zt.setFromRotationMatrix(t),n=jt.copy(t).multiply(this._parentMatrixWorld),r=Ft.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(n).sub(kt).normalize(),o=Bt.copy(this.settings.gravityDir).applyQuaternion(i).normalize(),s=this._getMatrixCenterToWorld(Qt);Wt.copy(this._currentTail).add(Dt.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(Dt.copy(r).multiplyScalar(this.settings.stiffness*e)).add(Dt.copy(o).multiplyScalar(this.settings.gravityPower*e)).applyMatrix4(s),Wt.sub(Ht).normalize().multiplyScalar(this._worldSpaceBoneLength).add(Ht),this._collision(Wt),t=this._getMatrixWorldToCenter(Qt),this._prevTail.copy(this._currentTail),this._currentTail.copy(Dt.copy(Wt).applyMatrix4(t));const a=Nt(Qt.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),l=zt.setFromUnitVectors(this._boneAxis,Dt.copy(Wt).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(l),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(e){this.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{const i=t.shape.calculateCollision(t.matrixWorld,e,this.settings.hitRadius,Dt);i<0&&(e.add(Dt.multiplyScalar(-i)),e.sub(Ht).normalize().multiplyScalar(this._worldSpaceBoneLength).add(Ht))}))}))}_calcWorldSpaceBoneLength(){Dt.setFromMatrixPosition(this.bone.matrixWorld),this.child?Ft.setFromMatrixPosition(this.child.matrixWorld):(Ft.copy(this._initialLocalChildPosition),Ft.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=Dt.sub(Ft).length()}_getMatrixCenterToWorld(e){return this._center?e.copy(this._center.matrixWorld):e.identity(),e}_getMatrixWorldToCenter(e){return this._center?e.copy(this._center.userData.inverseCacheProxy.inverse):e.identity(),e}}function Gt(e,t,i,n){return new(i||(i=Promise))((function(r,o){function s(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}l((n=n.apply(e,t||[])).next())}))}function Yt(e,t){const i=[];let n=e;for(;null!==n;)i.unshift(n),n=n.parent;i.forEach((e=>{t(e)}))}function qt(e,t){e.children.forEach((e=>{t(e)||qt(e,t)}))}class $t{constructor(){this._joints=new Set,this._objectSpringBonesMap=new Map}get joints(){return this._joints}get springBones(){return console.warn("VRMSpringBoneManager: springBones is deprecated. use joints instead."),this._joints}get colliderGroups(){const e=new Set;return this._joints.forEach((t=>{t.colliderGroups.forEach((t=>{e.add(t)}))})),Array.from(e)}get colliders(){const e=new Set;return this.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{e.add(t)}))})),Array.from(e)}addJoint(e){this._joints.add(e);let t=this._objectSpringBonesMap.get(e.bone);null==t&&(t=new Set,this._objectSpringBonesMap.set(e.bone,t)),t.add(e)}addSpringBone(e){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(e)}deleteJoint(e){this._joints.delete(e);this._objectSpringBonesMap.get(e.bone).delete(e)}deleteSpringBone(e){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(e)}setInitState(){const e=new Set,t=new Set,i=new Set;for(const n of this._joints)this._processSpringBone(n,e,t,i,(e=>e.setInitState()))}reset(){const e=new Set,t=new Set,i=new Set;for(const n of this._joints)this._processSpringBone(n,e,t,i,(e=>e.reset()))}update(e){const t=new Set,i=new Set,n=new Set;for(const r of this._joints)this._processSpringBone(r,t,i,n,(t=>t.update(e))),qt(r.bone,(e=>{var t,i;return(null!==(i=null===(t=this._objectSpringBonesMap.get(e))||void 0===t?void 0:t.size)&&void 0!==i?i:0)>0||(e.updateWorldMatrix(!1,!1),!1)}))}_processSpringBone(e,t,i,n,r){if(i.has(e))return;if(t.has(e))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");t.add(e);const o=this._getDependencies(e);for(const e of o)Yt(e,(e=>{const o=this._objectSpringBonesMap.get(e);if(o)for(const e of o)this._processSpringBone(e,t,i,n,r);else n.has(e)||(e.updateWorldMatrix(!1,!1),n.add(e))}));e.bone.updateMatrix(),e.bone.updateWorldMatrix(!1,!1),r(e),n.add(e.bone),i.add(e)}_getDependencies(e){const t=new Set,i=e.bone.parent;return i&&t.add(i),e.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{t.add(e)}))})),t}}const Zt=new Set(["1.0","1.0-beta"]);class Jt{get name(){return Jt.EXTENSION_NAME}constructor(e,t){this.parser=e,this.jointHelperRoot=null==t?void 0:t.jointHelperRoot,this.colliderHelperRoot=null==t?void 0:t.colliderHelperRoot}afterRoot(e){return Gt(this,void 0,void 0,(function*(){e.userData.vrmSpringBoneManager=yield this._import(e)}))}_import(e){return Gt(this,void 0,void 0,(function*(){const t=yield this._v1Import(e);if(null!=t)return t;const i=yield this._v0Import(e);return null!=i?i:null}))}_v1Import(t){var i,n,r,o,s;return Gt(this,void 0,void 0,(function*(){const a=t.parser.json;if(!(-1!==(null===(i=a.extensionsUsed)||void 0===i?void 0:i.indexOf(Jt.EXTENSION_NAME))))return null;const l=new $t,u=yield t.parser.getDependencies("node"),d=null===(n=a.extensions)||void 0===n?void 0:n[Jt.EXTENSION_NAME];if(!d)return null;const h=d.specVersion;if(!Zt.has(h))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${Jt.EXTENSION_NAME} specVersion "${h}"`),null;const c=null===(r=d.colliders)||void 0===r?void 0:r.map(((t,i)=>{var n,r,o,s,a;const l=u[t.node],d=t.shape;if(d.sphere)return this._importSphereCollider(l,{offset:(new e.Vector3).fromArray(null!==(n=d.sphere.offset)&&void 0!==n?n:[0,0,0]),radius:null!==(r=d.sphere.radius)&&void 0!==r?r:0});if(d.capsule)return this._importCapsuleCollider(l,{offset:(new e.Vector3).fromArray(null!==(o=d.capsule.offset)&&void 0!==o?o:[0,0,0]),radius:null!==(s=d.capsule.radius)&&void 0!==s?s:0,tail:(new e.Vector3).fromArray(null!==(a=d.capsule.tail)&&void 0!==a?a:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${i} has no valid shape`)})),p=null===(o=d.colliderGroups)||void 0===o?void 0:o.map(((e,t)=>{var i;return{colliders:(null!==(i=e.colliders)&&void 0!==i?i:[]).map((e=>{const i=null==c?void 0:c[e];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${t} attempted to use a collider #${e} but not found`);return i})),name:e.name}}));return null===(s=d.springs)||void 0===s||s.forEach(((t,i)=>{var n;const r=t.joints,o=null===(n=t.colliderGroups)||void 0===n?void 0:n.map((e=>{const t=null==p?void 0:p[e];if(null==t)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${e} but not found`);return t})),s=null!=t.center?u[t.center]:void 0;let a;r.forEach((t=>{if(a){const i=a.node,n=u[i],r=t.node,d=u[r],h={hitRadius:a.hitRadius,dragForce:a.dragForce,gravityPower:a.gravityPower,stiffness:a.stiffness,gravityDir:null!=a.gravityDir?(new e.Vector3).fromArray(a.gravityDir):void 0},c=this._importJoint(n,d,h,o);s&&(c.center=s),l.addJoint(c)}a=t}))})),l.setInitState(),l}))}_v0Import(t){var i,n,r;return Gt(this,void 0,void 0,(function*(){const o=t.parser.json;if(!(-1!==(null===(i=o.extensionsUsed)||void 0===i?void 0:i.indexOf("VRM"))))return null;const s=null===(n=o.extensions)||void 0===n?void 0:n.VRM,a=null==s?void 0:s.secondaryAnimation;if(!a)return null;const l=null==a?void 0:a.boneGroups;if(!l)return null;const u=new $t,d=yield t.parser.getDependencies("node"),h=null===(r=a.colliderGroups)||void 0===r?void 0:r.map((t=>{var i;const n=d[t.node],r=(null!==(i=t.colliders)&&void 0!==i?i:[]).map(((t,i)=>{var r,o,s;const a=new e.Vector3(0,0,0);return t.offset&&a.set(null!==(r=t.offset.x)&&void 0!==r?r:0,null!==(o=t.offset.y)&&void 0!==o?o:0,t.offset.z?-t.offset.z:0),this._importSphereCollider(n,{offset:a,radius:null!==(s=t.radius)&&void 0!==s?s:0})}));return{colliders:r}}));return null==l||l.forEach(((t,i)=>{const n=t.bones;n&&n.forEach((n=>{var r,o,s,a;const l=d[n],c=new e.Vector3;t.gravityDir?c.set(null!==(r=t.gravityDir.x)&&void 0!==r?r:0,null!==(o=t.gravityDir.y)&&void 0!==o?o:0,null!==(s=t.gravityDir.z)&&void 0!==s?s:0):c.set(0,-1,0);const p=null!=t.center?d[t.center]:void 0,m={hitRadius:t.hitRadius,dragForce:t.dragForce,gravityPower:t.gravityPower,stiffness:t.stiffiness,gravityDir:c},f=null===(a=t.colliderGroups)||void 0===a?void 0:a.map((e=>{const t=null==h?void 0:h[e];if(null==t)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${e} but not found`);return t}));l.traverse((e=>{var t;const i=null!==(t=e.children[0])&&void 0!==t?t:null,n=this._importJoint(e,i,m,f);p&&(n.center=p),u.addJoint(n)}))}))})),t.scene.updateMatrixWorld(),u.setInitState(),u}))}_importJoint(e,t,i,n){const r=new Xt(e,t,i,n);if(this.jointHelperRoot){const e=new It(r);this.jointHelperRoot.add(e),e.renderOrder=this.jointHelperRoot.renderOrder}return r}_importSphereCollider(e,t){const{offset:i,radius:n}=t,r=new Rt({offset:i,radius:n}),o=new Ut(r);if(e.add(o),this.colliderHelperRoot){const e=new St(o);this.colliderHelperRoot.add(e),e.renderOrder=this.colliderHelperRoot.renderOrder}return o}_importCapsuleCollider(e,t){const{offset:i,radius:n,tail:r}=t,o=new Tt({offset:i,radius:n,tail:r}),s=new Ut(o);if(e.add(s),this.colliderHelperRoot){const e=new St(s);this.colliderHelperRoot.add(e),e.renderOrder=this.colliderHelperRoot.renderOrder}return s}}Jt.EXTENSION_NAME="VRMC_springBone";class Kt{get name(){return"VRMLoaderPlugin"}constructor(e,t){var i,n,r,o,s,a,l,u,d,h;this.parser=e;const c=null==t?void 0:t.helperRoot,p=null==t?void 0:t.autoUpdateHumanBones;this.expressionPlugin=null!==(i=null==t?void 0:t.expressionPlugin)&&void 0!==i?i:new M(e),this.firstPersonPlugin=null!==(n=null==t?void 0:t.firstPersonPlugin)&&void 0!==n?n:new R(e),this.humanoidPlugin=null!==(r=null==t?void 0:t.humanoidPlugin)&&void 0!==r?r:new Q(e,{helperRoot:c,autoUpdateHumanBones:p}),this.lookAtPlugin=null!==(o=null==t?void 0:t.lookAtPlugin)&&void 0!==o?o:new we(e,{helperRoot:c}),this.metaPlugin=null!==(s=null==t?void 0:t.metaPlugin)&&void 0!==s?s:new Ae(e),this.mtoonMaterialPlugin=null!==(a=null==t?void 0:t.mtoonMaterialPlugin)&&void 0!==a?a:new ke(e),this.materialsHDREmissiveMultiplierPlugin=null!==(l=null==t?void 0:t.materialsHDREmissiveMultiplierPlugin)&&void 0!==l?l:new ze(e),this.materialsV0CompatPlugin=null!==(u=null==t?void 0:t.materialsV0CompatPlugin)&&void 0!==u?u:new Xe(e),this.springBonePlugin=null!==(d=null==t?void 0:t.springBonePlugin)&&void 0!==d?d:new Jt(e,{colliderHelperRoot:c,jointHelperRoot:c}),this.nodeConstraintPlugin=null!==(h=null==t?void 0:t.nodeConstraintPlugin)&&void 0!==h?h:new _t(e,{helperRoot:c})}beforeRoot(){return Ie(this,void 0,void 0,(function*(){yield this.materialsV0CompatPlugin.beforeRoot(),yield this.mtoonMaterialPlugin.beforeRoot()}))}loadMesh(e){return Ie(this,void 0,void 0,(function*(){return yield this.mtoonMaterialPlugin.loadMesh(e)}))}getMaterialType(e){const t=this.mtoonMaterialPlugin.getMaterialType(e);return null!=t?t:null}extendMaterialParams(e,t){return Ie(this,void 0,void 0,(function*(){yield this.materialsHDREmissiveMultiplierPlugin.extendMaterialParams(e,t),yield this.mtoonMaterialPlugin.extendMaterialParams(e,t)}))}afterRoot(e){return Ie(this,void 0,void 0,(function*(){yield this.metaPlugin.afterRoot(e),yield this.humanoidPlugin.afterRoot(e),yield this.expressionPlugin.afterRoot(e),yield this.lookAtPlugin.afterRoot(e),yield this.firstPersonPlugin.afterRoot(e),yield this.springBonePlugin.afterRoot(e),yield this.nodeConstraintPlugin.afterRoot(e),yield this.mtoonMaterialPlugin.afterRoot(e);const t=e.userData.vrmMeta,i=e.userData.vrmHumanoid;if(t&&i){const n=new be({scene:e.scene,expressionManager:e.userData.vrmExpressionManager,firstPerson:e.userData.vrmFirstPerson,humanoid:i,lookAt:e.userData.vrmLookAt,meta:t,materials:e.userData.vrmMToonMaterials,springBoneManager:e.userData.vrmSpringBoneManager,nodeConstraintManager:e.userData.vrmNodeConstraintManager});e.userData.vrm=n}}))}}function ei(e){if(Object.values(e).forEach((e=>{if(null==e?void 0:e.isTexture){e.dispose()}})),e.isShaderMaterial){const t=e.uniforms;t&&Object.values(t).forEach((e=>{const t=e.value;if(null==t?void 0:t.isTexture){t.dispose()}}))}e.dispose()}function ti(e){const t=e.geometry;t&&t.dispose();const i=e.skeleton;i&&i.dispose();const n=e.material;n&&(Array.isArray(n)?n.forEach((e=>ei(e))):n&&ei(n))}class ii{constructor(){}}ii.deepDispose=function(e){e.traverse(ti)},ii.removeUnnecessaryJoints=function(t){const i=new Map;t.traverse((t=>{if("SkinnedMesh"!==t.type)return;const n=t,r=n.geometry.getAttribute("skinIndex");let o=i.get(r);if(!o){const t=[],s=[],a={},l=r.array;for(let e=0;e<l.length;e++){const i=l[e];void 0===a[i]&&(a[i]=t.length,t.push(n.skeleton.bones[i]),s.push(n.skeleton.boneInverses[i])),l[e]=a[i]}r.copyArray(l),r.needsUpdate=!0,o=new e.Skeleton(t,s),i.set(r,o)}n.bind(o,new e.Matrix4)}))},ii.removeUnnecessaryVertices=function(i){const n=new Map;i.traverse((i=>{var r,o,s,a;if(!i.isMesh)return;const l=i,u=l.geometry,d=u.index;if(null==d)return;const h=n.get(u);if(null!=h)return void(l.geometry=h);const c=new e.BufferGeometry;c.name=u.name,c.morphTargetsRelative=u.morphTargetsRelative,u.groups.forEach((e=>{c.addGroup(e.start,e.count,e.materialIndex)})),c.boundingBox=null!==(o=null===(r=u.boundingBox)||void 0===r?void 0:r.clone())&&void 0!==o?o:null,c.boundingSphere=null!==(a=null===(s=u.boundingSphere)||void 0===s?void 0:s.clone())&&void 0!==a?a:null,c.setDrawRange(u.drawRange.start,u.drawRange.count),c.userData=u.userData,n.set(u,c);const p=[],m=[];{const e=d.array,i=new e.constructor(e.length);let n=0;for(let t=0;t<e.length;t++){const r=e[t];let o=p[r];null==o&&(p[r]=n,m[n]=r,o=n,n++),i[t]=o}c.setIndex(new t(i,1,!1))}Object.keys(u.attributes).forEach((e=>{const i=u.attributes[e];if(i.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");const n=i.array,{itemSize:r,normalized:o}=i,s=new n.constructor(m.length*r);m.forEach(((e,t)=>{for(let i=0;i<r;i++)s[t*r+i]=n[e*r+i]})),c.setAttribute(e,new t(s,r,o))}));let f=!0;Object.keys(u.morphAttributes).forEach((e=>{c.morphAttributes[e]=[];const i=u.morphAttributes[e];for(let n=0;n<i.length;n++){const r=i[n];if(r.isInterleavedBufferAttribute)throw new Error("removeUnnecessaryVertices: InterleavedBufferAttribute is not supported");const o=r.array,{itemSize:s,normalized:a}=r,l=new o.constructor(m.length*s);m.forEach(((e,t)=>{for(let i=0;i<s;i++)l[t*s+i]=o[e*s+i]})),f=f&&l.every((e=>0===e)),c.morphAttributes[e][n]=new t(l,s,a)}})),f&&(c.morphAttributes={}),l.geometry=c})),Array.from(n.keys()).forEach((e=>{e.dispose()}))},ii.rotateVRM0=function(e){var t;"0"===(null===(t=e.meta)||void 0===t?void 0:t.metaVersion)&&(e.scene.rotation.y=Math.PI)};export{De as MToonMaterial,Oe as MToonMaterialDebugMode,ke as MToonMaterialLoaderPlugin,Ne as MToonMaterialOutlineWidthMode,be as VRM,st as VRMAimConstraint,Se as VRMCore,Le as VRMCoreLoaderPlugin,i as VRMExpression,M as VRMExpressionLoaderPlugin,d as VRMExpressionManager,m as VRMExpressionMaterialColorBind,h as VRMExpressionMaterialColorType,f as VRMExpressionMorphTargetBind,x as VRMExpressionOverrideType,l as VRMExpressionPresetName,g as VRMExpressionTextureTransformBind,y as VRMFirstPerson,R as VRMFirstPersonLoaderPlugin,w as VRMFirstPersonMeshAnnotationType,L as VRMHumanBoneList,b as VRMHumanBoneName,I as VRMHumanBoneParentMap,H as VRMHumanoid,S as VRMHumanoidHelper,Q as VRMHumanoidLoaderPlugin,Kt as VRMLoaderPlugin,fe as VRMLookAt,xe as VRMLookAtBoneApplier,ye as VRMLookAtExpressionApplier,ee as VRMLookAtHelper,we as VRMLookAtLoaderPlugin,Te as VRMLookAtRangeMap,Ee as VRMLookAtTypeName,Ae as VRMMetaLoaderPlugin,Ke as VRMNodeConstraint,Ye as VRMNodeConstraintHelper,_t as VRMNodeConstraintLoaderPlugin,ut as VRMNodeConstraintManager,k as VRMRequiredHumanBoneName,vt as VRMRollConstraint,ct as VRMRotationConstraint,Ut as VRMSpringBoneCollider,St as VRMSpringBoneColliderHelper,Mt as VRMSpringBoneColliderShape,Tt as VRMSpringBoneColliderShapeCapsule,Rt as VRMSpringBoneColliderShapeSphere,Xt as VRMSpringBoneJoint,It as VRMSpringBoneJointHelper,Jt as VRMSpringBoneLoaderPlugin,$t as VRMSpringBoneManager,ii as VRMUtils};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixiv/three-vrm",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "description": "VRM file loader for three.js.",
5
5
  "license": "MIT",
6
6
  "author": "pixiv",
@@ -46,11 +46,11 @@
46
46
  ]
47
47
  },
48
48
  "dependencies": {
49
- "@pixiv/three-vrm-core": "2.0.4",
49
+ "@pixiv/three-vrm-core": "2.0.5",
50
50
  "@pixiv/three-vrm-materials-hdr-emissive-multiplier": "2.0.3",
51
51
  "@pixiv/three-vrm-materials-mtoon": "2.0.3",
52
52
  "@pixiv/three-vrm-materials-v0compat": "2.0.4",
53
- "@pixiv/three-vrm-node-constraint": "2.0.3",
53
+ "@pixiv/three-vrm-node-constraint": "2.0.5",
54
54
  "@pixiv/three-vrm-springbone": "2.0.3"
55
55
  },
56
56
  "devDependencies": {
@@ -63,5 +63,5 @@
63
63
  "@types/three": "^0.154.0",
64
64
  "three": "^0.154.0"
65
65
  },
66
- "gitHead": "fc417d5099d144ff947b4b7c457b5c31add5f78f"
66
+ "gitHead": "71fa8c97f9931902613f4299d08919a5bcb9f44f"
67
67
  }