Commit: 8b7c54e25a2f117fe280c815a2e511a86a801a09
Author: Lukas Tönne
Date:   Mon Nov 24 17:44:59 2014 +0100
Branches: hair_immediate_fixes
https://developer.blender.org/rB8b7c54e25a2f117fe280c815a2e511a86a801a09

Finished the particle-to-edit conversion function.

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

M       source/blender/editors/hair/hair_edit.c
M       source/blender/editors/hair/hair_particles.c

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

diff --git a/source/blender/editors/hair/hair_edit.c 
b/source/blender/editors/hair/hair_edit.c
index b34e6e3..d7491c1 100644
--- a/source/blender/editors/hair/hair_edit.c
+++ b/source/blender/editors/hair/hair_edit.c
@@ -31,6 +31,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_math.h"
+
 #include "hair_intern.h"
 
 HairEditData *ED_hair_edit_create(void)
@@ -86,5 +88,26 @@ void ED_hair_edit_clear(HairEditData *hedit)
 
 void ED_hair_edit_reserve(HairEditData *hedit, int alloc_curves, int 
alloc_verts, bool shrink)
 {
-       if (hedit)
+       if (!hedit)
+               return;
+       
+       if ((alloc_curves > hedit->alloc_curves) || (alloc_curves < 
hedit->alloc_curves && shrink)) {
+               size_t size_curves = sizeof(HairEditCurve) * alloc_curves;
+               if (hedit->curves)
+                       hedit->curves = MEM_recallocN_id(hedit->curves, 
size_curves, "hair edit curves");
+               else
+                       hedit->curves = MEM_callocN(size_curves, "hair edit 
curves");
+               hedit->alloc_curves = alloc_curves;
+               CLAMP_MAX(hedit->totcurves, alloc_curves);
+       }
+       
+       if ((alloc_verts > hedit->alloc_verts) || (alloc_verts < 
hedit->alloc_verts && shrink)) {
+               size_t size_verts = sizeof(HairEditVertex) * alloc_verts;
+               if (hedit->verts)
+                       hedit->verts = MEM_recallocN_id(hedit->verts, 
size_verts, "hair edit verts");
+               else
+                       hedit->verts = MEM_callocN(size_verts, "hair edit 
verts");
+               hedit->alloc_verts = alloc_verts;
+               CLAMP_MAX(hedit->totverts, alloc_verts);
+       }
 }
diff --git a/source/blender/editors/hair/hair_particles.c 
b/source/blender/editors/hair/hair_particles.c
index ccf0801..fca0325 100644
--- a/source/blender/editors/hair/hair_particles.c
+++ b/source/blender/editors/hair/hair_particles.c
@@ -42,9 +42,73 @@
 
 /* ==== convert particle data to hair edit ==== */
 
+static int particle_totverts(ParticleSystem *psys)
+{
+       ParticleData *pa;
+       int p;
+       int totverts = 0;
+       
+       for (p = 0, pa = psys->particles; p < psys->totpart; ++p, ++pa)
+               totverts += pa->totkey;
+       
+       return totverts;
+}
+
+static void copy_edit_curve(HairEditData *hedit, HairEditCurve *curve, 
ParticleData *pa, int start)
+{
+       int totverts = pa->totkey;
+       HairKey *hair = pa->hair;
+       HairEditVertex *vert;
+       HairKey *hkey;
+       int k;
+       
+       BLI_assert(start + totverts < hedit->alloc_verts);
+       
+       curve->start = start;
+       curve->numverts = totverts;
+       
+       for (k = 0, vert = hedit->verts + start, hkey = hair;
+            k < totverts;
+            ++k, ++vert, ++hkey) {
+               
+               copy_v3_v3(vert->co, hkey->co);
+               // TODO define other key stuff ...
+       }
+}
+
 void hair_edit_from_particles(HairEditData *hedit, Object *UNUSED(ob), 
ParticleSystem *psys)
 {
+       int totverts = particle_totverts(psys);
+       
+       HairEditCurve *curve;
+       int i;
+       ParticleData *pa;
+       int p;
+       int vert_start;
+       
        ED_hair_edit_clear(hedit);
+       
+       ED_hair_edit_reserve(hedit, psys->totpart, totverts, true);
+       
+       /* TODO we should have a clean input stream API for hair edit data
+        * to avoid implicit size and index calculations here and make the code
+        * as fool proof as possible.
+        */
+       
+       hedit->totcurves = psys->totpart;
+       hedit->totverts = totverts;
+       
+       vert_start = 0;
+       for (i = 0, curve = hedit->curves, p = 0, pa = psys->particles;
+            i < hedit->totcurves;
+            ++i, ++curve, ++p, ++pa) {
+               
+               copy_edit_curve(hedit, curve, pa, vert_start);
+               
+               // TODO copy particle stuff ...
+               
+               vert_start += curve->numverts;
+       }
 }
 
 /* ==== convert hair edit to particle data ==== */
@@ -71,13 +135,12 @@ static void create_particle_curve(ParticleData *pa, 
HairEditData *hedit, HairEdi
        int ntotkey = curve->numverts;
        HairKey *nhair = MEM_callocN(sizeof(HairKey) * ntotkey, "hair keys");
        HairEditVertex *vert;
-       int k;
        HairKey *hkey;
-       int j;
+       int k;
        
-       for (k = 0, vert = hedit->verts + curve->start, j = 0, hkey = nhair;
+       for (k = 0, vert = hedit->verts + curve->start, hkey = nhair;
             k < curve->numverts;
-            ++k, ++vert, ++j, ++hkey) {
+            ++k, ++vert, ++hkey) {
                
                copy_v3_v3(hkey->co, vert->co);
                // TODO define other key stuff ...

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to