Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get the number of terrain cells of each material in a sphere area?

Asked by
nc2r 117
4 years ago
Edited 4 years ago

I know the function workspace.Terrain:FillBall(Position, Radius, Enum.Material.Air) shall delete all the terrain in the Radius sized ball at Position, but, how can I return an array containing the number of cells of each material (if any) were displaced? Basically what I want is ReadVoxels() but accepts a point + radius instead of a region3.

function ClearTerrain(Position)
    workspace.Terrain:FillBall(Position, 8, Enum.Material.Air)
    --Return a table in this format {{Enum.Material.Rock, 8}, {Enum.Material.Basalt, 10}} for example, to know how many cells of each material were replaced with air. 
end

This example would be the case if 8 rock and 10 basalt cells were destroyed.

Just to clarify: This question is on-topic as it is to develop my Roblox game.

The problem with workspace.Terrain:ReadVoxels() is that it returns results that the rest of my program cannot parse, and it checks for cells in a block shape rather than a ball. The approach I MIGHT want to take is readvoxels once, clear out the area, read the same voxels again, and subtract, to disregard the cells that stay the same. Then parse the results into the format stated in the code block above. Though this might lack efficiency, and I don't quite know how to parse the results.

0
You have to just do ReadVoxels on the bounding box of the sphere, and then loop over the materials and occupancy results counting only voxels that are less than the radius distance from the center. There is no other way. EmilyBendsSpace 1025 — 4y

Answer this question