Axial Limitation Tracking Constraint - Ezekial711/MonsterHunterWorldModding GitHub Wiki
Quick Overview
The angular transformation on the ctc is actually setting the plane on which the rotations will happen (XY of the final coordinate system), however the vector formed by the mod3 skeleton determines the point that the rotating system tracks. If the point isn't on the plane however, the system will be tracking on one additional axis. it's hard to explain but if you only apply the rotation on the ctc without editing the mod3 it's very easy to tell what's happening if you know this in advance.
In this sense one simply has to set the x basis vector of the ctc node to point to the next bone in the chain, it rotates around the z basis vector of the ctc node orientation, and you give it a range by rotating it around different values of the z
Tutorial
Start with a 2 bone chain where the child is above the parent on the Z axis and matches on the other two dimensions
[]
Start with the two node chain where the base node has the -90,YY,90 transform (YY defines the angular limits of the rotation around our axis, values of 0 and 180 make it so it can only rotate in one direction (clockwise or anticlockwise), 90 means it can do a full turn in either direction, values around 45 are recommended to avoid some degenerate behavior though, 90° can have issues reorienting itself at times.
[]
Translate (it's important to TRANSLATE, NOT ROTATE the parent, TRANSLATE the children instead) the child bone such that it aligns with the axis of rotation.
[]
Notice how the parent is still in an untransformed coordinate basis
[]
[]
[]
Identify a rotation such that it transform the vertical children setup into this new setup.
[]
In this cause it's a 90° rotation on the Y axis. HOWEVER don't save the mod3 like this we just want the value we'll revert it We just want to identify
which is the equivalent Angular transform that corresponds to our previous translation
[]
[]
We revert the MOD3 to just be a translation but on the CTC
[]
We apply this transformation.
We can get the final rotation matrix we'll be using on the ctc by running this command while selecting the rotated frame:
bpy.context.active_object.matrix_world
In our example we'd get this (the rotation matrix for the 90 degree rotation on the Y axis)
>>> bpy.context.active_object.matrix_world
Matrix(((0, -1, 0, 0),
(1, 0, 0, 0.19413000345230103),
(0, 0, 1, 51.91337966918945),
(0, 0, 0, 1)))
We ignore the translation component (the last column) leaving us with
Matrix(((0, -1, 0, 0),
(1, 0, 0, 0),
(0, 0, 1, 0),
(0, 0, 0, 1)))
Remember in the ctc it's defined by columns so in this case it'd be [0,1,0,0], [1,0,0,0], [0,0,1,0], 0,0,0,1, alternatively, using this code:
import struct
def serializeMatrix(m):
m = m.copy()
m[0][3] = 0
m[1][3] = 0
m[2][3] = 0
b = struct.pack("ffffffffffffffff", *[m[i][j] for j in range(4) for i in range(4)])
print(''.join(map(lambda x: "%02x"%x,b)))
sm = lambda : serializeMatrix(bpy.context.active_object.matrix_world)
and calling
sm()
we get
>>> sm()
6e21a2330400803f0000000000000000040080bf6e21a233000000000000000000000000000000000000803f000000000000000000000000000000000000803f
and can just copy paste that directly to the ctc to the node's transform matrix.
Developments within the CTC toolbox allow this process to be helped along with GUI operations, this considerably simplify the above process. This operations are the alignment and projective alignment operators on the ctc frames.