I am trying to generate a terrain from a custom mesh, e,g. a torus. I’m starting from the SingleCube3DGeneratorModule class. In the SingleCube3DGeneratorModule the point’s distance is subtracted from the unit sphere’s size and returned as the density. Therefore, it seems that uTerrains (and pretty much every terrain mesher) draws the terrain at the point where *density transitions from NEGATIVE TO POSITIVE*. Is this correct?

So, for a torus, without doing raycasting, it’s very, very difficult for me to generate values that graciously transition from negative to positive. (I can test if a v3 point is inside a mesh without collisions or raycasting – necessary because uTerrains seems to be creating threads for generation and Raycasting and collisions have to run on the main thread). I can very easily put a negative value inside the mesh, and a positive value outside, but for some reason this doesn’t create any geometry. Can you think what could be happening?

I am trying to edit my question but I can’t.

Do I need to use the UnitConverter when generating the mesh? Or is the float x, y, z, that are checked in the SingleCube3DGeneratorModule for example in Unity worldspace?

The floats x y z in generators functions are in voxel unit. So yes, you’ll probably need to convert it to Unity unit. But I doubt this will solve your initial problem because if you didn’t change anything the size of a voxel is 1 (so the conversion won’t change anything even if you should do it).

I figured out what is going wrong. All the meshes I’ve tested have been at v3.zero and scale of 1. I was not transforming the vert object space to world space when testing the points. I fixed it, but now there seems to be a wierd issue with the normals of the vertices of a Unity cube.

I’m going to try to make my own cube with no shared vertices and see what happens

So my alogrithm is based off a paper I found and it has a tolerance factor that is based on a calculation of a certain radius after all the vertex interior angles are calculated. Anyway, long story short, it seems the Unity cube does have odd multiple verts, and I need to work with the tolerance setting to get the right effect. Here’s the smallest polyhedron possible (4 verts) and aside from some oddness based on the tolerance, it looks like we’re getting somewhere now.

Opps here’s the image https://imgur.com/a/AIsX0xY

♫♫ Look what I diiiiiiiiid……. ♫♫♫

Smoothing and intersections added…

https://imgur.com/a/7rIgpyk

Excellent!!! You’ve made a great job here! Would you be agree to share your work (ie. your generator) so I can include it in Ultimate Terrains package? (of course don’t feel obliged to say yes. This is your work)

Therefore, it seems that uTerrains (and pretty much every terrain mesher) draws the terrain at the point where density transitions from NEGATIVE TO POSITIVE. Is this correct?

Yes, this is correct.

I can test if a v3 point is inside a mesh without collisions or raycasting – necessary because uTerrains seems to be creating threads for generation and Raycasting and collisions have to run on the main thread

Yes indeed, generators are called from threads (I have to make that clear in the upcoming documentation).

I can very easily put a negative value inside the mesh, and a positive value outside, but for some reason this doesn’t create any geometry. Can you think what could be happening?

It’s hard to tell. What you describe should work. If you are able to tell that a given 3d point in space is inside or outside (ie. negative or positive value) the torus, this should work. If you want a perfect torus, your voxels’ values have to be equal to the (min) distance between the voxel and the surface of the torus.

Be sure that your camera is close to where the torus should be generated (to be sure it’s within terrain draw distance). Be sure also that your torus is big/small enough.

Let me know if you manage to make it work or if you need more help (but in this case I will probably need to see your code).