@pixiv/three-vrm-springbone 1.0.0-beta.9 → 1.0.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.js +1033 -1037
- package/lib/three-vrm-springbone.min.js +2 -2
- package/lib/three-vrm-springbone.module.js +1033 -1037
- package/lib/three-vrm-springbone.module.min.js +2 -2
- package/package.json +9 -8
- package/ts3.4/types/VRMSpringBoneJoint.d.ts +10 -23
- package/ts3.4/types/VRMSpringBoneManager.d.ts +17 -3
- package/types/VRMSpringBoneCollider.d.ts +12 -12
- package/types/VRMSpringBoneColliderGroup.d.ts +14 -14
- package/types/VRMSpringBoneColliderShape.d.ts +20 -20
- package/types/VRMSpringBoneColliderShapeCapsule.d.ts +23 -23
- package/types/VRMSpringBoneColliderShapeSphere.d.ts +18 -18
- package/types/VRMSpringBoneJoint.d.ts +110 -123
- package/types/VRMSpringBoneJointSettings.d.ts +10 -10
- package/types/VRMSpringBoneLoaderPlugin.d.ts +34 -34
- package/types/VRMSpringBoneLoaderPluginOptions.d.ts +14 -14
- package/types/VRMSpringBoneManager.d.ts +47 -33
- package/types/helpers/VRMSpringBoneColliderHelper.d.ts +10 -10
- package/types/helpers/VRMSpringBoneJointHelper.d.ts +10 -10
- package/types/helpers/index.d.ts +2 -2
- package/types/helpers/utils/ColliderShapeBufferGeometry.d.ts +4 -4
- package/types/helpers/utils/ColliderShapeCapsuleBufferGeometry.d.ts +15 -15
- package/types/helpers/utils/ColliderShapeSphereBufferGeometry.d.ts +14 -14
- package/types/helpers/utils/SpringBoneBufferGeometry.d.ts +13 -13
- package/types/index.d.ts +10 -10
- package/types/tests/VRMSpringBoneColliderShapeCapsule.test.d.ts +1 -1
- package/types/tests/VRMSpringBoneColliderShapeSphere.test.d.ts +1 -1
- package/types/tests/matchers/toBeCloseToArray.d.ts +9 -9
- package/types/tests/matchers/toBeCloseToVector3.d.ts +10 -10
- package/types/utils/Matrix4InverseCache.d.ts +28 -28
- package/types/utils/getWorldQuaternionLite.d.ts +8 -8
- package/types/utils/mat4InvertCompat.d.ts +8 -8
- package/types/utils/traverseAncestorsFromRoot.d.ts +2 -2
- package/types/utils/traverseChildrenUntilConditionMet.d.ts +8 -8
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! (c) 2020-2021 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{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:1}get type(){return"capsule"}calculateCollision(t,e,s,n){i.copy(this.offset).applyMatrix4(t),r.copy(this.tail).applyMatrix4(t),r.sub(i);const o=r.lengthSq();n.copy(e).sub(i);const a=r.dot(n);a<=0||(o<=a||r.multiplyScalar(a/o),n.sub(r));const l=s+this.radius,h=n.length()-l;return n.normalize(),h}}class n extends e{constructor(e){var i,r;super(),this.offset=null!==(i=null==e?void 0:e.offset)&&void 0!==i?i:new t.Vector3(0,0,0),this.radius=null!==(r=null==e?void 0:e.radius)&&void 0!==r?r:1}get type(){return"sphere"}calculateCollision(t,e,i,r){r.copy(this.offset).applyMatrix4(t),r.negate().add(e);const s=i+this.radius,n=r.length()-s;return r.normalize(),n}}const o=new t.Vector3;class a extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentOffset=new t.Vector3,this._currentTail=new t.Vector3,this._shape=e,this._attrPos=new t.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._shape.radius&&(this._currentRadius=this._shape.radius,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),this._currentTail.equals(this._shape.tail)||(this._currentTail.copy(this._shape.tail),t=!0),t&&this._buildPosition()}_buildPosition(){o.copy(this._currentTail).sub(this._currentOffset);const t=o.length()/this._currentRadius;for(let e=0;e<=16;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(e,-Math.sin(i),-Math.cos(i),0),this._attrPos.setXYZ(17+e,t+Math.sin(i),Math.cos(i),0),this._attrPos.setXYZ(34+e,-Math.sin(i),0,-Math.cos(i)),this._attrPos.setXYZ(51+e,t+Math.sin(i),0,Math.cos(i))}for(let e=0;e<32;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(68+e,0,Math.sin(i),Math.cos(i)),this._attrPos.setXYZ(100+e,t,Math.sin(i),Math.cos(i))}const e=Math.atan2(o.y,Math.sqrt(o.x*o.x+o.z*o.z)),i=-Math.atan2(o.z,o.x);this.rotateZ(e),this.rotateY(i),this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<34;t++){const e=(t+1)%34;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(68+2*t,34+t,34+e)}for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(136+2*t,68+t,68+e),this._attrIndex.setXY(200+2*t,100+t,100+e)}this._attrIndex.needsUpdate=!0}}class l extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentOffset=new t.Vector3,this._shape=e,this._attrPos=new t.BufferAttribute(new Float32Array(288),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(192),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._shape.radius&&(this._currentRadius=this._shape.radius,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.needsUpdate=!0}}class h extends t.Group{constructor(e){if(super(),this.matrixAutoUpdate=!1,this.collider=e,this.collider.shape instanceof n)this._geometry=new l(this.collider.shape);else{if(!(this.collider.shape instanceof s))throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");this._geometry=new a(this.collider.shape)}const i=new t.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new t.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld),this._geometry.update(),super.updateMatrixWorld(t)}}class c extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentTail=new t.Vector3,this._springBone=e,this._attrPos=new t.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._springBone.settings.hitRadius&&(this._currentRadius=this._springBone.settings.hitRadius,t=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}}class d 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),this._geometry.update(),super.updateMatrixWorld(t)}}class u extends t.Object3D{constructor(t){super(),this.shape=t}}const p=new t.Vector3,_=new t.Vector3;const f=new t.Matrix4;function x(t){return t.invert?t.invert():t.getInverse(f.copy(t)),t}class v{constructor(e){this._inverseCache=new t.Matrix4,this._shouldUpdateInverse=!0,this.matrix=e;const i={set:(t,e,i)=>(this._shouldUpdateInverse=!0,t[e]=i,!0)};this._originalElements=e.elements,e.elements=new Proxy(e.elements,i)}get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),x(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}}const y=Object.freeze(new t.Matrix4),g=Object.freeze(new t.Quaternion),m=new t.Vector3,M=new t.Vector3,w=new t.Quaternion,b=new t.Matrix4,P=new t.Matrix4;class S{constructor(e,i,r={},s=[]){var n,o,a,l,h,c;this._currentTail=new t.Vector3,this._prevTail=new t.Vector3,this._nextTail=new t.Vector3,this._boneAxis=new t.Vector3,this._centerSpaceBoneLength=0,this._centerSpacePosition=new t.Vector3,this._center=null,this._parentWorldRotation=new t.Quaternion,this._initialLocalMatrix=new t.Matrix4,this._initialLocalRotation=new t.Quaternion,this._initialLocalChildPosition=new t.Vector3,this.bone=e,this.bone.matrixAutoUpdate=!1,this.child=i,this.settings={hitRadius:null!==(n=r.hitRadius)&&void 0!==n?n:0,stiffness:null!==(o=r.stiffness)&&void 0!==o?o:1,gravityPower:null!==(a=r.gravityPower)&&void 0!==a?a:0,gravityDir:null!==(h=null===(l=r.gravityDir)||void 0===l?void 0:l.clone())&&void 0!==h?h:new t.Vector3(0,-1,0),dragForce:null!==(c=r.dragForce)&&void 0!==c?c:.4},this.colliderGroups=s}get center(){return this._center}set center(t){var e;this._getMatrixCenterToWorld(b),this._currentTail.applyMatrix4(b),this._prevTail.applyMatrix4(b),this._nextTail.applyMatrix4(b),(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 v(this._center.matrixWorld))),this._getMatrixWorldToCenter(b),this._currentTail.applyMatrix4(b),this._prevTail.applyMatrix4(b),this._nextTail.applyMatrix4(b),b.multiply(this.bone.matrixWorld),this._centerSpacePosition.setFromMatrixPosition(b),this._centerSpaceBoneLength=m.copy(this._initialLocalChildPosition).applyMatrix4(b).sub(this._centerSpacePosition).length()}get initialLocalChildPosition(){return this._initialLocalChildPosition}setInitState(){this.bone.updateMatrix(),this.bone.updateWorldMatrix(!1,!1),this._centerSpacePosition.setFromMatrixPosition(this.bone.matrixWorld),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),this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)),this._prevTail.copy(this._currentTail),this._nextTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize(),this._centerSpaceBoneLength=m.copy(this._initialLocalChildPosition).applyMatrix4(this.bone.matrixWorld).sub(this._centerSpacePosition).length()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._getParentMatrixWorld(),this.bone.matrix),this._centerSpacePosition.setFromMatrixPosition(this.bone.matrixWorld),this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)),this._prevTail.copy(this._currentTail),this._nextTail.copy(this._currentTail)}update(t){if(t<=0)return;var e,i;this.bone.matrixWorld.multiplyMatrices(this._getParentMatrixWorld(),this.bone.matrix),this.bone.parent?(e=this.bone.parent,i=this._parentWorldRotation,e.matrixWorld.decompose(p,i,_)):this._parentWorldRotation.copy(g),this._getMatrixWorldToCenter(b),b.multiply(this.bone.matrixWorld),this._centerSpacePosition.setFromMatrixPosition(b),this._getMatrixWorldToCenter(P),P.multiply(this._getParentMatrixWorld());const r=this.settings.stiffness*t,s=M.copy(this.settings.gravityDir).multiplyScalar(this.settings.gravityPower*t);this._nextTail.copy(this._currentTail).add(m.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(m.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(P).sub(this._centerSpacePosition).normalize().multiplyScalar(r)).add(s),this._nextTail.sub(this._centerSpacePosition).normalize().multiplyScalar(this._centerSpaceBoneLength).add(this._centerSpacePosition),this._collision(this._nextTail),this._prevTail.copy(this._currentTail),this._currentTail.copy(this._nextTail);const n=x(b.copy(P.multiply(this._initialLocalMatrix))),o=w.setFromUnitVectors(this._boneAxis,m.copy(this._nextTail).applyMatrix4(n).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(o),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._getParentMatrixWorld(),this.bone.matrix)}_collision(t){this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{this._getMatrixWorldToCenter(b),b.multiply(e.matrixWorld);const i=e.shape.calculateCollision(b,t,this.settings.hitRadius,m);i<0&&(t.add(m.multiplyScalar(-i)),t.sub(this._centerSpacePosition).normalize().multiplyScalar(this._centerSpaceBoneLength).add(this._centerSpacePosition))}))}))}_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}_getParentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:y}}
|
|
2
|
+
import*as t from"three";class e{}const i=new t.Vector3,r=new t.Vector3;class s extends e{constructor(e){var i,r,s;super(),this.offset=null!==(i=null==e?void 0:e.offset)&&void 0!==i?i:new t.Vector3(0,0,0),this.tail=null!==(r=null==e?void 0:e.tail)&&void 0!==r?r:new t.Vector3(0,0,0),this.radius=null!==(s=null==e?void 0:e.radius)&&void 0!==s?s:0}get type(){return"capsule"}calculateCollision(t,e,s,n){i.copy(this.offset).applyMatrix4(t),r.copy(this.tail).applyMatrix4(t),r.sub(i);const o=r.lengthSq();n.copy(e).sub(i);const a=r.dot(n);a<=0||(o<=a||r.multiplyScalar(a/o),n.sub(r));const l=s+this.radius,h=n.length()-l;return n.normalize(),h}}class n extends e{constructor(e){var i,r;super(),this.offset=null!==(i=null==e?void 0:e.offset)&&void 0!==i?i:new t.Vector3(0,0,0),this.radius=null!==(r=null==e?void 0:e.radius)&&void 0!==r?r:0}get type(){return"sphere"}calculateCollision(t,e,i,r){r.copy(this.offset).applyMatrix4(t),r.negate().add(e);const s=i+this.radius,n=r.length()-s;return r.normalize(),n}}const o=new t.Vector3;class a extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentOffset=new t.Vector3,this._currentTail=new t.Vector3,this._shape=e,this._attrPos=new t.BufferAttribute(new Float32Array(396),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(264),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._shape.radius&&(this._currentRadius=this._shape.radius,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),this._currentTail.equals(this._shape.tail)||(this._currentTail.copy(this._shape.tail),t=!0),t&&this._buildPosition()}_buildPosition(){o.copy(this._currentTail).sub(this._currentOffset);const t=o.length()/this._currentRadius;for(let e=0;e<=16;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(e,-Math.sin(i),-Math.cos(i),0),this._attrPos.setXYZ(17+e,t+Math.sin(i),Math.cos(i),0),this._attrPos.setXYZ(34+e,-Math.sin(i),0,-Math.cos(i)),this._attrPos.setXYZ(51+e,t+Math.sin(i),0,Math.cos(i))}for(let e=0;e<32;e++){const i=e/16*Math.PI;this._attrPos.setXYZ(68+e,0,Math.sin(i),Math.cos(i)),this._attrPos.setXYZ(100+e,t,Math.sin(i),Math.cos(i))}const e=Math.atan2(o.y,Math.sqrt(o.x*o.x+o.z*o.z)),i=-Math.atan2(o.z,o.x);this.rotateZ(e),this.rotateY(i),this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<34;t++){const e=(t+1)%34;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(68+2*t,34+t,34+e)}for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(136+2*t,68+t,68+e),this._attrIndex.setXY(200+2*t,100+t,100+e)}this._attrIndex.needsUpdate=!0}}class l extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentOffset=new t.Vector3,this._shape=e,this._attrPos=new t.BufferAttribute(new Float32Array(288),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(192),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._shape.radius&&(this._currentRadius=this._shape.radius,t=!0),this._currentOffset.equals(this._shape.offset)||(this._currentOffset.copy(this._shape.offset),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentOffset.x,this._currentOffset.y,this._currentOffset.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.needsUpdate=!0}}class h extends t.Group{constructor(e){if(super(),this.matrixAutoUpdate=!1,this.collider=e,this.collider.shape instanceof n)this._geometry=new l(this.collider.shape);else{if(!(this.collider.shape instanceof s))throw new Error("VRMSpringBoneColliderHelper: Unknown collider shape type detected");this._geometry=new a(this.collider.shape)}const i=new t.LineBasicMaterial({color:16711935,depthTest:!1,depthWrite:!1});this._line=new t.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.collider.updateWorldMatrix(!0,!1),this.matrix.copy(this.collider.matrixWorld),this._geometry.update(),super.updateMatrixWorld(t)}}class d extends t.BufferGeometry{constructor(e){super(),this._currentRadius=0,this._currentTail=new t.Vector3,this._springBone=e,this._attrPos=new t.BufferAttribute(new Float32Array(294),3),this.setAttribute("position",this._attrPos),this._attrIndex=new t.BufferAttribute(new Uint16Array(194),1),this.setIndex(this._attrIndex),this._buildIndex(),this.update()}update(){let t=!1;this._currentRadius!==this._springBone.settings.hitRadius&&(this._currentRadius=this._springBone.settings.hitRadius,t=!0),this._currentTail.equals(this._springBone.initialLocalChildPosition)||(this._currentTail.copy(this._springBone.initialLocalChildPosition),t=!0),t&&this._buildPosition()}_buildPosition(){for(let t=0;t<32;t++){const e=t/16*Math.PI;this._attrPos.setXYZ(t,Math.cos(e),Math.sin(e),0),this._attrPos.setXYZ(32+t,0,Math.cos(e),Math.sin(e)),this._attrPos.setXYZ(64+t,Math.sin(e),0,Math.cos(e))}this.scale(this._currentRadius,this._currentRadius,this._currentRadius),this.translate(this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.setXYZ(96,0,0,0),this._attrPos.setXYZ(97,this._currentTail.x,this._currentTail.y,this._currentTail.z),this._attrPos.needsUpdate=!0}_buildIndex(){for(let t=0;t<32;t++){const e=(t+1)%32;this._attrIndex.setXY(2*t,t,e),this._attrIndex.setXY(64+2*t,32+t,32+e),this._attrIndex.setXY(128+2*t,64+t,64+e)}this._attrIndex.setXY(192,96,97),this._attrIndex.needsUpdate=!0}}class c extends t.Group{constructor(e){super(),this.matrixAutoUpdate=!1,this.springBone=e,this._geometry=new d(this.springBone);const i=new t.LineBasicMaterial({color:16776960,depthTest:!1,depthWrite:!1});this._line=new t.LineSegments(this._geometry,i),this.add(this._line)}dispose(){this._geometry.dispose()}updateMatrixWorld(t){this.springBone.bone.updateWorldMatrix(!0,!1),this.matrix.copy(this.springBone.bone.matrixWorld),this._geometry.update(),super.updateMatrixWorld(t)}}class u extends t.Object3D{constructor(t){super(),this.shape=t}}const p=new t.Matrix4;function _(t){return t.invert?t.invert():t.getInverse(p.copy(t)),t}class f{constructor(e){this._inverseCache=new t.Matrix4,this._shouldUpdateInverse=!0,this.matrix=e;const i={set:(t,e,i)=>(this._shouldUpdateInverse=!0,t[e]=i,!0)};this._originalElements=e.elements,e.elements=new Proxy(e.elements,i)}get inverse(){return this._shouldUpdateInverse&&(this._inverseCache.copy(this.matrix),_(this._inverseCache),this._shouldUpdateInverse=!1),this._inverseCache}revert(){this.matrix.elements=this._originalElements}}const v=new t.Matrix4,x=new t.Vector3,y=new t.Vector3,g=new t.Vector3,w=new t.Vector3,M=new t.Vector3,m=new t.Vector3,b=new t.Quaternion,S=new t.Matrix4,P=new t.Matrix4;class R{constructor(e,i,r={},s=[]){var n,o,a,l,h,d;this._currentTail=new t.Vector3,this._prevTail=new t.Vector3,this._boneAxis=new t.Vector3,this._worldSpaceBoneLength=0,this._center=null,this._initialLocalMatrix=new t.Matrix4,this._initialLocalRotation=new t.Quaternion,this._initialLocalChildPosition=new t.Vector3,this.bone=e,this.bone.matrixAutoUpdate=!1,this.child=i,this.settings={hitRadius:null!==(n=r.hitRadius)&&void 0!==n?n:0,stiffness:null!==(o=r.stiffness)&&void 0!==o?o:1,gravityPower:null!==(a=r.gravityPower)&&void 0!==a?a:0,gravityDir:null!==(h=null===(l=r.gravityDir)||void 0===l?void 0:l.clone())&&void 0!==h?h:new t.Vector3(0,-1,0),dragForce:null!==(d=r.dragForce)&&void 0!==d?d:.4},this.colliderGroups=s}get center(){return this._center}set center(t){var e;(null===(e=this._center)||void 0===e?void 0:e.userData.inverseCacheProxy)&&(this._center.userData.inverseCacheProxy.revert(),delete this._center.userData.inverseCacheProxy),this._center=t,this._center&&(this._center.userData.inverseCacheProxy||(this._center.userData.inverseCacheProxy=new f(this._center.matrixWorld)))}get initialLocalChildPosition(){return this._initialLocalChildPosition}get _parentMatrixWorld(){return this.bone.parent?this.bone.parent.matrixWorld:v}setInitState(){this._initialLocalMatrix.copy(this.bone.matrix),this._initialLocalRotation.copy(this.bone.quaternion),this.child?this._initialLocalChildPosition.copy(this.child.position):this._initialLocalChildPosition.copy(this.bone.position).normalize().multiplyScalar(.07),this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)),this._prevTail.copy(this._currentTail),this._boneAxis.copy(this._initialLocalChildPosition).normalize(),this._worldSpaceBoneLength=x.copy(this._initialLocalChildPosition).applyMatrix4(this.bone.matrixWorld).sub(y.setFromMatrixPosition(this.bone.matrixWorld)).length()}reset(){this.bone.quaternion.copy(this._initialLocalRotation),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix);const t=this._getMatrixWorldToCenter(S);this.bone.localToWorld(this._currentTail.copy(this._initialLocalChildPosition)).applyMatrix4(t),this._prevTail.copy(this._currentTail)}update(t){if(t<=0)return;w.setFromMatrixPosition(this.bone.matrixWorld);let e=this._getMatrixWorldToCenter(S);M.copy(w).applyMatrix4(e);const i=b.setFromRotationMatrix(e),r=P.copy(e).multiply(this._parentMatrixWorld),s=y.copy(this._boneAxis).applyMatrix4(this._initialLocalMatrix).applyMatrix4(r).sub(M).normalize(),n=g.copy(this.settings.gravityDir).applyQuaternion(i).normalize(),o=this._getMatrixCenterToWorld(S);m.copy(this._currentTail).add(x.copy(this._currentTail).sub(this._prevTail).multiplyScalar(1-this.settings.dragForce)).add(x.copy(s).multiplyScalar(this.settings.stiffness*t)).add(x.copy(n).multiplyScalar(this.settings.gravityPower*t)).applyMatrix4(o),m.sub(w).normalize().multiplyScalar(this._worldSpaceBoneLength).add(w),this._collision(m),e=this._getMatrixWorldToCenter(S),this._prevTail.copy(this._currentTail),this._currentTail.copy(x.copy(m).applyMatrix4(e));const a=_(S.copy(this._parentMatrixWorld).multiply(this._initialLocalMatrix)),l=b.setFromUnitVectors(this._boneAxis,x.copy(m).applyMatrix4(a).normalize());this.bone.quaternion.copy(this._initialLocalRotation).multiply(l),this.bone.updateMatrix(),this.bone.matrixWorld.multiplyMatrices(this._parentMatrixWorld,this.bone.matrix)}_collision(t){this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{const i=e.shape.calculateCollision(e.matrixWorld,t,this.settings.hitRadius,x);i<0&&(t.add(x.multiplyScalar(-i)),t.sub(w).normalize().multiplyScalar(this._worldSpaceBoneLength).add(w))}))}))}_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}}
|
|
3
3
|
/*! *****************************************************************************
|
|
4
4
|
Copyright (c) Microsoft Corporation.
|
|
5
5
|
|
|
@@ -13,4 +13,4 @@ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
13
13
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
14
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
15
|
PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
-
***************************************************************************** */function
|
|
16
|
+
***************************************************************************** */function B(t,e,i,r){return new(i||(i=Promise))((function(s,n){function o(t){try{l(r.next(t))}catch(t){n(t)}}function a(t){try{l(r.throw(t))}catch(t){n(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(o,a)}l((r=r.apply(t,e||[])).next())}))}function I(t,e){const i=[];let r=t;for(;null!==r;)i.unshift(r),r=r.parent;i.forEach((t=>{e(t)}))}function T(t,e){t.children.forEach((t=>{e(t)||T(t,e)}))}class V{constructor(){this._joints=new Set,this._objectSpringBonesMap=new Map}get joints(){return this._joints}get springBones(){return console.warn("VRMSpringBoneManager: springBones is deprecated. use joints instead."),this._joints}get colliderGroups(){const t=new Set;return this._joints.forEach((e=>{e.colliderGroups.forEach((e=>{t.add(e)}))})),Array.from(t)}get colliders(){const t=new Set;return this.colliderGroups.forEach((e=>{e.colliders.forEach((e=>{t.add(e)}))})),Array.from(t)}addJoint(t){this._joints.add(t);let e=this._objectSpringBonesMap.get(t.bone);null==e&&(e=new Set,this._objectSpringBonesMap.set(t.bone,e)),e.add(t)}addSpringBone(t){console.warn("VRMSpringBoneManager: addSpringBone() is deprecated. use addJoint() instead."),this.addJoint(t)}deleteJoint(t){this._joints.delete(t);this._objectSpringBonesMap.get(t.bone).delete(t)}deleteSpringBone(t){console.warn("VRMSpringBoneManager: deleteSpringBone() is deprecated. use deleteJoint() instead."),this.deleteJoint(t)}setInitState(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.setInitState()))}reset(){const t=new Set,e=new Set,i=new Set;for(const r of this._joints)this._processSpringBone(r,t,e,i,(t=>t.reset()))}update(t){const e=new Set,i=new Set,r=new Set;for(const s of this._joints)this._processSpringBone(s,e,i,r,(e=>e.update(t))),T(s.bone,(t=>{var e,i;return(null!==(i=null===(e=this._objectSpringBonesMap.get(t))||void 0===e?void 0:e.size)&&void 0!==i?i:0)>0||(t.updateWorldMatrix(!1,!1),!1)}))}_processSpringBone(t,e,i,r,s){if(i.has(t))return;if(e.has(t))throw new Error("VRMSpringBoneManager: Circular dependency detected while updating springbones");e.add(t);const n=this._getDependencies(t);for(const t of n)I(t,(t=>{const n=this._objectSpringBonesMap.get(t);if(n)for(const t of n)this._processSpringBone(t,e,i,r,s);else r.has(t)||(t.updateWorldMatrix(!1,!1),r.add(t))}));t.bone.updateMatrix(),t.bone.updateWorldMatrix(!1,!1),s(t),r.add(t.bone),i.add(t)}_getDependencies(t){const e=new Set,i=t.bone.parent;return i&&e.add(i),t.colliderGroups.forEach((t=>{t.colliders.forEach((t=>{e.add(t)}))})),e}}const C=new Set(["1.0","1.0-beta"]);class E{constructor(t,e){this.parser=t,this.jointHelperRoot=null==e?void 0:e.jointHelperRoot,this.colliderHelperRoot=null==e?void 0:e.colliderHelperRoot}get name(){return E.EXTENSION_NAME}afterRoot(t){return B(this,void 0,void 0,(function*(){t.userData.vrmSpringBoneManager=yield this._import(t)}))}_import(t){return B(this,void 0,void 0,(function*(){const e=yield this._v1Import(t);if(null!=e)return e;const i=yield this._v0Import(t);return null!=i?i:null}))}_v1Import(e){var i,r,s,n,o;return B(this,void 0,void 0,(function*(){const a=e.parser.json;if(!(-1!==(null===(i=a.extensionsUsed)||void 0===i?void 0:i.indexOf(E.EXTENSION_NAME))))return null;const l=new V,h=yield e.parser.getDependencies("node"),d=null===(r=a.extensions)||void 0===r?void 0:r[E.EXTENSION_NAME];if(!d)return null;const c=d.specVersion;if(!C.has(c))return console.warn(`VRMSpringBoneLoaderPlugin: Unknown ${E.EXTENSION_NAME} specVersion "${c}"`),null;const u=null===(s=d.colliders)||void 0===s?void 0:s.map(((e,i)=>{var r,s,n,o,a;const l=h[e.node],d=e.shape;if(d.sphere)return this._importSphereCollider(l,{offset:(new t.Vector3).fromArray(null!==(r=d.sphere.offset)&&void 0!==r?r:[0,0,0]),radius:null!==(s=d.sphere.radius)&&void 0!==s?s:0});if(d.capsule)return this._importCapsuleCollider(l,{offset:(new t.Vector3).fromArray(null!==(n=d.capsule.offset)&&void 0!==n?n:[0,0,0]),radius:null!==(o=d.capsule.radius)&&void 0!==o?o:0,tail:(new t.Vector3).fromArray(null!==(a=d.capsule.tail)&&void 0!==a?a:[0,0,0])});throw new Error(`VRMSpringBoneLoaderPlugin: The collider #${i} has no valid shape`)})),p=null===(n=d.colliderGroups)||void 0===n?void 0:n.map(((t,e)=>{var i;return{colliders:(null!==(i=t.colliders)&&void 0!==i?i:[]).map((t=>{const i=null==u?void 0:u[t];if(null==i)throw new Error(`VRMSpringBoneLoaderPlugin: The colliderGroup #${e} attempted to use a collider #${t} but not found`);return i})),name:t.name}}));return null===(o=d.springs)||void 0===o||o.forEach(((e,i)=>{var r;const s=e.joints,n=null===(r=e.colliderGroups)||void 0===r?void 0:r.map((t=>{const e=null==p?void 0:p[t];if(null==e)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${t} but not found`);return e})),o=null!=e.center?h[e.center]:void 0;let a;s.forEach((e=>{if(a){const i=a.node,r=h[i],s=e.node,d=h[s],c={hitRadius:a.hitRadius,dragForce:a.dragForce,gravityPower:a.gravityPower,stiffness:a.stiffness,gravityDir:null!=a.gravityDir?(new t.Vector3).fromArray(a.gravityDir):void 0},u=this._importJoint(r,d,c,n);o&&(u.center=o),l.addJoint(u)}a=e}))})),l.setInitState(),l}))}_v0Import(e){var i,r,s;return B(this,void 0,void 0,(function*(){const n=e.parser.json;if(!(-1!==(null===(i=n.extensionsUsed)||void 0===i?void 0:i.indexOf("VRM"))))return null;const o=null===(r=n.extensions)||void 0===r?void 0:r.VRM,a=null==o?void 0:o.secondaryAnimation;if(!a)return null;const l=null==a?void 0:a.boneGroups;if(!l)return null;const h=new V,d=yield e.parser.getDependencies("node"),c=null===(s=a.colliderGroups)||void 0===s?void 0:s.map((e=>{var i;const r=d[e.node];return{colliders:(null!==(i=e.colliders)&&void 0!==i?i:[]).map(((e,i)=>{var s,n,o;const a=new t.Vector3(0,0,0);return e.offset&&a.set(null!==(s=e.offset.x)&&void 0!==s?s:0,null!==(n=e.offset.y)&&void 0!==n?n:0,e.offset.z?-e.offset.z:0),this._importSphereCollider(r,{offset:a,radius:null!==(o=e.radius)&&void 0!==o?o:0})}))}}));return null==l||l.forEach(((e,i)=>{const r=e.bones;r&&r.forEach((r=>{var s,n,o,a;const l=d[r],u=new t.Vector3;e.gravityDir?u.set(null!==(s=e.gravityDir.x)&&void 0!==s?s:0,null!==(n=e.gravityDir.y)&&void 0!==n?n:0,null!==(o=e.gravityDir.z)&&void 0!==o?o:0):u.set(0,-1,0);const p=null!=e.center?d[e.center]:void 0,_={hitRadius:e.hitRadius,dragForce:e.dragForce,gravityPower:e.gravityPower,stiffness:e.stiffiness,gravityDir:u},f=null===(a=e.colliderGroups)||void 0===a?void 0:a.map((t=>{const e=null==c?void 0:c[t];if(null==e)throw new Error(`VRMSpringBoneLoaderPlugin: The spring #${i} attempted to use a colliderGroup ${t} but not found`);return e}));l.traverse((t=>{var e;const i=null!==(e=t.children[0])&&void 0!==e?e:null,r=this._importJoint(t,i,_,f);p&&(r.center=p),h.addJoint(r)}))}))})),e.scene.updateMatrixWorld(),h.setInitState(),h}))}_importJoint(t,e,i,r){const s=new R(t,e,i,r);if(this.jointHelperRoot){const t=new c(s);this.jointHelperRoot.add(t),t.renderOrder=this.jointHelperRoot.renderOrder}return s}_importSphereCollider(t,e){const{offset:i,radius:r}=e,s=new n({offset:i,radius:r}),o=new u(s);if(t.add(o),this.colliderHelperRoot){const t=new h(o);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return o}_importCapsuleCollider(t,e){const{offset:i,radius:r,tail:n}=e,o=new s({offset:i,radius:r,tail:n}),a=new u(o);if(t.add(a),this.colliderHelperRoot){const t=new h(a);this.colliderHelperRoot.add(t),t.renderOrder=this.colliderHelperRoot.renderOrder}return a}}E.EXTENSION_NAME="VRMC_springBone";export{u as VRMSpringBoneCollider,h as VRMSpringBoneColliderHelper,e as VRMSpringBoneColliderShape,s as VRMSpringBoneColliderShapeCapsule,n as VRMSpringBoneColliderShapeSphere,R as VRMSpringBoneJoint,c as VRMSpringBoneJointHelper,E as VRMSpringBoneLoaderPlugin,V as VRMSpringBoneManager};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pixiv/three-vrm-springbone",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Spring bone module for @pixiv/three-vrm",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "pixiv",
|
|
@@ -31,8 +31,9 @@
|
|
|
31
31
|
"build-types": "tsc --declaration --declarationDir ./types --emitDeclarationOnly && downlevel-dts types ts3.4/types",
|
|
32
32
|
"docs": "typedoc --entryPoints ./src/index.ts --out docs",
|
|
33
33
|
"test": "jest",
|
|
34
|
-
"lint": "eslint \"src/**/*.{ts,tsx}\" &&
|
|
35
|
-
"lint-
|
|
34
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\" && yarn lint-examples && prettier \"src/**/*.{ts,tsx}\" --check",
|
|
35
|
+
"lint-examples": "eslint \"examples/**/*.{ts,tsx,js,html}\" --rule \"padded-blocks: error\"",
|
|
36
|
+
"lint-fix": "eslint \"src/**/*.{ts,tsx}\" --fix && eslint \"examples/**/*.{ts,tsx,js,html}\" --fix && prettier \"src/**/*.{ts,tsx}\" --write"
|
|
36
37
|
},
|
|
37
38
|
"lint-staged": {
|
|
38
39
|
"./src/**/*.{ts,tsx}": [
|
|
@@ -41,15 +42,15 @@
|
|
|
41
42
|
]
|
|
42
43
|
},
|
|
43
44
|
"dependencies": {
|
|
44
|
-
"@pixiv/types-vrm-0.0": "
|
|
45
|
-
"@pixiv/types-vrmc-springbone-1.0": "
|
|
45
|
+
"@pixiv/types-vrm-0.0": "1.0.0",
|
|
46
|
+
"@pixiv/types-vrmc-springbone-1.0": "1.0.0"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
49
|
"lint-staged": "10.4.2",
|
|
49
|
-
"three": "^0.
|
|
50
|
+
"three": "^0.140.2"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
|
-
"three": "^0.
|
|
53
|
+
"three": "^0.140.2"
|
|
53
54
|
},
|
|
54
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "4d68337eb9a48a1bc53db87c9f5db7894184ce35"
|
|
55
56
|
}
|
|
@@ -24,42 +24,28 @@ export declare class VRMSpringBoneJoint {
|
|
|
24
24
|
*/
|
|
25
25
|
readonly child: THREE.Object3D | null;
|
|
26
26
|
/**
|
|
27
|
-
* Current position of child tail, in
|
|
27
|
+
* Current position of child tail, in center unit. Will be used for verlet integration.
|
|
28
28
|
*/
|
|
29
29
|
private _currentTail;
|
|
30
30
|
/**
|
|
31
|
-
* Previous position of child tail, in
|
|
31
|
+
* Previous position of child tail, in center unit. Will be used for verlet integration.
|
|
32
32
|
*/
|
|
33
33
|
private _prevTail;
|
|
34
|
-
/**
|
|
35
|
-
* Next position of child tail, in world unit. Will be used for verlet integration.
|
|
36
|
-
* Actually used only in [[update]] and it's kind of temporary variable.
|
|
37
|
-
*/
|
|
38
|
-
private _nextTail;
|
|
39
34
|
/**
|
|
40
35
|
* Initial axis of the bone, in local unit.
|
|
41
36
|
*/
|
|
42
37
|
private _boneAxis;
|
|
43
38
|
/**
|
|
44
|
-
* Length of the bone in
|
|
45
|
-
* It's same as local unit length unless there are scale
|
|
46
|
-
*/
|
|
47
|
-
private _centerSpaceBoneLength;
|
|
48
|
-
/**
|
|
49
|
-
* Position of this bone in relative space, kind of a temporary variable.
|
|
39
|
+
* Length of the bone in world unit. Will be used for normalization in update loop.
|
|
40
|
+
* It's same as local unit length unless there are scale transformations in the world space.
|
|
50
41
|
*/
|
|
51
|
-
private
|
|
42
|
+
private _worldSpaceBoneLength;
|
|
52
43
|
/**
|
|
53
44
|
* This springbone will be calculated based on the space relative from this object.
|
|
54
45
|
* If this is `null`, springbone will be calculated in world space.
|
|
55
46
|
*/
|
|
56
47
|
private _center;
|
|
57
48
|
center: THREE.Object3D | null;
|
|
58
|
-
/**
|
|
59
|
-
* Rotation of parent bone, in world unit.
|
|
60
|
-
* We should update this constantly in [[update]].
|
|
61
|
-
*/
|
|
62
|
-
private _parentWorldRotation;
|
|
63
49
|
/**
|
|
64
50
|
* Initial state of the local matrix of the bone.
|
|
65
51
|
*/
|
|
@@ -73,6 +59,11 @@ export declare class VRMSpringBoneJoint {
|
|
|
73
59
|
*/
|
|
74
60
|
private _initialLocalChildPosition;
|
|
75
61
|
readonly initialLocalChildPosition: THREE.Vector3;
|
|
62
|
+
/*
|
|
63
|
+
* Returns the world matrix of its parent object.
|
|
64
|
+
* Note that it returns a reference to the matrix. Don't mutate this directly!
|
|
65
|
+
*/
|
|
66
|
+
private readonly _parentMatrixWorld: any;
|
|
76
67
|
/**
|
|
77
68
|
* Create a new VRMSpringBone.
|
|
78
69
|
*
|
|
@@ -115,8 +106,4 @@ export declare class VRMSpringBoneJoint {
|
|
|
115
106
|
* @param target Target matrix
|
|
116
107
|
*/
|
|
117
108
|
private _getMatrixWorldToCenter;
|
|
118
|
-
/**
|
|
119
|
-
* Returns the world matrix of its parent object.
|
|
120
|
-
*/
|
|
121
|
-
private _getParentMatrixWorld;
|
|
122
109
|
}
|
|
@@ -2,19 +2,32 @@ import { VRMSpringBoneJoint } from './VRMSpringBoneJoint';
|
|
|
2
2
|
import { VRMSpringBoneCollider } from './VRMSpringBoneCollider';
|
|
3
3
|
import { VRMSpringBoneColliderGroup } from './VRMSpringBoneColliderGroup';
|
|
4
4
|
export declare class VRMSpringBoneManager {
|
|
5
|
-
private
|
|
5
|
+
private _joints;
|
|
6
|
+
readonly joints: Set<VRMSpringBoneJoint>;
|
|
7
|
+
/*
|
|
8
|
+
* @deprecated Use {@link joints} instead.
|
|
9
|
+
*/
|
|
6
10
|
readonly springBones: Set<VRMSpringBoneJoint>;
|
|
7
11
|
readonly colliderGroups: VRMSpringBoneColliderGroup[];
|
|
8
12
|
readonly colliders: VRMSpringBoneCollider[];
|
|
9
13
|
private _objectSpringBonesMap;
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
addJoint(joint: VRMSpringBoneJoint): void;
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use {@link addJoint} instead.
|
|
17
|
+
*/
|
|
18
|
+
addSpringBone(joint: VRMSpringBoneJoint): void;
|
|
19
|
+
deleteJoint(joint: VRMSpringBoneJoint): void;
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated Use {@link deleteJoint} instead.
|
|
22
|
+
*/
|
|
23
|
+
deleteSpringBone(joint: VRMSpringBoneJoint): void;
|
|
12
24
|
setInitState(): void;
|
|
13
25
|
reset(): void;
|
|
14
26
|
update(delta: number): void;
|
|
15
27
|
/**
|
|
16
28
|
* Update a spring bone.
|
|
17
29
|
* If there are other spring bone that are dependant, it will try to update them recursively.
|
|
30
|
+
* It updates matrixWorld of all ancestors and myself.
|
|
18
31
|
* It might throw an error if there are circular dependencies.
|
|
19
32
|
*
|
|
20
33
|
* Intended to be used in {@link update} and {@link _processSpringBone} itself recursively.
|
|
@@ -22,6 +35,7 @@ export declare class VRMSpringBoneManager {
|
|
|
22
35
|
* @param springBone A springBone you want to update
|
|
23
36
|
* @param springBonesTried Set of springBones that are already tried to be updated
|
|
24
37
|
* @param springBonesDone Set of springBones that are already up to date
|
|
38
|
+
* @param objectUpdated Set of object3D whose matrixWorld is updated
|
|
25
39
|
*/
|
|
26
40
|
private _processSpringBone;
|
|
27
41
|
/**
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import type { VRMSpringBoneColliderShape } from './VRMSpringBoneColliderShape';
|
|
3
|
-
/**
|
|
4
|
-
* Represents a collider of a VRM.
|
|
5
|
-
*/
|
|
6
|
-
export declare class VRMSpringBoneCollider extends THREE.Object3D {
|
|
7
|
-
/**
|
|
8
|
-
* The shape of the collider.
|
|
9
|
-
*/
|
|
10
|
-
readonly shape: VRMSpringBoneColliderShape;
|
|
11
|
-
constructor(shape: VRMSpringBoneColliderShape);
|
|
12
|
-
}
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import type { VRMSpringBoneColliderShape } from './VRMSpringBoneColliderShape';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a collider of a VRM.
|
|
5
|
+
*/
|
|
6
|
+
export declare class VRMSpringBoneCollider extends THREE.Object3D {
|
|
7
|
+
/**
|
|
8
|
+
* The shape of the collider.
|
|
9
|
+
*/
|
|
10
|
+
readonly shape: VRMSpringBoneColliderShape;
|
|
11
|
+
constructor(shape: VRMSpringBoneColliderShape);
|
|
12
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { VRMSpringBoneCollider } from './VRMSpringBoneCollider';
|
|
2
|
-
/**
|
|
3
|
-
* Represents a collider group of a VRM.
|
|
4
|
-
*/
|
|
5
|
-
export interface VRMSpringBoneColliderGroup {
|
|
6
|
-
/**
|
|
7
|
-
* The colliders of the collider group.
|
|
8
|
-
*/
|
|
9
|
-
colliders: VRMSpringBoneCollider[];
|
|
10
|
-
/**
|
|
11
|
-
* The name of the collider.
|
|
12
|
-
*/
|
|
13
|
-
name?: string;
|
|
14
|
-
}
|
|
1
|
+
import type { VRMSpringBoneCollider } from './VRMSpringBoneCollider';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a collider group of a VRM.
|
|
4
|
+
*/
|
|
5
|
+
export interface VRMSpringBoneColliderGroup {
|
|
6
|
+
/**
|
|
7
|
+
* The colliders of the collider group.
|
|
8
|
+
*/
|
|
9
|
+
colliders: VRMSpringBoneCollider[];
|
|
10
|
+
/**
|
|
11
|
+
* The name of the collider.
|
|
12
|
+
*/
|
|
13
|
+
name?: string;
|
|
14
|
+
}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a shape of a collider.
|
|
3
|
-
*/
|
|
4
|
-
export declare abstract class VRMSpringBoneColliderShape {
|
|
5
|
-
/**
|
|
6
|
-
* The type of the shape.
|
|
7
|
-
*/
|
|
8
|
-
abstract get type(): string;
|
|
9
|
-
/**
|
|
10
|
-
* Calculate a distance and a direction from the collider to a target object.
|
|
11
|
-
* It's hit if the distance is negative.
|
|
12
|
-
* The direction will be contained in the given target vector.
|
|
13
|
-
*
|
|
14
|
-
* @param colliderMatrix A matrix represents the transform of the collider
|
|
15
|
-
* @param objectPosition A vector represents the position of the target object
|
|
16
|
-
* @param objectRadius The radius of the object
|
|
17
|
-
* @param target The result direction will be contained in this vector
|
|
18
|
-
*/
|
|
19
|
-
abstract calculateCollision(colliderMatrix: THREE.Matrix4, objectPosition: THREE.Vector3, objectRadius: number, target: THREE.Vector3): number;
|
|
20
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Represents a shape of a collider.
|
|
3
|
+
*/
|
|
4
|
+
export declare abstract class VRMSpringBoneColliderShape {
|
|
5
|
+
/**
|
|
6
|
+
* The type of the shape.
|
|
7
|
+
*/
|
|
8
|
+
abstract get type(): string;
|
|
9
|
+
/**
|
|
10
|
+
* Calculate a distance and a direction from the collider to a target object.
|
|
11
|
+
* It's hit if the distance is negative.
|
|
12
|
+
* The direction will be contained in the given target vector.
|
|
13
|
+
*
|
|
14
|
+
* @param colliderMatrix A matrix represents the transform of the collider
|
|
15
|
+
* @param objectPosition A vector represents the position of the target object
|
|
16
|
+
* @param objectRadius The radius of the object
|
|
17
|
+
* @param target The result direction will be contained in this vector
|
|
18
|
+
*/
|
|
19
|
+
abstract calculateCollision(colliderMatrix: THREE.Matrix4, objectPosition: THREE.Vector3, objectRadius: number, target: THREE.Vector3): number;
|
|
20
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { VRMSpringBoneColliderShape } from './VRMSpringBoneColliderShape';
|
|
3
|
-
export declare class VRMSpringBoneColliderShapeCapsule extends VRMSpringBoneColliderShape {
|
|
4
|
-
get type(): 'capsule';
|
|
5
|
-
/**
|
|
6
|
-
* The offset of the head from the origin.
|
|
7
|
-
*/
|
|
8
|
-
offset: THREE.Vector3;
|
|
9
|
-
/**
|
|
10
|
-
* The offset of the tail from the origin.
|
|
11
|
-
*/
|
|
12
|
-
tail: THREE.Vector3;
|
|
13
|
-
/**
|
|
14
|
-
* The radius.
|
|
15
|
-
*/
|
|
16
|
-
radius: number;
|
|
17
|
-
constructor(params?: {
|
|
18
|
-
radius?: number;
|
|
19
|
-
offset?: THREE.Vector3;
|
|
20
|
-
tail?: THREE.Vector3;
|
|
21
|
-
});
|
|
22
|
-
calculateCollision(colliderMatrix: THREE.Matrix4, objectPosition: THREE.Vector3, objectRadius: number, target: THREE.Vector3): number;
|
|
23
|
-
}
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { VRMSpringBoneColliderShape } from './VRMSpringBoneColliderShape';
|
|
3
|
+
export declare class VRMSpringBoneColliderShapeCapsule extends VRMSpringBoneColliderShape {
|
|
4
|
+
get type(): 'capsule';
|
|
5
|
+
/**
|
|
6
|
+
* The offset of the head from the origin.
|
|
7
|
+
*/
|
|
8
|
+
offset: THREE.Vector3;
|
|
9
|
+
/**
|
|
10
|
+
* The offset of the tail from the origin.
|
|
11
|
+
*/
|
|
12
|
+
tail: THREE.Vector3;
|
|
13
|
+
/**
|
|
14
|
+
* The radius.
|
|
15
|
+
*/
|
|
16
|
+
radius: number;
|
|
17
|
+
constructor(params?: {
|
|
18
|
+
radius?: number;
|
|
19
|
+
offset?: THREE.Vector3;
|
|
20
|
+
tail?: THREE.Vector3;
|
|
21
|
+
});
|
|
22
|
+
calculateCollision(colliderMatrix: THREE.Matrix4, objectPosition: THREE.Vector3, objectRadius: number, target: THREE.Vector3): number;
|
|
23
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import * as THREE from 'three';
|
|
2
|
-
import { VRMSpringBoneColliderShape } from './VRMSpringBoneColliderShape';
|
|
3
|
-
export declare class VRMSpringBoneColliderShapeSphere extends VRMSpringBoneColliderShape {
|
|
4
|
-
get type(): 'sphere';
|
|
5
|
-
/**
|
|
6
|
-
* The offset from the origin.
|
|
7
|
-
*/
|
|
8
|
-
offset: THREE.Vector3;
|
|
9
|
-
/**
|
|
10
|
-
* The radius.
|
|
11
|
-
*/
|
|
12
|
-
radius: number;
|
|
13
|
-
constructor(params?: {
|
|
14
|
-
radius?: number;
|
|
15
|
-
offset?: THREE.Vector3;
|
|
16
|
-
});
|
|
17
|
-
calculateCollision(colliderMatrix: THREE.Matrix4, objectPosition: THREE.Vector3, objectRadius: number, target: THREE.Vector3): number;
|
|
18
|
-
}
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import { VRMSpringBoneColliderShape } from './VRMSpringBoneColliderShape';
|
|
3
|
+
export declare class VRMSpringBoneColliderShapeSphere extends VRMSpringBoneColliderShape {
|
|
4
|
+
get type(): 'sphere';
|
|
5
|
+
/**
|
|
6
|
+
* The offset from the origin.
|
|
7
|
+
*/
|
|
8
|
+
offset: THREE.Vector3;
|
|
9
|
+
/**
|
|
10
|
+
* The radius.
|
|
11
|
+
*/
|
|
12
|
+
radius: number;
|
|
13
|
+
constructor(params?: {
|
|
14
|
+
radius?: number;
|
|
15
|
+
offset?: THREE.Vector3;
|
|
16
|
+
});
|
|
17
|
+
calculateCollision(colliderMatrix: THREE.Matrix4, objectPosition: THREE.Vector3, objectRadius: number, target: THREE.Vector3): number;
|
|
18
|
+
}
|