`
hereson
  • 浏览: 1449934 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

BitmapFileMaterial的用法

    博客分类:
  • Pv3d
阅读更多
package com.hclown.earth3d.map
{
    import org.papervision3d.objec ts.Plane;
    import org.papervision3d.materials.BitmapFileMaterial;
    import org.papervision3d.events.FileLoadEvent;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.BitmapMaterial;
    import flash.display.BitmapData;
   
    /**
     * 瓦片对象
     **/
    public class TilePlane extends Plane
    {
        private var imgUrl:String = null;
       
        private var bitmapMaterial:BitmapFileMaterial = null;
       
        /**
         * 构建一个瓦片面板
         * @parm imgUrl 渲染面板的图片
         **/
        public function TilePlane(imgUrl:String,width:Number,height:Number){
            this.bitmapMaterial = new BitmapFileMaterial();
            this.bitmapMaterial.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleFileLoaded);
            this.bitmapMaterial.doubleSided = true;
            this.bitmapMaterial.smooth = true;
            this.imgUrl = imgUrl;
            super(this.bitmapMaterial,width,height,4,4);
        }
       
        /**
         * 设置TilePlane的定位点,默认z=0
         **/
        public function setPosition(x:Number,y:Number,z:Number):void{
            this.x = x;
            this.y = y;
            this.z = z;
        }
       
        /**
         * 设置TilePlane的图片地址
         **/
        public function setImgUrl(url:String):void{
            this.imgUrl = url;
            refreshPlane();
        }
       
        /**
         * 获取TilePlane的图片地址
         **/
        public function getImgUrl():String{
            return this.imgUrl;
        }
       
        //初始化Plane
        private function refreshPlane():void{
            trace("1");
            this.bitmapMaterial = new BitmapFileMaterial();
            this.bitmapMaterial.addEventListener(FileLoadEvent.LOAD_COMPLETE, handleFileLoaded);
            this.bitmapMaterial.texture = this.imgUrl;
            trace("2");
        }
       
        protected function handleFileLoaded(e:FileLoadEvent):void
        {
            trace("3");
            this.bitmapMaterial.texture = this.imgUrl;
            //var plane:Plane = new Plane(this.material,256,256,4,4);
            //this.addChild(plane);
            trace("4");
        }
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics