@pixiv/three-vrm-springbone 2.1.1 → 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.
- package/lib/three-vrm-springbone.cjs +1135 -0
- package/lib/three-vrm-springbone.min.cjs +2 -0
- package/lib/three-vrm-springbone.module.js +1041 -1075
- package/lib/three-vrm-springbone.module.min.js +2 -2
- package/package.json +21 -20
- package/lib/three-vrm-springbone.js +0 -1175
- package/lib/three-vrm-springbone.min.js +0 -2
- package/ts3.4/types/VRMSpringBoneCollider.d.ts +0 -12
- package/ts3.4/types/VRMSpringBoneColliderGroup.d.ts +0 -14
- package/ts3.4/types/VRMSpringBoneColliderShape.d.ts +0 -21
- package/ts3.4/types/VRMSpringBoneColliderShapeCapsule.d.ts +0 -23
- package/ts3.4/types/VRMSpringBoneColliderShapeSphere.d.ts +0 -18
- package/ts3.4/types/VRMSpringBoneJoint.d.ts +0 -116
- package/ts3.4/types/VRMSpringBoneJointSettings.d.ts +0 -11
- package/ts3.4/types/VRMSpringBoneLoaderPlugin.d.ts +0 -34
- package/ts3.4/types/VRMSpringBoneLoaderPluginOptions.d.ts +0 -15
- package/ts3.4/types/VRMSpringBoneManager.d.ts +0 -47
- package/ts3.4/types/helpers/VRMSpringBoneColliderHelper.d.ts +0 -10
- package/ts3.4/types/helpers/VRMSpringBoneJointHelper.d.ts +0 -10
- package/ts3.4/types/helpers/index.d.ts +0 -2
- package/ts3.4/types/helpers/utils/ColliderShapeBufferGeometry.d.ts +0 -5
- package/ts3.4/types/helpers/utils/ColliderShapeCapsuleBufferGeometry.d.ts +0 -16
- package/ts3.4/types/helpers/utils/ColliderShapeSphereBufferGeometry.d.ts +0 -15
- package/ts3.4/types/helpers/utils/SpringBoneBufferGeometry.d.ts +0 -14
- package/ts3.4/types/index.d.ts +0 -10
- package/ts3.4/types/tests/VRMSpringBoneColliderShapeCapsule.test.d.ts +0 -1
- package/ts3.4/types/tests/VRMSpringBoneColliderShapeSphere.test.d.ts +0 -1
- package/ts3.4/types/tests/matchers/toBeCloseToArray.d.ts +0 -9
- package/ts3.4/types/tests/matchers/toBeCloseToVector3.d.ts +0 -10
- package/ts3.4/types/utils/Matrix4InverseCache.d.ts +0 -28
- package/ts3.4/types/utils/getWorldQuaternionLite.d.ts +0 -10
- package/ts3.4/types/utils/mat4InvertCompat.d.ts +0 -8
- package/ts3.4/types/utils/traverseAncestorsFromRoot.d.ts +0 -2
- package/ts3.4/types/utils/traverseChildrenUntilConditionMet.d.ts +0 -9
- package/types/tests/VRMSpringBoneColliderShapeCapsule.test.d.ts +0 -1
- package/types/tests/VRMSpringBoneColliderShapeSphere.test.d.ts +0 -1
- package/types/tests/matchers/toBeCloseToArray.d.ts +0 -9
- package/types/tests/matchers/toBeCloseToVector3.d.ts +0 -10
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! (c) 2019-2024 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
|
|
2
|
+
"use strict";var gt=Object.create;var et=Object.defineProperty;var St=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var Tt=Object.getPrototypeOf,bt=Object.prototype.hasOwnProperty;var xt=(s,e)=>{for(var t in e)et(s,t,{get:e[t],enumerable:!0})},dt=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Mt(e))!bt.call(s,i)&&i!==t&&et(s,i,{get:()=>e[i],enumerable:!(r=St(e,i))||r.enumerable});return s};var m=(s,e,t)=>(t=s!=null?gt(Tt(s)):{},dt(e||!s||!s.__esModule?et(t,"default",{value:s,enumerable:!0}):t,s)),yt=s=>dt(et({},"__esModule",{value:!0}),s);var Z=(s,e,t)=>new Promise((r,i)=>{var o=a=>{try{l(t.next(a))}catch(d){i(d)}},n=a=>{try{l(t.throw(a))}catch(d){i(d)}},l=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,n);l((t=t.apply(s,e)).next())});var It={};xt(It,{VRMSpringBoneCollider:()=>G,VRMSpringBoneColliderHelper:()=>j,VRMSpringBoneColliderShape:()=>B,VRMSpringBoneColliderShapeCapsule:()=>C,VRMSpringBoneColliderShapeSphere:()=>P,VRMSpringBoneJoint:()=>k,VRMSpringBoneJointHelper:()=>W,VRMSpringBoneLoaderPlugin:()=>pt,VRMSpringBoneManager:()=>U});module.exports=yt(It);var v=m(require("three"),1);var q=m(require("three"),1);var B=class{};var at=new q.Vector3,w=new q.Vector3,C=class extends B{get type(){return"capsule"}constructor(e){var t,r,i;super(),this.offset=(t=e==null?void 0:e.offset)!=null?t:new q.Vector3(0,0,0),this.tail=(r=e==null?void 0:e.tail)!=null?r:new q.Vector3(0,0,0),this.radius=(i=e==null?void 0:e.radius)!=null?i:0}calculateCollision(e,t,r,i){at.copy(this.offset).applyMatrix4(e),w.copy(this.tail).applyMatrix4(e),w.sub(at);let o=w.lengthSq();i.copy(t).sub(at);let n=w.dot(i);n<=0||(o<=n||w.multiplyScalar(n/o),i.sub(w));let l=r+this.radius,a=i.length()-l;return i.normalize(),a}};var ut=m(require("three"),1);var P=class extends B{get type(){return"sphere"}constructor(e){var t,r;super(),this.offset=(t=e==null?void 0:e.offset)!=null?t:new ut.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}};var x=m(require("three"),1),b=new x.Vector3,rt=class extends x.BufferGeometry{constructor(t){super();this.worldScale=1;this._currentRadius=0;this._currentOffset=new x.Vector3;this._currentTail=new x.Vector3;this._shape=t,this._attrPos=new x.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new x.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=b.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(i)>1e-10&&(this._currentTail.copy(i),t=!0),t&&this._buildPosition()}_buildPosition(){b.copy(this._currentTail).sub(this._currentOffset);let t=b.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(b.y,Math.sqrt(b.x*b.x+b.z*b.z)),i=-Math.atan2(b.z,b.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}};var I=m(require("three"),1),it=class extends I.BufferGeometry{constructor(t){super();this.worldScale=1;this._currentRadius=0;this._currentOffset=new I.Vector3;this._shape=t,this._attrPos=new I.BufferAttribute(new Float32Array(32*3*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new I.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 vt=new v.Vector3,j=class extends v.Group{constructor(e){if(super(),this.matrixAutoUpdate=!1,this.collider=e,this.collider.shape instanceof P)this._geometry=new it(this.collider.shape);else if(this.collider.shape instanceof C)this._geometry=new rt(this.collider.shape);else throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");let t=new v.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new v.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=vt.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}};var H=m(require("three"),1);var O=m(require("three"),1),ot=class extends O.BufferGeometry{constructor(t){super();this.worldScale=1;this._currentRadius=0;this._currentTail=new O.Vector3;this._springBone=t,this._attrPos=new O.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new O.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 Ht=new H.Vector3,W=class extends H.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.springBone=e,this._geometry=new ot(this.springBone);let t=new H.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new H.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=Ht.set(t[0],t[1],t[2]).length(),this._geometry.update(),super.updateMatrixWorld(e)}};var ht=m(require("three"),1),G=class extends ht.Object3D{constructor(e){super(),this.shape=e}};var c=m(require("three"),1);var ft=m(require("three"),1),Vt=new ft.Matrix4;function nt(s){return s.invert?s.invert():s.getInverse(Vt.copy(s)),s}var Et=m(require("three"),1);var st=class{constructor(e){this._inverseCache=new Et.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),nt(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}};var Bt=new c.Matrix4,y=new c.Vector3,$=new c.Vector3,wt=new c.Vector3,F=new c.Vector3,Rt=new c.Vector3,Q=new c.Vector3,_t=new c.Quaternion,X=new c.Matrix4,Ct=new c.Matrix4,k=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,l,a,d,g;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:(l=r.gravityPower)!=null?l:0,gravityDir:(d=(a=r.gravityDir)==null?void 0:a.clone())!=null?d:new c.Vector3(0,-1,0),dragForce:(g=r.dragForce)!=null?g:.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 st(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:Bt}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(X);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(X);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(e),this._prevTail.copy(this._currentTail)}update(e){if(e<=0)return;this._calcWorldSpaceBoneLength(),F.setFromMatrixPosition(this.bone.matrixWorld);let t=this._getMatrixWorldToCenter(X);Rt.copy(F).applyMatrix4(t);let r=_t.setFromRotationMatrix(t),i=Ct.copy(t).multiply(this._parentMatrixWorld),o=$.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(i).sub(Rt).normalize(),n=wt.copy(this.settings.gravityDir).applyQuaternion(r).normalize(),l=this._getMatrixCenterToWorld(X);Q.copy(this._currentTail).add(y.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(y.copy(o).multiplyScalar(this.settings.stiffness*e)).add(y.copy(n).multiplyScalar(this.settings.gravityPower*e)).applyMatrix4(l),Q.sub(F).normalize().multiplyScalar(this._worldSpaceBoneLength).add(F),this._collision(Q),t=this._getMatrixWorldToCenter(X),this._prevTail.copy(this._currentTail),this._currentTail.copy(y.copy(Q).applyMatrix4(t));let a=nt(X.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),d=_t.setFromUnitVectors(this._boneAxis,y.copy(Q).applyMatrix4(a).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,y);i<0&&(e.add(y.multiplyScalar(-i)),e.sub(F).normalize().multiplyScalar(this._worldSpaceBoneLength).add(F))})})}_calcWorldSpaceBoneLength(){y.setFromMatrixPosition(this.bone.matrixWorld),this.child?$.setFromMatrixPosition(this.child.matrixWorld):($.copy(this._initialLocalChildPosition),$.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=y.sub($).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}};var L=m(require("three"),1);function mt(s,e){let t=[],r=s;for(;r!==null;)t.unshift(r),r=r.parent;t.forEach(i=>{e(i)})}function lt(s,e){s.children.forEach(t=>{e(t)||lt(t,e)})}var U=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)),lt(o.bone,n=>{var l,a;return((a=(l=this._objectSpringBonesMap.get(n))==null?void 0:l.size)!=null?a: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 l of n)mt(l,a=>{let d=this._objectSpringBonesMap.get(a);if(d)for(let g of d)this._processSpringBone(g,t,r,i,o);else i.has(a)||(a.updateWorldMatrix(!1,!1),i.add(a))});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 Pt=new Set(["1.0","1.0-beta"]),D=class D{get name(){return D.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 Z(this,null,function*(){e.userData.vrmSpringBoneManager=yield this._import(e)})}_import(e){return Z(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 Z(this,null,function*(){var g,Y,z,u,J;let t=e.parser.json;if(!(((g=t.extensionsUsed)==null?void 0:g.indexOf(D.EXTENSION_NAME))!==-1))return null;let i=new U,o=yield e.parser.getDependencies("node"),n=(Y=t.extensions)==null?void 0:Y[D.EXTENSION_NAME];if(!n)return null;let l=n.specVersion;if(!Pt.has(l))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${D.EXTENSION_NAME} specVersion "${l}"`),null;let a=(z=n.colliders)==null?void 0:z.map((f,S)=>{var R,p,M,_,T;let E=o[f.node],h=f.shape;if(h.sphere)return this._importSphereCollider(E,{offset:new L.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 L.Vector3().fromArray((M=h.capsule.offset)!=null?M:[0,0,0]),radius:(_=h.capsule.radius)!=null?_:0,tail:new L.Vector3().fromArray((T=h.capsule.tail)!=null?T:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${S} has no valid shape`)}),d=(u=n.colliderGroups)==null?void 0:u.map((f,S)=>{var h;return{colliders:((h=f.colliders)!=null?h:[]).map(R=>{let p=a==null?void 0:a[R];if(p==null)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${S} attempted to use a collider #${R} but not found`);return p}),name:f.name}});return(J=n.springs)==null||J.forEach((f,S)=>{var M;let E=f.joints,h=(M=f.colliderGroups)==null?void 0:M.map(_=>{let T=d==null?void 0:d[_];if(T==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${S} attempted to use a colliderGroup ${_} but not found`);return T}),R=f.center!=null?o[f.center]:void 0,p;E.forEach(_=>{if(p){let T=p.node,K=o[T],tt=_.node,V=o[tt],A={hitRadius:p.hitRadius,dragForce:p.dragForce,gravityPower:p.gravityPower,stiffness:p.stiffness,gravityDir:p.gravityDir!=null?new L.Vector3().fromArray(p.gravityDir):void 0},N=this._importJoint(K,V,A,h);R&&(N.center=R),i.addJoint(N)}p=_})}),i.setInitState(),i})}_v0Import(e){return Z(this,null,function*(){var g,Y,z;let t=e.parser.json;if(!(((g=t.extensionsUsed)==null?void 0:g.indexOf("VRM"))!==-1))return null;let i=(Y=t.extensions)==null?void 0:Y.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 l=new U,a=yield e.parser.getDependencies("node"),d=(z=o.colliderGroups)==null?void 0:z.map(u=>{var S;let J=a[u.node];return{colliders:((S=u.colliders)!=null?S:[]).map((E,h)=>{var p,M,_;let R=new L.Vector3(0,0,0);return E.offset&&R.set((p=E.offset.x)!=null?p:0,(M=E.offset.y)!=null?M:0,E.offset.z?-E.offset.z:0),this._importSphereCollider(J,{offset:R,radius:(_=E.radius)!=null?_:0})})}});return n==null||n.forEach((u,J)=>{let f=u.bones;f&&f.forEach(S=>{var _,T,K,tt;let E=a[S],h=new L.Vector3;u.gravityDir?h.set((_=u.gravityDir.x)!=null?_:0,(T=u.gravityDir.y)!=null?T:0,(K=u.gravityDir.z)!=null?K:0):h.set(0,-1,0);let R=u.center!=null?a[u.center]:void 0,p={hitRadius:u.hitRadius,dragForce:u.dragForce,gravityPower:u.gravityPower,stiffness:u.stiffiness,gravityDir:h},M=(tt=u.colliderGroups)==null?void 0:tt.map(V=>{let A=d==null?void 0:d[V];if(A==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${J} attempted to use a colliderGroup ${V} but not found`);return A});E.traverse(V=>{var ct;let A=(ct=V.children[0])!=null?ct:null,N=this._importJoint(V,A,p,M);R&&(N.center=R),l.addJoint(N)})})}),e.scene.updateMatrixWorld(),l.setInitState(),l})}_importJoint(e,t,r,i){let o=new k(e,t,r,i);if(this.jointHelperRoot){let n=new W(o);this.jointHelperRoot.add(n),n.renderOrder=this.jointHelperRoot.renderOrder}return o}_importSphereCollider(e,t){let{offset:r,radius:i}=t,o=new P({offset:r,radius:i}),n=new G(o);if(e.add(n),this.colliderHelperRoot){let l=new j(n);this.colliderHelperRoot.add(l),l.renderOrder=this.colliderHelperRoot.renderOrder}return n}_importCapsuleCollider(e,t){let{offset:r,radius:i,tail:o}=t,n=new C({offset:r,radius:i,tail:o}),l=new G(n);if(e.add(l),this.colliderHelperRoot){let a=new j(l);this.colliderHelperRoot.add(a),a.renderOrder=this.colliderHelperRoot.renderOrder}return l}};D.EXTENSION_NAME="VRMC_springBone";var pt=D;
|