一半君的总结纸

听话只听一半君

如何直接在.ma文件里清理/删除 reference edits ?

很多Maya流程的公司都是把rig reference进animator用的文件,然后animator只管keyframe的,按理说正常情况下,如果只在anim controllers上设keyframe,reference node上的 reference edits 应该是比较”整洁的“,应该只有 setAttr connectAttr, 但是实际中经常会剪切粘贴keys,自己加constraints等等,经常发生文件打开奇慢,或者干脆打不开,或者rig上的某部分geom飞走拉伸等等奇怪现象,检查此类出现问题的.ma文件往往发现ref node上的ref edits里多出了很多“无意义”连接,他们如果能被删除,那很大可能性.ma文件就就复活了。

公司有个script是在maya gui里完成上述操作,首先unload ref, 然后regex删ref edits, 然后load ref, 但是场景“大”的时候这么做会很慢,有时候甚至达到1个小时以上(如果20-30个角色),所以下面是研究下如何直接在.ma文件里删ref edits.

已知”规律”:
Any reference edit to a file that’s being referenced with a namespace “ref” can be found in the .ma file starting with the code: “createNode reference -n “refRN”;”. The list ends the line before the next “createNode” command. This block contains lot of setAttr commands going by the rules of .ma file that after every “createNode”, a set of “setAttr” commands follow. The code looks something like this.

createNode reference -n "refRN";
    setAttr ".ed" -type "dataReferenceEdits" 
        "refRN"
        "refRN" 0
        "refRN" 1
        2 "|ref:nurbsSphere1" "translate" " -type \"double3\" 0.984522 0.648003 -1.95567";
    setAttr ".ptag" -type "string" "";

The above code is an extract from .ma file of a parent scene that references a child scene containing a “nurbsSphere1” object which has been translated by “0.984522 0.648003 -1.95567”. The three lines that start with “refRN” word appeared same in all cases i studied.
The digit “2” that is seen in the second last line indicates “setAttr” edit. It is 5 for “connectAttr”, 0 for “parent” edit and 1 for “addAttr” command.
The number 1 after the last “refRN” line stands for the number of edit entries that follow it. In this case, since the only edit is a “setAttr” edit of the “nurbsSphere1” it shows 1.

The “connectAttr” edit has a bit more detail. “connectAttr” edit is created when there is a connection between a node in the parent scene to a node in the child scene. The code is:

createNode reference -n "refRN";
    setAttr ".phl[0]" 0;
    setAttr ".ed" -type "dataReferenceEdits" 
        "refRN"
        "refRN" 0
        "refRN" 1
        5 4 "refRN" "|ref:nurbsSphere1.translateX" "refRN.placeHolderList[0]" 
        "";
    setAttr ".ptag" -type "string" "";

Above code is a from a file in which only translateX of “ref:nurbSphere1” has been keyed.
Notice that there is a “setAttr “.phl[0]” 0;” line that is added. phl stands for “placeHolderList” and a phl plug is created in the “refRN” node for every connection from a node in the parent scene to another node in the child scene. Also after the first number which is 5, there comes another number. 4 stands for connection from node in parent scene to a node in child scene. 3 stands for the other way connection.

That’s about my study so far. I have a few questions unanswered yet. They are:

  1. What does the line – “refRN” 0 signify? Are there cases where some entreis come between that line and the next “refRN” line?

    One of the “refRN #” lines stores loaded edits and the other unloaded edits. As of 6.5 all references are stored on disk in the unloaded state. This means that if the reference is loaded when you save the scene Maya has to implicitly unload it – basically it goes through the steps of finding and building the reference edits without actually removing the referenced nodes from the scene. To keep these edits separate from edits which were created due to unloading a reference, Maya sticks them in a special place and writes them out in their own “refRN #” block. After the save operation completes these edits are deleted. To give this a whirl try saving the same scene twice, once with the reference loaded and once with it unloaded.

  2. I’ve mentioned that 0 stands for “parent” edit, 1 for “addAttr”, 2 for “setAttr” and 5 for connectAttr. What does 3 and 4 signify? Or are there any other command that is represented by some other code.

    3 is disconnectAttr
    4 is deleteAttr

    A deleteAttr edit will be created if you delete a dynamic attribute from a referenced node.

    A disconnectAttr edit will be created if you disconnect a connection which was made in a referenced file. If you connect two referenced nodes and then break that connection, neither the connection nor the disconnection will be stored as edits (the end result is that there has been no change to the referenced nodes). However if you disconnect a connection that was made in the referenced file a disconnectAttr edit will be created. Things get a little hairier when dealing with multiple levels of referencing – but the same ideas should hold true.

  3. In case of connectAttr command, i said, 4 stands for incoming connection and 3 for outgoing. Is there any other kind of connection specified by the second code?

    Code 0 is for a connection between two nodes in the same reference.

    The other codes are only used when multiple references are involved. For example:

    1. Create a reference to a sphere
    2. Create a reference to a cube
    3. Connect the sphere’s translate to the cube’s translate
    4. Save

    If you open up the parent scene, you’ll see that there are two connectAttr edits, one stored on the sphere’s reference node (e.g. sphereRN) and one on the cube’s reference node (e.g. cubeRN). The edit stored on sphereRN has code 1, and the edit stored on cubeRN has code 2 – two edits are necessary in order to handle cases where only one of the two references is loaded. A similar situation can be created with multiple levels of references.

下面开始用python乱搞:

待续…

人肉备份:
.ma file specifications

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 博主赞过: