karimnaaji / voxelizer Goto Github PK
View Code? Open in Web Editor NEWHeader only mesh voxelizer in c99
Home Page: http://karim.naaji.fr/voxelizer.html
Header only mesh voxelizer in c99
Home Page: http://karim.naaji.fr/voxelizer.html
Hi.
For a project witch need to make fastly collisions for stages, I test yours solution to make voxels.
After getting the resulting point_cloud from yours functions, I add a algo to reduce the numbers of voxels by merging them into a Axis-Scaled-Voxel.
By trying to do this, I noticed there is some duplicate voxels (voxel on the same place because of float precisions : X.0002 vs Y.9999 , with Y = X -1).
The final result is I have some missing voxels, specially near of the plane Y=0, some with Z>0 and X>0. I temporaly solve the problem by using yours precision to be 20% of the voxel size.
But, that create more voxels we need, specially on walking objects.
So I search a little, I see a little mistake on the function vx__map_to_voxel() :
float vx__map_to_voxel(float position, float voxelSize, bool min)
{
float vox = (position + (position < 0.f ? -1.f : 1.f) * voxelSize * 0.5f) / voxelSize;
return (min ? floor(vox) : ceil(vox)) * voxelSize;
}
The problem is if you have a something about y~=0.5, you want the AABB.minimum.y=0, but you have 0.0 or 1.0 depending of being just bottom or up of 0.5,
0.51 + 0.5 = 1.01 => 1.0 with floor
0.49999 + 0.5 = 0.9999 => 0.0 with floor.
In case of having 1.0 with floor, you get the reason why there is some voxel on the same place.
I give a example with Y, but X and Z are also impacted.
By adding +0.5, without the "is min" condition, just decal the trouble of float precision. (I know you want to deal with the fact for negative the floor() function don't give what you want).
As we want all possibles voxels (and the validation of them is done after), I propose this solution :
float vx__map_to_voxel(float position, float voxelSize, bool min)
{
float vox = roundf(position / voxelSize);
return (min ? (vox - 1) : (vox + 1)) * voxelSize;
}
forcing to have one more on each direction could be a time consumer, but here you will be sure you have all voxels for the test with the triangle,
As there is more voxel around, I think that could also solve the trouble about hole (whena vertex of triangle is near a limit of th 3D grid of voxels) , but I don't have a good example for this. So people may be could put the precision to 0.0 (the one to solve holes).
Have a good day.
Line 107 in d175be5
the mesh free call should be after the point cloud ifdef
I was tinkering with this today. Really neat project.
It would have been nice to be able to get quads in the generated output instead of just triangles.
I saw it had some todos - such as "Triangle face merging". Would that be related?
voxelizer.h:793:49: warning: suggest braces around initialization of subobject [-Wmissing-braces]
vx_triangle_t t1 = {v1, v2, boxcenter, {0.0f, 0.0f, 0.0f}};
^~~~~~~~~~~~~~~~~
{ }
voxelizer.h:794:49: warning: suggest braces around initialization of subobject [-Wmissing-braces]
vx_triangle_t t2 = {v2, v3, boxcenter, {0.0f, 0.0f, 0.0f}};
^~~~~~~~~~~~~~~~~
{ }
voxelizer.h:795:69: warning: suggest braces around initialization of subobject [-Wmissing-braces]
vx_triangle_t t3 = {v3, v1, boxcenter, {0.0f, 0.0f, 0.0f}};
^~~~~~~~~~~~~~~~
{ }
voxelizer.h:842:23: warning: suggest braces around initialization of subobject [-Wmissing-braces]
vx_vertex_t vs = {voxelsizex, voxelsizey, voxelsizez};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{ }
voxelizer.h:902:21: warning: suggest braces around initialization of subobject [-Wmissing-braces]
vx_vec3_t vs = {voxelsizex, voxelsizey, voxelsizez};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{ }
I would like to point out that an identifier like "vx__map_to_voxel
" does eventually not fit to the expected naming convention of the C++ language standard.
Would you like to adjust your selection for unique names?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.