chunked-vox
    Preparing search index...

    Class VoxelModelWriter

    Class for writing large voxel models in MagicaVoxel format.

    function generateGrayscalePalette() {
    const palette = []
    for (let index = 0; index < 256; index++) {
    palette.push([index, index, index]) // RGB
    }
    return palette
    }
    const voxelModel = new VoxelModelWriter(generateGrayscalePalette())

    // generate random model
    function randomIntFromInterval(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min)
    }

    const modelSize = 368
    for (let x = 0; x < modelSize; x++) {
    for (let y = 0; y < modelSize; y++) {
    voxelModel.setBlock(x, y, 0, randomIntFromInterval(0, 255))
    }
    }

    const buffer = voxelModel.writeVox()
    Index

    Constructors

    • Creates a VoxelModelWriter instance.

      Parameters

      • palette: [number, number, number][]

        An array of RGB color triplets for the voxel model palette.

      • OptionalsectionSize: number = 64

        Size of the sparse models as chunks.

      Returns VoxelModelWriter

    Properties

    chunks: Map<any, any>
    palette: [number, number, number][]
    sectionSize: number
    sectionSizeOffset: number

    Methods

    • Set a voxel with a color palette index. Z is gravity direction.

      Parameters

      • x: number

        X coordinate of voxel.

      • y: number

        Y coordinate of voxel.

      • z: number

        Z coordinate of voxel.

      • i: number

        Color palette index.

      Returns void

    • Generate a MagicaVoxel formatted buffer.

      Parameters

      • OptionalreleaseInternalData: boolean = false

        Release internal data used for representing model.

      Returns Buffer<ArrayBufferLike>

      A buffer containing the voxel model in MagicaVoxel format.

    • Writes an ASCII-formatted string to the buffer.

      Parameters

      • buffer: SmartBuffer

        The buffer used for writing the string to.

      • string: string

        The string to write with.

      Returns void

    • Writes a key-value dictionary structure to the buffer.

      Parameters

      • buffer: SmartBuffer

        The buffer to write the dictionary with.

      • Optionalobject: {} = {}

        The object used as a key-value dictionary.

      Returns void