Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/curve_to_mesh_convert.cc
| Show All 21 Lines | |||||
| const int poly_offset, | const int poly_offset, | ||||
| const int loop_offset, | const int loop_offset, | ||||
| const int main_point_num, | const int main_point_num, | ||||
| const int profile_point_num, | const int profile_point_num, | ||||
| const bool main_cyclic, | const bool main_cyclic, | ||||
| const bool profile_cyclic, | const bool profile_cyclic, | ||||
| const bool fill_caps, | const bool fill_caps, | ||||
| MutableSpan<MEdge> edges, | MutableSpan<MEdge> edges, | ||||
| MutableSpan<MLoop> loops, | MutableSpan<int> corner_verts, | ||||
| MutableSpan<int> corner_edges, | |||||
| MutableSpan<MPoly> polys) | MutableSpan<MPoly> polys) | ||||
| { | { | ||||
| const int main_segment_num = curves::segments_num(main_point_num, main_cyclic); | const int main_segment_num = curves::segments_num(main_point_num, main_cyclic); | ||||
| const int profile_segment_num = curves::segments_num(profile_point_num, profile_cyclic); | const int profile_segment_num = curves::segments_num(profile_point_num, profile_cyclic); | ||||
| if (profile_point_num == 1) { | if (profile_point_num == 1) { | ||||
| for (const int i : IndexRange(main_point_num - 1)) { | for (const int i : IndexRange(main_point_num - 1)) { | ||||
| MEdge &edge = edges[edge_offset + i]; | MEdge &edge = edges[edge_offset + i]; | ||||
| ▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
| const int main_edge_start = main_edges_start + main_segment_num * i_profile; | const int main_edge_start = main_edges_start + main_segment_num * i_profile; | ||||
| const int next_main_edge_start = main_edges_start + main_segment_num * i_next_profile; | const int next_main_edge_start = main_edges_start + main_segment_num * i_next_profile; | ||||
| MPoly &poly = polys[ring_poly_offset + i_profile]; | MPoly &poly = polys[ring_poly_offset + i_profile]; | ||||
| poly.loopstart = ring_segment_loop_offset; | poly.loopstart = ring_segment_loop_offset; | ||||
| poly.totloop = 4; | poly.totloop = 4; | ||||
| poly.flag = ME_SMOOTH; | poly.flag = ME_SMOOTH; | ||||
| MLoop &loop_a = loops[ring_segment_loop_offset]; | corner_verts[ring_segment_loop_offset] = ring_vert_offset + i_profile; | ||||
| loop_a.v = ring_vert_offset + i_profile; | corner_edges[ring_segment_loop_offset] = ring_edge_start + i_profile; | ||||
| loop_a.e = ring_edge_start + i_profile; | |||||
| MLoop &loop_b = loops[ring_segment_loop_offset + 1]; | corner_verts[ring_segment_loop_offset + 1] = ring_vert_offset + i_next_profile; | ||||
| loop_b.v = ring_vert_offset + i_next_profile; | corner_edges[ring_segment_loop_offset + 1] = next_main_edge_start + i_ring; | ||||
| loop_b.e = next_main_edge_start + i_ring; | |||||
| MLoop &loop_c = loops[ring_segment_loop_offset + 2]; | corner_verts[ring_segment_loop_offset + 2] = next_ring_vert_offset + i_next_profile; | ||||
| loop_c.v = next_ring_vert_offset + i_next_profile; | corner_edges[ring_segment_loop_offset + 2] = next_ring_edge_offset + i_profile; | ||||
| loop_c.e = next_ring_edge_offset + i_profile; | |||||
| MLoop &loop_d = loops[ring_segment_loop_offset + 3]; | corner_verts[ring_segment_loop_offset + 3] = next_ring_vert_offset + i_profile; | ||||
| loop_d.v = next_ring_vert_offset + i_profile; | corner_edges[ring_segment_loop_offset + 3] = main_edge_start + i_ring; | ||||
| loop_d.e = main_edge_start + i_ring; | |||||
| } | } | ||||
| } | } | ||||
| const bool has_caps = fill_caps && !main_cyclic && profile_cyclic; | const bool has_caps = fill_caps && !main_cyclic && profile_cyclic; | ||||
| if (has_caps) { | if (has_caps) { | ||||
| const int poly_num = main_segment_num * profile_segment_num; | const int poly_num = main_segment_num * profile_segment_num; | ||||
| const int cap_loop_offset = loop_offset + poly_num * 4; | const int cap_loop_offset = loop_offset + poly_num * 4; | ||||
| const int cap_poly_offset = poly_offset + poly_num; | const int cap_poly_offset = poly_offset + poly_num; | ||||
| MPoly &poly_start = polys[cap_poly_offset]; | MPoly &poly_start = polys[cap_poly_offset]; | ||||
| poly_start.loopstart = cap_loop_offset; | poly_start.loopstart = cap_loop_offset; | ||||
| poly_start.totloop = profile_segment_num; | poly_start.totloop = profile_segment_num; | ||||
| MPoly &poly_end = polys[cap_poly_offset + 1]; | MPoly &poly_end = polys[cap_poly_offset + 1]; | ||||
| poly_end.loopstart = cap_loop_offset + profile_segment_num; | poly_end.loopstart = cap_loop_offset + profile_segment_num; | ||||
| poly_end.totloop = profile_segment_num; | poly_end.totloop = profile_segment_num; | ||||
| const int last_ring_index = main_point_num - 1; | const int last_ring_index = main_point_num - 1; | ||||
| const int last_ring_vert_offset = vert_offset + profile_point_num * last_ring_index; | const int last_ring_vert_offset = vert_offset + profile_point_num * last_ring_index; | ||||
| const int last_ring_edge_offset = profile_edges_start + profile_segment_num * last_ring_index; | const int last_ring_edge_offset = profile_edges_start + profile_segment_num * last_ring_index; | ||||
| for (const int i : IndexRange(profile_segment_num)) { | for (const int i : IndexRange(profile_segment_num)) { | ||||
| const int i_inv = profile_segment_num - i - 1; | const int i_inv = profile_segment_num - i - 1; | ||||
| MLoop &loop_start = loops[cap_loop_offset + i]; | corner_verts[cap_loop_offset + i] = vert_offset + i_inv; | ||||
| loop_start.v = vert_offset + i_inv; | corner_edges[cap_loop_offset + i] = profile_edges_start + ((i == (profile_segment_num - 1)) ? | ||||
| loop_start.e = profile_edges_start + | (profile_segment_num - 1) : | ||||
| ((i == (profile_segment_num - 1)) ? (profile_segment_num - 1) : (i_inv - 1)); | (i_inv - 1)); | ||||
| MLoop &loop_end = loops[cap_loop_offset + profile_segment_num + i]; | corner_verts[cap_loop_offset + profile_segment_num + i] = last_ring_vert_offset + i; | ||||
| loop_end.v = last_ring_vert_offset + i; | corner_edges[cap_loop_offset + profile_segment_num + i] = last_ring_edge_offset + i; | ||||
| loop_end.e = last_ring_edge_offset + i; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /** Set the sharp status for edges that correspond to control points with vector handles. */ | /** Set the sharp status for edges that correspond to control points with vector handles. */ | ||||
| static void mark_bezier_vector_edges_sharp(const int profile_point_num, | static void mark_bezier_vector_edges_sharp(const int profile_point_num, | ||||
| const int main_segment_num, | const int main_segment_num, | ||||
| const Span<int> control_point_offsets, | const Span<int> control_point_offsets, | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| Mesh *mesh = BKE_mesh_new_nomain( | Mesh *mesh = BKE_mesh_new_nomain( | ||||
| offsets.vert.last(), offsets.edge.last(), 0, offsets.loop.last(), offsets.poly.last()); | offsets.vert.last(), offsets.edge.last(), 0, offsets.loop.last(), offsets.poly.last()); | ||||
| mesh->flag |= ME_AUTOSMOOTH; | mesh->flag |= ME_AUTOSMOOTH; | ||||
| mesh->smoothresh = DEG2RADF(180.0f); | mesh->smoothresh = DEG2RADF(180.0f); | ||||
| MutableSpan<float3> positions = mesh->vert_positions_for_write(); | MutableSpan<float3> positions = mesh->vert_positions_for_write(); | ||||
| MutableSpan<MEdge> edges = mesh->edges_for_write(); | MutableSpan<MEdge> edges = mesh->edges_for_write(); | ||||
| MutableSpan<MPoly> polys = mesh->polys_for_write(); | MutableSpan<MPoly> polys = mesh->polys_for_write(); | ||||
| MutableSpan<MLoop> loops = mesh->loops_for_write(); | MutableSpan<int> corner_verts = mesh->corner_verts_for_write(); | ||||
| MutableSpan<int> corner_edges = mesh->corner_edges_for_write(); | |||||
| foreach_curve_combination(curves_info, offsets, [&](const CombinationInfo &info) { | foreach_curve_combination(curves_info, offsets, [&](const CombinationInfo &info) { | ||||
| fill_mesh_topology(info.vert_range.start(), | fill_mesh_topology(info.vert_range.start(), | ||||
| info.edge_range.start(), | info.edge_range.start(), | ||||
| info.poly_range.start(), | info.poly_range.start(), | ||||
| info.loop_range.start(), | info.loop_range.start(), | ||||
| info.main_points.size(), | info.main_points.size(), | ||||
| info.profile_points.size(), | info.profile_points.size(), | ||||
| info.main_cyclic, | info.main_cyclic, | ||||
| info.profile_cyclic, | info.profile_cyclic, | ||||
| fill_caps, | fill_caps, | ||||
| edges, | edges, | ||||
| loops, | corner_verts, | ||||
| corner_edges, | |||||
| polys); | polys); | ||||
| }); | }); | ||||
| const Span<float3> main_positions = main.evaluated_positions(); | const Span<float3> main_positions = main.evaluated_positions(); | ||||
| const Span<float3> tangents = main.evaluated_tangents(); | const Span<float3> tangents = main.evaluated_tangents(); | ||||
| const Span<float3> normals = main.evaluated_normals(); | const Span<float3> normals = main.evaluated_normals(); | ||||
| const Span<float3> profile_positions = profile.evaluated_positions(); | const Span<float3> profile_positions = profile.evaluated_positions(); | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||