2008年 04月 21日
Flash + Flex でやってきたんですが
今回は外部ファイルがいくつかあるのでEmbedで埋め込んで
Flex のみで作成しています。
colladaファイルとテクスチャーファイルは
papervision3d\trunk\as3\trunk\examples\Focus
を使用しました。
package {
import flash.display.Sprite;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.primitives.Plane;
import flash.events.Event;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.core.utils.Mouse3D;
import flash.display.BitmapData;
import flash.utils.getDefinitionByName;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.PhongMaterial;
import org.papervision3d.materials.shadematerials.GouraudMaterial;
import org.papervision3d.materials.shadematerials.CellMaterial;
import org.papervision3d.materials.shadematerials.EnvMapMaterial;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.objects.parsers.Collada;
import org.papervision3d.objects.DisplayObject3D;
import flash.display.Bitmap;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.events.RendererEvent;
import org.papervision3d.events.AnimationEvent;
import org.papervision3d.events.FileLoadEvent;
import org.papervision3d.materials.shaders.PhongShader;
import org.papervision3d.materials.shaders.ShadedMaterial;
import org.papervision3d.materials.WireframeMaterial;
import flash.display.StageQuality;
[SWF(width="400",height="300",frameRate="30",backgroundColor="#CCCCCC")]
public class pv3d_test8 extends Sprite
{
public var viewport :Viewport3D;
public var scene :Scene3D;
public var camera :Camera3D;
public var renderer :BasicRenderEngine;
public var model :DisplayObject3D;
public var Steer_FL :DisplayObject3D;
public var Steer_FR :DisplayObject3D;
public var Wheel_FR :DisplayObject3D;
public var Wheel_FL :DisplayObject3D;
public var Wheel_RR :DisplayObject3D;
public var Wheel_RL :DisplayObject3D;
[Embed(source="./data/Focus.dae", mimeType="application/octet-stream")]
private var collada_car:Class;
[Embed(source="./data/image/body.jpg")]
private var body_texture:Class;
[Embed(source="./data/image/wheel.jpg")]
private var wheel_texture:Class;
/**----------------------------------------------------------------------
* コンストラクタ
-----------------------------------------------------------------------*/
public function pv3d_test8() {
//画質を低に
this.stage.quality = StageQuality.LOW;
//初期化
init();
}
/**----------------------------------------------------------------------
* init
* 初期化
-----------------------------------------------------------------------*/
public function init():void {
//このムービーのスケールモードを設定
this.stage.scaleMode = "noScale"
this.stage.align = "left";
//3Dの初期設定
this.init3D();
//毎フレーム呼び出されるイベントを追加
this.addEventListener( Event.ENTER_FRAME, this.loop_Proc );
}
/**----------------------------------------------------------------------
* init3D
* 3Dの初期設定
-----------------------------------------------------------------------*/
public function init3D():void {
// ビューポートの作成
this.viewport = new Viewport3D(0, 0, true, true);
this.addChild( viewport );
//レンダラーの設定
this.renderer = new BasicRenderEngine();
//シーン作成
this.scene = new Scene3D();
//ライトの作成
var light:PointLight3D = new PointLight3D();
light.x = 100;
light.y = 1000;
light.z = -1000;
//ライトを追加
this.scene.addChild(light);
//テクスチャー
var body_tex:Bitmap = new body_texture() as Bitmap;
var body_bit_mat:BitmapMaterial = new BitmapMaterial(body_tex.bitmapData);
var phong_shader:PhongShader = new PhongShader(light ,0xFFFFFF , 0x444444,1);
//マテリアルリスト
var body_mat_list:MaterialsList = new MaterialsList(
{all:new ShadedMaterial(body_bit_mat,phong_shader)}
);
//collada から モデルを作成
this.model = new Collada(XML(new collada_car()),body_mat_list).getChildByName("Focus");
//モデルをシーンに追加
this.scene.addChild(this.model);
//ホイルのマテリアルを作成
var wheel_tex:Bitmap = new wheel_texture() as Bitmap;
var wheel_mat:BitmapMaterial = new BitmapMaterial(wheel_tex.bitmapData);
var wheel_sh_mat:ShadedMaterial = new ShadedMaterial(wheel_mat,phong_shader);
//パーツを取得
this.Steer_FL = this.model.getChildByName("Steer_FL");
this.Steer_FR = this.model.getChildByName("Steer_FR");
this.Wheel_FL = this.Steer_FL.getChildByName("Wheel_FL");
this.Wheel_FR = this.Steer_FR.getChildByName("Wheel_FR");
this.Wheel_RL = this.model.getChildByName("Wheel_RL");
this.Wheel_RR = this.model.getChildByName("Wheel_RR");
//ホイルのマテリアル設定
this.Wheel_RL.material = wheel_sh_mat;
this.Wheel_RR.material = wheel_sh_mat;
this.Wheel_FL.material = wheel_sh_mat;
this.Wheel_FR.material = wheel_sh_mat;
//地面を作成
var plane:Plane = new Plane(new WireframeMaterial(0x000000),2000,2000,5,5);
plane.rotationX = -90;
plane.y = -70;
this.scene.addChild(plane);
// カメラの作成
this.camera = new Camera3D();
this.camera.z = -1800;
this.camera.zoom = 5;
this.camera.y = 1000;
this.camera.lookAt(this.model);
}
/**----------------------------------------------------------------------
* loop_Proc
* 毎フレーム呼び出される 関数
-----------------------------------------------------------------------*/
public function loop_Proc(event:Event):void
{
//モデルの回転
this.model.rotationY += 2;
//レンダリング
this.renderer.renderScene(scene, camera, viewport);
}
}
}
なかなかいいじゃんー
投稿者: d5 23 : 04
更新日:2008-04-22 21:05:10
|
|
|
| |