[Closed] Hair2Splines
Coud someone help me please? I woud like to use Hair and Fur dynamics to drive ornatrix guides. So now I try to convert H&F guides to splines on every frame. Based on created objects I woud like to animate vertexes and splines of first Line. this shoud be the master for skinwrapped ornatrix’s guides.
I really do not understand the way it shoud be done. For “GetVertexPoint obj spline vertex.index” and “SetVertexPoint obj spline vertex.index” animate will not work . Why??? Please help. Coud be there any other problem in my script.
rollout Hair2Spline "HairAnima2SplineAnim" width:212 height:237
(
pickButton btn1 "PickButton" pos:[10,10] width:191 height:42
spinner spn1 "startFrame" pos:[17,75] width:182 height:16 range:[0,200000,0] scale:1
spinner spn2 "endFrame" pos:[16,143] width:183 height:16 range:[0,200000,100] scale:1
button btn2 "Button" pos:[12,179] width:184 height:45
on btn1 picked obj do
(
btn1.text=obj.name
Global Hairr = obj
)
on btn2 pressed do
(
HairStart=spn1.value
HairEnd=spn2.value
fn HairSpline = Hairr.modifiers[#Hair_and_Fur].ConvertGuidesToSplines instance:Hairr
sliderTime= HairStart
Hairr.modifiers[#Hair_and_Fur].ConvertGuidesToSplines instance:Hairr
FirstArray=objects as array
AnimSpline = FirstArray [FirstArray.count]
for i in HairStart+1 to HairEnd do
(
sliderTime=i
Hairr.modifiers[#Hair_and_Fur].ConvertGuidesToSplines instance:Hairr
SecondArray=objects as array
AnimTarget = SecondArray [SecondArray.count]
for s = 1 to (numSplines AnimSpline) do
(
for k = 1 to (numKnots AnimSpline s) do
(
animateVertex AnimSpline #all
animate on
AnimSpline.Spline_s___InVec_k=AnimTarget.Spline_s___InVec_k
AnimSpline.Spline_s___Vertex_k=AnimTarget.Spline_s___Vertex_k
AnimSpline.Spline_s___OutVec_k=AnimTarget.Spline_s___OutVec_k
)
)
delete AnimTarget
)
)
)
createDialog Hair2Spline
Thanks
I create two splines. After execute this lines:
animateVertex $[1] #all
animateVertex $[2] #all
$[1].Spline_1___Vertex_3 = $[2].Spline_1___Vertex_3
Vertex 3 does change its position.
But when I use it in loop:
for s = 1 to (numSplines $[1]) do
(
for k = 1 to (numKnots $[1] s) do
(
$[1].Spline_(s)___Vertex_(k) = $[2].Spline_(s)___Vertex_(k)
)
)
It gives me an error. “__Vertex: undefined”. probably I am doing something really wrong
But it is my 4 script so.
I was logged as someone else by mistake. So now I am back. Sorry ACEmax it will not happen again.
I found only one way to do this script /at my level of knowledge /.
I create strings with words needed to do the move. Some of them are updated in the loop. And I execute full string then. Sloooooow.
rollout Hair2Spline "HairAnima2SplineAnim" width:212 height:237
(
pickButton btn1 "PickButton" pos:[10,10] width:191 height:42
spinner spn1 "startFrame" pos:[17,75] width:182 height:16 range:[0,200000,0] scale:1
spinner spn2 "endFrame" pos:[16,105] width:183 height:16 range:[0,200000,100] scale:1
spinner spn3 "By" pos:[16,150] width:183 height:16 range:[0,100,2] scale:1
button btn2 "Hair2Spline" pos:[12,179] width:184 height:45
on btn1 picked obj do
(
btn1.text=obj.name
Global Hairr = obj
)
on btn2 pressed do
(
HairStart=spn1.value
HairEnd=spn2.value
fn HairSpline = Hairr.modifiers[#Hair_and_Fur].ConvertGuidesToSplines instance:Hairr
sliderTime= HairStart
Hairr.modifiers[#Hair_and_Fur].ConvertGuidesToSplines instance:Hairr
FirstArray=objects as array
AnimSpline = FirstArray [FirstArray.count]
animateVertex AnimSpline #all
for i in HairStart+1 to HairEnd by spn3.value do
(
sliderTime=i
Hairr.modifiers[#Hair_and_Fur].ConvertGuidesToSplines instance:Hairr
SekondArray=objects as array
AnimTarget = SekondArray [SekondArray.count]
animateVertex AnimTarget #all
for s = 1 to (numSplines AnimSpline) do
(
for k = 1 to (numKnots AnimSpline s) do
(
StringA="AnimSpline.Spline_"
StringB=s as string
StringC="___Vertex_"
StringD=k as string
StringE="=AnimTarget.Spline_"
FullString=StringA+StringB+StringC+StringD+StringE+StringB+StringC+StringD
animate on
execute FullString
updateShape AnimSpline
)
)
delete AnimTarget
)
)
)
createDialog Hair2Spline
I have made a tool that converts hair animation to animated splines.
What I did was first on every frame spit out the spline shape of the hair.
After that I looped over all splines and used all splines to drive position of the first spline… delete redundant splines afterwards.
But I didn’t “move” the splines, I added keyframes on every controller of the spline
take a look at my reply here
I found that was faster on large amounts of hair then manually positioning them every frame.
-Johan
Also please note that
Code:
[left]animateVertex $[1] #all
animateVertex $[2] #all
$[1].Spline_1___Vertex_3 = $[2].Spline_1___Vertex_3 [/left]
Does infact instance the controllers of each spline to each other! you’d be better off copying their values! The second example fails because I see no animatevertex statement. So no controllers are created, and thus no instancing can be done. Make sure you understand what you are copying… controllers or values. And even further more you can’t dynamicly cast your loop value in a controller name like that. $[1].Spline_1__Vertex_3 is a hard coded name, you can’t simply swap 1 with a variable… you’ll need some other way to loop over the verts, also see my example posted above.
I understand your way of thinking but doesn’t work like that… it would require execute to parse a string with values, but I would advise against it and look into subanims.
$[1][4][8][2] is vert 1
$[1][4][8][5] is vert 2
$[1][4][8][8] is vert 3 etc.
You’ll see that a loop will work better that way, although it’s a bit more abstract.
-Johan