mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2025-01-10 07:42:56 +08:00
PR #241 but maybe slightly optimized
This commit is contained in:
parent
e5dc63f429
commit
6d24603bf0
@ -87,6 +87,8 @@ namespace CodeWalker.Rendering
|
|||||||
public Dictionary<ushort, RenderableModel> ModelBoneLinks;
|
public Dictionary<ushort, RenderableModel> ModelBoneLinks;
|
||||||
|
|
||||||
public bool EnableRootMotion = false; //used to toggle whether or not to include root motion when playing animations
|
public bool EnableRootMotion = false; //used to toggle whether or not to include root motion when playing animations
|
||||||
|
public Vector3 RootMotionPosition;
|
||||||
|
public Quaternion RootMotionRotation;
|
||||||
|
|
||||||
public ClothInstance Cloth;
|
public ClothInstance Cloth;
|
||||||
|
|
||||||
@ -483,6 +485,8 @@ namespace CodeWalker.Rendering
|
|||||||
}
|
}
|
||||||
private void UpdateAnim(ClipMapEntry cme)
|
private void UpdateAnim(ClipMapEntry cme)
|
||||||
{
|
{
|
||||||
|
RootMotionPosition = Vector3.Zero;
|
||||||
|
RootMotionRotation = Quaternion.Identity;
|
||||||
|
|
||||||
var clipanim = cme.Clip as ClipAnimation;
|
var clipanim = cme.Clip as ClipAnimation;
|
||||||
if (clipanim?.Animation != null)
|
if (clipanim?.Animation != null)
|
||||||
@ -500,6 +504,57 @@ namespace CodeWalker.Rendering
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var bonesmap = Skeleton?.BonesMap;
|
||||||
|
var bones = Skeleton?.BonesSorted;
|
||||||
|
if (bones != null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < bones.Length; i++)
|
||||||
|
{
|
||||||
|
var bone = bones[i];
|
||||||
|
var tag = bone.Tag;
|
||||||
|
switch (bone.Tag)
|
||||||
|
{
|
||||||
|
case 23639: tag = 58271; break; //RB_L_ThighRoll: SKEL_L_Thigh
|
||||||
|
case 6442: tag = 51826; break; //RB_R_ThighRoll: SKEL_R_Thigh
|
||||||
|
//case 61007: tag = 61163; break; //RB_L_ForeArmRoll: SKEL_L_Forearm //NOT GOOD
|
||||||
|
//case 5232: tag = 45509; break; //RB_L_ArmRoll: SKEL_L_UpperArm
|
||||||
|
}
|
||||||
|
if ((tag != bone.Tag) && (tag != bone.Parent?.Tag))
|
||||||
|
{
|
||||||
|
if ((bonesmap != null) && bonesmap.TryGetValue(tag, out var obone))
|
||||||
|
{
|
||||||
|
bone.AnimRotation = obone.AnimRotation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < bones.Length; i++)
|
||||||
|
{
|
||||||
|
var bone = bones[i];
|
||||||
|
|
||||||
|
if (EnableRootMotion && (bone.Tag == 0))
|
||||||
|
{
|
||||||
|
bone.AnimTranslation = RootMotionPosition + RootMotionRotation.Multiply(bone.AnimTranslation);
|
||||||
|
bone.AnimRotation = RootMotionRotation * bone.AnimRotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
bone.UpdateAnimTransform();
|
||||||
|
bone.UpdateSkinTransform();
|
||||||
|
|
||||||
|
//update model's transform from animated bone
|
||||||
|
RenderableModel bmodel = null;
|
||||||
|
ModelBoneLinks?.TryGetValue(bone.Tag, out bmodel);
|
||||||
|
|
||||||
|
|
||||||
|
if (bmodel == null)
|
||||||
|
{ continue; }
|
||||||
|
if (bmodel.IsSkinMesh) //don't transform model for skin mesh
|
||||||
|
{ continue; }
|
||||||
|
|
||||||
|
bmodel.Transform = bone.AnimTransform;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void UpdateAnim(Animation anim, float t)
|
private void UpdateAnim(Animation anim, float t)
|
||||||
{
|
{
|
||||||
@ -570,18 +625,12 @@ namespace CodeWalker.Rendering
|
|||||||
bone.AnimScale = v.XYZ();
|
bone.AnimScale = v.XYZ();
|
||||||
break;
|
break;
|
||||||
case 5://root motion vector
|
case 5://root motion vector
|
||||||
if (EnableRootMotion)
|
|
||||||
{
|
|
||||||
v = anim.EvaluateVector4(frame, i, interpolate);
|
v = anim.EvaluateVector4(frame, i, interpolate);
|
||||||
bone.AnimTranslation += v.XYZ();
|
RootMotionPosition += v.XYZ();
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 6://quaternion... root rotation
|
case 6://quaternion... root rotation
|
||||||
if (EnableRootMotion)
|
|
||||||
{
|
|
||||||
q = anim.EvaluateQuaternion(frame, i, interpolate);
|
q = anim.EvaluateQuaternion(frame, i, interpolate);
|
||||||
bone.AnimRotation = q * bone.AnimRotation;
|
RootMotionRotation *= q;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 7://vector3... (camera position?)
|
case 7://vector3... (camera position?)
|
||||||
break;
|
break;
|
||||||
@ -620,47 +669,6 @@ namespace CodeWalker.Rendering
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < bones.Length; i++)
|
|
||||||
{
|
|
||||||
var bone = bones[i];
|
|
||||||
var tag = bone.Tag;
|
|
||||||
switch (bone.Tag)
|
|
||||||
{
|
|
||||||
case 23639: tag = 58271; break; //RB_L_ThighRoll: SKEL_L_Thigh
|
|
||||||
case 6442: tag = 51826; break; //RB_R_ThighRoll: SKEL_R_Thigh
|
|
||||||
//case 61007: tag = 61163; break; //RB_L_ForeArmRoll: SKEL_L_Forearm //NOT GOOD
|
|
||||||
//case 5232: tag = 45509; break; //RB_L_ArmRoll: SKEL_L_UpperArm
|
|
||||||
}
|
|
||||||
if ((tag != bone.Tag) && (tag != bone.Parent?.Tag))
|
|
||||||
{
|
|
||||||
var obone = bone;
|
|
||||||
if (skel.BonesMap.TryGetValue(tag, out obone))
|
|
||||||
{
|
|
||||||
bone.AnimRotation = obone.AnimRotation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < bones.Length; i++)
|
|
||||||
{
|
|
||||||
var bone = bones[i];
|
|
||||||
bone.UpdateAnimTransform();
|
|
||||||
bone.UpdateSkinTransform();
|
|
||||||
|
|
||||||
//update model's transform from animated bone
|
|
||||||
RenderableModel bmodel = null;
|
|
||||||
ModelBoneLinks?.TryGetValue(bone.Tag, out bmodel);
|
|
||||||
|
|
||||||
|
|
||||||
if (bmodel == null)
|
|
||||||
{ continue; }
|
|
||||||
if (bmodel.IsSkinMesh) //don't transform model for skin mesh
|
|
||||||
{ continue; }
|
|
||||||
|
|
||||||
bmodel.Transform = bone.AnimTransform;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
private void UpdateAnimUV(ClipMapEntry cme, RenderableGeometry rgeom = null)
|
private void UpdateAnimUV(ClipMapEntry cme, RenderableGeometry rgeom = null)
|
||||||
|
Loading…
Reference in New Issue
Block a user