Daily Tip: How to import 3D model to WPF from Blender
In resumption to my previous post “How to import 3D model to WPF from 3D Max” I want to present the “XAML exporter for Blender” (Blender is an open-source cross-platform 3D designer).
if(Blender.Name == Blend.Name)
{
Debug.WriteLine(“Wiiiiii !!!! :)”);
}
This post will guide you how to use this feature thru simple example.
Software requirements for this guide: Blender 2.48a or later, Microsoft Expression Blend 2.0 (Final Release).
SDK and Framework requirements: Microsoft .Net 3.0 or 3.5.
Let’s start:
(1) Download ZIP File from here and extract it into “[X]:\[*Blender*]\.blender\scripts” directory on your hard drive (to apply changes, you have to restart Blender, if you’ve copied file when it was open).
(2) Open/create scene with 3D objects in Blender. Select objects for exports and press on “File” menu.
(3) Go to “Export” sub-menu and click on “Xaml (.xaml)…”.
(4) Enter file path for export and press on “Export Xaml” button.
(5) Open created “xaml” file in any text editor (I prefer free “Notepad++”).
As we can see it contains 3D models under “Model3DGroup”, each model has definitions for “Geometry”, “*Material”, “*Back Material” and “*Transform” (* –> means that these are optional and depend on 3D object properties in Blender’s scene).
(6) Create/open WPF project in Blend.

(7) Add item “Resource Dictionary” to project-tree.
(8) Open created dictionary (XAML view), Copy-Paste XAML code from exported file into dictionary.
(9) The pasted “Model3DGroup” is an item in dictionary, all items must have Key-Name; add “x:Key=”modelGrp”” and remove “x:Name=”…”” tags from all nodes (dictionary cannot contain definitions with this tag). Save file and rebuild project [Ctrl]+[Shift]+[B].
(10) Open “Window1.xaml” in Blend editor (Design or Spitted view), go to “Resources” tab and links saved dictionary file to opened window (right-click on Window item to open context menu).
(11) Add 3D objects into main grid: “ViewPort3D” with “OrthographicCamera” + two 3D models (“ModelVisual3D”), one for “DirectionalLight” and another for our 3D objects from Blender (exported XAML contains “Model3DGroup” that can be used for 3D model content in WPF).
(12) Select 3D model object that was prepared to contain exported objects, go to “Properties” tab –> “Miscellaneous” –> “Content” and attach to local resource “modelGrp” (linked to dictionary).
After attachment we’ll see the result (maybe it will require some adjustments):
(13) Use object “Properties” tab to fix/adjust scene parameters/objects.
Many times we’ll prefer to adjust camera’s properties (it is much easier then changing/transforming 3D models). Also, we can “play” with light properties.
(14) Run [F5] project to see final result.
The example project with code can be downloaded from here
.
Summary: It is very easy to port 3D models from Blender into XAML, the “XAML exporter for Blender” is a plug-in (script file written in Python) that converts complex scene parameters (e.g.: mesh points, texture coordinates, etc) into readable XAML file, it isn’t perfect and has some minor bugs and hopefully will be fixed in future.
PS
I’m not responsible for any damage that may be caused by using this post or its content. Any materials in this post were provided AS IS without any changes and other meanings.