MeshExtensions

ceramic.MeshExtensions (Class)

Static extension class providing utility methods for Mesh manipulation.

This class contains helper methods for common mesh operations such as:

  • Creating quad geometry
  • Setting dark colors for special shaders
  • Creating arc/ring/pie geometry
  • Creating grid-based meshes

These methods are available on any Mesh instance through Haxe's static extension feature.

using ceramic.MeshExtensions;

var mesh = new Mesh();
mesh.createQuad(100, 100); // Creates a 100x100 quad
mesh.createArc(50, 180, 10, 32, INSIDE); // Creates a semi-circle arc
See: Mesh The base mesh class these extensions apply to, MeshUtils For lower-level mesh manipulation utilities

Static Members

createQuad(mesh: Mesh, width: Float, height: Float, ?floatsPerVertex: Int = -1): Void

Generates vertices, indices and uvs to form a rectangular quad.

Creates a quad with 4 vertices arranged as:

0 -- 1
|    |
3 -- 2

The quad is positioned with its top-left corner at (0,0). UV coordinates are mapped from 0 to 1 across the quad.

Name Type Default Description
mesh Mesh The mesh to configure as a quad
width Float Width of the quad in pixels
height Float Height of the quad in pixels
floatsPerVertex Int -1 Number of floats per vertex in the vertex buffer. - 2: Standard quad (x, y) - 6: Quad with dark color support (x, y, r, g, b, a) - -1: Auto-detect from mesh.customFloatAttributesSize Must be at least 2. * haxe var mesh = new Mesh(); mesh.createQuad(200, 150); // Creates a 200x150 quad mesh.texture = myTexture; // Apply texture

setDarkColor(mesh: Mesh, darkColor: Color): Void

Assigns a dark color to all vertices in the mesh.

This method is used with special shaders that support a secondary "dark" color for advanced rendering effects. The dark color is stored in vertex attributes positions 2-5 (r, g, b, a) of each vertex.

Requirements:

  • Mesh must have 6 floats per vertex
  • Vertex layout: [x, y, darkR, darkG, darkB, darkA]
Name Type Description
mesh Mesh The mesh to modify. Must have 6 floats per vertex.
darkColor Color The dark color to apply to all vertices. Alpha is automatically set to 1.0. * haxe var mesh = new Mesh(); mesh.createQuad(100, 100, 6); // 6 floats per vertex mesh.setDarkColor(Color.PURPLE); // Set dark color mesh.shader = myDarkColorShader; // Use compatible shader

setDarkAlphaColor(mesh: Mesh, darkAlphaColor: AlphaColor): Void

Assigns a dark color with alpha to all vertices in the mesh.

Similar to setDarkColor but preserves the alpha channel from the provided color. Used with special shaders that support transparent dark colors for effects like shadows or overlays.

Requirements:

  • Mesh must have 6 floats per vertex
  • Vertex layout: [x, y, darkR, darkG, darkB, darkA]
Name Type Description
mesh Mesh The mesh to modify. Must have 6 floats per vertex.
darkAlphaColor AlphaColor The dark color with alpha to apply to all vertices. * haxe var mesh = new Mesh(); mesh.createQuad(100, 100, 6); // 6 floats per vertex var shadowColor = AlphaColor.fromRGBA(0, 0, 0, 128); // 50% black mesh.setDarkAlphaColor(shadowColor);

createArc(mesh: Mesh, radius: Float, angle: Float, thickness: Float, sides: Int, borderPosition: Anonymous): Void

Generates vertices and indices to create arc, pie, ring or disc geometry.

This versatile method can create various circular shapes:

  • Arc: Partial circle outline (angle < 360, thickness < radius)
  • Ring: Full circle outline (angle = 360, thickness < radius)
  • Pie: Filled partial circle (angle < 360, thickness = radius, borderPosition = INSIDE)
  • Disc: Filled full circle (angle = 360, thickness = radius, borderPosition = INSIDE)

The shape is centered at (radius, radius) to ensure all vertices are positive.

Name Type Description
mesh Mesh The mesh to configure with arc geometry
radius Float Outer radius of the arc in pixels
angle Float Arc angle in degrees (0-360). 360 creates a full circle.
thickness Float Width of the arc stroke. Set equal to radius with INSIDE position for filled shapes.
sides Int Number of segments. More sides = smoother curves but more vertices. Recommended: 32 for small arcs, 64+ for large arcs.
borderPosition Anonymous Controls thickness direction: - INSIDE: Thickness extends inward from radius - OUTSIDE: Thickness extends outward from radius - MIDDLE: Thickness extends equally in both directions * haxe // Create a 90-degree arc mesh.createArc(50, 90, 10, 32, MIDDLE); * // Create a filled semi-circle (pie) mesh.createArc(50, 180, 50, 32, INSIDE); * // Create a ring (donut) mesh.createArc(50, 360, 20, 64, MIDDLE);

createVerticesGrid(mesh: Mesh, columns: Int, rows: Int, width: Float, height: Float, ?staggerX: Float = 0, ?staggerY: Float = 0, ?attrLength: Int = 0, ?attrValues: Array<Float>): Void

Creates a grid of vertices with optional staggering and custom attributes.

Generates a rectangular grid of vertices that can be used for:

  • Terrain meshes
  • Grid-based effects
  • Deformable surfaces
  • Tilemap rendering

Vertices are arranged in row-major order (left to right, top to bottom).

See: createIndicesGrid To create matching triangle indices, createUVsGrid To create matching UV coordinates, MeshUtils.createVerticesGrid The underlying implementation
Name Type Default Description
mesh Mesh The mesh to populate with grid vertices
columns Int Number of columns (vertices per row)
rows Int Number of rows
width Float Total width of the grid in pixels
height Float Total height of the grid in pixels
staggerX Float 0 Horizontal offset applied to odd rows (for hexagonal grids)
staggerY Float 0 Vertical offset applied to odd columns (for diamond grids)
attrLength Int 0 Number of custom float attributes per vertex (beyond x,y)
attrValues Array<Float> (optional) Optional array of custom attribute values. Length must equal (columns+1) * (rows+1) * attrLength * haxe // Create a 10x10 grid for terrain deformation mesh.createVerticesGrid(10, 10, 400, 400); mesh.createIndicesGrid(10, 10); * // Create hexagonal grid mesh.createVerticesGrid(10, 10, 400, 400, cellWidth * 0.5, 0); *

createIndicesGrid(mesh: Mesh, columns: Int, rows: Int, ?mirrorX: Bool = false, ?mirrorY: Bool = false, ?mirrorFlip: Bool = false): Void

Creates triangle indices for a grid of vertices.

Generates indices that connect grid vertices into triangles. Each grid cell is split into two triangles. The mirroring options allow for alternating triangle orientations, useful for:

  • Reducing visual patterns in deformed meshes
  • Creating more natural-looking terrain
  • Special tessellation patterns

Default triangle pattern (no mirroring):

0---1
|\  |
| \ |
|  \|
3---2
See: createVerticesGrid Must be called first to create vertices, MeshUtils.createIndicesGrid The underlying implementation
Name Type Default Description
mesh Mesh The mesh to populate with indices
columns Int Number of columns in the vertex grid
rows Int Number of rows in the vertex grid
mirrorX Bool false Mirror triangle orientation in odd columns
mirrorY Bool false Mirror triangle orientation in odd rows
mirrorFlip Bool false Inverts the mirroring pattern (even instead of odd) * haxe // Standard grid mesh.createIndicesGrid(10, 10); * // Alternating pattern for better deformation mesh.createIndicesGrid(10, 10, true, true); *

createUVsGrid(mesh: Mesh, columns: Int, rows: Int, ?offsetX: Float = 0, ?offsetY: Float = 0): Void

Creates UV coordinates for a grid of vertices.

Generates UV coordinates that map linearly across the grid, stretching any applied texture across the entire mesh. UVs range from (0+offsetX, 0+offsetY) to (1+offsetX, 1+offsetY).

This is useful for:

  • Applying textures to terrain meshes
  • Creating texture-based deformation maps
  • Mapping effects across grid surfaces
See: createVerticesGrid Must be called first to create vertices, MeshUtils.createUVsGrid The underlying implementation
Name Type Default Description
mesh Mesh The mesh to populate with UV coordinates
columns Int Number of columns in the vertex grid
rows Int Number of rows in the vertex grid
offsetX Float 0 UV offset in the X direction (texture scrolling)
offsetY Float 0 UV offset in the Y direction (texture scrolling) * haxe // Standard UV mapping mesh.createUVsGrid(10, 10); * // Scrolling texture effect mesh.createUVsGrid(10, 10, time * 0.1, 0); *