mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-14 18:25:55 +08:00
better implementation for bin file name checking
This commit is contained in:
parent
7cb31e4e23
commit
c884e5827e
19
tiny_gltf.h
19
tiny_gltf.h
@ -4567,7 +4567,7 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BUFFERS
|
// BUFFERS
|
||||||
int numDefaultBufferNamesUsed = 0;
|
std::vector<std::string> usedUris;
|
||||||
json buffers;
|
json buffers;
|
||||||
for (unsigned int i = 0; i < model->buffers.size(); ++i) {
|
for (unsigned int i = 0; i < model->buffers.size(); ++i) {
|
||||||
json buffer;
|
json buffer;
|
||||||
@ -4581,11 +4581,20 @@ bool TinyGLTF::WriteGltfSceneToFile(Model *model, const std::string &filename,
|
|||||||
binUri = model->buffers[i].uri;
|
binUri = model->buffers[i].uri;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
binUri = defaultBinFilename;
|
binUri = defaultBinFilename + defaultBinFileExt;
|
||||||
if(numDefaultBufferNamesUsed > 0)
|
bool inUse = true;
|
||||||
binUri += std::to_string(numDefaultBufferNamesUsed++);
|
int numUsed = 0;
|
||||||
binUri += defaultBinFileExt;
|
while(inUse) {
|
||||||
|
inUse = false;
|
||||||
|
for (const std::string& usedName : usedUris) {
|
||||||
|
if (binUri.compare(usedName) != 0) continue;
|
||||||
|
inUse = true;
|
||||||
|
binUri = defaultBinFilename + std::to_string(numUsed++) + defaultBinFileExt;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
usedUris.push_back(binUri);
|
||||||
binSavePath = JoinPath(baseDir, binUri);
|
binSavePath = JoinPath(baseDir, binUri);
|
||||||
SerializeGltfBuffer(model->buffers[i], buffer, binSavePath,
|
SerializeGltfBuffer(model->buffers[i], buffer, binSavePath,
|
||||||
binUri);
|
binUri);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user