Closed tempaccountforissue closed 1 year ago
Thanks for your issue. I have pushed an update, can you download it and have a try? Please let me know if you have any other questions.
@midstreeeam Thanks for the quick response. I just tried the new update, and it works for the example.py code I was using. However, it does produce this warning:
_t in nTRN not match models, transform not applied
I've also been getting other errors when trying to use my own custom numpy array. If I sent you the numpy array, do you think you could show me how to format it to get it to work? Additionally, the README mentioned automatic palette generation in a future update. Do you know when this might be added?
Thank you
@tempaccountforissue
For the warning _t in nTRN not match models, transform not applied
, you can just ignore it if you are dealing with single model. If you have multiple models stored in one vox file and get this warning, you should split them each into a single vox file. (you can try cars.vox
, there are two cars in one vox file)
According to the voxel's format, each model has a corresponding transformation stored in nTRN node, which is used to locate the relative position. This warning is triggered when number of transformation can not match number of models. The reason you got this warning in cat.vox
is because the cat model is a hand made model designed using MagicalVoxel v0.98. The old version MagicalVoxel doesn't have the transformation and can only handle one model in each vox file.
The numpy array should have a shape of (x1,x2,x3,4)
, where xn
is the length of the correspond axis and 4
is the [r,g,b,a]
color. It is pretty intuitive if you play with the array generated by 3x3x3.vox
a little bit, it has a shape of (3,3,3,4)
, which is human-readable.
And about automatic palette generation, it is a little bit tricky. While coding, it is really easy to generate a model that has tons of different colors, but the palette can only store 256 different color maximumly. It's the limitation of vox format. So I abandoned the implementation of this feature.
This vox io is written for my personal usage, so it might be buggy, and you might get errors like index out of range
that without a proper error message. So, please leave any question in issue, I will keep eyes on it.
I will consider rewrite it and upload an official release to python index if there are some people really using it. I might add the automatic palette generation at that time.
@midstreeeam Hey, me again. The code I'm using to make my NumPy array was originally intended to make pointclouds, so it's easy to get x,y,z and r,g,b data from it, but it's hard to arrange the data in a voxel grid. I was able to get the voxels in the right positions in the voxel grid using gromgull's original py-vox-io repo with a modified version of the from_dense
function in models.py
. However I'm still struggling to get the palette formated properly. As far as I know, .vox palettes only support up to 256 unique colors. However, I have about 5000 different voxels. Is there a way to "force" .vox files to support more than 256 unique colors? It seems like your code makes a voxel grid with the x1,x2,x3
and then colors in voxels with 4
. Could that potentially allow for more than the pallete limit of 256 colors?
@tempaccountforissue
You can use the plot_3d
function to plot a model with more than 256 colors and play with it, but you can not transform that model into vox file. As I mentioned in the last message, the palette can only store 256 different colors maximumly. It's the limitation of the vox format.
If you take a further look at the documentation of the vox format, you can find this paragraph below, there is only 1byte space in vox format for colorIndex.
6. Chunk id 'XYZI' : model voxels, paired with the SIZE chunk
-------------------------------------------------------------------------------
# Bytes | Type | Value
-------------------------------------------------------------------------------
4 | int | numVoxels (N)
4 x N | int | (x, y, z, colorIndex) : 1 byte for each component
-------------------------------------------------------------------------------
So, you can not have more than 256 colors in a vox file. By the way, you also can not have a large model in vox file since there is also only 1Byte space for x,y,z. It is not a good format for pointclouds as far as I know.
@midstreeeam Interesting. I didn't know that there was also a limit to the number of voxels. Do you know what the upper bound would be? My current model uses a (100,100,100) voxel grid allowing for a potential of 1000000 voxels. Also, do you know how the palette is "mapped" to the voxels? For Instance, if I have 256 colors and 300 voxels, how would the 44 remaining voxels get their color? Thanks for all the help by the way.
@tempaccountforissue I didn't test it before, but if there is only 1Byte space for x, y, and z, the upper bound of the scale should also be 256. But there is a way to solve this problem because the size limit is only for a single model. You can split a really large model into many small models and they can still be stored in a single vox file. (but this is only possible in v0.99 and later versions)
In the vox format, it stores the index of color rather than the color itself. So, you can have multiple voxels sharing the same color index (which means they are in the same color). But there can only be 256 indexes. The palette is stored in a separate chunk.
The issue closed since the original problem has been solved. You can open other issues for new questions.
I'm trying to use this code from the example:
v=vox_to_arr('C:/Users/Ryan/Downloads/PyVox-main/PyVox-main/vox/98/cat.vox')
path='C:/Users/Ryan/Downloads/PyVox-main/PyVox-main/palette/cat.png'
write_list_to_vox(v,'testing.vox',path)
But, I'm gettting this error:
Traceback (most recent call last): File "c:\Users\Ryan\Downloads\MasterFile.py", line 143, in <module> write_list_to_vox(v,'testing.vox',path) File "C:\Users\Ryan\anaconda3\envs\Python2Vox\lib\site-packages\pyvox\voxio.py", line 82, in write_list_to_vox t=ArrayWriter(arr,palette_path=palette_path) File "C:\Users\Ryan\anaconda3\envs\Python2Vox\lib\site-packages\pyvox\writer.py", line 48, in __init__ self.xyzi=XYZI(self.mapping()) File "C:\Users\Ryan\anaconda3\envs\Python2Vox\lib\site-packages\pyvox\writer.py", line 59, in mapping i=self._get_color_index(c) File "C:\Users\Ryan\anaconda3\envs\Python2Vox\lib\site-packages\pyvox\writer.py", line 21, in _get_color_index if com(arr[i],color): IndexError: string index out of range