gpt4 book ai didi

c++ - Maya Api 中的事件以捕获当前时间/帧更改

转载 作者:行者123 更新时间:2023-11-30 02:38:41 26 4
gpt4 key购买 nike


我目前正在开发一个 Maya 插件。我如何设置每次在场景中更改帧号/当前时间时触发的回调?
我查看了 MSceneMessage 类,但它似乎不包含我要查找的内容。
谢谢。

最佳答案

您可以使用 MEventMessage 设置每次时间范围/当前时间更改时的回调。代码胜于 Eloquent ,所以这里有一些代码和注释穿插在一起,以说明如何设置它:(对于不耐烦的人来说,TLDR 首先,完整的代码摘录将在下一节中提供)

简单描述:

不耐烦的代码摘要:

    // ...

// Our callback Id array to
// store the Ids of all our callbacks
// for later removal
MCallbackIdArray myCallbackIds;

// This is where the actual adding callback happens
// We register our callback to the "timeChanged" event
MCallbackId callbackId = MEventMessage::addEventCallback("timeChanged", (MMessage::MBasicFunction) MySampleCmd::userCB);

// ...

if(myCallbackIds.length() != 0)
// Make sure we remove all the callbacks we added
stat = MEventMessage::removeCallbacks(myCallbackIds);

带有注释的完整(大概)代码:

MySampleCommand.h

class MySampleCmd : public MPxCommand {
public:
MySampleCmd();
virtual ~MySampleCmd();

// Our callback - implemented as a static method
static void userCB(void* clientData);

MStatus doIt( const MArgList& );
MStatus redoIt();
MStatus undoIt();
bool isUndoable() const;
static void* creator();

public:

// Our callback Id array to
// store the Ids of all our callbacks
// for later removal
MCallbackIdArray myCallbackIds;
};

MySampleCommand.cpp(节选)

// Constructor
MySampleCmd::MySampleCmd() {

// Clearing our callback Id array
// for housekeeping
myCallbackIds.clear();
}

// Destructor
MySampleCmd::~MySampleCmd() {

// Make sure we remove all the callbacks we added
// Failing to do so will result in fatal error
if(myCallbackIds.length() != 0)

// Remove the MEventMessage callback
MEventMessage::removeCallbacks(myCallbackIds);
}

MStatus MySampleCmd::redoIt() {

// This is where the actual adding callback happens
// We register our callback to the "timeChanged" event
MCallbackId callbackId = MEventMessage::addEventCallback("timeChanged", (MMessage::MBasicFunction) MySampleCmd::userCB);

// Append the newly added callback's ID to our list of callback ids
// for future removal
myCallbackIds.append(callbackId);
return MS::kSuccess;
}

MStatus MySampleCmd::undoIt() {
MStatus stat;
if(myCallbackIds.length() != 0)
// Make sure we remove all the callbacks we added
stat = MEventMessage::removeCallbacks(myCallbackIds);
return stat;
}

// Our callback function
void SafeSelect::userCB(void* clientData) {
MGlobal::displayInfo( "Callback userCB called!\n" );
return;
}

关于c++ - Maya Api 中的事件以捕获当前时间/帧更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30568841/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com