We want to trigger masks with the AR marker. So we have to be able to put a png image on a plane, this is the code:
private function addPlaneForMask()
{
var mat:BitmapFileMaterial= new BitmapFileMaterial(“textureMap/cross.png”);
_plane1 = new Plane(mat , 150, 160);
this._plane1.z = 20;
this._plane1.rotationX = 180;
this._baseNode.addChild(this._plane1);
}
then we want to change the image shown by the marker:
private function removeAndAddPlaneForMask()
{
this._baseNode.removeChild(this._plane1);
var mat:BitmapFileMaterial= new BitmapFileMaterial(“textureMap/otherImage.png”);
_plane1 = new Plane(mat , 150, 160);
this._plane1.z = 20;
this._plane1.rotationX = 180;
this._baseNode.addChild(this._plane1);
}
and if you call this last function by a timer then the marker get refreshed every time the timer fires:
var refreshMaskTimer: Timer = new Timer(2000);
refreshMaskTimer.addEventListener(TimerEvent.TIMER, removeAndAddPlaneForMask );
refreshMaskTimer.start();
You can get the next image by using a counter in a the name (String) of an image:
adding: private var imageNumberOfMask : Number =1;//with the other private vars
in the function removeAndAddPlaneForMask:
var imageName : String = “textureMap/” + String(imageNumberOfMask) + “.png”;
var mat:BitmapFileMaterial= new BitmapFileMaterial(imageName);
imageNumberOfMask = imageNumberOfMask + 1; //increasing the number of the image
of course then you have to take care the number of images becomes not to high, so:
if ( imageNumberOfMask > 37 ) imageNumberOfMask = 1; //restart at 1 if your number of masks is 37
Aucun commentaire:
Enregistrer un commentaire