15534713 |
1 | Direct3D CSharp sample {#samples_csharp_direct3d} |
2 | ================== |
3 | |
f3fb84ce |
4 | This sample demonstrates how to use OCCT and DirectX libraries in <b>.Net</b> application |
5 | written using **CSharp** and **Windows Presentation Foundation** (WPF). |
15534713 |
6 | |
f3fb84ce |
7 | The connection between .Net, OCCT (C++) and DirectX level is provided by proxy libraries, |
8 | **OCCProxy** and **D3DProxy**, written in C++/CLI. The proxy library **OCCProxy** contains a single |
9 | *ref* class encapsulating OCCT viewer and providing the functionality to manipulate this viewer |
10 | and to import / export OCCT shapes from / to several supported CAD file formats (IGES, STEP, |
11 | BREP). The proxy library **D3DProxy** contains helper methods for rendering via DirectX. |
15534713 |
12 | |
f3fb84ce |
13 | The user interface in this sample is based on Windows Presentation Foundation (WPF). |
14 | It has the same functionality as the standard OCCT Import/Export sample. The project is |
15 | called *IE_WPF_D3D*. |
15534713 |
16 | |
17 | Note a few important details: |
18 | |
19 | - to build this sample you should to download and install DirectX SDK |
20 | http://www.microsoft.com/en-us/download/details.aspx?id=6812 |
21 | |
f3fb84ce |
22 | - OCCT template class *NCollection_Haft* is used to encapsulate C++ class into a field of *ref* class; |
15534713 |
23 | |
f3fb84ce |
24 | - It is necessary to explicitly set the target platform for C# assemblies to *x86* |
25 | in project **Properties - Build** to work consistently on 64-bit systems with OCCT libraries built in 32-bit mode; |
15534713 |
26 | |
f3fb84ce |
27 | - this sample demonstrates indirect method of wrapping C++ to C# using a manually |
28 | created proxy library. There is an alternative method of wrapping individual |
29 | OCCT classes to C# equivalents to make their full API available to a C# user |
30 | and to let the code be programmed on C# level similarly to C++ one. See the description |
31 | of **OCCT C# Wrapper** in **Advanced Samples and Tools** at |
15534713 |
32 | http://www.opencascade.org/support/products/advsamples |
33 | |
f3fb84ce |
34 | - in WPF sample, **WinForms** control is used to encapsulate OCC viewer since WPF |
35 | does not provide the necessary interface to embed OpenGl view. Other possible |
36 | solution could be to render OpenGl scene in an off-screen buffer and to map it |
37 | to WPF control as an image. That approach would allow using all WPF features to |
38 | control the OCCT viewer. |
15534713 |
39 | |
f3fb84ce |
40 | Run *msvc.bat* to start MS Visual Studio for building the sample. |
15534713 |
41 | Note that project files are provided only for VS 2010, you can open them in |
f3fb84ce |
42 | newer versions of Visual Studio using an automatic converter. |
15534713 |
43 | |
f3fb84ce |
44 | After conversion check option **Target framework** in the properties of C# projects |
45 | (tab **Application**) to make sure that it corresponds to the version set in |
46 | the properties of C++ projects (e.g. <b>.Net Framework 4.0</b> for VS 2010). |
15534713 |
47 | |
f3fb84ce |
48 | Run *run_wpf-D3D.bat* to launch the corresponding sample. |
49 | |
50 | Note that all batch scripts use the configuration defined in OCCT *custom.bat* file |
15534713 |
51 | as default; you can provide arguments specifying VS version, bitness, and mode |
52 | to override these settings, e.g.: |
53 | |
f3fb84ce |
54 | > msvc.bat vc10 win64 Debug |