public void Read(BinaryReader reader, float CoordZ, float scale) { RigidBodyName = MMDUtils.GetString(reader.ReadBytes(20)); RelateBoneIndex = BitConverter.ToUInt16(reader.ReadBytes(2), 0); GroupIndex = reader.ReadByte(); GroupTarget = BitConverter.ToUInt16(reader.ReadBytes(2), 0); ShapeType = reader.ReadByte(); ShapeWidth = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; ShapeHeight = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; ShapeDepth = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; Position = new float[3]; for (var i = 0; i < Position.Length; i++) { Position[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; } Rotation = new float[3]; for (var i = 0; i < Rotation.Length; i++) { Rotation[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } Weight = BitConverter.ToSingle(reader.ReadBytes(4), 0); LinerDamping = BitConverter.ToSingle(reader.ReadBytes(4), 0); AngularDamping = BitConverter.ToSingle(reader.ReadBytes(4), 0); Restitution = BitConverter.ToSingle(reader.ReadBytes(4), 0); Friction = BitConverter.ToSingle(reader.ReadBytes(4), 0); Type = reader.ReadByte(); Position[2] *= CoordZ; // 必要らしい Rotation[0] *= CoordZ; Rotation[1] *= CoordZ; }
public MMDModel(Stream fs, float scale) { Vertexes = null; EnglishExpantion = ToonExpantion = PhysicsExpantion = false; ToonFileNames = new List <string>(); Coordinate = CoordinateType.LeftHandedCoordinate; try { var reader = new BinaryReader(fs); Magic = MMDUtils.GetString(reader.ReadBytes(3)); if (Magic != "Pmd") { throw new FileLoadException("MMDモデルファイルではありません"); } Version = BitConverter.ToSingle(reader.ReadBytes(4), 0); if (Version != 1.0) { throw new FileLoadException("version=" + Version + "モデルは対応していません"); } Read(reader, Coordinate, scale); if (fs.Length != fs.Position) { Console.WriteLine("警告:ファイル末尾以降に不明データ?"); } } catch (Exception) { } }
public void Read(BinaryReader reader, float CoordZ, float scale) { Name = MMDUtils.GetString(reader.ReadBytes(20)); RigidBodyA = BitConverter.ToUInt32(reader.ReadBytes(4), 0); RigidBodyB = BitConverter.ToUInt32(reader.ReadBytes(4), 0); Position = new float[3]; for (var i = 0; i < Position.Length; i++) { Position[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; } Rotation = new float[3]; for (var i = 0; i < Rotation.Length; i++) { Rotation[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } ConstrainPosition1 = new float[3]; for (var i = 0; i < ConstrainPosition1.Length; i++) { ConstrainPosition1[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; } ConstrainPosition2 = new float[3]; for (var i = 0; i < ConstrainPosition2.Length; i++) { ConstrainPosition2[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; } ConstrainRotation1 = new float[3]; for (var i = 0; i < ConstrainRotation1.Length; i++) { ConstrainRotation1[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } ConstrainRotation2 = new float[3]; for (var i = 0; i < ConstrainRotation2.Length; i++) { ConstrainRotation2[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } SpringPosition = new float[3]; for (var i = 0; i < SpringPosition.Length; i++) { SpringPosition[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } SpringRotation = new float[3]; for (var i = 0; i < SpringRotation.Length; i++) { SpringRotation[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } // 必要? ConstrainRotation1[0] *= CoordZ; ConstrainRotation1[1] *= CoordZ; ConstrainRotation2[0] *= CoordZ; ConstrainRotation2[1] *= CoordZ; // これは必要 ConstrainPosition1[2] *= CoordZ; ConstrainPosition2[2] *= CoordZ; }
public void Read(BinaryReader reader, float CoordZ, float scale) { SkinName = MMDUtils.GetString(reader.ReadBytes(20)); var skinVertCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0); SkinType = reader.ReadByte(); SkinVertDatas = new ModelSkinVertexData[skinVertCount]; for (var i = 0; i < SkinVertDatas.Length; i++) { SkinVertDatas[i] = new ModelSkinVertexData(reader, CoordZ, scale); } SkinNameEnglish = null; }
public void Read(BinaryReader reader, float CoordZ, float scale) { BoneHeadPos = new float[3]; BoneName = MMDUtils.GetString(reader.ReadBytes(20)); ParentBoneIndex = BitConverter.ToUInt16(reader.ReadBytes(2), 0); TailPosBoneIndex = BitConverter.ToUInt16(reader.ReadBytes(2), 0); BoneType = reader.ReadByte(); IKParentBoneIndex = BitConverter.ToUInt16(reader.ReadBytes(2), 0); for (var i = 0; i < BoneHeadPos.Length; i++) { BoneHeadPos[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0) * scale; } BoneNameEnglish = null; // MMDModel.EnglishExpantionがtrueなら後で設定される // 座標系の調整 BoneHeadPos[2] *= CoordZ; }
public void Read(BinaryReader reader) { DiffuseColor = new float[3]; for (var i = 0; i < DiffuseColor.Length; i++) { DiffuseColor[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } Alpha = BitConverter.ToSingle(reader.ReadBytes(4), 0); Specularity = BitConverter.ToSingle(reader.ReadBytes(4), 0); SpecularColor = new float[3]; for (var i = 0; i < SpecularColor.Length; i++) { SpecularColor[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } AmbientColor = new float[3]; for (var i = 0; i < AmbientColor.Length; i++) { AmbientColor[i] = BitConverter.ToSingle(reader.ReadBytes(4), 0); } ToonIndex = reader.ReadByte(); EdgeFlag = reader.ReadByte(); FaceVertCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0); var FileName = MMDUtils.GetString(reader.ReadBytes(20)); var FileNames = FileName.Split('*'); TextureFileName = SphereTextureFileName = ""; foreach (var s in FileNames) { var ext = Path.GetExtension(s).ToLower(); if (ext == ".sph" || ext == ".spa") { SphereTextureFileName = s.Trim(); } else { TextureFileName = s.Trim(); } } }
public void ReadEnglishExpantion(BinaryReader reader) { SkinNameEnglish = MMDUtils.GetString(reader.ReadBytes(20)); }
public void ReadEnglishExpantion(BinaryReader reader) { ModelNameEnglish = MMDUtils.GetString(reader.ReadBytes(20)); CommentEnglish = MMDUtils.GetString(reader.ReadBytes(256)); }
public void Read(BinaryReader reader) { ModelName = MMDUtils.GetString(reader.ReadBytes(20)); Comment = MMDUtils.GetString(reader.ReadBytes(256)); ModelNameEnglish = CommentEnglish = null; }
public void ReadEnglishExpantion(BinaryReader reader) { BoneDispNameEnglish = MMDUtils.GetString(reader.ReadBytes(50)); }
public void Read(BinaryReader reader) { BoneDispName = MMDUtils.GetString(reader.ReadBytes(50)); BoneDispNameEnglish = null; }
public void Read(BinaryReader reader, CoordinateType coordinate, float scale) { Coordinate = coordinate; // ヘッダ Header = new ModelHeader(reader); // 頂点リスト var numVertex = BitConverter.ToUInt32(reader.ReadBytes(4), 0); Vertexes = new ModelVertex[numVertex]; for (uint i = 0; i < Vertexes.Length; i++) { Vertexes[i] = new ModelVertex(reader, CoordZ, scale); } var faceVertCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0); FaceVertexes = new ushort[faceVertCount]; for (uint i = 0; i < faceVertCount; i++) { FaceVertexes[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0); } var materialCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0); Materials = new ModelMaterial[materialCount]; for (uint i = 0; i < materialCount; i++) { Materials[i] = new ModelMaterial(reader); } var boneCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0); Bones = new ModelBone[boneCount]; for (ushort i = 0; i < boneCount; i++) { Bones[i] = new ModelBone(reader, CoordZ, scale); } var IKCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0); IKs = new ModelIK[IKCount]; for (ushort i = 0; i < IKs.Length; i++) { IKs[i] = new ModelIK(reader); } var skinCount = BitConverter.ToUInt16(reader.ReadBytes(2), 0); Skins = new ModelSkin[skinCount]; for (ushort i = 0; i < skinCount; i++) { Skins[i] = new ModelSkin(reader, CoordZ, scale); } var skinDispCount = reader.ReadByte(); SkinIndex = new ushort[skinDispCount]; for (byte i = 0; i < skinDispCount; i++) { SkinIndex[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0); } var boneDispNameCount = reader.ReadByte(); BoneDispName = new ModelBoneDispName[boneDispNameCount]; for (byte i = 0; i < boneDispNameCount; i++) { BoneDispName[i] = new ModelBoneDispName(reader); } var boneDispCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0); BoneDisp = new ModelBoneDisp[boneDispCount]; for (uint i = 0; i < boneDispCount; i++) { BoneDisp[i] = new ModelBoneDisp(reader); } EnglishExpantion = reader.ReadByte() != 0; if (EnglishExpantion) { Header.ReadEnglishExpantion(reader); for (var i = 0; i < Bones.Length; i++) { Bones[i].ReadEnglishExpantion(reader); } for (var i = 0; i < Skins.Length; i++) { // base のスキンには英名はない if (Skins[i].SkinType != 0) { Skins[i].ReadEnglishExpantion(reader); } } for (var i = 0; i < BoneDispName.Length; i++) { BoneDispName[i].ReadEnglishExpantion(reader); } } if (reader.BaseStream.Position >= reader.BaseStream.Length) { ToonExpantion = false; } else { ToonExpantion = true; ToonFileNames.Clear(); for (var i = 0; i < NumToonFileName; i++) { ToonFileNames.Add(MMDUtils.GetString(reader.ReadBytes(100))); } } if (reader.BaseStream.Position >= reader.BaseStream.Length) { PhysicsExpantion = false; } else { PhysicsExpantion = true; // 剛体リスト var rigidbodyCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0); RigidBodies = new ModelRigidBody[rigidbodyCount]; for (var i = 0; i < RigidBodies.Length; i++) { RigidBodies[i] = new ModelRigidBody(reader, CoordZ, scale); } var jointCount = BitConverter.ToUInt32(reader.ReadBytes(4), 0); Joints = new ModelJoint[jointCount]; for (var i = 0; i < Joints.Length; i++) { Joints[i] = new ModelJoint(reader, CoordZ, scale); } } }