Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
cinema4dのcameraの情報をjsonに書き出す
import c4d
import json
import os
from c4d import Quaternion
path = ""
fps = doc[c4d.DOCUMENT_FPS]
filename = os.path.normpath(doc.GetDocumentPath())+"/cam.json"
def main():
with open(filename, 'r') as f:
dic = json.load(f)
frames = dic["frames"]
currentFrame=doc.GetTime().GetFrame(doc.GetFps())
print "==" + str(currentFrame)
cam = op.GetObject()
if len(frames) <= currentFrame:
frames.append({})
frames[currentFrame] = {
"frame": currentFrame,
"q": toQuaternion( cam.GetMg() ),
"x": cam[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X],
"y": cam[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Y],
"z": -cam[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_Z],
"fov": cam[c4d.CAMERA_FOCUS]
}
print toQuaternion( cam.GetMg() )
#hozon
with open(filename, 'w') as f:
json.dump(dic, f, sort_keys=True, indent=4)
def toMatrix(mg):
v1, v2, v3, off = mg.v1, mg.v2, mg.v3, mg.off
return [
v1.x, v1.y, -v1.z,
v2.x, v2.y, -v2.z,
v3.x, v3.y, -v3.z,
off.x, off.y, -off.z,
]
def toQuaternion(mg):
q = Quaternion()
q.SetMatrix( mg )
return [
q.v.x,
q.v.y,
-q.v.z,
q.w
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment