three-stdlib 2.18.0 → 2.19.0
Sign up to get free protection for your applications and to get access to all the features.
- package/animation/CCDIKSolver.cjs.js +1 -1
- package/animation/CCDIKSolver.js +4 -2
- package/index.cjs.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/objects/Water2.cjs.js +1 -1
- package/objects/Water2.js +1 -1
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/defineProperty"),e=require("three");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@babel/runtime/helpers/defineProperty"),e=require("three");function i(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=i(t);class s extends e.Object3D{constructor(t,i=[],s=.25){super(),r.default(this,"_m",new e.Matrix4),r.default(this,"_v",new e.Vector3),this.root=t,this.iks=i,this.matrix.copy(t.matrixWorld),this.matrixAutoUpdate=!1,this.sphereGeometry=new e.SphereGeometry(s,16,8),this.targetSphereMaterial=new e.MeshBasicMaterial({color:new e.Color(16746632),depthTest:!1,depthWrite:!1,transparent:!0}),this.effectorSphereMaterial=new e.MeshBasicMaterial({color:new e.Color(8978312),depthTest:!1,depthWrite:!1,transparent:!0}),this.linkSphereMaterial=new e.MeshBasicMaterial({color:new e.Color(8947967),depthTest:!1,depthWrite:!1,transparent:!0}),this.lineMaterial=new e.LineBasicMaterial({color:new e.Color(16711680),depthTest:!1,depthWrite:!1,transparent:!0});const o=this;function n(t){return new e.Line(function(t){const i=new e.BufferGeometry,r=new Float32Array(3*(2+t.links.length));return i.setAttribute("position",new e.BufferAttribute(r,3)),i}(t),o.lineMaterial)}for(let t=0,r=i.length;t<r;t++){const r=i[t];this.add(new e.Mesh(o.sphereGeometry,o.targetSphereMaterial)),this.add(new e.Mesh(o.sphereGeometry,o.effectorSphereMaterial));for(let t=0,i=r.links.length;t<i;t++)this.add(new e.Mesh(o.sphereGeometry,o.linkSphereMaterial));this.add(n(r))}}_getPosition(t,e){return this._v.setFromMatrixPosition(t.matrixWorld).applyMatrix4(e)}_setPositionOfBoneToAttributeArray(t,e,i,r){const s=this._getPosition(i,r);t[3*e+0]=s.x,t[3*e+1]=s.y,t[3*e+2]=s.z}updateMatrixWorld(t){const e=this.root;if(this.visible){let t=0;const i=this.iks,r=e.skeleton.bones;this._m.copy(e.matrixWorld).invert();for(let e=0,s=i.length;e<s;e++){const s=i[e],o=r[s.target],n=r[s.effector],a=this.children[t++],h=this.children[t++];a.position.copy(this._getPosition(o,this._m)),h.position.copy(this._getPosition(n,this._m));for(let e=0,i=s.links.length;e<i;e++){const i=r[s.links[e].index];this.children[t++].position.copy(this._getPosition(i,this._m))}const l=this.children[t++],c=l.geometry.attributes.position.array;this._setPositionOfBoneToAttributeArray(c,0,o,this._m),this._setPositionOfBoneToAttributeArray(c,1,n,this._m);for(let t=0,e=s.links.length;t<e;t++){const e=r[s.links[t].index];this._setPositionOfBoneToAttributeArray(c,t+2,e,this._m)}l.geometry.attributes.position.needsUpdate=!0}}this.matrix.copy(e.matrixWorld),super.updateMatrixWorld(t)}}exports.CCDIKHelper=s,exports.CCDIKSolver=class{constructor(t,i){r.default(this,"q",new e.Quaternion),r.default(this,"targetPos",new e.Vector3),r.default(this,"targetVec",new e.Vector3),r.default(this,"effectorPos",new e.Vector3),r.default(this,"effectorVec",new e.Vector3),r.default(this,"linkPos",new e.Vector3),r.default(this,"invLinkQ",new e.Quaternion),r.default(this,"linkScale",new e.Vector3),r.default(this,"axis",new e.Vector3),r.default(this,"vector",new e.Vector3),this.mesh=t,this.iks=i;const s=this.mesh.skeleton.bones;for(let t=0,e=this.iks.length;t<e;t++){const e=this.iks[t],i=s[e.effector],r=e.links;let o,n;o=i;for(let t=0,e=r.length;t<e;t++)n=s[r[t].index],o.parent!==n&&console.warn(`THREE.CCDIKSolver: bone ${o.name} is not the child of bone ${n.name}`),o=n}}update(){const t=this.mesh.skeleton.bones,e=this.iks,i=Math;for(let r=0,s=e.length;r<s;r++){const s=e[r],o=t[s.effector],n=t[s.target];this.targetPos.setFromMatrixPosition(n.matrixWorld);const a=s.links,h=void 0!==s.iteration?s.iteration:1;for(let e=0;e<h;e++){let e=!1;for(let r=0,n=a.length;r<n;r++){const n=t[a[r].index];if(!1===a[r].enabled)break;const h=a[r].limitation,l=a[r].rotationMin,c=a[r].rotationMax;n.matrixWorld.decompose(this.linkPos,this.invLinkQ,this.linkScale),this.invLinkQ.invert(),this.effectorPos.setFromMatrixPosition(o.matrixWorld),this.effectorVec.subVectors(this.effectorPos,this.linkPos),this.effectorVec.applyQuaternion(this.invLinkQ),this.effectorVec.normalize(),this.targetVec.subVectors(this.targetPos,this.linkPos),this.targetVec.applyQuaternion(this.invLinkQ),this.targetVec.normalize();let f=this.targetVec.dot(this.effectorVec);if(f>1?f=1:f<-1&&(f=-1),f=i.acos(f),!(f<1e-5)){if(void 0!==s.minAngle&&f<s.minAngle&&(f=s.minAngle),void 0!==s.maxAngle&&f>s.maxAngle&&(f=s.maxAngle),this.axis.crossVectors(this.effectorVec,this.targetVec),this.axis.normalize(),this.q.setFromAxisAngle(this.axis,f),n.quaternion.multiply(this.q),void 0!==h){let t=n.quaternion.w;t>1&&(t=1);const e=i.sqrt(1-t*t);n.quaternion.set(h.x*e,h.y*e,h.z*e,t)}void 0!==l&&n.rotation.setFromVector3(this.vector.setFromEuler(n.rotation).max(l)),void 0!==c&&n.rotation.setFromVector3(this.vector.setFromEuler(n.rotation).min(c)),n.updateMatrixWorld(!0),e=!0}}if(!e)break}}return this}createHelper(){return new s(this.mesh,this.mesh.geometry.userData.MMD.iks)}};
|
package/animation/CCDIKSolver.js
CHANGED
@@ -2,7 +2,7 @@ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
2
|
import { Object3D, Matrix4, Vector3, SphereGeometry, MeshBasicMaterial, Color, LineBasicMaterial, Mesh, Line, Quaternion, BufferGeometry, BufferAttribute } from 'three';
|
3
3
|
|
4
4
|
class CCDIKHelper extends Object3D {
|
5
|
-
constructor(mesh, iks = []) {
|
5
|
+
constructor(mesh, iks = [], sphereSize = 0.25) {
|
6
6
|
super();
|
7
7
|
|
8
8
|
_defineProperty(this, "_m", new Matrix4());
|
@@ -13,7 +13,7 @@ class CCDIKHelper extends Object3D {
|
|
13
13
|
this.iks = iks;
|
14
14
|
this.matrix.copy(mesh.matrixWorld);
|
15
15
|
this.matrixAutoUpdate = false;
|
16
|
-
this.sphereGeometry = new SphereGeometry(
|
16
|
+
this.sphereGeometry = new SphereGeometry(sphereSize, 16, 8);
|
17
17
|
this.targetSphereMaterial = new MeshBasicMaterial({
|
18
18
|
color: new Color(0xff8888),
|
19
19
|
depthTest: false,
|
@@ -46,6 +46,8 @@ class CCDIKHelper extends Object3D {
|
|
46
46
|
return geometry;
|
47
47
|
}
|
48
48
|
|
49
|
+
const scope = this;
|
50
|
+
|
49
51
|
function createTargetMesh() {
|
50
52
|
return new Mesh(scope.sphereGeometry, scope.targetSphereMaterial);
|
51
53
|
}
|