[solved] transparency-problem by importing *.obj/*.mtl respectively *.mesh.xml/*.material

hi guys,

I’m a newbie on the jmonkey-plattform… but “cpiesker” and I working on a big study-project. so he implements the logic of our “world” and I model that via 3ds max 2013, cause I have some skills with the IDE since the last 8 years.



now, we get a problem by importing the .obj/.mtl files in jme. the standard textures work fine and looks good, but we have got some glass objects.

the next image shows the situation in 3ds max:

3dsmax_view.png



and this is the “result” in jme:

jme_view.png



the problem is, that the transparency-effect is not adopted in jme. I search since 6-7hrs through the forum and “google”, but I do not found a solution. :expressionless:

so I take a look into the *.mtl-file and the material, which represents the glass effect:

[xml]newmtl glass_standard

Ns 10.0000

Ni 1.5000

d 0.4000

Tr 0.6000

Tf 0.4000 0.4000 0.4000

illum 2

Ka 0.5880 0.5880 0.5880

Kd 0.5880 0.5880 0.5880

Ks 0.0000 0.0000 0.0000

Ke 0.0000 0.0000 0.0000

map_Ka glass.png

map_Kd glass.png[/xml]



so as we can see: “d” resp. “Tr” is set and the given images are in the same directory.



We also try the way of export that with the ogre exporter… the same problem occurred. the *.material-file looks like this:

[xml]material glass_standard

{

technique

{

pass

{

ambient 0.588 0.588 0.588 1

diffuse 0.588 0.588 0.588 1

specular 0 0 0 1 10

scene_blend one one_minus_src_alpha



texture_unit

{

texture glass.png

}



texture_unit

{

colour_op_ex blend_manual src_manual src_current 0.4 1 1 1

colour_op_multipass_fallback dest_colour zero

alpha_op_ex source1 src_manual src_current 0.4

}

}

}

}[/xml]



Has anybody an idea or a solution or proposal for our project? :slight_smile:

If we solve that problem, I would create a tutorial which describes the hole process of create objects, texturing them and import them to jme.



Thanks a lot for reading… :slight_smile:

Greetz,

Eric

You have to place the transparent object in the transparent bucket,

Then you have to specify to the material to use Alpha blending

[java]

object.setQueueBucket(Bucket.Transparent);

object.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

[/java]

this is from memory, the methods names may be slightly different.

1 Like

Seems that the transparency detection in the OBJ / MTL loader is a little bit incorrect. I read the spec again and it seems that the “d” value specifies alpha always, regardless of shading mode. The shading mode (“illum”) just specifies if the material uses reflection / refraction or solid color, etc.

@nehon:

we load our j3o-object via asset manager:

[java]Spatial s = assetManager.loadModel(“Scenes/vTrainStation.j3o”);[/java]

so we don’t get a option called “getMaterial”… ?! any idea? or its the wrong way to include the object?



@momoko_fan:

so what we are doing now?



I try the transparency effect with a simple plane (ground) and a wall (plane), where a box is positioned in front of the wall. so we don’t see any transparency. the *.obj/ *.mtl resp. ogre export files look like above.

In Addtiion we have the following code:



[java] Spatial s = assetManager.loadModel("Scenes/vTrainStation.j3o");

s.setShadowMode(ShadowMode.CastAndReceive);

s.addControl(new RigidBodyControl(0));

s.setQueueBucket(Bucket.Transparent);



for(Spatial child : ((Node)s).getChildren())

{

if (child instanceof Geometry)

{

Geometry g = (Geometry) child;

g.setQueueBucket(Bucket.Transparent);

g.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

}



}[/java]



But this way doesn´t work.

don’t do that :

[java]

s.setQueueBucket(Bucket.Transparent);

[/java]

By default everything is in the Opaque bucket and rendered front to back with a depth test to avoid overdraw.

The transparent bucket is rendered back to front after the opaque bucket with a depth test also to make sure every thing behind transparent objects is rendered…

Putting the whole scene in the transparent bucket makes no sense, and is just gonna make your scene slower because of the overdraw.

Just pick the transparent objects and put them in the transparent bucket. The others have to stay in the opaque bucket.



The engine should detect this when you load the material file, it seems to be a bug as Momoko_Fan mentioned, my solution is just a workaround until it’s fixed.

and how does the workaround looks like? :slight_smile: ?



now we pick out the objects which should be transparent in the world. but it doesn’t work… :frowning:

Hi,



also we have change our code, but it doesn´t work. Our code:

[java]

Spatial s = assetManager.loadModel("Scenes/vTrainStation.j3o");

s.setShadowMode(ShadowMode.CastAndReceive);

s.addControl(new RigidBodyControl(0));



for (Spatial child : ((Node) s).getChildren()) {

if (child instanceof Geometry) {

Geometry g = (Geometry) child;

if (g.getName().equals("vTrainStation-geom-44") || g.getName().equals("vTrainStation-geom-22")) {

g.setQueueBucket(Bucket.Translucent);

g.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

}

}

}

[/java]

The material is that:

[java]

newmtl glass_standard

Ns 10.0000

Ni 1.5000

d 0.3000

Tr 0.7000

Tf 0.3000 0.3000 0.3000

illum 2

Ka 0.5880 0.5880 0.5880

Kd 0.5880 0.5880 0.5880

Ks 0.0000 0.0000 0.0000

Ke 0.0000 0.0000 0.0000

map_Ka glass.png

map_Kd glass.png

[/java]



I hope you can us, or we get an answer.

I’m not familiar with the material format tbh, but is seems that the transparency color is not properly set on your JME material.



first it’s Transparent bucket, not Translucent.



then try to do this for each transparent geom :

[java]

g.setQueueBucket(Bucket.Transparent);

g.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

g.getMaterial().setColor(“Diffuse”, new ColorRGBA(1.0f,1.0f,0.8f,0.5f);

g.getMaterial().setBoolean(“useMaterialColors”,true);

[/java]

That’s just a test

Now the test doesn´t work. That change nothing.



The following I tested, I have plan without a texture, than its works ( we have not the hole world with textures at the moment). If a texture on the plan then it doesn´t work.



But at thirst thanks for all, we have found our mistake. In the material data is our illum value 2 but for transparency it must be 4. A good site for the definitions are http://local.wasp.uwa.edu.au/~pbourke/dataformats/mtl/.

mhh not sure I understand, is it working now?

Yes, it is working now. Thanks, the problem is solved. The thread can be closed.