using System; using UnityEngine; using System.Collections.Generic; using MVR.FileManagementSecure; using System.Linq; using SimpleJSON; using System.Collections; namespace ky1001 { public class PoseLoader : MVRScript { #region PluginInfo public string pluginAuthor = "ky1001"; public string pluginName = "PoseLoader"; public string pluginVersion = "11.0"; public string pluginDate = "2023-01-10"; public string pluginDescription = ""; #endregion #region Vars private const string _vapPosePath = "Custom/Atom/Person/Pose"; private const string _jsonPosePath = "Saves/Person/pose"; private const string _jsonScenePath = "Saves/scene"; private const string _addonPackagesPath = "AddonPackages"; private const string _filePrefs = "AddonPackagesFilePrefs/"; private const int _jsonstringLimit = 15000; private string LoadData; private string ext; private string reload; private string loadDir; private string vapPreviousFolder; private string jsonPreviousFolder; private string scenePreviousFolder; private string SELF; protected JSONStorableStringChooser selectControl; protected JSONStorableStringChooser selectDirection; protected JSONStorableStringChooser selectPerson; private JSONStorableBool collision_bool; private UIDynamicToggle collision_toggle; private JSONStorableBool base_bool; private UIDynamicToggle base_toggle; private JSONStorableBool invertDirect_bool; private UIDynamicToggle invertDirect_toggle; private JSONStorableBool controlOn_bool; private UIDynamicToggle controlOn_toggle; private JSONStorableBool useRigidData_bool; private UIDynamicToggle useRigidData_toggle; private JSONStorableBool shortcuts_Bool; private UIDynamicToggle shortcuts_toggle; private JSONStorableBool keepFolder_Bool; private UIDynamicToggle keepFolder_toggle; private JSONStorableBool resetFaceMorph_Bool; private UIDynamicToggle resetFaceMorph_toggle; private JSONStorableBool resetExpression_Bool; private UIDynamicToggle resetExpression_toggle; private JSONStorableString filename; private UIDynamicTextField messageBox; private JSONStorableString persons; private Dictionary atomControlsId = new Dictionary(); private Dictionary atomControlsPosiState = new Dictionary(); private Dictionary atomControlsRotaState = new Dictionary(); private Dictionary atomControlsPosi = new Dictionary(); private Dictionary atomControlsRota = new Dictionary(); private Dictionary atomControlsLink = new Dictionary(); private Dictionary atomRigidbodyPosi = new Dictionary(); private Dictionary atomRigidbodyRota = new Dictionary(); private Dictionary atomControlsPosiF = new Dictionary(); private Dictionary atomControlsRotaF = new Dictionary(); private Dictionary atomControlsPosiT = new Dictionary(); private Dictionary atomControlsRotaT = new Dictionary(); private Dictionary morphList = new Dictionary(); private Dictionary controlAndRigibodyList = new Dictionary(); private List personList = new List(); private List ControlList = new List(); private List RigidbodyList = new List(); private JSONNode jSONNode; private JSONArray atomArray; private JSONArray asArray; private JSONArray morphsAsArray; private JSONClass asAtomObject; private JSONClass asObject; private JSONClass morphs; protected Atom TargetAtom; private Vector3 rootPosi; private Vector3 rootRota; private Vector3 targetAtomPosi; private Quaternion targetAtomRota; private string id; private float minControl; private string minControlName; private bool zeroControl; private bool sceneBool; private bool reloadBool; Dictionary PosiST = new Dictionary(); Dictionary RotaST = new Dictionary(); private Rigidbody linkToAtom; private FreeControllerV3 CurrentController; JSONStorable geometry; DAZCharacterSelector character; GenerateDAZMorphsControlUI morphControl; JSONStorable geometry2; DAZCharacterSelector character2; GenerateDAZMorphsControlUI morphControl2; //private bool _isTopMenu = false; private int _menu = 2; private JSONStorableBool _enableRnd; private JSONStorableBool _enableSubfolder; private int _previousNumber; private string _poseListText; private string _favListText; private List _poseList = new List(); private List _favList = new List(); private List _poseFileList = new List(); private List _randomOrder = new List(); private JSONStorableString _poseDirectory; private JSONStorableBool _onlyFav; private JSONStorableString _currentPose; private JSONStorableString _filesInFolder; private JSONStorableBool _enableAutoLoad; private JSONStorableStringChooser _selectCount; private UIDynamicButton selectScene; private UIDynamicButton loadScene; private UIDynamicPopup selectPersonPop; private UIDynamicButton _loadPoseContButton; private UIDynamicToggle _enableAutoLoadToggle; private UIDynamicPopup _selectCountPop; private UIDynamicToggle _enableRndToggle; private UIDynamicToggle _enableSubfolderToggle; private UIDynamicToggle _onlyFavToggle; private UIDynamicButton _setVapPoseDirectoryButton; private UIDynamicButton _setJsonPoseDirectoryButton; private UIDynamicTextField _currentPoseText; private UIDynamicTextField _filesInFolderText; private UIDynamicToggle _isUseIncludedDataToggle; private JSONStorableBool _enablePathInSceneVar; private string _sceneVar; private string _varFileName; private bool _isMakePoseList; private bool _loopStart; private int _startTime; private Dictionary _morphDic = new Dictionary(); private List _poseMorph = new List(); private JSONStorableBool _enableCollision; private JSONStorableBool _enableDisable; private bool _isExistRigidData; private JSONStorableBool _isUseNewType; private UIDynamicToggle _isUseNewTypeToggle; private float _minRigid; private float _minControl; private Dictionary _rigidbodyPosiLocal = new Dictionary(); private Dictionary _rigidbodyRotaLocal = new Dictionary(); private Dictionary _rigidbodyPosiWorld = new Dictionary(); private Dictionary _rigidbodyRotaWorld = new Dictionary(); private List _boolParame = new List(); private List _floatParame = new List(); private JSONStorableBool _isKeepPosition; private UIDynamicToggle _isKeepPositionToggle; private bool _isExistControl; private List _readedControl = new List(); private List _readedRigidbody = new List(); private UIDynamicButton _loadCouplePoseButton; private UIDynamicButton _selectPose1Button; private UIDynamicButton _selectPose2Button; private UIDynamicPopup _selectPersonPopup; private JSONStorableStringChooser _selectPerson2; private Atom _2ndPerson; private string _pathFor1stPose; private string _pathFor2ndPose; private JSONStorableString _pathFor1stPoseString; private JSONStorableString _pathFor2ndPoseString; private UIDynamicTextField _pathFor1stPoseText; private UIDynamicTextField _pathFor2ndPoseText; private bool _isCurrent; #endregion private readonly string[] fullControlNames = new string[] { "hipControl", "pelvisControl", "rThighControl", "rKneeControl", "rFootControl", "rToeControl", "lThighControl", "lKneeControl", "lFootControl", "lToeControl", "penisBaseControl", "penisMidControl", "penisTipControl", "testesControl", "abdomenControl", "abdomen2Control", "chestControl", "lNippleControl", "rNippleControl", "rShoulderControl", "rArmControl", "rElbowControl", "rHandControl", "lShoulderControl", "lArmControl", "lElbowControl", "lHandControl", "neckControl", "headControl", "eyeTargetControl" }; private readonly string[] _rigidbodyNames = new string[] { "hip", "pelvis", "rThigh", "rShin", "rFoot", "rToe", "lThigh", "lShin", "lFoot", "lToe", "Gen1", "Gen2", "Gen3", "Testes", "abdomen", "abdomen2", "chest", "lPectoral", "rPectoral", "rCollar", "rShldr", "rForeArm", "rHand", "lCollar", "lShldr", "lForeArm", "lHand", "neck", "head", "" }; private readonly string[] _bodyControls = new string[] { "hipControl", "pelvisControl", "abdomenControl" }; private readonly string[] keyControls = new string[] { "headControl", "chestControl", "hipControl", "lFootControl", "lHandControl", "rFootControl", "rHandControl", "eyeTargetControl" }; // Use this for initialization public override void Init() { try { var sceneDir = SuperController.singleton.currentLoadDir; if (sceneDir.Contains(":")) { var sceneDirSplit = sceneDir.Split(':'); _sceneVar = sceneDirSplit[0]; } else { _sceneVar = ""; } TargetAtom = containingAtom; _floatParame = TargetAtom.GetStorableByID("hipControl").GetFloatParamNames(); _boolParame = TargetAtom.GetStorableByID("hipControl").GetBoolParamNames(); filename = new JSONStorableString("Set Pose Filename", "Custom/Atom/Person/Pose/"); vapPreviousFolder = _vapPosePath; jsonPreviousFolder = _jsonPosePath; scenePreviousFolder = _jsonScenePath; _pathFor1stPose = _vapPosePath; _pathFor2ndPose = _vapPosePath; SELF = ""; var topMenuButton = CreateButton("Change Menu"); topMenuButton.button.onClick.AddListener(ChangeMenu); topMenuButton.buttonColor = new Color(1.0f, 0.75f, 0.75f); var spacer = CreateSpacer(false); spacer.height = 10f; collision_bool = new JSONStorableBool("Collision", true); collision_toggle = CreateToggle(collision_bool, true); collision_toggle.toggle.onValueChanged.AddListener(delegate { collisionChange(); }); var spacerR1 = CreateSpacer(true); spacerR1.height = 10f; keepFolder_Bool = new JSONStorableBool("Keep the previous folder", true); keepFolder_toggle = CreateToggle(keepFolder_Bool, false); var loadVapPose = CreateButton("Load Vap Pose Preset", false); loadVapPose.button.onClick.AddListener(() => { if (!keepFolder_Bool.val) { vapPreviousFolder = _vapPosePath; } filename.val = ""; selectPerson.val = "None"; sceneBool = false; _isMakePoseList = false; _loopStart = false; var vapPoseShortcuts = FileManagerSecure.GetShortCutsForDirectory(_vapPosePath, false, false, true, true); SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, "vap", vapPreviousFolder, false, true, false, null, false, vapPoseShortcuts); }); JSONStorableAction LoadVapDatas = new JSONStorableAction("Load Pose from VapPreset", () => { selectPerson.val = "None"; sceneBool = false; _isMakePoseList = false; _loopStart = false; HandleLoadPreset(""); }); var loadJsonPose = CreateButton("Load Json Pose Preset", false); loadJsonPose.button.onClick.AddListener(() => { if (!keepFolder_Bool.val) { jsonPreviousFolder = _jsonPosePath; } filename.val = ""; selectPerson.val = "None"; sceneBool = false; _isMakePoseList = false; _loopStart = false; var jsonPoseShortcuts = FileManagerSecure.GetShortCutsForDirectory(_jsonPosePath, false, false, true, true); SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, "json", jsonPreviousFolder, false, true, false, null, false, jsonPoseShortcuts); }); JSONStorableAction LoadJsonDatas = new JSONStorableAction("Load Pose from JsonPreset", () => { selectPerson.val = "None"; sceneBool = false; _isMakePoseList = false; _loopStart = false; HandleLoadPreset(""); }); spacer = CreateSpacer(false); spacer.height = 80f; //spacer = CreateSpacer(true); //spacer.height = 40f; var reloadPose = CreateButton("Reload Pose Preset", true); reloadPose.button.onClick.AddListener(() => { reloadBool = true; _isMakePoseList = true; _loopStart = false; HandleLoadPreset(reload); }); reloadPose.buttonColor = Color.yellow; JSONStorableAction reloadAct = new JSONStorableAction("Reload Pose Preset", () => { reloadBool = true; _isMakePoseList = true; _loopStart = false; HandleLoadPreset(reload); }); _isKeepPosition = new JSONStorableBool("Keep Positon Data in File ", false); _isKeepPositionToggle = CreateToggle(_isKeepPosition, false); controlOn_bool = new JSONStorableBool("Enable Controls On", false); controlOn_toggle = CreateToggle(controlOn_bool, false); _isUseNewType = new JSONStorableBool("Use new load type", true); _isUseNewTypeToggle = CreateToggle(_isUseNewType); _enableDisable = new JSONStorableBool("Enable Person Disable", false); _enableAutoLoadToggle = CreateToggle(_enableDisable); _enableCollision = new JSONStorableBool("Enable Collision during load", true); _enableAutoLoadToggle = CreateToggle(_enableCollision); useRigidData_bool = new JSONStorableBool("Use Rigidbody Data", true); useRigidData_toggle = CreateToggle(useRigidData_bool, false); base_bool = new JSONStorableBool("Base is between lThigh and rThigh", false); base_toggle = CreateToggle(base_bool, false); List contList = new List(); contList.Add("None"); contList.Add("headControl"); contList.Add("chestControl"); contList.Add("hipControl"); contList.Add("hip to head line"); selectControl = new JSONStorableStringChooser("Select Control", contList, "None", "Select Control"); UIDynamicPopup udp = CreatePopup(selectControl, false); udp.popup.selectColor = new Color(0.8f, 0.8f, 0.8f); List dirList = new List(); dirList.Add("Reset to 0"); dirList.Add("Keep"); selectDirection = new JSONStorableStringChooser("Rotation around Y axis", dirList, "None", "Rotation around Y axis"); //UIDynamicPopup udp2 = CreatePopup(selectDirection, true); //udp2.popup.selectColor = new Color(0.8f, 0.8f, 0.8f); invertDirect_bool = new JSONStorableBool("Invert Direction", false); //invertDirect_toggle = CreateToggle(invertDirect_bool, false); persons = new JSONStorableString("", ""); spacer = CreateSpacer(false); spacer.height = 70f; var resetExpressionButton = CreateButton("Reset Facial Expression", false); if (resetExpressionButton != null) { resetExpressionButton.button.onClick.AddListener(resetExpression); } JSONStorableAction resetExpressionAct = new JSONStorableAction("Reset Facial Expression", () => { resetExpression(); }); resetFaceMorph_Bool = new JSONStorableBool("Reset Morph where Region is Pose", false); resetFaceMorph_toggle = CreateToggle(resetFaceMorph_Bool, false); resetExpression_Bool = new JSONStorableBool("Reset Expression Morphs", false); resetExpression_toggle = CreateToggle(resetExpression_Bool, false); spacer = CreateSpacer(false); spacer.height = 1f; shortcuts_Bool = new JSONStorableBool("Use Shortcuts in Scene Load Dialog", false); JSONStorableAction SelectSceneDatas = new JSONStorableAction("Select Scene", () => { selectPerson.val = "None"; sceneBool = true; _isMakePoseList = true; _loopStart = false; HandleLoadPreset(""); }); selectPerson = new JSONStorableStringChooser("Select Person", null, "None", "Select Person"); personList.Add("None"); selectPerson.choices = personList; selectPerson.val = "None"; JSONStorableAction LoadSceneDatas = new JSONStorableAction("Load Pose From Scene", () => { sceneBool = true; _isMakePoseList = true; _loopStart = false; HandleLoadPreset(""); }); JSONStorableAction _loadPoseContAct = new JSONStorableAction("Load Poses Continuously", LoadPoseCont); _enableRnd = new JSONStorableBool("Enable Random Load", true); _enableAutoLoad = new JSONStorableBool("Enable Auto Load", false); List waitCount = new List(); waitCount.Add("10"); waitCount.Add("15"); waitCount.Add("20"); waitCount.Add("30"); waitCount.Add("60"); waitCount.Add("120"); waitCount.Add("180"); _selectCount = new JSONStorableStringChooser("Interval", waitCount, "30", "Interval [sec]"); _enablePathInSceneVar = new JSONStorableBool("Enable Path in Scene var", true); _enableSubfolder = new JSONStorableBool("Include Subfolder", true); _onlyFav = new JSONStorableBool("Favorite Pose Only", false); _poseDirectory = new JSONStorableString("Pose Directory", ""); JSONStorableAction _setPoseDirectoryAct = new JSONStorableAction("Set Pose Directory", SetPoseDirectory); _currentPose = new JSONStorableString("", ""); _filesInFolder = new JSONStorableString("", ""); JSONStorableAction _loadCouplePoseAct = new JSONStorableAction("Load Couple Pose", LoadCouplePose); JSONStorableAction _selectPose1Act = new JSONStorableAction("Set Pose for 1st Person", SetPose1); JSONStorableAction _selectPose2Act = new JSONStorableAction("Set Pose for 2nd Person", SetPose2); _selectPerson2 = new JSONStorableStringChooser("Select 2nd Person", null, "None", "Select 2nd Person"); _pathFor1stPoseString = new JSONStorableString("1st Person Pose", ""); _pathFor2ndPoseString = new JSONStorableString("2nd Person Pose", ""); ChangeMenu(); var i = 0; foreach (var item in fullControlNames) { controlAndRigibodyList[item] = _rigidbodyNames[i]; i++; } RegisterString(filename); RegisterAction(LoadVapDatas); RegisterAction(LoadJsonDatas); RegisterAction(reloadAct); RegisterBool(keepFolder_Bool); RegisterBool(collision_bool); RegisterBool(_isKeepPosition); RegisterBool(controlOn_bool); RegisterBool(_enableDisable); RegisterBool(_enableCollision); RegisterBool(useRigidData_bool); RegisterBool(base_bool); RegisterStringChooser(selectControl); RegisterAction(SelectSceneDatas); RegisterAction(LoadSceneDatas); RegisterBool(shortcuts_Bool); RegisterStringChooser(selectPerson); RegisterAction(resetExpressionAct); RegisterBool(resetFaceMorph_Bool); RegisterBool(resetExpression_Bool); RegisterAction(_loadPoseContAct); RegisterString(_poseDirectory); RegisterAction(_setPoseDirectoryAct); RegisterBool(_enableRnd); RegisterBool(_enableAutoLoad); RegisterStringChooser(_selectCount); RegisterBool(_enablePathInSceneVar); RegisterBool(_enableSubfolder); RegisterBool(_onlyFav); RegisterAction(_loadCouplePoseAct); RegisterAction(_selectPose1Act); RegisterAction(_selectPose2Act); RegisterStringChooser(_selectPerson2); RegisterString(_pathFor1stPoseString); RegisterString(_pathFor2ndPoseString); PosiST["On"] = FreeControllerV3.PositionState.On; PosiST["Comply"] = FreeControllerV3.PositionState.Comply; PosiST["Off"] = FreeControllerV3.PositionState.Off; PosiST["ParentLink"] = FreeControllerV3.PositionState.ParentLink; PosiST["PhysicsLink"] = FreeControllerV3.PositionState.PhysicsLink; PosiST["Hold"] = FreeControllerV3.PositionState.Hold; PosiST["Lock"] = FreeControllerV3.PositionState.Lock; RotaST["On"] = FreeControllerV3.RotationState.On; RotaST["Comply"] = FreeControllerV3.RotationState.Comply; RotaST["Off"] = FreeControllerV3.RotationState.Off; RotaST["ParentLink"] = FreeControllerV3.RotationState.ParentLink; RotaST["PhysicsLink"] = FreeControllerV3.RotationState.PhysicsLink; RotaST["Hold"] = FreeControllerV3.RotationState.Hold; RotaST["Lock"] = FreeControllerV3.RotationState.Lock; } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } } private void ChangeMenu() { if (_menu == 0) { _menu = 1; if (shortcuts_toggle != null) { RemoveToggle(shortcuts_toggle); RemoveButton(selectScene); RemovePopup(selectPersonPop); RemoveButton(loadScene); RemoveTextField(messageBox); } _loadPoseContButton = CreateButton("Load Poses Continuously", true); _loadPoseContButton.button.onClick.AddListener(LoadPoseCont); _loadPoseContButton.buttonColor = Color.cyan; _enableRndToggle = CreateToggle(_enableRnd, true); _enableRndToggle.toggle.onValueChanged.AddListener(delegate { ResetCount(); }); _enableAutoLoadToggle = CreateToggle(_enableAutoLoad, true); _selectCountPop = CreatePopup(_selectCount, true); _selectCountPop.popup.selectColor = new Color(0.8f, 0.8f, 0.8f); _isUseIncludedDataToggle = CreateToggle(_enablePathInSceneVar, true); _isUseIncludedDataToggle.toggle.onValueChanged.AddListener(delegate { RefreshList(); }); _enableSubfolderToggle = CreateToggle(_enableSubfolder, true); _enableSubfolderToggle.toggle.onValueChanged.AddListener(delegate { RefreshList(); }); _onlyFavToggle = CreateToggle(_onlyFav, true); _onlyFavToggle.toggle.onValueChanged.AddListener(delegate { ChangePath(); }); _setVapPoseDirectoryButton = CreateButton("Set Vap Pose Directory", true); _setVapPoseDirectoryButton.button.onClick.AddListener(SetVapPoseDirectory); _setJsonPoseDirectoryButton = CreateButton("Set Json Pose Directory", true); _setJsonPoseDirectoryButton.button.onClick.AddListener(SetJsonPoseDirectory); _currentPoseText = CreateTextField(_currentPose, true); _currentPoseText.height = 130; _filesInFolderText = CreateTextField(_filesInFolder, true); _filesInFolderText.height = 280; } else if (_menu == 2) { _menu = 0; if (_loadPoseContButton != null) { RemoveButton(_loadPoseContButton); RemoveToggle(_enableRndToggle); RemoveToggle(_enableAutoLoadToggle); RemovePopup(_selectCountPop); RemoveToggle(_isUseIncludedDataToggle); RemoveToggle(_enableSubfolderToggle); RemoveToggle(_onlyFavToggle); RemoveButton(_setVapPoseDirectoryButton); RemoveButton(_setJsonPoseDirectoryButton); RemoveTextField(_currentPoseText); RemoveTextField(_filesInFolderText); } if (_loadCouplePoseButton != null) { RemoveButton(_loadCouplePoseButton); RemoveButton(_selectPose1Button); RemoveButton(_selectPose2Button); RemovePopup(_selectPerson2); RemoveTextField(_pathFor1stPoseText); RemoveTextField(_pathFor2ndPoseText); } shortcuts_toggle = CreateToggle(shortcuts_Bool, true); selectScene = CreateButton("Select Scene", true); selectScene.button.onClick.AddListener(() => { if (!keepFolder_Bool.val) { scenePreviousFolder = _jsonScenePath; } filename.val = ""; selectPerson.val = "None"; sceneBool = true; _isMakePoseList = true; var jsonSceneShortcuts = FileManagerSecure.GetShortCutsForDirectory(_jsonScenePath, false, false, true, true); if (!shortcuts_Bool.val) { jsonSceneShortcuts = null; } SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, "json", scenePreviousFolder, false, true, false, null, false, jsonSceneShortcuts); //SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, "json", _jsonScenePath); }); selectPersonPop = CreatePopup(selectPerson, true); selectPersonPop.popup.selectColor = new Color(0.8f, 0.8f, 0.8f); loadScene = CreateButton("Load Pose From Scene", true); loadScene.button.onClick.AddListener(() => { if (selectPerson.val == "None") { if (scenePreviousFolder == "" | !keepFolder_Bool.val) { scenePreviousFolder = _jsonScenePath; } filename.val = ""; sceneBool = true; _isMakePoseList = true; var jsonSceneShortcuts = FileManagerSecure.GetShortCutsForDirectory(_jsonScenePath, false, false, true, true); if (!shortcuts_Bool.val) { jsonSceneShortcuts = null; } SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, "json", scenePreviousFolder, false, true, false, null, false, jsonSceneShortcuts); //SuperController.singleton.GetMediaPathDialog(HandleLoadPreset, "json", _jsonScenePath); } else { sceneBool = true; _isMakePoseList = true; HandleLoadPreset(reload); } }); messageBox = CreateTextField(persons, true); messageBox.height = 205f; } else { _menu = 2; if (shortcuts_toggle != null) { RemoveToggle(shortcuts_toggle); RemoveButton(selectScene); RemovePopup(selectPersonPop); RemoveButton(loadScene); RemoveTextField(messageBox); } if (_loadCouplePoseButton != null) { RemoveButton(_loadCouplePoseButton); RemoveButton(_selectPose1Button); RemoveButton(_selectPose2Button); RemovePopup(_selectPerson2); RemoveTextField(_pathFor1stPoseText); RemoveTextField(_pathFor2ndPoseText); } if (_loadPoseContButton != null) { RemoveButton(_loadPoseContButton); RemoveToggle(_enableRndToggle); RemoveToggle(_enableAutoLoadToggle); RemovePopup(_selectCountPop); RemoveToggle(_isUseIncludedDataToggle); RemoveToggle(_enableSubfolderToggle); RemoveToggle(_onlyFavToggle); RemoveButton(_setVapPoseDirectoryButton); RemoveButton(_setJsonPoseDirectoryButton); RemoveTextField(_currentPoseText); RemoveTextField(_filesInFolderText); } _loadCouplePoseButton = CreateButton("Load Couple Pose", true); _loadCouplePoseButton.buttonColor = Color.cyan; _loadCouplePoseButton.button.onClick.AddListener(LoadCouplePose); _selectPose1Button = CreateButton("Select Pose for 1st Person", true); _selectPose1Button.button.onClick.AddListener(SelectPose1); _pathFor1stPoseText = CreateTextField(_pathFor1stPoseString, true); _pathFor1stPoseText.height = 130; _selectPersonPopup = CreatePopup(_selectPerson2, true); _selectPersonPopup.popup.selectColor = new Color(0.8f, 0.8f, 0.8f); _selectPose2Button = CreateButton("Select Pose for 2nd Person", true); _selectPose2Button.button.onClick.AddListener(SelectPose2); _pathFor2ndPoseText = CreateTextField(_pathFor2ndPoseString, true); _pathFor2ndPoseText.height = 130; MakePersonList(); } } private void collisionChange() { if (collision_bool.val) { TargetAtom.collisionEnabled = true; } else { TargetAtom.collisionEnabled = false; } } #region Preset Load and Save private void HandleLoadPreset(string path) { if (filename.val != "") { ext = ""; filename.val = filename.val.Replace("\\", "/"); if (filename.val.Length > 5) { if (filename.val.Substring(filename.val.Length - 5, 5) == ".json") { ext = ".json"; } } if (filename.val.Length > 4) { if (filename.val.Substring(filename.val.Length - 4, 4) == ".vap") { ext = ".vap"; } } if (!filename.val.Contains(":")) { if (ext == ".vap") { if (filename.val.Length < _vapPosePath.Length + 4 || filename.val.Substring(0, _vapPosePath.Length) != _vapPosePath) { filename.val = _vapPosePath + "/" + filename.val; } } else if (ext == ".json") { if (filename.val.Length < _jsonPosePath.Length + 5 || filename.val.Substring(0, _jsonPosePath.Length) != _jsonPosePath) { filename.val = _jsonPosePath + "/" + filename.val; } } else { if (filename.val.Length > _vapPosePath.Length && filename.val.Substring(0, _vapPosePath.Length) == _vapPosePath) { filename.val = filename.val + ".vap"; ext = ".vap"; } else if (filename.val.Length > _jsonPosePath.Length && filename.val.Substring(0, _jsonPosePath.Length) == _jsonPosePath) { filename.val = filename.val + ".json"; ext = ".json"; } else { filename.val = _vapPosePath + "/" + filename.val + ".vap"; ext = ".vap"; } } } else { filename.val = filename.val.Replace(".var:", ":").Replace(":/", ":"); var filenameSplit = filename.val.Split(':'); if (ext == ".vap") { if (filenameSplit[1].Length < _vapPosePath.Length + 4 || filenameSplit[1].Substring(0, _vapPosePath.Length) != _vapPosePath) { filenameSplit[1] = _vapPosePath + "/" + filenameSplit[1]; } } else if (ext == ".json") { if (filenameSplit[1].Length < _jsonPosePath.Length + 5 || filenameSplit[1].Substring(0, _jsonPosePath.Length) != _jsonPosePath) { filenameSplit[1] = _jsonPosePath + "/" + filenameSplit[1]; } } else { if (filenameSplit[1].Length > _vapPosePath.Length && filenameSplit[1].Substring(0, _vapPosePath.Length) == _vapPosePath) { filenameSplit[1] = filenameSplit[1] + ".vap"; ext = ".vap"; } else if (filenameSplit[1].Length > _jsonPosePath.Length && filenameSplit[1].Substring(0, _jsonPosePath.Length) == _jsonPosePath) { filenameSplit[1] = filenameSplit[1] + ".json"; ext = ".json"; } else { filenameSplit[1] = _vapPosePath + "/" + filenameSplit[1] + ".vap"; ext = ".vap"; } //filename.val = filenameSplit[0] + ":/" + filenameSplit[1]; } var varName = MakeVarName(filenameSplit[0]); filename.val = varName + ":/" + filenameSplit[1]; } var tempName = filename.val; if (ext == ".vap" && !tempName.Contains("/Preset_")) { var tempNameSplit = tempName.Split('/'); tempName = ""; for (int i = 0; i < tempNameSplit.Length - 1; i++) { tempName = tempName + tempNameSplit[i] + "/"; } filename.val = tempName + "Preset_" + tempNameSplit[tempNameSplit.Length - 1]; } path = filename.val; } if (!path.Contains(_jsonScenePath) && !_isMakePoseList) { MakePoseList(path); _currentPose.val = path; if (_poseList.Contains(path)) { _previousNumber = _poseList.IndexOf(path) + 1; if (_previousNumber >= _poseList.Count()) { _previousNumber = 0; } } } if (path == "") { return; } if (path != "") { reload = path.Replace("\\", "/"); } if (!sceneBool) { personList = new List(); personList.Clear(); personList.Add("None"); selectPerson.choices = personList; selectPerson.val = "None"; persons.val = ""; } if (sceneBool && selectPerson.val == "None") { personList = new List(); personList.Clear(); personList.Add("None"); persons.val = ""; } loadDir = ""; string[] dirList = path.Split('/'); for (int i = 0; i < dirList.Count() - 1; i++) { loadDir = loadDir + dirList[i] + "/"; } string tempPath = loadDir.Substring(0, loadDir.Length - 1); var charPosi = tempPath.IndexOf("Custom/Atom/Person/"); if (charPosi != -1) { vapPreviousFolder = tempPath.Substring(charPosi); vapPreviousFolder = vapPreviousFolder.Replace("/", "\\"); } charPosi = tempPath.IndexOf("Saves/Person/"); if (charPosi != -1) { jsonPreviousFolder = tempPath.Substring(charPosi); jsonPreviousFolder = jsonPreviousFolder.Replace("/", "\\"); } charPosi = tempPath.IndexOf("Saves/scene/"); if (charPosi != -1) { scenePreviousFolder = tempPath.Substring(charPosi); scenePreviousFolder = scenePreviousFolder.Replace("/", "\\"); } LoadData = SuperController.singleton.ReadFileIntoString(path); jSONNode = JSON.Parse(LoadData); bool jsonExt = (path.Substring(path.Length - 4, 4) != ".vap"); if (jsonExt) { atomArray = jSONNode["atoms"].AsArray; for (int k = 0; k < atomArray.Count; k++) { asAtomObject = atomArray[k].AsObject; id = asAtomObject["id"]; string type = asAtomObject["type"]; JSONArray tempArray = asAtomObject["storables"].AsArray; JSONClass tempObject; string characterType = ""; for (int l = 0; l < tempArray.Count; l++) { tempObject = tempArray[l].AsObject; string tempId = tempObject["id"]; if ("geometry" == tempId) { if (tempObject["character"] != null) { characterType = tempObject["character"]; } } } if (type == "Person") { if (sceneBool && selectPerson.val == "None") { personList.Add(id); persons.val = persons.val + id + " : " + characterType + "\n"; } asArray = asAtomObject["storables"].AsArray; } } if (sceneBool && selectPerson.val == "None") { if (personList.Count != 2) { selectPerson.choices = personList; return; } else { selectPerson.choices = personList; selectPerson.val = personList[1]; } } if (sceneBool) { for (int k = 0; k < atomArray.Count; k++) { asAtomObject = atomArray[k].AsObject; id = asAtomObject["id"]; string type = asAtomObject["type"]; if (type == "Person" && id == selectPerson.val) { asArray = asAtomObject["storables"].AsArray; } } } } else { asArray = jSONNode["storables"].AsArray; } if (!_enableCollision.val) { TargetAtom.collisionEnabled = false; } geometry = TargetAtom.GetStorableByID("geometry"); character = geometry as DAZCharacterSelector; morphControl = character.morphsControlUI; morphControl.GetMorphUids().ForEach((uid) => { DAZMorph morph = morphControl.GetMorphByUid(uid); if (morph.isPoseControl) { morph.SetDefaultValue(); } }); atomControlsId.Clear(); atomControlsPosiState.Clear(); atomControlsRotaState.Clear(); atomControlsPosi.Clear(); atomControlsRota.Clear(); atomControlsLink.Clear(); morphList.Clear(); ControlList = new List(); RigidbodyList = new List(); _readedControl = new List(); _readedRigidbody = new List(); atomControlsPosi["control"] = new Vector3(0f, 0f, 0f); atomControlsRota["control"] = new Vector3(0f, 0f, 0f); _isExistControl = false; targetAtomPosi = TargetAtom.GetStorableByID("control").transform.position; targetAtomRota = TargetAtom.GetStorableByID("control").transform.rotation; _poseMorph = new List(); _isExistRigidData = false; for (int i = 0; i < asArray.Count; i++) { asObject = asArray[i].AsObject; id = asObject["id"]; if (id == "geometry") { morphsAsArray = asObject["morphs"].AsArray; for (int j = 0; j < morphsAsArray.Count; j++) { morphs = morphsAsArray[j].AsObject; if (morphs["value"] != null) { if (morphControl.GetMorphByDisplayName(morphs["name"]) != null) { var isPoseMorph = morphControl.GetMorphByDisplayName(morphs["name"]).isPoseControl; if (isPoseMorph) { //morphControl.GetMorphByDisplayName(morphs["name"]).morphValue = float.Parse(morphs["value"]); _poseMorph.Add(morphs["name"]); _morphDic[morphs["name"]] = float.Parse(morphs["value"]); } } } } } else if (fullControlNames.Contains(id) | id == "eyeTargetControl") { _readedControl.Add(id); foreach (var item in _boolParame) { if (asObject[item] != null) { TargetAtom.GetStorableByID(id).GetBoolJSONParam(item).val = bool.Parse(asObject[item]); } else { if (TargetAtom.GetStorableByID(id).GetBoolJSONParam(item) != null) { TargetAtom.GetStorableByID(id).GetBoolJSONParam(item).SetValToDefault(); } } } foreach (var item in _floatParame) { if (asObject[item] != null) { TargetAtom.GetStorableByID(id).GetFloatJSONParam(item).val = float.Parse(asObject[item]); } else { if (TargetAtom.GetStorableByID(id).GetFloatJSONParam(item) != null) { TargetAtom.GetStorableByID(id).GetFloatJSONParam(item).SetValToDefault(); } } } string posiStat = "On"; if (asObject["positionState"] != null) { posiStat = asObject["positionState"]; } else { if (keyControls.Contains(id)) { posiStat = "On"; } else { posiStat = "Off"; } } string rotaStat = "On"; if (asObject["rotationState"] != null) { rotaStat = asObject["rotationState"]; } else { if (keyControls.Contains(id)) { rotaStat = "On"; } else { rotaStat = "Off"; } } float posiX; float posiY; float posiZ; if (asObject["localPosition"] != null) { posiX = float.Parse(asObject["localPosition"][0]); posiY = float.Parse(asObject["localPosition"][1]); posiZ = float.Parse(asObject["localPosition"][2]); } else { posiX = float.Parse(asObject["position"][0]); posiY = float.Parse(asObject["position"][1]); posiZ = float.Parse(asObject["position"][2]); } float rotaX; float rotaY; float rotaZ; if (asObject["localRotation"] != null) { rotaX = float.Parse(asObject["localRotation"][0]); rotaY = float.Parse(asObject["localRotation"][1]); rotaZ = float.Parse(asObject["localRotation"][2]); } else { rotaX = float.Parse(asObject["rotation"][0]); rotaY = float.Parse(asObject["rotation"][1]); rotaZ = float.Parse(asObject["rotation"][2]); } string linkTo = "None:None"; if (asObject["linkTo"] != null) { linkTo = asObject["linkTo"]; } Vector3 posiV3XYZ = new Vector3(posiX, posiY, posiZ); Vector3 rotaV3XYZ = new Vector3(rotaX, rotaY, rotaZ); ControlList.Add(id); atomControlsPosiState[id] = posiStat; atomControlsRotaState[id] = rotaStat; atomControlsPosi[id] = posiV3XYZ; atomControlsRota[id] = rotaV3XYZ; atomControlsLink[id] = linkTo; } else if (id == "hip") { _isExistRigidData = true; _readedRigidbody.Add(id); if (asObject["rootPosition"] != null) { rootPosi.x = float.Parse(asObject["rootPosition"][0]); rootPosi.y = float.Parse(asObject["rootPosition"][1]); rootPosi.z = float.Parse(asObject["rootPosition"][2]); } else { rootPosi = new Vector3(0f, 0f, 0f); } float posiX; float posiY; float posiZ; if (asObject["relativeRootPosition"] != null) { posiX = rootPosi.x + float.Parse(asObject["relativeRootPosition"][0]); posiY = rootPosi.y + float.Parse(asObject["relativeRootPosition"][1]); posiZ = rootPosi.z + float.Parse(asObject["relativeRootPosition"][2]); } else if (asObject["position"] != null) { posiX = float.Parse(asObject["position"][0]); posiY = float.Parse(asObject["position"][1]); posiZ = float.Parse(asObject["position"][2]); } else { posiX = 0f; posiY = 0f; posiZ = 0f; } if (asObject["rootRotation"] != null) { rootRota.x = float.Parse(asObject["rootRotation"][0]); rootRota.y = float.Parse(asObject["rootRotation"][1]); rootRota.z = float.Parse(asObject["rootRotation"][2]); } else { rootRota = new Vector3(0f, 0f, 0f); } float rotaX; float rotaY; float rotaZ; if (asObject["relativeRootRotation"] != null) { rotaX = rootRota.x + float.Parse(asObject["relativeRootRotation"][0]); rotaY = rootRota.y + float.Parse(asObject["relativeRootRotation"][1]); rotaZ = rootRota.z + float.Parse(asObject["relativeRootRotation"][2]); } else if (asObject["rotation"] != null) { rotaX = float.Parse(asObject["rotation"][0]); rotaY = float.Parse(asObject["rotation"][1]); rotaZ = float.Parse(asObject["rotation"][2]); } else { rotaX = 0f; rotaY = 0f; rotaZ = 0f; } Vector3 posiV3XYZ = new Vector3(posiX, posiY, posiZ); Vector3 rotaV3XYZ = new Vector3(rotaX, rotaY, rotaZ); RigidbodyList.Add(id); atomRigidbodyPosi[id] = posiV3XYZ; atomRigidbodyRota[id] = rotaV3XYZ; _rigidbodyPosiLocal[id] = posiV3XYZ; _rigidbodyRotaLocal[id] = Quaternion.Euler(rotaV3XYZ); _rigidbodyPosiWorld[id] = posiV3XYZ; _rigidbodyRotaWorld[id] = Quaternion.Euler(rotaV3XYZ); rootPosi = posiV3XYZ; rootRota = rotaV3XYZ; } else if ((_rigidbodyNames.Contains(id) && id != "") || id == "LGlute" || id == "RGlute") { _readedRigidbody.Add(id); float posiX; float posiY; float posiZ; if (asObject["rootPosition"] != null) { if (asObject["relativeRootPosition"] != null) { posiX = float.Parse(asObject["relativeRootPosition"][0]); posiY = float.Parse(asObject["relativeRootPosition"][1]); posiZ = float.Parse(asObject["relativeRootPosition"][2]); } else { posiX = 0f; posiY = 0f; posiZ = 0f; } } else { posiX = float.Parse(asObject["position"][0]); posiY = float.Parse(asObject["position"][1]); posiZ = float.Parse(asObject["position"][2]); } float rotaX; float rotaY; float rotaZ; if (asObject["rootRotation"] != null) { if (asObject["relativeRootRotation"] != null) { rotaX = float.Parse(asObject["relativeRootRotation"][0]); rotaY = float.Parse(asObject["relativeRootRotation"][1]); rotaZ = float.Parse(asObject["relativeRootRotation"][2]); } else { rotaX = 0f; rotaY = 0f; rotaZ = 0f; } } else { rotaX = float.Parse(asObject["rotation"][0]); rotaY = float.Parse(asObject["rotation"][1]); rotaZ = float.Parse(asObject["rotation"][2]); } Vector3 posiV3XYZ = new Vector3(posiX, posiY, posiZ); Vector3 rotaV3XYZ = new Vector3(rotaX, rotaY, rotaZ); RigidbodyList.Add(id); atomRigidbodyPosi[id] = posiV3XYZ; atomRigidbodyRota[id] = rotaV3XYZ; _rigidbodyPosiLocal[id] = posiV3XYZ; _rigidbodyRotaLocal[id] = Quaternion.Euler(rotaV3XYZ); GameObject parent = TargetAtom.GetStorableByID(id).transform.parent.gameObject; GameObject parentRigid = new GameObject(); GameObject currentRigid = new GameObject(); parentRigid.transform.position = _rigidbodyPosiWorld[parent.name]; parentRigid.transform.rotation = _rigidbodyRotaWorld[parent.name]; currentRigid.transform.position = parentRigid.transform.TransformPoint(posiV3XYZ); currentRigid.transform.rotation = _rigidbodyRotaWorld[parent.name] * _rigidbodyRotaLocal[id]; _rigidbodyPosiWorld[id] = currentRigid.transform.position; _rigidbodyRotaWorld[id] = currentRigid.transform.rotation; } else if (id == "control") { _isExistControl = true; foreach (var item in _boolParame) { if (asObject[item] != null) { TargetAtom.GetStorableByID(id).GetBoolJSONParam(item).val = bool.Parse(asObject[item]); } else { if (TargetAtom.GetStorableByID(id).GetBoolJSONParam(item) != null) { TargetAtom.GetStorableByID(id).GetBoolJSONParam(item).SetValToDefault(); } } } foreach (var item in _floatParame) { if (asObject[item] != null) { TargetAtom.GetStorableByID(id).GetFloatJSONParam(item).val = float.Parse(asObject[item]); } else { if (TargetAtom.GetStorableByID(id).GetFloatJSONParam(item) != null) { TargetAtom.GetStorableByID(id).GetFloatJSONParam(item).SetValToDefault(); } } } float posiX; float posiY; float posiZ; if (asObject["position"] != null) { posiX = float.Parse(asObject["position"][0]); posiY = float.Parse(asObject["position"][1]); posiZ = float.Parse(asObject["position"][2]); atomControlsPosi[id] = new Vector3(posiX, posiY, posiZ); } float rotaX; float rotaY; float rotaZ; if (asObject["rotation"] != null) { rotaX = float.Parse(asObject["rotation"][0]); rotaY = float.Parse(asObject["rotation"][1]); rotaZ = float.Parse(asObject["rotation"][2]); atomControlsRota[id] = new Vector3(rotaX, rotaY, rotaZ); } } } float minY = 10f; //foreach (var item in fullControlNames) foreach (var item in _readedControl) { if (atomControlsPosi[item] != null && item != "eyeTargetControl") { float thisY = atomControlsPosi[item].y; if (minY > thisY) { minY = thisY; } } } _minControl = minY; if (_isExistRigidData) { minY = 10f; //foreach (var item in _rigidbodyNames) foreach (var item in _readedRigidbody) { if (_rigidbodyPosiWorld[item] != null && item != "") { float thisY = _rigidbodyPosiWorld[item].y; if (minY > thisY) { minY = thisY; } } } _minRigid = minY; } else { _minRigid = 0; } StartCoroutine(moveControls()); } IEnumerator moveControls() { Vector3 tempPosi; Vector3 tempRota; Vector3 hipPosi; Vector3 newPosi; Vector3 contPosi = TargetAtom.GetStorableByID("control").transform.position; Vector3 contPosiT = contPosi; Vector3 contRotaV3 = TargetAtom.GetStorableByID("control").transform.rotation.eulerAngles; Quaternion contRota = TargetAtom.GetStorableByID("control").transform.rotation; if (_isKeepPosition.val) { if (_isExistControl) { tempPosi = atomControlsPosi["control"]; tempRota = atomControlsRota["control"]; } else { tempPosi = contPosi; tempRota = contRotaV3; } TargetAtom.GetStorableByID("control").transform.position = tempPosi; TargetAtom.GetStorableByID("control").transform.rotation = Quaternion.Euler(tempRota); if (_enableDisable.val) { TargetAtom.tempDisableRender = true; } else { TargetAtom.tempDisableRender = false; } foreach (var item in ControlList) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; CurrentController.currentPositionState = PosiST["On"]; CurrentController.currentRotationState = RotaST["On"]; linkToAtom = SuperController.singleton.RigidbodyNameToRigidbody("None:None"); CurrentController.SelectLinkToRigidbody(linkToAtom, FreeControllerV3.SelectLinkState.PositionAndRotation); //CurrentController.transform.localPosition = atomControlsPosiF[item]; } foreach (var item in _bodyControls) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; tempPosi = atomControlsPosi[item]; tempRota = atomControlsRota[item]; //tempPosi += new Vector3(hipPosi.x, -_minControl, hipPosi.z); CurrentController.transform.localPosition = tempPosi; CurrentController.transform.localRotation = Quaternion.Euler(tempRota); } CurrentController = TargetAtom.GetStorableByID("hipControl") as FreeControllerV3; var hipOnPosi = CurrentController.transform.localPosition; var hipOnRota = CurrentController.transform.localRotation; CurrentController.currentPositionState = PosiST["Comply"]; CurrentController.currentRotationState = RotaST["Comply"]; yield return new WaitForSeconds(0.5f); rootPosi = CurrentController.transform.position; rootRota = CurrentController.transform.rotation.eulerAngles; CurrentController.currentPositionState = PosiST["On"]; CurrentController.currentRotationState = RotaST["On"]; CurrentController.transform.localPosition = hipOnPosi; CurrentController.transform.localRotation = hipOnRota; if (useRigidData_bool.val && _isExistRigidData) { foreach (var item in _bodyControls) { var rigidItem = controlAndRigibodyList[item]; if (rigidItem == "hip") { TargetAtom.GetStorableByID(rigidItem).transform.position = rootPosi; TargetAtom.GetStorableByID(rigidItem).transform.rotation = Quaternion.Euler(rootRota); } else { var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } foreach (var item in _readedControl) { if (!_bodyControls.Contains(item)) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; tempPosi = atomControlsPosi[item]; tempRota = atomControlsRota[item]; //tempPosi += new Vector3(hipPosi.x, -_minControl, hipPosi.z); CurrentController.transform.localPosition = tempPosi; CurrentController.transform.localRotation = Quaternion.Euler(tempRota); if (item != "eyeTargetControl") { if (useRigidData_bool.val && _isExistRigidData) { var rigidItem = controlAndRigibodyList[item]; var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } } yield return new WaitForSeconds(0.5f); CurrentController = TargetAtom.GetStorableByID("hipControl") as FreeControllerV3; hipOnPosi = CurrentController.transform.localPosition; hipOnRota = CurrentController.transform.localRotation; CurrentController.currentPositionState = PosiST["Comply"]; CurrentController.currentRotationState = RotaST["Comply"]; yield return new WaitForSeconds(0.5f); rootPosi = CurrentController.transform.position; rootRota = CurrentController.transform.rotation.eulerAngles; CurrentController.currentPositionState = PosiST["On"]; CurrentController.currentRotationState = RotaST["On"]; CurrentController.transform.localPosition = hipOnPosi; CurrentController.transform.localRotation = hipOnRota; if (useRigidData_bool.val && _isExistRigidData) { foreach (var item in _bodyControls) { var rigidItem = controlAndRigibodyList[item]; if (rigidItem == "hip") { TargetAtom.GetStorableByID(rigidItem).transform.position = rootPosi; TargetAtom.GetStorableByID(rigidItem).transform.rotation = Quaternion.Euler(rootRota); } else { var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } foreach (var item in _readedControl) { if (!_bodyControls.Contains(item)) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; tempPosi = atomControlsPosi[item]; tempRota = atomControlsRota[item]; //tempPosi += new Vector3(hipPosi.x, -_minControl, hipPosi.z); CurrentController.transform.localPosition = tempPosi; CurrentController.transform.localRotation = Quaternion.Euler(tempRota); if (item != "eyeTargetControl") { if (useRigidData_bool.val && _isExistRigidData) { var rigidItem = controlAndRigibodyList[item]; var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } } foreach (var item in _readedControl) { if (!_bodyControls.Contains(item)) { if (item != "eyeTargetControl") { if (useRigidData_bool.val && _isExistRigidData) { var rigidItem = controlAndRigibodyList[item]; var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } } } else { if (!_isUseNewType.val) { bool zeroPosi = false; bool zeroRota = false; tempPosi = atomControlsPosi["control"]; tempRota = atomControlsRota["control"]; if (Mathf.Abs(tempPosi.x) < 0.01f && Mathf.Abs(tempPosi.y) < 0.01f && Mathf.Abs(tempPosi.z) < 0.01f) { zeroPosi = true; } if (Mathf.Abs(tempRota.x) < 1f && Mathf.Abs(tempRota.y) < 1f && Mathf.Abs(tempRota.z) < 1f) { zeroRota = true; } zeroControl = zeroPosi && zeroRota; contPosiT.y = atomControlsPosi["control"].y; TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = true; TargetAtom.GetStorableByID("control").transform.position = contPosiT; if (!zeroControl) { TargetAtom.GetStorableByID("control").transform.rotation = Quaternion.Euler(atomControlsRota["control"]); } TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = false; //yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.2f); hipPosi = atomControlsPosi["hipControl"]; tempPosi = hipPosi; tempPosi.y = 0f; if (_enableDisable.val) { TargetAtom.tempDisableRender = true; } else { TargetAtom.tempDisableRender = false; } foreach (var item in ControlList) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; CurrentController.currentPositionState = PosiST["On"]; CurrentController.currentRotationState = RotaST["On"]; linkToAtom = SuperController.singleton.RigidbodyNameToRigidbody("None:None"); CurrentController.SelectLinkToRigidbody(linkToAtom, FreeControllerV3.SelectLinkState.PositionAndRotation); //CurrentController.transform.localPosition = atomControlsPosiF[item]; if (!zeroControl) { CurrentController.transform.localPosition = atomControlsPosi[item]; CurrentController.transform.localRotation = Quaternion.Euler(atomControlsRota[item]); } } yield return new WaitForSeconds(0.5f); TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = true; TargetAtom.GetStorableByID("control").transform.position = contPosi; if (!zeroControl) { TargetAtom.GetStorableByID("control").transform.rotation = Quaternion.Euler(0f, 0f, 0f); } TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = false; //yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.2f); foreach (var item in ControlList) { if (!zeroControl) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; atomControlsPosiT[item] = CurrentController.transform.localPosition; atomControlsRotaT[item] = CurrentController.transform.localRotation; } else { atomControlsPosiT[item] = atomControlsPosi[item]; atomControlsRotaT[item] = Quaternion.Euler(atomControlsRota[item]); } } float angle; minControl = 10f; foreach (var item in ControlList) { tempPosi = atomControlsPosiT[item]; //if (tempPosi.y < minControl && (atomControlsPosiState[item] != "Off" | controlOn_bool.val)) if (tempPosi.y < minControl && item != "eyeTargetControl") { minControl = tempPosi.y; minControlName = item; } } if (base_bool.val) { var lThigh = atomControlsPosiT["lThighControl"]; var rThigh = atomControlsPosiT["rThighControl"]; hipPosi = (lThigh + rThigh) / 2; minControl = hipPosi.y; } else { hipPosi = atomControlsPosiT["hipControl"]; } foreach (var item in ControlList) { tempPosi = atomControlsPosiT[item]; tempPosi.x -= hipPosi.x; tempPosi.y -= minControl; tempPosi.z -= hipPosi.z; atomControlsPosiF[item] = tempPosi; atomControlsRotaF[item] = atomControlsRotaT[item]; } if (invertDirect_bool.val) { angle = 180f; } else { angle = 0f; } float contDirect; if (selectControl.val != "None" && selectControl.val != "hip to head line") { contDirect = atomControlsRotaF[selectControl.val].eulerAngles.y; } else if (selectControl.val == "hip to head line") { Vector3 head = atomControlsPosiF["headControl"]; Vector3 hip = atomControlsPosiF["hipControl"]; contDirect = Mathf.Atan2((hip.x - head.x), (hip.z - head.z)) * Mathf.Rad2Deg; } else { contDirect = 0f; } TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = true; TargetAtom.GetStorableByID("control").transform.rotation = Quaternion.Euler(0f, contRotaV3.y, 0f); TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = false; //yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.2f); angle += contDirect; hipPosi = atomControlsPosiF["hipControl"]; foreach (var item in ControlList) { tempPosi = atomControlsPosiF[item]; newPosi.x = (tempPosi.x - hipPosi.x) * Mathf.Cos(angle * Mathf.Deg2Rad) - (tempPosi.z - hipPosi.z) * Mathf.Sin(angle * Mathf.Deg2Rad) + hipPosi.x; newPosi.y = atomControlsPosiF[item].y; newPosi.z = (tempPosi.x - hipPosi.x) * Mathf.Sin(angle * Mathf.Deg2Rad) + (tempPosi.z - hipPosi.z) * Mathf.Cos(angle * Mathf.Deg2Rad) + hipPosi.z; atomControlsPosiF[item] = newPosi; tempRota = atomControlsRotaF[item].eulerAngles; tempRota.y = tempRota.y - angle; atomControlsRotaF[item] = Quaternion.Euler(tempRota); CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; CurrentController.transform.localPosition = atomControlsPosiF[item]; CurrentController.transform.localRotation = atomControlsRotaF[item]; if (item != "eyeTargetControl") { var _rigidbody = TargetAtom.rigidbodies.First(rb => rb.name == controlAndRigibodyList[item]); _rigidbody.detectCollisions = false; if (useRigidData_bool.val && _isExistRigidData) { tempPosi = atomRigidbodyPosi[controlAndRigibodyList[item]]; newPosi.x = (tempPosi.x - hipPosi.x) * Mathf.Cos(angle * Mathf.Deg2Rad) - (tempPosi.z - hipPosi.z) * Mathf.Sin(angle * Mathf.Deg2Rad) + hipPosi.x; newPosi.y = atomRigidbodyPosi[controlAndRigibodyList[item]].y; newPosi.z = (tempPosi.x - hipPosi.x) * Mathf.Sin(angle * Mathf.Deg2Rad) + (tempPosi.z - hipPosi.z) * Mathf.Cos(angle * Mathf.Deg2Rad) + hipPosi.z; tempRota = atomRigidbodyRota[controlAndRigibodyList[item]]; tempRota.y = tempRota.y - angle; _rigidbody.transform.localPosition = newPosi; _rigidbody.transform.localRotation = Quaternion.Euler(tempRota); } } } yield return new WaitForSeconds(0.5f); if (useRigidData_bool.val && _isExistRigidData) { CurrentController = TargetAtom.GetStorableByID("hipControl") as FreeControllerV3; var hipOnPosi = CurrentController.transform.localPosition; var hipOnRota = CurrentController.transform.localRotation; CurrentController.currentPositionState = PosiST["Comply"]; CurrentController.currentRotationState = RotaST["Comply"]; yield return new WaitForSeconds(0.5f); rootPosi = CurrentController.transform.position; rootRota = CurrentController.transform.rotation.eulerAngles; CurrentController.currentPositionState = PosiST["On"]; CurrentController.currentRotationState = RotaST["On"]; CurrentController.transform.localPosition = hipOnPosi; CurrentController.transform.localRotation = hipOnRota; //foreach (var rigidItem in _rigidbodyNames) foreach (var rigidItem in _readedRigidbody) { if (rigidItem != "") { if (rigidItem == "hip") { TargetAtom.GetStorableByID(rigidItem).transform.position = rootPosi; TargetAtom.GetStorableByID(rigidItem).transform.rotation = Quaternion.Euler(rootRota); } else { var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } } } else { if (_enableDisable.val) { TargetAtom.tempDisableRender = true; } else { TargetAtom.tempDisableRender = false; } float selectDir = 0; if (selectControl.val != "None" && selectControl.val != "hip to head line") { selectDir = atomControlsRota[selectControl.val].y; } else if (selectControl.val != "None") { Vector3 head = atomControlsPosi["headControl"]; Vector3 hip = atomControlsPosi["hipControl"]; selectDir = Mathf.Atan2((hip.x - head.x), (hip.z - head.z)) * Mathf.Rad2Deg; //selectDir = atomControlsRota["control"].y; } tempPosi = contPosi; tempPosi.y += atomControlsPosi["control"].y; //TargetAtom.GetStorableByID("control").transform.position = tempPosi; tempRota = atomControlsRota["control"]; //yield return new WaitForSeconds(0.5f); TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = true; TargetAtom.GetStorableByID("control").transform.position = tempPosi; TargetAtom.GetStorableByID("control").transform.rotation = Quaternion.Euler(new Vector3(tempRota.x, contRotaV3.y - selectDir, tempRota.z)); TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = false; yield return new WaitForSeconds(0.2f); hipPosi = atomControlsPosi["hipControl"]; //foreach (var item in fullControlNames) foreach (var item in _readedControl) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; CurrentController.currentPositionState = PosiST["On"]; CurrentController.currentRotationState = RotaST["On"]; linkToAtom = SuperController.singleton.RigidbodyNameToRigidbody("None:None"); CurrentController.SelectLinkToRigidbody(linkToAtom, FreeControllerV3.SelectLinkState.PositionAndRotation); } foreach (var item in _bodyControls) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; tempPosi = atomControlsPosi[item]; tempRota = atomControlsRota[item]; //tempPosi += new Vector3(hipPosi.x, -_minControl, hipPosi.z); CurrentController.transform.localPosition = tempPosi; CurrentController.transform.localRotation = Quaternion.Euler(tempRota); } CurrentController = TargetAtom.GetStorableByID("hipControl") as FreeControllerV3; var hipOnPosi = CurrentController.transform.localPosition; var hipOnRota = CurrentController.transform.localRotation; CurrentController.currentPositionState = PosiST["Comply"]; CurrentController.currentRotationState = RotaST["Comply"]; yield return new WaitForSeconds(0.5f); rootPosi = CurrentController.transform.position; rootRota = CurrentController.transform.rotation.eulerAngles; CurrentController.currentPositionState = PosiST["On"]; CurrentController.currentRotationState = RotaST["On"]; CurrentController.transform.localPosition = hipOnPosi; CurrentController.transform.localRotation = hipOnRota; if (useRigidData_bool.val && _isExistRigidData) { foreach (var item in _bodyControls) { var rigidItem = controlAndRigibodyList[item]; if (rigidItem == "hip") { TargetAtom.GetStorableByID(rigidItem).transform.position = rootPosi; TargetAtom.GetStorableByID(rigidItem).transform.rotation = Quaternion.Euler(rootRota); } else { var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } //foreach (var item in fullControlNames) foreach (var item in _readedControl) { if (!_bodyControls.Contains(item)) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; tempPosi = atomControlsPosi[item]; tempRota = atomControlsRota[item]; //tempPosi += new Vector3(hipPosi.x, -_minControl, hipPosi.z); CurrentController.transform.localPosition = tempPosi; CurrentController.transform.localRotation = Quaternion.Euler(tempRota); if (item != "eyeTargetControl") { if (useRigidData_bool.val && _isExistRigidData) { var rigidItem = controlAndRigibodyList[item]; var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } } yield return new WaitForSeconds(0.5f); CurrentController = TargetAtom.GetStorableByID("hipControl") as FreeControllerV3; hipOnPosi = CurrentController.transform.localPosition; hipOnRota = CurrentController.transform.localRotation; CurrentController.currentPositionState = PosiST["Comply"]; CurrentController.currentRotationState = RotaST["Comply"]; yield return new WaitForSeconds(0.5f); rootPosi = CurrentController.transform.position; rootRota = CurrentController.transform.rotation.eulerAngles; CurrentController.currentPositionState = PosiST["On"]; CurrentController.currentRotationState = RotaST["On"]; CurrentController.transform.localPosition = hipOnPosi; CurrentController.transform.localRotation = hipOnRota; if (useRigidData_bool.val && _isExistRigidData) { foreach (var item in _bodyControls) { var rigidItem = controlAndRigibodyList[item]; if (rigidItem == "hip") { TargetAtom.GetStorableByID(rigidItem).transform.position = rootPosi; TargetAtom.GetStorableByID(rigidItem).transform.rotation = Quaternion.Euler(rootRota); } else { var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } //foreach (var item in fullControlNames) foreach (var item in _readedControl) { if (!_bodyControls.Contains(item)) { CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; tempPosi = atomControlsPosi[item]; tempRota = atomControlsRota[item]; //tempPosi += new Vector3(hipPosi.x, -_minControl, hipPosi.z); CurrentController.transform.localPosition = tempPosi; CurrentController.transform.localRotation = Quaternion.Euler(tempRota); if (item != "eyeTargetControl") { if (useRigidData_bool.val && _isExistRigidData) { var rigidItem = controlAndRigibodyList[item]; var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } } _minRigid = 10f; //foreach (var item in _rigidbodyNames) foreach (var item in _readedRigidbody) { if (item != "") { var rigidPosi = TargetAtom.GetStorableByID(item).transform.position.y; if (_minRigid > rigidPosi) { _minRigid = rigidPosi; } } } if (base_bool.val) { var lThighPosi = TargetAtom.GetStorableByID("lThigh").transform.position.y; var rThighPosi = TargetAtom.GetStorableByID("rThigh").transform.position.y; _minRigid = (lThighPosi + rThighPosi) / 2; } tempPosi = atomControlsPosi["control"]; tempRota = atomControlsRota["control"]; hipPosi = TargetAtom.GetStorableByID("hip").transform.position; //TargetAtom.GetStorableByID("control").transform.position = contPosi - new Vector3(0, _minRigid - tempPosi.y, 0); //TargetAtom.GetStorableByID("control").transform.position = contPosi - new Vector3(hipPosi.x - contPosi.x, _minRigid - tempPosi.y, hipPosi.z - contPosi.z); TargetAtom.GetStorableByID("control").transform.position = contPosi - new Vector3(hipPosi.x - contPosi.x, _minRigid - tempPosi.y - contPosi.y, hipPosi.z - contPosi.z); yield return new WaitForSeconds(0.5f); TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = true; TargetAtom.GetStorableByID("control").transform.position = contPosi; TargetAtom.GetStorableByID("control").transform.rotation = contRota; TargetAtom.GetStorableByID("control").GetBoolJSONParam("detachControl").val = false; yield return new WaitForSeconds(0.2f); //foreach (var item in fullControlNames) foreach (var item in _readedControl) { if (!_bodyControls.Contains(item)) { if (item != "eyeTargetControl") { if (useRigidData_bool.val && _isExistRigidData) { var rigidItem = controlAndRigibodyList[item]; var parentControl = TargetAtom.GetStorableByID(rigidItem).transform.parent; TargetAtom.GetStorableByID(rigidItem).transform.position = parentControl.transform.TransformPoint(atomRigidbodyPosi[rigidItem]); TargetAtom.GetStorableByID(rigidItem).transform.rotation = parentControl.transform.rotation * Quaternion.Euler(atomRigidbodyRota[rigidItem]); } } } } } } List enableClothing = new List(); var allBool = TargetAtom.GetStorableByID("geometry").GetBoolParamNames(); foreach (var item in allBool) { if (item.Contains("clothing:")) { if (TargetAtom.GetStorableByID("geometry").GetBoolJSONParam(item).val) { enableClothing.Add(item); TargetAtom.GetStorableByID("geometry").GetBoolJSONParam(item).val = false; } } } foreach (var item in enableClothing) { TargetAtom.GetStorableByID("geometry").GetBoolJSONParam(item).val = true; } TargetAtom.tempDisableRender = false; foreach (string item in ControlList) { FreeControllerV3 CurrentController = TargetAtom.GetStorableByID(item) as FreeControllerV3; //if (atomControlsPosiState[item] != "ParentLink" && atomControlsPosiState[item] != "PhysicsLinky" && atomControlsPosiState[item] != "Comply") if (!controlOn_bool.val && atomControlsPosiState[item] != "ParentLink" && atomControlsPosiState[item] != "PhysicsLinky") { CurrentController.currentPositionState = PosiST[atomControlsPosiState[item]]; } //if (atomControlsRotaState[item] != "ParentLink" && atomControlsRotaState[item] != "PhysicsLinky" && atomControlsRotaState[item] != "Comply") if (!controlOn_bool.val && atomControlsRotaState[item] != "ParentLink" && atomControlsRotaState[item] != "PhysicsLinky") { CurrentController.currentRotationState = RotaST[atomControlsRotaState[item]]; } linkToAtom = SuperController.singleton.RigidbodyNameToRigidbody("None:None"); CurrentController.SelectLinkToRigidbody(linkToAtom, FreeControllerV3.SelectLinkState.PositionAndRotation); } yield return new WaitForSeconds(0.5f); if (collision_bool.val) { TargetAtom.collisionEnabled = false; yield return new WaitForSeconds(0.01f); TargetAtom.collisionEnabled = true; } else { TargetAtom.collisionEnabled = false; } foreach (var item in _poseMorph) { morphControl.GetMorphByDisplayName(item).morphValue = _morphDic[item]; } } public void resetExpression() { morphControl.GetMorphUids().ForEach((uid) => { DAZMorph morph = morphControl.GetMorphByUid(uid); if (morph.isPoseControl | (morph.region.Contains("Pose") && resetFaceMorph_Bool.val)) { if (morph.region.Contains("Head")) { morph.SetDefaultValue(); } } if ((morph.region.Contains("Expression") | morph.region.Contains("expression")) && resetExpression_Bool.val) { morph.SetDefaultValue(); } }); if (_selectPerson2.val != "None") { _2ndPerson = SuperController.singleton.GetAtomByUid(_selectPerson2.val); geometry2 = _2ndPerson.GetStorableByID("geometry"); character2 = geometry2 as DAZCharacterSelector; morphControl2 = character2.morphsControlUI; morphControl2.GetMorphUids().ForEach((uid) => { DAZMorph morph = morphControl2.GetMorphByUid(uid); if (morph.isPoseControl | (morph.region.Contains("Pose") && resetFaceMorph_Bool.val)) { if (morph.region.Contains("Head")) { morph.SetDefaultValue(); } } if ((morph.region.Contains("Expression") | morph.region.Contains("expression")) && resetExpression_Bool.val) { morph.SetDefaultValue(); } }); } } public void LoadPoseCont() { if (_enableAutoLoad.val) { _loopStart = true; } else { _loopStart = false; } if (_poseFileList != null && _poseFileList.Count != 0) { _isMakePoseList = true; filename.val = ""; if (_enableRnd.val) { _currentPose.val = _poseFileList[_randomOrder[_previousNumber]]; HandleLoadPreset(_poseFileList[_randomOrder[_previousNumber]]); } else { _currentPose.val = _poseFileList[_previousNumber]; HandleLoadPreset(_poseFileList[_previousNumber]); } _previousNumber++; if (_previousNumber >= _poseFileList.Count) { _previousNumber = 0; var lastNumber = _randomOrder[_poseFileList.Count - 1]; _randomOrder = MakeRandomOrder(_poseFileList.Count, lastNumber); } } else { _loopStart = false; } _startTime = DateTime.Now.Minute * 60 + DateTime.Now.Second; } public void SetVapPoseDirectory() { _loopStart = false; var shortcuts = FileManagerSecure.GetShortCutsForDirectory(_vapPosePath); var posePath = _vapPosePath; SuperController.singleton.GetDirectoryPathDialog(MakePoseList, posePath, shortcuts, false); } public void SetJsonPoseDirectory() { _loopStart = false; var shortcuts = FileManagerSecure.GetShortCutsForDirectory(_jsonPosePath); var posePath = _jsonPosePath; SuperController.singleton.GetDirectoryPathDialog(MakePoseList, posePath, shortcuts, false); } public void SetPoseDirectory() { _loopStart = false; MakePoseList(_poseDirectory.val); } public void MakePoseList(string path) { if (path != null && path != "") { path = path.Replace("\\", "/"); _poseDirectory.val = path; var varName = MakeVarName(path); var dirName = MakeDirName(path); //var filename = MakeFilename(path); if (varName == "" && _sceneVar != "") { var tempPath = _sceneVar + ":/" + dirName; if (FileManagerSecure.DirectoryExists(tempPath) && _enablePathInSceneVar.val) { path = tempPath; } else if (!FileManagerSecure.DirectoryExists(dirName)) { path = tempPath; } else { path = dirName; } } else if (varName != "") { path = varName + ":/" + dirName; } else { path = dirName; } _varFileName = ""; string favPath; if (path.Contains(":")) { var pathSplit = path.Split(':'); _varFileName = pathSplit[0]; favPath = _filePrefs + _varFileName + pathSplit[1]; } else { favPath = path; } string[] poseFiles; string[] favFiles; string poseFileList = ""; string favFileList = ""; if (_enableSubfolder.val) { ArrayList allFiles = new ArrayList(); SearchFile(path, "Preset_*.vap", ref allFiles); poseFiles = (string[])allFiles.ToArray(typeof(string)); Array.Sort(poseFiles); _poseList = new List(); foreach (var item in poseFiles) { string tempFileName = item.Replace("\\", "/"); _poseList.Add(tempFileName); if (tempFileName.Contains(":")) { var itemSplit = tempFileName.Split(':'); tempFileName = _varFileName + ":" + itemSplit[1].Remove(0, _vapPosePath.Length + 2); } else { tempFileName = tempFileName.Remove(0, _vapPosePath.Length + 1); } tempFileName = tempFileName.Remove(tempFileName.LastIndexOf("Preset_"), 7); tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".vap")); if (poseFileList.Length < _jsonstringLimit) { poseFileList = poseFileList + tempFileName + "\n"; } } allFiles = new ArrayList(); SearchFile(path, "*.json", ref allFiles); poseFiles = (string[])allFiles.ToArray(typeof(string)); Array.Sort(poseFiles); foreach (var item in poseFiles) { string tempFileName = item.Replace("\\", "/"); _poseList.Add(tempFileName); if (tempFileName.Contains(":")) { var itemSplit = tempFileName.Split(':'); tempFileName = _varFileName + ":" + itemSplit[1].Remove(0, _jsonPosePath.Length + 2); } else { tempFileName = tempFileName.Remove(0, _jsonPosePath.Length + 1); } tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".json")); if (poseFileList.Length < _jsonstringLimit) { poseFileList = poseFileList + tempFileName + "\n"; } } allFiles = new ArrayList(); if (FileManagerSecure.DirectoryExists(favPath)) { allFiles = new ArrayList(); SearchFile(favPath, "Preset_*.vap.fav", ref allFiles); favFiles = (string[])allFiles.ToArray(typeof(string)); Array.Sort(favFiles); _favList = new List(); foreach (var item in favFiles) { string tempFileName = item.Replace("\\", "/"); tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".fav")); var tempFavFile = tempFileName; if (tempFavFile.Contains(_filePrefs)) { tempFavFile = tempFavFile.Remove(0, _filePrefs.Length); tempFavFile = tempFavFile.Remove(0, _varFileName.Length + 1); tempFavFile = _varFileName + ":/" + tempFavFile; } _favList.Add(tempFavFile); if (tempFileName.Contains(_filePrefs)) { tempFileName = tempFileName.Remove(0, _filePrefs.Length); tempFileName = tempFileName.Remove(0, _varFileName.Length + 1); tempFileName = tempFileName.Remove(0, _vapPosePath.Length + 1); tempFileName = _varFileName + ":" + tempFileName; } else { tempFileName = tempFileName.Remove(0, _vapPosePath.Length + 1); } tempFileName = tempFileName.Remove(tempFileName.LastIndexOf("Preset_"), 7); tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".vap")); if (favFileList.Length < _jsonstringLimit) { favFileList = favFileList + tempFileName + "\n"; } } allFiles = new ArrayList(); SearchFile(favPath, "*.json.fav", ref allFiles); favFiles = (string[])allFiles.ToArray(typeof(string)); Array.Sort(favFiles); foreach (var item in favFiles) { string tempFileName = item.Replace("\\", "/"); tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".fav")); var tempFavFile = tempFileName; if (tempFavFile.Contains(_filePrefs)) { tempFavFile = tempFavFile.Remove(0, _filePrefs.Length); tempFavFile = tempFavFile.Remove(0, _varFileName.Length + 1); tempFavFile = _varFileName + ":/" + tempFavFile; } _favList.Add(tempFavFile); if (tempFileName.Contains(_filePrefs)) { tempFileName = tempFileName.Remove(0, _filePrefs.Length); tempFileName = tempFileName.Remove(0, _varFileName.Length + 1); tempFileName = tempFileName.Remove(0, _jsonPosePath.Length + 1); tempFileName = _varFileName + ":" + tempFileName; } else { tempFileName = tempFileName.Remove(0, _jsonPosePath.Length + 1); } tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".json")); if (favFileList.Length < _jsonstringLimit) { favFileList = favFileList + tempFileName + "\n"; } } } else { _favList = new List(); favFileList = ""; } } else { poseFiles = FileManagerSecure.GetFiles(path, "Preset_*.vap"); Array.Sort(poseFiles); _poseList = new List(); foreach (var item in poseFiles) { string tempFileName = item.Replace("\\", "/"); _poseList.Add(tempFileName); if (tempFileName.Contains(":")) { var itemSplit = tempFileName.Split(':'); tempFileName = _varFileName + ":" + itemSplit[1].Remove(0, _vapPosePath.Length + 2); } else { tempFileName = tempFileName.Remove(0, _vapPosePath.Length + 1); } tempFileName = tempFileName.Remove(tempFileName.LastIndexOf("Preset_"), 7); tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".vap")); if (poseFileList.Length < _jsonstringLimit) { poseFileList = poseFileList + tempFileName + "\n"; } } poseFiles = FileManagerSecure.GetFiles(path, "*.json"); Array.Sort(poseFiles); foreach (var item in poseFiles) { string tempFileName = item.Replace("\\", "/"); _poseList.Add(tempFileName); if (tempFileName.Contains(":")) { var itemSplit = tempFileName.Split(':'); tempFileName = _varFileName + ":" + itemSplit[1].Remove(0, _jsonPosePath.Length + 2); } else { tempFileName = tempFileName.Remove(0, _jsonPosePath.Length + 1); } tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".json")); if (poseFileList.Length < _jsonstringLimit) { poseFileList = poseFileList + tempFileName + "\n"; } } if (FileManagerSecure.DirectoryExists(favPath)) { favFiles = FileManagerSecure.GetFiles(favPath, "Preset_*.vap.fav"); Array.Sort(favFiles); _favList = new List(); foreach (var item in favFiles) { string tempFileName = item.Replace("\\", "/"); tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".fav")); var tempFavFile = tempFileName; if (tempFavFile.Contains(_filePrefs)) { tempFavFile = tempFavFile.Remove(0, _filePrefs.Length); tempFavFile = tempFavFile.Remove(0, _varFileName.Length + 1); tempFavFile = _varFileName + ":/" + tempFavFile; } _favList.Add(tempFavFile); if (tempFileName.Contains(_filePrefs)) { tempFileName = tempFileName.Remove(0, _filePrefs.Length); tempFileName = tempFileName.Remove(0, _vapPosePath.Length + 1); tempFileName = _varFileName + ":" + tempFileName; } else { tempFileName = tempFileName.Remove(0, _vapPosePath.Length + 1); } tempFileName = tempFileName.Remove(tempFileName.LastIndexOf("Preset_"), 7); tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".vap")); if (favFileList.Length < _jsonstringLimit) { favFileList = favFileList + tempFileName + "\n"; } } favFiles = FileManagerSecure.GetFiles(favPath, "*.json.fav"); Array.Sort(favFiles); foreach (var item in favFiles) { string tempFileName = item.Replace("\\", "/"); tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".fav")); var tempFavFile = tempFileName; if (tempFavFile.Contains(_filePrefs)) { tempFavFile = tempFavFile.Remove(0, _filePrefs.Length); tempFavFile = tempFavFile.Remove(0, _varFileName.Length + 1); tempFavFile = _varFileName + ":/" + tempFavFile; } _favList.Add(tempFavFile); if (tempFileName.Contains(_filePrefs)) { tempFileName = tempFileName.Remove(0, _filePrefs.Length); tempFileName = tempFileName.Remove(0, _jsonPosePath.Length + 1); tempFileName = _varFileName + ":" + tempFileName; } else { tempFileName = tempFileName.Remove(0, _jsonPosePath.Length + 1); } tempFileName = tempFileName.Remove(tempFileName.LastIndexOf(".json")); if (favFileList.Length < _jsonstringLimit) { favFileList = favFileList + tempFileName + "\n"; } } } else { _favList = new List(); favFileList = ""; } } _poseListText = poseFileList; _favListText = favFileList; if (_onlyFav.val) { _filesInFolder.val = _favListText; _poseFileList = new List(_favList); } else { _filesInFolder.val = _poseListText; _poseFileList = new List(_poseList); } _randomOrder = MakeRandomOrder(_poseFileList.Count, 0); _isMakePoseList = true; //_previousNumber = 0; } } public void LoadCouplePose() { if (_selectPerson2.val != "None") { _2ndPerson = SuperController.singleton.GetAtomByUid(_selectPerson2.val); _2ndPerson.GetStorableByID("PosePresets").GetStringJSONParam("presetName").val = _pathFor2ndPoseString.val; } else { _2ndPerson = null; } var setStartTime = DateTime.Now.Second * 1000 + DateTime.Now.Millisecond; var currentTime = setStartTime; do { currentTime = DateTime.Now.Second * 1000 + DateTime.Now.Millisecond; if (setStartTime > currentTime) { currentTime += 60000; } } while (currentTime - setStartTime < 200); TargetAtom.GetStorableByID("PosePresets").CallAction("LoadPreset"); if (_2ndPerson != null) { _2ndPerson.GetStorableByID("PosePresets").CallAction("LoadPreset"); } } public void MakePersonList() { List targetChoices = new List(); targetChoices.Add("None"); foreach (string atomUID in SuperController.singleton.GetAtomUIDs()) { var selectAtom = SuperController.singleton.GetAtomByUid(atomUID); if (selectAtom.type == "Person" && atomUID != TargetAtom.uid) { targetChoices.Add(atomUID); } } _selectPerson2.choices = targetChoices; } public void SelectPose1() { _isCurrent = true; if (!keepFolder_Bool.val) { _pathFor1stPose = _vapPosePath; } var vapPoseShortcuts = FileManagerSecure.GetShortCutsForDirectory(_vapPosePath, false, false, true, true); SuperController.singleton.GetMediaPathDialog(HandleSetPreset, "vap", _pathFor1stPose, false, true, false, null, false, vapPoseShortcuts); } public void SelectPose2() { _isCurrent = false; if (!keepFolder_Bool.val) { _pathFor2ndPose = _vapPosePath; } var vapPoseShortcuts = FileManagerSecure.GetShortCutsForDirectory(_vapPosePath, false, false, true, true); SuperController.singleton.GetMediaPathDialog(HandleSetPreset, "vap", _pathFor2ndPose, false, true, false, null, false, vapPoseShortcuts); } public void SetPose1() { _isCurrent = true; MakePath(_pathFor1stPoseString.val); } public void SetPose2() { _isCurrent = false; MakePath(_pathFor2ndPoseString.val); } public void MakePath(string tempName) { tempName = tempName.Replace("\\", "/"); tempName = tempName.Replace(".var:", ":").Replace(":/", ":"); string varName; string path; string[] pathSplit; if (tempName.Contains(":")) { pathSplit = tempName.Split(':'); varName = pathSplit[0] + ":"; path = pathSplit[1]; } else { varName = ""; path = tempName; } if (!path.Contains(_vapPosePath)) { path = _vapPosePath + "/" + path; path = path.Replace("//", "/"); } var pathPre = path.Substring(0, path.LastIndexOf("/")); var pathPost = path.Substring(path.LastIndexOf("/") + 1); if (pathPost.Substring(pathPost.Length - 4) != ".vap") { pathPost = pathPost + ".vap"; } if (pathPost.Substring(0, 7) != "Preset_") { pathPost = "Preset_" + pathPost; } tempName = varName + pathPre + "/" + pathPost; HandleSetPreset(tempName); } public void HandleSetPreset(string path) { if (path != null && path != "") { path = path.Replace("\\", "/").Replace(":/", ":"); string varName; if (path.Contains(":")) { var pathSplit = path.Split(':'); varName = pathSplit[0]; path = pathSplit[1]; } else { varName = ""; } var tempPath = path.Remove(path.LastIndexOf("/")); if (_isCurrent) { _pathFor1stPose = tempPath.Replace("/", "\\"); } else { _pathFor2ndPose = tempPath.Replace("/", "\\"); } tempPath = path.Remove(path.LastIndexOf(".vap")).Substring(_vapPosePath.Length + 1); if (tempPath.Contains("/Preset")) { var tempPre = tempPath.Substring(0, tempPath.LastIndexOf("/Preset_")); var tempPost = tempPath.Substring(tempPath.LastIndexOf("/Preset_") + 8); tempPath = tempPre + "/" + tempPost; } else { tempPath = tempPath.Substring(7); } if (_selectPerson2.val != "None") { _2ndPerson = SuperController.singleton.GetAtomByUid(_selectPerson2.val); } else { _2ndPerson = null; } if (varName != "") { tempPath = varName + ":" + tempPath; } if (_isCurrent) { _pathFor1stPoseString.val = tempPath; TargetAtom.GetStorableByID("PosePresets").GetStringJSONParam("presetName").val = tempPath; } else { _pathFor2ndPoseString.val = tempPath; if (_2ndPerson != null) { _2ndPerson.GetStorableByID("PosePresets").GetStringJSONParam("presetName").val = tempPath; } } } } public void ChangePath() { _loopStart = false; if (_onlyFav.val) { _filesInFolder.val = _favListText; _poseFileList = new List(_favList); } else { _filesInFolder.val = _poseListText; _poseFileList = new List(_poseList); } _randomOrder = MakeRandomOrder(_poseFileList.Count, 0); } public void ResetCount() { _loopStart = false; if (_enableRnd.val) { _randomOrder = MakeRandomOrder(_poseFileList.Count, 0); } else { _previousNumber = 0; } } public void RefreshList() { _poseFileList = new List(); MakePoseList(_poseDirectory.val); ChangePath(); } public List MakeRandomOrder(int number, int lastOne) { _previousNumber = 0; if (number != 0) { List randomOrder = new List(); List tempList = new List(); if (number == 1) { randomOrder.Add(0); } else if (number == 2) { if (lastOne == 0) { randomOrder.Add(1); randomOrder.Add(0); } else { randomOrder.Add(0); randomOrder.Add(1); } } else { for (int i = 0; i < number; i++) { tempList.Add(i); } int randomNumber; do { randomNumber = UnityEngine.Random.Range(0, number); } while (randomNumber == lastOne); randomOrder.Add(tempList[randomNumber]); tempList.Remove(randomNumber); number--; do { randomNumber = UnityEngine.Random.Range(0, number); randomOrder.Add(tempList[randomNumber]); tempList.RemoveAt(randomNumber); number--; } while (number > 0); } return randomOrder; } else { return null; } } public string MakeVarName(string path) { if (path != null && path != "") { path = path.Replace("\\", "/"); { if (path.Contains(":")) { var tempSplit = path.Split(':'); path = tempSplit[0]; } else if (!path.Contains(".")) { return ""; } else { var ext = path.Substring(path.LastIndexOf(".")); if (ext == ".vap" || ext == ".json") { return ""; } } if (path.Substring(path.Length - 4, 4) == ".var") { path = path.Remove(path.Length - 4, 4); } var varNameFull = path; if (path.Contains("/")) { var tempSplit = path.Split('/'); if (FileManagerSecure.FileExists(path + ".var")) { path = tempSplit[tempSplit.Length - 1]; return path; } else { varNameFull = tempSplit[tempSplit.Length - 1]; var tempVarSplit = varNameFull.Split('.'); if (tempVarSplit.Length != 3) { return ""; } } } var varNameSplit = varNameFull.Split('.'); var varName = varNameSplit[0] + "." + varNameSplit[1]; var varExist = FileManagerSecure.FileExists(_addonPackagesPath + "/" + varNameFull + ".var"); if (varExist) { path = varNameFull; return path; } else { int i = 100; bool varExistFull; bool varExistKy; do { i--; varExistFull = FileManagerSecure.FileExists(path.Remove(path.LastIndexOf(".")) + "." + i.ToString() + ".var"); varExist = FileManagerSecure.FileExists(_addonPackagesPath + "/" + varName + "." + i.ToString() + ".var"); varExistKy = FileManagerSecure.FileExists(_addonPackagesPath + "/" + _addonPackagesPath + "/" + varName + "." + i.ToString() + ".var"); } while (!varExistFull && !varExist && !varExistKy && i > 0); if (i != 0) { path = varName + "." + i.ToString(); } else { ArrayList allFiles = new ArrayList(); SearchFile(_addonPackagesPath, varName + ".*.var", ref allFiles); var searchedFiles = (string[])allFiles.ToArray(typeof(string)); List varFiles = new List(); if (searchedFiles != null) { foreach (var item in searchedFiles) { var searchedFilesSplit = item.Replace("\\", "/").Split('/'); var searchedVarName = searchedFilesSplit[searchedFilesSplit.Length - 1]; searchedVarName = searchedVarName.Remove(searchedVarName.LastIndexOf(".var")); varFiles.Add(searchedVarName); } if (varFiles.Contains(varNameFull)) { varName = varNameFull; } else { int latest = 1; foreach (var item in varFiles) { var itemSplit = item.Split('.'); if (latest <= int.Parse(itemSplit[2])) { latest = int.Parse(itemSplit[2]); } } varName = varNameFull.Remove(varNameFull.LastIndexOf(".")) + "." + latest.ToString(); } path = varName; } else { path = ""; } } } } return path; } return ""; } public string MakeDirName(string path) { if (path != null && path != "") { path = path.Replace("\\", "/"); if (path.Contains(":")) { path = path.Replace(":/", ":"); var pathSplit = path.Split(':'); path = pathSplit[1]; } if (!path.Contains(_vapPosePath) && !path.Contains(_jsonPosePath)) { path = _vapPosePath + "/" + path; } if (path.Contains(".")) { if (path.Substring(path.LastIndexOf("."), 4) == ".vap" || path.Substring(path.LastIndexOf("."), 5) == ".json") { path = path.Remove(path.LastIndexOf("/")); } } return path; } return ""; } public string MakeFilename(string path) { if (path != null && path != "") { path = path.Replace("\\", "/"); if (path.Contains(":")) { path = path.Replace(":/", ":"); var pathSplit = path.Split(':'); path = pathSplit[1]; } if (path.Length < 6 && !path.Contains(".")) { path = _vapPosePath + "/" + path + ".vap"; } else if (path.Substring(path.Length - 4, 4) == ".vap") { if (!path.Contains(_vapPosePath)) { path = _vapPosePath + "/" + path; } } else if (path.Substring(path.Length - 5, 5) == ".json") { if (!path.Contains(_jsonPosePath)) { path = _jsonPosePath + "/" + path; } return path; } else if (path.Contains(_vapPosePath)) { path = path + ".vap"; } else if (path.Contains(_jsonPosePath)) { path = path + ".json"; return path; } else { path = _vapPosePath + "/" + path + ".vap"; } if (path.Substring(path.LastIndexOf("/"), 8) != "/Preset_") { if (path.Substring(path.LastIndexOf("/"), 8) == "/preset_") { path = path.Replace("/preset_", "/Preset_"); } else { path = path.Insert(path.LastIndexOf("/") + 1, "Preset_"); } } return path; } return ""; } public static void SearchFile(string folder, string filter, ref ArrayList allFiles) { string[] filses = FileManagerSecure.GetFiles(folder, filter); allFiles.AddRange(filses); string[] subFolders = FileManagerSecure.GetDirectories(folder); foreach (string subF in subFolders) { SearchFile(subF, filter, ref allFiles); } } void Start() { UpdateInitialMorphs(); } private void UpdateInitialMorphs() { geometry = TargetAtom.GetStorableByID("geometry"); character = geometry as DAZCharacterSelector; morphControl = character.morphsControlUI; } #endregion public void FixedUpdate() { try { if (_loopStart && _enableAutoLoad.val) { var currentTime = DateTime.Now.Minute * 60 + DateTime.Now.Second; if (currentTime < _startTime) { currentTime += 3600; } if (currentTime - _startTime >= int.Parse(_selectCount.val)) { LoadPoseCont(); } } else { _loopStart = false; } } catch (Exception e) { SuperController.LogError("Exception caught: " + e); } } public void OnDisable() { } public void OnDestroy() { } } }