Steady IK target point moving

IK translation strings
This commit is contained in:
JannisX11 2020-10-12 22:48:28 +02:00
parent c95f51e647
commit 3f04392021
4 changed files with 24 additions and 24 deletions

View File

@ -1529,6 +1529,7 @@ BARS.defineActions(function() {
},
change: function(modify) {
Group.selected.ik_chain_length = modify(Group.selected.ik_chain_length);
updateSelection()
},
onBefore: function() {
Undo.initEdit({keyframes: Timeline.selected})

View File

@ -912,6 +912,7 @@
if (Toolbox.selected.id == 'resize_tool') {
Transformer.rotation_ref = Group.selected.mesh;
} else if (Toolbox.selected.id == 'move_tool' && Group.selected.ik_enabled && Group.selected.ik_chain_length) {
if (Transformer.dragging && Transformer.ik_target) Transformer.position.copy(Transformer.ik_target);
delete Transformer.rotation_ref;
} else {
Transformer.rotation_ref = Group.selected.mesh.parent;
@ -1110,9 +1111,10 @@
}
})
let target = new FIK.V3()
//let target = new FIK.V3()
Transformer.ik_target = new THREE.Vector3().copy(Transformer.position);
solver.add(chain, target, true);
solver.add(chain, Transformer.ik_target , true);
Transformer.ik_solver = solver;
Transformer.ik_solver.meshChains[0].forEach(mesh => {
@ -1340,24 +1342,14 @@
if (Toolbox.selected.id === 'rotate_tool' && Math.abs(difference) > 120) {
difference = 0;
}
if (axis == 'x' && Toolbox.selected.id === 'move_tool') {
difference *= -1
}
if (Group.selected.ik_enabled) {
var solver = Transformer.ik_solver;
console.log(originalPoint)
point.copy(originalPoint)
point[axis] = planeIntersect.point[axis];
solver.targets[0].copy(point);
Transformer.ik_target[axis] += difference
main_preview.render()
solver.update();
console.log(solver)
Transformer.ik_solver.update();
Animator.preview()
Transformer.bones.forEach((bone, i) => {
var keyframe = scope.keyframes[i];
if (keyframe) {
@ -1365,8 +1357,8 @@
let euler = new THREE.Euler()
let q = new THREE.Quaternion()
let start = new THREE.Vector3().copy(solver.chains[0].bones[i].start)
let end = new THREE.Vector3().copy(solver.chains[0].bones[i].end)
let start = new THREE.Vector3().copy(Transformer.ik_solver.chains[0].bones[i].start)
let end = new THREE.Vector3().copy(Transformer.ik_solver.chains[0].bones[i].end)
Transformer.bones[i].bone.mesh.worldToLocal(start)
Transformer.bones[i].bone.mesh.worldToLocal(end)
let diff = new THREE.Vector3().copy(end).sub(start)
@ -1389,6 +1381,9 @@
} else {
if (axis == 'x' && Toolbox.selected.id === 'move_tool') {
difference *= -1
}
scope.keyframes[0].offset(axis, difference);
scope.keyframes[0].select()
}

View File

@ -998,7 +998,10 @@
"action.timeline_focus": "Filter Channels",
"action.timeline_focus.desc": "Select the animation channels to display in the timeline",
"action.timeline_focus.hide_empty": "Hide empty channels",
"action.ik_enabled": "Enable IK",
"action.ik_enabled.desc": "Enable Inverse Kinematics for this bone",
"action.slider_ik_chain_length": "IK Chain Length",
"action.slider_ik_chain_length.desc": "Upwards length of the IK bone chain",
"timeline.rotation": "Rotation",
"timeline.position": "Position",
@ -1173,6 +1176,7 @@
"panel.element.rotation": "Rotation",
"panel.bone": "Bone",
"panel.bone.ik": "Inverse Kinematics (Experimental)",
"uv_editor.title": "UV Editor",
"uv_editor.all_faces": "All",

10
lib/fik.min.js vendored
View File

@ -52,10 +52,10 @@ updateChainLength:function(){this.chainLength=0;for(var a=this.numBones;a--;)thi
d.end),c=a.getBaseboneConstraintType(),c){case 4:case 5:this.tmpMtx.createRotationMatrix(d.getDirectionUV()),d=a.getBaseboneConstraintUV().clone().applyM3(this.tmpMtx),a.setBaseboneRelativeConstraintUV(d),5===c&&a.setBaseboneRelativeReferenceConstraintUV(a.bones[0].joint.getHingeReferenceAxis().clone().applyM3(this.tmpMtx))}a.useEmbeddedTarget?a.solveForEmbeddedTarget():a.solveForTarget(b);if(this.isWithMesh)for(b=this.meshChains[e],d=0;d<a.numBones;d++)c=a.bones[d],b[d].position.copy(c.start),b[d].lookAt(c.end)}},
clear:function(){this.clearAllBoneMesh();var a;for(a=this.numChains;a--;)this.remove(a);this.chains=[];this.meshChains=[];this.targets=[]},add:function(a,b,c){this.chains.push(a);this.targets.push(b);this.numChains++;c&&this.addChainMeshs(a)},remove:function(a){this.chains[a].clear();this.chains.splice(a,1);this.meshChains.splice(a,1);this.targets.splice(a,1);this.numChains--},setFixedBaseMode:function(a){this.fixedBaseMode=a;a=this.numChains;for(var b;a--;)b=this.chains[a].getConnectedChainNumber(),
-1===b&&this.chains[a].setFixedBaseMode(this.fixedBaseMode)},getNumChains:function(){return this.numChains},getChain:function(a){return this.chains[a]},connectChain:function(a,b,c,d,e,g,f){if(!(b>this.numChains||c>this.chains[b].numBones)){a=a.clone();void 0!==f&&a.setColor(f);a.setBoneConnectionPoint("end"===d?21:20);a.setConnectedChainNumber(b);a.setConnectedBoneNumber(c);b="end"===d?this.chains[b].bones[c].end:this.chains[b].bones[c].start;a.setBaseLocation(b);a.setFixedBaseMode(!0);for(c=0;c<
a.numBones;c++)a.bones[c].start.add(b),a.bones[c].end.add(b);this.add(a,e,g)}},addChainMeshs:function(a,b){this.isWithMesh=!0;b=[];for(var c=a.bones.length,d=0;d<c;d++)b.push(this.addBoneMesh(a.bones[d],d-1,b,a));this.meshChains.push(b)},addBoneMesh:function(a,b,c,d){var e=a.length,g=a.color,f=new THREE.CylinderBufferGeometry(1,.5,e,4);f.applyMatrix((new THREE.Matrix4).makeRotationX(.5*-Math.PI));f.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,.5*e));var h=new THREE.MeshStandardMaterial({color:g,
wireframe:!1,shadowSide:!1}),l=new THREE.MeshBasicMaterial({wireframe:!0}),m=null;e=a.joint.type;switch(e){case 10:l.color.setHex(16737792);if(a.joint.rotor===Math.PI)break;a=new THREE.CylinderBufferGeometry(0,2,2,6,1,!0);a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*-Math.PI));a.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,1));m=new THREE.Mesh(a,l);break;case 12:g=a.joint.getHingeRotationAxis();var n=a.joint.min;a=a.joint.max;m=2;l.color.setHex(16776960);a=new THREE.CircleBufferGeometry(m,
12,n,-n+a);1===g.z&&a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*-Math.PI));1===g.y&&(a.applyMatrix((new THREE.Matrix4).makeRotationY(.5*-Math.PI)),a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*-Math.PI)));1===g.x&&a.applyMatrix((new THREE.Matrix4).makeRotationY(.5*Math.PI));m=new THREE.Mesh(a,l);break;case 11:g=a.joint.getHingeRotationAxis(),m=2,n=a.joint.min,a=a.joint.max,l.color.setHex(65535),a=new THREE.CircleBufferGeometry(m,12,n,-n+a),a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*
-Math.PI)),1===g.z&&(a.applyMatrix((new THREE.Matrix4).makeRotationY(.5*-Math.PI)),a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*Math.PI))),1===g.x&&a.applyMatrix((new THREE.Matrix4).makeRotationZ(.5*-Math.PI)),1===g.y&&(a.applyMatrix((new THREE.Matrix4).makeRotationX(.5*Math.PI)),a.applyMatrix((new THREE.Matrix4).makeRotationY(.5*Math.PI))),m=new THREE.Mesh(a,l)}g=new THREE.AxesHelper(1.5);f=new THREE.Mesh(f,h);f.add(g);this.scene.add(f);f.castShadow=!0;f.receiveShadow=!0;-1!==b?null!==m&&(12!==
a.numBones;c++)a.bones[c].start.add(b),a.bones[c].end.add(b);this.add(a,e,g)}},addChainMeshs:function(a,b){this.isWithMesh=!0;b=[];for(var c=a.bones.length,d=0;d<c;d++)b.push(this.addBoneMesh(a.bones[d],d-1,b,a));this.meshChains.push(b)},addBoneMesh:function(a,b,c,d){var e=a.length,g=a.color,f=new THREE.CylinderBufferGeometry(1,.5,e,4);f.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*-Math.PI));f.applyMatrix4((new THREE.Matrix4).makeTranslation(0,0,.5*e));var h=new THREE.MeshStandardMaterial({color:g,
wireframe:!1,shadowSide:!1}),l=new THREE.MeshBasicMaterial({wireframe:!0}),m=null;e=a.joint.type;switch(e){case 10:l.color.setHex(16737792);if(a.joint.rotor===Math.PI)break;a=new THREE.CylinderBufferGeometry(0,2,2,6,1,!0);a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*-Math.PI));a.applyMatrix4((new THREE.Matrix4).makeTranslation(0,0,1));m=new THREE.Mesh(a,l);break;case 12:g=a.joint.getHingeRotationAxis();var n=a.joint.min;a=a.joint.max;m=2;l.color.setHex(16776960);a=new THREE.CircleBufferGeometry(m,
12,n,-n+a);1===g.z&&a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*-Math.PI));1===g.y&&(a.applyMatrix4((new THREE.Matrix4).makeRotationY(.5*-Math.PI)),a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*-Math.PI)));1===g.x&&a.applyMatrix4((new THREE.Matrix4).makeRotationY(.5*Math.PI));m=new THREE.Mesh(a,l);break;case 11:g=a.joint.getHingeRotationAxis(),m=2,n=a.joint.min,a=a.joint.max,l.color.setHex(65535),a=new THREE.CircleBufferGeometry(m,12,n,-n+a),a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*
-Math.PI)),1===g.z&&(a.applyMatrix4((new THREE.Matrix4).makeRotationY(.5*-Math.PI)),a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*Math.PI))),1===g.x&&a.applyMatrix4((new THREE.Matrix4).makeRotationZ(.5*-Math.PI)),1===g.y&&(a.applyMatrix4((new THREE.Matrix4).makeRotationX(.5*Math.PI)),a.applyMatrix4((new THREE.Matrix4).makeRotationY(.5*Math.PI))),m=new THREE.Mesh(a,l)}g=new THREE.AxesHelper(1.5);f=new THREE.Mesh(f,h);f.add(g);this.scene.add(f);f.castShadow=!0;f.receiveShadow=!0;-1!==b?null!==m&&(12!==
e?(m.position.z=d.bones[b].length,c[b].add(m)):f.add(m)):null!==m&&f.add(m);return f},clearAllBoneMesh:function(){if(this.isWithMesh){var a,b;for(a=this.meshChains.length;a--;){for(b=this.meshChains[a].length;b--;){var c=this.meshChains[a][b];this.scene.remove(c);c.geometry.dispose();c.material.dispose()}this.meshChains[a]=[]}this.meshChains=[]}}});Object.assign(w.prototype,{isJoint2D:!0,clone:function(){var a=new w;a.coordinateSystem=this.coordinateSystem;a.max=this.max;a.min=this.min;return a},
validateAngle:function(a){a=0>a?0:a;return 180<a?180:a},set:function(a){this.max=a.max;this.min=a.min;this.coordinateSystem=a.coordinateSystem},setClockwiseConstraintDegs:function(a){this.min=-(this.validateAngle(a)*n)},setAnticlockwiseConstraintDegs:function(a){this.max=this.validateAngle(a)*n},setConstraintCoordinateSystem:function(a){this.coordinateSystem=a},getConstraintCoordinateSystem:function(){return this.coordinateSystem}});Object.assign(x.prototype,{isBone2D:!0,clone:function(){var a=new x(this.start,
this.end);a.length=this.length;a.globalConstraintUV=this.globalConstraintUV;a.boneConnectionPoint=this.boneConnectionPoint;a.joint=this.joint.clone();a.color=this.color;a.name=this.name;return a},setName:function(a){this.name=a},setColor:function(a){this.color=a},setBoneConnectionPoint:function(a){this.boneConnectionPoint=a},setStartLocation:function(a){this.start.copy(a)},setEndLocation:function(a){this.end.copy(a)},setLength:function(a){0<a&&(this.length=a)},setGlobalConstraintUV:function(a){this.globalConstraintUV=
@ -76,7 +76,7 @@ updateChainLength:function(){this.chainLength=0;for(var a=this.numBones;a--;)thi
a.setBaseLocation(20===a.getBoneConnectionPoint()?e.start:e.end),e=e.getDirectionUV(),7===c?a.setBaseboneConstraintUV(e):8===c&&(c=F.getSignedAngle(e),c=a.getBaseboneConstraintUV().clone().rotate(c),a.setBaseboneRelativeConstraintUV(c))),a.useEmbeddedTarget?a.solveForEmbeddedTarget():a.solveForTarget(b),this.isWithMesh)for(b=this.meshChains[f],e=0;e<a.numBones;e++)c=a.bones[e],b[e].position.set(c.start.x,c.start.y,0),b[e].lookAt(d.set(c.end.x,c.end.y,0))},setFixedBaseMode:function(a){this.fixedBaseMode=
a;a=this.numChains;for(var b;a--;)b=this.chains[a].getConnectedChainNumber(),-1===b&&this.chains[a].setFixedBaseMode(this.fixedBaseMode)},clear:function(){this.clearAllBoneMesh();var a;for(a=this.numChains;a--;)this.remove(a);this.chains=[];this.meshChains=[];this.targets=[]},add:function(a,b,c){this.chains.push(a);this.targets.push(b);this.numChains++;c&&this.addChainMeshs(a)},remove:function(a){this.chains[a].clear();this.chains.splice(a,1);this.meshChains.splice(a,1);this.targets.splice(a,1);this.numChains--},
getNumChains:function(){return this.numChains},getChain:function(a){return this.chains[a]},connectChain:function(a,b,c,d,e,f,h){d=d||"end";if(b>this.numChains)p.error("Chain not existe !");else if(c>this.chains[b].numBones)p.error("Bone not existe !");else{a=a.clone();a.setBoneConnectionPoint("end"===d?21:20);a.setConnectedChainNumber(b);a.setConnectedBoneNumber(c);b="end"===d?this.chains[b].bones[c].end:this.chains[b].bones[c].start;a.setBaseLocation(b);a.setFixedBaseMode(!0);for(c=0;c<a.numBones;c++)a.bones[c].start.add(b),
a.bones[c].end.add(b);this.add(a,e,f)}},addChainMeshs:function(a,b){this.isWithMesh=!0;b=[];for(var c=a.bones.length,d=0;d<c;d++)b.push(this.addBoneMesh(a.bones[d]));this.meshChains.push(b)},addBoneMesh:function(a){var b=a.length,c=a.color;a=new THREE.CylinderBufferGeometry(1,.5,b,4);a.applyMatrix((new THREE.Matrix4).makeRotationX(-m.pi90));a.applyMatrix((new THREE.Matrix4).makeTranslation(0,0,.5*b));b=new THREE.MeshStandardMaterial({color:c,wireframe:!1,shadowSide:!1});new THREE.MeshBasicMaterial({wireframe:!0});
a.bones[c].end.add(b);this.add(a,e,f)}},addChainMeshs:function(a,b){this.isWithMesh=!0;b=[];for(var c=a.bones.length,d=0;d<c;d++)b.push(this.addBoneMesh(a.bones[d]));this.meshChains.push(b)},addBoneMesh:function(a){var b=a.length,c=a.color;a=new THREE.CylinderBufferGeometry(1,.5,b,4);a.applyMatrix4((new THREE.Matrix4).makeRotationX(-m.pi90));a.applyMatrix4((new THREE.Matrix4).makeTranslation(0,0,.5*b));b=new THREE.MeshStandardMaterial({color:c,wireframe:!1,shadowSide:!1});new THREE.MeshBasicMaterial({wireframe:!0});
b=new THREE.Mesh(a,b);b.castShadow=!0;b.receiveShadow=!0;this.scene.add(b);return b},clearAllBoneMesh:function(){if(this.isWithMesh){var a,b;for(a=this.meshChains.length;a--;){for(b=this.meshChains[a].length;b--;){var c=this.meshChains[a][b];this.scene.remove(c);c.geometry.dispose();c.material.dispose()}this.meshChains[a]=[]}this.meshChains=[]}}});Object.assign(D.prototype,{isIKSolver:!0});Object.assign(E.prototype,{isIKSolver:!0});h._Math=m;h.V2=l;h.V3=f;h.M3=y;h.Q=u;h.Joint3D=v;h.Bone3D=r;h.Chain3D=
z;h.Structure3D=B;h.Joint2D=w;h.Bone2D=x;h.Chain2D=A;h.Structure2D=C;h.IKSolver=D;h.HISolver=E;h.REVISION="1.3.3";h.PRECISION=.001;h.PRECISION_DEG=.01;h.MAX_VALUE=Infinity;h.PI=q;h.TORAD=n;h.TODEG=G;h.NONE=1;h.GLOBAL_ROTOR=2;h.GLOBAL_HINGE=3;h.LOCAL_ROTOR=4;h.LOCAL_HINGE=5;h.GLOBAL_ABSOLUTE=6;h.LOCAL_RELATIVE=7;h.LOCAL_ABSOLUTE=8;h.J_BALL=10;h.J_LOCAL=11;h.J_GLOBAL=12;h.START=20;h.END=21;h.X_AXE=H;h.Y_AXE=I;h.Z_AXE=J;h.X_NEG=K;h.Y_NEG=L;h.Z_NEG=M;h.UP=F;h.DOWN=N;h.LEFT=O;h.RIGHT=P;Object.defineProperty(h,
"__esModule",{value:!0})});