本文为摘录笔记,原文
之前已经做过摘录笔记Blender骨骼快速入门
所以关于一些基础操作就不再摘录,只做Unity中可复用角色相关需求,以及Blender对应快捷键,以及个人遇到的一些问题。
Rigging the Character
to be compatible with Unity’s Humanoid Avatar, some key bones are necessary:
Unity expects a minimum of 15 bones, which are:
- Hips (root bone)
- Lower spine
- Upper spine
- Neck
- Head
- Two upper arms
- Two lower arms
- Two hands
- Two upper legs
- Two lower legs
骨骼我们也只要建立一侧,建好后,选中一侧的骨骼, 接着press W and select Symmetrize.
最终得到:
Weight Painting
进入ObjectMode,先选中模型,再选中骨骼。(顺序很重要,虽都是选中,最后一个选中的为ActiveObject)。
Now press CTRL + P to open the Parent menu and choose With Automatic Weights to parent the model to the armature and perform automatic weight painting.
!(Automatic Weights Menu)[https://koenig-media.raywenderlich.com/uploads/2018/08/AutoWeights.png]
自动绑定处理的也不错,但也有一些细节问题,比如:眼睛没绑上.
自己绑定眼睛吧,选中模型进入WeightPainting Mode,
在这之前,务必先选择骨骼(Armature),使其进入Pose Mode。(不同类型的对象有不同的模式,骨骼就没WeightPainting Mode, 模型也没有Pose Mode)
如果不这么做的话,后续进入WeightPainting模式后,CTRL+RMB是无法选中骨骼的!
增加或减少Weight是通过Brush进行的,
这里教程的方法很巧妙,先把头部旋转,眼睛没有跟上。用笔刷增加权重后,眼睛就会跟上去了。
然后重置头部的旋转
press Alt (or Option) + R to reset the rotation of the Head bone.(位移,缩放也都是类似的操作,Option(Alt) + G, Option(Alt) + S)
按过R后再按一次,会进入trackball模式。
Note: The rotation above was done using trackball rotation. You can activate this rotation mode by pressing R again after you’ve started to rotate.
Adding Accessories
文章中描述了两种不同的Accessories
- 做到Model中的帽子
- 独立的模型,挂在骨骼上的棍子
添加帽子
这里就是正常的编辑模型。记录一些文章中用到的快捷键。
EditMode中,CTRL + Tab 唤出Mesh Select Mode的PopupMenu
Press CTRL + L to select all connected vertices。
此时,左边Tools面板会出现Delimit
Now select the UV delimiter by selecting UVs in the bottom left panel.
Select the edge loop underneath as well by holding Shift and Alt (or Option) and then right-clicking on any of the first horizontal edges below.
Now duplicate the selected faces by pressing Shift + D and then pressing Enter.
holding Alt (or Option) and right-clicking on one of the bottom edges.
这会选中一圈Edges
感到最神奇的是这,设置Z轴上Scale为0,居然可以拉直。。。就好像Sin函数有几何意义一样。。。
Make it straight by press S, Z and 0 in that order.
这里CTRL + L好像没有什么效果啊,并不是全部选中啊。。。手册也看不懂啥意思。
Select the entire hat by selecting any vertex on the hat and then pressing CTRL + L. Change the delimiter to Normal this time to select all of the connected vertices.
Manual:L (or Ctrl-L for all) will add to the selection the cursor’s nearest control point, and all the linked ones, i.e. all points belonging to the same curve. Note that for Bézier, using L with a handle selected will select the whole control point and all the linked ones.
For this hat, you’ll perform one of the easiest unwraps in existence: from the view. Press numpad 1 to get a front view, then press U to open the Unwrap menu and select Project From View.
Project From View的结果看看还是挺有意思的。
添加棍子
先建立一个独立的模型吧。
Get into Object mode and press Shift + A to open the Add menu. Select Mesh > Cylinder to add a new cylinder to the scene.
文中给的设置
Make the cylinder smooth by pressing the Smooth button in the Shading section in the Tool Shelf on the left.
这个选项不是出现在创建上下文Menu中的,就是Tools里的。之后也可以修改。
给棍子材质,选中棍子的状态下,open the Material tab in the Properties panel on the right and select CuteMaterial from the drop-down next to the New button.
To turn the cylinder into a brown staff, you’ll need to unwrap its UVs first. Press Tab to enter Edit mode, press U to open the Unwrap menu and select Project From View.
不要担心当前这个尴尬的位置,我们下面就会进行处理它/simle
Open the Constraints tab in the Properties panel. Add a new constraint by clicking the Add Object Constraint drop-down and selecting Child Of.
Setting up the constraint is straightforward. Click the Target drop-down and select Armature. Now click the Vertex Group drop-down and select Hand.R.
接下来就是把棍子摆到合适的位置,文中给出的配置:
R, X, 90
G, Y, -0.4
Pose模式晃晃看:
其实这个时候可以设置下棍子的原点,使其和骨骼的连接点作为原点。旋转不会破坏。
手持点为原点,棍尖向上。
导出
导出格式选择FBX
These default export settings will work with Unity, but there’s a chance they might make a mess in more complex scenes as it will export everything, even lamps and cameras. To make a clean export, make the following changes:
Deselect Camera, Lamp and Other. You can do this by holding down Shift and clicking the options you want to disable.
With just these options selected, you won’t get any undesired objects exported. Now check the !EXPERIMENTAL! Apply Transform checkbox right below the options you deselected. This applies the position, rotation and scale of all objects. That means any non-uniform values will be reset; if the rotation was set to (X:23, Y:125, Z:7), for example, it will be set to (X:0, Y:0, Z:0).
这个应该是针对于整体的Object。。。
Switch to the Geometries tab by clicking the Geometries button, and uncheck the Use Modifiers Render Setting checkbox. This allows you to keep a high poly count for renders inside Blender, but keep it low for use inside of Unity.
不明白什么意思,导出后不使用Modifiers,应该会导致导出的面数多吧?
Next, open the Armatures tab, check Only Deform Bones and uncheck Add Leaf Bones. This prevents Blender from adding extra bones to the armature. Leaf bones are only needed for compatibility with Maya. Non-deform bones like control bones are only needed in the modeling software to make precise adjustments; they’re useless in a game engine like Unity.
The default Animation options are fine, so you don’t need to tinker with those.
保存这个导出配置
To do this, click the + button next to the Operator Presets drop-down, type a name for the preset in the textbox and click the OK button. For the sake of this tutorial feel free to name it Unity FBX.
关于导出选项中的Forward和Up,感觉指的是在导出的使用场景中,哪个轴是Foward哪个轴是Up。
总之保持-Z Forward,Y Up
在Blender中编辑时,Front视图就是从前往后看,Right视图就是从右往左看。
Avatar Mapping
The way Unity uses these bones is by acting like a puppeteer. Instead of straight up using animation files to update the bones every frame, it reads the values and applies those to every humanoid based on their Avatar definition. This allows for flexibility when it comes to body shapes. Take the character you’ve been working on, for instance; its proportions are not realistic, but that doesn’t matter as its skeleton is also adjusted to fit while still having the essential bones like a spine, arms, legs, etc. Some of the bones may be shorter than in most humans, but they’re there.
Muscles&Settings
Muscles 肌肉
You’ll now see three sections:
- Muscle Group Preview
- Per-Muscle Settings
- Additional Settings
The first one has several sliders you can move from left to right to test if the muscles are mapped correctly. Try them out and see what they do. Note that the finger ones won’t have any effect since the character doesn’t have any fingers. Press the Reset All button after every test to reset all preview sliders.
使用MusclePreviews可以进行测试,看看会不会出现动画穿透。因为动画时共用的。这里可以对高矮胖瘦不同的模型进行各个部位的转角进行限制,从而避免模型作动画时出现的穿透情况。
The Per-Muscle Settings section contains sub-sections that can be unfolded by clicking the arrow next to them. Every one of these has some more specific previews and allows you to specify the minimum and maximum angles to prevent overlapping for your specific model.
Expand the Left Arm section and try sliding around the Arm Down-Up slider. Notice what happens with the minimum value selected:
The arm is moving through the character’s body. Ouch!
To fix this, set the preview slider to its lowest value and change the minimum angle of Arm Down-Up to -20.
Do the same for Right Arm > Arm Down-Up.
That concludes the tweaking of the muscles. There are more muscles you can tweak to prevent overlapping, but for the sake of this tutorial leave it at the arms up and down movement.
Press the Apply button at the bottom-right to save the changes to the Avatar and press Done to close the mapping mode.
如何在Unity3D中进行播放就不记录了,相关文档非常多。
后记
发现一个问题,模型的朝向和缩放都是正常的。
不过Armature(骨骼)的缩放和旋转不是identity。
缩放xyz均为100,旋转x=-90
解决xyz为100的方法:
导出时main tab中 Apply Scalings: 改为FBX All。
旋转没找到什么方法解决。
如果武器需要挂接到骨骼上,可以设置rotation x=90
有遇到一种情况,同事在3DMax中做好的模型动作,放入Unity3D中动作和建模软件中不一样,会有一定倾斜角度。查看动作模型导入选项Rig中的的Avatar,其T-Pose有倾斜,看了下根节点,旋转角度调整下就可以了。