public static void Read(BinaryReader reader, CoordinateType coordinate) { _coordinate = coordinate; _header = new ModelHeader(); _header.Read(reader); //Read Vertices UInt32 num_vertex = BitConverter.ToUInt32(reader.ReadBytes(4), 0); _vertices = new ModelVertex[num_vertex]; for (UInt32 i = 0; i < num_vertex; i++) { _vertices[i] = new ModelVertex(); _vertices[i].Read(reader, CoordZ); } //Read Primitives UInt32 face_vert_count = BitConverter.ToUInt32(reader.ReadBytes(4), 0); _faceIndices = new UInt16[face_vert_count]; for (UInt32 i = 0; i < face_vert_count; i++) _faceIndices[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0); //Read Materials UInt32 material_count = BitConverter.ToUInt32(reader.ReadBytes(4), 0); _materials = new ModelMaterial[material_count]; for (UInt32 i = 0; i < material_count; i++) { _materials[i] = new ModelMaterial(); _materials[i].Read(reader); } //Read Bones UInt16 bone_count = BitConverter.ToUInt16(reader.ReadBytes(2), 0); _bones = new ModelBone[bone_count]; for (UInt16 i = 0; i < bone_count; i++) { _bones[i] = new ModelBone(); _bones[i].Read(reader, CoordZ); } //Read IK Bones UInt16 ik_count = BitConverter.ToUInt16(reader.ReadBytes(2), 0); _IKs = new ModelIK[ik_count]; for (UInt16 i = 0; i < ik_count; i++) { _IKs[i] = new ModelIK(); _IKs[i].Read(reader); } //Read Face Morphs UInt16 skin_count = BitConverter.ToUInt16(reader.ReadBytes(2), 0); _skins = new ModelSkin[skin_count]; for (UInt16 i = 0; i < skin_count; i++) { _skins[i] = new ModelSkin(); _skins[i].Read(reader, CoordZ); } //Read face morph indices byte skin_disp_count = reader.ReadByte(); _skinIndex = new UInt16[skin_disp_count]; for (byte i = 0; i < _skinIndex.Length; i++) _skinIndex[i] = BitConverter.ToUInt16(reader.ReadBytes(2), 0); //Read bone morph names byte bone_disp_name_count = reader.ReadByte(); _boneDispNames = new ModelBoneDispName[bone_disp_name_count]; for (byte i = 0; i < _boneDispNames.Length; i++) { _boneDispNames[i] = new ModelBoneDispName(); _boneDispNames[i].Read(reader); } //Read bone morphs UInt32 bone_disp_count = BitConverter.ToUInt32(reader.ReadBytes(4), 0); _boneDisps = new ModelBoneDisp[bone_disp_count]; for (UInt32 i = 0; i < _boneDisps.Length; i++) { _boneDisps[i] = new ModelBoneDisp(); _boneDisps[i].Read(reader); } //Read English strings, if there are any. try { _expansion = (reader.ReadByte() != 0); if (_expansion) { _header.ReadExpansion(reader); for (UInt16 i = 0; i < bone_count; i++) { _bones[i].ReadExpansion(reader); } for (UInt16 i = 0; i < skin_count; i++) { if (_skins[i]._skinType != 0) _skins[i].ReadExpansion(reader); } for (byte i = 0; i < _boneDispNames.Length; i++) { _boneDispNames[i].ReadExpansion(reader); } if (reader.BaseStream.Position >= reader.BaseStream.Length) _toonExpansion = false; else { _toonExpansion = true; _toonFileNames = new string[_numToonFileName]; for (int i = 0; i < _toonFileNames.Length; i++) { _toonFileNames[i] = GetString(reader.ReadBytes(100)); } } if (reader.BaseStream.Position >= reader.BaseStream.Length) _physicsExpansion = false; else { _physicsExpansion = true; UInt32 rididbody_count = BitConverter.ToUInt32(reader.ReadBytes(4), 0); _rigidBodies = new ModelRigidBody[rididbody_count]; for (UInt32 i = 0; i < rididbody_count; i++) { _rigidBodies[i] = new ModelRigidBody(); _rigidBodies[i].ReadExpansion(reader, CoordZ); } UInt32 joint_count = BitConverter.ToUInt32(reader.ReadBytes(4), 0); _joints = new ModelJoint[joint_count]; for (UInt32 i = 0; i < joint_count; i++) { _joints[i] = new ModelJoint(); _joints[i].ReadExpansion(reader, CoordZ); } } } } catch { Console.WriteLine("This file does not contain English strings."); } }
public static unsafe void MDL02PMD(MDL0Node model) { _header = new ModelHeader(); _header._modelName = model.Name; //To do: Add the ability to change the comment _header._comment = "MDL0 model converted to PMD by Brawlbox."; foreach (MDL0MaterialNode m in model._matList) { ModelMaterial mat = new ModelMaterial(); mat._textureFileName = m.Children[0].Name; } _bones = new ModelBone[model._linker.BoneCache.Length]; for (int i = 0; i < model._linker.BoneCache.Length; i++) { ModelBone bone = new ModelBone(); MDL0BoneNode mBone = (MDL0BoneNode)model._linker.BoneCache[i]; Vector3 wPos = mBone._bindMatrix.GetPoint(); bone._wPos[0] = wPos._x; bone._wPos[1] = wPos._y; bone._wPos[2] = wPos._z; bone._boneName = mBone.Name; bone._boneType = 0; bone._parentBoneIndex = (ushort)model._linker.BoneCache.ToList<ResourceNode>().IndexOf(mBone.Parent); _bones[i] = bone; } }