[Bf-blender-cvs] [f8aa1c0fd71] temp-modifier-rm-cddm: First pass at porting mesh_calc_modifiers from DerivedMesh to Mesh
Mai Lavelle
noreply at git.blender.org
Thu May 3 11:23:26 CEST 2018
Commit: f8aa1c0fd715caf4d16d69a49b788cdaa57f9120
Author: Mai Lavelle
Date: Sat Apr 21 03:00:32 2018 -0400
Branches: temp-modifier-rm-cddm
https://developer.blender.org/rBf8aa1c0fd715caf4d16d69a49b788cdaa57f9120
First pass at porting mesh_calc_modifiers from DerivedMesh to Mesh
DerivedMesh is almost completely removed from the main loop.
Added `_dep` to dm pointers to make usage of them easy to locate by
searching for `dm_dep`.
Still some work to do. It looks like some of these code paths aren't
entered into, maybe things could be simplified if we can be sure of
whats actually needed.
===================================================================
M source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 4796e35684a..49155a841bc 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -1994,7 +1994,7 @@ static void mesh_calc_modifiers(
const int index, const bool useCache, const bool build_shapekey_layers,
const bool allow_gpu,
/* return args */
- DerivedMesh **r_deform, DerivedMesh **r_final)
+ DerivedMesh **r_deformdm_dep, DerivedMesh **r_finaldm_dep)
{
Mesh *me = ob->data;
/* Always get the vertex coordinates from the original mesh. Otherwise
@@ -2005,7 +2005,6 @@ static void mesh_calc_modifiers(
/* XXX Always copying POLYINDEX, else tessellated data are no more valid! */
CustomDataMask mask, nextmask, previewmask = 0, append_mask = CD_MASK_ORIGINDEX;
float (*deformedVerts)[3] = NULL;
- DerivedMesh *dm = NULL, *orcodm, *clothorcodm, *finaldm;
int numVerts = me->totvert;
const int required_mode = useRenderParams ? eModifierMode_Render : eModifierMode_Realtime;
bool isPrevDeform = false;
@@ -2070,10 +2069,10 @@ static void mesh_calc_modifiers(
datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode, previewmd, previewmask);
curr = datamasks;
- if (r_deform) {
- *r_deform = NULL;
+ if (r_deformdm_dep) {
+ *r_deformdm_dep = NULL;
}
- *r_final = NULL;
+ *r_finaldm_dep = NULL;
if (useDeform) {
if (inputVertexCos)
@@ -2097,7 +2096,7 @@ static void mesh_calc_modifiers(
if (!deformedVerts)
deformedVerts = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
- modwrap_deformVerts(md, &mectx_deform, NULL, deformedVerts, numVerts);
+ modifier_deformVerts_ensure_normals(md, &mectx_deform, NULL, deformedVerts, numVerts);
}
else {
break;
@@ -2112,14 +2111,15 @@ static void mesh_calc_modifiers(
* places that wish to use the original mesh but with deformed
* coordinates (vpaint, etc.)
*/
- if (r_deform) {
- *r_deform = CDDM_from_mesh(me);
+ if (r_deformdm_dep) {
+ *r_deformdm_dep = CDDM_from_mesh(me);
+ /* XXX: Is build_shapekey_layers ever even true? This should have crashed long ago... */
if (build_shapekey_layers)
- add_shapekey_layers(dm, me, ob);
+ add_shapekey_layers(*r_deformdm_dep, me, ob);
if (deformedVerts) {
- CDDM_apply_vert_coords(*r_deform, deformedVerts);
+ CDDM_apply_vert_coords(*r_deformdm_dep, deformedVerts);
}
}
}
@@ -2135,9 +2135,9 @@ static void mesh_calc_modifiers(
/* Now apply all remaining modifiers. If useDeform is off then skip
* OnlyDeform ones.
*/
- dm = NULL;
- orcodm = NULL;
- clothorcodm = NULL;
+ Mesh *mesh = NULL;
+ Mesh *orco_mesh = NULL;
+ Mesh *cloth_orco_mesh = NULL;
for (; md; md = md->next, curr = curr->next) {
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
@@ -2152,7 +2152,7 @@ static void mesh_calc_modifiers(
continue;
}
- if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && dm) {
+ if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && mesh) {
modifier_setError(md, "Modifier requires original data, bad stack position");
continue;
}
@@ -2203,8 +2203,9 @@ static void mesh_calc_modifiers(
else
mask = 0;
- if (dm && (mask & CD_MASK_ORCO))
- add_orco_dm(ob, NULL, dm, orcodm, CD_ORCO);
+ if (mesh && (mask & CD_MASK_ORCO)) {
+ add_orco_mesh(ob, NULL, mesh, orco_mesh, CD_ORCO);
+ }
/* How to apply modifier depends on (a) what we already have as
* a result of previous modifiers (could be a DerivedMesh or just
@@ -2214,15 +2215,12 @@ static void mesh_calc_modifiers(
if (mti->type == eModifierTypeType_OnlyDeform) {
/* No existing verts to deform, need to build them. */
if (!deformedVerts) {
- if (dm) {
- /* Deforming a derived mesh, read the vertex locations
+ if (mesh) {
+ /* Deforming a mesh, read the vertex locations
* out of the mesh and deform them. Once done with this
* run of deformers verts will be written back.
*/
- numVerts = dm->getNumVerts(dm);
- deformedVerts =
- MEM_malloc_arrayN(numVerts, sizeof(*deformedVerts), "dfmv");
- dm->getVertCos(dm, deformedVerts);
+ deformedVerts = BKE_mesh_vertexCos_get(mesh, &numVerts);
}
else {
deformedVerts = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
@@ -2233,16 +2231,14 @@ static void mesh_calc_modifiers(
* to avoid giving bogus normals to the next modifier see: [#23673] */
if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
/* XXX, this covers bug #23673, but we may need normal calc for other types */
- if (dm && dm->type == DM_TYPE_CDDM) {
- CDDM_apply_vert_coords(dm, deformedVerts);
+ if (mesh) {
+ apply_vert_coords(mesh, deformedVerts);
}
}
- modwrap_deformVerts(md, &mectx_deform, dm, deformedVerts, numVerts);
+ modifier_deformVerts_ensure_normals(md, &mectx_deform, mesh, deformedVerts, numVerts);
}
else {
- DerivedMesh *ndm;
-
/* determine which data layers are needed by following modifiers */
if (curr->next)
nextmask = curr->next->mask;
@@ -2250,28 +2246,30 @@ static void mesh_calc_modifiers(
nextmask = dataMask;
/* apply vertex coordinates or build a DerivedMesh as necessary */
- if (dm) {
+ if (mesh) {
if (deformedVerts) {
+ /* XXX: What's the point of this copy?
DerivedMesh *tdm = CDDM_copy(dm);
dm->release(dm);
- dm = tdm;
+ dm = tdm; */
- CDDM_apply_vert_coords(dm, deformedVerts);
+ apply_vert_coords(mesh, deformedVerts);
}
}
else {
- dm = CDDM_from_mesh(me);
- ASSERT_IS_VALID_DM(dm);
+ BKE_id_copy_ex(NULL, &me->id, (ID**)&mesh, LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT, false);
+ ASSERT_IS_VALID_MESH(mesh);
- if (build_shapekey_layers)
- add_shapekey_layers(dm, me, ob);
+ // XXX: port to Mesh if build_shapekey_layers can ever be true
+ //if (build_shapekey_layers)
+ // add_shapekey_layers(dm_dep, me, ob);
if (deformedVerts) {
- CDDM_apply_vert_coords(dm, deformedVerts);
+ apply_vert_coords(mesh, deformedVerts);
}
if (do_init_wmcol)
- DM_update_weight_mcol(ob, dm, draw_flag, NULL, 0, NULL);
+ mesh_update_weight_mcol(ob, mesh, draw_flag, NULL, 0, NULL);
/* Constructive modifiers need to have an origindex
* otherwise they wont have anywhere to copy the data from.
@@ -2282,14 +2280,14 @@ static void mesh_calc_modifiers(
*/
if (need_mapping || (nextmask & CD_MASK_ORIGINDEX)) {
/* calc */
- DM_add_vert_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
- DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
- DM_add_poly_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
+ CustomData_add_layer(&mesh->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totvert);
+ CustomData_add_layer(&mesh->edata, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totedge);
+ CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, mesh->totpoly);
/* Not worth parallelizing this, gives less than 0.1% overall speedup in best of best cases... */
- range_vn_i(DM_get_vert_data_layer(dm, CD_ORIGINDEX), dm->numVertData, 0);
- range_vn_i(DM_get_edge_data_layer(dm, CD_ORIGINDEX), dm->numEdgeData, 0);
- range_vn_i(DM_get_poly_data_layer(dm, CD_ORIGINDEX), dm->numPolyData, 0);
+ range_vn_i(CustomData_get_layer(&mesh->vdata, CD_ORIGINDEX), mesh->totvert, 0);
+ range_vn_i(CustomData_get_layer(&mesh->edata, CD_ORIGINDEX), mesh->totedge, 0);
+ range_vn_i(CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX), mesh->totpoly, 0);
}
}
@@ -2299,28 +2297,31 @@ static void mesh_calc_modifiers(
/* needMapping check here fixes bug [#28112], otherwise it's
* possible that it won't be copied */
mask |= append_mask;
- DM_set_only_copy(dm, mask | (need_mapping ? CD_MASK_ORIGINDEX : 0));
-
+ mesh_set_only_copy(mesh, mask | (need_mapping ? CD_MASK_ORIGINDEX : 0));
+
/* add cloth rest shape key if needed */
if (mask & CD_MASK_CLOTH_ORCO)
- add_orco_dm(ob, NULL, dm, clothorcodm, CD_CLOTH_ORCO);
+ add_orco_mesh(ob, NULL, mesh, orco_mesh, CD_CLOTH_ORCO);
/* add an origspace layer if needed */
if ((curr->mask) & CD_MASK_ORIGSPACE_MLOOP) {
- if (!CustomData_has_layer(&dm->loopData, CD_ORIGSPACE_MLOOP)) {
- DM_add_loop_layer(dm, CD_ORIGSPACE_MLOOP, CD_CALLOC, NULL);
- DM_init_origspace(dm);
+ if (!CustomData_has_layer(&mesh->ldata, CD_ORIGSPACE_MLOOP)) {
+ CustomData_add_layer(&mesh->ldata, CD_ORIGSPACE_MLOOP, CD_CALLOC, NULL, mesh->totloop);
+ mesh_init_origspace(mesh);
}
}
- ndm = modwrap_applyModifier(md, &mectx_apply, dm);
- ASSERT_IS_VALID_DM(ndm);
+ Mesh *new_mesh = modifier_applyModifier_ensure_normals(md, &mectx_apply, mesh);
+ ASSERT_IS_VALID_MESH(new_mesh);
- if (ndm) {
- /* if the modifier returned a new dm, release the old one */
- if (dm && dm != ndm) dm->release(dm);
+ if (new_mesh) {
+ /* if the modifier returned a new mesh, release the old one */
+ if (mesh && mesh != new_mesh) {
+ BKE_mesh_free(mesh);
+ MEM_freeN(mesh);
+ }
- dm = ndm;
+ mesh = new_mesh;
if (deformedVerts) {
if (deformedVerts != inputVertexCos)
@@ -2332,41 +2333,48 @@ static void mesh_calc_modifiers(
/* create an orco derivedmesh in parallel */
if (nextmask & CD_MASK_ORCO) {
- if (!orcodm)
- orcodm = create_orco_dm(ob, me, NULL, CD_ORCO);
+ if (!orco_mesh) {
+ orco_mesh = create_orco_mesh(ob, me, NULL, CD_ORCO);
+ }
nextmask &= ~CD_MASK_ORCO;
- DM_set_only_copy(orcodm, nextmask | CD_MASK_ORIGINDEX |
+ mesh_set_only_copy(orco_mesh, nextmask | CD_MASK_ORIGINDEX |
(mti->requiredDataMask ?
mti->requiredDataMask(ob, md) : 0));
- ndm = modwrap_applyModifier(md, &mectx_orco, orcodm);
- ASSERT_IS_VALID_DM(ndm);
+ new_mesh = modifier_applyModifier_ensure_normals(md, &mectx_orco, orco_mesh);
+ ASSERT_IS_VALID_MESH(new_mesh);
- if (ndm) {
- /* if the modifier returned a new dm, release the old one */
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list