private void ChangeLineMaterial(BaseLineVisual3D visual3D, Ab3d.DirectX.Materials.ILineMaterial newDXMaterial) { // First get the DXEngine's SceneNode that was created from WPF's Visual3D var sceneNode = GetSceneNodeForWpfObject(visual3D); // Otherwise we need to get the ScreenSpaceLineNode. var screenSpaceLineNode = sceneNode as ScreenSpaceLineNode; if (screenSpaceLineNode == null) { // ScreenSpaceLineNode is usually created as a child node of a WpfModelVisual3DNode: // WpfModelVisual3DNode is created for LineArcVisual3D (because it is derived from BaseLineVisual3D and that is derived from ModelVisual3D) if (sceneNode != null && sceneNode.ChildNodesCount == 1) { screenSpaceLineNode = sceneNode.ChildNodes[0] as ScreenSpaceLineNode; } } if (screenSpaceLineNode != null) { // Once we have the ScreenSpaceLineNode, we can get the used LineMaterial that has ReadZBuffer screenSpaceLineNode.LineMaterial = newDXMaterial; // IMPORTANT: // When we manually change the properties of materials or SceneNodes, // we also need to notify the changed SceneNode about the change. // Without this the DXEngine will not re-render the scene because it will think that there is no change. screenSpaceLineNode.NotifySceneNodeChange(SceneNode.SceneNodeDirtyFlags.MaterialChanged); } }
private void Show3DLines(BaseLineVisual3D lineVisual3D) { // To better view how 3D line is created from triangles, // we adjust the camera to direct front view Camera1.Heading = 0; Camera1.Attitude = 0; Camera1.Distance = 500; Camera1.Offset = new Vector3D(0, 0, 0); Camera1.Refresh(); // This sample is a detailed inspector for MeshGeometry3D objects. // To show MeshGeometry3D from 3D lines, we need to do a little trick: // 1) We need to create a new Viewport3D, sets its size (very important because the Viewport3D will not be shown and size is needed to get PerspectiveMatrix) // 2) In the new Viewport3D set the camera to the same camera as out main camera. // 3) Add line to Viewport3D. // 4) Force line geometry generation with Ab3d.Utilities.LinesUpdater (register Viewport3D and then call Refresh). // 5) After that we can access the MeshGeometry3D for the 3D line. var mainViewportCamera = (PerspectiveCamera)MainViewport.Camera; var perspectiveCamera = new PerspectiveCamera() { LookDirection = mainViewportCamera.LookDirection, Position = mainViewportCamera.Position, UpDirection = mainViewportCamera.UpDirection, FieldOfView = mainViewportCamera.FieldOfView }; var viewport3D = new Viewport3D(); viewport3D.Camera = perspectiveCamera; viewport3D.Width = MainViewport.ActualWidth; viewport3D.Height = MainViewport.ActualHeight; viewport3D.Children.Add(lineVisual3D); //var geometryModel3D = line.Content as GeometryModel3D; var geometryModel3D = lineVisual3D.Content as GeometryModel3D; if (geometryModel3D != null) { _rootMesh = (MeshGeometry3D)geometryModel3D.Geometry; } }
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); }