Code vs Data Driven Displacement
February 28, 2023About 2 min
Code vs Data Driven Displacement
原文地址:https://theorangeduck.com/page/code-vs-data-driven-displacement
Definitions
The Simulation Object
把手柄输入转化为预测要移动的物体。
将输入转化为速度的代码:
vec3 desired_velocity_update(
const vec3 gamepadstick_left,
const float camera_azimuth,
const quat simulation_rotation,
const float fwrd_speed,
const float side_speed,
const float back_speed)
{
// Find stick position in world space by rotating using camera azimuth
vec3 global_stick_direction = quat_mul_vec3(
quat_from_angle_axis(camera_azimuth, vec3(0, 1, 0)), gamepadstick_left);
// Find stick position local to current facing direction
vec3 local_stick_direction = quat_inv_mul_vec3(
simulation_rotation, global_stick_direction);
// Scale stick by forward, sideways and backwards speeds
vec3 local_desired_velocity = local_stick_direction.z > 0.0 ?
vec3(side_speed, 0.0f, fwrd_speed) * local_stick_direction :
vec3(side_speed, 0.0f, back_speed) * local_stick_direction;
// Re-orientate into the world space
return quat_mul_vec3(simulation_rotation, local_desired_velocity);
}
The Character Entity
这就是玩家可以看到角色。角色的移动数据是来自动画切片,这种方式叫作数据驱动。
动画切片:https://github.com/ubisoft/ubisoft-laforge-animation-dataset
Simulation Bone
模拟骨骼是给模拟对象使用的,用来代表移动旋转。通常是骨骼的根节点。
为了最大程度的减少视觉物体和模拟物体之间的脱节,是将脊椎骨骼之一投影到地面上,然后使用Savitzky-Golay过滤器平滑其位置-使它作为模拟骨骼的位置。然后将髋骨向前的方向,投影到地面上,用同样的方法抹平。将其旋转为绕垂直轴的旋转,并将其用作模拟骨骼的旋转。
这个原理是,平滑消除了因臀部前后摆动而引起的任何晓得振荡和方向变化;更接近地匹配临界阻尼弹簧产出的运动风格。这种方式并不适用于循环动画和小块动画。
画出行走和奔跑两个动画,模拟骨骼的轨迹,如下图:

同样可以画出两个动画的速度,加速度,角度速度的变化图:

这里记录模拟物体移动的数据;
然后再把模拟物体移动的数据做图像化,把轨迹和速度画出来,并与原动画的数据画在一起如下:


可以看到上图中有很多重叠的部分,这就说明模拟对象和角色实体的模拟骨骼之间有相当不错的匹配。这就意味着,给我们拥有的动画数据和模拟对象设置,很有可能再模拟对象的运动和角色的运动之间实现良好的视觉匹配。
Character Controller
Synchronization
有两种方式:
- 直接使用模拟物体同步到角色:会出现滑步
- 由数据驱动模拟物体:这会造成延迟感
那么想到的方式就是直接混合这两者。