Table of Contents

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

view Viewport3D

The viewport.

width double

The width.

height double

The height.

background Brush

The background.

m int

The oversampling multiplier.

Copy(Viewport3D, int)

Copies the specified viewport to the clipboard.

public static void Copy(this Viewport3D view, int m = 1)

Parameters

view Viewport3D

The viewport.

m int

The oversampling multiplier.

CopyXaml(Viewport3D)

Copies the viewport as

xaml
to the clipboard.
public static void CopyXaml(this Viewport3D viewport)

Parameters

viewport Viewport3D

The viewport.

Export(Viewport3D, string, Brush?)

Exports the specified viewport.

public static void Export(this Viewport3D viewport, string fileName, Brush? background = null)

Parameters

viewport Viewport3D

The viewport.

fileName string

Name of the file.

background Brush

The 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

viewport Viewport3D

The viewport.

fileName string

Name of the file.

stereoBase double

The stereo base.

background Brush

The 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

viewport Viewport3D

The viewport.

position Point

The position.

filterCallback HitTestFilterCallback

The 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

viewport Viewport3D

The viewport.

rectangle Rect

The rectangle.

mode SelectionHitMode

The 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

viewport Viewport3D

The viewport.

position Point

The position.

point Point3D

The 3D hit point.

normal Vector3D

The normal of the mesh at the hit point.

visual DependencyObject

The hit visual.

Returns

bool

true if 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

viewport Viewport3D

The viewport.

position Point

The 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

viewport Viewport3D

The viewport.

position Point

The position.

Returns

Visual3D

The nearest visual, or null if no visual was found.

GetCameraTransform(Viewport3D)

Gets the camera transform (viewport and projection).

public static Matrix3D GetCameraTransform(this Viewport3D viewport)

Parameters

viewport Viewport3D

The viewport.

Returns

Matrix3D

A Matrix3D.

GetCameraTransform(Viewport3DVisual)

Gets the camera transform.

public static Matrix3D GetCameraTransform(this Viewport3DVisual viewport3DVisual)

Parameters

viewport3DVisual Viewport3DVisual

The viewport visual.

Returns

Matrix3D

The camera transform.

GetLights(Viewport3D)

Gets all lights.

public static IEnumerable<Light?> GetLights(this Viewport3D viewport)

Parameters

viewport Viewport3D

The viewport.

Returns

IEnumerable<Light>

A sequence of Light objects.

GetProjectionMatrix(Viewport3D)

Gets the projection matrix.

public static Matrix3D GetProjectionMatrix(this Viewport3D viewport)

Parameters

viewport Viewport3D

The viewport.

Returns

Matrix3D

A Matrix3D.

GetRay(Viewport3D, Point)

Gets the ray at the specified position in 2D (screen coordinates).

public static Ray3D? GetRay(this Viewport3D viewport, Point position)

Parameters

viewport Viewport3D

The viewport.

position Point

A 2D point.

Returns

Ray3D

A Ray3D.

GetTotalNumberOfTriangles(Viewport3D)

Gets the total number of triangles in the viewport.

public static int GetTotalNumberOfTriangles(this Viewport3D viewport)

Parameters

viewport Viewport3D

The 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

viewport Viewport3D

The viewport.

Returns

Matrix3D

The total transform.

GetTotalTransform(Viewport3DVisual)

Gets the total transform (camera and viewport).

public static Matrix3D GetTotalTransform(this Viewport3DVisual viewport3DVisual)

Parameters

viewport3DVisual Viewport3DVisual

The 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

viewport Viewport3D

The viewport.

visual Visual3D

The visual.

Returns

GeneralTransform3D

The transform.

GetViewMatrix(Viewport3D)

Gets the view matrix.

public static Matrix3D GetViewMatrix(this Viewport3D viewport)

Parameters

viewport Viewport3D

The viewport.

Returns

Matrix3D

A Matrix3D.

GetViewportTransform(Viewport3D)

Gets the viewport transform.

public static Matrix3D GetViewportTransform(this Viewport3D viewport)

Parameters

viewport Viewport3D

The viewport.

Returns

Matrix3D

The transform.

GetViewportTransform(Viewport3DVisual)

Gets the viewport transform.

public static Matrix3D GetViewportTransform(this Viewport3DVisual viewport3DVisual)

Parameters

viewport3DVisual Viewport3DVisual

The 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

viewport Viewport3D

The viewport.

pointIn Point

The point to transform.

pointNear Point3D

The point at the near clipping plane.

pointFar Point3D

The 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

viewport Viewport3D

The viewport.

pointIn Point

The 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

viewport Viewport3D

The viewport.

points IEnumerable<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

viewport Viewport3D

The viewport.

point Point3D

The 3D point.

Returns

Point

The point.

Print(Viewport3D, string)

Prints the specified viewport.

public static void Print(this Viewport3D vp, string description)

Parameters

vp Viewport3D

The viewport.

description string

The 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

view Viewport3D

The viewport.

width double

The width.

height double

The height.

background Brush

The background.

m int

The 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

view Viewport3D

The viewport.

background Brush

The background.

m int

The 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

view Viewport3D

The viewport.

width double

The width.

height double

The 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

view Viewport3D

The view.

stream Stream

The output stream.

background Brush

The background brush.

m int

The oversampling multiplier.

format BitmapExporter.OutputFormat

The 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

view Viewport3D

The viewport.

fileName string

Name of the file.

background Brush

The background brush.

m int

The oversampling multiplier.

format BitmapExporter.OutputFormat

The 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

view Viewport3D

The viewport.

fileName string

Name of the file. "_L" and "_R" will be appended to the file name.

stereoBase double

The stereo base.

background Brush

The background brush.

m int

The 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

collection IEnumerable<Visual3D>

The collection.

Returns

IList<Model3D>

A list of models.

Type Parameters

T

The 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

viewport Viewport3D

The viewport.

p Point

The 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

viewport Viewport3D

The viewport.

p Point

The 2D point.

position Point3D

A point in the plane.

normal Vector3D

The plane normal.

Returns

Point3D?

A 3D point.

Remarks

Maps window coordinates to object coordinates like

gluUnProject
.