MaterialSystem.h 6.5 KB

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