@pspeed said:
By definition, a batch = 1 geometry. 1 geometry = 1 material
ergo: changing the material parameter changes it for the whole mesh.
Actually the BatchNode automatically creates multiple geometries from multiple materials. @homsi: The same way, you have to know what vertices there are.
@homsi said:
and thats exactly my question how do I do that?
for quad I simply do something like
[java] Vector2f[] texCoord = new Vector2f[4];
texCoord[0] = new Vector2f(0, 0);
texCoord[1] = new Vector2f(0.1f,0);
texCoord[2] = new Vector2f(0,.1f);
texCoord[3] = new Vector2f(.1f,.1f);[/java]
You don't really need to get that complicated. You could use the same x for every texture coordinate and the same y since you aren't using real texture. Stretching one texel over the whole face is not a problem.
Find the geometry you want to change. Reset its texture buffer.
If you already tested RESETTING (note: not just setting the first time but changing it later) the texture buffer on a simple cube then it is exactly the same... or should be.
Find the geometry you want to change. Reset its texture buffer.
If you already tested RESETTING (note: not just setting the first time but changing it later) the texture buffer on a simple cube then it is exactly the same… or should be.
so I reset it:
[java] geom.getMesh().clearBuffer(Type.TexCoord);[/java]
then I want to re-set it to the blue part, how do I do that ??? thats the question :S i am sorry if i'm slow..
this will trigger an illegalArgumentException as my obj has more vertices than 4:
[java]geom.getMesh().setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(new float[]{0,0, 0,0.5f, 0.5f,0.5f, 0.5f,0}));[/java]
edit:
in fact my object has 80 vertices so even if I do that:
[java]
for(int i = 0; i < 80; i++)
{
texCoord = new Vector2f(0, 0);
}
Geometry geom = (Geometry) mySpatial;
geom.getMesh().clearBuffer(Type.TexCoord);
geom.getMesh().setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
[/java]
I still get the same error. of course I would not want to do that as I have different types of shelves with diff amount of vertices
:facepalm: As he said, set all 240 vertices to the same coordinate… the things you don’t immediately get in the answers is not some background noise. After you have understood one thing, read the other answers again.
@tumaini your code makes perfect sense. I had a bg confusion in textures buffers and now I got it figure out however why would the follwoing code not work to change the color of a batched geom after the batch?
I believe that the actual batched geometries aren’t shown (CullHint.Always), but are still kept so you can manipulate them.
The shown mesh is the one (if you have one material) that is the result of combining the meshes of the batched geometries (it’s a separate mesh). Perhaps a change to the TexCoord buffer for the original meshes won’t be automatically reflected in the batch mesh?
You might try detaching the geometry, changing the TexCoord buffer, then reattaching and batching again, to see if there is any difference, but as pspeed notes, a test case would make it clearer what might be wrong.
@tumaini detaching and reattaching from BatchNode defies the purpose for me using a Texture Atlas file. I did that specifically not to deatach and attach.
No it doesn’t, as I said, if you map the textures beforehand you can add them to the batch with the same material. So in blender, create multiple boxes. Then set the texture coordinates of each box to point at different locations in the map. When you then load such a box (or any other model created this way) and add it to a batch with the others it will batch with them when you set the same material.
Nope, you changed the mesh of the geometry (which isn’t used when the geometry is in the batch), you didn’t add anything to the batch. Sorry, I’ll stop answering now, you’re in way over your head and this is becoming a fulltime teachers job.
I was wrong on one point. 0 is not the same as 1. But 50 is the same as 1. As is 2, 3, 4, 5, 6, 7, 8, 9, 10, etc.
Texture coordinates are from 0-1 unless you want repeating patterns… but if you have a texture that is 512 pixels wide then pixel 0 is texture coordinate 0, pixel 512 is texture coordinate 1, pixel 256 is texture coordinate 0.5 and so on.
So while this may not be why your color doesn’t change it will mess you up later, for sure.