rna api
authorCampbell Barton <ideasman42@gmail.com>
Fri, 11 Jun 2010 10:46:47 +0000 (10:46 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 11 Jun 2010 10:46:47 +0000 (10:46 +0000)
- ParticleHairKey.location can now be set (object space location).
- Library.parent was set to ID type.

source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_particle.c

index 467eb237b9a0851b1bc9c1c4069344d893c4057b..009afec2ded669c2c0a31db36a3131c32a81510f 100644 (file)
@@ -405,7 +405,7 @@ static void rna_def_library(BlenderRNA *brna)
        /* TODO - lib->filename isnt updated, however the outliner also skips this, probably only needed on read. */
        
        prop= RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
-       RNA_def_property_struct_type(prop, "ID");
+       RNA_def_property_struct_type(prop, "Library");
        RNA_def_property_ui_text(prop, "Parent", "");   
 }
 void RNA_def_ID(BlenderRNA *brna)
index ac1f27704d814b8b7122bfbc7e20093742c91bfb..7b8d4830d5cb23f06e8ce2cff2a56ec8b79ec84b 100644 (file)
@@ -106,7 +106,8 @@ EnumPropertyItem part_hair_ren_as_items[] = {
 #include "BLI_math.h"
 #include "BLI_listbase.h"
 
-static void rna_ParticleHairKey_location_object_get(PointerRNA *ptr, float *values)
+/* use for object space hair get/set */
+static void rna_ParticleHairKey_location_object_info(PointerRNA *ptr, ParticleSystemModifierData **psmd_pt, ParticleData **pa_pt)
 {
        HairKey *hkey= (HairKey *)ptr->data;
        Object *ob = (Object *)ptr->id.data;
@@ -115,37 +116,80 @@ static void rna_ParticleHairKey_location_object_get(PointerRNA *ptr, float *valu
        ParticleSystem *psys;
        ParticleData *pa;
        int i;
-       float hairmat[4][4];
-       
+
+       *psmd_pt= NULL;
+       *pa_pt= NULL;
+
+       /* weak, what about multiple particle systems? */
        for (md = ob->modifiers.first; md; md=md->next) {
                if (md->type == eModifierType_ParticleSystem)
                        psmd= (ParticleSystemModifierData*) md;
        }
-       
-       psys = psmd->psys;
-       
-       if (!psmd || !psmd->dm || !psys) {
-               values[0] = values[1] = values[2] = 0.f;
+
+       if (!psmd || !psmd->dm || !psmd->psys) {
                return;
        }
 
-       /* not a very efficient way of getting hair key location data, 
+       psys= psmd->psys;
+
+       /* not a very efficient way of getting hair key location data,
         * but it's the best we've got at the present */
-       
+
        /* find the particle that corresponds with this HairKey */
        for(i=0, pa=psys->particles; i<psys->totpart; i++, pa++) {
-               
-               /* hairkeys are stored sequentially in memory, so we can find if 
-                * it's the same particle by comparing pointers, without having 
+
+               /* hairkeys are stored sequentially in memory, so we can find if
+                * it's the same particle by comparing pointers, without having
                 * to iterate over them all */
                if ((hkey >= pa->hair) && (hkey < pa->hair + pa->totkey))
                        break;
        }
-       
-       psys_mat_hair_to_object(ob, psmd->dm, psys->part->from, pa, hairmat);
-       
-       copy_v3_v3(values, hkey->co);
-       mul_m4_v3(hairmat, values);
+
+       *psmd_pt= psmd;
+       *pa_pt= pa;
+}
+
+static void rna_ParticleHairKey_location_object_get(PointerRNA *ptr, float *values)
+{
+       HairKey *hkey= (HairKey *)ptr->data;
+       Object *ob = (Object *)ptr->id.data;
+       ParticleSystemModifierData *psmd;
+       ParticleData *pa;
+
+       rna_ParticleHairKey_location_object_info(ptr, &psmd, &pa);
+
+       if(pa) {
+               float hairmat[4][4];
+               psys_mat_hair_to_object(ob, psmd->dm, psmd->psys->part->from, pa, hairmat);
+               copy_v3_v3(values, hkey->co);
+               mul_m4_v3(hairmat, values);
+       }
+       else {
+               zero_v3(values);
+       }
+}
+
+static void rna_ParticleHairKey_location_object_set(PointerRNA *ptr, const float *values)
+{
+       HairKey *hkey= (HairKey *)ptr->data;
+       Object *ob = (Object *)ptr->id.data;
+       ParticleSystemModifierData *psmd;
+       ParticleData *pa;
+
+       rna_ParticleHairKey_location_object_info(ptr, &psmd, &pa);
+
+       if(pa) {
+               float hairmat[4][4];
+               float imat[4][4];
+
+               psys_mat_hair_to_object(ob, psmd->dm, psmd->psys->part->from, pa, hairmat);
+               invert_m4_m4(imat, hairmat);
+               copy_v3_v3(hkey->co, values);
+               mul_m4_v3(imat, hkey->co);
+       }
+       else {
+               zero_v3(hkey->co);
+       }
 }
 
 /* property update functions */
@@ -697,12 +741,11 @@ static void rna_def_particle_hair_key(BlenderRNA *brna)
        prop= RNA_def_property(srna, "weight", PROP_FLOAT, PROP_UNSIGNED);
        RNA_def_property_range(prop, 0.0, 1.0);
        RNA_def_property_ui_text(prop, "Weight", "Weight for cloth simulation");
-       
+
        prop= RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
        RNA_def_property_array(prop, 3);
        RNA_def_property_ui_text(prop, "Location (Object Space)", "Location of the hair key in object space");
-       RNA_def_property_float_funcs(prop, "rna_ParticleHairKey_location_object_get", NULL, NULL); 
+       RNA_def_property_float_funcs(prop, "rna_ParticleHairKey_location_object_get", "rna_ParticleHairKey_location_object_set", NULL);
        
        prop= RNA_def_property(srna, "location_hairspace", PROP_FLOAT, PROP_TRANSLATION);
        RNA_def_property_float_sdna(prop, NULL, "co");