Skip to content

Commit 782efbf

Browse files
authored
[PE] New fallback logic for missing bones (IllusionMods#195)
* [PE] Added fallback to GuideObject retrival [PE] Removed unised variables Signed-off-by: Lusiocc <252649741+Lusiocc@users.noreply.github.com> * [PE] code style fixes Signed-off-by: Lusiocc <252649741+Lusiocc@users.noreply.github.com> --------- Signed-off-by: Lusiocc <252649741+Lusiocc@users.noreply.github.com>
1 parent ab2de91 commit 782efbf

4 files changed

Lines changed: 74 additions & 21 deletions

File tree

Core.PoseEditor/AMModules/BlendShapesEditor.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,6 @@ private class BlendShapeData
9797
public float originalWeight;
9898
}
9999

100-
private class BlendLinkData
101-
{
102-
public SkinnedMeshRenderer renderer;
103-
public string blendName;
104-
}
105-
106100
#if HONEYSELECT || KOIKATSU
107101
[HarmonyPatch(typeof(FaceBlendShape), "LateUpdate")]
108102
private class FaceBlendShape_Patches
@@ -496,7 +490,6 @@ public void NonDirty(string blendName)
496490
private Vector2 _blendShapesScroll;
497491
private Vector2 _nonMatchBlendRendererScroll;
498492
private Vector2 _nonMatchBlendScroll;
499-
private int _headlessReconstructionTimeout = 0;
500493
private BlendRenderer _faceRenderer;
501494
private BlendRenderer _skinnedMeshTarget;
502495
private BlendRenderer _nonMatchTarget;

Core.PoseEditor/AMModules/BonesEditor.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Studio;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
43
using System.Linq;
54
using System.Text.RegularExpressions;
65
using System.Xml;
6+
using Studio;
77
using ToolBox.Extensions;
88
using UnityEngine;
99
using Vectrosity;
@@ -1021,9 +1021,10 @@ private void SetBoneTargetRotation(Quaternion rotation)
10211021
private void SetBoneRotation(Transform bone, Quaternion rotation)
10221022
{
10231023
OCIChar.BoneInfo value = null;
1024-
if (bone != null && _target.fkEnabled)
1024+
if (bone && _target.fkEnabled)
10251025
{
1026-
_target.fkObjects.TryGetValue(bone.gameObject, out value);
1026+
// ReSharper disable once Unity.PerformanceCriticalCodeInvocation
1027+
value = _target.GetBoneInfo(bone.gameObject);
10271028
}
10281029
if (value == null || !value.active)
10291030
{
@@ -1042,12 +1043,12 @@ internal void SetBoneTargetRotationFKNode(Quaternion rotation, bool pushValue)
10421043
}
10431044
OCIChar.BoneInfo value = null;
10441045
OCIChar.BoneInfo value2 = null;
1045-
_target.fkObjects.TryGetValue(_boneTarget.gameObject, out value);
1046+
value = _target.GetBoneInfo(_boneTarget.gameObject);
10461047
if (value != null && value.active)
10471048
{
1048-
if (_twinBoneTarget != null && value != null && value.active)
1049+
if (_twinBoneTarget != null)
10491050
{
1050-
_target.fkObjects.TryGetValue(_twinBoneTarget.gameObject, out value2);
1051+
value2 = _target.GetBoneInfo(_twinBoneTarget.gameObject);
10511052
}
10521053
SetBoneTargetRotationFKNode(rotation, pushValue, value, value2);
10531054
}
@@ -1183,8 +1184,8 @@ public override int SaveXml(XmlTextWriter xmlWriter)
11831184
xmlWriter.WriteAttributeString("posY", XmlConvert.ToString(kvp.Value.position.value.y));
11841185
xmlWriter.WriteAttributeString("posZ", XmlConvert.ToString(kvp.Value.position.value.z));
11851186
}
1186-
OCIChar.BoneInfo info;
1187-
if (kvp.Value.rotation.hasValue && (!_target.fkEnabled || !_target.fkObjects.TryGetValue(kvp.Key, out info) || info.active == false))
1187+
OCIChar.BoneInfo info = _target.GetBoneInfo(kvp.Key);
1188+
if (kvp.Value.rotation.hasValue && (!_target.fkEnabled || info == null || !info.active))
11881189
{
11891190
xmlWriter.WriteAttributeString("rotW", XmlConvert.ToString(kvp.Value.rotation.value.w));
11901191
xmlWriter.WriteAttributeString("rotX", XmlConvert.ToString(kvp.Value.rotation.value.x));
@@ -1321,13 +1322,14 @@ private void ResetBoneRot(Transform bone, Transform twinBone = null, bool withCh
13211322
if (depth == 64)
13221323
return;
13231324
TransformData data;
1324-
OCIChar.BoneInfo info;
1325-
if ((!_target.fkEnabled || !_target.fkObjects.TryGetValue(bone.gameObject, out info) || !info.active) && _dirtyBones.TryGetValue(bone.gameObject, out data))
1325+
OCIChar.BoneInfo info = _target.GetBoneInfo(bone.gameObject);
1326+
if ((!_target.fkEnabled || info == null || !info.active) && _dirtyBones.TryGetValue(bone.gameObject, out data))
13261327
{
13271328
data.rotation.Reset();
13281329
SetBoneNotDirtyIf(bone.gameObject);
13291330
}
1330-
if (_symmetricalEdition && twinBone != null && (!_target.fkEnabled || !_target.fkObjects.TryGetValue(twinBone.gameObject, out info) || !info.active) && _dirtyBones.TryGetValue(twinBone.gameObject, out data))
1331+
info = !twinBone ? null : _target.GetBoneInfo(twinBone.gameObject);
1332+
if (_symmetricalEdition && twinBone && (!_target.fkEnabled || info == null || !info.active) && _dirtyBones.TryGetValue(twinBone.gameObject, out data))
13311333
{
13321334
data.rotation.Reset();
13331335
SetBoneNotDirtyIf(twinBone.gameObject);

Core.PoseEditor/AMModules/GenericOCITarget.cs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using Studio;
2-
using System;
1+
using System;
32
using System.Collections.Generic;
3+
using System.Linq;
4+
using Studio;
45
using UnityEngine;
56

67
namespace HSPE.AMModules
@@ -77,5 +78,60 @@ public void RefreshFKBones()
7778
}
7879
}
7980

81+
public OCIChar.BoneInfo GetBoneInfo(GameObject go)
82+
{
83+
if (fkObjects.TryGetValue(go, out OCIChar.BoneInfo info))
84+
return info;
85+
86+
switch (type)
87+
{
88+
case Type.Character:
89+
{
90+
foreach (var bone in ociChar.listBones.Where(bone => bone.guideObject && bone.guideObject.transformTarget && bone.guideObject.transformTarget.gameObject == go))
91+
{
92+
if (!fkObjects.ContainsKey(go))
93+
fkObjects.Add(go, bone);
94+
return bone;
95+
}
96+
97+
if (ociChar.guideObject)
98+
{
99+
// Expensive fallback, but fine since it only handles missing GuideObjects and caches them.
100+
// ReSharper disable once Unity.PerformanceCriticalCodeInvocation
101+
foreach (GuideObject guide in ociChar.guideObject.transform.GetComponentsInChildren<GuideObject>(true))
102+
{
103+
if (guide.transformTarget != go.transform) continue;
104+
if (!ociChar.oiCharInfo.bones.TryGetValue(guide.dicKey, out OIBoneInfo oiBoneInfo)) continue;
105+
#if KOIKATSU || AISHOUJO || HONEYSELECT2
106+
var newBone = new OCIChar.BoneInfo(guide, oiBoneInfo, 0);
107+
#else
108+
var newBone = new OCIChar.BoneInfo(guide, oiBoneInfo);
109+
#endif
110+
if (!fkObjects.ContainsKey(go))
111+
fkObjects.Add(go, newBone);
112+
return newBone;
113+
}
114+
}
115+
116+
break;
117+
}
118+
case Type.Item:
119+
{
120+
if (ociItem.listBones != null)
121+
{
122+
foreach (var bone in ociItem.listBones.Where(bone => bone.guideObject && bone.guideObject.transformTarget && bone.guideObject.transformTarget.gameObject == go))
123+
{
124+
if (!fkObjects.ContainsKey(go))
125+
fkObjects.Add(go, bone);
126+
return bone;
127+
}
128+
}
129+
130+
break;
131+
}
132+
}
133+
return null;
134+
}
135+
80136
}
81137
}

Core.PoseEditor/PoseController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public enum DragType
3939
internal BlendShapesEditor _blendShapesEditor;
4040
internal CollidersEditor _collidersEditor;
4141
internal IKEditor _ikEditor;
42+
#if AISHOUJO || HONEYSELECT2
4243
internal ClothesTransformEditor _clothesTransformEditor;
44+
#endif
4345
protected readonly List<AdvancedModeModule> _modules = new List<AdvancedModeModule>();
4446
protected AdvancedModeModule _currentModule;
4547
internal GenericOCITarget _target;

0 commit comments

Comments
 (0)