Fix for bones on peds drawables with existing skeletons. Also included code to use geometry-specific bone matrices where boneIds array is used, but commented out since it never seems necessary (leaving in for reference)

This commit is contained in:
dexy 2019-11-09 21:07:41 +11:00
parent 20545145a5
commit 03fa5575bf
5 changed files with 73 additions and 2 deletions

View File

@ -924,7 +924,7 @@ namespace CodeWalker.GameFiles
var pbone = Parent;
while (pbone != null)
{
pos = pbone.AnimRotation.Multiply(pos) + pbone.AnimTranslation;
pos = pbone.AnimRotation.Multiply(pos * pbone.AnimScale) + pbone.AnimTranslation;
ori = pbone.AnimRotation * ori;
pbone = pbone.Parent;
}

View File

@ -1196,9 +1196,27 @@ namespace CodeWalker.Peds
var skel = SelectedPed.Yft?.Fragment?.Drawable?.Skeleton;
if (skel != null)
{
if (drawable.Skeleton == null)
{
drawable.Skeleton = skel;//force the drawable to use this skeleton.
}
else if (drawable.Skeleton != skel)
{
var dskel = drawable.Skeleton; //put the bones of the fragment into the drawable. drawable's bones in this case seem messed up!
for (int b = 0; b < skel.Bones.Count; b++)
{
var srcbone = skel.Bones[b];
var dstbone = srcbone;
if (dskel.BonesMap.TryGetValue(srcbone.Tag, out dstbone))
{
if (srcbone == dstbone) break; //bone reassignment already done!
dskel.Bones[dstbone.Index] = srcbone;
dskel.BonesMap[srcbone.Tag] = srcbone;
}
}
}
}
Renderer.RenderDrawable(drawable, null, null, 0, td, texture, ac);

View File

@ -384,6 +384,41 @@ namespace CodeWalker.Rendering
bt.Row3 = b.Column3;
BoneTransforms[i] = bt;
}
//var drawbl = Key;
//if (AllModels == null) return;
//for (int i = 0; i < AllModels.Length; i++)
//{
// var model = AllModels[i];
// if (model?.Geometries == null) continue;
// for (int g = 0; g < model.Geometries.Length; g++)
// {
// var geom = model.Geometries[g];
// var boneids = geom?.DrawableGeom?.BoneIds;
// if (boneids == null) continue;
// if (boneids.Length != Bones.Count)
// {
// var idc = boneids.Length;
// if (geom.BoneTransforms == null)
// {
// geom.BoneTransforms = new Matrix3_s[idc];
// }
// for (int b = 0; b < idc; b++)
// {
// var id = boneids[b];
// if (id < BoneTransforms.Length)
// {
// geom.BoneTransforms[b] = BoneTransforms[id];
// if (id != b)
// { }
// }
// else
// { }
// }
// }
// }
//}
}
@ -756,6 +791,8 @@ namespace CodeWalker.Rendering
public bool isHair = false;
public bool disableRendering = false;
//public Matrix3_s[] BoneTransforms = null;
public static ShaderParamNames[] GetTextureSamplerList()
{
return new ShaderParamNames[]

View File

@ -796,6 +796,14 @@ namespace CodeWalker.Rendering
{
tintpal.SetVSResource(context, 0);
}
//if (geom.BoneTransforms != null)
//{
// SetBoneMatrices(context, geom.BoneTransforms);
// defaultBoneMatricesBound = false;
//}
}
public void SetBoneMatrices(DeviceContext context, Matrix3_s[] matrices)

View File

@ -356,6 +356,14 @@ namespace CodeWalker.Rendering
{
texture.SetPSResource(context, 0);
}
//if (geom.BoneTransforms != null)
//{
// SetBoneMatrices(context, geom.BoneTransforms);
// defaultBoneMatricesBound = false;
//}
}
public void SetBoneMatrices(DeviceContext context, Matrix3_s[] matrices)