I'm trying to find the best way to generate perlin-noise-based cube voxel asteroids, but cannot seem to find a consistent method to do so.
I've tried to use this perlin noise library: https://github.com/warmwaffles/Noise/blob/master/src/prime/PerlinNoise.java
Along with this static method to get 3D noise out of it:
public static double Perlin3D(PerlinNoise noise, double x, double y, double z)
{
double AB = noise.getHeight(x, y);
double BC = noise.getHeight(y, z);
double AC = noise.getHeight(x, z);
double BA = noise.getHeight(y, x);
double CB = noise.getHeight(z, y);
double CA = noise.getHeight(z, x);
double ABC = AB + BC + AC + BA + CB + CA;
return ABC / 6;
}
And this method to make the actual asteroids:
public void Generate()
{
PerlinNoise p = new PerlinNoise(seed, persistence, frequency, amplitude, octaves);
GameObject newUnit = Instantiate(unit, genPoint, Quaternion.identity);
newUnit.transform.SetParent(transform);
for (int x = 0; x < maxDistanceFromCenter * 2; x++)
{
for (int y = 0; y < maxDistanceFromCenter * 2; y++)
{
for (int z = 0; z < maxDistanceFromCenter * 2; z++)
{
int targetX = genPoint.x - maxDistanceFromCenter + x;
int targetY = genPoint.y - maxDistanceFromCenter + y;
int targetZ = genPoint.z - maxDistanceFromCenter + z;
Vector3Int targetPos = new Vector3Int(targetX, targetY, targetZ);
Vector3 targetVector3d = new Vector3(targetX, targetY, targetZ).normalized;
double distFromCenter = Vector3.Distance(genPoint, targetPos);
double maxDistFromCenter = (NoiseHelper.Perlin3D(p, targetVector3d.x, targetVector3d.y, targetVector3d.z));
print(maxDistFromCenter);
if (distFromCenter < maxDistFromCenter)
{
GameObject newUnit2 = Instantiate(unit, targetPos, Quaternion.identity);
newUnit2.transform.SetParent(transform);
}
}
}
}
}
Unfortunately I'm getting results that look like this.
When I'm really looking for results like this Blender mock-up I made..
By the looks of it, you can see that I'm using Unity to do this as a medium to see what my code outputs. By no means am I looking for a Unity answer to this, this is entirely conceptual for uses in multiple coding projects.
I'm hoping to get some guidance, answers, or suggestions on achieving what I'm intending. Thank you for all of the help in advanced and I really appreciate your time in lending me a hand,
Cheers.