Fix bug in cached meshes where convex hull was missing. Previously if a mesh was copied from the cache it would not have its convex hull if the original mesh that was cached didn't previously compute it.

Fixes #2609

PiperOrigin-RevId: 756223337
Change-Id: I54705456636c270607a17340b249047e0df75d0b
This commit is contained in:
Kyle Bayes
2025-05-08 02:41:06 -07:00
committed by Copybara-Service
parent 6cfea71985
commit f4774a5449
6 changed files with 88 additions and 57 deletions
+12 -7
View File
@@ -75,14 +75,19 @@ PNGImage PNGImage::Load(const mjCBase* obj, mjResource* resource,
image.color_type_ = color_type;
mjCCache *cache = reinterpret_cast<mjCCache*>(mj_globalCache());
// cache callback
auto callback = [&image](const void* data) {
const PNGImage *cached_image = static_cast<const PNGImage*>(data);
if (cached_image->color_type_ == image.color_type_) {
image = *cached_image;
return true;
}
return false;
};
// try loading from cache
if (cache && cache->PopulateData(resource, [&image](const void* data) {
const PNGImage *cached_image = static_cast<const PNGImage*>(data);
if (cached_image->color_type_ == image.color_type_) {
image = *cached_image;
}
})) {
if (!image.data_.empty()) return image;
if (cache && cache->PopulateData(resource, callback)) {
return image;
}
// open PNG resource