New Intersect API use

76 views
Skip to first unread message

Mathew Schwartz

unread,
Jun 20, 2017, 3:33:31 PM6/20/17
to python_in...@googlegroups.com
I am trying to convert some old code to start working in newer maya.  It seems the API has changed as it doesnt recognize intersect as a method anymore.  (http://download.autodesk.com/us/maya/2009help/api/class_m_fn_mesh.html#4f5a5cc3ab4834b8045239a3438930dc)

I would like to simply have a start position and direction.  Then check if that vector hits an object/polygon.  

Below is how the code used to be structured   

dag = nameToDag(mesh_name)
    meshFn = om.MFnMesh()
    meshFn.setObject( dag )
    #This is the Ray being shot
    
    raySource = om.MPoint(source[0])
    rayDirection = om.MVector(source[1])
 
    pointsValue = om.MPointArray()
    polygonIdsValue = om.MIntArray()
    spaceValue = 4
    toleranceValue =  0.01
    intersectionPoints = om.MFloatPointArray()
    
    ret = om.MFnMesh.intersect(meshFn, raySource, rayDirection.normal(),
            pointsValue, toleranceValue, spaceValue, polygonIdsValue )

Now I tried replacing it with: 

    meshFn.allIntersections( raySource,                  # raySource - where we are shooting the ray from.
                             rayDirection,               # rayDirection - the direction in which we are shooting the ray.
                             None,                       # faceIds - here, we do not care if specific faces are intersected)
                             None,                       # triIds - here, we do not care if specific tri's are intersected)
                             False,                      # idsSorted - here, we do not need to sort the faceId's or triId's indices.
                             om.MSpace.kTransform, # coordinate space - the mesh's local coordinate space.
                             float(9999),                # the range of the ray.
                             False,                      # testBothDirections - we are not checking both directions from the raySource
                             None,                       # accelParams - this object is not applicable here.
                             False,                      # sortHits - we do not need to sort the intersection points along the ray.
                             intersectionPoints,         # hitPoints - the array of points which have been intersected.
                             None,                       # hitRayParams - we do not need any parametric distances of the points along the ray.
                             None,                       # hitFaces - we do not need the id's of the faces intersected.
                             None,                       # hitTriangles - we do not need the id's of the triangles intersected.
                             None,                       # hitBary1s - we do not need the barycentric coordinates of the points within the triangles.
                             None,                       # hitBary2s - we do not need the barycentric coordinates of the points within the triangles.
                             toleranceValue              # tolerance - a numeric tolerance threshold which allow intersections to occur just outside the mesh.


but it is giving the error:

# Error: TypeError: file <maya console> line 100: function takes at most 11 arguments (17 given) #

Can anyone give a basic working example with a plane, or explain what the problem is?
Thanks

Alec Fredericks

unread,
Jun 29, 2017, 1:06:13 PM6/29/17
to Python Programming for Autodesk Maya
Hey Mat,
It looks like you might be mixing API 1.0 and 2.0. Take a look at t more updated version of the API example here:

It breaks down the API 1.0 & 2.0 differences. Your example above shows what is in the 1.0 API code, while a version of allIntersections with fewer arguments is in the 2.0 code.

Alec

Mathew Schwartz

unread,
Jun 30, 2017, 3:12:38 PM6/30/17
to python_in...@googlegroups.com
Hi Alec,

Thanks for that link, I will try to figure out what my issue is using that function.  

 However, in both examples they use "allIntersections".  My old code just used a function "intersect"  from here: http://download.autodesk.com/us/maya/2009help/api/class_m_fn_mesh.html#4f5a5cc3ab4834b8045239a3438930dc

If the link you gave has API1 and API2 with the same allIntersections method, do you know what is different than the intersect method I had been using.


--
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 python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/906c1fb1-7d4d-4851-99c1-fb52ef2475e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alec Fredericks

unread,
Jun 30, 2017, 6:23:47 PM6/30/17
to python_in...@googlegroups.com
I'll take a look at your coffee later today to see if anything jumps out.

To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python_inside_maya/LoFCOV_Ltss/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CADiWwnTmObippcEKATJNZSDy2SHD1%3DzSgfj_CwHQPfA5xgBJ7g%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages