Posts

Showing posts with the label papervision3d

Away3D 3.6 Essentials – Book Review

Ok, so here’s a book I definitely can recommend! ;-) Away3D 3.6 Essentials by Matthew Casperson (published by Packt) is a really great introduction to creating 3D content in Flash with the free and open source Away3D library.



For a brief time in the summer of 2008 I was the golden-boy of Flash 3D after my team at Bloc launched the Papervision-powered game/transmedia experiential play-node called Meta4orce, which I documented to launch my new blog. While my experience and high google ranking for the term “papervision developer” (#2 – boom!) earned me a couple more PV3D gigs, it all tailed off by the end of 2009. The fact that the Papervision3D team pretty-much abandoned development and moved on to new projects didn’t help, but there was also a sense that the novelty of 3D Flash content was wearing off (especially with such jaw-dropping competition as Unity3D’s island demo).

But 3D Flash content was not in fact dead, and the Away3D engine very ably filled the gap left by the demise of Papervision. I never kept up with developments in the Away3D world, so this book was a great re-introduction. So what I have I learned? Well one nice thing to see is that many of the techniques I had to manually create in my Papervision3D work are actually integrated into the Away3D engine itself. This includes things like:
  • level-of-detail (LOD) model-swapping, so that when objects are far away they use a simpler mesh.
  • flat sprites and multi-directional sprites like you see in Doom and Duke Nukem 3D.
  • splitting objects into individual layers and display objects, to solve triangle-sorting issues when a model sits on top of the ground.
  • skyboxes.
  • isometric camera.
  • depth of field effects using sequences of sprites at different levels of blur.
Matthew’s book gives a good explanation of the theory behind these techniques (and many more – the book is incredibly thorough and comprehensive), as well as how to apply them using Away3D. I also learned a bit of general 3D theory about things like UV mapping, triangle Z-sorting and effects like normal mapping and bump mapping. On the whole, though, this book is very much a practical manual of how to use each of Away3D’s features. If I have any criticism, it is that there’s not too much there that you couldn’t get through scouring the documentation and source code, and it doesn’t ever pulled together all the strands to make one amazing demo at the end. That’s up you to go off and do yourself I guess. One really nice addition is that this book does document Away3D’s bugs and offers work-arounds, which could well prevent you from pulling your hair out a few times.

Reading Away3D 3.6 Essentials has really re-opened my interest in Flash 3D, and I think I’m going to do a few experiments with Away3D in its current form, so that when the hardware accelerated magic of Stage3D and Away3D v4 hit Flash, I’m not playing catch-up.

Better rollovers in PaperVision3D

I found a little perculiarity in the latest release of PaperVision3D today, and came up with a fix, so I thought I'd post it. The way it currently works, rollovers and rollouts may not be detected if you have a moving camera (which I normally do - hey it looks cooler!).

To fix, all you need to do is open org.papervision3d.core.utils.InteractiveSceneManager and delete or comment out line 236 if ( hasMouseMoved() ) in the handleMouseOver function and line 247 if( !hasMouseMoved() ) return; in the handleMouseOut function.

Now you will get nice responsive mouse events even if you have a nice drifty camera. I have tipped off Seb from the PV3D via twitter so I think those clever people are going to look into it.

By the way, if you haven't tried combining PaperVision3D with TweenMax, I highly recomend you do! I've had some freakin' incredible results that I wish I could post (but I can't).

The Wrong Door: creating PaperVision3D character animation with the Flash timeline

NOTE: I am now a freelance developer, and no longer an employee of Bloc.

Over at my employers, BLOC, we recently put the finishing touches on a new website to support BBC3's mad comedy show The Wrong Door. The site has lots of silly toys, interactions and animations to amuse you, but I thought the best one to document would be the experimental method I used to get some basic character animation into PaperVision3D.



The animation in question is of a giant robot walking around an asteroid on the site's homepage. My unorthodox approach was to make a side-on animation of the walk cycle using a set of MovieClips on the Flash timeline, then at runtime update the positions of the 3D robot's limbs based on the positions of these MovieClips.



The obvious drawback of this method is that all movement can only happen in 2 dimensions - so the effect will never look as cool as true motion capture and bones - but the advantages are that editing the movement is very easy, and you have a lot of potential for runtime control. This technique was fine for animating a robot, because it's OK if he looks a bit stiff, but for general character animation it's definitely not recommended, so I'm going to keep exploring new ways to bring animation into PaperVision3D. UPDATE! - as Away3D now supports Collada Bones, maybe that's the way to go.

Anyway, these were my steps. I started with one of Eadweard Muybridge's famous motion captures, of an old naked guy:



I used the walk on the bottom row. Based loosely on this movement, by eye I positioned a load of rectangular MovieClips on the timeline, representing the upper arms, lower arms, thighs, shins, torso and head. I used Muybridge's photos to set my keyframes, but also added tweens so that I could alter the speed of movement. It's important to put the rotation/pivot point at the end of the limb or none of the tweens will work. In the halcion days of banner-ads I made monster timeline's like this all the time, so it was a fun bit of nostalgia! (This kind of animation should get a lot easier with Flash CS4 and its native bones and inverse kinematics - but we'll see...)



With the walk animation complete, I then set about another timeline animation, for the robot's path around the asteroid. 3D artist Matt supplied me with a cut-away of the robot's path - I drew around this with the pen tool and set up a motion guide. Oldskool!



With the 2D animation complete, Matt 3D supplied me with the robot's body parts as seperate ActionScript classes, plus the texture bitmap. With these added to the PV3D scene, it was just a matter of updating the positions on the ENTER_FRAME listener. The MovieClip containing the animation is created but never added to the stage - the timeline animations still run, even though it is not rendered by the Flash player. It took a bit of trial and error to work out which 2D dimensions to map to which in 3D space, and I used A LOT of nested containers to simplify this process. Nesting a DisplayObect3D inside another is very useful PV3D feature.

I guess I'm the only person to have attempted this madness - I'd love to hear otherwise though so please leave comments!

Meta4orce: creating 3D Flash games with PaperVision3D

NOTE: I am now a freelance developer, and no longer an employee of Bloc.

Over at Bloc we recently launched Meta4orce, a unique interactive sci-fi TV show which was broadcast on BBC2 and is also available globally via the website. With a story created by legendary comic-book writer Peter Milligan, it's a project I'm very proud to have worked on. When viewed online, the show integrates broadcast quality animation with high quality interactive games. (Please note, it's very much a broadband only site as it features a lot of video, and the games do require a decent PC or Intel Mac to run smoothly). UPDATE: If you want to know even more about the project, I've been answering game design questions over at the excellent Brainy Gamer blog.

We wanted the site to invoke the gritty, futuristic feeling of the show, and also offer a gaming experience that resonated with console gamers. To this end we made extensive use of PaperVision3D, specifically version 2.0, dubbed Great White (at the moment this can only be downloaded via a subversion client, but these are free and fairly easy to set up). As we did some fairly unusual things with PV3D, I thought it might be useful to document some of the solutions and work-arounds we came up with:

Mako User Interface



The main user interface is implemented in Papervision3D, and makes extensive use of the MovieMaterial class to map 2D animations onto 3D planes. Developer Mat applied a custom displacement map to the Viewport to create the cool glitch effect. We found that setting the stage quality to LOW is a good way to get a bit of extra performance out of PV3D.

Deadsphere Pt. I



This first-person perspective maze game uses a custom Model View Controller framework to link a 2D maze game mechanic to a Papervision3D view. I initially created the game in a 2D top-down view, then added another View to display the game in 3D. This is probably one of the few times it's actually sensible to use MVC on a Flash game (I think I'll cover this topic in more detail in a future post).

The main technical challenge was to stop PV3D from clipping the walls when they are close to the camera - basically it seems that planes are not drawn if PaperVision thinks any one of their 3 corners is outside the viewing area. I got around this by switching low polygon, 2 triangle plains for high polygon plains when the camera is close to them. I also used a lower resolution texture to render far-away walls. To improve memory usage and general performance, all the animated textures in the maze are created by swapping the BitmapMaterial of a plane every frame, rather than using MovieMaterial - this eliminates a lot of costly copyPixels operations. Again to try and reduce the amount of memory PV3D was using, I implemented a custom object pooling system for textures and geometry - so that walls are re-used between different levels. The levels were created in a simple editor which saved out strings of 1s and 0s, so a basic 4x4 square level might look like "11110011001111".

Shock to the system



This tower defence game uses PV3D to render a 3D view of a 2D game mechanic, again using MVC to separate game logic from graphics rendering. The main technical challenge was to stop the towers and enemies clipping strangely with the floor – when 2 polygons are close together they will flicker wildly as PV3D cannot decide which to draw on top of which. I got around this by rendering 2 separate PV3D scenes into 2 separate viewports – one for the interactive (clickable) floor grid, and one for the towers and enemies on top. As this slowed the frame rate dramatically, it only renders the scene every other frame, so while the game logic and user interface run at 30 frames per second, the 3D graphics effectively render at 15fps.

3D artist Matt modelled the defence towers in Maya and then opened in Blender and exported to ActionScript classes. PaperVision models have to be very low polygon if you want your game to run at all smoothly! To improve performance, the enemies are pre rendered animations mapped onto transparent 2 triangle plains, which are set to point at the camera every frame using PV3D's "lookAt" function (I couldn’t find a native “billboard” or “sprite” class in PV3D to handle this effect – I’m sure one must exist somewhere though - I know Away3D has them).

Under the surface



In this game the player looks for clues beneath the waves of a flooded London street. For this game, developer / 3D guy Mark modelled a scene in Blender and exported the parts as AS classes. Unlike some of the other Meta4orce games, we didn’t use an MVC pattern – we directly control the camera in the scene using PV3D's built-in functions like moveForward, pitch, roll etc. This game also uses MovieMaterial for animation and 2D planes pointed at the camera to create the illusion of 3D objects. The built-in virtual mouse in PV3D makes it really easy to add interaction such as rollovers to 3D objects. This is one of PV3D's best points. Camera clipping was again a problem on this game, so we don’t allow the player to get too close to the walls or floor.

Deadsphere Pt. II



This 3rd person perspective maze game is implemented in a similar way to Deadsphere Pt. I and Shock to the system, with an MVC pattern, and all the game logic separated from the PV3D view. One cool thing on all the MVC games is that the sound is all handled as if it were another "view" onto the game "model", so none of the game classes need a reference to the sound code, or even know that sound exists. This kind of "loose coupling" is considered good practice in object oriented programming.

The avatar you control is very subtly animated by swapping between 10 separate models representing the frames of animation. This is a very inefficient method of animation that we wouldn’t recommend anyone else use (especially as it’s almost too subtle to notice anyway!). For future projects I definitely look forward to a work flow where 3D animation can easily be brought from Maya to Flash, maybe with "bones" (I’m sure someone is working on this if it doesn’t exist already).

Pandora



This is really just an extension of the Mako user interface, with simple 2D mini-games rendered onto PV3D planes using MovieMaterial. We made sure to use the “animated” property very sparingly, to stop PV3D redrawing materials unnecessarily, as that was the main source of slow down. Also, when the games are full screen, they are removed from PaperVision and added to the main stage, as interactivity is more stable and fully featured this way.

Pier to Piers



A hovercraft chase through the flooded remains of London! Just a note here to say that this game doesn’t use Papervision3D at all, but our own custom mode7 engine, created by developer Mat, which we like to call Samuri7!

Summary

We did some neat things on this project - one cool thing is that while you're playing the game we're buffering the next video in the background, so it's ready to watch when you finish playing. Please go and play with the site and tell me what you think - personally I love it, but understand that it's not to everybody's tastes (some people don't like sci-fi, some people don't like websites that use a lot of CPU and memory, etc etc). Either way, we achieved a lot and made PaperVision3D do some things it didn't want to, so it's all good!

If you want to read more about the project there are interviews with Peter Milligan, with the Director and Executive Producer and with the design and development team at the excellent "Adventures in Primetime" blog. The BBC site also has the full cast and crew credits for Meta4orce.