2008-05-09 17:24:28 +00:00
|
|
|
/*
|
2008-05-22 10:20:31 +00:00
|
|
|
Open Asset Import Library (ASSIMP)
|
2008-05-09 17:24:28 +00:00
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2008, ASSIMP Development Team
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the ASSIMP team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the ASSIMP Development Team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
#include "MaterialSystem.h"
|
2008-06-15 10:27:08 +00:00
|
|
|
#include "StringComparison.h"
|
2008-08-06 23:01:38 +00:00
|
|
|
#include "Hash.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-06-15 10:27:08 +00:00
|
|
|
#include "../include/aiMaterial.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
#include "../include/aiAssert.h"
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
// we are using sprintf only on fixed-size buffers, so the
|
|
|
|
// compiler should automatically expand the template sprintf_s<>
|
|
|
|
#if _MSC_VER >= 1400
|
|
|
|
# define sprintf sprintf_s
|
2008-07-30 23:00:25 +00:00
|
|
|
#endif
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
aiReturn aiGetMaterialProperty(const aiMaterial* pMat,
|
|
|
|
const char* pKey,
|
|
|
|
const aiMaterialProperty** pPropOut)
|
|
|
|
{
|
|
|
|
ai_assert (pMat != NULL);
|
|
|
|
ai_assert (pKey != NULL);
|
|
|
|
ai_assert (pPropOut != NULL);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < pMat->mNumProperties;++i)
|
|
|
|
{
|
|
|
|
if (NULL != pMat->mProperties[i])
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
if (0 == ASSIMP_stricmp( pMat->mProperties[i]->mKey.data, pKey ))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
*pPropOut = pMat->mProperties[i];
|
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pPropOut = NULL;
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
|
|
|
|
const char* pKey,
|
|
|
|
float* pOut,
|
|
|
|
unsigned int* pMax)
|
|
|
|
{
|
|
|
|
ai_assert (pMat != NULL);
|
|
|
|
ai_assert (pKey != NULL);
|
|
|
|
ai_assert (pOut != NULL);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < pMat->mNumProperties;++i)
|
|
|
|
{
|
|
|
|
if (NULL != pMat->mProperties[i])
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
if (0 == ASSIMP_stricmp( pMat->mProperties[i]->mKey.data, pKey ))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// data is given in floats, simply copy it
|
|
|
|
if( aiPTI_Float == pMat->mProperties[i]->mType ||
|
|
|
|
aiPTI_Buffer == pMat->mProperties[i]->mType)
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
unsigned int iWrite = pMat->mProperties[i]->mDataLength / sizeof(float);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
if (NULL != pMax)
|
|
|
|
iWrite = *pMax < iWrite ? *pMax : iWrite;
|
|
|
|
|
|
|
|
memcpy (pOut, pMat->mProperties[i]->mData, iWrite * sizeof (float));
|
|
|
|
|
|
|
|
if (NULL != pMax)
|
|
|
|
*pMax = iWrite;
|
|
|
|
}
|
|
|
|
// data is given in ints, convert to float
|
|
|
|
else if( aiPTI_Integer == pMat->mProperties[i]->mType)
|
|
|
|
{
|
|
|
|
unsigned int iWrite = pMat->mProperties[i]->
|
|
|
|
mDataLength / sizeof(int);
|
|
|
|
|
|
|
|
if (NULL != pMax)
|
|
|
|
iWrite = *pMax < iWrite ? *pMax : iWrite;
|
|
|
|
|
|
|
|
for (unsigned int a = 0; a < iWrite;++a)
|
|
|
|
{
|
|
|
|
pOut[a] = (float) ((int*)pMat->mProperties[i]->mData)[a];
|
|
|
|
}
|
|
|
|
if (NULL != pMax)
|
|
|
|
*pMax = iWrite;
|
|
|
|
}
|
|
|
|
// it is a string ... no way to read something out of this
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NULL != pMax)
|
|
|
|
*pMax = 0;
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
aiReturn aiGetMaterialIntegerArray(const aiMaterial* pMat,
|
|
|
|
const char* pKey,
|
|
|
|
int* pOut,
|
|
|
|
unsigned int* pMax)
|
|
|
|
{
|
|
|
|
ai_assert (pMat != NULL);
|
|
|
|
ai_assert (pKey != NULL);
|
|
|
|
ai_assert (pOut != NULL);
|
|
|
|
for (unsigned int i = 0; i < pMat->mNumProperties;++i)
|
|
|
|
{
|
|
|
|
if (NULL != pMat->mProperties[i])
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
if (0 == ASSIMP_stricmp( pMat->mProperties[i]->mKey.data, pKey ))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// data is given in ints, simply copy it
|
|
|
|
if( aiPTI_Integer == pMat->mProperties[i]->mType ||
|
|
|
|
aiPTI_Buffer == pMat->mProperties[i]->mType)
|
|
|
|
{
|
|
|
|
unsigned int iWrite = pMat->mProperties[i]->
|
|
|
|
mDataLength / sizeof(int);
|
|
|
|
|
|
|
|
if (NULL != pMax)
|
|
|
|
iWrite = *pMax < iWrite ? *pMax : iWrite;
|
|
|
|
|
|
|
|
memcpy (pOut, pMat->mProperties[i]->mData, iWrite * sizeof (int));
|
|
|
|
|
|
|
|
if (NULL != pMax)
|
|
|
|
*pMax = iWrite;
|
|
|
|
}
|
|
|
|
// data is given in floats convert to int (lossy!)
|
|
|
|
else if( aiPTI_Float == pMat->mProperties[i]->mType)
|
|
|
|
{
|
|
|
|
unsigned int iWrite = pMat->mProperties[i]->
|
|
|
|
mDataLength / sizeof(float);
|
|
|
|
|
|
|
|
if (NULL != pMax)
|
|
|
|
iWrite = *pMax < iWrite ? *pMax : iWrite;
|
|
|
|
|
|
|
|
for (unsigned int a = 0; a < iWrite;++a)
|
|
|
|
{
|
|
|
|
pOut[a] = (int) ((float*)pMat->mProperties[i]->mData)[a];
|
|
|
|
}
|
|
|
|
if (NULL != pMax)
|
|
|
|
*pMax = iWrite;
|
|
|
|
}
|
|
|
|
// it is a string ... no way to read something out of this
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (NULL != pMax)
|
|
|
|
*pMax = 0;
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
aiReturn aiGetMaterialColor(const aiMaterial* pMat,
|
|
|
|
const char* pKey,
|
|
|
|
aiColor4D* pOut)
|
|
|
|
{
|
|
|
|
unsigned int iMax = 4;
|
|
|
|
aiReturn eRet = aiGetMaterialFloatArray(pMat,pKey,(float*)pOut,&iMax);
|
|
|
|
|
|
|
|
// if no alpha channel is provided set it to 1.0 by default
|
|
|
|
if (3 == iMax)pOut->a = 1.0f;
|
|
|
|
return eRet;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
aiReturn aiGetMaterialString(const aiMaterial* pMat,
|
|
|
|
const char* pKey,
|
|
|
|
aiString* pOut)
|
|
|
|
{
|
|
|
|
ai_assert (pMat != NULL);
|
|
|
|
ai_assert (pKey != NULL);
|
|
|
|
ai_assert (pOut != NULL);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < pMat->mNumProperties;++i)
|
|
|
|
{
|
|
|
|
if (NULL != pMat->mProperties[i])
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
if (0 == ASSIMP_stricmp( pMat->mProperties[i]->mKey.data, pKey ))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
if( aiPTI_String == pMat->mProperties[i]->mType)
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
const aiString* pcSrc = (const aiString*)pMat->mProperties[i]->mData;
|
|
|
|
::memcpy (pOut->data, pcSrc->data, (pOut->length = pcSrc->length)+1);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
// wrong type
|
|
|
|
else return AI_FAILURE;
|
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-08-06 23:01:38 +00:00
|
|
|
MaterialHelper::MaterialHelper()
|
|
|
|
{
|
|
|
|
// allocate 5 entries by default
|
|
|
|
this->mNumProperties = 0;
|
|
|
|
this->mNumAllocated = 5;
|
|
|
|
this->mProperties = new aiMaterialProperty*[5];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
MaterialHelper::~MaterialHelper()
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < this->mNumProperties;++i)
|
|
|
|
{
|
|
|
|
// be careful ...
|
|
|
|
if(NULL != this->mProperties[i])
|
|
|
|
{
|
|
|
|
delete[] this->mProperties[i]->mData;
|
|
|
|
delete this->mProperties[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-07-30 23:00:25 +00:00
|
|
|
uint32_t MaterialHelper::ComputeHash()
|
|
|
|
{
|
|
|
|
uint32_t hash = 1503; // magic start value, choosen to be my birthday :-)
|
|
|
|
for (unsigned int i = 0; i < this->mNumProperties;++i)
|
|
|
|
{
|
|
|
|
aiMaterialProperty* prop;
|
|
|
|
|
|
|
|
// NOTE: We need to exclude the material name from the hash
|
2008-08-06 23:01:38 +00:00
|
|
|
if ((prop = this->mProperties[i]) && 0 != ::strcmp(prop->mKey.data,AI_MATKEY_NAME))
|
2008-07-30 23:00:25 +00:00
|
|
|
{
|
2008-08-28 17:35:36 +00:00
|
|
|
hash = SuperFastHash(prop->mKey.data,(unsigned int)prop->mKey.length,hash);
|
2008-07-30 23:00:25 +00:00
|
|
|
hash = SuperFastHash(prop->mData,prop->mDataLength,hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
aiReturn MaterialHelper::RemoveProperty (const char* pKey)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != pKey);
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < this->mNumProperties;++i)
|
|
|
|
{
|
2008-07-30 23:00:25 +00:00
|
|
|
if (this->mProperties[i]) // just for safety
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
if (0 == ASSIMP_stricmp( this->mProperties[i]->mKey.data, pKey ))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
|
|
|
// delete this entry
|
|
|
|
delete[] this->mProperties[i]->mData;
|
|
|
|
delete this->mProperties[i];
|
|
|
|
|
|
|
|
// collapse the array behind --.
|
|
|
|
--this->mNumProperties;
|
|
|
|
for (unsigned int a = i; a < this->mNumProperties;++a)
|
|
|
|
{
|
|
|
|
this->mProperties[a] = this->mProperties[a+1];
|
|
|
|
}
|
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
aiReturn MaterialHelper::AddBinaryProperty (const void* pInput,
|
|
|
|
const unsigned int pSizeInBytes,
|
|
|
|
const char* pKey,
|
|
|
|
aiPropertyTypeInfo pType)
|
|
|
|
{
|
|
|
|
ai_assert (pInput != NULL);
|
|
|
|
ai_assert (pKey != NULL);
|
|
|
|
ai_assert (0 != pSizeInBytes);
|
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
// first search the list whether there is already an entry
|
|
|
|
// with this name.
|
|
|
|
unsigned int iOutIndex = 0xFFFFFFFF;
|
|
|
|
for (unsigned int i = 0; i < this->mNumProperties;++i)
|
|
|
|
{
|
2008-07-30 23:00:25 +00:00
|
|
|
if (this->mProperties[i])
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
if (0 == ASSIMP_stricmp( this->mProperties[i]->mKey.data, pKey ))
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
|
|
|
// delete this entry
|
|
|
|
delete[] this->mProperties[i]->mData;
|
|
|
|
delete this->mProperties[i];
|
|
|
|
iOutIndex = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
aiMaterialProperty* pcNew = new aiMaterialProperty();
|
|
|
|
|
|
|
|
// fill this
|
|
|
|
pcNew->mType = pType;
|
|
|
|
|
|
|
|
pcNew->mDataLength = pSizeInBytes;
|
|
|
|
pcNew->mData = new char[pSizeInBytes];
|
|
|
|
memcpy (pcNew->mData,pInput,pSizeInBytes);
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
pcNew->mKey.length = ::strlen(pKey);
|
|
|
|
ai_assert ( MAXLEN > pcNew->mKey.length);
|
|
|
|
::strcpy( pcNew->mKey.data, pKey );
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
if (0xFFFFFFFF != iOutIndex)
|
|
|
|
{
|
|
|
|
this->mProperties[iOutIndex] = pcNew;
|
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-07-30 23:00:25 +00:00
|
|
|
// resize the array ... allocate storage for 5 other properties
|
2008-05-05 12:36:31 +00:00
|
|
|
if (this->mNumProperties == this->mNumAllocated)
|
|
|
|
{
|
|
|
|
unsigned int iOld = this->mNumAllocated;
|
|
|
|
this->mNumAllocated += 5;
|
|
|
|
|
|
|
|
aiMaterialProperty** ppTemp = new aiMaterialProperty*[this->mNumAllocated];
|
|
|
|
if (NULL == ppTemp)return AI_OUTOFMEMORY;
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
::memcpy (ppTemp,this->mProperties,iOld * sizeof(void*));
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
delete[] this->mProperties;
|
|
|
|
this->mProperties = ppTemp;
|
|
|
|
}
|
|
|
|
// push back ...
|
|
|
|
this->mProperties[this->mNumProperties++] = pcNew;
|
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-05 12:36:31 +00:00
|
|
|
aiReturn MaterialHelper::AddProperty (const aiString* pInput,
|
|
|
|
const char* pKey)
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
// fix ... don't keep the whole string buffer
|
2008-08-28 17:35:36 +00:00
|
|
|
return this->AddBinaryProperty(pInput,(unsigned int)pInput->length+1+
|
|
|
|
(unsigned int)(((uint8_t*)&pInput->data - (uint8_t*)&pInput->length)),
|
2008-08-06 23:01:38 +00:00
|
|
|
pKey,aiPTI_String);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void MaterialHelper::CopyPropertyList(MaterialHelper* pcDest,
|
|
|
|
const MaterialHelper* pcSrc)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != pcDest);
|
|
|
|
ai_assert(NULL != pcSrc);
|
|
|
|
|
|
|
|
unsigned int iOldNum = pcDest->mNumProperties;
|
|
|
|
pcDest->mNumAllocated += pcSrc->mNumAllocated;
|
|
|
|
pcDest->mNumProperties += pcSrc->mNumProperties;
|
|
|
|
|
|
|
|
aiMaterialProperty** pcOld = pcDest->mProperties;
|
|
|
|
pcDest->mProperties = new aiMaterialProperty*[pcDest->mNumAllocated];
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
if (iOldNum && pcOld)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < iOldNum;++i)
|
|
|
|
pcDest->mProperties[i] = pcOld[i];
|
|
|
|
|
2008-08-06 23:01:38 +00:00
|
|
|
delete[] pcOld;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i)
|
|
|
|
{
|
2008-08-06 23:01:38 +00:00
|
|
|
aiMaterialProperty* propSrc = pcSrc->mProperties[i];
|
|
|
|
|
|
|
|
// search whether we have already a property with this name
|
|
|
|
// (if yes we overwrite the old one)
|
|
|
|
aiMaterialProperty* prop;
|
|
|
|
for (unsigned int q = 0; q < iOldNum;++q)
|
|
|
|
{
|
|
|
|
prop = pcDest->mProperties[q];
|
|
|
|
if (propSrc->mKey.length == prop->mKey.length &&
|
|
|
|
!ASSIMP_stricmp(propSrc->mKey.data,prop->mKey.data))
|
|
|
|
{
|
|
|
|
delete prop;
|
|
|
|
|
|
|
|
// collapse the whole array ...
|
|
|
|
::memmove(&pcDest->mProperties[q],&pcDest->mProperties[q+1],i-q);
|
|
|
|
i--;
|
|
|
|
pcDest->mNumProperties--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
prop = pcDest->mProperties[i] = new aiMaterialProperty();
|
|
|
|
prop->mKey = propSrc->mKey;
|
|
|
|
prop->mDataLength = propSrc->mDataLength;
|
|
|
|
prop->mType = propSrc->mType;
|
|
|
|
prop->mData = new char[propSrc->mDataLength];
|
|
|
|
::memcpy(prop->mData,propSrc->mData,prop->mDataLength);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-06-15 10:27:08 +00:00
|
|
|
// we need this dummy because the compiler would otherwise complain about
|
|
|
|
// empty, but controlled statements ...
|
|
|
|
void DummyAssertFunction()
|
|
|
|
{
|
|
|
|
ai_assert(false);
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
aiReturn aiGetMaterialTexture(const aiMaterial* pcMat,
|
|
|
|
unsigned int iIndex,
|
|
|
|
unsigned int iTexType,
|
|
|
|
aiString* szOut,
|
|
|
|
unsigned int* piUVIndex,
|
|
|
|
float* pfBlendFactor,
|
2008-06-03 21:50:53 +00:00
|
|
|
aiTextureOp* peTextureOp,
|
|
|
|
aiTextureMapMode* peMapMode)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != pcMat);
|
|
|
|
ai_assert(NULL != szOut);
|
|
|
|
|
|
|
|
const char* szPathBase;
|
|
|
|
const char* szUVBase;
|
|
|
|
const char* szBlendBase;
|
|
|
|
const char* szOpBase;
|
2008-06-03 21:50:53 +00:00
|
|
|
const char* aszMapModeBase[3];
|
2008-05-09 17:24:28 +00:00
|
|
|
switch (iTexType)
|
|
|
|
{
|
|
|
|
case AI_TEXTYPE_DIFFUSE:
|
2008-06-03 21:50:53 +00:00
|
|
|
szPathBase = AI_MATKEY_TEXTURE_DIFFUSE_;
|
|
|
|
szUVBase = AI_MATKEY_UVWSRC_DIFFUSE_;
|
2008-05-09 17:24:28 +00:00
|
|
|
szBlendBase = AI_MATKEY_TEXBLEND_DIFFUSE_;
|
2008-06-03 21:50:53 +00:00
|
|
|
szOpBase = AI_MATKEY_TEXOP_DIFFUSE_;
|
|
|
|
aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_DIFFUSE_;
|
|
|
|
aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_DIFFUSE_;
|
|
|
|
aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_DIFFUSE_;
|
2008-05-09 17:24:28 +00:00
|
|
|
break;
|
|
|
|
case AI_TEXTYPE_SPECULAR:
|
2008-06-03 21:50:53 +00:00
|
|
|
szPathBase = AI_MATKEY_TEXTURE_SPECULAR_;
|
|
|
|
szUVBase = AI_MATKEY_UVWSRC_SPECULAR_;
|
2008-05-09 17:24:28 +00:00
|
|
|
szBlendBase = AI_MATKEY_TEXBLEND_SPECULAR_;
|
2008-06-03 21:50:53 +00:00
|
|
|
szOpBase = AI_MATKEY_TEXOP_SPECULAR_;
|
|
|
|
aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_SPECULAR_;
|
|
|
|
aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_SPECULAR_;
|
|
|
|
aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_SPECULAR_;
|
2008-05-09 17:24:28 +00:00
|
|
|
break;
|
|
|
|
case AI_TEXTYPE_AMBIENT:
|
2008-06-03 21:50:53 +00:00
|
|
|
szPathBase = AI_MATKEY_TEXTURE_AMBIENT_;
|
|
|
|
szUVBase = AI_MATKEY_UVWSRC_AMBIENT_;
|
2008-05-09 17:24:28 +00:00
|
|
|
szBlendBase = AI_MATKEY_TEXBLEND_AMBIENT_;
|
2008-06-03 21:50:53 +00:00
|
|
|
szOpBase = AI_MATKEY_TEXOP_AMBIENT_;
|
|
|
|
aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_AMBIENT_;
|
|
|
|
aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_AMBIENT_;
|
|
|
|
aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_AMBIENT_;
|
2008-05-09 17:24:28 +00:00
|
|
|
break;
|
|
|
|
case AI_TEXTYPE_EMISSIVE:
|
2008-06-03 21:50:53 +00:00
|
|
|
szPathBase = AI_MATKEY_TEXTURE_EMISSIVE_;
|
|
|
|
szUVBase = AI_MATKEY_UVWSRC_EMISSIVE_;
|
2008-05-09 17:24:28 +00:00
|
|
|
szBlendBase = AI_MATKEY_TEXBLEND_EMISSIVE_;
|
2008-06-03 21:50:53 +00:00
|
|
|
szOpBase = AI_MATKEY_TEXOP_EMISSIVE_;
|
|
|
|
aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_EMISSIVE_;
|
|
|
|
aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_EMISSIVE_;
|
|
|
|
aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_EMISSIVE_;
|
2008-05-09 17:24:28 +00:00
|
|
|
break;
|
|
|
|
case AI_TEXTYPE_HEIGHT:
|
2008-06-03 21:50:53 +00:00
|
|
|
szPathBase = AI_MATKEY_TEXTURE_HEIGHT_;
|
|
|
|
szUVBase = AI_MATKEY_UVWSRC_HEIGHT_;
|
2008-05-09 17:24:28 +00:00
|
|
|
szBlendBase = AI_MATKEY_TEXBLEND_HEIGHT_;
|
2008-06-03 21:50:53 +00:00
|
|
|
szOpBase = AI_MATKEY_TEXOP_HEIGHT_;
|
|
|
|
aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_HEIGHT_;
|
|
|
|
aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_HEIGHT_;
|
|
|
|
aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_HEIGHT_;
|
2008-05-09 17:24:28 +00:00
|
|
|
break;
|
|
|
|
case AI_TEXTYPE_NORMALS:
|
2008-06-03 21:50:53 +00:00
|
|
|
szPathBase = AI_MATKEY_TEXTURE_NORMALS_;
|
|
|
|
szUVBase = AI_MATKEY_UVWSRC_NORMALS_;
|
2008-05-09 17:24:28 +00:00
|
|
|
szBlendBase = AI_MATKEY_TEXBLEND_NORMALS_;
|
2008-06-03 21:50:53 +00:00
|
|
|
szOpBase = AI_MATKEY_TEXOP_NORMALS_;
|
|
|
|
aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_NORMALS_;
|
|
|
|
aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_NORMALS_;
|
|
|
|
aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_NORMALS_;
|
2008-05-09 17:24:28 +00:00
|
|
|
break;
|
|
|
|
case AI_TEXTYPE_SHININESS:
|
2008-06-03 21:50:53 +00:00
|
|
|
szPathBase = AI_MATKEY_TEXTURE_SHININESS_;
|
|
|
|
szUVBase = AI_MATKEY_UVWSRC_SHININESS_;
|
2008-05-09 17:24:28 +00:00
|
|
|
szBlendBase = AI_MATKEY_TEXBLEND_SHININESS_;
|
2008-06-03 21:50:53 +00:00
|
|
|
szOpBase = AI_MATKEY_TEXOP_SHININESS_;
|
|
|
|
aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_SHININESS_;
|
|
|
|
aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_SHININESS_;
|
|
|
|
aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_SHININESS_;
|
2008-05-09 17:24:28 +00:00
|
|
|
break;
|
2008-05-13 23:26:52 +00:00
|
|
|
case AI_TEXTYPE_OPACITY:
|
2008-06-03 21:50:53 +00:00
|
|
|
szPathBase = AI_MATKEY_TEXTURE_OPACITY_;
|
|
|
|
szUVBase = AI_MATKEY_UVWSRC_OPACITY_;
|
2008-05-13 23:26:52 +00:00
|
|
|
szBlendBase = AI_MATKEY_TEXBLEND_OPACITY_;
|
2008-06-03 21:50:53 +00:00
|
|
|
szOpBase = AI_MATKEY_TEXOP_OPACITY_;
|
|
|
|
aszMapModeBase[0] = AI_MATKEY_MAPPINGMODE_U_OPACITY_;
|
|
|
|
aszMapModeBase[1] = AI_MATKEY_MAPPINGMODE_V_OPACITY_;
|
|
|
|
aszMapModeBase[2] = AI_MATKEY_MAPPINGMODE_W_OPACITY_;
|
2008-05-13 23:26:52 +00:00
|
|
|
break;
|
2008-05-09 17:24:28 +00:00
|
|
|
default: return AI_FAILURE;
|
|
|
|
};
|
|
|
|
|
|
|
|
char szKey[256];
|
2008-06-22 10:09:26 +00:00
|
|
|
if (iIndex > 100)return AI_FAILURE;
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// get the path to the texture
|
2008-06-15 10:27:08 +00:00
|
|
|
if(0 >= sprintf(szKey,"%s[%i]",szPathBase,iIndex))DummyAssertFunction();
|
2008-05-09 17:24:28 +00:00
|
|
|
if (AI_SUCCESS != aiGetMaterialString(pcMat,szKey,szOut))
|
|
|
|
{
|
|
|
|
return AI_FAILURE;
|
|
|
|
}
|
|
|
|
// get the UV index of the texture
|
|
|
|
if (piUVIndex)
|
|
|
|
{
|
|
|
|
int iUV;
|
2008-06-15 10:27:08 +00:00
|
|
|
if(0 >= sprintf(szKey,"%s[%i]",szUVBase,iIndex))DummyAssertFunction();
|
2008-05-09 17:24:28 +00:00
|
|
|
if (AI_SUCCESS != aiGetMaterialInteger(pcMat,szKey,&iUV))
|
|
|
|
iUV = 0;
|
|
|
|
|
|
|
|
*piUVIndex = iUV;
|
|
|
|
}
|
|
|
|
// get the blend factor of the texture
|
|
|
|
if (pfBlendFactor)
|
|
|
|
{
|
|
|
|
float fBlend;
|
2008-06-15 10:27:08 +00:00
|
|
|
if(0 >= sprintf(szKey,"%s[%i]",szBlendBase,iIndex))DummyAssertFunction();
|
2008-05-09 17:24:28 +00:00
|
|
|
if (AI_SUCCESS != aiGetMaterialFloat(pcMat,szKey,&fBlend))
|
|
|
|
fBlend = 1.0f;
|
|
|
|
|
|
|
|
*pfBlendFactor = fBlend;
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// get the texture operation of the texture
|
|
|
|
if (peTextureOp)
|
|
|
|
{
|
|
|
|
aiTextureOp op;
|
2008-06-15 10:27:08 +00:00
|
|
|
if(0 >= sprintf(szKey,"%s[%i]",szOpBase,iIndex))DummyAssertFunction();
|
2008-05-09 17:24:28 +00:00
|
|
|
if (AI_SUCCESS != aiGetMaterialInteger(pcMat,szKey,(int*)&op))
|
|
|
|
op = aiTextureOp_Multiply;
|
|
|
|
|
|
|
|
*peTextureOp = op;
|
|
|
|
}
|
2008-06-03 21:50:53 +00:00
|
|
|
|
|
|
|
// get the texture mapping modes for the texture
|
|
|
|
if (peMapMode)
|
|
|
|
{
|
|
|
|
aiTextureMapMode eMode;
|
|
|
|
for (unsigned int q = 0; q < 3;++q)
|
|
|
|
{
|
2008-06-15 10:27:08 +00:00
|
|
|
if(0 >= sprintf(szKey,"%s[%i]",aszMapModeBase[q],iIndex))DummyAssertFunction();
|
2008-06-03 21:50:53 +00:00
|
|
|
if (AI_SUCCESS != aiGetMaterialInteger(pcMat,szKey,(int*)&eMode))
|
|
|
|
{
|
|
|
|
eMode = aiTextureMapMode_Wrap;
|
|
|
|
}
|
|
|
|
peMapMode[q] = eMode;
|
|
|
|
}
|
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
return AI_SUCCESS;
|
|
|
|
}
|
|
|
|
|