# Silhouette

## Description

`sealed` `class` `Tinman.Engine.Components.Silhouette`

Computes silhouette edges for a given view direction or view point of a soup of loosely connected triangular faces.

To build a silhouette, perform the following steps:

1. Create a new instance of Silhouette.

2. Add triangular faces with Face, which populates Edges, Faces and Vertices.

3. Optionally call Finish, to free the internal data structures for face specification.

4. Optionally call Prepare, to warm up the spatial acceleration data structures.

5. Call Compute (repeatedly) to build the silhouette edges, see Contour.

6. To start from scratch, call Clear and go to to step 2.

## Public / Constructors

### Silhouette

`public` `constructor` `Silhouette` → `()`

Creates a new instance of Silhouette.

## Public / Methods

### Clear

`public` `method` `Clear` → `()`

Clears the silhouette by deleting all vertices and faces.

### Compute

`public` `method` `Compute` → `(1)`

vector in : Vec4D

The unit-length view direction vector (if Vec4D.W is `0`) or the point of view (if Vec4D.W is not `0`).

Computes the silhouette for the given vector.

This method (re-)builds the whole content of Contour.

### Edge

`public` `method` `Edge` → `(2)`

in : Vec3D

Coordinates of first edge point.

in : Vec3D

Coordinates of second edge point.

Specifies a single edge.

Edges that are not connected to at least one face will always be included in Contour.

### Face

`public` `method` `Face` → `(3)`

in : Vec3D

Coordinates of first triangle point.

in : Vec3D

Coordinates of second triangle point.

in : Vec3D

Coordinates of third triangle point.

Specifies a triangular face.

First, the given points in, in, in are mapped to unique vertices, which may add new elements to Vertices. Then, the vertex indices are used to build one face tuple and three edge tuples, which may add new elements to Faces resp. Edges. Finally, the front-facing normal-vector of the triangle is computed as follows:

`normal = cross(b - a, c - a)`

### Finish

`public` `method` `Finish` → `()`

Finishes specification of faces via Face.

After this method has been called, no more faces can be added; Face will return silently. The Clear method will undo this. Finishing face specification allows to free internal data structures that are no longer needed.

### Prepare

`public` `method` `Prepare` → `()`

Computes all spatial acceleration data structures, if necessary.

Adding new faces via Face will invalidate the data structures. When the Compute method is called, the computations will be performed automatically. Calling this method is optional, but will make sure that all computations will have been performed when Compute is called.

### To​Model​Geometry

`public` `method` `ToModelGeometry` → `(2)`

builder in : ModelGeometryBuilder

`[not-null]`
The model geometry builder to feed.

which in : int32

Bitmask that chooses which data to feed to builder in:
`1` : Vertices using VertexWriter.P2
`2` : Faces using ModelGeometryBuilder.Triangle
`4` : Edges using ModelGeometryBuilder.LineSegment
`8` : Contour using ModelGeometryBuilder.LineSegment
Vertices are output before faces, faces are output before edges, edges are output before contours.

returns → Vec4I

The amount of geometry that has been fed to builder in:
Vec4I.X : the vertex count
Vec4I.Y : the index count for faces
Vec4I.Z : the index count for edges
Vec4I.W : the index count for contours

Feeds vertex, edge and/or contour data into the given model geometry builder.

## Public / Attributes

### Contour

`[Constant]`
`public` `attribute` `Contour` → `(get)`

value : IArrayVector<int32>

`[not-null]`
The edge array. Each element refers to a unique edge in Edges.

The silhouette edges that have been computed with Compute

### Edges

`[Constant]`
`public` `attribute` `Edges` → `(get)`

value : IArrayVector<Vec2I>

`[not-null]`
The edge array.

The unique edges that have been added with Face.

Adjacent edges of different faces produce only one unique edge. The Vec2I.X and Vec2I.Y indices depict the edge vertices (see Vertices), where Vec2I.X is always smaller than Vec2I.Y.

### Faces

`[Constant]`
`public` `attribute` `Faces` → `(get)`

value : IArrayVector<Vec3I>

`[not-null]`
The face array.

The unique faces that have been added with Face.

Each Vec3I value depicts three vertices in Vertices which span the triangular face, where Vec3I.X is always smaller than both Vec3I.Y and Vec3I.Z.

### Transform

`public` `attribute` `Transform` → `(get,set)`

value : AffineTransform

The transformation to apply.

The transformation that is applied to the vertex points that are passed to Edge and Face.

### Vertices

`[Constant]`
`public` `attribute` `Vertices` → `(get)`

value : IArrayVector<Vec3D>

`[not-null]`
The vertex array.

The unique vertices that have been added with Face.

Adding points with identical coordinates will create only a single unique vertex.