From BlenderWiki

Jump to: navigation, search
Blender3D FreeTip.gif
IMPORTANT! Do not update this page!
We have moved the Blender User Manual to a new location. Please do not update this page, as it will be locked soon.


Page status (reviewing guidelines)

Copy This page is a copy of the same page in 2.4 manual, need to be updated

Text Partially
Proposed fixes: none

布料模拟

布料示例.
人体木雕上的布料 (made by motorsep).
布料示例.

布料模拟是CG里最难的领域之一,因为它把真实世界的布料简化了,而实际上的布料有着相当复杂的内部和环境作用力。经过多年的发展,Blender也有了一个十分强劲的布料模拟可以用来模拟衣物、旗帜等物体。布料影响力会和其他移动的物体、风力以及其他力,还有一般的动力学模型相互影响,所有的事情都在你的控制之中。

描述

一块布料可以是任何打开或者闭合的被指定为布料的模型。布料 按钮在物理 子目录下,包含了三种按钮和设置。在打开或闭合的模型下所有的布料都被假定为每一单位面积的质量是一样的。

布料的模型一般是常见的网格物体、方块或者也可以是诸如泰迪熊之类的。Blender的 软体系统 为闭合模型提供了更好的模拟,布料只是其中一块很特殊的编织物模拟。

一旦物体被定义了布料属性,布料修改器 就会在物体的修改器栏下自动添加。作为一个修改器 ,它可以和其它的修改器相互作用,比如骨骼平滑。 所以,最终的形状讲取决于修改器的共同作用。比如,你应该在细分计算完形状之后进行平滑。

所以你可以在两个地方设置编辑布料:使用Shift+F7(译者注:英文页面写的是F7,测试了一下无效,切换面板快捷键应该加上Shift)找到物理按钮编辑,使用修改器模块编辑和其他修改器关联的布料修改器。

你可以应用 布料修改器锁定网格模型在这一帧的形状,应用之后修改器会被自动移除。例如,你可以在桌子上建一个平整的布料,开始模拟后应用修改器。这样可以给你节省不少建模的时间。

因为布料的模拟被放在了缓存里面,所以一旦这一帧的模型形状已经被模拟过了,就不用再去重新计算。如果对模拟进行了修改,你需要清楚缓存重新计算整个模拟。第一次运行模拟时是完全自动的,没有烘焙和其他独立步骤来打断工作流程。

后台会自动的将所有帧上的布料的形状计算出来,因此你可以在计算完成后继续你的工作。但是模拟时会大量使用到CPU,受你的PC性能以及模拟复杂程度还有你的CPU线程数量等影响,可能会出现一点短暂的卡顿。


不要向前跳转
如果你开始了布料模拟但是Blender还没有计算完布料模拟的所有的形状,这时候如果你向前跳转太多帧,而且之前没有计算过这一(些)帧,布料的模拟可能不能计算和显示这一帧的形状。


工作流程

普通的布料工作流程是:

  1. 建造布料物体的起始形状作为最初的模型。
  2. 属性窗口的 物理面板下给物体添加“布料” 属性。
  3. 添加其他会和布料相互作用的对象。确保这些东西在修改器的顺序要正确。
  4. 给布料添加光照和材质,UV。
  5. 添加粒子系统,比如从表面落下来的雾。
  6. 计算模拟,调整相关的选项数值知道结果合适为止。时间线窗口的VCR控制会在这里十分有用。
  7. 挑选某一时刻的物体形状作为模拟的初始形状。
  8. 岁模型做逐帧的调整。


创建布料模拟

这一块讲的是如何使用这些设置得到你想要的结果。 首先,添加布料。开始模拟,你可以选取一帧作为起始帧。可以看到织物越重,看上去会越僵硬,如果越轻就会更容易受空气影响。

布料面板

预设
包含了一系列预设好的模拟参数,当然也允许你自行设置修改。
品质
设置每一帧的模拟步数,值越高效果越好,但是计算的越慢。

材质

质量
布料的质量。
结构
布料的整体硬度。
弯曲
褶皱的系数。系数越高,褶皱越多。

阻尼

弹性
布料的速度阻尼效果,值越高速度变化越缓慢,抖动越少。
空气
空气通常会有一定的厚度会减慢物体下落。

钉住

Cloth in action.

在钉住一个物体前你需要了解物体的 顶点组. 可以利用权重绘制工具绘制一块区域达到钉住的效果 (参照教程的 权重绘制 板块).

添加了顶点组之后,看上去会更直观,你需要做的是勾选布料面板下的 选项设置你想要用的顶点组,并且设置想要的硬度。

硬度
目标位置的硬度。你可以保持默认的数值1。



布料碰撞

大多数情况下,一块布料不只是悬挂在3D空间中,它会和环境中的其他物体产生碰撞。为了确保更好的模拟运算,这里提供了很多项可以同时作用的设置。


  1. 布料物体必须包含碰撞
  2. 任选一个(必须有)物体设置自身为碰撞。
  3. 其他物体必须在布料物体的层下可见。
  4. 其他物体必须是网格物体。
  5. 其他物体可以移动,也可以由别的对象产生变化(比如动画和形变帧)。
  6. 其他的网格物体必须加上能和布料影响的属性。
  7. blend文件必须保存在一个路径下,这样才能确保模拟的结果能保存。
  8. 然后烘焙模拟。之后会计算出布料的每一帧的形状。
  9. 你可以编辑模拟的结果,或者在某一帧将它调整为一个适当的网格模型。
  10. 你可以根据环境设置,在现存的帧上重新模拟你的布料。


碰撞设置

Cloth Collisions panel.

然后你需要设置布料物体,赋予它碰撞。选择这个布料物体,布料碰撞菜单下,如右图:

激活碰撞
LMB Template-LMB.png点击将布料物体赋予碰撞属性。
品质
期望的模拟品质的大致设置。数值越高需要花费更多的时间但可以确定撕裂和穿透现象更少。
距离
其他物体检测到这个物体的距离(Blender单位),达到这个距离后会开始模拟。
消除
近距离碰撞时的布料排斥力。
消除间隔
最大斥力,要大于最小距离。
摩擦力
一个表示物体碰撞时平滑程度的参数。比如,丝绸的摩擦力会比棉的摩擦力小。


自碰撞

真是布料不可能穿透自己,所以通常需要布料有一个自碰撞。

激活自碰撞
勾选后表示告诉布料不应该穿透自身。会增加模拟的时间,但模拟结果更真实。一面旗帜,远距离看不需要激活自碰撞,但是近距离观察人物的披肩或者衣服时就需要激活此项了。
品质
自碰撞品质越高时需要提高布料整体的品质来体现多出来的品质。注意碰撞品质的值不能少于布料整体的品质的值
距离
如果遇到了问题,可以改变自碰撞最小距离的值。最好的值是0.75;在模拟一些快速运动的物体时建议用1。0.5的数值相当危险(会有很多的穿透)但是会有一些模拟速度的提升。

Regression blend file: Cloth selfcollisions.

Shared Layers

Suppose you have two objects: a pair of Pants on layers 2 and 3, and your Character mesh on layers 1 and 2. You have enabled the Pants as cloth as described above. You must now make the Character “visible” to the Cloth object, so that as your character bends its leg, it will push the cloth. This principle is the same for all simulations; simulations only interact with objects on a shared layer. In this example, both objects share layer 2.

To view/change an object’s layers, RMB Template-RMB.png click to select the object in Object mode in the 3D view. M to bring up the “Move Layers” popup, which shows you all the layers that the object is on. To put the object on a single layer, LMB Template-LMB.png click the layer button. To put the object on multiple layers, ⇧ ShiftLMB Template-LMB.png the layer buttons. To remove an object from a selected layer, simply ⇧ ShiftLMB Template-LMB.png the layer button again to toggle it.

Mesh Objects Collide

If your colliding object is not a mesh object, such as a NURBS surface, or text object, you must convert it to a mesh object. To do so, select the object in object mode, and in the 3D View header, select Object → Convert Object Type (AltC), and select Mesh from the popup menu.

Cloth - Object collisions

Collision settings.

The cloth object needs to be deflected by some other object. To deflect a cloth, the object must be enabled as an object that collides with the cloth object. To enable Cloth - Object collisions, you have to enable deflections on the collision object (not on the cloth object).

In the Buttons window, Object context, Physics sub-context, locate the Collision panel shown to the right. It is also important to note that this collision panel is used to tell all simulations that this object is to participate in colliding/deflecting other objects on a shared layer (particles, soft bodies, and cloth).

Beware
There are three different Collision panels, all found in the Physics sub-context. The first (by default), a tab beside the Fields panel, is the one needed here. The second panel, a tab in the Soft Body group, concern softbodies (and so has nothing to do with cloth). And we have already seen the last one, by default a tab beside the Cloth panel.


Mesh Object Modifier Stack

Collision stack.

The object’s shape deforms the cloth, so the cloth simulation must know the “true” shape of that mesh object at that frame. This true shape is the basis shape as modified by shape keys or armatures. Therefore, the Collision modifier must be after any of those. The image to the right shows the Modifiers panel for the Character mesh object (not the cloth object).

Cloth Cache

Cache settings for cloth are the same as with other dynamic systems. See Particle Cache for details.

Bake Collision

After Baking.

After you have set up the deflection mesh for the frame range you intend to run the simulation (including animating that mesh via armatures), you can now tell the cloth simulation to compute (and avoid) collisions. Select the cloth object and in the Object context, Physics sub-context, set the Start and End settings for the simulation frames you wish to compute, and click the Bake button.

You cannot change Start or End without clearing the bake simulation. When the simulation has finished, you will notice you have the option to free the bake, edit the bake and re-bake:

There’s a few things you’ll probably notice right away. First, it will bake significantly slower than before, and it will probably clip through the box pretty badly as in the picture on the right.

Editing the cached simulation=

The cache contains the shape of the mesh at each frame. You can edit the cached simulation, after you've baked the simulation and pressed the Bake Editing button. Just go to the frame you want to fix and ⇆ Tab into Edit mode. There you can move your vertices using all of Blender’s mesh shaping tools. When you exit, the shape of the mesh will be recorded for that frame of the animation. If you want Blender to resume the simulation using the new shape going forward, LMB Template-LMB.png click ’Rebake from next Frame and play the animation. Blender will then pick up with that shape and resume the simulation.

Edit the mesh to correct minor tears and places where the colliding object has punctured the cloth.

If you add, delete, extrude, or remove vertices in the mesh, Blender will take the new mesh as the starting shape of the mesh back to the first frame of the animation, replacing the original shape you started with, up to the frame you were on when you edited the mesh. Therefore, if you change the content of a mesh, when you ⇆ Tab out of Edit mode, you should unprotect and clear the cache so that Blender will make a consistent simulation.

Troubleshooting

If you encounter some problems with collision detection, there are two ways to fix them:

  • The fastest solution is to increase the Min Distance setting under the Cloth Collision panel. This will be the fastest way to fix the clipping; however, it will be less accurate and won’t look as good. Using this method tends to make it look like the cloth is resting on air, and gives it a very rounded look.
  • A second method is to increase the Quality (in the first Cloth panel). This results in smaller steps for the simulator and therefore to a higher probability that fast-moving collisions get caught. You can also increase the Collision Quality to perform more iterations to get collisions solved.
  • If none of the methods help, you can easily edit the cached/baked result in Edit mode afterwards.
  • My Cloth is torn by the deforming mesh - he “Hulks Out”: Increase its structural stiffness (StructStiff setting, Cloth panel), very high, like 1000.
Subsurf modifier
A bake/cache is done for every subsurf level so please use the equal subsurf level for render and preview.


Examples

To start with cloth, the first thing you need, of course, is some fabric. So, let's delete the default cube and add a plane. I scaled mine up along the Y axis, but you don’t have to do this. In order to get some good floppy and flexible fabric, you’ll need to subdivide it several times. I did it 8 times for this example. So ⇆ Tab into Edit mode, and press W → Subdivide multi, and set it to 8.

Now, we’ll make this cloth by going to the Object context (F7) → Physics sub-context. Scroll down until you see the Cloth panel, and press the Cloth button. Now, a lot of settings will appear, most of which we’ll ignore for now.

That’s all you need to do to set your cloth up for animating, but if you hit AltA, your lovely fabric will just drop very un-spectacularly. That’s what we’ll cover in the next two sections about pinning and colliding.

Using Simulation to Shape/Sculpt a Mesh

You can Apply the Cloth modifier at any point to freeze the mesh in position at that frame. You can then re-enable the cloth, setting the start and end frames from which to run the simulation forward.

Another example of aging is a flag. Define the flag as a simple grid shape and pin the edge against the flagpole. Simulate for 50 frames or so, and the flag will drop to its “rest” position. Apply the Cloth modifier. If you want the flag to flap or otherwise move in the scene, re-enable it for the frame range when it is in camera view.

Smoothing of Cloth

Now, if you followed this from the previous section, your cloth is probably looking a little blocky. In order to make it look nice and smooth like the picture you need to apply a Smooth and/or Subsurf modifier in the Modifiers panel under the Editing context (F9). Then, in the same context, find the Links and Materials panel (the same one you used for vertex groups) and press Set Smooth.

Now, if you hit AltA, things are starting to look pretty nice, don’t you think?

Cloth on armature

Cloth deformed by armature and also respecting an additional collision object: Regression blend file.

Cloth with animated vertex groups

Cloth with animated pinned vertices: Regression blend file. UNSUPPORTED: Starting with a goal of 0 and increasing it, but still having the vertex not pinned will not work (e.g. from goal = 0 to goal = 0.5).

Cloth with Dynamic Paint

Cloth with Dynamic Paint using animated vertex groups: Regression blend file. UNSUPPORTED: Starting with a goal of 0 and increasing it, but still having the vertex not pinned will not work (e.g. from goal = 0 to goal = 0.5) because the necessary "goal springs" cannot be generated on the fly.

Using Cloth for Softbodies

Using cloth for softbodies.

Cloth can also be used to simulate softbodies. It’s for sure not its main purpose but it works nonetheless. The example image uses standard Rubber material, no fancy settings, just AltA.

Blend file for the example image: Using Cloth for softbodies.

Cloth with Wind

Flag with wind applied.

Regression blend file for Cloth with wind and self collisions (also the blend for the image above): Cloth flag with wind and selfcollisions.