Broomstick: BitmapMaterial transparency

24 views
Skip to first unread message

0L4F

unread,
Jul 25, 2011, 8:31:19 AM7/25/11
to Away3D.dev
Hello all,

I've set up an Away3D - Flash IDE project. I'm using Sprites from the
Flash library to create BitmapMaterials for Planes in Away3D.

I'd really like the Sprite's transparencies (alpha channel) to show up
in the BitmapMaterials, but I can't seem to get it to work :(

Here's my code:

textSprite = new TextSprite(); // Sprite
object from the Flash libraty
matSprite = new BitmapMaterial(getBitmapData(textSprite));

//matSprite.transparent = true; // doesn't do the trick

matSprite.lights = [light1];

matSprite.diffuseMethod = new BasicDiffuseMethod();
matSprite.diffuseMethod.alphaThreshold = 0.5; // no
luck!


private function
getBitmapData(srcSprite:Sprite):BitmapData
{
var bmd:BitmapData = new BitmapData(srcSprite.width,
srcSprite.height);
var b:Bitmap = new Bitmap(bmd);
bmd.draw(srcSprite);
return(bmd);
}

I'd appreciate any hints / pointers! Thanks in advance,

0L4F

Fabrice3D

unread,
Jul 25, 2011, 8:37:57 AM7/25/11
to away3...@googlegroups.com
oops I see the method is beneath...
try change var bmd:BitmapData = new BitmapData(srcSprite.width, srcSprite.height);
by something like var bmd:BitmapData = new BitmapData(srcSprite.width, srcSprite.height, true, 0xFFFFFFFF);

and var b:Bitmap = new Bitmap(bmd); what is it for?

Fabrice

Fabrice3D

unread,
Jul 25, 2011, 8:35:22 AM7/25/11
to away3...@googlegroups.com
getBitmapData...
what is this method doing exactly?

Fabrice

On Jul 25, 2011, at 2:31 PM, 0L4F wrote:

0L4F

unread,
Jul 25, 2011, 8:55:00 AM7/25/11
to Away3D.dev
Fabrice, you rock!

var bmd:BitmapData = new BitmapData(srcSprite.width, srcSprite.height,
true, 0x00000000);

combined with

matSprite.transparent = true;

did the trick.


Thanks :)

0L4F

unread,
Jul 25, 2011, 9:00:03 AM7/25/11
to Away3D.dev
Ah, just a very simple method that receives a Sprite Object, and
returns the corresponding BitmapData.

var b:Bitmap = new Bitmap(bmd); is redundant code, whoops ;)

cheers,

0L4F

wagster

unread,
Aug 19, 2011, 5:15:46 PM8/19/11
to Away3D.dev
I'm still struggling with this one... here's my class


public class Floor extends Plane
{
public function Floor(floorMc:MovieClip, segmentsW:uint=1,
segmentsH:uint=1, yUp:Boolean=true)
{
var bitmapData:BitmapData = new BitmapData(2048, 2048, true,
0x00000000);
bitmapData.draw(floorMc);
var floorMaterial:BitmapMaterial = new BitmapMaterial(bitmapData,
false);
super(floorMaterial, floorMc.width, floorMc.height, 1, 1, true);
rotationX = 90;
trace();
}
}

Firstly, I would like to create a BitmapData object the same size as
the MovieClip, but Texture3DProxy throws a "size must be power of 2"
error unless I set both height and width to a power of two, so

new BitmapData(floorMc.width, floorMc.height, true, 0x00000000)

doesn't work.

Secondly, I can't set the BitmapMaterial to transparent = true as
suggested above - because BitmapMaterial doesn't have a transparent
property.

I'm trying to do much the same thing - draw a Sprite onto a plane and
show only the opaque parts of the Sprite.

Any ideas?

Cheers,

Wag

richardolsson

unread,
Aug 20, 2011, 9:14:22 AM8/20/11
to Away3D.dev
The properties for transparency are alphaBlending and alphaThreshold.
See a short explanation of them here:
http://groups.google.com/group/away3d-dev/browse_thread/thread/c62a6f8d8409b703/2c53be3228c4295a?show_docid=2c53be3228c4295a

Cheers
/R
Reply all
Reply to author
Forward
0 new messages