ent_getmesh(ENTITY* ent,var num,var lod);
ent_setmesh(ENTITY* ent,void* mesh,var num,var lod);
Returns or sets the DirectX mesh of the given model or terrain entity.
ent - model or terrain entity pointer, or NULL for level blocks.
num - number of the terrain chunk or level block,
beginning with 0.
lod - number of the lod step for the mesh, 0..3.
mesh - mesh pointer to be set, or NULL when the mesh was released.
LPD3DXMESH cast to void*, or NULL if the entity contains
than the given mesh or lod number.
- When setting the mesh of an entity, the old mesh is automatically
- Meshes can be set only for nonanimated entities.
- The collision shape is automatically updated after ent_setmesh, but the bounding box is unchanged. If desired, set min_x .. max_x manually afterwards.
The mesh vertex format (D3DVERTEX) is described
in the shader
section, and defined in the atypes.h file
in the lite-C
The vertex declaration can be read from the pvertexdecl variable.
The mesh should be created with the D3DXMESH_MANAGED flag.
The vertex buffer of a model mesh contains first the unique vertices of the mesh, then the duplicated vertices that have the same xyz position but different skins or uv positions. Depending on the terrain_lod setting, the vertex buffer of a terrain LOD mesh contains first the vertices of the terrain mesh, then the additional vertices for connecting chunks of different resolution.
For models with internal LOD steps, all LOD meshes must be replaced also if the size of the vertex buffer has changed. The vertex buffer of the LOD meshes must have the same size as the vertex buffer of the main mesh. The vertex buffer content of the LOD meshes is automatically updated after ent_setmesh, but you must set the index and attribute buffers of the LOD meshes to the correct content. Alternatively, disable LOD by setting all LOD meshes to the main mesh pointer.
- You can set a mesh that you've allocated, but you should
then release it yourself at the end of the game (see example).
A mesh allocated in a DLL that was compiled
with a certain DirectX SDK version should be released with the
same DirectX SDK version.
...// set up vertices, triangles, and attributes
// deallocate mesh at end of level or game
pNewMesh = ent_getmesh(my,0,0);