maya python API 2.0 , getPointsAtUV

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

 
Thread Tools Search this Thread Display Modes
  1 Week Ago
maya python API 2.0 , getPointsAtUV

Hello,
I am trying to get the XYZ point on a mesh at an UV with python 2.0 API (maya 2017). I am hoping it is faster than before where you would have to iterate over every face.

From the maya help:
Added theMFnMesh :: getPointsAtUV()function, which returns the positions of the points at the given UV value on the mesh.This function provides better performance for getting points at UV coordinates thanMItMeshPolygon :: pointAtUV().



But somehow i cant get it to work, here is my code.


import maya.api.OpenMaya as OpenMaya #python 2.0 API
selection = OpenMaya.MSelectionList()
selection.add('pPlane1')
nodeDagPath = selection.getDagPath(0)
mfnMesh = OpenMaya.MFnMesh(nodeDagPath)
#faces=mfnMesh.numPolygons
u=0.5
v=0.5
p=mfnMesh.getPointsAtUV(u, v, space=OpenMaya.MSpace.kObject, uvSet='map1', tolerance=0.0)
print p


please let me know what i am doing wrong.

Last edited by mfg : 1 Week Ago at 02:29 PM.
 
  6 Days Ago
The error message could certainly be more helpful, but the 'Unexpected Internal failure' is saying that it couldn't find a match. Try a more flexible (non-zero) tolerance like 1e-5. Setting the tolerance to 0.0 is requesting an exact match and floating point numbers don't always lend themselves well to that kind of rigidity.

import maya.api.OpenMaya as OpenMaya #python 2.0 API
selection = OpenMaya.MSelectionList()
selection.add('pPlane1')
nodeDagPath = selection.getDagPath(0)
mfnMesh = OpenMaya.MFnMesh(nodeDagPath)
#faces=mfnMesh.numPolygons
u=0.5
v=0.5
p=mfnMesh.getPointsAtUV(u, v, space=OpenMaya.MSpace.kObject, uvSet='map1', tolerance=1e-5)
print p
 
  6 Days Ago
Thank you Keilun,
The error message was(kFailure): Unexpected Internal Failure

Changing the tolerance did the trick in most cases, but it still fails too many times.
I changed the tolerance to 0.1, that helps a little (see image below). With 0.9 it gets too irregular

With python API 1.0mfnMesh.getPointAtUV i get no errors. But it cycles over every face ID and is extremelyslow. Using a follicle node to set UV attribute and get position is faster then using python API 1.0.

Is the problem the "mfnMesh.getpointsAtUV" API 2.0 command? or is there something else that i am missing?
Speed wise it is extremely fast compared to what i used before, that's why i would like to get it to work.



import maya.api.OpenMaya as OpenMaya #python 2.0 API
import maya.cmds as mc

def getPoint(u,v,meshname):
  selection = OpenMaya.MSelectionList()
  selection.add(meshname)
  nodeDagPath = selection.getDagPath(0)
  mfnMesh = OpenMaya.MFnMesh(nodeDagPath)

  try:
    p=mfnMesh.getPointsAtUV(u, v, space=OpenMaya.MSpace.kWorld, uvSet='map1', tolerance=0.1)
    #print p
    result=[]
    result.extend( [p[1][0][0],p[1][0][1],p[1][0][2]] )
    return result
       
  except:
    pass

#-------------------------------------------------------------------------------------------------

u=40
v=40
sel=mc.ls(sl=True,fl=True)
   
for i in range(u):
  for j in range(v):
    r=getPoint((i/float(u)),(j/float(v)),sel[0])
    if r!=None:
      mc.spaceLocator(p=r)



 
  5 Days Ago
0.1 is a really high tolerance. You're essentially saying any UV + or - 0.1 of the value you specify will match. So if your input UV is (0.5, 0.5) then any point in the range (0.4,0.4) and (0.6,0.6) will match. So typically you want to lower this for a more precise catch. I suggested 1e-5 to start. Did that result in too many errors? If so, try lowering it to 1e-4 or 1e-3. Maya's mesh API should have float precision so those values should work.

It's possible there's a bug with Python API 2.0's MFnMesh.getPointsAtUV. When I ran it on a simple sphere, for some reason it returned 2 results, but both results were the same point. I don't understand why that is. Anyway, that's about all I can help with. If you're still having trouble with it, then I'd suggest logging a support case on it. I don't see you doing anything wrong in your code other than having either too low a tolerance (0.0) or too high a tolerance (0.1)

Last edited by Keilun : 5 Days Ago at 10:22 PM.
 
  5 Days Ago
Thanks for your help, I think its a bug.
Too bad...the command is so fast; if it only worked reliably, Will continue using the follicle node...

everything lower then 1e-5 i get no results going closer to 0.1 the better but gets very inaccuratelike you said. ill try to log it as a bug once the bug report website is back online...

Last edited by mfg : 5 Days Ago at 11:20 AM.
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 03:06 PM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.