#Rotating a bone with GDscript properly.

1 messages · Page 1 of 1 (latest)

delicate drum
#

This is a long shot but i've been struggling with bone transformations in Godot as it works differently than most 3d applications. Godot seems to assume world-space for everything and this is often undesirable for hierarchy-based items like a rig skeleton.

Currently, I want the ability to specify euler angle rotations relative to a bone's rest rotation. IE: Vector3(0.5, 1.0, 1.5) would rotate the x, y, and z axis by those values. The issue is that Godot's built-in functions seem to rotate things in ways I'm not expecting. In experiments I have this code that rotates the second joint 45 degrees:

    var Skeleton = get_scene().find_child("Skeleton3D")
    var Bone = Skeleton.find_bone("Bone_(1)")
    var RestPos = Skeleton.get_bone_rest(Bone)
    
    var SetRot = RestPos.rotated(RestPos.basis.z, deg_to_rad(45))
    Skeleton.set_bone_pose(Bone, SetRot)

Applied to a test object, the rotation looks like this (see image). The pivot is correct, but the bone should not be moved positionally if its using the rest pose as a basis.

Is there an easier way to apply rotations explicitly in gdscript? I really need these rotations to be relative to the bone's rest position/rotation so that I can read external data to apply animations properly.

As a side note, I also have the option of exporting the full transformation data from external applications (Blender, Maya, etc), but I would like to avoid that as it needlessly bloats the data when all I want are rotations.

#

the test object is structured thusly, nothing special.

delicate drum
#

To boil it down to just the issue... why do rotation functions do this? I'm rotating the child of this bone yet applying the rotation moves it away from its pivot point.