Exemplo n.º 1
0
        public static HairStyle CreateFromPerson(Atom aPerson)
        {
            HairStyle            newHair   = new HairStyle();
            DAZCharacterSelector character = aPerson?.GetStorableByID("geometry") as DAZCharacterSelector;

            // Find relevant storables
            JSONStorable moveContainer = FindStorableByName(aPerson, "ScalpContainer", true);

            if (null == moveContainer)
            {
                return(null);
            }
            JSONStorable hairSettings = FindStorableByName(aPerson, "HairSettings");
            JSONStorable scalps       = FindStorableByName(aPerson, "Scalps");
            JSONStorable styles       = FindStorableByName(aPerson, "Styles");

            // Get Style and Scalp choices
            string scalpName = scalps.GetStringChooserParamValue("choiceName");
            string styleName = styles.GetStringChooserParamValue("choiceName");

            // Scalp store name is based on scalp name, so find the correct storable based on it
            JSONStorable scalpStorable = null;

            if (scalpName != "NoScalp")
            {
                scalpStorable = FindStorableByName(aPerson, scalpName.Replace("Scalp", "HairScalp"));
            }

            List <JSONStorable> saveList = new List <JSONStorable>();

            saveList.Add(styles);
            saveList.Add(scalps);
            saveList.Add(moveContainer);
            saveList.Add(hairSettings);
            if (scalpStorable != null)
            {
                saveList.Add(scalpStorable);
            }


            // Create save
            JsonDict newSaveStorable;

            foreach (var storable in saveList)
            {
                string saveName = storable.name;
                // Scalp storable name changes depending on scalp, so we'll rename it to a constant name
                if (storable == scalpStorable)
                {
                    saveName = "scalpParams";
                }
                newHair.SaveStorable(storable, out newSaveStorable);
                newHair._savedJson[saveName] = newSaveStorable;
            }

            return(newHair);
        }
Exemplo n.º 2
0
        public void ApplyToPerson(Atom aPerson, bool aColor = true, bool aStyle = true, bool aPhysics = true)
        {
            DAZCharacterSelector character = aPerson.GetStorableByID("geometry") as DAZCharacterSelector;
            List <string>        hairSettingsRestoreList = new List <string>();
            List <string>        restoreStorablesList    = new List <string>();

            HairStyle origStyle = null;

            // Colors are stored per-style. If we change styles, but not color, the color will change.
            // So, if we are changing style but not color, we need to store off the current color and
            // restore it after the style change to ensure the color doesn't actually change.
            if (aStyle && !aColor)
            {
                origStyle = HairStyle.CreateFromPerson(aPerson);
            }

            JSONStorable scalps = FindStorableByName(aPerson, "Scalps");
            JSONStorable styles = FindStorableByName(aPerson, "Styles");

            // Apply any style changes so we are sure to apply modifications to the correct style
            if (aStyle)
            {
                RestoreStorable(scalps, _savedJson["Scalps"]);
                RestoreStorable(styles, _savedJson["Styles"]);
            }

            // Now that any style change is done, let's get the rest of the storables
            JSONStorable moveContainer = FindStorableByName(aPerson, "ScalpContainer");
            JSONStorable hairSettings  = FindStorableByName(aPerson, "HairSettings");

            // Get Style and Scalp choices
            string       scalpName     = scalps.GetStringChooserParamValue("choiceName");
            JSONStorable scalpStorable = null;

            if (scalpName != "NoScalp")
            {
                scalpStorable = FindStorableByName(aPerson, scalpName.Replace("Scalp", "HairScalp"));
            }

            // HairSettings contains color, style and physics, so has a special-case filter list
            if (aColor)
            {
                restoreStorablesList.AddRange(colorLoadList);
                hairSettingsRestoreList.AddRange(simColorList);
            }
            if (aStyle)
            {
                restoreStorablesList.AddRange(styleLoadList);
                hairSettingsRestoreList.AddRange(simStyleList);
                // Scalp style has already been restored, if applicable.
            }
            if (aPhysics)
            {
                restoreStorablesList.AddRange(physicsLoadList);
                hairSettingsRestoreList.AddRange(simPhysicsList);
            }

            foreach (var saveGroup in _savedJson)
            {
                List <string> restoreList = null;
                string        groupName   = saveGroup.Key;
                if (!restoreStorablesList.Contains(groupName))
                {
                    continue;
                }

                // Hair Settings contains all parameters for sim hair so must be filtered
                if (groupName == "HairSettings")
                {
                    restoreList = hairSettingsRestoreList;
                }

                // Scalp params are stored per-style, but saved as scalpParams. Adjust the name to the current style.
                if (groupName == "scalpParams")
                {
                    if (null != scalpStorable)
                    {
                        groupName = scalpStorable.name;
                    }
                    else
                    {
                        continue; // Can't save scalp parameters when there is no scalp
                    }
                }

                // Restore the setting!
                var storable = FindStorableByName(aPerson, groupName);
                RestoreStorable(storable, saveGroup.Value, restoreList);
            }

            // If we switched styles without loading color, then copy over the color from the last style
            origStyle?.ApplyToPerson(aPerson, true, false, false);
        }