piece_mesh: Create rayvertex board game piece objects

View source: R/piece_mesh-rayvertex.R

piece_meshR Documentation

Create rayvertex board game piece objects

Description

piece_mesh() creates 3d board game piece objects for use with the rayvertex package.

Usage

piece_mesh(
  piece_side = "tile_back",
  suit = NA,
  rank = NA,
  cfg = pp_cfg(),
  x = 0,
  y = 0,
  z = NA,
  angle = 0,
  axis_x = 0,
  axis_y = 0,
  width = NA,
  height = NA,
  depth = NA,
  envir = NULL,
  ...,
  scale = 1,
  res = 72
)

Arguments

piece_side

A string with piece and side separated by a underscore e.g. "coin_face"

suit

Number of suit (starting from 1).

rank

Number of rank (starting from 1)

cfg

Piecepack configuration list or pp_cfg object, a list of pp_cfg objects, or a character vector referring to names in envir or a character vector referring to object names that can be retrieved by base::dynGet().

x

Where to place piece on x axis of viewport

y

Where to place piece on y axis of viewport

z

z-coordinate of the piece. Has no effect if op_scale is 0.

angle

Angle (on xy plane) to draw piece at

axis_x

First coordinate of the axis unit vector.

axis_y

Second coordinate of the axis unit vector.

width

Width of piece

height

Height of piece

depth

Depth (thickness) of piece. Has no effect if op_scale is 0.

envir

Environment (or named list) containing configuration list(s).

...

Ignored.

scale

Multiplicative scaling factor to apply to width, height, and depth.

res

Resolution of the faces.

Value

A rayvertex object.

See Also

See https://www.rayvertex.com for more information about the rayvertex package. See geometry_utils for a discussion of the 3D rotation parameterization.

Examples

cfg <- game_systems("sans", border = FALSE)$piecepack
rasterize_mesh <- function(mesh) {
  opt <- options(cores = getOption("Ncpus"))
  light <- rayvertex::directional_light(c(0, 0, 1))
  lookat <- c(0, 0, 0)
  rayvertex::rasterize_scene(mesh, light_info = light, lookat = lookat)
  invisible(options(opt))
}
should_run_piece_mesh_example <- piecepackr:::donttest() &&
  requireNamespace("rayvertex", quietly = TRUE) &&
  all(capabilities(c("cairo", "png")))
if (should_run_piece_mesh_example) {
  mesh <- piece_mesh("tile_face", suit = 3, rank = 3, cfg = cfg)
  rasterize_mesh(mesh)
}
if (should_run_piece_mesh_example) {
  mesh <- piece_mesh("coin_back", suit = 4, rank = 2, cfg = cfg)
  rasterize_mesh(mesh)
}
if (should_run_piece_mesh_example) {
  mesh <- piece_mesh("pawn_face", suit = 1, cfg = cfg)
  rasterize_mesh(mesh)
}

piecepackr documentation built on May 12, 2026, 9:07 a.m.