Alembic Referncing Bug in Maya
===
### 狀況簡述
同一個 alembic animation 檔案 reference 多次,存檔之後再次開啟會發現除了第一個 Alembic reference 之外,其他的 animation 都有 **rotation** 大幅偏移的情形。
### 還原臭蟲
1. 首先場景裡有一個簡單的方塊旋轉動態 (非變形動態)

```python
# 直接貼上這段 python 代碼即可重現
from maya import cmds
# 開新檔
cmds.file(new=True, force=True)
# 創方塊並且設 key
cube = cmds.polyCube(constructionHistory=False)[0]
cmds.select(cube + ".vtx[0:7]")
cmds.move(0, 5, 0, relative=True)
cmds.setKeyframe(cube, attribute="rx", time=100, value=0)
cmds.setKeyframe(cube, attribute="rx", time=120, value=90)
cmds.setKeyframe(cube, attribute="rx", time=140, value=0)
cmds.setKeyframe(cube, attribute="rx", time=160, value=-90)
cmds.setKeyframe(cube, attribute="rx", time=180, value=0)
```
2. 將這個方塊輸出 Alembic 並且 reference 兩次,可以看到動態是正常的

```python
# 輸出 Abc
cmds.AbcExport(jobArg="-frameRange 100 180 -root %s -file test_exp.abc" % cube)
# 開新檔
cmds.file(new=True, force=True)
# 載入 abc
cmds.file("cache/alembic/test_exp.abc", r=True, type="Alembic", namespace="No1")
# 再次載入相同的 abc
cmds.file("cache/alembic/test_exp.abc", r=True, type="Alembic", namespace="No2")
```
3. 存檔並且重新開啟,會發現第二個方塊的 roation 已經崩壞

```python
# 存檔
cmds.file(rename="test_abc_ref.ma")
cmds.file(save=True, type="mayaAscii", force=True)
# 重新開啟
cmds.file("test_abc_ref.ma", o=True, force=True)
```
### 原因
Alembic 在將 animation 資訊輸入到 transform 節點之前都會有一個單位轉換,如下圖

但由於 Maya 的 Bug,讓場景再次重新開啟的時候只有第一個 reference 會放上正確的轉換倍數,其他的則是預設值的 `1`

### 解決辦法
這個 Bug 據說已經存在至少 3 年有餘,但要繞過也很簡單。
其實,除非情況特殊,否則我們原本就只需要 reference 一個就可以了,其餘的用 *Duplicate Special* 工具,使用 **Copy** + **Duplicate input connections** 就可以解決。

1. 選取要複製的模型
2. 打開選單 `Edit > Duplicate Special` 工具
3. 上方的 Geometry tpye 選 *Copy*
> 這邊不可以使用 instance,否則複製連結的功能會無法啟用
4. 設定複製的數量,並勾選 *Duplicate input connections*
5. 完成
這個方法可行 (其實原本就該用這個方法而非 reference 多個 alembic) 是因為被複製出來的模型 transform 都取用同一個 Alembic 節點的 animation 資訊。

而且使用這個方法的話,之後你只需要更新那個 reference,所有的動態都會一起更新。
如果真的需要有多個本體,那就改用 import 吧。