[Bf-blender-cvs] [644b68a] alembic: Basic strand processing in the hair sim cache modifier.
Lukas Tönne
noreply at git.blender.org
Wed Apr 1 20:32:08 CEST 2015
Commit: 644b68ac6e9c2ee9c3ad4f7bb1cc38ae7bf21ce6
Author: Lukas Tönne
Date: Wed Apr 1 20:03:46 2015 +0200
Branches: alembic
https://developer.blender.org/rB644b68ac6e9c2ee9c3ad4f7bb1cc38ae7bf21ce6
Basic strand processing in the hair sim cache modifier.
===================================================================
M source/blender/blenkernel/BKE_anim.h
M source/blender/blenkernel/BKE_cache_library.h
M source/blender/blenkernel/intern/cache_library.c
M source/blender/blenkernel/intern/object_dupli.c
M source/blender/editors/io/io_cache_library.c
M source/blender/makesdna/DNA_cache_library_types.h
M source/blender/physics/BPH_mass_spring.h
M source/blender/physics/intern/BPH_mass_spring.cpp
M source/blender/pointcache/alembic/abc_particles.cpp
===================================================================
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 0539f25..b5c8bc6 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -48,6 +48,7 @@ struct DupliObjectData;
struct DerivedMesh;
struct Strands;
struct DupliCacheIterator;
+struct CacheLibrary;
/* ---------------------------------------------------- */
/* Animation Visualization */
@@ -91,10 +92,11 @@ void BKE_dupli_object_data_clear(struct DupliObjectData *data);
void BKE_dupli_object_data_set_mesh(struct DupliObjectData *data, struct DerivedMesh *dm);
void BKE_dupli_object_data_add_strands(struct DupliObjectData *data, struct Strands *strands);
-void BKE_dupli_cache_free(struct DupliCache *dupcache);
struct DupliCache *BKE_dupli_cache_new(void);
+void BKE_dupli_cache_free(struct DupliCache *dupcache);
struct DupliObjectData *BKE_dupli_cache_add_object(struct DupliCache *dupcache, struct Object *ob);
void BKE_dupli_cache_add_instance(struct DupliCache *dupcache, float obmat[4][4], struct DupliObjectData *data);
+void BKE_dupli_cache_from_group(struct Scene *scene, struct Group *group, struct CacheLibrary *cachelib, struct DupliCache *dupcache, struct EvaluationContext *eval_ctx);
struct DupliCacheIterator *BKE_dupli_cache_iter_new(struct DupliCache *dupcache);
void BKE_dupli_cache_iter_free(struct DupliCacheIterator *iter);
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index c0ced2b..c501f4e 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -46,6 +46,7 @@ struct DupliCache;
struct DupliObjectData;
struct CacheModifier;
struct ID;
+struct CacheProcessData;
struct ClothModifierData;
@@ -77,7 +78,7 @@ bool BKE_cache_read_dupli_cache(struct CacheLibrary *cachelib, struct DupliCache
bool BKE_cache_read_dupli_object(struct CacheLibrary *cachelib, struct DupliObjectData *data,
struct Scene *scene, struct Object *ob, float frame, eCacheLibrary_EvalMode eval_mode);
-void BKE_cache_process_dupli_cache(struct CacheLibrary *cachelib, struct DupliCache *dupcache,
+void BKE_cache_process_dupli_cache(struct CacheLibrary *cachelib, struct CacheProcessData *data,
struct Scene *scene, struct Group *dupgroup, float frame_prev, float frame, eCacheLibrary_EvalMode eval_mode);
/* ========================================================================= */
@@ -91,12 +92,16 @@ typedef struct CacheProcessContext {
struct Group *group;
} CacheProcessContext;
+typedef struct CacheProcessData {
+ struct DupliCache *dupcache;
+} CacheProcessData;
+
typedef void (*CacheModifier_InitFunc)(struct CacheModifier *md);
typedef void (*CacheModifier_FreeFunc)(struct CacheModifier *md);
typedef void (*CacheModifier_CopyFunc)(struct CacheModifier *md, struct CacheModifier *target);
typedef void (*CacheModifier_ForeachIDLinkFunc)(struct CacheModifier *md, struct CacheLibrary *cachelib,
CacheModifier_IDWalkFunc walk, void *userData);
-typedef void (*CacheModifier_ProcessFunc)(struct CacheModifier *md, struct CacheProcessContext *ctx, struct DupliCache *dupcache, int frame, int frame_prev);
+typedef void (*CacheModifier_ProcessFunc)(struct CacheModifier *md, struct CacheProcessContext *ctx, struct CacheProcessData *data, int frame, int frame_prev);
typedef struct CacheModifierTypeInfo {
/* The user visible name for this modifier */
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index a6c5d47..f3e37af 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -64,6 +64,8 @@
#include "PTC_api.h"
+#include "BPH_mass_spring.h"
+
CacheLibrary *BKE_cache_library_add(Main *bmain, const char *name)
{
CacheLibrary *cachelib;
@@ -534,7 +536,7 @@ void BKE_cache_modifier_foreachIDLink(struct CacheLibrary *cachelib, struct Cach
mti->foreachIDLink(md, cachelib, walk, userdata);
}
-void BKE_cache_process_dupli_cache(CacheLibrary *cachelib, DupliCache *dupcache,
+void BKE_cache_process_dupli_cache(CacheLibrary *cachelib, CacheProcessData *data,
Scene *scene, Group *dupgroup, float frame_prev, float frame, eCacheLibrary_EvalMode UNUSED(eval_mode))
{
CacheProcessContext ctx;
@@ -549,23 +551,30 @@ void BKE_cache_process_dupli_cache(CacheLibrary *cachelib, DupliCache *dupcache,
CacheModifierTypeInfo *mti = cache_modifier_type_get(md->type);
if (mti->process)
- mti->process(md, &ctx, dupcache, frame, frame_prev);
+ mti->process(md, &ctx, data, frame, frame_prev);
}
}
/* ------------------------------------------------------------------------- */
-static void hairsim_init(HairSimCacheModifier *UNUSED(md))
+static void hairsim_params_init(StrandSimParams *params)
+{
+ params->timescale = 1.0f;
+ params->substeps = 5;
+}
+
+static void hairsim_init(HairSimCacheModifier *hsmd)
{
+ hairsim_params_init(&hsmd->sim_params);
}
static void hairsim_copy(HairSimCacheModifier *UNUSED(md), HairSimCacheModifier *UNUSED(tmd))
{
}
-static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx, DupliCache *dupcache, int frame, int frame_prev)
+static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *UNUSED(ctx), CacheProcessData *data, int frame, int frame_prev)
{
- struct DupliCacheIterator *iter = BKE_dupli_cache_iter_new(dupcache);
+ struct DupliCacheIterator *iter = BKE_dupli_cache_iter_new(data->dupcache);
for (; BKE_dupli_cache_iter_valid(iter); BKE_dupli_cache_iter_next(iter)) {
DupliObjectData *data = BKE_dupli_cache_iter_get(iter);
LinkData *link;
@@ -573,7 +582,17 @@ static void hairsim_process(HairSimCacheModifier *hsmd, CacheProcessContext *ctx
for (link = data->strands.first; link; link = link->next) {
Strands *strands = link->data;
+ struct Implicit_Data *solver_data;
+ int numsprings;
+
BKE_strands_add_motion_state(strands);
+
+ numsprings = strands->totverts - strands->totcurves;
+ solver_data = BPH_mass_spring_solver_create(strands->totverts, numsprings);
+
+ BPH_strands_solve(strands, solver_data, &hsmd->sim_params, (float)frame, NULL);
+
+ BPH_mass_spring_solver_free(solver_data);
}
}
BKE_dupli_cache_iter_free(iter);
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 299ffe5..6153800 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -1421,14 +1421,6 @@ static void dupli_cache_clear(DupliCache *dupcache)
BLI_ghash_clear(dupcache->ghash, NULL, (GHashValFreeFP)dupli_object_data_free);
}
-void BKE_dupli_cache_free(DupliCache *dupcache)
-{
- dupli_cache_clear(dupcache);
-
- BLI_ghash_free(dupcache->ghash, NULL, (GHashValFreeFP)dupli_object_data_free);
- MEM_freeN(dupcache);
-}
-
DupliCache *BKE_dupli_cache_new(void)
{
DupliCache *dupcache = MEM_callocN(sizeof(DupliCache), "dupli object cache");
@@ -1438,6 +1430,14 @@ DupliCache *BKE_dupli_cache_new(void)
return dupcache;
}
+void BKE_dupli_cache_free(DupliCache *dupcache)
+{
+ dupli_cache_clear(dupcache);
+
+ BLI_ghash_free(dupcache->ghash, NULL, (GHashValFreeFP)dupli_object_data_free);
+ MEM_freeN(dupcache);
+}
+
static DupliObjectData *dupli_cache_add_object_data(DupliCache *dupcache, Object *ob)
{
DupliObjectData *data = MEM_callocN(sizeof(DupliObjectData), "dupli object data");
@@ -1457,6 +1457,90 @@ static DupliObject *dupli_cache_add_object(DupliCache *dupcache)
return dob;
}
+static int count_hair_verts(ParticleSystem *psys)
+{
+ int numverts = 0;
+ int p;
+ for (p = 0; p < psys->totpart; ++p) {
+ numverts += psys->particles[p].totkey;
+ }
+ return numverts;
+}
+
+void BKE_dupli_cache_from_group(Scene *scene, Group *group, CacheLibrary *cachelib, DupliCache *dupcache, EvaluationContext *eval_ctx)
+{
+ DupliObject *dob;
+
+ dupli_cache_clear(dupcache);
+
+ if (!(group && cachelib))
+ return;
+
+ {
+ /* copy duplilist to the cache */
+ ListBase *duplilist = group_duplilist(eval_ctx, scene, group);
+ dupcache->duplilist = *duplilist;
+ MEM_freeN(duplilist);
+ }
+
+ for (dob = dupcache->duplilist.first; dob; dob = dob->next) {
+ DupliObjectData *data = BKE_dupli_cache_find_data(dupcache, dob->ob);
+ if (!data) {
+ ParticleSystem *psys;
+
+ data = dupli_cache_add_object_data(dupcache, dob->ob);
+
+ if (cachelib->data_types & CACHE_TYPE_DERIVED_MESH) {
+ if (dob->ob->type == OB_MESH) {
+ DerivedMesh *dm;
+
+ if (eval_ctx->mode == DAG_EVAL_RENDER) {
+ dm = mesh_create_derived_render(scene, dob->ob, CD_MASK_BAREMESH);
+ }
+ else {
+ dm = mesh_create_derived_view(scene, dob->ob, CD_MASK_BAREMESH);
+ }
+
+ if (dm)
+ BKE_dupli_object_data_set_mesh(data, dm);
+ }
+ }
+
+ for (psys = dob->ob->particlesystem.first; psys; psys = psys->next) {
+ if (cachelib->data_types & CACHE_TYPE_HAIR) {
+ if (psys->part && psys->part->type == PART_HAIR) {
+ int numstrands = psys->totpart;
+ int numverts = count_hair_verts(psys);
+ ParticleData *pa;
+ HairKey *hkey;
+ int p, k;
+
+ Strands *strands = BKE_strands_new(numstrands, numverts);
+ StrandsCurve *scurve = strands->curves;
+ StrandsVertex *svert = strands->verts;
+
+ for (p = 0, pa = psys->particles; p < psys->totpart; ++p, ++pa) {
+ scurve->numverts = pa->totkey;
+
+ for (k = 0, hkey = pa->hair; k < pa->totkey; ++k, ++hkey) {
+ copy_v3_v3(svert->co, hkey->co);
+ svert->time = hkey->time;
+ svert->weight = hkey->weight;
+
+ ++svert;
+ }
+
+ ++scurve;
+ }
+
+ BKE_dupli_object_data_add_strands(data, strands);
+ }
+ }
+ }
+ }
+ }
+}
+
/* ------------------------------------------------------------------------- */
void BKE_object_dupli_cache_update(Scene *scene, Object *ob, EvaluationContext *eval_ctx, f
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list