primitives colour

Started by Mauri, April 07, 2012, 04:21:46 PM

Previous topic - Next topic

Mauri

Hi everyone,
first post here with a problem that probably is incredibly daft, but as I have just started out with both JPCT and android coding  I hope I will not get told off too badly for my question  :)
I want to visualise a model which is made of cubes and cylinders (1000+ cubes usually and cylinders, well I am not sure how many of them yet).
I am using the primitives to do this and I have been able, so far, to visualise the cubes just fine. However, when I try to add a solid colour to the cubes all I get is  grey cubes (the grey shade changes according to the ambient light), but there is no trace of the colour I wanted for my objects. This is what I have done:
public Object3D MakeCube(float size, float posX, float posY, float posZ, int red, int green, int blue) {

Object3D acube = Primitives.getCube(size);
RGBColor cubeColour= new RGBColor(red,green,blue);
acube.setAdditionalColor(cubeColour);
acube.rotateY(-(float) Math.PI/4f);
acube.rotateMesh();
acube.translate(posX, posY, posZ);
acube.translateMesh();
acube.strip();     
acube.build();

return(acube);
}


Where am I going wrong? thanks in advance for the replies.
Cheers.

EgonOlsen

What happens if you set the ambient color to (0,0,0)? Which values are you using when calling MakeCube?

Mauri

Thanks for your reply. This is the code I have and I tried ambient light from (0,0,0) , which made my cubes very dark grey to 250,250,250 which made them almost white
world = new World();
world.setAmbientLight(0, 0, 0);

sun = new Light(world);
sun.setIntensity(250, 250, 250);

the colour I have for the cubes at the moment is red=241 green =90 blue=43

EgonOlsen

No idea...which renderer are you using? OpenGL ES 1.1 or 2.0? If you set ambient to white (or almost), everything will be white no matter which additional color has been set, but if set to 0,0,0, the additional color should be fully visible. Could you try a getAdditionalColor() on one of the cubes and check that the returned values are actually correct!?

Mauri

Thanks again for your time.
The values returned by getAdditionalColor() are the correct ones for all cubes.
I am using OpenGL ES 1.1
Cheers

Mauri

OK I forgot to mention something that may be important here. I wanted all the cubes to rotate together, so after creating all the cubes i also merged them into a single Object3D with MergeAll()
Could it be that the color is lost when merging? and if so, is there a way to fix this?

EgonOlsen

Quote from: Mauri on April 07, 2012, 06:29:26 PM
Could it be that the color is lost when merging? and if so, is there a way to fix this?
Yes, that's the problem. Additional color is per object. If you merge them, you'll lose this information. You can set a new additional color to your merged object, but i'm not sure if that's what you want in this case. You might want to try to use colored textures (can be created using http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Texture.html#Texture(int, int, com.threed.jpct.RGBColor)) instead. They will "survive" the merge, but this will force jPCT-AE to split the object internally, so the performance gain from merging them might not be as large as you expect it to be.

Mauri

Thank you.
Using coloured textures does indeed solve the colour issue, but the performance hit is massive.  I am trying now to build a 15x15x15 matrix of cubes. If I leave the coloured textures out of the code, all the cubes are drawn and the frame rate is a very happy 60fps. But if I include the textures (one per cube) only about 500 of the cubes are shown and the frame rate drops to about 17-20fps
mmmmm back to the drawing board for me then.
Thanks again!

EgonOlsen

If the cubes' textures have the same color, make sure to use the same texture instance so that jPCT can group them.

Another idea: Model your cubes in a 3D editor with proper u/v coordinates, use one texture that contains all the colors needed and use different cubes with different u/v coordinates for the different colors. If you merge that, it'll be compiled to one large chunk of data, because all cubes use the same texture.

Mauri

Unfortunately I cannot model the cubes with a 3D editor, since the idea of the android application is to generate dynamically the models  by reading info from XML files. However I think I can use one basic texture and generate the other textures only when and if needed. That would reduce the number of textures and should speed things up a bit.
Cheers