2008/12/12 Friday

Papervision3D テンプレ

Filed under: Flash — at 19:58:50

久々に触ったのでついでにPlane1枚表示するまでの最低コードテンプレにしとく。

バージョンは2.0 Great White rev815 コードは以下

package{
  import flash.display.MovieClip;
  import flash.display.Stage;
  import flash.display.StageAlign;
  import flash.display.StageScaleMode;
  import flash.events.Event;

  import org.papervision3d.cameras.Camera3D;
  import org.papervision3d.render.BasicRenderEngine;
  import org.papervision3d.scenes.Scene3D;
  import org.papervision3d.view.Viewport3D;
  import org.papervision3d.materials.*;
  import org.papervision3d.objects.primitives.Plane;

  public class Main extends MovieClip{

    //set Var
    private var scene:Scene3D;
    private var viewport:Viewport3D;
    private var camera:Camera3D;
    private var renderer:BasicRenderEngine;
    private var objPlane:Plane;

    public function Main()
    {
      stage.align = StageAlign.TOP_LEFT;
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.frameRate = 30;

      init();
    }

    private function init():void
    {
      //set Viewport
      viewport = new Viewport3D(0, 0, true);
      addChild(viewport);

      //set Scene
      scene = new Scene3D();

      //set Render
      renderer = new BasicRenderEngine();

      //set Camera
      camera = new Camera3D();
      camera.z = -500;

      //make Object
      var colorMat:ColorMaterial = new ColorMaterial( 0x000011, 1);
      colorMat.doubleSided = true;
      objPlane = new Plane(colorMat, 200, 200);
      scene.addChild(objPlane);

      addEventListener(Event.ENTER_FRAME, update);
    }

    private function update(e:Event):void
    {
      objPlane.rotationX += 1;
      objPlane.rotationY -= 2;
      objPlane.rotationZ += 4;

      renderer.renderScene(scene,camera,viewport);
    }
  }
}

No Comments »

No comments yet.

Leave a comment

HTML convert time: 0.176 sec. Powered by WordPress