voxelizer
voxelizer copied to clipboard
Little, Easy but Cool Features to Add...
Hi Dear Qian (@topskychen ) First of all thanks a lot for your great support and great library!
These are a series of suggested features that are simple to implement but very useful and have been used in several powerful voxelizers, Using these capabilities, you can produce interesting meshes...
I made the following proposal for you :
-
Voxel Size based voxelizer model so we have two options like
GRID_SIZE_BASED
andVOXEL_SIZE_BASED
flags also it will be great if you add a Vector3 input like --size=(10 20 15) and if we select VOXEL_SIZE_BASED it will be used as voxel size , size parameter is Vector3 and Flag is a Byte :And with Vector3 Input :
-
Bound Clipping : in this feature we have our original bounding box and a clipper one with a Vector3 input (parameter is Vector3) :
-
Tight Fit Mode : Tight fit voxelizing is such that we check whether the center point of each voxel is inside the mesh or outside it, and if it is outside, we remove it. (parameter is Boolean)
-
Voxel Meta Bit Flags : It's extremely helpful if we know which voxel is solid and which one is surface, It would be great if you can add a flag to each voxel like SURFACE_VOXEL and
SOLID_VOXEL
(parameter is Byte) : -
Voxel Spacing We take voxels and add a Vector3 space between them (parameter is Vector3) :
-
Voxels Transformation : A very good feature to edit and change voxels transformations using modifiers like 3D Noises , Perlin and stuff. This feature data can be kept as extra voxel meta data, so each voxel can have a pos , rotation and scale.
Perlin 3D Noises :
-
Face Aligning : A very interesting method to align solid and surface voxels on original mesh surface (parameter is Boolean) :
-
Row Offset Alternating : A simple but cool method to offset odd rows by a float value relative to voxel size. (parameter is Float) :
-
UV Mapping and Color Picking : In this method voxelizer keeps UV of original base mesh and also pick a color from input texture and store it in voxel meta data like vector<RGBStruct> VoxelColors or even can be stored in voxel itself :
Sphere UV before and after voxelization :
I made this images using a commercial voxelizer and All of them are doable and technically possible.
With these features, your voxelizer will be one of the best and can help a lot of people. I have not very knowledge in this field, but I will help you wherever I can and also I can also make it a plugin for 3D software like 3ds Max, Blender or Maya.
And if this features be added, it's going to be hard to use using a command liner I can make a good GUI for it too.
Thanks for reading, Regards, Ultran
Hi Ultran,
Many thanks to the awesome proposal, especially with the clear demonstration images. I have the interests to make them happen, but may not be very fast since some of features are easy to add, but some of them may need redesign of the code structure. I will make a plan for v3 first, and track them in Projects
tab when ready.
Thank you in advance for your help. The plugins can help more people for sure. Again feel free to add more comments and contributions ; )
Regards, Qian
Update 1: The voxelizer gets rid of grid size limit of 1024 in v3.
Update 2: Feature 1 is supported in v3.
Example usage:
-
GRID_SIZE_BASED
./bin/voxelizer --input=../data/sphere.obj --output=../playground/sphere.binvox --verbose=true --mode=surface --grid_size=128,256,128
-
VOXEL_SIZE_BASED
./bin/voxelizer --input=../data/sphere.obj --output=../playground/sphere.binvox --verbose=true --mode=surface --voxel_size=1.0,1.5,1.0
Amazing job @topskychen ! I tried both of them and they just work fine! Keep it up man... I'm adding mesher too, soon I push the branch to the repo ^^
Thanks @Bit00009!
I have some questions about the features.
Feature 3: How to define the tight mode? e.g., https://en.wikipedia.org/wiki/Klein_bottle
Feature 4: This is more about voxels output format (e.g., including meta info SURFACE_VOXEL, SOLID_VOXEL). Do you have any suggested output format?
Hi Chen,
How to define the tight mode?
Hmm, AFAIK we have voxel size and voxel position, We calculate centers of each vertex and then determine which center points are inside or outside the surface. if they be out of surface we delete the voxel or flag it as non-tight.
I have no idea how can this be done fast as the voxelizer I used but I think it's doable if we raycast a ray from voxel center to surface and if raycast be positive it's outside if it's negative with backward direction it's inside.
This is more about voxels output format...
Oh I'm glad you asked. there's two nice approach for this... struct and flags , bits. A option will be added as -extra or -meta - or -extended , when user adds this option you create a vector list with the size as voxels count, then while processing you tag a flag to every voxel in the list with the same order, for a very minimal, small and memory saving way bits are very suitable but limit options only to 8 , if it's multi-threaded and and order is missing I suggest you to create a struct like this :
struct VoxelExtendedData
{
int _index;
int _flags;
bool _someoption; // With having flags we don't need this usually, just reserving
int32_t _color;
// ... so on
}
Now when we are processing voxels in each step we can allocate all the space in memory then add data to it and when it was done re-sort our vector list by _index property.
We make a flag enum like this :
enum VoxelFlags {
AIR = 0x01 << 0, // Optimal : When a voxel cell is empty
SOLID = 0x01 << 1, // Optimal : When a voxel cell is not empty
INSIDE = 0x01 << 2, // Voxel center is inside the mesh surface , TIGHT
OUTSIDE = 0x01 << 3, // Voxel center is outside the mesh surface , NOT TIGHT
SURFACE = 0x01 << 4, // Voxel is generated from surface in the surface voxelizing pass
FILLED = 0x01 << 5, // Voxel is generated in solid flood filling in the solid voxelizing pass
// ... so on
};
Regards, Ultran
Thanks Ultran. I would add a meta file to output voxel information (i.e., surface, solid etc).
And feature 2 bound clipping is supported now. The example commands are as follows.
/bin/voxelizer --input=../data/sphere.obj --output=../playground/sphere.binvox --verbose=true --mode=surface --grid_size=32 --clipping_size=26
/bin/voxelizer --input=../data/sphere.obj --output=../playground/sphere.binvox --verbose=true --mode=solid --grid_size=32 --clipping_size=26
Hi there @topskychen, How are you? Any news on the process I'm still following with 4 eyes :) I got busy in some projects soon I'll be back.
Stay safe.
Thanks for asking.
Feature 4 (Voxel Meta Bit Flags) is supported with flag --with_meta
to enable. The flags are
enum VoxelFlagsEnum {
FILLED = 0x01 << 0, // Set this bit when a voxel cell is not empty. Unset this bit when this voxel is empty.
INSIDE = 0x01 << 1, // Voxel center is inside the mesh surface , TIGHT
OUTSIDE = 0x01 << 2, // Voxel center is outside the mesh surface , NOT TIGHT
SURFACE = 0x01 << 3, // Voxel is generated from surface in the surface voxelizing pass
SOLID = 0x01 << 4, // Voxel is generated in solid flood filling in the solid voxelizing pass
CLIPPED = 0x01 << 5, // Voxel is clipped
};
Also an example to read the meta file is added as examples/read_meta.cpp
.
I tested it today and it's just amazing Chen!! This is exactly what I had in mind. All worked well and now I can group voxels in no time Very nice job man! 💙👌 I'm looking forward to see how you nail hard ones...
Thanks for trying and great to hear that.
In terms of feature 3, I do have some idea described here. I will work on it when I have more time.
By the way, would you like to recommend any tools to visualize the feature 5, 6 etc?
Hi Chen! Thanks for your great support!
I did read about feature 3 and understood it only works on watertight objects, what If you use this library ( Plus Version ) as an option to convert the mesh to watertight before doing raycasting or any other computing.
it can be as an option -force-watertight
to force voxelizer convert the mesh to watertight so in the case user faced wrong result he/she can use this option.
About feature 5 and 6, what about using ImGui and a simple opengl or directx backend? as you know imgui is very fast and easy to implement and it eases the workflow to add noise options and parameters.
Also if you can do a favor I'll be very thankful, Can you separate data folder to a different branch or some cloud drive? I know it's not much size but I feel it's an extra size I have to download on each commit.
Thanks and Stay Safe!
Agree that we can provide the force-watertight
flag to the users.
Thanks for the recommendation. I will take a look at the ImGui library.
I have moved other files to Google Drive except the sphere.obj, which should be very small-size.
Hi @topskychen Any news on the project?
Now feature 3 tight mode is supported (with --tight flag). Two screenshots show the tight mode and default mode. We can see some voxels are filtered in the tight mode.
Right now I assume the object is water-tight, and leave the caller to call the Manifold library.
@topskychen wow dude you're making a very good library my friend!! thanks for your great job 👏👏👏 keep going!
+1 Star from me
Thank you ; ) @RossetaGotStoned
Ultran (@Bit00009 ) helps a lot in formulating the features.
Also feel free to leave your comments on the library.
Any updates?