Commit: 974e55e3e62e04983870c55341522abee316748f
Author: Lukas Tönne
Date:   Sun Apr 15 13:30:38 2018 +0100
Branches: hair_guides
https://developer.blender.org/rB974e55e3e62e04983870c55341522abee316748f

Alternative guide curve setter function that works better for RNA.

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

M       source/blender/blenkernel/BKE_hair.h
M       source/blender/blenkernel/intern/hair.c

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

diff --git a/source/blender/blenkernel/BKE_hair.h 
b/source/blender/blenkernel/BKE_hair.h
index 01e4d3e0abe..be526233ac6 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -75,6 +75,10 @@ void BKE_hair_guide_curves_end(struct HairSystem *hsys);
  */
 void BKE_hair_set_guide_vertex(struct HairSystem *hsys, int index, int flag, 
const float co[3]);
 
+/* Set the hair guide data used by the hair system.
+ */
+void BKE_hair_set_hair_guides(struct HairSystem *hsys, struct HairGuideData 
*guides);
+
 /* === Follicles === */
 
 /* Calculate surface area of a scalp mesh */
diff --git a/source/blender/blenkernel/intern/hair.c 
b/source/blender/blenkernel/intern/hair.c
index 9d9f9df26c8..32794412826 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -228,7 +228,10 @@ void BKE_hair_set_guide_curve(HairSystem *hsys, int index, 
const MeshSample *mes
        BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
 }
 
-void BKE_hair_guide_curves_end(HairSystem *hsys)
+/* Calculate vertex start indices on all curves based on length.
+ * Returns the total number of vertices.
+ */
+static int hair_guide_calc_vertstart(HairSystem *hsys)
 {
        /* Recalculate vertex count and start offsets in curves */
        int vertstart = 0;
@@ -237,11 +240,18 @@ void BKE_hair_guide_curves_end(HairSystem *hsys)
                hsys->guides.curves[i].vertstart = vertstart;
                vertstart += hsys->guides.curves[i].numverts;
        }
+       
+       return vertstart;
+}
+
+void BKE_hair_guide_curves_end(HairSystem *hsys)
+{
+       const int totverts = hair_guide_calc_vertstart(hsys);
 
-       if (vertstart != hsys->guides.totverts)
+       if (totverts != hsys->guides.totverts)
        {
-               hsys->guides.verts = MEM_reallocN(hsys->guides.verts, 
sizeof(HairGuideVertex) * vertstart);
-               hsys->guides.totverts = vertstart;
+               hsys->guides.verts = MEM_reallocN(hsys->guides.verts, 
sizeof(HairGuideVertex) * totverts);
+               hsys->guides.totverts = totverts;
 
                BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
        }
@@ -258,6 +268,29 @@ void BKE_hair_set_guide_vertex(HairSystem *hsys, int 
index, int flag, const floa
        BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
 }
 
+void BKE_hair_set_hair_guides(HairSystem *hsys, HairGuideData *guides)
+{
+       if (hsys->guides.curves)
+       {
+               MEM_freeN(hsys->guides.curves);
+       }
+       hsys->guides.curves = MEM_dupallocN(hsys->guides.curves);
+       hsys->guides.totcurves = guides->totcurves;
+
+       if (hsys->guides.verts)
+       {
+               MEM_freeN(hsys->guides.verts);
+       }
+       hsys->guides.verts = MEM_dupallocN(hsys->guides.verts);
+       hsys->guides.totverts = guides->totverts;
+
+       const int vertcount = hair_guide_calc_vertstart(hsys);
+       BLI_assert(vertcount <= hsys->guides.totverts);
+
+       hsys->flag |= HAIR_SYSTEM_UPDATE_FOLLICLE_BINDING;
+       BKE_hair_batch_cache_dirty(hsys, BKE_HAIR_BATCH_DIRTY_ALL);
+}
+
 /* ================================= */
 
 BLI_INLINE void hair_fiber_verify_weights(HairFollicle *follicle)

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

Reply via email to