Thanks for that script Pete, it helped me understand how to approach this
:).

On a side note, I'm also trying to create a 4x4 matrix node, but I'm not
sure how to do it as it defaults to 3x3 if you use
nuke.createNode("Matrix"). I see that Nuke calls
nukescripts.create_matrix() when creating a matrix Node, but I can't seem
to find that script either. Any suggestions?

Thanks again.







2012/6/27 Pete O'Connell <[email protected]>

> Hi Simon. I think the code below should apply the returned variable of the
> getTheCornerpinAsMatrix() function to a new cornerpin node's matrix. See
> how getTheCornerpinAsMatrix() is being used in a loop below?
>
> Is that kind of what you are after?
> Pete
>
> #####################################################
> # by Pete O'Connell
> import nuke
> def convertCornerpinToMatrix():
>     theFirstFrame = int(nuke.root()['first_frame'].value())
>     theLastFrame = int(nuke.root()['last_frame'].value())
>
>     theAnimatedMatrixList = []
>     nuke.frame(theFirstFrame)
>     for i in range(theFirstFrame,theLastFrame+1):
>         theCurveToolNode = nuke.nodes.CurveTool()
>         theCurveToolNode['operation'].setValue('Auto Crop')
>         theCurveToolNode['name'].setValue("curveToolNode")
>
>         nuke.execute("curveToolNode",i,i)
>         # note: the next line refers to the getTheCornerpinAsMatrix()
> function
>         theAnimatedMatrixList.append(getTheCornerpinAsMatrix())
>         nuke.delete(theCurveToolNode)
>
>     theNewCornerpinNode = nuke.createNode("CornerPin2D")
>
>     theNewCornerpinNode['transform_matrix'].setAnimated()
>
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][0],aFrame,0)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][1],aFrame,1)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][2],aFrame,2)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][3],aFrame,3)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][4],aFrame,4)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][5],aFrame,5)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][6],aFrame,6)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][7],aFrame,7)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][8],aFrame,8)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][9],aFrame,9)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][10],aFrame,10)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][11],aFrame,11)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][12],aFrame,12)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][13],aFrame,13)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][14],aFrame,14)
>     for aFrame in range(theFirstFrame,theLastFrame+1):
>
> theNewCornerpinNode['transform_matrix'].setValueAt(theAnimatedMatrixList[aFrame-theFirstFrame][15],aFrame,15)
> #######################################################
>
>
>
>
>
> On Wed, Jun 27, 2012 at 2:55 AM, Magno Borgo <[email protected]> wrote:
>
>> **
>> Does  your corner pin uses expressions? You may need to bake/generate the
>> animated values.
>>
>> Magno.
>>
>>
>> Hi Magno,
>>
>> thanks for your reply and sorry for not replying earlier.
>>
>> I did take a look at your script, but couldn't get it to work. I copied
>> to corner pin matrix values to a new corner pin, but they don't seem to
>> match. Any idea? Then again, I'm no python expert.
>>
>> The script Pete O'Connel posted to this list eralier works, but I don't
>> get any animated values out of it. Anyone know how to modyfi it? Basically
>> I want to run the script on a corner-pin node, and create a Gridwarp with
>> that transform matrix.
>>
>> Here's Pete's script again. Hope you don't mind me reposting it.
>>
>>
>> import nukedef getTheCornerpinAsMatrix():
>>     projectionMatrixTo = nuke.math.Matrix4()     projectionMatrixFrom =
>> nuke.math.Matrix4()         #dir(projectionMatrix)    theCornerpinNode =
>> nuke.selectedNode()
>>     imageWidth = float(theCornerpinNode.width())     imageHeight =
>> float(theCornerpinNode.height())             to1x =
>> theCornerpinNode['to1'].value()[0]     to1y =
>> theCornerpinNode['to1'].value()[1]    to2x =
>> theCornerpinNode['to2'].value()[0]     to2y =
>> theCornerpinNode['to2'].value()[1]    to3x =
>> theCornerpinNode['to3'].value()[0]     to3y =
>> theCornerpinNode['to3'].value()[1]    to4x =
>> theCornerpinNode['to4'].value()[0]     to4y =
>> theCornerpinNode['to4'].value()[1]         from1x =
>> theCornerpinNode['from1'].value()[0]    from1y =
>> theCornerpinNode['from1'].value()[1]     from2x =
>> theCornerpinNode['from2'].value()[0]    from2y =
>> theCornerpinNode['from2'].value()[1]     from3x =
>> theCornerpinNode['from3'].value()[0]    from3y =
>> theCornerpinNode['from3'].value()[1]     from4x =
>> theCornerpinNode['from4'].value()[0]    from4y =
>> theCornerpinNode['from4'].value()[1]
>> projectionMatrixTo.mapUnitSquareToQuad(to1x,to1y,to2x,to2y,to3x,to3y,to4x,to4y)
>>
>> projectionMatrixFrom.mapUnitSquareToQuad(from1x,from1y,from2x,from2y,from3x,from3y,from4x,from4y)
>>        theCornerpinAsMatrix =
>> projectionMatrixTo*projectionMatrixFrom.inverse()
>> theCornerpinAsMatrix.transpose()         return theCornerpinAsMatrix
>>
>>
>> Best regards,
>>
>> Simon
>>
>> 2012/6/14 Magno Borgo <[email protected]>
>>
>>> The attached script should get you started.
>>>
>>>
>>>
>>> I found this,
>>> http://forums.thefoundry.co.uk/phpBB2/viewtopic.php?t=5810&view=previous&sid=5a7db5ea82b78d9cb79f400e14b18493
>>>  but
>>> unless I'm missing something it doen't seem to work for animated corner
>>> pins. Anyone know of a way?
>>>
>>> Best regards,
>>> Simon
>>>
>>>
>>>
>>>
>>> --
>>> **************************
>>> Magno Borgo
>>>
>>> www.borgo.tv
>>> www.boundaryvfx.com
>>>
>>> _______________________________________________
>>> Nuke-python mailing list
>>> [email protected], http://forums.thefoundry.co.uk/
>>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>>
>>>
>>
>>
>>
>> --
>> **************************
>> Magno Borgo
>>
>> www.borgo.tv
>> www.boundaryvfx.com
>>
>> _______________________________________________
>> Nuke-python mailing list
>> [email protected], http://forums.thefoundry.co.uk/
>> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>>
>>
>
>
> --
> -
>
> _______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python

Reply via email to