OpenVDB : use underscores instead of spaces in grid names.

Some other software cannot handle grid names with spaces in them. We still check for names with spaces so as to not break old
files.

This fixes T53802.
This commit is contained in:
Kévin Dietrich
2018-01-29 18:37:35 +01:00
parent 0aec2dcd3a
commit 6d8a4c10b6
3 changed files with 42 additions and 17 deletions

View File

@@ -165,4 +165,19 @@ void OpenVDB_import_grid_vector(
}
}
openvdb::Name do_name_versionning(const openvdb::Name &name)
{
openvdb::Name temp_name = name;
if (temp_name.find("_low", temp_name.size() - 4, 4) == temp_name.size() - 4) {
return temp_name.replace(temp_name.size() - 4, 4, " low");
}
if (temp_name.find("_old", temp_name.size() - 4, 4) == temp_name.size() - 4) {
return temp_name.replace(temp_name.size() - 4, 4, " old");
}
return temp_name;
}
} /* namespace internal */

View File

@@ -40,6 +40,10 @@
namespace internal {
/* Verify that the name does not correspond to the old format, in which case we
* need to replace the '_low' ending with ' low'. See T53802. */
openvdb::Name do_name_versionning(const openvdb::Name &name);
openvdb::Mat4R convertMatrix(const float mat[4][4]);
template <typename GridType, typename T>
@@ -87,13 +91,19 @@ void OpenVDB_import_grid(
{
using namespace openvdb;
if (!reader->hasGrid(name)) {
std::fprintf(stderr, "OpenVDB grid %s not found in file!\n", name.c_str());
memset(*data, 0, sizeof(T) * res[0] * res[1] * res[2]);
return;
openvdb::Name temp_name = name;
if (!reader->hasGrid(temp_name)) {
temp_name = do_name_versionning(temp_name);
if (!reader->hasGrid(temp_name)) {
std::fprintf(stderr, "OpenVDB grid %s not found in file!\n", temp_name.c_str());
memset(*data, 0, sizeof(T) * res[0] * res[1] * res[2]);
return;
}
}
typename GridType::Ptr grid = gridPtrCast<GridType>(reader->getGrid(name));
typename GridType::Ptr grid = gridPtrCast<GridType>(reader->getGrid(temp_name));
typename GridType::ConstAccessor acc = grid->getConstAccessor();
math::Coord xyz;