Original: WPF--3DMAX+BLEND+WPF Comprehensive application
Citation: http://blog.sina.com.cn/s/blog_95dbdf9e0100we3z.html
I have a side dish, WPF just getting started, just write a recent project experience. Welcome the predecessors to come to make the bricks, appreciate the disrespect! First of all, I started hurriedly, a lot of things are also smattering, so many problems even superficial understanding, so the great gods directly detour.
Summary one: 3D MAX+BLEND+WPF Comprehensive Application
Development environment:
Autodesk 3DS Max Design 2012
Micosoft Expression Blend 4,
Microsoft Visual Studio 2010
Younger brother before a project, you have to use WPF3D programming, but WPF 3D only the most basic 3D scene elements, such as cameras, lighting and so on. If you want to draw a cube or a sphere in WPF, you have to figure out the coordinates of each grid point in one step, add the vertex order of the triangular mesh, set the normal vector, and assign the corresponding vertex coordinates to the map. Drawing a simple model is so troublesome that a slightly more complex model can only rely on third-party modeling software to build the model, then convert the model into a loose XAML file to import into WPF, or embed the corresponding XAML code of the model directly into the program.
工欲善其事 its prerequisite, here are the relevant tools and examples I found, some of which I didn't use:
1.3D Max Studio has a plugin for exporting XAML: http://max2xaml.codeplex.com/
2. There are also open source blender:http://www.blender.org/and the corresponding plugins for exporting XAML:
http://xamlexporter.codeplex.com/
3. There is also viewer3ds-3ds to XAML converter:http://www.wpf-graphics.com/viewer3ds.aspx
4. WPF (C #) has a specialized 3D modeling tool, which is similar in use to 3DMax, and can be exported directly after making the XAML language easily and quickly: ZAM 3d:http://www.erain.com/products/zam3d/defaultpdc.asp
Example:
1.WPF 3D model loaded in obj format: http://www.pin5i.com/showtopic-26486.html
2.3DS Max modeling, blend design, VS2008 control for WPF 3D model examples
Http://www.cnblogs.com/foundation/archive/2008/05/23/1205892.html
Http://www.cnblogs.com/couhujia/archive/2010/07/28/1787103.html
Http://zhouwenqi.com/blog/board_33.html
Now online can be downloaded to a lot of fancy 3D models, models have many formats, we chose this time. Max format, because many models on the web (especially the game character prototypes) are. Max format, and most of the other formats can be opened in 3Dmax, and then saved in. max format.
Younger brother's 3Dmax door are immersed, the project to do half want to find a set of girlfriend to help me to build a model to do art, but under, to the library speed borrowed 2 3Dmax book, need to chew two, so only mastered the most basic model import, export and modify the composition of the function.
The following is an example of a game character prototype (a warrior in the fairy), this prototype is downloaded on the Internet, the specific URL is I forgot. After opening the model in 3Dmax, you can modify, dismember, or fit as you wish.
Reminder: When you open a model when the file Unit scale and System unit scale do not match, the following dialog box will pop up to let you choose. Choose whichever is not the matter, according to their own needs to choose it! However, if the ratio of the two is too large, such as the following system unit ratio is 1 units =1cm, and the file unit ratio is 1 units =1m, if the system unit is open, the model may be too large in the 3dmax view, can not be displayed in the 3Dmax view or only show the parts of the model, At this point, select the lower right corner of the button () to maximize the display of the selected object.
Choose the Save as type obj format, then name the file Man1, then click Save, there will be the following "Obj Export Options" dialog box:
The simple obj format is not with the map, want to export the map together, tick the material option "Export material" "Create Material Library", and click the "Material Export" button, will pop up "OBJ map-export Options" dialog box, where you can choose the format and size of the picture saved. Then select "Export", OBJ,MTL and the corresponding map picture file will be in the Export folder 3dmax, map information stored in the. MTL, the specific map is stored in the Maps folder.
Reminder: If there is a "missing map" dialog box on export, the "Manual Search Path", if skipped, will only have the MTL and obj files, and there will be no specific mapping files. The search path is typically the path where the original model is located, because. DDS-formatted files are typically combined with the. Max model files.
Then open blend 4, create a new project->WPF application, and click OK.
Select "Project", "Add Existing Item", the following dialog box appears, add MAN1.MTL and man1.obj two files to the project. In this case, double-clicking the man1.obj file will load the model without the map into the current project. Drag the lower right corner of the square border to control the size of the model, in general, you can see the model without a map, mostly bare drab gray white.
But why can't I see anything here? Take a closer look, and blend is actually loaded into the model (e.g.):
It's just that I have a slightly special case, not a visible one, because the "texture brush" or "diffuse color" of the diffuse material is set to transparent. You can see the model with a little modification, for example, the "Texture brush" and "diffuse color" of the "diffuse material" of the pants model is set to 100%, that is, the monotone gray model can be seen by opaque.
But such models certainly do not have beautiful stickers, only monotonous colors, so we need to load the corresponding map ourselves. I was depressed, because Blend4 's user guide said "When importing a three-dimensional object (. obj file), it is important to import any associated material files (. mtl) and all the image files used in the material file. If you lose any image files, you will not be able to add these files later. " So it seems that I did not import the picture file, so immediately "add existing Items", the four map files loaded into the project, still do not see the model with the map, here depressed long, can not find a solution to the method, have to manually load the map for each model. This is actually a way, the shortcut was found later, will be introduced. For example, to add texture images to the head, the effect is as follows:
After all the additions are complete, run the program as follows:
You can also make basic adjustments to the model in blend, such as scaling, rotating, panning, and so on.
However, there are still shortcomings and there are still problems with the decal details. For example, the back of the model in blend and the back of the 3Dmax model are the following: estimated because the mapping coordinates do not correspond to the resulting, with 3Dmax exported pictures directly in the blend, not to achieve the original effect. Or we can't do it at the moment, maybe the great gods can do it. These should belong to the art side. Hey.
You can then use VS2010 to open the WPF project created in Blend4, you can continue to add the corresponding interactive interface and control buttons in VS2010, here do not nag, you chew the book go!
Continue to tangle in the user Guide, "When importing a three-dimensional object (. obj file), it is important to import any associated material files (. mtl) and all the image files used in the material file. If you lose any image files, you will not be able to add these files later "the meaning of this sentence, I guess is the map path problem, the map information is exported by the 3Dmax, and the existence of the MTL format file, and then open the MTL file, only to find the map file before there is an maps file path (below), sure enough.
So hurriedly create a new maps folder in the project, then load the map into this folder, and then double-click the obj file, then blend will automatically help us map. But defects still exist, and the shortcomings of the previous mentioned as a touch, the back of the stickers and manual paste the effect of the same, the effect and the original 3Dmax model there are some differences, this is beyond the IT code farming category, to find an artist sister bar!
Summary two: WPF loading a loosely-loaded XAML model
Our project needs to load the 3Dmax model into WPF, mainly involving the storage, import, and control of the model.
The first is the problem of the storage of the model. Before you open the project with the 3Dmax model in blend, you will find that the corresponding XAML code for the model is embedded in the program. What if more than one model? It is not possible to put the XAML code corresponding to each model into the program, which is neither aesthetically pleasing nor conducive to the subsequent control of the model.
The XAML code of the model is then keyed out, put into TXT, and renamed in XAML format, which is a loose XAML model file.
The second is the import of the model. The model that is stored in the XAML file is imported into WPF, opened primarily through file stream FileStream, and then loaded with XamlReader and loaded into different types of variables depending on the model type. Generally loose XAML model types have geometrymodel3d,model3dgroup and so on, to see their own needs to convert.
public void Loadmodel (ref GeometryModel3D _model, String path)
{
if (path = null && file.exists (PATH))
{
using (FileStream file = file.openread (path))
{
_model = (GeometryModel3D) xamlreader.load (file);//
}
}
}
public void Loadmodel (ref model3dgroup _model, String path)
{
if (path = null && file.exists (PATH))
{
using (FileStream file = file.openread (path))
{
_model = (model3dgroup) xamlreader.load (file);
}
}
}
Finally, the model control, how to change the model posture in real-time based on the limb data provided in Kinect, we just cut the clothes into pieces and rigidly hang on the bone node, without considering all the physical effects, such as gravity, collision detection, bone skin and other effects. Because the 3D functionality of WPF is not so powerful, unless you have to rely on other game engines, or write them from the bottom, when time is tight, you can only blunt the model cut, and then put it on the block. The Kinect's bone data provides the XYZ space coordinate azimuth, so the angle and direction of the lines between the 2 bone points are easily calculated, and then the model is placed on the corresponding bone point by a series of translations, rotations, and indentation changes.
In order to achieve augmented reality, in the WPF interface, the Viewport3D and display the original video stream image control the size of a touch, the position is completely coincident. Then put the camera in the space coordinate system coordinates 0 points, so that the camera and the real space of the Kinect sensor position, the direction of the same. So, Viewport3D in the virtual effect can be covered in the bottom of the screen of the people, to achieve the effect of augmented reality. But there will be a small deviation from the Kinect skeleton data is not very accurate, so you also need to manually correct some of the details, so that the effect more realistic point.
Comprehensive application of WPF--3DMAX+BLEND+WPF