I am trying to write a little deformer,
Being fairly new to API I am still having trouble understanding the basic fundamentals,
I have a sourceMesh that I am connecting to my deformer node that I would like to use
as a driver. I would like to create a smoothed Mesh out of that sourceMesh, but the way I
have it now, its crashing MAYA.
I seem to be able to “query” and “print” the pointNumber of the sourceObject correctly,
but I can`t print the name / path of the sourceObject. It always returns an empty string.
And as mentioned when I try to generate a smooth object:
smoothMeshTransform = meshFn.generateSmoothMesh();
It crashes my Maya.
My guess is that it has to do with the MObject and the DataHandle.
So I think its data that I am passing around there, and not the actual object.
But my understanding of that is still vague and I don`t know how I can do what I want to
do. (smooth the sourceObject that is connected to the deformer node.)
Nico.
Here is my code, that I have:
//
// File: n_simpleDeform.cc
#include <maya/MPlug.h>
#include <maya/MFnPlugin.h>
#include <maya/MTypeId.h>
#include <maya/MPxDeformerNode.h>
#include <maya/MIOStream.h>
#include <maya/MIOStream.h>
#include <maya/MGlobal.h>
#include <maya/MDagPath.h>
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MPoint.h>
#include <maya/MPointArray.h>
#include <maya/MFloatArray.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFnMesh.h>
#include <maya/MFnMeshData.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnTypedAttribute.h>
class n_simpleDeform: public MPxDeformerNode
{
public:
n_simpleDeform();
virtual ~n_simpleDeform();
// virtual MStatus compute( const MPlug& plug, MDataBlock& data );
static void* creator();
static MStatus initialize();
virtual MStatus deform ( MDataBlock & data, MItGeometry & iterator, const MMatrix & matrix, unsigned int multiIndex);
MStatus convertPolyToSmooth(MObject meshObject, MDagPath &pathToSmooth);
static MTypeId id;
// Inputs
static MObject aBind;
static MObject aSrcMesh;
private:
unsigned int m_bound, m_boundPrev;
};
// Attributes first time defined
MTypeId n_simpleDeform::id( 0x8104D );
MObject n_simpleDeform::aBind;
MObject n_simpleDeform::aSrcMesh;
MStatus n_simpleDeform::initialize()
{
MFnNumericAttribute nAttr;
MFnTypedAttribute tAttr;
MStatus status;
// what coming in
aBind = nAttr.create( “bind”, “b”, MFnNumericData::kInt, 0 );
tAttr.setStorable(true);
tAttr.setKeyable(true);
tAttr.setReadable(true);
tAttr.setWritable(true);
tAttr.setCached(false);
status = addAttribute( aBind );
aSrcMesh = tAttr.create( "srcMesh", "smsh", MFnData::kMesh, MObject::kNullObj, &status );
tAttr.setStorable(false);
tAttr.setKeyable(false);
tAttr.setReadable(true);
tAttr.setWritable(true);
tAttr.setCached(false);
tAttr.setDisconnectBehavior( MFnAttribute::kReset );
status = addAttribute( aSrcMesh );
// what affects what
attributeAffects( aBind, outputGeom);
attributeAffects( aSrcMesh, outputGeom);
return MStatus::kSuccess;
}
//
/* THE DEFORMER PART */
//
MStatus n_simpleDeform::deform( MDataBlock& data, MItGeometry & iterator, const MMatrix & matrix, unsigned int multiIndex)
{
MStatus status = MS::kSuccess;
MStatus stat;
//////////////////////////////////////////////////////////////
// Create data handles for input data
/////////////////////////////////////////////////////////////
// input handles
MDataHandle dataHBind = data.inputValue( aBind );
MDataHandle dataHSrcMesh = data.inputValue( aSrcMesh );
// Variables
MDagPath pathToMesh;
MDagPath pathToSmoothMesh;
m_bound = dataHBind.asInt();
MObject srcMeshObj = dataHSrcMesh.asMesh();
if( srcMeshObj == MObject::kNullObj )
return MS::kSuccess;
MFnMesh scrMeshFn( srcMeshObj, &status );
if( status != MS::kSuccess )
return status;
// create a smooth poly from the srcMesh
convertPolyToSmooth( srcMeshObj, pathToSmoothMesh);
dataHBind.setClean();
return status;
}
///////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
///////////////////////////////////////////////////////////////////////////////////////////
MStatus n_simpleDeform::convertPolyToSmooth(MObject meshObject, MDagPath &pathToSmooth)
{
// Variables
MStatus status = MStatus::kSuccess;
MStatus stat;
MObject smoothMeshTransform;
//1 - First query the scrMesh
MFnMesh meshFn (meshObject);
// print the point number of the srcMesh
int numOfPoints = meshFn.numVertices();
MString txt1 = "ScrMesh has ";
txt1 += numOfPoints;
txt1 += " point!";
MGlobal::displayInfo( txt1 );
// print the name of the scrMesh
MFnDependencyNode nodeFn( meshObject );
MString txt = "The name of the mesh is: ";
txt += nodeFn.name();
MGlobal::displayInfo( txt );
// smooth the scrMesh - this is crashing Maya
//smoothMeshTransform = meshFn.generateSmoothMesh();
}
///////////////////////////////////////////////////////////////////////////////////////////
// STANDARD STUFF (initialize and creator, constructor, destructor,…)
///////////////////////////////////////////////////////////////////////////////////////////
/********************************************************************************************/
MStatus initializePlugin( MObject obj ) {
MStatus result;
MFnPlugin plugin( obj, “”, “1.0”, “Any”);
result = plugin.registerNode( “n_simpleDeform”, n_simpleDeform::id, n_simpleDeform::creator,
n_simpleDeform::initialize, MPxNode::kDeformerNode );
return result;
}
MStatus uninitializePlugin( MObject obj) {
MStatus result;
MFnPlugin plugin( obj );
result = plugin.deregisterNode( n_simpleDeform::id );
return result;
}
void* n_simpleDeform::creator() {
return new n_simpleDeform();
}
n_simpleDeform::n_simpleDeform() {
}
n_simpleDeform::~n_simpleDeform() {
}

