FLARToolKit 2 or 3 markers?

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 :slight_smile:

here is my code


// マーカーパラメータ初期化
            this.markerPatternList = new Vector.<FLARCode>();
            //this.markerPatternList.fixed = !fixed;
            // &#12510;&#12540;&#12459;&#12540;&#12398;&#12497;&#12479;&#12540;&#12531;&#12501;&#12449;&#12452;&#12523;
            this.markerPatternFileList = new Vector.<String>();
            this.markerPatternFileList.push('pattern/V.pat',
                                            'pattern/bbl.pat',
                                            'pattern/heart.pat'
                                            );
            
            // &#12510;&#12540;&#12459;&#12540;&#12398;&#19968;&#36794;&#12398;&#38263;&#12373;(px)
            this.codeWidthList = new Vector.<Number>();
            this.codeWidthList.push( 80, 80);
            
            // &#12497;&#12521;&#12513;&#12540;&#12479;&#12398;&#12525;&#12540;&#12489;
            this.paramLoad();
            //for (var j:int=0; j<markerPatternFileList.length; j++) {}
        
        
        /**
         * &#12459;&#12513;&#12521;&#12497;&#12521;&#12513;&#12540;&#12479;&#12434;&#35501;&#12415;&#36796;&#12415;&#12289;&#22793;&#25968;&#12395;&#12525;&#12540;&#12489;
         *@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);
                });
            // &#20998;&#21106;&#25968;(&#32294;&#12539;&#27178;)&#12289;&#40658;&#26528;&#12398;&#24133;(&#32294;&#12539;&#27178;)
            var markerPatternCode0:FLARCode = new FLARCode(16, 16);
            mf.addTarget(    markerPatternFileList[0], 
                             URLLoaderDataFormat.TEXT,
                            function(data:String):void
                            {markerPatternCode0.loadARPattFromFile(data);});
            
            // &#20998;&#21106;&#25968;(&#32294;&#12539;&#27178;)&#12289;&#40658;&#26528;&#12398;&#24133;(&#32294;&#12539;&#27178;)
            var markerPatternCode1:FLARCode = new FLARCode(16, 16);
            mf.addTarget(    markerPatternFileList[1], 
                            URLLoaderDataFormat.TEXT,
                            function(data:String):void{
                            markerPatternCode1.loadARPattFromFile(data);});
            
            // &#20998;&#21106;&#25968;(&#32294;&#12539;&#27178;)&#12289;&#40658;&#26528;&#12398;&#24133;(&#32294;&#12539;&#27178;)
            var markerPatternCode2:FLARCode = new FLARCode(16, 16);
            mf.addTarget(
                            markerPatternFileList[2], URLLoaderDataFormat.TEXT,
                            function(data:String):void
                            {markerPatternCode2.loadARPattFromFile(data);});
            //&#12525;&#12540;&#12489;&#38283;&#22987;
            mf.multiLoad();
            
            markerPatternList.push(markerPatternCode0);
            markerPatternList.push(markerPatternCode1);
            markerPatternList.push(markerPatternCode2);
            
            //&#32066;&#20102;&#24460;&#12289;&#21021;&#26399;&#21270;&#20966;&#29702;&#12395;&#36983;&#31227;&#12377;&#12427;&#12424;&#12358;&#12395;&#35373;&#23450;
            mf.addEventListener(Event.COMPLETE, initialization);
            
            return;
        }
        
        /**
         * web&#12459;&#12513;&#12521;&#12420;&#34920;&#31034;&#12289;detector&#12398;&#21021;&#26399;&#21270;
         * @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 );
            // &#12454;&#12455;&#12502;&#12459;&#12513;&#12521;&#12398;&#35299;&#20687;&#24230;&#12392;&#34920;&#31034;&#12469;&#12452;&#12474;&#12364;&#30064;&#12394;&#12427;&#22580;&#21512;&#12399;&#25313;&#22823;&#12377;&#12427;
            //capture.width = canvasWidth;
            //capture.height = canvasHeight;
            
            // &#12461;&#12515;&#12503;&#12481;&#12515;&#12540;&#12375;&#12390;&#12356;&#12427;&#20869;&#23481;&#12363;&#12425;&#12521;&#12473;&#12479;&#30011;&#20687;&#12434;&#29983;&#25104;
            //this.raster = new FLARRgbRaster_BitmapData( this.capture.bitmapData);
            raster = new FLARRgbRaster_BitmapData(capture.bitmapData);
            
            // &#12461;&#12515;&#12503;&#12481;&#12515;&#12540;&#12375;&#12390;&#12356;&#12427;&#20869;&#23481;&#12434; addChild
            //addChild(capture);
            
            // setup Single marker detector
            detector = new FLARMultiMarkerDetector(cameraParam,
                                                          markerPatternList,
                                                          codeWidthList,
                                                          markerPatternList.length
                                                          );
            // &#32153;&#32154;&#35469;&#35672;&#12514;&#12540;&#12489;&#30330;&#21205;
            detector.setContinueMode(true);
            // &#12375;&#12365;&#12356;&#20516;&#35519;&#25972;
            _threshold_detect=new FLARRasterThresholdAnalyzer_SlidePTile(15,4);
            
            // &#21021;&#26399;&#21270;&#23436;&#20102;
            dispatchEvent(new Event(Event.INIT));
            
            // 3D&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#38306;&#20418;&#12398;&#21021;&#26399;&#21270;&#12408;
            supportLibsInit();
            
            // &#12473;&#12479;&#12540;&#12488;
            start();
        }
        
        /**
         * 3D&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#38306;&#20418;&#12398;&#21021;&#26399;&#21270;
         * &#20351;&#29992;&#12377;&#12427;3D&#12521;&#12452;&#12502;&#12521;&#12522;&#12395;&#24540;&#12376;&#12390;&#12371;&#12398;&#37096;&#20998;&#12434;&#26360;&#12365;&#25563;&#12360;&#12427;&#12290;
         */
         function supportLibsInit(): void
        {
            viewport3d = new Viewport3D(320, 240);
            layerFlart.addChild(viewport3d);
            viewport3d.x = -4; // 4pix ???
            
            // &#12471;&#12540;&#12531;&#12398;&#29983;&#25104;
            scene3d = new Scene3D();
            
            // &#12510;&#12540;&#12459;&#12540;&#12494;&#12540;&#12489;&#12289;&#12510;&#12540;&#12459;&#12540;&#12487;&#12540;&#12479;&#12398;&#21021;&#26399;&#21270;&#12392;&#12471;&#12540;&#12531;&#12408;&#12398;&#36861;&#21152;
            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&#12514;&#12487;&#12523;&#34920;&#31034;&#26178;&#12398;&#35222;&#28857;&#12434;&#35373;&#23450;
            camera3d = new FLARCamera3D(cameraParam);
            
            // setup renderer
            renderer = new LazyRenderEngine(scene3d, camera3d, viewport3d);
        }
        
        /**
         * 3D&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#29983;&#25104; create 
        
         function createObject(_lightColor:Number,_ambientColor:Number):DisplayObject3D
        {// &#12521;&#12452;&#12488;&#12398;&#35373;&#23450;&#12290;&#25163;&#21069;&#12289;&#19978;&#12398;&#12411;&#12358;&#12290;
                        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 &#12395; &#36861;&#21152;
            _container.addChild(_plane);
 
            return _container;
        }
                      
        
///_________________________FLARTOOL KIT STUFF

        /**
         * 3D&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12398;&#29983;&#25104;&#12392;&#30331;&#37682;
         * &#12510;&#12540;&#12459;&#12540;&#12452;&#12505;&#12531;&#12488;&#26041;&#24335;&#12434;&#25505;&#29992;&#12375;&#12390;&#12356;&#12427;&#12383;&#12417;&#12289;marker&#12452;&#12505;&#12531;&#12488;&#12434;&#30331;&#37682;
         * &#12473;&#12524;&#12483;&#12489;&#12398;&#12473;&#12479;&#12540;&#12488;
         */
         function start():void
        {
            // 3D&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#29983;&#25104;&#12375;&#12390;Marker Node &#12395;&#36861;&#21152;
            this.markerNodeList[0].addChild(this.createCube(0xFF0000, 0x660000));
            this.markerNodeList[1].addChild(this.createObject(0x0000FF, 0x000066));
            this.markerNodeList[2].addChild(this.createObject(0x0000FF, 0x000066));
            
            // &#20966;&#29702;&#38283;&#22987;
            this.addEventListener(Event.ENTER_FRAME, this.run);
        }
        
        /**
         * &#12371;&#12371;&#12391;&#12501;&#12524;&#12540;&#12512;&#12372;&#12392;&#12395;&#20966;&#29702;
         * &#12452;&#12505;&#12531;&#12488;&#26041;&#24335;&#12391;&#12398;&#23455;&#35013;&#12399;&#12289;FLARManager &#12391;&#23455;&#35013;&#12373;&#12428;&#12390;&#12356;&#12427;&#12383;&#12417;&#12371;&#12371;&#12391;&#12399;&#20316;&#12425;&#12394;&#12356;&#12290;
         */
         function run(e:Event):void
        {
            capture.bitmapData.draw(vid);
            
            // Marker detect
            var detectedNumber:int = 0;
            try {
                // Single Marker detector &#12392;&#36949;&#12356;&#12289;&#19968;&#24230;&#12289;&#35469;&#35672;&#12375;&#12383;&#25968;&#12434;&#21462;&#24471;&#12377;&#12427;
                detectedNumber = this.detector.detectMarkerLite(this.raster, this._threshold);
            } catch (e:Error) {}
            
            // &#38750;&#35469;&#35672;&#29366;&#24907;&#12395;&#20999;&#26367;
            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;
            }
            
            // &#35469;&#35672;&#12375;&#12383;&#12510;&#12540;&#12459;&#12540;&#12434;&#36984;&#21029;&#12375;&#12390;&#20966;&#29702;&#12434;&#34892;&#12358;

            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;
                    }
                }
                    
            }