2
0

MaterialSystem.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. // ---------------------------------------------------------------------------
  40. /** Internal material helper class. Can be used to fill an aiMaterial
  41. structure easily. */
  42. class ASSIMP_API MaterialHelper : public ::aiMaterial
  43. {
  44. public:
  45. MaterialHelper();
  46. ~MaterialHelper();
  47. // -------------------------------------------------------------------
  48. /** Add a property with a given key and type info to the material
  49. * structure
  50. *
  51. * \param pInput Pointer to input data
  52. * \param pSizeInBytes Size of input data
  53. * \param pKey Key/Usage of the property (AI_MATKEY_XXX)
  54. * \param type Set by the AI_MATKEY_XXX macro
  55. * \param index Set by the AI_MATKEY_XXX macro
  56. * \param pType Type information hint
  57. */
  58. aiReturn AddBinaryProperty (const void* pInput,
  59. unsigned int pSizeInBytes,
  60. const char* pKey,
  61. unsigned int type,
  62. unsigned int index,
  63. aiPropertyTypeInfo pType);
  64. // -------------------------------------------------------------------
  65. /** Add a string property with a given key and type info to the
  66. * material structure
  67. *
  68. * \param pInput Input string
  69. * \param pKey Key/Usage of the property (AI_MATKEY_XXX)
  70. * \param type Set by the AI_MATKEY_XXX macro
  71. * \param index Set by the AI_MATKEY_XXX macro
  72. */
  73. aiReturn AddProperty (const aiString* pInput,
  74. const char* pKey,
  75. unsigned int type,
  76. unsigned int index);
  77. // -------------------------------------------------------------------
  78. /** Add a property with a given key to the material structure
  79. * \param pInput Pointer to the input data
  80. * \param pNumValues Number of values in the array
  81. * \param pKey Key/Usage of the property (AI_MATKEY_XXX)
  82. * \param type Set by the AI_MATKEY_XXX macro
  83. * \param index Set by the AI_MATKEY_XXX macro
  84. */
  85. template<class TYPE>
  86. aiReturn AddProperty (const TYPE* pInput,
  87. unsigned int pNumValues,
  88. const char* pKey,
  89. unsigned int type,
  90. unsigned int index);
  91. // -------------------------------------------------------------------
  92. /** Remove a given key from the list
  93. * The function fails if the key isn't found
  94. *
  95. * \param pKey Key to be deleted
  96. */
  97. aiReturn RemoveProperty (const char* pKey,
  98. unsigned int type,
  99. unsigned int index);
  100. // -------------------------------------------------------------------
  101. /** Removes all properties from the material
  102. */
  103. void Clear();
  104. // -------------------------------------------------------------------
  105. /** Computes a hash (hopefully unique) from all material properties
  106. * The hash value must be updated after material properties have
  107. * been changed.
  108. *
  109. * \return Unique hash
  110. */
  111. uint32_t ComputeHash();
  112. // -------------------------------------------------------------------
  113. /** Copy the property list of a material
  114. * \param pcDest Destination material
  115. * \param pcSrc Source material
  116. */
  117. static void CopyPropertyList(MaterialHelper* pcDest,
  118. const MaterialHelper* pcSrc);
  119. };
  120. // ---------------------------------------------------------------------------
  121. // ---------------------------------------------------------------------------
  122. template<class TYPE>
  123. aiReturn MaterialHelper::AddProperty (const TYPE* pInput,
  124. const unsigned int pNumValues,
  125. const char* pKey,
  126. unsigned int type,
  127. unsigned int index)
  128. {
  129. return this->AddBinaryProperty((const void*)pInput,
  130. pNumValues * sizeof(TYPE),
  131. pKey,type,index,aiPTI_Buffer);
  132. }
  133. // ---------------------------------------------------------------------------
  134. // ---------------------------------------------------------------------------
  135. template<>
  136. inline aiReturn MaterialHelper::AddProperty<float> (const float* pInput,
  137. const unsigned int pNumValues,
  138. const char* pKey,
  139. unsigned int type,
  140. unsigned int index)
  141. {
  142. return this->AddBinaryProperty((const void*)pInput,
  143. pNumValues * sizeof(float),
  144. pKey,type,index,aiPTI_Float);
  145. }
  146. // ---------------------------------------------------------------------------
  147. // ---------------------------------------------------------------------------
  148. template<>
  149. inline aiReturn MaterialHelper::AddProperty<aiColor4D> (const aiColor4D* pInput,
  150. const unsigned int pNumValues,
  151. const char* pKey,
  152. unsigned int type,
  153. unsigned int index)
  154. {
  155. return this->AddBinaryProperty((const void*)pInput,
  156. pNumValues * sizeof(aiColor4D),
  157. pKey,type,index,aiPTI_Float);
  158. }
  159. // ---------------------------------------------------------------------------
  160. // ---------------------------------------------------------------------------
  161. template<>
  162. inline aiReturn MaterialHelper::AddProperty<aiColor3D> (const aiColor3D* pInput,
  163. const unsigned int pNumValues,
  164. const char* pKey,
  165. unsigned int type,
  166. unsigned int index)
  167. {
  168. return this->AddBinaryProperty((const void*)pInput,
  169. pNumValues * sizeof(aiColor3D),
  170. pKey,type,index,aiPTI_Float);
  171. }
  172. // ---------------------------------------------------------------------------
  173. // ---------------------------------------------------------------------------
  174. template<>
  175. inline aiReturn MaterialHelper::AddProperty<int> (const int* pInput,
  176. const unsigned int pNumValues,
  177. const char* pKey,
  178. unsigned int type,
  179. unsigned int index)
  180. {
  181. return this->AddBinaryProperty((const void*)pInput,
  182. pNumValues * sizeof(int),
  183. pKey,type,index,aiPTI_Integer);
  184. }
  185. }
  186. #endif //!! AI_MATERIALSYSTEM_H_INC