Close Show/hide page

Archive for the ‘flash’ Category

Augmented Reality Texture Extraction Experiment

Saturday, September 19th, 2009

This is an AR-based experiment that enables the user to lift textures from real-world objects in live video and apply them onto 3D objects that are overlayed on top of them. Only box primitives are supported here, but the general idea could be extended to other types of 3D primitives or potentially even more complex objects with some clever image compositing and UV mapping (a-la Photosynth, I guess).


View on Vimeo.
Thumbnail - Click me
Click for live demo

Click the image on the right to run a live version of the experiment, in case you have the patience to suffer thru the quick-and-dirty hotkey-based UI.

Print the AR marker (PDF | PNG) and point your webcam at it.

It’s running Saqoosha’s (feature-incomplete) Alchemy branch of the FLAR Toolkit, along with Papervision3D.

In the future, it would be nice to figure out is how to apply bilinear filtering to the ‘deperspectivized’ textures. I could also add a feature to export the textured 3d objects into a 3D file format (probably OBJ) if there’s any interest.

Conceptually, this piece builds on these two video projection tests, and is a modest implementation of one of the themes from this post of ideas for augmented reality.

Complex Spotlight Shadow Caster for Papervision3D

Monday, June 8th, 2009
Thumbnail - Click me

Simulates the projection of shadows coming from a spotlight light source onto irregular surfaces. In the supplied example, an animated MD2 model (from Quake 2) is casting a shadow onto the inside of a sphere. Supported parameters include shadow color, alpha, blur, falloff and texture map size, as well as position, rotation and field of view. This evolves out of the projection work posted previously.

Source:

SpotlightShadowCasterManager.as

Usage:

After instantiating the manager –

	_shadowCaster = new SpotlightShadowCasterManager();

– assign one or more DisplayObject3D’s that will block the light from the spotlight:

	_shadowCaster.registerShadowCasterObject(myMesh);

Then register one or more meshes that can have shadows cast upon it with registerShadowCasterObject. As the second argument, you must supply a BitmapMaterial utilized by the mesh on which the manager will draw the shadows. Usually, you’ll want to create a CompositeMaterial, with the BitmapMaterial most likely at the top of the stack. It might look something like this:

	var compositeMaterial = new CompositeMaterial();
	compositeMaterial.addMaterial( new ColorMaterial(0x888888) );
	var mat:BitmapMaterial = new BitmapMaterial( new BitmapData(1,1) );
	// .. the bitmapdata will get overwritten,
	//    but must contain _something_
	var sphere:TriangleMesh3D = new Sphere(compositeMaterial, 1000);

	_shadowCaster.registerShadowReceiverObject(sphere, mat);

To update the shadow textures, call

	_shadowCaster.update();

– probably in your onEnterFrame or onRenderTick function.

That’s enough to get going. From there, it’s just a matter of adjusting the projector’s position and orientation in relation to the objects in your scene with the properties projectorPosition, projectorPitch, and projectorRoll. Check the source for the various configurable properties like blur, alpha, color, etc.

Limitations, bugs:

(more…)

Video Projector Effect, Advanced

Sunday, May 31st, 2009
Thumbnail - Click me

This version handles arbitrary rotations, field of view / focal length, and uses correct math; the previous example faked it somewhat, doing everything basically with 2D math (but why admit to that? :). I found it twice as difficult getting to this point compared to the version posted a few days ago. It turns out that when you want to rotate more than 90 degrees around the x-axis, it’s good to make friends with quaternions, if only superficially.

And it’s interactive this time. By the way, is it not a royal pain to design an interface to control more than two axes in Flash for the web?

There’s still a lot that could be done right / better with this: backface culling (already tried and failed); frustrum culling; per-triangle alpha based on distance and angle to simulate light intensity; per-triangle focus/blur based on distance, maybe (but probably not); a more straightforward way to implement video; shadows… Basically, anything short of building a renderer-inside-a-renderer.

Bonus points for identifying the band to whom the set list pictured in the third image belongs.

Sorry, still no source.

 

Video Projector Effect

Tuesday, May 26th, 2009
Thumbnail - Click me

My general goal for this was to approximate the look of a video projection hitting a ‘non-planar surface’ or otherwise intersecting objects in a 3d scene.

The underlying logic wasn’t too painful. The UV coordinates of each vertex are all that need to be solved for. There’s a linear relationship between the position and orientation of the ‘projector’, and the world space position and UV coordinates of each vertex in the scene — requiring just algebra, which is nice, because that’s about all the math I know. JiglibFlash is being used for the physics action.

In its current implementation, the projector is limited to looking straight down the z-axis. I have a feeling that the most elegant approach for all this would be to extend Camera3D or to piggyback on top of the plumbing of the Papervision framework in some other way (hint, hint)(apologies for the mixed metaphor). Should I develop the ‘Projection Manager’ to handle arbitrary projector orientation, I’ll post the source along with an updated example.

Faceted Crystal Ball

Tuesday, March 3rd, 2009
Thumbnail - Click me

Or at least, that’s the best easy analogy to describe it.

Gist: The color of each triangle in the mesh is obtained by averaging the pixel colors of the underlying image at the screen positions under each vertex as well as at the triangles’ center point. Some FlatShader-like lighting is used to add a little more three-dimensionality. Finally, a BlurFilter is applied to the source image to keep the transitions between colors from feeling too abrupt.

Source code: PvColorFacets.as

Licensed under a Creative Commons Attribution 3.0 License.

A few ideas for augmented reality

Friday, February 27th, 2009

Now that I’ve finally allowed myself to look at couple online examples of so-called augmented reality, I’ve become quite excited by its possibilities. (Eg, why the hell did I not see this sooner?) But since I have a semi-unhealthy desire to act on every passing interesting idea that comes to mind, I figure I can at least partially purge myself of feeling torn between executing 36 different ideas I don’t have time to and shouldn’t act on by publishing the following notes I’ve compiled over the last couple days… Nonetheless, I’m sure I’ll steal some (or more likely, a lot of) time over the next period exploring one or two of these ideas.

(Expand all)


[+] Large-scale art installation idea
A giant ‘AR square’ (not sure of the right terminology here…) is painted on the side of a building. People come by to view it thru the web application – an AIR app, possibly. Because the ‘geometry’ of the landscape around the painted square is known in advance (eg, city streets, adjacent buildings, etc), and can be assumed to remain ‘constant’, that information could be ‘hardcoded’ into the 3d scene for the dynamic 3d elements to interact with in a visually convincing manner. The 3d parts could also be properly occluded behind other buildings or certain street obstacles. The dynamic elements wouldn’t even have to specifically interact with the location of the square itself; the square simply situates the camera in relation to the entire 3d space… A feature to save footage locally to be uploaded to a central repository later. Also, it wouldn’t necessarily have to be a large-scale context. The same treatment could be done within a room-sized scene.
[+] An interactive setup-phase to define scene geometry
With the square remaining in a fixed position, the user uses a few simple tools to draw 3d planes and rectangles on top of the video to describe the physical space around them. Eg, user draws 4 connecting line segments to describe a plane which represents a room’s wall. (And then defines a few more planes that describe the other walls, floor, and ceiling). Actually, you might just be able to pinpoint the 8 corners of the inside box which makes up the room… Maybe the user can also ‘overlay’ a 3d cube over a coffee table or desk. Etc. The program could even draw from a library of furniture-like 3d objects for the user to translate, rotate, and scale to overlay onto the scene. These 3d elements then constitute solid objects which the dynamic 3d elements can interact with. The camera is free to move around within the scene as long as the square remains fixed.

(a) 3d rain falling and hitting indoor furniture in interesting, ‘convincing’ ways. Or snowflakes falling, and collecting on various surfaces. Or a room getting slowly flooded with water, starting from the floor up to the ceiling… The supplied room geometry forming the basis for a platform game…

(b) Actually, if the user-supplied data and the positioning information from the AR Toolkit are accurate enough, there’s no reason why you couldn’t take snapshots from the video imagery, dynamically snip out the various quadrilaterals corresponding to the scene geometry, correct for perspective, and then skin the 3d geometry with that video texture information… !

(c) A 3d box is positioned over a real-world rectangle-shaped table or something. The top of that box is then used as a playing surface for something like pong pong or air hockey, which uses normal 3d game mechanics and assets but which is of course overlayed on top of live video. Imagine a replay feature where the winning shot is replayed in slow motion, but the user views it from different angles by moving the webcam. Virtual indoor handball by using AR in combination with motion detection.

(d) A square is stuck on a person’s chest. If the person’s height is supplied, we have enough information for a gross bounding box. This is enough information to go on to do a number of potentially interesting things. If we make the assumption that the subject remains generally upright and standing, we know the general position of the floor as well.

Update: Of course all these questions have already been dreamed up, and solved. This page from chronotext.org looks useful…

[+] Use of ‘physics’; use of a physics engine (eg, Jiglib)
As the AR square describes a plane, it of course lends itself to being acted upon as a solid surface. If we introduce extra scene geometry as described in points 1 or 2 above, even more could be done. Cubes or spheres falling from the ceiling to fill up a room (of course). Apply that sweet-ass Jiglib rally car example to a scene where the AR square is placed on the floor…

Update: Cloth demo by Saqoosha. (I guess I should do more ‘research’ before clicking ‘Publish’ ;)

[+] A specific visual piece: Tentacles
The AR square, placed on the body. Multiple tentacles coming out of the square in anime/sci-fi style. A fun exercise to play with for… inverse kinematics; 3d bezier curve animation; animating bezier patches to generate mesh geometry (Away3D 2.3); tree-like branching of tentacles; ‘generative art’ generally; crazy, lurid motions. Assuming a fixed camera, various ‘motion behaviors’ based on the movement of the square on the body; tentacles reacting fluidly to translation and rotation of the square.
[+] Interaction of dynamic 3d elements between two or more squares
Particles coming out of one square and going into another; gravity-based motion between squares; arcs of electricity going from one to the other; tentacles (from point 4) coming out of one body and ‘attacking’ another body to which another square is attached, for some reason.
[+] Interaction of the video bitmap information with the 3d elements
(a) The video image used as an environment map applied to the dynamic 3d elements, to make it look reflective and vaguely chrome-like (with a little cleverness and finesse).

(b) Pixelbender-like effects applied to the areas of the video that are ‘underneath’ or adjacent to the 3d elements. A 3d ‘fire’ coming out of the square, and the video imagery around the fire shimmering from the ‘heat’ of it. Wind-like motion-blur effect emanating from a virtual fan or something, and taking account of perspective. Pixel-dissolve-y action?

(c) Real-time chroma-keying to mask out background video imagery. Dynamic 3d elements can then be made to appear to be circling around the subject by appearing both in front of or ‘behind’ the video.

(d) The idea of treating the entire video with various video filters momentarily/sporadically to put the artificial content in bolder relief appeals to me…

[+] Intelligent video color sampling
(a) Application polls the color information of the incoming video to try to mimic, vaguely, the scene’s lighting as applied to the 3d elements. Again, with some clever hand-wavery and finesse.

(b) The dynamic 3d elements attempt to ‘mimic’ the colors of the video pixels around it. An animated lizard character or something. Maybe the colors of the faces of a mesh are assigned by averaging the colors of the area of the video image that the face normals are pointing at.

(c) Random ‘remixing’ of nearby patches of video imagery applied to a 3d mesh to create its texture. Another Pixel Bender possibility. The invisible suit in the movie ‘A Scanner Darkly’…

[+] Save video to disk from within application
Add built-in feature to easily save composited output to disk (eg, using SimpleFlvWriter).
[+] Science museum-style interactive art installation
As many AR ideas might require specific rules, setups, or optimal conditions, set them up in an expressedly controlled setting…
[+] Use of augmented reality + head-mounted display/webcam + geotagging + wireless internet = William Gibson’s Spook Country
The composited output fed into a head-mounted display/’VR goggles’, with a lightweight webcam mounted on it pointing outward. When combined with GPS tagging, “locative art” a la Spook Country. (Actually, the GPS tagging wouldn’t even be necessary, just nice to have). Ie: Users view 3d sculpures and whatnot (pushed via wireless) associated with AR squares (made to various scales) that are ‘tagged’ around the (real-world) landscape by other users.

Webcam Green Screen Effect w/ Pixel Bender

Tuesday, February 17th, 2009
Thumbnail - Click me

A green-screen/chroma key effect utilizing Pixel Bender. With this version, the live video is compared against a reference image rather than a static color. Additionally, the alpha of the output is graduated based on the color difference between the base image and the incoming video (rather than just being either ‘on’ or ‘off’). Both of these differences may or may not be good for practical use, but can create interesting imagery.

Use the sliders to adjust the cutoff/falloff curve for the alpha. Click “Reset base image” to set the base image with which to compare any further changes in the video against. You can also choose your own background image (click “Browse…” at the bottom). Works best against a plain background and presumably best of all with proper lighting against a green background…

When I wrote the image processing routine in pure Actionscript, it ran like a slideshow. The Pixel Bender version on a 4-core system runs about 30x faster.

Pixel Bender kernel: GreenScreenEffect.pbk

Licensed under a Creative Commons Attribution 3.0 License.

Webcam image compositor, creating PNG48’s

Monday, February 9th, 2009

How it would look if you took a webcam or camera, and captured several frames of the same scene in quick succession, and then essentially averaged them out and composited them into one? My guess was that the resulting image would retain most of its sharpness but lose most of the ‘noise’. I made this quick mini-app with that thought in mind.

Here is an example of my results (before and after). The images were captured with a Logitech Quickcam Pro 9000 at a resolution of 1600×1200 (averaged from 128 (!) still images), and were not scaled or retouched.

Example - single frame Example - composited version
Example - movement...

As a side benefit, if the camera — or something in the foreground of the scene — moves during the image capturing process, you can get photography-like effects that look like a long exposure…

A PNG48 encoder class…

(more…)

Mesh Slicer v1.9 (Cube Steak Edition)

Sunday, December 21st, 2008

Sooner than expected (thanks no doubt to my first snow storm in two years giving me all the excuse I needed to stay in all day), this version covers bullet-point 2 of the previous post:

Adding extra faces to the cut-up meshes to make them closed shapes again would make the whole thing feel more “physical” and less abstract-graphics-demoey…

I’m using Adobe’s Kuler service to generate the color scheme, which I find quite exciting. Because it saves this particular demo from a world of red and black — which are basically the only colors I use when left to my own devices. (Press [C] to cycle through colors) Many thanks to Aden Forshaw for the AS3/Kuler example.

Finally worth noting is that the ‘physics’ have improved a little. I was previously using vertex count as a proxy for mass. Using the volume of the axis-aligned bounding box ends up being a better way of faking it.






Cutting up a mesh (into tiny little pieces)

Friday, December 19th, 2008
Thumbnail - Click me

A demonstration of splitting a mesh in two along an arbitrary plane. With some faux-physics for added value. I was thinking about the ‘laser room scene’ in Resident Evil, LOL.

I’ve included the source code of a minimal example showing how to cut up the faces of a mesh along a plane:

PlaneSplitMinimalExample.as | compiled swf

This is the foundation for everything in this demo, and for the following ideas which I think would be nice to see executed in Flash–

  • Making a more advanced intersection test using rectangles (which are bounded) instead of planes (which are infinite). The additional control would open up all sorts of fun possibilities. Projectiles or edge weapons hitting targets that get cleaved in half…
  • Adding extra faces to the cut-up meshes to make them closed shapes again would make the whole thing feel more “physical” and less abstract-graphics-demoey. And make it more useful for practical applications.
  • Maybe adding the ability to cut along an arbitrary path made up of connected line segments (like a cookie cutter)…
  • Make sure to try resetting the scene, pausing (with spacebar), clicking through a mesh several times, and then unpausing..

    Oh yeah, and the usual disclaimer/apologies about how much this demo hates your CPU, and how unoptimized it is (e.g., right now every face in the scene is tested against the plane with every click (ouch!)). Built with the most recent revision of Papervision 3D.

    Also, apologies for the long hiatus. I’ve been busy moving to the NYC. And working a lot. But y’know, whatever..

    UPDATE: John Lindquist has kindly pointed out there’s already a helper function in the Papervision framework for cutting meshes with planes! – MeshUtil.cutTriangleMesh().

    Licensed under a Creative Commons Attribution 3.0 License.