2008年 04月 21日
テクスチャーとPhong Shaderを組み合わせてみたいと思います。
ついでに バンプマップも使ってみます。
※stone.jpgをリンケージの設定をする必要があります。
今回使用したテクスチャー
http://textures.forrest.cz/library/stone/Benedeti.jpg
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.materials.shaders.ShadedMaterial;
import org.papervision3d.materials.shaders.PhongShader;
import org.papervision3d.materials.shaders.FlatShader;
public class pv3d_test7 extends Sprite
{
public var viewport :Viewport3D;
public var scene :Scene3D;
public var camera :Camera3D;
public var renderer :BasicRenderEngine;
public var sphere :Sphere;
/**----------------------------------------------------------------------
* コンストラクタ
-----------------------------------------------------------------------*/
public function pv3d_test7() {
//画質を低に
this.stage.quality = StageQuality.LOW;
//初期化
init();
}
/**----------------------------------------------------------------------
* init
* 初期化
-----------------------------------------------------------------------*/
public function init():void {
//このムービーのスケールモードを設定
this.stage.scaleMode = "noScale"
//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 = 300;
light.y = 500;
light.z = -1000;
//ライトを追加
this.scene.addChild(light);
//テクスチャーの作成
var texture:BitmapData = new (getDefinitionByName("stone.jpg"))(128,128);
//ビットマップマテリアル
var bit_mat:BitmapMaterial = new BitmapMaterial(texture);
//phong shaderの作成 PhongShader(ライト , ライト色 , 環境色 , スペキュラの強さ , バンプマップ , スペキュラマップ)
var phong_shader:PhongShader = new PhongShader(light ,0xFFFFFF , 0x444444,100,texture,texture);
//球体を作成
this.sphere = new Sphere(new ShadedMaterial(bit_mat,phong_shader),200,16,12);
//平面シーンに追加
this.scene.addChild(this.sphere);
// カメラの作成
this.camera = new Camera3D();
this.camera.zoom = 8;
}
/**----------------------------------------------------------------------
* loop_Proc
* 毎フレーム呼び出される 関数
-----------------------------------------------------------------------*/
public function loop_Proc(event:Event):void
{
//板ポリ
this.sphere.rotationX += 0.1;
this.sphere.rotationY += 0.5;
//レンダリング
this.renderer.renderScene(scene, camera, viewport);
}
}
}
なかなかいい具合にレンダリングされておりますね~
投稿者: d5 19 : 04
更新日:2008-04-22 20:59:25
|
|
|
| |