【Autodesk Maya Bridge Creator】使用各種節點來rig 橋梁. Rigging bridges using various nodes

【Autodesk Maya Bridge Creator】使用各種節點來rig 橋梁. Rigging bridges using various nodes

 




嗨,這是在看完Rigging Dojo的 Bridge課程之後學到的東西,想要紀錄一下。


有興去的人可以去買來看看。


這整個教學的核心概念很簡單,就是motionPath節點的各種應用,整個rig的結構以及所有的控制器跟locator都圍繞著這個節點來建構。


最後的成品如底下影片展示,是一個完整的橋梁rig,我另外再自己寫了工具把它程序化,這也是最麻煩的地方,除此之外核心的概念非常簡單。



Hi, this is what I learned after watching Rigging Dojo's Bridge course and I wanted to record it.

For those interested, you can go and check it out.

The core concept of this entire tutorial is very simple, which is the various applications of the motionPath node. The entire rig's structure and all controllers and locators are built around this node.

The final product, as shown in the video below, is a complete bridge rig. I also wrote my own tool to procedural it, which was the most troublesome part. Other than that, the core concepts are very simple.






那麼底下就來記錄一下將這個教學程序化的過程之中、我所學到的新的東西,有些跟python有關、有些跟maya 節點的用法有關,希望對任何正在看這篇文章的人有所幫助。

So let me record the process of proceduralizing this tutorial that I learned and some new things I learned along the way. Some are related to Python, while others are related to the usage of Maya nodes. I hope it will be helpful to anyone reading this article.



Bridge Rig整體結構/Bridge Rig Overall Structure


首先先簡單拆解一下rig的結構。


這個rig主要是由4條cv線來帶動的,MainCtrl 透過cluster來變形cv線,而控制器跟joint則是透過motionPath節點被cv線帶動。


下面的影片展示的是,MainCtrl控制的cluster,可以看到我把下面兩條cv線用同一個cluster來帶動,如果是為了更貼近真實狀態可以像上面的cv一樣用兩個。


First, let's break down the structure of the rig.

This rig is mainly driven by 4 cv curves. The MainCtrl deforms the cv curves through clusters, while the controllers and joints are driven by the cv curves through motionPath nodes.

The following video shows the cluster controlled by MainCtrl. You can see that I use the same cluster to drive the two cv curves below. If you want to be closer to reality, you can use two clusters like the cv curves above.








至於剩下的模型以及控制器,就是透過locator來帶動。

可以從底下的影片看到我是將控制器放在locator底下,這些locator會透過motionPath被cv帶動,因此控制器也會跟隨著移動,而控制器再帶動joints,如此一來就完整了整個結構。


As for the remaining models and controllers, they are driven by locators.

You can see from the following video that I put the controllers under locators. These locators are driven by motionPath through cv curves, so the controllers will also move accordingly, and the controllers will drive the joints. This completes the entire structure.











motionPath節點的Parametric Length開關/Parametric Length Switch in motionPath Node


在前面的Track Creator筆記有提到motionPath這個節點,這是一個可以幫助你讓物件跟隨curve線移動的節點,並且在curve線被拉伸時、物件的間距能夠保持同樣的數值!

這次的bridge rig用到最多的就是這個節點,以及它的Parametric Length開關。


使用motionPath節點讓物件跟隨cv線的接法如下。

記得要使用的是cv線的Shape節點!



In the earlier notes on Track Creator, we mentioned the motionPath node, which is a node that helps objects move along a curve, and keeps the distance between the objects the same when the curve is stretched!

The motionPath node and its Parametric Length switch were the most used nodes in this bridge rig.

The following is the method of using the motionPath node to make an object follow a cv curve.

Remember to use the Shape node of the cv curve!







下面的影片我們可以看到locator在兩條cv上面有不同的運動方式,他們唯一的差別就是motionPath上的Parametric Length開關。

如果取消勾選,那麼cv點在水平位移時,物件的間距不會被改變;反之如果打勾,那麼物件的間距就會被改變,這就是bridge rig最重要的選項,記得把它取消勾選。

這樣才有辦法做出橋梁在變形時、那種真實的扭曲方式!


In the following video, we can see that the locator has different motion paths on the two CV curves, and the only difference between them is the Parametric Length switch in the motionPath node.


If the switch is unchecked, the distance between objects will not change when the cv points move horizontally. If the switch is checked, the distance between objects will change. This is the most important option in the bridge rig, so remember to uncheck it.


Only by doing this can we create a realistic deformation of the bridge!





只要了解了Parametric Length開關的重要性,整個rig就已經完成一半了,剩下的部分就是把物件分配到cv線上、各自串上motionPath節點,然後再為cv線加上cluster以及控制器就可以完成效果不錯的bridge rig!

It can be said that understanding the importance of the Parametric Length option in the motionPath node is the key to completing the Bridge rig. The remaining part is to distribute objects to the CV curve, connect them to the motionPath node, add clusters and controllers to the CV curve, and the rig will be completed with a good effect.



Python zip():將多個list結合起來做迴圈/Combining multiple lists for looping


這是一個非常實用的python函數,可以將不同的序列list結合在一起做迭代。

如下面影片展示的,我們將兩個list用zip包裝在一起,這樣一來,兩個list中、相同index的物件就可以一起被處理並進行各種操作,這個函式對於想要「使用一個迴圈完成不同list之間的串聯」的情況非常好用!



This is a very useful Python function that can combine different sequence lists together for iteration.

As shown in the video below, we can use the zip function to wrap two lists together. This way, objects at the same index in both lists can be processed together and various operations can be performed. This function is very useful for situations where you want to "use a loop to concatenate different lists."









cmds.ikHandle()創建的是一個list


這是我在程序化bridge rig中遇到的一個問題,就是當我們使用cmds.ikHandle()這個命令時,maya其實創造了一個list,其中包含ikHandle以及effector!

所以如果我們想要將這個命令產生的物件進行其他操作,記得要指定index,不然會出現錯誤!

如下面影片展示,ikHandle命令產生了一個list,IK[0]的物件是ikHandle,IK[1]的物件是effector,用到的時候還需要多多注意!

This is a problem I encountered in my programmatic bridge rig, which is that when we use the cmds.ikHandle() command, Maya actually creates a list that includes both the IK handle and the effector!

So if we want to perform other operations on the objects generated by this command, we need to specify the index, otherwise an error will occur!

As shown in the video below, the ikHandle command generates a list, where the object at IK[0] is the IK handle and the object at IK[1] is the effector. It is important to keep this in mind when using them.














使用distanceBetween節點須注意



在bridge rig中也用到了很多distance between節點來測量joint之間的距離,以便完成stretch ik的效果,這邊要注意的是,盡量不要用位移數值是0的物件來測量,例如控制器。

下圖是我把兩個控制器連上disatance between然後輸出到multply節點。



Distance between nodes are also used a lot in bridge rig to measure the distance between joints in order to achieve the stretch IK effect. Here, it is important to avoid using objects with a translate value of 0, such as controllers, for measurement.

The image below shows how I connected two controllers to a distance between node and output it to a multiply node.







接下來,我們選擇multply節點,可以看到distance between輸出的數值為0,這樣並不是一個好的結果,因為如果要製作ik stretch的效果,那麼就必須有一組數值讓其他節點運作。

因此如果需要用到這樣的技巧,就要避免使用translate數值為0的物件。


Next, if we select the multiply node, we can see that the output value of the distance between node is 0. This is not a good result because if we want to create the stretch IK effect, there must be a set of values for other nodes to work with.

Therefore, if we need to use this technique, we should avoid using objects with a translate value of 0.








底下的影片是我將兩個locator parent到控制器的位置,並且讓他們的translate保持在有數值的狀態,然後輸出到distance between節點,可以看到最後輸出到multiply節點就有數值了!

The following video shows how I parented two locators to the position of a controller and kept their translate values in a non-zero state, then output them to a distance between node. As a result, we can see that there are values in the output of the multiply node!










在function內使用空白list的用意


之前看過很多教學都有用過這樣的技巧,就是在function開始運作前先創建之後會用到的空白list,以前不明白這樣做的用意,但是在開始自己寫工具之後也開始有點眉目了,尤其是牽涉到大量的、有序列的物件時,這樣做的好處是可以把新生成的物件統一集中,並且跟其他list交互作用,再搭配上面提到的zip函式,幾乎就可以滿足大部分list處理的需求。


下面是一個簡單的範例,我先製作了兩個空list A跟B,然後透過迴圈將一組數列利用append加入到兩個list裡面。


最後,再利用zip將他們打包在一起print出來,不知道這個範例能不能解釋清楚,總之這兩個list的數列可以代指任何其他物件,可能是控制器、joint之類的東西,當我們使用maya命令產生這些新物件的同時,將他們加入到原本安排好的空白list,那麼在之後的某個時刻就可以調用出來使用!


I have seen many tutorials use this technique, which is to create empty lists for the objects that will be used before the function starts running. I didn't understand the purpose of doing this before, but after starting to write my own tools, I began to understand its benefits, especially when dealing with large, ordered sets of objects. This method can unify and interact with newly generated objects and can be combined with the zip function mentioned above to satisfy most list processing needs.

Below is a simple example where I created two empty lists, A and B, and used a loop to append a sequence of numbers to both lists. Finally, I used zip to package them together and printed them out. This example may not be easy to understand, but these two lists of numbers can represent any other objects, such as controllers or joints. When we use Maya commands to generate these new objects, we can add them to the pre-arranged empty lists, so we can call them up and use them later!










串聯joint以及子階層所有的joints


如果想要串聯一個joint chain可以這麼做。

If you want to connect a joint chain, you can do it like this.

JNT=cmds.ls(sl=1)

for i in JNT:
    
    Sel=cmds.ls(i, dag=True, type='joint')
    
    for j in Sel:
        
        cmds.connectAttr("locator9.rotate",j+".rotate")


如下面影片示範的,我先選中所有joint chain的root,然後利用ls這個命令將他們加入到JNT這個list裡面,接下來再利用兩個迴圈將locator的rotate串聯到所有的joint上!

As demonstrated in the video below, I first selected the root of the joint chain, then used the ls command to add them to the list named "JNT". Next, I used two loops to link the rotation of the locators to all the joints!








使用eval()函數將str轉換回list



事情是這樣的,因為maya cmds的text field不能直接用cmds.ls選中物件顯示,會出現錯誤,因為我們選到的東西是unicode不是str,所以要先把list str()之後才能正常顯示(MAYA2022之後好像就不會了,是python版本問題)

這樣在執行function時會出現錯誤,就是for 迴圈無法直接讀取str()後的東西,所以我們需要再將它轉回list格式,所以就會用到eval()。


底下是一個簡單的示範,過程是將一個str利用eval()轉換回list,如果各位有遇到任何有關unicode錯誤的問題可以試試這個解法。

The thing is, the Maya cmds text field cannot directly display the selected objects using cmds.ls, which may cause errors because the selected items are unicode, not str. Therefore, we need to convert the list to str() before displaying it (this issue may have been resolved in Python versions after MAYA 2022).

This will cause an error when executing the function because the for loop cannot directly read the str() items. Therefore, we need to convert it back to list format using eval().

Here is a simple demonstration. The process is to convert a str back to a list using eval(). If you encounter any unicode errors, you can try this solution.









如果覺得這篇文章有幫助你在動畫之路走得更長遠,可以使用 Google 或 Facebook 帳號快速登入,按Like五下,就可以幫助我從Likecoin得到回饋,完全不用任何費用! 一點點的鼓勵都會成為我寫作的動力,感激不盡!

If you found this article helpful in your journey in animation, you can use your Google or Facebook account to quickly log in and click Like five times to help me earn rewards from Likecoin, without any cost! Your encouragement means a lot to me and will become the motivation behind my writing. Thank you so much!


 








張貼留言

0 留言