Using alpha transparency to change color?

Software: Away3D 4.x

abpyles, Newbie
Posted: 31 October 2013 01:44 AM   Total Posts: 4

I have searched the forums for the answer to this question, but have not found anything like it. I was wondering would it be possible to use alpha transparency to change the color of a bitmap/material. In other words instead of rendering transparent pixels as either transparent or black is there some way that transparent pixels could be made to represent another color like blue or red? I have attached an image of my project. What I want is for the transparent pixels of the texture to be rendered as another color, which would allow for the color of the car to be changed without loading a different texture. Is this at all possible in Away3d?
Thanks in advance.

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 31 October 2013 08:11 AM   Total Posts: 669   [ # 1 ]

You can do this quite easily by manipulating the bitmapData used in the texture material.

When creating the bitmapData you can assign a color that will be used for transparent textures. To get even more control, for example if you wanted to add different numbers on the sides of each car, etc. you could make a Sprite with all your configurations and then use myBitmapData.draw(mySprite) to assign it to the material. After assigning, just remember to run yourTexture.invalidateContent() to force the textureMaterial to update.

Good Luck!!

   

Avatar
GoroMatsumoto, Sr. Member
Posted: 01 November 2013 01:52 AM   Total Posts: 166   [ # 2 ]

How about ColorMatrixMethod or ColorTransformMethod?
I’ve not used these class, but I expect these classes are for changing color
of a material.

Doc about ColorTransformMethod:
http://away3d.com/livedocs/away3d/4.1.1Beta/away3d/materials/methods/ColorTransformMethod.html

init:

ct = new ColorTransform(4,0,0,255,-255,-255);
ctMethod = new ColorTransformMethod();
ctMethod.colorTransform ct;
material.addMethod(ctMethod); 

update:

ct.redMultiplier newRMul;
ct.greenMultiplier newGMul;
ct.blueMultiplier newBMul;
ct.redOffset newROffset;
ct.greenOffset newGOffset;
ct.blueOffset newBOffset

I’ve not used this class, and I’ve not tested this code.
But I think that above is not so far for working correctly.

Good luck.

Edit:
I tested this code. And this way is not so good for changing the color.
Because it change texture color, but it change shading color also.
Use @theMightyAtom’s way or ColorMaterial instead of TextureMaterial.

 

   

abpyles, Newbie
Posted: 01 November 2013 04:04 AM   Total Posts: 4   [ # 3 ]

Thanks for the help. I got it working using theMightyAtom’s method smile Again, thanks for the help guys.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X