Webcam 3D Cube Control
August 9th, 2008Inspired by quasimodo’s minority cube I have tryed to make my own based on PaperVision3D (as 3D engine for the cube) and Soulwire (motion tracking). Here’s the result:
This movie requires Flash Player 9
Note: You need a webcam to see this demo in action. Nothing is being recorded (no data is being sent to server).
A big difference between quasimodo’s and mine its that he can track your hand screwing (that’s really nice, so you can rotate all the axis). Another diference is that mine is Open Source
Please respect the credits.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | /* * CREDITS * ¯¯¯¯¯¯¯ * MAIN SOURCE: * Author: Edgar Griñant * Website: labs.grinant.com * * SOULWIRE CLASS: * Author: Justin Windle * Website: soulwire.co.uk * * PAPERVISION3D CLASSES: * Author: Carlos Ulloa * Website: blog.papervision3d.org * * INSPIRED BY QUASIMODO'S MINORITY CUBE (incubator.quasimondo.com/flash/minority_cube.php) */ package { // FLASH CLASSES import flash.display.Sprite; import flash.events.Event; import flash.media.Camera; import flash.media.Video; // SOULWIRE CLASS import com.soulwire.media.MotionTracker; // PAPERVISION3D CLASSES import org.papervision3d.cameras.Camera3D; import org.papervision3d.objects.primitives.Cube; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D; import org.papervision3d.objects.DisplayObject3D; import org.papervision3d.materials.utils.MaterialsList; import org.papervision3d.core.proto.MaterialObject3D; import org.papervision3d.materials.BitmapFileMaterial; public class Main extends Sprite { /*______________ ||PRIVATE VARS|| ¯¯¯¯¯¯¯¯¯¯¯¯¯¯*/ // SOULWIRE private var motionTracker :MotionTracker; // PAPERVISION private var viewport :Viewport3D; private var scene :Scene3D; private var camera :Camera3D; private var cube :Cube; private var renderer :BasicRenderEngine; private var universe :DisplayObject3D; /*_____________ ||CONSTRUCTOR|| ¯¯¯¯¯¯¯¯¯¯¯¯¯*/ public function Main() { // PAPERVISION3D ENVIRONMENT init3D(); createCube(); // SOULWIRE MOTION TRACKING SETUP soulwire(); // EVENT HANDLER ON ENTER FRAME (TRACK, ROTATE THE CUBE THEN RENDER) addEventListener( Event.ENTER_FRAME, track ); } private function soulwire():void { // All of these variables can be changed to get a more acurate motion tracking var camW:Number = 320; var camH:Number = 240; var blur:Number = 20; var brightness:Number = 20; var contrast:Number = 150; var minArea:Number = 10; // Create the camera var cam:Camera = Camera.getCamera(); cam.setMode( camW, camH, stage.frameRate ); // Create a video var vid:Video = new Video( camW, camH ); vid.attachCamera( cam ); // Create the Motion Tracker motionTracker = new MotionTracker( vid ); // We flip the input as we want a mirror image motionTracker.flipInput = true; // Apply some filters to ease the tracking motionTracker.blur = blur; motionTracker.brightness = brightness; motionTracker.contrast = contrast; motionTracker.minArea = minArea; } private function track( e:Event ):void { // Tell the MotionTracker to update itself motionTracker.track(); // Rotate the cube cube.rotationY -= ((motionTracker.x ) + cube.rotationY) / 20; cube.rotationX -= ((motionTracker.y ) + cube.rotationX) / 20; // Render the scene renderer.renderScene(scene, camera, viewport); } private function init3D():void { // VIEWPORT viewport = new Viewport3D( 0, 0, true); addChild( viewport ); // RENDERER renderer = new BasicRenderEngine(); // SCENE scene = new Scene3D(); // CAMERA camera = new Camera3D(); camera.z = -1000; // UNIVERSE universe = new DisplayObject3D(); scene.addChild(universe); } private function createCube():void { // Set the textures var materials:MaterialsList = new MaterialsList( { all: new BitmapFileMaterial("<a href="http://labs.grinant.com/uploads/2008/08/cube.png">http://labs.grinant.com/uploads/2008/08/cube.png</a>") }); // Create the cube cube = new Cube(materials); universe.addChild(cube); } } } |
Posted in AS3, PaperVision3D, Soulwire, Webcam | 1 Comment »