Import / Conversion API (including Qubicle)

Modified on Fri, 15 Oct 2021 at 08:43 AM

Voxel Play provides a few static classes to assist you in the process of converting objects made in Qubicle into Unity.


You can use QubicleImporter class to convert a qubicle binary file into a color array memory representation that can be used later by other tools to generate a voxelized gameobject or a model definition (like a building model):


ColorBasedModelDefinition colorModel = QubicleImporter.ImportBinary(stream, System.Text.Encoding.UTF8);


The above code will produce a ColorBasedModelDefinition object from the qubicle file (passed as a stream). This color-based object contains the following fields:


colorModel.name: the name of the qubicle object.

colorModel.sizeX/Y/Z: the size of the object.

colorModel.offsetX/Y/Z: an optional placement shift applied to the object.

colorModel.colors: this is a linearized array of colors for each voxel in the qubicle object. Each entry in the array corresponds to an x/y/z color defined by index = x + z * sizeX + y * sizeX * sizeZ;


Now that you can convert a qubicle binary file into a color-based object in memory, you can use the VoxelPlayConverter class to generate a gameobject or a model definition:


GameObject go = VoxelPlayConverter.GenerateVoxelObject(colorModel.colors, offset, scale);

This code will generate a gameobject from the colors array and optionally you can pass an offset and scale for the generated mesh.


You can also generate a Model Definition using this code:

ModelDefinition model = VoxelPlayConverter.GetModelDefinition(voxelTemplate, colorModel, colorToVoxelMapping);

The voxel template parameter is the default voxel definition used if no colorToVoxelMapping parameter is passed or if the color doesn't match to any entry in the colorToVoxelMapping parameter.


The colorToVoxelMapping parameter contains the translation between a color and a voxel definition. For example, you may want to convert white colors from the qubicle object to a "Sand" voxel definition, and a green color to a "Bush" color definition, etc.


You can create a ColorToVoxelMapping object using the method:

ColorToVoxelMap colorToVoxelMapping = VoxelPlayConverter.GetColorToVoxelMapDefinition(colorModel, ignoreTransparency);

This utility method will return a ready to use color to voxel definition mapping object which contains all the colors from the qubicle object. The ignoreTransparency parameter will discard the alpha value of the color when looking for different colors. So, if the qubicle object contains 15 unique colors, this method will return a color mapping object that contains an array of 15 colorMap entries. Each entry contains the color plus a voxel definition field, which you can set on your own to specify how the colors will be translated to voxel definitions when you use the GetModelDefinition method above.


Note that you can also import the Qubicle objects using the Editor tools.






Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article