Posts Tagged ‘spectrum’

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…

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

My first papervision spectrum analisys experiment

Monday, March 9th, 2009

pretty simple but i figured it out

music by ModdJobbs, my brother,  its an mc chris remix of  “Older Croud”
http://www.myspace.com/moddjobs

Go get the newest flash player if you dont have it please.

http://www.adobe.com/products/flashplayer/

Heres the example.

b00000010

midippvthingy2

And heres the code

WAY over imported, but its an experiment.

get TweenMax and the version of GreatWhite thats current with this post. both links are posted somewhere on this site.

the MP3 should be in the same folder as the SWF. its named OC.mp3 at the moment.


import flash.display.Sprite;
import flash.events.Event;
import flash.system.Security;
import flash.text.TextField;
import flash.text.TextFormat; 
import flash.events.Event;
import flash.ui.Mouse;
import flash.display.DisplayObject;
import flash.display.Shape;
import gs.*;
import gs.easing.*;
import gs.TweenMax;
 
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.*;


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

var viewport:Viewport3D = new Viewport3D(0, 0, true, true);
sp.addChild(viewport);
viewport.buttonMode = true;
                       
var renderer:BasicRenderEngine = new BasicRenderEngine();
                       
var scene:Scene3D = new Scene3D();
                       
var camera:Camera3D = new Camera3D();
camera.zoom = 11;
camera.focus = 100; 
//Spectrum Analisys///////////////////////////
var s:Sound = new Sound(new URLRequest("OC.mp3"));
s.play(1, 0);

var pointArray:Array = new Array();
var ba:ByteArray = new ByteArray();
for(var i:uint=0; i<255; i++)
  {
   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, 3, 3);
   plane.x = i * 3.75 - stage.width/2 +5;
   plane.y = 0;
   plane.name = "plane"+i;
   scene.addChild(plane);
   pointArray[i] = scene.getChildByName("plane"+i);
   //trace(pointArray);
   
   
   }

addEventListener(Event.ENTER_FRAME, enterFrameHandler);
  
  function enterFrameHandler(event:Event):void
  {
   SoundMixer.computeSpectrum(ba, false, 2);
   for(var i:uint=0; i<255; i++)
    {
     var num:Number = -ba.readFloat()*100;
     //trace(num);
     pointArray[i].scaleY = num;
     
    }
    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)*800)*0.2;
   
   camera.y = Math.max(-300, camera.y);
    renderer.renderScene(scene, camera, viewport);
    
  }