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)