Hello guys, its me again
I would like to divide my model in subregion and detect which area is hit by mouse clicking. First time i thinking about collision boxes. But subregions are not allowed to be no overlap BUT they must cover it all. (therefore be partitioned)
My second thought to make two textures for model, some real (displayed) and one other at Background which is inked for different areas.
Now I have been looking for ways to get the color from the collisions point.
But I haven’t found a easy way.
So I fetched the collision triangle of model.
int triindex = closest.getTriangleIndex(); // triangle contactpoint match
Geometry Model = closest.getGeometry(); //geometrie contactpoint match point
System.out.println("closest Objeckt" +Model.getName());
MatParamTexture texture = Model.getMaterial().getTextureParam("ColorMap");
VertexBuffer textureBuffer = Model.getMesh().getBuffer(Type.TexCoord);
VertexBuffer positionBuffer = Model.getMesh().getBuffer(Type.Position);
VertexBuffer color2Buffer = Model.getMesh().getBuffer(Type.Color);
IndexBuffer ib = Model.getMesh().getIndicesAsList();
But if I do something with color2Buffer like the follow, I get an display error
[Uncaught exception thrown in Thread[LWJGL Renderer Thread,6,main]java.lang.NullPointerException]
System.out.println("colorbuffer id: " +color2Buffer.toString());
Thus i tryed the following:
FloatBuffer textureFloatBuffer = (FloatBuffer) textureBuffer.getData();
FloatBuffer positionFloatBuffer = (FloatBuffer) positionBuffer.getData();
// aquire triangle's vertex indices
int vertIndex = triindex * 3; // compute verticies of the mesh (triindex number of triangle) *3 number of points
// indices of index list
int vertindex1 = ib.get(vertIndex); //1. triangle edge
int vertindex2 = ib.get(vertIndex + 1); //2. triangle edge
int vertindex3 = ib.get(vertIndex + 2); //3. triangle edge
// coordinats of edges
Vector3f px1 = new Vector3f();
Vector3f px2 = new Vector3f();
Vector3f px3 = new Vector3f();
// Updates values px of the given vector from positionFloatBuffer at vertext indeces.
BufferUtils.populateFromBuffer(px1, positionFloatBuffer, vertindex1);
BufferUtils.populateFromBuffer(px2, positionFloatBuffer, vertindex2);
BufferUtils.populateFromBuffer(px3, positionFloatBuffer, vertindex3);
// same for texture coordinats
final Vector2f tx1 = new Vector2f();
final Vector2f tx2 = new Vector2f();
final Vector2f tx3 = new Vector2f();
BufferUtils.populateFromBuffer(tx1, textureFloatBuffer, vertindex1);
BufferUtils.populateFromBuffer(tx2, textureFloatBuffer, vertindex2);
BufferUtils.populateFromBuffer(tx3, textureFloatBuffer, vertindex3);
Texture tex = texture.getTextureValue();
Image img = tex.getImage(); // returns the image data that makes up this texture.
List imgd = img.getData();
int size = imgd.size();
System.out.println("list buffer: " +size); // returns 1
// so i get only one ByteBuffer to use, from image
ByteBuffer imgbytebuffer = imgd.get(0);
//but why can I get the 4 color values from it (at right position)?
//the following returns for all the same value
float alpha = imgbytebuffer.get() / 255f;
float blue = imgbytebuffer.get() / 255f;
float green = imgbytebuffer.get() / 255f;
The ByteBuffer imgbytebuffer have only one index and i get only 4 equal values from it
But I have no idea, what can I make else.
In the tutorials I only read how can I set the color, never how can I get the color
If anyone could help, I would be very happy (maybe the @Pesegato ?)
Other ideas to implement the concept are also welcome
Best regards and good night at all of you :}
EsKay.