//Divides CuboidNet() result by texture size, to get relative coordinates. (0-1, not 0-32 pixels). public static void CuboidNetNormalize(RectangleFloat[] coords, float texturewidth, float textureheight) { float AtiArtifactFix = 0.15f; for (int i = 0; i < 6; i++) { float x = ((coords[i].X + AtiArtifactFix) / texturewidth); float y = ((coords[i].Y + AtiArtifactFix) / textureheight); float w = ((coords[i].X + coords[i].Width - AtiArtifactFix) / texturewidth) - x; float h = ((coords[i].Y + coords[i].Height - AtiArtifactFix) / textureheight) - y; coords[i] = RectangleFloat.Create(x, y, w, h); } }
//Maps description of position of 6 faces //of a single cuboid in texture file to UV coordinates (in pixels) //(one RectangleF in texture file for each 3d face of cuboid). //Arguments: // Size (in pixels) in 2d cuboid net. // Start position of 2d cuboid net in texture file. public static RectangleFloat[] CuboidNet(float tsizex, float tsizey, float tsizez, float tstartx, float tstarty) { RectangleFloat[] coords = new RectangleFloat[6]; { coords[0] = RectangleFloat.Create(tsizez + tstartx, tsizez + tstarty, tsizex, tsizey); //front coords[1] = RectangleFloat.Create(2 * tsizez + tsizex + tstartx, tsizez + tstarty, tsizex, tsizey); //back coords[2] = RectangleFloat.Create(tstartx, tsizez + tstarty, tsizez, tsizey); //right coords[3] = RectangleFloat.Create(tsizez + tsizex + tstartx, tsizez + tstarty, tsizez, tsizey); //left coords[4] = RectangleFloat.Create(tsizez + tstartx, tstarty, tsizex, tsizez); //top coords[5] = RectangleFloat.Create(tsizez + tsizex + tstartx, tstarty, tsizex, tsizez); //bottom } return(coords); }