Texture Shape3D - "Alpha Transparency "not working

Hi All,
I’m quiet new to java3D…but I’ve been trying my best to learn some of the main things. One thing I can’t seem to get to work, not matter what I seem to change is the Alpha value…I’ve loaded a texture and applied it to a shape, but wnat to set it to 20% transparent…or partially transparent so I can see through it.

I’ve set the shape3d appearance to use a transparencyAttribute, but I’m not sure if it has to be done in a specific order, or if something else in the code has to be set up…do I have to force the texture to be a texture2d?..any ideas or snippets or anything to fix this would be great.

I’ve put my main code below that does the shape texture and alpha values together before adding them to the child list.

Thanks,

Ben


        //Load and set texture if the object is textured
        Appearance app = null;
		{
			System.out.println("tex filename: " + m_fullTexPathName);
			
			app = new Appearance();
			
			TextureLoader loader = new TextureLoader(m_fullTexPathName, null);
			//TextureLoader loader = new TextureLoader(m_fullTexPathName,Texture.RGBA, null);

			Texture texture = loader.getTexture();
			app.setTexture(texture);

			TextureAttributes texatt = new TextureAttributes();
			texatt.setTextureMode(TextureAttributes.REPLACE);
			app.setTextureAttributes(texatt);
		}
        
        
        TransparencyAttributes ta;
        ta = new TransparencyAttributes();
		ta.setTransparencyMode(TransparencyAttributes.BLENDED);
		ta.setTransparency(0.15f);
        app.setTransparencyAttributes(ta);
        
        
        Shape3D shape = new Shape3D(m_triangleArray, app);
        
		
        
        m_tg.addChild(shape);
		m_tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

Far too long since I’ve used this a lot to make a detailed call and I’m too lazy to start up one of my applications that is lying around but looking at your code I’m wondering if it could it be something to do with using TextureAttributes.REPLACE ? Perhaps you want to Combine with the underlying appearance rather than replacing it altogether with the texture?

Yes I think you need to set the right mode. I vaugely remember running into this myself. I think it might be “modulate”

Fantastic!

Well I modified the code to get the appearance, also tried setting replace…but setting it to MODULATE got it to work in the end :slight_smile:

Modulate was what I was missing…sure I tried it before…but I tried so many different things, guess I might have missed this one…well great stuff…finally works…spent hours reading about on the net about it…but just couldn’t get it to work…just made up now…

Thanks everyone…just brilliant.

Ben


        Shape3D shape = new Shape3D(m_triangleArray, app);
        
        Appearance shapeApp = shape.getAppearance();
        
        TransparencyAttributes ta;
        ta = new TransparencyAttributes();
		ta.setTransparencyMode(TransparencyAttributes.BLENDED);
		ta.setTransparency(0.50f);
		shapeApp.setTransparencyAttributes(ta);
		
		TextureLoader loader = new TextureLoader(m_fullTexPathName, null);
		Texture texture = loader.getTexture();
		shapeApp.setTexture(texture);

		TextureAttributes texatt = new TextureAttributes();
		texatt.setTextureMode(TextureAttributes.MODULATE);
		shapeApp.setTextureAttributes(texatt);