[Away3D] 光の効果 (2)

Away3Dを使って、光のエフェクトを作るよ。 :boy:

away3dEffect2

SegmentSet, LineSegment を使ってみるよ。 :bouzu:
さらに、RadialBlurFilter3D も使ってみた! :cake:

clockmaker 先生 :hakase: のスクリプトをこっそり使わせてもらったよ。

:caution: 要 Flash Player 11.8 以上

This movie requires Flash Player 11.8.0

Main.as
package {

  import flash.display.Sprite;
  import flash.system.System;
  import flash.events.Event;
  import flash.geom.Vector3D;

  import away3d.Away3D;
  import away3d.containers.View3D;
  import away3d.containers.Scene3D;
  import away3d.cameras.Camera3D;
  import away3d.containers.ObjectContainer3D;
  import away3d.entities.SegmentSet;
  import away3d.primitives.LineSegment;
  import away3d.filters.RadialBlurFilter3D;

  import a24.tween.Tween24;
  import a24.tween.events.Tween24Event;


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

  public class Main extends Sprite {
    // プロパティ
    private var view:View3D;
    private var scene:Scene3D;
    private var camera:Camera3D;
    private var container:ObjectContainer3D;
    private var lights:Array;
    private var types:Array;
    private var vectors:Vector.<Vector3D>;
    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:Vector3D = new Vector3D();

    // コンストラクタ
    public function Main() {
      System.pauseForGCIfCollectionImminent(1);
      init();
    }

    // メソッド
    private function init():void {
      types = new Array();
      types.push({lines: 1600, color: 0x00CCFF, scale: 0.4});
      types.push({lines: 3200, color: 0x3399FF, scale: 1});
      vectors = new Vector.<Vector3D>();
      for (var n:uint = 0; n < 3200; n++) {
        var vector:Vector3D = createSphereVector(Math.random()*360, Math.random()*360, 120);
        vectors.push(vector);
      }
      view = new View3D();
      scene = view.scene;
      camera = view.camera;

      addChild(view);
      setup();
      initialize();
      addEventListener(Event.ENTER_FRAME, render, false, 0, true);
      start();
    }
    private function setup():void {
      view.backgroundColor = 0x000000;
      //view.antiAlias = 4;
      view.filters3d = [new RadialBlurFilter3D(4, 2, 1, - 0.4, 0.5, 0.5)];
      camera.x = 0;
      camera.y = 0;
      camera.z = - radius;
    }
    private function initialize():void {
      container = new ObjectContainer3D();
      scene.addChild(container);

      lights = new Array();
      for (var n:uint = 0; n < types.length; n++) {
        var light:SegmentSet = new SegmentSet();
        var type:Object = types[n];
        light.scale(type.scale);
        lights.push(light);
        for (var t:uint = 0; t < type.lines; t++) {
          var vector:Vector3D = vectors[t];
          var start:Vector3D = vector.clone();
          var end:Vector3D = vector.clone();
          end.scaleBy(1.1);

          var segment:LineSegment = new LineSegment(start, end, type.color, 0x000000, 0.4);
          light.addSegment(segment);
        }
        container.addChild(light);
      }
    }
    private function render(evt:Event):void {
      angle += 0.5;
      degree += 1;
      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);
      camera.lookAt(center);
      view.render();
    }
    private function start():void {
      var light1:SegmentSet = lights[0];
      var light2:SegmentSet = lights[1];
      var atween:Tween24 = Tween24.parallel(
        Tween24.serial(
          Tween24.tween(light1, 1.2, Tween24.ease.CubicIn).scaleXYZ(0.8, 0.8, 0.8),
          Tween24.tween(light1, 0.8, Tween24.ease.CubicOut). scaleXYZ(0.4, 0.4, 0.4)
        ),
        Tween24.serial(
          Tween24.tween(light2, 1.2, Tween24.ease.CubicIn). scaleXYZ(1.2, 1.2, 1.2),
          Tween24.tween(light2, 0.8, Tween24.ease.CubicOut). scaleXYZ(1, 1, 1)
        )
      ).delay(2);
      atween.addEventListener(Tween24Event.COMPLETE, complete, false, 0, true);
      atween.play();

    }
    private function complete(evt:Tween24Event):void {
      evt.target.removeEventListener(Tween24Event.COMPLETE, complete);
      start();
    }
    private function createSphereVector(a:Number, b:Number, r:Number):Vector3D {
      var px:Number = r*Math.cos(a*radian)*Math.cos(b*radian);
      var py:Number = r*Math.sin(a*radian);
      var pz:Number = r*Math.cos(a*radian)*Math.sin(b*radian);
      var vector:Vector3D = new Vector3D(px, py, pz);
      return vector;
    }

  }

}

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


[修正] (12/10/04 Thu 22:00)
Tween24 2.0.1 にバージョンアップ。
[修正] (13/01/14 Mon 23:04)
Away3D 4.1.0 Alpha にバージョンアップ。
[修正] (13/05/09 Thu 06:52)
Away3D 4.1.1 Beta にバージョンアップ。線の太さが大きくでるようになったので、1から0.4に変更。Vector3Dの座標計算で、120を72に変更。
[修正] (13/07/17 Wed 15:40)
Away3D 4.1.4 Gold にバージョンアップ。
[修正] (13/11/12 Tue 16:44)
Away3D 4.1.5 Gold にバージョンアップ。
[修正] (14/02/03 Mon 22:36)
Away3D 4.1.6 にバージョンアップ。Vector3Dの座標計算で、72を120に変更。
[修正] (14/10/08 Wed 15:12)
Tween24 2.1 にバージョンアップ。