Commit: 6621546d0c2ed57dfb26681b878d45b75f257506
Author: Lukas Tönne
Date:   Wed Jul 6 16:34:12 2016 +0200
Branches: strand_gpu
https://developer.blender.org/rB6621546d0c2ed57dfb26681b878d45b75f257506

Store a copy of the strand roots array in the strand edit data.

This will allow the edit mode to display render strands as well.
The roots may later be re-scattered or otherwise modified during editing,
and are eventually copied back to the Strands data when applying edits.

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

M       source/blender/blenkernel/BKE_editstrands.h
M       source/blender/blenkernel/intern/editstrands.c
M       source/blender/editors/hair/hair_object_mesh.c
M       source/blender/editors/hair/hair_object_particles.c
M       source/blender/editors/hair/hair_object_strands.c
M       source/blender/editors/hair/hair_undo.c

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

diff --git a/source/blender/blenkernel/BKE_editstrands.h 
b/source/blender/blenkernel/BKE_editstrands.h
index b456666..7e56170 100644
--- a/source/blender/blenkernel/BKE_editstrands.h
+++ b/source/blender/blenkernel/BKE_editstrands.h
@@ -46,12 +46,16 @@ struct DerivedMesh;
 struct Mesh;
 struct Object;
 struct Strands;
+struct StrandRoot;
 
 typedef struct BMEditStrands {
        BMEditMesh base;
        
+       /* Hair follicles */
+       struct StrandRoot *roots;
        /* Scalp mesh for fixing root vertices */
        struct DerivedMesh *root_dm;
+       int num_roots;
        
        int flag;
        
@@ -63,7 +67,8 @@ typedef enum BMEditStrandsFlag {
        BM_STRANDS_DIRTY_SEGLEN     = 1,
 } BMEditStrandsFlag;
 
-struct BMEditStrands *BKE_editstrands_create(struct BMesh *bm, struct 
DerivedMesh *root_dm);
+struct BMEditStrands *BKE_editstrands_create(struct BMesh *bm, struct 
DerivedMesh *root_dm,
+                                             struct StrandRoot *roots, int 
num_roots);
 struct BMEditStrands *BKE_editstrands_copy(struct BMEditStrands *es);
 struct BMEditStrands *BKE_editstrands_from_object(struct Object *ob);
 void BKE_editstrands_update_linked_customdata(struct BMEditStrands *es);
diff --git a/source/blender/blenkernel/intern/editstrands.c 
b/source/blender/blenkernel/intern/editstrands.c
index 259cafd..8110aa8 100644
--- a/source/blender/blenkernel/intern/editstrands.c
+++ b/source/blender/blenkernel/intern/editstrands.c
@@ -60,12 +60,16 @@
 #include "intern/bmesh_mesh_conv.h"
 #include "intern/bmesh_strands_conv.h"
 
-BMEditStrands *BKE_editstrands_create(BMesh *bm, DerivedMesh *root_dm)
+BMEditStrands *BKE_editstrands_create(BMesh *bm, DerivedMesh *root_dm, 
StrandRoot *roots, int num_roots)
 {
        BMEditStrands *es = MEM_callocN(sizeof(BMEditStrands), __func__);
        
        es->base.bm = bm;
        es->root_dm = CDDM_copy(root_dm);
+       if (roots && num_roots > 0) {
+               es->roots = MEM_dupallocN(roots);
+               es->num_roots = num_roots;
+       }
        
        return es;
 }
@@ -77,6 +81,10 @@ BMEditStrands *BKE_editstrands_copy(BMEditStrands *es)
        
        es_copy->base.bm = BM_mesh_copy(es->base.bm);
        es_copy->root_dm = CDDM_copy(es->root_dm);
+       if (es->roots) {
+               es_copy->roots = MEM_dupallocN(es->roots);
+               es_copy->num_roots = es->num_roots;
+       }
        
        es_copy->gpu_buffer = NULL;
        
@@ -129,6 +137,8 @@ void BKE_editstrands_free(BMEditStrands *es)
                BM_mesh_free(es->base.bm);
        if (es->root_dm)
                es->root_dm->release(es->root_dm);
+       if (es->roots)
+               MEM_freeN(es->roots);
        
        if (es->gpu_buffer)
                GPU_strands_buffer_free(es->gpu_buffer);
diff --git a/source/blender/editors/hair/hair_object_mesh.c 
b/source/blender/editors/hair/hair_object_mesh.c
index a1140c0..35df5a8 100644
--- a/source/blender/editors/hair/hair_object_mesh.c
+++ b/source/blender/editors/hair/hair_object_mesh.c
@@ -56,7 +56,7 @@ bool ED_hair_object_init_mesh_edit(Scene *UNUSED(scene), 
Object *ob)
                        BMesh *bm = BKE_editstrands_mesh_to_bmesh(ob, me);
                        DerivedMesh *root_dm = CDDM_new(0, 0, 0, 0, 0);
                        
-                       me->edit_strands = BKE_editstrands_create(bm, root_dm);
+                       me->edit_strands = BKE_editstrands_create(bm, root_dm, 
NULL, 0);
                        
                        root_dm->release(root_dm);
                }
diff --git a/source/blender/editors/hair/hair_object_particles.c 
b/source/blender/editors/hair/hair_object_particles.c
index b317763..8092290 100644
--- a/source/blender/editors/hair/hair_object_particles.c
+++ b/source/blender/editors/hair/hair_object_particles.c
@@ -73,7 +73,7 @@ bool ED_hair_object_init_particle_edit(Scene *scene, Object 
*ob)
                        else
                                dm = NULL;
                        
-                       psys->hairedit = BKE_editstrands_create(bm, dm);
+                       psys->hairedit = BKE_editstrands_create(bm, dm, NULL, 
0);
                }
                return true;
        }
diff --git a/source/blender/editors/hair/hair_object_strands.c 
b/source/blender/editors/hair/hair_object_strands.c
index 8c9104c..c5695ae 100644
--- a/source/blender/editors/hair/hair_object_strands.c
+++ b/source/blender/editors/hair/hair_object_strands.c
@@ -63,7 +63,7 @@ bool ED_hair_object_init_strands_edit(Scene *scene, Object 
*ob)
                if (dm) {
                        BMesh *bm = 
BKE_editstrands_strands_to_bmesh(smd->strands, dm);
                        
-                       smd->edit = BKE_editstrands_create(bm, dm);
+                       smd->edit = BKE_editstrands_create(bm, dm, smd->roots, 
smd->num_roots);
                        
                        return true;
                }
@@ -83,15 +83,19 @@ bool ED_hair_object_apply_strands_edit(Scene *scene, Object 
*ob)
                                
BKE_editstrands_strands_from_bmesh(smd->strands, smd->edit->base.bm, dm);
                        }
                        
-                       BKE_editstrands_free(smd->edit);
-                       MEM_freeN(smd->edit);
-                       smd->edit = NULL;
-                       
                        /* invalidate roots */
                        if (smd->roots) {
                                MEM_freeN(smd->roots);
                                smd->roots = NULL;
                        }
+                       if (smd->edit->num_roots) {
+                               smd->roots = MEM_dupallocN(smd->edit->roots);
+                               smd->num_roots = smd->edit->num_roots;
+                       }
+                       
+                       BKE_editstrands_free(smd->edit);
+                       MEM_freeN(smd->edit);
+                       smd->edit = NULL;
                }
                
                return true;
diff --git a/source/blender/editors/hair/hair_undo.c 
b/source/blender/editors/hair/hair_undo.c
index cb5ae43..01c3385 100644
--- a/source/blender/editors/hair/hair_undo.c
+++ b/source/blender/editors/hair/hair_undo.c
@@ -113,6 +113,8 @@ static void strands_undo_to_edit(void *undov, void *editv, 
void *UNUSED(obdata))
        BMEditStrands *edit = editv, *edit_tmp;
        Object *ob = edit->base.ob;
        DerivedMesh *dm = edit->root_dm;
+       struct StrandRoot *roots_tmp;
+       int num_roots_tmp;
        BMesh *bm;
 //     Key *key = ((Mesh *) obdata)->key;
        struct BMeshFromMeshParams params = {0};
@@ -131,9 +133,15 @@ static void strands_undo_to_edit(void *undov, void *editv, 
void *UNUSED(obdata))
         * because it owns the root_dm and we have to copy it before
         * it gets released when freeing the old edit.
         */
-       edit_tmp = BKE_editstrands_create(bm, dm);
+       edit_tmp = BKE_editstrands_create(bm, dm, NULL, 0);
+       /* keep roots array */
+       roots_tmp = edit->roots;
+       num_roots_tmp = edit->num_roots;
+       
        BKE_editstrands_free(edit);
        *edit = *edit_tmp;
+       edit->roots = roots_tmp;
+       edit->num_roots = num_roots_tmp;
        
        bm->selectmode = undo->selectmode;
        edit->base.ob = ob;

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

Reply via email to