Tag Archives: Python

Nov 12 2014

Evaluate DAT tutorial.

The Evaluate DAT. TouchDesigner 088. 2014.
The Evaluate DAT is an extremely powerful Operator. You can use it to selectively change, replace, or tweak DAT networks. If you have a solid understanding of the Evaluate DAT, you will find more and more uses for it.

1
00:00:00,267 –> 00:00:05,200
Let’s take a look at the
evaluate DAT.

2
00:00:05,200 –> 00:00:12,600
The evaluate DAT can alter the
content of a source table by
using expressions.

3
00:00:12,600 –> 00:00:22,000
The Python expression
“me.inputCell.val” is a
reference to each incoming cell.

4
00:00:22,000 –> 00:00:31,867
The evaluate DAT will examine
the content of every incoming
cell, and assign it to that
variable.

5
00:00:31,867 –> 00:00:40,100
I set the evaluate DAT to output
the result of the expression
evaluation.

6
00:00:40,100 –> 00:00:50,600
The Python expression will
create a string that appends
“hello”, to the input value, to
an exclamation point.

7
00:00:50,600 –> 00:00:59,300
The second example shows how we
can use the evaluate DAT to
perform math functions on the
input values.

8
00:00:59,300 –> 00:01:10,467
We start with a noise CHOP that
creates 60 samples, then use a
chop to DAT to create a table
with 60 rows.

9
00:01:10,467 –> 00:01:20,567
The Python snippet will convert
the input cell value to a
floating point number, then
multiply that by PI.

10
00:01:20,567 –> 00:01:29,833
The next example shows the
ability of the evaluate DAT to
process multiple rows and
columns simultaneously.

11
00:01:29,833 –> 00:01:35,300
The second input is now a table
with 2 columns, not 1.

12
00:01:35,300 –> 00:01:46,333
The first cell uses the Python
expression “me.inputCell.row”,
to extract the index of the row
being processed.

13
00:01:46,333 –> 00:01:58,933
In this example, we start with a
table that has entries that need
to maintain their order, but
they need to be assigned new
identification indices in proper
sequence.

14
00:01:58,933 –> 00:02:03,933
We use the row index to create
that new sequence.

15
00:02:03,933 –> 00:02:11,633
The last example shows how the
evaluate DAT can create new
entries in a table.

16
00:02:11,633 –> 00:02:17,833
Here, the second input is a
table of 2 rows and 4 columns.

17
00:02:17,833 –> 00:02:25,600
We want to re-sequence the ID
indices, keep the NAME column,
keep the AGE column,

18
00:02:25,600 –> 00:02:34,533
and then finally, use the AGE
column to calculate new values
for the AGE_in_days column.

19
00:02:34,533 –> 00:02:35,933

20
00:02:35,933 –> 00:02:47,100
When we simply use the
“me.inputCell.val” expression,
the evaluate DAT will leave the
input values unchanged.

21
00:02:47,100 –> 00:02:57,867
For the IDs, since we start
evaluating on row 1, we need to
subtract 1, so that we start
with index 0.

22
00:02:57,867 –> 00:03:02,000
The next 2 columns remain
unchanged.

23
00:03:02,000 –> 00:03:14,800
For the last column, we use the
expression “me.inputCell.offset”
to evaluate a specific offset
from the current cell.

24
00:03:14,800 –> 00:03:27,200
In this case, we want to look at
the column to the left, or
behind the current cell, and use
that value as the basis for the
rest of the math function.

25
00:03:27,200 –> 00:03:29,200

Posted In
Tagged
Nov 12 2014

Tile TOP tutorial.

The Tile TOP. TouchDesigner 088. 2014.
The Tile TOP is useful for texture mapping, image transformation, and creating kaleidoscopic effects.

1
00:00:00,267 –> 00:00:02,533
Let’s look at the tile TOP.

2
00:00:02,533 –> 00:00:05,833
I’ve set up two example networks
here.

3
00:00:05,833 –> 00:00:11,633
In the first, we’ll examine the
basic tile TOP parameters.

4
00:00:11,633 –> 00:00:14,967
I started this network with a
ramp TOP.

5
00:00:14,967 –> 00:00:23,867
The “Interpolate Notches”
parameter is set to “Step”, so
we can better visualize the
effect of the tile TOP.

6
00:00:23,867 –> 00:00:31,000
We use an add TOP to combine a
horizontal ramp and vertical
ramp.

7
00:00:31,000 –> 00:00:35,933
I’ll reset the tile TOP to its
default parameters settings.

8
00:00:35,933 –> 00:00:44,600
We can middle mouse click on the
operator, then choose “Reset All
Parameters” from the popup menu.

9
00:00:44,600 –> 00:00:53,100
Under the “Tile” tab, I’ll
change some default values to
see the effect of different
tiling settings.

10
00:00:53,100 –> 00:00:54,967

11
00:00:54,967 –> 00:01:02,767
Transpose will “flop” the image,
the bottom right corner will
become the top left.

12
00:01:02,767 –> 00:01:11,433
We can set the tile TOP to
repeat its input either once or
twice in both the X and Y.

13
00:01:11,433 –> 00:01:12,633

14
00:01:12,633 –> 00:01:21,000
The overlap adjustments will
blend the edges back on to it
tile, creating a smooth
interpolation.

15
00:01:21,000 –> 00:01:22,067

16
00:01:22,067 –> 00:01:29,033
In this example we combine two
tiled images to create a
kaleidoscopic effect.

17
00:01:29,033 –> 00:01:34,367
We use a beat CHOP to create a
series of sine waves.

18
00:01:34,367 –> 00:01:40,267
We then apply those animating
values to TOP parameters.

19
00:01:40,267 –> 00:01:46,333
We set the beat CHOP parameter
named “Multiples” to 4.

20
00:01:46,333 –> 00:01:49,933
This generates 4 channels.

21
00:01:49,933 –> 00:01:57,800
Changing the “Period” parameter
will increase or decrease the
animation speed.

22
00:01:57,800 –> 00:02:12,433
We wire the moviein TOP to a
transform TOP, and apply the
value generated by the beat CHOP
channel named “sine1” to the Z
rotation parameter.

23
00:02:12,433 –> 00:02:26,833
The beat CHOP generates of value
range of -1 to 1, so I multiply
that by 180 to create a 360
degree range of rotation.

24
00:02:26,833 –> 00:02:39,233
Using the same method, I apply
the value of the channel named
“sine3” to the “Crop Left”
parameter of the tile TOP named
“tile2”.

25
00:02:39,233 –> 00:02:52,433
You can easily adjust the Python
expressions to create different
animation effects by increasing
or decreasing the value ranges
created by the beat CHOP.

26
00:02:52,433 –> 00:03:00,367
At the end of the network we
combine the two tile TOPs by
using an add TOP.

27
00:03:00,367 –> 00:03:02,367

Posted In
Tagged
Nov 12 2014

Expression CHOP tutorial.

The Expression CHOP. TouchDesigner 088. 2014.
The Expression CHOP can help you customize and control CHOP behaviors.

1
00:00:00,433 –> 00:00:03,867
Let’s examine the expression
CHOP.

2
00:00:03,867 –> 00:00:05,200

3
00:00:05,200 –> 00:00:17,267
In this example network, we’ll
use the expression CHOP to
convert Cartesian X and Y
coordinates to polar angle
values.

4
00:00:17,267 –> 00:00:26,000
We’ll use a 2D slider to drive
the rotation of a 3 dimensional
geometry component.

5
00:00:26,000 –> 00:00:30,133
The network begins with a 2D
slider.

6
00:00:30,133 –> 00:00:38,667
The 2d slider outputs two
values, an X and Y, ranged 0 to
1.

7
00:00:38,667 –> 00:00:40,067

8
00:00:40,067 –> 00:00:48,167
By default, the slider names the
X channel “v1”, and the Y
channel “v2”.

9
00:00:48,167 –> 00:00:53,700
We use a rename CHOP to change
this to “x” and “y”.

10
00:00:53,700 –> 00:00:59,533
We then use a math CHOP to
re-range our incoming values.

11
00:00:59,533 –> 00:01:07,833
We need to define our Cartesian
space in a range of -1 to 1, not
0 to 1.

12
00:01:07,833 –> 00:01:15,200
The expression CHOP allows us to
modify the input channels by
using math expressions.

13
00:01:15,200 –> 00:01:16,767

14
00:01:16,767 –> 00:01:24,467
In this example we use
trigonometry to evaluate the X
and Y values.

15
00:01:24,467 –> 00:01:30,833
I’ve written a Python snippet
that breaks this expression into
simpler steps.

16
00:01:30,833 –> 00:01:33,000

17
00:01:33,000 –> 00:01:48,400
First, we assign the X and Y
values to variables, then we use
a tangent function to extract
the X & Y values in radians,
then convert radians to degrees.

18
00:01:48,400 –> 00:01:55,633
In Touch Designer, we can run
the contents of any text DAT as
a Python snippet.

19
00:01:55,633 –> 00:01:57,000

20
00:01:57,000 –> 00:02:04,167
When I run this code, you’ll see
that the printed output is the
correct evaluation.

21
00:02:04,167 –> 00:02:11,100
This is an extremely useful
technique for debugging in Touch
Designer.

22
00:02:11,100 –> 00:02:13,433

23
00:02:13,433 –> 00:02:22,567
The contents of the expression
field in the expression CHOP is
a single line version of the
example code.

24
00:02:22,567 –> 00:02:24,300

25
00:02:24,300 –> 00:02:35,267
Since we have combined our
incoming channels by using the
expression CHOP, I’ll rename
resulting channel to “rz”.

26
00:02:35,267 –> 00:02:45,900
We use a Python expression to
extract the value from the
channel named “rz”, of the
operator named “rename2”.

27
00:02:45,900 –> 00:02:53,967
We use this value as the
rotation Z parameter of the
geometry component.

28
00:02:53,967 –> 00:02:55,967

Nov 12 2014

Constant TOP tutorial.

The Constant TOP. TouchDesigner 088. 2014.
The Constant TOP is a fundamental Texture Operator.

1
00:00:00,400 –> 00:00:02,533
Let’s look at the constant TOP.

2
00:00:02,533 –> 00:00:06,933
The constant top creates a solid
color texture.

3
00:00:06,933 –> 00:00:09,767
I’ll add a new constant TOP.

4
00:00:09,767 –> 00:00:16,667
I press the “C” key to show only
the texture operators that begin
with the letter “C”.

5
00:00:16,667 –> 00:00:21,133
We can click the color parameter
to launch the color swatch
pop-up.

6
00:00:21,133 –> 00:00:22,233

7
00:00:22,233 –> 00:00:27,100
I can move the alpha slider to
adjust the density of the alpha
channel.

8
00:00:27,100 –> 00:00:27,933

9
00:00:27,933 –> 00:00:36,167
Under the Common tab, we can
choose from some standard
rendering resolutions.

10
00:00:36,167 –> 00:00:38,700

11
00:00:38,700 –> 00:00:48,700
In this example, I use a beat
CHOP to adjust the alpha channel
parameter of the constant TOP.

12
00:00:48,700 –> 00:00:50,667

13
00:00:50,667 –> 00:00:55,767
I’ll click the “viewer active”
button on the bottom right of
the operator.

14
00:00:55,767 –> 00:00:59,267
We’ll take a look at the beat
CHOP parameters.

15
00:00:59,267 –> 00:01:00,867

16
00:01:00,867 –> 00:01:08,833
We can adjust the period
parameter to increase or
decrease the beat timing.

17
00:01:08,833 –> 00:01:10,133

18
00:01:10,133 –> 00:01:17,000
Here we have a Python expression
written in the alpha parameter
of the constant TOP.

19
00:01:17,000 –> 00:01:18,267

20
00:01:18,267 –> 00:01:29,900
This expression references the 0
to 1 value created by the beat
CHOP, and applies it to the
alpha channel of the constant
TOP.

21
00:01:29,900 –> 00:01:35,400
Here is a simple technique we
can use in Touch Designer to
create expressions.

22
00:01:35,400 –> 00:01:36,500

23
00:01:36,500 –> 00:01:45,900
We click the “viewer active” tab
of the operator, and drag the
channel name to the parameter
field.

24
00:01:45,900 –> 00:01:46,367

25
00:01:46,367 –> 00:01:53,300
We can quickly create a
reference to that channel with
an editable Python expression.

26
00:01:53,300 –> 00:01:55,433

27
00:01:55,433 –> 00:02:05,600
In this example we use the noise
CHOP to create a random RGB
color value for the constant
TOP.

28
00:02:05,600 –> 00:02:08,100
We have 3 noise CHOPs.

29
00:02:08,100 –> 00:02:19,233
The first is set to generate
animating noise of a value range
of -1 to 1 in a channel named
“r”.

30
00:02:19,233 –> 00:02:28,867
The “me.time.frame” Python
expression references the number
of the current cooking frame for
that operator.

31
00:02:28,867 –> 00:02:36,033
Since that value is always
updating, we can use it to
create a simple animation
engine.

32
00:02:36,033 –> 00:02:40,700
We name channel created by this
noise CHOP “r”.

33
00:02:40,700 –> 00:02:45,067
The second noise CHOP differs in
only two settings.

34
00:02:45,067 –> 00:02:56,167
First, the seed parameter, which
is the basis for the noise
generation, and second, the
channel name, which is “g”.

35
00:02:56,167 –> 00:03:08,800
We can change the channel name
to anything we want, but since
we are referencing this channel
by name in the constant TOP,
we’ll leave the channel named
“g”.

36
00:03:08,800 –> 00:03:09,933

37
00:03:09,933 –> 00:03:19,267
The third noise CHOP, with a
channel name “b” for blue, also
has a discrete noise parameter
setting.

38
00:03:19,267 –> 00:03:21,467

39
00:03:21,467 –> 00:03:33,967
We wire all 3 noise CHOPs to a
math CHOP, and re-range our
incoming values to a range of 0
to 1.

40
00:03:33,967 –> 00:03:43,633
Now, using Python expressions,
we reference the 3 different
values created by the noise
CHOPs by channel name.

41
00:03:43,633 –> 00:03:52,167
We then assign them to the
“colorr”, “colorg”, and “colorb”
parameters of the constant TOP.

42
00:03:52,167 –> 00:03:54,167

Nov 12 2014

Select DAT tutorial.

The Select DAT. TouchDesigner 088. 2014.
The Select DAT can function in two powerful ways. It can help you create specified selection sets from table DATs, and it can allow you to reference DATs as instances.

1
00:00:00,500 –> 00:00:04,067
Let’s examine the select DAT.

2
00:00:04,067 –> 00:00:15,100
The select DAT chooses a subset
of rows and columns from the
input table DAT based on
specific search criteria.

3
00:00:15,100 –> 00:00:23,733
The select DAT has several
options for defining that search
or extraction criteria.

4
00:00:23,733 –> 00:00:31,267
In this example we will select
the range of rows based on the
name of the row.

5
00:00:31,267 –> 00:00:35,700
The first entry in a row is
considered its name.

6
00:00:35,700 –> 00:00:36,633

7
00:00:36,633 –> 00:00:45,533
In this example we will select
our rows by name, and we will
select our column subset by
index.

8
00:00:45,533 –> 00:00:53,500
The index is the numerical
identification value of the row
or column, starting with 0.

9
00:00:53,500 –> 00:01:02,800
If we extract a range of columns
starting with column index 1, we
will effectively delete column
0.

10
00:01:02,800 –> 00:01:09,733
The columns in “table2” are
indexed in the numerical range 0
to 5.

11
00:01:09,733 –> 00:01:18,433
In the parameters panel, we can
enter values by typing them in
directly, or by using the
slider.

12
00:01:18,433 –> 00:01:25,367
We can also use Python to create
expressions that will generate
numerical values.

13
00:01:25,367 –> 00:01:33,300
The Python expression will
automatically be evaluated, and
in this case, produce a
numerical result.

14
00:01:33,300 –> 00:01:47,700
In this example, “me” is the DAT
named “select2”, “inputs[0]” is
the DAT named “table2”, and
“numCols” is the number of
columns in “table2”.

15
00:01:47,700 –> 00:01:57,833
Even though we use a base 0
numbering system to index the
number of columns or rows, there
are 6 total columns, not 5.

16
00:01:57,833 –> 00:02:04,333
We subtract 1 from the total row
count to generate our desired
index.

17
00:02:04,333 –> 00:02:06,800

18
00:02:06,800 –> 00:02:16,700
We can click the “edit” button
on the parameters panel of a
text DAT to launch our default
text editor.

19
00:02:16,700 –> 00:02:25,167
Any changes we make and save in
the text editor will
automatically be updated in
Touch Designer.

20
00:02:25,167 –> 00:02:34,767
We can also press the “viewer
active” button on the bottom
right of the operator, to type
changes directly into the
operator.

21
00:02:34,767 –> 00:02:45,900
The text editor will launch with
a temporary file, so it’s
important to keep track of
changes made in either the text
editor, or directly in the
operator.

22
00:02:45,900 –> 00:02:53,733
In this example we convert our
text DAT to a table, by using
the convert DAT.

23
00:02:53,733 –> 00:03:04,000
The “split cells” option defines
which character Touch Designer
will use create new cells from
the incoming text DAT.

24
00:03:04,000 –> 00:03:12,100
As with any operator, we can
middle mouse click on the
operator to display information
about that node.

25
00:03:12,100 –> 00:03:13,367

26
00:03:13,367 –> 00:03:19,433
We’ve converted our text to a
table, now we feed that into a
select DAT.

27
00:03:19,433 –> 00:03:20,533

28
00:03:20,533 –> 00:03:25,367
We’ve chosen to extract our rows
by selected values.

29
00:03:25,367 –> 00:03:26,733

30
00:03:26,733 –> 00:03:34,167
The first entry in each row is
the value or string we will need
to search for.

31
00:03:34,167 –> 00:03:36,100

32
00:03:36,100 –> 00:03:43,433
We can separate string entries
by a “space” character to search
for multiple patterns.

33
00:03:43,433 –> 00:03:52,267
The select DAT will extract each
row from the incoming table that
matches the search pattern.

34
00:03:52,267 –> 00:03:57,667
Now we will extract our columns
by selected values.

35
00:03:57,667 –> 00:04:05,433
Again, the first value in each
column is the value or string we
will need to search for.

36
00:04:05,433 –> 00:04:06,800

37
00:04:06,800 –> 00:04:14,733
In this example we will use
Python expressions to create our
search and extraction criteria.

38
00:04:14,733 –> 00:04:21,600
I’ve included some links so you
can learn more about Python
regular expressions.

39
00:04:21,600 –> 00:04:23,700
We start with a text DAT.

40
00:04:23,700 –> 00:04:29,867
As you can see, I’ve capitalized
each occurrence of the letter
“M”.

41
00:04:29,867 –> 00:04:37,000
We wire the text DAT to a
convert DAT, to convert the text
into a table.

42
00:04:37,000 –> 00:04:41,700
We use the “space” character as
our split cell value.

43
00:04:41,700 –> 00:04:44,267

44
00:04:44,267 –> 00:04:53,500
We wire the convert DAT to our
select DAT, and we choose to
extract our rows by selected
condition.

45
00:04:53,500 –> 00:04:56,367

46
00:04:56,367 –> 00:05:05,533
We use a Python regular
expression to create our search
criteria, in this case the
capitalized letter M.

47
00:05:05,533 –> 00:05:08,433

48
00:05:08,433 –> 00:05:23,433
We use the “str.search” method
which will search for every
occurrence of the capitalized M
in every cell of our input table
DAT.

49
00:05:23,433 –> 00:05:29,200
We’ve extracted every row that
contains the string capital M.

50
00:05:29,200 –> 00:05:30,133

51
00:05:30,133 –> 00:05:42,067
In its default settings, the
selected DAT extracts only the
rows whose first cell contains
the letter M.

52
00:05:42,067 –> 00:05:50,967
We can easily change this
default setting, by adjusting
the “from column” parameter.

53
00:05:50,967 –> 00:06:00,833
We can search a specific column
to find cells that contain our
search string, then extract that
entire row.

54
00:06:00,833 –> 00:06:04,333

55
00:06:04,333 –> 00:06:11,667
In this example we search for
the value “5” in our input table
DAT.

56
00:06:11,667 –> 00:06:20,300
We search column 0, and for each
cell that contains the character
5, we extract that entire row.

57
00:06:20,300 –> 00:06:23,667
Now let’s extract some specific
columns.

58
00:06:23,667 –> 00:06:28,367
Let’s take a look at the
“str.match” method.

59
00:06:28,367 –> 00:06:33,067
The “match” method is different
than the “search” method.

60
00:06:33,067 –> 00:06:39,567
The “match” method only
evaluates the first character of
the input cell.

61
00:06:39,567 –> 00:06:45,033
With the match method, the input
cell “34” will evaluate FALSE.

62
00:06:45,033 –> 00:06:50,733
The search method evaluates all
the characters of the input
cell.

63
00:06:50,733 –> 00:06:57,900
When we search for the 3
character, we find two
conditions that evaluate TRUE.

64
00:06:57,900 –> 00:07:05,533
When we match for the 3
character, we also find two
conditions that evaluate TRUE.

65
00:07:05,533 –> 00:07:07,533