Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
| Show All 15 Lines | |||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "PIL_time.h" | #include "PIL_time.h" | ||||
| #include "BKE_camera.h" | #include "BKE_camera.h" | ||||
| #include "BKE_collection.h" | #include "BKE_collection.h" | ||||
| #include "BKE_customdata.h" | #include "BKE_customdata.h" | ||||
| #include "BKE_deform.h" | #include "BKE_deform.h" | ||||
| #include "BKE_duplilist.h" | |||||
| #include "BKE_editmesh.h" | #include "BKE_editmesh.h" | ||||
| #include "BKE_global.h" | #include "BKE_global.h" | ||||
| #include "BKE_gpencil.h" | #include "BKE_gpencil.h" | ||||
| #include "BKE_gpencil_geom.h" | #include "BKE_gpencil_geom.h" | ||||
| #include "BKE_gpencil_modifier.h" | #include "BKE_gpencil_modifier.h" | ||||
| #include "BKE_lib_id.h" | #include "BKE_lib_id.h" | ||||
| #include "BKE_material.h" | #include "BKE_material.h" | ||||
| #include "BKE_mesh.h" | #include "BKE_mesh.h" | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| for (int i = 0; i < 6; i++) { | for (int i = 0; i < 6; i++) { | ||||
| if (cond[i]) { | if (cond[i]) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| static void lineart_object_load_single_instance(LineartRenderBuffer *rb, | |||||
| Depsgraph *depsgraph, | |||||
| Scene *scene, | |||||
| Object *ob, | |||||
| Object *ref_ob, | |||||
| float use_mat[4][4], | |||||
| bool is_render, | |||||
| LineartObjectLoadTaskInfo *olti, | |||||
| int thread_count) | |||||
| { | |||||
| LineartObjectInfo *obi = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartObjectInfo)); | |||||
| obi->usage = lineart_usage_check(scene->master_collection, ob, is_render); | |||||
| obi->override_intersection_mask = lineart_intersection_mask_check(scene->master_collection, ob); | |||||
| Mesh *use_mesh; | |||||
| if (obi->usage == OBJECT_LRT_EXCLUDE) { | |||||
| return; | |||||
| } | |||||
| /* Prepare the matrix used for transforming this specific object (instance). This has to be | |||||
| * done before mesh boundbox check because the function needs that. */ | |||||
| mul_m4db_m4db_m4fl_uniq(obi->model_view_proj, rb->view_projection, use_mat); | |||||
| mul_m4db_m4db_m4fl_uniq(obi->model_view, rb->view, use_mat); | |||||
| if (!ELEM(ob->type, OB_MESH, OB_MBALL, OB_CURVES_LEGACY, OB_SURF, OB_FONT)) { | |||||
| return; | |||||
| } | |||||
| if (ob->type == OB_MESH) { | |||||
| use_mesh = BKE_object_get_evaluated_mesh(ob); | |||||
| } | |||||
| else { | |||||
| use_mesh = BKE_mesh_new_from_object(depsgraph, ob, true, true); | |||||
| } | |||||
| /* In case we still can not get any mesh geometry data from the object */ | |||||
| if (!use_mesh) { | |||||
| return; | |||||
| } | |||||
| if (!lineart_geometry_check_visible(obi->model_view_proj, rb->shift_x, rb->shift_y, use_mesh)) { | |||||
| return; | |||||
| } | |||||
| if (ob->type != OB_MESH) { | |||||
| obi->free_use_mesh = true; | |||||
| } | |||||
| /* Make normal matrix. */ | |||||
| float imat[4][4]; | |||||
| invert_m4_m4(imat, use_mat); | |||||
| transpose_m4(imat); | |||||
| copy_m4d_m4(obi->normal, imat); | |||||
| obi->original_me = use_mesh; | |||||
| obi->original_ob = (ref_ob->id.orig_id ? (Object *)ref_ob->id.orig_id : (Object *)ref_ob); | |||||
| lineart_geometry_load_assign_thread(olti, obi, thread_count, use_mesh->totpoly); | |||||
| } | |||||
| static void lineart_main_load_geometries( | static void lineart_main_load_geometries( | ||||
| Depsgraph *depsgraph, | Depsgraph *depsgraph, | ||||
| Scene *scene, | Scene *scene, | ||||
| Object *camera /* Still use camera arg for convenience. */, | Object *camera /* Still use camera arg for convenience. */, | ||||
| LineartRenderBuffer *rb, | LineartRenderBuffer *rb, | ||||
| bool allow_duplicates) | bool allow_duplicates) | ||||
| { | { | ||||
| double proj[4][4], view[4][4], result[4][4]; | double proj[4][4], view[4][4], result[4][4]; | ||||
| Show All 32 Lines | |||||
| copy_m4_m4_db(rb->view_projection, proj); | copy_m4_m4_db(rb->view_projection, proj); | ||||
| unit_m4_db(view); | unit_m4_db(view); | ||||
| copy_m4_m4_db(rb->view, view); | copy_m4_m4_db(rb->view, view); | ||||
| BLI_listbase_clear(&rb->triangle_buffer_pointers); | BLI_listbase_clear(&rb->triangle_buffer_pointers); | ||||
| BLI_listbase_clear(&rb->vertex_buffer_pointers); | BLI_listbase_clear(&rb->vertex_buffer_pointers); | ||||
| int flags = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET | | |||||
| DEG_ITER_OBJECT_FLAG_VISIBLE; | |||||
| /* Instance duplicated & particles. */ | |||||
| if (allow_duplicates) { | |||||
| flags |= DEG_ITER_OBJECT_FLAG_DUPLI; | |||||
| } | |||||
| int thread_count = rb->thread_count; | int thread_count = rb->thread_count; | ||||
| /* This memory is in render buffer memory pool. so we don't need to free those after loading. | /* This memory is in render buffer memory pool. so we don't need to free those after loading. | ||||
| */ | */ | ||||
| LineartObjectLoadTaskInfo *olti = lineart_mem_acquire( | LineartObjectLoadTaskInfo *olti = lineart_mem_acquire( | ||||
| &rb->render_data_pool, sizeof(LineartObjectLoadTaskInfo) * thread_count); | &rb->render_data_pool, sizeof(LineartObjectLoadTaskInfo) * thread_count); | ||||
| bool is_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER; | eEvaluationMode eval_mode = DEG_get_mode(depsgraph); | ||||
| bool is_render = eval_mode == DAG_EVAL_RENDER; | |||||
| DEG_OBJECT_ITER_BEGIN (depsgraph, ob, flags) { | |||||
| LineartObjectInfo *obi = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartObjectInfo)); | |||||
| obi->usage = lineart_usage_check(scene->master_collection, ob, is_render); | |||||
| obi->override_intersection_mask = lineart_intersection_mask_check(scene->master_collection, | |||||
| ob); | |||||
| Mesh *use_mesh; | |||||
| if (obi->usage == OBJECT_LRT_EXCLUDE) { | |||||
| continue; | |||||
| } | |||||
| Object *use_ob = DEG_get_evaluated_object(depsgraph, ob); | FOREACH_SCENE_OBJECT_BEGIN (scene, ob) { | ||||
| /* Prepare the matrix used for transforming this specific object (instance). This has to be | Object *eval_ob = DEG_get_evaluated_object(depsgraph, ob); | ||||
| * done before mesh boundbox check because the function needs that. */ | |||||
| mul_m4db_m4db_m4fl_uniq(obi->model_view_proj, rb->view_projection, ob->obmat); | |||||
| mul_m4db_m4db_m4fl_uniq(obi->model_view, rb->view, ob->obmat); | |||||
| if (!ELEM(use_ob->type, OB_MESH, OB_MBALL, OB_CURVES_LEGACY, OB_SURF, OB_FONT)) { | if (!eval_ob) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (use_ob->type == OB_MESH) { | if (BKE_object_visibility(eval_ob, eval_mode) & OB_VISIBLE_SELF) { | ||||
| use_mesh = BKE_object_get_evaluated_mesh(use_ob); | lineart_object_load_single_instance( | ||||
| } | rb, depsgraph, scene, eval_ob, eval_ob, eval_ob->obmat, is_render, olti, thread_count); | ||||
| else { | |||||
| /* If DEG_ITER_OBJECT_FLAG_DUPLI is set, some curve objects may also have an evaluated mesh | |||||
| * object in the list. To avoid adding duplicate geometry, ignore evaluated curve objects | |||||
| * in those cases. */ | |||||
| if (allow_duplicates && BKE_object_get_evaluated_mesh(ob) != NULL) { | |||||
| continue; | |||||
| } | |||||
| use_mesh = BKE_mesh_new_from_object(depsgraph, use_ob, true, true); | |||||
| } | } | ||||
| if (allow_duplicates) { | |||||
| /* In case we still can not get any mesh geometry data from the object */ | ListBase *dupli = object_duplilist(depsgraph, scene, eval_ob); | ||||
| if (!use_mesh) { | LISTBASE_FOREACH (DupliObject *, dob, dupli) { | ||||
| continue; | if (BKE_object_visibility(eval_ob, eval_mode) & | ||||
| } | (OB_VISIBLE_PARTICLES | OB_VISIBLE_INSTANCES)) { | ||||
| Object *ob_ref = (dob->type & OB_DUPLIPARTS) ? eval_ob : dob->ob; | |||||
| if (!lineart_geometry_check_visible( | lineart_object_load_single_instance( | ||||
| obi->model_view_proj, rb->shift_x, rb->shift_y, use_mesh)) { | rb, depsgraph, scene, dob->ob, ob_ref, dob->mat, is_render, olti, thread_count); | ||||
| if (ob->type != OB_MESH) { | } | ||||
| BKE_id_free(NULL, use_mesh); | |||||
| } | |||||
| if (G.debug_value == 4000) { | |||||
| bound_box_discard_count++; | |||||
| } | } | ||||
| continue; | free_object_duplilist(dupli); | ||||
| } | |||||
| if (ob->type != OB_MESH) { | |||||
| obi->free_use_mesh = true; | |||||
| } | } | ||||
| /* Make normal matrix. */ | |||||
| float imat[4][4]; | |||||
| invert_m4_m4(imat, ob->obmat); | |||||
| transpose_m4(imat); | |||||
| copy_m4d_m4(obi->normal, imat); | |||||
| obi->original_me = use_mesh; | |||||
| obi->original_ob = (ob->id.orig_id ? (Object *)ob->id.orig_id : (Object *)ob); | |||||
| lineart_geometry_load_assign_thread(olti, obi, thread_count, use_mesh->totpoly); | |||||
| } | } | ||||
| DEG_OBJECT_ITER_END; | FOREACH_SCENE_OBJECT_END; | ||||
| TaskPool *tp = BLI_task_pool_create(NULL, TASK_PRIORITY_HIGH); | TaskPool *tp = BLI_task_pool_create(NULL, TASK_PRIORITY_HIGH); | ||||
| if (G.debug_value == 4000) { | if (G.debug_value == 4000) { | ||||
| printf("thread count: %d\n", thread_count); | printf("thread count: %d\n", thread_count); | ||||
| } | } | ||||
| for (int i = 0; i < thread_count; i++) { | for (int i = 0; i < thread_count; i++) { | ||||
| olti[i].rb = rb; | olti[i].rb = rb; | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||