pokemon yiff art wedding invitations wording samples in spanish online melbourne chat sample student resume cigarette brands nicotine content t shirt printing machine for sale google earth free download sawgrass mills mall directory map evil desktop themes mercedes benz parts diagrams download dragonball game pontiac g8 gxp for sale used subwoofer wiring diagram crutchfield download balkan download gamecube emulator mac salary calculator pocket tanks deluxe download mac check engine mitsubishi eclipse of land pollution 3d kitchen design software flashget download mercury outboard serial identification free ball licking movies happy jesus song download the fuji viewer wine enthusiast coupon codes salary of professional athletes free pron movies radio flyer scooter target minivan rental orlando florida drug ultram mozzila slo download harley davidson sportster parts accessories nikon coolpix l100 10mp digital camera review nikon d3000 dslr camera price vintage cigarette cases for women scheduling software paige jeans funny quotes from movies hangover levitra clinical trials online pharmacy phentermine xenical hair cuttery coupons printable downloadable dbz computer games mitsubishi lancer evolution x body kits digital camera reviews canon powershot sx120 cheap usb flash drives bulk rpg maker xp download free full costumes for cats musical guitar pro 5 free download torrent furniture warehouse san diego kearny mesa autodesk revit architecture 2010 crack rapidshare antares auto tune mac crack winter olympics locations history glass pipes and bongs for sale honeymoon packages in india with prices free website builder for mac os x free animated powerpoint backgrounds subwoofer reviews home audio pizza hut menu and price list rolex watches for men uk yamaha atv parts diagrams free models download kia sorento 2011 reviews weather channel radar florida mitsubishi electric mr slim air conditioning atheros ar5005g wireless network adapter driver xp camera reviews nikon coolpix s203 used toyota tacoma prerunner double cab for sale family cruises deals 2010 honda generators for sale used laminate kitchen countertops belkin n1 wireless router setup guide egyptian symbols alphabet malayalam movies 2009 watch online autodesk sketchbook pro 2010 mac torrent dell printer drivers for mac os x big trucks parking games fruity loops download golf magazine top 100 courses you can play nintendo dsi xl reviews bmw x5 repair manual haircuts fine hair free 2d animation software for beginners 1999 chrysler sebring convertible problems hyundai sonata 2011 pictures shu uemura art of hair autodesk inventor 2010 student download movies on demand brighthouse list snow white and the seven dwarfs story online 2010 subaru forester xt limited review tattoos designs for men free dvd release schedule 2010 wireless g usb network adapter driver download mitsubishi tv remote codes free nintendo 64 emulators for mac funny pictures of people with no teeth bluetooth dongle software download vista gps reviews consumer reports hyundai sonata 2011 prices samsung lcd tv problems no picture plants vs zombies free download full version mac samsung omnia apps free download honda crv maintenance schedule 2004 microsoft flight simulator x demo crack honda civic type r for sale in us race v3 download playstation network card numbers for free flowers by zoe website wine country gift baskets coupon code free shipping xbox live gold subscription trial generator atheros ar5007eg wireless network adapter vista driver rpg maker xp keygen download cool desktop backgrounds for macbook football for dummies positions roses department store employment camcorders for sale uk flashget for mac free download honda civic 2010 pictures uae download sim city full toyota gas pedal recall list free flight simulator games online mattress factory direct post wedding reception invitation wording examples jeep cherokee accessories rpg maker vx resources battlers sony vegas 9 torrent mininova dvd decrypter download mac jewelry exchange reviews tustin nissan leaf release date honda crv parts used genuine subaru parts online harley davidson dealers in california hp compaq presario v5000 memory laminate wood flooring stairs active desktop calendar download free nintendo ds roms download professor layton playstation network card numbers rolex oyster perpetual datejust prices spanish music lyrics for free cable modem hack comcast original xbox live codes for free windowblinds serial red pubic hair japanese dating sim games ds free download full poker nikon d90 prices dubai sof2 wallhack download snowflake patterns to cut out for kids doctor serial number compaq laptops drivers cq40 kode gta san download bmw x6 reviews pinewood derby templates 2003 bmw m3 convertible hardtop star wars download jeep grand cherokee srt8 for sale in texas vadivel comedy download mud tires for sale cheap download pokemon game on pc mitsubishi lancer evolution x wallpaper female shaving pubic hair volkswagen cc reviews 2010 genuine microsoft software download windows click 1979 volkswagen beetle convertible for sale soccer practice drills honda generators prices in pakistan autodesk maya 2010 serial number and product key isuzu trooper diesel craigslist windows digital desktop background siding brake video down jackets for tall women xnxx flash jeep grand cherokee laredo 2000 manual rolex submariner used fonts calibri download replica handbags flight simulator 2004 demo free download w200i games free download download indian video songs conexant modem drivers for xp sony vegas 9 keygen serial flash player for mac snow leopard kaspersky internet key generator cowgirl boots for women cheap samsung eternity applications free download autodesk autocad 2010 torrent download winter olympics 2010 hockey bonzi download compaq presario v6000 wireless driver download winter olympics 2010 hockey teams download antares autotune 5 free download igra nfs subaru impreza outback sport forum cigarette prices by state map xbox live gold membership card 12 months buttmans art gallery youtube to mp3 converter for mac os x free download avid liquid linux mint 8 usb bootable dvd43 64 bit windows 7 virtual dj software download free full version warcraft 2 cheat codes small tattoos for girls on feet plants vs zombies free full version download link samsung i8000 omnia 2 reviews cricket flash games free download for pc evening dresses to buy online hindi movies released in 2009 list mobile phone free nintendo ds emulator download for pc camping checklist excel xbox live gold code generator download belkin wireless g usb network adapter driver download atheros ar928x wireless network adapter driver windows 7 hair gallery free flash hair photos hentai sim game tonya harding honeymoon video beowulf the movie monster trucks games for kids online download winzip incest chat rooms free rated movie clips honda accord body kit racer v3 download music player download for nokia 3110c enclosure subwoofer box dangerous dave download hot cartoon games lolita art handbags outlet online nudist art watch hindi movies free online without downloading msn account cracker download program football manager training schedules 2010 pictures of pubic hair styles download titans free oompa loompa costumes restaurant organizational chart met art underwear models photos play for free slot machine design your own wedding dress virtual antivirus bit torrent guild keygen inflation game adobe flash player for iphone safari dresses to wear to a wedding as a guest halo download mugen download microsoft office phone activation code keygen als scan download combofix mazda 626 manual book women their pubic hair black movies gamecube isos direct download marketing sample download free counter strike cd key nikon d40 kit refurbished at work brazzer hairstyles for women over 50 years old pictures free software downloads for blackberry curve 8520 printable viagra coupon lavetria plus size bra sony handycam dcr 30 driver vista tifa flash antivirus free download key gen sony vegas 9 serial number generator free download tamil mp3 songs download entrance theme adobe cs2 serial number activation code kaspersky keyboard symbol art download microsoft frontpage skype emoticons art happy birthday ubuntu smb password small bathroom remodeling ideas pictures free guitar pro download full version suzuki kizashi forum pizza hut delivery number malaysia dvdfab platinum 6 keygen dating rpg games online compaq evo drivers downloads dvdfab 6 registration key torrent malayalam movies free online watch famous graffiti artists list nokia 3110c music player download free slow down flash games freeware gamecube roms zelda the wind waker snow patrol chasing cars mp3 4shared opel astra parts catalog volkswagen beetle convertible for sale used guitar pro tabs free download summer fashion internships for high school students in nyc honda fit 2009 owners manual pdf opel astra wagon 2010 flash games index swf iskysoft dvd ripper for mac serial number autodesk maya 2010 crack nudity games compaq presario v2000 drivers skype download for blackberry curve 8900 compaq presario v6000 drivers for xp download porsche cayenne reliability 2004 warcraft 3 frozen throne torrent download free buy vans shoes online cheap desi movies watch online free kawasaki mule 3010 service manual dating sim rpg games for girls boeing 747 flight simulator games online windows server 2008 activation crack download toyota recall list of cars samsung cdma mobile phones microsoft points and xbox live gold membership generator sony vegas 9 keygen digital insanity tattoo ideas for men leg summer 2010 internships nintendo gamecube roms free download warcraft 3 download full game torrent best juice fasting recipes delta airlines flight attendant jobs rolex datejust oyster perpetual price wedding dresses for sale second hand flight simulator 2004 free download full version free skype video recorder for mac samsung led tv 6000 best settings sister wedding invitation wordings india miniclip flash games free download for pc kia sportage 2010 review hindu wedding card invitation wordings jacket sewing patterns free funny wedding invitation wording examples nokia 6300 music player download free best snow leopard hackintosh netbook porsche cayenne hybrid release date winterbells no sound dvd shrink for vista 64 bit download guitar pro 5 free download with crack 48 hour xbox live codes generator winterbells full screen game dvd shrink free download windows 7 volkswagen beetle for sale by owner watch movies online streaming megavideo sony vegas movie studio 9 platinum keygen warcraft 3 torrent limewire extended pro free download car battery trickle charger reviews gamecube emulator for psp satellite tv for pc 2009 titanium edition crack ar rehman video download compaq presario f700 drivers download nismo nissan skyline r34 gtr z tune for sale transparent desktop calendar freeware rpg maker vx activation code motorcycle superstore coupon 20 off chrysler town and country commercial music dvdfab 6 crack code dvd43 windows 7 compatible equipment rental agreement template free flight simulator x deluxe edition download volkswagen parts catalog online desktop themes for mac os x leopard xbox 360 hard drive transfer disc iso compaq presario c700 drivers malayalam movies free online watching snowboard boots reviews 2010 compaq presario drivers c500 samsung led tv 6000 problems xbox live gold membership codes free marlboro cigarette prices in north carolina isuzu trooper engine rebuild dvdfab 6 registration key free software testing tutorial pdf burton snowboard boots clearance famous quotes about life lessons bluetooth hack software nokia samsung omnia apps torrent samsung moment battery life issues sony ericsson k550i mazda miata parts diagram morgan movies compaq presario sound drivers free download soccer poems download vga for windows xp live satellite view of my house free t shirt gallery facebook bypass proxy server download full version gta3 birthday cake templates satellite view of my house real time nokia maps code hack ford motor company recalls 2009 cigarette lighting misa photoshoot download samsung impression apps free igre za mobitel download battery charger circuit schematic coolest desktop theme account cracker free download offline rpgs for pc sagem unlock codes mazda 626 timing belt monitor repair manual aurora snow flash flash revolution resonance take off my bra desktop destroyer 2 game moto racer download download dat mcafee update wow armory ensidia skinhead tattoo galleries free online templates for business cards free fretwork scroll saw patterns nature art gallery clips pants off dance off unedited sunny download free applications for mobile phones compaq evo drivers d51c games in eboot zip files tattoo magazines caribbean cruise line bahamas celebration scam youtube headshave golf gps comparison reviews download habbo hack mercedes 300sl gullwing sofa beds for sale ikea repossessed cars for jeeps for sale in pa pictures of highlighted hair download klm caribbean cruise line free cruise voucher lingerie models nude clothes steamer comparison norton antivirus code mms jamshedpur schools warcraft armory blackberry download pokemon ruby version wedding invitations wording samples microsoft security center antivirus override free antivirus for p3300 rpg maker vx sprite generator micro download keyboard symbols pictures sign in sheet templates free program templates download inspirat free wet t shirt wedding invitation wording templates soccer bulge current job vacancies in nigeria cashman slot donkey pc full download replica toy guns for sale i a japanese game show house of brides free powerpoint templates business free game download guitar chord chart for beginners antivirus plus v10 license key marathi download how to yourself a blow job free download form defend your castle flash game autoplay removal tool john mccain official website download san andreas where i download simtractor free free pantyhose movies samsung unlock codes fuse box diagram dodge dakota hidden games completly free avast antivirus free software sissy husband dress armpit hair galleries programi download glasbe free honda atv manuals online vista 64bit sony drivers bust move free download the perfume movie download spam list sign up software architecture design document sample contract template xbox 360 60gb hard drive transfer cable live satellite images of my house free buy rohypnol online ancient egypt food recipes for kids sony outlet short funny jokes one liners email marketing software freeware adobe raider download new marathi movies watch online student examples of letter writing flight simulator x acceleration expansion pack rapidshare cheap replica chanel designer handbags stronghold download compaq presario c700 drivers for vista free download certificate templates autodesk revit mep 2010 training compaq presario v6000 drivers download sample birth certificate nintendo ds emulator download for pc free sissy dress battery warehouse direct reviews compaq presario c700 hard drive replacement kalonline download t shirt printing machines for sale uk mazda protege free repair manuals dvdfab 6 registration key generator torrent nintendo ds roms torrent download wedding dance by amador daguio sony cybershot dsc s930 digital camera price in india free agenda templates summary of trojan war


Tag Archive for 'TweenLite'

Adding XML to the Papervision Coverflow

Papervision Coverflow XML feed

As a simple addition to yesterday's coverflow post, I wanted to show the same example but with loading images via XML. For simplicity sake the XML is loaded and parsed all in the main file.

The structure for our XML is very simple:

XML:
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <data>
  3.     <image><![CDATA[images/image1.jpg]]></image>
  4.     <image><![CDATA[images/image2.jpg]]></image>
  5.     <image><![CDATA[images/image3.jpg]]></image>
  6.     <image><![CDATA[images/image5.jpg]]></image>
  7.     <image><![CDATA[images/image4.jpg]]></image>
  8.     <image><![CDATA[images/image6.jpg]]></image>
  9.     <image><![CDATA[images/image7.jpg]]></image>
  10. </data>

We simply load our XML file with BulkLoader

Actionscript:
  1. protected function loadXML():void
  2. {
  3.     bulkInstance = new BulkLoader("bulkInstance");     
  4.     bulkInstance.add(xmlPath);
  5.     bulkInstance.addEventListener(BulkProgressEvent.COMPLETE, onXMLReady);
  6.     bulkInstance.start();
  7. }

Parse the results, now adding the images to the BulkLoader:

Actionscript:
  1. protected function onXMLReady(evt:BulkProgressEvent):void
  2. {
  3.     bulkInstance.removeEventListener(BulkProgressEvent.COMPLETE, onXMLReady);
  4.     bulkInstance.addEventListener(BulkProgressEvent.COMPLETE, onImagesReady);
  5.    
  6.     var xml:XML = bulkInstance.getXML(xmlPath);
  7.     var xmlList:XMLList = xml.image;
  8.    
  9.     for (var i:int = 0; i <xmlList.length(); i++)
  10.     {
  11.         var imagePath:String = String(xmlList[i])
  12.         bulkInstance.add(imagePath);
  13.        
  14.         //Add path to array for later access
  15.         images.push(imagePath);
  16.     }
  17.    
  18.     //Set our number of items based on how many images we load
  19.     numItems = images.length;
  20. }

When our images are ready we can continue the process of setting up our coverflow. But now using the images we just loaded for our materials.

Actionscript:
  1. var mat:BitmapMaterial  = new BitmapMaterial(bulkInstance.getBitmapData(images[i]));

It's that simple. Be sure to let us know if you find this useful and are able to use it in a project.

Here is the full code:

Actionscript:
  1. package
  2. {
  3.     import br.com.stimuli.loading.BulkLoader;
  4.     import br.com.stimuli.loading.BulkProgressEvent;
  5.     import flash.display.Sprite;
  6.     import flash.events.MouseEvent;
  7.     import flash.filters.GlowFilter;
  8.     import gs.easing.Quint;
  9.     import gs.TweenLite;
  10.     import org.papervision3d.events.InteractiveScene3DEvent;
  11.     import org.papervision3d.materials.BitmapMaterial;
  12.     import org.papervision3d.objects.DisplayObject3D;
  13.     import org.papervision3d.objects.primitives.Plane;
  14.     import org.papervision3d.view.BasicView;
  15.    
  16.     /**
  17.      * ...
  18.      * @author Charlie Schulze, charlie[at]woveninteractive[dot]com
  19.      * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
  20.      */
  21.    
  22.     public class Main extends BasicView
  23.     {
  24.         protected var planes:Array = [];
  25.         protected var images:Array = [];
  26.         protected var numItems:Number;
  27.         protected var currentItem:Number = 3;
  28.         protected var angle:Number = 25;       
  29.         protected var rightBtn:Sprite;
  30.         protected var leftBtn:Sprite;
  31.         protected var xmlPath:String = "xml/imageXML.xml";
  32.         protected var bulkInstance:BulkLoader;
  33.        
  34.         public function Main():void
  35.         {
  36.             //Make sure that your scene is set to interactive
  37.             super(640, 480, true, true);
  38.             loadXML();
  39.         }
  40.        
  41.         //First load our XML
  42.         protected function loadXML():void
  43.         {
  44.             bulkInstance = new BulkLoader("bulkInstance");     
  45.             bulkInstance.add(xmlPath);
  46.             bulkInstance.addEventListener(BulkProgressEvent.COMPLETE, onXMLReady);
  47.             bulkInstance.start();
  48.         }
  49.        
  50.         //When our xml is ready parse and load our images
  51.         protected function onXMLReady(evt:BulkProgressEvent):void
  52.         {
  53.             bulkInstance.removeEventListener(BulkProgressEvent.COMPLETE, onXMLReady);
  54.             bulkInstance.addEventListener(BulkProgressEvent.COMPLETE, onImagesReady);
  55.            
  56.             var xml:XML = bulkInstance.getXML(xmlPath);
  57.             var xmlList:XMLList = xml.image;
  58.            
  59.             for (var i:int = 0; i <xmlList.length(); i++)
  60.             {
  61.                 var imagePath:String = String(xmlList[i])
  62.                 bulkInstance.add(imagePath);
  63.                
  64.                 //Add path to array for later access
  65.                 images.push(imagePath);
  66.             }
  67.            
  68.             //Set our number of items based on how many images we load
  69.             numItems = images.length;
  70.         }
  71.        
  72.         //Images are finished loading we can now create our papervision coverflow
  73.         protected function onImagesReady(evt:BulkProgressEvent):void
  74.         {
  75.             init();
  76.         }
  77.        
  78.         protected function init():void
  79.         {
  80.             createChildren();
  81.             createNavigation();
  82.             animate();
  83.             startRendering();
  84.         }
  85.         protected function createChildren():void
  86.         {
  87.             for (var i:int = 0; i <numItems; i++)
  88.             {
  89.                 //Grab our bitmapData from the bulkLoader using our array of image paths as our key
  90.                 var mat:BitmapMaterial  = new BitmapMaterial(bulkInstance.getBitmapData(images[i]));
  91.                 mat.interactive         = true;
  92.                 mat.smooth     = true;
  93.                 var plane:Plane         = new Plane(mat, 280, 351, 4, 4);
  94.                
  95.                 planes.push(plane);
  96.                
  97.                 //Click straight to any plane
  98.                 plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, onPlaneClick);
  99.                
  100.                 //Set an id to target current item
  101.                 plane.id = i;
  102.                
  103.                 //Add plane to the scene
  104.                 scene.addChild(plane);
  105.             }
  106.            
  107.             camera.zoom = 50;
  108.         }
  109.        
  110.         protected function onPlaneClick(evt:InteractiveScene3DEvent):void
  111.         {
  112.             currentItem = evt.target.id;
  113.             animate();
  114.         }
  115.        
  116.         //Animate the coverflow left / right based off of currentItems
  117.         protected function animate():void
  118.         {
  119.             for (var i:int = 0; i <planes.length; i++)
  120.             {
  121.                 var plane:Plane = planes[i];
  122.                
  123.                 //Each if statement will adjust these numbers as needed
  124.                 var planeX:Number = 0;
  125.                 var planeZ:Number = -50;
  126.                 var planeRotationY:Number = 0
  127.  
  128.                 //Place  & Animate Center Item
  129.                 if (i == currentItem)
  130.                 {
  131.                     planeZ     = -300
  132.                    
  133.                     TweenLite.to(plane, 1, { rotationY:planeRotationY,x:planeX,z:planeZ, ease:Quint.easeInOut } );
  134.                 }
  135.                
  136.                 //Place & Animate Right Items
  137.                 if(i> currentItem) 
  138.                 {
  139.                     planeX     = (i - currentItem + 1) * 120;
  140.                     planeRotationY   = angle + 10 * (i - currentItem);
  141.                    
  142.                     TweenLite.to(plane, 1, { rotationY:planeRotationY,x:planeX,z:planeZ, ease:Quint.easeInOut } );
  143.                 }
  144.                
  145.                 //Place & Animate Left Items
  146.                 if (i <currentItem)
  147.                 {
  148.                     planeX     = (currentItem - i + 1) * -120;
  149.                     planeRotationY   = -angle - 10 * (currentItem - i);
  150.                    
  151.                     TweenLite.to(plane, 1, { rotationY:planeRotationY,x:planeX,z:planeZ, ease:Quint.easeInOut } );
  152.                 }
  153.             }
  154.         }
  155.        
  156.         /*
  157.          * Everything below this point is just for creating the buttons and
  158.          * setting button events for controlling the coverflow.
  159.          */
  160.  
  161.         protected function createNavigation():void
  162.         {
  163.             //Create / Add Buttons
  164.             rightBtn = createButton();
  165.             leftBtn = createButton();
  166.                
  167.             addChild(leftBtn);
  168.             addChild(rightBtn);
  169.            
  170.             //Add button listeners
  171.             rightBtn.buttonMode = true;
  172.             leftBtn.buttonMode = true;
  173.             rightBtn.addEventListener(MouseEvent.CLICK, buttonClick);
  174.             leftBtn.addEventListener(MouseEvent.CLICK, buttonClick);
  175.                        
  176.             //Place buttons on stage
  177.             rightBtn.x    = stage.stageWidth - 20;
  178.             leftBtn.x       = 20;
  179.             rightBtn.y    =  stage.stageHeight / 2;
  180.             leftBtn.y       =  (stage.stageHeight / 2) + 20;
  181.             leftBtn.rotation    = 180;
  182.         }
  183.        
  184.         //Button actions
  185.         protected function buttonClick(evt:MouseEvent):void
  186.         {
  187.             switch (evt.target)
  188.             {
  189.                 case rightBtn:
  190.                 currentItem ++
  191.                 break;
  192.                
  193.                 case leftBtn:
  194.                 currentItem --;
  195.                 break;
  196.             }
  197.            
  198.             //Don't allow any number lower than 0 or past max so there
  199.             //is always a center item
  200.            
  201.             if (currentItem <0)
  202.             {
  203.                 currentItem = 0;
  204.             }
  205.             if (currentItem> (planes.length - 1))
  206.             {
  207.                 currentItem = planes.length - 1;
  208.             }
  209.            
  210.             //Call animation
  211.             animate();
  212.         }
  213.        
  214.         //Creates a simple arrow shape / returns the sprite
  215.         protected function createButton():Sprite
  216.         {
  217.             var btn:Sprite = new Sprite();
  218.            
  219.             btn.graphics.beginFill(0x333333);
  220.             btn.graphics.moveTo(0, 0);
  221.             btn.graphics.lineTo(0, 20);
  222.             btn.graphics.lineTo(10, 10);
  223.             btn.graphics.lineTo(0, 0);
  224.             btn.graphics.endFill();
  225.             btn.filters = [new GlowFilter(0xFFFFFF,1,10,10,3)]
  226.             return btn;
  227.         }
  228.     }
  229. }

Post to Twitter Post to Delicious Delicious Post to Digg Digg This Post Post to Facebook Facebook Post to StumbleUpon Stumble This Post

Papervision Explode Image / Rebuild

In early 2008 I wrote a blog article on how to explode an image and rebuild it again. Recently this effect has been used in some amazing ways. Site's like Audi have taken this concept much further with the rows of these tiny boxes swimming in formation.

Today I decided to re-create that simple effect using the latest papervision code and provide a much needed update.

Creating this effect is actually fairly simple. You take an image, use some code to break it into smaller bitmaps which then are used as the materials for your planes. Then you just place the planes in a grid to re-create your image.

Here is a sample of the code that get's our image blocks to be used for our materials:

Actionscript:
  1. //Creates a 30 x 18 bitmapData block
  2. var bitmap_data:BitmapData  = new BitmapData(cellWidth, cellHeight, true, 0x00FFFF);
  3.                
  4. //Create a new Matrix - A matrix is a rectangular array / table
  5. //of numbers with any number of rows / columns.
  6. var matrix:Matrix         = new Matrix();
  7.  
  8. //Get's our desired x / y location information where we will
  9. //pull a block of our image
  10. matrix.translate( -cellWidth * cellX, -cellHeight * cellY);
  11.  
  12. //Write the data to our bitmap data object with our source and
  13. //matrix / block info
  14. bitmap_data.draw(imageMC, matrix);

Once you've created your grid you just need to store the locations of all your x,y,z,rotation etc so that when you break apart the image you can easily piece it back together.

Actionscript:
  1. planeVO.origX         = pl.x;
  2. planeVO.origY            = pl.y;
  3. planeVO.origZ         = pl.z;
  4. planeVO.origRotationY      = pl.rotationY;
  5. planeVO.origRotationX      = pl.rotationX;
  6. planeVO.origRotationZ      = pl.rotationZ;
  7. planeVO.planeRef          = pl;

PlaneVO is nothing more than a simple value object. A value object gives us a nice strongly typed object to store the variables we want to access later.

PlaneVO.as

Actionscript:
  1. package
  2. {
  3.     import org.papervision3d.objects.primitives.Plane;
  4.     /**
  5.      * ...
  6.      * @author Charlie Schulze, Woven Interactive, LLC
  7.      */
  8.     public class PlaneVO
  9.     {
  10.         public var origX:Number;
  11.         public var origY:Number
  12.         public var origZ:Number
  13.         public var origRotationY:Number
  14.         public var origRotationX:Number
  15.         public var origRotationZ:Number
  16.         public var planeRef:Plane;
  17.     }
  18.    
  19. }

Now on to the full code. I have left comments throughout to explain what is happening. Try changing some of the math or swapping the image with your own. Once you mess with it for a little while you'll find it's easy to create some amazing effects.

Actionscript:
  1. package
  2. {
  3.     import br.com.stimuli.loading.BulkLoader;
  4.     import br.com.stimuli.loading.BulkProgressEvent;
  5.     import com.foomonger.utils.Later;
  6.     import flash.display.Bitmap;
  7.     import flash.display.BitmapData;
  8.     import flash.display.DisplayObject;
  9.     import flash.display.MovieClip;
  10.     import flash.geom.Matrix;
  11.     import gs.easing.Quint;
  12.     import gs.TweenMax;
  13.     import org.papervision3d.materials.MovieMaterial;
  14.     import org.papervision3d.objects.DisplayObject3D;
  15.     import org.papervision3d.objects.primitives.Plane;
  16.     import org.papervision3d.view.BasicView;
  17.    
  18.     /**
  19.      * ...
  20.      * @author Charlie Schulze, charlie[at]woveninteractive[dot]com
  21.      */
  22.    
  23.     public class Main extends BasicView
  24.     {
  25.         protected var bulkInstance:BulkLoader;
  26.         protected var imageMC:MovieClip;
  27.         protected var imageString:String
  28.         protected var planeVOs:Array = [];
  29.         protected var planesContainer:DisplayObject3D;
  30.        
  31.         public function Main():void
  32.         {
  33.             super();
  34.            
  35.             //Set the image we want to load
  36.             imageString  = "images/king.gif";
  37.            
  38.             //Load our image
  39.             loadImage();
  40.         }
  41.         protected function loadImage():void
  42.         {
  43.             //BulkLoader is complete overkill for this but thought it would be a
  44.             //nice extra for everyone to see in action. Extremely useful set of classes.
  45.            
  46.             //Create our unique bulkInstance / available anywhere in our app by
  47.             //that name "bulkImageLoader"
  48.             bulkInstance = new BulkLoader("bulkImageLoader");
  49.            
  50.             //Add our image
  51.             bulkInstance.add(imageString);
  52.            
  53.             //Add our listeners
  54.             bulkInstance.addEventListener(BulkProgressEvent.COMPLETE, onImageLoaded);
  55.            
  56.             //Start Loading
  57.             bulkInstance.start();
  58.         }
  59.         protected function onImageLoaded(evt:BulkProgressEvent):void
  60.         {
  61.             init();
  62.         }
  63.         protected function init():void
  64.         {
  65.             createChildren();
  66.             explode();
  67.             startRendering();
  68.         }
  69.        
  70.         protected function createChildren():void
  71.         {
  72.             //Create the clip we will be getting our bitmap data from
  73.             imageMC = new MovieClip();
  74.            
  75.             //add our bitmap
  76.             imageMC.addChild(bulkInstance.getBitmap(imageString));
  77.  
  78.             //Optional - Create a container to hold our planes
  79.             planesContainer = new DisplayObject3D();
  80.            
  81.             //Array to store our value objects
  82.             planeVOs = [];
  83.            
  84.             for (var i:int = 0; i <65; i++)
  85.             {
  86.                 /**
  87.                  * Here is how we get our loop / colunm / cellWidth / cellHeight numbers
  88.                  *
  89.                  * 5 columns * 13 rows = 65 (number of loops)
  90.                  * 5 columns divided by the width (150) of our image = 30 pixels
  91.                  * 13 rows  divided by the height (234) of our image = 18 pixels
  92.                  */
  93.  
  94.                 var columns:uint          = 5;
  95.                 var cellWidth:int       = 30;
  96.                 var cellHeight:int    = 18;
  97.                 var cellX:int         = (i % columns)
  98.                 var cellY:int         = Math.floor(i / columns);
  99.  
  100.                 //Creates a 30 x 18 bitmapData block
  101.                 var bitmap_data:BitmapData  = new BitmapData(cellWidth, cellHeight, true, 0x00FFFF);
  102.                
  103.                 //Create a new Matrix - A matrix is a rectangular array / table
  104.                 //of numbers with any number of rows / columns.
  105.                 var matrix:Matrix         = new Matrix();
  106.                
  107.                 //Get's our desired x / y location information where we will
  108.                 //pull a block of our image
  109.                 matrix.translate( -cellWidth * cellX, -cellHeight * cellY);
  110.                
  111.                 //Write the data to our bitmap data object with our source and
  112.                 //matrix / block info
  113.                 bitmap_data.draw(imageMC, matrix);
  114.                
  115.                 //Create a bitmap with our bitmapData and add it to a movieclip
  116.                 var bitmap:Bitmap       = new Bitmap(bitmap_data);
  117.                 var myMovie:MovieClip     = new MovieClip();
  118.                
  119.                 myMovie.addChild(bitmap);
  120.                
  121.                 //Use the movieclip with our bitmap inside as our movieMaterial
  122.                 //needs to be cast as a DisplayObject to work
  123.                 var movieMat:MovieMaterial  = new MovieMaterial(myMovie as DisplayObject, true);
  124.                 movieMat.smooth             = true;
  125.                
  126.                 //Create a plane with our moviemat the size of our cellWidth/Height
  127.                 var pl:Plane             = new Plane(movieMat, cellWidth, cellHeight, 0, 0);
  128.                
  129.                 //Create a value object to store our origianl infomation
  130.                 //for when we animate we can then rebuild easily
  131.                 var planeVO:PlaneVO         = new PlaneVO();
  132.  
  133.                 //We want to place the planes to re-create our original image
  134.                 pl.x                        = ((cellX * cellWidth) + cellWidth) -(imageMC.width / 2);
  135.                 pl.y                   = -((cellY * cellHeight) + cellHeight) +(imageMC.height / 2);
  136.                
  137.                 //Set the original properties of our value object
  138.                 planeVO.origX         = pl.x;
  139.                 planeVO.origY            = pl.y;
  140.                 planeVO.origZ         = pl.z;
  141.                 planeVO.origRotationY      = pl.rotationY;
  142.                 planeVO.origRotationX      = pl.rotationX;
  143.                 planeVO.origRotationZ      = pl.rotationZ;
  144.                 planeVO.planeRef          = pl;
  145.                
  146.                 //Add our planeVO to our array
  147.                 planeVOs.push(planeVO)
  148.                
  149.                 //Add planes to our container
  150.                 planesContainer.addChild(pl);            
  151.             }
  152.            
  153.             //Add our container to our scene
  154.             scene.addChild(planesContainer);
  155.            
  156.             camera.zoom = 100;
  157.            
  158.             //rotate our container for an skewed effect
  159.             planesContainer.rotationY = 30;
  160.             planesContainer.rotationX = 30;
  161.         }
  162.        
  163.         protected function explode():void
  164.         {
  165.             //Create a for loop of our plane objects set random numbers to explode our image
  166.            
  167.             for (var i:int = 0; i <planeVOs.length; i++)
  168.             {
  169.                 var planeVO:PlaneVO     = planeVOs[i];
  170.                 var plane:Plane         = planeVO.planeRef;
  171.                
  172.                 var ranNumber:Number = Math.round(Math.random() * 200 - 200);
  173.                 var delayAmount:Number = i * .05;
  174.                 var shortDelayAmount:Number = delayAmount * .6;
  175.                
  176.                 var randomX:Number = (Math.random() * 4000) - 6000;
  177.                 var randomY:Number = (Math.random() * 8000) - 1000;
  178.                 var randomZ:Number = (Math.random() * 1000) + 5000;
  179.  
  180.                 TweenMax.to(plane, 2, { x:planeVO.origX + randomX, delay:shortDelayAmount,
  181.                                         z:randomZ, y:150 + planeVO.origY + randomY,
  182.                                         rotationY:180,ease:Quint.easeInOut} );
  183.             }
  184.            
  185.             //In 3 seconds rebuild
  186.             Later.call(this, rebuild, 3000, true);
  187.         }
  188.        
  189.         protected function rebuild():void
  190.         {
  191.             //Rebuild our image with the locations we stored in our VO
  192.            
  193.             for (var i:int = 0; i <planeVOs.length; i++)
  194.             {
  195.                 var planeVO:PlaneVO     = planeVOs[i];
  196.                 var plane:Plane         = planeVO.planeRef;
  197.                 var delayAmount:Number  = i * .005;
  198.                 TweenMax.to(plane, 1.8, { x:planeVO.origX, delay:delayAmount,
  199.                                         z:planeVO.origZ, y:planeVO.origY,
  200.                                         rotationY:planeVO.origRotationY,ease:Quint.easeInOut} );
  201.             }
  202.            
  203.             //In 5 seconds explode the image again
  204.             Later.call(this, explode, 5000, true);
  205.         }
  206.     }
  207. }

Post to Twitter Post to Delicious Delicious Post to Digg Digg This Post Post to Facebook Facebook Post to StumbleUpon Stumble This Post

A Simple Papervision Carousel

Papervision 3D Carousel

download-source

This week I set out to create a Papervision Carousel in it's simplest form. At the heart of this carousel is a simple "for" loop / math which places the items in a circle in 3D space

Actionscript:
  1. for (var i:int = 0; i <planes.length; i++)
  2. {
  3.     var angle:Number    = Math.PI * 2 / numItems * i;
  4.     var plane:Plane     = planes[i];
  5.     plane.x             = Math.cos(angle) * radius;
  6.     plane.z             = Math.sin(angle) * radius;
  7.     plane.rotationY     = -360 / numItems * i - 90;
  8. }

Then to rotate our carousel we apply some similar math

Actionscript:
  1. var rotateTo:Number = (-360 / numItems) * currentItem + 90;
  2. TweenLite.to(planesHolder, 1, { rotationY:rotateTo, ease:Quint.easeInOut } );

This code allows us to just increment currentItem and rotate our carousel. Another easy add-on would be to setup a navigation along the bottom where you could control and change the currentItem to a specific number to rotate right to that section of the carousel.

It's also very easy to customize the number of items and radius of the carousel by adjusting these numbers.

Actionscript:
  1. protected var numItems:Number = 20;
  2. protected var radius:Number = 500;

Here is the full code.

Actionscript:
  1. package
  2. {
  3.     import flash.display.DisplayObject;
  4.     import flash.display.MovieClip;
  5.     import flash.display.Sprite;
  6.     import flash.events.Event;
  7.     import flash.events.MouseEvent;
  8.     import gs.easing.Quint;
  9.     import gs.TweenLite;
  10.     import org.papervision3d.materials.BitmapFileMaterial;
  11.     import org.papervision3d.objects.DisplayObject3D;
  12.     import org.papervision3d.objects.primitives.Plane;
  13.     import org.papervision3d.view.BasicView;
  14.    
  15.     /**
  16.      * ...
  17.      * @author Charlie Schulze, charlie[at]woveninteractive[dot]com
  18.      */
  19.    
  20.     public class Main extends BasicView
  21.     {
  22.         protected var planes:Array = [];
  23.         protected var numItems:Number = 20;
  24.         protected var radius:Number = 500;
  25.         protected var currentItem:Number = 0;
  26.        
  27.         protected var mat:BitmapFileMaterial;
  28.         protected var planesHolder:DisplayObject3D;
  29.         protected var rightBtn:Sprite;
  30.         protected var leftBtn:Sprite;
  31.        
  32.         public function Main():void
  33.         {
  34.             super();
  35.             init();
  36.         }
  37.         protected function init():void
  38.         {
  39.             createChildren();
  40.             createButtons();
  41.             commitProperties();
  42.             startRendering();
  43.         }
  44.         protected function createChildren():void
  45.         {
  46.            
  47.             planesHolder = new DisplayObject3D();
  48.            
  49.             //Create Material
  50.             mat             = new BitmapFileMaterial("images/queen.gif");
  51.             mat.smooth   = true;
  52.             mat.doubleSided = true;
  53.            
  54.             for (var i:int = 0; i <numItems; i++)
  55.             {
  56.                 var plane:Plane = new Plane(mat, 150, 234);
  57.                 planes.push(plane);
  58.                
  59.                 //Add plane to the scene
  60.                 planesHolder.addChild(plane);
  61.             }
  62.             scene.addChild(planesHolder);
  63.         }
  64.        
  65.         protected function commitProperties():void
  66.         {
  67.             //Set properties of our planes
  68.             for (var i:int = 0; i <planes.length; i++)
  69.             {
  70.                 var angle:Number    = Math.PI * 2 / numItems * i;
  71.                 var plane:Plane     = planes[i];
  72.                 plane.x             = Math.cos(angle) * radius;
  73.                 plane.z             = Math.sin(angle) * radius;
  74.                 plane.rotationY     = -360 / numItems * i - 90;
  75.             }
  76.            
  77.             //Adjust camera
  78.             camera.y = 200;
  79.            
  80.             //Rotate once
  81.             rotate();
  82.         }
  83.  
  84.         //Rotates the carousel
  85.         protected function rotate():void
  86.         {
  87.             var rotateTo:Number = (-360 / numItems) * currentItem + 90;
  88.             TweenLite.to(planesHolder, 1, { rotationY:rotateTo, ease:Quint.easeInOut } );
  89.         }
  90.        
  91.         /*
  92.          * Everything below this point is just for creating the buttons and
  93.          * setting button events for controlling the carousel.
  94.          */
  95.  
  96.         protected function createButtons():void
  97.         {
  98.             //Create Buttons
  99.             rightBtn = createButton();
  100.             leftBtn = createButton();
  101.                
  102.             addChild(leftBtn);
  103.             addChild(rightBtn);
  104.            
  105.             //Add button listeners
  106.             rightBtn.buttonMode = true;
  107.             leftBtn.buttonMode = true;
  108.             rightBtn.addEventListener(MouseEvent.CLICK, buttonClick);
  109.             leftBtn.addEventListener(MouseEvent.CLICK, buttonClick);
  110.                        
  111.             //Place buttons on stage
  112.             rightBtn.x    = stage.stageWidth - 120;
  113.             leftBtn.x       = 100;
  114.             rightBtn.y    =  stage.stageHeight / 2;
  115.             leftBtn.y       =  (stage.stageHeight / 2) + 20;
  116.             leftBtn.rotation    = 180;
  117.         }
  118.        
  119.         //Button actions
  120.         protected function buttonClick(evt:MouseEvent):void
  121.         {
  122.             switch (evt.target)
  123.             {
  124.                 case rightBtn:
  125.                 currentItem --;
  126.                 break;
  127.                
  128.                 case leftBtn:
  129.                 currentItem ++;
  130.                 break;
  131.             }
  132.             rotate();
  133.         }
  134.        
  135.         //Creates a simple arrow shape / returns the sprite
  136.         protected function createButton():Sprite
  137.         {
  138.             var btn:Sprite = new Sprite();
  139.            
  140.             btn.graphics.beginFill(0x333333);
  141.             btn.graphics.moveTo(0, 0);
  142.             btn.graphics.lineTo(0, 20);
  143.             btn.graphics.lineTo(10, 10);
  144.             btn.graphics.lineTo(0, 0);
  145.             btn.graphics.endFill();
  146.             return btn;
  147.         }
  148.     }
  149. }

Feel free to post links to ways you expand upon this file.

download-source

Post to Twitter Post to Delicious Delicious Post to Digg Digg This Post Post to Facebook Facebook Post to StumbleUpon Stumble This Post

Animation Using TweenLite

In this tutorial we're going to use TweenLite to move a cube around. This will teach you basics of animation, and how to use TweenLite.

download-source

animating-using-tweenlite

In this example our solid red cube is trying to stay inside our green wireframe cube. Every time the red cube gets itself positioned completely inside the green cube, the green cube moves.

TweenLite is the package which is smoothly moving the red cube around. The TweenLite package is also firing the event to move the green cube when the tween is complete.

1: To start off, you'll need TweenLite. You can download it here if you don't already have it (also included in the source download "gs" folder): http://blog.greensock.com/tweenlite/

2: Import tweener - Add this line to your imports:

Actionscript:
  1. import gs.TweenLite;

3: Add a Tween. You can add tweens to any parameter of any object. The TweenLite package will gradually change any parameter in your code to a new value over time, so only numeric values will work nicely.

To add a tween, we use the code:

Actionscript:
  1. //TweenLite.to(objectToAnimate, time, { property:newValue, property:newValue, ease:Quint.easeInOut, onComplete:functionToCall} );
  2.  
  3. //Your code will end up looking something like this
  4. TweenLite.to(cube, 2, { x:xp, z:yp, ease:Quint.easeInOut, onComplete:randomize } );

The line above will add a tween. This tween will change the values "x" and "y" on the object "cube" to 1000 and 500 respectively. It will smoothly change the values over a period of 2 seconds and once the tween is complete and the cube.x is 1000 and cube.y is 500, it will trigger the "randomize" function.

Experiment with more ways to tween your objects. You can apply tweens to anything, including cameras, lights, rotations, sizes and camera zooms. Any numerical value you can think of.

Actionscript:
  1. package
  2. {
  3.     import gs.easing.Quint;
  4.     import gs.TweenLite;
  5.     import org.papervision3d.lights.PointLight3D;
  6.     import org.papervision3d.materials.ColorMaterial;
  7.     import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
  8.     import org.papervision3d.materials.utils.MaterialsList;
  9.     import org.papervision3d.materials.WireframeMaterial;
  10.     import org.papervision3d.objects.primitives.Cube;
  11.     import org.papervision3d.objects.primitives.Plane;
  12.     import org.papervision3d.view.BasicView;
  13.    
  14.     /**
  15.      * ...
  16.      * @author Charlie Schulze, charlie[at]woveninteractive[dot]com
  17.      */
  18.    
  19.     public class Main extends BasicView
  20.     {
  21.         protected var cube:Cube;
  22.         protected var cube2:Cube;
  23.         protected var mat:FlatShadeMaterial;
  24.         protected var mat2:WireframeMaterial;
  25.         protected var plane:Plane;
  26.        
  27.         public function Main():void
  28.         {
  29.             super();
  30.             init();
  31.         }
  32.         protected function init():void
  33.         {
  34.             createChildren();
  35.             commitProperties();
  36.             randomize();
  37.             startRendering();
  38.         }
  39.         protected function createChildren():void
  40.         {
  41.             //Create Materials:
  42.             mat     = new FlatShadeMaterial(new PointLight3D(), 0xFFFFFF, 0xFF0000);
  43.             mat2    = new WireframeMaterial(0x00FF00);
  44.            
  45.             //Create 3D Objects
  46.             plane   = new Plane(null, 2000, 2000, 10, 10);
  47.             cube    = new Cube(new MaterialsList( { all: mat } ), 100, 100, 100);
  48.             cube2   = new Cube(new MaterialsList( { all: mat2 } ), 100, 100, 100);
  49.            
  50.             //Add objects to the scene
  51.             scene.addChild(plane);
  52.             scene.addChild(cube);
  53.             scene.addChild(cube2);
  54.         }
  55.         protected function commitProperties():void
  56.         {
  57.             //Set properties of our plane
  58.             plane.material.lineColor = 0x777777;
  59.             plane.material.doubleSided = true;
  60.             plane.pitch(90);
  61.             plane.y     = -50;
  62.            
  63.             //Set the properties of our camera
  64.             camera.x    = 0;
  65.             camera.z    = 1000;
  66.             camera.y    = 1000;
  67.         }
  68.        
  69.         public function randomize():void
  70.         {
  71.             var xp:Number   = (Math.random() * 2000) - 1000;
  72.             var yp:Number   = (Math.random() * 2000) - 1000;
  73.             cube2.x         = xp;
  74.             cube2.z         = yp;
  75.            
  76.             //When complete it calls this method again
  77.             TweenLite.to(cube, 2, { x:xp, z:yp, ease:Quint.easeInOut, onComplete:randomize } );
  78.         }
  79.     }
  80. }

download-source

Post to Twitter Post to Delicious Delicious Post to Digg Digg This Post Post to Facebook Facebook Post to StumbleUpon Stumble This Post


Follow papervision2 on Twitter

Flash and the City banner
2010 Flash And The City Speaker

RSS Feed