I am having an issue with a texture image showing up right in JME3 it worked fine in JME1. It is a rgb file. I have an image loader for rgb files. This particular file has 1 byte per channel 2 dimensions is 256 x 256 and has 2 channels. In JME1 I used the image format RA88. In JME3 I am using Format.Luminance8Alpha8. It is a black and white with Alpha. It is a helicopter wheel.
/home/onesaf/Desktop/Screenshot-heli_wheels_otw_normal_256.rgb-1.0 (grayscale, 1 layer) 256x256.png
In order to get it to show up properly in JME1 the code looked like this:
[java]if (faceMaterial != null) {
MaterialState ms = renderer.createMaterialState();
ms.setEnabled(true);
ms.setAmbient(faceMaterial.getAmbient());
ms.setDiffuse(faceMaterial.getDiffuse());
ms.setEmissive(faceMaterial.getEmissive());
ms.setSpecular(faceMaterial.getSpecular());
ms.setShininess(faceMaterial.getShininess());
ms.setMaterialFace(MaterialState.MF_FRONT_AND_BACK);
if(!isLit()){
ms.setColorMaterial(MaterialState.CM_AMBIENT_AND_DIFFUSE);
}
mesh.setRenderState(ms);
mesh.updateRenderState();
AlphaState as = renderer.createAlphaState();
as.setEnabled(true);
as.setTestEnabled(true);
as.setBlendEnabled(true);
as.setTestFunction(AlphaState.TF_GREATER);
as.setReference(0.3f);
as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
mesh.setRenderState(as);
mesh.updateRenderState();[/java]
Here is what I tried in JME3:
[java]ms = new com.jme3.material.Material(doc.assetManager, “Common/MatDefs/Light/Lighting.j3md”);
ms.setColor(“Ambient”, faceMaterial.getAmbient());
ms.setColor(“Diffuse”, faceMaterial.getDiffuse());
ms.setColor(“Specular”, faceMaterial.getSpecular());
ms.setFloat(“Shininess”,faceMaterial.getShininess());
ms.setTexture(“DiffuseMap”,faceTexture);
if(hasAlpha()){
ms.setTexture(“AlphaMap”,faceTexture);
ms.setBoolean(“UseAlpha”, true);
geometry.setQueueBucket(Bucket.Transparent);
ms.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
}
//use material color when it does not have a texture
if(hasFaceTexture() && !isLit()){
ms.setBoolean(“UseMaterialColors”, true);
}
geometry.setMaterial(ms);[/java]
Here is what it looks like:
/home/onesaf/Desktop/Screenshot-Model Viewer.png
What do I have wrong? I am thinking it has to do with the Test Function set to GREATER which JME3 doesn’t have the ability to change.
cut this part
if(hasAlpha()){
ms.setTexture(“AlphaMap”,faceTexture);
ms.setBoolean(“UseAlpha”, true);
geometry.setQueueBucket(Bucket.Transparent);
ms.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
}
and try to use
if(hasAlpha()){
geometry.setQueueBucket(Bucket.Transparent);
ms.setFloat(“AlphaDiscardThreshold”, 0.1f);
}
Nope that didn’t work.
Can you show us your RGB loader code? Also, why aren’t you using the many other formats that jME3 supports?
hazmat submitted the RGBloader I wrote under this post:
http://hub.jmonkeyengine.org/groups/contribution-depot-jme3/forum/topic/rgba-rgb-sgi-attr-int-image-loader/
We are contractors for the government and have to work under their specifications which include OpenFlight models.
I have changed the format to RGBA for an image with two channels so that the first byte goes into red and the last byte into alpha and filled in the rest with 0. It comes in right except the wheel is red see below. It makes me wonder if the order for the Luminance8Alpha8 needs to be alpha first then color.
I figured out that if I format it as an RGBA8 and copy the first byte into the R, G, and B then the last byte into the alpha it works. I don’t really like this resolution.
His loader is broken, it fails to handle grayscale images correctly. See below:
[java]if (zSize == 1) {
// Black and White image
// JME does not have an image format for black and white
// using the same as zSize = 2
imageType = Format.Alpha16;
newSize = 2;
} else if (zSize == 2) {
// Black and White image with alpha
imageType = Format.Alpha16;
} else if (zSize == 3) {
// RGB Image
imageType = Format.RGB8;
} else if (zSize == 4) {
// RGBA Image
imageType = Format.RGBA8;
} else {
throw new IOException("Unsupported options in file");
}[/java]
Grayscale and grayscale images with alpha are loaded as 16 bit alpha, which is incorrect. It should be luminance8 and luminance8alpha8
Yes thats what I have been working on but a grayscale model with alpha doesn’t work with luminance8alpha8 either. I figured out that if I load the first byte evenly across the RGB and then the second byte as the alpha and format as a RBGA8 it works but I don’t understand why the luminance8alpha8 doesn’t work. I will put the new RGB loader out there if I ever figure it out. A grayscale without alpha does work with luminance8 though.
Turns out it was a bug in jME3.
The Luminance8Alpha8 and couple of other formats that were failing, I committed a fix to SVN. Thanks.