Terrain Generator trims mesh if exceeding 65k vertices

Hello guys!

I’ve tried this terrain generator: https://developer.playcanvas.com/en/tutorials/terrain-generation/
But it seems like it starts trimming the mesh once subdivisions go > 255 (number of vertices > 65k)

This doc claims it should be possible to generate meshes with >65k of vertices / indices: https://developer.playcanvas.com/en/api/pc.Mesh.html#setIndices

But seems like it’s not the case. Is it a bug or smth?

When you say ‘trim’, do you mean the collision mesh or the visible render?

The visible render also!

I didn’t try to reproduce it on original project, but in my project using this script the trimming happens. Should I provide a public example?

There is a limit on the number of vertices in a number of older devices that don’t support 32-bit index buffers. I am not sure though that’s the issue in your case.

I’ve tried the default terrain example with 300 subdivisions and it seems to work quite alright:

@Leonidas thank you for quick look!
I was trying my project in desktop environment, so it’s not mobile issue…
I’ll try reproducing this issue in original tutorial project then.

1 Like

@Leonidas @yaustar the trimming happens in tutorial project as well
to notice it you just need to set width / depth to 10, max height to 1
and then compare 250 subdivs vs 400, for example.

Cloned tutorial project with 400 subdivs:
https://playcanvas.com/project/773098/

Seems like something is wrong with pc.createMesh

You are right, but what’s interesting is that the collision mesh works. Here is me standing mid air because the collision mesh was fully generated:

@mvaligursky do you any idea what may the issue here?

Yeah, the collision is generated with 0.5 * subdiv, so it will not be trimmed until subdiv = 512

pc.CreateMesh only supports 16bit index buffers:

We need to port it to use new mesh api which does not have that limitation.

Alternatively, you can do one of these:

  • use Mesh API directly when generating terrain, instead of createMesh function. Note that as mentioned, some old mobile devices do not support 32bit index buffer

  • generates terrain in multiple patches, where each path does not go over 65535 vertices

4 Likes

@mvaligursky Thank you!

@yaustar @Leonidas Replacing

var mesh = pc.createMesh (this.app.graphicsDevice, vertexData.positions,
{
    normals: vertexData.normals,
    uvs: vertexData.uvs,
    indices: vertexData.indices
});

with this:

var mesh = new pc.Mesh (this.app.graphicsDevice);
mesh.setPositions (vertexData.positions);
mesh.setNormals (vertexData.normals);
mesh.setIndices (vertexData.indices);
mesh.setUvs (0, vertexData.uvs);
mesh.update ();

basically solves this issue

3 Likes

Thanks for sharing @underlight! Good to know.

1 Like

Added ticket to track the need to update the tutorial: https://github.com/playcanvas/developer.playcanvas.com/issues/247

Many thanks @underlight!

1 Like