private LineMaterial CreateLineMaterial(bool isPolyLine, Color lineColor) { var lineMaterial = new LineMaterial() { LineColor = lineColor.ToColor4(), LineThickness = 10, IsPolyLine = isPolyLine }; return(lineMaterial); }
private ScreenSpaceLineNode CreateLinesWithLineMesh(Vector3[] linePositions, bool isLineStrip, bool isLineClosed, Color lineColor, float xOffset, out ScreenSpaceLineMesh screenSpaceLineMesh) { if (linePositions == null || linePositions.Length < 2) { screenSpaceLineMesh = null; return(null); } // If line is closed but the first position is not the same as the last position, then add the first position as the last one if (isLineClosed && linePositions[0] != linePositions[linePositions.Length - 1]) { Array.Resize(ref linePositions, linePositions.Length + 1); linePositions[linePositions.Length - 1] = linePositions[0]; } // If we can easily calculate the bounding box from line positions // it is recommended to specify it in the ScreenSpaceLineMesh constructor. // If boundingBox is not specified, it will be calculated in the ScreenSpaceLineMesh constructor with checking all the positions. // // NOTE: If bounding box is not correct then camera's near and far planes can be invalid and this can cut some 3D objects at near or far plane (when DXScene.OptimizeNearAndFarCameraPlanes is true - by default) //var boundingBox = new BoundingBox(new Vector3(startX, 0, startZ), new Vector3(startX + linesCount * margin, 0, endZ)); // Create ScreenSpaceLineMesh - it is used to create DirectX vertex buffer from positions screenSpaceLineMesh = new ScreenSpaceLineMesh(linePositions, isLineStrip); // When the line positions are changed many times, it is recommended to set CreateDynamicVertexBuffer to true. screenSpaceLineMesh.CreateDynamicVertexBuffer = true; var lineMaterial = new LineMaterial() { LineColor = lineColor.ToColor4(), LineThickness = 2 }; var screenSpaceLineNode = new ScreenSpaceLineNode(screenSpaceLineMesh, lineMaterial); screenSpaceLineNode.Transform = new Transformation(SharpDX.Matrix.Translation(xOffset, 0, 0)); // To show ScreenSpaceLineNode in DXViewportView we need to put it inside a SceneNodeVisual3D var sceneNodeVisual3D = new SceneNodeVisual3D(screenSpaceLineNode); MainViewport.Children.Add(sceneNodeVisual3D); _disposables.Add(screenSpaceLineMesh); _disposables.Add(screenSpaceLineNode); _disposables.Add(lineMaterial); return(screenSpaceLineNode); }
private void ResetBurshes(RenderContainer renderContainer) { _selectedColorBrush?.Dispose(); _spacingColorBrush?.Dispose(); _notMappedColorBrush?.Dispose(); _gridColorBrush?.Dispose(); RenderTarget target2D = renderContainer.BackBuffer.Target2D; _selectedColorBrush = new SolidColorBrush(target2D, SelectedColor.ToColor4(), null); _spacingColorBrush = new SolidColorBrush(target2D, SpacingColor.ToColor4(), null); _notMappedColorBrush = new SolidColorBrush(target2D, NotMappedColor.ToColor4(), null); _gridColorBrush = new SolidColorBrush(target2D, GridColor.ToColor4(), null); }
private void AddLines(Point3D startPosition, int positionsCount, Color lineColor, bool readZBuffer = true, bool writeZBuffer = true, RenderingQueue customRenderingQueue = null) { Vector3[] positions = new Vector3[positionsCount * 2]; Vector3 position = startPosition.ToVector3(); int index = 0; for (int i = 0; i < positionsCount; i++) { positions[index] = position; positions[index + 1] = position + new Vector3(40, 0, 0); index += 2; position += new Vector3(0, 0, 10); } // ThickLineEffect that renders the 3D lines can use the ReadZBuffer and WriteZBuffer values from LineMaterial. // // When ReadZBuffer is false (true by default), then line is rendered without checking the depth buffer - // so it is always rendered even it is is behind some other 3D object and should not be visible from the camera). // // When WriteZBuffer is false (true by default), then when rendering the 3D line, the depth of the line is not // written to the depth buffer. So No other object will be made hidden by the line even if that object is behind the line. var lineMaterial = new LineMaterial() { LineColor = lineColor.ToColor4(), LineThickness = 2, ReadZBuffer = readZBuffer, WriteZBuffer = writeZBuffer }; _disposables.Add(lineMaterial); var screenSpaceLineNode = new ScreenSpaceLineNode(positions, isLineStrip: false, isLineClosed: false, lineMaterial: lineMaterial); // It is also needed that the 3D line is put to the Background or Overlay rendering queue so that it is rendered before or after other 3D objects. screenSpaceLineNode.CustomRenderingQueue = customRenderingQueue; var sceneNodeVisual3D = new SceneNodeVisual3D(screenSpaceLineNode); MainViewport.Children.Add(sceneNodeVisual3D); }
private ScreenSpaceLineNode CreateLinesWithPositions(Vector3[] linePositions, bool isLineStrip, bool isLineClosed, Color lineColor, float xOffset) { var lineMaterial = new LineMaterial() { LineColor = lineColor.ToColor4(), LineThickness = 2 }; var screenSpaceLineNode = new ScreenSpaceLineNode(linePositions, isLineStrip, isLineClosed, lineMaterial); screenSpaceLineNode.Transform = new Transformation(SharpDX.Matrix.Translation(xOffset, 0, 0)); // To show ScreenSpaceLineNode in DXViewportView we need to put it inside a SceneNodeVisual3D var sceneNodeVisual3D = new SceneNodeVisual3D(screenSpaceLineNode); MainViewport.Children.Add(sceneNodeVisual3D); _disposables.Add(screenSpaceLineNode); _disposables.Add(lineMaterial); return(screenSpaceLineNode); }
private void ChangeInstanceColor(int instanceIndex, System.Windows.Media.Color color) { if (_selectedInstanceIndex == -1) { return; } _instancedMeshGeometryVisual3D.InstancesData[instanceIndex].DiffuseColor = color.ToColor4(); _instancedMeshGeometryVisual3D.Update(instanceIndex, 1, updateBounds: false); }