Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/volume_to_mesh.cc
| Show All 26 Lines | |||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| #include "BKE_volume.h" | #include "BKE_volume.h" | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| # include <openvdb/tools/GridTransformer.h> | # include <openvdb/tools/GridTransformer.h> | ||||
| # include <openvdb/tools/VolumeToMesh.h> | # include <openvdb/tools/VolumeToMesh.h> | ||||
| #endif | #endif | ||||
| #include "BLI_timeit.hh" | |||||
| #include "BKE_volume_to_mesh.hh" | #include "BKE_volume_to_mesh.hh" | ||||
| namespace blender::bke { | namespace blender::bke { | ||||
| #ifdef WITH_OPENVDB | #ifdef WITH_OPENVDB | ||||
| struct VolumeToMeshOp { | struct VolumeToMeshOp { | ||||
| const openvdb::GridBase &base_grid; | const openvdb::GridBase &base_grid; | ||||
| ▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | |||||
| * Convert an OpenVDB volume grid to corresponding mesh data: vertex positions and quad and | * Convert an OpenVDB volume grid to corresponding mesh data: vertex positions and quad and | ||||
| * triangle indices. | * triangle indices. | ||||
| */ | */ | ||||
| bke::OpenVDBMeshData volume_to_mesh_data(const openvdb::GridBase &grid, | bke::OpenVDBMeshData volume_to_mesh_data(const openvdb::GridBase &grid, | ||||
| const VolumeToMeshResolution &resolution, | const VolumeToMeshResolution &resolution, | ||||
| const float threshold, | const float threshold, | ||||
| const float adaptivity) | const float adaptivity) | ||||
| { | { | ||||
| SCOPED_TIMER(__func__); | |||||
| const VolumeGridType grid_type = BKE_volume_grid_type_openvdb(grid); | const VolumeGridType grid_type = BKE_volume_grid_type_openvdb(grid); | ||||
| VolumeToMeshOp to_mesh_op{grid, resolution, threshold, adaptivity}; | VolumeToMeshOp to_mesh_op{grid, resolution, threshold, adaptivity}; | ||||
| if (!BKE_volume_grid_type_operation(grid_type, to_mesh_op)) { | if (!BKE_volume_grid_type_operation(grid_type, to_mesh_op)) { | ||||
| return {}; | return {}; | ||||
| } | } | ||||
| return {std::move(to_mesh_op.verts), std::move(to_mesh_op.tris), std::move(to_mesh_op.quads)}; | return {std::move(to_mesh_op.verts), std::move(to_mesh_op.tris), std::move(to_mesh_op.quads)}; | ||||
| } | } | ||||
| Show All 15 Lines | fill_mesh_from_openvdb_data(mesh_data.verts, | ||||
| mesh_data.quads, | mesh_data.quads, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| {mesh->mvert, mesh->totvert}, | {mesh->mvert, mesh->totvert}, | ||||
| {mesh->mpoly, mesh->totpoly}, | {mesh->mpoly, mesh->totpoly}, | ||||
| {mesh->mloop, mesh->totloop}); | {mesh->mloop, mesh->totloop}); | ||||
| BKE_mesh_calc_edges(mesh, false, false); | { | ||||
| SCOPED_TIMER("calc edges"); | |||||
| // BKE_mesh_calc_edges(mesh, false, false); | |||||
| BKE_mesh_calc_edges_from_polys(mesh); | |||||
| } | |||||
| BKE_mesh_normals_tag_dirty(mesh); | BKE_mesh_normals_tag_dirty(mesh); | ||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| #endif /* WITH_OPENVDB */ | #endif /* WITH_OPENVDB */ | ||||
| } // namespace blender::bke | } // namespace blender::bke | ||||