Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

[py] Multi quaternion slerp > Table DAT (optimizing tips?)

General discussion about anything TouchDesigner

[py] Multi quaternion slerp > Table DAT (optimizing tips?)

Postby why » Fri Aug 17, 2018 5:10 am

I have a python script that interpolates sequentially between 37 different quaternions and then writes it to a Table DAT. This then gets converted to a CHOP and used as a texture buffer in a GLSL MAT which controls the rotation of 37 instances. My cook times are a bit high when i run the script, so I'm hoping to see if there's a way to clean it up.

I'm using quaternion for continuous/infinite rotation because if i used euler, it would a) just increase the rotation value forever or b) if i limited it to 360° then the transition from 359 to 0, would make it spin the other way. If there's another way to do this, I'm open to trying. I'm not sure which part of my python script is slowing things down, but perhaps its the quat.slerp method and would be better off avoiding quaternions.

My script cook time when it's running is 2.5ms. I'll post the .tox and code here. In the tox, all you need to do is change the value in the "new_index" CHOP and it will make the script run.

pyQuatWrite2Table.tox
(2.67 KiB) Downloaded 22 times


Code: Select all
maxCharCount = int(op('maxCharCount')[0])

#set up the first two quaternions in the list
quatList = [
tdu.Quaternion(tdu.Vector(0, 0, 0)), tdu.Quaternion(tdu.Vector(181, 0, 0))
]

#set up the first two rotations
rotList = ['rot0','rot1']

#figure out how many remaining elements we need to add to the list
remaining = maxCharCount - 2;

#automatically fill in the rest of the lists
for x in range(remaining):
      value = 180 - ((x + 0.5) * (180/remaining))
      quatList.append(tdu.Quaternion(tdu.Vector(value, 0, 0)))
      rotList.append('rot' + str(x + 2))

qTable = op('table1')

def onValueChange(channel, sampleIndex, val, prev):
   
   #the transition time
   t = val % 1
   
   for x in range(maxCharCount):
      currentIndex = (math.floor(val) + x) % maxCharCount
      nextIndex = (math.floor(val) + x + 1) % maxCharCount
      
      #inerpolating between quaternions
      rotList[x] = quatList[currentIndex].slerp(quatList[nextIndex], t)
      
      #writing them to the table
      qTable[x,0] = rotList[x].x
      qTable[x,1] = rotList[x].y
      qTable[x,2] = rotList[x].z
      qTable[x,3] = rotList[x].w
      
   return
why
 
Posts: 44
Joined: Mon Apr 27, 2015 3:14 pm

Re: [py] Multi quaternion slerp > Table DAT (optimizing tips

Postby mouren » Sun Aug 19, 2018 12:58 am

Just for reference, I tried this out on my 2015 macbook pro in osx, 2.5 ghz i7, 16gb, high sierra, running build 2018.25000.

I was getting around 1.0-1.3 ms cook time in the info1 CHOP, timeline running at 60 fps.


Da.
mouren
 
Posts: 79
Joined: Fri Oct 17, 2014 3:10 am


Return to General TouchDesigner Discussion

Who is online

Users browsing this forum: Google [Bot] and 7 guests