Method for distributing objects along curve without twisting around tangent


#1

Hi
I’m trying to make node for maya with python that computes Euler rotations and positions for objects on curve
I tried some simple methods to create basis vectors and compute quaternions but it doesn’t work as expected so i tried to google some other methods but i’m a little lost now = )
Could you help me with some links or advices ?
For example, i have Head mesh and some curves that represents hair and i need to distribute joints on this curves.
So may be i can use head as orientation for basis vectors on curves to make this vectors with correct twisting around tangent but i can’t find any good methods.
Please help ! = )


#2

I think i need to tell about method that i’m currently using:

first i’m creating array of tangents by simply iterating along curve and using MFnNurbsCurve let’s call it

tans[]

second i make basis at first param on curve

up = (0, 1, 0)
helper = tans[0] ^ up

^ - cross product

norm_0 - normal vector at first param on curve

norm_0 = helper ^ tans[0]

Then i iterate along curve again by the same params and compute bitangent and normal vector for each param

To create normal vector i rotate previous one by quaternion

Quaternion using cross product of current and next tangent as rotate axis

prev_norm = norm_0
for i in xrange(count - 1):
rot_quat = quat_by_shortest_arc(tans[i], tans[i + 1])
current_norm = prev_norm.rotateBy(rot_quat)
binorm = tans[i] ^ tans[i + 1]
matrix = (tans[i+1], 0
  current_norm, 0
  binorm, 0
  0, 0, 0, 1)
# then i convert matirix to euler rotaions
rot = matrix.toEuler(matrix, orderXYZ)
# and store rot values for params and then apply rotations for objects at given position on curve


#3

Don’t know if it’s what you’re after, but: https://www.youtube.com/watch?v=_Ey8TSduH4U


#4

Yeah, that’s kinda result i’m after, but i’m using maya 2016 SP5 and want to make custom plugin so i can upgrade it depending on my needs
I think that problem in my method is that i’m converting Quternion to Euler angles and as result i get singularities ( gimbal lock ) i tried to find save method to convert Quaternion but didn’t find any working examples
So may be there is a way to plug quaternion ( or Matrix ) as a connection to other node for rotations ?