How to make an object Semitransparent?

Can I make the model semitransparent like Red Alert 3. When you select the place to build, the model of the building is semitransparent and you can both see the ground and the building’s model.

Yes.

An example:

		final Box b = new Box(1, 1, 1);
		final Geometry geom = new Geometry("Box", b);
		final Material mat = new Material(assetManager,
				"Common/MatDefs/Misc/Unshaded.j3md");
		mat.setColor("Color", new ColorRGBA(0, 1, 0, 0.50f));
		mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
		geom.setMaterial(mat);
		geom.setLocalTranslation(0, 5, 0);
		rootNode.attachChild(geom);

(Hope your Application becomes a Touhou Doujinshi <3
Should my also. This scene should become the Hakurei jinja)

3 Likes

Thanks a lot this is useful
!

1 Like

public static void setTransparent(Geometry geometry,float alpha)
{
Material material = geometry.getMaterial();
if(material.getParamsMap().containsKey(“BaseColor”))
{
material.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
material.getParam(“BaseColor”).setValue(new Vector4f(1f,1f,1f,alpha));
material.setTransparent(true);
geometry.setQueueBucket(RenderQueue.Bucket.Transparent);
}
}