Revision: 23738
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23738
Author:   blendix
Date:     2009-10-09 15:25:54 +0200 (Fri, 09 Oct 2009)

Log Message:
-----------
Particle Edit Mode:
* Fix crash trying to enter particle mode when the particle modifier
  is disabled in the stack.
* Fix redraw being very slow due to the draw function causing the
  object to be recalculated on each redraw (through PE_draw_object).

* Removed the system where PE_get_current would automatically create
  the particle edit, this would run from poll() functions, which gave
  all kinds of issues, now it only creates the data on enter/exit
  and switching active particle system.

Modified Paths:
--------------
    trunk/blender/source/blender/blenloader/intern/readfile.c
    trunk/blender/source/blender/editors/include/ED_particle.h
    trunk/blender/source/blender/editors/physics/particle_edit.c
    trunk/blender/source/blender/makesrna/intern/rna_object.c

Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c   2009-10-09 
12:48:28 UTC (rev 23737)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c   2009-10-09 
13:25:54 UTC (rev 23738)
@@ -3918,7 +3918,7 @@
        ob->flag &= ~OB_FROMGROUP;
        
        /* editmode doesn't get saved in files, so should get cleared when 
reloading... */
-       ob->mode &= ~OB_MODE_EDIT;
+       ob->mode &= ~(OB_MODE_EDIT|OB_MODE_PARTICLE_EDIT);
        
        ob->disp.first=ob->disp.last= NULL;
        

Modified: trunk/blender/source/blender/editors/include/ED_particle.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_particle.h  2009-10-09 
12:48:28 UTC (rev 23737)
+++ trunk/blender/source/blender/editors/include/ED_particle.h  2009-10-09 
13:25:54 UTC (rev 23738)
@@ -46,6 +46,8 @@
 
 /* access */
 struct PTCacheEdit *PE_get_current(struct Scene *scene, struct Object *ob);
+struct PTCacheEdit *PE_create_current(struct Scene *scene, struct Object *ob);
+void PE_current_changed(struct Scene *scene, struct Object *ob);
 int PE_minmax(struct Scene *scene, float *min, float *max);
 struct ParticleEditSettings *PE_settings(struct Scene *scene);
 

Modified: trunk/blender/source/blender/editors/physics/particle_edit.c
===================================================================
--- trunk/blender/source/blender/editors/physics/particle_edit.c        
2009-10-09 12:48:28 UTC (rev 23737)
+++ trunk/blender/source/blender/editors/physics/particle_edit.c        
2009-10-09 13:25:54 UTC (rev 23738)
@@ -194,7 +194,7 @@
 }
 
 /* always gets atleast the first particlesystem even if PSYS_CURRENT flag is 
not set */
-PTCacheEdit *PE_get_current(Scene *scene, Object *ob)
+static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create)
 {
        ParticleEditSettings *pset= PE_settings(scene);
        PTCacheEdit *edit = NULL;
@@ -232,18 +232,18 @@
                        if(psys->flag & PSYS_CURRENT) {
                                if(psys->part && psys->part->type == PART_HAIR) 
{
                                        if(psys->flag & PSYS_HAIR_DYNAMICS && 
psys->pointcache->flag & PTCACHE_BAKED) {
-                                               if(!psys->pointcache->edit)
+                                               if(create && 
!psys->pointcache->edit)
                                                        
PE_create_particle_edit(scene, ob, pid->cache, NULL);
                                                edit = pid->cache->edit;
                                        }
                                        else {
-                                               if(!psys->edit && psys->flag & 
PSYS_HAIR_DONE)
+                                               if(create && !psys->edit && 
psys->flag & PSYS_HAIR_DONE)
                                                        
PE_create_particle_edit(scene, ob, NULL, psys);
                                                edit = psys->edit;
                                        }
                                }
                                else {
-                                       if(pid->cache->flag & PTCACHE_BAKED && 
!pid->cache->edit)
+                                       if(create && pid->cache->flag & 
PTCACHE_BAKED && !pid->cache->edit)
                                                PE_create_particle_edit(scene, 
ob, pid->cache, psys);
                                        edit = pid->cache->edit;
                                }
@@ -252,13 +252,13 @@
                        }
                }
                else if(pset->edittype == PE_TYPE_SOFTBODY && pid->type == 
PTCACHE_TYPE_SOFTBODY) {
-                       if(pid->cache->flag & PTCACHE_BAKED && 
!pid->cache->edit)
+                       if(create && pid->cache->flag & PTCACHE_BAKED && 
!pid->cache->edit)
                                PE_create_particle_edit(scene, ob, pid->cache, 
NULL);
                        edit = pid->cache->edit;
                        break;
                }
                else if(pset->edittype == PE_TYPE_CLOTH && pid->type == 
PTCACHE_TYPE_CLOTH) {
-                       if(pid->cache->flag & PTCACHE_BAKED && 
!pid->cache->edit)
+                       if(create && pid->cache->flag & PTCACHE_BAKED && 
!pid->cache->edit)
                                PE_create_particle_edit(scene, ob, pid->cache, 
NULL);
                        edit = pid->cache->edit;
                        break;
@@ -273,6 +273,22 @@
        return edit;
 }
 
+PTCacheEdit *PE_get_current(Scene *scene, Object *ob)
+{
+       return pe_get_current(scene, ob, 0);
+}
+
+PTCacheEdit *PE_create_current(Scene *scene, Object *ob)
+{
+       return pe_get_current(scene, ob, 1);
+}
+
+void PE_current_changed(Scene *scene, Object *ob)
+{
+       if(ob->mode == OB_MODE_PARTICLE_EDIT)
+               PE_create_current(scene, ob);
+}
+
 void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra)
 {
        ParticleEditSettings *pset=PE_settings(scene);
@@ -1195,8 +1211,6 @@
 
        if(edit->psys)
                edit->psys->flag &= ~PSYS_HAIR_UPDATED;
-
-       DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
 }
 
 /************************************************/
@@ -2409,7 +2423,6 @@
        }
 
        PE_update_object(data.scene, data.ob, 0);
-
        DAG_id_flush_update(&data.ob->id, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE_DATA, data.ob);
 
@@ -3734,13 +3747,15 @@
 /* initialize needed data for bake edit */
 static void PE_create_particle_edit(Scene *scene, Object *ob, PointCache 
*cache, ParticleSystem *psys)
 {
-       PTCacheEdit *edit= psys ? psys->edit : cache->edit;
+       PTCacheEdit *edit= (psys)? psys->edit : cache->edit;
+       ParticleSystemModifierData *psmd= (psys)? psys_get_modifier(ob, psys): 
NULL;
        POINT_P; KEY_K;
        ParticleData *pa = NULL;
        HairKey *hkey;
        int totpoint;
 
-       if(!psys && !cache)
+       /* no psmd->dm happens in case particle system modifier is not enabled 
*/
+       if(!(psys && psmd && psmd->dm) && !cache)
                return;
 
        if(cache && cache->flag & PTCACHE_DISK_CACHE)
@@ -3850,10 +3865,12 @@
 
 static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
 {
+       Scene *scene= CTX_data_scene(C);
        Object *ob= CTX_data_active_object(C);
 
        if(!(ob->mode & OB_MODE_PARTICLE_EDIT)) {
                ob->mode |= OB_MODE_PARTICLE_EDIT;
+               PE_create_current(scene, ob);
                toggle_particle_cursor(C, 1);
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_PARTICLE, 
NULL);
        }

Modified: trunk/blender/source/blender/makesrna/intern/rna_object.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_object.c   2009-10-09 
12:48:28 UTC (rev 23737)
+++ trunk/blender/source/blender/makesrna/intern/rna_object.c   2009-10-09 
13:25:54 UTC (rev 23738)
@@ -102,6 +102,7 @@
 #include "BLI_editVert.h" /* for EditMesh->mat_nr */
 
 #include "ED_object.h"
+#include "ED_particle.h"
 
 void rna_Object_update(bContext *C, PointerRNA *ptr)
 {
@@ -460,12 +461,20 @@
        return psys_get_current_num(ob);
 }
 
-static void rna_Object_active_particle_system_index_set(struct PointerRNA 
*ptr, int value)
+static void rna_Object_active_particle_system_index_set(PointerRNA *ptr, int 
value)
 {
        Object *ob= (Object*)ptr->id.data;
        psys_set_current_num(ob, value);
 }
 
+static void rna_Object_particle_update(bContext *C, PointerRNA *ptr)
+{
+       Scene *scene= CTX_data_scene(C);
+       Object *ob= (Object*)ptr->id.data;
+
+       PE_current_changed(scene, ob);
+}
+
 /* rotation - axis-angle */
 static void rna_Object_rotation_axis_angle_get(PointerRNA *ptr, float *value)
 {
@@ -1418,7 +1427,7 @@
        prop= RNA_def_property(srna, "active_particle_system_index", PROP_INT, 
PROP_UNSIGNED);
        RNA_def_property_int_funcs(prop, 
"rna_Object_active_particle_system_index_get", 
"rna_Object_active_particle_system_index_set", 
"rna_Object_active_particle_system_index_range");
        RNA_def_property_ui_text(prop, "Active Particle System Index", "Index 
of active particle system slot.");
-       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
+       RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, 
"rna_Object_particle_update");
 
        /* restrict */
        prop= RNA_def_property(srna, "restrict_view", PROP_BOOLEAN, PROP_NONE);


_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to