Hi there,
Been toying aroung with augmented reality, works fine, just this time i nee three different markers to do 3 different things, i am working with NYArToolkit, which recognizes 2 patterns properly, but when i set ujp the third one i get this error:
RangeError: Error #1125: The index 2 is out of range 2.
at org.libspark.flartoolkit.detector::FLARMultiMarkerDetector/initInstance()
at org.libspark.flartoolkit.detector::FLARMultiMarkerDetector()
at Tees_fla::MainTimeline/initialization()
I dont see what setting i need to change or maybe 3 are one too many for the vectors? or fo rthe memory? please enlight me
here is my code
// マーカーパラメータ初期化
this.markerPatternList = new Vector.<FLARCode>();
//this.markerPatternList.fixed = !fixed;
// マーカーのパターンファイル
this.markerPatternFileList = new Vector.<String>();
this.markerPatternFileList.push('pattern/V.pat',
'pattern/bbl.pat',
'pattern/heart.pat'
);
// マーカーの一辺の長さ(px)
this.codeWidthList = new Vector.<Number>();
this.codeWidthList.push( 80, 80);
// パラメータのロード
this.paramLoad();
//for (var j:int=0; j<markerPatternFileList.length; j++) {}
/**
* カメラパラメータを読み込み、変数にロード
*@return void
*/
function paramLoad():void
{
var mf:NyMultiFileLoader=new NyMultiFileLoader();
mf.addTarget(
cameraParamFile, URLLoaderDataFormat.BINARY,
function(data:ByteArray):void
{
cameraParam = new FLARParam();
cameraParam.loadARParam(data);
cameraParam.changeScreenSize(captureWidth, captureHeight);
});
// 分割数(縦・横)、黒枠の幅(縦・横)
var markerPatternCode0:FLARCode = new FLARCode(16, 16);
mf.addTarget( markerPatternFileList[0],
URLLoaderDataFormat.TEXT,
function(data:String):void
{markerPatternCode0.loadARPattFromFile(data);});
// 分割数(縦・横)、黒枠の幅(縦・横)
var markerPatternCode1:FLARCode = new FLARCode(16, 16);
mf.addTarget( markerPatternFileList[1],
URLLoaderDataFormat.TEXT,
function(data:String):void{
markerPatternCode1.loadARPattFromFile(data);});
// 分割数(縦・横)、黒枠の幅(縦・横)
var markerPatternCode2:FLARCode = new FLARCode(16, 16);
mf.addTarget(
markerPatternFileList[2], URLLoaderDataFormat.TEXT,
function(data:String):void
{markerPatternCode2.loadARPattFromFile(data);});
//ロード開始
mf.multiLoad();
markerPatternList.push(markerPatternCode0);
markerPatternList.push(markerPatternCode1);
markerPatternList.push(markerPatternCode2);
//終了後、初期化処理に遷移するように設定
mf.addEventListener(Event.COMPLETE, initialization);
return;
}
/**
* webカメラや表示、detectorの初期化
* @return void
*/
function initialization(e:Event): void
{
removeEventListener(Event.COMPLETE, initialization);
// setup ARToolkit
capture = new Bitmap(new BitmapData(vid.width, vid.height, false, 0),
PixelSnapping.AUTO,
true);
capture.bitmapData.draw( vid );
// ウェブカメラの解像度と表示サイズが異なる場合は拡大する
//capture.width = canvasWidth;
//capture.height = canvasHeight;
// キャプチャーしている内容からラスタ画像を生成
//this.raster = new FLARRgbRaster_BitmapData( this.capture.bitmapData);
raster = new FLARRgbRaster_BitmapData(capture.bitmapData);
// キャプチャーしている内容を addChild
//addChild(capture);
// setup Single marker detector
detector = new FLARMultiMarkerDetector(cameraParam,
markerPatternList,
codeWidthList,
markerPatternList.length
);
// 継続認識モード発動
detector.setContinueMode(true);
// しきい値調整
_threshold_detect=new FLARRasterThresholdAnalyzer_SlidePTile(15,4);
// 初期化完了
dispatchEvent(new Event(Event.INIT));
// 3Dオブジェクト関係の初期化へ
supportLibsInit();
// スタート
start();
}
/**
* 3Dオブジェクト関係の初期化
* 使用する3Dライブラリに応じてこの部分を書き換える。
*/
function supportLibsInit(): void
{
viewport3d = new Viewport3D(320, 240);
layerFlart.addChild(viewport3d);
viewport3d.x = -4; // 4pix ???
// シーンの生成
scene3d = new Scene3D();
// マーカーノード、マーカーデータの初期化とシーンへの追加
markerNodeList = new Vector.<FLARBaseNode>();
markerList = new Vector.<MarkerData>();
for (var i:int=0; i<this.markerPatternList.length; i++) {
markerList.push(new MarkerData(i));
markerList*.confidence = 0;
markerNodeList* = new FLARBaseNode();
scene3d.addChild(markerNodeList*);
}
// 3Dモデル表示時の視点を設定
camera3d = new FLARCamera3D(cameraParam);
// setup renderer
renderer = new LazyRenderEngine(scene3d, camera3d, viewport3d);
}
/**
* 3Dオブジェクト生成 create
function createObject(_lightColor:Number,_ambientColor:Number):DisplayObject3D
{// ライトの設定。手前、上のほう。
trace("pattern detected");
//trace ("creating object");
var light:PointLight3D = new PointLight3D();
light.x = 0;
light.y = 1000;
light.z = -1000;
var fmat:FlatShadeMaterial = new FlatShadeMaterial(light, _lightColor, _ambientColor);
_plane = new Plane(fmat, 140, 260);
_plane.x = 0;
_plane.y = 0;
_plane.z = 0;
_plane.rotationX =90;
_container = new DisplayObject3D();
// _container に 追加
_container.addChild(_plane);
return _container;
}
///_________________________FLARTOOL KIT STUFF
/**
* 3Dオブジェクトの生成と登録
* マーカーイベント方式を採用しているため、markerイベントを登録
* スレッドのスタート
*/
function start():void
{
// 3Dオブジェクト生成してMarker Node に追加
this.markerNodeList[0].addChild(this.createCube(0xFF0000, 0x660000));
this.markerNodeList[1].addChild(this.createObject(0x0000FF, 0x000066));
this.markerNodeList[2].addChild(this.createObject(0x0000FF, 0x000066));
// 処理開始
this.addEventListener(Event.ENTER_FRAME, this.run);
}
/**
* ここでフレームごとに処理
* イベント方式での実装は、FLARManager で実装されているためここでは作らない。
*/
function run(e:Event):void
{
capture.bitmapData.draw(vid);
// Marker detect
var detectedNumber:int = 0;
try {
// Single Marker detector と違い、一度、認識した数を取得する
detectedNumber = this.detector.detectMarkerLite(this.raster, this._threshold);
} catch (e:Error) {}
// 非認識状態に切替
var i:int=0;
for (i=0; i<this.markerPatternList.length; i++) {
this.markerList*.isPrevDetect = this.markerList*.isDetect;
this.markerList*.isDetect = false;
this.markerList*.confidence = 0.3;
}
// 認識したマーカーを選別して処理を行う
for (i=0; i<detectedNumber; i++) {
if (this.detector.getConfidence(i) > 0.5) {
var detectMarkerID:int = this.detector.getARCodeIndex(i);
var congidence:Number = this.detector.getConfidence(i);
if (this.markerList[detectMarkerID].confidence < congidence) {
this.markerList[detectMarkerID].confidence = congidence;
this.detector.getTransformMatrix(i, this.markerList[detectMarkerID].resultMat);
this.markerList[detectMarkerID].isDetect = true;
}
}
}