How to use AlphaMaskMethod

Software: Away3D 4.x

Avatar
Raul Jimenez, Newbie
Posted: 23 September 2013 09:57 AM   Total Posts: 2

Hi all,

I’m want to apply an opacity texture, I don’t know if this is possible in Away3D but as far as I know maybe I could do it with an AlphaMaskMethod.

I tried to with an AlphaMaskMethod but it’s not working, I don’t know if I’m doing anything wrong.

This is my code:

armorMaterial = new TextureMaterial(new BitmapTexture(new ArmorDiffuse().bitmapData));
armorMaterial.specularMap = new BitmapTexture(new ArmorSpecular().bitmapData);
armorMaterial.normalMap = new BitmapTexture(new ArmorNormal().bitmapData);
armorMaterial.lightPicker lightPicker;
armorMaterial.specular 0.5;
armorMaterial.ambient 0.5;
armorMaterial.smooth true;
armorMaterial.gloss 80;

var 
alphaMethod:AlphaMaskMethod = new AlphaMaskMethod(new BitmapTexture(new ArmorOpacity().bitmapData), true);
armorMaterial.addMethod(alphaMethod); 

Also I’ve attached the opacity texture that have been prepared for me.

 

 

   

Lexcuk, Newbie
Posted: 24 September 2013 08:33 AM   Total Posts: 17   [ # 1 ]

I’d like to now how to use AlphaMaskMethod.
You see it’s huge black edges on leaves. it’s png and

branchMat.alphaThreshold 0.01

So I made a texture with green color and texture with alpha channel, I though if texture all green with no other color pixels so my leaves can only bee green, and with alpha mask, it’s beautiful and pleased, with no black edges, but unfortunately AlphaMaskMethod did not work for me, and no any little example i can not found.

Simple test

package  
{
   import away3d
.animators.*; import away3d.core.partition.*; import away3d.events.*;
   
import away3d.cameras.lenses.*;import away3d.core.base.*;import away3d.core.math.*;
   
import away3d.library.assets.*; import away3d.debug.*; import away3d.cameras.*;
   
import away3d.containers.*; import away3d.entities.*; import away3d.lights.*;
   
import away3d.materials.*; import away3d.materials.lightpickers.*;import away3d.materials.methods.*; 
   
import away3d.primitives.*; import away3d.textures.*;import away3d.filters.*;
   
import away3d.materials.utils.*;import away3d.primitives.data.*;
   
   
import flash.display.*;import flash.events.*;import flash.system.*; 
   
import flash.ui.*;import flash.utils.*;import flash.sampler.*; 
   
import flash.net.*;import flash.media.*; import flash.net.*; 
   
import flash.external.*;import flash.text.*;import flash.geom.*;
 
 
import flash.utils.*;
 
import mx.graphics.codec.*;
 
/**
  * ...
  * @author Lexcuk
  */
 
public class AlphaMaskTestDoc extends Sprite
 {
  
private var view:View3D;
  public function 
AlphaMaskTestDoc() 
  
{
   view 
= new View3D();
   
addChild(view);
   
   
view.antiAlias 4;
   
//setup the camera
   //trace('view.camera.lens.far ' + view.camera.lens.far);
   
view.camera.lens.far 60000;
   
view.camera.view.camera.0;
   
view.camera.300;
   
   
trace('hello AlphaMaskMethod');
   
   
view.camera.lookAt(new Vector3D(0,0,0));
   
view.backgroundColor 0xFFFFFF;
   
   var 
orangeBitmap:BitmapData = new BitmapData(256256false0x00FF00);
   var 
cubeMaterial:TextureMaterial = new TextureMaterial(new BitmapTexture(orangeBitmap), truetruetrue);
   
   var 
s:Sprite = new Sprite();
   
s.graphics.beginFill(0x0000001);
   
s.graphics.drawRect(00256256);
   
s.graphics.drawEllipse(1002560,90);
   
//addChild(s);
   
var alphaBitmap:BitmapData = new BitmapData(256256true0x00000000);
   
alphaBitmap.draw(s);
   
//addChild(new Bitmap(alphaBitmap));
   
   
var alphaMaskMethod:AlphaMaskMethod = new AlphaMaskMethod(new BitmapTexture(alphaBitmap), false);
   
cubeMaterial.addMethod(alphaMaskMethod);
   
   var 
cubeGeometry:CubeGeometry = new CubeGeometry(100100100111true);
   var 
mesh:Mesh = new Mesh(cubeGeometrycubeMaterial);
   
view.scene.addChild(mesh);
   
addEventListener(Event.ENTER_FRAMEenterFrameHandler);
  
}

  
private function enterFrameHandler(e:Event):void {
   view
.render();
  
}

 }

I see black square instead of green circle. How to do right thing with AlphaMaskMethod?

 

   

Avatar
Raul Jimenez, Newbie
Posted: 25 September 2013 08:31 AM   Total Posts: 2   [ # 2 ]

At the end I made a PNG with transparency and it worked like a charm smile

Hope it helps.

 

   

Lexcuk, Newbie
Posted: 25 September 2013 10:32 AM   Total Posts: 17   [ # 3 ]

I try png and

roadSideMat.alphaBlending true

But it’s seriously broken my z-sort

I made my own materials it’s look like AlphaMaskMethod

var alphaBitmap:BitmapData LexTextureMaterial.getOnlyAlphaBmd(pngBmd);
var 
noAlphaBmd:BitmapData LexTextureMaterial.getBmdWithoutAlpha(pngBmd
0x00FF00//default no alpha color
);

branchMat = new LexTextureMaterial(new BitmapTexture(noAlphaBmd), 
new 
BitmapTexture(alphaBitmap), 
new 
Vector3D(0.50.50.5), //color ambient (r=0..1,g=0..1,b=0..1)
new Vector3D(0.30.30.3), //lightA (0..1,0..1,0..1)
new Vector3D( -0.3, -0.3, -0.3), //lightB (0..1,0..1,0..1)
0.3 //alphaTreusold
);
//no need lightPicker
//no need param alphaTreusold, it's always True 

And z-sort if fine and no black edges, actually i can now choice color of last one.

 

File Attachments
LexTextureMaterial.zip  (File Size: 4KB - Downloads: 199)
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X