structs.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. #-*- coding: UTF-8 -*-
  2. """
  3. All ASSIMP C-structures. See the Assimp-headers for all formats.
  4. """
  5. from ctypes import POINTER, c_int, c_uint, c_char, c_float, Structure, c_char_p, c_double, c_ubyte
  6. class STRING(Structure):
  7. """
  8. Represents a String in ASSIMP.
  9. """
  10. #Maximum length of a string. See "MAXLEN" in "aiTypes.h"
  11. MAXLEN = 1024
  12. _fields_ = [
  13. #length of the string
  14. ("length", c_uint),
  15. #string data
  16. ("data", c_char*MAXLEN)
  17. ]
  18. class MATRIX4X4(Structure):
  19. """
  20. ASSIMP's 4x4-matrix
  21. """
  22. _fields_ = [
  23. #all the fields
  24. ("a1", c_float), ("a2", c_float), ("a3", c_float), ("a4", c_float),
  25. ("b1", c_float), ("b2", c_float), ("b3", c_float), ("b4", c_float),
  26. ("c1", c_float), ("c2", c_float), ("c3", c_float), ("c4", c_float),
  27. ("d1", c_float), ("d2", c_float), ("d3", c_float), ("d4", c_float),
  28. ]
  29. class NODE(Structure):
  30. """
  31. A node in the imported hierarchy.
  32. Each node has name, a parent node (except for the root node),
  33. a transformation relative to its parent and possibly several child nodes.
  34. Simple file formats don't support hierarchical structures, for these formats
  35. the imported scene does consist of only a single root node with no childs.
  36. """
  37. pass
  38. NODE._fields_ = [
  39. #The name of the node
  40. ("mName", STRING),
  41. #The transformation relative to the node's parent.
  42. ("aiMatrix4x4", MATRIX4X4),
  43. #Parent node. NULL if this node is the root node.
  44. ("mParent", POINTER(NODE)),
  45. #The number of child nodes of this node.
  46. ("mNumChildren", c_uint),
  47. #The child nodes of this node. NULL if mNumChildren is 0.
  48. ("mChildren", POINTER(POINTER(NODE))),
  49. #The number of meshes of this node.
  50. ("mNumMeshes", c_uint),
  51. #The meshes of this node. Each entry is an index into the mesh.
  52. ("mMeshes", POINTER(c_int))
  53. ]
  54. class VECTOR3D(Structure):
  55. """
  56. Represents a three-dimensional vector.
  57. """
  58. _fields_ = [
  59. ("x", c_float),
  60. ("y", c_float),
  61. ("z", c_float)
  62. ]
  63. class COLOR4D(Structure):
  64. """
  65. Represents a color in Red-Green-Blue space including an alpha component.
  66. """
  67. _fields_ = [
  68. ("r", c_float),
  69. ("g", c_float),
  70. ("b", c_float),
  71. ("a", c_float)
  72. ]
  73. class FACE(Structure):
  74. """
  75. A single face in a mesh, referring to multiple vertices.
  76. If mNumIndices is 3, the face is a triangle,
  77. for mNumIndices > 3 it's a polygon.
  78. Point and line primitives are rarely used and are NOT supported. However,
  79. a load could pass them as degenerated triangles.
  80. """
  81. _fields_ = [
  82. #Number of indices defining this face. 3 for a triangle, >3 for polygon
  83. ("mNumIndices", c_uint),
  84. #Pointer to the indices array. Size of the array is given in numIndices.
  85. ("mIndices", POINTER(c_uint))
  86. ]
  87. class VERTEXWEIGHT(Structure):
  88. """
  89. A single influence of a bone on a vertex.
  90. """
  91. _fields_ = [
  92. #Index of the vertex which is influenced by the bone.
  93. ("mVertexId", c_uint),
  94. #The strength of the influence in the range (0...1).
  95. #The influence from all bones at one vertex amounts to 1.
  96. ("mWeight", c_float)
  97. ]
  98. class BONE(Structure):
  99. """
  100. A single bone of a mesh. A bone has a name by which it can be found
  101. in the frame hierarchy and by which it can be addressed by animations.
  102. In addition it has a number of influences on vertices.
  103. """
  104. _fields_ = [
  105. #The name of the bone.
  106. ("mName", STRING),
  107. #The number of vertices affected by this bone
  108. ("mNumWeights", c_uint),
  109. #The vertices affected by this bone
  110. ("mWeights", POINTER(VERTEXWEIGHT)),
  111. #Matrix that transforms from mesh space to bone space in bind pose
  112. ("mOffsetMatrix", MATRIX4X4)
  113. ]
  114. class MESH(Structure):
  115. """
  116. A mesh represents a geometry or model with a single material.
  117. It usually consists of a number of vertices and a series of primitives/faces
  118. referencing the vertices. In addition there might be a series of bones, each
  119. of them addressing a number of vertices with a certain weight. Vertex data
  120. is presented in channels with each channel containing a single per-vertex
  121. information such as a set of texture coords or a normal vector.
  122. If a data pointer is non-null, the corresponding data stream is present.
  123. A Mesh uses only a single material which is referenced by a material ID.
  124. """
  125. #Maximum number of texture coord sets (UV(W) channels) per mesh.
  126. #See "AI_MAX_NUMBER_OF_TEXTURECOORDS" in "aiMesh.h" for further
  127. #information.
  128. AI_MAX_NUMBER_OF_TEXTURECOORDS = 4
  129. #Maximum number of vertex color sets per mesh.
  130. #Normally: Diffuse, specular, ambient and emissive
  131. #However one could use the vertex color sets for any other purpose, too.
  132. AI_MAX_NUMBER_OF_COLOR_SETS = 4
  133. _fields_ = [
  134. #The number of vertices in this mesh.
  135. #This is also the size of all of the per-vertex data arrays
  136. ("mNumVertices", c_uint), #OK
  137. #The number of primitives (triangles, polygones, lines) in this mesh.
  138. #This is also the size of the mFaces array
  139. ("mNumFaces", c_uint),
  140. #Vertex positions.
  141. #This array is always present in a mesh. The array is
  142. #mNumVertices in size.
  143. ("mVertices", POINTER(VECTOR3D)), #OK
  144. #Vertex normals.
  145. #The array contains normalized vectors, NULL if not present.
  146. #The array is mNumVertices in size.
  147. ("mNormals", POINTER(VECTOR3D)), #OK
  148. #Vertex tangents.
  149. #The tangent of a vertex points in the direction of the positive
  150. #X texture axis. The array contains normalized vectors, NULL if
  151. #not present. The array is mNumVertices in size.
  152. #@note If the mesh contains tangents, it automatically also
  153. #contains bitangents.
  154. ("mTangents", POINTER(VECTOR3D)), #OK
  155. #Vertex bitangents.
  156. #The bitangent of a vertex points in the direction of the positive
  157. #Y texture axis. The array contains normalized vectors, NULL if not
  158. #present. The array is mNumVertices in size.
  159. #@note If the mesh contains tangents, it automatically also contains
  160. #bitangents.
  161. ("mBitangents", POINTER(VECTOR3D)), #OK
  162. #Vertex color sets.
  163. #A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex
  164. #colors per vertex. NULL if not present. Each array is
  165. #mNumVertices in size if present.
  166. ("mColors", POINTER(COLOR4D)*AI_MAX_NUMBER_OF_COLOR_SETS), #OK
  167. #Vertex texture coords, also known as UV channels.
  168. #A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per
  169. #vertex. NULL if not present. The array is mNumVertices in size.
  170. ("mTextureCoords", POINTER(VECTOR3D)*AI_MAX_NUMBER_OF_TEXTURECOORDS),#OK
  171. #Specifies the number of components for a given UV channel.
  172. #Up to three channels are supported (UVW, for accessing volume
  173. #or cube maps). If the value is 2 for a given channel n, the
  174. #component p.z of mTextureCoords[n][p] is set to 0.0f.
  175. #If the value is 1 for a given channel, p.y is set to 0.0f, too.
  176. #@note 4D coords are not supported
  177. ("mNumUVComponents", c_uint*AI_MAX_NUMBER_OF_TEXTURECOORDS), #OK
  178. #The faces the mesh is contstructed from.
  179. #Each face referres to a number of vertices by their indices.
  180. #This array is always present in a mesh, its size is given
  181. #in mNumFaces.
  182. ("mFaces", POINTER(FACE)),
  183. #The number of bones this mesh contains.
  184. #Can be 0, in which case the mBones array is NULL.
  185. ("mNumBones", c_uint),
  186. #The bones of this mesh.
  187. #A bone consists of a name by which it can be found in the
  188. #frame hierarchy and a set of vertex weights.
  189. ("mBones", POINTER(POINTER(BONE))),
  190. #The material used by this mesh.
  191. #A mesh does use only a single material. If an imported model uses
  192. #multiple materials, the import splits up the mesh. Use this value
  193. #as index into the scene's material list.
  194. ("mMaterialIndex", c_uint) #OK
  195. ]
  196. class MATERIALPROPERTY(Structure):
  197. """
  198. Data structure for a single property inside a material.
  199. """
  200. _fields_ = [
  201. #Specifies the name of the property (key)
  202. #Keys are case insensitive.
  203. ("mKey", STRING),
  204. #Size of the buffer mData is pointing to, in bytes
  205. #This value may not be 0.
  206. ("mDataLength", c_uint),
  207. #Type information for the property.
  208. #Defines the data layout inside the
  209. #data buffer. This is used by the library
  210. #internally to perform debug checks.
  211. #THIS IS AN ENUM!
  212. ("mType", c_int),
  213. #Binary buffer to hold the property's value
  214. #The buffer has no terminal character. However,
  215. #if a string is stored inside it may use 0 as terminal,
  216. #but it would be contained in mDataLength. This member
  217. #is never 0
  218. ("mData", c_char_p)
  219. ]
  220. class MATERIAL(Structure):
  221. """
  222. Data structure for a material.
  223. Material data is stored using a key-value structure, called property
  224. (to guarant that the system is maximally flexible).
  225. The library defines a set of standard keys (AI_MATKEY) which should be
  226. enough for nearly all purposes.
  227. """
  228. _fields_ = [
  229. #List of all material properties loaded.
  230. ("mProperties", POINTER(POINTER(MATERIALPROPERTY))),
  231. #Number of properties loaded
  232. ("mNumProperties", c_uint),
  233. ("mNumAllocated", c_uint)
  234. ]
  235. class VECTORKEY(Structure):
  236. """
  237. A time-value pair specifying a certain 3D vector for the given time.
  238. """
  239. _fields_ = [
  240. #The time of this key
  241. ("mTime", c_double),
  242. #The value of this key
  243. ("mValue", VECTOR3D)
  244. ]
  245. class QUATERNION(Structure):
  246. """
  247. Represents a quaternion in a 4D vector.
  248. """
  249. _fields = [
  250. #the components
  251. ("w", c_float),
  252. ("x", c_float),
  253. ("y", c_float),
  254. ("z", c_float)
  255. ]
  256. class QUATKEY(Structure):
  257. """
  258. A time-value pair specifying a rotation for the given time. For joint
  259. animations the rotation is usually expressed using a quaternion.
  260. """
  261. _fields_ = [
  262. #The time of this key
  263. ("mTime", c_double),
  264. #The value of this key
  265. ("mValue", QUATERNION)
  266. ]
  267. class BONEANIM(Structure):
  268. """
  269. Describes the animation of a single node. The name specifies the bone/node
  270. which is affected by this animation channel. The keyframes are given in
  271. three separate series of values, one each for position, rotation and
  272. scaling.
  273. NOTE: The name "BoneAnim" is misleading. This structure is also used to
  274. describe the animation of regular nodes on the node graph. They needn't be
  275. nodes.
  276. """
  277. _fields_ = [
  278. #The name of the bone affected by this animation.
  279. ("mBoneName", STRING),
  280. #The number of position keys
  281. ("mNumPositionKeys", c_uint),
  282. #The position keys of this animation channel. Positions are
  283. #specified as 3D vector. The array is mNumPositionKeys in size.
  284. ("mPositionKeys", POINTER(VECTORKEY)),
  285. #The number of rotation keys
  286. ("mNumRotationKeys", c_uint),
  287. #The rotation keys of this animation channel. Rotations are given as
  288. #quaternions, which are 4D vectors. The array is mNumRotationKeys in
  289. #size.
  290. ("mRotationKeys", POINTER(QUATKEY)),
  291. #The number of scaling keys
  292. ("mNumScalingKeys", c_uint),
  293. #The scaling keys of this animation channel. Scalings are specified
  294. #as 3D vector. The array is mNumScalingKeys in size.
  295. ("mScalingKeys", POINTER(VECTORKEY))
  296. ]
  297. class ANIMATION(Structure):
  298. """
  299. An animation consists of keyframe data for a number of bones.
  300. For each bone affected by the animation a separate series of data is given.
  301. """
  302. _fields_ = [
  303. #The name of the animation. If the modelling package this data was
  304. #exported from does support only a single animation channel, this
  305. #name is usually empty (length is zero).
  306. ("mName", STRING),
  307. #Duration of the animation in ticks.
  308. ("mDuration", c_double),
  309. #Ticks per second. 0 if not specified in the imported file
  310. ("mTicksPerSecond", c_double),
  311. #The number of bone animation channels. Each channel affects a
  312. #single bone.
  313. ("mNumBones", c_uint),
  314. #The bone animation channels. Each channel affects a single bone.
  315. #The array is mNumBones in size.
  316. ("mBones", POINTER(POINTER(BONEANIM)))
  317. ]
  318. class TEXEL(Structure):
  319. """
  320. Helper structure to represent a texel in ARGB8888 format
  321. """
  322. _fields_ = [
  323. ("b", c_ubyte),
  324. ("g", c_ubyte),
  325. ("r", c_ubyte),
  326. ("a", c_ubyte)
  327. ]
  328. class TEXTURE(Structure):
  329. """
  330. Helper structure to describe an embedded texture
  331. Normally textures are contained in external files but some file formats
  332. do embedd them.
  333. """
  334. _fields_ = [
  335. #Width of the texture, in pixels
  336. #If mHeight is zero the texture is compressed in a format
  337. #like JPEG. In this case mWidth specifies the size of the
  338. #memory area pcData is pointing to, in bytes.
  339. ("mWidth", c_uint),
  340. #Height of the texture, in pixels
  341. #If this value is zero, pcData points to an compressed texture
  342. #in an unknown format (e.g. JPEG).
  343. ("mHeight", c_uint),
  344. #A hint from the loader to make it easier for applications
  345. #to determine the type of embedded compressed textures.
  346. #If mHeight != 0 this member is undefined. Otherwise it
  347. #will be set to '\0\0\0\0' if the loader has no additional
  348. #information about the texture file format used OR the
  349. #file extension of the format without a leading dot.
  350. #E.g. 'dds\0', 'pcx\0'. All characters are lower-case.
  351. ("achFormatHint", c_char*4),
  352. #Data of the texture.
  353. #Points to an array of mWidth * mHeight aiTexel's.
  354. #The format of the texture data is always ARGB8888 to
  355. #make the implementation for user of the library as easy
  356. #as possible. If mHeight = 0 this is a pointer to a memory
  357. #buffer of size mWidth containing the compressed texture
  358. #data. Good luck, have fun!
  359. ("pcData", POINTER(TEXEL))
  360. ]
  361. class SCENE(Structure):
  362. """
  363. The root structure of the imported data.
  364. Everything that was imported from the given file can be accessed from here.
  365. """
  366. _fields_ = [
  367. #Any combination of the AI_SCENE_FLAGS_XXX flags
  368. ("flags", c_uint), #OK
  369. #The root node of the hierarchy.
  370. #There will always be at least the root node if the import
  371. #was successful. Presence of further nodes depends on the
  372. #format and content of the imported file.
  373. ("mRootNode", POINTER(NODE)),
  374. #The number of meshes in the scene.
  375. ("mNumMeshes", c_uint), #OK
  376. #The array of meshes.
  377. #Use the indices given in the aiNode structure to access
  378. #this array. The array is mNumMeshes in size.
  379. ("mMeshes", POINTER(POINTER(MESH))), #OK
  380. #The number of materials in the scene.
  381. ("mNumMaterials", c_uint),
  382. #The array of materials.
  383. #Use the index given in each aiMesh structure to access this
  384. #array. The array is mNumMaterials in size.
  385. ("mMaterials", POINTER(POINTER(MATERIAL))),
  386. #The number of animations in the scene.
  387. ("mNumAnimations", c_uint),
  388. #The array of animations.
  389. #All animations imported from the given file are listed here.
  390. #The array is mNumAnimations in size.
  391. ("mAnimations", POINTER(POINTER(ANIMATION))),
  392. #The number of textures embedded into the file
  393. ("mNumTextures", c_uint),
  394. #The array of embedded textures.
  395. #Not many file formats embedd their textures into the file.
  396. #An example is Quake's MDL format (which is also used by
  397. #some GameStudio(TM) versions)
  398. ("mTextures", POINTER(POINTER(TEXTURE)))
  399. ]