[Bf-blender-cvs] [dd9f957] hair_immediate_fixes: Preliminary commit for simulation preview.
Lukas Tönne
noreply at git.blender.org
Fri Oct 10 10:32:12 CEST 2014
Commit: dd9f957ccbabbf9e13d1e8fdd567083f48a566ad
Author: Lukas Tönne
Date: Tue Oct 7 17:27:04 2014 +0200
Branches: hair_immediate_fixes
https://developer.blender.org/rBdd9f957ccbabbf9e13d1e8fdd567083f48a566ad
Preliminary commit for simulation preview.
===================================================================
M release/scripts/startup/bl_ui/properties_particle.py
M source/blender/blenkernel/BKE_cloth.h
M source/blender/blenkernel/BKE_particle.h
M source/blender/blenkernel/intern/cloth.c
M source/blender/blenkernel/intern/collision.c
M source/blender/blenkernel/intern/particle_system.c
M source/blender/makesdna/DNA_particle_types.h
M source/blender/makesrna/intern/rna_particle.c
M source/blender/physics/BPH_mass_spring.h
M source/blender/physics/intern/BPH_mass_spring.cpp
M source/blender/physics/intern/implicit_blender.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_particle.py b/release/scripts/startup/bl_ui/properties_particle.py
index 4869500..2e7df5b 100644
--- a/release/scripts/startup/bl_ui/properties_particle.py
+++ b/release/scripts/startup/bl_ui/properties_particle.py
@@ -284,6 +284,8 @@ class PARTICLE_PT_hair_dynamics(ParticleButtonsPanel, Panel):
layout.enabled = psys.use_hair_dynamics and psys.point_cache.is_baked is False
+ layout.prop(psys, "hair_preview_factor")
+
split = layout.split()
col = split.column()
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 940d8ea..9a0f7ce 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -56,10 +56,14 @@ struct PartDeflect;
#define ALMOST_ZERO FLT_EPSILON
/* Bits to or into the ClothVertex.flags. */
-typedef enum eClothVertexFlag {
- CLOTH_VERT_FLAG_PINNED = 1,
- CLOTH_VERT_FLAG_NOSELFCOLL = 2, /* vertex NOT used for self collisions */
-} eClothVertexFlag;
+//typedef enum eClothVertexFlag {
+// CLOTH_VERT_FLAG_PINNED = 1,
+// CLOTH_VERT_FLAG_NOSELFCOLL = 2, /* vertex NOT used for self collisions */
+// CLOTH_VERT_FLAG_EXCLUDE = 4, /* exclude vertex from the simulation */
+//} eClothVertexFlag;
+#define CLOTH_VERT_FLAG_PINNED 1
+#define CLOTH_VERT_FLAG_NOSELFCOLL 2 /* vertex NOT used for self collisions */
+#define CLOTH_VERT_FLAG_EXCLUDE 4 /* exclude vertex from the simulation */
typedef struct ClothHairRoot {
float loc[3];
@@ -107,6 +111,7 @@ typedef struct Cloth {
*/
typedef struct ClothVertex {
int flags; /* General flags per vertex. */
+ int solver_index; /* index in internal solver data */
float v[3]; /* The velocity of the point. */
float xconst[3]; /* constrained position */
float x[3]; /* The current position of this vertex. */
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 7c9dbf5..f698be2 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -325,6 +325,7 @@ void BKE_particlesettings_make_local(struct ParticleSettings *part);
void psys_reset(struct ParticleSystem *psys, int mode);
+void psys_hair_update_preview(struct ParticleSimulationData *sim);
void psys_find_parents(struct ParticleSimulationData *sim);
void psys_cache_paths(struct ParticleSimulationData *sim, float cfra);
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 96565d5..737574d 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -377,7 +377,7 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
return 0;
}
- BKE_cloth_solver_set_positions(clmd);
+ BPH_cloth_solver_set_positions(clmd);
clmd->clothObject->last_frame= MINFRAME-1;
}
@@ -560,7 +560,7 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe);
if (cache_result == PTCACHE_READ_EXACT || cache_result == PTCACHE_READ_INTERPOLATED) {
- BKE_cloth_solver_set_positions(clmd);
+ BPH_cloth_solver_set_positions(clmd);
cloth_to_object (ob, clmd, vertexCos);
BKE_ptcache_validate(cache, framenr);
@@ -573,7 +573,7 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
return;
}
else if (cache_result==PTCACHE_READ_OLD) {
- BKE_cloth_solver_set_positions(clmd);
+ BPH_cloth_solver_set_positions(clmd);
}
else if ( /*ob->id.lib ||*/ (cache->flag & PTCACHE_BAKED)) { /* 2.4x disabled lib, but this can be used in some cases, testing further - campbell */
/* if baked and nothing in cache, do nothing */
@@ -785,6 +785,7 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
{
int i = 0;
int j = 0;
+ MVert *mvert;
MDeformVert *dvert = NULL;
Cloth *clothObj = NULL;
int numverts;
@@ -795,11 +796,11 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
clothObj = clmd->clothObject;
- numverts = dm->getNumVerts (dm);
+ numverts = dm->getNumVerts(dm);
+ mvert = dm->getVertArray(dm);
- verts = clothObj->verts;
-
if (cloth_uses_vgroup(clmd)) {
+ verts = clothObj->verts;
for ( i = 0; i < numverts; i++, verts++ ) {
/* Reset Goal values to standard */
@@ -862,6 +863,12 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm )
}
}
}
+
+ verts = clothObj->verts;
+ for ( i = 0; i < numverts; i++, verts++ ) {
+ if (mvert[i].flag & ME_VERT_TMP_TAG)
+ verts->flags |= CLOTH_VERT_FLAG_EXCLUDE;
+ }
}
@@ -970,7 +977,7 @@ static int cloth_from_object(Object *ob, ClothModifierData *clmd, DerivedMesh *d
}
if (!first)
- BKE_cloth_solver_set_positions(clmd);
+ BPH_cloth_solver_set_positions(clmd);
clmd->clothObject->bvhtree = bvhtree_build_from_cloth ( clmd, MAX2(clmd->coll_parms->epsilon, clmd->coll_parms->distance_repel) );
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 560bbe8..91d0ac1 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -1402,7 +1402,14 @@ void cloth_find_point_contacts(Object *ob, ClothModifierData *clmd, float step,
unsigned int numcollobj = 0;
verts = cloth->verts;
- numverts = cloth->numverts;
+
+ numverts = 0;
+ for (i = 0; i < cloth->numverts; ++i) {
+ /* avoid costly collision detection for points that are excluded anyway */
+ if (verts[i].flags & CLOTH_VERT_FLAG_EXCLUDE)
+ continue;
+ ++numverts;
+ }
////////////////////////////////////////////////////////////
// static collisions
@@ -1411,8 +1418,11 @@ void cloth_find_point_contacts(Object *ob, ClothModifierData *clmd, float step,
// create temporary cloth points bvh
cloth_bvh = BLI_bvhtree_new(numverts, MAX2(clmd->coll_parms->epsilon, clmd->coll_parms->distance_repel), 4, 6);
/* fill tree */
- for (i = 0; i < numverts; i++) {
+ for (i = 0; i < cloth->numverts; i++) {
float co[6];
+ /* avoid costly collision detection for points that are excluded anyway */
+ if (verts[i].flags & CLOTH_VERT_FLAG_EXCLUDE)
+ continue;
copy_v3_v3(&co[0*3], verts[i].x);
copy_v3_v3(&co[1*3], verts[i].tx);
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 014a6b1..faee4f5 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -4059,34 +4059,81 @@ static MDeformVert *hair_set_pinning(MDeformVert *dvert, float weight)
return dvert;
}
-static void do_hair_dynamics(ParticleSimulationData *sim)
+void psys_hair_update_preview(ParticleSimulationData *sim)
+{
+ ParticleSystem *psys = sim->psys;
+ ParticleSettings *part = psys->part;
+ float factor = psys->hair_preview_factor * 0.01f;
+
+ if (!part->type == PART_HAIR)
+ return;
+
+ { /* Random hair selection method */
+ RNG *rng = BLI_rng_new(98250 + psys->seed);
+ ParticleData *pa;
+ int i;
+
+ pa = psys->particles;
+ for (i = 0; i < psys->totpart; ++i, ++pa) {
+ if (BLI_rng_get_float(rng) < factor) {
+ pa->flag |= PARS_HAIR_BLEND;
+ // XXX TODO
+ pa->blend_index[0] = -1;
+ pa->blend_index[1] = -1;
+ pa->blend_index[2] = -1;
+ pa->blend_index[3] = -1;
+ pa->blend_weight[0] = 0.0f;
+ pa->blend_weight[1] = 0.0f;
+ pa->blend_weight[2] = 0.0f;
+ pa->blend_weight[3] = 0.0f;
+ }
+ else {
+ pa->flag &= ~PARS_HAIR_BLEND;
+ pa->blend_index[0] = -1;
+ pa->blend_index[1] = -1;
+ pa->blend_index[2] = -1;
+ pa->blend_index[3] = -1;
+ pa->blend_weight[0] = 0.0f;
+ pa->blend_weight[1] = 0.0f;
+ pa->blend_weight[2] = 0.0f;
+ pa->blend_weight[3] = 0.0f;
+ }
+ }
+
+ BLI_rng_free(rng);
+ }
+}
+
+static void hair_create_input_dm(ParticleSimulationData *sim, int totpoint, int totedge, DerivedMesh **r_dm, ClothHairRoot **r_roots)
{
ParticleSystem *psys = sim->psys;
- DerivedMesh *dm = psys->hair_in_dm;
- MVert *mvert = NULL;
- MEdge *medge = NULL;
- MDeformVert *dvert = NULL;
+ DerivedMesh *dm;
+ ClothHairRoot *roots;
+ MVert *mvert;
+ MEdge *medge;
+ MDeformVert *dvert;
HairKey *key;
PARTICLE_P;
- int totpoint = 0;
- int totedge;
- int k;
+ int k, hair_index;
float hairmat[4][4];
- float (*deformedVerts)[3];
float max_length;
- bool realloc_roots;
float *shapekey_data, *shapekey;
int totshapekey;
-
- if (!psys->clmd) {
- psys->clmd = (ClothModifierData*)modifier_new(eModifierType_Cloth);
- psys->clmd->sim_parms->goalspring = 0.0f;
- psys->clmd->sim_parms->vel_damping = 1.0f;
- psys->clmd->sim_parms->flags |= CLOTH_SIMSETTINGS_FLAG_GOAL|CLOTH_SIMSETTINGS_FLAG_NO_SPRING_COMPRESS;
- psys->clmd->coll_parms->flags &= ~CLOTH_COLLSETTINGS_FLAG_SELF;
- psys->clmd->coll_parms->flags |= CLOTH_COLLSETTINGS_FLAG_POINTS;
+
+ dm = *r_dm;
+ if (!dm) {
+ *r_dm = dm = CDDM_new(totpoint, totedge, 0, 0, 0);
+ DM_add_vert_layer(dm, CD_MDEFORMVERT, CD_CALLOC, NULL);
}
-
+ mvert = CDDM_get_verts(dm);
+ medge = CDDM_get_edges(dm);
+ dvert = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
+
+ roots = *r_roots;
+ if (!roots) {
+ *r_roots = roots = MEM_mallocN(sizeof(ClothHairRoot) * totpoint, "hair roots");
+ }
+
/* calculate maximum segment length */
max_length = 0.0f;
LOOP_PARTICLES {
@@ -4096,56 +4143,24 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
max_length = length;
}
}
-
- /* create a dm from hair vertices */
- LOOP_PARTICLES
- totpoint += pa->totkey;
-
- totedge = totpoint;
- totpoint += psys->totpart;
-
- realloc_roots = false; /* whether hair root info array has to be reallocated */
- if (dm && (totpoint != dm->getNumVerts(dm) || totedge != dm->getNumEdges(dm))) {
- dm->release(dm);
- dm = psys->hair_in_dm = NULL;
-
- realloc_roots = true;
- }
-
- if (!dm) {
- dm = psys->hair_in_dm = CDDM_new(totpoint, totedge, 0, 0, 0);
- DM_add_vert_layer(dm, CD_MDEFORMVERT, CD_CALLOC, NULL);
-
- realloc_roots = true;
- }
- if (!psys->clmd->roots || realloc_roots) {
- if (psys->
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list