(YASL53DP) Supercharging Silverlight 5 3D projects with the Babylon Toolkit


(Yet Another Silverlight 5 3D Post)

I know, I've been doing a good bit of engine/toolkit and Silverlight 5 posts recently. This should be it for a little while, at least for Silverlight 3D stuff. But this post has been burning a hole in my C4F Post Planning OneNote Notebook for a while, so...

Answer: Provides a complete toolbox for Silverlight 5 3D

And includes:

  • A complete Effect class with shaders and parameters support (with an integrate shaders and registers cache system)
  • A Model/ModelMesh/ModelMeshPart object model
  • A ModelContent/ModelMeshContent/ModelMeshPartContent object model to create Model hierarchy
  • An importation system with support for .OBJ files
  • Cameras classes:
    • Orbit camera
    • Regular camera
  • A BasicEffect for simple rendering modes which supports:
    • Diffuse color & texture
    • Specular color & texture
    • Bump texture
    • Ambient color
    • Point light
  • Ray intersections system
    • BoundingSphere
    • Mesh vs Ray

Question: What is the Babylon Toolkit

Anything with a Viper model gets extra credit...


The toolkit and the sample comes in mixed binary/source form, via the v1.0.3 release page. If you download the sample source, Babylon.Toolkit.Sample.zip, also make sure to download the library binaries, Babylon.Toolkit. Then when you open the Sample project, fix up the References, using the DLL's from the binary download.


Now if you get the entire source for the project and want to compile it yourself, you should see this post, We're all one little world... as shown with the Silverlight 5 3D sample, Solar Wind, focusing on how the stuff you need to compile it. Both use the Shader MSBuild Task... OR if you already have the DirectX SDK installed, you go into the Libs folder use the ShaderBuildTaskSetup.msi to install the MSBuild Task.


So anyway...

What does that Viper like really?


(After a while, I don't see the code... There's a Blond, Redhead...)

Getting the Viper on the screen is pretty easy.

Here's the main drawing loop;

private void DrawingSurface_Draw(object sender, DrawEventArgs e)
if (model == null)
Dispatcher.BeginInvoke(() => InitModel(e.GraphicsDevice));

statesManager = new StatesManager(e.GraphicsDevice);

if (model == null)

DateTime start = DateTime.Now;

// States
statesManager.DepthBufferEnable = true;
statesManager.CullMode = CullMode.None;
e.GraphicsDevice.BlendState = BlendState.AlphaBlend;

// Draw
e.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, new Color(0, 0, 0, 0), 1.0f, 0);

foreach (ModelMesh mesh in model.Meshes)
foreach (BasicEffect basicEffect in mesh.Effects)
basicEffect.SceneAmbientColor = new Color(0.3f, 0.3f, 0.3f, 0);
basicEffect.World = Matrix.Identity;
basicEffect.View = camera.View;
basicEffect.Projection = camera.Projection;
basicEffect.LightPosition = camera.Position + new Vector3(1, 5, 3);
basicEffect.CameraPosition = camera.Position;

basicEffect.EmissiveColor = mesh == selectedMesh ? new Color(0.5f, 0.5f, 0.5f, 0) : Color.Black;



double duration = (double)DateTime.Now.Subtract(start).Ticks / TimeSpan.TicksPerMillisecond;
int verticesCount = model.Meshes.Sum(v => v.VerticesCount);
Dispatcher.BeginInvoke(() =>
frameTime.Text = string.Format("Frame time : {0:0.00} ms / {1:0.00} fps", duration, 1000 / duration);
counters.Text = string.Format("Vertices count : {0}", verticesCount);


Which calls the InitModel to actually load the Viper;

private void InitModel(GraphicsDevice device)
Stream objStream = Application.GetResourceStream(new Uri("/Babylon.Toolbox.Sample;component/Models/Viper-mk-IV-fighter.obj", UriKind.Relative)).Stream;
ObjImporter importer = new ObjImporter();

importer.OnImportCompleted += m =>
waitBar.Visibility = Visibility.Collapsed;
model = m.BuildModel(device, new ModelBuilding.BasicEffectMaterialConverter());

camera.Radius = model.BoundingSphere.Radius * 1.5f;
camera.Target = model.BoundingSphere.Center;


// Report loading progress
importer.OnImportProgressChanged += p =>
waitProgressBar.Value = p;

waitBar.Visibility = Visibility.Visible;

importer.ImportAsync(objStream, GetResourceStream, ImportationOptions.Optimize | ImportationOptions.GeneratePickingInformations);

Once loaded, moving the camera around;

private void drawingSurface_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
Point currentPosition = e.GetPosition(drawingSurface);

switch (currentMode)
case MouseMode.ArcRotate:
if (!mouseLeftDown)

camera.InertialAlpha += (float)(currentPosition.X - startPosition.X) * camera.AngularSpeed;
camera.InertialBeta -= (float)(currentPosition.Y - startPosition.Y) * camera.AngularSpeed;
startPosition = currentPosition;
case MouseMode.ObjectPicking:...

So if you're 3D'ing in Silverlight 5, don't reinvent the wheel. There's a number of cool toolkits and engines like the Babylon Toolkit. Remember, friends not let friends waste cycles on stuff that's available free elsewhere... Wink

Here’s a few more links you might find interesting:


Page thumbnail, Vic Viper Mk1, curtsey of pasukaru76 (busy with portal 2)

The Discussion

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.