I tried to add texture to a basic Mesh (4 points), but I coulnd’t succeed, here is my code :
[java]this.mD = new Mesh();
this.positionD = new Vector3f[4];
this.positionD[0] = this.objectToMove.get(0).getPos();
this.positionD[1] = this.objectToMove.get(1).getPos();
this.positionD[2] = this.objectToMove.get(2).getPos();
this.positionD[3] = this.objectToMove.get(3).getPos();
int[] indices = {0,1,1,3,3,2,2,0};
Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(0,0);
texCoord[1] = new Vector2f(1,0);
texCoord[2] = new Vector2f(0,1);
texCoord[3] = new Vector2f(1,1);
this.mD.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(this.positionD));
this.mD.setBuffer(Type.Index, 1, indices);
this.mD.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
this.mD.updateBound();
this.mD.updateCounts();
Material mat = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat.setColor(“Color”, ColorRGBA.Yellow);
this.gridGeometry = new Geometry(“GridDebris”, this.mD);
this.gridGeometry.setMaterial(mat);
this.gridGeometry.setIgnoreTransform(false);
rootNode.attachChild(this.gridGeometry);[/java]
But if I add :
[java]this.mD.setMode(Mesh.Mode.Lines); //this.mD.setLineWidth(2f);[/java]
It draw the mesh with the Lines, so I guess my mesh is good, I just don’t succeed to add the texture.
Hi I finally find the solution for my problem : The indices was completly wrong, I put : int[] indices = {1,0,3,0,2,3}; and it was Ok.
But is there another solutions to define the triangles of the Mesh, In the future I’ll have Mesh with more than 4 points and I don’t know their position.
The indexes are telling OpenGL the order of the shared vertexes for each triangle. What is the issue? You don’t have to create a mesh with an index buffer but it’s almost always more efficient since it’s the only way to share vertexes.
Without the indexes I can’t apply texture to my Mesh. But my question was more how to define the indexes when I don’t know the coordinates of my point ?
I will specify my problem, I have several points and I want to draw a surface passing by all the points, I don’t see how to define the indexes in that case.
@aprouzeau said:
Without the indexes I can’t apply texture to my Mesh. But my question was more how to define the indexes when I don’t know the coordinates of my point ?
You need to read more about meshes I think. Indexes have nothing to do with texture coordinates. Texture coordinates (Type.TexCoord) have to do with texture coordinates. You can have texture coordinates without indexes.
If you have 400 vertexes in your mesh (Type.Position) then the index buffer says how to make triangles out of them. (Type.Index) So 0, 1, 2 says ‘make a triangle from vertexes 0, 1, and 2’.
Ok I get this now, but how define the index in order to draw a surface passing by all the points defined ? Knowing the fact that I don’t know the coordinates of the points when I write the code.
@aprouzeau said:
Ok I get this now, but how define the index in order to draw a surface passing by all the points defined ? Knowing the fact that I don’t know the coordinates of the points when I write the code.
This is starting to feel kind of like a “How do I inject something right into my stomach?” sort of conversation (*). You have already ended up at some strange end place when chances are there were earlier choices to make that would make it a non-issue. Unfortunately, we don’t know what those decisions are. So the short answer is “math”.
(*) Conversation goes like this: (It’s a metaphor for about 30% of the threads here)
Q: “How do I inject something right into my stomach?”
R1: “You’re going to need a big needle!”
R2: “What?!? Why do you want to do such a thing?”
R3: “Make sure you use lots of antiseptic!”
Q: “Guys, I don’t understand why it’s so tough. I’ve seen this done all the time before.”
R1: “Maybe you should ask them how they did it.”
R2: “Wait, what is it that you want to inject in your stomach anyway.”
Q: “Food!. Duh. What else would I put in my stomach?!?”
R1: “Have you looked into ‘eating’ at all?”
Q: “Do I look stupid?!? What does a mouth have to do with my stomach?!?”
R1: “You should read some documentation on ingestion…”
TL;DR: if you are struggling with how to do something it is best not to assume anything about what led you there. When you ask for help, include all of the information.
@pspeed said:
This is starting to feel kind of like a "How do I inject something right into my stomach?" sort of conversation (*). You have already ended up at some strange end place when chances are there were earlier choices to make that would make it a non-issue. Unfortunately, we don't know what those decisions are. So the short answer is "math".
(*) Conversation goes like this: (It’s a metaphor for about 30% of the threads here)
Q: “How do I inject something right into my stomach?”
R1: “You’re going to need a big needle!”
R2: “What?!? Why do you want to do such a thing?”
R3: “Make sure you use lots of antiseptic!”
Q: “Guys, I don’t understand why it’s so tough. I’ve seen this done all the time before.”
R1: “Maybe you should ask them how they did it.”
R2: “Wait, what is it that you want to inject in your stomach anyway.”
Q: “Food!. Duh. What else would I put in my stomach?!?”
R1: “Have you looked into ‘eating’ at all?”
Q: “Do I look stupid?!? What does a mouth have to do with my stomach?!?”
R1: “You should read some documentation on ingestion…”
TL;DR: if you are struggling with how to do something it is best not to assume anything about what led you there. When you ask for help, include all of the information.
You are right, I was doing this in the wrong way. I follow your explanation about the triangles and I decided to use a Delaunay Algorithm. Thank you for your help.