PowerVR Software Development Kit |
00001 /*!*************************************************************************** 00002 @File PVRTModelPOD.h 00003 00004 @Brief Code to load POD files - models exported from MAX. 00005 00006 @Author PowerVR 00007 00008 @Date February 2003 00009 00010 @Copyright Copyright 2003-2004 by Imagination Technologies Limited. 00011 All rights reserved. No part of this software, either 00012 material or conceptual may be copied or distributed, 00013 transmitted, transcribed, stored in a retrieval system 00014 or translated into any human or computer language in any 00015 form by any means, electronic, mechanical, manual or 00016 other-wise, or disclosed to third parties without the 00017 express written permission of Imagination Technologies 00018 Limited, Unit 8, HomePark Industrial Estate, 00019 King's Langley, Hertfordshire, WD4 8LZ, U.K. 00020 00021 @Platform ANSI compatible 00022 00023 @Description Code to load POD files - models exported from MAX. 00024 00025 $Revision: 1.38 $ 00026 *****************************************************************************/ 00027 #ifndef _PVRTMODELPOD_H_ 00028 #define _PVRTMODELPOD_H_ 00029 00030 00031 /**************************************************************************** 00032 ** Defines 00033 ****************************************************************************/ 00034 #define PVRTMODELPOD_VERSION ("AB.POD.2.0") 00035 00036 // PVRTMODELPOD Scene Flags 00037 #define PVRTMODELPODSF_FIXED (0x00000001) // Fixed-point 16.16 data (otherwise float) 00038 00039 /**************************************************************************** 00040 ** Enumerations 00041 ****************************************************************************/ 00042 enum EPODLight { 00043 ePODPoint, 00044 ePODDirectional 00045 }; 00046 00047 /**************************************************************************** 00048 ** Structures 00049 ****************************************************************************/ 00050 class CPODData { 00051 public: 00052 EPVRTDataType eType; 00053 unsigned int n; 00054 unsigned int nStride; 00055 unsigned char *pData; 00056 }; 00057 00058 struct SPODCamera { 00059 int nIdxTarget; 00060 VERTTYPE fFOV; 00061 VERTTYPE fFar; 00062 VERTTYPE fNear; 00063 VERTTYPE *pfAnimFOV; 00064 }; 00065 00066 struct SPODLight { 00067 int nIdxTarget; 00068 VERTTYPE pfColour[3]; 00069 EPODLight eType; 00070 }; 00071 00072 struct SPODMesh { 00073 unsigned int nNumVertex; 00074 unsigned int nNumFaces; 00075 unsigned int nNumUVW; 00076 CPODData sFaces; 00077 unsigned int *pnStripLength; 00078 unsigned int nNumStrips; 00079 CPODData sVertex; 00080 CPODData sNormals; 00081 CPODData sTangents; 00082 CPODData sBinormals; 00083 CPODData *psUVW; 00084 CPODData sVtxColours; 00085 CPODData sBoneIdx; 00086 CPODData sBoneWeight; 00088 unsigned char *pInterleaved; 00090 CPVRTBoneBatches sBoneBatches; 00091 }; 00092 00093 struct SPODNode { 00094 int nIdx; 00095 char *pszName; 00096 int nIdxMaterial; 00098 int nIdxParent; 00099 VERTTYPE pfPosition[3]; 00100 VERTTYPE pfRotation[4]; 00101 VERTTYPE pfScale[3]; 00103 VERTTYPE *pfAnimPosition; 00104 VERTTYPE *pfAnimRotation; 00105 VERTTYPE *pfAnimScale; 00106 }; 00107 00108 struct SPODTexture { 00109 char *pszName; 00110 }; 00111 00112 struct SPODMaterial { 00113 char *pszName; 00114 int nIdxTexDiffuse; 00115 VERTTYPE fMatOpacity; 00116 VERTTYPE pfMatAmbient[3]; 00117 VERTTYPE pfMatDiffuse[3]; 00118 VERTTYPE pfMatSpecular[3]; 00119 VERTTYPE fMatShininess; 00120 }; 00121 00122 struct SPODScene { 00123 VERTTYPE pfColourBackground[3]; 00124 VERTTYPE pfColourAmbient[3]; 00126 unsigned int nNumCamera; 00127 SPODCamera *pCamera; 00129 unsigned int nNumLight; 00130 SPODLight *pLight; 00132 unsigned int nNumMesh; 00133 SPODMesh *pMesh; 00135 unsigned int nNumNode; 00136 unsigned int nNumMeshNode; 00137 SPODNode *pNode; 00139 unsigned int nNumTexture; 00140 SPODTexture *pTexture; 00141 00142 unsigned int nNumMaterial; 00143 SPODMaterial *pMaterial; 00144 00145 unsigned int nNumFrame; 00146 unsigned int nFlags; 00147 }; 00148 00149 struct SPVRTPODImpl; // Internal implementation data 00150 00151 class CPVRTPODScene : public SPODScene { 00152 public: 00153 /*!*********************************************************************** 00154 @Function ReadFromFile 00155 @Input pszFileName Filename to load 00156 @Output pszExpOpt String in which to place exporter options 00157 @Input count Maximum number of characters to store. 00158 @Return TRUE if successful, FALSE if not 00159 @Description Loads the specified ".POD" file; returns the scene in 00160 pScene. This structure must later be destroyed with 00161 PVRTModelPODDestroy() to prevent memory leaks. 00162 ".POD" files are exported from 3D Studio MAX using a 00163 PowerVR plugin. 00164 If pszExpOpt is NULL, the scene is loaded; otherwise the 00165 scene is not loaded and pszExpOpt is filled in. 00166 *************************************************************************/ 00167 bool ReadFromFile( 00168 const char * const pszFileName, 00169 char * const pszExpOpt = NULL, 00170 const size_t count = 0); 00171 00172 /*!*********************************************************************** 00173 @Function ReadFromMemory 00174 @Input scene Scene data from the header file 00175 @Return TRUE if successful, FALSE if not 00176 @Description Sets the scene data from the supplied data structure. Use 00177 when loading from .H files. 00178 *************************************************************************/ 00179 bool ReadFromMemory( 00180 const SPODScene &scene); 00181 00182 #ifdef WIN32 00183 /*!*********************************************************************** 00184 @Function ReadFromResource 00185 @Input pszName Name of the resource to load from 00186 @Return TRUE if successful, FALSE if not 00187 @Description Loads the specified ".POD" file; returns the scene in 00188 pScene. This structure must later be destroyed with 00189 PVRTModelPODDestroy() to prevent memory leaks. 00190 ".POD" files are exported from 3D Studio MAX using a 00191 PowerVR plugin. 00192 *************************************************************************/ 00193 bool ReadFromResource( 00194 const TCHAR * const pszName); 00195 #endif 00196 00197 /*!*********************************************************************** 00198 @Function InitImpl 00199 @Description Used by the Read*() fns to initialise implementation 00200 details. Should also be called by applications which 00201 manually build data in the POD structures for rendering; 00202 in this case call it after the data has been created. 00203 Otherwise, do not call this function. 00204 *************************************************************************/ 00205 bool InitImpl(); 00206 00207 /*!*********************************************************************** 00208 @Function Destroy 00209 @Description Frees the memory allocated to store the scene in pScene. 00210 *************************************************************************/ 00211 void Destroy(); 00212 00213 /*!*********************************************************************** 00214 @Function SetFrame 00215 @Input fFrame Frame number 00216 @Description Set the animation frame for which subsequent Get*() calls 00217 should return data. 00218 *************************************************************************/ 00219 void SetFrame( 00220 const VERTTYPE fFrame); 00221 00222 /*!*********************************************************************** 00223 @Function GetRotationMatrix 00224 @Output mOut Rotation matrix 00225 @Input node Node to get the rotation matrix from 00226 @Description Generates the world matrix for the given Mesh Instance; 00227 applies the parent's transform too. Uses animation data. 00228 *************************************************************************/ 00229 void GetRotationMatrix( 00230 PVRTMATRIX &mOut, 00231 const SPODNode &node) const; 00232 00233 /*!*********************************************************************** 00234 @Function GetScalingMatrix 00235 @Output mOut Scaling matrix 00236 @Input node Node to get the rotation matrix from 00237 @Description Generates the world matrix for the given Mesh Instance; 00238 applies the parent's transform too. Uses animation data. 00239 *************************************************************************/ 00240 void GetScalingMatrix( 00241 PVRTMATRIX &mOut, 00242 const SPODNode &node) const; 00243 00244 /*!*********************************************************************** 00245 @Function GetTranslation 00246 @Output V Translation vector 00247 @Input node Node to get the translation vector from 00248 @Description Generates the translation vector for the given Mesh 00249 Instance. Uses animation data. 00250 *************************************************************************/ 00251 void GetTranslation( 00252 PVRTVECTOR3 &V, 00253 const SPODNode &node) const; 00254 00255 /*!*********************************************************************** 00256 @Function GetTranslationMatrix 00257 @Output mOut Translation matrix 00258 @Input node Node to get the translation matrix from 00259 @Description Generates the world matrix for the given Mesh Instance; 00260 applies the parent's transform too. Uses animation data. 00261 *************************************************************************/ 00262 void GetTranslationMatrix( 00263 PVRTMATRIX &mOut, 00264 const SPODNode &node) const; 00265 00266 /*!*********************************************************************** 00267 @Function GetWorldMatrixNoCache 00268 @Output mOut World matrix 00269 @Input node Node to get the world matrix from 00270 @Description Generates the world matrix for the given Mesh Instance; 00271 applies the parent's transform too. Uses animation data. 00272 *************************************************************************/ 00273 void GetWorldMatrixNoCache( 00274 PVRTMATRIX &mOut, 00275 const SPODNode &node) const; 00276 00277 /*!*********************************************************************** 00278 @Function GetWorldMatrix 00279 @Output mOut World matrix 00280 @Input node Node to get the world matrix from 00281 @Description Generates the world matrix for the given Mesh Instance; 00282 applies the parent's transform too. Uses animation data. 00283 *************************************************************************/ 00284 void GetWorldMatrix( 00285 PVRTMATRIX &mOut, 00286 const SPODNode &node) const; 00287 00288 /*!*********************************************************************** 00289 @Function GetBoneWorldMatrix 00290 @Output mOut Bone world matrix 00291 @Input NodeMesh Mesh to take the bone matrix from 00292 @Input NodeBone Bone to take the matrix from 00293 @Description Generates the world matrix for the given bone. 00294 *************************************************************************/ 00295 void GetBoneWorldMatrix( 00296 PVRTMATRIX &mOut, 00297 const SPODNode &NodeMesh, 00298 const SPODNode &NodeBone); 00299 00300 /*!*********************************************************************** 00301 @Function GetCamera 00302 @Output vFrom Position of the camera 00303 @Output vTo Target of the camera 00304 @Output vUp Up direction of the camera 00305 @Input nIdx Camera number 00306 @Return Camera horizontal FOV 00307 @Description Calculate the From, To and Up vectors for the given 00308 camera. Uses animation data. 00309 Note that even if the camera has a target, *pvTo is not 00310 the position of that target. *pvTo is a position in the 00311 correct direction of the target, one unit away from the 00312 camera. 00313 *************************************************************************/ 00314 VERTTYPE GetCamera( 00315 PVRTVECTOR3 &vFrom, 00316 PVRTVECTOR3 &vTo, 00317 PVRTVECTOR3 &vUp, 00318 const unsigned int nIdx) const; 00319 00320 /*!*********************************************************************** 00321 @Function GetCameraPos 00322 @Output vFrom Position of the camera 00323 @Output vTo Target of the camera 00324 @Input nIdx Camera number 00325 @Return Camera horizontal FOV 00326 @Description Calculate the position of the camera and its target. Uses 00327 animation data. 00328 If the queried camera does not have a target, *pvTo is 00329 not changed. 00330 *************************************************************************/ 00331 VERTTYPE GetCameraPos( 00332 PVRTVECTOR3 &vFrom, 00333 PVRTVECTOR3 &vTo, 00334 const unsigned int nIdx) const; 00335 00336 /*!*********************************************************************** 00337 @Function GetLight 00338 @Output vPos Position of the light 00339 @Output vDir Direction of the light 00340 @Input nIdx Light number 00341 @Description Calculate the position and direction of the given Light. 00342 Uses animation data. 00343 *************************************************************************/ 00344 void GetLight( 00345 PVRTVECTOR3 &vPos, 00346 PVRTVECTOR3 &vDir, 00347 const unsigned int nIdx) const; 00348 00349 /*!*********************************************************************** 00350 @Function CreateSkinIdxWeight 00351 @Output pIdx Four bytes containing matrix indices for vertex (0..255) (D3D: use UBYTE4) 00352 @Output pWeight Four bytes containing blend weights for vertex (0.0 .. 1.0) (D3D: use D3DCOLOR) 00353 @Input nVertexBones Number of bones this vertex uses 00354 @Input pnBoneIdx Pointer to 'nVertexBones' indices 00355 @Input pfBoneWeight Pointer to 'nVertexBones' blend weights 00356 @Description Creates the matrix indices and blend weights for a boned 00357 vertex. Call once per vertex of a boned mesh. 00358 *************************************************************************/ 00359 bool CreateSkinIdxWeight( 00360 char * const pIdx, 00361 char * const pWeight, 00362 const int nVertexBones, 00363 const int * const pnBoneIdx, 00364 const VERTTYPE * const pfBoneWeight); 00365 00366 /*!*********************************************************************** 00367 @Function SavePOD 00368 @Input pszFilename Filename to save to 00369 @Input pszExpOpt A string containing the options used by the exporter 00370 @Description Save a binary POD file (.POD). 00371 *************************************************************************/ 00372 bool SavePOD(const char * const pszFilename, const char * const pszExpOpt = 0); 00373 00374 /*!*********************************************************************** 00375 @Function SaveH 00376 @Input pszFilename Filename to save to 00377 @Input pszExpOpt A string containing the options used by the exporter 00378 @Description Save a header file (.H). 00379 *************************************************************************/ 00380 bool SaveH(const char * const pszFilename, const char * const pszExpOpt = 0); 00381 00382 private: 00383 SPVRTPODImpl *m_pImpl; 00384 }; 00385 00386 /**************************************************************************** 00387 ** Declarations 00388 ****************************************************************************/ 00389 00390 /*!*************************************************************************** 00391 @Function PVRTModelPODDataTypeSize 00392 @Input type Type to get the size of 00393 @Return Size of the data element 00394 @Description Returns the size of each data element. 00395 *****************************************************************************/ 00396 size_t PVRTModelPODDataTypeSize(const EPVRTDataType type); 00397 00398 /*!*************************************************************************** 00399 @Function PVRTModelPODDataTypeComponentCount 00400 @Input type Type to get the number of components from 00401 @Return number of components in the data element 00402 @Description Returns the number of components in a data element. 00403 *****************************************************************************/ 00404 size_t PVRTModelPODDataTypeComponentCount(const EPVRTDataType type); 00405 00406 /*!*************************************************************************** 00407 @Function PVRTModelPODDataStride 00408 @Input data Data elements 00409 @Return Size of the vector elements 00410 @Description Returns the size of the vector of data elements. 00411 *****************************************************************************/ 00412 size_t PVRTModelPODDataStride(const CPODData &data); 00413 00414 /*!*************************************************************************** 00415 @Function PVRTModelPODDataConvert 00416 @Modified data Data elements to convert 00417 @Input eNewType New type of elements 00418 @Input nCnt Number of elements 00419 @Description Convert the format of the array of vectors. 00420 *****************************************************************************/ 00421 void PVRTModelPODDataConvert(CPODData &data, const unsigned int nCnt, const EPVRTDataType eNewType); 00422 00423 /*!*************************************************************************** 00424 @Function PVRTModelPODDataShred 00425 @Modified data Data elements to modify 00426 @Input nCnt Number of elements 00427 @Input nMask Channel masks 00428 @Description Reduce the number of dimensions in 'data' using the channel 00429 masks in 'nMask'. 00430 *****************************************************************************/ 00431 void PVRTModelPODDataShred(CPODData &data, const unsigned int nCnt, const unsigned int nMask); 00432 00433 /*!*************************************************************************** 00434 @Function PVRTModelPODToggleInterleaved 00435 @Modified mesh Mesh to modify 00436 @Description Switches the supplied mesh to or from interleaved data format. 00437 *****************************************************************************/ 00438 void PVRTModelPODToggleInterleaved(SPODMesh &mesh); 00439 00440 /*!*************************************************************************** 00441 @Function PVRTModelPODDeIndex 00442 @Modified mesh Mesh to modify 00443 @Description De-indexes the supplied mesh. The mesh must be 00444 Interleaved before calling this function. 00445 *****************************************************************************/ 00446 void PVRTModelPODDeIndex(SPODMesh &mesh); 00447 00448 /*!*************************************************************************** 00449 @Function PVRTModelPODToggleStrips 00450 @Modified mesh Mesh to modify 00451 @Description Converts the supplied mesh to or from strips. 00452 *****************************************************************************/ 00453 void PVRTModelPODToggleStrips(SPODMesh &mesh); 00454 00455 /*!*************************************************************************** 00456 @Function PVRTModelPODCountIndices 00457 @Input mesh Mesh 00458 @Return Number of indices used by mesh 00459 @Description Counts the number of indices of a mesh 00460 *****************************************************************************/ 00461 unsigned int PVRTModelPODCountIndices(const SPODMesh &mesh); 00462 00463 /*!*************************************************************************** 00464 @Function PVRTModelPODToggleFixedPoint 00465 @Modified s Scene to modify 00466 @Description Switch all non-vertex data between fixed-point and 00467 floating-point. 00468 *****************************************************************************/ 00469 void PVRTModelPODToggleFixedPoint(SPODScene &s); 00470 00471 00472 #endif /* _PVRTMODELPOD_H_ */ 00473 00474 /***************************************************************************** 00475 End of file (PVRTModelPOD.h) 00476 *****************************************************************************/
Copyright © 1999-2006, PowerVR Technologies and partners. PowerVR Technologies is a division of Imagination Technologies Ltd.