浏览代码

searches assimp-library automatically

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@151 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
sebastianhempel 17 年之前
父节点
当前提交
398879779e
共有 3 个文件被更改,包括 61 次插入18 次删除
  1. 11 0
      port/PyAssimp/pyassimp/errors.py
  2. 45 1
      port/PyAssimp/pyassimp/helper.py
  3. 5 17
      port/PyAssimp/pyassimp/pyassimp.py

+ 11 - 0
port/PyAssimp/pyassimp/errors.py

@@ -0,0 +1,11 @@
+#-*- coding: UTF-8 -*-
+
+"""
+All possible errors.
+"""
+
+class AssimpError(BaseException):
+    """
+    If an internal error occures.
+    """
+    pass

+ 45 - 1
port/PyAssimp/pyassimp/helper.py

@@ -4,9 +4,53 @@
 Some fancy helper functions.
 """
 
+import os
+import ctypes
+import structs
+from errors import AssimpError
+from ctypes import POINTER
+
 
 def vec2tuple(x):
     """
     Converts a VECTOR3D to a Tuple
     """
-    return (x.x, x.y, x.z)
+    return (x.x, x.y, x.z)
+
+
+def search_library():
+    """
+    Loads the assimp-Library.
+    
+    result (load-function, release-function)
+    
+    exception AssimpError if no library is found
+    """
+    #this path
+    folder = os.path.dirname(__file__)
+    
+    #test every file
+    for filename in os.listdir(folder):
+        library = os.path.join(folder, filename)
+        
+        try:
+            dll = ctypes.cdll.LoadLibrary(library)
+        except:
+            #OK, this except is evil. But different OSs will throw different
+            #errors. So just ignore errors.
+            pass
+        else:
+            #get the functions
+            try:
+                load = dll.aiImportFile
+                release = dll.aiReleaseImport
+            except AttributeError:
+                #OK, this is a library, but it has not the functions we need
+                pass
+            else:
+                #Library found!
+                load.restype = POINTER(structs.SCENE)
+                
+                return (load, release)
+    
+    raise AssimpError, "assimp library not found"

+ 5 - 17
port/PyAssimp/pyassimp/pyassimp.py

@@ -10,31 +10,19 @@ import structs
 import ctypes
 import os
 import helper
+from errors import AssimpError
 
 
 #get the assimp path
 LIBRARY = os.path.join(os.path.dirname(__file__), "assimp.so")
 
 
-class AssimpError(BaseException):
-    """
-    If ann internal error occures.
-    """
-    pass
-
-
 
 class AssimpLib(object):
-    from ctypes import POINTER
-    
-    #open library
-    _dll = ctypes.cdll.LoadLibrary(LIBRARY)
-    
-    #get functions
-    load = _dll.aiImportFile
-    load.restype = POINTER(structs.SCENE)
-    
-    release = _dll.aiReleaseImport
+    """
+    Assimp-Singleton
+    """
+    load, release = helper.search_library()