(YASL53DP) Supercharging Silverlight 5 3D projects with the Babylon Toolkit
- Posted: Jun 06, 2011 at 6:00 AM
- 6,980 Views
- 6 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
(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)
return;
DateTime start = DateTime.Now;
// States
statesManager.DepthBufferEnable = true;
statesManager.CullMode = CullMode.None;
statesManager.ApplyDepthStencilState();
statesManager.ApplyRasterizerState();
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;
}
}
model.Draw();
camera.ApplyInertia();
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);
});
e.InvalidateSurface();
}
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;
drawingSurface.Invalidate();
};
// 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)
return;
camera.InertialAlpha += (float)(currentPosition.X - startPosition.X) * camera.AngularSpeed;
camera.InertialBeta -= (float)(currentPosition.Y - startPosition.Y) * camera.AngularSpeed;
startPosition = currentPosition;
break;
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... ![]()
Here’s a few more links you might find interesting:
Page thumbnail, Vic Viper Mk1, curtsey of pasukaru76 (busy with portal 2)
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Great , If this Sort Of things More Advance In future many Of Problems For many Applications Will solve , Keep It Coming
Looks interesting, I will definitely play around with this. Thanks.
make me , more interest in all you that show me, move me.
Happy to discover that you like it :D
v1.0.4 is published. New version (1.0.5) is coming with scene and animations support :)
Nice job , keep up the good work.
Very nice,
Documentation would be nice and some simple examples
How to use a Model, Model mesh, Scene...
How to add a simple box and move around it.
Remove this comment
Remove this thread
close