Created
June 21, 2016 12:41
-
-
Save PierrickKoch/9bdc8f5a3926099f0fd84c83d2e96e7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from math import sin, cos | |
import bpy | |
from mathutils import Matrix | |
def matrix(yaw, pitch, roll, x, y, z): | |
# from pom-genom/libeuler/pomEuler.c:287 (pomWriteSensorPos) | |
# euler.{yaw,pitch,roll,x,y,z} | |
ca, sa = cos(yaw), sin(yaw) | |
cb, sb = cos(pitch), sin(pitch) | |
cg, sg = cos(roll), sin(roll) | |
return [[ ca*cb, ca*sb*sg - sa*cg, ca*sb*cg + sa*sg, x], | |
[ sa*cb, sa*sb*sg + ca*cg, sa*sb*cg - ca*sg, y], | |
[ -sb, cb*sg, cb*cg, z], | |
[ 0.0, 0.0, 0.0, 1.0]] | |
n = 0 | |
patern = 'cloud.%05i.pos' | |
while os.path.isfile(patern%n): | |
with open(patern%n) as f: | |
lines = f.readlines() | |
parser = lambda label: matrix(*map(float, [line for line in lines \ | |
if line.startswith(label)][0].strip().split()[2:])) | |
bpy.context.scene.frame_set(n) | |
bpy.context.active_object.matrix_world = Matrix(parser('mainToOrigin = ')) | |
bpy.ops.anim.keyframe_insert(type='LocRotScale', confirm_success=True) | |
n+=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment