[Papervision3D] モデル (2) 〜スライム〜

Papervision3Dを使って、モデルを作るよ。 :boy:

pv3dModel2

DAEクラス で Colladaデータ を読み込んでモデルを表示してみるよ。 :bouzu:
さらに、PointlLight3D, FlatShader, ShadedMaterial も使ってみたよ。 :cake:

Colladaデータとテクスチャは、@itoz師匠 :hakase: にいただきました。 :doki:

なんか変なラインが入ってるぅ。 😥

:caution: 要 Flash Player 11.8 以上

This movie requires Flash Player 11.8.0

Main.as
package {

  import flash.display.Sprite;
  import flash.display.StageScaleMode;
  import flash.display.StageAlign;
  import flash.events.Event;

  import org.papervision3d.Papervision3D;
  import org.papervision3d.scenes.Scene3D;
  import org.papervision3d.cameras.Camera3D;
  import org.papervision3d.view.Viewport3D;
  import org.papervision3d.lights.PointLight3D;
  import org.papervision3d.render.BasicRenderEngine;
  import org.papervision3d.objects.DisplayObject3D;
  import org.papervision3d.objects.parsers.DAE;
  import org.papervision3d.materials.BitmapMaterial;
  import org.papervision3d.materials.shaders.FlatShader;
  import org.papervision3d.materials.shaders.ShadedMaterial;
  import org.papervision3d.materials.utils.MaterialsList;
  import org.papervision3d.events.FileLoadEvent;


  [SWF(backgroundColor="#000000", width="600", height="600", frameRate="30")]

  public class Main extends Sprite {
    [Embed(source="assets/slime/slime.dae", mimeType="application/octet-stream")]
    private var ColladaData:Class;
    [Embed(source="assets/slime/slime.png")]
    private var ImageData:Class;
    // プロパティ
    private var scene:Scene3D;
    private var camera:Camera3D;
    private var viewport:Viewport3D;
    private var light:PointLight3D;
    private var renderer:BasicRenderEngine;
    private var container:DisplayObject3D;
    private var slime:DAE;
    private static var radius:uint = 500;
    private var angle:Number = - 90;
    private var degree:Number = 0;
    private static var depression:uint = 30;
    private static var radian:Number = Math.PI/180;
    private static var center:DisplayObject3D = DisplayObject3D.ZERO;

    // コンストラクタ
    public function Main() {
      stage.scaleMode = StageScaleMode.NO_SCALE;
      stage.align = StageAlign.TOP_LEFT;
      init();
    }

    // メソッド
    private function init():void {
      scene = new Scene3D();
      camera = new Camera3D();
      viewport = new Viewport3D(600, 600, false, false);

            light = new PointLight3D();
      scene.addChild(light);

      renderer = new BasicRenderEngine();
      setup();
      initialize();
      addChild(viewport);
    }
    private function setup():void {
      camera.x = 0;
      camera.y = 0;
      camera.z = - radius;
      camera.focus = radius;
      camera.zoom = 1;
      camera.target = center;
    }
    private function initialize():void {
      container = new DisplayObject3D();
      scene.addChild(container);

      var material:BitmapMaterial = new BitmapMaterial(new ImageData().bitmapData);
      material.smooth = true;
      var shader:FlatShader = new FlatShader(light, 0xFFFFFF, 0x666666);
      var shadedmaterial:ShadedMaterial = new ShadedMaterial(material, shader, 0);
      var materials:MaterialsList = new MaterialsList({all: shadedmaterial});

      slime = new DAE();
      slime.addEventListener(FileLoadEvent.LOAD_COMPLETE, loaded, false, 0, true);
      slime.load(XML(new ColladaData()), materials);
    }
    private function loaded(evt:FileLoadEvent):void {
      slime.removeEventListener(FileLoadEvent.LOAD_COMPLETE, loaded);
      container.addChild(slime);
      slime.rotationY = 90;
      slime.scale = 84;
      slime.y = - 40;
      addEventListener(Event.ENTER_FRAME, render, false, 0, true);
    }
    private function render(evt:Event):void {
      angle += 1;
      degree += 2;
      var dip:Number = depression*Math.sin(degree*radian);
      camera.x = radius*Math.cos(angle*radian)*Math.cos(dip*radian);
      camera.y = radius*Math.sin(dip*radian);
      camera.z = radius*Math.sin(angle*radian)*Math.cos(dip*radian);
      renderer.renderScene(scene, camera, viewport);
    }

  }

}

Flash CC + Flex 4 SDK でパブリッシュ。