Hi Francois,
I found your message when grappling with this problem myself, did you ever
resolve it? I've been using this code to test it out, just printing out
the matrix, rotating the camera, and then printing again. Using Maya 2014:
from maya import OpenMaya as om
from maya import OpenMayaUI as omui
mat = om.MMatrix()
tmat = om.MMatrix()
view = omui.M3dView().active3dView()
def print_mv():
global mat, tmat, view
result = view.modelViewMatrix(mat)
suff = '' if mat != tmat else '!'
for i in range(4):
print("{0}{1}".format(["{0:>12.6f}".format(mat(i,j)) for j in range(
4)], suff))
mat, tmat = tmat, mat
The matrix will update most of the time but has sporadic failures:
print_mv()
[' 0.258819', ' 0.332557', ' -0.906873', ' -0.000000']
[' -0.000000', ' 0.938864', ' 0.344288', ' 0.000000']
[' 0.965926', ' -0.089108', ' 0.242996', ' -0.000000']
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']
print_mv()
[' 0.697165', ' 0.211259', ' -0.685077', ' -0.000000']
[' 0.000000', ' 0.955596', ' 0.294680', ' -0.000000']
[' 0.716911', ' -0.205441', ' 0.666208', ' -0.000000']
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']
print_mv()
[' 0.697165', ' 0.211259', ' -0.685077', ' -0.000000']!
[' 0.000000', ' 0.955596', ' 0.294680', ' -0.000000']!
[' 0.716911', ' -0.205441', ' 0.666208', ' -0.000000']!
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']! #FAILURE!
print_mv()
[' 0.867765', ' 0.180836', ' -0.462905', ' -0.000000']
[' -0.000000', ' 0.931448', ' 0.363875', ' 0.000000']
[' 0.496974', ' -0.315758', ' 0.808278', ' -0.000000']
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']
print_mv()
[' 0.999848', ' -0.010634', ' 0.013839', ' -0.000000']
[' -0.000000', ' 0.792946', ' 0.609292', ' 0.000000']
[' -0.017452', ' -0.609200', ' 0.792825', ' -0.000000']
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']
print_mv()
[' 0.962218', ' -0.149640', ' 0.227474', ' -0.000000']
[' -0.000000', ' 0.835440', ' 0.549582', ' 0.000000']
[' -0.272280', ' -0.528818', ' 0.803875', ' -0.000000']
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']
print_mv()
[' 0.785857', ' -0.361203', ' 0.501958', ' -0.000000']
[' -0.000000', ' 0.811693', ' 0.584085', ' 0.000000']
[' -0.618408', ' -0.459007', ' 0.637874', ' -0.000000']
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']
print_mv()
[' -0.272280', ' -0.387351', ' 0.880808', ' -0.000000']
[' -0.000000', ' 0.915393', ' 0.402561', ' 0.000000']
[' -0.962218', ' 0.109609', ' -0.249244', ' 0.000000']
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']
print_mv()
[' -0.272280', ' -0.387351', ' 0.880808', ' -0.000000']!
[' -0.000000', ' 0.915393', ' 0.402561', ' 0.000000']!
[' -0.962218', ' 0.109609', ' -0.249244', ' 0.000000']!
[' 0.000000', ' 0.000000', ' -44.821870', ' 1.000000']! #FAILURE!
On Wednesday, March 20, 2013 10:02:53 PM UTC-7, Francois Valentine wrote:
>
> So i added a prerender callback to maya using this
> cbid = OpenMayaUI.MUiMessage.add3dViewPreRenderMsgCallback ("modelPanel1",
> ViewportCallback, self)
>
> and inside i am trying to draw some points.
> it works fine except for one thing
> i obtain my matrices using this:
> projection = OpenMaya.MMatrix()
> modelView = OpenMaya.MMatrix()
> view.projectionMatrix(projection)
> view.modelViewMatrix(modelView)
> and i do indeed get the matrices that i want but the problem occurs when i
> rotate my viewport. the modelview matrix doesn't seem to get updated
> properly.
> if i try to move an object in the scene, the matrix receives the update
>
> what's going on here? is there a way to force the update? or should i be
> querying the matrices from somewhere else?
> i tried to obtain them directly from opengl and i just received an
> identity matrix so i'm guessing that's no good either.
>
> any info would be appreciated
> cheers
>
>
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/0ee0db0e-d7d4-4f8e-b74f-377ca844b056%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.