Exemplo n.º 1
0
        private void LoadPoseNew(List <string> lines)
        {
            Armature armature = selectedItem.Model.Armature;
            Dictionary <string, BoneTransform> boneTransforms = new Dictionary <string, BoneTransform>();

            foreach (string line in lines)
            {
                string[] tokens1 = line.Split(':');
                if (tokens1.Length == 2)
                {
                    string        boneName = tokens1[0].Trim();
                    Armature.Bone bone     = armature.GetBone(boneName);
                    if (bone != null)
                    {
                        string[] tokens2 = tokens1[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        if (tokens2.Length == 3 || tokens2.Length == 6)
                        {
                            BoneTransform boneTransform = new BoneTransform();
                            boneTransform.rotX = float.Parse(tokens2[0]);
                            boneTransform.rotY = float.Parse(tokens2[1]);
                            boneTransform.rotZ = float.Parse(tokens2[2]);
                            if (tokens2.Length == 6)
                            {
                                boneTransform.moveX = float.Parse(tokens2[3]);
                                boneTransform.moveY = float.Parse(tokens2[4]);
                                boneTransform.moveZ = float.Parse(tokens2[5]);
                            }
                            else
                            {
                                boneTransform.moveX = 0;
                                boneTransform.moveY = 0;
                                boneTransform.moveZ = 0;
                            }
                            boneTransforms[boneName] = boneTransform;
                        }
                    }
                }
            }

            ICollection <string> boneNames = boneTransforms.Keys;
            PoseFilterDialog     dialog    = new PoseFilterDialog(game, "Load pose", "Select bones to load:", boneNames, true);

            if (dialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }
            DataSet dataSet = dataSetDict[selectedItem];

            foreach (string boneName in boneNames)
            {
                if (dialog.IsBoneSelected(boneName))
                {
                    Armature.Bone bone          = armature.GetBone(boneName);
                    BoneTransform boneTransform = boneTransforms[boneName];
                    dataSet.boneTransforms[bone.id] = boneTransform;
                    ApplyTransformToBone(bone, boneTransform);
                }
            }
        }
Exemplo n.º 2
0
        private void SavePose(string filename)
        {
            Armature      armature  = selectedItem.Model.Armature;
            List <string> boneNames = new List <string>();

            foreach (Armature.Bone bone in armature.Bones)
            {
                if (!bone.name.StartsWith("unused"))
                {
                    boneNames.Add(bone.name);
                }
            }

            PoseFilterDialog dialog = new PoseFilterDialog(game, "Save pose", "Select bones to save:", boneNames, true);

            if (dialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            try {
                DataSet      dataSet = dataSetDict[selectedItem];
                StreamWriter file    = new StreamWriter(filename);
                foreach (Armature.Bone bone in armature.Bones)
                {
                    if (!dialog.IsBoneSelected(bone.name))
                    {
                        continue;
                    }
                    BoneTransform boneTransform = dataSet.boneTransforms[bone.id];
                    file.WriteLine("{0}: {1} {2} {3} {4} {5} {6}", bone.name,
                                   boneTransform.rotX, boneTransform.rotY, boneTransform.rotZ,
                                   boneTransform.moveX, boneTransform.moveY, boneTransform.moveZ);
                }
                file.Close();
            }
            catch (Exception ex) {
                MessageBox.Show(this, "Could not save the pose file.\n" + ex.Message,
                                "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Exemplo n.º 3
0
        private void MirrorPose()
        {
            if (selectedItem == null)
            {
                return;
            }

            Armature armature = selectedItem.Model.Armature;

            List <string> labels = new List <string>();

            foreach (Armature.Bone bone in armature.Bones)
            {
                int    origSide;
                string mirroredName = GetMirroredBoneName(bone.name, out origSide);
                if (mirroredName != null && origSide < 0 && armature.GetBone(mirroredName) != null)
                {
                    labels.Add("L: " + bone.name);
                }
            }
            foreach (Armature.Bone bone in armature.Bones)
            {
                int    origSide;
                string mirroredName = GetMirroredBoneName(bone.name, out origSide);
                if (mirroredName != null && origSide > 0 && armature.GetBone(mirroredName) != null)
                {
                    labels.Add("R: " + bone.name);
                }
            }

            PoseFilterDialog dialog = new PoseFilterDialog(game, "Mirror (copy) pose left/right", "Select bones to mirror pose from:", labels, false);

            if (dialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            DataSet dataSet = dataSetDict[selectedItem];

            foreach (string label in labels)
            {
                if (!dialog.IsBoneSelected(label))
                {
                    continue;
                }

                string        boneNameFrom      = label.Substring(3);
                Armature.Bone boneFrom          = armature.GetBone(boneNameFrom);
                BoneTransform boneTransformFrom = dataSet.boneTransforms[boneFrom.id];

                string        boneNameTo      = GetMirroredBoneName(boneNameFrom);
                Armature.Bone boneTo          = armature.GetBone(boneNameTo);
                BoneTransform boneTransformTo = dataSet.boneTransforms[boneTo.id];

                boneTransformTo.moveX = -boneTransformFrom.moveX;
                boneTransformTo.moveY = +boneTransformFrom.moveY;
                boneTransformTo.moveZ = +boneTransformFrom.moveZ;

                boneTransformTo.rotX = +boneTransformFrom.rotX;
                boneTransformTo.rotY = -boneTransformFrom.rotY;
                boneTransformTo.rotZ = -boneTransformFrom.rotZ;

                ApplyTransformToBone(boneTo, boneTransformTo);
            }
        }
Exemplo n.º 4
0
        private void FlipPose()
        {
            if (selectedItem == null)
            {
                return;
            }

            Armature armature = selectedItem.Model.Armature;

            List <string> labels = new List <string>();
            Dictionary <string, string> labelsToBoneNames = new Dictionary <string, string>();

            foreach (Armature.Bone bone in armature.Bones)
            {
                int    origSide;
                string flippedName = GetFlippedBoneName(bone.name, out origSide);
                if (flippedName != null && origSide < 0 && armature.GetBone(flippedName) != null)
                {
                    string combinedName = GetCombinedBoneName(bone.name);
                    labels.Add(combinedName);
                    labelsToBoneNames[combinedName] = bone.name;
                }
            }

            PoseFilterDialog dialog = new PoseFilterDialog(game, "Flip (swap) pose left/right", "Select bone pairs whose pose to flip:", labels, false);

            if (dialog.ShowDialog(this) != DialogResult.OK)
            {
                return;
            }

            DataSet dataSet = dataSetDict[selectedItem];

            foreach (string label in labels)
            {
                if (!dialog.IsBoneSelected(label))
                {
                    continue;
                }

                string        boneName1      = labelsToBoneNames[label];
                Armature.Bone bone1          = armature.GetBone(boneName1);
                BoneTransform boneTransform1 = dataSet.boneTransforms[bone1.id];

                string        boneName2      = GetFlippedBoneName(boneName1);
                Armature.Bone bone2          = armature.GetBone(boneName2);
                BoneTransform boneTransform2 = dataSet.boneTransforms[bone2.id];

                float moveX1 = boneTransform1.moveX;
                float moveY1 = boneTransform1.moveY;
                float moveZ1 = boneTransform1.moveZ;

                float rotX1 = boneTransform1.rotX;
                float rotY1 = boneTransform1.rotY;
                float rotZ1 = boneTransform1.rotZ;

                float moveX2 = boneTransform2.moveX;
                float moveY2 = boneTransform2.moveY;
                float moveZ2 = boneTransform2.moveZ;

                float rotX2 = boneTransform2.rotX;
                float rotY2 = boneTransform2.rotY;
                float rotZ2 = boneTransform2.rotZ;

                boneTransform2.moveX = -moveX1;
                boneTransform2.moveY = +moveY1;
                boneTransform2.moveZ = +moveZ1;

                boneTransform2.rotX = +rotX1;
                boneTransform2.rotY = -rotY1;
                boneTransform2.rotZ = -rotZ1;

                boneTransform1.moveX = -moveX2;
                boneTransform1.moveY = +moveY2;
                boneTransform1.moveZ = +moveZ2;

                boneTransform1.rotX = +rotX2;
                boneTransform1.rotY = -rotY2;
                boneTransform1.rotZ = -rotZ2;

                ApplyTransformToBone(bone1, boneTransform1);
                ApplyTransformToBone(bone2, boneTransform2);
            }
        }