2008-09-18 13:17:44 +00:00
|
|
|
#-*- coding: UTF-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
Some fancy helper functions.
|
|
|
|
"""
|
|
|
|
|
2008-09-18 13:36:34 +00:00
|
|
|
import os
|
|
|
|
import ctypes
|
|
|
|
import structs
|
2008-09-19 18:06:04 +00:00
|
|
|
import operator
|
2008-09-18 13:36:34 +00:00
|
|
|
from errors import AssimpError
|
|
|
|
from ctypes import POINTER
|
|
|
|
|
2008-09-18 13:17:44 +00:00
|
|
|
|
|
|
|
def vec2tuple(x):
|
|
|
|
"""
|
|
|
|
Converts a VECTOR3D to a Tuple
|
|
|
|
"""
|
2008-09-18 13:36:34 +00:00
|
|
|
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__)
|
|
|
|
|
2009-04-23 20:58:16 +00:00
|
|
|
ctypes.windll.kernel32.SetErrorMode(0x8007)
|
|
|
|
|
2008-09-19 18:06:04 +00:00
|
|
|
candidates = []
|
|
|
|
|
2008-09-18 13:36:34 +00:00
|
|
|
#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!
|
2009-04-25 21:12:53 +00:00
|
|
|
load.restype = POINTER(structs.Scene)
|
2008-09-18 13:36:34 +00:00
|
|
|
|
2009-04-25 21:12:53 +00:00
|
|
|
candidates.append((library, load, release, dll))
|
2008-09-18 13:36:34 +00:00
|
|
|
|
2008-09-19 18:06:04 +00:00
|
|
|
if not candidates:
|
|
|
|
#no library found
|
|
|
|
raise AssimpError, "assimp library not found"
|
|
|
|
else:
|
|
|
|
#get the newest library
|
|
|
|
candidates = map(lambda x: (os.lstat(x[0])[-2], x), candidates)
|
2009-04-23 20:58:16 +00:00
|
|
|
return max(candidates, key=operator.itemgetter(0))[1][1:]
|