So, there really was something wrong with the intersection line, (I
did have Echo All and Stack Trace, and Line numbers visible, I only
posted the information that seemed pertinent).  I never did figured
out what it was, so I just gave up and went to
MFnMesh.closestIntersection, because I know how to make that work, and
I'll get the same information back.  Now, the whole thing seems to be
running great until the very very very end, where I try to "set" the
outMesh just like in qWrap, but it poops...  Here's the entire
compute:

def compute( self, plug, data ):

  if ( plug != qWrapNode.aOutShape ):
    return om.kUnknownParameter

  sourceMesh   = data.inputValue( qWrapNode.aSourceShape )\
                     .asMesh()
  sourceFnMesh = om.MFnMesh( sourceMesh )

  maxParam   = data.inputValue ( qWrapNode.aMaxDistance )
  maxDist    = maxParam.asFloat()

  sources    = om.MPointArray()       # where to shoot rays from
  outPoints  = om.MPointArray()       # where they hit
  directions = om.MFloatVectorArray() # direction to shoot rays

  sourceFnMesh.getPoints(  sources,    om.MSpace.kWorld )
  sourceFnMesh.getPoints(  outPoints,  om.MSpace.kWorld )
  sourceFnMesh.getNormals( directions, om.MSpace.kWorld )

  # create distances table - assign negative distance
  distances = om.MDoubleArray()
  distances.setLength( directions.length() )

  distances = [ -1 for i in range( 0, directions.length() ) ]

  targetsArrayHandle = data.inputArrayValue( qWrapNode.aTargetShapes )

  for i in range( 0, targetsArrayHandle.elementCount() ):

    targetsArrayHandle.jumpToElement( i )

    targetMesh    = om.MObject( targetsArrayHandle.inputValue()\
                      .asMesh() )
    #targetMesh   = targetsArrayHandle.inputValue().asMesh()
    targetFnMesh  = om.MFnMesh( targetMesh )
    intersections = om.MPointArray()

    for j in range( 0, directions.length() ):

      raySource    = om.MFloatPoint( sources[ j ][0],
                                     sources[ j ][1],
                                     sources[ j ][2] )

      rayDirection = om.MFloatVector( directions[ j ][0],
                                      directions[ j ][1],
                                      directions[ j ][2] )

      hitPoint = om.MFloatPoint()

      gotHit = targetFnMesh.closestIntersection(
                 raySource, rayDirection,
                 None, None, False,
                 om.MSpace.kWorld, maxDist,
                 False, None,
                 hitPoint,
                 None, None, None, None, None )

      if gotHit:

        delly    = om.MVector( sources[ j ] - hitPoint )
        distance = delly.length().asFloat()

        if ( ( distance < distances[ j ] )
        or (   distances[ j ] == -1 ) ):
          distances[ j ] = distance
          outPoints[ j ] = hitPoint

  # modify points by "amount" and "maxDistance"
  maxDistance     = data.inputValue( \
                         qWrapNode.aMaxDistance )\
                        .asDouble()

  amount = data.inputValue( qWrapNode.aAmount ).asDouble()

  for i in range( 0, outPoints.length() ):

    delly    = om.MVector( sources[ i ] - outPoints[ i ] )
    distance = delly.length()

    distMix = 1

    if ( distance != 0 ):
      distMix = min( 1, max( 0, maxDistance / distance ) )

      outPoints[ i ] =   sources  [ i ] \
                     + ( outPoints[ i ] - sources[ i ] ) \
                     *    distMix * amount

  # create output
  outFnMeshData = om.MFnMeshData()
  outMeshData   = outFnMeshData.create()
  outFnMesh     = om.MFnMesh()
  outFnMesh.copy( sourceMesh, outMeshData )
  outFnMesh.setPoints( outPoints )

  # store it
  data.outputValue( qWrapNode.aOutShape ).set( outMeshData )
  data.setClean( qWrapNode.aOutShape )



When I run that, I get this:

# Traceback (most recent call last):
#   File "C:/Documents and Settings/Jason Osipa/My Documents/
Production/osipaEntertainment/omen/pyScratch/qWrapNode.py", line 116,
in compute
#     data.outputValue( qWrapNode.aOutShape ).set( outMeshData )
#   File "C:\engserv\rbuild\194\build\wrk\optim\runTime\Python\Lib
\site-packages\maya\OpenMaya.py", line 8308, in <lambda>
#   File "C:\engserv\rbuild\194\build\wrk\optim\runTime\Python\Lib
\site-packages\maya\OpenMaya.py", line 34, in _swig_getattr
# AttributeError: set //

Help?  I can't seem to find an example of or documentation on
"setting" mesh data anywhere.
--~--~---------~--~----~------------~-------~--~----~
Yours,
Maya-Python Club Team.
-~----------~----~----~----~------~----~------~--~---

Reply via email to