private void AddAxisLines() { double zPos = -0.5; // Move axis slightly away from camera so other lines will be always on top of axis var axisRootVisual3D = new ContentVisual3D(); var xAxisLineVisual3D = new LineVisual3D() { StartPosition = new Point3D(0, 0, zPos), EndPosition = new Point3D(100, 0, zPos), LineColor = Colors.Red, EndLineCap = LineCap.ArrowAnchor }; axisRootVisual3D.Children.Add(xAxisLineVisual3D); var yAxisLineVisual3D = new LineVisual3D() { StartPosition = new Point3D(0, 0, zPos), EndPosition = new Point3D(0, 100, zPos), LineColor = Colors.Green, EndLineCap = LineCap.ArrowAnchor }; axisRootVisual3D.Children.Add(yAxisLineVisual3D); var xTextBlockVisual3D = new TextBlockVisual3D() { Text = "X", Position = new Point3D(110, 0, zPos), PositionType = PositionTypes.Center, Size = new Size(10, 10), TextDirection = new Vector3D(1, 0, 0), UpDirection = new Vector3D(0, 1, 0), Foreground = Brushes.Red, FontWeight = FontWeights.Bold }; axisRootVisual3D.Children.Add(xTextBlockVisual3D); var yTextBlockVisual3D = new TextBlockVisual3D() { Text = "Y", Position = new Point3D(0, 110, zPos), PositionType = PositionTypes.Center, Size = new Size(10, 10), TextDirection = new Vector3D(1, 0, 0), UpDirection = new Vector3D(0, 1, 0), Foreground = Brushes.Green, FontWeight = FontWeights.Bold }; axisRootVisual3D.Children.Add(yTextBlockVisual3D); MainViewport.Children.Add(axisRootVisual3D); }
private void AddContentVisual3DObjects() { var rootContentVisual3D = new ContentVisual3D(); rootContentVisual3D.Transform = new TranslateTransform3D(-200, 0, 0); rootContentVisual3D.SetName("Root_ContentVisual3D"); MainViewport.Children.Add(rootContentVisual3D); var bottomContentVisual3D = new ContentVisual3D(); bottomContentVisual3D.SetName("Bottom_ContentVisual3D"); var bottomBox3D = new BoxVisual3D() { CenterPosition = new Point3D(0, 0, 0), Size = new Size3D(200, 20, 120), Material = new DiffuseMaterial(Brushes.Green) }; bottomContentVisual3D.Children.Add(bottomBox3D); // You can add child Visual3D objects to ContentVisual3D rootContentVisual3D.Children.Add(bottomContentVisual3D); var left1ContentVisual3D = new ContentVisual3D(); left1ContentVisual3D.SetName("Left_1_ContentVisual3D"); var left1Box3D = new BoxVisual3D() { CenterPosition = new Point3D(-50, 50, 0), Size = new Size3D(80, 60, 100), Material = new DiffuseMaterial(Brushes.LimeGreen) }; left1ContentVisual3D.Children.Add(left1Box3D); var right1ContentVisual3D = new ContentVisual3D(); right1ContentVisual3D.SetName("Right_1_ContentVisual3D"); var right1Box3D = new BoxVisual3D() { CenterPosition = new Point3D(50, 40, 0), Size = new Size3D(80, 20, 100), Material = new DiffuseMaterial(Brushes.LimeGreen) }; right1ContentVisual3D.Children.Add(right1Box3D); bottomContentVisual3D.Children.Add(left1ContentVisual3D); bottomContentVisual3D.Children.Add(right1ContentVisual3D); var right21ContentVisual3D = new ContentVisual3D(); right21ContentVisual3D.SetName("Right_2_1_ContentVisual3D"); var right2_1Box3D = new BoxVisual3D() { CenterPosition = new Point3D(30, 70, 0), Size = new Size3D(30, 20, 80), Material = new DiffuseMaterial(Brushes.PaleGreen) }; right21ContentVisual3D.Children.Add(right2_1Box3D); var right22ContentVisual3D = new ContentVisual3D(); right22ContentVisual3D.SetName("Right_2_2_ContentVisual3D"); // With ContentVisual3D we can also show Model3D (GeometryModel3D or Model3DGroup) objects. // To do that we set it to ContentVisual3D.Content property or specify it in the constructor. var right2_2Model3D = Ab3d.Models.Model3DFactory.CreateBox(new Point3D(70, 70, 0), new Size3D(30, 20, 80), new DiffuseMaterial(Brushes.PaleGreen)); right22ContentVisual3D.Content = right2_2Model3D; right1ContentVisual3D.Children.Add(right21ContentVisual3D); right1ContentVisual3D.Children.Add(right22ContentVisual3D); Ab3d.Utilities.ModelIterator.IterateModelVisualsObjects(rootContentVisual3D.Children, null, delegate(ModelVisual3D visual3D, Transform3D transform3D) { CreateIsVisibleCheckBoxes(visual3D, ContentVisualStackPanel); }); }
private ContentVisual3D CreateWireGridLines(Point3D centerPosition, Size size, int widthCellsCount, int heightCellsCount, Vector3D widthDirection, Vector3D heightDirection, Color linesColor, double linesThickness) { var contentVisual3D = new ContentVisual3D(); Point3D onePosition; double width = size.Width; Vector3D widthVector = new Vector3D(width * widthDirection.X, width * widthDirection.Y, width * widthDirection.Z); double height = size.Height; Vector3D heightVector = new Vector3D(height * heightDirection.X, height * heightDirection.Y, height * heightDirection.Z); var startPosition = centerPosition - (widthVector + heightVector) * 0.5; double oneStepFactor = 1.0 / widthCellsCount; for (int x = 1; x < widthCellsCount; x++) { onePosition = startPosition + x * oneStepFactor * widthVector; var lineVisual3D = new LineVisual3D() { StartPosition = onePosition, EndPosition = onePosition + heightVector, LineColor = linesColor, LineThickness = linesThickness }; contentVisual3D.Children.Add(lineVisual3D); } oneStepFactor = 1.0 / heightCellsCount; for (int y = 1; y < heightCellsCount; y++) { onePosition = startPosition + y * oneStepFactor * heightVector; var lineVisual3D = new LineVisual3D() { StartPosition = onePosition, EndPosition = onePosition + widthVector, LineColor = linesColor, LineThickness = linesThickness }; contentVisual3D.Children.Add(lineVisual3D); } return(contentVisual3D); }