Merge pull request #1401 from melMass/python3

Detect if Anaconda and fixed 3d_viewer for Python 3
pull/1405/head
Kim Kulling 2017-08-25 12:23:24 +02:00 committed by GitHub
commit c6360ba1ab
2 changed files with 1353 additions and 21 deletions

View File

@ -9,6 +9,10 @@ import ctypes
from ctypes import POINTER
import operator
from distutils.sysconfig import get_python_lib
import re
import sys
try: import numpy
except: numpy = None
@ -26,7 +30,15 @@ if os.name=='posix':
additional_dirs.append('/usr/lib/x86_64-linux-gnu')
additional_dirs.append('/usr/local/lib/')
# note - this won't catch libassimp.so.N.n, but
# check if running from anaconda.
if "conda" or "continuum" in sys.version.lower():
cur_path = get_python_lib()
pattern = re.compile('.*\/lib\/')
conda_lib = pattern.match(cur_path).group()
logger.info("Adding Anaconda lib path:"+ conda_lib)
additional_dirs.append(conda_lib)
# note - this won't catch libassimp.so.N.n, but
# currently there's always a symlink called
# libassimp.so in /usr/local/lib.
ext_whitelist.append('.so')
@ -39,7 +51,7 @@ elif os.name=='nt':
for dir_candidate in path_dirs:
if 'assimp' in dir_candidate.lower():
additional_dirs.append(dir_candidate)
#print(additional_dirs)
def vec2tuple(x):
""" Converts a VECTOR3D to a Tuple """
@ -61,10 +73,10 @@ def transform(vector3, matrix4x4):
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] - \
@ -77,7 +89,7 @@ def _inv(matrix4x4):
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,
@ -94,7 +106,7 @@ def _inv(matrix4x4):
( 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
@ -129,7 +141,7 @@ def get_bounding_box_for_node(node, bb_min, bb_max, transformation):
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)
@ -149,25 +161,25 @@ def get_bounding_box_for_node(node, bb_min, bb_max, transformation):
def try_load_functions(library_path, dll):
'''
Try to bind to aiImportFile and aiReleaseImport
Arguments
---------
library_path: path to current lib
dll: ctypes handle to library
Returns
---------
If unsuccessful:
None
If successful:
Tuple containing (library_path,
Tuple containing (library_path,
load from filename function,
load from memory function,
export to filename function,
release function,
release function,
ctypes handle to assimp library)
'''
try:
load = dll.aiImportFile
release = dll.aiReleaseImport
@ -176,7 +188,7 @@ def try_load_functions(library_path, dll):
except AttributeError:
#OK, this is a library, but it doesn't have the functions we need
return None
# library found!
from .structs import Scene
load.restype = POINTER(Scene)
@ -185,13 +197,13 @@ def try_load_functions(library_path, dll):
def search_library():
'''
Loads the assimp library.
Loads the assimp library.
Throws exception AssimpError if no library_path is found
Returns: tuple, (load from filename function,
Returns: tuple, (load from filename function,
load from memory function,
export to filename function,
release function,
release function,
dll)
'''
#this path
@ -201,7 +213,7 @@ def search_library():
try:
ctypes.windll.kernel32.SetErrorMode(0x8007)
except AttributeError:
pass
pass
candidates = []
# test every file
@ -209,7 +221,7 @@ def search_library():
if os.path.isdir(curfolder):
for filename in os.listdir(curfolder):
# our minimum requirement for candidates is that
# they should contain 'assimp' somewhere in
# they should contain 'assimp' somewhere in
# their name
if filename.lower().find('assimp')==-1 or\
os.path.splitext(filename)[-1].lower() not in ext_whitelist:
@ -248,10 +260,10 @@ def hasattr_silent(object, name):
"""
Calls hasttr() with the given parameters and preserves the legacy (pre-Python 3.2)
functionality of silently catching exceptions.
Returns the result of hasatter() or False if an exception was raised.
"""
try:
return hasattr(object, name)
except:

File diff suppressed because it is too large Load Diff