vrshoot

diff libs/assimp/UnrealLoader.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/assimp/UnrealLoader.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,200 @@
     1.4 +/*
     1.5 +Open Asset Import Library (assimp)
     1.6 +----------------------------------------------------------------------
     1.7 +
     1.8 +Copyright (c) 2006-2012, assimp team
     1.9 +All rights reserved.
    1.10 +
    1.11 +Redistribution and use of this software in source and binary forms, 
    1.12 +with or without modification, are permitted provided that the 
    1.13 +following conditions are met:
    1.14 +
    1.15 +* Redistributions of source code must retain the above
    1.16 +  copyright notice, this list of conditions and the
    1.17 +  following disclaimer.
    1.18 +
    1.19 +* Redistributions in binary form must reproduce the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer in the documentation and/or other
    1.22 +  materials provided with the distribution.
    1.23 +
    1.24 +* Neither the name of the assimp team, nor the names of its
    1.25 +  contributors may be used to endorse or promote products
    1.26 +  derived from this software without specific prior
    1.27 +  written permission of the assimp team.
    1.28 +
    1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
    1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.40 +
    1.41 +----------------------------------------------------------------------
    1.42 +*/
    1.43 +
    1.44 +/** @file  UnrealLoader.h
    1.45 + *  @brief Declaration of the .3d (UNREAL) importer class.
    1.46 + */
    1.47 +#ifndef INCLUDED_AI_3D_LOADER_H
    1.48 +#define INCLUDED_AI_3D_LOADER_H
    1.49 +
    1.50 +#include "BaseImporter.h"
    1.51 +namespace Assimp	{
    1.52 +namespace Unreal {
    1.53 +
    1.54 +	/*
    1.55 +	0 = Normal one-sided
    1.56 +	1 = Normal two-sided
    1.57 +	2 = Translucent two-sided
    1.58 +	3 = Masked two-sided
    1.59 +	4 = Modulation blended two-sided
    1.60 +	8 = Placeholder triangle for weapon positioning (invisible)
    1.61 +	*/
    1.62 +enum MeshFlags {
    1.63 +	MF_NORMAL_OS            = 0,
    1.64 +	MF_NORMAL_TS            = 1,
    1.65 +	MF_NORMAL_TRANS_TS      = 2,
    1.66 +	MF_NORMAL_MASKED_TS     = 3,
    1.67 +	MF_NORMAL_MOD_TS        = 4,
    1.68 +	MF_WEAPON_PLACEHOLDER   = 8
    1.69 +};
    1.70 +
    1.71 +	// a single triangle
    1.72 +struct Triangle {
    1.73 +   uint16_t mVertex[3];		  // Vertex indices
    1.74 +   char mType;                // James' Mesh Type
    1.75 +   char mColor;               // Color for flat and Gourand Shaded
    1.76 +   unsigned char mTex[3][2];  // Texture UV coordinates
    1.77 +   unsigned char mTextureNum; // Source texture offset
    1.78 +   char mFlags;               // Unreal Mesh Flags (unused)
    1.79 +  
    1.80 +   unsigned int matIndex;
    1.81 +};
    1.82 +
    1.83 +// temporary representation for a material
    1.84 +struct TempMat	{
    1.85 +	TempMat()
    1.86 +		:	numFaces	(0)
    1.87 +	{}
    1.88 +
    1.89 +	TempMat(const Triangle& in)
    1.90 +		:	type		((Unreal::MeshFlags)in.mType)
    1.91 +		,	tex			(in.mTextureNum)
    1.92 +		,	numFaces	(0)
    1.93 +	{}
    1.94 +
    1.95 +	// type of mesh
    1.96 +	Unreal::MeshFlags type;
    1.97 +
    1.98 +	// index of texture
    1.99 +	unsigned int tex;
   1.100 +
   1.101 +	// number of faces using us
   1.102 +	unsigned int numFaces;
   1.103 +
   1.104 +	// for std::find
   1.105 +	bool operator == (const TempMat& o )	{
   1.106 +		return (tex == o.tex && type == o.type);
   1.107 +	}
   1.108 +};
   1.109 +
   1.110 +struct Vertex
   1.111 +{
   1.112 +	int32_t X : 11;
   1.113 +	int32_t Y : 11;
   1.114 +	int32_t Z : 10;
   1.115 +};
   1.116 +
   1.117 +	// UNREAL vertex compression
   1.118 +inline void CompressVertex(const aiVector3D& v, uint32_t& out)
   1.119 +{
   1.120 +	union {
   1.121 +		Vertex n;
   1.122 +		int32_t t;
   1.123 +	};
   1.124 +	n.X = (int32_t)v.x;
   1.125 +	n.Y = (int32_t)v.y;
   1.126 +	n.Z = (int32_t)v.z;
   1.127 +	out = t;
   1.128 +}
   1.129 +
   1.130 +	// UNREAL vertex decompression
   1.131 +inline void DecompressVertex(aiVector3D& v, int32_t in)
   1.132 +{
   1.133 +	union {
   1.134 +		Vertex n;
   1.135 +		int32_t i;
   1.136 +	}; 
   1.137 +	i = in;
   1.138 +	
   1.139 +	v.x = (float)n.X;
   1.140 +	v.y = (float)n.Y;
   1.141 +	v.z = (float)n.Z;
   1.142 +}
   1.143 +
   1.144 +} // end namespace Unreal
   1.145 +
   1.146 +// ---------------------------------------------------------------------------
   1.147 +/** @brief Importer class to load UNREAL files (*.3d)
   1.148 +*/
   1.149 +class UnrealImporter : public BaseImporter
   1.150 +{
   1.151 +public:
   1.152 +	UnrealImporter();
   1.153 +	~UnrealImporter();
   1.154 +
   1.155 +
   1.156 +public:
   1.157 +
   1.158 +	// -------------------------------------------------------------------
   1.159 +	/** @brief Returns whether we can handle the format of the given file
   1.160 +	 *
   1.161 +	 *  See BaseImporter::CanRead() for details.	
   1.162 +	 **/
   1.163 +	bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
   1.164 +		bool checkSig) const;
   1.165 +
   1.166 +protected:
   1.167 +
   1.168 +	// -------------------------------------------------------------------
   1.169 +	/** @brief Called by Importer::GetExtensionList() 
   1.170 +	 *
   1.171 +	 * See #BaseImporter::GetInfo for the details
   1.172 +	 */
   1.173 +	const aiImporterDesc* GetInfo () const;
   1.174 +
   1.175 +
   1.176 +	// -------------------------------------------------------------------
   1.177 +	/** @brief Setup properties for the importer
   1.178 +	 *
   1.179 +	 * See BaseImporter::SetupProperties() for details
   1.180 +	 */
   1.181 +	void SetupProperties(const Importer* pImp);
   1.182 +
   1.183 +
   1.184 +	// -------------------------------------------------------------------
   1.185 +	/** @brief Imports the given file into the given scene structure. 
   1.186 +	 *
   1.187 +	 * See BaseImporter::InternReadFile() for details
   1.188 +	 */
   1.189 +	void InternReadFile( const std::string& pFile, aiScene* pScene, 
   1.190 +		IOSystem* pIOHandler);
   1.191 +
   1.192 +private:
   1.193 +
   1.194 +	//! frame to be loaded
   1.195 +	uint32_t configFrameID;
   1.196 +
   1.197 +	//! process surface flags
   1.198 +	bool configHandleFlags;
   1.199 +
   1.200 +}; // !class UnrealImporter
   1.201 +
   1.202 +} // end of namespace Assimp
   1.203 +#endif // AI_UNREALIMPORTER_H_INC