Fix T46333: Particle Info Node broken w/ BI
authorCampbell Barton <ideasman42@gmail.com>
Mon, 5 Oct 2015 12:23:05 +0000 (23:23 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 5 Oct 2015 12:26:57 +0000 (23:26 +1100)
Patch from @a.romanov

This also fixes multiple particle systems - which never worked.

source/blender/render/intern/include/renderdatabase.h
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/renderdatabase.c

index da45a2bfead1ed5a5538f6606a0c17b9d94ae8db..224974454e82d352e28d5396171da51845326de4 100644 (file)
@@ -115,7 +115,9 @@ struct HaloRen *RE_inithalo_particle(struct Render *re, struct ObjectRen *obr, s
 struct StrandBuffer *RE_addStrandBuffer(struct ObjectRen *obr, int totvert);
 
 struct ObjectRen *RE_addRenderObject(struct Render *re, struct Object *ob, struct Object *par, int index, int psysindex, int lay);
-struct ObjectInstanceRen *RE_addRenderInstance(struct Render *re, struct ObjectRen *obr, struct Object *ob, struct Object *par, int index, int psysindex, float mat[4][4], int lay);
+struct ObjectInstanceRen *RE_addRenderInstance(
+        struct Render *re, struct ObjectRen *obr, struct Object *ob, struct Object *par,
+        int index, int psysindex, float mat[4][4], int lay, const struct DupliObject *dob);
 void RE_makeRenderInstances(struct Render *re);
 
 void RE_instance_rotate_ray_start(struct ObjectInstanceRen *obi, struct Isect *is);
index ee28c3b286f6140086208c7f106cef8e2b61fe0f..0adcc16514e86854a2c539bf6ccd6cf1f1aa462e 100644 (file)
@@ -4658,7 +4658,7 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject *
 
                /* only add instance for objects that have not been used for dupli */
                if (!(ob->transflag & OB_RENDER_DUPLI)) {
-                       obi= RE_addRenderInstance(re, obr, ob, par, index, 0, NULL, ob->lay);
+                       obi = RE_addRenderInstance(re, obr, ob, par, index, 0, NULL, ob->lay, dob);
                        if (dob) set_dupli_tex_mat(re, obi, dob, omat);
                }
                else
@@ -4692,7 +4692,7 @@ static void add_render_object(Render *re, Object *ob, Object *par, DupliObject *
 
                        /* only add instance for objects that have not been used for dupli */
                        if (!(ob->transflag & OB_RENDER_DUPLI)) {
-                               obi= RE_addRenderInstance(re, obr, ob, par, index, psysindex, NULL, ob->lay);
+                               obi = RE_addRenderInstance(re, obr, ob, par, index, psysindex, NULL, ob->lay, dob);
                                if (dob) set_dupli_tex_mat(re, obi, dob, omat);
                        }
                        else
@@ -5053,7 +5053,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp
                                                if (dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, 0))) {
                                                        mul_m4_m4m4(mat, re->viewmat, dob->mat);
                                                                                                                /* ob = particle system, use that layer */
-                                                       obi= RE_addRenderInstance(re, NULL, obd, ob, dob->persistent_id[0], 0, mat, ob->lay); 
+                                                       obi = RE_addRenderInstance(re, NULL, obd, ob, dob->persistent_id[0], 0, mat, ob->lay, dob);
 
                                                        /* fill in instance variables for texturing */
                                                        set_dupli_tex_mat(re, obi, dob, dob_extra->obmat);
@@ -5080,7 +5080,7 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp
                                                        if (dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, psysindex))) {
                                                                if (obi == NULL)
                                                                        mul_m4_m4m4(mat, re->viewmat, dob->mat);
-                                                               obi= RE_addRenderInstance(re, NULL, obd, ob, dob->persistent_id[0], psysindex++, mat, obd->lay);
+                                                               obi = RE_addRenderInstance(re, NULL, obd, ob, dob->persistent_id[0], psysindex++, mat, obd->lay, dob);
 
                                                                set_dupli_tex_mat(re, obi, dob, dob_extra->obmat);
                                                                if (dob->type != OB_DUPLIGROUP) {
index 7a9b2d0903e54bb29ff60cdef202033677229e7c..5f78c8a52db7cb54ce70233fa928b2883c89ca79 100644 (file)
@@ -1363,7 +1363,9 @@ void project_renderdata(Render *re,
 
 /* ------------------------------------------------------------------------- */
 
-ObjectInstanceRen *RE_addRenderInstance(Render *re, ObjectRen *obr, Object *ob, Object *par, int index, int psysindex, float mat[4][4], int lay)
+ObjectInstanceRen *RE_addRenderInstance(
+        Render *re, ObjectRen *obr, Object *ob, Object *par,
+        int index, int psysindex, float mat[4][4], int lay, const DupliObject *dob)
 {
        ObjectInstanceRen *obi;
        float mat3[3][3];
@@ -1377,33 +1379,30 @@ ObjectInstanceRen *RE_addRenderInstance(Render *re, ObjectRen *obr, Object *ob,
        obi->lay= lay;
 
        /* Fill particle info */
-       if (obi->psysindex > 0) {
-               int psysindex = 1;
-               int index;
-               ParticleSystem *psys;
-               if (obi->par) {
-                       for (psys = obi->par->particlesystem.first; psys; psys = psys->next) {
-                               if (psysindex == obi->psysindex)
-                                       break;
-                               ++psysindex;
+       if (par && dob) {
+               const ParticleSystem *psys = dob->particle_system;
+               if (psys) {
+                       int index;
+                       if (obi->index < psys->totpart) {
+                               index = obi->index;
                        }
-                       if (psys) {
-                               if (obi->index < psys->totpart)
-                                       index = obi->index;
-                               else {
-                                       index = psys->child[obi->index - psys->totpart].parent;
-                               }
-                               if (index >= 0) {
-                                       ParticleData* p = &psys->particles[index];
-                                       obi->part_index = index;
-                                       obi->part_size = p->size;
-                                       obi->part_age = RE_GetStats(re)->cfra - p->time;
-                                       obi->part_lifetime = p->lifetime;
-
-                                       copy_v3_v3(obi->part_co, p->state.co);
-                                       copy_v3_v3(obi->part_vel, p->state.vel);
-                                       copy_v3_v3(obi->part_avel, p->state.ave);
-                               }
+                       else if (psys->child) {
+                               index = psys->child[obi->index - psys->totpart].parent;
+                       }
+                       else {
+                               index = -1;
+                       }
+
+                       if (index >= 0) {
+                               const ParticleData *p = &psys->particles[index];
+                               obi->part_index = index;
+                               obi->part_size = p->size;
+                               obi->part_age = RE_GetStats(re)->cfra - p->time;
+                               obi->part_lifetime = p->lifetime;
+
+                               copy_v3_v3(obi->part_co, p->state.co);
+                               copy_v3_v3(obi->part_vel, p->state.vel);
+                               copy_v3_v3(obi->part_avel, p->state.ave);
                        }
                }
        }