Commit: fe2df4c771af415ea049497590b7d1a9699abccf Author: YimingWu Date: Mon Mar 28 13:34:17 2022 +0800 Branches: lineart-object-load https://developer.blender.org/rBfe2df4c771af415ea049497590b7d1a9699abccf
LineArt: Object loading wip =================================================================== M source/blender/blenlib/intern/BLI_mempool.c M source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h M source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c =================================================================== diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index f70b5ddd766..bc97b71c78e 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -355,32 +355,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr) { BLI_freenode *newhead = addr; -#ifndef NDEBUG - { - BLI_mempool_chunk *chunk; - bool found = false; - for (chunk = pool->chunks; chunk; chunk = chunk->next) { - if (ARRAY_HAS_ITEM((char *)addr, (char *)CHUNK_DATA(chunk), pool->csize)) { - found = true; - break; - } - } - if (!found) { - BLI_assert_msg(0, "Attempt to free data which is not in pool.\n"); - } - } - - /* Enable for debugging. */ - if (UNLIKELY(mempool_debug_memset)) { - memset(addr, 255, pool->esize); - } -#endif - if (pool->flag & BLI_MEMPOOL_ALLOW_ITER) { -#ifndef NDEBUG - /* This will detect double free's. */ - BLI_assert(newhead->freeword != FREEWORD); -#endif newhead->freeword = FREEWORD; } diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h index 5d952991cf7..a168873740a 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h +++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h @@ -14,6 +14,14 @@ #include <math.h> +typedef struct EdgeFacePair { + int v1; + int v2; + int f1; + int f2; + uint16_t eflag; +} EdgeFacePair; + typedef struct LineartStaticMemPoolNode { Link item; size_t size; @@ -396,7 +404,7 @@ typedef struct LineartObjectInfo { typedef struct LineartObjectLoadTaskInfo { struct LineartRenderBuffer *rb; - struct Depsgraph *dg; + int thread_id; /* LinkNode styled list */ LineartObjectInfo *pending; /* Used to spread the load across several threads. This can not overflow. */ diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c index 08737c19eef..981dd5105c4 100644 --- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c +++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c @@ -8,6 +8,7 @@ #include "MOD_gpencil_lineart.h" #include "MOD_lineart.h" +#include "BLI_edgehash.h" #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_math.h" @@ -28,6 +29,8 @@ #include "BKE_lib_id.h" #include "BKE_material.h" #include "BKE_mesh.h" +#include "BKE_mesh_mapping.h" +#include "BKE_mesh_runtime.h" #include "BKE_object.h" #include "BKE_pointcache.h" #include "BKE_scene.h" @@ -1439,6 +1442,39 @@ static void lineart_vert_transform( mul_v4_m4v3_db(vt->fbcoord, mvp_mat, co); } +typedef struct VertData { + MVert *mvert; + LineartVert *v_arr; + double (*model_view)[4]; + double (*model_view_proj)[4]; +} VertData; + +static void lineart_mvert_transform_task(void *__restrict userdata, + const int i, + const TaskParallelTLS *__restrict UNUSED(tls)) +{ + VertData *vert_task_data = (VertData *)userdata; + MVert *m_v = &vert_task_data->mvert[i]; + double co[4]; + LineartVert *v = &vert_task_data->v_arr[i]; + copy_v3db_v3fl(co, m_v->co); + mul_v3_m4v3_db(v->gloc, vert_task_data->model_view, co); + mul_v4_m4v3_db(v->fbcoord, vert_task_data->model_view_proj, co); + v->index = i; +} + +static int lineart_edge_type_duplication_count(char eflag) +{ + int count = 0; + /* See eLineartEdgeFlag for details. */ + for (int i = 0; i < 6; i++) { + if (eflag & (1 << i)) { + count++; + } + } + return count; +} + /** * Because we have a variable size for #LineartTriangle, we need an access helper. * See #LineartTriangleThread for more info. @@ -1452,6 +1488,161 @@ static LineartTriangle *lineart_triangle_from_index(LineartRenderBuffer *rb, return (LineartTriangle *)b; } +typedef struct EdgeFeatData { + LineartRenderBuffer *rb; + Mesh *me; + const MLoopTri *mlooptri; + EdgeFacePair *edge_pair_arr; + LineartTriangle *tri_array; + LineartVert *v_array; + float crease_threshold; + bool use_auto_smooth; +} EdgeFeatData; + +typedef struct EdgeFeatReduceData { + int feat_edges; +} EdgeFeatReduceData; + +static void feat_data_sum_reduce(const void *__restrict UNUSED(userdata), + void *__restrict chunk_join, + void *__restrict chunk) +{ + EdgeFeatReduceData *feat_chunk_join = (EdgeFeatReduceData *)chunk_join; + EdgeFeatReduceData *feat_chunk = (EdgeFeatReduceData *)chunk; + feat_chunk_join->feat_edges += feat_chunk->feat_edges; +} + +static void lineart_identify_mlooptri_feature_edges(void *__restrict userdata, + const int i, + const TaskParallelTLS *__restrict tls) +{ + EdgeFeatData *e_feat_data = (EdgeFeatData *)userdata; + EdgeFacePair *e_f_pair = &e_feat_data->edge_pair_arr[i]; + EdgeFeatReduceData *reduce_data = (EdgeFeatReduceData *)tls->userdata_chunk; + /* Mesh boundary */ + if (e_f_pair->f2 == -1) { + e_f_pair->eflag = LRT_EDGE_FLAG_CONTOUR; + reduce_data->feat_edges += 1; + return; + } + + LineartTriangle *tri1, *tri2; + LineartVert *vert; + LineartRenderBuffer *rb = e_feat_data->rb; + + /* The mesh should already be triangulated now, so we can assume each face is a triangle. */ + tri1 = lineart_triangle_from_index(rb, e_feat_data->tri_array, e_f_pair->f1); + tri2 = lineart_triangle_from_index(rb, e_feat_data->tri_array, e_f_pair->f2); + + vert = &e_feat_data->v_array[e_f_pair->v1]; + + double vv[3]; + double *view_vector = vv; + double dot_1 = 0, dot_2 = 0; + double result; + + if (rb->cam_is_persp) { + sub_v3_v3v3_db(view_vector, vert->gloc, rb->camera_pos); + } + else { + view_vector = rb->view_vector; + } + + dot_1 = dot_v3v3_db(view_vector, tri1->gn); + dot_2 = dot_v3v3_db(view_vector, tri2->gn); + uint16_t edge_flag_result = 0; + + if ((result = dot_1 * dot_2) <= 0 && (dot_1 + dot_2)) { + edge_flag_result |= LRT_EDGE_FLAG_CONTOUR; + } + + // if (rb->use_crease) { + // if (rb->sharp_as_crease && !BM_elem_flag_test(e, BM_ELEM_SMOOTH)) { + // edge_flag_result |= LRT_EDGE_FLAG_CREASE; + // } + // else { + // bool do_crease = true; + // if (!rb->force_crease && !use_auto_smooth && + // (BM_elem_flag_test(ll->f, BM_ELEM_SMOOTH) && BM_elem_flag_test(lr->f, + // BM_ELEM_SMOOTH))) { + // do_crease = false; + // } + // if (do_crease && (dot_v3v3_db(tri1->gn, tri2->gn) < crease_threshold)) { + // edge_flag_result |= LRT_EDGE_FLAG_CREASE; + // } + // } + // } + Mesh *me = e_feat_data->me; + const MLoopTri *mlooptri = e_feat_data->mlooptri; + + int mat1 = me->mpoly[mlooptri[e_f_pair->f1].poly].mat_nr; + int mat2 = me->mpoly[mlooptri[e_f_pair->f2].poly].mat_nr; + + if (rb->use_material && mat1 != mat2) { + edge_flag_result |= LRT_EDGE_FLAG_MATERIAL; + } + e_f_pair->eflag = edge_flag_result; + + if (edge_flag_result) { + /* Only allocate for feature edge (instead of all edges) to save memory. + * If allow duplicated edges, one edge gets added multiple times if it has multiple types. + */ + reduce_data->feat_edges += rb->allow_duplicated_types ? + lineart_edge_type_duplication_count(edge_flag_result) : + 1; + } +} + +static uint16_t lineart_identify_medge_feature_edges(LineartRenderBuffer *rb, + MEdge *medge, + bool use_freestyle_face, + bool use_freestyle_edge) +{ + if (medge->flag & ME_LOOSEEDGE) { + return LRT_EDGE_FLAG_LOOSE; + } + + FreestyleEdge *fel, *fer; + bool face_mark_filtered = false; + uint16_t edge_flag_result = 0; + + // if (use_freestyle_face && rb->filter_face_mark) { + // fel = CustomData_bmesh_get(&bm_if_freestyle->pdata, ll->f->head.data, CD_FREESTYLE_FACE); + // if (ll != lr && lr) { + // fer = CustomData_bmesh_get(&bm_if_freestyle->pdata, lr->f->head.data, CD_FREESTYLE_FACE); + // } + // else { + // /* Handles mesh boundary case */ + // fer = fel; + // } + // if (rb->filter_face_mark_boundaries ^ rb->filter_face_mark_invert) { + // if ((fel->flag & FREESTYLE_FACE_MARK) || (fer->flag & FREESTYLE_FACE_MARK)) { + // face_mark_filtered = true; + // } + // } + // else { + // if ((fel->flag & FREESTYLE_FACE_MARK) && (fer->flag & FREESTYLE_FACE_MARK) && (fer != + // fel)) { + // face_mark_filtered = true; + // } + // } + // if (rb->filter_face_mark_invert) { + // face_mark_filtered = !face_mark_filtered; + // } + // if (!face_mark_filtered) { + // return 0; + // } + // } + // if (use_freestyle_edge && rb->use_edge_marks) { + // FreestyleEdge *fe; + // fe = CustomData_bmesh_get(&bm_if_freestyle->edata, e->head.data, CD_FREESTYLE_EDGE); + // if (fe->flag & FREESTYLE_EDGE_MARK) { + // edge_flag_result |= LRT_EDGE_FLAG_EDGE_MARK; + // } + // } + return edge_flag_result; +} + static uint16_t lineart_identify_feature_line(LineartRenderBuffer *rb, BMEdge *e, LineartTriangle *rt_array, @@ -1702,16 +1893,490 @@ static void lineart_triangle_adjacent_assign(LineartTriangle *tri, } } -static int lineart_edge_type_duplication_count(char eflag) +typedef struct TriData { + LineartObjectInfo *ob_info; + const MLoopTri *mlooptri; + LineartVert *vert_arr; + LineartTriangle *tri_arr; + int lineart_triangle_size; + LineartTriangleAdjacent *tri_adj; +} TriData; + +typedef struct TriDataReduce { + EdgeHash *edge_hash; + EdgeFacePair *edge_pair_arr; + int arr_cur_len; + int arr_alloc_len; +} TriDataReduce; + +static void lineart_load_tri_task(void *__restrict userdata, + const int i, + const @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs