svn merge ^/trunk/blender -r40720:40872
[blender.git] / source / blender / render / intern / source / convertblender.c
index ba7af235accbbc7a2f197105d9e86c735859cb02..c241603f64a4eb29112fb3ea4570e30f98e52970 100644 (file)
@@ -981,7 +981,7 @@ static void flag_render_node_material(Render *re, bNodeTree *ntree)
        }
 }
 
-static Material *give_render_material(Render *re, Object *ob, int nr)
+static Material *give_render_material(Render *re, Object *ob, short nr)
 {
        extern Material defmaterial;    /* material.c */
        Material *ma;
@@ -1349,7 +1349,7 @@ static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, Particl
        int totsplit = bb->uv_split * bb->uv_split;
        int tile, x, y;
        /* Tile offsets */
-       float uvx = 0.0f, uvy = 0.0f, uvdx = 1.0f, uvdy = 1.0f, time = 0.0f;
+       float uvx = 0.0f, uvy = 0.0f, uvdx = 1.0f, uvdy = 1.0f, time = 0.0f;
 
        vlr= RE_findOrAddVlak(obr, obr->totvlak++);
        vlr->v1= RE_findOrAddVert(obr, obr->totvert++);
@@ -1524,7 +1524,7 @@ static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int
        if(sd->uvco && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) {
                for(i=0; i<sd->totuv; i++) {
                        if(num != DMCACHE_NOTFOUND) {
-                               MFace *mface = dm->getFaceData(dm, num, CD_MFACE);
+                               MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE);
                                MTFace *mtface = (MTFace*)CustomData_get_layer_n(&dm->faceData, CD_MTFACE, i);
                                mtface += num;
                                
@@ -1541,7 +1541,7 @@ static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int
        if(sd->mcol && ELEM(from,PART_FROM_FACE,PART_FROM_VOLUME)) {
                for(i=0; i<sd->totcol; i++) {
                        if(num != DMCACHE_NOTFOUND) {
-                               MFace *mface = dm->getFaceData(dm, num, CD_MFACE);
+                               MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE);
                                MCol *mc = (MCol*)CustomData_get_layer_n(&dm->faceData, CD_MCOL, i);
                                mc += num * 4;
 
@@ -1752,8 +1752,8 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                                if(ma->amb != 0.0f)
                                        dosurfacecache= 1;
 
-                       totface= psmd->dm->getNumFaces(psmd->dm);
-                       origindex= psmd->dm->getFaceDataArray(psmd->dm, CD_ORIGINDEX);
+                       totface= psmd->dm->getNumTessFaces(psmd->dm);
+                       origindex= psmd->dm->getTessFaceDataArray(psmd->dm, CD_ORIGINDEX);
                        for(a=0; a<totface; a++)
                                strandbuf->totbound= MAX2(strandbuf->totbound, (origindex)? origindex[a]: a);
 
@@ -1797,7 +1797,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                        num= pa->num_dmcache;
 
                        if(num == DMCACHE_NOTFOUND)
-                               if(pa->num < psmd->dm->getNumFaces(psmd->dm))
+                               if(pa->num < psmd->dm->getNumTessFaces(psmd->dm))
                                        num= pa->num;
 
                        get_particle_uvco_mcol(part->from, psmd->dm, pa->fuv, num, &sd);
@@ -1856,7 +1856,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                                num = parent->num_dmcache;
 
                                if(num == DMCACHE_NOTFOUND)
-                                       if(parent->num < psmd->dm->getNumFaces(psmd->dm))
+                                       if(parent->num < psmd->dm->getNumTessFaces(psmd->dm))
                                                num = parent->num;
 
                                get_particle_uvco_mcol(part->from, psmd->dm, parent->fuv, num, &sd);
@@ -2688,7 +2688,8 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr,
        int timeoffset, float *orco, float mat[4][4])
 {
        Object *ob= obr->ob;
-       int a, a1, end, totvert, vertofs;
+       int a, end, totvert, vertofs;
+       short mat_iter;
        VertRen *ver;
        VlakRen *vlr;
        MVert *mvert = NULL;
@@ -2718,16 +2719,16 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr,
 
                /* faces in order of color blocks */
                vertofs= obr->totvert - totvert;
-               for(a1=0; (a1<ob->totcol || (a1==0 && ob->totcol==0)); a1++) {
+               for(mat_iter= 0; (mat_iter < ob->totcol || (mat_iter==0 && ob->totcol==0)); mat_iter++) {
 
-                       ma= give_render_material(re, ob, a1+1);
-                       end= dm->getNumFaces(dm);
-                       mface= dm->getFaceArray(dm);
+                       ma= give_render_material(re, ob, mat_iter+1);
+                       end= dm->getNumTessFaces(dm);
+                       mface= dm->getTessFaceArray(dm);
 
                        for(a=0; a<end; a++, mface++) {
                                int v1, v2, v3, v4, flag;
 
-                               if( mface->mat_nr==a1 ) {
+                               if(mface->mat_nr == mat_iter) {
                                        float len;
 
                                        v1= mface->v1;
@@ -3101,10 +3102,10 @@ static struct edgesort *make_mesh_edge_lookup(DerivedMesh *dm, int *totedgesort)
        unsigned int *mcol=NULL;
        int a, totedge=0, totface;
 
-       mface= dm->getFaceArray(dm);
-       totface= dm->getNumFaces(dm);
-       tface= dm->getFaceDataArray(dm, CD_MTFACE);
-       mcol= dm->getFaceDataArray(dm, CD_MCOL);
+       mface= dm->getTessFaceArray(dm);
+       totface= dm->getNumTessFaces(dm);
+       tface= dm->getTessFaceDataArray(dm, CD_MTFACE);
+       mcol= dm->getTessFaceDataArray(dm, CD_MCOL);
 
        if(mcol==NULL && tface==NULL) return NULL;
 
@@ -3325,7 +3326,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
        totvert= dm->getNumVerts(dm);
 
        /* attempt to autsmooth on original mesh, only without subsurf */
-       if(do_autosmooth && me->totvert==totvert && me->totface==dm->getNumFaces(dm))
+       if(do_autosmooth && me->totvert==totvert && me->totface==dm->getNumTessFaces(dm))
                use_original_normals= 1;
        
        ms = (totvert==me->totvert)?me->msticky:NULL;
@@ -3398,8 +3399,8 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
                                }
 
                                if(ok) {
-                                       end= dm->getNumFaces(dm);
-                                       mface= dm->getFaceArray(dm);
+                                       end= dm->getNumTessFaces(dm);
+                                       mface= dm->getTessFaceArray(dm);
                                        
                                        for(a=0; a<end; a++, mface++) {
                                                int v1, v2, v3, v4, flag;
@@ -4358,9 +4359,9 @@ static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset)
 /* Database                                                                                                                                     */
 /* ------------------------------------------------------------------------- */
 
-static int render_object_type(int type) 
+static int render_object_type(short type)
 {
-       return ELEM5(type, OB_FONT, OB_CURVE, OB_SURF, OB_MESH, OB_MBALL);
+       return OB_TYPE_SUPPORT_MATERIAL(type);
 }
 
 static void find_dupli_instances(Render *re, ObjectRen *obr)
@@ -4851,8 +4852,13 @@ static void database_init_objects(Render *re, unsigned int renderlay, int nolamp
         * NULL is just for init */
        set_dupli_tex_mat(NULL, NULL, NULL);
 
-       for(SETLOOPER(re->scene, sce_iter, base)) {
-               ob= base->object;
+       /* loop over all objects rather then using SETLOOPER because we may
+        * reference an mtex-mapped object which isnt rendered or is an
+        * empty in a dupli group. We could scan all render material/lamp/world
+        * mtex's for mapto objects but its easier just to set the
+        * 'imat' / 'imat_ren' on all and unlikely to be a performance hit
+       * See bug: [#28744] - campbell */
+       for(ob= re->main->object.first; ob; ob= ob->id.next) {
                /* imat objects has to be done here, since displace can have texture using Object map-input */
                mul_m4_m4m4(mat, ob->obmat, re->viewmat);
                invert_m4_m4(ob->imat_ren, mat);
@@ -5020,7 +5026,7 @@ void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int l
        /* per second, per object, stats print this */
        re->i.infostr= "Preparing Scene data";
        re->i.cfra= scene->r.cfra;
-       strncpy(re->i.scenename, scene->id.name+2, 20);
+       BLI_strncpy(re->i.scenename, scene->id.name+2, sizeof(re->i.scenename));
        
        /* XXX add test if dbase was filled already? */
        
@@ -5303,11 +5309,13 @@ static void calculate_speedvector(const float vectors[2], int step, float winsq,
 
 static float *calculate_strandsurface_speedvectors(Render *re, ObjectInstanceRen *obi, StrandSurface *mesh)
 {
-       float winsq= (float)re->winx*(float)re->winy, winroot= sqrt(winsq), (*winspeed)[4];  /* int's can wrap on large images */
-       float ho[4], prevho[4], nextho[4], winmat[4][4], vec[2];
-       int a;
-
        if(mesh->co && mesh->prevco && mesh->nextco) {
+               float winsq= (float)re->winx*(float)re->winy; /* int's can wrap on large images */
+               float winroot= sqrt(winsq);
+               float (*winspeed)[4];
+               float ho[4], prevho[4], nextho[4], winmat[4][4], vec[2];
+               int a;
+
                if(obi->flag & R_TRANSFORMED)
                        mul_m4_m4m4(winmat, obi->mat, re->winmat);
                else