From d7bc843ae6e66f0c2ba7d94d35a919b54d0f9a82 Mon Sep 17 00:00:00 2001 From: sebastianhempel Date: Thu, 18 Sep 2008 12:45:03 +0000 Subject: [PATCH] texture coordinates git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@149 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- port/PyAssimp/pyassimp/pyassimp.py | 28 ++++++++++++++++++++++++++-- port/PyAssimp/pyassimp/structs.py | 6 +++--- port/PyAssimp/sample.py | 9 +++++++-- 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/port/PyAssimp/pyassimp/pyassimp.py b/port/PyAssimp/pyassimp/pyassimp.py index 55ae53be5..9b3e7170d 100644 --- a/port/PyAssimp/pyassimp/pyassimp.py +++ b/port/PyAssimp/pyassimp/pyassimp.py @@ -156,8 +156,14 @@ class Mesh(AssimpBase): #vertex color sets self.colors = self._load_colors(mesh) - #number of texture coordinates - self.numuv = self._load_uv_component_count(mesh) #FIXME + #number of coordinates per uv-channel + self.uvsize = self._load_uv_component_count(mesh) + + #number of uv channels + self.texcoords = self._load_texture_coords(mesh) + + #the used material + self.material_index = mesh.mMaterialIndex def _load_uv_component_count(self, mesh): @@ -172,6 +178,24 @@ class Mesh(AssimpBase): for i in range(structs.MESH.AI_MAX_NUMBER_OF_TEXTURECOORDS)) + def _load_texture_coords(self, mesh): + """ + Loads texture coordinates. + + mesh - mesh-data + + result texture coordinates + """ + result = [] + + 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))) + + return result + + def _load_colors(self, mesh): """ Loads color sets. diff --git a/port/PyAssimp/pyassimp/structs.py b/port/PyAssimp/pyassimp/structs.py index 0a7494602..a29d32080 100644 --- a/port/PyAssimp/pyassimp/structs.py +++ b/port/PyAssimp/pyassimp/structs.py @@ -224,7 +224,7 @@ class MESH(Structure): #Vertex texture coords, also known as UV channels. #A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per #vertex. NULL if not present. The array is mNumVertices in size. - ("mTextureCoords", POINTER(VECTOR3D)*AI_MAX_NUMBER_OF_TEXTURECOORDS), + ("mTextureCoords", POINTER(VECTOR3D)*AI_MAX_NUMBER_OF_TEXTURECOORDS),#OK #Specifies the number of components for a given UV channel. #Up to three channels are supported (UVW, for accessing volume @@ -232,7 +232,7 @@ class MESH(Structure): #component p.z of mTextureCoords[n][p] is set to 0.0f. #If the value is 1 for a given channel, p.y is set to 0.0f, too. #@note 4D coords are not supported - ("mNumUVComponents", c_uint*AI_MAX_NUMBER_OF_TEXTURECOORDS), + ("mNumUVComponents", c_uint*AI_MAX_NUMBER_OF_TEXTURECOORDS), #OK #The faces the mesh is contstructed from. #Each face referres to a number of vertices by their indices. @@ -253,7 +253,7 @@ class MESH(Structure): #A mesh does use only a single material. If an imported model uses #multiple materials, the import splits up the mesh. Use this value #as index into the scene's material list. - ("mMaterialIndex", c_uint) + ("mMaterialIndex", c_uint) #OK ] diff --git a/port/PyAssimp/sample.py b/port/PyAssimp/sample.py index 386329205..bd8b9bdb1 100644 --- a/port/PyAssimp/sample.py +++ b/port/PyAssimp/sample.py @@ -11,7 +11,7 @@ import os #get a model out of assimp's test-data MODEL = os.path.join(os.path.dirname(__file__), "..", "..", - "test", "ASEFiles", "MotionCaptureROM.ase") + "test", "3DSFiles", "test1.3ds") def main(): scene = pyassimp.load(MODEL) @@ -31,7 +31,12 @@ def main(): print " vertices:", len(mesh.vertices) print " first:", mesh.vertices[:3] print " colors:", len(mesh.colors) - print " uv-counts:", mesh.numuv + tc = mesh.texcoords + print " texture-coords 1:", len(tc[0]), "first:", tc[0][:3] + print " texture-coords 2:", len(tc[1]), "first:", tc[1][:3] + 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