最近在家研習面經,溫習基礎,索性花些時間將本科期間完成的一些學習之作整理出來,分享之余順便水點經驗![]()
其實這個事情起源於一門“計算機圖形與動畫(Computer Graphics & Animation)”的外方課程,當初的外籍教師Tony教的很認真,對於這門課自己也投入了非常多的時間。言歸正傳,這里先介紹一些涉及的技術,熟悉的同學請跳過哈~
D.准備工作
需要的相關庫有:
• QuickTime 7.7.1 for Windows (主要用於播放動畫與配音)
• QuickTime SDK (開發包)
•OpenGL、 GLUT庫 (基礎引擎)
當然如果使用 Visual Studio 的話記得添加上面的文件目錄與庫路徑,記得將其中的DLL加入環境變量或放入執行目錄下。
相關文件:https://github.com/Blz-Galaxy/OpenGL_Animation_MT/tree/master/Lib%26Preparation
E.建立基礎模型
舉幾個最簡單的例子,這是通過旋轉生成的鑽石:
這是鑽石輪廓的描述文本(重復數據會獲得更好的高光效果):
// ========================================================================================= // KXC354 - Computer Graphics & Animation, 2012 // Assignment 1 & 2 // 3D Engine Code // ========================================================================================= // // Edited by Evan // // diamondprofile.txt // // sweep profile for a diamond with the density of 8 // // radius y-coordinate 0.00001, 1.2 //draw table-board 0.5, 1.2 0.5, 1.2 //duplicate for better lighting 0.8, 1.2 0.8, 1.2 //duplicate for better lighting 1, 1.2 1, 1.2 //duplicate to make sharp edge 1.2, 1 1.2, 1 //duplicate for better lighting //draw girdle thickness 1.5, 0.68 1.5, 0.68 //duplicate to make sharp edge 1.5, 0.60 1.5, 0.60 //duplicate to make sharp edge //draw pavilion 0.00001, -1
再舉個拉伸體的例子,這是劍刃部分:
它由2個描述文本組成,一個是拉伸的截面形狀(即一個平行四邊形):
// ========================================================================================= // KXC354 - Computer Graphics & Animation, 2012 // Assignment 1 & 2 // 3D Engine Code // ========================================================================================= // // Edited by Evan // // quadprofile.txt // // a 2D profile for a quadrilateral extrusion (sword) // // radius y-coordinate 0, 1 //duplicate to make sharp edge 0, 1 -1, 0 //duplicate to make sharp edge -1, 0 0, -1 //duplicate to make sharp edge 0, -1 1, 0 //duplicate to make sharp edge 1, 0這是截面運動/縮放的路徑(同樣,重復數據會獲得更好的高光效果):
// ========================================================================================= // KXC354 - Computer Graphics & Animation, 2012 // Assignment 1 & 2 // 3D Engine Code // ========================================================================================= // // Edited by Evan // // swordpath.txt m -3 s .0001 .0001, p p //duplicate for better lighting m 0.5 s 3000 1500, p m 0.5 s 2 2, p p //duplicate for better lighting m 1.4 s 0.58 0.58, p m 1.2 s 0.58 0.58, p m 1 s 0.58 0.58, p p //duplicate for better lighting m 0.5, p p //duplicate for better lighting s .0001 .0001, p
當初為了調整輪廓外形,連excel都用上了
F.建立組合模型
代碼非常繁瑣,主要調用了很多事先打好草稿並測量后記錄在記事本里的關鍵點坐標(比如旋轉體的半輪廓、拉伸體的輪廓與拉伸/縮放路徑),這邊就顯示一小部分屬性設置/仿射變換,大致就能明白當初的純手工建模與調試的工作量了
composite1::composite1() { setName("composite1"); outface = new treasurebox(); outface->setColour(0.706, 0.471, 0.216); outface->attachToParentAt(this, 0, 0, 0); insideface = new treasurebox(); insideface->setColour(0.706, 0.471, 0.216); insideface->setScale(0.95); insideface->attachToParentAt(outface, 0, 0.01, 0); …… lid_frame3 = new extrusion("frameprofile.txt","framepath3.txt"); lid_frame3->useSmoothShading(); lid_frame3->setDeformation(0.9, 1, 1); lid_frame3->setRotation('y', 90, 'z', -10); lid_frame3->setColour(0.980, 0.957, 0.173); lid_frame3->attachToParentAt(lid, -0.3, 0, -1.5); milk = new sweep("milkprofile.txt", 20); milk->useSmoothShading(); milk->setRotation('z', 90); milk->attachToParentAt(insideface, 0, -0.7, 0); for(int i=0; i<10; i++) { diamond[i] = new sweep("diamondprofile.txt", 8); diamond[i]->useDiffuseShading(); diamond[i]->setColour(0.73, 0.91, 0.98, 0.8); diamond[i]->setScale(0.1); diamond[i]->setRotation('x', 90); diamond[i]->attachToParentAt(insideface, i*0.3 - 1.35, 0.5, 1.2); } // put the shape onto the shapeVector so it gets draw messages gShapeVector.push_back(this); }以上代碼做了個比較傻的寶箱模型。各個部件分別是:
這是組合成的最后效果(不好意思,當初為了增加構件數量達到要求,偷偷在里面放了個瓶子
)
然后就是當年打了無數草稿的“MT”模型:
順便解釋一下:
當初因為要在不規則的頭上貼“臉”,如果采用紋理貼圖的話映射函數反而會特別麻煩,因此索性都用圓球壓扁或者拉伸作為眼睛、眉毛,順便做了個圓環模型,效果上也更加立體;
此外由於考慮后續動畫設計,不得不再加入許多用於相對旋轉的球狀關節點(體內的紅色就是其中部分關節,因為需要節約面片,球體密度很低看起來像三角體)。
模型一覽:
目前先整理到模型這塊吧,后續動畫部分將包括:
- 模型動作設計
- 視窗設置(鏡頭運動、跟隨、震動等)
- 特效(迷霧、煙塵等粒子系統)
- 天空盒(世界背景)
- 地形制作(地勢生成與爬坡運動等)
- 貼圖(地面紋理貼圖、廣告牌:樹貼圖)
- 字幕設置
- 配樂
- ……
等有時間再做下整理哈![]()
相關鏈接
【OpenGL】“我叫MT”純手工3D動畫制作之1——基礎介紹: http://www.cnblogs.com/KC-Mei/p/4666099.html
【OpenGL】“我叫MT”純手工3D動畫制作之2——建立模型: http://www.cnblogs.com/KC-Mei/p/4666110.html
【OpenGL】“我叫MT”純手工3D動畫制作之3——動畫設計: (還在寫~)
需要的同學可以從這邊下載到引擎與我的項目:
Github項目文件:https://github.com/Blz-Galaxy/OpenGL_Animation_MT
(引擎交互的一些按鍵已經在 README.md 里注明,允許鼠標、鍵盤同時進行交互:按A鍵既可播放)
僅供學習參考,請勿用於其他目的,謝謝。














