new helper module; faces
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@150 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/1/head
parent
d7bc843ae6
commit
b50b8b3f43
|
@ -0,0 +1,12 @@
|
|||
#-*- coding: UTF-8 -*-
|
||||
|
||||
"""
|
||||
Some fancy helper functions.
|
||||
"""
|
||||
|
||||
|
||||
def vec2tuple(x):
|
||||
"""
|
||||
Converts a VECTOR3D to a Tuple
|
||||
"""
|
||||
return (x.x, x.y, x.z)
|
|
@ -9,7 +9,7 @@ This is the main-module of PyAssimp.
|
|||
import structs
|
||||
import ctypes
|
||||
import os
|
||||
from ctypes import POINTER, c_int, c_uint, c_double, c_char, c_float
|
||||
import helper
|
||||
|
||||
|
||||
#get the assimp path
|
||||
|
@ -25,6 +25,8 @@ class AssimpError(BaseException):
|
|||
|
||||
|
||||
class AssimpLib(object):
|
||||
from ctypes import POINTER
|
||||
|
||||
#open library
|
||||
_dll = ctypes.cdll.LoadLibrary(LIBRARY)
|
||||
|
||||
|
@ -103,6 +105,27 @@ class Scene(AssimpBase):
|
|||
if (key & self.flags)>0]
|
||||
|
||||
|
||||
class Face(AssimpBase):
|
||||
"""
|
||||
A single face in a mesh, referring to multiple vertices.
|
||||
If the number of indices is 3, the face is a triangle,
|
||||
for more than 3 it is a polygon.
|
||||
|
||||
Point and line primitives are rarely used and are NOT supported. However,
|
||||
a load could pass them as degenerated triangles.
|
||||
"""
|
||||
|
||||
def __init__(self, face):
|
||||
"""
|
||||
Loads a face from raw-data.
|
||||
"""
|
||||
self.indices = [face.mIndices[i] for i in range(face.mNumIndices)]
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return str(self.indices)
|
||||
|
||||
|
||||
class Mesh(AssimpBase):
|
||||
"""
|
||||
A mesh represents a geometry or model with a single material.
|
||||
|
@ -130,28 +153,25 @@ class Mesh(AssimpBase):
|
|||
|
||||
mesh - raw mesh-data
|
||||
"""
|
||||
#converts a VECTOR3D-struct to a tuple
|
||||
vec2tuple = lambda x: (x.x, x.y, x.z)
|
||||
|
||||
#load vertices
|
||||
self.vertices = self._load_array(mesh.mVertices,
|
||||
mesh.mNumVertices,
|
||||
vec2tuple)
|
||||
helper.vec2tuple)
|
||||
|
||||
#load normals
|
||||
self.normals = self._load_array(mesh.mNormals,
|
||||
mesh.mNumVertices,
|
||||
vec2tuple)
|
||||
helper.vec2tuple)
|
||||
|
||||
#load tangents
|
||||
self.tangents = self._load_array(mesh.mTangents,
|
||||
mesh.mNumVertices,
|
||||
vec2tuple)
|
||||
helper.vec2tuple)
|
||||
|
||||
#load bitangents
|
||||
self.bitangents = self._load_array(mesh.mBitangents,
|
||||
mesh.mNumVertices,
|
||||
vec2tuple)
|
||||
helper.vec2tuple)
|
||||
|
||||
#vertex color sets
|
||||
self.colors = self._load_colors(mesh)
|
||||
|
@ -163,7 +183,21 @@ class Mesh(AssimpBase):
|
|||
self.texcoords = self._load_texture_coords(mesh)
|
||||
|
||||
#the used material
|
||||
self.material_index = mesh.mMaterialIndex
|
||||
self.material_index = int(mesh.mMaterialIndex)
|
||||
|
||||
#faces
|
||||
self.faces = self._load_faces(mesh)
|
||||
|
||||
|
||||
def _load_faces(self, mesh):
|
||||
"""
|
||||
Loads all faces.
|
||||
|
||||
mesh - mesh-data
|
||||
|
||||
result faces
|
||||
"""
|
||||
return [Face(mesh.mFaces[i]) for i in range(mesh.mNumFaces)]
|
||||
|
||||
|
||||
def _load_uv_component_count(self, mesh):
|
||||
|
@ -191,7 +225,7 @@ class Mesh(AssimpBase):
|
|||
for i in range(structs.MESH.AI_MAX_NUMBER_OF_TEXTURECOORDS):
|
||||
result.append(self._load_array(mesh.mTextureCoords[i],
|
||||
mesh.mNumVertices,
|
||||
lambda x: (x.x, x.y, x.z)))
|
||||
helper.vec2tuple))
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ All ASSIMP C-structures. See the Assimp-headers for all formats.
|
|||
from ctypes import POINTER, c_int, c_uint, c_char, c_float, Structure, c_char_p, c_double, c_ubyte
|
||||
|
||||
|
||||
|
||||
class STRING(Structure):
|
||||
"""
|
||||
Represents a String in ASSIMP.
|
||||
|
@ -111,10 +112,10 @@ class FACE(Structure):
|
|||
|
||||
_fields_ = [
|
||||
#Number of indices defining this face. 3 for a triangle, >3 for polygon
|
||||
("mNumIndices", c_uint),
|
||||
("mNumIndices", c_uint), #OK
|
||||
|
||||
#Pointer to the indices array. Size of the array is given in numIndices.
|
||||
("mIndices", POINTER(c_uint))
|
||||
("mIndices", POINTER(c_uint)) #OK
|
||||
]
|
||||
|
||||
|
||||
|
@ -187,7 +188,7 @@ class MESH(Structure):
|
|||
|
||||
#The number of primitives (triangles, polygones, lines) in this mesh.
|
||||
#This is also the size of the mFaces array
|
||||
("mNumFaces", c_uint),
|
||||
("mNumFaces", c_uint), #OK
|
||||
|
||||
#Vertex positions.
|
||||
#This array is always present in a mesh. The array is
|
||||
|
@ -238,7 +239,7 @@ class MESH(Structure):
|
|||
#Each face referres to a number of vertices by their indices.
|
||||
#This array is always present in a mesh, its size is given
|
||||
#in mNumFaces.
|
||||
("mFaces", POINTER(FACE)),
|
||||
("mFaces", POINTER(FACE)), #OK
|
||||
|
||||
#The number of bones this mesh contains.
|
||||
#Can be 0, in which case the mBones array is NULL.
|
||||
|
|
|
@ -37,6 +37,7 @@ def main():
|
|||
print " texture-coords 3:", len(tc[2]), "first:", tc[2][:3]
|
||||
print " texture-coords 4:", len(tc[3]), "first:", tc[3][:3]
|
||||
print " uv-counts:", mesh.uvsize
|
||||
print " faces:", len(mesh.faces), "first:", mesh.faces[:3]
|
||||
print
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue