this is best part of open source :) modify+sharing! :D

cheers!

On 3 September 2010 05:35, Fabrice3D <fabric...@gmail.com> wrote:

> I'm sure you'll make some AwayLite fans happy with this one :)
> thx for sharing Anton!
>
> Fabrice
>
> On Sep 3, 2010, at 12:31 AM, antonkul...@gmail.com wrote:
>
> > dear list,
> >
> > At the moment there is only one skybox class in away3lite and it works
> > only with one image. Sometimes it is rather unconvenient, for instance
> > most of the panoramic stitchers does not save to appropriate for
> > skybox6 format and you have to compose it manualy..
> > That's why I decided to write my own skybox class capable of working
> > with 6 images. Here it is:
> >
> > /*
> > Skybox class for away3dlite
> > The idea is very simple: bitmapdata's from images are stitched
> > together and then used as an ordinary skybox6 texture
> >
> > Anton Kulaga, september 2010
> > */
> > package skyboxes
> > {
> >       import away3dlite.materials.BitmapMaterial;
> >       import away3dlite.materials.ColorMaterial;
> >       import away3dlite.materials.Material;
> >       import away3dlite.primitives.Skybox6;
> >
> >       import flash.display.Bitmap;
> >       import flash.display.BitmapData;
> >       import flash.display.Loader;
> >       import flash.events.Event;
> >       import flash.geom.Point;
> >       import flash.geom.Rectangle;
> >       import flash.net.URLRequest;
> >
> >       public class Skybox extends Skybox6
> >       {
> >               protected var bigBitmap:BitmapData;
> >               protected var _path:String;
> >               protected var _format:String="jpg"
> >
> >
> >               public var loaders:Vector.<Loader>;
> >               public var bmds:Vector.<BitmapData>;
> >
> >               public var imgWidth:Number;
> >               public var imgHeight:Number;
> >               public var rect:Rectangle;
> >               public var mat:BitmapMaterial;
> >               public var numLoad:int=0;
> >               public var picNames:Vector.<String>;
> >
> >               public function
> > Skybox(picNames:Vector.<String>,path:String="",format:String="jpg")
> >               {
> >                       super(null,80000,5,1);
> >                       this._format = format;
> >                       this._path = path;
> >                       this.picNames = picNames;
> >                       this.bmds = new Vector.<BitmapData>;
> >                       this.loaders = new Vector.<Loader>;
> >                       if(this.picNames.length>=6)
> this.startLoaders(); //checks if there
> > are enough pictures for skybox
> >               }
> >
> >               protected function startLoaders():void
> >               {
> >                       for(var i:int=0;i<6;i++)
> >                       {
> >                               if(this.loaders.length<=i)
>  this.loaders.push(new Loader());
> >
> >
> this.loaders[i].contentLoaderInfo.addEventListener(Event.COMPLETE,this.loaderHandler);
> >                               this.loaders[i].load(new
> URLRequest(_path+"/"+picNames[i]
> > +"."+this._format));
> >                       }
> >               }
> >
> >               protected function loaderHandler(event:Event):void
> >               {
> >                       this.numLoad++;
> >                       if(this.numLoad < 6) return void;
> >                       this.fromLoadersToBmps();
> >                       this.makeBigBitmap();
> >               }
> >
> >
> >               //extracts bitmaps from loaders to bitmapdata Vector
> >               protected function fromLoadersToBmps():void
> >               {
> >                       var bmp:BitmapData;
> >                       for(var i:int=0;i<this.loaders.length;i++)
> >                       {
> >                               bmp =
> > Bitmap(this.loaders[i].contentLoaderInfo.content).bitmapData;
> >                               if(this.bmds.length<=i) this.bmds[i] = bmp;
> else
> > this.bmds.push(bmp);
> >                       }
> >                       this.numLoad=0;
> >               }
> >
> >               protected function initBigBitmap():void
> >               {
> >                       this.imgHeight = this.bmds[0].height;
> >                       this.imgWidth = this.bmds[0].width;
> >                       this.rect = new
> Rectangle(0,0,this.imgWidth,this.imgHeight);
> >                       this.bigBitmap = new
> BitmapData(this.imgWidth*3,this.imgHeight*2);
> >                       this.material = new BitmapMaterial(this.bigBitmap);
> >                       BitmapMaterial(this.material).smooth = true;
> >               }
> >
> >               //makes one bitmap from all loaded bitmaps
> >               protected function makeBigBitmap():void
> >               {
> >                       if(!this.bigBitmap) this.initBigBitmap();
> >                       this.bigBitmap.copyPixels(this.front,this.rect,new
> Point(0,0));
> >                       this.bigBitmap.copyPixels(this.right,this.rect,new
> > Point(this.imgWidth,0));
> >                       this.bigBitmap.copyPixels(this.back,this.rect,new
> > Point(this.imgWidth*2,0));
> >
> >                       this.bigBitmap.copyPixels(this.left,this.rect,new
> > Point(0,this.imgHeight));
> >                       this.bigBitmap.copyPixels(this.top,this.rect,new
> > Point(this.imgWidth,this.imgHeight));
> >                       this.bigBitmap.copyPixels(this.bottom,this.rect,new
> > Point(this.imgWidth*2,this.imgHeight));
> >               }
> >
> >               //getters for bitmapdatas
> >               public function get front():BitmapData {return
> this.bmds[0];}
> >               public function get right():BitmapData {return
> this.bmds[1];}
> >               public function get back():BitmapData {return
> this.bmds[2];}
> >               public function get left():BitmapData {return
> this.bmds[3];}
> >               public function get top():BitmapData {return this.bmds[4];}
> >               public function get bottom():BitmapData {return
> this.bmds[5];}
> >       }
> > }
>
>


-- 
Regards
-----------------------------------------------------------
Todsaporn Banjerdkit, katopz, http://sleepydesign.com
Away3DLite and JigLibFlash Developer Team

Reply via email to