anam-ation

I live in my own little world. But its ok, they know me there.

Panda Data

Whilst at Jason Bruges Studio, as part of the maintenance for a project entitled ‘Panda Eyes’ for WWF i helped generate the 3d visualisation of the panda’s by scanning a panda using Trnio a scan app, and then placing that into Cinema4d and animating the 100 panda’s and saving the rotation data out.

 

Script to obtain rotation data from Panda’s in Cinema4d:

[python]

import c4d, math, random
from c4d.modules import mograph as mo
from c4d import Vector as v, Matrix as m
from c4d import utils
import csv
import time

def main():

rotationdata = "C:Users/anam/Dropbox/ANAM/PANDA/csv rotation files/sequence01.csv"

doc = c4d.documents.GetActiveDocument ()

#get fps and minimum and maximum frames

op = doc.SearchObject(‘test’) #search for object in c4d to store data

md = mo.GeGetMoData(op)
if md==None: return False

cnt = md.GetCount()
marr = md.GetArray(c4d.MODATA_MATRIX)

for i in xrange(0,cnt): # for matrices in matrix print individual matrices
m = marr[i]
rot = utils.MatrixToHPB(m)[0] #get the H rotation value from the objects

#convert radians to degrees

degrees = utils.RadToDeg(rot)
rotstr = str(int(degrees))

print i,rotstr
[/python]

Python script to write Panda rotation data for each frame in the timeline to CSV:

[python]
import c4d, math, random
from c4d.modules import mograph as mo
from c4d import Vector as v, Matrix as m
from c4d import utils
import csv
import time

def main():
doc = c4d.documents.GetActiveDocument ()
rotationdata = "C:/Users/anam/Desktop/pandarotation/sequence01.csv"
obj = doc.SearchObject(‘pfield’)

ctime = doc.GetTime() # Save current time

# Get FPS and minimum + maximum frames
fps = doc.GetFps()
start = doc.GetMinTime().GetFrame(fps)
end = doc.GetMaxTime().GetFrame(fps)

with open(rotationdata, ‘wb’) as f:

#for frame in xrange(start,end+1):
frame = 0
#print c4d.BaseTime(frame,fps)
while c4d.BaseTime(frame,fps) < doc.GetMaxTime():

bt = c4d.BaseTime (frame, fps) #current frame,frame rate
c4d.documents.SetDocumentTime (doc, bt)

#print "Document time : ", doc.GetTime().GetFrame(fps)

c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)# make the timeline, timeslider etc. do an instant redraw.)
c4d.EventAdd(c4d.EVENT_ANIMATE)
md = mo.GeGetMoData(op)
if md == None: return False

cnt = md.GetCount()
marr = md.GetArray(c4d.MODATA_CLONE)

c4d.DrawViews()

node_count = 0 #count node
for i in xrange(0,cnt):

m = marr[i]
rot = utils.MatrixToHPB(m)[0] #get the H rotation value from the objects

#convert radians to degrees

degrees = utils.RadToDeg(rot)
rotstr = str(int(degrees))

#print i,rotstr

f.write(rotstr)
f.write(‘,’) #separate values with comma in csv file

#see node and colour for each frame in c4d console

#print "Node ID : ", node_count, " || Writing value : ", col255

node_count += 1

#print "Frame " , frame

#gen.Message(c4d.MSG_UPDATE)
#op.Message(c4d.MSG_UPDATE)

c4d.EventAdd(c4d.EVENT_ANIMATE) #Adds a global event to Cinema 4D’s event queue. Results in a CoreMessage() message.

frame += 1

f.close()

if __name__==’__main__’:
main()

[/python]

Next Post

Previous Post

Leave a Reply

© 2020 anam-ation

Theme by Anders Norén