ModelsUtil

Description

static class Tinman.Engine.Models.ModelsUtil

Helper class for dealing with 3D model hierarchies.

The Distance* methods can be used for low-level distance computations for common geometric primitives found in 3D model hierarchies:

  • Point (A)

  • Line-segment (A,B)

  • Triangle (A,B,C)

The following computation pairs are supported:

  • Point to line-segment

  • Point to triangle

  • Line-segment to line-segment

  • Line-segment to triangle

  • Triangle to triangle

These methods are similar to the ones of Geometric, except that they use different input vector parametrization in order to reduce the amount of redundant computations.

The Terrain* methods are helpers for building 3D models from terrain mesh chunks, see MeshChunkBuilder.

Public / Methods

Apply​Transform

2 overloads


public static method ApplyTransform1 → (4)

data in : VertexArrays

[not-null]
The vertex arrays.

scaling in : Vec3D

The scaling to apply.

offset opt : int32 = 0

[0..data.Capacity]
Index of first vertex to transform.

count opt : int32 = -1

[-1..data.Capacity-offset]
Number of vertices to transform. If -1, all vertices from offset opt until the end of the vertex arrays will be transformed.

Applies the non-uniform scaling to the given vertex arrays.


public static method ApplyTransform2 → (4)

data in : VertexArrays

[not-null]
The vertex arrays.

transform in : Mat4D

The transformation to apply.

offset opt : int32 = 0

[0..data.Capacity]
Index of first vertex to transform.

count opt : int32 = -1

[-1..data.Capacity-offset]
Number of vertices to transform. If -1, all vertices from offset opt until the end of the vertex arrays will be transformed.

Applies the given transformation to the given vertex arrays.

Compute​Normals


public static method ComputeNormals → (2)

vertices in : VertexArrays

[not-null]
The vertex arrays.

triangleList in : int32 [ ]

[not-null]
The vertex indices of the triangle faces.

Computes smooth per-vertex normal vectors given vertex arrays.

Vertex positions are read from Semantic.Position, non unit-length normal vectors are written to Semantic.Normal. If Semantic.Normal is already present, normal vectors will only be computed for vertex array entries that are equal to Vec3F.Zero. To produce per-face normals, vertices must have been duplicated accordingly, before this method is called.

Distance​Line​Segment​To​Line​Segment


[Pure]
public static method DistanceLineSegmentToLineSegment → (9)

bx0 in : float64

X-coordinate of vertex B minus vertex A of first line-segment.

by0 in : float64

Y-coordinate of vertex B minus vertex A of first line-segment.

bz0 in : float64

Z-coordinate of vertex B minus vertex A of first line-segment.

ax1 in : float64

X-coordinate of vertex A of second line-segment minus vertex A of first line-segment.

ay1 in : float64

Y-coordinate of vertex A of second line-segment minus vertex A of first line-segment.

az1 in : float64

Z-coordinate of vertex A of second line-segment minus vertex A of first line-segment.

bx1 in : float64

X-coordinate of vertex B minus vertex A of second line-segment.

by1 in : float64

Y-coordinate of vertex B minus vertex A of second line-segment.

bz1 in : float64

Z-coordinate of vertex B minus vertex A of second line-segment.

returns → float64

The distance value.

Computes the distance between the given line-segment (first) and line-segment (second).

This method is similar to Geometric.DistanceLineToLine, if the returned line coefficients are clamped to [0..1].

Distance​Line​Segment​To​Triangle


[Pure]
public static method DistanceLineSegmentToTriangle → (13)

bx0 in : float64

X-coordinate of vertex B minus vertex A of first line-segment.

by0 in : float64

Y-coordinate of vertex B minus vertex A of first line-segment.

bz0 in : float64

Z-coordinate of vertex B minus vertex A of first line-segment.

ax1 in : float64

X-coordinate of vertex A of second triangle minus vertex A of first line-segment.

ay1 in : float64

Y-coordinate of vertex A of second triangle minus vertex A of first line-segment.

az1 in : float64

Z-coordinate of vertex A of second triangle minus vertex A of first line-segment.

bx1 in : float64

X-coordinate of vertex B minus vertex A of second triangle.

by1 in : float64

Y-coordinate of vertex B minus vertex A of second triangle.

bz1 in : float64

Z-coordinate of vertex B minus vertex A of second triangle.

cx1 in : float64

X-coordinate of vertex C minus vertex A of second triangle.

cy1 in : float64

Y-coordinate of vertex C minus vertex A of second triangle.

cz1 in : float64

Z-coordinate of vertex C minus vertex A of second triangle.

minimum opt : float64 = 0

The minimum distance value to return.

returns → float64

The distance value.

Computes the distance between the given line-segment (first) and triangle (second).

Distance​Point​To​Line​Segment


[Pure]
public static method DistancePointToLineSegment → (6)

ax in : float64

X-coordinate of vertex A of second line-segment minus first point.

ay in : float64

Y-coordinate of vertex A of second line-segment minus first point.

az in : float64

Z-coordinate of vertex A of second line-segment minus first point.

bx in : float64

X-coordinate of vertex B minus vertex A of second line-segment.

by in : float64

Y-coordinate of vertex B minus vertex A of second line-segment.

bz in : float64

Z-coordinate of vertex B minus vertex A of second line-segment.

returns → float64

The distance value.

Computes the distance between the given point (first) and line-segment (second).

This method is similar to Geometric.DistancePointToLineSegment3

Distance​Point​To​Triangle


[Pure]
public static method DistancePointToTriangle → (9)

ax1 in : float64

X-coordinate of vertex A of second triangle minus first point.

ay1 in : float64

Y-coordinate of vertex A of second triangle minus first point.

az1 in : float64

Z-coordinate of vertex A of second triangle minus first point.

bx1 in : float64

X-coordinate of vertex B minus vertex A of second triangle.

by1 in : float64

Y-coordinate of vertex B minus vertex A of second triangle.

bz1 in : float64

Z-coordinate of vertex B minus vertex A of second triangle.

cx1 in : float64

X-coordinate of vertex C minus vertex A of second triangle.

cy1 in : float64

Y-coordinate of vertex C minus vertex A of second triangle.

cz1 in : float64

Z-coordinate of vertex C minus vertex A of second triangle.

returns → float64

The distance value.

Computes the distance between the given point (first) and triangle (second).

This method is similar to Geometric.DistancePointToTriangle.

Distance​Triangle​To​Triangle


[Pure]
public static method DistanceTriangleToTriangle → (17)

bx0 in : float64

X-coordinate of vertex B minus vertex A of first triangle.

by0 in : float64

Y-coordinate of vertex B minus vertex A of first triangle.

bz0 in : float64

Z-coordinate of vertex B minus vertex A of first triangle.

cx0 in : float64

X-coordinate of vertex C minus vertex A of first triangle.

cy0 in : float64

Y-coordinate of vertex C minus vertex A of first triangle.

cz0 in : float64

Z-coordinate of vertex C minus vertex A of first triangle.

ax1 in : float64

X-coordinate of vertex A of second triangle minus vertex A of first triangle.

ay1 in : float64

Y-coordinate of vertex A of second triangle minus vertex A of first triangle.

az1 in : float64

Z-coordinate of vertex A of second triangle minus vertex A of first triangle.

bx1 in : float64

X-coordinate of vertex B minus vertex A of second triangle.

by1 in : float64

Y-coordinate of vertex B minus vertex A of second triangle.

bz1 in : float64

Z-coordinate of vertex B minus vertex A of second triangle.

cx1 in : float64

X-coordinate of vertex C minus vertex A of second triangle.

cy1 in : float64

Y-coordinate of vertex C minus vertex A of second triangle.

cz1 in : float64

Z-coordinate of vertex C minus vertex A of second triangle.

maximum opt : float64 = Maths.MaxDouble

The maximum distance value to return.

minimum opt : float64 = 0

The minimum distance value to return.

returns → float64

The distance value.

Computes the distance between the given triangle (first) and triangle (second).

Model​Vertex​Format​For


[Pure]
public static method ModelVertexFormatFor → (2)

vertices in : VertexArrays

[not-null]
The vertex array.

checkPositionExtra in : bool

Analyse coordinates of Semantic.Position in order to determine if ModelVertexFormat.PositionExtra must be present in the model vertex format?

returns → ModelVertexFormat

The model vertex format.

Returns the ModelVertexFormat that corresponds to the given vertex arrays.

Normalize​Normals


public static method NormalizeNormals → (1)

vertices in : VertexArrays

[not-null]
The vertex arrays.

Normalizes the normal vectors in the given vertex arrays to unit-length.

Undefined normal vectors will be set to Vec3F.Zero.

Read​Model​Debug


public static method ReadModelDebug → (3)

reader in : IModelReader

[not-null]
The model reader.

fileName in : string

[not-empty]
The diagnostic file name.

directory in : Path

[not-null]
The diagnostic output directory.

Implements the default behaviour of the IModelReader.ReadModelDebug method.

Implementations of IModelReader may delegate to this method in order to provide the default behaviour.

IOException

If an I/O error has occurred.

Read​Text​Line


public static method ReadTextLine → (2)

stream in : IDataStream

[not-null]
The data stream to read from.

output in : StringBuilder

[not-null]
The output string builder.

returns → int32

The 8-bit code (or -1 for EOF) that immediately follows the read line of text, including the line terminator character(s), if present.

Reads a line of text from stream in, using the CharacterEncodingSimple.ISO_8859_1 encoding.

IOException

If an I/O error has occurred while reading from stream in.

Terrain​Geometry


[Pure]
public static method TerrainGeometry → (2)

chunk in : MeshChunk

[not-null]
The terrain mesh chunk.

local opt : bool = true

Output the model part vertices in the local coordinate system of the mesh chunk (see MeshChunk.Matrix), instead of the terrain coordinate system?

returns → IModelGeometry

The 3D model part.

Builds model geometry for a terrain mesh chunk.

Terrain​Material


[Pure]
public static method TerrainMaterial → (1)

chunk in : MeshChunk

[not-null]
The terrain mesh chunk.

returns → Material

The created material.

Creates a material for the given terrain mesh chunk.

Terrain​Model

2 overloads


[Pure]
public static method TerrainModel1 → (3)

chunk in : MeshChunk

[not-null]
The terrain mesh chunk.

local opt : bool = true

Output the model part vertices in the local coordinate system of the mesh chunk (see MeshChunk.Matrix), instead of the terrain coordinate system?

model opt : Model = null

Optional model to use for adding model parts or null to create a new model.

returns → Model

The 3D model.

Creates a 3D model for the given terrain mesh chunk.

This method delegates to TerrainModelPart1 and wraps the returned ModelPart in a new Model.


[Pure]
public static method TerrainModel2 → (4)

builder in : MeshChunkBuilder

[not-null]
The terrain mesh chunk builder to use.

coords in : PyramidCoords

The pyramid coordinates of the terrain chunk, which may be PyramidCoords.All.

local opt : bool = true

Output the model part vertices in the local coordinate system of the mesh chunk (see MeshChunk.Matrix), instead of the terrain coordinate system?

model opt : Model = null

Optional model to use for adding model parts or null to create a new model.

returns → Model

The 3D model.

Creates a 3D model for the given terrain mesh chunk.

This method delegates to TerrainModel1 after using MeshChunkBuilder.Build of builder in.

Terrain​Model​Part

2 overloads


[Pure]
public static method TerrainModelPart1 → (3)

chunk in : MeshChunk

[not-null]
The terrain mesh chunk.

local opt : bool = true

Output the model part vertices in the local coordinate system of the mesh chunk (see MeshChunk.Matrix), instead of the terrain coordinate system?

quadrant opt : int32 = -1

[-1..3]
The mesh quadrant to cover (i.e., child of root sector, see MeshTree.GetChild and MeshChunk.IndexRange). Set to -1 to cover the whole chunk.

returns → ModelPart

The 3D model part.

Creates a model part for the given terrain mesh chunk.

If present, layer textures of the model chunk will be mapped as follows:

This method uses TerrainGeometry to create an own IModelGeometry object and TerrainMaterial to create an own Material object, for IModelPart.Geometry and IModelPart.Material of the returned ModelPart object.


[Pure]
public static method TerrainModelPart2 → (4)

chunk in : MeshChunk

[not-null]
The terrain mesh chunk.

geometry in : IModelGeometry

[not-null]
The model geometry, created with TerrainGeometry.

material in : IMaterial

[not-null]
The material, created with TerrainMaterial.

quadrant opt : int32 = -1

[-1..3]
The mesh quadrant to cover (i.e., child of root sector, see MeshTree.GetChild and MeshChunk.IndexRange). Set to -1 to cover the whole chunk.

returns → ModelPart

The 3D model part.

Creates a model part for the given terrain mesh chunk.

If present, layer textures of the model chunk will be mapped as follows:

This method uses TerrainGeometry to create an own IModelGeometry object for chunk in.

Vertex​Arrays​For


[Pure]
public static method VertexArraysFor → (2)

modelFormat in : ModelVertexFormat

The model vertex format flags.

capacity in : int32

[>0]
The capacity, in vertices.

returns → VertexArrays

The VertexArrays object.

Returns a VertexArrays object that corresponds to the given model format.

Vertex​Format​For


[Pure]
public static method VertexFormatFor → (1)

modelFormat in : ModelVertexFormat

The model vertex format flags.

returns → IVertexFormat

The IVertexFormat object.

Returns a IVertexFormat object that corresponds to the given model format.