Hi! I’m relatively new to TouchDesigner and am trying to do something that is definitely out of my knowledge. I’d appreciate any help! I’m trying to create mouse interactive images such that you can drag them around. My goal is to make an interactive scrapbook.
In terms of my set up I have rectangle sop connected to a GEO for instancing and am using a texture and replicate to load my images onto the rectangle. The rectangles currently have x y z motion using noise. I’m trying to use the Multi Touch In and Render pick to read the tx ty tz of the mouse and when the mouse is clicked.
I tried to take the instance tx ty tz data from the noise into a chop to DAT and then use a DAT Execute to adjust it. In my DAT execute I’m trying to read the mouse position, instance number, click, and write it to a new table which can then be turned back into a CHOP and into the geometry. To be honest, I haven’t done much coding or ever used the DAT execute so I’m pretty lost. Not sure if this is even possible or if there’s an entirely different easier way to go about this, please let me know!
When I tried to write the new table as well as to the DAT that’s being read, neither have any changes.
Thank you!
bay_images.18.toe (14.7 KB)
code in my dat execute
def onTableChange(dat):
mouse = op('mousein2')
pick = op('renderpick1')
pos_table = op('null3') # CHOP to DAT containing instance positions
# Ensure Render Pick has valid data
if pick.numRows > 1:
instance = int(pick[1, 8]) # Instance number from Render Pick (column 4)
tx, ty = int(pick[1, 1]), int(pick[1, 2]) # Get mouse positions?
click = mouse['left'] # Left click state (1 when pressed)
#if the user is clicking the mouse and on an image:
if click == 1 and 0 <= instance < pos_table.numRows:
# Update the corresponding row in chopto1
pos_table[instance, 0] = str(tx) # Update x position
pos_table[instance, 1] = str(ty) # Update y position
#question - can I write to the read table or do I need to write to a new table?
table1[instance, 0] = str(instance) # Store instance number
table1[instance, 1] = str(tx) # Store new tx
table1[instance, 2] = str(ty) # Store new ty
return