X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=blobdiff_plain;f=model_shared.h;h=cf5e02dc1ec4450210fceb52f9767a01ca738caf;hp=8bbd6921a7601a2646c2a8a0a4aed9e077935fea;hb=b12a31a10d99cf06fa6e3b2a098b7af69dec41a6;hpb=5fd2c001d6a6927f57020d24d34cd2fcbc6c439e diff --git a/model_shared.h b/model_shared.h index 8bbd6921..cf5e02dc 100644 --- a/model_shared.h +++ b/model_shared.h @@ -40,7 +40,7 @@ m*_t structures are in-memory */ -typedef enum modtype_e {mod_invalid, mod_brushq1, mod_sprite, mod_alias, mod_brushq2, mod_brushq3, mod_obj, mod_null} modtype_t; +typedef enum modtype_e {mod_invalid, mod_brushq1, mod_sprite, mod_alias, mod_brushq2, mod_brushq3, mod_brushhl2, mod_obj, mod_null} modtype_t; typedef struct animscene_s { @@ -370,33 +370,40 @@ typedef struct msurface_lightmapinfo_s msurface_lightmapinfo_t; struct q3deffect_s; + +/// +/// describes the textures to use on a range of triangles in the model, and mins/maxs (AABB) for culling. +/// typedef struct msurface_s { - // bounding box for onscreen checks - vec3_t mins; - vec3_t maxs; - // the texture to use on the surface + /// range of triangles and vertices in model->surfmesh + int num_triangles; // triangles + int num_firsttriangle; // first element is this *3 + int num_vertices; // length of the range referenced by elements + int num_firstvertex; // min vertex referenced by elements + + /// the texture to use on the surface texture_t *texture; - // the lightmap texture fragment to use on the rendering mesh + /// the lightmap texture fragment to use on the rendering mesh struct rtexture_s *lightmaptexture; - // the lighting direction texture fragment to use on the rendering mesh + /// the lighting direction texture fragment to use on the rendering mesh struct rtexture_s *deluxemaptexture; - // lightmaptexture rebuild information not used in q3bsp - msurface_lightmapinfo_t *lightmapinfo; // q1bsp - // fog volume info in q3bsp - struct q3deffect_s *effect; // q3bsp - // mesh information for collisions (only used by q3bsp curves) - int num_firstcollisiontriangle; - - // surfaces own ranges of vertices and triangles in the model->surfmesh - int num_triangles; // number of triangles - int num_firsttriangle; // first triangle - int num_vertices; // number of vertices - int num_firstvertex; // first vertex - - // mesh information for collisions (only used by q3bsp curves) - int num_collisiontriangles; // q3bsp - int num_collisionvertices; // q3bsp + + // the following fields are used situationally and are not part of rendering in typical usage + + /// bounding box for onscreen checks + vec3_t mins; + vec3_t maxs; + + /// lightmaptexture rebuild information not used in q3bsp + msurface_lightmapinfo_t* lightmapinfo; // q1bsp + /// fog volume info in q3bsp + struct q3deffect_s* effect; // q3bsp + + /// mesh information for collisions (only used by q3bsp curves) + int num_firstcollisiontriangle; // q3bsp only + int num_collisiontriangles; // number of triangles (if surface has collisions enabled) + int num_collisionvertices; // number of vertices referenced by collision triangles (if surface has collisions enabled) // used by Mod_Mesh_Finalize when building sortedmodelsurfaces qbool included; @@ -409,6 +416,7 @@ msurface_t; #include "model_q1bsp.h" #include "model_q2bsp.h" #include "model_q3bsp.h" +#include "model_vbsp.h" #include "model_sprite.h" #include "model_alias.h" @@ -455,10 +463,11 @@ typedef struct model_s animscene_t *skinscenes; // [numskins] // skin animation info animscene_t *animscenes; // [numframes] - // range of surface numbers in this (sub)model - int firstmodelsurface; - int nummodelsurfaces; - int *sortedmodelsurfaces; + // range of surface numbers in this model + int submodelsurfaces_start; + int submodelsurfaces_end; + /// surface indices of model in an optimal draw order (submodelindex -> texture -> lightmap -> index) + int *modelsurfaces_sorted; // same size as num_surfaces // range of collision brush numbers in this (sub)model int firstmodelbrush; int nummodelbrushes; @@ -496,9 +505,9 @@ typedef struct model_s const char *modeldatatypestring; // generates vertex data for a given frameblend void(*AnimateVertices)(const struct model_s * RESTRICT model, const struct frameblend_s * RESTRICT frameblend, const struct skeleton_s *skeleton, float * RESTRICT vertex3f, float * RESTRICT normal3f, float * RESTRICT svector3f, float * RESTRICT tvector3f); - // draw the model's sky polygons (only used by brush models) + // draw the model's sky polygons void(*DrawSky)(struct entity_render_s *ent); - // draw refraction/reflection textures for the model's water polygons (only used by brush models) + // draw refraction/reflection textures for the model's water polygons void(*DrawAddWaterPlanes)(struct entity_render_s *ent); // draw the model using lightmap/dlight shading void(*Draw)(struct entity_render_s *ent); @@ -541,12 +550,12 @@ typedef struct model_s qbool nolerp; } -dp_model_t; +model_t; //============================================================================ // model loading -extern dp_model_t *loadmodel; +extern model_t *loadmodel; extern unsigned char *mod_base; typedef struct modloader_s @@ -554,7 +563,7 @@ typedef struct modloader_s const char *extension; const char *header; size_t headersize; // The header might not be NULL terminated - void (*Load)(dp_model_t *, void *, void *); + void (*Load)(model_t *, void *, void *); } modloader_t; // sky/water subdivision @@ -577,16 +586,16 @@ extern struct cvar_s mod_q3bsp_lightgrid_bsp_surfaces; void Mod_Init (void); void Mod_Reload (void); -dp_model_t *Mod_LoadModel(dp_model_t *mod, qbool crash, qbool checkdisk); -dp_model_t *Mod_FindName (const char *name, const char *parentname); -dp_model_t *Mod_ForName (const char *name, qbool crash, qbool checkdisk, const char *parentname); -void Mod_UnloadModel (dp_model_t *mod); +model_t *Mod_LoadModel(model_t *mod, qbool crash, qbool checkdisk); +model_t *Mod_FindName (const char *name, const char *parentname); +model_t *Mod_ForName (const char *name, qbool crash, qbool checkdisk, const char *parentname); +void Mod_UnloadModel (model_t *mod); void Mod_ClearUsed(void); void Mod_PurgeUnused(void); -void Mod_RemoveStaleWorldModels(dp_model_t *skip); // only used during loading! +void Mod_RemoveStaleWorldModels(model_t *skip); // only used during loading! -extern dp_model_t *loadmodel; +extern model_t *loadmodel; extern char loadname[32]; // for hunk tags int Mod_BuildVertexRemapTableFromElements(int numelements, const int *elements, int numvertices, int *remapvertices); @@ -595,12 +604,17 @@ void Mod_BuildTextureVectorsFromNormals(int firstvertex, int numvertices, int nu qbool Mod_ValidateElements(int *element3i, unsigned short *element3s, int numtriangles, int firstvertex, int numvertices, const char *filename, int fileline); void Mod_AllocSurfMesh(struct mempool_s *mempool, int numvertices, int numtriangles, qbool lightmapoffsets, qbool vertexcolors); -void Mod_MakeSortedSurfaces(dp_model_t *mod); +void Mod_MakeSortedSurfaces(model_t *mod); // called specially by brush model loaders before generating submodels // automatically called after model loader returns void Mod_BuildVBOs(void); +/// Sets the mod->DrawSky and mod->DrawAddWaterPlanes pointers conditionally based on whether surfaces in this submodel use these features +/// called specifically by brush model loaders when generating submodels +/// automatically called after model loader returns +void Mod_SetDrawSkyAndWater(model_t* mod); + shadowmesh_t *Mod_ShadowMesh_Alloc(struct mempool_s *mempool, int maxverts, int maxtriangles); int Mod_ShadowMesh_AddVertex(shadowmesh_t *mesh, const float *vertex3f); void Mod_ShadowMesh_AddMesh(shadowmesh_t *mesh, const float *vertex3f, int numtris, const int *element3i); @@ -609,7 +623,7 @@ shadowmesh_t *Mod_ShadowMesh_Finish(shadowmesh_t *firstmesh, qbool createvbo); void Mod_ShadowMesh_CalcBBox(shadowmesh_t *firstmesh, vec3_t mins, vec3_t maxs, vec3_t center, float *radius); void Mod_ShadowMesh_Free(shadowmesh_t *mesh); -void Mod_CreateCollisionMesh(dp_model_t *mod); +void Mod_CreateCollisionMesh(model_t *mod); void Mod_FreeQ3Shaders(void); void Mod_LoadQ3Shaders(void); @@ -693,34 +707,34 @@ void R_Mod_DrawShadowMap(int side, struct entity_render_s *ent, const vec3_t rel void R_Mod_DrawLight(struct entity_render_s *ent, int numsurfaces, const int *surfacelist, const unsigned char *trispvs); // dynamic mesh building (every frame) for debugging and other uses -void Mod_Mesh_Create(dp_model_t *mod, const char *name); -void Mod_Mesh_Destroy(dp_model_t *mod); -void Mod_Mesh_Reset(dp_model_t *mod); -texture_t *Mod_Mesh_GetTexture(dp_model_t *mod, const char *name, int defaultdrawflags, int defaulttexflags, int defaultmaterialflags); -msurface_t *Mod_Mesh_AddSurface(dp_model_t *mod, texture_t *tex, qbool batchwithprevioussurface); -int Mod_Mesh_IndexForVertex(dp_model_t *mod, msurface_t *surf, float x, float y, float z, float nx, float ny, float nz, float s, float t, float u, float v, float r, float g, float b, float a); -void Mod_Mesh_AddTriangle(dp_model_t *mod, msurface_t *surf, int e0, int e1, int e2); -void Mod_Mesh_Validate(dp_model_t *mod); -void Mod_Mesh_Finalize(dp_model_t *mod); +void Mod_Mesh_Create(model_t *mod, const char *name); +void Mod_Mesh_Destroy(model_t *mod); +void Mod_Mesh_Reset(model_t *mod); +texture_t *Mod_Mesh_GetTexture(model_t *mod, const char *name, int defaultdrawflags, int defaulttexflags, int defaultmaterialflags); +msurface_t *Mod_Mesh_AddSurface(model_t *mod, texture_t *tex, qbool batchwithprevioussurface); +int Mod_Mesh_IndexForVertex(model_t *mod, msurface_t *surf, float x, float y, float z, float nx, float ny, float nz, float s, float t, float u, float v, float r, float g, float b, float a); +void Mod_Mesh_AddTriangle(model_t *mod, msurface_t *surf, int e0, int e1, int e2); +void Mod_Mesh_Validate(model_t *mod); +void Mod_Mesh_Finalize(model_t *mod); // Collision optimization using Bounding Interval Hierarchy -void Mod_CollisionBIH_TracePoint(dp_model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); -void Mod_CollisionBIH_TraceLine(dp_model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); -void Mod_CollisionBIH_TraceBox(dp_model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t boxmins, const vec3_t boxmaxs, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); -void Mod_CollisionBIH_TraceBrush(dp_model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, struct colbrushf_s *start, struct colbrushf_s *end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); -void Mod_CollisionBIH_TracePoint_Mesh(dp_model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); +void Mod_CollisionBIH_TracePoint(model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); +void Mod_CollisionBIH_TraceLine(model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); +void Mod_CollisionBIH_TraceBox(model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, const vec3_t boxmins, const vec3_t boxmaxs, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); +void Mod_CollisionBIH_TraceBrush(model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, struct colbrushf_s *start, struct colbrushf_s *end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); +void Mod_CollisionBIH_TracePoint_Mesh(model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, struct trace_s *trace, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask); qbool Mod_CollisionBIH_TraceLineOfSight(struct model_s *model, const vec3_t start, const vec3_t end, const vec3_t acceptmins, const vec3_t acceptmaxs); int Mod_CollisionBIH_PointSuperContents(struct model_s *model, int frame, const vec3_t point); int Mod_CollisionBIH_PointSuperContents_Mesh(struct model_s *model, int frame, const vec3_t point); -bih_t *Mod_MakeCollisionBIH(dp_model_t *model, qbool userendersurfaces, bih_t *out); +bih_t *Mod_MakeCollisionBIH(model_t *model, qbool userendersurfaces, bih_t *out); // alias models struct frameblend_s; struct skeleton_s; void Mod_AliasInit(void); -int Mod_Alias_GetTagMatrix(const dp_model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, int tagindex, matrix4x4_t *outmatrix); -int Mod_Alias_GetTagIndexForName(const dp_model_t *model, unsigned int skin, const char *tagname); -int Mod_Alias_GetExtendedTagInfoForIndex(const dp_model_t *model, unsigned int skin, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, int tagindex, int *parentindex, const char **tagname, matrix4x4_t *tag_localmatrix); +int Mod_Alias_GetTagMatrix(const model_t *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, int tagindex, matrix4x4_t *outmatrix); +int Mod_Alias_GetTagIndexForName(const model_t *model, unsigned int skin, const char *tagname); +int Mod_Alias_GetExtendedTagInfoForIndex(const model_t *model, unsigned int skin, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, int tagindex, int *parentindex, const char **tagname, matrix4x4_t *tag_localmatrix); void Mod_Skeletal_FreeBuffers(void); @@ -728,22 +742,23 @@ void Mod_Skeletal_FreeBuffers(void); void Mod_SpriteInit(void); // loaders -void Mod_2PSB_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_BSP2_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_HLBSP_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_Q1BSP_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_IBSP_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_MAP_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_OBJ_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_IDP0_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_IDP2_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_IDP3_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_ZYMOTICMODEL_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_DARKPLACESMODEL_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_PSKMODEL_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_IDSP_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_IDS2_Load(dp_model_t *mod, void *buffer, void *bufferend); -void Mod_INTERQUAKEMODEL_Load(dp_model_t *mod, void *buffer, void *bufferend); +void Mod_2PSB_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_BSP2_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_HLBSP_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_Q1BSP_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_IBSP_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_VBSP_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_MAP_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_OBJ_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_IDP0_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_IDP2_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_IDP3_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_ZYMOTICMODEL_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_DARKPLACESMODEL_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_PSKMODEL_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_IDSP_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_IDS2_Load(model_t *mod, void *buffer, void *bufferend); +void Mod_INTERQUAKEMODEL_Load(model_t *mod, void *buffer, void *bufferend); #endif // MODEL_SHARED_H