PVRTModelPOD.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. /******************************************************************************
  2. @File PVRTModelPOD.h
  3. @Title PVRTModelPOD
  4. @Version
  5. @Copyright Copyright (C) Imagination Technologies Limited.
  6. @Platform ANSI compatible
  7. @Description Code to load POD files - models exported from MAX.
  8. ******************************************************************************/
  9. #ifndef _PVRTMODELPOD_H_
  10. #define _PVRTMODELPOD_H_
  11. #include "PVRTVector.h"
  12. #include "PVRTError.h"
  13. #include "PVRTVertex.h"
  14. #include "PVRTBoneBatch.h"
  15. /****************************************************************************
  16. ** Defines
  17. ****************************************************************************/
  18. #define PVRTMODELPOD_VERSION ("AB.POD.2.0") /*!< POD file version string */
  19. // PVRTMODELPOD Scene Flags
  20. #define PVRTMODELPODSF_FIXED (0x00000001) /*!< PVRTMODELPOD Fixed-point 16.16 data (otherwise float) flag */
  21. /****************************************************************************
  22. ** Enumerations
  23. ****************************************************************************/
  24. /*!****************************************************************************
  25. @Struct EPODLight
  26. @Brief Enum for the POD format light types
  27. ******************************************************************************/
  28. enum EPODLight
  29. {
  30. ePODPoint=0, /*!< Point light */
  31. ePODDirectional, /*!< Directional light */
  32. ePODSpot /*!< Spot light */
  33. };
  34. /*!****************************************************************************
  35. @Struct EPODPrimitiveType
  36. @Brief Enum for the POD format primitive types
  37. ******************************************************************************/
  38. enum EPODPrimitiveType
  39. {
  40. ePODTriangles=0, /*!< Triangles */
  41. ePODLines /*!< Lines*/
  42. };
  43. /*!****************************************************************************
  44. @Struct EPODAnimationData
  45. @Brief Enum for the POD format animation types
  46. ******************************************************************************/
  47. enum EPODAnimationData
  48. {
  49. ePODHasPositionAni = 0x01, /*!< Position animation */
  50. ePODHasRotationAni = 0x02, /*!< Rotation animation */
  51. ePODHasScaleAni = 0x04, /*!< Scale animation */
  52. ePODHasMatrixAni = 0x08 /*!< Matrix animation */
  53. };
  54. /*!****************************************************************************
  55. @Struct EPODMaterialFlags
  56. @Brief Enum for the material flag options
  57. ******************************************************************************/
  58. enum EPODMaterialFlags
  59. {
  60. ePODEnableBlending = 0x01, /*!< Enable blending for this material */
  61. };
  62. /*!****************************************************************************
  63. @Struct EPODBlendFunc
  64. @Brief Enum for the POD format blend functions
  65. ******************************************************************************/
  66. enum EPODBlendFunc
  67. {
  68. ePODBlendFunc_ZERO=0,
  69. ePODBlendFunc_ONE,
  70. ePODBlendFunc_BLEND_FACTOR,
  71. ePODBlendFunc_ONE_MINUS_BLEND_FACTOR,
  72. ePODBlendFunc_SRC_COLOR = 0x0300,
  73. ePODBlendFunc_ONE_MINUS_SRC_COLOR,
  74. ePODBlendFunc_SRC_ALPHA,
  75. ePODBlendFunc_ONE_MINUS_SRC_ALPHA,
  76. ePODBlendFunc_DST_ALPHA,
  77. ePODBlendFunc_ONE_MINUS_DST_ALPHA,
  78. ePODBlendFunc_DST_COLOR,
  79. ePODBlendFunc_ONE_MINUS_DST_COLOR,
  80. ePODBlendFunc_SRC_ALPHA_SATURATE,
  81. ePODBlendFunc_CONSTANT_COLOR = 0x8001,
  82. ePODBlendFunc_ONE_MINUS_CONSTANT_COLOR,
  83. ePODBlendFunc_CONSTANT_ALPHA,
  84. ePODBlendFunc_ONE_MINUS_CONSTANT_ALPHA
  85. };
  86. /*!****************************************************************************
  87. @Struct EPODBlendOp
  88. @Brief Enum for the POD format blend operation
  89. ******************************************************************************/
  90. enum EPODBlendOp
  91. {
  92. ePODBlendOp_ADD = 0x8006,
  93. ePODBlendOp_MIN,
  94. ePODBlendOp_MAX,
  95. ePODBlendOp_SUBTRACT = 0x800A,
  96. ePODBlendOp_REVERSE_SUBTRACT,
  97. };
  98. /****************************************************************************
  99. ** Structures
  100. ****************************************************************************/
  101. /*!****************************************************************************
  102. @Class CPODData
  103. @Brief A class for representing POD data
  104. ******************************************************************************/
  105. class CPODData {
  106. public:
  107. /*!***************************************************************************
  108. @Function Reset
  109. @Description Resets the POD Data to NULL
  110. *****************************************************************************/
  111. void Reset();
  112. public:
  113. EPVRTDataType eType; /*!< Type of data stored */
  114. unsigned int n; /*!< Number of values per vertex */
  115. unsigned int nStride; /*!< Distance in bytes from one array entry to the next */
  116. unsigned char *pData; /*!< Actual data (array of values); if mesh is interleaved, this is an OFFSET from pInterleaved */
  117. };
  118. /*!****************************************************************************
  119. @Struct SPODCamera
  120. @Brief Struct for storing POD camera data
  121. ******************************************************************************/
  122. struct SPODCamera {
  123. int nIdxTarget; /*!< Index of the target object */
  124. VERTTYPE fFOV; /*!< Field of view */
  125. VERTTYPE fFar; /*!< Far clip plane */
  126. VERTTYPE fNear; /*!< Near clip plane */
  127. VERTTYPE *pfAnimFOV; /*!< 1 VERTTYPE per frame of animation. */
  128. };
  129. /*!****************************************************************************
  130. @Struct SPODLight
  131. @Brief Struct for storing POD light data
  132. ******************************************************************************/
  133. struct SPODLight {
  134. int nIdxTarget; /*!< Index of the target object */
  135. VERTTYPE pfColour[3]; /*!< Light colour (0.0f -> 1.0f for each channel) */
  136. EPODLight eType; /*!< Light type (point, directional, spot etc.) */
  137. float fConstantAttenuation; /*!< Constant attenuation */
  138. float fLinearAttenuation; /*!< Linear atternuation */
  139. float fQuadraticAttenuation; /*!< Quadratic attenuation */
  140. float fFalloffAngle; /*!< Falloff angle (in radians) */
  141. float fFalloffExponent; /*!< Falloff exponent */
  142. };
  143. /*!****************************************************************************
  144. @Struct SPODMesh
  145. @Brief Struct for storing POD mesh data
  146. ******************************************************************************/
  147. struct SPODMesh {
  148. unsigned int nNumVertex; /*!< Number of vertices in the mesh */
  149. unsigned int nNumFaces; /*!< Number of triangles in the mesh */
  150. unsigned int nNumUVW; /*!< Number of texture coordinate channels per vertex */
  151. CPODData sFaces; /*!< List of triangle indices */
  152. unsigned int *pnStripLength; /*!< If mesh is stripped: number of tris per strip. */
  153. unsigned int nNumStrips; /*!< If mesh is stripped: number of strips, length of pnStripLength array. */
  154. CPODData sVertex; /*!< List of vertices (x0, y0, z0, x1, y1, z1, x2, etc...) */
  155. CPODData sNormals; /*!< List of vertex normals (Nx0, Ny0, Nz0, Nx1, Ny1, Nz1, Nx2, etc...) */
  156. CPODData sTangents; /*!< List of vertex tangents (Tx0, Ty0, Tz0, Tx1, Ty1, Tz1, Tx2, etc...) */
  157. CPODData sBinormals; /*!< List of vertex binormals (Bx0, By0, Bz0, Bx1, By1, Bz1, Bx2, etc...) */
  158. CPODData *psUVW; /*!< List of UVW coordinate sets; size of array given by 'nNumUVW' */
  159. CPODData sVtxColours; /*!< A colour per vertex */
  160. CPODData sBoneIdx; /*!< nNumBones*nNumVertex ints (Vtx0Idx0, Vtx0Idx1, ... Vtx1Idx0, Vtx1Idx1, ...) */
  161. CPODData sBoneWeight; /*!< nNumBones*nNumVertex floats (Vtx0Wt0, Vtx0Wt1, ... Vtx1Wt0, Vtx1Wt1, ...) */
  162. unsigned char *pInterleaved; /*!< Interleaved vertex data */
  163. CPVRTBoneBatches sBoneBatches; /*!< Bone tables */
  164. EPODPrimitiveType ePrimitiveType; /*!< Primitive type used by this mesh */
  165. PVRTMATRIX mUnpackMatrix; /*!< A matrix used for unscaling scaled vertex data created with PVRTModelPODScaleAndConvertVtxData*/
  166. };
  167. /*!****************************************************************************
  168. @Struct SPODNode
  169. @Brief Struct for storing POD node data
  170. ******************************************************************************/
  171. struct SPODNode {
  172. int nIdx; /*!< Index into mesh, light or camera array, depending on which object list contains this Node */
  173. char *pszName; /*!< Name of object */
  174. int nIdxMaterial; /*!< Index of material used on this mesh */
  175. int nIdxParent; /*!< Index into MeshInstance array; recursively apply ancestor's transforms after this instance's. */
  176. unsigned int nAnimFlags; /*!< Stores which animation arrays the POD Node contains */
  177. unsigned int* pnAnimPositionIdx;
  178. VERTTYPE *pfAnimPosition; /*!< 3 floats per frame of animation. */
  179. unsigned int* pnAnimRotationIdx;
  180. VERTTYPE *pfAnimRotation; /*!< 4 floats per frame of animation. */
  181. unsigned int* pnAnimScaleIdx;
  182. VERTTYPE *pfAnimScale; /*!< 7 floats per frame of animation. */
  183. unsigned int* pnAnimMatrixIdx;
  184. VERTTYPE *pfAnimMatrix; /*!< 16 floats per frame of animation. */
  185. };
  186. /*!****************************************************************************
  187. @Struct SPODTexture
  188. @Brief Struct for storing POD texture data
  189. ******************************************************************************/
  190. struct SPODTexture {
  191. char *pszName; /*!< File-name of texture */
  192. };
  193. /*!****************************************************************************
  194. @Struct SPODMaterial
  195. @Brief Struct for storing POD material data
  196. ******************************************************************************/
  197. struct SPODMaterial {
  198. char *pszName; /*!< Name of material */
  199. int nIdxTexDiffuse; /*!< Idx into pTexture for the diffuse texture */
  200. int nIdxTexAmbient; /*!< Idx into pTexture for the ambient texture */
  201. int nIdxTexSpecularColour; /*!< Idx into pTexture for the specular colour texture */
  202. int nIdxTexSpecularLevel; /*!< Idx into pTexture for the specular level texture */
  203. int nIdxTexBump; /*!< Idx into pTexture for the bump map */
  204. int nIdxTexEmissive; /*!< Idx into pTexture for the emissive texture */
  205. int nIdxTexGlossiness; /*!< Idx into pTexture for the glossiness texture */
  206. int nIdxTexOpacity; /*!< Idx into pTexture for the opacity texture */
  207. int nIdxTexReflection; /*!< Idx into pTexture for the reflection texture */
  208. int nIdxTexRefraction; /*!< Idx into pTexture for the refraction texture */
  209. VERTTYPE fMatOpacity; /*!< Material opacity (used with vertex alpha ?) */
  210. VERTTYPE pfMatAmbient[3]; /*!< Ambient RGB value */
  211. VERTTYPE pfMatDiffuse[3]; /*!< Diffuse RGB value */
  212. VERTTYPE pfMatSpecular[3]; /*!< Specular RGB value */
  213. VERTTYPE fMatShininess; /*!< Material shininess */
  214. char *pszEffectFile; /*!< Name of effect file */
  215. char *pszEffectName; /*!< Name of effect in the effect file */
  216. EPODBlendFunc eBlendSrcRGB; /*!< Blending RGB source value */
  217. EPODBlendFunc eBlendSrcA; /*!< Blending alpha source value */
  218. EPODBlendFunc eBlendDstRGB; /*!< Blending RGB destination value */
  219. EPODBlendFunc eBlendDstA; /*!< Blending alpha destination value */
  220. EPODBlendOp eBlendOpRGB; /*!< Blending RGB operation */
  221. EPODBlendOp eBlendOpA; /*!< Blending alpha operation */
  222. VERTTYPE pfBlendColour[4]; /*!< A RGBA colour to be used in blending */
  223. VERTTYPE pfBlendFactor[4]; /*!< An array of blend factors, one for each RGBA component */
  224. unsigned int nFlags; /*!< Stores information about the material e.g. Enable blending */
  225. };
  226. /*!****************************************************************************
  227. @Struct SPODScene
  228. @Brief Struct for storing POD scene data
  229. ******************************************************************************/
  230. struct SPODScene {
  231. VERTTYPE pfColourBackground[3]; /*!< Background colour */
  232. VERTTYPE pfColourAmbient[3]; /*!< Ambient colour */
  233. unsigned int nNumCamera; /*!< The length of the array pCamera */
  234. SPODCamera *pCamera; /*!< Camera nodes array */
  235. unsigned int nNumLight; /*!< The length of the array pLight */
  236. SPODLight *pLight; /*!< Light nodes array */
  237. unsigned int nNumMesh; /*!< The length of the array pMesh */
  238. SPODMesh *pMesh; /*!< Mesh array. Meshes may be instanced several times in a scene; i.e. multiple Nodes may reference any given mesh. */
  239. unsigned int nNumNode; /*!< Number of items in the array pNode */
  240. unsigned int nNumMeshNode; /*!< Number of items in the array pNode which are objects */
  241. SPODNode *pNode; /*!< Node array. Sorted as such: objects, lights, cameras, Everything Else (bones, helpers etc) */
  242. unsigned int nNumTexture; /*!< Number of textures in the array pTexture */
  243. SPODTexture *pTexture; /*!< Texture array */
  244. unsigned int nNumMaterial; /*!< Number of materials in the array pMaterial */
  245. SPODMaterial *pMaterial; /*!< Material array */
  246. unsigned int nNumFrame; /*!< Number of frames of animation */
  247. unsigned int nFPS; /*!< The frames per second the animation should be played at */
  248. unsigned int nFlags; /*!< PVRTMODELPODSF_* bit-flags */
  249. };
  250. struct SPVRTPODImpl; // Internal implementation data
  251. /*!***************************************************************************
  252. @Class CPVRTModelPOD
  253. @Brief A class for loading and storing data from POD files/headers
  254. *****************************************************************************/
  255. class CPVRTModelPOD : public SPODScene{
  256. public:
  257. /*!***************************************************************************
  258. @Function Constructor
  259. @Description Constructor for CPVRTModelPOD class
  260. *****************************************************************************/
  261. CPVRTModelPOD();
  262. /*!***************************************************************************
  263. @Function Destructor
  264. @Description Destructor for CPVRTModelPOD class
  265. *****************************************************************************/
  266. ~CPVRTModelPOD();
  267. /*!***************************************************************************
  268. @Function ReadFromFile
  269. @Input pszFileName Filename to load
  270. @Output pszExpOpt String in which to place exporter options
  271. @Input count Maximum number of characters to store.
  272. @Output pszHistory String in which to place the pod file history
  273. @Input historyCount Maximum number of characters to store.
  274. @Return PVR_SUCCESS if successful, PVR_FAIL if not
  275. @Description Loads the specified ".POD" file; returns the scene in
  276. pScene. This structure must later be destroyed with
  277. PVRTModelPODDestroy() to prevent memory leaks.
  278. ".POD" files are exported using the PVRGeoPOD exporters.
  279. If pszExpOpt is NULL, the scene is loaded; otherwise the
  280. scene is not loaded and pszExpOpt is filled in. The same
  281. is true for pszHistory.
  282. *****************************************************************************/
  283. EPVRTError ReadFromFile(
  284. const char * const pszFileName,
  285. char * const pszExpOpt = NULL,
  286. const size_t count = 0,
  287. char * const pszHistory = NULL,
  288. const size_t historyCount = 0);
  289. /*!***************************************************************************
  290. @Function ReadFromMemory
  291. @Input pData Data to load
  292. @Input i32Size Size of data
  293. @Output pszExpOpt String in which to place exporter options
  294. @Input count Maximum number of characters to store.
  295. @Output pszHistory String in which to place the pod file history
  296. @Input historyCount Maximum number of characters to store.
  297. @Return PVR_SUCCESS if successful, PVR_FAIL if not
  298. @Description Loads the supplied pod data. This data can be exported
  299. directly to a header using one of the pod exporters.
  300. If pszExpOpt is NULL, the scene is loaded; otherwise the
  301. scene is not loaded and pszExpOpt is filled in. The same
  302. is true for pszHistory.
  303. *****************************************************************************/
  304. EPVRTError ReadFromMemory(
  305. const char * pData,
  306. const size_t i32Size,
  307. char * const pszExpOpt = NULL,
  308. const size_t count = NULL,
  309. char * const pszHistory = NULL,
  310. const size_t historyCount = NULL);
  311. /*!***************************************************************************
  312. @Function ReadFromMemory
  313. @Input scene Scene data from the header file
  314. @Return PVR_SUCCESS if successful, PVR_FAIL if not
  315. @Description Sets the scene data from the supplied data structure. Use
  316. when loading from .H files.
  317. *****************************************************************************/
  318. EPVRTError ReadFromMemory(
  319. const SPODScene &scene);
  320. /*!***************************************************************************
  321. @Function CopyFromMemory
  322. @Input scene Scene data from the header file
  323. @Return PVR_SUCCESS if successful, PVR_FAIL if not
  324. @Description Copies the scene data from the supplied data structure. Use
  325. when loading from .H files where you want to modify the data.
  326. *****************************************************************************/
  327. EPVRTError CopyFromMemory(
  328. const SPODScene &scene);
  329. #if defined(WIN32) && !defined(__BADA__)
  330. /*!***************************************************************************
  331. @Function ReadFromResource
  332. @Input pszName Name of the resource to load from
  333. @Return PVR_SUCCESS if successful, PVR_FAIL if not
  334. @Description Loads the specified ".POD" file; returns the scene in
  335. pScene. This structure must later be destroyed with
  336. PVRTModelPODDestroy() to prevent memory leaks.
  337. ".POD" files are exported from 3D Studio MAX using a
  338. PowerVR plugin.
  339. *****************************************************************************/
  340. EPVRTError ReadFromResource(
  341. const TCHAR * const pszName);
  342. #endif
  343. /*!***********************************************************************
  344. @Function InitImpl
  345. @Description Used by the Read*() fns to initialise implementation
  346. details. Should also be called by applications which
  347. manually build data in the POD structures for rendering;
  348. in this case call it after the data has been created.
  349. Otherwise, do not call this function.
  350. *************************************************************************/
  351. EPVRTError InitImpl();
  352. /*!***********************************************************************
  353. @Function DestroyImpl
  354. @Description Used to free memory allocated by the implementation.
  355. *************************************************************************/
  356. void DestroyImpl();
  357. /*!***********************************************************************
  358. @Function FlushCache
  359. @Description Clears the matrix cache; use this if necessary when you
  360. edit the position or animation of a node.
  361. *************************************************************************/
  362. void FlushCache();
  363. /*!***************************************************************************
  364. @Function Destroy
  365. @Description Frees the memory allocated to store the scene in pScene.
  366. *****************************************************************************/
  367. void Destroy();
  368. /*!***************************************************************************
  369. @Function SetFrame
  370. @Input fFrame Frame number
  371. @Description Set the animation frame for which subsequent Get*() calls
  372. should return data.
  373. *****************************************************************************/
  374. void SetFrame(
  375. const VERTTYPE fFrame);
  376. /*!***************************************************************************
  377. @Function GetRotationMatrix
  378. @Output mOut Rotation matrix
  379. @Input node Node to get the rotation matrix from
  380. @Description Generates the world matrix for the given Mesh Instance;
  381. applies the parent's transform too. Uses animation data.
  382. *****************************************************************************/
  383. void GetRotationMatrix(
  384. PVRTMATRIX &mOut,
  385. const SPODNode &node) const;
  386. /*!***************************************************************************
  387. @Function GetRotationMatrix
  388. @Input node Node to get the rotation matrix from
  389. @Returns Rotation matrix
  390. @Description Generates the world matrix for the given Mesh Instance;
  391. applies the parent's transform too. Uses animation data.
  392. *****************************************************************************/
  393. PVRTMat4 GetRotationMatrix(
  394. const SPODNode &node) const;
  395. /*!***************************************************************************
  396. @Function GetScalingMatrix
  397. @Output mOut Scaling matrix
  398. @Input node Node to get the rotation matrix from
  399. @Description Generates the world matrix for the given Mesh Instance;
  400. applies the parent's transform too. Uses animation data.
  401. *****************************************************************************/
  402. void GetScalingMatrix(
  403. PVRTMATRIX &mOut,
  404. const SPODNode &node) const;
  405. /*!***************************************************************************
  406. @Function GetScalingMatrix
  407. @Input node Node to get the rotation matrix from
  408. @Returns Scaling matrix
  409. @Description Generates the world matrix for the given Mesh Instance;
  410. applies the parent's transform too. Uses animation data.
  411. *****************************************************************************/
  412. PVRTMat4 GetScalingMatrix(
  413. const SPODNode &node) const;
  414. /*!***************************************************************************
  415. @Function GetTranslation
  416. @Output V Translation vector
  417. @Input node Node to get the translation vector from
  418. @Description Generates the translation vector for the given Mesh
  419. Instance. Uses animation data.
  420. *****************************************************************************/
  421. void GetTranslation(
  422. PVRTVECTOR3 &V,
  423. const SPODNode &node) const;
  424. /*!***************************************************************************
  425. @Function GetTranslation
  426. @Input node Node to get the translation vector from
  427. @Returns Translation vector
  428. @Description Generates the translation vector for the given Mesh
  429. Instance. Uses animation data.
  430. *****************************************************************************/
  431. PVRTVec3 GetTranslation(
  432. const SPODNode &node) const;
  433. /*!***************************************************************************
  434. @Function GetTranslationMatrix
  435. @Output mOut Translation matrix
  436. @Input node Node to get the translation matrix from
  437. @Description Generates the world matrix for the given Mesh Instance;
  438. applies the parent's transform too. Uses animation data.
  439. *****************************************************************************/
  440. void GetTranslationMatrix(
  441. PVRTMATRIX &mOut,
  442. const SPODNode &node) const;
  443. /*!***************************************************************************
  444. @Function GetTranslationMatrix
  445. @Input node Node to get the translation matrix from
  446. @Returns Translation matrix
  447. @Description Generates the world matrix for the given Mesh Instance;
  448. applies the parent's transform too. Uses animation data.
  449. *****************************************************************************/
  450. PVRTMat4 GetTranslationMatrix(
  451. const SPODNode &node) const;
  452. /*!***************************************************************************
  453. @Function GetTransformationMatrix
  454. @Output mOut Transformation matrix
  455. @Input node Node to get the transformation matrix from
  456. @Description Generates the world matrix for the given Mesh Instance;
  457. applies the parent's transform too. Uses animation data.
  458. *****************************************************************************/
  459. void GetTransformationMatrix(PVRTMATRIX &mOut, const SPODNode &node) const;
  460. /*!***************************************************************************
  461. @Function GetWorldMatrixNoCache
  462. @Output mOut World matrix
  463. @Input node Node to get the world matrix from
  464. @Description Generates the world matrix for the given Mesh Instance;
  465. applies the parent's transform too. Uses animation data.
  466. *****************************************************************************/
  467. void GetWorldMatrixNoCache(
  468. PVRTMATRIX &mOut,
  469. const SPODNode &node) const;
  470. /*!***************************************************************************
  471. @Function GetWorldMatrixNoCache
  472. @Input node Node to get the world matrix from
  473. @Returns World matrix
  474. @Description Generates the world matrix for the given Mesh Instance;
  475. applies the parent's transform too. Uses animation data.
  476. *****************************************************************************/
  477. PVRTMat4 GetWorldMatrixNoCache(
  478. const SPODNode &node) const;
  479. /*!***************************************************************************
  480. @Function GetWorldMatrix
  481. @Output mOut World matrix
  482. @Input node Node to get the world matrix from
  483. @Description Generates the world matrix for the given Mesh Instance;
  484. applies the parent's transform too. Uses animation data.
  485. *****************************************************************************/
  486. void GetWorldMatrix(
  487. PVRTMATRIX &mOut,
  488. const SPODNode &node) const;
  489. /*!***************************************************************************
  490. @Function GetWorldMatrix
  491. @Input node Node to get the world matrix from
  492. @Returns World matrix
  493. @Description Generates the world matrix for the given Mesh Instance;
  494. applies the parent's transform too. Uses animation data.
  495. *****************************************************************************/
  496. PVRTMat4 GetWorldMatrix(const SPODNode& node) const;
  497. /*!***************************************************************************
  498. @Function GetBoneWorldMatrix
  499. @Output mOut Bone world matrix
  500. @Input NodeMesh Mesh to take the bone matrix from
  501. @Input NodeBone Bone to take the matrix from
  502. @Description Generates the world matrix for the given bone.
  503. *****************************************************************************/
  504. void GetBoneWorldMatrix(
  505. PVRTMATRIX &mOut,
  506. const SPODNode &NodeMesh,
  507. const SPODNode &NodeBone);
  508. /*!***************************************************************************
  509. @Function GetBoneWorldMatrix
  510. @Input NodeMesh Mesh to take the bone matrix from
  511. @Input NodeBone Bone to take the matrix from
  512. @Returns Bone world matrix
  513. @Description Generates the world matrix for the given bone.
  514. *****************************************************************************/
  515. PVRTMat4 GetBoneWorldMatrix(
  516. const SPODNode &NodeMesh,
  517. const SPODNode &NodeBone);
  518. /*!***************************************************************************
  519. @Function GetCamera
  520. @Output vFrom Position of the camera
  521. @Output vTo Target of the camera
  522. @Output vUp Up direction of the camera
  523. @Input nIdx Camera number
  524. @Return Camera horizontal FOV
  525. @Description Calculate the From, To and Up vectors for the given
  526. camera. Uses animation data.
  527. Note that even if the camera has a target, *pvTo is not
  528. the position of that target. *pvTo is a position in the
  529. correct direction of the target, one unit away from the
  530. camera.
  531. *****************************************************************************/
  532. VERTTYPE GetCamera(
  533. PVRTVECTOR3 &vFrom,
  534. PVRTVECTOR3 &vTo,
  535. PVRTVECTOR3 &vUp,
  536. const unsigned int nIdx) const;
  537. /*!***************************************************************************
  538. @Function GetCameraPos
  539. @Output vFrom Position of the camera
  540. @Output vTo Target of the camera
  541. @Input nIdx Camera number
  542. @Return Camera horizontal FOV
  543. @Description Calculate the position of the camera and its target. Uses
  544. animation data.
  545. If the queried camera does not have a target, *pvTo is
  546. not changed.
  547. *****************************************************************************/
  548. VERTTYPE GetCameraPos(
  549. PVRTVECTOR3 &vFrom,
  550. PVRTVECTOR3 &vTo,
  551. const unsigned int nIdx) const;
  552. /*!***************************************************************************
  553. @Function GetLight
  554. @Output vPos Position of the light
  555. @Output vDir Direction of the light
  556. @Input nIdx Light number
  557. @Description Calculate the position and direction of the given Light.
  558. Uses animation data.
  559. *****************************************************************************/
  560. void GetLight(
  561. PVRTVECTOR3 &vPos,
  562. PVRTVECTOR3 &vDir,
  563. const unsigned int nIdx) const;
  564. /*!***************************************************************************
  565. @Function GetLightPosition
  566. @Input u32Idx Light number
  567. @Return PVRTVec4 position of light with w set correctly
  568. @Description Calculate the position the given Light. Uses animation data.
  569. *****************************************************************************/
  570. PVRTVec4 GetLightPosition(const unsigned int u32Idx) const;
  571. /*!***************************************************************************
  572. @Function GetLightDirection
  573. @Input u32Idx Light number
  574. @Return PVRTVec4 direction of light with w set correctly
  575. @Description Calculate the direction of the given Light. Uses animation data.
  576. *****************************************************************************/
  577. PVRTVec4 GetLightDirection(const unsigned int u32Idx) const;
  578. /*!***************************************************************************
  579. @Function CreateSkinIdxWeight
  580. @Output pIdx Four bytes containing matrix indices for vertex (0..255) (D3D: use UBYTE4)
  581. @Output pWeight Four bytes containing blend weights for vertex (0.0 .. 1.0) (D3D: use D3DCOLOR)
  582. @Input nVertexBones Number of bones this vertex uses
  583. @Input pnBoneIdx Pointer to 'nVertexBones' indices
  584. @Input pfBoneWeight Pointer to 'nVertexBones' blend weights
  585. @Description Creates the matrix indices and blend weights for a boned
  586. vertex. Call once per vertex of a boned mesh.
  587. *****************************************************************************/
  588. EPVRTError CreateSkinIdxWeight(
  589. char * const pIdx,
  590. char * const pWeight,
  591. const int nVertexBones,
  592. const int * const pnBoneIdx,
  593. const VERTTYPE * const pfBoneWeight);
  594. /*!***************************************************************************
  595. @Function SavePOD
  596. @Input pszFilename Filename to save to
  597. @Input pszExpOpt A string containing the options used by the exporter
  598. @Input pszHistory A string containing the history of the exported pod file
  599. @Description Save a binary POD file (.POD).
  600. *****************************************************************************/
  601. EPVRTError SavePOD(const char * const pszFilename, const char * const pszExpOpt = 0, const char * const pszHistory = 0);
  602. private:
  603. SPVRTPODImpl *m_pImpl; /*!< Internal implementation data */
  604. };
  605. /****************************************************************************
  606. ** Declarations
  607. ****************************************************************************/
  608. /*!***************************************************************************
  609. @Function PVRTModelPODDataTypeSize
  610. @Input type Type to get the size of
  611. @Return Size of the data element
  612. @Description Returns the size of each data element.
  613. *****************************************************************************/
  614. size_t PVRTModelPODDataTypeSize(const EPVRTDataType type);
  615. /*!***************************************************************************
  616. @Function PVRTModelPODDataTypeComponentCount
  617. @Input type Type to get the number of components from
  618. @Return number of components in the data element
  619. @Description Returns the number of components in a data element.
  620. *****************************************************************************/
  621. size_t PVRTModelPODDataTypeComponentCount(const EPVRTDataType type);
  622. /*!***************************************************************************
  623. @Function PVRTModelPODDataStride
  624. @Input data Data elements
  625. @Return Size of the vector elements
  626. @Description Returns the size of the vector of data elements.
  627. *****************************************************************************/
  628. size_t PVRTModelPODDataStride(const CPODData &data);
  629. /*!***************************************************************************
  630. @Function PVRTModelPODGetAnimArraySize
  631. @Input pAnimDataIdx
  632. @Input ui32Frames
  633. @Input ui32Components
  634. @Return Size of the animation array
  635. @Description Calculates the size of an animation array
  636. *****************************************************************************/
  637. unsigned int PVRTModelPODGetAnimArraySize(unsigned int *pAnimDataIdx, unsigned int ui32Frames, unsigned int ui32Components);
  638. /*!***************************************************************************
  639. @Function PVRTModelPODScaleAndConvertVtxData
  640. @Modified mesh POD mesh to scale and convert the mesh data
  641. @Input eNewType The data type to scale and convert the vertex data to
  642. @Return PVR_SUCCESS on success and PVR_FAIL on failure.
  643. @Description Scales the vertex data to fit within the range of the requested
  644. data type and then converts the data to that type. This function
  645. isn't currently compiled in for fixed point builds of the tools.
  646. *****************************************************************************/
  647. #if !defined(PVRT_FIXED_POINT_ENABLE)
  648. EPVRTError PVRTModelPODScaleAndConvertVtxData(SPODMesh &mesh, const EPVRTDataType eNewType);
  649. #endif
  650. /*!***************************************************************************
  651. @Function PVRTModelPODDataConvert
  652. @Modified data Data elements to convert
  653. @Input eNewType New type of elements
  654. @Input nCnt Number of elements
  655. @Description Convert the format of the array of vectors.
  656. *****************************************************************************/
  657. void PVRTModelPODDataConvert(CPODData &data, const unsigned int nCnt, const EPVRTDataType eNewType);
  658. /*!***************************************************************************
  659. @Function PVRTModelPODDataShred
  660. @Modified data Data elements to modify
  661. @Input nCnt Number of elements
  662. @Input pChannels A list of the wanted channels, e.g. {'x', 'y', 0}
  663. @Description Reduce the number of dimensions in 'data' using the requested
  664. channel array. The array should have a maximum length of 4
  665. or be null terminated if less channels are wanted. Supported
  666. elements are 'x','y','z' and 'w'. They must be defined in lower
  667. case. It is also possible to negate an element, e.g. {'x','y', -'z'}.
  668. *****************************************************************************/
  669. void PVRTModelPODDataShred(CPODData &data, const unsigned int nCnt, const int *pChannels);
  670. /*!***************************************************************************
  671. @Function PVRTModelPODReorderFaces
  672. @Modified mesh The mesh to re-order the faces of
  673. @Input i32El1 The first index to be written out
  674. @Input i32El2 The second index to be written out
  675. @Input i32El3 The third index to be written out
  676. @Description Reorders the face indices of a mesh.
  677. *****************************************************************************/
  678. void PVRTModelPODReorderFaces(SPODMesh &mesh, const int i32El1, const int i32El2, const int i32El3);
  679. /*!***************************************************************************
  680. @Function PVRTModelPODToggleInterleaved
  681. @Modified mesh Mesh to modify
  682. @Input ui32AlignToNBytes Align the interleaved data to this no. of bytes.
  683. @Description Switches the supplied mesh to or from interleaved data format.
  684. *****************************************************************************/
  685. void PVRTModelPODToggleInterleaved(SPODMesh &mesh, unsigned int ui32AlignToNBytes = 1);
  686. /*!***************************************************************************
  687. @Function PVRTModelPODDeIndex
  688. @Modified mesh Mesh to modify
  689. @Description De-indexes the supplied mesh. The mesh must be
  690. Interleaved before calling this function.
  691. *****************************************************************************/
  692. void PVRTModelPODDeIndex(SPODMesh &mesh);
  693. /*!***************************************************************************
  694. @Function PVRTModelPODToggleStrips
  695. @Modified mesh Mesh to modify
  696. @Description Converts the supplied mesh to or from strips.
  697. *****************************************************************************/
  698. void PVRTModelPODToggleStrips(SPODMesh &mesh);
  699. /*!***************************************************************************
  700. @Function PVRTModelPODCountIndices
  701. @Input mesh Mesh
  702. @Return Number of indices used by mesh
  703. @Description Counts the number of indices of a mesh
  704. *****************************************************************************/
  705. unsigned int PVRTModelPODCountIndices(const SPODMesh &mesh);
  706. /*!***************************************************************************
  707. @Function PVRTModelPODToggleFixedPoint
  708. @Modified s Scene to modify
  709. @Description Switch all non-vertex data between fixed-point and
  710. floating-point.
  711. *****************************************************************************/
  712. void PVRTModelPODToggleFixedPoint(SPODScene &s);
  713. /*!***************************************************************************
  714. @Function PVRTModelPODCopyCPODData
  715. @Input in
  716. @Output out
  717. @Input ui32No
  718. @Input bInterleaved
  719. @Description Used to copy a CPODData of a mesh
  720. *****************************************************************************/
  721. void PVRTModelPODCopyCPODData(const CPODData &in, CPODData &out, unsigned int ui32No, bool bInterleaved);
  722. /*!***************************************************************************
  723. @Function PVRTModelPODCopyNode
  724. @Input in
  725. @Output out
  726. @Input nNumFrames The number of animation frames
  727. @Description Used to copy a pod node
  728. *****************************************************************************/
  729. void PVRTModelPODCopyNode(const SPODNode &in, SPODNode &out, int nNumFrames);
  730. /*!***************************************************************************
  731. @Function PVRTModelPODCopyMesh
  732. @Input in
  733. @Output out
  734. @Description Used to copy a pod mesh
  735. *****************************************************************************/
  736. void PVRTModelPODCopyMesh(const SPODMesh &in, SPODMesh &out);
  737. /*!***************************************************************************
  738. @Function PVRTModelPODCopyTexture
  739. @Input in
  740. @Output out
  741. @Description Used to copy a pod texture
  742. *****************************************************************************/
  743. void PVRTModelPODCopyTexture(const SPODTexture &in, SPODTexture &out);
  744. /*!***************************************************************************
  745. @Function PVRTModelPODCopyMaterial
  746. @Input in
  747. @Output out
  748. @Description Used to copy a pod material
  749. *****************************************************************************/
  750. void PVRTModelPODCopyMaterial(const SPODMaterial &in, SPODMaterial &out);
  751. /*!***************************************************************************
  752. @Function PVRTModelPODCopyCamera
  753. @Input in
  754. @Output out
  755. @Input nNumFrames The number of animation frames
  756. @Description Used to copy a pod camera
  757. *****************************************************************************/
  758. void PVRTModelPODCopyCamera(const SPODCamera &in, SPODCamera &out, int nNumFrames);
  759. /*!***************************************************************************
  760. @Function PVRTModelPODCopyLight
  761. @Input in
  762. @Output out
  763. @Description Used to copy a pod light
  764. *****************************************************************************/
  765. void PVRTModelPODCopyLight(const SPODLight &in, SPODLight &out);
  766. /*!***************************************************************************
  767. @Function PVRTModelPODFlattenToWorldSpace
  768. @Input in - Source scene. All meshes must not be interleaved.
  769. @Output out
  770. @Description Used to flatten a pod scene to world space. All animation
  771. and skinning information will be removed. The returned
  772. position, normal, binormals and tangent data if present
  773. will be returned as floats regardless of the input data
  774. type.
  775. *****************************************************************************/
  776. EPVRTError PVRTModelPODFlattenToWorldSpace(CPVRTModelPOD &in, CPVRTModelPOD &out);
  777. #endif /* _PVRTMODELPOD_H_ */
  778. /*****************************************************************************
  779. End of file (PVRTModelPOD.h)
  780. *****************************************************************************/