File: helper.py

package info (click to toggle)
assimp 3.0~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 12,104 kB
  • sloc: cpp: 103,409; cs: 15,009; ansic: 5,273; python: 1,388; pascal: 337; objc: 121; xml: 100; sh: 86; makefile: 50
file content (48 lines) | stat: -rw-r--r-- 1,076 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#-*- coding: UTF-8 -*-

"""
Some fancy helper functions.
"""

import os
import ctypes
import sys
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)


def search_library():
    """Loads the assimp-Library.
    
    result (load-function, release-function)    
    exception AssimpError if no library is found
    
        """

    # silence 'DLL not found' message boxes on win
    try:
        ctypes.windll.kernel32.SetErrorMode(0x8007)
    except AttributeError:
        pass    

    libassimp = 'libassimp.so.3'
    LIBASSIMP = ctypes.CDLL(libassimp)

    try:
        load = LIBASSIMP.aiImportFile
        release = LIBASSIMP.aiReleaseImport
    except AttributeError:
        #OK, this is a library, but it has not the functions we need
        raise AssimpError, "assimp library not found"
    else:
        #Library found!
        load.restype = POINTER(structs.Scene)

    return(load, release, LIBASSIMP)