// rbox.inc -- Contains macros for RoundBox and Die /* RoundBox macro -- creates a box with rounded edges, * centered at the origin, with the specified dimensions * * Parameters: * Dims: Vector giving dimensions of the box * Rad: Radius of the edges * UseMerge: Flag for union vs merge, yes = merge, no = union */ #macro RoundBox(Dims, Rad, UseMerge) #local XMax = Dims.x / 2; #local YMax = Dims.y / 2; #local ZMax = Dims.z / 2; #local X = XMax - Rad; #local Y = YMax - Rad; #local Z = ZMax - Rad; #if (UseMerge) merge #else union #end { // Base box with clipped edges box { <-XMax, -Y, -Z>, } box { <-X, -YMax, -Z>, } box { <-X, -Y, -ZMax>, } // X Edges cylinder { <-X, Y, Z>, , Rad } cylinder { <-X, Y, -Z>, , Rad } cylinder { <-X, -Y, Z>, , Rad } cylinder { <-X, -Y, -Z>, , Rad } // Y Edges cylinder { < X, -Y, Z>, < X, Y, Z>, Rad } cylinder { < X, -Y, -Z>, < X, Y, -Z>, Rad } cylinder { <-X, -Y, Z>, <-X, Y, Z>, Rad } cylinder { <-X, -Y, -Z>, <-X, Y, -Z>, Rad } // Z Edges cylinder { < X, Y, -Z>, < X, Y, Z>, Rad } cylinder { < X, -Y, -Z>, < X, -Y, Z>, Rad } cylinder { <-X, Y, -Z>, <-X, Y, Z>, Rad } cylinder { <-X, -Y, -Z>, <-X, -Y, Z>, Rad } // Corners sphere { < X, Y, Z>, Rad } sphere { < X, Y, -Z>, Rad } sphere { < X, -Y, Z>, Rad } sphere { < X, -Y, -Z>, Rad } sphere { <-X, Y, Z>, Rad } sphere { <-X, Y, -Z>, Rad } sphere { <-X, -Y, Z>, Rad } sphere { <-X, -Y, -Z>, Rad } } #end // #macro RoundBox /////////////////////////////////////////////////////////////////// /* Macro to create a die * * Parameters: * Size: Size of the cube * Rad: Radius of the edges of the die * Dot: Color of the spots * UseMerge: Flag for union vs merge, yes = merge, no = union * * Uses RoundBox() #macro to create the base cube centered at the origin, * ready to be rotated and translated to its final position. * * Note: The color of the spots is passed as a parameter, but the final * pigment/texture/finish... for the body of the cube needs to be * applied separately. */ #macro Die(Size, Rad, Dot, UseMerge) #local Side = Size / 2; // Location of sides of the die #local Pos = Size / 6; // Offset position of corner spots #local Spot = Size / 12.5; // Diameter of spots #local Squash = <1, 1, .3>; // Scale factor to squash spots into ovals #local Shift = Side + Spot / 30; // Distance to translate spots from origin to sides #local S = <1, 1.4, 0>; // Multiplier to offset spots on side 6, // otherwise they're too close together // Array defining the positions of the spots #local Spots = array[7] { // Used for: <0, 0, 0>, // Center spot 1, 3, 5 <-Pos, -Pos, 0>, , // Lower-left & Upper-right 2 thru 6 <-Pos, Pos, 0>, , // Upper-left & Lower-right 4, 5, 6 <-Pos, 0, 0>, // Left-center & Right center 6 } difference { // Body of the die object { RoundBox(, Rad, UseMerge) } // One spot sphere { 0, Spot * 1.2 // Single spot slightly larger pigment { Dot } scale Squash // Reduce sphere in the z dimension translate z * -Shift // Shift to front side } // Two spots union { sphere { Spots[1], Spot } sphere { Spots[2], Spot } pigment { Dot } scale Squash rotate y * 90 // Rotate and translate x * Shift // shift to right side } // Three spots union { #local I = 0; #while (I < 3) sphere { Spots[I], Spot } #local I = I + 1; #end pigment { Dot } scale Squash rotate x * 90 // Rotate and translate y * Shift // shift to top side } // Four Spots union { #local I = 1; #while (I < 5) sphere { Spots[I], Spot } #local I = I + 1; #end scale Squash pigment { Dot } rotate x * 90 // Rotate and translate y * -Shift // shift to bottom side, opposite 3 } // Five Spots union { #local I = 0; #while (I < 5) sphere { Spots[I], Spot } #local I = I + 1; #end scale Squash pigment { Dot } rotate y * 90 // Rotate and translate x * -Shift // shift to left side, opposite 2 } // Six Spots union { #local I = 1; #while (I < 7) sphere { Spots[I] * S, Spot } #local I = I + 1; #end scale Squash pigment { Dot } translate z * Shift // Shift to back side, opposite 1 } } #end // #macro Die