[LibGDX] MeshBuilder "Too many vertices used"

I’m attempting to create some sort a voxel engine, and I am using LibGDX to help me. I want to create 16^3 chunks, so 24 vertices per cube at 4096 is 98,304 vertices to be used. However, when I try to build a single chunk mesh with the MeshPartBuilder class I get the error “Too many vertices used”. I took a look at the code, and it seems like you can only add Short.MAX_VALUE vertices, which I don’t understand because a short can’t hold THAT many values. Is there anyway to increase the number of vertices I can put into a mesh? Or am I doing something wrong?

This is my code (be aware I just started to look into the 3D API, so I don’t exactly know what I’m doing.):

ModelBuilder builder = new ModelBuilder();
		builder.begin();
		MeshPartBuilder mpb = builder.part("cubes", GL20.GL_TRIANGLES, (Usage.Position | Usage.Normal), new Material(ColorAttribute.createDiffuse(Color.WHITE)));
		for(int x = 0; x < noise.length; x++) {
			for(int y = 0; y < noise[0].length; y++) {
				float z = (int) (noise[x][y] * 16);
				mpb.box(x, z, y, 1, 1, 1);
			}
		}
		
		Model model = builder.end();
		
		instance = new ModelInstance(model);

Split it up into nodes, which can be children of a root model

Sorry, but can you provide an example of what you are talking about? Maybe psuedo code? Thanks!

A short can hold (Short.MAX_VALUE+1)*2 values.

Right, no unsigned variables in Java, forgot about that. My problem still remains, I simply can’t store all the vertices I need, and I don’t understand why.

Do you have the source code?

Have you tried reducing the amount of vertices in the model you’re building to below Short.MAX_VALUE? If that works then probably not.

First I would try to get a model working, I know you want more vertices, but there may be a hard limit in modelbuilder. If so then you have two options:

  1. ask them to increase the limit, assuming it’s not open source(I didn’t check to see and can’t find the website again)
  2. do what jrenner suggested.

Basically what he’s saying is you have a model, let’s say a humanoid.
You build arm 1 as a model, arm2, leg1, leg2, head, torso

Then you create a heirarchy for them
Torso
-Head
-Arm1
-Arm2
-Leg1
-Leg2

So torso contains all the other meshes, I wouldn’t do it like this per se(more like a container that holds a bunch of meshes), but I think it gets the idea across.

maybe it is related to

GL11.glDrawElements(target, num, indicesType, 0);

where indicesType can be [icode]GL11.GL_UNSIGNED_SHORT[/icode] or [icode]GL11.GL_UNSIGNED_INT[/icode] which caps the maximum length of the element array.

Is that a thing? I thought it was just the type you’re sending not the maximum length fo the array.

It caps* the size of the vertex array, not the index array.

*it doesn’t even cap the vertex array, as you can use offsets.

aye, that’s more correct. … i dont know the exact way of GDX draw issuing. just a guess.

putting something >short into a element buffer could cause such error.

o/

Thank you all. I was just looking for an explanation as to why the LibGDX team capped the vertex buffer at such a low value. I’m sure there’s some technical detail I am overlooking, so I’m just curious.