Beispiel #1
0
        private static void SetBoneRotation(BoneAssigner bone, CtMatrix4x4 tm)
        {
            CtMatrix4x4 ctMatrix4x = CtMatrix4x4.UnitMatrix();

            for (CtBone ctBone = bone.Bone; ctBone != null; ctBone = ctBone.Parent)
            {
                ctMatrix4x *= ctBone.InitMatrix;
            }
            CtMatrix4x4 ctMatrix4x2 = CtMatrix4x4.UnitMatrix();

            CtVector3D[] array = new CtVector3D[]
            {
                CtMatrix4x4.Mulv3xM4N(new CtVector3D(1f, 0f, 0f), ctMatrix4x),
                CtMatrix4x4.Mulv3xM4N(new CtVector3D(0f, 1f, 0f), ctMatrix4x),
                CtMatrix4x4.Mulv3xM4N(new CtVector3D(0f, 0f, 1f), ctMatrix4x)
            };
            array[0].Normalize();
            array[1].Normalize();
            array[2].Normalize();
            ctMatrix4x2.SetAxis3(array[0], array[1], array[2]);
            ctMatrix4x2.Transpose();
            CtMatrix4x4 ctMatrix4x3 = new CtMatrix4x4(ctMatrix4x2);

            CtMatrix4x4.Inverse(ctMatrix4x3);
            CtMatrix4x4 leftMatrix  = bone.LeftMatrix;
            CtMatrix4x4 rightMatrix = bone.RightMatrix;

            bone.Bone.TransformMatrix = ctMatrix4x2 * leftMatrix * tm * rightMatrix * ctMatrix4x3;
        }
Beispiel #2
0
 public BoneAssigner(CtBone bone, CtMatrix4x4 leftMatrix, CtMatrix4x4 rightMatrix)
 {
     this.Bone        = bone;
     this.LeftMatrix  = leftMatrix;
     this.RightMatrix = rightMatrix;
     if (this.LeftMatrix == null)
     {
         this.LeftMatrix = CtMatrix4x4.UnitMatrix();
     }
     if (this.RightMatrix == null)
     {
         this.RightMatrix = CtMatrix4x4.UnitMatrix();
     }
     this.ParentBone = null;
 }
Beispiel #3
0
        public static MMDDanceModel LoadMMDModel(CtGraphicsInterface gi, string fileName)
        {
            CtMeshContainer ctMeshContainer = null;
            string          text            = Path.GetExtension(fileName).ToLower();

            if (text.Equals(".ctmm"))
            {
                ctMeshContainer = CtModelFileLoader.LoadCTMM(fileName, gi);
            }
            else if (text.Equals(".pmd") || text.Equals(".pmx"))
            {
                ctMeshContainer = CtModelFileLoader.LoadPMD(fileName, gi);
            }
            Dictionary <string, BoneAssigner> dictionary = new Dictionary <string, BoneAssigner>();
            CtMatrixPallet matrixPallet = ctMeshContainer.MatrixPallet;
            BoneAssigner   boneAssigner = new BoneAssigner(matrixPallet.GetBone("下半身"));
            BoneAssigner   value        = new BoneAssigner(matrixPallet.GetBone("上半身"), boneAssigner);

            dictionary.Add("Hips", new BoneAssigner(matrixPallet.GetBone("センター")));
            dictionary.Add("Chest", boneAssigner);
            dictionary.Add("Chest2", value);
            dictionary.Add("Neck", new BoneAssigner(matrixPallet.GetBone("首")));
            dictionary.Add("Head", new BoneAssigner(matrixPallet.GetBone("頭")));
            double num = CtMath.DegToRad(40.0);

            dictionary.Add("LeftCollar", new BoneAssigner(matrixPallet.GetBone("左肩")));
            dictionary.Add("LeftShoulder", new BoneAssigner(matrixPallet.GetBone("左腕"), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), num), null));
            dictionary.Add("LeftElbow", new BoneAssigner(matrixPallet.GetBone("左ひじ"), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), num), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), -num)));
            dictionary.Add("LeftWrist", new BoneAssigner(matrixPallet.GetBone("左手首"), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), num), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), -num)));
            dictionary.Add("RightCollar", new BoneAssigner(matrixPallet.GetBone("右肩")));
            dictionary.Add("RightShoulder", new BoneAssigner(matrixPallet.GetBone("右腕"), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), -num), null));
            dictionary.Add("RightElbow", new BoneAssigner(matrixPallet.GetBone("右ひじ"), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), -num), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), num)));
            dictionary.Add("RightWrist", new BoneAssigner(matrixPallet.GetBone("右手首"), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), -num), CtMatrix4x4.Rotate(new CtVector3D(0f, 0f, 1f), num)));
            dictionary.Add("LeftHip", new BoneAssigner(matrixPallet.GetBone("左足")));
            dictionary.Add("LeftKnee", new BoneAssigner(matrixPallet.GetBone("左ひざ")));
            dictionary.Add("LeftAnkle", new BoneAssigner(matrixPallet.GetBone("左足首")));
            dictionary.Add("RightHip", new BoneAssigner(matrixPallet.GetBone("右足")));
            dictionary.Add("RightKnee", new BoneAssigner(matrixPallet.GetBone("右ひざ")));
            dictionary.Add("RightAnkle", new BoneAssigner(matrixPallet.GetBone("右足首")));
            return(new MMDDanceModel(ctMeshContainer, dictionary));
        }
Beispiel #4
0
 public BoneAssigner(CtBone bone, BoneAssigner parent) : this(bone, null, null)
 {
     this.ParentBone = parent;
 }