Auto-generate textures

Hi @all,



first much thanks from germany for this great project. We're using JME to visualize great software projects. At the moment the following scenario has to be solved:



We generate buildings at the scene with different properties. For example a building consists of multiple Spatials which represent a sequel of subversion modifications. So in the worst case a building consists of over 100s of modifications. To avoid the creation of lots of spatials i've tried to auto generate textures for these buildings representing the different author colors. For example fill buffer with red for author x and revision 1, with color blue for author y and revision 2 and so on and create image which can be set to a texture.



Is there an easy way to solve this problem without generating a BufferedImage and reconverting it?



Greets

oOMoeOo



PS.: Some kind of example code would be really helpful :wink:

The following doesn't work and results in SEVERE: GameTask.invoke()


ByteBuffer byteBuffer = ByteBuffer.allocate(10).order(ByteOrder.nativeOrder());
      IntBuffer colBuffer = byteBuffer.asIntBuffer();
      colBuffer.put(ColorRGBA.blue.asIntRGBA());
      colBuffer.put(ColorRGBA.blue.asIntRGBA());
      colBuffer.put(ColorRGBA.red.asIntRGBA());
      colBuffer.put(ColorRGBA.red.asIntRGBA());
      colBuffer.put(ColorRGBA.blue.asIntRGBA());
      colBuffer.put(ColorRGBA.blue.asIntRGBA());
      colBuffer.put(ColorRGBA.green.asIntRGBA());
      colBuffer.put(ColorRGBA.green.asIntRGBA());
      colBuffer.put(ColorRGBA.blue.asIntRGBA());
      colBuffer.put(ColorRGBA.blue.asIntRGBA());
      colBuffer.rewind();
      
      Image img = new Image(Format.RGBA32F, 1, 10, byteBuffer);
      
      TextureState ts = renderer.createTextureState();
      Texture texture = new Texture2D();
      texture.setImage(img);
       ts.setTexture(texture);
       ts.setEnabled(true);

Do you have to use Textures for this? if the color is to be solid you can use the Geometrys ColorBuffer directly. (one color per vertex) or if you split your buildings in seperate Geometries (one Geometry per modification) you can even set it like that:



modificationGeometry.setColorBuffer(null);
modificationGeometry.setDefaultColor(svnUser.getColorToUse());

Hi,



using the colorbuffer directly was my first idea too, but we had problems with using lighting and shading. Light sources had no effects for these objects. Now the use of textures works but the result doesn't look good - not anti aliased transitions from one color to another and so on.



Is there a way to use the color buffer and still see the right lightning?



We actually use cylinders as geometries but i need a possibility to use different textures for the cylinder wall, the top and bottom. Any ideas - maybe with color buffer too?

color buffer, or textureatlas are my guesses.



In your case then an atlas consistig of many one colourd blocks pixels, kinda like the color chooser in many apps.

Well, maybe the use of an atlas could be helpful, but how to define which data has to be used for top, bottom, walls? Is there any code to work with?

set texture coordiantes for the vertexes in their resepctive buffer

Well, Antialiasing is only done at Geometry borders. So what you can do is split your cylinders into N parts with different colors in the colorbuffer.

Yes, that would be the easiest way but doesn't work for our scenario. If there is a software system with 1000 classes overall and 200 modifications per class we have to build 200.000 geometries. And that's why i try to find another way to "emulate" these geometries. I think using textures is the fastest solution.