There's a print statement in the compute I forgot to nuke before
posting - please do so, it slows things down. :)

On Feb 12, 12:05 pm, jasonosipa <jason.os...@gmail.com> wrote:
> This works, now, thanks to ALL!!  I took out some features of the C
> qWrap to simplify the debugging process, but I'll add those back in
> eventually, and post results here.
>
> import sys
> import maya.OpenMaya as om
> import maya.OpenMayaMPx as omMPx
>
> nodeName = "qWrap"
> nodeId = om.MTypeId( 0x123457 )
>
> class qWrapNode( omMPx.MPxNode ):
>
>   aSourceShape  = om.MObject()
>   aCollider     = om.MObject()
>   aMaxDistance  = om.MObject()
>   aOutShape     = om.MObject()
>
>   def __init__ ( self ) :
>     omMPx.MPxNode.__init__( self )
>
>   def compute( self, plug, data ):
>
>     if ( plug != qWrapNode.aOutShape ):
>       return om.kUnknownParameter
>
>     sourceMesh   = data.inputValue( qWrapNode.aSourceShape )\
>                        .asMesh()
>     sourceFnMesh = om.MFnMesh( sourceMesh )
>
>     print type( sourceFnMesh )
>
>     maxDist = data.inputValue( qWrapNode.aMaxDistance )
>     maxDist = maxDist.asFloat()
>
>     sources    = om.MPointArray()
>     outPoints  = om.MPointArray()
>
>     sourceFnMesh.getPoints(  sources,    om.MSpace.kWorld )
>     sourceFnMesh.getPoints(  outPoints,  om.MSpace.kWorld )
>
>     targetMesh   = data.inputValue( qWrapNode.aCollider ).asMesh()
>     targetFnMesh = om.MFnMesh( targetMesh )
>
>     mainCount    = sources.length()
>
>     getVector = om.MVector()
>
>     for j in range( 0, mainCount ):
>
>       raySource    = om.MFloatPoint( sources[ j ][0],
>                                      sources[ j ][1],
>                                      sources[ j ][2] )
>
>       sourceFnMesh.getVertexNormal( j,
>                                     False,
>                                     getVector,
>                                     om.MSpace.kWorld )
>
>       rayDirection = om.MFloatVector( getVector )
>       rayDirection = rayDirection.normal()
>       hitPoint     = om.MFloatPoint()
>       hitFacePtr   = None
>       idsSorted    = False
>       testBothDirs = False
>       faceIds      = None
>       triIds       = None
>       accelParams  = None
>       hitRayParam  = None
>       hitTriangle  = None
>       hitBary1     = None
>       hitBary2     = None
>
>       gotHit =  targetFnMesh.closestIntersection(
>                      raySource,
>                      rayDirection,
>                      faceIds,
>                      triIds,
>                      idsSorted,
>                      om.MSpace.kWorld,
>                      maxDist,
>                      testBothDirs,
>                      accelParams,
>                      hitPoint,
>                      hitRayParam,
>                      hitFacePtr,
>                      hitTriangle,
>                      hitBary1,
>                      hitBary2 )
>
>       if gotHit:
>         outPoints.set( j, hitPoint[0], hitPoint[1], hitPoint[2] )
>
>       else:
>         outPoints.set( j,
>                 raySource.x + ( rayDirection.x * maxDist ),
>                 raySource.y + ( rayDirection.y * maxDist ),
>                 raySource.z + ( rayDirection.z * maxDist ) )
>
>     # create output
>     outFnMeshData = om.MFnMeshData()
>     outMeshData   = outFnMeshData.create()
>     outFnMesh     = om.MFnMesh()
>     outFnMesh.copy( sourceMesh, outMeshData )
>     outFnMesh.setPoints( outPoints )
>
>     # store it
>     data.outputValue( qWrapNode.aOutShape ).setMObject( outMeshData )
>     data.setClean( qWrapNode.aOutShape )
>
> def nodeCreator () :
>   return omMPx.asMPxPtr ( qWrapNode() )
>
> def nodeInit():
>
>   nAttr = om.MFnNumericAttribute()
>   qWrapNode.aMaxDistance = nAttr.create( 'maxDistance', 'md',
>                            om.MFnNumericData.kFloat, 99.9 )
>   nAttr.setKeyable (1)
>   nAttr.setWritable(1)
>   nAttr.setReadable(1)
>   nAttr.setStorable(1)
>   nAttr.setSoftMin (0)
>   qWrapNode.addAttribute( qWrapNode.aMaxDistance )
>
>   tAttr = om.MFnTypedAttribute()
>   qWrapNode.aSourceShape = tAttr.create( 'sourceShape', 'ss',
>                            om.MFnData.kMesh )
>   tAttr.setStorable(0)
>   qWrapNode.addAttribute( qWrapNode.aSourceShape )
>
>   tAttr = om.MFnTypedAttribute()
>   qWrapNode.aCollider = tAttr.create ( 'collider', 'c',
> om.MFnData.kMesh )
>   tAttr.setStorable(1)
>   tAttr.setStorable(1)
>   qWrapNode.addAttribute( qWrapNode.aCollider )
>
>   tAttr = om.MFnTypedAttribute()
>   qWrapNode.aOutShape = tAttr.create( 'outShape', 'os',
>                         om.MFnData.kMesh )
>   tAttr.setStorable(0)
>   tAttr.setWritable(0)
>   qWrapNode.addAttribute( qWrapNode.aOutShape )
>
>   qWrapNode.attributeAffects( qWrapNode.aSourceShape,
>                               qWrapNode.aOutShape )
>
>   qWrapNode.attributeAffects( qWrapNode.aCollider,
>                               qWrapNode.aOutShape )
>
>   qWrapNode.attributeAffects( qWrapNode.aMaxDistance,
>                               qWrapNode.aOutShape )
>
> def initializePlugin( mobject ):
>   mplugin = omMPx.MFnPlugin ( mobject )
>   try:
>     mplugin.registerNode( nodeName, nodeId, nodeCreator, nodeInit )
>   except:
>     sys.stderr.write( 'Error loading' )
>     raise
>
> def uninitializePlugin ( mobject ):
>   mplugin = omMPx.MFnPlugin ( mobject )
>   try:
>     mplugin.deregisterNode ( nodeId )
>   except:
>     sys.stderr.write( 'Error removing' )
>     raise
>
> '''
> #Eg Mel to use this
>
> file -f -new;
> polyCube -w 3 -h 3 -d 3 -sx 1 -sy 1 -sz 1 -ax 0 1 0 -cuv 4 -ch 0;
> polySphere -r 1 -sx 35 -sy 35 -ax 0 1 0 -cuv 2 -ch 0;
> polySphere -r 1 -sx 35 -sy 35 -ax 0 1 0 -cuv 2 -ch 0;
> createNode qWrap;
> connectAttr -f pCubeShape1.worldMesh qWrap1.collider;
> connectAttr -f pSphereShape1.worldMesh qWrap1.sourceShape;
> connectAttr -f qWrap1.outShape pSphereShape2.inMesh;
> '''
--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to