[Bf-blender-cvs] [3ca1cf2b519] master: Cleanup: Move object_dupli.cc to C++

Hans Goudey noreply at git.blender.org
Thu Apr 1 22:55:06 CEST 2021


Commit: 3ca1cf2b5197c0c2d5afa44ac28e7b63d401b489
Author: Hans Goudey
Date:   Thu Apr 1 15:54:48 2021 -0500
Branches: master
https://developer.blender.org/rB3ca1cf2b5197c0c2d5afa44ac28e7b63d401b489

Cleanup: Move object_dupli.cc to C++

This will hopefully allow more refactoring in the future to improve
the instancing system, especially how it relates to geometry nodes
instances.

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

M	source/blender/blenkernel/CMakeLists.txt
R087	source/blender/blenkernel/intern/object_dupli.c	source/blender/blenkernel/intern/object_dupli.cc

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

diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 8fbf49b31d4..f1f08b3ad3a 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -212,7 +212,7 @@ set(SRC
   intern/node_ui_storage.cc
   intern/object.c
   intern/object_deform.c
-  intern/object_dupli.c
+  intern/object_dupli.cc
   intern/object_facemap.c
   intern/object_update.c
   intern/ocean.c
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.cc
similarity index 87%
rename from source/blender/blenkernel/intern/object_dupli.c
rename to source/blender/blenkernel/intern/object_dupli.cc
index 632e7519f05..1830870b854 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.cc
@@ -21,9 +21,9 @@
  * \ingroup bke
  */
 
-#include <limits.h>
-#include <stddef.h>
-#include <stdlib.h>
+#include <climits>
+#include <cstddef>
+#include <cstdlib>
 
 #include "MEM_guardedalloc.h"
 
@@ -69,7 +69,7 @@
 /** \name Internal Duplicate Context
  * \{ */
 
-typedef struct DupliContext {
+struct DupliContext {
   Depsgraph *depsgraph;
   /** XXX child objects are selected from this group if set, could be nicer. */
   Collection *collection;
@@ -88,12 +88,12 @@ typedef struct DupliContext {
 
   /** Result containers. */
   ListBase *duplilist; /* Legacy doubly-linked list. */
-} DupliContext;
+};
 
-typedef struct DupliGenerator {
+struct DupliGenerator {
   short type; /* Dupli Type, see members of #OB_DUPLI. */
   void (*make_duplis)(const DupliContext *ctx);
-} DupliGenerator;
+};
 
 static const DupliGenerator *get_dupli_generator(const DupliContext *ctx);
 
@@ -109,7 +109,7 @@ static void init_context(DupliContext *r_ctx,
   r_ctx->depsgraph = depsgraph;
   r_ctx->scene = scene;
   r_ctx->view_layer = DEG_get_evaluated_view_layer(depsgraph);
-  r_ctx->collection = NULL;
+  r_ctx->collection = nullptr;
 
   r_ctx->object = ob;
   r_ctx->obedit = OBEDIT_FROM_OBACT(ob);
@@ -123,7 +123,7 @@ static void init_context(DupliContext *r_ctx,
 
   r_ctx->gen = get_dupli_generator(r_ctx);
 
-  r_ctx->duplilist = NULL;
+  r_ctx->duplilist = nullptr;
 }
 
 /**
@@ -165,11 +165,11 @@ static DupliObject *make_dupli(const DupliContext *ctx,
 
   /* Add a #DupliObject instance to the result container. */
   if (ctx->duplilist) {
-    dob = MEM_callocN(sizeof(DupliObject), "dupli object");
+    dob = (DupliObject *)MEM_callocN(sizeof(DupliObject), "dupli object");
     BLI_addtail(ctx->duplilist, dob);
   }
   else {
-    return NULL;
+    return nullptr;
   }
 
   dob->ob = ob;
@@ -242,7 +242,7 @@ static void make_recursive_duplis(const DupliContext *ctx,
 /** \name Internal Child Duplicates (Used by Other Functions)
  * \{ */
 
-typedef void (*MakeChildDuplisFunc)(const DupliContext *ctx, void *userdata, Object *child);
+using MakeChildDuplisFunc = void (*)(const DupliContext *ctx, void *userdata, Object *child);
 
 static bool is_child(const Object *ob, const Object *parent)
 {
@@ -270,7 +270,7 @@ static void make_child_duplis(const DupliContext *ctx,
     FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_BEGIN (ctx->collection, ob, mode) {
       if ((ob != ctx->obedit) && is_child(ob, parent)) {
         DupliContext pctx;
-        copy_dupli_context(&pctx, ctx, ctx->object, NULL, _base_id);
+        copy_dupli_context(&pctx, ctx, ctx->object, nullptr, _base_id);
 
         /* Meta-balls have a different dupli handling. */
         if (ob->type != OB_MBALL) {
@@ -282,13 +282,13 @@ static void make_child_duplis(const DupliContext *ctx,
     FOREACH_COLLECTION_VISIBLE_OBJECT_RECURSIVE_END;
   }
   else {
-    int baseid = 0;
+    int baseid;
     ViewLayer *view_layer = ctx->view_layer;
-    for (Base *base = view_layer->object_bases.first; base; base = base->next, baseid++) {
+    LISTBASE_FOREACH_INDEX (Base *, base, &view_layer->object_bases, baseid) {
       Object *ob = base->object;
       if ((ob != ctx->obedit) && is_child(ob, parent)) {
         DupliContext pctx;
-        copy_dupli_context(&pctx, ctx, ctx->object, NULL, baseid);
+        copy_dupli_context(&pctx, ctx, ctx->object, nullptr, baseid);
 
         /* Meta-balls have a different dupli-handling. */
         if (ob->type != OB_MBALL) {
@@ -316,30 +316,30 @@ static Mesh *mesh_data_from_duplicator_object(Object *ob,
   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;
+  *r_em = nullptr;
+  *r_vert_coords = nullptr;
+  if (r_vert_normals != nullptr) {
+    *r_vert_normals = nullptr;
   }
 
   /* 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) {
+  if (em != nullptr) {
     /* 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)) {
-      EditMeshData *emd = me_eval ? me_eval->runtime.edit_data : NULL;
+    if ((me_eval == nullptr) || (me_eval->runtime.wrapper_type == ME_WRAPPER_TYPE_BMESH)) {
+      EditMeshData *emd = me_eval ? me_eval->runtime.edit_data : nullptr;
 
       /* Only assign edit-mesh in the case we can't use `me_eval`. */
       *r_em = em;
-      me_eval = NULL;
+      me_eval = nullptr;
 
-      if ((emd != NULL) && (emd->vertexCos != NULL)) {
+      if ((emd != nullptr) && (emd->vertexCos != nullptr)) {
         *r_vert_coords = emd->vertexCos;
-        if (r_vert_normals != NULL) {
+        if (r_vert_normals != nullptr) {
           BKE_editmesh_cache_ensure_vert_normals(em, emd);
           *r_vert_normals = emd->vertexNos;
         }
@@ -364,7 +364,7 @@ static void make_duplis_collection(const DupliContext *ctx)
   Collection *collection;
   float collection_mat[4][4];
 
-  if (ob->instance_collection == NULL) {
+  if (ob->instance_collection == nullptr) {
     return;
   }
   collection = ob->instance_collection;
@@ -404,7 +404,7 @@ static const DupliGenerator gen_dupli_collection = {
  * \{ */
 
 /** Values shared between different mesh types. */
-typedef struct VertexDupliData_Params {
+struct VertexDupliData_Params {
   /**
    * It's important we use this context instead of the `ctx` passed into #make_child_duplis
    * since these won't match in the case of recursion.
@@ -412,23 +412,23 @@ typedef struct VertexDupliData_Params {
   const DupliContext *ctx;
 
   bool use_rotation;
-} VertexDupliData_Params;
+};
 
-typedef struct VertexDupliData_Mesh {
+struct VertexDupliData_Mesh {
   VertexDupliData_Params params;
 
   int totvert;
   const MVert *mvert;
 
   const float (*orco)[3];
-} VertexDupliData_Mesh;
+};
 
-typedef struct VertexDupliData_EditMesh {
+struct VertexDupliData_EditMesh {
   VertexDupliData_Params params;
 
   BMEditMesh *em;
 
-  /* Can be NULL. */
+  /* Can be nullptr. */
   const float (*vert_coords)[3];
   const float (*vert_normals)[3];
 
@@ -440,7 +440,7 @@ typedef struct VertexDupliData_EditMesh {
    * edit-mesh to be converted into a mesh.
    */
   bool has_orco;
-} VertexDupliData_EditMesh;
+};
 
 /**
  * \param no: The direction,
@@ -505,7 +505,7 @@ static void make_child_duplis_verts_from_mesh(const DupliContext *ctx,
                                               void *userdata,
                                               Object *inst_ob)
 {
-  VertexDupliData_Mesh *vdd = userdata;
+  VertexDupliData_Mesh *vdd = (VertexDupliData_Mesh *)userdata;
   const bool use_rotation = vdd->params.use_rotation;
 
   const MVert *mvert = vdd->mvert;
@@ -519,7 +519,8 @@ static void make_child_duplis_verts_from_mesh(const DupliContext *ctx,
   const MVert *mv = mvert;
   for (int i = 0; i < totvert; i++, mv++) {
     const float *co = mv->co;
-    const float no[3] = {UNPACK3(mv->no)};
+    float no[3];
+    normal_short_to_float_v3(no, mv->no);
     DupliObject *dob = vertex_dupli(vdd->params.ctx, inst_ob, child_imat, i, co, no, use_rotation);
     if (vdd->orco) {
       copy_v3_v3(dob->orco, vdd->orco[i]);
@@ -531,7 +532,7 @@ static void make_child_duplis_verts_from_editmesh(const DupliContext *ctx,
                                                   void *userdata,
                                                   Object *inst_ob)
 {
-  VertexDupliData_EditMesh *vdd = userdata;
+  VertexDupliData_EditMesh *vdd = (VertexDupliData_EditMesh *)userdata;
   BMEditMesh *em = vdd->em;
   const bool use_rotation = vdd->params.use_rotation;
 
@@ -549,9 +550,9 @@ static void make_child_duplis_verts_from_editmesh(const DupliContext *ctx,
 
   BM_ITER_MESH_INDEX (v, &iter, em->bm, BM_VERTS_OF_MESH, i) {
     const float *co, *no;
-    if (vert_coords != NULL) {
+    if (vert_coords != nullptr) {
       co = vert_coords[i];
-      no = vert_normals ? vert_normals[i] : NULL;
+      no = vert_normals ? vert_normals[i] : nullptr;
     }
     else {
       co = v->co;
@@ -571,37 +572,34 @@ static void make_duplis_verts(const DupliContext *ctx)
   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;
+  BMEditMesh *em = nullptr;
+  const float(*vert_coords)[3] = nullptr;
+  const float(*vert_normals)[3] = nullptr;
   Mesh *me_eval = mesh_data_from_duplicator_object(
-      parent, &em, &vert_coords, use_rotation ? &vert_normals : NULL);
-  if (em == NULL && me_eval == NULL) {
+      parent, &em, &vert_coords, use_rotation ? &vert_normals : nullptr);
+  if (em == nullptr && me_eval == nullptr) {
     return;
   }
 
-  VertexDupliData_Params vdd_params = {
-      .ctx = ctx,
-      .use_rotation = use_rotation,
-  };
+  VertexDupliData_Params vdd_params{ctx, use_rotation};
+
+  if (em != nullptr) {
+    VertexDupliData_EditMesh vdd{};
+    vdd.params = vdd_params;
+    vdd.em = em

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list