Occlusion material

Software: Away3D 4.x

Akaru, Newbie
Posted: 15 August 2013 01:43 PM   Total Posts: 4

Hi, I have problem with adding occlusion to material.
This is augmented reality project with face tracking. You can try on earrings.
Problem is with head object - in reality when you turn your face, one from earring is covered.
So for this case I use material occlusion attached to head mesh, but it dosent work :(
In onPostacComplete2 function I try do it - next step was adding alpha to head mesh. And then somthing is crash with background scene - is black (all object are including to contener3d object in away builder - it dosent open i prefabs now). Next problem I think is that something is wrong with this function :(
Maybe somebody have better solution for this case? See picture from application - it will be easier to understand my problem.

Embed (source="postac.awd", mimeType="application/octet-stream")]
private var postacAWD:Class;
                       
_postac = new Loader3D();
_postac.addEventListener(AssetEvent.ASSET_COMPLETE, onPostacComplete);

private function 
onPostacComplete(e:AssetEvent):void 
{
   
var glowa_mat:OcclusionMaterial = new OcclusionMaterial();
   
glowa_mat = OcclusionMaterial(AssetLibrary.getAsset('glowa'));
   
glowa_mat.occlude = true;
} 

Structure awd is >Container1>head_mesh
and head_mesh have material name ‘glowa’

In attachment is header object with

public class ScriptSampleMirrorCoord2D extends Sprite
 {
  
//AWAY3D
  
private var _view : View3D;
  private var 
_zegarek : Loader3D;
  private var 
_postac : Loader3D;
  private var 
_reka : Loader3D;
  
  private var 
postacCont :ObjectContainer3D;
  
  
// Text to display tracking values
  
protected var _infoTxt:TextField=null;
  protected var 
_myTextfor2DPose:TextField=null;
  
// Texture to display the webcam
  
protected var _captureBmp:Bitmap;
  
// To write the time in the log :
  
protected var _Date:Date = null;
  protected var 
myBitmap:BitmapData;
  protected var 
inter:interfejs;
  
  
[Embed (source="postac.awd", mimeType="application/octet-stream")]
  
private var postacAWD:Class;
  
[Embed (source="zegarek.awd", mimeType="application/octet-stream")]
  
private var zegarekAWD:Class;
  
[Embed (source="rekaaa.awd", mimeType="application/octet-stream")]
  
private var rekaaaAWD:Class;
  
  private var 
pngURLReq : URLRequest  = null;
  private var 
facing:Boolean = true;
  private var 
_poX:Number= 0;
  private var 
_poY:Number= 0;
  private var 
biblio:AssetLibrary;
  private var 
head_msh:Mesh;
  private var 
glowa:OcclusionMaterial;

  public function 
ScriptSampleMirrorCoord2D()
  
{
   
// Text creation
   
var infoTextFormat:TextFormat = new TextFormat(null, 20, 0xFF0000, true);
   
_infoTxt      = new TextField();
   
_infoTxt.selectable       = false,
   
_infoTxt.defaultTextFormat  = infoTextFormat,
   
_infoTxt.antiAliasType   = AntiAliasType.NORMAL,
   
_infoTxt.mouseEnabled   = false;
   
_infoTxt.autoSize    = TextFieldAutoSize.LEFT;
   
_infoTxt.x = 10;
   
_infoTxt.y = 10;
   
addChild(_infoTxt);
   
   
myBitmap = new BitmapData(512, 512,false, 0xff000000); 
   
   
// Text to display the 2D pos information
   
_myTextfor2DPose = new TextField();
            
_myTextfor2DPose.defaultTextFormat = new TextFormat(null, 18, 0xFF0000, true);
      
_myTextfor2DPose.text = "";
      
_myTextfor2DPose.x = 10;
        
_myTextfor2DPose.y = 20;
   
addChild(_myTextfor2DPose);
 
   
// Add a tracker
   
_tiTracker = new dafTracker();
   
addChild(_tiTracker);
   
   
_view = new View3D();
   
_view.camera.lens = new PerspectiveLens(60);
   (
_view.camera.lens as PerspectiveLens).fieldOfView = 54;
   
//_view.camera.
   
   //_tiTracker.getCameraFovX()
   
Loader3D.enableParsers(Parsers.ALL_BUNDLED);// Parsers.ALL_BUNDLED);
   
   
_zegarek = new Loader3D();
   
_zegarek.z = -40;
   
_zegarek.loadData(zegarekAWD);
   
   
_reka = new Loader3D();
   
_reka.scaleX = 11.6;
   
_reka.scaleY = 11.6;
   
_reka.scaleZ = 11.6;
   
_reka.x = -20;
   
_reka.loadData(rekaaaAWD);
   
   
_postac = new Loader3D();
   
_postac.addEventListener(AssetEvent.ASSET_COMPLETE, onPostacComplete2);
   
postacCont = new ObjectContainer3D();
   
_postac.loadData(postacAWD);
   
_postac.scaleX = 0.85;
   
_postac.scaleY = 0.85;
   
_postac.scaleZ = 0.85;
   
_postac.x = 300;
   
_postac.y = -300;
   
//_postac
   
   
addChild(_view);
   
postacCont.visible = false;
   
postacCont.addChild(_postac);
   
_view.scene.addChild(postacCont);
   
initCapture();
  
} 
  
  
/* is that working?
   * */
  
private function onPostacComplete2(e:AssetEvent):void 
  {
   
if (e.assetPrevName == 'glowa')
   
{
    glowa 
= new OcclusionMaterial();
    
glowa = e.asset as OcclusionMaterial;
    
glowa.occlude = true;
   
}
   
if (e.assetPrevName == 'head_msh')
   
{
    head_msh 
= e.asset as Mesh;
   
}
  }

  
protected function onEnterFrame(event:Event):void 
  {
   
// Update videoCapture texture
   
if (_videoCaptureLive)
   
_videoCaptureLive.update();
   
myBitmap.copyPixels(_captureBmp.bitmapData, new Rectangle(0, 0, 640, 480), new Point(0, 0));
   
_view.background = new BitmapTexture(myBitmap);
    
   
// Process tracking on current frame
   
var trackingData:Vector.<dafTrackerTargetData>=  _tiTracker.processTracking();
   
   if(
trackingData && facing == true)
   
{
   
....
}
_view
.render(); 

 

   

Avatar
80prozent, Sr. Member
Posted: 15 August 2013 09:19 PM   Total Posts: 430   [ # 1 ]

Hi

not shure i am understand you correctly…

all you want to do is to make the head transparent, so both earings can be seen all times ?

on thing about this function:

Embed (source="postac.awd", mimeType="application/octet-stream")]
private var postacAWD:Class;
                       
_postac = new Loader3D();
_postac.addEventListener(AssetEvent.ASSET_COMPLETE, onPostacComplete);

private function 
onPostacComplete(e:AssetEvent):void 
{
   
var glowa_mat:OcclusionMaterial = new OcclusionMaterial();
   
glowa_mat = OcclusionMaterial(AssetLibrary.getAsset('glowa'));
   
glowa_mat.occlude = true;
} 

this will be executed for each asset that is found in your file.
so the way you are doing it in the “onPostacComplete2”, would be the better option (checking for the name)....
you could also use the RESSOURCE_COMPLETE Event, instead of the ASSET_COMPLETE, as the RESSOURCE_COMPLETE is dispatched after all assets are loaded.

i am not shure about the occlusion-material as i never worked with it, but i think all you really need to do is turn the alpha of the head down to 0, so you can see trough it and see the background-video instead…
in awayBuilder there is no option to display a different background (yet)...

do not really understand the question, but hope this info helps a bit…

 Signature 

sorry…i hope my actionscript is better than my english…

   

Akaru, Newbie
Posted: 16 August 2013 12:09 AM   Total Posts: 4   [ # 2 ]

Thank you for your answer smile
I want to hide the earring by ghost head when head is rotating - I find sollution smile
In the ‘postac’ mesh were both objects - head and earing. I split them and use only for head:

occlusionMat = new OcclusionMaterial();
meshHead.material = occlusionMat; 

now is working

   

Avatar
80prozent, Sr. Member
Posted: 16 August 2013 12:17 AM   Total Posts: 430   [ # 3 ]

ah yes - that makes sense

cool you solved it

 Signature 

sorry…i hope my actionscript is better than my english…

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X