I need to create custom node that in caclculation use closest point to nurbs surface. So far I found solution for finding closest point to mesh:

goal = OpenMaya.MPoint(data.inputValue(self.aGoal).asFloatVector())
inputColliderMesh = data.inputValue(self.aInputColliderMesh)             
meshColl = inputColliderMesh.asMesh()
mFnMeshColl = OpenMaya.MFnMesh( meshColl )  
closestPoint = OpenMaya.MPoint()    
#collider mesh as input      
space = OpenMaya.MSpace.kWorld
mFnMeshColl.getClosestPoint(goal, closestPoint, space)

Input Data:

    typedAttr = OpenMaya.MFnTypedAttribute()
    nAttr = OpenMaya.MFnNumericAttribute()
    ### shape.outMesh to -->>>   nodeName.inputColliderMesh ###
    meshAsInput.aInputColliderMesh = typedAttr.create('inputColliderMesh', 'inputColliderMesh', OpenMaya.MFnData.kMesh )
    meshAsInput.addAttribute( meshAsInput.aInputColliderMesh ) 

    meshAsInput.aGoal = nAttr.createPoint('goal', 'goal')
    meshAsInput.attributeAffects(meshAsInput.aGoal, meshAsInput.aOutput)

I tried to recreate procedures form C++ example but I'm not experienced in that language and I got stuck. 

second question is how to get info about normal vector in that point.

any python examples will be helpfull :) regards, k.
Quote 0 0
What exactly is giving you trouble ?

As for retrieving the surface normal:
Quote 0 0
The biggest issue is that I have no experience in C++, so debugging etc. will be terrible. I have plans to learn that language (and maya api) but right now I need to create working prototype of maya node.
What I need is some example how to load Nurbs into node and apply '.closestPoint' or  '.getClosestPoint' .
for polyMesh I pasted before:
1. I create 'MFnData.kMesh' :
typedAttr.create('inputColliderMesh', 'inputColliderMesh', OpenMaya.MFnData.kMesh ).  And connect my 'meshShape.outMesh' to it.
2. Load input 'asMesh' :
meshColl = inputColliderMesh.asMesh()
mFnMeshColl = OpenMaya.MFnMesh( meshColl )  
3. Now I have all mesh data to get closest Point :
 mFnMeshColl.getClosestPoint(goal, closestPoint, space)

I cannot find method or example in Python how to get the same result on NURBS surface. In standard maya Closest Point on Surface node as input for NURBS I need to plug:
surfaceShape.WorldSpace[0]  ->  node.inputSurface.
How to prepare that data to getClosestPoint() and what is correct format for that procedure.


Quote 0 0

# work around maya python api nonsense
uu = om.MScriptUtil()
pu = uu.createFromDouble(0.0)
pu = uu.asDoublePtr()
uv = om.MScriptUtil()
pv = uv.createFromDouble(0.0)
pv = uv.asDoublePtr()

# get dag path to nurbs surface
sl = om.MSelectionList()
dp = om.MDagPath()
sl.getDagPath(0, dp)

fn = om.MFnNurbsSurface(dp)

# get the closest point on surface to provided point
p = om.MPoint(1,0,0)
cpos = fn.closestPoint(p)
# get U and V parameters from the point on surface
fn.getParamAtPoint(cpos, pu, pv)
u = uu.getDouble(pu)
v = uv.getDouble(pv)
# get normal at U and V parameters
n = fn.normal(u, v)
print n.x, n.y, n.z
Quote 1 0
oh thank you very much pshipkov, you saved my life :).
I'm curious about if I can change this part :


to have acces to that string and have ability to change connection in node editor.  
it is not important right now, becouse I've already have all data for making a working prototype :)


Quote 0 0