[This is the addon][1]
It seems like the only voxel addon that could make my project work long-term, but I don't understand how to use it.
As I understand, I have to use this python tool inside the repository to convert a MagicaVoxel model into some .pngs usable by the addon. It has the following comment:
How to use:
Export the Vox to slices format, then rename the PNG file as *Slice.png
Export the Vox to obj format, then rename the resulting PNG file as *Palette.png
Run this script (see usage by running it with no parameters)
So, exporting to these formats through MagicaVoxel, I can get those two files. The issue is...
This is an example usage of that python tool:
Example: {sys.argv[0]} Vox/Slice.png Vox/Palette.png Texture/Voxel.png Texture/Model.png 64 80 48
It also asks for a Voxel.png and Model.png files. How do I even get those?
Not only that but, I tried inputting placeholder images into the tool so that all arguments were fulfilled, and the Slice.png file I exported before failed the second assert statement:
slices: np.ndarray = cv2.imread(slices_path, cv2.IMREAD_UNCHANGED)
assert slices is not None, f"Failed to load slices: {slices_path}"
assert slices.shape == (height * depth, width, 4)
I believe that means my Slice.png isn't divisible by 16 or something? Since I think the tool requires your model to have sizes divisible by 16. But my model's size is divisible by 16.
I managed to make it work thanks to Theraot's answer. Here's the full process:
vox_to_images.py Input/Slices.png Input/Palette.png Output/Voxel.png Output/Model.png 16 32 16
The first two parameters, Slices.png and Palette.png, are the files we got before. The other two are files we're going to get from the script, Voxel.png and Model.png. Then, last, we have the model's size (I set the example 16, 32, 16 from before). Do note Input/ and Output/ are just folders, and the files are inside them.
# Material filenames
MAT_COLOR = ['color.png', 'color.jpg']
MAT_EMISSION = ['emission.png', 'emission.jpg']
MAT_NORMAL = ['normal.png', 'normal.jpg']
MAT_HEIGHT = ['height.png', 'height.jpg']
MAT_ROUGHNESS = ['roughness.png', 'roughness.jpg']
MAT_SPECULAR = ['specular.png', 'specular.jpg']
MAT_METALLIC = ['metallic.png', 'metallic.jpg']
MAT_AMBIENT_OCCLUSION = ['ao.png', 'ao.jpg']
When hovering over a color in the palette, MagicaVoxel will tell you its index at the bottom center of the screen.
Then you can create a palettes.json like this:
{
"materials": {
"001": ["Metal-Bronze"],
"002": ["Metal-Silver"],
"003": ["Metal-Gold"],
"004": ["Metal-Titanium"]
}
}
001 being the index 1, and so on. Metal-Bronze, for example, would be the name of a folder inside the Materials folder. I think it's required to add a material to all palette indexes you're using, otherwise they won't show up.
build_textures.py Input/palette.json ../Materials Output/Palette.png Output/Color.png Output/Emission.png Output/Normal.png Output/RSMA.png 512
The slices amount depends on the amount of materials being used. The amount is shared between these 4 images. First import it as horizontal 1 and vertical 1 if unsure of how many slices are needed. Then, add the image to TexturedVoxelModel script to see a preview on whether the value is right or not. You should only see a single texture in a square.