topskychen / voxelizer

A fast parallel CPU-based surface & solid voxelizer.
MIT License
75 stars 20 forks source link

Little, Easy but Cool Features to Add... #9

Open Bit00009 opened 4 years ago

Bit00009 commented 4 years ago

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...

ChenVox

I made the following proposal for you :

  1. Voxel Size based voxelizer model so we have two options like GRID_SIZE_BASED and VOXEL_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 : VoxelSize1 And with Vector3 Input : VoxelSize2

  2. Bound Clipping : in this feature we have our original bounding box and a clipper one with a Vector3 input (parameter is Vector3) : BoundClip

  3. 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) TightFit

  4. 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) : SolidSurfaceFlag

  5. Voxel Spacing We take voxels and add a Vector3 space between them (parameter is Vector3) : Spacing

  6. 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. VoxelTranformation Perlin 3D Noises : VoxelTransformationbyNoise

  7. Face Aligning : A very interesting method to align solid and surface voxels on original mesh surface (parameter is Boolean) : FaceAlignVoxel

  8. Row Offset Alternating : A simple but cool method to offset odd rows by a float value relative to voxel size. (parameter is Float) : RowOffseting

  9. 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 VoxelColors or even can be stored in voxel itself : UVMapandColorPick Sphere UV before and after voxelization : UVExample

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

topskychen commented 4 years ago

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

topskychen commented 4 years ago

Update 1: The voxelizer gets rid of grid size limit of 1024 in v3.

Update 2: Feature 1 is supported in v3.

Example usage:

Bit00009 commented 4 years ago

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 ^^

topskychen commented 4 years ago

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?

Bit00009 commented 4 years ago

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. Example

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

topskychen commented 4 years ago

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

image

/bin/voxelizer --input=../data/sphere.obj --output=../playground/sphere.binvox --verbose=true --mode=solid --grid_size=32 --clipping_size=26

image

Bit00009 commented 3 years ago

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.

topskychen commented 3 years ago

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.

Bit00009 commented 3 years ago

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...

topskychen commented 3 years ago

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?

Bit00009 commented 3 years ago

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!

topskychen commented 3 years ago

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.

Bit00009 commented 3 years ago

Hi @topskychen Any news on the project?

topskychen commented 3 years ago

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. tight_mode default

Right now I assume the object is water-tight, and leave the caller to call the Manifold library.

InactivatedPyschiopath commented 3 years ago

@topskychen wow dude you're making a very good library my friend!! thanks for your great job 👏👏👏 keep going!

+1 Star from me

topskychen commented 3 years ago

Thank you ; ) @RossetaGotStoned
Ultran (@Bit00009 ) helps a lot in formulating the features. Also feel free to leave your comments on the library.

CycloneRing commented 2 years ago

Any updates?