[Bf-blender-cvs] [49f57d8de87] temp_bmesh_multires: COde cleanup
Joseph Eagar
noreply at git.blender.org
Mon Oct 19 03:10:48 CEST 2020
Commit: 49f57d8de87370cebaefc8b0b33fb9206806d3b3
Author: Joseph Eagar
Date: Sun Oct 18 16:12:02 2020 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB49f57d8de87370cebaefc8b0b33fb9206806d3b3
COde cleanup
===================================================================
M source/blender/blenkernel/intern/mesh.c
M source/blender/blenkernel/intern/multires.c
M source/blender/blenkernel/intern/pbvh.c
M source/blender/blenkernel/intern/subdiv_ccg.c
M source/blender/blenkernel/intern/subdiv_displacement_multires.c
M source/blender/editors/mesh/editmesh_tools.c
===================================================================
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 24e800be379..15589e13017 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -1016,7 +1016,6 @@ Mesh *BKE_mesh_copy_for_eval(struct Mesh *source, bool reference)
}
BMesh *BKE_mesh_to_bmesh_ex(const Mesh *me,
- const Object *ob,
const struct BMeshCreateParams *create_params,
const struct BMeshFromMeshParams *convert_params)
{
@@ -1024,7 +1023,7 @@ BMesh *BKE_mesh_to_bmesh_ex(const Mesh *me,
const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me);
bm = BM_mesh_create(&allocsize, create_params);
- BM_mesh_bm_from_me(ob, bm, me, convert_params);
+ BM_mesh_bm_from_me(NULL, bm, me, convert_params);
return bm;
}
@@ -1035,7 +1034,6 @@ BMesh *BKE_mesh_to_bmesh(Mesh *me,
const struct BMeshCreateParams *params)
{
return BKE_mesh_to_bmesh_ex(me,
- ob,
params,
&(struct BMeshFromMeshParams){
.calc_face_normal = false,
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index 09de551fec5..d069386b7a1 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -39,12 +39,12 @@
#include "BLI_utildefines.h"
#include "BKE_ccg.h"
-#include "BKE_collection.h"
-#include "BKE_layer.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_editmesh.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
@@ -997,7 +997,6 @@ static void grid_tangent(const CCGKey *key, int x, int y, int axis, CCGElem *gri
}
}
-
/* Construct 3x3 tangent-space matrix in 'mat' */
static void grid_tangent_matrix(float mat[3][3], const CCGKey *key, int x, int y, CCGElem *grid)
{
@@ -1023,22 +1022,23 @@ typedef struct MultiresThreadedData {
MDisps *mdisps;
GridPaintMask *grid_paint_mask;
int *gridOffset;
- int cd_mdisps_off;
+ int cd_mdisps_off, cd_mask_off;
int gridSize, dGridSize, dSkip;
float (*smat)[3];
+ bool has_grid_mask;
} MultiresThreadedData;
-Object *multires_dump_grids_bmesh(BMesh *bm)
+Object *multires_dump_grids_bmesh(Object *bmob, BMesh *bm)
{
if (!CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
printf("multires_dump_grids_bmesh: error: no multires grids\n");
- return;
+ return NULL;
}
bool spaceset = false;
if (bm->multiresSpace != MULTIRES_SPACE_ABSOLUTE) {
- BKE_multires_bmesh_space_set(NULL, bm, MULTIRES_SPACE_ABSOLUTE);
+ BKE_multires_bmesh_space_set(bmob, bm, MULTIRES_SPACE_ABSOLUTE);
spaceset = true;
}
@@ -1050,16 +1050,14 @@ Object *multires_dump_grids_bmesh(BMesh *bm)
CTX_wm_manager_set(ctx, G.main->wm.first);
CTX_data_scene_set(ctx, G.main->scenes.first);
- Scene *scene = CTX_data_scene(ctx);
ViewLayer *view_layer = CTX_data_view_layer(ctx);
Object *ob = BKE_object_add_only_object(bmain, OB_MESH, name);
- Base *base;
LayerCollection *layer_collection;
ob->data = BKE_object_obdata_add_from_type(bmain, OB_MESH, name);
DEG_id_tag_update_ex(
bmain, &ob->id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
- //DEG_id_tag_update_ex(
+ // DEG_id_tag_update_ex(
// bmain, &ob->data, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY | ID_RECALC_ANIMATION);
layer_collection = BKE_layer_collection_get_active(view_layer);
@@ -1079,8 +1077,6 @@ Object *multires_dump_grids_bmesh(BMesh *bm)
Mesh *me = ob->data;
BMIter iter;
- BMVert *v;
- BMEdge *e;
BMFace *f;
int cd_mdisp_off = CustomData_get_offset(&bm->ldata, CD_MDISPS);
@@ -1095,7 +1091,7 @@ Object *multires_dump_grids_bmesh(BMesh *bm)
if (!dimen) {
printf("multires_dump_grids_bmesh: error: corrupted multires data\n");
- return;
+ return NULL;
}
int totvert = bm->totloop * dimen * dimen;
@@ -1161,9 +1157,9 @@ Object *multires_dump_grids_bmesh(BMesh *bm)
copy_v3_v3(mv->co, co);
}
}
-
- for (int i = 0; i < dimen-1; i++) {
- for (int j = 0; j < dimen-1; j++) {
+
+ for (int i = 0; i < dimen - 1; i++) {
+ for (int j = 0; j < dimen - 1; j++) {
// do face
int fidx = loopi * (dimen - 1) * (dimen - 1) + (j * (dimen - 1) + i);
MPoly *mp = mpoly + fidx;
@@ -1178,12 +1174,12 @@ Object *multires_dump_grids_bmesh(BMesh *bm)
ml[2].v = VINDEX(i + 1, j + 1);
ml[3].v = VINDEX(i + 1, j);
- for (int i2=0; i2<4; i2++) {
- int a = ml[i2].v, b = ml[(i2+1) % 4].v;
+ for (int i2 = 0; i2 < 4; i2++) {
+ int a = ml[i2].v, b = ml[(i2 + 1) % 4].v;
int e;
if (!BLI_edgehash_haskey(eh, a, b)) {
- BLI_edgehash_insert(eh, a, b, (void*)medi);
+ BLI_edgehash_insert(eh, a, b, (void *)medi);
e = medi;
MEdge *med = medge + medi;
@@ -1192,7 +1188,8 @@ Object *multires_dump_grids_bmesh(BMesh *bm)
med->v2 = b;
medi++;
- } else {
+ }
+ else {
e = (int)BLI_edgehash_lookup(eh, a, b);
}
@@ -1208,21 +1205,24 @@ Object *multires_dump_grids_bmesh(BMesh *bm)
} while (l != f->l_first);
}
- for (int i=0; i<me->totpoly; i++) {
+ for (int i = 0; i < me->totpoly; i++) {
if (!mpoly[i].totloop) {
printf("error 1! %d %d\n", i, me->totpoly);
}
if (mpoly[i].loopstart >= me->totloop) {
- printf("error 2! %d %d l: %d totl: %d\n", i, me->totpoly, mpoly[i].loopstart, mpoly[i].totloop);
+ printf(
+ "error 2! %d %d l: %d totl: %d\n", i, me->totpoly, mpoly[i].loopstart, mpoly[i].totloop);
}
}
if (spaceset) {
- BKE_multires_bmesh_space_set(NULL, bm, MULTIRES_SPACE_TANGENT);
+ BKE_multires_bmesh_space_set(bmob, bm, MULTIRES_SPACE_TANGENT);
}
BKE_mesh_calc_normals(me);
BKE_mesh_tessface_calc(me);
+
+ return ob;
}
static void multires_bmesh_space_set_cb(void *__restrict userdata,
@@ -1232,27 +1232,20 @@ static void multires_bmesh_space_set_cb(void *__restrict userdata,
MultiresThreadedData *tdata = userdata;
int cd_mdisps_off = tdata->cd_mdisps_off;
+ // int cd_mask_off = tdata->cd_mask_off;
BMesh *bm = tdata->bm;
MultiResSpace op = tdata->bmop;
- CCGElem **gridData = tdata->gridData;
- CCGElem **subGridData = tdata->subGridData;
- CCGKey *key = tdata->key;
BMFace *f = bm->ftable[pidx];
- MDisps *mdisps = tdata->mdisps;
- GridPaintMask *grid_paint_mask = tdata->grid_paint_mask;
- int *gridOffset = tdata->gridOffset;
int gridSize = tdata->gridSize;
- int dGridSize = tdata->dGridSize;
- int dSkip = tdata->dSkip;
- int S, x, y, gIndex = gridOffset[pidx];
+ int S, x, y;
BMLoop *l = f->l_first;
float cent[3];
int tot = 0;
+ // get face center to calculate maximum allowable displacement length
zero_v3(cent);
-
do {
add_v3_v3(cent, l->v->co);
tot++;
@@ -1261,47 +1254,33 @@ static void multires_bmesh_space_set_cb(void *__restrict userdata,
mul_v3_fl(cent, 1.0f / (float)tot);
- float simplemat[3][3];
+ // bool has_grid_mask = tdata->has_grid_mask;
l = f->l_first;
S = 0;
do {
- // for (S = 0; S < numVerts; S++, gIndex++) {
-
- GridPaintMask *gpm = grid_paint_mask ? &grid_paint_mask[gIndex] : NULL;
- MDisps *mdisp = BM_ELEM_CD_GET_VOID_P(l, cd_mdisps_off); //&mdisps[mpoly[pidx].loopstart + S];
- CCGElem *grid = gridData[gIndex];
- CCGElem *subgrid = subGridData[gIndex];
+ // GridPaintMask *gpm = has_grid_mask ? BM_ELEM_CD_GET_VOID_P(l, cd_mask_off) : NULL;
+ MDisps *mdisp = BM_ELEM_CD_GET_VOID_P(l, cd_mdisps_off);
float(*dispgrid)[3] = NULL;
dispgrid = mdisp->disps;
- float quad[4][3];
-
- // copy_v3_v3(quad[0], cent);
- // interp_v3_v3v3(quad[1], l->v->co, l->next->v->co, 0.5);
- // copy_v3_v3(quad[2], l->v->co);
- // interp_v3_v3v3(quad[3], l->v->co, l->prev->v->co, 0.5);
float maxlen = len_v3v3(l->v->co, cent) * 15.0f;
maxlen = MAX2(maxlen, 0.00001f);
for (y = 0; y < gridSize; y++) {
for (x = 0; x < gridSize; x++) {
- // float *sco = CCG_grid_elem_co(key, grid, x, y);
- // float *sco = CCG_grid_elem_co(key, subgrid, x, y);
float sco[8], udv[3], vdv[3];
- float *data = dispgrid[dGridSize * y * dSkip + x * dSkip];
- float mat[3][3], disp[3], d[3], mask;
- // float baseco[3];
+ float *data = dispgrid[gridSize * y + x];
+ float mat[3][3], disp[3];
- float grid_u = (float)x / (float)(dGridSize - 1);
- float grid_v = (float)y / (float)(dGridSize - 1);
+ float grid_u = (float)x / (float)(gridSize - 1);
+ float grid_v = (float)y / (float)(gridSize - 1);
float u, v;
int corner = S;
if (f->len == 4) {
BKE_subdiv_rotate_grid_to_quad(corner, grid_u, grid_v, &u, &v);
- // continue;
}
else {
u = 1.0 - grid_v;
@@ -1319,7 +1298,6 @@ static void multires_bmesh_space_set_cb(void *__restrict userdata,
* and add to grid points */
mul_v3_m3v3(disp, mat, data);
add_v3_v3v3(data, disp, sco);
- //copy_v3_v3(data, sco);
break;
case MULTIRES_SPACE_TANGENT:
/* Calculate displacement between new and old
@@ -1329,17 +1307,20 @@ static void multires_bmesh_space_set_cb(void *__restrict userdata,
sub_v3_v3v3(disp, data, sco);
mul_v3_m3v3(data, mat, disp);
- // float len = len_v3(data);
- // if (len > maxlen) {
- // mul_v3_fl(data, maxlen/len);
- //}
+ // try to prevent errors
+ float len = len_v3(data);
+ /*
+ if (len > maxlen) {
+ mul_v3_fl(data, maxlen/len);
+ } else if (isnan(len)) {
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list