Although piecepackr has basic 3D graphic support via a manually drawn oblique projection this package aims to extend support to 3D graphics using the rgl
and rayrender
packages. It also supports exporting images using the Wavefront OBJ file format as well as a function that saves png textures for use with James H. Vipond's piecepack OBJ files.
library("ppgames") library("piecepackr") library("piecepackr3d") df <- ppgames::df_four_field_kono() envir <- piecepackr::game_systems("dejavu3d")
piece3d
draws pieces using rgl
graphics.
library("rgl") pmap_piece(df, piece3d, trans=op_transform, envir = envir, scale = 0.98, res = 150)
piece
creates rayrender
objects.
library("rayrender") l <- pmap_piece(df, piece, trans=op_transform, envir = envir, scale = 0.98, res = 150) scene <- do.call(dplyr::bind_rows, l) render_scene(scene, lookat = c(2.5, 2.5, 0), lookfrom = c(0, -2, 13))
write_obj
saves the specified piece as a Wavefront OBJ file (plus an associated MTL file and a png texture).
files <- write_obj("tile_face", suit=3, rank=3, cfg = envir$piecepack) print(files)
$obj [1] "/tmp/RtmpvhT4ZB/file11fa251def12.obj" $mtl [1] "/tmp/RtmpvhT4ZB/file11fa251def12.mtl" $png [1] "/tmp/RtmpvhT4ZB/file11fa251def12.png"
save_3d_textures
saves png textures for use with James H. Vipond's piecepack OBJ files. Jame's OBJ models are much richer than the ones generated by write_obj
, for instance his tiles have 49 vertices whereas mine only have 8 vertices.
save_3d_textures(cfg = envir$piecepack, directory = tempdir())
piecepackr
configurations for 3d graphicsHere are a couple of suggestions when making piecepackr configurations for 3d graphics:
border_color = "transparent"
.belt_face.width=1, belt_face.height=265/189
if using save_3d_textures
.edge_color.tile = "black", edge_color.coin = "black"
.remotes::install_github("piecepackr/piecepackr") remotes::install_github("tylermorganwall/rayrender") install.packages("rgl", repos="http://R-Forge.R-project.org") remotes::install_github("piecepackr/piecepackr3d")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.