protected uint U32PerVert(eVertexType type) { switch (type) { case eVertexType.Thin: return(1); case eVertexType.Lit: case eVertexType.Unlit: return(2); case eVertexType.Fat: case eVertexType.Deform: return(3); case eVertexType.FatDeform: return(4); case eVertexType.Raw: default: return(0); } }
public bool Load(ref CDynMemoryReader r, ref CUberData data) { string s0 = r.ReadPascalStr(); if (s0 == "") { return(false); } MaterialName = s0; uint n = 0; if (!r.Get(ref Flags)) { return(false); } if (!r.Get(ref ID)) { return(false); } if (!r.Get(ref MeshID)) { return(false); } if (!r.Get(ref LOD)) { return(false); } // This is a workaround for Marshal.SizeOf not working with enums. Assign to a temporary variable of the correct byte length first. uint vertexTypeTemp = 0; if (!r.Get(ref vertexTypeTemp)) { return(false); } VertexType = (eVertexType)vertexTypeTemp; if (!r.Get(ref BBMin)) { return(false); } if (!r.Get(ref BBMax)) { return(false); } if (!r.Get(ref IndexCount)) { return(false); } var pIndexData = data.ReadMeshData(sizeof(UInt16) * IndexCount); Indices.Capacity = (int)IndexCount; // Convert from byte to short UInt16[] indices = new ushort[pIndexData.Length / 2]; Buffer.BlockCopy(pIndexData, 0, indices, 0, pIndexData.Length); Indices = indices.ToList(); uint d = 0; switch (VertexType) { case eVertexType.Fat: case eVertexType.Lit: case eVertexType.Unlit: case eVertexType.Thin: case eVertexType.Raw: case eVertexType.FatDeform: case eVertexType.Deform: if (!r.Get(ref VertexCount)) { return(false); } LookupOffset = data.GetLookup(VertexCount); n = U32PerVert(VertexType); U32Offset = n != 0 ? data.GetU32(VertexCount * n) : 0; break; default: VertexCount = 0; break; } switch (VertexType) { case eVertexType.Fat: BuildVertices_Fat(ref data); break; case eVertexType.Lit: BuildVerticies_Lit(ref data); break; case eVertexType.Unlit: BuildVertices_Unlit(ref data); break; case eVertexType.Thin: BuildVertices_Thin(ref data); break; case eVertexType.Raw: BuildVertices_Raw(ref data); break; case eVertexType.Deform: BuildVertices_Deform(ref data); break; case eVertexType.FatDeform: // Do nothing? break; } return(true); }