1
\$\begingroup\$

I have a cube-sphere made from 6 planes. I am deforming each of the plane vertices using this code (C#):

aPlane.transform.aPoint(vertices[i]).normalized * this.radius + (randomFloat));

This gives me large gaps where my planes join. How can I separate between shared and non-shared vertices, adding the randomfloat to shared/non-edge vertices only.

Pseudo code could be (C#):

Vector3[] vertices = mesh.vertices;
//maybe add int[] tris = mesh.triangles?
if (vertice is shared)
add randomfloat;
else deform without randomfloat;

I'm quite certain I need to create an array and add triangle vertices and check if the vertices belong to one triangle or two/more triangles.

Everything is generated from code and this is for a hobby project. I already have planet generators from the Asset store but if I use those I might as well just slap together Asset store content and put my name on it.

\$\endgroup\$
0
\$\begingroup\$

I've solved this in a couple of different ways in the past:

  1. Use a 3-dimensional noise function, like Perlin noise or a noisy volume texture, instead of a pure random value. Seed the noise lookup with the original position of your vertex. Since shared vertices have the same position, they'll get the same displacement, keeping them tightly joined.

  2. Use vertex colours to associate a mask with each of your vertices. eg. Make the blue channel of each edge vertex 0, fading to 1 away from the edge. Multiply your random offset by this value so it falls off to zero at the shared vertices. Or, use it as a lerp weight between your pure random method and a more coherent method like 1.

As for your comment about the Asset Store, remember, that's what it's there for — other creators uploaded content there specifically so that fellow developers can use it in their games. Software development, and game development in particular, has a bit of a macho culture where we feel like doing everything ourselves from scratch is the only way to be a "real" developer — but it leads to a lot of reinventing the wheel, and stumbling into mistakes that have been solved by others long ago. If there's already a high-quality solution to your problem out there, I say just use it, and use the time you save to make your core gameplay even better. :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.