Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/assimp/material.inl is written in an unsupported language. File is not indexed.

0001 /*
0002 ---------------------------------------------------------------------------
0003 Open Asset Import Library (assimp)
0004 ---------------------------------------------------------------------------
0005 
0006 Copyright (c) 2006-2024, assimp team
0007 
0008 All rights reserved.
0009 
0010 Redistribution and use of this software in source and binary forms,
0011 with or without modification, are permitted provided that the following
0012 conditions are met:
0013 
0014 * Redistributions of source code must retain the above
0015   copyright notice, this list of conditions and the
0016   following disclaimer.
0017 
0018 * Redistributions in binary form must reproduce the above
0019   copyright notice, this list of conditions and the
0020   following disclaimer in the documentation and/or other
0021   materials provided with the distribution.
0022 
0023 * Neither the name of the assimp team, nor the names of its
0024   contributors may be used to endorse or promote products
0025   derived from this software without specific prior
0026   written permission of the assimp team.
0027 
0028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0029 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0030 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0031 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0032 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0033 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0034 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0035 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0036 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0037 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0038 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0039 ---------------------------------------------------------------------------
0040 */
0041 
0042 /** @file material.inl
0043  *  @brief Defines the C++ getters for the material system
0044  */
0045 
0046 #pragma once
0047 
0048 #ifdef __GNUC__
0049 #   pragma GCC system_header
0050 #endif
0051 
0052 // ---------------------------------------------------------------------------
0053 AI_FORCE_INLINE aiPropertyTypeInfo ai_real_to_property_type_info(float) {
0054         return aiPTI_Float;
0055 }
0056 
0057 AI_FORCE_INLINE aiPropertyTypeInfo ai_real_to_property_type_info(double) {
0058         return aiPTI_Double;
0059 }
0060 // ---------------------------------------------------------------------------
0061 
0062 //! @cond never
0063 
0064 // ---------------------------------------------------------------------------
0065 AI_FORCE_INLINE aiReturn aiMaterial::GetTexture( aiTextureType type,
0066        unsigned int  index,
0067        C_STRUCT aiString* path,
0068        aiTextureMapping* mapping    /*= NULL*/,
0069        unsigned int* uvindex        /*= NULL*/,
0070        float* blend               /*= NULL*/,
0071        aiTextureOp* op              /*= NULL*/,
0072        aiTextureMapMode* mapmode    /*= NULL*/) const {
0073     return ::aiGetMaterialTexture(this,type,index,path,mapping,uvindex,blend,op,mapmode);
0074 }
0075 
0076 // ---------------------------------------------------------------------------
0077 AI_FORCE_INLINE unsigned int aiMaterial::GetTextureCount(aiTextureType type) const {
0078     return ::aiGetMaterialTextureCount(this,type);
0079 }
0080 
0081 // ---------------------------------------------------------------------------
0082 template <typename Type>
0083 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0084         unsigned int idx, Type* pOut,
0085         unsigned int* pMax) const {
0086     unsigned int iNum = pMax ? *pMax : 1;
0087 
0088     const aiMaterialProperty* prop;
0089     const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx,
0090         (const aiMaterialProperty**)&prop);
0091     if ( AI_SUCCESS == ret )    {
0092 
0093         if (prop->mDataLength < sizeof(Type)*iNum) {
0094             return AI_FAILURE;
0095         }
0096 
0097         if (prop->mType != aiPTI_Buffer) {
0098             return AI_FAILURE;
0099         }
0100 // std::min has in some cases a conflict with a defined min
0101 #ifdef min
0102 #   undef min
0103 #endif
0104         iNum = static_cast<unsigned int>(std::min(static_cast<size_t>(iNum),prop->mDataLength / sizeof(Type)));
0105         std::memcpy(pOut,prop->mData,iNum * sizeof(Type));
0106         if (pMax) {
0107             *pMax = iNum;
0108         }
0109     }
0110     return ret;
0111 }
0112 
0113 // ---------------------------------------------------------------------------
0114 template <typename Type>
0115 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0116         unsigned int idx,Type& pOut) const {
0117     const aiMaterialProperty* prop;
0118     const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx,
0119         (const aiMaterialProperty**)&prop);
0120     if ( AI_SUCCESS == ret ) {
0121 
0122         if (prop->mDataLength < sizeof(Type)) {
0123             return AI_FAILURE;
0124         }
0125 
0126         if (prop->mType != aiPTI_Buffer) {
0127             return AI_FAILURE;
0128         }
0129 
0130         ::memcpy( &pOut, prop->mData, sizeof( Type ) );
0131     }
0132     return ret;
0133 }
0134 
0135 // ---------------------------------------------------------------------------
0136 // Specialisation for a single bool.
0137 // Casts floating point and integer to bool
0138 template <>
0139 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char *pKey, unsigned int type,
0140                 unsigned int idx, bool &pOut) const {
0141     const aiMaterialProperty *prop;
0142     const aiReturn ret = ::aiGetMaterialProperty(this, pKey, type, idx,
0143             (const aiMaterialProperty **)&prop);
0144     if (AI_SUCCESS == ret) {
0145 
0146         switch (prop->mType) {
0147             // Type cannot be converted
0148         default: return AI_FAILURE;
0149 
0150         case aiPTI_Buffer: {
0151             // Native bool value storage
0152             if (prop->mDataLength < sizeof(bool)) {
0153                 return AI_FAILURE;
0154             }
0155             ::memcpy(&pOut, prop->mData, sizeof(bool));
0156         } break;
0157 
0158         case aiPTI_Float:
0159         case aiPTI_Double: {
0160             // Read as float and cast to bool
0161             ai_real value = 0.0f;
0162             if (AI_SUCCESS == ::aiGetMaterialFloat(this, pKey, type, idx, &value)) {
0163                 pOut = static_cast<bool>(value);
0164                 return AI_SUCCESS;
0165             }
0166             return AI_FAILURE;
0167         }
0168         case aiPTI_Integer: {
0169             // Cast to bool
0170             const int value = static_cast<int>(*prop->mData);
0171             pOut = static_cast<bool>(value);
0172             return AI_SUCCESS;
0173         }
0174         }
0175     }
0176     return ret;
0177 }
0178 
0179 // ---------------------------------------------------------------------------
0180 AI_FORCE_INLINE
0181 aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0182         unsigned int idx,ai_real* pOut,
0183         unsigned int* pMax) const {
0184     return ::aiGetMaterialFloatArray(this,pKey,type,idx,pOut,pMax);
0185 }
0186 // ---------------------------------------------------------------------------
0187 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0188         unsigned int idx,int* pOut,
0189         unsigned int* pMax) const {
0190     return ::aiGetMaterialIntegerArray(this,pKey,type,idx,pOut,pMax);
0191 }
0192 // ---------------------------------------------------------------------------
0193 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0194         unsigned int idx, float& pOut) const {
0195     return aiGetMaterialFloat(this,pKey,type,idx,&pOut);
0196 }
0197 // ---------------------------------------------------------------------------
0198 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0199         unsigned int idx,int& pOut) const {
0200     return aiGetMaterialInteger(this,pKey,type,idx,&pOut);
0201 }
0202 // ---------------------------------------------------------------------------
0203 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0204         unsigned int idx,aiColor4D& pOut) const {
0205     return aiGetMaterialColor(this,pKey,type,idx,&pOut);
0206 }
0207 // ---------------------------------------------------------------------------
0208 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0209         unsigned int idx,aiColor3D& pOut) const {
0210     aiColor4D c;
0211     const aiReturn ret = aiGetMaterialColor(this,pKey,type,idx,&c);
0212     if (ret == aiReturn_SUCCESS)
0213         pOut = aiColor3D(c.r,c.g,c.b);
0214     return ret;
0215 }
0216 // ---------------------------------------------------------------------------
0217 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0218         unsigned int idx,aiString& pOut) const {
0219     return aiGetMaterialString(this,pKey,type,idx,&pOut);
0220 }
0221 // ---------------------------------------------------------------------------
0222 AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
0223         unsigned int idx,aiUVTransform& pOut) const {
0224     return aiGetMaterialUVTransform(this,pKey,type,idx,&pOut);
0225 }
0226 
0227 // ---------------------------------------------------------------------------
0228 template<class TYPE>
0229 aiReturn aiMaterial::AddProperty (const TYPE* pInput,
0230         const unsigned int pNumValues, const char* pKey, unsigned int type,
0231         unsigned int index) {
0232     return AddBinaryProperty((const void*)pInput, pNumValues * sizeof(TYPE),
0233         pKey,type,index,aiPTI_Buffer);
0234 }
0235 
0236 // ---------------------------------------------------------------------------
0237 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const float* pInput,
0238         const unsigned int pNumValues,
0239         const char* pKey,
0240         unsigned int type,
0241         unsigned int index) {
0242     return AddBinaryProperty((const void*)pInput,
0243         pNumValues * sizeof(float),
0244         pKey,type,index,aiPTI_Float);
0245 }
0246 
0247 // ---------------------------------------------------------------------------
0248 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const double* pInput,
0249         const unsigned int pNumValues,
0250         const char* pKey,
0251         unsigned int type,
0252         unsigned int index) {
0253     return AddBinaryProperty((const void*)pInput,
0254         pNumValues * sizeof(double),
0255         pKey,type,index,aiPTI_Double);
0256 }
0257 
0258 // ---------------------------------------------------------------------------
0259 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput,
0260         const unsigned int pNumValues,
0261         const char* pKey,
0262         unsigned int type,
0263         unsigned int index) {
0264     return AddBinaryProperty((const void*)pInput,
0265         pNumValues * sizeof(aiUVTransform),
0266         pKey,type,index,ai_real_to_property_type_info(pInput->mRotation));
0267 }
0268 
0269 // ---------------------------------------------------------------------------
0270 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiColor4D* pInput,
0271         const unsigned int pNumValues,
0272         const char* pKey,
0273         unsigned int type,
0274         unsigned int index) {
0275     return AddBinaryProperty((const void*)pInput,
0276         pNumValues * sizeof(aiColor4D),
0277         pKey,type,index,ai_real_to_property_type_info(pInput->a));
0278 }
0279 
0280 // ---------------------------------------------------------------------------
0281 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiColor3D* pInput,
0282         const unsigned int pNumValues,
0283         const char* pKey,
0284         unsigned int type,
0285         unsigned int index) {
0286     return AddBinaryProperty((const void*)pInput,
0287         pNumValues * sizeof(aiColor3D),
0288         pKey,type,index,ai_real_to_property_type_info(pInput->b));
0289 }
0290 
0291 // ---------------------------------------------------------------------------
0292 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const aiVector3D* pInput,
0293         const unsigned int pNumValues,
0294         const char* pKey,
0295         unsigned int type,
0296         unsigned int index) {
0297     return AddBinaryProperty((const void*)pInput,
0298         pNumValues * sizeof(aiVector3D),
0299         pKey,type,index,ai_real_to_property_type_info(pInput->x));
0300 }
0301 
0302 // ---------------------------------------------------------------------------
0303 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty(const int* pInput,
0304         const unsigned int pNumValues,
0305         const char* pKey,
0306         unsigned int type,
0307         unsigned int index) {
0308     return AddBinaryProperty((const void*)pInput,
0309         pNumValues * sizeof(int),
0310         pKey,type,index,aiPTI_Integer);
0311 }
0312 
0313 // ---------------------------------------------------------------------------
0314 // The template specializations below are for backwards compatibility.
0315 // The recommended way to add material properties is using the non-template
0316 // overloads.
0317 // ---------------------------------------------------------------------------
0318 
0319 // ---------------------------------------------------------------------------
0320 template<>
0321 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty<float>(const float* pInput,
0322         const unsigned int pNumValues,
0323         const char* pKey,
0324         unsigned int type,
0325         unsigned int index) {
0326     return AddBinaryProperty((const void*)pInput,
0327         pNumValues * sizeof(float),
0328         pKey,type,index,aiPTI_Float);
0329 }
0330 
0331 // ---------------------------------------------------------------------------
0332 template<>
0333 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty<double>(const double* pInput,
0334         const unsigned int pNumValues,
0335         const char* pKey,
0336         unsigned int type,
0337         unsigned int index) {
0338     return AddBinaryProperty((const void*)pInput,
0339         pNumValues * sizeof(double),
0340         pKey,type,index,aiPTI_Double);
0341 }
0342 
0343 // ---------------------------------------------------------------------------
0344 template<>
0345 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty<aiUVTransform>(const aiUVTransform* pInput,
0346         const unsigned int pNumValues,
0347         const char* pKey,
0348         unsigned int type,
0349         unsigned int index) {
0350     return AddBinaryProperty((const void*)pInput,
0351         pNumValues * sizeof(aiUVTransform),
0352         pKey,type,index,aiPTI_Float);
0353 }
0354 
0355 // ---------------------------------------------------------------------------
0356 template<>
0357 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty<aiColor4D>(const aiColor4D* pInput,
0358         const unsigned int pNumValues,
0359         const char* pKey,
0360         unsigned int type,
0361         unsigned int index) {
0362     return AddBinaryProperty((const void*)pInput,
0363         pNumValues * sizeof(aiColor4D),
0364         pKey,type,index,aiPTI_Float);
0365 }
0366 
0367 // ---------------------------------------------------------------------------
0368 template<>
0369 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty<aiColor3D>(const aiColor3D* pInput,
0370         const unsigned int pNumValues,
0371         const char* pKey,
0372         unsigned int type,
0373         unsigned int index) {
0374     return AddBinaryProperty((const void*)pInput,
0375         pNumValues * sizeof(aiColor3D),
0376         pKey,type,index,aiPTI_Float);
0377 }
0378 
0379 // ---------------------------------------------------------------------------
0380 template<>
0381 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty<aiVector3D>(const aiVector3D* pInput,
0382         const unsigned int pNumValues,
0383         const char* pKey,
0384         unsigned int type,
0385         unsigned int index) {
0386     return AddBinaryProperty((const void*)pInput,
0387         pNumValues * sizeof(aiVector3D),
0388         pKey,type,index,aiPTI_Float);
0389 }
0390 
0391 // ---------------------------------------------------------------------------
0392 template<>
0393 AI_FORCE_INLINE aiReturn aiMaterial::AddProperty<int>(const int* pInput,
0394         const unsigned int pNumValues,
0395         const char* pKey,
0396         unsigned int type,
0397         unsigned int index) {
0398     return AddBinaryProperty((const void*)pInput,
0399         pNumValues * sizeof(int),
0400         pKey,type,index,aiPTI_Integer);
0401 }
0402 
0403 //! @endcond