Maya Deformer - Polygon face based deformation

Maya Deformer - Polygon face based deformation

bradley_henke
Enthusiast Enthusiast
999 Views
2 Replies
Message 1 of 3

Maya Deformer - Polygon face based deformation

bradley_henke
Enthusiast
Enthusiast

I'm overloading the compute function of my deformer as described in the Maya Documentation. My goal is to use MItMeshPolygon to deform my shape on a face by face basis. However, when my points don't seem to get updated when calling "setPoints()". I don't have any problems setting new positions using MFnMesh or MItGeometry. Is there any tricks that I might be missing?

0 Likes
Accepted solutions (1)
1,000 Views
2 Replies
Replies (2)
Message 2 of 3

bradley_henke
Enthusiast
Enthusiast

For completeness sake, this is what I'm trying to accomplish.

 

MStatus compute(const MPlug& plug, MDataBlock& data)
{
   if(plug.attribute() != outputGeom) return MStatus::kUnknownParameter;

   MObject thisNode = this->thisMObject();
   const unsigned int index = plug.logicalIndex();

   // Get input geometry
   MArrayDataHandle inputArrayData = data.inputArrayValue(input);
   inputArrayData.jumpToElement(index);
   MDataHandle inputData = inputArrayData.inputValue();
   MDataHandle inputGeomData = inputData.child(inputGeom);

   // Get output geometry plug
   MArrayDataHandle outputGeomArrayData = outputArrayValue(outputGeom);
   outputGeomArrayData.jumpToElement(index);
   MDataHandle outputGeomData = outputGeomArrayData.outputValue();

   // Copy input mesh to output mesh
   outputGeomData.copy(inputGeomData);

   // Get the mesh
   MObject mesh = outputGeomData.asMesh();

   // Now iterate over the mesh faces
   MItMeshPolygon iter(mesh);
   for(iter.reset(); !iter.isDone(); iter.next())
   {
      MPointArray points;
      iter.getPoints(points);
      for(unsigned int i = 0; i < points.length(); ++i)
         points[i] = MPoint(10.0, 10.0, 10.0);
      iter.setPoints(points);
   }

   // Clean the datablock
   data.setClean(plug);
}

 

0 Likes
Message 3 of 3

bradley_henke
Enthusiast
Enthusiast
Accepted solution

I think this is a bug (please correct me if I'm wrong, or if I've made a silly mistake). MItMeshPolygon::setPoints() does not work for me, but MItMeshPolygon.setPoint() successfully updates the point. I'm currently using Maya 2015 Extension 1 on Linux.

 

// DOES NOT WORK
MItMeshPolygon iter(mesh);
for(iter.reset(); !iter.isDone(); iter.next())
{
   MPointArray points;
   iter.getPoints(points);
   for(unsigned int i = 0; i < points.length(); ++i)
   {
      points[i] += points[i] + MPoint(0.0, 10, 0.0);
   }
   iter.setPoints(points);
}


// THIS WORKS
MItMeshPolygon iter(mesh);
for(iter.reset(); !iter.isDone(); iter.next())
{
      MPointArray points;
   iter.getPoints(points);
   for(unsigned int i = 0; i < points.length(); ++i)
   {
      MPoint newPoint = points[i] + MPoint(0.0, 10, 0.0);
      iter.setPoint(newPoint, i);
   }
}

 

0 Likes