public static PmdIK Parse(BinaryReader br, PmdDocument doc) { var rt = new PmdIK { IKBone = doc.GetBone(br.ReadInt16()), TargetBone = doc.GetBone(br.ReadInt16()), }; var bindedBones = br.ReadByte(); rt.LoopCount = br.ReadUInt16(); rt.AngleLimitUnit = br.ReadSingle(); rt.BindedBones = Enumerable.Range(0, bindedBones).Select(_ => doc.GetBone(br.ReadInt16())).ToList(); return rt; }
public static PmdIK Parse(BinaryReader br) { var rt = new PmdIK { IKBone = br.ReadInt16(), TargetBone = br.ReadInt16(), }; var bindedBones = br.ReadByte(); rt.LoopCount = br.ReadUInt16(); rt.AngleLimitUnit = br.ReadSingle(); rt.BindedBones = Enumerable.Range(0, bindedBones).Select(_ => br.ReadInt16()).ToList(); return(rt); }
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); }