Hiya guys! cant figure out why this maya node is not computing the correct output geometry when i change the gravity attribute. The mesh is just staying in the same place, and not moving down. If anyone could give me a pointer that would be much appreciated!
`
class nodeTest : public MPxNode
{
public:
nodeTest() {};
virtual MStatus compute(const MPlug& plug, MDataBlock& data);
static void* creator();
static MStatus initialize();
public:
static const MTypeId id;
static MObject input_gravity;
static MObject input_mesh;
static MObject output_mesh;
private:
MPointArray _vertex_positions;
};
const MTypeId nodeTest::id( 0x00080052 );
MObject nodeTest::input_gravity;
MObject nodeTest::input_mesh;
MObject nodeTest::output_mesh;
void* nodeTest::creator()
{
return new nodeTest();
}
MStatus nodeTest::initialize()
{
MFnTypedAttribute tAttr;
MFnNumericAttribute nAttr;
MFnUnitAttribute uAttr;
MFnCompoundAttribute cAttr;
output_mesh = tAttr.create("outputMesh", "om", MFnMeshData::kMesh);
tAttr.setKeyable(true);
tAttr.setStorable(true);
tAttr.setReadable(true);
tAttr.setWritable(false);
addAttribute(output_mesh);
input_mesh = tAttr.create("inputMesh", "im", MFnMeshData::kMesh);
tAttr.setKeyable(false);
tAttr.setStorable(true);
tAttr.setReadable(true);
tAttr.setWritable(true);
addAttribute(input_mesh);
attributeAffects(input_mesh, output_mesh);
input_gravity = nAttr.create("gravity", "gr", MFnNumericData::kFloat, -10.0);
nAttr.setKeyable(true);
nAttr.setStorable(true);
addAttribute(input_gravity);
attributeAffects(input_gravity, output_mesh);
return MStatus::kSuccess;
}
MStatus nodeTest::compute(const MPlug& plug, MDataBlock& data)
{
if (plug == output_mesh)
{
float gravity = data.inputValue(input_gravity).asFloat();
MDataHandle input_mesh_handle = data.inputValue(input_mesh);
MDataHandle output_mesh_handle = data.outputValue(output_mesh);
MFnMesh output_mesh_fn;
MFnMeshData output_mesh_data;
MObject output_mesh_object = output_mesh_data.create();
output_mesh_fn.copy(input_mesh_handle.asMeshTransformed(), output_mesh_object);
output_mesh_fn.getPoints(_vertex_positions);
for (int i = 0; i < (int)_vertex_positions.length(); ++i)
{
_vertex_positions[i] += MPoint(0.0, gravity, 0.0);
}
output_mesh_fn.setPoints(_vertex_positions);
output_mesh_handle.set(output_mesh_object);
data.setClean(plug);
}
else
{
return MS::kUnknownParameter;
}
std::cout << "computing";
return MS::kSuccess;
}
`