小技巧, 如何保持DG节点之间的连接不被破坏或者不被创建
2013-07-05 11:02
309 查看
如果你有节点A 和 B,并且他们这样相连 A.output -> B.input ,如果你希望保持这个连接不被删除,那么你可以考虑重载 MPxNode 中的两个虚函数 legalConnection 和 legalDisconnection 来实现这个目的。
重载这两个虚函数可以用来确定指定的接口之间的 连接/删除连接 是否被允许,当这个节点上的连接被建立或者删除的时候,Maya都会先调用这个虚函数来确定这个操作是否合法。让我们来看一个例子:
如果我希望 NodeForTest.output 不能连接到任何节点 radius 属性上,那我就可以通过设置 isLegal 标志来阻止这个连接,
MStatus NodeForTest::legalConnection(const MPlug & plug, const MPlug & otherPlug, bool asSrc, bool & isLegal ) const
{
MFnDependencyNode node( otherPlug.node() );
MPlug radius = node.findPlug("radius");
if( plug == output && otherPlug == radius )
{
isLegal = false;
return MS::kSuccess;
}
return MS::kNotImplemented;
}
当用户试图调用Mel命令 (connectAttr -f NodeForTest1.output polyCylinder1.radius; )来创建连接的时候,Maya就会报错,并且提示:
// Error: line 1: Connection not made: 'NodeForTest1.output' -> 'polyCylinder1.radius'. Source node will not allow the connection. //
// Error: line 1: The attribute 'NodeForTest1.output' cannot be connected to 'polyCylinder1.radius'. //
同样的,如果我们设置了删除 NodeForTest.output 到任何节点的height属性为非法的话,那么我们就能保持这个连接不被破坏,
MStatus NodeForTest::legalDisconnection( const MPlug & plug, const MPlug & otherPlug, bool asSrc, bool & isLegal ) const
{
MFnDependencyNode node( otherPlug.node() );
MPlug height = node.findPlug("height");
if( plug == output && otherPlug == height )
{
isLegal = false;
return MS::kSuccess;
}
return MS::kNotImplemented;
}
当用户试图通过disconnectAttr NodeForTest1.output polyCylinder1.height;来删除该连接时,Maya会阻止该行为,并且提示:
// Result: Can not disconnect. //
# Error: line 1: Connection not made: 'NodeForTest1.output' -> 'polyCylinder1.height'. Source node will not allow the disconnection. #
重载这两个虚函数可以用来确定指定的接口之间的 连接/删除连接 是否被允许,当这个节点上的连接被建立或者删除的时候,Maya都会先调用这个虚函数来确定这个操作是否合法。让我们来看一个例子:
如果我希望 NodeForTest.output 不能连接到任何节点 radius 属性上,那我就可以通过设置 isLegal 标志来阻止这个连接,
MStatus NodeForTest::legalConnection(const MPlug & plug, const MPlug & otherPlug, bool asSrc, bool & isLegal ) const
{
MFnDependencyNode node( otherPlug.node() );
MPlug radius = node.findPlug("radius");
if( plug == output && otherPlug == radius )
{
isLegal = false;
return MS::kSuccess;
}
return MS::kNotImplemented;
}
当用户试图调用Mel命令 (connectAttr -f NodeForTest1.output polyCylinder1.radius; )来创建连接的时候,Maya就会报错,并且提示:
// Error: line 1: Connection not made: 'NodeForTest1.output' -> 'polyCylinder1.radius'. Source node will not allow the connection. //
// Error: line 1: The attribute 'NodeForTest1.output' cannot be connected to 'polyCylinder1.radius'. //
同样的,如果我们设置了删除 NodeForTest.output 到任何节点的height属性为非法的话,那么我们就能保持这个连接不被破坏,
MStatus NodeForTest::legalDisconnection( const MPlug & plug, const MPlug & otherPlug, bool asSrc, bool & isLegal ) const
{
MFnDependencyNode node( otherPlug.node() );
MPlug height = node.findPlug("height");
if( plug == output && otherPlug == height )
{
isLegal = false;
return MS::kSuccess;
}
return MS::kNotImplemented;
}
当用户试图通过disconnectAttr NodeForTest1.output polyCylinder1.height;来删除该连接时,Maya会阻止该行为,并且提示:
// Result: Can not disconnect. //
# Error: line 1: Connection not made: 'NodeForTest1.output' -> 'polyCylinder1.height'. Source node will not allow the disconnection. #
相关文章推荐
- 如何让ssh连接服务器或者sshtunnel保持连接呢?
- 如何创建数据源进行与数据库的连接
- SVN如何从创建一个分支或者标记
- Java 如何证明加载类的动作仅发生一次。证明该类的第一个实体的创建或者对static成员的访问都有可能引起加载
- PS文件和AI文件之间如何保持分层相互导入?
- 如何创建一个映射驱动器使用的网络连接对话框
- 在SQL Server 中,如何实现DBF文件和SQL Server表之间的导入或者导出?
- win8如何创建虚拟网卡-图文演示,连接到GNS3的云模块
- 【未来研究】城市云脑是互联网云脑的节点,城市云脑之间如何互补与支撑
- VB编程的一些小技巧 - ado如何连接oracle
- 服务器上传,时间超时 tomcat 如何设置保持连接
- 开发小技巧: 如何在jQuery中禁用或者启用滚动事件.scroll
- Android中如何使用Intent在Activity之间传递对象[使用Serializable或者Parcelable]
- 如何创建一个Tab bar Application (xcode 4.2中或者代码的方式)
- Eclipse ADT 开发Android APP,如何在多个连接设备之间选择卸载测试APP的设备?
- Nginx代理webSocket经常中断的解决方案, 如何保持长连接
- 虚幻4如何通过C++创建UObject或者UClass
- 如何让secureCRT保持连接不端开
- PPC中如何判断网络已经连接或者断开(转)
- EXT.NET如何动态的创建树形节点