I'm a bit confused about these classes extending JSONStorable, I see they are usually used in UI components (Utils from MacGruber for example)
But are they only required if we need to persiste the state of those components?
I mean if I'm creating components dynamically and use components from MacGruber they will make a mess in the final json creating when saving the scene?
Example:
I'm saving in my plugin the current active morphs in a List (to save keyframe of different facial expressions)
In my UI the user can then select any of those keyframes, the morphs are applied and I want to show a slider for those morphs too so the user can edit them
But I don't need to persist these sliders (or maybe yes, I don't know how to save the state of my plugin with the list of morphs and their settings yet)
I'm doing something like this now:
And when a new Keyframe is selected I remove all the sliders and create new ones:
It works fine, but I'm not sure if this is the correct way to work in VAM
But are they only required if we need to persiste the state of those components?
I mean if I'm creating components dynamically and use components from MacGruber they will make a mess in the final json creating when saving the scene?
Example:
I'm saving in my plugin the current active morphs in a List (to save keyframe of different facial expressions)
In my UI the user can then select any of those keyframes, the morphs are applied and I want to show a slider for those morphs too so the user can edit them
But I don't need to persist these sliders (or maybe yes, I don't know how to save the state of my plugin with the list of morphs and their settings yet)
I'm doing something like this now:
Code:
private void UpdateCurrentKeyframeMorphs()
{
List<DAZMorph> activeExpressionMorphs = GetAllActiveMorphs(true);
MorphKeyFrame frame = morphFrames[currentKeyframeIndexActive];
frame.morphsAndValues = new List<MorphUidAndValue>();
foreach (var morph in activeExpressionMorphs)
{
frame.AddMorphAndValue(new MorphUidAndValue(morph.uid, morph.appliedValue, morph.morphName));
}
}
private UIDynamicSlider CreateMorphSlider(DAZMorph morph)
{
string morphName = morph.morphName;
float defaultValue = morph.jsonFloat.defaultVal;
float min = morph.jsonFloat.min;
float max = morph.jsonFloat.max;
JSONStorableFloat storable = new JSONStorableFloat(morphName, defaultValue, min, max, true, true);
storable.storeType = JSONStorableParam.StoreType.Full;
UIDynamicSlider slider = this.CreateSlider(storable, true);
this.RegisterFloat(storable);
storable.valNoCallback = morph.morphValue;
// storable.val = morph.morphValue;
storable.setCallbackFunction += (float newVal) =>
{
morph.morphValue = newVal;
// appliedValue ??
UpdateCurrentKeyframeMorphs();
};
return slider;
}
And when a new Keyframe is selected I remove all the sliders and create new ones:
Code:
private void RefreshMorphSlidersForKeyframe(int selectedKeyframe)
{
Utils.RemoveUIElements(this, morphSliders.Cast<object>().ToList());
morphSliders = new List<UIDynamicSlider>();
if(selectedKeyframe >= 0 && morphFrames.Count() > selectedKeyframe)
{
foreach (MorphUidAndValue muv in morphFrames[selectedKeyframe].morphsAndValues)
{
DAZMorph morph = GetMorphByUid(muv.uid);
morphSliders.Add(CreateMorphSlider(morph));
}
}
}
It works fine, but I'm not sure if this is the correct way to work in VAM