Skip to content

Commit

Permalink
Negative m will avoid smoothing
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyettinger committed Aug 17, 2018
1 parent 9e8be25 commit 71917a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
31 changes: 21 additions & 10 deletions IsoVoxel/PaletteDraw.cs
Expand Up @@ -4448,7 +4448,7 @@ private static Bitmap renderLargeOrtho(byte[,,] voxels, int xSize, int ySize, in
return bmp;
}

public static void processUnitSmart(MagicaVoxelData[][] parsed, string u, int xSize, int ySize, int zSize, Outlining o, int multiplier)
public static void ProcessUnitSmart(MagicaVoxelData[][] parsed, string u, int xSize, int ySize, int zSize, Outlining o, int multiplier)
{
xSize = Math.Max(sizex, xSize);
ySize = Math.Max(sizey, ySize);
Expand All @@ -4470,6 +4470,8 @@ public static void processUnitSmart(MagicaVoxelData[][] parsed, string u, int xS
int frames = parsed.Length;
if (frames == 1)
{
bool cubic = multiplier < 0;
multiplier = Math.Abs(multiplier);
renderSmart(parsed[0], bx, by, bz, Direction.SE, o, true).Save(di.FullName + SEP + u + "_SE" + ".png", ImageFormat.Png); //se
renderSmart(parsed[0], bx, by, bz, Direction.SW, o, true).Save(di.FullName + SEP + u + "_SW" + ".png", ImageFormat.Png); //sw
renderSmart(parsed[0], bx, by, bz, Direction.NW, o, true).Save(di.FullName + SEP + u + "_NW" + ".png", ImageFormat.Png); //nw
Expand Down Expand Up @@ -4527,7 +4529,9 @@ public static void processUnitSmart(MagicaVoxelData[][] parsed, string u, int xS
for (int s = 1; s <= multiplier; s++)
{
if (s > 1)
colors2 = TransformLogic.RunCA(TransformLogic.ScalePartial(colors, s), s);
colors2 = cubic
? TransformLogic.ScalePartial(colors, s)
: TransformLogic.RunCA(TransformLogic.ScalePartial(colors, s), s);
else
colors2 = colors.Replicate();
//RenderOrthoMultiSize(TransformLogic.SealGaps(colors2), ySize, xSize, zSize, o, s)
Expand Down Expand Up @@ -4555,9 +4559,12 @@ public static void processUnitSmart(MagicaVoxelData[][] parsed, string u, int xS
RenderSmartFaces(faces3, xSize * s, ySize * s, zSize * s, o, true).Save(di.FullName + SEP + u + "_Size" + s + "_Slope_NE" + fs, ImageFormat.Png);
RenderSmartFacesOrtho(faces3, xSize * s, ySize * s, zSize * s, o, true).Save(di.FullName + SEP + u + "_Size" + s + "_Slope_E" + fs, ImageFormat.Png);
}

}
else
{
bool cubic = multiplier < 0;
multiplier = Math.Abs(multiplier);
for (int f = 0; f < frames; f++)
{
string fs = $"_{f:D2}.png";
Expand Down Expand Up @@ -4628,7 +4635,9 @@ public static void processUnitSmart(MagicaVoxelData[][] parsed, string u, int xS
for (int s = 1; s <= multiplier; s++)
{
if (s > 1)
colors2 = TransformLogic.RunCA(TransformLogic.ScalePartial(colors, s), s);
colors2 = cubic
? TransformLogic.ScalePartial(colors, s)
: TransformLogic.RunCA(TransformLogic.ScalePartial(colors, s), s);
else
colors2 = colors.Replicate();
//RenderOrthoMultiSize(TransformLogic.SealGaps(colors2), ySize, xSize, zSize, o, s)
Expand Down Expand Up @@ -4678,7 +4687,8 @@ static void Main(string[] args)
else
{
Console.WriteLine("Args: 'file x y z m o'. file is a MagicaVoxel .vox file, x y z are sizes,");
Console.WriteLine("m is a multiplier to draw extra renders up to that size (integer, at least 1),");
Console.WriteLine("m is an integer multiplier to draw larger renders up to that size");
Console.WriteLine(" (if m is negative it renders the same sizes but without smoothing),");
Console.WriteLine("o must be one of these words, changing how outlines are drawn (default light):");
Console.WriteLine(" outline=full Draw a black outer outline and shaded inner outlines.");
Console.WriteLine(" outline=light Draw a shaded outer outline and shaded inner outlines.");
Expand All @@ -4688,7 +4698,7 @@ static void Main(string[] args)
Console.WriteLine("Defaults: runs on Zombie.vox with x y z set by the model, m is 3, o is light.");
Console.WriteLine("Given no arguments, running on " + voxfile + " ...");
}
byte x = 0, y = 0, z = 0;
int x = 0, y = 0, z = 0;
int m = 3;
Outlining o = Outlining.Light;
int al = args.Length;
Expand All @@ -4701,15 +4711,15 @@ static void Main(string[] args)
{
if (al >= 2)
{
x = byte.Parse(args[1]);
x = int.Parse(args[1]);
}
if (al >= 3)
{
y = byte.Parse(args[2]);
y = int.Parse(args[2]);
}
if(al >= 4)
{
z = byte.Parse(args[3]);
z = int.Parse(args[3]);
}
if(al >= 5)
{
Expand All @@ -4719,7 +4729,8 @@ static void Main(string[] args)
catch (Exception)
{
Console.WriteLine("Args: 'file x y z m o'. file is a MagicaVoxel .vox file, x y z are sizes,");
Console.WriteLine("m is a multiplier to draw extra renders up to that size (integer, at least 1),");
Console.WriteLine("m is an integer multiplier to draw larger renders up to that size");
Console.WriteLine(" (if m is negative it renders the same sizes but without smoothing),");
Console.WriteLine("o must be one of these words, changing how outlines are drawn (default light):");
Console.WriteLine(" outline=full Draw a black outer outline and shaded inner outlines.");
Console.WriteLine(" outline=light Draw a shaded outer outline and shaded inner outlines.");
Expand All @@ -4738,7 +4749,7 @@ static void Main(string[] args)
StoreColorCubesFaces();
StoreColorCubesFacesSmall();
StoreColorCubesFacesOrtho();
processUnitSmart(mvd, voxfile, x, y, z, o, m);
ProcessUnitSmart(mvd, voxfile, x, y, z, o, m);
bin.Close();
}

Expand Down
32 changes: 17 additions & 15 deletions IsoVoxel/TransformLogic.cs
Expand Up @@ -490,39 +490,41 @@ public static List<MagicaVoxelData> VoxArrayToListSmoothed(byte[,,] voxelData)
}


public static byte[,,] ScalePartial(byte[,,] colors, double scale)
public static byte[,,] ScalePartial(byte[,,] colors, int scale)
{
if(scale == 1.0) return colors;
if(scale == 1) return colors.Replicate();
return ScalePartial(colors, scale, scale, scale);
}
public static byte[,,] ScalePartial(byte[,,] colors, double xScale, double yScale, double zScale)
public static byte[,,] ScalePartial(byte[,,] colors, int xScale, int yScale, int zScale)
{
int xSize = colors.GetLength(0), ySize = colors.GetLength(1), zSize = colors.GetLength(2);

if(xScale <= 0 || yScale <= 0 || zScale <= 0)
return colors;
byte[,,] vls = new byte[(int)(xSize * xScale), (int)(ySize * yScale), (int)(zSize * zScale)];
byte[,,] vls = new byte[(xSize * xScale), (ySize * yScale), (zSize * zScale)];

for(int z = 0; z < zSize; z++)
{
for(int y = 0; y < ySize; y++)
{
for(int x = 0; x < xSize; x++)
{
for(double xsc = 0.0; xsc < xScale; xsc += 1.0)
for(int xsc = 0; xsc < xScale; xsc++)
{
for(double ysc = 0.0; ysc < yScale; ysc += 1.0)
for(int ysc = 0; ysc < yScale; ysc++)
{
for(double zsc = 0.0; zsc < zScale; zsc += 1.0)
for(int zsc = 0; zsc < zScale; zsc++)
{
int tempX = (x - (xSize / 2));
int tempY = (y - (ySize / 2));
int tempZ = (z - (zSize / 2));
int x2 = (int)Math.Round((xScale * tempX) + (xScale * xSize / 2) + ((tempX < 0) ? xsc : -xsc));
int y2 = (int)Math.Round((yScale * tempY) + (yScale * ySize / 2) + ((tempY < 0) ? ysc : -ysc));
int z2 = (int)Math.Round((zScale * tempZ) + (zScale * zSize / 2) + ((tempZ < 0) ? zsc : -zsc));

if(colors[x, y, z] > 0 && x2 >= 0 && y2 >= 0 && z2 >= 0 && x2 < xSize * xScale && y2 < ySize * yScale && z2 < zSize * zScale)
//int tempX = (x - (xSize / 2));
//int tempY = (y - (ySize / 2));
//int tempZ = (z - (zSize / 2));
//int x2 = ((xScale * tempX) + (xScale * xSize / 2) + ((tempX < 0) ? xsc : -xsc));
//int y2 = ((yScale * tempY) + (yScale * ySize / 2) + ((tempY < 0) ? ysc : -ysc));
//int z2 = ((zScale * tempZ) + (zScale * zSize / 2) + ((tempZ < 0) ? zsc : -zsc));
int x2 = xScale * x + xsc;
int y2 = yScale * y + ysc;
int z2 = zScale * z + zsc;
if (colors[x, y, z] > 0 && x2 >= 0 && y2 >= 0 && z2 >= 0 && x2 < xSize * xScale && y2 < ySize * yScale && z2 < zSize * zScale)
vls[x2, y2, z2] = colors[x, y, z];
}
}
Expand Down
3 changes: 2 additions & 1 deletion Usage.txt
Expand Up @@ -21,7 +21,8 @@ For this, use `IsoVoxel.exe file.vox x y z m o`, where the arguments are:
- file.vox was saved from MagicaVoxel, in the vox/ subfolder usually as mentioned before
- x, y, and z are the bounds of the model, which can be up to 128, and don't have to match the dimensions given in MagicaVoxel;
this can be useful to render multiple models at the same position in the images
- m is a multiplier to draw extra renders at multiples of the current size, from size 1 to size m; m defaults to 3 and can be any non-negative integer.
- m is a multiplier to draw extra renders at multiples of the current size, from size 1 to size m; m defaults to 3 and can be any integer.
- if m is negative, the larger sizes willl not be smoothed at all, and each voxel will simply become a larger cube of voxels. When m is -3, it will act exactly like when m is 3 except for not smoothing.
- o is an outline mode, which can be omitted and defaults to `outline=light`:
- `outline=full` (this makes black outlines around the edge of the model and shading on inner gaps)
- `outline=light` (which uses the shaded color instead of black for outer outlines)
Expand Down

0 comments on commit 71917a6

Please sign in to comment.