/// <summary> /// Creates a new Buffermesh with only polygon data /// </summary> /// <param name="corners">Triangle corner data</param> /// <param name="triangleList">Triangle index list</param> /// <param name="material">Material</param> public BufferMesh(BufferCorner[] corners, uint[] triangleList, BufferMaterial material, ushort vertexReadOffset = 0) { Corners = corners == null || corners.Length == 0 ? throw new ArgumentNullException(nameof(corners), "Corners can't be null or empty") : corners; TriangleList = triangleList != null && triangleList.Length == 0 ? throw new ArgumentNullException(nameof(triangleList), "Triangle list cant be empty") : triangleList; Material = material ?? throw new ArgumentNullException(nameof(material), "Material can't be null"); VertexReadOffset = vertexReadOffset; }
/// <summary> /// Reads a buffer mesh from a byte array /// </summary> /// <param name="source">Byte source</param> /// <param name="address">Address at which the buffermesh is located</param> public static BufferMesh Read(byte[] source, uint address, uint imageBase) { BufferVertex[] vertices = new BufferVertex[source.ToUInt16(address)]; bool continueWeight = source.ToUInt16(address + 2) != 0; BufferCorner[] corners = new BufferCorner[source.ToUInt32(address + 4)]; uint[] triangles = new uint[source.ToUInt32(address + 8)]; address += 12; BufferMaterial material = BufferMaterial.Read(source, ref address); uint tmpAddr = source.ToUInt32(address) - imageBase; for (int i = 0; i < vertices.Length; i++) { vertices[i] = BufferVertex.Read(source, ref tmpAddr); } tmpAddr = source.ToUInt32(address += 4) - imageBase; for (int i = 0; i < corners.Length; i++) { corners[i] = BufferCorner.Read(source, ref tmpAddr); } tmpAddr = source.ToUInt32(address += 4) - imageBase; for (int i = 0; i < triangles.Length; i++) { triangles[i] = source.ToUInt32(tmpAddr); tmpAddr += 4; } if (vertices.Length == 0) { return(new BufferMesh(corners, triangles, material)); } else if (corners.Length == 0) { return(new BufferMesh(vertices, continueWeight)); } else { return(new BufferMesh(vertices, continueWeight, corners, triangles, material)); } }