mcwind's blog

游戏开发 Unity3d catia二次开发,协同设计流程,多学科设计仿真
posts - 37, comments - 6, trackbacks - 0, articles - 0
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

三维游戏引擎——Unity 角色模型优化要点

Posted on 2011-02-18 22:06 mcwind 阅读(...) 评论(...) 编辑 收藏

在和朋友制作游戏的过程中,经常有人问到角色模型应该怎么建才更符合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之类的),程序的兄弟写起脚本来就很费劲。