Cleanup: remove unused DM_to_mesh function
This commit is contained in:
@@ -303,14 +303,6 @@ void DM_from_template(DerivedMesh *dm,
|
||||
*/
|
||||
int DM_release(DerivedMesh *dm);
|
||||
|
||||
/** utility function to convert a DerivedMesh to a Mesh
|
||||
*/
|
||||
void DM_to_mesh(DerivedMesh *dm,
|
||||
struct Mesh *me,
|
||||
struct Object *ob,
|
||||
const struct CustomData_MeshMasks *mask,
|
||||
bool take_ownership);
|
||||
|
||||
void DM_set_only_copy(DerivedMesh *dm, const struct CustomData_MeshMasks *mask);
|
||||
|
||||
/* adds a vertex/edge/face custom data layer to a DerivedMesh, optionally
|
||||
|
||||
@@ -87,11 +87,8 @@
|
||||
# define ASSERT_IS_VALID_MESH(mesh)
|
||||
#endif
|
||||
|
||||
static CLG_LogRef LOG = {"bke.derivedmesh"};
|
||||
static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER;
|
||||
|
||||
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
|
||||
|
||||
static void mesh_init_origspace(Mesh *mesh);
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
@@ -516,154 +513,6 @@ void DM_ensure_looptri_data(DerivedMesh *dm)
|
||||
}
|
||||
}
|
||||
|
||||
void DM_to_mesh(
|
||||
DerivedMesh *dm, Mesh *me, Object *ob, const CustomData_MeshMasks *mask, bool take_ownership)
|
||||
{
|
||||
/* dm might depend on me, so we need to do everything with a local copy */
|
||||
Mesh tmp = *me;
|
||||
int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly;
|
||||
int did_shapekeys = 0;
|
||||
eCDAllocType alloctype = CD_DUPLICATE;
|
||||
|
||||
if (take_ownership && dm->type == DM_TYPE_CDDM && dm->needsFree) {
|
||||
bool has_any_referenced_layers = CustomData_has_referenced(&dm->vertData) ||
|
||||
CustomData_has_referenced(&dm->edgeData) ||
|
||||
CustomData_has_referenced(&dm->loopData) ||
|
||||
CustomData_has_referenced(&dm->faceData) ||
|
||||
CustomData_has_referenced(&dm->polyData);
|
||||
if (!has_any_referenced_layers) {
|
||||
alloctype = CD_ASSIGN;
|
||||
}
|
||||
}
|
||||
|
||||
CustomData_reset(&tmp.vdata);
|
||||
CustomData_reset(&tmp.edata);
|
||||
CustomData_reset(&tmp.fdata);
|
||||
CustomData_reset(&tmp.ldata);
|
||||
CustomData_reset(&tmp.pdata);
|
||||
|
||||
DM_ensure_normals(dm);
|
||||
|
||||
totvert = tmp.totvert = dm->getNumVerts(dm);
|
||||
totedge = tmp.totedge = dm->getNumEdges(dm);
|
||||
totloop = tmp.totloop = dm->getNumLoops(dm);
|
||||
totpoly = tmp.totpoly = dm->getNumPolys(dm);
|
||||
tmp.totface = 0;
|
||||
|
||||
CustomData_copy(&dm->vertData, &tmp.vdata, mask->vmask, alloctype, totvert);
|
||||
CustomData_copy(&dm->edgeData, &tmp.edata, mask->emask, alloctype, totedge);
|
||||
CustomData_copy(&dm->loopData, &tmp.ldata, mask->lmask, alloctype, totloop);
|
||||
CustomData_copy(&dm->polyData, &tmp.pdata, mask->pmask, alloctype, totpoly);
|
||||
tmp.cd_flag = dm->cd_flag;
|
||||
tmp.runtime.deformed_only = dm->deformedOnly;
|
||||
|
||||
if (CustomData_has_layer(&dm->vertData, CD_SHAPEKEY)) {
|
||||
KeyBlock *kb;
|
||||
int uid;
|
||||
|
||||
if (ob) {
|
||||
kb = BLI_findlink(&me->key->block, ob->shapenr - 1);
|
||||
if (kb) {
|
||||
uid = kb->uid;
|
||||
}
|
||||
else {
|
||||
CLOG_ERROR(&LOG, "could not find active shapekey %d!", ob->shapenr - 1);
|
||||
uid = INT_MAX;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* if no object, set to INT_MAX so we don't mess up any shapekey layers */
|
||||
uid = INT_MAX;
|
||||
}
|
||||
|
||||
shapekey_layers_to_keyblocks(dm, me, uid);
|
||||
did_shapekeys = 1;
|
||||
}
|
||||
|
||||
/* copy texture space */
|
||||
if (ob) {
|
||||
BKE_mesh_texspace_copy_from_object(&tmp, ob);
|
||||
}
|
||||
|
||||
/* not all DerivedMeshes store their verts/edges/faces in CustomData, so
|
||||
* we set them here in case they are missing */
|
||||
if (!CustomData_has_layer(&tmp.vdata, CD_MVERT)) {
|
||||
CustomData_add_layer(&tmp.vdata,
|
||||
CD_MVERT,
|
||||
CD_ASSIGN,
|
||||
(alloctype == CD_ASSIGN) ? dm->getVertArray(dm) : dm->dupVertArray(dm),
|
||||
totvert);
|
||||
}
|
||||
if (!CustomData_has_layer(&tmp.edata, CD_MEDGE)) {
|
||||
CustomData_add_layer(&tmp.edata,
|
||||
CD_MEDGE,
|
||||
CD_ASSIGN,
|
||||
(alloctype == CD_ASSIGN) ? dm->getEdgeArray(dm) : dm->dupEdgeArray(dm),
|
||||
totedge);
|
||||
}
|
||||
if (!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) {
|
||||
tmp.mloop = (alloctype == CD_ASSIGN) ? dm->getLoopArray(dm) : dm->dupLoopArray(dm);
|
||||
tmp.mpoly = (alloctype == CD_ASSIGN) ? dm->getPolyArray(dm) : dm->dupPolyArray(dm);
|
||||
|
||||
CustomData_add_layer(&tmp.ldata, CD_MLOOP, CD_ASSIGN, tmp.mloop, tmp.totloop);
|
||||
CustomData_add_layer(&tmp.pdata, CD_MPOLY, CD_ASSIGN, tmp.mpoly, tmp.totpoly);
|
||||
}
|
||||
|
||||
/* object had got displacement layer, should copy this layer to save sculpted data */
|
||||
/* NOTE: maybe some other layers should be copied? nazgul */
|
||||
if (CustomData_has_layer(&me->ldata, CD_MDISPS)) {
|
||||
if (totloop == me->totloop) {
|
||||
MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
|
||||
CustomData_add_layer(&tmp.ldata, CD_MDISPS, alloctype, mdisps, totloop);
|
||||
}
|
||||
}
|
||||
|
||||
/* yes, must be before _and_ after tessellate */
|
||||
BKE_mesh_update_customdata_pointers(&tmp, false);
|
||||
|
||||
/* since 2.65 caller must do! */
|
||||
// BKE_mesh_tessface_calc(&tmp);
|
||||
|
||||
CustomData_free(&me->vdata, me->totvert);
|
||||
CustomData_free(&me->edata, me->totedge);
|
||||
CustomData_free(&me->fdata, me->totface);
|
||||
CustomData_free(&me->ldata, me->totloop);
|
||||
CustomData_free(&me->pdata, me->totpoly);
|
||||
|
||||
/* ok, this should now use new CD shapekey data,
|
||||
* which should be fed through the modifier
|
||||
* stack */
|
||||
if (tmp.totvert != me->totvert && !did_shapekeys && me->key) {
|
||||
CLOG_WARN(&LOG, "YEEK! this should be recoded! Shape key loss!: ID '%s'", tmp.id.name);
|
||||
if (tmp.key && !(tmp.id.tag & LIB_TAG_NO_MAIN)) {
|
||||
id_us_min(&tmp.key->id);
|
||||
}
|
||||
tmp.key = NULL;
|
||||
}
|
||||
|
||||
/* Clear selection history */
|
||||
MEM_SAFE_FREE(tmp.mselect);
|
||||
tmp.totselect = 0;
|
||||
BLI_assert(ELEM(tmp.bb, NULL, me->bb));
|
||||
if (me->bb) {
|
||||
MEM_freeN(me->bb);
|
||||
tmp.bb = NULL;
|
||||
}
|
||||
|
||||
/* skip the listbase */
|
||||
MEMCPY_STRUCT_AFTER(me, &tmp, id.prev);
|
||||
|
||||
if (take_ownership) {
|
||||
if (alloctype == CD_ASSIGN) {
|
||||
CustomData_free_typemask(&dm->vertData, dm->numVertData, ~mask->vmask);
|
||||
CustomData_free_typemask(&dm->edgeData, dm->numEdgeData, ~mask->emask);
|
||||
CustomData_free_typemask(&dm->loopData, dm->numLoopData, ~mask->lmask);
|
||||
CustomData_free_typemask(&dm->polyData, dm->numPolyData, ~mask->pmask);
|
||||
}
|
||||
dm->release(dm);
|
||||
}
|
||||
}
|
||||
|
||||
/** Utility function to convert an (evaluated) Mesh to a shape key block. */
|
||||
/* Just a shallow wrapper around BKE_keyblock_convert_from_mesh,
|
||||
* that ensures both evaluated mesh and original one has same number of vertices. */
|
||||
@@ -948,67 +797,6 @@ static void editmesh_update_statvis_color(const Scene *scene, Object *ob)
|
||||
BKE_editmesh_statvis_calc(em, me->runtime.edit_data, &scene->toolsettings->statvis);
|
||||
}
|
||||
|
||||
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid)
|
||||
{
|
||||
KeyBlock *kb;
|
||||
int i, j, tot;
|
||||
|
||||
if (!me->key) {
|
||||
return;
|
||||
}
|
||||
|
||||
tot = CustomData_number_of_layers(&dm->vertData, CD_SHAPEKEY);
|
||||
for (i = 0; i < tot; i++) {
|
||||
CustomDataLayer *layer =
|
||||
&dm->vertData.layers[CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i)];
|
||||
float(*cos)[3], (*kbcos)[3];
|
||||
|
||||
for (kb = me->key->block.first; kb; kb = kb->next) {
|
||||
if (kb->uid == layer->uid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!kb) {
|
||||
kb = BKE_keyblock_add(me->key, layer->name);
|
||||
kb->uid = layer->uid;
|
||||
}
|
||||
|
||||
if (kb->data) {
|
||||
MEM_freeN(kb->data);
|
||||
}
|
||||
|
||||
cos = CustomData_get_layer_n(&dm->vertData, CD_SHAPEKEY, i);
|
||||
kb->totelem = dm->numVertData;
|
||||
|
||||
kb->data = kbcos = MEM_malloc_arrayN(kb->totelem, 3 * sizeof(float), "kbcos DerivedMesh.c");
|
||||
if (kb->uid == actshape_uid) {
|
||||
MVert *mvert = dm->getVertArray(dm);
|
||||
|
||||
for (j = 0; j < dm->numVertData; j++, kbcos++, mvert++) {
|
||||
copy_v3_v3(*kbcos, mvert->co);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (j = 0; j < kb->totelem; j++, cos++, kbcos++) {
|
||||
copy_v3_v3(*kbcos, *cos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (kb = me->key->block.first; kb; kb = kb->next) {
|
||||
if (kb->totelem != dm->numVertData) {
|
||||
if (kb->data) {
|
||||
MEM_freeN(kb->data);
|
||||
}
|
||||
|
||||
kb->totelem = dm->numVertData;
|
||||
kb->data = MEM_calloc_arrayN(kb->totelem, 3 * sizeof(float), "kb->data derivedmesh.c");
|
||||
CLOG_ERROR(&LOG, "lost a shapekey layer: '%s'! (bmesh internal error)", kb->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_copy_autosmooth(Mesh *me, Mesh *me_orig)
|
||||
{
|
||||
if (me_orig->flag & ME_AUTOSMOOTH) {
|
||||
|
||||
@@ -1434,7 +1434,6 @@ static void shapekey_layers_to_keyblocks(Mesh *mesh_src, Mesh *mesh_dst, int act
|
||||
}
|
||||
}
|
||||
|
||||
/* This is a Mesh-based copy of DM_to_mesh() */
|
||||
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src,
|
||||
Mesh *mesh_dst,
|
||||
Object *ob,
|
||||
@@ -1442,7 +1441,7 @@ void BKE_mesh_nomain_to_mesh(Mesh *mesh_src,
|
||||
bool take_ownership)
|
||||
{
|
||||
/* mesh_src might depend on mesh_dst, so we need to do everything with a local copy */
|
||||
/* TODO(Sybren): the above claim came from DM_to_mesh();
|
||||
/* TODO(Sybren): the above claim came from 2.7x derived-mesh code (DM_to_mesh);
|
||||
* check whether it is still true with Mesh */
|
||||
Mesh tmp = *mesh_dst;
|
||||
int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly;
|
||||
@@ -1594,7 +1593,6 @@ void BKE_mesh_nomain_to_mesh(Mesh *mesh_src,
|
||||
}
|
||||
}
|
||||
|
||||
/* This is a Mesh-based copy of DM_to_meshkey() */
|
||||
void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb)
|
||||
{
|
||||
int a, totvert = mesh_src->totvert;
|
||||
|
||||
Reference in New Issue
Block a user