Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/volume.cc
| Show First 20 Lines • Show All 777 Lines • ▼ Show 20 Lines | #ifdef WITH_OPENVDB | ||||
| /* Double-checked lock. */ | /* Double-checked lock. */ | ||||
| std::lock_guard<std::mutex> lock(grids.mutex); | std::lock_guard<std::mutex> lock(grids.mutex); | ||||
| if (BKE_volume_is_loaded(volume)) { | if (BKE_volume_is_loaded(volume)) { | ||||
| return grids.error_msg.empty(); | return grids.error_msg.empty(); | ||||
| } | } | ||||
| /* Get absolute file path at current frame. */ | /* Get absolute file path at current frame. */ | ||||
| const char *volume_name = volume->id.name + 2; | const char *volume_name = volume->id.name + 2; | ||||
| volume_filepath_get(bmain, volume, grids.filepath); | char filepath[FILE_MAX]; | ||||
| volume_filepath_get(bmain, volume, filepath); | |||||
| CLOG_INFO(&LOG, 1, "Volume %s: load %s", volume_name, grids.filepath); | CLOG_INFO(&LOG, 1, "Volume %s: load %s", volume_name, filepath); | ||||
| /* Test if file exists. */ | /* Test if file exists. */ | ||||
| if (!BLI_exists(grids.filepath)) { | if (!BLI_exists(filepath)) { | ||||
| char filename[FILE_MAX]; | char filename[FILE_MAX]; | ||||
| BLI_split_file_part(grids.filepath, filename, sizeof(filename)); | BLI_split_file_part(filepath, filename, sizeof(filename)); | ||||
| grids.error_msg = filename + std::string(" not found"); | grids.error_msg = filename + std::string(" not found"); | ||||
| CLOG_INFO(&LOG, 1, "Volume %s: %s", volume_name, grids.error_msg.c_str()); | CLOG_INFO(&LOG, 1, "Volume %s: %s", volume_name, grids.error_msg.c_str()); | ||||
| return false; | return false; | ||||
| } | } | ||||
| /* Open OpenVDB file. */ | /* Open OpenVDB file. */ | ||||
| openvdb::io::File file(grids.filepath); | openvdb::io::File file(filepath); | ||||
| openvdb::GridPtrVec vdb_grids; | openvdb::GridPtrVec vdb_grids; | ||||
| try { | try { | ||||
| file.setCopyMaxBytes(0); | file.setCopyMaxBytes(0); | ||||
| file.open(); | file.open(); | ||||
| vdb_grids = *(file.readAllGridMetadata()); | vdb_grids = *(file.readAllGridMetadata()); | ||||
| grids.metadata = file.getMetadata(); | grids.metadata = file.getMetadata(); | ||||
| } | } | ||||
| catch (const openvdb::IoError &e) { | catch (const openvdb::IoError &e) { | ||||
| grids.error_msg = e.what(); | grids.error_msg = e.what(); | ||||
| CLOG_INFO(&LOG, 1, "Volume %s: %s", volume_name, grids.error_msg.c_str()); | CLOG_INFO(&LOG, 1, "Volume %s: %s", volume_name, grids.error_msg.c_str()); | ||||
| } | } | ||||
| /* Add grids read from file to own vector, filtering out any NULL pointers. */ | /* Add grids read from file to own vector, filtering out any NULL pointers. */ | ||||
| for (const openvdb::GridBase::Ptr &vdb_grid : vdb_grids) { | for (const openvdb::GridBase::Ptr &vdb_grid : vdb_grids) { | ||||
| if (vdb_grid) { | if (vdb_grid) { | ||||
| VolumeFileCache::Entry template_entry(grids.filepath, vdb_grid); | VolumeFileCache::Entry template_entry(filepath, vdb_grid); | ||||
| grids.emplace_back(template_entry, volume->runtime.default_simplify_level); | grids.emplace_back(template_entry, volume->runtime.default_simplify_level); | ||||
| } | } | ||||
| } | } | ||||
| BLI_strncpy(grids.filepath, filepath, FILE_MAX); | |||||
| return grids.error_msg.empty(); | return grids.error_msg.empty(); | ||||
| #else | #else | ||||
| UNUSED_VARS(bmain, volume); | UNUSED_VARS(bmain, volume); | ||||
| return true; | return true; | ||||
| #endif | #endif | ||||
| } | } | ||||
| void BKE_volume_unload(Volume *volume) | void BKE_volume_unload(Volume *volume) | ||||
| ▲ Show 20 Lines • Show All 715 Lines • Show Last 20 Lines | |||||