Skip to content

Commit

Permalink
Added a fully working RR-Comparison and did a massive refactor of the…
Browse files Browse the repository at this point in the history
… code

I could clean some code by simply deleting now unused variables. Also the RRComparison seems to be working fine apart from a sometimes disapearing TwoBoneIK.
SkeletonModification2DSlider is still not able to work (see issue #2) but I had forgot to push the project file which contains a reference to the class.
  • Loading branch information
pwab committed Sep 5, 2020
1 parent ffac99d commit e33fae5
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 98 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[gd_scene load_steps=1491 format=2]
[gd_scene load_steps=1490 format=2]

[ext_resource path="res://icon.png" type="Texture2D" id=2]
[ext_resource path="res://Assets/Linkages/rotational_joint.png" type="Texture2D" id=3]
[ext_resource path="res://Scenes/Test_CrankRocker/target.gd" type="Script" id=4]

[sub_resource type="StyleBoxFlat" id=1]
Expand Down Expand Up @@ -11071,12 +11070,6 @@ position = Vector2( 469.864, 115.874 )
modification_stack = SubResource( 1480 )
script = null

[node name="Joint" type="Sprite2D" parent="Crank"]
scale = Vector2( 0.07, 0.07 )
skew = 4.37114e-08
texture = ExtResource( 3 )
script = null

[node name="Bone2D" type="Bone2D" parent="Crank"]
skew = 4.37114e-08
rest = Transform2D( 100, 100, 0, 0, 0, 0 )
Expand Down
15 changes: 0 additions & 15 deletions Scenes/Test_CrankRocker/target.gd
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
extends Position2D

# HACK: changed export to nothing
#@export var tip_node: NodePath
var tip_node: NodePath
@onready var active = false

### HACK
func _ready():
print(self.name)
if self.name == "Crank_Target":
tip_node = NodePath("Crank/Bone2D/Tip")
elif self.name == "Crank_Rocker_Target_1":
tip_node = NodePath("Crank_Rocker_1/Bone2D_A0A/Tip")
elif self.name == "Crank_Rocker_Target_2":
tip_node = NodePath("Crank_Rocker_2/Bone2D_B0B/Tip")
### END OF HACK

func _process(delta):
if active:
self.position = get_global_mouse_position()

func _input(event):
if active:
if event is InputEventMouseButton and not event.is_pressed():
print("Released on ", self.name)
active = false

func _on_Tip_input_event(viewport, event, shape_idx):
Expand Down
26 changes: 26 additions & 0 deletions Scenes/Test_RRComparison/RR_target.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
extends Position2D

var target_nodes
@onready var active = false

func _ready():
target_nodes = [
get_parent().get_node("RR_FABRIK_Target"),
get_parent().get_node("RR_CCDIK_Target"),
get_parent().get_node("RR_TwoBoneIK_Target")
]

func _process(delta):
if active:
var position_delta = get_global_mouse_position() - self.global_position
for target in target_nodes:
target.position += position_delta

func _input(event):
if active:
if event is InputEventMouseButton and not event.is_pressed():
active = false

func _on_Tip_input_event(viewport, event, shape_idx):
if event is InputEventMouseButton and event.is_pressed():
active = true
220 changes: 199 additions & 21 deletions Scenes/Test_RRComparison/SkeletonModification_TestRRComparison.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_scene load_steps=1484 format=2]
[gd_scene load_steps=1488 format=2]

[ext_resource path="res://Scenes/Test_RRComparison/RR_target.gd" type="Script" id=1]
[ext_resource path="res://icon.png" type="Texture2D" id=2]
[ext_resource path="res://Scenes/Test_CrankRocker/target.gd" type="Script" id=4]

[sub_resource type="StyleBoxFlat" id=1]
content_margin_left = 6.0
Expand Down Expand Up @@ -10935,8 +10935,8 @@ Window/icons/close_highlight = SubResource( 539 )
Window/styles/panel = SubResource( 1449 )
Window/styles/panel_window = SubResource( 1477 )

[sub_resource type="SkeletonModification2DFABRIK" id=1480]
target_nodepath = NodePath("../RR_Robot_FABRIK_Target")
[sub_resource type="SkeletonModification2DFABRIK" id=1479]
target_nodepath = NodePath("../RR_FABRIK_Target")
fabrik_data_chain_length = 2
joint_data/0/bone_index = 0
joint_data/0/bone2d_node = NodePath("Bone2D_A0A")
Expand All @@ -10947,14 +10947,44 @@ joint_data/1/magnet_position = Vector2( 0, 0 )
joint_data/1/use_target_rotation = false
joint_data/1/enable_constraint = false

[sub_resource type="SkeletonModificationStack2D" id=1481]
[sub_resource type="SkeletonModificationStack2D" id=1480]
enabled = true
modification_count = 1
modifications/0 = SubResource( 1480 )
modifications/0 = SubResource( 1479 )

[sub_resource type="CircleShape2D" id=1479]
[sub_resource type="CircleShape2D" id=1481]
radius = 20.0

[sub_resource type="SkeletonModification2DCCDIK" id=1482]
target_nodepath = NodePath("../RR_CCDIK_Target")
tip_nodepath = NodePath("Bone2D_A0A/Bone2D_AB/Tip")
ccdik_data_chain_length = 2
joint_data/0/bone_index = 0
joint_data/0/bone2d_node = NodePath("Bone2D_A0A")
joint_data/0/rotate_from_joint = false
joint_data/0/enable_constraint = false
joint_data/1/bone_index = 1
joint_data/1/bone2d_node = NodePath("Bone2D_A0A/Bone2D_AB")
joint_data/1/rotate_from_joint = false
joint_data/1/enable_constraint = false

[sub_resource type="SkeletonModificationStack2D" id=1483]
enabled = true
modification_count = 1
modifications/0 = SubResource( 1482 )

[sub_resource type="SkeletonModification2DTwoBoneIK" id=1484]
target_nodepath = NodePath("../RR_TwoBoneIK_Target")
joint_one_bone_idx = 0
joint_one_bone2d_node = NodePath("Bone2D_A0A")
joint_two_bone_idx = 1
joint_two_bone2d_node = NodePath("Bone2D_A0A/Bone2D_AB")

[sub_resource type="SkeletonModificationStack2D" id=1485]
enabled = true
modification_count = 1
modifications/0 = SubResource( 1484 )

[node name="SkeletonModification_TestRRComparison" type="Node2D"]
script = null

Expand Down Expand Up @@ -11020,17 +11050,17 @@ __meta__ = {
"_edit_use_anchors_": false
}

[node name="RR_Robot_FABRIK" type="Skeleton2D" parent="."]
[node name="RR_FABRIK" type="Skeleton2D" parent="."]
position = Vector2( 150, 350 )
skew = 4.37114e-08
modification_stack = SubResource( 1481 )
modification_stack = SubResource( 1480 )
script = null

[node name="FixedJoint_A0" type="Sprite2D" parent="RR_Robot_FABRIK"]
[node name="FixedJoint_A0" type="Sprite2D" parent="RR_FABRIK"]
skew = 4.37114e-08
script = null

[node name="Bone2D_A0A" type="Bone2D" parent="RR_Robot_FABRIK"]
[node name="Bone2D_A0A" type="Bone2D" parent="RR_FABRIK"]
scale = Vector2( 0.999969, 0.999969 )
skew = 4.37114e-08
rest = Transform2D( 0, -100, 0, 0, 0, 0 )
Expand All @@ -11039,13 +11069,13 @@ __meta__ = {
"_local_pose_override_enabled_": true
}

[node name="Polygon2D" type="Polygon2D" parent="RR_Robot_FABRIK/Bone2D_A0A"]
[node name="Polygon2D" type="Polygon2D" parent="RR_FABRIK/Bone2D_A0A"]
color = Color( 0.0117647, 0.117647, 0.376471, 1 )
antialiased = true
polygon = PackedVector2Array( 3.40427, 5.52051, 8.58723, 4.39639, 11.6141, 1.17117, 14.1946, -4.77911, 15.3173, -12.1989, 10.4843, -116.481, 9.08598, -121.161, 5.31137, -121.952, 1.57472, -122.215, -2.61446, -121.383, -6.04756, -117.418, -11.7823, -12.3773, -11.8933, -6.52704, -10.1172, 0.475861, -6.87413, 3.75211, -2.12656, 5.29105 )
script = null

[node name="Bone2D_AB" type="Bone2D" parent="RR_Robot_FABRIK/Bone2D_A0A"]
[node name="Bone2D_AB" type="Bone2D" parent="RR_FABRIK/Bone2D_A0A"]
position = Vector2( 2.69264, -123.598 )
rotation = -0.186272
skew = 4.37114e-08
Expand All @@ -11058,36 +11088,184 @@ __meta__ = {
"_local_pose_override_enabled_": true
}

[node name="Line2D" type="Polygon2D" parent="RR_Robot_FABRIK/Bone2D_A0A/Bone2D_AB"]
[node name="Line2D" type="Polygon2D" parent="RR_FABRIK/Bone2D_A0A/Bone2D_AB"]
rotation = 0.42809
color = Color( 0.0235294, 0.207843, 0.556863, 1 )
antialiased = true
polygon = PackedVector2Array( -9.66638, 4.38167, -6.78394, 6.77997, -3.51218, 7.35481, 0.479279, 7.05531, 5.76993, 4.94412, 8.12379, 1.37128, 8.43338, -2.00713, 7.9758, -6.30751, -34.0905, -89.0124, -35.6384, -91.5352, -37.286, -93.4, -39.4998, -95.0812, -41.9115, -95.7189, -44.1115, -95.1506, -45.5733, -92.9036, -45.5634, -90.2993, -44.6611, -86.8666, -43.9055, -84.5359, -11.1561, 1.31435 )
script = null

[node name="Tip" type="Area2D" parent="RR_Robot_FABRIK/Bone2D_A0A/Bone2D_AB"]
[node name="Tip" type="Area2D" parent="RR_FABRIK/Bone2D_A0A/Bone2D_AB"]
position = Vector2( 0, -100 )
scale = Vector2( 1.00003, 1.00003 )
skew = 4.37114e-08
script = null

[node name="Sprite" type="Sprite2D" parent="RR_Robot_FABRIK/Bone2D_A0A/Bone2D_AB/Tip"]
[node name="Sprite" type="Sprite2D" parent="RR_FABRIK/Bone2D_A0A/Bone2D_AB/Tip"]
modulate = Color( 0, 0, 0, 1 )
scale = Vector2( 0.05, 0.05 )
skew = 4.37114e-08
texture = ExtResource( 2 )
script = null

[node name="CollisionShape2D" type="CollisionShape2D" parent="RR_Robot_FABRIK/Bone2D_A0A/Bone2D_AB/Tip"]
shape = SubResource( 1479 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="RR_FABRIK/Bone2D_A0A/Bone2D_AB/Tip"]
shape = SubResource( 1481 )
script = null

[node name="RR_Robot_FABRIK_Target" type="Position2D" parent="."]
[node name="RR_FABRIK_Target" type="Position2D" parent="."]
modulate = Color( 0, 0, 0, 1 )
position = Vector2( 150.105, 127.576 )
skew = 4.37114e-08
script = ExtResource( 4 )
script = ExtResource( 1 )
__meta__ = {
"_gizmo_extents_": 20.0
}

[node name="RR_CCDIK" type="Skeleton2D" parent="."]
position = Vector2( 504.392, 347.618 )
skew = 4.37114e-08
modification_stack = SubResource( 1483 )
script = null

[node name="FixedJoint_A0" type="Sprite2D" parent="RR_CCDIK"]
skew = 4.37114e-08
script = null

[node name="Bone2D_A0A" type="Bone2D" parent="RR_CCDIK"]
rotation = 0.0717154
scale = Vector2( 0.999968, 0.999968 )
skew = 4.37114e-08
rest = Transform2D( 0, -100, 0, 0, 0, 0 )
script = null
__meta__ = {
"_local_pose_override_enabled_": true
}

[node name="Polygon2D" type="Polygon2D" parent="RR_CCDIK/Bone2D_A0A"]
color = Color( 0.0117647, 0.117647, 0.376471, 1 )
antialiased = true
polygon = PackedVector2Array( 3.40427, 5.52051, 8.58723, 4.39639, 11.6141, 1.17117, 14.1946, -4.77911, 15.3173, -12.1989, 10.4843, -116.481, 9.08598, -121.161, 5.31137, -121.952, 1.57472, -122.215, -2.61446, -121.383, -6.04756, -117.418, -11.7823, -12.3773, -11.8933, -6.52704, -10.1172, 0.475861, -6.87413, 3.75211, -2.12656, 5.29105 )
script = null

[node name="Bone2D_AB" type="Bone2D" parent="RR_CCDIK/Bone2D_A0A"]
position = Vector2( 2.69263, -123.598 )
rotation = -0.186336
scale = Vector2( 1, 1 )
skew = 4.37114e-08
rest = Transform2D( 100, 0, 0, 0, 0, 0 )
auto_calculate_length_and_angle = false
length = 100.0
bone_angle = -90.0
script = null
__meta__ = {
"_local_pose_override_enabled_": true
}

[node name="Line2D" type="Polygon2D" parent="RR_CCDIK/Bone2D_A0A/Bone2D_AB"]
rotation = 0.42809
color = Color( 0.0235294, 0.207843, 0.556863, 1 )
antialiased = true
polygon = PackedVector2Array( -9.66638, 4.38167, -6.78394, 6.77997, -3.51218, 7.35481, 0.479279, 7.05531, 5.76993, 4.94412, 8.12379, 1.37128, 8.43338, -2.00713, 7.9758, -6.30751, -34.0905, -89.0124, -35.6384, -91.5352, -37.286, -93.4, -39.4998, -95.0812, -41.9115, -95.7189, -44.1115, -95.1506, -45.5733, -92.9036, -45.5634, -90.2993, -44.6611, -86.8666, -43.9055, -84.5359, -11.1561, 1.31435 )
script = null

[node name="Tip" type="Area2D" parent="RR_CCDIK/Bone2D_A0A/Bone2D_AB"]
position = Vector2( 0, -100 )
scale = Vector2( 1.00003, 1.00003 )
skew = 4.37114e-08
script = null

[node name="Sprite" type="Sprite2D" parent="RR_CCDIK/Bone2D_A0A/Bone2D_AB/Tip"]
modulate = Color( 0, 0, 0, 1 )
scale = Vector2( 0.05, 0.05 )
skew = 4.37114e-08
texture = ExtResource( 2 )
script = null

[node name="CollisionShape2D" type="CollisionShape2D" parent="RR_CCDIK/Bone2D_A0A/Bone2D_AB/Tip"]
shape = SubResource( 1481 )
script = null

[node name="RR_CCDIK_Target" type="Position2D" parent="."]
modulate = Color( 0, 0, 0, 1 )
position = Vector2( 504.497, 125.194 )
skew = 4.37114e-08
script = ExtResource( 1 )
__meta__ = {
"_gizmo_extents_": 20.0
}

[node name="RR_TwoBoneIK" type="Skeleton2D" parent="."]
position = Vector2( 831.023, 347.618 )
skew = 4.37114e-08
modification_stack = SubResource( 1485 )
script = null

[node name="FixedJoint_A0" type="Sprite2D" parent="RR_TwoBoneIK"]
skew = 4.37114e-08
script = null

[node name="Bone2D_A0A" type="Bone2D" parent="RR_TwoBoneIK"]
rotation = 0.0716933
scale = Vector2( 0.999965, 0.999965 )
skew = 4.37114e-08
rest = Transform2D( 0, -100, 0, 0, 0, 0 )
script = null
__meta__ = {
"_local_pose_override_enabled_": true
}

[node name="Polygon2D" type="Polygon2D" parent="RR_TwoBoneIK/Bone2D_A0A"]
color = Color( 0.0117647, 0.117647, 0.376471, 1 )
antialiased = true
polygon = PackedVector2Array( 3.40427, 5.52051, 8.58723, 4.39639, 11.6141, 1.17117, 14.1946, -4.77911, 15.3173, -12.1989, 10.4843, -116.481, 9.08598, -121.161, 5.31137, -121.952, 1.57472, -122.215, -2.61446, -121.383, -6.04756, -117.418, -11.7823, -12.3773, -11.8933, -6.52704, -10.1172, 0.475861, -6.87413, 3.75211, -2.12656, 5.29105 )
script = null

[node name="Bone2D_AB" type="Bone2D" parent="RR_TwoBoneIK/Bone2D_A0A"]
position = Vector2( 2.68976, -123.598 )
rotation = -0.186258
scale = Vector2( 0.999998, 0.999998 )
skew = 4.37114e-08
rest = Transform2D( 100, 0, 0, 0, 0, 0 )
auto_calculate_length_and_angle = false
length = 100.0
bone_angle = -90.0
script = null
__meta__ = {
"_local_pose_override_enabled_": true
}

[node name="Line2D" type="Polygon2D" parent="RR_TwoBoneIK/Bone2D_A0A/Bone2D_AB"]
rotation = 0.42809
color = Color( 0.0235294, 0.207843, 0.556863, 1 )
antialiased = true
polygon = PackedVector2Array( -9.66638, 4.38167, -6.78394, 6.77997, -3.51218, 7.35481, 0.479279, 7.05531, 5.76993, 4.94412, 8.12379, 1.37128, 8.43338, -2.00713, 7.9758, -6.30751, -34.0905, -89.0124, -35.6384, -91.5352, -37.286, -93.4, -39.4998, -95.0812, -41.9115, -95.7189, -44.1115, -95.1506, -45.5733, -92.9036, -45.5634, -90.2993, -44.6611, -86.8666, -43.9055, -84.5359, -11.1561, 1.31435 )
script = null

[node name="Tip" type="Area2D" parent="RR_TwoBoneIK/Bone2D_A0A/Bone2D_AB"]
position = Vector2( 0, -100 )
scale = Vector2( 1.00003, 1.00003 )
skew = 4.37114e-08
script = null

[node name="Sprite" type="Sprite2D" parent="RR_TwoBoneIK/Bone2D_A0A/Bone2D_AB/Tip"]
modulate = Color( 0, 0, 0, 1 )
scale = Vector2( 0.05, 0.05 )
skew = 4.37114e-08
texture = ExtResource( 2 )
script = null

[node name="CollisionShape2D" type="CollisionShape2D" parent="RR_TwoBoneIK/Bone2D_A0A/Bone2D_AB/Tip"]
shape = SubResource( 1481 )
script = null

[node name="RR_TwoBoneIK_Target" type="Position2D" parent="."]
modulate = Color( 0, 0, 0, 1 )
position = Vector2( 831.128, 125.194 )
skew = 4.37114e-08
script = ExtResource( 1 )
__meta__ = {
"_gizmo_extents_": 20.0
}
[connection signal="input_event" from="RR_Robot_FABRIK/Bone2D_A0A/Bone2D_AB/Tip" to="RR_Robot_FABRIK_Target" method="_on_Tip_input_event"]
[connection signal="input_event" from="RR_FABRIK/Bone2D_A0A/Bone2D_AB/Tip" to="RR_FABRIK_Target" method="_on_Tip_input_event"]
[connection signal="input_event" from="RR_CCDIK/Bone2D_A0A/Bone2D_AB/Tip" to="RR_FABRIK_Target" method="_on_Tip_input_event"]
[connection signal="input_event" from="RR_TwoBoneIK/Bone2D_A0A/Bone2D_AB/Tip" to="RR_FABRIK_Target" method="_on_Tip_input_event"]
Loading

0 comments on commit e33fae5

Please sign in to comment.