topical media & game development

talk show tell print

student-ar-org-tarotaro-flash-ar-ComboSample.mx

student-ar-org-tarotaro-flash-ar-ComboSample.mx [swf] flex


  <?xml version="1.0" encoding="utf-8"?>
  <!-- コンボボックスでキャラクターを選択可能な、FLARToolKitの利用サンプル -->
  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                                  styleName="plain" 
                                  width="640"
                                  height="480"
                                  applicationComplete="onInit();">
      <mx:Script>
      <![CDATA[
                  import flash.events.Event;
                  import org.tarotaro.flash.pv3d.Metasequoia;
                  import org.papervision3d.materials.WireframeMaterial;
                  import org.papervision3d.objects.DisplayObject3D;
                  import org.papervision3d.objects.primitives.Plane;
                  import org.tarotaro.flash.ar.SimpleFLARToolKitView;
                  import mx.core.UIComponent;
                  import mx.collections.ArrayCollection;
  
                  
コンボボックスに表示するデータ一覧を表すArrayCollectionインスタンス

  
                  [Bindable]
                  public var models:ArrayCollection = new ArrayCollection(
                          [ {label:"パイプ", data:"model/pipe.mqo"}, 
                            {label:"角無し立方体", data:"model/cube.mqo" }
                          ]
                  );
                  
                  
AR用の表示領域

  
                  private var ar:SimpleFLARToolKitView;
                  
                  

  
                  private function onInit():void
                  {
                          ar = new SimpleFLARToolKitView();
                          ar.addEventListener(Event.COMPLETE,function(e:Event):void 
                          {
                                  var uiComp:UIComponent = new UIComponent();
                                  uiComp.addChild(ar);
                                  arCanvas.addChild(uiComp);
                                  ar.scaleX = ar.scaleY = 2;
                                  loadMetasequoia(models[0].data);
                                  ar.start();
                          });
                          ar.setupAR();
                  }
                  
                  
メタセコイアファイルを読み込み、AR用オブジェクトに渡す。 モデルの下には、赤い正方形の枠を出す。 @param url 読み込むメタセコイアファイルのURL

  
                  private function loadMetasequoia(url:String):void 
                  {
                          var grp:DisplayObject3D = new DisplayObject3D("model");
                          var wmat:WireframeMaterial = new WireframeMaterial(0xff0000, 1, 2);
                          wmat.doubleSided = true;
                          var basePlane:Plane = new Plane(wmat, 80, 80);
                          grp.addChild(basePlane);
                          if (url != null &&url.length > 0) {
                                  var mqo:Metasequoia = new Metasequoia();
                                  mqo.load(url, 0.3);
                                  mqo.rotationX = 90;
                                  mqo.z += 40;
                                  grp.addChild(mqo);
                          }
                          ar.model = grp;
                  }
      ]]>
      </mx:Script>
          <mx:UIComponent id="arCanvas" x="0" y="0" width="100%" height="100%" />
          <mx:Panel width="100%" layout="horizontal" title="モデルを選択" alpha="1">
                  <mx:ComboBox id="modelList" dataProvider="{models}" width="100%" close="loadMetasequoia(modelList.selectedItem.data)"/>
      </mx:Panel>
  </mx:Application>
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.