[Bf-blender-cvs] [e3b58b64515] temp_bmesh_multires: Sculpt dyntopo: Split off dyntopo stuff from pbvh_bmesh.c into a new file, dyntopo.c.
Joseph Eagar
noreply at git.blender.org
Sun Jul 18 22:13:29 CEST 2021
Commit: e3b58b64515648f62d361b109e447866ce0f9c28
Author: Joseph Eagar
Date: Sun Jul 18 13:12:08 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rBe3b58b64515648f62d361b109e447866ce0f9c28
Sculpt dyntopo: Split off dyntopo stuff from pbvh_bmesh.c into a new file, dyntopo.c.
===================================================================
A source/blender/blenkernel/BKE_dyntopo.h
M source/blender/blenkernel/CMakeLists.txt
A source/blender/blenkernel/intern/dyntopo.c
M source/blender/blenkernel/intern/paint.c
M source/blender/blenkernel/intern/pbvh_bmesh.c
M source/blender/blenkernel/intern/pbvh_intern.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_dyntopo.h b/source/blender/blenkernel/BKE_dyntopo.h
new file mode 100644
index 00000000000..7944567a141
--- /dev/null
+++ b/source/blender/blenkernel/BKE_dyntopo.h
@@ -0,0 +1,24 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+/** \file
+ * \ingroup bke
+ * \brief Dynamic topology remeshing API
+ */
+
+typedef struct DynTopo DynTopo;
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 1b6de62fecb..714ea8b1c23 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -121,6 +121,7 @@ set(SRC
intern/displist.cc
intern/displist_tangent.c
intern/dynamicpaint.c
+ intern/dyntopo.c
intern/editlattice.c
intern/editmesh.c
intern/editmesh_bvh.c
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/dyntopo.c
similarity index 50%
copy from source/blender/blenkernel/intern/pbvh_bmesh.c
copy to source/blender/blenkernel/intern/dyntopo.c
index 20629e51186..a15fd4ce875 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/dyntopo.c
@@ -1,49 +1,16 @@
-/*
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-/** \file
- * \ingroup bli
- */
-
-/*
-
-TODO:
-
-Convergence improvements:
-1. DONE: Limit number of edges processed per run.
-2. DONE: Scale split steps by ratio of long to short edges to
- prevent runaway tesselation.
-3. DONE: Detect and dissolve three and four valence vertices that are surrounded by
- all tris.
-4. DONE: Use different (coarser) brush spacing for applying dyntopo
-
-Drawing improvements:
-4. PARTIAL DONE: Build and cache vertex index buffers, to reduce GPU bandwidth
-
-Topology rake:
-5. DONE: Enable new curvature topology rake code and add to UI.
-6. DONE: Add code to cache curvature data per vertex in a CD layer.
-
-*/
-
#include "MEM_guardedalloc.h"
+#include "DNA_customdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
#include "BLI_array.h"
+#include "BLI_bitmap.h"
#include "BLI_buffer.h"
+#include "BLI_compiler_attrs.h"
+#include "BLI_compiler_compat.h"
#include "BLI_ghash.h"
+#include "BLI_heap.h"
#include "BLI_heap_simple.h"
#include "BLI_math.h"
#include "BLI_memarena.h"
@@ -53,17 +20,15 @@ Topology rake:
#include "PIL_time.h"
#include "atomic_ops.h"
-#include "DNA_material_types.h"
-
-#include "BKE_DerivedMesh.h"
-#include "BKE_ccg.h"
+#include "BKE_customdata.h"
+#include "BKE_dyntopo.h"
#include "BKE_pbvh.h"
-#include "GPU_buffers.h"
-
#include "bmesh.h"
#include "pbvh_intern.h"
+#include <stdio.h>
+
#define DYNTOPO_MAX_ITER 4096
#define DYNTOPO_USE_HEAP
@@ -97,71 +62,9 @@ Topology rake:
# include "BKE_global.h"
#endif
-#ifndef DEBUG
-# define DEBUG_DEFINED
-# define DEBUG
-#endif
-
-#ifdef WIN32
-# include "crtdbg.h"
-#endif
-
-static void check_heap()
-{
-#ifdef WIN32
- if (!_CrtCheckMemory()) {
- printf("Memory corruption!");
- _CrtDbgBreak();
- }
-# ifdef DEBUG_DEFINED
-# undef DEBUG_DEFINED
-# undef DEBUG
-# endif
-#endif
-}
/* Support for only operating on front-faces */
#define USE_EDGEQUEUE_FRONTFACE
-static void check_nodes(PBVH *pbvh)
-{
-#if 0
- for (int i = 0; i < pbvh->totnode; i++) {
- PBVHNode *node = pbvh->nodes + i;
- BMVert *v;
- BMFace *f;
-
- if (!(node->flag & PBVH_Leaf)) {
- continue;
- }
-
- TGSET_ITER (v, node->bm_unique_verts) {
- if (v->head.htype > 8) {
- printf("corruption in pbvh! bm_unique_verts\n");
- }
- }
- TGSET_ITER_END;
-
- TGSET_ITER (v, node->bm_other_verts) {
- if (v->head.htype > 8) {
- printf("corruption in pbvh! bm_other_verts\n");
- }
- }
- TGSET_ITER_END;
-
- TGSET_ITER (f, node->bm_faces) {
- if (f->head.htype > 8) {
- printf("corruption in pbvh! bm_faces\n");
- }
- }
- TGSET_ITER_END;
- }
-#endif
-}
-
-void pbvh_bmesh_check_nodes(PBVH *pbvh)
-{
- check_nodes(pbvh);
-}
/**
* Ensure we don't have dirty tags for the edge queue, and that they are left cleared.
* (slow, even for debug mode, so leave disabled for now).
@@ -350,221 +253,6 @@ static BMVert *bm_vert_hash_lookup_chain(GHash *deleted_verts, BMVert *v)
}
}
-/** \} */
-
-/****************************** Building ******************************/
-
-/* Update node data after splitting */
-static void pbvh_bmesh_node_finalize(PBVH *pbvh,
- const int node_index,
- const int cd_vert_node_offset,
- const int cd_face_node_offset,
- bool add_orco)
-{
- PBVHNode *n = &pbvh->nodes[node_index];
- bool has_visible = false;
-
- /* Create vert hash sets */
- n->bm_unique_verts = BLI_table_gset_new("bm_unique_verts");
- n->bm_other_verts = BLI_table_gset_new("bm_other_verts");
-
- BB_reset(&n->vb);
- BMFace *f;
-
- TGSET_ITER (f, n->bm_faces) {
- /* Update ownership of faces */
- BM_ELEM_CD_SET_INT(f, cd_face_node_offset, node_index);
-
- /* Update vertices */
- BMLoop *l_first = BM_FACE_FIRST_LOOP(f);
- BMLoop *l_iter = l_first;
-
- do {
- BMVert *v = l_iter->v;
- if (!BLI_table_gset_haskey(n->bm_unique_verts, v)) {
- if (BM_ELEM_CD_GET_INT(v, cd_vert_node_offset) != DYNTOPO_NODE_NONE) {
- BLI_table_gset_add(n->bm_other_verts, v);
- }
- else {
- BLI_table_gset_insert(n->bm_unique_verts, v);
- BM_ELEM_CD_SET_INT(v, cd_vert_node_offset, node_index);
- }
- }
- /* Update node bounding box */
- BB_expand(&n->vb, v->co);
- } while ((l_iter = l_iter->next) != l_first);
-
- if (!BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
- has_visible = true;
- }
- }
- TGSET_ITER_END
-
- BLI_assert(n->vb.bmin[0] <= n->vb.bmax[0] && n->vb.bmin[1] <= n->vb.bmax[1] &&
- n->vb.bmin[2] <= n->vb.bmax[2]);
-
- n->orig_vb = n->vb;
-
- /* Build GPU buffers for new node and update vertex normals */
- BKE_pbvh_node_mark_rebuild_draw(n);
-
- BKE_pbvh_node_fully_hidden_set(n, !has_visible);
- n->flag |= PBVH_UpdateNormals | PBVH_UpdateTopology | PBVH_UpdateCurvatureDir | PBVH_UpdateTris;
-
- if (add_orco) {
- BKE_pbvh_bmesh_check_tris(pbvh, n);
- }
-}
-
-/* Recursively split the node if it exceeds the leaf_limit */
-static void pbvh_bmesh_node_split(
- PBVH *pbvh, const BBC *bbc_array, int node_index, bool add_orco, int depth)
-{
- const int cd_vert_node_offset = pbvh->cd_vert_node_offset;
- const int cd_face_node_offset = pbvh->cd_face_node_offset;
- PBVHNode *n = &pbvh->nodes[node_index];
-
-#ifdef PROXY_ADVANCED
- BKE_pbvh_free_proxyarray(pbvh, n);
-#endif
-
- if (depth > 6 || BLI_table_gset_len(n->bm_faces) <= pbvh->leaf_limit) {
- /* Node limit not exceeded */
- pbvh_bmesh_node_finalize(pbvh, node_index, cd_vert_node_offset, cd_face_node_offset, add_orco);
- return;
- }
-
- /* Calculate bounding box around primitive centroids */
- BB cb;
- BB_reset(&cb);
- BMFace *f;
-
- TGSET_ITER (f, n->bm_faces) {
- const BBC *bbc = &bbc_array[BM_elem_index_get(f)];
-
- BB_expand(&cb, bbc->bcentroid);
- }
- TGSET_ITER_END
-
- /* Find widest axis and its midpoint */
- const int axis = BB_widest_axis(&cb);
- const float mid = (cb.bmax[axis] + cb.bmin[axis]) * 0.5f;
-
- if (isnan(mid)) {
- printf("NAN ERROR! %s\n", __func__);
- }
-
- /* Add two new child nodes */
- const int children = pbvh->totnode;
- n->children_offset = children;
- pbvh_grow_nodes(pbvh, pbvh->totnode + 2);
-
- /* Array reallocated, update current node pointer */
- n = &pbvh->nodes[node_index];
-
- /* Initialize children */
- PBVHNode *c1 = &pbvh->nodes[children], *c2 = &pbvh->nodes[children + 1];
-
- c1->flag |= PBVH_Leaf;
- c2->flag |= PBVH_Leaf;
- c1->bm_faces = BLI_table_gset_new_ex("bm_faces", BLI_table_gset_len(n->bm_faces) / 2);
- c2->bm_faces = BLI_table_gset_new_ex("bm_faces", BLI_table_gset_len(n->bm_faces) / 2);
-
- c1->bm_unique_verts = c2->bm_unique_verts = NULL;
- c1->bm_other_verts = c2->bm_other_verts = NULL;
-
- /* Partition the parent node's faces between the two children */
- TGSET_ITER (f, n->bm_faces) {
- const BBC *bbc = &bbc_array[BM_elem_index_get(f)];
-
- if (bbc->bcentroid[axis] < mid) {
- BLI_table_gset_insert(c1->bm_faces, f);
- }
- else {
- BLI_table_gset_insert(c2->bm_faces, f);
- }
- }
- TGSET_ITER_END
-#if 0
- /* Enforce at least one primitive in each node */
- TableGSet *empty = NULL, *other;
- if (BLI_table_gset_len(c1->bm_faces) == 0) {
- empty = c1->bm_faces;
- other = c2->bm_faces;
- }
- else if (BLI_table_gset_len(c2->bm_faces) == 0) {
- empty = c2->bm_faces;
- other = c1->bm_faces;
- }
-
- if (empty) {
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list