安裝設定
範例 MainPV3D001 :材質使用WireframeMaterial(內建材質)
package
{
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.materials.WireframeMaterial;
/**
* ...
* @author Ercrta 嵐
*/
public class MainPV3D001 extends Sprite {
//BasicView(寬:Number = 640, 高:Number = 480, scaleToStage:Boolean = true, interactive:Boolean = false, cameraType:String = "Target")
private var basicView:BasicView= new BasicView();; //3D環境
private var material:WireframeMaterial; //材質
private var plane:Plane; //建立3d物件-平面
public function MainPV3D001():void {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
initPV3D();
}
private function initPV3D():void {
//WireframeMaterial(顏色:Number = 0xFF00FF, 透明度:Number = 100, 線框厚度:Number = 0)
material = new WireframeMaterial(0xFF6655,50,5);
material.doubleSided = true;//材質是否用在正反兩面
//primitive = new Plane(材質:MaterialObject3D = null, 寬:Number = 0, 高:Number = 0, 寬分割數:Number = 0, 高分割數:Number = 0);//分割數愈少,愈省效能
plane = new Plane(material, 200, 200, 1, 1);
basicView.scene.addChild(plane);//把3D物件加進3D環境中
basicView.startRendering();//開始渲染
this.addChild(basicView);//場景加入3D
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void{
plane.localRotationY++;
}
}
}
範例 Mainpv3D002:材質使用ColorMaterial(內建材質)
package {
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.materials.ColorMaterial;
/**
* ...
* @author Ercrta 嵐
* @date: 2010/4/29 下午 10:19
*/
public class Mainpv3D002 extends Sprite {
//BasicView(寬:Number = 640, 高:Number = 480, scaleToStage:Boolean = true, interactive:Boolean = false, cameraType:String = "Target")
private var basicView:BasicView = new BasicView(); //3D環境
private var material:ColorMaterial; //材質
private var plane:Plane; //建立3d物件-平面
public function Mainpv3D002() {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init():void{
removeEventListener(Event.ADDED_TO_STAGE, init);
initPV3D();
}
private function initPV3D():void{
//ColorMaterial(顏色:Number = 0xFF00FF, 透明度:Number = 1, interactive:Boolean = false)
material = new ColorMaterial(0xFF6655,50);
material.doubleSided = true;//材質是否用在正反兩面
//primitive = new Plane(材質:MaterialObject3D = null, 寬:Number = 0, 高:Number = 0, 寬分割數:Number = 0, 高分割數:Number = 0);//分割數愈少,愈省效能
plane = new Plane(material, 200, 200, 1, 1);
basicView.scene.addChild(plane);//把3D物件加進3D環境中
basicView.startRendering();//開始渲染
this.addChild(basicView);//場景加入3D
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void{
plane.localRotationY++;
}
}
}
範例 Mainpv3D003:材質使用BitmapMaterial(使用自己的jpg圖片)
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.events.Event;
import org.papervision3d.view.BasicView;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.materials.BitmapMaterial;
/**
* ...
* @author Ercrta 嵐
* @date: 2010/4/29 下午 10:19
*/
public class MainPV3D003 extends Sprite {
//BasicView(寬:Number = 640, 高:Number = 480, scaleToStage:Boolean = true, interactive:Boolean = false, cameraType:String = "Target")
private var basicView:BasicView = new BasicView(); //3D環境
private var material:BitmapMaterial; //材質
private var plane:Plane; //建立3d物件-平面
[Embed(source="../asset/material.jpg")]
private static var imgClass:Class;
private var img:Bitmap = new imgClass();
public function MainPV3D003() {
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init():void{
removeEventListener(Event.ADDED_TO_STAGE, init);
initPV3D();
}
private function initPV3D():void {
//BitmapMaterial(材質來源:BitmapData = null, precise:Boolean = false)
material = new BitmapMaterial(img.bitmapData);
material.doubleSided = true;//材質是否用在正反兩面
//primitive = new Plane(材質:MaterialObject3D = null, 寬:Number = 0, 高:Number = 0, 寬分割數:Number = 0, 高分割數:Number = 0);//分割數愈少,愈省效能
plane = new Plane(material, 200, 200, 1, 1);
basicView.scene.addChild(plane);//把3D物件加進3D環境中
basicView.startRendering();//開始渲染
this.addChild(basicView);//場景加入3D
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void{
plane.localRotationY++;
}
}
}
材質部份,基本上都劃分在 org.papervision3d.materials下。
範例檔下載
0 意見:
張貼留言