Changed a few things in the IK demo to make it work on Linux.

Renamed the exported variables in the Look At IK to better follow Godot's API.
Removed all of the commented out constraint code for the FABRIK IK.
This commit is contained in:
TwistedTwigleg
2018-04-23 11:09:06 -04:00
parent 85c72987fc
commit 01abbff26d
11 changed files with 62 additions and 170 deletions

BIN
3d/ik/Gun_Emission.material Normal file

Binary file not shown.

View File

@@ -39,13 +39,6 @@ export (bool) var reset_iterations_on_update = false
export (bool) var use_middle_joint_target = false
var middle_joint_target = null
# NOT WORKING.
# A boolean to track whether or not we want to constrain the bones in the bone chain.
#export (bool) var constrained = false
# A array of strings contraining the bone constraints for each bone (assuming the order is the same
# as bones_in_chain). (ORDER: Left,Right,Up,Down)
#export (PoolStringArray) var bone_constraints
# Have we called _set_skeleton_path or not already. Due to some issues using exported NodePaths,
# we need to ignore the first _set_skeleton_path call.
var first_call = true
@@ -222,25 +215,6 @@ func _set_bone_chain_lengths(new_value):
total_length = null
# NOT USED -- part of the (not working) constraint system
"""
func get_bone_constraints(index):
# NOTE: assumed angle constraint order:
# Left angle in degrees, right angle in degrees, up angle in degress, down angle in degrees.
if index <= bones_in_chain.size()-1:
var index_str = bone_constraints[index]
var floats = index_str.split_floats(",", false)
if (floats.size() >= 4):
return floats
else:
print (self.name, " - IK_FABRIK: Not all constraints are present for bone number ", index, " found!")
return null
print (self.name, " - IK_FABRIK: No constraints for bone number ", index, " found!")
return null
"""
# Various upate methods
# ---------------------
func _process(delta):
@@ -396,8 +370,6 @@ func solve_chain():
func chain_backward():
# Backward reaching pass
#var dir = -target.global_transform.basis.z.normalized()
# Get the direction of the final bone by using the next to last bone if there is more than 2 bones.
# If there are only 2 bones, we use the target's forward Z vector instead (not ideal, but it works fairly well)
var dir
@@ -437,90 +409,10 @@ func chain_forward():
# Set the new joint position
var new_pos = (1 - l) * bone_nodes[i].global_transform.origin + l * bone_nodes[i+1].global_transform.origin
# Apply constraints (if we have them)
# NOTE: this does not work. It is left in as an example to help others if they decide to add constraints
"""
if (constrained == true):
var cf = bone_nodes[i].global_transform
cf = cf.looking_at(bone_nodes[i+1].global_transform.origin, Vector3(0, 1, 0))
var line = (new_pos - bone_nodes[i+1].global_transform.origin).normalized() * bones_in_chain_lengths[i]
new_pos += chain_constrain(new_pos, line, cf, i+1)
"""
# Apply the new joint position, (potentially with constraints), to the bone node
bone_nodes[i+1].global_transform.origin = new_pos
i += 1
# NOT USED -- part of the (not working) constraint system
"""
func chain_constrain(calc, line, cf, bone):
var scalar = calc.dot(line) / line.length()
var proj = scalar * line.normalized()
# NOTE: Something in the calculation for proj may be wrong.
# get axis that is closest
# NOTE: Not sure if we need to do a calculation or not. For now, we are just going to use Basis
var tmp = cf.looking_at(cf.origin - Vector3(0, 1, 0), Vector3(1, 0, 0))
var upvec = cf.basis.x
tmp = cf.looking_at(cf.origin - Vector3(1, 0, 0), Vector3(0, 1, 0))
var rightvec = cf.basis.z
# Get the vector from the projection to the calculated vector
var adjust = calc - proj
if scalar > 0:
# If we are below the cone, flip the projection vector
proj = -proj
pass
# Get the 2D components
var xaspect = adjust.dot(rightvec)
var yaspect = adjust.dot(upvec)
# Get the cross section of the cone
var constraint_angles = get_bone_constraints(bone)
var left = -(proj.length() * tan(deg2rad(constraint_angles[0])) )
var right = (proj.length() * tan(deg2rad(constraint_angles[1])) )
var up = (proj.length() * tan(deg2rad(constraint_angles[2])) )
var down = -(proj.length() * tan(deg2rad(constraint_angles[3])) )
# Find the quadrant
var xbound = xaspect >= 0 and right or left
var ybound = yaspect >= 0 and up or down
if xbound == true:
xbound = 1
else:
xbound = 0
if ybound == true:
ybound = 1
else:
ybound = 0
var f = calc
# Check if in 2D point lies in the ellipse
var ellipse = pow(xaspect, 2)/pow(xbound, 2) + pow(yaspect, 2)/pow(ybound, 2)
var inbounds = ellipse <= 1 and scalar >= 0
if not inbounds:
# Get the angle of our out of ellipse point
var a = atan2(yaspect, xaspect)
# Find the nearest point
var x = xbound * cos(a)
var y = ybound * sin(a)
# Convert back to 3D
#f = (proj + rightvec * x + upvec * y ).normalized() * calc.length()
f = (proj + rightvec * x + upvec * y ).normalized() * bones_in_chain_lengths[bone]
return f
"""
func chain_apply_rotation():

View File

@@ -2,14 +2,14 @@
importer="texture"
type="StreamTexture"
path="res://.import/ik_fabrik.png-c3d637ec075c87710a4a8abbfbd526e1.stex"
path="res://.import/ik_fabrik.png-c99ad3d889def35eb72d4107e9571c00.stex"
[deps]
source_file="res://addons/SADE/ik_fabrik.png"
source_file="res://addons/sade/ik_fabrik.png"
source_md5="2909090602f64d38ce0bb7314ec7b39d"
dest_files=[ "res://.import/ik_fabrik.png-c3d637ec075c87710a4a8abbfbd526e1.stex" ]
dest_files=[ "res://.import/ik_fabrik.png-c99ad3d889def35eb72d4107e9571c00.stex" ]
dest_md5="80bbb72f55f6ea1f119b08dc61b9526e"
[params]

View File

@@ -5,9 +5,9 @@ export (NodePath) var skeleton_path setget _set_skeleton_path
export (String) var bone_name = ""
export (int, "_process", "_physics_process", "_notification", "none") var update_mode = 0 setget _set_update
export (int, "X-up", "Y-up", "Z-up") var look_at_axis = 1
export (bool) var use_our_rot_x = false
export (bool) var use_our_rot_y = false
export (bool) var use_our_rot_z = false
export (bool) var use_our_rotation_x = false
export (bool) var use_our_rotation_y = false
export (bool) var use_our_rotation_z = false
export (bool) var use_negative_our_rot = false
export (Vector3) var additional_rotation = Vector3()
export (bool) var debug_messages = false
@@ -174,11 +174,11 @@ func update_skeleton():
self_euler = -self_euler
# Apply our rotation euler, if wanted/required
if use_our_rot_x == true:
if use_our_rotation_x == true:
rest_euler.x = self_euler.x
if use_our_rot_y == true:
if use_our_rotation_y == true:
rest_euler.y = self_euler.y
if use_our_rot_z == true:
if use_our_rotation_z == true:
rest_euler.z = self_euler.z
# Rotate the bone by the (potentially) changed euler angle(s)

View File

@@ -2,14 +2,14 @@
importer="texture"
type="StreamTexture"
path="res://.import/ik_look_at.png-ec8164b5f09a539e05ec8153e50e1d99.stex"
path="res://.import/ik_look_at.png-9127e12c7a59faf98e66142c84e0d5b7.stex"
[deps]
source_file="res://addons/SADE/ik_look_at.png"
source_file="res://addons/sade/ik_look_at.png"
source_md5="49fed7fb3ba1856215d1f334ed8bc583"
dest_files=[ "res://.import/ik_look_at.png-ec8164b5f09a539e05ec8153e50e1d99.stex" ]
dest_files=[ "res://.import/ik_look_at.png-9127e12c7a59faf98e66142c84e0d5b7.stex" ]
dest_md5="690d9e1323d33b31eefd4014776d78d4"
[params]

View File

@@ -3,5 +3,5 @@
name="S.A.D.E (Skeleton additions and extensions)"
description="S.A.D.E is A bunch of helpful nodes designed to make using skeletons in Godot powerful and easy."
author="TwistedTwigleg"
version="0.1.0"
version="0.1.1"
script="plugin_main.gd"

View File

@@ -2,12 +2,12 @@
[ext_resource path="res://addons/sade/editor_gizmo_texture.png" type="Texture" id=1]
[ext_resource path="res://godot_battle_bot.dae" type="PackedScene" id=2]
[ext_resource path="res://Target_From_MousePos.gd" type="Script" id=3]
[ext_resource path="res://target_from_mousepos.gd" type="Script" id=3]
[ext_resource path="res://addons/sade/ik_look_at.gd" type="Script" id=4]
[ext_resource path="res://addons/sade/ik_look_at.png" type="Texture" id=5]
[ext_resource path="res://addons/SADE/IK_FABRIK.gd" type="Script" id=6]
[ext_resource path="res://addons/SADE/IK_FABRIK.png" type="Texture" id=7]
[ext_resource path="res://Button_Change_Scene.gd" type="Script" id=8]
[ext_resource path="res://addons/sade/ik_fabrik.gd" type="Script" id=6]
[ext_resource path="res://addons/sade/ik_fabrik.png" type="Texture" id=7]
[ext_resource path="res://button_change_scene.gd" type="Script" id=8]
[sub_resource type="PlaneMesh" id=1]
@@ -314,9 +314,9 @@ skeleton_path = NodePath("../../../BattleBot/Armature/Skeleton")
bone_name = "Head"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = false
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = false
additional_rotation = Vector3( 90, 0, 0 )
debug_messages = false
@@ -353,9 +353,9 @@ skeleton_path = NodePath("../../../../../BattleBot/Armature/Skeleton")
bone_name = "Left_Hand"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = false
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = false
additional_rotation = Vector3( 0, 0, 90 )
debug_messages = false
@@ -366,11 +366,11 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 7.16849, 0, -5.31922 )
[node name="Left_UpperArm" type="Spatial" parent="Camera/targets/IK_FABRIK_Left_Arm" index="2"]
transform = Transform( -0.66477, 0.0771345, -0.743055, -2.23517e-08, 0.994655, 0.103252, 0.747048, 0.0686391, -0.661217, 1.53444, 0.300478, -3.63533 )
transform = Transform( -0.664762, 0.077136, -0.743062, -2.23517e-08, 0.994655, 0.103253, 0.747055, 0.068639, -0.661209, 1.53443, 0.300478, -3.63529 )
[node name="Left_LowerArm" type="Spatial" parent="Camera/targets/IK_FABRIK_Left_Arm" index="3"]
transform = Transform( -0.773624, -0.0228999, 0.633231, 2.98023e-08, 0.999347, 0.03614, -0.633645, 0.0279588, -0.773119, 2.94998, 0.10378, -2.37569 )
transform = Transform( -0.773622, -0.022882, 0.633234, 1.49012e-08, 0.999348, 0.0361116, -0.633648, 0.0279367, -0.773117, 2.94998, 0.103698, -2.37567 )
[node name="IK_FABRIK_Right_Arm" type="Spatial" parent="Camera/targets" index="2"]
@@ -404,9 +404,9 @@ skeleton_path = NodePath("../../../../../BattleBot/Armature/Skeleton")
bone_name = "Right_Hand"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = false
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = false
additional_rotation = Vector3( 0, 0, 90 )
debug_messages = false
@@ -417,15 +417,15 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -6.34515, 0, -3.7843 )
[node name="Right_UpperArm" type="Spatial" parent="Camera/targets/IK_FABRIK_Right_Arm" index="2"]
transform = Transform( -0.694982, -0.0753926, 0.715064, -7.45058e-09, 0.994488, 0.104854, -0.719028, 0.0728714, -0.691151, -1.53339, 0.300478, -3.63533 )
transform = Transform( -0.694976, -0.0753919, 0.715069, 5.96046e-08, 0.994488, 0.104852, -0.719033, 0.0728695, -0.691145, -1.5334, 0.300478, -3.63531 )
[node name="Right_LowerArm" type="Spatial" parent="Camera/targets/IK_FABRIK_Right_Arm" index="3"]
transform = Transform( -0.792024, 0.0165705, -0.610266, 0, 0.999631, 0.0271429, 0.61049, 0.0214978, -0.791732, -2.89561, 0.100753, -2.31866 )
transform = Transform( -0.792023, 0.0165762, -0.610266, 0, 0.999631, 0.0271522, 0.610491, 0.0215051, -0.791731, -2.89562, 0.100769, -2.31865 )
[node name="Right_Hand" type="Spatial" parent="Camera/targets/IK_FABRIK_Right_Arm" index="4"]
transform = Transform( -0.678335, 0.00698586, -0.734719, -1.86265e-09, 0.999955, 0.00950778, 0.734753, 0.00644946, -0.678304, -1.07914, 0.0200729, 0.0379109 )
transform = Transform( -0.678313, 0.00695222, -0.73474, 9.31323e-10, 0.999955, 0.00946173, 0.734773, 0.00641802, -0.678282, -1.0791, 0.0200329, 0.0379918 )
[node name="MeshInstance" type="MeshInstance" parent="Camera/targets" index="3"]

View File

@@ -1,12 +1,12 @@
[gd_scene load_steps=24 format=2]
[ext_resource path="res://addons/sade/editor_gizmo_texture.png" type="Texture" id=1]
[ext_resource path="res://Button_Change_Scene.gd" type="Script" id=2]
[ext_resource path="res://button_change_scene.gd" type="Script" id=2]
[ext_resource path="res://example_player.gd" type="Script" id=3]
[ext_resource path="res://addons/sade/ik_look_at.gd" type="Script" id=4]
[ext_resource path="res://addons/sade/ik_look_at.png" type="Texture" id=5]
[ext_resource path="res://addons/SADE/IK_FABRIK.gd" type="Script" id=6]
[ext_resource path="res://addons/SADE/IK_FABRIK.png" type="Texture" id=7]
[ext_resource path="res://addons/sade/ik_fabrik.gd" type="Script" id=6]
[ext_resource path="res://addons/sade/ik_fabrik.png" type="Texture" id=7]
[ext_resource path="res://weapon_pistol.dae" type="PackedScene" id=8]
[ext_resource path="res://godot_battle_bot.dae" type="PackedScene" id=9]
@@ -429,7 +429,7 @@ tracks/2/keys = {
"values": [ 80.0 ]
}
[node name="LookAt_IK" type="Spatial" index="0"]
[node name="LookAt_IK" type="Spatial"]
[node name="Level" type="Spatial" parent="." index="0"]
@@ -1382,7 +1382,7 @@ curve = SubResource( 11 )
[node name="PathFollow" type="PathFollow" parent="KinematicBody/CameraHolder/Lean_Path" index="0"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0412404, 0.205172, 0 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0412405, 0.205172, 0 )
offset = 2.71865
h_offset = 0.0
v_offset = 0.0
@@ -1402,9 +1402,9 @@ skeleton_path = NodePath("../../../../BattleBot/Armature/Skeleton")
bone_name = "Chest"
update_mode = 0
look_at_axis = 2
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = false
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = false
additional_rotation = Vector3( -10, 0, 0 )
debug_messages = false
@@ -1463,9 +1463,9 @@ skeleton_path = NodePath("../../../../../../../../BattleBot/Armature/Skeleton")
bone_name = "Left_Hand"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = true
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = true
additional_rotation = Vector3( 0, 0, 90 )
debug_messages = false
@@ -1517,9 +1517,9 @@ skeleton_path = NodePath("../../../../../../../../BattleBot/Armature/Skeleton")
bone_name = "Right_Hand"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = true
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = true
additional_rotation = Vector3( 0, 0, 90 )
debug_messages = false
@@ -1557,9 +1557,9 @@ skeleton_path = NodePath("../../../../BattleBot/Armature/Skeleton")
bone_name = "Head"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = false
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = false
additional_rotation = Vector3( 0, 0, 0 )
debug_messages = false

View File

@@ -10,7 +10,7 @@ source_file="res://godot_battle_bot.dae"
source_md5="6921b921d8668c6bb39ab8c5745b70fa"
dest_files=[ "res://.import/godot_battle_bot.dae-eca9fb346b160636fd03ddf258af136e.scn" ]
dest_md5="5826d8872384107dcbcf8b6a04aeb7fa"
dest_md5="d92ca022336b0f6d352865a05d12af5a"
[params]

View File

@@ -2,10 +2,10 @@
[ext_resource path="res://addons/sade/editor_gizmo_texture.png" type="Texture" id=1]
[ext_resource path="res://godot_battle_bot.dae" type="PackedScene" id=2]
[ext_resource path="res://Target_From_MousePos.gd" type="Script" id=3]
[ext_resource path="res://target_from_mousepos.gd" type="Script" id=3]
[ext_resource path="res://addons/sade/ik_look_at.gd" type="Script" id=4]
[ext_resource path="res://addons/sade/ik_look_at.png" type="Texture" id=5]
[ext_resource path="res://Button_Change_Scene.gd" type="Script" id=6]
[ext_resource path="res://button_change_scene.gd" type="Script" id=6]
[sub_resource type="PlaneMesh" id=1]
@@ -166,7 +166,7 @@ adjustment_contrast = 1.0
adjustment_saturation = 1.0
_sections_unfolded = [ "Glow", "Glow/levels" ]
[node name="LookAt_IK" type="Spatial"]
[node name="LookAt_IK" type="Spatial" index="0"]
[node name="Floor_plane" type="MeshInstance" parent="." index="0"]
@@ -251,9 +251,9 @@ skeleton_path = NodePath("../../../BattleBot/Armature/Skeleton")
bone_name = "Head"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = false
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = false
additional_rotation = Vector3( 90, 0, 0 )
debug_messages = false
@@ -269,9 +269,9 @@ skeleton_path = NodePath("../../../BattleBot/Armature/Skeleton")
bone_name = "Left_UpperArm"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = false
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = false
additional_rotation = Vector3( 0, 0, 0 )
debug_messages = false
@@ -287,9 +287,9 @@ skeleton_path = NodePath("../../../BattleBot/Armature/Skeleton")
bone_name = "Right_UpperArm"
update_mode = 0
look_at_axis = 1
use_our_rot_x = false
use_our_rot_y = false
use_our_rot_z = false
use_our_rotation_x = false
use_our_rotation_y = false
use_our_rotation_z = false
use_negative_our_rot = false
additional_rotation = Vector3( 0, 0, 180 )
debug_messages = false

View File

@@ -10,7 +10,7 @@ source_file="res://weapon_pistol.dae"
source_md5="5070f29403355abe514cc6a266bd148e"
dest_files=[ "res://.import/weapon_pistol.dae-b8ccfaa12c6b728117e9f797617f9226.scn" ]
dest_md5="20e86722c36f5eb06cf9891a168f03ea"
dest_md5="c812d9a4944bb42985cf5cfd81d0678c"
[params]