Skip to content

Commit 49dc898

Browse files
RisaDevCaraxi
andcommitted
Allow editor values to cross 0 when propagation is on (rewrite of #81)
Co-Authored-By: Caraxi <[email protected]>
1 parent ea608cf commit 49dc898

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

CustomizePlus/Core/Data/BoneTransform.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,18 @@ internal void OnDeserialized(StreamingContext context)
7171
_scaling = ClampToDefaultLimits(_scaling);
7272
}
7373

74-
public bool IsEdited()
74+
//"considerPropagationAsEdit" only should be true if you know what you are doing
75+
//currently is here only to allow bones to be not removed when live editing is off in the editor and propagation is on on the bone
76+
public bool IsEdited(bool considerPropagationAsEdit = false)
7577
{
78+
bool propagation = false;
79+
if (considerPropagationAsEdit)
80+
propagation = PropagateTranslation || PropagateRotation || PropagateScale;
81+
7682
return !Translation.IsApproximately(Vector3.Zero, 0.00001f)
7783
|| !Rotation.IsApproximately(Vector3.Zero, 0.1f)
78-
|| !Scaling.IsApproximately(Vector3.One, 0.00001f);
84+
|| !Scaling.IsApproximately(Vector3.One, 0.00001f)
85+
|| propagation;
7986
}
8087

8188
public BoneTransform DeepCopy()

CustomizePlus/Templates/Data/Template.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ public Template(Template original) : this()
6666
{
6767
foreach (var kvp in original.Bones)
6868
{
69+
if (!kvp.Value.IsEdited()) //do not copy unedited bones
70+
continue;
71+
6972
Bones[kvp.Key] = new BoneTransform();
7073
Bones[kvp.Key].UpdateToMatch(kvp.Value);
7174
}

CustomizePlus/Templates/TemplateManager.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void LoadTemplates()
6767
if (_templates.Any(f => f.UniqueId == template.UniqueId))
6868
throw new Exception($"ID {template.UniqueId} was not unique.");
6969

70-
PruneIdempotentTransforms(template);
70+
PruneUneditedBones(template);
7171

7272
_templates.Add(template);
7373
}
@@ -100,7 +100,7 @@ public Template Create(string name, Dictionary<string, BoneTransform>? bones, bo
100100
};
101101

102102
if (template.Bones.Count > 0)
103-
PruneIdempotentTransforms(template);
103+
PruneUneditedBones(template);
104104

105105
_templates.Add(template);
106106
_logger.Debug($"Added new template {template.UniqueId}.");
@@ -220,7 +220,7 @@ public bool ModifyBoneTransform(Template template, string boneName, BoneTransfor
220220
if (boneTransform == transform)
221221
return false;
222222

223-
if (transform.IsEdited())
223+
if (transform.IsEdited(true)) //true here to allow values of bones with propagations on to cross 0 during editing
224224
{
225225
template.Bones[boneName].UpdateToMatch(transform);
226226

@@ -240,7 +240,7 @@ public bool ModifyBoneTransform(Template template, string boneName, BoneTransfor
240240
else
241241
{
242242

243-
if (!transform.IsEdited())
243+
if (!transform.IsEdited(true)) //true here to allow values of bones with propagations on to cross 0 during editing
244244
return false;
245245

246246
template.Bones[boneName] = new BoneTransform(transform);
@@ -263,7 +263,7 @@ private void DeleteBoneTransform(Template template, string boneName)
263263
_event.Invoke(TemplateChanged.Type.DeletedBone, template, boneName);
264264
}
265265

266-
private static void PruneIdempotentTransforms(Template template)
266+
private void PruneUneditedBones(Template template)
267267
{
268268
foreach (var kvp in template.Bones)
269269
{
@@ -276,6 +276,8 @@ private static void PruneIdempotentTransforms(Template template)
276276

277277
private void SaveTemplate(Template template)
278278
{
279+
PruneUneditedBones(template);
280+
279281
template.ModifiedDate = DateTimeOffset.UtcNow;
280282
_saveService.QueueSave(template);
281283
}

0 commit comments

Comments
 (0)