コード例 #1
0
        public static PmdMorph Parse(BinaryReader br)
        {
            var rt = new PmdMorph
            {
                Name = PmdDocument.ReadPmdString(br, 20),
            };
            var count = br.ReadUInt32();

            rt.Kind = (PmdMorphKind)br.ReadByte();

            for (uint i = 0; i < count; i++)
            {
                rt.Indices.Add((ushort)br.ReadUInt32());
                rt.Offsets.Add(new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() });
            }

            return(rt);
        }
コード例 #2
0
ファイル: PmdMorph.cs プロジェクト: ZeusAFK/Keystone
        public static PmdMorph Parse(BinaryReader br)
        {
            var rt = new PmdMorph
            {
                Name = PmdDocument.ReadPmdString(br, 20),
            };
            var count = br.ReadUInt32();

            rt.Kind = (PmdMorphKind)br.ReadByte();

            for (uint i = 0; i < count; i++)
            {
                rt.Indices.Add((ushort)br.ReadUInt32());
                rt.Offsets.Add(new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() });
            }

            return rt;
        }
コード例 #3
0
ファイル: PmdMorph.cs プロジェクト: mfakane/Keystone
        public static PmdMorph Parse(BinaryReader br, PmdDocument doc, PmdMorph morphBase)
        {
            var rt = new PmdMorph
            {
                Name = PmdDocument.ReadPmdString(br, 20),
            };
            var count = br.ReadUInt32();

            rt.Kind = (PmdMorphKind)br.ReadByte();

            for (uint i = 0; i < count; i++)
            {
                var idx = (ushort)br.ReadUInt32();

                rt.Indices.Add(rt.Kind == PmdMorphKind.None ? doc.Vertices[idx] : morphBase.Indices[idx]);
                rt.Offsets.Add(new[] { br.ReadSingle(), br.ReadSingle(), br.ReadSingle() });
            }

            return rt;
        }
コード例 #4
0
        public static PmdDocument Parse(Stream stream)
        {
            var rt = new PmdDocument();

            // leave open
            var br     = new BinaryReader(stream);
            var header = ReadPmdString(br, 3);

            if (header != "Pmd")
            {
                throw new InvalidOperationException("invalid format");
            }

            rt.Version = br.ReadSingle();

            if (rt.Version >= 2)
            {
                throw new NotSupportedException("specified format version not supported");
            }

            rt.ModelName   = ReadPmdString(br, 20);
            rt.Description = ReadPmdString(br, 256);

            for (var i = br.ReadInt32() - 1; i >= 0; i--)
            {
                rt.Vertices.Add(PmdVertex.Parse(br));
            }

            for (var i = br.ReadInt32() - 1; i >= 0; i--)
            {
                rt.Indices.Add(br.ReadUInt16());
            }

            for (var i = br.ReadInt32() - 1; i >= 0; i--)
            {
                rt.Materials.Add(PmdMaterial.Parse(br));
            }

            var bones = br.ReadUInt16();

            for (ushort i = 0; i < bones; i++)
            {
                rt.Bones.Add(PmdBone.Parse(br));
            }

            for (var i = br.ReadUInt16() - 1; i >= 0; i--)
            {
                rt.IK.Add(PmdIK.Parse(br));
            }

            var morphs = br.ReadUInt16();

            for (ushort i = 0; i < morphs; i++)
            {
                rt.Morphs.Add(PmdMorph.Parse(br));
            }

            for (var i = br.ReadByte() - 1; i >= 0; i--)
            {
                rt.VisibleMorphs.Add(br.ReadUInt16());
            }

            var visibleBoneCategories = br.ReadByte();

            for (byte i = 0; i < visibleBoneCategories; i++)
            {
                rt.VisibleBoneCategories.Add(ReadPmdString(br, 50));
            }

            for (var i = br.ReadInt32() - 1; i >= 0; i--)
            {
                rt.VisibleBones.Add(br.ReadInt16(), br.ReadByte());
            }

            if (br.GetRemainingLength() > 0)
            {
                rt.EnglishCompatible = br.ReadBoolean();

                if (rt.EnglishCompatible)
                {
                    rt.EnglishModelName   = ReadPmdString(br, 20);
                    rt.EnglishDescription = ReadPmdString(br, 256);

                    for (ushort i = 0; i < bones; i++)
                    {
                        rt.EnglishBoneNames.Add(ReadPmdString(br, 20));
                    }

                    for (ushort i = 0; i < morphs - 1; i++)
                    {
                        rt.EnglishMorphNames.Add(ReadPmdString(br, 20));
                    }

                    for (byte i = 0; i < visibleBoneCategories; i++)
                    {
                        rt.EnglishVisibleBoneCategories.Add(ReadPmdString(br, 50));
                    }
                }

                if (br.GetRemainingLength() > 0)
                {
                    rt.ToonFileNames = Enumerable.Range(0, 10).Select(_ => ReadPmdString(br, 100)).ToList();
                }

                if (br.GetRemainingLength() > 0)
                {
                    for (var i = br.ReadInt32() - 1; i >= 0; i--)
                    {
                        rt.Rigids.Add(PmdRigidBody.Parse(br));
                    }

                    for (var i = br.ReadInt32() - 1; i >= 0; i--)
                    {
                        rt.Constraints.Add(PmdConstraint.Parse(br));
                    }
                }
            }

            return(rt);
        }