Fix bug #19699: point density texture doesn't save particle system.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 4 Nov 2009 08:44:42 +0000 (08:44 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 4 Nov 2009 08:44:42 +0000 (08:44 +0000)
Non-ID pointers in DNA can only point to data from own ID block, so
now instead it uses an index into the particle system list, but still
exposed as a pointer through RNA.

source/blender/blenkernel/intern/texture.c
source/blender/blenloader/intern/readfile.c
source/blender/makesdna/DNA_texture_types.h
source/blender/makesrna/intern/rna_texture.c
source/blender/render/intern/source/pointdensity.c

index 33dfcfca76ea63578e6781c9823068460e19c8aa..1446042399981e0101a532fa7eba97f4a71c755f 100644 (file)
@@ -1125,7 +1125,7 @@ PointDensity *BKE_add_pointdensity(void)
        pd->totpoints = 0;
        pd->coba = add_colorband(1);
        pd->object = NULL;
-       pd->psys = NULL;
+       pd->psys = 0;
        return pd;
 } 
 
index ebfa701be4ef53eccfed3bfa43686d12f118c216..00f7cbd9eebfbe99c99e4b345b294ed6f49aed10 100644 (file)
@@ -2882,10 +2882,8 @@ static void lib_link_texture(FileData *fd, Main *main)
                        tex->ima= newlibadr_us(fd, tex->id.lib, tex->ima);
                        tex->ipo= newlibadr_us(fd, tex->id.lib, tex->ipo);
                        if(tex->env) tex->env->object= newlibadr(fd, tex->id.lib, tex->env->object);
-                       if(tex->pd) {
+                       if(tex->pd)
                                tex->pd->object= newlibadr(fd, tex->id.lib, tex->pd->object);
-                               tex->pd->psys= newlibadr(fd, tex->id.lib, tex->pd->psys);
-                       }
                        if(tex->vd) tex->vd->object= newlibadr(fd, tex->id.lib, tex->vd->object);
 
                        if(tex->nodetree)
index a43e5c7ae1335ff9ee174f4db5d9a4a17691e5e6..eac7a97f0c08349cc0bc05d5d3b9f68e2fb91448 100644 (file)
@@ -159,12 +159,10 @@ typedef struct PointDensity {
        int pdpad;
 
        struct Object *object;  /* for 'Object' or 'Particle system' type - source object */
-       struct ParticleSystem *psys;
+       int psys;                               /* index+1 in ob.particlesystem, non-ID pointer not allowed */
        short psys_cache_space;         /* cache points in worldspace, object space, ... ? */
        short ob_cache_space;           /* cache points in worldspace, object space, ... ? */
        
-       short pdpad2[2];
-       
        void *point_tree;               /* the acceleration tree containing points */
        float *point_data;              /* dynamically allocated extra for extra information, like particle age */
        
index 5a18a7a987cfc4f757eafa95e70c5026342b104f..44e7d0f68d05db8ab2f3799ac75a10ff5a6a966b 100644 (file)
 #include "DNA_brush_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_material_types.h"
+#include "DNA_object_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_world_types.h"
 #include "DNA_node_types.h"
+#include "DNA_particle_types.h"
 #include "DNA_scene_types.h" /* MAXFRAME only */
 
 #include "BKE_node.h"
@@ -321,6 +323,29 @@ static EnumPropertyItem *rna_ImageTexture_filter_itemf(bContext *C, PointerRNA *
        return item;
 }
 
+static PointerRNA rna_PointDensity_psys_get(PointerRNA *ptr)
+{
+       PointDensity *pd= ptr->data;
+       Object *ob= pd->object;
+       ParticleSystem *psys= NULL;
+       PointerRNA value;
+
+       if(ob && pd->psys)
+               psys= BLI_findlink(&ob->particlesystem, pd->psys-1);
+
+       RNA_pointer_create(&ob->id, &RNA_ParticleSystem, psys, &value);
+       return value;
+}
+
+static void rna_PointDensity_psys_set(PointerRNA *ptr, PointerRNA value)
+{
+       PointDensity *pd= ptr->data;
+       Object *ob= pd->object;
+
+       if(ob && value.id.data == ob)
+               pd->psys= BLI_findindex(&ob->particlesystem, value.data) + 1;
+}
+
 static char *rna_ColorRamp_path(PointerRNA *ptr)
 {
        /* handle the cases where a single datablock may have 2 ramp types */
@@ -1552,9 +1577,9 @@ static void rna_def_texture_pointdensity(BlenderRNA *brna)
        RNA_def_property_update(prop, 0, "rna_Texture_update");
        
        prop= RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
-       RNA_def_property_pointer_sdna(prop, NULL, "psys");
        RNA_def_property_ui_text(prop, "Particle System", "Particle System to render as points");
        RNA_def_property_struct_type(prop, "ParticleSystem");
+       RNA_def_property_pointer_funcs(prop, "rna_PointDensity_psys_get", "rna_PointDensity_psys_set", NULL);
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_update(prop, 0, "rna_Texture_update");
        
index c1cca4e217a7949ee44da05cc7107607d573128f..2b3e6047af402ec308ad244aa8b0ccefb3587143 100644 (file)
@@ -236,11 +236,14 @@ static void cache_pointdensity(Render *re, Tex *tex)
        
        if (pd->source == TEX_PD_PSYS) {
                Object *ob = pd->object;
+               ParticleSystem *psys;
 
-               if (!ob) return;
-               if (!pd->psys) return;
+               if (!ob || !pd->psys) return;
+
+               psys= BLI_findlink(&ob->particlesystem, pd->psys-1);
+               if (!psys) return;
                
-               pointdensity_cache_psys(re, pd, ob, pd->psys);
+               pointdensity_cache_psys(re, pd, ob, psys);
        }
        else if (pd->source == TEX_PD_OBJECT) {
                Object *ob = pd->object;