[Papervision3D] モデル (4) ~ねぎミク~

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

pv3dModel4

DAEクラス で Colladaデータ を読み込んでモデルを表示してみるよ。 :bouzu:
BasicRenderEngine の代わりに、QuadrantRenderEngine を使ってみたよ。 :cake:

@rect 先生 :hakase: の「note.x | [Papervision3D]ねぎ振り完了」から、Colladaデータとテクスチャをダウンロードさせていただきました。 :doki:

ポリゴン欠けが少し軽減されたかも。 :girl:

: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.render.QuadrantRenderEngine;
  import org.papervision3d.objects.DisplayObject3D;
  import org.papervision3d.objects.parsers.DAE;
  import org.papervision3d.materials.BitmapMaterial;
  import org.papervision3d.materials.utils.MaterialsList;
  import org.papervision3d.events.FileLoadEvent;

  import org.libspark.betweenas3.BetweenAS3;
  import org.libspark.betweenas3.tweens.ITween;
  import org.libspark.betweenas3.events.TweenEvent;
  import org.libspark.betweenas3.easing.*;


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

  public class Main extends Sprite {
    [Embed(source="assets/negimiku/negimiku.dae", mimeType="application/octet-stream")]
    private var ColladaData:Class;
    [Embed(source="assets/negimiku/negimiku.png")]
    private var ImageData:Class;
    // プロパティ
    private var scene:Scene3D;
    private var camera:Camera3D;
    private var viewport:Viewport3D;
    private var renderer:QuadrantRenderEngine;
    private var container:DisplayObject3D;
    private var negimiku: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);

      renderer = new QuadrantRenderEngine();
      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 materials:MaterialsList = new MaterialsList({all: material});

      negimiku = new DAE();
      negimiku.addEventListener(FileLoadEvent.LOAD_COMPLETE, loaded, false, 0, true);
      negimiku.load(XML(new ColladaData()), materials);
    }
    private function loaded(evt:FileLoadEvent):void {
      negimiku.removeEventListener(FileLoadEvent.LOAD_COMPLETE, loaded);
      container.addChild(negimiku);
      negimiku.scale = 16.8;
      addEventListener(Event.ENTER_FRAME, render, false, 0, true);
      jump();
    }
    private function jump():void {
      var itween:ITween = BetweenAS3.serial(
        BetweenAS3.tween(negimiku, {y: 50}, {y: -50}, 0.5, Cubic.easeOut),
        BetweenAS3.tween(negimiku, {y: -50}, {y: 50}, 0.5, Cubic.easeIn)
      );
      itween.addEventListener(TweenEvent.COMPLETE, jumped, false, 0, true);
      itween.play();

    }
    private function jumped(evt:TweenEvent):void {
      evt.target.removeEventListener(TweenEvent.COMPLETE, jumped);
      jump();
    }
    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 でパブリッシュ。