Я хочу разместить wpf-canvas в классе формы windows для отображения 3d-quader. поэтому у меня есть следующий класс в проекте формы windows:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ElementHost eh = new ElementHost();
eh.Dock = DockStyle.Fill;
wpf.Canvas cv = new wpf.Canvas();
//wpf.DockPanel dp = new wpf.DockPanel();
cv.Background = wpfpaint.Brushes.Green;
eh.Child = cv;
this.Controls.Add(eh);
Line myLine = new Line();
myLine.X1 = 1;
myLine.X2 = 50;
myLine.Y1 = 1;
myLine.Y2 = 50;
myLine.Stroke = wpfpaint.Brushes.Black;
myLine.StrokeThickness = 2;
cv.Children.Add(myLine);
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);
// Kamera definieren
Point3D position = new Point3D(1.5, 2, 3);
Vector3D lookDirection = new Vector3D(-position.X, -position.Y, -position.Z);
Vector3D upDirection = new Vector3D(0, 1, 0);
double fieldOfView = 60;
PerspectiveCamera camera = new PerspectiveCamera(position, lookDirection, upDirection, fieldOfView);
vp3d.Camera = camera;
// Licht definieren
group3d.Children.Add(new AmbientLight(wpfpaint.Colors.Gray));
Vector3D direction = new Vector3D(1, -2, -3);
group3d.Children.Add(new DirectionalLight(wpfpaint.Colors.Gray, direction));
// Modell definieren
MeshGeometry3D mesh = new MeshGeometry3D();
Point3D[] points =
{
new Point3D(-1, -1, -1), new Point3D(1, -1, -1),
new Point3D(1, -1, 1), new Point3D(-1, -1, 1),
new Point3D(-1, -1, 1), new Point3D(1, -1, 1),
new Point3D(1, 1, 1), new Point3D(-1, 1, 1),
new Point3D(1, -1, 1), new Point3D(1, -1, -1),
new Point3D(1, 1, -1), new Point3D(1, 1, 1),
new Point3D(1, 1, 1), new Point3D(1, 1, -1),
new Point3D(-1, 1, -1), new Point3D(-1, 1, 1),
new Point3D(-1, -1, 1), new Point3D(-1, 1, 1),
new Point3D(-1, 1, -1), new Point3D(-1, -1, -1),
new Point3D(-1, -1, -1), new Point3D(-1, 1, -1),
new Point3D(1, 1, -1), new Point3D(1, -1, -1),
};
foreach (Point3D point in points) mesh.Positions.Add(point);
Tuple<int, int, int>[] triangles =
{
new Tuple<int, int, int>(0, 1, 2),
new Tuple<int, int, int>(2, 3, 0),
new Tuple<int, int, int>(4, 5, 6),
new Tuple<int, int, int>(6, 7, 4),
new Tuple<int, int, int>(8, 9, 10),
new Tuple<int, int, int>(10, 11, 8),
new Tuple<int, int, int>(12, 13, 14),
new Tuple<int, int, int>(14, 15, 12),
new Tuple<int, int, int>(16, 17, 18),
new Tuple<int, int, int>(18, 19, 16),
new Tuple<int, int, int>(20, 21, 22),
new Tuple<int, int, int>(22, 23, 20),
};
foreach (Tuple<int,int,int> tuple in triangles)
{
mesh.TriangleIndices.Add(tuple.Item1);
mesh.TriangleIndices.Add(tuple.Item2);
mesh.TriangleIndices.Add(tuple.Item3);
}
// Objektmaterial definieren
DiffuseMaterial material = new DiffuseMaterial(wpfpaint.Brushes.LightBlue);
// Modell creieren
GeometryModel3D model = new GeometryModel3D(mesh, material);
// Modell der Geometriegruppe zuweisen
group3d.Children.Add(model);
cv.Children.Add(vp3d);
}
}
Мой вопрос: почему отображается 2-я линия, а не квадер? если я реализую это в аналогичном wpf-проекте и wpf-окне, он показывает Quader.
Может ли кто-нибудь помочь?
с наилучшими пожеланиями
Volkhard