public void AddMotionOffsets(MotionOffsetsXML motionOffsets) { var existingMotionOffsets = MotionOffsetList.Find(x => x.MotionName == motionOffsets.MotionName); if (existingMotionOffsets != null) { MotionOffsetList.Remove(existingMotionOffsets); } MotionOffsetList.Add(motionOffsets); }
//-- Save the character pair of offsets to the xml file, overwriting if necessary --// public static void SaveCharacterGroupOffsets(List <string> characterNames, List <OffsetVectors[]> offsetVectorList, List <bool[]> jointCorrectionList, List <float> shoeOffsets, bool isDefault = false) { if (characterNames.IsNullOrEmpty() || offsetVectorList.IsNullOrEmpty() || shoeOffsets.IsNullOrEmpty()) { return; } var currentAnimation = AI_BetterHScenes.hFlagCtrl.nowAnimationInfo.nameAnimation; if (currentAnimation == null || AI_BetterHScenes.currentMotion == null) { return; } var currentMotion = AI_BetterHScenes.currentMotion; if (isDefault) { currentMotion = "default"; } string characterGroupName = null; foreach (var name in characterNames) { if (characterGroupName == null) { characterGroupName = name; } else { characterGroupName += "_" + name; } } AI_BetterHScenes.Logger.LogMessage("Saving Offsets for " + currentAnimation + " Motion " + currentMotion + " for characters " + characterGroupName); var characterGroup = new CharacterGroupXML(characterGroupName); for (var charIndex = 0; charIndex < characterNames.Count; charIndex++) { var motionOffsets = new MotionOffsetsXML(currentMotion, offsetVectorList[charIndex], jointCorrectionList[charIndex]); var animation = new AnimationXML(currentAnimation); animation.AddMotionOffsets(motionOffsets); var character = new CharacterXML(characterNames[charIndex], shoeOffsets[charIndex]); character.AddAnimation(animation); characterGroup.AddCharacter(character); } hSceneOffsets.AddCharacterGroup(characterGroup); SaveOffsetsToFile(); }
private static void ConvertLegacyFile() { hSceneOffsets = new BetterHScenesOffsetsXML(); Stream OffsetFile; try { // Read in the data string fileName = AI_BetterHScenes.offsetFile.Value; OffsetFile = new FileStream(fileName, FileMode.Open); var serializer = new XmlSerializer(typeof(AnimationOffsets)); var animationOffsets = (AnimationOffsets)serializer.Deserialize(OffsetFile); foreach (var animation in animationOffsets.Animations) { foreach (var motion in animation.MotionList) { foreach (var characterPair in motion.CharacterPairList) { CharacterGroupXML characterGroupXML = new CharacterGroupXML(characterPair.CharacterPairName); foreach (var character in characterPair.CharacterOffsets) { OffsetVectors[] offsetVectors = new OffsetVectors[(int)BodyPart.BodyPartsCount]; offsetVectors[(int)BodyPart.WholeBody] = new OffsetVectors(new Vector3(character.PositionOffsetX, character.PositionOffsetY, character.PositionOffsetZ), new Vector3(character.RotationOffsetP, character.RotationOffsetY, character.RotationOffsetR), Vector3.zero, 0f); offsetVectors[(int)BodyPart.LeftHand] = new OffsetVectors(new Vector3(character.LeftHandPositionOffsetX, character.LeftHandPositionOffsetY, character.LeftHandPositionOffsetZ), new Vector3(character.LeftHandRotationOffsetP, character.LeftHandRotationOffsetY, character.LeftHandRotationOffsetR), new Vector3(character.LeftHandHintPositionOffsetX, character.LeftHandHintPositionOffsetY, character.LeftHandHintPositionOffsetZ), 0f); offsetVectors[(int)BodyPart.RightHand] = new OffsetVectors(new Vector3(character.RightHandPositionOffsetX, character.RightHandPositionOffsetY, character.RightHandPositionOffsetZ), new Vector3(character.RightHandRotationOffsetP, character.RightHandRotationOffsetY, character.RightHandRotationOffsetR), new Vector3(character.RightHandHintPositionOffsetX, character.RightHandHintPositionOffsetY, character.RightHandHintPositionOffsetZ), 0f); offsetVectors[(int)BodyPart.LeftFoot] = new OffsetVectors(new Vector3(character.LeftFootPositionOffsetX, character.LeftFootPositionOffsetY, character.LeftFootPositionOffsetZ), new Vector3(character.LeftFootRotationOffsetP, character.LeftFootRotationOffsetY, character.LeftFootRotationOffsetR), new Vector3(character.LeftFootHintPositionOffsetX, character.LeftFootHintPositionOffsetY, character.LeftFootHintPositionOffsetZ), 0f); offsetVectors[(int)BodyPart.RightFoot] = new OffsetVectors(new Vector3(character.RightFootPositionOffsetX, character.RightFootPositionOffsetY, character.RightFootPositionOffsetZ), new Vector3(character.RightFootRotationOffsetP, character.RightFootRotationOffsetY, character.RightFootRotationOffsetR), new Vector3(character.RightFootHintPositionOffsetX, character.RightFootHintPositionOffsetY, character.RightFootHintPositionOffsetZ), 0f); bool[] jointCorrections = new bool[(int)BodyPart.BodyPartsCount]; MotionOffsetsXML motionOffsetsXML = new MotionOffsetsXML(motion.MotionName, offsetVectors, jointCorrections); AnimationXML animationXML = new AnimationXML(animation.AnimationName); CharacterXML characterXML = new CharacterXML(character.CharacterName, 0); animationXML.AddMotionOffsets(motionOffsetsXML); characterXML.AddAnimation(animationXML); characterGroupXML.AddCharacter(characterXML); } hSceneOffsets.AddCharacterGroup(characterGroupXML); } } } SaveOffsetsToFile(); // Close the file OffsetFile.Close(); File.Delete(fileName); } catch { //HS2_BetterHScenes.Logger.LogMessage("read error!"); return; } }