21#define LRT_OTHER_VERT(e, vt) ((vt) == (e)->v1 ? (e)->v2 : ((vt) == (e)->v2 ? (e)->v1 : nullptr))
93 if (((eci->
pos[0] + threshold) >=
x) && ((eci->
pos[0] - threshold) <=
x) &&
94 ((eci->
pos[1] + threshold) >=
y) && ((eci->
pos[1] - threshold) <=
y))
156 return ec->
chain.first();
185 float use_fbcoord[4];
188#define VERT_COORD_TO_FLOAT(a) \
189 copy_v4fl_v4db(use_fbcoord, (a)->fbcoord); \
190 copy_v3fl_v3db(use_gpos, (a)->gloc);
192#define POS_TO_FLOAT(lpos, gpos) \
193 copy_v3fl_v3db(use_fbcoord, lpos); \
194 copy_v3fl_v3db(use_gpos, gpos);
225 N[0] +=
e->t1->gn[0];
226 N[1] +=
e->t1->gn[1];
227 N[2] +=
e->t1->gn[2];
230 N[0] +=
e->t2->gn[0];
231 N[1] +=
e->t2->gn[1];
232 N[2] +=
e->t2->gn[2];
234 if (
e->t1 ||
e->t2) {
242 es =
e->segments.first();
259 if (new_e->
t1 || new_e->
t2) {
262 N[0] += new_e->
t1->
gn[0];
263 N[1] += new_e->
t1->
gn[1];
264 N[2] += new_e->
t1->
gn[2];
267 N[0] += new_e->
t2->
gn[0];
268 N[1] += new_e->
t2->
gn[1];
269 N[2] += new_e->
t2->
gn[2];
274 if (new_vt == new_e->
v1) {
276 double gpos[3], lpos[3];
278 double global_at = lfb[3] * es.
ratio / (es.
ratio * lfb[3] + (1 - es.
ratio) * rfb[3]);
298 else if (new_vt == new_e->
v2) {
304 for (; es; es = es->
next) {
305 double gpos[3], lpos[3];
307 double global_at = lfb[3] * es->
ratio / (es->
ratio * lfb[3] + (1 - es->
ratio) * rfb[3]);
342 if (
e->t1 ||
e->t2) {
345 N[0] +=
e->t1->gn[0];
346 N[1] +=
e->t1->gn[1];
347 N[2] +=
e->t1->gn[2];
350 N[0] +=
e->t2->gn[0];
351 N[1] +=
e->t2->gn[1];
352 N[2] +=
e->t2->gn[2];
358 es =
e->segments.first();
362 for (es = es->
next; es; es = es->
next) {
363 double gpos[3], lpos[3];
364 double *lfb =
e->v1->fbcoord, *rfb =
e->v2->fbcoord;
365 double global_at = lfb[3] * es->
ratio / (es->
ratio * lfb[3] + (1 - es->
ratio) * rfb[3]);
368 use_fbcoord[3] =
interpf(
e->v2->fbcoord[3],
e->v1->fbcoord[3], global_at);
404 if (new_e->
t1 || new_e->
t2) {
407 N[0] += new_e->
t1->
gn[0];
408 N[1] += new_e->
t1->
gn[1];
409 N[2] += new_e->
t1->
gn[2];
412 N[0] += new_e->
t2->
gn[0];
413 N[1] += new_e->
t2->
gn[1];
414 N[2] += new_e->
t2->
gn[2];
420 eci = ec->
chain.last();
423 if (new_vt == new_e->
v1) {
433 double gpos[3], lpos[3];
435 double global_at = lfb[3] * es.
ratio / (es.
ratio * lfb[3] + (1 - es.
ratio) * rfb[3]);
455 else if (new_vt == new_e->
v2) {
464 for (; es; es = es->
next) {
465 double gpos[3], lpos[3];
467 double global_at = lfb[3] * es->
ratio / (es->
ratio * lfb[3] + (1 - es->
ratio) * rfb[3]);
514 if (root->
child ==
nullptr) {
519#define IN_BOUND(ba, eci) \
520 ba.l <= eci->pos[0] && ba.r >= eci->pos[0] && ba.b <= eci->pos[1] && ba.u >= eci->pos[1]
545 if (root ==
nullptr) {
562 if (root->
child ==
nullptr) {
569 if (eci == ec->
chain.first()) {
576#define IN_BOUND(ba, eci) \
577 ba.l <= eci->pos[0] && ba.r >= eci->pos[0] && ba.b <= eci->pos[1] && ba.u >= eci->pos[1]
613 float distance_threshold,
614 bool preserve_details,
617 float dist_accum = 0;
619 int fixed_occ = last_matching_eci->
occlusion;
627 if (dist_accum > distance_threshold) {
633 if (eci->occlusion < fixed_occ) {
636 if (eci->material_mask_bits == fixed_mask && eci->occlusion == fixed_occ &&
637 eci->shadow_mask_bits == fixed_shadow)
647 next_eci = eci->
next;
648 if (eci->material_mask_bits == fixed_mask && eci->occlusion == fixed_occ &&
649 eci->shadow_mask_bits == fixed_shadow)
653 if (preserve_details) {
654 eci->material_mask_bits = fixed_mask;
655 eci->occlusion = fixed_occ;
656 eci->shadow_mask_bits = fixed_shadow;
662 *r_next_eci = can_skip_to;
671 ListBaseT<void>
swap = {
nullptr};
680 ec->next = ec->prev =
nullptr;
683 ec->loop_id = loop_id;
690 ec->level = fixed_occ;
691 ec->material_mask_bits = fixed_mask;
692 ec->shadow_mask_bits = fixed_shadow;
693 for (eci = first_eci->
next; eci; eci = next_eci) {
694 next_eci = eci->
next;
721 new_ec->
chain.first_ = eci;
722 new_ec->
chain.last_ = ec->chain.last();
724 ec->chain.last_ = eci->
prev;
725 (ec->chain.last())->
next =
nullptr;
740 new_ec->
type = ec->type;
746 ec->level = fixed_occ;
747 ec->material_mask_bits = fixed_mask;
748 ec->shadow_mask_bits = fixed_shadow;
787 eci = sub->
chain.first();
790 if (sub->
chain.first() ==
nullptr) {
794 (onto->
chain.last())->next = sub->
chain.first();
795 (sub->
chain.first())->prev = onto->
chain.last();
802 eci = onto->
chain.first();
805 if (onto->
chain.first() ==
nullptr) {
809 (sub->
chain.last())->next = onto->
chain.first();
810 (onto->
chain.first())->prev = sub->
chain.last();
825 float *result_new_len,
849 if (cre.ec->picked || cre.picked) {
852 if (cre.ec == ec || (!cre.ec->chain.first()) || (cre.ec->level != occlusion) ||
853 (cre.ec->material_mask_bits != material_mask_bits) ||
854 (cre.ec->intersection_mask != isec_mask) || (cre.ec->shadow_mask_bits != shadow_mask))
859 if (cre.ec->type != ec->
type) {
878 if (((cre.ec->loop_id == loop_id) && (new_len < dist)) ||
879 ((cre.ec->loop_id != loop_id) && (new_len < dist / 10)))
883 if (result_new_len) {
884 (*result_new_len) = new_len;
890 float adjacent_new_len = dist;
893#define LRT_TEST_ADJACENT_AREAS(dist_to, list) \
894 if (dist_to < dist && dist_to > 0) { \
895 for (LinkData &link : list) { \
896 LineartBoundingArea *sba = (LineartBoundingArea *)link.data; \
897 adjacent_closest = lineart_chain_get_closest_cre(ld, \
902 material_mask_bits, \
909 if (adjacent_new_len < dist) { \
910 dist = adjacent_new_len; \
911 closest_cre = adjacent_closest; \
921 if (result_new_len) {
922 (*result_new_len) = dist;
933 float dist_l, dist_r;
934 int reverse_main, loop_id;
935 uint8_t occlusion, material_mask_bits, isec_mask;
937 ListBaseT<void>
swap = {
nullptr};
949 ec->next = ec->prev =
nullptr;
950 if (ec->picked || ec->chain.first() == ec->chain.last()) {
954 loop_id = ec->loop_id;
960 occlusion = ec->level;
961 material_mask_bits = ec->material_mask_bits;
962 isec_mask = ec->intersection_mask;
963 shadow_mask = ec->shadow_mask_bits;
965 eci_l = ec->chain.first();
966 eci_r = ec->chain.last();
994 if (closest_cre_l && closest_cre_r) {
995 if (dist_l < dist_r) {
996 closest_cre = closest_cre_l;
1000 closest_cre = closest_cre_r;
1004 else if (closest_cre_l) {
1005 closest_cre = closest_cre_l;
1008 else if (closest_cre_r) {
1009 closest_cre = closest_cre_r;
1025 eci_l = ec->chain.first();
1026 eci_r = ec->chain.last();
1035 float offset_accum = 0;
1037 float last_point[2];
1039 eci = ec->
chain.first();
1046 offset_accum += dist;
1049 return offset_accum;
1053 const float threshold,
1057 for (ec = ld->
chains.first(); ec; ec = next_ec) {
1067 return ec->
chain.count();
1072 if (lc ==
nullptr) {
1084 if (eln.object_ref == ob) {
1104 if (eln) [[likely]] {
1118 for (
int times = 0; times < 2; times++) {
1124 if (!(eci2 = eci->
next) || !(eci3 = eci2->
next)) {
1126 next_eci = eci->next;
1142 float vec2[2], vec3[2], v2n[2], ratio, len2;
1156 if (ratio < len2 && ratio > -len2 * 10) {
1158 if ((eci4 = eci3->
next) &&
1177 next_eci = eci->
next;
1190 float ref_lu[2] = {-1.0f, 1.0f}, ref_lb[2] = {-1.0f, -1.0f}, ref_ru[2] = {1.0f, 1.0f},
1191 ref_rb[2] = {1.0f, -1.0f};
1194 if (eci2->
pos[0] < -1.0f) {
1197 if (!found && eci2->
pos[0] > 1.0f) {
1200 if (!found && eci2->
pos[1] < -1.0f) {
1203 if (!found && eci2->
pos[1] > 1.0f) {
1207 if (!found) [[unlikely]] {
1211 float ratio = (
fabs(eci2->
pos[0] - eci1->pos[0]) >
fabs(eci2->
pos[1] - eci1->pos[1])) ?
1212 ratiof(eci1->pos[0], eci2->
pos[0], isec[0]) :
1213 ratiof(eci1->pos[1], eci2->
pos[1], isec[1]);
1214 float gratio = eci1->pos[3] * ratio / (ratio * eci1->pos[3] + (1 - ratio) * eci2->
pos[3]);
1226#define LRT_ECI_INSIDE(eci) \
1227 ((eci)->pos[0] >= -1.0f && (eci)->pos[0] <= 1.0f && (eci)->pos[1] >= -1.0f && \
1228 (eci)->pos[1] <= 1.0f)
1233 bool is_inside, new_inside;
1234 ListBaseT<void>
swap = {
nullptr};
1240 bool ec_added =
false;
1246 for (eci = first_eci->
next; eci; eci = next_eci) {
1247 next_eci = eci->
next;
1248 prev_eci = eci->
prev;
1253 if (new_inside ==
false) {
1260 new_ec->
chain.first_ = next_eci;
1261 eci->
prev =
nullptr;
1262 prev_eci->
next =
nullptr;
1263 ec->chain.last_ = prev_eci;
1269 next_eci = eci->
next;
1270 is_inside = new_inside;
1276 ec->chain.first_ = eci;
1277 eci->
prev =
nullptr;
1283 next_eci = eci->
next;
1284 is_inside = new_inside;
1289 if ((!ec_added) && is_inside) {
1298 ListBaseT<void>
swap = {
nullptr};
1306 ec->next = ec->prev =
nullptr;
1309 for (eci = first_eci->
next; eci; eci = next_eci) {
1310 next_eci = eci->
next;
1311 prev_eci = eci->
prev;
1313 if (next_eci && prev_eci) {
1319 if (
angle < angle_threshold_rad) {
1322 new_ec->
chain.first_ = eci;
1323 new_ec->
chain.last_ = ec->chain.last();
1324 ec->chain.last_ = eci->
prev;
1325 (ec->chain.last())->
next =
nullptr;
1326 eci->
prev =
nullptr;
1340 new_ec->
type = ec->type;
1341 new_ec->
level = ec->level;
1342 new_ec->
loop_id = ec->loop_id;
1357 float view_clamp[3];
1359 if (use_custom_camera) {
1370 float orig_len =
len_v3(dir);
1384 mul_v3_fl(view_clamp, std::min(dist, len_lim));
#define MOD_LINEART_EDGE_FLAG_ALL_TYPE
#define LRT_OBINDEX_HIGHER
#define LRT_SHADOW_SILHOUETTE_ERASED_GROUP
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
#define POS_TO_FLOAT(lpos, gpos)
#define LRT_ECI_INSIDE(eci)
#define VERT_COORD_TO_FLOAT(a)
#define LRT_OTHER_VERT(e, vt)
#define LRT_TEST_ADJACENT_AREAS(dist_to, list)
#define IN_BOUND(ba, eci)
#define LRT_ITER_ALL_LINES_END
#define LRT_ITER_ALL_LINES_NEXT
#define LRT_ITER_ALL_LINES_BEGIN
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void MOD_lineart_smooth_chains(LineartData *ld, float tolerance)
static LineartEdge * lineart_line_get_connected(LineartBoundingArea *ba, LineartVert *vt, LineartVert **new_vt, int match_flag, uint8_t match_isec_mask, Object *match_isec_object)
LineartBoundingArea * MOD_lineart_get_parent_bounding_area(LineartData *ld, double x, double y)
MINLINE void copy_v3_v3(float r[3], const float a[3])
float angle_v2v2v2(const float a[2], const float b[2], const float c[2]) ATTR_WARN_UNUSED_RESULT
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE void copy_v2_v2(float r[2], const float a[2])
LineartElementLinkNode * lineart_find_matching_eln_obj(ListBaseT< LineartElementLinkNode > *elns, Object *ob)
static LineartEdgeChain * lineart_chain_create(LineartData *ld)
int isect_seg_seg_v2_point(const float v0[2], const float v1[2], const float v2[2], const float v3[2], float r_vi[2])
void MOD_lineart_chain_feature_lines(LineartData *ld)
void * lineart_list_append_pointer_pool_sized(ListBase *h, struct LineartStaticMemPool *smp, void *data, int size)
MINLINE void sub_v2_v2v2(float r[2], const float a[2], const float b[2])
static LineartEdgeChainItem * lineart_chain_prepend_point(LineartData *ld, LineartEdgeChain *ec, float fbcoord[4], float gpos[3], float normal[3], uint8_t type, int level, uint8_t material_mask_bits, uint32_t shadow_mask_bits, size_t index)
void MOD_lineart_chain_offset_towards_camera(LineartData *ld, float dist, bool use_custom_camera)
static bool lineart_point_overlapping(LineartEdgeChainItem *eci, float x, float y, double threshold)
void MOD_lineart_finalize_chains(LineartData *ld)
void MOD_lineart_chain_clip_at_border(LineartData *ld)
MINLINE void mul_v3_fl(float r[3], float f)
int MOD_lineart_chain_count(const LineartEdgeChain *ec)
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
void MOD_lineart_chain_clear_picked_flag(LineartCache *lc)
static bool lineart_chain_fix_ambiguous_segments(LineartEdgeChain *ec, LineartEdgeChainItem *last_matching_eci, float distance_threshold, bool preserve_details, LineartEdgeChainItem **r_next_eci)
void MOD_lineart_chain_split_for_fixed_occlusion(LineartData *ld)
static LineartBoundingArea * lineart_bounding_area_get_end_point(LineartData *ld, LineartEdgeChainItem *eci)
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2])
static LineartChainRegisterEntry * lineart_chain_get_closest_cre(LineartData *ld, LineartBoundingArea *ba, LineartEdgeChain *ec, LineartEdgeChainItem *eci, int occlusion, uint8_t material_mask_bits, uint8_t isec_mask, uint32_t shadow_mask, int loop_id, float dist, float *result_new_len, LineartBoundingArea *caller_ba)
void MOD_lineart_chain_split_angle(LineartData *ld, float angle_threshold_rad)
void MOD_lineart_chain_connect(LineartData *ld)
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
void void void void void void void BLI_listbase_reverse(ListBase *lb) ATTR_NONNULL(1)
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void zero_v3(float r[3])
MINLINE float dot_v2v2(const float a[2], const float b[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v3fl_v3db(float r[3], const double a[3])
LineartBoundingArea * MOD_lineart_get_bounding_area(LineartData *ld, double x, double y)
MINLINE float normalize_v3_v3(float r[3], const float a[3])
@ MOD_LINEART_EDGE_FLAG_PROJECTED_SHADOW
@ MOD_LINEART_EDGE_FLAG_LOOSE
@ MOD_LINEART_EDGE_FLAG_CHAIN_PICKED
@ MOD_LINEART_EDGE_FLAG_INTERSECTION
@ MOD_LINEART_EDGE_FLAG_LIGHT_CONTOUR
@ MOD_LINEART_EDGE_FLAG_CONTOUR
MINLINE float normalize_v3(float n[3])
MINLINE void add_v3_v3(float r[3], const float a[3])
void interp_v3_v3v3_db(double target[3], const double a[3], const double b[3], double t)
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
void * lineart_mem_acquire(struct LineartStaticMemPool *smp, size_t size)
static void lineart_bounding_area_link_chain(LineartData *ld, LineartEdgeChain *ec)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
MINLINE float ratiof(float min, float max, float pos)
MINLINE float len_v2v2(const float v1[2], const float v2[2]) ATTR_WARN_UNUSED_RESULT
float MOD_lineart_chain_compute_length(LineartEdgeChain *ec)
static LineartEdgeChainItem * lineart_chain_append_point(LineartData *ld, LineartEdgeChain *ec, float fbcoord[4], float gpos[3], float normal[3], uint8_t type, int level, uint8_t material_mask_bits, uint32_t shadow_mask_bits, size_t index)
static void lineart_bounding_area_link_point_recursive(LineartData *ld, LineartBoundingArea *root, LineartEdgeChain *ec, LineartEdgeChainItem *eci)
MINLINE float interpf(float target, float origin, float t)
void MOD_lineart_chain_find_silhouette_backdrop_objects(LineartData *ld)
static LineartEdgeChainItem * lineart_chain_create_crossing_point(LineartData *ld, LineartEdgeChainItem *eci_inside, LineartEdgeChainItem *eci_outside)
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
void MOD_lineart_chain_discard_unused(LineartData *ld, const float threshold, uint8_t max_occlusion)
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
static void lineart_chain_connect(LineartData *, LineartEdgeChain *onto, LineartEdgeChain *sub, int reverse_1, int reverse_2)
MINLINE float normalize_v2_v2(float r[2], const float a[2])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static LineartBoundingArea * lineart_bounding_area_get_eci_recursive(LineartData *ld, LineartBoundingArea *root, LineartEdgeChainItem *eci)
LineartElementLinkNode * lineart_find_matching_eln(ListBaseT< LineartElementLinkNode > *shadow_elns, int obindex)
LineartBoundingArea * child
ListBaseT< LineartChainRegisterEntry > linked_chains
LineartEdge ** linked_lines
ListBaseT< LineartEdgeChain > chains
LineartEdgeChainItem * eci
bool chain_preserve_details
bool use_loose_edge_chain
double active_camera_pos[3]
bool use_geometry_space_chain
float chaining_image_threshold
ListBaseT< LineartElementLinkNode > vertex_buffer_pointers
ListBaseT< LineartElementLinkNode > line_buffer_pointers
LineartStaticMemPool * chain_data_pool
struct blender::LineartData::_geom geom
struct blender::LineartData::_conf conf
ListBaseT< LineartEdgeChain > chains
LineartEdgeChainItem * prev
uint8_t material_mask_bits
uint32_t shadow_mask_bits
LineartEdgeChainItem * next
ListBaseT< LineartEdgeChainItem > chain
uint8_t intersection_mask
uint32_t shadow_mask_bits
Object * silhouette_backdrop
uint8_t material_mask_bits
LineartEdgeSegment * next
uint32_t shadow_mask_bits
uint8_t material_mask_bits
LineartEdgeSegment * prev
ListBaseT< LineartEdgeSegment > segments
uint8_t intersection_mask