2008年10月7日 星期二

《 AS3 》Alternativa3D 安裝與配置

官方網站
http://alternativaplatform.com/en/

官方文件網頁
http://docs.alternativaplatform.com/dashboard.action

1. 下載
        註冊之後,觀看合約即可下載
        取得 Flash  組件檔案(.swc for 9 & 10)
        用此製作的程式,無法/嚴禁商業使用

2. 安裝與配置
        環境配置官方網站說明
             http://docs.alternativaplatform.com/display/TDEN/Connecting+library
      
        示範(Flash CS3)
            (1) 複製 全部的 .swc 到 C: \ Documents and Settings \ {username} \ Local Settings \ Application Data \ Adobe \ Flash CS3 \ en \ Configuration \ Components \.
            (2) 打開FlashCS3 IDE,將組件視窗打開,拉入元件庫即可。
 
        
3.範例測試
    官方的文件
    http://docs.alternativaplatform.com/display/TDEN/Hello%2C+Alternativa3D

    轉貼程式碼:
package {
import alternativa.engine3d.controllers.CameraController;
import alternativa.engine3d.core.Camera3D;
import alternativa.engine3d.core.Object3D;
import alternativa.engine3d.core.Scene3D;
import alternativa.engine3d.display.View;
import alternativa.engine3d.materials.WireMaterial;
import alternativa.engine3d.primitives.Box;
import alternativa.utils.FPS;

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

[SWF(backgroundColor="#000000", frameRate="100")]

public class HelloAlternativa3D extends Sprite {

private var scene:Scene3D;
private var view:View;
private var camera:Camera3D;
private var cameraController:CameraController;
private var box:Box;

public function HelloAlternativa3D() {
addEventListener(Event.ADDED_TO_STAGE, init);
}

public function init(e:Event): void {
removeEventListener(Event.ADDED_TO_STAGE, init);

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

// Creating scene
scene = new Scene3D();
scene.root = new Object3D();
box = new Box(100, 100, 100, 3, 3, 3);
box.cloneMaterialToAllSurfaces(new WireMaterial(1, 0xFFFFFF));
scene.root.addChild(box);

// Adding camera and view
camera = new Camera3D();
camera.x = 100;
camera.y = -150;
camera.z = 100;
scene.root.addChild(camera);

view = new View();
addChild(view);
view.camera = camera;

// Connecting camera controller
cameraController = new CameraController(stage);
cameraController.camera = camera;
cameraController.setDefaultBindings();
cameraController.checkCollisions = true;
cameraController.collisionRadius = 20;
cameraController.lookAt(box.coords);
cameraController.controlsEnabled = true;

// FPS display launch
FPS.init(stage);

stage.addEventListener(Event.RESIZE, onResize);
stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
onResize(null);
}

private function onResize(e:Event):void {
view.width = stage.stageWidth;
view.height = stage.stageHeight;
}

private function onEnterFrame(e:Event):void {
// User input processing
cameraController.processInput();
// Scene calculating
scene.calculate();
}
}
}

將背景設為暗色,就會發現成功囉 :D

參考來源:
【Alternativa3D】我的第一个DEMO