[Bf-blender-cvs] [d88f0b1052a] temp-trimesh-sculpt: More trimesh stuff
Joseph Eagar
noreply at git.blender.org
Wed Oct 14 04:05:42 CEST 2020
Commit: d88f0b1052a707eab3d0cb077d9ca9c11c0c3663
Author: Joseph Eagar
Date: Tue Sep 29 19:34:12 2020 -0700
Branches: temp-trimesh-sculpt
https://developer.blender.org/rBd88f0b1052a707eab3d0cb077d9ca9c11c0c3663
More trimesh stuff
===================================================================
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/BKE_pbvh.h
M source/blender/blenkernel/intern/paint.c
M source/blender/blenkernel/intern/pbvh_bmesh.c
M source/blender/blenkernel/intern/pbvh_intern.h
M source/blender/blenkernel/intern/pbvh_trimesh.c
M source/blender/blenlib/BLI_trimesh.h
M source/blender/blenlib/intern/BLI_trimesh.c
M source/blender/editors/sculpt_paint/sculpt.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 881f3356a86..7fc94ba9b26 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -298,6 +298,9 @@ typedef struct SculptSession {
/* Mesh Face Sets */
int *face_sets;
+ struct BLI_TriMesh *tm;
+ struct TriMeshLog *tm_log;
+
/* BMesh for dynamic topology sculpting */
struct BMesh *bm;
int cd_vert_node_offset;
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index a9ff2a3b46a..2f238dd45a3 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -118,6 +118,13 @@ void BKE_pbvh_build_bmesh(PBVH *bvh,
struct BMLog *log,
const int cd_vert_node_offset,
const int cd_face_node_offset);
+void BKE_pbvh_build_trimesh(PBVH *bvh,
+ struct BLI_TriMesh *bm,
+ bool smooth_shading,
+ struct TriMeshLog *log,
+ const int cd_vert_node_offset,
+ const int cd_face_node_offset);
+
void BKE_pbvh_free(PBVH *bvh);
void BKE_pbvh_free_layer_disp(PBVH *bvh);
@@ -162,6 +169,11 @@ bool BKE_pbvh_bmesh_node_raycast_detail(PBVHNode *node,
struct IsectRayPrecalc *isect_precalc,
float *depth,
float *r_edge_length);
+bool BKE_pbvh_trimesh_node_raycast_detail(PBVHNode *node,
+ const float ray_start[3],
+ struct IsectRayPrecalc *isect_precalc,
+ float *depth,
+ float *r_edge_length);
/* for orthographic cameras, project the far away ray segment points to the root node so
* we can have better precision. */
@@ -228,7 +240,8 @@ int BKE_pbvh_get_grid_num_vertices(const PBVH *pbvh);
/* Only valid for type == PBVH_BMESH */
struct BMesh *BKE_pbvh_get_bmesh(PBVH *pbvh);
-void BKE_pbvh_bmesh_detail_size_set(PBVH *pbvh, float detail_size);
+struct BLI_TriMesh *BKE_pbvh_get_trimesh(PBVH *pbvh);
+void BKE_pbvh_topology_detail_size_set(PBVH *pbvh, float detail_size);
typedef enum {
PBVH_Subdivide = 1,
@@ -242,6 +255,13 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *bvh,
const bool use_frontface,
const bool use_projected);
+bool BKE_pbvh_trimesh_update_topology(PBVH *bvh,
+ PBVHTopologyUpdateMode mode,
+ const float center[3],
+ const float view_normal[3],
+ float radius,
+ const bool use_frontface,
+ const bool use_projected);
/* Node Access */
void BKE_pbvh_node_mark_update(PBVHNode *node);
@@ -286,6 +306,12 @@ struct GSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node);
void BKE_pbvh_bmesh_node_save_orig(struct BMesh *bm, PBVHNode *node);
void BKE_pbvh_bmesh_after_stroke(PBVH *bvh);
+struct GSet *BKE_pbvh_trimesh_node_unique_verts(PBVHNode *node);
+struct GSet *BKE_pbvh_trimesh_node_other_verts(PBVHNode *node);
+struct GSet *BKE_pbvh_trimesh_node_faces(PBVHNode *node);
+void BKE_pbvh_trimesh_node_save_orig(struct BLI_TriMesh *tm, PBVHNode *node);
+void BKE_pbvh_trimesh_after_stroke(PBVH *bvh);
+
/* Update Bounding Box/Redraw and clear flags */
void BKE_pbvh_update_bounds(PBVH *bvh, int flags);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 719336f7351..d44dc9bd7f5 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -74,6 +74,7 @@
#include "RNA_enum_types.h"
#include "bmesh.h"
+#include "BLI_trimesh.h"
static void palette_init_data(ID *id)
{
@@ -1158,6 +1159,17 @@ bool paint_is_bmesh_face_hidden(BMFace *f)
return false;
}
+
+/* Return true if all vertices in the face are visible, false otherwise */
+bool paint_is_trimesh_face_hidden(TMFace *f)
+{
+ bool ret = f->v1->flag & TRIMESH_HIDE;
+ ret = ret || (f->v2->flag & TRIMESH_HIDE);
+ ret = ret || (f->v3->flag & TRIMESH_HIDE);
+
+ return ret;
+}
+
float paint_grid_paint_mask(const GridPaintMask *gpm, uint level, uint x, uint y)
{
int factor = BKE_ccg_factor(level, gpm->level);
@@ -1257,6 +1269,34 @@ void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss)
MEM_SAFE_FREE(gmap->poly_map_mem);
}
+/* Write out the sculpt dynamic-topology BMesh to the Mesh */
+static void sculptsession_tm_to_me_update_data_only(Object *ob, bool reorder)
+{
+ SculptSession *ss = ob->sculpt;
+
+ if (ss->bm) {
+ if (ob->data) {
+ BLI_TriMeshIter iter;
+ TMFace *f;
+
+ BLI_trimesh_tri_iternew(ss->tm, &iter);
+ f = BLI_trimesh_iterstep(&iter);
+ for (; f; f = BLI_trimesh_iterstep(&iter)) {
+ TRIMESH_elem_flag_set(f, TRIMESH_SMOOTH, ss->bm_smooth_shading);
+ }
+ //if (reorder) {
+ // BM_log_mesh_elems_reorder(ss->bm, ss->bm_log);
+ //}
+ BLI_trimesh_mesh_bm_to_me(NULL,
+ ss->tm,
+ ob->data,
+ (&(struct TMeshToMeshParams){
+ .calc_object_remap = false,
+ }));
+ }
+ }
+}
+
/* Write out the sculpt dynamic-topology BMesh to the Mesh */
static void sculptsession_bm_to_me_update_data_only(Object *ob, bool reorder)
{
@@ -1796,10 +1836,10 @@ static bool check_sculpt_object_deformed(Object *object, const bool for_construc
static PBVH *build_pbvh_for_dynamic_topology(Object *ob)
{
PBVH *pbvh = BKE_pbvh_new();
- BKE_pbvh_build_bmesh(pbvh,
- ob->sculpt->bm,
+ BKE_pbvh_build_trimesh(pbvh,
+ ob->sculpt->tm,
ob->sculpt->bm_smooth_shading,
- ob->sculpt->bm_log,
+ ob->sculpt->tm_log,
ob->sculpt->cd_vert_node_offset,
ob->sculpt->cd_face_node_offset);
pbvh_show_mask_set(pbvh, ob->sculpt->show_mask);
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 73042222436..39d13f84810 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -1887,7 +1887,7 @@ void BKE_pbvh_build_bmesh(PBVH *bvh,
bvh->cd_face_node_offset = cd_face_node_offset;
bvh->bm = bm;
- BKE_pbvh_bmesh_detail_size_set(bvh, 0.75);
+ BKE_pbvh_topology_detail_size_set(bvh, 0.75);
bvh->type = PBVH_BMESH;
bvh->bm_log = log;
@@ -2107,7 +2107,7 @@ void BKE_pbvh_bmesh_after_stroke(PBVH *bvh)
}
}
-void BKE_pbvh_bmesh_detail_size_set(PBVH *bvh, float detail_size)
+void BKE_pbvh_topology_detail_size_set(PBVH *bvh, float detail_size)
{
bvh->bm_max_edge_len = detail_size;
bvh->bm_min_edge_len = bvh->bm_max_edge_len * 0.4f;
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index cabe96dc158..493e0905f0d 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -242,4 +242,22 @@ bool pbvh_bmesh_node_nearest_to_ray(PBVHNode *node,
void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode);
+/* pbvh_bmesh.c */
+bool pbvh_trimesh_node_raycast(PBVHNode *node,
+ const float ray_start[3],
+ const float ray_normal[3],
+ struct IsectRayPrecalc *isect_precalc,
+ float *dist,
+ bool use_original,
+ int *r_active_vertex_index,
+ float *r_face_normal);
+bool pbvh_trimesh_node_nearest_to_ray(PBVHNode *node,
+ const float ray_start[3],
+ const float ray_normal[3],
+ float *depth,
+ float *dist_sq,
+ bool use_original);
+
+void pbvh_trimesh_normals_update(PBVHNode **nodes, int totnode);
+
#endif
diff --git a/source/blender/blenkernel/intern/pbvh_trimesh.c b/source/blender/blenkernel/intern/pbvh_trimesh.c
index 35accad9133..ba9d3bcdc31 100644
--- a/source/blender/blenkernel/intern/pbvh_trimesh.c
+++ b/source/blender/blenkernel/intern/pbvh_trimesh.c
@@ -333,7 +333,7 @@ static bool pbvh_trimesh_node_limit_ensure(PBVH *bvh, int node_index)
f->index = i; /* set_dirty! */
}
/* Likely this is already dirty. */
- bvh->bm->elem_index_dirty |= BM_FACE;
+ //bvh->tm->elem_index_dirty |= BM_FACE;
pbvh_trimesh_node_split(bvh, bbc_array, node_index);
@@ -1271,7 +1271,7 @@ static void pbvh_trimesh_collapse_edge(PBVH *bvh,
BLI_assert(BLI_trimesh_edge_is_wire(e));
//XXX check threadnr argument!
- BLI_trimesh_kill_edge(bvh->bm, e, 0, false);
+ BLI_trimesh_kill_edge(bvh->tm, e, 0, false);
/* For all remaining faces of v_del, create a new face that is the
* same except it uses v_conn instead of v_del */
@@ -1294,7 +1294,7 @@ static void pbvh_trimesh_collapse_edge(PBVH *bvh,
PBVHNode *n = pbvh_trimesh_node_from_face(bvh, tri);
int ni = n - bvh->nodes;
- tm_edges_from_tri(bvh->bm, v_tri, e_tri, 0, true);
+ tm_edges_from_tri(bvh->tm, v_tri, e_tri, 0, true);
pbvh_trimesh_face_create(bvh, ni, v_tri, e_tri, tri);
/* Ensure that v_conn is in the new face's node */
@@ -1344,7 +1344,7 @@ static void pbvh_trimesh_collapse_edge(PBVH *bvh,
v_conn = NULL;
}
BLI_ghash_insert(deleted_verts, v_tri[j], NULL);
- BLI_trimesh_vert_kill(bvh->bm, v_tri[j]);
+ BLI_trimesh_kill_vert(bvh->tm, v_tri[j], 0); //XXX check threadnr
}
}
}
@@ -1809,7 +1809,7 @@ void BKE_pbvh_build_trimesh(PBVH *bvh,
bvh->cd_face_node_offset = cd_face_node_offset;
bvh->tm = tm;
- BKE_pbvh_trimesh_detail_size_set(bvh, 0.75);
+ BKE_pbvh_topology_detail_size_set(bvh, 0.75);
bvh->type = PBVH_TRIMESH;
bvh->tm_log = log;
diff --git a/source/blender/blenlib/BLI_trimesh.h b/source/blender/blenlib/BLI_trimesh.h
index c9c613fe148..af14f5137f7 100644
--- a/source/blender/blenlib/BLI_trimesh.h
+++ b/source/blender/blenlib/BLI_trimesh.h
@@ -3,6 +3,7 @@
#include "BLI_threads.h"
#include "BLI_threadsafe_mempool.h"
#include "DNA_customdata_types.h"
+#include "DNA_meshdata_types.h"
#include <stdint.h>
@@ -10,9 +11,51 @@ struct OptTriVert;
struct OptTriEdge;
struct OptTri;
-#define TRIMESH_SELECT (1<<1)
-#define TRIMESH_HIDE (1<<2)
-#define TRIMESH_VT_ITERFLAG (1<<7)
+enum {
+ TRIMESH_SELECT = 1<<1,
+ TRIMESH_HIDE = 1<<1,
+ TRIMESH_SMOOTH = 1<<3,
+ TRIMESH_VT_ITERFLAG = 1<<9
+};
+
+static uint8_t BLI_trimesh_vert_flag_to_mflag(int16_t
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list