[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31721] trunk/blender/source/blender: "Fix " for [#23621] lattice modifier on particle hair when applied doesn' t apply it to the hair

Janne Karhu jhkarh at gmail.com
Thu Sep 2 10:06:53 CEST 2010


Revision: 31721
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31721
Author:   jhk
Date:     2010-09-02 10:06:53 +0200 (Thu, 02 Sep 2010)

Log Message:
-----------
"Fix" for [#23621] lattice modifier on particle hair when applied doesn't apply it to the hair
* Although not strictly a bug it is the expected behavior and won't mess anything else up.
* Note: the lattice is applied to the actual hair keys instead of the calculated strands so the applied result will differ a bit from the original.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/BKE_particle.h
    trunk/blender/source/blender/blenkernel/intern/particle.c
    trunk/blender/source/blender/editors/object/object_modifier.c
    trunk/blender/source/blender/editors/physics/particle_edit.c

Modified: trunk/blender/source/blender/blenkernel/BKE_particle.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_particle.h	2010-09-02 07:24:38 UTC (rev 31720)
+++ trunk/blender/source/blender/blenkernel/BKE_particle.h	2010-09-02 08:06:53 UTC (rev 31721)
@@ -253,6 +253,7 @@
 void psys_threads_free(ParticleThread *threads);
 
 void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]);
+void psys_apply_hair_lattice(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
 
 /* particle_system.c */
 struct ParticleSystem *psys_get_target_system(struct Object *ob, struct ParticleTarget *pt);

Modified: trunk/blender/source/blender/blenkernel/intern/particle.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/particle.c	2010-09-02 07:24:38 UTC (rev 31720)
+++ trunk/blender/source/blender/blenkernel/intern/particle.c	2010-09-02 08:06:53 UTC (rev 31721)
@@ -4431,3 +4431,34 @@
 	VECADDFAC(center, center, yvec, bb->offset[1]);
 }
 
+
+void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys) {
+	ParticleSimulationData sim = {scene, ob, psys, psys_get_modifier(ob, psys)};
+
+	psys->lattice = psys_get_lattice(&sim);
+
+	if(psys->lattice) {
+		ParticleData *pa = psys->particles;
+		HairKey *hkey;
+		int p, h;
+		float hairmat[4][4], imat[4][4];
+
+		for(p=0; p<psys->totpart; p++, pa++) {
+			psys_mat_hair_to_global(sim.ob, sim.psmd->dm, psys->part->from, pa, hairmat);
+			invert_m4_m4(imat, hairmat);
+
+			hkey = pa->hair;
+			for(h=0; h<pa->totkey; h++, hkey++) {
+				mul_m4_v3(hairmat, hkey->co);
+				calc_latt_deform(psys->lattice, hkey->co, 1.0f);
+				mul_m4_v3(imat, hkey->co);
+			}
+		}
+		
+		end_latt_deform(psys->lattice);
+		psys->lattice= NULL;
+
+		/* protect the applied shape */
+		psys->flag |= PSYS_EDITED;
+	}
+}
\ No newline at end of file

Modified: trunk/blender/source/blender/editors/object/object_modifier.c
===================================================================
--- trunk/blender/source/blender/editors/object/object_modifier.c	2010-09-02 07:24:38 UTC (rev 31720)
+++ trunk/blender/source/blender/editors/object/object_modifier.c	2010-09-02 08:06:53 UTC (rev 31721)
@@ -453,6 +453,21 @@
 		BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
 		return 0;
 	}
+
+	/* lattice modifier can be applied to particle system too */
+	if(ob->particlesystem.first) {
+
+		ParticleSystem *psys = ob->particlesystem.first;
+
+		for(; psys; psys=psys->next) {
+			
+			if(psys->part->type != PART_HAIR)
+				continue;
+
+			psys_apply_hair_lattice(scene, ob, psys);
+		}
+	}
+
 	return 1;
 }
 

Modified: trunk/blender/source/blender/editors/physics/particle_edit.c
===================================================================
--- trunk/blender/source/blender/editors/physics/particle_edit.c	2010-09-02 07:24:38 UTC (rev 31720)
+++ trunk/blender/source/blender/editors/physics/particle_edit.c	2010-09-02 08:06:53 UTC (rev 31721)
@@ -4151,6 +4151,13 @@
 			DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
 		}
 	}
+	else { /* some operation might have protected hair from editing so let's clear the flag */
+		psys->recalc |= PSYS_RECALC_RESET;
+		psys->flag &= ~PSYS_GLOBAL_HAIR;
+		psys->flag &= ~PSYS_EDITED;
+		WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
+		DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+	}
 
 	return OPERATOR_FINISHED;
 }





More information about the Bf-blender-cvs mailing list