My latest mail got bounced, not sure if it worked, I usually bake the world
matrix first otherwise it comes out non animated.
I use the script attached.

On May 18, 2017 7:42 PM, "Falk Hofmann" <f...@kombinat-13b.de> wrote:

> I thought about baking the world matrix prior export. but this seems not
> to work out with .fbx.
>
> With .abc instead it worked fine from and back into nuke. if this might be
> an option as well.
>
>
>
> Hi there,
>
> I would like to Export a camera which is animated itself and also
> transformed by another animated axis
>
> If I try to export the camera with WriteGeo as a fbx the axis animation is
> ignored.
> Am I doing something wrong?
>
> Workaround so far would be to export the axis too and setting it up in my
> DCC of choice.
>
> BUT why?
>
> cheers,
> Vincent
>
>
>
>
> _______________________________________________
> Nuke-python mailing list
> Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
# Code by Erwan Leroy 

import math
import threading

def bakeCameraThread(firstFrame, lastFrame):

    n = nuke.selectedNode()
    n.setSelected(False)
    #check if it has a world matrix knob.
    if not n.knobs().has_key('world_matrix'):
        print "Error: The selected node is not supported"
        return 0

    #Create task to be run in separate thread
    task = nuke.ProgressTask("Baking Camera")
    task.setMessage("Baking Frame")
    
    #create new camera/Axis
    newNode = nuke.createNode(n.Class(), n.writeKnobs(nuke.WRITE_USER_KNOB_DEFS | nuke.WRITE_NON_DEFAULT_ONLY | nuke.TO_SCRIPT), inpanel=False)
    newNode['xpos'].setValue(n['xpos'].value()+100)
    newNode['ypos'].setValue(n['ypos'].value())
    newNode['label'].setValue("Baked {0}".format(n.name()))
    #Access Translation, Rotation, Scale knobs
    translate = newNode['translate']
    rotate = newNode['rotate']
    scale = newNode['scaling']
    #Reset Translation, Rotation, Scale
    translate.clearAnimated()
    translate.setAnimated()
    rotate.clearAnimated()
    rotate.setAnimated()
    scale.clearAnimated()
    scale.setAnimated()

    #Calculate Trans/Rot/Scale from matrix for each frame
    for f in xrange(firstFrame, lastFrame+1):

        if task.isCancelled():
              nuke.executeInMainThread( nuke.message, args=( "Canceled" ) )
              break;
        #create blank Matrix
        mResult = nuke.math.Matrix4()
        for i in xrange(0,16):
            mResult[i] = n['world_matrix'].valueAt(f)[i]
        mResult.transpose()
        #Calculate Stuff
        mTranslate = nuke.math.Matrix4(mResult)
        mTranslate.translationOnly()
        mRotate = nuke.math.Matrix4(mResult)
        mRotate.rotationOnly()
        rotateRad = mRotate.rotationsZXY()
        mScale = nuke.math.Matrix4(mResult)
        mScale.scaleOnly()
        #Assign Keyframes     
        translate.setValueAt( mTranslate[12], f, 0)
        translate.setValueAt( mTranslate[13], f, 1)
        translate.setValueAt( mTranslate[14], f, 2)
        rotate.setValueAt( math.degrees(rotateRad[0]), f, 0)
        rotate.setValueAt( math.degrees(rotateRad[1]), f, 1)
        rotate.setValueAt( math.degrees(rotateRad[2]), f, 2)
        scale.setValueAt( mScale.xAxis().x, f, 0)
        scale.setValueAt( mScale.yAxis().y, f, 1)
        scale.setValueAt( mScale.zAxis().z, f, 2)

        #set thread progress
        task.setProgress(int((f-firstFrame)/((lastFrame-firstFrame)*0.01)))

def bakeCamera(firstFrame, lastFrame):
    threading.Thread( None, bakeCameraThread(firstFrame, lastFrame) ).start()
bakeCamera(1001, 1400)
_______________________________________________
Nuke-python mailing list
Nuke-python@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to