Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1932 lines
44 KiB

  1. //===== Copyright � 1996-2008, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #ifndef STUDIOMDL_H
  9. #define STUDIOMDL_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include <stdio.h>
  14. #include "basetypes.h"
  15. #include "tier1/utlvector.h"
  16. #include "tier1/utlsymbol.h"
  17. #include "tier1/utlstring.h"
  18. #include "mathlib/vector.h"
  19. #include "studio.h"
  20. #include "datamodel/dmelementhandle.h"
  21. struct LodScriptData_t;
  22. struct s_flexkey_t;
  23. struct s_flexcontroller_t;
  24. struct s_flexcontrollerremap_t;
  25. struct s_combinationrule_t;
  26. struct s_combinationcontrol_t;
  27. class CDmeVertexDeltaData;
  28. class CDmeCombinationOperator;
  29. #ifdef MDLCOMPILE
  30. #define SRC_FILE_EXT ".mc"
  31. #define MC_CURRENT_VERSION 1
  32. #else
  33. #define SRC_FILE_EXT ".qc"
  34. #define MC_CURRENT_VERSION 0
  35. #endif
  36. #define IDSTUDIOHEADER (('T'<<24)+('S'<<16)+('D'<<8)+'I')
  37. // little-endian "IDST"
  38. #define IDSTUDIOANIMGROUPHEADER (('G'<<24)+('A'<<16)+('D'<<8)+'I')
  39. // little-endian "IDAG"
  40. #define STUDIO_QUADRATIC_MOTION 0x00002000
  41. #define MAXSTUDIOANIMFRAMES 5000 // max frames per animation
  42. // [mlowrance] updated total number of animations to give more headroom for new weapons
  43. // bumped up from 2k to 3k
  44. #define MAXSTUDIOANIMS 3000 // total animations
  45. #define MAXSTUDIOSEQUENCES 1524 // total sequences
  46. #define MAXSTUDIOSRCBONES 1024 // bones allowed at source movement
  47. #define MAXSTUDIOTEXCOORDS 8
  48. #define MAXSTUDIOMESHES 256
  49. #define MAXSTUDIOEVENTS 1024
  50. #define MAXSTUDIOFLEXKEYS 512
  51. #define MAXSTUDIOFLEXRULES 1024
  52. #define MAXSTUDIOBONEWEIGHTS 3
  53. #define MAXSTUDIOCMDS 64
  54. #define MAXSTUDIOMOVEKEYS 64
  55. #define MAXSTUDIOIKRULES 64
  56. #define MAXSTUDIONAME 128
  57. #define MAXSTUDIOACTIVITYMODIFIERS 128
  58. #define MAXSTUDIOTAGS 1024
  59. #define MAXSTUDIOSRCVERTS (8*65536)
  60. #ifndef EXTERN
  61. #define EXTERN extern
  62. #endif
  63. EXTERN char g_outname[MAX_PATH];
  64. EXTERN char g_szInternalName[MAX_PATH];
  65. EXTERN qboolean cdset;
  66. EXTERN int numdirs;
  67. EXTERN char cddir[32][MAX_PATH];
  68. EXTERN int numcdtextures;
  69. EXTERN char * cdtextures[16];
  70. EXTERN char g_fullpath[MAX_PATH];
  71. EXTERN char rootname[MAXSTUDIONAME]; // name of the root bone
  72. EXTERN float g_defaultscale;
  73. EXTERN float g_currentscale;
  74. EXTERN RadianEuler g_defaultrotation;
  75. EXTERN char defaulttexture[16][MAX_PATH];
  76. EXTERN char sourcetexture[16][MAX_PATH];
  77. EXTERN int numrep;
  78. EXTERN int tag_reversed;
  79. EXTERN int tag_normals;
  80. EXTERN float normal_blend;
  81. EXTERN int dump_hboxes;
  82. EXTERN int ignore_warnings;
  83. EXTERN Vector eyeposition;
  84. EXTERN float g_flMaxEyeDeflection;
  85. EXTERN int g_illumpositionattachment;
  86. EXTERN Vector illumposition;
  87. EXTERN int illumpositionset;
  88. EXTERN int gflags;
  89. EXTERN Vector bbox[2];
  90. EXTERN Vector cbox[2];
  91. EXTERN bool g_wrotebbox;
  92. EXTERN bool g_wrotecbox;
  93. EXTERN bool g_bboxonlyverts;
  94. EXTERN int clip_texcoords;
  95. EXTERN bool g_staticprop;
  96. EXTERN bool g_centerstaticprop;
  97. EXTERN bool g_realignbones;
  98. EXTERN bool g_definebones;
  99. EXTERN bool g_bSkinnedLODs;
  100. EXTERN byte g_constdirectionalightdot;
  101. // Methods associated with the key value text block
  102. extern CUtlVector< char > g_KeyValueText;
  103. int KeyValueTextSize( CUtlVector< char > *pKeyValue );
  104. const char *KeyValueText( CUtlVector< char > *pKeyValue );
  105. extern vec_t Q_rint (vec_t in);
  106. extern void WriteModelFiles(void);
  107. // --------------------------------------------------------------------
  108. template< class T >
  109. class CUtlVectorAuto : public CUtlVector< T >
  110. {
  111. // typedef CUtlVectorAuto< T, CUtlVector<T > > BaseClass;
  112. public:
  113. T& operator[]( int i );
  114. };
  115. template< typename T >
  116. inline T& CUtlVectorAuto<T>::operator[]( int i )
  117. {
  118. EnsureCount( i + 1 );
  119. Assert( IsValidIndex(i) );
  120. return Base()[i];
  121. }
  122. //////////////////////////////////////////////////////////////////////////
  123. // Purpose: contains settings specified in gameinfo.txt
  124. //////////////////////////////////////////////////////////////////////////
  125. struct GameInfo_t
  126. {
  127. bool bSupportsXBox360;
  128. bool bSupportsDX8;
  129. };
  130. extern struct GameInfo_t g_gameinfo;
  131. // --------------------------------------------------------------------
  132. struct s_trianglevert_t
  133. {
  134. int vertindex;
  135. int normindex; // index into normal array
  136. int s,t;
  137. float u,v;
  138. };
  139. struct s_boneweight_t
  140. {
  141. int numbones;
  142. int bone[MAXSTUDIOBONEWEIGHTS];
  143. float weight[MAXSTUDIOBONEWEIGHTS];
  144. };
  145. struct s_tmpface_t
  146. {
  147. int material;
  148. unsigned long a, b, c, d; //
  149. unsigned long na, nb, nc, nd; //
  150. unsigned long ta[MAXSTUDIOTEXCOORDS];
  151. unsigned long tb[MAXSTUDIOTEXCOORDS];
  152. unsigned long tc[MAXSTUDIOTEXCOORDS];
  153. unsigned long td[MAXSTUDIOTEXCOORDS]; // d used by subd quads, otherwise 0xFFFFFFFF
  154. s_tmpface_t(){
  155. a = b = c = d = 0xFFFFFFFF; na = nb = nc = nd = 0xFFFFFFFF;
  156. for ( int i = 0; i < MAXSTUDIOTEXCOORDS; ++i ) { ta[i] = tb[i] = tc[i] = td[i] = 0xFFFFFFFF; }
  157. }
  158. };
  159. struct s_face_t
  160. {
  161. s_face_t(){ a = b = c = d = 0xFFFFFFFF; }
  162. unsigned long a, b, c, d; // d used by subd quads
  163. };
  164. struct s_vertexinfo_t
  165. {
  166. int material;
  167. int mesh;
  168. Vector position;
  169. Vector normal;
  170. Vector4D tangentS;
  171. int numTexcoord;
  172. Vector2D texcoord[MAXSTUDIOTEXCOORDS];
  173. s_boneweight_t boneweight;
  174. };
  175. //============================================================================
  176. // dstudiobone_t bone[MAXSTUDIOBONES];
  177. struct s_bonefixup_t
  178. {
  179. matrix3x4_t m;
  180. };
  181. EXTERN int g_numbones;
  182. struct s_bonetable_t
  183. {
  184. char name[MAXSTUDIONAME]; // bone name for symbolic links
  185. int parent; // parent bone
  186. bool split;
  187. int bonecontroller; // -1 == 0
  188. Vector pos; // default pos
  189. Vector posscale; // pos values scale
  190. RadianEuler rot; // default pos
  191. Vector rotscale; // rotation values scale
  192. int group; // hitgroup
  193. Vector bmin, bmax; // bounding box
  194. bool bPreDefined;
  195. matrix3x4_t rawLocalOriginal; // original transform of preDefined bone
  196. matrix3x4_t rawLocal;
  197. matrix3x4_t srcRealign;
  198. bool bPreAligned;
  199. matrix3x4_t boneToPose;
  200. int flags;
  201. int proceduralindex;
  202. int physicsBoneIndex;
  203. int surfacePropIndex;
  204. Quaternion qAlignment;
  205. bool bDontCollapse;
  206. Vector posrange;
  207. };
  208. EXTERN s_bonetable_t g_bonetable[MAXSTUDIOSRCBONES];
  209. extern int findGlobalBone( const char *name ); // finds a named bone in the global bone table
  210. EXTERN int g_numrenamedbones;
  211. struct s_renamebone_t
  212. {
  213. char from[MAXSTUDIONAME];
  214. char to[MAXSTUDIONAME];
  215. };
  216. EXTERN s_renamebone_t g_renamedbone[MAXSTUDIOSRCBONES];
  217. const char *RenameBone( const char *pName ); // returns new name if available, else return pName.
  218. EXTERN char g_szStripBonePrefix[MAXSTUDIOSRCBONES][MAXSTUDIONAME];
  219. EXTERN int g_numStripBonePrefixes;
  220. EXTERN s_renamebone_t g_szRenameBoneSubstr[MAXSTUDIOSRCBONES];
  221. EXTERN int g_numRenameBoneSubstr;
  222. EXTERN int g_numimportbones;
  223. struct s_importbone_t
  224. {
  225. char name[MAXSTUDIONAME];
  226. char parent[MAXSTUDIONAME];
  227. matrix3x4_t rawLocal;
  228. bool bPreAligned;
  229. matrix3x4_t srcRealign;
  230. bool bUnlocked;
  231. };
  232. EXTERN s_importbone_t g_importbone[MAXSTUDIOSRCBONES];
  233. EXTERN int g_numincludemodels;
  234. struct s_includemodel_t
  235. {
  236. char name[MAXSTUDIONAME];
  237. };
  238. EXTERN s_includemodel_t g_includemodel[128];
  239. struct s_bbox_t
  240. {
  241. char name[MAXSTUDIONAME]; // bone name
  242. char hitboxname[MAXSTUDIONAME]; // hitbox name
  243. int bone;
  244. int group; // hitgroup
  245. int model;
  246. Vector bmin, bmax; // bounding box
  247. QAngle angOffsetOrientation;
  248. float flCapsuleRadius;
  249. };
  250. #define MAXSTUDIOHITBOXSETNAME 64
  251. struct s_hitboxset
  252. {
  253. char hitboxsetname[ MAXSTUDIOHITBOXSETNAME ];
  254. int numhitboxes;
  255. s_bbox_t hitbox[MAXSTUDIOSRCBONES];
  256. };
  257. extern CUtlVector< s_hitboxset > g_hitboxsets;
  258. EXTERN int g_numhitgroups;
  259. struct s_hitgroup_t
  260. {
  261. int models;
  262. int group;
  263. char name[MAXSTUDIONAME]; // bone name
  264. };
  265. EXTERN s_hitgroup_t g_hitgroup[MAXSTUDIOSRCBONES];
  266. struct s_bonecontroller_t
  267. {
  268. char name[MAXSTUDIONAME];
  269. int bone;
  270. int type;
  271. int inputfield;
  272. float start;
  273. float end;
  274. };
  275. EXTERN s_bonecontroller_t g_bonecontroller[MAXSTUDIOSRCBONES];
  276. EXTERN int g_numbonecontrollers;
  277. struct s_screenalignedbone_t
  278. {
  279. char name[MAXSTUDIONAME];
  280. int flags;
  281. };
  282. EXTERN s_screenalignedbone_t g_screenalignedbone[MAXSTUDIOSRCBONES];
  283. EXTERN int g_numscreenalignedbones;
  284. struct s_worldalignedbone_t
  285. {
  286. char name[MAXSTUDIONAME];
  287. int flags;
  288. };
  289. EXTERN s_worldalignedbone_t g_worldalignedbone[MAXSTUDIOSRCBONES];
  290. EXTERN int g_numworldalignedbones;
  291. struct s_attachment_t
  292. {
  293. char name[MAXSTUDIONAME];
  294. char bonename[MAXSTUDIONAME];
  295. int bone;
  296. int type;
  297. int flags;
  298. matrix3x4_t local;
  299. bool operator==( const s_attachment_t &rhs ) const;
  300. };
  301. #define IS_ABSOLUTE 0x0001
  302. #define IS_RIGID 0x0002
  303. EXTERN s_attachment_t g_attachment[MAXSTUDIOSRCBONES];
  304. EXTERN int g_numattachments;
  305. struct s_bonemerge_t
  306. {
  307. char bonename[MAXSTUDIONAME];
  308. };
  309. EXTERN CUtlVector< s_bonemerge_t > g_BoneMerge;
  310. struct s_alwayssetup_t
  311. {
  312. char bonename[MAXSTUDIONAME];
  313. };
  314. EXTERN CUtlVector< s_alwayssetup_t > g_BoneAlwaysSetup;
  315. struct s_mouth_t
  316. {
  317. char bonename[MAXSTUDIONAME];
  318. int bone;
  319. Vector forward;
  320. int flexdesc;
  321. };
  322. EXTERN s_mouth_t g_mouth[MAXSTUDIOSRCBONES]; // ?? skins?
  323. EXTERN int g_nummouths;
  324. struct s_node_t
  325. {
  326. char name[MAXSTUDIONAME];
  327. int parent;
  328. };
  329. struct s_bone_t
  330. {
  331. Vector pos;
  332. RadianEuler rot;
  333. };
  334. struct s_linearmove_t
  335. {
  336. int endframe; // frame when pos, rot is valid.
  337. int flags; // type of motion. Only linear, linear accel, and linear decel is allowed
  338. float v0;
  339. float v1;
  340. Vector vector; // movement vector
  341. Vector pos; // final position
  342. RadianEuler rot; // final rotation
  343. };
  344. #define CMD_WEIGHTS 1
  345. #define CMD_SUBTRACT 2
  346. #define CMD_AO 3
  347. #define CMD_MATCH 4
  348. #define CMD_FIXUP 5
  349. #define CMD_ANGLE 6
  350. #define CMD_IKFIXUP 7
  351. #define CMD_IKRULE 8
  352. #define CMD_MOTION 9
  353. #define CMD_REFMOTION 10
  354. #define CMD_DERIVATIVE 11
  355. #define CMD_NOANIMATION 12
  356. #define CMD_LINEARDELTA 13
  357. #define CMD_SPLINEDELTA 14
  358. #define CMD_COMPRESS 15
  359. #define CMD_NUMFRAMES 16
  360. #define CMD_COUNTERROTATE 17
  361. #define CMD_SETBONE 18
  362. #define CMD_WORLDSPACEBLEND 19
  363. #define CMD_MATCHBLEND 20
  364. #define CMD_LOCALHIERARCHY 21
  365. #define CMD_FORCEBONEPOSROT 22
  366. #define CMD_REVERSE 23
  367. #define CMD_APPENDANIM 24
  368. #define CMD_BONEDRIVER 25
  369. #define CMD_NOANIM_KEEPDURATION 26
  370. struct s_animation_t;
  371. struct s_ikrule_t;
  372. struct s_motion_t
  373. {
  374. int motiontype;
  375. int iStartFrame;// starting frame to apply motion over
  376. int iEndFrame; // end frame to apply motion over
  377. int iSrcFrame; // frame that matches the "reference" animation
  378. s_animation_t *pRefAnim; // animation to match
  379. int iRefFrame; // reference animation's frame to match
  380. };
  381. struct s_animcmd_t
  382. {
  383. int cmd;
  384. union
  385. {
  386. struct
  387. {
  388. int index;
  389. } weightlist;
  390. struct
  391. {
  392. s_animation_t *ref;
  393. int frame;
  394. int flags;
  395. } subtract;
  396. struct
  397. {
  398. s_animation_t *ref;
  399. int motiontype;
  400. int srcframe;
  401. int destframe;
  402. char *pBonename;
  403. } ao;
  404. struct
  405. {
  406. s_animation_t *ref;
  407. int srcframe;
  408. int destframe;
  409. int destpre;
  410. int destpost;
  411. } match;
  412. struct
  413. {
  414. s_animation_t *ref;
  415. int startframe;
  416. int loops;
  417. } world;
  418. struct
  419. {
  420. int start;
  421. int end;
  422. } fixuploop;
  423. struct
  424. {
  425. float angle;
  426. } angle;
  427. struct
  428. {
  429. s_ikrule_t *pRule;
  430. } ikfixup;
  431. struct
  432. {
  433. s_ikrule_t *pRule;
  434. } ikrule;
  435. struct
  436. {
  437. float scale;
  438. } derivative;
  439. struct
  440. {
  441. int flags;
  442. } linear;
  443. struct
  444. {
  445. int frames;
  446. } compress;
  447. struct
  448. {
  449. int frames;
  450. } numframes;
  451. struct
  452. {
  453. char *pBonename;
  454. bool bHasTarget;
  455. float targetAngle[3];
  456. } counterrotate;
  457. struct
  458. {
  459. char *pBonename;
  460. char *pParentname;
  461. int start;
  462. int peak;
  463. int tail;
  464. int end;
  465. } localhierarchy;
  466. struct
  467. {
  468. char *pBonename;
  469. bool bDoPos;
  470. float pos[3];
  471. bool bDoRot;
  472. float rot[3];
  473. bool bRotIsLocal;
  474. } forceboneposrot;
  475. struct
  476. {
  477. char *pBonename;
  478. int iAxis;
  479. float value;
  480. int start;
  481. int peak;
  482. int tail;
  483. int end;
  484. bool all;
  485. } bonedriver;
  486. struct
  487. {
  488. s_animation_t *ref;
  489. } appendanim;
  490. struct s_motion_t motion;
  491. } u;
  492. };
  493. struct s_streamdata_t
  494. {
  495. Vector pos;
  496. Quaternion q;
  497. };
  498. struct s_animationstream_t
  499. {
  500. // source animations
  501. int numerror;
  502. s_streamdata_t *pError;
  503. // compressed animations
  504. float scale[6];
  505. int numanim[6];
  506. mstudioanimvalue_t *anim[6];
  507. };
  508. struct s_ikrule_t
  509. {
  510. int chain;
  511. int index;
  512. int type;
  513. int slot;
  514. char bonename[MAXSTUDIONAME];
  515. char attachment[MAXSTUDIONAME];
  516. int bone;
  517. Vector pos;
  518. Quaternion q;
  519. float height;
  520. float floor;
  521. float radius;
  522. int start;
  523. int peak;
  524. int tail;
  525. int end;
  526. int contact;
  527. bool usesequence;
  528. bool usesource;
  529. int flags;
  530. s_animationstream_t errorData;
  531. };
  532. struct s_localhierarchy_t
  533. {
  534. int bone;
  535. int newparent;
  536. int start;
  537. int peak;
  538. int tail;
  539. int end;
  540. s_animationstream_t localData;
  541. };
  542. struct s_source_t;
  543. EXTERN int g_numani;
  544. struct s_compressed_t
  545. {
  546. int num[6];
  547. mstudioanimvalue_t *data[6];
  548. };
  549. struct s_animation_t
  550. {
  551. bool isImplied;
  552. bool isOverride;
  553. bool doesOverride;
  554. int index;
  555. char name[MAXSTUDIONAME];
  556. char filename[MAX_PATH];
  557. /*
  558. int animsubindex;
  559. // For sharing outside of current .mdl file
  560. bool shared_group_checkvalidity;
  561. bool shared_group_valid;
  562. char shared_animgroup_file[ MAX_PATH ]; // share file name
  563. char shared_animgroup_name[ MAXSTUDIONAME ]; // group name in share file
  564. int shared_group_subindex;
  565. studioanimhdr_t *shared_group_header;
  566. */
  567. float fps;
  568. int startframe;
  569. int endframe;
  570. int flags;
  571. // animations processed (time shifted, linearized, and bone adjusted ) from source animations
  572. CUtlVectorAuto< s_bone_t * > sanim; // [MAXSTUDIOANIMFRAMES]; // [frame][bones];
  573. int motiontype;
  574. int fudgeloop;
  575. int looprestart; // new starting frame for looping animations
  576. float looprestartpercent;
  577. // piecewise linear motion
  578. int numpiecewisekeys;
  579. s_linearmove_t piecewisemove[MAXSTUDIOMOVEKEYS];
  580. // default adjustments
  581. Vector adjust;
  582. float scale; // ????
  583. RadianEuler rotation;
  584. s_source_t *source;
  585. char animationname[MAX_PATH];
  586. Vector bmin;
  587. Vector bmax;
  588. int numframes;
  589. // compressed animation data
  590. int numsections;
  591. int sectionframes;
  592. CUtlVectorAuto< CUtlVectorAuto< s_compressed_t > > anim;
  593. // int weightlist;
  594. float weight[MAXSTUDIOSRCBONES];
  595. float posweight[MAXSTUDIOSRCBONES];
  596. int numcmds;
  597. s_animcmd_t cmds[MAXSTUDIOCMDS];
  598. int numikrules;
  599. s_ikrule_t ikrule[MAXSTUDIOIKRULES];
  600. bool noAutoIK;
  601. int numlocalhierarchy;
  602. s_localhierarchy_t localhierarchy[MAXSTUDIOIKRULES];
  603. float motionrollback;
  604. bool disableAnimblocks; // no demand loading
  605. bool isFirstSectionLocal; // first block of a section isn't demand loaded
  606. int numNostallFrames; // number of frames to keep in memory (modulo segement size)
  607. int rootDriverIndex;
  608. };
  609. EXTERN s_animation_t *g_panimation[MAXSTUDIOANIMS];
  610. EXTERN int g_numcmdlists;
  611. struct s_cmdlist_t
  612. {
  613. char name[MAXSTUDIONAME];
  614. int numcmds;
  615. s_animcmd_t cmds[MAXSTUDIOCMDS];
  616. };
  617. EXTERN s_cmdlist_t g_cmdlist[MAXSTUDIOANIMS];
  618. struct s_iklock_t
  619. {
  620. char name[MAXSTUDIONAME];
  621. int chain;
  622. float flPosWeight;
  623. float flLocalQWeight;
  624. };
  625. EXTERN int g_numikautoplaylocks;
  626. EXTERN s_iklock_t g_ikautoplaylock[16];
  627. struct s_animtag_t
  628. {
  629. int tag;
  630. float cycle;
  631. char tagname[MAXSTUDIONAME];
  632. };
  633. struct s_event_t
  634. {
  635. int event;
  636. int frame;
  637. char options[64];
  638. char eventname[MAXSTUDIONAME];
  639. };
  640. struct s_autolayer_t
  641. {
  642. char name[MAXSTUDIONAME];
  643. int sequence;
  644. int flags;
  645. int pose;
  646. float start;
  647. float peak;
  648. float tail;
  649. float end;
  650. };
  651. struct s_activitymodifier_t
  652. {
  653. int id;
  654. char name[64];
  655. };
  656. class s_sequence_t
  657. {
  658. public:
  659. char name[MAXSTUDIONAME];
  660. char activityname[MAXSTUDIONAME]; // index into the string table, the name of this activity.
  661. int flags;
  662. // float fps;
  663. // int numframes;
  664. int activity;
  665. int actweight;
  666. int numanimtags;
  667. s_animtag_t animtags[MAXSTUDIOTAGS];
  668. int numevents;
  669. s_event_t event[MAXSTUDIOEVENTS];
  670. int numblends;
  671. int groupsize[2];
  672. CUtlVectorAuto< CUtlVectorAuto< s_animation_t * > > panim; // [MAXSTUDIOBLENDS][MAXSTUDIOBLENDS];
  673. int paramindex[2];
  674. float paramstart[2];
  675. float paramend[2];
  676. int paramattachment[2];
  677. int paramcontrol[2];
  678. CUtlVectorAuto< float >param0; // [MAXSTUDIOBLENDS];
  679. CUtlVectorAuto< float >param1; // [MAXSTUDIOBLENDS];
  680. s_animation_t *paramanim;
  681. s_animation_t *paramcompanim;
  682. s_animation_t *paramcenter;
  683. // Vector automovepos[MAXSTUDIOANIMATIONS];
  684. // Vector automoveangle[MAXSTUDIOANIMATIONS];
  685. int animindex;
  686. Vector bmin;
  687. Vector bmax;
  688. float fadeintime;
  689. float fadeouttime;
  690. int entrynode;
  691. int exitnode;
  692. int nodeflags;
  693. float entryphase;
  694. float exitphase;
  695. int numikrules;
  696. int numautolayers;
  697. s_autolayer_t autolayer[64];
  698. float weight[MAXSTUDIOSRCBONES];
  699. s_iklock_t iklock[64];
  700. int numiklocks;
  701. int cycleposeindex;
  702. CUtlVector< char > KeyValue;
  703. int numactivitymodifiers;
  704. s_activitymodifier_t activitymodifier[MAXSTUDIOACTIVITYMODIFIERS];
  705. int rootDriverIndex;
  706. char rootDriverBoneName[MAXSTUDIONAME];
  707. };
  708. EXTERN CUtlVector< s_sequence_t > g_sequence;
  709. //EXTERN int g_numseq;
  710. EXTERN int g_numanimblocks;
  711. struct s_animblock_t
  712. {
  713. int iStartAnim;
  714. int iEndAnim;
  715. byte *start;
  716. byte *end;
  717. };
  718. EXTERN s_animblock_t g_animblock[MAXSTUDIOANIMBLOCKS];
  719. EXTERN int g_animblocksize;
  720. EXTERN char g_animblockname[260];
  721. EXTERN int g_animblockmaxframes;
  722. EXTERN int g_numposeparameters;
  723. struct s_poseparameter_t
  724. {
  725. char name[MAXSTUDIONAME];
  726. float min;
  727. float max;
  728. int flags;
  729. float loop;
  730. };
  731. EXTERN s_poseparameter_t g_pose[32]; // FIXME: this shouldn't be hard coded
  732. EXTERN int g_numxnodes;
  733. EXTERN char *g_xnodename[100];
  734. EXTERN int g_xnode[100][100];
  735. EXTERN int g_numxnodeskips;
  736. EXTERN int g_xnodeskip[10000][2];
  737. struct rgb_t
  738. {
  739. byte r, g, b;
  740. };
  741. struct rgb2_t
  742. {
  743. float r, g, b, a;
  744. };
  745. // FIXME: what about texture overrides inline with loading models
  746. enum TextureFlags_t
  747. {
  748. RELATIVE_TEXTURE_PATH_SPECIFIED = 0x1
  749. };
  750. struct s_texture_t
  751. {
  752. char name[MAX_PATH];
  753. int flags;
  754. int parent;
  755. int material;
  756. float width;
  757. float height;
  758. float dPdu;
  759. float dPdv;
  760. };
  761. EXTERN s_texture_t g_texture[MAXSTUDIOSKINS];
  762. EXTERN int g_numtextures;
  763. EXTERN int g_material[MAXSTUDIOSKINS]; // link into texture array
  764. EXTERN int g_nummaterials;
  765. EXTERN float g_gamma;
  766. EXTERN int g_numskinref;
  767. EXTERN int g_numskinfamilies;
  768. EXTERN int g_skinref[256][MAXSTUDIOSKINS]; // [skin][skinref], returns texture index
  769. EXTERN int g_numtexturegroups;
  770. EXTERN int g_numtexturelayers[32];
  771. EXTERN int g_numtexturereps[32];
  772. EXTERN int g_texturegroup[32][32][32];
  773. struct s_mesh_t
  774. {
  775. int numvertices;
  776. int vertexoffset;
  777. int numfaces;
  778. int faceoffset;
  779. };
  780. struct s_vertanim_t
  781. {
  782. int vertex;
  783. float speed;
  784. float side;
  785. Vector pos;
  786. Vector normal;
  787. float wrinkle;
  788. };
  789. struct s_lodvertexinfo_t : public s_vertexinfo_t
  790. {
  791. int lodFlag;
  792. };
  793. // processed aggregate lod pools
  794. struct s_loddata_t
  795. {
  796. int numvertices;
  797. s_lodvertexinfo_t *vertex;
  798. int numfaces;
  799. s_face_t *face;
  800. s_mesh_t mesh[MAXSTUDIOSKINS];
  801. // remaps verts from an lod's source mesh to this all-lod processed aggregate pool
  802. int *pMeshVertIndexMaps[MAX_NUM_LODS];
  803. };
  804. // Animations stored in raw off-disk source files. Raw data should be not processed.
  805. class s_sourceanim_t
  806. {
  807. public:
  808. char animationname[MAX_PATH];
  809. int numframes;
  810. int startframe;
  811. int endframe;
  812. CUtlVectorAuto< s_bone_t * >rawanim;
  813. // vertex animation
  814. bool newStyleVertexAnimations; // new style doesn't store a base pose in vertex anim[0]
  815. int *vanim_mapcount; // local verts map to N target verts
  816. int **vanim_map; // local vertices to target vertices mapping list
  817. int *vanim_flag; // local vert does animate
  818. int numvanims[MAXSTUDIOANIMFRAMES];
  819. s_vertanim_t *vanim[MAXSTUDIOANIMFRAMES]; // [frame][vertex]
  820. };
  821. // raw off-disk source files. Raw data should be not processed.
  822. struct s_source_t
  823. {
  824. char filename[MAX_PATH];
  825. int version; // Version number from SMD file, otherwise 0
  826. bool isActiveModel;
  827. // local skeleton hierarchy
  828. int numbones;
  829. s_node_t localBone[MAXSTUDIOSRCBONES];
  830. matrix3x4_t boneToPose[MAXSTUDIOSRCBONES]; // converts bone local data into initial pose data
  831. // bone remapping
  832. int boneflags[MAXSTUDIOSRCBONES]; // attachment, vertex, etc flags for this bone
  833. int boneref[MAXSTUDIOSRCBONES]; // flags for this and child bones
  834. int boneLocalToGlobal[MAXSTUDIOSRCBONES]; // bonemap : local bone to world bone mapping
  835. int boneGlobalToLocal[MAXSTUDIOSRCBONES]; // boneimap : world bone to local bone mapping
  836. int texmap[MAXSTUDIOSKINS*4]; // map local MAX materials to unique textures
  837. // per material mesh
  838. int nummeshes;
  839. int meshindex[MAXSTUDIOSKINS]; // mesh to skin index
  840. s_mesh_t mesh[MAXSTUDIOSKINS];
  841. // vertices defined in "local" space (not remapped to global bones)
  842. int numvertices;
  843. s_vertexinfo_t *vertex;
  844. // vertices defined in "global" space (remapped to global bones)
  845. CUtlVector< s_vertexinfo_t > m_GlobalVertices;
  846. int numfaces;
  847. s_face_t *face; // vertex indexs per face
  848. // raw skeletal animation
  849. CUtlVector< s_sourceanim_t > m_Animations;
  850. // default adjustments
  851. Vector adjust;
  852. float scale; // ????
  853. RadianEuler rotation;
  854. // Flex keys stored in the source data
  855. bool bNoAutoDMXRules;
  856. CUtlVector< s_flexkey_t > m_FlexKeys;
  857. // Combination controls stored in the source data
  858. CUtlVector< s_combinationcontrol_t > m_CombinationControls;
  859. // Combination rules stored in the source data
  860. CUtlVector< s_combinationrule_t > m_CombinationRules;
  861. // Flexcontroller remaps
  862. CUtlVector< s_flexcontrollerremap_t > m_FlexControllerRemaps;
  863. // Attachment points stored in the SMD/DMX/etc. file
  864. CUtlVector< s_attachment_t > m_Attachments;
  865. // Information about how flex controller remaps map into flex rules
  866. int m_nKeyStartIndex; // The index at which the flex keys for this model start in the global list
  867. CUtlVector< int > m_rawIndexToRemapSourceIndex;
  868. CUtlVector< int > m_rawIndexToRemapLocalIndex;
  869. CUtlVector< int > m_leftRemapIndexToGlobalFlexControllIndex;
  870. CUtlVector< int > m_rightRemapIndexToGlobalFlexControllIndex;
  871. };
  872. EXTERN int g_numsources;
  873. EXTERN s_source_t *g_source[MAXSTUDIOSEQUENCES];
  874. struct s_eyeball_t
  875. {
  876. char name[MAXSTUDIONAME];
  877. int index;
  878. int bone;
  879. Vector org;
  880. float zoffset;
  881. float radius;
  882. Vector up;
  883. Vector forward;
  884. int mesh;
  885. float iris_scale;
  886. int upperlidflexdesc;
  887. int upperflexdesc[3];
  888. float uppertarget[3];
  889. int lowerlidflexdesc;
  890. int lowerflexdesc[3];
  891. float lowertarget[3];
  892. };
  893. struct s_model_t
  894. {
  895. char name[MAXSTUDIONAME];
  896. char filename[MAX_PATH];
  897. // needs local scaling and rotation paramaters
  898. s_source_t *source; // index into source table
  899. float scale; // UNUSED
  900. float boundingradius;
  901. Vector boundingbox[MAXSTUDIOSRCBONES][2];
  902. int numattachments;
  903. s_attachment_t attachment[32];
  904. int numeyeballs;
  905. s_eyeball_t eyeball[4];
  906. // References to sources which are the LODs for this model
  907. CUtlVector< s_source_t* > m_LodSources;
  908. // processed aggregate lod data
  909. s_loddata_t *m_pLodData;
  910. };
  911. EXTERN int g_nummodels;
  912. EXTERN int g_nummodelsbeforeLOD;
  913. EXTERN CUtlVectorAuto< s_model_t *> g_model;
  914. struct s_flexdesc_t
  915. {
  916. char FACS[MAXSTUDIONAME]; // FACS identifier
  917. };
  918. EXTERN int g_numflexdesc;
  919. EXTERN s_flexdesc_t g_flexdesc[MAXSTUDIOFLEXDESC];
  920. int Add_Flexdesc( const char *name );
  921. struct s_flexcontroller_t
  922. {
  923. char name[MAXSTUDIONAME];
  924. char type[MAXSTUDIONAME];
  925. float min;
  926. float max;
  927. };
  928. EXTERN int g_numflexcontrollers;
  929. EXTERN s_flexcontroller_t g_flexcontroller[MAXSTUDIOFLEXCTRL];
  930. struct s_flexcontrollerremap_t
  931. {
  932. CUtlString m_Name;
  933. FlexControllerRemapType_t m_RemapType;
  934. bool m_bIsStereo;
  935. CUtlVector< CUtlString > m_RawControls;
  936. int m_Index; ///< The model relative index of the slider control for value for this if it's not split, -1 otherwise
  937. int m_LeftIndex; ///< The model relative index of the left slider control for this if it's split, -1 otherwise
  938. int m_RightIndex; ///< The model relative index of the right slider control for this if it's split, -1 otherwise
  939. int m_MultiIndex; ///< The model relative index of the value slider control for this if it's multi, -1 otherwise
  940. CUtlString m_EyesUpDownFlexName; // The name of the eyes up/down flex controller
  941. int m_EyesUpDownFlexController; // The global index of the Eyes Up/Down Flex Controller
  942. int m_BlinkController; // The global index of the Blink Up/Down Flex Controller
  943. };
  944. extern CUtlVector<s_flexcontrollerremap_t> g_FlexControllerRemap;
  945. struct s_flexkey_t
  946. {
  947. int flexdesc;
  948. int flexpair;
  949. s_source_t *source; // index into source table
  950. char animationname[MAX_PATH];
  951. int imodel;
  952. int frame;
  953. float target0;
  954. float target1;
  955. float target2;
  956. float target3;
  957. float split;
  958. float decay;
  959. // extracted and remapped vertex animations
  960. int numvanims;
  961. s_vertanim_t *vanim;
  962. int vanimtype;
  963. int weighttable;
  964. };
  965. EXTERN int g_numflexkeys;
  966. EXTERN s_flexkey_t g_flexkey[MAXSTUDIOFLEXKEYS];
  967. EXTERN s_flexkey_t *g_defaultflexkey;
  968. #define MAX_OPS 512
  969. struct s_flexop_t
  970. {
  971. int op;
  972. union
  973. {
  974. int index;
  975. float value;
  976. } d;
  977. };
  978. struct s_flexrule_t
  979. {
  980. int flex;
  981. int numops;
  982. s_flexop_t op[MAX_OPS];
  983. };
  984. EXTERN int g_numflexrules;
  985. EXTERN s_flexrule_t g_flexrule[MAXSTUDIOFLEXRULES];
  986. struct s_combinationcontrol_t
  987. {
  988. char name[MAX_PATH];
  989. };
  990. struct s_combinationrule_t
  991. {
  992. // The 'ints' here are indices into the m_Controls array
  993. CUtlVector< int > m_Combination;
  994. CUtlVector< CUtlVector< int > > m_Dominators;
  995. // The index into the flexkeys to put the result in
  996. // (should affect both left + right if the key is sided)
  997. int m_nFlex;
  998. };
  999. EXTERN Vector g_defaultadjust;
  1000. struct s_bodypart_t
  1001. {
  1002. char name[MAXSTUDIONAME];
  1003. int nummodels;
  1004. int base;
  1005. CUtlVectorAuto< s_model_t * > pmodel;
  1006. s_bodypart_t()
  1007. {
  1008. memset( this, 0, sizeof( s_bodypart_t ) );
  1009. }
  1010. };
  1011. EXTERN int g_numbodyparts;
  1012. EXTERN CUtlVectorAuto< s_bodypart_t > g_bodypart;
  1013. struct s_bodygrouppreset_t
  1014. {
  1015. char name[MAXSTUDIONAME];
  1016. int iValue;
  1017. int iMask;
  1018. s_bodygrouppreset_t()
  1019. {
  1020. memset( this, 0, sizeof( s_bodygrouppreset_t ) );
  1021. }
  1022. };
  1023. EXTERN int g_numbodygrouppresets;
  1024. EXTERN CUtlVectorAuto< s_bodygrouppreset_t > g_bodygrouppresets;
  1025. #define MAXWEIGHTLISTS 128
  1026. #define MAXWEIGHTSPERLIST (MAXSTUDIOBONES)
  1027. struct s_weightlist_t
  1028. {
  1029. // weights, indexed by numbones per weightlist
  1030. char name[MAXSTUDIONAME];
  1031. int numbones;
  1032. char *bonename[MAXWEIGHTSPERLIST];
  1033. float boneweight[MAXWEIGHTSPERLIST];
  1034. float boneposweight[MAXWEIGHTSPERLIST];
  1035. // weights, indexed by global bone index
  1036. float weight[MAXSTUDIOBONES];
  1037. float posweight[MAXSTUDIOBONES];
  1038. };
  1039. EXTERN int g_numweightlist;
  1040. EXTERN s_weightlist_t g_weightlist[MAXWEIGHTLISTS];
  1041. struct s_iklink_t
  1042. {
  1043. int bone;
  1044. Vector kneeDir;
  1045. };
  1046. struct s_ikchain_t
  1047. {
  1048. char name[MAXSTUDIONAME];
  1049. char bonename[MAXSTUDIONAME];
  1050. int axis;
  1051. float value;
  1052. int numlinks;
  1053. s_iklink_t link[10]; // hip, knee, ankle, toes...
  1054. float height;
  1055. float radius;
  1056. float floor;
  1057. Vector center;
  1058. };
  1059. EXTERN int g_numikchains;
  1060. EXTERN s_ikchain_t g_ikchain[16];
  1061. struct s_jigglebone_t
  1062. {
  1063. int flags;
  1064. char bonename[MAXSTUDIONAME];
  1065. int bone;
  1066. mstudiojigglebone_t data; // the actual jiggle properties
  1067. };
  1068. EXTERN int g_numjigglebones;
  1069. EXTERN s_jigglebone_t g_jigglebones[MAXSTUDIOBONES];
  1070. EXTERN int g_jigglebonemap[MAXSTUDIOBONES]; // map used jigglebone's to source jigglebonebone's
  1071. struct s_axisinterpbone_t
  1072. {
  1073. int flags;
  1074. char bonename[MAXSTUDIONAME];
  1075. int bone;
  1076. char controlname[MAXSTUDIONAME];
  1077. int control;
  1078. int axis;
  1079. Vector pos[6];
  1080. Quaternion quat[6];
  1081. };
  1082. EXTERN int g_numaxisinterpbones;
  1083. EXTERN s_axisinterpbone_t g_axisinterpbones[MAXSTUDIOBONES];
  1084. EXTERN int g_axisinterpbonemap[MAXSTUDIOBONES]; // map used axisinterpbone's to source axisinterpbone's
  1085. struct s_quatinterpbone_t
  1086. {
  1087. int flags;
  1088. char bonename[MAXSTUDIONAME];
  1089. int bone;
  1090. char parentname[MAXSTUDIONAME];
  1091. // int parent;
  1092. char controlparentname[MAXSTUDIONAME];
  1093. // int controlparent;
  1094. char controlname[MAXSTUDIONAME];
  1095. int control;
  1096. int numtriggers;
  1097. Vector size;
  1098. Vector basepos;
  1099. float percentage;
  1100. float tolerance[32];
  1101. Quaternion trigger[32];
  1102. Vector pos[32];
  1103. Quaternion quat[32];
  1104. };
  1105. EXTERN int g_numquatinterpbones;
  1106. EXTERN s_quatinterpbone_t g_quatinterpbones[MAXSTUDIOBONES];
  1107. EXTERN int g_quatinterpbonemap[MAXSTUDIOBONES]; // map used quatinterpbone's to source axisinterpbone's
  1108. struct s_aimatbone_t
  1109. {
  1110. char bonename[MAXSTUDIONAME];
  1111. int bone;
  1112. char parentname[MAXSTUDIONAME];
  1113. int parent;
  1114. char aimname[MAXSTUDIONAME];
  1115. int aimAttach;
  1116. int aimBone;
  1117. Vector aimvector;
  1118. Vector upvector;
  1119. Vector basepos;
  1120. };
  1121. EXTERN int g_numaimatbones;
  1122. EXTERN s_aimatbone_t g_aimatbones[MAXSTUDIOBONES];
  1123. EXTERN int g_aimatbonemap[MAXSTUDIOBONES]; // map used aimatpbone's to source aimatpbone's (may be optimized out)
  1124. //-----------------------------------------------------------------------------
  1125. //
  1126. //-----------------------------------------------------------------------------
  1127. struct s_constraintbonetarget_t
  1128. {
  1129. char m_szBoneName[MAXSTUDIONAME];
  1130. int m_nBone;
  1131. float m_flWeight;
  1132. Vector m_vOffset;
  1133. Quaternion m_qOffset;
  1134. bool operator==( const s_constraintbonetarget_t &rhs ) const;
  1135. bool operator!=( const s_constraintbonetarget_t &rhs ) const { return !( *this == rhs ); }
  1136. };
  1137. //-----------------------------------------------------------------------------
  1138. //
  1139. //-----------------------------------------------------------------------------
  1140. struct s_constraintboneslave_t
  1141. {
  1142. char m_szBoneName[MAXSTUDIONAME];
  1143. int m_nBone;
  1144. Vector m_vBaseTranslate;
  1145. Quaternion m_qBaseRotation;
  1146. bool operator==( const s_constraintboneslave_t &rhs ) const;
  1147. bool operator!=( const s_constraintboneslave_t &rhs ) const { return !( *this == rhs ); }
  1148. };
  1149. //-----------------------------------------------------------------------------
  1150. //
  1151. //-----------------------------------------------------------------------------
  1152. class CTwistBone
  1153. {
  1154. public:
  1155. bool m_bInverse;
  1156. Vector m_vUpVector;
  1157. char m_szParentBoneName[MAXSTUDIONAME];
  1158. int m_nParentBone;
  1159. Quaternion m_qBaseRotation;
  1160. char m_szChildBoneName[MAXSTUDIONAME];
  1161. int m_nChildBone;
  1162. CUtlVector< s_constraintbonetarget_t > m_twistBoneTargets;
  1163. CTwistBone()
  1164. {
  1165. m_bInverse = false;
  1166. m_vUpVector.Init();
  1167. m_szParentBoneName[0] = '\0';
  1168. m_nParentBone = -1;
  1169. m_qBaseRotation.Init();
  1170. m_szChildBoneName[0] = '\0';
  1171. m_nChildBone = -1;
  1172. }
  1173. };
  1174. EXTERN CUtlVector< CTwistBone > g_twistbones;
  1175. //-----------------------------------------------------------------------------
  1176. //
  1177. //-----------------------------------------------------------------------------
  1178. class CConstraintBoneBase
  1179. {
  1180. public:
  1181. virtual ~CConstraintBoneBase() {}
  1182. CUtlVector< s_constraintbonetarget_t > m_targets;
  1183. s_constraintboneslave_t m_slave;
  1184. bool operator==( const CConstraintBoneBase &rhs ) const;
  1185. bool operator!=( const CConstraintBoneBase &rhs ) const { return !( *this == rhs ); }
  1186. };
  1187. //-----------------------------------------------------------------------------
  1188. //
  1189. //-----------------------------------------------------------------------------
  1190. EXTERN CUtlVector< CConstraintBoneBase * > g_constraintBones;
  1191. //-----------------------------------------------------------------------------
  1192. //
  1193. //-----------------------------------------------------------------------------
  1194. class CPointConstraint : public CConstraintBoneBase
  1195. {
  1196. public:
  1197. };
  1198. //-----------------------------------------------------------------------------
  1199. //
  1200. //-----------------------------------------------------------------------------
  1201. class COrientConstraint : public CConstraintBoneBase
  1202. {
  1203. public:
  1204. };
  1205. //-----------------------------------------------------------------------------
  1206. //
  1207. //-----------------------------------------------------------------------------
  1208. class CAimConstraint : public CConstraintBoneBase
  1209. {
  1210. public:
  1211. CAimConstraint()
  1212. {
  1213. m_nUpSpaceTargetBone = -1;
  1214. }
  1215. Quaternion m_qAimOffset;
  1216. Vector m_vUpVector;
  1217. char m_szUpSpaceTargetBone[MAXSTUDIONAME];
  1218. int m_nUpSpaceTargetBone;
  1219. int m_nUpType; // CConstraintBones::AimConstraintUpType_t
  1220. };
  1221. //-----------------------------------------------------------------------------
  1222. //
  1223. //-----------------------------------------------------------------------------
  1224. class CParentConstraint : public CConstraintBoneBase
  1225. {
  1226. public:
  1227. };
  1228. struct s_forcedhierarchy_t
  1229. {
  1230. char parentname[MAXSTUDIONAME];
  1231. char childname[MAXSTUDIONAME];
  1232. char subparentname[MAXSTUDIONAME];
  1233. };
  1234. EXTERN int g_numforcedhierarchy;
  1235. EXTERN s_forcedhierarchy_t g_forcedhierarchy[MAXSTUDIOBONES];
  1236. struct s_forcedrealign_t
  1237. {
  1238. char name[MAXSTUDIONAME];
  1239. RadianEuler rot;
  1240. };
  1241. EXTERN int g_numforcedrealign;
  1242. EXTERN s_forcedrealign_t g_forcedrealign[MAXSTUDIOBONES];
  1243. struct s_limitrotation_t
  1244. {
  1245. char name[MAXSTUDIONAME];
  1246. int numseq;
  1247. char *sequencename[64];
  1248. };
  1249. EXTERN int g_numlimitrotation;
  1250. EXTERN s_limitrotation_t g_limitrotation[MAXSTUDIOBONES];
  1251. extern int BuildTris (s_trianglevert_t (*x)[3], s_mesh_t *y, byte **ppdata );
  1252. struct s_bonesaveframe_t
  1253. {
  1254. char name[ MAXSTUDIOHITBOXSETNAME ];
  1255. bool bSavePos;
  1256. bool bSaveRot;
  1257. bool bSaveRot64;
  1258. };
  1259. EXTERN CUtlVector< s_bonesaveframe_t > g_bonesaveframe;
  1260. int OpenGlobalFile( char *src );
  1261. bool GetGlobalFilePath( const char *pSrc, char *pFullPath, int nMaxLen );
  1262. s_source_t *Load_Source( const char *filename, const char *ext, bool reverse = false, bool isActiveModel = false, bool bUseCache = true );
  1263. void ApplyOffsetToSrcVerts( s_source_t *pModel, matrix3x4_t matOffset );
  1264. void AddSrcToSrc( s_source_t *pOrigSource, s_source_t *pAppendSource, matrix3x4_t matOffset );
  1265. void AddSrcToSrc( s_source_t *pOrigSource, s_source_t *pAppendSource );
  1266. int Load_VRM( s_source_t *psource );
  1267. int Load_SMD( s_source_t *psource );
  1268. int Load_VTA( s_source_t *psource );
  1269. int Load_OBJ( s_source_t *psource );
  1270. int Load_DMX( s_source_t *psource );
  1271. int Load_FBX( s_source_t *psource );
  1272. bool LoadPreprocessedFile( const char *pFileName, float flScale );
  1273. int AppendVTAtoOBJ( s_source_t *psource, char *filename, int frame );
  1274. void Build_Reference( s_source_t *psource, const char *pAnimName );
  1275. int Grab_Nodes( s_node_t *pnodes );
  1276. void Grab_Animation( s_source_t *psource, const char *pAnimName );
  1277. // Processes source comment line and extracts information about the data file
  1278. void ProcessSourceComment( s_source_t *psource, const char *pCommentString );
  1279. // Processes original content file "szOriginalContentFile" that was used to generate
  1280. // data file "szDataFile"
  1281. void ProcessOriginalContentFile( const char *szDataFile, const char *szOriginalContentFile );
  1282. //-----------------------------------------------------------------------------
  1283. // Utility methods to get or add animation data from sources
  1284. //-----------------------------------------------------------------------------
  1285. s_sourceanim_t *FindSourceAnim( s_source_t *pSource, const char *pAnimName );
  1286. const s_sourceanim_t *FindSourceAnim( const s_source_t *pSource, const char *pAnimName );
  1287. s_sourceanim_t *FindOrAddSourceAnim( s_source_t *pSource, const char *pAnimName );
  1288. // Adds flexkey data to a particular source
  1289. void AddFlexKey( s_source_t *pSource, CDmeCombinationOperator *pComboOp, const char *pFlexKeyName );
  1290. // Adds combination data to the source
  1291. void AddCombination( s_source_t *pSource, CDmeCombinationOperator *pCombination );
  1292. int LookupTexture( const char *pTextureName, bool bRelativePath = false );
  1293. int UseTextureAsMaterial( int textureindex );
  1294. int MaterialToTexture( int material );
  1295. int LookupAttachment( const char *name );
  1296. void ClearModel (void);
  1297. void SimplifyModel (void);
  1298. void CollapseBones (void);
  1299. void adjust_vertex( float *org );
  1300. void scale_vertex( Vector &org );
  1301. void clip_rotations( RadianEuler& rot );
  1302. void clip_rotations( Vector& rot );
  1303. char *stristr( const char *string, const char *string2 );
  1304. #define strcpyn( a, b ) strncpy( a, b, sizeof( a ) )
  1305. void CalcBoneTransforms( s_animation_t *panimation, int frame, matrix3x4_t* pBoneToWorld );
  1306. void CalcBoneTransforms( s_animation_t *panimation, s_animation_t *pbaseanimation, int frame, matrix3x4_t* pBoneToWorld );
  1307. void CalcBoneTransformsCycle( s_animation_t *panimation, s_animation_t *pbaseanimation, float flCycle, matrix3x4_t* pBoneToWorld );
  1308. void BuildRawTransforms( const s_source_t *psource, const char *pAnimationName, int frame, float scale, Vector const &shift, RadianEuler const &rotate, int flags, matrix3x4_t* boneToWorld );
  1309. void BuildRawTransforms( const s_source_t *psource, const char *pAnimationName, int frame, matrix3x4_t* boneToWorld );
  1310. void TranslateAnimations( const s_source_t *pSource, const matrix3x4_t *pSrcBoneToWorld, matrix3x4_t *pDestBoneToWorld );
  1311. // Returns surface property for a given joint
  1312. char* GetSurfaceProp ( const char* pJointName );
  1313. int GetContents ( const char* pJointName );
  1314. char* GetDefaultSurfaceProp ( );
  1315. int GetDefaultContents( );
  1316. // Did we read 'end'
  1317. bool IsEnd( const char* pLine );
  1318. // Parses an LOD command
  1319. void Cmd_LOD( const char *cmdname );
  1320. void Cmd_ShadowLOD( void );
  1321. // Fixes up the LOD source files
  1322. void FixupLODSources();
  1323. // Get model LOD source
  1324. s_source_t* GetModelLODSource( const char *pModelName,
  1325. const LodScriptData_t& scriptLOD, bool* pFound );
  1326. void LoadLODSources( void );
  1327. void ConvertBoneTreeCollapsesToReplaceBones( void );
  1328. void FixupReplacedBones( void );
  1329. void UnifyLODs( void );
  1330. void SpewBoneUsageStats( void );
  1331. void MarkParentBoneLODs( void );
  1332. //void CheckAutoShareAnimationGroup( const char *animation_name );
  1333. /*
  1334. =================
  1335. =================
  1336. */
  1337. extern bool GetLineInput(void);
  1338. extern char g_szFilename[1024];
  1339. extern FILE *g_fpInput;
  1340. extern char g_szLine[4096];
  1341. extern int g_iLinecount;
  1342. extern int g_min_faces, g_max_faces;
  1343. extern float g_min_resolution, g_max_resolution;
  1344. EXTERN int g_numverts;
  1345. EXTERN CUtlVectorAuto< Vector > g_vertex;
  1346. EXTERN CUtlVectorAuto< s_boneweight_t > g_bone;
  1347. EXTERN int g_numnormals;
  1348. EXTERN CUtlVectorAuto< Vector > g_normal;
  1349. extern int g_numtexcoords[MAXSTUDIOTEXCOORDS];
  1350. extern CUtlVectorAuto< Vector2D > g_texcoord[MAXSTUDIOTEXCOORDS];
  1351. EXTERN int g_numfaces;
  1352. EXTERN CUtlVectorAuto< s_tmpface_t > g_face;
  1353. EXTERN CUtlVectorAuto< s_face_t > g_src_uface; // max res unified faces
  1354. struct v_unify_t
  1355. {
  1356. int refcount;
  1357. int lastref;
  1358. int firstref;
  1359. int v;
  1360. int m;
  1361. int n;
  1362. int t[MAXSTUDIOTEXCOORDS];
  1363. v_unify_t *next; // pointer to next entry with same v
  1364. };
  1365. EXTERN v_unify_t *v_list[MAXSTUDIOSRCVERTS];
  1366. EXTERN v_unify_t v_listdata[MAXSTUDIOSRCVERTS];
  1367. EXTERN int g_numvlist;
  1368. int SortAndBalanceBones( int iCount, int iMaxCount, int bones[], float weights[] );
  1369. void Grab_Vertexanimation( s_source_t *psource, const char *pAnimationName );
  1370. extern void BuildIndividualMeshes( s_source_t *psource );
  1371. //-----------------------------------------------------------------------------
  1372. // A little class used to deal with replacement commands
  1373. //-----------------------------------------------------------------------------
  1374. class CLodScriptReplacement_t
  1375. {
  1376. public:
  1377. void SetSrcName( const char *pSrcName )
  1378. {
  1379. if( m_pSrcName )
  1380. {
  1381. delete [] m_pSrcName;
  1382. }
  1383. m_pSrcName = new char[strlen( pSrcName ) + 1];
  1384. strcpy( m_pSrcName, pSrcName );
  1385. }
  1386. void SetDstName( const char *pDstName )
  1387. {
  1388. if( m_pDstName )
  1389. {
  1390. delete [] m_pDstName;
  1391. }
  1392. m_pDstName = new char[strlen( pDstName ) + 1];
  1393. strcpy( m_pDstName, pDstName );
  1394. }
  1395. const char *GetSrcName( void ) const
  1396. {
  1397. return m_pSrcName;
  1398. }
  1399. const char *GetDstName( void ) const
  1400. {
  1401. return m_pDstName;
  1402. }
  1403. CLodScriptReplacement_t()
  1404. {
  1405. m_pSrcName = NULL;
  1406. m_pDstName = NULL;
  1407. m_pSource = 0;
  1408. }
  1409. ~CLodScriptReplacement_t()
  1410. {
  1411. delete [] m_pSrcName;
  1412. delete [] m_pDstName;
  1413. }
  1414. s_source_t* m_pSource;
  1415. private:
  1416. char *m_pSrcName;
  1417. char *m_pDstName;
  1418. };
  1419. struct LodScriptData_t
  1420. {
  1421. public:
  1422. float switchValue;
  1423. CUtlVector<CLodScriptReplacement_t> modelReplacements;
  1424. CUtlVector<CLodScriptReplacement_t> boneReplacements;
  1425. CUtlVector<CLodScriptReplacement_t> boneTreeCollapses;
  1426. CUtlVector<CLodScriptReplacement_t> materialReplacements;
  1427. CUtlVector<CLodScriptReplacement_t> meshRemovals;
  1428. void EnableFacialAnimation( bool val )
  1429. {
  1430. m_bFacialAnimation = val;
  1431. }
  1432. bool GetFacialAnimationEnabled() const
  1433. {
  1434. return m_bFacialAnimation;
  1435. }
  1436. void StripFromModel( bool val )
  1437. {
  1438. m_bStrippedFromModel = val;
  1439. }
  1440. bool IsStrippedFromModel() const
  1441. {
  1442. return m_bStrippedFromModel;
  1443. }
  1444. LodScriptData_t()
  1445. {
  1446. m_bFacialAnimation = true;
  1447. m_bStrippedFromModel = false;
  1448. }
  1449. private:
  1450. bool m_bFacialAnimation;
  1451. bool m_bStrippedFromModel;
  1452. };
  1453. EXTERN CUtlVector<LodScriptData_t> g_ScriptLODs;
  1454. extern bool g_parseable_completion_output;
  1455. extern bool g_collapse_bones_message;
  1456. extern bool g_collapse_bones;
  1457. extern bool g_collapse_bones_aggressive;
  1458. extern bool g_quiet;
  1459. extern bool g_verbose;
  1460. extern bool g_bCheckLengths;
  1461. extern bool g_bPrintBones;
  1462. extern bool g_bPerf;
  1463. extern bool g_bFast;
  1464. extern bool g_bDumpGraph;
  1465. extern bool g_bMultistageGraph;
  1466. extern bool g_bCreateMakefile;
  1467. extern bool g_bZBrush;
  1468. extern bool g_bVerifyOnly;
  1469. extern bool g_bUseBoneInBBox;
  1470. extern bool g_bLockBoneLengths;
  1471. extern bool g_bDefineBonesLockedByDefault;
  1472. extern bool g_bX360;
  1473. extern int g_minLod;
  1474. extern bool g_bFastBuild;
  1475. extern int g_numAllowedRootLODs;
  1476. extern bool g_bBuildPreview;
  1477. extern bool g_bPreserveTriangleOrder;
  1478. extern bool g_bCenterBonesOnVerts;
  1479. extern float g_flDefaultMotionRollback;
  1480. extern int g_minSectionFrameLimit;
  1481. extern int g_sectionFrames;
  1482. extern bool g_bNoAnimblockStall;
  1483. extern float g_flPreloadTime;
  1484. extern bool g_bStripLods;
  1485. extern bool g_bAnimblockHighRes;
  1486. extern bool g_bAnimblockLowRes;
  1487. extern int g_nMaxZeroFrames;
  1488. extern bool g_bZeroFramesHighres;
  1489. extern float g_flMinZeroFramePosDelta;
  1490. extern Vector g_vecMinWorldspace;
  1491. extern Vector g_vecMaxWorldspace;
  1492. extern bool g_bLCaseAllSequences;
  1493. extern bool g_bErrorOnSeqRemapFail;
  1494. extern bool g_bModelIntentionallyHasZeroSequences;
  1495. extern float g_flDefaultFadeInTime;
  1496. extern float g_flDefaultFadeOutTime;
  1497. extern float g_flCollisionPrecision;
  1498. EXTERN CUtlVector< char * >g_collapse;
  1499. extern float GetCollisionModelMass();
  1500. // List of defined bone flex drivers
  1501. extern DmElementHandle_t g_hDmeBoneFlexDriverList;
  1502. // the first time these are called, the name of the model/QC file is printed so that when
  1503. // running in batch mode, no echo, when dumping to a file, it can be determined which file is broke.
  1504. void MdlError( const char *pMsg, ... );
  1505. void MdlWarning( const char *pMsg, ... );
  1506. void CreateMakefile_AddDependency( const char *pFileName );
  1507. void EnsureDependencyFileCheckedIn( const char *pFileName );
  1508. void AddSurfaceProp( const char *pBoneName, const char *pSurfaceProperty );
  1509. char* FindSurfaceProp( const char* pBoneName );
  1510. bool ComparePath( const char *a, const char *b );
  1511. void SetDefaultSurfaceProp( const char *pSurfaceProperty );
  1512. void PostProcessSource( s_source_t *pSource, int imodel );
  1513. byte IsByte( int val );
  1514. char IsChar( int val );
  1515. int IsInt24( int val );
  1516. short IsShort( int val );
  1517. unsigned short IsUShort( int val );
  1518. struct MDLCommand_t
  1519. {
  1520. char *m_pName;
  1521. void (*m_pCmd)();
  1522. int m_nLastValidVersion;
  1523. };
  1524. //-----------------------------------------------------------------------------
  1525. // Assigns a default contents to the entire model
  1526. //-----------------------------------------------------------------------------
  1527. struct ContentsName_t
  1528. {
  1529. char m_pJointName[128];
  1530. int m_nContents;
  1531. };
  1532. extern int s_nDefaultContents; // in studiomdl.cpp
  1533. extern CUtlVector<ContentsName_t> s_JointContents; // in studiomdl.cpp
  1534. #ifdef MDLCOMPILE
  1535. void ConvertToCurrentVersion( int nSrcVersion, const char *pFullPath );
  1536. extern int g_nMDLCommandCount;
  1537. extern MDLCommand_t *g_pMDLCommands;
  1538. void ProcessStaticProp();
  1539. s_sequence_t *ProcessCmdSequence( const char *pSequenceName );
  1540. s_animation_t *ProcessImpliedAnimation( s_sequence_t *psequence, const char *filename );
  1541. void ProcessSequence( s_sequence_t *pseq, int numblends, s_animation_t **animations, bool isAppend );
  1542. s_animation_t *LookupAnimation( const char *name );
  1543. int LookupXNode( const char *name );
  1544. int LookupPoseParameter( const char *name );
  1545. void AddBodyAttachments( s_source_t *pSource );
  1546. #endif
  1547. //-----------------------------------------------------------------------------
  1548. //
  1549. //-----------------------------------------------------------------------------
  1550. enum EyelidType_t
  1551. {
  1552. kLowerer = 0,
  1553. kNeutral = 1,
  1554. kRaiser = 2,
  1555. kEyelidTypeCount = 3
  1556. };
  1557. //-----------------------------------------------------------------------------
  1558. // Used to point to the current s_model_t when loading QcModelElements from DMX
  1559. //-----------------------------------------------------------------------------
  1560. extern s_model_t *g_pCurrentModel;
  1561. #endif // STUDIOMDL_H