@pixiv/three-vrm-springbone 2.1.2 → 3.0.0-beta.0

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.
Files changed (38) hide show
  1. package/lib/three-vrm-springbone.cjs +1135 -0
  2. package/lib/three-vrm-springbone.min.cjs +2 -0
  3. package/lib/three-vrm-springbone.module.js +1041 -1075
  4. package/lib/three-vrm-springbone.module.min.js +2 -2
  5. package/package.json +19 -18
  6. package/lib/three-vrm-springbone.js +0 -1175
  7. package/lib/three-vrm-springbone.min.js +0 -2
  8. package/ts3.4/types/VRMSpringBoneCollider.d.ts +0 -12
  9. package/ts3.4/types/VRMSpringBoneColliderGroup.d.ts +0 -14
  10. package/ts3.4/types/VRMSpringBoneColliderShape.d.ts +0 -21
  11. package/ts3.4/types/VRMSpringBoneColliderShapeCapsule.d.ts +0 -23
  12. package/ts3.4/types/VRMSpringBoneColliderShapeSphere.d.ts +0 -18
  13. package/ts3.4/types/VRMSpringBoneJoint.d.ts +0 -116
  14. package/ts3.4/types/VRMSpringBoneJointSettings.d.ts +0 -11
  15. package/ts3.4/types/VRMSpringBoneLoaderPlugin.d.ts +0 -34
  16. package/ts3.4/types/VRMSpringBoneLoaderPluginOptions.d.ts +0 -15
  17. package/ts3.4/types/VRMSpringBoneManager.d.ts +0 -47
  18. package/ts3.4/types/helpers/VRMSpringBoneColliderHelper.d.ts +0 -10
  19. package/ts3.4/types/helpers/VRMSpringBoneJointHelper.d.ts +0 -10
  20. package/ts3.4/types/helpers/index.d.ts +0 -2
  21. package/ts3.4/types/helpers/utils/ColliderShapeBufferGeometry.d.ts +0 -5
  22. package/ts3.4/types/helpers/utils/ColliderShapeCapsuleBufferGeometry.d.ts +0 -16
  23. package/ts3.4/types/helpers/utils/ColliderShapeSphereBufferGeometry.d.ts +0 -15
  24. package/ts3.4/types/helpers/utils/SpringBoneBufferGeometry.d.ts +0 -14
  25. package/ts3.4/types/index.d.ts +0 -10
  26. package/ts3.4/types/tests/VRMSpringBoneColliderShapeCapsule.test.d.ts +0 -1
  27. package/ts3.4/types/tests/VRMSpringBoneColliderShapeSphere.test.d.ts +0 -1
  28. package/ts3.4/types/tests/matchers/toBeCloseToArray.d.ts +0 -9
  29. package/ts3.4/types/tests/matchers/toBeCloseToVector3.d.ts +0 -10
  30. package/ts3.4/types/utils/Matrix4InverseCache.d.ts +0 -28
  31. package/ts3.4/types/utils/getWorldQuaternionLite.d.ts +0 -10
  32. package/ts3.4/types/utils/mat4InvertCompat.d.ts +0 -8
  33. package/ts3.4/types/utils/traverseAncestorsFromRoot.d.ts +0 -2
  34. package/ts3.4/types/utils/traverseChildrenUntilConditionMet.d.ts +0 -9
  35. package/types/tests/VRMSpringBoneColliderShapeCapsule.test.d.ts +0 -1
  36. package/types/tests/VRMSpringBoneColliderShapeSphere.test.d.ts +0 -1
  37. package/types/tests/matchers/toBeCloseToArray.d.ts +0 -9
  38. package/types/tests/matchers/toBeCloseToVector3.d.ts +0 -10
@@ -1,2 +1,2 @@
1
- /*! (c) 2020-2024 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
2
- import*as t from"three";class e{}const i=new t.Vector3,r=new t.Vector3;class s extends e{get type(){return"capsule"}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}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{get type(){return"sphere"}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}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{get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),v(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}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)}revert(){this.matrix.elements=this._originalElements}}const y=new t.Matrix4,g=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{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:y}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}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(g.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(g.copy(s).multiplyScalar(this.settings.stiffness*t)).add(g.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(g.copy(b).applyMatrix4(e));const a=v(R.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),l=P.setFromUnitVectors(this._boneAxis,g.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,g);i<0&&(t.add(g.multiplyScalar(-i)),t.sub(m).normalize().multiplyScalar(this._worldSpaceBoneLength).add(m))}))}))}_calcWorldSpaceBoneLength(){g.setFromMatrixPosition(this.bone.matrixWorld),this.child?w.setFromMatrixPosition(this.child.matrixWorld):(w.copy(this._initialLocalChildPosition),w.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=g.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)}))}"function"==typeof SuppressedError&&SuppressedError;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{get name(){return A.EXTENSION_NAME}constructor(t,e){this.parser=t,this.jointHelperRoot=null==e?void 0:e.jointHelperRoot,this.colliderHelperRoot=null==e?void 0:e.colliderHelperRoot}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};
1
+ /*! (c) 2019-2024 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
2
+ var U=(l,e,t)=>new Promise((r,i)=>{var o=s=>{try{a(t.next(s))}catch(d){i(d)}},n=s=>{try{a(t.throw(s))}catch(d){i(d)}},a=s=>s.done?r(s.value):Promise.resolve(s.value).then(o,n);a((t=t.apply(l,e)).next())});import*as y from"three";import*as Y from"three";var O=class{};var nt=new Y.Vector3,V=new Y.Vector3,L=class extends O{get type(){return"capsule"}constructor(e){var t,r,i;super(),this.offset=(t=e==null?void 0:e.offset)!=null?t:new Y.Vector3(0,0,0),this.tail=(r=e==null?void 0:e.tail)!=null?r:new Y.Vector3(0,0,0),this.radius=(i=e==null?void 0:e.radius)!=null?i:0}calculateCollision(e,t,r,i){nt.copy(this.offset).applyMatrix4(e),V.copy(this.tail).applyMatrix4(e),V.sub(nt);let o=V.lengthSq();i.copy(t).sub(nt);let n=V.dot(i);n<=0||(o<=n||V.multiplyScalar(n/o),i.sub(V));let a=r+this.radius,s=i.length()-a;return i.normalize(),s}};import*as lt from"three";var D=class extends O{get type(){return"sphere"}constructor(e){var t,r;super(),this.offset=(t=e==null?void 0:e.offset)!=null?t:new lt.Vector3(0,0,0),this.radius=(r=e==null?void 0:e.radius)!=null?r:0}calculateCollision(e,t,r,i){i.copy(this.offset).applyMatrix4(e),i.negate().add(t);let o=r+this.radius,n=i.length()-o;return i.normalize(),n}};import*as b from"three";var T=new b.Vector3,K=class extends b.BufferGeometry{constructor(t){super();this.worldScale=1;this._currentRadius=0;this._currentOffset=new b.Vector3;this._currentTail=new b.Vector3;this._shape=t,this._attrPos=new b.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new b.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1,r=this._shape.radius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0);let i=T.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(i)>1e-10&&(this._currentTail.copy(i),t=!0),t&&this._buildPosition()}_buildPosition(){T.copy(this._currentTail).sub(this._currentOffset);let t=T.length()/this._currentRadius;for(let o=0;o<=16;o++){let n=o/16*Math.PI;this._attrPos.setXYZ(o,-Math.sin(n),-Math.cos(n),0),this._attrPos.setXYZ(17+o,t+Math.sin(n),Math.cos(n),0),this._attrPos.setXYZ(34+o,-Math.sin(n),0,-Math.cos(n)),this._attrPos.setXYZ(51+o,t+Math.sin(n),0,Math.cos(n))}for(let o=0;o<32;o++){let n=o/16*Math.PI;this._attrPos.setXYZ(68+o,0,Math.sin(n),Math.cos(n)),this._attrPos.setXYZ(100+o,t,Math.sin(n),Math.cos(n))}let r=Math.atan2(T.y,Math.sqrt(T.x*T.x+T.z*T.z)),i=-Math.atan2(T.z,T.x);this.rotateZ(r),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++){let r=(t+1)%34;this._attrIndex.setXY(t*2,t,r),this._attrIndex.setXY(68+t*2,34+t,34+r)}for(let t=0;t<32;t++){let r=(t+1)%32;this._attrIndex.setXY(136+t*2,68+t,68+r),this._attrIndex.setXY(200+t*2,100+t,100+r)}this._attrIndex.needsUpdate=!0}};import*as B from"three";var tt=class extends B.BufferGeometry{constructor(t){super();this.worldScale=1;this._currentRadius=0;this._currentOffset=new B.Vector3;this._shape=t,this._attrPos=new B.BufferAttribute(new Float32Array(32*3*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new B.BufferAttribute(new Uint16Array(64*3),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1,r=this._shape.radius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){let r=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(r),Math.sin(r),0),this._attrPos.setXYZ(32+t,0,Math.cos(r),Math.sin(r)),this._attrPos.setXYZ(64+t,Math.sin(r),0,Math.cos(r))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){let r=(t+1)%32;this._attrIndex.setXY(t*2,t,r),this._attrIndex.setXY(64+t*2,32+t,32+r),this._attrIndex.setXY(128+t*2,64+t,64+r)}this._attrIndex.needsUpdate=!0}};var Rt=new y.Vector3,J=class extends y.Group{constructor(e){if(super(),this.matrixAutoUpdate=!1,this.collider=e,this.collider.shape instanceof D)this._geometry=new tt(this.collider.shape);else if(this.collider.shape instanceof L)this._geometry=new K(this.collider.shape);else throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");let t=new y.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new y.LineSegments(this._geometry,t),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(e){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld);let t=this.matrix.elements;this._geometry.worldScale=Rt.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}};import*as v from"three";import*as w from"three";var et=class extends w.BufferGeometry{constructor(t){super();this.worldScale=1;this._currentRadius=0;this._currentTail=new w.Vector3;this._springBone=t,this._attrPos=new w.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new w.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1,r=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,t=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){let r=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(r),Math.sin(r),0),this._attrPos.setXYZ(32+t,0,Math.cos(r),Math.sin(r)),this._attrPos.setXYZ(64+t,Math.sin(r),0,Math.cos(r))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){let r=(t+1)%32;this._attrIndex.setXY(t*2,t,r),this._attrIndex.setXY(64+t*2,32+t,32+r),this._attrIndex.setXY(128+t*2,64+t,64+r)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}};var _t=new v.Vector3,z=class extends v.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.springBone=e,this._geometry=new et(this.springBone);let t=new v.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new v.LineSegments(this._geometry,t),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(e){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld);let t=this.matrix.elements;this._geometry.worldScale=_t.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}};import*as pt from"three";var N=class extends pt.Object3D{constructor(e){super(),this.shape=e}};import*as c from"three";import*as ct from"three";var mt=new ct.Matrix4;function rt(l){return l.invert?l.invert():l.getInverse(mt.copy(l)),l}import*as dt from"three";var it=class{constructor(e){this._inverseCache=new dt.Matrix4;this._shouldUpdateInverse=!0;this.matrix=e;let t={set:(r,i,o)=>(this._shouldUpdateInverse=!0,r[i]=o,!0)};this._originalElements=e.elements,e.elements=new Proxy(e.elements,t)}get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),rt(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}};var gt=new c.Matrix4,x=new c.Vector3,Z=new c.Vector3,St=new c.Vector3,A=new c.Vector3,ut=new c.Vector3,q=new c.Vector3,ht=new c.Quaternion,W=new c.Matrix4,Mt=new c.Matrix4,ot=class{constructor(e,t,r={},i=[]){this._currentTail=new c.Vector3;this._prevTail=new c.Vector3;this._boneAxis=new c.Vector3;this._worldSpaceBoneLength=0;this._center=null;this._initialLocalMatrix=new c.Matrix4;this._initialLocalRotation=new c.Quaternion;this._initialLocalChildPosition=new c.Vector3;var o,n,a,s,d,m;this.bone=e,this.bone.matrixAutoUpdate=!1,this.child=t,this.settings={hitRadius:(o=r.hitRadius)!=null?o:0,stiffness:(n=r.stiffness)!=null?n:1,gravityPower:(a=r.gravityPower)!=null?a:0,gravityDir:(d=(s=r.gravityDir)==null?void 0:s.clone())!=null?d:new c.Vector3(0,-1,0),dragForce:(m=r.dragForce)!=null?m:.4},this.colliderGroups=i}get center(){return this._center}set center(e){var t;(t=this._center)!=null&&t.userData.inverseCacheProxy&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=e,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new it(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:gt}setInitState(){this._initialLocalMatrix.copy(this.bone.matrix),this._initialLocalRotation.copy(this.bone.quaternion),this.child?this._initialLocalChildPosition.copy(this.child.position):this._initialLocalChildPosition.copy(this.bone.position).normalize().multiplyScalar(.07);let e=this._getMatrixWorldToCenter(W);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);let e=this._getMatrixWorldToCenter(W);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail)}update(e){if(e<=0)return;this._calcWorldSpaceBoneLength(),A.setFromMatrixPosition(this.bone.matrixWorld);let t=this._getMatrixWorldToCenter(W);ut.copy(A).applyMatrix4(t);let r=ht.setFromRotationMatrix(t),i=Mt.copy(t).multiply(this._parentMatrixWorld),o=Z.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(i).sub(ut).normalize(),n=St.copy(this.settings.gravityDir).applyQuaternion(r).normalize(),a=this._getMatrixCenterToWorld(W);q.copy(this._currentTail).add(x.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(x.copy(o).multiplyScalar(this.settings.stiffness*e)).add(x.copy(n).multiplyScalar(this.settings.gravityPower*e)).applyMatrix4(a),q.sub(A).normalize().multiplyScalar(this._worldSpaceBoneLength).add(A),this._collision(q),t=this._getMatrixWorldToCenter(W),this._prevTail.copy(this._currentTail),this._currentTail.copy(x.copy(q).applyMatrix4(t));let s=rt(W.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),d=ht.setFromUnitVectors(this._boneAxis,x.copy(q).applyMatrix4(s).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(d),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(e){this.colliderGroups.forEach(t=>{t.colliders.forEach(r=>{let i=r.shape.calculateCollision(r.matrixWorld,e,this.settings.hitRadius,x);i<0&&(e.add(x.multiplyScalar(-i)),e.sub(A).normalize().multiplyScalar(this._worldSpaceBoneLength).add(A))})})}_calcWorldSpaceBoneLength(){x.setFromMatrixPosition(this.bone.matrixWorld),this.child?Z.setFromMatrixPosition(this.child.matrixWorld):(Z.copy(this._initialLocalChildPosition),Z.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=x.sub(Z).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}};import*as C from"three";function ft(l,e){let t=[],r=l;for(;r!==null;)t.unshift(r),r=r.parent;t.forEach(i=>{e(i)})}function st(l,e){l.children.forEach(t=>{e(t)||st(t,e)})}var $=class{constructor(){this._joints=new Set;this._objectSpringBonesMap=new Map}get joints(){return this._joints}get springBones(){return console.warn("VRMSpringBoneManager: springBones is deprecated. use joints instead."),this._joints}get colliderGroups(){let e=new Set;return this._joints.forEach(t=>{t.colliderGroups.forEach(r=>{e.add(r)})}),Array.from(e)}get colliders(){let e=new Set;return this.colliderGroups.forEach(t=>{t.colliders.forEach(r=>{e.add(r)})}),Array.from(e)}addJoint(e){this._joints.add(e);let t=this._objectSpringBonesMap.get(e.bone);t==null&&(t=new Set,this._objectSpringBonesMap.set(e.bone,t)),t.add(e)}addSpringBone(e){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(e)}deleteJoint(e){this._joints.delete(e),this._objectSpringBonesMap.get(e.bone).delete(e)}deleteSpringBone(e){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(e)}setInitState(){let e=new Set,t=new Set,r=new Set;for(let i of this._joints)this._processSpringBone(i,e,t,r,o=>o.setInitState())}reset(){let e=new Set,t=new Set,r=new Set;for(let i of this._joints)this._processSpringBone(i,e,t,r,o=>o.reset())}update(e){let t=new Set,r=new Set,i=new Set;for(let o of this._joints)this._processSpringBone(o,t,r,i,n=>n.update(e)),st(o.bone,n=>{var a,s;return((s=(a=this._objectSpringBonesMap.get(n))==null?void 0:a.size)!=null?s:0)>0?!0:(n.updateWorldMatrix(!1,!1),!1)})}_processSpringBone(e,t,r,i,o){if(r.has(e))return;if(t.has(e))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");t.add(e);let n=this._getDependencies(e);for(let a of n)ft(a,s=>{let d=this._objectSpringBonesMap.get(s);if(d)for(let m of d)this._processSpringBone(m,t,r,i,o);else i.has(s)||(s.updateWorldMatrix(!1,!1),i.add(s))});e.bone.updateMatrix(),e.bone.updateWorldMatrix(!1,!1),o(e),i.add(e.bone),r.add(e)}_getDependencies(e){let t=new Set,r=e.bone.parent;return r&&t.add(r),e.colliderGroups.forEach(i=>{i.colliders.forEach(o=>{t.add(o)})}),t}};var Tt=new Set(["1.0","1.0-beta"]),P=class P{get name(){return P.EXTENSION_NAME}constructor(e,t){this.parser=e,this.jointHelperRoot=t==null?void 0:t.jointHelperRoot,this.colliderHelperRoot=t==null?void 0:t.colliderHelperRoot}afterRoot(e){return U(this,null,function*(){e.userData.vrmSpringBoneManager=yield this._import(e)})}_import(e){return U(this,null,function*(){let t=yield this._v1Import(e);if(t!=null)return t;let r=yield this._v0Import(e);return r!=null?r:null})}_v1Import(e){return U(this,null,function*(){var m,G,F,u,I;let t=e.parser.json;if(!(((m=t.extensionsUsed)==null?void 0:m.indexOf(P.EXTENSION_NAME))!==-1))return null;let i=new $,o=yield e.parser.getDependencies("node"),n=(G=t.extensions)==null?void 0:G[P.EXTENSION_NAME];if(!n)return null;let a=n.specVersion;if(!Tt.has(a))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${P.EXTENSION_NAME} specVersion "${a}"`),null;let s=(F=n.colliders)==null?void 0:F.map((f,g)=>{var R,p,S,_,M;let E=o[f.node],h=f.shape;if(h.sphere)return this._importSphereCollider(E,{offset:new C.Vector3().fromArray((R=h.sphere.offset)!=null?R:[0,0,0]),radius:(p=h.sphere.radius)!=null?p:0});if(h.capsule)return this._importCapsuleCollider(E,{offset:new C.Vector3().fromArray((S=h.capsule.offset)!=null?S:[0,0,0]),radius:(_=h.capsule.radius)!=null?_:0,tail:new C.Vector3().fromArray((M=h.capsule.tail)!=null?M:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${g} has no valid shape`)}),d=(u=n.colliderGroups)==null?void 0:u.map((f,g)=>{var h;return{colliders:((h=f.colliders)!=null?h:[]).map(R=>{let p=s==null?void 0:s[R];if(p==null)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${g} attempted to use a collider #${R} but not found`);return p}),name:f.name}});return(I=n.springs)==null||I.forEach((f,g)=>{var S;let E=f.joints,h=(S=f.colliderGroups)==null?void 0:S.map(_=>{let M=d==null?void 0:d[_];if(M==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${g} attempted to use a colliderGroup ${_} but not found`);return M}),R=f.center!=null?o[f.center]:void 0,p;E.forEach(_=>{if(p){let M=p.node,Q=o[M],k=_.node,H=o[k],j={hitRadius:p.hitRadius,dragForce:p.dragForce,gravityPower:p.gravityPower,stiffness:p.stiffness,gravityDir:p.gravityDir!=null?new C.Vector3().fromArray(p.gravityDir):void 0},X=this._importJoint(Q,H,j,h);R&&(X.center=R),i.addJoint(X)}p=_})}),i.setInitState(),i})}_v0Import(e){return U(this,null,function*(){var m,G,F;let t=e.parser.json;if(!(((m=t.extensionsUsed)==null?void 0:m.indexOf("VRM"))!==-1))return null;let i=(G=t.extensions)==null?void 0:G.VRM,o=i==null?void 0:i.secondaryAnimation;if(!o)return null;let n=o==null?void 0:o.boneGroups;if(!n)return null;let a=new $,s=yield e.parser.getDependencies("node"),d=(F=o.colliderGroups)==null?void 0:F.map(u=>{var g;let I=s[u.node];return{colliders:((g=u.colliders)!=null?g:[]).map((E,h)=>{var p,S,_;let R=new C.Vector3(0,0,0);return E.offset&&R.set((p=E.offset.x)!=null?p:0,(S=E.offset.y)!=null?S:0,E.offset.z?-E.offset.z:0),this._importSphereCollider(I,{offset:R,radius:(_=E.radius)!=null?_:0})})}});return n==null||n.forEach((u,I)=>{let f=u.bones;f&&f.forEach(g=>{var _,M,Q,k;let E=s[g],h=new C.Vector3;u.gravityDir?h.set((_=u.gravityDir.x)!=null?_:0,(M=u.gravityDir.y)!=null?M:0,(Q=u.gravityDir.z)!=null?Q:0):h.set(0,-1,0);let R=u.center!=null?s[u.center]:void 0,p={hitRadius:u.hitRadius,dragForce:u.dragForce,gravityPower:u.gravityPower,stiffness:u.stiffiness,gravityDir:h},S=(k=u.colliderGroups)==null?void 0:k.map(H=>{let j=d==null?void 0:d[H];if(j==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${I} attempted to use a colliderGroup ${H} but not found`);return j});E.traverse(H=>{var at;let j=(at=H.children[0])!=null?at:null,X=this._importJoint(H,j,p,S);R&&(X.center=R),a.addJoint(X)})})}),e.scene.updateMatrixWorld(),a.setInitState(),a})}_importJoint(e,t,r,i){let o=new ot(e,t,r,i);if(this.jointHelperRoot){let n=new z(o);this.jointHelperRoot.add(n),n.renderOrder=this.jointHelperRoot.renderOrder}return o}_importSphereCollider(e,t){let{offset:r,radius:i}=t,o=new D({offset:r,radius:i}),n=new N(o);if(e.add(n),this.colliderHelperRoot){let a=new J(n);this.colliderHelperRoot.add(a),a.renderOrder=this.colliderHelperRoot.renderOrder}return n}_importCapsuleCollider(e,t){let{offset:r,radius:i,tail:o}=t,n=new L({offset:r,radius:i,tail:o}),a=new N(n);if(e.add(a),this.colliderHelperRoot){let s=new J(a);this.colliderHelperRoot.add(s),s.renderOrder=this.colliderHelperRoot.renderOrder}return a}};P.EXTENSION_NAME="VRMC_springBone";var Et=P;export{N as VRMSpringBoneCollider,J as VRMSpringBoneColliderHelper,O as VRMSpringBoneColliderShape,L as VRMSpringBoneColliderShapeCapsule,D as VRMSpringBoneColliderShapeSphere,ot as VRMSpringBoneJoint,z as VRMSpringBoneJointHelper,Et as VRMSpringBoneLoaderPlugin,$ as VRMSpringBoneManager};
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@pixiv/three-vrm-springbone",
3
- "version": "2.1.2",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "Spring bone module for @pixiv/three-vrm",
5
5
  "license": "MIT",
6
6
  "author": "pixiv",
7
7
  "files": [
8
8
  "/lib/",
9
- "/ts*/",
10
9
  "/types/",
11
10
  "LICENSE"
12
11
  ],
13
- "main": "lib/three-vrm-springbone.js",
14
- "module": "lib/three-vrm-springbone.module.js",
12
+ "type": "module",
13
+ "main": "lib/three-vrm-springbone.module.js",
15
14
  "types": "types/index.d.ts",
16
- "typesVersions": {
17
- "<3.9": {
18
- "*": [
19
- "ts3.4/*"
20
- ]
21
- }
15
+ "exports": {
16
+ ".": {
17
+ "types": "./types/index.d.ts",
18
+ "import": "./lib/three-vrm-springbone.module.js",
19
+ "require": "./lib/three-vrm-springbone.cjs"
20
+ },
21
+ "./package.json": "./package.json"
22
22
  },
23
23
  "repository": {
24
24
  "type": "git",
@@ -28,12 +28,13 @@
28
28
  "scripts": {
29
29
  "version": "yarn all",
30
30
  "all": "yarn lint && yarn clean && yarn build && yarn docs",
31
- "dev": "cross-env NODE_ENV=development rollup -w -c",
32
- "clean": "rimraf docs/ lib/ ts*/ types/",
31
+ "dev": "cross-env SERVE=1 yarn build-dev",
32
+ "clean": "rimraf docs/ lib/ types/",
33
33
  "build": "yarn build-dev && yarn build-prod && yarn build-types",
34
- "build-dev": "cross-env NODE_ENV=development rollup -c",
35
- "build-prod": "cross-env NODE_ENV=production rollup -c",
36
- "build-types": "tsc --declaration --declarationDir ./types --emitDeclarationOnly && downlevel-dts types ts3.4/types",
34
+ "build-js": "node ../../bin/build.mjs",
35
+ "build-dev": "cross-env NODE_ENV=development yarn build-js",
36
+ "build-prod": "cross-env NODE_ENV=production yarn build-js",
37
+ "build-types": "tsc --project ./tsconfig.build-types.json",
37
38
  "docs": "typedoc --entryPoints ./src/index.ts --out docs",
38
39
  "test": "jest",
39
40
  "lint": "eslint \"src/**/*.{ts,tsx}\" && yarn lint-examples && prettier \"src/**/*.{ts,tsx}\" --check",
@@ -50,8 +51,8 @@
50
51
  ]
51
52
  },
52
53
  "dependencies": {
53
- "@pixiv/types-vrm-0.0": "2.1.2",
54
- "@pixiv/types-vrmc-springbone-1.0": "2.1.2"
54
+ "@pixiv/types-vrm-0.0": "3.0.0-beta.0",
55
+ "@pixiv/types-vrmc-springbone-1.0": "3.0.0-beta.0"
55
56
  },
56
57
  "devDependencies": {
57
58
  "three": "^0.164.1"
@@ -59,5 +60,5 @@
59
60
  "peerDependencies": {
60
61
  "three": "^0.164.1"
61
62
  },
62
- "gitHead": "2ea1a8f0d12a421c572514b86a84fef8ddfe752f"
63
+ "gitHead": "a8ac23ec2e534dcae60de7cce71542a03537fcea"
63
64
  }