public static odfSubmesh FindMeshObject(ObjectID id, odfMeshSection meshSection) { for (int meshIdx = 0; meshIdx < meshSection.Count; meshIdx++) { odfMesh mesh = meshSection[meshIdx]; for (int submeshIdx = 0; submeshIdx < mesh.Count; submeshIdx++) { odfSubmesh meshObj = mesh[submeshIdx]; if (meshObj.Id == id) { return(meshObj); } } } return(null); }
public static odfMesh FindMeshListSome(String meshName, odfMeshSection meshSection) { if (meshSection == null) { return(null); } for (int meshIdx = 0; meshIdx < meshSection.Count; meshIdx++) { if (meshSection[meshIdx].Name == meshName) { return(meshSection[meshIdx]); } } return(null); }
public static odfMesh FindMeshListSome(ObjectID id, odfMeshSection meshSection) { if (meshSection == null) { return(null); } for (int meshIdx = 0; meshIdx < meshSection.Count; meshIdx++) { if (meshSection[meshIdx].Id == id) { return(meshSection[meshIdx]); } } return(null); }
private bool loadMESH(BinaryReader reader, odfFileSection fileSec) { odfMeshSection meshSection = new odfMeshSection(0); meshSection._FormatType = 10; if (!reader.BaseStream.CanSeek) { byte[] buffer = reader.ReadBytes(fileSec.Size); reader = new BinaryReader(new MemoryStream(buffer)); } for (int endPosition = (int)reader.BaseStream.Position + fileSec.Size; reader.BaseStream.Position < endPosition;) { ObjectName name = new ObjectName(reader.ReadBytes(64)); ObjectID id = new ObjectID(reader.ReadBytes(4)); int numSubmeshes = reader.ReadInt32(); odfMesh mesh = new odfMesh(name, id, numSubmeshes); for (int submeshIdx = 0; submeshIdx < numSubmeshes; submeshIdx++) { name = new ObjectName(reader.ReadBytes(64)); id = new ObjectID(reader.ReadBytes(4)); int unknown1 = reader.ReadInt32(); byte[] alwaysZero1 = reader.ReadBytes(4); ObjectID materialId = new ObjectID(reader.ReadBytes(4)); ObjectID[] texID = new ObjectID[4]; for (int texIdx = 0; texIdx < 4; texIdx++) { texID[texIdx] = new ObjectID(reader.ReadBytes(4)); } UInt32 unknown31 = reader.ReadUInt32(); byte[] alwaysZero2 = reader.ReadBytes(16); int unknown3 = reader.ReadInt32(); byte[] numVertsOrUnknown = reader.ReadBytes(4); byte[] numVertIndicesOrUnknown = reader.ReadBytes(4); int unknown4 = reader.ReadInt32(); int unknown5 = reader.ReadInt32(); byte[] unknownOrNumVerts = reader.ReadBytes(4); byte[] unknownOrNumVertIndices = reader.ReadBytes(4); if (meshSection.Count == 0) { int numVerts = BitConverter.ToInt32(numVertsOrUnknown, 0); int numVertexIdxs = BitConverter.ToInt32(numVertIndicesOrUnknown, 0); if (numVerts * numVertexIdxs == 0) { meshSection._FormatType = 9; } } odfSubmesh submesh = new odfSubmesh(name, id, meshSection._FormatType); submesh.Unknown1 = unknown1; submesh.AlwaysZero1 = alwaysZero1; submesh.MaterialId = materialId; submesh.TextureIds = texID; submesh.Unknown31 = unknown31; submesh.AlwaysZero2 = alwaysZero2; submesh.Unknown4 = unknown3; submesh.Unknown5 = unknown4; submesh.Unknown6 = unknown5; int numVertices, numVertexIndices; if (meshSection._FormatType < 10) { submesh.Unknown7 = BitConverter.ToInt32(numVertsOrUnknown, 0); submesh.Unknown8 = numVertIndicesOrUnknown; numVertices = BitConverter.ToInt32(unknownOrNumVerts, 0); numVertexIndices = BitConverter.ToInt32(unknownOrNumVertIndices, 0); submesh.AlwaysZero3 = reader.ReadBytes(448); } else { numVertices = BitConverter.ToInt32(numVertsOrUnknown, 0); numVertexIndices = BitConverter.ToInt32(numVertIndicesOrUnknown, 0); submesh.Unknown7 = BitConverter.ToInt32(unknownOrNumVerts, 0); submesh.Unknown8 = unknownOrNumVertIndices; } submesh.VertexList = ParseVertexList(reader, numVertices); submesh.FaceList = ParseFaceList(reader, numVertexIndices / 3); submesh.AlwaysZero4 = reader.ReadBytes(24); mesh.AddChild(submesh); } meshSection.AddChild(mesh); } fileSec.Section = meshSection; MeshSection = meshSection; return(true); }
private void CollectObjectIDs(IObjInfo obj) { ObjectID id = null; if (obj is odfMaterial) { id = ((odfMaterial)obj).Id; } else if (obj is odfTexture) { id = ((odfTexture)obj).Id; } else if (obj is odfMesh) { odfMesh mesh = (odfMesh)obj; for (int i = 0; i < mesh.Count; i++) { odfSubmesh submesh = mesh[i]; CollectObjectIDs(submesh); } id = ((odfMesh)obj).Id; } else if (obj is odfSubmesh) { id = ((odfSubmesh)obj).Id; } else if (obj is odfFrame) { odfFrame frame = (odfFrame)obj; for (int i = 0; i < frame.Count; i++) { odfFrame childFrame = frame[i]; CollectObjectIDs(childFrame); } id = frame.Id; } else if (obj is odfMaterialSection) { odfMaterialSection matSec = (odfMaterialSection)obj; foreach (odfMaterial mat in matSec) { CollectObjectIDs(mat); } } else if (obj is odfTextureSection) { odfTextureSection texSec = (odfTextureSection)obj; foreach (odfTexture tex in texSec) { CollectObjectIDs(tex); } } else if (obj is odfMeshSection) { odfMeshSection meshSec = (odfMeshSection)obj; foreach (odfMesh mesh in meshSec) { CollectObjectIDs(mesh); } } else if (obj is odfFrameSection) { odfFrameSection frameSec = (odfFrameSection)obj; foreach (odfFrame frame in frameSec) { CollectObjectIDs(frame); } } else if (obj is odfEnvelopeSection) { odfEnvelopeSection envSec = (odfEnvelopeSection)obj; foreach (odfBoneList boneList in envSec.ChildList) { CollectObjectIDs(boneList); } id = envSec.Id; } else if (obj is odfBoneList) { odfBoneList boneList = (odfBoneList)obj; foreach (odfBone bone in boneList) { CollectObjectIDs(bone); } id = boneList.Id; } else if (obj is odfMorphSection) { id = ((odfMorphSection)obj).Id; } else if (obj is odfTXPTSection) { id = ((odfTXPTSection)obj).Id; } else if (obj is odfMATASection) { id = ((odfMATASection)obj).Id; } else if (obj is odfANIMSection) { id = ((odfANIMSection)obj).Id; } else if (obj is odfBANMSection) { id = ((odfBANMSection)obj).Id; } if (id != null) { int idVal = (int)id; if (idVal != 0) { try { this.UsedIDs.Add(idVal, obj.GetType()); } catch (ArgumentException argEx) { Type typeInDic; this.UsedIDs.TryGetValue(idVal, out typeInDic); Report.ReportLog(obj.GetType() + " ID: " + id + " - " + argEx.Message + " - " + typeInDic); } catch (Exception ex) { Report.ReportLog(obj.GetType() + " ID: " + id + " - " + ex.Message); } } else if (!(obj is odfBoneList)) { Report.ReportLog("Invalid ID used by " + obj.GetType().Name); } } }