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:
# add points and velocity into empty numpy array
oldPoints = np.empty([len(points),3])
oldVelocity = np.empty([len(points),3])
count = 0
for 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:
# update point location and save velocity into Z
p = myPoints[j]
p.P += rules
p.Z = rules
p.N = rules
Note: This component requires TouchDesigner088 BoidsWithSOPs.tox (5.37 KB)
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
points = scriptOP.copy(op('point1'))
instead of
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.
Yes, there were some recent changes to clean up syntax. There is a new Python example file for you to refer to found here:
/Samples/Python/PythonExamples.toe
sorry I’m a newbie with this, and it’s also 8 years after the last thread reply, but here it goes –
how do we control the number of boids within this script? I’m not so sure how to read through it…