pythongodotvoxelgodot4

How to use Viktor Ferenczi's Godot Voxel addon?


[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.


Solution

  • I managed to make it work thanks to Theraot's answer. Here's the full process:

    1. Create model in MagicaVoxel, sizes have to be multiples of 16 (for example, 16, 32, 16)
    2. Export to slices format, rename the resulting.png file to Slices.png for example
    3. Export to obj format. A few files will be exported, one of them being a .png file. Rename the file to Palette.png
    4. Run the vox_to_images script, go into cmd and do something like:
    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.

    1. At this point, we only have 2 files out of the 7 required to display the model. We're going to get the remaining files through the build_textures script.
    2. Create a materials folder. Inside these folder, each material will have their own folder. Their name matters since it'll be used as a reference later.
    3. Each material folder will have photos that represent the material (do save the resolution, they must have the same resolution and you need to input what it is, such as 512 for 512x512). The supported names are:
    # 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']
    
    1. Create a palettes.json file. It'll index each of the MagicaVoxel's palette indexes with a material folder's file name:

    enter image description here

    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.

    1. Run the last script to get the last files:
    build_textures.py Input/palette.json ../Materials Output/Palette.png Output/Color.png Output/Emission.png Output/Normal.png Output/RSMA.png 512
    
    1. Now that we have all the required files, we need to add a TexturedVoxelModel node to the Godot scene, then add a TexturedVoxelModel script.
    2. Finally, set up the files' import settings. There are 2 configurations used:

    enter image description here

    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.

    enter image description here

    1. Then just apply the files to the script:

    enter image description here