一半君的总结纸

听话只听一半君

#89 如何只用一个快捷键切换 ‘Show’ Option (或者其他模式)?

通常采取的方法是对当前state的值和1使用异或( XOR)操作, 例如:

$state = ( $state || 1 ) && !( $state && 1 );

(上面写这么长是因为 Maya 没有 XOR function)
PS: 其实lz没看懂这是要干嘛,上网搜了下XOR应该等效于
A XOR B = ( A AND (NOT B) ) OR ( (NOT A) AND B)

对于只是 on|off 状态切换的简单情况, 只需要在值的前面加上非操作符( NOT operator)即可 ( 在MEL里是’!’):

$newstate = !$oldstate;

所以, 切换当前modelPanel里的joints显示状态的 MEL 可以这么写:

// 找到当前 focus 所在的panel
$currentPanel = `getPanel -withFocus`;

//确认这个panel是一个 modelPanel
string $panelType = `getPanel -to $currentPanel`;
if ($panelType == "modelPanel")
{
  // 切换 Joint visibility 的状态
  modelEditor -e -joints ( !`modelEditor -q -joints $currentPanel` ) $currentPanel;

  // or...

  // 切换 X-Ray mode 的状态
  modelEditor -e -xray ( !`modelEditor -q -xray $currentPanel` ) $currentPanel;
}

如果你需要在0和一个不是1的值之前切换:

$newstate = !$oldstate * $setValue;

比如想在 0 和 2之间切换:

int $state = 0;
int $setValue = 2;

$state = !$state * $setValue;
// Result: 2 //
$state = !$state * $setValue;
// Result: 0 //

如果想在两个非零的值之间切换, 比如3 和 5 :

int $state;
int $stateLoValue = 3;
int $stateOffset = 2;  // 两个值之间的差

$state = ( !( $state - $stateLoValue ) * $stateOffset ) + $stateLoValue;
// Result: 3 //
$state = ( !( $state - $stateLoValue ) * $stateOffset ) + $stateLoValue;
// Result: 5 //

Related How-To’s

Monday, May 21, 2001

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: