Register Latest Topics
 
 
 


Reply
  Author   Comment  
KacperSoup

Asking for seconds
Registered:
Posts: 26
Reply with quote  #1 
Hello,
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:

Code:

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:
Code:

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

    meshAsInput.aGoal = nAttr.createPoint('goal', 'goal')
    meshAsInput.addAttribute(meshAsInput.aGoal)
    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. 
http://download.autodesk.com/us/maya/2011help/API/closest_point_on_nurbs_surface_cmd_8cpp-example.html



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






any python examples will be helpfull :) regards, k.
0
pshipkov

SOuP Jedi
Registered:
Posts: 4,639
Reply with quote  #2 
What exactly is giving you trouble ?

As for retrieving the surface normal:
http://download.autodesk.com/us/maya/2011help/API/class_m_fn_nurbs_surface.html#24e03ba1b74a08986e652e6b9e3dbf8a
0
KacperSoup

Asking for seconds
Registered:
Posts: 26
Reply with quote  #3 
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.


regards.
k.


0
pshipkov

SOuP Jedi
Registered:
Posts: 4,639
Reply with quote  #4 
Code:

# 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()
sl.add("nurbsSphereShape1")
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
0
KacperSoup

Asking for seconds
Registered:
Posts: 26
Reply with quote  #5 
oh thank you very much pshipkov, you saved my life :).
I'm curious about if I can change this part :
Code:

sl.add("nurbsSphereShape1")

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 :)


regards,
k.

0
Previous Topic | Next Topic
Print
Reply

Quick Navigation: