Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/volume_to_mesh.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| void fill_mesh_from_openvdb_data(const Span<openvdb::Vec3s> vdb_verts, | void fill_mesh_from_openvdb_data(const Span<openvdb::Vec3s> vdb_verts, | ||||
| const Span<openvdb::Vec3I> vdb_tris, | const Span<openvdb::Vec3I> vdb_tris, | ||||
| const Span<openvdb::Vec4I> vdb_quads, | const Span<openvdb::Vec4I> vdb_quads, | ||||
| const int vert_offset, | const int vert_offset, | ||||
| const int poly_offset, | const int poly_offset, | ||||
| const int loop_offset, | const int loop_offset, | ||||
| MutableSpan<float3> vert_positions, | MutableSpan<float3> vert_positions, | ||||
| MutableSpan<MPoly> polys, | MutableSpan<MPoly> polys, | ||||
| MutableSpan<MLoop> loops) | MutableSpan<int> corner_verts) | ||||
| { | { | ||||
| /* Write vertices. */ | /* Write vertices. */ | ||||
| vert_positions.slice(vert_offset, vdb_verts.size()).copy_from(vdb_verts.cast<float3>()); | vert_positions.slice(vert_offset, vdb_verts.size()).copy_from(vdb_verts.cast<float3>()); | ||||
| /* Write triangles. */ | /* Write triangles. */ | ||||
| for (const int i : vdb_tris.index_range()) { | for (const int i : vdb_tris.index_range()) { | ||||
| polys[poly_offset + i].loopstart = loop_offset + 3 * i; | polys[poly_offset + i].loopstart = loop_offset + 3 * i; | ||||
| polys[poly_offset + i].totloop = 3; | polys[poly_offset + i].totloop = 3; | ||||
| for (int j = 0; j < 3; j++) { | for (int j = 0; j < 3; j++) { | ||||
| /* Reverse vertex order to get correct normals. */ | /* Reverse vertex order to get correct normals. */ | ||||
| loops[loop_offset + 3 * i + j].v = vert_offset + vdb_tris[i][2 - j]; | corner_verts[loop_offset + 3 * i + j] = vert_offset + vdb_tris[i][2 - j]; | ||||
| } | } | ||||
| } | } | ||||
| /* Write quads. */ | /* Write quads. */ | ||||
| const int quad_offset = poly_offset + vdb_tris.size(); | const int quad_offset = poly_offset + vdb_tris.size(); | ||||
| const int quad_loop_offset = loop_offset + vdb_tris.size() * 3; | const int quad_loop_offset = loop_offset + vdb_tris.size() * 3; | ||||
| for (const int i : vdb_quads.index_range()) { | for (const int i : vdb_quads.index_range()) { | ||||
| polys[quad_offset + i].loopstart = quad_loop_offset + 4 * i; | polys[quad_offset + i].loopstart = quad_loop_offset + 4 * i; | ||||
| polys[quad_offset + i].totloop = 4; | polys[quad_offset + i].totloop = 4; | ||||
| for (int j = 0; j < 4; j++) { | for (int j = 0; j < 4; j++) { | ||||
| /* Reverse vertex order to get correct normals. */ | /* Reverse vertex order to get correct normals. */ | ||||
| loops[quad_loop_offset + 4 * i + j].v = vert_offset + vdb_quads[i][3 - j]; | corner_verts[quad_loop_offset + 4 * i + j] = vert_offset + vdb_quads[i][3 - j]; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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) | ||||
| Show All 22 Lines | |||||
| fill_mesh_from_openvdb_data(mesh_data.verts, | fill_mesh_from_openvdb_data(mesh_data.verts, | ||||
| mesh_data.tris, | mesh_data.tris, | ||||
| mesh_data.quads, | mesh_data.quads, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| mesh->vert_positions_for_write(), | mesh->vert_positions_for_write(), | ||||
| mesh->polys_for_write(), | mesh->polys_for_write(), | ||||
| mesh->loops_for_write()); | mesh->corner_verts_for_write()); | ||||
| BKE_mesh_calc_edges(mesh, false, false); | BKE_mesh_calc_edges(mesh, false, false); | ||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| #endif /* WITH_OPENVDB */ | #endif /* WITH_OPENVDB */ | ||||
| } // namespace blender::bke | } // namespace blender::bke | ||||
| Context not available. | |||||