material.inl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2015, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file material.inl
  35. * @brief Defines the C++ getters for the material system
  36. */
  37. #ifndef AI_MATERIAL_INL_INC
  38. #define AI_MATERIAL_INL_INC
  39. //! @cond never
  40. // ---------------------------------------------------------------------------
  41. inline aiReturn aiMaterial::GetTexture( aiTextureType type,
  42. unsigned int index,
  43. C_STRUCT aiString* path,
  44. aiTextureMapping* mapping /*= NULL*/,
  45. unsigned int* uvindex /*= NULL*/,
  46. float* blend /*= NULL*/,
  47. aiTextureOp* op /*= NULL*/,
  48. aiTextureMapMode* mapmode /*= NULL*/) const
  49. {
  50. return ::aiGetMaterialTexture(this,type,index,path,mapping,uvindex,blend,op,mapmode);
  51. }
  52. // ---------------------------------------------------------------------------
  53. inline unsigned int aiMaterial::GetTextureCount(aiTextureType type) const
  54. {
  55. return ::aiGetMaterialTextureCount(this,type);
  56. }
  57. // ---------------------------------------------------------------------------
  58. template <typename Type>
  59. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  60. unsigned int idx, Type* pOut,
  61. unsigned int* pMax) const
  62. {
  63. unsigned int iNum = pMax ? *pMax : 1;
  64. const aiMaterialProperty* prop;
  65. const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx,
  66. (const aiMaterialProperty**)&prop);
  67. if ( AI_SUCCESS == ret ) {
  68. if (prop->mDataLength < sizeof(Type)*iNum) {
  69. return AI_FAILURE;
  70. }
  71. if (prop->mType != aiPTI_Buffer) {
  72. return AI_FAILURE;
  73. }
  74. iNum = std::min((size_t)iNum,prop->mDataLength / sizeof(Type));
  75. ::memcpy(pOut,prop->mData,iNum * sizeof(Type));
  76. if (pMax) {
  77. *pMax = iNum;
  78. }
  79. }
  80. return ret;
  81. }
  82. // ---------------------------------------------------------------------------
  83. template <typename Type>
  84. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  85. unsigned int idx,Type& pOut) const
  86. {
  87. const aiMaterialProperty* prop;
  88. const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx,
  89. (const aiMaterialProperty**)&prop);
  90. if ( AI_SUCCESS == ret ) {
  91. if (prop->mDataLength < sizeof(Type)) {
  92. return AI_FAILURE;
  93. }
  94. if (prop->mType != aiPTI_Buffer) {
  95. return AI_FAILURE;
  96. }
  97. ::memcpy(&pOut,prop->mData,sizeof(Type));
  98. }
  99. return ret;
  100. }
  101. // ---------------------------------------------------------------------------
  102. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  103. unsigned int idx,float* pOut,
  104. unsigned int* pMax) const
  105. {
  106. return ::aiGetMaterialFloatArray(this,pKey,type,idx,pOut,pMax);
  107. }
  108. // ---------------------------------------------------------------------------
  109. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  110. unsigned int idx,int* pOut,
  111. unsigned int* pMax) const
  112. {
  113. return ::aiGetMaterialIntegerArray(this,pKey,type,idx,pOut,pMax);
  114. }
  115. // ---------------------------------------------------------------------------
  116. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  117. unsigned int idx,float& pOut) const
  118. {
  119. return aiGetMaterialFloat(this,pKey,type,idx,&pOut);
  120. }
  121. // ---------------------------------------------------------------------------
  122. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  123. unsigned int idx,int& pOut) const
  124. {
  125. return aiGetMaterialInteger(this,pKey,type,idx,&pOut);
  126. }
  127. // ---------------------------------------------------------------------------
  128. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  129. unsigned int idx,aiColor4D& pOut) const
  130. {
  131. return aiGetMaterialColor(this,pKey,type,idx,&pOut);
  132. }
  133. // ---------------------------------------------------------------------------
  134. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  135. unsigned int idx,aiColor3D& pOut) const
  136. {
  137. aiColor4D c;
  138. const aiReturn ret = aiGetMaterialColor(this,pKey,type,idx,&c);
  139. pOut = aiColor3D(c.r,c.g,c.b);
  140. return ret;
  141. }
  142. // ---------------------------------------------------------------------------
  143. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  144. unsigned int idx,aiString& pOut) const
  145. {
  146. return aiGetMaterialString(this,pKey,type,idx,&pOut);
  147. }
  148. // ---------------------------------------------------------------------------
  149. inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
  150. unsigned int idx,aiUVTransform& pOut) const
  151. {
  152. return aiGetMaterialUVTransform(this,pKey,type,idx,&pOut);
  153. }
  154. // ---------------------------------------------------------------------------
  155. template<class TYPE>
  156. aiReturn aiMaterial::AddProperty (const TYPE* pInput,
  157. const unsigned int pNumValues,
  158. const char* pKey,
  159. unsigned int type,
  160. unsigned int index)
  161. {
  162. return AddBinaryProperty((const void*)pInput,
  163. pNumValues * sizeof(TYPE),
  164. pKey,type,index,aiPTI_Buffer);
  165. }
  166. // ---------------------------------------------------------------------------
  167. inline aiReturn aiMaterial::AddProperty(const float* pInput,
  168. const unsigned int pNumValues,
  169. const char* pKey,
  170. unsigned int type,
  171. unsigned int index)
  172. {
  173. return AddBinaryProperty((const void*)pInput,
  174. pNumValues * sizeof(float),
  175. pKey,type,index,aiPTI_Float);
  176. }
  177. // ---------------------------------------------------------------------------
  178. inline aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput,
  179. const unsigned int pNumValues,
  180. const char* pKey,
  181. unsigned int type,
  182. unsigned int index)
  183. {
  184. return AddBinaryProperty((const void*)pInput,
  185. pNumValues * sizeof(aiUVTransform),
  186. pKey,type,index,aiPTI_Float);
  187. }
  188. // ---------------------------------------------------------------------------
  189. inline aiReturn aiMaterial::AddProperty(const aiColor4D* 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(aiColor4D),
  197. pKey,type,index,aiPTI_Float);
  198. }
  199. // ---------------------------------------------------------------------------
  200. inline aiReturn aiMaterial::AddProperty(const aiColor3D* pInput,
  201. const unsigned int pNumValues,
  202. const char* pKey,
  203. unsigned int type,
  204. unsigned int index)
  205. {
  206. return AddBinaryProperty((const void*)pInput,
  207. pNumValues * sizeof(aiColor3D),
  208. pKey,type,index,aiPTI_Float);
  209. }
  210. // ---------------------------------------------------------------------------
  211. inline aiReturn aiMaterial::AddProperty(const aiVector3D* pInput,
  212. const unsigned int pNumValues,
  213. const char* pKey,
  214. unsigned int type,
  215. unsigned int index)
  216. {
  217. return AddBinaryProperty((const void*)pInput,
  218. pNumValues * sizeof(aiVector3D),
  219. pKey,type,index,aiPTI_Float);
  220. }
  221. // ---------------------------------------------------------------------------
  222. inline aiReturn aiMaterial::AddProperty(const int* pInput,
  223. const unsigned int pNumValues,
  224. const char* pKey,
  225. unsigned int type,
  226. unsigned int index)
  227. {
  228. return AddBinaryProperty((const void*)pInput,
  229. pNumValues * sizeof(int),
  230. pKey,type,index,aiPTI_Integer);
  231. }
  232. // ---------------------------------------------------------------------------
  233. // The template specializations below are for backwards compatibility.
  234. // The recommended way to add material properties is using the non-template
  235. // overloads.
  236. // ---------------------------------------------------------------------------
  237. // ---------------------------------------------------------------------------
  238. template<>
  239. inline aiReturn aiMaterial::AddProperty<float>(const float* pInput,
  240. const unsigned int pNumValues,
  241. const char* pKey,
  242. unsigned int type,
  243. unsigned int index)
  244. {
  245. return AddBinaryProperty((const void*)pInput,
  246. pNumValues * sizeof(float),
  247. pKey,type,index,aiPTI_Float);
  248. }
  249. // ---------------------------------------------------------------------------
  250. template<>
  251. inline aiReturn aiMaterial::AddProperty<aiUVTransform>(const aiUVTransform* pInput,
  252. const unsigned int pNumValues,
  253. const char* pKey,
  254. unsigned int type,
  255. unsigned int index)
  256. {
  257. return AddBinaryProperty((const void*)pInput,
  258. pNumValues * sizeof(aiUVTransform),
  259. pKey,type,index,aiPTI_Float);
  260. }
  261. // ---------------------------------------------------------------------------
  262. template<>
  263. inline aiReturn aiMaterial::AddProperty<aiColor4D>(const aiColor4D* pInput,
  264. const unsigned int pNumValues,
  265. const char* pKey,
  266. unsigned int type,
  267. unsigned int index)
  268. {
  269. return AddBinaryProperty((const void*)pInput,
  270. pNumValues * sizeof(aiColor4D),
  271. pKey,type,index,aiPTI_Float);
  272. }
  273. // ---------------------------------------------------------------------------
  274. template<>
  275. inline aiReturn aiMaterial::AddProperty<aiColor3D>(const aiColor3D* pInput,
  276. const unsigned int pNumValues,
  277. const char* pKey,
  278. unsigned int type,
  279. unsigned int index)
  280. {
  281. return AddBinaryProperty((const void*)pInput,
  282. pNumValues * sizeof(aiColor3D),
  283. pKey,type,index,aiPTI_Float);
  284. }
  285. // ---------------------------------------------------------------------------
  286. template<>
  287. inline aiReturn aiMaterial::AddProperty<aiVector3D>(const aiVector3D* pInput,
  288. const unsigned int pNumValues,
  289. const char* pKey,
  290. unsigned int type,
  291. unsigned int index)
  292. {
  293. return AddBinaryProperty((const void*)pInput,
  294. pNumValues * sizeof(aiVector3D),
  295. pKey,type,index,aiPTI_Float);
  296. }
  297. // ---------------------------------------------------------------------------
  298. template<>
  299. inline aiReturn aiMaterial::AddProperty<int>(const int* pInput,
  300. const unsigned int pNumValues,
  301. const char* pKey,
  302. unsigned int type,
  303. unsigned int index)
  304. {
  305. return AddBinaryProperty((const void*)pInput,
  306. pNumValues * sizeof(int),
  307. pKey,type,index,aiPTI_Integer);
  308. }
  309. //! @endcond
  310. #endif //! AI_MATERIAL_INL_INC