private void CreateBoxWithEdgeLines(Point3D centerPosition, Size3D size, DiffuseMaterial material) { var boxVisual3D = new BoxVisual3D() { CenterPosition = centerPosition, Size = size, Material = material }; TestObjectsModelVisual3D.Children.Add(boxVisual3D); var wireBoxVisual3D = new WireBoxVisual3D() { CenterPosition = centerPosition, Size = size, LineColor = Colors.Yellow, LineThickness = 3 }; // Set LineDepthBias to prevent rendering wireframe at the same depth as the 3D objects. // This creates much nicer 3D lines. See the LineDepthBiasSample for more information. wireBoxVisual3D.SetDXAttribute(DXAttributeType.LineDepthBias, 0.1); TestObjectsModelVisual3D.Children.Add(wireBoxVisual3D); }
private void EnsureWireBox() { if (_wireBoxVisual3D == null) { _wireBoxVisual3D = new WireBoxVisual3D(); this.Children.Add(_wireBoxVisual3D); } }
public override void ShowRotationAdorner(Point rotationCenterPosition) { if (Viewport3D != null) { // In this sample we show WireBoxVisual3D around selected box (when there is a box selected) if (SelectedBoxVisual3D != null) { _wireBoxVisual3D = new WireBoxVisual3D() { LineColor = Colors.Red, LineThickness = 3, CenterPosition = SelectedBoxVisual3D.CenterPosition, Size = SelectedBoxVisual3D.Size }; Viewport3D.Children.Add(_wireBoxVisual3D); return; } // If no box is selected, we show WireCrossVisual3D at the RotationCenterPosition (if set) // When MouseCameraController.RotateAroundMousePosition is set to true, // MouseCameraController calculates the RotationCenterPosition with hit testing current mouse position on the 3D scene. var targetPositionCamera = TargetCamera as TargetPositionCamera; if (targetPositionCamera != null && targetPositionCamera.RotationCenterPosition != null) { _wireCrossVisual3D = new WireCrossVisual3D() { LineColor = Colors.Red, LineThickness = 3, LinesLength = 30, Position = targetPositionCamera.RotationCenterPosition.Value }; Viewport3D.Children.Add(_wireCrossVisual3D); return; } } // If we came here then Viewport3D and SelectedBoxVisual3D are not set or there is no 3D object behind the mouse position (RotationCenterPosition is null) // In this case we show standard rotation marker base.ShowRotationAdorner(rotationCenterPosition); }
private BaseLineVisual3D CloneLineVisuals(BaseLineVisual3D lineVisual) { BaseLineVisual3D clonedLineVisual = null; // NOTE: // This method supports only cloning LineArcVisual3D and WireBoxVisual3D var lineArcVisual3D = lineVisual as LineArcVisual3D; if (lineArcVisual3D != null) { clonedLineVisual = new LineArcVisual3D() { CircleCenterPosition = lineArcVisual3D.CircleCenterPosition, Radius = lineArcVisual3D.Radius, CircleNormal = lineArcVisual3D.CircleNormal, ZeroAngleDirection = lineArcVisual3D.ZeroAngleDirection, StartAngle = lineArcVisual3D.StartAngle, EndAngle = lineArcVisual3D.EndAngle, LineColor = lineArcVisual3D.LineColor, LineThickness = lineArcVisual3D.LineThickness }; } else { var wireBoxVisual3D = lineVisual as WireBoxVisual3D; if (wireBoxVisual3D != null) { clonedLineVisual = new WireBoxVisual3D() { CenterPosition = wireBoxVisual3D.CenterPosition, Size = wireBoxVisual3D.Size, LineColor = wireBoxVisual3D.LineColor, LineThickness = wireBoxVisual3D.LineThickness }; } } return(clonedLineVisual); }
public override void HideRotationAdorner() { if (Viewport3D != null) { if (_wireBoxVisual3D != null) { Viewport3D.Children.Remove(_wireBoxVisual3D); _wireBoxVisual3D = null; return; } if (_wireCrossVisual3D != null) { Viewport3D.Children.Remove(_wireCrossVisual3D); _wireCrossVisual3D = null; return; } } base.HideRotationAdorner(); }
private void AddModel(Model3D originalModel3D, Point3D position, PositionTypes positionType, Size3D size, bool preserveAspectRatio = true) { // Create a new Model3DGroup that will hold the originalModel3D. // This allows us to have different transformation for each originalModel3D (transformation is on Model3DGroup) var model3DGroup = new Model3DGroup(); model3DGroup.Children.Add(originalModel3D); Ab3d.Utilities.ModelUtils.PositionAndScaleModel3D(model3DGroup, position, positionType, size, preserveAspectRatio); // Add the model var modelVisual3D = new ModelVisual3D() { Content = model3DGroup }; SolidObjectsVisual3D.Children.Add(modelVisual3D); // Now add red WireCrossVisual3D at the specified position var wireCrossVisual3D = new Ab3d.Visuals.WireCrossVisual3D() { Position = position, LinesLength = 30, LineColor = Colors.Red }; SolidObjectsVisual3D.Children.Add(wireCrossVisual3D); // Now show a WireBoxVisual3D (box from 3D lines) that would represent the position, positionType and size. // To get the correct CenterPosition of the WireBoxVisual3D, // we start with creating a bounding box (Rect3D) that would be used when CenterPosition would be set to (0, 0, 0): var wireboxInitialBounds = new Point3D(-size.X * 0.5, -size.Y * 0.5, -size.Z * 0.5); // Then we use that bounding box and call GetModelTranslationVector3D method // that will tell us how much we need to move the bounding box so that it will be positioned at position and for positionType: var wireboxCenterOffset = Ab3d.Utilities.ModelUtils.GetModelTranslationVector3D(new Rect3D(wireboxInitialBounds, size), position, positionType); // Now we can use the result wireboxCenterOffset as a CenterPosition or a WireBoxVisual3D var wireBoxVisual3D = new WireBoxVisual3D() { CenterPosition = new Point3D(wireboxCenterOffset.X, wireboxCenterOffset.Y, wireboxCenterOffset.Z), Size = size, LineColor = Colors.Green, LineThickness = 1 }; SolidObjectsVisual3D.Children.Add(wireBoxVisual3D); // Finally we add TextBlockVisual3D to show position and size information for this model // Note that the TextBlockVisual3D is added to the TransparentObjectsVisual3D. // The reason for this is that TextBlockVisual3D uses semi-transparent background. // To correctly show other object through semi-transparent, the semi-transparent must be added to the scene after solid objects. var infoText = string.Format("Position: {0:0}\r\nPositionType: {1}\r\nSize: {2:0}", position, positionType, size); if (!preserveAspectRatio) { infoText += "\r\npreserveAspectRatio: false"; } var textBlockVisual3D = new TextBlockVisual3D() { Position = new Point3D(model3DGroup.Bounds.GetCenterPosition().X, -15, 55), // Show so that X center position is the same as model center position PositionType = PositionTypes.Center, TextDirection = new Vector3D(1, 0, 0), UpDirection = new Vector3D(0, 1, -1), // angled at 45 degrees Size = new Size(80, 0), // y size will be calculated automatically based on x size (80) and size of the text Text = infoText, BorderBrush = Brushes.DimGray, BorderThickness = new Thickness(1, 1, 1, 1), Background = new SolidColorBrush(Color.FromArgb(180, 200, 200, 200)), TextPadding = new Thickness(5, 2, 5, 2) }; TransparentObjectsVisual3D.Children.Add(textBlockVisual3D); }