Some multires stuff

This commit is contained in:
Joseph Eagar 2020-11-18 18:34:08 -08:00
parent a1ac104f02
commit f30225725d
4 changed files with 65 additions and 24 deletions

View File

@ -48,6 +48,39 @@
#include "atomic_ops.h"
#include "subdiv_converter.h"
bool debug_invert_m3_m3(float m1[3][3], const float m2[3][3], const char *func, int line)
{
float det;
int a, b;
bool success;
/* calc adjoint */
adjoint_m3_m3(m1, m2);
/* then determinant old matrix! */
det = determinant_m3_array(m2);
if (det > -0.0001 && det < 0.0001) {
fprintf(stderr, "matrix inverse error %s:%i\n\n", func, line);
}
success = (det != 0.0f);
if (LIKELY(det != 0.0f)) {
det = 1.0f / det;
for (a = 0; a < 3; a++) {
for (b = 0; b < 3; b++) {
m1[a][b] *= det;
}
}
}
return success;
}
//#define invert_m3_m3(m1, m2) debug_invert_m3_m3(m1, m2, __func__, __LINE__)
/* -------------------------------------------------------------------- */
/** \name Local Structs
* \{ */

View File

@ -326,8 +326,8 @@ static bool quad_co(const float v1[3],
}
// expand quad a bit
#if 1
float eps = FLT_EPSILON * 400000;
#if 0
float eps = FLT_EPSILON * 40000;
float c[3];
mid_v3_v3v3v3v3(c, projverts[0], projverts[1], projverts[2], projverts[3]);
@ -352,9 +352,12 @@ static bool quad_co(const float v1[3],
resolve_quad_uv_v2(r_uv, origin, projverts[0], projverts[3], projverts[2], projverts[1]);
// if (r_uv[0] < -eps || r_uv[1] < -eps || r_uv[0] > 1.0+eps || r_uv[1] > 1.0+eps) {
// return false;
//}
#if 0
float eps2 = FLT_EPSILON * 4000;
if (r_uv[0] < -eps2 || r_uv[1] < -eps2 || r_uv[0] > 1.0 + eps2 || r_uv[1] > 1.0 + eps2) {
return false;
}
#endif
CLAMP(r_uv[0], 0.0f, 0.99999f);
CLAMP(r_uv[1], 0.0f, 0.99999f);
@ -943,12 +946,12 @@ void bmo_test_mres_smooth_exec(BMesh *bm, BMOperator *op)
continue;
}
//bm_multires_smooth(bm, f, true);
// bm_multires_smooth(bm, f, true);
// BM_multires_smooth(bm, f, false);
// BM_multires_smooth(bm, f, false);
//for (int i=0; i<5; i++) {
// for (int i=0; i<5; i++) {
BM_face_multires_bounds_smooth(bm, f);
// }
// }
}
multires_dump_grids_bmesh(NULL, bm);
@ -960,9 +963,8 @@ void BM_face_multires_bounds_smooth(BMesh *bm, BMFace *f)
if (bm->multiresSpace == MULTIRES_SPACE_ABSOLUTE) {
BM_face_multires_stitch(bm, f);
//for (int i=0; i<5; i++) {
//bm_multires_smooth(bm, f, true);
// for (int i=0; i<5; i++) {
// bm_multires_smooth(bm, f, true);
//}
}
}

View File

@ -6936,6 +6936,8 @@ static const char *sculpt_tool_name(Sculpt *sd)
return "Paint Brush";
case SCULPT_TOOL_SMEAR:
return "Smear Brush";
case SCULPT_TOOL_VCOL_BOUNDARY:
return "Color Boundary";
}
return "Sculpting";

View File

@ -183,14 +183,14 @@ static bool sculpt_undo_restore_deformed(
return false;
}
static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, SculptUndoNode *unode)
__attribute__((optnone)) static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, SculptUndoNode *unode)
{
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = OBACT(view_layer);
SculptSession *ss = ob->sculpt;
SubdivCCG *subdiv_ccg = ss->subdiv_ccg;
MVert *mvert;
int *index;
SculptVertRef *index;
if (unode->maxvert) {
/* Regular mesh restore. */
@ -224,18 +224,18 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
if (unode->orig_co) {
if (ss->deform_modifiers_active) {
for (int i = 0; i < unode->totvert; i++) {
sculpt_undo_restore_deformed(ss, unode, i, index[i], vertCos[index[i]]);
sculpt_undo_restore_deformed(ss, unode, i, index[i].i, vertCos[index[i].i]);
}
}
else {
for (int i = 0; i < unode->totvert; i++) {
swap_v3_v3(vertCos[index[i]], unode->orig_co[i]);
swap_v3_v3(vertCos[index[i].i], unode->orig_co[i]);
}
}
}
else {
for (int i = 0; i < unode->totvert; i++) {
swap_v3_v3(vertCos[index[i]], unode->co[i]);
swap_v3_v3(vertCos[index[i].i], unode->co[i]);
}
}
@ -252,21 +252,21 @@ static bool sculpt_undo_restore_coords(bContext *C, Depsgraph *depsgraph, Sculpt
if (unode->orig_co) {
if (ss->deform_modifiers_active) {
for (int i = 0; i < unode->totvert; i++) {
sculpt_undo_restore_deformed(ss, unode, i, index[i], mvert[index[i]].co);
mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
sculpt_undo_restore_deformed(ss, unode, i, index[i].i, mvert[index[i].i].co);
mvert[index[i].i].flag |= ME_VERT_PBVH_UPDATE;
}
}
else {
for (int i = 0; i < unode->totvert; i++) {
swap_v3_v3(mvert[index[i]].co, unode->orig_co[i]);
mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
swap_v3_v3(mvert[index[i].i].co, unode->orig_co[i]);
mvert[index[i].i].flag |= ME_VERT_PBVH_UPDATE;
}
}
}
else {
for (int i = 0; i < unode->totvert; i++) {
swap_v3_v3(mvert[index[i]].co, unode->co[i]);
mvert[index[i]].flag |= ME_VERT_PBVH_UPDATE;
swap_v3_v3(mvert[index[i].i].co, unode->co[i]);
mvert[index[i].i].flag |= ME_VERT_PBVH_UPDATE;
}
}
}
@ -1072,7 +1072,7 @@ static SculptUndoNode *sculpt_undo_alloc_node(Object *ob, PBVHNode *node, Sculpt
else {
/* Regular mesh. */
unode->maxvert = ss->totvert;
unode->index = MEM_callocN(sizeof(int) * allvert, "SculptUndoNode.index");
unode->index = MEM_callocN(sizeof(SculptVertRef) * allvert, "SculptUndoNode.index");
}
if (ss->deform_modifiers_active) {
@ -1418,7 +1418,11 @@ SculptUndoNode *SCULPT_undo_push_node(Object *ob, PBVHNode *node, SculptUndoType
int allvert;
BKE_pbvh_node_num_verts(ss->pbvh, node, NULL, &allvert);
BKE_pbvh_node_get_verts(ss->pbvh, node, &vert_indices, NULL);
memcpy(unode->index, vert_indices, sizeof(int) * unode->totvert);
for (int i=0; i<unode->totvert; i++) {
unode->index[i].i = vert_indices[i];
}
//memcpy(unode->index, vert_indices, sizeof(int) * unode->totvert);
}
switch (type) {