如何在Maya中创建带有边界框的MPxTransform节点

How to create an MPxTransform node in Maya with a bounding box?

本文关键字:边界 MPxTransform 节点 Maya 创建      更新时间:2023-10-16

在cpp中,我正在寻找在Maya中创建带有边界框的MPxTransform节点的代码。但是,我的代码既没有在大纲中添加转换节点,也没有创建边界框。我错过了什么?

. cpp文件:

myClass::myClass() // Entry point: This one is executed
{
    myMPxTransformClass prox;
    MPxTransformationMatrix *transformMtrx;
    transformMtrx=prox.createTransformationMatrix();
// What is missing here to get the node registered in Maya and bounding box displayed ?
}
myMPxTransformClass::myMPxTransformClass()  // This one is executed
{
    MGlobal::displayInfo("MPx Initialized");
}
bool myMPxTransformClass::isBounded()  // This one is not called
{
    MGlobal::displayInfo("isBounded returned");
    return true;
}
MBoundingBox myMPxTransformClass::boundingBox()  // This one is not called
{
    MPoint p1,p2;
    p1=MPoint(-1,-1,-1);
    p2=MPoint(1,1,1);
    MGlobal::displayInfo("Bounding box returned");
    return MBoundingBox(p1,p2);
}

和相应的。h文件

class myMPxTransformClass : public MPxTransform
{
public:
    myMPxTransformClass();
    virtual ~myMPxTransformClass() {};
protected:
    virtual MBoundingBox boundingBox();
    bool isBounded();
};

如果要编写插件,则需要实现3个常用功能:

  1. initializePlugin,在加载插件时调用

  2. uninitializePlugin,当插件被卸载时调用Maya调用来创建对象的新实例,例如create节点

  3. creator, Maya调用创建对象的新实例,如createNode

这是一个示例代码:

#include "include/HelloWorldCmd.h"
#include <maya/MFnPlugin.h>
void* HelloWorld::creator() { return new HelloWorld; }
MStatus HelloWorld::doIt(const MArgList& argList) {
  MGlobal::displayInfo("Hello World!");
  return MS::kSuccess;
}
MStatus initializePlugin(MObject obj) {
  MFnPlugin plugin(obj, "Chad Vernon", "1.0", "Any");
  MStatus status = plugin.registerCommand("helloWorld", HelloWorld::creator);
  CHECK_MSTATUS_AND_RETURN_IT(status);
  return status;
}
MStatus uninitializePlugin(MObject obj) {
  MFnPlugin plugin(obj);
  MStatus status = plugin.deregisterCommand("helloWorld");
  CHECK_MSTATUS_AND_RETURN_IT(status);
  return status;
}

在这里你可以找到更多关于它的信息:

http://www.chadvernon.com/blog/resources/maya-api-programming/your-first-plug-in/