MaterialSystem.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2010, ASSIMP Development Team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the ASSIMP team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the ASSIMP Development Team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file MaterialSystem.h
  34. * Definition of the #MaterialHelper utility class.
  35. */
  36. #ifndef AI_MATERIALSYSTEM_H_INC
  37. #define AI_MATERIALSYSTEM_H_INC
  38. #include "../include/aiMaterial.h"
  39. namespace Assimp {
  40. // ----------------------------------------------------------------------------------------
  41. /** Internal material helper class deriving from aiMaterial.
  42. *
  43. * Intended to be used to fill an aiMaterial structure more easily.
  44. */
  45. class ASSIMP_API MaterialHelper : public ::aiMaterial
  46. {
  47. public:
  48. // Construction and destruction
  49. MaterialHelper();
  50. ~MaterialHelper();
  51. // ------------------------------------------------------------------------------
  52. /** @brief Add a property with a given key and type info to the material
  53. * structure
  54. *
  55. * @param pInput Pointer to input data
  56. * @param pSizeInBytes Size of input data
  57. * @param pKey Key/Usage of the property (AI_MATKEY_XXX)
  58. * @param type Set by the AI_MATKEY_XXX macro
  59. * @param index Set by the AI_MATKEY_XXX macro
  60. * @param pType Type information hint
  61. */
  62. aiReturn AddBinaryProperty (const void* pInput,
  63. unsigned int pSizeInBytes,
  64. const char* pKey,
  65. unsigned int type ,
  66. unsigned int index ,
  67. aiPropertyTypeInfo pType);
  68. // ------------------------------------------------------------------------------
  69. /** @brief Add a string property with a given key and type info to the
  70. * material structure
  71. *
  72. * @param pInput Input string
  73. * @param pKey Key/Usage of the property (AI_MATKEY_XXX)
  74. * @param type Set by the AI_MATKEY_XXX macro
  75. * @param index Set by the AI_MATKEY_XXX macro
  76. */
  77. aiReturn AddProperty (const aiString* pInput,
  78. const char* pKey,
  79. unsigned int type = 0,
  80. unsigned int index = 0);
  81. // ------------------------------------------------------------------------------
  82. /** @brief Add a property with a given key to the material structure
  83. * @param pInput Pointer to the input data
  84. * @param pNumValues Number of values in the array
  85. * @param pKey Key/Usage of the property (AI_MATKEY_XXX)
  86. * @param type Set by the AI_MATKEY_XXX macro
  87. * @param index Set by the AI_MATKEY_XXX macro
  88. */
  89. template<class TYPE>
  90. aiReturn AddProperty (const TYPE* pInput,
  91. unsigned int pNumValues,
  92. const char* pKey,
  93. unsigned int type = 0,
  94. unsigned int index = 0);
  95. // ------------------------------------------------------------------------------
  96. /** @brief Remove a given key from the list.
  97. *
  98. * The function fails if the key isn't found
  99. * @param pKey Key to be deleted
  100. */
  101. aiReturn RemoveProperty (const char* pKey,
  102. unsigned int type = 0,
  103. unsigned int index = 0);
  104. // ------------------------------------------------------------------------------
  105. /** @brief Removes all properties from the material.
  106. *
  107. * The data array remains allocated so adding new properties is quite fast.
  108. */
  109. void Clear();
  110. // ------------------------------------------------------------------------------
  111. /** Computes a hash (hopefully unique) from all material properties
  112. * The hash value reflects the current property state, so if you add any
  113. * proprty and call this method again, the resulting hash value will be
  114. * different.
  115. *
  116. * @param includeMatName Set to 'true' to take all properties with
  117. * '?' as initial character in their name into account.
  118. * Currently #AI_MATKEY_NAME is the only example.
  119. * @return Unique hash
  120. */
  121. uint32_t ComputeHash(bool includeMatName = false);
  122. // ------------------------------------------------------------------------------
  123. /** Copy the property list of a material
  124. * @param pcDest Destination material
  125. * @param pcSrc Source material
  126. */
  127. static void CopyPropertyList(MaterialHelper* pcDest,
  128. const MaterialHelper* pcSrc);
  129. public:
  130. // For internal use. That's why it's public.
  131. void _InternDestruct();
  132. };
  133. // ----------------------------------------------------------------------------------------
  134. template<class TYPE>
  135. aiReturn MaterialHelper::AddProperty (const TYPE* pInput,
  136. const unsigned int pNumValues,
  137. const char* pKey,
  138. unsigned int type,
  139. unsigned int index)
  140. {
  141. return AddBinaryProperty((const void*)pInput,
  142. pNumValues * sizeof(TYPE),
  143. pKey,type,index,aiPTI_Buffer);
  144. }
  145. // ----------------------------------------------------------------------------------------
  146. template<>
  147. inline aiReturn MaterialHelper::AddProperty<float> (const float* pInput,
  148. const unsigned int pNumValues,
  149. const char* pKey,
  150. unsigned int type,
  151. unsigned int index)
  152. {
  153. return AddBinaryProperty((const void*)pInput,
  154. pNumValues * sizeof(float),
  155. pKey,type,index,aiPTI_Float);
  156. }
  157. // ----------------------------------------------------------------------------------------
  158. template<>
  159. inline aiReturn MaterialHelper::AddProperty<aiUVTransform> (const aiUVTransform* pInput,
  160. const unsigned int pNumValues,
  161. const char* pKey,
  162. unsigned int type,
  163. unsigned int index)
  164. {
  165. return AddBinaryProperty((const void*)pInput,
  166. pNumValues * sizeof(aiUVTransform),
  167. pKey,type,index,aiPTI_Float);
  168. }
  169. // ----------------------------------------------------------------------------------------
  170. template<>
  171. inline aiReturn MaterialHelper::AddProperty<aiColor4D> (const aiColor4D* pInput,
  172. const unsigned int pNumValues,
  173. const char* pKey,
  174. unsigned int type,
  175. unsigned int index)
  176. {
  177. return AddBinaryProperty((const void*)pInput,
  178. pNumValues * sizeof(aiColor4D),
  179. pKey,type,index,aiPTI_Float);
  180. }
  181. // ----------------------------------------------------------------------------------------
  182. template<>
  183. inline aiReturn MaterialHelper::AddProperty<aiColor3D> (const aiColor3D* pInput,
  184. const unsigned int pNumValues,
  185. const char* pKey,
  186. unsigned int type,
  187. unsigned int index)
  188. {
  189. return AddBinaryProperty((const void*)pInput,
  190. pNumValues * sizeof(aiColor3D),
  191. pKey,type,index,aiPTI_Float);
  192. }
  193. // ----------------------------------------------------------------------------------------
  194. template<>
  195. inline aiReturn MaterialHelper::AddProperty<aiVector3D> (const aiVector3D* pInput,
  196. const unsigned int pNumValues,
  197. const char* pKey,
  198. unsigned int type,
  199. unsigned int index)
  200. {
  201. return AddBinaryProperty((const void*)pInput,
  202. pNumValues * sizeof(aiVector3D),
  203. pKey,type,index,aiPTI_Float);
  204. }
  205. // ----------------------------------------------------------------------------------------
  206. template<>
  207. inline aiReturn MaterialHelper::AddProperty<int> (const int* pInput,
  208. const unsigned int pNumValues,
  209. const char* pKey,
  210. unsigned int type,
  211. unsigned int index)
  212. {
  213. return AddBinaryProperty((const void*)pInput,
  214. pNumValues * sizeof(int),
  215. pKey,type,index,aiPTI_Integer);
  216. }
  217. } // ! namespace Assimp
  218. #endif //!! AI_MATERIALSYSTEM_H_INC