unity-voxel
unity-voxel copied to clipboard
Empty Voxel position not set
I recently acquired this tool in an attempt to use it to identify empty space as a starting point for generating a navigation graph. Unfortunately I found that while I can retrieve empty voxels from the GPUVoxelizer, Voxel's which return true from IsEmpty have their position set to Vector3.zero unexpectedly.
I attempted to determine what the problem was in the existing code, but it appeared to me that all voxels should be getting their correct position set and I don't understand the code well enough to understand why they don't in the context.
However, I was able to add in a new kernel which simply iterates over the the buffer and sets the position, which appears to work correctly.
The code for that kernel is as follows;
[numthreads(8, 8, 8)]
void FixVoxelPositions(uint3 id : SV_DispatchThreadID)
{
int x = (int)id.x;
int y = (int)id.y;
int z = (int)id.z;
if(x >= _Width) return;
if(y >= _Height) return;
if(z >= _Depth) return;
uint vid = get_voxel_index(x, y, z);
Voxel v = _VoxelBuffer[vid];
v.position = get_voxel_position(x, y, z);
_VoxelBuffer[vid] = v;
}