[Bf-blender-cvs] [debd4210164] temp-vert-normals-cleanup: Merge branch 'master' into temp-vert-normals-cleanup

Hans Goudey noreply at git.blender.org
Sun Sep 12 18:31:41 CEST 2021


Commit: debd42101644d9836433985b250ac5d7c7a13d89
Author: Hans Goudey
Date:   Sat Sep 11 16:20:15 2021 -0500
Branches: temp-vert-normals-cleanup
https://developer.blender.org/rBdebd42101644d9836433985b250ac5d7c7a13d89

Merge branch 'master' into temp-vert-normals-cleanup

===================================================================



===================================================================

diff --cc source/blender/blenkernel/intern/displist.cc
index 4b247bb2418,f37978d14bb..79e7c2cee1d
--- a/source/blender/blenkernel/intern/displist.cc
+++ b/source/blender/blenkernel/intern/displist.cc
@@@ -911,152 -898,47 +898,47 @@@ static GeometrySet curve_calc_modifiers
        continue;
      }
  
-     /* If we need normals, no choice, have to convert to mesh now. */
-     const bool need_normal = mti->dependsOnNormals != nullptr && mti->dependsOnNormals(md);
-     /* XXX 2.8 : now that batch cache is stored inside the ob->data
-      * we need to create a Mesh for each curve that uses modifiers. */
-     if (modified == nullptr /* && need_normal */) {
-       if (vertCos != nullptr) {
-         displist_vert_coords_apply(dispbase, vertCos);
-       }
- 
-       if (ELEM(ob->type, OB_CURVE, OB_FONT) && (cu->flag & CU_DEFORM_FILL)) {
-         curve_to_filledpoly(cu, dispbase);
-       }
+     if (md->type == eModifierType_Nodes) {
+       mti->modifyGeometrySet(md, &mectx_apply, &geometry_set);
+       continue;
+     }
  
-       modified = BKE_mesh_new_nomain_from_curve_displist(ob, dispbase);
+     if (!geometry_set.has_mesh()) {
+       geometry_set.replace_mesh(BKE_mesh_new_nomain(0, 0, 0, 0, 0));
      }
+     Mesh *mesh = geometry_set.get_mesh_for_write();
  
-     if (mti->type == eModifierTypeType_OnlyDeform ||
-         (mti->type == eModifierTypeType_DeformOrConstruct && !modified)) {
-       if (modified) {
-         if (!vertCos) {
-           vertCos = BKE_mesh_vert_coords_alloc(modified, &totvert);
-         }
-         if (need_normal) {
-           BKE_mesh_ensure_vertex_normals(modified);
-         }
-         mti->deformVerts(md, &mectx_deform, modified, vertCos, totvert);
-       }
-       else {
-         if (!vertCos) {
-           vertCos = displist_vert_coords_alloc(dispbase, &totvert);
-         }
-         mti->deformVerts(md, &mectx_deform, nullptr, vertCos, totvert);
+     if (mti->type == eModifierTypeType_OnlyDeform) {
+       int totvert;
+       float(*vertex_coords)[3] = BKE_mesh_vert_coords_alloc(mesh, &totvert);
+       if (mti->dependsOnNormals != nullptr && mti->dependsOnNormals(md)) {
 -        BKE_mesh_ensure_normals(mesh);
++        BKE_mesh_ensure_vertex_normals(mesh);
        }
+       mti->deformVerts(md, &mectx_deform, mesh, vertex_coords, totvert);
+       BKE_mesh_vert_coords_apply(mesh, vertex_coords);
+       MEM_freeN(vertex_coords);
      }
      else {
-       if (!r_final) {
-         /* makeDisplistCurveTypes could be used for beveling, where mesh
-          * is totally unnecessary, so we could stop modifiers applying
-          * when we found constructive modifier but mesh is unwanted. */
-         break;
-       }
- 
-       if (modified) {
-         if (vertCos) {
-           Mesh *temp_mesh = (Mesh *)BKE_id_copy_ex(
-               nullptr, &modified->id, nullptr, LIB_ID_COPY_LOCALIZE);
-           BKE_id_free(nullptr, modified);
-           modified = temp_mesh;
- 
-           BKE_mesh_vert_coords_apply(modified, vertCos);
-         }
-       }
-       else {
-         if (vertCos) {
-           displist_vert_coords_apply(dispbase, vertCos);
-         }
- 
-         if (ELEM(ob->type, OB_CURVE, OB_FONT) && (cu->flag & CU_DEFORM_FILL)) {
-           curve_to_filledpoly(cu, dispbase);
-         }
- 
-         modified = BKE_mesh_new_nomain_from_curve_displist(ob, dispbase);
-       }
- 
-       if (vertCos) {
-         /* Vertex coordinates were applied to necessary data, could free it */
-         MEM_freeN(vertCos);
-         vertCos = nullptr;
-       }
- 
-       if (need_normal) {
-         BKE_mesh_ensure_vertex_normals(modified);
+       if (mti->dependsOnNormals != nullptr && mti->dependsOnNormals(md)) {
 -        BKE_mesh_ensure_normals(mesh);
++        BKE_mesh_ensure_vertex_normals(mesh);
        }
-       Mesh *mesh_applied = mti->modifyMesh(md, &mectx_apply, modified);
- 
-       if (mesh_applied) {
-         if (modified && modified != mesh_applied) {
-           BKE_id_free(nullptr, modified);
-         }
-         modified = mesh_applied;
+       Mesh *output_mesh = mti->modifyMesh(md, &mectx_apply, mesh);
+       if (mesh != output_mesh) {
+         geometry_set.replace_mesh(output_mesh);
        }
      }
    }
  
-   if (vertCos) {
-     if (modified) {
-       Mesh *temp_mesh = (Mesh *)BKE_id_copy_ex(
-           nullptr, &modified->id, nullptr, LIB_ID_COPY_LOCALIZE);
-       BKE_id_free(nullptr, modified);
-       modified = temp_mesh;
+   if (geometry_set.has_mesh()) {
+     Mesh *final_mesh = geometry_set.get_mesh_for_write();
  
-       BKE_mesh_vert_coords_apply(modified, vertCos);
-       BKE_mesh_calc_normals(modified);
 -    BKE_mesh_calc_normals(final_mesh);
++    BKE_mesh_ensure_normals_for_display(final_mesh);
  
-       MEM_freeN(vertCos);
-     }
-     else {
-       displist_vert_coords_apply(dispbase, vertCos);
-       MEM_freeN(vertCos);
-       vertCos = nullptr;
-     }
+     BLI_strncpy(final_mesh->id.name, cu->id.name, sizeof(final_mesh->id.name));
+     *((short *)final_mesh->id.name) = ID_ME;
    }
  
-   if (r_final) {
-     if (force_mesh_conversion && !modified) {
-       /* XXX 2.8 : This is a workaround for by some deeper technical debts:
-        * - DRW Batch cache is stored inside the ob->data.
-        * - Curve data is not COWed for instances that use different modifiers.
-        * This can causes the modifiers to be applied on all user of the same data-block
-        * (see T71055)
-        *
-        * The easy workaround is to force to generate a Mesh that will be used for display data
-        * since a Mesh output is already used for generative modifiers.
-        * However it does not fix problems with actual edit data still being shared.
-        *
-        * The right solution would be to COW the Curve data block at the input of the modifier
-        * stack just like what the mesh modifier does.
-        */
-       modified = BKE_mesh_new_nomain_from_curve_displist(ob, dispbase);
-     }
- 
-     if (modified) {
- 
-       /* XXX2.8(Sybren): make sure the face normals are recalculated as well */
-       BKE_mesh_ensure_vertex_normals(modified);
- 
-       /* Special tweaks, needed since neither BKE_mesh_new_nomain_from_template() nor
-        * BKE_mesh_new_nomain_from_curve_displist() properly duplicate mat info... */
-       BLI_strncpy(modified->id.name, cu->id.name, sizeof(modified->id.name));
-       *((short *)modified->id.name) = ID_ME;
-       MEM_SAFE_FREE(modified->mat);
-       /* Set flag which makes it easier to see what's going on in a debugger. */
-       modified->id.tag |= LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT;
-       modified->mat = (Material **)MEM_dupallocN(cu->mat);
-       modified->totcol = cu->totcol;
- 
-       (*r_final) = modified;
-     }
-     else {
-       (*r_final) = nullptr;
-     }
-   }
-   else if (modified != nullptr) {
-     /* Pretty stupid to generate that whole mesh if it's unused, yet we have to free it. */
-     BKE_id_free(nullptr, modified);
-   }
+   return geometry_set;
  }
  
  static void displist_surf_indices(DispList *dl)



More information about the Bf-blender-cvs mailing list