Chain UpVector Positioning


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from win32com.client import constants as c
from win32com.client import Dispatch as d
 
xsi = Application
log = xsi.LogMessage
oSceneRoot = xsi.ActiveProject2.ActiveScene.Root
collSel = xsi.Selection
 
# Create rotation vectors
vecHip = XSIMath.CreateVector3()
vecKnee = XSIMath.CreateVector3()
vecAnkle = XSIMath.CreateVector3()
 
vec1 = XSIMath.CreateVector3()
vec2 = XSIMath.CreateVector3()
vecCross = XSIMath.CreateVector3()
vecUpVectorPos = XSIMath.CreateVector3()
 
collSel(0).Kinematics.Global.Transform.GetTranslation(vecHip)
collSel(1).Kinematics.Global.Transform.GetTranslation(vecKnee)
collSel(2).Kinematics.Global.Transform.GetTranslation(vecAnkle)
 
vec1.Sub(vecHip, vecAnkle)
vec2.Sub(vecHip, vecKnee)
 
vecXUpVector = XSIMath.CreateVector3()
vecYUpVector = XSIMath.CreateVector3()
vecZUpVector = XSIMath.CreateVector3()
 
vecUpVectorPos.LinearlyInterpolate( vecHip, vecAnkle, 0.5 )
vecXUpVector.Cross(vec2,vec1)
vecYUpVector.Sub(vecUpVectorPos,vecHip)
vecZUpVector.Sub(vecKnee,vecUpVectorPos)
 
vecPosOffset = XSIMath.CreateVector3()
vecPosOffset.Sub(vecKnee,vecUpVectorPos)
vecPosOffset.Set(vecPosOffset.X * 2,vecPosOffset.Y,vecPosOffset.Z * 2)
vecUpVectorPos.AddInPlace(vecPosOffset)
 
vecXUpVector.NormalizeInPlace()
vecYUpVector.NormalizeInPlace()
vecZUpVector.NormalizeInPlace()
 
xformUpVector = XSIMath.CreateTransform()
xformUpVector.SetRotationFromXYZAxes(vecXUpVector,vecYUpVector,vecZUpVector)
xformUpVector.SetTranslation(vecUpVectorPos)
 
collSel(3).Kinematics.Global.PutTransform2("",xformUpVector)