Loading and rendering a 3D model

First of all you'll need a ASE (3DSMAX ASCII Scene Export) file. The file must have only one 3D model in it and can have one material with the usage of diffuse map, which can be a texturemap. This limitation is for the 0.8 version of Balder. The texture must be a PNG file and be 32 bits per pixel (RGBA). These limitations are something we're working on getting out of the release 1.0 of Balder.

Implementing your game class

First in your newly created project, you'll need a game class that will serve as the entrypoint for your game, see the Getting Started section for more details, and for Silverlight specifics on how to initialize the engine look here.


Balder, much like Microsoft Xna, uses the term asset for content used in a game. Also, as in Xna, the default path of assets is a directory called assets, that should be located within the root of your game project. All assets should be marked as a Resource when adding it to the project in Visual Studio. Whenever you're loading assets, you do not need to specify the root directory in the path, as this will automatically be handled by the ContentManager.

Create a Assets folder (case is very important) and put your asset in the Assets folder.

In addition you'll need to modify the build action for the file. By right-clicking the file and selecting properties, a properties window should appear and you can set the build action to be Resource.

The reason you need to do this, is so that the asset will be part of the compiled and packaged game when you're building your solution. For Silverlight for instance, this means being part of the XAP file.


The Game class you have inherited from has several methods that can be overridden, amongst these methods is a method called LoadContent(). This method is called automatically during initialization of the engine. It is in this method you'll be placing your content loading.
You'll find a property called ContentManager inherited from the base Game class from Balder, you'll find a Load() method that takes a generic parameter and a path. In the generic parameter you specify the type of asset you are loading, in our case a Mesh, and the path is the filename of the asset minus the prefix of the asset directory.

public override void LoadContent()
    var mesh = ContentManager.Load<Mesh>("teapot.ase"); // Notice we're not prefixing the Assets path, as this is set by the ContentManager automatically


In your game class, that inherits from the Balders Game class, there is a protected property called Scene. Balder automatically creates a default scene for your game for you to add content to. All you need to do is take your loaded asset and add it to the scene and it will automatically get rendered.

After loading the asset, you can add it directly to the scene:
public override void LoadContent()
    var mesh = ContentManager.Load<Mesh>("teapot.ase"); // Notice we're not prefixing the Assets path, as this is set by the ContentManager automatically

You should now have a 3D model added to your scene and rendering should occur.


Your game class also comes with a camera. By now you might not be able to see something. This might be because the default position and target position of the camera are inside your 3D model you've just added to the scene. You can modify the camera by doing the following:
Camera.Position.X = 0;
Camera.Position.Y = 0;
Camera.Position.Z = -50;
Or the target position:
Camera.Target.X = 0;
Camera.Target.Y = -10;
Camera.Target.Z = 0;

You should try different values that corresponds to the object and its dimensions found in the 3D modelling software you exported the model from.

Adding lights

If you're using a model that does not have a texture for its diffuse material, you are probably not seeing much still. You'll need to add a light in order for the model to be visible. Balder supports one type of light at the moment; the omnilight. An omni-light is a light that has a position, color, strength but no direction or spot. Adding a light is very simple, during initialization you simply create an OmniLight (Balder.Core.Lighting namespace) and add it to the scene:
light = new OmniLight();
light.Range = 3.0f;
light.Position.X = 0;
light.Position.Y = 0;
light.Position.Z = -30;
light.ColorDiffuse = Color.FromArgb(0xff, 0x1f, 0x1f, 0x6f);
light.ColorSpecular = Color.FromArgb(0xff, 0xff, 0xff, 0xff);
light.ColorAmbient = Color.FromArgb(0xff, 0, 0x5f, 0);

Last edited Oct 15, 2009 at 6:52 PM by adept, version 5


adept Oct 29, 2010 at 7:27 AM 
For now, only .ase files are supported. But creating a FileLoader to support any format is pretty straight forward with Balder - if you know the format and want to put in the work creating the loader, that is.

autivrushali Oct 28, 2010 at 12:20 PM 
can we use .mb(Maya binary) file instead of .ase to render 3D models in balder?

adept Sep 1, 2009 at 8:13 PM 
Thanks for you input. Updated the "Getting started" section with the namespace. Oversight.

As for Expression Blend, we have not yet tested Balder with it. It is something that we should look into. Thanks for the input on that as well.

doncasteel8587 Aug 31, 2009 at 12:40 AM 
Importiant to note, if using Expression Blend 3 you can not yet (as of Aug 30, 2009) set the .ASE file to build as a Reference.
I was forced to setup VisualStudio 2008 for Silverlight 3.

Also I needed to set a "using" statement for using "Balder.Core.Lighting;" (using Balder.Core.Lighting;) to get the light to work.