3D Physics XBAP

I’ve created a small XBAP 3D physics demo for pure geeky delight.  It’s got a long way to go, but it’s got a nice button that lets you drop beachballs on to each other, so I think that makes it morally OK smile_wink

It’s built on a managed version of the Bullet Physics Library, tweaked slightly for WPF (so it’ll run locally as an XBAP).  Give it a try and see what you think.  Some general notes:

  • Performance is fair; it could struggle on slow machines.  There are loads of optimizations we can do with WPF 3D (merging models into one GeometryModel3D can give huge improvements) but I’ll save that for another post smile_shades
  • Dropping too many objects will bring any system to its knees pretty quickly.  It’s not culling anything to a view frustum yet and the sphere models probably have too many vertices, so even if objects roll off screen they’ll still suck your CPU dry.  Just don’t do it smile_regular
  • You’ll get better performance with spheres than boxes.  They generally come to a rest more decisively (the physics engine marks objects as inactive when they’re at rest, at least until something hits them).  Boxes can currently ‘jitter’ a while before they settle down.

I’ve published the source on CodePlex.  Let me know if you’d be interested in contributing!

UPDATE: Did a couple of rendering tweaks and enabled camera movements (drag mouse to move, right-drag to zoom).  Also, thanks for the great feedback!

UPDATE 2: Fixed earlier ‘rolling’ issue (my bad) and added a ‘drop box’ button.  Boxes don’t behave quite as nicely as the beachballs yet (they act like jello cubes) but they’re still a lot of fun smile_party

38 Comments

  1. Nice! This is very cool. In case you’re interested in some feedback from the community, here’s my 2 cents. I think it would be awesome if:
    1) Larger planets had stronger gravitational attraction.

    2) Planets could have one or more moon which orbits it.

    3) The moons could collide with other objects in the scene and shatter. (That would be sooo cool!)

    Anyways, thanks for the cool app. 🙂

    Josh

    Reply

  2. Ruurd – Thanks! But sorry for the confusion. My original demo had planets rolling around (Jupiter actually; was the only bitmap I had to hand!). The problem was gas giants don’t usually bounce and roll so well, so when I updated it (for some performance improvements and fix to how the physics engine was used) I threw in some beachballs instead 🙂 I was going to leave the post unedited (with just updates at the bottom) but didn’t want it to be too confusing for newer readers. I really like Josh’s suggestion of a planetary demo though, so I might just make one 😀

    Reply

  3. 😉
    You’re really on to something here. There is probably going to be great demand for 2d and 3d engines for wpf.
    I was looking in to some of the examples of Kevin Moore where he is doing funky 2d physics, and I definitely see opportunities for animations even in business applications.

    Reply

  4. how did you created the 3d scenes? the sames objects that are used in wpf? how do you manage to create the 3d objects for the browser?

    Reply

  5. Jose – The objects are just regular WPF 3D meshes. I cheated a little on the spheres and used some code by Daniel Lehenbauer (there’s also some code for cones and cylinders I think). It calculated all the texture co-ordinates and vertex normals. The boxes (including the ground) are made from 24 vertices to prevent the [Gouraud] shading blending the corners away (none of the faces share vertices). Hope this helps!

    Reply

  6. Try piling up 3 boxes (possible but takes a bit of trying), the ones already on ground tend to stay wobbling really long as if the surfaces had no friction to stop the wobble sooner.

    Reply

  7. Joku – Yeah I’ve noticed that; it’s something I’ve been meaning to fix! I don’t think it’s a problem with the physics engine though (unless I did a sloppy port to WPF). Right now the cubes bounce like jello, which is still kinda fun 🙂

    Reply

  8. John – I’d love to take a look at the terrain XBAP but I’m getting an error 😦 Here are the details (edited for length):

    ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * An exception occurred while downloading the manifest. Following failure messages were detected:
    + Downloading http://www.lunchgamer.com/ did not succeed.
    + The remote server returned an error: (500) Internal Server Error.

    COMPONENT STORE TRANSACTION FAILURE SUMMARY
    No transaction error was detected.

    ERROR DETAILS
    Following errors were detected during this operation.
    * [7/29/2007 5:58:44 PM] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
    – Downloading http://www.lunchgamer.com/ did not succeed.
    – Source: System.Deployment
    – Stack trace:
    at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
    at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
    at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
    at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
    at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirect(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
    at System.Deployment.Application.DownloadManager.DownloadDeploymentManifest(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, IDownloadNotification notification, DownloadOptions options)
    at System.Deployment.Application.DeploymentManager.BindCore(Boolean blocking, TempFile& tempDeploy, TempDirectory& tempAppDir, FileStream& refTransaction, String& productName)
    at System.Deployment.Application.DeploymentManager.BindAsyncWorker()
    — Inner Exception —
    System.Net.WebException
    – The remote server returned an error: (500) Internal Server Error.
    – Source: System
    – Stack trace:
    at System.Net.HttpWebRequest.GetResponse()
    at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)

    Reply

  9. Hey John – That works great now! Very cool and runs nice & smooth 🙂

    Would it be tricky to make it hit Virtual Earth or Google maps? (Virtual Earth has height data too I think; just a thought!).

    Reply

  10. I’d have to dig into their API a bit. Certainly the map images themselves would be the surface texture. I’m assuming the height map data is accessible as Virtual Earth 3D uses it (but I don’t know if it’s public). They also now do “hill shading” (there’s probably a better name, but I think that’s what they called it) where it applies some shading as an overlay on 2D maps (that’s probably done on the server through).

    Maybe this could help: http://blogs.msdn.com/publicsector/archive/2007/05/08/update-virtual-earth-with-silverlight-sample.aspx.

    Reply

  11. John – What error/message do you get? For some errors (related to old cached versions) clearing any cached XBAPs may help… Copy the following into a batch file and just run it if things get weird (replace with your Windows account name).:

    @echo off
    rundll32 %windir%\system32\dfshim.dll CleanOnlineAppCache
    del /S /Q /F “C:\Documents and Settings\\Local Settings\Apps\2.0\*.*”

    (I can’t remember where I dug this up from, but maybe it’ll help) 🙂

    Reply

  12. sorry, i broke this one to….

    PLATFORM VERSION INFO
    Windows : 6.0.6000.0 (Win32NT)
    Common Language Runtime : 2.0.50727.1318
    System.Deployment.dll : 2.0.50727.1318 (redbitsb1.050727-1300)
    mscorwks.dll : 2.0.50727.1318 (redbitsb1.050727-1300)
    dfshim.dll : 2.0.50727.1318 (redbitsb1.050727-1300)

    SOURCES
    Deployment url : http://www.chriscavanagh.com/Chris/CJC.Bullet/BulletDemo1.xbap

    ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * An exception occurred while downloading the manifest. Following failure messages were detected:
    + Downloading http://www.chriscavanagh.com/Chris/CJC.Bullet/BulletDemo1.xbap did not succeed.
    + The remote server returned an error: (407) Proxy Authentication Required.

    COMPONENT STORE TRANSACTION FAILURE SUMMARY
    No transaction error was detected.

    WARNINGS
    There were no warnings during this operation.

    OPERATION PROGRESS STATUS
    No phase information is available.

    ERROR DETAILS
    Following errors were detected during this operation.
    * [07/08/2007 12:05:08] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
    – Downloading http://www.chriscavanagh.com/Chris/CJC.Bullet/BulletDemo1.xbap did not succeed.
    – Source: System.Deployment
    – Stack trace:
    at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
    at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
    at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
    at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
    at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirect(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
    at System.Deployment.Application.DownloadManager.DownloadDeploymentManifest(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, IDownloadNotification notification, DownloadOptions options)
    at System.Deployment.Application.DeploymentManager.BindCore(Boolean blocking, TempFile& tempDeploy, TempDirectory& tempAppDir, FileStream& refTransaction, String& productName)
    at System.Deployment.Application.DeploymentManager.BindAsyncWorker()
    — Inner Exception —
    System.Net.WebException
    – The remote server returned an error: (407) Proxy Authentication Required.
    – Source: System
    – Stack trace:
    at System.Net.HttpWebRequest.GetResponse()
    at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)

    COMPONENT STORE TRANSACTION DETAILS
    No transaction information is available.

    Martin

    Reply

  13. Wow. Too cool. I never cease to be amazed at what’s possible with the framework. I’ve really got to stop making boring business apps and play with some of this stuff.

    Reply

  14. This looks very cool from the description, and is something I’ve been interested in some time. Unfortunately, like most year-old Web content, it doesn’t actually work. I get exceptions when trying to run the online demo.

    I’ll have to check out the code, I guess 🙂

    Reply

Leave a reply to theWPFblog » WPF 3D Physics Poopr Application Cancel reply