ModelGeometry

Description

abstract class Tinman.Engine.Models.ModelGeometry

Derived from

IModelGeometry

Abstract base class for IModelGeometry implementations.

This class provides factory methods for building instances of the IModelGeometry interface:

  • Box: axis-aligned box

  • Build: custom geometry

  • Sphere: tessellated sphere

  • Wrap: wrap terrain vertex data

Public / Constants

Instance​Format


public static readonly attribute InstanceFormat → (VertexElements)

The vertex elements to use for instance buffers.

The vertex buffer layout for instance data is defined as follows:

@0  : Float x 3 (Position)
@12 : Float x 3 (Tangent)
@24 : Float x 3 (Tangent)
@36 : UInt8_Norm_Srgb x 4 (Color)
@40 : Float x 1 (TextureCoords)
@44 : Float x 1 (TextureCoords)
@48 : - end -

To write instance data, use the InstanceWrite method.

Public / Constructors

Box


public static method Box → (3)

box in : Box3D

The box coordinates.

normals opt : int32 = 0

Generate normal vectors?
> 0 : Generate normals by right-hand rule for CCW faces (see figure).
< 0 : Generate normals by right-hand rule for CW faces (see figure).
= 0 : Do not generate normals.

texCoords opt : int32 = 0

[>=0]
The texture coordinate repeat count per face. Set to 0 to disable texture coordinates.

returns → IModelGeometrySimple

The model geometry.

Builds an axis-aligned box.

The following figure shows the mapping from the given box in to the 3D model:

   121-----221
   /|      /|
  / |     / |
122-----222 |
 | 111---|-211
 | /     | /
 |/      |/
112-----212

where 111 maps to Box3D.X1, Box3D.Y1, Box3D.Z1 and 222 maps to Box3D.X2, Box3D.Y2, Box3D.Z2.

Build


public static method Build → ()

returns → ModelGeometryBuilder

The model geometry builder.

Creates a builder for IModelGeometry objects.

Capsule


public static method Capsule → (4)

length in : float64

[>=0]
The distance between A and B.

radius in : float64

[>=0]
The hemisphere radius at A and B.

segments opt : int32 = 12

[>=3]
The number of circle segments.

modulo opt : int32 = 1

[>=1]
The modulo to use for generating segment lines.

returns → IModelGeometrySimple

The model geometry.

Builds a capsule.

  ________________
 /                \     A = (0,0,0)
|  A------------B  |
 \________________/     B = (0,length,0)

   |____________|       length

                |__|    radius

Cone


public static method Cone → (4)

length in : float64

[>=0]
The distance between A and B.

radius in : float64

[>=0]
The disc radius at A.

segments opt : int32 = 12

[>=3]
The number of circle segments.

modulo opt : int32 = 1

[>=1]
The modulo to use for generating segment lines.

returns → IModelGeometrySimple

The model geometry.

Builds a cone.

     B
    /|\        A = (0,0,0)
   / | \
  /  |  \      B = (0,length,0)
 /   |   \
+----A----+

     |____|    radius

Cylinder


public static method Cylinder → (4)

length in : float64

[>=0]
The distance between A and B.

radius in : float64

[>=0]
The disc radius at A and B.

segments opt : int32 = 12

[>=3]
The number of circle segments.

modulo opt : int32 = 1

[>=1]
The modulo to use for generating segment lines.

returns → IModelGeometrySimple

The model geometry.

Builds a cylinder.

 ____________
|            |    A = (0,0,0)
A------------B
|____________|    B = (0,length,0)

Disc


public static method Disc → (2)

radius in : float64

[>=0]
The disc radius at A.

segments opt : int32 = 12

[>=3]
The number of circle segments.

returns → IModelGeometrySimple

The model geometry.

Builds a disc that is perpendicular to (0,1,0).

+--A--+    A = (0,0,0)
   |__|    radius

Dynamic


public static method Dynamic → (3)

vertices in : int32

[>0]
The vertex count.

format in : ModelVertexFormat

The vertex format.

indices opt : int32 = 0

[>=0]
The index count or 0 for none.

returns → IModelGeometryDynamic

The dynamic model geometry.

Creates an instance of IModelGeometryDynamic.

Generic


public static method Generic → (7)

length in : float64

[>=0]
The distance between A and B.

radiusA in : float64

[>=0]
The radius at A.

radiusB in : float64

[>=0]
The radius at B.

capA in : int32

The cap to build at A.

capB in : int32

The cap to build at B.

segments opt : int32 = 12

[>=3]
The number of circle segments.

modulo opt : int32 = 1

[>=1]
The modulo to use for generating segment lines.

returns → IModelGeometrySimple

The model geometry or null if empty.

Builds a 3D primitive from a generic, possibly degenerated capsule.

The point A is at (0,0,0), the point B is at (0, length in ,0):

  ________________
 /                \
|  A------------B  |    Round (cap > 0)
 \________________/

    ____________
   |            |
   A------------B       Flat  (cap = 0)
   |____________|

    ____________

   A------------B       None  (cap < 0)
    ____________


   |____________|       length

|__|            |__|    radiusA, radiusB

By choosing parameter values carefully, a variety of 3D primitives can be built with this method:

Primitive  | len = 0 | rA = 0 | rB = 0 | rA = rB | cA | cB
-----------+---------+--------+--------+---------+----+----
Capsule    |    no   |    no  |    no  |   yes   |  1 |  1
-----------+---------+--------+--------+---------+----+----
Cone       |    no   |   yes  |    no  |    no   | -1 |  0
           |    no   |    no  |   yes  |    no   |  0 | -1
-----------+---------+--------+--------+---------+----+----
Cylinder   |    no   |    no  |    no  |   yes   |  0 |  0
-----------+---------+--------+--------+---------+----+----
Disc       |   yes   |    no  |    no  |   yes   |  0 |  0
-----------+---------+--------+--------+---------+----+----
Hemisphere |   yes   |    no  |    no  |    no   |  1 |  0
           |   yes   |    no  |   yes  |   yes   |  0 |  1
-----------+---------+--------+--------+---------+----+----
Line       |    no   |   yes  |   yes  |   yes   | -1 | -1
-----------+---------+--------+--------+---------+----+----
Point      |   yes   |   yes  |   yes  |   yes   | -1 | -1
-----------+---------+--------+--------+---------+----+----
Sphere     |   yes   |    no  |    no  |   yes   |  1 |  1
-----------+---------+--------+--------+---------+----+----
Tube       |    no   |    no  |    no  |   yes   | -1 | -1

where len is length in, rA is radiusA in, rB is radiusB in, cA is capA in and cB is capB in.

Hemisphere


public static method Hemisphere → (3)

radius in : float64

[>=0]
The hemisphere radius at A.

segments opt : int32 = 12

[>=3]
The number of circle segments.

modulo opt : int32 = 1

[>=1]
The modulo to use for generating segment lines.

returns → IModelGeometrySimple

The model geometry.

Builds a hemisphere.

 _
| \     A = (0,0,0)
A  B
|_/     B = (0,radius,0)

Line


public static method Line → (1)

length in : float64

[>=0]
The distance between A and B.

returns → IModelGeometrySimple

The model geometry.

Builds a line segment.

A------------B    A = (0,0,0)
                  B = (0,length,0)

Shape


public static method Shape → (7)

shape in : IShape

[not-null]
The 2D shape.

triangles opt : bool = true

Generate triangles?

lines opt : bool = true

Generate lines

u0 opt : float64 = 0

Texture U-coordinate to map to Box2D.X1 of IShape.Bounds.

v0 opt : float64 = 0

Texture V-coordinate to map to Box2D.Y1 of IShape.Bounds.

u1 opt : float64 = 1

Texture U-coordinate to map to Box2D.X2 of IShape.Bounds.

v1 opt : float64 = 1

Texture V-coordinate to map to Box2D.Y2 of IShape.Bounds.

returns → IModelGeometrySimple

The model geometry or null if empty.

Builds a 3D shape.

The shape is in the XY-plane, having the normal vector (0,0,1). Texture coordinates are generated in the range (u0 opt, v0 opt) to ( u1 opt, v1 opt), which maps to Box2D.TopLeft resp. Box2D.BottomRight of IShape.Bounds.

The triangles of the 3D shape are obtained by first converting the given shape in to ShapeType.Mesh and then using IShape.TriangleAt.

The lines of the 3D shape are obtained by first converting the given shape in to ShapeType.Graph and then using IShape.EdgeAt.

Sphere


public static method Sphere → (3)

radius in : float64

[>=0]
The sphere radius.

segments opt : int32 = 12

[>=3]
The number of circle segments.

modulo opt : int32 = 1

[>=1]
The modulo to use for generating segment lines.

returns → IModelGeometrySimple

The model geometry.

Builds a sphere.

  ___
 /   \
|  A  |    A = (0,0,0)
 \___/

   |__|    radius

Sphere​Ico


public static method SphereIco → (5)

center in : Vec3D

The sphere center.

radius in : float64

The sphere radius. If negative, the sphere will be mirrored at center in, making the normals point inwards.

levels in : int32

[>=0]
Subdivisions to perform for faces (see IModelGeometrySimple.Triangles). Level 7 generates approximately one million triangles.

levelsEdges opt : int32 = 0

[0..levels]
Subdivisions to perform for edges (see IModelGeometrySimple.Lines). Level 7 generates approximately one million lines.

textureCoordinates opt : bool = false

Generate U and V texture coordinates?

The U-coordinate range [0..1] is mapped to longitude [-180° .. +180°].
The V-coordinate range [0..1] is mapped to latitude  [ +90° ..  -90°].

Vertex positions are mapped to geographic coordinates using the conventions of Geocentric.

returns → IModelGeometrySimple

The model geometry.

Builds a sphere by subdividing an icosahedron.

The number of triangle vertices resp. line vertices (see PrimitiveBatch.Count) can be computed from the subdivision count levels in resp. levelsEdges opt as follows:

vertices = 4 ^ levels * 60

The first eight subdivision levels produce the following triangle resp. line vertex counts:

count = 0 : vertices =      60
count = 1 : vertices =     240
count = 2 : vertices =     960
count = 3 : vertices =   3,840
count = 4 : vertices =  15,360
count = 5 : vertices =  61,440
count = 6 : vertices = 245,760
count = 7 : vertices = 983,040

Tube


public static method Tube → (4)

length in : float64

[>=0]
The distance between A and B.

radius in : float64

[>=0]
The hemisphere radius at A and B.

segments opt : int32 = 12

[>=3]
The number of circle segments.

modulo opt : int32 = 1

[>=1]
The modulo to use for generating segment lines.

returns → IModelGeometrySimple

The model geometry.

Builds a tube.

______________
                  A = (0,0,0)
A------------B
______________    B = (0,length,0)

Wrap


[Pure]
public static method Wrap → (2)

vertices in : VertexArrays

[not-null]
The vertex data to wrap.

indices opt : int32 [ ] = null

The index data to wrap or null to create non-indexed geometry.

returns → IModelGeometry

The model geometry.

Creates a new instance of ModelGeometry.

The given vertices in object and indices opt array will be referenced by the returned IModelGeometry object, no data is copied.

Public / Methods

Instance​Write


public static method InstanceWrite → (13)

buffer in : ByteBuffer

[not-null]
The output byte buffer.

positionX in : float32

X-coordinate of instance position.

positionY in : float32

Y-coordinate of instance position.

positionZ in : float32

Z-coordinate of instance position.

tangentX opt : float32 = 1

X-component of unit-length side vector.

tangentY opt : float32 = 0

Y-component of unit-length side vector.

tangentZ opt : float32 = 0

Z-component of unit-length side vector.

normalX opt : float32 = 0

X-component of unit-length up vector.

normalY opt : float32 = 1

Y-component of unit-length up vector.

normalZ opt : float32 = 0

Z-component of unit-length up vector.

scale opt : float32 = 1

Uniform instance scale factor.

color opt : int64 = ~0

The instance color (low-dynamic range).

intensity opt : float32 = 1

The absolute value is used as the high-dynamic range scale for color opt. The sign decides how the instance position is applied (see remarks).

Writes instance data to the given buffer.

This method will write a full instance, according to InstanceFormat, including padding for alignment. The instance elements have the same order as the parameters of this method and are applied during rendering as follows:

  • scale
    The vertices in model-space are scaled by the given scale opt factor.

  • rotation
    A 3x3 orthonormal rotation matrix is applied to the scaled vertices in model-space, where the row vectors given by tangentXYZ, normalXYZ and cross(tangentXYZ,normalXYZ).

  • position
    The rotated model-space vertices are translated by the given position offsets, before (if intensity opt is negative) or after (if intensity opt is positive) transforming them from model-space to world-space.

  • color
    After applying ModelPartFlags.VertexAlphaIsOcclusion and ModelPartFlags.VertexColorIsBaseColor, the vertex color is modulated with the given color opt factor (all channels). Then, the color channels are scaled by the given intensity opt factor, to produce high-dynamic range colors.

Logging

Logger


public static readonly attribute Logger → (ILogger)

The logger object of this class.