andrewrgarcia / voxelmap

A Python library for making voxel and 3D mesh models from images and arrays
https://voxelmap.vercel.app
MIT License
20 stars 2 forks source link

Direct transfer of voxel colors from external file (e.g. Goxel --> .txt) to voxelmap model by default #5

Closed andrewrgarcia closed 1 year ago

andrewrgarcia commented 1 year ago

Currently, external files are imported into a voxelmap (vxm) model by the vxm.Goxel() structure. For this, its function vxm.Goxel().update_colors() must be used to map the RRGGBB hexanumerical voxel colors of the imported file to a specific integer, i.e. :

gox = vxm.Goxel('your-imported-file.txt')
gox.update_colors('8f563b',1)
gox.update_colors('ac3232',2)
gox.update_colors('000000',3)
array = gox.importfile()      # turn txt file to array

If the voxel coloring is intended to be made the same in the Python voxel draw as in the original model, they must then be defined, once again, in the vxm.Model() structure with its vxm.Model().customadd() function:

'load array to voxelmap Model'
model = vxm.Model(array)

'draw with same voxel colors as original external file '
model.customadd(1,'#8f563b')
model.customadd(2,'#ac3232')
model.customadd(3,'#000000')
model.draw('voxels')

Develop a medium which automatically defines the voxel colors of the external file into the Model structure by default. i.e. gox.update_colors('8f563b',1) --> model.customadd(1,'#8f563b'); ...

andrewrgarcia commented 1 year ago

Update:

vxm.Goxel() now automatically updates hashblocks voxel dictionary with the colors from the imported .txt file on the form {index: [ #rrggbb, 1]} after call, i.e. :

gox = vxm.Goxel('your-imported-file.txt')

# automatically updated hashblocks dictionary! no need for gox.update_colors anymore (deprecated)

array = gox.importfile()      # turn txt file to array

Updated strategy which transfer voxel colors from Goxel to Model structure:

'load array to voxelmap Model'
model = vxm.Model(array)

'draw with same voxel colors as original external file '
model.hashblocks = gox.hashblocks
model.draw('voxels')

Keeping this issue open as it may be automated further beyond the current strategy.

andrewrgarcia commented 1 year ago

commit 75106fe closes issue