diff --git a/code/AssetLib/IFC/IFCLoader.cpp b/code/AssetLib/IFC/IFCLoader.cpp index df1ca32de..bdac1801a 100644 --- a/code/AssetLib/IFC/IFCLoader.cpp +++ b/code/AssetLib/IFC/IFCLoader.cpp @@ -115,7 +115,7 @@ static const aiImporterDesc desc = { 0, 0, 0, - "ifc ifczip stp" + "ifc ifczip step stp" }; // ------------------------------------------------------------------------------------------------ diff --git a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp index 4df0d0d1d..eee9ed346 100644 --- a/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/AssetLib/MDL/HalfLife/HL1MDLLoader.cpp @@ -57,6 +57,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include +#include #ifdef MDL_HALFLIFE_LOG_WARN_HEADER #undef MDL_HALFLIFE_LOG_WARN_HEADER diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 83036e761..2783a8372 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -65,20 +65,6 @@ using namespace Assimp; // Constructor to be privately used by Importer BaseImporter::BaseImporter() AI_NO_EXCEPT : m_progress() { - /** - * Assimp Importer - * unit conversions available - * if you need another measurment unit add it below. - * it's currently defined in assimp that we prefer meters. - * - * NOTE: Initialised here rather than in the header file - * to workaround a VS2013 bug with brace initialisers - * */ - importerUnits[ImporterUnits::M] = 1.0; - importerUnits[ImporterUnits::CM] = 0.01; - importerUnits[ImporterUnits::MM] = 0.001; - importerUnits[ImporterUnits::INCHES] = 0.0254; - importerUnits[ImporterUnits::FEET] = 0.3048; } // ------------------------------------------------------------------------------------------------ diff --git a/code/PostProcessing/GenFaceNormalsProcess.cpp b/code/PostProcessing/GenFaceNormalsProcess.cpp index a73df2b5d..3e8612d29 100644 --- a/code/PostProcessing/GenFaceNormalsProcess.cpp +++ b/code/PostProcessing/GenFaceNormalsProcess.cpp @@ -70,6 +70,7 @@ GenFaceNormalsProcess::~GenFaceNormalsProcess() { // Returns whether the processing step is present in the given flag field. bool GenFaceNormalsProcess::IsActive(unsigned int pFlags) const { force_ = (pFlags & aiProcess_ForceGenNormals) != 0; + flippedWindingOrder_ = (pFlags & aiProcess_FlipWindingOrder) != 0; return (pFlags & aiProcess_GenNormals) != 0; } @@ -134,6 +135,8 @@ bool GenFaceNormalsProcess::GenMeshFaceNormals(aiMesh *pMesh) { const aiVector3D *pV1 = &pMesh->mVertices[face.mIndices[0]]; const aiVector3D *pV2 = &pMesh->mVertices[face.mIndices[1]]; const aiVector3D *pV3 = &pMesh->mVertices[face.mIndices[face.mNumIndices - 1]]; + if (flippedWindingOrder_) + std::swap( pV2, pV3 ); const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe(); for (unsigned int i = 0; i < face.mNumIndices; ++i) { diff --git a/code/PostProcessing/GenFaceNormalsProcess.h b/code/PostProcessing/GenFaceNormalsProcess.h index 4b9222af3..eefff6c73 100644 --- a/code/PostProcessing/GenFaceNormalsProcess.h +++ b/code/PostProcessing/GenFaceNormalsProcess.h @@ -80,6 +80,7 @@ public: private: bool GenMeshFaceNormals(aiMesh* pcMesh); mutable bool force_ = false; + mutable bool flippedWindingOrder_ = false; }; } // end of namespace Assimp diff --git a/code/PostProcessing/GenVertexNormalsProcess.cpp b/code/PostProcessing/GenVertexNormalsProcess.cpp index 5c9a6b754..e82bc3e6f 100644 --- a/code/PostProcessing/GenVertexNormalsProcess.cpp +++ b/code/PostProcessing/GenVertexNormalsProcess.cpp @@ -70,6 +70,7 @@ GenVertexNormalsProcess::~GenVertexNormalsProcess() { // Returns whether the processing step is present in the given flag field. bool GenVertexNormalsProcess::IsActive(unsigned int pFlags) const { force_ = (pFlags & aiProcess_ForceGenNormals) != 0; + flippedWindingOrder_ = (pFlags & aiProcess_FlipWindingOrder) != 0; return (pFlags & aiProcess_GenSmoothNormals) != 0; } @@ -142,6 +143,8 @@ bool GenVertexNormalsProcess::GenMeshVertexNormals(aiMesh *pMesh, unsigned int m const aiVector3D *pV1 = &pMesh->mVertices[face.mIndices[0]]; const aiVector3D *pV2 = &pMesh->mVertices[face.mIndices[1]]; const aiVector3D *pV3 = &pMesh->mVertices[face.mIndices[face.mNumIndices - 1]]; + if (flippedWindingOrder_) + std::swap( pV2, pV3 ); const aiVector3D vNor = ((*pV2 - *pV1) ^ (*pV3 - *pV1)).NormalizeSafe(); for (unsigned int i = 0; i < face.mNumIndices; ++i) { diff --git a/code/PostProcessing/GenVertexNormalsProcess.h b/code/PostProcessing/GenVertexNormalsProcess.h index 8b98ea8e6..8fc301ab7 100644 --- a/code/PostProcessing/GenVertexNormalsProcess.h +++ b/code/PostProcessing/GenVertexNormalsProcess.h @@ -104,6 +104,7 @@ private: /** Configuration option: maximum smoothing angle, in radians*/ ai_real configMaxAngle; mutable bool force_ = false; + mutable bool flippedWindingOrder_ = false; }; } // end of namespace Assimp diff --git a/code/PostProcessing/PretransformVertices.cpp b/code/PostProcessing/PretransformVertices.cpp index d1740f30b..2691ed488 100644 --- a/code/PostProcessing/PretransformVertices.cpp +++ b/code/PostProcessing/PretransformVertices.cpp @@ -429,7 +429,7 @@ void PretransformVertices::Execute(aiScene *pScene) { const unsigned int iOldNodes = CountNodes(pScene->mRootNode); if (configTransform) { - pScene->mRootNode->mTransformation = configTransformation; + pScene->mRootNode->mTransformation = configTransformation * pScene->mRootNode->mTransformation; } // first compute absolute transformation matrices for all nodes diff --git a/include/assimp/BaseImporter.h b/include/assimp/BaseImporter.h index 86d7ba70f..38bec1afd 100644 --- a/include/assimp/BaseImporter.h +++ b/include/assimp/BaseImporter.h @@ -51,10 +51,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "Exceptional.h" -#include #include #include -#include #include #include #include @@ -179,42 +177,10 @@ public: /** * Will be called only by scale process when scaling is requested. */ - virtual void SetFileScale(double scale) { + void SetFileScale(double scale) { fileScale = scale; } - virtual double GetFileScale() const { - return fileScale; - } - - enum ImporterUnits { - M, - MM, - CM, - INCHES, - FEET - }; - - /** - * Assimp Importer - * unit conversions available - * NOTE: Valid options are initialised in the - * constructor in the implementation file to - * work around a VS2013 compiler bug if support - * for that compiler is dropped in the future - * initialisation can be moved back here - * */ - std::map importerUnits; - - virtual void SetApplicationUnits(const ImporterUnits &unit) { - importerScale = importerUnits[unit]; - applicationUnits = unit; - } - - virtual const ImporterUnits &GetApplicationUnits() { - return applicationUnits; - } - // ------------------------------------------------------------------- /** Called by #Importer::GetExtensionList for each loaded importer. * Take the extension list contained in the structure returned by @@ -223,7 +189,6 @@ public: void GetExtensionList(std::set &extensions); protected: - ImporterUnits applicationUnits = ImporterUnits::M; double importerScale = 1.0; double fileScale = 1.0; @@ -420,7 +385,7 @@ public: // static utilities private: /* Pushes state into importer for the importer scale */ - virtual void UpdateImporterScale(Importer *pImp); + void UpdateImporterScale(Importer *pImp); protected: /// Error description in case there was one. diff --git a/include/assimp/XmlParser.h b/include/assimp/XmlParser.h index f525d3549..91fb9907f 100644 --- a/include/assimp/XmlParser.h +++ b/include/assimp/XmlParser.h @@ -43,8 +43,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define INCLUDED_AI_IRRXML_WRAPPER #include +#include + #include "BaseImporter.h" #include "IOStream.hpp" + #include #include diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp index 733d3d620..92760d691 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.cpp @@ -42,22 +42,12 @@ void ModelLoader::Draw(ID3D11DeviceContext * devcon) { } } -std::string textype; - Mesh ModelLoader::processMesh(aiMesh * mesh, const aiScene * scene) { // Data to fill std::vector vertices; std::vector indices; std::vector textures; - if (mesh->mMaterialIndex >= 0) { - aiMaterial* mat = scene->mMaterials[mesh->mMaterialIndex]; - - if (textype.empty()) { - textype = determineTextureType(scene, mat); - } - } - // Walk through each of the mesh's vertices for (UINT i = 0; i < mesh->mNumVertices; i++) { VERTEX vertex; @@ -108,9 +98,10 @@ std::vector ModelLoader::loadMaterialTextures(aiMaterial * mat, aiTextu if (!skip) { // If texture hasn't been loaded already, load it HRESULT hr; Texture texture; - if (textype == "embedded compressed texture") { - int textureindex = getTextureIndex(&str); - texture.texture = getTextureFromModel(scene, textureindex); + + const aiTexture* embeddedTexture = scene->GetEmbeddedTexture(str.C_Str()); + if (embeddedTexture != nullptr) { + texture.texture = loadEmbeddedTexture(embeddedTexture); } else { std::string filename = std::string(str.C_Str()); filename = directory_ + '/' + filename; @@ -148,38 +139,46 @@ void ModelLoader::processNode(aiNode * node, const aiScene * scene) { } } -std::string ModelLoader::determineTextureType(const aiScene * scene, aiMaterial * mat) { - aiString textypeStr; - mat->GetTexture(aiTextureType_DIFFUSE, 0, &textypeStr); - std::string textypeteststr = textypeStr.C_Str(); - if (textypeteststr == "*0" || textypeteststr == "*1" || textypeteststr == "*2" || textypeteststr == "*3" || textypeteststr == "*4" || textypeteststr == "*5") { - if (scene->mTextures[0]->mHeight == 0) { - return "embedded compressed texture"; - } else { - return "embedded non-compressed texture"; - } - } - if (textypeteststr.find('.') != std::string::npos) { - return "textures are on disk"; - } - - return "."; -} - -int ModelLoader::getTextureIndex(aiString * str) { - std::string tistr; - tistr = str->C_Str(); - tistr = tistr.substr(1); - return stoi(tistr); -} - -ID3D11ShaderResourceView * ModelLoader::getTextureFromModel(const aiScene * scene, int textureindex) { +ID3D11ShaderResourceView * ModelLoader::loadEmbeddedTexture(const aiTexture* embeddedTexture) { HRESULT hr; - ID3D11ShaderResourceView *texture; + ID3D11ShaderResourceView *texture = nullptr; - int* size = reinterpret_cast(&scene->mTextures[textureindex]->mWidth); + if (embeddedTexture->mHeight != 0) { + // Load an uncompressed ARGB8888 embedded texture + D3D11_TEXTURE2D_DESC desc; + desc.Width = embeddedTexture->mWidth; + desc.Height = embeddedTexture->mHeight; + desc.MipLevels = 1; + desc.ArraySize = 1; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.Usage = D3D11_USAGE_DEFAULT; + desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = 0; + desc.MiscFlags = 0; - hr = CreateWICTextureFromMemory(dev_, devcon_, reinterpret_cast(scene->mTextures[textureindex]->pcData), *size, nullptr, &texture); + D3D11_SUBRESOURCE_DATA subresourceData; + subresourceData.pSysMem = embeddedTexture->pcData; + subresourceData.SysMemPitch = embeddedTexture->mWidth * 4; + subresourceData.SysMemSlicePitch = embeddedTexture->mWidth * embeddedTexture->mHeight * 4; + + ID3D11Texture2D *texture2D = nullptr; + hr = dev_->CreateTexture2D(&desc, &subresourceData, &texture2D); + if (FAILED(hr)) + MessageBox(hwnd_, "CreateTexture2D failed!", "Error!", MB_ICONERROR | MB_OK); + + hr = dev_->CreateShaderResourceView(texture2D, nullptr, &texture); + if (FAILED(hr)) + MessageBox(hwnd_, "CreateShaderResourceView failed!", "Error!", MB_ICONERROR | MB_OK); + + return texture; + } + + // mHeight is 0, so try to load a compressed texture of mWidth bytes + const size_t size = embeddedTexture->mWidth; + + hr = CreateWICTextureFromMemory(dev_, devcon_, reinterpret_cast(embeddedTexture->pcData), size, nullptr, &texture); if (FAILED(hr)) MessageBox(hwnd_, "Texture couldn't be created from memory!", "Error!", MB_ICONERROR | MB_OK); diff --git a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h index 9d3ed50b3..a04484f08 100644 --- a/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h +++ b/samples/SimpleTexturedDirectx11/SimpleTexturedDirectx11/ModelLoader.h @@ -35,9 +35,7 @@ private: void processNode(aiNode* node, const aiScene* scene); Mesh processMesh(aiMesh* mesh, const aiScene* scene); std::vector loadMaterialTextures(aiMaterial* mat, aiTextureType type, std::string typeName, const aiScene* scene); - std::string determineTextureType(const aiScene* scene, aiMaterial* mat); - int getTextureIndex(aiString* str); - ID3D11ShaderResourceView* getTextureFromModel(const aiScene* scene, int textureindex); + ID3D11ShaderResourceView* loadEmbeddedTexture(const aiTexture* embeddedTexture); }; #endif // !MODEL_LOADER_H