First of all, thank you for inviting me to the forum. I've been spending all my free time on this project and I love what you have made here.
Please excuse me if this question has already been addressed, I tried my best to read over the existing forum posts.
I've been working with PolyVox for a couple months now. At first I was using Cubiquity for unity3d, and now I've switched to using PolyVox directly, with UE4. I've had some great success generating endless terrain with the blocky minecraft style, but I'd like to generate a smooth terrain, like the one shown in the Cubiquity plugin. I've been trying for many days now to generate a smooth sphere.
Using the marching cubes method, I keep getting results like this:
http://imgur.com/a/TGrZ4And I want results like this:
http://www.cubiquity.net/cubiquity-for-unity3d/1.2/docs/smooth-terrain.jpgI experimented with the LowPassFilter, and it did seem to smooth it a little, but I can never get it to be round like a sphere. I guess I don't understand how the density of each voxel effects the outcome of the mesh.
Could anyone provide a short block of code to generate the voxel density values for a sphere? This is what I was trying but it doesnt seem to work.
Code:
VoxelData_sp createSphereInVolume(const PolyVox::Region& region)
{
const int32_t xSize = region.getUpperX() - region.getLowerX() + 1;
const int32_t ySize = region.getUpperY() - region.getLowerY() + 1;
const int32_t zSize = region.getUpperZ() - region.getLowerZ() + 1;
float fRadius = xSize / 2.2;
VoxelData_sp voxelData = MakeShareable(new VoxelData(xSize, ySize, zSize));
Vector3DFloat v3dVolCenter(xSize / 2, ySize / 2, zSize / 2);
const float innerBoundary = 0.1f * fRadius;
for (int z = 0; z < zSize; z++)
{
for (int y = 0; y < ySize; y++)
{
for (int x = 0; x < xSize; x++)
{
Vector3DFloat v3dCurrentPos(x, y, z);
float fDistToCenter = (v3dCurrentPos - v3dVolCenter).length();
MDP88 Voxel;
if (fDistToCenter <= fRadius && fDistToCenter >= (innerBoundary))
{
Voxel.setDensity(255 * (5 * (fDistToCenter / fRadius) - 4));
}
else if (fDistToCenter <= (innerBoundary)) {
Voxel.setDensity(255);
}
else {
Voxel.setDensity(0);
}
Voxel.setMaterial(3);
voxelData->at(x, y, z) = Voxel;
}
}
}
return voxelData;
}