From e761f13c8042f6a840b8e29e77698046fc0b9a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=B6ller?= Date: Thu, 24 May 2018 12:07:05 +0200 Subject: [PATCH 01/11] does not access undefined memory area anymore. This will fix some Debuggers, which throw an exception, when accessing out-of-bound memory --- code/STLLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/STLLoader.cpp b/code/STLLoader.cpp index 73a780e34..b0ace74b6 100644 --- a/code/STLLoader.cpp +++ b/code/STLLoader.cpp @@ -365,10 +365,10 @@ void STLImporter::LoadASCIIFile( aiNode *root ) { pMesh->mNumFaces = static_cast(positionBuffer.size() / 3); pMesh->mNumVertices = static_cast(positionBuffer.size()); pMesh->mVertices = new aiVector3D[pMesh->mNumVertices]; - memcpy(pMesh->mVertices, &positionBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D)); + memcpy(pMesh->mVertices, positionBuffer.data(), pMesh->mNumVertices * sizeof(aiVector3D)); positionBuffer.clear(); pMesh->mNormals = new aiVector3D[pMesh->mNumVertices]; - memcpy(pMesh->mNormals, &normalBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D)); + memcpy(pMesh->mNormals, normalBuffer.data(), pMesh->mNumVertices * sizeof(aiVector3D)); normalBuffer.clear(); // now copy faces From 97cecc858a8d2dbedcd1f3517b8dc02f616d5143 Mon Sep 17 00:00:00 2001 From: gstanlo Date: Thu, 24 May 2018 17:25:26 -0700 Subject: [PATCH 02/11] Properly reads in glTF/2.0 sampler address modes. Assimp was returning glTF/2.0 values as address modes instead of aiTextureMapModes. Also modified text glTF/2.0 model's sampler uv address modes to mirror/clamp respectively, and tests for them in the unit test. --- code/glTF2Importer.cpp | 21 +++++++++++++++++-- .../glTF2/BoxTextured-glTF/BoxTextured.gltf | 4 ++-- test/unit/utglTF2ImportExport.cpp | 17 ++++++++++++++- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/code/glTF2Importer.cpp b/code/glTF2Importer.cpp index f478ca487..15c338716 100644 --- a/code/glTF2Importer.cpp +++ b/code/glTF2Importer.cpp @@ -121,6 +121,21 @@ bool glTF2Importer::CanRead(const std::string& pFile, IOSystem* pIOHandler, bool return false; } +static aiTextureMapMode ConvertWrappingMode(SamplerWrap gltfWrapMode) +{ + switch (gltfWrapMode) { + case SamplerWrap::Mirrored_Repeat: + return aiTextureMapMode_Mirror; + + case SamplerWrap::Clamp_To_Edge: + return aiTextureMapMode_Clamp; + + case SamplerWrap::UNSET: + case SamplerWrap::Repeat: + default: + return aiTextureMapMode_Wrap; + } +} //static void CopyValue(const glTF2::vec3& v, aiColor3D& out) //{ @@ -198,8 +213,10 @@ inline void SetMaterialTextureProperty(std::vector& embeddedTexIdxs, Asset& mat->AddProperty(&name, AI_MATKEY_GLTF_MAPPINGNAME(texType, texSlot)); mat->AddProperty(&id, AI_MATKEY_GLTF_MAPPINGID(texType, texSlot)); - mat->AddProperty(&sampler->wrapS, 1, AI_MATKEY_MAPPINGMODE_U(texType, texSlot)); - mat->AddProperty(&sampler->wrapT, 1, AI_MATKEY_MAPPINGMODE_V(texType, texSlot)); + aiTextureMapMode wrapS = ConvertWrappingMode(sampler->wrapS); + aiTextureMapMode wrapT = ConvertWrappingMode(sampler->wrapT); + mat->AddProperty(&wrapS, 1, AI_MATKEY_MAPPINGMODE_U(texType, texSlot)); + mat->AddProperty(&wrapT, 1, AI_MATKEY_MAPPINGMODE_V(texType, texSlot)); if (sampler->magFilter != SamplerMagFilter::UNSET) { mat->AddProperty(&sampler->magFilter, 1, AI_MATKEY_GLTF_MAPPINGFILTER_MAG(texType, texSlot)); diff --git a/test/models/glTF2/BoxTextured-glTF/BoxTextured.gltf b/test/models/glTF2/BoxTextured-glTF/BoxTextured.gltf index eff658f02..88d65391e 100644 --- a/test/models/glTF2/BoxTextured-glTF/BoxTextured.gltf +++ b/test/models/glTF2/BoxTextured-glTF/BoxTextured.gltf @@ -146,8 +146,8 @@ { "magFilter": 9729, "minFilter": 9986, - "wrapS": 10497, - "wrapT": 10497 + "wrapS": 33648, + "wrapT": 33071 } ], "bufferViews": [ diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index 58ebe3017..5117a56fc 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -46,6 +46,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include using namespace Assimp; @@ -54,7 +55,21 @@ public: virtual bool importerTest() { Assimp::Importer importer; const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/glTF2/BoxTextured-glTF/BoxTextured.gltf", aiProcess_ValidateDataStructure); - return nullptr != scene; + EXPECT_NE( scene, nullptr ); + if ( !scene ) return false; + + EXPECT_TRUE( scene->HasMaterials() ); + if ( !scene->HasMaterials() ) return false; + const aiMaterial *material = scene->mMaterials[0]; + + aiString path; + aiTextureMapMode modes[2]; + EXPECT_EQ( aiReturn_SUCCESS, material->GetTexture(aiTextureType_DIFFUSE, 0, &path, nullptr, nullptr, nullptr, nullptr, modes) ); + EXPECT_STREQ( path.C_Str(), "CesiumLogoFlat.png" ); + EXPECT_EQ( modes[0], aiTextureMapMode_Mirror ); + EXPECT_EQ( modes[1], aiTextureMapMode_Clamp ); + + return true; } virtual bool binaryImporterTest() { From b6888962edd5510c71bef6bebccfe96ce435b0ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verin=20Lemaignan?= Date: Mon, 28 May 2018 23:53:28 +0100 Subject: [PATCH 03/11] [pyassimp] Updated setup.py --- port/PyAssimp/README.md | 4 ++-- port/PyAssimp/setup.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/port/PyAssimp/README.md b/port/PyAssimp/README.md index 37ecdb65d..056794fa8 100644 --- a/port/PyAssimp/README.md +++ b/port/PyAssimp/README.md @@ -1,5 +1,5 @@ -PyAssimp Readme -=============== +PyAssimp: Python bindings for libassimp +======================================= A simple Python wrapper for Assimp using `ctypes` to access the library. Requires Python >= 2.6. diff --git a/port/PyAssimp/setup.py b/port/PyAssimp/setup.py index 4ccfaf116..8157bf0ef 100644 --- a/port/PyAssimp/setup.py +++ b/port/PyAssimp/setup.py @@ -1,12 +1,22 @@ + #!/usr/bin/env python # -*- coding: utf-8 -*- import os from distutils.core import setup +def readme(): + with open('README.md') as f: + return f.read() + setup(name='pyassimp', - version='4.1.0', + version='4.1.2', license='ISC', description='Python bindings for the Open Asset Import Library (ASSIMP)', + long_description=readme(), url='https://github.com/assimp/assimp', + author='ASSIMP developers', + author_email='assimp-discussions@lists.sourceforge.net', + maintainer='Séverin Lemaignan', + maintainer_email='severin@guakamole.org', packages=['pyassimp'], data_files=[ ('share/pyassimp', ['README.md']), From c12c56d33ee5ff9734f45acf9c884a593d3bb1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9verin=20Lemaignan?= Date: Tue, 29 May 2018 10:47:40 +0100 Subject: [PATCH 04/11] [pyassimp] README.{md->rst} to please distutils. Bumped to 4.1.3 --- port/PyAssimp/README.md | 94 --------------------------------------- port/PyAssimp/README.rst | 96 ++++++++++++++++++++++++++++++++++++++++ port/PyAssimp/setup.py | 6 +-- 3 files changed, 99 insertions(+), 97 deletions(-) delete mode 100644 port/PyAssimp/README.md create mode 100644 port/PyAssimp/README.rst diff --git a/port/PyAssimp/README.md b/port/PyAssimp/README.md deleted file mode 100644 index 056794fa8..000000000 --- a/port/PyAssimp/README.md +++ /dev/null @@ -1,94 +0,0 @@ -PyAssimp: Python bindings for libassimp -======================================= - -A simple Python wrapper for Assimp using `ctypes` to access the library. -Requires Python >= 2.6. - -Python 3 support is mostly here, but not well tested. - -Note that pyassimp is not complete. Many ASSIMP features are missing. - -USAGE ------ - -### Complete example: 3D viewer - -`pyassimp` comes with a simple 3D viewer that shows how to load and display a 3D -model using a shader-based OpenGL pipeline. - -![Screenshot](3d_viewer_screenshot.png) - -To use it, from within `/port/PyAssimp`: - -``` -$ cd scripts -$ python ./3D-viewer -``` - -You can use this code as starting point in your applications. - -### Writing your own code - -To get started with `pyassimp`, examine the simpler `sample.py` script in `scripts/`, -which illustrates the basic usage. All Assimp data structures are wrapped using -`ctypes`. All the data+length fields in Assimp's data structures (such as -`aiMesh::mNumVertices`, `aiMesh::mVertices`) are replaced by simple python -lists, so you can call `len()` on them to get their respective size and access -members using `[]`. - -For example, to load a file named `hello.3ds` and print the first -vertex of the first mesh, you would do (proper error handling -substituted by assertions ...): - -```python - -from pyassimp import * -scene = load('hello.3ds') - -assert len(scene.meshes) -mesh = scene.meshes[0] - -assert len(mesh.vertices) -print(mesh.vertices[0]) - -# don't forget this one, or you will leak! -release(scene) - -``` - -Another example to list the 'top nodes' in a -scene: - -```python - -from pyassimp import * -scene = load('hello.3ds') - -for c in scene.rootnode.children: - print(str(c)) - -release(scene) - -``` - -INSTALL -------- - -Install `pyassimp` by running: - -``` -$ python setup.py install -``` - -PyAssimp requires a assimp dynamic library (`DLL` on windows, -`.so` on linux, `.dynlib` on macOS) in order to work. The default search directories -are: - -- the current directory -- on linux additionally: `/usr/lib`, `/usr/local/lib`, - `/usr/lib/x86_64-linux-gnu` - -To build that library, refer to the Assimp master `INSTALL` -instructions. To look in more places, edit `./pyassimp/helper.py`. -There's an `additional_dirs` list waiting for your entries. - diff --git a/port/PyAssimp/README.rst b/port/PyAssimp/README.rst new file mode 100644 index 000000000..f909e2cd0 --- /dev/null +++ b/port/PyAssimp/README.rst @@ -0,0 +1,96 @@ +PyAssimp: Python bindings for libassimp +======================================= + +A simple Python wrapper for Assimp using ``ctypes`` to access the +library. Requires Python >= 2.6. + +Python 3 support is mostly here, but not well tested. + +Note that pyassimp is not complete. Many ASSIMP features are missing. + +USAGE +----- + +Complete example: 3D viewer +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``pyassimp`` comes with a simple 3D viewer that shows how to load and +display a 3D model using a shader-based OpenGL pipeline. + +.. figure:: 3d_viewer_screenshot.png + :alt: Screenshot + + Screenshot + +To use it, from within ``/port/PyAssimp``: + +:: + + $ cd scripts + $ python ./3D-viewer + +You can use this code as starting point in your applications. + +Writing your own code +~~~~~~~~~~~~~~~~~~~~~ + +To get started with ``pyassimp``, examine the simpler ``sample.py`` +script in ``scripts/``, which illustrates the basic usage. All Assimp +data structures are wrapped using ``ctypes``. All the data+length fields +in Assimp's data structures (such as ``aiMesh::mNumVertices``, +``aiMesh::mVertices``) are replaced by simple python lists, so you can +call ``len()`` on them to get their respective size and access members +using ``[]``. + +For example, to load a file named ``hello.3ds`` and print the first +vertex of the first mesh, you would do (proper error handling +substituted by assertions ...): + +.. code:: python + + + from pyassimp import * + scene = load('hello.3ds') + + assert len(scene.meshes) + mesh = scene.meshes[0] + + assert len(mesh.vertices) + print(mesh.vertices[0]) + + # don't forget this one, or you will leak! + release(scene) + +Another example to list the 'top nodes' in a scene: + +.. code:: python + + + from pyassimp import * + scene = load('hello.3ds') + + for c in scene.rootnode.children: + print(str(c)) + + release(scene) + +INSTALL +------- + +Install ``pyassimp`` by running: + +:: + + $ python setup.py install + +PyAssimp requires a assimp dynamic library (``DLL`` on windows, ``.so`` +on linux, ``.dynlib`` on macOS) in order to work. The default search +directories are: + +- the current directory +- on linux additionally: ``/usr/lib``, ``/usr/local/lib``, + ``/usr/lib/x86_64-linux-gnu`` + +To build that library, refer to the Assimp master ``INSTALL`` +instructions. To look in more places, edit ``./pyassimp/helper.py``. +There's an ``additional_dirs`` list waiting for your entries. diff --git a/port/PyAssimp/setup.py b/port/PyAssimp/setup.py index 8157bf0ef..e19e497f0 100644 --- a/port/PyAssimp/setup.py +++ b/port/PyAssimp/setup.py @@ -4,11 +4,11 @@ import os from distutils.core import setup def readme(): - with open('README.md') as f: + with open('README.rst') as f: return f.read() setup(name='pyassimp', - version='4.1.2', + version='4.1.3', license='ISC', description='Python bindings for the Open Asset Import Library (ASSIMP)', long_description=readme(), @@ -19,7 +19,7 @@ setup(name='pyassimp', maintainer_email='severin@guakamole.org', packages=['pyassimp'], data_files=[ - ('share/pyassimp', ['README.md']), + ('share/pyassimp', ['README.rst']), ('share/examples/pyassimp', ['scripts/' + f for f in os.listdir('scripts/')]) ], requires=['numpy'] From ffb6756d2a2dc690e173b89679335ac99d885f29 Mon Sep 17 00:00:00 2001 From: Tammo Hinrichs Date: Wed, 30 May 2018 14:56:53 +0200 Subject: [PATCH 05/11] FBX: LayeredTextures now work with embedded texture data --- code/FBXConverter.cpp | 80 +++++++++++++++++++++++-------------------- code/FBXConverter.h | 4 +++ 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index c50e88390..9c07e9c58 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -1526,6 +1526,46 @@ unsigned int Converter::ConvertVideo( const Video& video ) return static_cast( textures.size() - 1 ); } +aiString Converter::GetTexturePath(const Texture* tex) +{ + aiString path; + path.Set(tex->RelativeFilename()); + + const Video* media = tex->Media(); + if (media != 0) { + bool textureReady = false; //tells if our texture is ready (if it was loaded or if it was found) + unsigned int index; + + VideoMap::const_iterator it = textures_converted.find(media); + if (it != textures_converted.end()) { + index = (*it).second; + textureReady = true; + } + else { + if (media->ContentLength() > 0) { + index = ConvertVideo(*media); + textures_converted[media] = index; + textureReady = true; + } + } + + // setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture), if the texture is ready + if (doc.Settings().useLegacyEmbeddedTextureNaming) { + if (textureReady) { + // TODO: check the possibility of using the flag "AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING" + // In FBX files textures are now stored internally by Assimp with their filename included + // Now Assimp can lookup through the loaded textures after all data is processed + // We need to load all textures before referencing them, as FBX file format order may reference a texture before loading it + // This may occur on this case too, it has to be studied + path.data[0] = '*'; + path.length = 1 + ASSIMP_itoa10(path.data + 1, MAXLEN - 1, index); + } + } + } + + return path; +} + void Converter::TrySetTextureProperties( aiMaterial* out_mat, const TextureMap& textures, const std::string& propName, aiTextureType target, const MeshGeometry* const mesh ) @@ -1538,41 +1578,7 @@ void Converter::TrySetTextureProperties( aiMaterial* out_mat, const TextureMap& const Texture* const tex = ( *it ).second; if ( tex != 0 ) { - aiString path; - path.Set( tex->RelativeFilename() ); - - const Video* media = tex->Media(); - if (media != 0) { - bool textureReady = false; //tells if our texture is ready (if it was loaded or if it was found) - unsigned int index; - - VideoMap::const_iterator it = textures_converted.find(media); - if (it != textures_converted.end()) { - index = (*it).second; - textureReady = true; - } - else { - if (media->ContentLength() > 0) { - index = ConvertVideo(*media); - textures_converted[media] = index; - textureReady = true; - } - } - - // setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture), if the texture is ready - if (doc.Settings().useLegacyEmbeddedTextureNaming) { - if (textureReady) { - // TODO: check the possibility of using the flag "AI_CONFIG_IMPORT_FBX_EMBEDDED_TEXTURES_LEGACY_NAMING" - // In FBX files textures are now stored internally by Assimp with their filename included - // Now Assimp can lookup through the loaded textures after all data is processed - // We need to load all textures before referencing them, as FBX file format order may reference a texture before loading it - // This may occur on this case too, it has to be studied - path.data[0] = '*'; - path.length = 1 + ASSIMP_itoa10(path.data + 1, MAXLEN - 1, index); - } - } - } - + aiString path = GetTexturePath(tex); out_mat->AddProperty( &path, _AI_MATKEY_TEXTURE_BASE, target, 0 ); aiUVTransform uvTrafo; @@ -1696,9 +1702,7 @@ void Converter::TrySetTextureProperties( aiMaterial* out_mat, const LayeredTextu const Texture* const tex = ( *it ).second->getTexture(texIndex); - aiString path; - path.Set( tex->RelativeFilename() ); - + aiString path = GetTexturePath(tex); out_mat->AddProperty( &path, _AI_MATKEY_TEXTURE_BASE, target, texIndex ); aiUVTransform uvTrafo; diff --git a/code/FBXConverter.h b/code/FBXConverter.h index 71d93d339..fca42e8d7 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -228,6 +228,10 @@ private: // Video -> aiTexture unsigned int ConvertVideo(const Video& video); + // ------------------------------------------------------------------------------------------------ + // convert embedded texture if necessary and return actual texture path + aiString GetTexturePath(const Texture* tex); + // ------------------------------------------------------------------------------------------------ void TrySetTextureProperties(aiMaterial* out_mat, const TextureMap& textures, const std::string& propName, From 64ba839f47a8198f15a070106413fa6e55c9d610 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 31 May 2018 20:04:48 +0200 Subject: [PATCH 06/11] Update Readme.md Fix the link to the active repo containing the assimp-net-code. --- port/AssimpNET/Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/AssimpNET/Readme.md b/port/AssimpNET/Readme.md index d251cecc3..dca57470c 100644 --- a/port/AssimpNET/Readme.md +++ b/port/AssimpNET/Readme.md @@ -1 +1 @@ -See https://code.google.com/p/assimp-net/ and https://github.com/assimp/assimp-net for a Github mirror. \ No newline at end of file +Please check the following github-repo for the source: https://github.com/kebby/assimp-net From 31e75b9d5438ea4de3204555a8741119e41041d2 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 31 May 2018 20:18:17 +0200 Subject: [PATCH 07/11] Update FBXConverter.cpp Replaces a 0 by nullptr. --- code/FBXConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index 9c07e9c58..981203abb 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -1532,7 +1532,7 @@ aiString Converter::GetTexturePath(const Texture* tex) path.Set(tex->RelativeFilename()); const Video* media = tex->Media(); - if (media != 0) { + if (media != nullptr) { bool textureReady = false; //tells if our texture is ready (if it was loaded or if it was found) unsigned int index; From 6aa32b41a1f64fb03f40bbd902950de3bc158d26 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Fri, 1 Jun 2018 12:05:42 +0300 Subject: [PATCH 08/11] Replace type punning with explicit memcpys --- include/assimp/qnan.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/include/assimp/qnan.h b/include/assimp/qnan.h index 6ee3b7ce5..251688989 100644 --- a/include/assimp/qnan.h +++ b/include/assimp/qnan.h @@ -98,8 +98,10 @@ AI_FORCE_INLINE bool is_qnan(float in) // compare against // FIXME: Use stuff instead? I think fpclassify needs C99 - return (reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1 && - reinterpret_cast<_IEEESingle*>(&in)->IEEE.Frac); + _IEEESingle temp; + memcpy(&temp, &in, sizeof(float)); + return (temp.IEEE.Exp == (1u << 8)-1 && + temp.IEEE.Frac); } // --------------------------------------------------------------------------- @@ -114,8 +116,10 @@ AI_FORCE_INLINE bool is_qnan(double in) // compare against // FIXME: Use stuff instead? I think fpclassify needs C99 - return (reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Exp == (1u << 11)-1 && - reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Frac); + _IEEEDouble temp; + memcpy(&temp, &in, sizeof(in)); + return (temp.IEEE.Exp == (1u << 11)-1 && + temp.IEEE.Frac); } // --------------------------------------------------------------------------- @@ -125,7 +129,9 @@ AI_FORCE_INLINE bool is_qnan(double in) * @param in Input value */ AI_FORCE_INLINE bool is_special_float(float in) { - return (reinterpret_cast<_IEEESingle*>(&in)->IEEE.Exp == (1u << 8)-1); + _IEEESingle temp; + memcpy(&temp, &in, sizeof(float)); + return (temp.IEEE.Exp == (1u << 8)-1); } // --------------------------------------------------------------------------- @@ -135,7 +141,9 @@ AI_FORCE_INLINE bool is_special_float(float in) * @param in Input value */ AI_FORCE_INLINE bool is_special_float(double in) { - return (reinterpret_cast<_IEEEDouble*>(&in)->IEEE.Exp == (1u << 11)-1); + _IEEESingle temp; + memcpy(&temp, &in, sizeof(float)); + return (temp.IEEE.Exp == (1u << 11)-1); } // --------------------------------------------------------------------------- From bbb60c29f09f2ed378fcbe5063851b476f4bfadc Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Fri, 1 Jun 2018 12:20:16 +0300 Subject: [PATCH 09/11] Fix strict aliasing violation in MaterialSystem --- code/MaterialSystem.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/MaterialSystem.cpp b/code/MaterialSystem.cpp index 97892658f..c8262dff0 100644 --- a/code/MaterialSystem.cpp +++ b/code/MaterialSystem.cpp @@ -354,8 +354,9 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial* mat, return AI_FAILURE; } // Determine mapping type - aiTextureMapping mapping = aiTextureMapping_UV; - aiGetMaterialInteger(mat,AI_MATKEY_MAPPING(type,index),(int*)&mapping); + int mapping_ = static_cast(aiTextureMapping_UV); + aiGetMaterialInteger(mat,AI_MATKEY_MAPPING(type,index), &mapping_); + aiTextureMapping mapping = static_cast(mapping_); if (_mapping) *_mapping = mapping; From 6788d7b18b284e1efa02e59e91a3dba4b52072f6 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Fri, 1 Jun 2018 12:28:33 +0300 Subject: [PATCH 10/11] 3DS: Fix strict aliasing violations --- code/3DSConverter.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/3DSConverter.cpp b/code/3DSConverter.cpp index e07ca4c2d..7ec79ba64 100644 --- a/code/3DSConverter.cpp +++ b/code/3DSConverter.cpp @@ -204,8 +204,9 @@ void CopyTexture(aiMaterial& mat, D3DS::Texture& texture, aiTextureType type) mat.AddProperty( &texture.mTextureBlend, 1, AI_MATKEY_TEXBLEND(type,0)); // Setup the texture mapping mode - mat.AddProperty((int*)&texture.mMapMode,1,AI_MATKEY_MAPPINGMODE_U(type,0)); - mat.AddProperty((int*)&texture.mMapMode,1,AI_MATKEY_MAPPINGMODE_V(type,0)); + int mapMode = static_cast(texture.mMapMode); + mat.AddProperty(&mapMode,1,AI_MATKEY_MAPPINGMODE_U(type,0)); + mat.AddProperty(&mapMode,1,AI_MATKEY_MAPPINGMODE_V(type,0)); // Mirroring - double the scaling values // FIXME: this is not really correct ... @@ -313,7 +314,8 @@ void Discreet3DSImporter::ConvertMaterial(D3DS::Material& oldMat, case D3DS::Discreet3DS::Blinn : eShading = aiShadingMode_Blinn; break; } - mat.AddProperty( (int*)&eShading,1,AI_MATKEY_SHADING_MODEL); + int eShading_ = static_cast(eShading); + mat.AddProperty(&eShading_, 1, AI_MATKEY_SHADING_MODEL); // DIFFUSE texture if( oldMat.sTexDiffuse.mMapName.length() > 0) From b0b604850207a4bf11bc0b4d4f7ce10538c44cc5 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Fri, 1 Jun 2018 12:37:21 +0300 Subject: [PATCH 11/11] LWOMaterial: Fix strict aliasing violations --- code/LWOMaterial.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/code/LWOMaterial.cpp b/code/LWOMaterial.cpp index f4f43ced6..15c210460 100644 --- a/code/LWOMaterial.cpp +++ b/code/LWOMaterial.cpp @@ -253,7 +253,8 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex pcMat->AddProperty((int*)&temp,1,AI_MATKEY_TEXOP(type,cur)); // setup the mapping mode - pcMat->AddProperty((int*)&mapping,1,AI_MATKEY_MAPPING(type,cur)); + int mapping_ = static_cast(mapping); + pcMat->AddProperty(&mapping_, 1, AI_MATKEY_MAPPING(type, cur)); // add the u-wrapping temp = (unsigned int)GetMapMode(texture.wrapModeWidth); @@ -365,7 +366,8 @@ void LWOImporter::ConvertMaterial(const LWO::Surface& surf,aiMaterial* pcMat) } if (surf.mMaximumSmoothAngle <= 0.0) m = aiShadingMode_Flat; - pcMat->AddProperty((int*)&m,1,AI_MATKEY_SHADING_MODEL); + int m_ = static_cast(m); + pcMat->AddProperty(&m_, 1, AI_MATKEY_SHADING_MODEL); // (the diffuse value is just a scaling factor) // If a diffuse texture is set, we set this value to 1.0