Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

088: Boids with Script SOP

Share your components here. First one to 100 wins!

088: Boids with Script SOP

Postby snaut » Mon Sep 10, 2012 7:29 pm

boids1_small.jpg
boids1_small.jpg (27.55 KiB) Viewed 9601 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 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:

Code: Select all
# 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
Attachments
BoidsWithSOPs.tox
build with version 088.52320
(5.37 KiB) Downloaded 297 times
User avatar
snaut
Staff
 
Posts: 904
Joined: Mon Nov 12, 2007 6:21 pm
Location: Toronto

Re: 088: Boids with Script SOP

Postby ab30 » Sat Feb 16, 2013 8:09 am

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

Postby Achim » Fri Jul 05, 2013 4:02 am

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: 1711
Joined: Wed Nov 14, 2007 1:52 pm
Location: Cologne

Re: 088: Boids with Script SOP

Postby ivanzlobov » 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'))

instead of
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

Postby manoeuvre » Sat Dec 14, 2013 8:32 pm

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

Re: 088: Boids with Script SOP

Postby ben » 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
User avatar
ben
Staff
 
Posts: 2599
Joined: Thu Nov 08, 2007 6:55 pm
Location: Toronto

Re: 088: Boids with Script SOP

Postby snaut » Mon Dec 16, 2013 4:50 pm

Hey,

an updated version has been added to the initial post.

cheers
Markus
User avatar
snaut
Staff
 
Posts: 904
Joined: Mon Nov 12, 2007 6:21 pm
Location: Toronto

Re: 088: Boids with Script SOP

Postby rodberry » 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.
Attachments
BoidsWithSOPsRodModAudio.4.toe
(5.81 MiB) Downloaded 598 times
User avatar
rodberry
 
Posts: 1068
Joined: Wed Nov 14, 2007 2:51 pm
Location: Hobart, Tasmania, Australia


Return to Shared .tox Components

Who is online

Users browsing this forum: No registered users and 5 guests