OK, I’ve rewritten the main part of the bone generation based on some SDK examples which cuts the amount of code needed in half. I would love to get some feedback on if this can be cleaned up even more to be even more efficient.
This will generate the curve the bones will be aligned to:
SICreateCurve "crvlist", 1, 1
SIAddPointOnCurveAtEnd "crvlist", -5.56400247283325, 15.5115341097636, 4.4254119186418, False, 0
SIAddPointOnCurveAtEnd "crvlist", -7.54199935613224, 15.3638670622132, 2.89084056715819, False, 0
SIAddPointOnCurveAtEnd "crvlist", -9.07458678847619, 14.8604566728363, 3.20805546316486, False, 0
SetValue "crvlist.Name", "R_Arm_Crv"
This will Generate the bones:
Option Explicit
Dim oRoot, oArmCrv_1, oGeometry, oPos1, oPos2, oPos3, oChain, oBone2, ort, CurSel, bn2Sel, oEff
Dim time_in,LinearNonInterpolated,Time_Out
'**** Start Timer ****
time_in = timer
Function Create2boneChain(Side,Name,view)
set oRoot = application.activeproject.activescene.root
set oArmCrv_1 = oRoot.FindChild(Side & Name & "_Crv")
set oGeometry = oArmCrv_1.activeprimitive.geometry
set oPos1 = oGeometry.Points(0).position
set oPos2 = oGeometry.Points(1).position
set oPos3 = oGeometry.Points(2).position
Logmessage oPos1.x
Logmessage oPos2.x
Logmessage oPos3.x
set oChain = oRoot.Add2DChain( array(oPos1.x,oPos1.y,oPos1.z), array(oPos2.x,oPos2.y,oPos2.z), , view, Side&Name&"_Root" )
Set oBone2 = oChain.AddBone (array(oPos3.x,oPos3.y,oPos3.z), siChainBonePin, Side & Name&"_Bone2")
End Function
Create2boneChain "R_","Arm","0"
'**** End timer ****
time_out = timer
logmessage "elapsed time: " & round(time_out - time_in,3)
What I found to take a huge amount of time is renaming the bones.
The code I’m using basically finds the root bone (using oRoot.FindChild()), then finds the neighbor (using SelectNeighborObj)and renames it.
Time without renaming the bones:0.078[size=2]
[/size]Time with renaming the bones:0.506
If anyone know a more efficient way to rename the bones I would realy appreciate it.