Draft: Update init of aiString (#5623)
* Draft: Update init of aiString - closes https://github.com/assimp/assimp/issues/5622 * Update types.h * Fix typo * Fix another typo * Adapt usage of AI_MAXLEN * Fix compare operator * Add missing renamespull/5625/head^2
parent
75091d4529
commit
a51500ba2b
|
@ -709,7 +709,7 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene *pcOut) {
|
|||
pcNode->mNumMeshes = 1;
|
||||
|
||||
// Build a name for the node
|
||||
pcNode->mName.length = ai_snprintf(pcNode->mName.data, MAXLEN, "3DSMesh_%u", i);
|
||||
pcNode->mName.length = ai_snprintf(pcNode->mName.data, AI_MAXLEN, "3DSMesh_%u", i);
|
||||
}
|
||||
|
||||
// Build dummy nodes for all cameras
|
||||
|
|
|
@ -193,7 +193,7 @@ bool AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
|
|||
|
||||
// Generate a default name for both the light source and the node
|
||||
// FIXME - what's the right way to print a size_t? Is 'zu' universally available? stick with the safe version.
|
||||
light->mName.length = ::ai_snprintf(light->mName.data, MAXLEN, "ACLight_%i", static_cast<unsigned int>(mLights->size()) - 1);
|
||||
light->mName.length = ::ai_snprintf(light->mName.data, AI_MAXLEN, "ACLight_%i", static_cast<unsigned int>(mLights->size()) - 1);
|
||||
obj.name = std::string(light->mName.data);
|
||||
|
||||
ASSIMP_LOG_VERBOSE_DEBUG("AC3D: Light source encountered");
|
||||
|
@ -696,18 +696,18 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
|
|||
// generate a name depending on the type of the node
|
||||
switch (object.type) {
|
||||
case Object::Group:
|
||||
node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACGroup_%i", mGroupsCounter++);
|
||||
node->mName.length = ::ai_snprintf(node->mName.data, AI_MAXLEN, "ACGroup_%i", mGroupsCounter++);
|
||||
break;
|
||||
case Object::Poly:
|
||||
node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACPoly_%i", mPolysCounter++);
|
||||
node->mName.length = ::ai_snprintf(node->mName.data, AI_MAXLEN, "ACPoly_%i", mPolysCounter++);
|
||||
break;
|
||||
case Object::Light:
|
||||
node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACLight_%i", mLightsCounter++);
|
||||
node->mName.length = ::ai_snprintf(node->mName.data, AI_MAXLEN, "ACLight_%i", mLightsCounter++);
|
||||
break;
|
||||
|
||||
// there shouldn't be more than one world, but we don't care
|
||||
case Object::World:
|
||||
node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACWorld_%i", mWorldsCounter++);
|
||||
node->mName.length = ::ai_snprintf(node->mName.data, AI_MAXLEN, "ACWorld_%i", mWorldsCounter++);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -359,7 +359,7 @@ void BlenderImporter::ResolveImage(aiMaterial *out, const Material *mat, const M
|
|||
// check if the file contents are bundled with the BLEND file
|
||||
if (img->packedfile) {
|
||||
name.data[0] = '*';
|
||||
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(conv_data.textures->size()));
|
||||
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(AI_MAXLEN - 1), static_cast<int32_t>(conv_data.textures->size()));
|
||||
|
||||
conv_data.textures->push_back(new aiTexture());
|
||||
aiTexture *curTex = conv_data.textures->back();
|
||||
|
@ -433,7 +433,7 @@ void BlenderImporter::AddSentinelTexture(aiMaterial *out, const Material *mat, c
|
|||
(void)conv_data;
|
||||
|
||||
aiString name;
|
||||
name.length = ai_snprintf(name.data, MAXLEN, "Procedural,num=%i,type=%s", conv_data.sentinel_cnt++,
|
||||
name.length = ai_snprintf(name.data, AI_MAXLEN, "Procedural,num=%i,type=%s", conv_data.sentinel_cnt++,
|
||||
GetTextureTypeDisplayString(tex->tex->type));
|
||||
out->AddProperty(&name, AI_MATKEY_TEXTURE_DIFFUSE(
|
||||
conv_data.next_texture[aiTextureType_DIFFUSE]++));
|
||||
|
|
|
@ -1860,7 +1860,7 @@ aiString FBXConverter::GetTexturePath(const Texture *tex) {
|
|||
// We need to load all textures before referencing them, as FBX file format order may reference a texture before loading it
|
||||
// This may occur on this case too, it has to be studied
|
||||
path.data[0] = '*';
|
||||
path.length = 1 + ASSIMP_itoa10(path.data + 1, MAXLEN - 1, index);
|
||||
path.length = 1 + ASSIMP_itoa10(path.data + 1, AI_MAXLEN - 1, index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2440,7 +2440,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTa
|
|||
|
||||
// setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture)
|
||||
path.data[0] = '*';
|
||||
path.length = 1 + ASSIMP_itoa10(path.data + 1, MAXLEN - 1, index);
|
||||
path.length = 1 + ASSIMP_itoa10(path.data + 1, AI_MAXLEN - 1, index);
|
||||
}
|
||||
|
||||
out_mat->AddProperty(&path, (name + "|file").c_str(), aiTextureType_UNKNOWN, 0);
|
||||
|
@ -2806,7 +2806,7 @@ void FBXConverter::ProcessMorphAnimDatas(std::map<std::string, morphAnimData *>
|
|||
auto geoIt = std::find(model->GetGeometry().begin(), model->GetGeometry().end(), geo);
|
||||
auto geoIndex = static_cast<unsigned int>(std::distance(model->GetGeometry().begin(), geoIt));
|
||||
auto name = aiString(FixNodeName(model->Name() + "*"));
|
||||
name.length = 1 + ASSIMP_itoa10(name.data + name.length, MAXLEN - 1, geoIndex);
|
||||
name.length = 1 + ASSIMP_itoa10(name.data + name.length, AI_MAXLEN - 1, geoIndex);
|
||||
morphAnimData *animData;
|
||||
auto animIt = morphAnimDatas->find(name.C_Str());
|
||||
if (animIt == morphAnimDatas->end()) {
|
||||
|
|
|
@ -134,7 +134,7 @@ public:
|
|||
const char* elementNameCStr = elementName.c_str();
|
||||
for (auto element = elements.begin(); element != elements.end(); ++element)
|
||||
{
|
||||
if (!ASSIMP_strincmp(element->first.c_str(), elementNameCStr, MAXLEN)) {
|
||||
if (!ASSIMP_strincmp(element->first.c_str(), elementNameCStr, AI_MAXLEN)) {
|
||||
return element->second;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,7 +168,7 @@ void IRRImporter::BuildSkybox(std::vector<aiMesh *> &meshes, std::vector<aiMater
|
|||
aiMaterial *out = (aiMaterial *)(*(materials.end() - (6 - i)));
|
||||
|
||||
aiString s;
|
||||
s.length = ::ai_snprintf(s.data, MAXLEN, "SkyboxSide_%u", i);
|
||||
s.length = ::ai_snprintf(s.data, AI_MAXLEN, "SkyboxSide_%u", i);
|
||||
out->AddProperty(&s, AI_MATKEY_NAME);
|
||||
|
||||
int shading = aiShadingMode_NoShading;
|
||||
|
@ -316,7 +316,7 @@ void IRRImporter::ComputeAnimations(Node *root, aiNode *real, std::vector<aiNode
|
|||
if (cur != total - 1) {
|
||||
// Build a new name - a prefix instead of a suffix because it is
|
||||
// easier to check against
|
||||
anim->mNodeName.length = ::ai_snprintf(anim->mNodeName.data, MAXLEN,
|
||||
anim->mNodeName.length = ::ai_snprintf(anim->mNodeName.data, AI_MAXLEN,
|
||||
"$INST_DUMMY_%i_%s", total - 1,
|
||||
(root->name.length() ? root->name.c_str() : ""));
|
||||
|
||||
|
|
|
@ -305,14 +305,14 @@ void LWSImporter::SetupNodeName(aiNode *nd, LWS::NodeDesc &src) {
|
|||
}
|
||||
std::string::size_type t = src.path.substr(s).find_last_of('.');
|
||||
|
||||
nd->mName.length = ::ai_snprintf(nd->mName.data, MAXLEN, "%s_(%08X)", src.path.substr(s).substr(0, t).c_str(), combined);
|
||||
if (nd->mName.length > MAXLEN) {
|
||||
nd->mName.length = MAXLEN;
|
||||
nd->mName.length = ::ai_snprintf(nd->mName.data, AI_MAXLEN, "%s_(%08X)", src.path.substr(s).substr(0, t).c_str(), combined);
|
||||
if (nd->mName.length > AI_MAXLEN) {
|
||||
nd->mName.length = AI_MAXLEN;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
nd->mName.length = ::ai_snprintf(nd->mName.data, MAXLEN, "%s_(%08X)", src.name, combined);
|
||||
nd->mName.length = ::ai_snprintf(nd->mName.data, AI_MAXLEN, "%s_(%08X)", src.name, combined);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -707,7 +707,7 @@ void MD5Importer::LoadMD5CameraFile() {
|
|||
for (std::vector<unsigned int>::const_iterator it = cuts.begin(); it != cuts.end() - 1; ++it) {
|
||||
|
||||
aiAnimation *anim = *tmp++ = new aiAnimation();
|
||||
anim->mName.length = ::ai_snprintf(anim->mName.data, MAXLEN, "anim%u_from_%u_to_%u", (unsigned int)(it - cuts.begin()), (*it), *(it + 1));
|
||||
anim->mName.length = ::ai_snprintf(anim->mName.data, AI_MAXLEN, "anim%u_from_%u_to_%u", (unsigned int)(it - cuts.begin()), (*it), *(it + 1));
|
||||
|
||||
anim->mTicksPerSecond = cameraParser.fFrameRate;
|
||||
anim->mChannels = new aiNodeAnim *[anim->mNumChannels = 1];
|
||||
|
|
|
@ -962,7 +962,7 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7 **apcOutBones)
|
|||
|
||||
if (AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE == pcHeader->bone_stc_size) {
|
||||
// no real name for our poor bone is specified :-(
|
||||
pcOutBone->mName.length = ai_snprintf(pcOutBone->mName.data, MAXLEN,
|
||||
pcOutBone->mName.length = ai_snprintf(pcOutBone->mName.data, AI_MAXLEN,
|
||||
"UnnamedBone_%i", iBone);
|
||||
} else {
|
||||
// Make sure we won't run over the buffer's end if there is no
|
||||
|
@ -1567,7 +1567,7 @@ void MDLImporter::InternReadFile_3DGS_MDL7() {
|
|||
} else {
|
||||
pcNode->mName.length = (ai_uint32)::strlen(szBuffer);
|
||||
}
|
||||
::strncpy(pcNode->mName.data, szBuffer, MAXLEN - 1);
|
||||
::strncpy(pcNode->mName.data, szBuffer, AI_MAXLEN - 1);
|
||||
++p;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -494,7 +494,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
|
|||
|
||||
aiString szFile;
|
||||
const size_t iLen = strlen((const char *)szCurrent);
|
||||
size_t iLen2 = iLen > (MAXLEN - 1) ? (MAXLEN - 1) : iLen;
|
||||
size_t iLen2 = iLen > (AI_MAXLEN - 1) ? (AI_MAXLEN - 1) : iLen;
|
||||
memcpy(szFile.data, (const char *)szCurrent, iLen2);
|
||||
szFile.data[iLen2] = '\0';
|
||||
szFile.length = static_cast<ai_uint32>(iLen2);
|
||||
|
|
|
@ -588,7 +588,7 @@ bool Q3BSPFileImporter::importTextureFromArchive(const Q3BSP::Q3BSPModel *model,
|
|||
|
||||
aiString name;
|
||||
name.data[0] = '*';
|
||||
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
|
||||
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(AI_MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
|
||||
|
||||
archive->Close(pTextureStream);
|
||||
|
||||
|
@ -641,7 +641,7 @@ bool Q3BSPFileImporter::importLightmap(const Q3BSP::Q3BSPModel *pModel, aiScene
|
|||
|
||||
aiString name;
|
||||
name.data[0] = '*';
|
||||
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
|
||||
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(AI_MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
|
||||
|
||||
pMatHelper->AddProperty(&name, AI_MATKEY_TEXTURE_LIGHTMAP(1));
|
||||
mTextures.push_back(pTexture);
|
||||
|
|
|
@ -250,7 +250,7 @@ void Q3DImporter::InternReadFile(const std::string &pFile,
|
|||
c = stream.GetI1();
|
||||
while (c) {
|
||||
mat.name.data[mat.name.length++] = c;
|
||||
if (mat.name.length == MAXLEN) {
|
||||
if (mat.name.length == AI_MAXLEN) {
|
||||
ASSIMP_LOG_ERROR("String ouverflow detected, skipped material name parsing.");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -589,12 +589,12 @@ void SMDImporter::CreateOutputMaterials() {
|
|||
pScene->mMaterials[iMat] = pcMat;
|
||||
|
||||
aiString szName;
|
||||
szName.length = static_cast<ai_uint32>(ai_snprintf(szName.data,MAXLEN,"Texture_%u",iMat));
|
||||
szName.length = static_cast<ai_uint32>(ai_snprintf(szName.data, AI_MAXLEN, "Texture_%u", iMat));
|
||||
pcMat->AddProperty(&szName,AI_MATKEY_NAME);
|
||||
|
||||
if (aszTextures[iMat].length())
|
||||
{
|
||||
::strncpy(szName.data, aszTextures[iMat].c_str(),MAXLEN-1);
|
||||
::strncpy(szName.data, aszTextures[iMat].c_str(), AI_MAXLEN - 1);
|
||||
szName.length = static_cast<ai_uint32>( aszTextures[iMat].length() );
|
||||
pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ void STLImporter::LoadASCIIFile(aiNode *root) {
|
|||
size_t temp = (size_t)(sz - szMe);
|
||||
// setup the name of the node
|
||||
if (temp) {
|
||||
if (temp >= MAXLEN) {
|
||||
if (temp >= AI_MAXLEN) {
|
||||
throw DeadlyImportError("STL: Node name too long");
|
||||
}
|
||||
std::string name(szMe, temp);
|
||||
|
|
|
@ -452,7 +452,7 @@ void UnrealImporter::InternReadFile(const std::string &pFile,
|
|||
aiColor3D color(1.f, 1.f, 1.f);
|
||||
|
||||
aiString s;
|
||||
::ai_snprintf(s.data, MAXLEN, "mat%u_tx%u_", i, materials[i].tex);
|
||||
::ai_snprintf(s.data, AI_MAXLEN, "mat%u_tx%u_", i, materials[i].tex);
|
||||
|
||||
// set the two-sided flag
|
||||
if (materials[i].type == Unreal::MF_NORMAL_TS) {
|
||||
|
@ -472,7 +472,7 @@ void UnrealImporter::InternReadFile(const std::string &pFile,
|
|||
|
||||
// a special name for the weapon attachment point
|
||||
if (materials[i].type == Unreal::MF_WEAPON_PLACEHOLDER) {
|
||||
s.length = ::ai_snprintf(s.data, MAXLEN, "$WeaponTag$");
|
||||
s.length = ::ai_snprintf(s.data, AI_MAXLEN, "$WeaponTag$");
|
||||
color = aiColor3D(0.f, 0.f, 0.f);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,7 +109,7 @@ inline void SetMaterialColorProperty(std::vector<int> &embeddedTexIdxs, Asset &
|
|||
if (texIdx != -1) { // embedded
|
||||
// setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture)
|
||||
uri.data[0] = '*';
|
||||
uri.length = 1 + ASSIMP_itoa10(uri.data + 1, MAXLEN - 1, texIdx);
|
||||
uri.length = 1 + ASSIMP_itoa10(uri.data + 1, AI_MAXLEN - 1, texIdx);
|
||||
}
|
||||
|
||||
mat->AddProperty(&uri, _AI_MATKEY_TEXTURE_BASE, texType, 0);
|
||||
|
@ -242,7 +242,7 @@ void glTFImporter::ImportMeshes(glTF::Asset &r) {
|
|||
if (mesh.primitives.size() > 1) {
|
||||
ai_uint32 &len = aim->mName.length;
|
||||
aim->mName.data[len] = '-';
|
||||
len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(MAXLEN - len - 1), p);
|
||||
len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(AI_MAXLEN - len - 1), p);
|
||||
}
|
||||
|
||||
switch (prim.mode) {
|
||||
|
|
|
@ -161,7 +161,7 @@ static void SetMaterialTextureProperty(std::vector<int> &embeddedTexIdxs, Asset
|
|||
if (texIdx != -1) { // embedded
|
||||
// setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture)
|
||||
uri.data[0] = '*';
|
||||
uri.length = 1 + ASSIMP_itoa10(uri.data + 1, MAXLEN - 1, texIdx);
|
||||
uri.length = 1 + ASSIMP_itoa10(uri.data + 1, AI_MAXLEN - 1, texIdx);
|
||||
}
|
||||
|
||||
mat->AddProperty(&uri, AI_MATKEY_TEXTURE(texType, texSlot));
|
||||
|
@ -539,7 +539,7 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
|
|||
if (mesh.primitives.size() > 1) {
|
||||
ai_uint32 &len = aim->mName.length;
|
||||
aim->mName.data[len] = '-';
|
||||
len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(MAXLEN - len - 1), p);
|
||||
len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(AI_MAXLEN - len - 1), p);
|
||||
}
|
||||
|
||||
switch (prim.mode) {
|
||||
|
|
|
@ -78,7 +78,7 @@ inline void PrefixString(aiString &string, const char *prefix, unsigned int len)
|
|||
if (string.length >= 1 && string.data[0] == '$')
|
||||
return;
|
||||
|
||||
if (len + string.length >= MAXLEN - 1) {
|
||||
if (len + string.length >= AI_MAXLEN - 1) {
|
||||
ASSIMP_LOG_VERBOSE_DEBUG("Can't add an unique prefix because the string is too long");
|
||||
ai_assert(false);
|
||||
return;
|
||||
|
@ -408,7 +408,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
|
|||
// where n is the index of the texture.
|
||||
// Copy here because we overwrite the string data in-place and the buffer inside of aiString
|
||||
// will be a lie if we just reinterpret from prop->mData. The size of mData is not guaranteed to be
|
||||
// MAXLEN in size.
|
||||
// AI_MAXLEN in size.
|
||||
aiString s(*(aiString *)prop->mData);
|
||||
if ('*' == s.data[0]) {
|
||||
// Offset the index and write it back ..
|
||||
|
|
|
@ -486,7 +486,7 @@ aiReturn aiMaterial::AddBinaryProperty(const void *pInput,
|
|||
memcpy(pcNew->mData, pInput, pSizeInBytes);
|
||||
|
||||
pcNew->mKey.length = static_cast<ai_uint32>(::strlen(pKey));
|
||||
ai_assert(MAXLEN > pcNew->mKey.length);
|
||||
ai_assert(AI_MAXLEN > pcNew->mKey.length);
|
||||
strcpy(pcNew->mKey.data, pKey);
|
||||
|
||||
if (UINT_MAX != iOutIndex) {
|
||||
|
|
|
@ -164,7 +164,7 @@ void OptimizeGraphProcess::CollectNewChildren(aiNode *nd, std::list<aiNode *> &n
|
|||
++it;
|
||||
}
|
||||
if (join_master && !join.empty()) {
|
||||
join_master->mName.length = ::ai_snprintf(join_master->mName.data, MAXLEN, "$MergedNode_%u", count_merged++);
|
||||
join_master->mName.length = ::ai_snprintf(join_master->mName.data, AI_MAXLEN, "$MergedNode_%u", count_merged++);
|
||||
|
||||
unsigned int out_meshes = 0;
|
||||
for (std::list<aiNode *>::const_iterator it = join.cbegin(); it != join.cend(); ++it) {
|
||||
|
|
|
@ -635,7 +635,7 @@ void PretransformVertices::Execute(aiScene *pScene) {
|
|||
aiNode *pcNode = new aiNode();
|
||||
*nodes = pcNode;
|
||||
pcNode->mParent = pScene->mRootNode;
|
||||
pcNode->mName.length = ai_snprintf(pcNode->mName.data, MAXLEN, "light_%u", i);
|
||||
pcNode->mName.length = ai_snprintf(pcNode->mName.data, AI_MAXLEN, "light_%u", i);
|
||||
pScene->mLights[i]->mName = pcNode->mName;
|
||||
}
|
||||
// generate camera nodes
|
||||
|
@ -643,7 +643,7 @@ void PretransformVertices::Execute(aiScene *pScene) {
|
|||
aiNode *pcNode = new aiNode();
|
||||
*nodes = pcNode;
|
||||
pcNode->mParent = pScene->mRootNode;
|
||||
pcNode->mName.length = ::ai_snprintf(pcNode->mName.data, MAXLEN, "cam_%u", i);
|
||||
pcNode->mName.length = ::ai_snprintf(pcNode->mName.data, AI_MAXLEN, "cam_%u", i);
|
||||
pScene->mCameras[i]->mName = pcNode->mName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,7 +176,7 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) {
|
|||
if (ppcMaterials[idx]) {
|
||||
aiString sz;
|
||||
if( ppcMaterials[idx]->Get(AI_MATKEY_NAME, sz) != AI_SUCCESS ) {
|
||||
sz.length = ::ai_snprintf(sz.data,MAXLEN,"JoinedMaterial_#%u",p);
|
||||
sz.length = ::ai_snprintf(sz.data, AI_MAXLEN,"JoinedMaterial_#%u",p);
|
||||
((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -909,9 +909,9 @@ void ValidateDSProcess::Validate(const aiNode *pNode) {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ValidateDSProcess::Validate(const aiString *pString) {
|
||||
if (pString->length > MAXLEN) {
|
||||
if (pString->length > AI_MAXLEN) {
|
||||
ReportError("aiString::length is too large (%u, maximum is %lu)",
|
||||
pString->length, MAXLEN);
|
||||
pString->length, AI_MAXLEN);
|
||||
}
|
||||
const char *sz = pString->data;
|
||||
while (true) {
|
||||
|
@ -920,7 +920,7 @@ void ValidateDSProcess::Validate(const aiString *pString) {
|
|||
ReportError("aiString::data is invalid: the terminal zero is at a wrong offset");
|
||||
}
|
||||
break;
|
||||
} else if (sz >= &pString->data[MAXLEN]) {
|
||||
} else if (sz >= &pString->data[AI_MAXLEN]) {
|
||||
ReportError("aiString::data is invalid. There is no terminal character");
|
||||
}
|
||||
++sz;
|
||||
|
|
|
@ -57,9 +57,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <iomanip>
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#define AI_SIZEFMT "%Iu"
|
||||
# define AI_SIZEFMT "%Iu"
|
||||
#else
|
||||
#define AI_SIZEFMT "%zu"
|
||||
# define AI_SIZEFMT "%zu"
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
@ -99,9 +99,9 @@ inline int ai_snprintf(char *outBuf, size_t size, const char *format, ...) {
|
|||
}
|
||||
|
||||
#elif defined(__MINGW32__)
|
||||
#define ai_snprintf __mingw_snprintf
|
||||
# define ai_snprintf __mingw_snprintf
|
||||
#else
|
||||
#define ai_snprintf snprintf
|
||||
# define ai_snprintf snprintf
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
@ -185,6 +185,7 @@ AI_FORCE_INLINE std::string ai_rgba2hex(int r, int g, int b, int a, bool with_he
|
|||
// ---------------------------------------------------------------------------------
|
||||
/// @brief Performs a trim from start (in place)
|
||||
/// @param s string to trim.
|
||||
// ---------------------------------------------------------------------------------
|
||||
AI_FORCE_INLINE void ai_trim_left(std::string &s) {
|
||||
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
|
@ -195,7 +196,6 @@ AI_FORCE_INLINE void ai_trim_left(std::string &s) {
|
|||
/// @brief Performs a trim from end (in place).
|
||||
/// @param s string to trim.
|
||||
// ---------------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------------
|
||||
AI_FORCE_INLINE void ai_trim_right(std::string &s) {
|
||||
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
||||
return !std::isspace(ch);
|
||||
|
@ -214,6 +214,10 @@ AI_FORCE_INLINE std::string ai_trim(std::string &s) {
|
|||
return out;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
/// @brief Performs a to lower operation onto on single character.
|
||||
/// @param in The character
|
||||
/// @return the character as lower-case.
|
||||
// ---------------------------------------------------------------------------------
|
||||
template <class char_t>
|
||||
AI_FORCE_INLINE char_t ai_tolower(char_t in) {
|
||||
|
@ -233,6 +237,10 @@ AI_FORCE_INLINE std::string ai_tolower(const std::string &in) {
|
|||
return out;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
/// @brief Performs a to upper operation onto on single character.
|
||||
/// @param in The character
|
||||
/// @return the character as upper-case.
|
||||
// ---------------------------------------------------------------------------------
|
||||
template <class char_t>
|
||||
AI_FORCE_INLINE char_t ai_toupper(char_t in) {
|
||||
|
@ -243,6 +251,7 @@ AI_FORCE_INLINE char_t ai_toupper(char_t in) {
|
|||
/// @brief Performs a ToLower-operation and return the upper-case string.
|
||||
/// @param in The incoming string.
|
||||
/// @return The string as uppercase.
|
||||
// ---------------------------------------------------------------------------------
|
||||
AI_FORCE_INLINE std::string ai_str_toupper(const std::string &in) {
|
||||
std::string out(in);
|
||||
std::transform(out.begin(), out.end(), out.begin(), [](char c) { return ai_toupper(c); });
|
||||
|
@ -255,6 +264,7 @@ AI_FORCE_INLINE std::string ai_str_toupper(const std::string &in) {
|
|||
/// @param in The incoming string.
|
||||
/// @param placeholder Placeholder character, default is a question mark.
|
||||
/// @return The string, with all non-printable characters replaced.
|
||||
// ---------------------------------------------------------------------------------
|
||||
AI_FORCE_INLINE std::string ai_str_toprintable(const std::string &in, char placeholder = '?') {
|
||||
std::string out(in);
|
||||
std::transform(out.begin(), out.end(), out.begin(), [placeholder] (unsigned char c) {
|
||||
|
@ -271,9 +281,9 @@ AI_FORCE_INLINE std::string ai_str_toprintable(const std::string &in, char place
|
|||
/// @param placeholder Placeholder character, default is a question mark.
|
||||
/// @return The string, with all non-printable characters replaced. Will return an
|
||||
/// empty string if in is null or len is <= 0.
|
||||
// ---------------------------------------------------------------------------------
|
||||
AI_FORCE_INLINE std::string ai_str_toprintable(const char *in, int len, char placeholder = '?') {
|
||||
return (in && len > 0) ? ai_str_toprintable(std::string(in, len), placeholder) : std::string();
|
||||
}
|
||||
|
||||
|
||||
#endif // INCLUDED_AI_STRINGUTILS_H
|
||||
|
|
|
@ -118,9 +118,9 @@ extern "C" {
|
|||
|
||||
/** Maximum dimension for strings, ASSIMP strings are zero terminated. */
|
||||
#ifdef __cplusplus
|
||||
static const size_t MAXLEN = 1024;
|
||||
static const size_t AI_MAXLEN = 1024;
|
||||
#else
|
||||
#define MAXLEN 1024
|
||||
#define AI_MAXLEN 1024
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
@ -243,7 +243,8 @@ struct aiColor3D {
|
|||
}; // !struct aiColor3D
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
/** Represents an UTF-8 string, zero byte terminated.
|
||||
/**
|
||||
* @brief Represents an UTF-8 string, zero byte terminated.
|
||||
*
|
||||
* The character set of an aiString is explicitly defined to be UTF-8. This Unicode
|
||||
* transformation was chosen in the belief that most strings in 3d files are limited
|
||||
|
@ -260,42 +261,40 @@ struct aiColor3D {
|
|||
* UTF-8 strings to their working character set (i.e. MBCS, WideChar).
|
||||
*
|
||||
* We use this representation instead of std::string to be C-compatible. The
|
||||
* (binary) length of such a string is limited to MAXLEN characters (including the
|
||||
* (binary) length of such a string is limited to AI_MAXLEN characters (including the
|
||||
* the terminating zero).
|
||||
*/
|
||||
*/
|
||||
struct aiString {
|
||||
#ifdef __cplusplus
|
||||
/** Default constructor, the string is set to have zero length */
|
||||
aiString() AI_NO_EXCEPT
|
||||
: length(0) {
|
||||
data[0] = '\0';
|
||||
|
||||
aiString() AI_NO_EXCEPT :
|
||||
length(0), data{'\0'} {
|
||||
#ifdef ASSIMP_BUILD_DEBUG
|
||||
// Debug build: overwrite the string on its full length with ESC (27)
|
||||
memset(data + 1, 27, MAXLEN - 1);
|
||||
memset(data + 1, 27, AI_MAXLEN - 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Copy constructor */
|
||||
aiString(const aiString &rOther) :
|
||||
length(rOther.length) {
|
||||
length(rOther.length), data{'\0'} {
|
||||
// Crop the string to the maximum length
|
||||
length = length >= MAXLEN ? MAXLEN - 1 : length;
|
||||
length = length >= AI_MAXLEN ? AI_MAXLEN - 1 : length;
|
||||
memcpy(data, rOther.data, length);
|
||||
data[length] = '\0';
|
||||
}
|
||||
|
||||
/** Constructor from std::string */
|
||||
explicit aiString(const std::string &pString) :
|
||||
length((ai_uint32)pString.length()) {
|
||||
length = length >= MAXLEN ? MAXLEN - 1 : length;
|
||||
length((ai_uint32)pString.length()), data{'\0'} {
|
||||
length = length >= AI_MAXLEN ? AI_MAXLEN - 1 : length;
|
||||
memcpy(data, pString.c_str(), length);
|
||||
data[length] = '\0';
|
||||
}
|
||||
|
||||
/** Copy a std::string to the aiString */
|
||||
void Set(const std::string &pString) {
|
||||
if (pString.length() > MAXLEN - 1) {
|
||||
if (pString.length() > AI_MAXLEN - 1) {
|
||||
return;
|
||||
}
|
||||
length = (ai_uint32)pString.length();
|
||||
|
@ -306,8 +305,8 @@ struct aiString {
|
|||
/** Copy a const char* to the aiString */
|
||||
void Set(const char *sz) {
|
||||
ai_int32 len = (ai_uint32)::strlen(sz);
|
||||
if (len > (ai_int32)MAXLEN - 1) {
|
||||
len = (ai_int32) MAXLEN - 1;
|
||||
if (len > static_cast<ai_int32>(AI_MAXLEN - 1)) {
|
||||
len = static_cast<ai_int32>(AI_MAXLEN - 1);
|
||||
}
|
||||
length = len;
|
||||
memcpy(data, sz, len);
|
||||
|
@ -321,8 +320,8 @@ struct aiString {
|
|||
}
|
||||
|
||||
length = rOther.length;
|
||||
if (length >(MAXLEN - 1)) {
|
||||
length = (ai_int32) MAXLEN - 1;
|
||||
if (length > (AI_MAXLEN - 1)) {
|
||||
length = static_cast<ai_int32>(AI_MAXLEN - 1);
|
||||
}
|
||||
|
||||
memcpy(data, rOther.data, length);
|
||||
|
@ -344,21 +343,24 @@ struct aiString {
|
|||
|
||||
/** Comparison operator */
|
||||
bool operator==(const aiString &other) const {
|
||||
return (length == other.length && 0 == memcmp(data, other.data, length));
|
||||
if (length == other.length) {
|
||||
return memcmp(data, other.data, length) == 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Inverse comparison operator */
|
||||
bool operator!=(const aiString &other) const {
|
||||
return (length != other.length || 0 != memcmp(data, other.data, length));
|
||||
return !(*this == other);
|
||||
}
|
||||
|
||||
/** Append a string to the string */
|
||||
void Append(const char *app) {
|
||||
const ai_uint32 len = (ai_uint32)::strlen(app);
|
||||
const ai_uint32 len = static_cast<ai_uint32>(::strlen(app));
|
||||
if (!len) {
|
||||
return;
|
||||
}
|
||||
if (length + len >= MAXLEN) {
|
||||
if (length + len >= AI_MAXLEN) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -373,7 +375,7 @@ struct aiString {
|
|||
|
||||
#ifdef ASSIMP_BUILD_DEBUG
|
||||
// Debug build: overwrite the string on its full length with ESC (27)
|
||||
memset(data + 1, 27, MAXLEN - 1);
|
||||
memset(data + 1, 27, AI_MAXLEN - 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -389,8 +391,8 @@ struct aiString {
|
|||
* the number of bytes from the beginning of the string to its end.*/
|
||||
ai_uint32 length;
|
||||
|
||||
/** String buffer. Size limit is MAXLEN */
|
||||
char data[MAXLEN];
|
||||
/** String buffer. Size limit is AI_MAXLEN */
|
||||
char data[AI_MAXLEN];
|
||||
}; // !struct aiString
|
||||
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
|
|
@ -68,7 +68,7 @@ void AddNodes(unsigned int num, aiNode *father, unsigned int depth) {
|
|||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
aiNode *nd = father->mChildren[i] = new aiNode();
|
||||
|
||||
nd->mName.length = snprintf(nd->mName.data, MAXLEN, "%i%i", depth, i);
|
||||
nd->mName.length = snprintf(nd->mName.data, AI_MAXLEN, "%i%i", depth, i);
|
||||
|
||||
// spawn two meshes
|
||||
nd->mMeshes = new unsigned int[nd->mNumMeshes = 2];
|
||||
|
|
|
@ -174,7 +174,7 @@ int CDisplay::AddNodeToDisplayList(
|
|||
ai_assert(nullptr != pcNode);
|
||||
ai_assert(nullptr != hRoot);
|
||||
|
||||
char chTemp[MAXLEN];
|
||||
char chTemp[AI_MAXLEN];
|
||||
|
||||
if(0 == pcNode->mName.length) {
|
||||
if (iIndex >= 100) {
|
||||
|
@ -186,12 +186,12 @@ int CDisplay::AddNodeToDisplayList(
|
|||
}
|
||||
else
|
||||
iIndex += iDepth * 10;
|
||||
ai_snprintf(chTemp, MAXLEN,"Node %u",iIndex);
|
||||
ai_snprintf(chTemp,AI_MAXLEN,"Node %u",iIndex);
|
||||
}
|
||||
else {
|
||||
ai_snprintf(chTemp, MAXLEN,"%s",pcNode->mName.data);
|
||||
ai_snprintf(chTemp, AI_MAXLEN, "%s", pcNode->mName.data);
|
||||
}
|
||||
ai_snprintf(chTemp+strlen(chTemp), MAXLEN- strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)",pcNode->mNumMeshes);
|
||||
ai_snprintf(chTemp + strlen(chTemp), AI_MAXLEN - strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)", pcNode->mNumMeshes);
|
||||
|
||||
TVITEMEXW tvi;
|
||||
TVINSERTSTRUCTW sNew;
|
||||
|
@ -236,15 +236,15 @@ int CDisplay::AddMeshToDisplayList(unsigned int iIndex, HTREEITEM hRoot)
|
|||
{
|
||||
aiMesh* pcMesh = g_pcAsset->pcScene->mMeshes[iIndex];
|
||||
|
||||
char chTemp[MAXLEN];
|
||||
char chTemp[AI_MAXLEN];
|
||||
|
||||
if(0 == pcMesh->mName.length) {
|
||||
ai_snprintf(chTemp,MAXLEN,"Mesh %u",iIndex);
|
||||
ai_snprintf(chTemp, AI_MAXLEN, "Mesh %u", iIndex);
|
||||
}
|
||||
else {
|
||||
ai_snprintf(chTemp,MAXLEN,"%s",pcMesh->mName.data);
|
||||
ai_snprintf(chTemp, AI_MAXLEN, "%s", pcMesh->mName.data);
|
||||
}
|
||||
ai_snprintf(chTemp+strlen(chTemp),MAXLEN-strlen(chTemp), iIndex ? " (%i)" : " (%i faces)",pcMesh->mNumFaces);
|
||||
ai_snprintf(chTemp + strlen(chTemp), AI_MAXLEN - strlen(chTemp), iIndex ? " (%i)" : " (%i faces)", pcMesh->mNumFaces);
|
||||
|
||||
TVITEMEXW tvi;
|
||||
TVINSERTSTRUCTW sNew;
|
||||
|
@ -280,8 +280,7 @@ int CDisplay::AddMeshToDisplayList(unsigned int iIndex, HTREEITEM hRoot)
|
|||
|
||||
//-------------------------------------------------------------------------------
|
||||
// Replace the currently selected texture by another one
|
||||
int CDisplay::ReplaceCurrentTexture(const char* szPath)
|
||||
{
|
||||
int CDisplay::ReplaceCurrentTexture(const char* szPath) {
|
||||
ai_assert(nullptr != szPath);
|
||||
|
||||
// well ... try to load it
|
||||
|
|
|
@ -281,7 +281,7 @@ bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString)
|
|||
// copy the result string back to the aiString
|
||||
const size_t iLen = strlen(szTempB);
|
||||
size_t iLen2 = iLen+1;
|
||||
iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
|
||||
iLen2 = iLen2 > AI_MAXLEN ? AI_MAXLEN : iLen2;
|
||||
memcpy(p_szString->data,szTempB,iLen2);
|
||||
p_szString->length = static_cast<ai_uint32>(iLen);
|
||||
return true;
|
||||
|
@ -295,7 +295,7 @@ bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString)
|
|||
// copy the result string back to the aiString
|
||||
const size_t iLen = strlen(szTempB);
|
||||
size_t iLen2 = iLen+1;
|
||||
iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
|
||||
iLen2 = iLen2 > AI_MAXLEN ? AI_MAXLEN : iLen2;
|
||||
memcpy(p_szString->data,szTempB,iLen2);
|
||||
p_szString->length = static_cast<ai_uint32>(iLen);
|
||||
return true;
|
||||
|
@ -402,7 +402,7 @@ int CMaterialManager::FindValidPath(aiString* p_szString)
|
|||
// copy the result string back to the aiStr
|
||||
const size_t len = strlen(szTemp);
|
||||
size_t len2 = len+1;
|
||||
len2 = len2 > MAXLEN ? MAXLEN : len2;
|
||||
len2 = len2 > AI_MAXLEN ? AI_MAXLEN : len2;
|
||||
memcpy(p_szString->data, szTemp, len2);
|
||||
p_szString->length = static_cast<ai_uint32>(len);
|
||||
}
|
||||
|
|
|
@ -842,7 +842,7 @@ void OpenAsset() {
|
|||
aiString sz;
|
||||
aiGetExtensionList(&sz);
|
||||
|
||||
char szList[MAXLEN + 100];
|
||||
char szList[AI_MAXLEN + 100];
|
||||
strcpy(szList,"ASSIMP assets");
|
||||
char* szCur = szList + 14;
|
||||
strcpy(szCur,sz.data);
|
||||
|
|
Loading…
Reference in New Issue