|
@@ -11,7 +11,7 @@ Skeleton node
|
|
|
-------------
|
|
|
|
|
|
The Skeleton node can be directly added anywhere you want on a scene. Usually
|
|
|
-the target mesh is a child of Skeleton, as it easier to manipulate this way, since
|
|
|
+the target mesh is a child of Skeleton, as it is easier to manipulate this way, since
|
|
|
Transforms within a skeleton are relative to where the Skeleton is. But you
|
|
|
can specify a Skeleton node in every MeshInstance.
|
|
|
|
|
@@ -21,13 +21,13 @@ applied to a group of vertices within a mesh. You can directly control a group
|
|
|
of vertices from Godot. For that please reference the :ref:`class_MeshDataTool`
|
|
|
class and its method :ref:`set_vertex_bones <class_MeshDataTool_set_vertex_bones>`.
|
|
|
|
|
|
-The "bones" are organized hierarchically. Every bone, except for root
|
|
|
-bone(s) have a parent. Every bone also has an associated name you can use to
|
|
|
+The "bones" are organized hierarchically. Every bone, except for the root
|
|
|
+bone(s), has a parent. Every bone also has an associated name you can use to
|
|
|
refer to it (e.g. "root" or "hand.L", etc.). All bones are numbered, and
|
|
|
-these numbers are bone IDs. Bone parents are referred by their numbered
|
|
|
+these numbers are bone IDs. Bone parents are referred to by their numbered
|
|
|
IDs.
|
|
|
|
|
|
-For the rest of the article we consider the following scene:
|
|
|
+For the rest of the article, we will consider the following scene:
|
|
|
|
|
|
::
|
|
|
|
|
@@ -68,9 +68,9 @@ function:**
|
|
|
func _ready():
|
|
|
skel = get_node("skel")
|
|
|
var id = skel.find_bone("upperarm")
|
|
|
- print("bone id:", id)
|
|
|
+ print("bone ID:", id)
|
|
|
|
|
|
-Now, we want to do something interesting with the ID, not just printing it.
|
|
|
+Now, we want to do something interesting with the ID, not just print it.
|
|
|
Also, we might need additional information, finding bone parents to
|
|
|
complete chains, etc. This is done with the get/set_bone\_\* functions.
|
|
|
|
|
@@ -84,14 +84,14 @@ complete chains, etc. This is done with the get/set_bone\_\* functions.
|
|
|
func _ready():
|
|
|
skel = get_node("skel")
|
|
|
var id = skel.find_bone("upperarm")
|
|
|
- print("bone id:", id)
|
|
|
+ print("bone ID:", id)
|
|
|
var parent = skel.get_bone_parent(id)
|
|
|
- print("bone parent id:", id)
|
|
|
+ print("bone parent ID:", parent)
|
|
|
|
|
|
-The bone transforms are the things of our interest here. There are 3 kind of
|
|
|
-transforms: local, global, custom.
|
|
|
+The bone transforms are what interests us here. There are 3 kinds of
|
|
|
+transform: local, global, custom.
|
|
|
|
|
|
-**To find the local Transform of a bone we use get_bone_pose(id) function:**
|
|
|
+**To find the local Transform of a bone, we use get_bone_pose(id) function:**
|
|
|
|
|
|
::
|
|
|
|
|
@@ -101,9 +101,9 @@ transforms: local, global, custom.
|
|
|
func _ready():
|
|
|
skel = get_node("skel")
|
|
|
var id = skel.find_bone("upperarm")
|
|
|
- print("bone id:", id)
|
|
|
+ print("bone ID:", id)
|
|
|
var parent = skel.get_bone_parent(id)
|
|
|
- print("bone parent id:", id)
|
|
|
+ print("bone parent ID:", parent)
|
|
|
var t = skel.get_bone_pose(id)
|
|
|
print("bone transform: ", t)
|
|
|
|
|
@@ -123,9 +123,9 @@ other objects there. So let's rotate our "upperarm" bone:
|
|
|
func _ready():
|
|
|
skel = get_node("skel")
|
|
|
id = skel.find_bone("upperarm")
|
|
|
- print("bone id:", id)
|
|
|
+ print("bone ID:", id)
|
|
|
var parent = skel.get_bone_parent(id)
|
|
|
- print("bone parent id:", id)
|
|
|
+ print("bone parent ID:", parent)
|
|
|
var t = skel.get_bone_pose(id)
|
|
|
print("bone transform: ", t)
|
|
|
set_process(true)
|
|
@@ -141,7 +141,7 @@ translate. Try these on your own and check the results.
|
|
|
What we used here was the local pose. By default all bones are not modified.
|
|
|
But this Transform tells us nothing about the relationship between bones.
|
|
|
This information is needed for quite a number of tasks. How can we get
|
|
|
-it? Here the global transform comes into play:
|
|
|
+it? This is where the global transform comes into play:
|
|
|
|
|
|
**To find the bone global Transform we use get_bone_global_pose(id)
|
|
|
function:**
|
|
@@ -156,9 +156,9 @@ Let's find the global Transform for the lowerarm bone:
|
|
|
func _ready():
|
|
|
skel = get_node("skel")
|
|
|
var id = skel.find_bone("lowerarm")
|
|
|
- print("bone id:", id)
|
|
|
+ print("bone ID:", id)
|
|
|
var parent = skel.get_bone_parent(id)
|
|
|
- print("bone parent id:", id)
|
|
|
+ print("bone parent ID:", parent)
|
|
|
var t = skel.get_bone_global_pose(id)
|
|
|
print("bone transform: ", t)
|
|
|
|
|
@@ -174,15 +174,15 @@ at 0 if not modified. Let's print the origin for our lowerarm bone:
|
|
|
func _ready():
|
|
|
skel = get_node("skel")
|
|
|
var id = skel.find_bone("lowerarm")
|
|
|
- print("bone id:", id)
|
|
|
+ print("bone ID:", id)
|
|
|
var parent = skel.get_bone_parent(id)
|
|
|
- print("bone parent id:", id)
|
|
|
+ print("bone parent ID:", parent)
|
|
|
var t = skel.get_bone_global_pose(id)
|
|
|
print("bone origin: ", t.origin)
|
|
|
|
|
|
You will see a number. What does this number mean? It is a rotation
|
|
|
-point of the Transform. So it is base part of the bone. In Blender you can
|
|
|
-go to Pose mode and try there to rotate bones. They will rotate around
|
|
|
+point of the Transform. So it is base part of the bone. In Blender, you can
|
|
|
+go to Pose mode and try to rotate bones there. They will rotate around
|
|
|
their origin.
|
|
|
|
|
|
But what about the bone tip? We can't know things like the bone length,
|
|
@@ -201,10 +201,10 @@ and storing the value in your script.
|
|
|
Using 3D "bones" for mesh control
|
|
|
---------------------------------
|
|
|
|
|
|
-Now as you know the basics we can apply these to make full FK-control of our
|
|
|
+Now, as you know the basics, we can apply these to make full FK-control of our
|
|
|
arm (FK is forward-kinematics).
|
|
|
|
|
|
-To fully control our arm we need the following parameters:
|
|
|
+To fully control our arm, we need the following parameters:
|
|
|
|
|
|
- Upperarm angle x, y, z
|
|
|
- Lowerarm angle x, y, z
|
|
@@ -232,7 +232,7 @@ First we define the setup parameters:
|
|
|
var lowerarm_angle = Vector3()
|
|
|
var upperarm_angle = Vector3()
|
|
|
|
|
|
-Now we need to setup a way to change them. Let us use keys for that.
|
|
|
+Now we need to set up a way to change them. Let us use keys for that.
|
|
|
|
|
|
Please create 7 actions under project settings -> Input Map:
|
|
|
|
|
@@ -244,7 +244,7 @@ Please create 7 actions under project settings -> Input Map:
|
|
|
- **increment** - bind to key numpad +
|
|
|
- **decrement** - bind to key numpad -
|
|
|
|
|
|
-So now we want to adjust the above parameters. Therefore we create code
|
|
|
+So now we want to adjust the above parameters. Therefore, we create code
|
|
|
which does that:
|
|
|
|
|
|
::
|
|
@@ -324,13 +324,13 @@ The full code for arm control is this:
|
|
|
set_bone_rot("lowerarm", lowerarm_angle)
|
|
|
set_bone_rot("upperarm", upperarm_angle)
|
|
|
|
|
|
-Pressing keys 1/2 selects upperarm/lowerarm, select the axis by pressing x,
|
|
|
-y, z, rotate using numpad "+"/"-"
|
|
|
+Pressing keys 1/2 selects upperarm/lowerarm; select the axis by pressing x,
|
|
|
+y, z, rotate using numpad "+"/"-".
|
|
|
|
|
|
This way you fully control your arm in FK mode using 2 bones. You can
|
|
|
add additional bones and/or improve the "feel" of the interface by using
|
|
|
coefficients for the change. I recommend you play with this example a
|
|
|
-lot before going to next part.
|
|
|
+lot before moving on to the next part.
|
|
|
|
|
|
You can clone the demo code for this chapter using
|
|
|
|