Skip to content

Missing some Voxel near of origin of scene #9

@Olganix

Description

@Olganix

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions