aiMaterial.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /** @file Defines the material system of the library
  2. *
  3. */
  4. #ifndef AI_MATERIAL_H_INC
  5. #define AI_MATERIAL_H_INC
  6. #include "aiTypes.h"
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. // ---------------------------------------------------------------------------
  11. /** Defines type identifiers for use within the material system.
  12. *
  13. */
  14. // ---------------------------------------------------------------------------
  15. enum aiPropertyTypeInfo
  16. {
  17. /** Array of single-precision floats
  18. */
  19. aiPTI_Float = 0x1,
  20. /** aiString data structure
  21. */
  22. aiPTI_String = 0x3,
  23. /** Array of Integers
  24. */
  25. aiPTI_Integer = 0x4,
  26. /** Simple binary buffer
  27. */
  28. aiPTI_Buffer = 0x5,
  29. };
  30. // ---------------------------------------------------------------------------
  31. /** Defines algorithms for generating UVW-coords (for texture sampling)
  32. * procedurally.
  33. */
  34. // ---------------------------------------------------------------------------
  35. enum aiTexUVWGen
  36. {
  37. /** The view vector will be reflected to a pixel's normal.
  38. *
  39. * The result is used as UVW-coordinate for
  40. * accessing a cubemap
  41. */
  42. aiTexUVWGen_VIEWREFLEFT = 0x800001,
  43. /** The view vector will be used as UVW-src
  44. *
  45. * The view vector is used as UVW-coordinate for
  46. * accessing a cubemap
  47. */
  48. aiTexUVWGen_VIEW = 0x800002,
  49. /** The view vector will be refracted to the pixel's normal.
  50. *
  51. * If this is used, the refraction index to be applied should
  52. * also be contained in the material description.
  53. * The result is used as UVW-coordinate for
  54. * accessing a cubemap.
  55. */
  56. aiTexUVWGen_VIEWREFRACT = 0x800003
  57. };
  58. // ---------------------------------------------------------------------------
  59. /** Defines all shading models supported by the library
  60. *
  61. * @note The list of shading modes has been taken from Blender3D.
  62. * See Blender3D documentation for more information. The API does
  63. * not distinguish between "specular" and "diffuse" shaders (thus the
  64. * specular term for diffuse shading models like Oren-Nayar remains
  65. * undefined)
  66. */
  67. // ---------------------------------------------------------------------------
  68. enum aiShadingMode
  69. {
  70. /** Flat shading. Shading is done on per-face base,
  71. * diffuse only.
  72. */
  73. aiShadingMode_Flat = 0x1,
  74. /** Diffuse gouraud shading. Shading on per-vertex base
  75. */
  76. aiShadingMode_Gouraud = 0x2,
  77. /** Diffuse/Specular Phong-Shading
  78. *
  79. * Shading is applied on per-pixel base. This is the
  80. * slowest algorithm, but generates the best results.
  81. */
  82. aiShadingMode_Phong = 0x3,
  83. /** Diffuse/Specular Phong-Blinn-Shading
  84. *
  85. * Shading is applied on per-pixel base. This is a little
  86. * bit faster than phong and in some cases even
  87. * more realistic
  88. */
  89. aiShadingMode_Blinn = 0x4,
  90. /** Toon-Shading per pixel
  91. *
  92. * Shading is applied on per-pixel base. The output looks
  93. * like a comic. Often combined with edge detection.
  94. */
  95. aiShadingMode_Toon = 0x5,
  96. /** OrenNayar-Shading per pixel
  97. *
  98. * Extension to standard lambertian shading, taking the
  99. * roughness of the material into account
  100. *
  101. */
  102. aiShadingMode_OrenNayar = 0x6,
  103. /** Minnaert-Shading per pixel
  104. *
  105. * Extension to standard lambertian shading, taking the
  106. * "darkness" of the material into account
  107. */
  108. aiShadingMode_Minnaert = 0x7,
  109. /** CookTorrance-Shading per pixel
  110. */
  111. aiShadingMode_CookTorrance = 0x8,
  112. /** No shading at all
  113. */
  114. aiShadingMode_NoShading = 0x8
  115. };
  116. // ---------------------------------------------------------------------------
  117. /** Data structure for a single property inside a material
  118. *
  119. * @see aiMaterial
  120. */
  121. // ---------------------------------------------------------------------------
  122. struct aiMaterialProperty
  123. {
  124. /** Specifies the name of the property (key)
  125. *
  126. * Keys are case insensitive.
  127. */
  128. aiString* mKey;
  129. /** Size of the buffer mData is pointing to, in bytes
  130. */
  131. unsigned int mDataLength;
  132. /** Type information for the property.
  133. *
  134. * Defines the data layout inside the
  135. * data buffer. This is used by the library
  136. * internally to perform debug checks.
  137. */
  138. aiPropertyTypeInfo mType;
  139. /** Binary buffer to hold the property's value
  140. *
  141. * The buffer has no terminal character. However,
  142. * if a string is stored inside it may use 0 as terminal,
  143. * but it would be contained in mDataLength.
  144. */
  145. char* mData;
  146. };
  147. // ---------------------------------------------------------------------------
  148. /** Data structure for a material
  149. *
  150. * Material data is stored using a key-value structure, called property
  151. * (to guarant that the system is maximally flexible).
  152. * The library defines a set of standard keys, which should be enough
  153. * for nearly all purposes.
  154. */
  155. // ---------------------------------------------------------------------------
  156. #ifdef __cplusplus
  157. class aiMaterial
  158. {
  159. protected:
  160. aiMaterial() {}
  161. public:
  162. #else
  163. struct aiMaterial
  164. {
  165. #endif // __cplusplus
  166. /** List of all material properties loaded.
  167. */
  168. aiMaterialProperty** mProperties;
  169. /** Number of properties loaded
  170. */
  171. unsigned int mNumProperties;
  172. unsigned int mNumAllocated;
  173. };
  174. // ---------------------------------------------------------------------------
  175. /** @def AI_MATKEY_NAME
  176. * Defines the name of the material (aiString)
  177. */
  178. #define AI_MATKEY_NAME "$mat.name"
  179. /** @def AI_MATKEY_SHADING_MODE
  180. * Defines the shading model to use (aiShadingMode)
  181. */
  182. #define AI_MATKEY_SHADING_MODEL "$mat.shadingm"
  183. /** @def AI_MATKEY_OPACITY
  184. * Defines the base opacity of the material
  185. */
  186. #define AI_MATKEY_OPACITY "$mat.opacity"
  187. /** @def AI_MATKEY_BUMPSCALING
  188. * Defines the height scaling of a bump map (for stuff like Parallax
  189. * Occlusion Mapping)
  190. */
  191. #define AI_MATKEY_BUMPSCALING "$mat.bumpscaling"
  192. /** @def AI_MATKEY_SHININESS
  193. * Defines the base shininess of the material
  194. */
  195. #define AI_MATKEY_SHININESS "$mat.shininess"
  196. /** @def AI_MATKEY_COLOR_DIFFUSE
  197. * Defines the diffuse base color of the material
  198. */
  199. #define AI_MATKEY_COLOR_DIFFUSE "$clr.diffuse"
  200. /** @def AI_MATKEY_COLOR_AMBIENT
  201. * Defines the ambient base color of the material
  202. */
  203. #define AI_MATKEY_COLOR_AMBIENT "$clr.ambient"
  204. /** @def AI_MATKEY_COLOR_SPECULAR
  205. * Defines the specular base color of the material
  206. */
  207. #define AI_MATKEY_COLOR_SPECULAR "$clr.specular"
  208. /** @def AI_MATKEY_COLOR_EMISSIVE
  209. * Defines the emissive base color of the material
  210. */
  211. #define AI_MATKEY_COLOR_EMISSIVE "$clr.emissive"
  212. /** @def AI_MATKEY_TEXTURE_DIFFUSE
  213. * Defines a specified diffuse texture channel of the material
  214. */
  215. #define AI_MATKEY_TEXTURE_DIFFUSE(N) "$tex.file.diffuse["#N"]"
  216. #define AI_MATKEY_TEXTURE_DIFFUSE_ "$tex.file.diffuse"
  217. /** @def AI_MATKEY_TEXTURE_AMBIENT
  218. * Defines a specified ambient texture channel of the material
  219. */
  220. #define AI_MATKEY_TEXTURE_AMBIENT(N) "$tex.file.ambient["#N"]"
  221. #define AI_MATKEY_TEXTURE_AMBIENT_ "$tex.file.ambient"
  222. /** @def AI_MATKEY_TEXTURE_SPECULAR
  223. * Defines a specified specular texture channel of the material
  224. */
  225. #define AI_MATKEY_TEXTURE_SPECULAR(N) "$tex.file.specular["#N"]"
  226. #define AI_MATKEY_TEXTURE_SPECULAR_ "$tex.file.specular"
  227. /** @def AI_MATKEY_TEXTURE_EMISSIVE
  228. * Defines a specified emissive texture channel of the material
  229. */
  230. #define AI_MATKEY_TEXTURE_EMISSIVE(N) "$tex.file.emissive["#N"]"
  231. #define AI_MATKEY_TEXTURE_EMISSIVE_ "$tex.file.emissive"
  232. /** @def AI_MATKEY_TEXTURE_NORMALS
  233. * Defines a specified normal texture channel of the material
  234. */
  235. #define AI_MATKEY_TEXTURE_NORMALS(N) "$tex.file.normals["#N"]"
  236. #define AI_MATKEY_TEXTURE_NORMALS_ "$tex.file.normals"
  237. /** @def AI_MATKEY_TEXTURE_BUMP
  238. * Defines a specified bumpmap texture (=heightmap) channel of the material
  239. * This is very similar to #AI_MATKEY_TEXTURE_NORMALS. It is provided
  240. * to allow applications to determine whether the input data for
  241. * normal mapping is already a normal map or needs to be converted to
  242. * a heightmap.
  243. */
  244. #define AI_MATKEY_TEXTURE_BUMP(N) "$tex.file.bump["#N"]"
  245. #define AI_MATKEY_TEXTURE_BUMP_ "$tex.file.bump"
  246. /** @def AI_MATKEY_TEXTURE_SHININESS
  247. * Defines a specified shininess texture channel of the material
  248. */
  249. #define AI_MATKEY_TEXTURE_SHININESS(N) "$tex.file.shininess["#N"]"
  250. #define AI_MATKEY_TEXTURE_SHININESS_ "$tex.file.shininess"
  251. /** @def AI_MATKEY_TEXTURE_OPACITY
  252. * Defines a specified opacity texture channel of the material
  253. */
  254. #define AI_MATKEY_TEXTURE_OPACITY(N) "$tex.file.opacity["#N"]"
  255. #define AI_MATKEY_TEXTURE_OPACITY_ "$tex.file.opacity"
  256. #define AI_MATKEY_TEXOP_DIFFUSE(N) "$tex.op.diffuse["#N"]"
  257. #define AI_MATKEY_TEXOP_AMBIENT(N) "$tex.op.ambient["#N"]"
  258. #define AI_MATKEY_TEXOP_SPECULAR(N) "$tex.op.specular["#N"]"
  259. #define AI_MATKEY_TEXOP_EMISSIVE(N) "$tex.op.emissive["#N"]"
  260. #define AI_MATKEY_TEXOP_NORMALS(N) "$tex.op.normals["#N"]"
  261. #define AI_MATKEY_TEXOP_BUMP(N) "$tex.op.bump["#N"]"
  262. #define AI_MATKEY_TEXOP_SHININESS(N) "$tex.op.shininess["#N"]"
  263. #define AI_MATKEY_TEXOP_OPACITY(N) "$tex.op.opacity["#N"]"
  264. #define AI_MATKEY_UVWSRC_DIFFUSE(N) "$tex.uvw.diffuse["#N"]"
  265. #define AI_MATKEY_UVWSRC_AMBIENT(N) "$tex.uvw.ambient["#N"]"
  266. #define AI_MATKEY_UVWSRC_SPECULAR(N) "$tex.uvw.specular["#N"]"
  267. #define AI_MATKEY_UVWSRC_EMISSIVE(N) "$tex.uvw.emissive["#N"]"
  268. #define AI_MATKEY_UVWSRC_NORMALS(N) "$tex.uvw.normals["#N"]"
  269. #define AI_MATKEY_UVWSRC_BUMP(N) "$tex.uvw.bump["#N"]"
  270. #define AI_MATKEY_UVWSRC_SHININESS(N) "$tex.uvw.shininess["#N"]"
  271. #define AI_MATKEY_UVWSRC_OPACITY(N) "$tex.uvw.opacity["#N"]"
  272. #define AI_MATKEY_REFRACTI_DIFFUSE(N) "$tex.refracti.diffuse["#N"]"
  273. #define AI_MATKEY_REFRACTI_AMBIENT(N) "$tex.refracti.ambient["#N"]"
  274. #define AI_MATKEY_REFRACTI_SPECULAR(N) "$tex.refracti.specular["#N"]"
  275. #define AI_MATKEY_REFRACTI_EMISSIVE(N) "$tex.refracti.emissive["#N"]"
  276. #define AI_MATKEY_REFRACTI_NORMALS(N) "$tex.refracti.normals["#N"]"
  277. #define AI_MATKEY_REFRACTI_BUMP(N) "$tex.refracti.bump["#N"]"
  278. #define AI_MATKEY_REFRACTI_SHININESS(N) "$tex.refracti.shininess["#N"]"
  279. #define AI_MATKEY_REFRACTI_OPACITY(N) "$tex.refracti.opacity["#N"]"
  280. #define AI_MATKEY_TEXBLEND_DIFFUSE(N) "$tex.blend.diffuse["#N"]"
  281. #define AI_MATKEY_TEXBLEND_AMBIENT(N) "$tex.blend.ambient["#N"]"
  282. #define AI_MATKEY_TEXBLEND_SPECULAR(N) "$tex.blend.specular["#N"]"
  283. #define AI_MATKEY_TEXBLEND_EMISSIVE(N) "$tex.blend.emissive["#N"]"
  284. #define AI_MATKEY_TEXBLEND_NORMALS(N) "$tex.blend.normals["#N"]"
  285. #define AI_MATKEY_TEXBLEND_BUMP(N) "$tex.blend.bump["#N"]"
  286. #define AI_MATKEY_TEXBLEND_SHININESS(N) "$tex.blend.shininess["#N"]"
  287. #define AI_MATKEY_TEXBLEND_OPACITY(N) "$tex.blend.opacity["#N"]"
  288. #define AI_MATKEY_ORENNAYAR_ROUGHNESS "$shading.orennayar.roughness"
  289. #define AI_MATKEY_MINNAERT_DARKNESS "$shading.minnaert.darkness"
  290. #define AI_MATKEY_COOK_TORRANCE_REFRACTI "$shading.cookt.refracti"
  291. #define AI_MATKEY_COOK_TORRANCE_PARAM "$shading.cookt.param"
  292. /** @def AI_MATKEY_GLOBAL_BACKGROUND_IMAGE
  293. * Global property defined by some loaders. Contains the path to
  294. * the image file to be used as background image.
  295. */
  296. #define AI_MATKEY_GLOBAL_BACKGROUND_IMAGE "$global.bg.image2d"
  297. // ---------------------------------------------------------------------------
  298. /** Retrieve a material property with a specific key from the material
  299. *
  300. * @param pMat Pointer to the input material. May not be NULL
  301. * @param pKey Key to search for. One of the AI_MATKEY_XXX constants.
  302. * @param pPropOut Pointer to receive a pointer to a valid aiMaterialProperty
  303. * structure or NULL if the key has not been found.
  304. */
  305. // ---------------------------------------------------------------------------
  306. aiReturn aiGetMaterialProperty(const aiMaterial* pMat,
  307. const char* pKey,
  308. const aiMaterialProperty** pPropOut);
  309. // ---------------------------------------------------------------------------
  310. /** Retrieve an array of float values with a specific key
  311. * from the material
  312. *
  313. * @param pMat Pointer to the input material. May not be NULL
  314. * @param pKey Key to search for. One of the AI_MATKEY_XXX constants.
  315. * @param pOut Pointer to a buffer to receive the result.
  316. * @param pMax Specifies the size of the given buffer, in float's.
  317. * Receives the number of values (not bytes!) read.
  318. */
  319. // ---------------------------------------------------------------------------
  320. aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
  321. const char* pKey,
  322. float* pOut,
  323. unsigned int* pMax);
  324. #ifdef __cplusplus
  325. // inline it
  326. inline aiReturn aiGetMaterialFloat(const aiMaterial* pMat,
  327. const char* pKey,
  328. float* pOut)
  329. {return aiGetMaterialFloatArray(pMat,pKey,pOut,(unsigned int*)0x0);}
  330. #else
  331. // use our friend, the C preprocessor
  332. #define aiGetMaterialFloat (pMat, pKey, pOut) \
  333. aiGetMaterialFloatArray(pMat, pKey, pOut, NULL)
  334. #endif //!__cplusplus
  335. // ---------------------------------------------------------------------------
  336. /** Retrieve an array of integer values with a specific key
  337. * from the material
  338. *
  339. * @param pMat Pointer to the input material. May not be NULL
  340. * @param pKey Key to search for. One of the AI_MATKEY_XXX constants.
  341. * @param pOut Pointer to a buffer to receive the result.
  342. * @param pMax Specifies the size of the given buffer, in int's.
  343. * Receives the number of values (not bytes!) read.
  344. */
  345. // ---------------------------------------------------------------------------
  346. aiReturn aiGetMaterialIntegerArray(const aiMaterial* pMat,
  347. const char* pKey,
  348. int* pOut,
  349. unsigned int* pMax);
  350. #ifdef __cplusplus
  351. // inline it
  352. inline aiReturn aiGetMaterialInteger(const aiMaterial* pMat,
  353. const char* pKey,
  354. int* pOut)
  355. {return aiGetMaterialIntegerArray(pMat,pKey,pOut,(unsigned int*)0x0);}
  356. #else
  357. // use our friend, the C preprocessor
  358. #define aiGetMaterialInteger (pMat, pKey, pOut) \
  359. aiGetMaterialIntegerArray(pMat, pKey, pOut, NULL)
  360. #endif //!__cplusplus
  361. // ---------------------------------------------------------------------------
  362. /** Retrieve a color value from the material property table
  363. *
  364. * @param pMat Pointer to the input material. May not be NULL
  365. * @param pKey Key to search for. One of the AI_MATKEY_XXX constants.
  366. * @param pOut Pointer to a buffer to receive the result.
  367. */
  368. // ---------------------------------------------------------------------------
  369. aiReturn aiGetMaterialColor(const aiMaterial* pMat,
  370. const char* pKey,
  371. aiColor4D* pOut);
  372. // ---------------------------------------------------------------------------
  373. /** Retrieve a string from the material property table
  374. *
  375. * @param pMat Pointer to the input material. May not be NULL
  376. * @param pKey Key to search for. One of the AI_MATKEY_XXX constants.
  377. * @param pOut Pointer to a buffer to receive the result.
  378. */
  379. // ---------------------------------------------------------------------------
  380. aiReturn aiGetMaterialString(const aiMaterial* pMat,
  381. const char* pKey,
  382. aiString* pOut);
  383. #ifdef __cplusplus
  384. }
  385. #endif //!__cplusplus
  386. #endif //!!AI_MATERIAL_H_INC