/// <summary>Writes the vertices to the meshes buffer. Called during a layout event.</summary> public void Layout() { // Apply the vertices: if (Transform != null) { // Top Left: ParentMesh.Vertices.Buffer[VertexIndex] = Transform.Apply(VertexTopLeft); // Top Right: ParentMesh.Vertices.Buffer[VertexIndex + 1] = Transform.Apply(VertexTopRight); // Bottom Left: ParentMesh.Vertices.Buffer[VertexIndex + 2] = Transform.Apply(VertexBottomLeft); // Bottom Right: ParentMesh.Vertices.Buffer[VertexIndex + 3] = Transform.Apply(VertexBottomRight); } else { // Top Left: ParentMesh.Vertices.Buffer[VertexIndex] = VertexTopLeft; // Top Right: ParentMesh.Vertices.Buffer[VertexIndex + 1] = VertexTopRight; // Bottom Left: ParentMesh.Vertices.Buffer[VertexIndex + 2] = VertexBottomLeft; // Bottom Right: ParentMesh.Vertices.Buffer[VertexIndex + 3] = VertexBottomRight; } }
/// <summary>Calculates where the transformation origin should go in screen space.</summary> /// <param name="relativeTo">The computed style of the element that the origin will be /// relative to if the origin position is 'Relative'</param> private void CalculateOrigin(ComputedStyle relativeTo) { // We need to figure out where the origin is and then apply the parent transformation to it. _Origin = _OriginOffset; if (_OriginOffsetPercX) { _Origin.x *= relativeTo.PixelWidth; } if (_OriginOffsetPercY) { _Origin.y *= relativeTo.PixelHeight; } if (_OriginPosition == PositionType.Relative) { _Origin.x += relativeTo.OffsetLeft; _Origin.y += relativeTo.OffsetTop; } // Map origin to world space: Renderman renderer = relativeTo.Element.Document.Renderer; _Origin = renderer.PixelToWorldUnit(_Origin.x, _Origin.y, relativeTo.ZIndex); if (Parent != null) { _Origin = Parent.Apply(_Origin); } }
/// <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; } }