1

I want to create a NURBS curve in Maya through a MEL script, bind it to my plugin and simply update the CVs in the plugin (and in the viewport). The problem is that I don't think it's possible to read and write to the same shape. Here is the MEL code:

curve -p 0 10 0 -p 5 0 0 -p 5 0 5 -p 0 0 5;
createNode FurrySystemNode -n furry;
connectAttr time1.outTime furry.time;
connectAttr curveShape1.local furry.input_curve;
connectAttr furry.output_curve curveShape1.create

Where input_curve and output_curve are typed attributes in the plugin. It fails when trying to create the MFnNurbsCurve because curve_obj is null. If I write to another shape as output it works just fine.

MStatus FurrySystemNode::compute(const MPlug& plug, MDataBlock& data) {
  if (plug == output_curve) {
    cout << "Computing input_curve\n";

    MStatus stat;
    MDataHandle handle = data.inputValue(input_curve, &stat);
    MDataHandle output_handle = data.outputValue(output_curve, &stat);
    McheckErr(stat, "Failed at getting data.inputValue\n");
    MObject curve_obj = handle.data();

    MFnNurbsCurve curve_fn(curve_obj, &stat);
    McheckErr(stat, "Failed at creating the MFnNurbsCurve function set\n"); // Fails here

    MPointArray cvs;
    stat = curve_fn.getCVs(cvs, MSpace::kWorld);
    for (int i = 0; i < cvs.length(); i++) {
      cvs[i] += MPoint(i, 0, 0);
    }

    curve_fn.setCVs(cvs, MSpace::kWorld);
    curve_fn.updateCurve(); // Don't think this one is needed
    output_handle.set(curve_obj);
    stat = data.setClean(plug);
    McheckErr(stat, "Failed at cleaning data\n");
  }
  return MS::kSuccess;
}

Any ideas?

novalain
  • 2,181
  • 19
  • 36
  • What are you trying to achieve. Are you trying to simulate physics on the curve over time? (I'm guessing by the name furrySystem ;) If so I think you should use one input curve to represent the initial state, then keep track of the previous frame positions and velocities in private data in your plugin. Then you can update an output curve every frame. Let me know if that's the case and I'll post an answer with some sample code. – Julian Mann Dec 12 '16 at 20:21
  • Hey Julian, thanks for your reponse. Yes I was trying to simulate physics over time, The thing I totally misunderstood is that writing to the same shape as input and output doesn't make any sense in Maya. This is because of the DAG system I guess and maya pulls data rather than pushes it and therefore output needs to be something else. Anyhow I got it working by setting `output_curve` to some dummy curve – novalain Dec 21 '16 at 09:03

0 Answers0