Transparency on a j3o model while retaining it's texture

I have made a model with texture in Blender, exported is as ogre mesh, and converting it to j3o in jMonkeyEngine SDK.

On other nodes/geometry i have managed to achieve transparency using a material with “Common/MatDefs/Light/Lighting.j3md” but when i do it on my j3o model it loses it’s texture.



I googled and found this but it didn’t seem to do anything: http://hub.jmonkeyengine.org/groups/graphics/forum/topic/rendering-meshesfaces-two-sided-obj/#post-108780

Hello!



If you’ve done it before I’m not 100% sure why it’s not working now. I’ve smacked the Oto.j3o model around with transparency before by using the diffuse alpha of it’s material.



[java]

ColorRGBA diffuse = (ColorRGBA) material.getParam(“m_Diffuse”).getValue();

diffuse.a = transparency;

[/java]



Only other things I can think of is to make sure you tossed the model into the Transparent render bucket and set the material’s blendstate to alpha as usual.



[java]

yourMaterial.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

yourModel.setQueueBucket(Bucket.Transparent);

[/java]



Oh, I did do this too when I was doing it:



[java]

golemMaterial.setColor(“m_Diffuse”, new ColorRGBA(1, 1, 1, 1));

golemMaterial.setBoolean(“m_UseMaterialColors”, true);

golemMaterial.setBoolean(“m_UseAlpha”, true);

[/java]



Probably need those too :stuck_out_tongue: Let us know how it turns out!



~FlaH

I’ll try that, thanks. Setting a material on my j3o model makes it lose it texture. And my other nodes/geometry doesn’t have a texture. That’s why I haven’t been able to set transparency on my j3o models. So I have not been able to use transparency on j3o models before as you seemed to think.



Is the the correct way to load a j3o model?

[java]Node playerNode = (Node) assetManager.loadModel(“Models/Player.j3o”);[/java]

I’m not sure how to get it’s material after that. playerNode.getChildren().size() returns 2. Should I change the material of those 2 childs?

I’m not 100% certain, but if that’s the case I think you can still get the material from the spatial and set parameters on it this way. No need to set a new texture to it. Pretty sure the loader defaults to using the Lighted.j3md definition so you can use the params from there.



~FlaH

This is my code right now

[java] playerNode = (Node) assetManager.loadModel(“Models/BallGuy.j3o”);

playerNode.setLocalScale(0.5f);



for(Spatial child : playerNode.getChildren()){

Material mat = ((Geometry) child).getMaterial();

((ColorRGBA) mat.getParam(“m_Diffuse”).getValue()).a = .5f;

mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

// mat.setBoolean(“m_UseMaterialColors”, true);

mat.setBoolean(“m_UseAlpha”, true);

}



playerNode.setQueueBucket(Bucket.Transparent);[/java]

And my model ingame looks just the same. When i uncomment mat.setBoolean(“m_UseMaterialColors”, true); i get this exception…

[java]java.lang.ClassCastException: java.lang.Boolean cannot be cast to com.jme3.math.Quaternion

at com.jme3.renderer.lwjgl.LwjglRenderer.updateUniform(LwjglRenderer.java:657)

at com.jme3.renderer.lwjgl.LwjglRenderer.updateShaderUniforms(LwjglRenderer.java:710)

at com.jme3.renderer.lwjgl.LwjglRenderer.setShader(LwjglRenderer.java:925)

at com.jme3.material.Material.renderMultipassLighting(Material.java:531)

at com.jme3.material.Material.render(Material.java:697)

at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:386)

at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:132)

at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:185)

at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:540)

at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:502)

at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:664)

at com.jme3.renderer.RenderManager.render(RenderManager.java:684)

at com.jme3.app.SimpleApplication.update(SimpleApplication.java:216)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:144)

at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:141)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:198)

at java.lang.Thread.run(Thread.java:619)

Java Result: -1073741819[/java]

I managed to solve the problem in a very spooky way… I think there is a bug somewhere in jME…



This code:

[java] MatParam mp = mat.getParam(“m_UseMaterialColors”);

System.out.println(mp.getName()+", “+mp.getVarType()+”, “+mp.getValue());

MatParam mp2 = mat.getParam(“m_Diffuse”);

System.out.println(mp2.getName()+”, “+mp2.getVarType()+”, “+mp2.getValue());

MatParam mp3 = mat.getParam(“m_DiffuseMap”);

System.out.println(mp3.getName()+”, “+mp3.getVarType()+”, "+mp3.getValue());[/java]

Gives this output:

[java]m_Diffuse, Vector4, Color[0.0, 0.621177, 0.8, 1.0]

m_Specular, Vector4, Color[0.5, 0.5, 0.5, 0.5]

m_UseMaterialColors, Boolean, true[/java]



So when i ask for “m_UseMaterialColors”. It returns “m_Diffuse”… I managed to set the transparency by doing it in reverse:

[java]mat.setColor(“m_UseMaterialColors”, new ColorRGBA(0.0f, 0.621177f, 0.8f, 0.5f));[/java]

This way my character became transparent. So the keys are linked to the wrong objects. I think this explains why i got my ClassCastException that i mentioned in my last post.