Team Fortress 2 Source Code as on 22/4/2020
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.

274 lines
5.9 KiB

  1. /***
  2. *
  3. //========= Copyright Valve Corporation, All rights reserved. ============//
  4. *
  5. * This product contains software technology licensed from Id
  6. * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
  7. * All Rights Reserved.
  8. *
  9. ****/
  10. #include <stdio.h>
  11. #include "basetypes.h"
  12. #include "utlvector.h"
  13. #include "utlsymbol.h"
  14. #include "mathlib/vector.h"
  15. #include "studio.h"
  16. struct LodScriptData_t;
  17. #define IDSTUDIOHEADER (('T'<<24)+('S'<<16)+('D'<<8)+'I')
  18. // little-endian "IDST"
  19. #define IDSTUDIOANIMGROUPHEADER (('G'<<24)+('A'<<16)+('D'<<8)+'I')
  20. // little-endian "IDAG"
  21. #define STUDIO_QUADRATIC_MOTION 0x00002000
  22. #define MAXSTUDIOANIMFRAMES 2000 // max frames per animation
  23. #define MAXSTUDIOSEQUENCES 1524 // total sequences
  24. #define MAXSTUDIOSRCBONES 512 // bones allowed at source movement
  25. #define MAXSTUDIOBONEWEIGHTS 3
  26. #define MAXSTUDIONAME 128
  27. #ifndef EXTERN
  28. #define EXTERN extern
  29. #endif
  30. EXTERN char outname[1024];
  31. EXTERN int numdirs;
  32. EXTERN char cddir[32][MAX_PATH];
  33. EXTERN char fullpath[1024];
  34. EXTERN float g_defaultscale;
  35. EXTERN float g_currentscale;
  36. EXTERN RadianEuler g_defaultrotation;
  37. EXTERN char defaulttexture[16][MAX_PATH];
  38. EXTERN char sourcetexture[16][MAX_PATH];
  39. EXTERN int numrep;
  40. EXTERN int flip_triangles;
  41. EXTERN float normal_blend;
  42. void *kalloc( int num, int size );
  43. struct s_trianglevert_t
  44. {
  45. int vertindex;
  46. int normindex; // index into normal array
  47. int s,t;
  48. float u,v;
  49. };
  50. struct s_boneweight_t
  51. {
  52. int numbones;
  53. int bone[MAXSTUDIOBONEWEIGHTS];
  54. float weight[MAXSTUDIOBONEWEIGHTS];
  55. };
  56. struct s_vertexinfo_t
  57. {
  58. // wtf is this doing here?
  59. int material;
  60. int firstref;
  61. int lastref;
  62. int flexmask;
  63. int numflex;
  64. int flexoffset;
  65. };
  66. struct s_tmpface_t
  67. {
  68. int material;
  69. unsigned long a, b, c;
  70. unsigned long ta, tb, tc;
  71. unsigned long na, nb, nc;
  72. };
  73. struct s_face_t
  74. {
  75. unsigned long a, b, c;
  76. };
  77. struct s_node_t
  78. {
  79. char name[MAXSTUDIONAME];
  80. int parent;
  81. };
  82. struct s_bone_t
  83. {
  84. Vector pos;
  85. RadianEuler rot;
  86. };
  87. struct s_texture_t
  88. {
  89. char name[MAX_PATH];
  90. int flags;
  91. int parent;
  92. int material;
  93. float width;
  94. float height;
  95. float dPdu;
  96. float dPdv;
  97. };
  98. EXTERN s_texture_t g_texture[MAXSTUDIOSKINS];
  99. EXTERN int g_numtextures;
  100. EXTERN int g_material[MAXSTUDIOSKINS]; // link into texture array
  101. EXTERN int g_nummaterials;
  102. EXTERN float g_gamma;
  103. EXTERN int g_numskinref;
  104. EXTERN int g_numskinfamilies;
  105. EXTERN int g_skinref[256][MAXSTUDIOSKINS]; // [skin][skinref], returns texture index
  106. EXTERN int g_numtexturegroups;
  107. EXTERN int g_numtexturelayers[32];
  108. EXTERN int g_numtexturereps[32];
  109. EXTERN int g_texturegroup[32][32][32];
  110. struct s_mesh_t
  111. {
  112. int numvertices;
  113. int vertexoffset;
  114. int numfaces;
  115. int faceoffset;
  116. };
  117. struct s_vertanim_t
  118. {
  119. int vertex;
  120. float speed;
  121. float side;
  122. Vector pos;
  123. Vector normal;
  124. };
  125. // processed aggregate lod pools
  126. struct s_loddata_t
  127. {
  128. int numvertices;
  129. s_boneweight_t *globalBoneweight;
  130. s_vertexinfo_t *vertexInfo;
  131. Vector *vertex;
  132. Vector *normal;
  133. Vector4D *tangentS;
  134. Vector2D *texcoord;
  135. int numfaces;
  136. s_face_t *face;
  137. s_mesh_t mesh[MAXSTUDIOSKINS];
  138. // remaps verts from an lod's source mesh to this all-lod processed aggregate pool
  139. int *pMeshVertIndexMaps[MAX_NUM_LODS];
  140. };
  141. // raw off-disk source files. Raw data should be not processed.
  142. struct s_source_t
  143. {
  144. char filename[MAX_PATH];
  145. int time; // time stamp
  146. bool isActiveModel;
  147. // local skeleton hierarchy
  148. int numbones;
  149. s_node_t localBone[MAXSTUDIOSRCBONES];
  150. matrix3x4_t boneToPose[MAXSTUDIOSRCBONES]; // converts bone local data into initial pose data
  151. // bone remapping
  152. int boneflags[MAXSTUDIOSRCBONES]; // attachment, vertex, etc flags for this bone
  153. int boneref[MAXSTUDIOSRCBONES]; // flags for this and child bones
  154. int boneLocalToGlobal[MAXSTUDIOSRCBONES]; // bonemap : local bone to world bone mapping
  155. int boneGlobalToLocal[MAXSTUDIOSRCBONES]; // boneimap : world bone to local bone mapping
  156. int texmap[MAXSTUDIOSKINS*4]; // map local MAX materials to unique textures
  157. // per material mesh
  158. int nummeshes;
  159. int meshindex[MAXSTUDIOSKINS]; // mesh to skin index
  160. s_mesh_t mesh[MAXSTUDIOSKINS];
  161. // model global copy of vertices
  162. int numvertices;
  163. s_boneweight_t *localBoneweight; // vertex info about local bone weighting
  164. s_boneweight_t *globalBoneweight; // vertex info about global bone weighting
  165. s_vertexinfo_t *vertexInfo; // generic vertex info
  166. Vector *vertex;
  167. Vector *normal;
  168. Vector4D *tangentS;
  169. Vector2D *texcoord;
  170. int numfaces;
  171. s_face_t *face; // vertex indexs per face
  172. // raw skeletal animation
  173. int numframes;
  174. int startframe;
  175. int endframe;
  176. s_bone_t *rawanim[MAXSTUDIOANIMFRAMES]; // [frame][bones];
  177. // vertex animation
  178. int *vanim_mapcount; // local verts map to N target verts
  179. int **vanim_map; // local vertices to target vertices mapping list
  180. int *vanim_flag; // local vert does animate
  181. int numvanims[MAXSTUDIOANIMFRAMES];
  182. s_vertanim_t *vanim[MAXSTUDIOANIMFRAMES]; // [frame][vertex]
  183. // processed aggregate lod data
  184. s_loddata_t *pLodData;
  185. };
  186. EXTERN int g_numsources;
  187. EXTERN s_source_t *g_source[MAXSTUDIOSEQUENCES];
  188. EXTERN int is_v1support;
  189. EXTERN int g_numverts;
  190. EXTERN Vector g_vertex[MAXSTUDIOVERTS];
  191. EXTERN s_boneweight_t g_bone[MAXSTUDIOVERTS];
  192. EXTERN int g_numnormals;
  193. EXTERN Vector g_normal[MAXSTUDIOVERTS];
  194. EXTERN int g_numtexcoords;
  195. EXTERN Vector2D g_texcoord[MAXSTUDIOVERTS];
  196. EXTERN int g_numfaces;
  197. EXTERN s_tmpface_t g_face[MAXSTUDIOTRIANGLES];
  198. EXTERN s_face_t g_src_uface[MAXSTUDIOTRIANGLES]; // max res unified faces
  199. struct v_unify_t
  200. {
  201. int refcount;
  202. int lastref;
  203. int firstref;
  204. int v;
  205. int m;
  206. int n;
  207. int t;
  208. v_unify_t *next;
  209. };
  210. EXTERN v_unify_t *v_list[MAXSTUDIOVERTS];
  211. EXTERN v_unify_t v_listdata[MAXSTUDIOVERTS];
  212. EXTERN int numvlist;
  213. int SortAndBalanceBones( int iCount, int iMaxCount, int bones[], float weights[] );
  214. void Grab_Vertexanimation( s_source_t *psource );
  215. extern void BuildIndividualMeshes( s_source_t *psource );