| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/lib/polymodel.h $ |
| 21 | * $Revision: 83 $ |
| 22 | * $Date: 7/08/99 5:47p $ |
| 23 | * $Author: Jason $ |
| 24 | * |
| 25 | * Header for polygon model loading funcs |
| 26 | * |
| 27 | * $Log: /DescentIII/Main/lib/polymodel.h $ |
| 28 | * |
| 29 | * 83 7/08/99 5:47p Jason |
| 30 | * changes for new bumpmapping system in 1.1 update patch |
| 31 | * |
| 32 | * 82 6/08/99 1:00p Jason |
| 33 | * changes for bumpmapping |
| 34 | * |
| 35 | * 81 4/09/99 12:06p Jason |
| 36 | * made model setup code faster |
| 37 | * |
| 38 | * 80 1/21/99 11:16p Jeff |
| 39 | * pulled out some structs and defines from header files and moved them |
| 40 | * into seperate header files so that multiplayer dlls don't require major |
| 41 | * game headers, just those new headers. Side effect is a shorter build |
| 42 | * time. Also cleaned up some header file #includes that weren't needed. |
| 43 | * This affected polymodel.h, object.h, player.h, vecmat.h, room.h, |
| 44 | * manage.h and multi.h |
| 45 | * |
| 46 | * 79 1/20/99 5:36p Jason |
| 47 | * added custom glows for teams |
| 48 | * |
| 49 | * 78 1/13/99 12:43p Jason |
| 50 | * added some more detail settings |
| 51 | * |
| 52 | * 77 1/07/99 5:01p Keneta |
| 53 | * added more polymodel slots |
| 54 | * |
| 55 | * 76 11/30/98 3:59p Jason |
| 56 | * changed dynamic lighting to be better |
| 57 | * |
| 58 | * 75 10/12/98 9:30a Jason |
| 59 | * new polymodel memory scheme |
| 60 | * |
| 61 | * 74 10/07/98 5:07p Jason |
| 62 | * added new polymodel effect type |
| 63 | * |
| 64 | * 73 10/07/98 3:40p Chris |
| 65 | * Added $thruster |
| 66 | * |
| 67 | * 72 9/09/98 7:09p Jason |
| 68 | * changed afterburner effect for ships |
| 69 | * |
| 70 | * 71 8/31/98 1:35p Keneta |
| 71 | * Made some use count unsigned shorts |
| 72 | * |
| 73 | * 70 8/24/98 1:01p Jason |
| 74 | * made object specular faces selectable by texture |
| 75 | * |
| 76 | * 69 8/21/98 5:14p Jason |
| 77 | * made better memory use of primitives |
| 78 | * |
| 79 | * 68 8/18/98 11:38a Jason |
| 80 | * fixed polymodel fog lighting |
| 81 | * |
| 82 | * 67 8/18/98 11:26a Matt |
| 83 | * Changed outline code to only outline polymodel objects when they're |
| 84 | * being rendered in the mine, and not when they're being drawn in the |
| 85 | * editor, main menu, cockpit, etc. |
| 86 | * |
| 87 | * 66 8/14/98 4:00p Jason |
| 88 | * added specular objects outside |
| 89 | * |
| 90 | * 65 8/13/98 6:56p Jason |
| 91 | * made objects foggable correctly |
| 92 | * |
| 93 | * 64 8/12/98 12:04p Chris |
| 94 | * Attach system version .5 (still needs more work to be multiplayer |
| 95 | * friendly) |
| 96 | * |
| 97 | * 63 8/04/98 2:32p Chris |
| 98 | * Improved attach code added more fixes to the AABB partial computation |
| 99 | * patch |
| 100 | * |
| 101 | * 62 7/29/98 5:05p Chris |
| 102 | * Made more of the wb info dynamically allocated. Added Attach points to |
| 103 | * the polymodel structure |
| 104 | * |
| 105 | * 61 7/27/98 10:39a Jason |
| 106 | * added customizable skins |
| 107 | * |
| 108 | * 60 6/22/98 7:31p Samir |
| 109 | * added mask for monitors. |
| 110 | * |
| 111 | * 59 6/15/98 4:00p Jason |
| 112 | * replaced monochromatic polymodel lighting with rgb lighting |
| 113 | * |
| 114 | * 58 5/13/98 12:06p Jason |
| 115 | * trimmed some memory usage |
| 116 | * |
| 117 | * 57 4/30/98 12:22p Jason |
| 118 | * did some lo-res model optimizations |
| 119 | * |
| 120 | * 56 4/30/98 11:32a Chris |
| 121 | * ClearWB to WBClear |
| 122 | * |
| 123 | * 55 4/17/98 12:45p Jason |
| 124 | * various changes for multiplayer |
| 125 | * |
| 126 | * 54 4/15/98 3:28p Jason |
| 127 | * changed glow stuff to work with new system |
| 128 | * |
| 129 | * 53 4/07/98 6:22p Samir |
| 130 | * restored a couple of variables to the poly_model array that were used |
| 131 | * elsewhere in the code. left out the nasty one though. |
| 132 | * |
| 133 | * 52 4/07/98 5:59p Jason |
| 134 | * saved about 15 megs of storage by deleting an unused array |
| 135 | * |
| 136 | * 51 4/06/98 3:03p Jason |
| 137 | * added polygon rendering overlays |
| 138 | * |
| 139 | * 50 4/03/98 1:13p Jason |
| 140 | * shaved off a few more bytes from the polyface structure |
| 141 | * |
| 142 | * 49 4/03/98 10:07a Chris |
| 143 | * Added support for objects getting their size computed when the |
| 144 | * polymodel is paged in the first time as an object |
| 145 | * |
| 146 | * 48 4/02/98 3:54p Jason |
| 147 | * first pass in getting polymodel paging to work |
| 148 | * |
| 149 | * 47 4/02/98 12:22p Jason |
| 150 | * changes for deformation effect |
| 151 | * |
| 152 | * 46 4/01/98 6:23p Jason |
| 153 | * added a slew of stuff for multiplayer |
| 154 | * |
| 155 | * 45 3/31/98 11:12a Brent |
| 156 | * upped number of textures for the undisciplined bastard know as BRENT |
| 157 | * |
| 158 | * 44 3/29/98 11:58p Jason |
| 159 | * saved some memory with object lightmaps |
| 160 | * |
| 161 | * 43 3/26/98 2:14p Jason |
| 162 | * added dynamic lighting for objects |
| 163 | * |
| 164 | * 42 3/24/98 5:16p Jason |
| 165 | * upped polyvecs for that fucker brent |
| 166 | * |
| 167 | * 41 3/23/98 10:03a Chris |
| 168 | * Added independant wb animations |
| 169 | * |
| 170 | * 40 3/19/98 4:30p Samir |
| 171 | * added ability to mark subobjects as layered. |
| 172 | * |
| 173 | * 39 3/18/98 6:24p Samir |
| 174 | * Fixed some bugs with normalizing MONITORs and added VIEWER flag. |
| 175 | * |
| 176 | * 38 3/16/98 3:47p Jason |
| 177 | * got rid of circular dependencies for objects and polymodels |
| 178 | * |
| 179 | * 37 3/16/98 3:24p Chris |
| 180 | * Removed my the object.h dependancy |
| 181 | * |
| 182 | * 36 3/16/98 11:34a Chris |
| 183 | * Polymodels have 3 levels of AABB (object, subobject, and face level) |
| 184 | * |
| 185 | * 35 3/13/98 5:55p Chris |
| 186 | * Added the new collision spheres |
| 187 | * |
| 188 | * 34 3/11/98 4:59p Chris |
| 189 | * Added a few new sphere types (wall and anim) |
| 190 | * |
| 191 | * 33 3/10/98 6:54p Chris |
| 192 | * All start and end frame for ComputeDefaultSize |
| 193 | * |
| 194 | * 32 2/17/98 12:19p Jason |
| 195 | * upped max polymodel count to 500 |
| 196 | * |
| 197 | * 31 2/16/98 2:49p Chris |
| 198 | * Made the MAX_SUBOBJECTS determine the number of normalized_time values |
| 199 | * to be processed. No longer a 'literal' problem. |
| 200 | * |
| 201 | * 30 2/16/98 2:12p Jason |
| 202 | * fixed bug with lightmaps and door shells |
| 203 | * |
| 204 | * 29 2/13/98 12:44p Jason |
| 205 | * upped max number of subobjects |
| 206 | * |
| 207 | * 28 2/04/98 9:28p Jason |
| 208 | * added some new weapons effects |
| 209 | * |
| 210 | * 27 1/13/98 3:09p Jason |
| 211 | * added glow effect for engines |
| 212 | * |
| 213 | * 26 12/31/97 3:34p Jason |
| 214 | * added alpha per vertex for polymodels |
| 215 | * |
| 216 | * 25 11/17/97 6:28p Mark |
| 217 | * FROM Jason:fixed memory leak |
| 218 | * |
| 219 | * 24 11/06/97 4:18p Samir |
| 220 | * texture numbers are now shorts in polymodel |
| 221 | * |
| 222 | * 23 11/04/97 4:58p Samir |
| 223 | * Added 4 more monitors. |
| 224 | * |
| 225 | * 22 10/28/97 6:37p Samir |
| 226 | * Submodels now can be monitors. |
| 227 | * |
| 228 | * 21 10/23/97 2:07p Jason |
| 229 | * fixed some problems with debris not spinning about their center point |
| 230 | * |
| 231 | * 20 10/01/97 7:00p Jason |
| 232 | * did more work on object lightmaps |
| 233 | * |
| 234 | * 19 9/30/97 6:40p Jason |
| 235 | * got lightmap stuff sort of working with objects |
| 236 | * |
| 237 | * 18 9/26/97 12:09p Jason |
| 238 | * made positional/rotational animations have differing |
| 239 | * track_min/track_max |
| 240 | * |
| 241 | * 17 9/25/97 4:54p Jason |
| 242 | * added timer info to polymodels |
| 243 | * |
| 244 | * 16 9/17/97 10:59a Chris |
| 245 | * Added a new way to compute radi |
| 246 | * |
| 247 | * 15 9/11/97 5:38p Jason |
| 248 | * initial door coding for room engine |
| 249 | * |
| 250 | * 14 9/10/97 5:36p Jason |
| 251 | * changed version number for new oofs |
| 252 | * |
| 253 | * 13 9/10/97 5:17p Jason |
| 254 | * more lighting improvements |
| 255 | * |
| 256 | * 12 9/09/97 6:15p Jason |
| 257 | * made dynamic lighting on objects more memory efficient |
| 258 | * |
| 259 | * 11 9/04/97 3:49p Chris |
| 260 | * Added additional turret information from pofgen, added ground plane |
| 261 | * stuff |
| 262 | * |
| 263 | * 10 9/03/97 4:11p Chris |
| 264 | * Moved some code so that pofview will compile |
| 265 | * |
| 266 | * 9 9/03/97 2:12p Chris |
| 267 | * Added new weapon battery system and made the animation system usable. |
| 268 | * |
| 269 | * 8 8/25/97 6:19p Chris |
| 270 | * Added support for knowing which subobject a gun point is linked to |
| 271 | * |
| 272 | * 7 8/20/97 3:16p Chris |
| 273 | * Added some hooks for turrets |
| 274 | * |
| 275 | * 6 8/03/97 2:25p Jason |
| 276 | * made polymodels use less memory |
| 277 | * |
| 278 | * 5 7/28/97 1:16p Chris |
| 279 | * |
| 280 | * 4 7/23/97 11:48a Jason |
| 281 | * added support for newstyle pof format |
| 282 | * |
| 283 | * 3 7/22/97 1:34a Jason |
| 284 | * added code to support newstyle polymodels |
| 285 | * |
| 286 | * 18 6/24/97 6:13p Matt |
| 287 | * Got rid of DrawPolygonObject(), since it required the inclusion of |
| 288 | * object.h, which is a main directory header file (& thus shouldn't be |
| 289 | * accessible by a library). |
| 290 | * |
| 291 | * $NoKeywords: $ |
| 292 | */ |
| 293 | |
| 294 | #ifndef POLYMODEL_H |
| 295 | #define POLYMODEL_H |
| 296 | |
| 297 | #include <cstdint> |
| 298 | #include <filesystem> |
| 299 | |
| 300 | #include "3d.h" |
| 301 | #include "object_external_struct.h" |
| 302 | #include "polymodel_external.h" |
| 303 | #include "vecmat.h" |
| 304 | |
| 305 | #define PM_COMPATIBLE_VERSION 1807 |
| 306 | #define PM_OBJFILE_VERSION 2300 |
| 307 | |
| 308 | #define WB_INDEX_SHIFT 16 // bits to shift over to get the weapon battery index (after masking out flags) |
| 309 | #define SOF_WB_MASKS 0x01F0000 // Room for 32 weapon batteries (currently we only use 21 slots) |
| 310 | |
| 311 | #define SOF_MONITOR_MASK 0x0ff0 // mask for monitors |
| 312 | |
| 313 | extern int Num_poly_models; |
| 314 | extern poly_model Poly_models[]; |
| 315 | |
| 316 | extern int Polymodel_use_effect; |
| 317 | extern polymodel_effect Polymodel_effect; |
| 318 | extern polymodel_light_type Polymodel_light_type; |
| 319 | extern float Polylighting_static_red; |
| 320 | extern float Polylighting_static_green; |
| 321 | extern float Polylighting_static_blue; |
| 322 | extern vector *Polymodel_light_direction, Polymodel_fog_portal_vert, Polymodel_fog_plane, Polymodel_specular_pos, |
| 323 | Polymodel_bump_pos; |
| 324 | extern lightmap_object *Polylighting_lightmap_object; |
| 325 | |
| 326 | extern vector Interp_pos_instance_vec; |
| 327 | extern g3Point Robot_points[]; |
| 328 | |
| 329 | // Flag to draw an outline around the faces |
| 330 | extern bool Polymodel_outline_mode; |
| 331 | |
| 332 | // given a filename, reads in a POF and returns an index into the Poly_models array |
| 333 | // returns -1 if something is wrong |
| 334 | int LoadPolyModel(const std::filesystem::path &filename, int pageable); |
| 335 | |
| 336 | // gets the filename from a path, plus appends our .pof extension |
| 337 | std::filesystem::path ChangePolyModelName(const std::filesystem::path &src); |
| 338 | |
| 339 | // Searches through all polymodels for a specific name, returns -1 if not found |
| 340 | // or index of polymodel with name |
| 341 | int FindPolyModelName(const std::filesystem::path &name); |
| 342 | |
| 343 | // Draws a polygon model to the viewport |
| 344 | // Normalized_time is an array of floats from 0 to 1 that represent how far into |
| 345 | // an animation state we are |
| 346 | |
| 347 | // This one is for static lighting - ie 1 light value for the entire model |
| 348 | void DrawPolygonModel(vector *pos, matrix *orient, int model_num, float *normalized_time, int flags, float r, float g, |
| 349 | float b, uint32_t f_render_sub = 0xFFFFFFFF, uint8_t use_effect = 0, uint8_t overlay = 0); |
| 350 | |
| 351 | // This one is for gouraud shading - the lightdir is the normalized light direction, and lightscalar is a 0-1 scalar to |
| 352 | // apply |
| 353 | void DrawPolygonModel(vector *pos, matrix *orient, int model_num, float *normalized_time, int flags, vector *lightdir, |
| 354 | float r, float g, float b, uint32_t f_render_sub = 0xFFFFFFFF, uint8_t use_effect = 0, |
| 355 | uint8_t overlay = 0); |
| 356 | |
| 357 | // This one is for lightmap rendering |
| 358 | void DrawPolygonModel(vector *pos, matrix *orient, int model_num, float *normalized_time, int flags, |
| 359 | lightmap_object *lm_object, uint32_t f_render_sub, uint8_t use_effect = 0, uint8_t overlay = 0); |
| 360 | |
| 361 | // Inits our models array |
| 362 | int InitModels(); |
| 363 | |
| 364 | // Frees polymodel located in index of Poly_models array |
| 365 | void FreePolyModel(int index); |
| 366 | |
| 367 | // Given an actual keyframe number, returns the normalized (0 to 1) position of that |
| 368 | // keyframe. Handle is an index into the Poly_models array |
| 369 | float GetNormalizedKeyframe(int handle, float num); |
| 370 | |
| 371 | // Goes through all poly models and gets all missing textures |
| 372 | void RemapPolyModels(); |
| 373 | |
| 374 | // Sets a positional instance |
| 375 | void StartPolyModelPosInstance(vector *posvec); |
| 376 | |
| 377 | // Pops a positional instance |
| 378 | void DonePolyModelPosInstance(); |
| 379 | |
| 380 | void SetModelAngles(poly_model *po, const float *normalized_angles); |
| 381 | void SetModelInterpPos(poly_model *po, const float *normalized_pos); |
| 382 | |
| 383 | void SetNormalizedTimeObj(object *obj, float *normalized_time); |
| 384 | void SetNormalizedTimeAnim(float norm_anim_frame, float *normalized_time, poly_model *pm); |
| 385 | |
| 386 | void WBClearInfo(poly_model *pm); |
| 387 | |
| 388 | // Computes the size of a polymodel. |
| 389 | float ComputeDefaultSize(int type, int handle, float *size_ptr); |
| 390 | |
| 391 | // Returns the total number of faces in a model |
| 392 | int CountFacesInPolymodel(poly_model *pm); |
| 393 | |
| 394 | // Rendering functions |
| 395 | int RenderPolygonModel(poly_model *, uint32_t f_render_sub = 0xFFFFFFFF); |
| 396 | void RenderSubmodel(poly_model *pm, bsp_info *sm, uint32_t f_render_sub); |
| 397 | |
| 398 | // returns point within polymodel/submodel in world coordinates. |
| 399 | void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix *orient, int subnum, vector *pos, |
| 400 | vector *norm = nullptr); |
| 401 | void GetPolyModelPointInWorld(vector *dest, poly_model *pm, vector *wpos, matrix *orient, int subnum, |
| 402 | float *normalized_time, vector *pos, vector *norm = nullptr); |
| 403 | |
| 404 | // Returns 1 if this submodel shouldn't be rendered |
| 405 | int IsNonRenderableSubmodel(poly_model *pm, int submodelnum); |
| 406 | |
| 407 | // Sets the effect used by a polymodel |
| 408 | void SetPolymodelEffect(polymodel_effect *); |
| 409 | |
| 410 | // Pages in a polymodel if its not already in memory |
| 411 | void PageInPolymodel(int polynum, int type = -1, float *size_ptr = nullptr); |
| 412 | |
| 413 | // Gets a pointer to a polymodel. Pages it in if neccessary |
| 414 | poly_model *GetPolymodelPointer(int polynum); |
| 415 | |
| 416 | // Frees all the polymodel data, but doesn't free the actual polymodel itself |
| 417 | void FreePolymodelData(int i); |
| 418 | |
| 419 | // Sets the position and rotation of a polymodel. Used for rendering and collision detection |
| 420 | void SetModelAnglesAndPos(poly_model *po, float *normalized_time, uint32_t subobj_flags = 0xFFFFFFFF); |
| 421 | |
| 422 | extern void DoneLightInstance(); |
| 423 | extern void StartLightInstance(vector *, matrix *); |
| 424 | |
| 425 | #endif |