M2/Rendering a model

From wowdev
Revision as of 21:55, 22 December 2016 by Warpten (talk | contribs) (Created page with "= HIGHLY WIP = When trying to render M2 geometry on screen, there are a few things to remember. Rather than shooting random bits of code at you, this page will explain all th...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

HIGHLY WIP

When trying to render M2 geometry on screen, there are a few things to remember. Rather than shooting random bits of code at you, this page will explain all the process behind rendering M2s. This is all from my own experience. Some things might not be blizzlike, because I'm still learning this, and don't know everything; some things might be plain out wrong, because I don't know how to correctly make it happen. -- Warpten

This is not going to give you a step-by-step detailed way to render geometry and textures on screen. Consider it a general approach to M2 rendering.

All of the below has been done on Legion data files.

Drawing geometry and textures

Geometry is pretty straightforward: just push M2Vertex to the GPU.

As far as textures go, you need to be aware of a few things.

  • Type 0 - the simplest one to implement, since the path to the actual texture is embedded in the model.
  • Type 1 - Can be read from DB/CreatureDisplayInfoExtra
    • For Wrath, you basically have a direct string in that DBC.
    • For Legion, it gets technical.

Since Legion (or was it WoD) introduced HD textures, you have up to two texture FileDataIDs in here. For now, we will keep it simple, and use non-HD texture, since HD textures require parsing of another DBC to only push specifics parts of it to the GPU, one part for each render pass.

  • Type 2 - Cape texture.
  • Type 6 - TEX_COMPONENT_CHAR_HAIR

For this one, you need to use DB/CharSections. GenType is 3, and you need to match gender, hair color, hair style, and race from DB/CreatureDisplayInfoExtra.

  • Type 7 - TEX_COMPONENT_CHAR_FACIAL_HAIR

This one is very similar to type 6, except GenType becomes 2 and you need to match facial hair style, not hair style.

  • Type 8 - TEX_COMPONENT_SKIN_EXTRA

Again, much like 6 and 7, but GenType is 0.

  • Types 11, 12, and 13

These are read from CreatureDisplayInfo.TextureVariation[textureType - 11].

This should cover most uses of textures.