Some more fixes for particle textures:
authorJanne Karhu <jhkarh@gmail.com>
Sun, 13 Feb 2011 12:35:26 +0000 (12:35 +0000)
committerJanne Karhu <jhkarh@gmail.com>
Sun, 13 Feb 2011 12:35:26 +0000 (12:35 +0000)
* Moving a texture slot didn't keep the moved slot active.
* Copy & paste for particle textures didn't work.
* New textures weren't freed properly.

source/blender/blenkernel/intern/particle.c
source/blender/blenkernel/intern/texture.c
source/blender/editors/render/render_shading.c

index 3204a1c38e742b9837199ce96f992f91d52beac9..d1d5c13c3dd943bacad23c2b72808ced17e01ebf 100644 (file)
@@ -366,6 +366,8 @@ static void fluid_free_settings(SPHFluidSettings *fluid)
 
 void psys_free_settings(ParticleSettings *part)
 {
+       MTex *mtex;
+       int a;
        BKE_free_animdata(&part->id);
        free_partdeflect(part->pd);
        free_partdeflect(part->pd2);
@@ -377,6 +379,12 @@ void psys_free_settings(ParticleSettings *part)
 
        boid_free_settings(part->boids);
        fluid_free_settings(part->fluid);
+
+       for(a=0; a<MAX_MTEX; a++) {
+               mtex= part->mtex[a];
+               if(mtex && mtex->tex) mtex->tex->id.us--;
+               if(mtex) MEM_freeN(mtex);
+       }
 }
 
 void free_hair(Object *UNUSED(ob), ParticleSystem *psys, int dynamics)
index cf4fcbb4def54e206f70afd28e6b74f032541576..c22b1d32849d88464ef12ffa3ad42cff4f20e380 100644 (file)
@@ -779,6 +779,7 @@ void make_local_texture(Tex *tex)
        World *wrld;
        Lamp *la;
        Brush *br;
+       ParticleSettings *pa;
        int a, local=0, lib=0;
 
        /* - only lib users: do nothing
@@ -841,6 +842,16 @@ void make_local_texture(Tex *tex)
                }
                br= br->id.next;
        }
+       pa= bmain->particle.first;
+       while(pa) {
+               for(a=0; a<MAX_MTEX; a++) {
+                       if(pa->mtex[a] && pa->mtex[a]->tex==tex) {
+                               if(pa->id.lib) lib= 1;
+                               else local= 1;
+                       }
+               }
+               pa= pa->id.next;
+       }
        
        if(local && lib==0) {
                tex->id.lib= NULL;
@@ -901,6 +912,19 @@ void make_local_texture(Tex *tex)
                        }
                        br= br->id.next;
                }
+               pa= bmain->particle.first;
+               while(pa) {
+                       for(a=0; a<MAX_MTEX; a++) {
+                               if(pa->mtex[a] && pa->mtex[a]->tex==tex) {
+                                       if(pa->id.lib==NULL) {
+                                               pa->mtex[a]->tex= texn;
+                                               texn->id.us++;
+                                               tex->id.us--;
+                                       }
+                               }
+                       }
+                       pa= pa->id.next;
+               }
        }
 }
 
@@ -1079,6 +1103,9 @@ void set_active_mtex(ID *id, short act)
        case ID_LA:
                ((Lamp *)id)->texact= act;
                break;
+       case ID_PA:
+               ((ParticleSettings *)id)->texact= act;
+               break;
        }
 }
 
index df32a0619e35c05417ce478c465adbe8bc1ff97e..cb4c727c213099ccce8d1a5aab939f261c86b5f8 100644 (file)
@@ -34,6 +34,7 @@
 #include "DNA_material_types.h"
 #include "DNA_node_types.h"
 #include "DNA_object_types.h"
+#include "DNA_particle_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_space_types.h"
 #include "DNA_world_types.h"
@@ -1110,6 +1111,9 @@ void copy_mtex_copybuf(ID *id)
                        mtex= &(((World *)id)->mtex[(int)((World *)id)->texact]);
                        // mtex= wrld->mtex[(int)wrld->texact]; // TODO
                        break;
+               case ID_PA:
+                       mtex= &(((ParticleSettings *)id)->mtex[(int)((ParticleSettings *)id)->texact]);
+                       break;
        }
        
        if(mtex && *mtex) {
@@ -1140,6 +1144,9 @@ void paste_mtex_copybuf(ID *id)
                        mtex= &(((World *)id)->mtex[(int)((World *)id)->texact]);
                        // mtex= wrld->mtex[(int)wrld->texact]; // TODO
                        break;
+               case ID_PA:
+                       mtex= &(((ParticleSettings *)id)->mtex[(int)((ParticleSettings *)id)->texact]);
+                       break;
        }
        
        if(mtex) {
@@ -1204,6 +1211,7 @@ static int paste_mtex_exec(bContext *C, wmOperator *UNUSED(op))
                Material *ma= CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
                Lamp *la= CTX_data_pointer_get_type(C, "lamp", &RNA_Lamp).data;
                World *wo= CTX_data_pointer_get_type(C, "world", &RNA_World).data;
+               ParticleSystem *psys= CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data;
                
                if (ma)
                        id = &ma->id;
@@ -1211,6 +1219,8 @@ static int paste_mtex_exec(bContext *C, wmOperator *UNUSED(op))
                        id = &la->id;
                else if (wo)
                        id = &wo->id;
+               else if (psys)
+                       id = &psys->part->id;
                
                if (id==NULL)
                        return OPERATOR_CANCELLED;