PDA

View Full Version : Spline_IK_control: select the createhelper point


flyingaway
03-30-2009, 05:13 AM
when I created a spline_IK_control,and created 10 points, how I can use for loop to select the points and update their postion?
JHN give me the method

Code:
getProperty $.modifiers[1] #helper_list


Assuming modifiers[1] is the modifier. If you create a modifier in script you could also directly call the getProperty on the modifier like


Code:
getProperty theSplineIKMod #helper_list


Provided theSplineIKMod is the variable pointing to the modifier.

It will return an array of helpers, which you can use to apply the data to.

and what I want to do:
SC=Spline_IK_Control()
addModifier $MySpline01 SC
SC.linkTypes=2
SC.createhelper 10
getProperty SC #helper_list
--a=#helper_list
--dont know how to get the following through
with animation on
for i=1 to 10 do
(
read data from dat file
get point[i]
point[i].pos=readvalue of file

)

JHN
03-31-2009, 08:27 AM
theSpline = selection[1]
numSplinePoints = numKnots theSpline

-- I have no clue on how your data looks, so can't help with that.
-- I'm using a sample array of arrays to get data, will generate a 10 row array (time) in wich each row has 8 position values
timeStep = 10
dataArray = for t = 0 to 100 by dataArray collect for o = 1 to numSplinePoints collect [random -100 100,random -100 100,random -100 100]

sc = Spline_IK_Control()
sc.linkTypes=2
addModifier theSpline sc
sc.createhelper numSplinePoints
thePoints = getProperty sc #helper_list

with animate on
for i = 1 to dataArray.count do -- time loop
(
--read data from dat file
for j = 1 to dataArray[i].count do -- data loop
(
at time ((i - 1) * timeStep) -- start at 0 (-1) and times (*) timeStep
thePoints[j].pos = dataArray[i][j]
)
)


I would recommend chewing on this a bit and read through the manual and on this forum about retreiving data from a file, there's plenty of info on that.
Also try to keep related posts in the same thread, you shouldn't have to create a new thread for each "clearly related to the original problem" request/question.

Hope this helps,

-Johan

flyingaway
04-01-2009, 01:29 AM
Hi ,JHN , thanks for take time to solve my questions and I will take care next time;)
the data was created by random function ,but we can make it fuitable , isnt it?
here I give the link that the code to create the data I will use to animate the points
http://forums.cgsociety.org/showthread.php?f=98&t=747372

flyingaway
04-10-2009, 12:37 PM
My code as follow,when I excute it , it got a erro:
-- Compile error: Unexpected end-of-script
-- In line: 

/* CREATE A SPLINE */
theSpline = splineShape name:(uniqueName #MySpline) wirecolor:orange -- create a base spline
addNewSpline theSpline -- add a spline
for i = 1 to 10 do
addKnot theSpline 1 #smooth #curve [30*i,0,0] -- add some knots
updateShape theSpline -- Now draw the shape in the viewport
SC=Spline_IK_Control()
addModifier $MySpline01 SC
SC.linkTypes=2
SC.createhelper 10
thePoints =getProperty SC #helper_list
with animate on(
f=getopenfilename types:"data(*.dat)|*.dat|all|*.*"
thefile=openfile f
for t = 0 to 100 by 5 do (
at time t
for i = 1 to thePoints.count do (
local theLine = readLine thefile
if (eof thefile) do ( seek thefile 0 )
local mySet
if (matchPattern theLine pattern:"set *") then (
mySet = (filterString theLine " ")[2] as integer
)
else if (matchPattern theLine pattern:"end set *") then ( )
else if (theLine == "") then ( )
else (
local myPoint3Array = filterString theLine " "
local myPoint3 = point3 (myPoint3Array[1] as float) (myPoint3Array[2] as float) (myPoint3Array[3] as float)
thePoints[i].pos += myPoint3
)
)
)

the data was created by random and the code was given by losbellos as follow
function writeout = (
a=1
b=1000
extfile = createfile "d:/randomdata.dat"
for i= 1 to 44 do (
format "set %\n" i to:extfile
for k=1 to 500 do (
format "% % %\n" (random a b) (random a b) (random a b) to:extfile
)
format "end set %\n" i to:extfile
format "\n" i to:extfile
)
close extfile
)
writeout()

some one can figure out why I got the erro ,thanks

CGTalk Moderation
04-10-2009, 12:37 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.