No More Retake

3DCG屋さん向けTips&Referenceサイト

メニュー

Maya:車輪でリグ(失敗3)

※ 注意 ※
この記事のリグは失敗例です。
記事のとおり作ると、記事の通り失敗します。
それでもよいという天の邪鬼な方に向けておくる、”Mayaで作る車輪リグ考察(失敗編3)


そろそろ成功例だけ載せてくれ、とお叱りを頂きそうな今日この頃。
それでも載せます失敗例。
前回、オブジェクトスペースを使った作戦は、方向転換時の挙動に難あり。あえなく廃棄。

今回は考え方を変えて、1フレームあたりの移動距離から回転角を求める方法をとることにしました。
毎フレームごと、移動距離から角度を計算し、足してゆきます。
イメージはこんな感じ。


Gear_02Gear_03またこれだけでは前進しているのか、後退しているのかの判別がつかないので、進む方向の指針となるガイドも追加します。イメージはこんな感じ。Gear_04

以上、これらをMayaで実装しました。(Pymel)

import pymel.core as pm

#車輪オブジェクト作成
oObj = pm.polyCylinder(n="Wheel_GEO", r=5, h=1,sz=1)[0]
oObj.rotate.set(90,0,0)

#回転制御用グループ作成
oRot = pm.group(n="Rot")

#コントローラ作成 配置
oCtr = pm.curve( d=1, p=[(-5, 6, -2.5), (0, 6,-2.5), (0 ,6 ,-5), (7 ,6 ,0), (0 ,6 ,5), (0, 6 ,2.5), (-5, 6 ,2.5), (-5, 6 ,-2.5)], k=[ 0,1,2,3,4,5,6,7] ,n="CTR")
pm.makeIdentity( apply=True )

#TOPグループ作成
oTOP = pm.group(n="TOP")
pm.parent(oRot, oCtr)

#Directionコントローラ
oDir = pm.curve( d=1, p=[( -0.6, 0 , -1 ), (-0.6, 0, 1), (1.2, 0, 0), (-0.6, 0 ,-1)], k=[ 0,1,2,3] ,n="Dir")
oDir.translate.set(10,0,0)
pm.parent(oDir, oTOP)
#コンストレイン
pm.parentConstraint("CTR", "Dir", mo=True)

#距離は測るヤツ
oStartNull = pm.spaceLocator( p=(0, 0, 0))
pm.hide()
oEndNull = pm.spaceLocator( p=(0, 5, 0))
pm.hide()
oDst = pm.distanceDimension( oStartNull, oEndNull)
pm.hide()
pm.parent(oStartNull, oEndNull, oDst, oObj)

#expression 実装
expName = "Wheel_SampleEXP03"
exp = "//1フレーム前の位置(global変数)n"
exp += "global vector $oldPos = <<0>>;;nn"

exp += "//初期化n"
exp += "int $frm = frame;n"
exp += "float $rot = 0;n"
exp += "int $dir = 1;nn"

exp += "//1フレームあたりの移動距離n"
exp += "float $dx = `getAttr -time $frm CTR.tx` - `getAttr -time ($frm-1) CTR.tx`;n"
exp += "float $dz = `getAttr -time $frm CTR.tz` - `getAttr -time ($frm-1) CTR.tz`;n"
exp += "$distance = sqrt($dx*$dx + $dz*$dz);n"

exp += "//進んだ方向を判定n"
exp += "float $dx2 = `getAttr -time ($frm+1) CTR.tx` - `getAttr -time $frm Dir.tx`;n"
exp += "float $dz2 = `getAttr -time ($frm+1) CTR.tz` - `getAttr -time $frm Dir.tz`;n"
exp += "$distance2 = sqrt($dx2*$dx2 + $dz2*$dz2);n"
exp += "if ($distance2 > 10){n"
exp += " $dir = -1;n"
exp += "}else{n"
exp += " $dir = 1;n"
exp += "}nn"
exp += "//車輪の半径を取得n"
exp += "$r = distanceDimensionShape1.distance;nn"
exp += "//移動に応じた回転角を計算n"
exp += "$rot = rad_to_deg($distance / $r) * $dir;n"
exp += "Rot.rotateZ -= $rot;n"

pm.expression(string = exp,  name = expName)

pm.cycleCheck( e=0)

長いですが、コレをMayaで実行するとサンプルシーンが作成されます。
動かしていろいろ試してみます。
前回、問題だった車輪の向き変更時の問題は改善されました。
前進も後退もバッチリです。
モーションパスにも対応しました。

が、なんということでしょう。
スライド(ドリフト)時、車輪が回転してしまっています。
それ以外はだいじょぶそうなのに・・・。

今回の方法だと、軸とか関係なし問答無用で移動距離から角度を求めるので、この問題が起きたと思われます。
・・・あちらを立てればこちらが立たず。

移動距離から進行方法ベクトルの成分だけ抽出出来れば・・・。

切り替えて、次!

2へ戻る Maya:車輪でリグ(了)へ

Related Posts Plugin for WordPress, Blogger...

関連記事

  1. 2019.09.04

    Maya:dirmap(MEL)
  2. 2012.06.29

    Maya:Input List

コメントをお待ちしております

このサイトについて

3DCG Tipsサイト。Houdiniの記事が多めです。

RSS

follow us in feedly

Archives

  • 2024 (1)
  • 2023 (2)
  • 2022 (9)
  • 2021 (14)
  • 2020 (46)
  • 2019 (17)
  • 2018 (33)
  • 2017 (29)
  • 2016 (36)
  • 2015 (64)
  • 2014 (54)
  • 2013 (60)
  • 2012 (55)

スポンサードリンク

言語切り替え

  • English (United States)
  • 日本語

スポンサードリンク

言語切り替え

  • English (United States)
  • 日本語

Houdiniを使えるようになる本


Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /usr/home/nomorere/nomoreretake.net/wordpress/wp-content/themes/n1-custom/functions/social.php on line 132

Warning: file_get_contents(): Failed to enable crypto in /usr/home/nomorere/nomoreretake.net/wordpress/wp-content/themes/n1-custom/functions/social.php on line 132

Warning: file_get_contents(http://api.facebook.com/restserver.php?method=links.getStats&urls=http%3A%2F%2Fnomoreretake.net%2F2013%2F12%2F16%2Fmaya03%2F): failed to open stream: operation failed in /usr/home/nomorere/nomoreretake.net/wordpress/wp-content/themes/n1-custom/functions/social.php on line 132

Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /usr/home/nomorere/nomoreretake.net/wordpress/wp-content/themes/n1-custom/functions/social.php on line 132

Warning: file_get_contents(): Failed to enable crypto in /usr/home/nomorere/nomoreretake.net/wordpress/wp-content/themes/n1-custom/functions/social.php on line 132

Warning: file_get_contents(http://api.b.st-hatena.com/entry.count?url=http%3A%2F%2Fnomoreretake.net%2F2013%2F12%2F16%2Fmaya03%2F): failed to open stream: operation failed in /usr/home/nomorere/nomoreretake.net/wordpress/wp-content/themes/n1-custom/functions/social.php on line 132