Exemple #1
0
        public static void LoadOffsetsFromFile()
        {
            ConvertLegacyFile();

            // Create an XML serializer so we can read the offset configuration in an XML file
            var serializer = new XmlSerializer(typeof(BetterHScenesOffsetsXML));

            hSceneOffsets = new BetterHScenesOffsetsXML();

            Stream OffsetFile;

            try
            {
                // Read in the data
                string fileName = HS2_BetterHScenes.offsetFileV2.Value;

                OffsetFile    = new FileStream(fileName, FileMode.Open);
                hSceneOffsets = (BetterHScenesOffsetsXML)serializer.Deserialize(OffsetFile);
            }
            catch
            {
                //HS2_BetterHScenes.Logger.LogMessage("read error!");
                return;
            }

            // Close the file
            OffsetFile.Close();
        }
Exemple #2
0
        private static void ConvertLegacyFile()
        {
            hSceneOffsets = new BetterHScenesOffsetsXML();

            Stream OffsetFile;

            try
            {
                // Read in the data
                string fileName = HS2_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);
                                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));
                                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));
                                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));
                                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));

                                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;
            }
        }