[Bf-blender-cvs] [1c294fb1fd4] blender-v2.90-release: Revert "Fix T77409: Crash showing vertex/face duplicators in edit-mode"

Sybren A. Stüvel noreply at git.blender.org
Tue Aug 11 16:13:46 CEST 2020


Commit: 1c294fb1fd4e9df7c0501a84a04c0a6e1ccbd003
Author: Sybren A. Stüvel
Date:   Tue Aug 11 16:12:44 2020 +0200
Branches: blender-v2.90-release
https://developer.blender.org/rB1c294fb1fd4e9df7c0501a84a04c0a6e1ccbd003

Revert "Fix T77409: Crash showing vertex/face duplicators in edit-mode"

This reverts commit 9adedb26055f03263fefba380980ee2abcb5327e. It changes
how duplis work, and by that altered how Alembic and USD files are
written. This was signalled by a failing Alembic unit test.

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

M	source/blender/blenkernel/intern/object_dupli.c

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

diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 2c71ef3f471..452c1657ed5 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -30,7 +30,6 @@
 #include "BLI_listbase.h"
 #include "BLI_string_utf8.h"
 
-#include "BLI_alloca.h"
 #include "BLI_math.h"
 #include "BLI_rand.h"
 
@@ -44,7 +43,6 @@
 #include "BKE_collection.h"
 #include "BKE_duplilist.h"
 #include "BKE_editmesh.h"
-#include "BKE_editmesh_cache.h"
 #include "BKE_font.h"
 #include "BKE_global.h"
 #include "BKE_idprop.h"
@@ -301,55 +299,6 @@ static void make_child_duplis(const DupliContext *ctx,
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Internal Data Access Utilities
- * \{ */
-
-static Mesh *mesh_data_from_duplicator_object(Object *ob,
-                                              BMEditMesh **r_em,
-                                              const float (**r_vert_coords)[3],
-                                              const float (**r_vert_normals)[3])
-{
-  /* Gather mesh info. */
-  BMEditMesh *em = BKE_editmesh_from_object(ob);
-  Mesh *me_eval;
-
-  *r_em = NULL;
-  *r_vert_coords = NULL;
-  if (r_vert_normals != NULL) {
-    *r_vert_normals = NULL;
-  }
-
-  /* We do not need any render-specific handling anymore, depsgraph takes care of that. */
-  /* NOTE: Do direct access to the evaluated mesh: this function is used
-   * during meta balls evaluation. But even without those all the objects
-   * which are needed for correct instancing are already evaluated. */
-  if (em != NULL) {
-    /* Note that this will only show deformation if #eModifierMode_OnCage is enabled.
-     * We could change this but it matches 2.7x behavior. */
-    me_eval = em->mesh_eval_cage;
-    if ((me_eval == NULL) || (me_eval->runtime.wrapper_type == ME_WRAPPER_TYPE_BMESH)) {
-      *r_em = em;
-      if (me_eval != NULL) {
-        EditMeshData *emd = me_eval->runtime.edit_data;
-        if ((emd != NULL) && (emd->vertexCos != NULL)) {
-          *r_vert_coords = emd->vertexCos;
-          if (r_vert_normals != NULL) {
-            BKE_editmesh_cache_ensure_vert_normals(em, emd);
-            *r_vert_normals = emd->vertexNos;
-          }
-        }
-      }
-    }
-  }
-  else {
-    me_eval = BKE_object_get_evaluated_mesh(ob);
-  }
-  return me_eval;
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Dupli-Collection Implementation (#OB_DUPLICOLLECTION)
  * \{ */
@@ -399,178 +348,124 @@ static const DupliGenerator gen_dupli_collection = {
 /** \name Dupli-Vertices Implementation (#OB_DUPLIVERTS for Geometry)
  * \{ */
 
-typedef struct VertexDupliData_Mesh {
+typedef struct VertexDupliData {
   Mesh *me_eval;
-
+  BMEditMesh *edit_mesh;
   int totvert;
-  MVert *mvert;
-
   float (*orco)[3];
-
   bool use_rotation;
-} VertexDupliData_Mesh;
-
-typedef struct VertexDupliData_BMesh {
-  BMEditMesh *em;
 
-  /* Can be NULL. */
-  const float (*vert_coords)[3];
-  const float (*vert_normals)[3];
-
-  bool has_orco;
-  bool use_rotation;
-} VertexDupliData_BMesh;
+  const DupliContext *ctx;
+  Object *inst_ob; /* object to instantiate (argument for vertex map callback) */
+  float child_imat[4][4];
+} VertexDupliData;
 
 static void get_duplivert_transform(const float co[3],
-                                    const float no[3],
-                                    const bool use_rotation,
+                                    const short no[3],
+                                    bool use_rotation,
                                     short axis,
                                     short upflag,
-                                    float r_mat[4][4])
+                                    float mat[4][4])
 {
   float quat[4];
   const float size[3] = {1.0f, 1.0f, 1.0f};
 
   if (use_rotation) {
-    /* Construct rotation matrix from normals. */
-    float no_flip[3];
-    negate_v3_v3(no_flip, no);
-    vec_to_quat(quat, no_flip, axis, upflag);
+    /* construct rotation matrix from normals */
+    float nor_f[3];
+    nor_f[0] = (float)-no[0];
+    nor_f[1] = (float)-no[1];
+    nor_f[2] = (float)-no[2];
+    vec_to_quat(quat, nor_f, axis, upflag);
   }
   else {
     unit_qt(quat);
   }
 
-  loc_quat_size_to_mat4(r_mat, co, quat, size);
+  loc_quat_size_to_mat4(mat, co, quat, size);
 }
 
-/**
- * \param no: The direction, doesn't need to be normalized.
- */
-static DupliObject *vertex_dupli(const DupliContext *ctx,
-                                 Object *child,
-                                 const float child_imat[4][4],
-                                 int index,
-                                 float space_mat[4][4])
+static void vertex_dupli(const VertexDupliData *vdd,
+                         int index,
+                         const float co[3],
+                         const short no[3])
 {
-  float obmat[4][4];
+  Object *inst_ob = vdd->inst_ob;
+  DupliObject *dob;
+  float obmat[4][4], space_mat[4][4];
 
-  /* Make offset relative to child using relative child transform. */
-  mul_mat3_m4_v3(child_imat, space_mat[3]);
+  /* obmat is transform to vertex */
+  get_duplivert_transform(co, no, vdd->use_rotation, inst_ob->trackflag, inst_ob->upflag, obmat);
+  /* make offset relative to inst_ob using relative child transform */
+  mul_mat3_m4_v3((float(*)[4])vdd->child_imat, obmat[3]);
+  /* apply obmat _after_ the local vertex transform */
+  mul_m4_m4m4(obmat, inst_ob->obmat, obmat);
 
-  /* Apply `obmat` _after_ the local vertex transform. */
-  mul_m4_m4m4(obmat, child->obmat, space_mat);
+  /* space matrix is constructed by removing obmat transform,
+   * this yields the worldspace transform for recursive duplis
+   */
+  mul_m4_m4m4(space_mat, obmat, inst_ob->imat);
 
-  DupliObject *dob = make_dupli(ctx, child, obmat, index);
+  dob = make_dupli(vdd->ctx, vdd->inst_ob, obmat, index);
 
-  /* Recursion. */
-  make_recursive_duplis(ctx, child, space_mat, index);
+  if (vdd->orco) {
+    copy_v3_v3(dob->orco, vdd->orco[index]);
+  }
 
-  return dob;
+  /* recursion */
+  make_recursive_duplis(vdd->ctx, vdd->inst_ob, space_mat, index);
 }
 
-static void make_child_duplis_verts_from_mesh(const DupliContext *ctx,
-                                              void *userdata,
-                                              Object *child)
+static void make_child_duplis_verts(const DupliContext *ctx, void *userdata, Object *child)
 {
-  VertexDupliData_Mesh *vdd = userdata;
-
-  const MVert *mvert = vdd->mvert;
-  const int totvert = vdd->totvert;
+  VertexDupliData *vdd = userdata;
+  Mesh *me_eval = vdd->me_eval;
 
+  vdd->inst_ob = child;
   invert_m4_m4(child->imat, child->obmat);
-  /* Relative transform from parent to child space. */
-  float child_imat[4][4];
-  mul_m4_m4m4(child_imat, child->imat, ctx->object->obmat);
-
-  const MVert *mv = mvert;
-  for (int i = 0; i < totvert; i++, mv++) {
-    const float no[3] = {mv->no[0], mv->no[1], mv->no[2]};
-    /* space_mat is transform to vertex. */
-    float space_mat[4][4];
-    get_duplivert_transform(
-        mv->co, no, vdd->use_rotation, child->trackflag, child->upflag, space_mat);
-    DupliObject *dob = vertex_dupli(ctx, child, child_imat, i, space_mat);
-    if (vdd->orco) {
-      copy_v3_v3(dob->orco, vdd->orco[i]);
-    }
+  /* relative transform from parent to child space */
+  mul_m4_m4m4(vdd->child_imat, child->imat, ctx->object->obmat);
+
+  const MVert *mvert = me_eval->mvert;
+  for (int i = 0; i < me_eval->totvert; i++) {
+    vertex_dupli(vdd, i, mvert[i].co, mvert[i].no);
   }
 }
 
-static void make_child_duplis_verts_from_bmesh(const DupliContext *ctx,
-                                               void *userdata,
-                                               Object *child)
+static void make_duplis_verts(const DupliContext *ctx)
 {
-  VertexDupliData_BMesh *vdd = userdata;
-  BMEditMesh *em = vdd->em;
-
-  invert_m4_m4(child->imat, child->obmat);
-  /* Relative transform from parent to child space. */
-  float child_imat[4][4];
-  mul_m4_m4m4(child_imat, child->imat, ctx->object->obmat);
-
-  BMVert *v;
-  BMIter iter;
-  int i;
+  Object *parent = ctx->object;
+  VertexDupliData vdd;
 
-  const float(*vert_coords)[3] = vdd->vert_coords;
-  const float(*vert_normals)[3] = vdd->vert_normals;
+  vdd.ctx = ctx;
+  vdd.use_rotation = parent->transflag & OB_DUPLIROT;
 
-  BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) {
-    const float *co, *no;
-    if (vert_coords != NULL) {
-      co = vert_coords[i];
-      no = vert_normals[i];
+  /* gather mesh info */
+  {
+    vdd.edit_mesh = BKE_editmesh_from_object(parent);
+
+    /* We do not need any render-specific handling anymore, depsgraph takes care of that. */
+    /* NOTE: Do direct access to the evaluated mesh: this function is used
+     * during meta balls evaluation. But even without those all the objects
+     * which are needed for correct instancing are already evaluated. */
+    if (vdd.edit_mesh != NULL) {
+      vdd.me_eval = vdd.edit_mesh->mesh_eval_cage;
     }
     else {
-      co = v->co;
-      no = v->no;
+      vdd.me_eval = BKE_object_get_evaluated_mesh(parent);
     }
 
-    /* space_mat is transform to vertex. */
-    float space_mat[4][4];
-    get_duplivert_transform(co, no, vdd->use_rotation, child->trackflag, child->upflag, space_mat);
-    DupliObject *dob = vertex_dupli(ctx, child, child_imat, i, space_mat);
-    if (vdd->has_orco) {
-      copy_v3_v3(dob->orco, v->co);
+    if (vdd.me_eval == NULL) {
+      return;
     }
-  }
-}
-
-static void make_duplis_verts(const DupliContext *ctx)
-{
-  Object *parent = ctx->object;
-
-  const bool use_rotation = parent->transflag & OB_DUPLIROT;
 
-  /* Gather mesh info. */
-  BMEditMesh *em = NULL;
-  const float(*vert_coords)[3] = NULL;
-  const float(*vert_normals)[3] = NULL;
-  Mesh *me_eval = mesh_data_from_duplicator_object(parent, &em, &vert_coords, &vert_normals);
-  if (em == NULL && me_eval == NULL) {
-    return;
+    vdd.orco = CustomData_get_layer(&vdd.me_eval->vdata, CD_ORCO);
+    vdd.totvert = vdd.me_eval->totvert;
   }
 
- 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list