[Bf-blender-cvs] [b690f22] gooseberry: Basic drawing code for strands loaded from caches.
Lukas Tönne
noreply at git.blender.org
Wed Mar 25 18:07:46 CET 2015
Commit: b690f220e2305407e191b3d732d9759fa3d4dcfa
Author: Lukas Tönne
Date: Wed Mar 25 18:07:03 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBb690f220e2305407e191b3d732d9759fa3d4dcfa
Basic drawing code for strands loaded from caches.
This is entirely separate from particle systems and their insane
drawing function.
===================================================================
M source/blender/blenkernel/BKE_strands.h
M source/blender/editors/space_view3d/CMakeLists.txt
A source/blender/editors/space_view3d/drawstrands.c
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/editors/space_view3d/view3d_intern.h
M source/blender/pointcache/alembic/abc_particles.cpp
M source/blender/pointcache/alembic/abc_particles.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_strands.h b/source/blender/blenkernel/BKE_strands.h
index 22e9c4b..f19c137 100644
--- a/source/blender/blenkernel/BKE_strands.h
+++ b/source/blender/blenkernel/BKE_strands.h
@@ -53,6 +53,7 @@ BLI_INLINE void BKE_strand_iter_init(StrandIterator *iter, Strands *strands)
iter->tot = strands->totcurves;
iter->index = 0;
iter->curve = strands->curves;
+ iter->verts = strands->verts;
}
BLI_INLINE bool BKE_strand_iter_valid(StrandIterator *iter)
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index ab69e67..7d36931 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -45,6 +45,7 @@ set(SRC
drawmesh.c
drawobject.c
drawsimdebug.c
+ drawstrands.c
drawvolume.c
space_view3d.c
view3d_buttons.c
diff --git a/source/blender/editors/space_view3d/drawstrands.c b/source/blender/editors/space_view3d/drawstrands.c
new file mode 100644
index 0000000..ccc5d67
--- /dev/null
+++ b/source/blender/editors/space_view3d/drawstrands.c
@@ -0,0 +1,121 @@
+/*
+ * ***** 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) 2014 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/drawsimdebug.c
+ * \ingroup spview3d
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_object_types.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_global.h"
+#include "BKE_strands.h"
+
+#include "view3d_intern.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "UI_resources.h"
+
+static void draw_strand_lines(Strands *strands, short dflag)
+{
+ GLint polygonmode[2];
+ StrandIterator it_strand;
+
+ glGetIntegerv(GL_POLYGON_MODE, polygonmode);
+ glEnableClientState(GL_VERTEX_ARRAY);
+
+ /* setup gl flags */
+// glEnableClientState(GL_NORMAL_ARRAY);
+
+ if ((dflag & DRAW_CONSTCOLOR) == 0) {
+// if (part->draw_col == PART_DRAW_COL_MAT)
+// glEnableClientState(GL_COLOR_ARRAY);
+ }
+
+ glColor3f(1,1,1);
+// glEnable(GL_LIGHTING);
+// glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
+// glEnable(GL_COLOR_MATERIAL);
+
+ for (BKE_strand_iter_init(&it_strand, strands); BKE_strand_iter_valid(&it_strand); BKE_strand_iter_next(&it_strand)) {
+ if (it_strand.tot <= 0)
+ continue;
+
+ glVertexPointer(3, GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->co);
+// glNormalPointer(GL_FLOAT, sizeof(StrandsVertex), it_strand.verts->nor);
+ if ((dflag & DRAW_CONSTCOLOR) == 0) {
+// if (part->draw_col == PART_DRAW_COL_MAT) {
+// glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
+// }
+ }
+
+ glDrawArrays(GL_LINE_STRIP, 0, it_strand.curve->numverts);
+ }
+
+ /* restore & clean up */
+// if (part->draw_col == PART_DRAW_COL_MAT)
+// glDisableClientState(GL_COLOR_ARRAY);
+ glDisable(GL_COLOR_MATERIAL);
+
+ glLineWidth(1.0f);
+
+ glPolygonMode(GL_FRONT, polygonmode[0]);
+ glPolygonMode(GL_BACK, polygonmode[1]);
+}
+
+void draw_strands(Scene *UNUSED(scene), View3D *UNUSED(v3d), ARegion *ar, Object *ob, Strands *strands, short dflag)
+{
+ RegionView3D *rv3d = ar->regiondata;
+ float imat[4][4];
+
+ invert_m4_m4(imat, rv3d->viewmatob);
+
+// glDepthMask(GL_FALSE);
+// glEnable(GL_BLEND);
+
+ glPushMatrix();
+
+ glLoadMatrixf(rv3d->viewmat);
+ glMultMatrixf(ob->obmat);
+
+ draw_strand_lines(strands, dflag);
+
+ glPopMatrix();
+
+// glDepthMask(GL_TRUE);
+// glDisable(GL_BLEND);
+}
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 6aa05f0..47c8ea2 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -2071,6 +2071,20 @@ int dupli_ob_sort(void *arg1, void *arg2)
}
#endif
+static void draw_dupli_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, DupliObject *UNUSED(dob), DupliObjectData *dob_data, short dflag)
+{
+ draw_object(scene, ar, v3d, base, dflag);
+
+ if (dob_data) {
+ LinkData *link;
+
+ for (link = dob_data->strands.first; link; link = link->next) {
+ struct Strands *strands = link->data;
+
+ draw_strands(scene, v3d, ar, base->object, strands, dflag);
+ }
+ }
+}
static DupliObject *dupli_step(DupliObject *dob)
{
@@ -2120,6 +2134,7 @@ static void draw_dupli_objects_color(
for (; dob; dob_prev = dob, dob = dob_next, dob_next = dob_next ? dupli_step(dob_next->next) : NULL) {
/* for restoring after override */
+ DupliObjectData *dob_data = NULL;
DerivedMesh *store_final_dm;
tbase.object = dob->ob;
@@ -2164,7 +2179,7 @@ static void draw_dupli_objects_color(
bb_tmp = NULL;
tbase.object->transflag &= ~OB_IS_DUPLI_CACHE;
if (base->object->dup_cache) {
- DupliObjectData *dob_data = BKE_dupli_cache_find_data(base->object->dup_cache, tbase.object);
+ dob_data = BKE_dupli_cache_find_data(base->object->dup_cache, tbase.object);
if (dob_data->dm) {
tbase.object->transflag |= OB_IS_DUPLI_CACHE;
@@ -2221,7 +2236,7 @@ static void draw_dupli_objects_color(
displist = glGenLists(1);
glNewList(displist, GL_COMPILE);
- draw_object(scene, ar, v3d, &tbase, dflag_dupli);
+ draw_dupli_object(scene, ar, v3d, &tbase, dob, dob_data, dflag_dupli);
glEndList();
use_displist = true;
@@ -2237,7 +2252,7 @@ static void draw_dupli_objects_color(
}
else {
copy_m4_m4(dob->ob->obmat, dob->mat);
- draw_object(scene, ar, v3d, &tbase, dflag_dupli);
+ draw_dupli_object(scene, ar, v3d, &tbase, dob, dob_data, dflag_dupli);
}
}
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 046f057..6e12296 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -49,6 +49,7 @@ struct bPoseChannel;
struct bScreen;
struct Mesh;
struct SimDebugData;
+struct Strands;
struct wmNDOFMotionData;
struct wmOperatorType;
struct wmWindowManager;
@@ -184,6 +185,9 @@ void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d,
/* drawsimdebug.c */
void draw_sim_debug_data(Scene *scene, View3D *v3d, ARegion *ar);
+/* drawstrands.c */
+void draw_strands(Scene *scene, View3D *v3d, ARegion *ar, struct Object *ob, struct Strands *strands, short dflag);
+
/* view3d_draw.c */
void view3d_main_area_draw(const struct bContext *C, struct ARegion *ar);
void ED_view3d_draw_depth(Scene *scene, struct ARegion *ar, View3D *v3d, bool alphaoverride);
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp b/source/blender/pointcache/alembic/abc_particles.cpp
index 43f7e19..14f7e53 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -137,6 +137,7 @@ struct ParticleHairSample {
AbcHairWriter::AbcHairWriter(const std::string &name, Object *ob, ParticleSystem *psys) :
ParticlesWriter(ob, psys, name)
{
+ m_psmd = psys_get_modifier(ob, psys);
}
AbcHairWriter::~AbcHairWriter()
@@ -169,7 +170,7 @@ static int hair_count_totverts(ParticleSystem *psys)
return totverts;
}
-static void hair_create_sample(ParticleSystem *psys, ParticleHairSample &sample, bool do_numverts)
+static void hair_create_sample(Object *ob, DerivedMesh *dm, ParticleSystem *psys, ParticleHairSample &sample, bool do_numverts)
{
int totpart = psys->totpart;
int totverts = hair_count_totverts(psys);
@@ -193,8 +194,17 @@ static void hair_create_sample(ParticleSystem *psys, ParticleHairSample &sample,
for (k = 0; k < numverts; ++k) {
HairKey *key = &pa->hair[k];
+ float hairmat[4][4];
+ float co[3];
- sample.positions.push_back(V3f(key->co[0], key->co[1], key->co[2]));
+ /* hair keys are in "hair space" relative to the mesh,
+ * store them in object space for compatibility and to avoid
+ * complexities of how particles work.
+ */
+ psys_mat_hair_to_object(ob, dm, psys->part->from, pa, hairmat);
+ mul_v3_m4v3(co, hairmat, key->co);
+
+ sample.positions.push_back(V3f(co[0], co[1], co[2]));
sample.times.push_back(key->time);
sample.weights.push_back(key->weight);
}
@@ -205,6 +215,8 @@ void AbcHairWriter::write_sample()
{
if (!m_curves)
return;
+ if (!m_psmd || !m_psmd->dm)
+ return;
OCurvesSchema &schema = m_curves.getSchema();
@@ -212,11 +224,11 @@ void AbcHairWriter::write_sample()
OCurvesSchema::Sample sample;
if (schema.getNumSamples() == 0) {
/* write curve sizes only first time, assuming they are constant! */
- hair_create_sample(m_psys, hair_sample, true);
+ hair_create_sample(m_ob, m_psmd->dm, m_psys, hair_sample, true);
sample = OCurvesSchema::Sample(hair_sample.positions, hair_sample.numverts);
}
else {
- hair_create_sample(m_psys, hair_sample, false);
+ hair_create_sample(m_ob, m_psmd->dm, m_psys, hair_sample, false);
sample = OCurvesSchema::Sample(hair_sample.positions);
}
schema.set(sample);
diff --git a/source/blender/pointcache/alembic/abc_particles.h b/source/blender/pointcache/alembic/abc_particles.h
index 4cf1676..31d87cd 100644
--- a/source/blender/pointcache/alembic/abc_particles.h
+++ b/source
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list