代码清单:
package
{
import flash.display.Sprite;
import flash.events.*;
import sandy.core.Scene3D;
import sandy.core.scenegraph.*;
import sandy.primitive.*;
import sandy.core.data.*;
import sandy.materials.*;
import sandy.materials.attributes.*;
import sandy.core.scenegraph.mode7.*;
import flash.ui.Keyboard;
import flash.display.Bitmap;
import flash.display.BitmapData;
public class My3D2 extends Sprite
{
private var scenne:Scene3D;
private var camera:CameraMode7;
private var ranY:Number=0.5;
private var box:Box;
private var skin1:BitmapData=new Face1(0,0);
private var skin2:BitmapData=new Face2(0,0);
private var skin3:BitmapData=new Face3(0,0);
private var skin4:BitmapData=new Face4(0,0);
private var skin5:BitmapData=new Face5(0,0);
private var skin6:BitmapData=new Face6(0,0);
private var _leftPush:Number=0;
private var _rightPush:Number=0;
private var _upPush:int=0;
private var _downPush:int=0;
public function My3D2()
{
camera=new CameraMode7(400,400);//设定摄影机大小和位置
camera.x = 0;
camera.y = 100;
camera.z = -200;
camera.tilt = 20;
var root:Group=createScene();
scenne=new Scene3D("scene1",this,camera,root);//创建带摄像机的场景
addEventListener(Event.ENTER_FRAME,Run);
}
private function createScene():Group
{
var g:Group=new Group();
box=new Box("box",100,100,100);
var material1:BitmapMaterial=new BitmapMaterial(skin1);
var material2:BitmapMaterial=new BitmapMaterial(skin2);
var material3:BitmapMaterial=new BitmapMaterial(skin3);
var material4:BitmapMaterial=new BitmapMaterial(skin4);
var material5:BitmapMaterial=new BitmapMaterial(skin5);
var material6:BitmapMaterial=new BitmapMaterial(skin6);
material1.lightingEnable = true;
material2.lightingEnable = true;
material3.lightingEnable = true;
material4.lightingEnable = true;
material5.lightingEnable = true;
material6.lightingEnable = true;
var app1:Appearance = new Appearance( material1);//为物体创建材质表面
var app2:Appearance = new Appearance( material2 );//为物体创建材质表面
var app3:Appearance = new Appearance( material3);//为物体创建材质表面
var app4:Appearance = new Appearance( material4 );//为物体创建材质表面
var app5:Appearance = new Appearance( material5);//为物体创建材质表面
var app6:Appearance = new Appearance( material6 );//为物体创建材质表面
box.rotateX=10;
box.rotateY=0;
box.getFace(0).appearance = app1;//指定材质表面
box.getFace(1).appearance = app2;//指定材质表面
box.getFace(2).appearance = app3;//指定材质表面
box.getFace(3).appearance = app4;//指定材质表面
box.getFace(4).appearance = app5;//指定材质表面
box.getFace(5).appearance = app6;//指定材质表面
camera.lookAt(box.x,box.y,box.z);
g.addChild(box);
return g;
}
private function Run(event:Event):void
{
scenne.render();
box.rotateX+=1;//让立方体会在x轴上旋转
box.rotateY+=1;//让立方体会在y轴上旋转
// keyPress();
}
}
}
回复Comments
作者:
{commentrecontent}