MaterialSystem.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. Open Asset Import Library (ASSIMP)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2008, 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 Definition of the base class for all importer worker classes. */
  34. #ifndef AI_MATERIALSYSTEM_H_INC
  35. #define AI_MATERIALSYSTEM_H_INC
  36. #include "../include/aiMaterial.h"
  37. namespace Assimp {
  38. // ----------------------------------------------------------------------------------------
  39. /** Internal material helper class. Intended to be used to fill an aiMaterial
  40. structure easily. */
  41. class ASSIMP_API MaterialHelper : public ::aiMaterial
  42. {
  43. public:
  44. MaterialHelper();
  45. ~MaterialHelper();
  46. // ------------------------------------------------------------------------------
  47. /** @brief Add a property with a given key and type info to the material
  48. * structure
  49. *
  50. * @param pInput Pointer to input data
  51. * @param pSizeInBytes Size of input data
  52. * @param pKey Key/Usage of the property (AI_MATKEY_XXX)
  53. * @param type Set by the AI_MATKEY_XXX macro
  54. * @param index Set by the AI_MATKEY_XXX macro
  55. * @param pType Type information hint
  56. */
  57. aiReturn AddBinaryProperty (const void* pInput,
  58. unsigned int pSizeInBytes,
  59. const char* pKey,
  60. unsigned int type ,
  61. unsigned int index ,
  62. aiPropertyTypeInfo pType);
  63. // ------------------------------------------------------------------------------
  64. /** @brief Add a string property with a given key and type info to the
  65. * material structure
  66. *
  67. * @param pInput Input string
  68. * @param pKey Key/Usage of the property (AI_MATKEY_XXX)
  69. * @param type Set by the AI_MATKEY_XXX macro
  70. * @param index Set by the AI_MATKEY_XXX macro
  71. */
  72. aiReturn AddProperty (const aiString* pInput,
  73. const char* pKey,
  74. unsigned int type = 0,
  75. unsigned int index = 0);
  76. // ------------------------------------------------------------------------------
  77. /** @brief Add a property with a given key to the material structure
  78. * @param pInput Pointer to the input data
  79. * @param pNumValues Number of values in the array
  80. * @param pKey Key/Usage of the property (AI_MATKEY_XXX)
  81. * @param type Set by the AI_MATKEY_XXX macro
  82. * @param index Set by the AI_MATKEY_XXX macro
  83. */
  84. template<class TYPE>
  85. aiReturn AddProperty (const TYPE* pInput,
  86. unsigned int pNumValues,
  87. const char* pKey,
  88. unsigned int type = 0,
  89. unsigned int index = 0);
  90. // ------------------------------------------------------------------------------
  91. /** @brief Remove a given key from the list.
  92. *
  93. * The function fails if the key isn't found
  94. * @param pKey Key to be deleted
  95. */
  96. aiReturn RemoveProperty (const char* pKey,
  97. unsigned int type = 0,
  98. unsigned int index = 0);
  99. // ------------------------------------------------------------------------------
  100. /** @brief Removes all properties from the material.
  101. *
  102. * The array remains allocated, so adding new properties is quite fast.
  103. */
  104. void Clear();
  105. // ------------------------------------------------------------------------------
  106. /** Computes a hash (hopefully unique) from all material properties
  107. * The hash value reflects the current property state, so if you add any
  108. * proprty and call this method again, the resulting hash value will be
  109. * different.
  110. *
  111. * @param includeMatName Set to 'true' to take all properties with
  112. * '?' as initial character in their name into account.
  113. * Currently #AI_MATKEY_NAME is the only example.
  114. * @return Unique hash
  115. */
  116. uint32_t ComputeHash(bool includeMatName = false);
  117. // ------------------------------------------------------------------------------
  118. /** Copy the property list of a material
  119. * \param pcDest Destination material
  120. * \param pcSrc Source material
  121. */
  122. static void CopyPropertyList(MaterialHelper* pcDest,
  123. const MaterialHelper* pcSrc);
  124. // For internal use
  125. void _InternDestruct();
  126. };
  127. // ----------------------------------------------------------------------------------------
  128. template<class TYPE>
  129. aiReturn MaterialHelper::AddProperty (const TYPE* pInput,
  130. const unsigned int pNumValues,
  131. const char* pKey,
  132. unsigned int type,
  133. unsigned int index)
  134. {
  135. return AddBinaryProperty((const void*)pInput,
  136. pNumValues * sizeof(TYPE),
  137. pKey,type,index,aiPTI_Buffer);
  138. }
  139. // ----------------------------------------------------------------------------------------
  140. template<>
  141. inline aiReturn MaterialHelper::AddProperty<float> (const float* pInput,
  142. const unsigned int pNumValues,
  143. const char* pKey,
  144. unsigned int type,
  145. unsigned int index)
  146. {
  147. return AddBinaryProperty((const void*)pInput,
  148. pNumValues * sizeof(float),
  149. pKey,type,index,aiPTI_Float);
  150. }
  151. // ----------------------------------------------------------------------------------------
  152. template<>
  153. inline aiReturn MaterialHelper::AddProperty<aiUVTransform> (const aiUVTransform* pInput,
  154. const unsigned int pNumValues,
  155. const char* pKey,
  156. unsigned int type,
  157. unsigned int index)
  158. {
  159. return AddBinaryProperty((const void*)pInput,
  160. pNumValues * sizeof(aiUVTransform),
  161. pKey,type,index,aiPTI_Float);
  162. }
  163. // ----------------------------------------------------------------------------------------
  164. template<>
  165. inline aiReturn MaterialHelper::AddProperty<aiColor4D> (const aiColor4D* pInput,
  166. const unsigned int pNumValues,
  167. const char* pKey,
  168. unsigned int type,
  169. unsigned int index)
  170. {
  171. return AddBinaryProperty((const void*)pInput,
  172. pNumValues * sizeof(aiColor4D),
  173. pKey,type,index,aiPTI_Float);
  174. }
  175. // ----------------------------------------------------------------------------------------
  176. template<>
  177. inline aiReturn MaterialHelper::AddProperty<aiColor3D> (const aiColor3D* pInput,
  178. const unsigned int pNumValues,
  179. const char* pKey,
  180. unsigned int type,
  181. unsigned int index)
  182. {
  183. return AddBinaryProperty((const void*)pInput,
  184. pNumValues * sizeof(aiColor3D),
  185. pKey,type,index,aiPTI_Float);
  186. }
  187. // ----------------------------------------------------------------------------------------
  188. template<>
  189. inline aiReturn MaterialHelper::AddProperty<aiVector3D> (const aiVector3D* pInput,
  190. const unsigned int pNumValues,
  191. const char* pKey,
  192. unsigned int type,
  193. unsigned int index)
  194. {
  195. return AddBinaryProperty((const void*)pInput,
  196. pNumValues * sizeof(aiVector3D),
  197. pKey,type,index,aiPTI_Float);
  198. }
  199. // ----------------------------------------------------------------------------------------
  200. template<>
  201. inline aiReturn MaterialHelper::AddProperty<int> (const int* pInput,
  202. const unsigned int pNumValues,
  203. const char* pKey,
  204. unsigned int type,
  205. unsigned int index)
  206. {
  207. return AddBinaryProperty((const void*)pInput,
  208. pNumValues * sizeof(int),
  209. pKey,type,index,aiPTI_Integer);
  210. }
  211. } // ! namespace Assimp
  212. #endif //!! AI_MATERIALSYSTEM_H_INC