fix invalid check

pull/3012/head
Kim Kulling 2020-03-22 14:21:24 +01:00
parent 14860f3822
commit c0ae9b6040
4 changed files with 248 additions and 329 deletions

View File

@ -41,85 +41,77 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/** @file Implementation of the material part of the MDL importer class */ /** @file Implementation of the material part of the MDL importer class */
#ifndef ASSIMP_BUILD_NO_MDL_IMPORTER #ifndef ASSIMP_BUILD_NO_MDL_IMPORTER
// internal headers // internal headers
#include "MDLLoader.h"
#include "MDLDefaultColorMap.h" #include "MDLDefaultColorMap.h"
#include <assimp/StringUtils.h> #include "MDLLoader.h"
#include <assimp/texture.h>
#include <assimp/IOSystem.hpp>
#include <assimp/DefaultLogger.hpp>
#include <assimp/scene.h>
#include <assimp/Defines.h> #include <assimp/Defines.h>
#include <assimp/StringUtils.h>
#include <assimp/qnan.h> #include <assimp/qnan.h>
#include <assimp/scene.h>
#include <assimp/texture.h>
#include <assimp/DefaultLogger.hpp>
#include <assimp/IOSystem.hpp>
#include <memory> #include <memory>
using namespace Assimp; using namespace Assimp;
static aiTexel* const bad_texel = reinterpret_cast<aiTexel*>(SIZE_MAX);
static aiTexel *const bad_texel = reinterpret_cast<aiTexel *>(SIZE_MAX);
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Find a suitable palette file or take the default one // Find a suitable palette file or take the default one
void MDLImporter::SearchPalette(const unsigned char** pszColorMap) void MDLImporter::SearchPalette(const unsigned char **pszColorMap) {
{
// now try to find the color map in the current directory // now try to find the color map in the current directory
IOStream* pcStream = mIOHandler->Open(configPalette,"rb"); IOStream *pcStream = mIOHandler->Open(configPalette, "rb");
const unsigned char* szColorMap = (const unsigned char*)::g_aclrDefaultColorMap; const unsigned char *szColorMap = (const unsigned char *)::g_aclrDefaultColorMap;
if(pcStream) if (pcStream) {
{ if (pcStream->FileSize() >= 768) {
if (pcStream->FileSize() >= 768)
{
size_t len = 256 * 3; size_t len = 256 * 3;
unsigned char* colorMap = new unsigned char[len]; unsigned char *colorMap = new unsigned char[len];
szColorMap = colorMap; szColorMap = colorMap;
pcStream->Read(colorMap, len,1); pcStream->Read(colorMap, len, 1);
ASSIMP_LOG_INFO("Found valid colormap.lmp in directory. " ASSIMP_LOG_INFO("Found valid colormap.lmp in directory. "
"It will be used to decode embedded textures in palletized formats."); "It will be used to decode embedded textures in palletized formats.");
} }
delete pcStream; delete pcStream;
pcStream = NULL; pcStream = nullptr;
} }
*pszColorMap = szColorMap; *pszColorMap = szColorMap;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Free the palette again // Free the palette again
void MDLImporter::FreePalette(const unsigned char* szColorMap) void MDLImporter::FreePalette(const unsigned char *szColorMap) {
{ if (szColorMap != (const unsigned char *)::g_aclrDefaultColorMap) {
if (szColorMap != (const unsigned char*)::g_aclrDefaultColorMap)
delete[] szColorMap; delete[] szColorMap;
}
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Check whether we can replace a texture with a single color // Check whether we can replace a texture with a single color
aiColor4D MDLImporter::ReplaceTextureWithColor(const aiTexture* pcTexture) aiColor4D MDLImporter::ReplaceTextureWithColor(const aiTexture *pcTexture) {
{ ai_assert(nullptr != pcTexture);
ai_assert(NULL != pcTexture);
aiColor4D clrOut; aiColor4D clrOut;
clrOut.r = get_qnan(); clrOut.r = get_qnan();
if (!pcTexture->mHeight || !pcTexture->mWidth) if (!pcTexture->mHeight || !pcTexture->mWidth)
return clrOut; return clrOut;
const unsigned int iNumPixels = pcTexture->mHeight*pcTexture->mWidth; const unsigned int iNumPixels = pcTexture->mHeight * pcTexture->mWidth;
const aiTexel* pcTexel = pcTexture->pcData+1; const aiTexel *pcTexel = pcTexture->pcData + 1;
const aiTexel* const pcTexelEnd = &pcTexture->pcData[iNumPixels]; const aiTexel *const pcTexelEnd = &pcTexture->pcData[iNumPixels];
while (pcTexel != pcTexelEnd) while (pcTexel != pcTexelEnd) {
{ if (*pcTexel != *(pcTexel - 1)) {
if (*pcTexel != *(pcTexel-1)) pcTexel = nullptr;
{
pcTexel = NULL;
break; break;
} }
++pcTexel; ++pcTexel;
} }
if (pcTexel) if (pcTexel) {
{
clrOut.r = pcTexture->pcData->r / 255.0f; clrOut.r = pcTexture->pcData->r / 255.0f;
clrOut.g = pcTexture->pcData->g / 255.0f; clrOut.g = pcTexture->pcData->g / 255.0f;
clrOut.b = pcTexture->pcData->b / 255.0f; clrOut.b = pcTexture->pcData->b / 255.0f;
@ -130,28 +122,26 @@ aiColor4D MDLImporter::ReplaceTextureWithColor(const aiTexture* pcTexture)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Read a texture from a MDL3 file // Read a texture from a MDL3 file
void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char* szData) void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char *szData) {
{ const MDL::Header *pcHeader = (const MDL::Header *)mBuffer; //the endianness is already corrected in the InternReadFile_3DGS_MDL345 function
const MDL::Header *pcHeader = (const MDL::Header*)mBuffer; //the endianness is already corrected in the InternReadFile_3DGS_MDL345 function
VALIDATE_FILE_SIZE(szData + pcHeader->skinwidth * VALIDATE_FILE_SIZE(szData + pcHeader->skinwidth *
pcHeader->skinheight); pcHeader->skinheight);
// allocate a new texture object // allocate a new texture object
aiTexture* pcNew = new aiTexture(); aiTexture *pcNew = new aiTexture();
pcNew->mWidth = pcHeader->skinwidth; pcNew->mWidth = pcHeader->skinwidth;
pcNew->mHeight = pcHeader->skinheight; pcNew->mHeight = pcHeader->skinheight;
pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight]; pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight];
const unsigned char* szColorMap; const unsigned char *szColorMap;
this->SearchPalette(&szColorMap); this->SearchPalette(&szColorMap);
// copy texture data // copy texture data
for (unsigned int i = 0; i < pcNew->mWidth*pcNew->mHeight;++i) for (unsigned int i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
{
const unsigned char val = szData[i]; const unsigned char val = szData[i];
const unsigned char* sz = &szColorMap[val*3]; const unsigned char *sz = &szColorMap[val * 3];
pcNew->pcData[i].a = 0xFF; pcNew->pcData[i].a = 0xFF;
pcNew->pcData[i].r = *sz++; pcNew->pcData[i].r = *sz++;
@ -162,29 +152,26 @@ void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char* szData)
FreePalette(szColorMap); FreePalette(szColorMap);
// store the texture // store the texture
aiTexture** pc = this->pScene->mTextures; aiTexture **pc = this->pScene->mTextures;
this->pScene->mTextures = new aiTexture*[pScene->mNumTextures+1]; this->pScene->mTextures = new aiTexture *[pScene->mNumTextures + 1];
for (unsigned int i = 0; i <pScene->mNumTextures;++i) for (unsigned int i = 0; i < pScene->mNumTextures; ++i)
pScene->mTextures[i] = pc[i]; pScene->mTextures[i] = pc[i];
pScene->mTextures[this->pScene->mNumTextures] = pcNew; pScene->mTextures[this->pScene->mNumTextures] = pcNew;
pScene->mNumTextures++; pScene->mNumTextures++;
delete[] pc; delete[] pc;
return;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Read a texture from a MDL4 file // Read a texture from a MDL4 file
void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char* szData, void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char *szData,
unsigned int iType, unsigned int iType,
unsigned int* piSkip) unsigned int *piSkip) {
{ ai_assert(nullptr != piSkip);
ai_assert(NULL != piSkip);
const MDL::Header *pcHeader = (const MDL::Header*)mBuffer; //the endianness is already corrected in the InternReadFile_3DGS_MDL345 function const MDL::Header *pcHeader = (const MDL::Header *)mBuffer; //the endianness is already corrected in the InternReadFile_3DGS_MDL345 function
if (iType == 1 || iType > 3) if (iType == 1 || iType > 3) {
{
ASSIMP_LOG_ERROR("Unsupported texture file format"); ASSIMP_LOG_ERROR("Unsupported texture file format");
return; return;
} }
@ -192,35 +179,30 @@ void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char* szData,
const bool bNoRead = *piSkip == UINT_MAX; const bool bNoRead = *piSkip == UINT_MAX;
// allocate a new texture object // allocate a new texture object
aiTexture* pcNew = new aiTexture(); aiTexture *pcNew = new aiTexture();
pcNew->mWidth = pcHeader->skinwidth; pcNew->mWidth = pcHeader->skinwidth;
pcNew->mHeight = pcHeader->skinheight; pcNew->mHeight = pcHeader->skinheight;
if (bNoRead)pcNew->pcData = bad_texel; if (bNoRead) pcNew->pcData = bad_texel;
ParseTextureColorData(szData,iType,piSkip,pcNew); ParseTextureColorData(szData, iType, piSkip, pcNew);
// store the texture // store the texture
if (!bNoRead) if (!bNoRead) {
{ if (!this->pScene->mNumTextures) {
if (!this->pScene->mNumTextures)
{
pScene->mNumTextures = 1; pScene->mNumTextures = 1;
pScene->mTextures = new aiTexture*[1]; pScene->mTextures = new aiTexture *[1];
pScene->mTextures[0] = pcNew; pScene->mTextures[0] = pcNew;
} } else {
else aiTexture **pc = pScene->mTextures;
{ pScene->mTextures = new aiTexture *[pScene->mNumTextures + 1];
aiTexture** pc = pScene->mTextures; for (unsigned int i = 0; i < this->pScene->mNumTextures; ++i)
pScene->mTextures = new aiTexture*[pScene->mNumTextures+1];
for (unsigned int i = 0; i < this->pScene->mNumTextures;++i)
pScene->mTextures[i] = pc[i]; pScene->mTextures[i] = pc[i];
pScene->mTextures[pScene->mNumTextures] = pcNew; pScene->mTextures[pScene->mNumTextures] = pcNew;
pScene->mNumTextures++; pScene->mNumTextures++;
delete[] pc; delete[] pc;
} }
} } else {
else { pcNew->pcData = nullptr;
pcNew->pcData = NULL;
delete pcNew; delete pcNew;
} }
return; return;
@ -228,11 +210,10 @@ void MDLImporter::CreateTexture_3DGS_MDL4(const unsigned char* szData,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Load color data of a texture and convert it to our output format // Load color data of a texture and convert it to our output format
void MDLImporter::ParseTextureColorData(const unsigned char* szData, void MDLImporter::ParseTextureColorData(const unsigned char *szData,
unsigned int iType, unsigned int iType,
unsigned int* piSkip, unsigned int *piSkip,
aiTexture* pcNew) aiTexture *pcNew) {
{
const bool do_read = bad_texel != pcNew->pcData; const bool do_read = bad_texel != pcNew->pcData;
// allocate storage for the texture image // allocate storage for the texture image
@ -242,17 +223,14 @@ void MDLImporter::ParseTextureColorData(const unsigned char* szData,
// R5G6B5 format (with or without MIPs) // R5G6B5 format (with or without MIPs)
// **************************************************************** // ****************************************************************
if (2 == iType || 10 == iType) if (2 == iType || 10 == iType) {
{ VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight * 2);
VALIDATE_FILE_SIZE(szData + pcNew->mWidth*pcNew->mHeight*2);
// copy texture data // copy texture data
unsigned int i; unsigned int i;
if (do_read) if (do_read) {
{ for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
for (i = 0; i < pcNew->mWidth*pcNew->mHeight;++i) MDL::RGB565 val = ((MDL::RGB565 *)szData)[i];
{
MDL::RGB565 val = ((MDL::RGB565*)szData)[i];
AI_SWAP2(val); AI_SWAP2(val);
pcNew->pcData[i].a = 0xFF; pcNew->pcData[i].a = 0xFF;
@ -260,30 +238,27 @@ void MDLImporter::ParseTextureColorData(const unsigned char* szData,
pcNew->pcData[i].g = (unsigned char)val.g << 2; pcNew->pcData[i].g = (unsigned char)val.g << 2;
pcNew->pcData[i].b = (unsigned char)val.r << 3; pcNew->pcData[i].b = (unsigned char)val.r << 3;
} }
} else {
i = pcNew->mWidth * pcNew->mHeight;
} }
else i = pcNew->mWidth*pcNew->mHeight;
*piSkip = i * 2; *piSkip = i * 2;
// apply MIP maps // apply MIP maps
if (10 == iType) if (10 == iType) {
{
*piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 1; *piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 1;
VALIDATE_FILE_SIZE(szData + *piSkip); VALIDATE_FILE_SIZE(szData + *piSkip);
} }
} }
// ARGB4 format (with or without MIPs) // ARGB4 format (with or without MIPs)
// **************************************************************** // ****************************************************************
else if (3 == iType || 11 == iType) else if (3 == iType || 11 == iType) {
{ VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight * 4);
VALIDATE_FILE_SIZE(szData + pcNew->mWidth*pcNew->mHeight*4);
// copy texture data // copy texture data
unsigned int i; unsigned int i;
if (do_read) if (do_read) {
{ for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
for (i = 0; i < pcNew->mWidth*pcNew->mHeight;++i) MDL::ARGB4 val = ((MDL::ARGB4 *)szData)[i];
{
MDL::ARGB4 val = ((MDL::ARGB4*)szData)[i];
AI_SWAP2(val); AI_SWAP2(val);
pcNew->pcData[i].a = (unsigned char)val.a << 4; pcNew->pcData[i].a = (unsigned char)val.a << 4;
@ -291,95 +266,83 @@ void MDLImporter::ParseTextureColorData(const unsigned char* szData,
pcNew->pcData[i].g = (unsigned char)val.g << 4; pcNew->pcData[i].g = (unsigned char)val.g << 4;
pcNew->pcData[i].b = (unsigned char)val.b << 4; pcNew->pcData[i].b = (unsigned char)val.b << 4;
} }
} } else
else i = pcNew->mWidth*pcNew->mHeight; i = pcNew->mWidth * pcNew->mHeight;
*piSkip = i * 2; *piSkip = i * 2;
// apply MIP maps // apply MIP maps
if (11 == iType) if (11 == iType) {
{
*piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 1; *piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 1;
VALIDATE_FILE_SIZE(szData + *piSkip); VALIDATE_FILE_SIZE(szData + *piSkip);
} }
} }
// RGB8 format (with or without MIPs) // RGB8 format (with or without MIPs)
// **************************************************************** // ****************************************************************
else if (4 == iType || 12 == iType) else if (4 == iType || 12 == iType) {
{ VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight * 3);
VALIDATE_FILE_SIZE(szData + pcNew->mWidth*pcNew->mHeight*3);
// copy texture data // copy texture data
unsigned int i; unsigned int i;
if (do_read) if (do_read) {
{ for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
for (i = 0; i < pcNew->mWidth*pcNew->mHeight;++i) const unsigned char *_szData = &szData[i * 3];
{
const unsigned char* _szData = &szData[i*3];
pcNew->pcData[i].a = 0xFF; pcNew->pcData[i].a = 0xFF;
pcNew->pcData[i].b = *_szData++; pcNew->pcData[i].b = *_szData++;
pcNew->pcData[i].g = *_szData++; pcNew->pcData[i].g = *_szData++;
pcNew->pcData[i].r = *_szData; pcNew->pcData[i].r = *_szData;
} }
} } else
else i = pcNew->mWidth*pcNew->mHeight; i = pcNew->mWidth * pcNew->mHeight;
// apply MIP maps // apply MIP maps
*piSkip = i * 3; *piSkip = i * 3;
if (12 == iType) if (12 == iType) {
{ *piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) * 3;
*piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) *3;
VALIDATE_FILE_SIZE(szData + *piSkip); VALIDATE_FILE_SIZE(szData + *piSkip);
} }
} }
// ARGB8 format (with ir without MIPs) // ARGB8 format (with ir without MIPs)
// **************************************************************** // ****************************************************************
else if (5 == iType || 13 == iType) else if (5 == iType || 13 == iType) {
{ VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight * 4);
VALIDATE_FILE_SIZE(szData + pcNew->mWidth*pcNew->mHeight*4);
// copy texture data // copy texture data
unsigned int i; unsigned int i;
if (do_read) if (do_read) {
{ for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
for (i = 0; i < pcNew->mWidth*pcNew->mHeight;++i) const unsigned char *_szData = &szData[i * 4];
{
const unsigned char* _szData = &szData[i*4];
pcNew->pcData[i].b = *_szData++; pcNew->pcData[i].b = *_szData++;
pcNew->pcData[i].g = *_szData++; pcNew->pcData[i].g = *_szData++;
pcNew->pcData[i].r = *_szData++; pcNew->pcData[i].r = *_szData++;
pcNew->pcData[i].a = *_szData; pcNew->pcData[i].a = *_szData;
} }
} else {
i = pcNew->mWidth * pcNew->mHeight;
} }
else i = pcNew->mWidth*pcNew->mHeight;
// apply MIP maps // apply MIP maps
*piSkip = i << 2; *piSkip = i << 2;
if (13 == iType) if (13 == iType) {
{
*piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 2; *piSkip += ((i >> 2) + (i >> 4) + (i >> 6)) << 2;
} }
} }
// palletized 8 bit texture. As for Quake 1 // palletized 8 bit texture. As for Quake 1
// **************************************************************** // ****************************************************************
else if (0 == iType) else if (0 == iType) {
{ VALIDATE_FILE_SIZE(szData + pcNew->mWidth * pcNew->mHeight);
VALIDATE_FILE_SIZE(szData + pcNew->mWidth*pcNew->mHeight);
// copy texture data // copy texture data
unsigned int i; unsigned int i;
if (do_read) if (do_read) {
{
const unsigned char* szColorMap; const unsigned char *szColorMap;
SearchPalette(&szColorMap); SearchPalette(&szColorMap);
for (i = 0; i < pcNew->mWidth*pcNew->mHeight;++i) for (i = 0; i < pcNew->mWidth * pcNew->mHeight; ++i) {
{
const unsigned char val = szData[i]; const unsigned char val = szData[i];
const unsigned char* sz = &szColorMap[val*3]; const unsigned char *sz = &szColorMap[val * 3];
pcNew->pcData[i].a = 0xFF; pcNew->pcData[i].a = 0xFF;
pcNew->pcData[i].r = *sz++; pcNew->pcData[i].r = *sz++;
@ -388,8 +351,8 @@ void MDLImporter::ParseTextureColorData(const unsigned char* szData,
} }
this->FreePalette(szColorMap); this->FreePalette(szColorMap);
} } else
else i = pcNew->mWidth*pcNew->mHeight; i = pcNew->mWidth * pcNew->mHeight;
*piSkip = i; *piSkip = i;
// FIXME: Also support for MIP maps? // FIXME: Also support for MIP maps?
@ -398,24 +361,23 @@ void MDLImporter::ParseTextureColorData(const unsigned char* szData,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Get a texture from a MDL5 file // Get a texture from a MDL5 file
void MDLImporter::CreateTexture_3DGS_MDL5(const unsigned char* szData, void MDLImporter::CreateTexture_3DGS_MDL5(const unsigned char *szData,
unsigned int iType, unsigned int iType,
unsigned int* piSkip) unsigned int *piSkip) {
{
ai_assert(NULL != piSkip); ai_assert(NULL != piSkip);
bool bNoRead = *piSkip == UINT_MAX; bool bNoRead = *piSkip == UINT_MAX;
// allocate a new texture object // allocate a new texture object
aiTexture* pcNew = new aiTexture(); aiTexture *pcNew = new aiTexture();
VALIDATE_FILE_SIZE(szData+8); VALIDATE_FILE_SIZE(szData + 8);
// first read the size of the texture // first read the size of the texture
pcNew->mWidth = *((uint32_t*)szData); pcNew->mWidth = *((uint32_t *)szData);
AI_SWAP4(pcNew->mWidth); AI_SWAP4(pcNew->mWidth);
szData += sizeof(uint32_t); szData += sizeof(uint32_t);
pcNew->mHeight = *((uint32_t*)szData); pcNew->mHeight = *((uint32_t *)szData);
AI_SWAP4(pcNew->mHeight); AI_SWAP4(pcNew->mHeight);
szData += sizeof(uint32_t); szData += sizeof(uint32_t);
@ -427,14 +389,12 @@ void MDLImporter::CreateTexture_3DGS_MDL5(const unsigned char* szData,
// however, one can easily try out what MED does if you have // however, one can easily try out what MED does if you have
// a model with a DDS texture and export it to MDL5 ... // a model with a DDS texture and export it to MDL5 ...
// yeah, it embedds the DDS file. // yeah, it embedds the DDS file.
if (6 == iType) if (6 == iType) {
{
// this is a compressed texture in DDS format // this is a compressed texture in DDS format
*piSkip = pcNew->mWidth; *piSkip = pcNew->mWidth;
VALIDATE_FILE_SIZE(szData + *piSkip); VALIDATE_FILE_SIZE(szData + *piSkip);
if (!bNoRead) if (!bNoRead) {
{
// place a hint and let the application know that this is a DDS file // place a hint and let the application know that this is a DDS file
pcNew->mHeight = 0; pcNew->mHeight = 0;
pcNew->achFormatHint[0] = 'd'; pcNew->achFormatHint[0] = 'd';
@ -442,39 +402,32 @@ void MDLImporter::CreateTexture_3DGS_MDL5(const unsigned char* szData,
pcNew->achFormatHint[2] = 's'; pcNew->achFormatHint[2] = 's';
pcNew->achFormatHint[3] = '\0'; pcNew->achFormatHint[3] = '\0';
pcNew->pcData = (aiTexel*) new unsigned char[pcNew->mWidth]; pcNew->pcData = (aiTexel *)new unsigned char[pcNew->mWidth];
::memcpy(pcNew->pcData,szData,pcNew->mWidth); ::memcpy(pcNew->pcData, szData, pcNew->mWidth);
} }
} } else {
else
{
// parse the color data of the texture // parse the color data of the texture
ParseTextureColorData(szData,iType,piSkip,pcNew); ParseTextureColorData(szData, iType, piSkip, pcNew);
} }
*piSkip += sizeof(uint32_t) * 2; *piSkip += sizeof(uint32_t) * 2;
if (!bNoRead) if (!bNoRead) {
{
// store the texture // store the texture
if (!this->pScene->mNumTextures) if (!this->pScene->mNumTextures) {
{
pScene->mNumTextures = 1; pScene->mNumTextures = 1;
pScene->mTextures = new aiTexture*[1]; pScene->mTextures = new aiTexture *[1];
pScene->mTextures[0] = pcNew; pScene->mTextures[0] = pcNew;
} } else {
else aiTexture **pc = pScene->mTextures;
{ pScene->mTextures = new aiTexture *[pScene->mNumTextures + 1];
aiTexture** pc = pScene->mTextures; for (unsigned int i = 0; i < pScene->mNumTextures; ++i)
pScene->mTextures = new aiTexture*[pScene->mNumTextures+1];
for (unsigned int i = 0; i < pScene->mNumTextures;++i)
this->pScene->mTextures[i] = pc[i]; this->pScene->mTextures[i] = pc[i];
pScene->mTextures[pScene->mNumTextures] = pcNew; pScene->mTextures[pScene->mNumTextures] = pcNew;
pScene->mNumTextures++; pScene->mNumTextures++;
delete[] pc; delete[] pc;
} }
} } else {
else {
pcNew->pcData = NULL; pcNew->pcData = NULL;
delete pcNew; delete pcNew;
} }
@ -484,31 +437,26 @@ void MDLImporter::CreateTexture_3DGS_MDL5(const unsigned char* szData,
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Get a skin from a MDL7 file - more complex than all other subformats // Get a skin from a MDL7 file - more complex than all other subformats
void MDLImporter::ParseSkinLump_3DGS_MDL7( void MDLImporter::ParseSkinLump_3DGS_MDL7(
const unsigned char* szCurrent, const unsigned char *szCurrent,
const unsigned char** szCurrentOut, const unsigned char **szCurrentOut,
aiMaterial* pcMatOut, aiMaterial *pcMatOut,
unsigned int iType, unsigned int iType,
unsigned int iWidth, unsigned int iWidth,
unsigned int iHeight) unsigned int iHeight) {
{
std::unique_ptr<aiTexture> pcNew; std::unique_ptr<aiTexture> pcNew;
// get the type of the skin // get the type of the skin
unsigned int iMasked = (unsigned int)(iType & 0xF); unsigned int iMasked = (unsigned int)(iType & 0xF);
if (0x1 == iMasked) if (0x1 == iMasked) {
{
// ***** REFERENCE TO ANOTHER SKIN INDEX ***** // ***** REFERENCE TO ANOTHER SKIN INDEX *****
int referrer = (int)iWidth; int referrer = (int)iWidth;
pcMatOut->AddProperty<int>(&referrer,1,AI_MDL7_REFERRER_MATERIAL); pcMatOut->AddProperty<int>(&referrer, 1, AI_MDL7_REFERRER_MATERIAL);
} } else if (0x6 == iMasked) {
else if (0x6 == iMasked)
{
// ***** EMBEDDED DDS FILE ***** // ***** EMBEDDED DDS FILE *****
if (1 != iHeight) if (1 != iHeight) {
{
ASSIMP_LOG_WARN("Found a reference to an embedded DDS texture, " ASSIMP_LOG_WARN("Found a reference to an embedded DDS texture, "
"but texture height is not equal to 1, which is not supported by MED"); "but texture height is not equal to 1, which is not supported by MED");
} }
pcNew.reset(new aiTexture()); pcNew.reset(new aiTexture());
@ -521,57 +469,47 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
pcNew->achFormatHint[2] = 's'; pcNew->achFormatHint[2] = 's';
pcNew->achFormatHint[3] = '\0'; pcNew->achFormatHint[3] = '\0';
pcNew->pcData = (aiTexel*) new unsigned char[pcNew->mWidth]; pcNew->pcData = (aiTexel *)new unsigned char[pcNew->mWidth];
memcpy(pcNew->pcData,szCurrent,pcNew->mWidth); memcpy(pcNew->pcData, szCurrent, pcNew->mWidth);
szCurrent += iWidth; szCurrent += iWidth;
} } else if (0x7 == iMasked) {
else if (0x7 == iMasked)
{
// ***** REFERENCE TO EXTERNAL FILE ***** // ***** REFERENCE TO EXTERNAL FILE *****
if (1 != iHeight) if (1 != iHeight) {
{
ASSIMP_LOG_WARN("Found a reference to an external texture, " ASSIMP_LOG_WARN("Found a reference to an external texture, "
"but texture height is not equal to 1, which is not supported by MED"); "but texture height is not equal to 1, which is not supported by MED");
} }
aiString szFile; aiString szFile;
const size_t iLen = strlen((const char*)szCurrent); const size_t iLen = strlen((const char *)szCurrent);
size_t iLen2 = iLen+1; size_t iLen2 = iLen + 1;
iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2; iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
memcpy(szFile.data,(const char*)szCurrent,iLen2); memcpy(szFile.data, (const char *)szCurrent, iLen2);
szFile.length = (ai_uint32)iLen; szFile.length = (ai_uint32)iLen;
szCurrent += iLen2; szCurrent += iLen2;
// place this as diffuse texture // place this as diffuse texture
pcMatOut->AddProperty(&szFile,AI_MATKEY_TEXTURE_DIFFUSE(0)); pcMatOut->AddProperty(&szFile, AI_MATKEY_TEXTURE_DIFFUSE(0));
} } else if (iMasked || !iType || (iType && iWidth && iHeight)) {
else if (iMasked || !iType || (iType && iWidth && iHeight))
{
pcNew.reset(new aiTexture()); pcNew.reset(new aiTexture());
if (!iHeight || !iWidth) if (!iHeight || !iWidth) {
{
ASSIMP_LOG_WARN("Found embedded texture, but its width " ASSIMP_LOG_WARN("Found embedded texture, but its width "
"an height are both 0. Is this a joke?"); "an height are both 0. Is this a joke?");
// generate an empty chess pattern // generate an empty chess pattern
pcNew->mWidth = pcNew->mHeight = 8; pcNew->mWidth = pcNew->mHeight = 8;
pcNew->pcData = new aiTexel[64]; pcNew->pcData = new aiTexel[64];
for (unsigned int x = 0; x < 8;++x) for (unsigned int x = 0; x < 8; ++x) {
{ for (unsigned int y = 0; y < 8; ++y) {
for (unsigned int y = 0; y < 8;++y)
{
const bool bSet = ((0 == x % 2 && 0 != y % 2) || const bool bSet = ((0 == x % 2 && 0 != y % 2) ||
(0 != x % 2 && 0 == y % 2)); (0 != x % 2 && 0 == y % 2));
aiTexel* pc = &pcNew->pcData[y * 8 + x]; aiTexel *pc = &pcNew->pcData[y * 8 + x];
pc->r = pc->b = pc->g = (bSet?0xFF:0); pc->r = pc->b = pc->g = (bSet ? 0xFF : 0);
pc->a = 0xFF; pc->a = 0xFF;
} }
} }
} } else {
else
{
// it is a standard color texture. Fill in width and height // it is a standard color texture. Fill in width and height
// and call the same function we used for loading MDL5 files // and call the same function we used for loading MDL5 files
@ -579,7 +517,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
pcNew->mHeight = iHeight; pcNew->mHeight = iHeight;
unsigned int iSkip = 0; unsigned int iSkip = 0;
ParseTextureColorData(szCurrent,iMasked,&iSkip,pcNew.get()); ParseTextureColorData(szCurrent, iMasked, &iSkip, pcNew.get());
// skip length of texture data // skip length of texture data
szCurrent += iSkip; szCurrent += iSkip;
@ -590,25 +528,25 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
// texture instead of material colors ... posssible they have // texture instead of material colors ... posssible they have
// been converted to MDL7 from other formats, such as MDL5 // been converted to MDL7 from other formats, such as MDL5
aiColor4D clrTexture; aiColor4D clrTexture;
if (pcNew)clrTexture = ReplaceTextureWithColor(pcNew.get()); if (pcNew)
else clrTexture.r = get_qnan(); clrTexture = ReplaceTextureWithColor(pcNew.get());
else
clrTexture.r = get_qnan();
// check whether a material definition is contained in the skin // check whether a material definition is contained in the skin
if (iType & AI_MDL7_SKINTYPE_MATERIAL) if (iType & AI_MDL7_SKINTYPE_MATERIAL) {
{ BE_NCONST MDL::Material_MDL7 *pcMatIn = (BE_NCONST MDL::Material_MDL7 *)szCurrent;
BE_NCONST MDL::Material_MDL7* pcMatIn = (BE_NCONST MDL::Material_MDL7*)szCurrent; szCurrent = (unsigned char *)(pcMatIn + 1);
szCurrent = (unsigned char*)(pcMatIn+1);
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
aiColor3D clrTemp; aiColor3D clrTemp;
#define COLOR_MULTIPLY_RGB() \ #define COLOR_MULTIPLY_RGB() \
if (is_not_qnan(clrTexture.r)) \ if (is_not_qnan(clrTexture.r)) { \
{ \ clrTemp.r *= clrTexture.r; \
clrTemp.r *= clrTexture.r; \ clrTemp.g *= clrTexture.g; \
clrTemp.g *= clrTexture.g; \ clrTemp.b *= clrTexture.b; \
clrTemp.b *= clrTexture.b; \ }
}
// read diffuse color // read diffuse color
clrTemp.r = pcMatIn->Diffuse.r; clrTemp.r = pcMatIn->Diffuse.r;
@ -618,7 +556,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
clrTemp.b = pcMatIn->Diffuse.b; clrTemp.b = pcMatIn->Diffuse.b;
AI_SWAP4(clrTemp.b); AI_SWAP4(clrTemp.b);
COLOR_MULTIPLY_RGB(); COLOR_MULTIPLY_RGB();
pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_DIFFUSE); pcMatOut->AddProperty<aiColor3D>(&clrTemp, 1, AI_MATKEY_COLOR_DIFFUSE);
// read specular color // read specular color
clrTemp.r = pcMatIn->Specular.r; clrTemp.r = pcMatIn->Specular.r;
@ -628,7 +566,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
clrTemp.b = pcMatIn->Specular.b; clrTemp.b = pcMatIn->Specular.b;
AI_SWAP4(clrTemp.b); AI_SWAP4(clrTemp.b);
COLOR_MULTIPLY_RGB(); COLOR_MULTIPLY_RGB();
pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_SPECULAR); pcMatOut->AddProperty<aiColor3D>(&clrTemp, 1, AI_MATKEY_COLOR_SPECULAR);
// read ambient color // read ambient color
clrTemp.r = pcMatIn->Ambient.r; clrTemp.r = pcMatIn->Ambient.r;
@ -638,7 +576,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
clrTemp.b = pcMatIn->Ambient.b; clrTemp.b = pcMatIn->Ambient.b;
AI_SWAP4(clrTemp.b); AI_SWAP4(clrTemp.b);
COLOR_MULTIPLY_RGB(); COLOR_MULTIPLY_RGB();
pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_AMBIENT); pcMatOut->AddProperty<aiColor3D>(&clrTemp, 1, AI_MATKEY_COLOR_AMBIENT);
// read emissive color // read emissive color
clrTemp.r = pcMatIn->Emissive.r; clrTemp.r = pcMatIn->Emissive.r;
@ -647,7 +585,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
AI_SWAP4(clrTemp.g); AI_SWAP4(clrTemp.g);
clrTemp.b = pcMatIn->Emissive.b; clrTemp.b = pcMatIn->Emissive.b;
AI_SWAP4(clrTemp.b); AI_SWAP4(clrTemp.b);
pcMatOut->AddProperty<aiColor3D>(&clrTemp,1,AI_MATKEY_COLOR_EMISSIVE); pcMatOut->AddProperty<aiColor3D>(&clrTemp, 1, AI_MATKEY_COLOR_EMISSIVE);
#undef COLOR_MULITPLY_RGB #undef COLOR_MULITPLY_RGB
@ -659,38 +597,33 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
if (is_not_qnan(clrTexture.r)) { if (is_not_qnan(clrTexture.r)) {
clrTemp.r *= clrTexture.a; clrTemp.r *= clrTexture.a;
} }
pcMatOut->AddProperty<ai_real>(&clrTemp.r,1,AI_MATKEY_OPACITY); pcMatOut->AddProperty<ai_real>(&clrTemp.r, 1, AI_MATKEY_OPACITY);
// read phong power // read phong power
int iShadingMode = (int)aiShadingMode_Gouraud; int iShadingMode = (int)aiShadingMode_Gouraud;
AI_SWAP4(pcMatIn->Power); AI_SWAP4(pcMatIn->Power);
if (0.0f != pcMatIn->Power) if (0.0f != pcMatIn->Power) {
{
iShadingMode = (int)aiShadingMode_Phong; iShadingMode = (int)aiShadingMode_Phong;
// pcMatIn is packed, we can't form pointers to its members // pcMatIn is packed, we can't form pointers to its members
float power = pcMatIn->Power; float power = pcMatIn->Power;
pcMatOut->AddProperty<float>(&power,1,AI_MATKEY_SHININESS); pcMatOut->AddProperty<float>(&power, 1, AI_MATKEY_SHININESS);
} }
pcMatOut->AddProperty<int>(&iShadingMode,1,AI_MATKEY_SHADING_MODEL); pcMatOut->AddProperty<int>(&iShadingMode, 1, AI_MATKEY_SHADING_MODEL);
} } else if (is_not_qnan(clrTexture.r)) {
else if (is_not_qnan(clrTexture.r)) pcMatOut->AddProperty<aiColor4D>(&clrTexture, 1, AI_MATKEY_COLOR_DIFFUSE);
{ pcMatOut->AddProperty<aiColor4D>(&clrTexture, 1, AI_MATKEY_COLOR_SPECULAR);
pcMatOut->AddProperty<aiColor4D>(&clrTexture,1,AI_MATKEY_COLOR_DIFFUSE);
pcMatOut->AddProperty<aiColor4D>(&clrTexture,1,AI_MATKEY_COLOR_SPECULAR);
} }
// if the texture could be replaced by a single material color // if the texture could be replaced by a single material color
// we don't need the texture anymore // we don't need the texture anymore
if (is_not_qnan(clrTexture.r)) if (is_not_qnan(clrTexture.r)) {
{
pcNew.reset(); pcNew.reset();
} }
// If an ASCII effect description (HLSL?) is contained in the file, // If an ASCII effect description (HLSL?) is contained in the file,
// we can simply ignore it ... // we can simply ignore it ...
if (iType & AI_MDL7_SKINTYPE_MATERIAL_ASCDEF) if (iType & AI_MDL7_SKINTYPE_MATERIAL_ASCDEF) {
{
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
int32_t iMe = *((int32_t*)szCurrent); int32_t iMe = *((int32_t *)szCurrent);
AI_SWAP4(iMe); AI_SWAP4(iMe);
szCurrent += sizeof(char) * iMe + sizeof(int32_t); szCurrent += sizeof(char) * iMe + sizeof(int32_t);
VALIDATE_FILE_SIZE(szCurrent); VALIDATE_FILE_SIZE(szCurrent);
@ -698,8 +631,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
// If an embedded texture has been loaded setup the corresponding // If an embedded texture has been loaded setup the corresponding
// data structures in the aiScene instance // data structures in the aiScene instance
if (pcNew && pScene->mNumTextures <= 999) if (pcNew && pScene->mNumTextures <= 999) {
{
// place this as diffuse texture // place this as diffuse texture
char current[5]; char current[5];
ai_snprintf(current, 5, "*%i", this->pScene->mNumTextures); ai_snprintf(current, 5, "*%i", this->pScene->mNumTextures);
@ -709,20 +641,17 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
::memcpy(szFile.data, (const char *)current, iLen + 1); ::memcpy(szFile.data, (const char *)current, iLen + 1);
szFile.length = (ai_uint32)iLen; szFile.length = (ai_uint32)iLen;
pcMatOut->AddProperty(&szFile,AI_MATKEY_TEXTURE_DIFFUSE(0)); pcMatOut->AddProperty(&szFile, AI_MATKEY_TEXTURE_DIFFUSE(0));
// store the texture // store the texture
if (!pScene->mNumTextures) if (!pScene->mNumTextures) {
{
pScene->mNumTextures = 1; pScene->mNumTextures = 1;
pScene->mTextures = new aiTexture*[1]; pScene->mTextures = new aiTexture *[1];
pScene->mTextures[0] = pcNew.release(); pScene->mTextures[0] = pcNew.release();
} } else {
else aiTexture **pc = pScene->mTextures;
{ pScene->mTextures = new aiTexture *[pScene->mNumTextures + 1];
aiTexture** pc = pScene->mTextures; for (unsigned int i = 0; i < pScene->mNumTextures; ++i) {
pScene->mTextures = new aiTexture*[pScene->mNumTextures+1];
for (unsigned int i = 0; i < pScene->mNumTextures;++i) {
pScene->mTextures[i] = pc[i]; pScene->mTextures[i] = pc[i];
} }
@ -738,28 +667,22 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Skip a skin lump // Skip a skin lump
void MDLImporter::SkipSkinLump_3DGS_MDL7( void MDLImporter::SkipSkinLump_3DGS_MDL7(
const unsigned char* szCurrent, const unsigned char *szCurrent,
const unsigned char** szCurrentOut, const unsigned char **szCurrentOut,
unsigned int iType, unsigned int iType,
unsigned int iWidth, unsigned int iWidth,
unsigned int iHeight) unsigned int iHeight) {
{
// get the type of the skin // get the type of the skin
const unsigned int iMasked = (unsigned int)(iType & 0xF); const unsigned int iMasked = (unsigned int)(iType & 0xF);
if (0x6 == iMasked) if (0x6 == iMasked) {
{
szCurrent += iWidth; szCurrent += iWidth;
} }
if (0x7 == iMasked) if (0x7 == iMasked) {
{ const size_t iLen = std::strlen((const char *)szCurrent);
const size_t iLen = ::strlen((const char*)szCurrent); szCurrent += iLen + 1;
szCurrent += iLen+1; } else if (iMasked || !iType) {
} if (iMasked || !iType || (iType && iWidth && iHeight)) {
else if (iMasked || !iType)
{
if (iMasked || !iType || (iType && iWidth && iHeight))
{
// ParseTextureColorData(..., aiTexture::pcData == bad_texel) will simply // ParseTextureColorData(..., aiTexture::pcData == bad_texel) will simply
// return the size of the color data in bytes in iSkip // return the size of the color data in bytes in iSkip
unsigned int iSkip = 0; unsigned int iSkip = 0;
@ -768,10 +691,10 @@ void MDLImporter::SkipSkinLump_3DGS_MDL7(
tex.pcData = bad_texel; tex.pcData = bad_texel;
tex.mHeight = iHeight; tex.mHeight = iHeight;
tex.mWidth = iWidth; tex.mWidth = iWidth;
ParseTextureColorData(szCurrent,iMasked,&iSkip,&tex); ParseTextureColorData(szCurrent, iMasked, &iSkip, &tex);
// FIX: Important, otherwise the destructor will crash // FIX: Important, otherwise the destructor will crash
tex.pcData = NULL; tex.pcData = nullptr;
// skip length of texture data // skip length of texture data
szCurrent += iSkip; szCurrent += iSkip;
@ -779,17 +702,15 @@ void MDLImporter::SkipSkinLump_3DGS_MDL7(
} }
// check whether a material definition is contained in the skin // check whether a material definition is contained in the skin
if (iType & AI_MDL7_SKINTYPE_MATERIAL) if (iType & AI_MDL7_SKINTYPE_MATERIAL) {
{ BE_NCONST MDL::Material_MDL7 *pcMatIn = (BE_NCONST MDL::Material_MDL7 *)szCurrent;
BE_NCONST MDL::Material_MDL7* pcMatIn = (BE_NCONST MDL::Material_MDL7*)szCurrent; szCurrent = (unsigned char *)(pcMatIn + 1);
szCurrent = (unsigned char*)(pcMatIn+1);
} }
// if an ASCII effect description (HLSL?) is contained in the file, // if an ASCII effect description (HLSL?) is contained in the file,
// we can simply ignore it ... // we can simply ignore it ...
if (iType & AI_MDL7_SKINTYPE_MATERIAL_ASCDEF) if (iType & AI_MDL7_SKINTYPE_MATERIAL_ASCDEF) {
{ int32_t iMe = *((int32_t *)szCurrent);
int32_t iMe = *((int32_t*)szCurrent);
AI_SWAP4(iMe); AI_SWAP4(iMe);
szCurrent += sizeof(char) * iMe + sizeof(int32_t); szCurrent += sizeof(char) * iMe + sizeof(int32_t);
} }
@ -798,39 +719,37 @@ void MDLImporter::SkipSkinLump_3DGS_MDL7(
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void MDLImporter::ParseSkinLump_3DGS_MDL7( void MDLImporter::ParseSkinLump_3DGS_MDL7(
const unsigned char* szCurrent, const unsigned char *szCurrent,
const unsigned char** szCurrentOut, const unsigned char **szCurrentOut,
std::vector<aiMaterial*>& pcMats) std::vector<aiMaterial *> &pcMats) {
{ ai_assert(nullptr != szCurrent);
ai_assert(NULL != szCurrent); ai_assert(nullptr != szCurrentOut);
ai_assert(NULL != szCurrentOut);
*szCurrentOut = szCurrent; *szCurrentOut = szCurrent;
BE_NCONST MDL::Skin_MDL7* pcSkin = (BE_NCONST MDL::Skin_MDL7*)szCurrent; BE_NCONST MDL::Skin_MDL7 *pcSkin = (BE_NCONST MDL::Skin_MDL7 *)szCurrent;
AI_SWAP4(pcSkin->width); AI_SWAP4(pcSkin->width);
AI_SWAP4(pcSkin->height); AI_SWAP4(pcSkin->height);
szCurrent += 12; szCurrent += 12;
// allocate an output material // allocate an output material
aiMaterial* pcMatOut = new aiMaterial(); aiMaterial *pcMatOut = new aiMaterial();
pcMats.push_back(pcMatOut); pcMats.push_back(pcMatOut);
// skip length of file name // skip length of file name
szCurrent += AI_MDL7_MAX_TEXNAMESIZE; szCurrent += AI_MDL7_MAX_TEXNAMESIZE;
ParseSkinLump_3DGS_MDL7(szCurrent,szCurrentOut,pcMatOut, ParseSkinLump_3DGS_MDL7(szCurrent, szCurrentOut, pcMatOut,
pcSkin->typ,pcSkin->width,pcSkin->height); pcSkin->typ, pcSkin->width, pcSkin->height);
// place the name of the skin in the material // place the name of the skin in the material
if (pcSkin->texture_name[0]) if (pcSkin->texture_name[0]) {
{
// the 0 termination could be there or not - we can't know // the 0 termination could be there or not - we can't know
aiString szFile; aiString szFile;
::memcpy(szFile.data,pcSkin->texture_name,sizeof(pcSkin->texture_name)); ::memcpy(szFile.data, pcSkin->texture_name, sizeof(pcSkin->texture_name));
szFile.data[sizeof(pcSkin->texture_name)] = '\0'; szFile.data[sizeof(pcSkin->texture_name)] = '\0';
szFile.length = (ai_uint32)::strlen(szFile.data); szFile.length = (ai_uint32)::strlen(szFile.data);
pcMatOut->AddProperty(&szFile,AI_MATKEY_NAME); pcMatOut->AddProperty(&szFile, AI_MATKEY_NAME);
} }
} }

View File

@ -46,12 +46,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef ASSIMP_BUILD_NO_PLY_IMPORTER #ifndef ASSIMP_BUILD_NO_PLY_IMPORTER
// internal headers // internal headers
# include "PlyLoader.h" #include "PlyLoader.h"
# include <assimp/IOStreamBuffer.h> #include <assimp/IOStreamBuffer.h>
# include <assimp/importerdesc.h> #include <assimp/importerdesc.h>
# include <assimp/scene.h> #include <assimp/scene.h>
# include <assimp/IOSystem.hpp> #include <assimp/IOSystem.hpp>
# include <memory> #include <memory>
using namespace ::Assimp; using namespace ::Assimp;
@ -132,15 +132,15 @@ static bool isBigEndian(const char *szMe) {
// binary_little_endian // binary_little_endian
// binary_big_endian // binary_big_endian
bool isBigEndian(false); bool isBigEndian(false);
# if (defined AI_BUILD_BIG_ENDIAN) #if (defined AI_BUILD_BIG_ENDIAN)
if ('l' == *szMe || 'L' == *szMe) { if ('l' == *szMe || 'L' == *szMe) {
isBigEndian = true; isBigEndian = true;
} }
# else #else
if ('b' == *szMe || 'B' == *szMe) { if ('b' == *szMe || 'B' == *szMe) {
isBigEndian = true; isBigEndian = true;
} }
# endif // ! AI_BUILD_BIG_ENDIAN #endif // ! AI_BUILD_BIG_ENDIAN
return isBigEndian; return isBigEndian;
} }
@ -487,24 +487,24 @@ void PLYImporter::LoadVertex(const PLY::Element *pcElement, const PLY::ElementIn
// Convert a color component to [0...1] // Convert a color component to [0...1]
ai_real PLYImporter::NormalizeColorValue(PLY::PropertyInstance::ValueUnion val, PLY::EDataType eType) { ai_real PLYImporter::NormalizeColorValue(PLY::PropertyInstance::ValueUnion val, PLY::EDataType eType) {
switch (eType) { switch (eType) {
case EDT_Float: case EDT_Float:
return val.fFloat; return val.fFloat;
case EDT_Double: case EDT_Double:
return (ai_real)val.fDouble; return (ai_real)val.fDouble;
case EDT_UChar: case EDT_UChar:
return (ai_real)val.iUInt / (ai_real)0xFF; return (ai_real)val.iUInt / (ai_real)0xFF;
case EDT_Char: case EDT_Char:
return (ai_real)(val.iInt + (0xFF / 2)) / (ai_real)0xFF; return (ai_real)(val.iInt + (0xFF / 2)) / (ai_real)0xFF;
case EDT_UShort: case EDT_UShort:
return (ai_real)val.iUInt / (ai_real)0xFFFF; return (ai_real)val.iUInt / (ai_real)0xFFFF;
case EDT_Short: case EDT_Short:
return (ai_real)(val.iInt + (0xFFFF / 2)) / (ai_real)0xFFFF; return (ai_real)(val.iInt + (0xFFFF / 2)) / (ai_real)0xFFFF;
case EDT_UInt: case EDT_UInt:
return (ai_real)val.iUInt / (ai_real)0xFFFF; return (ai_real)val.iUInt / (ai_real)0xFFFF;
case EDT_Int: case EDT_Int:
return ((ai_real)val.iInt / (ai_real)0xFF) + 0.5f; return ((ai_real)val.iInt / (ai_real)0xFF) + 0.5f;
default: default:
break; break;
} }
return 0.0f; return 0.0f;

View File

@ -356,7 +356,7 @@ TEST_F(utObjImportExport, homogeneous_coordinates_divide_by_zero_Test) {
"f 1 2 3\nB"; "f 1 2 3\nB";
Assimp::Importer myimporter; Assimp::Importer myimporter;
const aiScene *scene = myimporter.ReadFileFromMemory(curObjModel, strlen(curObjModel), aiProcess_ValidateDataStructure); const aiScene *scene = myimporter.ReadFileFromMemory(curObjModel, std::strlen(curObjModel), aiProcess_ValidateDataStructure);
EXPECT_EQ(nullptr, scene); EXPECT_EQ(nullptr, scene);
} }

View File

@ -63,7 +63,7 @@ const char *AICMD_MSG_DUMP_HELP =
#include <memory> #include <memory>
FILE *out = NULL; FILE *out = nullptr;
bool shortened = false; bool shortened = false;
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
@ -108,7 +108,7 @@ int Assimp_Dump(const char *const *params, unsigned int num) {
if (!strcmp(params[i], "-b") || !strcmp(params[i], "--binary")) { if (!strcmp(params[i], "-b") || !strcmp(params[i], "--binary")) {
binary = true; binary = true;
} else if (!strcmp(params[i], "-s") || !strcmp(params[i], "--short")) { } else if (!strcmp(params[i], "-s") || !strcmp(params[i], "--short")) {
shortened = true; cur_shortened = true;
} else if (!strcmp(params[i], "-z") || !strcmp(params[i], "--compressed")) { } else if (!strcmp(params[i], "-z") || !strcmp(params[i], "--compressed")) {
compressed = true; compressed = true;
} }