Close Show/hide page

Archive for the ‘papervision3d’ Category

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.

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.

    Robot Arm, Slideshow Viewer

    Thursday, June 19th, 2008
    Thumbnail - Click me

    This is a slideshow viewer, utilizing the robot arm from this previous post done with Papervision 3D. I created it on the occasion of a presentation I’m preparing for the Flash user group, San Flashcisco. In typical fashion, I’ve spent more time creating the slideshow program than preparing the presentation itself, or the slides for it. :P The slides themselves (dealing with Papervision3D) aren’t of too much value outside of the context of the presentation, but you can choose your own if you like (see below).

    The program uses hotkeys only –

    
      [SPACE/BACKSPACE]  Next/previous slide
      [BRACKET KEYS]     Next/previous slide without transition
      [COMMA]            Zoom in and out of slide, for the fun of it
    
       Also:             [1/Q, 2/W, 3/E, 4/R, 5/T, 6/Y, and 7/U] - Rotate joints
                         [Z,X,C,V] - Moves robot arm to various keyframes/poses
    
    

    How to use this with your own images, from the Desktop…

    (more…)

    Strange 3D objects, Perlin noise

    Sunday, May 18th, 2008
    Thumbnail - Click me

    Recently I’ve been thinking on ways of programmatically creating curvy and strange, organic-looking shapes in 3D. And reflecting on the fact that I can think of no particular ‘practical’ application for such an endeavor. And concluding that that’s part of what makes it interesting…

    Here’s the high-level recipe:

    Start with a cylinder or sphere-shaped mesh, where the vertices are evenly spaced . The vertices of the mesh can be thought of as a matrix or grid, where the left and right edges are curved 360 degrees until they meet.

    Take an interesting bitmap with varying light and dark areas, whose height and width match the number of rows and columns in the mesh.

    Use brightness (or some other color-derived property) from the pixels of the bitmap as a multiplier value to dictate the distance of the corresponding vertices from the z-axis (center) of the shape.

    That’s basically it. In Flash, the built-in BitmapData.perlinNoise method is perfect for generating interesting gradients. The kicker is that the last parameter of the method allows you to change the x & y offset for each ‘octave’ (think semi-transparent layer), allowing for gradual, random-looking changes over time.

    So on each update, change the offset of each octave of the perlin noise image and recalculate the vertices accordingly. The behavior and properties of Perlin noise does the rest.

    Main class.as | Project.zip (Flex Builder 3)

    Licensed under a Creative Commons Attribution 3.0 License.

    Testing Kinematics with Papervision3D, Collada

    Wednesday, January 30th, 2008
    Thumbnail - Click me

    A forward kinematics experiment using Papervision3D v2.0 alpha and a Collada 3D model of a robotic arm.

    Hope you enjoy it.

    I don’t want to release any source from this yet, as I want to do some more work on it, relating to the following items…

    (more…)

    Papervision3D training in San Francisco at EVB

    Tuesday, January 15th, 2008

    Just wanted to let anyone in or around the Bay Area know that there’s going to be a Papervision3D training with John Grden on the weekend of February 3-4 in San Francisco. It’s being held at EVB, which is where I work.

    Here’s the link: http://pv3d.eventbrite.com/

    If you’re going, look me up, as I’ll be there…