It does not display properly mesh

Hey.
Create a flat mesh in runtime (many small meshes), load height map with Google in it. Mesh doing standard: the vertices, triangles and uv.
Attached three images: 1 general view that it was clear what was going on, 2 and 3 are views of the same site. On 2 shows that the short-range mesh is not visible to the camera. 3 On the camera raised up and drawn mesh. How to make that mesh was always drawn, if the camera is looking at him?
I tried to change the shader, and various camera settings.
Thank you.



Guys, where are the specialists?
I really need help!

can you explain what you are trying to do a little more?

I’m not sure i understand. It sounds like you may have some float precision issues, quite common when dealing with large terrain data that is to scale. What is the position of the terrain meshes and how large are they?

I believe you’re having problems with frustum culling. The “mesh” as far as the CPU knows is out of view so it isn’t being rendered. If you disable the in shader’s vertex displacement and can’t see the mesh then you will possibly won’t see it with displacement either.

The solution is when generating your mesh override the bounds to include the possible displacement range.

1 Like

Sorry, I was busy.
Here is the code for creating a mesh:

public void CreateMeshPart (GameObject PartTerrain, Texture2D tex, int xSize, int ySize, int Grid, ref TMeshOptions MeshOptions, bool MaxSize)
{

Mesh mesh = new Mesh();
mesh.name = PartTerrain.name;
MeshFilter mf = PartTerrain.AddComponent ();
MeshRenderer mr = PartTerrain.AddComponent ();

if (xSize % Grid != 0) MeshOptions.TailX = true;
if (ySize % Grid != 0) MeshOptions.TailY = true;

xSize++;
ySize++;

int xxSize = xSize / Grid;
int yySize = ySize / Grid;

if (xSize % Grid != 0) xxSize += 1;
if (ySize % Grid != 0) yySize += 1;

if (MeshOptions.TailX) xxSize++;
if (MeshOptions.TailY) yySize++;

MeshOptions.XCount = xxSize;
MeshOptions.YCount = yySize;

Vector3[ ] vertices = new Vector3[xxSize * yySize];
Vector2[ ] uv = new Vector2[vertices.Length];
for (int y = 0, i = 0; y < yySize; y += 1)
{
for (int x = 0; x < xxSize; x += 1, i += 1)
{
float PixX = x * Grid;
float PixY = y * Grid;

if (x == xxSize - 1 && MeshOptions.TailX) PixX = xSize - 1;
if (y == yySize - 1 && MeshOptions.TailY) PixY = ySize - 1;

vertices = new Vector3(PixX, 0, PixY);
uv = new Vector2((float)PixX / xSize - 1, (float)PixY / ySize - 1);
}
}
mesh.vertices = vertices;
mesh.uv = uv;
int[ ] triangles = new int[(xxSize - 1) * (yySize - 1) * 6];
for (int ti = 0, vi = 0, y = 0; y < yySize - 1; y++, vi++)
{
for (int x = 0; x < xxSize - 1; x++, ti += 6, vi++)
{
triangles[ti] = vi;
triangles[ti + 3] = triangles[ti + 2] = vi + 1;
triangles[ti + 4] = triangles[ti + 1] = vi + xxSize - 1 + 1;
triangles[ti + 5] = vi + xxSize - 1 + 2;
}
}
mesh.triangles = triangles;
mesh.RecalculateNormals();
mf.mesh = mesh;
mr.material.mainTexture = tex;
mr.material.mainTextureScale = new Vector2(mf.mesh.bounds.size.x / (250 / 15), mf.mesh.bounds.size.z / (250 / 15));
mr.material.shader = Shader.Find(“Legacy Shaders/Diffuse”);
}

Can I talk more, please?
I create a mesh with the desired step as seen in my code and can not change the step, because I overlay the map of heights with the same pitch. I have an emulator in which the real values of space.
Is your decision related to changing the mesh’s grid? Or I not so understood?

Sizes are arbitrary, as I said it’s an emulator. I take the map of heights from Google.

Try:
mesh.bounds.size.y = 1000.0;

I get the height value from Google, then I pass these values to the mesh.
Do you suggest that everyone should put 1000 forcibly? Do I understand correctly?
The whole task is to properly build a height map.
Here is the code for determining the height map for the mesh:

Mesh mesh = _masMeshTerrain*.MeshTerrain.GetComponent().mesh;*
Vector3[ ] vv = new Vector3[mesh.vertices.Length];
mesh.vertices.CopyTo(vv, 0);
for (int k = 0; k < vv.Length; k++)
{
vv[k].y = /…calc/ ;
}
mesh.vertices = vv;
mesh.RecalculateNormals();
MeshCollider mm = _masMeshTerrain*.MeshTerrain.GetComponent();*
mm.enabled = false;
mm.enabled = true;

Setting the bounds to 1000 high is just to see if that solves the problem you’re having, it’s not a final solution. If you’re modifying the height from script it shouldn’t be necessary, you made it sound like you were modifying the height in the shader which would cause the problem.

Try calling RecalculateBounds() when you call RecalculateNormals()

3 Likes

Your decision helped, Thank you very much!

Thank you so much man, I have been trying to fix a similar problem for a very long time.