Getting Voxel Count

0
ttuzun posted this 21 October 2017

Hi There

I was wondering if there is a way to get a voxel count of a volüme. Both in editör and in runtime.

Thanks

1 Comments
Order By: Standard | Newest | Votes
0
GarethIW posted this 22 October 2017

Sure, all you have to do is count how many voxels in teh voxel array have a State of VoxelState.Active. The voxel array is on the Frame, so you'll need a reference to the current animation Frame first.

If you have a reference to the volume, you can get the current Frame with volume.GetCurrentFrame().

After that, you just need to loop through Frame.Voxels and count where Voxel.State == VoxelState.Active.

Here's an example script that you can attach to a Volume to get a count:

https://gist.github.com/GarethIW/630d891982c0be0f69fa80093781904e

It has two counting methods, one that uses LINQ and one that does a simple loop. The loop would be better for runtime as it won't create any garbage.


Our 103 members have posted 431 times in 104 discussions