Unity自习室 您所在的位置:网站首页 unity前后左右行走代码 Unity自习室

Unity自习室

#Unity自习室| 来源: 网络整理| 查看: 265

Blend Trees

A common task in game animation is to blend between two or more similar motions. Perhaps the best known example is the blending of walking and running animations according to the character’s speed. Another example is a character leaning to the left or right as it turns during a run.

游戏动画里有一个常见的任务就是要将两个或者更多相似的运动之间进行混合。也许最熟知的例子就是根据角色的速度来混合走路和奔跑的动画。另一个例子就是角色在奔跑的过程中根据转向来决定角色倾向左侧或是右侧。

It is important to distinguish between Transitions and Blend Trees. While both are used for creating smooth animation, they are used for different kinds of situations.

区别转换和混合树很重要。虽然它们都是用来创造平滑的动画,但是它们的的适用场合却不一样。

· Transitions are used for transitioning smoothly from one Animation State to another over a given amount of time. Transitions are specified as part of an Animation State Machine. A transition from one motion to a completely different motion is usually fine if the transition is quick.

转换通常用于根据一个给定的具体时间来将一个动画状态平滑地转换到另一个动画状态。转换是被指定为Animation State Machine的一部分。如果转换的过程较为迅速,那么从一个运动转到一个完全不同的运动对于转换来说是非常合适的。

· Blend Trees are used for allowing multiple animations to be blended smoothly by incorporating parts of them all to varying degrees. The amount that each of the motions contributes to the final effect is controlled using a blending parameter, which is just one of the numeric animation parameters associated with the Animator Controller. In order for the blended motion to make sense, the motions that are blended must be of similar nature and timing. Blend Trees are a special type of state in an Animation State Machine.

混合树通常用来将多个动画合并在一起并且根据不同的度量将它们分配在不同区域,从而能够让这些动画平滑地进行混合。每个运动对最终效果的权重量是通过使用混合参数来控制的,而混合参数是与动画控制器关联的 animation parameters数值的一种。为了让混合的运动有意义,进行混合的运动必须要有相似的属性或者触发时机。混合树是动画状态机中状态的一种特殊类型。

Examples of similar motions could be various walk and run animations. In order for the blend to work well, the movements in the clips must take place at the same points in normalized time. For example, walking and running animations can be aligned so that the moments of contact of foot to the floor take place at the same points in normalized time (e.g. the left foot hits at 0.0 and the right foot at 0.5). Since normalized time is used, it doesn’t matter if the clips are of different length.

相似运动的例子可以是不同的走路和奔跑动画。为了让混合工作进展顺利,移动的动画片段需要发生在同一个标准化时间点上。例如,走路和奔跑动画可以被较准,从而让脚和地板触碰的时刻发生在同一个标准化时间点上(例如,左脚在0.0触碰,右脚在0.5触碰)。由于使用了标准化时间,所以并不用关心动画片段长度是否不同。

Using Blend Trees

To start working with a new Blend Tree, you need to:

1. Right-click on empty space on the Animator Controller Window.

在动画控制器窗口的空白区域右键。

2. Select Create State > From New Blend Tree from the context menu that appears.

在出现的菜单中选择 Create State > From New Blend Tree。

3. Double-click on the Blend Tree to enter the Blend Tree Graph.

双击混合树进入混合树图像。

The Animator Window now shows a graph of the entire Blend Tree while the Inspector shows the currently selected node and its immediate children.

动画窗口现在会显示整个混合树的图像,同时监视面板会展示当前选中节点以及它的直系子节点。

The Animator Window shows a graph of the entire Blend Tree. To the left is a Blend Tree with only the root Blend Node (no child nodes have been added yet). To the right is a Blend Tree with a root Blend Node and three Animation Clips as child nodes. ……左边的混合树只展示根节点。右边的混合树展示根节点以及作为子节点的3个动画片段。

To add animation clips to the blend tree you can select the blend tree, then click the plus icon in the motion field in the inspector.

如果想要给混合树添加动画片段,可以选择混合树,然后在监视面板中点击运动区域的加号按钮。

A Blend Node shown in the inspector before any motions have been added. The plus icon is used to add animation clips or child blend trees. 在添加运动之前混合树节点就已经在监视面板下显示了。点击加号按钮添加动画片段或者子混合树。

Alternatively, you can add animation clips or child blend nodes by right-clicking on the blend tree and selecting from the context menu:

另一种添加动画片段或者子混合节点的方式是右键点击混合树然后从菜单选择添加的项。

The context menu when right-clicking on a blend tree node. 右键混合树节点时出现的菜单。

When the blend tree is set up with Animation clips and input parameters, the inspector window gives a graphical visualization of how the animations are combined as the parameter value changes (as you drag the slider, the arrows from the tree root change their shading to show the dominant animation clip).

当混合树设置了动画片段以及输入参数时,监视器窗口会提供一个图形视图展示动画是如何按照参数值变化来结合的(随着你拖拽滑动条,树根节点的箭头会改变它们的着色用来展示动画片段所占据的区域)。

A 2D Blendtree set up with five animation clips, being previewed in the inspector 一个设置了5个动画片段的2D混合树,监视面板中有预览。

You can select any of the nodes in the Blend Tree graph to inspect it in the Inspector. If the selected node is an Animation Clip the Inspector for that Animation Clip will be shown. The settings will be read-only if the animation is imported from a model. If the node is a Blend Node, the Inspector for Blend Nodes will be shown.

你可以选择混合树图像中的任意节点从而在监视面板中查看它。如果选择的节点是动画片段,那么对应的动画片段会在监视面板中呈现。

You can choose either 1D or 2D blending from the Blend Type menu; the differences between the two types are described on their own pages in this section.

你可以在Blend Type菜单中选择混合类型是1D还是2D。下面两个部分将会具体描述两种呼和类型的区别。

Blend Trees and Root Motion

The blending between animations is handled using linear interpolation (ie, the amount of each animation is an average of the separate animations weighted by the blending parameter). However, you should note that root motion is not interpolated in the same way. See the page about root motion for further details about how this might affect your characters.

动画混合的方式是线性插值(也就是说,每个动画的占比量是混合参数对单独动画的加权平均值)。不过,你要注意的是根节点的运动不是按照这种方式插值的。详情见……

1D Blending

The first option in the Inspector of a Blend Node is the Blend Type. This drop-down is used to select one of the different blend types that can blend according to one or two parameters. 1D Blending blends the child motions according to a single parameter.

混合节点在监视面板的第一个选项就是混合类型。其下拉列表用来选择不同的混合类型,而混合类型分为根据1个还是2个参数进行混合。1D Blending是根据1个参数来混合子运动。

After setting the Blend Type, the first thing you need is to select the Animation Parameter that will control this Blend Tree. In this example, the parameter is direction which varies between –1.0 (left) and +1.0 (right), with 0.0 denoting a straight run without leaning.

选择了混合类型后,你要做的第一件事就是选择用于控制该混合的Animation Parameter。在这个例子中,这个参数是从-1.0(左)到+1.0(右)的方向,其中0.0表示没有偏向的奔跑。

Then you can add individual animations by clicking the small “+” button and selecting Add Motion Field from the popup menu. When you’re done, it should look something like this:

然后你可以通过点击“+”按钮然后从Add Motion Field里面的弹窗菜单中选择要添加的1个动画。

A 1D Blend Tree with three Animation Clips. 带有3个动画片段的1D混合树。

The diagram at the top of the Inspector shows the influence of each of the child motions as the parameter varies between its minimum and maximum values. Each motion is shown as a little blue pyramid (the first and last are only shown in half), and if you click and hold down the left mouse button on one them, the corresponding motion is highlighted in the motion list below. The peak of each pyramid defines the parameter value where the motion has full influence, meaning that its animation weight is 1 and the other animations have a weight of 0. This is also called the threshold of the motion.

监视面板顶部的图表展示了参数在最小值和最大值之间变化对每个子运动的影响。每个运动都以一个小蓝色金字塔(第一个和最后一个只显示一半)的形式展现,并且如果你在它们上面左键点击并且按住不放,对应的运动就会在下面的运动列表中高亮。每个金字塔的塔尖定义了运动产生完全影响的参数值,意味着它的动画权重为1而其它的动画权重为0。权重也叫做运动的阈值。

The diagram at the top of the Blend Tree Inspector visualizes the weights of the child motions over the range of the parameter values.

混合树监视面板图表的顶部展示了子运动随着参数范围而变化的权重。

The red vertical bar indicates the value of the Parameter. If you press Play in the Preview at the bottom of the Inspector and drag the red bar in the diagram left and right, you can see how the value of the parameter is controlling the blending of the different motions.

红色的垂直栏表明了参数的值。如果你点击了监视面板底部的预览窗口中的Play按钮,并将图表中的红色栏左右拖拽,就可以看到参数值是如何控制不同运动的混合。

Parameter Range

The range of the parameter used by the Blend Tree is shown below the diagram as two numbers to the left and right. Either one of them can be changed by clicking on the number and dragging left or right with the mouse. Note that the values correspond to the threshold of the first and last motion in the motion list.

混合树的参数范围显示在图表中左右两侧的数字。通过点击数字并左右拖拽可以改变它们其一的值。值得注意的是。参数值对应运动列表中的第一个和最后一个运动的阈值。

Thresholds

You can change the threshold value of a motion by clicking on its corresponding blue pyramid in the diagram and dragging it left or right. If the “Automate Thresholds” toggle is not enabled, you can also edit the threshold value of a motion in the motion list by typing in a number in the number field in the Threshold column.

你可以通过点击一个图表中运动对应的蓝色金字塔并左右拖动来改变它的阈值。如果“自动阈值”的复选框没有勾选,你也可以在阈值列中的数字输入栏区域输入数字来编辑运动列表中的运动阈值。

Below the motion list is the checkbox Automate Thresholds. Enabling it will distribute the thresholds of the motions evenly across the parameter range. For example, if there are five clips and the parameter ranges from –90 to +90, the thresholds will be set to –90, –45, 0, +45 and +90 in order.

在运动列表下方的是自动阈值的勾选框。启用它会在参数范围内对运动的阈值进行均匀分配。例如,如果有5个片段,并且参数范围为-90到+90,那么5个阈值就会依次为-90,-45,0,+45和+90。

The Compute Thresholds drop-down will set the thresholds from data of your choice obtained from the root motions in the Animation Clips. The data that is available to choose from is speed, velocity x, y, or z, and angular speed in degrees or radians. If your parameter corresponds to one of these properties, you can compute the thresholds using the Compute Thresholds drop-down.

Compute Thresholds下拉列表可以从位于动画片段中的根运动获取的参数选项里来设置阈值。可选择的参数有速率、速度的x,y,z以及以角度或者弧度表示的角速度。如果参数对应了其中的一个属性,你可以用Compute Thresholds下拉列表来计算阈值。

Say, for example, you had a walk animation that covered 1.5 units per second, a jog at 2.3 units per second, and a run at 4 units per second, choosing the Speed option from the drop-down would set the parameter range and thresholds for the three animations based on these values. So, if you set the speed parameter to 3.0, it would blend the jog and run with a slight bias toward the jog.

比如说,你有一个每秒移动1.5个单位的走路动画,一个每秒2.3个单位的慢跑动画,以及一个每秒4个单位的奔跑动画,从下拉列表中选择速率选项会为这仨动画基于速率值来设置参数范围和阈值。

2D Blending

The first option in the Inspector of a Blend Node is the Blend Type. This drop-down is used to select one of the different blend types that can blend according to one or two parameters. The 2D blending types blends the child motions according to two parameters.

…… 2D混合类型是通过2个参数来混合子运动。

The different 2D Blend Types have different uses that they are suitable for. They differ in how the influence of each motion is calculated.

不同的2D混合类型有不同的适用场合。它们的区别在于影响每个运动的计算方式。

2D Simple Directional: Best used when your motions represent different directions, such as “walk forward”, “walk backward”, “walk left”, and “walk right”, or “aim up”, “aim down”, “aim left”, and “aim right”. Optionally a single motion at position (0, 0) can be included, such as “idle” or “aim straight”. In the Simple Directional type there should not be multiple motions in the same direction, such as “walk forward” and “run forward”.

2D 简单定向:当你的运动代表了不同方向时,这种类型最好用。比如“向前走”……“向右瞄准”。可以选择包含一个位置为(0,0)的一个运动,例如“待机”或者“直接瞄准”。在这个模式下,相同方向上不应该有多个运动,例如“向前走”和“向前跑”。

2D Freeform Directional: This blend type is also used when your motions represent different directions, however you can have multiple motions in the same direction, for example “walk forward” and “run forward”. In the Freeform Directional type the set of motions should always include a single motion at position (0, 0), such as “idle”.

2D 自由定向:同样是适用于代表方向的运动,不过,这下你可以在相同的方向上有多个运动。例如“向前走”和“向前跑”。在该模式下,就必须要包含一个位置为(0,0)的运动,例如“待机”。

2D Freeform Cartesian: Best used when your motions do not represent different directions. With Freeform Cartesian your X parameter and Y parameter can represent different concepts, such as angular speed and linear speed. An example would be motions such as “walk forward no turn”, “run forward no turn”, “walk forward turn right”, “run forward turn right” etc.

2D 自由笛卡尔坐标系:当你的运动不是代表方向的时候,就用它。笛卡尔坐标系中的X和Y参数可以代表不同的概念,例如角速度和线性速度。一个例子是“向前走不转向”,“向前跑不转向”,“向前走且向右转”,“向前跑且向右转”等等。

Direct: This type of blend tree lets user control the weight of each node directly. Useful for facial shapes or random idle blending.

直接:这种模式允许用户直接控制每个节点的权重。对于面部形状或者随机待机的混合很实用。

After setting the Blend Type, the first thing you need is to select the two Animation Parameters that will control this Blend Tree. In this example, the parameters are velocityX (strafing) and velocityZ (forward speed).

…… 这个例子中参数分别为x向速度(扫射)和z向速度(向前的速率)。

Then you can add individual animations by clicking + -> Add Motion Field to add an Animation Clip to the blend tree. When you’re done, it should look something like this:

……

A 2D Blend Node with five Animation Clips. 带有5个动画片段的2D混合节点。

The positions in 2D blending are like the thresholds in 1D blending, except that there are two values instead of one, corresponding to each of the two parameters. Their positions along the horizontal X axis correspond to the first parameter, and their positions along the vertical Y axis correspond to the second parameter. A walking forward animation might have a velocity X of 0 and a velocity Z of 1.5, so those values should be typed into the Pos X and Pos Y number fields for the motion.

2D混合中的位置和1D混合中的阈值类似,只不过是用2个值代替1个值,这2个值分别对应着2个参数。沿着水平X轴的位置对应第一个值,而沿着垂直Y轴的位置对应第二个值。一个向前走的动画可能有一个0的X方向速度和一个1.5的Z方向速度,因此这些值应该输入到Pos X和Pos Y的输入框内,以用于动作。

The 2D Blending Diagram

The diagram at the top of the Inspector shows the positions of the child motions in the 2D blend space. The motions are shown as blue dots. Motions with no Animation Clip or Blend Tree assigned have no influence on the blend and are shown as gray dots. You can select a motion by clicking on its dot in the diagram. Once selected, the influence of that motion for each point in the blending space is visualized as a blue field. The field is strongest right under the position of the motion, where the motion has full influence, meaning that its animation weight is 1 and the other animations have a weight of 0. Further away the influence decreases as the influence of other motions take over.

监视器顶部的图表展示了在2D混合空间中的子动作的位置。动作以蓝色的点表示。不带有动画片段的或者混合树未指定的动作不会对混合产生任何影响,且会以灰色的点表示。你可以通过点击图表中的点来选择对应的动作。一旦选中,该动作对于混合空间中每一个点的影响将可视化为一个蓝色的区域。在动作正下方处的区域影响最大,此处的动作拥有绝对的影响值,这意味着它的动画权重为1而其它的动画权重为0。离该区域越远影响值会递减并被其它动作所接替。

The diagram at the top of the Blend Node Inspector visualizes the weights of the child motions over the extends of the parameter values.

混合节点监视器顶部的图表可视化了在参数值范围内的子动作。

The red dot indicates the values of the two Parameters. If you press Play in the Preview at the bottom of the Inspector and drag the red dot in the diagram around, you can see how the values of the parameters are controlling the blending of the different motions. In the diagram you can also see the influence of each motion represented as circles around each motion. You will see that if you move the red dot on top of one of the blue dots representing a motion, the circle for that motion gains its maximum radius and the circles for all other motions shrink down to nothing. At positions that are in between several motions, multiple of the nearby motions will have an influence on the blend. If you select one of the motions in order to see the blue influence field of that motion, you can see that as you move the red dot around, the circle size of the motion corresponds exactly with how strong the influence field is at various positions.

红点代表了2个参数的值。如果你点击位于监视器底部的预览窗口内的Play按钮,并在图表中拖拽红点,你就会看到参数的值是如何控制不同动作的混合。在图表中你也可以看到表现为环绕着每个动作的圆圈的动作影响。如果你移动了位于代表着动作的一个蓝点顶部的红点,那么你将会看到那个动作的圆圈获取了最大的半径,而其它动作的圆圈将会逐渐缩小至消失。在一个几个动作之间的位置上,多个临近的动作会对这个混合产生影响。如果你想要通过选中一个动作来查看该动作的蓝色影响区域,那么你可以选择四处移动红点来查看,动作的圆圈大小准确对应了不同位置的影响力。

When no motion is selected, the diagram shows a mix of all the influence fields that is more blue where a single motion dominates and less blue where many motions contribute to the blend.

当没有选中动作时,图表展示了一个所有影响区域的混合,某个单一动作的权重越大那里的颜色也越深,而如果是多个动作对混合都有影响,那么那个地方的颜色也就越浅。

Positions

You can change the positions of a motion by clicking on its corresponding blue dot in the diagram and dragging it around. You can also edit position coordinates of a motion in the motion list by typing in numbers in the number fields in the Pos X and Pos Y columns.

你可以通过点击图表中对应的蓝点并拖拽它来改变该动作的位置。也可以通过在动作列表中的数字区域输入Pos X和Pos Y的值来编辑动作位置的坐标。

The Compute Positions drop-down will set the positions from data of your choice obtained from the root motions in the Animation Clips. The data that is available to choose from is speed, velocity x, y, or z, and angular speed in degrees or radians. If one or both of your parameters correspond to one of these properties, you can compute the Pos X and/or Pos Y using the Compute Positions drop-down.

Compute Positions下拉菜单中可以从动画片段里的根动作中获取的选项数据来设置位置。数据可以是速率、xyz的速度、以及以角度或弧度表示的角速度。如果一个或者两个参数对应了其中的一种属性,你就可以用Compute Positions的下拉菜单来计算Pos X和Pos Y了。

Furthermore you can mix and match by choosing Compute Position -> X Position From and/or Compute Position -> Y Position From to only auto-compute one of them at a time, leaving the other unchanged.

另外你还可以通过选择Compute Position -> X Position From以及Compute Position -> Y Position From在同一时间内对它们中唯一自动计算的进行混合和匹配,并保证其它的动作不变。

Say, for example, that your parameters correspond to sideways velocity and forward velocity, and that you have an idle animation with an average velocity (0, 0, 0), a walk animation with (0, 0, 1.5), and two strafe animations with velocities of (–1.5, 0, 0) and (1.5, 0, 0) respectively. Choosing the Velocity XZ option from the drop-down would set the positions of the motions according to the X and Z coordinates of those velocities.

也就是说,比如你的参数对应了斜向速度和前向速度,并且你有一个平均速度为(0, 0, 0)的待机动画,一个速度为(0, 0, 1,5)的行走动画,以及两个速度分别为(-1.5, 0, 0)和(1.5, 0,  0)的扫射动画。从下拉菜单中选择Velocity XZ 这个选项,就能根据这些速度的X和Z坐标来设置对应动作的位置。

Direct Blending

Using a Direct Blend Tree allows you to map animator parameters directly to the weight of a BlendTree child. This can be useful if you want to have exact control over the various animations that are being blended rather than blend them indirectly using one or two parameters (in the case of 1D and 2D blend trees).

使用直接混合树可以让你直接将动画器的参数映射到混合树子树的权重值。如果你你想精确地控制各类正在混合的动画而不是通过用1或2个参数来混合,那么用直接混合最方便。

A Direct Blend Tree with five animation clips assigned.

指定了5个动画片段的直接混合树。

 

When setting up a direct blend tree, the inspector allows you to add motions to the motion list. Each motion should then be assigned a corresponding parameter to directly control its blend weight in the tree. Read more about creating Animator Parameters here.

当设置一个直接混合树时,监视器允许你在动作列表中添加动作。每个动作随后都要指定一个对应的参数来直接控制它在树中的混合权重。

In effect, this Direct mode simply bypasses the crossfading, or the various 2D blending algorithms (Freeform Directional, Freeform Cartesian, etc) and allows you to implement whatever code you like to control the mix of blended animations.

实际上,直接混合模式仅仅是绕过了交叉渐隐,或者是各种2D混合算法并且允许你执行你喜欢的任何代码来控制动画混合。

This can be particularly useful when mixing blend shape animations for facial expressions, or when blending together additive animations.

当混合面部表情的动画时特别实用,或者将额外添加的动画混合在一起。

The blend weights for each clip can be blended arbitrarily. 可以任意混合每个片段的权重。Additional Blend Tree Options

The options below are common to both 1D and 2D blending.

如下选项在1D和2D混合中常见。

Time Scale

You can alter the “natural” speed of the animation clips using the animation speed number fields (the columns with a clock icon at the top), so you could make the walk twice as fast by using a value of 2.0 as its speed. The Adjust Time Scale > Homogeneous Speed button rescales the speeds of the clips so that they correspond with the chosen minimum and maximum values of the parameter but keep the same relative speeds they initially had.

你可以通过使用动画速率输入区域(顶部的带有一个时钟图表的列)来改变动画片段的原本速率,因此你可以用一个速率为2.0的值来让走路快上2倍。 Adjust Time Scale > Homogeneous Speed 按钮重新改变了片段的速率以致它们对应了选中的参数最小和最大值的同时保证了各自原本相对速率的不变。

Note that the Adjust Time Scale drop-down is only available if all the motions are Animation Clips and not child Blend Trees.

注意 Adjust Time Scale下拉菜单只有在所有动作都是动画片段而非子混合树的情况下才可用。

Mirroring

You can mirror any humanoid Animation Clip in the motions list by enabling the mirror toggle at the far right. This feature enables you to use the same animation in its original form and in a mirrored version without needing twice the memory and space.

你可以通过勾选在最右边的镜像复选框来镜像复制任意动作列表中的humanoid动画片段。这个特性能够让你使用原来形式一样的动画,并且以镜像的版本可以无需占用2倍的内存和空间。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有