From 2b38a90a58adccd3ab3b0af3735e70352d825193 Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Sun, 30 Aug 2020 15:00:41 +0200 Subject: [PATCH] Reactivate old IK code --- index.html | 2 +- js/animations.js | 4 +-- js/blockbench.js | 4 +-- js/interface/actions.js | 3 +- js/interface/panels.js | 6 ++-- js/outliner/group.js | 2 ++ js/preview/transformer.js | 64 +++++++++++++++++++++------------------ 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/index.html b/index.html index b096c9e..42f6f09 100644 --- a/index.html +++ b/index.html @@ -50,7 +50,7 @@ - + diff --git a/js/animations.js b/js/animations.js index 71e1323..742413a 100644 --- a/js/animations.js +++ b/js/animations.js @@ -2521,7 +2521,7 @@ BARS.defineActions(function() { Timeline.vue._data.focus_channel = val != 'all' ? val : null; } }) - /* + //Inverse Kinematics new Action('ik_enabled', { icon: 'check_box_outline_blank', @@ -2553,6 +2553,6 @@ BARS.defineActions(function() { onAfter: function() { Undo.finishEdit('move keyframes') } - })*/ + }) }) diff --git a/js/blockbench.js b/js/blockbench.js index 6263ace..ca50b3e 100644 --- a/js/blockbench.js +++ b/js/blockbench.js @@ -88,8 +88,8 @@ function updateNslideValues() { } } if (Modes.animate && Group.selected) { - //BarItems.slider_ik_chain_length.update(); - //BarItems.ik_enabled.setIcon(Group.selected.ik_enabled ? 'check_box' : 'check_box_outline_blank') + BarItems.slider_ik_chain_length.update(); + BarItems.ik_enabled.setIcon(Group.selected.ik_enabled ? 'check_box' : 'check_box_outline_blank') } } function setProjectResolution(width, height, modify_uv) { diff --git a/js/interface/actions.js b/js/interface/actions.js index 3cfb916..c74e08c 100644 --- a/js/interface/actions.js +++ b/js/interface/actions.js @@ -1493,7 +1493,6 @@ const BARS = { 'rescale_toggle' ] }) - /* Toolbars.bone_ik = new Toolbar({ id: 'bone_ik', children: [ @@ -1501,7 +1500,7 @@ const BARS = { 'slider_ik_chain_length' ], default_place: !Blockbench.isMobile - })*/ + }) Toolbars.palette = new Toolbar({ diff --git a/js/interface/panels.js b/js/interface/panels.js index 2150357..4972847 100644 --- a/js/interface/panels.js +++ b/js/interface/panels.js @@ -228,15 +228,15 @@ function setupPanels() { condition: {modes: ['animate']}, selection_only: true, toolbars: { - //bone_ik: Toolbars.bone_ik, + bone_ik: Toolbars.bone_ik, }, component: { template: `

${ tl('panel.element.origin') }

- +

${ tl('panel.bone.ik') }

+
` } diff --git a/js/outliner/group.js b/js/outliner/group.js index f4cd72d..db3ef8a 100644 --- a/js/outliner/group.js +++ b/js/outliner/group.js @@ -428,6 +428,8 @@ class Group extends OutlinerElement { }}); new Property(Group, 'vector', 'rotation'); 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() { diff --git a/js/preview/transformer.js b/js/preview/transformer.js index 7b6933c..defec29 100644 --- a/js/preview/transformer.js +++ b/js/preview/transformer.js @@ -1049,7 +1049,10 @@ var undo_keyframes = []; var animator = Animator.selected.getBoneAnimator(); if (animator && Toolbox.selected.id === 'move_tool' && Group.selected.ik_enabled && Group.selected.ik_chain_length) { - /* + + + + var bone = Group.selected; for (var i = Group.selected.ik_chain_length; i > 0; i--) { bone = bone.parent; @@ -1063,18 +1066,12 @@ } 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; - 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) { bones.push(bone); bone = bone.parent; @@ -1082,29 +1079,35 @@ } 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) => { - var copy_bone = new THREE.Bone(); - var startPoint = new FIK.V3(0,0,0).copy(bone.mesh.getWorldPosition(new THREE.Vector3())) + if (!bones[i+1]) return; - var bone = new FIK.Bone3D(startPoint, startPoint) - chain.addBone(bone) + let startPoint = new FIK.V3(0,0,0).copy(bone.mesh.getWorldPosition(new THREE.Vector3())) + 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) { - basebone = bone; + basebone = fik_bone; } }) - - //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() + let target = new FIK.V3() solver.add(chain, target, true); - Transformer.solver = solver - - /* + Transformer.solver = solver + + + /* var ik_solver = Transformer.ik_solver = {}; @@ -1385,16 +1388,16 @@ //scope.keyframes[0].select() - /* - var ik_solver = Transformer.ik_solver; + var solver = Transformer.solver; + console.log(solver) - ik_solver.target.position.copy(planeIntersect.point); + solver.targets[0].copy(planeIntersect.point); 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]; if (keyframe) { var bone = copy_bone.original; @@ -1408,7 +1411,10 @@ } }) - */ + + + + } else { scope.keyframes[0].offset(axis, difference);