【问题标题】:How to create an MPxTransform node in Maya with a bounding box?如何在 Maya 中使用边界框创建 MPxTransform 节点?
【发布时间】:2015-08-11 12:47:12
【问题描述】:

在 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();
};

【问题讨论】:

    标签: c++ transform nodes maya bounding-box


    【解决方案1】:

    如果要写插件,需要实现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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-18
      • 1970-01-01
      • 2017-03-18
      • 1970-01-01
      • 1970-01-01
      • 2015-05-28
      • 1970-01-01
      • 2013-05-16
      相关资源
      最近更新 更多