1
\$\begingroup\$

I have been having an issue in making floating islands. For this i have created an array filled with the position data for both the top and bottom half of the island. Everything works fine when i only have the top half of the triangles implimented, but when i add the bottom half of the triangles become triangles that are shifted to the top half of the island.

To be more precise, the traingle index data seems to change while writing it to mesh.triangles.

This happens after mesh.triangles = triangles in the following code

    mesh.Clear();

    transform.position = new Vector3(-width/2,0 * scale,-height/2 * scale);

    positionsAll = new Vector3[2 * width * height];

    setupHeightMap();
    int[] triangles = getTriangles();

    mesh.vertices = positionsAll;
    mesh.triangles = triangles;
    mesh.RecalculateNormals();

An example watch can be seen here, witth the first four showing the change in index, and the final four showing how the point is the same point but on the above surface.

    triangles[0]    30785   System.Int32
    triangles[4]    96322   System.Int32
    mesh.triangles[0]   30785   System.Int32
    mesh.triangles[4]   30786   System.Int32
    mesh.vertices[triangles[0]] "(65.0, 0.0, 120.0)"    UnityEngine.Vector3
    mesh.vertices[triangles[4]] "(66.0, -0.2, 120.0)"   UnityEngine.Vector3
    mesh.vertices[mesh.triangles[0]]    "(65.0, 0.0, 120.0)"    UnityEngine.Vector3
    mesh.vertices[mesh.triangles[4]]    "(66.0, 0.2, 120.0)"    UnityEngine.Vector3

This watch data was generated in an instance where all triangles that had positive values were not instanciated, but the same problem hapens if all Triangles are instanciated.

If anyone can tell me why this happens and/or how i can fix this problem that would be extremly helpful. thank you!

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

It looks like you are trying to create meshes with quite a few vertices. More than 65,536 (2^16) vertices in fact. Until Unity 2017.3 this is not supported, so you would need to split it into two separate meshes. In 2017.3 they added support for 32-bit indices, but you have to enable it per mesh:

mesh.IndexFormat = IndexFormat.UInt32;
\$\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.