diff --git a/CMakeLists.txt b/CMakeLists.txt index a1a13ef6f..cbb7bd641 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ execute_process( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET ) # Get the latest abbreviated commit hash of the working branch @@ -35,6 +36,7 @@ execute_process( WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET ) if(NOT GIT_COMMIT_HASH) @@ -63,7 +65,9 @@ if( CMAKE_COMPILER_IS_MINGW ) endif() if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) AND NOT CMAKE_COMPILER_IS_MINGW) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") # this is a very important switch and some libraries seem now to have it.... + if (BUILD_SHARED_LIBS AND CMAKE_SIZEOF_VOID_P EQUAL 8) # -fPIC is only required for shared libs on 64 bit + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + endif() # hide all not-exported symbols set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -Wall" ) elseif(MSVC) @@ -119,7 +123,9 @@ IF ( ASSIMP_ENABLE_BOOST_WORKAROUND ) MESSAGE( STATUS "Building a non-boost version of Assimp." ) ELSE ( ASSIMP_ENABLE_BOOST_WORKAROUND ) SET( Boost_DETAILED_FAILURE_MSG ON ) - SET( Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0" "1.48.0" "1.48" "1.49" "1.49.0" "1.50" "1.50.0" "1.51" "1.51.0" "1.52.0" "1.53.0" "1.54.0" "1.55" "1.55.0" "1.56" "1.56.0" "1.57" "1.57.0" "1.58" "1.58.0" ) + IF ( NOT Boost_ADDITIONAL_VERSIONS ) + SET( Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0" "1.48.0" "1.48" "1.49" "1.49.0" "1.50" "1.50.0" "1.51" "1.51.0" "1.52.0" "1.53.0" "1.54.0" "1.55" "1.55.0" "1.56" "1.56.0" "1.57" "1.57.0" "1.58" "1.58.0" "1.59" "1.59.0") + ENDIF ( NOT Boost_ADDITIONAL_VERSIONS ) FIND_PACKAGE( Boost ) IF ( NOT Boost_FOUND ) MESSAGE( FATAL_ERROR diff --git a/Readme.md b/Readme.md index bc94885b3..1a99bf873 100644 --- a/Readme.md +++ b/Readme.md @@ -113,6 +113,9 @@ If the docs don't solve your problem, ask on [StackOverflow](http://stackoverflo For development discussions, there is also a (very low-volume) mailing list, _assimp-discussions_ [(subscribe here)]( https://lists.sourceforge.net/lists/listinfo/assimp-discussions) +And we also have an IRC-channel at freenode: #assetimporterlib . You can easily join us via: [KiwiIRC/freenote](https://kiwiirc.com/client/irc.freenode.net), choose your nickname and type +> /join #assetimporterlib + ### Contributing ### Contributions to assimp are highly appreciated. The easiest way to get involved is to submit @@ -125,4 +128,3 @@ Our license is based on the modified, __3-clause BSD__-License. An _informal_ summary is: do whatever you want, but include Assimp's license text with your product - and don't sue us if our code doesn't work. Note that, unlike LGPLed code, you may link statically to Assimp. For the legal details, see the `LICENSE` file. - diff --git a/appveyor.yml b/appveyor.yml index 6e5c146a1..8c3264cbf 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,6 @@ # AppVeyor file # http://www.appveyor.com/docs/appveyor-yml -# Operating system (build VM template) -os: Previous Windows Server 2012 R2 # using previous worker images since default worker has problem installing DART-Prerequisites.msi - # clone directory clone_folder: c:\projects\assimp diff --git a/cmake-modules/FindDirectX.cmake b/cmake-modules/FindDirectX.cmake index 38a861a83..707043142 100644 --- a/cmake-modules/FindDirectX.cmake +++ b/cmake-modules/FindDirectX.cmake @@ -35,6 +35,7 @@ if(WIN32) # The only platform it makes sense to check for DirectX SDK "C:/Program Files (x86)/Microsoft DirectX SDK*" "C:/apps/Microsoft DirectX SDK*" "C:/Program Files/Microsoft DirectX SDK*" + "C:/Program Files (x86)/Windows Kits/8.1" "$ENV{ProgramFiles}/Microsoft DirectX SDK*" ) create_search_paths(DirectX) diff --git a/code/BaseImporter.cpp b/code/BaseImporter.cpp index 3c8d9e39b..303c06779 100644 --- a/code/BaseImporter.cpp +++ b/code/BaseImporter.cpp @@ -63,7 +63,7 @@ using namespace Assimp; // ------------------------------------------------------------------------------------------------ // Constructor to be privately used by Importer BaseImporter::BaseImporter() -: progress() +: m_progress() { // nothing to do here } @@ -79,8 +79,8 @@ BaseImporter::~BaseImporter() // Imports the given file and returns the imported data. aiScene* BaseImporter::ReadFile(const Importer* pImp, const std::string& pFile, IOSystem* pIOHandler) { - progress = pImp->GetProgressHandler(); - ai_assert(progress); + m_progress = pImp->GetProgressHandler(); + ai_assert(m_progress); // Gather configuration properties for this run SetupProperties( pImp ); @@ -98,8 +98,8 @@ aiScene* BaseImporter::ReadFile(const Importer* pImp, const std::string& pFile, } catch( const std::exception& err ) { // extract error description - mErrorText = err.what(); - DefaultLogger::get()->error(mErrorText); + m_ErrorText = err.what(); + DefaultLogger::get()->error(m_ErrorText); return NULL; } @@ -274,7 +274,7 @@ void BaseImporter::GetExtensionList(std::set& extensions) for (unsigned int i = 0; i < num; ++i) { // also check against big endian versions of tokens with size 2,4 - // that's just for convinience, the chance that we cause conflicts + // that's just for convenience, the chance that we cause conflicts // is quite low and it can save some lines and prevent nasty bugs if (2 == size) { uint16_t rev = *magic_u16; diff --git a/code/BaseImporter.h b/code/BaseImporter.h index 2234d7116..e8ed7460d 100644 --- a/code/BaseImporter.h +++ b/code/BaseImporter.h @@ -181,7 +181,7 @@ public: * string if there was no error. */ const std::string& GetErrorText() const { - return mErrorText; + return m_ErrorText; } // ------------------------------------------------------------------- @@ -362,10 +362,10 @@ public: // static utilities protected: /** Error description in case there was one. */ - std::string mErrorText; + std::string m_ErrorText; /** Currently set progress handler */ - ProgressHandler* progress; + ProgressHandler* m_progress; }; diff --git a/code/DefaultIOSystem.cpp b/code/DefaultIOSystem.cpp index 32ea03b71..89d40e2a5 100644 --- a/code/DefaultIOSystem.cpp +++ b/code/DefaultIOSystem.cpp @@ -135,11 +135,11 @@ inline void MakeAbsolutePath (const char* in, char* _out) { ai_assert(in && _out); char* ret; -#ifdef _WIN32 - ret = ::_fullpath(_out, in,PATHLIMIT); +#if defined( _MSC_VER ) || defined( __MINGW32__ ) + ret = ::_fullpath( _out, in, PATHLIMIT ); #else - // use realpath - ret = realpath(in, _out); + // use realpath + ret = realpath(in, _out); #endif if(!ret) { // preserve the input path, maybe someone else is able to fix @@ -167,8 +167,8 @@ bool DefaultIOSystem::ComparePaths (const char* one, const char* second) const return !ASSIMP_stricmp(temp1,temp2); } - -std::string DefaultIOSystem::fileName(std::string path) +// ------------------------------------------------------------------------------------------------ +std::string DefaultIOSystem::fileName( const std::string &path ) { std::string ret = path; std::size_t last = ret.find_last_of("\\/"); @@ -177,7 +177,8 @@ std::string DefaultIOSystem::fileName(std::string path) } -std::string DefaultIOSystem::completeBaseName(std::string path) +// ------------------------------------------------------------------------------------------------ +std::string DefaultIOSystem::completeBaseName( const std::string &path ) { std::string ret = fileName(path); std::size_t pos = ret.find_last_of('.'); @@ -185,8 +186,8 @@ std::string DefaultIOSystem::completeBaseName(std::string path) return ret; } - -std::string DefaultIOSystem::absolutePath(std::string path) +// ------------------------------------------------------------------------------------------------ +std::string DefaultIOSystem::absolutePath( const std::string &path ) { std::string ret = path; std::size_t last = ret.find_last_of("\\/"); @@ -194,4 +195,6 @@ std::string DefaultIOSystem::absolutePath(std::string path) return ret; } +// ------------------------------------------------------------------------------------------------ + #undef PATHLIMIT diff --git a/code/DefaultIOSystem.h b/code/DefaultIOSystem.h index b46169f79..cc2118fb9 100644 --- a/code/DefaultIOSystem.h +++ b/code/DefaultIOSystem.h @@ -80,17 +80,17 @@ public: /** @brief get the file name of a full filepath * example: /tmp/archive.tar.gz -> archive.tar.gz */ - static std::string fileName(std::string path); + static std::string fileName( const std::string &path ); /** @brief get the complete base name of a full filepath * example: /tmp/archive.tar.gz -> archive.tar */ - static std::string completeBaseName(std::string path); + static std::string completeBaseName( const std::string &path); /** @brief get the path of a full filepath * example: /tmp/archive.tar.gz -> /tmp/ */ - static std::string absolutePath(std::string path); + static std::string absolutePath( const std::string &path); }; } //!ns Assimp diff --git a/code/MD5Loader.cpp b/code/MD5Loader.cpp index 6628aa346..6f0780e6d 100644 --- a/code/MD5Loader.cpp +++ b/code/MD5Loader.cpp @@ -285,9 +285,6 @@ void MD5Importer::AttachChilds_Mesh(int iParentID,aiNode* piParent, BoneList& bo aiQuaternion quat; MD5::ConvertQuaternion ( bones[i].mRotationQuat, quat ); - // FIX to get to Assimp's quaternion conventions - quat.w *= -1.f; - bones[i].mTransform = aiMatrix4x4 ( quat.GetMatrix()); bones[i].mTransform.a4 = bones[i].mPositionXYZ.x; bones[i].mTransform.b4 = bones[i].mPositionXYZ.y; @@ -656,9 +653,6 @@ void MD5Importer::LoadMD5AnimFile () MD5::ConvertQuaternion(vTemp, qKey->mValue); qKey->mTime = vKey->mTime = dTime; - - // we need this to get to Assimp quaternion conventions - qKey->mValue.w *= -1.f; } } diff --git a/code/MD5Parser.h b/code/MD5Parser.h index fd13961e2..e08d6d8b4 100644 --- a/code/MD5Parser.h +++ b/code/MD5Parser.h @@ -262,6 +262,9 @@ inline void ConvertQuaternion (const aiVector3D& in, aiQuaternion& out) { if (t < 0.0f) out.w = 0.0f; else out.w = std::sqrt (t); + + // Assimp convention. + out.w *= -1.f; } // --------------------------------------------------------------------------- diff --git a/code/ObjFileData.h b/code/ObjFileData.h index 2d5100ba8..9aa44576b 100644 --- a/code/ObjFileData.h +++ b/code/ObjFileData.h @@ -156,6 +156,7 @@ struct Material aiString textureEmissive; aiString textureBump; aiString textureNormal; + aiString textureReflection[6]; aiString textureSpecularity; aiString textureOpacity; aiString textureDisp; @@ -167,6 +168,13 @@ struct Material TextureEmissiveType, TextureBumpType, TextureNormalType, + TextureReflectionSphereType, + TextureReflectionCubeTopType, + TextureReflectionCubeBottomType, + TextureReflectionCubeFrontType, + TextureReflectionCubeBackType, + TextureReflectionCubeLeftType, + TextureReflectionCubeRightType, TextureSpecularityType, TextureOpacityType, TextureDispType, diff --git a/code/ObjFileImporter.cpp b/code/ObjFileImporter.cpp index 7bf6154df..ebf75b3c4 100644 --- a/code/ObjFileImporter.cpp +++ b/code/ObjFileImporter.cpp @@ -636,6 +636,22 @@ void ObjFileImporter::createMaterials(const ObjFile::Model* pModel, aiScene* pSc } } + if( 0 != pCurrentMaterial->textureReflection[0].length ) + { + ObjFile::Material::TextureType type = 0 != pCurrentMaterial->textureReflection[1].length ? + ObjFile::Material::TextureReflectionCubeTopType : + ObjFile::Material::TextureReflectionSphereType; + + unsigned count = type == ObjFile::Material::TextureReflectionSphereType ? 1 : 6; + for( unsigned i = 0; i < count; i++ ) + mat->AddProperty(&pCurrentMaterial->textureReflection[i], AI_MATKEY_TEXTURE_REFLECTION(i)); + + if(pCurrentMaterial->clamp[type]) + //TODO addTextureMappingModeProperty should accept an index to handle clamp option for each + //texture of a cubemap + addTextureMappingModeProperty(mat, aiTextureType_REFLECTION); + } + if ( 0 != pCurrentMaterial->textureDisp.length ) { mat->AddProperty( &pCurrentMaterial->textureDisp, AI_MATKEY_TEXTURE_DISPLACEMENT(0) ); diff --git a/code/ObjFileMtlImporter.cpp b/code/ObjFileMtlImporter.cpp index c993cd203..5b5160a44 100644 --- a/code/ObjFileMtlImporter.cpp +++ b/code/ObjFileMtlImporter.cpp @@ -64,6 +64,7 @@ static const std::string BumpTexture1 = "map_bump"; static const std::string BumpTexture2 = "map_Bump"; static const std::string BumpTexture3 = "bump"; static const std::string NormalTexture = "map_Kn"; +static const std::string ReflectionTexture = "refl"; static const std::string DisplacementTexture = "disp"; static const std::string SpecularityTexture = "map_ns"; @@ -200,6 +201,7 @@ void ObjFileMtlImporter::load() case 'm': // Texture case 'b': // quick'n'dirty - for 'bump' sections + case 'r': // quick'n'dirty - for 'refl' sections { getTexture(); m_DataIt = skipLine( m_DataIt, m_DataItEnd, m_uiLine ); @@ -332,6 +334,9 @@ void ObjFileMtlImporter::getTexture() { // Normal map out = & m_pModel->m_pCurrentMaterial->textureNormal; clampIndex = ObjFile::Material::TextureNormalType; + } else if(!ASSIMP_strincmp( pPtr, ReflectionTexture.c_str(), ReflectionTexture.size() ) ) { + // Reflection texture(s) + //Do nothing here } else if (!ASSIMP_strincmp( pPtr, DisplacementTexture.c_str(), DisplacementTexture.size() ) ) { // Displacement texture out = &m_pModel->m_pCurrentMaterial->textureDisp; @@ -346,7 +351,7 @@ void ObjFileMtlImporter::getTexture() { } bool clamp = false; - getTextureOption(clamp); + getTextureOption(clamp, clampIndex, out); m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp; std::string texture; @@ -369,7 +374,7 @@ void ObjFileMtlImporter::getTexture() { * Because aiMaterial supports clamp option, so we also want to return it * ///////////////////////////////////////////////////////////////////////////// */ -void ObjFileMtlImporter::getTextureOption(bool &clamp) +void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString *&out) { m_DataIt = getNextToken(m_DataIt, m_DataItEnd); @@ -392,13 +397,55 @@ void ObjFileMtlImporter::getTextureOption(bool &clamp) skipToken = 2; } - else if ( !ASSIMP_strincmp(pPtr, BlendUOption.c_str(), BlendUOption.size()) + else if( !ASSIMP_strincmp( pPtr, TypeOption.c_str(), TypeOption.size() ) ) + { + DataArrayIt it = getNextToken( m_DataIt, m_DataItEnd ); + char value[ 12 ]; + CopyNextWord( it, m_DataItEnd, value, sizeof( value ) / sizeof( *value ) ); + if( !ASSIMP_strincmp( value, "cube_top", 8 ) ) + { + clampIndex = ObjFile::Material::TextureReflectionCubeTopType; + out = &m_pModel->m_pCurrentMaterial->textureReflection[0]; + } + else if( !ASSIMP_strincmp( value, "cube_bottom", 11 ) ) + { + clampIndex = ObjFile::Material::TextureReflectionCubeBottomType; + out = &m_pModel->m_pCurrentMaterial->textureReflection[1]; + } + else if( !ASSIMP_strincmp( value, "cube_front", 10 ) ) + { + clampIndex = ObjFile::Material::TextureReflectionCubeFrontType; + out = &m_pModel->m_pCurrentMaterial->textureReflection[2]; + } + else if( !ASSIMP_strincmp( value, "cube_back", 9 ) ) + { + clampIndex = ObjFile::Material::TextureReflectionCubeBackType; + out = &m_pModel->m_pCurrentMaterial->textureReflection[3]; + } + else if( !ASSIMP_strincmp( value, "cube_left", 9 ) ) + { + clampIndex = ObjFile::Material::TextureReflectionCubeLeftType; + out = &m_pModel->m_pCurrentMaterial->textureReflection[4]; + } + else if( !ASSIMP_strincmp( value, "cube_right", 10 ) ) + { + clampIndex = ObjFile::Material::TextureReflectionCubeRightType; + out = &m_pModel->m_pCurrentMaterial->textureReflection[5]; + } + else if( !ASSIMP_strincmp( value, "sphere", 6 ) ) + { + clampIndex = ObjFile::Material::TextureReflectionSphereType; + out = &m_pModel->m_pCurrentMaterial->textureReflection[0]; + } + + skipToken = 2; + } + else if (!ASSIMP_strincmp(pPtr, BlendUOption.c_str(), BlendUOption.size()) || !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), BlendVOption.size()) || !ASSIMP_strincmp(pPtr, BoostOption.c_str(), BoostOption.size()) || !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), ResolutionOption.size()) || !ASSIMP_strincmp(pPtr, BumpOption.c_str(), BumpOption.size()) - || !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), ChannelOption.size()) - || !ASSIMP_strincmp(pPtr, TypeOption.c_str(), TypeOption.size()) ) + || !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), ChannelOption.size())) { skipToken = 2; } diff --git a/code/ObjFileMtlImporter.h b/code/ObjFileMtlImporter.h index 3278e380b..8bcfc51e1 100644 --- a/code/ObjFileMtlImporter.h +++ b/code/ObjFileMtlImporter.h @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include struct aiColor3D; +struct aiString; namespace Assimp { @@ -89,7 +90,7 @@ private: void createMaterial(); /// Get texture name from loaded data. void getTexture(); - void getTextureOption(bool &clamp); + void getTextureOption(bool &clamp, int &clampIndex, aiString *&out); private: //! Absolute pathname diff --git a/code/PlyParser.cpp b/code/PlyParser.cpp index db4c2b5d4..8d6ce0698 100644 --- a/code/PlyParser.cpp +++ b/code/PlyParser.cpp @@ -857,7 +857,7 @@ bool PLY::PropertyInstance::ParseValueBinary( case EDT_UShort: { - int16_t i = *((uint16_t*)pCur); + uint16_t i = *((uint16_t*)pCur); // Swap endianess if (p_bBE)ByteSwap::Swap(&i); diff --git a/code/STLLoader.cpp b/code/STLLoader.cpp index f840ce29c..96cded883 100644 --- a/code/STLLoader.cpp +++ b/code/STLLoader.cpp @@ -74,7 +74,7 @@ static const aiImporterDesc desc = { // 1) 80 byte header // 2) 4 byte face count // 3) 50 bytes per face -bool IsBinarySTL(const char* buffer, unsigned int fileSize) { +static bool IsBinarySTL(const char* buffer, unsigned int fileSize) { if( fileSize < 84 ) { return false; } @@ -88,7 +88,7 @@ bool IsBinarySTL(const char* buffer, unsigned int fileSize) { // An ascii STL buffer will begin with "solid NAME", where NAME is optional. // Note: The "solid NAME" check is necessary, but not sufficient, to determine // if the buffer is ASCII; a binary header could also begin with "solid NAME". -bool IsAsciiSTL(const char* buffer, unsigned int fileSize) { +static bool IsAsciiSTL(const char* buffer, unsigned int fileSize) { if (IsBinarySTL(buffer, fileSize)) return false; diff --git a/include/assimp/types.h b/include/assimp/types.h index 8e784cfe8..82be2d62f 100644 --- a/include/assimp/types.h +++ b/include/assimp/types.h @@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // Some runtime headers #include -#include #include #include #include diff --git a/port/PyAssimp/pyassimp/core.py b/port/PyAssimp/pyassimp/core.py index 29550eb35..f035b35e5 100644 --- a/port/PyAssimp/pyassimp/core.py +++ b/port/PyAssimp/pyassimp/core.py @@ -10,7 +10,9 @@ if sys.version_info < (2,6): import ctypes import os -import numpy + +try: import numpy +except: numpy = None import logging logger = logging.getLogger("pyassimp") @@ -33,12 +35,30 @@ _assimp_lib = AssimpLib() def make_tuple(ai_obj, type = None): res = None + + #notes: + # ai_obj._fields_ = [ ("attr", c_type), ... ] + # getattr(ai_obj, e[0]).__class__ == float + if isinstance(ai_obj, structs.Matrix4x4): - res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((4,4)) + if numpy: + res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((4,4)) + #import pdb;pdb.set_trace() + else: + res = [getattr(ai_obj, e[0]) for e in ai_obj._fields_] + res = [res[i:i+4] for i in xrange(0,16,4)] elif isinstance(ai_obj, structs.Matrix3x3): - res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((3,3)) + if numpy: + res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]).reshape((3,3)) + else: + res = [getattr(ai_obj, e[0]) for e in ai_obj._fields_] + res = [res[i:i+3] for i in xrange(0,9,3)] else: - res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]) + if numpy: + res = numpy.array([getattr(ai_obj, e[0]) for e in ai_obj._fields_]) + else: + res = [getattr(ai_obj, e[0]) for e in ai_obj._fields_] + return res # It is faster and more correct to have an init function for each assimp class @@ -135,9 +155,14 @@ def _init(self, target = None, parent = None): try: if obj._type_ in structs.assimp_structs_as_tuple: - setattr(target, name, numpy.array([make_tuple(obj[i]) for i in range(length)], dtype=numpy.float32)) + if numpy: + setattr(target, name, numpy.array([make_tuple(obj[i]) for i in range(length)], dtype=numpy.float32)) - logger.debug(str(self) + ": Added an array of numpy arrays (type "+ str(type(obj)) + ") as self." + name) + logger.debug(str(self) + ": Added an array of numpy arrays (type "+ str(type(obj)) + ") as self." + name) + else: + setattr(target, name, [make_tuple(obj[i]) for i in range(length)]) + + logger.debug(str(self) + ": Added a list of lists (type "+ str(type(obj)) + ") as self." + name) else: setattr(target, name, [obj[i] for i in range(length)]) #TODO: maybe not necessary to recreate an array? @@ -292,7 +317,10 @@ def release(scene): def _finalize_texture(tex, target): setattr(target, "achformathint", tex.achFormatHint) - data = numpy.array([make_tuple(getattr(tex, "pcData")[i]) for i in range(tex.mWidth * tex.mHeight)]) + if numpy: + data = numpy.array([make_tuple(getattr(tex, "pcData")[i]) for i in range(tex.mWidth * tex.mHeight)]) + else: + data = [make_tuple(getattr(tex, "pcData")[i]) for i in range(tex.mWidth * tex.mHeight)] setattr(target, "data", data) def _finalize_mesh(mesh, target): @@ -308,11 +336,18 @@ def _finalize_mesh(mesh, target): def fill(name): mAttr = getattr(mesh, name) - if mAttr: - data = numpy.array([make_tuple(getattr(mesh, name)[i]) for i in range(nb_vertices)], dtype=numpy.float32) - setattr(target, name[1:].lower(), data) + if numpy: + if mAttr: + data = numpy.array([make_tuple(getattr(mesh, name)[i]) for i in range(nb_vertices)], dtype=numpy.float32) + setattr(target, name[1:].lower(), data) + else: + setattr(target, name[1:].lower(), numpy.array([], dtype="float32")) else: - setattr(target, name[1:].lower(), numpy.array([], dtype="float32")) + if mAttr: + data = [make_tuple(getattr(mesh, name)[i]) for i in range(nb_vertices)] + setattr(target, name[1:].lower(), data) + else: + setattr(target, name[1:].lower(), []) def fillarray(name): mAttr = getattr(mesh, name) @@ -322,7 +357,10 @@ def _finalize_mesh(mesh, target): if mSubAttr: data.append([make_tuple(getattr(mesh, name)[index][i]) for i in range(nb_vertices)]) - setattr(target, name[1:].lower(), numpy.array(data, dtype=numpy.float32)) + if numpy: + setattr(target, name[1:].lower(), numpy.array(data, dtype=numpy.float32)) + else: + setattr(target, name[1:].lower(), data) fill("mNormals") fill("mTangents") @@ -332,7 +370,10 @@ def _finalize_mesh(mesh, target): fillarray("mTextureCoords") # prepare faces - faces = numpy.array([f.indices for f in target.faces], dtype=numpy.int32) + if numpy: + faces = numpy.array([f.indices for f in target.faces], dtype=numpy.int32) + else: + faces = [f.indices for f in target.faces] setattr(target, 'faces', faces) diff --git a/port/PyAssimp/pyassimp/helper.py b/port/PyAssimp/pyassimp/helper.py index 07d09a568..ad38e3b71 100644 --- a/port/PyAssimp/pyassimp/helper.py +++ b/port/PyAssimp/pyassimp/helper.py @@ -8,8 +8,9 @@ import os import ctypes from ctypes import POINTER import operator -import numpy -from numpy import linalg + +try: import numpy +except: numpy = None import logging;logger = logging.getLogger("pyassimp") @@ -46,20 +47,88 @@ def vec2tuple(x): def transform(vector3, matrix4x4): """ Apply a transformation matrix on a 3D vector. - :param vector3: a numpy array with 3 elements - :param matrix4x4: a numpy 4x4 matrix + :param vector3: array with 3 elements + :param matrix4x4: 4x4 matrix """ - return numpy.dot(matrix4x4, numpy.append(vector3, 1.)) - + if numpy: + return numpy.dot(matrix4x4, numpy.append(vector3, 1.)) + else: + m0,m1,m2,m3 = matrix4x4; x,y,z = vector3 + return [ + m0[0]*x + m0[1]*y + m0[2]*z + m0[3], + m1[0]*x + m1[1]*y + m1[2]*z + m1[3], + m2[0]*x + m2[1]*y + m2[2]*z + m2[3], + m3[0]*x + m3[1]*y + m3[2]*z + m3[3] + ] + +def _inv(matrix4x4): + m0,m1,m2,m3 = matrix4x4 + + det = m0[3]*m1[2]*m2[1]*m3[0] - m0[2]*m1[3]*m2[1]*m3[0] - \ + m0[3]*m1[1]*m2[2]*m3[0] + m0[1]*m1[3]*m2[2]*m3[0] + \ + m0[2]*m1[1]*m2[3]*m3[0] - m0[1]*m1[2]*m2[3]*m3[0] - \ + m0[3]*m1[2]*m2[0]*m3[1] + m0[2]*m1[3]*m2[0]*m3[1] + \ + m0[3]*m1[0]*m2[2]*m3[1] - m0[0]*m1[3]*m2[2]*m3[1] - \ + m0[2]*m1[0]*m2[3]*m3[1] + m0[0]*m1[2]*m2[3]*m3[1] + \ + m0[3]*m1[1]*m2[0]*m3[2] - m0[1]*m1[3]*m2[0]*m3[2] - \ + m0[3]*m1[0]*m2[1]*m3[2] + m0[0]*m1[3]*m2[1]*m3[2] + \ + m0[1]*m1[0]*m2[3]*m3[2] - m0[0]*m1[1]*m2[3]*m3[2] - \ + m0[2]*m1[1]*m2[0]*m3[3] + m0[1]*m1[2]*m2[0]*m3[3] + \ + m0[2]*m1[0]*m2[1]*m3[3] - m0[0]*m1[2]*m2[1]*m3[3] - \ + m0[1]*m1[0]*m2[2]*m3[3] + m0[0]*m1[1]*m2[2]*m3[3] + + return[[( m1[2]*m2[3]*m3[1] - m1[3]*m2[2]*m3[1] + m1[3]*m2[1]*m3[2] - m1[1]*m2[3]*m3[2] - m1[2]*m2[1]*m3[3] + m1[1]*m2[2]*m3[3]) /det, + ( m0[3]*m2[2]*m3[1] - m0[2]*m2[3]*m3[1] - m0[3]*m2[1]*m3[2] + m0[1]*m2[3]*m3[2] + m0[2]*m2[1]*m3[3] - m0[1]*m2[2]*m3[3]) /det, + ( m0[2]*m1[3]*m3[1] - m0[3]*m1[2]*m3[1] + m0[3]*m1[1]*m3[2] - m0[1]*m1[3]*m3[2] - m0[2]*m1[1]*m3[3] + m0[1]*m1[2]*m3[3]) /det, + ( m0[3]*m1[2]*m2[1] - m0[2]*m1[3]*m2[1] - m0[3]*m1[1]*m2[2] + m0[1]*m1[3]*m2[2] + m0[2]*m1[1]*m2[3] - m0[1]*m1[2]*m2[3]) /det], + [( m1[3]*m2[2]*m3[0] - m1[2]*m2[3]*m3[0] - m1[3]*m2[0]*m3[2] + m1[0]*m2[3]*m3[2] + m1[2]*m2[0]*m3[3] - m1[0]*m2[2]*m3[3]) /det, + ( m0[2]*m2[3]*m3[0] - m0[3]*m2[2]*m3[0] + m0[3]*m2[0]*m3[2] - m0[0]*m2[3]*m3[2] - m0[2]*m2[0]*m3[3] + m0[0]*m2[2]*m3[3]) /det, + ( m0[3]*m1[2]*m3[0] - m0[2]*m1[3]*m3[0] - m0[3]*m1[0]*m3[2] + m0[0]*m1[3]*m3[2] + m0[2]*m1[0]*m3[3] - m0[0]*m1[2]*m3[3]) /det, + ( m0[2]*m1[3]*m2[0] - m0[3]*m1[2]*m2[0] + m0[3]*m1[0]*m2[2] - m0[0]*m1[3]*m2[2] - m0[2]*m1[0]*m2[3] + m0[0]*m1[2]*m2[3]) /det], + [( m1[1]*m2[3]*m3[0] - m1[3]*m2[1]*m3[0] + m1[3]*m2[0]*m3[1] - m1[0]*m2[3]*m3[1] - m1[1]*m2[0]*m3[3] + m1[0]*m2[1]*m3[3]) /det, + ( m0[3]*m2[1]*m3[0] - m0[1]*m2[3]*m3[0] - m0[3]*m2[0]*m3[1] + m0[0]*m2[3]*m3[1] + m0[1]*m2[0]*m3[3] - m0[0]*m2[1]*m3[3]) /det, + ( m0[1]*m1[3]*m3[0] - m0[3]*m1[1]*m3[0] + m0[3]*m1[0]*m3[1] - m0[0]*m1[3]*m3[1] - m0[1]*m1[0]*m3[3] + m0[0]*m1[1]*m3[3]) /det, + ( m0[3]*m1[1]*m2[0] - m0[1]*m1[3]*m2[0] - m0[3]*m1[0]*m2[1] + m0[0]*m1[3]*m2[1] + m0[1]*m1[0]*m2[3] - m0[0]*m1[1]*m2[3]) /det], + [( m1[2]*m2[1]*m3[0] - m1[1]*m2[2]*m3[0] - m1[2]*m2[0]*m3[1] + m1[0]*m2[2]*m3[1] + m1[1]*m2[0]*m3[2] - m1[0]*m2[1]*m3[2]) /det, + ( m0[1]*m2[2]*m3[0] - m0[2]*m2[1]*m3[0] + m0[2]*m2[0]*m3[1] - m0[0]*m2[2]*m3[1] - m0[1]*m2[0]*m3[2] + m0[0]*m2[1]*m3[2]) /det, + ( m0[2]*m1[1]*m3[0] - m0[1]*m1[2]*m3[0] - m0[2]*m1[0]*m3[1] + m0[0]*m1[2]*m3[1] + m0[1]*m1[0]*m3[2] - m0[0]*m1[1]*m3[2]) /det, + ( m0[1]*m1[2]*m2[0] - m0[2]*m1[1]*m2[0] + m0[2]*m1[0]*m2[1] - m0[0]*m1[2]*m2[1] - m0[1]*m1[0]*m2[2] + m0[0]*m1[1]*m2[2]) /det]] def get_bounding_box(scene): bb_min = [1e10, 1e10, 1e10] # x,y,z bb_max = [-1e10, -1e10, -1e10] # x,y,z - return get_bounding_box_for_node(scene.rootnode, bb_min, bb_max, linalg.inv(scene.rootnode.transformation)) + inv = numpy.linalg.inv if numpy else _inv + return get_bounding_box_for_node(scene.rootnode, bb_min, bb_max, inv(scene.rootnode.transformation)) def get_bounding_box_for_node(node, bb_min, bb_max, transformation): - transformation = numpy.dot(transformation, node.transformation) + if numpy: + transformation = numpy.dot(transformation, node.transformation) + else: + t0,t1,t2,t3 = transformation + T0,T1,T2,T3 = node.transformation + transformation = [ [ + t0[0]*T0[0] + t0[1]*T1[0] + t0[2]*T2[0] + t0[3]*T3[0], + t0[0]*T0[1] + t0[1]*T1[1] + t0[2]*T2[1] + t0[3]*T3[1], + t0[0]*T0[2] + t0[1]*T1[2] + t0[2]*T2[2] + t0[3]*T3[2], + t0[0]*T0[3] + t0[1]*T1[3] + t0[2]*T2[3] + t0[3]*T3[3] + ],[ + t1[0]*T0[0] + t1[1]*T1[0] + t1[2]*T2[0] + t1[3]*T3[0], + t1[0]*T0[1] + t1[1]*T1[1] + t1[2]*T2[1] + t1[3]*T3[1], + t1[0]*T0[2] + t1[1]*T1[2] + t1[2]*T2[2] + t1[3]*T3[2], + t1[0]*T0[3] + t1[1]*T1[3] + t1[2]*T2[3] + t1[3]*T3[3] + ],[ + t2[0]*T0[0] + t2[1]*T1[0] + t2[2]*T2[0] + t2[3]*T3[0], + t2[0]*T0[1] + t2[1]*T1[1] + t2[2]*T2[1] + t2[3]*T3[1], + t2[0]*T0[2] + t2[1]*T1[2] + t2[2]*T2[2] + t2[3]*T3[2], + t2[0]*T0[3] + t2[1]*T1[3] + t2[2]*T2[3] + t2[3]*T3[3] + ],[ + t3[0]*T0[0] + t3[1]*T1[0] + t3[2]*T2[0] + t3[3]*T3[0], + t3[0]*T0[1] + t3[1]*T1[1] + t3[2]*T2[1] + t3[3]*T3[1], + t3[0]*T0[2] + t3[1]*T1[2] + t3[2]*T2[2] + t3[3]*T3[2], + t3[0]*T0[3] + t3[1]*T1[3] + t3[2]*T2[3] + t3[3]*T3[3] + ] ] + for mesh in node.meshes: for v in mesh.vertices: v = transform(v, transformation) diff --git a/samples/SimpleOpenGL/makefile b/samples/SimpleOpenGL/makefile deleted file mode 100644 index d8c7425e4..000000000 --- a/samples/SimpleOpenGL/makefile +++ /dev/null @@ -1,28 +0,0 @@ - -# --------------------------------------------------------------------------- -# Makefile for assimp/Sample_SimpleOpenGL -# aramis_acg@users.sourceforge.net -# -# Usage: make - -# TARGETS: -# all Build the sample + assimp itself -# clean Cleanup all object files -# --------------------------------------------------------------------------- - -VPATH = ./usr/include/ -# Include flags for gcc -INCLUDEFLAGS = -I../../include - -# Library flags for gcc -LIBFLAGS = -L../../bin/gcc - -# Output name of executable -OUTPUT = samplegl - -all: $(OBJECTS) - cd ../../code/ && $(MAKE) static - gcc -o $(OUTPUT) $(INCLUDEFLAGS) -s Sample_SimpleOpenGL.c $(LIBFLAGS) -Wl,-Bstatic -lassimp -Wl,-Bdynamic -lstdc++ -lglut -.PHONY: clean -clean: - -rm *.o diff --git a/test/regression/db.zip b/test/regression/db.zip index 3808ded59..c94598840 100644 Binary files a/test/regression/db.zip and b/test/regression/db.zip differ