Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/volume_to_mesh.cc
| Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | static Mesh *new_mesh_from_openvdb_data(Span<openvdb::Vec3s> verts, | ||||
| Span<openvdb::Vec4I> quads) | Span<openvdb::Vec4I> quads) | ||||
| { | { | ||||
| const int tot_loops = 3 * tris.size() + 4 * quads.size(); | const int tot_loops = 3 * tris.size() + 4 * quads.size(); | ||||
| const int tot_polys = tris.size() + quads.size(); | const int tot_polys = tris.size() + quads.size(); | ||||
| Mesh *mesh = BKE_mesh_new_nomain(verts.size(), 0, 0, tot_loops, tot_polys); | Mesh *mesh = BKE_mesh_new_nomain(verts.size(), 0, 0, tot_loops, tot_polys); | ||||
| /* Write vertices. */ | /* Write vertices. */ | ||||
| for (const int i : verts.index_range()) { | for (const int i : blender::iter_indices(verts)) { | ||||
| const blender::float3 co = blender::float3(verts[i].asV()); | const blender::float3 co = blender::float3(verts[i].asV()); | ||||
| copy_v3_v3(mesh->mvert[i].co, co); | copy_v3_v3(mesh->mvert[i].co, co); | ||||
| } | } | ||||
| /* Write triangles. */ | /* Write triangles. */ | ||||
| for (const int i : tris.index_range()) { | for (const int i : blender::iter_indices(tris)) { | ||||
| mesh->mpoly[i].loopstart = 3 * i; | mesh->mpoly[i].loopstart = 3 * i; | ||||
| mesh->mpoly[i].totloop = 3; | mesh->mpoly[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. */ | ||||
| mesh->mloop[3 * i + j].v = tris[i][2 - j]; | mesh->mloop[3 * i + j].v = tris[i][2 - j]; | ||||
| } | } | ||||
| } | } | ||||
| /* Write quads. */ | /* Write quads. */ | ||||
| const int poly_offset = tris.size(); | const int poly_offset = tris.size(); | ||||
| const int loop_offset = tris.size() * 3; | const int loop_offset = tris.size() * 3; | ||||
| for (const int i : quads.index_range()) { | for (const int i : blender::iter_indices(quads)) { | ||||
| mesh->mpoly[poly_offset + i].loopstart = loop_offset + 4 * i; | mesh->mpoly[poly_offset + i].loopstart = loop_offset + 4 * i; | ||||
| mesh->mpoly[poly_offset + i].totloop = 4; | mesh->mpoly[poly_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. */ | ||||
| mesh->mloop[loop_offset + 4 * i + j].v = quads[i][3 - j]; | mesh->mloop[loop_offset + 4 * i + j].v = quads[i][3 - j]; | ||||
| } | } | ||||
| } | } | ||||
| Show All 23 Lines | |||||