From 03fa5575bf1be5c8618aea705b18fbbd73e99264 Mon Sep 17 00:00:00 2001 From: dexy Date: Sat, 9 Nov 2019 21:07:41 +1100 Subject: [PATCH] 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) --- .../GameFiles/Resources/Drawable.cs | 2 +- Peds/PedsForm.cs | 20 +++++++++- Rendering/Renderable.cs | 37 +++++++++++++++++++ Rendering/Shaders/BasicShader.cs | 8 ++++ Rendering/Shaders/ShadowShader.cs | 8 ++++ 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/CodeWalker.Core/GameFiles/Resources/Drawable.cs b/CodeWalker.Core/GameFiles/Resources/Drawable.cs index c779499..6159a61 100644 --- a/CodeWalker.Core/GameFiles/Resources/Drawable.cs +++ b/CodeWalker.Core/GameFiles/Resources/Drawable.cs @@ -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; } diff --git a/Peds/PedsForm.cs b/Peds/PedsForm.cs index 8b43077..6897f63 100644 --- a/Peds/PedsForm.cs +++ b/Peds/PedsForm.cs @@ -1197,7 +1197,25 @@ namespace CodeWalker.Peds var skel = SelectedPed.Yft?.Fragment?.Drawable?.Skeleton; if (skel != null) { - drawable.Skeleton = skel;//force the drawable to use this skeleton. + 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; + } + } + } } diff --git a/Rendering/Renderable.cs b/Rendering/Renderable.cs index cd429e0..e1b1888 100644 --- a/Rendering/Renderable.cs +++ b/Rendering/Renderable.cs @@ -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[] diff --git a/Rendering/Shaders/BasicShader.cs b/Rendering/Shaders/BasicShader.cs index 9aafcd6..0d8ad01 100644 --- a/Rendering/Shaders/BasicShader.cs +++ b/Rendering/Shaders/BasicShader.cs @@ -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) diff --git a/Rendering/Shaders/ShadowShader.cs b/Rendering/Shaders/ShadowShader.cs index 29d9256..a2b18d0 100644 --- a/Rendering/Shaders/ShadowShader.cs +++ b/Rendering/Shaders/ShadowShader.cs @@ -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)