if ((node == null) || !(node.getChild(0) instanceof TexturedQuad)) {
logger.warning("can't find quad for view, unable to set transparency");
return;
}
final TexturedQuad quad = (TexturedQuad) node.getChild(0);
RenderUpdater updater = new RenderUpdater() {
public void update(Object arg0) {
WorldManager wm = (WorldManager) arg0;
BlendState as = (BlendState) wm.getRenderManager().createRendererState(RenderState.StateType.Blend);
// activate blending
as.setBlendEnabled(true);
// set the source function
as.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
// set the destination function
as.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
// disable test
as.setTestEnabled(false);
// activate the blend state
as.setEnabled(true);
// assign the blender state to the node
quad.setRenderState(as);
quad.updateRenderState();
MaterialState ms = (MaterialState) quad.getRenderState(RenderState.StateType.Material);
if (ms == null) {
ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
quad.setRenderState(ms);
}
if (ms != null) {
ColorRGBA diffuse = ms.getDiffuse();
diffuse.a = 1.0f - transparency;
ms.setDiffuse(diffuse);
} else {
logger.warning("quad has no material state, unable to set transparency");
return;
}
ColorRGBA color = quad.getDefaultColor();
color.a = transparency;
quad.setDefaultColor(color);
wm.addToUpdateList(quad);
}
};
WorldManager wm = ClientContextJME.getWorldManager();