Updating a vertex not working

I have a quick question. I’m using TexCoord8 to hold light source levels in my game. I have a bunch of objects that I break down into 4 chunks. I then batch the objects together using SimpleBatchNode.

Everything works great when I start, it finds all the torches (static, using this for lights). In the game when I need to place a new torch into the world. I need to update a few block (Forgot to mention, it is grid based, x and y + height, but reality is it is really flat) .

Is there an example of updating vertex buffer from time to time. So I can check it out.

What is the proper why of getting those TexCoord8 values updated. The shader does not see the changes.

If they are under a batch node then you need to let it know to rebatch the geometry when it changes.

Here is my loop for updating the batch nodes.

	public ArrayList<Node> mapChunkNodes;
....
	public void update(float tpf)
	{
           .....  (checking to see if an update is needed, check a variable. when
                    torch is place it calls to set update needed.
            if (updateneeded)
            {
					for (Node node : mapChunkNodes)
					{
						List<Spatial> spatials = node.getChildren();
						for (int pos = 0; pos < spatials.size(); pos++)
						{
							Spatial spat = spatials.get(pos);
							if (spat instanceof BatchNodeLB)
							{
								List<Spatial> batchSpats = ((BatchNodeLB) spat).getChildren();
								for(int batchPos = 0; batchPos < batchSpats.size(); batchPos++)
								{
									Geometry batchSpat = (Geometry) batchSpats.get(batchPos);
									Mesh mesh = batchSpat.getMesh();

//							        final VertexBuffer colorvb = mesh.getBuffer(VertexBuffer.Type.Color);
//							        if (colorvb != null)
//							        {
//								        final ByteBuffer colors = (ByteBuffer) colorvb.getData();
//								        colors.rewind();
//							            colors.putInt(ColorRGBA.randomColor().asIntABGR());
//							            colors.flip();
//							            colorvb.updateData(colors);
//							        }

									final VertexBuffer cvb = mesh.getBuffer(VertexBuffer.Type.TexCoord8);
									if (cvb != null)
									{
								        int numElements = cvb.getNumElements();
							       		final FloatBuffer lightLevel = (FloatBuffer) cvb.getData();

//							            // update data in vertex buffers
//							       		lightLevel.clear();
//							       		lightLevel.rewind();
//										
//							       		//Need to update the light level
							       		int newLightLevel = Utils.randn(0, 2);
System.out.println("num Elements "+numElements+"  new light level "+newLightLevel);							       		
							            for(int index =0; index < numElements; index++)
							            	lightLevel.put(newLightLevel);
//							       		
//							            lightLevel.flip();
//							            
							            
							            cvb.updateData(lightLevel);
							            mesh.updateBound();
							            ((BatchNodeLB)spat).onTransformChange(batchSpat);

									}
								}
								
								((BatchNodeLB)spat).onGeometryUnassociated(null);
								((BatchNodeLB)spat).batch();
							} 
							else {
								
								System.out.println("Missing textCoord8 "+spat.getName());
								//								spat.addMatParamOverride(new MatParamOverride(VarType.Float, "lighting", Utils.randf(0.1f, 1f)));
							}
						}
					}
					
				}
               }
}

got it worked out.

What was the solution? Something that would be helpful for others or something specific to your BatchNodeLB subclass or something?

I cleared my array of batched nodes.
I just loop through the torches in the world to determine position, and then got the surrounding grids and update the texcoord8 variable with the new light level for each spatial. Then called batch again, but I made sure to call zoneNode[x].onGeometryUnassociated(null);. to force the rebuild of the batch.

Now it is time to optimize this. Find which chunk needs updating and just update that one only, instead of the whole world. Also, find a way to optimize torch removal. Right now it only updates spatial based on the area to a torch, if I remove a torch, the light stays because it doesn’t update it. It only updates area close to the torch. The loop is based on the torch and then getting grid coords based on torch grid coords.

Thinks of keeping an old copy, looping through that to erase light levels and then grab the new torch array and then go through the process.