created a python3 version of the 3dviewer and fixed the / = float in py3
parent
91f6a9a721
commit
37f5619149
|
@ -9,6 +9,10 @@ import ctypes
|
||||||
from ctypes import POINTER
|
from ctypes import POINTER
|
||||||
import operator
|
import operator
|
||||||
|
|
||||||
|
from distutils.sysconfig import get_python_lib
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
try: import numpy
|
try: import numpy
|
||||||
except: numpy = None
|
except: numpy = None
|
||||||
|
|
||||||
|
@ -26,7 +30,15 @@ if os.name=='posix':
|
||||||
additional_dirs.append('/usr/lib/x86_64-linux-gnu')
|
additional_dirs.append('/usr/lib/x86_64-linux-gnu')
|
||||||
additional_dirs.append('/usr/local/lib/')
|
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
|
# currently there's always a symlink called
|
||||||
# libassimp.so in /usr/local/lib.
|
# libassimp.so in /usr/local/lib.
|
||||||
ext_whitelist.append('.so')
|
ext_whitelist.append('.so')
|
||||||
|
@ -39,7 +51,7 @@ elif os.name=='nt':
|
||||||
for dir_candidate in path_dirs:
|
for dir_candidate in path_dirs:
|
||||||
if 'assimp' in dir_candidate.lower():
|
if 'assimp' in dir_candidate.lower():
|
||||||
additional_dirs.append(dir_candidate)
|
additional_dirs.append(dir_candidate)
|
||||||
|
|
||||||
#print(additional_dirs)
|
#print(additional_dirs)
|
||||||
def vec2tuple(x):
|
def vec2tuple(x):
|
||||||
""" Converts a VECTOR3D to a Tuple """
|
""" 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],
|
m2[0]*x + m2[1]*y + m2[2]*z + m2[3],
|
||||||
m3[0]*x + m3[1]*y + m3[2]*z + m3[3]
|
m3[0]*x + m3[1]*y + m3[2]*z + m3[3]
|
||||||
]
|
]
|
||||||
|
|
||||||
def _inv(matrix4x4):
|
def _inv(matrix4x4):
|
||||||
m0,m1,m2,m3 = matrix4x4
|
m0,m1,m2,m3 = matrix4x4
|
||||||
|
|
||||||
det = m0[3]*m1[2]*m2[1]*m3[0] - m0[2]*m1[3]*m2[1]*m3[0] - \
|
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[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[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[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[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]
|
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,
|
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[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[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[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[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]]
|
( 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):
|
def get_bounding_box(scene):
|
||||||
bb_min = [1e10, 1e10, 1e10] # x,y,z
|
bb_min = [1e10, 1e10, 1e10] # x,y,z
|
||||||
bb_max = [-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[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]
|
t3[0]*T0[3] + t3[1]*T1[3] + t3[2]*T2[3] + t3[3]*T3[3]
|
||||||
] ]
|
] ]
|
||||||
|
|
||||||
for mesh in node.meshes:
|
for mesh in node.meshes:
|
||||||
for v in mesh.vertices:
|
for v in mesh.vertices:
|
||||||
v = transform(v, transformation)
|
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):
|
def try_load_functions(library_path, dll):
|
||||||
'''
|
'''
|
||||||
Try to bind to aiImportFile and aiReleaseImport
|
Try to bind to aiImportFile and aiReleaseImport
|
||||||
|
|
||||||
Arguments
|
Arguments
|
||||||
---------
|
---------
|
||||||
library_path: path to current lib
|
library_path: path to current lib
|
||||||
dll: ctypes handle to library
|
dll: ctypes handle to library
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
---------
|
---------
|
||||||
If unsuccessful:
|
If unsuccessful:
|
||||||
None
|
None
|
||||||
If successful:
|
If successful:
|
||||||
Tuple containing (library_path,
|
Tuple containing (library_path,
|
||||||
load from filename function,
|
load from filename function,
|
||||||
load from memory function,
|
load from memory function,
|
||||||
export to filename function,
|
export to filename function,
|
||||||
release function,
|
release function,
|
||||||
ctypes handle to assimp library)
|
ctypes handle to assimp library)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
load = dll.aiImportFile
|
load = dll.aiImportFile
|
||||||
release = dll.aiReleaseImport
|
release = dll.aiReleaseImport
|
||||||
|
@ -176,7 +188,7 @@ def try_load_functions(library_path, dll):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
#OK, this is a library, but it doesn't have the functions we need
|
#OK, this is a library, but it doesn't have the functions we need
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# library found!
|
# library found!
|
||||||
from .structs import Scene
|
from .structs import Scene
|
||||||
load.restype = POINTER(Scene)
|
load.restype = POINTER(Scene)
|
||||||
|
@ -185,13 +197,13 @@ def try_load_functions(library_path, dll):
|
||||||
|
|
||||||
def search_library():
|
def search_library():
|
||||||
'''
|
'''
|
||||||
Loads the assimp library.
|
Loads the assimp library.
|
||||||
Throws exception AssimpError if no library_path is found
|
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,
|
load from memory function,
|
||||||
export to filename function,
|
export to filename function,
|
||||||
release function,
|
release function,
|
||||||
dll)
|
dll)
|
||||||
'''
|
'''
|
||||||
#this path
|
#this path
|
||||||
|
@ -201,7 +213,7 @@ def search_library():
|
||||||
try:
|
try:
|
||||||
ctypes.windll.kernel32.SetErrorMode(0x8007)
|
ctypes.windll.kernel32.SetErrorMode(0x8007)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
candidates = []
|
candidates = []
|
||||||
# test every file
|
# test every file
|
||||||
|
@ -209,7 +221,7 @@ def search_library():
|
||||||
if os.path.isdir(curfolder):
|
if os.path.isdir(curfolder):
|
||||||
for filename in os.listdir(curfolder):
|
for filename in os.listdir(curfolder):
|
||||||
# our minimum requirement for candidates is that
|
# our minimum requirement for candidates is that
|
||||||
# they should contain 'assimp' somewhere in
|
# they should contain 'assimp' somewhere in
|
||||||
# their name
|
# their name
|
||||||
if filename.lower().find('assimp')==-1 or\
|
if filename.lower().find('assimp')==-1 or\
|
||||||
os.path.splitext(filename)[-1].lower() not in ext_whitelist:
|
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)
|
Calls hasttr() with the given parameters and preserves the legacy (pre-Python 3.2)
|
||||||
functionality of silently catching exceptions.
|
functionality of silently catching exceptions.
|
||||||
|
|
||||||
Returns the result of hasatter() or False if an exception was raised.
|
Returns the result of hasatter() or False if an exception was raised.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return hasattr(object, name)
|
return hasattr(object, name)
|
||||||
except:
|
except:
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue