ModelGeometry
Description
- Derived from
Abstract base class for IModelGeometry implementations.
This class provides factory methods for building instances of the IModelGeometry interface:
Public / Constants
InstanceFormat
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
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
Capsule
Builds a capsule.
________________ / \ A = (0,0,0) | A------------B | \________________/ B = (0,length,0) |____________| length |__| radius
- See also
Cone
Builds a cone.
B /|\ A = (0,0,0) / | \ / | \ B = (0,length,0) / | \ +----A----+ |____| radius
- See also
Cylinder
Builds a cylinder.
____________ | | A = (0,0,0) A------------B |____________| B = (0,length,0)
- See also
Generic
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.
Shape
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.
SphereIco
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
Builds a tube.
______________ A = (0,0,0) A------------B ______________ B = (0,length,0)
- See also
Wrap
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
InstanceWrite
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 bytangentXYZ
,normalXYZ
andcross(tangentXYZ,normalXYZ)
. -
position
The rotated model-space vertices are translated by the givenposition
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.