[Bf-blender-cvs] [a9fe5cb8593] lineart-fn-thread-loading: Lineart: loading
YimingWu
noreply at git.blender.org
Tue Jun 1 15:32:27 CEST 2021
Commit: a9fe5cb8593237b2d115c488252d1e535ebcf02c
Author: YimingWu
Date: Mon May 31 20:52:01 2021 +0800
Branches: lineart-fn-thread-loading
https://developer.blender.org/rBa9fe5cb8593237b2d115c488252d1e535ebcf02c
Lineart: loading
===================================================================
M source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
M source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
M source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
===================================================================
diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index ee1ff62f19e..45b37efbee4 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -350,6 +350,7 @@ struct BMesh;
typedef struct LineartObjectInfo {
struct LineartObjectInfo *next;
struct Object *original_ob;
+ struct Mesh *me;
struct BMesh *original_bm;
double new_mvp[4][4];
double new_mv[4][4];
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
index 23928b4ccda..2345ffc6d94 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_chain.c
@@ -77,6 +77,7 @@ static LineartEdgeChain *lineart_chain_create(LineartRenderBuffer *rb)
ec = lineart_mem_acquire(&rb->render_data_pool, sizeof(LineartEdgeChain));
BLI_addtail(&rb->chains, ec);
+ printf("chain%d\n", ec);
return ec;
}
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index a3899c0d945..d8cb1523a71 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -42,6 +42,7 @@
#include "BKE_gpencil_modifier.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
+#include "BKE_mesh_runtime.h"
#include "BKE_scene.h"
#include "DEG_depsgraph_query.h"
#include "DNA_camera_types.h"
@@ -443,6 +444,7 @@ static void lineart_occlusion_worker(TaskPool *__restrict UNUSED(pool), LineartR
while (lineart_occlusion_make_task_info(rb, rti)) {
for (eip = rti->contour.first; eip && eip != rti->contour.last; eip = eip->next) {
+ printf("eip l %d r %d t1 %d t2 %d fl %d\n", eip->v1, eip->v2, eip->t1, eip->t2, eip->flags);
lineart_occlusion_single_line(rb, eip, rti->thread_id);
}
@@ -1370,6 +1372,14 @@ static void lineart_main_perspective_division(LineartRenderBuffer *rb)
}
}
+typedef struct LineartMeshEdge {
+ int v1, v2;
+ LineartTriangle *t1, *t2;
+ int poly1, poly2;
+ int flags;
+ bool managed;
+} LineartMeshEdge;
+
/**
* Transform a single vert to it's viewing position.
*/
@@ -1383,6 +1393,16 @@ static void lineart_vert_transform(
mul_v4_m4v3_db(vt->fbcoord, mvp_mat, co);
}
+static void lineart_mvert_transform(
+ MVert *v, int index, LineartVert *RvBuf, double (*mv_mat)[4], double (*mvp_mat)[4])
+{
+ double co[4];
+ LineartVert *vt = &RvBuf[index];
+ copy_v3db_v3fl(co, v->co);
+ mul_v3_m4v3_db(vt->gloc, mv_mat, co);
+ mul_v4_m4v3_db(vt->fbcoord, mvp_mat, co);
+}
+
/**
* Because we have a variable size for #LineartTriangle, we need an access helper.
* See #LineartTriangleThread for more info.
@@ -1396,6 +1416,74 @@ static LineartTriangle *lineart_triangle_from_index(LineartRenderBuffer *rb,
return (LineartTriangle *)b;
}
+static char lineart_identify_feature_line_me(LineartRenderBuffer *rb,
+ LineartMeshEdge *la_me,
+ LineartTriangle *rt_array,
+ LineartVert *rv_array,
+ float crease_threshold,
+ bool no_crease,
+ bool count_freestyle,
+ Mesh *me)
+{
+ return LRT_EDGE_FLAG_CONTOUR;
+ if (!la_me->managed) {
+ return 0;
+ }
+
+ if (la_me->t1 && !la_me->t2) {
+ return LRT_EDGE_FLAG_CONTOUR;
+ }
+
+ LineartTriangle *tri1, *tri2;
+ LineartVert *l;
+
+ tri1 = la_me->t1;
+ tri2 = la_me->t2;
+
+ l = &rv_array[la_me->v1];
+
+ double vv[3];
+ double *view_vector = vv;
+ double dot_1 = 0, dot_2 = 0;
+ double result;
+ FreestyleEdge *fe;
+
+ if (rb->cam_is_persp) {
+ sub_v3_v3v3_db(view_vector, l->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);
+
+ if ((result = dot_1 * dot_2) <= 0 && (dot_1 + dot_2)) {
+ return LRT_EDGE_FLAG_CONTOUR;
+ }
+
+ if (rb->use_crease && (dot_v3v3_db(tri1->gn, tri2->gn) < crease_threshold)) {
+ if (!no_crease) {
+ return LRT_EDGE_FLAG_CREASE;
+ }
+ }
+ else if (rb->use_material &&
+ (me->mpoly[la_me->poly1].mat_nr != me->mpoly[la_me->poly2].mat_nr)) {
+ return LRT_EDGE_FLAG_MATERIAL;
+ }
+
+#ifdef LINEART_HOLD_ON_THIS_IS_NOT_DONE_YET
+ else if (count_freestyle && rb->use_edge_marks) {
+ fe = CustomData_bmesh_get(&bm_if_freestyle->edata, e->head.data, CD_FREESTYLE_EDGE);
+ if (fe->flag & FREESTYLE_EDGE_MARK) {
+ return LRT_EDGE_FLAG_EDGE_MARK;
+ }
+ }
+#endif
+
+ return 0;
+}
+
static char lineart_identify_feature_line(LineartRenderBuffer *rb,
BMEdge *e,
LineartTriangle *rt_array,
@@ -1540,9 +1628,303 @@ static void lineart_triangle_adjacent_assign(LineartTriangle *tri,
}
}
+static void lineart_triangle_adjacent_assign_me(LineartTriangle *tri,
+ LineartTriangleAdjacent *ta,
+ LineartEdge *e)
+{
+ if (lineart_edge_match(tri, e, 0, 1)) {
+ ta->e[0] = e;
+ }
+ else if (lineart_edge_match(tri, e, 1, 2)) {
+ ta->e[1] = e;
+ }
+ else if (lineart_edge_match(tri, e, 2, 0)) {
+ ta->e[2] = e;
+ }
+}
+
+static int lineart_mesh_edge_get_or_insert_from_vpair(LineartMeshEdge *table,
+ int real_edge,
+ int orig_edge_count,
+ int max_edge_count,
+ int v1,
+ int v2,
+ LineartTriangle *from,
+ int poly)
+{
+ if (real_edge >= 0) {
+ LineartMeshEdge *e = &table[real_edge];
+ if (!e->t1) {
+ e->t1 = from;
+ e->poly1 = poly;
+ printf("old edge %d %d f %d\n", v1, v2, from);
+ }
+ else {
+ e->t2 = from;
+ e->poly2 = poly;
+ printf("old_edge %d %d f %d\n", v1, v2, from);
+ }
+ return real_edge;
+ }
+ else {
+ printf("new_edge %d %d f %d\n", v1, v2, from);
+ for (int i = orig_edge_count; i < max_edge_count; i++) {
+ LineartMeshEdge *e = &table[i];
+ if (e->managed) {
+ if ((e->v1 == v1 && e->v2 == v2) || (e->v1 == v2 && e->v2 == v1)) {
+ if (!e->t1) {
+ e->t1 = from;
+ e->poly1 = poly;
+ }
+ else {
+ e->t2 = from;
+ e->poly2 = poly;
+ }
+ return i;
+ }
+ }
+ else {
+ e->managed = true;
+ e->v1 = v1;
+ e->v2 = v2;
+ e->t1 = from;
+ e->poly1 = poly;
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+
+static void lineart_geometry_object_load_mesh(LineartObjectInfo *obi, LineartRenderBuffer *rb)
+{
+ Mesh *me;
+ MVert *v;
+ MPoly *f;
+ MLoopTri *looptri;
+ MEdge *e;
+ MLoop *loop;
+ LineartMeshEdge *la_me;
+ LineartEdge *la_e;
+ LineartEdgeSegment *la_s;
+ LineartTriangle *tri;
+ LineartTriangleAdjacent *orta;
+ double(*new_mvp)[4] = obi->new_mvp, (*new_mv)[4] = obi->new_mv, (*normal)[4] = obi->normal;
+ LineartElementLinkNode *eln;
+ LineartVert *orv;
+ LineartEdge *o_la_e;
+ LineartEdgeSegment *o_la_s;
+ LineartTriangle *ort;
+ Object *orig_ob = obi->original_ob;
+ int CanFindFreestyle = 0;
+ int i;
+ float use_crease = 0;
+
+ int usage = obi->override_usage;
+
+ me = obi->me;
+
+ if (orig_ob->lineart.flags & OBJECT_LRT_OWN_CREASE) {
+ use_crease = cosf(M_PI - orig_ob->lineart.crease_threshold);
+ }
+ else {
+ use_crease = rb->crease_threshold;
+ }
+
+ /* FIXME(Yiming): Hack for getting clean 3D text, the seam that extruded text object creates
+ * erroneous detection on creases. Future configuration should allow options. */
+ if (orig_ob->type == OB_FONT) {
+ eln->flags |= LRT_ELEMENT_BORDER_ONLY;
+ }
+
+ BKE_mesh_runtime_looptri_ensure(me);
+
+ int tri_count = BKE_mesh_runtime_looptri_len(me);
+ int max_edge_count = tri_count * 3;
+ int mesh_edge_count = me->totedge;
+
+ /* Only allocate memory for verts and tris as we don't know how many lines we will generate
+ * yet. */
+ orv = lineart_mem_acquire_thread(&rb->render_data_pool, sizeof(LineartVert) * me->totvert);
+ ort = lineart_mem_acquire_thread(&rb->render_data_pool, tri_count * rb->triangle_size);
+
+ BLI_spin_lock(&rb->lock_task);
+ eln = lineart_list_append_pointer_pool_sized_thread(
+ &rb->vertex_buffer_pointers, &rb->render_data_pool, orv, sizeof(LineartElementLinkNode));
+ BLI_spin_unlock(&rb->lock_task);
+
+ eln->element_count = me->totvert;
+ eln->object_ref = orig_ob;
+ obi->v_reln = eln;
+
+ BLI_spin_lock(&rb->lock_task);
+ eln = lineart_list_append_pointer_pool_sized_thread(
+ &rb->triangle_buffer_pointers, &rb->render_data_pool, ort, sizeof(LineartElementLinkNode));
+ BLI_spin_unlock(&rb->lock_task);
+
+ eln->element_count = tri_count;
+ eln->object_ref = orig_ob;
+ eln->flags |= (usage == OBJECT_LRT_NO_INTERSECTION ? LRT_ELEMENT_NO_INTERSECTION : 0);
+
+ /* Note this memory is not from pool, will be deleted after culling. */
+ orta = MEM_callocN(sizeof(LineartTriangleAdjacent) * tri_count, "LineartTriangleAdjacent");
+ /* Link is minimal so we use pool anyway. */
+ BLI_spin_lock(&rb->lock_task);
+ lineart_list_append_pointer_pool_thread(
+ &rb->triangle_adjacent_pointers, &rb->render_data_pool, orta);
+ BLI_spin_unlock(&rb->lock_task);
+
+ for (i = 0; i < me->totvert; i++) {
+ v = &me->mvert[i];
+ lineart_mvert_transform(v, i, orv, new_mv, new_mvp);
+ orv[i].index = i;
+ }
+ /* Register a global index increment. See
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list