Commit: e9cf9776f80ab1d8efdfc46020995a48382dee09
Author: Lukas Tönne
Date:   Sun Apr 15 12:54:39 2018 +0100
Branches: hair_guides
https://developer.blender.org/rBe9cf9776f80ab1d8efdfc46020995a48382dee09

Move guide curve into a nested struct, so it can be replace in one operation.

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

M       source/blender/blenkernel/intern/hair.c
M       source/blender/blenkernel/intern/hair_draw.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c
M       source/blender/makesdna/DNA_hair_types.h

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

diff --git a/source/blender/blenkernel/intern/hair.c 
b/source/blender/blenkernel/intern/hair.c
index 5a9af8aba58..9d9f9df26c8 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -74,13 +74,13 @@ HairSystem* BKE_hair_copy(HairSystem *hsys)
                nhsys->pattern->follicles = 
MEM_dupallocN(hsys->pattern->follicles);
        }
        
-       if (hsys->curves)
+       if (hsys->guides.curves)
        {
-               nhsys->curves = MEM_dupallocN(hsys->curves);
+               nhsys->guides.curves = MEM_dupallocN(hsys->guides.curves);
        }
-       if (hsys->verts)
+       if (hsys->guides.verts)
        {
-               nhsys->verts = MEM_dupallocN(hsys->verts);
+               nhsys->guides.verts = MEM_dupallocN(hsys->guides.verts);
        }
        
        nhsys->draw_batch_cache = NULL;
@@ -93,13 +93,13 @@ void BKE_hair_free(HairSystem *hsys)
 {
        BKE_hair_batch_cache_free(hsys);
        
-       if (hsys->curves)
+       if (hsys->guides.curves)
        {
-               MEM_freeN(hsys->curves);
+               MEM_freeN(hsys->guides.curves);
        }
-       if (hsys->verts)
+       if (hsys->guides.verts)
        {
-               MEM_freeN(hsys->verts);
+               MEM_freeN(hsys->guides.verts);
        }
        
        if (hsys->pattern)
@@ -206,10 +206,10 @@ void BKE_hair_generate_follicles(
 
 void BKE_hair_guide_curves_begin(HairSystem *hsys, int totcurves)
 {
-       if (totcurves != hsys->totcurves)
+       if (totcurves != hsys->guides.totcurves)
        {
-               hsys->curves = MEM_reallocN(hsys->curves, 
sizeof(HairGuideCurve) * totcurves);
-               hsys->totcurves = totcurves;
+               hsys->guides.curves = MEM_reallocN(hsys->guides.curves, 
sizeof(HairGuideCurve) * totcurves);
+               hsys->guides.totcurves = totcurves;
 
                hsys->flag |= HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
                BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
@@ -218,9 +218,9 @@ void BKE_hair_guide_curves_begin(HairSystem *hsys, int 
totcurves)
 
 void BKE_hair_set_guide_curve(HairSystem *hsys, int index, const MeshSample 
*mesh_sample, int numverts)
 {
-       BLI_assert(index <= hsys->totcurves);
+       BLI_assert(index <= hsys->guides.totcurves);
        
-       HairGuideCurve *curve = &hsys->curves[index];
+       HairGuideCurve *curve = &hsys->guides.curves[index];
        memcpy(&curve->mesh_sample, mesh_sample, sizeof(MeshSample));
        curve->numverts = numverts;
        
@@ -232,16 +232,16 @@ void BKE_hair_guide_curves_end(HairSystem *hsys)
 {
        /* Recalculate vertex count and start offsets in curves */
        int vertstart = 0;
-       for (int i = 0; i < hsys->totcurves; ++i)
+       for (int i = 0; i < hsys->guides.totcurves; ++i)
        {
-               hsys->curves[i].vertstart = vertstart;
-               vertstart += hsys->curves[i].numverts;
+               hsys->guides.curves[i].vertstart = vertstart;
+               vertstart += hsys->guides.curves[i].numverts;
        }
 
-       if (vertstart != hsys->totverts)
+       if (vertstart != hsys->guides.totverts)
        {
-               hsys->verts = MEM_reallocN(hsys->verts, sizeof(HairGuideVertex) 
* vertstart);
-               hsys->totverts = vertstart;
+               hsys->guides.verts = MEM_reallocN(hsys->guides.verts, 
sizeof(HairGuideVertex) * vertstart);
+               hsys->guides.totverts = vertstart;
 
                BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
        }
@@ -249,9 +249,9 @@ void BKE_hair_guide_curves_end(HairSystem *hsys)
 
 void BKE_hair_set_guide_vertex(HairSystem *hsys, int index, int flag, const 
float co[3])
 {
-       BLI_assert(index <= hsys->totverts);
+       BLI_assert(index <= hsys->guides.totverts);
        
-       HairGuideVertex *vertex = &hsys->verts[index];
+       HairGuideVertex *vertex = &hsys->guides.verts[index];
        vertex->flag = flag;
        copy_v3_v3(vertex->co, co);
        
@@ -353,7 +353,7 @@ void BKE_hair_bind_follicles(HairSystem *hsys, DerivedMesh 
*scalp)
        hsys->flag &= ~HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
        
        HairPattern *pattern = hsys->pattern;
-       const int num_strands = hsys->totcurves;
+       const int num_strands = hsys->guides.totcurves;
        if (num_strands == 0 || !pattern)
                return;
        
@@ -361,7 +361,7 @@ void BKE_hair_bind_follicles(HairSystem *hsys, DerivedMesh 
*scalp)
        {
                for (int i = 0; i < num_strands; ++i) {
                        float nor[3], tang[3];
-                       if (!BKE_mesh_sample_eval(scalp, 
&hsys->curves[i].mesh_sample, strandloc[i], nor, tang)) {
+                       if (!BKE_mesh_sample_eval(scalp, 
&hsys->guides.curves[i].mesh_sample, strandloc[i], nor, tang)) {
                                zero_v3(strandloc[i]);
                        }
                }
diff --git a/source/blender/blenkernel/intern/hair_draw.c 
b/source/blender/blenkernel/intern/hair_draw.c
index 37de8bc742d..da90ff7aa4a 100644
--- a/source/blender/blenkernel/intern/hair_draw.c
+++ b/source/blender/blenkernel/intern/hair_draw.c
@@ -86,11 +86,11 @@ int* BKE_hair_get_fiber_lengths(const HairSystem *hsys, int 
subdiv)
        const int totfibers = hsys->pattern->num_follicles;
        int *fiber_length = MEM_mallocN(sizeof(int) * totfibers, "fiber 
length");
        
-       const int num_strands = hsys->totcurves;
+       const int num_strands = hsys->guides.totcurves;
        /* Cache subdivided lengths for repeated lookup */
        int *lengths = MEM_mallocN(sizeof(int) * num_strands, "strand length");
-       for (int i = 0; i < hsys->totcurves; ++i) {
-               lengths[i] = 
hair_get_strand_subdiv_length(hsys->curves[i].numverts, subdiv);
+       for (int i = 0; i < hsys->guides.totcurves; ++i) {
+               lengths[i] = 
hair_get_strand_subdiv_length(hsys->guides.curves[i].numverts, subdiv);
        }
        
        // Calculate the length of the fiber from the weighted average of its 
guide strands
@@ -198,7 +198,7 @@ static int hair_strand_subdivide(const HairSystem *hsys, 
const HairGuideCurve* c
                float (*dst)[3] = verts;
                int vertend = curve->vertstart + curve->numverts;
                for (int i = curve->vertstart; i < vertend; ++i) {
-                       copy_v3_v3(*dst, hsys->verts[i].co);
+                       copy_v3_v3(*dst, hsys->guides.verts[i].co);
                        dst += step;
                }
        }
@@ -239,15 +239,15 @@ static void hair_get_strand_buffer(
         HairStrandMapTextureBuffer *strand_map_buffer,
         HairStrandVertexTextureBuffer *strand_vertex_buffer)
 {
-       const int numverts = hair_get_strand_subdiv_numverts(hsys->totcurves, 
hsys->totverts, subdiv);
+       const int numverts = 
hair_get_strand_subdiv_numverts(hsys->guides.totcurves, hsys->guides.totverts, 
subdiv);
        
        float (*vertco)[3] = MEM_mallocN(sizeof(float[3]) * numverts, "strand 
vertex positions subdivided");
        
        HairStrandMapTextureBuffer *smap = strand_map_buffer;
        HairStrandVertexTextureBuffer *svert = strand_vertex_buffer;
        int vertex_start = 0;
-       for (int i = 0; i < hsys->totcurves; ++i) {
-               const HairGuideCurve *curve = &hsys->curves[i];
+       for (int i = 0; i < hsys->guides.totcurves; ++i) {
+               const HairGuideCurve *curve = &hsys->guides.curves[i];
                const int len_orig = curve->numverts;
                const int len = hair_get_strand_subdiv_length(len_orig, subdiv);
                smap->vertex_start = vertex_start;
@@ -258,7 +258,7 @@ static void hair_get_strand_buffer(
                {
                        float pos[3];
                        float matrix[3][3];
-                       BKE_mesh_sample_eval(scalp, 
&hsys->curves[i].mesh_sample, pos, matrix[2], matrix[0]);
+                       BKE_mesh_sample_eval(scalp, 
&hsys->guides.curves[i].mesh_sample, pos, matrix[2], matrix[0]);
                        cross_v3_v3v3(matrix[1], matrix[2], matrix[0]);
                        hair_strand_calc_vectors(vertco + vertex_start, len, 
matrix, svert);
                }
@@ -300,8 +300,8 @@ void BKE_hair_get_texture_buffer_size(
         int *r_strand_vertex_start,
         int *r_fiber_start)
 {
-       int numstrands = hsys->totcurves;
-       int numverts_orig = hsys->totverts;
+       int numstrands = hsys->guides.totcurves;
+       int numverts_orig = hsys->guides.totverts;
        int numfibers = hsys->pattern ? hsys->pattern->num_follicles : 0;
        const int numverts = hair_get_strand_subdiv_numverts(numstrands, 
numverts_orig, subdiv);
        *r_strand_map_start = 0;
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index ac5673e1402..452ce42d5a3 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5228,8 +5228,8 @@ static void direct_link_hair(FileData *fd, HairSystem* 
hsys)
                hsys->pattern->follicles = newdataadr(fd, 
hsys->pattern->follicles);
        }
        
-       hsys->curves = newdataadr(fd, hsys->curves);
-       hsys->verts = newdataadr(fd, hsys->verts);
+       hsys->guides.curves = newdataadr(fd, hsys->guides.curves);
+       hsys->guides.verts = newdataadr(fd, hsys->guides.verts);
        
        hsys->draw_batch_cache = NULL;
        hsys->draw_texture_cache = NULL;
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index 973fac1d13a..580d821be5b 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1775,8 +1775,8 @@ static void write_hair(WriteData *wd, HairSystem *hsys)
                writestruct(wd, DATA, HairFollicle, 
hsys->pattern->num_follicles, hsys->pattern->follicles);
        }
        
-       writestruct(wd, DATA, HairGuideCurve, hsys->totcurves, hsys->curves);
-       writestruct(wd, DATA, HairGuideVertex, hsys->totverts, hsys->verts);
+       writestruct(wd, DATA, HairGuideCurve, hsys->guides.totcurves, 
hsys->guides.curves);
+       writestruct(wd, DATA, HairGuideVertex, hsys->guides.totverts, 
hsys->guides.verts);
 }
 
 static void write_modifiers(WriteData *wd, ListBase *modbase)
diff --git a/source/blender/makesdna/DNA_hair_types.h 
b/source/blender/makesdna/DNA_hair_types.h
index 8a95077c7f6..26833792ab2 100644
--- a/source/blender/makesdna/DNA_hair_types.h
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -68,13 +68,9 @@ typedef struct HairGuideVertex {
        float co[3];
 } HairGuideVertex;
 
-typedef struct HairSystem {
-       int flag;
-       int pad;
-       
-       /* Set of hair follicles on the scalp mesh */
-       struct HairPattern *pattern;
-       
+/* Guide curve data */
+typedef struct HairGuideData
+{
        /* Curves for guiding hair fibers */
        struct HairGuideCurve *curves;
        /* Control vertices on guide curves */
@@ -83,6 +79,17 @@ typedef struct HairSystem {
        int totcurves;
        /* Number of guide curve vertices */
        int totverts;
+} HairGuideData;
+
+typedef struct HairSystem {
+       int flag;
+       int pad;
+       
+       /* Set of hair follicles on the scalp mesh */
+       struct HairPattern *pattern;
+       
+       /* Guide curve data */
+       HairGuideData guides;
        
        /* Material used for drawing and rendering hair fibers */
        int material_index;

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

Reply via email to