コード例 #1
0
ファイル: PmdReader.cs プロジェクト: Romulion/GameEngine
        void ReadMorhps(Reader reader)
        {
            int morphCount = reader.ReadUInt16();

            morphs = new MorphVertex[morphCount];

            for (int i = 0; i < morphCount; i++)
            {
                var name      = reader.readStringLength(20);
                var vertCount = reader.ReadInt32();
                var category  = reader.ReadByte();
                var morph     = new MorphVertex(name, "", vertCount, meshRigged.GetMorpher);
                for (int n = 0; n < vertCount; n++)
                {
                    var index = reader.ReadInt32();
                    var pos   = reader.readVector3() * multipler;
                    pos.Z = -pos.Z;
                    morph.AddVertex(pos, index);
                }
                morphs[i] = morph;
            }

            MorphVertex baseMorph = morphs[0];

            //local to global index
            for (int i = 1; i < morphs.Length; i++)
            {
                for (int n = 0; n < morphs[i].morph.Length; n++)
                {
                    morphs[i].morph[n].W = baseMorph.morph[(int)morphs[i].morph[n].W].W;
                }
            }
        }
コード例 #2
0
ファイル: PmxReader.cs プロジェクト: Romulion/GameEngine
        void ReadMorhps(Reader reader)
        {
            int morphCount = reader.ReadInt32();

            morphs = new Morph[morphCount];

            for (int i = 0; i < morphCount; i++)
            {
                string name    = reader.readString();
                string nameEng = reader.readString();
                int    panel   = reader.ReadByte();
                int    type    = reader.ReadByte();
                int    size    = reader.ReadInt32();

                if (type == (int)MorphType.Vertex)
                {
                    morphs[i] = new MorphVertex(name, nameEng, size, meshRigged.GetMorpher);
                }
                else if (type == (int)MorphType.Material)
                {
                    morphs[i] = new MorphMaterial(name, nameEng, size);
                }
                else if (type == (int)MorphType.Uv)
                {
                    morphs[i] = new MorphUV(name, nameEng, size, meshRigged.GetMorpher);
                }
                else if (type == (int)MorphType.Bone)
                {
                    morphs[i] = new MorphSkeleton(name, nameEng, size, boneController);
                }
                else if (type == (int)MorphType.Group)
                {
                    morphs[i] = new MorphGroup(name, nameEng, size, morphs);
                }


                for (int n = 0; n < size; n++)
                {
                    switch (type)
                    {
                    case 0:                             //group
                        var gId  = reader.readVal(header.GetMorphIndexSize);
                        var gval = reader.ReadSingle();
                        ((MorphGroup)morphs[i]).AddMorph(gId, gval);
                        break;

                    case 1:                             //vertex
                        int     index = reader.readVal(header.GetVertexIndexSize);
                        Vector3 pos   = reader.readVector3() * multipler;
                        pos.Z = -pos.Z;
                        ((MorphVertex)morphs[i]).AddVertex(pos, index);
                        break;

                    case 2:                              //bone morph
                        var id   = reader.readVal(header.GetBoneIndexSize);
                        var posB = reader.readVector3();
                        posB.Z = -posB.Z;
                        var rotB = reader.readVector4();
                        ((MorphSkeleton)morphs[i]).AddBone(id, posB, new Quaternion(rotB.X, rotB.Y, -rotB.Z, -rotB.W));
                        break;

                    case 3:                              //uv
                        int vIndex = reader.readVal(header.GetVertexIndexSize);
                        var value  = reader.readVector4();
                        ((MorphUV)morphs[i]).AddVertex(new Vector2(value.X, value.Y), vIndex);
                        break;

                    case 8:                             //material

                        int      idx = reader.readVal(header.GetMaterialIndexSize);
                        Material mat = null;
                        if (idx >= 0 && idx < mats.Length)
                        {
                            mat = mats[idx];
                        }

                        var MMorpher = new MaterialMorpher(mat);
                        MMorpher.mode          = reader.ReadByte();
                        MMorpher.DiffuseColor  = reader.readVector4();
                        MMorpher.SpecularColor = reader.readVector3();
                        reader.ReadSingle();
                        MMorpher.AmbientColor = reader.readVector3();
                        reader.readVector4();
                        reader.ReadSingle();
                        reader.readVector4();
                        reader.readVector4();
                        reader.readVector4();
                        ((MorphMaterial)morphs[i]).MaterialMorphers.Add(MMorpher);

                        break;

                    case 9:                             //flip
                        reader.readVal(header.GetMaterialIndexSize);
                        reader.ReadSingle();
                        break;

                    case 10:                             //impulse
                        reader.readVal(header.GetRigidBodyIndexSize);
                        reader.ReadByte();
                        reader.readVector3();
                        reader.readVector3();
                        break;

                    default:
                        Console.WriteLine(type);
                        break;
                    }
                }
            }
        }