Commit: bf342499129e64f801523267f16e2df2398d80f8
Author: Lukas Tönne
Date:   Sun Apr 12 14:39:03 2015 +0200
Branches: alembic
https://developer.blender.org/rBbf342499129e64f801523267f16e2df2398d80f8

Fix for broken and messy particle time values to get consistent caches.

Particles use 0..100 range for parent particle "times" (curve parameter)
and 0..1 for children. For caches this is now uniformly calculated in
the 0..1 range to avoid breaking child interpolation.

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

M       source/blender/blenkernel/intern/strands.c
M       source/blender/pointcache/alembic/abc_particles.cpp

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

diff --git a/source/blender/blenkernel/intern/strands.c 
b/source/blender/blenkernel/intern/strands.c
index 82a2b04..85a0b24 100644
--- a/source/blender/blenkernel/intern/strands.c
+++ b/source/blender/blenkernel/intern/strands.c
@@ -243,6 +243,7 @@ void 
BKE_strands_children_deform_from_parents(StrandsChildren *strands, Strands
                                        
                                        dt = pverts[pv1].time - 
pverts[pv0].time;
                                        x = dt > 0.0f ? (time - 
pverts[pv0].time) / dt : 0.0f;
+                                       CLAMP(x, 0.0f, 1.0f);
                                        interp_v3_v3v3(offset, poffset0, 
poffset1, x);
                                        
                                        madd_v3_v3fl(it_vert.vertex->co, 
offset, w);
diff --git a/source/blender/pointcache/alembic/abc_particles.cpp 
b/source/blender/pointcache/alembic/abc_particles.cpp
index e4b83da..f25ba97 100644
--- a/source/blender/pointcache/alembic/abc_particles.cpp
+++ b/source/blender/pointcache/alembic/abc_particles.cpp
@@ -191,7 +191,7 @@ static int hair_children_count_totkeys(ParticleCacheKey 
**pathcache, int totpart
        return totkeys;
 }
 
-static void hair_children_create_sample(ParticleSystem *psys, ParticleCacheKey 
**pathcache, int totpart, int totkeys, float imat[4][4], StrandsChildrenSample 
&sample, bool do_numkeys)
+static void hair_children_create_sample(ParticleSystem *psys, ParticleCacheKey 
**pathcache, int totpart, int totkeys, int maxkeys, float imat[4][4], 
StrandsChildrenSample &sample, bool do_numkeys)
 {
        const bool between = (psys->part->childtype == PART_CHILD_FACES);
        float iqt[4];
@@ -246,7 +246,8 @@ static void hair_children_create_sample(ParticleSystem 
*psys, ParticleCacheKey *
                        mul_qt_qtqt(rot, iqt, key->rot);
                        
                        sample.positions.push_back(V3f(co[0], co[1], co[2]));
-                       sample.times.push_back(key->time);
+                       /* XXX particle time values are too messy and 
confusing, recalculate */
+                       sample.times.push_back(maxkeys > 1 ? (float)k / 
(float)(maxkeys-1) : 0.0f);
                }
        }
 }
@@ -265,19 +266,24 @@ void AbcHairChildrenWriter::write_sample()
        float imat[4][4];
        invert_m4_m4(imat, m_ob->obmat);
        
+       int keysteps = abc_archive()->use_render() ? m_psys->part->ren_step : 
m_psys->part->draw_step;
+       int maxkeys = (1 << keysteps) + 1 + (m_psys->part->kink);
+       if (ELEM(m_psys->part->kink, PART_KINK_SPIRAL))
+               maxkeys += m_psys->part->kink_extra_steps;
+       
        OCurvesSchema &schema = m_curves.getSchema();
        
        StrandsChildrenSample child_sample;
        OCurvesSchema::Sample sample;
        if (schema.getNumSamples() == 0) {
                /* write curve sizes only first time, assuming they are 
constant! */
-               hair_children_create_sample(m_psys, m_psys->childcache, 
m_psys->totchild, totkeys, imat, child_sample, true);
+               hair_children_create_sample(m_psys, m_psys->childcache, 
m_psys->totchild, totkeys, maxkeys, imat, child_sample, true);
                sample = OCurvesSchema::Sample(child_sample.positions, 
child_sample.numverts);
                m_prop_parents.set(Int32ArraySample(child_sample.parents));
                
m_prop_parent_weights.set(FloatArraySample(child_sample.parent_weights));
        }
        else {
-               hair_children_create_sample(m_psys, m_psys->childcache, 
m_psys->totchild, totkeys, imat, child_sample, false);
+               hair_children_create_sample(m_psys, m_psys->childcache, 
m_psys->totchild, totkeys, maxkeys, imat, child_sample, false);
                sample = OCurvesSchema::Sample(child_sample.positions);
        }
        schema.set(sample);
@@ -374,8 +380,8 @@ static void hair_create_sample(Object *ob, DerivedMesh *dm, 
ParticleSystem *psys
                        mul_v3_m4v3(co, hairmat, key->co);
                        
                        sample.positions.push_back(V3f(co[0], co[1], co[2]));
-                       /* XXX particle times are in 0..100, normalize to 0..1 
range */
-                       sample.times.push_back(key->time * 0.01f);
+                       /* XXX particle time values are too messy and 
confusing, recalculate */
+                       sample.times.push_back(numverts > 1 ? (float)k / 
(float)(numverts-1) : 0.0f);
                        sample.weights.push_back(key->weight);
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to