Author 
Topic 

funkit1
Infrequent Poster
Denmark
3 Posts 
Posted  11/15/2010 : 18:58:18

im doing a project where a string of berries has to pass through a rotary pump. So far i have via the node scripting box managed to make one berry behave correctly. My problem is I need 20 or more berries. I can make those manually and set an offset variable for each individually. But i hope there is a shortcut (perhaps via the console) where i can both replicate and set the variables for the new berries dynamically – anybody out there with a great idea??
ckm 

strata_geek
Infrequent Poster
USA
21 Posts 
Posted  11/15/2010 : 23:55:05

Maybe do what you're doing now in the script but supply a table of offsets to it as well? For a quick hack that just runs once on your system you could set a global with the table of offset values, or you could embed that table into your script source.
Feel free to post your script source if you'd like concrete advice, and indicate which program version you're running.
strata_geek 


funkit1
Infrequent Poster
Denmark
3 Posts 
Posted  11/16/2010 : 17:18:32

Hi strata_geek
Thanks for fast reply. I have uploaded an file here: http://www.funkit.dk/files/strata/novalobe.zip. I have added some more berries to show how it's suposed to work. Alle the 'berry'nodescripts are the same except for the offsetvariable which positions the berry and the whichway variable which determines if the berry is following the upper or the lower rotor through the pump. My programming skills are primarily flash actionscript. In flash we have a neat displaylist where variables can be set dependant of the sprites position in the displaylist. Has Strata something similar? I can see your point in making an array of offsetvalues but i still have to find a way of telling the individual berry which entry in the array to use? Hopes this makes sence :)
(I am using design 3d cx6 version 6.1)
ckm 


tbgriswold
Regularly Educational
USA
1389 Posts 
Posted  11/17/2010 : 12:52:34

This looks very interesting, but I can even find the scripts in this file. They don't seem to show up anywhere when I select the items. But I am a noob when it comes to scripting.
Britt 


jpro
A Fountain of Information
USA
4991 Posts 
Posted  11/17/2010 : 14:37:16

the scripts are attached to the position node of each berry. You have to open the Rotors shape to see the individual berries.
Jean



tbgriswold
Regularly Educational
USA
1389 Posts 
Posted  11/17/2010 : 15:44:54

Thanks! That helped me find them. so many places to hide those scripts.. 


strata_geek
Infrequent Poster
USA
21 Posts 
Posted  11/20/2010 : 17:13:13

Here's a quick pass at a solution based on a Script FX shader rather than a node script. This is your original code slightly modified for the Script FX. I haven't dealt with any timing issues or grouping things so they move exactly the way you want them, but I'm sure you can finesse it from here. I did test this with all but one of your spheres deleted, then I stripped that remaining sphere of the node script, replicated it 100x in place, and then applied the shader to all those spheres at once.
Create a new Script FX from the resource palette and paste the part between the ==== dividers into the initialization section:
==========================
if assert_version then assert_version( 6, 1, 0, prog.program_version ) else assert( false, "This script only works in version 6.1 or later of Strata Design 3D CX" ) end
local phase=nil local nextIndex=0 local initialOffset=125*72 local r = 1.1*72 local speed = 0.5 local newPos = s3d.vec.Point3d() local current = s3d.vec.Point3d()  Prepare precached values.
local function ComputeOffset () local useIndex = nextIndex nextIndex = nextIndex + 1 return initialOffset  math.pi*1.1*72/3*useIndex end
 Report what's implemented for better efficiency. local implemented = { prepare=true, pixel=false, final=false, cleanup=false }
==========================
Then paste the next part between ==== lines into the script body:
==========================
if prepare then  Take advantage of the fact that we extract for globals and then for geometry  so that we can reset the offset index.
if prepare.forGeometry then if phase ~= "geometry" then phase = "geometry" nextIndex = 0 end else if phase ~= "globals" then phase = "globals" nextIndex = 0 end end
local handler = prepare.handler local time = handler:GetTime() local transformation = handler:GetCurrentTransformation() current:Set( 0.0 ) transformation:PointProduct( time, current )  Compute the current position of the object origin.
 Compute our new motion.
local whichway = (nextIndex % 2) == 0 and 1 or 1 local dist = ComputeOffset()  speed*math.pi*2*r*time local v = dist/r newPos.z = 0 if dist>=math.pi*r then newPos.x=distmath.pi*r+2*r newPos.y=0 end if dist< math.pi*r and dist>=math.pi*r/2 then newPos.x=2*r+math.sin(v)*r newPos.y=1*r*whichway+math.cos(v)*r*whichway end if dist<math.pi*r/2 and dist>=math.pi*r/2 then newPos.x=math.sin(v)*r newPos.y=1*r*whichway+math.cos(v)*r*whichway end if dist<math.pi*r/2 and dist>=math.pi*r then newPos.x=2*r+math.sin(v)*r newPos.y=1*r*whichway+math.cos(v)*r*whichway end if dist<math.pi*r then newPos.x=dist+math.pi*r2*r newPos.y=0 end handler:PushTranslation( newPos  current ) end
==========================
It's a hack but I kind of like it. :)
strata_geek 


funkit1
Infrequent Poster
Denmark
3 Posts 
Posted  11/21/2010 : 15:09:49

I have just tried it out and it works brilliantly. Thank you a lot, strata_geek. This was very helpfull and just what i needed.
ckm 



Topic 
