I have to identify which voxels are empty and which are filled for my unity voxel game object.
I am new to voxel rendering, I have read many articles online but couldn't find anything that which answers my queries.
Below is an example of the voxel model
In each of the voxel, I want to assign a set of {RGBAC}, where R, G, B, and A are the red, blue, green, and alpha components. C defines whether the voxel is empty or filled if C=1 voxel is filled with the game object if C=0 voxel is empty.
The voxel filled with light red color is considered the voxel containing the game object, and the other voxels are considered empty voxels. How could I identify the empty and the filled voxels? I am using C# attached with unity.
CodePudding user response:
In principle a voxel is equivalent to a 3d pixel in a bitmap. So a straightforward way to represent a bunch of voxels would be with a multidimensional array:
public struct MyVoxel{
public bool IsEmpty {get; init;}
}
...
public MyVoxel[,,] voxels = new MyVoxel[100,100,100];
This give you a easy way to store if a voxel is empty and any other information you want to associate with a voxel. You can then generate graphics objects from your voxels on demand, based on the information stored in the voxel.
The downside with this solution is that it requires a huge amount of memory if you want a large area to play in. Because of this most serious implementations use various tricks to reduce memory usage, like procedurally generating voxels, using various compression schemes etc.
CodePudding user response:
You can use Physics.OverlapBox
or Physics.OverlapSphere
, but you need to have a collider attached to each gameobject, that you want to detect. Have a look in the docs.