Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/sculpt_paint/sculpt.c
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
| Show First 20 Lines • Show All 9,087 Lines • ▼ Show 20 Lines | void sculpt_geometry_preview_lines_update(bContext *C, SculptSession *ss, float radius) | ||||
| } | } | ||||
| float brush_co[3]; | float brush_co[3]; | ||||
| copy_v3_v3(brush_co, sculpt_vertex_co_get(ss, sculpt_active_vertex_get(ss))); | copy_v3_v3(brush_co, sculpt_vertex_co_get(ss, sculpt_active_vertex_get(ss))); | ||||
| char *visited_vertices = MEM_callocN(sculpt_vertex_count_get(ss) * sizeof(char), | char *visited_vertices = MEM_callocN(sculpt_vertex_count_get(ss) * sizeof(char), | ||||
| "visited vertices"); | "visited vertices"); | ||||
| int max_preview_vertices = sculpt_vertex_count_get(ss) * 4; | |||||
jbakker: If I understand the code correctly we can only support on average 2 lines per vertex, Some… | |||||
Done Inline ActionsAdd a note so it is clear for other developers where this originates from we should make it a const int. jbakker: Add a note so it is clear for other developers where this originates from
we should make it a… | |||||
| if (ss->preview_vert_index_list == NULL) { | if (ss->preview_vert_index_list == NULL) { | ||||
| ss->preview_vert_index_list = MEM_callocN(4 * sizeof(int) * sculpt_vertex_count_get(ss), | ss->preview_vert_index_list = MEM_callocN(max_preview_vertices * sizeof(int), "preview lines"); | ||||
| "preview lines"); | |||||
| } | } | ||||
| BLI_Stack *not_visited_vertices = BLI_stack_new(sizeof(VertexTopologyIterator), | BLI_Stack *not_visited_vertices = BLI_stack_new(sizeof(VertexTopologyIterator), | ||||
| "Not visited vertices stack"); | "Not visited vertices stack"); | ||||
| VertexTopologyIterator mevit; | VertexTopologyIterator mevit; | ||||
| mevit.v = sculpt_active_vertex_get(ss); | mevit.v = sculpt_active_vertex_get(ss); | ||||
| BLI_stack_push(not_visited_vertices, &mevit); | BLI_stack_push(not_visited_vertices, &mevit); | ||||
| while (!BLI_stack_is_empty(not_visited_vertices)) { | while (!BLI_stack_is_empty(not_visited_vertices)) { | ||||
| VertexTopologyIterator c_mevit; | VertexTopologyIterator c_mevit; | ||||
| BLI_stack_pop(not_visited_vertices, &c_mevit); | BLI_stack_pop(not_visited_vertices, &c_mevit); | ||||
| SculptVertexNeighborIter ni; | SculptVertexNeighborIter ni; | ||||
| sculpt_vertex_neighbors_iter_begin(ss, c_mevit.v, ni) | sculpt_vertex_neighbors_iter_begin(ss, c_mevit.v, ni) | ||||
| { | { | ||||
| if (totpoints + (ni.size * 2) < max_preview_vertices) { | |||||
| VertexTopologyIterator new_entry; | VertexTopologyIterator new_entry; | ||||
| new_entry.v = ni.index; | new_entry.v = ni.index; | ||||
| new_entry.it = c_mevit.it + 1; | new_entry.it = c_mevit.it + 1; | ||||
| ss->preview_vert_index_list[totpoints] = c_mevit.v; | ss->preview_vert_index_list[totpoints] = c_mevit.v; | ||||
| totpoints++; | totpoints++; | ||||
| ss->preview_vert_index_list[totpoints] = new_entry.v; | ss->preview_vert_index_list[totpoints] = new_entry.v; | ||||
| totpoints++; | totpoints++; | ||||
| if (visited_vertices[(int)ni.index] == 0) { | if (visited_vertices[(int)ni.index] == 0) { | ||||
| visited_vertices[(int)ni.index] = 1; | visited_vertices[(int)ni.index] = 1; | ||||
| if (len_squared_v3v3(brush_co, sculpt_vertex_co_get(ss, new_entry.v)) < radius * radius) { | if (len_squared_v3v3(brush_co, sculpt_vertex_co_get(ss, new_entry.v)) < | ||||
| radius * radius) { | |||||
| BLI_stack_push(not_visited_vertices, &new_entry); | BLI_stack_push(not_visited_vertices, &new_entry); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| sculpt_vertex_neighbors_iter_end(ni); | sculpt_vertex_neighbors_iter_end(ni); | ||||
| } | } | ||||
| BLI_stack_free(not_visited_vertices); | BLI_stack_free(not_visited_vertices); | ||||
| MEM_freeN(visited_vertices); | MEM_freeN(visited_vertices); | ||||
| ss->preview_vert_index_count = totpoints; | ss->preview_vert_index_count = totpoints; | ||||
| ▲ Show 20 Lines • Show All 373 Lines • Show Last 20 Lines | |||||
If I understand the code correctly we can only support on average 2 lines per vertex, Some might have less, other have more.
When assuming a mesh is triangulated the realistic average per vertex is 6 connected lines. So in the worst case we now only draw 2/3 of all the edges.
As an edge is only drawn once sculpt_vertex_count_get(ss) * 3 * 2 would be more realistic.