Posts Tagged ‘source’

A symphony of light without sound.

Wednesday, April 15th, 2009

Heres my second submission to the AR contest. i call it.
“A symphony of light without sound.”

enjoy

 

I’m really not sure how to deal with the copyright’s situation. so i just leave it where i put the corrosponding code most of the time, hehe.

I try my best to give credit above and beyond where applicable.

And really i have such a terrible method of coding  i dont know what i should leave from fork to fork and what i dont need as you can see in what i call my “vestigial import evolution” system.

Since my grasp of AS3 goes about as far as questionable grammar and syntax, and try as i may i am just unable to wrap my mind around the class system as of yet (just know this all of you Flex programmers… you are the enemy). Sooo to get a little understanding of what youre seeing here i’ll explain my Nintendo Gauntlet style HACK and SLASH  method of coding.

I take whole classes, remove all the public, private, class, static etc. statements, paste everything in the main time line in flash, call the main function from the root in flash and work out errors from there :-) my theory is, if I did it, theres probably a better way.

I know i totally break everyones very well organized and pretty code structure and proceduralize it to my understanding. Just giving you a referance as to what youre looking at.

Something in the source is killing my whole post.
Heres a link to the code in a .txt file
http://www.splengy.com/FireWorksMidiAS3.txt
Flint, papervision, FlarManager.

the magic here is a midi Java applett written by a programmer named “abudaan”. as it turns out the week i decided to throw my self into Flash and AS3 this brilliant gentleman decided it was time to take alot of the complexity out of AS3 and midi communication. He wrote a beautifully simple set of java applets that connect to your systems midi devices and give you variables in flash.

to be honest thats the end of my understanding about it. the beauty is thats all ive needed to know up till now.

theres a java applet and swf that has to be running in a browser to connect to the midi hardware and translate midi to flash. it only runs on a single domain. so you cant connect to it from a differant domain. for instance your swf and the midi java applet have to be on Splengy.com, or 127.0.0.1,

then theres a block of code i copy and paste from file to file that gives me access to allmost anything i could need out of in bound midi communications.

http://code.google.com/p/miditoflash/

I’m going to do my best to get an online version running for any of you that have midi hardware plugged in. If not i’ll post a few more videos of velocity response and such.

ONLINE DEMO INFO!!

If for some reason youve allready clicked the links and are wondering why it doesnt work let me first ask you, do you have any midi hardware? You’ll NEED midi hardware (a keyboard, drum pad, retro midi wind controller, free energy device…) to make this work.

First click this link. it brings up the java midi bridge.(update java and flash player if you think you maybe should please) it should bring up a list of midi devices connected to your machine. if it doesnt, refresh the screen once or twice, it should work. then when you see a list of available midi devices click the one you want to use to input data, and click OK.

http://www.splengy.com/MIDI/src/bridge.html

Once all that is done and you have a connection to the applet click the link below.

http://www.splengy.com/MIDI/src/ARfireworksMidi2.swf

it will bring up the SWF in a differant window.

I USED MIDI NOTES  69, 70, 71, and 72 FOR THIS DEMO AND IT SHOULD REACT TO THOSE NOTES REGARDLESS OF THE CHANNEL#, GLOBAL RESPONSE TO THOSE NOTES.

if for some reason those notes do not get a response like the one in the video, do the refresh dance, refresh one then the other, and keep trying. it may or may not work for you, i have gotten it to work here pretty successfully.

You may need these. same markers for both examples.
patt012patt004patt010pmarker

submissionexamples.zip Both submissions one zip. virus scanned right before upload.

If you take a look at my past posts you’ll see that this is really a compilation of most of my work with AS3 up till this point used in 2 files. though my acomplishments may not be great in the scale of things, it doesnt detract from the works taken to get there. enjoy them.

pv3d.org AR contest submission one

Tuesday, April 14th, 2009
Its still a work in progress, going to add further functionality. playlist, ID3 tags, other visualizations.
i wanted to make something with AR that was not only cool to look at but was some what functional. The song is courtesy of http://www.ModdJobs.com and mc chris, the rest of the album is available there too.
FREE DOWNLOAD!
Check it out.
http://www.ModdJobs.com

 Demo it works, yay.

ARMP3Player

Heres the source, demo swf’s, fla’s, DAE, java applett, short description, and prolly a bunch of stuff you dont need.

submissionexamples.zip Both submissions one zip. virus scanned right before upload.

Song

OC.mp3

DAE

PLP.DAE

credits where credit is due.
the spectrum analysis came directly from here. lee was the beginning of all my flash happieness, i owe alot to him.
http://www.gotoandlearn.com/play?id=63

the text is right out of johns papervision twitter tutorial(wich i still get an import error off)
http://pv3d.org/2009/03/31/twitter-papervision3d-using-tweetr/

the flar manager source was a combo of marcs tutorial and erics examples.
http://words.transmote.com/wp/20090328/flarmanager-v03/
http://www.marcpelland.com/2009/03/26/getting-started-with-augmented-reality-flartoolkit/

of course i got started in AR here
http://pv3d.org/2009/03/12/augmented-reality-flartoolkit-demo-reel/
http://saqoosha.net/en

the visualizer thing is loosely based on johns sound analysis project
http://pv3d.org/2008/12/06/papervision3d-sound-spectrum/

ive never considered my self a very creative programmer but more of a very selective coppier.

heres the mess that got me here. main time line in flash. i’ll put the song and DAE an other stuff up soon.

import com.transmote.flar.FLARManager;
import com.transmote.flar.marker.FLARMarkerEvent;
import com.transmote.flar.pattern.FLARPattern;
import com.transmote.flar.source.FLARCameraSource;
import com.transmote.utils.time.FramerateDisplay;
import com.transmote.flar.marker.FLARMarker;
import com.transmote.flar.utils.FLARPVGeomUtils;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.PixelSnapping;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.utils.ByteArray;
import flash.media.Camera;
import flash.media.Video;
import flash.media.Sound;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.events.Event;
import flash.utils.Dictionary;
import org.papervision3d.view.stats.StatsView;
import org.libspark.flartoolkit.core.param.FLARParam;
import org.libspark.flartoolkit.pv3d.FLARCamera3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.LazyRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.materials.BitmapAssetMaterial;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.Letter3DMaterial;
import org.papervision3d.typography.Text3D;
import org.papervision3d.typography.fonts.HelveticaBold;

import flash.display.Sprite;
import flash.events.Event;

 /**
  * standard FLARToolkit Papervision3D example, with our friends the Cubes.
  * code is borrowed heavily from Saqoosha, Mikko Haapoja, and Squidder.
  * http://saqoosha.net/en/flartoolkit/start-up-guide/
  * http://www.mikkoh.com/blog/?p=182
  * http://www.squidder.com/2009/03/06/flar-how-to-multiple-instances-of-multiple-markers/#more-285
  *
  * @author Eric Socolofsky
  * @url  http://transmote.com/flar
  */
//   var statsView:StatsView = new StatsView(); addChild(statsView);
   var stats:Boolean = true;  // display the stats view
   var CUBE_SIZE:Number=40;
  var viewport3D:Viewport3D;
  var camera3D:FLARCamera3D;
  var scene3D:Scene3D;
  var renderEngine:LazyRenderEngine;
  var pointLight3D:PointLight3D;

  var CAMERA_PARAMS_PATH:String = "../resources/flar/FLARparams.dat";
  var PATTERN_PATH:String = "../resources/flar/patterns/pat16/";
  var PATTERN_RESOLUTION:uint = 16;

  var patterns:Vector.;
  var _param:FLARParam;
  var flarManager:FLARManager;
  var markersByPatternId:Vector.>;// FLARMarkers, arranged by patternId
  var containersByMarker:Dictionary;// Cube containers, hashed by corresponding FLARMarker

  var plane:Plane;
  var s:Sound = new Sound(new URLRequest("OC.mp3"));
  var pointArray:Array = new Array();
  var ba:ByteArray = new ByteArray();
  var active:Boolean;
  var viz:Boolean;
  active = false;
  viz = false;
  var sc:SoundChannel;
  var pos:Number = new Number(0);
  var text3d:Text3D;
  var text3dtwo:Text3D;
  var text3dOther:Text3D;

  var bmd:BitmapData = new BitmapData(512, 450, true, 0x000000);
  var bm:Bitmap = new Bitmap(bmd);

  var spOne:Sprite = new Sprite();
  //addChild(spOne);

  var blur:BlurFilter = new BlurFilter(10,10,3);

  var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter([
    1, 0, 0, 0, 0,
    0, 1, 0, 0, 0,
    0, 0, 20, 0, 0,
    0, 0, 0, 50, 0
  ]);

init();
////////////////////////
//Sound Movie material
////////////////////////
var mc:MovieClip = new MovieClip();
mc.graphics.beginFill( 0xFF0000 );
mc.graphics.drawRect( 0, 0, 512, 450 );
mc.graphics.endFill();
mc.addChild(bm);
mc.addChild(spOne);
var mmTransparent:Boolean = false;
var mmAnimated:Boolean = true;
var mmPrecise:Boolean = true;
var mm:MovieMaterial = new MovieMaterial( mc, mmTransparent, mmAnimated, mmPrecise );

  function init () :void {
   // build list of FLARPatterns for FLARToolkit to detect
   patterns = new Vector.();
   patterns.push(new FLARPattern(PATTERN_PATH+"patt012.pat", PATTERN_RESOLUTION));
   patterns.push(new FLARPattern(PATTERN_PATH+"patt004.pat", PATTERN_RESOLUTION));
   patterns.push(new FLARPattern(PATTERN_PATH+"patt002.pat", PATTERN_RESOLUTION));
   patterns.push(new FLARPattern(PATTERN_PATH+"patt010.pat", PATTERN_RESOLUTION));
   patterns.push(new FLARPattern(PATTERN_PATH+"patt016.pat", PATTERN_RESOLUTION));

   // use Camera (default)
   flarManager = new FLARManager(CAMERA_PARAMS_PATH, patterns);
   addChild(FLARCameraSource(flarManager.flarSource));

   // begin listening for FLARMarkerEvents
   flarManager.addEventListener(FLARMarkerEvent.MARKER_ADDED, onMarkerAdded);
   flarManager.addEventListener(FLARMarkerEvent.MARKER_UPDATED, onMarkerUpdated);
   flarManager.addEventListener(FLARMarkerEvent.MARKER_REMOVED, onMarkerRemoved);

   var framerateDisplay:FramerateDisplay = new FramerateDisplay();
   addChild(framerateDisplay);

   flarManager.addEventListener(Event.INIT, onFlarManagerInited);
  }

  function onFlarManagerInited (evt:Event) :void {
   trace("FLAR Manager Inited");
   initPapervisionEnvironment(flarManager.cameraParams, stage.stageWidth, stage.stageHeight);
   var numPatterns:uint = new uint(patterns.length);
   initTwo(numPatterns);
  }

  function addMarker(marker:FLARMarker):void {
   // store marker
   var markerList:Vector.=markersByPatternId[marker.patternId];
   markerList.push(marker);
   // create a new thing, and place it inside a container (DisplayObject3D) for manipulation
   var container:DisplayObject3D = new DisplayObject3D();
   if (marker.patternId == 0){
   //Spectrum Analisys///////////////////////////
   for(var i:uint=0; i<64; i++)
    {
     //var saHolder:DisplayObject3D;
     var randomColor:Number = Math.random() * 0xffffff;
     var shape:Shape = new Shape();
     with(shape)
      {
       graphics.beginFill(randomColor);
       graphics.drawRect(0, 0, 2, 2);
       graphics.endFill();
      }
     var material:MovieMaterial = new MovieMaterial(shape);
     //animated needs to be true to tween the color
     material.animated = true;
     material.doubleSided = true;
     material.interactive = false;
     var plane:Plane = new Plane(material, 2, 2);
     var lineLeangth:Number = new Number(175);
     var xLoc:Number = new Number();
     xLoc = (lineLeangth/-2)+(i*3.5);
     plane.x = xLoc;
     plane.y = 0;
     plane.z = 120;
     plane.rotationX = 90;
     plane.rotationZ = 45;
     plane.name = "plane"+i;
     container.addChild(plane);
     pointArray[i] = container.getChildByName("plane"+i);

   }
    viz = true;
    trace("object one");
   }else if(marker.patternId == 1){
    //Text
    var msg:String;
    msg = "Splengy.com AR MP3 player";
    var letterMaterial:Letter3DMaterial = new Letter3DMaterial(0xcc0000);
    letterMaterial.doubleSided = true;
    text3d = new Text3D(msg, new HelveticaBold(), letterMaterial);
    text3d.scaleX = .25;
    text3d.scaleY = .25;
    text3d.scaleZ = .25;
    text3d.rotationX = 90;
    text3d.z = 30;
    container.addChild(text3d);

    //PLP extrusion
    var PLP:DAE;
    var cm:ColorMaterial;
    var holder:DisplayObject3D;
    var lMaterialsList:MaterialsList = new MaterialsList();
    lMaterialsList.addMaterial ( mm, "ERTransparent44");
   //DAE
    PLP = new DAE();
    PLP.load("PLP.dae", lMaterialsList);

    holder = new DisplayObject3D();
    holder.addChild(PLP);

    holder.rotationX = 90;
   //holder.rotationY = 45
    holder.scaleX = 15;
    holder.scaleY = 15;
    holder.scaleZ = 20;
    holder.z = 80;
    container.addChild(holder);
   if (active == false){
    sc = s.play(pos, 1000);
   }

    trace("object two");
   }else if(marker.patternId == 2){
        //Text
    var msgOther:String;
    msgOther = "Music by ModdJobs.com and mc chris, free download";
    var letterMaterialOther:Letter3DMaterial = new Letter3DMaterial(0xcc0000);
    letterMaterialOther.doubleSided = true;
    text3dOther = new Text3D(msgOther, new HelveticaBold(), letterMaterialOther);
    text3dOther.scaleX = .25;
    text3dOther.scaleY = .25;
    text3dOther.scaleZ = .25;
    text3dOther.rotationX = 90;
    text3dOther.z = 30;
    container.addChild(text3dOther);
    trace("object three");
   }else if(marker.patternId == 3){
    //Text
    var msgtwo:String;
    msgtwo = "I'm going to scream, yay scream";
    var letterMaterialtwo:Letter3DMaterial = new Letter3DMaterial(0xcc0000);
    letterMaterialtwo.doubleSided = true;
    text3dtwo = new Text3D(msgtwo, new HelveticaBold(), letterMaterialtwo);
    text3dtwo.scaleX = .25;
    text3dtwo.scaleY = .25;
    text3dtwo.scaleZ = .25;
    text3dtwo.rotationX = 90;
    text3dtwo.z = 30;
    container.addChild(text3dtwo);
    trace("object four");
   }else if(marker.patternId == 4){
    trace("object five");
   }

   // associate container with corresponding marker
   scene3D.addChild(container);
   containersByMarker[marker]=container;
  }

  function removeMarker(marker:FLARMarker):void {
   // find and remove marker
   var markerList:Vector.=markersByPatternId[marker.patternId];
   var markerIndex:uint=markerList.indexOf(marker);
   if (markerIndex!=-1) {
    markerList.splice(markerIndex, 1);
   }
   if (marker.patternId == 0){
    viz = false;
   }else if(marker.patternId == 1){
    active = false;
    pos = sc.position;
    sc.stop();
   }

   // find and remove corresponding container
   var container:DisplayObject3D=containersByMarker[marker];
   if (container) {
    scene3D.removeChild(container);
   }
   delete containersByMarker[marker];
  }

  function initTwo(numPatterns:uint):void {
   // set up lists (Vectors) of FLARMarkers, arranged by patternId
   markersByPatternId=new Vector.>(numPatterns,true);
   while (numPatterns--) {
    markersByPatternId[numPatterns] = new Vector.();
   }

   // prepare hashtable for associating Cube containers with FLARMarkers
   containersByMarker=new Dictionary(true);
  }

  function initPapervisionEnvironment(cameraParams:FLARParam, viewportWidth:Number, viewportHeight:Number):void {
   scene3D = new Scene3D();
   camera3D=new FLARCamera3D(cameraParams);

   viewport3D=new Viewport3D(viewportWidth,viewportHeight, true, true, true, true);
   addChild(viewport3D);

   renderEngine=new LazyRenderEngine(scene3D,camera3D,viewport3D);

   pointLight3D = new PointLight3D();
   pointLight3D.x=1000;
   pointLight3D.y=1000;
   pointLight3D.z=-1000;

   addEventListener(Event.ENTER_FRAME, onEnterFrame);
  }

  function onEnterFrame(evt:Event):void {
   updateCubes();
//   text3d.rotationX= text3d.rotationX +5;
   SoundMixer.computeSpectrum(ba, false, 2);
   if (viz == true){
    for(var i:uint=0; i<256; i++)
    {
     var j:uint = new uint(i/4);
     var num:Number = -ba.readFloat()*100+5;
     pointArray[j].scaleY = num;
     i = i+1;
    }
   }
   renderEngine.render();
  }

  function updateCubes():void {
   // update all Cube containers according to the transformation matrix in their associated FLARMarkers
   var i:int=markersByPatternId.length;
   var markerList:Vector.;
   var marker:FLARMarker;
   var container:DisplayObject3D;
   var j:int;
   while (i--) {
    markerList=markersByPatternId[i];
    j=markerList.length;
    while (j--) {
     marker=markerList[j];
     container=containersByMarker[marker];
     container.transform=FLARPVGeomUtils.convertFLARMatrixToPVMatrix(marker.transformMatrix);
    }
   }
  }

  function onMarkerAdded (evt:FLARMarkerEvent) :void {
   trace("["+evt.marker.patternId+"] added");
   addMarker(evt.marker);
  }

  function onMarkerUpdated (evt:FLARMarkerEvent) :void {
   //trace("["+evt.marker.patternId+"] updated");
  }

  function onMarkerRemoved (evt:FLARMarkerEvent) :void {
   trace("["+evt.marker.patternId+"] removed");
   removeMarker(evt.marker);
  }
///////////////////////////
//Sound Line thingy
///////////////////////////
addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void
{
 spOne.graphics.clear();
 spOne.graphics.lineStyle(3, 0xFFFFFF);
 spOne.graphics.moveTo(-1, 256);
 SoundMixer.computeSpectrum(ba);
 for(var i:uint=0; i<256; i++)
 {
  var num:Number = -ba.readFloat()*200 + 225;
  spOne.graphics.lineTo(i*2, num);
 }

}

So it appears as though my code wammy is eating all my <’s and >’s

details, details, details…

Saqoosha’s “hole” Effect

Friday, April 10th, 2009

http://saqoosha.net/

so after much searching and still not finding what i’m really looking for wich is the recipe to capture bitmapdata off the marker.rect or something along those lines, i tackled “the virtual hole” with the samples from Saqoosha’s site and a little hacking away of useless code i made it work. Woo!

virtual hole

and the code that got me here.


import flash.display.Bitmap;
import flash.display.Sprite;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.filters.ColorMatrixFilter;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.core.math.Matrix3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.render.*;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.view.stats.StatsView;
import org.papervision3d.materials.MovieAssetMaterial;
import org.papervision3d.materials.*;
import org.papervision3d.materials.BitmapAssetMaterial;
import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.objects.parsers.DAE;
import org.papervision3d.objects.DisplayObject3D;

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.utils.BitmapMaterialTools;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;

  [Embed(source='../assets/bg.png')]
  var bgTextureClass:Class;
  [Embed(source='../assets/cube-side.png')]
  var cubeSideTextureClass:Class;
  [Embed(source='../assets/cube-bottom.png')]
  var cubeBottomTextureClass:Class;

  var _green:Cube;

var sp:Sprite = new Sprite();
addChild(sp);

var viewport:Viewport3D = new Viewport3D( 960, 720, true, true, true, true );
sp.addChild(viewport);
viewport.buttonMode = false;

var renderer:BasicRenderEngine = new BasicRenderEngine();
var scene:Scene3D = new Scene3D();
var camera:Camera3D = new Camera3D();
camera.zoom = 11;
camera.focus = 100;

  var cmats:BitmapMaterial = BitmapMaterialTools.createBitmapMaterial(cubeSideTextureClass);
  var cmatb:BitmapMaterial = BitmapMaterialTools.createBitmapMaterial(cubeBottomTextureClass);
  var hole:Cube = this.scene.addChild(new Cube(new MaterialsList({all: cmats, bottom: cmatb}), 300, 300, 300, 1, 1, 1, Cube.ALL, Cube.TOP)) as Cube;
  this._green = this.scene.addChild(new Cube(new MaterialsList({all: new ColorMaterial(0x00ff00)}), 300, 300, 300, 1, 1, 1, 0, Cube.TOP)) as Cube;
  hole.y = this._green.y = -150;

  this.filters = [
   new ColorMatrixFilter([
    1, 0, 0, 0, 0,
    0, 1, 0, 0, 0,
    0, 0, 1, 0, 0,
    1, -1, 1, 1, 0
   ])
  ];

 this.addEventListener(Event.ENTER_FRAME, this._update);

  function _update(e:Event):void {
   renderer.renderScene(scene, camera, viewport);
   camera.orbit(this.stage.mouseY / 600 * 90, this.stage.mouseX / 800 * 180);
  }

You’ll need to find the newyears source on saqooshas blog for the .png’s but theyre just a grey-white gradient. could be generated on the spot.

Papervision BitmapViewport realization

Sunday, March 15th, 2009

i was playing with filters and papervision when i came up with this.

i set up a pretty simple ppv3D scene with a bitmapViewport and added this line


viewport.fillBeforeRender = false;

and presto insta trails. it just keeps rendering ontop of its self. add a little blur and this effect just happened.

Example: ppveffects123

and the code


//flash imports
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.geom.Point;
import flash.display.Sprite;
import flash.events.Event;
import flash.system.Security;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.ui.Mouse;
import flash.display.DisplayObject;
import flash.display.Shape;
import gs.*;
import gs.easing.*;
import gs.TweenMax;
//papervision imports
import org.papervision3d.materials.MovieAssetMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.core.utils.Mouse3D;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.objects.*;
import org.papervision3d.objects.special.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.materials.utils.*;
import org.papervision3d.lights.*;
import org.papervision3d.render.*;
import org.papervision3d.view.*;
import org.papervision3d.view.BasicView;
import org.papervision3d.events.*;
import org.papervision3d.core.utils.*;
import org.papervision3d.core.utils.virtualmouse.VirtualMouse;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.core.effects.*;
//scene setup
var sp:Sprite = new Sprite();
addChild(sp);

var viewport:BitmapViewport3D = new BitmapViewport3D(960, 720, true, true, 0x000000, true, false );
viewport.fillBeforeRender = false;
sp.addChild(viewport);
viewport.buttonMode = false;

var renderer:BasicRenderEngine = new BasicRenderEngine();

var scene:Scene3D = new Scene3D();

var camera:Camera3D = new Camera3D();
camera.zoom = 11;
camera.focus = 100; 

//Filters
var cmf:ColorMatrixFilter = new ColorMatrixFilter([3,0,0,0,0,
               0,-3,0,0,0,
               0,0,3,0,0,
               0,0,0,0,0]);

var blur:BlurFilter = new BlurFilter(3, 3, 1);
var alphaTrans:ColorTransform = new ColorTransform(1, 1, 1, 1, 4, 5, 3, -10);
var pointArray:Array = new Array();
for(var i:uint=0; i&lt;10; i++)
  {
   var randomColor:Number = Math.random() * 0xEEEEEE;
   var shape:Shape = new Shape();
   with(shape)
    {
     graphics.beginFill(randomColor);
     graphics.drawRect(0, 0, 2, 2);
     graphics.endFill();
    }
   var mam:MovieMaterial = new MovieMaterial(shape);
   var mList = new MaterialsList({front:mam, back:mam, left:mam, right:mam,top:mam, bottom:mam})
   var cube:Cube = new Cube(mList, 20, 20, 20, 1, 1, 1);
   mam.animated = true;
   mam.doubleSided = false;
   mam.interactive = false;
   cube.x = Math.random()*700;
   cube.y = Math.random()*700;
   cube.z = Math.random()*700;
   cube.name = "cube"+i;
   scene.addChild(cube);
   pointArray[i] = scene.getChildByName("cube"+i);
   //addChild(planeBm);

   }
addEventListener(Event.ENTER_FRAME, loop);

function loop(e:Event):void
{
 camera.x -= (camera.x-(stage.stageWidth*0.5-mouseX)/(stage.stageWidth*0.5)*1600)*0.2;
 camera.y -= (camera.y-(stage.stageHeight*0.5-mouseY)/(stage.stageHeight*0.5)*1800)*0.2;

 renderer.renderScene(scene, camera, viewport);
 //viewport.bitmapData.colorTransform(viewport.bitmapData.rect, alphaTrans);
 viewport.bitmapData.applyFilter(viewport.bitmapData, viewport.bitmapData.rect, new Point(0,0), blur);
 //viewport.bitmapData.applyFilter(viewport.bitmapData, viewport.bitmapData.rect, new Point(0,0), cmf);
 viewport.bitmapData.scroll(0, -4);
}

more PPV sound fun

Wednesday, March 11th, 2009

this is built off my previous ppv sound example.

i added a tween to a circle, woo hoo. its still fun :)

oh i need to learn more math.

ppv sound fun
ppv sound fun

Example

midippvthingy31

and the code i added to tween

function circle(){
var angleOffset:Number = Math.PI*2/255;
var radius:Number = 300;
var angle:Number = 360;
var planeX:Number;
var planeZ:Number;

		for(var i:int =0;i&lt;255;i++)
	{
		planeX = Math.cos(angle)*radius;
		planeZ = Math.sin(angle)*radius;
		TweenLite.to(pointArray[i], 5, {x:planeX, z:planeZ});
		angle += angleOffset;
	}

}

enjoy

WebCam FUN now with Ripples!!

Tuesday, March 10th, 2009
I just LOVE this effect and flash. its like salt and food, i put it on everything.
first make the file midi capable, then add stuff, then ripples :)
couldnt be easier to do, just feed it bitmapData.
WebCamRipples with flash
WebCamRipples with flash

 

 

the camera is set to 960 x 720 thats what looks best on my projector. and i have a nice webcam.

It should default to your cameras highest resolution. if anyone has problems leave a comment and i’ll put up a 640 x 480 version.

And the code.
the ripple class is posted earlier on the site.

	import flash.events.Event;
	import flash.system.Security;
	import flash.text.TextField;
	import flash.text.TextFormat;	

	import Rippler;

    import flash.display.Bitmap;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.MouseEvent;

stage.cacheAsBitmap;

var camW:int = 960;
var camH:int = 720;

// Create the camera
var cam:Camera = Camera.getCamera();
cam.setMode( camW, camH, stage.frameRate );
cam.addEventListener(Event.ACTIVATE, active);

// Create a video
var vid:Video = new Video( camW, camH );
vid.attachCamera( cam );
addChild(vid);

var mainBmd:BitmapData= new BitmapData(960, 720, false, 0);
var mainBm:Bitmap = new Bitmap;

function active(event:Event){
	addEventListener(Event.ENTER_FRAME, onEnterFrame );
} ;

function onEnterFrame(event:Event) : void
	{
		mainBmd.draw(vid);
		var mainBm:Bitmap = new Bitmap(mainBmd);
		//addChild(mainBm);	

	};			

        var _target : Bitmap = new Bitmap(mainBmd);
        var _rippler : Rippler;

        function Ripple()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            // create a Bitmap displayobject and add it to the stage
            _target = new Bitmap(mainBmd);
            addChild(_target);

            // create the Rippler instance to affect the Bitmap object
            _rippler = new Rippler(_target, 160, 16);

            // create the event listener for mouse movements
            stage.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove);
        }

        // creates a ripple at mouse coordinates on mouse movement
        function handleMouseMove(event : MouseEvent) : void
        {
            // the ripple point of impact is size 20 and has alpha 1
            _rippler.drawRipple(_target.mouseX, _target.mouseY, 50, .65);
        }

Ripple();

WebCam snippet

Tuesday, March 10th, 2009

I figured around the time of the cam ripples post id share my webcam snippet.

in changing over from AS2 to AS3 i had to search out the new code for camera interaction.

as with all things theres many ways to do it.

ive come up with a snippet i use all the time. it’s set to a camera resolution of 960 x 720.

i have a logitech 9000 pro.

it kicks arse

change the resolution if you want but i think flash defaults to the highest available resolution if your hardware doesnt support whats called for.

First we set our width and height,  grab the default camera ,create a video object to attach the camera to, create our “when camera becomes active” listener, and add the camera to the display list.

then theres a little bitmapData action happening in there,  followed by its partner in crime, the bitmap.

when the camera is active we add our holy enterframe listener and in the enterframe event we have that bitmapData draw() our video object giving us access to fresh bitmapdata from the camera when ever we need it.

the first line there, stagecacheAsBitmap; isnt necessary but i spent DAYS looking for those words in that order, i wanted to draw() the stage and couldnt for the life of me. So i’m leaving that line there hoping someone will stumble upon it and either end their search or be inspired by a new possability.

stage.cacheAsBitmap;

var camW:int = 960;
var camH:int = 720;

// Create the camera
var cam:Camera = Camera.getCamera();
cam.setMode( camW, camH, stage.frameRate );
cam.addEventListener(Event.ACTIVATE, active);

// Create a video
var vid:Video = new Video( camW, camH );
vid.attachCamera( cam );
addChild(vid);

var mainBmd:BitmapData= new BitmapData(960, 720, false, 0);
var mainBm:Bitmap = new Bitmap;

function active(event:Event){
addEventListener(Event.ENTER_FRAME, onEnterFrame );
} ;

function onEnterFrame(event:Event) : void
{
mainBmd.draw(vid);
var mainBm:Bitmap = new Bitmap(mainBmd);
//addChild(mainBm);

};

A few words about papervision 3D

Sunday, March 8th, 2009

 http://www.papervision3d.org/ first go here, let it load, look around and come back if youre not allready familiar.

Before i jump into talking about papervision code and stuff i wanted to say a few words about it.

First the differance between papervision and pay per view(ive been asked a few times now) is you have to wait till tomorrow to download a pay per view event, but you can download papervision now. http://code.google.com/p/papervision3d/

you’ll need to download the tortise SNV whammy to get the full source. its not that hard. post if you cant work it out, i’ll put something up on how svn’s work to the best of my knowledge. please dont ask me to do it, you’re WAY better off finding a tutorial by someone who actually knows what theyre talking about.  Now that i think about it, there just isnt enough BS on the internet. maybe i’ll do a tut on it just because i dont know what i’m talking about. wait and see.

Papervision has become my white whale.

Papervision 3D is an open source 3d rendering “environment” for the flash player.

It can be compiled in a number of programs, flex and flash to name a few.

there in lies one of the major double edged swords. about 1/2 the tutorials out there are written in Flex( I dont flex) and half the remaining tutorials are written in AS3 class files. the remainder are written in flash on the main timeline or via “other” methods of compiling. so finding tutorials you can use without being nearly fluent in at least flex AND flash is frustrating at best.

NOW on to the branch trunk system. if you can find the branch(dead or not), or trunk version that the person writing any instructions or a tutorial used consider it an acomplishment. I stood up and did a little dance a few times here just after getting a demo running.

Papervision’s core and extended group of contributers are in my opinion some of the greatest minds AS programming has to offer at the moment. The stuff that comes from those labs makes my nipples more than a little stiff.
Just a side note. i love these guys taste in music. its allways nice to go to a computeSpectrum example and want to turn the music UP or hitting refresh just to hear the song again instead of leaping for mute. thx.

heres a few sites ive driven the hit counters up quite a bit recently.

http://blog.papervision3d.org/

i tripped out on this page for a while
http://mrdoob.com/

http://www.sebleedelisle.com/

http://blog.zupko.info/

http://rockonflash.wordpress.com/

goToandLearn.com

Sunday, March 8th, 2009

Lee Brimlowe is without a doubt one of my heros.

he’s up there with Alton Brown.

if youre beginning flash, or looking to expand your pallate lee’s work is so easy to understand, he has a great library of free video tutorials. if you dont know allready goToandLearn ASAP

http://www.gotoandlearn.com

sources included with tutorials