Modifiers: Simple Deform & Build, DerivedMesh → Mesh
This commit introduces `EditMeshData`. The fields in this struct are extracted from `EditDerivedBMesh` into their own struct `EditMeshData`, which can then also be used by the `Mesh` struct. This allows passing deformed vertices efficiently to the draw routines. The modifier code constructs a new Mesh instead of writing to ob->data; even when ob->data is a CoW copy, it can still be used by different objects and thus shouldn't be modified by a modifier.
This commit is contained in:
@@ -93,6 +93,14 @@ struct Mesh *BKE_mesh_copy(struct Main *bmain, const struct Mesh *me);
|
||||
void BKE_mesh_update_customdata_pointers(struct Mesh *me, const bool do_ensure_tess_cd);
|
||||
void BKE_mesh_ensure_skin_customdata(struct Mesh *me);
|
||||
|
||||
struct Mesh * BKE_mesh_from_template(
|
||||
struct Mesh *me_src,
|
||||
int numVerts, int numEdges, int numTessFaces,
|
||||
int numLoops, int numPolys);
|
||||
|
||||
bool BKE_mesh_ensure_edit_data(struct Mesh *me);
|
||||
bool BKE_mesh_clear_edit_data(struct Mesh *me);
|
||||
|
||||
bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me);
|
||||
bool BKE_mesh_clear_facemap_customdata(struct Mesh *me);
|
||||
|
||||
|
@@ -1162,7 +1162,10 @@ DerivedMesh *mesh_create_derived_for_modifier(
|
||||
|
||||
if (mti->type == eModifierTypeType_OnlyDeform) {
|
||||
int numVerts;
|
||||
float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, &numVerts);
|
||||
/* Always get the vertex coordinates from the original mesh. Otherwise
|
||||
* there is the risk of deforming already-deformed coordinates. */
|
||||
Mesh *mesh_orig_id = (Mesh *)DEG_get_original_id(&me->id);
|
||||
float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
|
||||
|
||||
modwrap_deformVerts(md, depsgraph, ob, NULL, deformedVerts, numVerts, 0);
|
||||
dm = mesh_create_derived(me, deformedVerts);
|
||||
@@ -1748,6 +1751,9 @@ static void mesh_calc_modifiers(
|
||||
DerivedMesh **r_deform, DerivedMesh **r_final)
|
||||
{
|
||||
Mesh *me = ob->data;
|
||||
/* Always get the vertex coordinates from the original mesh. Otherwise
|
||||
* there is the risk of deforming already-deformed coordinates. */
|
||||
Mesh *mesh_orig_id = (Mesh *)DEG_get_original_id(&me->id);
|
||||
ModifierData *firstmd, *md, *previewmd = NULL;
|
||||
CDMaskLink *datamasks, *curr;
|
||||
/* XXX Always copying POLYINDEX, else tessellated data are no more valid! */
|
||||
@@ -1837,7 +1843,7 @@ static void mesh_calc_modifiers(
|
||||
|
||||
if (mti->type == eModifierTypeType_OnlyDeform && !sculpt_dyntopo) {
|
||||
if (!deformedVerts)
|
||||
deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
|
||||
deformedVerts = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
|
||||
|
||||
modwrap_deformVerts(md, depsgraph, ob, NULL, deformedVerts, numVerts, deform_app_flags);
|
||||
}
|
||||
@@ -1870,7 +1876,7 @@ static void mesh_calc_modifiers(
|
||||
if (inputVertexCos)
|
||||
deformedVerts = inputVertexCos;
|
||||
else
|
||||
deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
|
||||
deformedVerts = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
|
||||
}
|
||||
|
||||
|
||||
@@ -1967,7 +1973,7 @@ static void mesh_calc_modifiers(
|
||||
dm->getVertCos(dm, deformedVerts);
|
||||
}
|
||||
else {
|
||||
deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
|
||||
deformedVerts = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2467,6 +2473,11 @@ static void editbmesh_calc_modifiers(
|
||||
*r_cage = dm;
|
||||
}
|
||||
else {
|
||||
struct Mesh *mesh = ob->data;
|
||||
if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) {
|
||||
BKE_mesh_ensure_edit_data(mesh);
|
||||
mesh->emd->vertexCos = MEM_dupallocN(deformedVerts);
|
||||
}
|
||||
*r_cage = getEditDerivedBMesh(
|
||||
em, ob, mask,
|
||||
deformedVerts ? MEM_dupallocN(deformedVerts) : NULL);
|
||||
@@ -2504,6 +2515,13 @@ static void editbmesh_calc_modifiers(
|
||||
}
|
||||
else {
|
||||
/* this is just a copy of the editmesh, no need to calc normals */
|
||||
struct Mesh *mesh = ob->data;
|
||||
if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) {
|
||||
BKE_mesh_ensure_edit_data(mesh);
|
||||
if (mesh->emd->vertexCos != NULL)
|
||||
MEM_freeN((void *)mesh->emd->vertexCos);
|
||||
mesh->emd->vertexCos = MEM_dupallocN(deformedVerts);
|
||||
}
|
||||
*r_final = getEditDerivedBMesh(em, ob, dataMask, deformedVerts);
|
||||
deformedVerts = NULL;
|
||||
|
||||
|
@@ -56,6 +56,7 @@
|
||||
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -64,14 +65,7 @@ typedef struct EditDerivedBMesh {
|
||||
|
||||
BMEditMesh *em;
|
||||
|
||||
/** when set, \a vertexNos, polyNos are lazy initialized */
|
||||
const float (*vertexCos)[3];
|
||||
|
||||
/** lazy initialize (when \a vertexCos is set) */
|
||||
float const (*vertexNos)[3];
|
||||
float const (*polyNos)[3];
|
||||
/** also lazy init but dont depend on \a vertexCos */
|
||||
const float (*polyCos)[3];
|
||||
EditMeshData emd;
|
||||
} EditDerivedBMesh;
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
@@ -81,7 +75,7 @@ static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm);
|
||||
|
||||
static void emDM_ensureVertNormals(EditDerivedBMesh *bmdm)
|
||||
{
|
||||
if (bmdm->vertexCos && (bmdm->vertexNos == NULL)) {
|
||||
if (bmdm->emd.vertexCos && (bmdm->emd.vertexNos == NULL)) {
|
||||
|
||||
BMesh *bm = bmdm->em->bm;
|
||||
const float (*vertexCos)[3], (*polyNos)[3];
|
||||
@@ -92,19 +86,19 @@ static void emDM_ensureVertNormals(EditDerivedBMesh *bmdm)
|
||||
|
||||
BM_mesh_elem_index_ensure(bm, BM_FACE);
|
||||
|
||||
polyNos = bmdm->polyNos;
|
||||
vertexCos = bmdm->vertexCos;
|
||||
polyNos = bmdm->emd.polyNos;
|
||||
vertexCos = bmdm->emd.vertexCos;
|
||||
vertexNos = MEM_callocN(sizeof(*vertexNos) * bm->totvert, __func__);
|
||||
|
||||
BM_verts_calc_normal_vcos(bm, polyNos, vertexCos, vertexNos);
|
||||
|
||||
bmdm->vertexNos = (const float (*)[3])vertexNos;
|
||||
bmdm->emd.vertexNos = (const float (*)[3])vertexNos;
|
||||
}
|
||||
}
|
||||
|
||||
static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm)
|
||||
{
|
||||
if (bmdm->vertexCos && (bmdm->polyNos == NULL)) {
|
||||
if (bmdm->emd.vertexCos && (bmdm->emd.polyNos == NULL)) {
|
||||
BMesh *bm = bmdm->em->bm;
|
||||
const float (*vertexCos)[3];
|
||||
float (*polyNos)[3];
|
||||
@@ -117,7 +111,7 @@ static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm)
|
||||
|
||||
polyNos = MEM_mallocN(sizeof(*polyNos) * bm->totface, __func__);
|
||||
|
||||
vertexCos = bmdm->vertexCos;
|
||||
vertexCos = bmdm->emd.vertexCos;
|
||||
|
||||
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
|
||||
BM_elem_index_set(efa, i); /* set_inline */
|
||||
@@ -125,13 +119,13 @@ static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm)
|
||||
}
|
||||
bm->elem_index_dirty &= ~BM_FACE;
|
||||
|
||||
bmdm->polyNos = (const float (*)[3])polyNos;
|
||||
bmdm->emd.polyNos = (const float (*)[3])polyNos;
|
||||
}
|
||||
}
|
||||
|
||||
static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm)
|
||||
{
|
||||
if (bmdm->polyCos == NULL) {
|
||||
if (bmdm->emd.polyCos == NULL) {
|
||||
BMesh *bm = bmdm->em->bm;
|
||||
float (*polyCos)[3];
|
||||
|
||||
@@ -141,9 +135,9 @@ static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm)
|
||||
|
||||
polyCos = MEM_mallocN(sizeof(*polyCos) * bm->totface, __func__);
|
||||
|
||||
if (bmdm->vertexCos) {
|
||||
if (bmdm->emd.vertexCos) {
|
||||
const float (*vertexCos)[3];
|
||||
vertexCos = bmdm->vertexCos;
|
||||
vertexCos = bmdm->emd.vertexCos;
|
||||
|
||||
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
||||
|
||||
@@ -157,7 +151,7 @@ static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm)
|
||||
}
|
||||
}
|
||||
|
||||
bmdm->polyCos = (const float (*)[3])polyCos;
|
||||
bmdm->emd.polyCos = (const float (*)[3])polyCos;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,9 +187,9 @@ static void emDM_calcLoopNormalsSpaceArray(
|
||||
emDM_ensurePolyNormals(bmdm);
|
||||
dm->dirty &= ~DM_DIRTY_NORMALS;
|
||||
|
||||
vertexCos = bmdm->vertexCos;
|
||||
vertexNos = bmdm->vertexNos;
|
||||
polyNos = bmdm->polyNos;
|
||||
vertexCos = bmdm->emd.vertexCos;
|
||||
vertexNos = bmdm->emd.vertexNos;
|
||||
polyNos = bmdm->emd.polyNos;
|
||||
|
||||
loopNos = dm->getLoopDataArray(dm, CD_NORMAL);
|
||||
if (!loopNos) {
|
||||
@@ -247,7 +241,7 @@ static void emDM_calc_loop_tangents(
|
||||
return;
|
||||
}
|
||||
|
||||
const float (*poly_normals)[3] = bmdm->polyNos;
|
||||
const float (*poly_normals)[3] = bmdm->emd.polyNos;
|
||||
const float (*loop_normals)[3] = CustomData_get_layer(&dm->loopData, CD_NORMAL);
|
||||
const float (*vert_orco)[3] = dm->getVertDataArray(dm, CD_ORCO); /* can be NULL */
|
||||
BKE_editmesh_loop_tangent_calc(
|
||||
@@ -311,13 +305,13 @@ static void emDM_foreachMappedVert(
|
||||
BMIter iter;
|
||||
int i;
|
||||
|
||||
if (bmdm->vertexCos) {
|
||||
const float (*vertexCos)[3] = bmdm->vertexCos;
|
||||
if (bmdm->emd.vertexCos) {
|
||||
const float (*vertexCos)[3] = bmdm->emd.vertexCos;
|
||||
const float (*vertexNos)[3];
|
||||
|
||||
if (flag & DM_FOREACH_USE_NORMAL) {
|
||||
emDM_ensureVertNormals(bmdm);
|
||||
vertexNos = bmdm->vertexNos;
|
||||
vertexNos = bmdm->emd.vertexNos;
|
||||
}
|
||||
else {
|
||||
vertexNos = NULL;
|
||||
@@ -346,14 +340,14 @@ static void emDM_foreachMappedEdge(
|
||||
BMIter iter;
|
||||
int i;
|
||||
|
||||
if (bmdm->vertexCos) {
|
||||
if (bmdm->emd.vertexCos) {
|
||||
|
||||
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
||||
|
||||
BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
|
||||
func(userData, i,
|
||||
bmdm->vertexCos[BM_elem_index_get(eed->v1)],
|
||||
bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
|
||||
bmdm->emd.vertexCos[BM_elem_index_get(eed->v1)],
|
||||
bmdm->emd.vertexCos[BM_elem_index_get(eed->v2)]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -378,7 +372,7 @@ static void emDM_foreachMappedLoop(
|
||||
BMFace *efa;
|
||||
BMIter iter;
|
||||
|
||||
const float (*vertexCos)[3] = bmdm->vertexCos;
|
||||
const float (*vertexCos)[3] = bmdm->emd.vertexCos;
|
||||
int f_idx;
|
||||
|
||||
BM_mesh_elem_index_ensure(bm, BM_VERT);
|
||||
@@ -411,11 +405,11 @@ static void emDM_foreachMappedFaceCenter(
|
||||
int i;
|
||||
|
||||
emDM_ensurePolyCenters(bmdm);
|
||||
polyCos = bmdm->polyCos; /* always set */
|
||||
polyCos = bmdm->emd.polyCos; /* always set */
|
||||
|
||||
if (flag & DM_FOREACH_USE_NORMAL) {
|
||||
emDM_ensurePolyNormals(bmdm);
|
||||
polyNos = bmdm->polyNos; /* maybe NULL */
|
||||
polyNos = bmdm->emd.polyNos; /* maybe NULL */
|
||||
}
|
||||
else {
|
||||
polyNos = NULL;
|
||||
@@ -444,9 +438,9 @@ static void emDM_getMinMax(DerivedMesh *dm, float r_min[3], float r_max[3])
|
||||
int i;
|
||||
|
||||
if (bm->totvert) {
|
||||
if (bmdm->vertexCos) {
|
||||
if (bmdm->emd.vertexCos) {
|
||||
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
||||
minmax_v3v3_v3(r_min, r_max, bmdm->vertexCos[i]);
|
||||
minmax_v3v3_v3(r_min, r_max, bmdm->emd.vertexCos[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -526,8 +520,8 @@ static void emDM_getVert(DerivedMesh *dm, int index, MVert *r_vert)
|
||||
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
|
||||
|
||||
bmvert_to_mvert(bm, ev, r_vert);
|
||||
if (bmdm->vertexCos)
|
||||
copy_v3_v3(r_vert->co, bmdm->vertexCos[index]);
|
||||
if (bmdm->emd.vertexCos)
|
||||
copy_v3_v3(r_vert->co, bmdm->emd.vertexCos[index]);
|
||||
}
|
||||
|
||||
static void emDM_getVertCo(DerivedMesh *dm, int index, float r_co[3])
|
||||
@@ -540,8 +534,8 @@ static void emDM_getVertCo(DerivedMesh *dm, int index, float r_co[3])
|
||||
return;
|
||||
}
|
||||
|
||||
if (bmdm->vertexCos) {
|
||||
copy_v3_v3(r_co, bmdm->vertexCos[index]);
|
||||
if (bmdm->emd.vertexCos) {
|
||||
copy_v3_v3(r_co, bmdm->emd.vertexCos[index]);
|
||||
}
|
||||
else {
|
||||
BMVert *ev;
|
||||
@@ -564,9 +558,9 @@ static void emDM_getVertNo(DerivedMesh *dm, int index, float r_no[3])
|
||||
}
|
||||
|
||||
|
||||
if (bmdm->vertexCos) {
|
||||
if (bmdm->emd.vertexCos) {
|
||||
emDM_ensureVertNormals(bmdm);
|
||||
copy_v3_v3(r_no, bmdm->vertexNos[index]);
|
||||
copy_v3_v3(r_no, bmdm->emd.vertexNos[index]);
|
||||
}
|
||||
else {
|
||||
BMVert *ev;
|
||||
@@ -588,9 +582,9 @@ static void emDM_getPolyNo(DerivedMesh *dm, int index, float r_no[3])
|
||||
return;
|
||||
}
|
||||
|
||||
if (bmdm->vertexCos) {
|
||||
if (bmdm->emd.vertexCos) {
|
||||
emDM_ensurePolyNormals(bmdm);
|
||||
copy_v3_v3(r_no, bmdm->polyNos[index]);
|
||||
copy_v3_v3(r_no, bmdm->emd.polyNos[index]);
|
||||
}
|
||||
else {
|
||||
BMFace *efa;
|
||||
@@ -665,11 +659,11 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *r_vert)
|
||||
BMIter iter;
|
||||
const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
|
||||
|
||||
if (bmdm->vertexCos) {
|
||||
if (bmdm->emd.vertexCos) {
|
||||
int i;
|
||||
|
||||
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
||||
copy_v3_v3(r_vert->co, bmdm->vertexCos[i]);
|
||||
copy_v3_v3(r_vert->co, bmdm->emd.vertexCos[i]);
|
||||
normal_float_to_short_v3(r_vert->no, eve->no);
|
||||
r_vert->flag = BM_vert_flag_to_mflag(eve);
|
||||
|
||||
@@ -873,9 +867,9 @@ static void emDM_getVertCos(DerivedMesh *dm, float (*r_cos)[3])
|
||||
BMIter iter;
|
||||
int i;
|
||||
|
||||
if (bmdm->vertexCos) {
|
||||
if (bmdm->emd.vertexCos) {
|
||||
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
|
||||
copy_v3_v3(r_cos[i], bmdm->vertexCos[i]);
|
||||
copy_v3_v3(r_cos[i], bmdm->emd.vertexCos[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -890,18 +884,18 @@ static void emDM_release(DerivedMesh *dm)
|
||||
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
|
||||
|
||||
if (DM_release(dm)) {
|
||||
if (bmdm->vertexCos) {
|
||||
MEM_freeN((void *)bmdm->vertexCos);
|
||||
if (bmdm->vertexNos) {
|
||||
MEM_freeN((void *)bmdm->vertexNos);
|
||||
if (bmdm->emd.vertexCos) {
|
||||
MEM_freeN((void *)bmdm->emd.vertexCos);
|
||||
if (bmdm->emd.vertexNos) {
|
||||
MEM_freeN((void *)bmdm->emd.vertexNos);
|
||||
}
|
||||
if (bmdm->polyNos) {
|
||||
MEM_freeN((void *)bmdm->polyNos);
|
||||
if (bmdm->emd.polyNos) {
|
||||
MEM_freeN((void *)bmdm->emd.polyNos);
|
||||
}
|
||||
}
|
||||
|
||||
if (bmdm->polyCos) {
|
||||
MEM_freeN((void *)bmdm->polyCos);
|
||||
if (bmdm->emd.polyCos) {
|
||||
MEM_freeN((void *)bmdm->emd.polyCos);
|
||||
}
|
||||
|
||||
MEM_freeN(bmdm);
|
||||
@@ -1006,7 +1000,7 @@ DerivedMesh *getEditDerivedBMesh(
|
||||
|
||||
bmdm->dm.release = emDM_release;
|
||||
|
||||
bmdm->vertexCos = (const float (*)[3])vertexCos;
|
||||
bmdm->emd.vertexCos = (const float (*)[3])vertexCos;
|
||||
bmdm->dm.deformedOnly = (vertexCos != NULL);
|
||||
|
||||
const int cd_dvert_offset = (data_mask & CD_MASK_MDEFORMVERT) ?
|
||||
@@ -1434,7 +1428,7 @@ void BKE_editmesh_statvis_calc(
|
||||
{
|
||||
BKE_editmesh_color_ensure(em, BM_FACE);
|
||||
statvis_calc_overhang(
|
||||
em, bmdm ? bmdm->polyNos : NULL,
|
||||
em, bmdm ? bmdm->emd.polyNos : NULL,
|
||||
statvis->overhang_min / (float)M_PI,
|
||||
statvis->overhang_max / (float)M_PI,
|
||||
statvis->overhang_axis,
|
||||
@@ -1446,7 +1440,7 @@ void BKE_editmesh_statvis_calc(
|
||||
const float scale = 1.0f / mat4_to_scale(em->ob->obmat);
|
||||
BKE_editmesh_color_ensure(em, BM_FACE);
|
||||
statvis_calc_thickness(
|
||||
em, bmdm ? bmdm->vertexCos : NULL,
|
||||
em, bmdm ? bmdm->emd.vertexCos : NULL,
|
||||
statvis->thickness_min * scale,
|
||||
statvis->thickness_max * scale,
|
||||
statvis->thickness_samples,
|
||||
@@ -1457,7 +1451,7 @@ void BKE_editmesh_statvis_calc(
|
||||
{
|
||||
BKE_editmesh_color_ensure(em, BM_FACE);
|
||||
statvis_calc_intersect(
|
||||
em, bmdm ? bmdm->vertexCos : NULL,
|
||||
em, bmdm ? bmdm->emd.vertexCos : NULL,
|
||||
em->derivedFaceColor);
|
||||
break;
|
||||
}
|
||||
@@ -1469,7 +1463,7 @@ void BKE_editmesh_statvis_calc(
|
||||
emDM_ensurePolyNormals(bmdm);
|
||||
|
||||
statvis_calc_distort(
|
||||
em, bmdm ? bmdm->vertexCos : NULL, bmdm ? bmdm->polyNos : NULL,
|
||||
em, bmdm ? bmdm->emd.vertexCos : NULL, bmdm ? bmdm->emd.polyNos : NULL,
|
||||
statvis->distort_min,
|
||||
statvis->distort_max,
|
||||
em->derivedFaceColor);
|
||||
@@ -1479,7 +1473,7 @@ void BKE_editmesh_statvis_calc(
|
||||
{
|
||||
BKE_editmesh_color_ensure(em, BM_VERT);
|
||||
statvis_calc_sharp(
|
||||
em, bmdm ? bmdm->vertexCos : NULL,
|
||||
em, bmdm ? bmdm->emd.vertexCos : NULL,
|
||||
statvis->sharp_min,
|
||||
statvis->sharp_max,
|
||||
/* in this case they are vertex colors */
|
||||
|
@@ -388,6 +388,36 @@ void BKE_mesh_ensure_skin_customdata(Mesh *me)
|
||||
}
|
||||
}
|
||||
|
||||
bool BKE_mesh_ensure_edit_data(struct Mesh *me)
|
||||
{
|
||||
if (me->emd != NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
me->emd = MEM_callocN(sizeof(EditMeshData), "EditMeshData");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BKE_mesh_clear_edit_data(struct Mesh *me)
|
||||
{
|
||||
if (me->emd == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (me->emd->polyCos != NULL)
|
||||
MEM_freeN((void *)me->emd->polyCos);
|
||||
if (me->emd->polyNos != NULL)
|
||||
MEM_freeN((void *)me->emd->polyNos);
|
||||
if (me->emd->vertexCos != NULL)
|
||||
MEM_freeN((void *)me->emd->vertexCos);
|
||||
if (me->emd->vertexNos != NULL)
|
||||
MEM_freeN((void *)me->emd->vertexNos);
|
||||
|
||||
MEM_SAFE_FREE(me->emd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me)
|
||||
{
|
||||
BMesh *bm = me->edit_btmesh ? me->edit_btmesh->bm : NULL;
|
||||
@@ -481,6 +511,7 @@ void BKE_mesh_free(Mesh *me)
|
||||
BKE_animdata_free(&me->id, false);
|
||||
|
||||
BKE_mesh_batch_cache_free(me);
|
||||
BKE_mesh_clear_edit_data(me);
|
||||
|
||||
CustomData_free(&me->vdata, me->totvert);
|
||||
CustomData_free(&me->edata, me->totedge);
|
||||
@@ -580,6 +611,52 @@ void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int
|
||||
}
|
||||
}
|
||||
|
||||
static Mesh *mesh_from_template_ex(
|
||||
Mesh *me_src,
|
||||
int numVerts, int numEdges, int numTessFaces,
|
||||
int numLoops, int numPolys,
|
||||
CustomDataMask mask)
|
||||
{
|
||||
const bool do_tessface = ((me_src->totface != 0) && (me_src->totpoly == 0)); /* only do tessface if we have no polys */
|
||||
|
||||
Mesh *me_dst = MEM_callocN(sizeof(struct Mesh), "Mesh");
|
||||
BKE_mesh_init(me_dst);
|
||||
|
||||
me_dst->mat = MEM_dupallocN(me_src->mat);
|
||||
me_dst->mselect = MEM_dupallocN(me_dst->mselect);
|
||||
|
||||
me_dst->totvert = numVerts;
|
||||
me_dst->totedge = numEdges;
|
||||
me_dst->totloop = numLoops;
|
||||
me_dst->totpoly = numPolys;
|
||||
|
||||
CustomData_copy(&me_src->vdata, &me_dst->vdata, mask, CD_CALLOC, numVerts);
|
||||
CustomData_copy(&me_src->edata, &me_dst->edata, mask, CD_CALLOC, numEdges);
|
||||
CustomData_copy(&me_src->ldata, &me_dst->ldata, mask, CD_CALLOC, numLoops);
|
||||
CustomData_copy(&me_src->pdata, &me_dst->pdata, mask, CD_CALLOC, numPolys);
|
||||
if (do_tessface) {
|
||||
CustomData_copy(&me_src->fdata, &me_dst->fdata, mask, CD_CALLOC, numTessFaces);
|
||||
}
|
||||
else {
|
||||
mesh_tessface_clear_intern(me_dst, false);
|
||||
}
|
||||
|
||||
BKE_mesh_update_customdata_pointers(me_dst, false);
|
||||
|
||||
return me_dst;
|
||||
}
|
||||
|
||||
Mesh * BKE_mesh_from_template(Mesh *me_src,
|
||||
int numVerts, int numEdges, int numTessFaces,
|
||||
int numLoops, int numPolys)
|
||||
{
|
||||
return mesh_from_template_ex(
|
||||
me_src,
|
||||
numVerts, numEdges, numTessFaces,
|
||||
numLoops, numPolys,
|
||||
CD_MASK_EVERYTHING);
|
||||
}
|
||||
|
||||
Mesh *BKE_mesh_copy(Main *bmain, const Mesh *me)
|
||||
{
|
||||
Mesh *me_copy;
|
||||
|
@@ -863,11 +863,16 @@ void modifier_deformVerts(struct ModifierData *md, struct Depsgraph *depsgraph,
|
||||
mti->deformVerts(md, depsgraph, ob, mesh, vertexCos, numVerts, flag);
|
||||
}
|
||||
else {
|
||||
DerivedMesh *dm = CDDM_from_mesh(mesh);
|
||||
DerivedMesh *dm = NULL;
|
||||
if (mesh) {
|
||||
dm = CDDM_from_mesh(mesh);
|
||||
}
|
||||
|
||||
mti->deformVerts_DM(md, depsgraph, ob, dm, vertexCos, numVerts, flag);
|
||||
|
||||
dm->release(dm);
|
||||
if (dm) {
|
||||
dm->release(dm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -881,11 +886,16 @@ void modifier_deformMatrices(struct ModifierData *md, struct Depsgraph *depsgrap
|
||||
mti->deformMatrices(md, depsgraph, ob, mesh, vertexCos, defMats, numVerts);
|
||||
}
|
||||
else {
|
||||
DerivedMesh *dm = CDDM_from_mesh(mesh);
|
||||
DerivedMesh *dm = NULL;
|
||||
if (mesh) {
|
||||
dm = CDDM_from_mesh(mesh);
|
||||
}
|
||||
|
||||
mti->deformMatrices_DM(md, depsgraph, ob, dm, vertexCos, defMats, numVerts);
|
||||
|
||||
dm->release(dm);
|
||||
if (dm) {
|
||||
dm->release(dm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -899,11 +909,16 @@ void modifier_deformVertsEM(struct ModifierData *md, struct Depsgraph *depsgraph
|
||||
mti->deformVertsEM(md, depsgraph, ob, editData, mesh, vertexCos, numVerts);
|
||||
}
|
||||
else {
|
||||
DerivedMesh *dm = CDDM_from_mesh(mesh);
|
||||
DerivedMesh *dm = NULL;
|
||||
if (mesh) {
|
||||
dm = CDDM_from_mesh(mesh);
|
||||
}
|
||||
|
||||
mti->deformVertsEM_DM(md, depsgraph, ob, editData, dm, vertexCos, numVerts);
|
||||
|
||||
dm->release(dm);
|
||||
if (dm) {
|
||||
dm->release(dm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -917,11 +932,16 @@ void modifier_deformMatricesEM(struct ModifierData *md, struct Depsgraph *depsgr
|
||||
mti->deformMatricesEM(md, depsgraph, ob, editData, mesh, vertexCos, defMats, numVerts);
|
||||
}
|
||||
else {
|
||||
DerivedMesh *dm = CDDM_from_mesh(mesh);
|
||||
DerivedMesh *dm = NULL;
|
||||
if (mesh) {
|
||||
dm = CDDM_from_mesh(mesh);
|
||||
}
|
||||
|
||||
mti->deformMatricesEM_DM(md, depsgraph, ob, editData, dm, vertexCos, defMats, numVerts);
|
||||
|
||||
dm->release(dm);
|
||||
if (dm) {
|
||||
dm->release(dm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -985,14 +1005,20 @@ void modifier_deformVerts_DM_deprecated(struct ModifierData *md, struct Depsgrap
|
||||
mti->deformVerts_DM(md, depsgraph, ob, dm, vertexCos, numVerts, flag);
|
||||
}
|
||||
else {
|
||||
struct Mesh mesh;
|
||||
BKE_mesh_init(&mesh);
|
||||
/* TODO(sybren): deduplicate all the copies of this code in this file. */
|
||||
Mesh *mesh = NULL;
|
||||
if (dm != NULL) {
|
||||
mesh = BKE_libblock_alloc_notest(ID_ME);
|
||||
BKE_mesh_init(mesh);
|
||||
DM_to_mesh(dm, mesh, ob, CD_MASK_EVERYTHING, false);
|
||||
}
|
||||
|
||||
DM_to_mesh(dm, &mesh, ob, CD_MASK_EVERYTHING, false);
|
||||
mti->deformVerts(md, depsgraph, ob, mesh, vertexCos, numVerts, flag);
|
||||
|
||||
mti->deformVerts(md, depsgraph, ob, &mesh, vertexCos, numVerts, flag);
|
||||
|
||||
BKE_mesh_free(&mesh);
|
||||
if (mesh != NULL) {
|
||||
BKE_mesh_free(mesh);
|
||||
MEM_freeN(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1028,14 +1054,19 @@ void modifier_deformVertsEM_DM_deprecated(struct ModifierData *md, struct Depsgr
|
||||
mti->deformVertsEM_DM(md, depsgraph, ob, editData, dm, vertexCos, numVerts);
|
||||
}
|
||||
else {
|
||||
struct Mesh mesh;
|
||||
BKE_mesh_init(&mesh);
|
||||
Mesh *mesh = NULL;
|
||||
if (dm != NULL) {
|
||||
mesh = BKE_libblock_alloc_notest(ID_ME);
|
||||
BKE_mesh_init(mesh);
|
||||
DM_to_mesh(dm, mesh, ob, CD_MASK_EVERYTHING, false);
|
||||
}
|
||||
|
||||
DM_to_mesh(dm, &mesh, ob, CD_MASK_EVERYTHING, false);
|
||||
mti->deformVertsEM(md, depsgraph, ob, editData, mesh, vertexCos, numVerts);
|
||||
|
||||
mti->deformVertsEM(md, depsgraph, ob, editData, &mesh, vertexCos, numVerts);
|
||||
|
||||
BKE_mesh_free(&mesh);
|
||||
if (mesh != NULL) {
|
||||
BKE_mesh_free(mesh);
|
||||
MEM_freeN(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1069,19 +1100,30 @@ struct DerivedMesh *modifier_applyModifier_DM_deprecated(struct ModifierData *md
|
||||
return mti->applyModifier_DM(md, depsgraph, ob, dm, flag);
|
||||
}
|
||||
else {
|
||||
struct Mesh mesh;
|
||||
BKE_mesh_init(&mesh);
|
||||
/* TODO(sybren): deduplicate all the copies of this code in this file. */
|
||||
Mesh *mesh = NULL;
|
||||
if (dm != NULL) {
|
||||
mesh = BKE_libblock_alloc_notest(ID_ME);
|
||||
BKE_mesh_init(mesh);
|
||||
DM_to_mesh(dm, mesh, ob, CD_MASK_EVERYTHING, false);
|
||||
}
|
||||
|
||||
DM_to_mesh(dm, &mesh, ob, CD_MASK_EVERYTHING, false);
|
||||
|
||||
struct Mesh *new_mesh = mti->applyModifier(md, depsgraph, ob, &mesh, flag);
|
||||
struct Mesh *new_mesh = mti->applyModifier(md, depsgraph, ob, mesh, flag);
|
||||
|
||||
DerivedMesh *ndm = CDDM_from_mesh(new_mesh);
|
||||
if(new_mesh != mesh) {
|
||||
/* Make a DM that doesn't reference new_mesh so we can free the latter. */
|
||||
/* TODO(sybren): create CDDM_from_mesh_ex() that creates a copy directly. */
|
||||
DerivedMesh *nonref_dm = CDDM_copy(ndm);
|
||||
ndm->release(ndm);
|
||||
ndm = nonref_dm;
|
||||
|
||||
if(new_mesh != &mesh) {
|
||||
BKE_mesh_free(&mesh);
|
||||
|
||||
/* XXX free new_mesh? */
|
||||
BKE_mesh_free(new_mesh);
|
||||
MEM_freeN(new_mesh);
|
||||
}
|
||||
if (mesh != NULL) {
|
||||
BKE_mesh_free(mesh);
|
||||
MEM_freeN(mesh);
|
||||
}
|
||||
|
||||
return ndm;
|
||||
|
@@ -128,6 +128,8 @@ typedef struct MeshRenderData {
|
||||
int loose_edge_len;
|
||||
|
||||
BMEditMesh *edit_bmesh;
|
||||
struct EditMeshData *edit_data;
|
||||
|
||||
MVert *mvert;
|
||||
MEdge *medge;
|
||||
MLoop *mloop;
|
||||
@@ -389,6 +391,7 @@ static MeshRenderData *mesh_render_data_create_ex(
|
||||
BMesh *bm = embm->bm;
|
||||
|
||||
rdata->edit_bmesh = embm;
|
||||
rdata->edit_data = me->emd;
|
||||
|
||||
int bm_ensure_types = 0;
|
||||
if (types & (MR_DATATYPE_VERT)) {
|
||||
@@ -426,6 +429,9 @@ static MeshRenderData *mesh_render_data_create_ex(
|
||||
if (types & (MR_DATATYPE_DVERT)) {
|
||||
bm_ensure_types |= BM_VERT;
|
||||
}
|
||||
if (rdata->edit_data != NULL) {
|
||||
bm_ensure_types |= BM_VERT;
|
||||
}
|
||||
|
||||
BM_mesh_elem_index_ensure(bm, bm_ensure_types);
|
||||
BM_mesh_elem_table_ensure(bm, bm_ensure_types & ~BM_LOOP);
|
||||
@@ -1359,9 +1365,19 @@ static void add_overlay_tri(
|
||||
unsigned char vflag;
|
||||
|
||||
if (vbo_pos) {
|
||||
for (uint i = 0; i < 3; i++) {
|
||||
const float *pos = bm_looptri[i]->v->co;
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
|
||||
/* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */
|
||||
if (rdata->edit_data && rdata->edit_data->vertexCos) {
|
||||
for (uint i = 0; i < 3; i++) {
|
||||
int vidx = BM_elem_index_get(bm_looptri[i]->v);
|
||||
const float *pos = rdata->edit_data->vertexCos[vidx];
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (uint i = 0; i < 3; i++) {
|
||||
const float *pos = bm_looptri[i]->v->co;
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1399,9 +1415,19 @@ static void add_overlay_loose_edge(
|
||||
const BMEdge *eed, const int base_vert_idx)
|
||||
{
|
||||
if (vbo_pos) {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
const float *pos = (&eed->v1)[i]->co;
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
|
||||
/* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */
|
||||
if (rdata->edit_data && rdata->edit_data->vertexCos) {
|
||||
for (uint i = 0; i < 2; i++) {
|
||||
int vidx = BM_elem_index_get((&eed->v1)[i]);
|
||||
const float *pos = rdata->edit_data->vertexCos[vidx];
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
const float *pos = (&eed->v1)[i]->co;
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1428,8 +1454,16 @@ static void add_overlay_loose_vert(
|
||||
const BMVert *eve, const int base_vert_idx)
|
||||
{
|
||||
if (vbo_pos) {
|
||||
const float *pos = eve->co;
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx, pos);
|
||||
/* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */
|
||||
if (rdata->edit_data && rdata->edit_data->vertexCos) {
|
||||
int vidx = BM_elem_index_get(eve);
|
||||
const float *pos = rdata->edit_data->vertexCos[vidx];
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx, pos);
|
||||
}
|
||||
else {
|
||||
const float *pos = eve->co;
|
||||
GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx, pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (vbo_nor) {
|
||||
@@ -2095,8 +2129,18 @@ static Gwn_VertBuf *mesh_batch_cache_get_tri_pos_and_normals_ex(
|
||||
}
|
||||
}
|
||||
|
||||
for (uint t = 0; t < 3; t++) {
|
||||
copy_v3_v3(GWN_vertbuf_raw_step(&pos_step), bm_looptri[t]->v->co);
|
||||
/* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */
|
||||
if (rdata->edit_data && rdata->edit_data->vertexCos) {
|
||||
for (uint t = 0; t < 3; t++) {
|
||||
int vidx = BM_elem_index_get(bm_looptri[t]->v);
|
||||
const float *pos = rdata->edit_data->vertexCos[vidx];
|
||||
copy_v3_v3(GWN_vertbuf_raw_step(&pos_step), pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (uint t = 0; t < 3; t++) {
|
||||
copy_v3_v3(GWN_vertbuf_raw_step(&pos_step), bm_looptri[t]->v->co);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -52,6 +52,19 @@ struct Material;
|
||||
struct Mesh;
|
||||
struct Multires;
|
||||
|
||||
#
|
||||
#
|
||||
typedef struct EditMeshData {
|
||||
/** when set, \a vertexNos, polyNos are lazy initialized */
|
||||
const float (*vertexCos)[3];
|
||||
|
||||
/** lazy initialize (when \a vertexCos is set) */
|
||||
float const (*vertexNos)[3];
|
||||
float const (*polyNos)[3];
|
||||
/** also lazy init but dont depend on \a vertexCos */
|
||||
const float (*polyCos)[3];
|
||||
} EditMeshData;
|
||||
|
||||
typedef struct Mesh {
|
||||
ID id;
|
||||
struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */
|
||||
@@ -87,6 +100,7 @@ typedef struct Mesh {
|
||||
|
||||
/* When the object is available, the preferred access method is: BKE_editmesh_from_object(ob) */
|
||||
struct BMEditMesh *edit_btmesh; /* not saved in file! */
|
||||
struct EditMeshData *emd; /* not saved in file! */
|
||||
|
||||
struct CustomData vdata, edata, fdata;
|
||||
|
||||
|
@@ -41,8 +41,13 @@
|
||||
#include "BLI_ghash.h"
|
||||
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_particle.h"
|
||||
#include "BKE_scene.h"
|
||||
@@ -75,12 +80,11 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
|
||||
return true;
|
||||
}
|
||||
|
||||
static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(depsgraph),
|
||||
Object *UNUSED(ob), DerivedMesh *derivedData,
|
||||
ModifierApplyFlag UNUSED(flag))
|
||||
static Mesh *applyModifier(ModifierData *md, struct Depsgraph *depsgraph,
|
||||
Object *UNUSED(ob), struct Mesh *mesh,
|
||||
ModifierApplyFlag UNUSED(flag))
|
||||
{
|
||||
DerivedMesh *dm = derivedData;
|
||||
DerivedMesh *result;
|
||||
Mesh *result;
|
||||
BuildModifierData *bmd = (BuildModifierData *) md;
|
||||
int i, j, k;
|
||||
int numFaces_dst, numEdges_dst, numLoops_dst = 0;
|
||||
@@ -93,16 +97,16 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
GHash *vertHash = BLI_ghash_int_new("build ve apply gh");
|
||||
/* maps edge indices in new mesh to indices in old mesh */
|
||||
GHash *edgeHash = BLI_ghash_int_new("build ed apply gh");
|
||||
/* maps edge indices in old mesh to indices in new mesh */
|
||||
GHash *edgeHash2 = BLI_ghash_int_new("build ed apply gh");
|
||||
|
||||
const int numVert_src = dm->getNumVerts(dm);
|
||||
const int numEdge_src = dm->getNumEdges(dm);
|
||||
const int numPoly_src = dm->getNumPolys(dm);
|
||||
MPoly *mpoly_src = dm->getPolyArray(dm);
|
||||
MLoop *mloop_src = dm->getLoopArray(dm);
|
||||
MEdge *medge_src = dm->getEdgeArray(dm);
|
||||
MVert *mvert_src = dm->getVertArray(dm);
|
||||
|
||||
const int numVert_src = mesh->totvert;
|
||||
const int numEdge_src = mesh->totedge;
|
||||
const int numPoly_src = mesh->totpoly;
|
||||
MPoly *mpoly_src = mesh->mpoly;
|
||||
MLoop *mloop_src = mesh->mloop;
|
||||
MEdge *medge_src = mesh->medge;
|
||||
MVert *mvert_src = mesh->mvert;
|
||||
|
||||
vertMap = MEM_malloc_arrayN(numVert_src, sizeof(*vertMap), "build modifier vertMap");
|
||||
edgeMap = MEM_malloc_arrayN(numEdge_src, sizeof(*edgeMap), "build modifier edgeMap");
|
||||
@@ -112,13 +116,13 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
range_vn_i(edgeMap, numEdge_src, 0);
|
||||
range_vn_i(faceMap, numPoly_src, 0);
|
||||
|
||||
frac = (BKE_scene_frame_get(md->scene) - bmd->start) / bmd->length;
|
||||
struct Scene *scene = DEG_get_input_scene(depsgraph);
|
||||
frac = (BKE_scene_frame_get(scene) - bmd->start) / bmd->length;
|
||||
CLAMP(frac, 0.0f, 1.0f);
|
||||
|
||||
if (bmd->flag & MOD_BUILD_FLAG_REVERSE) {
|
||||
frac = 1.0f - frac;
|
||||
}
|
||||
|
||||
|
||||
numFaces_dst = numPoly_src * frac;
|
||||
numEdges_dst = numEdge_src * frac;
|
||||
|
||||
@@ -126,7 +130,6 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
if (numFaces_dst) {
|
||||
MPoly *mpoly, *mp;
|
||||
MLoop *ml, *mloop;
|
||||
MEdge *medge;
|
||||
uintptr_t hash_num, hash_num_alt;
|
||||
|
||||
if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE) {
|
||||
@@ -159,11 +162,10 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
/* get the set of edges that will be in the new mesh (i.e. all edges
|
||||
* that have both verts in the new mesh)
|
||||
*/
|
||||
medge = medge_src;
|
||||
hash_num = 0;
|
||||
hash_num_alt = 0;
|
||||
for (i = 0; i < numEdge_src; i++, hash_num_alt++) {
|
||||
MEdge *me = medge + i;
|
||||
MEdge *me = medge_src + i;
|
||||
|
||||
if (BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1)) &&
|
||||
BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v2)))
|
||||
@@ -173,6 +175,7 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
hash_num++;
|
||||
}
|
||||
}
|
||||
BLI_assert(hash_num == BLI_ghash_len(edgeHash));
|
||||
}
|
||||
else if (numEdges_dst) {
|
||||
MEdge *medge, *me;
|
||||
@@ -206,7 +209,7 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
/* get the set of edges that will be in the new mesh */
|
||||
for (i = 0; i < numEdges_dst; i++) {
|
||||
j = BLI_ghash_len(edgeHash);
|
||||
|
||||
|
||||
BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(j),
|
||||
SET_INT_IN_POINTER(edgeMap[i]));
|
||||
BLI_ghash_insert(edgeHash2, SET_INT_IN_POINTER(edgeMap[i]),
|
||||
@@ -229,11 +232,9 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
}
|
||||
}
|
||||
|
||||
/* now we know the number of verts, edges and faces, we can create
|
||||
* the mesh
|
||||
*/
|
||||
result = CDDM_from_template(dm, BLI_ghash_len(vertHash),
|
||||
BLI_ghash_len(edgeHash), 0, numLoops_dst, numFaces_dst);
|
||||
/* now we know the number of verts, edges and faces, we can create the mesh. */
|
||||
result = BKE_mesh_from_template(mesh, BLI_ghash_len(vertHash), BLI_ghash_len(edgeHash),
|
||||
0, numLoops_dst, numFaces_dst);
|
||||
|
||||
/* copy the vertices across */
|
||||
GHASH_ITER (gh_iter, vertHash) {
|
||||
@@ -243,45 +244,44 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter));
|
||||
|
||||
source = mvert_src[oldIndex];
|
||||
dest = CDDM_get_vert(result, newIndex);
|
||||
dest = &result->mvert[newIndex];
|
||||
|
||||
DM_copy_vert_data(dm, result, oldIndex, newIndex, 1);
|
||||
CustomData_copy_data(&mesh->vdata, &result->vdata, oldIndex, newIndex, 1);
|
||||
*dest = source;
|
||||
}
|
||||
|
||||
|
||||
/* copy the edges across, remapping indices */
|
||||
for (i = 0; i < BLI_ghash_len(edgeHash); i++) {
|
||||
MEdge source;
|
||||
MEdge *dest;
|
||||
int oldIndex = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash, SET_INT_IN_POINTER(i)));
|
||||
|
||||
|
||||
source = medge_src[oldIndex];
|
||||
dest = CDDM_get_edge(result, i);
|
||||
|
||||
dest = &result->medge[i];
|
||||
|
||||
source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1)));
|
||||
source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2)));
|
||||
|
||||
DM_copy_edge_data(dm, result, oldIndex, i, 1);
|
||||
|
||||
CustomData_copy_data(&mesh->edata, &result->edata, oldIndex, i, 1);
|
||||
*dest = source;
|
||||
}
|
||||
|
||||
mpoly_dst = CDDM_get_polys(result);
|
||||
/* mloop_dst = */ ml_dst = CDDM_get_loops(result);
|
||||
mpoly_dst = result->mpoly;
|
||||
ml_dst = result->mloop;
|
||||
|
||||
/* copy the faces across, remapping indices */
|
||||
k = 0;
|
||||
for (i = 0; i < numFaces_dst; i++) {
|
||||
MPoly *source;
|
||||
MPoly *dest;
|
||||
|
||||
|
||||
source = mpoly_src + faceMap[i];
|
||||
dest = mpoly_dst + i;
|
||||
DM_copy_poly_data(dm, result, faceMap[i], i, 1);
|
||||
|
||||
CustomData_copy_data(&mesh->pdata, &result->pdata, faceMap[i], i, 1);
|
||||
|
||||
*dest = *source;
|
||||
dest->loopstart = k;
|
||||
|
||||
DM_copy_loop_data(dm, result, source->loopstart, dest->loopstart, dest->totloop);
|
||||
CustomData_copy_data(&mesh->ldata, &result->ldata, source->loopstart, dest->loopstart, dest->totloop);
|
||||
|
||||
ml_src = mloop_src + source->loopstart;
|
||||
for (j = 0; j < source->totloop; j++, k++, ml_src++, ml_dst++) {
|
||||
@@ -298,10 +298,7 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Depsgraph *UNUSED(dep
|
||||
MEM_freeN(edgeMap);
|
||||
MEM_freeN(faceMap);
|
||||
|
||||
if (dm->dirty & DM_DIRTY_NORMALS) {
|
||||
result->dirty |= DM_DIRTY_NORMALS;
|
||||
}
|
||||
|
||||
/* TODO(sybren): also copy flags & tags? */
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -319,14 +316,14 @@ ModifierTypeInfo modifierType_Build = {
|
||||
/* deformMatrices_DM */ NULL,
|
||||
/* deformVertsEM_DM */ NULL,
|
||||
/* deformMatricesEM_DM*/NULL,
|
||||
/* applyModifier_DM */ applyModifier,
|
||||
/* applyModifier_DM */ NULL,
|
||||
/* applyModifierEM_DM */NULL,
|
||||
|
||||
/* deformVerts */ NULL,
|
||||
/* deformMatrices */ NULL,
|
||||
/* deformVertsEM */ NULL,
|
||||
/* deformMatricesEM */ NULL,
|
||||
/* applyModifier */ NULL,
|
||||
/* applyModifier */ applyModifier,
|
||||
/* applyModifierEM */ NULL,
|
||||
|
||||
/* initData */ initData,
|
||||
|
@@ -32,6 +32,7 @@
|
||||
* \ingroup modifiers
|
||||
*/
|
||||
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
@@ -39,6 +40,7 @@
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_library_query.h"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_deform.h"
|
||||
@@ -180,11 +182,10 @@ static void simpleDeform_bend(const float factor, const int axis, const float dc
|
||||
|
||||
|
||||
/* simple deform modifier */
|
||||
static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, struct DerivedMesh *dm,
|
||||
static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, struct Mesh *mesh,
|
||||
float (*vertexCos)[3], int numVerts)
|
||||
{
|
||||
const float base_limit[2] = {0.0f, 0.0f};
|
||||
|
||||
int i;
|
||||
float smd_limit[2], smd_factor;
|
||||
SpaceTransform *transf = NULL, tmp_transf;
|
||||
@@ -281,7 +282,7 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object
|
||||
}
|
||||
}
|
||||
|
||||
modifier_get_vgroup(ob, dm, smd->vgroup_name, &dvert, &vgroup);
|
||||
modifier_get_vgroup_mesh(ob, mesh, smd->vgroup_name, &dvert, &vgroup);
|
||||
const bool invert_vgroup = (smd->flag & MOD_SIMPLEDEFORM_FLAG_INVERT_VGROUP) != 0;
|
||||
const uint *axis_map = axis_map_table[(smd->mode != MOD_SIMPLEDEFORM_MODE_BEND) ? deform_axis : 2];
|
||||
|
||||
@@ -384,43 +385,21 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
|
||||
}
|
||||
|
||||
static void deformVerts(ModifierData *md, struct Depsgraph *UNUSED(depsgraph),
|
||||
Object *ob, DerivedMesh *derivedData,
|
||||
Object *ob, struct Mesh *mesh,
|
||||
float (*vertexCos)[3],
|
||||
int numVerts,
|
||||
ModifierApplyFlag UNUSED(flag))
|
||||
{
|
||||
DerivedMesh *dm = derivedData;
|
||||
CustomDataMask dataMask = requiredDataMask(ob, md);
|
||||
|
||||
/* we implement requiredDataMask but thats not really useful since
|
||||
* mesh_calc_modifiers pass a NULL derivedData */
|
||||
if (dataMask)
|
||||
dm = get_dm(ob, NULL, dm, NULL, false, false);
|
||||
|
||||
SimpleDeformModifier_do((SimpleDeformModifierData *)md, ob, dm, vertexCos, numVerts);
|
||||
|
||||
if (dm != derivedData)
|
||||
dm->release(dm);
|
||||
SimpleDeformModifier_do((SimpleDeformModifierData *)md, ob, mesh, vertexCos, numVerts);
|
||||
}
|
||||
|
||||
static void deformVertsEM(ModifierData *md, struct Depsgraph *UNUSED(depsgraph),
|
||||
Object *ob, struct BMEditMesh *editData,
|
||||
DerivedMesh *derivedData,
|
||||
Object *ob, struct BMEditMesh *UNUSED(editData),
|
||||
struct Mesh *mesh,
|
||||
float (*vertexCos)[3],
|
||||
int numVerts)
|
||||
{
|
||||
DerivedMesh *dm = derivedData;
|
||||
CustomDataMask dataMask = requiredDataMask(ob, md);
|
||||
|
||||
/* we implement requiredDataMask but thats not really useful since
|
||||
* mesh_calc_modifiers pass a NULL derivedData */
|
||||
if (dataMask)
|
||||
dm = get_dm(ob, editData, dm, NULL, false, false);
|
||||
|
||||
SimpleDeformModifier_do((SimpleDeformModifierData *)md, ob, dm, vertexCos, numVerts);
|
||||
|
||||
if (dm != derivedData)
|
||||
dm->release(dm);
|
||||
SimpleDeformModifier_do((SimpleDeformModifierData *)md, ob, mesh, vertexCos, numVerts);
|
||||
}
|
||||
|
||||
|
||||
@@ -438,16 +417,16 @@ ModifierTypeInfo modifierType_SimpleDeform = {
|
||||
|
||||
/* copyData */ copyData,
|
||||
|
||||
/* deformVerts_DM */ deformVerts,
|
||||
/* deformVerts_DM */ NULL,
|
||||
/* deformMatrices_DM */ NULL,
|
||||
/* deformVertsEM_DM */ deformVertsEM,
|
||||
/* deformVertsEM_DM */ NULL,
|
||||
/* deformMatricesEM_DM*/NULL,
|
||||
/* applyModifier_DM */ NULL,
|
||||
/* applyModifierEM_DM */NULL,
|
||||
|
||||
/* deformVerts */ NULL,
|
||||
/* deformVerts */ deformVerts,
|
||||
/* deformMatrices */ NULL,
|
||||
/* deformVertsEM */ NULL,
|
||||
/* deformVertsEM */ deformVertsEM,
|
||||
/* deformMatricesEM */ NULL,
|
||||
/* applyModifier */ NULL,
|
||||
/* applyModifierEM */ NULL,
|
||||
|
@@ -34,9 +34,11 @@
|
||||
|
||||
#include "DNA_image_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
#include "BLI_math_vector.h"
|
||||
@@ -229,6 +231,20 @@ void modifier_get_vgroup(Object *ob, DerivedMesh *dm, const char *name, MDeformV
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO(sybren): replace the above function with this one, once we got rid of DerivedMesh for modifiers. */
|
||||
void modifier_get_vgroup_mesh(Object *ob, struct Mesh *mesh, const char *name, MDeformVert **dvert, int *defgrp_index)
|
||||
{
|
||||
*defgrp_index = defgroup_name_index(ob, name);
|
||||
*dvert = NULL;
|
||||
|
||||
if (*defgrp_index != -1) {
|
||||
if (ob->type == OB_LATTICE)
|
||||
*dvert = BKE_lattice_deform_verts_get(ob);
|
||||
else if (mesh)
|
||||
*dvert = mesh->dvert;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* only called by BKE_modifier.h/modifier.c */
|
||||
void modifier_type_init(ModifierTypeInfo *types[])
|
||||
|
@@ -51,5 +51,7 @@ struct DerivedMesh *get_dm(struct Object *ob, struct BMEditMesh *em, struct Deri
|
||||
struct DerivedMesh *get_dm_for_modifier(struct Object *ob, ModifierApplyFlag flag);
|
||||
void modifier_get_vgroup(struct Object *ob, struct DerivedMesh *dm,
|
||||
const char *name, struct MDeformVert **dvert, int *defgrp_index);
|
||||
void modifier_get_vgroup_mesh(struct Object *ob, struct Mesh *mesh,
|
||||
const char *name, struct MDeformVert **dvert, int *defgrp_index);
|
||||
|
||||
#endif /* __MOD_UTIL_H__ */
|
||||
|
Reference in New Issue
Block a user