[Bf-blender-cvs] [27cfc39] hair_system: Operator for copying hair data from old particle systems to the new hair data structure.

Lukas Tönne noreply at git.blender.org
Fri Jul 25 19:35:01 CEST 2014


Commit: 27cfc39a29289bf53a29b510d3758a446d055f2c
Author: Lukas Tönne
Date:   Fri Jul 25 19:33:22 2014 +0200
Branches: hair_system
https://developer.blender.org/rB27cfc39a29289bf53a29b510d3758a446d055f2c

Operator for copying hair data from old particle systems to the new
hair data structure.

This will allow a quick initialization of the hair data with real world
examples, so we can test the hair simulation etc. without having to
write setup code or fully fledged tools first.

Possibly could also allow porting of old blend file data, but that is
of secondary importance for now.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/editors/physics/CMakeLists.txt
A	source/blender/editors/physics/hair_ops.c
M	source/blender/editors/physics/physics_intern.h
M	source/blender/editors/physics/physics_ops.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 784bfff..2097c46 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1223,7 +1223,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "material_offset", text="Material Offset")
 
     def HAIR(self, layout, ob, md):
-        pass
+        col = layout.column()
+        col.operator("hair.copy_from_particles")
 
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt
index 892d71b..5a07d55 100644
--- a/source/blender/editors/physics/CMakeLists.txt
+++ b/source/blender/editors/physics/CMakeLists.txt
@@ -36,6 +36,7 @@ set(INC_SYS
 
 set(SRC
 	dynamicpaint_ops.c
+	hair_ops.c
 	particle_boids.c
 	particle_edit.c
 	particle_object.c
diff --git a/source/blender/editors/physics/hair_ops.c b/source/blender/editors/physics/hair_ops.c
new file mode 100644
index 0000000..ebc9e3e
--- /dev/null
+++ b/source/blender/editors/physics/hair_ops.c
@@ -0,0 +1,147 @@
+/*
+ * ***** 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 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Blender Foundation,
+ *                 Lukas Toenne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/physics/hair_ops.c
+ *  \ingroup edphys
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_hair_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+
+#include "BKE_context.h"
+#include "BKE_hair.h"
+#include "BKE_modifier.h"
+#include "BKE_object.h"
+#include "BKE_report.h"
+
+#include "ED_screen.h"
+
+#include "WM_types.h"
+#include "WM_api.h"
+
+#include "physics_intern.h" // own include
+
+static bool ED_hair_get(bContext *C, Object **r_ob, HairSystem **r_hsys)
+{
+	Object *ob;
+	HairModifierData *hmd;
+	
+	ob = CTX_data_active_object(C);
+	if (!ob)
+		return false;
+	
+	hmd = (HairModifierData *)modifiers_findByType(ob, eModifierType_Hair);
+	if (!hmd)
+		return false;
+	
+	if (r_ob) *r_ob = ob;
+	if (r_hsys) *r_hsys = hmd->hairsys;
+	return true;
+}
+
+static int ED_hair_active_poll(bContext *C)
+{
+	return ED_hair_get(C, NULL, NULL);
+}
+
+static void hair_copy_from_particles_psys(Object *ob, HairSystem *hsys, Object *pob, ParticleSystem *psys)
+{
+	HairCurve *hairs;
+	int tothairs;
+	float mat[4][4];
+	int i, k;
+	
+	/* matrix for bringing hairs from pob to ob space */
+	invert_m4_m4(ob->imat, ob->obmat);
+	mul_m4_m4m4(mat, ob->imat, pob->obmat);
+	
+	tothairs = psys->totpart;
+	hairs = BKE_hair_curve_add_multi(hsys, tothairs);
+	
+	for (i = 0; i < tothairs; ++i) {
+		ParticleData *pa = psys->particles + i;
+		HairCurve *hair = hairs + i;
+		HairPoint *points;
+		int totpoints;
+		
+		totpoints = pa->totkey;
+		points = BKE_hair_point_append_multi(hsys, hair, totpoints);
+		
+		for (k = 0; k < totpoints; ++k) {
+			HairKey *pa_key = pa->hair + k;
+			HairPoint *point = points + k;
+			
+			copy_v3_v3(point->co, pa_key->co);
+		}
+	}
+}
+
+static int hair_copy_from_particles_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	Object *ob;
+	HairSystem *hsys;
+	ED_hair_get(C, &ob, &hsys);
+	
+	CTX_DATA_BEGIN (C, Base *, base, selected_bases) {
+		Object *pob = base->object;
+		ParticleSystem *psys;
+		
+		for (psys = pob->particlesystem.first; psys; psys = psys->next) {
+			if (psys->part->type != PART_HAIR)
+				continue;
+			
+			hair_copy_from_particles_psys(ob, hsys, pob, psys);
+		}
+	}
+	CTX_DATA_END;
+	
+	return OPERATOR_FINISHED;
+}
+
+void HAIR_OT_copy_from_particles(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->idname = "HAIR_OT_copy_from_particles";
+	ot->name = "Copy from particles";
+	ot->description = "Copy hair data from particles to the hair system";
+
+	/* callbacks */
+	ot->exec = hair_copy_from_particles_exec;
+	ot->poll = ED_hair_active_poll;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
+}
diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h
index 77ce5a3..4b69c56 100644
--- a/source/blender/editors/physics/physics_intern.h
+++ b/source/blender/editors/physics/physics_intern.h
@@ -124,4 +124,7 @@ void RIGIDBODY_OT_world_add(struct wmOperatorType *ot);
 void RIGIDBODY_OT_world_remove(struct wmOperatorType *ot);
 void RIGIDBODY_OT_world_export(struct wmOperatorType *ot);
 
+/* hair_ops.c */
+void HAIR_OT_copy_from_particles(struct wmOperatorType *ot);
+
 #endif /* __PHYSICS_INTERN_H__ */
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index 48cc51f..32d27a2 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -102,6 +102,8 @@ static void operatortypes_particle(void)
 	WM_operatortype_append(RIGIDBODY_OT_world_add);
 	WM_operatortype_append(RIGIDBODY_OT_world_remove);
 //	WM_operatortype_append(RIGIDBODY_OT_world_export);
+
+	WM_operatortype_append(HAIR_OT_copy_from_particles);
 }
 
 static void keymap_particle(wmKeyConfig *keyconf)




More information about the Bf-blender-cvs mailing list