Exemplo n.º 1
0
        public void SetPose(DancePose pose)
        {
            if (pose.FootState == DancePoseFootState.Auto)
            {
                CtMatrix4x4[] transformedMatrices = this.Mesh.MatrixPallet.TransformedMatrices;
                uint          matrixIndex         = this.BoneTable["LeftAnkle"].Bone.MatrixIndex;
                uint          matrixIndex2        = this.BoneTable["RightAnkle"].Bone.MatrixIndex;
                CtVector3D    position            = transformedMatrices[(int)((UIntPtr)matrixIndex)].GetPosition();
                CtVector3D    position2           = transformedMatrices[(int)((UIntPtr)matrixIndex2)].GetPosition();
                bool          flag = position.Y < position2.Y;
                CtVector3D    a    = flag ? position : position2;
                a.Y = this.AnkleHeight;
                this.SetPoseWithoutPivoting(pose);
                this.Mesh.UpdateBoneMatrices();
                CtVector3D position3 = (flag ? transformedMatrices[(int)((UIntPtr)matrixIndex)] : transformedMatrices[(int)((UIntPtr)matrixIndex2)]).GetPosition();
                CtBone     bone      = this.BoneTable["Hips"].Bone;
                bone.TransformMatrix = CtMatrix4x4.MulM4xM4(bone.TransformMatrix, CtMatrix4x4.Translate(a - position3));
                this.Mesh.UpdateBoneMatrices();
                return;
            }
            this.SetPoseWithoutPivoting(pose);
            CtBone     bone2     = this.Mesh.MatrixPallet.GetBone(MMDDanceModel.mmdBoneNameOfROOT);
            CtBone     bone3     = this.Mesh.MatrixPallet.GetBone(MMDDanceModel.mmdBoneNameOfLOWERBODY);
            float      f         = -bone3.OffsetMatrix.GetPosition().Y;
            CtVector3D position4 = bone2.TransformedMatrix.GetPosition();
            CtVector3D position5 = bone3.TransformedMatrix.GetPosition();
            CtVector3D b         = position4 - position5 + bone2.OffsetMatrix.GetPosition();

            bone2.TransformMatrix.TranslateFromRight(f * pose.BodyPosition + b);
            this.Mesh.UpdateBoneMatrices();
        }
Exemplo n.º 2
0
 public BvhNode(string name, CtVector3D offset, BvhChannels[] channels, BvhNode[] nodes)
 {
     this.Name     = name;
     this.Offset   = offset;
     this.Channels = channels;
     this.Nodes    = nodes;
 }
Exemplo n.º 3
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;
        }
Exemplo n.º 4
0
            protected override DanceMotion ReadTarget(BinaryReader reader, IReadingSession session)
            {
                string         name        = reader.ReadMoostaString();
                int            beatCount   = reader.ReadInt32();
                int            num         = reader.ReadInt32();
                DanceModelInfo sourceModel = (num == 0) ? null : (session.GetObject(num) as DanceModelInfo);

                string[] array = new string[reader.ReadInt32()];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = reader.ReadMoostaString();
                }
                string[] array2 = new string[reader.ReadInt32()];
                for (int j = 0; j < array2.Length; j++)
                {
                    array2[j] = reader.ReadMoostaString();
                }
                string[] array3 = new string[reader.ReadInt32()];
                for (int k = 0; k < array3.Length; k++)
                {
                    array3[k] = reader.ReadMoostaString();
                }
                DancePose[] array4 = new DancePose[reader.ReadInt32()];
                for (int l = 0; l < array4.Length; l++)
                {
                    CtVector3D         bodyPos   = new CtVector3D(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                    DancePoseFootState footState = (DancePoseFootState)reader.ReadInt32();
                    BoneState[]        array5    = new BoneState[array2.Length];
                    for (int m = 0; m < array2.Length; m++)
                    {
                        array5[m] = new BoneState(new CtQuaternion(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()));
                    }
                    SkinState[] array6 = new SkinState[array3.Length];
                    for (int n = 0; n < array3.Length; n++)
                    {
                        array6[n] = new SkinState(reader.ReadSingle());
                    }
                    array4[l] = new DancePose(array2, array5, array3, array6, bodyPos)
                    {
                        FootState = footState
                    };
                }
                return(new DanceMotion(name, beatCount, array4, sourceModel)
                {
                    Tags = array
                });
            }
Exemplo n.º 5
0
        private static BvhNode ReadNode(string name, TextReader reader)
        {
            CtVector3D         zero  = CtVector3D.Zero;
            List <BvhChannels> list  = new List <BvhChannels>();
            List <BvhNode>     list2 = new List <BvhNode>();

            if (reader.ReadLine().Trim() != "{")
            {
                throw new Exception();
            }
            while (true)
            {
                string[] array = reader.ReadLine().Trim().Split(new char[]
                {
                    ' ',
                    '\t'
                }, StringSplitOptions.RemoveEmptyEntries);
                if (array[0] == "}")
                {
                    break;
                }
                if (array[0] == "OFFSET")
                {
                    zero = new CtVector3D(float.Parse(array[1]), float.Parse(array[2]), float.Parse(array[3]));
                }
                else if (array[0] == "CHANNELS")
                {
                    for (int i = 2; i < array.Length; i++)
                    {
                        list.Add((BvhChannels)Enum.Parse(typeof(BvhChannels), array[i]));
                    }
                }
                else if (array[0] == "JOINT" || array[0] == "End")
                {
                    list2.Add(BvhFormat.ReadNode(array[1], reader));
                }
            }
            return(new BvhNode(name, zero, list.ToArray(), list2.ToArray()));
        }
Exemplo n.º 6
0
 public CtVector3D RotateVectorByBone(CtVector3D dir, string boneName)
 {
     return(dir);
 }
Exemplo n.º 7
0
        public void ReadObj(TextReader objTr, string directory, CtGraphicsInterface gi)
        {
            this.materials.Clear();
            List <CtVector3D> list  = new List <CtVector3D>();
            List <CtVector3D> list2 = new List <CtVector3D>();
            List <CtVector2D> list3 = new List <CtVector2D>();
            string            text  = "";
            float             f     = 0.1f;
            CtVector3D        b     = new CtVector3D(0f, 0f, -16f);
            string            path  = Path.Combine(directory, "setting.txt");

            this.stageBgList.Clear();
            try
            {
                using (StreamReader streamReader = new StreamReader(path))
                {
                    while (streamReader.Peek() > -1)
                    {
                        try
                        {
                            string text2 = streamReader.ReadLine();
                            if (text2.Length <= 0 || text2[0] != '#')
                            {
                                string[] array = text2.Split(new char[]
                                {
                                    ':'
                                });
                                if (array[0].Equals("Scale") && array.Length == 2)
                                {
                                    f = float.Parse(array[1]);
                                }
                                else if (array[0].Equals("Diff") && array.Length == 2)
                                {
                                    string[] array2 = array[1].Split(new char[]
                                    {
                                        ','
                                    });
                                    if (array2.Length == 3)
                                    {
                                        b.X = float.Parse(array2[0]);
                                        b.Y = float.Parse(array2[1]);
                                        b.Z = float.Parse(array2[2]);
                                    }
                                }
                                else if (array[0].Equals("Lighting") && array.Length == 2)
                                {
                                    base.LightingModeName = array[1];
                                }
                                else if (array[0].Equals("BackGroundImage") && array.Length == 3)
                                {
                                    StageBackGround stageBackGround = new StageBackGround();
                                    stageBackGround.TranslateScale = float.Parse(array[1]);
                                    stageBackGround.FileName       = array[2];
                                    string fileName = Path.Combine(Path.GetDirectoryName(this.ObjFileName), stageBackGround.FileName);
                                    stageBackGround.BackGroundTextureIDNumber = CtTextureManager.CreateTexture(gi, fileName);
                                    CtTexture texture = CtTextureManager.GetTexture(stageBackGround.BackGroundTextureIDNumber);
                                    if (texture != null)
                                    {
                                        texture.DeleteBitmapResource();
                                    }
                                    this.stageBgList.Add(stageBackGround);
                                }
                                else if (array[0].Equals("DropObjectImage") && array.Length == 4)
                                {
                                    this.dropObject             = new StageDropObject();
                                    this.dropObject.ObjectCount = int.Parse(array[1]);
                                    this.dropObject.ObjectSize  = float.Parse(array[2]);
                                    this.dropObject.FileName    = array[3];
                                    string fileName2 = Path.Combine(Path.GetDirectoryName(this.ObjFileName), this.dropObject.FileName);
                                    this.dropObject.ObjectTextureIndex = CtTextureManager.CreateTexture(gi, fileName2);
                                    CtTexture texture2 = CtTextureManager.GetTexture(this.dropObject.ObjectTextureIndex);
                                    if (texture2 != null)
                                    {
                                        texture2.DeleteBitmapResource();
                                    }
                                }
                                else if (array[0].Equals("DropObjectSpeedRange") && array.Length == 7)
                                {
                                    if (this.dropObject != null)
                                    {
                                        CtVector3D minSpeedRange = default(CtVector3D);
                                        CtVector3D maxSpeedRange = default(CtVector3D);
                                        minSpeedRange.X = float.Parse(array[1]);
                                        maxSpeedRange.X = float.Parse(array[2]);
                                        minSpeedRange.Y = float.Parse(array[3]);
                                        maxSpeedRange.Y = float.Parse(array[4]);
                                        minSpeedRange.Z = float.Parse(array[5]);
                                        maxSpeedRange.Z = float.Parse(array[6]);
                                        this.dropObject.MinSpeedRange = minSpeedRange;
                                        this.dropObject.MaxSpeedRange = maxSpeedRange;
                                    }
                                }
                                else if (array[0].Equals("DropObjectSpace") && array.Length == 5 && this.dropObject != null)
                                {
                                    this.dropObject.ObjectFieldScale   = float.Parse(array[1]);
                                    this.dropObject.ObjectCreateHeight = float.Parse(array[2]);
                                    this.dropObject.ObjectDeleteHeight = float.Parse(array[3]);
                                    this.dropObject.ObjectGroundHeight = float.Parse(array[4]);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }
            catch
            {
            }
            CtMaterial material = null;

            StageModelFromOBJ.MsRenderMesh msRenderMesh = null;
            while (objTr.Peek() > -1)
            {
                string text3 = objTr.ReadLine().Trim();
                if (!string.IsNullOrEmpty(text3))
                {
                    try
                    {
                        if (text3[0] != '#')
                        {
                            string[] array3 = text3.Split(new char[]
                            {
                                ' '
                            });
                            if (array3[0].Equals("v"))
                            {
                                CtVector3D ctVector3D = new CtVector3D(float.Parse(array3[1]), float.Parse(array3[2]), float.Parse(array3[3]));
                                ctVector3D *= f;
                                ctVector3D += b;
                                list.Add(ctVector3D);
                            }
                            else if (array3[0].Equals("vt"))
                            {
                                CtVector2D item = new CtVector2D(float.Parse(array3[1]), float.Parse(array3[2]));
                                list3.Add(item);
                            }
                            else if (array3[0].Equals("vn"))
                            {
                                CtVector3D item2 = new CtVector3D(float.Parse(array3[1]), float.Parse(array3[2]), float.Parse(array3[3]));
                                list2.Add(item2);
                            }
                            else if (array3[0].Equals("f"))
                            {
                                StageModelFromOBJ.MsFace msFace = new StageModelFromOBJ.MsFace(array3.Length - 1, material);
                                for (int i = 1; i < array3.Length; i++)
                                {
                                    string[] array4 = array3[i].Split(new char[]
                                    {
                                        '/'
                                    });
                                    if (array4.Length == 3)
                                    {
                                        msFace.Position[i - 1] = list[int.Parse(array4[0]) - 1];
                                        msFace.UV[i - 1]       = list3[int.Parse(array4[1]) - 1];
                                        msFace.Normal[i - 1]   = list2[int.Parse(array4[2]) - 1];
                                    }
                                    else
                                    {
                                        int arg_5C9_0 = array4.Length;
                                    }
                                }
                                if (msFace.Position.Length == 3)
                                {
                                    msRenderMesh.renderPosition.Add(msFace.Position[0]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[0]);
                                    msRenderMesh.renderUV.Add(msFace.UV[0]);
                                    msRenderMesh.renderPosition.Add(msFace.Position[2]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[2]);
                                    msRenderMesh.renderUV.Add(msFace.UV[2]);
                                    msRenderMesh.renderPosition.Add(msFace.Position[1]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[1]);
                                    msRenderMesh.renderUV.Add(msFace.UV[1]);
                                }
                                else if (msFace.Position.Length == 4)
                                {
                                    msRenderMesh.renderPosition.Add(msFace.Position[0]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[0]);
                                    msRenderMesh.renderUV.Add(msFace.UV[0]);
                                    msRenderMesh.renderPosition.Add(msFace.Position[2]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[2]);
                                    msRenderMesh.renderUV.Add(msFace.UV[2]);
                                    msRenderMesh.renderPosition.Add(msFace.Position[1]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[1]);
                                    msRenderMesh.renderUV.Add(msFace.UV[1]);
                                    msRenderMesh.renderPosition.Add(msFace.Position[3]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[3]);
                                    msRenderMesh.renderUV.Add(msFace.UV[3]);
                                    msRenderMesh.renderPosition.Add(msFace.Position[2]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[2]);
                                    msRenderMesh.renderUV.Add(msFace.UV[2]);
                                    msRenderMesh.renderPosition.Add(msFace.Position[0]);
                                    msRenderMesh.renderNormal.Add(msFace.Normal[0]);
                                    msRenderMesh.renderUV.Add(msFace.UV[0]);
                                }
                            }
                            else if (array3[0].Equals("usemtl"))
                            {
                                CtMaterial ctMaterial;
                                if (!this.materials.TryGetValue(array3[1], out ctMaterial))
                                {
                                    ctMaterial      = new CtMaterial();
                                    ctMaterial.Name = array3[1];
                                    this.materials.Add(ctMaterial.Name, ctMaterial);
                                    ctMaterial.TextureIdNumber = -1;
                                }
                                material = ctMaterial;
                                StageModelFromOBJ.MsRenderMesh msRenderMesh2 = null;
                                if (!this.renderMeshes.TryGetValue(array3[1], out msRenderMesh2))
                                {
                                    msRenderMesh2 = new StageModelFromOBJ.MsRenderMesh();
                                    this.renderMeshes.Add(ctMaterial.Name, msRenderMesh2);
                                }
                                msRenderMesh          = msRenderMesh2;
                                msRenderMesh.material = material;
                            }
                            else if (array3[0].Equals("mtllib"))
                            {
                                text = array3[1];
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            if (File.Exists(directory + "\\" + text) && !string.IsNullOrEmpty(text))
            {
                using (StreamReader streamReader2 = new StreamReader(directory + "\\" + text, Encoding.GetEncoding("Shift_JIS")))
                {
                    this.readMaterial(streamReader2);
                }
            }
        }