Commit: 8abe6745a49a9e6d2e5598352f4e8f4ba87f93fc
Author: Lukas Tönne
Date:   Mon Aug 7 10:54:02 2017 +0100
Branches: strand_editmode
https://developer.blender.org/rB8abe6745a49a9e6d2e5598352f4e8f4ba87f93fc

DNA data + modifier for storing persistent hair data.

This stores basic hair follicle data, rather than full fiber caches
(which should only be generated for render data).

Note that deformation by strands will just be one possible way to generate
hair fibers, so strands should be kept separate from the hair follicle data 
somewhat.

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

M       release/scripts/startup/bl_ui/properties_data_modifier.py
M       source/blender/blenkernel/BKE_hair.h
M       source/blender/blenkernel/intern/hair.c
M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/writefile.c
M       source/blender/editors/space_outliner/outliner_draw.c
A       source/blender/makesdna/DNA_hair_types.h
M       source/blender/makesdna/DNA_modifier_types.h
M       source/blender/makesdna/intern/makesdna.c
M       source/blender/makesrna/RNA_access.h
M       source/blender/makesrna/intern/CMakeLists.txt
M       source/blender/makesrna/intern/makesrna.c
A       source/blender/makesrna/intern/rna_hair.c
M       source/blender/makesrna/intern/rna_internal.h
M       source/blender/makesrna/intern/rna_modifier.c
M       source/blender/modifiers/CMakeLists.txt
M       source/blender/modifiers/MOD_modifiertypes.h
A       source/blender/modifiers/intern/MOD_hair.c
M       source/blender/modifiers/intern/MOD_util.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py 
b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 05321ee4486..9f62bf89204 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1528,6 +1528,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         if md.rest_source == 'BIND':
             layout.operator("object.correctivesmooth_bind", text="Unbind" if 
is_bind else "Bind")
 
+    def HAIR(self, layout, ob, md):
+        pass
+
 
 classes = (
     DATA_PT_modifiers,
diff --git a/source/blender/blenkernel/BKE_hair.h 
b/source/blender/blenkernel/BKE_hair.h
index 367741fb4fe..0aa5d96231d 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -34,8 +34,19 @@
 
 #include "BLI_utildefines.h"
 
+struct HairFollicle;
+struct HairPattern;
+
 static const unsigned int STRAND_INDEX_NONE = 0xFFFFFFFF;
 
+struct HairPattern* BKE_hair_new(void);
+struct HairPattern* BKE_hair_copy(struct HairPattern *hair);
+void BKE_hair_free(struct HairPattern *hair);
+
+void BKE_hair_set_num_follicles(struct HairPattern *hair, int num_follicles);
+
+/* ================================= */
+
 typedef struct HairFiber {
        /* Sample on the scalp mesh for the root vertex */
        MeshSample root;
diff --git a/source/blender/blenkernel/intern/hair.c 
b/source/blender/blenkernel/intern/hair.c
index f26c0ae6a5f..778c1460f77 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -37,12 +37,52 @@
 #include "BLI_kdtree.h"
 #include "BLI_rand.h"
 
+#include "DNA_hair_types.h"
+
 #include "BKE_DerivedMesh.h"
 #include "BKE_mesh_sample.h"
 #include "BKE_hair.h"
 
 #include "bmesh.h"
 
+HairPattern* BKE_hair_new(void)
+{
+       HairPattern *hair = MEM_mallocN(sizeof(HairPattern), "hair");
+       
+       hair->follicles = NULL;
+       hair->num_follicles = 0;
+       
+       return hair;
+}
+
+HairPattern* BKE_hair_copy(HairPattern *hair)
+{
+       HairPattern *newhair = MEM_dupallocN(hair);
+       
+       newhair->follicles = MEM_dupallocN(hair->follicles);
+       
+       return newhair;
+}
+
+void BKE_hair_free(struct HairPattern *hair)
+{
+       if (hair->follicles) {
+               MEM_freeN(hair->follicles);
+       }
+       
+       MEM_freeN(hair);
+}
+
+void BKE_hair_set_num_follicles(HairPattern *hair, int num_follicles)
+{
+       if (hair->num_follicles != num_follicles) {
+               hair->follicles = MEM_reallocN_id(hair->follicles, 
sizeof(HairFollicle) * num_follicles, "hair follicles");
+               hair->num_follicles = num_follicles;
+       }
+}
+
+/* ================================= */
+
 bool BKE_hair_fiber_get_location(const HairFiber *fiber, DerivedMesh *root_dm, 
float loc[3])
 {
        float nor[3], tang[3];
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 988101e4bcb..9fdb0152dfe 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -73,6 +73,7 @@
 #include "DNA_genfile.h"
 #include "DNA_group_types.h"
 #include "DNA_gpencil_types.h"
+#include "DNA_hair_types.h"
 #include "DNA_ipo_types.h"
 #include "DNA_key_types.h"
 #include "DNA_lattice_types.h"
@@ -5118,6 +5119,15 @@ static void direct_link_pose(FileData *fd, bPose *pose)
        }
 }
 
+static void direct_link_hair(FileData *fd, HairPattern *hair)
+{
+       if (!hair) {
+               return;
+       }
+       
+       hair->follicles = newdataadr(fd, hair->follicles);
+}
+
 static void direct_link_modifiers(FileData *fd, ListBase *lb)
 {
        ModifierData *md;
@@ -5439,6 +5449,14 @@ static void direct_link_modifiers(FileData *fd, ListBase 
*lb)
                                }
                        }
                }
+               else if (md->type == eModifierType_Hair) {
+                       HairModifierData *hmd = (HairModifierData *)md;
+                       
+                       hmd->hair = newdataadr(fd, hmd->hair);
+                       direct_link_hair(fd, hmd->hair);
+                       
+                       hmd->edit = NULL;
+               }
        }
 }
 
diff --git a/source/blender/blenloader/intern/writefile.c 
b/source/blender/blenloader/intern/writefile.c
index bf50ba8975a..2f7c64d3bd8 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -121,6 +121,7 @@
 #include "DNA_group_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_fileglobal_types.h"
+#include "DNA_hair_types.h"
 #include "DNA_key_types.h"
 #include "DNA_lattice_types.h"
 #include "DNA_lamp_types.h"
@@ -1706,6 +1707,11 @@ static void write_fmaps(WriteData *wd, ListBase *fbase)
        }
 }
 
+static void write_hair(WriteData *wd, HairPattern *hair)
+{
+       writestruct(wd, DATA, HairPattern, hair->num_follicles, 
hair->follicles);
+}
+
 static void write_modifiers(WriteData *wd, ListBase *modbase)
 {
        ModifierData *md;
@@ -1877,6 +1883,14 @@ static void write_modifiers(WriteData *wd, ListBase 
*modbase)
                                }
                        }
                }
+               else if (md->type == eModifierType_Hair) {
+                       HairModifierData *hmd = (HairModifierData *)md;
+                       
+                       if (hmd->hair) {
+                               writestruct(wd, DATA, HairPattern, 1, 
hmd->hair);
+                               write_hair(wd, hmd->hair);
+                       }
+               }
        }
 }
 
diff --git a/source/blender/editors/space_outliner/outliner_draw.c 
b/source/blender/editors/space_outliner/outliner_draw.c
index 7a1eca0f179..ed3bd84be8c 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -1017,6 +1017,9 @@ static void tselem_draw_icon(uiBlock *block, int xmax, 
float x, float y, TreeSto
                                        case eModifierType_NormalEdit:
                                                ICON_DRAW(ICON_MOD_NORMALEDIT);
                                                break;
+                                       case eModifierType_Hair:
+                                               ICON_DRAW(ICON_STRANDS);
+                                               break;
                                        /* Default */
                                        case eModifierType_None:
                                        case eModifierType_ShapeKey:
diff --git a/source/blender/makesdna/DNA_hair_types.h 
b/source/blender/makesdna/DNA_hair_types.h
new file mode 100644
index 00000000000..57619396e1b
--- /dev/null
+++ b/source/blender/makesdna/DNA_hair_types.h
@@ -0,0 +1,57 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software  Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file DNA_hair_types.h
+ *  \ingroup DNA
+ */
+
+#ifndef __DNA_HAIR_TYPES_H__
+#define __DNA_HAIR_TYPES_H__
+
+#include "DNA_defs.h"
+#include "DNA_listBase.h"
+#include "DNA_ID.h"
+#include "DNA_meshdata_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Root point (follicle) of a hair on a surface */
+typedef struct HairFollicle {
+       /* Sample on the scalp mesh for the root vertex */
+       MeshSample mesh_sample;
+} HairFollicle;
+
+/* Collection of hair roots on a surface */
+typedef struct HairPattern {
+       struct HairFollicle *follicles;
+       int num_follicles;
+       int pad;
+} HairPattern;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DNA_HAIR_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index 4959055ed10..ef5f9df2298 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -87,6 +87,7 @@ typedef enum ModifierType {
        eModifierType_CorrectiveSmooth  = 51,
        eModifierType_MeshSequenceCache = 52,
        eModifierType_SurfaceDeform     = 53,
+       eModifierType_Hair              = 54,
        NUM_MODIFIER_TYPES
 } ModifierType;
 
@@ -1615,4 +1616,17 @@ enum {
 #define MOD_MESHSEQ_READ_ALL \
        (MOD_MESHSEQ_READ_VERT | MOD_MESHSEQ_READ_POLY | MOD_MESHSEQ_READ_UV | 
MOD_MESHSEQ_READ_COLOR)
 
+/* Hair modifier */
+typedef struct HairModifierData {
+       ModifierData modifier;
+       
+       int flag;
+       int pad;
+       
+       struct HairPattern *hair;
+       
+       struct BMEditStrands *edit;         /* edit data (runtime) */
+       
+} HairModifierData;
+
 #endif  /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesdna/intern/makesdna.c 
b/source/blender/makesdna/intern/makesdna.c
index 182a026df94..1edd5f8010e 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -133,6 +133,7 @@ static const char *includefiles[] = {
        "DNA_layer_types.h",
        "DNA_workspace_types.h",
        "DNA_lightprobe_types.h",
+       "DNA_hair_types.h",
 
        /* see comment above before editing! */
 
@@ -1360,5 +1361,6 @@ int main(int argc, char **argv)
 #include "DNA_layer_types.h"
 #include "DNA_workspace_types.h"
 #include "DNA_lightprobe_types.h"
+#include "DNA_hair_types.h"
 
 /* end of list */
diff --git a/source/blender/makesrna/RNA_access.h 
b/source/blender/makesrna/RNA_access.h
index a07cb86fdf7..1c01b5b460d 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -283,6 +283,7 @@ extern StructRNA RNA_GaussianBlurSequence;
 extern StructRNA RNA_GlowSequence;
 extern StructRNA RNA_GreasePencil;
 extern StructRNA RNA_Group;
+extern StructRNA RNA_HairModifier;
 extern StructRNA RNA_Header;
 extern StructRNA RNA_HemiLamp;
 extern StructRNA RNA_Histogram;
diff --git a/source/blender/makesrna/intern/CMakeLists.txt 
b/source/blender/makesrna/intern/CMakeLists.txt
index aede2bd9708..01831c95b7a 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -52,6 +52,7 @@ set(DEFSRC
        rna_fluidsim.c
        rna_gpencil.c
        rna_group.c
+       rna_hair.c
        rna_image.c
        rna_key.c
        rna_lamp.c
diff --git a/source/blender/makesrna/intern/makesrna.c 
b/source/blender/makesrna/intern/makesrna.c
index 4c0a1e9c181..579b72e55ad 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -3326,6 +3326,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
        {"rna_fluidsim.c", NULL, RNA_def_fluidsim},
        {"rna_gpencil.c", NULL, RNA_def_gpencil},
        {"rna_group.c

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to