RestoreObj 在3ds max 中

來源:互聯網
上載者:User

undo和redo操作在許多軟體中都有應用,而3ds max也不例外。那麼3ds max是用什麼東東來實現undo和redo呢?

看了max sdk 2010的Deriving From RestoreObj後,你會恍然大悟,max是用RestoreObj來實現undo和redo的。

首先, 你要實現一個繼承RestoreObj的類(DeriveRestoreObj) ,在這個類裡要實現RestoreObj裡的Restore和Redo函數,它們分別是用來

實現max的undo和redo操作的。

再者 , 你還要實現其他方法,比如size(),EndHold(),Description()等函數。size函數是告訴你你的RestoreObj的位元組數。

EndHold()是設定一個restore的結束。

接下來,就是配合theHold來實現undo和redo操作了。這裡你把theHold當做一個堆棧桶,theHold.begin()就代表開始往裡面

放入操作,而緊接著的theHold.put(new DeriveRestoreObj(....))就代表這個堆棧桶要以DeriveRestoreObj裡的Restore函數和

Redo函數來執行undo和redo操作。

然後,經過一段代碼操作後,theHold.accept()就代表這段代碼操作被壓到堆棧桶裡了,而theHold.cancel()就代表撤銷了壓入堆棧桶

的操作,即這段代碼操作沒有壓入堆棧桶,同時撤銷了theHold 堆棧桶。

最後,拿max sdk的例子給大家看看:

class NodeRest : public RestoreObj {

   public:

     Orient offs;

     Orient redoOffs;

     Node *cur;

     NodeRest() { cur = NULL; }

     NodeRest(Node *node) {

       cur = node;

       offs = node->modOffset;

     }

     ~NodeRest() {}

     void Restore(int isUndo);

     void Redo();

     int Size() { return 2*sizeof(Orient) + sizeof(INode*); }

     void EndHold() { cur->ClearAFlag(A_HELD); }

     virtual TSTR Description() { return TSTR(_T(" Node State")); }

};

 

void Node::HoldState() {

   if (theHold.Holding() && !TestAFlag(A_HELD))

   {

     theHold.Put(new NodeRest(this));

     SetAFlag(A_HELD);

   }

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.