Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/5036842932c873518f0e to your computer and use it in GitHub Desktop.
Save zeffii/5036842932c873518f0e to your computer and use it in GitHub Desktop.
import bpy
running_check = {}
def pack_frame_info(idx):
f = bpy.context.scene.frame_current
dp_str = []
dp_str.append(str(f))
for obj in bpy.data.objects:
if not (tuple(True if i==idx else False for i in range(20)) == obj.layers[:]):
continue
mat = obj.matrix_world
loc = mat.to_translation()
rot = mat.to_3x3().to_quaternion()
scale = obj.dimensions
apt = {
'obj': obj.name,
'qtX': round(rot.x,3),
'qtY': round(rot.y,3),
'qtZ': round(rot.z,3),
'qtW': round(rot.w,3),
'loX': round(loc.x,3),
'loY': round(loc.y,3),
'loZ': round(loc.z,3),
'scX': round(scale.x,3),
'scY': round(scale.y,3),
'scZ': round(scale.z,3)
}
j = '{obj} {loX} {loY} {loZ} {qtX} {qtY} {qtZ} {qtW} {scX} {scY} {scZ}'.format(**apt)
stored_values = running_check.get(obj.name)
if not stored_values:
running_check[obj.name] = j
else:
if (stored_values == j):
# means it was the same, and can be skipped.
continue
else:
# means we proceed to adding this to the output, and store it for next
# iteration.
running_check[obj.name] = j
dp_str.append(j)
return ','.join(dp_str)
k = pack_frame_info(3)
print(k)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment