Model Definition¶
The 3D geometry of a model: its vertices, the triangles between them, and the colour, texture and transparency of each of those.
The cache holds three generations of the format, which TModelDefinition.Create tells apart and decodes.
ModelDefinition.DetectFormat¶
function TModelDefinition.DetectFormat(const data: TByteArray): Integer; static;
Which of the model formats data is in: 0 for the original one, or 2 or 3 for the two
that came after it.
The newer formats mark themselves with a two byte tag at the very end of the buffer. The original one has no tag, so anything without a recognised one is assumed to be it.
ModelDefinition.DecodeOldFormat¶
function TModelDefinition.DecodeOldFormat(id: Integer; const data: TByteArray): TModelDefinition; static;
Decodes a model in the original format. Use TModelDefinition.Create rather than calling this directly.
A model is not stored as one stream but as several parallel ones, and the header at the end of the buffer gives the length of each so that the cursors into them can be positioned before anything is read. Vertices are deltas from the vertex before, and face indices are deltas from the face before, in one of four ways that the compression type per face selects between.
ModelDefinition.DecodeType2¶
function TModelDefinition.DecodeType2(id: Integer; const data: TByteArray): TModelDefinition; static;
Decodes a model in format 2, which adds vertex skinning groups. Use TModelDefinition.Create rather than calling this directly.
It is laid out like the original format - see TModelDefinition.DecodeOldFormat - with the flags in the trailing header rearranged and the animation groups added.
ModelDefinition.DecodeType3¶
function TModelDefinition.DecodeType3(id: Integer; const data: TByteArray): TModelDefinition; static;
Decodes a model in format 3, the current one. Use TModelDefinition.Create rather than calling this directly.
The layout follows TModelDefinition.DecodeType2, with textures given their own stream and their mapping described per texture rather than per face.
ModelDefinition.Create¶
function TModelDefinition.Create(id: Integer; const data: TByteArray): TModelDefinition; static;
Decodes a model’s geometry: its vertices, the triangles between them, and the colour, texture and transparency of each of those.
Which of the three formats to decode is worked out by TModelDefinition.DetectFormat.
ModelDefinition.Recolor¶
procedure TModelDefinition.Recolor(findColor, replaceColor: Integer);
Repaints every face currently coloured findColor.
This is how one model serves many items: the cache stores the recolours an item wants alongside it rather than storing a separate model per colour.
ModelDefinition.Retexture¶
procedure TModelDefinition.Retexture(findTex, replaceTex: Integer);
TModelDefinition.Recolor for textures rather than flat colours.
ModelDefinition.Resize¶
procedure TModelDefinition.Resize(x, y, z: Integer);
Scales the model along each axis, where 128 is its original size.