Hello,
i do have following Code on a winform:
- using System;
- using System.Windows.Forms;
- using System.Windows.Forms.Integration;
-
- using wpf = System.Windows.Controls;
- using wpfpaint = System.Windows.Media;
- using System.Windows.Media.Media3D;
-
- namespace WindowsForms_WPF_3
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
-
- FormBorderStyle = FormBorderStyle.Fixed3D;
-
-
-
- ElementHost eh = new ElementHost();
- eh.Dock = DockStyle.Fill;
- this.Controls.Add(eh);
-
-
-
-
- wpf.DockPanel dp = new wpf.DockPanel();
- dp.Background = wpfpaint.Brushes.LightGray;
- eh.Child = dp;
-
-
-
-
- wpf.Viewport3D vp3d = new wpf.Viewport3D();
-
-
-
-
- wpfpaint.Media3D.ModelVisual3D visual3d = new wpfpaint.Media3D.ModelVisual3D();
- wpfpaint.Media3D.Model3DGroup group3d = new wpfpaint.Media3D.Model3DGroup();
-
- visual3d.Content = group3d;
- vp3d.Children.Add(visual3d);
-
-
-
-
- Point3D position = new Point3D(1, -1, 15);
- Vector3D lookDirection = new Vector3D(1, 1, 0);
- Vector3D upDirection = new Vector3D(0, 1, 0);
- double fieldOfView = 45;
- PerspectiveCamera camera = new PerspectiveCamera(position, lookDirection, upDirection, fieldOfView);
-
- vp3d.Camera = camera;
-
-
-
- group3d.Children.Add(new AmbientLight(wpfpaint.Colors.LightGreen));
- Vector3D direction = new Vector3D(1, -2, -3);
- group3d.Children.Add(new DirectionalLight(wpfpaint.Colors.LightSalmon, direction));
-
-
-
- MeshGeometry3D mesh = new MeshGeometry3D();
- Point3D[] points =
- {
- new Point3D(1, 1, 0), new Point3D(5, 1, 0), new Point3D(2.5, 5, 0)
- };
-
- foreach (Point3D point in points) mesh.Positions.Add(point);
-
- Tuple<int, int, int>[] triangles =
- {
- new Tuple<int, int, int>(0, 1, 2)
- };
-
- foreach (Tuple<int, int, int> tuple in triangles)
- {
- mesh.TriangleIndices.Add(tuple.Item1);
- mesh.TriangleIndices.Add(tuple.Item2);
- mesh.TriangleIndices.Add(tuple.Item3);
- }
-
-
-
- DiffuseMaterial material = new DiffuseMaterial(wpfpaint.Brushes.LightBlue);
-
-
-
- GeometryModel3D model = new GeometryModel3D(mesh, material);
-
-
-
-
- group3d.Children.Add(model);
-
-
-
- dp.Children.Add(vp3d);
-
- }
- }
- }
I expect that it Shows a cube but it doesn´t - When i do the simular thing within an wpf-program it works.
So i do have some Questions:
1) It is possible to use ElementHost to draw 3Ds in this way?
2) what is the failure in the Code above?
3) Is there the same ccordinate-System?
best regards
Volkhard