/// <summary>Writes out the UV and vertex colours to the meshes buffers.</summary> public void Paint() { // The UVs: if (ImageUV != null) { ImageUV.Write(ParentMesh.UV.Buffer, VertexIndex); } else { BlankUV.Write(ParentMesh.UV.Buffer, VertexIndex); } if (TextUV != null) { TextUV.Write(ParentMesh.UV2.Buffer, VertexIndex); } else { BlankUV.Write(ParentMesh.UV2.Buffer, VertexIndex); } // Apply the colour: Color[] buffer = ParentMesh.Colours.Buffer; for (int i = 0; i < 4; i++) { buffer[VertexIndex + i] = Colour; } }
/// <summary>Writes out the data to the meshes buffers.</summary> public void Done(Transformation transform) { int vertexIndex = VertexIndex; int triangleIndex = TriangleIndex; Vector3[] verts; Vector3[] normals; int[] triangles; Color[] colours; Vector2[] uv1; Vector2[] uv2; int triOffset; // Get the raw buffers: if (Buffer == null) { // Paint mode. verts = Mesh.Vertices.Buffer; normals = Mesh.Normals.Buffer; triangles = Mesh.Triangles.Buffer; colours = Mesh.Colours.Buffer; uv1 = Mesh.UV.Buffer; uv2 = Mesh.UV2.Buffer; triOffset = 0; } else { // Layout mode. verts = Buffer.Vertices; normals = Buffer.Normals; triangles = Buffer.Triangles; colours = Buffer.Colours; uv1 = Buffer.UV1; uv2 = Buffer.UV2; triOffset = Buffer.Offset + vertexIndex; } // First triangle - Top left corner: triangles[triangleIndex++] = triOffset; // Top right corner: triangles[triangleIndex++] = triOffset + 1; // Bottom left corner: triangles[triangleIndex++] = triOffset + 2; // Second triangle - Top right corner: triangles[triangleIndex++] = triOffset + 1; // Bottom right corner: triangles[triangleIndex++] = triOffset + 3; // Bottom left corner: triangles[triangleIndex++] = triOffset + 2; // Vertices next! if (transform != null) { // Top Left: verts[vertexIndex] = transform.Apply(VertexTopLeft); // Top Right: verts[vertexIndex + 1] = transform.Apply(VertexTopRight); // Bottom Left: verts[vertexIndex + 2] = transform.Apply(VertexBottomLeft); // Bottom Right: verts[vertexIndex + 3] = transform.Apply(VertexBottomRight); if (normals != null) { // Top Left: normals[vertexIndex] = transform.Apply(new Vector3(0f, 0f, -1f)); // Top Right: normals[vertexIndex + 1] = transform.Apply(new Vector3(0f, 0f, -1f)); // Bottom Left: normals[vertexIndex + 2] = transform.Apply(new Vector3(0f, 0f, -1f)); // Bottom Right: normals[vertexIndex + 3] = transform.Apply(new Vector3(0f, 0f, -1f)); } } else { // Top Left: verts[vertexIndex] = VertexTopLeft; // Top Right: verts[vertexIndex + 1] = VertexTopRight; // Bottom Left: verts[vertexIndex + 2] = VertexBottomLeft; // Bottom Right: verts[vertexIndex + 3] = VertexBottomRight; if (normals != null) { // Top Left: normals[vertexIndex] = new Vector3(0f, 0f, -1f); // Top Right: normals[vertexIndex + 1] = new Vector3(0f, 0f, -1f); // Bottom Left: normals[vertexIndex + 2] = new Vector3(0f, 0f, -1f); // Bottom Right: normals[vertexIndex + 3] = new Vector3(0f, 0f, -1f); } } // The UVs: if (ImageUV != null) { ImageUV.Write(uv1, vertexIndex); } else { BlankUV.Write(uv1, vertexIndex); } if (TextUV != null) { TextUV.Write(uv2, vertexIndex); } else { BlankUV.Write(uv2, vertexIndex); } #if LINEAR Color colour = Colour.linear; #else Color colour = Colour; #endif for (int i = 0; i < 4; i++) { colours[vertexIndex + i] = colour; } }