Reactivate old IK code

This commit is contained in:
JannisX11 2020-08-30 15:00:41 +02:00
parent 5cec293c90
commit 2b38a90a58
7 changed files with 46 additions and 39 deletions

View File

@ -50,7 +50,7 @@
<script src="lib/three_custom.js"></script> <script src="lib/three_custom.js"></script>
<script src="lib/GLTFExporter.js"></script> <script src="lib/GLTFExporter.js"></script>
<script src="lib/CanvasFrame.js"></script> <script src="lib/CanvasFrame.js"></script>
<!--script src="lib/fik.min.js"></script--> <script src="lib/fik.min.js"></script>
<script src="lib/molang.js"></script> <script src="lib/molang.js"></script>
<script src="js/preview/OrbitControls.js"></script> <script src="js/preview/OrbitControls.js"></script>
<script src="js/outliner/tree.vue.js"></script> <script src="js/outliner/tree.vue.js"></script>

View File

@ -2521,7 +2521,7 @@ BARS.defineActions(function() {
Timeline.vue._data.focus_channel = val != 'all' ? val : null; Timeline.vue._data.focus_channel = val != 'all' ? val : null;
} }
}) })
/*
//Inverse Kinematics //Inverse Kinematics
new Action('ik_enabled', { new Action('ik_enabled', {
icon: 'check_box_outline_blank', icon: 'check_box_outline_blank',
@ -2553,6 +2553,6 @@ BARS.defineActions(function() {
onAfter: function() { onAfter: function() {
Undo.finishEdit('move keyframes') Undo.finishEdit('move keyframes')
} }
})*/ })
}) })

View File

@ -88,8 +88,8 @@ function updateNslideValues() {
} }
} }
if (Modes.animate && Group.selected) { if (Modes.animate && Group.selected) {
//BarItems.slider_ik_chain_length.update(); BarItems.slider_ik_chain_length.update();
//BarItems.ik_enabled.setIcon(Group.selected.ik_enabled ? 'check_box' : 'check_box_outline_blank') BarItems.ik_enabled.setIcon(Group.selected.ik_enabled ? 'check_box' : 'check_box_outline_blank')
} }
} }
function setProjectResolution(width, height, modify_uv) { function setProjectResolution(width, height, modify_uv) {

View File

@ -1493,7 +1493,6 @@ const BARS = {
'rescale_toggle' 'rescale_toggle'
] ]
}) })
/*
Toolbars.bone_ik = new Toolbar({ Toolbars.bone_ik = new Toolbar({
id: 'bone_ik', id: 'bone_ik',
children: [ children: [
@ -1501,7 +1500,7 @@ const BARS = {
'slider_ik_chain_length' 'slider_ik_chain_length'
], ],
default_place: !Blockbench.isMobile default_place: !Blockbench.isMobile
})*/ })
Toolbars.palette = new Toolbar({ Toolbars.palette = new Toolbar({

View File

@ -228,15 +228,15 @@ function setupPanels() {
condition: {modes: ['animate']}, condition: {modes: ['animate']},
selection_only: true, selection_only: true,
toolbars: { toolbars: {
//bone_ik: Toolbars.bone_ik, bone_ik: Toolbars.bone_ik,
}, },
component: { component: {
template: ` template: `
<div> <div>
<p>${ tl('panel.element.origin') }</p> <p>${ tl('panel.element.origin') }</p>
<div class="toolbar_wrapper bone_origin"></div> <div class="toolbar_wrapper bone_origin"></div>
<!--p>${ tl('panel.bone.ik') }</p> <p>${ tl('panel.bone.ik') }</p>
<div class="toolbar_wrapper bone_ik"></div--> <div class="toolbar_wrapper bone_ik"></div>
</div> </div>
` `
} }

View File

@ -428,6 +428,8 @@ class Group extends OutlinerElement {
}}); }});
new Property(Group, 'vector', 'rotation'); new Property(Group, 'vector', 'rotation');
new Property(Group, 'array', 'cem_animations', {condition: () => Format.id == 'optifine_entity'}); new Property(Group, 'array', 'cem_animations', {condition: () => Format.id == 'optifine_entity'});
new Property(Group, 'boolean', 'ik_enabled', {condition: () => Format.animation_mode});
new Property(Group, 'number', 'ik_chain_length', {condition: () => Format.animation_mode});
function getCurrentGroup() { function getCurrentGroup() {

View File

@ -1049,7 +1049,10 @@
var undo_keyframes = []; var undo_keyframes = [];
var animator = Animator.selected.getBoneAnimator(); var animator = Animator.selected.getBoneAnimator();
if (animator && Toolbox.selected.id === 'move_tool' && Group.selected.ik_enabled && Group.selected.ik_chain_length) { if (animator && Toolbox.selected.id === 'move_tool' && Group.selected.ik_enabled && Group.selected.ik_chain_length) {
/*
var bone = Group.selected; var bone = Group.selected;
for (var i = Group.selected.ik_chain_length; i > 0; i--) { for (var i = Group.selected.ik_chain_length; i > 0; i--) {
bone = bone.parent; bone = bone.parent;
@ -1063,18 +1066,12 @@
} }
Undo.initEdit({keyframes: undo_keyframes}) Undo.initEdit({keyframes: undo_keyframes})
var solver = new FIK.Structure3D(scene);
var chain = new FIK.Chain3D();
var start = new FIK.V3(0, 0, 0);
var endLoc = new FIK.V3(0, 2, 0);
var basebone;
var bones = []; let basebone;
let bones = [];
var bone = Group.selected; var bone = Group.selected;
for (var i = Group.selected.ik_chain_length; i >= 0; i--) { for (let i = Group.selected.ik_chain_length; i >= 0; i--) {
if (bone instanceof Group) { if (bone instanceof Group) {
bones.push(bone); bones.push(bone);
bone = bone.parent; bone = bone.parent;
@ -1082,29 +1079,35 @@
} }
bones.reverse(); bones.reverse();
var parent_bone; console.log(bones)
let solver = new FIK.Structure3D(scene);
let chain = new FIK.Chain3D();
let parent_bone;
bones.forEach((bone, i) => { bones.forEach((bone, i) => {
var copy_bone = new THREE.Bone(); if (!bones[i+1]) return;
var startPoint = new FIK.V3(0,0,0).copy(bone.mesh.getWorldPosition(new THREE.Vector3()))
var bone = new FIK.Bone3D(startPoint, startPoint) let startPoint = new FIK.V3(0,0,0).copy(bone.mesh.getWorldPosition(new THREE.Vector3()))
chain.addBone(bone) let endPoint = new FIK.V3(0,0,0).copy(bones[i+1].mesh.getWorldPosition(new THREE.Vector3()))
console.log(startPoint, endPoint)
let fik_bone = new FIK.Bone3D(startPoint, endPoint)
chain.addBone(fik_bone)
if (!basebone) { if (!basebone) {
basebone = bone; basebone = fik_bone;
} }
}) })
let target = new FIK.V3()
//chain.addBone(new FIK.Bone3D(new FIK.V3(1, 2, 0), new FIK.V3(0, 6, 0), undefined, 1, 0x00FF00));
//chain.addBone(new FIK.Bone3D(new FIK.V3(0, 6, 0), new FIK.V3(0, 9, 0), undefined, 1, 0x0000FF));
var target = new FIK.V3()
solver.add(chain, target, true); solver.add(chain, target, true);
Transformer.solver = solver Transformer.solver = solver
/*
/*
var ik_solver = Transformer.ik_solver = {}; var ik_solver = Transformer.ik_solver = {};
@ -1385,16 +1388,16 @@
//scope.keyframes[0].select() //scope.keyframes[0].select()
/* var solver = Transformer.solver;
var ik_solver = Transformer.ik_solver; console.log(solver)
ik_solver.target.position.copy(planeIntersect.point); solver.targets[0].copy(planeIntersect.point);
main_preview.render() main_preview.render()
ik_solver.ik.solve(); solver.update();
ik_solver.copy_bones.forEach((copy_bone, i) => { [].forEach((copy_bone, i) => {
var keyframe = scope.keyframes[i]; var keyframe = scope.keyframes[i];
if (keyframe) { if (keyframe) {
var bone = copy_bone.original; var bone = copy_bone.original;
@ -1408,7 +1411,10 @@
} }
}) })
*/
} else { } else {
scope.keyframes[0].offset(axis, difference); scope.keyframes[0].offset(axis, difference);