model import: embedded image will use full file data hash as resource name to avoid collisions between multiple models
This commit is contained in:
@@ -112,10 +112,7 @@ void ImportModel_FBX(const std::string& filename, wi::scene::Scene& scene)
|
||||
if (filename.empty())
|
||||
{
|
||||
// Force some image resource name:
|
||||
do {
|
||||
filename.clear();
|
||||
filename += "fbximport_" + std::to_string(wi::random::GetRandom(std::numeric_limits<uint32_t>::max())) + ".png";
|
||||
} while (wi::resourcemanager::Contains(filename)); // this is to avoid overwriting an existing imported image
|
||||
filename = "fbximport_" + std::to_string(wi::helper::HashByteData((const uint8_t*)texture->content.data, texture->content.size)) + ".png";
|
||||
}
|
||||
|
||||
auto resource = wi::resourcemanager::Load(
|
||||
|
||||
@@ -90,12 +90,7 @@ namespace tinygltf
|
||||
if (image->uri.empty())
|
||||
{
|
||||
// Force some image resource name:
|
||||
std::string ss;
|
||||
do {
|
||||
ss.clear();
|
||||
ss += "gltfimport_" + std::to_string(wi::random::GetRandom(std::numeric_limits<uint32_t>::max())) + ".png";
|
||||
} while (wi::resourcemanager::Contains(ss)); // this is to avoid overwriting an existing imported image
|
||||
image->uri = ss;
|
||||
image->uri = "gltfimport_" + std::to_string(wi::helper::HashByteData(bytes, size)) + ".png";
|
||||
}
|
||||
|
||||
auto resource = wi::resourcemanager::Load(
|
||||
|
||||
@@ -1612,4 +1612,14 @@ namespace wi::helper
|
||||
res = ZSTD_decompress(dst_data.data(), dst_data.size(), src_data, src_size);
|
||||
return ZSTD_isError(res) == 0;
|
||||
}
|
||||
|
||||
size_t HashByteData(const uint8_t* data, size_t size)
|
||||
{
|
||||
size_t hash = 0;
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
{
|
||||
hash_combine(hash, data[i]);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,4 +190,7 @@ namespace wi::helper
|
||||
|
||||
// Lossless decompression of byte array that was compressed with wi::helper::Compress()
|
||||
bool Decompress(const uint8_t* src_data, size_t src_size, wi::vector<uint8_t>& dst_data);
|
||||
|
||||
// Hash the contents of a file:
|
||||
size_t HashByteData(const uint8_t* data, size_t size);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user