From 6e13381bdb7029d263b480d70dacdf1c92a43317 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Tue, 18 Feb 2020 14:41:19 +0100 Subject: [PATCH] next warnings. --- code/3DS/3DSHelper.h | 471 +++++---- code/3DS/3DSLoader.cpp | 25 +- code/AC/ACLoader.cpp | 678 ++++++------- code/AC/ACLoader.h | 2 +- code/AMF/AMFImporter_Postprocess.cpp | 2 +- code/HMP/HMPLoader.cpp | 6 +- code/LWO/LWOAnimation.cpp | 8 +- code/MDL/MDLLoader.cpp | 1182 +++++++++++----------- code/MDL/MDLLoader.h | 4 +- code/Material/MaterialSystem.cpp | 3 +- code/PostProcessing/SplitLargeMeshes.cpp | 5 +- code/PostProcessing/TextureTransform.cpp | 6 +- 12 files changed, 1110 insertions(+), 1282 deletions(-) diff --git a/code/3DS/3DSHelper.h b/code/3DS/3DSHelper.h index 00b439e56..3ef9b8604 100644 --- a/code/3DS/3DSHelper.h +++ b/code/3DS/3DSHelper.h @@ -45,18 +45,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef AI_3DSFILEHELPER_H_INC #define AI_3DSFILEHELPER_H_INC -#include #include +#include #include -#include -#include +#include #include #include -#include +#include +#include #include //sprintf -namespace Assimp { -namespace D3DS { +namespace Assimp { +namespace D3DS { #include @@ -77,15 +77,13 @@ private: public: //! data structure for a single chunk in a .3ds file struct Chunk { - uint16_t Flag; - uint32_t Size; + uint16_t Flag; + uint32_t Size; } PACK_STRUCT; - //! Used for shading field in material3ds structure //! From AutoDesk 3ds SDK - typedef enum - { + typedef enum { // translated to gouraud shading with wireframe active Wire = 0x0, @@ -109,59 +107,57 @@ public: } shadetype3ds; // Flags for animated keys - enum - { - KEY_USE_TENS = 0x1, - KEY_USE_CONT = 0x2, - KEY_USE_BIAS = 0x4, - KEY_USE_EASE_TO = 0x8, - KEY_USE_EASE_FROM = 0x10 - } ; + enum { + KEY_USE_TENS = 0x1, + KEY_USE_CONT = 0x2, + KEY_USE_BIAS = 0x4, + KEY_USE_EASE_TO = 0x8, + KEY_USE_EASE_FROM = 0x10 + }; - enum - { + enum { // ******************************************************************** // Basic chunks which can be found everywhere in the file - CHUNK_VERSION = 0x0002, - CHUNK_RGBF = 0x0010, // float4 R; float4 G; float4 B - CHUNK_RGBB = 0x0011, // int1 R; int1 G; int B + CHUNK_VERSION = 0x0002, + CHUNK_RGBF = 0x0010, // float4 R; float4 G; float4 B + CHUNK_RGBB = 0x0011, // int1 R; int1 G; int B // Linear color values (gamma = 2.2?) - CHUNK_LINRGBF = 0x0013, // float4 R; float4 G; float4 B - CHUNK_LINRGBB = 0x0012, // int1 R; int1 G; int B + CHUNK_LINRGBF = 0x0013, // float4 R; float4 G; float4 B + CHUNK_LINRGBB = 0x0012, // int1 R; int1 G; int B - CHUNK_PERCENTW = 0x0030, // int2 percentage - CHUNK_PERCENTF = 0x0031, // float4 percentage - CHUNK_PERCENTD = 0x0032, // float8 percentage + CHUNK_PERCENTW = 0x0030, // int2 percentage + CHUNK_PERCENTF = 0x0031, // float4 percentage + CHUNK_PERCENTD = 0x0032, // float8 percentage // ******************************************************************** // Prj master chunk - CHUNK_PRJ = 0xC23D, + CHUNK_PRJ = 0xC23D, // MDLI master chunk - CHUNK_MLI = 0x3DAA, + CHUNK_MLI = 0x3DAA, // Primary main chunk of the .3ds file - CHUNK_MAIN = 0x4D4D, + CHUNK_MAIN = 0x4D4D, // Mesh main chunk - CHUNK_OBJMESH = 0x3D3D, + CHUNK_OBJMESH = 0x3D3D, // Specifies the background color of the .3ds file // This is passed through the material system for // viewing purposes. - CHUNK_BKGCOLOR = 0x1200, + CHUNK_BKGCOLOR = 0x1200, // Specifies the ambient base color of the scene. // This is added to all materials in the file - CHUNK_AMBCOLOR = 0x2100, + CHUNK_AMBCOLOR = 0x2100, // Specifies the background image for the whole scene // This value is passed through the material system // to the viewer - CHUNK_BIT_MAP = 0x1100, - CHUNK_BIT_MAP_EXISTS = 0x1101, + CHUNK_BIT_MAP = 0x1100, + CHUNK_BIT_MAP_EXISTS = 0x1101, // ******************************************************************** // Viewport related stuff. Ignored @@ -177,183 +173,204 @@ public: // ******************************************************************** // Mesh chunks - CHUNK_OBJBLOCK = 0x4000, - CHUNK_TRIMESH = 0x4100, - CHUNK_VERTLIST = 0x4110, + CHUNK_OBJBLOCK = 0x4000, + CHUNK_TRIMESH = 0x4100, + CHUNK_VERTLIST = 0x4110, CHUNK_VERTFLAGS = 0x4111, - CHUNK_FACELIST = 0x4120, - CHUNK_FACEMAT = 0x4130, - CHUNK_MAPLIST = 0x4140, - CHUNK_SMOOLIST = 0x4150, - CHUNK_TRMATRIX = 0x4160, + CHUNK_FACELIST = 0x4120, + CHUNK_FACEMAT = 0x4130, + CHUNK_MAPLIST = 0x4140, + CHUNK_SMOOLIST = 0x4150, + CHUNK_TRMATRIX = 0x4160, CHUNK_MESHCOLOR = 0x4165, - CHUNK_TXTINFO = 0x4170, - CHUNK_LIGHT = 0x4600, - CHUNK_CAMERA = 0x4700, + CHUNK_TXTINFO = 0x4170, + CHUNK_LIGHT = 0x4600, + CHUNK_CAMERA = 0x4700, CHUNK_HIERARCHY = 0x4F00, // Specifies the global scaling factor. This is applied // to the root node's transformation matrix - CHUNK_MASTER_SCALE = 0x0100, + CHUNK_MASTER_SCALE = 0x0100, // ******************************************************************** // Material chunks - CHUNK_MAT_MATERIAL = 0xAFFF, + CHUNK_MAT_MATERIAL = 0xAFFF, - // asciiz containing the name of the material - CHUNK_MAT_MATNAME = 0xA000, - CHUNK_MAT_AMBIENT = 0xA010, // followed by color chunk - CHUNK_MAT_DIFFUSE = 0xA020, // followed by color chunk - CHUNK_MAT_SPECULAR = 0xA030, // followed by color chunk + // asciiz containing the name of the material + CHUNK_MAT_MATNAME = 0xA000, + CHUNK_MAT_AMBIENT = 0xA010, // followed by color chunk + CHUNK_MAT_DIFFUSE = 0xA020, // followed by color chunk + CHUNK_MAT_SPECULAR = 0xA030, // followed by color chunk - // Specifies the shininess of the material - // followed by percentage chunk - CHUNK_MAT_SHININESS = 0xA040, - CHUNK_MAT_SHININESS_PERCENT = 0xA041 , + // Specifies the shininess of the material + // followed by percentage chunk + CHUNK_MAT_SHININESS = 0xA040, + CHUNK_MAT_SHININESS_PERCENT = 0xA041, - // Specifies the shading mode to be used - // followed by a short - CHUNK_MAT_SHADING = 0xA100, + // Specifies the shading mode to be used + // followed by a short + CHUNK_MAT_SHADING = 0xA100, - // NOTE: Emissive color (self illumination) seems not - // to be a color but a single value, type is unknown. - // Make the parser accept both of them. - // followed by percentage chunk (?) - CHUNK_MAT_SELF_ILLUM = 0xA080, + // NOTE: Emissive color (self illumination) seems not + // to be a color but a single value, type is unknown. + // Make the parser accept both of them. + // followed by percentage chunk (?) + CHUNK_MAT_SELF_ILLUM = 0xA080, - // Always followed by percentage chunk (?) - CHUNK_MAT_SELF_ILPCT = 0xA084, + // Always followed by percentage chunk (?) + CHUNK_MAT_SELF_ILPCT = 0xA084, - // Always followed by percentage chunk - CHUNK_MAT_TRANSPARENCY = 0xA050, + // Always followed by percentage chunk + CHUNK_MAT_TRANSPARENCY = 0xA050, - // Diffuse texture channel 0 - CHUNK_MAT_TEXTURE = 0xA200, + // Diffuse texture channel 0 + CHUNK_MAT_TEXTURE = 0xA200, - // Contains opacity information for each texel - CHUNK_MAT_OPACMAP = 0xA210, + // Contains opacity information for each texel + CHUNK_MAT_OPACMAP = 0xA210, - // Contains a reflection map to be used to reflect - // the environment. This is partially supported. - CHUNK_MAT_REFLMAP = 0xA220, + // Contains a reflection map to be used to reflect + // the environment. This is partially supported. + CHUNK_MAT_REFLMAP = 0xA220, - // Self Illumination map (emissive colors) - CHUNK_MAT_SELFIMAP = 0xA33d, + // Self Illumination map (emissive colors) + CHUNK_MAT_SELFIMAP = 0xA33d, - // Bumpmap. Not specified whether it is a heightmap - // or a normal map. Assme it is a heightmap since - // artist normally prefer this format. - CHUNK_MAT_BUMPMAP = 0xA230, + // Bumpmap. Not specified whether it is a heightmap + // or a normal map. Assme it is a heightmap since + // artist normally prefer this format. + CHUNK_MAT_BUMPMAP = 0xA230, - // Specular map. Seems to influence the specular color - CHUNK_MAT_SPECMAP = 0xA204, + // Specular map. Seems to influence the specular color + CHUNK_MAT_SPECMAP = 0xA204, - // Holds shininess data. - CHUNK_MAT_MAT_SHINMAP = 0xA33C, + // Holds shininess data. + CHUNK_MAT_MAT_SHINMAP = 0xA33C, - // Scaling in U/V direction. - // (need to gen separate UV coordinate set - // and do this by hand) - CHUNK_MAT_MAP_USCALE = 0xA354, - CHUNK_MAT_MAP_VSCALE = 0xA356, + // Scaling in U/V direction. + // (need to gen separate UV coordinate set + // and do this by hand) + CHUNK_MAT_MAP_USCALE = 0xA354, + CHUNK_MAT_MAP_VSCALE = 0xA356, - // Translation in U/V direction. - // (need to gen separate UV coordinate set - // and do this by hand) - CHUNK_MAT_MAP_UOFFSET = 0xA358, - CHUNK_MAT_MAP_VOFFSET = 0xA35a, + // Translation in U/V direction. + // (need to gen separate UV coordinate set + // and do this by hand) + CHUNK_MAT_MAP_UOFFSET = 0xA358, + CHUNK_MAT_MAP_VOFFSET = 0xA35a, - // UV-coordinates rotation around the z-axis - // Assumed to be in radians. - CHUNK_MAT_MAP_ANG = 0xA35C, + // UV-coordinates rotation around the z-axis + // Assumed to be in radians. + CHUNK_MAT_MAP_ANG = 0xA35C, - // Tiling flags for 3DS files - CHUNK_MAT_MAP_TILING = 0xa351, + // Tiling flags for 3DS files + CHUNK_MAT_MAP_TILING = 0xa351, - // Specifies the file name of a texture - CHUNK_MAPFILE = 0xA300, + // Specifies the file name of a texture + CHUNK_MAPFILE = 0xA300, - // Specifies whether a materail requires two-sided rendering - CHUNK_MAT_TWO_SIDE = 0xA081, + // Specifies whether a materail requires two-sided rendering + CHUNK_MAT_TWO_SIDE = 0xA081, // ******************************************************************** // Main keyframer chunk. Contains translation/rotation/scaling data - CHUNK_KEYFRAMER = 0xB000, + CHUNK_KEYFRAMER = 0xB000, // Supported sub chunks - CHUNK_TRACKINFO = 0xB002, - CHUNK_TRACKOBJNAME = 0xB010, - CHUNK_TRACKDUMMYOBJNAME = 0xB011, - CHUNK_TRACKPIVOT = 0xB013, - CHUNK_TRACKPOS = 0xB020, - CHUNK_TRACKROTATE = 0xB021, - CHUNK_TRACKSCALE = 0xB022, + CHUNK_TRACKINFO = 0xB002, + CHUNK_TRACKOBJNAME = 0xB010, + CHUNK_TRACKDUMMYOBJNAME = 0xB011, + CHUNK_TRACKPIVOT = 0xB013, + CHUNK_TRACKPOS = 0xB020, + CHUNK_TRACKROTATE = 0xB021, + CHUNK_TRACKSCALE = 0xB022, // ******************************************************************** // Keyframes for various other stuff in the file // Partially ignored - CHUNK_AMBIENTKEY = 0xB001, - CHUNK_TRACKMORPH = 0xB026, - CHUNK_TRACKHIDE = 0xB029, - CHUNK_OBJNUMBER = 0xB030, - CHUNK_TRACKCAMERA = 0xB003, - CHUNK_TRACKFOV = 0xB023, - CHUNK_TRACKROLL = 0xB024, - CHUNK_TRACKCAMTGT = 0xB004, - CHUNK_TRACKLIGHT = 0xB005, - CHUNK_TRACKLIGTGT = 0xB006, - CHUNK_TRACKSPOTL = 0xB007, - CHUNK_FRAMES = 0xB008, + CHUNK_AMBIENTKEY = 0xB001, + CHUNK_TRACKMORPH = 0xB026, + CHUNK_TRACKHIDE = 0xB029, + CHUNK_OBJNUMBER = 0xB030, + CHUNK_TRACKCAMERA = 0xB003, + CHUNK_TRACKFOV = 0xB023, + CHUNK_TRACKROLL = 0xB024, + CHUNK_TRACKCAMTGT = 0xB004, + CHUNK_TRACKLIGHT = 0xB005, + CHUNK_TRACKLIGTGT = 0xB006, + CHUNK_TRACKSPOTL = 0xB007, + CHUNK_FRAMES = 0xB008, // ******************************************************************** // light sub-chunks - CHUNK_DL_OFF = 0x4620, - CHUNK_DL_OUTER_RANGE = 0x465A, - CHUNK_DL_INNER_RANGE = 0x4659, - CHUNK_DL_MULTIPLIER = 0x465B, - CHUNK_DL_EXCLUDE = 0x4654, - CHUNK_DL_ATTENUATE = 0x4625, - CHUNK_DL_SPOTLIGHT = 0x4610, + CHUNK_DL_OFF = 0x4620, + CHUNK_DL_OUTER_RANGE = 0x465A, + CHUNK_DL_INNER_RANGE = 0x4659, + CHUNK_DL_MULTIPLIER = 0x465B, + CHUNK_DL_EXCLUDE = 0x4654, + CHUNK_DL_ATTENUATE = 0x4625, + CHUNK_DL_SPOTLIGHT = 0x4610, // camera sub-chunks - CHUNK_CAM_RANGES = 0x4720 + CHUNK_CAM_RANGES = 0x4720 }; }; // --------------------------------------------------------------------------- /** Helper structure representing a 3ds mesh face */ -struct Face : public FaceWithSmoothingGroup -{ +struct Face : public FaceWithSmoothingGroup { }; +#pragma warning(disable : 4315 ) + // --------------------------------------------------------------------------- /** Helper structure representing a texture */ struct Texture { //! Default constructor Texture() AI_NO_EXCEPT - : mOffsetU (0.0) - , mOffsetV (0.0) - , mScaleU (1.0) - , mScaleV (1.0) - , mRotation (0.0) - , mMapMode (aiTextureMapMode_Wrap) - , bPrivate() - , iUVSrc (0) { + : mTextureBlend(0.0f), + mMapName(), + mOffsetU(0.0), + mOffsetV(0.0), + mScaleU(1.0), + mScaleV(1.0), + mRotation(0.0), + mMapMode(aiTextureMapMode_Wrap), + bPrivate(), + iUVSrc(0) { mTextureBlend = get_qnan(); } - Texture(Texture &&other) AI_NO_EXCEPT : - mTextureBlend(std::move(other.mTextureBlend)), - mMapName(std::move(mMapName)), - mOffsetU(std::move(mOffsetU)), - mOffsetV(std::move(mOffsetV)), - mScaleU(std::move(mScaleU)), - mScaleV(std::move(mScaleV)), - mRotation(std::move(mRotation)), - mMapMode(std::move(mMapMode)), - bPrivate(std::move(bPrivate)), - iUVSrc(std::move(iUVSrc)) { + Texture(Texture &&other) AI_NO_EXCEPT : mTextureBlend(std::move(other.mTextureBlend)), + mMapName(std::move(mMapName)), + mOffsetU(std::move(mOffsetU)), + mOffsetV(std::move(mOffsetV)), + mScaleU(std::move(mScaleU)), + mScaleV(std::move(mScaleV)), + mRotation(std::move(mRotation)), + mMapMode(std::move(mMapMode)), + bPrivate(std::move(bPrivate)), + iUVSrc(std::move(iUVSrc)) { + // empty + } + Texture &operator=(Texture &&other) AI_NO_EXCEPT { + if (this == &other) { + return *this; + } + + mTextureBlend = std::move(other.mTextureBlend); + mMapName = std::move(other.mMapName); + mOffsetU = std::move(other.mOffsetU); + mOffsetV = std::move(other.mOffsetV); + mScaleU = std::move(other.mScaleU); + mScaleV = std::move(other.mScaleV); + mRotation = std::move(other.mRotation); + mMapMode = std::move(other.mMapMode); + bPrivate = std::move(other.bPrivate); + iUVSrc = std::move(other.iUVSrc); + + return *this; } //! Specifies the blend factor for the texture @@ -381,55 +398,48 @@ struct Texture { // --------------------------------------------------------------------------- /** Helper structure representing a 3ds material */ -struct Material -{ +struct Material { //! Default constructor has been deleted Material() = delete; - //! Constructor with explicit name - explicit Material(const std::string &name) - : mName(name) - , mDiffuse ( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ) ) // FIX ... we won't want object to be black - , mSpecularExponent ( ai_real( 0.0 ) ) - , mShininessStrength ( ai_real( 1.0 ) ) - , mShading(Discreet3DS::Gouraud) - , mTransparency ( ai_real( 1.0 ) ) - , mBumpHeight ( ai_real( 1.0 ) ) - , mTwoSided (false) - { + explicit Material(const std::string &name) : + mName(name), mDiffuse(ai_real(0.6), ai_real(0.6), ai_real(0.6)) // FIX ... we won't want object to be black + , + mSpecularExponent(ai_real(0.0)), + mShininessStrength(ai_real(1.0)), + mShading(Discreet3DS::Gouraud), + mTransparency(ai_real(1.0)), + mBumpHeight(ai_real(1.0)), + mTwoSided(false) { } - - Material(const Material &other) = default; + Material(const Material &other) = default; Material &operator=(const Material &other) = default; - //! Move constructor. This is explicitly written because MSVC doesn't support defaulting it Material(Material &&other) AI_NO_EXCEPT - : mName(std::move(other.mName)) - , mDiffuse(std::move(other.mDiffuse)) - , mSpecularExponent(std::move(other.mSpecularExponent)) - , mShininessStrength(std::move(other.mShininessStrength)) - , mSpecular(std::move(other.mSpecular)) - , mAmbient(std::move(other.mAmbient)) - , mShading(std::move(other.mShading)) - , mTransparency(std::move(other.mTransparency)) - , sTexDiffuse(std::move(other.sTexDiffuse)) - , sTexOpacity(std::move(other.sTexOpacity)) - , sTexSpecular(std::move(other.sTexSpecular)) - , sTexReflective(std::move(other.sTexReflective)) - , sTexBump(std::move(other.sTexBump)) - , sTexEmissive(std::move(other.sTexEmissive)) - , sTexShininess(std::move(other.sTexShininess)) - , mBumpHeight(std::move(other.mBumpHeight)) - , mEmissive(std::move(other.mEmissive)) - , sTexAmbient(std::move(other.sTexAmbient)) - , mTwoSided(std::move(other.mTwoSided)) - { + : mName(std::move(other.mName)), + mDiffuse(std::move(other.mDiffuse)), + mSpecularExponent(std::move(other.mSpecularExponent)), + mShininessStrength(std::move(other.mShininessStrength)), + mSpecular(std::move(other.mSpecular)), + mAmbient(std::move(other.mAmbient)), + mShading(std::move(other.mShading)), + mTransparency(std::move(other.mTransparency)), + sTexDiffuse(std::move(other.sTexDiffuse)), + sTexOpacity(std::move(other.sTexOpacity)), + sTexSpecular(std::move(other.sTexSpecular)), + sTexReflective(std::move(other.sTexReflective)), + sTexBump(std::move(other.sTexBump)), + sTexEmissive(std::move(other.sTexEmissive)), + sTexShininess(std::move(other.sTexShininess)), + mBumpHeight(std::move(other.mBumpHeight)), + mEmissive(std::move(other.mEmissive)), + sTexAmbient(std::move(other.sTexAmbient)), + mTwoSided(std::move(other.mTwoSided)) { } - Material &operator=(Material &&other) AI_NO_EXCEPT { if (this == &other) { return *this; @@ -458,10 +468,8 @@ struct Material return *this; } - virtual ~Material() {} - //! Name of the material std::string mName; //! Diffuse color of the material @@ -505,18 +513,15 @@ struct Material // --------------------------------------------------------------------------- /** Helper structure to represent a 3ds file mesh */ -struct Mesh : public MeshWithSmoothingGroups -{ +struct Mesh : public MeshWithSmoothingGroups { //! Default constructor has been deleted Mesh() = delete; //! Constructor with explicit name - explicit Mesh(const std::string &name) - : mName(name) - { + explicit Mesh(const std::string &name) : + mName(name) { } - //! Name of the mesh std::string mName; @@ -533,62 +538,48 @@ struct Mesh : public MeshWithSmoothingGroups // --------------------------------------------------------------------------- /** Float key - quite similar to aiVectorKey and aiQuatKey. Both are in the C-API, so it would be difficult to make them a template. */ -struct aiFloatKey -{ - double mTime; ///< The time of this key - ai_real mValue; ///< The value of this key +struct aiFloatKey { + double mTime; ///< The time of this key + ai_real mValue; ///< The value of this key #ifdef __cplusplus // time is not compared - bool operator == (const aiFloatKey& o) const - {return o.mValue == this->mValue;} + bool operator==(const aiFloatKey &o) const { return o.mValue == this->mValue; } - bool operator != (const aiFloatKey& o) const - {return o.mValue != this->mValue;} + bool operator!=(const aiFloatKey &o) const { return o.mValue != this->mValue; } // Only time is compared. This operator is defined // for use with std::sort - bool operator < (const aiFloatKey& o) const - {return mTime < o.mTime;} + bool operator<(const aiFloatKey &o) const { return mTime < o.mTime; } - bool operator > (const aiFloatKey& o) const - {return mTime > o.mTime;} + bool operator>(const aiFloatKey &o) const { return mTime > o.mTime; } #endif }; // --------------------------------------------------------------------------- /** Helper structure to represent a 3ds file node */ -struct Node -{ +struct Node { Node() = delete; - explicit Node(const std::string &name) - : mParent(NULL) - , mName(name) - , mInstanceNumber(0) - , mHierarchyPos (0) - , mHierarchyIndex (0) - , mInstanceCount (1) - { - aRotationKeys.reserve (20); - aPositionKeys.reserve (20); - aScalingKeys.reserve (20); + explicit Node(const std::string &name) : + mParent(NULL), mName(name), mInstanceNumber(0), mHierarchyPos(0), mHierarchyIndex(0), mInstanceCount(1) { + aRotationKeys.reserve(20); + aPositionKeys.reserve(20); + aScalingKeys.reserve(20); } - - ~Node() - { - for (unsigned int i = 0; i < mChildren.size();++i) + ~Node() { + for (unsigned int i = 0; i < mChildren.size(); ++i) delete mChildren[i]; } //! Pointer to the parent node - Node* mParent; + Node *mParent; //! Holds all child nodes - std::vector mChildren; + std::vector mChildren; //! Name of the node std::string mName; @@ -614,13 +605,12 @@ struct Node //! Scaling keys loaded from the file std::vector aScalingKeys; - // For target lights (spot lights and directional lights): // The position of the target - std::vector< aiVectorKey > aTargetPositionKeys; + std::vector aTargetPositionKeys; // For cameras: the camera roll angle - std::vector< aiFloatKey > aCameraRollKeys; + std::vector aCameraRollKeys; //! Pivot position loaded from the file aiVector3D vPivot; @@ -630,8 +620,7 @@ struct Node //! Add a child node, setup the right parent node for it //! \param pc Node to be 'adopted' - inline Node& push_back(Node* pc) - { + inline Node &push_back(Node *pc) { mChildren.push_back(pc); pc->mParent = this; return *this; @@ -639,8 +628,7 @@ struct Node }; // --------------------------------------------------------------------------- /** Helper structure analogue to aiScene */ -struct Scene -{ +struct Scene { //! List of all materials loaded //! NOTE: 3ds references materials globally std::vector mMaterials; @@ -649,17 +637,16 @@ struct Scene std::vector mMeshes; //! List of all cameras loaded - std::vector mCameras; + std::vector mCameras; //! List of all lights loaded - std::vector mLights; + std::vector mLights; //! Pointer to the root node of the scene // --- moved to main class // Node* pcRootNode; }; - } // end of namespace D3DS } // end of namespace Assimp diff --git a/code/3DS/3DSLoader.cpp b/code/3DS/3DSLoader.cpp index 3e8e08967..0b4a93a2b 100644 --- a/code/3DS/3DSLoader.cpp +++ b/code/3DS/3DSLoader.cpp @@ -158,13 +158,13 @@ void Discreet3DSImporter::SetupProperties(const Importer* /*pImp*/) void Discreet3DSImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) { - StreamReaderLE stream(pIOHandler->Open(pFile,"rb")); + StreamReaderLE theStream(pIOHandler->Open(pFile,"rb")); // We should have at least one chunk - if (stream.GetRemainingSize() < 16) { + if (theStream.GetRemainingSize() < 16) { throw DeadlyImportError("3DS file is either empty or corrupt: " + pFile); } - this->stream = &stream; + this->stream = &theStream; // Allocate our temporary 3DS representation D3DS::Scene _scene; @@ -599,16 +599,19 @@ void Discreet3DSImporter::InverseNodeSearch(D3DS::Node* pcNode,D3DS::Node* pcCur // ------------------------------------------------------------------------------------------------ // Find a node with a specific name in the import hierarchy -D3DS::Node* FindNode(D3DS::Node* root, const std::string& name) -{ - if (root->mName == name) +D3DS::Node* FindNode(D3DS::Node* root, const std::string& name) { + if (root->mName == name) { return root; - for (std::vector::iterator it = root->mChildren.begin();it != root->mChildren.end(); ++it) { - D3DS::Node* nd; - if (( nd = FindNode(*it,name))) - return nd; } - return NULL; + + for (std::vector::iterator it = root->mChildren.begin();it != root->mChildren.end(); ++it) { + D3DS::Node *nd = FindNode(*it, name); + if (nullptr != nd) { + return nd; + } + } + + return nullptr; } // ------------------------------------------------------------------------------------------------ diff --git a/code/AC/ACLoader.cpp b/code/AC/ACLoader.cpp index ea533743f..196f26253 100644 --- a/code/AC/ACLoader.cpp +++ b/code/AC/ACLoader.cpp @@ -44,25 +44,23 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /** @file Implementation of the AC3D importer class */ - - #ifndef ASSIMP_BUILD_NO_AC_IMPORTER // internal headers #include "ACLoader.h" -#include -#include -#include #include "Common/Importer.h" #include -#include +#include +#include +#include +#include +#include #include -#include #include #include -#include +#include #include -#include +#include #include using namespace Assimp; @@ -82,116 +80,102 @@ static const aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // skip to the next token -#define AI_AC_SKIP_TO_NEXT_TOKEN() \ - if (!SkipSpaces(&buffer)) \ - { \ +#define AI_AC_SKIP_TO_NEXT_TOKEN() \ + if (!SkipSpaces(&buffer)) { \ ASSIMP_LOG_ERROR("AC3D: Unexpected EOF/EOL"); \ - continue; \ + continue; \ } // ------------------------------------------------------------------------------------------------ // read a string (may be enclosed in double quotation marks). buffer must point to " -#define AI_AC_GET_STRING(out) \ - if (*buffer == '\0') { \ - throw DeadlyImportError("AC3D: Unexpected EOF in string"); \ - } \ - ++buffer; \ - const char* sz = buffer; \ - while ('\"' != *buffer) \ - { \ - if (IsLineEnd( *buffer )) \ - { \ +#define AI_AC_GET_STRING(out) \ + if (*buffer == '\0') { \ + throw DeadlyImportError("AC3D: Unexpected EOF in string"); \ + } \ + ++buffer; \ + const char *sz = buffer; \ + while ('\"' != *buffer) { \ + if (IsLineEnd(*buffer)) { \ ASSIMP_LOG_ERROR("AC3D: Unexpected EOF/EOL in string"); \ - out = "ERROR"; \ - break; \ - } \ - ++buffer; \ - } \ - if (IsLineEnd( *buffer ))continue; \ - out = std::string(sz,(unsigned int)(buffer-sz)); \ + out = "ERROR"; \ + break; \ + } \ + ++buffer; \ + } \ + if (IsLineEnd(*buffer)) continue; \ + out = std::string(sz, (unsigned int)(buffer - sz)); \ ++buffer; - // ------------------------------------------------------------------------------------------------ // read 1 to n floats prefixed with an optional predefined identifier -#define AI_AC_CHECKED_LOAD_FLOAT_ARRAY(name,name_length,num,out) \ - AI_AC_SKIP_TO_NEXT_TOKEN(); \ - if (name_length) \ - { \ - if (strncmp(buffer,name,name_length) || !IsSpace(buffer[name_length])) \ - { \ - ASSIMP_LOG_ERROR("AC3D: Unexpexted token. " name " was expected."); \ - continue; \ - } \ - buffer += name_length+1; \ - } \ - for (unsigned int i = 0; i < num;++i) \ - { \ - AI_AC_SKIP_TO_NEXT_TOKEN(); \ - buffer = fast_atoreal_move(buffer,((float*)out)[i]); \ +#define AI_AC_CHECKED_LOAD_FLOAT_ARRAY(name, name_length, num, out) \ + AI_AC_SKIP_TO_NEXT_TOKEN(); \ + if (name_length) { \ + if (strncmp(buffer, name, name_length) || !IsSpace(buffer[name_length])) { \ + ASSIMP_LOG_ERROR("AC3D: Unexpexted token. " name " was expected."); \ + continue; \ + } \ + buffer += name_length + 1; \ + } \ + for (unsigned int _i = 0; _i < num; ++_i) { \ + AI_AC_SKIP_TO_NEXT_TOKEN(); \ + buffer = fast_atoreal_move(buffer, ((float *)out)[_i]); \ } - // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer -AC3DImporter::AC3DImporter() - : buffer(), - configSplitBFCull(), - configEvalSubdivision(), - mNumMeshes(), - mLights(), - lights(), - groups(), - polys(), - worlds() -{ +AC3DImporter::AC3DImporter() : + buffer(), + configSplitBFCull(), + configEvalSubdivision(), + mNumMeshes(), + mLights(), + mLightsCounter(0), + mGroupsCounter(0), + mPolysCounter(0), + mWorldsCounter(0) { // nothing to be done here } // ------------------------------------------------------------------------------------------------ // Destructor, private as well -AC3DImporter::~AC3DImporter() -{ +AC3DImporter::~AC3DImporter() { // nothing to be done here } // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. -bool AC3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const -{ +bool AC3DImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const { std::string extension = GetExtension(pFile); // fixme: are acc and ac3d *really* used? Some sources say they are - if(extension == "ac" || extension == "ac3d" || extension == "acc") { + if (extension == "ac" || extension == "ac3d" || extension == "acc") { return true; } if (!extension.length() || checkSig) { uint32_t token = AI_MAKE_MAGIC("AC3D"); - return CheckMagicToken(pIOHandler,pFile,&token,1,0); + return CheckMagicToken(pIOHandler, pFile, &token, 1, 0); } return false; } // ------------------------------------------------------------------------------------------------ // Loader meta information -const aiImporterDesc* AC3DImporter::GetInfo () const -{ +const aiImporterDesc *AC3DImporter::GetInfo() const { return &desc; } // ------------------------------------------------------------------------------------------------ // Get a pointer to the next line from the file -bool AC3DImporter::GetNextLine( ) -{ +bool AC3DImporter::GetNextLine() { SkipLine(&buffer); return SkipSpaces(&buffer); } // ------------------------------------------------------------------------------------------------ // Parse an object section in an AC file -void AC3DImporter::LoadObjectSection(std::vector& objects) -{ - if (!TokenMatch(buffer,"OBJECT",6)) +void AC3DImporter::LoadObjectSection(std::vector &objects) { + if (!TokenMatch(buffer, "OBJECT", 6)) return; SkipSpaces(&buffer); @@ -199,145 +183,109 @@ void AC3DImporter::LoadObjectSection(std::vector& objects) ++mNumMeshes; objects.push_back(Object()); - Object& obj = objects.back(); + Object &obj = objects.back(); - aiLight* light = NULL; - if (!ASSIMP_strincmp(buffer,"light",5)) - { + aiLight *light = NULL; + if (!ASSIMP_strincmp(buffer, "light", 5)) { // This is a light source. Add it to the list mLights->push_back(light = new aiLight()); // Return a point light with no attenuation light->mType = aiLightSource_POINT; - light->mColorDiffuse = light->mColorSpecular = aiColor3D(1.f,1.f,1.f); + light->mColorDiffuse = light->mColorSpecular = aiColor3D(1.f, 1.f, 1.f); light->mAttenuationConstant = 1.f; // Generate a default name for both the light source and the node // FIXME - what's the right way to print a size_t? Is 'zu' universally available? stick with the safe version. - light->mName.length = ::ai_snprintf(light->mName.data, MAXLEN, "ACLight_%i",static_cast(mLights->size())-1); - obj.name = std::string( light->mName.data ); + light->mName.length = ::ai_snprintf(light->mName.data, MAXLEN, "ACLight_%i", static_cast(mLights->size()) - 1); + obj.name = std::string(light->mName.data); ASSIMP_LOG_DEBUG("AC3D: Light source encountered"); obj.type = Object::Light; - } - else if (!ASSIMP_strincmp(buffer,"group",5)) - { + } else if (!ASSIMP_strincmp(buffer, "group", 5)) { obj.type = Object::Group; - } - else if (!ASSIMP_strincmp(buffer,"world",5)) - { + } else if (!ASSIMP_strincmp(buffer, "world", 5)) { obj.type = Object::World; - } - else obj.type = Object::Poly; - while (GetNextLine()) - { - if (TokenMatch(buffer,"kids",4)) - { + } else + obj.type = Object::Poly; + while (GetNextLine()) { + if (TokenMatch(buffer, "kids", 4)) { SkipSpaces(&buffer); - unsigned int num = strtoul10(buffer,&buffer); + unsigned int num = strtoul10(buffer, &buffer); GetNextLine(); - if (num) - { + if (num) { // load the children of this object recursively obj.children.reserve(num); for (unsigned int i = 0; i < num; ++i) LoadObjectSection(obj.children); } return; - } - else if (TokenMatch(buffer,"name",4)) - { + } else if (TokenMatch(buffer, "name", 4)) { SkipSpaces(&buffer); AI_AC_GET_STRING(obj.name); // If this is a light source, we'll also need to store // the name of the node in it. - if (light) - { + if (light) { light->mName.Set(obj.name); } - } - else if (TokenMatch(buffer,"texture",7)) - { + } else if (TokenMatch(buffer, "texture", 7)) { SkipSpaces(&buffer); AI_AC_GET_STRING(obj.texture); - } - else if (TokenMatch(buffer,"texrep",6)) - { + } else if (TokenMatch(buffer, "texrep", 6)) { SkipSpaces(&buffer); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,2,&obj.texRepeat); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("", 0, 2, &obj.texRepeat); if (!obj.texRepeat.x || !obj.texRepeat.y) - obj.texRepeat = aiVector2D (1.f,1.f); - } - else if (TokenMatch(buffer,"texoff",6)) - { + obj.texRepeat = aiVector2D(1.f, 1.f); + } else if (TokenMatch(buffer, "texoff", 6)) { SkipSpaces(&buffer); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,2,&obj.texOffset); - } - else if (TokenMatch(buffer,"rot",3)) - { + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("", 0, 2, &obj.texOffset); + } else if (TokenMatch(buffer, "rot", 3)) { SkipSpaces(&buffer); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,9,&obj.rotation); - } - else if (TokenMatch(buffer,"loc",3)) - { + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("", 0, 9, &obj.rotation); + } else if (TokenMatch(buffer, "loc", 3)) { SkipSpaces(&buffer); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,3,&obj.translation); - } - else if (TokenMatch(buffer,"subdiv",6)) - { + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("", 0, 3, &obj.translation); + } else if (TokenMatch(buffer, "subdiv", 6)) { SkipSpaces(&buffer); - obj.subDiv = strtoul10(buffer,&buffer); - } - else if (TokenMatch(buffer,"crease",6)) - { + obj.subDiv = strtoul10(buffer, &buffer); + } else if (TokenMatch(buffer, "crease", 6)) { SkipSpaces(&buffer); obj.crease = fast_atof(buffer); - } - else if (TokenMatch(buffer,"numvert",7)) - { + } else if (TokenMatch(buffer, "numvert", 7)) { SkipSpaces(&buffer); - unsigned int t = strtoul10(buffer,&buffer); + unsigned int t = strtoul10(buffer, &buffer); if (t >= AI_MAX_ALLOC(aiVector3D)) { throw DeadlyImportError("AC3D: Too many vertices, would run out of memory"); } obj.vertices.reserve(t); - for (unsigned int i = 0; i < t;++i) - { - if (!GetNextLine()) - { + for (unsigned int i = 0; i < t; ++i) { + if (!GetNextLine()) { ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: not all vertices have been parsed yet"); break; - } - else if (!IsNumeric(*buffer)) - { + } else if (!IsNumeric(*buffer)) { ASSIMP_LOG_ERROR("AC3D: Unexpected token: not all vertices have been parsed yet"); --buffer; // make sure the line is processed a second time break; } obj.vertices.push_back(aiVector3D()); - aiVector3D& v = obj.vertices.back(); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,3,&v.x); + aiVector3D &v = obj.vertices.back(); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("", 0, 3, &v.x); } - } - else if (TokenMatch(buffer,"numsurf",7)) - { + } else if (TokenMatch(buffer, "numsurf", 7)) { SkipSpaces(&buffer); bool Q3DWorkAround = false; - const unsigned int t = strtoul10(buffer,&buffer); + const unsigned int t = strtoul10(buffer, &buffer); obj.surfaces.reserve(t); - for (unsigned int i = 0; i < t;++i) - { + for (unsigned int i = 0; i < t; ++i) { GetNextLine(); - if (!TokenMatch(buffer,"SURF",4)) - { + if (!TokenMatch(buffer, "SURF", 4)) { // FIX: this can occur for some files - Quick 3D for // example writes no surf chunks - if (!Q3DWorkAround) - { + if (!Q3DWorkAround) { ASSIMP_LOG_WARN("AC3D: SURF token was expected"); ASSIMP_LOG_DEBUG("Continuing with Quick3D Workaround enabled"); } @@ -348,27 +296,20 @@ void AC3DImporter::LoadObjectSection(std::vector& objects) } SkipSpaces(&buffer); obj.surfaces.push_back(Surface()); - Surface& surf = obj.surfaces.back(); + Surface &surf = obj.surfaces.back(); surf.flags = strtoul_cppstyle(buffer); - while (1) - { - if(!GetNextLine()) - { + while (1) { + if (!GetNextLine()) { throw DeadlyImportError("AC3D: Unexpected EOF: surface is incomplete"); } - if (TokenMatch(buffer,"mat",3)) - { + if (TokenMatch(buffer, "mat", 3)) { SkipSpaces(&buffer); surf.mat = strtoul10(buffer); - } - else if (TokenMatch(buffer,"refs",4)) - { + } else if (TokenMatch(buffer, "refs", 4)) { // --- see fix notes above - if (Q3DWorkAround) - { - if (!surf.entries.empty()) - { + if (Q3DWorkAround) { + if (!surf.entries.empty()) { buffer -= 6; break; } @@ -380,23 +321,19 @@ void AC3DImporter::LoadObjectSection(std::vector& objects) obj.numRefs += m; - for (unsigned int k = 0; k < m; ++k) - { - if(!GetNextLine()) - { + for (unsigned int k = 0; k < m; ++k) { + if (!GetNextLine()) { ASSIMP_LOG_ERROR("AC3D: Unexpected EOF: surface references are incomplete"); break; } surf.entries.push_back(Surface::SurfaceEntry()); - Surface::SurfaceEntry& entry = surf.entries.back(); + Surface::SurfaceEntry &entry = surf.entries.back(); - entry.first = strtoul10(buffer,&buffer); + entry.first = strtoul10(buffer, &buffer); SkipSpaces(&buffer); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("",0,2,&entry.second); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("", 0, 2, &entry.second); } - } - else - { + } else { --buffer; // make sure the line is processed a second time break; @@ -410,65 +347,57 @@ void AC3DImporter::LoadObjectSection(std::vector& objects) // ------------------------------------------------------------------------------------------------ // Convert a material from AC3DImporter::Material to aiMaterial -void AC3DImporter::ConvertMaterial(const Object& object, - const Material& matSrc, - aiMaterial& matDest) -{ +void AC3DImporter::ConvertMaterial(const Object &object, + const Material &matSrc, + aiMaterial &matDest) { aiString s; - if (matSrc.name.length()) - { + if (matSrc.name.length()) { s.Set(matSrc.name); - matDest.AddProperty(&s,AI_MATKEY_NAME); + matDest.AddProperty(&s, AI_MATKEY_NAME); } - if (object.texture.length()) - { + if (object.texture.length()) { s.Set(object.texture); - matDest.AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0)); + matDest.AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0)); // UV transformation if (1.f != object.texRepeat.x || 1.f != object.texRepeat.y || - object.texOffset.x || object.texOffset.y) - { + object.texOffset.x || object.texOffset.y) { aiUVTransform transform; transform.mScaling = object.texRepeat; transform.mTranslation = object.texOffset; - matDest.AddProperty(&transform,1,AI_MATKEY_UVTRANSFORM_DIFFUSE(0)); + matDest.AddProperty(&transform, 1, AI_MATKEY_UVTRANSFORM_DIFFUSE(0)); } } - matDest.AddProperty(&matSrc.rgb,1, AI_MATKEY_COLOR_DIFFUSE); - matDest.AddProperty(&matSrc.amb,1, AI_MATKEY_COLOR_AMBIENT); - matDest.AddProperty(&matSrc.emis,1,AI_MATKEY_COLOR_EMISSIVE); - matDest.AddProperty(&matSrc.spec,1,AI_MATKEY_COLOR_SPECULAR); + matDest.AddProperty(&matSrc.rgb, 1, AI_MATKEY_COLOR_DIFFUSE); + matDest.AddProperty(&matSrc.amb, 1, AI_MATKEY_COLOR_AMBIENT); + matDest.AddProperty(&matSrc.emis, 1, AI_MATKEY_COLOR_EMISSIVE); + matDest.AddProperty(&matSrc.spec, 1, AI_MATKEY_COLOR_SPECULAR); int n; - if (matSrc.shin) - { + if (matSrc.shin) { n = aiShadingMode_Phong; - matDest.AddProperty(&matSrc.shin,1,AI_MATKEY_SHININESS); - } - else n = aiShadingMode_Gouraud; - matDest.AddProperty(&n,1,AI_MATKEY_SHADING_MODEL); + matDest.AddProperty(&matSrc.shin, 1, AI_MATKEY_SHININESS); + } else + n = aiShadingMode_Gouraud; + matDest.AddProperty(&n, 1, AI_MATKEY_SHADING_MODEL); float f = 1.f - matSrc.trans; - matDest.AddProperty(&f,1,AI_MATKEY_OPACITY); + matDest.AddProperty(&f, 1, AI_MATKEY_OPACITY); } // ------------------------------------------------------------------------------------------------ // Converts the loaded data to the internal verbose representation -aiNode* AC3DImporter::ConvertObjectSection(Object& object, - std::vector& meshes, - std::vector& outMaterials, - const std::vector& materials, - aiNode* parent) -{ - aiNode* node = new aiNode(); +aiNode *AC3DImporter::ConvertObjectSection(Object &object, + std::vector &meshes, + std::vector &outMaterials, + const std::vector &materials, + aiNode *parent) { + aiNode *node = new aiNode(); node->mParent = parent; - if (object.vertices.size()) - { - if (!object.surfaces.size() || !object.numRefs) - { + if (object.vertices.size()) { + if (!object.surfaces.size() || !object.numRefs) { /* " An object with 7 vertices (no surfaces, no materials defined). This is a good way of getting point data into AC3D. The Vertex->create convex-surface/object can be used on these @@ -479,17 +408,16 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, */ ASSIMP_LOG_INFO("AC3D: No surfaces defined in object definition, " - "a point list is returned"); + "a point list is returned"); meshes.push_back(new aiMesh()); - aiMesh* mesh = meshes.back(); + aiMesh *mesh = meshes.back(); mesh->mNumFaces = mesh->mNumVertices = (unsigned int)object.vertices.size(); - aiFace* faces = mesh->mFaces = new aiFace[mesh->mNumFaces]; - aiVector3D* verts = mesh->mVertices = new aiVector3D[mesh->mNumVertices]; + aiFace *faces = mesh->mFaces = new aiFace[mesh->mNumFaces]; + aiVector3D *verts = mesh->mVertices = new aiVector3D[mesh->mNumVertices]; - for (unsigned int i = 0; i < mesh->mNumVertices;++i,++faces,++verts) - { + for (unsigned int i = 0; i < mesh->mNumVertices; ++i, ++faces, ++verts) { *verts = object.vertices[i]; faces->mNumIndices = 1; faces->mIndices = new unsigned int[1]; @@ -502,86 +430,77 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, mesh->mMaterialIndex = 0; outMaterials.push_back(new aiMaterial()); ConvertMaterial(object, materials[0], *outMaterials.back()); - } - else - { + } else { // need to generate one or more meshes for this object. // find out how many different materials we have - typedef std::pair< unsigned int, unsigned int > IntPair; - typedef std::vector< IntPair > MatTable; - MatTable needMat(materials.size(),IntPair(0,0)); + typedef std::pair IntPair; + typedef std::vector MatTable; + MatTable needMat(materials.size(), IntPair(0, 0)); - std::vector::iterator it,end = object.surfaces.end(); - std::vector::iterator it2,end2; + std::vector::iterator it, end = object.surfaces.end(); + std::vector::iterator it2, end2; - for (it = object.surfaces.begin(); it != end; ++it) - { + for (it = object.surfaces.begin(); it != end; ++it) { unsigned int idx = (*it).mat; - if (idx >= needMat.size()) - { + if (idx >= needMat.size()) { ASSIMP_LOG_ERROR("AC3D: material index is out of range"); idx = 0; } - if ((*it).entries.empty()) - { + if ((*it).entries.empty()) { ASSIMP_LOG_WARN("AC3D: surface her zero vertex references"); } // validate all vertex indices to make sure we won't crash here - for (it2 = (*it).entries.begin(), - end2 = (*it).entries.end(); it2 != end2; ++it2) - { - if ((*it2).first >= object.vertices.size()) - { + for (it2 = (*it).entries.begin(), + end2 = (*it).entries.end(); + it2 != end2; ++it2) { + if ((*it2).first >= object.vertices.size()) { ASSIMP_LOG_WARN("AC3D: Invalid vertex reference"); (*it2).first = 0; } } - if (!needMat[idx].first)++node->mNumMeshes; + if (!needMat[idx].first) ++node->mNumMeshes; - switch ((*it).flags & 0xf) - { - // closed line - case 0x1: + switch ((*it).flags & 0xf) { + // closed line + case 0x1: - needMat[idx].first += (unsigned int)(*it).entries.size(); - needMat[idx].second += (unsigned int)(*it).entries.size()<<1u; - break; + needMat[idx].first += (unsigned int)(*it).entries.size(); + needMat[idx].second += (unsigned int)(*it).entries.size() << 1u; + break; - // unclosed line - case 0x2: + // unclosed line + case 0x2: - needMat[idx].first += (unsigned int)(*it).entries.size()-1; - needMat[idx].second += ((unsigned int)(*it).entries.size()-1)<<1u; - break; + needMat[idx].first += (unsigned int)(*it).entries.size() - 1; + needMat[idx].second += ((unsigned int)(*it).entries.size() - 1) << 1u; + break; - // 0 == polygon, else unknown - default: + // 0 == polygon, else unknown + default: - if ((*it).flags & 0xf) - { - ASSIMP_LOG_WARN("AC3D: The type flag of a surface is unknown"); - (*it).flags &= ~(0xf); - } + if ((*it).flags & 0xf) { + ASSIMP_LOG_WARN("AC3D: The type flag of a surface is unknown"); + (*it).flags &= ~(0xf); + } - // the number of faces increments by one, the number - // of vertices by surface.numref. - needMat[idx].first++; - needMat[idx].second += (unsigned int)(*it).entries.size(); + // the number of faces increments by one, the number + // of vertices by surface.numref. + needMat[idx].first++; + needMat[idx].second += (unsigned int)(*it).entries.size(); }; } - unsigned int* pip = node->mMeshes = new unsigned int[node->mNumMeshes]; + unsigned int *pip = node->mMeshes = new unsigned int[node->mNumMeshes]; unsigned int mat = 0; const size_t oldm = meshes.size(); for (MatTable::const_iterator cit = needMat.begin(), cend = needMat.end(); - cit != cend; ++cit, ++mat) - { - if (!(*cit).first)continue; + cit != cend; ++cit, ++mat) { + if (!(*cit).first) continue; // allocate a new aiMesh object *pip++ = (unsigned int)meshes.size(); - aiMesh* mesh = new aiMesh(); + aiMesh *mesh = new aiMesh(); meshes.push_back(mesh); mesh->mMaterialIndex = (unsigned int)outMaterials.size(); @@ -595,7 +514,7 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, } else if (mesh->mNumFaces > AI_MAX_ALLOC(aiFace)) { throw DeadlyImportError("AC3D: Too many faces, would run out of memory"); } - aiFace* faces = mesh->mFaces = new aiFace[mesh->mNumFaces]; + aiFace *faces = mesh->mFaces = new aiFace[mesh->mNumFaces]; mesh->mNumVertices = (*cit).second; if (mesh->mNumVertices == 0) { @@ -603,35 +522,29 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, } else if (mesh->mNumVertices > AI_MAX_ALLOC(aiVector3D)) { throw DeadlyImportError("AC3D: Too many vertices, would run out of memory"); } - aiVector3D* vertices = mesh->mVertices = new aiVector3D[mesh->mNumVertices]; + aiVector3D *vertices = mesh->mVertices = new aiVector3D[mesh->mNumVertices]; unsigned int cur = 0; // allocate UV coordinates, but only if the texture name for the // surface is not empty - aiVector3D* uv = NULL; - if(object.texture.length()) - { + aiVector3D *uv = NULL; + if (object.texture.length()) { uv = mesh->mTextureCoords[0] = new aiVector3D[mesh->mNumVertices]; mesh->mNumUVComponents[0] = 2; } - for (it = object.surfaces.begin(); it != end; ++it) - { - if (mat == (*it).mat) - { - const Surface& src = *it; + for (it = object.surfaces.begin(); it != end; ++it) { + if (mat == (*it).mat) { + const Surface &src = *it; // closed polygon unsigned int type = (*it).flags & 0xf; - if (!type) - { - aiFace& face = *faces++; - if((face.mNumIndices = (unsigned int)src.entries.size())) - { + if (!type) { + aiFace &face = *faces++; + if ((face.mNumIndices = (unsigned int)src.entries.size())) { face.mIndices = new unsigned int[face.mNumIndices]; - for (unsigned int i = 0; i < face.mNumIndices;++i,++vertices) - { - const Surface::SurfaceEntry& entry = src.entries[i]; + for (unsigned int i = 0; i < face.mNumIndices; ++i, ++vertices) { + const Surface::SurfaceEntry &entry = src.entries[i]; face.mIndices[i] = cur++; // copy vertex positions @@ -640,28 +553,23 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, } *vertices = object.vertices[entry.first] + object.translation; - // copy texture coordinates - if (uv) - { - uv->x = entry.second.x; - uv->y = entry.second.y; + if (uv) { + uv->x = entry.second.x; + uv->y = entry.second.y; ++uv; } } } - } - else - { + } else { - it2 = (*it).entries.begin(); + it2 = (*it).entries.begin(); // either a closed or an unclosed line unsigned int tmp = (unsigned int)(*it).entries.size(); - if (0x2 == type)--tmp; - for (unsigned int m = 0; m < tmp;++m) - { - aiFace& face = *faces++; + if (0x2 == type) --tmp; + for (unsigned int m = 0; m < tmp; ++m) { + aiFace &face = *faces++; face.mNumIndices = 2; face.mIndices = new unsigned int[2]; @@ -669,35 +577,31 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, face.mIndices[1] = cur++; // copy vertex positions - if (it2 == (*it).entries.end() ) { + if (it2 == (*it).entries.end()) { throw DeadlyImportError("AC3D: Bad line"); } ai_assert((*it2).first < object.vertices.size()); *vertices++ = object.vertices[(*it2).first]; // copy texture coordinates - if (uv) - { - uv->x = (*it2).second.x; - uv->y = (*it2).second.y; + if (uv) { + uv->x = (*it2).second.x; + uv->y = (*it2).second.y; ++uv; } - - if (0x1 == type && tmp-1 == m) - { + if (0x1 == type && tmp - 1 == m) { // if this is a closed line repeat its beginning now - it2 = (*it).entries.begin(); - } - else ++it2; + it2 = (*it).entries.begin(); + } else + ++it2; // second point *vertices++ = object.vertices[(*it2).first]; - if (uv) - { - uv->x = (*it2).second.x; - uv->y = (*it2).second.y; + if (uv) { + uv->x = (*it2).second.x; + uv->y = (*it2).second.y; ++uv; } } @@ -709,20 +613,18 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, // Now apply catmull clark subdivision if necessary. We split meshes into // materials which is not done by AC3D during smoothing, so we need to // collect all meshes using the same material group. - if (object.subDiv) { + if (object.subDiv) { if (configEvalSubdivision) { std::unique_ptr div(Subdivider::Create(Subdivider::CATMULL_CLARKE)); - ASSIMP_LOG_INFO("AC3D: Evaluating subdivision surface: "+object.name); + ASSIMP_LOG_INFO("AC3D: Evaluating subdivision surface: " + object.name); - std::vector cpy(meshes.size()-oldm,NULL); - div->Subdivide(&meshes[oldm],cpy.size(),&cpy.front(),object.subDiv,true); - std::copy(cpy.begin(),cpy.end(),meshes.begin()+oldm); + std::vector cpy(meshes.size() - oldm, NULL); + div->Subdivide(&meshes[oldm], cpy.size(), &cpy.front(), object.subDiv, true); + std::copy(cpy.begin(), cpy.end(), meshes.begin() + oldm); // previous meshes are deleted vy Subdivide(). - } - else { - ASSIMP_LOG_INFO("AC3D: Letting the subdivision surface untouched due to my configuration: " - +object.name); + } else { + ASSIMP_LOG_INFO("AC3D: Letting the subdivision surface untouched due to my configuration: " + object.name); } } } @@ -730,48 +632,42 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, if (object.name.length()) node->mName.Set(object.name); - else - { + else { // generate a name depending on the type of the node - switch (object.type) - { - case Object::Group: - node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACGroup_%i",groups++); - break; - case Object::Poly: - node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACPoly_%i",polys++); - break; - case Object::Light: - node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACLight_%i",lights++); - break; + switch (object.type) { + case Object::Group: + node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACGroup_%i", mGroupsCounter++); + break; + case Object::Poly: + node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACPoly_%i", mPolysCounter++); + break; + case Object::Light: + node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACLight_%i", mLightsCounter++); + break; - // there shouldn't be more than one world, but we don't care - case Object::World: - node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACWorld_%i",worlds++); - break; + // there shouldn't be more than one world, but we don't care + case Object::World: + node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACWorld_%i", mWorldsCounter++); + break; } } - // setup the local transformation matrix of the object // compute the transformation offset to the parent node - node->mTransformation = aiMatrix4x4 ( object.rotation ); + node->mTransformation = aiMatrix4x4(object.rotation); - if (object.type == Object::Group || !object.numRefs) - { + if (object.type == Object::Group || !object.numRefs) { node->mTransformation.a4 = object.translation.x; node->mTransformation.b4 = object.translation.y; node->mTransformation.c4 = object.translation.z; } // add children to the object - if (object.children.size()) - { + if (object.children.size()) { node->mNumChildren = (unsigned int)object.children.size(); - node->mChildren = new aiNode*[node->mNumChildren]; - for (unsigned int i = 0; i < node->mNumChildren;++i) - { - node->mChildren[i] = ConvertObjectSection(object.children[i],meshes,outMaterials,materials,node); + node->mChildren = new aiNode *[node->mNumChildren]; + for (unsigned int i = 0; i < node->mNumChildren; ++i) { + node->mChildren[i] = ConvertObjectSection(object.children[i], meshes, outMaterials, materials, node); } } @@ -779,40 +675,38 @@ aiNode* AC3DImporter::ConvertObjectSection(Object& object, } // ------------------------------------------------------------------------------------------------ -void AC3DImporter::SetupProperties(const Importer* pImp) -{ - configSplitBFCull = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_AC_SEPARATE_BFCULL,1) ? true : false; - configEvalSubdivision = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_AC_EVAL_SUBDIVISION,1) ? true : false; +void AC3DImporter::SetupProperties(const Importer *pImp) { + configSplitBFCull = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_AC_SEPARATE_BFCULL, 1) ? true : false; + configEvalSubdivision = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_AC_EVAL_SUBDIVISION, 1) ? true : false; } // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. -void AC3DImporter::InternReadFile( const std::string& pFile, - aiScene* pScene, IOSystem* pIOHandler) -{ - std::unique_ptr file( pIOHandler->Open( pFile, "rb")); +void AC3DImporter::InternReadFile(const std::string &pFile, + aiScene *pScene, IOSystem *pIOHandler) { + std::unique_ptr file(pIOHandler->Open(pFile, "rb")); // Check whether we can read from the file - if( file.get() == NULL) - throw DeadlyImportError( "Failed to open AC3D file " + pFile + "."); + if (file.get() == NULL) + throw DeadlyImportError("Failed to open AC3D file " + pFile + "."); // allocate storage and copy the contents of the file to a memory buffer std::vector mBuffer2; - TextFileToBuffer(file.get(),mBuffer2); + TextFileToBuffer(file.get(), mBuffer2); buffer = &mBuffer2[0]; mNumMeshes = 0; - lights = polys = worlds = groups = 0; + mLightsCounter = mPolysCounter = mWorldsCounter = mGroupsCounter = 0; - if (::strncmp(buffer,"AC3D",4)) { + if (::strncmp(buffer, "AC3D", 4)) { throw DeadlyImportError("AC3D: No valid AC3D file, magic sequence not found"); } // print the file format version to the console - unsigned int version = HexDigitToDecimal( buffer[4] ); + unsigned int version = HexDigitToDecimal(buffer[4]); char msg[3]; - ASSIMP_itoa10(msg,3,version); + ASSIMP_itoa10(msg, 3, version); ASSIMP_LOG_INFO_F("AC3D file format version: ", msg); std::vector materials; @@ -821,89 +715,81 @@ void AC3DImporter::InternReadFile( const std::string& pFile, std::vector rootObjects; rootObjects.reserve(5); - std::vector lights; - mLights = & lights; + std::vector lights; + mLights = &lights; - while (GetNextLine()) - { - if (TokenMatch(buffer,"MATERIAL",8)) - { + while (GetNextLine()) { + if (TokenMatch(buffer, "MATERIAL", 8)) { materials.push_back(Material()); - Material& mat = materials.back(); + Material &mat = materials.back(); // manually parse the material ... sscanf would use the buldin atof ... // Format: (name) rgb %f %f %f amb %f %f %f emis %f %f %f spec %f %f %f shi %d trans %f AI_AC_SKIP_TO_NEXT_TOKEN(); - if ('\"' == *buffer) - { + if ('\"' == *buffer) { AI_AC_GET_STRING(mat.name); AI_AC_SKIP_TO_NEXT_TOKEN(); } - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("rgb",3,3,&mat.rgb); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("amb",3,3,&mat.amb); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("emis",4,3,&mat.emis); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("spec",4,3,&mat.spec); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("shi",3,1,&mat.shin); - AI_AC_CHECKED_LOAD_FLOAT_ARRAY("trans",5,1,&mat.trans); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("rgb", 3, 3, &mat.rgb); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("amb", 3, 3, &mat.amb); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("emis", 4, 3, &mat.emis); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("spec", 4, 3, &mat.spec); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("shi", 3, 1, &mat.shin); + AI_AC_CHECKED_LOAD_FLOAT_ARRAY("trans", 5, 1, &mat.trans); } LoadObjectSection(rootObjects); } - if (rootObjects.empty() || !mNumMeshes) - { + if (rootObjects.empty() || !mNumMeshes) { throw DeadlyImportError("AC3D: No meshes have been loaded"); } - if (materials.empty()) - { + if (materials.empty()) { ASSIMP_LOG_WARN("AC3D: No material has been found"); materials.push_back(Material()); } - mNumMeshes += (mNumMeshes>>2u) + 1; - std::vector meshes; + mNumMeshes += (mNumMeshes >> 2u) + 1; + std::vector meshes; meshes.reserve(mNumMeshes); - std::vector omaterials; + std::vector omaterials; materials.reserve(mNumMeshes); // generate a dummy root if there are multiple objects on the top layer - Object* root; + Object *root; if (1 == rootObjects.size()) root = &rootObjects[0]; - else - { + else { root = new Object(); } // now convert the imported stuff to our output data structure - pScene->mRootNode = ConvertObjectSection(*root,meshes,omaterials,materials); - if (1 != rootObjects.size())delete root; + pScene->mRootNode = ConvertObjectSection(*root, meshes, omaterials, materials); + if (1 != rootObjects.size()) delete root; - if (!::strncmp( pScene->mRootNode->mName.data, "Node", 4)) + if (!::strncmp(pScene->mRootNode->mName.data, "Node", 4)) pScene->mRootNode->mName.Set(""); // copy meshes - if (meshes.empty()) - { + if (meshes.empty()) { throw DeadlyImportError("An unknown error occurred during converting"); } pScene->mNumMeshes = (unsigned int)meshes.size(); - pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; - ::memcpy(pScene->mMeshes,&meshes[0],pScene->mNumMeshes*sizeof(void*)); + pScene->mMeshes = new aiMesh *[pScene->mNumMeshes]; + ::memcpy(pScene->mMeshes, &meshes[0], pScene->mNumMeshes * sizeof(void *)); // copy materials pScene->mNumMaterials = (unsigned int)omaterials.size(); - pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials]; - ::memcpy(pScene->mMaterials,&omaterials[0],pScene->mNumMaterials*sizeof(void*)); + pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials]; + ::memcpy(pScene->mMaterials, &omaterials[0], pScene->mNumMaterials * sizeof(void *)); // copy lights pScene->mNumLights = (unsigned int)lights.size(); - if (lights.size()) - { - pScene->mLights = new aiLight*[lights.size()]; - ::memcpy(pScene->mLights,&lights[0],lights.size()*sizeof(void*)); + if (lights.size()) { + pScene->mLights = new aiLight *[lights.size()]; + ::memcpy(pScene->mLights, &lights[0], lights.size() * sizeof(void *)); } } diff --git a/code/AC/ACLoader.h b/code/AC/ACLoader.h index 1fc654f3c..890fb2ac2 100644 --- a/code/AC/ACLoader.h +++ b/code/AC/ACLoader.h @@ -268,7 +268,7 @@ private: std::vector* mLights; // name counters - unsigned int lights, groups, polys, worlds; + unsigned int mLightsCounter, mGroupsCounter, mPolysCounter, mWorldsCounter; }; } // end of namespace Assimp diff --git a/code/AMF/AMFImporter_Postprocess.cpp b/code/AMF/AMFImporter_Postprocess.cpp index 8496d8ded..273b8e0c4 100644 --- a/code/AMF/AMFImporter_Postprocess.cpp +++ b/code/AMF/AMFImporter_Postprocess.cpp @@ -465,7 +465,7 @@ std::list mesh_idx; { auto VertexIndex_GetMinimal = [](const std::list& pFaceList, const size_t* pBiggerThan) -> size_t { - size_t rv; + size_t rv=0; if(pBiggerThan != nullptr) { diff --git a/code/HMP/HMPLoader.cpp b/code/HMP/HMPLoader.cpp index 0d1334fdd..0dea09ee0 100644 --- a/code/HMP/HMPLoader.cpp +++ b/code/HMP/HMPLoader.cpp @@ -118,11 +118,11 @@ void HMPImporter::InternReadFile( const std::string& pFile, aiScene* _pScene, IOSystem* _pIOHandler) { pScene = _pScene; - pIOHandler = _pIOHandler; - std::unique_ptr file( pIOHandler->Open( pFile)); + mIOHandler = _pIOHandler; + std::unique_ptr file(mIOHandler->Open(pFile)); // Check whether we can read from the file - if( file.get() == NULL) + if( file.get() == nullptr) throw DeadlyImportError( "Failed to open HMP file " + pFile + "."); // Check whether the HMP file is large enough to contain diff --git a/code/LWO/LWOAnimation.cpp b/code/LWO/LWOAnimation.cpp index ae9c4c13b..c5913b7f1 100644 --- a/code/LWO/LWOAnimation.cpp +++ b/code/LWO/LWOAnimation.cpp @@ -185,9 +185,11 @@ void AnimResolver::UpdateAnimRangeSetup() for (unsigned int i = 0; i < num; ++i) { m = n+old_size*(i+1); std::copy(n,n+old_size,m); - - if ((*it).pre == LWO::PrePostBehaviour_Oscillate && (reverse = !reverse)) + const bool res = ((*it).pre == LWO::PrePostBehaviour_Oscillate); + reverse = !reverse; + if (res && reverse ) { std::reverse(m,m+old_size-1); + } } // update time values @@ -533,7 +535,7 @@ void AnimResolver::GetKeys(std::vector& out, // ------------------------------------------------------------------------------------------------ // Extract animation channel -void AnimResolver::ExtractAnimChannel(aiNodeAnim** out, unsigned int flags /*= 0*/) +void AnimResolver::ExtractAnimChannel(aiNodeAnim** out, unsigned int /*= 0*/) { *out = NULL; diff --git a/code/MDL/MDLLoader.cpp b/code/MDL/MDLLoader.cpp index 11c6e3ecb..4128b4bfe 100644 --- a/code/MDL/MDLLoader.cpp +++ b/code/MDL/MDLLoader.cpp @@ -49,17 +49,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_MDL_IMPORTER #include "MDL/MDLLoader.h" -#include "MDL/MDLDefaultColorMap.h" #include "MD2/MD2FileData.h" #include "MDL/HalfLife/HL1MDLLoader.h" +#include "MDL/MDLDefaultColorMap.h" -#include #include -#include -#include +#include +#include #include #include -#include +#include +#include #include @@ -80,24 +80,19 @@ static const aiImporterDesc desc = { // ------------------------------------------------------------------------------------------------ // Ugly stuff ... nevermind -#define _AI_MDL7_ACCESS(_data, _index, _limit, _type) \ - (*((const _type*)(((const char*)_data) + _index * _limit))) +#define _AI_MDL7_ACCESS(_data, _index, _limit, _type) \ + (*((const _type *)(((const char *)_data) + _index * _limit))) -#define _AI_MDL7_ACCESS_PTR(_data, _index, _limit, _type) \ - ((BE_NCONST _type*)(((const char*)_data) + _index * _limit)) +#define _AI_MDL7_ACCESS_PTR(_data, _index, _limit, _type) \ + ((BE_NCONST _type *)(((const char *)_data) + _index * _limit)) -#define _AI_MDL7_ACCESS_VERT(_data, _index, _limit) \ - _AI_MDL7_ACCESS(_data,_index,_limit,MDL::Vertex_MDL7) +#define _AI_MDL7_ACCESS_VERT(_data, _index, _limit) \ + _AI_MDL7_ACCESS(_data, _index, _limit, MDL::Vertex_MDL7) // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer -MDLImporter::MDLImporter() -: configFrameID() -, mBuffer() -, iGSFileVersion() -, pIOHandler() -, pScene() -, iFileSize() { +MDLImporter::MDLImporter() : + configFrameID(), mBuffer(), iGSFileVersion(), mIOHandler(nullptr), pScene(), iFileSize() { // empty } @@ -109,11 +104,11 @@ MDLImporter::~MDLImporter() { // ------------------------------------------------------------------------------------------------ // Returns whether the class can handle the format of the given file. -bool MDLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const { +bool MDLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const { const std::string extension = GetExtension(pFile); // if check for extension is not enough, check for the magic tokens - if (extension == "mdl" || !extension.length() || checkSig) { + if (extension == "mdl" || !extension.length() || checkSig) { uint32_t tokens[8]; tokens[0] = AI_MDL_MAGIC_NUMBER_LE_HL2a; tokens[1] = AI_MDL_MAGIC_NUMBER_LE_HL2b; @@ -123,26 +118,25 @@ bool MDLImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool tokens[5] = AI_MDL_MAGIC_NUMBER_LE_GS4; tokens[6] = AI_MDL_MAGIC_NUMBER_LE_GS3; tokens[7] = AI_MDL_MAGIC_NUMBER_LE; - return CheckMagicToken(pIOHandler,pFile,tokens,8,0); + return CheckMagicToken(pIOHandler, pFile, tokens, 8, 0); } return false; } // ------------------------------------------------------------------------------------------------ // Setup configuration properties -void MDLImporter::SetupProperties(const Importer* pImp) -{ - configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_MDL_KEYFRAME,-1); +void MDLImporter::SetupProperties(const Importer *pImp) { + configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_MDL_KEYFRAME, -1); // The // AI_CONFIG_IMPORT_MDL_KEYFRAME option overrides the // AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option. - if(static_cast(-1) == configFrameID) { - configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0); + if (static_cast(-1) == configFrameID) { + configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME, 0); } // AI_CONFIG_IMPORT_MDL_COLORMAP - palette file - configPalette = pImp->GetPropertyString(AI_CONFIG_IMPORT_MDL_COLORMAP,"colormap.lmp"); + configPalette = pImp->GetPropertyString(AI_CONFIG_IMPORT_MDL_COLORMAP, "colormap.lmp"); // Read configuration specific to MDL (Half-Life 1). mHL1ImportSettings.read_animations = pImp->GetPropertyBool(AI_CONFIG_IMPORT_MDL_HL1_READ_ANIMATIONS, true); @@ -159,121 +153,114 @@ void MDLImporter::SetupProperties(const Importer* pImp) // ------------------------------------------------------------------------------------------------ // Get a list of all supported extensions -const aiImporterDesc* MDLImporter::GetInfo () const -{ +const aiImporterDesc *MDLImporter::GetInfo() const { return &desc; } // ------------------------------------------------------------------------------------------------ // Imports the given file into the given scene structure. -void MDLImporter::InternReadFile( const std::string& pFile, - aiScene* _pScene, IOSystem* _pIOHandler) -{ - pScene = _pScene; - pIOHandler = _pIOHandler; - std::unique_ptr file( pIOHandler->Open( pFile)); +void MDLImporter::InternReadFile(const std::string &pFile, + aiScene *_pScene, IOSystem *pIOHandler) { + pScene = _pScene; + mIOHandler = pIOHandler; + std::unique_ptr file(pIOHandler->Open(pFile)); // Check whether we can read from the file - if( file.get() == NULL) { - throw DeadlyImportError( "Failed to open MDL file " + pFile + "."); + if (file.get() == nullptr) { + throw DeadlyImportError("Failed to open MDL file " + pFile + "."); } // This should work for all other types of MDL files, too ... // the HL1 sequence group header is one of the smallest, afaik iFileSize = (unsigned int)file->FileSize(); - if( iFileSize < sizeof(MDL::HalfLife::SequenceHeader_HL1)) { - throw DeadlyImportError( "MDL File is too small."); + if (iFileSize < sizeof(MDL::HalfLife::SequenceHeader_HL1)) { + throw DeadlyImportError("MDL File is too small."); } - + // delete the file buffer and cleanup. auto DeleteBufferAndCleanup = [&]() { if (mBuffer) { - delete [] mBuffer; + delete[] mBuffer; mBuffer = nullptr; } - AI_DEBUG_INVALIDATE_PTR(pIOHandler); + AI_DEBUG_INVALIDATE_PTR(mIOHandler); AI_DEBUG_INVALIDATE_PTR(pScene); }; - + try { // Allocate storage and copy the contents of the file to a memory buffer - mBuffer = new unsigned char[iFileSize+1]; - file->Read( (void*)mBuffer, 1, iFileSize); + mBuffer = new unsigned char[iFileSize + 1]; + file->Read((void *)mBuffer, 1, iFileSize); // Append a binary zero to the end of the buffer. // this is just for safety that string parsing routines // find the end of the buffer ... mBuffer[iFileSize] = '\0'; - const uint32_t iMagicWord = *((uint32_t*)mBuffer); + const uint32_t iMagicWord = *((uint32_t *)mBuffer); // Determine the file subtype and call the appropriate member function // Original Quake1 format - if (AI_MDL_MAGIC_NUMBER_BE == iMagicWord || AI_MDL_MAGIC_NUMBER_LE == iMagicWord) { + if (AI_MDL_MAGIC_NUMBER_BE == iMagicWord || AI_MDL_MAGIC_NUMBER_LE == iMagicWord) { ASSIMP_LOG_DEBUG("MDL subtype: Quake 1, magic word is IDPO"); iGSFileVersion = 0; InternReadFile_Quake1(); } // GameStudio A MDL2 format - used by some test models that come with 3DGS - else if (AI_MDL_MAGIC_NUMBER_BE_GS3 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS3 == iMagicWord) { + else if (AI_MDL_MAGIC_NUMBER_BE_GS3 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS3 == iMagicWord) { ASSIMP_LOG_DEBUG("MDL subtype: 3D GameStudio A2, magic word is MDL2"); iGSFileVersion = 2; InternReadFile_Quake1(); } // GameStudio A4 MDL3 format - else if (AI_MDL_MAGIC_NUMBER_BE_GS4 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS4 == iMagicWord) { + else if (AI_MDL_MAGIC_NUMBER_BE_GS4 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS4 == iMagicWord) { ASSIMP_LOG_DEBUG("MDL subtype: 3D GameStudio A4, magic word is MDL3"); iGSFileVersion = 3; InternReadFile_3DGS_MDL345(); } // GameStudio A5+ MDL4 format - else if (AI_MDL_MAGIC_NUMBER_BE_GS5a == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS5a == iMagicWord) { + else if (AI_MDL_MAGIC_NUMBER_BE_GS5a == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS5a == iMagicWord) { ASSIMP_LOG_DEBUG("MDL subtype: 3D GameStudio A4, magic word is MDL4"); iGSFileVersion = 4; InternReadFile_3DGS_MDL345(); } // GameStudio A5+ MDL5 format - else if (AI_MDL_MAGIC_NUMBER_BE_GS5b == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS5b == iMagicWord) { + else if (AI_MDL_MAGIC_NUMBER_BE_GS5b == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS5b == iMagicWord) { ASSIMP_LOG_DEBUG("MDL subtype: 3D GameStudio A5, magic word is MDL5"); iGSFileVersion = 5; InternReadFile_3DGS_MDL345(); } // GameStudio A7 MDL7 format - else if (AI_MDL_MAGIC_NUMBER_BE_GS7 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS7 == iMagicWord) { + else if (AI_MDL_MAGIC_NUMBER_BE_GS7 == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_GS7 == iMagicWord) { ASSIMP_LOG_DEBUG("MDL subtype: 3D GameStudio A7, magic word is MDL7"); iGSFileVersion = 7; InternReadFile_3DGS_MDL7(); } // IDST/IDSQ Format (CS:S/HL^2, etc ...) else if (AI_MDL_MAGIC_NUMBER_BE_HL2a == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_HL2a == iMagicWord || - AI_MDL_MAGIC_NUMBER_BE_HL2b == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_HL2b == iMagicWord) - { + AI_MDL_MAGIC_NUMBER_BE_HL2b == iMagicWord || AI_MDL_MAGIC_NUMBER_LE_HL2b == iMagicWord) { iGSFileVersion = 0; HalfLife::HalfLifeMDLBaseHeader *pHeader = (HalfLife::HalfLifeMDLBaseHeader *)mBuffer; - if (pHeader->version == AI_MDL_HL1_VERSION) - { + if (pHeader->version == AI_MDL_HL1_VERSION) { ASSIMP_LOG_DEBUG("MDL subtype: Half-Life 1/Goldsrc Engine, magic word is IDST/IDSQ"); InternReadFile_HL1(pFile, iMagicWord); - } - else - { + } else { ASSIMP_LOG_DEBUG("MDL subtype: Source(tm) Engine, magic word is IDST/IDSQ"); InternReadFile_HL2(); } - } - else { + } else { // print the magic word to the log file - throw DeadlyImportError( "Unknown MDL subformat " + pFile + - ". Magic word (" + std::string((char*)&iMagicWord,4) + ") is not known"); + throw DeadlyImportError("Unknown MDL subformat " + pFile + + ". Magic word (" + std::string((char *)&iMagicWord, 4) + ") is not known"); } // Now rotate the whole scene 90 degrees around the x axis to convert to internal coordinate system - pScene->mRootNode->mTransformation = aiMatrix4x4(1.f,0.f,0.f,0.f, - 0.f,0.f,1.f,0.f,0.f,-1.f,0.f,0.f,0.f,0.f,0.f,1.f); + pScene->mRootNode->mTransformation = aiMatrix4x4(1.f, 0.f, 0.f, 0.f, + 0.f, 0.f, 1.f, 0.f, 0.f, -1.f, 0.f, 0.f, 0.f, 0.f, 0.f, 1.f); DeleteBufferAndCleanup(); - } catch(...) { + } catch (...) { DeleteBufferAndCleanup(); throw; } @@ -281,33 +268,34 @@ void MDLImporter::InternReadFile( const std::string& pFile, // ------------------------------------------------------------------------------------------------ // Check whether we're still inside the valid file range -void MDLImporter::SizeCheck(const void* szPos) -{ - if (!szPos || (const unsigned char*)szPos > this->mBuffer + this->iFileSize) - { +void MDLImporter::SizeCheck(const void *szPos) { + if (!szPos || (const unsigned char *)szPos > this->mBuffer + this->iFileSize) { throw DeadlyImportError("Invalid MDL file. The file is too small " - "or contains invalid data."); + "or contains invalid data."); } } // ------------------------------------------------------------------------------------------------ // Just for debugging purposes -void MDLImporter::SizeCheck(const void* szPos, const char* szFile, unsigned int iLine) -{ +void MDLImporter::SizeCheck(const void *szPos, const char *szFile, unsigned int iLine) { ai_assert(NULL != szFile); - if (!szPos || (const unsigned char*)szPos > mBuffer + iFileSize) - { + if (!szPos || (const unsigned char *)szPos > mBuffer + iFileSize) { // remove a directory if there is one - const char* szFilePtr = ::strrchr(szFile,'\\'); + const char *szFilePtr = ::strrchr(szFile, '\\'); if (!szFilePtr) { - if(!(szFilePtr = ::strrchr(szFile,'/'))) + szFilePtr = ::strrchr(szFile, '/'); + if (nullptr == szFilePtr) { szFilePtr = szFile; + } + } + if (szFilePtr) { + ++szFilePtr; } - if (szFilePtr)++szFilePtr; char szBuffer[1024]; - ::sprintf(szBuffer,"Invalid MDL file. The file is too small " - "or contains invalid data (File: %s Line: %u)",szFilePtr,iLine); + ::sprintf(szBuffer, "Invalid MDL file. The file is too small " + "or contains invalid data (File: %s Line: %u)", + szFilePtr, iLine); throw DeadlyImportError(szBuffer); } @@ -315,21 +303,19 @@ void MDLImporter::SizeCheck(const void* szPos, const char* szFile, unsigned int // ------------------------------------------------------------------------------------------------ // Validate a quake file header -void MDLImporter::ValidateHeader_Quake1(const MDL::Header* pcHeader) -{ +void MDLImporter::ValidateHeader_Quake1(const MDL::Header *pcHeader) { // some values may not be NULL if (!pcHeader->num_frames) - throw DeadlyImportError( "[Quake 1 MDL] There are no frames in the file"); + throw DeadlyImportError("[Quake 1 MDL] There are no frames in the file"); if (!pcHeader->num_verts) - throw DeadlyImportError( "[Quake 1 MDL] There are no vertices in the file"); + throw DeadlyImportError("[Quake 1 MDL] There are no vertices in the file"); if (!pcHeader->num_tris) - throw DeadlyImportError( "[Quake 1 MDL] There are no triangles in the file"); + throw DeadlyImportError("[Quake 1 MDL] There are no triangles in the file"); // check whether the maxima are exceeded ...however, this applies for Quake 1 MDLs only - if (!this->iGSFileVersion) - { + if (!this->iGSFileVersion) { if (pcHeader->num_verts > AI_MDL_MAX_VERTS) ASSIMP_LOG_WARN("Quake 1 MDL model has more than AI_MDL_MAX_VERTS vertices"); @@ -342,33 +328,31 @@ void MDLImporter::ValidateHeader_Quake1(const MDL::Header* pcHeader) // (this does not apply for 3DGS MDLs) if (!this->iGSFileVersion && pcHeader->version != AI_MDL_VERSION) ASSIMP_LOG_WARN("Quake 1 MDL model has an unknown version: AI_MDL_VERSION (=6) is " - "the expected file format version"); - if(pcHeader->num_skins && (!pcHeader->skinwidth || !pcHeader->skinheight)) + "the expected file format version"); + if (pcHeader->num_skins && (!pcHeader->skinwidth || !pcHeader->skinheight)) ASSIMP_LOG_WARN("Skin width or height are 0"); } } #ifdef AI_BUILD_BIG_ENDIAN // ------------------------------------------------------------------------------------------------ -void FlipQuakeHeader(BE_NCONST MDL::Header* pcHeader) -{ - AI_SWAP4( pcHeader->ident); - AI_SWAP4( pcHeader->version); - AI_SWAP4( pcHeader->boundingradius); - AI_SWAP4( pcHeader->flags); - AI_SWAP4( pcHeader->num_frames); - AI_SWAP4( pcHeader->num_skins); - AI_SWAP4( pcHeader->num_tris); - AI_SWAP4( pcHeader->num_verts); - for (unsigned int i = 0; i < 3;++i) - { - AI_SWAP4( pcHeader->scale[i]); - AI_SWAP4( pcHeader->translate[i]); +void FlipQuakeHeader(BE_NCONST MDL::Header *pcHeader) { + AI_SWAP4(pcHeader->ident); + AI_SWAP4(pcHeader->version); + AI_SWAP4(pcHeader->boundingradius); + AI_SWAP4(pcHeader->flags); + AI_SWAP4(pcHeader->num_frames); + AI_SWAP4(pcHeader->num_skins); + AI_SWAP4(pcHeader->num_tris); + AI_SWAP4(pcHeader->num_verts); + for (unsigned int i = 0; i < 3; ++i) { + AI_SWAP4(pcHeader->scale[i]); + AI_SWAP4(pcHeader->translate[i]); } - AI_SWAP4( pcHeader->size); - AI_SWAP4( pcHeader->skinheight); - AI_SWAP4( pcHeader->skinwidth); - AI_SWAP4( pcHeader->synctype); + AI_SWAP4(pcHeader->size); + AI_SWAP4(pcHeader->skinheight); + AI_SWAP4(pcHeader->skinwidth); + AI_SWAP4(pcHeader->synctype); } #endif @@ -377,7 +361,7 @@ void FlipQuakeHeader(BE_NCONST MDL::Header* pcHeader) void MDLImporter::InternReadFile_Quake1() { ai_assert(NULL != pScene); - BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header*)this->mBuffer; + BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header *)this->mBuffer; #ifdef AI_BUILD_BIG_ENDIAN FlipQuakeHeader(pcHeader); @@ -386,24 +370,24 @@ void MDLImporter::InternReadFile_Quake1() { ValidateHeader_Quake1(pcHeader); // current cursor position in the file - const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1); + const unsigned char *szCurrent = (const unsigned char *)(pcHeader + 1); // need to read all textures - for ( unsigned int i = 0; i < (unsigned int)pcHeader->num_skins; ++i) { + for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins; ++i) { union { - BE_NCONST MDL::Skin* pcSkin; - BE_NCONST MDL::GroupSkin* pcGroupSkin; + BE_NCONST MDL::Skin *pcSkin; + BE_NCONST MDL::GroupSkin *pcGroupSkin; }; if (szCurrent + sizeof(MDL::Skin) > this->mBuffer + this->iFileSize) { throw DeadlyImportError("[Quake 1 MDL] Unexpected EOF"); } - pcSkin = (BE_NCONST MDL::Skin*)szCurrent; + pcSkin = (BE_NCONST MDL::Skin *)szCurrent; - AI_SWAP4( pcSkin->group ); + AI_SWAP4(pcSkin->group); // Quake 1 group-skins if (1 == pcSkin->group) { - AI_SWAP4( pcGroupSkin->nb ); + AI_SWAP4(pcGroupSkin->nb); // need to skip multiple images const unsigned int iNumImages = (unsigned int)pcGroupSkin->nb; @@ -416,53 +400,51 @@ void MDLImporter::InternReadFile_Quake1() { } // go to the end of the skin section / the beginning of the next skin szCurrent += pcHeader->skinheight * pcHeader->skinwidth + - sizeof(float) * iNumImages; + sizeof(float) * iNumImages; } } else { szCurrent += sizeof(uint32_t); unsigned int iSkip = i ? UINT_MAX : 0; - CreateTexture_3DGS_MDL4(szCurrent,pcSkin->group,&iSkip); + CreateTexture_3DGS_MDL4(szCurrent, pcSkin->group, &iSkip); szCurrent += iSkip; } } // get a pointer to the texture coordinates - BE_NCONST MDL::TexCoord* pcTexCoords = (BE_NCONST MDL::TexCoord*)szCurrent; + BE_NCONST MDL::TexCoord *pcTexCoords = (BE_NCONST MDL::TexCoord *)szCurrent; szCurrent += sizeof(MDL::TexCoord) * pcHeader->num_verts; // get a pointer to the triangles - BE_NCONST MDL::Triangle* pcTriangles = (BE_NCONST MDL::Triangle*)szCurrent; + BE_NCONST MDL::Triangle *pcTriangles = (BE_NCONST MDL::Triangle *)szCurrent; szCurrent += sizeof(MDL::Triangle) * pcHeader->num_tris; VALIDATE_FILE_SIZE(szCurrent); // now get a pointer to the first frame in the file - BE_NCONST MDL::Frame* pcFrames = (BE_NCONST MDL::Frame*)szCurrent; - MDL::SimpleFrame* pcFirstFrame; + BE_NCONST MDL::Frame *pcFrames = (BE_NCONST MDL::Frame *)szCurrent; + MDL::SimpleFrame *pcFirstFrame; if (0 == pcFrames->type) { // get address of single frame - pcFirstFrame =( MDL::SimpleFrame*) &pcFrames->frame; + pcFirstFrame = (MDL::SimpleFrame *)&pcFrames->frame; } else { // get the first frame in the group - BE_NCONST MDL::GroupFrame* pcFrames2 = (BE_NCONST MDL::GroupFrame*) pcFrames; + BE_NCONST MDL::GroupFrame *pcFrames2 = (BE_NCONST MDL::GroupFrame *)pcFrames; pcFirstFrame = &(pcFrames2->frames[0]); } - BE_NCONST MDL::Vertex* pcVertices = (BE_NCONST MDL::Vertex*) ((pcFirstFrame->name) + sizeof(pcFirstFrame->name)); - VALIDATE_FILE_SIZE((const unsigned char*)(pcVertices + pcHeader->num_verts)); + BE_NCONST MDL::Vertex *pcVertices = (BE_NCONST MDL::Vertex *)((pcFirstFrame->name) + sizeof(pcFirstFrame->name)); + VALIDATE_FILE_SIZE((const unsigned char *)(pcVertices + pcHeader->num_verts)); #ifdef AI_BUILD_BIG_ENDIAN - for (int i = 0; inum_verts;++i) - { - AI_SWAP4( pcTexCoords[i].onseam ); - AI_SWAP4( pcTexCoords[i].s ); - AI_SWAP4( pcTexCoords[i].t ); + for (int i = 0; i < pcHeader->num_verts; ++i) { + AI_SWAP4(pcTexCoords[i].onseam); + AI_SWAP4(pcTexCoords[i].s); + AI_SWAP4(pcTexCoords[i].t); } - for (int i = 0; inum_tris;++i) - { - AI_SWAP4( pcTriangles[i].facesfront); - AI_SWAP4( pcTriangles[i].vertex[0]); - AI_SWAP4( pcTriangles[i].vertex[1]); - AI_SWAP4( pcTriangles[i].vertex[2]); + for (int i = 0; i < pcHeader->num_tris; ++i) { + AI_SWAP4(pcTriangles[i].facesfront); + AI_SWAP4(pcTriangles[i].vertex[0]); + AI_SWAP4(pcTriangles[i].vertex[1]); + AI_SWAP4(pcTriangles[i].vertex[2]); } #endif @@ -470,7 +452,7 @@ void MDLImporter::InternReadFile_Quake1() { SetupMaterialProperties_3DGS_MDL5_Quake1(); // allocate enough storage to hold all vertices and triangles - aiMesh* pcMesh = new aiMesh(); + aiMesh *pcMesh = new aiMesh(); pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; pcMesh->mNumVertices = pcHeader->num_tris * 3; @@ -487,30 +469,27 @@ void MDLImporter::InternReadFile_Quake1() { pScene->mRootNode->mMeshes = new unsigned int[1]; pScene->mRootNode->mMeshes[0] = 0; pScene->mNumMeshes = 1; - pScene->mMeshes = new aiMesh*[1]; + pScene->mMeshes = new aiMesh *[1]; pScene->mMeshes[0] = pcMesh; // now iterate through all triangles unsigned int iCurrent = 0; - for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i) - { + for (unsigned int i = 0; i < (unsigned int)pcHeader->num_tris; ++i) { pcMesh->mFaces[i].mIndices = new unsigned int[3]; pcMesh->mFaces[i].mNumIndices = 3; unsigned int iTemp = iCurrent; - for (unsigned int c = 0; c < 3;++c,++iCurrent) - { + for (unsigned int c = 0; c < 3; ++c, ++iCurrent) { pcMesh->mFaces[i].mIndices[c] = iCurrent; // read vertices unsigned int iIndex = pcTriangles->vertex[c]; - if (iIndex >= (unsigned int)pcHeader->num_verts) - { - iIndex = pcHeader->num_verts-1; + if (iIndex >= (unsigned int)pcHeader->num_verts) { + iIndex = pcHeader->num_verts - 1; ASSIMP_LOG_WARN("Index overflow in Q1-MDL vertex list."); } - aiVector3D& vec = pcMesh->mVertices[iCurrent]; + aiVector3D &vec = pcMesh->mVertices[iCurrent]; vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0]; vec.x += pcHeader->translate[0]; @@ -522,7 +501,7 @@ void MDLImporter::InternReadFile_Quake1() { vec.z += pcHeader->translate[2]; // read the normal vector from the precalculated normal table - MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]); + MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex, pcMesh->mNormals[iCurrent]); //pcMesh->mNormals[iCurrent].y *= -1.0f; // read texture coordinates @@ -530,18 +509,17 @@ void MDLImporter::InternReadFile_Quake1() { float t = (float)pcTexCoords[iIndex].t; // translate texture coordinates - if (0 == pcTriangles->facesfront && 0 != pcTexCoords[iIndex].onseam) { + if (0 == pcTriangles->facesfront && 0 != pcTexCoords[iIndex].onseam) { s += pcHeader->skinwidth * 0.5f; } // Scale s and t to range from 0.0 to 1.0 pcMesh->mTextureCoords[0][iCurrent].x = (s + 0.5f) / pcHeader->skinwidth; - pcMesh->mTextureCoords[0][iCurrent].y = 1.0f-(t + 0.5f) / pcHeader->skinheight; - + pcMesh->mTextureCoords[0][iCurrent].y = 1.0f - (t + 0.5f) / pcHeader->skinheight; } - pcMesh->mFaces[i].mIndices[0] = iTemp+2; - pcMesh->mFaces[i].mIndices[1] = iTemp+1; - pcMesh->mFaces[i].mIndices[2] = iTemp+0; + pcMesh->mFaces[i].mIndices[0] = iTemp + 2; + pcMesh->mFaces[i].mIndices[1] = iTemp + 1; + pcMesh->mFaces[i].mIndices[2] = iTemp + 0; pcTriangles++; } return; @@ -549,22 +527,21 @@ void MDLImporter::InternReadFile_Quake1() { // ------------------------------------------------------------------------------------------------ // Setup material properties for Quake and older GameStudio files -void MDLImporter::SetupMaterialProperties_3DGS_MDL5_Quake1( ) -{ - const MDL::Header* const pcHeader = (const MDL::Header*)this->mBuffer; +void MDLImporter::SetupMaterialProperties_3DGS_MDL5_Quake1() { + const MDL::Header *const pcHeader = (const MDL::Header *)this->mBuffer; // allocate ONE material - pScene->mMaterials = new aiMaterial*[1]; + pScene->mMaterials = new aiMaterial *[1]; pScene->mMaterials[0] = new aiMaterial(); pScene->mNumMaterials = 1; // setup the material's properties const int iMode = (int)aiShadingMode_Gouraud; - aiMaterial* const pcHelper = (aiMaterial*)pScene->mMaterials[0]; + aiMaterial *const pcHelper = (aiMaterial *)pScene->mMaterials[0]; pcHelper->AddProperty(&iMode, 1, AI_MATKEY_SHADING_MODEL); aiColor4D clr; - if (0 != pcHeader->num_skins && pScene->mNumTextures) { + if (0 != pcHeader->num_skins && pScene->mNumTextures) { // can we replace the texture with a single color? clr = this->ReplaceTextureWithColor(pScene->mTextures[0]); if (is_not_qnan(clr.r)) { @@ -573,89 +550,86 @@ void MDLImporter::SetupMaterialProperties_3DGS_MDL5_Quake1( ) pScene->mTextures = NULL; pScene->mNumTextures = 0; - } - else { + } else { clr.b = clr.a = clr.g = clr.r = 1.0f; aiString szString; - ::memcpy(szString.data,AI_MAKE_EMBEDDED_TEXNAME(0),3); + ::memcpy(szString.data, AI_MAKE_EMBEDDED_TEXNAME(0), 3); szString.length = 2; - pcHelper->AddProperty(&szString,AI_MATKEY_TEXTURE_DIFFUSE(0)); + pcHelper->AddProperty(&szString, AI_MATKEY_TEXTURE_DIFFUSE(0)); } } - pcHelper->AddProperty(&clr, 1,AI_MATKEY_COLOR_DIFFUSE); - pcHelper->AddProperty(&clr, 1,AI_MATKEY_COLOR_SPECULAR); + pcHelper->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE); + pcHelper->AddProperty(&clr, 1, AI_MATKEY_COLOR_SPECULAR); - clr.r *= 0.05f;clr.g *= 0.05f; - clr.b *= 0.05f;clr.a = 1.0f; - pcHelper->AddProperty(&clr, 1,AI_MATKEY_COLOR_AMBIENT); + clr.r *= 0.05f; + clr.g *= 0.05f; + clr.b *= 0.05f; + clr.a = 1.0f; + pcHelper->AddProperty(&clr, 1, AI_MATKEY_COLOR_AMBIENT); } // ------------------------------------------------------------------------------------------------ // Read a MDL 3,4,5 file -void MDLImporter::InternReadFile_3DGS_MDL345( ) -{ +void MDLImporter::InternReadFile_3DGS_MDL345() { ai_assert(NULL != pScene); // the header of MDL 3/4/5 is nearly identical to the original Quake1 header - BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header*)this->mBuffer; + BE_NCONST MDL::Header *pcHeader = (BE_NCONST MDL::Header *)this->mBuffer; #ifdef AI_BUILD_BIG_ENDIAN FlipQuakeHeader(pcHeader); #endif ValidateHeader_Quake1(pcHeader); // current cursor position in the file - const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1); - const unsigned char* szEnd = mBuffer + iFileSize; + const unsigned char *szCurrent = (const unsigned char *)(pcHeader + 1); + const unsigned char *szEnd = mBuffer + iFileSize; // need to read all textures - for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins;++i) { + for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins; ++i) { if (szCurrent >= szEnd) { - throw DeadlyImportError( "Texture data past end of file."); + throw DeadlyImportError("Texture data past end of file."); } - BE_NCONST MDL::Skin* pcSkin; - pcSkin = (BE_NCONST MDL::Skin*)szCurrent; - AI_SWAP4( pcSkin->group); + BE_NCONST MDL::Skin *pcSkin; + pcSkin = (BE_NCONST MDL::Skin *)szCurrent; + AI_SWAP4(pcSkin->group); // create one output image unsigned int iSkip = i ? UINT_MAX : 0; - if (5 <= iGSFileVersion) - { + if (5 <= iGSFileVersion) { // MDL5 format could contain MIPmaps - CreateTexture_3DGS_MDL5((unsigned char*)pcSkin + sizeof(uint32_t), - pcSkin->group,&iSkip); - } - else { - CreateTexture_3DGS_MDL4((unsigned char*)pcSkin + sizeof(uint32_t), - pcSkin->group,&iSkip); + CreateTexture_3DGS_MDL5((unsigned char *)pcSkin + sizeof(uint32_t), + pcSkin->group, &iSkip); + } else { + CreateTexture_3DGS_MDL4((unsigned char *)pcSkin + sizeof(uint32_t), + pcSkin->group, &iSkip); } // need to skip one image szCurrent += iSkip + sizeof(uint32_t); - } // get a pointer to the texture coordinates - BE_NCONST MDL::TexCoord_MDL3* pcTexCoords = (BE_NCONST MDL::TexCoord_MDL3*)szCurrent; + BE_NCONST MDL::TexCoord_MDL3 *pcTexCoords = (BE_NCONST MDL::TexCoord_MDL3 *)szCurrent; szCurrent += sizeof(MDL::TexCoord_MDL3) * pcHeader->synctype; // NOTE: for MDLn formats "synctype" corresponds to the number of UV coords // get a pointer to the triangles - BE_NCONST MDL::Triangle_MDL3* pcTriangles = (BE_NCONST MDL::Triangle_MDL3*)szCurrent; + BE_NCONST MDL::Triangle_MDL3 *pcTriangles = (BE_NCONST MDL::Triangle_MDL3 *)szCurrent; szCurrent += sizeof(MDL::Triangle_MDL3) * pcHeader->num_tris; #ifdef AI_BUILD_BIG_ENDIAN - for (int i = 0; isynctype;++i) { - AI_SWAP2( pcTexCoords[i].u ); - AI_SWAP2( pcTexCoords[i].v ); + for (int i = 0; i < pcHeader->synctype; ++i) { + AI_SWAP2(pcTexCoords[i].u); + AI_SWAP2(pcTexCoords[i].v); } - for (int i = 0; inum_tris;++i) { - AI_SWAP2( pcTriangles[i].index_xyz[0]); - AI_SWAP2( pcTriangles[i].index_xyz[1]); - AI_SWAP2( pcTriangles[i].index_xyz[2]); - AI_SWAP2( pcTriangles[i].index_uv[0]); - AI_SWAP2( pcTriangles[i].index_uv[1]); - AI_SWAP2( pcTriangles[i].index_uv[2]); + for (int i = 0; i < pcHeader->num_tris; ++i) { + AI_SWAP2(pcTriangles[i].index_xyz[0]); + AI_SWAP2(pcTriangles[i].index_xyz[1]); + AI_SWAP2(pcTriangles[i].index_xyz[2]); + AI_SWAP2(pcTriangles[i].index_uv[0]); + AI_SWAP2(pcTriangles[i].index_uv[1]); + AI_SWAP2(pcTriangles[i].index_uv[2]); } #endif @@ -666,7 +640,7 @@ void MDLImporter::InternReadFile_3DGS_MDL345( ) SetupMaterialProperties_3DGS_MDL5_Quake1(); // allocate enough storage to hold all vertices and triangles - aiMesh* pcMesh = new aiMesh(); + aiMesh *pcMesh = new aiMesh(); pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; pcMesh->mNumVertices = pcHeader->num_tris * 3; @@ -679,13 +653,13 @@ void MDLImporter::InternReadFile_3DGS_MDL345( ) pScene->mRootNode->mMeshes = new unsigned int[1]; pScene->mRootNode->mMeshes[0] = 0; pScene->mNumMeshes = 1; - pScene->mMeshes = new aiMesh*[1]; + pScene->mMeshes = new aiMesh *[1]; pScene->mMeshes[0] = pcMesh; // allocate output storage - pcMesh->mNumVertices = (unsigned int)pcHeader->num_tris*3; - pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices]; - pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices]; + pcMesh->mNumVertices = (unsigned int)pcHeader->num_tris * 3; + pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices]; + pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices]; if (pcHeader->synctype) { pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices]; @@ -693,35 +667,35 @@ void MDLImporter::InternReadFile_3DGS_MDL345( ) } // now get a pointer to the first frame in the file - BE_NCONST MDL::Frame* pcFrames = (BE_NCONST MDL::Frame*)szCurrent; + BE_NCONST MDL::Frame *pcFrames = (BE_NCONST MDL::Frame *)szCurrent; AI_SWAP4(pcFrames->type); // byte packed vertices // FIXME: these two snippets below are almost identical ... join them? ///////////////////////////////////////////////////////////////////////////////////// - if (0 == pcFrames->type || 3 >= this->iGSFileVersion) { + if (0 == pcFrames->type || 3 >= this->iGSFileVersion) { - const MDL::SimpleFrame* pcFirstFrame = (const MDL::SimpleFrame*)(szCurrent + sizeof(uint32_t)); - const MDL::Vertex* pcVertices = (const MDL::Vertex*) ((pcFirstFrame->name) + sizeof(pcFirstFrame->name)); + const MDL::SimpleFrame *pcFirstFrame = (const MDL::SimpleFrame *)(szCurrent + sizeof(uint32_t)); + const MDL::Vertex *pcVertices = (const MDL::Vertex *)((pcFirstFrame->name) + sizeof(pcFirstFrame->name)); VALIDATE_FILE_SIZE(pcVertices + pcHeader->num_verts); // now iterate through all triangles unsigned int iCurrent = 0; - for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i) { + for (unsigned int i = 0; i < (unsigned int)pcHeader->num_tris; ++i) { pcMesh->mFaces[i].mIndices = new unsigned int[3]; pcMesh->mFaces[i].mNumIndices = 3; unsigned int iTemp = iCurrent; - for (unsigned int c = 0; c < 3;++c,++iCurrent) { + for (unsigned int c = 0; c < 3; ++c, ++iCurrent) { // read vertices unsigned int iIndex = pcTriangles->index_xyz[c]; - if (iIndex >= (unsigned int)pcHeader->num_verts) { - iIndex = pcHeader->num_verts-1; + if (iIndex >= (unsigned int)pcHeader->num_verts) { + iIndex = pcHeader->num_verts - 1; ASSIMP_LOG_WARN("Index overflow in MDLn vertex list"); } - aiVector3D& vec = pcMesh->mVertices[iCurrent]; + aiVector3D &vec = pcMesh->mVertices[iCurrent]; vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0]; vec.x += pcHeader->translate[0]; @@ -733,50 +707,50 @@ void MDLImporter::InternReadFile_3DGS_MDL345( ) vec.z += pcHeader->translate[2]; // read the normal vector from the precalculated normal table - MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]); + MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex, pcMesh->mNormals[iCurrent]); // pcMesh->mNormals[iCurrent].y *= -1.0f; // read texture coordinates if (pcHeader->synctype) { ImportUVCoordinate_3DGS_MDL345(pcMesh->mTextureCoords[0][iCurrent], - pcTexCoords,pcTriangles->index_uv[c]); + pcTexCoords, pcTriangles->index_uv[c]); } } - pcMesh->mFaces[i].mIndices[0] = iTemp+2; - pcMesh->mFaces[i].mIndices[1] = iTemp+1; - pcMesh->mFaces[i].mIndices[2] = iTemp+0; + pcMesh->mFaces[i].mIndices[0] = iTemp + 2; + pcMesh->mFaces[i].mIndices[1] = iTemp + 1; + pcMesh->mFaces[i].mIndices[2] = iTemp + 0; pcTriangles++; } } // short packed vertices ///////////////////////////////////////////////////////////////////////////////////// - else { + else { // now get a pointer to the first frame in the file - const MDL::SimpleFrame_MDLn_SP* pcFirstFrame = (const MDL::SimpleFrame_MDLn_SP*) (szCurrent + sizeof(uint32_t)); + const MDL::SimpleFrame_MDLn_SP *pcFirstFrame = (const MDL::SimpleFrame_MDLn_SP *)(szCurrent + sizeof(uint32_t)); // get a pointer to the vertices - const MDL::Vertex_MDL4* pcVertices = (const MDL::Vertex_MDL4*) ((pcFirstFrame->name) + - sizeof(pcFirstFrame->name)); + const MDL::Vertex_MDL4 *pcVertices = (const MDL::Vertex_MDL4 *)((pcFirstFrame->name) + + sizeof(pcFirstFrame->name)); VALIDATE_FILE_SIZE(pcVertices + pcHeader->num_verts); // now iterate through all triangles unsigned int iCurrent = 0; - for (unsigned int i = 0; i < (unsigned int) pcHeader->num_tris;++i) { + for (unsigned int i = 0; i < (unsigned int)pcHeader->num_tris; ++i) { pcMesh->mFaces[i].mIndices = new unsigned int[3]; pcMesh->mFaces[i].mNumIndices = 3; unsigned int iTemp = iCurrent; - for (unsigned int c = 0; c < 3;++c,++iCurrent) { + for (unsigned int c = 0; c < 3; ++c, ++iCurrent) { // read vertices unsigned int iIndex = pcTriangles->index_xyz[c]; - if (iIndex >= (unsigned int)pcHeader->num_verts) { - iIndex = pcHeader->num_verts-1; + if (iIndex >= (unsigned int)pcHeader->num_verts) { + iIndex = pcHeader->num_verts - 1; ASSIMP_LOG_WARN("Index overflow in MDLn vertex list"); } - aiVector3D& vec = pcMesh->mVertices[iCurrent]; + aiVector3D &vec = pcMesh->mVertices[iCurrent]; vec.x = (float)pcVertices[iIndex].v[0] * pcHeader->scale[0]; vec.x += pcHeader->translate[0]; @@ -788,18 +762,18 @@ void MDLImporter::InternReadFile_3DGS_MDL345( ) vec.z += pcHeader->translate[2]; // read the normal vector from the precalculated normal table - MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex,pcMesh->mNormals[iCurrent]); + MD2::LookupNormalIndex(pcVertices[iIndex].normalIndex, pcMesh->mNormals[iCurrent]); // pcMesh->mNormals[iCurrent].y *= -1.0f; // read texture coordinates if (pcHeader->synctype) { ImportUVCoordinate_3DGS_MDL345(pcMesh->mTextureCoords[0][iCurrent], - pcTexCoords,pcTriangles->index_uv[c]); + pcTexCoords, pcTriangles->index_uv[c]); } } - pcMesh->mFaces[i].mIndices[0] = iTemp+2; - pcMesh->mFaces[i].mIndices[1] = iTemp+1; - pcMesh->mFaces[i].mIndices[2] = iTemp+0; + pcMesh->mFaces[i].mIndices[0] = iTemp + 2; + pcMesh->mFaces[i].mIndices[1] = iTemp + 1; + pcMesh->mFaces[i].mIndices[2] = iTemp + 0; pcTriangles++; } } @@ -814,16 +788,15 @@ void MDLImporter::InternReadFile_3DGS_MDL345( ) // ------------------------------------------------------------------------------------------------ // Get a single UV coordinate for Quake and older GameStudio files void MDLImporter::ImportUVCoordinate_3DGS_MDL345( - aiVector3D& vOut, - const MDL::TexCoord_MDL3* pcSrc, - unsigned int iIndex) -{ + aiVector3D &vOut, + const MDL::TexCoord_MDL3 *pcSrc, + unsigned int iIndex) { ai_assert(NULL != pcSrc); - const MDL::Header* const pcHeader = (const MDL::Header*)this->mBuffer; + const MDL::Header *const pcHeader = (const MDL::Header *)this->mBuffer; // validate UV indices - if (iIndex >= (unsigned int) pcHeader->synctype) { - iIndex = pcHeader->synctype-1; + if (iIndex >= (unsigned int)pcHeader->synctype) { + iIndex = pcHeader->synctype - 1; ASSIMP_LOG_WARN("Index overflow in MDLn UV coord list"); } @@ -831,9 +804,9 @@ void MDLImporter::ImportUVCoordinate_3DGS_MDL345( float t = (float)pcSrc[iIndex].v; // Scale s and t to range from 0.0 to 1.0 - if (0x5 != iGSFileVersion) { - s = (s + 0.5f) / pcHeader->skinwidth; - t = 1.0f-(t + 0.5f) / pcHeader->skinheight; + if (0x5 != iGSFileVersion) { + s = (s + 0.5f) / pcHeader->skinwidth; + t = 1.0f - (t + 0.5f) / pcHeader->skinheight; } vOut.x = s; @@ -843,43 +816,39 @@ void MDLImporter::ImportUVCoordinate_3DGS_MDL345( // ------------------------------------------------------------------------------------------------ // Compute UV coordinates for a MDL5 file -void MDLImporter::CalculateUVCoordinates_MDL5() -{ - const MDL::Header* const pcHeader = (const MDL::Header*)this->mBuffer; - if (pcHeader->num_skins && this->pScene->mNumTextures) { - const aiTexture* pcTex = this->pScene->mTextures[0]; +void MDLImporter::CalculateUVCoordinates_MDL5() { + const MDL::Header *const pcHeader = (const MDL::Header *)this->mBuffer; + if (pcHeader->num_skins && this->pScene->mNumTextures) { + const aiTexture *pcTex = this->pScene->mTextures[0]; // if the file is loaded in DDS format: get the size of the // texture from the header of the DDS file // skip three DWORDs and read first height, then the width unsigned int iWidth, iHeight; - if (!pcTex->mHeight) { - const uint32_t* piPtr = (uint32_t*)pcTex->pcData; + if (!pcTex->mHeight) { + const uint32_t *piPtr = (uint32_t *)pcTex->pcData; piPtr += 3; iHeight = (unsigned int)*piPtr++; - iWidth = (unsigned int)*piPtr; - if (!iHeight || !iWidth) - { + iWidth = (unsigned int)*piPtr; + if (!iHeight || !iWidth) { ASSIMP_LOG_WARN("Either the width or the height of the " - "embedded DDS texture is zero. Unable to compute final texture " - "coordinates. The texture coordinates remain in their original " - "0-x/0-y (x,y = texture size) range."); - iWidth = 1; + "embedded DDS texture is zero. Unable to compute final texture " + "coordinates. The texture coordinates remain in their original " + "0-x/0-y (x,y = texture size) range."); + iWidth = 1; iHeight = 1; } - } - else { - iWidth = pcTex->mWidth; + } else { + iWidth = pcTex->mWidth; iHeight = pcTex->mHeight; } - if (1 != iWidth || 1 != iHeight) { + if (1 != iWidth || 1 != iHeight) { const float fWidth = (float)iWidth; const float fHeight = (float)iHeight; - aiMesh* pcMesh = this->pScene->mMeshes[0]; - for (unsigned int i = 0; i < pcMesh->mNumVertices;++i) - { + aiMesh *pcMesh = this->pScene->mMeshes[0]; + for (unsigned int i = 0; i < pcMesh->mNumVertices; ++i) { pcMesh->mTextureCoords[0][i].x /= fWidth; pcMesh->mTextureCoords[0][i].y /= fHeight; pcMesh->mTextureCoords[0][i].y = 1.0f - pcMesh->mTextureCoords[0][i].y; // DX to OGL @@ -890,36 +859,34 @@ void MDLImporter::CalculateUVCoordinates_MDL5() // ------------------------------------------------------------------------------------------------ // Validate the header of a MDL7 file -void MDLImporter::ValidateHeader_3DGS_MDL7(const MDL::Header_MDL7* pcHeader) -{ +void MDLImporter::ValidateHeader_3DGS_MDL7(const MDL::Header_MDL7 *pcHeader) { ai_assert(NULL != pcHeader); // There are some fixed sizes ... - if (sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size) { + if (sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size) { throw DeadlyImportError( - "[3DGS MDL7] sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size"); + "[3DGS MDL7] sizeof(MDL::ColorValue_MDL7) != pcHeader->colorvalue_stc_size"); } if (sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size) { throw DeadlyImportError( - "[3DGS MDL7] sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size"); + "[3DGS MDL7] sizeof(MDL::TexCoord_MDL7) != pcHeader->skinpoint_stc_size"); } - if (sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size) { + if (sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size) { throw DeadlyImportError( - "sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size"); + "sizeof(MDL::Skin_MDL7) != pcHeader->skin_stc_size"); } // if there are no groups ... how should we load such a file? - if(!pcHeader->groups_num) { - throw DeadlyImportError( "[3DGS MDL7] No frames found"); + if (!pcHeader->groups_num) { + throw DeadlyImportError("[3DGS MDL7] No frames found"); } } // ------------------------------------------------------------------------------------------------ // resolve bone animation matrices -void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones) -{ - const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer; - const MDL::Bone_MDL7* pcBones = (const MDL::Bone_MDL7*)(pcHeader+1); +void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7 **apcOutBones) { + const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7 *)this->mBuffer; + const MDL::Bone_MDL7 *pcBones = (const MDL::Bone_MDL7 *)(pcHeader + 1); ai_assert(NULL != apcOutBones); // first find the bone that has NO parent, calculate the @@ -928,16 +895,16 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones) uint16_t iParent = 0xffff; uint32_t iIterations = 0; while (iIterations++ < pcHeader->bones_num) { - for (uint32_t iBone = 0; iBone < pcHeader->bones_num;++iBone) { - BE_NCONST MDL::Bone_MDL7* pcBone = _AI_MDL7_ACCESS_PTR(pcBones,iBone, - pcHeader->bone_stc_size,MDL::Bone_MDL7); + for (uint32_t iBone = 0; iBone < pcHeader->bones_num; ++iBone) { + BE_NCONST MDL::Bone_MDL7 *pcBone = _AI_MDL7_ACCESS_PTR(pcBones, iBone, + pcHeader->bone_stc_size, MDL::Bone_MDL7); AI_SWAP2(pcBone->parent_index); AI_SWAP4(pcBone->x); AI_SWAP4(pcBone->y); AI_SWAP4(pcBone->z); - if (iParent == pcBone->parent_index) { + if (iParent == pcBone->parent_index) { // MDL7 readme //////////////////////////////////////////////////////////////// /* @@ -958,12 +925,12 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones) */ ///////////////////////////////////////////////////////////////// - MDL::IntBone_MDL7* const pcOutBone = apcOutBones[iBone]; + MDL::IntBone_MDL7 *const pcOutBone = apcOutBones[iBone]; // store the parent index of the bone pcOutBone->iParent = pcBone->parent_index; - if (0xffff != iParent) { - const MDL::IntBone_MDL7* pcParentBone = apcOutBones[iParent]; + if (0xffff != iParent) { + const MDL::IntBone_MDL7 *pcParentBone = apcOutBones[iParent]; pcOutBone->mOffsetMatrix.a4 = -pcParentBone->vPosition.x; pcOutBone->mOffsetMatrix.b4 = -pcParentBone->vPosition.y; pcOutBone->mOffsetMatrix.c4 = -pcParentBone->vPosition.z; @@ -978,15 +945,14 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones) if (AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE == pcHeader->bone_stc_size) { // no real name for our poor bone is specified :-( pcOutBone->mName.length = ai_snprintf(pcOutBone->mName.data, MAXLEN, - "UnnamedBone_%i",iBone); - } - else { + "UnnamedBone_%i", iBone); + } else { // Make sure we won't run over the buffer's end if there is no // terminal 0 character (however the documentation says there // should be one) - uint32_t iMaxLen = pcHeader->bone_stc_size-16; - for (uint32_t qq = 0; qq < iMaxLen;++qq) { - if (!pcBone->name[qq]) { + uint32_t iMaxLen = pcHeader->bone_stc_size - 16; + for (uint32_t qq = 0; qq < iMaxLen; ++qq) { + if (!pcBone->name[qq]) { iMaxLen = qq; break; } @@ -994,7 +960,7 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones) // store the name of the bone pcOutBone->mName.length = (size_t)iMaxLen; - ::memcpy(pcOutBone->mName.data,pcBone->name,pcOutBone->mName.length); + ::memcpy(pcOutBone->mName.data, pcBone->name, pcOutBone->mName.length); pcOutBone->mName.data[pcOutBone->mName.length] = '\0'; } } @@ -1005,21 +971,19 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7** apcOutBones) // ------------------------------------------------------------------------------------------------ // read bones from a MDL7 file -MDL::IntBone_MDL7** MDLImporter::LoadBones_3DGS_MDL7() -{ - const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer; - if (pcHeader->bones_num) { +MDL::IntBone_MDL7 **MDLImporter::LoadBones_3DGS_MDL7() { + const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7 *)this->mBuffer; + if (pcHeader->bones_num) { // validate the size of the bone data structure in the file - if (AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_20_CHARS != pcHeader->bone_stc_size && - AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_32_CHARS != pcHeader->bone_stc_size && - AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE != pcHeader->bone_stc_size) - { + if (AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_20_CHARS != pcHeader->bone_stc_size && + AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_32_CHARS != pcHeader->bone_stc_size && + AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE != pcHeader->bone_stc_size) { ASSIMP_LOG_WARN("Unknown size of bone data structure"); return NULL; } - MDL::IntBone_MDL7** apcBonesOut = new MDL::IntBone_MDL7*[pcHeader->bones_num]; - for (uint32_t crank = 0; crank < pcHeader->bones_num;++crank) + MDL::IntBone_MDL7 **apcBonesOut = new MDL::IntBone_MDL7 *[pcHeader->bones_num]; + for (uint32_t crank = 0; crank < pcHeader->bones_num; ++crank) apcBonesOut[crank] = new MDL::IntBone_MDL7(); // and calculate absolute bone offset matrices ... @@ -1031,11 +995,10 @@ MDL::IntBone_MDL7** MDLImporter::LoadBones_3DGS_MDL7() // ------------------------------------------------------------------------------------------------ // read faces from a MDL7 file -void MDLImporter::ReadFaces_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInfo, - MDL::IntGroupData_MDL7& groupData) -{ - const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)this->mBuffer; - MDL::Triangle_MDL7* pcGroupTris = groupInfo.pcGroupTris; +void MDLImporter::ReadFaces_3DGS_MDL7(const MDL::IntGroupInfo_MDL7 &groupInfo, + MDL::IntGroupData_MDL7 &groupData) { + const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7 *)this->mBuffer; + MDL::Triangle_MDL7 *pcGroupTris = groupInfo.pcGroupTris; // iterate through all triangles and build valid display lists unsigned int iOutIndex = 0; @@ -1045,142 +1008,143 @@ void MDLImporter::ReadFaces_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInfo, AI_SWAP2(pcGroupTris->v_index[2]); // iterate through all indices of the current triangle - for (unsigned int c = 0; c < 3;++c,++iOutIndex) { + for (unsigned int c = 0; c < 3; ++c, ++iOutIndex) { // validate the vertex index unsigned int iIndex = pcGroupTris->v_index[c]; - if(iIndex > (unsigned int)groupInfo.pcGroup->numverts) { + if (iIndex > (unsigned int)groupInfo.pcGroup->numverts) { // (we might need to read this section a second time - to process frame vertices correctly) - pcGroupTris->v_index[c] = iIndex = groupInfo.pcGroup->numverts-1; + pcGroupTris->v_index[c] = (uint16_t) (iIndex = groupInfo.pcGroup->numverts - 1 ); ASSIMP_LOG_WARN("Index overflow in MDL7 vertex list"); } // write the output face index - groupData.pcFaces[iTriangle].mIndices[2-c] = iOutIndex; + groupData.pcFaces[iTriangle].mIndices[2 - c] = iOutIndex; - aiVector3D& vPosition = groupData.vPositions[ iOutIndex ]; - vPosition.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex, pcHeader->mainvertex_stc_size) .x; - vPosition.y = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .y; - vPosition.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .z; + aiVector3D &vPosition = groupData.vPositions[iOutIndex]; + vPosition.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts, iIndex, pcHeader->mainvertex_stc_size).x; + vPosition.y = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts, iIndex, pcHeader->mainvertex_stc_size).y; + vPosition.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts, iIndex, pcHeader->mainvertex_stc_size).z; // if we have bones, save the index if (!groupData.aiBones.empty()) { groupData.aiBones[iOutIndex] = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts, - iIndex,pcHeader->mainvertex_stc_size).vertindex; + iIndex, pcHeader->mainvertex_stc_size) + .vertindex; } // now read the normal vector if (AI_MDL7_FRAMEVERTEX030305_STCSIZE <= pcHeader->mainvertex_stc_size) { // read the full normal vector - aiVector3D& vNormal = groupData.vNormals[ iOutIndex ]; - vNormal.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[0]; + aiVector3D &vNormal = groupData.vNormals[iOutIndex]; + vNormal.x = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts, iIndex, pcHeader->mainvertex_stc_size).norm[0]; AI_SWAP4(vNormal.x); - vNormal.y = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[1]; + vNormal.y = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts, iIndex, pcHeader->mainvertex_stc_size).norm[1]; AI_SWAP4(vNormal.y); - vNormal.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex,pcHeader->mainvertex_stc_size) .norm[2]; + vNormal.z = _AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts, iIndex, pcHeader->mainvertex_stc_size).norm[2]; AI_SWAP4(vNormal.z); - } - else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size) { + } else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size) { // read the normal vector from Quake2's smart table - aiVector3D& vNormal = groupData.vNormals[ iOutIndex ]; - MD2::LookupNormalIndex(_AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts,iIndex, - pcHeader->mainvertex_stc_size) .norm162index,vNormal); + aiVector3D &vNormal = groupData.vNormals[iOutIndex]; + MD2::LookupNormalIndex(_AI_MDL7_ACCESS_VERT(groupInfo.pcGroupVerts, iIndex, + pcHeader->mainvertex_stc_size) + .norm162index, + vNormal); } // validate and process the first uv coordinate set - if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV) { + if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV) { - if (groupInfo.pcGroup->num_stpts) { + if (groupInfo.pcGroup->num_stpts) { AI_SWAP2(pcGroupTris->skinsets[0].st_index[0]); AI_SWAP2(pcGroupTris->skinsets[0].st_index[1]); AI_SWAP2(pcGroupTris->skinsets[0].st_index[2]); iIndex = pcGroupTris->skinsets[0].st_index[c]; - if(iIndex > (unsigned int)groupInfo.pcGroup->num_stpts) { - iIndex = groupInfo.pcGroup->num_stpts-1; + if (iIndex > (unsigned int)groupInfo.pcGroup->num_stpts) { + iIndex = groupInfo.pcGroup->num_stpts - 1; ASSIMP_LOG_WARN("Index overflow in MDL7 UV coordinate list (#1)"); } float u = groupInfo.pcGroupUVs[iIndex].u; - float v = 1.0f-groupInfo.pcGroupUVs[iIndex].v; // DX to OGL + float v = 1.0f - groupInfo.pcGroupUVs[iIndex].v; // DX to OGL groupData.vTextureCoords1[iOutIndex].x = u; groupData.vTextureCoords1[iOutIndex].y = v; } // assign the material index, but only if it is existing - if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV_WITH_MATINDEX){ + if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_ONE_UV_WITH_MATINDEX) { AI_SWAP4(pcGroupTris->skinsets[0].material); groupData.pcFaces[iTriangle].iMatIndex[0] = pcGroupTris->skinsets[0].material; } } // validate and process the second uv coordinate set - if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV) { + if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV) { - if (groupInfo.pcGroup->num_stpts) { + if (groupInfo.pcGroup->num_stpts) { AI_SWAP2(pcGroupTris->skinsets[1].st_index[0]); AI_SWAP2(pcGroupTris->skinsets[1].st_index[1]); AI_SWAP2(pcGroupTris->skinsets[1].st_index[2]); AI_SWAP4(pcGroupTris->skinsets[1].material); iIndex = pcGroupTris->skinsets[1].st_index[c]; - if(iIndex > (unsigned int)groupInfo.pcGroup->num_stpts) { - iIndex = groupInfo.pcGroup->num_stpts-1; + if (iIndex > (unsigned int)groupInfo.pcGroup->num_stpts) { + iIndex = groupInfo.pcGroup->num_stpts - 1; ASSIMP_LOG_WARN("Index overflow in MDL7 UV coordinate list (#2)"); } - float u = groupInfo.pcGroupUVs[ iIndex ].u; - float v = 1.0f-groupInfo.pcGroupUVs[ iIndex ].v; + float u = groupInfo.pcGroupUVs[iIndex].u; + float v = 1.0f - groupInfo.pcGroupUVs[iIndex].v; - groupData.vTextureCoords2[ iOutIndex ].x = u; - groupData.vTextureCoords2[ iOutIndex ].y = v; // DX to OGL + groupData.vTextureCoords2[iOutIndex].x = u; + groupData.vTextureCoords2[iOutIndex].y = v; // DX to OGL // check whether we do really need the second texture // coordinate set ... wastes memory and loading time - if (0 != iIndex && (u != groupData.vTextureCoords1[ iOutIndex ].x || - v != groupData.vTextureCoords1[ iOutIndex ].y ) ) + if (0 != iIndex && (u != groupData.vTextureCoords1[iOutIndex].x || + v != groupData.vTextureCoords1[iOutIndex].y)) groupData.bNeed2UV = true; // if the material differs, we need a second skin, too - if (pcGroupTris->skinsets[ 1 ].material != pcGroupTris->skinsets[ 0 ].material) + if (pcGroupTris->skinsets[1].material != pcGroupTris->skinsets[0].material) groupData.bNeed2UV = true; } // assign the material index - groupData.pcFaces[ iTriangle ].iMatIndex[ 1 ] = pcGroupTris->skinsets[ 1 ].material; + groupData.pcFaces[iTriangle].iMatIndex[1] = pcGroupTris->skinsets[1].material; } } // get the next triangle in the list - pcGroupTris = (MDL::Triangle_MDL7*)((const char*)pcGroupTris + pcHeader->triangle_stc_size); + pcGroupTris = (MDL::Triangle_MDL7 *)((const char *)pcGroupTris + pcHeader->triangle_stc_size); } } // ------------------------------------------------------------------------------------------------ // handle frames in a MDL7 file -bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInfo, - MDL::IntGroupData_MDL7& groupData, - MDL::IntSharedData_MDL7& shared, - const unsigned char* szCurrent, - const unsigned char** szCurrentOut) -{ - ai_assert( nullptr != szCurrent ); - ai_assert( nullptr != szCurrentOut); +bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7 &groupInfo, + MDL::IntGroupData_MDL7 &groupData, + MDL::IntSharedData_MDL7 &shared, + const unsigned char *szCurrent, + const unsigned char **szCurrentOut) { + ai_assert(nullptr != szCurrent); + ai_assert(nullptr != szCurrentOut); - const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7*)mBuffer; + const MDL::Header_MDL7 *pcHeader = (const MDL::Header_MDL7 *)mBuffer; // if we have no bones we can simply skip all frames, // otherwise we'll need to process them. // FIX: If we need another frame than the first we must apply frame vertex replacements ... - for(unsigned int iFrame = 0; iFrame < (unsigned int)groupInfo.pcGroup->numframes;++iFrame) { - MDL::IntFrameInfo_MDL7 frame ((BE_NCONST MDL::Frame_MDL7*)szCurrent,iFrame); + for (unsigned int iFrame = 0; iFrame < (unsigned int)groupInfo.pcGroup->numframes; ++iFrame) { + MDL::IntFrameInfo_MDL7 frame((BE_NCONST MDL::Frame_MDL7 *)szCurrent, iFrame); AI_SWAP4(frame.pcFrame->vertices_count); AI_SWAP4(frame.pcFrame->transmatrix_count); const unsigned int iAdd = pcHeader->frame_stc_size + - frame.pcFrame->vertices_count * pcHeader->framevertex_stc_size + - frame.pcFrame->transmatrix_count * pcHeader->bonetrans_stc_size; + frame.pcFrame->vertices_count * pcHeader->framevertex_stc_size + + frame.pcFrame->transmatrix_count * pcHeader->bonetrans_stc_size; - if (((const char*)szCurrent - (const char*)pcHeader) + iAdd > (unsigned int)pcHeader->data_size) { + if (((const char *)szCurrent - (const char *)pcHeader) + iAdd > (unsigned int)pcHeader->data_size) { ASSIMP_LOG_WARN("Index overflow in frame area. " - "Ignoring all frames and all further mesh groups, too."); + "Ignoring all frames and all further mesh groups, too."); // don't parse more groups if we can't even read one // FIXME: sometimes this seems to occur even for valid files ... @@ -1188,66 +1152,68 @@ bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInf return false; } // our output frame? - if (configFrameID == iFrame) { - BE_NCONST MDL::Vertex_MDL7* pcFrameVertices = (BE_NCONST MDL::Vertex_MDL7*)(szCurrent+pcHeader->frame_stc_size); + if (configFrameID == iFrame) { + BE_NCONST MDL::Vertex_MDL7 *pcFrameVertices = (BE_NCONST MDL::Vertex_MDL7 *)(szCurrent + pcHeader->frame_stc_size); - for (unsigned int qq = 0; qq < frame.pcFrame->vertices_count;++qq) { + for (unsigned int qq = 0; qq < frame.pcFrame->vertices_count; ++qq) { // I assume this are simple replacements for normal vertices, the bone index serving // as the index of the vertex to be replaced. - uint16_t iIndex = _AI_MDL7_ACCESS(pcFrameVertices,qq,pcHeader->framevertex_stc_size,MDL::Vertex_MDL7).vertindex; + uint16_t iIndex = _AI_MDL7_ACCESS(pcFrameVertices, qq, pcHeader->framevertex_stc_size, MDL::Vertex_MDL7).vertindex; AI_SWAP2(iIndex); - if (iIndex >= groupInfo.pcGroup->numverts) { + if (iIndex >= groupInfo.pcGroup->numverts) { ASSIMP_LOG_WARN("Invalid vertex index in frame vertex section"); continue; } - aiVector3D vPosition,vNormal; + aiVector3D vPosition, vNormal; - vPosition.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .x; + vPosition.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices, qq, pcHeader->framevertex_stc_size).x; AI_SWAP4(vPosition.x); - vPosition.y = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .y; + vPosition.y = _AI_MDL7_ACCESS_VERT(pcFrameVertices, qq, pcHeader->framevertex_stc_size).y; AI_SWAP4(vPosition.y); - vPosition.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .z; + vPosition.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices, qq, pcHeader->framevertex_stc_size).z; AI_SWAP4(vPosition.z); // now read the normal vector if (AI_MDL7_FRAMEVERTEX030305_STCSIZE <= pcHeader->mainvertex_stc_size) { // read the full normal vector - vNormal.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[0]; + vNormal.x = _AI_MDL7_ACCESS_VERT(pcFrameVertices, qq, pcHeader->framevertex_stc_size).norm[0]; AI_SWAP4(vNormal.x); - vNormal.y = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[1]; + vNormal.y = _AI_MDL7_ACCESS_VERT(pcFrameVertices, qq, pcHeader->framevertex_stc_size).norm[1]; AI_SWAP4(vNormal.y); - vNormal.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices,qq,pcHeader->framevertex_stc_size) .norm[2]; + vNormal.z = _AI_MDL7_ACCESS_VERT(pcFrameVertices, qq, pcHeader->framevertex_stc_size).norm[2]; AI_SWAP4(vNormal.z); - } - else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size) { + } else if (AI_MDL7_FRAMEVERTEX120503_STCSIZE <= pcHeader->mainvertex_stc_size) { // read the normal vector from Quake2's smart table - MD2::LookupNormalIndex(_AI_MDL7_ACCESS_VERT(pcFrameVertices,qq, - pcHeader->framevertex_stc_size) .norm162index,vNormal); + MD2::LookupNormalIndex(_AI_MDL7_ACCESS_VERT(pcFrameVertices, qq, + pcHeader->framevertex_stc_size) + .norm162index, + vNormal); } // FIXME: O(n^2) at the moment ... - BE_NCONST MDL::Triangle_MDL7* pcGroupTris = groupInfo.pcGroupTris; + BE_NCONST MDL::Triangle_MDL7 *pcGroupTris = groupInfo.pcGroupTris; unsigned int iOutIndex = 0; for (unsigned int iTriangle = 0; iTriangle < (unsigned int)groupInfo.pcGroup->numtris; ++iTriangle) { // iterate through all indices of the current triangle - for (unsigned int c = 0; c < 3;++c,++iOutIndex) { + for (unsigned int c = 0; c < 3; ++c, ++iOutIndex) { // replace the vertex with the new data const unsigned int iCurIndex = pcGroupTris->v_index[c]; - if (iCurIndex == iIndex) { + if (iCurIndex == iIndex) { groupData.vPositions[iOutIndex] = vPosition; groupData.vNormals[iOutIndex] = vNormal; } } // get the next triangle in the list - pcGroupTris = (BE_NCONST MDL::Triangle_MDL7*)((const char*) - pcGroupTris + pcHeader->triangle_stc_size); + pcGroupTris = (BE_NCONST MDL::Triangle_MDL7 *)((const char *) + pcGroupTris + + pcHeader->triangle_stc_size); } } } // parse bone trafo matrix keys (only if there are bones ...) if (shared.apcOutBones) { - ParseBoneTrafoKeys_3DGS_MDL7(groupInfo,frame,shared); + ParseBoneTrafoKeys_3DGS_MDL7(groupInfo, frame, shared); } szCurrent += iAdd; } @@ -1258,92 +1224,88 @@ bool MDLImporter::ProcessFrames_3DGS_MDL7(const MDL::IntGroupInfo_MDL7& groupInf // ------------------------------------------------------------------------------------------------ // Sort faces by material, handle multiple UVs correctly void MDLImporter::SortByMaterials_3DGS_MDL7( - const MDL::IntGroupInfo_MDL7& groupInfo, - MDL::IntGroupData_MDL7& groupData, - MDL::IntSplitGroupData_MDL7& splitGroupData) -{ + const MDL::IntGroupInfo_MDL7 &groupInfo, + MDL::IntGroupData_MDL7 &groupData, + MDL::IntSplitGroupData_MDL7 &splitGroupData) { const unsigned int iNumMaterials = (unsigned int)splitGroupData.shared.pcMats.size(); - if (!groupData.bNeed2UV) { + if (!groupData.bNeed2UV) { // if we don't need a second set of texture coordinates there is no reason to keep it in memory ... groupData.vTextureCoords2.clear(); // allocate the array - splitGroupData.aiSplit = new std::vector*[iNumMaterials]; + splitGroupData.aiSplit = new std::vector *[iNumMaterials]; - for (unsigned int m = 0; m < iNumMaterials;++m) + for (unsigned int m = 0; m < iNumMaterials; ++m) splitGroupData.aiSplit[m] = new std::vector(); // iterate through all faces and sort by material - for (unsigned int iFace = 0; iFace < (unsigned int)groupInfo.pcGroup->numtris;++iFace) { + for (unsigned int iFace = 0; iFace < (unsigned int)groupInfo.pcGroup->numtris; ++iFace) { // check range if (groupData.pcFaces[iFace].iMatIndex[0] >= iNumMaterials) { // use the last material instead - splitGroupData.aiSplit[iNumMaterials-1]->push_back(iFace); + splitGroupData.aiSplit[iNumMaterials - 1]->push_back(iFace); // sometimes MED writes -1, but normally only if there is only // one skin assigned. No warning in this case - if(0xFFFFFFFF != groupData.pcFaces[iFace].iMatIndex[0]) + if (0xFFFFFFFF != groupData.pcFaces[iFace].iMatIndex[0]) ASSIMP_LOG_WARN("Index overflow in MDL7 material list [#0]"); - } - else splitGroupData.aiSplit[groupData.pcFaces[iFace]. - iMatIndex[0]]->push_back(iFace); + } else + splitGroupData.aiSplit[groupData.pcFaces[iFace].iMatIndex[0]]->push_back(iFace); } - } - else - { + } else { // we need to build combined materials for each combination of std::vector avMats; - avMats.reserve(iNumMaterials*2); + avMats.reserve(iNumMaterials * 2); // fixme: why on the heap? - std::vector* > aiTempSplit(iNumMaterials*2); - for (unsigned int m = 0; m < iNumMaterials;++m) + std::vector *> aiTempSplit(iNumMaterials * 2); + for (unsigned int m = 0; m < iNumMaterials; ++m) aiTempSplit[m] = new std::vector(); // iterate through all faces and sort by material - for (unsigned int iFace = 0; iFace < (unsigned int)groupInfo.pcGroup->numtris;++iFace) { + for (unsigned int iFace = 0; iFace < (unsigned int)groupInfo.pcGroup->numtris; ++iFace) { // check range unsigned int iMatIndex = groupData.pcFaces[iFace].iMatIndex[0]; if (iMatIndex >= iNumMaterials) { // sometimes MED writes -1, but normally only if there is only // one skin assigned. No warning in this case - if(UINT_MAX != iMatIndex) + if (UINT_MAX != iMatIndex) ASSIMP_LOG_WARN("Index overflow in MDL7 material list [#1]"); - iMatIndex = iNumMaterials-1; + iMatIndex = iNumMaterials - 1; } unsigned int iMatIndex2 = groupData.pcFaces[iFace].iMatIndex[1]; unsigned int iNum = iMatIndex; - if (UINT_MAX != iMatIndex2 && iMatIndex != iMatIndex2) { - if (iMatIndex2 >= iNumMaterials) { + if (UINT_MAX != iMatIndex2 && iMatIndex != iMatIndex2) { + if (iMatIndex2 >= iNumMaterials) { // sometimes MED writes -1, but normally only if there is only // one skin assigned. No warning in this case ASSIMP_LOG_WARN("Index overflow in MDL7 material list [#2]"); - iMatIndex2 = iNumMaterials-1; + iMatIndex2 = iNumMaterials - 1; } // do a slow search in the list ... iNum = 0; bool bFound = false; - for (std::vector::iterator i = avMats.begin();i != avMats.end();++i,++iNum){ - if ((*i).iOldMatIndices[0] == iMatIndex && (*i).iOldMatIndices[1] == iMatIndex2) { + for (std::vector::iterator i = avMats.begin(); i != avMats.end(); ++i, ++iNum) { + if ((*i).iOldMatIndices[0] == iMatIndex && (*i).iOldMatIndices[1] == iMatIndex2) { // reuse this material bFound = true; break; } } - if (!bFound) { + if (!bFound) { // build a new material ... MDL::IntMaterial_MDL7 sHelper; sHelper.pcMat = new aiMaterial(); sHelper.iOldMatIndices[0] = iMatIndex; sHelper.iOldMatIndices[1] = iMatIndex2; JoinSkins_3DGS_MDL7(splitGroupData.shared.pcMats[iMatIndex], - splitGroupData.shared.pcMats[iMatIndex2],sHelper.pcMat); + splitGroupData.shared.pcMats[iMatIndex2], sHelper.pcMat); // and add it to the list avMats.push_back(sHelper); - iNum = (unsigned int)avMats.size()-1; + iNum = (unsigned int)avMats.size() - 1; } // adjust the size of the file array if (iNum == aiTempSplit.size()) { @@ -1354,36 +1316,34 @@ void MDLImporter::SortByMaterials_3DGS_MDL7( } // now add the newly created materials to the old list - if (0 == groupInfo.iIndex) { + if (0 == groupInfo.iIndex) { splitGroupData.shared.pcMats.resize(avMats.size()); - for (unsigned int o = 0; o < avMats.size();++o) + for (unsigned int o = 0; o < avMats.size(); ++o) splitGroupData.shared.pcMats[o] = avMats[o].pcMat; - } - else { + } else { // This might result in redundant materials ... splitGroupData.shared.pcMats.resize(iNumMaterials + avMats.size()); - for (unsigned int o = iNumMaterials; o < avMats.size();++o) + for (unsigned int o = iNumMaterials; o < avMats.size(); ++o) splitGroupData.shared.pcMats[o] = avMats[o].pcMat; } // and build the final face-to-material array - splitGroupData.aiSplit = new std::vector*[aiTempSplit.size()]; - for (unsigned int m = 0; m < iNumMaterials;++m) + splitGroupData.aiSplit = new std::vector *[aiTempSplit.size()]; + for (unsigned int m = 0; m < iNumMaterials; ++m) splitGroupData.aiSplit[m] = aiTempSplit[m]; } } // ------------------------------------------------------------------------------------------------ // Read a MDL7 file -void MDLImporter::InternReadFile_3DGS_MDL7( ) -{ +void MDLImporter::InternReadFile_3DGS_MDL7() { ai_assert(NULL != pScene); MDL::IntSharedData_MDL7 sharedData; // current cursor position in the file - BE_NCONST MDL::Header_MDL7 *pcHeader = (BE_NCONST MDL::Header_MDL7*)this->mBuffer; - const unsigned char* szCurrent = (const unsigned char*)(pcHeader+1); + BE_NCONST MDL::Header_MDL7 *pcHeader = (BE_NCONST MDL::Header_MDL7 *)this->mBuffer; + const unsigned char *szCurrent = (const unsigned char *)(pcHeader + 1); AI_SWAP4(pcHeader->version); AI_SWAP4(pcHeader->bones_num); @@ -1413,21 +1373,21 @@ void MDLImporter::InternReadFile_3DGS_MDL7( ) sharedData.apcOutBones = this->LoadBones_3DGS_MDL7(); // vector to held all created meshes - std::vector* avOutList; + std::vector *avOutList; // 3 meshes per group - that should be OK for most models - avOutList = new std::vector[pcHeader->groups_num]; - for (uint32_t i = 0; i < pcHeader->groups_num;++i) + avOutList = new std::vector[pcHeader->groups_num]; + for (uint32_t i = 0; i < pcHeader->groups_num; ++i) avOutList[i].reserve(3); // buffer to held the names of all groups in the file - const size_t buffersize(AI_MDL7_MAX_GROUPNAMESIZE*pcHeader->groups_num); - char* aszGroupNameBuffer = new char[ buffersize ]; + const size_t buffersize(AI_MDL7_MAX_GROUPNAMESIZE * pcHeader->groups_num); + char *aszGroupNameBuffer = new char[buffersize]; // read all groups for (unsigned int iGroup = 0; iGroup < (unsigned int)pcHeader->groups_num; ++iGroup) { - MDL::IntGroupInfo_MDL7 groupInfo((BE_NCONST MDL::Group_MDL7*)szCurrent,iGroup); - szCurrent = (const unsigned char*)(groupInfo.pcGroup+1); + MDL::IntGroupInfo_MDL7 groupInfo((BE_NCONST MDL::Group_MDL7 *)szCurrent, iGroup); + szCurrent = (const unsigned char *)(groupInfo.pcGroup + 1); VALIDATE_FILE_SIZE(szCurrent); @@ -1438,64 +1398,65 @@ void MDLImporter::InternReadFile_3DGS_MDL7( ) AI_SWAP4(groupInfo.pcGroup->numverts); AI_SWAP4(groupInfo.pcGroup->numframes); - if (1 != groupInfo.pcGroup->typ) { + if (1 != groupInfo.pcGroup->typ) { // Not a triangle-based mesh ASSIMP_LOG_WARN("[3DGS MDL7] Not a triangle mesh group. Continuing happily"); } // store the name of the group - const unsigned int ofs = iGroup*AI_MDL7_MAX_GROUPNAMESIZE; + const unsigned int ofs = iGroup * AI_MDL7_MAX_GROUPNAMESIZE; ::memcpy(&aszGroupNameBuffer[ofs], - groupInfo.pcGroup->name,AI_MDL7_MAX_GROUPNAMESIZE); + groupInfo.pcGroup->name, AI_MDL7_MAX_GROUPNAMESIZE); // make sure '\0' is at the end - aszGroupNameBuffer[ofs+AI_MDL7_MAX_GROUPNAMESIZE-1] = '\0'; + aszGroupNameBuffer[ofs + AI_MDL7_MAX_GROUPNAMESIZE - 1] = '\0'; // read all skins sharedData.pcMats.reserve(sharedData.pcMats.size() + groupInfo.pcGroup->numskins); sharedData.abNeedMaterials.resize(sharedData.abNeedMaterials.size() + - groupInfo.pcGroup->numskins,false); + groupInfo.pcGroup->numskins, + false); - for (unsigned int iSkin = 0; iSkin < (unsigned int)groupInfo.pcGroup->numskins;++iSkin) { - ParseSkinLump_3DGS_MDL7(szCurrent,&szCurrent,sharedData.pcMats); + for (unsigned int iSkin = 0; iSkin < (unsigned int)groupInfo.pcGroup->numskins; ++iSkin) { + ParseSkinLump_3DGS_MDL7(szCurrent, &szCurrent, sharedData.pcMats); } // if we have absolutely no skin loaded we need to generate a default material - if (sharedData.pcMats.empty()) { + if (sharedData.pcMats.empty()) { const int iMode = (int)aiShadingMode_Gouraud; sharedData.pcMats.push_back(new aiMaterial()); - aiMaterial* pcHelper = (aiMaterial*)sharedData.pcMats[0]; + aiMaterial *pcHelper = (aiMaterial *)sharedData.pcMats[0]; pcHelper->AddProperty(&iMode, 1, AI_MATKEY_SHADING_MODEL); aiColor3D clr; clr.b = clr.g = clr.r = 0.6f; - pcHelper->AddProperty(&clr, 1,AI_MATKEY_COLOR_DIFFUSE); - pcHelper->AddProperty(&clr, 1,AI_MATKEY_COLOR_SPECULAR); + pcHelper->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE); + pcHelper->AddProperty(&clr, 1, AI_MATKEY_COLOR_SPECULAR); clr.b = clr.g = clr.r = 0.05f; - pcHelper->AddProperty(&clr, 1,AI_MATKEY_COLOR_AMBIENT); + pcHelper->AddProperty(&clr, 1, AI_MATKEY_COLOR_AMBIENT); aiString szName; szName.Set(AI_DEFAULT_MATERIAL_NAME); - pcHelper->AddProperty(&szName,AI_MATKEY_NAME); + pcHelper->AddProperty(&szName, AI_MATKEY_NAME); - sharedData.abNeedMaterials.resize(1,false); + sharedData.abNeedMaterials.resize(1, false); } // now get a pointer to all texture coords in the group - groupInfo.pcGroupUVs = (BE_NCONST MDL::TexCoord_MDL7*)szCurrent; - for(int i = 0; i < groupInfo.pcGroup->num_stpts; ++i){ + groupInfo.pcGroupUVs = (BE_NCONST MDL::TexCoord_MDL7 *)szCurrent; + for (int i = 0; i < groupInfo.pcGroup->num_stpts; ++i) { AI_SWAP4(groupInfo.pcGroupUVs[i].u); AI_SWAP4(groupInfo.pcGroupUVs[i].v); } szCurrent += pcHeader->skinpoint_stc_size * groupInfo.pcGroup->num_stpts; // now get a pointer to all triangle in the group - groupInfo.pcGroupTris = (Triangle_MDL7*)szCurrent; + groupInfo.pcGroupTris = (Triangle_MDL7 *)szCurrent; szCurrent += pcHeader->triangle_stc_size * groupInfo.pcGroup->numtris; // now get a pointer to all vertices in the group - groupInfo.pcGroupVerts = (BE_NCONST MDL::Vertex_MDL7*)szCurrent; - for(int i = 0; i < groupInfo.pcGroup->numverts; ++i){ + groupInfo.pcGroupVerts = (BE_NCONST MDL::Vertex_MDL7 *)szCurrent; + for (int i = 0; i < groupInfo.pcGroup->numverts; ++i) { AI_SWAP4(groupInfo.pcGroupVerts[i].x); AI_SWAP4(groupInfo.pcGroupVerts[i].y); AI_SWAP4(groupInfo.pcGroupVerts[i].z); @@ -1506,25 +1467,24 @@ void MDLImporter::InternReadFile_3DGS_MDL7( ) szCurrent += pcHeader->mainvertex_stc_size * groupInfo.pcGroup->numverts; VALIDATE_FILE_SIZE(szCurrent); - MDL::IntSplitGroupData_MDL7 splitGroupData(sharedData,avOutList[iGroup]); + MDL::IntSplitGroupData_MDL7 splitGroupData(sharedData, avOutList[iGroup]); MDL::IntGroupData_MDL7 groupData; - if (groupInfo.pcGroup->numtris && groupInfo.pcGroup->numverts) - { + if (groupInfo.pcGroup->numtris && groupInfo.pcGroup->numverts) { // build output vectors - const unsigned int iNumVertices = groupInfo.pcGroup->numtris*3; + const unsigned int iNumVertices = groupInfo.pcGroup->numtris * 3; groupData.vPositions.resize(iNumVertices); groupData.vNormals.resize(iNumVertices); - if (sharedData.apcOutBones)groupData.aiBones.resize(iNumVertices,UINT_MAX); + if (sharedData.apcOutBones) groupData.aiBones.resize(iNumVertices, UINT_MAX); // it is also possible that there are 0 UV coordinate sets - if (groupInfo.pcGroup->num_stpts){ - groupData.vTextureCoords1.resize(iNumVertices,aiVector3D()); + if (groupInfo.pcGroup->num_stpts) { + groupData.vTextureCoords1.resize(iNumVertices, aiVector3D()); // check whether the triangle data structure is large enough // to contain a second UV coordinate set - if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV) { - groupData.vTextureCoords2.resize(iNumVertices,aiVector3D()); + if (pcHeader->triangle_stc_size >= AI_MDL7_TRIANGLE_STD_SIZE_TWO_UV) { + groupData.vTextureCoords2.resize(iNumVertices, aiVector3D()); groupData.bNeed2UV = true; } } @@ -1535,73 +1495,74 @@ void MDLImporter::InternReadFile_3DGS_MDL7( ) // sort by materials SortByMaterials_3DGS_MDL7(groupInfo, groupData, - splitGroupData); + splitGroupData); - for (unsigned int qq = 0; qq < sharedData.pcMats.size();++qq) { + for (unsigned int qq = 0; qq < sharedData.pcMats.size(); ++qq) { if (!splitGroupData.aiSplit[qq]->empty()) sharedData.abNeedMaterials[qq] = true; } - } - else ASSIMP_LOG_WARN("[3DGS MDL7] Mesh group consists of 0 " - "vertices or faces. It will be skipped."); + } else + ASSIMP_LOG_WARN("[3DGS MDL7] Mesh group consists of 0 " + "vertices or faces. It will be skipped."); // process all frames and generate output meshes - ProcessFrames_3DGS_MDL7(groupInfo,groupData, sharedData,szCurrent,&szCurrent); - GenerateOutputMeshes_3DGS_MDL7(groupData,splitGroupData); + ProcessFrames_3DGS_MDL7(groupInfo, groupData, sharedData, szCurrent, &szCurrent); + GenerateOutputMeshes_3DGS_MDL7(groupData, splitGroupData); } // generate a nodegraph and subnodes for each group pScene->mRootNode = new aiNode(); // now we need to build a final mesh list - for (uint32_t i = 0; i < pcHeader->groups_num;++i) + for (uint32_t i = 0; i < pcHeader->groups_num; ++i) pScene->mNumMeshes += (unsigned int)avOutList[i].size(); - pScene->mMeshes = new aiMesh*[pScene->mNumMeshes]; { - unsigned int p = 0,q = 0; - for (uint32_t i = 0; i < pcHeader->groups_num;++i) { - for (unsigned int a = 0; a < avOutList[i].size();++a) { + pScene->mMeshes = new aiMesh *[pScene->mNumMeshes]; + { + unsigned int p = 0, q = 0; + for (uint32_t i = 0; i < pcHeader->groups_num; ++i) { + for (unsigned int a = 0; a < avOutList[i].size(); ++a) { pScene->mMeshes[p++] = avOutList[i][a]; } - if (!avOutList[i].empty())++pScene->mRootNode->mNumChildren; + if (!avOutList[i].empty()) ++pScene->mRootNode->mNumChildren; } // we will later need an extra node to serve as parent for all bones - if (sharedData.apcOutBones)++pScene->mRootNode->mNumChildren; - this->pScene->mRootNode->mChildren = new aiNode*[pScene->mRootNode->mNumChildren]; + if (sharedData.apcOutBones) ++pScene->mRootNode->mNumChildren; + this->pScene->mRootNode->mChildren = new aiNode *[pScene->mRootNode->mNumChildren]; p = 0; - for (uint32_t i = 0; i < pcHeader->groups_num;++i) { - if (avOutList[i].empty())continue; + for (uint32_t i = 0; i < pcHeader->groups_num; ++i) { + if (avOutList[i].empty()) continue; - aiNode* const pcNode = pScene->mRootNode->mChildren[p] = new aiNode(); + aiNode *const pcNode = pScene->mRootNode->mChildren[p] = new aiNode(); pcNode->mNumMeshes = (unsigned int)avOutList[i].size(); pcNode->mMeshes = new unsigned int[pcNode->mNumMeshes]; pcNode->mParent = this->pScene->mRootNode; - for (unsigned int a = 0; a < pcNode->mNumMeshes;++a) + for (unsigned int a = 0; a < pcNode->mNumMeshes; ++a) pcNode->mMeshes[a] = q + a; q += (unsigned int)avOutList[i].size(); // setup the name of the node - char* const szBuffer = &aszGroupNameBuffer[i*AI_MDL7_MAX_GROUPNAMESIZE]; - if ('\0' == *szBuffer) { - const size_t maxSize(buffersize - (i*AI_MDL7_MAX_GROUPNAMESIZE)); - pcNode->mName.length = ai_snprintf(szBuffer, maxSize, "Group_%u", p); - } else { - pcNode->mName.length = (ai_uint32)::strlen(szBuffer); - } - ::strncpy(pcNode->mName.data,szBuffer,MAXLEN-1); + char *const szBuffer = &aszGroupNameBuffer[i * AI_MDL7_MAX_GROUPNAMESIZE]; + if ('\0' == *szBuffer) { + const size_t maxSize(buffersize - (i * AI_MDL7_MAX_GROUPNAMESIZE)); + pcNode->mName.length = ai_snprintf(szBuffer, maxSize, "Group_%u", p); + } else { + pcNode->mName.length = (ai_uint32)::strlen(szBuffer); + } + ::strncpy(pcNode->mName.data, szBuffer, MAXLEN - 1); ++p; } } // if there is only one root node with a single child we can optimize it a bit ... - if (1 == pScene->mRootNode->mNumChildren && !sharedData.apcOutBones) { - aiNode* pcOldRoot = this->pScene->mRootNode; + if (1 == pScene->mRootNode->mNumChildren && !sharedData.apcOutBones) { + aiNode *pcOldRoot = this->pScene->mRootNode; pScene->mRootNode = pcOldRoot->mChildren[0]; pcOldRoot->mChildren[0] = NULL; delete pcOldRoot; pScene->mRootNode->mParent = NULL; - } - else pScene->mRootNode->mName.Set(""); + } else + pScene->mRootNode->mName.Set(""); delete[] avOutList; delete[] aszGroupNameBuffer; @@ -1616,53 +1577,51 @@ void MDLImporter::InternReadFile_3DGS_MDL7( ) if (sharedData.apcOutBones) { // this step adds empty dummy bones to the nodegraph // insert another dummy node to avoid name conflicts - aiNode* const pc = pScene->mRootNode->mChildren[pScene->mRootNode->mNumChildren-1] = new aiNode(); + aiNode *const pc = pScene->mRootNode->mChildren[pScene->mRootNode->mNumChildren - 1] = new aiNode(); pc->mName.Set(""); // add bones to the nodegraph AddBonesToNodeGraph_3DGS_MDL7((const Assimp::MDL::IntBone_MDL7 **) - sharedData.apcOutBones,pc,0xffff); + sharedData.apcOutBones, + pc, 0xffff); // this steps build a valid output animation BuildOutputAnims_3DGS_MDL7((const Assimp::MDL::IntBone_MDL7 **) - sharedData.apcOutBones); + sharedData.apcOutBones); } } // ------------------------------------------------------------------------------------------------ // Copy materials -void MDLImporter::CopyMaterials_3DGS_MDL7(MDL::IntSharedData_MDL7 &shared) -{ +void MDLImporter::CopyMaterials_3DGS_MDL7(MDL::IntSharedData_MDL7 &shared) { pScene->mNumMaterials = (unsigned int)shared.pcMats.size(); - pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials]; - for (unsigned int i = 0; i < pScene->mNumMaterials;++i) + pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials]; + for (unsigned int i = 0; i < pScene->mNumMaterials; ++i) pScene->mMaterials[i] = shared.pcMats[i]; } - // ------------------------------------------------------------------------------------------------ // Process material references -void MDLImporter::HandleMaterialReferences_3DGS_MDL7() -{ +void MDLImporter::HandleMaterialReferences_3DGS_MDL7() { // search for referrer materials - for (unsigned int i = 0; i < pScene->mNumMaterials;++i) { + for (unsigned int i = 0; i < pScene->mNumMaterials; ++i) { int iIndex = 0; - if (AI_SUCCESS == aiGetMaterialInteger(pScene->mMaterials[i],AI_MDL7_REFERRER_MATERIAL, &iIndex) ) { - for (unsigned int a = 0; a < pScene->mNumMeshes;++a) { - aiMesh* const pcMesh = pScene->mMeshes[a]; + if (AI_SUCCESS == aiGetMaterialInteger(pScene->mMaterials[i], AI_MDL7_REFERRER_MATERIAL, &iIndex)) { + for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) { + aiMesh *const pcMesh = pScene->mMeshes[a]; if (i == pcMesh->mMaterialIndex) { pcMesh->mMaterialIndex = iIndex; } } // collapse the rest of the array delete pScene->mMaterials[i]; - for (unsigned int pp = i; pp < pScene->mNumMaterials-1;++pp) { + for (unsigned int pp = i; pp < pScene->mNumMaterials - 1; ++pp) { - pScene->mMaterials[pp] = pScene->mMaterials[pp+1]; - for (unsigned int a = 0; a < pScene->mNumMeshes;++a) { - aiMesh* const pcMesh = pScene->mMeshes[a]; - if (pcMesh->mMaterialIndex > i)--pcMesh->mMaterialIndex; + pScene->mMaterials[pp] = pScene->mMaterials[pp + 1]; + for (unsigned int a = 0; a < pScene->mNumMeshes; ++a) { + aiMesh *const pcMesh = pScene->mMeshes[a]; + if (pcMesh->mMaterialIndex > i) --pcMesh->mMaterialIndex; } } --pScene->mNumMaterials; @@ -1673,35 +1632,30 @@ void MDLImporter::HandleMaterialReferences_3DGS_MDL7() // ------------------------------------------------------------------------------------------------ // Read bone transformation keys void MDLImporter::ParseBoneTrafoKeys_3DGS_MDL7( - const MDL::IntGroupInfo_MDL7& groupInfo, - IntFrameInfo_MDL7& frame, - MDL::IntSharedData_MDL7& shared) -{ - const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer; + const MDL::IntGroupInfo_MDL7 &groupInfo, + IntFrameInfo_MDL7 &frame, + MDL::IntSharedData_MDL7 &shared) { + const MDL::Header_MDL7 *const pcHeader = (const MDL::Header_MDL7 *)this->mBuffer; // only the first group contains bone animation keys - if (frame.pcFrame->transmatrix_count) { - if (!groupInfo.iIndex) { + if (frame.pcFrame->transmatrix_count) { + if (!groupInfo.iIndex) { // skip all frames vertices. We can't support them - const MDL::BoneTransform_MDL7* pcBoneTransforms = (const MDL::BoneTransform_MDL7*) - (((const char*)frame.pcFrame) + pcHeader->frame_stc_size + - frame.pcFrame->vertices_count * pcHeader->framevertex_stc_size); + const MDL::BoneTransform_MDL7 *pcBoneTransforms = (const MDL::BoneTransform_MDL7 *)(((const char *)frame.pcFrame) + pcHeader->frame_stc_size + + frame.pcFrame->vertices_count * pcHeader->framevertex_stc_size); // read all transformation matrices - for (unsigned int iTrafo = 0; iTrafo < frame.pcFrame->transmatrix_count;++iTrafo) { - if(pcBoneTransforms->bone_index >= pcHeader->bones_num) { + for (unsigned int iTrafo = 0; iTrafo < frame.pcFrame->transmatrix_count; ++iTrafo) { + if (pcBoneTransforms->bone_index >= pcHeader->bones_num) { ASSIMP_LOG_WARN("Index overflow in frame area. " - "Unable to parse this bone transformation"); - } - else { + "Unable to parse this bone transformation"); + } else { AddAnimationBoneTrafoKey_3DGS_MDL7(frame.iIndex, - pcBoneTransforms,shared.apcOutBones); + pcBoneTransforms, shared.apcOutBones); } - pcBoneTransforms = (const MDL::BoneTransform_MDL7*)( - (const char*)pcBoneTransforms + pcHeader->bonetrans_stc_size); + pcBoneTransforms = (const MDL::BoneTransform_MDL7 *)((const char *)pcBoneTransforms + pcHeader->bonetrans_stc_size); } - } - else { + } else { ASSIMP_LOG_WARN("Ignoring animation keyframes in groups != 0"); } } @@ -1709,79 +1663,79 @@ void MDLImporter::ParseBoneTrafoKeys_3DGS_MDL7( // ------------------------------------------------------------------------------------------------ // Attach bones to the output nodegraph -void MDLImporter::AddBonesToNodeGraph_3DGS_MDL7(const MDL::IntBone_MDL7** apcBones, - aiNode* pcParent,uint16_t iParentIndex) -{ +void MDLImporter::AddBonesToNodeGraph_3DGS_MDL7(const MDL::IntBone_MDL7 **apcBones, + aiNode *pcParent, uint16_t iParentIndex) { ai_assert(NULL != apcBones && NULL != pcParent); // get a pointer to the header ... - const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer; + const MDL::Header_MDL7 *const pcHeader = (const MDL::Header_MDL7 *)this->mBuffer; - const MDL::IntBone_MDL7** apcBones2 = apcBones; - for (uint32_t i = 0; i < pcHeader->bones_num;++i) { + const MDL::IntBone_MDL7 **apcBones2 = apcBones; + for (uint32_t i = 0; i < pcHeader->bones_num; ++i) { - const MDL::IntBone_MDL7* const pcBone = *apcBones2++; + const MDL::IntBone_MDL7 *const pcBone = *apcBones2++; if (pcBone->iParent == iParentIndex) { ++pcParent->mNumChildren; } } - pcParent->mChildren = new aiNode*[pcParent->mNumChildren]; + pcParent->mChildren = new aiNode *[pcParent->mNumChildren]; unsigned int qq = 0; - for (uint32_t i = 0; i < pcHeader->bones_num;++i) { + for (uint32_t i = 0; i < pcHeader->bones_num; ++i) { - const MDL::IntBone_MDL7* const pcBone = *apcBones++; - if (pcBone->iParent != iParentIndex)continue; + const MDL::IntBone_MDL7 *const pcBone = *apcBones++; + if (pcBone->iParent != iParentIndex) continue; - aiNode* pcNode = pcParent->mChildren[qq++] = new aiNode(); - pcNode->mName = aiString( pcBone->mName ); + aiNode *pcNode = pcParent->mChildren[qq++] = new aiNode(); + pcNode->mName = aiString(pcBone->mName); - AddBonesToNodeGraph_3DGS_MDL7(apcBones,pcNode,(uint16_t)i); + AddBonesToNodeGraph_3DGS_MDL7(apcBones, pcNode, (uint16_t)i); } } // ------------------------------------------------------------------------------------------------ // Build output animations void MDLImporter::BuildOutputAnims_3DGS_MDL7( - const MDL::IntBone_MDL7** apcBonesOut) -{ + const MDL::IntBone_MDL7 **apcBonesOut) { ai_assert(NULL != apcBonesOut); - const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)mBuffer; + const MDL::Header_MDL7 *const pcHeader = (const MDL::Header_MDL7 *)mBuffer; // one animation ... - aiAnimation* pcAnim = new aiAnimation(); - for (uint32_t i = 0; i < pcHeader->bones_num;++i) { + aiAnimation *pcAnim = new aiAnimation(); + for (uint32_t i = 0; i < pcHeader->bones_num; ++i) { if (!apcBonesOut[i]->pkeyPositions.empty()) { // get the last frame ... (needn't be equal to pcHeader->frames_num) - for (size_t qq = 0; qq < apcBonesOut[i]->pkeyPositions.size();++qq) { + for (size_t qq = 0; qq < apcBonesOut[i]->pkeyPositions.size(); ++qq) { pcAnim->mDuration = std::max(pcAnim->mDuration, (double) - apcBonesOut[i]->pkeyPositions[qq].mTime); + apcBonesOut[i] + ->pkeyPositions[qq] + .mTime); } ++pcAnim->mNumChannels; } } - if (pcAnim->mDuration) { - pcAnim->mChannels = new aiNodeAnim*[pcAnim->mNumChannels]; + if (pcAnim->mDuration) { + pcAnim->mChannels = new aiNodeAnim *[pcAnim->mNumChannels]; unsigned int iCnt = 0; - for (uint32_t i = 0; i < pcHeader->bones_num;++i) { + for (uint32_t i = 0; i < pcHeader->bones_num; ++i) { if (!apcBonesOut[i]->pkeyPositions.empty()) { - const MDL::IntBone_MDL7* const intBone = apcBonesOut[i]; + const MDL::IntBone_MDL7 *const intBone = apcBonesOut[i]; - aiNodeAnim* const pcNodeAnim = pcAnim->mChannels[iCnt++] = new aiNodeAnim(); - pcNodeAnim->mNodeName = aiString( intBone->mName ); + aiNodeAnim *const pcNodeAnim = pcAnim->mChannels[iCnt++] = new aiNodeAnim(); + pcNodeAnim->mNodeName = aiString(intBone->mName); // allocate enough storage for all keys pcNodeAnim->mNumPositionKeys = (unsigned int)intBone->pkeyPositions.size(); - pcNodeAnim->mNumScalingKeys = (unsigned int)intBone->pkeyPositions.size(); + pcNodeAnim->mNumScalingKeys = (unsigned int)intBone->pkeyPositions.size(); pcNodeAnim->mNumRotationKeys = (unsigned int)intBone->pkeyPositions.size(); pcNodeAnim->mPositionKeys = new aiVectorKey[pcNodeAnim->mNumPositionKeys]; - pcNodeAnim->mScalingKeys = new aiVectorKey[pcNodeAnim->mNumPositionKeys]; + pcNodeAnim->mScalingKeys = new aiVectorKey[pcNodeAnim->mNumPositionKeys]; pcNodeAnim->mRotationKeys = new aiQuatKey[pcNodeAnim->mNumPositionKeys]; // copy all keys - for (unsigned int qq = 0; qq < pcNodeAnim->mNumPositionKeys;++qq) { + for (unsigned int qq = 0; qq < pcNodeAnim->mNumPositionKeys; ++qq) { pcNodeAnim->mPositionKeys[qq] = intBone->pkeyPositions[qq]; pcNodeAnim->mScalingKeys[qq] = intBone->pkeyScalings[qq]; pcNodeAnim->mRotationKeys[qq] = intBone->pkeyRotations[qq]; @@ -1791,17 +1745,16 @@ void MDLImporter::BuildOutputAnims_3DGS_MDL7( // store the output animation pScene->mNumAnimations = 1; - pScene->mAnimations = new aiAnimation*[1]; + pScene->mAnimations = new aiAnimation *[1]; pScene->mAnimations[0] = pcAnim; - } - else delete pcAnim; + } else + delete pcAnim; } // ------------------------------------------------------------------------------------------------ void MDLImporter::AddAnimationBoneTrafoKey_3DGS_MDL7(unsigned int iTrafo, - const MDL::BoneTransform_MDL7* pcBoneTransforms, - MDL::IntBone_MDL7** apcBonesOut) -{ + const MDL::BoneTransform_MDL7 *pcBoneTransforms, + MDL::IntBone_MDL7 **apcBonesOut) { ai_assert(NULL != pcBoneTransforms); ai_assert(NULL != apcBonesOut); @@ -1824,39 +1777,38 @@ void MDLImporter::AddAnimationBoneTrafoKey_3DGS_MDL7(unsigned int iTrafo, // now decompose the transformation matrix into separate // scaling, rotation and translation - aiVectorKey vScaling,vPosition; + aiVectorKey vScaling, vPosition; aiQuatKey qRotation; // FIXME: Decompose will assert in debug builds if the matrix is invalid ... - mTransform.Decompose(vScaling.mValue,qRotation.mValue,vPosition.mValue); + mTransform.Decompose(vScaling.mValue, qRotation.mValue, vPosition.mValue); // now generate keys vScaling.mTime = qRotation.mTime = vPosition.mTime = (double)iTrafo; // add the keys to the bone - MDL::IntBone_MDL7* const pcBoneOut = apcBonesOut[pcBoneTransforms->bone_index]; - pcBoneOut->pkeyPositions.push_back ( vPosition ); - pcBoneOut->pkeyScalings.push_back ( vScaling ); - pcBoneOut->pkeyRotations.push_back ( qRotation ); + MDL::IntBone_MDL7 *const pcBoneOut = apcBonesOut[pcBoneTransforms->bone_index]; + pcBoneOut->pkeyPositions.push_back(vPosition); + pcBoneOut->pkeyScalings.push_back(vScaling); + pcBoneOut->pkeyRotations.push_back(qRotation); } // ------------------------------------------------------------------------------------------------ // Construct output meshes void MDLImporter::GenerateOutputMeshes_3DGS_MDL7( - MDL::IntGroupData_MDL7& groupData, - MDL::IntSplitGroupData_MDL7& splitGroupData) -{ - const MDL::IntSharedData_MDL7& shared = splitGroupData.shared; + MDL::IntGroupData_MDL7 &groupData, + MDL::IntSplitGroupData_MDL7 &splitGroupData) { + const MDL::IntSharedData_MDL7 &shared = splitGroupData.shared; // get a pointer to the header ... - const MDL::Header_MDL7* const pcHeader = (const MDL::Header_MDL7*)this->mBuffer; + const MDL::Header_MDL7 *const pcHeader = (const MDL::Header_MDL7 *)this->mBuffer; const unsigned int iNumOutBones = pcHeader->bones_num; - for (std::vector::size_type i = 0; i < shared.pcMats.size();++i) { - if (!splitGroupData.aiSplit[i]->empty()) { + for (std::vector::size_type i = 0; i < shared.pcMats.size(); ++i) { + if (!splitGroupData.aiSplit[i]->empty()) { // allocate the output mesh - aiMesh* pcMesh = new aiMesh(); + aiMesh *pcMesh = new aiMesh(); pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE; pcMesh->mMaterialIndex = (unsigned int)i; @@ -1865,7 +1817,7 @@ void MDLImporter::GenerateOutputMeshes_3DGS_MDL7( pcMesh->mNumFaces = (unsigned int)splitGroupData.aiSplit[i]->size(); pcMesh->mFaces = new aiFace[pcMesh->mNumFaces]; - pcMesh->mNumVertices = pcMesh->mNumFaces*3; + pcMesh->mNumVertices = pcMesh->mNumFaces * 3; pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices]; pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices]; @@ -1880,15 +1832,15 @@ void MDLImporter::GenerateOutputMeshes_3DGS_MDL7( // iterate through all faces and build an unique set of vertices unsigned int iCurrent = 0; - for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace) { + for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces; ++iFace) { pcMesh->mFaces[iFace].mNumIndices = 3; pcMesh->mFaces[iFace].mIndices = new unsigned int[3]; unsigned int iSrcFace = splitGroupData.aiSplit[i]->operator[](iFace); - const MDL::IntFace_MDL7& oldFace = groupData.pcFaces[iSrcFace]; + const MDL::IntFace_MDL7 &oldFace = groupData.pcFaces[iSrcFace]; // iterate through all face indices - for (unsigned int c = 0; c < 3;++c) { + for (unsigned int c = 0; c < 3; ++c) { const uint32_t iIndex = oldFace.mIndices[c]; pcMesh->mVertices[iCurrent] = groupData.vPositions[iIndex]; pcMesh->mNormals[iCurrent] = groupData.vNormals[iIndex]; @@ -1907,51 +1859,50 @@ void MDLImporter::GenerateOutputMeshes_3DGS_MDL7( // if we have bones in the mesh we'll need to generate // proper vertex weights for them if (!groupData.aiBones.empty()) { - std::vector > aaiVWeightList; + std::vector> aaiVWeightList; aaiVWeightList.resize(iNumOutBones); - int iCurrent = 0; - for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace) { + int iCurrentWeight = 0; + for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces; ++iFace) { unsigned int iSrcFace = splitGroupData.aiSplit[i]->operator[](iFace); - const MDL::IntFace_MDL7& oldFace = groupData.pcFaces[iSrcFace]; + const MDL::IntFace_MDL7 &oldFace = groupData.pcFaces[iSrcFace]; // iterate through all face indices - for (unsigned int c = 0; c < 3;++c) { - unsigned int iBone = groupData.aiBones[ oldFace.mIndices[c] ]; - if (UINT_MAX != iBone) { - if (iBone >= iNumOutBones) { + for (unsigned int c = 0; c < 3; ++c) { + unsigned int iBone = groupData.aiBones[oldFace.mIndices[c]]; + if (UINT_MAX != iBone) { + if (iBone >= iNumOutBones) { ASSIMP_LOG_ERROR("Bone index overflow. " - "The bone index of a vertex exceeds the allowed range. "); - iBone = iNumOutBones-1; + "The bone index of a vertex exceeds the allowed range. "); + iBone = iNumOutBones - 1; } - aaiVWeightList[ iBone ].push_back ( iCurrent ); + aaiVWeightList[iBone].push_back(iCurrentWeight); } - ++iCurrent; + ++iCurrentWeight; } } // now check which bones are required ... - for (std::vector >::const_iterator k = aaiVWeightList.begin();k != aaiVWeightList.end();++k) { + for (std::vector>::const_iterator k = aaiVWeightList.begin(); k != aaiVWeightList.end(); ++k) { if (!(*k).empty()) { ++pcMesh->mNumBones; } } - pcMesh->mBones = new aiBone*[pcMesh->mNumBones]; + pcMesh->mBones = new aiBone *[pcMesh->mNumBones]; iCurrent = 0; - for (std::vector >::const_iterator k = aaiVWeightList.begin();k!= aaiVWeightList.end();++k,++iCurrent) - { + for (std::vector>::const_iterator k = aaiVWeightList.begin(); k != aaiVWeightList.end(); ++k, ++iCurrent) { if ((*k).empty()) continue; // seems we'll need this node - aiBone* pcBone = pcMesh->mBones[ iCurrent ] = new aiBone(); - pcBone->mName = aiString(shared.apcOutBones[ iCurrent ]->mName); - pcBone->mOffsetMatrix = shared.apcOutBones[ iCurrent ]->mOffsetMatrix; + aiBone *pcBone = pcMesh->mBones[iCurrent] = new aiBone(); + pcBone->mName = aiString(shared.apcOutBones[iCurrent]->mName); + pcBone->mOffsetMatrix = shared.apcOutBones[iCurrent]->mOffsetMatrix; // setup vertex weights pcBone->mNumWeights = (unsigned int)(*k).size(); pcBone->mWeights = new aiVertexWeight[pcBone->mNumWeights]; - for (unsigned int weight = 0; weight < pcBone->mNumWeights;++weight) { + for (unsigned int weight = 0; weight < pcBone->mNumWeights; ++weight) { pcBone->mWeights[weight].mVertexId = (*k)[weight]; pcBone->mWeights[weight].mWeight = 1.0f; } @@ -1966,50 +1917,47 @@ void MDLImporter::GenerateOutputMeshes_3DGS_MDL7( // ------------------------------------------------------------------------------------------------ // Join to materials void MDLImporter::JoinSkins_3DGS_MDL7( - aiMaterial* pcMat1, - aiMaterial* pcMat2, - aiMaterial* pcMatOut) -{ + aiMaterial *pcMat1, + aiMaterial *pcMat2, + aiMaterial *pcMatOut) { ai_assert(NULL != pcMat1 && NULL != pcMat2 && NULL != pcMatOut); // first create a full copy of the first skin property set // and assign it to the output material - aiMaterial::CopyPropertyList(pcMatOut,pcMat1); + aiMaterial::CopyPropertyList(pcMatOut, pcMat1); int iVal = 0; - pcMatOut->AddProperty(&iVal,1,AI_MATKEY_UVWSRC_DIFFUSE(0)); + pcMatOut->AddProperty(&iVal, 1, AI_MATKEY_UVWSRC_DIFFUSE(0)); // then extract the diffuse texture from the second skin, // setup 1 as UV source and we have it aiString sString; - if(AI_SUCCESS == aiGetMaterialString ( pcMat2, AI_MATKEY_TEXTURE_DIFFUSE(0),&sString )) { + if (AI_SUCCESS == aiGetMaterialString(pcMat2, AI_MATKEY_TEXTURE_DIFFUSE(0), &sString)) { iVal = 1; - pcMatOut->AddProperty(&iVal,1,AI_MATKEY_UVWSRC_DIFFUSE(1)); - pcMatOut->AddProperty(&sString,AI_MATKEY_TEXTURE_DIFFUSE(1)); + pcMatOut->AddProperty(&iVal, 1, AI_MATKEY_UVWSRC_DIFFUSE(1)); + pcMatOut->AddProperty(&sString, AI_MATKEY_TEXTURE_DIFFUSE(1)); } } // ------------------------------------------------------------------------------------------------ // Read a Half-life 1 MDL -void MDLImporter::InternReadFile_HL1(const std::string& pFile, const uint32_t iMagicWord) -{ +void MDLImporter::InternReadFile_HL1(const std::string &pFile, const uint32_t iMagicWord) { // We can't correctly load an MDL from a MDL "sequence" file. if (iMagicWord == AI_MDL_MAGIC_NUMBER_BE_HL2b || iMagicWord == AI_MDL_MAGIC_NUMBER_LE_HL2b) throw DeadlyImportError("Impossible to properly load a model from an MDL sequence file."); // Read the MDL file. HalfLife::HL1MDLLoader loader( - pScene, - pIOHandler, - mBuffer, - pFile, - mHL1ImportSettings); + pScene, + mIOHandler, + mBuffer, + pFile, + mHL1ImportSettings); } // ------------------------------------------------------------------------------------------------ // Read a half-life 2 MDL -void MDLImporter::InternReadFile_HL2( ) -{ +void MDLImporter::InternReadFile_HL2() { //const MDL::Header_HL2* pcHeader = (const MDL::Header_HL2*)this->mBuffer; throw DeadlyImportError("HL2 MDLs are not implemented"); } diff --git a/code/MDL/MDLLoader.h b/code/MDL/MDLLoader.h index 0bb78a2b1..635b84316 100644 --- a/code/MDL/MDLLoader.h +++ b/code/MDL/MDLLoader.h @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2020, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -58,7 +57,6 @@ struct aiTexture; namespace Assimp { - using namespace MDL; // -------------------------------------------------------------------------------------- @@ -436,7 +434,7 @@ protected: unsigned int iGSFileVersion; /** Output I/O handler. used to load external lmp files */ - IOSystem* pIOHandler; + IOSystem* mIOHandler; /** Output scene to be filled */ aiScene* pScene; diff --git a/code/Material/MaterialSystem.cpp b/code/Material/MaterialSystem.cpp index 63fad4268..0435f029e 100644 --- a/code/Material/MaterialSystem.cpp +++ b/code/Material/MaterialSystem.cpp @@ -561,7 +561,8 @@ uint32_t Assimp::ComputeMaterialHash(const aiMaterial* mat, bool includeMatName // Exclude all properties whose first character is '?' from the hash // See doc for aiMaterialProperty. - if ((prop = mat->mProperties[i]) && (includeMatName || prop->mKey.data[0] != '?')) { + prop = mat->mProperties[ i ]; + if ( nullptr != prop && (includeMatName || prop->mKey.data[0] != '?')) { hash = SuperFastHash(prop->mKey.data,(unsigned int)prop->mKey.length,hash); hash = SuperFastHash(prop->mData,prop->mDataLength,hash); diff --git a/code/PostProcessing/SplitLargeMeshes.cpp b/code/PostProcessing/SplitLargeMeshes.cpp index 70960f4a8..d74a335ad 100644 --- a/code/PostProcessing/SplitLargeMeshes.cpp +++ b/code/PostProcessing/SplitLargeMeshes.cpp @@ -575,8 +575,9 @@ void SplitLargeMeshesProcess_Vertex::SplitMesh( for (unsigned int k = 0; k < pMesh->mNumBones;++k) { // check whether the bone is existing BoneWeightList* pcWeightList; - if ((pcWeightList = (BoneWeightList*)pcMesh->mBones[k])) { - aiBone* pcOldBone = pMesh->mBones[k]; + pcWeightList = (BoneWeightList *)pcMesh->mBones[k]; + if (nullptr != pcWeightList) { + aiBone *pcOldBone = pMesh->mBones[k]; aiBone* pcOut( nullptr ); *ppCurrent++ = pcOut = new aiBone(); pcOut->mName = aiString(pcOldBone->mName); diff --git a/code/PostProcessing/TextureTransform.cpp b/code/PostProcessing/TextureTransform.cpp index cebbd8042..f979f0f4d 100644 --- a/code/PostProcessing/TextureTransform.cpp +++ b/code/PostProcessing/TextureTransform.cpp @@ -125,7 +125,8 @@ void TextureTransformStep::PreProcessUVTransform(STransformVecInfo& info) * type (e.g. if mirroring is active there IS a difference between * offset 2 and 3) */ - if ((rounded = (int)info.mTranslation.x)) { + rounded = (int)info.mTranslation.x; + if (rounded) { float out = 0.0f; szTemp[0] = 0; if (aiTextureMapMode_Wrap == info.mapU) { @@ -158,7 +159,8 @@ void TextureTransformStep::PreProcessUVTransform(STransformVecInfo& info) * type (e.g. if mirroring is active there IS a difference between * offset 2 and 3) */ - if ((rounded = (int)info.mTranslation.y)) { + rounded = (int)info.mTranslation.y; + if (rounded) { float out = 0.0f; szTemp[0] = 0; if (aiTextureMapMode_Wrap == info.mapV) {