How to get indexbuffer?

Hi, i have a pretty complex mesh called Superellipsoid which is rendered through a bunch of functions. Since it is nearly (or completely) impossible to manually define the index buffer, i just used triangle mesh which doesnt need to have an explicitly defined buffer (or maybe im wrong, summa summarum: i didnt define the indexbuffer). Later in a method i have to get the indexbuffer of the mesh, but when i call mesh.getIndexBuffer() it returns null. Is it possible somehow to get it’s indexbuffer?

something like:

[java]IntBuffer ib = (IntBuffer)mesh.getBuffer(Type.Index).getData();[/java]

Still getting null :S its like theres no indexbuffer for the mesh…is it possible?

oO If you “cannot” set the index buffer manually how did you manage to create the vertex data? ^^ Did you read the custom meshes tutorial? This is normal opengl meshes, it seems you didn’t quite get the purpose of the index buffer yet?

I did read it. Heres and older topic where i got some problems with the indices: http://hub.jmonkeyengine.org/groups/graphics/forum/topic/rendering-superellipsoids/

I removed the setIndexBuffer line, and set TriangleMesh and its working, but now i get null for getIndexBuffer (because i didnt set it?)

@a-bedleg said:
I removed the setIndexBuffer line, and set TriangleMesh and its working, but now i get null for getIndexBuffer (because i didnt set it?)

That sounds pretty obvious, isn't it?
How would it be not null if you didn't set it?

Yeah, and that is my main problem, because now i should get the indexbuffer :S to be clear the thing i want to do is to render superellipsoids and then using CSG operations on them (union complement and intersection), so i tried to use this: http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/boolmesh-java-boolean-operations-on-mesh/?topic_page=1&num=15 which requires the indexbuffer at one point. I guess i just have to write my own class for those csg operations…gonna be a tough one :slight_smile:

… you generate that mesh yourself right? How come you are incapable to create the index buffer. I think you should read up on this and then rethink what you are doing.

Ok, i was able to create the indexbuffer, now im facing another problem, when i say:

int[] indices = index.array();

where index is an IntBuffer, i get an exception UnsupportedOperationException

It says that this exception occurs when “If this buffer is not backed by an accessible array”. Whats that mean exactly?

http://docs.oracle.com/javase/1.5.0/docs/api/java/nio/IntBuffer.html#array()

It simply means that the array() method is optional (also in the javadoc) and that you can not call it, i.e. not all Buffers implement such a method.

Also the index buffer is Direct and very often when a buffer is direct it doesn’t have a Backing array (not always).

You can check if it has a backing array though there is a hasArray method that returns a boolean.



If the array is direct you’ll have to use the Buffers get method that will populate your array. (it’s better to use this all the time because if the buffer has a backing array it will probably just do an arrayCopy of it in your array)