[Bf-blender-cvs] [d69735a] hair_system: Stub hair simulation modifier to attach a hair system to an object.

Lukas Tönne noreply at git.blender.org
Thu Jul 24 14:49:37 CEST 2014


Commit: d69735abce2481c4350a67f3f0c6499eb953569b
Author: Lukas Tönne
Date:   Thu Jul 24 13:01:22 2014 +0200
Branches: hair_system
https://developer.blender.org/rBd69735abce2481c4350a67f3f0c6499eb953569b

Stub hair simulation modifier to attach a hair system to an object.

The modifier should never get anything more than a hair system and
some basic access features, all the logic should be in the hair system
only.

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

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/makesdna/DNA_modifier_types.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 5769db5..784bfff 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1222,6 +1222,9 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
 
         col.prop(md, "material_offset", text="Material Offset")
 
+    def HAIR(self, layout, ob, md):
+        pass
+
 
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)
diff --git a/source/blender/blenkernel/BKE_hair.h b/source/blender/blenkernel/BKE_hair.h
index e5077df..2a3c5e8 100644
--- a/source/blender/blenkernel/BKE_hair.h
+++ b/source/blender/blenkernel/BKE_hair.h
@@ -33,6 +33,10 @@
 
 struct HairSystem;
 
+struct HairSystem *BKE_hairsys_new(void);
+void BKE_hairsys_free(struct HairSystem *hsys);
+struct HairSystem *BKE_hairsys_copy(struct HairSystem *hsys);
+
 void BKE_hair_calc_curve_offsets(HairSystem *hsys);
 
 #endif
diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c
index ebc0a30..76cab0a 100644
--- a/source/blender/blenkernel/intern/hair.c
+++ b/source/blender/blenkernel/intern/hair.c
@@ -28,10 +28,36 @@
  *  \ingroup bke
  */
 
+#include "MEM_guardedalloc.h"
+
 #include "DNA_hair_types.h"
 
 #include "BKE_hair.h"
 
+struct HairSystem *BKE_hairsys_new(void)
+{
+	HairSystem *hsys = MEM_callocN(sizeof(HairSystem), "hair system");
+	return hsys;
+}
+
+void BKE_hairsys_free(struct HairSystem *hsys)
+{
+	if (hsys->curves)
+		MEM_freeN(hsys->curves);
+	if (hsys->points)
+		MEM_freeN(hsys->points);
+	MEM_freeN(hsys);
+}
+
+struct HairSystem *BKE_hairsys_copy(struct HairSystem *hsys)
+{
+	HairSystem *thsys = MEM_dupallocN(hsys);
+	thsys->points = MEM_dupallocN(hsys->points);
+	thsys->curves = MEM_dupallocN(hsys->curves);
+	
+	return thsys;
+}
+
 void BKE_hair_calc_curve_offsets(HairSystem *hsys)
 {
 	HairCurve *hair;
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 2bd33ae..31b11d0 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -82,6 +82,7 @@ typedef enum ModifierType {
 	eModifierType_MeshCache         = 46,
 	eModifierType_LaplacianDeform   = 47,
 	eModifierType_Wireframe         = 48,
+	eModifierType_Hair              = 49,
 	NUM_MODIFIER_TYPES
 } ModifierType;
 
@@ -1365,6 +1366,11 @@ enum {
 	MOD_WIREFRAME_CREASE        = (1 << 5),
 };
 
+typedef struct HairModifierData {
+	ModifierData modifier;
+	
+	struct HairSystem *hairsys;
+} HairModifierData;
 
 
 #endif  /* __DNA_MODIFIER_TYPES_H__ */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index fb76010..4086414 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -102,6 +102,7 @@ EnumPropertyItem modifier_type_items[] = {
 	{eModifierType_DynamicPaint, "DYNAMIC_PAINT", ICON_MOD_DYNAMICPAINT, "Dynamic Paint", ""},
 	{eModifierType_Explode, "EXPLODE", ICON_MOD_EXPLODE, "Explode", ""},
 	{eModifierType_Fluidsim, "FLUID_SIMULATION", ICON_MOD_FLUIDSIM, "Fluid Simulation", ""},
+	{eModifierType_Hair, "HAIR", ICON_HAIR, "Hair", ""},
 	{eModifierType_Ocean, "OCEAN", ICON_MOD_OCEAN, "Ocean", ""},
 	{eModifierType_ParticleInstance, "PARTICLE_INSTANCE", ICON_MOD_PARTICLES, "Particle Instance", ""},
 	{eModifierType_ParticleSystem, "PARTICLE_SYSTEM", ICON_MOD_PARTICLES, "Particle System", ""},
@@ -244,6 +245,8 @@ static StructRNA *rna_Modifier_refine(struct PointerRNA *ptr)
 			return &RNA_LaplacianDeformModifier;
 		case eModifierType_Wireframe:
 			return &RNA_WireframeModifier;
+		case eModifierType_Hair:
+			return &RNA_HairModifier;
 		/* Default */
 		case eModifierType_None:
 		case eModifierType_ShapeKey:
@@ -3659,6 +3662,17 @@ static void rna_def_modifier_wireframe(BlenderRNA *brna)
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 }
 
+static void rna_def_modifier_hair(BlenderRNA *brna)
+{
+	StructRNA *srna;
+//	PropertyRNA *prop;
+
+	srna = RNA_def_struct(brna, "HairModifier", "Modifier");
+	RNA_def_struct_ui_text(srna, "Hair Modifier", "Hair simulation modifier");
+	RNA_def_struct_sdna(srna, "HairModifierData");
+	RNA_def_struct_ui_icon(srna, ICON_HAIR);
+}
+
 void RNA_def_modifier(BlenderRNA *brna)
 {
 	StructRNA *srna;
@@ -3771,6 +3785,7 @@ void RNA_def_modifier(BlenderRNA *brna)
 	rna_def_modifier_meshcache(brna);
 	rna_def_modifier_laplaciandeform(brna);
 	rna_def_modifier_wireframe(brna);
+	rna_def_modifier_hair(brna);
 }
 
 #endif
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index b841356..e300469 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -60,6 +60,7 @@ set(SRC
 	intern/MOD_explode.c
 	intern/MOD_fluidsim.c
 	intern/MOD_fluidsim_util.c
+	intern/MOD_hair.c
 	intern/MOD_hook.c
 	intern/MOD_laplaciandeform.c
 	intern/MOD_laplaciansmooth.c
diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h
index 9c7c21c..68fa8d1 100644
--- a/source/blender/modifiers/MOD_modifiertypes.h
+++ b/source/blender/modifiers/MOD_modifiertypes.h
@@ -81,6 +81,7 @@ extern ModifierTypeInfo modifierType_UVWarp;
 extern ModifierTypeInfo modifierType_MeshCache;
 extern ModifierTypeInfo modifierType_LaplacianDeform;
 extern ModifierTypeInfo modifierType_Wireframe;
+extern ModifierTypeInfo modifierType_Hair;
 
 /* MOD_util.c */
 void modifier_type_init(ModifierTypeInfo *types[]);
diff --git a/source/blender/modifiers/intern/MOD_hair.c b/source/blender/modifiers/intern/MOD_hair.c
new file mode 100644
index 0000000..e22896e
--- /dev/null
+++ b/source/blender/modifiers/intern/MOD_hair.c
@@ -0,0 +1,119 @@
+/*
+ * ***** 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.
+ *
+ * The Original Code is Copyright (C) 2014 by the Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file blender/modifiers/intern/MOD_hair.c
+ *  \ingroup modifiers
+ */
+
+#include "BLI_utildefines.h"
+
+#include "DNA_hair_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_DerivedMesh.h"
+#include "BKE_hair.h"
+#include "BKE_modifier.h"
+
+#include "depsgraph_private.h"
+
+#include "MOD_util.h"
+#include "MEM_guardedalloc.h"
+
+static void initData(ModifierData *md)
+{
+	HairModifierData *hmd = (HairModifierData *) md;
+	
+	hmd->hairsys = BKE_hairsys_new();
+}
+static void freeData(ModifierData *md)
+{
+	HairModifierData *hmd = (HairModifierData *) md;
+	
+	BKE_hairsys_free(hmd->hairsys);
+}
+
+static void copyData(ModifierData *md, ModifierData *target)
+{
+	HairModifierData *hmd = (HairModifierData *) md;
+	HairModifierData *thmd = (HairModifierData *) target;
+	
+	if (thmd->hairsys)
+		BKE_hairsys_free(thmd->hairsys);
+	
+	thmd->hairsys = BKE_hairsys_copy(hmd->hairsys);
+}
+
+static DerivedMesh *applyModifier(ModifierData *UNUSED(md), Object *UNUSED(ob),
+                                  DerivedMesh *dm,
+                                  ModifierApplyFlag UNUSED(flag))
+{
+	/*HairModifierData *hmd = (HairModifierData *) md;*/
+	
+	return dm;
+}
+
+static void updateDepgraph(
+        ModifierData *UNUSED(md), DagForest *UNUSED(forest), Scene *UNUSED(scene),
+        Object *UNUSED(ob), DagNode *UNUSED(obNode))
+{
+	/*HairModifierData *hmd = (HairModifierData *) md;*/
+}
+
+static bool dependsOnTime(ModifierData *UNUSED(md))
+{
+	return true;
+}
+
+
+ModifierTypeInfo modifierType_Hair = {
+	/* name */              "Hair",
+	/* structName */        "HairModifierData",
+	/* structSize */        sizeof(HairModifierData),
+	/* type */              eModifierTypeType_Nonconstructive,
+
+	/* flags */             eModifierTypeFlag_AcceptsMesh |
+	                        eModifierTypeFlag_RequiresOriginalData |
+	                        eModifierTypeFlag_Single,
+
+	/* copyData */          copyData,
+	/* deformVerts */       NULL,
+	/* deformMatrices */    NULL,
+	/* deformVertsEM */     NULL,
+	/* deformMatricesEM */  NULL,
+	/* applyModifier */     applyModifier,
+	/* applyModifierEM */   NULL,
+	/* initData */          initData,
+	/* requiredDataMask */  NULL,
+	/* freeData */          freeData,
+	/* isDisabled */        NULL,
+	/* updateDepgraph */    updateDepgraph,
+	/* dependsOnTime */     dependsOnTime,
+	/* dependsOnNormals */	NULL,
+	/* foreachObjectLink */ NULL,
+	/* foreachIDLink */     NULL,
+	/* foreachTexLink */    NULL,
+};
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index 829c2b8..da3f8e5 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -309,5 +309,6 @@ void modifier_type_init(ModifierTypeInfo *types[])
 	INIT_TYPE(MeshCache);
 	INIT_TYPE(LaplacianDeform);
 	INIT_TYPE(Wireframe);
+	INIT_TYPE(Hair);
 #undef INIT_TYPE
 }




More information about the Bf-blender-cvs mailing list