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

@pixiv/three-vrm-springbone

Package Overview
Dependencies
Maintainers
6
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

Comparing version 1.0.7 to 1.0.9

2

lib/three-vrm-springbone.min.js
/*! (c) 2020-2023 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("three")):"function"==typeof define&&define.amd?define(["exports","three"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).THREE_VRM_SPRINGBONE={},t.THREE)}(this,(function(t,e){"use strict";function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,r.get?r:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var r=i(e);class s{}const n=new r.Vector3,o=new r.Vector3;class a extends s{constructor(t){var e,i,s;super(),this.offset=null!==(e=null==t?void 0:t.offset)&&void 0!==e?e:new r.Vector3(0,0,0),this.tail=null!==(i=null==t?void 0:t.tail)&&void 0!==i?i:new r.Vector3(0,0,0),this.radius=null!==(s=null==t?void 0:t.radius)&&void 0!==s?s:0}get type(){return"capsule"}calculateCollision(t,e,i,r){n.copy(this.offset).applyMatrix4(t),o.copy(this.tail).applyMatrix4(t),o.sub(n);const s=o.lengthSq();r.copy(e).sub(n);const a=o.dot(r);a<=0||(s<=a||o.multiplyScalar(a/s),r.sub(o));const l=i+this.radius,d=r.length()-l;return r.normalize(),d}}class l extends s{constructor(t){var e,i;super(),this.offset=null!==(e=null==t?void 0:t.offset)&&void 0!==e?e:new r.Vector3(0,0,0),this.radius=null!==(i=null==t?void 0:t.radius)&&void 0!==i?i:0}get type(){return"sphere"}calculateCollision(t,e,i,r){r.copy(this.offset).applyMatrix4(t),r.negate().add(e);const s=i+this.radius,n=r.length()-s;return r.normalize(),n}}const d=new r.Vector3;class h extends r.BufferGeometry{constructor(t){super(),this._currentRadius=0,this._currentOffset=new r.Vector3,this._currentTail=new r.Vector3,this._shape=t,this._attrPos=new r.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new r.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._shape.radius&&(this._currentRadius=this._shape.radius,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),this._currentTail.equals(this._shape.tail)||(this._currentTail.copy(this._shape.tail),t=!0),t&&this._buildPosition()}_buildPosition(){d.copy(this._currentTail).sub(this._currentOffset);const t=d.length()/this._currentRadius;for(let e=0;e<=16;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(e,-Math.sin(i),-Math.cos(i),0),this._attrPos.setXYZ(17+e,t+Math.sin(i),Math.cos(i),0),this._attrPos.setXYZ(34+e,-Math.sin(i),0,-Math.cos(i)),this._attrPos.setXYZ(51+e,t+Math.sin(i),0,Math.cos(i))}for(let e=0;e<32;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(68+e,0,Math.sin(i),Math.cos(i)),this._attrPos.setXYZ(100+e,t,Math.sin(i),Math.cos(i))}const e=Math.atan2(d.y,Math.sqrt(d.x*d.x+d.z*d.z)),i=-Math.atan2(d.z,d.x);this.rotateZ(e),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 t=0;t<34;t++){const e=(t+1)%34;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(68+2*t,34+t,34+e)}for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(136+2*t,68+t,68+e),this._attrIndex.setXY(200+2*t,100+t,100+e)}this._attrIndex.needsUpdate=!0}}class c extends r.BufferGeometry{constructor(t){super(),this._currentRadius=0,this._currentOffset=new r.Vector3,this._shape=t,this._attrPos=new r.BufferAttribute(new Float32Array(288),3),this.setAttribute("position",this._attrPos),this._attrIndex=new r.BufferAttribute(new Uint16Array(192),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._shape.radius&&(this._currentRadius=this._shape.radius,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.needsUpdate=!0}}class u extends r.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof l)this._geometry=new c(this.collider.shape);else{if(!(this.collider.shape instanceof a))throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");this._geometry=new h(this.collider.shape)}const e=new r.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new r.LineSegments(this._geometry,e),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld),this._geometry.update(),super.updateMatrixWorld(t)}}class p extends r.BufferGeometry{constructor(t){super(),this._currentRadius=0,this._currentTail=new r.Vector3,this._springBone=t,this._attrPos=new r.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new r.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._springBone.settings.hitRadius&&(this._currentRadius=this._springBone.settings.hitRadius,t=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}}class _ extends r.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new p(this.springBone);const e=new r.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new r.LineSegments(this._geometry,e),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld),this._geometry.update(),super.updateMatrixWorld(t)}}class f extends r.Object3D{constructor(t){super(),this.shape=t}}const g=new r.Matrix4;function v(t){return t.invert?t.invert():t.getInverse(g.copy(t)),t}class y{constructor(t){this._inverseCache=new r.Matrix4,this._shouldUpdateInverse=!0,this.matrix=t;const e={set:(t,e,i)=>(this._shouldUpdateInverse=!0,t[e]=i,!0)};this._originalElements=t.elements,t.elements=new Proxy(t.elements,e)}get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),v(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}}const x=new r.Matrix4,M=new r.Vector3,w=new r.Vector3,m=new r.Vector3,b=new r.Vector3,S=new r.Vector3,R=new r.Vector3,P=new r.Quaternion,B=new r.Matrix4,I=new r.Matrix4;class V{constructor(t,e,i={},s=[]){var n,o,a,l,d,h;this._currentTail=new r.Vector3,this._prevTail=new r.Vector3,this._boneAxis=new r.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new r.Matrix4,this._initialLocalRotation=new r.Quaternion,this._initialLocalChildPosition=new r.Vector3,this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=e,this.settings={hitRadius:null!==(n=i.hitRadius)&&void 0!==n?n:0,stiffness:null!==(o=i.stiffness)&&void 0!==o?o:1,gravityPower:null!==(a=i.gravityPower)&&void 0!==a?a:0,gravityDir:null!==(d=null===(l=i.gravityDir)||void 0===l?void 0:l.clone())&&void 0!==d?d:new r.Vector3(0,-1,0),dragForce:null!==(h=i.dragForce)&&void 0!==h?h:.4},this.colliderGroups=s}get center(){return this._center}set center(t){var e;(null===(e=this._center)||void 0===e?void 0:e.userData.inverseCacheProxy)&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=t,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new y(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:x}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 t=this._getMatrixWorldToCenter(B);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);const t=this._getMatrixWorldToCenter(B);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength(),b.setFromMatrixPosition(this.bone.matrixWorld);let e=this._getMatrixWorldToCenter(B);S.copy(b).applyMatrix4(e);const i=P.setFromRotationMatrix(e),r=I.copy(e).multiply(this._parentMatrixWorld),s=w.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(r).sub(S).normalize(),n=m.copy(this.settings.gravityDir).applyQuaternion(i).normalize(),o=this._getMatrixCenterToWorld(B);R.copy(this._currentTail).add(M.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(M.copy(s).multiplyScalar(this.settings.stiffness*t)).add(M.copy(n).multiplyScalar(this.settings.gravityPower*t)).applyMatrix4(o),R.sub(b).normalize().multiplyScalar(this._worldSpaceBoneLength).add(b),this._collision(R),e=this._getMatrixWorldToCenter(B),this._prevTail.copy(this._currentTail),this._currentTail.copy(M.copy(R).applyMatrix4(e));const a=v(B.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),l=P.setFromUnitVectors(this._boneAxis,M.copy(R).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(l),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{const i=e.shape.calculateCollision(e.matrixWorld,t,this.settings.hitRadius,M);i<0&&(t.add(M.multiplyScalar(-i)),t.sub(b).normalize().multiplyScalar(this._worldSpaceBoneLength).add(b))}))}))}_calcWorldSpaceBoneLength(){M.setFromMatrixPosition(this.bone.matrixWorld),this.child?w.setFromMatrixPosition(this.child.matrixWorld):(w.copy(this._initialLocalChildPosition),w.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=M.sub(w).length()}_getMatrixCenterToWorld(t){return this._center?t.copy(this._center.matrixWorld):t.identity(),t}_getMatrixWorldToCenter(t){return this._center?t.copy(this._center.userData.inverseCacheProxy.inverse):t.identity(),t}}function T(t,e,i,r){return new(i||(i=Promise))((function(s,n){function o(t){try{l(r.next(t))}catch(t){n(t)}}function a(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}l((r=r.apply(t,e||[])).next())}))}function C(t,e){const i=[];let r=t;for(;null!==r;)i.unshift(r),r=r.parent;i.forEach((t=>{e(t)}))}function E(t,e){t.children.forEach((t=>{e(t)||E(t,e)}))}class W{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 t=new Set;return this._joints.forEach((e=>{e.colliderGroups.forEach((e=>{t.add(e)}))})),Array.from(t)}get colliders(){const t=new Set;return this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{t.add(e)}))})),Array.from(t)}addJoint(t){this._joints.add(t);let e=this._objectSpringBonesMap.get(t.bone);null==e&&(e=new Set,this._objectSpringBonesMap.set(t.bone,e)),e.add(t)}addSpringBone(t){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(t)}deleteJoint(t){this._joints.delete(t);this._objectSpringBonesMap.get(t.bone).delete(t)}deleteSpringBone(t){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(t)}setInitState(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.setInitState()))}reset(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.reset()))}update(t){const e=new Set,i=new Set,r=new Set;for(const s of this._joints)this._processSpringBone(s,e,i,r,(e=>e.update(t))),E(s.bone,(t=>{var e,i;return(null!==(i=null===(e=this._objectSpringBonesMap.get(t))||void 0===e?void 0:e.size)&&void 0!==i?i:0)>0||(t.updateWorldMatrix(!1,!1),!1)}))}_processSpringBone(t,e,i,r,s){if(i.has(t))return;if(e.has(t))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");e.add(t);const n=this._getDependencies(t);for(const t of n)C(t,(t=>{const n=this._objectSpringBonesMap.get(t);if(n)for(const t of n)this._processSpringBone(t,e,i,r,s);else r.has(t)||(t.updateWorldMatrix(!1,!1),r.add(t))}));t.bone.updateMatrix(),t.bone.updateWorldMatrix(!1,!1),s(t),r.add(t.bone),i.add(t)}_getDependencies(t){const e=new Set,i=t.bone.parent;return i&&e.add(i),t.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{e.add(t)}))})),e}}const O=new Set(["1.0","1.0-beta"]);class L{constructor(t,e){this.parser=t,this.jointHelperRoot=null==e?void 0:e.jointHelperRoot,this.colliderHelperRoot=null==e?void 0:e.colliderHelperRoot}get name(){return L.EXTENSION_NAME}afterRoot(t){return T(this,void 0,void 0,(function*(){t.userData.vrmSpringBoneManager=yield this._import(t)}))}_import(t){return T(this,void 0,void 0,(function*(){const e=yield this._v1Import(t);if(null!=e)return e;const i=yield this._v0Import(t);return null!=i?i:null}))}_v1Import(t){var e,i,s,n,o;return T(this,void 0,void 0,(function*(){const a=t.parser.json;if(!(-1!==(null===(e=a.extensionsUsed)||void 0===e?void 0:e.indexOf(L.EXTENSION_NAME))))return null;const l=new W,d=yield t.parser.getDependencies("node"),h=null===(i=a.extensions)||void 0===i?void 0:i[L.EXTENSION_NAME];if(!h)return null;const c=h.specVersion;if(!O.has(c))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${L.EXTENSION_NAME} specVersion "${c}"`),null;const u=null===(s=h.colliders)||void 0===s?void 0:s.map(((t,e)=>{var i,s,n,o,a;const l=d[t.node],h=t.shape;if(h.sphere)return this._importSphereCollider(l,{offset:(new r.Vector3).fromArray(null!==(i=h.sphere.offset)&&void 0!==i?i:[0,0,0]),radius:null!==(s=h.sphere.radius)&&void 0!==s?s:0});if(h.capsule)return this._importCapsuleCollider(l,{offset:(new r.Vector3).fromArray(null!==(n=h.capsule.offset)&&void 0!==n?n:[0,0,0]),radius:null!==(o=h.capsule.radius)&&void 0!==o?o:0,tail:(new r.Vector3).fromArray(null!==(a=h.capsule.tail)&&void 0!==a?a:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${e} has no valid shape`)})),p=null===(n=h.colliderGroups)||void 0===n?void 0:n.map(((t,e)=>{var i;return{colliders:(null!==(i=t.colliders)&&void 0!==i?i:[]).map((t=>{const i=null==u?void 0:u[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${e} attempted to use a collider #${t} but not found`);return i})),name:t.name}}));return null===(o=h.springs)||void 0===o||o.forEach(((t,e)=>{var i;const s=t.joints,n=null===(i=t.colliderGroups)||void 0===i?void 0:i.map((t=>{const i=null==p?void 0:p[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${e} attempted to use a colliderGroup ${t} but not found`);return i})),o=null!=t.center?d[t.center]:void 0;let a;s.forEach((t=>{if(a){const e=a.node,i=d[e],s=t.node,h=d[s],c={hitRadius:a.hitRadius,dragForce:a.dragForce,gravityPower:a.gravityPower,stiffness:a.stiffness,gravityDir:null!=a.gravityDir?(new r.Vector3).fromArray(a.gravityDir):void 0},u=this._importJoint(i,h,c,n);o&&(u.center=o),l.addJoint(u)}a=t}))})),l.setInitState(),l}))}_v0Import(t){var e,i,s;return T(this,void 0,void 0,(function*(){const n=t.parser.json;if(!(-1!==(null===(e=n.extensionsUsed)||void 0===e?void 0:e.indexOf("VRM"))))return null;const o=null===(i=n.extensions)||void 0===i?void 0:i.VRM,a=null==o?void 0:o.secondaryAnimation;if(!a)return null;const l=null==a?void 0:a.boneGroups;if(!l)return null;const d=new W,h=yield t.parser.getDependencies("node"),c=null===(s=a.colliderGroups)||void 0===s?void 0:s.map((t=>{var e;const i=h[t.node],s=(null!==(e=t.colliders)&&void 0!==e?e:[]).map(((t,e)=>{var s,n,o;const a=new r.Vector3(0,0,0);return t.offset&&a.set(null!==(s=t.offset.x)&&void 0!==s?s:0,null!==(n=t.offset.y)&&void 0!==n?n:0,t.offset.z?-t.offset.z:0),this._importSphereCollider(i,{offset:a,radius:null!==(o=t.radius)&&void 0!==o?o:0})}));return{colliders:s}}));return null==l||l.forEach(((t,e)=>{const i=t.bones;i&&i.forEach((i=>{var s,n,o,a;const l=h[i],u=new r.Vector3;t.gravityDir?u.set(null!==(s=t.gravityDir.x)&&void 0!==s?s:0,null!==(n=t.gravityDir.y)&&void 0!==n?n:0,null!==(o=t.gravityDir.z)&&void 0!==o?o:0):u.set(0,-1,0);const p=null!=t.center?h[t.center]:void 0,_={hitRadius:t.hitRadius,dragForce:t.dragForce,gravityPower:t.gravityPower,stiffness:t.stiffiness,gravityDir:u},f=null===(a=t.colliderGroups)||void 0===a?void 0:a.map((t=>{const i=null==c?void 0:c[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${e} attempted to use a colliderGroup ${t} but not found`);return i}));l.traverse((t=>{var e;const i=null!==(e=t.children[0])&&void 0!==e?e:null,r=this._importJoint(t,i,_,f);p&&(r.center=p),d.addJoint(r)}))}))})),t.scene.updateMatrixWorld(),d.setInitState(),d}))}_importJoint(t,e,i,r){const s=new V(t,e,i,r);if(this.jointHelperRoot){const t=new _(s);this.jointHelperRoot.add(t),t.renderOrder=this.jointHelperRoot.renderOrder}return s}_importSphereCollider(t,e){const{offset:i,radius:r}=e,s=new l({offset:i,radius:r}),n=new f(s);if(t.add(n),this.colliderHelperRoot){const t=new u(n);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return n}_importCapsuleCollider(t,e){const{offset:i,radius:r,tail:s}=e,n=new a({offset:i,radius:r,tail:s}),o=new f(n);if(t.add(o),this.colliderHelperRoot){const t=new u(o);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return o}}L.EXTENSION_NAME="VRMC_springBone",t.VRMSpringBoneCollider=f,t.VRMSpringBoneColliderHelper=u,t.VRMSpringBoneColliderShape=s,t.VRMSpringBoneColliderShapeCapsule=a,t.VRMSpringBoneColliderShapeSphere=l,t.VRMSpringBoneJoint=V,t.VRMSpringBoneJointHelper=_,t.VRMSpringBoneLoaderPlugin=L,t.VRMSpringBoneManager=W,Object.defineProperty(t,"__esModule",{value:!0}),Object.assign(e,t)}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("three")):"function"==typeof define&&define.amd?define(["exports","three"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).THREE_VRM_SPRINGBONE={},t.THREE)}(this,(function(t,e){"use strict";function i(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var r=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,r.get?r:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var r=i(e);class s{}const n=new r.Vector3,o=new r.Vector3;class a extends s{constructor(t){var e,i,s;super(),this.offset=null!==(e=null==t?void 0:t.offset)&&void 0!==e?e:new r.Vector3(0,0,0),this.tail=null!==(i=null==t?void 0:t.tail)&&void 0!==i?i:new r.Vector3(0,0,0),this.radius=null!==(s=null==t?void 0:t.radius)&&void 0!==s?s:0}get type(){return"capsule"}calculateCollision(t,e,i,r){n.copy(this.offset).applyMatrix4(t),o.copy(this.tail).applyMatrix4(t),o.sub(n);const s=o.lengthSq();r.copy(e).sub(n);const a=o.dot(r);a<=0||(s<=a||o.multiplyScalar(a/s),r.sub(o));const l=i+this.radius,d=r.length()-l;return r.normalize(),d}}class l extends s{constructor(t){var e,i;super(),this.offset=null!==(e=null==t?void 0:t.offset)&&void 0!==e?e:new r.Vector3(0,0,0),this.radius=null!==(i=null==t?void 0:t.radius)&&void 0!==i?i:0}get type(){return"sphere"}calculateCollision(t,e,i,r){r.copy(this.offset).applyMatrix4(t),r.negate().add(e);const s=i+this.radius,n=r.length()-s;return r.normalize(),n}}const d=new r.Vector3;class c extends r.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new r.Vector3,this._currentTail=new r.Vector3,this._shape=t,this._attrPos=new r.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new r.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;const e=this._shape.radius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0);const i=d.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(i)>1e-10&&(this._currentTail.copy(i),t=!0),t&&this._buildPosition()}_buildPosition(){d.copy(this._currentTail).sub(this._currentOffset);const t=d.length()/this._currentRadius;for(let e=0;e<=16;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(e,-Math.sin(i),-Math.cos(i),0),this._attrPos.setXYZ(17+e,t+Math.sin(i),Math.cos(i),0),this._attrPos.setXYZ(34+e,-Math.sin(i),0,-Math.cos(i)),this._attrPos.setXYZ(51+e,t+Math.sin(i),0,Math.cos(i))}for(let e=0;e<32;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(68+e,0,Math.sin(i),Math.cos(i)),this._attrPos.setXYZ(100+e,t,Math.sin(i),Math.cos(i))}const e=Math.atan2(d.y,Math.sqrt(d.x*d.x+d.z*d.z)),i=-Math.atan2(d.z,d.x);this.rotateZ(e),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 t=0;t<34;t++){const e=(t+1)%34;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(68+2*t,34+t,34+e)}for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(136+2*t,68+t,68+e),this._attrIndex.setXY(200+2*t,100+t,100+e)}this._attrIndex.needsUpdate=!0}}class h extends r.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new r.Vector3,this._shape=t,this._attrPos=new r.BufferAttribute(new Float32Array(288),3),this.setAttribute("position",this._attrPos),this._attrIndex=new r.BufferAttribute(new Uint16Array(192),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;const e=this._shape.radius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.needsUpdate=!0}}const u=new r.Vector3;class p extends r.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof l)this._geometry=new h(this.collider.shape);else{if(!(this.collider.shape instanceof a))throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");this._geometry=new c(this.collider.shape)}const e=new r.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new r.LineSegments(this._geometry,e),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld);const e=this.matrix.elements;this._geometry.worldScale=u.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}}class _ extends r.BufferGeometry{constructor(t){super(),this.worldScale=1,this._currentRadius=0,this._currentTail=new r.Vector3,this._springBone=t,this._attrPos=new r.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new r.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;const e=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}}const f=new r.Vector3;class g extends r.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new _(this.springBone);const e=new r.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new r.LineSegments(this._geometry,e),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld);const e=this.matrix.elements;this._geometry.worldScale=f.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}}class y extends r.Object3D{constructor(t){super(),this.shape=t}}const v=new r.Matrix4;function x(t){return t.invert?t.invert():t.getInverse(v.copy(t)),t}class M{constructor(t){this._inverseCache=new r.Matrix4,this._shouldUpdateInverse=!0,this.matrix=t;const e={set:(t,e,i)=>(this._shouldUpdateInverse=!0,t[e]=i,!0)};this._originalElements=t.elements,t.elements=new Proxy(t.elements,e)}get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),x(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}}const w=new r.Matrix4,m=new r.Vector3,S=new r.Vector3,b=new r.Vector3,P=new r.Vector3,R=new r.Vector3,B=new r.Vector3,V=new r.Quaternion,I=new r.Matrix4,T=new r.Matrix4;class C{constructor(t,e,i={},s=[]){var n,o,a,l,d,c;this._currentTail=new r.Vector3,this._prevTail=new r.Vector3,this._boneAxis=new r.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new r.Matrix4,this._initialLocalRotation=new r.Quaternion,this._initialLocalChildPosition=new r.Vector3,this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=e,this.settings={hitRadius:null!==(n=i.hitRadius)&&void 0!==n?n:0,stiffness:null!==(o=i.stiffness)&&void 0!==o?o:1,gravityPower:null!==(a=i.gravityPower)&&void 0!==a?a:0,gravityDir:null!==(d=null===(l=i.gravityDir)||void 0===l?void 0:l.clone())&&void 0!==d?d:new r.Vector3(0,-1,0),dragForce:null!==(c=i.dragForce)&&void 0!==c?c:.4},this.colliderGroups=s}get center(){return this._center}set center(t){var e;(null===(e=this._center)||void 0===e?void 0:e.userData.inverseCacheProxy)&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=t,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new M(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:w}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 t=this._getMatrixWorldToCenter(I);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);const t=this._getMatrixWorldToCenter(I);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength(),P.setFromMatrixPosition(this.bone.matrixWorld);let e=this._getMatrixWorldToCenter(I);R.copy(P).applyMatrix4(e);const i=V.setFromRotationMatrix(e),r=T.copy(e).multiply(this._parentMatrixWorld),s=S.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(r).sub(R).normalize(),n=b.copy(this.settings.gravityDir).applyQuaternion(i).normalize(),o=this._getMatrixCenterToWorld(I);B.copy(this._currentTail).add(m.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(m.copy(s).multiplyScalar(this.settings.stiffness*t)).add(m.copy(n).multiplyScalar(this.settings.gravityPower*t)).applyMatrix4(o),B.sub(P).normalize().multiplyScalar(this._worldSpaceBoneLength).add(P),this._collision(B),e=this._getMatrixWorldToCenter(I),this._prevTail.copy(this._currentTail),this._currentTail.copy(m.copy(B).applyMatrix4(e));const a=x(I.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),l=V.setFromUnitVectors(this._boneAxis,m.copy(B).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(l),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{const i=e.shape.calculateCollision(e.matrixWorld,t,this.settings.hitRadius,m);i<0&&(t.add(m.multiplyScalar(-i)),t.sub(P).normalize().multiplyScalar(this._worldSpaceBoneLength).add(P))}))}))}_calcWorldSpaceBoneLength(){m.setFromMatrixPosition(this.bone.matrixWorld),this.child?S.setFromMatrixPosition(this.child.matrixWorld):(S.copy(this._initialLocalChildPosition),S.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=m.sub(S).length()}_getMatrixCenterToWorld(t){return this._center?t.copy(this._center.matrixWorld):t.identity(),t}_getMatrixWorldToCenter(t){return this._center?t.copy(this._center.userData.inverseCacheProxy.inverse):t.identity(),t}}function E(t,e,i,r){return new(i||(i=Promise))((function(s,n){function o(t){try{l(r.next(t))}catch(t){n(t)}}function a(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}l((r=r.apply(t,e||[])).next())}))}function W(t,e){const i=[];let r=t;for(;null!==r;)i.unshift(r),r=r.parent;i.forEach((t=>{e(t)}))}function O(t,e){t.children.forEach((t=>{e(t)||O(t,e)}))}class L{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 t=new Set;return this._joints.forEach((e=>{e.colliderGroups.forEach((e=>{t.add(e)}))})),Array.from(t)}get colliders(){const t=new Set;return this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{t.add(e)}))})),Array.from(t)}addJoint(t){this._joints.add(t);let e=this._objectSpringBonesMap.get(t.bone);null==e&&(e=new Set,this._objectSpringBonesMap.set(t.bone,e)),e.add(t)}addSpringBone(t){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(t)}deleteJoint(t){this._joints.delete(t);this._objectSpringBonesMap.get(t.bone).delete(t)}deleteSpringBone(t){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(t)}setInitState(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.setInitState()))}reset(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.reset()))}update(t){const e=new Set,i=new Set,r=new Set;for(const s of this._joints)this._processSpringBone(s,e,i,r,(e=>e.update(t))),O(s.bone,(t=>{var e,i;return(null!==(i=null===(e=this._objectSpringBonesMap.get(t))||void 0===e?void 0:e.size)&&void 0!==i?i:0)>0||(t.updateWorldMatrix(!1,!1),!1)}))}_processSpringBone(t,e,i,r,s){if(i.has(t))return;if(e.has(t))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");e.add(t);const n=this._getDependencies(t);for(const t of n)W(t,(t=>{const n=this._objectSpringBonesMap.get(t);if(n)for(const t of n)this._processSpringBone(t,e,i,r,s);else r.has(t)||(t.updateWorldMatrix(!1,!1),r.add(t))}));t.bone.updateMatrix(),t.bone.updateWorldMatrix(!1,!1),s(t),r.add(t.bone),i.add(t)}_getDependencies(t){const e=new Set,i=t.bone.parent;return i&&e.add(i),t.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{e.add(t)}))})),e}}const j=new Set(["1.0","1.0-beta"]);class A{constructor(t,e){this.parser=t,this.jointHelperRoot=null==e?void 0:e.jointHelperRoot,this.colliderHelperRoot=null==e?void 0:e.colliderHelperRoot}get name(){return A.EXTENSION_NAME}afterRoot(t){return E(this,void 0,void 0,(function*(){t.userData.vrmSpringBoneManager=yield this._import(t)}))}_import(t){return E(this,void 0,void 0,(function*(){const e=yield this._v1Import(t);if(null!=e)return e;const i=yield this._v0Import(t);return null!=i?i:null}))}_v1Import(t){var e,i,s,n,o;return E(this,void 0,void 0,(function*(){const a=t.parser.json;if(!(-1!==(null===(e=a.extensionsUsed)||void 0===e?void 0:e.indexOf(A.EXTENSION_NAME))))return null;const l=new L,d=yield t.parser.getDependencies("node"),c=null===(i=a.extensions)||void 0===i?void 0:i[A.EXTENSION_NAME];if(!c)return null;const h=c.specVersion;if(!j.has(h))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${A.EXTENSION_NAME} specVersion "${h}"`),null;const u=null===(s=c.colliders)||void 0===s?void 0:s.map(((t,e)=>{var i,s,n,o,a;const l=d[t.node],c=t.shape;if(c.sphere)return this._importSphereCollider(l,{offset:(new r.Vector3).fromArray(null!==(i=c.sphere.offset)&&void 0!==i?i:[0,0,0]),radius:null!==(s=c.sphere.radius)&&void 0!==s?s:0});if(c.capsule)return this._importCapsuleCollider(l,{offset:(new r.Vector3).fromArray(null!==(n=c.capsule.offset)&&void 0!==n?n:[0,0,0]),radius:null!==(o=c.capsule.radius)&&void 0!==o?o:0,tail:(new r.Vector3).fromArray(null!==(a=c.capsule.tail)&&void 0!==a?a:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${e} has no valid shape`)})),p=null===(n=c.colliderGroups)||void 0===n?void 0:n.map(((t,e)=>{var i;return{colliders:(null!==(i=t.colliders)&&void 0!==i?i:[]).map((t=>{const i=null==u?void 0:u[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${e} attempted to use a collider #${t} but not found`);return i})),name:t.name}}));return null===(o=c.springs)||void 0===o||o.forEach(((t,e)=>{var i;const s=t.joints,n=null===(i=t.colliderGroups)||void 0===i?void 0:i.map((t=>{const i=null==p?void 0:p[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${e} attempted to use a colliderGroup ${t} but not found`);return i})),o=null!=t.center?d[t.center]:void 0;let a;s.forEach((t=>{if(a){const e=a.node,i=d[e],s=t.node,c=d[s],h={hitRadius:a.hitRadius,dragForce:a.dragForce,gravityPower:a.gravityPower,stiffness:a.stiffness,gravityDir:null!=a.gravityDir?(new r.Vector3).fromArray(a.gravityDir):void 0},u=this._importJoint(i,c,h,n);o&&(u.center=o),l.addJoint(u)}a=t}))})),l.setInitState(),l}))}_v0Import(t){var e,i,s;return E(this,void 0,void 0,(function*(){const n=t.parser.json;if(!(-1!==(null===(e=n.extensionsUsed)||void 0===e?void 0:e.indexOf("VRM"))))return null;const o=null===(i=n.extensions)||void 0===i?void 0:i.VRM,a=null==o?void 0:o.secondaryAnimation;if(!a)return null;const l=null==a?void 0:a.boneGroups;if(!l)return null;const d=new L,c=yield t.parser.getDependencies("node"),h=null===(s=a.colliderGroups)||void 0===s?void 0:s.map((t=>{var e;const i=c[t.node],s=(null!==(e=t.colliders)&&void 0!==e?e:[]).map(((t,e)=>{var s,n,o;const a=new r.Vector3(0,0,0);return t.offset&&a.set(null!==(s=t.offset.x)&&void 0!==s?s:0,null!==(n=t.offset.y)&&void 0!==n?n:0,t.offset.z?-t.offset.z:0),this._importSphereCollider(i,{offset:a,radius:null!==(o=t.radius)&&void 0!==o?o:0})}));return{colliders:s}}));return null==l||l.forEach(((t,e)=>{const i=t.bones;i&&i.forEach((i=>{var s,n,o,a;const l=c[i],u=new r.Vector3;t.gravityDir?u.set(null!==(s=t.gravityDir.x)&&void 0!==s?s:0,null!==(n=t.gravityDir.y)&&void 0!==n?n:0,null!==(o=t.gravityDir.z)&&void 0!==o?o:0):u.set(0,-1,0);const p=null!=t.center?c[t.center]:void 0,_={hitRadius:t.hitRadius,dragForce:t.dragForce,gravityPower:t.gravityPower,stiffness:t.stiffiness,gravityDir:u},f=null===(a=t.colliderGroups)||void 0===a?void 0:a.map((t=>{const i=null==h?void 0:h[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${e} attempted to use a colliderGroup ${t} but not found`);return i}));l.traverse((t=>{var e;const i=null!==(e=t.children[0])&&void 0!==e?e:null,r=this._importJoint(t,i,_,f);p&&(r.center=p),d.addJoint(r)}))}))})),t.scene.updateMatrixWorld(),d.setInitState(),d}))}_importJoint(t,e,i,r){const s=new C(t,e,i,r);if(this.jointHelperRoot){const t=new g(s);this.jointHelperRoot.add(t),t.renderOrder=this.jointHelperRoot.renderOrder}return s}_importSphereCollider(t,e){const{offset:i,radius:r}=e,s=new l({offset:i,radius:r}),n=new y(s);if(t.add(n),this.colliderHelperRoot){const t=new p(n);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return n}_importCapsuleCollider(t,e){const{offset:i,radius:r,tail:s}=e,n=new a({offset:i,radius:r,tail:s}),o=new y(n);if(t.add(o),this.colliderHelperRoot){const t=new p(o);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return o}}A.EXTENSION_NAME="VRMC_springBone",t.VRMSpringBoneCollider=y,t.VRMSpringBoneColliderHelper=p,t.VRMSpringBoneColliderShape=s,t.VRMSpringBoneColliderShapeCapsule=a,t.VRMSpringBoneColliderShapeSphere=l,t.VRMSpringBoneJoint=C,t.VRMSpringBoneJointHelper=g,t.VRMSpringBoneLoaderPlugin=A,t.VRMSpringBoneManager=L,Object.defineProperty(t,"__esModule",{value:!0}),Object.assign(e,t)}));
/*! (c) 2020-2023 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
import*as t from"three";class e{}const i=new t.Vector3,r=new t.Vector3;class s extends e{constructor(e){var i,r,s;super(),this.offset=null!==(i=null==e?void 0:e.offset)&&void 0!==i?i:new t.Vector3(0,0,0),this.tail=null!==(r=null==e?void 0:e.tail)&&void 0!==r?r:new t.Vector3(0,0,0),this.radius=null!==(s=null==e?void 0:e.radius)&&void 0!==s?s:0}get type(){return"capsule"}calculateCollision(t,e,s,n){i.copy(this.offset).applyMatrix4(t),r.copy(this.tail).applyMatrix4(t),r.sub(i);const o=r.lengthSq();n.copy(e).sub(i);const a=r.dot(n);a<=0||(o<=a||r.multiplyScalar(a/o),n.sub(r));const l=s+this.radius,h=n.length()-l;return n.normalize(),h}}class n extends e{constructor(e){var i,r;super(),this.offset=null!==(i=null==e?void 0:e.offset)&&void 0!==i?i:new t.Vector3(0,0,0),this.radius=null!==(r=null==e?void 0:e.radius)&&void 0!==r?r:0}get type(){return"sphere"}calculateCollision(t,e,i,r){r.copy(this.offset).applyMatrix4(t),r.negate().add(e);const s=i+this.radius,n=r.length()-s;return r.normalize(),n}}const o=new t.Vector3;class a extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentOffset=new t.Vector3,this._currentTail=new t.Vector3,this._shape=e,this._attrPos=new t.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._shape.radius&&(this._currentRadius=this._shape.radius,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),this._currentTail.equals(this._shape.tail)||(this._currentTail.copy(this._shape.tail),t=!0),t&&this._buildPosition()}_buildPosition(){o.copy(this._currentTail).sub(this._currentOffset);const t=o.length()/this._currentRadius;for(let e=0;e<=16;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(e,-Math.sin(i),-Math.cos(i),0),this._attrPos.setXYZ(17+e,t+Math.sin(i),Math.cos(i),0),this._attrPos.setXYZ(34+e,-Math.sin(i),0,-Math.cos(i)),this._attrPos.setXYZ(51+e,t+Math.sin(i),0,Math.cos(i))}for(let e=0;e<32;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(68+e,0,Math.sin(i),Math.cos(i)),this._attrPos.setXYZ(100+e,t,Math.sin(i),Math.cos(i))}const e=Math.atan2(o.y,Math.sqrt(o.x*o.x+o.z*o.z)),i=-Math.atan2(o.z,o.x);this.rotateZ(e),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 t=0;t<34;t++){const e=(t+1)%34;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(68+2*t,34+t,34+e)}for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(136+2*t,68+t,68+e),this._attrIndex.setXY(200+2*t,100+t,100+e)}this._attrIndex.needsUpdate=!0}}class l extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentOffset=new t.Vector3,this._shape=e,this._attrPos=new t.BufferAttribute(new Float32Array(288),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(192),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._shape.radius&&(this._currentRadius=this._shape.radius,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.needsUpdate=!0}}class h extends t.Group{constructor(e){if(super(),this.matrixAutoUpdate=!1,this.collider=e,this.collider.shape instanceof n)this._geometry=new l(this.collider.shape);else{if(!(this.collider.shape instanceof s))throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");this._geometry=new a(this.collider.shape)}const i=new t.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new t.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld),this._geometry.update(),super.updateMatrixWorld(t)}}class d extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentTail=new t.Vector3,this._springBone=e,this._attrPos=new t.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._springBone.settings.hitRadius&&(this._currentRadius=this._springBone.settings.hitRadius,t=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}}class c extends t.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.springBone=e,this._geometry=new d(this.springBone);const i=new t.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new t.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld),this._geometry.update(),super.updateMatrixWorld(t)}}class u extends t.Object3D{constructor(t){super(),this.shape=t}}const p=new t.Matrix4;function _(t){return t.invert?t.invert():t.getInverse(p.copy(t)),t}class f{constructor(e){this._inverseCache=new t.Matrix4,this._shouldUpdateInverse=!0,this.matrix=e;const i={set:(t,e,i)=>(this._shouldUpdateInverse=!0,t[e]=i,!0)};this._originalElements=e.elements,e.elements=new Proxy(e.elements,i)}get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),_(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}}const v=new t.Matrix4,x=new t.Vector3,g=new t.Vector3,y=new t.Vector3,M=new t.Vector3,w=new t.Vector3,m=new t.Vector3,b=new t.Quaternion,S=new t.Matrix4,P=new t.Matrix4;class R{constructor(e,i,r={},s=[]){var n,o,a,l,h,d;this._currentTail=new t.Vector3,this._prevTail=new t.Vector3,this._boneAxis=new t.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new t.Matrix4,this._initialLocalRotation=new t.Quaternion,this._initialLocalChildPosition=new t.Vector3,this.bone=e,this.bone.matrixAutoUpdate=!1,this.child=i,this.settings={hitRadius:null!==(n=r.hitRadius)&&void 0!==n?n:0,stiffness:null!==(o=r.stiffness)&&void 0!==o?o:1,gravityPower:null!==(a=r.gravityPower)&&void 0!==a?a:0,gravityDir:null!==(h=null===(l=r.gravityDir)||void 0===l?void 0:l.clone())&&void 0!==h?h:new t.Vector3(0,-1,0),dragForce:null!==(d=r.dragForce)&&void 0!==d?d:.4},this.colliderGroups=s}get center(){return this._center}set center(t){var e;(null===(e=this._center)||void 0===e?void 0:e.userData.inverseCacheProxy)&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=t,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new f(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:v}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 t=this._getMatrixWorldToCenter(S);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);const t=this._getMatrixWorldToCenter(S);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength(),M.setFromMatrixPosition(this.bone.matrixWorld);let e=this._getMatrixWorldToCenter(S);w.copy(M).applyMatrix4(e);const i=b.setFromRotationMatrix(e),r=P.copy(e).multiply(this._parentMatrixWorld),s=g.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(r).sub(w).normalize(),n=y.copy(this.settings.gravityDir).applyQuaternion(i).normalize(),o=this._getMatrixCenterToWorld(S);m.copy(this._currentTail).add(x.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(x.copy(s).multiplyScalar(this.settings.stiffness*t)).add(x.copy(n).multiplyScalar(this.settings.gravityPower*t)).applyMatrix4(o),m.sub(M).normalize().multiplyScalar(this._worldSpaceBoneLength).add(M),this._collision(m),e=this._getMatrixWorldToCenter(S),this._prevTail.copy(this._currentTail),this._currentTail.copy(x.copy(m).applyMatrix4(e));const a=_(S.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),l=b.setFromUnitVectors(this._boneAxis,x.copy(m).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(l),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{const i=e.shape.calculateCollision(e.matrixWorld,t,this.settings.hitRadius,x);i<0&&(t.add(x.multiplyScalar(-i)),t.sub(M).normalize().multiplyScalar(this._worldSpaceBoneLength).add(M))}))}))}_calcWorldSpaceBoneLength(){x.setFromMatrixPosition(this.bone.matrixWorld),this.child?g.setFromMatrixPosition(this.child.matrixWorld):(g.copy(this._initialLocalChildPosition),g.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=x.sub(g).length()}_getMatrixCenterToWorld(t){return this._center?t.copy(this._center.matrixWorld):t.identity(),t}_getMatrixWorldToCenter(t){return this._center?t.copy(this._center.userData.inverseCacheProxy.inverse):t.identity(),t}}function B(t,e,i,r){return new(i||(i=Promise))((function(s,n){function o(t){try{l(r.next(t))}catch(t){n(t)}}function a(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}l((r=r.apply(t,e||[])).next())}))}function I(t,e){const i=[];let r=t;for(;null!==r;)i.unshift(r),r=r.parent;i.forEach((t=>{e(t)}))}function T(t,e){t.children.forEach((t=>{e(t)||T(t,e)}))}class V{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 t=new Set;return this._joints.forEach((e=>{e.colliderGroups.forEach((e=>{t.add(e)}))})),Array.from(t)}get colliders(){const t=new Set;return this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{t.add(e)}))})),Array.from(t)}addJoint(t){this._joints.add(t);let e=this._objectSpringBonesMap.get(t.bone);null==e&&(e=new Set,this._objectSpringBonesMap.set(t.bone,e)),e.add(t)}addSpringBone(t){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(t)}deleteJoint(t){this._joints.delete(t);this._objectSpringBonesMap.get(t.bone).delete(t)}deleteSpringBone(t){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(t)}setInitState(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.setInitState()))}reset(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.reset()))}update(t){const e=new Set,i=new Set,r=new Set;for(const s of this._joints)this._processSpringBone(s,e,i,r,(e=>e.update(t))),T(s.bone,(t=>{var e,i;return(null!==(i=null===(e=this._objectSpringBonesMap.get(t))||void 0===e?void 0:e.size)&&void 0!==i?i:0)>0||(t.updateWorldMatrix(!1,!1),!1)}))}_processSpringBone(t,e,i,r,s){if(i.has(t))return;if(e.has(t))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");e.add(t);const n=this._getDependencies(t);for(const t of n)I(t,(t=>{const n=this._objectSpringBonesMap.get(t);if(n)for(const t of n)this._processSpringBone(t,e,i,r,s);else r.has(t)||(t.updateWorldMatrix(!1,!1),r.add(t))}));t.bone.updateMatrix(),t.bone.updateWorldMatrix(!1,!1),s(t),r.add(t.bone),i.add(t)}_getDependencies(t){const e=new Set,i=t.bone.parent;return i&&e.add(i),t.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{e.add(t)}))})),e}}const C=new Set(["1.0","1.0-beta"]);class W{constructor(t,e){this.parser=t,this.jointHelperRoot=null==e?void 0:e.jointHelperRoot,this.colliderHelperRoot=null==e?void 0:e.colliderHelperRoot}get name(){return W.EXTENSION_NAME}afterRoot(t){return B(this,void 0,void 0,(function*(){t.userData.vrmSpringBoneManager=yield this._import(t)}))}_import(t){return B(this,void 0,void 0,(function*(){const e=yield this._v1Import(t);if(null!=e)return e;const i=yield this._v0Import(t);return null!=i?i:null}))}_v1Import(e){var i,r,s,n,o;return B(this,void 0,void 0,(function*(){const a=e.parser.json;if(!(-1!==(null===(i=a.extensionsUsed)||void 0===i?void 0:i.indexOf(W.EXTENSION_NAME))))return null;const l=new V,h=yield e.parser.getDependencies("node"),d=null===(r=a.extensions)||void 0===r?void 0:r[W.EXTENSION_NAME];if(!d)return null;const c=d.specVersion;if(!C.has(c))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${W.EXTENSION_NAME} specVersion "${c}"`),null;const u=null===(s=d.colliders)||void 0===s?void 0:s.map(((e,i)=>{var r,s,n,o,a;const l=h[e.node],d=e.shape;if(d.sphere)return this._importSphereCollider(l,{offset:(new t.Vector3).fromArray(null!==(r=d.sphere.offset)&&void 0!==r?r:[0,0,0]),radius:null!==(s=d.sphere.radius)&&void 0!==s?s:0});if(d.capsule)return this._importCapsuleCollider(l,{offset:(new t.Vector3).fromArray(null!==(n=d.capsule.offset)&&void 0!==n?n:[0,0,0]),radius:null!==(o=d.capsule.radius)&&void 0!==o?o:0,tail:(new t.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===(n=d.colliderGroups)||void 0===n?void 0:n.map(((t,e)=>{var i;return{colliders:(null!==(i=t.colliders)&&void 0!==i?i:[]).map((t=>{const i=null==u?void 0:u[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${e} attempted to use a collider #${t} but not found`);return i})),name:t.name}}));return null===(o=d.springs)||void 0===o||o.forEach(((e,i)=>{var r;const s=e.joints,n=null===(r=e.colliderGroups)||void 0===r?void 0:r.map((t=>{const e=null==p?void 0:p[t];if(null==e)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${t} but not found`);return e})),o=null!=e.center?h[e.center]:void 0;let a;s.forEach((e=>{if(a){const i=a.node,r=h[i],s=e.node,d=h[s],c={hitRadius:a.hitRadius,dragForce:a.dragForce,gravityPower:a.gravityPower,stiffness:a.stiffness,gravityDir:null!=a.gravityDir?(new t.Vector3).fromArray(a.gravityDir):void 0},u=this._importJoint(r,d,c,n);o&&(u.center=o),l.addJoint(u)}a=e}))})),l.setInitState(),l}))}_v0Import(e){var i,r,s;return B(this,void 0,void 0,(function*(){const n=e.parser.json;if(!(-1!==(null===(i=n.extensionsUsed)||void 0===i?void 0:i.indexOf("VRM"))))return null;const o=null===(r=n.extensions)||void 0===r?void 0:r.VRM,a=null==o?void 0:o.secondaryAnimation;if(!a)return null;const l=null==a?void 0:a.boneGroups;if(!l)return null;const h=new V,d=yield e.parser.getDependencies("node"),c=null===(s=a.colliderGroups)||void 0===s?void 0:s.map((e=>{var i;const r=d[e.node],s=(null!==(i=e.colliders)&&void 0!==i?i:[]).map(((e,i)=>{var s,n,o;const a=new t.Vector3(0,0,0);return e.offset&&a.set(null!==(s=e.offset.x)&&void 0!==s?s:0,null!==(n=e.offset.y)&&void 0!==n?n:0,e.offset.z?-e.offset.z:0),this._importSphereCollider(r,{offset:a,radius:null!==(o=e.radius)&&void 0!==o?o:0})}));return{colliders:s}}));return null==l||l.forEach(((e,i)=>{const r=e.bones;r&&r.forEach((r=>{var s,n,o,a;const l=d[r],u=new t.Vector3;e.gravityDir?u.set(null!==(s=e.gravityDir.x)&&void 0!==s?s:0,null!==(n=e.gravityDir.y)&&void 0!==n?n:0,null!==(o=e.gravityDir.z)&&void 0!==o?o:0):u.set(0,-1,0);const p=null!=e.center?d[e.center]:void 0,_={hitRadius:e.hitRadius,dragForce:e.dragForce,gravityPower:e.gravityPower,stiffness:e.stiffiness,gravityDir:u},f=null===(a=e.colliderGroups)||void 0===a?void 0:a.map((t=>{const e=null==c?void 0:c[t];if(null==e)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${t} but not found`);return e}));l.traverse((t=>{var e;const i=null!==(e=t.children[0])&&void 0!==e?e:null,r=this._importJoint(t,i,_,f);p&&(r.center=p),h.addJoint(r)}))}))})),e.scene.updateMatrixWorld(),h.setInitState(),h}))}_importJoint(t,e,i,r){const s=new R(t,e,i,r);if(this.jointHelperRoot){const t=new c(s);this.jointHelperRoot.add(t),t.renderOrder=this.jointHelperRoot.renderOrder}return s}_importSphereCollider(t,e){const{offset:i,radius:r}=e,s=new n({offset:i,radius:r}),o=new u(s);if(t.add(o),this.colliderHelperRoot){const t=new h(o);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return o}_importCapsuleCollider(t,e){const{offset:i,radius:r,tail:n}=e,o=new s({offset:i,radius:r,tail:n}),a=new u(o);if(t.add(a),this.colliderHelperRoot){const t=new h(a);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return a}}W.EXTENSION_NAME="VRMC_springBone";export{u as VRMSpringBoneCollider,h as VRMSpringBoneColliderHelper,e as VRMSpringBoneColliderShape,s as VRMSpringBoneColliderShapeCapsule,n as VRMSpringBoneColliderShapeSphere,R as VRMSpringBoneJoint,c as VRMSpringBoneJointHelper,W as VRMSpringBoneLoaderPlugin,V as VRMSpringBoneManager};
import*as t from"three";class e{}const i=new t.Vector3,r=new t.Vector3;class s extends e{constructor(e){var i,r,s;super(),this.offset=null!==(i=null==e?void 0:e.offset)&&void 0!==i?i:new t.Vector3(0,0,0),this.tail=null!==(r=null==e?void 0:e.tail)&&void 0!==r?r:new t.Vector3(0,0,0),this.radius=null!==(s=null==e?void 0:e.radius)&&void 0!==s?s:0}get type(){return"capsule"}calculateCollision(t,e,s,o){i.copy(this.offset).applyMatrix4(t),r.copy(this.tail).applyMatrix4(t),r.sub(i);const n=r.lengthSq();o.copy(e).sub(i);const a=r.dot(o);a<=0||(n<=a||r.multiplyScalar(a/n),o.sub(r));const l=s+this.radius,d=o.length()-l;return o.normalize(),d}}class o extends e{constructor(e){var i,r;super(),this.offset=null!==(i=null==e?void 0:e.offset)&&void 0!==i?i:new t.Vector3(0,0,0),this.radius=null!==(r=null==e?void 0:e.radius)&&void 0!==r?r:0}get type(){return"sphere"}calculateCollision(t,e,i,r){r.copy(this.offset).applyMatrix4(t),r.negate().add(e);const s=i+this.radius,o=r.length()-s;return r.normalize(),o}}const n=new t.Vector3;class a extends t.BufferGeometry{constructor(e){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new t.Vector3,this._currentTail=new t.Vector3,this._shape=e,this._attrPos=new t.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;const e=this._shape.radius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0);const i=n.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(i)>1e-10&&(this._currentTail.copy(i),t=!0),t&&this._buildPosition()}_buildPosition(){n.copy(this._currentTail).sub(this._currentOffset);const t=n.length()/this._currentRadius;for(let e=0;e<=16;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(e,-Math.sin(i),-Math.cos(i),0),this._attrPos.setXYZ(17+e,t+Math.sin(i),Math.cos(i),0),this._attrPos.setXYZ(34+e,-Math.sin(i),0,-Math.cos(i)),this._attrPos.setXYZ(51+e,t+Math.sin(i),0,Math.cos(i))}for(let e=0;e<32;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(68+e,0,Math.sin(i),Math.cos(i)),this._attrPos.setXYZ(100+e,t,Math.sin(i),Math.cos(i))}const e=Math.atan2(n.y,Math.sqrt(n.x*n.x+n.z*n.z)),i=-Math.atan2(n.z,n.x);this.rotateZ(e),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 t=0;t<34;t++){const e=(t+1)%34;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(68+2*t,34+t,34+e)}for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(136+2*t,68+t,68+e),this._attrIndex.setXY(200+2*t,100+t,100+e)}this._attrIndex.needsUpdate=!0}}class l extends t.BufferGeometry{constructor(e){super(),this.worldScale=1,this._currentRadius=0,this._currentOffset=new t.Vector3,this._shape=e,this._attrPos=new t.BufferAttribute(new Float32Array(288),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(192),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;const e=this._shape.radius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.needsUpdate=!0}}const d=new t.Vector3;class h extends t.Group{constructor(e){if(super(),this.matrixAutoUpdate=!1,this.collider=e,this.collider.shape instanceof o)this._geometry=new l(this.collider.shape);else{if(!(this.collider.shape instanceof s))throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");this._geometry=new a(this.collider.shape)}const i=new t.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new t.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld);const e=this.matrix.elements;this._geometry.worldScale=d.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}}class c extends t.BufferGeometry{constructor(e){super(),this.worldScale=1,this._currentRadius=0,this._currentTail=new t.Vector3,this._springBone=e,this._attrPos=new t.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;const e=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==e&&(this._currentRadius=e,t=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}}const u=new t.Vector3;class p extends t.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.springBone=e,this._geometry=new c(this.springBone);const i=new t.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new t.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld);const e=this.matrix.elements;this._geometry.worldScale=u.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}}class _ extends t.Object3D{constructor(t){super(),this.shape=t}}const f=new t.Matrix4;function v(t){return t.invert?t.invert():t.getInverse(f.copy(t)),t}class x{constructor(e){this._inverseCache=new t.Matrix4,this._shouldUpdateInverse=!0,this.matrix=e;const i={set:(t,e,i)=>(this._shouldUpdateInverse=!0,t[e]=i,!0)};this._originalElements=e.elements,e.elements=new Proxy(e.elements,i)}get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),v(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}}const g=new t.Matrix4,y=new t.Vector3,w=new t.Vector3,M=new t.Vector3,m=new t.Vector3,S=new t.Vector3,b=new t.Vector3,P=new t.Quaternion,R=new t.Matrix4,B=new t.Matrix4;class I{constructor(e,i,r={},s=[]){var o,n,a,l,d,h;this._currentTail=new t.Vector3,this._prevTail=new t.Vector3,this._boneAxis=new t.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new t.Matrix4,this._initialLocalRotation=new t.Quaternion,this._initialLocalChildPosition=new t.Vector3,this.bone=e,this.bone.matrixAutoUpdate=!1,this.child=i,this.settings={hitRadius:null!==(o=r.hitRadius)&&void 0!==o?o:0,stiffness:null!==(n=r.stiffness)&&void 0!==n?n:1,gravityPower:null!==(a=r.gravityPower)&&void 0!==a?a:0,gravityDir:null!==(d=null===(l=r.gravityDir)||void 0===l?void 0:l.clone())&&void 0!==d?d:new t.Vector3(0,-1,0),dragForce:null!==(h=r.dragForce)&&void 0!==h?h:.4},this.colliderGroups=s}get center(){return this._center}set center(t){var e;(null===(e=this._center)||void 0===e?void 0:e.userData.inverseCacheProxy)&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=t,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new x(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:g}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 t=this._getMatrixWorldToCenter(R);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);const t=this._getMatrixWorldToCenter(R);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength(),m.setFromMatrixPosition(this.bone.matrixWorld);let e=this._getMatrixWorldToCenter(R);S.copy(m).applyMatrix4(e);const i=P.setFromRotationMatrix(e),r=B.copy(e).multiply(this._parentMatrixWorld),s=w.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(r).sub(S).normalize(),o=M.copy(this.settings.gravityDir).applyQuaternion(i).normalize(),n=this._getMatrixCenterToWorld(R);b.copy(this._currentTail).add(y.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(y.copy(s).multiplyScalar(this.settings.stiffness*t)).add(y.copy(o).multiplyScalar(this.settings.gravityPower*t)).applyMatrix4(n),b.sub(m).normalize().multiplyScalar(this._worldSpaceBoneLength).add(m),this._collision(b),e=this._getMatrixWorldToCenter(R),this._prevTail.copy(this._currentTail),this._currentTail.copy(y.copy(b).applyMatrix4(e));const a=v(R.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),l=P.setFromUnitVectors(this._boneAxis,y.copy(b).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(l),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{const i=e.shape.calculateCollision(e.matrixWorld,t,this.settings.hitRadius,y);i<0&&(t.add(y.multiplyScalar(-i)),t.sub(m).normalize().multiplyScalar(this._worldSpaceBoneLength).add(m))}))}))}_calcWorldSpaceBoneLength(){y.setFromMatrixPosition(this.bone.matrixWorld),this.child?w.setFromMatrixPosition(this.child.matrixWorld):(w.copy(this._initialLocalChildPosition),w.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=y.sub(w).length()}_getMatrixCenterToWorld(t){return this._center?t.copy(this._center.matrixWorld):t.identity(),t}_getMatrixWorldToCenter(t){return this._center?t.copy(this._center.userData.inverseCacheProxy.inverse):t.identity(),t}}function T(t,e,i,r){return new(i||(i=Promise))((function(s,o){function n(t){try{l(r.next(t))}catch(t){o(t)}}function a(t){try{l(r.throw(t))}catch(t){o(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}l((r=r.apply(t,e||[])).next())}))}function V(t,e){const i=[];let r=t;for(;null!==r;)i.unshift(r),r=r.parent;i.forEach((t=>{e(t)}))}function C(t,e){t.children.forEach((t=>{e(t)||C(t,e)}))}class W{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 t=new Set;return this._joints.forEach((e=>{e.colliderGroups.forEach((e=>{t.add(e)}))})),Array.from(t)}get colliders(){const t=new Set;return this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{t.add(e)}))})),Array.from(t)}addJoint(t){this._joints.add(t);let e=this._objectSpringBonesMap.get(t.bone);null==e&&(e=new Set,this._objectSpringBonesMap.set(t.bone,e)),e.add(t)}addSpringBone(t){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(t)}deleteJoint(t){this._joints.delete(t);this._objectSpringBonesMap.get(t.bone).delete(t)}deleteSpringBone(t){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(t)}setInitState(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.setInitState()))}reset(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.reset()))}update(t){const e=new Set,i=new Set,r=new Set;for(const s of this._joints)this._processSpringBone(s,e,i,r,(e=>e.update(t))),C(s.bone,(t=>{var e,i;return(null!==(i=null===(e=this._objectSpringBonesMap.get(t))||void 0===e?void 0:e.size)&&void 0!==i?i:0)>0||(t.updateWorldMatrix(!1,!1),!1)}))}_processSpringBone(t,e,i,r,s){if(i.has(t))return;if(e.has(t))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");e.add(t);const o=this._getDependencies(t);for(const t of o)V(t,(t=>{const o=this._objectSpringBonesMap.get(t);if(o)for(const t of o)this._processSpringBone(t,e,i,r,s);else r.has(t)||(t.updateWorldMatrix(!1,!1),r.add(t))}));t.bone.updateMatrix(),t.bone.updateWorldMatrix(!1,!1),s(t),r.add(t.bone),i.add(t)}_getDependencies(t){const e=new Set,i=t.bone.parent;return i&&e.add(i),t.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{e.add(t)}))})),e}}const E=new Set(["1.0","1.0-beta"]);class A{constructor(t,e){this.parser=t,this.jointHelperRoot=null==e?void 0:e.jointHelperRoot,this.colliderHelperRoot=null==e?void 0:e.colliderHelperRoot}get name(){return A.EXTENSION_NAME}afterRoot(t){return T(this,void 0,void 0,(function*(){t.userData.vrmSpringBoneManager=yield this._import(t)}))}_import(t){return T(this,void 0,void 0,(function*(){const e=yield this._v1Import(t);if(null!=e)return e;const i=yield this._v0Import(t);return null!=i?i:null}))}_v1Import(e){var i,r,s,o,n;return T(this,void 0,void 0,(function*(){const a=e.parser.json;if(!(-1!==(null===(i=a.extensionsUsed)||void 0===i?void 0:i.indexOf(A.EXTENSION_NAME))))return null;const l=new W,d=yield e.parser.getDependencies("node"),h=null===(r=a.extensions)||void 0===r?void 0:r[A.EXTENSION_NAME];if(!h)return null;const c=h.specVersion;if(!E.has(c))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${A.EXTENSION_NAME} specVersion "${c}"`),null;const u=null===(s=h.colliders)||void 0===s?void 0:s.map(((e,i)=>{var r,s,o,n,a;const l=d[e.node],h=e.shape;if(h.sphere)return this._importSphereCollider(l,{offset:(new t.Vector3).fromArray(null!==(r=h.sphere.offset)&&void 0!==r?r:[0,0,0]),radius:null!==(s=h.sphere.radius)&&void 0!==s?s:0});if(h.capsule)return this._importCapsuleCollider(l,{offset:(new t.Vector3).fromArray(null!==(o=h.capsule.offset)&&void 0!==o?o:[0,0,0]),radius:null!==(n=h.capsule.radius)&&void 0!==n?n:0,tail:(new t.Vector3).fromArray(null!==(a=h.capsule.tail)&&void 0!==a?a:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${i} has no valid shape`)})),p=null===(o=h.colliderGroups)||void 0===o?void 0:o.map(((t,e)=>{var i;return{colliders:(null!==(i=t.colliders)&&void 0!==i?i:[]).map((t=>{const i=null==u?void 0:u[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${e} attempted to use a collider #${t} but not found`);return i})),name:t.name}}));return null===(n=h.springs)||void 0===n||n.forEach(((e,i)=>{var r;const s=e.joints,o=null===(r=e.colliderGroups)||void 0===r?void 0:r.map((t=>{const e=null==p?void 0:p[t];if(null==e)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${t} but not found`);return e})),n=null!=e.center?d[e.center]:void 0;let a;s.forEach((e=>{if(a){const i=a.node,r=d[i],s=e.node,h=d[s],c={hitRadius:a.hitRadius,dragForce:a.dragForce,gravityPower:a.gravityPower,stiffness:a.stiffness,gravityDir:null!=a.gravityDir?(new t.Vector3).fromArray(a.gravityDir):void 0},u=this._importJoint(r,h,c,o);n&&(u.center=n),l.addJoint(u)}a=e}))})),l.setInitState(),l}))}_v0Import(e){var i,r,s;return T(this,void 0,void 0,(function*(){const o=e.parser.json;if(!(-1!==(null===(i=o.extensionsUsed)||void 0===i?void 0:i.indexOf("VRM"))))return null;const n=null===(r=o.extensions)||void 0===r?void 0:r.VRM,a=null==n?void 0:n.secondaryAnimation;if(!a)return null;const l=null==a?void 0:a.boneGroups;if(!l)return null;const d=new W,h=yield e.parser.getDependencies("node"),c=null===(s=a.colliderGroups)||void 0===s?void 0:s.map((e=>{var i;const r=h[e.node],s=(null!==(i=e.colliders)&&void 0!==i?i:[]).map(((e,i)=>{var s,o,n;const a=new t.Vector3(0,0,0);return e.offset&&a.set(null!==(s=e.offset.x)&&void 0!==s?s:0,null!==(o=e.offset.y)&&void 0!==o?o:0,e.offset.z?-e.offset.z:0),this._importSphereCollider(r,{offset:a,radius:null!==(n=e.radius)&&void 0!==n?n:0})}));return{colliders:s}}));return null==l||l.forEach(((e,i)=>{const r=e.bones;r&&r.forEach((r=>{var s,o,n,a;const l=h[r],u=new t.Vector3;e.gravityDir?u.set(null!==(s=e.gravityDir.x)&&void 0!==s?s:0,null!==(o=e.gravityDir.y)&&void 0!==o?o:0,null!==(n=e.gravityDir.z)&&void 0!==n?n:0):u.set(0,-1,0);const p=null!=e.center?h[e.center]:void 0,_={hitRadius:e.hitRadius,dragForce:e.dragForce,gravityPower:e.gravityPower,stiffness:e.stiffiness,gravityDir:u},f=null===(a=e.colliderGroups)||void 0===a?void 0:a.map((t=>{const e=null==c?void 0:c[t];if(null==e)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${t} but not found`);return e}));l.traverse((t=>{var e;const i=null!==(e=t.children[0])&&void 0!==e?e:null,r=this._importJoint(t,i,_,f);p&&(r.center=p),d.addJoint(r)}))}))})),e.scene.updateMatrixWorld(),d.setInitState(),d}))}_importJoint(t,e,i,r){const s=new I(t,e,i,r);if(this.jointHelperRoot){const t=new p(s);this.jointHelperRoot.add(t),t.renderOrder=this.jointHelperRoot.renderOrder}return s}_importSphereCollider(t,e){const{offset:i,radius:r}=e,s=new o({offset:i,radius:r}),n=new _(s);if(t.add(n),this.colliderHelperRoot){const t=new h(n);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return n}_importCapsuleCollider(t,e){const{offset:i,radius:r,tail:o}=e,n=new s({offset:i,radius:r,tail:o}),a=new _(n);if(t.add(a),this.colliderHelperRoot){const t=new h(a);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return a}}A.EXTENSION_NAME="VRMC_springBone";export{_ as VRMSpringBoneCollider,h as VRMSpringBoneColliderHelper,e as VRMSpringBoneColliderShape,s as VRMSpringBoneColliderShapeCapsule,o as VRMSpringBoneColliderShapeSphere,I as VRMSpringBoneJoint,p as VRMSpringBoneJointHelper,A as VRMSpringBoneLoaderPlugin,W as VRMSpringBoneManager};
{
"name": "@pixiv/three-vrm-springbone",
"version": "1.0.7",
"version": "1.0.9",
"description": "Spring bone module for @pixiv/three-vrm",

@@ -49,9 +49,9 @@ "license": "MIT",

"devDependencies": {
"lint-staged": "13.0.3",
"three": "^0.148.0"
"lint-staged": "13.1.2",
"three": "^0.149.0"
},
"peerDependencies": {
"three": "^0.148.0"
"three": "^0.149.0"
},
"gitHead": "2db83111fa915ccf58c0ff9428c68971c2232ed8"
"gitHead": "57d7bdae4f41009e2ca362852e3e2138b4f5a65a"
}
import * as THREE from 'three';
export interface ColliderShapeBufferGeometry extends THREE.BufferGeometry {
worldScale: number;
update: () => void;
}

@@ -5,2 +5,3 @@ import * as THREE from 'three';

export declare class ColliderShapeCapsuleBufferGeometry extends THREE.BufferGeometry implements ColliderShapeBufferGeometry {
worldScale: number;
private readonly _attrPos;

@@ -7,0 +8,0 @@ private readonly _attrIndex;

@@ -5,2 +5,3 @@ import * as THREE from 'three';

export declare class ColliderShapeSphereBufferGeometry extends THREE.BufferGeometry implements ColliderShapeBufferGeometry {
worldScale: number;
private readonly _attrPos;

@@ -7,0 +8,0 @@ private readonly _attrIndex;

import * as THREE from 'three';
import { VRMSpringBoneJoint } from '../../VRMSpringBoneJoint';
export declare class SpringBoneBufferGeometry extends THREE.BufferGeometry {
worldScale: number;
private readonly _attrPos;

@@ -5,0 +6,0 @@ private readonly _attrIndex;

import * as THREE from 'three';
export interface ColliderShapeBufferGeometry extends THREE.BufferGeometry {
worldScale: number;
update: () => void;
}

@@ -5,2 +5,3 @@ import * as THREE from 'three';

export declare class ColliderShapeCapsuleBufferGeometry extends THREE.BufferGeometry implements ColliderShapeBufferGeometry {
worldScale: number;
private readonly _attrPos;

@@ -7,0 +8,0 @@ private readonly _attrIndex;

@@ -5,2 +5,3 @@ import * as THREE from 'three';

export declare class ColliderShapeSphereBufferGeometry extends THREE.BufferGeometry implements ColliderShapeBufferGeometry {
worldScale: number;
private readonly _attrPos;

@@ -7,0 +8,0 @@ private readonly _attrIndex;

import * as THREE from 'three';
import { VRMSpringBoneJoint } from '../../VRMSpringBoneJoint';
export declare class SpringBoneBufferGeometry extends THREE.BufferGeometry {
worldScale: number;
private readonly _attrPos;

@@ -5,0 +6,0 @@ private readonly _attrIndex;

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

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