[Bf-blender-cvs] [dc93c57] particles_refactor: Basic display feature for particles. This is organized as a list of NParticleDisplay in the modifier for now. Each NParticleDisplay adds a visualization element of some type in the viewport, which will allow combining elements for custom attributes with standard display modes for particles.

Lukas Tönne noreply at git.blender.org
Tue Apr 22 12:06:07 CEST 2014


Commit: dc93c57b41de9360887fedf0430b831530a7e5b7
Author: Lukas Tönne
Date:   Wed Dec 18 10:47:43 2013 +0100
https://developer.blender.org/rBdc93c57b41de9360887fedf0430b831530a7e5b7

Basic display feature for particles. This is organized as a list of
NParticleDisplay in the modifier for now. Each NParticleDisplay adds
a visualization element of some type in the viewport, which will allow
combining elements for custom attributes with standard display modes
for particles.

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

M	source/blender/blenkernel/BKE_nparticle.h
M	source/blender/blenkernel/intern/nparticle.c
M	source/blender/editors/space_view3d/CMakeLists.txt
M	source/blender/editors/space_view3d/drawobject.c
A	source/blender/editors/space_view3d/drawparticles.c
M	source/blender/editors/space_view3d/view3d_intern.h
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesdna/DNA_nparticle_types.h
M	source/blender/modifiers/intern/MOD_nparticle.c

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

diff --git a/source/blender/blenkernel/BKE_nparticle.h b/source/blender/blenkernel/BKE_nparticle.h
index 74d21c8..5529864 100644
--- a/source/blender/blenkernel/BKE_nparticle.h
+++ b/source/blender/blenkernel/BKE_nparticle.h
@@ -35,6 +35,7 @@ struct NParticleSystem;
 struct NParticleAttribute;
 struct NParticleState;
 struct NParticleAttributeState;
+struct NParticleDisplay;
 
 /* XXX where to put this? */
 typedef uint32_t NParticleID;
@@ -73,6 +74,14 @@ int BKE_nparticle_iter_get_int(struct NParticleIterator *it, const char *attr);
 void BKE_nparticle_iter_set_int(struct NParticleIterator *it, const char *attr, int value);
 float BKE_nparticle_iter_get_float(struct NParticleIterator *it, const char *attr);
 void BKE_nparticle_iter_set_float(struct NParticleIterator *it, const char *attr, float value);
+void BKE_nparticle_iter_get_vector(struct NParticleIterator *it, const char *attr, float *result);
+void BKE_nparticle_iter_set_vector(struct NParticleIterator *it, const char *attr, const float *value);
+
+
+struct NParticleDisplay *BKE_nparticle_display_particle(void);
+struct NParticleDisplay *BKE_nparticle_display_copy(struct NParticleDisplay *display);
+void BKE_nparticle_display_free(struct NParticleDisplay *display);
+
 
 #if 0 /* old code */
 #include "BLI_math.h"
diff --git a/source/blender/blenkernel/intern/nparticle.c b/source/blender/blenkernel/intern/nparticle.c
index 312c091..4bc6f5e 100644
--- a/source/blender/blenkernel/intern/nparticle.c
+++ b/source/blender/blenkernel/intern/nparticle.c
@@ -29,12 +29,12 @@
 #include <string.h>
 #include "MEM_guardedalloc.h"
 
-#include "BLI_utildefines.h"
+#include "BLI_utildefines.h"	/* XXX stupid, needed by ghash, should be included there ... */
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
+#include "BLI_math.h"
 #include "BLI_pagedbuffer.h"
 #include "BLI_string.h"
-#include "BLI_utildefines.h"
 
 #include "DNA_nparticle_types.h"
 
@@ -452,6 +452,48 @@ void BKE_nparticle_iter_set_float(NParticleIterator *it, const char *attr, float
 		*data = value;
 }
 
+void BKE_nparticle_iter_get_vector(NParticleIterator *it, const char *attr, float *result)
+{
+	float *data = nparticle_data_ptr(it->state, attr, it->index);
+	BLI_assert(nparticle_check_attribute_type(it->state, attr, PAR_ATTR_DATATYPE_VECTOR)
+	           || nparticle_check_attribute_type(it->state, attr, PAR_ATTR_DATATYPE_POINT)
+	           || nparticle_check_attribute_type(it->state, attr, PAR_ATTR_DATATYPE_NORMAL));
+	if (data)
+		copy_v3_v3(result, data);
+	else
+		zero_v3(result);
+}
+
+void BKE_nparticle_iter_set_vector(NParticleIterator *it, const char *attr, const float *value)
+{
+	float *data = nparticle_data_ptr(it->state, attr, it->index);
+	BLI_assert(nparticle_check_attribute_type(it->state, attr, PAR_ATTR_DATATYPE_VECTOR)
+	           || nparticle_check_attribute_type(it->state, attr, PAR_ATTR_DATATYPE_POINT)
+	           || nparticle_check_attribute_type(it->state, attr, PAR_ATTR_DATATYPE_NORMAL));
+	if (data)
+		copy_v3_v3(data, value);
+}
+
+
+NParticleDisplay *BKE_nparticle_display_particle(void)
+{
+	NParticleDisplay *display = MEM_callocN(sizeof(NParticleDisplay), "particle display");
+	display->type = PAR_DISPLAY_PARTICLE;
+	BLI_strncpy(display->attribute, "position", sizeof(display->attribute));
+	return display;
+}
+
+NParticleDisplay *BKE_nparticle_display_copy(NParticleDisplay *display)
+{
+	NParticleDisplay *ndisplay = MEM_dupallocN(display);
+	return ndisplay;
+}
+
+void BKE_nparticle_display_free(NParticleDisplay *display)
+{
+	MEM_freeN(display);
+}
+
 
 #if 0 /* old code */
 #include <assert.h>
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index 97c328d..2d724ed 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -43,6 +43,7 @@ set(SRC
 	drawarmature.c
 	drawmesh.c
 	drawobject.c
+	drawparticles.c
 	drawvolume.c
 	space_view3d.c
 	view3d_buttons.c
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 84b3935..5a59153 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -37,6 +37,7 @@
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meta_types.h"
+#include "DNA_nparticle_types.h"
 #include "DNA_rigidbody_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_smoke_types.h"
@@ -7190,6 +7191,25 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short
 		}
 	}
 
+	/* nparticles */
+	if ((md = modifiers_findByType(ob, eModifierType_NParticleSystem))) {
+		NParticleSystemModifierData *pmd = (NParticleSystemModifierData *)md;
+		NParticleDisplay *display;
+		
+		if (col || (ob->flag & SELECT))
+			cpack(0xFFFFFF);
+		
+		glLoadMatrixf(rv3d->viewmat);
+		
+		for (display = pmd->display.first; display; display = display->next)
+			draw_nparticles(pmd->psys, display);
+		
+		glMultMatrixf(ob->obmat);
+		
+		if (col)
+			cpack(col);
+	}
+
 	/* draw code for smoke */
 	if ((md = modifiers_findByType(ob, eModifierType_Smoke))) {
 		SmokeModifierData *smd = (SmokeModifierData *)md;
diff --git a/source/blender/editors/space_view3d/drawparticles.c b/source/blender/editors/space_view3d/drawparticles.c
new file mode 100644
index 0000000..8eccec5
--- /dev/null
+++ b/source/blender/editors/space_view3d/drawparticles.c
@@ -0,0 +1,72 @@
+/*
+ * ***** 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) 2013 by the Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/drawparticles.c
+ *  \ingroup spview3d
+ */
+
+#include "DNA_nparticle_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BKE_nparticle.h"
+
+#include "BIF_gl.h"
+
+#include "view3d_intern.h"
+
+static void draw_particles(NParticleSystem *psys, const char *attr_pos)
+{
+	NParticleIterator it;
+	float pos[3];
+	
+	if (!psys->state)
+		return;
+	
+	glPointSize(2.0);
+	
+	glBegin(GL_POINTS);
+	for (BKE_nparticle_iter_init(psys->state, &it); BKE_nparticle_iter_valid(&it); BKE_nparticle_iter_next(&it)) {
+		BKE_nparticle_iter_get_vector(&it, attr_pos, pos);
+		glVertex3fv(pos);
+	}
+	glEnd();
+	
+	glPointSize(1.0);
+}
+
+void draw_nparticles(NParticleSystem *psys, NParticleDisplay *display)
+{
+	switch (display->type) {
+		case PAR_DISPLAY_PARTICLE:
+			draw_particles(psys, display->attribute);
+			break;
+	}
+}
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 9bc4988..2210cbb 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -39,6 +39,8 @@ struct ARegion;
 struct ARegionType;
 struct BoundBox;
 struct DerivedMesh;
+struct NParticleDisplay;
+struct NParticleSystem;
 struct Object;
 struct SmokeDomainSettings;
 struct ViewContext;
@@ -173,6 +175,9 @@ void draw_mesh_paint_weight_edges(RegionView3D *rv3d, struct DerivedMesh *dm,
 void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d,
                      struct Object *ob, struct DerivedMesh *dm, const int draw_flags);
 
+/* drawparticles.c */
+void draw_nparticles(struct NParticleSystem *psys, struct NParticleDisplay *display);
+
 /* view3d_draw.c */
 void view3d_main_area_draw(const struct bContext *C, struct ARegion *ar);
 void draw_depth(Scene *scene, struct ARegion *ar, View3D *v3d, int (*func)(void *), bool alphaoverride);
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 297fc8c..85e8dd4 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1368,6 +1368,7 @@ typedef struct NParticleSystemModifierData {
 	ModifierData modifier;
 	
 	struct NParticleSystem *psys;
+	ListBase display;
 } NParticleSystemModifierData;
 
 
diff --git a/source/blender/makesdna/DNA_nparticle_types.h b/source/blender/makesdna/DNA_nparticle_types.h
index fd33a36..985602b 100644
--- a/source/blender/makesdna/DNA_nparticle_types.h
+++ b/source/blender/makesdna/DNA_nparticle_types.h
@@ -94,4 +94,17 @@ typedef struct NParticleSystem {
 	struct NParticleState *state;
 } NParticleSystem;
 
+
+typedef struct NParticleDisplay {
+	struct NParticleDisplay *next, *prev;
+	
+	int type;
+	int pad;
+	char attribute[64];
+} NParticleDisplay;
+
+typedef enum eParticleDisplayType {
+	PAR_DISPLAY_PARTICLE		= 1
+} eParticleDisplayType;
+
 #endif
diff --git a/source/blender/modifiers/intern/MOD_nparticle.c b/source/blender/modifiers/intern/MOD_nparticle.c
index 28a8e12..4bfd7c5 100644
--- a/source/blender/modifiers/intern/MOD_nparticle.c
+++ b/source/blender/modifiers/intern/MOD_nparticle.c
@@ -30,7 +30,10 @@
  *  \ingroup modifiers
  */
 
+#include "BLI_listbase.h"
+
 #include "DNA_modifier_types.h"
+#include "DNA_nparticle_types.h"
 
 #include "BKE_modifier.h"
 #include "BKE_nparticle.h"
@@ -41,12 +44,24 @@ struct Object;
 static void nparticle_system_initData(ModifierData *md) 
 {
 	NParticleSystemModifierData *pmd= (NParticleSystemModifierData *)md;
+	
 	pmd->psys = BKE_nparticle_system_new();
+	
+	/* add default particle display *

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list