/**
* ...
* @author 张首尚
*/
public class vb extends BasicView
{
private var shpere:Sphere;
private var shpere2:Sphere;
private var planelane;
private var cube:Cube;
private var mList:MaterialsList;
private var paperPlaneaperPlane;
private var do3DisplayObject3D;
/**图片*/
private var imageBitmap:Bitmap;
/**图片加载*/
private var imageLoaderoader;
public function vb()
{
super(640, 480, false, ***e); //***e 可交互
init();
}
private function init():void
{
imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
imageLoader.load(new URLRequest("assets/1.jpg"));
}
private function onComplete(evt:Event):void
{
//图片数据
imageBitmap = imageLoader.content as Bitmap;
mList = new MaterialsList();
//线条材质
var xt:WireframeMaterial = new WireframeMaterial(0xFF00FF, 1, 2);
xt.interactive = ***e;
//颜色材质
var cl:ColorMaterial = new ColorMaterial(0x11FF55, 1);
//shape 图形
var shap:Shape = new Shape();
shap.graphics.beginFill(0x334455, 1);
shap.graphics.drawCircle(100, 100, 100);
var bitdata:BitmapData = new BitmapData(200, 200, ***e, 0x0);
bitdata.draw(shap);
//位图材质一 程序绘制
var bitM:BitmapMaterial = new BitmapMaterial(bitdata, ***e);
bitM.smooth = ***e;
//位图材质二 导入图片
var bitM2:BitmapMaterial = new BitmapMaterial(imageBitmap.bitmapData, ***e);
bitM2.smooth = ***e;
//位图材质三 导入图片
var bitM3:BitmapFileMaterial = new BitmapFileMaterial("assets/2.jpg");
bitM3.smooth = ***e;
//元件位图材质 IMG_0010库里的图片元件类名
var bitM4:BitmapAssetMaterial = new BitmapAssetMaterial("IMG_0010");
bitM4.smooth = ***e;
/*在Flex Builder and Flash Builder中使用元件是将元件转换成BitmapAsset对象 ,然后用
BitmapAsset的bitmapData属性然创建一个常规的BitmapMaterial.对象。
嵌入也可以实现。使用元数据标签[Embed]:如下面的代码所示:
[Embed (source="assets/mill.jpg")] public var mill:Class;
我们将mill.jpg文件导入为元件。命名为mill类,下面这行代码将创建mill
对象并将它转换成BitmapAsset格式。
var millAsset:BitmapAsset = new mill() as BitmapAsset;
然后创建位图材质,就像我们前面的做法一样。
var material:BitmapMaterial = new BitmapMaterial(millAsset.bitmapData);
注意这种方法只能在flex Builder 和Flash Builder 中使用。并且没有用到BitmapAssetMaterial
类。*/
var materialSprite:Sprite = new Sprite();
materialSprite.graphics.beginFill(0x333333);
materialSprite.graphics.drawRect(0,0,200,200);
var textfield:TextField = new TextField();
textfield.text = "Hello 3D world!";
textfield.autoSize = TextFieldAutoSize.LEFT;
textfield.setTextFormat(new TextFormat("Arial",25));
textfield.x = (materialSprite.width - textfield.width) / 2;
textfield.y = (materialSprite.height - textfield.height) / 2;
materialSprite.addChild(textfield);
//displayObject 子类做材质
var bitM5:MovieMaterial = new MovieMaterial(materialSprite);
bitM5.doubleSided = ***e;
bitM5.smooth = ***e;
//影片剪辑做材质
var bitM6:MovieAssetMaterial = new MovieAssetMaterial("mc1",false,***e,false,***e);
bitM6.doubleSided = ***e;
bitM6.smooth = ***e;
bitM6.interactive = ***e;
//bitM6.rect = new Rectangle(100,100,500,500);