Edit Mesh: basic show in edit mode support
authorCampbell Barton <ideasman42@gmail.com>
Mon, 8 Oct 2018 06:29:59 +0000 (17:29 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 8 Oct 2018 06:31:32 +0000 (17:31 +1100)
Note this is just using the derived-mesh data at the moment,
to support this properly we'll need to remove derived-mesh.

source/blender/blenkernel/BKE_cdderivedmesh.h
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/draw/intern/draw_cache_impl_mesh.c

index 6d96bd6ab7cfae764965b2f1be1689f88be0b830..b31a3548a1e6e3b7d8a77a3b728c50d1fe9b16af 100644 (file)
@@ -178,4 +178,6 @@ void CDDM_set_mface(struct DerivedMesh *dm, struct MFace *mface);
 void CDDM_set_mloop(struct DerivedMesh *dm, struct MLoop *mloop);
 void CDDM_set_mpoly(struct DerivedMesh *dm, struct MPoly *mpoly);
 
+void CDDM_to_mesh__fast_borrow(struct DerivedMesh *dm, struct Mesh *me, const struct Mesh *me_reference);
+
 #endif
index 9043460562deb52547018b7eb3f459411d1a9390..83424da3a3d95eb1f9f123f1a6cf0adedd83e6ad 100644 (file)
@@ -2258,3 +2258,29 @@ void CDDM_set_mpoly(DerivedMesh *dm, MPoly *mpoly)
 
        cddm->mpoly = mpoly;
 }
+
+/** Hack to fill in an empty (non library mesh struct) with CDDM values. */
+void CDDM_to_mesh__fast_borrow(DerivedMesh *dm, Mesh *me, const Mesh *me_reference)
+{
+       CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
+       me->totvert = cddm->dm.numVertData;
+       me->totedge = cddm->dm.numEdgeData;
+       me->totloop = cddm->dm.numLoopData;
+       me->totpoly = cddm->dm.numPolyData;
+
+       me->mvert = cddm->mvert;
+       me->medge = cddm->medge;
+       me->mface = cddm->mface;
+       me->mloop = cddm->mloop;
+       me->mpoly = cddm->mpoly;
+
+       me->vdata = dm->vertData;
+       me->edata = dm->edgeData;
+       me->ldata = dm->loopData;
+       me->pdata = dm->polyData;
+
+       if (me_reference) {
+               me->mat = me_reference->mat;
+               me->totcol = me_reference->totcol;
+       }
+}
index 4fe7a32a8249966e508f1d80c37cbc73b322481f..e1787c2650b3f30f75fed275f543988dbbfdeb85 100644 (file)
@@ -53,6 +53,7 @@
 #include "BKE_mesh.h"
 #include "BKE_mesh_tangent.h"
 #include "BKE_colorband.h"
+#include "BKE_cdderivedmesh.h"
 
 #include "bmesh.h"
 
@@ -4459,6 +4460,19 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(
        MeshBatchCache *cache = mesh_batch_cache_get(me);
 
        if (cache->shaded_triangles == NULL) {
+
+               /* Hack to show the final result. */
+               const bool use_em_final = (
+                       me->edit_btmesh &&
+                       me->edit_btmesh->derivedFinal &&
+                       (me->edit_btmesh->derivedFinal->type == DM_TYPE_CDDM));
+               Mesh me_fake;
+               if (use_em_final) {
+                       memset(&me_fake, 0x0, sizeof(me_fake));
+                       CDDM_to_mesh__fast_borrow(me->edit_btmesh->derivedFinal, &me_fake, me);
+                       me = &me_fake;
+               }
+
                /* create batch from DM */
                const int datatype =
                        MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_LOOPTRI |