vrshoot
diff libs/assimp/assimp/material.inl @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/assimp/material.inl Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,272 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2012, assimp team 1.10 + 1.11 +All rights reserved. 1.12 + 1.13 +Redistribution and use of this software in source and binary forms, 1.14 +with or without modification, are permitted provided that the following 1.15 +conditions are met: 1.16 + 1.17 +* Redistributions of source code must retain the above 1.18 + copyright notice, this list of conditions and the 1.19 + following disclaimer. 1.20 + 1.21 +* Redistributions in binary form must reproduce the above 1.22 + copyright notice, this list of conditions and the 1.23 + following disclaimer in the documentation and/or other 1.24 + materials provided with the distribution. 1.25 + 1.26 +* Neither the name of the assimp team, nor the names of its 1.27 + contributors may be used to endorse or promote products 1.28 + derived from this software without specific prior 1.29 + written permission of the assimp team. 1.30 + 1.31 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.32 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.33 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.34 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.35 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.36 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.37 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.38 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.39 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.40 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.41 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.42 +--------------------------------------------------------------------------- 1.43 +*/ 1.44 + 1.45 +/** @file aiMaterial.inl 1.46 + * @brief Defines the C++ getters for the material system 1.47 + */ 1.48 + 1.49 +#ifndef AI_MATERIAL_INL_INC 1.50 +#define AI_MATERIAL_INL_INC 1.51 + 1.52 +//! @cond never 1.53 + 1.54 +// --------------------------------------------------------------------------- 1.55 +inline aiReturn aiMaterial::GetTexture( aiTextureType type, 1.56 + unsigned int index, 1.57 + C_STRUCT aiString* path, 1.58 + aiTextureMapping* mapping /*= NULL*/, 1.59 + unsigned int* uvindex /*= NULL*/, 1.60 + float* blend /*= NULL*/, 1.61 + aiTextureOp* op /*= NULL*/, 1.62 + aiTextureMapMode* mapmode /*= NULL*/) const 1.63 +{ 1.64 + return ::aiGetMaterialTexture(this,type,index,path,mapping,uvindex,blend,op,mapmode); 1.65 +} 1.66 + 1.67 +// --------------------------------------------------------------------------- 1.68 +inline unsigned int aiMaterial::GetTextureCount(aiTextureType type) const 1.69 +{ 1.70 + return ::aiGetMaterialTextureCount(this,type); 1.71 +} 1.72 + 1.73 +// --------------------------------------------------------------------------- 1.74 +template <typename Type> 1.75 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, 1.76 + unsigned int idx, Type* pOut, 1.77 + unsigned int* pMax) const 1.78 +{ 1.79 + unsigned int iNum = pMax ? *pMax : 1; 1.80 + 1.81 + const aiMaterialProperty* prop; 1.82 + const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx, 1.83 + (const aiMaterialProperty**)&prop); 1.84 + if ( AI_SUCCESS == ret ) { 1.85 + 1.86 + if (prop->mDataLength < sizeof(Type)*iNum) { 1.87 + return AI_FAILURE; 1.88 + } 1.89 + 1.90 + if (prop->mType != aiPTI_Buffer) { 1.91 + return AI_FAILURE; 1.92 + } 1.93 + 1.94 + iNum = std::min((size_t)iNum,prop->mDataLength / sizeof(Type)); 1.95 + memcpy(pOut,prop->mData,iNum * sizeof(Type)); 1.96 + if (pMax) { 1.97 + *pMax = iNum; 1.98 + } 1.99 + } 1.100 + return ret; 1.101 +} 1.102 + 1.103 +// --------------------------------------------------------------------------- 1.104 +template <typename Type> 1.105 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, 1.106 + unsigned int idx,Type& pOut) const 1.107 +{ 1.108 + const aiMaterialProperty* prop; 1.109 + const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx, 1.110 + (const aiMaterialProperty**)&prop); 1.111 + if ( AI_SUCCESS == ret ) { 1.112 + 1.113 + if (prop->mDataLength < sizeof(Type)) { 1.114 + return AI_FAILURE; 1.115 + } 1.116 + 1.117 + if (prop->mType != aiPTI_Buffer) { 1.118 + return AI_FAILURE; 1.119 + } 1.120 + 1.121 + memcpy(&pOut,prop->mData,sizeof(Type)); 1.122 + } 1.123 + return ret; 1.124 +} 1.125 + 1.126 +// --------------------------------------------------------------------------- 1.127 +template <> 1.128 +inline aiReturn aiMaterial::Get<float>(const char* pKey,unsigned int type, 1.129 + unsigned int idx,float* pOut, 1.130 + unsigned int* pMax) const 1.131 +{ 1.132 + return ::aiGetMaterialFloatArray(this,pKey,type,idx,pOut,pMax); 1.133 +} 1.134 +// --------------------------------------------------------------------------- 1.135 +template <> 1.136 +inline aiReturn aiMaterial::Get<int>(const char* pKey,unsigned int type, 1.137 + unsigned int idx,int* pOut, 1.138 + unsigned int* pMax) const 1.139 +{ 1.140 + return ::aiGetMaterialIntegerArray(this,pKey,type,idx,pOut,pMax); 1.141 +} 1.142 +// --------------------------------------------------------------------------- 1.143 +template <> 1.144 +inline aiReturn aiMaterial::Get<float>(const char* pKey,unsigned int type, 1.145 + unsigned int idx,float& pOut) const 1.146 +{ 1.147 + return aiGetMaterialFloat(this,pKey,type,idx,&pOut); 1.148 +} 1.149 +// --------------------------------------------------------------------------- 1.150 +template <> 1.151 +inline aiReturn aiMaterial::Get<int>(const char* pKey,unsigned int type, 1.152 + unsigned int idx,int& pOut) const 1.153 +{ 1.154 + return aiGetMaterialInteger(this,pKey,type,idx,&pOut); 1.155 +} 1.156 +// --------------------------------------------------------------------------- 1.157 +template <> 1.158 +inline aiReturn aiMaterial::Get<aiColor4D>(const char* pKey,unsigned int type, 1.159 + unsigned int idx,aiColor4D& pOut) const 1.160 +{ 1.161 + return aiGetMaterialColor(this,pKey,type,idx,&pOut); 1.162 +} 1.163 +// --------------------------------------------------------------------------- 1.164 +template <> 1.165 +inline aiReturn aiMaterial::Get<aiColor3D>(const char* pKey,unsigned int type, 1.166 + unsigned int idx,aiColor3D& pOut) const 1.167 +{ 1.168 + aiColor4D c; 1.169 + const aiReturn ret = aiGetMaterialColor(this,pKey,type,idx,&c); 1.170 + pOut = aiColor3D(c.r,c.g,c.b); 1.171 + return ret; 1.172 +} 1.173 +// --------------------------------------------------------------------------- 1.174 +template <> 1.175 +inline aiReturn aiMaterial::Get<aiString>(const char* pKey,unsigned int type, 1.176 + unsigned int idx,aiString& pOut) const 1.177 +{ 1.178 + return aiGetMaterialString(this,pKey,type,idx,&pOut); 1.179 +} 1.180 + 1.181 + 1.182 +// --------------------------------------------------------------------------- 1.183 +template<class TYPE> 1.184 +aiReturn aiMaterial::AddProperty (const TYPE* pInput, 1.185 + const unsigned int pNumValues, 1.186 + const char* pKey, 1.187 + unsigned int type, 1.188 + unsigned int index) 1.189 +{ 1.190 + return AddBinaryProperty((const void*)pInput, 1.191 + pNumValues * sizeof(TYPE), 1.192 + pKey,type,index,aiPTI_Buffer); 1.193 +} 1.194 + 1.195 +// --------------------------------------------------------------------------- 1.196 +template<> 1.197 +inline aiReturn aiMaterial::AddProperty<float> (const float* pInput, 1.198 + const unsigned int pNumValues, 1.199 + const char* pKey, 1.200 + unsigned int type, 1.201 + unsigned int index) 1.202 +{ 1.203 + return AddBinaryProperty((const void*)pInput, 1.204 + pNumValues * sizeof(float), 1.205 + pKey,type,index,aiPTI_Float); 1.206 +} 1.207 + 1.208 +// --------------------------------------------------------------------------- 1.209 +template<> 1.210 +inline aiReturn aiMaterial::AddProperty<aiUVTransform> (const aiUVTransform* pInput, 1.211 + const unsigned int pNumValues, 1.212 + const char* pKey, 1.213 + unsigned int type, 1.214 + unsigned int index) 1.215 +{ 1.216 + return AddBinaryProperty((const void*)pInput, 1.217 + pNumValues * sizeof(aiUVTransform), 1.218 + pKey,type,index,aiPTI_Float); 1.219 +} 1.220 + 1.221 +// --------------------------------------------------------------------------- 1.222 +template<> 1.223 +inline aiReturn aiMaterial::AddProperty<aiColor4D> (const aiColor4D* pInput, 1.224 + const unsigned int pNumValues, 1.225 + const char* pKey, 1.226 + unsigned int type, 1.227 + unsigned int index) 1.228 +{ 1.229 + return AddBinaryProperty((const void*)pInput, 1.230 + pNumValues * sizeof(aiColor4D), 1.231 + pKey,type,index,aiPTI_Float); 1.232 +} 1.233 + 1.234 +// --------------------------------------------------------------------------- 1.235 +template<> 1.236 +inline aiReturn aiMaterial::AddProperty<aiColor3D> (const aiColor3D* pInput, 1.237 + const unsigned int pNumValues, 1.238 + const char* pKey, 1.239 + unsigned int type, 1.240 + unsigned int index) 1.241 +{ 1.242 + return AddBinaryProperty((const void*)pInput, 1.243 + pNumValues * sizeof(aiColor3D), 1.244 + pKey,type,index,aiPTI_Float); 1.245 +} 1.246 + 1.247 +// --------------------------------------------------------------------------- 1.248 +template<> 1.249 +inline aiReturn aiMaterial::AddProperty<aiVector3D> (const aiVector3D* pInput, 1.250 + const unsigned int pNumValues, 1.251 + const char* pKey, 1.252 + unsigned int type, 1.253 + unsigned int index) 1.254 +{ 1.255 + return AddBinaryProperty((const void*)pInput, 1.256 + pNumValues * sizeof(aiVector3D), 1.257 + pKey,type,index,aiPTI_Float); 1.258 +} 1.259 + 1.260 +// --------------------------------------------------------------------------- 1.261 +template<> 1.262 +inline aiReturn aiMaterial::AddProperty<int> (const int* pInput, 1.263 + const unsigned int pNumValues, 1.264 + const char* pKey, 1.265 + unsigned int type, 1.266 + unsigned int index) 1.267 +{ 1.268 + return AddBinaryProperty((const void*)pInput, 1.269 + pNumValues * sizeof(int), 1.270 + pKey,type,index,aiPTI_Integer); 1.271 +} 1.272 + 1.273 +//! @endcond 1.274 + 1.275 +#endif //! AI_MATERIAL_INL_INC