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();