@pixiv/three-vrm-springbone 3.1.0 → 3.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! (c) 2019-2024 pixiv Inc. - https://github.com/pixiv/three-vrm/blob/release/LICENSE */
|
|
2
|
-
"use strict";var Ie=Object.create;var se=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var Le=Object.getPrototypeOf,je=Object.prototype.hasOwnProperty;var De=(s,t)=>{for(var e in t)se(s,e,{get:t[e],enumerable:!0})},xe=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ae(t))!je.call(s,i)&&i!==e&&se(s,i,{get:()=>t[i],enumerable:!(r=Oe(t,i))||r.enumerable});return s};var m=(s,t,e)=>(e=s!=null?Ie(Le(s)):{},xe(t||!s||!s.__esModule?se(e,"default",{value:s,enumerable:!0}):e,s)),Je=s=>xe(se({},"__esModule",{value:!0}),s);var te=(s,t,e)=>new Promise((r,i)=>{var o=a=>{try{l(e.next(a))}catch(d){i(d)}},n=a=>{try{l(e.throw(a))}catch(d){i(d)}},l=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,n);l((e=e.apply(s,t)).next())});var Ze={};De(Ze,{VRMSpringBoneCollider:()=>U,VRMSpringBoneColliderHelper:()=>I,VRMSpringBoneColliderShape:()=>v,VRMSpringBoneColliderShapeCapsule:()=>G,VRMSpringBoneColliderShapePlane:()=>W,VRMSpringBoneColliderShapeSphere:()=>X,VRMSpringBoneJoint:()=>ne,VRMSpringBoneJointHelper:()=>Z,VRMSpringBoneLoaderPlugin:()=>Re,VRMSpringBoneManager:()=>k});module.exports=Je(Ze);var O=m(require("three"),1);var re=m(require("three"),1);var v=class{};var ue=new re.Vector3,J=new re.Vector3,G=class extends v{get type(){return"capsule"}constructor(t){var e,r,i,o;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new re.Vector3(0,0,0),this.tail=(r=t==null?void 0:t.tail)!=null?r:new re.Vector3(0,0,0),this.radius=(i=t==null?void 0:t.radius)!=null?i:0,this.inside=(o=t==null?void 0:t.inside)!=null?o:!1}calculateCollision(t,e,r,i){ue.copy(this.offset).applyMatrix4(t),J.copy(this.tail).applyMatrix4(t),J.sub(ue);let o=J.lengthSq();i.copy(e).sub(ue);let n=J.dot(i);n<=0||(o<=n||J.multiplyScalar(n/o),i.sub(J));let l=this.inside?this.radius-r-i.length():i.length()-r-this.radius;return i.normalize(),this.inside&&i.negate(),l}};var z=m(require("three"),1);var fe=new z.Vector3,be=new z.Matrix3,W=class extends v{get type(){return"plane"}constructor(t){var e,r;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new z.Vector3(0,0,0),this.normal=(r=t==null?void 0:t.normal)!=null?r:new z.Vector3(0,0,1)}calculateCollision(t,e,r,i){i.copy(this.offset).applyMatrix4(t),i.negate().add(e),be.getNormalMatrix(t),fe.copy(this.normal).applyNormalMatrix(be).normalize();let o=i.dot(fe)-r;return i.copy(fe),o}};var ye=m(require("three"),1);var X=class extends v{get type(){return"sphere"}constructor(t){var e,r,i;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new ye.Vector3(0,0,0),this.radius=(r=t==null?void 0:t.radius)!=null?r:0,this.inside=(i=t==null?void 0:t.inside)!=null?i:!1}calculateCollision(t,e,r,i){i.copy(this.offset).applyMatrix4(t),i.negate().add(e);let o=this.inside?this.radius-r-i.length():i.length()-r-this.radius;return i.normalize(),this.inside&&i.negate(),o}};var B=m(require("three"),1),H=new B.Vector3,ae=class extends B.BufferGeometry{constructor(e){super();this.worldScale=1;this._currentRadius=0;this._currentOffset=new B.Vector3;this._currentTail=new B.Vector3;this._shape=e,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 e=!1,r=this._shape.radius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0);let i=H.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(i)>1e-10&&(this._currentTail.copy(i),e=!0),e&&this._buildPosition()}_buildPosition(){H.copy(this._currentTail).sub(this._currentOffset);let e=H.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,e+Math.sin(n),Math.cos(n),0),this._attrPos.setXYZ(34+o,-Math.sin(n),0,-Math.cos(n)),this._attrPos.setXYZ(51+o,e+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,e,Math.sin(n),Math.cos(n))}let r=Math.atan2(H.y,Math.sqrt(H.x*H.x+H.z*H.z)),i=-Math.atan2(H.z,H.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 e=0;e<34;e++){let r=(e+1)%34;this._attrIndex.setXY(e*2,e,r),this._attrIndex.setXY(68+e*2,34+e,34+r)}for(let e=0;e<32;e++){let r=(e+1)%32;this._attrIndex.setXY(136+e*2,68+e,68+r),this._attrIndex.setXY(200+e*2,100+e,100+r)}this._attrIndex.needsUpdate=!0}};var P=m(require("three"),1),le=class extends P.BufferGeometry{constructor(e){super();this.worldScale=1;this._currentOffset=new P.Vector3;this._currentNormal=new P.Vector3;this._shape=e,this._attrPos=new P.BufferAttribute(new Float32Array(6*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new P.BufferAttribute(new Uint16Array(10),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0),this._currentNormal.equals(this._shape.normal)||(this._currentNormal.copy(this._shape.normal),e=!0),e&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,-.5,-.5,0),this._attrPos.setXYZ(1,.5,-.5,0),this._attrPos.setXYZ(2,.5,.5,0),this._attrPos.setXYZ(3,-.5,.5,0),this._attrPos.setXYZ(4,0,0,0),this._attrPos.setXYZ(5,0,0,.25),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this.lookAt(this._currentNormal),this._attrPos.needsUpdate=!0}_buildIndex(){this._attrIndex.setXY(0,0,1),this._attrIndex.setXY(2,1,2),this._attrIndex.setXY(4,2,3),this._attrIndex.setXY(6,3,0),this._attrIndex.setXY(8,4,5),this._attrIndex.needsUpdate=!0}};var F=m(require("three"),1),pe=class extends F.BufferGeometry{constructor(e){super();this.worldScale=1;this._currentRadius=0;this._currentOffset=new F.Vector3;this._shape=e,this._attrPos=new F.BufferAttribute(new Float32Array(32*3*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new F.BufferAttribute(new Uint16Array(64*3),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1,r=this._shape.radius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){let r=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(r),Math.sin(r),0),this._attrPos.setXYZ(32+e,0,Math.cos(r),Math.sin(r)),this._attrPos.setXYZ(64+e,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 e=0;e<32;e++){let r=(e+1)%32;this._attrIndex.setXY(e*2,e,r),this._attrIndex.setXY(64+e*2,32+e,32+r),this._attrIndex.setXY(128+e*2,64+e,64+r)}this._attrIndex.needsUpdate=!0}};var Ge=new O.Vector3,I=class extends O.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof X)this._geometry=new pe(this.collider.shape);else if(this.collider.shape instanceof G)this._geometry=new ae(this.collider.shape);else if(this.collider.shape instanceof W)this._geometry=new le(this.collider.shape);else throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");let e=new O.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new O.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);let e=this.matrix.elements;this._geometry.worldScale=Ge.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}};var A=m(require("three"),1);var Y=m(require("three"),1),ce=class extends Y.BufferGeometry{constructor(e){super();this.worldScale=1;this._currentRadius=0;this._currentTail=new Y.Vector3;this._springBone=e,this._attrPos=new Y.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new Y.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1,r=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,e=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){let r=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(r),Math.sin(r),0),this._attrPos.setXYZ(32+e,0,Math.cos(r),Math.sin(r)),this._attrPos.setXYZ(64+e,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 e=0;e<32;e++){let r=(e+1)%32;this._attrIndex.setXY(e*2,e,r),this._attrIndex.setXY(64+e*2,32+e,32+r),this._attrIndex.setXY(128+e*2,64+e,64+r)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}};var We=new A.Vector3,Z=class extends A.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new ce(this.springBone);let e=new A.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new A.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);let e=this.matrix.elements;this._geometry.worldScale=We.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}};var He=m(require("three"),1),U=class extends He.Object3D{constructor(t){super(),this.shape=t}};var c=m(require("three"),1);var Ve=m(require("three"),1),Xe=new Ve.Matrix4;function de(s){return s.invert?s.invert():s.getInverse(Xe.copy(s)),s}var ve=m(require("three"),1);var he=class{constructor(t){this._inverseCache=new ve.Matrix4;this._shouldUpdateInverse=!0;this.matrix=t;let e={set:(r,i,o)=>(this._shouldUpdateInverse=!0,r[i]=o,!0)};this._originalElements=t.elements,t.elements=new Proxy(t.elements,e)}get inverse(){return this._shouldUpdateInverse&&(de(this._inverseCache.copy(this.matrix)),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}};var Fe=new c.Matrix4,w=new c.Vector3,ie=new c.Vector3,Ye=new c.Vector3,q=new c.Vector3,Be=new c.Vector3,oe=new c.Vector3,we=new c.Quaternion,$=new c.Matrix4,Ue=new c.Matrix4,ne=class{constructor(t,e,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,T;this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=e,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:(T=r.dragForce)!=null?T:.4},this.colliderGroups=i}get center(){return this._center}set center(t){var e;(e=this._center)!=null&&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 he(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:Fe}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 t=this._getMatrixWorldToCenter($);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);let t=this._getMatrixWorldToCenter($);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength(),q.setFromMatrixPosition(this.bone.matrixWorld);let e=this._getMatrixWorldToCenter($);Be.copy(q).applyMatrix4(e);let r=we.setFromRotationMatrix(e),i=Ue.copy(e).multiply(this._parentMatrixWorld),o=ie.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(i).sub(Be).normalize(),n=Ye.copy(this.settings.gravityDir).applyQuaternion(r).normalize(),l=this._getMatrixCenterToWorld($);oe.copy(this._currentTail).add(w.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(w.copy(o).multiplyScalar(this.settings.stiffness*t)).add(w.copy(n).multiplyScalar(this.settings.gravityPower*t)).applyMatrix4(l),oe.sub(q).normalize().multiplyScalar(this._worldSpaceBoneLength).add(q),this._collision(oe),e=this._getMatrixWorldToCenter($),this._prevTail.copy(this._currentTail),this._currentTail.copy(w.copy(oe).applyMatrix4(e));let a=de($.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),d=we.setFromUnitVectors(this._boneAxis,w.copy(oe).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(d),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){this.colliderGroups.forEach(e=>{e.colliders.forEach(r=>{let i=r.shape.calculateCollision(r.matrixWorld,t,this.settings.hitRadius,w);i<0&&(t.add(w.multiplyScalar(-i)),t.sub(q).normalize().multiplyScalar(this._worldSpaceBoneLength).add(q))})})}_calcWorldSpaceBoneLength(){w.setFromMatrixPosition(this.bone.matrixWorld),this.child?ie.setFromMatrixPosition(this.child.matrixWorld):(ie.copy(this._initialLocalChildPosition),ie.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=w.sub(ie).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}};var g=m(require("three"),1);function Ce(s,t){let e=[],r=s;for(;r!==null;)e.unshift(r),r=r.parent;e.forEach(i=>{t(i)})}function Ee(s,t){s.children.forEach(e=>{t(e)||Ee(e,t)})}var k=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 t=new Set;return this._joints.forEach(e=>{e.colliderGroups.forEach(r=>{t.add(r)})}),Array.from(t)}get colliders(){let t=new Set;return this.colliderGroups.forEach(e=>{e.colliders.forEach(r=>{t.add(r)})}),Array.from(t)}addJoint(t){this._joints.add(t);let e=this._objectSpringBonesMap.get(t.bone);e==null&&(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(){let t=new Set,e=new Set,r=new Set;for(let i of this._joints)this._processSpringBone(i,t,e,r,o=>o.setInitState())}reset(){let t=new Set,e=new Set,r=new Set;for(let i of this._joints)this._processSpringBone(i,t,e,r,o=>o.reset())}update(t){let e=new Set,r=new Set,i=new Set;for(let o of this._joints)this._processSpringBone(o,e,r,i,n=>n.update(t)),Ee(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(t,e,r,i,o){if(r.has(t))return;if(e.has(t))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");e.add(t);let n=this._getDependencies(t);for(let l of n)Ce(l,a=>{let d=this._objectSpringBonesMap.get(a);if(d)for(let T of d)this._processSpringBone(T,e,r,i,o);else i.has(a)||(a.updateWorldMatrix(!1,!1),i.add(a))});t.bone.updateMatrix(),t.bone.updateWorldMatrix(!1,!1),o(t),i.add(t.bone),r.add(t)}_getDependencies(t){let e=new Set,r=t.bone.parent;return r&&e.add(r),t.colliderGroups.forEach(i=>{i.colliders.forEach(o=>{e.add(o)})}),e}};var Pe="VRMC_springBone_extended_collider",Ne=new Set(["1.0","1.0-beta"]),ze=new Set(["1.0"]),L=class L{get name(){return L.EXTENSION_NAME}constructor(t,e){var r;this.parser=t,this.jointHelperRoot=e==null?void 0:e.jointHelperRoot,this.colliderHelperRoot=e==null?void 0:e.colliderHelperRoot,this.useExtendedColliders=(r=e==null?void 0:e.useExtendedColliders)!=null?r:!0}afterRoot(t){return te(this,null,function*(){t.userData.vrmSpringBoneManager=yield this._import(t)})}_import(t){return te(this,null,function*(){let e=yield this._v1Import(t);if(e!=null)return e;let r=yield this._v0Import(t);return r!=null?r:null})}_v1Import(t){return te(this,null,function*(){var T,Q,K,h,N;let e=t.parser.json;if(!(((T=e.extensionsUsed)==null?void 0:T.indexOf(L.EXTENSION_NAME))!==-1))return null;let i=new k,o=yield t.parser.getDependencies("node"),n=(Q=e.extensions)==null?void 0:Q[L.EXTENSION_NAME];if(!n)return null;let l=n.specVersion;if(!Ne.has(l))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${L.EXTENSION_NAME} specVersion "${l}"`),null;let a=(K=n.colliders)==null?void 0:K.map((E,M)=>{var p,x,_,b,j,D,y,V,C,ee,_e,me,Se,ge,Te;let u=o[E.node],f=E.shape,R=(p=E.extensions)==null?void 0:p[Pe];if(this.useExtendedColliders&&R!=null){let Me=R.specVersion;if(!ze.has(Me))console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${Pe} specVersion "${Me}". Fallbacking to the ${L.EXTENSION_NAME} definition`);else{let S=R.shape;if(S.sphere)return this._importSphereCollider(u,{offset:new g.Vector3().fromArray((x=S.sphere.offset)!=null?x:[0,0,0]),radius:(_=S.sphere.radius)!=null?_:0,inside:(b=S.sphere.inside)!=null?b:!1});if(S.capsule)return this._importCapsuleCollider(u,{offset:new g.Vector3().fromArray((j=S.capsule.offset)!=null?j:[0,0,0]),radius:(D=S.capsule.radius)!=null?D:0,tail:new g.Vector3().fromArray((y=S.capsule.tail)!=null?y:[0,0,0]),inside:(V=S.capsule.inside)!=null?V:!1});if(S.plane)return this._importPlaneCollider(u,{offset:new g.Vector3().fromArray((C=S.plane.offset)!=null?C:[0,0,0]),normal:new g.Vector3().fromArray((ee=S.plane.normal)!=null?ee:[0,0,1])})}}if(f.sphere)return this._importSphereCollider(u,{offset:new g.Vector3().fromArray((_e=f.sphere.offset)!=null?_e:[0,0,0]),radius:(me=f.sphere.radius)!=null?me:0,inside:!1});if(f.capsule)return this._importCapsuleCollider(u,{offset:new g.Vector3().fromArray((Se=f.capsule.offset)!=null?Se:[0,0,0]),radius:(ge=f.capsule.radius)!=null?ge:0,tail:new g.Vector3().fromArray((Te=f.capsule.tail)!=null?Te:[0,0,0]),inside:!1});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${M} has no valid shape`)}),d=(h=n.colliderGroups)==null?void 0:h.map((E,M)=>{var f;return{colliders:((f=E.colliders)!=null?f:[]).map(R=>{let p=a==null?void 0:a[R];if(p==null)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${M} attempted to use a collider #${R} but not found`);return p}),name:E.name}});return(N=n.springs)==null||N.forEach((E,M)=>{var x;let u=E.joints,f=(x=E.colliderGroups)==null?void 0:x.map(_=>{let b=d==null?void 0:d[_];if(b==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${M} attempted to use a colliderGroup ${_} but not found`);return b}),R=E.center!=null?o[E.center]:void 0,p;u.forEach(_=>{if(p){let b=p.node,j=o[b],D=_.node,y=o[D],V={hitRadius:p.hitRadius,dragForce:p.dragForce,gravityPower:p.gravityPower,stiffness:p.stiffness,gravityDir:p.gravityDir!=null?new g.Vector3().fromArray(p.gravityDir):void 0},C=this._importJoint(j,y,V,f);R&&(C.center=R),i.addJoint(C)}p=_})}),i.setInitState(),i})}_v0Import(t){return te(this,null,function*(){var T,Q,K;let e=t.parser.json;if(!(((T=e.extensionsUsed)==null?void 0:T.indexOf("VRM"))!==-1))return null;let i=(Q=e.extensions)==null?void 0:Q.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 k,a=yield t.parser.getDependencies("node"),d=(K=o.colliderGroups)==null?void 0:K.map(h=>{var M;let N=a[h.node];return{colliders:((M=h.colliders)!=null?M:[]).map((u,f)=>{var p,x,_;let R=new g.Vector3(0,0,0);return u.offset&&R.set((p=u.offset.x)!=null?p:0,(x=u.offset.y)!=null?x:0,u.offset.z?-u.offset.z:0),this._importSphereCollider(N,{offset:R,radius:(_=u.radius)!=null?_:0,inside:!1})})}});return n==null||n.forEach((h,N)=>{let E=h.bones;E&&E.forEach(M=>{var _,b,j,D;let u=a[M],f=new g.Vector3;h.gravityDir?f.set((_=h.gravityDir.x)!=null?_:0,(b=h.gravityDir.y)!=null?b:0,(j=h.gravityDir.z)!=null?j:0):f.set(0,-1,0);let R=h.center!=null?a[h.center]:void 0,p={hitRadius:h.hitRadius,dragForce:h.dragForce,gravityPower:h.gravityPower,stiffness:h.stiffiness,gravityDir:f},x=(D=h.colliderGroups)==null?void 0:D.map(y=>{let V=d==null?void 0:d[y];if(V==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${N} attempted to use a colliderGroup ${y} but not found`);return V});u.traverse(y=>{var ee;let V=(ee=y.children[0])!=null?ee:null,C=this._importJoint(y,V,p,x);R&&(C.center=R),l.addJoint(C)})})}),t.scene.updateMatrixWorld(),l.setInitState(),l})}_importJoint(t,e,r,i){let o=new ne(t,e,r,i);if(this.jointHelperRoot){let n=new Z(o);this.jointHelperRoot.add(n),n.renderOrder=this.jointHelperRoot.renderOrder}return o}_importSphereCollider(t,e){let r=new X(e),i=new U(r);if(t.add(i),this.colliderHelperRoot){let o=new I(i);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return i}_importCapsuleCollider(t,e){let r=new G(e),i=new U(r);if(t.add(i),this.colliderHelperRoot){let o=new I(i);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return i}_importPlaneCollider(t,e){let r=new W(e),i=new U(r);if(t.add(i),this.colliderHelperRoot){let o=new I(i);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return i}};L.EXTENSION_NAME="VRMC_springBone";var Re=L;
|
|
2
|
+
"use strict";var Ie=Object.create;var se=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var Ae=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,Le=Object.prototype.hasOwnProperty;var je=(s,t)=>{for(var e in t)se(s,e,{get:t[e],enumerable:!0})},xe=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ae(t))!Le.call(s,i)&&i!==e&&se(s,i,{get:()=>t[i],enumerable:!(r=Oe(t,i))||r.enumerable});return s};var m=(s,t,e)=>(e=s!=null?Ie(De(s)):{},xe(t||!s||!s.__esModule?se(e,"default",{value:s,enumerable:!0}):e,s)),Je=s=>xe(se({},"__esModule",{value:!0}),s);var te=(s,t,e)=>new Promise((r,i)=>{var o=a=>{try{l(e.next(a))}catch(d){i(d)}},n=a=>{try{l(e.throw(a))}catch(d){i(d)}},l=a=>a.done?r(a.value):Promise.resolve(a.value).then(o,n);l((e=e.apply(s,t)).next())});var Ze={};je(Ze,{VRMSpringBoneCollider:()=>U,VRMSpringBoneColliderHelper:()=>I,VRMSpringBoneColliderShape:()=>v,VRMSpringBoneColliderShapeCapsule:()=>W,VRMSpringBoneColliderShapePlane:()=>G,VRMSpringBoneColliderShapeSphere:()=>X,VRMSpringBoneJoint:()=>ne,VRMSpringBoneJointHelper:()=>Z,VRMSpringBoneLoaderPlugin:()=>_e,VRMSpringBoneManager:()=>k});module.exports=Je(Ze);var O=m(require("three"),1);var re=m(require("three"),1);var v=class{};var ue=new re.Vector3,J=new re.Vector3,W=class extends v{get type(){return"capsule"}constructor(t){var e,r,i,o;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new re.Vector3(0,0,0),this.tail=(r=t==null?void 0:t.tail)!=null?r:new re.Vector3(0,0,0),this.radius=(i=t==null?void 0:t.radius)!=null?i:0,this.inside=(o=t==null?void 0:t.inside)!=null?o:!1}calculateCollision(t,e,r,i){ue.copy(this.offset).applyMatrix4(t),J.copy(this.tail).applyMatrix4(t),J.sub(ue);let o=J.lengthSq();i.copy(e).sub(ue);let n=J.dot(i);n<=0||(o<=n||J.multiplyScalar(n/o),i.sub(J));let l=this.inside?this.radius-r-i.length():i.length()-r-this.radius;return i.normalize(),this.inside&&i.negate(),l}};var z=m(require("three"),1);var fe=new z.Vector3,be=new z.Matrix3,G=class extends v{get type(){return"plane"}constructor(t){var e,r;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new z.Vector3(0,0,0),this.normal=(r=t==null?void 0:t.normal)!=null?r:new z.Vector3(0,0,1)}calculateCollision(t,e,r,i){i.copy(this.offset).applyMatrix4(t),i.negate().add(e),be.getNormalMatrix(t),fe.copy(this.normal).applyNormalMatrix(be).normalize();let o=i.dot(fe)-r;return i.copy(fe),o}};var ye=m(require("three"),1);var X=class extends v{get type(){return"sphere"}constructor(t){var e,r,i;super(),this.offset=(e=t==null?void 0:t.offset)!=null?e:new ye.Vector3(0,0,0),this.radius=(r=t==null?void 0:t.radius)!=null?r:0,this.inside=(i=t==null?void 0:t.inside)!=null?i:!1}calculateCollision(t,e,r,i){i.copy(this.offset).applyMatrix4(t),i.negate().add(e);let o=this.inside?this.radius-r-i.length():i.length()-r-this.radius;return i.normalize(),this.inside&&i.negate(),o}};var B=m(require("three"),1),H=new B.Vector3,ae=class extends B.BufferGeometry{constructor(e){super();this.worldScale=1;this._currentRadius=0;this._currentOffset=new B.Vector3;this._currentTail=new B.Vector3;this._shape=e,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 e=!1,r=this._shape.radius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0);let i=H.copy(this._shape.tail).divideScalar(this.worldScale);this._currentTail.distanceToSquared(i)>1e-10&&(this._currentTail.copy(i),e=!0),e&&this._buildPosition()}_buildPosition(){H.copy(this._currentTail).sub(this._currentOffset);let e=H.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,e+Math.sin(n),Math.cos(n),0),this._attrPos.setXYZ(34+o,-Math.sin(n),0,-Math.cos(n)),this._attrPos.setXYZ(51+o,e+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,e,Math.sin(n),Math.cos(n))}let r=Math.atan2(H.y,Math.sqrt(H.x*H.x+H.z*H.z)),i=-Math.atan2(H.z,H.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 e=0;e<34;e++){let r=(e+1)%34;this._attrIndex.setXY(e*2,e,r),this._attrIndex.setXY(68+e*2,34+e,34+r)}for(let e=0;e<32;e++){let r=(e+1)%32;this._attrIndex.setXY(136+e*2,68+e,68+r),this._attrIndex.setXY(200+e*2,100+e,100+r)}this._attrIndex.needsUpdate=!0}};var P=m(require("three"),1),le=class extends P.BufferGeometry{constructor(e){super();this.worldScale=1;this._currentOffset=new P.Vector3;this._currentNormal=new P.Vector3;this._shape=e,this._attrPos=new P.BufferAttribute(new Float32Array(6*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new P.BufferAttribute(new Uint16Array(10),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1;this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0),this._currentNormal.equals(this._shape.normal)||(this._currentNormal.copy(this._shape.normal),e=!0),e&&this._buildPosition()}_buildPosition(){this._attrPos.setXYZ(0,-.5,-.5,0),this._attrPos.setXYZ(1,.5,-.5,0),this._attrPos.setXYZ(2,.5,.5,0),this._attrPos.setXYZ(3,-.5,.5,0),this._attrPos.setXYZ(4,0,0,0),this._attrPos.setXYZ(5,0,0,.25),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this.lookAt(this._currentNormal),this._attrPos.needsUpdate=!0}_buildIndex(){this._attrIndex.setXY(0,0,1),this._attrIndex.setXY(2,1,2),this._attrIndex.setXY(4,2,3),this._attrIndex.setXY(6,3,0),this._attrIndex.setXY(8,4,5),this._attrIndex.needsUpdate=!0}};var F=m(require("three"),1),pe=class extends F.BufferGeometry{constructor(e){super();this.worldScale=1;this._currentRadius=0;this._currentOffset=new F.Vector3;this._shape=e,this._attrPos=new F.BufferAttribute(new Float32Array(32*3*3),3),this.setAttribute("position",this._attrPos),this._attrIndex=new F.BufferAttribute(new Uint16Array(64*3),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1,r=this._shape.radius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,e=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){let r=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(r),Math.sin(r),0),this._attrPos.setXYZ(32+e,0,Math.cos(r),Math.sin(r)),this._attrPos.setXYZ(64+e,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 e=0;e<32;e++){let r=(e+1)%32;this._attrIndex.setXY(e*2,e,r),this._attrIndex.setXY(64+e*2,32+e,32+r),this._attrIndex.setXY(128+e*2,64+e,64+r)}this._attrIndex.needsUpdate=!0}};var We=new O.Vector3,I=class extends O.Group{constructor(t){if(super(),this.matrixAutoUpdate=!1,this.collider=t,this.collider.shape instanceof X)this._geometry=new pe(this.collider.shape);else if(this.collider.shape instanceof W)this._geometry=new ae(this.collider.shape);else if(this.collider.shape instanceof G)this._geometry=new le(this.collider.shape);else throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");let e=new O.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new O.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);let e=this.matrix.elements;this._geometry.worldScale=We.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}};var A=m(require("three"),1);var Y=m(require("three"),1),ce=class extends Y.BufferGeometry{constructor(e){super();this.worldScale=1;this._currentRadius=0;this._currentTail=new Y.Vector3;this._springBone=e,this._attrPos=new Y.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new Y.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let e=!1,r=this._springBone.settings.hitRadius/this.worldScale;this._currentRadius!==r&&(this._currentRadius=r,e=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),e=!0),e&&this._buildPosition()}_buildPosition(){for(let e=0;e<32;e++){let r=e/16*Math.PI;this._attrPos.setXYZ(e,Math.cos(r),Math.sin(r),0),this._attrPos.setXYZ(32+e,0,Math.cos(r),Math.sin(r)),this._attrPos.setXYZ(64+e,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 e=0;e<32;e++){let r=(e+1)%32;this._attrIndex.setXY(e*2,e,r),this._attrIndex.setXY(64+e*2,32+e,32+r),this._attrIndex.setXY(128+e*2,64+e,64+r)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}};var Ge=new A.Vector3,Z=class extends A.Group{constructor(t){super(),this.matrixAutoUpdate=!1,this.springBone=t,this._geometry=new ce(this.springBone);let e=new A.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new A.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);let e=this.matrix.elements;this._geometry.worldScale=Ge.set(e[0],e[1],e[2]).length(),this._geometry.update(),super.updateMatrixWorld(t)}};var He=m(require("three"),1),U=class extends He.Object3D{constructor(t){super(),this.shape=t}};var c=m(require("three"),1);var Ve=m(require("three"),1),Xe=new Ve.Matrix4;function de(s){return s.invert?s.invert():s.getInverse(Xe.copy(s)),s}var ve=m(require("three"),1);var he=class{constructor(t){this._inverseCache=new ve.Matrix4;this._shouldUpdateInverse=!0;this.matrix=t;let e={set:(r,i,o)=>(this._shouldUpdateInverse=!0,r[i]=o,!0)};this._originalElements=t.elements,t.elements=new Proxy(t.elements,e)}get inverse(){return this._shouldUpdateInverse&&(de(this._inverseCache.copy(this.matrix)),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}};var Fe=new c.Matrix4,w=new c.Vector3,ie=new c.Vector3,Ye=new c.Vector3,q=new c.Vector3,Be=new c.Vector3,oe=new c.Vector3,we=new c.Quaternion,$=new c.Matrix4,Ue=new c.Matrix4,ne=class{constructor(t,e,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,T;this.bone=t,this.bone.matrixAutoUpdate=!1,this.child=e,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:(T=r.dragForce)!=null?T:.4},this.colliderGroups=i}get center(){return this._center}set center(t){var e;(e=this._center)!=null&&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 he(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:Fe}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 t=this._getMatrixWorldToCenter($);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);let t=this._getMatrixWorldToCenter($);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;this._calcWorldSpaceBoneLength(),q.setFromMatrixPosition(this.bone.matrixWorld);let e=this._getMatrixWorldToCenter($);Be.copy(q).applyMatrix4(e);let r=we.setFromRotationMatrix(e),i=Ue.copy(e).multiply(this._parentMatrixWorld),o=ie.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(i).sub(Be).normalize(),n=Ye.copy(this.settings.gravityDir).applyQuaternion(r).normalize(),l=this._getMatrixCenterToWorld($);oe.copy(this._currentTail).add(w.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(w.copy(o).multiplyScalar(this.settings.stiffness*t)).add(w.copy(n).multiplyScalar(this.settings.gravityPower*t)).applyMatrix4(l),oe.sub(q).normalize().multiplyScalar(this._worldSpaceBoneLength).add(q),this._collision(oe),e=this._getMatrixWorldToCenter($),this._prevTail.copy(this._currentTail),this._currentTail.copy(w.copy(oe).applyMatrix4(e));let a=de($.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),d=we.setFromUnitVectors(this._boneAxis,w.copy(oe).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(d),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){this.colliderGroups.forEach(e=>{e.colliders.forEach(r=>{let i=r.shape.calculateCollision(r.matrixWorld,t,this.settings.hitRadius,w);i<0&&(t.add(w.multiplyScalar(-i)),t.sub(q).normalize().multiplyScalar(this._worldSpaceBoneLength).add(q))})})}_calcWorldSpaceBoneLength(){w.setFromMatrixPosition(this.bone.matrixWorld),this.child?ie.setFromMatrixPosition(this.child.matrixWorld):(ie.copy(this._initialLocalChildPosition),ie.applyMatrix4(this.bone.matrixWorld)),this._worldSpaceBoneLength=w.sub(ie).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}};var g=m(require("three"),1);function Ce(s,t){let e=[],r=s;for(;r!==null;)e.unshift(r),r=r.parent;e.forEach(i=>{t(i)})}function Ee(s,t){s.children.forEach(e=>{t(e)||Ee(e,t)})}var k=class{constructor(){this._joints=new Set;this._hasWarnedCircularDependency=!1;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 t=new Set;return this._joints.forEach(e=>{e.colliderGroups.forEach(r=>{t.add(r)})}),Array.from(t)}get colliders(){let t=new Set;return this.colliderGroups.forEach(e=>{e.colliders.forEach(r=>{t.add(r)})}),Array.from(t)}addJoint(t){this._joints.add(t);let e=this._objectSpringBonesMap.get(t.bone);e==null&&(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(){let t=new Set,e=new Set,r=new Set;for(let i of this._joints)this._processSpringBone(i,t,e,r,o=>o.setInitState())}reset(){let t=new Set,e=new Set,r=new Set;for(let i of this._joints)this._processSpringBone(i,t,e,r,o=>o.reset())}update(t){let e=new Set,r=new Set,i=new Set;for(let o of this._joints)this._processSpringBone(o,e,r,i,n=>n.update(t)),Ee(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(t,e,r,i,o){if(r.has(t))return;if(e.has(t)){this._hasWarnedCircularDependency||(console.warn("VRMSpringBoneManager: Circular dependency detected while updating springbones"),this._hasWarnedCircularDependency=!0);return}e.add(t);let n=this._getDependencies(t);for(let l of n)Ce(l,a=>{let d=this._objectSpringBonesMap.get(a);if(d)for(let T of d)this._processSpringBone(T,e,r,i,o);else i.has(a)||(a.updateWorldMatrix(!1,!1),i.add(a))});t.bone.updateMatrix(),t.bone.updateWorldMatrix(!1,!1),o(t),i.add(t.bone),r.add(t)}_getDependencies(t){let e=new Set,r=t.bone.parent;return r&&e.add(r),t.colliderGroups.forEach(i=>{i.colliders.forEach(o=>{e.add(o)})}),e}};var Pe="VRMC_springBone_extended_collider",Ne=new Set(["1.0","1.0-beta"]),ze=new Set(["1.0"]),D=class D{get name(){return D.EXTENSION_NAME}constructor(t,e){var r;this.parser=t,this.jointHelperRoot=e==null?void 0:e.jointHelperRoot,this.colliderHelperRoot=e==null?void 0:e.colliderHelperRoot,this.useExtendedColliders=(r=e==null?void 0:e.useExtendedColliders)!=null?r:!0}afterRoot(t){return te(this,null,function*(){t.userData.vrmSpringBoneManager=yield this._import(t)})}_import(t){return te(this,null,function*(){let e=yield this._v1Import(t);if(e!=null)return e;let r=yield this._v0Import(t);return r!=null?r:null})}_v1Import(t){return te(this,null,function*(){var T,Q,K,h,N;let e=t.parser.json;if(!(((T=e.extensionsUsed)==null?void 0:T.indexOf(D.EXTENSION_NAME))!==-1))return null;let i=new k,o=yield t.parser.getDependencies("node"),n=(Q=e.extensions)==null?void 0:Q[D.EXTENSION_NAME];if(!n)return null;let l=n.specVersion;if(!Ne.has(l))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${D.EXTENSION_NAME} specVersion "${l}"`),null;let a=(K=n.colliders)==null?void 0:K.map((E,M)=>{var p,x,R,b,L,j,y,V,C,ee,Re,me,Se,ge,Te;let u=o[E.node],f=E.shape,_=(p=E.extensions)==null?void 0:p[Pe];if(this.useExtendedColliders&&_!=null){let Me=_.specVersion;if(!ze.has(Me))console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${Pe} specVersion "${Me}". Fallbacking to the ${D.EXTENSION_NAME} definition`);else{let S=_.shape;if(S.sphere)return this._importSphereCollider(u,{offset:new g.Vector3().fromArray((x=S.sphere.offset)!=null?x:[0,0,0]),radius:(R=S.sphere.radius)!=null?R:0,inside:(b=S.sphere.inside)!=null?b:!1});if(S.capsule)return this._importCapsuleCollider(u,{offset:new g.Vector3().fromArray((L=S.capsule.offset)!=null?L:[0,0,0]),radius:(j=S.capsule.radius)!=null?j:0,tail:new g.Vector3().fromArray((y=S.capsule.tail)!=null?y:[0,0,0]),inside:(V=S.capsule.inside)!=null?V:!1});if(S.plane)return this._importPlaneCollider(u,{offset:new g.Vector3().fromArray((C=S.plane.offset)!=null?C:[0,0,0]),normal:new g.Vector3().fromArray((ee=S.plane.normal)!=null?ee:[0,0,1])})}}if(f.sphere)return this._importSphereCollider(u,{offset:new g.Vector3().fromArray((Re=f.sphere.offset)!=null?Re:[0,0,0]),radius:(me=f.sphere.radius)!=null?me:0,inside:!1});if(f.capsule)return this._importCapsuleCollider(u,{offset:new g.Vector3().fromArray((Se=f.capsule.offset)!=null?Se:[0,0,0]),radius:(ge=f.capsule.radius)!=null?ge:0,tail:new g.Vector3().fromArray((Te=f.capsule.tail)!=null?Te:[0,0,0]),inside:!1});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${M} has no valid shape`)}),d=(h=n.colliderGroups)==null?void 0:h.map((E,M)=>{var f;return{colliders:((f=E.colliders)!=null?f:[]).map(_=>{let p=a==null?void 0:a[_];if(p==null)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${M} attempted to use a collider #${_} but not found`);return p}),name:E.name}});return(N=n.springs)==null||N.forEach((E,M)=>{var x;let u=E.joints,f=(x=E.colliderGroups)==null?void 0:x.map(R=>{let b=d==null?void 0:d[R];if(b==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${M} attempted to use a colliderGroup ${R} but not found`);return b}),_=E.center!=null?o[E.center]:void 0,p;u.forEach(R=>{if(p){let b=p.node,L=o[b],j=R.node,y=o[j],V={hitRadius:p.hitRadius,dragForce:p.dragForce,gravityPower:p.gravityPower,stiffness:p.stiffness,gravityDir:p.gravityDir!=null?new g.Vector3().fromArray(p.gravityDir):void 0},C=this._importJoint(L,y,V,f);_&&(C.center=_),i.addJoint(C)}p=R})}),i.setInitState(),i})}_v0Import(t){return te(this,null,function*(){var T,Q,K;let e=t.parser.json;if(!(((T=e.extensionsUsed)==null?void 0:T.indexOf("VRM"))!==-1))return null;let i=(Q=e.extensions)==null?void 0:Q.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 k,a=yield t.parser.getDependencies("node"),d=(K=o.colliderGroups)==null?void 0:K.map(h=>{var M;let N=a[h.node];return{colliders:((M=h.colliders)!=null?M:[]).map((u,f)=>{var p,x,R;let _=new g.Vector3(0,0,0);return u.offset&&_.set((p=u.offset.x)!=null?p:0,(x=u.offset.y)!=null?x:0,u.offset.z?-u.offset.z:0),this._importSphereCollider(N,{offset:_,radius:(R=u.radius)!=null?R:0,inside:!1})})}});return n==null||n.forEach((h,N)=>{let E=h.bones;E&&E.forEach(M=>{var R,b,L,j;let u=a[M],f=new g.Vector3;h.gravityDir?f.set((R=h.gravityDir.x)!=null?R:0,(b=h.gravityDir.y)!=null?b:0,(L=h.gravityDir.z)!=null?L:0):f.set(0,-1,0);let _=h.center!=null?a[h.center]:void 0,p={hitRadius:h.hitRadius,dragForce:h.dragForce,gravityPower:h.gravityPower,stiffness:h.stiffiness,gravityDir:f},x=(j=h.colliderGroups)==null?void 0:j.map(y=>{let V=d==null?void 0:d[y];if(V==null)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${N} attempted to use a colliderGroup ${y} but not found`);return V});u.traverse(y=>{var ee;let V=(ee=y.children[0])!=null?ee:null,C=this._importJoint(y,V,p,x);_&&(C.center=_),l.addJoint(C)})})}),t.scene.updateMatrixWorld(),l.setInitState(),l})}_importJoint(t,e,r,i){let o=new ne(t,e,r,i);if(this.jointHelperRoot){let n=new Z(o);this.jointHelperRoot.add(n),n.renderOrder=this.jointHelperRoot.renderOrder}return o}_importSphereCollider(t,e){let r=new X(e),i=new U(r);if(t.add(i),this.colliderHelperRoot){let o=new I(i);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return i}_importCapsuleCollider(t,e){let r=new W(e),i=new U(r);if(t.add(i),this.colliderHelperRoot){let o=new I(i);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return i}_importPlaneCollider(t,e){let r=new G(e),i=new U(r);if(t.add(i),this.colliderHelperRoot){let o=new I(i);this.colliderHelperRoot.add(o),o.renderOrder=this.colliderHelperRoot.renderOrder}return i}};D.EXTENSION_NAME="VRMC_springBone";var _e=D;
|