ModelReader

Description

abstract class Tinman.Engine.Models.ModelReader

Derived from

ModelReaderBase abstract

Extended by

OpenFlightModelReader sealed

Abstract base class for implementations of the IModelReader interface that perform additional processing while reading 3D models.

Public / Methods

Resolve​Texture​Path


[Pure]
public method ResolveTexturePath → (1)

path in : Path

[not-null]
The texture path.

returns → Path

The resolved canonical texture path.

Resolves the given texture path, using the current model reader settings.

Resolve​Texture​Path​Reverse


public method ResolveTexturePathReverse → (1)

path in : Path

[not-null]
The resolved texture path.

returns → Path

The texture path (relative if possible).

Reverse-resolves the given texture path.

Texture​File​Replace


public method TextureFileReplace → (2)

path in : Path

[not-null]
The texture file path.

texture in : IModelTexture

[not-null]
The replacement model texture object.

Replaces a texture file.

The given texture file path will be resolved (see ResolveTexturePath), if necessary.

Texture​Name​Replace


public method TextureNameReplace → (2)

original in : string

[not-null]
The original texture name.

corrected in : string

[not-null]
The corrected texture name.

Replaces a texture name.

Public / Attributes

Bad​Texture​Names


public attribute BadTextureNames → (get)

value : string [ ]

The bad texture names or null if texture names have been resolved or the IModelReader.ReadModel method has not been called yet.

Returns the texture names (see TextureName1 and TextureName2) that could not have been resolved.

A warning message is generated for each bad texture name during validation (see IValidatable.Validate).

Bump​Scale


public attribute BumpScale → (get,set)

value : float64

The relative bump height. This value is interpreted relative to the dimensions of the unit square of normalized texture coordinates. A value of 1 will extrude the unit square to the unit cube.

Relative height of bump maps.

Instead of a normal map, a model may define a bump height map. In this case, a tangent-space normal map can be generated from the bump map, using the given bump height.

Defaults to 0.

Fix​Winding


public attribute FixWinding → (get,set)

value : int32

Given a triangle (a,b,c), vertex winding is fixed using the face normal N and the cross product X=(b-a)x(c-a):
> 0 : Fix triangle winding so that dot(N,X) is positive.
< 0 : Fix triangle winding so that dot(N,X) is negative.
= 0 : Do not fix triangle winding.

Fix vertex winding of indexed triangle list primitives?

If the model does not have normal vectors, vertex winding will never be fixed. This fix is applied after ReadModelFlags.FlipWinding.

Defaults to 0.

Flags


public attribute Flags → (get,set)

value : ReadModelFlags

The flags.

The flags to use for reading the 3D model.

Defaults to ReadModelFlags.None.

Glossiness​Scale


public attribute GlossinessScale → (get,set)

value : float32

[>=0]
The gloss scale.

Scale factor to apply to IMaterial.Glossiness. MaterialPart.Value of all read materials.

Defaults to 1.0.

Model​Names


public attribute ModelNames → (get)

value : ISortedSet<string>

[not-null]
The set of model names to keep.

Names of the model nodes to keep, including their hierarchical structure.

If ReadModelFlags.ModelNames is present, this property is ignored.

Reflectivity​Scale


public attribute ReflectivityScale → (get,set)

value : ColorF

The reflectivity scale.

Modulation color to apply to IMaterial.Reflectivity. MaterialPart.Value of all read materials.

Defaults to ColorF.White.

Root​Material


public attribute RootMaterial → (get,set)

value : IMaterial

The root material or null.

The material to use for the model root node.

Root​Unit


public attribute RootUnit → (get,set)

value : UnitOfMeasure

The root unit of measure or null.

The unit of measure to use for the model root node.

Simplify


public attribute Simplify → (get,set)

value : ModelSimplifyFlags

The model simplification actions.

The model simplification actions that will be performed by IModelReader.ReadModel before returning the final IModel.

Defaults to ModelSimplifyFlags.All.

Texture​Path


public attribute TexturePath → (get,set)

value : Path

[not-null]
The texture base directory.

The base directory to use for resolving relative texture file paths in the 3D model.

The given base directory can be relative; in this case, it will be resolved using the path of the directory that contains the model file. If there is no path info for the model data (see IFileData.IsPathInfoValid), the current filesystem directory is used instead.

Defaults to Path.Current.

Transform


public attribute Transform → (get,set)

value : Mat4D

The transformation matrix.

Optional transformation matrix to apply to the model geometry.

The transformation matrix is applied as the last transformation step, before the custom post processors are invoked.

Defaults to Mat4D.Identity.

Protected / Constructors

Model​Reader


protected constructor ModelReader → (2)

data in : IFileData

[not-null]
The 3D model file data to read.

modelFormatName in : string

Name of the ModelFormat.

Creates a new instance of ModelReader.

Protected / Methods

Compute​Normals


protected 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.

Message


protected method Message → (1)

message in : ValidateMessage

[not-null]
The validation message.

Provides a validation message that shall be returned by IValidatable.Validate.

Model​Name​Keep


[Pure]
protected method ModelNameKeep → (1)

name in : string

The model name.

returns → bool

true if the model shall be kept,
false if it may be merged.

Checks if the given model name shall be kept, including its hierarchical structure.

Normalize​Normals


protected 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.

Post​Process​Indices


protected method PostProcessIndices → (3)

vertices in : VertexArrays

The vertex data.

indices in : int32 [ ]

The index data to process.

batch in : PrimitiveBatch

The geometry batch.

Performs in-place post processing on the given index data:

Post​Process​Texture​Coords​Normals


protected method PostProcessTextureCoordsNormals → (1)

vertices in : VertexArrays

The vertex data to process.

Performs in-place post processing on the given vertex data:

Post​Process​Vertices

2 overloads


protected method PostProcessVertices1 → ()

returns → Mat4D

The transformation matrix.

Returns a transformation matrix for performing post processing on vertex data:


protected method PostProcessVertices2 → (1)

vertices in : VertexArrays

The vertex data to process.

Performs in-place post processing on the given vertex data:

Read​Text​Line


protected 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.

Texture​File

2 overloads


[Pure]
protected method TextureFile1 → (1)

file in : Path

[not-null]
The texture file path.

returns → IModelTexture

The model texture or null.

Returns the model texture object that has been specified for the given texture file.

The model texture object for the given texture file in is obtained by the following steps:

  1. The given texture path is resolved (see ResolveTexturePath).

  2. If a model texture object has been specified earlier for the resolved texture path via TextureFileReplace, that object is used.


protected method TextureFile2 → (3)

file in : Path

[not-null]
The texture file path.

srgb in : bool

The ISrgb.Srgb flag to use for encoding the texture. Will be ignored if a cached texture is used.

format opt : TextureFormat = null

The texture format to use or null to choose one automatically. Will be ignored if a cached texture is used.

returns → IModelTexture

The model texture or null.

Returns the model texture object for the given texture file.

The model texture object for the given texture file in is obtained by the following steps:

  1. The given texture path is resolved (see ResolveTexturePath).

  2. If a model texture object has been specified earlier for the resolved texture path via TextureFileReplace, that object is used (the srgb in parameter is ignored in this case). Otherwise, a new model texture object is created and cached, using the canonical path value as the key.

IOException

An I/O error has occurred while reading the image metadata in order to determine the texture format.

ValidatingException

The image reader has reported an error while reading the image metadata for determining the texture format, for example because of a missing file format feature.

Texture​Name

2 overloads


[Pure]
protected method TextureName1 → (1)

name in : string

The texture name, as found in the 3D model.

returns → string

The model texture name or null iff there is no texture name replacement.

Returns the model texture name replacement for the given texture name.


protected method TextureName2 → (3)

name in : string

The texture name, as found in the 3D model.

srgb in : bool

The ISrgb.Srgb flag to use for encoding the texture.

format opt : TextureFormat = null

The texture format to use or null to choose one automatically.

returns → IModelTexture

The model texture or null if name in is null.

Returns the model texture object for the given texture name.

The model texture object for the given texture name in is obtained by the following steps:

  1. The texture name in is replaced, according to the mappings that have been established earlier via TextureNameReplace. If there is no mapping for name in and it is an absolute path to a non-existent file, it will be replaced with the last path element (i.e. the file name).

  2. The texture name is interpreted as a file path and resolved (see Path.Resolve) using the configured texture path (see TexturePath).

  3. This method delegates to TextureFile2, using the resolved texture path.

IOException

An I/O error has occurred while reading the image metadata in order to determine the texture format.

ValidatingException

The image reader has reported an error while reading the image metadata for determining the texture format, for example because of a missing file format feature.

Configuration

Config


public static attribute Config → (get)

value : IConfigurator<IModelReader>

[not-null]
The configurator object.

The configurator object for this type.

Config​Read​Model​Flags


public static attribute ConfigReadModelFlags → (get)

value : IConfigurator<ReadModelFlags>

[not-null]
The configurator object.

The configurator object for ReadModelFlags values.