## 088: Boids with Script SOP

Share your components here. First one to 100 wins!

### 088: Boids with Script SOP

boids1_small.jpg (27.55 KiB) Viewed 9431 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
Attachments
BoidsWithSOPs.tox
build with version 088.52320

snaut
Staff

Posts: 901
Joined: Mon Nov 12, 2007 6:21 pm
Location: Toronto

### Re: 088: Boids with Script SOP

Same idea with a little bit more of user control
ab30

Posts: 276
Joined: Fri Apr 27, 2012 11:36 am

### Re: 088: Boids with Script SOP

is it normal that the script SOP takes ~14 ms for this rather small amount of points?

Cologne area TD artists? Let’s get in touch

Achim

Posts: 1706
Joined: Wed Nov 14, 2007 1:52 pm
Location: Cologne

### Re: 088: Boids with Script SOP

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.
ivanzlobov

Posts: 8
Joined: Sun May 20, 2012 1:01 pm

### Re: 088: Boids with Script SOP

manoeuvre

Posts: 27
Joined: Sun Jan 22, 2012 10:19 am
Location: Australia

### Re: 088: Boids with Script SOP

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

ben
Staff

Posts: 2557
Joined: Thu Nov 08, 2007 6:55 pm
Location: Toronto

### Re: 088: Boids with Script SOP

Hey,

an updated version has been added to the initial post.

cheers
Markus

snaut
Staff

Posts: 901
Joined: Mon Nov 12, 2007 6:21 pm
Location: Toronto

### Re: 088: Boids with Script SOP

I had some fun with this. No optimisation. The oscillator CHOP is the big fat CPU-sucker in this case.

rod.
Attachments
BoidsWithSOPsRodModAudio.4.toe

rodberry

Posts: 1068
Joined: Wed Nov 14, 2007 2:51 pm
Location: Hobart, Tasmania, Australia

### Who is online

Users browsing this forum: No registered users and 4 guests