| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- /*
- Open Asset Import Library (ASSIMP)
- ----------------------------------------------------------------------
- Copyright (c) 2006-2008, ASSIMP Development Team
- All rights reserved.
- Redistribution and use of this software in source and binary forms,
- with or without modification, are permitted provided that the
- following conditions are met:
- * Redistributions of source code must retain the above
- copyright notice, this list of conditions and the
- following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the
- following disclaimer in the documentation and/or other
- materials provided with the distribution.
- * Neither the name of the ASSIMP team, nor the names of its
- contributors may be used to endorse or promote products
- derived from this software without specific prior
- written permission of the ASSIMP Development Team.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ----------------------------------------------------------------------
- */
- //!
- //! @file Definition of MDL importer class
- //!
- #ifndef AI_MDLLOADER_H_INCLUDED
- #define AI_MDLLOADER_H_INCLUDED
- #include "BaseImporter.h"
- #include "../include/aiTypes.h"
- #include "../include/aiTexture.h"
- #include "../include/aiMaterial.h"
- struct aiNode;
- #include "MDLFileData.h"
- #include "HalfLifeFileData.h"
- namespace Assimp
- {
- class MaterialHelper;
- using namespace MDL;
- // ---------------------------------------------------------------------------
- /** Used to load MDL files
- */
- class MDLImporter : public BaseImporter
- {
- friend class Importer;
- protected:
- /** Constructor to be privately used by Importer */
- MDLImporter();
- /** Destructor, private as well */
- ~MDLImporter();
- public:
- // -------------------------------------------------------------------
- /** Returns whether the class can handle the format of the given file.
- * See BaseImporter::CanRead() for details. */
- bool CanRead( const std::string& pFile, IOSystem* pIOHandler) const;
- protected:
- // -------------------------------------------------------------------
- /** Called by Importer::GetExtensionList() for each loaded importer.
- * See BaseImporter::GetExtensionList() for details
- */
- void GetExtensionList(std::string& append)
- {
- append.append("*.mdl");
- }
- // -------------------------------------------------------------------
- /** Imports the given file into the given scene structure.
- * See BaseImporter::InternReadFile() for details
- */
- void InternReadFile( const std::string& pFile, aiScene* pScene,
- IOSystem* pIOHandler);
- protected:
- // -------------------------------------------------------------------
- /** Import a quake 1 MDL file
- */
- void InternReadFile_Quake1( );
- // -------------------------------------------------------------------
- /** Import a GameStudio A4/A5 file
- */
- void InternReadFile_GameStudio( );
- // -------------------------------------------------------------------
- /** Import a GameStudio A7 file
- */
- void InternReadFile_GameStudioA7( );
- // -------------------------------------------------------------------
- /** Import a CS:S/HL2 MDL file
- */
- void InternReadFile_HL2( );
- // -------------------------------------------------------------------
- /** Load a paletized texture from the file and convert it to 32bpp
- */
- void CreateTextureARGB8(const unsigned char* szData);
- // -------------------------------------------------------------------
- /** Used to load textures from MDL3/4
- * \param szData Input data
- * \param iType Color data type
- * \param piSkip Receive: Size to skip
- */
- void CreateTextureARGB8_GS4(const unsigned char* szData,
- unsigned int iType,
- unsigned int* piSkip);
- // -------------------------------------------------------------------
- /** Used to load textures from MDL5
- * \param szData Input data
- * \param iType Color data type
- * \param piSkip Receive: Size to skip
- */
- void CreateTextureARGB8_GS5(const unsigned char* szData,
- unsigned int iType,
- unsigned int* piSkip);
- // -------------------------------------------------------------------
- /** Parse a skin lump in a MDL7 file with all of its features
- * \param szCurrent Current data pointer
- * \param szCurrentOut Output data pointer
- * \param pcMats Material list for this group. To be filled ...
- */
- void ParseSkinLump_GameStudioA7(
- const unsigned char* szCurrent,
- const unsigned char** szCurrentOut,
- std::vector<MaterialHelper*>& pcMats);
- // -------------------------------------------------------------------
- /** Parse texture color data for MDL5, MDL6 and MDL7 formats
- * \param szData Current data pointer
- * \param iType type of the texture data. No DDS or external
- * \param piSkip Receive the number of bytes to skip
- * \param pcNew Must point to fully initialized data. Width and
- * height must be set.
- */
- void ParseTextureColorData(const unsigned char* szData,
- unsigned int iType,
- unsigned int* piSkip,
- aiTexture* pcNew);
- // -------------------------------------------------------------------
- /** Validate the header data structure of a game studio MDL7 file
- * \param pcHeader Input header to be validated
- */
- void ValidateHeader_GameStudioA7(const MDL::Header_MDL7* pcHeader);
- // -------------------------------------------------------------------
- /** Join two materials / skins. Setup UV source ... etc
- * \param pcMat1 First input material
- * \param pcMat2 Second input material
- * \param pcMatOut Output material instance to be filled. Must be empty
- */
- void JoinSkins_GameStudioA7(MaterialHelper* pcMat1,
- MaterialHelper* pcMat2,
- MaterialHelper* pcMatOut);
- // -------------------------------------------------------------------
- /** Generate the final output meshes for a7 models
- * \param aiSplit Face-per-material list
- * \param pcMats List of all materials
- * \param avOutList Output: List of all meshes
- * \param pcFaces List of all input faces
- * \param vPositions List of all input vectors
- * \param vNormals List of all input normal vectors
- * \param vTextureCoords1 List of all input UV coords #1
- * \param vTextureCoords2 List of all input UV coords #2
- */
- void GenerateOutputMeshes_GameStudioA7(
- const std::vector<unsigned int>** aiSplit,
- const std::vector<MaterialHelper*>& pcMats,
- std::vector<aiMesh*>& avOutList,
- const MDL::IntFace_MDL7* pcFaces,
- const std::vector<aiVector3D>& vPositions,
- const std::vector<aiVector3D>& vNormals,
- const std::vector<aiVector3D>& vTextureCoords1,
- const std::vector<aiVector3D>& vTextureCoords2);
- // -------------------------------------------------------------------
- /** Try to load a palette from the current directory (colormap.lmp)
- * If it is not found the default palette of Quake1 is returned
- */
- void SearchPalette(const unsigned char** pszColorMap);
- // -------------------------------------------------------------------
- /** Free a palette created with a previous call to SearchPalette()
- */
- void FreePalette(const unsigned char* pszColorMap);
- // -------------------------------------------------------------------
- /** Try to determine whether the normals of the model are flipped
- * Some MDL7 models seem to have flipped normals (and there is also
- * an option "flip normals" in MED). However, I don't see a proper
- * way to read from the file whether all normals are correctly
- * facing outwards ...
- */
- void FlipNormals(aiMesh* pcMesh);
- private:
- /** Header of the MDL file */
- const MDL::Header* m_pcHeader;
- /** Buffer to hold the loaded file */
- unsigned char* mBuffer;
- /** For GameStudio MDL files: The number in the magic
- word, either 3,4 or 5*/
- unsigned int iGSFileVersion;
- /** Output I/O handler. used to load external lmp files
- */
- IOSystem* pIOHandler;
- /** Output scene to be filled
- */
- aiScene* pScene;
- };
- }; // end of namespace Assimp
- #endif // AI_3DSIMPORTER_H_INC
|