Friday, September 21, 2018

Need to enable playback on all viewports at the same time?

Go to preferences > Time Slider>Playback and change Update View from Active to All.
Source:
https://forums.cgsociety.org/t/scrub-animation-in-all-viewports/1524209

Wednesday, September 5, 2018

Get distance between two points

Question was simple. Get the world position of any item in space throughout the entire timeline, then compare each point to get the frame-by-frame traveled distance.

With pymel, first get the item:

import pymel.all as pm
item = pm.selected()[0]

Get the frame range and turn off cycle check:

start_time = pm.playbackOptions(q=1,animationStartTime=1)
end_time = pm.playbackOptions(q=1,animationEndTime=1)
anim_range = range(int(start_time),int(end_time))
pm.cycleCheck(evaluation = 0)

Then, get its worldMatrix at every frame:

item_values = [pm.getAttr(item.worldMatrix,time=t)[-1][:-1] for t in anim_range]

To figure out the difference between frames, I didn't know how to do, so after some searching, this post had the most concise result:

https://stackoverflow.com/questions/1401712/how-can-the-euclidean-distance-be-calculated-with-numpy

And finally, the code needed to get the differences

per_frame_change = []
for i in range(len(item_values)-1):
    per_frame_change.append(numpy.linalg.norm(item_values[i] - item_values[i-1]))


Here's the whole code!

import pymel.all as pm
import numpy
start_time = pm.playbackOptions(q=1,animationStartTime=1)
end_time = pm.playbackOptions(q=1,animationEndTime=1)
anim_range = range(int(start_time),int(end_time))
pm.cycleCheck(evaluation = 0)

item = pm.selected()[0]
item_values = [pm.getAttr(item.worldMatrix,time=t)[-1][:-1] for t in anim_range]

per_frame_change = []
for i in range(len(item_values)-1):
    per_frame_change.append(numpy.linalg.norm(item_values[i] - item_values[i-1]))