[Bf-blender-cvs] [88c88c46102] blender2.8: Fix T51210: Draw Manager: Support for Metaball Drawing

Germano noreply at git.blender.org
Thu Nov 16 18:12:44 CET 2017


Commit: 88c88c4610260ef3d00420c3e9fc3c1cd56aad14
Author: Germano
Date:   Thu Nov 16 15:12:32 2017 -0200
Branches: blender2.8
https://developer.blender.org/rB88c88c4610260ef3d00420c3e9fc3c1cd56aad14

Fix T51210: Draw Manager: Support for Metaball Drawing

Differential Revision: D2914

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

M	source/blender/blenkernel/BKE_mball.h
M	source/blender/blenkernel/intern/mball.c
M	source/blender/blenkernel/intern/object_update.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/draw/CMakeLists.txt
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache.h
M	source/blender/draw/intern/draw_cache_impl.h
M	source/blender/draw/intern/draw_cache_impl_displist.c
A	source/blender/draw/intern/draw_cache_impl_metaball.c
M	source/blender/draw/intern/draw_common.c
M	source/blender/draw/intern/draw_common.h
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/modes/edit_metaball_mode.c
M	source/blender/draw/modes/object_mode.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_shader.h
M	source/blender/gpu/intern/gpu_shader.c
A	source/blender/gpu/shaders/gpu_shader_instance_mball_helpers_vert.glsl
M	source/blender/makesdna/DNA_meta_types.h
M	source/blender/makesrna/intern/rna_meta_api.c

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

diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h
index 0c07ce55781..9db277f95fb 100644
--- a/source/blender/blenkernel/BKE_mball.h
+++ b/source/blender/blenkernel/BKE_mball.h
@@ -75,5 +75,16 @@ struct EvaluationContext;
 
 void BKE_mball_eval_geometry(const struct EvaluationContext *eval_ctx,
                              struct MetaBall *mball);
+/* Draw Cache */
+
+void BKE_mball_element_calc_display_m3x4(float r_scale_xform[3][4],
+                                         const float obmat[4][4],
+                                         const float local_pos[3]);
+
+enum {
+	BKE_MBALL_BATCH_DIRTY_ALL = 0,
+};
+void BKE_mball_batch_cache_dirty(struct MetaBall *mb, int mode);
+void BKE_mball_batch_cache_free(struct MetaBall *mb);
 
 #endif
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index f2c39d6cc72..d5cddf34eb5 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -75,6 +75,8 @@ void BKE_mball_free(MetaBall *mb)
 {
 	BKE_animdata_free((ID *)mb, false);
 
+	BKE_mball_batch_cache_free(mb);
+
 	MEM_SAFE_FREE(mb->mat);
 
 	BLI_freelistN(&mb->elems);
@@ -120,6 +122,7 @@ void BKE_mball_copy_data(Main *UNUSED(bmain), MetaBall *mb_dst, const MetaBall *
 
 	mb_dst->editelems = NULL;
 	mb_dst->lastelem = NULL;
+	mb_dst->batch_cache = NULL;
 }
 
 MetaBall *BKE_mball_copy(Main *bmain, const MetaBall *mb)
@@ -542,3 +545,47 @@ void BKE_mball_eval_geometry(const struct EvaluationContext *UNUSED(eval_ctx),
                              MetaBall *UNUSED(mball))
 {
 }
+
+/* Draw Engine */
+
+/* use for draw-manager only. */
+void BKE_mball_element_calc_display_m3x4(float r_scale_xform[3][4],
+                                         const float obmat[4][4],
+                                         const float local_pos[3])
+{
+	float world_pos[3], scamat[3][3];
+	mul_v3_m4v3(world_pos, obmat, local_pos);
+	copy_m3_m4(scamat, obmat);
+	{
+		/* Get the normalized inverse matrix to extract only
+		 * the scale of Scamat */
+		float iscamat[3][3];
+		invert_m3_m3(iscamat, scamat);
+		normalize_m3(iscamat);
+		mul_m3_m3_post(scamat, iscamat);
+	}
+
+	copy_v3_v3(r_scale_xform[0], scamat[0]);
+	copy_v3_v3(r_scale_xform[1], scamat[1]);
+	copy_v3_v3(r_scale_xform[2], scamat[2]);
+
+	r_scale_xform[0][3] = world_pos[0];
+	r_scale_xform[1][3] = world_pos[1];
+	r_scale_xform[2][3] = world_pos[2];
+}
+
+void (*BKE_mball_batch_cache_dirty_cb)(MetaBall *mb, int mode) = NULL;
+void (*BKE_mball_batch_cache_free_cb)(MetaBall *mb) = NULL;
+
+void BKE_mball_batch_cache_dirty(MetaBall *mb, int mode)
+{
+	if (mb->batch_cache) {
+		BKE_mball_batch_cache_dirty_cb(mb, mode);
+	}
+}
+void BKE_mball_batch_cache_free(MetaBall *mb)
+{
+	if (mb->batch_cache) {
+		BKE_mball_batch_cache_free_cb(mb);
+	}
+}
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index 665fc357a32..9c235fb8d8c 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -58,6 +58,7 @@
 #include "BKE_pointcache.h"
 #include "BKE_scene.h"
 #include "BKE_material.h"
+#include "BKE_mball.h"
 #include "BKE_mesh.h"
 #include "BKE_image.h"
 
@@ -322,6 +323,9 @@ void BKE_object_eval_uber_data(const EvaluationContext *eval_ctx,
 		case OB_SURF:
 			BKE_curve_batch_cache_dirty(ob->data, BKE_CURVE_BATCH_DIRTY_ALL);
 			break;
+		case OB_MBALL:
+			BKE_mball_batch_cache_dirty(ob->data, BKE_MBALL_BATCH_DIRTY_ALL);
+			break;
 	}
 
 	if (DEG_depsgraph_use_copy_on_write()) {
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 0fc00945b4c..7c08b909920 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3692,6 +3692,7 @@ static void direct_link_mball(FileData *fd, MetaBall *mb)
 	mb->editelems = NULL;
 /*	mb->edit_elems.first= mb->edit_elems.last= NULL;*/
 	mb->lastelem = NULL;
+	mb->batch_cache = NULL;
 }
 
 /* ************ READ WORLD ***************** */
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
index c3ae8050491..9c806f26fda 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -59,6 +59,7 @@ set(SRC
 	intern/draw_cache_impl_displist.c
 	intern/draw_cache_impl_lattice.c
 	intern/draw_cache_impl_mesh.c
+	intern/draw_cache_impl_metaball.c
 	intern/draw_cache_impl_particles.c
 	intern/draw_common.c
 	intern/draw_manager.c
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 13df65cf741..8010a232f89 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -507,6 +507,8 @@ Gwn_Batch *DRW_cache_object_surface_get(Object *ob)
 			return DRW_cache_surf_surface_get(ob);
 		case OB_FONT:
 			return DRW_cache_text_surface_get(ob);
+		case OB_MBALL:
+			return DRW_cache_mball_surface_get(ob);
 		default:
 			return NULL;
 	}
@@ -2336,6 +2338,19 @@ Gwn_Batch *DRW_cache_curve_surface_get(Object *ob)
 
 /* -------------------------------------------------------------------- */
 
+/** \name MetaBall
+ * \{ */
+
+Gwn_Batch *DRW_cache_mball_surface_get(Object *ob)
+{
+	BLI_assert(ob->type == OB_MBALL);
+	return DRW_metaball_batch_cache_get_triangles_with_normals(ob);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
 /** \name Font
  * \{ */
 
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
index 54b840edfe6..35ac8f4a35d 100644
--- a/source/blender/draw/intern/draw_cache.h
+++ b/source/blender/draw/intern/draw_cache.h
@@ -157,4 +157,7 @@ struct Gwn_Batch *DRW_cache_particles_get_hair(struct ParticleSystem *psys, stru
 struct Gwn_Batch *DRW_cache_particles_get_dots(struct ParticleSystem *psys);
 struct Gwn_Batch *DRW_cache_particles_get_prim(int type);
 
+/* Metaball */
+struct Gwn_Batch *DRW_cache_mball_surface_get(struct Object *ob);
+
 #endif /* __DRAW_CACHE_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
index 82972b9f75b..e0da2227a77 100644
--- a/source/blender/draw/intern/draw_cache_impl.h
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -38,6 +38,9 @@ struct Lattice;
 struct Mesh;
 
 /* Expose via BKE callbacks */
+void DRW_mball_batch_cache_dirty(struct MetaBall *mb, int mode);
+void DRW_mball_batch_cache_free(struct MetaBall *mb);
+
 void DRW_curve_batch_cache_dirty(struct Curve *cu, int mode);
 void DRW_curve_batch_cache_free(struct Curve *cu);
 
@@ -59,6 +62,9 @@ struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_verts(struct Curve *cu);
 
 struct Gwn_Batch *DRW_curve_batch_cache_get_triangles_with_normals(struct Curve *cu, struct CurveCache *ob_curve_cache);
 
+/* Metaball */
+struct Gwn_Batch *DRW_metaball_batch_cache_get_triangles_with_normals(struct Object *ob);
+
 /* Curve (Font) */
 struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_cursor(struct Curve *cu);
 struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_select(struct Curve *cu);
diff --git a/source/blender/draw/intern/draw_cache_impl_displist.c b/source/blender/draw/intern/draw_cache_impl_displist.c
index e051d61d056..96386f82faf 100644
--- a/source/blender/draw/intern/draw_cache_impl_displist.c
+++ b/source/blender/draw/intern/draw_cache_impl_displist.c
@@ -136,27 +136,31 @@ Gwn_Batch *BLI_displist_batch_calc_surface(ListBase *lb)
 		GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tri_len, vert_len);
 
 		int ofs = 0;
-		int tri_len_used = 0;
 		for (const DispList *dl = lb->first; dl; dl = dl->next) {
 			if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
+				const int *idx = dl->index;
 				if (dl->type == DL_INDEX3) {
-					const int *idx = dl->index;
 					const int i_end = dl->parts;
-					for (int i = 0; i < i_end; i++) {
+					for (int i = 0; i < i_end; i++, idx += 3) {
 						GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[1] + ofs, idx[2] + ofs);
-						tri_len_used += 1;
-						idx += 3;
 					}
 				}
-				else if (ELEM(dl->type, DL_INDEX4, DL_SURF)) {
-					const int *idx = dl->index;
+				else if (dl->type == DL_SURF) {
 					const int i_end = dl->totindex;
-					for (int i = 0; i < i_end; i++) {
+					for (int i = 0; i < i_end; i++, idx += 4) {
 						GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[1] + ofs, idx[2] + ofs);
-						tri_len_used += 1;
 						GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[2] + ofs, idx[3] + ofs);
-						tri_len_used += 1;
-						idx += 4;
+					}
+				}
+				else {
+					BLI_assert(dl->type == DL_INDEX4);
+					const int i_end = dl->parts;
+					for (int i = 0; i < i_end; i++, idx += 4) {
+						GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[1] + ofs, idx[2] + ofs);
+
+						if (idx[2] != idx[3]) {
+							GWN_indexbuf_add_tri_verts(&elb, idx[0] + ofs, idx[2] + ofs, idx[3] + ofs);
+						}
 					}
 				}
 				ofs += dl_vert_len(dl);
diff --git a/source/blender/draw/intern/draw_cache_impl_metaball.c b/source/blender/draw/intern/draw_cache_impl_metaball.c
new file mode 100644
index 00000000000..cf7d2f84133
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl_metaball.c
@@ -0,0 +1,196 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file dr

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list