[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11268] branches/particles/source/blender: *bugs fixed:

Janne Karhu jhkarh at utu.fi
Fri Jul 13 20:06:18 CEST 2007


Revision: 11268
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11268
Author:   jhk
Date:     2007-07-13 20:06:17 +0200 (Fri, 13 Jul 2007)

Log Message:
-----------
*bugs fixed:
	-a memory leak that happened when particle emitter was set as a deflector also
	-particles emitted from a deflector sometimes collided with it straight from birth
	-preview render crashed with "only render children"
*new things:
	-all render parameters from modifiers before a particle system are ignored (not a real solution to the "emitter structure changed -> particle emit indexes wrong", but a small improvement)
	-emitter positions are determined exactly at particle birth (much better for fast moving emitters)
	-selectable integration method for newtonian physics (euler, midpoint, RK4)
	-effector field movement & ipo timing is more precisely taken into account
	-particle mode has option to clip editing with the zbuffer (same toggle button as edit mode and same effect: not combing/selecting editing through the emitter)

Modified Paths:
--------------
    branches/particles/source/blender/blenkernel/BKE_particle.h
    branches/particles/source/blender/blenkernel/intern/DerivedMesh.c
    branches/particles/source/blender/blenkernel/intern/modifier.c
    branches/particles/source/blender/blenkernel/intern/particle.c
    branches/particles/source/blender/blenkernel/intern/particle_edit.c
    branches/particles/source/blender/blenkernel/intern/particle_system.c
    branches/particles/source/blender/makesdna/DNA_curve_types.h
    branches/particles/source/blender/makesdna/DNA_particle_types.h
    branches/particles/source/blender/render/intern/source/convertblender.c
    branches/particles/source/blender/src/buttons_editing.c
    branches/particles/source/blender/src/buttons_object.c
    branches/particles/source/blender/src/drawobject.c
    branches/particles/source/blender/src/header_view3d.c
    branches/particles/source/blender/src/view.c

Modified: branches/particles/source/blender/blenkernel/BKE_particle.h
===================================================================
--- branches/particles/source/blender/blenkernel/BKE_particle.h	2007-07-13 16:37:27 UTC (rev 11267)
+++ branches/particles/source/blender/blenkernel/BKE_particle.h	2007-07-13 18:06:17 UTC (rev 11268)
@@ -118,6 +118,7 @@
 struct ParticleKey *psys_get_selected_key(struct ParticleSystem *psys, int pa_index, int *key_index);
 void psys_change_act(void *ob_v, void *old_act);
 struct Object *psys_get_lattice(struct ParticleSystemModifierData *psmd);
+int psys_is_after_modifier(struct ModifierData *tmd);
 
 void psys_free_settings(struct ParticleSettings *part);
 void psys_free_bake(struct ParticleSystem *psys);

Modified: branches/particles/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/DerivedMesh.c	2007-07-13 16:37:27 UTC (rev 11267)
+++ branches/particles/source/blender/blenkernel/intern/DerivedMesh.c	2007-07-13 18:06:17 UTC (rev 11268)
@@ -1814,7 +1814,8 @@
 			/* set the DerivedMesh to only copy needed data */
 			DM_set_only_copy(dm, (CustomDataMask)curr->link);
 
-			ndm = mti->applyModifier(md, ob, dm, useRenderParams,
+			ndm = mti->applyModifier(md, ob, dm,
+									 psys_is_after_modifier(md)?0:useRenderParams,
 			                         !inputVertexCos);
 
 			if(ndm) {

Modified: branches/particles/source/blender/blenkernel/intern/modifier.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/modifier.c	2007-07-13 16:37:27 UTC (rev 11267)
+++ branches/particles/source/blender/blenkernel/intern/modifier.c	2007-07-13 18:06:17 UTC (rev 11268)
@@ -4955,13 +4955,21 @@
 	ParticleSystemModifierData *psmd= (ParticleSystemModifierData*) md;
 	ParticleSystem * psys=0;
 	int totvert=0,totedge=0,totface=0,needsFree=0;
+	
+	if(ob->particleSystem)
+		psys=psmd->psys;
+	else
+		return;
+	
+	if(psys->flag & PSYS_NO_STEP || (psys->flag&PSYS_ENABLED)==0)
+		return;
 
 	if(dm==0){
 		if(ob->type==OB_MESH){
 			dm = CDDM_from_mesh((Mesh*)(ob->data), ob);
 
 			CDDM_apply_vert_coords(dm, vertexCos);
-			CDDM_calc_normals(dm);
+			//CDDM_calc_normals(dm);
 
 			needsFree=1;
 		}
@@ -4982,7 +4990,7 @@
 				nurbs_to_mesh( tmpobj );
 
 				dm = CDDM_from_mesh((Mesh*)(tmpobj->data), tmpobj);
-				CDDM_calc_normals(dm);
+				//CDDM_calc_normals(dm);
 
 				free_libblock_us( &G.main->object, tmpobj );
 
@@ -4993,9 +5001,6 @@
 		else return;
 	}
 
-	if(ob->particleSystem)
-		psys=psmd->psys;
-
 	/* clear old dm */
 	if(psmd->dm){
 		totvert=psmd->dm->getNumVerts(psmd->dm);
@@ -5007,6 +5012,7 @@
 
 	/* make new dm */
 	psmd->dm=CDDM_copy(dm);
+	CDDM_calc_normals(psmd->dm);
 
 	if(needsFree){
 		dm->needsFree = 1;
@@ -5029,7 +5035,7 @@
 		}
 	}
 
-	if(psys && (psys->flag & PSYS_NO_STEP)==0){
+	if(psys){
 		particle_system_update(ob,psys);
 		psmd->flag &= ~eParticleSystemFlag_DM_changed;
 	}

Modified: branches/particles/source/blender/blenkernel/intern/particle.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle.c	2007-07-13 16:37:27 UTC (rev 11267)
+++ branches/particles/source/blender/blenkernel/intern/particle.c	2007-07-13 18:06:17 UTC (rev 11268)
@@ -192,6 +192,18 @@
 	}
 	return 0;
 }
+int psys_is_after_modifier(ModifierData *tmd)
+{
+	ModifierData *md=tmd;
+
+	if(md){
+		for(md=md->next; md; md=md->next){
+			if(md->type==eModifierType_ParticleSystem) return 1;
+		}
+	}
+
+	return 0;
+}
 /************************************************/
 /*			Freeing stuff						*/
 /************************************************/
@@ -658,8 +670,8 @@
 	Normalize(n3);
 
 	if(mface->v4 && uv[2]<0.0f){
-		u=(u-0.5f)*(-1.0-uv[2])+0.5f;
-		v=(v-0.5f)*(-1.0-uv[2])+0.5f;
+		u=(u-0.5f)*(-1.0f-uv[2])+0.5f;
+		v=(v-0.5f)*(-1.0f-uv[2])+0.5f;
 	}
 	
 	if(mface->v4) {
@@ -697,8 +709,8 @@
 		}
 
 		if(uv[2]<0.0f){
-			u=(u-0.5f)*(-1.0-uv[2])+0.5f + 0.16667f*(-2.0-uv[2]);
-			v=(v-0.5f)*(-1.0-uv[2])+0.5f + 0.16667f*(-2.0-uv[2]);
+			u=(u-0.5f)*(-1.0f-uv[2])+0.5f + 0.16667f*(-2.0f-uv[2]);
+			v=(v-0.5f)*(-1.0f-uv[2])+0.5f + 0.16667f*(-2.0f-uv[2]);
 		}
 
 		vec[0]= v1[0] + u*(v3[0]-v1[0]) + v*(v2[0]-v1[0]);
@@ -896,8 +908,7 @@
 {
 	ModifierData *md;
 	ParticleSystemModifierData *psmd;
-	int i;
-	for(i=0,md=ob->modifiers.first; md; i++,md=md->next){
+	for(md=ob->modifiers.first; md; md=md->next){
 		if(md->type==eModifierType_ParticleSystem){
 			psmd= (ParticleSystemModifierData*) md;
 			if(psmd->psys==psys){
@@ -1389,7 +1400,7 @@
 	ParticleSettings *part=psys->part;
 	ParticleData *pa;
 	ChildParticle *cpa;
-	ParticleKey *state, **cache=psys->pathcache, state1, state2, *par;
+	ParticleKey *state, **cache=psys->pathcache, state1, state2, *par=0;
 	ParticleKey *key[4], **keys=psys->keys;
 	ParticleKey k1,k2,k3,k4;
 	ParticleTexture ptex;

Modified: branches/particles/source/blender/blenkernel/intern/particle_edit.c
===================================================================
--- branches/particles/source/blender/blenkernel/intern/particle_edit.c	2007-07-13 16:37:27 UTC (rev 11267)
+++ branches/particles/source/blender/blenkernel/intern/particle_edit.c	2007-07-13 18:06:17 UTC (rev 11268)
@@ -43,6 +43,7 @@
 #include "BSE_view.h"
 
 #include "BDR_editobject.h" //rightmouse_transform()
+#include "BDR_drawobject.h"
 
 #include "blendef.h"
 #include "mydevice.h"
@@ -113,12 +114,46 @@
 	else
 		return 0;
 }
+static int test_key_depth(float *co, bglMats *mats){
+	double ux, uy, uz;
+	float depth;
+	short wco[3], x,y;
+
+	if((G.vd->flag & V3D_ZBUF_SELECT)==0) return 1;
+
+	gluProject(co[0],co[1],co[2], mats->modelview, mats->projection,
+				(GLint *)mats->viewport, &ux, &uy, &uz );
+
+	project_short_noclip(co,wco);
+
+	x=wco[0];
+	y=wco[1];
+
+	if(G.vd->depths && x<G.vd->depths->w && y<G.vd->depths->h){
+		if((float)uz>G.vd->depths->depths[y*G.vd->depths->w+x])
+			return 0;
+		else
+			return 1;
+	}
+	else{
+		x+= (short)curarea->winrct.xmin;
+		y+= (short)curarea->winrct.ymin;
+		
+		glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
+
+		if((float)uz>depth)
+			return 0;
+		else
+			return 1;
+	}
+}
 /*-----iterators over editable particles-----*/
 static void for_mouse_hit_particle_keys(int nearest, ParticleSystem *psys, void (*func)(ParticleSystem *psys, int pa_index, int key_index, void *userData), void *userData){
 			/* these are allways the first in this userData */
 	struct { short *mval; float rad; rcti *rect;} *data = userData;
 	ParticleData *pa;
 	ParticleKey *key;
+	bglMats mats;
 	int p,k, totpart, nearest_p=-1, nearest_k=-1;
 	float dist=data->rad;
 	float *co;
@@ -127,34 +162,37 @@
 	
 	totpart=psys->totpart;
 
+	bgl_get_mats(&mats);
+
 	for(p=0, pa=psys->particles; p<totpart; p++,pa++){
 		if(pa->flag & PARS_HIDE) continue;
 
 		if(G.scene->selectmode==SCE_SELECT_END){
 			co=psys->edit_path->world_cos[p]+3*(pa->totkey-1);
+
 			key=psys->keys[p]+pa->totkey-1;
 			if(nearest){
-				if(particle_inside_circle(data->mval,dist,co,&dist)){
+				if(particle_inside_circle(data->mval,dist,co,&dist) && test_key_depth(co,&mats)){
 					nearest_p=p;
 					nearest_k=pa->totkey-1;
 				}
 			}
 			else if(((data->mval)?
 				particle_inside_circle(data->mval,data->rad,co,0):
-				particle_inside_rect(data->rect,co)))
+				particle_inside_rect(data->rect,co)) && test_key_depth(co,&mats))
 				func(psys,p,pa->totkey-1,userData);
 		}
 		else{
 			for(k=0,key=psys->keys[p],co=psys->edit_path->world_cos[p]; k<pa->totkey; k++,key++,co+=3){
 				if(nearest){
-					if(particle_inside_circle(data->mval,dist,co,&dist)){
+					if(particle_inside_circle(data->mval,dist,co,&dist) && test_key_depth(co,&mats)){
 						nearest_p=p;
 						nearest_k=k;
 					}
 				}
 				else if(((data->mval)?
 					particle_inside_circle(data->mval,data->rad,co,0):
-					particle_inside_rect(data->rect,co)))
+					particle_inside_rect(data->rect,co)) && test_key_depth(co,&mats))
 					func(psys,p,k,userData);
 			}
 		}
@@ -168,6 +206,7 @@
 	struct { short *mval; float rad; rcti* rect;} *data = userData;
 	ParticleData *pa;
 	ParticleKey *key;
+	bglMats mats;
 	int p,k, totpart;
 	float *co;
 
@@ -175,6 +214,8 @@
 	
 	totpart=psys->totpart;
 
+	bgl_get_mats(&mats);
+
 	if(G.scene->selectmode==SCE_SELECT_PATH)
 		selected=0;
 
@@ -184,12 +225,12 @@
 		if(G.scene->selectmode==SCE_SELECT_END){
 			co=psys->edit_path->world_cos[p]+3*(pa->totkey-1);
 			key=psys->keys[p]+pa->totkey-1;
-			if(particle_inside_circle(data->mval,data->rad,co,0) && (selected==0 || key->flag&PSYS_KEY_SELECT))
+			if(particle_inside_circle(data->mval,data->rad,co,0) && (selected==0 || key->flag&PSYS_KEY_SELECT) && test_key_depth(co,&mats))
 				func(psys,p,userData);
 		}
 		else{
 			for(k=0,key=psys->keys[p],co=psys->edit_path->world_cos[p]; k<pa->totkey; k++,key++,co+=3){
-				if(particle_inside_circle(data->mval,data->rad,co,0) && (selected==0 || key->flag&PSYS_KEY_SELECT)){
+				if(particle_inside_circle(data->mval,data->rad,co,0) && (selected==0 || key->flag&PSYS_KEY_SELECT) && test_key_depth(co,&mats)){
 					func(psys,p,userData);
 					break;
 				}
@@ -203,6 +244,7 @@
 	ParticleData *pa;
 	ParticleKey *key;
 	ParticleSystemModifierData *psmd=psys_get_modifier(ob,psys);
+	bglMats mats;
 	int p,k, totpart;
 	float mat[4][4], imat[4][4], *co;
 
@@ -210,6 +252,8 @@
 	
 	totpart=psys->totpart;
 
+	bgl_get_mats(&mats);
+
 	if(G.scene->selectmode==SCE_SELECT_PATH)
 		selected=0;
 
@@ -237,12 +281,12 @@
 		if(G.scene->selectmode==SCE_SELECT_END){
 			co=psys->edit_path->world_cos[p]+3*(pa->totkey-1);
 			key=psys->keys[p]+pa->totkey-1;
-			if(particle_inside_circle(data->mval,data->rad,co,&data->dist) && (selected==0 || key->flag&PSYS_KEY_SELECT))
+			if(particle_inside_circle(data->mval,data->rad,co,&data->dist) && (selected==0 || key->flag&PSYS_KEY_SELECT) && test_key_depth(co,&mats))
 				func(psys,mat,imat,p,pa->totkey-1,userData);
 		}
 		else{
 			for(k=0,key=psys->keys[p],co=psys->edit_path->world_cos[p]; k<pa->totkey; k++,key++,co+=3){
-				if(particle_inside_circle(data->mval,data->rad,co,&data->dist) && (selected==0 || key->flag&PSYS_KEY_SELECT)){
+				if(particle_inside_circle(data->mval,data->rad,co,&data->dist) && (selected==0 || key->flag&PSYS_KEY_SELECT) && test_key_depth(co,&mats)){
 					func(psys,mat,imat,p,k,userData);
 				}
 			}
@@ -1024,6 +1068,11 @@
 
 	totpart=psys->totpart;
 
+	bglFlush();

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list