diff options
Diffstat (limited to 'intern/cycles/render/image_vdb.cpp')
-rw-r--r-- | intern/cycles/render/image_vdb.cpp | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/intern/cycles/render/image_vdb.cpp b/intern/cycles/render/image_vdb.cpp index 3f7dd45ee88..fc2cfe9874e 100644 --- a/intern/cycles/render/image_vdb.cpp +++ b/intern/cycles/render/image_vdb.cpp @@ -20,6 +20,9 @@ # include <openvdb/openvdb.h> # include <openvdb/tools/Dense.h> #endif +#ifdef WITH_NANOVDB +# include <nanovdb/util/OpenToNanoVDB.h> +#endif CCL_NAMESPACE_BEGIN @@ -53,41 +56,84 @@ bool VDBImageLoader::load_metadata(ImageMetaData &metadata) /* Set data type. */ if (grid->isType<openvdb::FloatGrid>()) { metadata.channels = 1; +# ifdef WITH_NANOVDB + nanogrid = nanovdb::openToNanoVDB(*openvdb::gridConstPtrCast<openvdb::FloatGrid>(grid)); +# endif } else if (grid->isType<openvdb::Vec3fGrid>()) { metadata.channels = 3; +# ifdef WITH_NANOVDB + nanogrid = nanovdb::openToNanoVDB(*openvdb::gridConstPtrCast<openvdb::Vec3fGrid>(grid)); +# endif } else if (grid->isType<openvdb::BoolGrid>()) { metadata.channels = 1; +# ifdef WITH_NANOVDB + nanogrid = nanovdb::openToNanoVDB( + openvdb::FloatGrid(*openvdb::gridConstPtrCast<openvdb::BoolGrid>(grid))); +# endif } else if (grid->isType<openvdb::DoubleGrid>()) { metadata.channels = 1; +# ifdef WITH_NANOVDB + nanogrid = nanovdb::openToNanoVDB( + openvdb::FloatGrid(*openvdb::gridConstPtrCast<openvdb::DoubleGrid>(grid))); +# endif } else if (grid->isType<openvdb::Int32Grid>()) { metadata.channels = 1; +# ifdef WITH_NANOVDB + nanogrid = nanovdb::openToNanoVDB( + openvdb::FloatGrid(*openvdb::gridConstPtrCast<openvdb::Int32Grid>(grid))); +# endif } else if (grid->isType<openvdb::Int64Grid>()) { metadata.channels = 1; +# ifdef WITH_NANOVDB + nanogrid = nanovdb::openToNanoVDB( + openvdb::FloatGrid(*openvdb::gridConstPtrCast<openvdb::Int64Grid>(grid))); +# endif } else if (grid->isType<openvdb::Vec3IGrid>()) { metadata.channels = 3; +# ifdef WITH_NANOVDB + nanogrid = nanovdb::openToNanoVDB( + openvdb::Vec3fGrid(*openvdb::gridConstPtrCast<openvdb::Vec3IGrid>(grid))); +# endif } else if (grid->isType<openvdb::Vec3dGrid>()) { metadata.channels = 3; +# ifdef WITH_NANOVDB + nanogrid = nanovdb::openToNanoVDB( + openvdb::Vec3fGrid(*openvdb::gridConstPtrCast<openvdb::Vec3dGrid>(grid))); +# endif } else if (grid->isType<openvdb::MaskGrid>()) { metadata.channels = 1; +# ifdef WITH_NANOVDB + return false; // Unsupported +# endif } else { return false; } +# ifdef WITH_NANOVDB + metadata.byte_size = nanogrid.size(); + if (metadata.channels == 1) { + metadata.type = IMAGE_DATA_TYPE_NANOVDB_FLOAT; + } + else { + metadata.type = IMAGE_DATA_TYPE_NANOVDB_FLOAT3; + } +# else if (metadata.channels == 1) { metadata.type = IMAGE_DATA_TYPE_FLOAT; } else { metadata.type = IMAGE_DATA_TYPE_FLOAT4; } +# endif /* Set transform from object space to voxel index. */ openvdb::math::Mat4f grid_matrix = grid->transform().baseMap()->getAffineMap()->getMat4(); @@ -113,7 +159,10 @@ bool VDBImageLoader::load_metadata(ImageMetaData &metadata) bool VDBImageLoader::load_pixels(const ImageMetaData &, void *pixels, const size_t, const bool) { -#ifdef WITH_OPENVDB +#if defined(WITH_NANOVDB) + memcpy(pixels, nanogrid.data(), nanogrid.size()); + return true; +#elif defined(WITH_OPENVDB) if (grid->isType<openvdb::FloatGrid>()) { openvdb::tools::Dense<float, openvdb::tools::LayoutXYZ> dense(bbox, (float *)pixels); openvdb::tools::copyToDense(*openvdb::gridConstPtrCast<openvdb::FloatGrid>(grid), dense); @@ -183,6 +232,9 @@ void VDBImageLoader::cleanup() /* Free OpenVDB grid memory as soon as we can. */ grid.reset(); #endif +#ifdef WITH_NANOVDB + nanogrid.reset(); +#endif } bool VDBImageLoader::is_vdb_loader() const |