Page 1 of 1

### 088: Boids with Script SOP

Posted: Mon Sep 10, 2012 7:29 pm
boids1_small.jpg (27.55 KiB) Viewed 9464 times

Note: the most recent version of this file can be found here:

BoidsWithSOPs is another example usage of the Script SOP. Here I am using the numpy library (which is included in the TouchDesigner088 installation) to apply rules derived from code here based on Craig W. Reynolds' description of boid systems.

Of note here is the Table DAT called controls holding parameters that can be adjusted.
cohesionScale, alignmentScale and targetScale are reversed meaning larger values equal to a lesser effect.

To start things up, all point positions and the values for a Custom Attrib (added in a Point SOP) are read into a numpy arrays:

Code: Select all
`# add points and velocity into empty numpy arrayoldPoints = np.empty([len(points),3])oldVelocity = np.empty([len(points),3])count = 0for i in points:   oldPoints[count]=[i.x,i.y,i.z]   oldVelocity[count]=[i.Z[0],i.Z[1],i.Z[2]]   count += 1`

After looping through all points and determining their new velocity the result is added back on to the point position and velocity is stored as an attribute. In order to also rotate them correctly, the velocity is applied as the Normal to the point:

Code: Select all
`# update point location and save velocity into Zp = myPoints[j]p.P += rulesp.Z = rulesp.N = rules`

Note: This component requires TouchDesigner088

### Re: 088: Boids with Script SOP

Posted: Sat Feb 16, 2013 8:09 am
Same idea with a little bit more of user control

### Re: 088: Boids with Script SOP

Posted: Fri Jul 05, 2013 4:02 am
is it normal that the script SOP takes ~14 ms for this rather small amount of points?

### Re: 088: Boids with Script SOP

Posted: Wed Dec 04, 2013 4:49 am
Hey! So i was trying 088 scripting and found this interesting, i love boids!

The script doesn't work for me unless you rename 'points' array to something else and will directly grab sop content by EG
Code: Select all
`points = scriptOP.copy(op('point1')) `

Code: Select all
`scriptOP.copy(scriptOP.inputs[0])`

2 Derivative - my python skills are kinda fresh, two days at all =), but it looks like there were changes at some point in scriptSOP method calling fields for similar reason (is this to avoid variable vs method names override or something else)?

Because I see /geometry_examples/script1_script in old PythonExamples.toe calling scriptop.appendPoly with points=true instead of addPoints=true and that doesn't work in my build (11760) unless fixed.

### Re: 088: Boids with Script SOP

Posted: Sat Dec 14, 2013 8:32 pm

### Re: 088: Boids with Script SOP

Posted: Mon Dec 16, 2013 3:32 pm
ivanzlobov wrote: it looks like there were changes at some point in scriptSOP method calling fields for similar reason

Yes, there were some recent changes to clean up syntax. There is a new Python example file for you to refer to found here:
<TouchDesigner088 install dir>/Samples/Python/PythonExamples.toe

### Re: 088: Boids with Script SOP

Posted: Mon Dec 16, 2013 4:50 pm
Hey,

an updated version has been added to the initial post.

cheers
Markus

### Re: 088: Boids with Script SOP

Posted: Tue Dec 17, 2013 4:01 am
I had some fun with this. No optimisation. The oscillator CHOP is the big fat CPU-sucker in this case.

rod.