在和朋友製作遊戲的過程中,經常有人問到角色模型應該怎麼建才更符合Unity的需要。在此,我將Unity官方網站中關於建模要求的部分翻譯如下,供參考。
限於本人英文水平有限,而且並沒有一字一句地翻譯,而是基於自己對引擎的理解,採用更符合中文的語序來翻譯。故採取在原文段落下方附加中文翻譯的做法,以便大家對照。有些內容若朋友們覺得翻譯得不妥,歡迎給我留言。
Modeling Optimized Characters角色最佳化建模Use one Skinned Mesh Renderer一個角色僅使用一個SkinedMeshRenderer(後簡稱 SMR)
Your character should use only a single skinned mesh renderer. There is usually no reason to
use multiple meshes for a character. Unity also has optimizations related to visibility culling and bounding volume updating which only kick in if you use one animation
component and one skinned mesh renderer in conjunction. If you care about performance, multiple skinned meshes per character is not an option. If you use two skinned mesh renderers for one
character instead of one, the time spent on rendering the character will most likely double!
在Unity中您應該每個角色僅使用一個SkinedMeshRenderer來繪製。一般來說單個角色沒必要用到兩個或更多的網格(譯者:此網格應理解為Unity中Render組件所使用的Mesh,該Mesh可以包含多個sub mesh,各sub mesh有自己的材質,但都用一個Render繪製)。而且,Unity在最佳化視景裁剪和更新角色包圍體時,是基於僅有一個動畫組件和一個SMR的假設的。所以,如果你最求效能,就不應該為一個角色使用多個SMR。如果你用了兩個SMR,則時間消耗可能是用一個SMR的兩倍!
Don't Use Many Materials不要使用過多的材質
You also want to keep the number of materials on that mesh as low as possible. There is only
one reason why you might want to have more than one material on the character: when you need to use a different shader (e.g. if you want to use a special shader for the eyes). However, 2-3 materials per character should be sufficient in almost all cases. If
your character is carrying a gun, it might be useful to have the gun a separate object, simply because it might get detached.
你還應該儘可能地減少角色所用材質的數量。你應該只有一個理由使用多個材質:那就是你想使用多個著色器(例如,你想為角色眼睛使用另外一個著色器)。但是,大多數情況下,每個角色2-3個材質就夠了。如果你的角色還有一把槍,那你應該考慮把槍作為另外一個物體(而不是角色的一部分),因為它可以從角色身上拿走。(譯者:我認為裝備和武器網格點如果要求受到多個角色骨骼的控制,而不是單純作為剛體隨骨骼運動,則最好還是作為角色的一部分建模,然後用指令碼動態組合實現換裝,參見3D遊戲引擎——Unity中網格合并樣本研究)
Reduce Amount of Bones減少骨骼數量
Medium Desktop games use bone hierarchies with 15-60 bones. The fewer bones you use the faster; with 30 bones you can achieve very good quality on Desktop platforms and fairly good quality on Mobile Platforms. Unless you really have to, we strongly
recommend you use fewer than 30 bones if you are developing for Mobile Platforms and around 30 bones per character on Desktop platforms.
中型的PC遊戲每個角色一般使用15-60個骨骼。骨骼越少,計算執行速度越快。一般用30個骨骼就可以在PC遊戲中獲得很好的表現效果,同時在手機平台上也如此。我們建議如果不是特別有需要的話,在手機平台上單角色的骨骼不要超過30個,在PC平台上也盡量只用30個左右的骨骼。
Polygon Count三角片數量
How many polygons you should use depends on the quality you require and the platform you are targeting. Anything between 300-1500 triangles on Mobile Platforms and 500-6000 triangles on Desktop Platforms is reasonable. If you want lots of characters
on screen or want the game to run on old machines, you will have to reduce the polygon count for each character. As an example: Half Life 2 characters used 2500-5000 triangles per character. Next-gen AAA games running on PS3 or Xbox 360 usually have characters
with 5000-7000 triangles.
究竟用多少三角片取決於你所要求的細緻程度和遊戲啟動並執行目標平台。一般手機上單角色200-1500,PC上500-6000個三角片都是合適的。如果你想同時顯示很多個角色,或者想在較早的硬體平台上流暢運行,那麼就需要再削減三角片數量。舉個例子:半條命2 每個角色用2500-5000個三角片,在PS3或者Xbox360上啟動並執行下一代的AAA(譯者:這是啥。。。)遊戲一般每個角色5000-7000三角片。
Separate Out IK and FK將IK和FK分開
Separate out inverse kinematics (IK) and forward kinematics (FK). When animations are imported, the IK nodes are baked into FK, thus Unity doesn't need the IK nodes at all. You can either kill the GameObjects in Unity or the nodes in the modelling
tool. By removing them, the IK nodes don't need to be animated every frame anymore. For this reason it is a very bad idea to intermix IK and FK hierarchies. Instead, you should create two hierarchies: one strictly for IK and one for FK. This way you can very
easily select the whole IK hierarchy and delete it.
將IK和FK分開。當Unity匯入模型動作時,IK節點會被烘焙成FK,因為Unity根本不需要IK節點。你可以在Uniy中將IK節點對應產生的GameObject刪除,或者直接在建模工具(如maya、MAX等)中將IK節點刪除後再匯入。這樣,Unity在繪製每幀時就不需要再考慮IK節點的動作了,由此提高了效能。所以,建模時將IK和FK混在一起可不是什麼好主意。正確的做法是:你應該將IK和FK分成兩組。這樣刪除的時候就非常方便。(譯者:本人對Max等建模工具完全不懂,不妥之處請多指教)
Use Reusable Rigs建立可重用的Rig
Create a rig which you can reuse. This allows you to share animations between different characters.
建立並使用可重用的rig。這樣,你就可以將一套動作應用到不同的角色。(譯者:基於骨骼設計動作,然後在骨骼上設計多套Mesh,就可以實現不同外貌的角色具有相同的動作。這個在遊戲中提供使用者自訂角色外貌時很有用。)
Name Bones Correctly為骨骼取直觀易懂的名字
Name the bones correctly (left hip, left ankle, left foot etc.). Especially with characters, naming your bones correctly is very important. For example if you want to turn a character into a Ragdoll you will have to find the right bones for each
body part. If they are not named correctly, finding all the body parts will take much longer.
為骨骼取上直觀易懂的名字(例如左臀、左踝、右腿等等)。對於人物角色,為骨骼取個正確的名字尤其重要。舉個例子:如果你要讓一個角色進入紙娃娃(譯者:一種靠物理引擎驅動的動作模型,常用於類比人體與真實環境相互作用下的動作)狀態,你就需要正確定位角色的各段骨骼。如果名字取得不好(例如 1、2、3之類的),程式的兄弟寫起指令碼來就很費勁。