This is my very first project so I don’t really know how Touchdesigner works.
I’m trying to show a different 3D model depending on your hand gesture but I really struggle to make it work… For that, I use a switch SOP to change between 4 different file in SOP depending on the hand gesture that the MediaPipe plug-in detects. The script is supposed to change the value of the “Select Input” of the switch when you change your hand gesture.
I tried to look everywhere and the only possibility seems to code so I asked ChatGPT and this is what he gave me :
# Inputs: Each gesture corresponds to a separate CHOP with a binary output (1 = active, 0 = inactive)
gesture1 = op('mathILY') # CHOP for ILY
gesture2 = op('mathPoint') # CHOP for Point
gesture3 = op('mathVic') # CHOP for Victory
gesture4 = op('mathNone') # CHOP for Nonep
# Output: The index to set for the Switch SOP
switch_sop = op('switch2')
#Determine which gesture is active
def get_active_gesture():
if gesture1[0] == 1:
return 0 # Index 0 for ILY
elif gesture2[0] == 1:
return 1 # Index 1 for Point
elif gesture3[0] == 1:
return 2 # Index 2 for Victory
else:
return 3 # Default index if no gesture is active
#Update the Switch SOP index
switch_index = get_active_gesture()
switch_sop.par.index = switch_index
If you have any clue on how I can build such a thing or on how I can code this it would help me a lot !!!
The select CHOP recognize the hand gesture and give a number between 0 and 1 (the probability of the gesture)
The first math CHOP round the number (so it’s now always 1)
The second math CHOP multiply the number (either by 1, 2, 3 or 0)
The last math CHOP as ‘Combine CHOPs’ set on ‘Add’ + is linked to the ‘Select Input’ of the ‘switch2’
The Fan CHOP converts one channel out to many channels, or converts many channels down to one.
Its first operation, Fan Out, takes one channel and generates 2 or more channels. It sets to 1 one of the output channels while all others are 0, based on the input channel’s value. The first output channel is index value 0, the second, 1, and so on. If the input value is above N-1 or below 0, the value can be clamped, cycled or ignored.
For example, if the value of the input channel at a certain frame is 4, and if the CHOP outputs 8 channels, the fifth channel will have a value of 1, and all other channels will have a zero value at that frame.
The input is assumed to have 1 channel which contains integer values; fractions are truncated and extra channels are ignored. The output channels are binary (0 or 1) channels.
The second operation, Fan In, does the opposite: it takes a bunch of binary inputs and produces one channel containing the index of the “On” channel. If more than one input channel is “On”, the first “On” input channel is selected.
The second operation “Fan In” would be the one of interest for you.
Always a good idea also to export from a Null CHOP. Just keeps things tidy. More info also to be found in our curriculum at