MagicaX.VoxGenerator (MagicaX v0.1.0)
View SourceA flexible VOX file generator for MagicaVoxel format.
Supports multiple input methods:
- Direct programmatic generation
- JSON-to-VOX conversion with comprehensive validation
- Built-in shape generators (cube, sphere, teapot)
- Custom palette support with 256-color capability
Examples
# Generate from JSON file
{:ok, message} = MagicaX.VoxGenerator.generate_from_json_file("model.json")
# Generate programmatically
dimensions = {10, 10, 10}
voxels = [{0, 0, 0, 1}, {1, 1, 1, 2}]
{:ok, message} = MagicaX.VoxGenerator.generate_vox_file("model.vox", dimensions, voxels)
# Generate basic shapes
{:ok, message} = MagicaX.VoxGenerator.generate_cube("cube.vox", 10)
{:ok, message} = MagicaX.VoxGenerator.generate_sphere("sphere.vox", 8)
Summary
Functions
Creates a simple cube VOX file.
Generates a VOX file from JSON data.
Generates a VOX file from a JSON file with automatic output naming.
Generates a VOX file from a parsed JSON map.
Creates a sphere VOX file.
Creates a teapot-like shape VOX file.
Generates a new VOX file with specified dimensions and voxel data.
Functions
Creates a simple cube VOX file.
Parameters
filename- Output VOX file pathsize- Cube size (default: 10)
Returns
{:ok, message}- Success message{:error, reason}- Error description
Generates a VOX file from JSON data.
JSON Structure
{
"dimensions": [x, y, z], // REQUIRED: 3D dimensions
"voxels": [ // REQUIRED: Array of voxel objects
{
"x": 0, // REQUIRED: X coordinate (0-255)
"y": 0, // REQUIRED: Y coordinate (0-255)
"z": 0, // REQUIRED: Z coordinate (0-255)
"color_index": 1 // REQUIRED: Color index (0-255)
}
],
"palette": [ // OPTIONAL: Custom color palette
{
"r": 255, // REQUIRED: Red component (0-255)
"g": 255, // REQUIRED: Green component (0-255)
"b": 255, // REQUIRED: Blue component (0-255)
"a": 255 // REQUIRED: Alpha component (0-255)
}
],
"metadata": { // OPTIONAL: File metadata
"name": "My VOX Model",
"author": "Creator Name",
"description": "Model description"
}
}Example
json = """
{
"dimensions": [10, 10, 10],
"voxels": [
{"x": 0, "y": 0, "z": 0, "color_index": 1},
{"x": 1, "y": 0, "z": 0, "color_index": 2}
]
}
"""
MagicaX.VoxGenerator.generate_from_json("output.vox", json)
Generates a VOX file from a JSON file with automatic output naming.
If no output filename is provided, it will use the same name as the JSON file but with .vox extension.
Examples
# Creates model.vox from model.json
MagicaX.VoxGenerator.generate_from_json_file("model.json")
# Creates custom.vox from model.json
MagicaX.VoxGenerator.generate_from_json_file("model.json", "custom.vox")
Generates a VOX file from a parsed JSON map.
Creates a sphere VOX file.
Parameters
filename- Output VOX file pathradius- Sphere radius (default: 10)
Creates a teapot-like shape VOX file.
Parameters
filename- Output VOX file pathscale- Scale factor (default: 1.0)
Generates a new VOX file with specified dimensions and voxel data.
Parameters
filename- Output VOX file pathdimensions- Tuple of{x, y, z}dimensionsvoxels- List of{x, y, z, color_index}tuplespalette- Optional custom palette (defaults to built-in palette)
Returns
{:ok, message}- Success message{:error, reason}- Error description