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.
Parameters:
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.
Returns
LPD3DXMESH cast to void*, or NULL if the entity contains
less meshes
than the given mesh or lod number.
Speed:
FastRemarks:
- When setting the mesh of an entity, the old mesh is automatically
released.
- 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
include directory.
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.
Example (lite-C):
#include <d3d9.h>
...
LPD3DXMESH pNewMesh;
D3DXCreateMesh(num_tris,num_verts,D3DXMESH_MANAGED,pvertexdecl,pd3ddev,&pNewMesh);
pNewMesh->LockVertexBuffer(0, &VBuffer);
pNewMesh->LockIndexBuffer(0, &wIndexBuffer);
pNewMesh->LockAttributeBuffer(0, &dwAttribBuffer);
...// set up vertices, triangles, and attributes
pNewMesh->UnlockVertexBuffer();
pNewMesh->UnlockIndexBuffer();
pNewMesh->UnlockAttributeBuffer();
ent_setmesh(my,pNewMesh,0,0);
...
// deallocate mesh at end of level or game
pNewMesh = ent_getmesh(my,0,0);
pNewMesh->Release();
ent_setmesh(my,NULL,0,0);
See also:
ent_status, vec_for_mesh,
ent_getvertex, ent_buffers,
pd3ddev
► latest
version online