miniassimp

diff include/miniassimp/material.inl @ 0:879c81d94345

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 28 Jan 2019 18:19:26 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/include/miniassimp/material.inl	Mon Jan 28 18:19:26 2019 +0200
     1.3 @@ -0,0 +1,390 @@
     1.4 +/*
     1.5 +---------------------------------------------------------------------------
     1.6 +Open Asset Import Library (assimp)
     1.7 +---------------------------------------------------------------------------
     1.8 +
     1.9 +Copyright (c) 2006-2018, assimp team
    1.10 +
    1.11 +
    1.12 +
    1.13 +All rights reserved.
    1.14 +
    1.15 +Redistribution and use of this software in source and binary forms,
    1.16 +with or without modification, are permitted provided that the following
    1.17 +conditions are met:
    1.18 +
    1.19 +* Redistributions of source code must retain the above
    1.20 +  copyright notice, this list of conditions and the
    1.21 +  following disclaimer.
    1.22 +
    1.23 +* Redistributions in binary form must reproduce the above
    1.24 +  copyright notice, this list of conditions and the
    1.25 +  following disclaimer in the documentation and/or other
    1.26 +  materials provided with the distribution.
    1.27 +
    1.28 +* Neither the name of the assimp team, nor the names of its
    1.29 +  contributors may be used to endorse or promote products
    1.30 +  derived from this software without specific prior
    1.31 +  written permission of the assimp team.
    1.32 +
    1.33 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.34 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.35 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.36 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.37 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.38 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.39 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.40 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.41 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.42 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.43 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.44 +---------------------------------------------------------------------------
    1.45 +*/
    1.46 +
    1.47 +/** @file material.inl
    1.48 + *  @brief Defines the C++ getters for the material system
    1.49 + */
    1.50 +
    1.51 +#pragma once
    1.52 +#ifndef AI_MATERIAL_INL_INC
    1.53 +#define AI_MATERIAL_INL_INC
    1.54 +
    1.55 +// ---------------------------------------------------------------------------
    1.56 +inline aiPropertyTypeInfo ai_real_to_property_type_info(float)
    1.57 +{
    1.58 +	return aiPTI_Float;
    1.59 +}
    1.60 +
    1.61 +inline aiPropertyTypeInfo ai_real_to_property_type_info(double)
    1.62 +{
    1.63 +	return aiPTI_Double;
    1.64 +}
    1.65 +// ---------------------------------------------------------------------------
    1.66 +
    1.67 +//! @cond never
    1.68 +
    1.69 +// ---------------------------------------------------------------------------
    1.70 +inline aiReturn aiMaterial::GetTexture( aiTextureType type,
    1.71 +   unsigned int  index,
    1.72 +   C_STRUCT aiString* path,
    1.73 +   aiTextureMapping* mapping    /*= NULL*/,
    1.74 +   unsigned int* uvindex        /*= NULL*/,
    1.75 +   ai_real* blend               /*= NULL*/,
    1.76 +   aiTextureOp* op              /*= NULL*/,
    1.77 +   aiTextureMapMode* mapmode    /*= NULL*/) const
    1.78 +{
    1.79 +    return ::aiGetMaterialTexture(this,type,index,path,mapping,uvindex,blend,op,mapmode);
    1.80 +}
    1.81 +
    1.82 +// ---------------------------------------------------------------------------
    1.83 +inline unsigned int aiMaterial::GetTextureCount(aiTextureType type) const
    1.84 +{
    1.85 +    return ::aiGetMaterialTextureCount(this,type);
    1.86 +}
    1.87 +
    1.88 +// ---------------------------------------------------------------------------
    1.89 +template <typename Type>
    1.90 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
    1.91 +    unsigned int idx, Type* pOut,
    1.92 +    unsigned int* pMax) const
    1.93 +{
    1.94 +    unsigned int iNum = pMax ? *pMax : 1;
    1.95 +
    1.96 +    const aiMaterialProperty* prop;
    1.97 +    const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx,
    1.98 +        (const aiMaterialProperty**)&prop);
    1.99 +    if ( AI_SUCCESS == ret )    {
   1.100 +
   1.101 +        if (prop->mDataLength < sizeof(Type)*iNum) {
   1.102 +            return AI_FAILURE;
   1.103 +        }
   1.104 +
   1.105 +        if (prop->mType != aiPTI_Buffer) {
   1.106 +            return AI_FAILURE;
   1.107 +        }
   1.108 +
   1.109 +        iNum = std::min((size_t)iNum,prop->mDataLength / sizeof(Type));
   1.110 +        ::memcpy(pOut,prop->mData,iNum * sizeof(Type));
   1.111 +        if (pMax) {
   1.112 +            *pMax = iNum;
   1.113 +        }
   1.114 +    }
   1.115 +    return ret;
   1.116 +}
   1.117 +
   1.118 +// ---------------------------------------------------------------------------
   1.119 +template <typename Type>
   1.120 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.121 +    unsigned int idx,Type& pOut) const
   1.122 +{
   1.123 +    const aiMaterialProperty* prop;
   1.124 +    const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx,
   1.125 +        (const aiMaterialProperty**)&prop);
   1.126 +    if ( AI_SUCCESS == ret ) {
   1.127 +
   1.128 +        if (prop->mDataLength < sizeof(Type)) {
   1.129 +            return AI_FAILURE;
   1.130 +        }
   1.131 +
   1.132 +        if (prop->mType != aiPTI_Buffer) {
   1.133 +            return AI_FAILURE;
   1.134 +        }
   1.135 +
   1.136 +        ::memcpy( &pOut, prop->mData, sizeof( Type ) );
   1.137 +    }
   1.138 +    return ret;
   1.139 +}
   1.140 +
   1.141 +// ---------------------------------------------------------------------------
   1.142 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.143 +    unsigned int idx,ai_real* pOut,
   1.144 +    unsigned int* pMax) const
   1.145 +{
   1.146 +    return ::aiGetMaterialFloatArray(this,pKey,type,idx,pOut,pMax);
   1.147 +}
   1.148 +// ---------------------------------------------------------------------------
   1.149 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.150 +    unsigned int idx,int* pOut,
   1.151 +    unsigned int* pMax) const
   1.152 +{
   1.153 +    return ::aiGetMaterialIntegerArray(this,pKey,type,idx,pOut,pMax);
   1.154 +}
   1.155 +// ---------------------------------------------------------------------------
   1.156 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.157 +    unsigned int idx,ai_real& pOut) const
   1.158 +{
   1.159 +    return aiGetMaterialFloat(this,pKey,type,idx,&pOut);
   1.160 +}
   1.161 +// ---------------------------------------------------------------------------
   1.162 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.163 +    unsigned int idx,int& pOut) const
   1.164 +{
   1.165 +    return aiGetMaterialInteger(this,pKey,type,idx,&pOut);
   1.166 +}
   1.167 +// ---------------------------------------------------------------------------
   1.168 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.169 +    unsigned int idx,aiColor4D& pOut) const
   1.170 +{
   1.171 +    return aiGetMaterialColor(this,pKey,type,idx,&pOut);
   1.172 +}
   1.173 +// ---------------------------------------------------------------------------
   1.174 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.175 +    unsigned int idx,aiColor3D& pOut) const
   1.176 +{
   1.177 +    aiColor4D c;
   1.178 +    const aiReturn ret = aiGetMaterialColor(this,pKey,type,idx,&c);
   1.179 +    pOut = aiColor3D(c.r,c.g,c.b);
   1.180 +    return ret;
   1.181 +}
   1.182 +// ---------------------------------------------------------------------------
   1.183 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.184 +    unsigned int idx,aiString& pOut) const
   1.185 +{
   1.186 +    return aiGetMaterialString(this,pKey,type,idx,&pOut);
   1.187 +}
   1.188 +// ---------------------------------------------------------------------------
   1.189 +inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
   1.190 +    unsigned int idx,aiUVTransform& pOut) const
   1.191 +{
   1.192 +    return aiGetMaterialUVTransform(this,pKey,type,idx,&pOut);
   1.193 +}
   1.194 +
   1.195 +
   1.196 +// ---------------------------------------------------------------------------
   1.197 +template<class TYPE>
   1.198 +aiReturn aiMaterial::AddProperty (const TYPE* pInput,
   1.199 +    const unsigned int pNumValues,
   1.200 +    const char* pKey,
   1.201 +    unsigned int type,
   1.202 +    unsigned int index)
   1.203 +{
   1.204 +    return AddBinaryProperty((const void*)pInput,
   1.205 +        pNumValues * sizeof(TYPE),
   1.206 +        pKey,type,index,aiPTI_Buffer);
   1.207 +}
   1.208 +
   1.209 +// ---------------------------------------------------------------------------
   1.210 +inline aiReturn aiMaterial::AddProperty(const float* 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(float),
   1.218 +        pKey,type,index,aiPTI_Float);
   1.219 +}
   1.220 +
   1.221 +// ---------------------------------------------------------------------------
   1.222 +inline aiReturn aiMaterial::AddProperty(const double* pInput,
   1.223 +    const unsigned int pNumValues,
   1.224 +    const char* pKey,
   1.225 +    unsigned int type,
   1.226 +    unsigned int index)
   1.227 +{
   1.228 +    return AddBinaryProperty((const void*)pInput,
   1.229 +        pNumValues * sizeof(double),
   1.230 +        pKey,type,index,aiPTI_Double);
   1.231 +}
   1.232 +
   1.233 +// ---------------------------------------------------------------------------
   1.234 +inline aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput,
   1.235 +    const unsigned int pNumValues,
   1.236 +    const char* pKey,
   1.237 +    unsigned int type,
   1.238 +    unsigned int index)
   1.239 +{
   1.240 +    return AddBinaryProperty((const void*)pInput,
   1.241 +        pNumValues * sizeof(aiUVTransform),
   1.242 +        pKey,type,index,ai_real_to_property_type_info(pInput->mRotation));
   1.243 +}
   1.244 +
   1.245 +// ---------------------------------------------------------------------------
   1.246 +inline aiReturn aiMaterial::AddProperty(const aiColor4D* pInput,
   1.247 +    const unsigned int pNumValues,
   1.248 +    const char* pKey,
   1.249 +    unsigned int type,
   1.250 +    unsigned int index)
   1.251 +{
   1.252 +    return AddBinaryProperty((const void*)pInput,
   1.253 +        pNumValues * sizeof(aiColor4D),
   1.254 +        pKey,type,index,ai_real_to_property_type_info(pInput->a));
   1.255 +}
   1.256 +
   1.257 +// ---------------------------------------------------------------------------
   1.258 +inline aiReturn aiMaterial::AddProperty(const aiColor3D* pInput,
   1.259 +    const unsigned int pNumValues,
   1.260 +    const char* pKey,
   1.261 +    unsigned int type,
   1.262 +    unsigned int index)
   1.263 +{
   1.264 +    return AddBinaryProperty((const void*)pInput,
   1.265 +        pNumValues * sizeof(aiColor3D),
   1.266 +        pKey,type,index,ai_real_to_property_type_info(pInput->b));
   1.267 +}
   1.268 +
   1.269 +// ---------------------------------------------------------------------------
   1.270 +inline aiReturn aiMaterial::AddProperty(const aiVector3D* pInput,
   1.271 +    const unsigned int pNumValues,
   1.272 +    const char* pKey,
   1.273 +    unsigned int type,
   1.274 +    unsigned int index)
   1.275 +{
   1.276 +    return AddBinaryProperty((const void*)pInput,
   1.277 +        pNumValues * sizeof(aiVector3D),
   1.278 +        pKey,type,index,ai_real_to_property_type_info(pInput->x));
   1.279 +}
   1.280 +
   1.281 +// ---------------------------------------------------------------------------
   1.282 +inline aiReturn aiMaterial::AddProperty(const int* pInput,
   1.283 +    const unsigned int pNumValues,
   1.284 +    const char* pKey,
   1.285 +    unsigned int type,
   1.286 +    unsigned int index)
   1.287 +{
   1.288 +    return AddBinaryProperty((const void*)pInput,
   1.289 +        pNumValues * sizeof(int),
   1.290 +        pKey,type,index,aiPTI_Integer);
   1.291 +}
   1.292 +
   1.293 +
   1.294 +// ---------------------------------------------------------------------------
   1.295 +// The template specializations below are for backwards compatibility.
   1.296 +// The recommended way to add material properties is using the non-template
   1.297 +// overloads.
   1.298 +// ---------------------------------------------------------------------------
   1.299 +
   1.300 +// ---------------------------------------------------------------------------
   1.301 +template<>
   1.302 +inline aiReturn aiMaterial::AddProperty<float>(const float* pInput,
   1.303 +    const unsigned int pNumValues,
   1.304 +    const char* pKey,
   1.305 +    unsigned int type,
   1.306 +    unsigned int index)
   1.307 +{
   1.308 +    return AddBinaryProperty((const void*)pInput,
   1.309 +        pNumValues * sizeof(float),
   1.310 +        pKey,type,index,aiPTI_Float);
   1.311 +}
   1.312 +
   1.313 +// ---------------------------------------------------------------------------
   1.314 +template<>
   1.315 +inline aiReturn aiMaterial::AddProperty<double>(const double* pInput,
   1.316 +    const unsigned int pNumValues,
   1.317 +    const char* pKey,
   1.318 +    unsigned int type,
   1.319 +    unsigned int index)
   1.320 +{
   1.321 +    return AddBinaryProperty((const void*)pInput,
   1.322 +        pNumValues * sizeof(double),
   1.323 +        pKey,type,index,aiPTI_Double);
   1.324 +}
   1.325 +
   1.326 +// ---------------------------------------------------------------------------
   1.327 +template<>
   1.328 +inline aiReturn aiMaterial::AddProperty<aiUVTransform>(const aiUVTransform* pInput,
   1.329 +    const unsigned int pNumValues,
   1.330 +    const char* pKey,
   1.331 +    unsigned int type,
   1.332 +    unsigned int index)
   1.333 +{
   1.334 +    return AddBinaryProperty((const void*)pInput,
   1.335 +        pNumValues * sizeof(aiUVTransform),
   1.336 +        pKey,type,index,aiPTI_Float);
   1.337 +}
   1.338 +
   1.339 +// ---------------------------------------------------------------------------
   1.340 +template<>
   1.341 +inline aiReturn aiMaterial::AddProperty<aiColor4D>(const aiColor4D* pInput,
   1.342 +    const unsigned int pNumValues,
   1.343 +    const char* pKey,
   1.344 +    unsigned int type,
   1.345 +    unsigned int index)
   1.346 +{
   1.347 +    return AddBinaryProperty((const void*)pInput,
   1.348 +        pNumValues * sizeof(aiColor4D),
   1.349 +        pKey,type,index,aiPTI_Float);
   1.350 +}
   1.351 +
   1.352 +// ---------------------------------------------------------------------------
   1.353 +template<>
   1.354 +inline aiReturn aiMaterial::AddProperty<aiColor3D>(const aiColor3D* pInput,
   1.355 +    const unsigned int pNumValues,
   1.356 +    const char* pKey,
   1.357 +    unsigned int type,
   1.358 +    unsigned int index)
   1.359 +{
   1.360 +    return AddBinaryProperty((const void*)pInput,
   1.361 +        pNumValues * sizeof(aiColor3D),
   1.362 +        pKey,type,index,aiPTI_Float);
   1.363 +}
   1.364 +
   1.365 +// ---------------------------------------------------------------------------
   1.366 +template<>
   1.367 +inline aiReturn aiMaterial::AddProperty<aiVector3D>(const aiVector3D* pInput,
   1.368 +    const unsigned int pNumValues,
   1.369 +    const char* pKey,
   1.370 +    unsigned int type,
   1.371 +    unsigned int index)
   1.372 +{
   1.373 +    return AddBinaryProperty((const void*)pInput,
   1.374 +        pNumValues * sizeof(aiVector3D),
   1.375 +        pKey,type,index,aiPTI_Float);
   1.376 +}
   1.377 +
   1.378 +// ---------------------------------------------------------------------------
   1.379 +template<>
   1.380 +inline aiReturn aiMaterial::AddProperty<int>(const int* pInput,
   1.381 +    const unsigned int pNumValues,
   1.382 +    const char* pKey,
   1.383 +    unsigned int type,
   1.384 +    unsigned int index)
   1.385 +{
   1.386 +    return AddBinaryProperty((const void*)pInput,
   1.387 +        pNumValues * sizeof(int),
   1.388 +        pKey,type,index,aiPTI_Integer);
   1.389 +}
   1.390 +
   1.391 +//! @endcond
   1.392 +
   1.393 +#endif //! AI_MATERIAL_INL_INC