Class Viewport3DHelper
- Namespace
- HelixToolkit.Wpf
- Assembly
- HelixToolkit.Wpf.dll
Provides extension methods for Viewport3D.
public static class Viewport3DHelper
- Inheritance
-
Viewport3DHelper
- Inherited Members
Remarks
See "3D programming for Windows" (Charles Petzold book) and Twelve Days of WPF 3D.
Methods
Copy(Viewport3D, double, double, Brush, int)
Copies the specified viewport to the clipboard.
public static void Copy(this Viewport3D view, double width, double height, Brush background, int m = 1)
Parameters
viewViewport3DThe viewport.
widthdoubleThe width.
heightdoubleThe height.
backgroundBrushThe background.
mintThe oversampling multiplier.
Copy(Viewport3D, int)
Copies the specified viewport to the clipboard.
public static void Copy(this Viewport3D view, int m = 1)
Parameters
viewViewport3DThe viewport.
mintThe oversampling multiplier.
CopyXaml(Viewport3D)
Copies the viewport as
xaml to the clipboard.
public static void CopyXaml(this Viewport3D viewport)
Parameters
viewportViewport3DThe viewport.
Export(Viewport3D, string, Brush?)
Exports the specified viewport.
public static void Export(this Viewport3D viewport, string fileName, Brush? background = null)
Parameters
viewportViewport3DThe viewport.
fileNamestringName of the file.
backgroundBrushThe background brush.
ExportStereo(Viewport3D, string, double, Brush?)
Exports the specified viewport.
public static void ExportStereo(this Viewport3D viewport, string fileName, double stereoBase, Brush? background = null)
Parameters
viewportViewport3DThe viewport.
fileNamestringName of the file.
stereoBasedoubleThe stereo base.
backgroundBrushThe background brush.
Exceptions
- HelixToolkitException
Not supported file format.
FindHits(Viewport3D, Point, HitTestFilterCallback?)
Finds the hits for the specified position.
public static IList<PointHitResult> FindHits(this Viewport3D viewport, Point position, HitTestFilterCallback? filterCallback = null)
Parameters
viewportViewport3DThe viewport.
positionPointThe position.
filterCallbackHitTestFilterCallbackThe method that represents the hit test filter callback value./>
Returns
- IList<PointHitResult>
List of hits, sorted with the nearest hit first.
FindHits(Viewport3D, Rect, SelectionHitMode)
Finds the hits for the specified rectangle.
public static IEnumerable<RectangleHitResult> FindHits(this Viewport3D viewport, Rect rectangle, SelectionHitMode mode)
Parameters
viewportViewport3DThe viewport.
rectangleRectThe rectangle.
modeSelectionHitModeThe mode of selection.
Returns
- IEnumerable<RectangleHitResult>
The list of the hits.
FindNearest(Viewport3D, Point, out Point3D, out Vector3D, out DependencyObject?)
Finds the nearest visual, hit point and its normal at the specified position.
public static bool FindNearest(this Viewport3D viewport, Point position, out Point3D point, out Vector3D normal, out DependencyObject? visual)
Parameters
viewportViewport3DThe viewport.
positionPointThe position.
pointPoint3DThe 3D hit point.
normalVector3DThe normal of the mesh at the hit point.
visualDependencyObjectThe hit visual.
Returns
- bool
trueif a visual was found at the specified position.
FindNearestPoint(Viewport3D, Point)
Finds the coordinates of the nearest point at the specified position.
public static Point3D? FindNearestPoint(this Viewport3D viewport, Point position)
Parameters
viewportViewport3DThe viewport.
positionPointThe position.
Returns
- Point3D?
The nearest point, or null if no point was found.
FindNearestVisual(Viewport3D, Point)
Finds the Visual3D that is nearest the specified position.
public static Visual3D? FindNearestVisual(this Viewport3D viewport, Point position)
Parameters
viewportViewport3DThe viewport.
positionPointThe position.
Returns
- Visual3D
The nearest visual, or
nullif no visual was found.
GetCameraTransform(Viewport3D)
Gets the camera transform (viewport and projection).
public static Matrix3D GetCameraTransform(this Viewport3D viewport)
Parameters
viewportViewport3DThe viewport.
Returns
GetCameraTransform(Viewport3DVisual)
Gets the camera transform.
public static Matrix3D GetCameraTransform(this Viewport3DVisual viewport3DVisual)
Parameters
viewport3DVisualViewport3DVisualThe viewport visual.
Returns
- Matrix3D
The camera transform.
GetLights(Viewport3D)
Gets all lights.
public static IEnumerable<Light?> GetLights(this Viewport3D viewport)
Parameters
viewportViewport3DThe viewport.
Returns
- IEnumerable<Light>
A sequence of Light objects.
GetProjectionMatrix(Viewport3D)
Gets the projection matrix.
public static Matrix3D GetProjectionMatrix(this Viewport3D viewport)
Parameters
viewportViewport3DThe viewport.
Returns
GetRay(Viewport3D, Point)
Gets the ray at the specified position in 2D (screen coordinates).
public static Ray3D? GetRay(this Viewport3D viewport, Point position)
Parameters
viewportViewport3DThe viewport.
positionPointA 2D point.
Returns
GetTotalNumberOfTriangles(Viewport3D)
Gets the total number of triangles in the viewport.
public static int GetTotalNumberOfTriangles(this Viewport3D viewport)
Parameters
viewportViewport3DThe viewport.
Returns
- int
The total number of triangles
GetTotalTransform(Viewport3D)
Gets the total transform (camera and viewport).
public static Matrix3D GetTotalTransform(this Viewport3D viewport)
Parameters
viewportViewport3DThe viewport.
Returns
- Matrix3D
The total transform.
GetTotalTransform(Viewport3DVisual)
Gets the total transform (camera and viewport).
public static Matrix3D GetTotalTransform(this Viewport3DVisual viewport3DVisual)
Parameters
viewport3DVisualViewport3DVisualThe viewport visual.
Returns
- Matrix3D
The total transform.
GetTransform(Viewport3D, Visual3D)
Gets the total transform of the specified visual.
public static GeneralTransform3D? GetTransform(this Viewport3D viewport, Visual3D visual)
Parameters
viewportViewport3DThe viewport.
visualVisual3DThe visual.
Returns
- GeneralTransform3D
The transform.
GetViewMatrix(Viewport3D)
Gets the view matrix.
public static Matrix3D GetViewMatrix(this Viewport3D viewport)
Parameters
viewportViewport3DThe viewport.
Returns
GetViewportTransform(Viewport3D)
Gets the viewport transform.
public static Matrix3D GetViewportTransform(this Viewport3D viewport)
Parameters
viewportViewport3DThe viewport.
Returns
- Matrix3D
The transform.
GetViewportTransform(Viewport3DVisual)
Gets the viewport transform.
public static Matrix3D GetViewportTransform(this Viewport3DVisual viewport3DVisual)
Parameters
viewport3DVisualViewport3DVisualThe viewport3DVisual.
Returns
- Matrix3D
The transform.
Point2DtoPoint3D(Viewport3D, Point, out Point3D, out Point3D)
Transforms a position to Point3D at the near and far clipping planes.
public static bool Point2DtoPoint3D(this Viewport3D viewport, Point pointIn, out Point3D pointNear, out Point3D pointFar)
Parameters
viewportViewport3DThe viewport.
pointInPointThe point to transform.
pointNearPoint3DThe point at the near clipping plane.
pointFarPoint3DThe point at the far clipping plane.
Returns
- bool
True if points were found.
Point2DtoRay3D(Viewport3D, Point)
Transforms a 2D point to a ray.
public static Ray3D? Point2DtoRay3D(this Viewport3D viewport, Point pointIn)
Parameters
viewportViewport3DThe viewport.
pointInPointThe point.
Returns
- Ray3D
The ray.
Point3DtoPoint2D(Viewport3D, IEnumerable<Point3D>)
Transforms the set of Point3D to a set of Point2D.
public static IEnumerable<Point> Point3DtoPoint2D(this Viewport3D viewport, IEnumerable<Point3D> points)
Parameters
viewportViewport3DThe viewport.
pointsIEnumerable<Point3D>The set of 3D points.
Returns
- IEnumerable<Point>
The transformed points.
Point3DtoPoint2D(Viewport3D, Point3D)
Transforms the Point3D to a Point2D.
public static Point Point3DtoPoint2D(this Viewport3D viewport, Point3D point)
Parameters
viewportViewport3DThe viewport.
pointPoint3DThe 3D point.
Returns
- Point
The point.
Print(Viewport3D, string)
Prints the specified viewport.
public static void Print(this Viewport3D vp, string description)
Parameters
vpViewport3DThe viewport.
descriptionstringThe description.
RenderBitmap(Viewport3D, double, double, Brush, int)
Renders the viewport to a bitmap.
public static BitmapSource RenderBitmap(this Viewport3D view, double width, double height, Brush background, int m = 1)
Parameters
viewViewport3DThe viewport.
widthdoubleThe width.
heightdoubleThe height.
backgroundBrushThe background.
mintThe oversampling multiplier.
Returns
- BitmapSource
A bitmap.
RenderBitmap(Viewport3D, Brush, int)
Renders the viewport to a bitmap.
public static BitmapSource RenderBitmap(this Viewport3D view, Brush background, int m = 1)
Parameters
viewViewport3DThe viewport.
backgroundBrushThe background.
mintThe oversampling multiplier.
Returns
- BitmapSource
A bitmap.
ResizeAndArrange(Viewport3D, double, double)
Resizes and arranges the viewport.
public static void ResizeAndArrange(this Viewport3D view, double width, double height)
Parameters
viewViewport3DThe viewport.
widthdoubleThe width.
heightdoubleThe height.
SaveBitmap(Viewport3D, Stream, Brush?, int, OutputFormat)
Saves the Viewport3D to a bitmap.
public static void SaveBitmap(this Viewport3D view, Stream stream, Brush? background = null, int m = 1, BitmapExporter.OutputFormat format = OutputFormat.Png)
Parameters
viewViewport3DThe view.
streamStreamThe output stream.
backgroundBrushThe background brush.
mintThe oversampling multiplier.
formatBitmapExporter.OutputFormatThe output format.
SaveBitmap(Viewport3D, string, Brush?, int, OutputFormat)
Saves the viewport to a file.
public static void SaveBitmap(this Viewport3D view, string fileName, Brush? background = null, int m = 1, BitmapExporter.OutputFormat format = OutputFormat.Png)
Parameters
viewViewport3DThe viewport.
fileNamestringName of the file.
backgroundBrushThe background brush.
mintThe oversampling multiplier.
formatBitmapExporter.OutputFormatThe output format.
SaveStereoBitmap(Viewport3D, string, double, Brush?, int)
Saves the Viewport3D to left/right bitmap files.
public static void SaveStereoBitmap(this Viewport3D view, string fileName, double stereoBase, Brush? background = null, int m = 1)
Parameters
viewViewport3DThe viewport.
fileNamestringName of the file. "_L" and "_R" will be appended to the file name.
stereoBasedoubleThe stereo base.
backgroundBrushThe background brush.
mintThe oversampling multiplier.
SearchFor<T>(IEnumerable<Visual3D>)
Recursive search in a Visual3D collection for objects of given type T
public static IList<Model3D> SearchFor<T>(this IEnumerable<Visual3D> collection)
Parameters
collectionIEnumerable<Visual3D>The collection.
Returns
Type Parameters
TThe type to search for.
UnProject(Viewport3D, Point)
Transforms a point from the screen (2D) to a point on the plane trough the camera target point.
public static Point3D? UnProject(this Viewport3D viewport, Point p)
Parameters
viewportViewport3DThe viewport.
pPointThe 2D point.
Returns
- Point3D?
A 3D point.
UnProject(Viewport3D, Point, Point3D, Vector3D)
Transforms a point from the screen (2D) to a point on plane (3D)
public static Point3D? UnProject(this Viewport3D viewport, Point p, Point3D position, Vector3D normal)
Parameters
viewportViewport3DThe viewport.
pPointThe 2D point.
positionPoint3DA point in the plane.
normalVector3DThe plane normal.
Returns
- Point3D?
A 3D point.
Remarks
Maps window coordinates to object coordinates like
gluUnProject.