【发布时间】:2015-06-01 08:27:19
【问题描述】:
我目前正在开发一个 Maya 插件。如何设置每次在场景中更改帧号/当前时间时触发的回调?
我查看了 MSceneMessage 类,但它似乎不包含我要查找的内容。
谢谢。
【问题讨论】:
标签: c++ events callback message maya
我目前正在开发一个 Maya 插件。如何设置每次在场景中更改帧号/当前时间时触发的回调?
我查看了 MSceneMessage 类,但它似乎不包含我要查找的内容。
谢谢。
【问题讨论】:
标签: c++ events callback message maya
您可以使用MEventMessage 在每次帧/当前时间更改时设置回调。代码胜于雄辩,所以这里有一些代码,其中穿插了 cmets 来说明如何设置:(不耐烦的先用 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);
scriptJob 命令中)列出的事件可以与MEventMessage 一起使用。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;
};
// 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;
}
【讨论】:
此外,根据应用程序,您可以创建一个调用 arbitray python/mel 的表达式(包括插件中的 MPXCommand)。
【讨论】: