[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23020] branches/blender2.5/blender: Disconnect/connect hair:

Janne Karhu jhkarh at utu.fi
Sat Sep 5 22:12:09 CEST 2009


Revision: 23020
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23020
Author:   jhk
Date:     2009-09-05 22:12:08 +0200 (Sat, 05 Sep 2009)

Log Message:
-----------
Disconnect/connect hair:
- Moves hair from face-space to global space and back.
- Allows for editing of emitter mesh after hair combing.
- Disconnect hair before doing topology changing changes in mesh edit mode, connect after changes.
- Notes:
	* The closest location on emitter surface to the hair root is used to connect the hair.
	* Emitter deflection, sticky roots and add brush don't apply for disconnect hair in particle mode.
- Todo for future:
	* Copy disconnected hair from object to another (when 2.5 has proper copy operators again).
	* Possible automatic disconnect/connect with topology changing operations in mesh edit mode.
	
Other changes/fixes:
- Proper subtypes for some particle mode notifiers.
- Particle mode selections didn't draw correctly because of using lighting for the paths.

Modified Paths:
--------------
    branches/blender2.5/blender/release/ui/buttons_particle.py
    branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/particle.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/particle_system.c
    branches/blender2.5/blender/source/blender/editors/physics/editparticle.c
    branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_intern.h
    branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_ops.c
    branches/blender2.5/blender/source/blender/editors/space_buttons/space_buttons.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/drawobject.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_header.c
    branches/blender2.5/blender/source/blender/editors/transform/transform_conversions.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_particle.c
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_sculpt_paint.c

Modified: branches/blender2.5/blender/release/ui/buttons_particle.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_particle.py	2009-09-05 09:54:01 UTC (rev 23019)
+++ branches/blender2.5/blender/release/ui/buttons_particle.py	2009-09-05 20:12:08 UTC (rev 23020)
@@ -151,6 +151,11 @@
 					row = split.row()
 					row.enabled = particle_panel_enabled(psys)
 					row.itemR(part, "hair_step")
+					if psys.edited==True:
+						if psys.global_hair:
+							layout.itemO("particle.connect_hair")
+						else:
+							layout.itemO("particle.disconnect_hair")
 				elif part.type=='REACTOR':
 					split.enabled = particle_panel_enabled(psys)
 					split.itemR(psys, "reactor_target_object")

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h	2009-09-05 09:54:01 UTC (rev 23019)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_pointcache.h	2009-09-05 20:12:08 UTC (rev 23020)
@@ -192,6 +192,7 @@
 	struct ParticleData *particles;
 	struct KDTree *emitter_field;
 	float *emitter_cosnos;
+	int psys_flag;
 
 	/* cache stuff */
 	struct ListBase mem_cache;

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/particle.c	2009-09-05 09:54:01 UTC (rev 23019)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/particle.c	2009-09-05 20:12:08 UTC (rev 23020)
@@ -418,7 +418,7 @@
 		edit->pathcache= NULL;
 		edit->totcached= 0;
 	}
-	else {
+	if(psys) {
 		psys_free_path_cache_buffers(psys->pathcache, &psys->pathcachebufs);
 		psys->pathcache= NULL;
 		psys->totcached= 0;
@@ -2676,7 +2676,7 @@
 	baked = psys->pointcache->flag & PTCACHE_BAKED;
 
 	/* clear out old and create new empty path cache */
-	psys_free_path_cache(psys, NULL);
+	psys_free_path_cache(psys, psys->edit);
 	cache= psys->pathcache= psys_alloc_path_cache_buffers(&psys->pathcachebufs, totpart, steps+1);
 
 	if(psys->soft && psys->softflag & OB_SB_ENABLE) {
@@ -2891,7 +2891,7 @@
 
 	if(!cache || edit->totpoint != edit->totcached) {
 		/* clear out old and create new empty path cache */
-		psys_free_path_cache(NULL, edit);
+		psys_free_path_cache(edit->psys, edit);
 		cache= edit->pathcache= psys_alloc_path_cache_buffers(&edit->pathcachebufs, totpart, steps+1);
 	}
 
@@ -2946,7 +2946,7 @@
 			do_particle_interpolation(psys, i, pa, t, frs_sec, &pind, &result);
 
 			 /* non-hair points are allready in global space */
-			if(psys)
+			if(psys && !(psys->flag & PSYS_GLOBAL_HAIR))
 				Mat4MulVecfl(hairmat, result.co);
 
 			VECCOPY(ca->co, result.co);

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/particle_system.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/particle_system.c	2009-09-05 09:54:01 UTC (rev 23019)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/particle_system.c	2009-09-05 20:12:08 UTC (rev 23020)
@@ -158,7 +158,7 @@
 	psys->totchild= 0;
 
 	/* reset path cache */
-	psys_free_path_cache(psys, NULL);
+	psys_free_path_cache(psys, psys->edit);
 
 	/* reset point cache */
 	psys->pointcache->flag &= ~PTCACHE_SIMULATION_VALID;

Modified: branches/blender2.5/blender/source/blender/editors/physics/editparticle.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/physics/editparticle.c	2009-09-05 09:54:01 UTC (rev 23019)
+++ branches/blender2.5/blender/source/blender/editors/physics/editparticle.c	2009-09-05 20:12:08 UTC (rev 23020)
@@ -555,7 +555,7 @@
 	Mat4One(mat);
 
 	LOOP_VISIBLE_POINTS {
-		if(edit->psys) {
+		if(edit->psys && !(edit->psys->flag & PSYS_GLOBAL_HAIR)) {
 			psys_mat_hair_to_global(data->ob, psmd->dm, psys->part->from, psys->particles + p, mat);
 			Mat4Invert(imat,mat);
 		}
@@ -812,7 +812,7 @@
 	float *vec, *nor, dvec[3], dot, dist_1st;
 	float hairimat[4][4], hairmat[4][4];
 
-	if(edit==NULL || edit->psys==NULL || (pset->flag & PE_DEFLECT_EMITTER)==0)
+	if(edit==NULL || edit->psys==NULL || (pset->flag & PE_DEFLECT_EMITTER)==0 || (edit->psys->flag & PSYS_GLOBAL_HAIR))
 		return;
 
 	psys = edit->psys;
@@ -876,6 +876,9 @@
 	if(edit==0 || (pset->flag & PE_KEEP_LENGTHS)==0)
 		return;
 
+	if(edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
+		return;
+
 	LOOP_EDITED_POINTS {
 		LOOP_KEYS {
 			if(k) {
@@ -899,10 +902,10 @@
 	float dv1[3]= {0.0f, 0.0f, 0.0f};
 	float dv2[3]= {0.0f, 0.0f, 0.0f};
 
-	if(edit==0)
+	if(edit==0 || (pset->flag & PE_KEEP_LENGTHS)==0)
 		return;
 
-	if((pset->flag & PE_KEEP_LENGTHS)==0)
+	if(edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
 		return;
 
 	LOOP_EDITED_POINTS {
@@ -1057,11 +1060,13 @@
 		return;
 
 	LOOP_POINTS {
-		psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, psys->particles+p, hairmat);
+		if(!(psys->flag & PSYS_GLOBAL_HAIR))
+			psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, psys->particles+p, hairmat);
 
 		LOOP_KEYS {
 			VECCOPY(key->world_co,key->co);
-			Mat4MulVecfl(hairmat, key->world_co);
+			if(!(psys->flag & PSYS_GLOBAL_HAIR))
+				Mat4MulVecfl(hairmat, key->world_co);
 		}
 	}
 }
@@ -1480,7 +1485,7 @@
 	Mat4One(mat);
 
 	LOOP_VISIBLE_POINTS {
-		if(edit->psys)
+		if(edit->psys && !(psys->flag & PSYS_GLOBAL_HAIR))
 			psys_mat_hair_to_global(ob, psmd->dm, psys->part->from, psys->particles + p, mat);
 
 		if(pset->selectmode==SCE_SELECT_POINT) {
@@ -1777,7 +1782,8 @@
 	for(k=0, key=pa->hair; k<pa->totkey; k++, key++, ekey++) {
 		ekey->co= key->co;
 		ekey->time= &key->time;
-		ekey->flag |= PEK_USE_WCO;
+		if(!(psys->flag & PSYS_GLOBAL_HAIR))
+			ekey->flag |= PEK_USE_WCO;
 	}
 
 	pa->flag &= ~PARS_REKEY;
@@ -2059,7 +2065,9 @@
 
 			nekey->co= nkey->co;
 			nekey->time= &nkey->time;
-			nekey->flag |= (PEK_SELECT|PEK_USE_WCO);
+			nekey->flag |= PEK_SELECT;
+			if(!(psys->flag & PSYS_GLOBAL_HAIR))
+				nekey->flag |= PEK_USE_WCO;
 
 			nekey++;
 			nkey++;
@@ -2129,6 +2137,9 @@
 	float mat[4][4], co[3], threshold= RNA_float_get(op->ptr, "threshold");
 	int n, totn, removed, flag, totremoved;
 
+	if(psys->flag & PSYS_GLOBAL_HAIR)
+		return OPERATOR_CANCELLED;
+
 	edit= psys->edit;
 	psmd= psys_get_modifier(ob, psys);
 	totremoved= 0;
@@ -2400,6 +2411,9 @@
 	int *mirrorfaces;
 	int rotation, totpart, newtotpart;
 
+	if(psys->flag & PSYS_GLOBAL_HAIR)
+		return;
+
 	psmd= psys_get_modifier(ob, psys);
 
 	mirrorfaces= mesh_get_x_mirror_faces(ob, NULL);
@@ -2750,7 +2764,7 @@
 	float mat[4][4], imat[4][4];
 	float lastco[3], rootco[3], co[3], nor[3], kco[3], dco[3], fac, length;
 
-	if(psys) {
+	if(psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
 		psys_mat_hair_to_global(data->ob, data->dm, psys->part->from, psys->particles + point_index, mat);
 		Mat4Invert(imat,mat);
 	}
@@ -2849,6 +2863,9 @@
 	DerivedMesh *dm=0;
 	Mat4Invert(imat,ob->obmat);
 
+	if(psys->flag & PSYS_GLOBAL_HAIR)
+		return;
+
 	BLI_srandom(psys->seed+data->mval[0]+data->mval[1]);
 	
 	/* painting onto the deformed mesh, could be an option? */
@@ -3070,6 +3087,7 @@
 	float vec[3], mousef[2];
 	short mval[2], mvalo[2];
 	int flip, mouse[2], dx, dy, removed= 0, selected= 0;
+	int lock_root = pset->flag & PE_LOCK_FIRST;
 
 	if(!PE_start_edit(edit))
 		return;
@@ -3093,6 +3111,10 @@
 	mvalo[0]= bedit->lastmouse[0];
 	mvalo[1]= bedit->lastmouse[1];
 
+	/* disable locking temporatily for disconnected hair */
+	if(edit->psys && edit->psys->flag & PSYS_GLOBAL_HAIR)
+		pset->flag &= ~PE_LOCK_FIRST;
+
 	if(((pset->brushtype == PE_BRUSH_ADD) ?
 		(sqrt(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0))
 		|| bedit->first) {
@@ -3248,6 +3270,8 @@
 		bedit->lastmouse[1]= mouse[1];
 		bedit->first= 0;
 	}
+
+	pset->flag |= lock_root;
 }
 
 static void brush_edit_exit(bContext *C, wmOperator *op)
@@ -3382,6 +3406,8 @@
 
 		for(i=0; i<edit->totpoint; i++, pa++)
 			pa->hair= MEM_dupallocN(pa->hair);
+
+		undo->psys_flag = edit->psys->flag;
 	}
 	else {
 		PTCacheMem *pm;
@@ -3449,6 +3475,8 @@
 				hkey++;
 			}
 		}
+
+		psys->flag = undo->psys_flag;
 	}
 	else {
 		PTCacheMem *pm;
@@ -3704,7 +3732,8 @@
 					key->co= hkey->co;
 					key->time= &hkey->time;
 					key->flag= hkey->editflag;
-					key->flag |= PEK_USE_WCO;
+					if(!(psys->flag & PSYS_GLOBAL_HAIR))
+						key->flag |= PEK_USE_WCO;
 					hkey++;
 				}
 				pa++;
@@ -3828,6 +3857,7 @@
 			psys->free_edit = NULL;
 
 			psys->recalc |= PSYS_RECALC_RESET;
+			psys->flag &= ~PSYS_GLOBAL_HAIR;
 
 			psys_reset(psys, PSYS_RESET_DEPSGRAPH);
 			DAG_id_flush_update(&ob->id, OB_RECALC_DATA);

Modified: branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_intern.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_intern.h	2009-09-05 09:54:01 UTC (rev 23019)
+++ branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_intern.h	2009-09-05 20:12:08 UTC (rev 23020)
@@ -85,6 +85,8 @@
 void PARTICLE_OT_remove_target(struct wmOperatorType *ot);
 void PARTICLE_OT_target_move_up(struct wmOperatorType *ot);
 void PARTICLE_OT_target_move_down(struct wmOperatorType *ot);
+void PARTICLE_OT_connect_hair(struct wmOperatorType *ot);
+void PARTICLE_OT_disconnect_hair(struct wmOperatorType *ot);
 
 void SCENE_OT_render_layer_add(struct wmOperatorType *ot);
 void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);

Modified: branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_ops.c	2009-09-05 09:54:01 UTC (rev 23019)
+++ branches/blender2.5/blender/source/blender/editors/space_buttons/buttons_ops.c	2009-09-05 20:12:08 UTC (rev 23020)
@@ -35,6 +35,8 @@
 #include "DNA_group_types.h"
 #include "DNA_object_types.h"
 #include "DNA_material_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
 #include "DNA_node_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_scene_types.h"
@@ -42,8 +44,11 @@
 #include "DNA_space_types.h"
 #include "DNA_world_types.h"
 
+#include "BKE_bvhutils.h"
+#include "BKE_cdderivedmesh.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list